@roll-agent/protocol 0.6.1 → 0.8.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,
@@ -146,6 +160,7 @@ export function isRuntimeServerRequestMethodRequired(version, method) {
146
160
  return getRuntimeProtocolCapabilities(version).requiredServerRequestMethods.some((requiredMethod) => requiredMethod === method);
147
161
  }
148
162
  export const RUNTIME_METHODS = {
163
+ operationResultGet: "operation.result.get",
149
164
  initialize: "initialize",
150
165
  clientCapabilitiesSet: "client.capabilities.set",
151
166
  threadList: "thread.list",
@@ -177,7 +192,8 @@ export const RUNTIME_FEATURES_V13 = [
177
192
  "process-local-sequence",
178
193
  ];
179
194
  export const RUNTIME_FEATURES_V14 = [...RUNTIME_FEATURES_V13, "attachments"];
180
- 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;
181
197
  export const RUNTIME_ERROR_CODES_V11 = {
182
198
  protocolVersionUnsupported: "PROTOCOL_VERSION_UNSUPPORTED",
183
199
  initializeRequired: "INITIALIZE_REQUIRED",
@@ -432,8 +448,18 @@ export const initializeResultV14Schema = z
432
448
  })
433
449
  .strict()
434
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();
435
460
  /** Any currently supported Runtime Protocol initialize result. */
436
461
  export const initializeResultSchema = z.union([
462
+ initializeResultV15Schema,
437
463
  initializeResultV14Schema,
438
464
  initializeResultV13Schema,
439
465
  initializeResultV12Schema,
@@ -543,7 +569,7 @@ export const toolOutcomeSchema = z
543
569
  })
544
570
  .strict()
545
571
  .readonly();
546
- export const operationViewSchema = z
572
+ const operationViewObjectSchema = z
547
573
  .object({
548
574
  id: operationIdSchema,
549
575
  sequence: z.number().int().nonnegative(),
@@ -554,7 +580,12 @@ export const operationViewSchema = z
554
580
  outcome: toolOutcomeSchema,
555
581
  display: jsonValueSchema,
556
582
  })
557
- .strict()
583
+ .strict();
584
+ export const operationViewSchema = operationViewObjectSchema.readonly();
585
+ export const operationViewV15Schema = operationViewObjectSchema
586
+ .extend({
587
+ appOutput: appOutputDescriptorSchema,
588
+ })
558
589
  .readonly();
559
590
  export const activeTurnV11Schema = z
560
591
  .object({
@@ -599,13 +630,13 @@ export const messagePageV14Schema = z
599
630
  })
600
631
  .strict()
601
632
  .readonly();
602
- export const operationPageSchema = z
633
+ const operationPageObjectSchema = z
603
634
  .object({
604
635
  items: z.array(operationViewSchema),
605
636
  nextBeforeSequence: z.number().int().nonnegative().nullable(),
606
637
  })
607
- .strict()
608
- .readonly();
638
+ .strict();
639
+ export const operationPageSchema = operationPageObjectSchema.readonly();
609
640
  const threadSnapshotV11Fields = {
610
641
  thread: threadSummarySchema,
611
642
  messages: messagePageSchema,
@@ -935,20 +966,31 @@ export const threadSnapshotV13Schema = z.union([
935
966
  threadSnapshotV13FullSchema,
936
967
  threadRecoverySnapshotV13Schema,
937
968
  ]);
938
- export const threadSnapshotV14FullSchema = z
969
+ const threadSnapshotV14FullObjectSchema = z
939
970
  .object({
940
971
  ...threadSnapshotV12Fields,
941
972
  messages: messagePageV14Schema,
942
973
  eventCursor: runtimeEventCursorSchema.nullable(),
943
974
  })
944
- .strict()
945
- .readonly();
975
+ .strict();
976
+ export const threadSnapshotV14FullSchema = threadSnapshotV14FullObjectSchema.readonly();
946
977
  export const threadSnapshotV14Schema = z.union([
947
978
  threadSnapshotV14FullSchema,
948
979
  threadRecoverySnapshotV13Schema,
949
980
  ]);
950
981
  /** Latest Runtime Protocol snapshot. Use versioned schemas for compatibility. */
951
- 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;
952
994
  const pageSizeSchema = z.number().int().min(1).max(500).default(100);
953
995
  const requestFields = { requestId: requestIdSchema };
954
996
  const threadRequestFields = { threadId: threadIdSchema };
@@ -1306,6 +1348,26 @@ export const operationGetResultSchema = z
1306
1348
  })
1307
1349
  .strict()
