import type { AgentSseApprovalPayload, AgentSseCompletePayload } from '../agent-sse.js'; import type { ToolCall } from '../types.js'; import { type AgentRunOutput, type AgentRunRequest, type AgentToolResult } from './agent-run.js'; /** * Run status. While the run is paused awaiting client tools (no resolver) or an * approval decision, status stays `'running'` and `pendingClientTools` / * `pendingApproval` are populated — the UI renders the prompt and calls * `respond` / `approve` / `reject` to continue the same logical run. */ export type AgentRunStatus = 'idle' | 'running' | 'complete' | 'error'; export interface UseAgentRunOptions { /** * Turn a run/resume intent into the streaming SSE `Response`. The app owns * the endpoint and request-body shape (only its route can reconstruct the * server-side message history); typically `fetch(endpoint, { ..., signal })`. */ request: (req: AgentRunRequest, signal: AbortSignal) => Promise; /** * Optional client-tool resolver. When set, a run that pauses awaiting client * tools auto-executes them and resumes; omit it to surface * `pendingClientTools` and resume manually via `respond`. */ clientTools?: (call: ToolCall) => unknown | Promise; onComplete?: (data: AgentSseCompletePayload) => void; onError?: (message: string) => void; /** Fired for any SSE event outside the standard protocol vocabulary (e.g. a * server-issued `run_started` carrying a correlation `runId`). Forwarded * directly to `readAgentStream`'s `onAppEvent` callback. */ onAppEvent?: (event: string, data: unknown) => void; } export interface UseAgentRunResult { status: AgentRunStatus; /** Renderable transcript, accumulated across the run and every resume. */ outputs: AgentRunOutput[]; /** Client-tool calls awaiting a browser round-trip (empty when auto-resolved). */ pendingClientTools: ToolCall[]; /** The approval gate the run parked on, or `null`. */ pendingApproval: AgentSseApprovalPayload | null; error: string | null; /** Start a fresh run, resetting the transcript. */ run: (input: TInput) => Promise; /** Resume a client-tool pause with results gathered by hand. */ respond: (results: AgentToolResult[]) => Promise; /** Approve the pending approval gate and resume. */ approve: (toolCallId: string) => Promise; /** Reject the pending approval gate and resume. */ reject: (toolCallId: string) => Promise; /** Abort any in-flight stream and return to `idle`. */ reset: () => void; } /** * React client runtime for the named-event agent-SSE protocol. Drives * `readAgentStream` (via the framework-free `driveAgentRun`), accumulates the * transcript, tracks run status, and surfaces pending client-tool calls and * approval requests with imperative `run` / `respond` / `approve` / `reject`. * * Lives behind the `@gemstack/ai-sdk/react` subpath so the main entry stays * runtime-agnostic. * * @example * const { status, outputs, run } = useAgentRun({ * request: (req, signal) => * fetch('/api/agent', { method: 'POST', body: JSON.stringify(req), signal }), * }) * // */ export declare function useAgentRun(options: UseAgentRunOptions): UseAgentRunResult; //# sourceMappingURL=useAgentRun.d.ts.map