@octavus/core 0.2.0 → 1.0.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 CHANGED
@@ -15,827 +15,432 @@ declare class ValidationError extends AppError {
15
15
  declare class ConflictError extends AppError {
16
16
  constructor(resource: string, identifier: string);
17
17
  }
18
+ declare class ForbiddenError extends AppError {
19
+ constructor(message?: string);
20
+ }
18
21
 
19
22
  /**
20
- * Generate a unique ID for messages, tool calls, etc.
21
- * Format: timestamp-random (e.g., "1702345678901-abc123def")
23
+ * Error types for Octavus streaming errors.
24
+ * These types categorize errors to enable appropriate UI handling.
22
25
  */
23
- declare function generateId(): string;
26
+ type ErrorType = 'authentication_error' | 'permission_error' | 'validation_error' | 'not_found_error' | 'rate_limit_error' | 'quota_exceeded_error' | 'provider_error' | 'provider_overloaded' | 'provider_timeout' | 'execution_error' | 'tool_error' | 'protocol_error' | 'internal_error' | 'unknown_error';
24
27
  /**
25
- * Check if an error is an abort error.
28
+ * Error source - where the error originated.
29
+ */
30
+ type ErrorSource = 'platform' | 'provider' | 'tool' | 'client';
31
+ /**
32
+ * Provider information for provider errors.
33
+ */
34
+ interface ProviderErrorInfo {
35
+ /** Provider name (e.g., 'openai', 'anthropic', 'google') */
36
+ name: string;
37
+ /** Model that caused the error */
38
+ model?: string;
39
+ /** HTTP status code from provider */
40
+ statusCode?: number;
41
+ /** Provider's error type string */
42
+ errorType?: string;
43
+ /** Provider's request ID for support */
44
+ requestId?: string;
45
+ }
46
+ /**
47
+ * Tool information for tool errors.
48
+ */
49
+ interface ToolErrorInfo {
50
+ /** Tool name */
51
+ name: string;
52
+ /** Tool call ID */
53
+ callId?: string;
54
+ }
55
+ /**
56
+ * Options for creating an OctavusError.
57
+ */
58
+ interface OctavusErrorOptions {
59
+ errorType: ErrorType;
60
+ message: string;
61
+ source: ErrorSource;
62
+ retryable?: boolean;
63
+ retryAfter?: number;
64
+ code?: string;
65
+ provider?: ProviderErrorInfo;
66
+ tool?: ToolErrorInfo;
67
+ cause?: unknown;
68
+ }
69
+
70
+ /**
71
+ * Base error class for Octavus streaming errors.
26
72
  *
27
- * This handles the various ways abort errors can manifest across different
28
- * environments (browsers, Node.js, Next.js, etc.).
73
+ * Provides structured error information including:
74
+ * - Error type classification for UI handling
75
+ * - Source information (platform, provider, tool)
76
+ * - Retryability flag and retry delay
77
+ * - Provider/tool details when applicable
29
78
  *
30
- * @param error - The error to check
31
- * @returns True if the error is an abort error
79
+ * @example
80
+ * ```typescript
81
+ * const error = new OctavusError({
82
+ * errorType: 'rate_limit_error',
83
+ * message: 'Rate limit exceeded. Please try again later.',
84
+ * source: 'provider',
85
+ * retryable: true,
86
+ * retryAfter: 60,
87
+ * provider: {
88
+ * name: 'anthropic',
89
+ * statusCode: 429,
90
+ * requestId: 'req_xxx',
91
+ * },
92
+ * });
93
+ * ```
32
94
  */
33
- declare function isAbortError(error: unknown): error is Error;
34
-
95
+ declare class OctavusError extends Error {
96
+ /** @internal Marker for cross-version instanceof checks */
97
+ readonly __octavusErrorMarker = "octavus.error";
98
+ /** Error type classification */
99
+ readonly errorType: ErrorType;
100
+ /** Where the error originated */
101
+ readonly source: ErrorSource;
102
+ /** Whether automatic retry is possible */
103
+ readonly retryable: boolean;
104
+ /** Suggested retry delay in seconds (from provider headers) */
105
+ readonly retryAfter?: number;
106
+ /** Machine-readable error code */
107
+ readonly code?: string;
108
+ /** Provider details (when source === 'provider') */
109
+ readonly provider?: ProviderErrorInfo;
110
+ /** Tool details (when source === 'tool') */
111
+ readonly tool?: ToolErrorInfo;
112
+ constructor(options: OctavusErrorOptions);
113
+ /**
114
+ * Check if an unknown value is an OctavusError.
115
+ * Works reliably across package versions using marker property.
116
+ */
117
+ static isInstance(error: unknown): error is OctavusError;
118
+ /**
119
+ * Convert error to plain object for serialization.
120
+ * Used for streaming error events.
121
+ */
122
+ toJSON(): Record<string, unknown>;
123
+ }
35
124
  /**
36
- * Default thread name when none is specified.
125
+ * Check if an error is a rate limit error.
37
126
  */
38
- declare const MAIN_THREAD: "main";
127
+ declare function isRateLimitError(error: unknown): error is OctavusError;
39
128
  /**
40
- * Resolve a thread name, defaulting to main thread.
129
+ * Check if an error is an authentication error.
41
130
  */
42
- declare function resolveThread(thread: string | undefined): string;
131
+ declare function isAuthenticationError(error: unknown): error is OctavusError;
43
132
  /**
44
- * Check if a thread is the main thread.
133
+ * Check if an error is a provider error.
45
134
  */
46
- declare function isMainThread(thread: string | undefined): boolean;
135
+ declare function isProviderError(error: unknown): error is OctavusError;
47
136
  /**
48
- * Normalize thread for storage in message parts.
49
- * Main thread is stored as undefined to save space.
137
+ * Check if an error is a tool error.
50
138
  */
51
- declare function threadForPart(thread: string | undefined): string | undefined;
139
+ declare function isToolError(error: unknown): error is OctavusError;
52
140
  /**
53
- * Check if a message part belongs to a non-main thread.
54
- * Non-main thread content (e.g., "summary") is typically displayed differently.
141
+ * Check if an error is retryable.
55
142
  */
56
- declare function isOtherThread(part: {
57
- thread?: string;
58
- }): boolean;
143
+ declare function isRetryableError(error: unknown): boolean;
144
+ /**
145
+ * Check if an error is a validation error (non-retryable request issue).
146
+ */
147
+ declare function isValidationError(error: unknown): error is OctavusError;
59
148
 
60
149
  /**
61
- * Zod schemas for stream events.
150
+ * Stream event types for Octavus agent communication.
62
151
  *
63
- * Schemas are organized into two categories:
64
- * - Standard Events (====): Aligned with Vercel AI SDK for interoperability
152
+ * Events are organized into two categories:
153
+ * - Standard Events (====): Common streaming patterns for AI agents
65
154
  * - Octavus Events (----): Octavus-specific protocol events
66
155
  */
156
+ /**
157
+ * Display mode - controls execution indicator visibility (NOT final message visibility).
158
+ * - hidden: Block runs silently
159
+ * - name: Shows block/tool name
160
+ * - description: Shows description
161
+ * - stream: Shows live streaming content
162
+ */
67
163
 
68
- declare const toolResultSchema: z.ZodObject<{
69
- toolCallId: z.ZodString;
70
- toolName: z.ZodOptional<z.ZodString>;
71
- result: z.ZodOptional<z.ZodUnknown>;
72
- error: z.ZodOptional<z.ZodString>;
73
- outputVariable: z.ZodOptional<z.ZodString>;
74
- blockIndex: z.ZodOptional<z.ZodNumber>;
75
- }, z.core.$strip>;
164
+ type DisplayMode = 'hidden' | 'name' | 'description' | 'stream';
165
+ type ToolHandler = (args: Record<string, unknown>) => Promise<unknown>;
166
+ type ToolHandlers = Record<string, ToolHandler>;
76
167
  /**
77
- * Schema for file references used in trigger input and user messages.
168
+ * Reference to an uploaded file.
169
+ * Used in trigger input and user messages for file attachments.
170
+ * Compatible with UIFilePart structure for rendering.
78
171
  */
79
- declare const fileReferenceSchema: z.ZodObject<{
80
- id: z.ZodString;
81
- mediaType: z.ZodString;
82
- url: z.ZodString;
83
- filename: z.ZodOptional<z.ZodString>;
84
- size: z.ZodOptional<z.ZodNumber>;
85
- }, z.core.$strip>;
86
- declare const chatMessageSchema: z.ZodObject<{
87
- id: z.ZodString;
88
- role: z.ZodEnum<{
89
- user: "user";
90
- assistant: "assistant";
91
- system: "system";
92
- }>;
93
- parts: z.ZodArray<z.ZodObject<{
94
- type: z.ZodEnum<{
95
- object: "object";
96
- file: "file";
97
- source: "source";
98
- text: "text";
99
- reasoning: "reasoning";
100
- "tool-call": "tool-call";
101
- }>;
102
- visible: z.ZodBoolean;
103
- content: z.ZodOptional<z.ZodString>;
104
- toolCall: z.ZodOptional<z.ZodObject<{
105
- id: z.ZodString;
106
- name: z.ZodString;
107
- description: z.ZodOptional<z.ZodString>;
108
- arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
109
- status: z.ZodEnum<{
110
- pending: "pending";
111
- streaming: "streaming";
112
- available: "available";
113
- error: "error";
114
- }>;
115
- result: z.ZodOptional<z.ZodUnknown>;
116
- error: z.ZodOptional<z.ZodString>;
117
- }, z.core.$strip>>;
118
- source: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
119
- sourceType: z.ZodLiteral<"url">;
120
- id: z.ZodString;
121
- url: z.ZodString;
122
- title: z.ZodOptional<z.ZodString>;
123
- }, z.core.$strip>, z.ZodObject<{
124
- sourceType: z.ZodLiteral<"document">;
125
- id: z.ZodString;
126
- mediaType: z.ZodString;
127
- title: z.ZodString;
128
- filename: z.ZodOptional<z.ZodString>;
129
- }, z.core.$strip>], "sourceType">>;
130
- file: z.ZodOptional<z.ZodObject<{
131
- id: z.ZodString;
132
- mediaType: z.ZodString;
133
- url: z.ZodString;
134
- filename: z.ZodOptional<z.ZodString>;
135
- size: z.ZodOptional<z.ZodNumber>;
136
- toolCallId: z.ZodOptional<z.ZodString>;
137
- }, z.core.$strip>>;
138
- object: z.ZodOptional<z.ZodObject<{
139
- id: z.ZodString;
140
- typeName: z.ZodString;
141
- value: z.ZodUnknown;
142
- }, z.core.$strip>>;
143
- thread: z.ZodOptional<z.ZodString>;
144
- }, z.core.$strip>>;
145
- createdAt: z.ZodString;
146
- visible: z.ZodOptional<z.ZodBoolean>;
147
- content: z.ZodString;
148
- toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
149
- id: z.ZodString;
150
- name: z.ZodString;
151
- description: z.ZodOptional<z.ZodString>;
152
- arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
153
- status: z.ZodEnum<{
154
- pending: "pending";
155
- streaming: "streaming";
156
- available: "available";
157
- error: "error";
158
- }>;
159
- result: z.ZodOptional<z.ZodUnknown>;
160
- error: z.ZodOptional<z.ZodString>;
161
- }, z.core.$strip>>>;
162
- reasoning: z.ZodOptional<z.ZodString>;
163
- reasoningSignature: z.ZodOptional<z.ZodString>;
164
- }, z.core.$strip>;
165
- declare const uiMessagePartSchema: z.ZodUnion<readonly [z.ZodObject<{
166
- type: z.ZodLiteral<"text">;
167
- text: z.ZodString;
168
- status: z.ZodEnum<{
169
- streaming: "streaming";
170
- done: "done";
171
- }>;
172
- thread: z.ZodOptional<z.ZodString>;
173
- }, z.core.$strip>, z.ZodObject<{
174
- type: z.ZodLiteral<"reasoning">;
175
- text: z.ZodString;
176
- status: z.ZodEnum<{
177
- streaming: "streaming";
178
- done: "done";
179
- }>;
180
- thread: z.ZodOptional<z.ZodString>;
181
- }, z.core.$strip>, z.ZodObject<{
182
- type: z.ZodLiteral<"tool-call">;
183
- toolCallId: z.ZodString;
184
- toolName: z.ZodString;
185
- displayName: z.ZodOptional<z.ZodString>;
186
- args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
187
- result: z.ZodOptional<z.ZodUnknown>;
188
- error: z.ZodOptional<z.ZodString>;
189
- status: z.ZodEnum<{
190
- pending: "pending";
191
- error: "error";
192
- done: "done";
193
- running: "running";
194
- }>;
195
- thread: z.ZodOptional<z.ZodString>;
196
- }, z.core.$strip>, z.ZodObject<{
197
- type: z.ZodLiteral<"operation">;
198
- operationId: z.ZodString;
199
- name: z.ZodString;
200
- operationType: z.ZodString;
201
- status: z.ZodEnum<{
202
- done: "done";
203
- running: "running";
204
- }>;
205
- thread: z.ZodOptional<z.ZodString>;
206
- }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
207
- type: z.ZodLiteral<"source">;
208
- sourceType: z.ZodLiteral<"url">;
209
- id: z.ZodString;
210
- url: z.ZodString;
211
- title: z.ZodOptional<z.ZodString>;
212
- thread: z.ZodOptional<z.ZodString>;
213
- }, z.core.$strip>, z.ZodObject<{
214
- type: z.ZodLiteral<"source">;
215
- sourceType: z.ZodLiteral<"document">;
216
- id: z.ZodString;
217
- mediaType: z.ZodString;
218
- title: z.ZodString;
219
- filename: z.ZodOptional<z.ZodString>;
220
- thread: z.ZodOptional<z.ZodString>;
221
- }, z.core.$strip>], "sourceType">, z.ZodObject<{
222
- type: z.ZodLiteral<"file">;
223
- id: z.ZodString;
224
- mediaType: z.ZodString;
225
- url: z.ZodString;
226
- filename: z.ZodOptional<z.ZodString>;
227
- size: z.ZodOptional<z.ZodNumber>;
228
- toolCallId: z.ZodOptional<z.ZodString>;
229
- thread: z.ZodOptional<z.ZodString>;
230
- }, z.core.$strip>, z.ZodObject<{
231
- type: z.ZodLiteral<"object">;
232
- id: z.ZodString;
233
- typeName: z.ZodString;
234
- partial: z.ZodOptional<z.ZodUnknown>;
235
- object: z.ZodOptional<z.ZodUnknown>;
236
- status: z.ZodEnum<{
237
- streaming: "streaming";
238
- error: "error";
239
- done: "done";
240
- }>;
241
- error: z.ZodOptional<z.ZodString>;
242
- thread: z.ZodOptional<z.ZodString>;
243
- }, z.core.$strip>]>;
244
- declare const uiMessageSchema: z.ZodObject<{
245
- id: z.ZodString;
246
- role: z.ZodEnum<{
247
- user: "user";
248
- assistant: "assistant";
249
- }>;
250
- parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
251
- type: z.ZodLiteral<"text">;
252
- text: z.ZodString;
253
- status: z.ZodEnum<{
254
- streaming: "streaming";
255
- done: "done";
256
- }>;
257
- thread: z.ZodOptional<z.ZodString>;
258
- }, z.core.$strip>, z.ZodObject<{
259
- type: z.ZodLiteral<"reasoning">;
260
- text: z.ZodString;
261
- status: z.ZodEnum<{
262
- streaming: "streaming";
263
- done: "done";
264
- }>;
265
- thread: z.ZodOptional<z.ZodString>;
266
- }, z.core.$strip>, z.ZodObject<{
267
- type: z.ZodLiteral<"tool-call">;
268
- toolCallId: z.ZodString;
269
- toolName: z.ZodString;
270
- displayName: z.ZodOptional<z.ZodString>;
271
- args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
272
- result: z.ZodOptional<z.ZodUnknown>;
273
- error: z.ZodOptional<z.ZodString>;
274
- status: z.ZodEnum<{
275
- pending: "pending";
276
- error: "error";
277
- done: "done";
278
- running: "running";
279
- }>;
280
- thread: z.ZodOptional<z.ZodString>;
281
- }, z.core.$strip>, z.ZodObject<{
282
- type: z.ZodLiteral<"operation">;
283
- operationId: z.ZodString;
284
- name: z.ZodString;
285
- operationType: z.ZodString;
286
- status: z.ZodEnum<{
287
- done: "done";
288
- running: "running";
289
- }>;
290
- thread: z.ZodOptional<z.ZodString>;
291
- }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
292
- type: z.ZodLiteral<"source">;
293
- sourceType: z.ZodLiteral<"url">;
294
- id: z.ZodString;
295
- url: z.ZodString;
296
- title: z.ZodOptional<z.ZodString>;
297
- thread: z.ZodOptional<z.ZodString>;
298
- }, z.core.$strip>, z.ZodObject<{
299
- type: z.ZodLiteral<"source">;
300
- sourceType: z.ZodLiteral<"document">;
301
- id: z.ZodString;
302
- mediaType: z.ZodString;
303
- title: z.ZodString;
304
- filename: z.ZodOptional<z.ZodString>;
305
- thread: z.ZodOptional<z.ZodString>;
306
- }, z.core.$strip>], "sourceType">, z.ZodObject<{
307
- type: z.ZodLiteral<"file">;
308
- id: z.ZodString;
309
- mediaType: z.ZodString;
310
- url: z.ZodString;
311
- filename: z.ZodOptional<z.ZodString>;
312
- size: z.ZodOptional<z.ZodNumber>;
313
- toolCallId: z.ZodOptional<z.ZodString>;
314
- thread: z.ZodOptional<z.ZodString>;
315
- }, z.core.$strip>, z.ZodObject<{
316
- type: z.ZodLiteral<"object">;
317
- id: z.ZodString;
318
- typeName: z.ZodString;
319
- partial: z.ZodOptional<z.ZodUnknown>;
320
- object: z.ZodOptional<z.ZodUnknown>;
321
- status: z.ZodEnum<{
322
- streaming: "streaming";
323
- error: "error";
324
- done: "done";
325
- }>;
326
- error: z.ZodOptional<z.ZodString>;
327
- thread: z.ZodOptional<z.ZodString>;
328
- }, z.core.$strip>]>>;
329
- status: z.ZodEnum<{
330
- streaming: "streaming";
331
- done: "done";
332
- }>;
333
- createdAt: z.ZodCoercedDate<unknown>;
334
- }, z.core.$strip>;
335
- declare function safeParseStreamEvent(data: unknown): z.ZodSafeParseResult<{
336
- type: "source";
337
- sourceType: "url";
172
+ interface FileReference {
173
+ /** Unique file ID (platform-generated) */
338
174
  id: string;
175
+ /** IANA media type (e.g., 'image/png', 'application/pdf') */
176
+ mediaType: string;
177
+ /** Presigned download URL (S3) */
339
178
  url: string;
340
- title?: string | undefined;
341
- } | {
342
- type: "source";
343
- sourceType: "document";
179
+ /** Original filename */
180
+ filename?: string;
181
+ /** File size in bytes */
182
+ size?: number;
183
+ }
184
+ type ResourceUpdateHandler = (name: string, value: unknown) => Promise<void> | void;
185
+ type MessageRole = 'user' | 'assistant' | 'system';
186
+ type ToolCallStatus = 'pending' | 'streaming' | 'available' | 'error';
187
+ interface ToolCallInfo {
344
188
  id: string;
345
- mediaType: string;
346
- title: string;
347
- filename?: string | undefined;
348
- } | {
349
- type: "start";
350
- messageId?: string | undefined;
351
- } | {
352
- type: "finish";
353
- finishReason: "error" | "stop" | "tool-calls" | "length" | "content-filter" | "other";
354
- } | {
355
- type: "error";
356
- errorText: string;
357
- } | {
358
- type: "text-start";
189
+ name: string;
190
+ description?: string;
191
+ arguments: Record<string, unknown>;
192
+ status: ToolCallStatus;
193
+ result?: unknown;
194
+ error?: string;
195
+ }
196
+ /** Signals the start of a response message */
197
+ interface StartEvent {
198
+ type: 'start';
199
+ messageId?: string;
200
+ }
201
+ /** Signals completion of streaming */
202
+ interface FinishEvent {
203
+ type: 'finish';
204
+ finishReason: FinishReason;
205
+ }
206
+
207
+ /**
208
+ * Error during streaming.
209
+ *
210
+ * Enhanced with structured error information including:
211
+ * - Error type classification for UI handling
212
+ * - Source information (platform, provider, tool)
213
+ * - Retryability flag and retry delay
214
+ * - Provider/tool details when applicable
215
+ *
216
+ * @example Rate limit error from provider
217
+ * ```typescript
218
+ * {
219
+ * type: 'error',
220
+ * errorType: 'rate_limit_error',
221
+ * message: 'Rate limit exceeded',
222
+ * source: 'provider',
223
+ * retryable: true,
224
+ * retryAfter: 60,
225
+ * provider: { name: 'anthropic', statusCode: 429 }
226
+ * }
227
+ * ```
228
+ */
229
+ interface ErrorEvent {
230
+ type: 'error';
231
+ /** Error type classification for UI handling */
232
+ errorType: ErrorType;
233
+ /** Human-readable error message */
234
+ message: string;
235
+ /** Whether automatic retry is possible */
236
+ retryable: boolean;
237
+ /** Where the error originated */
238
+ source: ErrorSource;
239
+ /** Suggested retry delay in seconds (from provider headers) */
240
+ retryAfter?: number;
241
+ /** Machine-readable error code */
242
+ code?: string;
243
+ /** Provider details (when source === 'provider') */
244
+ provider?: ProviderErrorInfo;
245
+ /** Tool details (when source === 'tool') */
246
+ tool?: ToolErrorInfo;
247
+ }
248
+ type FinishReason = 'stop' | 'tool-calls' | 'length' | 'content-filter' | 'error' | 'other';
249
+ /**
250
+ * Start of text generation for a specific text part.
251
+ *
252
+ * If `responseType` is set, the text content is JSON matching a custom type.
253
+ * The client SDK should parse the text as a structured object instead of
254
+ * displaying it as plain text.
255
+ */
256
+ interface TextStartEvent {
257
+ type: 'text-start';
359
258
  id: string;
360
- responseType?: string | undefined;
361
- } | {
362
- type: "text-delta";
259
+ /**
260
+ * If specified, the text content is JSON matching this type name.
261
+ * Client SDK should parse as object, not display as text.
262
+ */
263
+ responseType?: string;
264
+ }
265
+ /** Incremental text content */
266
+ interface TextDeltaEvent {
267
+ type: 'text-delta';
363
268
  id: string;
364
269
  delta: string;
365
- } | {
366
- type: "text-end";
270
+ }
271
+ /** End of text generation for a specific text part */
272
+ interface TextEndEvent {
273
+ type: 'text-end';
367
274
  id: string;
368
- } | {
369
- type: "reasoning-start";
275
+ }
276
+ /** Start of reasoning/thinking generation */
277
+ interface ReasoningStartEvent {
278
+ type: 'reasoning-start';
370
279
  id: string;
371
- } | {
372
- type: "reasoning-delta";
280
+ }
281
+ /** Incremental reasoning content */
282
+ interface ReasoningDeltaEvent {
283
+ type: 'reasoning-delta';
373
284
  id: string;
374
285
  delta: string;
375
- } | {
376
- type: "reasoning-end";
286
+ }
287
+ /** End of reasoning generation */
288
+ interface ReasoningEndEvent {
289
+ type: 'reasoning-end';
377
290
  id: string;
378
- } | {
379
- type: "tool-input-start";
291
+ }
292
+ /** Tool call initiated - input streaming will follow */
293
+ interface ToolInputStartEvent {
294
+ type: 'tool-input-start';
380
295
  toolCallId: string;
381
296
  toolName: string;
382
- title?: string | undefined;
383
- } | {
384
- type: "tool-input-delta";
297
+ /** Human-readable title/description for the tool call */
298
+ title?: string;
299
+ }
300
+ /** Incremental tool input/arguments */
301
+ interface ToolInputDeltaEvent {
302
+ type: 'tool-input-delta';
385
303
  toolCallId: string;
386
304
  inputTextDelta: string;
387
- } | {
388
- type: "tool-input-end";
305
+ }
306
+ /** Tool input streaming has ended */
307
+ interface ToolInputEndEvent {
308
+ type: 'tool-input-end';
389
309
  toolCallId: string;
390
- } | {
391
- type: "tool-input-available";
310
+ }
311
+ /** Tool input is complete and available */
312
+ interface ToolInputAvailableEvent {
313
+ type: 'tool-input-available';
392
314
  toolCallId: string;
393
315
  toolName: string;
394
316
  input: unknown;
395
- } | {
396
- type: "tool-output-available";
317
+ }
318
+ /** Tool output/result is available */
319
+ interface ToolOutputAvailableEvent {
320
+ type: 'tool-output-available';
397
321
  toolCallId: string;
398
322
  output: unknown;
399
- } | {
400
- type: "tool-output-error";
323
+ }
324
+ /** Tool execution resulted in error */
325
+ interface ToolOutputErrorEvent {
326
+ type: 'tool-output-error';
401
327
  toolCallId: string;
402
- errorText: string;
403
- } | {
404
- type: "block-start";
328
+ error: string;
329
+ }
330
+ /** Base source event fields */
331
+ interface BaseSourceEvent {
332
+ type: 'source';
333
+ /** Unique source ID */
334
+ id: string;
335
+ }
336
+ /** URL source from web search or similar tools */
337
+ interface SourceUrlEvent extends BaseSourceEvent {
338
+ sourceType: 'url';
339
+ /** URL of the source */
340
+ url: string;
341
+ /** Title of the source */
342
+ title?: string;
343
+ }
344
+ /** Document source from file processing */
345
+ interface SourceDocumentEvent extends BaseSourceEvent {
346
+ sourceType: 'document';
347
+ /** IANA media type (e.g., 'application/pdf') */
348
+ mediaType: string;
349
+ /** Title of the document */
350
+ title: string;
351
+ /** Filename of the document */
352
+ filename?: string;
353
+ }
354
+ /** Source event - union of all source types */
355
+ type SourceEvent = SourceUrlEvent | SourceDocumentEvent;
356
+ /** Protocol block execution started */
357
+ interface BlockStartEvent {
358
+ type: 'block-start';
405
359
  blockId: string;
406
360
  blockName: string;
407
361
  blockType: string;
408
- display: "hidden" | "name" | "description" | "stream";
409
- description?: string | undefined;
410
- outputToChat?: boolean | undefined;
411
- thread?: string | undefined;
412
- } | {
413
- type: "block-end";
414
- blockId: string;
415
- summary?: string | undefined;
416
- } | {
417
- type: "resource-update";
362
+ display: DisplayMode;
363
+ description?: string;
364
+ /** Whether output goes to main chat (false for independent blocks) */
365
+ outputToChat?: boolean;
366
+ /** Thread name (undefined or 'main' for main thread) */
367
+ thread?: string;
368
+ }
369
+ /** Protocol block execution completed */
370
+ interface BlockEndEvent {
371
+ type: 'block-end';
372
+ blockId: string;
373
+ summary?: string;
374
+ }
375
+ /** Resource value updated */
376
+ interface ResourceUpdateEvent {
377
+ type: 'resource-update';
418
378
  name: string;
419
379
  value: unknown;
420
- } | {
421
- type: "tool-request";
422
- toolCalls: {
423
- toolCallId: string;
424
- toolName: string;
425
- args: Record<string, unknown>;
426
- source?: "llm" | "block" | undefined;
427
- outputVariable?: string | undefined;
428
- blockIndex?: number | undefined;
429
- }[];
430
- } | {
431
- type: "file-available";
432
- id: string;
433
- mediaType: string;
434
- url: string;
435
- filename?: string | undefined;
436
- size?: number | undefined;
437
- toolCallId?: string | undefined;
438
- }>;
439
- declare function safeParseUIMessage(data: unknown): z.ZodSafeParseResult<{
440
- id: string;
441
- role: "user" | "assistant";
442
- parts: ({
443
- type: "source";
444
- sourceType: "url";
445
- id: string;
446
- url: string;
447
- title?: string | undefined;
448
- thread?: string | undefined;
449
- } | {
450
- type: "source";
451
- sourceType: "document";
452
- id: string;
453
- mediaType: string;
454
- title: string;
455
- filename?: string | undefined;
456
- thread?: string | undefined;
457
- } | {
458
- type: "text";
459
- text: string;
460
- status: "streaming" | "done";
461
- thread?: string | undefined;
462
- } | {
463
- type: "reasoning";
464
- text: string;
465
- status: "streaming" | "done";
466
- thread?: string | undefined;
467
- } | {
468
- type: "tool-call";
469
- toolCallId: string;
470
- toolName: string;
471
- args: Record<string, unknown>;
472
- status: "pending" | "error" | "done" | "running";
473
- displayName?: string | undefined;
474
- result?: unknown;
475
- error?: string | undefined;
476
- thread?: string | undefined;
477
- } | {
478
- type: "operation";
479
- operationId: string;
480
- name: string;
481
- operationType: string;
482
- status: "done" | "running";
483
- thread?: string | undefined;
484
- } | {
485
- type: "file";
486
- id: string;
487
- mediaType: string;
488
- url: string;
489
- filename?: string | undefined;
490
- size?: number | undefined;
491
- toolCallId?: string | undefined;
492
- thread?: string | undefined;
493
- } | {
494
- type: "object";
495
- id: string;
496
- typeName: string;
497
- status: "streaming" | "error" | "done";
498
- partial?: unknown;
499
- object?: unknown;
500
- error?: string | undefined;
501
- thread?: string | undefined;
502
- })[];
503
- status: "streaming" | "done";
504
- createdAt: Date;
505
- }>;
506
- declare function safeParseUIMessages(data: unknown): z.ZodSafeParseResult<{
507
- id: string;
508
- role: "user" | "assistant";
509
- parts: ({
510
- type: "source";
511
- sourceType: "url";
512
- id: string;
513
- url: string;
514
- title?: string | undefined;
515
- thread?: string | undefined;
516
- } | {
517
- type: "source";
518
- sourceType: "document";
519
- id: string;
520
- mediaType: string;
521
- title: string;
522
- filename?: string | undefined;
523
- thread?: string | undefined;
524
- } | {
525
- type: "text";
526
- text: string;
527
- status: "streaming" | "done";
528
- thread?: string | undefined;
529
- } | {
530
- type: "reasoning";
531
- text: string;
532
- status: "streaming" | "done";
533
- thread?: string | undefined;
534
- } | {
535
- type: "tool-call";
536
- toolCallId: string;
537
- toolName: string;
538
- args: Record<string, unknown>;
539
- status: "pending" | "error" | "done" | "running";
540
- displayName?: string | undefined;
541
- result?: unknown;
542
- error?: string | undefined;
543
- thread?: string | undefined;
544
- } | {
545
- type: "operation";
546
- operationId: string;
547
- name: string;
548
- operationType: string;
549
- status: "done" | "running";
550
- thread?: string | undefined;
551
- } | {
552
- type: "file";
553
- id: string;
554
- mediaType: string;
555
- url: string;
556
- filename?: string | undefined;
557
- size?: number | undefined;
558
- toolCallId?: string | undefined;
559
- thread?: string | undefined;
560
- } | {
561
- type: "object";
562
- id: string;
563
- typeName: string;
564
- status: "streaming" | "error" | "done";
565
- partial?: unknown;
566
- object?: unknown;
567
- error?: string | undefined;
568
- thread?: string | undefined;
569
- })[];
570
- status: "streaming" | "done";
571
- createdAt: Date;
572
- }[]>;
573
- /**
574
- * Type guard to check if a value is a FileReference object.
575
- */
576
- declare function isFileReference(value: unknown): value is z.infer<typeof fileReferenceSchema>;
577
- /**
578
- * Type guard to check if a value is an array of FileReference objects.
579
- */
580
- declare function isFileReferenceArray(value: unknown): value is z.infer<typeof fileReferenceSchema>[];
581
-
380
+ }
381
+ /** Pending tool call that needs external execution (continuation pattern) */
382
+ interface PendingToolCall {
383
+ toolCallId: string;
384
+ toolName: string;
385
+ args: Record<string, unknown>;
386
+ /** 'llm' for LLM-initiated, 'block' for protocol block */
387
+ source?: 'llm' | 'block';
388
+ /** For block-based tools: variable name to store result in */
389
+ outputVariable?: string;
390
+ /** For block-based tools: block index to resume from after execution */
391
+ blockIndex?: number;
392
+ }
582
393
  /**
583
- * Stream event types for Octavus agent communication.
584
- *
585
- * Events are organized into two categories:
586
- * - Standard Events (====): Aligned with Vercel AI SDK for interoperability
587
- * - Octavus Events (----): Octavus-specific protocol events
394
+ * When this event is received, the stream will close.
395
+ * Consumer should execute the tools and POST a new trigger request with toolResults.
588
396
  */
