mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 21:04:59 +00:00
feat(runner): replace server-side bash sandbox with remote runner (#530)
* feat(runner): replace server-side bash sandbox with remote runner * fix(runner): address review findings for output bounds, key rotation, defaults, and generated uploads * chore(docker): remove sandbox privileges and env vars from remaining compose files * feat(cli): add runner start with bundled SRT sandboxing (#535) * refactor(agent): expose runner bash without skill gating * feat(cli): add runner start with optional SRT sandboxing * refactor(cli): remove runner Python dependency * feat(cli): bundle SRT and use platform-native runner shells * refactor(cli): delegate runner processes to Execa * chore(cli): upgrade @anthropic-ai/sandbox-runtime to 0.0.83 * feat(cli): discover Bash for Windows runners Use Pi-style Bash discovery and launch behavior, exercise the packaged CLI shell, and wait for pending ZIP metadata reads before closing cancelled downloads. * fix(runner): enforce ownership and safe reconnects Gate dispatch on reconciliation, retain cancellations across disconnects, and stop replaced clients. Guard the single-server runner topology with a database lease. Restage missing generated inputs, report signal exits, and bound generated-file cleanup. * feat(webui): add Korean translations for agent runners * feat(cli): add runner event logging and --verbose flag (#536) * feat(cli): add runner event logging and --verbose flag * fix(cli): log runner capacity rejections accurately and use monotonic duration
This commit is contained in:
@@ -64,6 +64,7 @@ const agentFormSchema = z.object({
|
||||
skills: z.array(z.string()).optional(),
|
||||
mcpServerIds: z.array(z.string()).optional(),
|
||||
deniedTools: z.array(z.string()).optional(),
|
||||
runnerId: z.string().nullable().optional(),
|
||||
})
|
||||
|
||||
const BUILTIN_TOOLS = [
|
||||
@@ -256,6 +257,22 @@ export function AgentFormDialog({
|
||||
|
||||
const allMcpServers = mcpData?.servers || []
|
||||
|
||||
// Fetch Runners
|
||||
const { data: runnersData } = useQuery({
|
||||
queryKey: ['teams', teamId, 'runners'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].runners.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch runners')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: isOpen,
|
||||
})
|
||||
|
||||
const allRunners = runnersData || []
|
||||
const defaultRunner = allRunners.find((r) => r.isDefault) || allRunners[0]
|
||||
|
||||
const schema = useMemo(() => {
|
||||
return agentFormSchema.superRefine((data, ctx) => {
|
||||
if (data.type === 'chat' || data.type === 'autofill') {
|
||||
@@ -291,6 +308,7 @@ export function AgentFormDialog({
|
||||
skills: initialValues?.skills?.map((s) => s.skillId) || ([] as string[]),
|
||||
mcpServerIds: initialValues?.mcpServerIds || ([] as string[]),
|
||||
deniedTools: initialValues?.deniedTools ?? [...DEFAULT_DENIED_TOOLS],
|
||||
runnerId: initialValues?.runnerId ?? null,
|
||||
} as AgentFormValues,
|
||||
validators: {
|
||||
onChange: schema,
|
||||
@@ -1052,8 +1070,66 @@ export function AgentFormDialog({
|
||||
name="deniedTools"
|
||||
children={(deniedToolsField) => {
|
||||
const currentDenied = deniedToolsField.state.value || []
|
||||
const isBashEnabled = !currentDenied.includes('bash')
|
||||
return (
|
||||
<>
|
||||
{isBashEnabled && (
|
||||
<div className="p-3.5 mb-3 rounded-lg border border-border bg-muted/40 space-y-2">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
|
||||
<div>
|
||||
<Label className="text-sm font-medium text-foreground">
|
||||
{m.agent_runner_label()}
|
||||
</Label>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
{m.agent_runner_description()}
|
||||
</p>
|
||||
</div>
|
||||
{allRunners.length > 0 && (
|
||||
<form.Field
|
||||
name="runnerId"
|
||||
children={(runnerField) => (
|
||||
<Select
|
||||
value={runnerField.state.value || '__default__'}
|
||||
onValueChange={(val) =>
|
||||
runnerField.handleChange(
|
||||
val === '__default__' ? null : val,
|
||||
)
|
||||
}
|
||||
disabled={readOnly || !canAdmin}
|
||||
>
|
||||
<SelectTrigger className="w-full sm:w-[240px] h-8 text-xs bg-background">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__default__">
|
||||
{defaultRunner
|
||||
? m.agent_runner_team_default_with_name({
|
||||
name: defaultRunner.name,
|
||||
})
|
||||
: m.agent_runner_team_default()}
|
||||
</SelectItem>
|
||||
{allRunners.map((r) => (
|
||||
<SelectItem key={r.id} value={r.id}>
|
||||
{r.name} (
|
||||
{r.status === 'connected'
|
||||
? m.runner_status_connected()
|
||||
: m.runner_status_disconnected()}
|
||||
)
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{allRunners.length === 0 && (
|
||||
<p className="text-xs text-amber-600 dark:text-amber-400">
|
||||
{m.agent_runner_none_configured_warning()}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{BUILTIN_TOOLS.map((tool) => {
|
||||
const isEnabled = !currentDenied.includes(tool.id)
|
||||
return (
|
||||
|
||||
@@ -148,6 +148,7 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
||||
soul?: string
|
||||
skills?: string[]
|
||||
deniedTools?: string[]
|
||||
runnerId?: string | null
|
||||
}) => {
|
||||
const res = await client.api.agents[':agentId'].$put({
|
||||
param: { agentId: params.agentId },
|
||||
@@ -163,6 +164,7 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
||||
soul: params.soul,
|
||||
skills: params.skills,
|
||||
deniedTools: params.deniedTools,
|
||||
runnerId: params.runnerId,
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error('failed to update agent')
|
||||
@@ -434,6 +436,7 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
||||
soul: agent.soul,
|
||||
skills: agent.skills?.map((s) => s.skillId),
|
||||
deniedTools: agent.deniedTools,
|
||||
runnerId: agent.runnerId,
|
||||
})
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,650 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { ScrollArea } from '@/ui/components/ui/scroll-area'
|
||||
import { Card, CardContent } from '@/ui/components/ui/card'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Badge } from '@/ui/components/ui/badge'
|
||||
import { Label } from '@/ui/components/ui/label'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { Textarea } from '@/ui/components/ui/textarea'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/ui/components/ui/dialog'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/ui/components/ui/alert-dialog'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import {
|
||||
Check,
|
||||
Copy,
|
||||
Edit2,
|
||||
KeyRound,
|
||||
Loader2,
|
||||
MoreVertical,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Star,
|
||||
Terminal,
|
||||
Trash2,
|
||||
} from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import type { RunnerInfo } from '@shumai/dtos'
|
||||
|
||||
export function RunnerSettings({ teamId }: { teamId: string }) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
// Create Dialog state
|
||||
const [isCreateOpen, setIsCreateOpen] = useState(false)
|
||||
const [newName, setNewName] = useState('')
|
||||
const [newDescription, setNewDescription] = useState('')
|
||||
const [newIsDefault, setNewIsDefault] = useState(false)
|
||||
|
||||
// Edit Dialog state
|
||||
const [editingRunner, setEditingRunner] = useState<RunnerInfo | null>(null)
|
||||
const [editName, setEditName] = useState('')
|
||||
const [editDescription, setEditDescription] = useState('')
|
||||
|
||||
// Rotate & Delete Confirm Dialog state
|
||||
const [runnerToRotate, setRunnerToRotate] = useState<RunnerInfo | null>(null)
|
||||
const [runnerToDelete, setRunnerToDelete] = useState<RunnerInfo | null>(null)
|
||||
|
||||
// One-time Key Reveal Dialog state
|
||||
const [revealedKeyData, setRevealedKeyData] = useState<{
|
||||
name: string
|
||||
key: string
|
||||
} | null>(null)
|
||||
const [copiedField, setCopiedField] = useState<string | null>(null)
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['teams', teamId, 'runners'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].runners.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_load_runners())
|
||||
return await res.json()
|
||||
},
|
||||
refetchInterval: 5000,
|
||||
})
|
||||
|
||||
const runners = data ?? []
|
||||
|
||||
const createRunnerMutation = useMutation({
|
||||
mutationFn: async (params: { name: string; description?: string; isDefault?: boolean }) => {
|
||||
const res = await client.api.teams[':teamId'].runners.$post({
|
||||
param: { teamId },
|
||||
json: params,
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_create_runner())
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: (created) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'runners'] })
|
||||
setIsCreateOpen(false)
|
||||
setNewName('')
|
||||
setNewDescription('')
|
||||
setNewIsDefault(false)
|
||||
setRevealedKeyData({ name: created.runner.name, key: created.key })
|
||||
toast.success(m.runner_created_successfully())
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : m.failed_to_create_runner())
|
||||
},
|
||||
})
|
||||
|
||||
const updateRunnerMutation = useMutation({
|
||||
mutationFn: async (params: {
|
||||
runnerId: string
|
||||
name?: string
|
||||
description?: string | null
|
||||
isDefault?: boolean
|
||||
}) => {
|
||||
const res = await client.api.teams[':teamId'].runners[':runnerId'].$patch({
|
||||
param: { teamId, runnerId: params.runnerId },
|
||||
json: {
|
||||
name: params.name,
|
||||
description: params.description,
|
||||
isDefault: params.isDefault,
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_update_runner())
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'runners'] })
|
||||
setEditingRunner(null)
|
||||
toast.success(m.runner_updated_successfully())
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : m.failed_to_update_runner())
|
||||
},
|
||||
})
|
||||
|
||||
const rotateKeyMutation = useMutation({
|
||||
mutationFn: async (runnerId: string) => {
|
||||
const res = await client.api.teams[':teamId'].runners[':runnerId']['rotate-key'].$post({
|
||||
param: { teamId, runnerId },
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_rotate_runner_key())
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: (rotated) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'runners'] })
|
||||
setRunnerToRotate(null)
|
||||
setRevealedKeyData({ name: rotated.runner.name, key: rotated.key })
|
||||
toast.success(m.runner_key_rotated_successfully())
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : m.failed_to_rotate_runner_key())
|
||||
},
|
||||
})
|
||||
|
||||
const deleteRunnerMutation = useMutation({
|
||||
mutationFn: async (runnerId: string) => {
|
||||
const res = await client.api.teams[':teamId'].runners[':runnerId'].$delete({
|
||||
param: { teamId, runnerId },
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_delete_runner())
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'runners'] })
|
||||
setRunnerToDelete(null)
|
||||
toast.success(m.runner_deleted_successfully())
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : m.failed_to_delete_runner())
|
||||
},
|
||||
})
|
||||
|
||||
const handleCopy = async (text: string, field: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
setCopiedField(field)
|
||||
toast.success(m.runner_copied_to_clipboard())
|
||||
setTimeout(() => {
|
||||
setCopiedField((prev) => (prev === field ? null : prev))
|
||||
}, 2000)
|
||||
} catch {
|
||||
// Ignore clipboard failure
|
||||
}
|
||||
}
|
||||
|
||||
const serverOrigin = typeof window !== 'undefined' ? window.location.origin : ''
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ScrollArea className="h-full">
|
||||
<div className="space-y-4 pr-4 pb-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{runners.length > 0 ? `${runners.length} ${m.runners()}` : ''}
|
||||
</div>
|
||||
<Button onClick={() => setIsCreateOpen(true)}>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
{m.create_runner()}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{runners.length === 0 ? (
|
||||
<Card className="border-dashed">
|
||||
<CardContent className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<div className="w-12 h-12 rounded-full bg-muted flex items-center justify-center mb-4">
|
||||
<Terminal className="w-6 h-6 text-muted-foreground" />
|
||||
</div>
|
||||
<h3 className="text-base font-semibold text-foreground mb-1">
|
||||
{m.runner_empty_title()}
|
||||
</h3>
|
||||
<p className="text-sm text-muted-foreground max-w-md mb-6">
|
||||
{m.runner_empty_description()}
|
||||
</p>
|
||||
<Button onClick={() => setIsCreateOpen(true)}>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
{m.create_runner()}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{runners.map((runner) => {
|
||||
const isOnline = runner.status === 'connected'
|
||||
return (
|
||||
<Card key={runner.id} className="border-border">
|
||||
<CardContent className="p-4 flex items-center justify-between gap-4">
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="font-semibold text-foreground truncate">
|
||||
{runner.name}
|
||||
</span>
|
||||
<Badge
|
||||
variant="outline"
|
||||
className={
|
||||
isOnline
|
||||
? 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/30 gap-1.5'
|
||||
: 'bg-muted text-muted-foreground border-border gap-1.5'
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
isOnline
|
||||
? 'w-1.5 h-1.5 rounded-full bg-emerald-500'
|
||||
: 'w-1.5 h-1.5 rounded-full bg-muted-foreground'
|
||||
}
|
||||
/>
|
||||
{isOnline
|
||||
? m.runner_status_connected()
|
||||
: m.runner_status_disconnected()}
|
||||
</Badge>
|
||||
{runner.isDefault && (
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="bg-primary/10 text-primary border-primary/20 gap-1"
|
||||
>
|
||||
<Star className="w-3 h-3 fill-current" />
|
||||
{m.runner_default_badge()}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
{runner.description && (
|
||||
<p className="text-xs text-muted-foreground line-clamp-1">
|
||||
{runner.description}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex items-center gap-4 text-xs text-muted-foreground pt-1">
|
||||
<span className="font-mono bg-muted px-1.5 py-0.5 rounded border border-border">
|
||||
{m.runner_key_prefix_label()}: {runner.keyPrefix}...
|
||||
</span>
|
||||
<span>
|
||||
{runner.lastConnectedAt
|
||||
? m.runner_last_seen_label({
|
||||
time: new Date(runner.lastConnectedAt).toLocaleString(),
|
||||
})
|
||||
: m.runner_never_connected()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||
<MoreVertical className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-44">
|
||||
{!runner.isDefault && (
|
||||
<DropdownMenuItem
|
||||
onClick={() =>
|
||||
updateRunnerMutation.mutate({
|
||||
runnerId: runner.id,
|
||||
isDefault: true,
|
||||
})
|
||||
}
|
||||
className="gap-2 cursor-pointer"
|
||||
>
|
||||
<Star className="w-4 h-4" />
|
||||
{m.runner_set_default_action()}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setEditingRunner(runner)
|
||||
setEditName(runner.name)
|
||||
setEditDescription(runner.description || '')
|
||||
}}
|
||||
className="gap-2 cursor-pointer"
|
||||
>
|
||||
<Edit2 className="w-4 h-4" />
|
||||
{m.runner_edit_action()}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setRunnerToRotate(runner)}
|
||||
className="gap-2 cursor-pointer"
|
||||
>
|
||||
<RefreshCw className="w-4 h-4" />
|
||||
{m.runner_rotate_key_action()}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => setRunnerToDelete(runner)}
|
||||
className="text-destructive focus:text-destructive gap-2 cursor-pointer"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
{m.delete()}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
{/* Create Runner Dialog */}
|
||||
<Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{m.create_runner()}</DialogTitle>
|
||||
<DialogDescription>{m.create_runner_description()}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
if (!newName.trim()) return
|
||||
createRunnerMutation.mutate({
|
||||
name: newName.trim(),
|
||||
description: newDescription.trim() || undefined,
|
||||
isDefault: newIsDefault || runners.length === 0,
|
||||
})
|
||||
}}
|
||||
className="space-y-4"
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="runner-name">{m.runner_name()}</Label>
|
||||
<Input
|
||||
id="runner-name"
|
||||
value={newName}
|
||||
onChange={(e) => setNewName(e.target.value)}
|
||||
placeholder={m.runner_name_placeholder()}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="runner-description">{m.runner_description()}</Label>
|
||||
<Textarea
|
||||
id="runner-description"
|
||||
value={newDescription}
|
||||
onChange={(e) => setNewDescription(e.target.value)}
|
||||
placeholder={m.runner_description_placeholder()}
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
{runners.length > 0 && (
|
||||
<div className="flex items-center justify-between rounded-lg border border-border p-3 bg-muted/30">
|
||||
<Label htmlFor="runner-default-switch" className="cursor-pointer text-sm">
|
||||
{m.runner_set_as_default()}
|
||||
</Label>
|
||||
<Switch
|
||||
id="runner-default-switch"
|
||||
checked={newIsDefault}
|
||||
onCheckedChange={setNewIsDefault}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => setIsCreateOpen(false)}>
|
||||
{m.cancel()}
|
||||
</Button>
|
||||
<Button type="submit" disabled={!newName.trim() || createRunnerMutation.isPending}>
|
||||
{createRunnerMutation.isPending && (
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
)}
|
||||
{m.create_runner()}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Edit Runner Dialog */}
|
||||
<Dialog open={!!editingRunner} onOpenChange={(open) => !open && setEditingRunner(null)}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{m.runner_edit_action()}</DialogTitle>
|
||||
<DialogDescription>{m.runner_edit_description()}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
if (!editingRunner || !editName.trim()) return
|
||||
updateRunnerMutation.mutate({
|
||||
runnerId: editingRunner.id,
|
||||
name: editName.trim(),
|
||||
description: editDescription.trim() || null,
|
||||
})
|
||||
}}
|
||||
className="space-y-4"
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-runner-name">{m.runner_name()}</Label>
|
||||
<Input
|
||||
id="edit-runner-name"
|
||||
value={editName}
|
||||
onChange={(e) => setEditName(e.target.value)}
|
||||
placeholder={m.runner_name_placeholder()}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-runner-description">{m.runner_description()}</Label>
|
||||
<Textarea
|
||||
id="edit-runner-description"
|
||||
value={editDescription}
|
||||
onChange={(e) => setEditDescription(e.target.value)}
|
||||
placeholder={m.runner_description_placeholder()}
|
||||
rows={2}
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => setEditingRunner(null)}>
|
||||
{m.cancel()}
|
||||
</Button>
|
||||
<Button type="submit" disabled={!editName.trim() || updateRunnerMutation.isPending}>
|
||||
{updateRunnerMutation.isPending && (
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
)}
|
||||
{m.save_changes()}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* One-Time Key Reveal Modal */}
|
||||
<Dialog open={!!revealedKeyData} onOpenChange={(open) => !open && setRevealedKeyData(null)}>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<KeyRound className="w-5 h-5 text-primary" />
|
||||
{m.runner_key_dialog_title()}
|
||||
</DialogTitle>
|
||||
<DialogDescription>{m.runner_key_dialog_description()}</DialogDescription>
|
||||
</DialogHeader>
|
||||
{revealedKeyData && (
|
||||
<div className="space-y-4 py-2">
|
||||
<div className="space-y-1.5">
|
||||
<Label className="text-xs text-muted-foreground">{m.runner_key_label()}</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
readOnly
|
||||
value={revealedKeyData.key}
|
||||
className="font-mono text-xs bg-muted"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleCopy(revealedKeyData.key, 'key')}
|
||||
>
|
||||
{copiedField === 'key' ? (
|
||||
<Check className="w-4 h-4 text-emerald-500" />
|
||||
) : (
|
||||
<Copy className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
{m.runner_quickstart_command_label()}
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
readOnly
|
||||
value={`shumai-cli runner start --url ${serverOrigin} --key ${revealedKeyData.key}`}
|
||||
className="font-mono text-xs bg-muted"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() =>
|
||||
handleCopy(
|
||||
`shumai-cli runner start --url ${serverOrigin} --key ${revealedKeyData.key}`,
|
||||
'cmd',
|
||||
)
|
||||
}
|
||||
>
|
||||
{copiedField === 'cmd' ? (
|
||||
<Check className="w-4 h-4 text-emerald-500" />
|
||||
) : (
|
||||
<Copy className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
{m.runner_quickstart_sandbox_label()}
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
readOnly
|
||||
value={`shumai-cli runner start --url ${serverOrigin} --key ${revealedKeyData.key} --srt sandbox.json`}
|
||||
className="font-mono text-xs bg-muted"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() =>
|
||||
handleCopy(
|
||||
`shumai-cli runner start --url ${serverOrigin} --key ${revealedKeyData.key} --srt sandbox.json`,
|
||||
'sandboxCmd',
|
||||
)
|
||||
}
|
||||
>
|
||||
{copiedField === 'sandboxCmd' ? (
|
||||
<Check className="w-4 h-4 text-emerald-500" />
|
||||
) : (
|
||||
<Copy className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<DialogFooter>
|
||||
<Button type="button" onClick={() => setRevealedKeyData(null)}>
|
||||
{m.close()}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Rotate Key Confirmation */}
|
||||
<AlertDialog
|
||||
open={!!runnerToRotate}
|
||||
onOpenChange={(open) => !open && setRunnerToRotate(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{m.runner_rotate_key_confirm_title()}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{m.runner_rotate_key_confirm_description({ name: runnerToRotate?.name ?? '' })}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{m.cancel()}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={(e) => {
|
||||
if (rotateKeyMutation.isPending) {
|
||||
e.preventDefault()
|
||||
return
|
||||
}
|
||||
if (runnerToRotate) {
|
||||
rotateKeyMutation.mutate(runnerToRotate.id)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{rotateKeyMutation.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
m.runner_rotate_key_action()
|
||||
)}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
{/* Delete Runner Confirmation */}
|
||||
<AlertDialog
|
||||
open={!!runnerToDelete}
|
||||
onOpenChange={(open) => !open && setRunnerToDelete(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{m.runner_delete_confirm_title()}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{m.runner_delete_confirm_description({ name: runnerToDelete?.name ?? '' })}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{m.cancel()}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive hover:bg-destructive/90 text-white"
|
||||
onClick={(e) => {
|
||||
if (deleteRunnerMutation.isPending) {
|
||||
e.preventDefault()
|
||||
return
|
||||
}
|
||||
if (runnerToDelete) {
|
||||
deleteRunnerMutation.mutate(runnerToDelete.id)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteRunnerMutation.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
m.delete()
|
||||
)}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { ScrollArea } from '@/ui/components/ui/scroll-area'
|
||||
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 { Switch } from '@/ui/components/ui/switch'
|
||||
import { Loader2, Plus, X, Globe, Check, Trash2, ShieldAlert, Info } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
const queryClient = useQueryClient()
|
||||
const [newDomain, setNewDomain] = useState('')
|
||||
|
||||
const { data: sandbox, isLoading } = useQuery({
|
||||
queryKey: ['teams', teamId, 'sandbox'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_load_settings())
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const { mutate: updateSandbox, isPending: isUpdating } = useMutation({
|
||||
mutationFn: async (params: {
|
||||
networkSandboxEnabled?: boolean
|
||||
allowedDomains?: string[]
|
||||
pendingDomains?: string[]
|
||||
}) => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$put({
|
||||
param: { teamId },
|
||||
json: params,
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_update_sandbox_settings())
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'sandbox'] })
|
||||
toast.success(m.sandbox_settings_updated())
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : m.failed_to_update_sandbox_settings())
|
||||
},
|
||||
})
|
||||
|
||||
const handleToggleNetworkSandbox = (enabled: boolean) => {
|
||||
updateSandbox({
|
||||
networkSandboxEnabled: enabled,
|
||||
})
|
||||
}
|
||||
|
||||
const handleAddDomain = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!newDomain.trim()) return
|
||||
if (sandbox?.allowedDomains.includes(newDomain.trim())) {
|
||||
toast.error(m.domain_already_exists())
|
||||
return
|
||||
}
|
||||
const updatedAllowed = [...(sandbox?.allowedDomains || []), newDomain.trim()]
|
||||
const updatedPending = sandbox?.pendingDomains || []
|
||||
updateSandbox({ allowedDomains: updatedAllowed, pendingDomains: updatedPending })
|
||||
setNewDomain('')
|
||||
}
|
||||
|
||||
const handleRemoveDomain = (domain: string) => {
|
||||
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) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const isNetworkSandboxEnabled = !!sandbox?.networkSandboxEnabled
|
||||
|
||||
return (
|
||||
<ScrollArea className="h-full">
|
||||
<div className="space-y-6 pr-4 pb-8">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Globe className="w-5 h-5 text-primary" />
|
||||
<CardTitle>{m.network_sandbox()}</CardTitle>
|
||||
</div>
|
||||
<CardDescription>{m.network_sandbox_description()}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{/* Toggle Switch */}
|
||||
<div className="flex items-center justify-between p-4 mb-6 rounded-lg border border-border bg-muted/30">
|
||||
<div className="space-y-0.5 pr-4">
|
||||
<label
|
||||
htmlFor="network-sandbox-switch"
|
||||
className="text-sm font-medium text-foreground cursor-pointer"
|
||||
>
|
||||
{m.enable_network_sandbox()}
|
||||
</label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{m.network_sandbox_enabled_description()}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="network-sandbox-switch"
|
||||
checked={isNetworkSandboxEnabled}
|
||||
onCheckedChange={handleToggleNetworkSandbox}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{!isNetworkSandboxEnabled && (
|
||||
<div className="flex items-start gap-2.5 p-3.5 mb-6 rounded-lg bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-300 text-sm">
|
||||
<Info className="w-4 h-4 mt-0.5 shrink-0" />
|
||||
<span>{m.network_sandbox_disabled_notice()}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleAddDomain} className="flex gap-2 mb-6">
|
||||
<Input
|
||||
placeholder="e.g. api.openai.com"
|
||||
value={newDomain}
|
||||
onChange={(e) => setNewDomain(e.target.value)}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
/>
|
||||
<Button type="submit" disabled={isUpdating || !isNetworkSandboxEnabled}>
|
||||
{isUpdating ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
{m.add_domain()}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="space-y-2">
|
||||
<h4 className="text-sm font-medium text-muted-foreground mb-3">
|
||||
{m.allowed_domains()}
|
||||
</h4>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{sandbox?.allowedDomains.map((domain: string) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center gap-1 px-3 py-1.5 bg-muted rounded-full text-sm border border-border transition-all hover:border-muted-foreground/50"
|
||||
>
|
||||
<span className="font-medium text-foreground">{domain}</span>
|
||||
<button
|
||||
onClick={() => handleRemoveDomain(domain)}
|
||||
className="ml-1 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
{sandbox?.allowedDomains.length === 0 && (
|
||||
<div className="text-sm text-muted-foreground italic">
|
||||
{m.no_custom_domains_allowed()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Pending Domains Section */}
|
||||
<Card className="border-orange-500/20 bg-orange-500/5">
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<ShieldAlert className="w-5 h-5 text-orange-500" />
|
||||
<CardTitle>{m.pending_domain_approvals()}</CardTitle>
|
||||
</div>
|
||||
<CardDescription>{m.pending_domains_description()}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{sandbox?.pendingDomains && sandbox.pendingDomains.length > 0 ? (
|
||||
<div className="divide-y divide-border">
|
||||
{sandbox.pendingDomains.map((domain: string) => (
|
||||
<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-foreground bg-muted px-2 py-1 rounded break-all">
|
||||
{domain}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 border-emerald-500/20 text-emerald-600 hover:bg-emerald-500/10 hover:text-emerald-600 dark:text-emerald-400 dark:hover:bg-emerald-500/20"
|
||||
onClick={() => handleApproveDomain(domain)}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<Check className="w-4 h-4 mr-1.5" />
|
||||
{m.approve()}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 border-destructive/20 text-destructive hover:bg-destructive/10"
|
||||
onClick={() => handleDeletePendingDomain(domain)}
|
||||
disabled={isUpdating || !isNetworkSandboxEnabled}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-1.5" />
|
||||
{m.delete()}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-sm text-muted-foreground italic py-2">
|
||||
{m.no_pending_domains()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{m.filesystem_restriction()}</CardTitle>
|
||||
<CardDescription>{m.filesystem_restriction_description()}</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user