import type { ChatMessage, ChatCompletionChunk, ContentPart, AskUserPayload, MissionPreviewPayload, VaultPreviewPayload, OpenFilePayload, NavigateToPayload, OpenTabPayload, ToolCallEvent, ChatSuggestion, RuntimeSandboxOptions } from "@polpo-ai/sdk"; export interface UseChatOptions { /** Target a specific agent for direct conversation. Omit for orchestrator mode. */ agent?: string; /** Target a project-level loop assigned to the selected agent. */ loop?: string; /** Optional per-request model override for the selected agent. */ model?: string; /** Optional runtime sandbox policy for chat requests. */ sandbox?: RuntimeSandboxOptions; /** Keep execution alive and resume automatically when its SSE connection drops. */ durable?: boolean; /** Resume an existing session by ID. If omitted, the server auto-creates or reuses one (30-min window). */ sessionId?: string; /** Called on each streaming text chunk. */ onChunk?: (chunk: ChatCompletionChunk) => void; /** Called when the stream completes. */ onFinish?: (text: string) => void; /** Called on error. */ onError?: (error: Error) => void; /** Called after each stream update — useful for scroll-to-bottom. */ onUpdate?: () => void; /** Called when a new session is created (first message in a new chat). */ onSessionCreated?: (sessionId: string) => void; /** Called when the agent asks clarifying questions (legacy orchestrator mode). */ onAskUser?: (payload: AskUserPayload) => void; /** Called when suggested next messages are available. */ onSuggestions?: (suggestions: ChatSuggestion[]) => void; /** Called when the agent proposes a mission for review. */ onMissionPreview?: (payload: MissionPreviewPayload) => void; /** Called when the agent proposes a vault entry. */ onVaultPreview?: (payload: VaultPreviewPayload) => void; /** Called when the agent wants to open a file. */ onOpenFile?: (payload: OpenFilePayload) => void; /** Called when the agent wants to navigate the UI. */ onNavigateTo?: (payload: NavigateToPayload) => void; /** Called when the agent wants to open a URL. */ onOpenTab?: (payload: OpenTabPayload) => void; /** Called when a tool call event is emitted. */ onToolCall?: (toolCall: ToolCallEvent) => void; } export type ChatStatus = "idle" | "streaming" | "reconnecting" | "loading" | "error"; export interface SendMessageOptions { /** Assigned skills to apply explicitly to this message. Additive, not restrictive. */ skills?: string[]; } /** A pending client-side tool call that needs a result from the client. */ export interface PendingToolCall { /** Tool call ID from the LLM. */ toolCallId: string; /** Tool name (e.g. "ask_user_question"). */ toolName: string; /** Parsed arguments from the LLM. */ arguments: Record; } export interface UseChatReturn { /** * All messages in the current session (user + assistant). * During streaming, the last assistant message updates in-place with accumulating * content and tool calls — no separate `streamingText` needed. */ messages: ChatMessage[]; /** Send a message (text or multimodal content parts). Streams the response automatically. */ sendMessage: (content: string | ContentPart[], options?: SendMessageOptions) => Promise; /** Send a tool result back to the server. Used for client-side tools (e.g. ask_user_question). */ sendToolResult: (toolCallId: string, toolName: string, result: string) => Promise; /** Continue a pending client tool in direct chat or an explicit durable Project Loop. */ continueToolResult: (toolCallId: string, result: string | ContentPart[], options: { loop?: string; idempotencyKey: string; }) => Promise; /** Current session ID. `null` until the first response from the server. */ sessionId: string | null; /** Monotonic server transcript version used by deterministic continuations. */ sessionVersion: number | null; /** Set the session ID manually (e.g. to resume a different session). Loads its messages. */ setSessionId: (id: string | null) => Promise; /** Start a new session. Clears messages and session ID. */ newSession: () => void; /** Current status. */ status: ChatStatus; /** Last error, if any. */ error: Error | null; /** Whether a response is currently streaming. */ isStreaming: boolean; /** Client-side tool call awaiting a result (e.g. ask_user_question). null when none pending. */ pendingToolCall: PendingToolCall | null; /** Suggested next messages for the latest assistant response. */ suggestions: ChatSuggestion[]; /** Active durable run identifier, once accepted by the server. */ runId: string | null; /** Last fully processed durable stream cursor. */ lastEventId: string | null; /** Explicitly cancel the active run. */ abort: () => void; /** Close this subscriber while allowing a durable run to continue. */ detach: () => void; /** Explicitly cancel the active run and wait for acknowledgement. */ cancel: (reason?: string) => Promise; } export declare function useChat(options?: UseChatOptions): UseChatReturn; //# sourceMappingURL=use-chat.d.ts.map