397
+ interface ToolRequestEvent {
398
+ type: 'tool-request';
399
+ toolCalls: PendingToolCall[];
400
+ }
401
+ /** Result from tool execution (consumer's response to tool-request) */
402
+ interface ToolResult {
403
+ toolCallId: string;
404
+ toolName?: string;
405
+ result?: unknown;
406
+ error?: string;
407
+ outputVariable?: string;
408
+ blockIndex?: number;
409
+ }
589
410
  /**
590
- * Display mode - controls execution indicator visibility (NOT final message visibility).
591
- * - hidden: Block runs silently
592
- * - name: Shows block/tool name
593
- * - description: Shows description
594
- * - stream: Shows live streaming content
411
+ * A file generated during execution.
412
+ * Used for skill outputs, image generation, code execution artifacts, etc.
595
413
  */
596
- type DisplayMode = 'hidden' | 'name' | 'description' | 'stream';
597
- type ToolHandler = (args: Record<string, unknown>) => Promise<unknown>;
598
- type ToolHandlers = Record<string, ToolHandler>;
414
+ interface GeneratedFile {
415
+ /** Unique file ID */
416
+ id: string;
417
+ /** MIME type (e.g., 'image/png', 'application/pdf') */
418
+ mediaType: string;
419
+ /** URL for download/display */
420
+ url: string;
421
+ /** Original filename (for display/download) */
422
+ filename?: string;
423
+ /** Size in bytes */
424
+ size?: number;
425
+ }
599
426
  /**
600
- * Reference to an uploaded file.
601
- * Used in trigger input and user messages for file attachments.
602
- * Compatible with UIFilePart structure for rendering.
427
+ * File generated and available for download/display.
428
+ * Emitted when a tool or skill produces a file output.
603
429
  */
