@roll-agent/protocol 0.6.0 → 0.7.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/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod/v4";
2
+ import { appOutputDescriptorSchema, appOutputResultSchema } from "./app-output.js";
3
+ export * from "./app-output.js";
2
4
  export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V11 = ["1.1", "1.0"];
3
5
  export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V12 = [
4
6
  "1.2",
@@ -8,10 +10,14 @@ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V13 = [
8
10
  "1.3",
9
11
  ...SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V12,
10
12
  ];
11
- export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS = [
13
+ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V14 = [
12
14
  "1.4",
13
15
  ...SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V13,
14
16
  ];
17
+ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS = [
18
+ "1.5",
19
+ ...SUPPORTED_RUNTIME_PROTOCOL_VERSIONS_V14,
20
+ ];
15
21
  export const RUNTIME_PROTOCOL_VERSION = SUPPORTED_RUNTIME_PROTOCOL_VERSIONS[0];
16
22
  export const RUNTIME_EVENT_NOTIFICATION = "runtime.event";
17
23
  export const RUNTIME_SERVER_REQUEST_CANCEL_NOTIFICATION = "runtime.serverRequest.cancel";
@@ -83,6 +89,13 @@ export const USER_INPUT_CONTROL_TYPES = {
83
89
  choice: "choice",
84
90
  };
85
91
  export const RUNTIME_PROTOCOL_CAPABILITIES = {
92
+ "1.5": {
93
+ serverRequests: true,
94
+ serverRequestCapabilityNegotiation: true,
95
+ approvalResolvedEvents: true,
96
+ clientApprovalResponses: false,
97
+ requiredServerRequestMethods: [],
98
+ },
86
99
  "1.4": {
87
100
  serverRequests: true,
88
101
  serverRequestCapabilityNegotiation: true,
@@ -120,6 +133,7 @@ export const RUNTIME_PROTOCOL_CAPABILITIES = {
120
133
  },
121
134
  };
122
135
  export const REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION = {
136
+ "1.5": RUNTIME_PROTOCOL_CAPABILITIES["1.5"].requiredServerRequestMethods,
123
137
  "1.4": RUNTIME_PROTOCOL_CAPABILITIES["1.4"].requiredServerRequestMethods,
124
138
  "1.3": RUNTIME_PROTOCOL_CAPABILITIES["1.3"].requiredServerRequestMethods,
125
139
  "1.2": RUNTIME_PROTOCOL_CAPABILITIES["1.2"].requiredServerRequestMethods,
@@ -129,10 +143,24 @@ export const REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION = {
129
143
  export function getRuntimeProtocolCapabilities(version) {
130
144
  return RUNTIME_PROTOCOL_CAPABILITIES[version];
131
145
  }
146
+ const RUNTIME_SERVER_REQUEST_WIRE_SHAPES = {
147
+ interaction: "interaction",
148
+ legacy: "legacy",
149
+ };
150
+ function resolveRuntimeServerRequestWireShape(version) {
151
+ const capabilities = getRuntimeProtocolCapabilities(version);
152
+ if (!capabilities.serverRequests) {
153
+ return null;
154
+ }
155
+ return capabilities.serverRequestCapabilityNegotiation
156
+ ? RUNTIME_SERVER_REQUEST_WIRE_SHAPES.interaction
157
+ : RUNTIME_SERVER_REQUEST_WIRE_SHAPES.legacy;
158
+ }
132
159
  export function isRuntimeServerRequestMethodRequired(version, method) {
133
160
  return getRuntimeProtocolCapabilities(version).requiredServerRequestMethods.some((requiredMethod) => requiredMethod === method);
134
161
  }
135
162
  export const RUNTIME_METHODS = {
163
+ operationResultGet: "operation.result.get",
136
164
  initialize: "initialize",
137
165
  clientCapabilitiesSet: "client.capabilities.set",
138
166
  threadList: "thread.list",
@@ -164,7 +192,8 @@ export const RUNTIME_FEATURES_V13 = [
164
192
  "process-local-sequence",
165
193
  ];
166
194
  export const RUNTIME_FEATURES_V14 = [...RUNTIME_FEATURES_V13, "attachments"];
167
- export const RUNTIME_FEATURES = RUNTIME_FEATURES_V14;
195
+ export const RUNTIME_FEATURES_V15 = [...RUNTIME_FEATURES_V14, "app-output"];
196
+ export const RUNTIME_FEATURES = RUNTIME_FEATURES_V15;
168
197
  export const RUNTIME_ERROR_CODES_V11 = {
169
198
  protocolVersionUnsupported: "PROTOCOL_VERSION_UNSUPPORTED",
170
199
  initializeRequired: "INITIALIZE_REQUIRED",
@@ -419,8 +448,18 @@ export const initializeResultV14Schema = z
419
448
  })
420
449
  .strict()
421
450
  .readonly();
451
+ export const initializeResultV15Schema = z
452
+ .object({
453
+ protocolVersion: z.literal("1.5"),
454
+ ...initializeResultV14Fields,
455
+ features: z.array(z.enum(RUNTIME_FEATURES_V15)),
456
+ limits: runtimeLimitsV14Schema,
457
+ })
458
+ .strict()
459
+ .readonly();
422
460
  /** Any currently supported Runtime Protocol initialize result. */
423
461
  export const initializeResultSchema = z.union([
462
+ initializeResultV15Schema,
424
463
  initializeResultV14Schema,
425
464
  initializeResultV13Schema,
426
465
  initializeResultV12Schema,
@@ -530,7 +569,7 @@ export const toolOutcomeSchema = z
530
569
  })
531
570
  .strict()
532
571
  .readonly();
533
- export const operationViewSchema = z
572
+ const operationViewObjectSchema = z
534
573
  .object({
535
574
  id: operationIdSchema,
536
575
  sequence: z.number().int().nonnegative(),
@@ -541,7 +580,12 @@ export const operationViewSchema = z
541
580
  outcome: toolOutcomeSchema,
542
581
  display: jsonValueSchema,
543
582
  })
544
- .strict()
583
+ .strict();
584
+ export const operationViewSchema = operationViewObjectSchema.readonly();
585
+ export const operationViewV15Schema = operationViewObjectSchema
586
+ .extend({
587
+ appOutput: appOutputDescriptorSchema,
588
+ })
545
589
  .readonly();
546
590
  export const activeTurnV11Schema = z
547
591
  .object({
@@ -586,13 +630,13 @@ export const messagePageV14Schema = z
586
630
  })
587
631
  .strict()
588
632
  .readonly();
589
- export const operationPageSchema = z
633
+ const operationPageObjectSchema = z
590
634
  .object({
591
635
  items: z.array(operationViewSchema),
592
636
  nextBeforeSequence: z.number().int().nonnegative().nullable(),
593
637
  })
594
- .strict()
595
- .readonly();
638
+ .strict();
639
+ export const operationPageSchema = operationPageObjectSchema.readonly();
596
640
  const threadSnapshotV11Fields = {
597
641
  thread: threadSummarySchema,
598
642
  messages: messagePageSchema,
@@ -922,20 +966,31 @@ export const threadSnapshotV13Schema = z.union([
922
966
  threadSnapshotV13FullSchema,
923
967
  threadRecoverySnapshotV13Schema,
924
968
  ]);
925
- export const threadSnapshotV14FullSchema = z
969
+ const threadSnapshotV14FullObjectSchema = z
926
970
  .object({
927
971
  ...threadSnapshotV12Fields,
928
972
  messages: messagePageV14Schema,
929
973
  eventCursor: runtimeEventCursorSchema.nullable(),
930
974
  })
931
- .strict()
932
- .readonly();
975
+ .strict();
976
+ export const threadSnapshotV14FullSchema = threadSnapshotV14FullObjectSchema.readonly();
933
977
  export const threadSnapshotV14Schema = z.union([
934
978
  threadSnapshotV14FullSchema,
935
979
  threadRecoverySnapshotV13Schema,
936
980
  ]);
937
981
  /** Latest Runtime Protocol snapshot. Use versioned schemas for compatibility. */
938
- export const threadSnapshotSchema = threadSnapshotV14Schema;
982
+ export const threadSnapshotV15FullSchema = threadSnapshotV14FullObjectSchema
983
+ .extend({
984
+ operations: operationPageObjectSchema
985
+ .extend({ items: z.array(operationViewV15Schema) })
986
+ .readonly(),
987
+ })
988
+ .readonly();
989
+ export const threadSnapshotV15Schema = z.union([
990
+ threadSnapshotV15FullSchema,
991
+ threadRecoverySnapshotV13Schema,
992
+ ]);
993
+ export const threadSnapshotSchema = threadSnapshotV15Schema;
939
994
  const pageSizeSchema = z.number().int().min(1).max(500).default(100);
940
995
  const requestFields = { requestId: requestIdSchema };
941
996
  const threadRequestFields = { threadId: threadIdSchema };
@@ -1293,6 +1348,26 @@ export const operationGetResultSchema = z
1293
1348
  })
1294
1349
  .strict()
1295
1350
  .readonly();
1351
+ export const operationResultGetParamsSchema = operationGetParamsSchema;
1352
+ export const operationResultViewSchema = z
1353
+ .object({
1354
+ threadId: threadIdSchema,
1355
+ operationId: operationIdSchema,
1356
+ agentName: z.string().min(1),
1357
+ toolName: z.string().min(1),
1358
+ createdAt: timestampSchema,
1359
+ output: appOutputResultSchema,
1360
+ })
1361
+ .strict()
1362
+ .readonly();
1363
+ export const operationResultGetResultSchema = z
1364
+ .object({ result: operationResultViewSchema.nullable() })
1365
+ .strict()
1366
+ .readonly();
1367
+ export const operationGetResultV15Schema = z
1368
+ .object({ operation: operationViewV15Schema.nullable() })
1369
+ .strict()
1370
+ .readonly();
1296
1371
  export const approvalResolutionSchema = z.union([
1297
1372
  z
1298
1373
  .object({
@@ -1369,7 +1444,7 @@ const toolOutputEventSchema = z
1369
1444
  })
1370
1445
  .strict()
1371
1446
  .readonly();
1372
- const toolCompletedEventSchema = z
1447
+ const toolCompletedEventObjectSchema = z
1373
1448
  .object({
1374
1449
  type: z.literal("tool.completed"),
1375
1450
  toolCallId: z.string().min(1),
@@ -1379,8 +1454,8 @@ const toolCompletedEventSchema = z
1379
1454
  outcome: toolOutcomeSchema.optional(),
1380
1455
  display: jsonValueSchema,
1381
1456
  })
1382
- .strict()
1383
- .readonly();
1457
+ .strict();
1458
+ const toolCompletedEventSchema = toolCompletedEventObjectSchema.readonly();
1384
1459
  const approvalRequiredEventSchema = z
1385
1460
  .object({ type: z.literal("approval.required"), approval: pendingApprovalSchema })
1386
1461
  .strict()
@@ -1452,8 +1527,26 @@ export const runtimeEphemeralEventV13Schema = z.discriminatedUnion("type", [
1452
1527
  export const runtimeEventV12Schema = runtimeEventV11Schema;
1453
1528
  /** Runtime Protocol 1.3 retains the event payload registry and versions durability in the envelope. */
1454
1529
  export const runtimeEventV13Schema = runtimeEventV12Schema;
1530
+ export const toolCompletedEventV15Schema = toolCompletedEventObjectSchema
1531
+ .extend({ appOutput: appOutputDescriptorSchema.default({ status: "not_provided" }) })
1532
+ .readonly();
1533
+ export const runtimeDurableEventV15Schema = z.discriminatedUnion("type", [
1534
+ turnStartedEventSchema,
1535
+ messageCompletedEventSchema,
1536
+ toolCompletedEventV15Schema,
1537
+ approvalRequiredEventSchema,
1538
+ approvalResolvedEventSchema,
1539
+ turnCompletedEventSchema,
1540
+ turnCancelledEventSchema,
1541
+ turnFailedEventSchema,
1542
+ capabilitiesChangedEventSchema,
1543
+ ]);
1544
+ export const runtimeEventV15Schema = z.union([
1545
+ runtimeDurableEventV15Schema,
1546
+ runtimeEphemeralEventV13Schema,
1547
+ ]);
1455
1548
  /** Latest Runtime Protocol event payloads. */
1456
- export const runtimeEventSchema = runtimeEventV13Schema;
1549
+ export const runtimeEventSchema = runtimeEventV15Schema;
1457
1550
  const runtimeEventEnvelopeFields = {
1458
1551
  runtimeInstanceId: runtimeInstanceIdSchema,
1459
1552
  sequence: z.number().int().nonnegative(),
@@ -1543,8 +1636,35 @@ export const runtimeEventEnvelopeV14Schema = z.discriminatedUnion("durability",
1543
1636
  runtimeDurableEventEnvelopeV14Schema,
1544
1637
  runtimeEphemeralEventEnvelopeV14Schema,
1545
1638
  ]);
1639
+ export const runtimeDurableEventEnvelopeV15Schema = z
1640
+ .object({
1641
+ protocolVersion: z.literal("1.5"),
1642
+ ...runtimeEventEnvelopeFields,
1643
+ durability: z.literal("durable"),
1644
+ eventId: runtimeEventIdSchema,
1645
+ cursor: runtimeEventCursorSchema,
1646
+ event: runtimeDurableEventV15Schema,
1647
+ })
1648
+ .strict()
1649
+ .superRefine(validateRuntimeEventCapabilities)
1650
+ .readonly();
1651
+ export const runtimeEphemeralEventEnvelopeV15Schema = z
1652
+ .object({
1653
+ protocolVersion: z.literal("1.5"),
1654
+ ...runtimeEventEnvelopeFields,
1655
+ durability: z.literal("ephemeral"),
1656
+ event: runtimeEphemeralEventV13Schema,
1657
+ })
1658
+ .strict()
1659
+ .superRefine(validateRuntimeEventCapabilities)
1660
+ .readonly();
1661
+ export const runtimeEventEnvelopeV15Schema = z.discriminatedUnion("durability", [
1662
+ runtimeDurableEventEnvelopeV15Schema,
1663
+ runtimeEphemeralEventEnvelopeV15Schema,
1664
+ ]);
1546
1665
  /** Any currently supported Runtime Event envelope. */
1547
1666
  export const runtimeEventEnvelopeSchema = z.union([
1667
+ runtimeEventEnvelopeV15Schema,
1548
1668
  runtimeEventEnvelopeV14Schema,
1549
1669
  runtimeEventEnvelopeV13Schema,
1550
1670
  runtimeEventEnvelopeV12Schema,
@@ -1713,7 +1833,27 @@ export const runtimeMethodSchemasV14 = {
1713
1833
  },
1714
1834
  };
1715
1835
  /** Latest Runtime method registry. Use the version registry for negotiated availability. */
1716
- export const runtimeMethodSchemas = runtimeMethodSchemasV14;
1836
+ export const runtimeMethodSchemasV15 = {
1837
+ ...runtimeMethodSchemasV14,
1838
+ [RUNTIME_METHODS.initialize]: {
1839
+ params: initializeParamsSchema,
1840
+ result: initializeResultV15Schema,
1841
+ },
1842
+ [RUNTIME_METHODS.threadOpen]: { params: threadOpenParamsSchema, result: threadSnapshotV15Schema },
1843
+ [RUNTIME_METHODS.threadSnapshot]: {
1844
+ params: threadSnapshotParamsV13Schema,
1845
+ result: threadSnapshotV15Schema,
1846
+ },
1847
+ [RUNTIME_METHODS.operationGet]: {
1848
+ params: operationGetParamsSchema,
1849
+ result: operationGetResultV15Schema,
1850
+ },
1851
+ [RUNTIME_METHODS.operationResultGet]: {
1852
+ params: operationResultGetParamsSchema,
1853
+ result: operationResultGetResultSchema,
1854
+ },
1855
+ };
1856
+ export const runtimeMethodSchemas = runtimeMethodSchemasV15;
1717
1857
  export const runtimeServerRequestSchemasV10 = {};
1718
1858
  export const runtimeServerRequestSchemasV11 = {
1719
1859
  [RUNTIME_SERVER_REQUEST_METHODS.approvalRequest]: {
@@ -1735,6 +1875,14 @@ export const runtimeServerRequestSchemasV13 = runtimeServerRequestSchemasV12;
1735
1875
  /** Protocol 1.1 compatibility facade. Prefer the version registry in new code. */
1736
1876
  export const runtimeServerRequestSchemas = runtimeServerRequestSchemasV11;
1737
1877
  export const RUNTIME_PROTOCOL_REGISTRY = {
1878
+ "1.5": {
1879
+ methods: runtimeMethodSchemasV15,
1880
+ serverRequests: runtimeServerRequestSchemasV13,
1881
+ serverRequestMethods: RUNTIME_SERVER_REQUEST_METHOD_VALUES,
1882
+ serverRequestCancelParamsSchema: runtimeServerRequestCancelParamsV12Schema,
1883
+ eventEnvelopeSchema: runtimeEventEnvelopeV15Schema,
1884
+ errorDataSchema: runtimeProtocolErrorDataV14Schema,
1885
+ },
1738
1886
  "1.4": {
1739
1887
  methods: runtimeMethodSchemasV14,
1740
1888
  serverRequests: runtimeServerRequestSchemasV13,
@@ -2002,8 +2150,36 @@ function projectUiMessagePageToTextParts(page) {
2002
2150
  nextBeforeSequence: page.nextBeforeSequence,
2003
2151
  };
2004
2152
  }
2153
+ export function projectOperationViewForVersion(version, value) {
2154
+ const current = operationViewV15Schema.safeParse(value);
2155
+ if (version === "1.5") {
2156
+ return current.success
2157
+ ? current.data
2158
+ : operationViewV15Schema.parse({
2159
+ ...operationViewSchema.parse(value),
2160
+ appOutput: { status: "not_provided" },
2161
+ });
2162
+ }
2163
+ if (!current.success)
2164
+ return operationViewSchema.parse(value);
2165
+ const { appOutput: _appOutput, ...legacy } = current.data;
2166
+ return operationViewSchema.parse(legacy);
2167
+ }
2005
2168
  export function projectThreadSnapshotForVersion(version, value) {
2006
- const latestV14 = threadSnapshotV14Schema.safeParse(value);
2169
+ const latestV15 = threadSnapshotV15Schema.safeParse(value);
2170
+ if (version === "1.5") {
2171
+ return threadSnapshotV15Schema.parse(value);
2172
+ }
2173
+ const legacyValue = latestV15.success && !("recoveryProjection" in latestV15.data)
2174
+ ? {
2175
+ ...latestV15.data,
2176
+ operations: {
2177
+ ...latestV15.data.operations,
2178
+ items: latestV15.data.operations.items.map((op) => projectOperationViewForVersion("1.4", op)),
2179
+ },
2180
+ }
2181
+ : value;
2182
+ const latestV14 = threadSnapshotV14Schema.safeParse(legacyValue);
2007
2183
  if (version === "1.4") {
2008
2184
  if (!latestV14.success) {
2009
2185
  throw latestV14.error;
@@ -2015,7 +2191,7 @@ export function projectThreadSnapshotForVersion(version, value) {
2015
2191
  ...latestV14.data,
2016
2192
  messages: projectUiMessagePageToTextParts(latestV14.data.messages),
2017
2193
  }
2018
- : value;
2194
+ : legacyValue;
2019
2195
  const latest = threadSnapshotV13Schema.safeParse(v13Candidate);
2020
2196
  if (version === "1.3") {
2021
2197
  if (!latest.success) {
@@ -2054,7 +2230,27 @@ export function projectThreadSnapshotForVersion(version, value) {
2054
2230
  });
2055
2231
  }
2056
2232
  export function projectRuntimeEventEnvelopeForVersion(version, value) {
2057
- const source = runtimeEventEnvelopeSchema.parse(value);
2233
+ const parsedSource = runtimeEventEnvelopeSchema.parse(value);
2234
+ if (version === "1.5") {
2235
+ return runtimeEventEnvelopeV15Schema.parse({
2236
+ ...parsedSource,
2237
+ protocolVersion: version,
2238
+ event: parsedSource.event.type === "tool.completed"
2239
+ ? {
2240
+ ...parsedSource.event,
2241
+ appOutput: "appOutput" in parsedSource.event
2242
+ ? parsedSource.event.appOutput
2243
+ : { status: "not_provided" },
2244
+ }
2245
+ : parsedSource.event,
2246
+ });
2247
+ }
2248
+ const source = {
2249
+ ...parsedSource,
2250
+ event: runtimeEventV13Schema.parse(parsedSource.event.type === "tool.completed" && "appOutput" in parsedSource.event
2251
+ ? (({ appOutput: _appOutput, ...rest }) => rest)(parsedSource.event)
2252
+ : parsedSource.event),
2253
+ };
2058
2254
  if (version === "1.4") {
2059
2255
  return runtimeEventEnvelopeV14Schema.parse({
2060
2256
  ...source,
@@ -2121,10 +2317,12 @@ export function parseRuntimeProtocolErrorDataForVersion(version, value) {
2121
2317
  }
2122
2318
  export function projectRuntimeServerRequestParams(version, method, value) {
2123
2319
  const latest = parseRuntimeServerRequestParamsForVersion("1.3", method, value);
2124
- if (version === "1.3" || version === "1.2") {
2320
+ const shape = resolveRuntimeServerRequestWireShape(version);
2321
+ if (shape === RUNTIME_SERVER_REQUEST_WIRE_SHAPES.interaction) {
2125
2322
  return latest;
2126
2323
  }
2127
- if (version === "1.1" && method === RUNTIME_SERVER_REQUEST_METHODS.approvalRequest) {
2324
+ if (shape === RUNTIME_SERVER_REQUEST_WIRE_SHAPES.legacy &&
2325
+ method === RUNTIME_SERVER_REQUEST_METHODS.approvalRequest) {
2128
2326
  const approval = approvalRequestParamsV12Schema.parse(latest);
2129
2327
  return approvalRequestParamsV11Schema.parse({
2130
2328
  threadId: approval.threadId,
@@ -2136,13 +2334,14 @@ export function projectRuntimeServerRequestParams(version, method, value) {
2136
2334
  }
2137
2335
  export function projectRuntimeServerRequestCancelParams(version, value) {
2138
2336
  const input = runtimeServerRequestCancelProjectionInputSchema.parse(value);
2139
- if (version === "1.3" || version === "1.2") {
2337
+ const shape = resolveRuntimeServerRequestWireShape(version);
2338
+ if (shape === RUNTIME_SERVER_REQUEST_WIRE_SHAPES.interaction) {
2140
2339
  return runtimeServerRequestCancelParamsV12Schema.parse({
2141
2340
  interactionId: input.interactionId,
2142
2341
  reason: input.reason,
2143
2342
  });
2144
2343
  }
2145
- if (version === "1.1") {
2344
+ if (shape === RUNTIME_SERVER_REQUEST_WIRE_SHAPES.legacy) {
2146
2345
  return runtimeServerRequestCancelParamsV11Schema.parse({
2147
2346
  serverRequestId: input.serverRequestId,
2148
2347
  ...(input.approvalId === undefined ? {} : { approvalId: input.approvalId }),