@agen-ai/agent-protocol 0.1.0 → 0.2.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.
@@ -1,12 +1,39 @@
1
1
  import { z } from 'zod/v4';
2
2
  import type { AgentEvent } from '../events/types.js';
3
+ import { type AgentContextUsage } from '../turns/types.js';
4
+ export declare const AgentContextUsagePortableSchema: z.ZodReadonly<z.ZodObject<{
5
+ measurementScope: z.ZodEnum<{
6
+ session: "session";
7
+ materialization: "materialization";
8
+ }>;
9
+ usedTokens: z.ZodNumber;
10
+ maxTokens: z.ZodNumber;
11
+ cumulative: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
12
+ inputTokens: z.ZodOptional<z.ZodNumber>;
13
+ outputTokens: z.ZodOptional<z.ZodNumber>;
14
+ cachedReadTokens: z.ZodOptional<z.ZodNumber>;
15
+ cacheCreationTokens: z.ZodOptional<z.ZodNumber>;
16
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
17
+ modelCalls: z.ZodOptional<z.ZodNumber>;
18
+ turns: z.ZodOptional<z.ZodNumber>;
19
+ }, z.core.$strict>>>;
20
+ compaction: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
21
+ state: z.ZodEnum<{
22
+ in_progress: "in_progress";
23
+ idle: "idle";
24
+ approaching: "approaching";
25
+ }>;
26
+ thresholdTokens: z.ZodOptional<z.ZodNumber>;
27
+ }, z.core.$strict>>>;
28
+ }, z.core.$strict>>;
29
+ export declare const AgentContextUsageSchema: z.ZodType<AgentContextUsage>;
3
30
  export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
4
31
  type: z.ZodLiteral<"turn.started">;
5
32
  turnId: z.ZodType<import("../index.js").AgentTurnId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentTurnId, unknown>>;
6
33
  payload: z.ZodReadonly<z.ZodObject<{
7
34
  message: z.ZodOptional<z.ZodString>;
8
35
  }, z.core.$strict>>;
9
- protocolVersion: z.ZodLiteral<6>;
36
+ protocolVersion: z.ZodLiteral<7>;
10
37
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
11
38
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
12
39
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -27,7 +54,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
27
54
  requestId: z.ZodOptional<z.ZodType<import("../index.js").AgentRequestId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentRequestId, unknown>>>;
28
55
  message: z.ZodOptional<z.ZodString>;
29
56
  }, z.core.$strict>>;
30
- protocolVersion: z.ZodLiteral<6>;
57
+ protocolVersion: z.ZodLiteral<7>;
31
58
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
32
59
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
33
60
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -50,7 +77,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
50
77
  reason: z.ZodOptional<z.ZodString>;
51
78
  error: z.ZodOptional<z.ZodType<import("../index.js").AgentError, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentError, unknown>>>;
52
79
  }, z.core.$strict>>;
53
- protocolVersion: z.ZodLiteral<6>;
80
+ protocolVersion: z.ZodLiteral<7>;
54
81
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
55
82
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
56
83
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -64,7 +91,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
64
91
  type: z.ZodLiteral<"item.started">;
65
92
  turnId: z.ZodType<import("../index.js").AgentTurnId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentTurnId, unknown>>;
66
93
  payload: z.ZodType<import("../index.js").AgentItemSnapshot, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentItemSnapshot, unknown>>;
67
- protocolVersion: z.ZodLiteral<6>;
94
+ protocolVersion: z.ZodLiteral<7>;
68
95
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
69
96
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
70
97
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -78,7 +105,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
78
105
  type: z.ZodLiteral<"item.updated">;
79
106
  turnId: z.ZodType<import("../index.js").AgentTurnId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentTurnId, unknown>>;
80
107
  payload: z.ZodType<import("../index.js").AgentItemSnapshot, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentItemSnapshot, unknown>>;
81
- protocolVersion: z.ZodLiteral<6>;
108
+ protocolVersion: z.ZodLiteral<7>;
82
109
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
83
110
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
84
111
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -92,7 +119,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
92
119
  type: z.ZodLiteral<"item.completed">;
93
120
  turnId: z.ZodType<import("../index.js").AgentTurnId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentTurnId, unknown>>;
94
121
  payload: z.ZodType<import("../index.js").AgentItemSnapshot, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentItemSnapshot, unknown>>;
