@agen-ai/agent-protocol 0.4.3 → 0.4.5

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.
Files changed (52) hide show
  1. package/README.md +151 -21
  2. package/dist/capabilities/types.d.ts +3 -1
  3. package/dist/events/types.d.ts +1 -1
  4. package/dist/foundation/types.d.ts +2 -1
  5. package/dist/foundation/types.js +1 -1
  6. package/dist/jsonSchema/generated.d.ts +13637 -9890
  7. package/dist/jsonSchema/generated.js +3025 -644
  8. package/dist/public/index.d.ts +1 -0
  9. package/dist/public/index.js +1 -0
  10. package/dist/public/structuredOutput.d.ts +2 -0
  11. package/dist/public/structuredOutput.js +1 -0
  12. package/dist/sessions/types.d.ts +2 -0
  13. package/dist/structuredOutput/boundedJson.d.ts +13 -0
  14. package/dist/structuredOutput/boundedJson.js +143 -0
  15. package/dist/structuredOutput/constants.d.ts +24 -0
  16. package/dist/structuredOutput/constants.js +57 -0
  17. package/dist/structuredOutput/definition.d.ts +9 -0
  18. package/dist/structuredOutput/definition.js +15 -0
  19. package/dist/structuredOutput/index.d.ts +9 -0
  20. package/dist/structuredOutput/index.js +12 -0
  21. package/dist/structuredOutput/issues.d.ts +8 -0
  22. package/dist/structuredOutput/issues.js +76 -0
  23. package/dist/structuredOutput/parsers.d.ts +10 -0
  24. package/dist/structuredOutput/parsers.js +74 -0
  25. package/dist/structuredOutput/schemaAdmission.d.ts +9 -0
  26. package/dist/structuredOutput/schemaAdmission.js +247 -0
  27. package/dist/structuredOutput/types.d.ts +75 -0
  28. package/dist/structuredOutput/types.js +0 -0
  29. package/dist/structuredOutput/values.d.ts +5 -0
  30. package/dist/structuredOutput/values.js +89 -0
  31. package/dist/turns/types.d.ts +18 -5
  32. package/dist/zod/capabilities.d.ts +3 -2
  33. package/dist/zod/capabilities.js +2 -0
  34. package/dist/zod/events.d.ts +24 -33
  35. package/dist/zod/events.js +94 -94
  36. package/dist/zod/foundation.d.ts +1 -0
  37. package/dist/zod/foundation.js +3 -0
  38. package/dist/zod/index.d.ts +2 -0
  39. package/dist/zod/index.js +25 -1
  40. package/dist/zod/operations.d.ts +2 -2
  41. package/dist/zod/outputDefinition.d.ts +4 -0
  42. package/dist/zod/outputDefinition.js +22 -0
  43. package/dist/zod/outputSchema.d.ts +4 -0
  44. package/dist/zod/outputSchema.js +177 -0
  45. package/dist/zod/sessions.d.ts +14 -0
  46. package/dist/zod/sessions.js +26 -3
  47. package/dist/zod/structuredOutput.d.ts +14 -0
  48. package/dist/zod/structuredOutput.js +209 -0
  49. package/dist/zod/turns.d.ts +19 -5
  50. package/dist/zod/turns.js +63 -24
  51. package/dist/zod/typeEquality.generated.d.ts +16 -2
  52. package/package.json +6 -2
package/README.md CHANGED
@@ -6,12 +6,15 @@ capabilities, typed operations, safe configuration and managed-content inventori
6
6
  observations, effective harness content and package catalogs, environment observations, account-quota observations, operational failures and recovery hints, collaboration lifecycles, generated resources, portable
7
7
  artifact descriptors, and provider-observed events. The package does not define a transport or
8
8
  execution runtime.
9
- The coordinated release is `0.4.3` and uses Agent Protocol V12, including exact request
10
- unavailability and session decisions, forms and plan reviews. Published `0.4.1` retains V11;
11
- `0.4.0` retains V10. Source versioning does not establish registry publication.
9
+ Current source is the unpublished coordinated eight-package `0.4.4` candidate and uses Agent
10
+ Protocol V13, adding structured final output. Published `0.4.3` is the seven-package V12 release,
11
+ including exact request unavailability and session decisions, forms and plan reviews. Published
12
+ `0.4.1` retains V11; `0.4.0` retains V10. Source versioning does not establish registry publication.
12
13
  Keep all installed SDK packages at one coordinated version. The [0.4.2 migration
13
14
  guide](../../MIGRATING-TO-0.4.2.md) covers V12 envelopes, tagged session responses and
