@octavus/core 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Octavus AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,324 @@
1
+ import { z } from 'zod';
2
+
3
+ declare class AppError extends Error {
4
+ code: string;
5
+ statusCode: number;
6
+ constructor(message: string, code: string, statusCode?: number);
7
+ }
8
+ declare class NotFoundError extends AppError {
9
+ constructor(resource: string, id: string);
10
+ }
11
+ declare class ValidationError extends AppError {
12
+ issues?: unknown[] | undefined;
13
+ constructor(message: string, issues?: unknown[] | undefined);
14
+ }
15
+ declare class ConflictError extends AppError {
16
+ constructor(resource: string, identifier: string);
17
+ }
18
+
19
+ /**
20
+ * Generate a unique ID for messages, tool calls, etc.
21
+ * Format: timestamp-random (e.g., "1702345678901-abc123def")
22
+ */
23
+ declare function generateId(): string;
24
+
25
+ /**
26
+ * Display mode - controls execution indicator visibility (NOT final message visibility).
27
+ * - hidden: Block runs silently
28
+ * - name: Shows block/tool name
29
+ * - description: Shows description
30
+ * - stream: Shows live streaming content
31
+ */
32
+ type DisplayMode = 'hidden' | 'name' | 'description' | 'stream';
33
+ type ToolHandler = (args: Record<string, unknown>) => Promise<unknown>;
34
+ type ToolHandlers = Record<string, ToolHandler>;
35
+ type ResourceUpdateHandler = (name: string, value: unknown) => Promise<void> | void;
36
+ type MessageRole = 'user' | 'assistant' | 'system';
37
+ type ToolCallStatus = 'pending' | 'in_progress' | 'completed' | 'error';
38
+ interface ToolCallInfo {
39
+ id: string;
40
+ name: string;
41
+ description?: string;
42
+ arguments: Record<string, unknown>;
43
+ status: ToolCallStatus;
44
+ result?: unknown;
45
+ error?: string;
46
+ }
47
+ interface TextDeltaEvent {
48
+ type: 'text-delta';
49
+ content: string;
50
+ }
51
+ interface TextStartEvent {
52
+ type: 'text-start';
53
+ id: string;
54
+ }
55
+ interface TextEndEvent {
56
+ type: 'text-end';
57
+ id: string;
58
+ }
59
+ interface ToolCallStartEvent {
60
+ type: 'tool-call-start';
61
+ toolCallId: string;
62
+ toolName: string;
63
+ toolDescription?: string;
64
+ toolDisplay?: DisplayMode;
65
+ }
66
+ interface ToolCallArgsEvent {
67
+ type: 'tool-call-args';
68
+ toolCallId: string;
69
+ argsJson: string;
70
+ }
71
+ interface ToolCallResultEvent {
72
+ type: 'tool-call-result';
73
+ toolCallId: string;
74
+ result: unknown;
75
+ }
76
+ interface ToolCallErrorEvent {
77
+ type: 'tool-call-error';
78
+ toolCallId: string;
79
+ error: string;
80
+ }
81
+ interface ResourceUpdateEvent {
82
+ type: 'resource-update';
83
+ name: string;
84
+ value: unknown;
85
+ }
86
+ interface DoneEvent {
87
+ type: 'done';
88
+ finishReason: 'stop' | 'tool-calls' | 'length' | 'error' | 'unknown';
89
+ }
90
+ interface ErrorEvent {
91
+ type: 'error';
92
+ message: string;
93
+ code?: string;
94
+ }
95
+ interface BlockStartEvent {
96
+ type: 'block-start';
97
+ blockId: string;
98
+ blockName: string;
99
+ blockType: string;
100
+ display: DisplayMode;
101
+ description?: string;
102
+ /** Whether output goes to main chat (false for independent blocks) */
103
+ outputToChat?: boolean;
104
+ }
105
+ interface BlockEndEvent {
106
+ type: 'block-end';
107
+ blockId: string;
108
+ summary?: string;
109
+ }
110
+ interface ThinkingStartEvent {
111
+ type: 'thinking-start';
112
+ id: string;
113
+ thread?: string;
114
+ }
115
+ interface ThinkingDeltaEvent {
116
+ type: 'thinking-delta';
117
+ content: string;
118
+ thread?: string;
119
+ }
120
+ interface ThinkingEndEvent {
121
+ type: 'thinking-end';
122
+ id: string;
123
+ }
124
+ interface PendingToolCall {
125
+ toolCallId: string;
126
+ toolName: string;
127
+ args: Record<string, unknown>;
128
+ /** 'llm' for LLM-initiated, 'block' for protocol block */
129
+ source?: 'llm' | 'block';
130
+ /** For block-based tools: variable name to store result in */
131
+ outputVariable?: string;
132
+ /** For block-based tools: block index to resume from after execution */
133
+ blockIndex?: number;
134
+ }
135
+ /**
136
+ * When this event is received, the stream will close.
137
+ * Consumer should execute the tools and POST a new trigger request with toolResults.
138
+ */
139
+ interface ToolRequestEvent {
140
+ type: 'tool-request';
141
+ toolCalls: PendingToolCall[];
142
+ }
143
+ interface ToolResult {
144
+ toolCallId: string;
145
+ toolName?: string;
146
+ result?: unknown;
147
+ error?: string;
148
+ outputVariable?: string;
149
+ blockIndex?: number;
150
+ }
151
+ type StreamEvent = TextDeltaEvent | TextStartEvent | TextEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallResultEvent | ToolCallErrorEvent | ToolRequestEvent | ResourceUpdateEvent | BlockStartEvent | BlockEndEvent | ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent | DoneEvent | ErrorEvent;
152
+ /**
153
+ * Type of content in a message part
154
+ */
155
+ type MessagePartType = 'text' | 'thinking' | 'tool-call';
156
+ /**
157
+ * A single part of a message, stored in order for proper display
158
+ */
159
+ interface MessagePart {
160
+ type: MessagePartType;
161
+ /** Whether shown in chat UI (false = LLM sees it, user doesn't) */
162
+ visible: boolean;
163
+ /** Content for text/thinking parts */
164
+ content?: string;
165
+ /** Tool call info for tool-call parts */
166
+ toolCall?: ToolCallInfo;
167
+ /** Thread name for non-main-thread content (e.g., "summary") */
168
+ thread?: string;
169
+ }
170
+ interface ChatMessage {
171
+ id: string;
172
+ role: MessageRole;
173
+ /** Ordered parts for display - preserves thinking/tool/text order */
174
+ parts: MessagePart[];
175
+ createdAt: string;
176
+ /**
177
+ * Whether shown in chat UI (false = LLM sees it, user doesn't).
178
+ * Use for internal directives. Different from `display` which controls execution indicator.
179
+ * @default true
180
+ */
181
+ visible?: boolean;
182
+ content: string;
183
+ toolCalls?: ToolCallInfo[];
184
+ reasoning?: string;
185
+ /** Required by Anthropic to verify thinking blocks */
186
+ reasoningSignature?: string;
187
+ }
188
+
189
+ /**
190
+ * Schema for tool result (consumer's response to tool-request)
191
+ */
192
+ declare const toolResultSchema: z.ZodObject<{
193
+ toolCallId: z.ZodString;
194
+ toolName: z.ZodOptional<z.ZodString>;
195
+ result: z.ZodOptional<z.ZodUnknown>;
196
+ error: z.ZodOptional<z.ZodString>;
197
+ outputVariable: z.ZodOptional<z.ZodString>;
198
+ blockIndex: z.ZodOptional<z.ZodNumber>;
199
+ }, z.core.$strip>;
200
+ declare const chatMessageSchema: z.ZodObject<{
201
+ id: z.ZodString;
202
+ role: z.ZodEnum<{
203
+ user: "user";
204
+ assistant: "assistant";
205
+ system: "system";
206
+ }>;
207
+ parts: z.ZodArray<z.ZodObject<{
208
+ type: z.ZodEnum<{
209
+ text: "text";
210
+ thinking: "thinking";
211
+ "tool-call": "tool-call";
212
+ }>;
213
+ visible: z.ZodBoolean;
214
+ content: z.ZodOptional<z.ZodString>;
215
+ toolCall: z.ZodOptional<z.ZodObject<{
216
+ id: z.ZodString;
217
+ name: z.ZodString;
218
+ description: z.ZodOptional<z.ZodString>;
219
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
220
+ status: z.ZodEnum<{
221
+ pending: "pending";
222
+ in_progress: "in_progress";
223
+ completed: "completed";
224
+ error: "error";
225
+ }>;
226
+ result: z.ZodOptional<z.ZodUnknown>;
227
+ error: z.ZodOptional<z.ZodString>;
228
+ }, z.core.$strip>>;
229
+ thread: z.ZodOptional<z.ZodString>;
230
+ }, z.core.$strip>>;
231
+ createdAt: z.ZodString;
232
+ visible: z.ZodOptional<z.ZodBoolean>;
233
+ content: z.ZodString;
234
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
235
+ id: z.ZodString;
236
+ name: z.ZodString;
237
+ description: z.ZodOptional<z.ZodString>;
238
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
239
+ status: z.ZodEnum<{
240
+ pending: "pending";
241
+ in_progress: "in_progress";
242
+ completed: "completed";
243
+ error: "error";
244
+ }>;
245
+ result: z.ZodOptional<z.ZodUnknown>;
246
+ error: z.ZodOptional<z.ZodString>;
247
+ }, z.core.$strip>>>;
248
+ reasoning: z.ZodOptional<z.ZodString>;
249
+ reasoningSignature: z.ZodOptional<z.ZodString>;
250
+ }, z.core.$strip>;
251
+ declare function safeParseStreamEvent(data: unknown): z.ZodSafeParseResult<{
252
+ type: "text-delta";
253
+ content: string;
254
+ } | {
255
+ type: "text-start";
256
+ id: string;
257
+ } | {
258
+ type: "text-end";
259
+ id: string;
260
+ } | {
261
+ type: "tool-call-start";
262
+ toolCallId: string;
263
+ toolName: string;
264
+ toolDescription?: string | undefined;
265
+ toolDisplay?: "hidden" | "name" | "description" | "stream" | undefined;
266
+ } | {
267
+ type: "tool-call-args";
268
+ toolCallId: string;
269
+ argsJson: string;
270
+ } | {
271
+ type: "tool-call-result";
272
+ toolCallId: string;
273
+ result: unknown;
274
+ } | {
275
+ type: "tool-call-error";
276
+ toolCallId: string;
277
+ error: string;
278
+ } | {
279
+ type: "tool-request";
280
+ toolCalls: {
281
+ toolCallId: string;
282
+ toolName: string;
283
+ args: Record<string, unknown>;
284
+ source?: "llm" | "block" | undefined;
285
+ outputVariable?: string | undefined;
286
+ blockIndex?: number | undefined;
287
+ }[];
288
+ } | {
289
+ type: "resource-update";
290
+ name: string;
291
+ value: unknown;
292
+ } | {
293
+ type: "block-start";
294
+ blockId: string;
295
+ blockName: string;
296
+ blockType: string;
297
+ display: "hidden" | "name" | "description" | "stream";
298
+ description?: string | undefined;
299
+ outputToChat?: boolean | undefined;
300
+ } | {
301
+ type: "block-end";
302
+ blockId: string;
303
+ summary?: string | undefined;
304
+ } | {
305
+ type: "thinking-start";
306
+ id: string;
307
+ thread?: string | undefined;
308
+ } | {
309
+ type: "thinking-delta";
310
+ content: string;
311
+ thread?: string | undefined;
312
+ } | {
313
+ type: "thinking-end";
314
+ id: string;
315
+ } | {
316
+ type: "done";
317
+ finishReason: "error" | "stop" | "tool-calls" | "length" | "unknown";
318
+ } | {
319
+ type: "error";
320
+ message: string;
321
+ code?: string | undefined;
322
+ }>;
323
+
324
+ export { AppError, type BlockEndEvent, type BlockStartEvent, type ChatMessage, ConflictError, type DisplayMode, type DoneEvent, type ErrorEvent, type MessagePart, type MessagePartType, type MessageRole, NotFoundError, type PendingToolCall, type ResourceUpdateEvent, type ResourceUpdateHandler, type StreamEvent, type TextDeltaEvent, type TextEndEvent, type TextStartEvent, type ThinkingDeltaEvent, type ThinkingEndEvent, type ThinkingStartEvent, type ToolCallArgsEvent, type ToolCallErrorEvent, type ToolCallInfo, type ToolCallResultEvent, type ToolCallStartEvent, type ToolCallStatus, type ToolHandler, type ToolHandlers, type ToolRequestEvent, type ToolResult, ValidationError, chatMessageSchema, generateId, safeParseStreamEvent, toolResultSchema };
package/dist/index.js ADDED
@@ -0,0 +1,196 @@
1
+ // src/errors.ts
2
+ var AppError = class extends Error {
3
+ constructor(message, code, statusCode = 500) {
4
+ super(message);
5
+ this.code = code;
6
+ this.statusCode = statusCode;
7
+ this.name = "AppError";
8
+ }
9
+ };
10
+ var NotFoundError = class extends AppError {
11
+ constructor(resource, id) {
12
+ super(`${resource} not found: ${id}`, "NOT_FOUND", 404);
13
+ this.name = "NotFoundError";
14
+ }
15
+ };
16
+ var ValidationError = class extends AppError {
17
+ constructor(message, issues) {
18
+ super(message, "VALIDATION_ERROR", 400);
19
+ this.issues = issues;
20
+ this.name = "ValidationError";
21
+ }
22
+ };
23
+ var ConflictError = class extends AppError {
24
+ constructor(resource, identifier) {
25
+ super(`${resource} already exists: ${identifier}`, "CONFLICT", 409);
26
+ this.name = "ConflictError";
27
+ }
28
+ };
29
+
30
+ // src/utils.ts
31
+ function generateId() {
32
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
33
+ }
34
+
35
+ // src/stream/schemas.ts
36
+ import { z } from "zod";
37
+ var displayModeSchema = z.enum(["hidden", "name", "description", "stream"]);
38
+ var messageRoleSchema = z.enum(["user", "assistant", "system"]);
39
+ var toolCallStatusSchema = z.enum(["pending", "in_progress", "completed", "error"]);
40
+ var finishReasonSchema = z.enum(["stop", "tool-calls", "length", "error", "unknown"]);
41
+ var toolCallInfoSchema = z.object({
42
+ id: z.string(),
43
+ name: z.string(),
44
+ description: z.string().optional(),
45
+ arguments: z.record(z.string(), z.unknown()),
46
+ status: toolCallStatusSchema,
47
+ result: z.unknown().optional(),
48
+ error: z.string().optional()
49
+ });
50
+ var textDeltaEventSchema = z.object({
51
+ type: z.literal("text-delta"),
52
+ content: z.string()
53
+ });
54
+ var textStartEventSchema = z.object({
55
+ type: z.literal("text-start"),
56
+ id: z.string()
57
+ });
58
+ var textEndEventSchema = z.object({
59
+ type: z.literal("text-end"),
60
+ id: z.string()
61
+ });
62
+ var toolCallStartEventSchema = z.object({
63
+ type: z.literal("tool-call-start"),
64
+ toolCallId: z.string(),
65
+ toolName: z.string(),
66
+ toolDescription: z.string().optional(),
67
+ toolDisplay: displayModeSchema.optional()
68
+ });
69
+ var toolCallArgsEventSchema = z.object({
70
+ type: z.literal("tool-call-args"),
71
+ toolCallId: z.string(),
72
+ argsJson: z.string()
73
+ });
74
+ var toolCallResultEventSchema = z.object({
75
+ type: z.literal("tool-call-result"),
76
+ toolCallId: z.string(),
77
+ result: z.unknown()
78
+ });
79
+ var toolCallErrorEventSchema = z.object({
80
+ type: z.literal("tool-call-error"),
81
+ toolCallId: z.string(),
82
+ error: z.string()
83
+ });
84
+ var resourceUpdateEventSchema = z.object({
85
+ type: z.literal("resource-update"),
86
+ name: z.string(),
87
+ value: z.unknown()
88
+ });
89
+ var doneEventSchema = z.object({
90
+ type: z.literal("done"),
91
+ finishReason: finishReasonSchema
92
+ });
93
+ var errorEventSchema = z.object({
94
+ type: z.literal("error"),
95
+ message: z.string(),
96
+ code: z.string().optional()
97
+ });
98
+ var blockStartEventSchema = z.object({
99
+ type: z.literal("block-start"),
100
+ blockId: z.string(),
101
+ blockName: z.string(),
102
+ blockType: z.string(),
103
+ display: displayModeSchema,
104
+ description: z.string().optional(),
105
+ outputToChat: z.boolean().optional()
106
+ });
107
+ var blockEndEventSchema = z.object({
108
+ type: z.literal("block-end"),
109
+ blockId: z.string(),
110
+ summary: z.string().optional()
111
+ });
112
+ var thinkingStartEventSchema = z.object({
113
+ type: z.literal("thinking-start"),
114
+ id: z.string(),
115
+ thread: z.string().optional()
116
+ });
117
+ var thinkingDeltaEventSchema = z.object({
118
+ type: z.literal("thinking-delta"),
119
+ content: z.string(),
120
+ thread: z.string().optional()
121
+ });
122
+ var thinkingEndEventSchema = z.object({
123
+ type: z.literal("thinking-end"),
124
+ id: z.string()
125
+ });
126
+ var pendingToolCallSchema = z.object({
127
+ toolCallId: z.string(),
128
+ toolName: z.string(),
129
+ args: z.record(z.string(), z.unknown()),
130
+ source: z.enum(["llm", "block"]).optional(),
131
+ outputVariable: z.string().optional(),
132
+ blockIndex: z.number().optional()
133
+ });
134
+ var toolRequestEventSchema = z.object({
135
+ type: z.literal("tool-request"),
136
+ toolCalls: z.array(pendingToolCallSchema)
137
+ });
138
+ var toolResultSchema = z.object({
139
+ toolCallId: z.string(),
140
+ toolName: z.string().optional(),
141
+ result: z.unknown().optional(),
142
+ error: z.string().optional(),
143
+ outputVariable: z.string().optional(),
144
+ blockIndex: z.number().optional()
145
+ });
146
+ var streamEventSchema = z.discriminatedUnion("type", [
147
+ textDeltaEventSchema,
148
+ textStartEventSchema,
149
+ textEndEventSchema,
150
+ toolCallStartEventSchema,
151
+ toolCallArgsEventSchema,
152
+ toolCallResultEventSchema,
153
+ toolCallErrorEventSchema,
154
+ toolRequestEventSchema,
155
+ resourceUpdateEventSchema,
156
+ blockStartEventSchema,
157
+ blockEndEventSchema,
158
+ thinkingStartEventSchema,
159
+ thinkingDeltaEventSchema,
160
+ thinkingEndEventSchema,
161
+ doneEventSchema,
162
+ errorEventSchema
163
+ ]);
164
+ var messagePartTypeSchema = z.enum(["text", "thinking", "tool-call"]);
165
+ var messagePartSchema = z.object({
166
+ type: messagePartTypeSchema,
167
+ visible: z.boolean(),
168
+ content: z.string().optional(),
169
+ toolCall: toolCallInfoSchema.optional(),
170
+ thread: z.string().optional()
171
+ });
172
+ var chatMessageSchema = z.object({
173
+ id: z.string(),
174
+ role: messageRoleSchema,
175
+ parts: z.array(messagePartSchema),
176
+ createdAt: z.string(),
177
+ visible: z.boolean().optional(),
178
+ content: z.string(),
179
+ toolCalls: z.array(toolCallInfoSchema).optional(),
180
+ reasoning: z.string().optional(),
181
+ reasoningSignature: z.string().optional()
182
+ });
183
+ function safeParseStreamEvent(data) {
184
+ return streamEventSchema.safeParse(data);
185
+ }
186
+ export {
187
+ AppError,
188
+ ConflictError,
189
+ NotFoundError,
190
+ ValidationError,
191
+ chatMessageSchema,
192
+ generateId,
193
+ safeParseStreamEvent,
194
+ toolResultSchema
195
+ };
196
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/utils.ts","../src/stream/schemas.ts"],"sourcesContent":["export class AppError extends Error {\n constructor(\n message: string,\n public code: string,\n public statusCode = 500,\n ) {\n super(message);\n this.name = 'AppError';\n }\n}\n\nexport class NotFoundError extends AppError {\n constructor(resource: string, id: string) {\n super(`${resource} not found: ${id}`, 'NOT_FOUND', 404);\n this.name = 'NotFoundError';\n }\n}\n\nexport class ValidationError extends AppError {\n constructor(\n message: string,\n public issues?: unknown[],\n ) {\n super(message, 'VALIDATION_ERROR', 400);\n this.name = 'ValidationError';\n }\n}\n\nexport class ConflictError extends AppError {\n constructor(resource: string, identifier: string) {\n super(`${resource} already exists: ${identifier}`, 'CONFLICT', 409);\n this.name = 'ConflictError';\n }\n}\n","/**\n * Generate a unique ID for messages, tool calls, etc.\n * Format: timestamp-random (e.g., \"1702345678901-abc123def\")\n */\nexport function generateId(): string {\n return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;\n}\n","import { z } from 'zod';\n\nexport const displayModeSchema = z.enum(['hidden', 'name', 'description', 'stream']);\nexport const messageRoleSchema = z.enum(['user', 'assistant', 'system']);\nexport const toolCallStatusSchema = z.enum(['pending', 'in_progress', 'completed', 'error']);\nexport const finishReasonSchema = z.enum(['stop', 'tool-calls', 'length', 'error', 'unknown']);\n\n// ToolCallInfo\nexport const toolCallInfoSchema = z.object({\n id: z.string(),\n name: z.string(),\n description: z.string().optional(),\n arguments: z.record(z.string(), z.unknown()),\n status: toolCallStatusSchema,\n result: z.unknown().optional(),\n error: z.string().optional(),\n});\n\n// Stream Events\nexport const textDeltaEventSchema = z.object({\n type: z.literal('text-delta'),\n content: z.string(),\n});\n\nexport const textStartEventSchema = z.object({\n type: z.literal('text-start'),\n id: z.string(),\n});\n\nexport const textEndEventSchema = z.object({\n type: z.literal('text-end'),\n id: z.string(),\n});\n\nexport const toolCallStartEventSchema = z.object({\n type: z.literal('tool-call-start'),\n toolCallId: z.string(),\n toolName: z.string(),\n toolDescription: z.string().optional(),\n toolDisplay: displayModeSchema.optional(),\n});\n\nexport const toolCallArgsEventSchema = z.object({\n type: z.literal('tool-call-args'),\n toolCallId: z.string(),\n argsJson: z.string(),\n});\n\nexport const toolCallResultEventSchema = z.object({\n type: z.literal('tool-call-result'),\n toolCallId: z.string(),\n result: z.unknown(),\n});\n\nexport const toolCallErrorEventSchema = z.object({\n type: z.literal('tool-call-error'),\n toolCallId: z.string(),\n error: z.string(),\n});\n\nexport const resourceUpdateEventSchema = z.object({\n type: z.literal('resource-update'),\n name: z.string(),\n value: z.unknown(),\n});\n\nexport const doneEventSchema = z.object({\n type: z.literal('done'),\n finishReason: finishReasonSchema,\n});\n\nexport const errorEventSchema = z.object({\n type: z.literal('error'),\n message: z.string(),\n code: z.string().optional(),\n});\n\nexport const blockStartEventSchema = z.object({\n type: z.literal('block-start'),\n blockId: z.string(),\n blockName: z.string(),\n blockType: z.string(),\n display: displayModeSchema,\n description: z.string().optional(),\n outputToChat: z.boolean().optional(),\n});\n\nexport const blockEndEventSchema = z.object({\n type: z.literal('block-end'),\n blockId: z.string(),\n summary: z.string().optional(),\n});\n\nexport const thinkingStartEventSchema = z.object({\n type: z.literal('thinking-start'),\n id: z.string(),\n thread: z.string().optional(),\n});\n\nexport const thinkingDeltaEventSchema = z.object({\n type: z.literal('thinking-delta'),\n content: z.string(),\n thread: z.string().optional(),\n});\n\nexport const thinkingEndEventSchema = z.object({\n type: z.literal('thinking-end'),\n id: z.string(),\n});\n\nexport const pendingToolCallSchema = z.object({\n toolCallId: z.string(),\n toolName: z.string(),\n args: z.record(z.string(), z.unknown()),\n source: z.enum(['llm', 'block']).optional(),\n outputVariable: z.string().optional(),\n blockIndex: z.number().optional(),\n});\n\nexport const toolRequestEventSchema = z.object({\n type: z.literal('tool-request'),\n toolCalls: z.array(pendingToolCallSchema),\n});\n\n/**\n * Schema for tool result (consumer's response to tool-request)\n */\nexport const toolResultSchema = z.object({\n toolCallId: z.string(),\n toolName: z.string().optional(),\n result: z.unknown().optional(),\n error: z.string().optional(),\n outputVariable: z.string().optional(),\n blockIndex: z.number().optional(),\n});\n\n// Union of all stream events\nexport const streamEventSchema = z.discriminatedUnion('type', [\n textDeltaEventSchema,\n textStartEventSchema,\n textEndEventSchema,\n toolCallStartEventSchema,\n toolCallArgsEventSchema,\n toolCallResultEventSchema,\n toolCallErrorEventSchema,\n toolRequestEventSchema,\n resourceUpdateEventSchema,\n blockStartEventSchema,\n blockEndEventSchema,\n thinkingStartEventSchema,\n thinkingDeltaEventSchema,\n thinkingEndEventSchema,\n doneEventSchema,\n errorEventSchema,\n]);\n\n// Message types\nexport const messagePartTypeSchema = z.enum(['text', 'thinking', 'tool-call']);\n\nexport const messagePartSchema = z.object({\n type: messagePartTypeSchema,\n visible: z.boolean(),\n content: z.string().optional(),\n toolCall: toolCallInfoSchema.optional(),\n thread: z.string().optional(),\n});\n\nexport const chatMessageSchema = z.object({\n id: z.string(),\n role: messageRoleSchema,\n parts: z.array(messagePartSchema),\n createdAt: z.string(),\n visible: z.boolean().optional(),\n content: z.string(),\n toolCalls: z.array(toolCallInfoSchema).optional(),\n reasoning: z.string().optional(),\n reasoningSignature: z.string().optional(),\n});\n\nexport function safeParseStreamEvent(data: unknown) {\n return streamEventSchema.safeParse(data);\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YACE,SACO,MACA,aAAa,KACpB;AACA,UAAM,OAAO;AAHN;AACA;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,SAAS;AAAA,EAC1C,YAAY,UAAkB,IAAY;AACxC,UAAM,GAAG,QAAQ,eAAe,EAAE,IAAI,aAAa,GAAG;AACtD,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,SAAS;AAAA,EAC5C,YACE,SACO,QACP;AACA,UAAM,SAAS,oBAAoB,GAAG;AAF/B;AAGP,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,SAAS;AAAA,EAC1C,YAAY,UAAkB,YAAoB;AAChD,UAAM,GAAG,QAAQ,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EAC7B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,gBAAgB,EAAE,OAAO,EAAE,SAAS;AAAA,EACpC,YAAY,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAGM,IAAM,oBAAoB,EAAE,mBAAmB,QAAQ;AAAA,EAC5D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,wBAAwB,EAAE,KAAK,CAAC,QAAQ,YAAY,WAAW,CAAC;AAEtE,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,MAAM;AAAA,EACN,SAAS,EAAE,QAAQ;AAAA,EACnB,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,UAAU,mBAAmB,SAAS;AAAA,EACtC,QAAQ,EAAE,OAAO,EAAE,SAAS;AAC9B,CAAC;AAEM,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,IAAI,EAAE,OAAO;AAAA,EACb,MAAM;AAAA,EACN,OAAO,EAAE,MAAM,iBAAiB;AAAA,EAChC,WAAW,EAAE,OAAO;AAAA,EACpB,SAAS,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC9B,SAAS,EAAE,OAAO;AAAA,EAClB,WAAW,EAAE,MAAM,kBAAkB,EAAE,SAAS;AAAA,EAChD,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,oBAAoB,EAAE,OAAO,EAAE,SAAS;AAC1C,CAAC;AAEM,SAAS,qBAAqB,MAAe;AAClD,SAAO,kBAAkB,UAAU,IAAI;AACzC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@octavus/core",
3
+ "version": "0.0.1",
4
+ "description": "Public types and utilities for Octavus client/server SDK communication",
5
+ "license": "MIT",
6
+ "author": "Octavus AI <hello@octavus.ai>",
7
+ "homepage": "https://octavus.dev",
8
+ "keywords": [
9
+ "octavus",
10
+ "ai",
11
+ "agents",
12
+ "sdk"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "devDependencies": {
31
+ "tsup": "^8.3.5",
32
+ "typescript": "^5.6.3"
33
+ },
34
+ "dependencies": {
35
+ "zod": "^4.1.13"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "dev": "tsup --watch",
40
+ "lint": "eslint src/ --max-warnings 0",
41
+ "lint:fix": "eslint src/ --max-warnings 0 --fix",
42
+ "type-check": "tsc --noEmit",
43
+ "clean": "rm -rf dist .turbo"
44
+ }
45
+ }