@futurity/chat-protocol 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/dist/index.js ADDED
@@ -0,0 +1,489 @@
1
+ // src/chat-websocket.ts
2
+ import { z as z2 } from "zod";
3
+
4
+ // src/message-parts.ts
5
+ import { z } from "zod";
6
+ var Z_ProviderMetadataSchema = z.record(
7
+ z.string(),
8
+ z.record(z.string(), z.any())
9
+ );
10
+ var Z_TextUIPartSchema = z.object({
11
+ type: z.literal("text"),
12
+ text: z.string(),
13
+ state: z.enum(["streaming", "done"]).optional(),
14
+ providerMetadata: Z_ProviderMetadataSchema.optional()
15
+ });
16
+ var Z_ReasoningUIPartSchema = z.object({
17
+ type: z.literal("reasoning"),
18
+ text: z.string(),
19
+ state: z.enum(["streaming", "done"]).optional(),
20
+ providerMetadata: Z_ProviderMetadataSchema.optional()
21
+ });
22
+ var Z_SourceUrlUIPartSchema = z.object({
23
+ type: z.literal("source-url"),
24
+ sourceId: z.string(),
25
+ url: z.string(),
26
+ title: z.string().optional(),
27
+ providerMetadata: Z_ProviderMetadataSchema.optional()
28
+ });
29
+ var Z_SourceDocumentUIPartSchema = z.object({
30
+ type: z.literal("source-document"),
31
+ sourceId: z.string(),
32
+ mediaType: z.string(),
33
+ title: z.string(),
34
+ filename: z.string().optional(),
35
+ providerMetadata: Z_ProviderMetadataSchema.optional()
36
+ });
37
+ var Z_FileUIPartSchema = z.object({
38
+ type: z.literal("file"),
39
+ mediaType: z.string(),
40
+ filename: z.string().optional(),
41
+ url: z.string(),
42
+ providerMetadata: Z_ProviderMetadataSchema.optional()
43
+ });
44
+ var Z_StepStartUIPartSchema = z.object({
45
+ type: z.literal("step-start")
46
+ });
47
+ var Z_DataUIPartSchema = z.object({
48
+ type: z.custom((value) => {
49
+ return typeof value === "string" && value.startsWith("data-");
50
+ }),
51
+ id: z.string().optional(),
52
+ data: z.unknown()
53
+ });
54
+ var Z_DataSplitSchema = z.object({
55
+ type: z.literal("data-split"),
56
+ data: z.object({
57
+ title: z.string(),
58
+ subtitle: z.string().optional(),
59
+ desktopSessionId: z.string().optional(),
60
+ subAgentId: z.string().optional()
61
+ })
62
+ });
63
+ var Z_DataEndSplitSchema = z.object({
64
+ type: z.literal("data-endsplit"),
65
+ data: z.object({
66
+ desktopSessionId: z.string().optional(),
67
+ subAgentId: z.string().optional()
68
+ }).optional()
69
+ });
70
+ var Z_DataSubagentPartSchema = z.object({
71
+ type: z.literal("data-subagent-part"),
72
+ data: z.object({
73
+ subAgentId: z.string(),
74
+ part: z.unknown()
75
+ })
76
+ });
77
+ var Z_DataStatusSchema = z.object({
78
+ type: z.literal("data-status"),
79
+ id: z.string().optional(),
80
+ data: z.object({
81
+ status: z.enum(["loading", "ready", "error"]),
82
+ text: z.string()
83
+ })
84
+ });
85
+ var Z_DataClarifyResponseSchema = z.object({
86
+ type: z.literal("data-clarify-response"),
87
+ data: z.object({
88
+ answers: z.record(z.string(), z.string())
89
+ })
90
+ });
91
+ var Z_DataScreenshotSchema = z.object({
92
+ type: z.literal("data-screenshot"),
93
+ data: z.object({
94
+ src: z.string(),
95
+ toolName: z.string().optional()
96
+ })
97
+ });
98
+ var Z_DataViewSwitchSchema = z.object({
99
+ type: z.literal("data-view-switch"),
100
+ data: z.object({
101
+ view: z.enum(["browser", "terminal"])
102
+ })
103
+ });
104
+ var Z_DataFileHighlightSchema = z.object({
105
+ type: z.literal("data-file-highlight"),
106
+ data: z.object({
107
+ path: z.string(),
108
+ label: z.string().optional()
109
+ })
110
+ });
111
+ var Z_BaseToolInvocationSchema = z.object({
112
+ toolCallId: z.string(),
113
+ title: z.string().optional(),
114
+ providerExecuted: z.boolean().optional()
115
+ });
116
+ var Z_ToolInvocationInputStreamingSchema = Z_BaseToolInvocationSchema.extend({
117
+ state: z.literal("input-streaming"),
118
+ input: z.unknown(),
119
+ callProviderMetadata: Z_ProviderMetadataSchema.optional()
120
+ });
121
+ var Z_ToolInvocationInputAvailableSchema = Z_BaseToolInvocationSchema.extend({
122
+ state: z.literal("input-available"),
123
+ input: z.unknown(),
124
+ callProviderMetadata: Z_ProviderMetadataSchema.optional()
125
+ });
126
+ var Z_ToolInvocationApprovalRequestedSchema = Z_BaseToolInvocationSchema.extend({
127
+ state: z.literal("approval-requested"),
128
+ input: z.unknown(),
129
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
130
+ approval: z.object({
131
+ id: z.string()
132
+ })
133
+ });
134
+ var Z_ToolInvocationApprovalRespondedSchema = Z_BaseToolInvocationSchema.extend({
135
+ state: z.literal("approval-responded"),
136
+ input: z.unknown(),
137
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
138
+ approval: z.object({
139
+ id: z.string(),
140
+ approved: z.boolean(),
141
+ reason: z.string().optional()
142
+ })
143
+ });
144
+ var Z_ToolInvocationOutputAvailableSchema = Z_BaseToolInvocationSchema.extend({
145
+ state: z.literal("output-available"),
146
+ input: z.unknown(),
147
+ output: z.unknown(),
148
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
149
+ preliminary: z.boolean().optional(),
150
+ approval: z.object({
151
+ id: z.string(),
152
+ approved: z.literal(true),
153
+ reason: z.string().optional()
154
+ }).optional()
155
+ });
156
+ var Z_ToolInvocationOutputErrorSchema = Z_BaseToolInvocationSchema.extend({
157
+ state: z.literal("output-error"),
158
+ input: z.unknown(),
159
+ rawInput: z.unknown().optional(),
160
+ errorText: z.string(),
161
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
162
+ approval: z.object({
163
+ id: z.string(),
164
+ approved: z.literal(true),
165
+ reason: z.string().optional()
166
+ }).optional()
167
+ });
168
+ var Z_ToolInvocationOutputDeniedSchema = Z_BaseToolInvocationSchema.extend({
169
+ state: z.literal("output-denied"),
170
+ input: z.unknown(),
171
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
172
+ approval: z.object({
173
+ id: z.string(),
174
+ approved: z.literal(false),
175
+ reason: z.string().optional()
176
+ })
177
+ });
178
+ var Z_ToolInvocationSchema = z.discriminatedUnion("state", [
179
+ Z_ToolInvocationInputStreamingSchema,
180
+ Z_ToolInvocationInputAvailableSchema,
181
+ Z_ToolInvocationApprovalRequestedSchema,
182
+ Z_ToolInvocationApprovalRespondedSchema,
183
+ Z_ToolInvocationOutputAvailableSchema,
184
+ Z_ToolInvocationOutputErrorSchema,
185
+ Z_ToolInvocationOutputDeniedSchema
186
+ ]);
187
+ var Z_ToolUIPartSchema = z.object({
188
+ type: z.custom((value) => {
189
+ return typeof value === "string" && value.startsWith("tool-");
190
+ })
191
+ }).and(Z_ToolInvocationSchema);
192
+ var Z_DynamicToolUIPartSchema = z.object({
193
+ type: z.literal("dynamic-tool"),
194
+ toolName: z.string(),
195
+ toolCallId: z.string(),
196
+ title: z.string().optional(),
197
+ providerExecuted: z.boolean().optional()
198
+ }).and(
199
+ z.discriminatedUnion("state", [
200
+ z.object({
201
+ state: z.literal("input-streaming"),
202
+ input: z.unknown(),
203
+ callProviderMetadata: Z_ProviderMetadataSchema.optional()
204
+ }),
205
+ z.object({
206
+ state: z.literal("input-available"),
207
+ input: z.unknown(),
208
+ callProviderMetadata: Z_ProviderMetadataSchema.optional()
209
+ }),
210
+ z.object({
211
+ state: z.literal("approval-requested"),
212
+ input: z.unknown(),
213
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
214
+ approval: z.object({
215
+ id: z.string()
216
+ })
217
+ }),
218
+ z.object({
219
+ state: z.literal("approval-responded"),
220
+ input: z.unknown(),
221
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
222
+ approval: z.object({
223
+ id: z.string(),
224
+ approved: z.boolean(),
225
+ reason: z.string().optional()
226
+ })
227
+ }),
228
+ z.object({
229
+ state: z.literal("output-available"),
230
+ input: z.unknown(),
231
+ output: z.unknown(),
232
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
233
+ preliminary: z.boolean().optional(),
234
+ approval: z.object({
235
+ id: z.string(),
236
+ approved: z.literal(true),
237
+ reason: z.string().optional()
238
+ }).optional()
239
+ }),
240
+ z.object({
241
+ state: z.literal("output-error"),
242
+ input: z.unknown(),
243
+ errorText: z.string(),
244
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
245
+ approval: z.object({
246
+ id: z.string(),
247
+ approved: z.literal(true),
248
+ reason: z.string().optional()
249
+ }).optional()
250
+ }),
251
+ z.object({
252
+ state: z.literal("output-denied"),
253
+ input: z.unknown(),
254
+ callProviderMetadata: Z_ProviderMetadataSchema.optional(),
255
+ approval: z.object({
256
+ id: z.string(),
257
+ approved: z.literal(false),
258
+ reason: z.string().optional()
259
+ })
260
+ })
261
+ ])
262
+ );
263
+ var Z_MessagePart = z.union([
264
+ Z_TextUIPartSchema,
265
+ Z_ReasoningUIPartSchema,
266
+ Z_SourceUrlUIPartSchema,
267
+ Z_SourceDocumentUIPartSchema,
268
+ Z_FileUIPartSchema,
269
+ Z_StepStartUIPartSchema,
270
+ Z_DataUIPartSchema,
271
+ Z_ToolUIPartSchema,
272
+ Z_DynamicToolUIPartSchema
273
+ ]);
274
+
275
+ // src/chat-websocket.ts
276
+ var wsMessageMetadataSchema = z2.object({
277
+ parent_id: z2.string().uuid().nullable()
278
+ });
279
+ var wsMessageSchema = z2.object({
280
+ id: z2.string(),
281
+ role: z2.enum(["user", "assistant", "system"]),
282
+ parts: z2.array(Z_MessagePart),
283
+ metadata: wsMessageMetadataSchema.optional()
284
+ });
285
+ var wsVaultItemSchema = z2.object({
286
+ id: z2.string(),
287
+ name: z2.string(),
288
+ url: z2.string()
289
+ });
290
+ var wsClarifyOptionSchema = z2.object({
291
+ label: z2.string(),
292
+ description: z2.string()
293
+ });
294
+ var wsClarifyQuestionSchema = z2.object({
295
+ question: z2.string(),
296
+ header: z2.string(),
297
+ options: z2.array(wsClarifyOptionSchema),
298
+ multiSelect: z2.boolean()
299
+ });
300
+ var wsRunCommandSchema = z2.object({
301
+ type: z2.literal("run"),
302
+ data: z2.object({
303
+ id: z2.string(),
304
+ message: wsMessageSchema,
305
+ vaultItems: z2.array(wsVaultItemSchema),
306
+ timezone: z2.string()
307
+ })
308
+ });
309
+ var wsGetChatCommandSchema = z2.object({
310
+ type: z2.literal("get_chat"),
311
+ data: z2.object({
312
+ chat_id: z2.string()
313
+ })
314
+ });
315
+ var wsCancelCommandSchema = z2.object({
316
+ type: z2.literal("cancel"),
317
+ data: z2.object({
318
+ job_id: z2.string()
319
+ })
320
+ });
321
+ var wsClarifyResponseCommandSchema = z2.object({
322
+ type: z2.literal("clarify_response"),
323
+ data: z2.object({
324
+ job_id: z2.string(),
325
+ requestId: z2.string(),
326
+ answers: z2.record(z2.string(), z2.string())
327
+ })
328
+ });
329
+ var wsInjectMessageCommandSchema = z2.object({
330
+ type: z2.literal("inject_message"),
331
+ data: z2.object({
332
+ job_id: z2.string(),
333
+ text: z2.string().max(5e4),
334
+ message_id: z2.string().uuid()
335
+ })
336
+ });
337
+ var wsClientCommandSchema = z2.discriminatedUnion("type", [
338
+ wsRunCommandSchema,
339
+ wsGetChatCommandSchema,
340
+ wsCancelCommandSchema,
341
+ wsClarifyResponseCommandSchema,
342
+ wsInjectMessageCommandSchema
343
+ ]);
344
+ var wsReadyMessageSchema = z2.object({
345
+ type: z2.literal("ready"),
346
+ data: z2.object({
347
+ success: z2.boolean()
348
+ })
349
+ });
350
+ var wsRunMessageSchema = z2.object({
351
+ type: z2.literal("run"),
352
+ data: z2.object({
353
+ job_id: z2.string(),
354
+ message_id: z2.string()
355
+ })
356
+ });
357
+ var wsStreamMessageSchema = z2.object({
358
+ type: z2.literal("stream"),
359
+ jobId: z2.string(),
360
+ chatId: z2.string(),
361
+ messageId: z2.string(),
362
+ delta: Z_MessagePart,
363
+ index: z2.number(),
364
+ consolidated: z2.boolean().optional().default(false),
365
+ partsLength: z2.number()
366
+ });
367
+ var wsStreamResumeMessageSchema = z2.object({
368
+ type: z2.literal("stream_resume"),
369
+ jobId: z2.string(),
370
+ chatId: z2.string(),
371
+ messageId: z2.string(),
372
+ parts: z2.array(Z_MessagePart)
373
+ });
374
+ var wsErrorMessageSchema = z2.object({
375
+ type: z2.literal("error"),
376
+ error: z2.string().optional(),
377
+ message: z2.string().optional(),
378
+ data: z2.any().optional()
379
+ });
380
+ var wsChatHistoryMessageSchema = z2.object({
381
+ type: z2.literal("chat_history"),
382
+ data: z2.object({
383
+ messages: z2.array(z2.any()),
384
+ activeMessageId: z2.string().optional()
385
+ })
386
+ });
387
+ var wsCancelMessageSchema = z2.object({
388
+ type: z2.literal("cancel"),
389
+ data: z2.object({
390
+ job_id: z2.string(),
391
+ success: z2.boolean(),
392
+ reason: z2.string().optional()
393
+ })
394
+ });
395
+ var wsDoneMessageSchema = z2.object({
396
+ type: z2.literal("done"),
397
+ data: z2.object({
398
+ job_id: z2.string()
399
+ })
400
+ });
401
+ var wsClarifyRequestMessageSchema = z2.object({
402
+ type: z2.literal("clarify_request"),
403
+ data: z2.object({
404
+ job_id: z2.string(),
405
+ requestId: z2.string(),
406
+ questions: z2.array(wsClarifyQuestionSchema)
407
+ })
408
+ });
409
+ var wsInjectAckMessageSchema = z2.object({
410
+ type: z2.literal("inject_ack"),
411
+ data: z2.object({
412
+ job_id: z2.string(),
413
+ inject_message_id: z2.string(),
414
+ new_assistant_id: z2.string()
415
+ })
416
+ });
417
+ var wsInjectSplitMessageSchema = z2.object({
418
+ type: z2.literal("inject_split"),
419
+ data: z2.object({
420
+ job_id: z2.string(),
421
+ new_message_id: z2.string()
422
+ })
423
+ });
424
+ var wsServerMessageSchema = z2.discriminatedUnion("type", [
425
+ wsReadyMessageSchema,
426
+ wsRunMessageSchema,
427
+ wsStreamMessageSchema,
428
+ wsStreamResumeMessageSchema,
429
+ wsErrorMessageSchema,
430
+ wsChatHistoryMessageSchema,
431
+ wsCancelMessageSchema,
432
+ wsDoneMessageSchema,
433
+ wsClarifyRequestMessageSchema,
434
+ wsInjectAckMessageSchema,
435
+ wsInjectSplitMessageSchema
436
+ ]);
437
+ export {
438
+ Z_BaseToolInvocationSchema,
439
+ Z_DataClarifyResponseSchema,
440
+ Z_DataEndSplitSchema,
441
+ Z_DataFileHighlightSchema,
442
+ Z_DataScreenshotSchema,
443
+ Z_DataSplitSchema,
444
+ Z_DataStatusSchema,
445
+ Z_DataSubagentPartSchema,
446
+ Z_DataUIPartSchema,
447
+ Z_DataViewSwitchSchema,
448
+ Z_DynamicToolUIPartSchema,
449
+ Z_FileUIPartSchema,
450
+ Z_MessagePart,
451
+ Z_ProviderMetadataSchema,
452
+ Z_ReasoningUIPartSchema,
453
+ Z_SourceDocumentUIPartSchema,
454
+ Z_SourceUrlUIPartSchema,
455
+ Z_StepStartUIPartSchema,
456
+ Z_TextUIPartSchema,
457
+ Z_ToolInvocationApprovalRequestedSchema,
458
+ Z_ToolInvocationApprovalRespondedSchema,
459
+ Z_ToolInvocationInputAvailableSchema,
460
+ Z_ToolInvocationInputStreamingSchema,
461
+ Z_ToolInvocationOutputAvailableSchema,
462
+ Z_ToolInvocationOutputDeniedSchema,
463
+ Z_ToolInvocationOutputErrorSchema,
464
+ Z_ToolInvocationSchema,
465
+ Z_ToolUIPartSchema,
466
+ wsCancelCommandSchema,
467
+ wsCancelMessageSchema,
468
+ wsChatHistoryMessageSchema,
469
+ wsClarifyOptionSchema,
470
+ wsClarifyQuestionSchema,
471
+ wsClarifyRequestMessageSchema,
472
+ wsClarifyResponseCommandSchema,
473
+ wsClientCommandSchema,
474
+ wsDoneMessageSchema,
475
+ wsErrorMessageSchema,
476
+ wsGetChatCommandSchema,
477
+ wsInjectAckMessageSchema,
478
+ wsInjectMessageCommandSchema,
479
+ wsInjectSplitMessageSchema,
480
+ wsMessageMetadataSchema,
481
+ wsMessageSchema,
482
+ wsReadyMessageSchema,
483
+ wsRunCommandSchema,
484
+ wsRunMessageSchema,
485
+ wsServerMessageSchema,
486
+ wsStreamMessageSchema,
487
+ wsStreamResumeMessageSchema,
488
+ wsVaultItemSchema
489
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@futurity/chat-protocol",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": ["dist", "src", "README.md"],
16
+ "scripts": {
17
+ "build": "tsup",
18
+ "check": "tsgo --noEmit",
19
+ "prepublishOnly": "tsup"
20
+ },
21
+ "peerDependencies": {
22
+ "zod": "^4.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "tsup": "^8.5.0",
26
+ "zod": "^4.1.13"
27
+ }
28
+ }