14
15
  the separate ownership of request eligibility, entered receipts and continuation output.
16
+ The [0.4.4 upgrade guide](../../UPGRADING-TO-0.4.4.md) covers the V13 source changes and optional,
17
+ execution-independent `@agen-ai/agent-history` package.
15
18
 
16
19
  ## Ownership boundary
17
20
 
@@ -38,8 +41,9 @@ carry no fabricated windows or hints.
38
41
  - `@agen-ai/agent-protocol` exports the complete plain API.
39
42
  - `/sessions`, `/session-interactions`, `/turns`, `/requests`, `/events`, `/capabilities`, `/artifacts`, `/operations`,
40
43
  `/configuration`, `/managed-content`, `/integrations`, `/collaboration`, `/resources`, and
41
- `/account-quota`, `/effective-content`, `/commands`, `/extensions`, and `/environment` are focused plain entrypoints.
42
- - `/zod` is the only entrypoint that exposes Zod schemas.
44
+ `/account-quota`, `/effective-content`, `/commands`, `/extensions`, `/environment`, and
45
+ `/structured-output` are focused plain entrypoints.
46
+ - `/zod` is the only entrypoint that exposes Zod schemas and the `zodOutput` authoring adapter.
43
47
  - `/json-schema` exposes deterministic draft 2020-12 schema artifacts.
44
48
 
45
49
  Ordinary entrypoints expose plain TypeScript types, constants, parsers, and validator-neutral
@@ -56,7 +60,7 @@ import {
56
60
  } from '@agen-ai/agent-protocol';
57
61
 