604
- interface FileReference {
605
- /** Unique file ID (platform-generated) */
430
+ interface FileAvailableEvent {
431
+ type: 'file-available';
432
+ /** Unique file ID */
606
433
  id: string;
607
- /** IANA media type (e.g., 'image/png', 'application/pdf') */
434
+ /** MIME type (e.g., 'image/png', 'application/pdf') */
608
435
  mediaType: string;
609
- /** Presigned download URL (S3) */
436
+ /** URL for download/display */
610
437
  url: string;
611
438
  /** Original filename */
612
439
  filename?: string;
613
- /** File size in bytes */
440
+ /** Size in bytes */
614
441
  size?: number;
615
- }
616
- type ResourceUpdateHandler = (name: string, value: unknown) => Promise<void> | void;
617
- type MessageRole = 'user' | 'assistant' | 'system';
618
- type ToolCallStatus = 'pending' | 'streaming' | 'available' | 'error';
619
- interface ToolCallInfo {
620
- id: string;
621
- name: string;
622
- description?: string;
623
- arguments: Record<string, unknown>;
624
- status: ToolCallStatus;
625
- result?: unknown;
626
- error?: string;
627
- }
628
- /** Signals the start of a response message */
629
- interface StartEvent {
630
- type: 'start';
631
- messageId?: string;
632
- }
633
- /** Signals completion of streaming */
634
- interface FinishEvent {
635
- type: 'finish';
636
- finishReason: FinishReason;
637
- }
638
- /** Error during streaming */
639
- interface ErrorEvent {
640
- type: 'error';
641
- errorText: string;
642
- }
643
- type FinishReason = 'stop' | 'tool-calls' | 'length' | 'content-filter' | 'error' | 'other';
644
- /**
645
- * Start of text generation for a specific text part.
646
- *
647
- * If `responseType` is set, the text content is JSON matching a custom type.
648
- * The client SDK should parse the text as a structured object instead of
649
- * displaying it as plain text.
650
- */
651
- interface TextStartEvent {
652
- type: 'text-start';
653
- id: string;
654
- /**
655
- * If specified, the text content is JSON matching this type name.
656
- * Client SDK should parse as object, not display as text.
657
- */
658
- responseType?: string;
659
- }
660
- /** Incremental text content */
661
- interface TextDeltaEvent {
662
- type: 'text-delta';
663
- id: string;
664
- delta: string;
665
- }
666
- /** End of text generation for a specific text part */
667
- interface TextEndEvent {
668
- type: 'text-end';
669
- id: string;
670
- }
671
- /** Start of reasoning/thinking generation */
672
- interface ReasoningStartEvent {
673
- type: 'reasoning-start';
674
- id: string;
675
- }
676
- /** Incremental reasoning content */
677
- interface ReasoningDeltaEvent {
678
- type: 'reasoning-delta';
679
- id: string;
680
- delta: string;
681
- }
682
- /** End of reasoning generation */
683
- interface ReasoningEndEvent {
684
- type: 'reasoning-end';
685
- id: string;
686
- }
687
- /** Tool call initiated - input streaming will follow */
688
- interface ToolInputStartEvent {
689
- type: 'tool-input-start';
690
- toolCallId: string;
691
- toolName: string;
692
- /** Human-readable title/description for the tool call */
693
- title?: string;
694
- }
695
- /** Incremental tool input/arguments */
696
- interface ToolInputDeltaEvent {
697
- type: 'tool-input-delta';
698
- toolCallId: string;
699
- inputTextDelta: string;
700
- }
701
- /** Tool input streaming has ended */
702
- interface ToolInputEndEvent {
703
- type: 'tool-input-end';
704
- toolCallId: string;
705
- }
706
- /** Tool input is complete and available */
707
- interface ToolInputAvailableEvent {
708
- type: 'tool-input-available';
709
- toolCallId: string;
710
- toolName: string;
711
- input: unknown;
712
- }
713
- /** Tool output/result is available */
714
- interface ToolOutputAvailableEvent {
715
- type: 'tool-output-available';
716
- toolCallId: string;
717
- output: unknown;
718
- }
719
- /** Tool execution resulted in error */
720
- interface ToolOutputErrorEvent {
721
- type: 'tool-output-error';
722
- toolCallId: string;
723
- errorText: string;
724
- }
725
- /** Base source event fields */
726
- interface BaseSourceEvent {
727
- type: 'source';
728
- /** The ID of the source */
729
- id: string;
730
- }
731
- /** URL source from web search or similar tools */
732
- interface SourceUrlEvent extends BaseSourceEvent {
733
- sourceType: 'url';
734
- /** The URL of the source */
735
- url: string;
736
- /** The title of the source */
737
- title?: string;
738
- }
739
- /** Document source from file processing */
740
- interface SourceDocumentEvent extends BaseSourceEvent {
741
- sourceType: 'document';
742
- /** IANA media type of the document (e.g., 'application/pdf') */
743
- mediaType: string;
744
- /** The title of the document */
745
- title: string;
746
- /** Optional filename of the document */
747
- filename?: string;
748
- }
749
- /** Source event - union of all source types */
750
- type SourceEvent = SourceUrlEvent | SourceDocumentEvent;
751
- /** Protocol block execution started */
752
- interface BlockStartEvent {
753
- type: 'block-start';
754
- blockId: string;
755
- blockName: string;
756
- blockType: string;
757
- display: DisplayMode;
758
- description?: string;
759
- /** Whether output goes to main chat (false for independent blocks) */
760
- outputToChat?: boolean;
761
- /** Thread name (undefined or 'main' for main thread) */
762
- thread?: string;
763
- }
764
- /** Protocol block execution completed */
765
- interface BlockEndEvent {
766
- type: 'block-end';
767
- blockId: string;
768
- summary?: string;
769
- }
770
- /** Resource value updated */
771
- interface ResourceUpdateEvent {
772
- type: 'resource-update';
773
- name: string;
774
- value: unknown;
775
- }
776
- /** Pending tool call that needs external execution (continuation pattern) */
777
- interface PendingToolCall {
778
- toolCallId: string;
779
- toolName: string;
780
- args: Record<string, unknown>;
781
- /** 'llm' for LLM-initiated, 'block' for protocol block */
782
- source?: 'llm' | 'block';
783
- /** For block-based tools: variable name to store result in */
784
- outputVariable?: string;
785
- /** For block-based tools: block index to resume from after execution */
786
- blockIndex?: number;
787
- }
788
- /**
789
- * When this event is received, the stream will close.
790
- * Consumer should execute the tools and POST a new trigger request with toolResults.
791
- */
792
- interface ToolRequestEvent {
793
- type: 'tool-request';
794
- toolCalls: PendingToolCall[];
795
- }
796
- /** Result from tool execution (consumer's response to tool-request) */
797
- interface ToolResult {
798
- toolCallId: string;
799
- toolName?: string;
800
- result?: unknown;
801
- error?: string;
802
- outputVariable?: string;
803
- blockIndex?: number;
804
- }
805
- /**
806
- * A file generated during execution (aligned with Vercel AI SDK FilePart).
807
- * Used for skill outputs, image generation, code execution artifacts, etc.
808
- */
809
- interface GeneratedFile {
810
- /** Unique file ID */
811
- id: string;
812
- /** MIME type (e.g., 'image/png', 'application/pdf') - aligned with Vercel AI SDK */
813
- mediaType: string;
814
- /** URL for download/display (presigned S3 URL or data URL) */
815
- url: string;
816
- /** Original filename (optional, for display/download) */
817
- filename?: string;
818
- /** Size in bytes (optional, for display) */
819
- size?: number;
820
- }
821
- /**
822
- * File generated and available for download/display.
823
- * Emitted when a tool or skill produces a file output.
824
- */
825
- interface FileAvailableEvent {
826
- type: 'file-available';
827
- /** Unique file ID */
828
- id: string;
829
- /** MIME type (aligned with Vercel AI SDK) */
830
- mediaType: string;
831
- /** URL for download/display */
832
- url: string;
833
- /** Original filename */
834
- filename?: string;
835
- /** Size in bytes */
836
- size?: number;
837
- /** Tool call that generated this file */
838
- toolCallId?: string;
442
+ /** Tool call that generated this file */
443
+ toolCallId?: string;
839
444
  }
840
445
  type StreamEvent = StartEvent | FinishEvent | ErrorEvent | TextStartEvent | TextDeltaEvent | TextEndEvent | ReasoningStartEvent | ReasoningDeltaEvent | ReasoningEndEvent | ToolInputStartEvent | ToolInputDeltaEvent | ToolInputEndEvent | ToolInputAvailableEvent | ToolOutputAvailableEvent | ToolOutputErrorEvent | SourceEvent | BlockStartEvent | BlockEndEvent | ResourceUpdateEvent | ToolRequestEvent | FileAvailableEvent;
841
446
  /**
@@ -1024,16 +629,16 @@ interface UISourceDocumentPart extends BaseUISourcePart {
1024
629
  */
1025
630
  type UISourcePart = UISourceUrlPart | UISourceDocumentPart;
1026
631
  /**
1027
- * File attachment part (aligned with Vercel AI SDK FilePart).
632
+ * File attachment part.
1028
633
  * Generated by skill execution, image generation, code execution, etc.
1029
634
  */
1030
635
  interface UIFilePart {
1031
636
  type: 'file';
1032
637
  /** Unique file ID */
1033
638
  id: string;
1034
- /** MIME type for rendering (aligned with Vercel AI SDK) */
639
+ /** MIME type (e.g., 'image/png', 'application/pdf') */
1035
640
  mediaType: string;
1036
- /** URL for download/display (presigned URL or data URL) */
641
+ /** URL for download/display */
1037
642
  url: string;
1038
643
  /** Original filename (for display/download) */
1039
644
  filename?: string;
@@ -1086,6 +691,623 @@ interface UIMessage {
1086
691
  createdAt: Date;
1087
692
  }
1088
693
 
694
+ /**
695
+ * Options for creating an error event.
696
+ */
697
+ interface CreateErrorEventOptions {
698
+ errorType: ErrorType;
699
+ message: string;
700
+ source: ErrorSource;
701
+ retryable?: boolean;
702
+ retryAfter?: number;
703
+ code?: string;
704
+ provider?: ProviderErrorInfo;
705
+ tool?: ToolErrorInfo;
706
+ }
707
+ /**
708
+ * Create an ErrorEvent from options.
709
+ * Use this for constructing error events in streaming responses.
710
+ */
711
+ declare function createErrorEvent(options: CreateErrorEventOptions): ErrorEvent;
712
+ /**
713
+ * Create an ErrorEvent from an OctavusError.
714
+ */
715
+ declare function errorToStreamEvent(error: OctavusError): ErrorEvent;
716
+ /**
717
+ * Create an internal error event.
718
+ * Convenience function for platform-level errors.
719
+ */
720
+ declare function createInternalErrorEvent(message: string): ErrorEvent;
721
+ /**
722
+ * Create an error event from an API response.
723
+ * Maps HTTP status codes to appropriate error types.
724
+ *
725
+ * Use this when handling errors from API responses (before streaming starts).
726
+ *
727
+ * @param statusCode - HTTP status code from the response
728
+ * @param message - Error message to display
729
+ */
730
+ declare function createApiErrorEvent(statusCode: number, message: string): ErrorEvent;
731
+
732
+ /**
733
+ * Generate a unique ID for messages, tool calls, etc.
734
+ * Format: timestamp-random (e.g., "1702345678901-abc123def")
735
+ */
736
+ declare function generateId(): string;
737
+ /**
738
+ * Check if an error is an abort error.
739
+ *
740
+ * This handles the various ways abort errors can manifest across different
741
+ * environments (browsers, Node.js, Next.js, etc.).
742
+ *
743
+ * @param error - The error to check
744
+ * @returns True if the error is an abort error
745
+ */
746
+ declare function isAbortError(error: unknown): error is Error;
747
+
748
+ /**
749
+ * Default thread name when none is specified.
750
+ */
751
+ declare const MAIN_THREAD: "main";
752
+ /**
753
+ * Resolve a thread name, defaulting to main thread.
754
+ */
755
+ declare function resolveThread(thread: string | undefined): string;
756
+ /**
757
+ * Check if a thread is the main thread.
758
+ */
759
+ declare function isMainThread(thread: string | undefined): boolean;
760
+ /**
761
+ * Normalize thread for storage in message parts.
762
+ * Main thread is stored as undefined to save space.
763
+ */
764
+ declare function threadForPart(thread: string | undefined): string | undefined;
765
+ /**
766
+ * Check if a message part belongs to a non-main thread.
767
+ * Non-main thread content (e.g., "summary") is typically displayed differently.
768
+ */
769
+ declare function isOtherThread(part: {
770
+ thread?: string;
771
+ }): boolean;
772
+
773
+ /**
774
+ * Zod schemas for stream events.
775
+ *
776
+ * Schemas are organized into two categories:
777
+ * - Standard Events (====): Common streaming patterns for AI agents
778
+ * - Octavus Events (----): Octavus-specific protocol events
779
+ */
780
+
781
+ declare const toolResultSchema: z.ZodObject<{
782
+ toolCallId: z.ZodString;
783
+ toolName: z.ZodOptional<z.ZodString>;
784
+ result: z.ZodOptional<z.ZodUnknown>;
785
+ error: z.ZodOptional<z.ZodString>;
786
+ outputVariable: z.ZodOptional<z.ZodString>;
787
+ blockIndex: z.ZodOptional<z.ZodNumber>;
788
+ }, z.core.$strip>;
789
+ /**
790
+ * Schema for file references used in trigger input and user messages.
791
+ */
792
+ declare const fileReferenceSchema: z.ZodObject<{
793
+ id: z.ZodString;
794
+ mediaType: z.ZodString;
795
+ url: z.ZodString;
796
+ filename: z.ZodOptional<z.ZodString>;
797
+ size: z.ZodOptional<z.ZodNumber>;
798
+ }, z.core.$strip>;
799
+ declare const chatMessageSchema: z.ZodObject<{
800
+ id: z.ZodString;
801
+ role: z.ZodEnum<{
802
+ user: "user";
803
+ assistant: "assistant";
804
+ system: "system";
805
+ }>;
806
+ parts: z.ZodArray<z.ZodObject<{
807
+ type: z.ZodEnum<{
808
+ object: "object";
809
+ source: "source";
810
+ text: "text";
811
+ reasoning: "reasoning";
812
+ "tool-call": "tool-call";
813
+ file: "file";
814
+ }>;
815
+ visible: z.ZodBoolean;
816
+ content: z.ZodOptional<z.ZodString>;
817
+ toolCall: z.ZodOptional<z.ZodObject<{
818
+ id: z.ZodString;
819
+ name: z.ZodString;
820
+ description: z.ZodOptional<z.ZodString>;
821
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
822
+ status: z.ZodEnum<{
823
+ pending: "pending";
824
+ streaming: "streaming";
825
+ available: "available";
826
+ error: "error";
827
+ }>;
828
+ result: z.ZodOptional<z.ZodUnknown>;
829
+ error: z.ZodOptional<z.ZodString>;
830
+ }, z.core.$strip>>;
831
+ source: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
832
+ sourceType: z.ZodLiteral<"url">;
833
+ id: z.ZodString;
834
+ url: z.ZodString;
835
+ title: z.ZodOptional<z.ZodString>;
836
+ }, z.core.$strip>, z.ZodObject<{
837
+ sourceType: z.ZodLiteral<"document">;
838
+ id: z.ZodString;
839
+ mediaType: z.ZodString;
840
+ title: z.ZodString;
841
+ filename: z.ZodOptional<z.ZodString>;
842
+ }, z.core.$strip>], "sourceType">>;
843
+ file: z.ZodOptional<z.ZodObject<{
844
+ id: z.ZodString;
845
+ mediaType: z.ZodString;
846
+ url: z.ZodString;
847
+ filename: z.ZodOptional<z.ZodString>;
848
+ size: z.ZodOptional<z.ZodNumber>;
849
+ toolCallId: z.ZodOptional<z.ZodString>;
850
+ }, z.core.$strip>>;
851
+ object: z.ZodOptional<z.ZodObject<{
852
+ id: z.ZodString;
853
+ typeName: z.ZodString;
854
+ value: z.ZodUnknown;
855
+ }, z.core.$strip>>;
856
+ thread: z.ZodOptional<z.ZodString>;
857
+ }, z.core.$strip>>;
858
+ createdAt: z.ZodString;
859
+ visible: z.ZodOptional<z.ZodBoolean>;
860
+ content: z.ZodString;
861
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
862
+ id: z.ZodString;
863
+ name: z.ZodString;
864
+ description: z.ZodOptional<z.ZodString>;
865
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
866
+ status: z.ZodEnum<{
867
+ pending: "pending";
868
+ streaming: "streaming";
869
+ available: "available";
870
+ error: "error";
871
+ }>;
872
+ result: z.ZodOptional<z.ZodUnknown>;
873
+ error: z.ZodOptional<z.ZodString>;
874
+ }, z.core.$strip>>>;
875
+ reasoning: z.ZodOptional<z.ZodString>;
876
+ reasoningSignature: z.ZodOptional<z.ZodString>;
877
+ }, z.core.$strip>;
878
+ declare const uiMessagePartSchema: z.ZodUnion<readonly [z.ZodObject<{
879
+ type: z.ZodLiteral<"text">;
880
+ text: z.ZodString;
881
+ status: z.ZodEnum<{
882
+ streaming: "streaming";
883
+ done: "done";
884
+ }>;
885
+ thread: z.ZodOptional<z.ZodString>;
886
+ }, z.core.$strip>, z.ZodObject<{
887
+ type: z.ZodLiteral<"reasoning">;
888
+ text: z.ZodString;
889
+ status: z.ZodEnum<{
890
+ streaming: "streaming";
891
+ done: "done";
892
+ }>;
893
+ thread: z.ZodOptional<z.ZodString>;
894
+ }, z.core.$strip>, z.ZodObject<{
895
+ type: z.ZodLiteral<"tool-call">;
896
+ toolCallId: z.ZodString;
897
+ toolName: z.ZodString;
898
+ displayName: z.ZodOptional<z.ZodString>;
899
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
900
+ result: z.ZodOptional<z.ZodUnknown>;
901
+ error: z.ZodOptional<z.ZodString>;
902
+ status: z.ZodEnum<{
903
+ pending: "pending";
904
+ error: "error";
905
+ done: "done";
906
+ running: "running";
907
+ }>;
908
+ thread: z.ZodOptional<z.ZodString>;
909
+ }, z.core.$strip>, z.ZodObject<{
910
+ type: z.ZodLiteral<"operation">;
911
+ operationId: z.ZodString;
912
+ name: z.ZodString;
913
+ operationType: z.ZodString;
914
+ status: z.ZodEnum<{
915
+ done: "done";
916
+ running: "running";
917
+ }>;
918
+ thread: z.ZodOptional<z.ZodString>;
919
+ }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
920
+ type: z.ZodLiteral<"source">;
921
+ sourceType: z.ZodLiteral<"url">;
922
+ id: z.ZodString;
923
+ url: z.ZodString;
924
+ title: z.ZodOptional<z.ZodString>;
925
+ thread: z.ZodOptional<z.ZodString>;
926
+ }, z.core.$strip>, z.ZodObject<{
927
+ type: z.ZodLiteral<"source">;
928
+ sourceType: z.ZodLiteral<"document">;
929
+ id: z.ZodString;
930
+ mediaType: z.ZodString;
931
+ title: z.ZodString;
932
+ filename: z.ZodOptional<z.ZodString>;
933
+ thread: z.ZodOptional<z.ZodString>;
934
+ }, z.core.$strip>], "sourceType">, z.ZodObject<{
935
+ type: z.ZodLiteral<"file">;
936
+ id: z.ZodString;
937
+ mediaType: z.ZodString;
938
+ url: z.ZodString;
939
+ filename: z.ZodOptional<z.ZodString>;
940
+ size: z.ZodOptional<z.ZodNumber>;
941
+ toolCallId: z.ZodOptional<z.ZodString>;
942
+ thread: z.ZodOptional<z.ZodString>;
943
+ }, z.core.$strip>, z.ZodObject<{
944
+ type: z.ZodLiteral<"object">;
945
+ id: z.ZodString;
946
+ typeName: z.ZodString;
947
+ partial: z.ZodOptional<z.ZodUnknown>;
948
+ object: z.ZodOptional<z.ZodUnknown>;
949
+ status: z.ZodEnum<{
950
+ streaming: "streaming";
951
+ error: "error";
952
+ done: "done";
953
+ }>;
954
+ error: z.ZodOptional<z.ZodString>;
955
+ thread: z.ZodOptional<z.ZodString>;
956
+ }, z.core.$strip>]>;
957
+ declare const uiMessageSchema: z.ZodObject<{
958
+ id: z.ZodString;
959
+ role: z.ZodEnum<{
960
+ user: "user";
961
+ assistant: "assistant";
962
+ }>;
963
+ parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
964
+ type: z.ZodLiteral<"text">;
965
+ text: z.ZodString;
966
+ status: z.ZodEnum<{
967
+ streaming: "streaming";
968
+ done: "done";
969
+ }>;
970
+ thread: z.ZodOptional<z.ZodString>;
971
+ }, z.core.$strip>, z.ZodObject<{
972
+ type: z.ZodLiteral<"reasoning">;
973
+ text: z.ZodString;
974
+ status: z.ZodEnum<{
975
+ streaming: "streaming";
976
+ done: "done";
977
+ }>;
978
+ thread: z.ZodOptional<z.ZodString>;
979
+ }, z.core.$strip>, z.ZodObject<{
980
+ type: z.ZodLiteral<"tool-call">;
981
+ toolCallId: z.ZodString;
982
+ toolName: z.ZodString;
983
+ displayName: z.ZodOptional<z.ZodString>;
984
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
985
+ result: z.ZodOptional<z.ZodUnknown>;
986
+ error: z.ZodOptional<z.ZodString>;
987
+ status: z.ZodEnum<{
988
+ pending: "pending";
989
+ error: "error";
990
+ done: "done";
991
+ running: "running";
992
+ }>;
993
+ thread: z.ZodOptional<z.ZodString>;
994
+ }, z.core.$strip>, z.ZodObject<{
995
+ type: z.ZodLiteral<"operation">;
996
+ operationId: z.ZodString;
997
+ name: z.ZodString;
998
+ operationType: z.ZodString;
999
+ status: z.ZodEnum<{
1000
+ done: "done";
1001
+ running: "running";
1002
+ }>;
1003
+ thread: z.ZodOptional<z.ZodString>;
1004
+ }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
1005
+ type: z.ZodLiteral<"source">;
1006
+ sourceType: z.ZodLiteral<"url">;
1007
+ id: z.ZodString;
1008
+ url: z.ZodString;
1009
+ title: z.ZodOptional<z.ZodString>;
1010
+ thread: z.ZodOptional<z.ZodString>;
1011
+ }, z.core.$strip>, z.ZodObject<{
1012
+ type: z.ZodLiteral<"source">;
1013
+ sourceType: z.ZodLiteral<"document">;
1014
+ id: z.ZodString;
1015
+ mediaType: z.ZodString;
1016
+ title: z.ZodString;
1017
+ filename: z.ZodOptional<z.ZodString>;
1018
+ thread: z.ZodOptional<z.ZodString>;
1019
+ }, z.core.$strip>], "sourceType">, z.ZodObject<{
1020
+ type: z.ZodLiteral<"file">;
1021
+ id: z.ZodString;
1022
+ mediaType: z.ZodString;
1023
+ url: z.ZodString;
1024
+ filename: z.ZodOptional<z.ZodString>;
1025
+ size: z.ZodOptional<z.ZodNumber>;
1026
+ toolCallId: z.ZodOptional<z.ZodString>;
1027
+ thread: z.ZodOptional<z.ZodString>;
1028
+ }, z.core.$strip>, z.ZodObject<{
1029
+ type: z.ZodLiteral<"object">;
1030
+ id: z.ZodString;
1031
+ typeName: z.ZodString;
1032
+ partial: z.ZodOptional<z.ZodUnknown>;
1033
+ object: z.ZodOptional<z.ZodUnknown>;
1034
+ status: z.ZodEnum<{
1035
+ streaming: "streaming";
1036
+ error: "error";
1037
+ done: "done";
1038
+ }>;
1039
+ error: z.ZodOptional<z.ZodString>;
1040
+ thread: z.ZodOptional<z.ZodString>;
1041
+ }, z.core.$strip>]>>;
1042
+ status: z.ZodEnum<{
1043
+ streaming: "streaming";
1044
+ done: "done";
1045
+ }>;
1046
+ createdAt: z.ZodCoercedDate<unknown>;
1047
+ }, z.core.$strip>;
1048
+ declare function safeParseStreamEvent(data: unknown): z.ZodSafeParseResult<{
1049
+ type: "source";
1050
+ sourceType: "url";
1051
+ id: string;
1052
+ url: string;
1053
+ title?: string | undefined;
1054
+ } | {
1055
+ type: "source";
1056
+ sourceType: "document";
1057
+ id: string;
1058
+ mediaType: string;
1059
+ title: string;
1060
+ filename?: string | undefined;
1061
+ } | {
1062
+ type: "start";
1063
+ messageId?: string | undefined;
1064
+ } | {
1065
+ type: "finish";
1066
+ finishReason: "error" | "stop" | "tool-calls" | "length" | "content-filter" | "other";
1067
+ } | {
1068
+ type: "error";
1069
+ errorType: "authentication_error" | "permission_error" | "validation_error" | "not_found_error" | "rate_limit_error" | "quota_exceeded_error" | "provider_error" | "provider_overloaded" | "provider_timeout" | "execution_error" | "tool_error" | "protocol_error" | "internal_error" | "unknown_error";
1070
+ message: string;
1071
+ retryable: boolean;
1072
+ source: "platform" | "provider" | "tool" | "client";
1073
+ retryAfter?: number | undefined;
1074
+ code?: string | undefined;
1075
+ provider?: {
1076
+ name: string;
1077
+ model?: string | undefined;
1078
+ statusCode?: number | undefined;
1079
+ errorType?: string | undefined;
1080
+ requestId?: string | undefined;
1081
+ } | undefined;
1082
+ tool?: {
1083
+ name: string;
1084
+ callId?: string | undefined;
1085
+ } | undefined;
1086
+ } | {
1087
+ type: "text-start";
1088
+ id: string;
1089
+ responseType?: string | undefined;
1090
+ } | {
1091
+ type: "text-delta";
1092
+ id: string;
1093
+ delta: string;
1094
+ } | {
1095
+ type: "text-end";
1096
+ id: string;
1097
+ } | {
1098
+ type: "reasoning-start";
1099
+ id: string;
1100
+ } | {
1101
+ type: "reasoning-delta";
1102
+ id: string;
1103
+ delta: string;
1104
+ } | {
1105
+ type: "reasoning-end";
1106
+ id: string;
1107
+ } | {
1108
+ type: "tool-input-start";
1109
+ toolCallId: string;
1110
+ toolName: string;
1111
+ title?: string | undefined;
1112
+ } | {
1113
+ type: "tool-input-delta";
1114
+ toolCallId: string;
1115
+ inputTextDelta: string;
1116
+ } | {
1117
+ type: "tool-input-end";
1118
+ toolCallId: string;
1119
+ } | {
1120
+ type: "tool-input-available";
1121
+ toolCallId: string;
1122
+ toolName: string;
1123
+ input: unknown;
1124
+ } | {
1125
+ type: "tool-output-available";
1126
+ toolCallId: string;
1127
+ output: unknown;
1128
+ } | {
1129
+ type: "tool-output-error";
1130
+ toolCallId: string;
1131
+ error: string;
1132
+ } | {
1133
+ type: "block-start";
1134
+ blockId: string;
1135
+ blockName: string;
1136
+ blockType: string;
1137
+ display: "name" | "hidden" | "description" | "stream";
1138
+ description?: string | undefined;
1139
+ outputToChat?: boolean | undefined;
1140
+ thread?: string | undefined;
1141
+ } | {
1142
+ type: "block-end";
1143
+ blockId: string;
1144
+ summary?: string | undefined;
1145
+ } | {
1146
+ type: "resource-update";
1147
+ name: string;
1148
+ value: unknown;
1149
+ } | {
1150
+ type: "tool-request";
1151
+ toolCalls: {
1152
+ toolCallId: string;
1153
+ toolName: string;
1154
+ args: Record<string, unknown>;
1155
+ source?: "llm" | "block" | undefined;
1156
+ outputVariable?: string | undefined;
1157
+ blockIndex?: number | undefined;
1158
+ }[];
1159
+ } | {
1160
+ type: "file-available";
1161
+ id: string;
1162
+ mediaType: string;
1163
+ url: string;
1164
+ filename?: string | undefined;
1165
+ size?: number | undefined;
1166
+ toolCallId?: string | undefined;
1167
+ }>;
1168
+ declare function safeParseUIMessage(data: unknown): z.ZodSafeParseResult<{
1169
+ id: string;
1170
+ role: "user" | "assistant";
1171
+ parts: ({
1172
+ type: "source";
1173
+ sourceType: "url";
1174
+ id: string;
1175
+ url: string;
1176
+ title?: string | undefined;
1177
+ thread?: string | undefined;
1178
+ } | {
1179
+ type: "source";
1180
+ sourceType: "document";
1181
+ id: string;
1182
+ mediaType: string;
1183
+ title: string;
1184
+ filename?: string | undefined;
1185
+ thread?: string | undefined;
1186
+ } | {
1187
+ type: "text";
1188
+ text: string;
1189
+ status: "streaming" | "done";
1190
+ thread?: string | undefined;
1191
+ } | {
1192
+ type: "reasoning";
1193
+ text: string;
1194
+ status: "streaming" | "done";
1195
+ thread?: string | undefined;
1196
+ } | {
1197
+ type: "tool-call";
1198
+ toolCallId: string;
1199
+ toolName: string;
1200
+ args: Record<string, unknown>;
1201
+ status: "pending" | "error" | "done" | "running";
1202
+ displayName?: string | undefined;
1203
+ result?: unknown;
1204
+ error?: string | undefined;
1205
+ thread?: string | undefined;
1206
+ } | {
1207
+ type: "operation";
1208
+ operationId: string;
1209
+ name: string;
1210
+ operationType: string;
1211
+ status: "done" | "running";
1212
+ thread?: string | undefined;
1213
+ } | {
1214
+ type: "file";
1215
+ id: string;
1216
+ mediaType: string;
1217
+ url: string;
1218
+ filename?: string | undefined;
1219
+ size?: number | undefined;
1220
+ toolCallId?: string | undefined;
1221
+ thread?: string | undefined;
1222
+ } | {
1223
+ type: "object";
1224
+ id: string;
1225
+ typeName: string;
1226
+ status: "streaming" | "error" | "done";
1227
+ partial?: unknown;
1228
+ object?: unknown;
1229
+ error?: string | undefined;
1230
+ thread?: string | undefined;
1231
+ })[];
1232
+ status: "streaming" | "done";
1233
+ createdAt: Date;
1234
+ }>;
1235
+ declare function safeParseUIMessages(data: unknown): z.ZodSafeParseResult<{
1236
+ id: string;
1237
+ role: "user" | "assistant";
1238
+ parts: ({
1239
+ type: "source";
1240
+ sourceType: "url";
1241
+ id: string;
1242
+ url: string;
1243
+ title?: string | undefined;
1244
+ thread?: string | undefined;
1245
+ } | {
1246
+ type: "source";
1247
+ sourceType: "document";
1248
+ id: string;
1249
+ mediaType: string;
1250
+ title: string;
1251
+ filename?: string | undefined;
1252
+ thread?: string | undefined;
1253
+ } | {
1254
+ type: "text";
1255
+ text: string;
1256
+ status: "streaming" | "done";
1257
+ thread?: string | undefined;
1258
+ } | {
1259
+ type: "reasoning";
1260
+ text: string;
1261
+ status: "streaming" | "done";
1262
+ thread?: string | undefined;
1263
+ } | {
1264
+ type: "tool-call";
1265
+ toolCallId: string;
1266
+ toolName: string;
1267
+ args: Record<string, unknown>;
1268
+ status: "pending" | "error" | "done" | "running";
1269
+ displayName?: string | undefined;
1270
+ result?: unknown;
1271
+ error?: string | undefined;
1272
+ thread?: string | undefined;
1273
+ } | {
1274
+ type: "operation";
1275
+ operationId: string;
1276
+ name: string;
1277
+ operationType: string;
1278
+ status: "done" | "running";
1279
+ thread?: string | undefined;
1280
+ } | {
1281
+ type: "file";
1282
+ id: string;
1283
+ mediaType: string;
1284
+ url: string;
1285
+ filename?: string | undefined;
1286
+ size?: number | undefined;
1287
+ toolCallId?: string | undefined;
1288
+ thread?: string | undefined;
1289
+ } | {
1290
+ type: "object";
1291
+ id: string;
1292
+ typeName: string;
1293
+ status: "streaming" | "error" | "done";
1294
+ partial?: unknown;
1295
+ object?: unknown;
1296
+ error?: string | undefined;
1297
+ thread?: string | undefined;
1298
+ })[];
1299
+ status: "streaming" | "done";
1300
+ createdAt: Date;
1301
+ }[]>;
1302
+ /**
1303
+ * Type guard to check if a value is a FileReference object.
1304
+ */
1305
+ declare function isFileReference(value: unknown): value is z.infer<typeof fileReferenceSchema>;
1306
+ /**
1307
+ * Type guard to check if a value is an array of FileReference objects.
1308
+ */
1309
+ declare function isFileReferenceArray(value: unknown): value is z.infer<typeof fileReferenceSchema>[];
1310
+
1089
1311
  /**
1090
1312
  * Octavus skill tool names
1091
1313
  *
@@ -1131,4 +1353,4 @@ declare function isOctavusSkillTool(toolName: string): toolName is OctavusSkillT
1131
1353
  */
