@octavus/core 2.19.0 → 2.20.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.cjs ADDED
@@ -0,0 +1,883 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AppError: () => AppError,
24
+ ConflictError: () => ConflictError,
25
+ ForbiddenError: () => ForbiddenError,
26
+ MAIN_THREAD: () => MAIN_THREAD,
27
+ NotFoundError: () => NotFoundError,
28
+ OCTAVUS_INTERNAL_PREFIX: () => OCTAVUS_INTERNAL_PREFIX,
29
+ OCTAVUS_INTERNAL_TOOLS: () => OCTAVUS_INTERNAL_TOOLS,
30
+ OCTAVUS_REFERENCE_TOOLS: () => OCTAVUS_REFERENCE_TOOLS,
31
+ OCTAVUS_SKILL_TOOLS: () => OCTAVUS_SKILL_TOOLS,
32
+ OctavusError: () => OctavusError,
33
+ ValidationError: () => ValidationError,
34
+ chatMessageSchema: () => chatMessageSchema,
35
+ createApiErrorEvent: () => createApiErrorEvent,
36
+ createErrorEvent: () => createErrorEvent,
37
+ createInternalErrorEvent: () => createInternalErrorEvent,
38
+ errorToStreamEvent: () => errorToStreamEvent,
39
+ fileReferenceSchema: () => fileReferenceSchema,
40
+ generateId: () => generateId,
41
+ getSkillSlugFromToolCall: () => getSkillSlugFromToolCall,
42
+ isAbortError: () => isAbortError,
43
+ isAuthenticationError: () => isAuthenticationError,
44
+ isFileReference: () => isFileReference,
45
+ isFileReferenceArray: () => isFileReferenceArray,
46
+ isMainThread: () => isMainThread,
47
+ isOctavusInternalTool: () => isOctavusInternalTool,
48
+ isOctavusReferenceTool: () => isOctavusReferenceTool,
49
+ isOctavusSkillTool: () => isOctavusSkillTool,
50
+ isOtherThread: () => isOtherThread,
51
+ isProviderError: () => isProviderError,
52
+ isRateLimitError: () => isRateLimitError,
53
+ isRetryableError: () => isRetryableError,
54
+ isToolError: () => isToolError,
55
+ isValidationError: () => isValidationError,
56
+ resolveThread: () => resolveThread,
57
+ safeParseStreamEvent: () => safeParseStreamEvent,
58
+ safeParseUIMessage: () => safeParseUIMessage,
59
+ safeParseUIMessages: () => safeParseUIMessages,
60
+ threadForPart: () => threadForPart,
61
+ toolResultSchema: () => toolResultSchema,
62
+ uiMessagePartSchema: () => uiMessagePartSchema,
63
+ uiMessageSchema: () => uiMessageSchema,
64
+ uiWorkerPartSchema: () => uiWorkerPartSchema,
65
+ uiWorkerStatusSchema: () => uiWorkerStatusSchema
66
+ });
67
+ module.exports = __toCommonJS(index_exports);
68
+
69
+ // src/errors.ts
70
+ var AppError = class extends Error {
71
+ constructor(message, code, statusCode = 500) {
72
+ super(message);
73
+ this.code = code;
74
+ this.statusCode = statusCode;
75
+ this.name = "AppError";
76
+ }
77
+ };
78
+ var NotFoundError = class extends AppError {
79
+ constructor(resource, id) {
80
+ super(`${resource} not found: ${id}`, "NOT_FOUND", 404);
81
+ this.name = "NotFoundError";
82
+ }
83
+ };
84
+ var ValidationError = class extends AppError {
85
+ constructor(message, issues) {
86
+ super(message, "VALIDATION_ERROR", 400);
87
+ this.issues = issues;
88
+ this.name = "ValidationError";
89
+ }
90
+ };
91
+ var ConflictError = class extends AppError {
92
+ constructor(resource, identifier) {
93
+ super(`${resource} already exists: ${identifier}`, "CONFLICT", 409);
94
+ this.name = "ConflictError";
95
+ }
96
+ };
97
+ var ForbiddenError = class extends AppError {
98
+ constructor(message = "Access denied") {
99
+ super(message, "FORBIDDEN", 403);
100
+ this.name = "ForbiddenError";
101
+ }
102
+ };
103
+
104
+ // src/errors/octavus-error.ts
105
+ var MARKER_KEY = "octavus.error";
106
+ var OctavusError = class extends Error {
107
+ /** @internal Marker for cross-version instanceof checks */
108
+ __octavusErrorMarker = MARKER_KEY;
109
+ /** Error type classification */
110
+ errorType;
111
+ /** Where the error originated */
112
+ source;
113
+ /** Whether automatic retry is possible */
114
+ retryable;
115
+ /** Suggested retry delay in seconds (from provider headers) */
116
+ retryAfter;
117
+ /** Machine-readable error code */
118
+ code;
119
+ /** Provider details (when source === 'provider') */
120
+ provider;
121
+ /** Tool details (when source === 'tool') */
122
+ tool;
123
+ constructor(options) {
124
+ super(options.message);
125
+ this.name = "OctavusError";
126
+ this.errorType = options.errorType;
127
+ this.source = options.source;
128
+ this.retryable = options.retryable ?? false;
129
+ this.retryAfter = options.retryAfter;
130
+ this.code = options.code;
131
+ this.provider = options.provider;
132
+ this.tool = options.tool;
133
+ if (options.cause instanceof Error && options.cause.stack) {
134
+ this.stack = `${this.stack}
135
+ Caused by: ${options.cause.stack}`;
136
+ }
137
+ }
138
+ /**
139
+ * Check if an unknown value is an OctavusError.
140
+ * Works reliably across package versions using marker property.
141
+ */
142
+ static isInstance(error) {
143
+ return typeof error === "object" && error !== null && "__octavusErrorMarker" in error && error.__octavusErrorMarker === MARKER_KEY;
144
+ }
145
+ /**
146
+ * Convert error to plain object for serialization.
147
+ * Used for streaming error events.
148
+ */
149
+ toJSON() {
150
+ return {
151
+ name: this.name,
152
+ message: this.message,
153
+ errorType: this.errorType,
154
+ source: this.source,
155
+ retryable: this.retryable,
156
+ retryAfter: this.retryAfter,
157
+ code: this.code,
158
+ provider: this.provider,
159
+ tool: this.tool
160
+ };
161
+ }
162
+ };
163
+ function isRateLimitError(error) {
164
+ return OctavusError.isInstance(error) && (error.errorType === "rate_limit_error" || error.errorType === "quota_exceeded_error");
165
+ }
166
+ function isAuthenticationError(error) {
167
+ return OctavusError.isInstance(error) && (error.errorType === "authentication_error" || error.errorType === "permission_error");
168
+ }
169
+ function isProviderError(error) {
170
+ return OctavusError.isInstance(error) && error.source === "provider";
171
+ }
172
+ function isToolError(error) {
173
+ return OctavusError.isInstance(error) && (error.source === "tool" || error.errorType === "tool_error");
174
+ }
175
+ function isRetryableError(error) {
176
+ if (OctavusError.isInstance(error)) {
177
+ return error.retryable;
178
+ }
179
+ return false;
180
+ }
181
+ function isValidationError(error) {
182
+ return OctavusError.isInstance(error) && error.errorType === "validation_error";
183
+ }
184
+
185
+ // src/errors/helpers.ts
186
+ function createErrorEvent(options) {
187
+ return {
188
+ type: "error",
189
+ errorType: options.errorType,
190
+ message: options.message,
191
+ source: options.source,
192
+ retryable: options.retryable ?? false,
193
+ retryAfter: options.retryAfter,
194
+ code: options.code,
195
+ provider: options.provider,
196
+ tool: options.tool
197
+ };
198
+ }
199
+ function errorToStreamEvent(error) {
200
+ return createErrorEvent({
201
+ errorType: error.errorType,
202
+ message: error.message,
203
+ source: error.source,
204
+ retryable: error.retryable,
205
+ retryAfter: error.retryAfter,
206
+ code: error.code,
207
+ provider: error.provider,
208
+ tool: error.tool
209
+ });
210
+ }
211
+ function createInternalErrorEvent(message) {
212
+ return createErrorEvent({
213
+ errorType: "internal_error",
214
+ message,
215
+ source: "platform",
216
+ retryable: false
217
+ });
218
+ }
219
+ function mapStatusCodeToErrorType(statusCode) {
220
+ switch (statusCode) {
221
+ case 400:
222
+ return "validation_error";
223
+ case 401:
224
+ return "authentication_error";
225
+ case 403:
226
+ return "permission_error";
227
+ case 404:
228
+ return "not_found_error";
229
+ case 429:
230
+ return "rate_limit_error";
231
+ case 503:
232
+ return "provider_overloaded";
233
+ case 504:
234
+ return "provider_timeout";
235
+ default:
236
+ return statusCode >= 500 ? "internal_error" : "unknown_error";
237
+ }
238
+ }
239
+ function createApiErrorEvent(statusCode, message) {
240
+ const errorType = mapStatusCodeToErrorType(statusCode);
241
+ const retryable = statusCode === 429 || statusCode >= 500;
242
+ return createErrorEvent({
243
+ errorType,
244
+ message,
245
+ source: "platform",
246
+ retryable
247
+ });
248
+ }
249
+
250
+ // src/utils.ts
251
+ function generateId() {
252
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
253
+ }
254
+ function isAbortError(error) {
255
+ return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
256
+ error.name === "TimeoutError");
257
+ }
258
+
259
+ // src/thread.ts
260
+ var MAIN_THREAD = "main";
261
+ function resolveThread(thread) {
262
+ return thread ?? MAIN_THREAD;
263
+ }
264
+ function isMainThread(thread) {
265
+ return thread === void 0 || thread === MAIN_THREAD;
266
+ }
267
+ function threadForPart(thread) {
268
+ return isMainThread(thread) ? void 0 : thread;
269
+ }
270
+ function isOtherThread(part) {
271
+ return !isMainThread(part.thread);
272
+ }
273
+
274
+ // src/stream/schemas.ts
275
+ var import_zod = require("zod");
276
+ var displayModeSchema = import_zod.z.enum(["hidden", "name", "description", "stream"]);
277
+ var messageRoleSchema = import_zod.z.enum(["user", "assistant", "system"]);
278
+ var toolCallStatusSchema = import_zod.z.enum(["pending", "streaming", "available", "error"]);
279
+ var finishReasonSchema = import_zod.z.enum([
280
+ "stop",
281
+ "tool-calls",
282
+ "client-tool-calls",
283
+ "length",
284
+ "content-filter",
285
+ "error",
286
+ "other"
287
+ ]);
288
+ var toolCallInfoSchema = import_zod.z.object({
289
+ id: import_zod.z.string(),
290
+ name: import_zod.z.string(),
291
+ description: import_zod.z.string().optional(),
292
+ arguments: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()),
293
+ status: toolCallStatusSchema,
294
+ result: import_zod.z.unknown().optional(),
295
+ error: import_zod.z.string().optional(),
296
+ thoughtSignature: import_zod.z.string().optional(),
297
+ display: displayModeSchema.optional()
298
+ });
299
+ var startEventSchema = import_zod.z.object({
300
+ type: import_zod.z.literal("start"),
301
+ messageId: import_zod.z.string().optional(),
302
+ executionId: import_zod.z.string().optional(),
303
+ lastMessageId: import_zod.z.string().optional()
304
+ });
305
+ var finishEventSchema = import_zod.z.object({
306
+ type: import_zod.z.literal("finish"),
307
+ finishReason: finishReasonSchema,
308
+ executionId: import_zod.z.string().optional()
309
+ });
310
+ var errorTypeSchema = import_zod.z.enum([
311
+ "authentication_error",
312
+ "permission_error",
313
+ "validation_error",
314
+ "not_found_error",
315
+ "rate_limit_error",
316
+ "quota_exceeded_error",
317
+ "provider_error",
318
+ "provider_overloaded",
319
+ "provider_timeout",
320
+ "execution_error",
321
+ "tool_error",
322
+ "protocol_error",
323
+ "internal_error",
324
+ "unknown_error"
325
+ ]);
326
+ var errorSourceSchema = import_zod.z.enum(["platform", "provider", "tool", "client"]);
327
+ var providerErrorInfoSchema = import_zod.z.object({
328
+ name: import_zod.z.string(),
329
+ model: import_zod.z.string().optional(),
330
+ statusCode: import_zod.z.number().optional(),
331
+ errorType: import_zod.z.string().optional(),
332
+ requestId: import_zod.z.string().optional()
333
+ });
334
+ var toolErrorInfoSchema = import_zod.z.object({
335
+ name: import_zod.z.string(),
336
+ callId: import_zod.z.string().optional()
337
+ });
338
+ var errorEventSchema = import_zod.z.object({
339
+ type: import_zod.z.literal("error"),
340
+ errorType: errorTypeSchema,
341
+ message: import_zod.z.string(),
342
+ retryable: import_zod.z.boolean(),
343
+ source: errorSourceSchema,
344
+ retryAfter: import_zod.z.number().optional(),
345
+ code: import_zod.z.string().optional(),
346
+ provider: providerErrorInfoSchema.optional(),
347
+ tool: toolErrorInfoSchema.optional()
348
+ });
349
+ var textStartEventSchema = import_zod.z.object({
350
+ type: import_zod.z.literal("text-start"),
351
+ id: import_zod.z.string(),
352
+ responseType: import_zod.z.string().optional(),
353
+ workerId: import_zod.z.string().optional()
354
+ });
355
+ var textDeltaEventSchema = import_zod.z.object({
356
+ type: import_zod.z.literal("text-delta"),
357
+ id: import_zod.z.string(),
358
+ delta: import_zod.z.string(),
359
+ workerId: import_zod.z.string().optional()
360
+ });
361
+ var textEndEventSchema = import_zod.z.object({
362
+ type: import_zod.z.literal("text-end"),
363
+ id: import_zod.z.string(),
364
+ workerId: import_zod.z.string().optional()
365
+ });
366
+ var reasoningStartEventSchema = import_zod.z.object({
367
+ type: import_zod.z.literal("reasoning-start"),
368
+ id: import_zod.z.string(),
369
+ workerId: import_zod.z.string().optional()
370
+ });
371
+ var reasoningDeltaEventSchema = import_zod.z.object({
372
+ type: import_zod.z.literal("reasoning-delta"),
373
+ id: import_zod.z.string(),
374
+ delta: import_zod.z.string(),
375
+ workerId: import_zod.z.string().optional()
376
+ });
377
+ var reasoningEndEventSchema = import_zod.z.object({
378
+ type: import_zod.z.literal("reasoning-end"),
379
+ id: import_zod.z.string(),
380
+ workerId: import_zod.z.string().optional()
381
+ });
382
+ var toolInputStartEventSchema = import_zod.z.object({
383
+ type: import_zod.z.literal("tool-input-start"),
384
+ toolCallId: import_zod.z.string(),
385
+ toolName: import_zod.z.string(),
386
+ title: import_zod.z.string().optional(),
387
+ workerId: import_zod.z.string().optional()
388
+ });
389
+ var toolInputDeltaEventSchema = import_zod.z.object({
390
+ type: import_zod.z.literal("tool-input-delta"),
391
+ toolCallId: import_zod.z.string(),
392
+ inputTextDelta: import_zod.z.string(),
393
+ workerId: import_zod.z.string().optional()
394
+ });
395
+ var toolInputEndEventSchema = import_zod.z.object({
396
+ type: import_zod.z.literal("tool-input-end"),
397
+ toolCallId: import_zod.z.string(),
398
+ workerId: import_zod.z.string().optional()
399
+ });
400
+ var toolInputAvailableEventSchema = import_zod.z.object({
401
+ type: import_zod.z.literal("tool-input-available"),
402
+ toolCallId: import_zod.z.string(),
403
+ toolName: import_zod.z.string(),
404
+ input: import_zod.z.unknown(),
405
+ workerId: import_zod.z.string().optional()
406
+ });
407
+ var toolOutputAvailableEventSchema = import_zod.z.object({
408
+ type: import_zod.z.literal("tool-output-available"),
409
+ toolCallId: import_zod.z.string(),
410
+ output: import_zod.z.unknown(),
411
+ workerId: import_zod.z.string().optional()
412
+ });
413
+ var toolOutputErrorEventSchema = import_zod.z.object({
414
+ type: import_zod.z.literal("tool-output-error"),
415
+ toolCallId: import_zod.z.string(),
416
+ error: import_zod.z.string(),
417
+ workerId: import_zod.z.string().optional()
418
+ });
419
+ var sourceUrlEventSchema = import_zod.z.object({
420
+ type: import_zod.z.literal("source"),
421
+ sourceType: import_zod.z.literal("url"),
422
+ id: import_zod.z.string(),
423
+ url: import_zod.z.string(),
424
+ title: import_zod.z.string().optional(),
425
+ workerId: import_zod.z.string().optional()
426
+ });
427
+ var sourceDocumentEventSchema = import_zod.z.object({
428
+ type: import_zod.z.literal("source"),
429
+ sourceType: import_zod.z.literal("document"),
430
+ id: import_zod.z.string(),
431
+ mediaType: import_zod.z.string(),
432
+ title: import_zod.z.string(),
433
+ filename: import_zod.z.string().optional(),
434
+ workerId: import_zod.z.string().optional()
435
+ });
436
+ var sourceEventSchema = import_zod.z.discriminatedUnion("sourceType", [
437
+ sourceUrlEventSchema,
438
+ sourceDocumentEventSchema
439
+ ]);
440
+ var blockStartEventSchema = import_zod.z.object({
441
+ type: import_zod.z.literal("block-start"),
442
+ blockId: import_zod.z.string(),
443
+ blockName: import_zod.z.string(),
444
+ blockType: import_zod.z.string(),
445
+ display: displayModeSchema,
446
+ description: import_zod.z.string().optional(),
447
+ outputToChat: import_zod.z.boolean().optional(),
448
+ thread: import_zod.z.string().optional(),
449
+ workerId: import_zod.z.string().optional()
450
+ });
451
+ var blockEndEventSchema = import_zod.z.object({
452
+ type: import_zod.z.literal("block-end"),
453
+ blockId: import_zod.z.string(),
454
+ summary: import_zod.z.string().optional(),
455
+ workerId: import_zod.z.string().optional()
456
+ });
457
+ var resourceUpdateEventSchema = import_zod.z.object({
458
+ type: import_zod.z.literal("resource-update"),
459
+ name: import_zod.z.string(),
460
+ value: import_zod.z.unknown()
461
+ });
462
+ var fileReferenceSchema = import_zod.z.object({
463
+ id: import_zod.z.string(),
464
+ mediaType: import_zod.z.string(),
465
+ url: import_zod.z.string(),
466
+ filename: import_zod.z.string().optional(),
467
+ size: import_zod.z.number().optional()
468
+ });
469
+ var pendingToolCallSchema = import_zod.z.object({
470
+ toolCallId: import_zod.z.string(),
471
+ toolName: import_zod.z.string(),
472
+ args: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()),
473
+ source: import_zod.z.enum(["llm", "block"]).optional(),
474
+ outputVariable: import_zod.z.string().optional(),
475
+ blockIndex: import_zod.z.number().optional(),
476
+ thread: import_zod.z.string().optional(),
477
+ workerId: import_zod.z.string().optional()
478
+ });
479
+ var toolResultSchema = import_zod.z.object({
480
+ toolCallId: import_zod.z.string(),
481
+ toolName: import_zod.z.string().optional(),
482
+ result: import_zod.z.unknown().optional(),
483
+ error: import_zod.z.string().optional(),
484
+ files: import_zod.z.array(fileReferenceSchema).optional(),
485
+ outputVariable: import_zod.z.string().optional(),
486
+ blockIndex: import_zod.z.number().optional(),
487
+ thread: import_zod.z.string().optional(),
488
+ workerId: import_zod.z.string().optional()
489
+ });
490
+ var toolRequestEventSchema = import_zod.z.object({
491
+ type: import_zod.z.literal("tool-request"),
492
+ toolCalls: import_zod.z.array(pendingToolCallSchema),
493
+ workerId: import_zod.z.string().optional()
494
+ });
495
+ var clientToolRequestEventSchema = import_zod.z.object({
496
+ type: import_zod.z.literal("client-tool-request"),
497
+ executionId: import_zod.z.string(),
498
+ toolCalls: import_zod.z.array(pendingToolCallSchema),
499
+ serverToolResults: import_zod.z.array(toolResultSchema).optional()
500
+ });
501
+ var fileAvailableEventSchema = import_zod.z.object({
502
+ type: import_zod.z.literal("file-available"),
503
+ id: import_zod.z.string(),
504
+ mediaType: import_zod.z.string(),
505
+ url: import_zod.z.string(),
506
+ filename: import_zod.z.string().optional(),
507
+ size: import_zod.z.number().optional(),
508
+ toolCallId: import_zod.z.string().optional(),
509
+ workerId: import_zod.z.string().optional()
510
+ });
511
+ var workerStartEventSchema = import_zod.z.object({
512
+ type: import_zod.z.literal("worker-start"),
513
+ workerId: import_zod.z.string(),
514
+ workerSlug: import_zod.z.string(),
515
+ description: import_zod.z.string().optional()
516
+ });
517
+ var workerResultEventSchema = import_zod.z.object({
518
+ type: import_zod.z.literal("worker-result"),
519
+ workerId: import_zod.z.string(),
520
+ output: import_zod.z.unknown().optional(),
521
+ error: import_zod.z.string().optional()
522
+ });
523
+ var streamEventSchema = import_zod.z.union([
524
+ // Lifecycle events
525
+ startEventSchema,
526
+ finishEventSchema,
527
+ errorEventSchema,
528
+ // Text events
529
+ textStartEventSchema,
530
+ textDeltaEventSchema,
531
+ textEndEventSchema,
532
+ // Reasoning events
533
+ reasoningStartEventSchema,
534
+ reasoningDeltaEventSchema,
535
+ reasoningEndEventSchema,
536
+ // Tool events
537
+ toolInputStartEventSchema,
538
+ toolInputDeltaEventSchema,
539
+ toolInputEndEventSchema,
540
+ toolInputAvailableEventSchema,
541
+ toolOutputAvailableEventSchema,
542
+ toolOutputErrorEventSchema,
543
+ // Source events
544
+ sourceEventSchema,
545
+ // Octavus-specific events
546
+ blockStartEventSchema,
547
+ blockEndEventSchema,
548
+ resourceUpdateEventSchema,
549
+ toolRequestEventSchema,
550
+ clientToolRequestEventSchema,
551
+ fileAvailableEventSchema,
552
+ // Worker events
553
+ workerStartEventSchema,
554
+ workerResultEventSchema
555
+ ]);
556
+ var messagePartTypeSchema = import_zod.z.enum([
557
+ "text",
558
+ "reasoning",
559
+ "tool-call",
560
+ "operation",
561
+ "source",
562
+ "file",
563
+ "object",
564
+ "worker"
565
+ ]);
566
+ var sourceUrlInfoSchema = import_zod.z.object({
567
+ sourceType: import_zod.z.literal("url"),
568
+ id: import_zod.z.string(),
569
+ url: import_zod.z.string(),
570
+ title: import_zod.z.string().optional()
571
+ });
572
+ var sourceDocumentInfoSchema = import_zod.z.object({
573
+ sourceType: import_zod.z.literal("document"),
574
+ id: import_zod.z.string(),
575
+ mediaType: import_zod.z.string(),
576
+ title: import_zod.z.string(),
577
+ filename: import_zod.z.string().optional()
578
+ });
579
+ var sourceInfoSchema = import_zod.z.discriminatedUnion("sourceType", [
580
+ sourceUrlInfoSchema,
581
+ sourceDocumentInfoSchema
582
+ ]);
583
+ var fileInfoSchema = import_zod.z.object({
584
+ id: import_zod.z.string(),
585
+ mediaType: import_zod.z.string(),
586
+ url: import_zod.z.string(),
587
+ filename: import_zod.z.string().optional(),
588
+ size: import_zod.z.number().optional(),
589
+ toolCallId: import_zod.z.string().optional()
590
+ });
591
+ var objectInfoSchema = import_zod.z.object({
592
+ id: import_zod.z.string(),
593
+ typeName: import_zod.z.string(),
594
+ value: import_zod.z.unknown()
595
+ });
596
+ var operationInfoSchema = import_zod.z.object({
597
+ id: import_zod.z.string(),
598
+ name: import_zod.z.string(),
599
+ operationType: import_zod.z.string()
600
+ });
601
+ var baseMessagePartSchema = import_zod.z.object({
602
+ type: import_zod.z.enum(["text", "reasoning", "tool-call", "operation", "source", "file", "object"]),
603
+ visible: import_zod.z.boolean(),
604
+ content: import_zod.z.string().optional(),
605
+ toolCall: toolCallInfoSchema.optional(),
606
+ operation: operationInfoSchema.optional(),
607
+ source: sourceInfoSchema.optional(),
608
+ file: fileInfoSchema.optional(),
609
+ object: objectInfoSchema.optional(),
610
+ thread: import_zod.z.string().optional()
611
+ });
612
+ var workerPartInfoSchema = import_zod.z.object({
613
+ workerId: import_zod.z.string(),
614
+ workerSlug: import_zod.z.string(),
615
+ description: import_zod.z.string().optional(),
616
+ // Worker nested parts can contain base parts (text, reasoning, tools, etc.) but not nested workers
617
+ nestedParts: import_zod.z.array(baseMessagePartSchema),
618
+ output: import_zod.z.unknown().optional(),
619
+ error: import_zod.z.string().optional()
620
+ });
621
+ var messagePartSchema = import_zod.z.object({
622
+ type: messagePartTypeSchema,
623
+ visible: import_zod.z.boolean(),
624
+ content: import_zod.z.string().optional(),
625
+ toolCall: toolCallInfoSchema.optional(),
626
+ operation: operationInfoSchema.optional(),
627
+ source: sourceInfoSchema.optional(),
628
+ file: fileInfoSchema.optional(),
629
+ object: objectInfoSchema.optional(),
630
+ worker: workerPartInfoSchema.optional(),
631
+ thread: import_zod.z.string().optional()
632
+ });
633
+ var chatMessageSchema = import_zod.z.object({
634
+ id: import_zod.z.string(),
635
+ role: messageRoleSchema,
636
+ parts: import_zod.z.array(messagePartSchema),
637
+ createdAt: import_zod.z.string(),
638
+ visible: import_zod.z.boolean().optional(),
639
+ content: import_zod.z.string(),
640
+ toolCalls: import_zod.z.array(toolCallInfoSchema).optional(),
641
+ reasoning: import_zod.z.string().optional(),
642
+ reasoningSignature: import_zod.z.string().optional()
643
+ });
644
+ var uiMessageStatusSchema = import_zod.z.enum(["streaming", "done"]);
645
+ var uiPartStatusSchema = import_zod.z.enum(["streaming", "done"]);
646
+ var uiToolCallStatusSchema = import_zod.z.enum(["pending", "running", "done", "error"]);
647
+ var uiTextPartSchema = import_zod.z.object({
648
+ type: import_zod.z.literal("text"),
649
+ text: import_zod.z.string(),
650
+ status: uiPartStatusSchema,
651
+ thread: import_zod.z.string().optional()
652
+ });
653
+ var uiReasoningPartSchema = import_zod.z.object({
654
+ type: import_zod.z.literal("reasoning"),
655
+ text: import_zod.z.string(),
656
+ status: uiPartStatusSchema,
657
+ thread: import_zod.z.string().optional(),
658
+ providerMetadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
659
+ });
660
+ var uiToolCallPartSchema = import_zod.z.object({
661
+ type: import_zod.z.literal("tool-call"),
662
+ toolCallId: import_zod.z.string(),
663
+ toolName: import_zod.z.string(),
664
+ displayName: import_zod.z.string().optional(),
665
+ args: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()),
666
+ result: import_zod.z.unknown().optional(),
667
+ error: import_zod.z.string().optional(),
668
+ status: uiToolCallStatusSchema,
669
+ thread: import_zod.z.string().optional(),
670
+ providerMetadata: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
671
+ });
672
+ var uiOperationStatusSchema = import_zod.z.enum(["running", "done"]);
673
+ var uiOperationPartSchema = import_zod.z.object({
674
+ type: import_zod.z.literal("operation"),
675
+ operationId: import_zod.z.string(),
676
+ name: import_zod.z.string(),
677
+ operationType: import_zod.z.string(),
678
+ status: uiOperationStatusSchema,
679
+ thread: import_zod.z.string().optional()
680
+ });
681
+ var uiSourceUrlPartSchema = import_zod.z.object({
682
+ type: import_zod.z.literal("source"),
683
+ sourceType: import_zod.z.literal("url"),
684
+ id: import_zod.z.string(),
685
+ url: import_zod.z.string(),
686
+ title: import_zod.z.string().optional(),
687
+ thread: import_zod.z.string().optional()
688
+ });
689
+ var uiSourceDocumentPartSchema = import_zod.z.object({
690
+ type: import_zod.z.literal("source"),
691
+ sourceType: import_zod.z.literal("document"),
692
+ id: import_zod.z.string(),
693
+ mediaType: import_zod.z.string(),
694
+ title: import_zod.z.string(),
695
+ filename: import_zod.z.string().optional(),
696
+ thread: import_zod.z.string().optional()
697
+ });
698
+ var uiSourcePartSchema = import_zod.z.discriminatedUnion("sourceType", [
699
+ uiSourceUrlPartSchema,
700
+ uiSourceDocumentPartSchema
701
+ ]);
702
+ var uiFilePartSchema = import_zod.z.object({
703
+ type: import_zod.z.literal("file"),
704
+ id: import_zod.z.string(),
705
+ mediaType: import_zod.z.string(),
706
+ url: import_zod.z.string(),
707
+ filename: import_zod.z.string().optional(),
708
+ size: import_zod.z.number().optional(),
709
+ toolCallId: import_zod.z.string().optional(),
710
+ thread: import_zod.z.string().optional()
711
+ });
712
+ var uiObjectStatusSchema = import_zod.z.enum(["streaming", "done", "error"]);
713
+ var uiObjectPartSchema = import_zod.z.object({
714
+ type: import_zod.z.literal("object"),
715
+ id: import_zod.z.string(),
716
+ typeName: import_zod.z.string(),
717
+ partial: import_zod.z.unknown().optional(),
718
+ object: import_zod.z.unknown().optional(),
719
+ status: uiObjectStatusSchema,
720
+ error: import_zod.z.string().optional(),
721
+ thread: import_zod.z.string().optional()
722
+ });
723
+ var uiWorkerStatusSchema = import_zod.z.enum(["running", "done", "error"]);
724
+ var baseUiMessagePartSchema = import_zod.z.union([
725
+ uiTextPartSchema,
726
+ uiReasoningPartSchema,
727
+ uiToolCallPartSchema,
728
+ uiOperationPartSchema,
729
+ uiSourcePartSchema,
730
+ uiFilePartSchema,
731
+ uiObjectPartSchema
732
+ ]);
733
+ var uiWorkerPartSchema = import_zod.z.object({
734
+ type: import_zod.z.literal("worker"),
735
+ workerId: import_zod.z.string(),
736
+ workerSlug: import_zod.z.string(),
737
+ description: import_zod.z.string().optional(),
738
+ // Worker parts can contain base parts (text, reasoning, tools, etc.) but not nested workers
739
+ parts: import_zod.z.array(baseUiMessagePartSchema),
740
+ output: import_zod.z.unknown().optional(),
741
+ error: import_zod.z.string().optional(),
742
+ status: uiWorkerStatusSchema
743
+ });
744
+ var uiMessagePartSchema = import_zod.z.union([
745
+ uiTextPartSchema,
746
+ uiReasoningPartSchema,
747
+ uiToolCallPartSchema,
748
+ uiOperationPartSchema,
749
+ uiSourcePartSchema,
750
+ uiFilePartSchema,
751
+ uiObjectPartSchema,
752
+ uiWorkerPartSchema
753
+ ]);
754
+ var uiMessageSchema = import_zod.z.object({
755
+ id: import_zod.z.string(),
756
+ role: import_zod.z.enum(["user", "assistant"]),
757
+ parts: import_zod.z.array(uiMessagePartSchema),
758
+ status: uiMessageStatusSchema,
759
+ createdAt: import_zod.z.coerce.date()
760
+ });
761
+ function safeParseStreamEvent(data) {
762
+ return streamEventSchema.safeParse(data);
763
+ }
764
+ function safeParseUIMessage(data) {
765
+ return uiMessageSchema.safeParse(data);
766
+ }
767
+ function safeParseUIMessages(data) {
768
+ return import_zod.z.array(uiMessageSchema).safeParse(data);
769
+ }
770
+ function isFileReference(value) {
771
+ return fileReferenceSchema.safeParse(value).success;
772
+ }
773
+ function isFileReferenceArray(value) {
774
+ return import_zod.z.array(fileReferenceSchema).safeParse(value).success;
775
+ }
776
+
777
+ // src/internal-tools.ts
778
+ var OCTAVUS_INTERNAL_PREFIX = "octavus_";
779
+ var OCTAVUS_INTERNAL_TOOLS = {
780
+ // === Skill Tools (executed in E2B sandboxes) ===
781
+ /** Read skill documentation (SKILL.md) */
782
+ SKILL_READ: "octavus_skill_read",
783
+ /** List available scripts in a skill */
784
+ SKILL_LIST: "octavus_skill_list",
785
+ /** Execute a pre-built skill script */
786
+ SKILL_RUN: "octavus_skill_run",
787
+ /** Execute Python/Bash code in sandbox */
788
+ CODE_RUN: "octavus_code_run",
789
+ /** Create/write files in sandbox */
790
+ FILE_WRITE: "octavus_file_write",
791
+ /** Read files from sandbox */
792
+ FILE_READ: "octavus_file_read",
793
+ // === Reference Tools (agent-local documents fetched on demand) ===
794
+ /** List all available references with descriptions */
795
+ REFERENCE_LIST: "octavus_reference_list",
796
+ /** Read the full content of a specific reference */
797
+ REFERENCE_READ: "octavus_reference_read",
798
+ // === Image Generation ===
799
+ /** Generate images using AI models */
800
+ GENERATE_IMAGE: "octavus_generate_image",
801
+ // === Web Search ===
802
+ /** Search the web for current information */
803
+ WEB_SEARCH: "octavus_web_search"
804
+ };
805
+ function isOctavusInternalTool(toolName) {
806
+ return toolName.startsWith(OCTAVUS_INTERNAL_PREFIX);
807
+ }
808
+ var OCTAVUS_SKILL_TOOLS = {
809
+ SKILL_READ: OCTAVUS_INTERNAL_TOOLS.SKILL_READ,
810
+ SKILL_LIST: OCTAVUS_INTERNAL_TOOLS.SKILL_LIST,
811
+ SKILL_RUN: OCTAVUS_INTERNAL_TOOLS.SKILL_RUN,
812
+ CODE_RUN: OCTAVUS_INTERNAL_TOOLS.CODE_RUN,
813
+ FILE_WRITE: OCTAVUS_INTERNAL_TOOLS.FILE_WRITE,
814
+ FILE_READ: OCTAVUS_INTERNAL_TOOLS.FILE_READ
815
+ };
816
+ function isOctavusSkillTool(toolName) {
817
+ return Object.values(OCTAVUS_SKILL_TOOLS).includes(toolName);
818
+ }
819
+ var OCTAVUS_REFERENCE_TOOLS = {
820
+ REFERENCE_LIST: OCTAVUS_INTERNAL_TOOLS.REFERENCE_LIST,
821
+ REFERENCE_READ: OCTAVUS_INTERNAL_TOOLS.REFERENCE_READ
822
+ };
823
+ function isOctavusReferenceTool(toolName) {
824
+ return Object.values(OCTAVUS_REFERENCE_TOOLS).includes(toolName);
825
+ }
826
+
827
+ // src/skills.ts
828
+ function getSkillSlugFromToolCall(toolName, args) {
829
+ if (!isOctavusSkillTool(toolName) || !args) {
830
+ return void 0;
831
+ }
832
+ if (typeof args.skill === "string") {
833
+ return args.skill;
834
+ }
835
+ return void 0;
836
+ }
837
+ // Annotate the CommonJS export names for ESM import in node:
838
+ 0 && (module.exports = {
839
+ AppError,
840
+ ConflictError,
841
+ ForbiddenError,
842
+ MAIN_THREAD,
843
+ NotFoundError,
844
+ OCTAVUS_INTERNAL_PREFIX,
845
+ OCTAVUS_INTERNAL_TOOLS,
846
+ OCTAVUS_REFERENCE_TOOLS,
847
+ OCTAVUS_SKILL_TOOLS,
848
+ OctavusError,
849
+ ValidationError,
850
+ chatMessageSchema,
851
+ createApiErrorEvent,
852
+ createErrorEvent,
853
+ createInternalErrorEvent,
854
+ errorToStreamEvent,
855
+ fileReferenceSchema,
856
+ generateId,
857
+ getSkillSlugFromToolCall,
858
+ isAbortError,
859
+ isAuthenticationError,
860
+ isFileReference,
861
+ isFileReferenceArray,
862
+ isMainThread,
863
+ isOctavusInternalTool,
864
+ isOctavusReferenceTool,
865
+ isOctavusSkillTool,
866
+ isOtherThread,
867
+ isProviderError,
868
+ isRateLimitError,
869
+ isRetryableError,
870
+ isToolError,
871
+ isValidationError,
872
+ resolveThread,
873
+ safeParseStreamEvent,
874
+ safeParseUIMessage,
875
+ safeParseUIMessages,
876
+ threadForPart,
877
+ toolResultSchema,
878
+ uiMessagePartSchema,
879
+ uiMessageSchema,
880
+ uiWorkerPartSchema,
881
+ uiWorkerStatusSchema
882
+ });
883
+ //# sourceMappingURL=index.cjs.map