58
62
  const event: AgentEvent = parseAgentEvent({
59
- protocolVersion: 12,
63
+ protocolVersion: 13,
60
64
  type: 'content.delta',
61
65
  sessionId: parseAgentSessionId('external-session:42'),
62
66
  turnId: parseAgentTurnId('external-turn:9'),
@@ -71,7 +75,7 @@ const event: AgentEvent = parseAgentEvent({
71
75
  const roundTripped = parseAgentEvent(JSON.parse(JSON.stringify(event)));
72
76
  ```
73
77
 
74
- Serialized values carry `protocolVersion: 12`; TypeScript API names remain unsuffixed. Unknown
78
+ Serialized values carry `protocolVersion: 13`; TypeScript API names remain unsuffixed. Unknown
75
79
  fields and unsupported protocol versions are rejected.
76
80
 
77
81
  Item snapshots are a closed union keyed by `itemKind`. Common identity and lifecycle fields are
@@ -88,7 +92,7 @@ Approval requests correlate to one live item or exact proposed-plan artifact and
88
92
  bounded list of typed options. Every option declares its decision and a closed `consequence`.
89
93
  `scoped` contains precise `persistence` and `scope`; `provider_managed_remembrance` contains explicit
90
94
  unknown duration and applicability and a required bounded explanation. Flat persistence/scope
91
- fields are rejected in V12. Neither approval nor a delivered answer proves the provider wrote a rule.
95
+ fields are rejected in the current protocol. Neither approval nor a delivered answer proves the provider wrote a rule.
92
96
  Resolutions select one exact offered `optionId` or explicitly cancel. Supported approval capability
93
97
  requires `providerManagedRemembrance`: false requires a nonempty readonly precise-mode tuple; true
94
98
  allows a bounded readonly array, including empty for a remembered-only provider. Scoped options
@@ -117,6 +121,130 @@ collapse unrelated pools into one percentage. Quantity units remain distinct fro
117
121
  which uses integer minor units with an explicit scale. None of these domains has a generic
118
122
  extension or metadata bag.
119
123
 
124
+ ## Structured final output
125
+
126
+ V13 defines a provider-neutral output request, finite JSON Schema profile, and terminal result.
127
+ Use [`generateObject`](../agent-runtime/README.md#generate-a-typed-object) from
128
+ `@agen-ai/agent-runtime/generation` to own a fresh generation session, or use the lower-level
129
+ session/turn API when the application owns that lifecycle. Successful generation establishes that
130
+ the returned JSON satisfies the admitted schema and local decoder. It does not establish factual
131
+ correctness or guarantee that every run completes.
132
+
133
+ `capabilities.turns.structuredOutput` is a required discriminated union:
134
+
135
+ | Capability | Contract |
136
+ | --- | --- |
137
+ | `{ kind: 'unsupported' }` | Structured requests fail before provider delegation. |
138
+ | `{ kind: 'supported', mechanism: 'native', schemaProfile: 'agenai.output-schema.v1', scope, maxSchemaBytes, maxOutputBytes, resume: false, branch: false }` | A native mapping accepts the exact profile within its advertised byte limits. `scope` is `turn` or `session`; limits can be stricter than the portable ceilings below. |
139
+
140
+ For `turn` scope, supply `output: { kind: 'json_schema', schema }` on `startTurn`; a later turn
141
+ without `output` is ordinary text. For `session` scope, supply it on `createSession`; every turn
142
+ inherits that immutable schema. An `output` property on a schema-bound turn is rejected even if
143
+ its value is `undefined` or the same schema. Steering cannot change the schema. Structured resume
144
+ and branch are unsupported; ordinary resume/branch remain separate capabilities. The validated
145
+ runtime copies and freezes admitted schema data, so caller mutation cannot change the request.
146
+
147
+ Every `turn.completed` payload requires `structuredOutput`:
148
+
149
+ | Result | Meaning |
150
+ | --- | --- |
151
+ | `{ kind: 'not_requested' }` | The turn had no admitted output schema. |
152
+ | `{ kind: 'json', value }` | A complete JSON object is available; only `outcome: 'completed'` can carry it. The runtime independently validates it against the admitted schema. |
153
+ | `{ kind: 'unavailable', reason }` | Requested structured generation has no validated value. `schema_mismatch` may include bounded validator-neutral `issues`. |
154
+
155
+ The unavailable reasons are `refused`, `incomplete`, `missing_output`, `invalid_json`,
156
+ `schema_mismatch`, `output_limit_exceeded`, `native_retries_exhausted`, and `provider_error`.
157
+ A native `completed` outcome can coexist with `unavailable`; failed, canceled and expired outcomes
158
+ cannot carry `json`. An unsolicited value or an admitted request reported as `not_requested` is a
159
+ provider contract violation. Ordinary text/reasoning deltas remain observations, never partial
160
+ validated JSON. The SDK does not extract JSON from prose, repair values, or replay generation.
161
+
162
+ ### Plain schemas and typed decoders
163
+
164
+ The root and `/structured-output` entrypoints export `createAgentOutputDefinition`,
165
+ `parseAgentOutputSchema`, `safeParseAgentOutputSchema`, `validateAgentOutputValue`, the plain types,
166
+ and limits. A schema-only definition produces `AgentJsonObject`. A decoder supplies actual type
167
+ evidence; there is no unchecked `createAgentOutputDefinition<MyType>(schema)` overload.
168
+
169
+ ```ts
170
+ import { createAgentOutputDefinition } from '@agen-ai/agent-protocol';
171
+
172
+ const titleOutput = createAgentOutputDefinition({
173
+ type: 'object',
174
+ properties: { title: { type: 'string', minLength: 1, maxLength: 80 } },
175
+ required: ['title'],
176
+ additionalProperties: false,
177
+ }, (value) => typeof value.title === 'string'
178
+ ? { success: true, data: { title: value.title } }
179
+ : { success: false, issues: [{ code: 'title_required', path: ['title'], message: 'A title is required.' }] });
180
+ // The decoder infers { title: string } for generateObject({ output: titleOutput, ... }).
181
+ ```
182
+
183
+ The decoder returns `AgentProtocolParseResult<T>` and performs local validation only. The runtime
184
+ checks its successful result again and requires it to preserve the generated JSON value exactly.
185
+ Coercion, trimming, defaults, dropped properties, classes and transformed values are rejected.
186
+ Apply presentation or persistence transforms after `generateObject` succeeds.
187
+
188
+ `zodOutput` explicitly opts into Zod composition and executes that schema as the local decoder:
189
+
190
+ ```ts
191
+ import { z } from 'zod/v4';
192
+ import { zodOutput } from '@agen-ai/agent-protocol/zod';
193
+
194
+ const titleOutput = zodOutput(z.strictObject({ title: z.string() }));
195
+ // Inferred value: { title: string }; ordinary protocol/runtime declarations stay validator-neutral.
196
+ ```
197
+
198
+ The Zod adapter accepts finite strict objects with required fields, plain strings, string enums
199
+ and literals, booleans, null, homogeneous arrays, one nullable wrapper, and finite numbers with
200
+ inclusive bounds or safe-integer checks. It rejects optional fields, transforms/coercion, defaults,
201
+ refinements, formats/patterns, lazy/recursive schemas, general unions and unsupported wrappers.
202
+ It also rejects Zod string length checks because they count UTF-16 units while this profile counts
203
+ Unicode code points. Zod array checks, including `.min()`, `.max()` and `.length()`, are rejected
204
+ because their condition provenance cannot be represented safely. For string or array bounds, use
205
+ `createAgentOutputDefinition` with neutral `minLength`/`maxLength` or `minItems`/`maxItems` plus a
206
+ validation-only decoder. An explicitly local check can reject a value but does not become a native
207
+ generation constraint. Unsupported authoring raises `AgentProtocolValidationError` with an
208
+ actionable issue path; the adapter never silently strips a check.
209
+
210
+ ### The `agenai.output-schema.v1` profile
211
+
212
+ The root is an object. Every object, including nested objects, requires exactly all declared
213
+ properties and `additionalProperties: false`; represent absence through a required nullable field.
214
+ The optional root `$schema` must be `https://json-schema.org/draft/2020-12/schema`.
215
+
216
+ | Node | Accepted keywords beyond `type` |
217
+ | --- | --- |
218
+ | Object | `properties`, `required`, `additionalProperties: false`, `description` |
219
+ | Array | One homogeneous `items` schema, optional `minItems`, `maxItems`, `description` |
220
+ | String | Optional nonempty unique string `enum`, `minLength`, `maxLength`, `description` |
221
+ | Integer or number | Optional inclusive finite `minimum`, `maximum`, `description` |
222
+ | Boolean or null | Optional `description` |
223
+ | Nullable node | Exactly `anyOf: [nonNullNode, { type: 'null' }]` and optional `description`; either input branch order is accepted and canonicalized. Nested nullable wrappers are rejected. |
224
+
225
+ Unknown keywords fail admission. There are no references/definitions, recursion, general
226
+ `anyOf`/`oneOf`/`allOf`, optional properties, tuples, patterns, formats, defaults or arbitrary
227
+ extensions. Numeric bounds must be ordered, integer bounds must admit an integer, and every enum
228
+ entry must satisfy its string bounds. Admission rejects schemas whose minimum possible value
229
+ cannot fit the value or advertised output capacity.
230
+
231
+ | Bound | Portable ceiling |
232
+ | --- | --- |
233
+ | Serialized schema / canonical value | 16,384 UTF-8 bytes each; provider capability can lower either limit |
234
+ | Schema nodes / nesting depth | 256 / 8, counting the root at depth 1 |
235
+ | Properties per object / string enum entries | 100 / 100 |
236
+ | Property names / descriptions | 1–128 / 0–2,000 Unicode code points; names exclude `__proto__`, `constructor`, `prototype` |
237
+ | Declared string/array length bounds | Nonnegative safe integers up to 16,384; array minimum cannot exceed 100 |
238
+ | Value nodes / nesting depth / entries per object or array | 1,024 / 16 / 100 |
239
+ | Raw JSON candidate text | 65,536 UTF-8 bytes before complete parsing; the decoded value must still fit 16,384 bytes |
240
+ | Validation diagnostics | 8 issues / 4,096 serialized UTF-8 bytes total; each code/message is at most 64/256 code points and each path at most 16 segments / 1,024 serialized bytes |
241
+
242
+ The object/array value ceiling still applies when a schema's `maxItems` is higher. String lengths
243
+ count code points without normalization; number validation uses finite JavaScript JSON numbers,
244
+ with `Number.isInteger` for `integer`. Schemas and values must be plain acyclic JSON data with data
245
+ properties: accessors, symbols, sparse arrays, non-finite numbers and prototype-sensitive keys fail
246
+ before use. The byte limits measure serialized JSON, including escaping and property names.
247
+
120
248
  ## Request lifecycle and session interactions
121
249
 
122
250
  `request.unavailable` is a turn event with the existing session, turn and timestamp envelope.
@@ -132,14 +260,14 @@ explicit offered choices and optional `expiresAt`. That expiry is only a provide
132
260
  the host's effective deadline is a separate runtime observation. Descriptors have no `turnId`,
133
261
  provider-native request ID, metadata bag or transport correlation field. The root and focused
134
262
  `@agen-ai/agent-protocol/session-interactions` entrypoints expose plain types and parsers.
135
- Only `/zod` exposes schemas. The `/json-schema` registry contains 35 deterministic contracts,
136
- including request/response schemas for each session kind and their complete unions.
263
+ Only `/zod` exposes validator schemas. The `/json-schema` registry contains deterministic contracts,
264
+ including request/response schemas for each session kind, their complete unions, and structured output.
137
265
 
138
266
  A workspace decision preserves its exact target and grant/decline consequences. A workspace
139
267
  `grant` is provider-managed, persistent and may affect other sessions; it covers the workspace
140
268
  rather than only the categories detected when the question was created. A `decline` leaves
141
269
  configuration gated without promising revocation, persisted denial or suppression of future
142
- questions. Present the target and consequences before applying a decision policy. V12 responses
270
+ questions. Present the target and consequences before applying a decision policy. Current responses
143
271
  are tagged: `parseAgentSessionDecisionResponseFor(request, { kind: 'decision', choiceId })`.
144
272
  The earlier untagged `{ choiceId }` argument is rejected.
145
273
 
@@ -286,18 +414,20 @@ before delegation; a composer can use the same pure functions to preserve and ex
286
414
 
287
415
  ## Versioning and release
288
416
 
289
- Agent Protocol V12 defines the contract shared by this package, `@agen-ai/validation`, and
290
- `@agen-ai/agent-runtime`. The coordinated release is `0.4.3`; published `0.4.1` retains
291
- V11 and `0.4.0` retains V10. Registry publication and dist-tag state are release metadata outside
292
- this contract. Earlier public releases remain historical. The complete seven-package public
293
- release inventory must use one coordinated source version.
294
-
295
- Protocol V12 is independent of private transport and product persistence versions and replaces
296
- V11 at live boundaries. There is one current parser. V11 and older serialized data require the
297
- historical owner's frozen decoder and are rejected by the live V12 parser where versioned.
417
+ Agent Protocol V13 defines the current source contract shared with `@agen-ai/agent-runtime`.
418
+ The coordinated eight-package `0.4.4` candidate is unpublished. Published `0.4.3` retains V12,
419
+ `0.4.1` retains V11 and `0.4.0` retains V10. Registry publication and dist-tag state are release
420
+ metadata outside this contract. Earlier public releases remain historical. The complete candidate
421
+ release inventory must use one coordinated source version. Optional `@agen-ai/agent-history`
422
+ browses native saved conversations independently of execution; it does not infer structured-output
423
+ support or validated values from native transcript JSON.
424
+
425
+ Protocol V13 is independent of private transport and product persistence versions and replaces
426
+ V12 at live boundaries. There is one current parser. V12 and older serialized data require the
427
+ historical owner's frozen decoder and are rejected by the live V13 parser where versioned.
298
428
  The environment and account-quota namespaces each retain their own schema version 1.
299
429
 
300
- The repository release proof builds and packs the exact seven-package release set, rejects
430
+ The repository release proof builds and packs the exact eight-package release set, rejects
301
431
  workspace-only or private references, then typechecks and runs a consumer outside the monorepo.
302
432
 
303
433
  From the public repository root, run `pnpm check` to execute the same packed-consumer proof.
@@ -1,3 +1,4 @@
1
+ import type { AgentStructuredOutputCapability } from '../structuredOutput/types.js';
1
2
  import type { AgentEnvironmentCapability } from '../environment/types.js';
2
3
  import type { AgentArtifactKind } from '../artifacts/index.js';
3
4
  import type { AgentCollaborationControlAction, AgentCollaborationRole } from '../collaboration/index.js';
@@ -154,7 +155,7 @@ export type AgentTurnSteeringCapability = Readonly<{
154
155
  input: AgentOperationInputCapability;
155
156
  }>;
156
157
  export interface AgentCapabilities {
157
- readonly protocolVersion: 12;
158
+ readonly protocolVersion: 13;
158
159
  readonly providerKey: AgentProviderKey;
159
160
  readonly sessions: Readonly<{
160
161
  create: true;
@@ -164,6 +165,7 @@ export interface AgentCapabilities {
164
165
  readonly turns: Readonly<{
165
166
  interactionModes: readonly AgentTurnInteractionMode[];
166
167
  interrupt: boolean;
168
+ structuredOutput: AgentStructuredOutputCapability;
167
169
  steer: AgentTurnSteeringCapability;
168
170
  }>;
169
171
  readonly requests: Readonly<{
@@ -8,7 +8,7 @@ import type { AgentContentStreamKind, AgentContextUsage, AgentDiffSummary, Agent
8
8
  export declare const AGENT_EVENT_TYPES: readonly ["turn.started", "turn.state_changed", "turn.completed", "item.started", "item.updated", "item.completed", "content.delta", "turn.plan.updated", "turn.plan.proposed", "turn.diff.updated", "request.opened", "request.unavailable", "progress.updated", "context.usage.updated", "artifact.referenced", "operation.updated", "collaboration.updated", "resource.updated", "runtime.retrying", "runtime.warning", "runtime.error", "provider.diagnostic"];
9
9
  export type AgentEventType = (typeof AGENT_EVENT_TYPES)[number];
10
10
  interface AgentEventBase<Type extends AgentEventType, Payload> {
11
- readonly protocolVersion: 12;
11
+ readonly protocolVersion: 13;
12
12
  readonly type: Type;
13
13
  readonly sessionId: AgentSessionId;
14
14
  readonly providerRefs?: AgentProviderRefs;
@@ -1,7 +1,7 @@
1
1
  export type { AgentProtocolParseFailure, AgentProtocolParseResult, AgentProtocolParseSuccess, ValidationIssue, ValidationPathSegment, } from './validation.js';
2
2
  export { AgentProtocolValidationError } from './validation.js';
3
3
  export type { AgentError, AgentErrorContext } from '../failures/types.js';
4
- export declare const AGENT_PROTOCOL_VERSION: 12;
4
+ export declare const AGENT_PROTOCOL_VERSION: 13;
5
5
  export declare const AGENT_PROTOCOL_ID_MAX_LENGTH = 256;
6
6
  export declare const AGENT_PROTOCOL_PROVIDER_REFERENCE_MAX_LENGTH = 512;
7
7
  export declare const AGENT_PROTOCOL_PROVIDER_KEY_MAX_LENGTH = 100;
@@ -55,6 +55,7 @@ export type AgentJsonPrimitive = string | number | boolean | null;
55
55
  export type AgentJsonValue = AgentJsonPrimitive | readonly AgentJsonValue[] | {
56
56
  readonly [key: string]: AgentJsonValue;
57
57
  };
58
+ export type AgentJsonObject = Readonly<Record<string, AgentJsonValue>>;
58
59
  export interface AgentProviderRefs {
59
60
  readonly conversationId?: AgentProviderConversationId;
60
61
  readonly historyAnchor?: AgentProviderHistoryAnchor;
@@ -1,5 +1,5 @@
1
1
  import { AgentProtocolValidationError } from "./validation.js";
2
- const AGENT_PROTOCOL_VERSION = 12;
2
+ const AGENT_PROTOCOL_VERSION = 13;
3
3
  const AGENT_PROTOCOL_ID_MAX_LENGTH = 256;
4
4
  const AGENT_PROTOCOL_PROVIDER_REFERENCE_MAX_LENGTH = 512;
5
5
  const AGENT_PROTOCOL_PROVIDER_KEY_MAX_LENGTH = 100;