@roll-agent/relay-protocol 0.1.0 → 0.2.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 +90 -39
- package/dist/conformance.d.ts +571 -4
- package/dist/conformance.js +677 -8
- package/dist/index.d.ts +3977 -303
- package/dist/index.js +664 -77
- package/dist/reference-adapter.d.ts +56 -0
- package/dist/reference-adapter.js +122 -0
- package/dist/schema/roll-relay-protocol-v1.1.schema.json +3791 -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 +8 -2
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,
|
|
60
95
|
];
|
|
61
|
-
export const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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,
|
|
110
|
+
];
|
|
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",
|
|
128
|
+
};
|
|
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",
|
|
76
143
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
86
155
|
];
|
|
87
|
-
export const
|
|
88
|
-
|
|
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,
|
|
89
164
|
];
|
|
165
|
+
export const RELAY_LOCAL_ONLY_REQUEST_METHODS_V10 = [
|
|
166
|
+
RELAY_REQUEST_METHODS_V10.initialize,
|
|
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",
|
|
@@ -119,6 +202,7 @@ export const deviceIdSchema = z.string().uuid().brand();
|
|
|
119
202
|
export const workspaceIdSchema = z.string().uuid().brand();
|
|
120
203
|
export const relayRequestIdSchema = z.string().uuid().brand();
|
|
121
204
|
export const relayEnvelopeIdSchema = z.string().uuid();
|
|
205
|
+
export const relayInteractionIdSchema = interactionIdSchema;
|
|
122
206
|
export const relayApprovalCandidateParamsSchema = z
|
|
123
207
|
.object({
|
|
124
208
|
threadId: threadIdSchema,
|
|
@@ -135,25 +219,107 @@ export const relayApprovalCandidateResultSchema = z
|
|
|
135
219
|
})
|
|
136
220
|
.strict()
|
|
137
221
|
.readonly();
|
|
138
|
-
export const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
222
|
+
export const RELAY_INTERACTION_METHODS_V11 = {
|
|
223
|
+
approvalRequest: RUNTIME_SERVER_REQUEST_METHODS.approvalRequest,
|
|
224
|
+
userInputRequest: RUNTIME_SERVER_REQUEST_METHODS.userInputRequest,
|
|
225
|
+
};
|
|
226
|
+
export const RELAY_INTERACTION_METHOD_VALUES_V11 = [
|
|
227
|
+
RELAY_INTERACTION_METHODS_V11.approvalRequest,
|
|
228
|
+
RELAY_INTERACTION_METHODS_V11.userInputRequest,
|
|
229
|
+
];
|
|
230
|
+
export const relayApprovalInteractionProjectionSchemaV11 = z
|
|
231
|
+
.object({
|
|
232
|
+
approvalId: approvalIdSchema,
|
|
233
|
+
agentName: z.string().min(1),
|
|
234
|
+
toolName: z.string().min(1),
|
|
235
|
+
explanation: approvalExplanationSchema.optional(),
|
|
236
|
+
})
|
|
237
|
+
.strict()
|
|
238
|
+
.readonly();
|
|
239
|
+
export const relayUserInputInteractionProjectionSchemaV11 = userInputFormSchema;
|
|
240
|
+
const relayInteractionCandidateBaseFieldsV11 = {
|
|
241
|
+
interactionId: interactionIdSchema,
|
|
242
|
+
threadId: threadIdSchema,
|
|
243
|
+
turnId: turnIdSchema,
|
|
244
|
+
};
|
|
245
|
+
export const relayApprovalInteractionCandidateParamsSchemaV11 = z
|
|
246
|
+
.object({
|
|
247
|
+
...relayInteractionCandidateBaseFieldsV11,
|
|
248
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.approvalRequest),
|
|
249
|
+
candidate: approvalRequestResultSchema,
|
|
250
|
+
})
|
|
251
|
+
.strict()
|
|
252
|
+
.readonly();
|
|
253
|
+
export const relayUserInputInteractionCandidateParamsSchemaV11 = z
|
|
254
|
+
.object({
|
|
255
|
+
...relayInteractionCandidateBaseFieldsV11,
|
|
256
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.userInputRequest),
|
|
257
|
+
candidate: userInputResultSchema,
|
|
258
|
+
})
|
|
259
|
+
.strict()
|
|
260
|
+
.readonly();
|
|
261
|
+
export const relayInteractionCandidateParamsSchemaV11 = z.discriminatedUnion("method", [
|
|
262
|
+
relayApprovalInteractionCandidateParamsSchemaV11,
|
|
263
|
+
relayUserInputInteractionCandidateParamsSchemaV11,
|
|
264
|
+
]);
|
|
265
|
+
export const relayInteractionCandidateResultSchemaV11 = z
|
|
266
|
+
.object({ accepted: z.literal(true) })
|
|
267
|
+
.strict()
|
|
268
|
+
.readonly();
|
|
269
|
+
const relayCommonRequestMethodSchemas = {
|
|
270
|
+
initialize: runtimeMethodSchemasV11["initialize"],
|
|
271
|
+
threadList: runtimeMethodSchemasV11["thread.list"],
|
|
272
|
+
threadCreate: runtimeMethodSchemasV11["thread.create"],
|
|
273
|
+
threadOpen: runtimeMethodSchemasV11["thread.open"],
|
|
274
|
+
threadSnapshot: runtimeMethodSchemasV11["thread.snapshot"],
|
|
275
|
+
threadRename: runtimeMethodSchemasV11["thread.rename"],
|
|
276
|
+
threadDelete: runtimeMethodSchemasV11["thread.delete"],
|
|
277
|
+
threadDetach: runtimeMethodSchemasV11["thread.detach"],
|
|
278
|
+
threadCapabilities: runtimeMethodSchemasV11["thread.capabilities"],
|
|
279
|
+
turnStart: runtimeMethodSchemasV11["turn.start"],
|
|
280
|
+
turnCancel: runtimeMethodSchemasV11["turn.cancel"],
|
|
281
|
+
approvalRespond: runtimeMethodSchemasV11["approval.respond"],
|
|
282
|
+
operationGet: runtimeMethodSchemasV11["operation.get"],
|
|
283
|
+
};
|
|
284
|
+
export const relayRequestMethodSchemasV10 = {
|
|
285
|
+
[RELAY_REQUEST_METHODS_V10.initialize]: relayCommonRequestMethodSchemas.initialize,
|
|
286
|
+
[RELAY_REQUEST_METHODS_V10.threadList]: relayCommonRequestMethodSchemas.threadList,
|
|
287
|
+
[RELAY_REQUEST_METHODS_V10.threadCreate]: relayCommonRequestMethodSchemas.threadCreate,
|
|
288
|
+
[RELAY_REQUEST_METHODS_V10.threadOpen]: relayCommonRequestMethodSchemas.threadOpen,
|
|
289
|
+
[RELAY_REQUEST_METHODS_V10.threadSnapshot]: relayCommonRequestMethodSchemas.threadSnapshot,
|
|
290
|
+
[RELAY_REQUEST_METHODS_V10.threadRename]: relayCommonRequestMethodSchemas.threadRename,
|
|
291
|
+
[RELAY_REQUEST_METHODS_V10.threadDelete]: relayCommonRequestMethodSchemas.threadDelete,
|
|
292
|
+
[RELAY_REQUEST_METHODS_V10.threadDetach]: relayCommonRequestMethodSchemas.threadDetach,
|
|
293
|
+
[RELAY_REQUEST_METHODS_V10.threadCapabilities]: relayCommonRequestMethodSchemas.threadCapabilities,
|
|
294
|
+
[RELAY_REQUEST_METHODS_V10.turnStart]: relayCommonRequestMethodSchemas.turnStart,
|
|
295
|
+
[RELAY_REQUEST_METHODS_V10.turnCancel]: relayCommonRequestMethodSchemas.turnCancel,
|
|
296
|
+
[RELAY_REQUEST_METHODS_V10.approvalRespond]: relayCommonRequestMethodSchemas.approvalRespond,
|
|
297
|
+
[RELAY_REQUEST_METHODS_V10.operationGet]: relayCommonRequestMethodSchemas.operationGet,
|
|
298
|
+
[RELAY_REQUEST_METHODS_V10.approvalCandidate]: {
|
|
153
299
|
params: relayApprovalCandidateParamsSchema,
|
|
154
300
|
result: relayApprovalCandidateResultSchema,
|
|
155
301
|
},
|
|
156
302
|
};
|
|
303
|
+
export const relayRequestMethodSchemasV11 = {
|
|
304
|
+
[RELAY_REQUEST_METHODS_V11.initialize]: relayCommonRequestMethodSchemas.initialize,
|
|
305
|
+
[RELAY_REQUEST_METHODS_V11.threadList]: relayCommonRequestMethodSchemas.threadList,
|
|
306
|
+
[RELAY_REQUEST_METHODS_V11.threadCreate]: relayCommonRequestMethodSchemas.threadCreate,
|
|
307
|
+
[RELAY_REQUEST_METHODS_V11.threadOpen]: relayCommonRequestMethodSchemas.threadOpen,
|
|
308
|
+
[RELAY_REQUEST_METHODS_V11.threadSnapshot]: relayCommonRequestMethodSchemas.threadSnapshot,
|
|
309
|
+
[RELAY_REQUEST_METHODS_V11.threadRename]: relayCommonRequestMethodSchemas.threadRename,
|
|
310
|
+
[RELAY_REQUEST_METHODS_V11.threadDelete]: relayCommonRequestMethodSchemas.threadDelete,
|
|
311
|
+
[RELAY_REQUEST_METHODS_V11.threadDetach]: relayCommonRequestMethodSchemas.threadDetach,
|
|
312
|
+
[RELAY_REQUEST_METHODS_V11.threadCapabilities]: relayCommonRequestMethodSchemas.threadCapabilities,
|
|
313
|
+
[RELAY_REQUEST_METHODS_V11.turnStart]: relayCommonRequestMethodSchemas.turnStart,
|
|
314
|
+
[RELAY_REQUEST_METHODS_V11.turnCancel]: relayCommonRequestMethodSchemas.turnCancel,
|
|
315
|
+
[RELAY_REQUEST_METHODS_V11.operationGet]: relayCommonRequestMethodSchemas.operationGet,
|
|
316
|
+
[RELAY_REQUEST_METHODS_V11.interactionCandidate]: {
|
|
317
|
+
params: relayInteractionCandidateParamsSchemaV11,
|
|
318
|
+
result: relayInteractionCandidateResultSchemaV11,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
322
|
+
export const relayRequestMethodSchemas = relayRequestMethodSchemasV10;
|
|
157
323
|
export function isRelayRequestMethod(value) {
|
|
158
324
|
return Object.hasOwn(relayRequestMethodSchemas, value);
|
|
159
325
|
}
|
|
@@ -215,7 +381,7 @@ export const relayRuntimeEventSchema = z
|
|
|
215
381
|
type: z.literal(RELAY_MESSAGE_TYPES.runtimeEvent),
|
|
216
382
|
workspaceId: workspaceIdSchema,
|
|
217
383
|
relaySequence: z.number().int().nonnegative(),
|
|
218
|
-
event:
|
|
384
|
+
event: runtimeEventEnvelopeV11Schema,
|
|
219
385
|
})
|
|
220
386
|
.strict()
|
|
221
387
|
.readonly();
|
|
@@ -255,7 +421,332 @@ export const relayEncryptedMessageSchema = z
|
|
|
255
421
|
})
|
|
256
422
|
.strict()
|
|
257
423
|
.readonly();
|
|
258
|
-
export const
|
|
424
|
+
export const relayDeviceConnectSchemaV10 = relayDeviceConnectSchema;
|
|
425
|
+
export const relayRuntimeRequestSchemaV10 = relayRuntimeRequestSchema;
|
|
426
|
+
export const relayRuntimeResponseSchemaV10 = relayRuntimeResponseSchema;
|
|
427
|
+
export const relayRuntimeEventSchemaV10 = relayRuntimeEventSchema;
|
|
428
|
+
export const relayAckSchemaV10 = relayAckSchema;
|
|
429
|
+
export const relayGapSchemaV10 = relayGapSchema;
|
|
430
|
+
export const relayEncryptedMessageSchemaV10 = relayEncryptedMessageSchema;
|
|
431
|
+
export const relaySafeToolOutcomeSchemaV11 = z
|
|
432
|
+
.object({ kind: z.enum(TOOL_OUTCOME_KINDS) })
|
|
433
|
+
.strict()
|
|
434
|
+
.readonly();
|
|
435
|
+
export const relaySafeApprovalResolutionSchemaV11 = z.discriminatedUnion("status", [
|
|
436
|
+
z
|
|
437
|
+
.object({ status: z.literal("resolved"), decision: z.enum(["approve", "reject"]) })
|
|
438
|
+
.strict()
|
|
439
|
+
.readonly(),
|
|
440
|
+
z
|
|
441
|
+
.object({ status: z.literal("cancelled") })
|
|
442
|
+
.strict()
|
|
443
|
+
.readonly(),
|
|
444
|
+
z
|
|
445
|
+
.object({ status: z.literal("expired") })
|
|
446
|
+
.strict()
|
|
447
|
+
.readonly(),
|
|
448
|
+
]);
|
|
449
|
+
export const relayTimelineEventSchemaV11 = z.discriminatedUnion("type", [
|
|
450
|
+
z
|
|
451
|
+
.object({ type: z.literal("turn.started") })
|
|
452
|
+
.strict()
|
|
453
|
+
.readonly(),
|
|
454
|
+
z
|
|
455
|
+
.object({ type: z.literal("message.started"), streamId: streamIdSchema })
|
|
456
|
+
.strict()
|
|
457
|
+
.readonly(),
|
|
458
|
+
z
|
|
459
|
+
.object({ type: z.literal("message.delta"), streamId: streamIdSchema, delta: z.string() })
|
|
460
|
+
.strict()
|
|
461
|
+
.readonly(),
|
|
462
|
+
z
|
|
463
|
+
.object({ type: z.literal("message.completed"), streamId: streamIdSchema, text: z.string() })
|
|
464
|
+
.strict()
|
|
465
|
+
.readonly(),
|
|
466
|
+
z
|
|
467
|
+
.object({
|
|
468
|
+
type: z.literal("reasoning.summary.delta"),
|
|
469
|
+
reasoningId: z.string().min(1),
|
|
470
|
+
delta: z.string(),
|
|
471
|
+
})
|
|
472
|
+
.strict()
|
|
473
|
+
.readonly(),
|
|
474
|
+
z
|
|
475
|
+
.object({
|
|
476
|
+
type: z.literal("tool.started"),
|
|
477
|
+
toolCallId: z.string().min(1),
|
|
478
|
+
agentName: z.string().min(1),
|
|
479
|
+
toolName: z.string().min(1),
|
|
480
|
+
})
|
|
481
|
+
.strict()
|
|
482
|
+
.readonly(),
|
|
483
|
+
z
|
|
484
|
+
.object({
|
|
485
|
+
type: z.literal("tool.completed"),
|
|
486
|
+
toolCallId: z.string().min(1),
|
|
487
|
+
agentName: z.string().min(1),
|
|
488
|
+
toolName: z.string().min(1),
|
|
489
|
+
outcome: relaySafeToolOutcomeSchemaV11.optional(),
|
|
490
|
+
})
|
|
491
|
+
.strict()
|
|
492
|
+
.readonly(),
|
|
493
|
+
z
|
|
494
|
+
.object({
|
|
495
|
+
type: z.literal("approval.required"),
|
|
496
|
+
approval: relayApprovalInteractionProjectionSchemaV11,
|
|
497
|
+
})
|
|
498
|
+
.strict()
|
|
499
|
+
.readonly(),
|
|
500
|
+
z
|
|
501
|
+
.object({
|
|
502
|
+
type: z.literal("approval.resolved"),
|
|
503
|
+
approvalId: approvalIdSchema,
|
|
504
|
+
resolution: relaySafeApprovalResolutionSchemaV11,
|
|
505
|
+
})
|
|
506
|
+
.strict()
|
|
507
|
+
.readonly(),
|
|
508
|
+
z
|
|
509
|
+
.object({ type: z.literal("turn.completed") })
|
|
510
|
+
.strict()
|
|
511
|
+
.readonly(),
|
|
512
|
+
z
|
|
513
|
+
.object({ type: z.literal("turn.cancelled") })
|
|
514
|
+
.strict()
|
|
515
|
+
.readonly(),
|
|
516
|
+
z
|
|
517
|
+
.object({ type: z.literal("turn.failed"), stage: z.enum(["bootstrap", "plan", "execute"]) })
|
|
518
|
+
.strict()
|
|
519
|
+
.readonly(),
|
|
520
|
+
z
|
|
521
|
+
.object({ type: z.literal("capabilities.changed") })
|
|
522
|
+
.strict()
|
|
523
|
+
.readonly(),
|
|
524
|
+
]);
|
|
525
|
+
export const relayRuntimeEventEnvelopeSchemaV11 = z
|
|
526
|
+
.object({
|
|
527
|
+
protocolVersion: z.enum(["1.1", "1.0"]),
|
|
528
|
+
runtimeInstanceId: runtimeInstanceIdSchema,
|
|
529
|
+
sequence: z.number().int().nonnegative(),
|
|
530
|
+
timestamp: timestampSchema,
|
|
531
|
+
threadId: threadIdSchema,
|
|
532
|
+
turnId: turnIdSchema.optional(),
|
|
533
|
+
event: relayTimelineEventSchemaV11,
|
|
534
|
+
})
|
|
535
|
+
.strict()
|
|
536
|
+
.readonly();
|
|
537
|
+
function projectRelayTimelineEventV11(event) {
|
|
538
|
+
if (event.type === "tool.output") {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
if (event.type === "tool.started") {
|
|
542
|
+
return relayTimelineEventSchemaV11.parse({
|
|
543
|
+
type: event.type,
|
|
544
|
+
toolCallId: event.toolCallId,
|
|
545
|
+
agentName: event.agentName,
|
|
546
|
+
toolName: event.toolName,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (event.type === "tool.completed") {
|
|
550
|
+
return relayTimelineEventSchemaV11.parse({
|
|
551
|
+
type: event.type,
|
|
552
|
+
toolCallId: event.toolCallId,
|
|
553
|
+
agentName: event.agentName,
|
|
554
|
+
toolName: event.toolName,
|
|
555
|
+
...(event.outcome === undefined ? {} : { outcome: { kind: event.outcome.kind } }),
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
if (event.type === "approval.required") {
|
|
559
|
+
const explanation = getApprovalExplanation(event.approval);
|
|
560
|
+
return relayTimelineEventSchemaV11.parse({
|
|
561
|
+
type: event.type,
|
|
562
|
+
approval: {
|
|
563
|
+
approvalId: event.approval.id,
|
|
564
|
+
agentName: event.approval.agentName,
|
|
565
|
+
toolName: event.approval.toolName,
|
|
566
|
+
...(explanation === undefined ? {} : { explanation }),
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
if (event.type === "approval.resolved") {
|
|
571
|
+
const resolution = event.resolution.status === "resolved"
|
|
572
|
+
? { status: event.resolution.status, decision: event.resolution.decision }
|
|
573
|
+
: { status: event.resolution.status };
|
|
574
|
+
return relayTimelineEventSchemaV11.parse({
|
|
575
|
+
type: event.type,
|
|
576
|
+
approvalId: event.approvalId,
|
|
577
|
+
resolution,
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
if (event.type === "turn.cancelled") {
|
|
581
|
+
return relayTimelineEventSchemaV11.parse({ type: event.type });
|
|
582
|
+
}
|
|
583
|
+
if (event.type === "turn.failed") {
|
|
584
|
+
return relayTimelineEventSchemaV11.parse({ type: event.type, stage: event.stage });
|
|
585
|
+
}
|
|
586
|
+
return relayTimelineEventSchemaV11.parse(event);
|
|
587
|
+
}
|
|
588
|
+
export function projectRuntimeEventEnvelopeForRelayV11(value) {
|
|
589
|
+
const envelope = runtimeEventEnvelopeSchema.parse(value);
|
|
590
|
+
const event = projectRelayTimelineEventV11(envelope.event);
|
|
591
|
+
if (event === undefined) {
|
|
592
|
+
return undefined;
|
|
593
|
+
}
|
|
594
|
+
return relayRuntimeEventEnvelopeSchemaV11.parse({
|
|
595
|
+
protocolVersion: envelope.protocolVersion === "1.0" ? "1.0" : "1.1",
|
|
596
|
+
runtimeInstanceId: envelope.runtimeInstanceId,
|
|
597
|
+
sequence: envelope.sequence,
|
|
598
|
+
timestamp: envelope.timestamp,
|
|
599
|
+
threadId: envelope.threadId,
|
|
600
|
+
...(envelope.turnId === undefined ? {} : { turnId: envelope.turnId }),
|
|
601
|
+
event,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
function redactRelayOperationViewV11(operation) {
|
|
605
|
+
return operationViewSchema.parse({
|
|
606
|
+
id: operation.id,
|
|
607
|
+
sequence: operation.sequence,
|
|
608
|
+
toolCallId: operation.toolCallId,
|
|
609
|
+
agentName: operation.agentName,
|
|
610
|
+
toolName: operation.toolName,
|
|
611
|
+
createdAt: operation.createdAt,
|
|
612
|
+
outcome: { kind: operation.outcome.kind },
|
|
613
|
+
display: null,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function redactRelayPendingApprovalV11(approval) {
|
|
617
|
+
const explanation = getApprovalExplanation(approval);
|
|
618
|
+
return pendingApprovalSchema.parse({
|
|
619
|
+
id: approval.id,
|
|
620
|
+
turnId: approval.turnId,
|
|
621
|
+
agentName: approval.agentName,
|
|
622
|
+
toolName: approval.toolName,
|
|
623
|
+
preview: explanation === undefined ? null : { explanation },
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
/** Projects a Runtime snapshot into the allowlisted Relay Wire 1.1 query shape. */
|
|
627
|
+
export function projectRelayThreadSnapshotV11(value) {
|
|
628
|
+
const legacySnapshot = threadSnapshotV11Schema.safeParse(value);
|
|
629
|
+
const snapshot = legacySnapshot.success
|
|
630
|
+
? legacySnapshot.data
|
|
631
|
+
: projectThreadSnapshotForVersion("1.1", value);
|
|
632
|
+
return threadSnapshotV11Schema.parse({
|
|
633
|
+
thread: snapshot.thread,
|
|
634
|
+
messages: snapshot.messages,
|
|
635
|
+
operations: {
|
|
636
|
+
items: snapshot.operations.items.map(redactRelayOperationViewV11),
|
|
637
|
+
nextBeforeSequence: snapshot.operations.nextBeforeSequence,
|
|
638
|
+
},
|
|
639
|
+
...(snapshot.activeTurn === undefined ? {} : { activeTurn: snapshot.activeTurn }),
|
|
640
|
+
pendingApprovals: snapshot.pendingApprovals.map(redactRelayPendingApprovalV11),
|
|
641
|
+
transcriptCompleteness: snapshot.transcriptCompleteness,
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
/** Projects an operation query result without local display or outcome details. */
|
|
645
|
+
export function projectRelayOperationGetResultV11(value) {
|
|
646
|
+
const result = operationGetResultSchema.parse(value);
|
|
647
|
+
return operationGetResultSchema.parse({
|
|
648
|
+
operation: result.operation === null ? null : redactRelayOperationViewV11(result.operation),
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
const relayInteractionRequestBaseFieldsV11 = {
|
|
652
|
+
workspaceId: workspaceIdSchema,
|
|
653
|
+
relaySequence: z.number().int().nonnegative(),
|
|
654
|
+
interactionId: interactionIdSchema,
|
|
655
|
+
threadId: threadIdSchema,
|
|
656
|
+
turnId: turnIdSchema,
|
|
657
|
+
expiresAt: timestampSchema,
|
|
658
|
+
sensitivity: z.literal("normal"),
|
|
659
|
+
};
|
|
660
|
+
export const relayApprovalInteractionRequestSchemaV11 = z
|
|
661
|
+
.object({
|
|
662
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionRequest),
|
|
663
|
+
...relayInteractionRequestBaseFieldsV11,
|
|
664
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.approvalRequest),
|
|
665
|
+
projection: relayApprovalInteractionProjectionSchemaV11,
|
|
666
|
+
})
|
|
667
|
+
.strict()
|
|
668
|
+
.readonly();
|
|
669
|
+
export const relayUserInputInteractionRequestSchemaV11 = z
|
|
670
|
+
.object({
|
|
671
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionRequest),
|
|
672
|
+
...relayInteractionRequestBaseFieldsV11,
|
|
673
|
+
method: z.literal(RELAY_INTERACTION_METHODS_V11.userInputRequest),
|
|
674
|
+
projection: relayUserInputInteractionProjectionSchemaV11,
|
|
675
|
+
})
|
|
676
|
+
.strict()
|
|
677
|
+
.readonly();
|
|
678
|
+
export const relayInteractionRequestSchemaV11 = z.discriminatedUnion("method", [
|
|
679
|
+
relayApprovalInteractionRequestSchemaV11,
|
|
680
|
+
relayUserInputInteractionRequestSchemaV11,
|
|
681
|
+
]);
|
|
682
|
+
const relayInteractionTerminalBaseFieldsV11 = {
|
|
683
|
+
workspaceId: workspaceIdSchema,
|
|
684
|
+
relaySequence: z.number().int().nonnegative(),
|
|
685
|
+
interactionId: interactionIdSchema,
|
|
686
|
+
threadId: threadIdSchema,
|
|
687
|
+
turnId: turnIdSchema,
|
|
688
|
+
method: z.enum(RELAY_INTERACTION_METHOD_VALUES_V11),
|
|
689
|
+
};
|
|
690
|
+
export const relayInteractionResolvedSchemaV11 = z
|
|
691
|
+
.object({
|
|
692
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionResolved),
|
|
693
|
+
...relayInteractionTerminalBaseFieldsV11,
|
|
694
|
+
})
|
|
695
|
+
.strict()
|
|
696
|
+
.readonly();
|
|
697
|
+
export const relayInteractionCancelledSchemaV11 = z
|
|
698
|
+
.object({
|
|
699
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.interactionCancelled),
|
|
700
|
+
...relayInteractionTerminalBaseFieldsV11,
|
|
701
|
+
})
|
|
702
|
+
.strict()
|
|
703
|
+
.readonly();
|
|
704
|
+
export const relayDeviceConnectSchemaV11 = z
|
|
705
|
+
.object({
|
|
706
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.deviceConnect),
|
|
707
|
+
protocolVersion: z.literal("1.1"),
|
|
708
|
+
deviceId: deviceIdSchema,
|
|
709
|
+
pairingToken: z.string().min(16),
|
|
710
|
+
})
|
|
711
|
+
.strict()
|
|
712
|
+
.readonly();
|
|
713
|
+
export const relayRuntimeRequestSchemaV11 = z
|
|
714
|
+
.object({
|
|
715
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.runtimeRequest),
|
|
716
|
+
requestId: relayRequestIdSchema,
|
|
717
|
+
workspaceId: workspaceIdSchema,
|
|
718
|
+
method: z.enum(RELAY_REQUEST_METHOD_VALUES_V11),
|
|
719
|
+
params: jsonValueSchema,
|
|
720
|
+
})
|
|
721
|
+
.strict()
|
|
722
|
+
.readonly();
|
|
723
|
+
export const relayRuntimeResponseSchemaV11 = relayRuntimeResponseSchemaV10;
|
|
724
|
+
export const relayRuntimeEventSchemaV11 = z
|
|
725
|
+
.object({
|
|
726
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.runtimeEvent),
|
|
727
|
+
workspaceId: workspaceIdSchema,
|
|
728
|
+
relaySequence: z.number().int().nonnegative(),
|
|
729
|
+
event: relayRuntimeEventEnvelopeSchemaV11,
|
|
730
|
+
})
|
|
731
|
+
.strict()
|
|
732
|
+
.readonly();
|
|
733
|
+
export const relayAckSchemaV11 = relayAckSchemaV10;
|
|
734
|
+
export const relayGapSchemaV11 = relayGapSchemaV10;
|
|
735
|
+
export const relayEncryptedMessageSchemaV11 = z
|
|
736
|
+
.object({
|
|
737
|
+
type: z.literal(RELAY_MESSAGE_TYPES_V11.runtimeEncrypted),
|
|
738
|
+
workspaceId: workspaceIdSchema,
|
|
739
|
+
envelopeId: relayEnvelopeIdSchema,
|
|
740
|
+
payloadKind: z.enum(["request", "response", "event", "interaction"]),
|
|
741
|
+
requestId: relayRequestIdSchema.optional(),
|
|
742
|
+
relaySequence: z.number().int().nonnegative().optional(),
|
|
743
|
+
algorithm: z.string().min(1),
|
|
744
|
+
nonce: z.string().min(1),
|
|
745
|
+
ciphertext: z.string().min(1),
|
|
746
|
+
})
|
|
747
|
+
.strict()
|
|
748
|
+
.readonly();
|
|
749
|
+
export const relayMessageSchemasV10 = {
|
|
259
750
|
[RELAY_MESSAGE_TYPES.deviceConnect]: relayDeviceConnectSchema,
|
|
260
751
|
[RELAY_MESSAGE_TYPES.runtimeRequest]: relayRuntimeRequestSchema,
|
|
261
752
|
[RELAY_MESSAGE_TYPES.runtimeResponse]: relayRuntimeResponseSchema,
|
|
@@ -264,7 +755,7 @@ export const relayMessageSchemas = {
|
|
|
264
755
|
[RELAY_MESSAGE_TYPES.runtimeGap]: relayGapSchema,
|
|
265
756
|
[RELAY_MESSAGE_TYPES.runtimeEncrypted]: relayEncryptedMessageSchema,
|
|
266
757
|
};
|
|
267
|
-
export const
|
|
758
|
+
export const relayMessageSchemaV10 = z.discriminatedUnion("type", [
|
|
268
759
|
relayDeviceConnectSchema,
|
|
269
760
|
relayRuntimeRequestSchema,
|
|
270
761
|
relayRuntimeResponseSchema,
|
|
@@ -273,17 +764,113 @@ export const relayMessageSchema = z.discriminatedUnion("type", [
|
|
|
273
764
|
relayGapSchema,
|
|
274
765
|
relayEncryptedMessageSchema,
|
|
275
766
|
]);
|
|
767
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
768
|
+
export const relayMessageSchemas = relayMessageSchemasV10;
|
|
769
|
+
/** @deprecated Legacy generic Relay exports remain pinned to Wire 1.0. */
|
|
770
|
+
export const relayMessageSchema = relayMessageSchemaV10;
|
|
771
|
+
export const relayMessageSchemasV11 = {
|
|
772
|
+
[RELAY_MESSAGE_TYPES_V11.deviceConnect]: relayDeviceConnectSchemaV11,
|
|
773
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeRequest]: relayRuntimeRequestSchemaV11,
|
|
774
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeResponse]: relayRuntimeResponseSchemaV11,
|
|
775
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeEvent]: relayRuntimeEventSchemaV11,
|
|
776
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeAck]: relayAckSchemaV11,
|
|
777
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeGap]: relayGapSchemaV11,
|
|
778
|
+
[RELAY_MESSAGE_TYPES_V11.runtimeEncrypted]: relayEncryptedMessageSchemaV11,
|
|
779
|
+
[RELAY_MESSAGE_TYPES_V11.interactionRequest]: relayInteractionRequestSchemaV11,
|
|
780
|
+
[RELAY_MESSAGE_TYPES_V11.interactionResolved]: relayInteractionResolvedSchemaV11,
|
|
781
|
+
[RELAY_MESSAGE_TYPES_V11.interactionCancelled]: relayInteractionCancelledSchemaV11,
|
|
782
|
+
};
|
|
783
|
+
export const relayMessageSchemaV11 = z.discriminatedUnion("type", [
|
|
784
|
+
relayDeviceConnectSchemaV11,
|
|
785
|
+
relayRuntimeRequestSchemaV11,
|
|
786
|
+
relayRuntimeResponseSchemaV11,
|
|
787
|
+
relayRuntimeEventSchemaV11,
|
|
788
|
+
relayAckSchemaV11,
|
|
789
|
+
relayGapSchemaV11,
|
|
790
|
+
relayEncryptedMessageSchemaV11,
|
|
791
|
+
relayInteractionRequestSchemaV11,
|
|
792
|
+
relayInteractionResolvedSchemaV11,
|
|
793
|
+
relayInteractionCancelledSchemaV11,
|
|
794
|
+
]);
|
|
276
795
|
export const RELAY_PROTOCOL_REGISTRY = {
|
|
796
|
+
"1.1": {
|
|
797
|
+
messageTypes: RELAY_MESSAGE_TYPE_VALUES_V11,
|
|
798
|
+
messageSchema: relayMessageSchemaV11,
|
|
799
|
+
requestMethods: RELAY_REQUEST_METHOD_VALUES_V11,
|
|
800
|
+
requestMethodSchemas: relayRequestMethodSchemasV11,
|
|
801
|
+
requestMethodDispositions: RELAY_REQUEST_METHOD_DISPOSITIONS_V11,
|
|
802
|
+
mutationMethods: RELAY_MUTATION_REQUEST_METHODS_V11,
|
|
803
|
+
localOnlyMethods: RELAY_LOCAL_ONLY_REQUEST_METHODS_V11,
|
|
804
|
+
},
|
|
277
805
|
"1.0": {
|
|
278
|
-
messageTypes:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
806
|
+
messageTypes: RELAY_MESSAGE_TYPE_VALUES_V10,
|
|
807
|
+
messageSchema: relayMessageSchemaV10,
|
|
808
|
+
requestMethods: RELAY_REQUEST_METHOD_VALUES_V10,
|
|
809
|
+
requestMethodSchemas: relayRequestMethodSchemasV10,
|
|
810
|
+
requestMethodDispositions: RELAY_REQUEST_METHOD_DISPOSITIONS_V10,
|
|
811
|
+
mutationMethods: RELAY_MUTATION_REQUEST_METHODS_V10,
|
|
812
|
+
localOnlyMethods: RELAY_LOCAL_ONLY_REQUEST_METHODS_V10,
|
|
282
813
|
},
|
|
283
814
|
};
|
|
284
815
|
export function getRelayProtocolRegistry(version) {
|
|
285
816
|
return RELAY_PROTOCOL_REGISTRY[version];
|
|
286
817
|
}
|
|
818
|
+
export function parseRelayMessageForVersion(version, value) {
|
|
819
|
+
return getRelayProtocolRegistry(version).messageSchema.parse(value);
|
|
820
|
+
}
|
|
821
|
+
export function isRelayRequestMethodForVersion(version, value) {
|
|
822
|
+
return Object.hasOwn(getRelayProtocolRegistry(version).requestMethodSchemas, value);
|
|
823
|
+
}
|
|
824
|
+
export function getRelayRequestMethodDispositionForVersion(version, value) {
|
|
825
|
+
if (!isRelayRequestMethodForVersion(version, value)) {
|
|
826
|
+
return undefined;
|
|
827
|
+
}
|
|
828
|
+
const dispositions = getRelayProtocolRegistry(version).requestMethodDispositions;
|
|
829
|
+
return dispositions[value];
|
|
830
|
+
}
|
|
831
|
+
export function parseRelayRequestParamsForVersion(version, method, value) {
|
|
832
|
+
const definitions = getRelayProtocolRegistry(version).requestMethodSchemas;
|
|
833
|
+
const definition = definitions[method];
|
|
834
|
+
if (definition === undefined) {
|
|
835
|
+
throw new Error(`Relay request method ${method} is unavailable in Wire ${version}`);
|
|
836
|
+
}
|
|
837
|
+
return definition.params.parse(value);
|
|
838
|
+
}
|
|
839
|
+
export function parseRelayRequestResultForVersion(version, method, value) {
|
|
840
|
+
const definitions = getRelayProtocolRegistry(version).requestMethodSchemas;
|
|
841
|
+
const definition = definitions[method];
|
|
842
|
+
if (definition === undefined) {
|
|
843
|
+
throw new Error(`Relay request method ${method} is unavailable in Wire ${version}`);
|
|
844
|
+
}
|
|
845
|
+
return definition.result.parse(value);
|
|
846
|
+
}
|
|
847
|
+
export function parseRelayInteractionCandidateForRequestV11(request, candidate) {
|
|
848
|
+
const base = {
|
|
849
|
+
interactionId: request.interactionId,
|
|
850
|
+
threadId: request.threadId,
|
|
851
|
+
turnId: request.turnId,
|
|
852
|
+
};
|
|
853
|
+
if (request.method === RELAY_INTERACTION_METHODS_V11.approvalRequest) {
|
|
854
|
+
return relayInteractionCandidateParamsSchemaV11.parse({
|
|
855
|
+
...base,
|
|
856
|
+
method: request.method,
|
|
857
|
+
candidate: approvalRequestResultSchema.parse(candidate),
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
const normalized = normalizeUserInputResult({
|
|
861
|
+
interactionId: request.interactionId,
|
|
862
|
+
threadId: request.threadId,
|
|
863
|
+
turnId: request.turnId,
|
|
864
|
+
expiresAt: request.expiresAt,
|
|
865
|
+
sensitivity: request.sensitivity,
|
|
866
|
+
...request.projection,
|
|
867
|
+
}, candidate);
|
|
868
|
+
return relayInteractionCandidateParamsSchemaV11.parse({
|
|
869
|
+
...base,
|
|
870
|
+
method: request.method,
|
|
871
|
+
candidate: normalized,
|
|
872
|
+
});
|
|
873
|
+
}
|
|
287
874
|
export function negotiateRelayProtocolVersion(peerVersions) {
|
|
288
875
|
return SUPPORTED_RELAY_PROTOCOL_VERSIONS.find((version) => peerVersions.includes(version));
|
|
289
876
|
}
|