95
- protocolVersion: z.ZodLiteral<6>;
122
+ protocolVersion: z.ZodLiteral<7>;
96
123
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
97
124
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
98
125
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -118,7 +145,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
118
145
  }>;
119
146
  delta: z.ZodString;
120
147
  }, z.core.$strict>>;
121
- protocolVersion: z.ZodLiteral<6>;
148
+ protocolVersion: z.ZodLiteral<7>;
122
149
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
123
150
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
124
151
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -135,7 +162,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
135
162
  explanation: z.ZodOptional<z.ZodString>;
136
163
  steps: z.ZodReadonly<z.ZodArray<z.ZodType<import("../index.js").AgentPlanStep, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentPlanStep, unknown>>>>;
137
164
  }, z.core.$strict>>;
138
- protocolVersion: z.ZodLiteral<6>;
165
+ protocolVersion: z.ZodLiteral<7>;
139
166
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
140
167
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
141
168
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -152,7 +179,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
152
179
  artifactId: z.ZodType<import("../index.js").AgentArtifactId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentArtifactId, unknown>>;
153
180
  requestId: z.ZodType<import("../index.js").AgentRequestId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentRequestId, unknown>>;
154
181
  }, z.core.$strict>>;
155
- protocolVersion: z.ZodLiteral<6>;
182
+ protocolVersion: z.ZodLiteral<7>;
156
183
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
157
184
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
158
185
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -166,7 +193,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
166
193
  type: z.ZodLiteral<"turn.diff.updated">;
167
194
  turnId: z.ZodType<import("../index.js").AgentTurnId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentTurnId, unknown>>;
168
195
  payload: z.ZodType<import("../index.js").AgentDiffSummary, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentDiffSummary, unknown>>;
169
- protocolVersion: z.ZodLiteral<6>;
196
+ protocolVersion: z.ZodLiteral<7>;
170
197
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
171
198
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
172
199
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -193,12 +220,37 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
193
220
  kind: z.ZodEnum<{
194
221
  other: "other";
195
222
  file_change: "file_change";
196
- command: "command";
197
223
  tool: "tool";
224
+ command: "command";
198
225
  }>;
199
226
  title: z.ZodString;
200
227
  description: z.ZodOptional<z.ZodString>;
228
+ itemId: z.ZodType<import("../index.js").AgentItemId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentItemId, unknown>>;
201
229
  }, z.core.$strict>>], "kind">;
230
+ options: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
231
+ optionId: z.ZodType<import("../index.js").AgentApprovalOptionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentApprovalOptionId, unknown>>;
232
+ label: z.ZodString;
233
+ description: z.ZodOptional<z.ZodString>;
234
+ decision: z.ZodEnum<{
235
+ approved: "approved";
236
+ denied: "denied";
237
+ }>;
238
+ persistence: z.ZodEnum<{
239
+ session: "session";
240
+ once: "once";
241
+ workspace: "workspace";
242
+ }>;
243
+ scope: z.ZodReadonly<z.ZodObject<{
244
+ kind: z.ZodEnum<{
245
+ exact_action: "exact_action";
246
+ command_pattern: "command_pattern";
247
+ domain: "domain";
248
+ tool: "tool";
249
+ server: "server";
250
+ all_edits: "all_edits";
251
+ }>;
252
+ }, z.core.$strict>>;
253
+ }, z.core.$strict>>>>;
202
254
  expiresAt: z.ZodOptional<z.ZodType<import("../index.js").AgentIsoDateTime, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentIsoDateTime, unknown>>>;
203
255
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
204
256
  requestKind: z.ZodLiteral<"elicitation">;
@@ -234,7 +286,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
234
286
  expiresAt: z.ZodOptional<z.ZodType<import("../index.js").AgentIsoDateTime, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentIsoDateTime, unknown>>>;
235
287
  }, z.core.$strict>>], "requestKind">;
236
288
  }, z.core.$strict>>;
237
- protocolVersion: z.ZodLiteral<6>;
289
+ protocolVersion: z.ZodLiteral<7>;
238
290
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
239
291
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
240
292
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -265,7 +317,45 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
265
317
  current: z.ZodOptional<z.ZodNumber>;
266
318
  total: z.ZodOptional<z.ZodNumber>;
267
319
  }, z.core.$strict>>;
