okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1306424be
main
1/** The card that asks the person to approve or deny one action of the assistant, and the dock that keeps it in view. */ 2import { useMemo } from 'react' ; 3import { tr } from '../lib/i18n' ; 4import { Btn , Icon } from './ui' ; 5import { askQuestion , askSub , askIcon } from '../lib/ask' ; 6import { resolveTool , useStore } from '../lib/store' ; 7import { pendingApprovals } from '../lib/approvals' ; 8import { QuestionCard } from './QuestionCard' ; 9import type { AgentAsk } from '../lib/agent-ask' ; 10import type { ToolCall } from '../lib/types' ; 11 12const NO_ASKS :AgentAsk [] = []; 13export const SCOPE :Record < ToolCall [ 'scope' ], { 14label :string ; 15tone :'plain' | 'info' | 'warn' ; 16}> = { 17read :{ label :'Reads' , tone :'plain' }, 18write :{ label :'Writes' , tone :'warn' }, 19shell :{ label :'Runs a command' , tone :'warn' }, 20connected :{ label :'Connected tool' , tone :'info' }, 21}; 22 23/** 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). */ 24export function ApprovalCard ({ messageId, tool :t } :{ 25messageId :string ; 26tool :ToolCall ; 27}) { 28const scope = SCOPE [ t . scope ]; 29if ( t . ask ) 30return < section className = "askcard" data-state = { t . state } aria-label = { tr ( askQuestion ( t . ask ))}> 31< div className = "askcard__top" >< span className = "askcard__icon" >< Icon name = { askIcon ( t . ask )} size = { 18 }/></ span > 32< div className = "askcard__text" >< p className = "askcard__q" >{ askQuestion ( t . ask )}</ p >{ askSub ( t . ask ) ?< p className = "askcard__why" title = { askSub ( t . ask )}>{ askSub ( t . ask )}</ p > :null }</ div > 33< div className = "askcard__acts" >< Btn size = "sm" onClick = {() => resolveTool ( messageId , t . id , false )}>{ tr ( "Deny" )}</ Btn >< Btn variant = "primary" size = "sm" onClick = {() => resolveTool ( messageId , t . id , true )}>{ tr ( "Approve" )}</ Btn ></ div ></ div > 34< details className = "askcard__details" >< summary >< Icon name = "chevron" size = { 11 }/>{ tr ( "Details" )}</ summary >< pre >{ t . preview }</ pre ></ details > 35</ section >; 36return < section className = "toolcard toolcard--compact" data-state = { t . state } aria-label = { t . name }> 37< details className = "toolcard__disclosure" > 38< summary >< Icon name = { t . scope === 'shell' ?'bolt' :'tool' } size = { 17 }/>< span className = "toolcard__title" >{ tr ( t . verb ?? t . name )}</ span >< span className = "toolcard__scope xs muted" >{ tr ( scope . label )}</ span >< Icon name = "chevron" className = "toolcard__chevron" size = { 15 }/></ summary > 39< div className = "toolcard__body" >< code className = "toolcard__preview" >{ t . preview }</ code >< p className = "small muted" >{ tr ( t . effect )}</ p >{ t . result ?< p className = "small" >{ t . result }</ p > :null }</ div > 40</ details > 41{ t . target ?< code className = "toolcard__what" title = { t . target }>{ t . target }</ code > :null } 42< div className = "toolcard__quick-actions" >< span className = "xs muted" >{ tr ( "Needs your approval" )}</ span >< Btn size = "sm" onClick = {() => resolveTool ( messageId , t . id , false )}>{ tr ( "Deny" )}</ Btn >< Btn variant = "primary" size = "sm" icon = "check" onClick = {() => resolveTool ( messageId , t . id , true )}>{ tr ( "Approve" )}</ Btn ></ div > 43</ section >; 44} 45 46/** 47* 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 48* person reading the end of it never saw that the assistant had stopped to ask. The dock sits directly above the message box and 49* does not scroll with the conversation. Where the card was, the conversation says that it is waiting. 50*/ 51export function ApprovalDock ({ sessionId} :{ 52sessionId :string | undefined ; 53}) { 54const session = useStore ( s => s . sessions . find ( x => x . id === sessionId )); 55const items = useMemo (() => pendingApprovals ( session ), [ session ]); 56const asks = useStore ( s => ( sessionId ?s . agentAsks [ sessionId ] :undefined )) ?? NO_ASKS ; 57if ( ! items . length && ! asks . length ) 58return null ; 59return < section className = "approvaldock" role = "group" aria-label = { tr ( "Waiting for your answer" )} data-count = { items . length }> 60{ asks . map ( a => < QuestionCard key = { a . callId } sessionId = { sessionId ! } ask = { a }/>)} 61{ items . map (({ messageId, tool}) => < ApprovalCard key = { tool . id } messageId = { messageId } tool = { tool }/>)} 62</ section >; 63}