@roll-agent/relay-protocol 0.4.2 → 0.5.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.
Files changed (35) hide show
  1. package/README.md +4 -0
  2. package/dist/control.d.ts +31 -0
  3. package/dist/control.js +6 -0
  4. package/dist/index.d.ts +1893 -2
  5. package/dist/index.js +92 -2
  6. package/dist/schema/roll-relay-protocol-v1.3.schema.json +4606 -0
  7. package/fixtures/v1.3/invalid-approval-projection-raw-input-leak.json +19 -0
  8. package/fixtures/v1.3/invalid-authentication-local-only.json +12 -0
  9. package/fixtures/v1.3/invalid-context-recovery-notes.json +22 -0
  10. package/fixtures/v1.3/invalid-file-picker-local-only.json +12 -0
  11. package/fixtures/v1.3/invalid-interaction-cancelled-reason-leak.json +10 -0
  12. package/fixtures/v1.3/invalid-interaction-resolved-result-leak.json +18 -0
  13. package/fixtures/v1.3/invalid-legacy-approval-candidate.json +7 -0
  14. package/fixtures/v1.3/invalid-legacy-approval-respond.json +7 -0
  15. package/fixtures/v1.3/invalid-n-minus-one-device-connect.json +6 -0
  16. package/fixtures/v1.3/invalid-non-normal-sensitivity.json +21 -0
  17. package/fixtures/v1.3/invalid-runtime-event-tool-input-leak.json +22 -0
  18. package/fixtures/v1.3/invalid-runtime-event-tool-output-leak.json +21 -0
  19. package/fixtures/v1.3/invalid-user-input-projection-secret-leak.json +22 -0
  20. package/fixtures/v1.3/manifest.json +489 -0
  21. package/fixtures/v1.3/valid-context-recovery.json +21 -0
  22. package/fixtures/v1.3/valid-device-connect.json +6 -0
  23. package/fixtures/v1.3/valid-interaction-cancelled.json +9 -0
  24. package/fixtures/v1.3/valid-interaction-candidate-user-input.json +25 -0
  25. package/fixtures/v1.3/valid-interaction-request-approval.json +17 -0
  26. package/fixtures/v1.3/valid-interaction-request-user-input.json +40 -0
  27. package/fixtures/v1.3/valid-interaction-resolved.json +9 -0
  28. package/fixtures/v1.3/valid-runtime-ack.json +5 -0
  29. package/fixtures/v1.3/valid-runtime-encrypted-interaction.json +10 -0
  30. package/fixtures/v1.3/valid-runtime-event-runtime-n-minus-one.json +16 -0
  31. package/fixtures/v1.3/valid-runtime-event.json +16 -0
  32. package/fixtures/v1.3/valid-runtime-gap.json +7 -0
  33. package/fixtures/v1.3/valid-runtime-request.json +10 -0
  34. package/fixtures/v1.3/valid-runtime-response.json +8 -0
  35. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { RUNTIME_SERVER_REQUEST_METHODS, TOOL_OUTCOME_KINDS, approvalIdSchema, approvalExplanationSchema, approvalRequestResultSchema, getApprovalExplanation, interactionIdSchema, jsonValueSchema, normalizeUserInputResult, operationGetResultSchema, operationViewV15Schema, operationIdSchema, operationResultGetParamsSchema, operationResultGetResultSchema, appOutputDescriptorSchema, runtimeMethodSchemasV15, operationViewSchema, pendingApprovalSchema, projectThreadSnapshotForVersion, runtimeEventEnvelopeSchema, runtimeEventEnvelopeV11Schema, runtimeMethodSchemasV11, runtimeInstanceIdSchema, streamIdSchema, threadIdSchema, threadSnapshotV11Schema, timestampSchema, turnIdSchema, userInputFormSchema, userInputResultSchema, } from "@roll-agent/protocol";