268
- protocolVersion: z.ZodLiteral<6>;
320
+ protocolVersion: z.ZodLiteral<7>;
321
+ sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
322
+ providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
323
+ conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
324
+ historyAnchor: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderHistoryAnchor, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderHistoryAnchor, unknown>>>;
325
+ turnId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderTurnRef, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderTurnRef, unknown>>>;
326
+ itemId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderItemRef, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderItemRef, unknown>>>;
327
+ requestId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderRequestRef, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderRequestRef, unknown>>>;
328
+ }, z.core.$strict>>>;
329
+ occurredAt: z.ZodType<import("../index.js").AgentIsoDateTime, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentIsoDateTime, unknown>>;
330
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
331
+ type: z.ZodLiteral<"context.usage.updated">;
332
+ turnId: z.ZodType<import("../index.js").AgentTurnId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentTurnId, unknown>>;
333
+ payload: z.ZodReadonly<z.ZodObject<{
334
+ measurementScope: z.ZodEnum<{
335
+ session: "session";
336
+ materialization: "materialization";
337
+ }>;
338
+ usedTokens: z.ZodNumber;
339
+ maxTokens: z.ZodNumber;
340
+ cumulative: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
341
+ inputTokens: z.ZodOptional<z.ZodNumber>;
342
+ outputTokens: z.ZodOptional<z.ZodNumber>;
343
+ cachedReadTokens: z.ZodOptional<z.ZodNumber>;
344
+ cacheCreationTokens: z.ZodOptional<z.ZodNumber>;
345
+ reasoningTokens: z.ZodOptional<z.ZodNumber>;
346
+ modelCalls: z.ZodOptional<z.ZodNumber>;
347
+ turns: z.ZodOptional<z.ZodNumber>;
348
+ }, z.core.$strict>>>;
349
+ compaction: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
350
+ state: z.ZodEnum<{
351
+ in_progress: "in_progress";
352
+ idle: "idle";
353
+ approaching: "approaching";
354
+ }>;
355
+ thresholdTokens: z.ZodOptional<z.ZodNumber>;
356
+ }, z.core.$strict>>>;
357
+ }, z.core.$strict>>;
358
+ protocolVersion: z.ZodLiteral<7>;
269
359
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
270
360
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
271
361
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -281,7 +371,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
281
371
  payload: z.ZodReadonly<z.ZodObject<{
282
372
  artifact: z.ZodType<import("../index.js").AgentArtifactDescriptor, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentArtifactDescriptor, unknown>>;
283
373
  }, z.core.$strict>>;
284
- protocolVersion: z.ZodLiteral<6>;
374
+ protocolVersion: z.ZodLiteral<7>;
285
375
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
286
376
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
287
377
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -304,7 +394,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
304
394
  status: z.ZodOptional<z.ZodString>;
305
395
  }, z.core.$strict>>>;
306
396
  }, z.core.$strict>>;
307
- protocolVersion: z.ZodLiteral<6>;
397
+ protocolVersion: z.ZodLiteral<7>;
308
398
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
309
399
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
310
400
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -320,7 +410,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
320
410
  payload: z.ZodReadonly<z.ZodObject<{
321
411
  error: z.ZodType<import("../index.js").AgentError, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentError, unknown>>;
322
412
  }, z.core.$strict>>;
323
- protocolVersion: z.ZodLiteral<6>;
413
+ protocolVersion: z.ZodLiteral<7>;
324
414
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
325
415
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
326
416
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -342,7 +432,7 @@ export declare const AgentEventPortableSchema: z.ZodDiscriminatedUnion<[z.ZodRea
342
432
  status: z.ZodOptional<z.ZodString>;
343
433
  }, z.core.$strict>>>;
344
434
  }, z.core.$strict>>;
345
- protocolVersion: z.ZodLiteral<6>;
435
+ protocolVersion: z.ZodLiteral<7>;
346
436
  sessionId: z.ZodType<import("../index.js").AgentSessionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentSessionId, unknown>>;
347
437
  providerRefs: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
348
438
  conversationId: z.ZodOptional<z.ZodType<import("../index.js").AgentProviderConversationId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentProviderConversationId, unknown>>>;
@@ -9,6 +9,10 @@ import {
9
9
  agentProtocolSerializedJsonBytes
10
10
  } from "../foundation/types.js";
11
11
  import { AgentRequestPortableSchema, AgentRequestSchema } from "./requests.js";
