/** * use-agent — agent run state for the TUI. * * Drives `Agent.chat(input, signal, approveTool, permissionLevel, onStep)`, * which (in TUI mode) opts into token streaming — the loop emits `text_delta` * steps as tokens arrive. Those accumulate into `streamingText` (rendered live * in the message area, since Ink `` freezes completed entries); on a * tool call or turn end the accumulated text is committed to the feed history. * ESC/Ctrl+C calls `agent.abort()`. * * `approveTool` runs inside the detached `runAgentLoop` promise, so it must * pause and wait for the user to press y/n in ``. This hook * owns that bridge: it stores the pending resolver in a ref (stable across * renders) and the pending prompt's view in state (so the component re-renders). */ import { Agent } from '../../agent.js'; import type { PermissionLevel, CumulativeUsage } from '../../../../core/types.js'; import type { Todo } from '../components/goal-status.js'; import type { FeedApi } from './use-feed.js'; export interface PendingPermissionView { toolName: string; args: Record; } export interface StreamingToolView { name: string; args: Record; output: string; } export interface AgentApi { isRunning: boolean; pendingPermission: PendingPermissionView | null; /** Live, accumulating assistant text while streaming (empty when idle). */ streamingText: string; /** Live, accumulating tool output while a tool runs (null when idle). */ streamingTool: StreamingToolView | null; /** Cumulative token/cost usage across the session (for the footer). */ usage: CumulativeUsage; /** Last turn's input size in tokens — the current context-window usage. */ contextTokens: number; /** Persistent todo list (updated by manage_todos tool; null when none). */ latestTodos: Todo[] | null; submit: (input: string) => Promise; resolvePermission: (approve: boolean) => void; abort: () => void; resetTodos: () => void; /** Restore the persistent todo panel (e.g. from a resumed session). */ restoreTodos: (todos: Todo[] | null) => void; } export interface UseAgentArgs { agent: Agent; feed: FeedApi; permissionLevel?: PermissionLevel; } export declare function useAgent({ agent, feed, permissionLevel }: UseAgentArgs): AgentApi;