diff --git a/console/src/features/tools/tools-page.tsx b/console/src/features/tools/tools-page.tsx index 7862d6e..5b79f8e 100644 --- a/console/src/features/tools/tools-page.tsx +++ b/console/src/features/tools/tools-page.tsx @@ -1,11 +1,11 @@ import { useMemo, useState } from 'react' import { Plug } from 'lucide-react' -import { Badge, type BadgeTone, Card, EmptyState, Segmented } from '@/components/ui' +import { Badge, Button, type BadgeTone, Card, EmptyState, Input, Segmented, toast } from '@/components/ui' import { useResource } from '@/lib/backup' import { DISPOSITION_TONE as DISP_TONE } from '@/lib/disposition' import { type MessageKey, useTranslation } from '@/lib/i18n' import { type Disposition, type ToolCall, type Trust } from './data' -import { useToolCalls } from './use-tools' +import { confirmToolCall, proposeToolCall, useToolCalls, type ToolCallProposal } from './use-tools' // 色调单一真源 @/lib/disposition(M29);文案按本页语境留在 tools.* 命名空间。 const DISP_KEY: Record = { @@ -31,8 +31,15 @@ export function ToolsPage() { { value: 'allow', label: t('tools.filter.allow') }, ] const [filter, setFilter] = useState('all') + const [toolName, setToolName] = useState('echo') + const [argumentsText, setArgumentsText] = useState('{"text":"console test"}') + const [sessionId] = useState(() => `tools:${crypto.randomUUID()}`) + const [proposal, setProposal] = useState(null) + const [result, setResult] = useState('') + const [busy, setBusy] = useState(false) // 三态:真后端工具流水 → 真;否则用户载入的备份演示数据;都没有 → 诚实空态(绝不自动塞假数据)。 - const live = useToolCalls().data + const toolCalls = useToolCalls() + const live = toolCalls.data const backup = useResource('tools') const calls = live && live.length > 0 ? live : backup const rows = useMemo( @@ -44,14 +51,91 @@ export function ToolsPage() { ) const held = calls.filter((c) => c.decision !== 'allow').length + const createProposal = async () => { + let args: Record + try { + const parsed: unknown = JSON.parse(argumentsText) + if (!parsed || Array.isArray(parsed) || typeof parsed !== 'object') throw new Error() + args = parsed as Record + } catch { + toast(t('tools.execute.invalid_args')) + return + } + setBusy(true) + setResult('') + try { + setProposal(await proposeToolCall(toolName.trim(), args, sessionId)) + } catch (error) { + toast(error instanceof Error ? error.message : t('tools.execute.failed')) + } finally { + setBusy(false) + } + } + + const confirmProposal = async () => { + if (!proposal) return + setBusy(true) + try { + const response = await confirmToolCall(proposal.action_token, proposal.args, sessionId) + setResult(response.summary) + if (response.ok) { + setProposal(null) + await toolCalls.refetch() + } + } catch (error) { + toast(error instanceof Error ? error.message : t('tools.execute.failed')) + } finally { + setBusy(false) + } + } + + const executionPanel = ( + +
+ +