mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 20:34:28 +00:00
feat(sandbox): add pending domains support for network sandbox
This commit is contained in:
@@ -4,7 +4,7 @@ import { client } from '@/ui/api/client'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Loader2, Plus, X, Globe } from 'lucide-react'
|
||||
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
@@ -23,10 +23,10 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
})
|
||||
|
||||
const { mutate: updateSandbox, isPending: isUpdating } = useMutation({
|
||||
mutationFn: async (allowedDomains: string[]) => {
|
||||
mutationFn: async (params: { allowedDomains: string[]; pendingDomains: string[] }) => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$put({
|
||||
param: { teamId },
|
||||
json: { allowedDomains },
|
||||
json: params,
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update sandbox settings')
|
||||
return await res.json()
|
||||
@@ -47,14 +47,27 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
toast.error('Domain already exists')
|
||||
return
|
||||
}
|
||||
const updated = [...(sandbox?.allowedDomains || []), newDomain.trim()]
|
||||
updateSandbox(updated)
|
||||
const updatedAllowed = [...(sandbox?.allowedDomains || []), newDomain.trim()]
|
||||
const updatedPending = sandbox?.pendingDomains || []
|
||||
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
|
||||
setNewDomain('')
|
||||
}
|
||||
|
||||
const handleRemoveDomain = (domain: string) => {
|
||||
const updated = (sandbox?.allowedDomains || []).filter((d) => d !== domain)
|
||||
updateSandbox(updated)
|
||||
const updatedAllowed = (sandbox?.allowedDomains || []).filter((d) => d !== domain)
|
||||
const updatedPending = sandbox?.pendingDomains || []
|
||||
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
|
||||
}
|
||||
|
||||
const handleApproveDomain = (domain: string) => {
|
||||
const updatedAllowed = [...(sandbox?.allowedDomains || []), domain]
|
||||
const updatedPending = (sandbox?.pendingDomains || []).filter((d) => d !== domain)
|
||||
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
|
||||
}
|
||||
|
||||
const handleDeletePendingDomain = (domain: string) => {
|
||||
const updatedPending = (sandbox?.pendingDomains || []).filter((d) => d !== domain)
|
||||
updateSandbox({ allowedDomains: sandbox?.allowedDomains || [], pendingDomains: updatedPending })
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
@@ -122,6 +135,64 @@ export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Pending Domains Section */}
|
||||
<Card className="border-amber-200 dark:border-amber-900 bg-amber-50/10 dark:bg-amber-950/5">
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<ShieldAlert className="w-5 h-5 text-amber-500" />
|
||||
<CardTitle>Pending Domain Approvals</CardTitle>
|
||||
</div>
|
||||
<CardDescription>
|
||||
These domains were blocked during agent execution. You can approve them to allow future
|
||||
network requests, or delete them from this list.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{sandbox?.pendingDomains && sandbox.pendingDomains.length > 0 ? (
|
||||
<div className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{sandbox.pendingDomains.map((domain) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center justify-between py-2.5 first:pt-0 last:pb-0"
|
||||
>
|
||||
<span className="font-mono text-sm text-slate-700 dark:text-slate-300 bg-slate-100 dark:bg-slate-800 px-2 py-1 rounded">
|
||||
{domain}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 border-emerald-200 text-emerald-600 hover:bg-emerald-50 hover:text-emerald-700 dark:border-emerald-900 dark:text-emerald-400 dark:hover:bg-emerald-950/20"
|
||||
onClick={() => handleApproveDomain(domain)}
|
||||
disabled={isUpdating}
|
||||
>
|
||||
<Check className="w-4 h-4 mr-1.5" />
|
||||
Approve
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 border-red-200 text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-900 dark:text-red-400 dark:hover:bg-red-950/20"
|
||||
onClick={() => handleDeletePendingDomain(domain)}
|
||||
disabled={isUpdating}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-1.5" />
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-sm text-slate-400 italic py-2">
|
||||
No pending domains requiring approval
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Filesystem Restriction</CardTitle>
|
||||
|
||||
Reference in New Issue
Block a user