@agen-ai/agent-protocol 0.1.0 → 0.2.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.
@@ -5,31 +5,65 @@ import {
5
5
  AGENT_PROTOCOL_TEXT_MAX_LENGTH
6
6
  } from "../foundation/types.js";
7
7
  import {
8
+ AGENT_APPROVAL_DESCRIPTION_MAX_LENGTH,
9
+ AGENT_APPROVAL_LABEL_MAX_LENGTH,
10
+ AGENT_APPROVAL_OPTIONS_MAX_LENGTH,
11
+ AGENT_APPROVAL_PERSISTENCES,
12
+ AGENT_APPROVAL_SCOPE_KINDS
13
+ } from "../requests/types.js";
14
+ import {
15
+ AgentApprovalOptionIdSchema,
8
16
  AgentArtifactIdSchema,
9
17
  AgentCanonicalIdValueSchema,
18
+ AgentItemIdSchema,
10
19
  AgentIsoDateTimeSchema,
11
20
  AgentRequestFieldIdSchema,
12
21
  AgentRequestIdSchema
13
22
  } from "./foundation.js";
14
- const AgentApprovalRequestSchema = z.object({
23
+ const AgentApprovalLabelSchema = z.string().min(1).max(AGENT_APPROVAL_LABEL_MAX_LENGTH).regex(/^(?:\S|\S[\s\S]*\S)$/u);
24
+ const AgentApprovalDescriptionSchema = z.string().min(1).max(AGENT_APPROVAL_DESCRIPTION_MAX_LENGTH).regex(/^(?:\S|\S[\s\S]*\S)$/u);
25
+ const AgentApprovalOptionSchema = z.object({
26
+ optionId: AgentApprovalOptionIdSchema,
27
+ label: AgentApprovalLabelSchema,
28
+ description: AgentApprovalDescriptionSchema.optional(),
29
+ decision: z.enum(["approved", "denied"]),
30
+ persistence: z.enum(AGENT_APPROVAL_PERSISTENCES),
31
+ scope: z.object({ kind: z.enum(AGENT_APPROVAL_SCOPE_KINDS) }).strict().readonly()
32
+ }).strict().readonly();
33
+ const AgentApprovalRequestPortableSchema = z.object({
15
34
  requestKind: z.literal("approval"),
16
35
  requestId: AgentRequestIdSchema,
17
- prompt: z.string().min(1).max(AGENT_PROTOCOL_TEXT_MAX_LENGTH),
36
+ prompt: AgentApprovalDescriptionSchema,
18
37
  subject: z.discriminatedUnion("kind", [
19
38
  z.object({
20
39
  kind: z.literal("plan"),
21
- title: z.string().min(1).max(200),
22
- description: z.string().max(AGENT_PROTOCOL_SUMMARY_MAX_LENGTH).optional(),
40
+ title: AgentApprovalLabelSchema,
41
+ description: AgentApprovalDescriptionSchema.optional(),
23
42
  artifactId: AgentArtifactIdSchema
24
43
  }).strict().readonly(),
25
44
  z.object({
26
45
  kind: z.enum(["command", "file_change", "tool", "other"]),
27
- title: z.string().min(1).max(200),
28
- description: z.string().max(AGENT_PROTOCOL_SUMMARY_MAX_LENGTH).optional()
46
+ title: AgentApprovalLabelSchema,
47
+ description: AgentApprovalDescriptionSchema.optional(),
48
+ itemId: AgentItemIdSchema
29
49
  }).strict().readonly()
30
50
  ]),
51
+ options: z.array(AgentApprovalOptionSchema).min(1).max(AGENT_APPROVAL_OPTIONS_MAX_LENGTH).readonly(),
31
52
  expiresAt: AgentIsoDateTimeSchema.optional()
32
53
  }).strict().readonly();
54
+ const AgentApprovalRequestSchema = AgentApprovalRequestPortableSchema.superRefine((request, context) => {
55
+ const optionIds = /* @__PURE__ */ new Set();
56
+ request.options.forEach((option, optionIndex) => {
57
+ if (optionIds.has(option.optionId)) {
58
+ context.addIssue({
59
+ code: "custom",
60
+ path: ["options", optionIndex, "optionId"],
61
+ message: "Approval option IDs must be unique within a request."
62
+ });
63
+ }
64
+ optionIds.add(option.optionId);
65
+ });
66
+ });
33
67
  const AgentRequestChoiceValueSchema = AgentCanonicalIdValueSchema.and(
34
68
  z.string().max(160)
35
69
  );
@@ -98,12 +132,11 @@ const AgentElicitationRequestSchema = AgentElicitationRequestPortableSchema.supe
98
132
  });
