@machinemetrics/agent-event-protocol 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.
package/dist/core.d.ts ADDED
@@ -0,0 +1,463 @@
1
+ export { h as AbortedEvent, a as ActionResult, i as AgentEvent, b as AgentRequest, A as AssistantContentBlock, C as ContinuationEvent, D as DoneEvent, c as ErrorCode, g as ErrorEvent, E as EventStage, F as FinishReason, I as InputMessage, M as MetadataEvent, T as TextEvent, d as ThinkingEvent, e as ToolCallEvent, f as ToolResultEvent, U as UserContentBlock } from './types-CttB5bnC.js';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * Zod schema for validating user content blocks.
6
+ * Currently only supports text; extensible for multimodal.
7
+ */
8
+ declare const UserContentBlockSchema: z.ZodObject<{
9
+ type: z.ZodLiteral<"text">;
10
+ text: z.ZodString;
11
+ }, z.core.$strip>;
12
+ /**
13
+ * Zod schema for validating assistant content blocks.
14
+ * Discriminated union supporting text, thinking, tool_use, and tool_result.
15
+ */
16
+ declare const AssistantContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
17
+ type: z.ZodLiteral<"text">;
18
+ text: z.ZodString;
19
+ }, z.core.$strip>, z.ZodObject<{
20
+ type: z.ZodLiteral<"thinking">;
21
+ text: z.ZodString;
22
+ }, z.core.$strip>, z.ZodObject<{
23
+ type: z.ZodLiteral<"tool_use">;
24
+ toolCallId: z.ZodString;
25
+ tool: z.ZodString;
26
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ type: z.ZodLiteral<"tool_result">;
29
+ toolCallId: z.ZodString;
30
+ tool: z.ZodString;
31
+ status: z.ZodEnum<{
32
+ success: "success";
33
+ error: "error";
34
+ }>;
35
+ summary: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strip>], "type">;
37
+ /**
38
+ * Zod schema for validating input messages.
39
+ */
40
+ declare const InputMessageSchema: z.ZodObject<{
41
+ content: z.ZodArray<z.ZodObject<{
42
+ type: z.ZodLiteral<"text">;
43
+ text: z.ZodString;
44
+ }, z.core.$strip>>;
45
+ }, z.core.$strip>;
46
+ /**
47
+ * Zod schema for validating action results from continuation events.
48
+ */
49
+ declare const ActionResultSchema: z.ZodObject<{
50
+ actionId: z.ZodString;
51
+ kind: z.ZodString;
52
+ status: z.ZodEnum<{
53
+ success: "success";
54
+ error: "error";
55
+ }>;
56
+ data: z.ZodOptional<z.ZodUnknown>;
57
+ error: z.ZodOptional<z.ZodString>;
58
+ }, z.core.$strip>;
59
+ /**
60
+ * Zod schema for validating agent request payloads.
61
+ * Context object uses passthrough() to allow additional fields.
62
+ */
63
+ declare const AgentRequestSchema: z.ZodObject<{
64
+ messages: z.ZodArray<z.ZodObject<{
65
+ content: z.ZodArray<z.ZodObject<{
66
+ type: z.ZodLiteral<"text">;
67
+ text: z.ZodString;
68
+ }, z.core.$strip>>;
69
+ }, z.core.$strip>>;
70
+ threadId: z.ZodOptional<z.ZodString>;
71
+ context: z.ZodOptional<z.ZodObject<{
72
+ actionResults: z.ZodOptional<z.ZodArray<z.ZodObject<{
73
+ actionId: z.ZodString;
74
+ kind: z.ZodString;
75
+ status: z.ZodEnum<{
76
+ success: "success";
77
+ error: "error";
78
+ }>;
79
+ data: z.ZodOptional<z.ZodUnknown>;
80
+ error: z.ZodOptional<z.ZodString>;
81
+ }, z.core.$strip>>>;
82
+ }, z.core.$loose>>;
83
+ }, z.core.$strip>;
84
+ /**
85
+ * Zod schema for event lifecycle stages.
86
+ */
87
+ declare const EventStageSchema: z.ZodEnum<{
88
+ start: "start";
89
+ delta: "delta";
90
+ stop: "stop";
91
+ }>;
92
+ /**
93
+ * Zod schema for protocol error codes.
94
+ */
95
+ declare const ErrorCodeSchema: z.ZodEnum<{
96
+ auth_failed: "auth_failed";
97
+ thread_not_found: "thread_not_found";
98
+ thread_access_denied: "thread_access_denied";
99
+ invalid_message_format: "invalid_message_format";
100
+ message_too_large: "message_too_large";
101
+ rate_limit_exceeded: "rate_limit_exceeded";
102
+ stream_timeout: "stream_timeout";
103
+ agent_error: "agent_error";
104
+ tool_error: "tool_error";
105
+ internal_error: "internal_error";
106
+ invalid_action_id: "invalid_action_id";
107
+ }>;
108
+ /**
109
+ * Zod schema for stream finish reasons.
110
+ */
111
+ declare const FinishReasonSchema: z.ZodEnum<{
112
+ error: "error";
113
+ stop: "stop";
114
+ length: "length";
115
+ action_required: "action_required";
116
+ }>;
117
+ /**
118
+ * Zod schema for metadata events.
119
+ * First event in every stream, provides identifiers.
120
+ */
121
+ declare const MetadataEventSchema: z.ZodObject<{
122
+ event: z.ZodLiteral<"metadata">;
123
+ requestId: z.ZodString;
124
+ threadId: z.ZodString;
125
+ agentId: z.ZodString;
126
+ timestamp: z.ZodString;
127
+ }, z.core.$strip>;
128
+ /**
129
+ * Zod schema for text streaming events.
130
+ * Validates the stage lifecycle with appropriate optional fields per stage.
131
+ */
132
+ declare const TextEventSchema: z.ZodObject<{
133
+ event: z.ZodLiteral<"text">;
134
+ requestId: z.ZodString;
135
+ messageId: z.ZodString;
136
+ blockId: z.ZodString;
137
+ blockIndex: z.ZodOptional<z.ZodNumber>;
138
+ stage: z.ZodEnum<{
139
+ start: "start";
140
+ delta: "delta";
141
+ stop: "stop";
142
+ }>;
143
+ delta: z.ZodOptional<z.ZodString>;
144
+ deltaIndex: z.ZodOptional<z.ZodNumber>;
145
+ timestamp: z.ZodString;
146
+ }, z.core.$strip>;
147
+ /**
148
+ * Zod schema for thinking/reasoning events.
149
+ * Structure mirrors TextEventSchema.
150
+ */
151
+ declare const ThinkingEventSchema: z.ZodObject<{
152
+ event: z.ZodLiteral<"thinking">;
153
+ requestId: z.ZodString;
154
+ messageId: z.ZodString;
155
+ blockId: z.ZodString;
156
+ blockIndex: z.ZodOptional<z.ZodNumber>;
157
+ stage: z.ZodEnum<{
158
+ start: "start";
159
+ delta: "delta";
160
+ stop: "stop";
161
+ }>;
162
+ delta: z.ZodOptional<z.ZodString>;
163
+ deltaIndex: z.ZodOptional<z.ZodNumber>;
164
+ timestamp: z.ZodString;
165
+ }, z.core.$strip>;
166
+ /**
167
+ * Zod schema for tool call events.
168
+ * Args are optional (only present on stop stage).
169
+ */
170
+ declare const ToolCallEventSchema: z.ZodObject<{
171
+ event: z.ZodLiteral<"tool_call">;
172
+ requestId: z.ZodString;
173
+ messageId: z.ZodString;
174
+ blockId: z.ZodString;
175
+ blockIndex: z.ZodOptional<z.ZodNumber>;
176
+ stage: z.ZodEnum<{
177
+ start: "start";
178
+ delta: "delta";
179
+ stop: "stop";
180
+ }>;
181
+ toolCallId: z.ZodOptional<z.ZodString>;
182
+ tool: z.ZodOptional<z.ZodString>;
183
+ delta: z.ZodOptional<z.ZodString>;
184
+ deltaIndex: z.ZodOptional<z.ZodNumber>;
185
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
186
+ timestamp: z.ZodString;
187
+ }, z.core.$strip>;
188
+ /**
189
+ * Zod schema for tool result events.
190
+ * Status and summary only present on stop stage.
191
+ */
192
+ declare const ToolResultEventSchema: z.ZodObject<{
193
+ event: z.ZodLiteral<"tool_result">;
194
+ requestId: z.ZodString;
195
+ messageId: z.ZodString;
196
+ blockId: z.ZodString;
197
+ blockIndex: z.ZodOptional<z.ZodNumber>;
198
+ stage: z.ZodEnum<{
199
+ start: "start";
200
+ delta: "delta";
201
+ stop: "stop";
202
+ }>;
203
+ toolCallId: z.ZodOptional<z.ZodString>;
204
+ tool: z.ZodOptional<z.ZodString>;
205
+ status: z.ZodOptional<z.ZodEnum<{
206
+ success: "success";
207
+ error: "error";
208
+ }>>;
209
+ summary: z.ZodOptional<z.ZodString>;
210
+ timestamp: z.ZodString;
211
+ }, z.core.$strip>;
212
+ /**
213
+ * Zod schema for done events.
214
+ * Terminal event with complete content array.
215
+ */
216
+ declare const DoneEventSchema: z.ZodObject<{
217
+ event: z.ZodLiteral<"done">;
218
+ requestId: z.ZodString;
219
+ messageId: z.ZodString;
220
+ threadId: z.ZodString;
221
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
222
+ type: z.ZodLiteral<"text">;
223
+ text: z.ZodString;
224
+ }, z.core.$strip>, z.ZodObject<{
225
+ type: z.ZodLiteral<"thinking">;
226
+ text: z.ZodString;
227
+ }, z.core.$strip>, z.ZodObject<{
228
+ type: z.ZodLiteral<"tool_use">;
229
+ toolCallId: z.ZodString;
230
+ tool: z.ZodString;
231
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
232
+ }, z.core.$strip>, z.ZodObject<{
233
+ type: z.ZodLiteral<"tool_result">;
234
+ toolCallId: z.ZodString;
235
+ tool: z.ZodString;
236
+ status: z.ZodEnum<{
237
+ success: "success";
238
+ error: "error";
239
+ }>;
240
+ summary: z.ZodOptional<z.ZodString>;
241
+ }, z.core.$strip>], "type">>;
242
+ usage: z.ZodOptional<z.ZodObject<{
243
+ promptTokens: z.ZodNumber;
244
+ completionTokens: z.ZodNumber;
245
+ }, z.core.$strip>>;
246
+ finishReason: z.ZodEnum<{
247
+ error: "error";
248
+ stop: "stop";
249
+ length: "length";
250
+ action_required: "action_required";
251
+ }>;
252
+ traceId: z.ZodOptional<z.ZodString>;
253
+ timestamp: z.ZodString;
254
+ }, z.core.$strip>;
255
+ /**
256
+ * Zod schema for error events.
257
+ * Terminal event with error details and retry guidance.
258
+ */
259
+ declare const ErrorEventSchema: z.ZodObject<{
260
+ event: z.ZodLiteral<"error">;
261
+ requestId: z.ZodString;
262
+ message: z.ZodString;
263
+ code: z.ZodOptional<z.ZodEnum<{
264
+ auth_failed: "auth_failed";
265
+ thread_not_found: "thread_not_found";
266
+ thread_access_denied: "thread_access_denied";
267
+ invalid_message_format: "invalid_message_format";
268
+ message_too_large: "message_too_large";
269
+ rate_limit_exceeded: "rate_limit_exceeded";
270
+ stream_timeout: "stream_timeout";
271
+ agent_error: "agent_error";
272
+ tool_error: "tool_error";
273
+ internal_error: "internal_error";
274
+ invalid_action_id: "invalid_action_id";
275
+ }>>;
276
+ retryable: z.ZodOptional<z.ZodBoolean>;
277
+ timestamp: z.ZodString;
278
+ }, z.core.$strip>;
279
+ /**
280
+ * Zod schema for aborted events.
281
+ * Terminal event acknowledging client cancellation.
282
+ */
283
+ declare const AbortedEventSchema: z.ZodObject<{
284
+ event: z.ZodLiteral<"aborted">;
285
+ requestId: z.ZodString;
286
+ messageId: z.ZodOptional<z.ZodString>;
287
+ timestamp: z.ZodString;
288
+ }, z.core.$strip>;
289
+ /**
290
+ * Zod schema for continuation events.
291
+ * Signals client action required before stream can continue.
292
+ */
293
+ declare const ContinuationEventSchema: z.ZodObject<{
294
+ event: z.ZodLiteral<"continuation">;
295
+ requestId: z.ZodString;
296
+ actionId: z.ZodString;
297
+ kind: z.ZodString;
298
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
299
+ timestamp: z.ZodString;
300
+ }, z.core.$strip>;
301
+ /**
302
+ * Zod schema for all protocol events.
303
+ * Discriminated union on the `event` field for efficient parsing.
304
+ */
305
+ declare const AgentEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
306
+ event: z.ZodLiteral<"metadata">;
307
+ requestId: z.ZodString;
308
+ threadId: z.ZodString;
309
+ agentId: z.ZodString;
310
+ timestamp: z.ZodString;
311
+ }, z.core.$strip>, z.ZodObject<{
312
+ event: z.ZodLiteral<"text">;
313
+ requestId: z.ZodString;
314
+ messageId: z.ZodString;
315
+ blockId: z.ZodString;
316
+ blockIndex: z.ZodOptional<z.ZodNumber>;
317
+ stage: z.ZodEnum<{
318
+ start: "start";
319
+ delta: "delta";
320
+ stop: "stop";
321
+ }>;
322
+ delta: z.ZodOptional<z.ZodString>;
323
+ deltaIndex: z.ZodOptional<z.ZodNumber>;
324
+ timestamp: z.ZodString;
325
+ }, z.core.$strip>, z.ZodObject<{
326
+ event: z.ZodLiteral<"thinking">;
327
+ requestId: z.ZodString;
328
+ messageId: z.ZodString;
329
+ blockId: z.ZodString;
330
+ blockIndex: z.ZodOptional<z.ZodNumber>;
331
+ stage: z.ZodEnum<{
332
+ start: "start";
333
+ delta: "delta";
334
+ stop: "stop";
335
+ }>;
336
+ delta: z.ZodOptional<z.ZodString>;
337
+ deltaIndex: z.ZodOptional<z.ZodNumber>;
338
+ timestamp: z.ZodString;
339
+ }, z.core.$strip>, z.ZodObject<{
340
+ event: z.ZodLiteral<"tool_call">;
341
+ requestId: z.ZodString;
342
+ messageId: z.ZodString;
343
+ blockId: z.ZodString;
344
+ blockIndex: z.ZodOptional<z.ZodNumber>;
345
+ stage: z.ZodEnum<{
346
+ start: "start";
347
+ delta: "delta";
348
+ stop: "stop";
349
+ }>;
350
+ toolCallId: z.ZodOptional<z.ZodString>;
351
+ tool: z.ZodOptional<z.ZodString>;
352
+ delta: z.ZodOptional<z.ZodString>;
353
+ deltaIndex: z.ZodOptional<z.ZodNumber>;
354
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
355
+ timestamp: z.ZodString;
356
+ }, z.core.$strip>, z.ZodObject<{
357
+ event: z.ZodLiteral<"tool_result">;
358
+ requestId: z.ZodString;
359
+ messageId: z.ZodString;
360
+ blockId: z.ZodString;
361
+ blockIndex: z.ZodOptional<z.ZodNumber>;
362
+ stage: z.ZodEnum<{
363
+ start: "start";
364
+ delta: "delta";
365
+ stop: "stop";
366
+ }>;
367
+ toolCallId: z.ZodOptional<z.ZodString>;
368
+ tool: z.ZodOptional<z.ZodString>;
369
+ status: z.ZodOptional<z.ZodEnum<{
370
+ success: "success";
371
+ error: "error";
372
+ }>>;
373
+ summary: z.ZodOptional<z.ZodString>;
374
+ timestamp: z.ZodString;
375
+ }, z.core.$strip>, z.ZodObject<{
376
+ event: z.ZodLiteral<"done">;
377
+ requestId: z.ZodString;
378
+ messageId: z.ZodString;
379
+ threadId: z.ZodString;
380
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
381
+ type: z.ZodLiteral<"text">;
382
+ text: z.ZodString;
383
+ }, z.core.$strip>, z.ZodObject<{
384
+ type: z.ZodLiteral<"thinking">;
385
+ text: z.ZodString;
386
+ }, z.core.$strip>, z.ZodObject<{
387
+ type: z.ZodLiteral<"tool_use">;
388
+ toolCallId: z.ZodString;
389
+ tool: z.ZodString;
390
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
391
+ }, z.core.$strip>, z.ZodObject<{
392
+ type: z.ZodLiteral<"tool_result">;
393
+ toolCallId: z.ZodString;
394
+ tool: z.ZodString;
395
+ status: z.ZodEnum<{
396
+ success: "success";
397
+ error: "error";
398
+ }>;
399
+ summary: z.ZodOptional<z.ZodString>;
400
+ }, z.core.$strip>], "type">>;
401
+ usage: z.ZodOptional<z.ZodObject<{
402
+ promptTokens: z.ZodNumber;
403
+ completionTokens: z.ZodNumber;
404
+ }, z.core.$strip>>;
405
+ finishReason: z.ZodEnum<{
406
+ error: "error";
407
+ stop: "stop";
408
+ length: "length";
409
+ action_required: "action_required";
410
+ }>;
411
+ traceId: z.ZodOptional<z.ZodString>;
412
+ timestamp: z.ZodString;
413
+ }, z.core.$strip>, z.ZodObject<{
414
+ event: z.ZodLiteral<"error">;
415
+ requestId: z.ZodString;
416
+ message: z.ZodString;
417
+ code: z.ZodOptional<z.ZodEnum<{
418
+ auth_failed: "auth_failed";
419
+ thread_not_found: "thread_not_found";
420
+ thread_access_denied: "thread_access_denied";
421
+ invalid_message_format: "invalid_message_format";
422
+ message_too_large: "message_too_large";
423
+ rate_limit_exceeded: "rate_limit_exceeded";
424
+ stream_timeout: "stream_timeout";
425
+ agent_error: "agent_error";
426
+ tool_error: "tool_error";
427
+ internal_error: "internal_error";
428
+ invalid_action_id: "invalid_action_id";
429
+ }>>;
430
+ retryable: z.ZodOptional<z.ZodBoolean>;
431
+ timestamp: z.ZodString;
432
+ }, z.core.$strip>, z.ZodObject<{
433
+ event: z.ZodLiteral<"aborted">;
434
+ requestId: z.ZodString;
435
+ messageId: z.ZodOptional<z.ZodString>;
436
+ timestamp: z.ZodString;
437
+ }, z.core.$strip>, z.ZodObject<{
438
+ event: z.ZodLiteral<"continuation">;
439
+ requestId: z.ZodString;
440
+ actionId: z.ZodString;
441
+ kind: z.ZodString;
442
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
443
+ timestamp: z.ZodString;
444
+ }, z.core.$strip>], "event">;
445
+
446
+ /**
447
+ * Current protocol version.
448
+ * Additive changes (new events, optional fields) don't require version bump.
449
+ * Breaking changes require new endpoint version (v2, v3, etc).
450
+ */
451
+ declare const PROTOCOL_VERSION = "1.0.0";
452
+ /**
453
+ * All valid event type identifiers in the protocol.
454
+ * Used for discriminated union parsing and validation.
455
+ */
456
+ declare const EVENT_TYPES: readonly ["metadata", "text", "thinking", "tool_call", "tool_result", "done", "error", "aborted", "continuation"];
457
+ /**
458
+ * Event type identifier.
459
+ * Union of all valid event type strings.
460
+ */
461
+ type EventType = (typeof EVENT_TYPES)[number];
462
+
463
+ export { AbortedEventSchema, ActionResultSchema, AgentEventSchema, AgentRequestSchema, AssistantContentBlockSchema, ContinuationEventSchema, DoneEventSchema, EVENT_TYPES, ErrorCodeSchema, ErrorEventSchema, EventStageSchema, type EventType, FinishReasonSchema, InputMessageSchema, MetadataEventSchema, PROTOCOL_VERSION, TextEventSchema, ThinkingEventSchema, ToolCallEventSchema, ToolResultEventSchema, UserContentBlockSchema };
package/dist/core.js ADDED
@@ -0,0 +1,47 @@
1
+ import {
2
+ EVENT_TYPES,
3
+ PROTOCOL_VERSION
4
+ } from "./chunk-ZINGYSGU.js";
5
+ import {
6
+ AbortedEventSchema,
7
+ ActionResultSchema,
8
+ AgentEventSchema,
9
+ AgentRequestSchema,
10
+ AssistantContentBlockSchema,
11
+ ContinuationEventSchema,
12
+ DoneEventSchema,
13
+ ErrorCodeSchema,
14
+ ErrorEventSchema,
15
+ EventStageSchema,
16
+ FinishReasonSchema,
17
+ InputMessageSchema,
18
+ MetadataEventSchema,
19
+ TextEventSchema,
20
+ ThinkingEventSchema,
21
+ ToolCallEventSchema,
22
+ ToolResultEventSchema,
23
+ UserContentBlockSchema
24
+ } from "./chunk-WZD2VBMM.js";
25
+ export {
26
+ AbortedEventSchema,
27
+ ActionResultSchema,
28
+ AgentEventSchema,
29
+ AgentRequestSchema,
30
+ AssistantContentBlockSchema,
31
+ ContinuationEventSchema,
32
+ DoneEventSchema,
33
+ EVENT_TYPES,
34
+ ErrorCodeSchema,
35
+ ErrorEventSchema,
36
+ EventStageSchema,
37
+ FinishReasonSchema,
38
+ InputMessageSchema,
39
+ MetadataEventSchema,
40
+ PROTOCOL_VERSION,
41
+ TextEventSchema,
42
+ ThinkingEventSchema,
43
+ ToolCallEventSchema,
44
+ ToolResultEventSchema,
45
+ UserContentBlockSchema
46
+ };
47
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}