@adea-ai/runtime-gateway-protocol 1.16.0 → 1.16.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 +12 -23
- package/dist/device-relay.d.ts +2 -0
- package/dist/device-relay.js +14 -0
- package/dist/device-sync.d.ts +239 -0
- package/dist/device-sync.js +437 -0
- package/dist/index.d.ts +2 -6
- package/dist/index.js +2 -6
- package/package.json +13 -18
- package/dist/acp-remote-sealed-channel.d.ts +0 -12
- package/dist/acp-remote-sealed-channel.js +0 -1
- package/dist/authentication.d.ts +0 -45
- package/dist/authentication.js +0 -71
- package/dist/emulator.d.ts +0 -24
- package/dist/emulator.js +0 -137
- package/dist/fixtures.d.ts +0 -149
- package/dist/fixtures.js +0 -48
- package/dist/protocol.d.ts +0 -716
- package/dist/protocol.js +0 -522
- package/dist/public-identity-validation-compatibility.d.ts +0 -1
- package/dist/public-identity-validation-compatibility.js +0 -10
- package/fixtures/golden/envelopes.json +0 -153
- package/fixtures/index.mjs +0 -4
- package/fixtures/malformed/envelopes.json +0 -70
- package/schema/gateway-envelope.v1.json +0 -990
package/dist/protocol.js
DELETED
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { RuntimeUsageSchema } from '@adea-ai/runtime-sdk';
|
|
3
|
-
const canonicalId = (prefix, label) => z.string().regex(new RegExp(`^${prefix}_[0-9A-HJKMNP-TV-Z]{26}$`), `Invalid ${label}`);
|
|
4
|
-
const TimestampSchema = z.iso.datetime();
|
|
5
|
-
const DigestSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
6
|
-
const CapabilitySchema = z.string().regex(/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/);
|
|
7
|
-
const DriverFamilySchema = z.string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/);
|
|
8
|
-
const VersionStringSchema = z.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/);
|
|
9
|
-
const forbiddenPayloadKeys = [
|
|
10
|
-
'command',
|
|
11
|
-
'credential',
|
|
12
|
-
'cwd',
|
|
13
|
-
'databaseid',
|
|
14
|
-
'directory',
|
|
15
|
-
'endpoint',
|
|
16
|
-
'executable',
|
|
17
|
-
'file',
|
|
18
|
-
'host',
|
|
19
|
-
'localpath',
|
|
20
|
-
'password',
|
|
21
|
-
'path',
|
|
22
|
-
'privatekey',
|
|
23
|
-
'projectid',
|
|
24
|
-
'sourcescope',
|
|
25
|
-
'token',
|
|
26
|
-
'url',
|
|
27
|
-
];
|
|
28
|
-
const safePayloadKeys = new Set(['profile', 'profileid', 'profileversionid']);
|
|
29
|
-
export const GatewayProtocolVersionSchema = z
|
|
30
|
-
.object({ major: z.number().int().positive(), minor: z.number().int().nonnegative() })
|
|
31
|
-
.strict();
|
|
32
|
-
export const GatewayProtocolManifest = Object.freeze({
|
|
33
|
-
name: 'control-plane-runtime-gateway',
|
|
34
|
-
current: { major: 1, minor: 8 },
|
|
35
|
-
supported: [
|
|
36
|
-
{ major: 1, minor: 0 },
|
|
37
|
-
{ major: 1, minor: 1 },
|
|
38
|
-
{ major: 1, minor: 2 },
|
|
39
|
-
{ major: 1, minor: 3 },
|
|
40
|
-
{ major: 1, minor: 4 },
|
|
41
|
-
{ major: 1, minor: 5 },
|
|
42
|
-
{ major: 1, minor: 6 },
|
|
43
|
-
{ major: 1, minor: 7 },
|
|
44
|
-
{ major: 1, minor: 8 },
|
|
45
|
-
],
|
|
46
|
-
});
|
|
47
|
-
export const GatewayProtocolDeprecationSchema = z
|
|
48
|
-
.object({
|
|
49
|
-
version: GatewayProtocolVersionSchema,
|
|
50
|
-
deprecatedAt: TimestampSchema,
|
|
51
|
-
sunsetAt: TimestampSchema.optional(),
|
|
52
|
-
replacement: GatewayProtocolVersionSchema.optional(),
|
|
53
|
-
})
|
|
54
|
-
.strict()
|
|
55
|
-
.superRefine((deprecation, context) => {
|
|
56
|
-
if (deprecation.sunsetAt !== undefined &&
|
|
57
|
-
Date.parse(deprecation.sunsetAt) <= Date.parse(deprecation.deprecatedAt)) {
|
|
58
|
-
context.addIssue({
|
|
59
|
-
code: 'custom',
|
|
60
|
-
path: ['sunsetAt'],
|
|
61
|
-
message: 'Protocol sunset must follow deprecation',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
export function negotiateGatewayProtocolVersion(localValues, remoteValues) {
|
|
66
|
-
const local = highestMinor(localValues);
|
|
67
|
-
const remote = highestMinor(remoteValues);
|
|
68
|
-
const major = [...local.keys()]
|
|
69
|
-
.filter((candidate) => remote.has(candidate))
|
|
70
|
-
.toSorted((left, right) => right - left)[0];
|
|
71
|
-
return major === undefined
|
|
72
|
-
? undefined
|
|
73
|
-
: { major, minor: Math.min(local.get(major) ?? 0, remote.get(major) ?? 0) };
|
|
74
|
-
}
|
|
75
|
-
const CommonEnvelopeSchema = z
|
|
76
|
-
.object({
|
|
77
|
-
schemaVersion: z.literal(1),
|
|
78
|
-
protocolVersion: GatewayProtocolVersionSchema,
|
|
79
|
-
sequence: z.number().int().nonnegative().max(2_147_483_647),
|
|
80
|
-
nodeId: canonicalId('rnr', 'RuntimeNode ID'),
|
|
81
|
-
workspaceId: canonicalId('wsp', 'workspace ID'),
|
|
82
|
-
traceId: canonicalId('trc', 'trace ID'),
|
|
83
|
-
sentAt: TimestampSchema,
|
|
84
|
-
channelGeneration: z.number().int().positive(),
|
|
85
|
-
})
|
|
86
|
-
.strict();
|
|
87
|
-
export const GatewayArtifactReferenceSchema = z
|
|
88
|
-
.object({
|
|
89
|
-
artifactId: canonicalId('art', 'Artifact ID'),
|
|
90
|
-
digest: DigestSchema,
|
|
91
|
-
mediaType: z.string().min(1).max(128),
|
|
92
|
-
sizeBytes: z
|
|
93
|
-
.number()
|
|
94
|
-
.int()
|
|
95
|
-
.nonnegative()
|
|
96
|
-
.max(64 * 1024 * 1024),
|
|
97
|
-
})
|
|
98
|
-
.strict();
|
|
99
|
-
const InlinePayloadSchema = z
|
|
100
|
-
.object({
|
|
101
|
-
version: z.number().int().positive(),
|
|
102
|
-
parameters: z.record(z.string(), z.json()),
|
|
103
|
-
})
|
|
104
|
-
.strict()
|
|
105
|
-
.superRefine((payload, context) => rejectPrivilegedPayload(payload.parameters, context));
|
|
106
|
-
const CommandPayloadSchema = z.union([
|
|
107
|
-
InlinePayloadSchema,
|
|
108
|
-
z
|
|
109
|
-
.object({ version: z.number().int().positive(), artifact: GatewayArtifactReferenceSchema })
|
|
110
|
-
.strict(),
|
|
111
|
-
]);
|
|
112
|
-
export const GatewayRetainedCommandOutcomeSchema = z
|
|
113
|
-
.object({
|
|
114
|
-
commandId: canonicalId('cmd', 'command ID'),
|
|
115
|
-
payloadHash: DigestSchema,
|
|
116
|
-
status: z.enum([
|
|
117
|
-
'accepted',
|
|
118
|
-
'running',
|
|
119
|
-
'cancelling',
|
|
120
|
-
'succeeded',
|
|
121
|
-
'failed',
|
|
122
|
-
'cancelled',
|
|
123
|
-
'unknown',
|
|
124
|
-
]),
|
|
125
|
-
observedAt: TimestampSchema,
|
|
126
|
-
result: z
|
|
127
|
-
.union([
|
|
128
|
-
z.object({ data: z.record(z.string(), z.json()) }).strict(),
|
|
129
|
-
z.object({ artifact: GatewayArtifactReferenceSchema }).strict(),
|
|
130
|
-
])
|
|
131
|
-
.optional(),
|
|
132
|
-
})
|
|
133
|
-
.strict()
|
|
134
|
-
.superRefine((outcome, context) => {
|
|
135
|
-
if (outcome.status === 'succeeded' && outcome.result === undefined) {
|
|
136
|
-
context.addIssue({
|
|
137
|
-
code: 'custom',
|
|
138
|
-
path: ['result'],
|
|
139
|
-
message: 'Successful retained outcomes require a result',
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
export const GatewayHelloEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
144
|
-
type: z.literal('hello'),
|
|
145
|
-
supportedVersions: z.array(GatewayProtocolVersionSchema).min(1).max(16),
|
|
146
|
-
lastAcknowledgedSequence: z.number().int().nonnegative(),
|
|
147
|
-
retainedCommandOutcomes: z.array(GatewayRetainedCommandOutcomeSchema).max(256).optional(),
|
|
148
|
-
})
|
|
149
|
-
.strict()
|
|
150
|
-
.superRefine((hello, context) => {
|
|
151
|
-
const outcomes = hello.retainedCommandOutcomes ?? [];
|
|
152
|
-
if (new Set(outcomes.map(({ commandId }) => commandId)).size !== outcomes.length) {
|
|
153
|
-
context.addIssue({
|
|
154
|
-
code: 'custom',
|
|
155
|
-
path: ['retainedCommandOutcomes'],
|
|
156
|
-
message: 'Retained command outcomes must be unique',
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
if (outcomes.length > 0 && hello.protocolVersion.minor < 3) {
|
|
160
|
-
context.addIssue({
|
|
161
|
-
code: 'custom',
|
|
162
|
-
path: ['retainedCommandOutcomes'],
|
|
163
|
-
message: 'Retained outcomes require protocol v1.3',
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
const GatewayCommandBaseSchema = CommonEnvelopeSchema.extend({
|
|
168
|
-
type: z.literal('command'),
|
|
169
|
-
canonicalizationVersion: z.union([z.literal(1), z.literal(2)]).optional(),
|
|
170
|
-
commandId: canonicalId('cmd', 'command ID'),
|
|
171
|
-
idempotencyKey: z
|
|
172
|
-
.string()
|
|
173
|
-
.min(16)
|
|
174
|
-
.max(128)
|
|
175
|
-
.regex(/^[A-Za-z0-9._:-]+$/),
|
|
176
|
-
payloadHash: DigestSchema,
|
|
177
|
-
issuedAt: TimestampSchema,
|
|
178
|
-
expiresAt: TimestampSchema,
|
|
179
|
-
family: z.enum(['runtime', 'context_provider']),
|
|
180
|
-
operation: z.enum([
|
|
181
|
-
'runtime.execute',
|
|
182
|
-
'runtime.cancel',
|
|
183
|
-
'runtime.input',
|
|
184
|
-
'runtime.approval',
|
|
185
|
-
'runtime.status',
|
|
186
|
-
'runtime.session',
|
|
187
|
-
'runtime.acp-remote-sealed',
|
|
188
|
-
'context.status',
|
|
189
|
-
'context.read',
|
|
190
|
-
'context.write',
|
|
191
|
-
]),
|
|
192
|
-
driver: z.object({ family: DriverFamilySchema, version: VersionStringSchema }).strict(),
|
|
193
|
-
runtimeConnectionId: canonicalId('rtc', 'runtime connection ID').optional(),
|
|
194
|
-
executionId: canonicalId('exe', 'execution ID').optional(),
|
|
195
|
-
attemptId: canonicalId('att', 'attempt ID').optional(),
|
|
196
|
-
providerRef: canonicalId('pvr', 'context provider reference').optional(),
|
|
197
|
-
authorizationRef: z
|
|
198
|
-
.string()
|
|
199
|
-
.min(16)
|
|
200
|
-
.max(128)
|
|
201
|
-
.regex(/^authz:[A-Za-z0-9._:-]+$/)
|
|
202
|
-
.optional(),
|
|
203
|
-
requiredCapabilities: z.array(CapabilitySchema).min(1).max(64),
|
|
204
|
-
payload: CommandPayloadSchema,
|
|
205
|
-
});
|
|
206
|
-
export const GatewayCommandEnvelopeSchema = GatewayCommandBaseSchema.strict().superRefine((command, context) => {
|
|
207
|
-
if (command.canonicalizationVersion !== undefined &&
|
|
208
|
-
command.protocolVersion.major === 1 &&
|
|
209
|
-
command.protocolVersion.minor < 8) {
|
|
210
|
-
context.addIssue({
|
|
211
|
-
code: 'custom',
|
|
212
|
-
path: ['canonicalizationVersion'],
|
|
213
|
-
message: 'Command canonicalization versions require protocol v1.8 or later',
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
if (Date.parse(command.expiresAt) <= Date.parse(command.issuedAt)) {
|
|
217
|
-
context.addIssue({
|
|
218
|
-
code: 'custom',
|
|
219
|
-
path: ['expiresAt'],
|
|
220
|
-
message: 'Command expiry must follow issue time',
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (command.family === 'runtime') {
|
|
224
|
-
for (const field of ['runtimeConnectionId', 'executionId', 'attemptId']) {
|
|
225
|
-
if (command[field] === undefined) {
|
|
226
|
-
context.addIssue({
|
|
227
|
-
code: 'custom',
|
|
228
|
-
path: [field],
|
|
229
|
-
message: `${field} is required for runtime commands`,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (!command.operation.startsWith('runtime.')) {
|
|
234
|
-
context.addIssue({
|
|
235
|
-
code: 'custom',
|
|
236
|
-
path: ['operation'],
|
|
237
|
-
message: 'Runtime command operation mismatch',
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
const controlCapability = command.operation === 'runtime.cancel'
|
|
241
|
-
? 'execution.cancel'
|
|
242
|
-
: command.operation === 'runtime.input'
|
|
243
|
-
? 'interaction.user-input'
|
|
244
|
-
: command.operation === 'runtime.approval'
|
|
245
|
-
? 'interaction.approval'
|
|
246
|
-
: command.operation === 'runtime.status'
|
|
247
|
-
? 'stream.events'
|
|
248
|
-
: undefined;
|
|
249
|
-
if (controlCapability && !command.requiredCapabilities.includes(controlCapability)) {
|
|
250
|
-
context.addIssue({
|
|
251
|
-
code: 'custom',
|
|
252
|
-
path: ['requiredCapabilities'],
|
|
253
|
-
message: 'Runtime control command requires its operation capability',
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
if (command.operation === 'runtime.session') {
|
|
257
|
-
if (command.protocolVersion.minor < 5) {
|
|
258
|
-
context.addIssue({
|
|
259
|
-
code: 'custom',
|
|
260
|
-
path: ['protocolVersion'],
|
|
261
|
-
message: 'Runtime session commands require protocol v1.5',
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
if (!command.requiredCapabilities.some((capability) => capability.startsWith('session.'))) {
|
|
265
|
-
context.addIssue({
|
|
266
|
-
code: 'custom',
|
|
267
|
-
path: ['requiredCapabilities'],
|
|
268
|
-
message: 'Runtime session commands require a session capability',
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
if (command.providerRef === undefined) {
|
|
275
|
-
context.addIssue({
|
|
276
|
-
code: 'custom',
|
|
277
|
-
path: ['providerRef'],
|
|
278
|
-
message: 'providerRef is required',
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
if (!command.operation.startsWith('context.')) {
|
|
282
|
-
context.addIssue({
|
|
283
|
-
code: 'custom',
|
|
284
|
-
path: ['operation'],
|
|
285
|
-
message: 'Provider command operation mismatch',
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
if (command.operation === 'context.write' && command.authorizationRef === undefined) {
|
|
289
|
-
context.addIssue({
|
|
290
|
-
code: 'custom',
|
|
291
|
-
path: ['authorizationRef'],
|
|
292
|
-
message: 'Writes require separate authorization',
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
export const GatewayAcknowledgementEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
298
|
-
type: z.literal('ack'),
|
|
299
|
-
commandId: canonicalId('cmd', 'command ID'),
|
|
300
|
-
payloadHash: DigestSchema,
|
|
301
|
-
disposition: z.enum(['accepted', 'replayed', 'rejected', 'expired']),
|
|
302
|
-
}).strict();
|
|
303
|
-
export const GatewayProgressEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
304
|
-
type: z.literal('progress'),
|
|
305
|
-
commandId: canonicalId('cmd', 'command ID'),
|
|
306
|
-
payloadHash: DigestSchema,
|
|
307
|
-
eventSequence: z.number().int().positive().max(2_147_483_647),
|
|
308
|
-
event: z.object({ kind: CapabilitySchema, data: z.record(z.string(), z.json()) }).strict(),
|
|
309
|
-
}).strict();
|
|
310
|
-
export const GatewayResultEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
311
|
-
type: z.literal('result'),
|
|
312
|
-
commandId: canonicalId('cmd', 'command ID'),
|
|
313
|
-
payloadHash: DigestSchema,
|
|
314
|
-
status: z.enum(['succeeded', 'failed', 'cancelled']),
|
|
315
|
-
completedAt: TimestampSchema,
|
|
316
|
-
terminalUsage: RuntimeUsageSchema.optional(),
|
|
317
|
-
result: z.union([
|
|
318
|
-
z.object({ data: z.record(z.string(), z.json()) }).strict(),
|
|
319
|
-
z.object({ artifact: GatewayArtifactReferenceSchema }).strict(),
|
|
320
|
-
]),
|
|
321
|
-
})
|
|
322
|
-
.strict()
|
|
323
|
-
.superRefine((result, context) => {
|
|
324
|
-
if (result.terminalUsage !== undefined && result.protocolVersion.minor < 7) {
|
|
325
|
-
context.addIssue({
|
|
326
|
-
code: 'custom',
|
|
327
|
-
path: ['terminalUsage'],
|
|
328
|
-
message: 'Terminal usage requires protocol v1.7',
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
export const GatewayCancellationEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
333
|
-
type: z.literal('cancel'),
|
|
334
|
-
commandId: canonicalId('cmd', 'command ID'),
|
|
335
|
-
payloadHash: DigestSchema,
|
|
336
|
-
requestedAt: TimestampSchema,
|
|
337
|
-
reason: z.enum(['user_requested', 'policy_revoked', 'deadline_exceeded', 'shutdown']),
|
|
338
|
-
}).strict();
|
|
339
|
-
export const GatewayHeartbeatEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
340
|
-
type: z.literal('heartbeat'),
|
|
341
|
-
observedAt: TimestampSchema,
|
|
342
|
-
status: z.enum(['online', 'degraded', 'draining']),
|
|
343
|
-
}).strict();
|
|
344
|
-
const DriverInventorySchema = z
|
|
345
|
-
.object({
|
|
346
|
-
opaqueRef: z.string().regex(/^(?:nref|pvr)_[0-9A-HJKMNP-TV-Z]{26}$/),
|
|
347
|
-
driverFamily: DriverFamilySchema,
|
|
348
|
-
adapterVersion: VersionStringSchema.optional(),
|
|
349
|
-
driverVersion: VersionStringSchema,
|
|
350
|
-
harnessVersion: VersionStringSchema.optional(),
|
|
351
|
-
capabilityTtlMs: z.number().int().positive().max(60_000).optional(),
|
|
352
|
-
protocolVersion: GatewayProtocolVersionSchema,
|
|
353
|
-
health: z.enum(['healthy', 'degraded', 'unavailable']),
|
|
354
|
-
capabilities: z.array(CapabilitySchema).max(128),
|
|
355
|
-
limitations: z.array(z.string().regex(/^[A-Z][A-Z0-9_]*$/)).max(64),
|
|
356
|
-
})
|
|
357
|
-
.strict();
|
|
358
|
-
export const GatewayInventoryEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
359
|
-
type: z.literal('inventory'),
|
|
360
|
-
mode: z.enum(['snapshot', 'delta']).optional(),
|
|
361
|
-
snapshotVersion: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
362
|
-
baseSnapshotVersion: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).optional(),
|
|
363
|
-
observedAt: TimestampSchema,
|
|
364
|
-
runtimeDrivers: z.array(DriverInventorySchema).max(128),
|
|
365
|
-
contextProviders: z.array(DriverInventorySchema).max(32),
|
|
366
|
-
removedRuntimeRefs: z
|
|
367
|
-
.array(z.string().regex(/^nref_[0-9A-HJKMNP-TV-Z]{26}$/))
|
|
368
|
-
.max(128)
|
|
369
|
-
.optional(),
|
|
370
|
-
})
|
|
371
|
-
.strict()
|
|
372
|
-
.superRefine((inventory, context) => {
|
|
373
|
-
for (const family of ['runtimeDrivers', 'contextProviders']) {
|
|
374
|
-
inventory[family].forEach((driver, index) => {
|
|
375
|
-
if (driver.capabilityTtlMs !== undefined && inventory.protocolVersion.minor < 6) {
|
|
376
|
-
context.addIssue({
|
|
377
|
-
code: 'custom',
|
|
378
|
-
path: [family, index, 'capabilityTtlMs'],
|
|
379
|
-
message: 'Advertised capability TTL requires protocol v1.6',
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
const mode = inventory.mode ?? 'snapshot';
|
|
385
|
-
if (mode === 'delta' && inventory.protocolVersion.minor < 2) {
|
|
386
|
-
context.addIssue({
|
|
387
|
-
code: 'custom',
|
|
388
|
-
path: ['mode'],
|
|
389
|
-
message: 'Inventory deltas require protocol v1.2',
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
if (mode === 'delta' && inventory.baseSnapshotVersion === undefined) {
|
|
393
|
-
context.addIssue({
|
|
394
|
-
code: 'custom',
|
|
395
|
-
path: ['baseSnapshotVersion'],
|
|
396
|
-
message: 'Inventory deltas require a base snapshot version',
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
if (mode === 'snapshot' && inventory.baseSnapshotVersion !== undefined) {
|
|
400
|
-
context.addIssue({
|
|
401
|
-
code: 'custom',
|
|
402
|
-
path: ['baseSnapshotVersion'],
|
|
403
|
-
message: 'Inventory snapshots cannot declare a base version',
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
const runtimeRefs = inventory.runtimeDrivers.map(({ opaqueRef }) => opaqueRef);
|
|
407
|
-
const removedRefs = inventory.removedRuntimeRefs ?? [];
|
|
408
|
-
if (new Set(runtimeRefs).size !== runtimeRefs.length ||
|
|
409
|
-
new Set(removedRefs).size !== removedRefs.length) {
|
|
410
|
-
context.addIssue({ code: 'custom', message: 'Inventory runtime references must be unique' });
|
|
411
|
-
}
|
|
412
|
-
if (runtimeRefs.some((runtimeRef) => removedRefs.includes(runtimeRef))) {
|
|
413
|
-
context.addIssue({
|
|
414
|
-
code: 'custom',
|
|
415
|
-
message: 'Inventory cannot update and remove the same runtime',
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
if (inventory.protocolVersion.minor >= 2) {
|
|
419
|
-
inventory.runtimeDrivers.forEach((driver, index) => {
|
|
420
|
-
if (driver.adapterVersion === undefined) {
|
|
421
|
-
context.addIssue({
|
|
422
|
-
code: 'custom',
|
|
423
|
-
path: ['runtimeDrivers', index, 'adapterVersion'],
|
|
424
|
-
message: 'Protocol v1.2 runtime inventory requires an adapter version',
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
if (driver.harnessVersion === undefined) {
|
|
428
|
-
context.addIssue({
|
|
429
|
-
code: 'custom',
|
|
430
|
-
path: ['runtimeDrivers', index, 'harnessVersion'],
|
|
431
|
-
message: 'Protocol v1.2 runtime inventory requires a harness version',
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
export const GatewayErrorEnvelopeSchema = CommonEnvelopeSchema.extend({
|
|
438
|
-
type: z.literal('error'),
|
|
439
|
-
commandId: canonicalId('cmd', 'command ID').optional(),
|
|
440
|
-
payloadHash: DigestSchema.optional(),
|
|
441
|
-
code: z
|
|
442
|
-
.string()
|
|
443
|
-
.regex(/^[A-Z][A-Z0-9_]*$/)
|
|
444
|
-
.max(96),
|
|
445
|
-
retryable: z.boolean(),
|
|
446
|
-
}).strict();
|
|
447
|
-
export const GatewayEnvelopeSchema = z.discriminatedUnion('type', [
|
|
448
|
-
GatewayHelloEnvelopeSchema,
|
|
449
|
-
GatewayCommandEnvelopeSchema,
|
|
450
|
-
GatewayAcknowledgementEnvelopeSchema,
|
|
451
|
-
GatewayProgressEnvelopeSchema,
|
|
452
|
-
GatewayResultEnvelopeSchema,
|
|
453
|
-
GatewayCancellationEnvelopeSchema,
|
|
454
|
-
GatewayHeartbeatEnvelopeSchema,
|
|
455
|
-
GatewayInventoryEnvelopeSchema,
|
|
456
|
-
GatewayErrorEnvelopeSchema,
|
|
457
|
-
]);
|
|
458
|
-
function highestMinor(values) {
|
|
459
|
-
const result = new Map();
|
|
460
|
-
for (const value of values) {
|
|
461
|
-
const version = GatewayProtocolVersionSchema.parse(value);
|
|
462
|
-
result.set(version.major, Math.max(result.get(version.major) ?? -1, version.minor));
|
|
463
|
-
}
|
|
464
|
-
return result;
|
|
465
|
-
}
|
|
466
|
-
function rejectPrivilegedPayload(value, context, path = []) {
|
|
467
|
-
if (Array.isArray(value)) {
|
|
468
|
-
value.forEach((entry, index) => rejectPrivilegedPayload(entry, context, [...path, index]));
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
if (typeof value !== 'object' || value === null)
|
|
472
|
-
return;
|
|
473
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
474
|
-
const normalizedKey = key.replaceAll(/[^a-z0-9]/gi, '').toLowerCase();
|
|
475
|
-
if (!safePayloadKeys.has(normalizedKey) &&
|
|
476
|
-
forbiddenPayloadKeys.some((forbidden) => forbiddenKeyMatches(normalizedKey, forbidden))) {
|
|
477
|
-
context.addIssue({
|
|
478
|
-
code: 'custom',
|
|
479
|
-
path: [...path, key],
|
|
480
|
-
message: 'Privileged local selector is prohibited',
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
rejectPrivilegedPayload(entry, context, [...path, key]);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
function forbiddenKeyMatches(normalizedKey, forbidden) {
|
|
487
|
-
if (forbidden !== 'token')
|
|
488
|
-
return normalizedKey.includes(forbidden);
|
|
489
|
-
return (normalizedKey === 'token' ||
|
|
490
|
-
[
|
|
491
|
-
'accesstoken',
|
|
492
|
-
'apitoken',
|
|
493
|
-
'authtoken',
|
|
494
|
-
'bearertoken',
|
|
495
|
-
'idtoken',
|
|
496
|
-
'refreshtoken',
|
|
497
|
-
'sessiontoken',
|
|
498
|
-
].includes(normalizedKey));
|
|
499
|
-
}
|
|
500
|
-
export const GrantReferenceSchema = z
|
|
501
|
-
.string()
|
|
502
|
-
.min(16)
|
|
503
|
-
.max(128)
|
|
504
|
-
.regex(/^grant:[A-Za-z0-9._:-]+$/);
|
|
505
|
-
export const RuntimeErrorDataSchema = z
|
|
506
|
-
.object({
|
|
507
|
-
code: z.string().regex(/^[A-Z][A-Z0-9_]*$/),
|
|
508
|
-
classification: z.enum([
|
|
509
|
-
'validation',
|
|
510
|
-
'unsupported',
|
|
511
|
-
'unavailable',
|
|
512
|
-
'conflict',
|
|
513
|
-
'timeout',
|
|
514
|
-
'cancelled',
|
|
515
|
-
'runtime',
|
|
516
|
-
'infrastructure',
|
|
517
|
-
'unknown',
|
|
518
|
-
]),
|
|
519
|
-
message: z.string().min(1).max(4096),
|
|
520
|
-
retryable: z.boolean(),
|
|
521
|
-
})
|
|
522
|
-
.strict();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"hello": {
|
|
3
|
-
"type": "hello",
|
|
4
|
-
"schemaVersion": 1,
|
|
5
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
6
|
-
"sequence": 0,
|
|
7
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
8
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
9
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
10
|
-
"sentAt": "2026-08-25T12:00:00.000Z",
|
|
11
|
-
"channelGeneration": 1,
|
|
12
|
-
"supportedVersions": [{ "major": 1, "minor": 0 }],
|
|
13
|
-
"lastAcknowledgedSequence": 0
|
|
14
|
-
},
|
|
15
|
-
"command": {
|
|
16
|
-
"type": "command",
|
|
17
|
-
"schemaVersion": 1,
|
|
18
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
19
|
-
"sequence": 1,
|
|
20
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
21
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
22
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
23
|
-
"sentAt": "2026-08-25T12:00:00.000Z",
|
|
24
|
-
"channelGeneration": 1,
|
|
25
|
-
"commandId": "cmd_01JABCDEF0123456789ABCDEFG",
|
|
26
|
-
"idempotencyKey": "runtime-command:01JABCDEF0123456789ABCDEFG",
|
|
27
|
-
"payloadHash": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
28
|
-
"issuedAt": "2026-08-25T12:00:00.000Z",
|
|
29
|
-
"expiresAt": "2026-08-25T12:01:00.000Z",
|
|
30
|
-
"family": "runtime",
|
|
31
|
-
"operation": "runtime.execute",
|
|
32
|
-
"driver": { "family": "reference-runtime", "version": "1.0.0" },
|
|
33
|
-
"runtimeConnectionId": "rtc_01JABCDEF0123456789ABCDEFG",
|
|
34
|
-
"executionId": "exe_01JABCDEF0123456789ABCDEFG",
|
|
35
|
-
"attemptId": "att_01JABCDEF0123456789ABCDEFG",
|
|
36
|
-
"requiredCapabilities": ["runtime.execute"],
|
|
37
|
-
"payload": { "version": 1, "parameters": { "prompt": "golden fixture" } }
|
|
38
|
-
},
|
|
39
|
-
"ack": {
|
|
40
|
-
"type": "ack",
|
|
41
|
-
"schemaVersion": 1,
|
|
42
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
43
|
-
"sequence": 1,
|
|
44
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
45
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
46
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
47
|
-
"sentAt": "2026-08-25T12:00:01.000Z",
|
|
48
|
-
"channelGeneration": 1,
|
|
49
|
-
"commandId": "cmd_01JABCDEF0123456789ABCDEFG",
|
|
50
|
-
"payloadHash": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
51
|
-
"disposition": "accepted"
|
|
52
|
-
},
|
|
53
|
-
"progress": {
|
|
54
|
-
"type": "progress",
|
|
55
|
-
"schemaVersion": 1,
|
|
56
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
57
|
-
"sequence": 2,
|
|
58
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
59
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
60
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
61
|
-
"sentAt": "2026-08-25T12:00:02.000Z",
|
|
62
|
-
"channelGeneration": 1,
|
|
63
|
-
"commandId": "cmd_01JABCDEF0123456789ABCDEFG",
|
|
64
|
-
"payloadHash": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
65
|
-
"eventSequence": 1,
|
|
66
|
-
"event": { "kind": "runtime.progress", "data": { "message": "running" } }
|
|
67
|
-
},
|
|
68
|
-
"result": {
|
|
69
|
-
"type": "result",
|
|
70
|
-
"schemaVersion": 1,
|
|
71
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
72
|
-
"sequence": 3,
|
|
73
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
74
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
75
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
76
|
-
"sentAt": "2026-08-25T12:00:03.000Z",
|
|
77
|
-
"channelGeneration": 1,
|
|
78
|
-
"commandId": "cmd_01JABCDEF0123456789ABCDEFG",
|
|
79
|
-
"payloadHash": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
80
|
-
"status": "succeeded",
|
|
81
|
-
"completedAt": "2026-08-25T12:00:03.000Z",
|
|
82
|
-
"result": { "data": { "outcome": "complete" } }
|
|
83
|
-
},
|
|
84
|
-
"cancel": {
|
|
85
|
-
"type": "cancel",
|
|
86
|
-
"schemaVersion": 1,
|
|
87
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
88
|
-
"sequence": 4,
|
|
89
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
90
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
91
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
92
|
-
"sentAt": "2026-08-25T12:00:04.000Z",
|
|
93
|
-
"channelGeneration": 1,
|
|
94
|
-
"commandId": "cmd_01JABCDEF0123456789ABCDEFG",
|
|
95
|
-
"payloadHash": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
96
|
-
"requestedAt": "2026-08-25T12:00:04.000Z",
|
|
97
|
-
"reason": "user_requested"
|
|
98
|
-
},
|
|
99
|
-
"heartbeat": {
|
|
100
|
-
"type": "heartbeat",
|
|
101
|
-
"schemaVersion": 1,
|
|
102
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
103
|
-
"sequence": 5,
|
|
104
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
105
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
106
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
107
|
-
"sentAt": "2026-08-25T12:00:05.000Z",
|
|
108
|
-
"channelGeneration": 1,
|
|
109
|
-
"observedAt": "2026-08-25T12:00:05.000Z",
|
|
110
|
-
"status": "online"
|
|
111
|
-
},
|
|
112
|
-
"inventory": {
|
|
113
|
-
"type": "inventory",
|
|
114
|
-
"schemaVersion": 1,
|
|
115
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
116
|
-
"sequence": 6,
|
|
117
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
118
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
119
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
120
|
-
"sentAt": "2026-08-25T12:00:06.000Z",
|
|
121
|
-
"channelGeneration": 1,
|
|
122
|
-
"snapshotVersion": 1,
|
|
123
|
-
"observedAt": "2026-08-25T12:00:06.000Z",
|
|
124
|
-
"runtimeDrivers": [
|
|
125
|
-
{
|
|
126
|
-
"opaqueRef": "nref_01JABCDEF0123456789ABCDEFG",
|
|
127
|
-
"driverFamily": "reference-runtime",
|
|
128
|
-
"driverVersion": "1.0.0",
|
|
129
|
-
"harnessVersion": "1.0.0",
|
|
130
|
-
"protocolVersion": { "major": 1, "minor": 0 },
|
|
131
|
-
"health": "healthy",
|
|
132
|
-
"capabilities": ["runtime.execute"],
|
|
133
|
-
"limitations": []
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
"contextProviders": []
|
|
137
|
-
},
|
|
138
|
-
"error": {
|
|
139
|
-
"type": "error",
|
|
140
|
-
"schemaVersion": 1,
|
|
141
|
-
"protocolVersion": { "major": 1, "minor": 1 },
|
|
142
|
-
"sequence": 7,
|
|
143
|
-
"nodeId": "rnr_01JABCDEF0123456789ABCDEFG",
|
|
144
|
-
"workspaceId": "wsp_01JABCDEF0123456789ABCDEFG",
|
|
145
|
-
"traceId": "trc_01JABCDEF0123456789ABCDEFG",
|
|
146
|
-
"sentAt": "2026-08-25T12:00:07.000Z",
|
|
147
|
-
"channelGeneration": 1,
|
|
148
|
-
"commandId": "cmd_01JABCDEF0123456789ABCDEFG",
|
|
149
|
-
"payloadHash": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
150
|
-
"code": "RUNTIME_UNAVAILABLE",
|
|
151
|
-
"retryable": true
|
|
152
|
-
}
|
|
153
|
-
}
|
package/fixtures/index.mjs
DELETED