@classic-homes/agent-contracts 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,515 @@
1
+ import { z } from 'zod';
2
+ import { RequestId } from './ids.js';
3
+ /** Which backend produced a stream. `mock` must always be visible to the user. */
4
+ export declare const BackendMode: z.ZodEnum<{
5
+ mock: "mock";
6
+ live: "live";
7
+ }>;
8
+ export type BackendMode = z.infer<typeof BackendMode>;
9
+ export declare const ErrorCode: z.ZodEnum<{
10
+ bad_request: "bad_request";
11
+ unauthenticated: "unauthenticated";
12
+ forbidden: "forbidden";
13
+ not_found: "not_found";
14
+ message_too_large: "message_too_large";
15
+ rate_limited: "rate_limited";
16
+ upstream_unavailable: "upstream_unavailable";
17
+ upstream_error: "upstream_error";
18
+ timeout: "timeout";
19
+ cancelled: "cancelled";
20
+ internal: "internal";
21
+ }>;
22
+ export type ErrorCode = z.infer<typeof ErrorCode>;
23
+ /**
24
+ * Which agent run an event belongs to. The router's run has no parent; a delegated child's run
25
+ * names the router's run as its parent. Absent on the turn-level events (`start`, `done`).
26
+ */
27
+ export declare const AgentScope: z.ZodObject<{
28
+ agent: z.ZodString;
29
+ runId: z.ZodString;
30
+ parentRunId: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strip>;
32
+ export type AgentScope = z.infer<typeof AgentScope>;
33
+ export declare const StartEvent: z.ZodObject<{
34
+ conversationId: z.ZodString;
35
+ mode: z.ZodEnum<{
36
+ mock: "mock";
37
+ live: "live";
38
+ }>;
39
+ requestId: z.ZodUUID;
40
+ seq: z.ZodNumber;
41
+ type: z.ZodLiteral<"start">;
42
+ }, z.core.$strip>;
43
+ export declare const DeltaEvent: z.ZodObject<{
44
+ text: z.ZodString;
45
+ requestId: z.ZodUUID;
46
+ seq: z.ZodNumber;
47
+ type: z.ZodLiteral<"delta">;
48
+ }, z.core.$strip>;
49
+ export declare const ProposalEvent: z.ZodObject<{
50
+ operation: z.ZodUnion<readonly [z.ZodObject<{
51
+ target: z.ZodObject<{
52
+ sheet: z.ZodString;
53
+ address: z.ZodString;
54
+ }, z.core.$strip>;
55
+ write: z.ZodDiscriminatedUnion<[z.ZodObject<{
56
+ type: z.ZodLiteral<"values">;
57
+ values: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
58
+ }, z.core.$strip>, z.ZodObject<{
59
+ type: z.ZodLiteral<"formulas">;
60
+ formulas: z.ZodArray<z.ZodArray<z.ZodString>>;
61
+ }, z.core.$strip>], "type">;
62
+ precondition: z.ZodObject<{
63
+ formulas: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
64
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>>;
65
+ }, z.core.$strip>;
66
+ operationId: z.ZodUUID;
67
+ documentId: z.ZodString;
68
+ summary: z.ZodString;
69
+ kind: z.ZodLiteral<"excel.writeRange">;
70
+ }, z.core.$strip>, z.ZodObject<{
71
+ target: z.ZodObject<{
72
+ targetId: z.ZodString;
73
+ expectedText: z.ZodString;
74
+ }, z.core.$strip>;
75
+ location: z.ZodEnum<{
76
+ before: "before";
77
+ after: "after";
78
+ }>;
79
+ text: z.ZodString;
80
+ operationId: z.ZodUUID;
81
+ documentId: z.ZodString;
82
+ summary: z.ZodString;
83
+ kind: z.ZodLiteral<"word.insertText">;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ target: z.ZodObject<{
86
+ targetId: z.ZodString;
87
+ expectedText: z.ZodString;
88
+ }, z.core.$strip>;
89
+ text: z.ZodString;
90
+ operationId: z.ZodUUID;
91
+ documentId: z.ZodString;
92
+ summary: z.ZodString;
93
+ kind: z.ZodLiteral<"word.replaceSelection">;
94
+ }, z.core.$strip>]>;
95
+ requestId: z.ZodUUID;
96
+ seq: z.ZodNumber;
97
+ type: z.ZodLiteral<"proposal">;
98
+ }, z.core.$strip>;
99
+ export declare const ErrorEvent: z.ZodObject<{
100
+ code: z.ZodEnum<{
101
+ bad_request: "bad_request";
102
+ unauthenticated: "unauthenticated";
103
+ forbidden: "forbidden";
104
+ not_found: "not_found";
105
+ message_too_large: "message_too_large";
106
+ rate_limited: "rate_limited";
107
+ upstream_unavailable: "upstream_unavailable";
108
+ upstream_error: "upstream_error";
109
+ timeout: "timeout";
110
+ cancelled: "cancelled";
111
+ internal: "internal";
112
+ }>;
113
+ message: z.ZodString;
114
+ retryable: z.ZodBoolean;
115
+ requestId: z.ZodUUID;
116
+ seq: z.ZodNumber;
117
+ type: z.ZodLiteral<"error">;
118
+ }, z.core.$strip>;
119
+ export declare const DoneEvent: z.ZodObject<{
120
+ finishReason: z.ZodEnum<{
121
+ length: "length";
122
+ error: "error";
123
+ cancelled: "cancelled";
124
+ stop: "stop";
125
+ }>;
126
+ requestId: z.ZodUUID;
127
+ seq: z.ZodNumber;
128
+ type: z.ZodLiteral<"done">;
129
+ }, z.core.$strip>;
130
+ /** The agent asked a tool to run. Arguments are previewed, never echoed in full. */
131
+ export declare const ToolCallEvent: z.ZodObject<{
132
+ callId: z.ZodString;
133
+ name: z.ZodString;
134
+ server: z.ZodOptional<z.ZodString>;
135
+ argsPreview: z.ZodString;
136
+ agent: z.ZodString;
137
+ runId: z.ZodString;
138
+ parentRunId: z.ZodOptional<z.ZodString>;
139
+ requestId: z.ZodUUID;
140
+ seq: z.ZodNumber;
141
+ type: z.ZodLiteral<"tool_call">;
142
+ }, z.core.$strip>;
143
+ export declare const ToolResultStatus: z.ZodEnum<{
144
+ error: "error";
145
+ unauthenticated: "unauthenticated";
146
+ ok: "ok";
147
+ refused: "refused";
148
+ }>;
149
+ export type ToolResultStatus = z.infer<typeof ToolResultStatus>;
150
+ export declare const ToolResultEvent: z.ZodObject<{
151
+ callId: z.ZodString;
152
+ status: z.ZodEnum<{
153
+ error: "error";
154
+ unauthenticated: "unauthenticated";
155
+ ok: "ok";
156
+ refused: "refused";
157
+ }>;
158
+ durationMs: z.ZodNumber;
159
+ summary: z.ZodString;
160
+ agent: z.ZodString;
161
+ runId: z.ZodString;
162
+ parentRunId: z.ZodOptional<z.ZodString>;
163
+ requestId: z.ZodUUID;
164
+ seq: z.ZodNumber;
165
+ type: z.ZodLiteral<"tool_result">;
166
+ }, z.core.$strip>;
167
+ /** The router handed a task to a specialist child and later got it back. */
168
+ export declare const DelegationEvent: z.ZodObject<{
169
+ child: z.ZodString;
170
+ childRunId: z.ZodString;
171
+ status: z.ZodEnum<{
172
+ start: "start";
173
+ end: "end";
174
+ }>;
175
+ summary: z.ZodOptional<z.ZodString>;
176
+ agent: z.ZodString;
177
+ runId: z.ZodString;
178
+ parentRunId: z.ZodOptional<z.ZodString>;
179
+ requestId: z.ZodUUID;
180
+ seq: z.ZodNumber;
181
+ type: z.ZodLiteral<"delegation">;
182
+ }, z.core.$strip>;
183
+ export declare const ArtifactMediaType: z.ZodEnum<{
184
+ "text/markdown": "text/markdown";
185
+ "text/html": "text/html";
186
+ "application/vnd.ant.code": "application/vnd.ant.code";
187
+ "application/vnd.ant.mermaid": "application/vnd.ant.mermaid";
188
+ "application/vnd.ant.react": "application/vnd.ant.react";
189
+ "image/svg+xml": "image/svg+xml";
190
+ }>;
191
+ export type ArtifactMediaType = z.infer<typeof ArtifactMediaType>;
192
+ /**
193
+ * A rendered artifact streamed alongside the answer. `open` carries the metadata, `delta`
194
+ * appends text, `close` ends it. Artifacts render only inside the client sandbox.
195
+ */
196
+ export declare const ArtifactEvent: z.ZodObject<{
197
+ artifactId: z.ZodString;
198
+ op: z.ZodEnum<{
199
+ delta: "delta";
200
+ open: "open";
201
+ close: "close";
202
+ }>;
203
+ mediaType: z.ZodOptional<z.ZodEnum<{
204
+ "text/markdown": "text/markdown";
205
+ "text/html": "text/html";
206
+ "application/vnd.ant.code": "application/vnd.ant.code";
207
+ "application/vnd.ant.mermaid": "application/vnd.ant.mermaid";
208
+ "application/vnd.ant.react": "application/vnd.ant.react";
209
+ "image/svg+xml": "image/svg+xml";
210
+ }>>;
211
+ title: z.ZodOptional<z.ZodString>;
212
+ language: z.ZodOptional<z.ZodString>;
213
+ text: z.ZodOptional<z.ZodString>;
214
+ agent: z.ZodString;
215
+ runId: z.ZodString;
216
+ parentRunId: z.ZodOptional<z.ZodString>;
217
+ requestId: z.ZodUUID;
218
+ seq: z.ZodNumber;
219
+ type: z.ZodLiteral<"artifact">;
220
+ }, z.core.$strip>;
221
+ /** An MCP-UI resource returned by a tool. The client renders it in an isolated sandbox only. */
222
+ export declare const UiEvent: z.ZodObject<{
223
+ callId: z.ZodString;
224
+ uri: z.ZodString;
225
+ mimeType: z.ZodLiteral<"text/html">;
226
+ html: z.ZodString;
227
+ preferredFrameSize: z.ZodOptional<z.ZodTuple<[z.ZodString, z.ZodString], null>>;
228
+ agent: z.ZodString;
229
+ runId: z.ZodString;
230
+ parentRunId: z.ZodOptional<z.ZodString>;
231
+ requestId: z.ZodUUID;
232
+ seq: z.ZodNumber;
233
+ type: z.ZodLiteral<"ui">;
234
+ }, z.core.$strip>;
235
+ /** A file the agent produced or mirrored, downloadable from the backend. */
236
+ export declare const FileEvent: z.ZodObject<{
237
+ fileId: z.ZodString;
238
+ name: z.ZodString;
239
+ mimeType: z.ZodString;
240
+ bytes: z.ZodNumber;
241
+ path: z.ZodString;
242
+ agent: z.ZodString;
243
+ runId: z.ZodString;
244
+ parentRunId: z.ZodOptional<z.ZodString>;
245
+ requestId: z.ZodUUID;
246
+ seq: z.ZodNumber;
247
+ type: z.ZodLiteral<"file">;
248
+ }, z.core.$strip>;
249
+ /** Token usage of one model call. Display and budgeting only. */
250
+ export declare const UsageEvent: z.ZodObject<{
251
+ model: z.ZodString;
252
+ inputTokens: z.ZodNumber;
253
+ outputTokens: z.ZodNumber;
254
+ cacheReadTokens: z.ZodOptional<z.ZodNumber>;
255
+ agent: z.ZodString;
256
+ runId: z.ZodString;
257
+ parentRunId: z.ZodOptional<z.ZodString>;
258
+ requestId: z.ZodUUID;
259
+ seq: z.ZodNumber;
260
+ type: z.ZodLiteral<"usage">;
261
+ }, z.core.$strip>;
262
+ /**
263
+ * Streamed chat events. A well-formed stream is `start`, then any number of `delta`,
264
+ * `proposal`, `tool_call`, `tool_result`, `delegation`, `artifact`, `ui`, `file` and `usage`,
265
+ * then optionally one `error`, then exactly one `done`.
266
+ */
267
+ export declare const ChatEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
268
+ conversationId: z.ZodString;
269
+ mode: z.ZodEnum<{
270
+ mock: "mock";
271
+ live: "live";
272
+ }>;
273
+ requestId: z.ZodUUID;
274
+ seq: z.ZodNumber;
275
+ type: z.ZodLiteral<"start">;
276
+ }, z.core.$strip>, z.ZodObject<{
277
+ text: z.ZodString;
278
+ requestId: z.ZodUUID;
279
+ seq: z.ZodNumber;
280
+ type: z.ZodLiteral<"delta">;
281
+ }, z.core.$strip>, z.ZodObject<{
282
+ operation: z.ZodUnion<readonly [z.ZodObject<{
283
+ target: z.ZodObject<{
284
+ sheet: z.ZodString;
285
+ address: z.ZodString;
286
+ }, z.core.$strip>;
287
+ write: z.ZodDiscriminatedUnion<[z.ZodObject<{
288
+ type: z.ZodLiteral<"values">;
289
+ values: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
290
+ }, z.core.$strip>, z.ZodObject<{
291
+ type: z.ZodLiteral<"formulas">;
292
+ formulas: z.ZodArray<z.ZodArray<z.ZodString>>;
293
+ }, z.core.$strip>], "type">;
294
+ precondition: z.ZodObject<{
295
+ formulas: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
296
+ values: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>>;
297
+ }, z.core.$strip>;
298
+ operationId: z.ZodUUID;
299
+ documentId: z.ZodString;
300
+ summary: z.ZodString;
301
+ kind: z.ZodLiteral<"excel.writeRange">;
302
+ }, z.core.$strip>, z.ZodObject<{
303
+ target: z.ZodObject<{
304
+ targetId: z.ZodString;
305
+ expectedText: z.ZodString;
306
+ }, z.core.$strip>;
307
+ location: z.ZodEnum<{
308
+ before: "before";
309
+ after: "after";
310
+ }>;
311
+ text: z.ZodString;
312
+ operationId: z.ZodUUID;
313
+ documentId: z.ZodString;
314
+ summary: z.ZodString;
315
+ kind: z.ZodLiteral<"word.insertText">;
316
+ }, z.core.$strip>, z.ZodObject<{
317
+ target: z.ZodObject<{
318
+ targetId: z.ZodString;
319
+ expectedText: z.ZodString;
320
+ }, z.core.$strip>;
321
+ text: z.ZodString;
322
+ operationId: z.ZodUUID;
323
+ documentId: z.ZodString;
324
+ summary: z.ZodString;
325
+ kind: z.ZodLiteral<"word.replaceSelection">;
326
+ }, z.core.$strip>]>;
327
+ requestId: z.ZodUUID;
328
+ seq: z.ZodNumber;
329
+ type: z.ZodLiteral<"proposal">;
330
+ }, z.core.$strip>, z.ZodObject<{
331
+ code: z.ZodEnum<{
332
+ bad_request: "bad_request";
333
+ unauthenticated: "unauthenticated";
334
+ forbidden: "forbidden";
335
+ not_found: "not_found";
336
+ message_too_large: "message_too_large";
337
+ rate_limited: "rate_limited";
338
+ upstream_unavailable: "upstream_unavailable";
339
+ upstream_error: "upstream_error";
340
+ timeout: "timeout";
341
+ cancelled: "cancelled";
342
+ internal: "internal";
343
+ }>;
344
+ message: z.ZodString;
345
+ retryable: z.ZodBoolean;
346
+ requestId: z.ZodUUID;
347
+ seq: z.ZodNumber;
348
+ type: z.ZodLiteral<"error">;
349
+ }, z.core.$strip>, z.ZodObject<{
350
+ finishReason: z.ZodEnum<{
351
+ length: "length";
352
+ error: "error";
353
+ cancelled: "cancelled";
354
+ stop: "stop";
355
+ }>;
356
+ requestId: z.ZodUUID;
357
+ seq: z.ZodNumber;
358
+ type: z.ZodLiteral<"done">;
359
+ }, z.core.$strip>, z.ZodObject<{
360
+ callId: z.ZodString;
361
+ name: z.ZodString;
362
+ server: z.ZodOptional<z.ZodString>;
363
+ argsPreview: z.ZodString;
364
+ agent: z.ZodString;
365
+ runId: z.ZodString;
366
+ parentRunId: z.ZodOptional<z.ZodString>;
367
+ requestId: z.ZodUUID;
368
+ seq: z.ZodNumber;
369
+ type: z.ZodLiteral<"tool_call">;
370
+ }, z.core.$strip>, z.ZodObject<{
371
+ callId: z.ZodString;
372
+ status: z.ZodEnum<{
373
+ error: "error";
374
+ unauthenticated: "unauthenticated";
375
+ ok: "ok";
376
+ refused: "refused";
377
+ }>;
378
+ durationMs: z.ZodNumber;
379
+ summary: z.ZodString;
380
+ agent: z.ZodString;
381
+ runId: z.ZodString;
382
+ parentRunId: z.ZodOptional<z.ZodString>;
383
+ requestId: z.ZodUUID;
384
+ seq: z.ZodNumber;
385
+ type: z.ZodLiteral<"tool_result">;
386
+ }, z.core.$strip>, z.ZodObject<{
387
+ child: z.ZodString;
388
+ childRunId: z.ZodString;
389
+ status: z.ZodEnum<{
390
+ start: "start";
391
+ end: "end";
392
+ }>;
393
+ summary: z.ZodOptional<z.ZodString>;
394
+ agent: z.ZodString;
395
+ runId: z.ZodString;
396
+ parentRunId: z.ZodOptional<z.ZodString>;
397
+ requestId: z.ZodUUID;
398
+ seq: z.ZodNumber;
399
+ type: z.ZodLiteral<"delegation">;
400
+ }, z.core.$strip>, z.ZodObject<{
401
+ artifactId: z.ZodString;
402
+ op: z.ZodEnum<{
403
+ delta: "delta";
404
+ open: "open";
405
+ close: "close";
406
+ }>;
407
+ mediaType: z.ZodOptional<z.ZodEnum<{
408
+ "text/markdown": "text/markdown";
409
+ "text/html": "text/html";
410
+ "application/vnd.ant.code": "application/vnd.ant.code";
411
+ "application/vnd.ant.mermaid": "application/vnd.ant.mermaid";
412
+ "application/vnd.ant.react": "application/vnd.ant.react";
413
+ "image/svg+xml": "image/svg+xml";
414
+ }>>;
415
+ title: z.ZodOptional<z.ZodString>;
416
+ language: z.ZodOptional<z.ZodString>;
417
+ text: z.ZodOptional<z.ZodString>;
418
+ agent: z.ZodString;
419
+ runId: z.ZodString;
420
+ parentRunId: z.ZodOptional<z.ZodString>;
421
+ requestId: z.ZodUUID;
422
+ seq: z.ZodNumber;
423
+ type: z.ZodLiteral<"artifact">;
424
+ }, z.core.$strip>, z.ZodObject<{
425
+ callId: z.ZodString;
426
+ uri: z.ZodString;
427
+ mimeType: z.ZodLiteral<"text/html">;
428
+ html: z.ZodString;
429
+ preferredFrameSize: z.ZodOptional<z.ZodTuple<[z.ZodString, z.ZodString], null>>;
430
+ agent: z.ZodString;
431
+ runId: z.ZodString;
432
+ parentRunId: z.ZodOptional<z.ZodString>;
433
+ requestId: z.ZodUUID;
434
+ seq: z.ZodNumber;
435
+ type: z.ZodLiteral<"ui">;
436
+ }, z.core.$strip>, z.ZodObject<{
437
+ fileId: z.ZodString;
438
+ name: z.ZodString;
439
+ mimeType: z.ZodString;
440
+ bytes: z.ZodNumber;
441
+ path: z.ZodString;
442
+ agent: z.ZodString;
443
+ runId: z.ZodString;
444
+ parentRunId: z.ZodOptional<z.ZodString>;
445
+ requestId: z.ZodUUID;
446
+ seq: z.ZodNumber;
447
+ type: z.ZodLiteral<"file">;
448
+ }, z.core.$strip>, z.ZodObject<{
449
+ model: z.ZodString;
450
+ inputTokens: z.ZodNumber;
451
+ outputTokens: z.ZodNumber;
452
+ cacheReadTokens: z.ZodOptional<z.ZodNumber>;
453
+ agent: z.ZodString;
454
+ runId: z.ZodString;
455
+ parentRunId: z.ZodOptional<z.ZodString>;
456
+ requestId: z.ZodUUID;
457
+ seq: z.ZodNumber;
458
+ type: z.ZodLiteral<"usage">;
459
+ }, z.core.$strip>], "type">;
460
+ export type ChatEvent = z.infer<typeof ChatEvent>;
461
+ export type ChatEventType = ChatEvent['type'];
462
+ export type StartEvent = z.infer<typeof StartEvent>;
463
+ export type DeltaEvent = z.infer<typeof DeltaEvent>;
464
+ export type ProposalEvent = z.infer<typeof ProposalEvent>;
465
+ export type ErrorEvent = z.infer<typeof ErrorEvent>;
466
+ export type DoneEvent = z.infer<typeof DoneEvent>;
467
+ export type ToolCallEvent = z.infer<typeof ToolCallEvent>;
468
+ export type ToolResultEvent = z.infer<typeof ToolResultEvent>;
469
+ export type DelegationEvent = z.infer<typeof DelegationEvent>;
470
+ export type ArtifactEvent = z.infer<typeof ArtifactEvent>;
471
+ export type UiEvent = z.infer<typeof UiEvent>;
472
+ export type FileEvent = z.infer<typeof FileEvent>;
473
+ export type UsageEvent = z.infer<typeof UsageEvent>;
474
+ /** Event types every client must handle; the rest may be ignored by a client that cannot render them. */
475
+ export declare const CORE_EVENT_TYPES: readonly ["start", "delta", "proposal", "error", "done"];
476
+ /**
477
+ * Minimal shape of any stream event. A decoder validates this first so a client can keep its
478
+ * ordering guarantees for event types it does not know yet.
479
+ */
480
+ export declare const EventEnvelope: z.ZodObject<{
481
+ requestId: z.ZodUUID;
482
+ seq: z.ZodNumber;
483
+ type: z.ZodString;
484
+ }, z.core.$strip>;
485
+ export type EventEnvelope = z.infer<typeof EventEnvelope>;
486
+ /** An event of a type this client build does not know. Carries only the envelope. */
487
+ export type UnknownEvent = {
488
+ type: 'unknown';
489
+ requestId: RequestId;
490
+ seq: number;
491
+ rawType: string;
492
+ };
493
+ export type DecodedChatEvent = ChatEvent | UnknownEvent;
494
+ /** Non-stream JSON error body used for 4xx/5xx responses. */
495
+ export declare const ApiError: z.ZodObject<{
496
+ error: z.ZodObject<{
497
+ code: z.ZodEnum<{
498
+ bad_request: "bad_request";
499
+ unauthenticated: "unauthenticated";
500
+ forbidden: "forbidden";
501
+ not_found: "not_found";
502
+ message_too_large: "message_too_large";
503
+ rate_limited: "rate_limited";
504
+ upstream_unavailable: "upstream_unavailable";
505
+ upstream_error: "upstream_error";
506
+ timeout: "timeout";
507
+ cancelled: "cancelled";
508
+ internal: "internal";
509
+ }>;
510
+ message: z.ZodString;
511
+ correlationId: z.ZodOptional<z.ZodString>;
512
+ }, z.core.$strip>;
513
+ }, z.core.$strip>;
514
+ export type ApiError = z.infer<typeof ApiError>;
515
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKL,SAAS,EAGV,MAAM,UAAU,CAAC;AAIlB,kFAAkF;AAClF,eAAO,MAAM,WAAW;;;EAA2B,CAAC;AACpD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,eAAO,MAAM,SAAS;;;;;;;;;;;;EAYpB,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAQlD;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;iBAIrB,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAGpD,eAAO,MAAM,UAAU;;;;;;;;;iBAKrB,CAAC;AACH,eAAO,MAAM,UAAU;;;;;iBAAyE,CAAC;AACjG,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIxB,CAAC;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;iBAOrB,CAAC;AACH,eAAO,MAAM,SAAS;;;;;;;;;;iBAIpB,CAAC;AAEH,oFAAoF;AACpF,eAAO,MAAM,aAAa;;;;;;;;;;;iBAQxB,CAAC;AACH,eAAO,MAAM,gBAAgB;;;;;EAAwD,CAAC;AACtF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAChE,eAAO,MAAM,eAAe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.js ADDED
@@ -0,0 +1,178 @@
1
+ import { z } from 'zod';
2
+ import { AgentKey, ArtifactId, ConversationId, FileId, RequestId, RunId, ToolCallId, } from './ids.js';
3
+ import { LIMITS } from './limits.js';
4
+ import { ProposedOperation } from './operations.js';
5
+ /** Which backend produced a stream. `mock` must always be visible to the user. */
6
+ export const BackendMode = z.enum(['mock', 'live']);
7
+ export const ErrorCode = z.enum([
8
+ 'bad_request',
9
+ 'unauthenticated',
10
+ 'forbidden',
11
+ 'not_found',
12
+ 'message_too_large',
13
+ 'rate_limited',
14
+ 'upstream_unavailable',
15
+ 'upstream_error',
16
+ 'timeout',
17
+ 'cancelled',
18
+ 'internal',
19
+ ]);
20
+ const eventBase = {
21
+ requestId: RequestId,
22
+ /** Monotonic per-request sequence number starting at 0. */
23
+ seq: z.number().int().nonnegative(),
24
+ };
25
+ /**
26
+ * Which agent run an event belongs to. The router's run has no parent; a delegated child's run
27
+ * names the router's run as its parent. Absent on the turn-level events (`start`, `done`).
28
+ */
29
+ export const AgentScope = z.object({
30
+ agent: AgentKey,
31
+ runId: RunId,
32
+ parentRunId: RunId.optional(),
33
+ });
34
+ const scoped = { ...eventBase, ...AgentScope.shape };
35
+ export const StartEvent = z.object({
36
+ type: z.literal('start'),
37
+ ...eventBase,
38
+ conversationId: ConversationId,
39
+ mode: BackendMode,
40
+ });
41
+ export const DeltaEvent = z.object({ type: z.literal('delta'), ...eventBase, text: z.string() });
42
+ export const ProposalEvent = z.object({
43
+ type: z.literal('proposal'),
44
+ ...eventBase,
45
+ operation: ProposedOperation,
46
+ });
47
+ export const ErrorEvent = z.object({
48
+ type: z.literal('error'),
49
+ ...eventBase,
50
+ code: ErrorCode,
51
+ message: z.string().max(1_000),
52
+ /** Whether repeating the same chat request is safe. Never true for document writes. */
53
+ retryable: z.boolean(),
54
+ });
55
+ export const DoneEvent = z.object({
56
+ type: z.literal('done'),
57
+ ...eventBase,
58
+ finishReason: z.enum(['stop', 'length', 'cancelled', 'error']),
59
+ });
60
+ /** The agent asked a tool to run. Arguments are previewed, never echoed in full. */
61
+ export const ToolCallEvent = z.object({
62
+ type: z.literal('tool_call'),
63
+ ...scoped,
64
+ callId: ToolCallId,
65
+ name: z.string().min(1).max(128),
66
+ /** MCP server key for MCP tools; absent for builtins. */
67
+ server: z.string().min(1).max(64).optional(),
68
+ argsPreview: z.string().max(LIMITS.toolPreviewChars),
69
+ });
70
+ export const ToolResultStatus = z.enum(['ok', 'error', 'refused', 'unauthenticated']);
71
+ export const ToolResultEvent = z.object({
72
+ type: z.literal('tool_result'),
73
+ ...scoped,
74
+ callId: ToolCallId,
75
+ status: ToolResultStatus,
76
+ durationMs: z.number().int().nonnegative(),
77
+ summary: z.string().max(LIMITS.toolPreviewChars),
78
+ });
79
+ /** The router handed a task to a specialist child and later got it back. */
80
+ export const DelegationEvent = z.object({
81
+ type: z.literal('delegation'),
82
+ ...scoped,
83
+ child: AgentKey,
84
+ /** The child's run id, so its scoped events can be grouped under this delegation. */
85
+ childRunId: RunId,
86
+ status: z.enum(['start', 'end']),
87
+ summary: z.string().max(LIMITS.toolPreviewChars).optional(),
88
+ });
89
+ export const ArtifactMediaType = z.enum([
90
+ 'text/markdown',
91
+ 'text/html',
92
+ 'application/vnd.ant.code',
93
+ 'application/vnd.ant.mermaid',
94
+ 'application/vnd.ant.react',
95
+ 'image/svg+xml',
96
+ ]);
97
+ /**
98
+ * A rendered artifact streamed alongside the answer. `open` carries the metadata, `delta`
99
+ * appends text, `close` ends it. Artifacts render only inside the client sandbox.
100
+ */
101
+ export const ArtifactEvent = z.object({
102
+ type: z.literal('artifact'),
103
+ ...scoped,
104
+ artifactId: ArtifactId,
105
+ op: z.enum(['open', 'delta', 'close']),
106
+ mediaType: ArtifactMediaType.optional(),
107
+ title: z.string().max(200).optional(),
108
+ language: z.string().max(40).optional(),
109
+ text: z.string().max(LIMITS.artifactDeltaChars).optional(),
110
+ });
111
+ /** An MCP-UI resource returned by a tool. The client renders it in an isolated sandbox only. */
112
+ export const UiEvent = z.object({
113
+ type: z.literal('ui'),
114
+ ...scoped,
115
+ callId: ToolCallId,
116
+ uri: z.string().regex(/^ui:\/\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]+$/),
117
+ mimeType: z.literal('text/html'),
118
+ html: z.string().max(LIMITS.uiHtmlChars),
119
+ /** `[width, height]` CSS sizes suggested by the tool. */
120
+ preferredFrameSize: z.tuple([z.string().max(20), z.string().max(20)]).optional(),
121
+ });
122
+ /** A file the agent produced or mirrored, downloadable from the backend. */
123
+ export const FileEvent = z.object({
124
+ type: z.literal('file'),
125
+ ...scoped,
126
+ fileId: FileId,
127
+ name: z.string().min(1).max(255),
128
+ mimeType: z.string().min(1).max(127),
129
+ bytes: z.number().int().nonnegative(),
130
+ /** Same-origin download path on the backend; never an upstream or signed third-party URL. */
131
+ path: z.string().startsWith('/').max(512),
132
+ });
133
+ /** Token usage of one model call. Display and budgeting only. */
134
+ export const UsageEvent = z.object({
135
+ type: z.literal('usage'),
136
+ ...scoped,
137
+ model: z.string().min(1).max(100),
138
+ inputTokens: z.number().int().nonnegative(),
139
+ outputTokens: z.number().int().nonnegative(),
140
+ cacheReadTokens: z.number().int().nonnegative().optional(),
141
+ });
142
+ /**
143
+ * Streamed chat events. A well-formed stream is `start`, then any number of `delta`,
144
+ * `proposal`, `tool_call`, `tool_result`, `delegation`, `artifact`, `ui`, `file` and `usage`,
145
+ * then optionally one `error`, then exactly one `done`.
146
+ */
147
+ export const ChatEvent = z.discriminatedUnion('type', [
148
+ StartEvent,
149
+ DeltaEvent,
150
+ ProposalEvent,
151
+ ErrorEvent,
152
+ DoneEvent,
153
+ ToolCallEvent,
154
+ ToolResultEvent,
155
+ DelegationEvent,
156
+ ArtifactEvent,
157
+ UiEvent,
158
+ FileEvent,
159
+ UsageEvent,
160
+ ]);
161
+ /** Event types every client must handle; the rest may be ignored by a client that cannot render them. */
162
+ export const CORE_EVENT_TYPES = [
163
+ 'start',
164
+ 'delta',
165
+ 'proposal',
166
+ 'error',
167
+ 'done',
168
+ ];
169
+ /**
170
+ * Minimal shape of any stream event. A decoder validates this first so a client can keep its
171
+ * ordering guarantees for event types it does not know yet.
172
+ */
173
+ export const EventEnvelope = z.object({ type: z.string().min(1).max(64), ...eventBase });
174
+ /** Non-stream JSON error body used for 4xx/5xx responses. */
175
+ export const ApiError = z.object({
176
+ error: z.object({ code: ErrorCode, message: z.string(), correlationId: z.string().optional() }),
177
+ });
178
+ //# sourceMappingURL=events.js.map