@roll-agent/relay-protocol 0.1.1 → 0.3.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/README.md +134 -39
- package/dist/conformance.d.ts +571 -4
- package/dist/conformance.js +677 -8
- package/dist/control.d.ts +188 -0
- package/dist/control.js +180 -0
- package/dist/index.d.ts +3991 -287
- package/dist/index.js +676 -77
- package/dist/reference-adapter.d.ts +56 -0
- package/dist/reference-adapter.js +122 -0
- package/dist/schema/roll-relay-browser-session-v1.schema.json +23 -0
- package/dist/schema/roll-relay-control-v1.schema.json +127 -0
- package/dist/schema/roll-relay-protocol-v1.1.schema.json +3791 -0
- package/dist/schema/roll-relay-protocol-v1.schema.json +1 -1
- package/fixtures/control/v1.0/invalid-browser-session-trailing-whitespace.json +4 -0
- package/fixtures/control/v1.0/invalid-browser-session-uppercase-scheme.json +4 -0
- package/fixtures/control/v1.0/invalid-browser-session-url.json +4 -0
- package/fixtures/control/v1.0/invalid-browser-session-ws.json +4 -0
- package/fixtures/control/v1.0/invalid-control-extra-field.json +6 -0
- package/fixtures/control/v1.0/invalid-session-ready-wire-version.json +8 -0
- package/fixtures/control/v1.0/manifest.json +52 -0
- package/fixtures/control/v1.0/valid-browser-session.json +4 -0
- package/fixtures/control/v1.0/valid-session-error.json +5 -0
- package/fixtures/control/v1.0/valid-session-ready.json +8 -0
- package/fixtures/control/v1.0/valid-workspace-status.json +5 -0
- package/fixtures/v1.1/invalid-approval-projection-raw-input-leak.json +19 -0
- package/fixtures/v1.1/invalid-authentication-local-only.json +12 -0
- package/fixtures/v1.1/invalid-file-picker-local-only.json +12 -0
- package/fixtures/v1.1/invalid-interaction-cancelled-reason-leak.json +10 -0
- package/fixtures/v1.1/invalid-interaction-resolved-result-leak.json +18 -0
- package/fixtures/v1.1/invalid-legacy-approval-candidate.json +7 -0
- package/fixtures/v1.1/invalid-legacy-approval-respond.json +7 -0
- package/fixtures/v1.1/invalid-n-minus-one-device-connect.json +6 -0
- package/fixtures/v1.1/invalid-non-normal-sensitivity.json +21 -0
- package/fixtures/v1.1/invalid-runtime-event-tool-input-leak.json +22 -0
- package/fixtures/v1.1/invalid-runtime-event-tool-output-leak.json +21 -0
- package/fixtures/v1.1/invalid-user-input-projection-secret-leak.json +22 -0
- package/fixtures/v1.1/manifest.json +673 -0
- package/fixtures/v1.1/valid-device-connect.json +6 -0
- package/fixtures/v1.1/valid-interaction-cancelled.json +9 -0
- package/fixtures/v1.1/valid-interaction-candidate-user-input.json +25 -0
- package/fixtures/v1.1/valid-interaction-request-approval.json +17 -0
- package/fixtures/v1.1/valid-interaction-request-user-input.json +40 -0
- package/fixtures/v1.1/valid-interaction-resolved.json +9 -0
- package/fixtures/v1.1/valid-runtime-ack.json +5 -0
- package/fixtures/v1.1/valid-runtime-encrypted-interaction.json +10 -0
- package/fixtures/v1.1/valid-runtime-event-runtime-n-minus-one.json +16 -0
- package/fixtures/v1.1/valid-runtime-event.json +16 -0
- package/fixtures/v1.1/valid-runtime-gap.json +7 -0
- package/fixtures/v1.1/valid-runtime-request.json +10 -0
- package/fixtures/v1.1/valid-runtime-response.json +8 -0
- package/package.json +16 -3
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { approvalIdSchema, jsonValueSchema, runtimeEventEnvelopeSchema,
|
|
1
|
+
import { RUNTIME_SERVER_REQUEST_METHODS, TOOL_OUTCOME_KINDS, approvalIdSchema, approvalExplanationSchema, approvalRequestResultSchema, getApprovalExplanation, interactionIdSchema, jsonValueSchema, normalizeUserInputResult, operationGetResultSchema, 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.0"];
|
|
4
|
-
export const
|
|
5
|
-
/** @deprecated
|
|
3
|
+
export const SUPPORTED_RELAY_PROTOCOL_VERSIONS = ["1.1", "1.0"];
|
|
4
|
+
export const LATEST_RELAY_PROTOCOL_VERSION = SUPPORTED_RELAY_PROTOCOL_VERSIONS[0];
|
|
5
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
6
|
+
export const RELAY_PROTOCOL_VERSION = "1.0";
|
|
7
|
+
/** @deprecated The one-argument Companion connection API remains pinned to Wire 1.0. */
|
|
6
8
|
export const COMPANION_RELAY_PROTOCOL_VERSION = RELAY_PROTOCOL_VERSION;
|
|
7
|
-
export const
|
|
9
|
+
export const RELAY_MESSAGE_TYPES_V10 = {
|
|
8
10
|
deviceConnect: "device.connect",
|
|
9
11
|
runtimeRequest: "runtime.request",
|
|
10
12
|
runtimeResponse: "runtime.response",
|
|
@@ -13,20 +15,36 @@ export const RELAY_MESSAGE_TYPES = {
|
|
|
13
15
|
runtimeGap: "runtime.gap",
|
|
14
16
|
runtimeEncrypted: "runtime.encrypted",
|
|
15
17
|
};
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export const RELAY_MESSAGE_TYPES_V11 = {
|
|
19
|
+
...RELAY_MESSAGE_TYPES_V10,
|
|
20
|
+
interactionRequest: "interaction.request",
|
|
21
|
+
interactionResolved: "interaction.resolved",
|
|
22
|
+
interactionCancelled: "interaction.cancelled",
|
|
23
|
+
};
|
|
24
|
+
export const RELAY_MESSAGE_TYPE_VALUES_V10 = [
|
|
25
|
+
RELAY_MESSAGE_TYPES_V10.deviceConnect,
|
|
26
|
+
RELAY_MESSAGE_TYPES_V10.runtimeRequest,
|
|
27
|
+
RELAY_MESSAGE_TYPES_V10.runtimeResponse,
|
|
28
|
+
RELAY_MESSAGE_TYPES_V10.runtimeEvent,
|
|
29
|
+
RELAY_MESSAGE_TYPES_V10.runtimeAck,
|
|
30
|
+
RELAY_MESSAGE_TYPES_V10.runtimeGap,
|
|
31
|
+
RELAY_MESSAGE_TYPES_V10.runtimeEncrypted,
|
|
32
|
+
];
|
|
33
|
+
export const RELAY_MESSAGE_TYPE_VALUES_V11 = [
|
|
34
|
+
...RELAY_MESSAGE_TYPE_VALUES_V10,
|
|
35
|
+
RELAY_MESSAGE_TYPES_V11.interactionRequest,
|
|
36
|
+
RELAY_MESSAGE_TYPES_V11.interactionResolved,
|
|
37
|
+
RELAY_MESSAGE_TYPES_V11.interactionCancelled,
|
|
24
38
|
];
|
|
39
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
40
|
+
export const RELAY_MESSAGE_TYPES = RELAY_MESSAGE_TYPES_V10;
|
|
41
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
42
|
+
export const RELAY_MESSAGE_TYPE_VALUES = RELAY_MESSAGE_TYPE_VALUES_V10;
|
|
25
43
|
/**
|
|
26
44
|
* Relay Wire 1.0 is intentionally independent from the latest Runtime registry.
|
|
27
45
|
* New Runtime methods never become remotely callable without a Relay version change.
|
|
28
46
|
*/
|
|
29
|
-
export const
|
|
47
|
+
export const RELAY_REQUEST_METHODS_V10 = {
|
|
30
48
|
initialize: "initialize",
|
|
31
49
|
threadList: "thread.list",
|
|
32
50
|
threadCreate: "thread.create",
|
|
@@ -42,51 +60,116 @@ export const RELAY_REQUEST_METHODS = {
|
|
|
42
60
|
operationGet: "operation.get",
|
|
43
61
|
approvalCandidate: "approval.candidate",
|
|
44
62
|
};
|
|
45
|
-
export const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
export const RELAY_REQUEST_METHODS_V11 = {
|
|
64
|
+
initialize: "initialize",
|
|
65
|
+
threadList: "thread.list",
|
|
66
|
+
threadCreate: "thread.create",
|
|
67
|
+
threadOpen: "thread.open",
|
|
68
|
+
threadSnapshot: "thread.snapshot",
|
|
69
|
+
threadRename: "thread.rename",
|
|
70
|
+
threadDelete: "thread.delete",
|
|
71
|
+
threadDetach: "thread.detach",
|
|
72
|
+
threadCapabilities: "thread.capabilities",
|
|
73
|
+
turnStart: "turn.start",
|
|
74
|
+
turnCancel: "turn.cancel",
|
|
75
|
+
operationGet: "operation.get",
|
|
76
|
+
interactionCandidate: "interaction.candidate",
|
|
77
|
+
};
|
|
78
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
79
|
+
export const RELAY_REQUEST_METHODS = RELAY_REQUEST_METHODS_V10;
|
|
80
|
+
export const RELAY_REQUEST_METHOD_VALUES_V10 = [
|
|
81
|
+
RELAY_REQUEST_METHODS_V10.initialize,
|
|
82
|
+
RELAY_REQUEST_METHODS_V10.threadList,
|
|
83
|
+
RELAY_REQUEST_METHODS_V10.threadCreate,
|
|
84
|
+
RELAY_REQUEST_METHODS_V10.threadOpen,
|
|
85
|
+
RELAY_REQUEST_METHODS_V10.threadSnapshot,
|
|
86
|
+
RELAY_REQUEST_METHODS_V10.threadRename,
|
|
87
|
+
RELAY_REQUEST_METHODS_V10.threadDelete,
|
|
88
|
+
RELAY_REQUEST_METHODS_V10.threadDetach,
|
|
89
|
+
RELAY_REQUEST_METHODS_V10.threadCapabilities,
|
|
90
|
+
RELAY_REQUEST_METHODS_V10.turnStart,
|
|
91
|
+
RELAY_REQUEST_METHODS_V10.turnCancel,
|
|
92
|
+
RELAY_REQUEST_METHODS_V10.approvalRespond,
|
|
93
|
+
RELAY_REQUEST_METHODS_V10.operationGet,
|
|
94
|
+
RELAY_REQUEST_METHODS_V10.approvalCandidate,
|
|
95
|
+
];
|
|
96
|
+
export const RELAY_REQUEST_METHOD_VALUES_V11 = [
|
|
97
|
+
RELAY_REQUEST_METHODS_V11.initialize,
|
|
98
|
+
RELAY_REQUEST_METHODS_V11.threadList,
|
|
99
|
+
RELAY_REQUEST_METHODS_V11.threadCreate,
|
|
100
|
+
RELAY_REQUEST_METHODS_V11.threadOpen,
|
|
101
|
+
RELAY_REQUEST_METHODS_V11.threadSnapshot,
|
|
102
|
+
RELAY_REQUEST_METHODS_V11.threadRename,
|
|
103
|
+
RELAY_REQUEST_METHODS_V11.threadDelete,
|
|
104
|
+
RELAY_REQUEST_METHODS_V11.threadDetach,
|
|
105
|
+
RELAY_REQUEST_METHODS_V11.threadCapabilities,
|
|
106
|
+
RELAY_REQUEST_METHODS_V11.turnStart,
|
|
107
|
+
RELAY_REQUEST_METHODS_V11.turnCancel,
|
|
108
|
+
RELAY_REQUEST_METHODS_V11.operationGet,
|
|
109
|
+
RELAY_REQUEST_METHODS_V11.interactionCandidate,
|
|
60
110
|
];
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[
|
|
65
|
-
[
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
111
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
112
|
+
export const RELAY_REQUEST_METHOD_VALUES = RELAY_REQUEST_METHOD_VALUES_V10;
|
|
113
|
+
export const RELAY_REQUEST_METHOD_DISPOSITIONS_V10 = {
|
|
114
|
+
[RELAY_REQUEST_METHODS_V10.initialize]: "local-only",
|
|
115
|
+
[RELAY_REQUEST_METHODS_V10.threadList]: "query",
|
|
116
|
+
[RELAY_REQUEST_METHODS_V10.threadCreate]: "mutation",
|
|
117
|
+
[RELAY_REQUEST_METHODS_V10.threadOpen]: "query",
|
|
118
|
+
[RELAY_REQUEST_METHODS_V10.threadSnapshot]: "query",
|
|
119
|
+
[RELAY_REQUEST_METHODS_V10.threadRename]: "mutation",
|
|
120
|
+
[RELAY_REQUEST_METHODS_V10.threadDelete]: "mutation",
|
|
121
|
+
[RELAY_REQUEST_METHODS_V10.threadDetach]: "mutation",
|
|
122
|
+
[RELAY_REQUEST_METHODS_V10.threadCapabilities]: "query",
|
|
123
|
+
[RELAY_REQUEST_METHODS_V10.turnStart]: "mutation",
|
|
124
|
+
[RELAY_REQUEST_METHODS_V10.turnCancel]: "mutation",
|
|
125
|
+
[RELAY_REQUEST_METHODS_V10.approvalRespond]: "mutation",
|
|
126
|
+
[RELAY_REQUEST_METHODS_V10.operationGet]: "query",
|
|
127
|
+
[RELAY_REQUEST_METHODS_V10.approvalCandidate]: "mutation",
|
|
76
128
|
};
|
|
77
|
-
export const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
129
|
+
export const RELAY_REQUEST_METHOD_DISPOSITIONS_V11 = {
|
|
130
|
+
[RELAY_REQUEST_METHODS_V11.initialize]: "local-only",
|
|
131
|
+
[RELAY_REQUEST_METHODS_V11.threadList]: "query",
|
|
132
|
+
[RELAY_REQUEST_METHODS_V11.threadCreate]: "mutation",
|
|
133
|
+
[RELAY_REQUEST_METHODS_V11.threadOpen]: "query",
|
|
134
|
+
[RELAY_REQUEST_METHODS_V11.threadSnapshot]: "query",
|
|
135
|
+
[RELAY_REQUEST_METHODS_V11.threadRename]: "mutation",
|
|
136
|
+
[RELAY_REQUEST_METHODS_V11.threadDelete]: "mutation",
|
|
137
|
+
[RELAY_REQUEST_METHODS_V11.threadDetach]: "mutation",
|
|
138
|
+
[RELAY_REQUEST_METHODS_V11.threadCapabilities]: "query",
|
|
139
|
+
[RELAY_REQUEST_METHODS_V11.turnStart]: "mutation",
|
|
140
|
+
[RELAY_REQUEST_METHODS_V11.turnCancel]: "mutation",
|
|
141
|
+
[RELAY_REQUEST_METHODS_V11.operationGet]: "query",
|
|
142
|
+
[RELAY_REQUEST_METHODS_V11.interactionCandidate]: "mutation",
|
|
143
|
+
};
|
|
144
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
145
|
+
export const RELAY_REQUEST_METHOD_DISPOSITIONS = RELAY_REQUEST_METHOD_DISPOSITIONS_V10;
|
|
146
|
+
export const RELAY_MUTATION_REQUEST_METHODS_V10 = [
|
|
147
|
+
RELAY_REQUEST_METHODS_V10.threadCreate,
|
|
148
|
+
RELAY_REQUEST_METHODS_V10.threadRename,
|
|
149
|
+
RELAY_REQUEST_METHODS_V10.threadDelete,
|
|
150
|
+
RELAY_REQUEST_METHODS_V10.threadDetach,
|
|
151
|
+
RELAY_REQUEST_METHODS_V10.turnStart,
|
|
152
|
+
RELAY_REQUEST_METHODS_V10.turnCancel,
|
|
153
|
+
RELAY_REQUEST_METHODS_V10.approvalRespond,
|
|
154
|
+
RELAY_REQUEST_METHODS_V10.approvalCandidate,
|
|
155
|
+
];
|
|
156
|
+
export const RELAY_MUTATION_REQUEST_METHODS_V11 = [
|
|
157
|
+
RELAY_REQUEST_METHODS_V11.threadCreate,
|
|
158
|
+
RELAY_REQUEST_METHODS_V11.threadRename,
|
|
159
|
+
RELAY_REQUEST_METHODS_V11.threadDelete,
|
|
160
|
+
RELAY_REQUEST_METHODS_V11.threadDetach,
|
|
161
|
+
RELAY_REQUEST_METHODS_V11.turnStart,
|
|
162
|
+
RELAY_REQUEST_METHODS_V11.turnCancel,
|
|
163
|
+
RELAY_REQUEST_METHODS_V11.interactionCandidate,
|
|
86
164
|
];
|
|
87
|
-
export const
|
|
88
|
-
|
|
165
|
+
export const RELAY_LOCAL_ONLY_REQUEST_METHODS_V10 = [
|
|
166
|
+
RELAY_REQUEST_METHODS_V10.initialize,
|
|
89
167
|
];
|
|
168
|
+
export const RELAY_LOCAL_ONLY_REQUEST_METHODS_V11 = [RELAY_REQUEST_METHODS_V11.initialize];
|
|
169
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
170
|
+
export const RELAY_MUTATION_REQUEST_METHODS = RELAY_MUTATION_REQUEST_METHODS_V10;
|
|
171
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
172
|
+
export const RELAY_LOCAL_ONLY_REQUEST_METHODS = RELAY_LOCAL_ONLY_REQUEST_METHODS_V10;
|
|
90
173
|
export const RELAY_ERROR_CODES = {
|
|
91
174
|
protocolVersionUnsupported: "RELAY_PROTOCOL_VERSION_UNSUPPORTED",
|
|
92
175
|
invalidFrame: "RELAY_INVALID_FRAME",
|
|
@@ -114,11 +197,24 @@ export const RELAY_ERROR_RETRYABILITY = {
|
|
|
114
197
|
export function getRelayErrorRetryability(code) {
|
|
115
198
|
return RELAY_ERROR_RETRYABILITY[code];
|
|
116
199
|
}
|
|
200
|
+
/** Wire 1.1 adds Host-level request authorization without mutating frozen Wire 1.0 exports. */
|
|
201
|
+
export const RELAY_ERROR_CODES_V11 = {
|
|
202
|
+
...RELAY_ERROR_CODES,
|
|
203
|
+
remoteRequestDenied: "REMOTE_REQUEST_DENIED",
|
|
204
|
+
};
|
|
205
|
+
export const RELAY_ERROR_RETRYABILITY_V11 = {
|
|
206
|
+
...RELAY_ERROR_RETRYABILITY,
|
|
207
|
+
[RELAY_ERROR_CODES_V11.remoteRequestDenied]: false,
|
|
208
|
+
};
|
|
209
|
+
export function getRelayErrorRetryabilityV11(code) {
|
|
210
|
+
return RELAY_ERROR_RETRYABILITY_V11[code];
|
|
211
|
+
}
|
|
117
212
|
export const relayProtocolVersionSchema = z.enum(SUPPORTED_RELAY_PROTOCOL_VERSIONS);
|
|
118
213
|
export const deviceIdSchema = z.string().uuid().brand();
|
|
119
214
|
export const workspaceIdSchema = z.string().uuid().brand();
|
|
120
215
|
export const relayRequestIdSchema = z.string().uuid().brand();
|
|
121
216
|
export const relayEnvelopeIdSchema = z.string().uuid();
|
|
217
|
+
export const relayInteractionIdSchema = interactionIdSchema;
|
|
122
218
|
export const relayApprovalCandidateParamsSchema = z
|
|
123
219
|
.object({
|
|
124
220
|
threadId: threadIdSchema,
|
|
@@ -135,25 +231,107 @@ export const relayApprovalCandidateResultSchema = z
|
|
|
135
231
|
})
|
|
136
232
|
.strict()
|
|
137
233
|
.readonly();
|
|
138
|
-
export const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
234
|
+
export const RELAY_INTERACTION_METHODS_V11 = {
|
|
235
|
+
approvalRequest: RUNTIME_SERVER_REQUEST_METHODS.approvalRequest,
|
|
236
|
+
userInputRequest: RUNTIME_SERVER_REQUEST_METHODS.userInputRequest,
|
|
237
|
+
};
|
|
238
|
+
export const RELAY_INTERACTION_METHOD_VALUES_V11 = [
|
|
239
|
+
RELAY_INTERACTION_METHODS_V11.approvalRequest,
|
|
240
|
+
RELAY_INTERACTION_METHODS_V11.userInputRequest,
|
|
241
|
+
];
|
|
242
|
+
export const relayApprovalInteractionProjectionSchemaV11 = z
|
|
243
|
+
.object({
|
|
244
|
+
approvalId: approvalIdSchema,
|
|
245
|
+
agentName: z.string().min(1),
|
|
246
|
+
toolName: z.string().min(1),
|
|
247
|
+
explanation: approvalExplanationSchema.optional(),
|
|
248
|
+
})
|
|
249
|
+
.strict()
|
|
250
|
+
.readonly();
|
|
251
|
+
export const relayUserInputInteractionProjectionSchemaV11 = userInputFormSchema;
|
|
252
|
+
const relayInteractionCandidateBaseFieldsV11 = {
|
|
253
|
+
interactionId: interactionIdSchema,
|
|
254
|
+
threadId: threadIdSchema,
|
|
255
|
+
turnId: turnIdSchema,
|
|
256
|
+
};
|
|
257
|
+
export const relayApprovalInteractionCandidateParamsSchemaV11 = z
|
|
258
|
+
.object({
|
|
259
|
+
...relayInteractionCandidateBaseFieldsV11,
|
|
260
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.approvalRequest),
|
|
261
|
+
candidate: approvalRequestResultSchema,
|
|
262
|
+
})
|
|
263
|
+
.strict()
|
|
264
|
+
.readonly();
|
|
265
|
+
export const relayUserInputInteractionCandidateParamsSchemaV11 = z
|
|
266
|
+
.object({
|
|
267
|
+
...relayInteractionCandidateBaseFieldsV11,
|
|
268
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.userInputRequest),
|
|
269
|
+
candidate: userInputResultSchema,
|
|
270
|
+
})
|
|
271
|
+
.strict()
|
|
272
|
+
.readonly();
|
|
273
|
+
export const relayInteractionCandidateParamsSchemaV11 = z.discriminatedUnion("method", [
|
|
274
|
+
relayApprovalInteractionCandidateParamsSchemaV11,
|
|
275
|
+
relayUserInputInteractionCandidateParamsSchemaV11,
|
|
276
|
+
]);
|
|
277
|
+
export const relayInteractionCandidateResultSchemaV11 = z
|
|
278
|
+
.object({ accepted: z.literal(true) })
|
|
279
|
+
.strict()
|
|
280
|
+
.readonly();
|
|
281
|
+
const relayCommonRequestMethodSchemas = {
|
|
282
|
+
initialize: runtimeMethodSchemasV11["initialize"],
|
|
283
|
+
threadList: runtimeMethodSchemasV11["thread.list"],
|
|
284
|
+
threadCreate: runtimeMethodSchemasV11["thread.create"],
|
|
285
|
+
threadOpen: runtimeMethodSchemasV11["thread.open"],
|
|
286
|
+
threadSnapshot: runtimeMethodSchemasV11["thread.snapshot"],
|
|
287
|
+
threadRename: runtimeMethodSchemasV11["thread.rename"],
|
|
288
|
+
threadDelete: runtimeMethodSchemasV11["thread.delete"],
|
|
289
|
+
threadDetach: runtimeMethodSchemasV11["thread.detach"],
|
|
290
|
+
threadCapabilities: runtimeMethodSchemasV11["thread.capabilities"],
|
|
291
|
+
turnStart: runtimeMethodSchemasV11["turn.start"],
|
|
292
|
+
turnCancel: runtimeMethodSchemasV11["turn.cancel"],
|
|
293
|
+
approvalRespond: runtimeMethodSchemasV11["approval.respond"],
|
|
294
|
+
operationGet: runtimeMethodSchemasV11["operation.get"],
|
|
295
|
+
};
|
|
296
|
+
export const relayRequestMethodSchemasV10 = {
|
|
297
|
+
[RELAY_REQUEST_METHODS_V10.initialize]: relayCommonRequestMethodSchemas.initialize,
|
|
298
|
+
[RELAY_REQUEST_METHODS_V10.threadList]: relayCommonRequestMethodSchemas.threadList,
|
|
299
|
+
[RELAY_REQUEST_METHODS_V10.threadCreate]: relayCommonRequestMethodSchemas.threadCreate,
|
|
300
|
+
[RELAY_REQUEST_METHODS_V10.threadOpen]: relayCommonRequestMethodSchemas.threadOpen,
|
|
301
|
+
[RELAY_REQUEST_METHODS_V10.threadSnapshot]: relayCommonRequestMethodSchemas.threadSnapshot,
|
|
302
|
+
[RELAY_REQUEST_METHODS_V10.threadRename]: relayCommonRequestMethodSchemas.threadRename,
|
|
303
|
+
[RELAY_REQUEST_METHODS_V10.threadDelete]: relayCommonRequestMethodSchemas.threadDelete,
|
|
304
|
+
[RELAY_REQUEST_METHODS_V10.threadDetach]: relayCommonRequestMethodSchemas.threadDetach,
|
|
305
|
+
[RELAY_REQUEST_METHODS_V10.threadCapabilities]: relayCommonRequestMethodSchemas.threadCapabilities,
|
|
306
|
+
[RELAY_REQUEST_METHODS_V10.turnStart]: relayCommonRequestMethodSchemas.turnStart,
|
|
307
|
+
[RELAY_REQUEST_METHODS_V10.turnCancel]: relayCommonRequestMethodSchemas.turnCancel,
|
|
308
|
+
[RELAY_REQUEST_METHODS_V10.approvalRespond]: relayCommonRequestMethodSchemas.approvalRespond,
|
|
309
|
+
[RELAY_REQUEST_METHODS_V10.operationGet]: relayCommonRequestMethodSchemas.operationGet,
|
|
310
|
+
[RELAY_REQUEST_METHODS_V10.approvalCandidate]: {
|
|
153
311
|
params: relayApprovalCandidateParamsSchema,
|
|
154
312
|
result: relayApprovalCandidateResultSchema,
|
|
155
313
|
},
|
|
156
314
|
};
|
|
315
|
+
export const relayRequestMethodSchemasV11 = {
|
|
316
|
+
[RELAY_REQUEST_METHODS_V11.initialize]: relayCommonRequestMethodSchemas.initialize,
|
|
317
|
+
[RELAY_REQUEST_METHODS_V11.threadList]: relayCommonRequestMethodSchemas.threadList,
|
|
318
|
+
[RELAY_REQUEST_METHODS_V11.threadCreate]: relayCommonRequestMethodSchemas.threadCreate,
|
|
319
|
+
[RELAY_REQUEST_METHODS_V11.threadOpen]: relayCommonRequestMethodSchemas.threadOpen,
|
|
320
|
+
[RELAY_REQUEST_METHODS_V11.threadSnapshot]: relayCommonRequestMethodSchemas.threadSnapshot,
|
|
321
|
+
[RELAY_REQUEST_METHODS_V11.threadRename]: relayCommonRequestMethodSchemas.threadRename,
|
|
322
|
+
[RELAY_REQUEST_METHODS_V11.threadDelete]: relayCommonRequestMethodSchemas.threadDelete,
|
|
323
|
+
[RELAY_REQUEST_METHODS_V11.threadDetach]: relayCommonRequestMethodSchemas.threadDetach,
|
|
324
|
+
[RELAY_REQUEST_METHODS_V11.threadCapabilities]: relayCommonRequestMethodSchemas.threadCapabilities,
|
|
325
|
+
[RELAY_REQUEST_METHODS_V11.turnStart]: relayCommonRequestMethodSchemas.turnStart,
|
|
326
|
+
[RELAY_REQUEST_METHODS_V11.turnCancel]: relayCommonRequestMethodSchemas.turnCancel,
|
|
327
|
+
[RELAY_REQUEST_METHODS_V11.operationGet]: relayCommonRequestMethodSchemas.operationGet,
|
|
328
|
+
[RELAY_REQUEST_METHODS_V11.interactionCandidate]: {
|
|
329
|
+
params: relayInteractionCandidateParamsSchemaV11,
|
|
330
|
+
result: relayInteractionCandidateResultSchemaV11,
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
334
|
+
export const relayRequestMethodSchemas = relayRequestMethodSchemasV10;
|
|
157
335
|
export function isRelayRequestMethod(value) {
|
|
158
336
|
return Object.hasOwn(relayRequestMethodSchemas, value);
|
|
159
337
|
}
|
|
@@ -215,7 +393,7 @@ export const relayRuntimeEventSchema = z
|
|
|
215
393
|
type: z.literal(RELAY_MESSAGE_TYPES.runtimeEvent),
|
|
216
394
|
workspaceId: workspaceIdSchema,
|
|
217
395
|
relaySequence: z.number().int().nonnegative(),
|
|
218
|
-
event:
|
|
396
|
+
event: runtimeEventEnvelopeV11Schema,
|
|
219
397
|
})
|
|
220
398
|
.strict()
|
|
221
399
|
.readonly();
|
|
@@ -255,7 +433,332 @@ export const relayEncryptedMessageSchema = z
|
|
|
255
433
|
})
|
|
256
434
|
.strict()
|
|
257
435
|
.readonly();
|
|
258
|
-
export const
|
|
436
|
+
export const relayDeviceConnectSchemaV10 = relayDeviceConnectSchema;
|
|
437
|
+
export const relayRuntimeRequestSchemaV10 = relayRuntimeRequestSchema;
|
|
438
|
+
export const relayRuntimeResponseSchemaV10 = relayRuntimeResponseSchema;
|
|
439
|
+
export const relayRuntimeEventSchemaV10 = relayRuntimeEventSchema;
|
|
440
|
+
export const relayAckSchemaV10 = relayAckSchema;
|
|
441
|
+
export const relayGapSchemaV10 = relayGapSchema;
|
|
442
|
+
export const relayEncryptedMessageSchemaV10 = relayEncryptedMessageSchema;
|
|
443
|
+
export const relaySafeToolOutcomeSchemaV11 = z
|
|
444
|
+
.object({ kind: z.enum(TOOL_OUTCOME_KINDS) })
|
|
445
|
+
.strict()
|
|
446
|
+
.readonly();
|
|
447
|
+
export const relaySafeApprovalResolutionSchemaV11 = z.discriminatedUnion("status", [
|
|
448
|
+
z
|
|
449
|
+
.object({ status: z.literal("resolved"), decision: z.enum(["approve", "reject"]) })
|
|
450
|
+
.strict()
|
|
451
|
+
.readonly(),
|
|
452
|
+
z
|
|
453
|
+
.object({ status: z.literal("cancelled") })
|
|
454
|
+
.strict()
|
|
455
|
+
.readonly(),
|
|
456
|
+
z
|
|
457
|
+
.object({ status: z.literal("expired") })
|
|
458
|
+
.strict()
|
|
459
|
+
.readonly(),
|
|
460
|
+
]);
|
|
461
|
+
export const relayTimelineEventSchemaV11 = z.discriminatedUnion("type", [
|
|
462
|
+
z
|
|
463
|
+
.object({ type: z.literal("turn.started") })
|
|
464
|
+
.strict()
|
|
465
|
+
.readonly(),
|
|
466
|
+
z
|
|
467
|
+
.object({ type: z.literal("message.started"), streamId: streamIdSchema })
|
|
468
|
+
.strict()
|
|
469
|
+
.readonly(),
|
|
470
|
+
z
|
|
471
|
+
.object({ type: z.literal("message.delta"), streamId: streamIdSchema, delta: z.string() })
|
|
472
|
+
.strict()
|
|
473
|
+
.readonly(),
|
|
474
|
+
z
|
|
475
|
+
.object({ type: z.literal("message.completed"), streamId: streamIdSchema, text: z.string() })
|
|
476
|
+
.strict()
|
|
477
|
+
.readonly(),
|
|
478
|
+
z
|
|
479
|
+
.object({
|
|
480
|
+
type: z.literal("reasoning.summary.delta"),
|
|
481
|
+
reasoningId: z.string().min(1),
|
|
482
|
+
delta: z.string(),
|
|
483
|
+
})
|
|
484
|
+
.strict()
|
|
485
|
+
.readonly(),
|
|
486
|
+
z
|
|
487
|
+
.object({
|
|
488
|
+
type: z.literal("tool.started"),
|
|
489
|
+
toolCallId: z.string().min(1),
|
|
490
|
+
agentName: z.string().min(1),
|
|
491
|
+
toolName: z.string().min(1),
|
|
492
|
+
})
|
|
493
|
+
.strict()
|
|
494
|
+
.readonly(),
|
|
495
|
+
z
|
|
496
|
+
.object({
|
|
497
|
+
type: z.literal("tool.completed"),
|
|
498
|
+
toolCallId: z.string().min(1),
|
|
499
|
+
agentName: z.string().min(1),
|
|
500
|
+
toolName: z.string().min(1),
|
|
501
|
+
outcome: relaySafeToolOutcomeSchemaV11.optional(),
|
|
502
|
+
})
|
|
503
|
+
.strict()
|
|
504
|
+
.readonly(),
|
|
505
|
+
z
|
|
506
|
+
.object({
|
|
507
|
+
type: z.literal("approval.required"),
|
|
508
|
+
approval: relayApprovalInteractionProjectionSchemaV11,
|
|
509
|
+
})
|
|
510
|
+
.strict()
|
|
511
|
+
.readonly(),
|
|
512
|
+
z
|
|
513
|
+
.object({
|
|
514
|
+
type: z.literal("approval.resolved"),
|
|
515
|
+
approvalId: approvalIdSchema,
|
|
516
|
+
resolution: relaySafeApprovalResolutionSchemaV11,
|
|
517
|
+
})
|
|
518
|
+
.strict()
|
|
519
|
+
.readonly(),
|
|
520
|
+
z
|
|
521
|
+
.object({ type: z.literal("turn.completed") })
|
|
522
|
+
.strict()
|
|
523
|
+
.readonly(),
|
|
524
|
+
z
|
|
525
|
+
.object({ type: z.literal("turn.cancelled") })
|
|
526
|
+
.strict()
|
|
527
|
+
.readonly(),
|
|
528
|
+
z
|
|
529
|
+
.object({ type: z.literal("turn.failed"), stage: z.enum(["bootstrap", "plan", "execute"]) })
|
|
530
|
+
.strict()
|
|
531
|
+
.readonly(),
|
|
532
|
+
z
|
|
533
|
+
.object({ type: z.literal("capabilities.changed") })
|
|
534
|
+
.strict()
|
|
535
|
+
.readonly(),
|
|
536
|
+
]);
|
|
537
|
+
export const relayRuntimeEventEnvelopeSchemaV11 = z
|
|
538
|
+
.object({
|
|
539
|
+
protocolVersion: z.enum(["1.1", "1.0"]),
|
|
540
|
+
runtimeInstanceId: runtimeInstanceIdSchema,
|
|
541
|
+
sequence: z.number().int().nonnegative(),
|
|
542
|
+
timestamp: timestampSchema,
|
|
543
|
+
threadId: threadIdSchema,
|
|
544
|
+
turnId: turnIdSchema.optional(),
|
|
545
|
+
event: relayTimelineEventSchemaV11,
|
|
546
|
+
})
|
|
547
|
+
.strict()
|
|
548
|
+
.readonly();
|
|
549
|
+
function projectRelayTimelineEventV11(event) {
|
|
550
|
+
if (event.type === "tool.output") {
|
|
551
|
+
return undefined;
|
|
552
|
+
}
|
|
553
|
+
if (event.type === "tool.started") {
|
|
554
|
+
return relayTimelineEventSchemaV11.parse({
|
|
555
|
+
type: event.type,
|
|
556
|
+
toolCallId: event.toolCallId,
|
|
557
|
+
agentName: event.agentName,
|
|
558
|
+
toolName: event.toolName,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
if (event.type === "tool.completed") {
|
|
562
|
+
return relayTimelineEventSchemaV11.parse({
|
|
563
|
+
type: event.type,
|
|
564
|
+
toolCallId: event.toolCallId,
|
|
565
|
+
agentName: event.agentName,
|
|
566
|
+
toolName: event.toolName,
|
|
567
|
+
...(event.outcome === undefined ? {} : { outcome: { kind: event.outcome.kind } }),
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
if (event.type === "approval.required") {
|
|
571
|
+
const explanation = getApprovalExplanation(event.approval);
|
|
572
|
+
return relayTimelineEventSchemaV11.parse({
|
|
573
|
+
type: event.type,
|
|
574
|
+
approval: {
|
|
575
|
+
approvalId: event.approval.id,
|
|
576
|
+
agentName: event.approval.agentName,
|
|
577
|
+
toolName: event.approval.toolName,
|
|
578
|
+
...(explanation === undefined ? {} : { explanation }),
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
if (event.type === "approval.resolved") {
|
|
583
|
+
const resolution = event.resolution.status === "resolved"
|
|
584
|
+
? { status: event.resolution.status, decision: event.resolution.decision }
|
|
585
|
+
: { status: event.resolution.status };
|
|
586
|
+
return relayTimelineEventSchemaV11.parse({
|
|
587
|
+
type: event.type,
|
|
588
|
+
approvalId: event.approvalId,
|
|
589
|
+
resolution,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
if (event.type === "turn.cancelled") {
|
|
593
|
+
return relayTimelineEventSchemaV11.parse({ type: event.type });
|
|
594
|
+
}
|
|
595
|
+
if (event.type === "turn.failed") {
|
|
596
|
+
return relayTimelineEventSchemaV11.parse({ type: event.type, stage: event.stage });
|
|
597
|
+
}
|
|
598
|
+
return relayTimelineEventSchemaV11.parse(event);
|
|
599
|
+
}
|
|
600
|
+
export function projectRuntimeEventEnvelopeForRelayV11(value) {
|
|
601
|
+
const envelope = runtimeEventEnvelopeSchema.parse(value);
|
|
602
|
+
const event = projectRelayTimelineEventV11(envelope.event);
|
|
603
|
+
if (event === undefined) {
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
return relayRuntimeEventEnvelopeSchemaV11.parse({
|
|
607
|
+
protocolVersion: envelope.protocolVersion === "1.0" ? "1.0" : "1.1",
|
|
608
|
+
runtimeInstanceId: envelope.runtimeInstanceId,
|
|
609
|
+
sequence: envelope.sequence,
|
|
610
|
+
timestamp: envelope.timestamp,
|
|
611
|
+
threadId: envelope.threadId,
|
|
612
|
+
...(envelope.turnId === undefined ? {} : { turnId: envelope.turnId }),
|
|
613
|
+
event,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function redactRelayOperationViewV11(operation) {
|
|
617
|
+
return operationViewSchema.parse({
|
|
618
|
+
id: operation.id,
|
|
619
|
+
sequence: operation.sequence,
|
|
620
|
+
toolCallId: operation.toolCallId,
|
|
621
|
+
agentName: operation.agentName,
|
|
622
|
+
toolName: operation.toolName,
|
|
623
|
+
createdAt: operation.createdAt,
|
|
624
|
+
outcome: { kind: operation.outcome.kind },
|
|
625
|
+
display: null,
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
function redactRelayPendingApprovalV11(approval) {
|
|
629
|
+
const explanation = getApprovalExplanation(approval);
|
|
630
|
+
return pendingApprovalSchema.parse({
|
|
631
|
+
id: approval.id,
|
|
632
|
+
turnId: approval.turnId,
|
|
633
|
+
agentName: approval.agentName,
|
|
634
|
+
toolName: approval.toolName,
|
|
635
|
+
preview: explanation === undefined ? null : { explanation },
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/** Projects a Runtime snapshot into the allowlisted Relay Wire 1.1 query shape. */
|
|
639
|
+
export function projectRelayThreadSnapshotV11(value) {
|
|
640
|
+
const legacySnapshot = threadSnapshotV11Schema.safeParse(value);
|
|
641
|
+
const snapshot = legacySnapshot.success
|
|
642
|
+
? legacySnapshot.data
|
|
643
|
+
: projectThreadSnapshotForVersion("1.1", value);
|
|
644
|
+
return threadSnapshotV11Schema.parse({
|
|
645
|
+
thread: snapshot.thread,
|
|
646
|
+
messages: snapshot.messages,
|
|
647
|
+
operations: {
|
|
648
|
+
items: snapshot.operations.items.map(redactRelayOperationViewV11),
|
|
649
|
+
nextBeforeSequence: snapshot.operations.nextBeforeSequence,
|
|
650
|
+
},
|
|
651
|
+
...(snapshot.activeTurn === undefined ? {} : { activeTurn: snapshot.activeTurn }),
|
|
652
|
+
pendingApprovals: snapshot.pendingApprovals.map(redactRelayPendingApprovalV11),
|
|
653
|
+
transcriptCompleteness: snapshot.transcriptCompleteness,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/** Projects an operation query result without local display or outcome details. */
|
|
657
|
+
export function projectRelayOperationGetResultV11(value) {
|
|
658
|
+
const result = operationGetResultSchema.parse(value);
|
|
659
|
+
return operationGetResultSchema.parse({
|
|
660
|
+
operation: result.operation === null ? null : redactRelayOperationViewV11(result.operation),
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
const relayInteractionRequestBaseFieldsV11 = {
|
|
664
|
+
workspaceId: workspaceIdSchema,
|
|
665
|
+
relaySequence: z.number().int().nonnegative(),
|
|
666
|
+
interactionId: interactionIdSchema,
|
|
667
|
+
threadId: threadIdSchema,
|
|
668
|
+
turnId: turnIdSchema,
|
|
669
|
+
expiresAt: timestampSchema,
|
|
670
|
+
sensitivity: z.literal("normal"),
|
|
671
|
+
};
|
|
672
|
+
export const relayApprovalInteractionRequestSchemaV11 = z
|
|
673
|
+
.object({
|
|
674
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionRequest),
|
|
675
|
+
...relayInteractionRequestBaseFieldsV11,
|
|
676
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.approvalRequest),
|
|
677
|
+
projection: relayApprovalInteractionProjectionSchemaV11,
|
|
678
|
+
})
|
|
679
|
+
.strict()
|
|
680
|
+
.readonly();
|
|
681
|
+
export const relayUserInputInteractionRequestSchemaV11 = z
|
|
682
|
+
.object({
|
|
683
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionRequest),
|
|
684
|
+
...relayInteractionRequestBaseFieldsV11,
|
|
685
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.userInputRequest),
|
|
686
|
+
projection: relayUserInputInteractionProjectionSchemaV11,
|
|
687
|
+
})
|
|
688
|
+
.strict()
|
|
689
|
+
.readonly();
|
|
690
|
+
export const relayInteractionRequestSchemaV11 = z.discriminatedUnion("method", [
|
|
691
|
+
relayApprovalInteractionRequestSchemaV11,
|
|
692
|
+
relayUserInputInteractionRequestSchemaV11,
|
|
693
|
+
]);
|
|
694
|
+
const relayInteractionTerminalBaseFieldsV11 = {
|
|
695
|
+
workspaceId: workspaceIdSchema,
|
|
696
|
+
relaySequence: z.number().int().nonnegative(),
|
|
697
|
+
interactionId: interactionIdSchema,
|
|
698
|
+
threadId: threadIdSchema,
|
|
699
|
+
turnId: turnIdSchema,
|
|
700
|
+
method: z.enum(RELAY_INTERACTION_METHOD_VALUES_V11),
|
|
701
|
+
};
|
|
702
|
+
export const relayInteractionResolvedSchemaV11 = z
|
|
703
|
+
.object({
|
|
704
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionResolved),
|
|
705
|
+
...relayInteractionTerminalBaseFieldsV11,
|
|
706
|
+
})
|
|
707
|
+
.strict()
|
|
708
|
+
.readonly();
|
|
709
|
+
export const relayInteractionCancelledSchemaV11 = z
|
|
710
|
+
.object({
|
|
711
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionCancelled),
|
|
712
|
+
...relayInteractionTerminalBaseFieldsV11,
|
|
713
|
+
})
|
|
714
|
+
.strict()
|
|
715
|
+
.readonly();
|
|
716
|
+
export const relayDeviceConnectSchemaV11 = z
|
|
717
|
+
.object({
|
|
718
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.deviceConnect),
|
|
719
|
+
protocolVersion: z.literal("1.1"),
|
|
720
|
+
deviceId: deviceIdSchema,
|
|
721
|
+
pairingToken: z.string().min(16),
|
|
722
|
+
})
|
|
723
|
+
.strict()
|
|
724
|
+
.readonly();
|
|
725
|
+
export const relayRuntimeRequestSchemaV11 = z
|
|
726
|
+
.object({
|
|
727
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.runtimeRequest),
|
|
728
|
+
requestId: relayRequestIdSchema,
|
|
729
|
+
workspaceId: workspaceIdSchema,
|
|
730
|
+
method: z.enum(RELAY_REQUEST_METHOD_VALUES_V11),
|
|
731
|
+
params: jsonValueSchema,
|
|
732
|
+
})
|
|
733
|
+
.strict()
|
|
734
|
+
.readonly();
|
|
735
|
+
export const relayRuntimeResponseSchemaV11 = relayRuntimeResponseSchemaV10;
|
|
736
|
+
export const relayRuntimeEventSchemaV11 = z
|
|
737
|
+
.object({
|
|
738
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.runtimeEvent),
|
|
739
|
+
workspaceId: workspaceIdSchema,
|
|
740
|
+
relaySequence: z.number().int().nonnegative(),
|
|
741
|
+
event: relayRuntimeEventEnvelopeSchemaV11,
|
|
742
|
+
})
|
|
743
|
+
.strict()
|
|
744
|
+
.readonly();
|
|
745
|
+
export const relayAckSchemaV11 = relayAckSchemaV10;
|
|
746
|
+
export const relayGapSchemaV11 = relayGapSchemaV10;
|
|
747
|
+
export const relayEncryptedMessageSchemaV11 = z
|
|
748
|
+
.object({
|
|
749
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.runtimeEncrypted),
|
|
750
|
+
workspaceId: workspaceIdSchema,
|
|
751
|
+
envelopeId: relayEnvelopeIdSchema,
|
|
752
|
+
payloadKind: z.enum(["request", "response", "event", "interaction"]),
|
|
753
|
+
requestId: relayRequestIdSchema.optional(),
|
|
754
|
+
relaySequence: z.number().int().nonnegative().optional(),
|
|
755
|
+
algorithm: z.string().min(1),
|
|
756
|
+
nonce: z.string().min(1),
|
|
757
|
+
ciphertext: z.string().min(1),
|
|
758
|
+
})
|
|
759
|
+
.strict()
|
|
760
|
+
.readonly();
|
|
761
|
+
export const relayMessageSchemasV10 = {
|
|
259
762
|
[RELAY_MESSAGE_TYPES.deviceConnect]: relayDeviceConnectSchema,
|
|
260
763
|
[RELAY_MESSAGE_TYPES.runtimeRequest]: relayRuntimeRequestSchema,
|
|
261
764
|
[RELAY_MESSAGE_TYPES.runtimeResponse]: relayRuntimeResponseSchema,
|
|
@@ -264,7 +767,7 @@ export const relayMessageSchemas = {
|
|
|
264
767
|
[RELAY_MESSAGE_TYPES.runtimeGap]: relayGapSchema,
|
|
265
768
|
[RELAY_MESSAGE_TYPES.runtimeEncrypted]: relayEncryptedMessageSchema,
|
|
266
769
|
};
|
|
267
|
-
export const
|
|
770
|
+
export const relayMessageSchemaV10 = z.discriminatedUnion("type", [
|
|
268
771
|
relayDeviceConnectSchema,
|
|
269
772
|
relayRuntimeRequestSchema,
|
|
270
773
|
relayRuntimeResponseSchema,
|
|
@@ -273,17 +776,113 @@ export const relayMessageSchema = z.discriminatedUnion("type", [
|
|
|
273
776
|
relayGapSchema,
|
|
274
777
|
relayEncryptedMessageSchema,
|
|
275
778
|
]);
|
|
779
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
780
|
+
export const relayMessageSchemas = relayMessageSchemasV10;
|
|
781
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
782
|
+
export const relayMessageSchema = relayMessageSchemaV10;
|
|
783
|
+
export const relayMessageSchemasV11 = {
|
|
784
|
+
[RELAY_MESSAGE_TYPES_V11.deviceConnect]: relayDeviceConnectSchemaV11,
|
|
785
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeRequest]: relayRuntimeRequestSchemaV11,
|
|
786
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeResponse]: relayRuntimeResponseSchemaV11,
|
|
787
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeEvent]: relayRuntimeEventSchemaV11,
|
|
788
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeAck]: relayAckSchemaV11,
|
|
789
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeGap]: relayGapSchemaV11,
|
|
790
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeEncrypted]: relayEncryptedMessageSchemaV11,
|
|
791
|
+
[RELAY_MESSAGE_TYPES_V11.interactionRequest]: relayInteractionRequestSchemaV11,
|
|
792
|
+
[RELAY_MESSAGE_TYPES_V11.interactionResolved]: relayInteractionResolvedSchemaV11,
|
|
793
|
+
[RELAY_MESSAGE_TYPES_V11.interactionCancelled]: relayInteractionCancelledSchemaV11,
|
|
794
|
+
};
|
|
795
|
+
export const relayMessageSchemaV11 = z.discriminatedUnion("type", [
|
|
796
|
+
relayDeviceConnectSchemaV11,
|
|
797
|
+
relayRuntimeRequestSchemaV11,
|
|
798
|
+
relayRuntimeResponseSchemaV11,
|
|
799
|
+
relayRuntimeEventSchemaV11,
|
|
800
|
+
relayAckSchemaV11,
|
|
801
|
+
relayGapSchemaV11,
|
|
802
|
+
relayEncryptedMessageSchemaV11,
|
|
803
|
+
relayInteractionRequestSchemaV11,
|
|
804
|
+
relayInteractionResolvedSchemaV11,
|
|
805
|
+
relayInteractionCancelledSchemaV11,
|
|
806
|
+
]);
|
|
276
807
|
export const RELAY_PROTOCOL_REGISTRY = {
|
|
808
|
+
"1.1": {
|
|
809
|
+
messageTypes: RELAY_MESSAGE_TYPE_VALUES_V11,
|
|
810
|
+
messageSchema: relayMessageSchemaV11,
|
|
811
|
+
requestMethods: RELAY_REQUEST_METHOD_VALUES_V11,
|
|
812
|
+
requestMethodSchemas: relayRequestMethodSchemasV11,
|
|
813
|
+
requestMethodDispositions: RELAY_REQUEST_METHOD_DISPOSITIONS_V11,
|
|
814
|
+
mutationMethods: RELAY_MUTATION_REQUEST_METHODS_V11,
|
|
815
|
+
localOnlyMethods: RELAY_LOCAL_ONLY_REQUEST_METHODS_V11,
|
|
816
|
+
},
|
|
277
817
|
"1.0": {
|
|
278
|
-
messageTypes:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
818
|
+
messageTypes: RELAY_MESSAGE_TYPE_VALUES_V10,
|
|
819
|
+
messageSchema: relayMessageSchemaV10,
|
|
820
|
+
requestMethods: RELAY_REQUEST_METHOD_VALUES_V10,
|
|
821
|
+
requestMethodSchemas: relayRequestMethodSchemasV10,
|
|
822
|
+
requestMethodDispositions: RELAY_REQUEST_METHOD_DISPOSITIONS_V10,
|
|
823
|
+
mutationMethods: RELAY_MUTATION_REQUEST_METHODS_V10,
|
|
824
|
+
localOnlyMethods: RELAY_LOCAL_ONLY_REQUEST_METHODS_V10,
|
|
282
825
|
},
|
|
283
826
|
};
|
|
284
827
|
export function getRelayProtocolRegistry(version) {
|
|
285
828
|
return RELAY_PROTOCOL_REGISTRY[version];
|
|
286
829
|
}
|
|
830
|
+
export function parseRelayMessageForVersion(version, value) {
|
|
831
|
+
return getRelayProtocolRegistry(version).messageSchema.parse(value);
|
|
832
|
+
}
|
|
833
|
+
export function isRelayRequestMethodForVersion(version, value) {
|
|
834
|
+
return Object.hasOwn(getRelayProtocolRegistry(version).requestMethodSchemas, value);
|
|
835
|
+
}
|
|
836
|
+
export function getRelayRequestMethodDispositionForVersion(version, value) {
|
|
837
|
+
if (!isRelayRequestMethodForVersion(version, value)) {
|
|
838
|
+
return undefined;
|
|
839
|
+
}
|
|
840
|
+
const dispositions = getRelayProtocolRegistry(version).requestMethodDispositions;
|
|
841
|
+
return dispositions[value];
|
|
842
|
+
}
|
|
843
|
+
export function parseRelayRequestParamsForVersion(version, method, value) {
|
|
844
|
+
const definitions = getRelayProtocolRegistry(version).requestMethodSchemas;
|
|
845
|
+
const definition = definitions[method];
|
|
846
|
+
if (definition === undefined) {
|
|
847
|
+
throw new Error(`Relay request method ${method} is unavailable in Wire ${version}`);
|
|
848
|
+
}
|
|
849
|
+
return definition.params.parse(value);
|
|
850
|
+
}
|
|
851
|
+
export function parseRelayRequestResultForVersion(version, method, value) {
|
|
852
|
+
const definitions = getRelayProtocolRegistry(version).requestMethodSchemas;
|
|
853
|
+
const definition = definitions[method];
|
|
854
|
+
if (definition === undefined) {
|
|
855
|
+
throw new Error(`Relay request method ${method} is unavailable in Wire ${version}`);
|
|
856
|
+
}
|
|
857
|
+
return definition.result.parse(value);
|
|
858
|
+
}
|
|
859
|
+
export function parseRelayInteractionCandidateForRequestV11(request, candidate) {
|
|
860
|
+
const base = {
|
|
861
|
+
interactionId: request.interactionId,
|
|
862
|
+
threadId: request.threadId,
|
|
863
|
+
turnId: request.turnId,
|
|
864
|
+
};
|
|
865
|
+
if (request.method === RELAY_INTERACTION_METHODS_V11.approvalRequest) {
|
|
866
|
+
return relayInteractionCandidateParamsSchemaV11.parse({
|
|
867
|
+
...base,
|
|
868
|
+
method: request.method,
|
|
869
|
+
candidate: approvalRequestResultSchema.parse(candidate),
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
const normalized = normalizeUserInputResult({
|
|
873
|
+
interactionId: request.interactionId,
|
|
874
|
+
threadId: request.threadId,
|
|
875
|
+
turnId: request.turnId,
|
|
876
|
+
expiresAt: request.expiresAt,
|
|
877
|
+
sensitivity: request.sensitivity,
|
|
878
|
+
...request.projection,
|
|
879
|
+
}, candidate);
|
|
880
|
+
return relayInteractionCandidateParamsSchemaV11.parse({
|
|
881
|
+
...base,
|
|
882
|
+
method: request.method,
|
|
883
|
+
candidate: normalized,
|
|
884
|
+
});
|
|
885
|
+
}
|
|
287
886
|
export function negotiateRelayProtocolVersion(peerVersions) {
|
|
288
887
|
return SUPPORTED_RELAY_PROTOCOL_VERSIONS.find((version) => peerVersions.includes(version));
|
|
289
888
|
}
|