99
133
  });
100
134
  const AgentRequestPortableSchema = z.discriminatedUnion("requestKind", [
101
- AgentApprovalRequestSchema,
135
+ AgentApprovalRequestPortableSchema,
102
136
  AgentElicitationRequestPortableSchema
103
137
  ]);
104
138
  const AgentRequestSchema = AgentRequestPortableSchema.superRefine((request, context) => {
105
- if (request.requestKind !== "elicitation") return;
106
- const parsed = AgentElicitationRequestSchema.safeParse(request);
139
+ const parsed = request.requestKind === "approval" ? AgentApprovalRequestSchema.safeParse(request) : AgentElicitationRequestSchema.safeParse(request);
107
140
  if (parsed.success) return;
108
141
  for (const issue of parsed.error.issues) {
109
142
  context.addIssue({
@@ -132,12 +165,21 @@ const AgentElicitationAnswerSchema = z.discriminatedUnion("kind", [
132
165
  value: z.boolean()
133
166
  }).strict().readonly()
134
167
  ]);
135
- const AgentRequestResolutionPortableSchema = z.union([
168
+ const AgentApprovalResolutionSchema = z.discriminatedUnion("disposition", [
136
169
  z.object({
137
170
  requestKind: z.literal("approval"),
138
171
  requestId: AgentRequestIdSchema,
139
- decision: z.enum(["approved", "denied", "canceled"])
172
+ disposition: z.literal("selected"),
173
+ optionId: AgentApprovalOptionIdSchema
140
174
  }).strict().readonly(),
175
+ z.object({
176
+ requestKind: z.literal("approval"),
177
+ requestId: AgentRequestIdSchema,
178
+ disposition: z.literal("canceled")
179
+ }).strict().readonly()
180
+ ]);
181
+ const AgentRequestResolutionPortableSchema = z.union([
182
+ AgentApprovalResolutionSchema,
141
183
  z.object({
142
184
  requestKind: z.literal("elicitation"),
143
185
  requestId: AgentRequestIdSchema,
@@ -165,6 +207,9 @@ const AgentRequestResolutionSchema = AgentRequestResolutionPortableSchema.superR
165
207
  });
166
208
  });
167
209
  export {
210
+ AgentApprovalRequestPortableSchema,
211
+ AgentApprovalRequestSchema,
212
+ AgentApprovalResolutionSchema,
168
213
  AgentElicitationRequestPortableSchema,
169
214
  AgentElicitationRequestSchema,
170
215
  AgentRequestPortableSchema,
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
- import { type AgentBrowserActionDetails, type AgentCollaborationToolCallDetails, type AgentCommandExecutionDetails, type AgentComputerActionDetails, type AgentDiffSummary, type AgentDynamicToolCallDetails, type AgentFileChange, type AgentFileChangeDetails, type AgentImageViewDetails, type AgentItemSnapshot, type AgentMcpToolCallDetails, type AgentPlanStep, type AgentReviewDetails, type AgentTurnCompletedPayload, type AgentTurnInputContent, type AgentTurnInterruptionInput, type AgentTurnRunInput, type AgentWebSearchDetails } from '../turns/types.js';
2
+ import { type AgentBrowserActionDetails, type AgentCollaborationToolCallDetails, type AgentCommandExecutionDetails, type AgentComputerActionDetails, type AgentContextCompactionDetails, type AgentDiffSummary, type AgentDynamicToolCallDetails, type AgentFileChange, type AgentFileChangeDetails, type AgentImageViewDetails, type AgentItemSnapshot, type AgentMcpToolCallDetails, type AgentPlanStep, type AgentReviewDetails, type AgentTurnCompletedPayload, type AgentTurnInputContent, type AgentTurnInterruptionInput, type AgentTurnRunInput, type AgentWebSearchDetails } from '../turns/types.js';
3
3
  export declare const AGENT_PROTOCOL_INLINE_IMAGE_BASE64_MAX_LENGTH = 500000;
4
4
  export declare const AgentImageInputSourceSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
5
5
  mediaType: z.ZodEnum<{
@@ -193,6 +193,7 @@ export declare const AgentBrowserActionDetailsSchema: z.ZodType<AgentBrowserActi
193
193
  export declare const AgentComputerActionDetailsSchema: z.ZodType<AgentComputerActionDetails>;
194
194
  export declare const AgentImageViewDetailsSchema: z.ZodType<AgentImageViewDetails>;
195
195
  export declare const AgentReviewDetailsSchema: z.ZodType<AgentReviewDetails>;
196
+ export declare const AgentContextCompactionDetailsSchema: z.ZodType<AgentContextCompactionDetails>;
196
197
  export declare const AgentItemSnapshotSchema: z.ZodType<AgentItemSnapshot>;
197
198
  export declare const AgentContentStreamKindSchema: z.ZodEnum<{
198
199
  unknown: "unknown";
package/dist/zod/turns.js CHANGED
@@ -9,6 +9,9 @@ import {
9
9
  import { compareStringsByUnicodeCodePoint } from "../foundation/ordering.js";
10
10
  import {
11
11
  AGENT_CONTENT_STREAM_KINDS,
12
+ AGENT_CONTEXT_COMPACTION_DURATION_MAX_MILLISECONDS,
13
+ AGENT_CONTEXT_COMPACTION_SUMMARY_PREVIEW_MAX_LENGTH,
14
+ AGENT_CONTEXT_COMPACTION_TRIGGERS,
12
15
  AGENT_FILE_CHANGE_KINDS,
13
16
  AGENT_IMAGE_INPUT_MEDIA_TYPES,
14
17
  AGENT_ITEM_STATUSES,
@@ -262,6 +265,31 @@ const AgentReviewDetailsSchema = z.discriminatedUnion("phase", [
262
265
  ...TruncatedShape
263
266
  }).strict().readonly()
264
267
  ]);
268
+ const AgentContextCompactionDetailsSchema = z.object({
269
+ trigger: z.enum(AGENT_CONTEXT_COMPACTION_TRIGGERS),
270
+ beforeTokens: NonNegativeSafeIntegerSchema.optional(),
271
+ afterTokens: NonNegativeSafeIntegerSchema.optional(),
272
+ durationMs: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).max(AGENT_CONTEXT_COMPACTION_DURATION_MAX_MILLISECONDS).optional(),
273
+ summaryPreview: createAgentCanonicalNonBlankStringSchema(
274
+ AGENT_CONTEXT_COMPACTION_SUMMARY_PREVIEW_MAX_LENGTH
275
+ ).optional()
276
+ }).strict().superRefine((details, context) => {
277
+ if (details.beforeTokens === void 0 !== (details.afterTokens === void 0)) {
278
+ context.addIssue({
279
+ code: "custom",
280
+ path: ["beforeTokens"],
281
+ message: "Compaction before/after tokens must be present together."
282
+ });
283
+ return;
284
+ }
285
+ if (details.beforeTokens !== void 0 && details.afterTokens !== void 0 && details.afterTokens > details.beforeTokens) {
286
+ context.addIssue({
287
+ code: "custom",
288
+ path: ["afterTokens"],
289
+ message: "Compaction cannot increase retained context tokens."
290
+ });
291
+ }
292
+ }).readonly();
265
293
  const AgentItemSnapshotCommonShape = {
266
294
  itemId: AgentItemIdSchema,
267
295
  status: z.enum(AGENT_ITEM_STATUSES),
@@ -329,7 +357,11 @@ const AgentItemSnapshotSchema = z.discriminatedUnion("itemKind", [
329
357
  itemKind: z.literal("review"),
330
358
  details: AgentReviewDetailsSchema
331
359
  }).strict().readonly(),
332
- itemWithoutDetails("context_compaction"),
360
+ z.object({
361
+ ...AgentItemSnapshotCommonShape,
362
+ itemKind: z.literal("context_compaction"),
363
+ details: AgentContextCompactionDetailsSchema
364
+ }).strict().readonly(),
333
365
  itemWithoutDetails("unknown")
334
366
  ]);
335
367
  const AgentContentStreamKindSchema = z.enum(AGENT_CONTENT_STREAM_KINDS);
@@ -377,6 +409,7 @@ export {
377
409
  AgentCommandExecutionDetailsSchema,
378
410
  AgentComputerActionDetailsSchema,
379
411
  AgentContentStreamKindSchema,
412
+ AgentContextCompactionDetailsSchema,
380
413
  AgentDiffSummarySchema,
381
414
  AgentDynamicToolCallDetailsSchema,
382
415
  AgentFileChangeDetailsSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agen-ai/agent-protocol",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "Provider-neutral sessions, turns, requests, capabilities, artifacts, and events for coding-agent runtimes.",
6
6
  "type": "module",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "zod": "4.4.3",
59
- "@agen-ai/validation": "^0.1.0"
59
+ "@agen-ai/validation": "^0.2.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "ajv": "8.17.1",