/** The card that asks the person to approve or deny one action of the assistant, and the dock that keeps it in view. */ import { useMemo } from 'react'; import { tr } from '../lib/i18n'; import { Btn, Icon } from './ui'; import { askQuestion, askSub, askIcon } from '../lib/ask'; import { resolveTool, useStore } from '../lib/store'; import { pendingApprovals } from '../lib/approvals'; import { QuestionCard } from './QuestionCard'; import type { AgentAsk } from '../lib/agent-ask'; import type { ToolCall } from '../lib/types'; const NO_ASKS: AgentAsk[] = []; export const SCOPE: Record = { read: { label: 'Reads', tone: 'plain' }, write: { label: 'Writes', tone: 'warn' }, shell: { label: 'Runs a command', tone: 'warn' }, connected: { label: 'Connected tool', tone: 'info' }, }; /** The one place the Approve and Deny buttons live. Chat shows it in the dock above the box, not in the middle of a long reply (#4725). */ export function ApprovalCard({ messageId, tool: t }: { messageId: string; tool: ToolCall; }) { const scope = SCOPE[t.scope]; if (t.ask) return

{askQuestion(t.ask)}

{askSub(t.ask) ?

{askSub(t.ask)}

: null}
resolveTool(messageId, t.id, false)}>{tr("Deny")} resolveTool(messageId, t.id, true)}>{tr("Approve")}
{tr("Details")}
{t.preview}
; return
{tr(t.verb ?? t.name)}{tr(scope.label)}
{t.preview}

{tr(t.effect)}

{t.result ?

{t.result}

: null}
{t.target ? {t.target} : null}
{tr("Needs your approval")} resolveTool(messageId, t.id, false)}>{tr("Deny")} resolveTool(messageId, t.id, true)}>{tr("Approve")}
; } /** * Keeps an approval where the person is looking. A reply can run to many screens; the card used to sit above its text, so a * person reading the end of it never saw that the assistant had stopped to ask. The dock sits directly above the message box and * does not scroll with the conversation. Where the card was, the conversation says that it is waiting. */ export function ApprovalDock({ sessionId }: { sessionId: string | undefined; }) { const session = useStore(s => s.sessions.find(x => x.id === sessionId)); const items = useMemo(() => pendingApprovals(session), [session]); const asks = useStore(s => (sessionId ? s.agentAsks[sessionId] : undefined)) ?? NO_ASKS; if (!items.length && !asks.length) return null; return
{asks.map(a => )} {items.map(({ messageId, tool }) => )}
; }