@roll-agent/relay-protocol 0.4.2 → 0.5.1
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/README.md +4 -0
- package/dist/control.d.ts +52 -21
- package/dist/control.js +8 -1
- package/dist/index.d.ts +2781 -890
- package/dist/index.js +96 -6
- package/dist/schema/roll-relay-protocol-v1.3.schema.json +4606 -0
- package/fixtures/v1.3/invalid-approval-projection-raw-input-leak.json +19 -0
- package/fixtures/v1.3/invalid-authentication-local-only.json +12 -0
- package/fixtures/v1.3/invalid-context-recovery-notes.json +22 -0
- package/fixtures/v1.3/invalid-file-picker-local-only.json +12 -0
- package/fixtures/v1.3/invalid-interaction-cancelled-reason-leak.json +10 -0
- package/fixtures/v1.3/invalid-interaction-resolved-result-leak.json +18 -0
- package/fixtures/v1.3/invalid-legacy-approval-candidate.json +7 -0
- package/fixtures/v1.3/invalid-legacy-approval-respond.json +7 -0
- package/fixtures/v1.3/invalid-n-minus-one-device-connect.json +6 -0
- package/fixtures/v1.3/invalid-non-normal-sensitivity.json +21 -0
- package/fixtures/v1.3/invalid-runtime-event-tool-input-leak.json +22 -0
- package/fixtures/v1.3/invalid-runtime-event-tool-output-leak.json +21 -0
- package/fixtures/v1.3/invalid-user-input-projection-secret-leak.json +22 -0
- package/fixtures/v1.3/manifest.json +489 -0
- package/fixtures/v1.3/valid-context-recovery.json +21 -0
- package/fixtures/v1.3/valid-device-connect.json +6 -0
- package/fixtures/v1.3/valid-interaction-cancelled.json +9 -0
- package/fixtures/v1.3/valid-interaction-candidate-user-input.json +25 -0
- package/fixtures/v1.3/valid-interaction-request-approval.json +17 -0
- package/fixtures/v1.3/valid-interaction-request-user-input.json +40 -0
- package/fixtures/v1.3/valid-interaction-resolved.json +9 -0
- package/fixtures/v1.3/valid-runtime-ack.json +5 -0
- package/fixtures/v1.3/valid-runtime-encrypted-interaction.json +10 -0
- package/fixtures/v1.3/valid-runtime-event-runtime-n-minus-one.json +16 -0
- package/fixtures/v1.3/valid-runtime-event.json +16 -0
- package/fixtures/v1.3/valid-runtime-gap.json +7 -0
- package/fixtures/v1.3/valid-runtime-request.json +10 -0
- package/fixtures/v1.3/valid-runtime-response.json +8 -0
- package/package.json +5 -4
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, uuidSchema, 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";
|
|
@@ -210,10 +210,10 @@ export function getRelayErrorRetryabilityV11(code) {
|
|
|
210
210
|
return RELAY_ERROR_RETRYABILITY_V11[code];
|
|
211
211
|
}
|
|
212
212
|
export const relayProtocolVersionSchema = z.enum(SUPPORTED_RELAY_PROTOCOL_VERSIONS);
|
|
213
|
-
export const deviceIdSchema =
|
|
214
|
-
export const workspaceIdSchema =
|
|
215
|
-
export const relayRequestIdSchema =
|
|
216
|
-
export const relayEnvelopeIdSchema =
|
|
213
|
+
export const deviceIdSchema = uuidSchema.clone().brand();
|
|
214
|
+
export const workspaceIdSchema = uuidSchema.clone().brand();
|
|
215
|
+
export const relayRequestIdSchema = uuidSchema.clone().brand();
|
|
216
|
+
export const relayEnvelopeIdSchema = uuidSchema.clone();
|
|
217
217
|
export const relayInteractionIdSchema = interactionIdSchema;
|
|
218
218
|
export const relayApprovalCandidateParamsSchema = z
|
|
219
219
|
.object({
|
|
@@ -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,
|