1132
1354
  declare function getSkillSlugFromToolCall(toolName: string, args: Record<string, unknown> | undefined): string | undefined;
1133
1355
 
1134
- export { AppError, type BlockEndEvent, type BlockStartEvent, type ChatMessage, ConflictError, type DisplayMode, type ErrorEvent, type FileAvailableEvent, type FileInfo, type FileReference, type FinishEvent, type FinishReason, type GeneratedFile, MAIN_THREAD, type MessagePart, type MessagePartType, type MessageRole, NotFoundError, OCTAVUS_SKILL_TOOLS, type ObjectInfo, type OctavusSkillToolName, type PendingToolCall, type ReasoningDeltaEvent, type ReasoningEndEvent, type ReasoningStartEvent, type ResourceUpdateEvent, type ResourceUpdateHandler, type SourceDocumentEvent, type SourceDocumentInfo, type SourceEvent, type SourceInfo, type SourceUrlEvent, type SourceUrlInfo, type StartEvent, type StreamEvent, type TextDeltaEvent, type TextEndEvent, type TextStartEvent, type ToolCallInfo, type ToolCallStatus, type ToolHandler, type ToolHandlers, type ToolInputAvailableEvent, type ToolInputDeltaEvent, type ToolInputEndEvent, type ToolInputStartEvent, type ToolOutputAvailableEvent, type ToolOutputErrorEvent, type ToolRequestEvent, type ToolResult, type UIFilePart, type UIMessage, type UIMessagePart, type UIMessageStatus, type UIObjectPart, type UIObjectStatus, type UIOperationPart, type UIOperationStatus, type UIPartStatus, type UIReasoningPart, type UISourceDocumentPart, type UISourcePart, type UISourceUrlPart, type UITextPart, type UIToolCallPart, type UIToolCallStatus, ValidationError, chatMessageSchema, fileReferenceSchema, generateId, getSkillSlugFromToolCall, isAbortError, isFileReference, isFileReferenceArray, isMainThread, isOctavusSkillTool, isOtherThread, resolveThread, safeParseStreamEvent, safeParseUIMessage, safeParseUIMessages, threadForPart, toolResultSchema, uiMessagePartSchema, uiMessageSchema };
1356
+ export { AppError, type BlockEndEvent, type BlockStartEvent, type ChatMessage, ConflictError, type CreateErrorEventOptions, type DisplayMode, type ErrorEvent, type ErrorSource, type ErrorType, type FileAvailableEvent, type FileInfo, type FileReference, type FinishEvent, type FinishReason, ForbiddenError, type GeneratedFile, MAIN_THREAD, type MessagePart, type MessagePartType, type MessageRole, NotFoundError, OCTAVUS_SKILL_TOOLS, type ObjectInfo, OctavusError, type OctavusErrorOptions, type OctavusSkillToolName, type PendingToolCall, type ProviderErrorInfo, type ReasoningDeltaEvent, type ReasoningEndEvent, type ReasoningStartEvent, type ResourceUpdateEvent, type ResourceUpdateHandler, type SourceDocumentEvent, type SourceDocumentInfo, type SourceEvent, type SourceInfo, type SourceUrlEvent, type SourceUrlInfo, type StartEvent, type StreamEvent, type TextDeltaEvent, type TextEndEvent, type TextStartEvent, type ToolCallInfo, type ToolCallStatus, type ToolErrorInfo, type ToolHandler, type ToolHandlers, type ToolInputAvailableEvent, type ToolInputDeltaEvent, type ToolInputEndEvent, type ToolInputStartEvent, type ToolOutputAvailableEvent, type ToolOutputErrorEvent, type ToolRequestEvent, type ToolResult, type UIFilePart, type UIMessage, type UIMessagePart, type UIMessageStatus, type UIObjectPart, type UIObjectStatus, type UIOperationPart, type UIOperationStatus, type UIPartStatus, type UIReasoningPart, type UISourceDocumentPart, type UISourcePart, type UISourceUrlPart, type UITextPart, type UIToolCallPart, type UIToolCallStatus, ValidationError, chatMessageSchema, createApiErrorEvent, createErrorEvent, createInternalErrorEvent, errorToStreamEvent, fileReferenceSchema, generateId, getSkillSlugFromToolCall, isAbortError, isAuthenticationError, isFileReference, isFileReferenceArray, isMainThread, isOctavusSkillTool, isOtherThread, isProviderError, isRateLimitError, isRetryableError, isToolError, isValidationError, resolveThread, safeParseStreamEvent, safeParseUIMessage, safeParseUIMessages, threadForPart, toolResultSchema, uiMessagePartSchema, uiMessageSchema };