1
+ import { contextRecoveryViewSchema, contextRecoveryChangedEventSchema, RUNTIME_SERVER_REQUEST_METHODS, TOOL_OUTCOME_KINDS, approvalIdSchema, approvalExplanationSchema, approvalRequestResultSchema, getApprovalExplanation, interactionIdSchema, jsonValueSchema, normalizeUserInputResult, operationGetResultSchema, operationViewV15Schema, operationIdSchema, operationResultGetParamsSchema, operationResultGetResultSchema, appOutputDescriptorSchema, runtimeMethodSchemasV15, operationViewSchema, pendingApprovalSchema, projectThreadSnapshotForVersion, runtimeEventEnvelopeSchema, runtimeEventEnvelopeV11Schema, runtimeMethodSchemasV11, runtimeInstanceIdSchema, streamIdSchema, threadIdSchema, threadSnapshotV11Schema, timestampSchema, turnIdSchema, userInputFormSchema, userInputResultSchema, } from "@roll-agent/protocol";
2
2
  import { z } from "zod/v4";
3
- export const SUPPORTED_RELAY_PROTOCOL_VERSIONS = ["1.2", "1.1", "1.0"];
3
+ export const SUPPORTED_RELAY_PROTOCOL_VERSIONS = ["1.3", "1.2", "1.1", "1.0"];
4
4
  export const LATEST_RELAY_PROTOCOL_VERSION = SUPPORTED_RELAY_PROTOCOL_VERSIONS[0];
5
5
  /** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
6
6
  export const RELAY_PROTOCOL_VERSION = "1.0";
@@ -547,6 +547,8 @@ export const relayRuntimeEventEnvelopeSchemaV11 = z
547
547
  .strict()
548
548
  .readonly();
549
549
  function projectRelayTimelineEventV11(event) {
550
+ if (event.type === "context.recovery.changed")
551
+ return { type: "capabilities.changed" };
550
552
  if (event.type === "tool.output") {
551
553
  return undefined;
552
554
  }
@@ -637,6 +639,9 @@ function redactRelayPendingApprovalV11(approval) {
637
639
  }
638
640
  /** Projects a Runtime snapshot into the allowlisted Relay Wire 1.1 query shape. */
639
641
  export function projectRelayThreadSnapshotV11(value) {
642
+ if (typeof value === "object" && value !== null && "contextRecovery" in value) {
643
+ value = Object.fromEntries(Object.entries(value).filter(([key]) => key !== "contextRecovery"));
644
+ }
640
645
  const legacySnapshot = z
641
646
  .union([threadSnapshotV11Schema, relayThreadSnapshotSchemaV12])
642
647
  .safeParse(value);
@@ -956,7 +961,92 @@ export function projectRelayMessageV12ToV11(message) {
956
961
  }
957
962
  return relayMessageSchemaV11.parse(message);
958
963
  }