1308
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();
1309
1371
  export const approvalResolutionSchema = z.union([
1310
1372
  z
1311
1373
  .object({
@@ -1382,7 +1444,7 @@ const toolOutputEventSchema = z
1382
1444
  })
1383
1445
  .strict()
1384
1446
  .readonly();
1385
- const toolCompletedEventSchema = z
1447
+ const toolCompletedEventObjectSchema = z
1386
1448
  .object({
1387
1449
  type: z.literal("tool.completed"),
1388
1450
  toolCallId: z.string().min(1),
@@ -1392,8 +1454,8 @@ const toolCompletedEventSchema = z
1392
1454
  outcome: toolOutcomeSchema.optional(),
1393
1455
  display: jsonValueSchema,
1394
1456
  })
1395
- .strict()
1396
- .readonly();
1457
+ .strict();
1458
+ const toolCompletedEventSchema = toolCompletedEventObjectSchema.readonly();
1397
1459
  const approvalRequiredEventSchema = z
1398
1460
  .object({ type: z.literal("approval.required"), approval: pendingApprovalSchema })
1399
1461
  .strict()
@@ -1465,8 +1527,26 @@ export const runtimeEphemeralEventV13Schema = z.discriminatedUnion("type", [
1465
1527
  export const runtimeEventV12Schema = runtimeEventV11Schema;
1466
1528
  /** Runtime Protocol 1.3 retains the event payload registry and versions durability in the envelope. */
1467
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
+ ]);
1468
1548
  /** Latest Runtime Protocol event payloads. */
1469
- export const runtimeEventSchema = runtimeEventV13Schema;
1549
+ export const runtimeEventSchema = runtimeEventV15Schema;
1470
1550
  const runtimeEventEnvelopeFields = {
1471
1551
  runtimeInstanceId: runtimeInstanceIdSchema,
1472
1552
  sequence: z.number().int().nonnegative(),
@@ -1556,8 +1636,35 @@ export const runtimeEventEnvelopeV14Schema = z.discriminatedUnion("durability",
1556
1636
  runtimeDurableEventEnvelopeV14Schema,
1557
1637
  runtimeEphemeralEventEnvelopeV14Schema,
1558
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
+ ]);
1559
1665
  /** Any currently supported Runtime Event envelope. */
1560
1666
  export const runtimeEventEnvelopeSchema = z.union([
1667
+ runtimeEventEnvelopeV15Schema,
1561
1668
  runtimeEventEnvelopeV14Schema,
1562
1669
  runtimeEventEnvelopeV13Schema,
1563
1670
  runtimeEventEnvelopeV12Schema,
@@ -1726,7 +1833,27 @@ export const runtimeMethodSchemasV14 = {
1726
1833
  },
1727
1834
  };
1728
1835
  /** Latest Runtime method registry. Use the version registry for negotiated availability. */
1729
- 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;
1730
1857
  export const runtimeServerRequestSchemasV10 = {};
1731
1858
  export const runtimeServerRequestSchemasV11 = {
1732
1859
  [RUNTIME_SERVER_REQUEST_METHODS.approvalRequest]: {
@@ -1748,6 +1875,14 @@ export const runtimeServerRequestSchemasV13 = runtimeServerRequestSchemasV12;
1748
1875
  /** Protocol 1.1 compatibility facade. Prefer the version registry in new code. */
1749
1876
  export const runtimeServerRequestSchemas = runtimeServerRequestSchemasV11;
1750
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
+ },
1751
1886
  "1.4": {
1752
1887
  methods: runtimeMethodSchemasV14,
1753
1888
  serverRequests: runtimeServerRequestSchemasV13,
@@ -2015,8 +2150,36 @@ function projectUiMessagePageToTextParts(page) {
2015
2150
  nextBeforeSequence: page.nextBeforeSequence,
2016
2151
  };
2017
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
+ }
2018
2168
  export function projectThreadSnapshotForVersion(version, value) {
2019
- 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);
2020
2183
  if (version === "1.4") {
2021
2184
  if (!latestV14.success) {
2022
2185
  throw latestV14.error;
@@ -2028,7 +2191,7 @@ export function projectThreadSnapshotForVersion(version, value) {
2028
2191
  ...latestV14.data,
2029
2192
  messages: projectUiMessagePageToTextParts(latestV14.data.messages),
2030
2193
  }
2031
- : value;
2194
+ : legacyValue;
2032
2195
  const latest = threadSnapshotV13Schema.safeParse(v13Candidate);
2033
2196
  if (version === "1.3") {
2034
2197
  if (!latest.success) {
@@ -2067,7 +2230,27 @@ export function projectThreadSnapshotForVersion(version, value) {
2067
2230
  });
2068
2231
  }
2069
2232
  export function projectRuntimeEventEnvelopeForVersion(version, value) {
2070
- 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
+ };
2071
2254
  if (version === "1.4") {
2072
2255
  return runtimeEventEnvelopeV14Schema.parse({
2073
2256
  ...source,
@@ -2173,3 +2356,4 @@ export function parseRuntimeServerRequestParams(method, value) {
2173
2356
  export function parseRuntimeServerRequestResult(method, value) {
2174
2357
  return runtimeServerRequestSchemas[method].result.parse(value);
2175
2358
  }
2359
+ export { OBSERVATION_RETENTION_META_KEY, observationRetentionDeclarationSchema, } from "./observation-retention.js";
@@ -0,0 +1,7 @@
1
+ import { z } from "zod/v4";
2
+ /** MCP metadata for tools whose successful results are replaceable observations. */
3
+ export declare const OBSERVATION_RETENTION_META_KEY = "roll/observationRetention";
4
+ export declare const observationRetentionDeclarationSchema: z.ZodObject<{
5
+ kind: z.ZodLiteral<"browser-ax-snapshot">;
6
+ }, z.core.$strict>;
7
+ export type ObservationRetentionDeclaration = z.infer<typeof observationRetentionDeclarationSchema>;
@@ -0,0 +1,6 @@
1
+ import { z } from "zod/v4";
2
+ /** MCP metadata for tools whose successful results are replaceable observations. */
3
+ export const OBSERVATION_RETENTION_META_KEY = "roll/observationRetention";
4
+ export const observationRetentionDeclarationSchema = z
5
+ .object({ kind: z.literal("browser-ax-snapshot") })
6
+ .strict();