@octavus/client-sdk 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -396,6 +396,7 @@ declare class OctavusChat {
|
|
|
396
396
|
private _clientToolAbortController;
|
|
397
397
|
private _serverToolResults;
|
|
398
398
|
private _pendingExecutionId;
|
|
399
|
+
private _readyToContinue;
|
|
399
400
|
private listeners;
|
|
400
401
|
constructor(options: OctavusChatOptions);
|
|
401
402
|
get messages(): UIMessage[];
|
package/dist/index.js
CHANGED
|
@@ -194,6 +194,9 @@ var OctavusChat = class {
|
|
|
194
194
|
_serverToolResults = [];
|
|
195
195
|
// Execution ID for continuation (from client-tool-request event)
|
|
196
196
|
_pendingExecutionId = null;
|
|
197
|
+
// Flag indicating automatic client tools have completed and are ready to continue
|
|
198
|
+
// We wait for the finish event before actually continuing to avoid race conditions
|
|
199
|
+
_readyToContinue = false;
|
|
197
200
|
// Listener sets for reactive frameworks
|
|
198
201
|
listeners = /* @__PURE__ */ new Set();
|
|
199
202
|
constructor(options) {
|
|
@@ -346,6 +349,7 @@ var OctavusChat = class {
|
|
|
346
349
|
this._completedToolResults = [];
|
|
347
350
|
this._serverToolResults = [];
|
|
348
351
|
this._pendingExecutionId = null;
|
|
352
|
+
this._readyToContinue = false;
|
|
349
353
|
this.updatePendingClientToolsCache();
|
|
350
354
|
try {
|
|
351
355
|
for await (const event of this.transport.trigger(triggerName, processedInput)) {
|
|
@@ -485,6 +489,7 @@ var OctavusChat = class {
|
|
|
485
489
|
this._completedToolResults = [];
|
|
486
490
|
this._serverToolResults = [];
|
|
487
491
|
this._pendingExecutionId = null;
|
|
492
|
+
this._readyToContinue = false;
|
|
488
493
|
this.updatePendingClientToolsCache();
|
|
489
494
|
this.transport.stop();
|
|
490
495
|
const state = this.streamingState;
|
|
@@ -824,6 +829,9 @@ var OctavusChat = class {
|
|
|
824
829
|
if (event.finishReason === "client-tool-calls") {
|
|
825
830
|
if (this._pendingToolsByCallId.size > 0) {
|
|
826
831
|
this.setStatus("awaiting-input");
|
|
832
|
+
} else if (this._readyToContinue) {
|
|
833
|
+
this._readyToContinue = false;
|
|
834
|
+
void this.continueWithClientToolResults();
|
|
827
835
|
}
|
|
828
836
|
return;
|
|
829
837
|
}
|
|
@@ -1038,7 +1046,7 @@ var OctavusChat = class {
|
|
|
1038
1046
|
}
|
|
1039
1047
|
}
|
|
1040
1048
|
if (this._pendingToolsByCallId.size === 0 && this._completedToolResults.length > 0) {
|
|
1041
|
-
|
|
1049
|
+
this._readyToContinue = true;
|
|
1042
1050
|
}
|
|
1043
1051
|
}
|
|
1044
1052
|
};
|
|
@@ -1271,6 +1279,7 @@ function createSocketTransport(options) {
|
|
|
1271
1279
|
async *trigger(triggerName, input) {
|
|
1272
1280
|
await ensureConnected();
|
|
1273
1281
|
eventQueue = [];
|
|
1282
|
+
eventResolver = null;
|
|
1274
1283
|
isStreaming = true;
|
|
1275
1284
|
socket.send(
|
|
1276
1285
|
JSON.stringify({
|
|
@@ -1304,6 +1313,7 @@ function createSocketTransport(options) {
|
|
|
1304
1313
|
async *continueWithToolResults(executionId, toolResults) {
|
|
1305
1314
|
await ensureConnected();
|
|
1306
1315
|
eventQueue = [];
|
|
1316
|
+
eventResolver = null;
|
|
1307
1317
|
isStreaming = true;
|
|
1308
1318
|
socket.send(
|
|
1309
1319
|
JSON.stringify({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chat.ts","../src/files.ts","../src/stream/reader.ts","../src/transports/types.ts","../src/transports/http.ts","../src/transports/socket.ts","../src/index.ts"],"sourcesContent":["import {\n generateId,\n threadForPart,\n isFileReferenceArray,\n OctavusError,\n type UIMessage,\n type UIMessagePart,\n type UITextPart,\n type UIReasoningPart,\n type UIToolCallPart,\n type UIOperationPart,\n type UISourcePart,\n type UIFilePart,\n type UIObjectPart,\n type DisplayMode,\n type StreamEvent,\n type FileReference,\n type PendingToolCall,\n type ToolResult,\n} from '@octavus/core';\nimport type { Transport } from './transports/types';\nimport { uploadFiles, type UploadFilesOptions } from './files';\n\n/** Block types that are internal operations (not LLM-driven) */\nconst OPERATION_BLOCK_TYPES = new Set(['set-resource', 'serialize-thread', 'generate-image']);\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type ChatStatus = 'idle' | 'streaming' | 'error' | 'awaiting-input';\n\n/**\n * Context provided to client tool handlers.\n */\nexport interface ClientToolContext {\n /** Unique identifier for this tool call */\n toolCallId: string;\n /** Name of the tool being called */\n toolName: string;\n /** Signal for cancellation if user stops generation */\n signal: AbortSignal;\n}\n\n/**\n * Handler function for client-side tool execution.\n * Can be:\n * - An async function that executes automatically and returns a result\n * - The string 'interactive' to indicate the tool requires user interaction\n */\nexport type ClientToolHandler =\n | ((args: Record<string, unknown>, ctx: ClientToolContext) => Promise<unknown>)\n | 'interactive';\n\n/**\n * Interactive tool call awaiting user interaction.\n * The `submit` and `cancel` methods are pre-bound to this tool call's ID.\n */\nexport interface InteractiveTool {\n /** Unique identifier for this tool call */\n toolCallId: string;\n /** Name of the tool being called */\n toolName: string;\n /** Arguments passed to the tool */\n args: Record<string, unknown>;\n /**\n * Submit a result for this tool call.\n * Call this when the user has provided input.\n *\n * @param result - The result from user interaction\n */\n submit: (result: unknown) => void;\n /**\n * Cancel this tool call with an optional reason.\n * Call this when the user dismisses the UI without providing input.\n *\n * @param reason - Optional reason for cancellation (default: 'User cancelled')\n */\n cancel: (reason?: string) => void;\n}\n\n/**\n * Internal pending tool state (before binding submit/cancel).\n */\ninterface PendingToolState {\n toolCallId: string;\n toolName: string;\n args: Record<string, unknown>;\n source?: 'llm' | 'block';\n outputVariable?: string;\n blockIndex?: number;\n}\n\n/**\n * Input for creating a user message.\n * Supports text content, structured object content, and file attachments.\n */\nexport interface UserMessageInput {\n /**\n * Content of the message. Can be:\n * - string: Creates a text part\n * - object: Creates an object part (uses `type` field as typeName if present)\n */\n content?: string | Record<string, unknown>;\n /**\n * File attachments (shorthand). Can be:\n * - FileList: From file input element (will be uploaded via uploadFiles)\n * - File[]: Array of File objects (will be uploaded via uploadFiles)\n * - FileReference[]: Already uploaded files (used directly)\n */\n files?: FileList | File[] | FileReference[];\n}\n\nexport interface OctavusChatOptions {\n /**\n * Transport for streaming events.\n * Use `createHttpTransport` for HTTP/SSE or `createSocketTransport` for WebSocket/SockJS.\n */\n transport: Transport;\n\n /**\n * Function to request upload URLs from the platform.\n * Required if you want to use file uploads with FileList/File[].\n *\n * @example\n * ```typescript\n * requestUploadUrls: async (files) => {\n * const response = await fetch('/api/upload-urls', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, files }),\n * });\n * return response.json();\n * }\n * ```\n */\n requestUploadUrls?: UploadFilesOptions['requestUploadUrls'];\n\n /**\n * Client-side tool handlers.\n * Register handlers for tools that should execute in the browser.\n *\n * - If a tool has a handler function: executes automatically\n * - If a tool is marked as 'interactive': appears in `pendingClientTools` with bound `submit()`/`cancel()`\n *\n * @example Automatic client tool\n * ```typescript\n * clientTools: {\n * 'get-browser-location': async () => {\n * const pos = await new Promise((resolve, reject) => {\n * navigator.geolocation.getCurrentPosition(resolve, reject);\n * });\n * return { lat: pos.coords.latitude, lng: pos.coords.longitude };\n * },\n * }\n * ```\n *\n * @example Interactive client tool (user input required)\n * ```typescript\n * clientTools: {\n * 'request-feedback': 'interactive',\n * }\n * // Then render UI based on pendingClientTools['request-feedback']\n * // and call tool.submit(result) or tool.cancel()\n * ```\n */\n clientTools?: Record<string, ClientToolHandler>;\n\n /** Initial messages (for session refresh) */\n initialMessages?: UIMessage[];\n /**\n * Callback when an error occurs.\n * Receives an OctavusError with structured error information.\n *\n * @example\n * ```typescript\n * onError: (error) => {\n * console.error('Chat error:', {\n * type: error.errorType,\n * message: error.message,\n * retryable: error.retryable,\n * provider: error.provider,\n * });\n *\n * // Handle specific error types\n * if (isRateLimitError(error)) {\n * showRetryButton(error.retryAfter);\n * }\n * }\n * ```\n */\n onError?: (error: OctavusError) => void;\n /** Callback when streaming finishes successfully */\n onFinish?: () => void;\n /** Callback when streaming is stopped by user */\n onStop?: () => void;\n /** Callback when a resource is updated */\n onResourceUpdate?: (name: string, value: unknown) => void;\n}\n\n// =============================================================================\n// Internal Types\n// =============================================================================\n\ninterface BlockState {\n blockId: string;\n blockName: string;\n blockType: string;\n display: DisplayMode;\n description?: string;\n outputToChat: boolean;\n thread?: string;\n reasoning: string;\n text: string;\n toolCalls: Map<string, UIToolCallPart>;\n}\n\ninterface StreamingState {\n messageId: string;\n parts: UIMessagePart[];\n activeBlock: BlockState | null;\n blocks: Map<string, BlockState>;\n currentTextPartIndex: number | null;\n currentReasoningPartIndex: number | null;\n currentObjectPartIndex: number | null;\n accumulatedJson: string;\n}\n\ntype Listener = () => void;\n\n// =============================================================================\n// Helpers\n// =============================================================================\n\n/**\n * Create a user message from input with optional file attachments.\n * Parts order: files first (for vision models), then content (text or object).\n */\nfunction createUserMessage(input: UserMessageInput, files?: FileReference[]): UIMessage {\n const parts: UIMessagePart[] = [];\n\n // Add file parts first (vision models expect images before text)\n if (files && files.length > 0) {\n for (const file of files) {\n parts.push({\n type: 'file',\n id: file.id,\n mediaType: file.mediaType,\n url: file.url,\n filename: file.filename,\n size: file.size,\n });\n }\n }\n\n // Add content part after files\n if (input.content !== undefined) {\n if (typeof input.content === 'string') {\n // String content → text part\n parts.push({ type: 'text', text: input.content, status: 'done' });\n } else {\n // Object content → object part\n // Use the object's `type` field as typeName if present, otherwise fallback to 'object'\n const typeName = (input.content as { type?: string }).type ?? 'object';\n parts.push({\n type: 'object',\n id: generateId(),\n typeName,\n object: input.content,\n status: 'done',\n });\n }\n }\n\n return {\n id: generateId(),\n role: 'user',\n parts,\n status: 'done',\n createdAt: new Date(),\n };\n}\n\n/**\n * Parse partial JSON by fixing incomplete structures (unclosed strings, brackets, braces).\n */\nfunction parsePartialJson(jsonText: string): unknown {\n if (!jsonText.trim()) {\n return undefined;\n }\n\n try {\n return JSON.parse(jsonText) as unknown;\n } catch {\n // Continue to fix incomplete JSON\n }\n\n let fixed = jsonText;\n\n // Count unclosed brackets/braces while tracking string boundaries\n let openBraces = 0;\n let openBrackets = 0;\n let inString = false;\n let escaped = false;\n\n for (const char of fixed) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === '\\\\') {\n escaped = true;\n continue;\n }\n\n if (char === '\"') {\n inString = !inString;\n continue;\n }\n\n if (!inString) {\n if (char === '{') openBraces += 1;\n else if (char === '}') openBraces -= 1;\n else if (char === '[') openBrackets += 1;\n else if (char === ']') openBrackets -= 1;\n }\n }\n\n // Close unclosed structures\n if (inString) {\n fixed += '\"';\n }\n while (openBrackets > 0) {\n fixed += ']';\n openBrackets -= 1;\n }\n while (openBraces > 0) {\n fixed += '}';\n openBraces -= 1;\n }\n\n try {\n return JSON.parse(fixed) as unknown;\n } catch {\n return undefined;\n }\n}\n\nfunction createEmptyStreamingState(): StreamingState {\n return {\n messageId: generateId(),\n parts: [],\n activeBlock: null,\n blocks: new Map(),\n currentTextPartIndex: null,\n currentReasoningPartIndex: null,\n currentObjectPartIndex: null,\n accumulatedJson: '',\n };\n}\n\nfunction buildMessageFromState(state: StreamingState, status: 'streaming' | 'done'): UIMessage {\n return {\n id: state.messageId,\n role: 'assistant',\n parts: [...state.parts],\n status,\n createdAt: new Date(),\n };\n}\n\n// =============================================================================\n// OctavusChat Class\n// =============================================================================\n\n/**\n * Framework-agnostic chat client for Octavus agents.\n * Manages chat state and streaming, allowing reactive frameworks to subscribe to updates.\n *\n * @example HTTP transport (Next.js, etc.)\n * ```typescript\n * import { OctavusChat, createHttpTransport } from '@octavus/client-sdk';\n *\n * const chat = new OctavusChat({\n * transport: createHttpTransport({\n * request: (payload, options) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, ...payload }),\n * signal: options?.signal,\n * }),\n * }),\n * });\n * ```\n *\n * @example Socket transport (WebSocket, SockJS, Meteor)\n * ```typescript\n * import { OctavusChat, createSocketTransport } from '@octavus/client-sdk';\n *\n * const chat = new OctavusChat({\n * transport: createSocketTransport({\n * connect: () => new Promise((resolve, reject) => {\n * const ws = new WebSocket(`wss://api.octavus.ai/stream?sessionId=${sessionId}`);\n * ws.onopen = () => resolve(ws);\n * ws.onerror = () => reject(new Error('Connection failed'));\n * }),\n * }),\n * });\n * ```\n */\nexport class OctavusChat {\n // Private state\n private _messages: UIMessage[];\n private _status: ChatStatus = 'idle';\n private _error: OctavusError | null = null;\n private options: OctavusChatOptions;\n private transport: Transport;\n private streamingState: StreamingState | null = null;\n\n // Client tool state\n // Keyed by toolName -> array of pending tools for that name\n private _pendingToolsByName = new Map<string, PendingToolState[]>();\n // Keyed by toolCallId -> pending tool state (for internal lookup when submitting)\n private _pendingToolsByCallId = new Map<string, PendingToolState>();\n // Cache for React useSyncExternalStore compatibility\n private _pendingClientToolsCache: Record<string, InteractiveTool[]> = {};\n private _completedToolResults: ToolResult[] = [];\n private _clientToolAbortController: AbortController | null = null;\n // Server tool results from mixed server+client tools (for continuation)\n private _serverToolResults: ToolResult[] = [];\n // Execution ID for continuation (from client-tool-request event)\n private _pendingExecutionId: string | null = null;\n\n // Listener sets for reactive frameworks\n private listeners = new Set<Listener>();\n\n constructor(options: OctavusChatOptions) {\n this.options = options;\n this._messages = options.initialMessages ?? [];\n this.transport = options.transport;\n }\n\n // =========================================================================\n // Public Getters\n // =========================================================================\n\n get messages(): UIMessage[] {\n return this._messages;\n }\n\n get status(): ChatStatus {\n return this._status;\n }\n\n /**\n * The current error, if any.\n * Contains structured error information including type, source, and retryability.\n */\n get error(): OctavusError | null {\n return this._error;\n }\n\n /**\n * Pending interactive tool calls keyed by tool name.\n * Each tool has bound `submit()` and `cancel()` methods.\n *\n * @example\n * ```tsx\n * const feedbackTools = pendingClientTools['request-feedback'] ?? [];\n *\n * {feedbackTools.map(tool => (\n * <FeedbackModal\n * key={tool.toolCallId}\n * {...tool.args}\n * onSubmit={(result) => tool.submit(result)}\n * onCancel={() => tool.cancel()}\n * />\n * ))}\n * ```\n */\n get pendingClientTools(): Record<string, InteractiveTool[]> {\n return this._pendingClientToolsCache;\n }\n\n // =========================================================================\n // Subscription Methods (for reactive frameworks)\n // =========================================================================\n\n /**\n * Subscribe to state changes. The callback is called whenever messages, status, or error changes.\n * @returns Unsubscribe function\n */\n subscribe(listener: Listener): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((l) => l());\n }\n\n // =========================================================================\n // Private Setters (notify listeners)\n // =========================================================================\n\n private setMessages(messages: UIMessage[]): void {\n this._messages = messages;\n this.notifyListeners();\n }\n\n private setStatus(status: ChatStatus): void {\n this._status = status;\n this.notifyListeners();\n }\n\n private setError(error: OctavusError | null): void {\n this._error = error;\n this.notifyListeners();\n }\n\n private updatePendingClientToolsCache(): void {\n const cache: Record<string, InteractiveTool[]> = {};\n for (const [toolName, tools] of this._pendingToolsByName.entries()) {\n cache[toolName] = tools.map((tool) => ({\n toolCallId: tool.toolCallId,\n toolName: tool.toolName,\n args: tool.args,\n submit: (result: unknown) => this.submitToolResult(tool.toolCallId, result),\n cancel: (reason?: string) =>\n this.submitToolResult(tool.toolCallId, undefined, reason ?? 'User cancelled'),\n }));\n }\n this._pendingClientToolsCache = cache;\n }\n\n // =========================================================================\n // Public Methods\n // =========================================================================\n\n /**\n * Trigger the agent and optionally add a user message to the chat.\n *\n * @param triggerName - The trigger name defined in the agent's protocol.yaml\n * @param input - Input parameters for the trigger (variable substitutions)\n * @param options.userMessage - If provided, adds a user message to the chat before triggering\n *\n * @example Send a text message\n * ```typescript\n * await chat.send('user-message',\n * { USER_MESSAGE: message },\n * { userMessage: { content: message } }\n * );\n * ```\n *\n * @example Send a message with file attachments\n * ```typescript\n * await chat.send('user-message',\n * { USER_MESSAGE: message, FILES: fileRefs },\n * { userMessage: { content: message, files: fileRefs } }\n * );\n * ```\n */\n async send(\n triggerName: string,\n input?: Record<string, unknown>,\n sendOptions?: { userMessage?: UserMessageInput },\n ): Promise<void> {\n this.transport.stop();\n\n let fileRefs: FileReference[] | undefined;\n if (sendOptions?.userMessage?.files) {\n const files = sendOptions.userMessage.files;\n if (isFileReferenceArray(files)) {\n fileRefs = files;\n } else if (this.options.requestUploadUrls) {\n fileRefs = await uploadFiles(files, {\n requestUploadUrls: this.options.requestUploadUrls,\n });\n } else {\n throw new Error(\n 'File upload requires requestUploadUrls option. Either provide FileReference[] or configure requestUploadUrls.',\n );\n }\n }\n\n // Auto-upload FILES in trigger input if needed\n let processedInput = input;\n if (input?.FILES !== undefined && !isFileReferenceArray(input.FILES)) {\n if (this.options.requestUploadUrls) {\n const inputFiles = input.FILES as FileList | File[];\n const uploadedRefs =\n fileRefs ??\n (await uploadFiles(inputFiles, {\n requestUploadUrls: this.options.requestUploadUrls,\n }));\n processedInput = { ...input, FILES: uploadedRefs };\n fileRefs = fileRefs ?? uploadedRefs;\n }\n }\n\n // Optimistic UI: add user message before server responds\n if (sendOptions?.userMessage !== undefined) {\n const userMsg = createUserMessage(sendOptions.userMessage, fileRefs);\n this.setMessages([...this._messages, userMsg]);\n }\n\n this.setStatus('streaming');\n this.setError(null);\n this.streamingState = createEmptyStreamingState();\n\n // Clear any previous client tool state\n this._pendingToolsByName.clear();\n this._pendingToolsByCallId.clear();\n this._completedToolResults = [];\n this._serverToolResults = [];\n this._pendingExecutionId = null;\n this.updatePendingClientToolsCache();\n\n try {\n for await (const event of this.transport.trigger(triggerName, processedInput)) {\n if (this.streamingState === null) break;\n\n this.handleStreamEvent(event, this.streamingState);\n }\n } catch (err) {\n // Convert unknown errors to OctavusError\n const errorObj = OctavusError.isInstance(err)\n ? err\n : new OctavusError({\n errorType: 'internal_error',\n message: err instanceof Error ? err.message : 'Unknown error',\n source: 'client',\n retryable: false,\n cause: err,\n });\n\n // Finalize any streaming message before setting error state\n const state = this.streamingState;\n if (state !== null) {\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n\n if (state.parts.length > 0) {\n // Mark in-progress parts as done/cancelled\n const finalParts = state.parts.map((part): UIMessagePart => {\n if (part.type === 'text' || part.type === 'reasoning') {\n if (part.status === 'streaming') {\n return { ...part, status: 'done' };\n }\n }\n if (part.type === 'object' && part.status === 'streaming') {\n return { ...part, status: 'done' };\n }\n if (part.type === 'tool-call') {\n if (part.status === 'pending' || part.status === 'running') {\n return { ...part, status: 'cancelled' };\n }\n }\n if (part.type === 'operation' && part.status === 'running') {\n return { ...part, status: 'cancelled' };\n }\n return part;\n });\n\n const finalMessage: UIMessage = {\n id: state.messageId,\n role: 'assistant',\n parts: finalParts,\n status: 'done',\n createdAt: new Date(),\n };\n\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n } else if (lastMsg?.id === state.messageId) {\n // No parts yet - remove the empty streaming message\n messages.pop();\n this.setMessages(messages);\n }\n }\n\n this.setError(errorObj);\n this.setStatus('error');\n this.streamingState = null;\n this.options.onError?.(errorObj);\n }\n }\n\n /**\n * Upload files directly without sending a message.\n * Useful for showing upload progress before sending.\n *\n * @param files - Files to upload\n * @param onProgress - Optional progress callback\n * @returns Array of file references\n *\n * @example\n * ```typescript\n * const fileRefs = await chat.uploadFiles(fileInput.files, (i, progress) => {\n * console.log(`File ${i}: ${progress}%`);\n * });\n * // Later...\n * await chat.send('user-message', { FILES: fileRefs }, { userMessage: { files: fileRefs } });\n * ```\n */\n async uploadFiles(\n files: FileList | File[],\n onProgress?: (fileIndex: number, progress: number) => void,\n ): Promise<FileReference[]> {\n if (!this.options.requestUploadUrls) {\n throw new Error('File upload requires requestUploadUrls option');\n }\n return await uploadFiles(files, {\n requestUploadUrls: this.options.requestUploadUrls,\n onProgress,\n });\n }\n\n /**\n * Internal: Submit a result for a pending tool.\n * Called by bound submit/cancel methods on InteractiveTool.\n */\n private submitToolResult(toolCallId: string, result?: unknown, error?: string): void {\n const pendingTool = this._pendingToolsByCallId.get(toolCallId);\n if (!pendingTool) {\n // Tool not found - may have been cancelled or already resolved\n return;\n }\n\n // Remove from both maps\n this._pendingToolsByCallId.delete(toolCallId);\n const toolsForName = this._pendingToolsByName.get(pendingTool.toolName);\n if (toolsForName) {\n const filtered = toolsForName.filter((t) => t.toolCallId !== toolCallId);\n if (filtered.length === 0) {\n this._pendingToolsByName.delete(pendingTool.toolName);\n } else {\n this._pendingToolsByName.set(pendingTool.toolName, filtered);\n }\n }\n this.updatePendingClientToolsCache();\n\n const toolResult: ToolResult = {\n toolCallId,\n toolName: pendingTool.toolName,\n result: error ? undefined : result,\n error,\n outputVariable: pendingTool.outputVariable,\n blockIndex: pendingTool.blockIndex,\n };\n this._completedToolResults.push(toolResult);\n\n if (error) {\n this.emitToolOutputError(toolCallId, error);\n } else {\n this.emitToolOutputAvailable(toolCallId, result);\n }\n\n if (this._pendingToolsByCallId.size === 0) {\n void this.continueWithClientToolResults();\n }\n\n this.notifyListeners();\n }\n\n /** Stop the current streaming and finalize any partial message */\n stop(): void {\n if (this._status !== 'streaming' && this._status !== 'awaiting-input') {\n return;\n }\n\n this._clientToolAbortController?.abort();\n this._clientToolAbortController = null;\n this._pendingToolsByName.clear();\n this._pendingToolsByCallId.clear();\n this._completedToolResults = [];\n this._serverToolResults = [];\n this._pendingExecutionId = null;\n this.updatePendingClientToolsCache();\n\n this.transport.stop();\n\n const state = this.streamingState;\n if (state && state.parts.length > 0) {\n // Mark in-progress parts as cancelled/done\n const finalParts = state.parts.map((part): UIMessagePart => {\n if (part.type === 'tool-call') {\n const toolPart = part;\n // Mark pending/running tools as cancelled\n if (toolPart.status === 'pending' || toolPart.status === 'running') {\n return { ...toolPart, status: 'cancelled' };\n }\n }\n if (part.type === 'operation') {\n const opPart = part;\n // Mark running operations as cancelled\n if (opPart.status === 'running') {\n return { ...opPart, status: 'cancelled' };\n }\n }\n if (part.type === 'text' || part.type === 'reasoning') {\n const textPart = part;\n // Mark streaming text/reasoning as done (it's not an error)\n if (textPart.status === 'streaming') {\n return { ...textPart, status: 'done' };\n }\n }\n if (part.type === 'object') {\n const objPart = part;\n // Mark streaming objects as done\n if (objPart.status === 'streaming') {\n return { ...objPart, status: 'done' };\n }\n }\n return part;\n });\n\n const finalMessage: UIMessage = {\n id: state.messageId,\n role: 'assistant',\n parts: finalParts,\n status: 'done',\n createdAt: new Date(),\n };\n\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n }\n\n this.streamingState = null;\n this.setStatus('idle');\n this.options.onStop?.();\n }\n\n // =========================================================================\n // Private Helpers\n // =========================================================================\n\n private handleStreamEvent(event: StreamEvent, state: StreamingState): void {\n switch (event.type) {\n case 'start':\n break;\n\n case 'block-start': {\n const block: BlockState = {\n blockId: event.blockId,\n blockName: event.blockName,\n blockType: event.blockType,\n display: event.display,\n description: event.description,\n outputToChat: event.outputToChat ?? true,\n thread: event.thread,\n reasoning: '',\n text: '',\n toolCalls: new Map(),\n };\n state.blocks.set(event.blockId, block);\n state.activeBlock = block;\n\n const isOperation = OPERATION_BLOCK_TYPES.has(event.blockType);\n const isHidden = event.display === 'hidden';\n if (isOperation && !isHidden) {\n const thread = event.thread;\n const operationPart: UIOperationPart = {\n type: 'operation',\n operationId: event.blockId,\n name: event.description ?? event.blockName,\n operationType: event.blockType,\n status: 'running',\n thread: threadForPart(thread),\n };\n state.parts.push(operationPart);\n }\n\n state.currentTextPartIndex = null;\n state.currentReasoningPartIndex = null;\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'block-end': {\n const operationPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'operation' && p.operationId === event.blockId,\n );\n if (operationPartIndex >= 0) {\n const part = state.parts[operationPartIndex] as UIOperationPart;\n state.parts[operationPartIndex] = { ...part, status: 'done' };\n }\n\n if (state.activeBlock?.blockId === event.blockId) {\n state.activeBlock = null;\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'reasoning-start': {\n const reasoningPart: UIReasoningPart = {\n type: 'reasoning',\n text: '',\n status: 'streaming',\n thread: threadForPart(state.activeBlock?.thread),\n };\n state.parts.push(reasoningPart);\n state.currentReasoningPartIndex = state.parts.length - 1;\n this.updateStreamingMessage();\n break;\n }\n\n case 'reasoning-delta': {\n if (state.currentReasoningPartIndex !== null) {\n const part = state.parts[state.currentReasoningPartIndex] as UIReasoningPart;\n part.text += event.delta;\n state.parts[state.currentReasoningPartIndex] = { ...part };\n }\n\n if (state.activeBlock) {\n state.activeBlock.reasoning += event.delta;\n }\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'reasoning-end': {\n if (state.currentReasoningPartIndex !== null) {\n const part = state.parts[state.currentReasoningPartIndex] as UIReasoningPart;\n part.status = 'done';\n state.parts[state.currentReasoningPartIndex] = { ...part };\n state.currentReasoningPartIndex = null;\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'text-start': {\n const thread = threadForPart(state.activeBlock?.thread);\n const shouldAddPart = state.activeBlock?.outputToChat !== false || thread !== undefined;\n\n if (shouldAddPart) {\n // Structured output mode: accumulate JSON and parse progressively\n if (event.responseType) {\n const objectPart: UIObjectPart = {\n type: 'object',\n id: event.id,\n typeName: event.responseType,\n partial: undefined,\n object: undefined,\n status: 'streaming',\n thread,\n };\n state.parts.push(objectPart);\n state.currentObjectPartIndex = state.parts.length - 1;\n state.accumulatedJson = '';\n state.currentTextPartIndex = null;\n } else {\n const textPart: UITextPart = {\n type: 'text',\n text: '',\n status: 'streaming',\n thread,\n };\n state.parts.push(textPart);\n state.currentTextPartIndex = state.parts.length - 1;\n state.currentObjectPartIndex = null;\n }\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'text-delta': {\n if (state.currentObjectPartIndex !== null) {\n state.accumulatedJson += event.delta;\n const part = state.parts[state.currentObjectPartIndex] as UIObjectPart;\n const parsed = parsePartialJson(state.accumulatedJson);\n if (parsed !== undefined) {\n part.partial = parsed;\n state.parts[state.currentObjectPartIndex] = { ...part };\n }\n } else if (state.currentTextPartIndex !== null) {\n const part = state.parts[state.currentTextPartIndex] as UITextPart;\n part.text += event.delta;\n state.parts[state.currentTextPartIndex] = { ...part };\n }\n\n if (state.activeBlock) {\n state.activeBlock.text += event.delta;\n }\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'text-end': {\n if (state.currentObjectPartIndex !== null) {\n const part = state.parts[state.currentObjectPartIndex] as UIObjectPart;\n try {\n const finalObject = JSON.parse(state.accumulatedJson) as unknown;\n part.object = finalObject;\n part.partial = finalObject;\n part.status = 'done';\n } catch {\n // Keep partial data but mark as error\n part.status = 'error';\n part.error = 'Failed to parse response as JSON';\n }\n state.parts[state.currentObjectPartIndex] = { ...part };\n state.currentObjectPartIndex = null;\n state.accumulatedJson = '';\n } else if (state.currentTextPartIndex !== null) {\n const part = state.parts[state.currentTextPartIndex] as UITextPart;\n part.status = 'done';\n state.parts[state.currentTextPartIndex] = { ...part };\n state.currentTextPartIndex = null;\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'tool-input-start': {\n const toolPart: UIToolCallPart = {\n type: 'tool-call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n displayName: event.title,\n args: {},\n status: 'pending',\n thread: threadForPart(state.activeBlock?.thread),\n };\n state.parts.push(toolPart);\n\n if (state.activeBlock) {\n state.activeBlock.toolCalls.set(event.toolCallId, toolPart);\n }\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'tool-input-delta': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n try {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.args = JSON.parse(event.inputTextDelta) as Record<string, unknown>;\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n } catch {\n // Partial JSON, ignore\n }\n }\n break;\n }\n\n case 'tool-input-end':\n // Input streaming ended, wait for tool-input-available\n break;\n\n case 'tool-input-available': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.args = event.input as Record<string, unknown>;\n part.status = 'running';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n break;\n }\n\n case 'tool-output-available': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.result = event.output;\n part.status = 'done';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n break;\n }\n\n case 'tool-output-error': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.error = event.error;\n part.status = 'error';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n break;\n }\n\n case 'source': {\n // Add source (URL or document) as a part\n const thread = threadForPart(state.activeBlock?.thread);\n\n let sourcePart: UISourcePart;\n if (event.sourceType === 'url') {\n sourcePart = {\n type: 'source',\n sourceType: 'url',\n id: event.id,\n url: event.url,\n title: event.title,\n thread,\n };\n } else {\n sourcePart = {\n type: 'source',\n sourceType: 'document',\n id: event.id,\n mediaType: event.mediaType,\n title: event.title,\n filename: event.filename,\n thread,\n };\n }\n\n state.parts.push(sourcePart);\n this.updateStreamingMessage();\n break;\n }\n\n case 'file-available': {\n // Add generated file as a part\n const filePart: UIFilePart = {\n type: 'file',\n id: event.id,\n mediaType: event.mediaType,\n url: event.url,\n filename: event.filename,\n size: event.size,\n toolCallId: event.toolCallId,\n thread: threadForPart(state.activeBlock?.thread),\n };\n state.parts.push(filePart);\n this.updateStreamingMessage();\n break;\n }\n\n case 'resource-update':\n this.options.onResourceUpdate?.(event.name, event.value);\n break;\n\n case 'finish': {\n // Handle client-tool-calls finish reason\n if (event.finishReason === 'client-tool-calls') {\n // Don't finalize message - we're waiting for client tools\n if (this._pendingToolsByCallId.size > 0) {\n this.setStatus('awaiting-input');\n }\n // If no interactive tools but we have completed results, continueWithClientToolResults\n // was already called from handleClientToolRequest\n return;\n }\n\n const finalMessage = buildMessageFromState(state, 'done');\n\n finalMessage.parts = finalMessage.parts.map((part) => {\n if (part.type === 'text' || part.type === 'reasoning') {\n return { ...part, status: 'done' as const };\n }\n if (part.type === 'object' && part.status === 'streaming') {\n return { ...part, status: 'done' as const };\n }\n return part;\n });\n\n if (finalMessage.parts.length > 0) {\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n }\n\n this.setStatus('idle');\n this.streamingState = null;\n this.options.onFinish?.();\n break;\n }\n\n case 'error': {\n // Create structured error from the error event\n throw new OctavusError({\n errorType: event.errorType,\n message: event.message,\n source: event.source,\n retryable: event.retryable,\n retryAfter: event.retryAfter,\n code: event.code,\n provider: event.provider,\n tool: event.tool,\n });\n }\n\n case 'tool-request':\n // Handled by server-sdk, not relevant for UI\n break;\n\n case 'client-tool-request':\n // Store execution ID and server tool results for continuation\n this._pendingExecutionId = event.executionId;\n this._serverToolResults = event.serverToolResults ?? [];\n // Handle client-side tool execution\n void this.handleClientToolRequest(event.toolCalls, state);\n break;\n }\n }\n\n private updateStreamingMessage(): void {\n const state = this.streamingState;\n if (!state) return;\n\n const msg = buildMessageFromState(state, 'streaming');\n const messages = [...this._messages];\n\n const lastMsg = messages[messages.length - 1];\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = msg;\n } else {\n messages.push(msg);\n }\n\n this.setMessages(messages);\n }\n\n /**\n * Emit a tool-output-available event for a client tool result.\n */\n private emitToolOutputAvailable(toolCallId: string, output: unknown): void {\n const state = this.streamingState;\n if (!state) return;\n\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.result = output;\n part.status = 'done';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n }\n\n /**\n * Emit a tool-output-error event for a client tool result.\n */\n private emitToolOutputError(toolCallId: string, error: string): void {\n const state = this.streamingState;\n if (!state) return;\n\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.error = error;\n part.status = 'error';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n }\n\n /**\n * Continue execution with collected client tool results.\n */\n private async continueWithClientToolResults(): Promise<void> {\n if (this._completedToolResults.length === 0) return;\n\n if (this._pendingExecutionId === null) {\n // Context lost - this shouldn't happen, but handle gracefully\n const errorObj = new OctavusError({\n errorType: 'internal_error',\n message: 'Cannot continue execution: execution ID was lost.',\n source: 'client',\n retryable: false,\n });\n this.setError(errorObj);\n this.setStatus('error');\n this.options.onError?.(errorObj);\n return;\n }\n\n // Combine server results (from mixed tools scenario) with client results\n const allResults = [...this._serverToolResults, ...this._completedToolResults];\n const executionId = this._pendingExecutionId;\n this._serverToolResults = [];\n this._completedToolResults = [];\n this._pendingExecutionId = null;\n\n this.setStatus('streaming');\n\n try {\n // Use the transport's continuation method (works for both HTTP and Socket)\n for await (const event of this.transport.continueWithToolResults(executionId, allResults)) {\n if (this.streamingState === null) break;\n this.handleStreamEvent(event, this.streamingState);\n }\n } catch (err) {\n const errorObj = OctavusError.isInstance(err)\n ? err\n : new OctavusError({\n errorType: 'internal_error',\n message: err instanceof Error ? err.message : 'Unknown error',\n source: 'client',\n retryable: false,\n cause: err,\n });\n\n this.setError(errorObj);\n this.setStatus('error');\n this.streamingState = null;\n this.options.onError?.(errorObj);\n }\n }\n\n /**\n * Handle client tool request event.\n *\n * IMPORTANT: Interactive tools must be registered synchronously (before any await)\n * to avoid a race condition where the finish event is processed before tools are added.\n */\n private async handleClientToolRequest(\n toolCalls: PendingToolCall[],\n state: StreamingState,\n ): Promise<void> {\n this._clientToolAbortController = new AbortController();\n\n // FIRST PASS: Register all interactive tools synchronously (no await)\n // This ensures pending tools are populated before finish event is processed\n for (const tc of toolCalls) {\n const handler = this.options.clientTools?.[tc.toolName];\n if (handler === 'interactive') {\n const toolState: PendingToolState = {\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n args: tc.args,\n source: tc.source,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n };\n // Add to both maps\n this._pendingToolsByCallId.set(tc.toolCallId, toolState);\n const existing = this._pendingToolsByName.get(tc.toolName) ?? [];\n this._pendingToolsByName.set(tc.toolName, [...existing, toolState]);\n }\n }\n if (this._pendingToolsByCallId.size > 0) {\n this.updatePendingClientToolsCache();\n }\n\n // SECOND PASS: Execute automatic handlers and handle missing handlers\n for (const tc of toolCalls) {\n const handler = this.options.clientTools?.[tc.toolName];\n\n if (handler === 'interactive') {\n // Already registered above, just update UI state\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === tc.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n // Keep running status - user will see the tool is \"executing\" while modal is open\n state.parts[toolPartIndex] = { ...part };\n }\n } else if (handler) {\n try {\n const result = await handler(tc.args, {\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n signal: this._clientToolAbortController.signal,\n });\n\n this._completedToolResults.push({\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n result,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n });\n\n this.emitToolOutputAvailable(tc.toolCallId, result);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Tool execution failed';\n this._completedToolResults.push({\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n error: errorMessage,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n });\n\n this.emitToolOutputError(tc.toolCallId, errorMessage);\n }\n } else {\n // No handler registered - treat as error\n const errorMessage = `No client handler for tool: ${tc.toolName}`;\n this._completedToolResults.push({\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n error: errorMessage,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n });\n\n this.emitToolOutputError(tc.toolCallId, errorMessage);\n }\n }\n\n // If no interactive tools, auto-continue with results\n if (this._pendingToolsByCallId.size === 0 && this._completedToolResults.length > 0) {\n await this.continueWithClientToolResults();\n }\n }\n}\n","import type { FileReference } from '@octavus/core';\n\n/**\n * Response from the upload URLs endpoint\n */\nexport interface UploadUrlsResponse {\n files: {\n id: string;\n uploadUrl: string;\n downloadUrl: string;\n }[];\n}\n\n/**\n * Options for uploading files\n */\nexport interface UploadFilesOptions {\n /**\n * Function to request upload URLs from the platform.\n * Consumer apps must implement this to authenticate with the platform.\n *\n * @param files - Array of file metadata to request URLs for\n * @returns Response with presigned upload and download URLs\n *\n * @example\n * ```typescript\n * requestUploadUrls: async (files) => {\n * const response = await fetch('/api/upload-urls', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, files }),\n * });\n * return response.json();\n * }\n * ```\n */\n requestUploadUrls: (\n files: { filename: string; mediaType: string; size: number }[],\n ) => Promise<UploadUrlsResponse>;\n\n /**\n * Callback for upload progress (0-100 per file).\n * Called multiple times during upload with real-time progress.\n *\n * @param fileIndex - Index of the file being uploaded\n * @param progress - Progress percentage (0-100)\n */\n onProgress?: (fileIndex: number, progress: number) => void;\n}\n\n/**\n * Upload a single file to S3 with progress tracking.\n * Uses XMLHttpRequest for upload progress events (fetch doesn't support this).\n */\nfunction uploadFileWithProgress(\n url: string,\n file: File,\n onProgress?: (progress: number) => void,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n\n xhr.upload.addEventListener('progress', (event) => {\n if (event.lengthComputable) {\n const progress = Math.round((event.loaded / event.total) * 100);\n onProgress?.(progress);\n }\n });\n\n xhr.addEventListener('load', () => {\n if (xhr.status >= 200 && xhr.status < 300) {\n resolve();\n } else {\n reject(new Error(`Upload failed with status ${xhr.status}`));\n }\n });\n\n xhr.addEventListener('error', () => {\n reject(new Error('Upload failed: network error'));\n });\n\n xhr.addEventListener('abort', () => {\n reject(new Error('Upload aborted'));\n });\n\n xhr.open('PUT', url);\n xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');\n xhr.send(file);\n });\n}\n\n/**\n * Upload files to the Octavus platform.\n *\n * This function:\n * 1. Requests presigned upload URLs from the platform\n * 2. Uploads each file directly to S3 with progress tracking\n * 3. Returns file references that can be used in trigger input\n *\n * @param files - Files to upload (from file input or drag/drop)\n * @param options - Upload configuration\n * @returns Array of file references with download URLs\n *\n * @example\n * ```typescript\n * const fileRefs = await uploadFiles(fileInputRef.current.files, {\n * requestUploadUrls: async (files) => {\n * const response = await fetch('/api/upload-urls', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, files }),\n * });\n * return response.json();\n * },\n * onProgress: (fileIndex, progress) => {\n * console.log(`File ${fileIndex}: ${progress}%`);\n * },\n * });\n * ```\n */\nexport async function uploadFiles(\n files: FileList | File[],\n options: UploadFilesOptions,\n): Promise<FileReference[]> {\n const fileArray = Array.from(files);\n\n if (fileArray.length === 0) {\n return [];\n }\n\n const { files: uploadInfos } = await options.requestUploadUrls(\n fileArray.map((f) => ({\n filename: f.name,\n mediaType: f.type || 'application/octet-stream',\n size: f.size,\n })),\n );\n\n const references: FileReference[] = [];\n\n for (let i = 0; i < fileArray.length; i++) {\n const file = fileArray[i]!;\n const uploadInfo = uploadInfos[i]!;\n\n await uploadFileWithProgress(uploadInfo.uploadUrl, file, (progress) => {\n options.onProgress?.(i, progress);\n });\n\n references.push({\n id: uploadInfo.id,\n mediaType: file.type || 'application/octet-stream',\n url: uploadInfo.downloadUrl,\n filename: file.name,\n size: file.size,\n });\n }\n\n return references;\n}\n","import { safeParseStreamEvent, isAbortError, type StreamEvent } from '@octavus/core';\n\n/**\n * Parse SSE stream events.\n *\n * @param response - The HTTP response with SSE body\n * @param signal - Optional abort signal to cancel reading\n */\nexport async function* parseSSEStream(\n response: Response,\n signal?: AbortSignal,\n): AsyncGenerator<StreamEvent, void, unknown> {\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('Response body is not readable');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n try {\n let reading = true;\n while (reading) {\n // Check if aborted before reading\n if (signal?.aborted) {\n return;\n }\n\n let readResult: ReadableStreamReadResult<Uint8Array>;\n try {\n readResult = await reader.read();\n } catch (err) {\n // Handle abort errors gracefully - exit without throwing\n if (isAbortError(err)) {\n return;\n }\n throw err;\n }\n\n const { done, value } = readResult;\n\n if (done) {\n reading = false;\n continue;\n }\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ') && line !== 'data: [DONE]') {\n try {\n const parsed = safeParseStreamEvent(JSON.parse(line.slice(6)));\n if (parsed.success) {\n yield parsed.data;\n }\n // Skip malformed events silently\n } catch {\n // Skip malformed JSON - no logging in production\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n","import type { StreamEvent, ToolResult } from '@octavus/core';\n\n// =============================================================================\n// Base Transport Interface\n// =============================================================================\n\n/**\n * Transport interface for delivering events from server to client.\n *\n * Abstracts the connection mechanism (HTTP/SSE or WebSocket) behind a unified\n * async iterator interface. Use `createHttpTransport` or `createSocketTransport`\n * to create an implementation.\n */\nexport interface Transport {\n /**\n * Trigger the agent and stream events.\n * @param triggerName - The trigger name defined in the agent's protocol\n * @param input - Input parameters for variable substitution\n */\n trigger(triggerName: string, input?: Record<string, unknown>): AsyncIterable<StreamEvent>;\n\n /**\n * Continue execution with tool results after client-side tool handling.\n *\n * @param executionId - The execution ID from the client-tool-request event\n * @param results - All tool results (server + client) to send\n */\n continueWithToolResults(executionId: string, results: ToolResult[]): AsyncIterable<StreamEvent>;\n\n /** Stop the current stream. Safe to call when no stream is active. */\n stop(): void;\n}\n\n// =============================================================================\n// Socket Transport (extends Transport with connection management)\n// =============================================================================\n\n/**\n * Connection states for socket transport.\n *\n * - `disconnected`: Not connected (initial state or after disconnect)\n * - `connecting`: Connection attempt in progress\n * - `connected`: Successfully connected and ready\n * - `error`: Connection failed (check error in listener callback)\n */\nexport type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';\n\n/**\n * Callback for connection state changes.\n */\nexport type ConnectionStateListener = (state: ConnectionState, error?: Error) => void;\n\n/**\n * Socket transport with connection management capabilities.\n *\n * Extends the base Transport interface with methods for managing persistent\n * WebSocket/SockJS connections. Use this when you need:\n * - Eager connection (connect before first message)\n * - Connection status UI indicators\n * - Manual connection lifecycle control\n *\n * Created via `createSocketTransport()`.\n */\nexport interface SocketTransport extends Transport {\n /**\n * Current connection state.\n *\n * - `disconnected`: Not connected (initial state)\n * - `connecting`: Connection in progress\n * - `connected`: Ready to send/receive\n * - `error`: Connection failed\n */\n readonly connectionState: ConnectionState;\n\n /**\n * Subscribe to connection state changes.\n *\n * The listener is called immediately with the current state, then again\n * whenever the state changes.\n *\n * @param listener - Callback invoked on state changes\n * @returns Unsubscribe function\n *\n * @example\n * ```typescript\n * const unsubscribe = transport.onConnectionStateChange((state, error) => {\n * setConnectionState(state);\n * if (error) setConnectionError(error);\n * });\n * ```\n */\n onConnectionStateChange(listener: ConnectionStateListener): () => void;\n\n /**\n * Eagerly establish the connection.\n *\n * By default, socket transport connects lazily on first `trigger()`. Call\n * this method to establish the connection early (e.g., on component mount):\n * - Faster first message response\n * - Show accurate connection status in UI\n * - Handle connection errors before user interaction\n *\n * Safe to call multiple times - resolves immediately if already connected.\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * transport.connect()\n * .then(() => console.log('Connected'))\n * .catch((err) => console.error('Failed:', err));\n *\n * return () => transport.disconnect();\n * }, [transport]);\n * ```\n */\n connect(): Promise<void>;\n\n /**\n * Close the connection and clean up resources.\n *\n * The transport will reconnect automatically on next `trigger()` call.\n */\n disconnect(): void;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if a transport is a SocketTransport with connection management.\n *\n * @example\n * ```typescript\n * if (isSocketTransport(transport)) {\n * transport.connect(); // TypeScript knows this is available\n * }\n * ```\n */\nexport function isSocketTransport(transport: Transport): transport is SocketTransport {\n return (\n 'connect' in transport &&\n 'disconnect' in transport &&\n 'connectionState' in transport &&\n 'onConnectionStateChange' in transport\n );\n}\n","import { isAbortError, type ToolResult } from '@octavus/core';\nimport { parseSSEStream } from '@/stream/reader';\nimport type { Transport } from './types';\n\n// =============================================================================\n// Request Types\n// =============================================================================\n\n/** Start a new trigger execution */\nexport interface TriggerRequest {\n type: 'trigger';\n triggerName: string;\n input?: Record<string, unknown>;\n}\n\n/** Continue execution after client-side tool handling */\nexport interface ContinueRequest {\n type: 'continue';\n executionId: string;\n toolResults: ToolResult[];\n}\n\n/** All request types supported by the HTTP transport */\nexport type HttpRequest = TriggerRequest | ContinueRequest;\n\n// =============================================================================\n// Transport Options\n// =============================================================================\n\n/** Request options passed to the request callback */\nexport interface HttpRequestOptions {\n /** Abort signal to cancel the request */\n signal?: AbortSignal;\n}\n\n/**\n * Options for creating an HTTP transport.\n */\nexport interface HttpTransportOptions {\n /**\n * Function to make requests to your backend.\n * Receives a discriminated union with `type` to identify the request kind.\n *\n * @param request - The request payload (check `request.type` for the kind)\n * @param options - Request options including abort signal\n * @returns Response with SSE stream body\n *\n * @example\n * ```typescript\n * request: (payload, options) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, ...payload }),\n * signal: options?.signal,\n * })\n * ```\n */\n request: (request: HttpRequest, options?: HttpRequestOptions) => Promise<Response>;\n}\n\n// =============================================================================\n// Transport Implementation\n// =============================================================================\n\n/**\n * Create an HTTP transport using native fetch() and SSE parsing.\n * This is the default transport for Next.js and other HTTP-based applications.\n *\n * @example\n * ```typescript\n * const transport = createHttpTransport({\n * request: (payload, options) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, ...payload }),\n * signal: options?.signal,\n * }),\n * });\n * ```\n */\nexport function createHttpTransport(options: HttpTransportOptions): Transport {\n let abortController: AbortController | null = null;\n\n async function* streamResponse(responsePromise: Promise<Response>) {\n try {\n const response = await responsePromise;\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => `Request failed: ${response.status}`);\n throw new Error(errorText);\n }\n\n if (!response.body) {\n throw new Error('Response body is empty');\n }\n\n for await (const event of parseSSEStream(response, abortController!.signal)) {\n if (abortController?.signal.aborted) {\n break;\n }\n yield event;\n }\n } catch (err) {\n if (isAbortError(err)) {\n return;\n }\n throw err;\n }\n }\n\n return {\n async *trigger(triggerName, input) {\n abortController = new AbortController();\n const response = options.request(\n { type: 'trigger', triggerName, input },\n { signal: abortController.signal },\n );\n yield* streamResponse(response);\n },\n\n async *continueWithToolResults(executionId, toolResults) {\n abortController = new AbortController();\n const response = options.request(\n { type: 'continue', executionId, toolResults },\n { signal: abortController.signal },\n );\n yield* streamResponse(response);\n },\n\n stop() {\n abortController?.abort();\n abortController = null;\n },\n };\n}\n","import { safeParseStreamEvent, type StreamEvent, type ToolResult } from '@octavus/core';\nimport type { SocketTransport, ConnectionState, ConnectionStateListener } from './types';\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Socket interface compatible with both WebSocket and SockJS.\n *\n * Uses MessageEvent for the message handler, which both WebSocket and SockJS support.\n * The `| undefined` union accommodates SockJS's optional property typing.\n */\nexport interface SocketLike {\n send(data: string): void;\n close(): void;\n readyState: number;\n onmessage: ((event: MessageEvent) => void) | null | undefined;\n onclose: ((event: CloseEvent) => void) | null | undefined;\n}\n\n/** WebSocket readyState constants */\nconst SOCKET_OPEN = 1;\n\n// =============================================================================\n// Transport Options\n// =============================================================================\n\n/**\n * Options for creating a socket transport.\n */\nexport interface SocketTransportOptions {\n /**\n * Function to create and connect the socket.\n * Works directly with WebSocket and SockJS - no wrappers needed.\n *\n * @example Native WebSocket\n * ```typescript\n * connect: () => new Promise((resolve, reject) => {\n * const ws = new WebSocket('wss://api.example.com/stream?sessionId=xxx');\n * ws.onopen = () => resolve(ws);\n * ws.onerror = () => reject(new Error('Connection failed'));\n * })\n * ```\n *\n * @example SockJS\n * ```typescript\n * connect: () => new Promise((resolve, reject) => {\n * const sock = new SockJS('/chat-service');\n * sock.onopen = () => resolve(sock);\n * sock.onerror = () => reject(new Error('Connection failed'));\n * })\n * ```\n */\n connect: () => Promise<SocketLike>;\n\n /**\n * Called for every message received (parsed as JSON).\n * Use this to handle custom (non-Octavus) events.\n * Octavus StreamEvents are handled automatically by the transport.\n *\n * @example\n * ```typescript\n * onMessage: (data) => {\n * const msg = data as { type: string };\n * if (msg.type === 'typing-indicator') {\n * setIsTyping(true);\n * }\n * if (msg.type === 'presence-update') {\n * updatePresence(msg.users);\n * }\n * }\n * ```\n */\n onMessage?: (data: unknown) => void;\n\n /**\n * Called when the socket connection closes.\n * Use this for cleanup or reconnection logic.\n */\n onClose?: () => void;\n}\n\n/**\n * Create a socket transport that works with any WebSocket-like connection.\n * Supports native WebSocket, SockJS, or any compatible socket implementation.\n *\n * The server should send StreamEvent format (same as SSE) over the socket.\n * Unknown events are safely ignored using Zod validation.\n *\n * ## Connection Lifecycle\n *\n * By default, the socket connects **lazily** on the first `send()` call.\n * Use `connect()` to establish the connection eagerly (e.g., on component mount):\n *\n * ```typescript\n * // Eager connection for UI status indicators\n * useEffect(() => {\n * transport.connect()\n * .then(() => console.log('Connected'))\n * .catch((err) => console.error('Failed:', err));\n *\n * return () => transport.disconnect();\n * }, [transport]);\n * ```\n *\n * @example Basic usage with WebSocket\n * ```typescript\n * const transport = createSocketTransport({\n * connect: () => new Promise((resolve, reject) => {\n * const ws = new WebSocket(`wss://api.octavus.ai/stream?sessionId=${sessionId}`);\n * ws.onopen = () => resolve(ws);\n * ws.onerror = () => reject(new Error('Connection failed'));\n * }),\n * });\n * ```\n *\n * @example With SockJS and connection state\n * ```typescript\n * const transport = createSocketTransport({\n * connect: () => new Promise((resolve, reject) => {\n * const sock = new SockJS('/octavus-stream');\n * sock.onopen = () => resolve(sock);\n * sock.onerror = () => reject(new Error('Connection failed'));\n * }),\n * });\n *\n * // Subscribe to connection state changes\n * transport.onConnectionStateChange((state, error) => {\n * setConnectionState(state);\n * if (error) setConnectionError(error);\n * });\n * ```\n */\nexport function createSocketTransport(options: SocketTransportOptions): SocketTransport {\n let socket: SocketLike | null = null;\n let eventQueue: StreamEvent[] = [];\n let eventResolver: ((event: StreamEvent | null) => void) | null = null;\n let isStreaming = false;\n\n let connectionState: ConnectionState = 'disconnected';\n let connectionError: Error | undefined;\n let connectionPromise: Promise<void> | null = null;\n const connectionListeners = new Set<ConnectionStateListener>();\n\n function setConnectionState(state: ConnectionState, error?: Error) {\n connectionState = state;\n connectionError = error;\n connectionListeners.forEach((listener) => listener(state, error));\n }\n\n function enqueueEvent(event: StreamEvent) {\n if (eventResolver) {\n eventResolver(event);\n eventResolver = null;\n } else {\n eventQueue.push(event);\n }\n }\n\n function nextEvent(): Promise<StreamEvent | null> {\n if (eventQueue.length > 0) {\n return Promise.resolve(eventQueue.shift()!);\n }\n if (!isStreaming) {\n return Promise.resolve(null);\n }\n return new Promise((resolve) => {\n eventResolver = resolve;\n });\n }\n\n function setupSocketHandlers(sock: SocketLike): void {\n sock.onmessage = (e: MessageEvent) => {\n try {\n const data: unknown = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;\n\n options.onMessage?.(data);\n\n const result = safeParseStreamEvent(data);\n if (result.success) {\n const event = result.data;\n enqueueEvent(event);\n\n if (event.type === 'finish' || event.type === 'error') {\n isStreaming = false;\n }\n }\n } catch {\n // Malformed JSON, skip\n }\n };\n\n sock.onclose = () => {\n socket = null;\n connectionPromise = null;\n setConnectionState('disconnected');\n options.onClose?.();\n\n isStreaming = false;\n if (eventResolver) {\n eventResolver(null);\n eventResolver = null;\n }\n };\n }\n\n async function ensureConnected(): Promise<void> {\n // Already connected\n if (socket?.readyState === SOCKET_OPEN) {\n return;\n }\n\n // Connection in progress - wait for it\n if (connectionPromise) {\n await connectionPromise;\n return;\n }\n\n // Start new connection\n setConnectionState('connecting');\n\n connectionPromise = (async () => {\n try {\n const sock = await options.connect();\n socket = sock;\n setupSocketHandlers(sock);\n setConnectionState('connected');\n } catch (err) {\n socket = null;\n connectionPromise = null;\n const error = err instanceof Error ? err : new Error('Connection failed');\n setConnectionState('error', error);\n throw error;\n }\n })();\n\n await connectionPromise;\n }\n\n return {\n // =========================================================================\n // Connection Management\n // =========================================================================\n\n get connectionState(): ConnectionState {\n return connectionState;\n },\n\n onConnectionStateChange(listener: ConnectionStateListener): () => void {\n connectionListeners.add(listener);\n // Immediately notify with current state\n listener(connectionState, connectionError);\n return () => connectionListeners.delete(listener);\n },\n\n async connect(): Promise<void> {\n await ensureConnected();\n },\n\n disconnect(): void {\n if (socket) {\n socket.close();\n socket = null;\n }\n connectionPromise = null;\n isStreaming = false;\n if (eventResolver) {\n eventResolver(null);\n eventResolver = null;\n }\n setConnectionState('disconnected');\n },\n\n // =========================================================================\n // Streaming\n // =========================================================================\n\n async *trigger(triggerName, input) {\n await ensureConnected();\n\n eventQueue = [];\n isStreaming = true;\n\n // Note: clientToolResults not sent here - socket uses sendClientToolResults() for continuation\n socket!.send(\n JSON.stringify({\n type: 'trigger',\n triggerName,\n input,\n }),\n );\n\n while (true) {\n const event = await nextEvent();\n if (event === null) break;\n yield event;\n if (event.type === 'finish' || event.type === 'error') break;\n }\n },\n\n stop() {\n if (socket?.readyState === SOCKET_OPEN) {\n socket.send(JSON.stringify({ type: 'stop' }));\n }\n isStreaming = false;\n if (eventResolver) {\n eventResolver(null);\n eventResolver = null;\n }\n },\n\n /**\n * Continue execution with tool results after client-side tool handling.\n * @param executionId - The execution ID from the client-tool-request event\n * @param toolResults - All tool results (server + client) to send\n */\n async *continueWithToolResults(executionId: string, toolResults: ToolResult[]) {\n await ensureConnected();\n\n eventQueue = [];\n isStreaming = true;\n\n socket!.send(\n JSON.stringify({\n type: 'continue',\n executionId,\n toolResults,\n }),\n );\n\n while (true) {\n const event = await nextEvent();\n if (event === null) break;\n yield event;\n if (event.type === 'finish' || event.type === 'error') break;\n }\n },\n };\n}\n","export {\n OctavusChat,\n type OctavusChatOptions,\n type ChatStatus,\n type UserMessageInput,\n type ClientToolContext,\n type ClientToolHandler,\n type InteractiveTool,\n} from './chat';\n\nexport { uploadFiles, type UploadFilesOptions, type UploadUrlsResponse } from './files';\n\nexport { parseSSEStream } from './stream/reader';\n\n// Transport exports\nexport {\n createHttpTransport,\n createSocketTransport,\n isSocketTransport,\n type Transport,\n type SocketTransport,\n type ConnectionState,\n type ConnectionStateListener,\n type HttpTransportOptions,\n type HttpRequestOptions,\n type HttpRequest,\n type TriggerRequest,\n type ContinueRequest,\n type SocketLike,\n type SocketTransportOptions,\n} from './transports';\n\nexport type * from '@octavus/core';\nexport {\n // Error classes\n AppError,\n NotFoundError,\n ValidationError,\n ConflictError,\n ForbiddenError,\n OctavusError,\n // Error type guards\n isRateLimitError,\n isAuthenticationError,\n isProviderError,\n isToolError,\n isRetryableError,\n isValidationError,\n // Error event helpers\n createErrorEvent,\n errorToStreamEvent,\n createInternalErrorEvent,\n createApiErrorEvent,\n // Utilities\n generateId,\n isAbortError,\n // Thread helpers\n MAIN_THREAD,\n resolveThread,\n isMainThread,\n threadForPart,\n isOtherThread,\n // Type guards\n isFileReference,\n isFileReferenceArray,\n // Safe parse helpers\n safeParseStreamEvent,\n safeParseUIMessage,\n safeParseUIMessages,\n // Skills\n OCTAVUS_SKILL_TOOLS,\n isOctavusSkillTool,\n getSkillSlugFromToolCall,\n} from '@octavus/core';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAeK;;;ACmCP,SAAS,uBACP,KACA,MACA,YACe;AACf,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,MAAM,IAAI,eAAe;AAE/B,QAAI,OAAO,iBAAiB,YAAY,CAAC,UAAU;AACjD,UAAI,MAAM,kBAAkB;AAC1B,cAAM,WAAW,KAAK,MAAO,MAAM,SAAS,MAAM,QAAS,GAAG;AAC9D,qBAAa,QAAQ;AAAA,MACvB;AAAA,IACF,CAAC;AAED,QAAI,iBAAiB,QAAQ,MAAM;AACjC,UAAI,IAAI,UAAU,OAAO,IAAI,SAAS,KAAK;AACzC,gBAAQ;AAAA,MACV,OAAO;AACL,eAAO,IAAI,MAAM,6BAA6B,IAAI,MAAM,EAAE,CAAC;AAAA,MAC7D;AAAA,IACF,CAAC;AAED,QAAI,iBAAiB,SAAS,MAAM;AAClC,aAAO,IAAI,MAAM,8BAA8B,CAAC;AAAA,IAClD,CAAC;AAED,QAAI,iBAAiB,SAAS,MAAM;AAClC,aAAO,IAAI,MAAM,gBAAgB,CAAC;AAAA,IACpC,CAAC;AAED,QAAI,KAAK,OAAO,GAAG;AACnB,QAAI,iBAAiB,gBAAgB,KAAK,QAAQ,0BAA0B;AAC5E,QAAI,KAAK,IAAI;AAAA,EACf,CAAC;AACH;AA+BA,eAAsB,YACpB,OACA,SAC0B;AAC1B,QAAM,YAAY,MAAM,KAAK,KAAK;AAElC,MAAI,UAAU,WAAW,GAAG;AAC1B,WAAO,CAAC;AAAA,EACV;AAEA,Q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AAC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["isAbortError","isAbortError","safeParseStreamEvent","OctavusError","generateId","isAbortError","threadForPart","isFileReferenceArray","safeParseStreamEvent"]}
|
|
1
|
+
{"version":3,"sources":["../src/chat.ts","../src/files.ts","../src/stream/reader.ts","../src/transports/types.ts","../src/transports/http.ts","../src/transports/socket.ts","../src/index.ts"],"sourcesContent":["import {\n generateId,\n threadForPart,\n isFileReferenceArray,\n OctavusError,\n type UIMessage,\n type UIMessagePart,\n type UITextPart,\n type UIReasoningPart,\n type UIToolCallPart,\n type UIOperationPart,\n type UISourcePart,\n type UIFilePart,\n type UIObjectPart,\n type DisplayMode,\n type StreamEvent,\n type FileReference,\n type PendingToolCall,\n type ToolResult,\n} from '@octavus/core';\nimport type { Transport } from './transports/types';\nimport { uploadFiles, type UploadFilesOptions } from './files';\n\n/** Block types that are internal operations (not LLM-driven) */\nconst OPERATION_BLOCK_TYPES = new Set(['set-resource', 'serialize-thread', 'generate-image']);\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type ChatStatus = 'idle' | 'streaming' | 'error' | 'awaiting-input';\n\n/**\n * Context provided to client tool handlers.\n */\nexport interface ClientToolContext {\n /** Unique identifier for this tool call */\n toolCallId: string;\n /** Name of the tool being called */\n toolName: string;\n /** Signal for cancellation if user stops generation */\n signal: AbortSignal;\n}\n\n/**\n * Handler function for client-side tool execution.\n * Can be:\n * - An async function that executes automatically and returns a result\n * - The string 'interactive' to indicate the tool requires user interaction\n */\nexport type ClientToolHandler =\n | ((args: Record<string, unknown>, ctx: ClientToolContext) => Promise<unknown>)\n | 'interactive';\n\n/**\n * Interactive tool call awaiting user interaction.\n * The `submit` and `cancel` methods are pre-bound to this tool call's ID.\n */\nexport interface InteractiveTool {\n /** Unique identifier for this tool call */\n toolCallId: string;\n /** Name of the tool being called */\n toolName: string;\n /** Arguments passed to the tool */\n args: Record<string, unknown>;\n /**\n * Submit a result for this tool call.\n * Call this when the user has provided input.\n *\n * @param result - The result from user interaction\n */\n submit: (result: unknown) => void;\n /**\n * Cancel this tool call with an optional reason.\n * Call this when the user dismisses the UI without providing input.\n *\n * @param reason - Optional reason for cancellation (default: 'User cancelled')\n */\n cancel: (reason?: string) => void;\n}\n\n/**\n * Internal pending tool state (before binding submit/cancel).\n */\ninterface PendingToolState {\n toolCallId: string;\n toolName: string;\n args: Record<string, unknown>;\n source?: 'llm' | 'block';\n outputVariable?: string;\n blockIndex?: number;\n}\n\n/**\n * Input for creating a user message.\n * Supports text content, structured object content, and file attachments.\n */\nexport interface UserMessageInput {\n /**\n * Content of the message. Can be:\n * - string: Creates a text part\n * - object: Creates an object part (uses `type` field as typeName if present)\n */\n content?: string | Record<string, unknown>;\n /**\n * File attachments (shorthand). Can be:\n * - FileList: From file input element (will be uploaded via uploadFiles)\n * - File[]: Array of File objects (will be uploaded via uploadFiles)\n * - FileReference[]: Already uploaded files (used directly)\n */\n files?: FileList | File[] | FileReference[];\n}\n\nexport interface OctavusChatOptions {\n /**\n * Transport for streaming events.\n * Use `createHttpTransport` for HTTP/SSE or `createSocketTransport` for WebSocket/SockJS.\n */\n transport: Transport;\n\n /**\n * Function to request upload URLs from the platform.\n * Required if you want to use file uploads with FileList/File[].\n *\n * @example\n * ```typescript\n * requestUploadUrls: async (files) => {\n * const response = await fetch('/api/upload-urls', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, files }),\n * });\n * return response.json();\n * }\n * ```\n */\n requestUploadUrls?: UploadFilesOptions['requestUploadUrls'];\n\n /**\n * Client-side tool handlers.\n * Register handlers for tools that should execute in the browser.\n *\n * - If a tool has a handler function: executes automatically\n * - If a tool is marked as 'interactive': appears in `pendingClientTools` with bound `submit()`/`cancel()`\n *\n * @example Automatic client tool\n * ```typescript\n * clientTools: {\n * 'get-browser-location': async () => {\n * const pos = await new Promise((resolve, reject) => {\n * navigator.geolocation.getCurrentPosition(resolve, reject);\n * });\n * return { lat: pos.coords.latitude, lng: pos.coords.longitude };\n * },\n * }\n * ```\n *\n * @example Interactive client tool (user input required)\n * ```typescript\n * clientTools: {\n * 'request-feedback': 'interactive',\n * }\n * // Then render UI based on pendingClientTools['request-feedback']\n * // and call tool.submit(result) or tool.cancel()\n * ```\n */\n clientTools?: Record<string, ClientToolHandler>;\n\n /** Initial messages (for session refresh) */\n initialMessages?: UIMessage[];\n /**\n * Callback when an error occurs.\n * Receives an OctavusError with structured error information.\n *\n * @example\n * ```typescript\n * onError: (error) => {\n * console.error('Chat error:', {\n * type: error.errorType,\n * message: error.message,\n * retryable: error.retryable,\n * provider: error.provider,\n * });\n *\n * // Handle specific error types\n * if (isRateLimitError(error)) {\n * showRetryButton(error.retryAfter);\n * }\n * }\n * ```\n */\n onError?: (error: OctavusError) => void;\n /** Callback when streaming finishes successfully */\n onFinish?: () => void;\n /** Callback when streaming is stopped by user */\n onStop?: () => void;\n /** Callback when a resource is updated */\n onResourceUpdate?: (name: string, value: unknown) => void;\n}\n\n// =============================================================================\n// Internal Types\n// =============================================================================\n\ninterface BlockState {\n blockId: string;\n blockName: string;\n blockType: string;\n display: DisplayMode;\n description?: string;\n outputToChat: boolean;\n thread?: string;\n reasoning: string;\n text: string;\n toolCalls: Map<string, UIToolCallPart>;\n}\n\ninterface StreamingState {\n messageId: string;\n parts: UIMessagePart[];\n activeBlock: BlockState | null;\n blocks: Map<string, BlockState>;\n currentTextPartIndex: number | null;\n currentReasoningPartIndex: number | null;\n currentObjectPartIndex: number | null;\n accumulatedJson: string;\n}\n\ntype Listener = () => void;\n\n// =============================================================================\n// Helpers\n// =============================================================================\n\n/**\n * Create a user message from input with optional file attachments.\n * Parts order: files first (for vision models), then content (text or object).\n */\nfunction createUserMessage(input: UserMessageInput, files?: FileReference[]): UIMessage {\n const parts: UIMessagePart[] = [];\n\n // Add file parts first (vision models expect images before text)\n if (files && files.length > 0) {\n for (const file of files) {\n parts.push({\n type: 'file',\n id: file.id,\n mediaType: file.mediaType,\n url: file.url,\n filename: file.filename,\n size: file.size,\n });\n }\n }\n\n // Add content part after files\n if (input.content !== undefined) {\n if (typeof input.content === 'string') {\n // String content → text part\n parts.push({ type: 'text', text: input.content, status: 'done' });\n } else {\n // Object content → object part\n // Use the object's `type` field as typeName if present, otherwise fallback to 'object'\n const typeName = (input.content as { type?: string }).type ?? 'object';\n parts.push({\n type: 'object',\n id: generateId(),\n typeName,\n object: input.content,\n status: 'done',\n });\n }\n }\n\n return {\n id: generateId(),\n role: 'user',\n parts,\n status: 'done',\n createdAt: new Date(),\n };\n}\n\n/**\n * Parse partial JSON by fixing incomplete structures (unclosed strings, brackets, braces).\n */\nfunction parsePartialJson(jsonText: string): unknown {\n if (!jsonText.trim()) {\n return undefined;\n }\n\n try {\n return JSON.parse(jsonText) as unknown;\n } catch {\n // Continue to fix incomplete JSON\n }\n\n let fixed = jsonText;\n\n // Count unclosed brackets/braces while tracking string boundaries\n let openBraces = 0;\n let openBrackets = 0;\n let inString = false;\n let escaped = false;\n\n for (const char of fixed) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === '\\\\') {\n escaped = true;\n continue;\n }\n\n if (char === '\"') {\n inString = !inString;\n continue;\n }\n\n if (!inString) {\n if (char === '{') openBraces += 1;\n else if (char === '}') openBraces -= 1;\n else if (char === '[') openBrackets += 1;\n else if (char === ']') openBrackets -= 1;\n }\n }\n\n // Close unclosed structures\n if (inString) {\n fixed += '\"';\n }\n while (openBrackets > 0) {\n fixed += ']';\n openBrackets -= 1;\n }\n while (openBraces > 0) {\n fixed += '}';\n openBraces -= 1;\n }\n\n try {\n return JSON.parse(fixed) as unknown;\n } catch {\n return undefined;\n }\n}\n\nfunction createEmptyStreamingState(): StreamingState {\n return {\n messageId: generateId(),\n parts: [],\n activeBlock: null,\n blocks: new Map(),\n currentTextPartIndex: null,\n currentReasoningPartIndex: null,\n currentObjectPartIndex: null,\n accumulatedJson: '',\n };\n}\n\nfunction buildMessageFromState(state: StreamingState, status: 'streaming' | 'done'): UIMessage {\n return {\n id: state.messageId,\n role: 'assistant',\n parts: [...state.parts],\n status,\n createdAt: new Date(),\n };\n}\n\n// =============================================================================\n// OctavusChat Class\n// =============================================================================\n\n/**\n * Framework-agnostic chat client for Octavus agents.\n * Manages chat state and streaming, allowing reactive frameworks to subscribe to updates.\n *\n * @example HTTP transport (Next.js, etc.)\n * ```typescript\n * import { OctavusChat, createHttpTransport } from '@octavus/client-sdk';\n *\n * const chat = new OctavusChat({\n * transport: createHttpTransport({\n * request: (payload, options) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, ...payload }),\n * signal: options?.signal,\n * }),\n * }),\n * });\n * ```\n *\n * @example Socket transport (WebSocket, SockJS, Meteor)\n * ```typescript\n * import { OctavusChat, createSocketTransport } from '@octavus/client-sdk';\n *\n * const chat = new OctavusChat({\n * transport: createSocketTransport({\n * connect: () => new Promise((resolve, reject) => {\n * const ws = new WebSocket(`wss://api.octavus.ai/stream?sessionId=${sessionId}`);\n * ws.onopen = () => resolve(ws);\n * ws.onerror = () => reject(new Error('Connection failed'));\n * }),\n * }),\n * });\n * ```\n */\nexport class OctavusChat {\n // Private state\n private _messages: UIMessage[];\n private _status: ChatStatus = 'idle';\n private _error: OctavusError | null = null;\n private options: OctavusChatOptions;\n private transport: Transport;\n private streamingState: StreamingState | null = null;\n\n // Client tool state\n // Keyed by toolName -> array of pending tools for that name\n private _pendingToolsByName = new Map<string, PendingToolState[]>();\n // Keyed by toolCallId -> pending tool state (for internal lookup when submitting)\n private _pendingToolsByCallId = new Map<string, PendingToolState>();\n // Cache for React useSyncExternalStore compatibility\n private _pendingClientToolsCache: Record<string, InteractiveTool[]> = {};\n private _completedToolResults: ToolResult[] = [];\n private _clientToolAbortController: AbortController | null = null;\n // Server tool results from mixed server+client tools (for continuation)\n private _serverToolResults: ToolResult[] = [];\n // Execution ID for continuation (from client-tool-request event)\n private _pendingExecutionId: string | null = null;\n // Flag indicating automatic client tools have completed and are ready to continue\n // We wait for the finish event before actually continuing to avoid race conditions\n private _readyToContinue = false;\n\n // Listener sets for reactive frameworks\n private listeners = new Set<Listener>();\n\n constructor(options: OctavusChatOptions) {\n this.options = options;\n this._messages = options.initialMessages ?? [];\n this.transport = options.transport;\n }\n\n // =========================================================================\n // Public Getters\n // =========================================================================\n\n get messages(): UIMessage[] {\n return this._messages;\n }\n\n get status(): ChatStatus {\n return this._status;\n }\n\n /**\n * The current error, if any.\n * Contains structured error information including type, source, and retryability.\n */\n get error(): OctavusError | null {\n return this._error;\n }\n\n /**\n * Pending interactive tool calls keyed by tool name.\n * Each tool has bound `submit()` and `cancel()` methods.\n *\n * @example\n * ```tsx\n * const feedbackTools = pendingClientTools['request-feedback'] ?? [];\n *\n * {feedbackTools.map(tool => (\n * <FeedbackModal\n * key={tool.toolCallId}\n * {...tool.args}\n * onSubmit={(result) => tool.submit(result)}\n * onCancel={() => tool.cancel()}\n * />\n * ))}\n * ```\n */\n get pendingClientTools(): Record<string, InteractiveTool[]> {\n return this._pendingClientToolsCache;\n }\n\n // =========================================================================\n // Subscription Methods (for reactive frameworks)\n // =========================================================================\n\n /**\n * Subscribe to state changes. The callback is called whenever messages, status, or error changes.\n * @returns Unsubscribe function\n */\n subscribe(listener: Listener): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((l) => l());\n }\n\n // =========================================================================\n // Private Setters (notify listeners)\n // =========================================================================\n\n private setMessages(messages: UIMessage[]): void {\n this._messages = messages;\n this.notifyListeners();\n }\n\n private setStatus(status: ChatStatus): void {\n this._status = status;\n this.notifyListeners();\n }\n\n private setError(error: OctavusError | null): void {\n this._error = error;\n this.notifyListeners();\n }\n\n private updatePendingClientToolsCache(): void {\n const cache: Record<string, InteractiveTool[]> = {};\n for (const [toolName, tools] of this._pendingToolsByName.entries()) {\n cache[toolName] = tools.map((tool) => ({\n toolCallId: tool.toolCallId,\n toolName: tool.toolName,\n args: tool.args,\n submit: (result: unknown) => this.submitToolResult(tool.toolCallId, result),\n cancel: (reason?: string) =>\n this.submitToolResult(tool.toolCallId, undefined, reason ?? 'User cancelled'),\n }));\n }\n this._pendingClientToolsCache = cache;\n }\n\n // =========================================================================\n // Public Methods\n // =========================================================================\n\n /**\n * Trigger the agent and optionally add a user message to the chat.\n *\n * @param triggerName - The trigger name defined in the agent's protocol.yaml\n * @param input - Input parameters for the trigger (variable substitutions)\n * @param options.userMessage - If provided, adds a user message to the chat before triggering\n *\n * @example Send a text message\n * ```typescript\n * await chat.send('user-message',\n * { USER_MESSAGE: message },\n * { userMessage: { content: message } }\n * );\n * ```\n *\n * @example Send a message with file attachments\n * ```typescript\n * await chat.send('user-message',\n * { USER_MESSAGE: message, FILES: fileRefs },\n * { userMessage: { content: message, files: fileRefs } }\n * );\n * ```\n */\n async send(\n triggerName: string,\n input?: Record<string, unknown>,\n sendOptions?: { userMessage?: UserMessageInput },\n ): Promise<void> {\n this.transport.stop();\n\n let fileRefs: FileReference[] | undefined;\n if (sendOptions?.userMessage?.files) {\n const files = sendOptions.userMessage.files;\n if (isFileReferenceArray(files)) {\n fileRefs = files;\n } else if (this.options.requestUploadUrls) {\n fileRefs = await uploadFiles(files, {\n requestUploadUrls: this.options.requestUploadUrls,\n });\n } else {\n throw new Error(\n 'File upload requires requestUploadUrls option. Either provide FileReference[] or configure requestUploadUrls.',\n );\n }\n }\n\n // Auto-upload FILES in trigger input if needed\n let processedInput = input;\n if (input?.FILES !== undefined && !isFileReferenceArray(input.FILES)) {\n if (this.options.requestUploadUrls) {\n const inputFiles = input.FILES as FileList | File[];\n const uploadedRefs =\n fileRefs ??\n (await uploadFiles(inputFiles, {\n requestUploadUrls: this.options.requestUploadUrls,\n }));\n processedInput = { ...input, FILES: uploadedRefs };\n fileRefs = fileRefs ?? uploadedRefs;\n }\n }\n\n // Optimistic UI: add user message before server responds\n if (sendOptions?.userMessage !== undefined) {\n const userMsg = createUserMessage(sendOptions.userMessage, fileRefs);\n this.setMessages([...this._messages, userMsg]);\n }\n\n this.setStatus('streaming');\n this.setError(null);\n this.streamingState = createEmptyStreamingState();\n\n // Clear any previous client tool state\n this._pendingToolsByName.clear();\n this._pendingToolsByCallId.clear();\n this._completedToolResults = [];\n this._serverToolResults = [];\n this._pendingExecutionId = null;\n this._readyToContinue = false;\n this.updatePendingClientToolsCache();\n\n try {\n for await (const event of this.transport.trigger(triggerName, processedInput)) {\n if (this.streamingState === null) break;\n\n this.handleStreamEvent(event, this.streamingState);\n }\n } catch (err) {\n // Convert unknown errors to OctavusError\n const errorObj = OctavusError.isInstance(err)\n ? err\n : new OctavusError({\n errorType: 'internal_error',\n message: err instanceof Error ? err.message : 'Unknown error',\n source: 'client',\n retryable: false,\n cause: err,\n });\n\n // Finalize any streaming message before setting error state\n const state = this.streamingState;\n if (state !== null) {\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n\n if (state.parts.length > 0) {\n // Mark in-progress parts as done/cancelled\n const finalParts = state.parts.map((part): UIMessagePart => {\n if (part.type === 'text' || part.type === 'reasoning') {\n if (part.status === 'streaming') {\n return { ...part, status: 'done' };\n }\n }\n if (part.type === 'object' && part.status === 'streaming') {\n return { ...part, status: 'done' };\n }\n if (part.type === 'tool-call') {\n if (part.status === 'pending' || part.status === 'running') {\n return { ...part, status: 'cancelled' };\n }\n }\n if (part.type === 'operation' && part.status === 'running') {\n return { ...part, status: 'cancelled' };\n }\n return part;\n });\n\n const finalMessage: UIMessage = {\n id: state.messageId,\n role: 'assistant',\n parts: finalParts,\n status: 'done',\n createdAt: new Date(),\n };\n\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n } else if (lastMsg?.id === state.messageId) {\n // No parts yet - remove the empty streaming message\n messages.pop();\n this.setMessages(messages);\n }\n }\n\n this.setError(errorObj);\n this.setStatus('error');\n this.streamingState = null;\n this.options.onError?.(errorObj);\n }\n }\n\n /**\n * Upload files directly without sending a message.\n * Useful for showing upload progress before sending.\n *\n * @param files - Files to upload\n * @param onProgress - Optional progress callback\n * @returns Array of file references\n *\n * @example\n * ```typescript\n * const fileRefs = await chat.uploadFiles(fileInput.files, (i, progress) => {\n * console.log(`File ${i}: ${progress}%`);\n * });\n * // Later...\n * await chat.send('user-message', { FILES: fileRefs }, { userMessage: { files: fileRefs } });\n * ```\n */\n async uploadFiles(\n files: FileList | File[],\n onProgress?: (fileIndex: number, progress: number) => void,\n ): Promise<FileReference[]> {\n if (!this.options.requestUploadUrls) {\n throw new Error('File upload requires requestUploadUrls option');\n }\n return await uploadFiles(files, {\n requestUploadUrls: this.options.requestUploadUrls,\n onProgress,\n });\n }\n\n /**\n * Internal: Submit a result for a pending tool.\n * Called by bound submit/cancel methods on InteractiveTool.\n */\n private submitToolResult(toolCallId: string, result?: unknown, error?: string): void {\n const pendingTool = this._pendingToolsByCallId.get(toolCallId);\n if (!pendingTool) {\n // Tool not found - may have been cancelled or already resolved\n return;\n }\n\n // Remove from both maps\n this._pendingToolsByCallId.delete(toolCallId);\n const toolsForName = this._pendingToolsByName.get(pendingTool.toolName);\n if (toolsForName) {\n const filtered = toolsForName.filter((t) => t.toolCallId !== toolCallId);\n if (filtered.length === 0) {\n this._pendingToolsByName.delete(pendingTool.toolName);\n } else {\n this._pendingToolsByName.set(pendingTool.toolName, filtered);\n }\n }\n this.updatePendingClientToolsCache();\n\n const toolResult: ToolResult = {\n toolCallId,\n toolName: pendingTool.toolName,\n result: error ? undefined : result,\n error,\n outputVariable: pendingTool.outputVariable,\n blockIndex: pendingTool.blockIndex,\n };\n this._completedToolResults.push(toolResult);\n\n if (error) {\n this.emitToolOutputError(toolCallId, error);\n } else {\n this.emitToolOutputAvailable(toolCallId, result);\n }\n\n if (this._pendingToolsByCallId.size === 0) {\n void this.continueWithClientToolResults();\n }\n\n this.notifyListeners();\n }\n\n /** Stop the current streaming and finalize any partial message */\n stop(): void {\n if (this._status !== 'streaming' && this._status !== 'awaiting-input') {\n return;\n }\n\n this._clientToolAbortController?.abort();\n this._clientToolAbortController = null;\n this._pendingToolsByName.clear();\n this._pendingToolsByCallId.clear();\n this._completedToolResults = [];\n this._serverToolResults = [];\n this._pendingExecutionId = null;\n this._readyToContinue = false;\n this.updatePendingClientToolsCache();\n\n this.transport.stop();\n\n const state = this.streamingState;\n if (state && state.parts.length > 0) {\n // Mark in-progress parts as cancelled/done\n const finalParts = state.parts.map((part): UIMessagePart => {\n if (part.type === 'tool-call') {\n const toolPart = part;\n // Mark pending/running tools as cancelled\n if (toolPart.status === 'pending' || toolPart.status === 'running') {\n return { ...toolPart, status: 'cancelled' };\n }\n }\n if (part.type === 'operation') {\n const opPart = part;\n // Mark running operations as cancelled\n if (opPart.status === 'running') {\n return { ...opPart, status: 'cancelled' };\n }\n }\n if (part.type === 'text' || part.type === 'reasoning') {\n const textPart = part;\n // Mark streaming text/reasoning as done (it's not an error)\n if (textPart.status === 'streaming') {\n return { ...textPart, status: 'done' };\n }\n }\n if (part.type === 'object') {\n const objPart = part;\n // Mark streaming objects as done\n if (objPart.status === 'streaming') {\n return { ...objPart, status: 'done' };\n }\n }\n return part;\n });\n\n const finalMessage: UIMessage = {\n id: state.messageId,\n role: 'assistant',\n parts: finalParts,\n status: 'done',\n createdAt: new Date(),\n };\n\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n }\n\n this.streamingState = null;\n this.setStatus('idle');\n this.options.onStop?.();\n }\n\n // =========================================================================\n // Private Helpers\n // =========================================================================\n\n private handleStreamEvent(event: StreamEvent, state: StreamingState): void {\n switch (event.type) {\n case 'start':\n break;\n\n case 'block-start': {\n const block: BlockState = {\n blockId: event.blockId,\n blockName: event.blockName,\n blockType: event.blockType,\n display: event.display,\n description: event.description,\n outputToChat: event.outputToChat ?? true,\n thread: event.thread,\n reasoning: '',\n text: '',\n toolCalls: new Map(),\n };\n state.blocks.set(event.blockId, block);\n state.activeBlock = block;\n\n const isOperation = OPERATION_BLOCK_TYPES.has(event.blockType);\n const isHidden = event.display === 'hidden';\n if (isOperation && !isHidden) {\n const thread = event.thread;\n const operationPart: UIOperationPart = {\n type: 'operation',\n operationId: event.blockId,\n name: event.description ?? event.blockName,\n operationType: event.blockType,\n status: 'running',\n thread: threadForPart(thread),\n };\n state.parts.push(operationPart);\n }\n\n state.currentTextPartIndex = null;\n state.currentReasoningPartIndex = null;\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'block-end': {\n const operationPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'operation' && p.operationId === event.blockId,\n );\n if (operationPartIndex >= 0) {\n const part = state.parts[operationPartIndex] as UIOperationPart;\n state.parts[operationPartIndex] = { ...part, status: 'done' };\n }\n\n if (state.activeBlock?.blockId === event.blockId) {\n state.activeBlock = null;\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'reasoning-start': {\n const reasoningPart: UIReasoningPart = {\n type: 'reasoning',\n text: '',\n status: 'streaming',\n thread: threadForPart(state.activeBlock?.thread),\n };\n state.parts.push(reasoningPart);\n state.currentReasoningPartIndex = state.parts.length - 1;\n this.updateStreamingMessage();\n break;\n }\n\n case 'reasoning-delta': {\n if (state.currentReasoningPartIndex !== null) {\n const part = state.parts[state.currentReasoningPartIndex] as UIReasoningPart;\n part.text += event.delta;\n state.parts[state.currentReasoningPartIndex] = { ...part };\n }\n\n if (state.activeBlock) {\n state.activeBlock.reasoning += event.delta;\n }\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'reasoning-end': {\n if (state.currentReasoningPartIndex !== null) {\n const part = state.parts[state.currentReasoningPartIndex] as UIReasoningPart;\n part.status = 'done';\n state.parts[state.currentReasoningPartIndex] = { ...part };\n state.currentReasoningPartIndex = null;\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'text-start': {\n const thread = threadForPart(state.activeBlock?.thread);\n const shouldAddPart = state.activeBlock?.outputToChat !== false || thread !== undefined;\n\n if (shouldAddPart) {\n // Structured output mode: accumulate JSON and parse progressively\n if (event.responseType) {\n const objectPart: UIObjectPart = {\n type: 'object',\n id: event.id,\n typeName: event.responseType,\n partial: undefined,\n object: undefined,\n status: 'streaming',\n thread,\n };\n state.parts.push(objectPart);\n state.currentObjectPartIndex = state.parts.length - 1;\n state.accumulatedJson = '';\n state.currentTextPartIndex = null;\n } else {\n const textPart: UITextPart = {\n type: 'text',\n text: '',\n status: 'streaming',\n thread,\n };\n state.parts.push(textPart);\n state.currentTextPartIndex = state.parts.length - 1;\n state.currentObjectPartIndex = null;\n }\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'text-delta': {\n if (state.currentObjectPartIndex !== null) {\n state.accumulatedJson += event.delta;\n const part = state.parts[state.currentObjectPartIndex] as UIObjectPart;\n const parsed = parsePartialJson(state.accumulatedJson);\n if (parsed !== undefined) {\n part.partial = parsed;\n state.parts[state.currentObjectPartIndex] = { ...part };\n }\n } else if (state.currentTextPartIndex !== null) {\n const part = state.parts[state.currentTextPartIndex] as UITextPart;\n part.text += event.delta;\n state.parts[state.currentTextPartIndex] = { ...part };\n }\n\n if (state.activeBlock) {\n state.activeBlock.text += event.delta;\n }\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'text-end': {\n if (state.currentObjectPartIndex !== null) {\n const part = state.parts[state.currentObjectPartIndex] as UIObjectPart;\n try {\n const finalObject = JSON.parse(state.accumulatedJson) as unknown;\n part.object = finalObject;\n part.partial = finalObject;\n part.status = 'done';\n } catch {\n // Keep partial data but mark as error\n part.status = 'error';\n part.error = 'Failed to parse response as JSON';\n }\n state.parts[state.currentObjectPartIndex] = { ...part };\n state.currentObjectPartIndex = null;\n state.accumulatedJson = '';\n } else if (state.currentTextPartIndex !== null) {\n const part = state.parts[state.currentTextPartIndex] as UITextPart;\n part.status = 'done';\n state.parts[state.currentTextPartIndex] = { ...part };\n state.currentTextPartIndex = null;\n }\n this.updateStreamingMessage();\n break;\n }\n\n case 'tool-input-start': {\n const toolPart: UIToolCallPart = {\n type: 'tool-call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n displayName: event.title,\n args: {},\n status: 'pending',\n thread: threadForPart(state.activeBlock?.thread),\n };\n state.parts.push(toolPart);\n\n if (state.activeBlock) {\n state.activeBlock.toolCalls.set(event.toolCallId, toolPart);\n }\n\n this.updateStreamingMessage();\n break;\n }\n\n case 'tool-input-delta': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n try {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.args = JSON.parse(event.inputTextDelta) as Record<string, unknown>;\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n } catch {\n // Partial JSON, ignore\n }\n }\n break;\n }\n\n case 'tool-input-end':\n // Input streaming ended, wait for tool-input-available\n break;\n\n case 'tool-input-available': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.args = event.input as Record<string, unknown>;\n part.status = 'running';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n break;\n }\n\n case 'tool-output-available': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.result = event.output;\n part.status = 'done';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n break;\n }\n\n case 'tool-output-error': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.error = event.error;\n part.status = 'error';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n break;\n }\n\n case 'source': {\n // Add source (URL or document) as a part\n const thread = threadForPart(state.activeBlock?.thread);\n\n let sourcePart: UISourcePart;\n if (event.sourceType === 'url') {\n sourcePart = {\n type: 'source',\n sourceType: 'url',\n id: event.id,\n url: event.url,\n title: event.title,\n thread,\n };\n } else {\n sourcePart = {\n type: 'source',\n sourceType: 'document',\n id: event.id,\n mediaType: event.mediaType,\n title: event.title,\n filename: event.filename,\n thread,\n };\n }\n\n state.parts.push(sourcePart);\n this.updateStreamingMessage();\n break;\n }\n\n case 'file-available': {\n // Add generated file as a part\n const filePart: UIFilePart = {\n type: 'file',\n id: event.id,\n mediaType: event.mediaType,\n url: event.url,\n filename: event.filename,\n size: event.size,\n toolCallId: event.toolCallId,\n thread: threadForPart(state.activeBlock?.thread),\n };\n state.parts.push(filePart);\n this.updateStreamingMessage();\n break;\n }\n\n case 'resource-update':\n this.options.onResourceUpdate?.(event.name, event.value);\n break;\n\n case 'finish': {\n // Handle client-tool-calls finish reason\n if (event.finishReason === 'client-tool-calls') {\n // Don't finalize message - we're waiting for client tools\n if (this._pendingToolsByCallId.size > 0) {\n this.setStatus('awaiting-input');\n } else if (this._readyToContinue) {\n // Automatic tools completed before finish event arrived - continue now\n this._readyToContinue = false;\n void this.continueWithClientToolResults();\n }\n return;\n }\n\n const finalMessage = buildMessageFromState(state, 'done');\n\n finalMessage.parts = finalMessage.parts.map((part) => {\n if (part.type === 'text' || part.type === 'reasoning') {\n return { ...part, status: 'done' as const };\n }\n if (part.type === 'object' && part.status === 'streaming') {\n return { ...part, status: 'done' as const };\n }\n return part;\n });\n\n if (finalMessage.parts.length > 0) {\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n }\n\n this.setStatus('idle');\n this.streamingState = null;\n this.options.onFinish?.();\n break;\n }\n\n case 'error': {\n // Create structured error from the error event\n throw new OctavusError({\n errorType: event.errorType,\n message: event.message,\n source: event.source,\n retryable: event.retryable,\n retryAfter: event.retryAfter,\n code: event.code,\n provider: event.provider,\n tool: event.tool,\n });\n }\n\n case 'tool-request':\n // Handled by server-sdk, not relevant for UI\n break;\n\n case 'client-tool-request':\n // Store execution ID and server tool results for continuation\n this._pendingExecutionId = event.executionId;\n this._serverToolResults = event.serverToolResults ?? [];\n // Handle client-side tool execution\n void this.handleClientToolRequest(event.toolCalls, state);\n break;\n }\n }\n\n private updateStreamingMessage(): void {\n const state = this.streamingState;\n if (!state) return;\n\n const msg = buildMessageFromState(state, 'streaming');\n const messages = [...this._messages];\n\n const lastMsg = messages[messages.length - 1];\n if (lastMsg?.id === state.messageId) {\n messages[messages.length - 1] = msg;\n } else {\n messages.push(msg);\n }\n\n this.setMessages(messages);\n }\n\n /**\n * Emit a tool-output-available event for a client tool result.\n */\n private emitToolOutputAvailable(toolCallId: string, output: unknown): void {\n const state = this.streamingState;\n if (!state) return;\n\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.result = output;\n part.status = 'done';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n }\n\n /**\n * Emit a tool-output-error event for a client tool result.\n */\n private emitToolOutputError(toolCallId: string, error: string): void {\n const state = this.streamingState;\n if (!state) return;\n\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.error = error;\n part.status = 'error';\n state.parts[toolPartIndex] = { ...part };\n this.updateStreamingMessage();\n }\n }\n\n /**\n * Continue execution with collected client tool results.\n */\n private async continueWithClientToolResults(): Promise<void> {\n if (this._completedToolResults.length === 0) return;\n\n if (this._pendingExecutionId === null) {\n // Context lost - this shouldn't happen, but handle gracefully\n const errorObj = new OctavusError({\n errorType: 'internal_error',\n message: 'Cannot continue execution: execution ID was lost.',\n source: 'client',\n retryable: false,\n });\n this.setError(errorObj);\n this.setStatus('error');\n this.options.onError?.(errorObj);\n return;\n }\n\n // Combine server results (from mixed tools scenario) with client results\n const allResults = [...this._serverToolResults, ...this._completedToolResults];\n const executionId = this._pendingExecutionId;\n this._serverToolResults = [];\n this._completedToolResults = [];\n this._pendingExecutionId = null;\n\n this.setStatus('streaming');\n\n try {\n // Use the transport's continuation method (works for both HTTP and Socket)\n for await (const event of this.transport.continueWithToolResults(executionId, allResults)) {\n if (this.streamingState === null) break;\n this.handleStreamEvent(event, this.streamingState);\n }\n } catch (err) {\n const errorObj = OctavusError.isInstance(err)\n ? err\n : new OctavusError({\n errorType: 'internal_error',\n message: err instanceof Error ? err.message : 'Unknown error',\n source: 'client',\n retryable: false,\n cause: err,\n });\n\n this.setError(errorObj);\n this.setStatus('error');\n this.streamingState = null;\n this.options.onError?.(errorObj);\n }\n }\n\n /**\n * Handle client tool request event.\n *\n * IMPORTANT: Interactive tools must be registered synchronously (before any await)\n * to avoid a race condition where the finish event is processed before tools are added.\n */\n private async handleClientToolRequest(\n toolCalls: PendingToolCall[],\n state: StreamingState,\n ): Promise<void> {\n this._clientToolAbortController = new AbortController();\n\n // FIRST PASS: Register all interactive tools synchronously (no await)\n // This ensures pending tools are populated before finish event is processed\n for (const tc of toolCalls) {\n const handler = this.options.clientTools?.[tc.toolName];\n if (handler === 'interactive') {\n const toolState: PendingToolState = {\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n args: tc.args,\n source: tc.source,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n };\n // Add to both maps\n this._pendingToolsByCallId.set(tc.toolCallId, toolState);\n const existing = this._pendingToolsByName.get(tc.toolName) ?? [];\n this._pendingToolsByName.set(tc.toolName, [...existing, toolState]);\n }\n }\n if (this._pendingToolsByCallId.size > 0) {\n this.updatePendingClientToolsCache();\n }\n\n // SECOND PASS: Execute automatic handlers and handle missing handlers\n for (const tc of toolCalls) {\n const handler = this.options.clientTools?.[tc.toolName];\n\n if (handler === 'interactive') {\n // Already registered above, just update UI state\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === tc.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n // Keep running status - user will see the tool is \"executing\" while modal is open\n state.parts[toolPartIndex] = { ...part };\n }\n } else if (handler) {\n try {\n const result = await handler(tc.args, {\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n signal: this._clientToolAbortController.signal,\n });\n\n this._completedToolResults.push({\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n result,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n });\n\n this.emitToolOutputAvailable(tc.toolCallId, result);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Tool execution failed';\n this._completedToolResults.push({\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n error: errorMessage,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n });\n\n this.emitToolOutputError(tc.toolCallId, errorMessage);\n }\n } else {\n // No handler registered - treat as error\n const errorMessage = `No client handler for tool: ${tc.toolName}`;\n this._completedToolResults.push({\n toolCallId: tc.toolCallId,\n toolName: tc.toolName,\n error: errorMessage,\n outputVariable: tc.outputVariable,\n blockIndex: tc.blockIndex,\n });\n\n this.emitToolOutputError(tc.toolCallId, errorMessage);\n }\n }\n\n // If no interactive tools, mark as ready to continue.\n // We wait for the finish event to arrive first to avoid a race condition where\n // the finish event gets delivered to the continuation's event resolver.\n if (this._pendingToolsByCallId.size === 0 && this._completedToolResults.length > 0) {\n this._readyToContinue = true;\n }\n }\n}\n","import type { FileReference } from '@octavus/core';\n\n/**\n * Response from the upload URLs endpoint\n */\nexport interface UploadUrlsResponse {\n files: {\n id: string;\n uploadUrl: string;\n downloadUrl: string;\n }[];\n}\n\n/**\n * Options for uploading files\n */\nexport interface UploadFilesOptions {\n /**\n * Function to request upload URLs from the platform.\n * Consumer apps must implement this to authenticate with the platform.\n *\n * @param files - Array of file metadata to request URLs for\n * @returns Response with presigned upload and download URLs\n *\n * @example\n * ```typescript\n * requestUploadUrls: async (files) => {\n * const response = await fetch('/api/upload-urls', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, files }),\n * });\n * return response.json();\n * }\n * ```\n */\n requestUploadUrls: (\n files: { filename: string; mediaType: string; size: number }[],\n ) => Promise<UploadUrlsResponse>;\n\n /**\n * Callback for upload progress (0-100 per file).\n * Called multiple times during upload with real-time progress.\n *\n * @param fileIndex - Index of the file being uploaded\n * @param progress - Progress percentage (0-100)\n */\n onProgress?: (fileIndex: number, progress: number) => void;\n}\n\n/**\n * Upload a single file to S3 with progress tracking.\n * Uses XMLHttpRequest for upload progress events (fetch doesn't support this).\n */\nfunction uploadFileWithProgress(\n url: string,\n file: File,\n onProgress?: (progress: number) => void,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n\n xhr.upload.addEventListener('progress', (event) => {\n if (event.lengthComputable) {\n const progress = Math.round((event.loaded / event.total) * 100);\n onProgress?.(progress);\n }\n });\n\n xhr.addEventListener('load', () => {\n if (xhr.status >= 200 && xhr.status < 300) {\n resolve();\n } else {\n reject(new Error(`Upload failed with status ${xhr.status}`));\n }\n });\n\n xhr.addEventListener('error', () => {\n reject(new Error('Upload failed: network error'));\n });\n\n xhr.addEventListener('abort', () => {\n reject(new Error('Upload aborted'));\n });\n\n xhr.open('PUT', url);\n xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');\n xhr.send(file);\n });\n}\n\n/**\n * Upload files to the Octavus platform.\n *\n * This function:\n * 1. Requests presigned upload URLs from the platform\n * 2. Uploads each file directly to S3 with progress tracking\n * 3. Returns file references that can be used in trigger input\n *\n * @param files - Files to upload (from file input or drag/drop)\n * @param options - Upload configuration\n * @returns Array of file references with download URLs\n *\n * @example\n * ```typescript\n * const fileRefs = await uploadFiles(fileInputRef.current.files, {\n * requestUploadUrls: async (files) => {\n * const response = await fetch('/api/upload-urls', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, files }),\n * });\n * return response.json();\n * },\n * onProgress: (fileIndex, progress) => {\n * console.log(`File ${fileIndex}: ${progress}%`);\n * },\n * });\n * ```\n */\nexport async function uploadFiles(\n files: FileList | File[],\n options: UploadFilesOptions,\n): Promise<FileReference[]> {\n const fileArray = Array.from(files);\n\n if (fileArray.length === 0) {\n return [];\n }\n\n const { files: uploadInfos } = await options.requestUploadUrls(\n fileArray.map((f) => ({\n filename: f.name,\n mediaType: f.type || 'application/octet-stream',\n size: f.size,\n })),\n );\n\n const references: FileReference[] = [];\n\n for (let i = 0; i < fileArray.length; i++) {\n const file = fileArray[i]!;\n const uploadInfo = uploadInfos[i]!;\n\n await uploadFileWithProgress(uploadInfo.uploadUrl, file, (progress) => {\n options.onProgress?.(i, progress);\n });\n\n references.push({\n id: uploadInfo.id,\n mediaType: file.type || 'application/octet-stream',\n url: uploadInfo.downloadUrl,\n filename: file.name,\n size: file.size,\n });\n }\n\n return references;\n}\n","import { safeParseStreamEvent, isAbortError, type StreamEvent } from '@octavus/core';\n\n/**\n * Parse SSE stream events.\n *\n * @param response - The HTTP response with SSE body\n * @param signal - Optional abort signal to cancel reading\n */\nexport async function* parseSSEStream(\n response: Response,\n signal?: AbortSignal,\n): AsyncGenerator<StreamEvent, void, unknown> {\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('Response body is not readable');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n try {\n let reading = true;\n while (reading) {\n // Check if aborted before reading\n if (signal?.aborted) {\n return;\n }\n\n let readResult: ReadableStreamReadResult<Uint8Array>;\n try {\n readResult = await reader.read();\n } catch (err) {\n // Handle abort errors gracefully - exit without throwing\n if (isAbortError(err)) {\n return;\n }\n throw err;\n }\n\n const { done, value } = readResult;\n\n if (done) {\n reading = false;\n continue;\n }\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ') && line !== 'data: [DONE]') {\n try {\n const parsed = safeParseStreamEvent(JSON.parse(line.slice(6)));\n if (parsed.success) {\n yield parsed.data;\n }\n // Skip malformed events silently\n } catch {\n // Skip malformed JSON - no logging in production\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n","import type { StreamEvent, ToolResult } from '@octavus/core';\n\n// =============================================================================\n// Base Transport Interface\n// =============================================================================\n\n/**\n * Transport interface for delivering events from server to client.\n *\n * Abstracts the connection mechanism (HTTP/SSE or WebSocket) behind a unified\n * async iterator interface. Use `createHttpTransport` or `createSocketTransport`\n * to create an implementation.\n */\nexport interface Transport {\n /**\n * Trigger the agent and stream events.\n * @param triggerName - The trigger name defined in the agent's protocol\n * @param input - Input parameters for variable substitution\n */\n trigger(triggerName: string, input?: Record<string, unknown>): AsyncIterable<StreamEvent>;\n\n /**\n * Continue execution with tool results after client-side tool handling.\n *\n * @param executionId - The execution ID from the client-tool-request event\n * @param results - All tool results (server + client) to send\n */\n continueWithToolResults(executionId: string, results: ToolResult[]): AsyncIterable<StreamEvent>;\n\n /** Stop the current stream. Safe to call when no stream is active. */\n stop(): void;\n}\n\n// =============================================================================\n// Socket Transport (extends Transport with connection management)\n// =============================================================================\n\n/**\n * Connection states for socket transport.\n *\n * - `disconnected`: Not connected (initial state or after disconnect)\n * - `connecting`: Connection attempt in progress\n * - `connected`: Successfully connected and ready\n * - `error`: Connection failed (check error in listener callback)\n */\nexport type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';\n\n/**\n * Callback for connection state changes.\n */\nexport type ConnectionStateListener = (state: ConnectionState, error?: Error) => void;\n\n/**\n * Socket transport with connection management capabilities.\n *\n * Extends the base Transport interface with methods for managing persistent\n * WebSocket/SockJS connections. Use this when you need:\n * - Eager connection (connect before first message)\n * - Connection status UI indicators\n * - Manual connection lifecycle control\n *\n * Created via `createSocketTransport()`.\n */\nexport interface SocketTransport extends Transport {\n /**\n * Current connection state.\n *\n * - `disconnected`: Not connected (initial state)\n * - `connecting`: Connection in progress\n * - `connected`: Ready to send/receive\n * - `error`: Connection failed\n */\n readonly connectionState: ConnectionState;\n\n /**\n * Subscribe to connection state changes.\n *\n * The listener is called immediately with the current state, then again\n * whenever the state changes.\n *\n * @param listener - Callback invoked on state changes\n * @returns Unsubscribe function\n *\n * @example\n * ```typescript\n * const unsubscribe = transport.onConnectionStateChange((state, error) => {\n * setConnectionState(state);\n * if (error) setConnectionError(error);\n * });\n * ```\n */\n onConnectionStateChange(listener: ConnectionStateListener): () => void;\n\n /**\n * Eagerly establish the connection.\n *\n * By default, socket transport connects lazily on first `trigger()`. Call\n * this method to establish the connection early (e.g., on component mount):\n * - Faster first message response\n * - Show accurate connection status in UI\n * - Handle connection errors before user interaction\n *\n * Safe to call multiple times - resolves immediately if already connected.\n *\n * @example\n * ```tsx\n * useEffect(() => {\n * transport.connect()\n * .then(() => console.log('Connected'))\n * .catch((err) => console.error('Failed:', err));\n *\n * return () => transport.disconnect();\n * }, [transport]);\n * ```\n */\n connect(): Promise<void>;\n\n /**\n * Close the connection and clean up resources.\n *\n * The transport will reconnect automatically on next `trigger()` call.\n */\n disconnect(): void;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if a transport is a SocketTransport with connection management.\n *\n * @example\n * ```typescript\n * if (isSocketTransport(transport)) {\n * transport.connect(); // TypeScript knows this is available\n * }\n * ```\n */\nexport function isSocketTransport(transport: Transport): transport is SocketTransport {\n return (\n 'connect' in transport &&\n 'disconnect' in transport &&\n 'connectionState' in transport &&\n 'onConnectionStateChange' in transport\n );\n}\n","import { isAbortError, type ToolResult } from '@octavus/core';\nimport { parseSSEStream } from '@/stream/reader';\nimport type { Transport } from './types';\n\n// =============================================================================\n// Request Types\n// =============================================================================\n\n/** Start a new trigger execution */\nexport interface TriggerRequest {\n type: 'trigger';\n triggerName: string;\n input?: Record<string, unknown>;\n}\n\n/** Continue execution after client-side tool handling */\nexport interface ContinueRequest {\n type: 'continue';\n executionId: string;\n toolResults: ToolResult[];\n}\n\n/** All request types supported by the HTTP transport */\nexport type HttpRequest = TriggerRequest | ContinueRequest;\n\n// =============================================================================\n// Transport Options\n// =============================================================================\n\n/** Request options passed to the request callback */\nexport interface HttpRequestOptions {\n /** Abort signal to cancel the request */\n signal?: AbortSignal;\n}\n\n/**\n * Options for creating an HTTP transport.\n */\nexport interface HttpTransportOptions {\n /**\n * Function to make requests to your backend.\n * Receives a discriminated union with `type` to identify the request kind.\n *\n * @param request - The request payload (check `request.type` for the kind)\n * @param options - Request options including abort signal\n * @returns Response with SSE stream body\n *\n * @example\n * ```typescript\n * request: (payload, options) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, ...payload }),\n * signal: options?.signal,\n * })\n * ```\n */\n request: (request: HttpRequest, options?: HttpRequestOptions) => Promise<Response>;\n}\n\n// =============================================================================\n// Transport Implementation\n// =============================================================================\n\n/**\n * Create an HTTP transport using native fetch() and SSE parsing.\n * This is the default transport for Next.js and other HTTP-based applications.\n *\n * @example\n * ```typescript\n * const transport = createHttpTransport({\n * request: (payload, options) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ sessionId, ...payload }),\n * signal: options?.signal,\n * }),\n * });\n * ```\n */\nexport function createHttpTransport(options: HttpTransportOptions): Transport {\n let abortController: AbortController | null = null;\n\n async function* streamResponse(responsePromise: Promise<Response>) {\n try {\n const response = await responsePromise;\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => `Request failed: ${response.status}`);\n throw new Error(errorText);\n }\n\n if (!response.body) {\n throw new Error('Response body is empty');\n }\n\n for await (const event of parseSSEStream(response, abortController!.signal)) {\n if (abortController?.signal.aborted) {\n break;\n }\n yield event;\n }\n } catch (err) {\n if (isAbortError(err)) {\n return;\n }\n throw err;\n }\n }\n\n return {\n async *trigger(triggerName, input) {\n abortController = new AbortController();\n const response = options.request(\n { type: 'trigger', triggerName, input },\n { signal: abortController.signal },\n );\n yield* streamResponse(response);\n },\n\n async *continueWithToolResults(executionId, toolResults) {\n abortController = new AbortController();\n const response = options.request(\n { type: 'continue', executionId, toolResults },\n { signal: abortController.signal },\n );\n yield* streamResponse(response);\n },\n\n stop() {\n abortController?.abort();\n abortController = null;\n },\n };\n}\n","import { safeParseStreamEvent, type StreamEvent, type ToolResult } from '@octavus/core';\nimport type { SocketTransport, ConnectionState, ConnectionStateListener } from './types';\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Socket interface compatible with both WebSocket and SockJS.\n *\n * Uses MessageEvent for the message handler, which both WebSocket and SockJS support.\n * The `| undefined` union accommodates SockJS's optional property typing.\n */\nexport interface SocketLike {\n send(data: string): void;\n close(): void;\n readyState: number;\n onmessage: ((event: MessageEvent) => void) | null | undefined;\n onclose: ((event: CloseEvent) => void) | null | undefined;\n}\n\n/** WebSocket readyState constants */\nconst SOCKET_OPEN = 1;\n\n// =============================================================================\n// Transport Options\n// =============================================================================\n\n/**\n * Options for creating a socket transport.\n */\nexport interface SocketTransportOptions {\n /**\n * Function to create and connect the socket.\n * Works directly with WebSocket and SockJS - no wrappers needed.\n *\n * @example Native WebSocket\n * ```typescript\n * connect: () => new Promise((resolve, reject) => {\n * const ws = new WebSocket('wss://api.example.com/stream?sessionId=xxx');\n * ws.onopen = () => resolve(ws);\n * ws.onerror = () => reject(new Error('Connection failed'));\n * })\n * ```\n *\n * @example SockJS\n * ```typescript\n * connect: () => new Promise((resolve, reject) => {\n * const sock = new SockJS('/chat-service');\n * sock.onopen = () => resolve(sock);\n * sock.onerror = () => reject(new Error('Connection failed'));\n * })\n * ```\n */\n connect: () => Promise<SocketLike>;\n\n /**\n * Called for every message received (parsed as JSON).\n * Use this to handle custom (non-Octavus) events.\n * Octavus StreamEvents are handled automatically by the transport.\n *\n * @example\n * ```typescript\n * onMessage: (data) => {\n * const msg = data as { type: string };\n * if (msg.type === 'typing-indicator') {\n * setIsTyping(true);\n * }\n * if (msg.type === 'presence-update') {\n * updatePresence(msg.users);\n * }\n * }\n * ```\n */\n onMessage?: (data: unknown) => void;\n\n /**\n * Called when the socket connection closes.\n * Use this for cleanup or reconnection logic.\n */\n onClose?: () => void;\n}\n\n/**\n * Create a socket transport that works with any WebSocket-like connection.\n * Supports native WebSocket, SockJS, or any compatible socket implementation.\n *\n * The server should send StreamEvent format (same as SSE) over the socket.\n * Unknown events are safely ignored using Zod validation.\n *\n * ## Connection Lifecycle\n *\n * By default, the socket connects **lazily** on the first `send()` call.\n * Use `connect()` to establish the connection eagerly (e.g., on component mount):\n *\n * ```typescript\n * // Eager connection for UI status indicators\n * useEffect(() => {\n * transport.connect()\n * .then(() => console.log('Connected'))\n * .catch((err) => console.error('Failed:', err));\n *\n * return () => transport.disconnect();\n * }, [transport]);\n * ```\n *\n * @example Basic usage with WebSocket\n * ```typescript\n * const transport = createSocketTransport({\n * connect: () => new Promise((resolve, reject) => {\n * const ws = new WebSocket(`wss://api.octavus.ai/stream?sessionId=${sessionId}`);\n * ws.onopen = () => resolve(ws);\n * ws.onerror = () => reject(new Error('Connection failed'));\n * }),\n * });\n * ```\n *\n * @example With SockJS and connection state\n * ```typescript\n * const transport = createSocketTransport({\n * connect: () => new Promise((resolve, reject) => {\n * const sock = new SockJS('/octavus-stream');\n * sock.onopen = () => resolve(sock);\n * sock.onerror = () => reject(new Error('Connection failed'));\n * }),\n * });\n *\n * // Subscribe to connection state changes\n * transport.onConnectionStateChange((state, error) => {\n * setConnectionState(state);\n * if (error) setConnectionError(error);\n * });\n * ```\n */\nexport function createSocketTransport(options: SocketTransportOptions): SocketTransport {\n let socket: SocketLike | null = null;\n let eventQueue: StreamEvent[] = [];\n let eventResolver: ((event: StreamEvent | null) => void) | null = null;\n let isStreaming = false;\n\n let connectionState: ConnectionState = 'disconnected';\n let connectionError: Error | undefined;\n let connectionPromise: Promise<void> | null = null;\n const connectionListeners = new Set<ConnectionStateListener>();\n\n function setConnectionState(state: ConnectionState, error?: Error) {\n connectionState = state;\n connectionError = error;\n connectionListeners.forEach((listener) => listener(state, error));\n }\n\n function enqueueEvent(event: StreamEvent) {\n if (eventResolver) {\n eventResolver(event);\n eventResolver = null;\n } else {\n eventQueue.push(event);\n }\n }\n\n function nextEvent(): Promise<StreamEvent | null> {\n if (eventQueue.length > 0) {\n return Promise.resolve(eventQueue.shift()!);\n }\n if (!isStreaming) {\n return Promise.resolve(null);\n }\n return new Promise((resolve) => {\n eventResolver = resolve;\n });\n }\n\n function setupSocketHandlers(sock: SocketLike): void {\n sock.onmessage = (e: MessageEvent) => {\n try {\n const data: unknown = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;\n\n options.onMessage?.(data);\n\n const result = safeParseStreamEvent(data);\n if (result.success) {\n const event = result.data;\n enqueueEvent(event);\n\n if (event.type === 'finish' || event.type === 'error') {\n isStreaming = false;\n }\n }\n } catch {\n // Malformed JSON, skip\n }\n };\n\n sock.onclose = () => {\n socket = null;\n connectionPromise = null;\n setConnectionState('disconnected');\n options.onClose?.();\n\n isStreaming = false;\n if (eventResolver) {\n eventResolver(null);\n eventResolver = null;\n }\n };\n }\n\n async function ensureConnected(): Promise<void> {\n // Already connected\n if (socket?.readyState === SOCKET_OPEN) {\n return;\n }\n\n // Connection in progress - wait for it\n if (connectionPromise) {\n await connectionPromise;\n return;\n }\n\n // Start new connection\n setConnectionState('connecting');\n\n connectionPromise = (async () => {\n try {\n const sock = await options.connect();\n socket = sock;\n setupSocketHandlers(sock);\n setConnectionState('connected');\n } catch (err) {\n socket = null;\n connectionPromise = null;\n const error = err instanceof Error ? err : new Error('Connection failed');\n setConnectionState('error', error);\n throw error;\n }\n })();\n\n await connectionPromise;\n }\n\n return {\n // =========================================================================\n // Connection Management\n // =========================================================================\n\n get connectionState(): ConnectionState {\n return connectionState;\n },\n\n onConnectionStateChange(listener: ConnectionStateListener): () => void {\n connectionListeners.add(listener);\n // Immediately notify with current state\n listener(connectionState, connectionError);\n return () => connectionListeners.delete(listener);\n },\n\n async connect(): Promise<void> {\n await ensureConnected();\n },\n\n disconnect(): void {\n if (socket) {\n socket.close();\n socket = null;\n }\n connectionPromise = null;\n isStreaming = false;\n if (eventResolver) {\n eventResolver(null);\n eventResolver = null;\n }\n setConnectionState('disconnected');\n },\n\n // =========================================================================\n // Streaming\n // =========================================================================\n\n async *trigger(triggerName, input) {\n await ensureConnected();\n\n eventQueue = [];\n eventResolver = null; // Clear any pending resolver\n isStreaming = true;\n\n // Note: clientToolResults not sent here - socket uses sendClientToolResults() for continuation\n socket!.send(\n JSON.stringify({\n type: 'trigger',\n triggerName,\n input,\n }),\n );\n\n while (true) {\n const event = await nextEvent();\n if (event === null) break;\n yield event;\n if (event.type === 'finish' || event.type === 'error') break;\n }\n },\n\n stop() {\n if (socket?.readyState === SOCKET_OPEN) {\n socket.send(JSON.stringify({ type: 'stop' }));\n }\n isStreaming = false;\n if (eventResolver) {\n eventResolver(null);\n eventResolver = null;\n }\n },\n\n /**\n * Continue execution with tool results after client-side tool handling.\n * @param executionId - The execution ID from the client-tool-request event\n * @param toolResults - All tool results (server + client) to send\n */\n async *continueWithToolResults(executionId: string, toolResults: ToolResult[]) {\n await ensureConnected();\n\n eventQueue = [];\n eventResolver = null; // Clear any pending resolver from previous operation\n isStreaming = true;\n\n socket!.send(\n JSON.stringify({\n type: 'continue',\n executionId,\n toolResults,\n }),\n );\n\n while (true) {\n const event = await nextEvent();\n if (event === null) break;\n yield event;\n if (event.type === 'finish' || event.type === 'error') break;\n }\n },\n };\n}\n","export {\n OctavusChat,\n type OctavusChatOptions,\n type ChatStatus,\n type UserMessageInput,\n type ClientToolContext,\n type ClientToolHandler,\n type InteractiveTool,\n} from './chat';\n\nexport { uploadFiles, type UploadFilesOptions, type UploadUrlsResponse } from './files';\n\nexport { parseSSEStream } from './stream/reader';\n\n// Transport exports\nexport {\n createHttpTransport,\n createSocketTransport,\n isSocketTransport,\n type Transport,\n type SocketTransport,\n type ConnectionState,\n type ConnectionStateListener,\n type HttpTransportOptions,\n type HttpRequestOptions,\n type HttpRequest,\n type TriggerRequest,\n type ContinueRequest,\n type SocketLike,\n type SocketTransportOptions,\n} from './transports';\n\nexport type * from '@octavus/core';\nexport {\n // Error classes\n AppError,\n NotFoundError,\n ValidationError,\n ConflictError,\n ForbiddenError,\n OctavusError,\n // Error type guards\n isRateLimitError,\n isAuthenticationError,\n isProviderError,\n isToolError,\n isRetryableError,\n isValidationError,\n // Error event helpers\n createErrorEvent,\n errorToStreamEvent,\n createInternalErrorEvent,\n createApiErrorEvent,\n // Utilities\n generateId,\n isAbortError,\n // Thread helpers\n MAIN_THREAD,\n resolveThread,\n isMainThread,\n threadForPart,\n isOtherThread,\n // Type guards\n isFileReference,\n isFileReferenceArray,\n // Safe parse helpers\n safeParseStreamEvent,\n safeParseUIMessage,\n safeParseUIMessages,\n // Skills\n OCTAVUS_SKILL_TOOLS,\n isOctavusSkillTool,\n getSkillSlugFromToolCall,\n} from '@octavus/core';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAeK;;;ACmCP,SAAS,uBACP,KACA,MACA,YACe;AACf,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,MAAM,IAAI,eAAe;AAE/B,QAAI,OAAO,iBAAiB,YAAY,CAAC,UAAU;AACjD,UAAI,MAAM,kBAAkB;AAC1B,cAAM,WAAW,KAAK,MAAO,MAAM,SAAS,MAAM,QAAS,GAAG;AAC9D,qBAAa,QAAQ;AAAA,MACvB;AAAA,IACF,CAAC;AAED,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ACjB,sBAAc,IAAI;AAClB,wBAAgB;AAAA,MAClB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,OAAO,wBAAwB,aAAqB,aAA2B;AAC7E,YAAM,gBAAgB;AAEtB,mBAAa,CAAC;AACd,sBAAgB;AAChB,oBAAc;AAEd,aAAQ;AAAA,QACN,KAAK,UAAU;AAAA,UACb,MAAM;AAAA,UACN;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO,MAAM;AACX,cAAM,QAAQ,MAAM,UAAU;AAC9B,YAAI,UAAU,KAAM;AACpB,cAAM;AACN,YAAI,MAAM,SAAS,YAAY,MAAM,SAAS,QAAS;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;;;ACpTA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAAC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAAC;AAAA,EACA,gBAAAC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAAC;AAAA,EACA;AAAA,EAEA;AAAA,EACA,wBAAAC;AAAA,EAEA,wBAAAC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["isAbortError","isAbortError","safeParseStreamEvent","OctavusError","generateId","isAbortError","threadForPart","isFileReferenceArray","safeParseStreamEvent"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octavus/client-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Framework-agnostic client SDK for Octavus agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Octavus AI <dev@octavus.ai>",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@octavus/core": "^2.
|
|
42
|
+
"@octavus/core": "^2.1.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"tsup": "^8.3.5",
|