964
+ /** Wire 1.3 carries bounded context recovery state; older wire contracts stay frozen. */
965
+ export const relayThreadSnapshotSchemaV13 = relayThreadSnapshotSchemaV12.def.innerType
966
+ .extend({
967
+ contextRecovery: contextRecoveryViewSchema.nullable(),
968
+ })
969
+ .readonly();
970
+ export const relayRequestMethodSchemasV13 = {
971
+ ...relayRequestMethodSchemasV12,
972
+ "thread.open": {
973
+ ...relayRequestMethodSchemasV12["thread.open"],
974
+ result: relayThreadSnapshotSchemaV13,
975
+ },
976
+ "thread.snapshot": {
977
+ ...relayRequestMethodSchemasV12["thread.snapshot"],
978
+ result: relayThreadSnapshotSchemaV13,
979
+ },
980
+ };
981
+ export const relayRuntimeEventEnvelopeSchemaV13 = relayRuntimeEventEnvelopeSchemaV12.def.innerType
982
+ .extend({
983
+ event: z.union([
984
+ relayTimelineEventSchemaV11,
985
+ relayToolCompletedSchemaV12,
986
+ contextRecoveryChangedEventSchema,
987
+ ]),
988
+ })
989
+ .readonly();
990
+ export const relayDeviceConnectSchemaV13 = relayDeviceConnectSchemaV12.def.innerType
991
+ .extend({ protocolVersion: z.literal("1.3") })
992
+ .readonly();
993
+ export const relayRuntimeEventSchemaV13 = relayRuntimeEventSchemaV12.def.innerType
994
+ .extend({ event: relayRuntimeEventEnvelopeSchemaV13 })
995
+ .readonly();
996
+ export const relayMessageSchemaV13 = z.discriminatedUnion("type", [
997
+ relayDeviceConnectSchemaV13,
998
+ relayRuntimeRequestSchemaV12,
999
+ relayRuntimeResponseSchemaV11,
1000
+ relayRuntimeEventSchemaV13,
1001
+ relayAckSchemaV11,
1002
+ relayGapSchemaV11,
1003
+ relayEncryptedMessageSchemaV11,
1004
+ relayInteractionRequestSchemaV11,
1005
+ relayInteractionResolvedSchemaV11,
1006
+ relayInteractionCancelledSchemaV11,
1007
+ ]);
1008
+ export function projectRelayThreadSnapshotV13(value) {
1009
+ const source = z
1010
+ .object({ contextRecovery: contextRecoveryViewSchema.nullable().optional() })
1011
+ .parse(value);
1012
+ // Strip the extension before using the frozen 1.2 redaction pipeline.
1013
+ const legacySource = typeof value === "object" && value !== null
1014
+ ? Object.fromEntries(Object.entries(value).filter(([key]) => key !== "contextRecovery"))
1015
+ : value;
1016
+ return relayThreadSnapshotSchemaV13.parse({
1017
+ ...projectRelayThreadSnapshotV12(legacySource),
1018
+ contextRecovery: source.contextRecovery ?? null,
1019
+ });
1020
+ }
1021
+ export function projectRuntimeEventEnvelopeForRelayV13(value) {
1022
+ const source = runtimeEventEnvelopeSchema.parse(value);
1023
+ const base = projectRuntimeEventEnvelopeForRelayV12(value);
1024
+ return base && source.event.type === "context.recovery.changed"
1025
+ ? relayRuntimeEventEnvelopeSchemaV13.parse({ ...base, event: source.event })
1026
+ : base;
1027
+ }
1028
+ export function projectRelayMessageV13ToV12(message) {
1029
+ if (message.type === "device.connect") {
1030
+ return relayDeviceConnectSchemaV12.parse({ ...message, protocolVersion: "1.2" });
1031
+ }
1032
+ if (message.type === "runtime.event" && message.event.event.type === "context.recovery.changed") {
1033
+ return relayMessageSchemaV12.parse({
1034
+ ...message,
1035
+ event: { ...message.event, event: { type: "capabilities.changed" } },
1036
+ });
1037
+ }
1038
+ return relayMessageSchemaV12.parse(message);
1039
+ }
959
1040
  export const RELAY_PROTOCOL_REGISTRY = {
1041
+ "1.3": {
1042
+ messageTypes: RELAY_MESSAGE_TYPE_VALUES_V11,
1043
+ messageSchema: relayMessageSchemaV13,
1044
+ requestMethods: RELAY_REQUEST_METHOD_VALUES_V12,
1045
+ requestMethodSchemas: relayRequestMethodSchemasV13,
1046
+ requestMethodDispositions: RELAY_REQUEST_METHOD_DISPOSITIONS_V12,
1047
+ mutationMethods: RELAY_MUTATION_REQUEST_METHODS_V11,
1048
+ localOnlyMethods: RELAY_LOCAL_ONLY_REQUEST_METHODS_V11,
1049
+ },
960
1050
  "1.2": {
961
1051
  messageTypes: RELAY_MESSAGE_TYPE_VALUES_V11,
962
1052
  messageSchema: relayMessageSchemaV12,