12
+ import {
13
+ AGENT_CONTEXT_COMPACTION_STATES,
14
+ AGENT_CONTEXT_MEASUREMENT_SCOPES
15
+ } from "../turns/types.js";
12
16
  import {
13
17
  AgentContentStreamKindSchema,
14
18
  AgentDiffSummarySchema,
@@ -68,6 +72,45 @@ const ProgressUpdatedPayloadSchema = z.object({
68
72
  current: z.number().int().min(0).optional(),
69
73
  total: z.number().int().min(0).optional()
70
74
  }).strict().readonly();
75
+ const NonNegativeSafeIntegerSchema = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
76
+ const PositiveSafeIntegerSchema = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
77
+ const AgentContextCumulativeUsageSchema = z.object({
78
+ inputTokens: NonNegativeSafeIntegerSchema.optional(),
79
+ outputTokens: NonNegativeSafeIntegerSchema.optional(),
80
+ cachedReadTokens: NonNegativeSafeIntegerSchema.optional(),
81
+ cacheCreationTokens: NonNegativeSafeIntegerSchema.optional(),
82
+ reasoningTokens: NonNegativeSafeIntegerSchema.optional(),
83
+ modelCalls: NonNegativeSafeIntegerSchema.optional(),
84
+ turns: NonNegativeSafeIntegerSchema.optional()
85
+ }).strict().refine((usage) => Object.keys(usage).length > 0, {
86
+ message: "Cumulative context usage must contain at least one counter."
87
+ }).readonly();
88
+ const AgentContextUsagePortableSchema = z.object({
89
+ measurementScope: z.enum(AGENT_CONTEXT_MEASUREMENT_SCOPES),
90
+ usedTokens: NonNegativeSafeIntegerSchema,
91
+ maxTokens: PositiveSafeIntegerSchema,
92
+ cumulative: AgentContextCumulativeUsageSchema.optional(),
93
+ compaction: z.object({
94
+ state: z.enum(AGENT_CONTEXT_COMPACTION_STATES),
95
+ thresholdTokens: PositiveSafeIntegerSchema.optional()
96
+ }).strict().readonly().optional()
97
+ }).strict().readonly();
98
+ const AgentContextUsageSchema = AgentContextUsagePortableSchema.superRefine((usage, context) => {
99
+ if (usage.usedTokens > usage.maxTokens) {
100
+ context.addIssue({
101
+ code: "custom",
102
+ path: ["usedTokens"],
103
+ message: "Used context tokens cannot exceed the context maximum."
104
+ });
105
+ }
106
+ if (usage.compaction?.thresholdTokens !== void 0 && usage.compaction.thresholdTokens > usage.maxTokens) {
107
+ context.addIssue({
108
+ code: "custom",
109
+ path: ["compaction", "thresholdTokens"],
110
+ message: "Compaction threshold cannot exceed the context maximum."
111
+ });
112
+ }
113
+ });
71
114
  const AgentEventPortableSchema = z.discriminatedUnion("type", [
72
115
  turnEvent(
73
116
  "turn.started",
@@ -106,6 +149,7 @@ const AgentEventPortableSchema = z.discriminatedUnion("type", [
106
149
  z.object({ request: AgentRequestPortableSchema }).strict().readonly()
107
150
  ),
108
151
  turnEvent("progress.updated", ProgressUpdatedPayloadSchema),
152
+ turnEvent("context.usage.updated", AgentContextUsagePortableSchema),
109
153
  optionallyTurnScopedEvent(
110
154
  "artifact.referenced",
111
155
  z.object({ artifact: AgentArtifactDescriptorSchema }).strict().readonly()
@@ -177,6 +221,17 @@ const AgentEventSchema = AgentEventPortableSchema.superRefine((event, context) =
177
221
  message: "Progress current cannot exceed total."
178
222
  });
179
223
  }
224
+ if (event.type === "context.usage.updated") {
225
+ const usage = AgentContextUsageSchema.safeParse(event.payload);
226
+ if (!usage.success) {
227
+ for (const issue of usage.error.issues) {
228
+ context.addIssue({
229
+ ...issue,
230
+ path: ["payload", ...issue.path]
231
+ });
232
+ }
233
+ }
234
+ }
180
235
  if (agentProtocolSerializedJsonBytes(event) > AGENT_PROTOCOL_EVENT_BYTES_LIMIT) {
181
236
  context.addIssue({
182
237
  code: "custom",
@@ -185,6 +240,8 @@ const AgentEventSchema = AgentEventPortableSchema.superRefine((event, context) =
185
240
  }
186
241
  });
187
242
  export {
243
+ AgentContextUsagePortableSchema,
244
+ AgentContextUsageSchema,
188
245
  AgentEventPortableSchema,
189
246
  AgentEventSchema
190
247
  };
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
- import { type AgentArtifactId, type AgentConfigurationRevisionId, type AgentError, type AgentInstanceId, type AgentIsoDateTime, type AgentItemId, type AgentJsonValue, type AgentProviderConversationId, type AgentProviderHistoryAnchor, type AgentProviderItemRef, type AgentProviderKey, type AgentProviderRefs, type AgentProviderRequestRef, type AgentProviderTurnRef, type AgentRequestFieldId, type AgentRequestId, type AgentSessionId, type AgentTurnId } from '../foundation/types.js';
2
+ import { type AgentArtifactId, type AgentApprovalOptionId, type AgentConfigurationRevisionId, type AgentError, type AgentInstanceId, type AgentIsoDateTime, type AgentItemId, type AgentJsonValue, type AgentProviderConversationId, type AgentProviderHistoryAnchor, type AgentProviderItemRef, type AgentProviderKey, type AgentProviderRefs, type AgentProviderRequestRef, type AgentProviderTurnRef, type AgentRequestFieldId, type AgentRequestId, type AgentSessionId, type AgentTurnId } from '../foundation/types.js';
3
3
  export declare const AgentCanonicalIdValueSchema: z.ZodString;
4
4
  export declare function createAgentCanonicalNonBlankStringSchema(maxLength: number): z.ZodString;
5
5
  export declare const AgentCanonicalNonBlankTextSchema: z.ZodString;
@@ -9,6 +9,7 @@ export declare const AgentSessionIdSchema: z.ZodType<AgentSessionId, unknown, z.
9
9
  export declare const AgentTurnIdSchema: z.ZodType<AgentTurnId, unknown, z.core.$ZodTypeInternals<AgentTurnId, unknown>>;
10
10
  export declare const AgentItemIdSchema: z.ZodType<AgentItemId, unknown, z.core.$ZodTypeInternals<AgentItemId, unknown>>;
11
11
  export declare const AgentRequestIdSchema: z.ZodType<AgentRequestId, unknown, z.core.$ZodTypeInternals<AgentRequestId, unknown>>;
12
+ export declare const AgentApprovalOptionIdSchema: z.ZodType<AgentApprovalOptionId, unknown, z.core.$ZodTypeInternals<AgentApprovalOptionId, unknown>>;
12
13
  export declare const AgentRequestFieldIdSchema: z.ZodType<AgentRequestFieldId, unknown, z.core.$ZodTypeInternals<AgentRequestFieldId, unknown>>;
13
14
  export declare const AgentArtifactIdSchema: z.ZodType<AgentArtifactId, unknown, z.core.$ZodTypeInternals<AgentArtifactId, unknown>>;
14
15
  export declare const AgentConfigurationRevisionIdSchema: z.ZodType<AgentConfigurationRevisionId, unknown, z.core.$ZodTypeInternals<AgentConfigurationRevisionId, unknown>>;
@@ -40,6 +40,7 @@ const AgentSessionIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
40
40
  const AgentTurnIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
41
41
  const AgentItemIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
42
42
  const AgentRequestIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
43
+ const AgentApprovalOptionIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
43
44
  const AgentRequestFieldIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
44
45
  const AgentArtifactIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
45
46
  const AgentConfigurationRevisionIdSchema = opaqueStringSchema(AgentCanonicalIdValueSchema);
@@ -175,6 +176,7 @@ const AgentErrorSchema = z.object({
175
176
  context: AgentErrorContextSchema.optional()
176
177
  }).strict().readonly();
177
178
  export {
179
+ AgentApprovalOptionIdSchema,
178
180
  AgentArtifactIdSchema,
179
181
  AgentCanonicalCodeSchema,
180
182
  AgentCanonicalIdValueSchema,
@@ -1,9 +1,9 @@
1
- export { AgentArtifactIdSchema, AgentConfigurationRevisionIdSchema, AgentErrorContextSchema, AgentErrorSchema, AgentInstanceIdSchema, AgentIsoDateTimeSchema, AgentItemIdSchema, AgentJsonValueSchema, AgentProviderConversationIdSchema, AgentProviderHistoryAnchorSchema, AgentProviderItemRefSchema, AgentProviderKeySchema, AgentProviderRefsSchema, AgentProviderRequestRefSchema, AgentProviderTurnRefSchema, AgentRequestFieldIdSchema, AgentRequestIdSchema, AgentSessionIdSchema, AgentTurnIdSchema, } from './foundation.js';
1
+ export { AgentApprovalOptionIdSchema, AgentArtifactIdSchema, AgentConfigurationRevisionIdSchema, AgentErrorContextSchema, AgentErrorSchema, AgentInstanceIdSchema, AgentIsoDateTimeSchema, AgentItemIdSchema, AgentJsonValueSchema, AgentProviderConversationIdSchema, AgentProviderHistoryAnchorSchema, AgentProviderItemRefSchema, AgentProviderKeySchema, AgentProviderRefsSchema, AgentProviderRequestRefSchema, AgentProviderTurnRefSchema, AgentRequestFieldIdSchema, AgentRequestIdSchema, AgentSessionIdSchema, AgentTurnIdSchema, } from './foundation.js';
2
2
  export { AgentSessionBindingSchema, AgentSessionBranchSourceSchema, AgentSessionBranchInputSchema, AgentSessionConfigurationSchema, AgentSessionCreateInputSchema, AgentSessionOpenInputSchema, AgentSessionResumeInputSchema, } from './sessions.js';
3
- export { AgentBrowserActionDetailsSchema, AgentCollaborationToolCallDetailsSchema, AgentCommandExecutionDetailsSchema, AgentComputerActionDetailsSchema, AgentContentStreamKindSchema, AgentDiffSummarySchema, AgentDynamicToolCallDetailsSchema, AgentFileChangeDetailsSchema, AgentFileChangeSchema, AgentImageViewDetailsSchema, AgentItemSnapshotSchema, AgentMcpToolCallDetailsSchema, AgentPlanStepSchema, AgentReviewDetailsSchema, AgentTurnCompletedPayloadSchema, AgentTurnInputContentCompositionSchema, AgentTurnInputContentSchema, AgentTurnInteractionModeSchema, AgentTurnInputPartSchema, AgentTurnInterruptionInputSchema, AgentTurnRunInputSchema, AgentWebSearchDetailsSchema, } from './turns.js';
4
- export { AgentElicitationRequestSchema, AgentRequestResolutionSchema, AgentRequestSchema, } from './requests.js';
5
- export { AgentCapabilitiesSchema } from './capabilities.js';
3
+ export { AgentBrowserActionDetailsSchema, AgentCollaborationToolCallDetailsSchema, AgentCommandExecutionDetailsSchema, AgentComputerActionDetailsSchema, AgentContentStreamKindSchema, AgentContextCompactionDetailsSchema, AgentDiffSummarySchema, AgentDynamicToolCallDetailsSchema, AgentFileChangeDetailsSchema, AgentFileChangeSchema, AgentImageViewDetailsSchema, AgentItemSnapshotSchema, AgentMcpToolCallDetailsSchema, AgentPlanStepSchema, AgentReviewDetailsSchema, AgentTurnCompletedPayloadSchema, AgentTurnInputContentCompositionSchema, AgentTurnInputContentSchema, AgentTurnInteractionModeSchema, AgentTurnInputPartSchema, AgentTurnInterruptionInputSchema, AgentTurnRunInputSchema, AgentWebSearchDetailsSchema, } from './turns.js';
4
+ export { AgentApprovalRequestSchema, AgentApprovalResolutionSchema, AgentElicitationRequestSchema, AgentRequestResolutionSchema, AgentRequestSchema, } from './requests.js';
5
+ export { AgentApprovalCapabilitySchema, AgentCapabilitiesSchema, } from './capabilities.js';
6
6
  export { AgentArtifactDescriptorSchema } from './artifacts.js';
7
- export { AgentEventSchema } from './events.js';
7
+ export { AgentContextUsageSchema, AgentEventSchema } from './events.js';
8
8
  export type { AgentProtocolSchemaTypeAssertions } from './typeEquality.generated.js';
9
9
  //# sourceMappingURL=index.d.ts.map
package/dist/zod/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AgentApprovalOptionIdSchema,
2
3
  AgentArtifactIdSchema,
3
4
  AgentConfigurationRevisionIdSchema,
4
5
  AgentErrorContextSchema,
@@ -34,6 +35,7 @@ import {
34
35
  AgentCommandExecutionDetailsSchema,
35
36
  AgentComputerActionDetailsSchema,
36
37
  AgentContentStreamKindSchema,
38
+ AgentContextCompactionDetailsSchema,
37
39
  AgentDiffSummarySchema,
38
40
  AgentDynamicToolCallDetailsSchema,
39
41
  AgentFileChangeDetailsSchema,
@@ -53,14 +55,23 @@ import {
53
55
  AgentWebSearchDetailsSchema
54
56
  } from "./turns.js";
55
57
  import {
58
+ AgentApprovalRequestSchema,
59
+ AgentApprovalResolutionSchema,
56
60
  AgentElicitationRequestSchema,
57
61
  AgentRequestResolutionSchema,
58
62
  AgentRequestSchema
59
63
  } from "./requests.js";
60
- import { AgentCapabilitiesSchema } from "./capabilities.js";
64
+ import {
65
+ AgentApprovalCapabilitySchema,
66
+ AgentCapabilitiesSchema
67
+ } from "./capabilities.js";
61
68
  import { AgentArtifactDescriptorSchema } from "./artifacts.js";
62
- import { AgentEventSchema } from "./events.js";
69
+ import { AgentContextUsageSchema, AgentEventSchema } from "./events.js";
63
70
  export {
71
+ AgentApprovalCapabilitySchema,
72
+ AgentApprovalOptionIdSchema,
73
+ AgentApprovalRequestSchema,
74
+ AgentApprovalResolutionSchema,
64
75
  AgentArtifactDescriptorSchema,
65
76
  AgentArtifactIdSchema,
66
77
  AgentBrowserActionDetailsSchema,
@@ -70,6 +81,8 @@ export {
70
81
  AgentComputerActionDetailsSchema,
71
82
  AgentConfigurationRevisionIdSchema,
72
83
  AgentContentStreamKindSchema,
84
+ AgentContextCompactionDetailsSchema,
85
+ AgentContextUsageSchema,
73
86
  AgentDiffSummarySchema,
74
87
  AgentDynamicToolCallDetailsSchema,
75
88
  AgentElicitationRequestSchema,
@@ -1,5 +1,52 @@
1
1
  import { z } from 'zod/v4';
2
- import type { AgentElicitationRequest, AgentRequest, AgentRequestResolution } from '../requests/types.js';
2
+ import type { AgentApprovalRequest, AgentApprovalResolution, AgentElicitationRequest, AgentRequest, AgentRequestResolution } from '../requests/types.js';
3
+ export declare const AgentApprovalRequestPortableSchema: z.ZodReadonly<z.ZodObject<{
4
+ requestKind: z.ZodLiteral<"approval">;
5
+ requestId: z.ZodType<import("../index.js").AgentRequestId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentRequestId, unknown>>;
6
+ prompt: z.ZodString;
7
+ subject: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
8
+ kind: z.ZodLiteral<"plan">;
9
+ title: z.ZodString;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ artifactId: z.ZodType<import("../index.js").AgentArtifactId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentArtifactId, unknown>>;
12
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
13
+ kind: z.ZodEnum<{
14
+ other: "other";
15
+ file_change: "file_change";
16
+ tool: "tool";
17
+ command: "command";
18
+ }>;
19
+ title: z.ZodString;
20
+ description: z.ZodOptional<z.ZodString>;
21
+ itemId: z.ZodType<import("../index.js").AgentItemId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentItemId, unknown>>;
22
+ }, z.core.$strict>>], "kind">;
23
+ options: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
24
+ optionId: z.ZodType<import("../index.js").AgentApprovalOptionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentApprovalOptionId, unknown>>;
25
+ label: z.ZodString;
26
+ description: z.ZodOptional<z.ZodString>;
27
+ decision: z.ZodEnum<{
28
+ approved: "approved";
29
+ denied: "denied";
30
+ }>;
31
+ persistence: z.ZodEnum<{
32
+ session: "session";
33
+ once: "once";
34
+ workspace: "workspace";
35
+ }>;
36
+ scope: z.ZodReadonly<z.ZodObject<{
37
+ kind: z.ZodEnum<{
38
+ exact_action: "exact_action";
39
+ command_pattern: "command_pattern";
40
+ domain: "domain";
41
+ tool: "tool";
42
+ server: "server";
43
+ all_edits: "all_edits";
44
+ }>;
45
+ }, z.core.$strict>>;
46
+ }, z.core.$strict>>>>;
47
+ expiresAt: z.ZodOptional<z.ZodType<import("../index.js").AgentIsoDateTime, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentIsoDateTime, unknown>>>;
48
+ }, z.core.$strict>>;
49
+ export declare const AgentApprovalRequestSchema: z.ZodType<AgentApprovalRequest>;
3
50
  export declare const AgentElicitationRequestPortableSchema: z.ZodReadonly<z.ZodObject<{
4
51
  requestKind: z.ZodLiteral<"elicitation">;
5
52
  requestId: z.ZodType<import("../index.js").AgentRequestId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentRequestId, unknown>>;
@@ -47,12 +94,37 @@ export declare const AgentRequestPortableSchema: z.ZodDiscriminatedUnion<[z.ZodR
47
94
  kind: z.ZodEnum<{
48
95
  other: "other";
49
96
  file_change: "file_change";
50
- command: "command";
51
97
  tool: "tool";
98
+ command: "command";
52
99
  }>;
53
100
  title: z.ZodString;
54
101
  description: z.ZodOptional<z.ZodString>;
102
+ itemId: z.ZodType<import("../index.js").AgentItemId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentItemId, unknown>>;
55
103
  }, z.core.$strict>>], "kind">;
104
+ options: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
105
+ optionId: z.ZodType<import("../index.js").AgentApprovalOptionId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentApprovalOptionId, unknown>>;
106
+ label: z.ZodString;
107
+ description: z.ZodOptional<z.ZodString>;
108
+ decision: z.ZodEnum<{
109
+ approved: "approved";
110
+ denied: "denied";
111
+ }>;
112
+ persistence: z.ZodEnum<{
113
+ session: "session";
114
+ once: "once";
115
+ workspace: "workspace";
116
+ }>;
117
+ scope: z.ZodReadonly<z.ZodObject<{
118
+ kind: z.ZodEnum<{
119
+ exact_action: "exact_action";
120
+ command_pattern: "command_pattern";
121
+ domain: "domain";
122
+ tool: "tool";
123
+ server: "server";
124
+ all_edits: "all_edits";
125
+ }>;
126
+ }, z.core.$strict>>;
127
+ }, z.core.$strict>>>>;
56
128
  expiresAt: z.ZodOptional<z.ZodType<import("../index.js").AgentIsoDateTime, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentIsoDateTime, unknown>>>;
57
129
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
58
130
  requestKind: z.ZodLiteral<"elicitation">;
@@ -88,15 +160,8 @@ export declare const AgentRequestPortableSchema: z.ZodDiscriminatedUnion<[z.ZodR
88
160
  expiresAt: z.ZodOptional<z.ZodType<import("../index.js").AgentIsoDateTime, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentIsoDateTime, unknown>>>;
89
161
  }, z.core.$strict>>], "requestKind">;
90
162
  export declare const AgentRequestSchema: z.ZodType<AgentRequest>;
91
- export declare const AgentRequestResolutionPortableSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
92
- requestKind: z.ZodLiteral<"approval">;
93
- requestId: z.ZodType<import("../index.js").AgentRequestId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentRequestId, unknown>>;
94
- decision: z.ZodEnum<{
95
- canceled: "canceled";
96
- approved: "approved";
97
- denied: "denied";
98
- }>;
99
- }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
163
+ export declare const AgentApprovalResolutionSchema: z.ZodType<AgentApprovalResolution>;
164
+ export declare const AgentRequestResolutionPortableSchema: z.ZodUnion<readonly [z.ZodType<AgentApprovalResolution, unknown, z.core.$ZodTypeInternals<AgentApprovalResolution, unknown>>, z.ZodReadonly<z.ZodObject<{
100
165
  requestKind: z.ZodLiteral<"elicitation">;
101
166
  requestId: z.ZodType<import("../index.js").AgentRequestId, unknown, z.core.$ZodTypeInternals<import("../index.js").AgentRequestId, unknown>>;
102
167
  disposition: z.ZodLiteral<"answered">;