import type { Agent, AgentResponse, Message } from "../types.js"; import { type RunResumeSessionManager } from "../runtime/index.js"; import { type AgUiBeforeStream } from "../service/before-stream.js"; import { type AgUiResumeValue } from "./tool-shared.js"; export { type AgUiContextItem, AgUiContextItemSchema, type AgUiInjectedTool, AgUiInjectedToolSchema, type AgUiRequest, AgUiRequestSchema, } from "./host-support.js"; /** * Payload handed to {@link AgUiHandlerOptions.onComplete} after an AG-UI run * streams to completion successfully — the server-side counterpart to the * client's `useConversationChat` persistence path. Lets an application persist * the finalized conversation without reconstructing it from the SSE stream. */ export interface AgUiCompletion { agentId: string; threadId: string; runId: string; /** * The finalized messages this run produced (the assistant turn plus any tool * messages), as returned by the agent's own `onFinish`. */ messages: Message[]; /** The messages sent to the agent for this run (after `beforeStream`). */ inputMessages: Message[]; /** The full finalized response (text, toolCalls, usage, metadata). */ response: AgentResponse; } /** * Called once after a successful AG-UI run with the finalized conversation. * * Semantics: * - Fires exactly once, and only on success (a run that produced a finalized * response). It does NOT fire on error, or when the client disconnects before * the stream finishes. * - Runs after the SSE stream has been fully flushed and closed, so a slow or * throwing persistence never delays or corrupts the response stream. * - A rejected/throwing callback is caught and logged (never rethrown into the * stream); the run is still considered complete. */ export type AgUiOnComplete = (completion: AgUiCompletion) => void | Promise; /** Options accepted by AG-UI handler. */ export interface AgUiHandlerOptions { context?: Record | ((request: Request) => Record | Promise>); sessionManager?: RunResumeSessionManager; beforeStream?: AgUiBeforeStream; /** * Called once after a successful run with the finalized conversation, so an * application can persist it server-side. See {@link AgUiOnComplete} for the * success / error / disconnect semantics. */ onComplete?: AgUiOnComplete; } /** Public API contract for AG-UI handler config with agent. */ export interface AgUiHandlerConfigWithAgent extends AgUiHandlerOptions { agent: Agent; } /** Handler for create AG-UI. */ export declare function createAgUiHandler(agentId: string, options?: AgUiHandlerOptions): (requestOrCtx: unknown) => Promise; /** Handler for create AG-UI. */ export declare function createAgUiHandler(config: AgUiHandlerConfigWithAgent, options?: AgUiHandlerOptions): (requestOrCtx: unknown) => Promise; //# sourceMappingURL=handler.d.ts.map