@xemahq/agent-session-runtime 0.6.7 → 0.8.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 +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-resolution.d.ts.map +1 -1
- package/dist/lib/agent-resolution.js.map +1 -1
- package/dist/lib/dispatch-contract.d.ts +2 -1
- package/dist/lib/dispatch-contract.d.ts.map +1 -1
- package/dist/lib/launch-identity/canonical-contract.d.ts +22 -0
- package/dist/lib/launch-identity/canonical-contract.d.ts.map +1 -0
- package/dist/lib/launch-identity/canonical-contract.js +229 -0
- package/dist/lib/launch-identity/canonical-contract.js.map +1 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan-store.d.ts +44 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan-store.d.ts.map +1 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan-store.js +116 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan-store.js.map +1 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan.d.ts +84 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan.d.ts.map +1 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan.js +382 -0
- package/dist/lib/launch-identity/compiled-session-launch-plan.js.map +1 -0
- package/dist/lib/launch-identity/index.d.ts +7 -0
- package/dist/lib/launch-identity/index.d.ts.map +1 -0
- package/dist/lib/launch-identity/index.js +23 -0
- package/dist/lib/launch-identity/index.js.map +1 -0
- package/dist/lib/launch-identity/runtime-template-key.d.ts +30 -0
- package/dist/lib/launch-identity/runtime-template-key.d.ts.map +1 -0
- package/dist/lib/launch-identity/runtime-template-key.js +69 -0
- package/dist/lib/launch-identity/runtime-template-key.js.map +1 -0
- package/dist/lib/launch-identity/session-binding.d.ts +24 -0
- package/dist/lib/launch-identity/session-binding.d.ts.map +1 -0
- package/dist/lib/launch-identity/session-binding.js +62 -0
- package/dist/lib/launch-identity/session-binding.js.map +1 -0
- package/dist/lib/launch-identity/thread-reuse-key.d.ts +19 -0
- package/dist/lib/launch-identity/thread-reuse-key.d.ts.map +1 -0
- package/dist/lib/launch-identity/thread-reuse-key.js +46 -0
- package/dist/lib/launch-identity/thread-reuse-key.js.map +1 -0
- package/package.json +7 -5
- package/src/index.ts +1 -0
- package/src/lib/agent-resolution.ts +15 -4
- package/src/lib/dispatch-contract.ts +4 -9
- package/src/lib/launch-identity/canonical-contract.ts +352 -0
- package/src/lib/launch-identity/compiled-session-launch-plan-store.ts +178 -0
- package/src/lib/launch-identity/compiled-session-launch-plan.ts +681 -0
- package/src/lib/launch-identity/index.ts +6 -0
- package/src/lib/launch-identity/runtime-template-key.ts +143 -0
- package/src/lib/launch-identity/session-binding.ts +152 -0
- package/src/lib/launch-identity/thread-reuse-key.ts +93 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalContractJson,
|
|
3
|
+
type CanonicalJsonValue,
|
|
4
|
+
hashCanonicalContract,
|
|
5
|
+
requireBoolean,
|
|
6
|
+
requireCanonicalJsonObject,
|
|
7
|
+
requireEnumValue,
|
|
8
|
+
requireExactObject,
|
|
9
|
+
requireImageDigest,
|
|
10
|
+
requireNonEmptyString,
|
|
11
|
+
requireSha256,
|
|
12
|
+
requireStringRefs,
|
|
13
|
+
} from './canonical-contract';
|
|
14
|
+
import {
|
|
15
|
+
createRuntimeTemplateKey,
|
|
16
|
+
type RuntimeTemplateKey,
|
|
17
|
+
RuntimeTemplateTenantDependency,
|
|
18
|
+
RuntimeTemplateTrustPolicy,
|
|
19
|
+
} from './runtime-template-key';
|
|
20
|
+
|
|
21
|
+
export enum LaunchPlanBindingSlotKind {
|
|
22
|
+
OrganizationId = 'organization-id',
|
|
23
|
+
ProjectId = 'project-id',
|
|
24
|
+
UserId = 'user-id',
|
|
25
|
+
SessionId = 'session-id',
|
|
26
|
+
ThreadId = 'thread-id',
|
|
27
|
+
InvocationId = 'invocation-id',
|
|
28
|
+
DomainRef = 'domain-ref',
|
|
29
|
+
Input = 'input',
|
|
30
|
+
DynamicContext = 'dynamic-context',
|
|
31
|
+
StorageAllocationRef = 'storage-allocation-ref',
|
|
32
|
+
WorkingFileSourceRef = 'working-file-source-ref',
|
|
33
|
+
OutputRouteRef = 'output-route-ref',
|
|
34
|
+
ActorTokenRef = 'actor-token-ref',
|
|
35
|
+
ServiceTokenRef = 'service-token-ref',
|
|
36
|
+
ProviderTokenRef = 'provider-token-ref',
|
|
37
|
+
CredentialGrantRef = 'credential-grant-ref',
|
|
38
|
+
DatabaseGrantRef = 'database-grant-ref',
|
|
39
|
+
SecretRef = 'secret-ref',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export enum LaunchPlanBindingSlotCardinality {
|
|
43
|
+
One = 'one',
|
|
44
|
+
Many = 'many',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface LaunchPlanBindingSlot {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly kind: LaunchPlanBindingSlotKind;
|
|
50
|
+
readonly cardinality: LaunchPlanBindingSlotCardinality;
|
|
51
|
+
readonly required: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PinnedLaunchResource {
|
|
55
|
+
readonly kind: string;
|
|
56
|
+
readonly ref: string;
|
|
57
|
+
readonly revisionRef: string;
|
|
58
|
+
readonly contentHash: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface CompiledWorkspaceLaunchPlan {
|
|
62
|
+
readonly manifestRef: string;
|
|
63
|
+
readonly manifestHash: string;
|
|
64
|
+
readonly structure: Readonly<Record<string, CanonicalJsonValue>>;
|
|
65
|
+
readonly layout: Readonly<Record<string, CanonicalJsonValue>>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface CompiledRuntimeRequirements {
|
|
69
|
+
readonly runtimeRef: string;
|
|
70
|
+
readonly runtimeRevision: string;
|
|
71
|
+
readonly imageDigest: string;
|
|
72
|
+
readonly requirementsHash: string;
|
|
73
|
+
readonly requirements: Readonly<Record<string, CanonicalJsonValue>>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface LaunchPolicyCompatibility {
|
|
77
|
+
readonly tenantDependency: RuntimeTemplateTenantDependency;
|
|
78
|
+
readonly trustPolicy: RuntimeTemplateTrustPolicy;
|
|
79
|
+
readonly compatibleSurfaces: readonly string[];
|
|
80
|
+
readonly policies: readonly PinnedLaunchResource[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface CompiledOutputSurfaceSchema {
|
|
84
|
+
readonly kind: string;
|
|
85
|
+
readonly schemaRef: string;
|
|
86
|
+
readonly schemaHash: string;
|
|
87
|
+
readonly schema: Readonly<Record<string, CanonicalJsonValue>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Immutable, publish-time session launch input. This protocol deliberately
|
|
92
|
+
* excludes invocation identity, tenant data, credentials and raw inputs.
|
|
93
|
+
* Runtime values are supplied only through the declared `bindingSlots`.
|
|
94
|
+
*/
|
|
95
|
+
export interface CompiledSessionLaunchPlan {
|
|
96
|
+
readonly schemaVersion: 1;
|
|
97
|
+
readonly runtimeTemplateKey: RuntimeTemplateKey;
|
|
98
|
+
readonly agent: PinnedLaunchResource;
|
|
99
|
+
readonly subagents: readonly PinnedLaunchResource[];
|
|
100
|
+
readonly skills: readonly PinnedLaunchResource[];
|
|
101
|
+
readonly tools: readonly PinnedLaunchResource[];
|
|
102
|
+
readonly mcpDescriptors: readonly PinnedLaunchResource[];
|
|
103
|
+
readonly capabilityDescriptors: readonly PinnedLaunchResource[];
|
|
104
|
+
readonly workspace: CompiledWorkspaceLaunchPlan;
|
|
105
|
+
readonly runtimeRequirements: CompiledRuntimeRequirements;
|
|
106
|
+
readonly policyCompatibility: LaunchPolicyCompatibility;
|
|
107
|
+
readonly outputSurface: CompiledOutputSurfaceSchema;
|
|
108
|
+
readonly bindingSlots: readonly LaunchPlanBindingSlot[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const PLAN_KEYS = [
|
|
112
|
+
'schemaVersion',
|
|
113
|
+
'runtimeTemplateKey',
|
|
114
|
+
'agent',
|
|
115
|
+
'subagents',
|
|
116
|
+
'skills',
|
|
117
|
+
'tools',
|
|
118
|
+
'mcpDescriptors',
|
|
119
|
+
'capabilityDescriptors',
|
|
120
|
+
'workspace',
|
|
121
|
+
'runtimeRequirements',
|
|
122
|
+
'policyCompatibility',
|
|
123
|
+
'outputSurface',
|
|
124
|
+
'bindingSlots',
|
|
125
|
+
] as const;
|
|
126
|
+
const RESOURCE_KEYS = ['kind', 'ref', 'revisionRef', 'contentHash'] as const;
|
|
127
|
+
const WORKSPACE_KEYS = [
|
|
128
|
+
'manifestRef',
|
|
129
|
+
'manifestHash',
|
|
130
|
+
'structure',
|
|
131
|
+
'layout',
|
|
132
|
+
] as const;
|
|
133
|
+
const RUNTIME_REQUIREMENT_KEYS = [
|
|
134
|
+
'runtimeRef',
|
|
135
|
+
'runtimeRevision',
|
|
136
|
+
'imageDigest',
|
|
137
|
+
'requirementsHash',
|
|
138
|
+
'requirements',
|
|
139
|
+
] as const;
|
|
140
|
+
const POLICY_KEYS = [
|
|
141
|
+
'tenantDependency',
|
|
142
|
+
'trustPolicy',
|
|
143
|
+
'compatibleSurfaces',
|
|
144
|
+
'policies',
|
|
145
|
+
] as const;
|
|
146
|
+
const OUTPUT_SURFACE_KEYS = [
|
|
147
|
+
'kind',
|
|
148
|
+
'schemaRef',
|
|
149
|
+
'schemaHash',
|
|
150
|
+
'schema',
|
|
151
|
+
] as const;
|
|
152
|
+
const BINDING_SLOT_KEYS = ['name', 'kind', 'cardinality', 'required'] as const;
|
|
153
|
+
const BINDING_SLOT_KINDS = Object.values(LaunchPlanBindingSlotKind);
|
|
154
|
+
const BINDING_SLOT_CARDINALITIES = Object.values(
|
|
155
|
+
LaunchPlanBindingSlotCardinality,
|
|
156
|
+
);
|
|
157
|
+
const TENANT_DEPENDENCIES = Object.values(RuntimeTemplateTenantDependency);
|
|
158
|
+
const TRUST_POLICIES = Object.values(RuntimeTemplateTrustPolicy);
|
|
159
|
+
const BINDING_SLOT_NAME_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z][a-z0-9]*)*$/u;
|
|
160
|
+
const DYNAMIC_LITERAL_PATTERN =
|
|
161
|
+
/\$\{\s*(?:input|tenant|org|organization|project|user|session|thread|domain|token|secret|credential)(?:[.:[\]}]|$)/iu;
|
|
162
|
+
const SECRET_REFERENCE_PATTERN =
|
|
163
|
+
/^(?:secret|vault|credential|token)(?:-ref)?:\/\//iu;
|
|
164
|
+
const DYNAMIC_FIELD_NAMES = new Set([
|
|
165
|
+
'apikey',
|
|
166
|
+
'authorization',
|
|
167
|
+
'cookie',
|
|
168
|
+
'credential',
|
|
169
|
+
'credentialgrantref',
|
|
170
|
+
'credentialref',
|
|
171
|
+
'databasegrantref',
|
|
172
|
+
'domain',
|
|
173
|
+
'domainid',
|
|
174
|
+
'domainref',
|
|
175
|
+
'input',
|
|
176
|
+
'invocationid',
|
|
177
|
+
'organization',
|
|
178
|
+
'organizationid',
|
|
179
|
+
'org',
|
|
180
|
+
'orgid',
|
|
181
|
+
'password',
|
|
182
|
+
'privatekey',
|
|
183
|
+
'project',
|
|
184
|
+
'projectid',
|
|
185
|
+
'secret',
|
|
186
|
+
'secretref',
|
|
187
|
+
'session',
|
|
188
|
+
'sessionid',
|
|
189
|
+
'storageref',
|
|
190
|
+
'tenant',
|
|
191
|
+
'tenantid',
|
|
192
|
+
'thread',
|
|
193
|
+
'threadid',
|
|
194
|
+
'token',
|
|
195
|
+
'tokenref',
|
|
196
|
+
'user',
|
|
197
|
+
'userid',
|
|
198
|
+
'value',
|
|
199
|
+
]);
|
|
200
|
+
const SECRET_OR_CREDENTIAL_FIELD_PATTERN =
|
|
201
|
+
/(?:apikey|authorization|cookie|credential|password|privatekey|secret|token)(?:ref)?$/u;
|
|
202
|
+
|
|
203
|
+
export function createCompiledSessionLaunchPlan(
|
|
204
|
+
input: unknown,
|
|
205
|
+
): CompiledSessionLaunchPlan {
|
|
206
|
+
const object = requireExactObject(
|
|
207
|
+
input,
|
|
208
|
+
'CompiledSessionLaunchPlan',
|
|
209
|
+
PLAN_KEYS,
|
|
210
|
+
);
|
|
211
|
+
if (object.schemaVersion !== 1) {
|
|
212
|
+
throw new TypeError('CompiledSessionLaunchPlan.schemaVersion must be 1.');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const runtimeTemplateKey = createRuntimeTemplateKey(
|
|
216
|
+
object.runtimeTemplateKey,
|
|
217
|
+
);
|
|
218
|
+
const agent = requirePinnedResource(
|
|
219
|
+
object.agent,
|
|
220
|
+
'CompiledSessionLaunchPlan.agent',
|
|
221
|
+
);
|
|
222
|
+
const subagents = requirePinnedResources(
|
|
223
|
+
object.subagents,
|
|
224
|
+
'CompiledSessionLaunchPlan.subagents',
|
|
225
|
+
);
|
|
226
|
+
const skills = requirePinnedResources(
|
|
227
|
+
object.skills,
|
|
228
|
+
'CompiledSessionLaunchPlan.skills',
|
|
229
|
+
);
|
|
230
|
+
const tools = requirePinnedResources(
|
|
231
|
+
object.tools,
|
|
232
|
+
'CompiledSessionLaunchPlan.tools',
|
|
233
|
+
);
|
|
234
|
+
const mcpDescriptors = requirePinnedResources(
|
|
235
|
+
object.mcpDescriptors,
|
|
236
|
+
'CompiledSessionLaunchPlan.mcpDescriptors',
|
|
237
|
+
);
|
|
238
|
+
const capabilityDescriptors = requirePinnedResources(
|
|
239
|
+
object.capabilityDescriptors,
|
|
240
|
+
'CompiledSessionLaunchPlan.capabilityDescriptors',
|
|
241
|
+
);
|
|
242
|
+
const workspace = requireWorkspace(object.workspace);
|
|
243
|
+
const runtimeRequirements = requireRuntimeRequirements(
|
|
244
|
+
object.runtimeRequirements,
|
|
245
|
+
);
|
|
246
|
+
const policyCompatibility = requirePolicyCompatibility(
|
|
247
|
+
object.policyCompatibility,
|
|
248
|
+
);
|
|
249
|
+
const outputSurface = requireOutputSurface(object.outputSurface);
|
|
250
|
+
const bindingSlots = requireBindingSlots(object.bindingSlots);
|
|
251
|
+
|
|
252
|
+
assertTemplateConsistency({
|
|
253
|
+
runtimeTemplateKey,
|
|
254
|
+
agent,
|
|
255
|
+
subagents,
|
|
256
|
+
skills,
|
|
257
|
+
tools,
|
|
258
|
+
mcpDescriptors,
|
|
259
|
+
capabilityDescriptors,
|
|
260
|
+
workspace,
|
|
261
|
+
runtimeRequirements,
|
|
262
|
+
policyCompatibility,
|
|
263
|
+
});
|
|
264
|
+
assertDeclaredBindingSlotReferences(
|
|
265
|
+
[workspace.structure, workspace.layout, runtimeRequirements.requirements],
|
|
266
|
+
bindingSlots,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
return Object.freeze({
|
|
270
|
+
schemaVersion: 1,
|
|
271
|
+
runtimeTemplateKey,
|
|
272
|
+
agent,
|
|
273
|
+
subagents,
|
|
274
|
+
skills,
|
|
275
|
+
tools,
|
|
276
|
+
mcpDescriptors,
|
|
277
|
+
capabilityDescriptors,
|
|
278
|
+
workspace,
|
|
279
|
+
runtimeRequirements,
|
|
280
|
+
policyCompatibility,
|
|
281
|
+
outputSurface,
|
|
282
|
+
bindingSlots,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function encodeCompiledSessionLaunchPlan(
|
|
287
|
+
input: CompiledSessionLaunchPlan,
|
|
288
|
+
): string {
|
|
289
|
+
return canonicalContractJson(createCompiledSessionLaunchPlan(input));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function decodeCompiledSessionLaunchPlan(
|
|
293
|
+
encoded: string,
|
|
294
|
+
): CompiledSessionLaunchPlan {
|
|
295
|
+
let parsed: unknown;
|
|
296
|
+
try {
|
|
297
|
+
parsed = JSON.parse(encoded);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
throw new TypeError(
|
|
300
|
+
`CompiledSessionLaunchPlan is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return createCompiledSessionLaunchPlan(parsed);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function hashCompiledSessionLaunchPlan(
|
|
307
|
+
input: CompiledSessionLaunchPlan,
|
|
308
|
+
): string {
|
|
309
|
+
return hashCanonicalContract(createCompiledSessionLaunchPlan(input));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function hashCompiledWorkspaceLaunchPlan(
|
|
313
|
+
input: CompiledWorkspaceLaunchPlan,
|
|
314
|
+
): string {
|
|
315
|
+
return hashCanonicalContract(input);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function requirePinnedResource(
|
|
319
|
+
value: unknown,
|
|
320
|
+
path: string,
|
|
321
|
+
): PinnedLaunchResource {
|
|
322
|
+
const object = requireExactObject(value, path, RESOURCE_KEYS);
|
|
323
|
+
return Object.freeze({
|
|
324
|
+
kind: requireNonEmptyString(object.kind, `${path}.kind`),
|
|
325
|
+
ref: requireNonEmptyString(object.ref, `${path}.ref`),
|
|
326
|
+
revisionRef: requireNonEmptyString(
|
|
327
|
+
object.revisionRef,
|
|
328
|
+
`${path}.revisionRef`,
|
|
329
|
+
),
|
|
330
|
+
contentHash: requireSha256(object.contentHash, `${path}.contentHash`),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function requirePinnedResources(
|
|
335
|
+
value: unknown,
|
|
336
|
+
path: string,
|
|
337
|
+
): readonly PinnedLaunchResource[] {
|
|
338
|
+
if (!Array.isArray(value)) {
|
|
339
|
+
throw new TypeError(`${path} must be an array.`);
|
|
340
|
+
}
|
|
341
|
+
const resources = value.map((entry, index) =>
|
|
342
|
+
requirePinnedResource(entry, `${path}[${index}]`),
|
|
343
|
+
);
|
|
344
|
+
const identities = new Set<string>();
|
|
345
|
+
for (const resource of resources) {
|
|
346
|
+
const identity = `${resource.kind}\u0000${resource.ref}`;
|
|
347
|
+
if (identities.has(identity)) {
|
|
348
|
+
throw new TypeError(
|
|
349
|
+
`${path} contains duplicate resource '${resource.kind}:${resource.ref}'.`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
identities.add(identity);
|
|
353
|
+
}
|
|
354
|
+
return Object.freeze(
|
|
355
|
+
resources.toSorted((left, right) =>
|
|
356
|
+
canonicalContractJson(left).localeCompare(canonicalContractJson(right)),
|
|
357
|
+
),
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function requireWorkspace(value: unknown): CompiledWorkspaceLaunchPlan {
|
|
362
|
+
const path = 'CompiledSessionLaunchPlan.workspace';
|
|
363
|
+
const object = requireExactObject(value, path, WORKSPACE_KEYS);
|
|
364
|
+
return Object.freeze({
|
|
365
|
+
manifestRef: requireNonEmptyString(
|
|
366
|
+
object.manifestRef,
|
|
367
|
+
`${path}.manifestRef`,
|
|
368
|
+
),
|
|
369
|
+
manifestHash: requireSha256(object.manifestHash, `${path}.manifestHash`),
|
|
370
|
+
structure: requireStaticPayload(object.structure, `${path}.structure`),
|
|
371
|
+
layout: requireStaticPayload(object.layout, `${path}.layout`),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function requireRuntimeRequirements(
|
|
376
|
+
value: unknown,
|
|
377
|
+
): CompiledRuntimeRequirements {
|
|
378
|
+
const path = 'CompiledSessionLaunchPlan.runtimeRequirements';
|
|
379
|
+
const object = requireExactObject(value, path, RUNTIME_REQUIREMENT_KEYS);
|
|
380
|
+
const imageDigest = requireImageDigest(object.imageDigest, `${path}.imageDigest`);
|
|
381
|
+
const requirements = requireStaticPayload(
|
|
382
|
+
object.requirements,
|
|
383
|
+
`${path}.requirements`,
|
|
384
|
+
);
|
|
385
|
+
const requirementsHash = requireSha256(
|
|
386
|
+
object.requirementsHash,
|
|
387
|
+
`${path}.requirementsHash`,
|
|
388
|
+
);
|
|
389
|
+
assertContentHash(requirementsHash, requirements, `${path}.requirementsHash`);
|
|
390
|
+
return Object.freeze({
|
|
391
|
+
runtimeRef: requireNonEmptyString(object.runtimeRef, `${path}.runtimeRef`),
|
|
392
|
+
runtimeRevision: requireNonEmptyString(
|
|
393
|
+
object.runtimeRevision,
|
|
394
|
+
`${path}.runtimeRevision`,
|
|
395
|
+
),
|
|
396
|
+
imageDigest,
|
|
397
|
+
requirementsHash,
|
|
398
|
+
requirements,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function requirePolicyCompatibility(value: unknown): LaunchPolicyCompatibility {
|
|
403
|
+
const path = 'CompiledSessionLaunchPlan.policyCompatibility';
|
|
404
|
+
const object = requireExactObject(value, path, POLICY_KEYS);
|
|
405
|
+
return Object.freeze({
|
|
406
|
+
tenantDependency: requireEnumValue(
|
|
407
|
+
object.tenantDependency,
|
|
408
|
+
`${path}.tenantDependency`,
|
|
409
|
+
TENANT_DEPENDENCIES,
|
|
410
|
+
),
|
|
411
|
+
trustPolicy: requireEnumValue(
|
|
412
|
+
object.trustPolicy,
|
|
413
|
+
`${path}.trustPolicy`,
|
|
414
|
+
TRUST_POLICIES,
|
|
415
|
+
),
|
|
416
|
+
compatibleSurfaces: requireStringRefs(
|
|
417
|
+
object.compatibleSurfaces,
|
|
418
|
+
`${path}.compatibleSurfaces`,
|
|
419
|
+
),
|
|
420
|
+
policies: requirePinnedResources(object.policies, `${path}.policies`),
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function requireOutputSurface(value: unknown): CompiledOutputSurfaceSchema {
|
|
425
|
+
const path = 'CompiledSessionLaunchPlan.outputSurface';
|
|
426
|
+
const object = requireExactObject(value, path, OUTPUT_SURFACE_KEYS);
|
|
427
|
+
const schema = requireCanonicalJsonObject(object.schema, `${path}.schema`);
|
|
428
|
+
const schemaHash = requireSha256(object.schemaHash, `${path}.schemaHash`);
|
|
429
|
+
assertContentHash(schemaHash, schema, `${path}.schemaHash`);
|
|
430
|
+
return Object.freeze({
|
|
431
|
+
kind: requireNonEmptyString(object.kind, `${path}.kind`),
|
|
432
|
+
schemaRef: requireNonEmptyString(object.schemaRef, `${path}.schemaRef`),
|
|
433
|
+
schemaHash,
|
|
434
|
+
schema,
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function requireBindingSlots(value: unknown): readonly LaunchPlanBindingSlot[] {
|
|
439
|
+
const path = 'CompiledSessionLaunchPlan.bindingSlots';
|
|
440
|
+
if (!Array.isArray(value)) {
|
|
441
|
+
throw new TypeError(`${path} must be an array.`);
|
|
442
|
+
}
|
|
443
|
+
const slots = value.map((entry, index) => {
|
|
444
|
+
const slotPath = `${path}[${index}]`;
|
|
445
|
+
const object = requireExactObject(entry, slotPath, BINDING_SLOT_KEYS);
|
|
446
|
+
const name = requireNonEmptyString(object.name, `${slotPath}.name`);
|
|
447
|
+
if (!BINDING_SLOT_NAME_PATTERN.test(name)) {
|
|
448
|
+
throw new TypeError(
|
|
449
|
+
`${slotPath}.name must be a lowercase dotted or hyphenated identifier.`,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
return Object.freeze({
|
|
453
|
+
name,
|
|
454
|
+
kind: requireEnumValue(
|
|
455
|
+
object.kind,
|
|
456
|
+
`${slotPath}.kind`,
|
|
457
|
+
BINDING_SLOT_KINDS,
|
|
458
|
+
),
|
|
459
|
+
cardinality: requireEnumValue(
|
|
460
|
+
object.cardinality,
|
|
461
|
+
`${slotPath}.cardinality`,
|
|
462
|
+
BINDING_SLOT_CARDINALITIES,
|
|
463
|
+
),
|
|
464
|
+
required: requireBoolean(object.required, `${slotPath}.required`),
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
const names = new Set<string>();
|
|
468
|
+
for (const slot of slots) {
|
|
469
|
+
if (names.has(slot.name)) {
|
|
470
|
+
throw new TypeError(`${path} contains duplicate slot '${slot.name}'.`);
|
|
471
|
+
}
|
|
472
|
+
names.add(slot.name);
|
|
473
|
+
}
|
|
474
|
+
return Object.freeze(
|
|
475
|
+
slots.toSorted((left, right) => left.name.localeCompare(right.name)),
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function requireStaticPayload(
|
|
480
|
+
value: unknown,
|
|
481
|
+
path: string,
|
|
482
|
+
): Readonly<Record<string, CanonicalJsonValue>> {
|
|
483
|
+
const normalized = requireCanonicalJsonObject(value, path);
|
|
484
|
+
assertStaticPayloadNode(normalized, path);
|
|
485
|
+
return normalized;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function assertStaticPayloadNode(
|
|
489
|
+
value: CanonicalJsonValue,
|
|
490
|
+
path: string,
|
|
491
|
+
): void {
|
|
492
|
+
if (typeof value === 'string') {
|
|
493
|
+
if (
|
|
494
|
+
DYNAMIC_LITERAL_PATTERN.test(value) ||
|
|
495
|
+
SECRET_REFERENCE_PATTERN.test(value)
|
|
496
|
+
) {
|
|
497
|
+
throw new TypeError(
|
|
498
|
+
`${path} embeds dynamic or secret data; use a typed $bindingSlot reference.`,
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (value === null || typeof value !== 'object') {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (Array.isArray(value)) {
|
|
507
|
+
value.forEach((entry, index) =>
|
|
508
|
+
assertStaticPayloadNode(entry, `${path}[${index}]`),
|
|
509
|
+
);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (Object.hasOwn(value, '$bindingSlot')) {
|
|
513
|
+
const marker = requireExactObject(value, path, ['$bindingSlot']);
|
|
514
|
+
requireNonEmptyString(marker.$bindingSlot, `${path}.$bindingSlot`);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
518
|
+
const normalizedKey = key.replaceAll(/[^a-z0-9]/giu, '').toLowerCase();
|
|
519
|
+
if (
|
|
520
|
+
DYNAMIC_FIELD_NAMES.has(normalizedKey) ||
|
|
521
|
+
SECRET_OR_CREDENTIAL_FIELD_PATTERN.test(normalizedKey)
|
|
522
|
+
) {
|
|
523
|
+
if (!isBindingSlotMarker(entry)) {
|
|
524
|
+
throw new TypeError(
|
|
525
|
+
`${path}.${key} is dynamic data; its value must be a typed $bindingSlot reference.`,
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
assertStaticPayloadNode(entry, `${path}.${key}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function isBindingSlotMarker(
|
|
534
|
+
value: CanonicalJsonValue,
|
|
535
|
+
): value is Readonly<{ readonly $bindingSlot: CanonicalJsonValue }> {
|
|
536
|
+
return (
|
|
537
|
+
value !== null &&
|
|
538
|
+
typeof value === 'object' &&
|
|
539
|
+
!Array.isArray(value) &&
|
|
540
|
+
Object.hasOwn(value, '$bindingSlot')
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function assertDeclaredBindingSlotReferences(
|
|
545
|
+
values: readonly Readonly<Record<string, CanonicalJsonValue>>[],
|
|
546
|
+
slots: readonly LaunchPlanBindingSlot[],
|
|
547
|
+
): void {
|
|
548
|
+
const declared = new Set(slots.map((slot) => slot.name));
|
|
549
|
+
for (const [index, value] of values.entries()) {
|
|
550
|
+
inspectBindingSlotReferences(value, `staticPayloads[${index}]`, declared);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function inspectBindingSlotReferences(
|
|
555
|
+
value: CanonicalJsonValue,
|
|
556
|
+
path: string,
|
|
557
|
+
declared: ReadonlySet<string>,
|
|
558
|
+
): void {
|
|
559
|
+
if (value === null || typeof value !== 'object') {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (Array.isArray(value)) {
|
|
563
|
+
value.forEach((entry, index) =>
|
|
564
|
+
inspectBindingSlotReferences(entry, `${path}[${index}]`, declared),
|
|
565
|
+
);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
if (isBindingSlotMarker(value)) {
|
|
569
|
+
const name = value.$bindingSlot;
|
|
570
|
+
if (typeof name !== 'string' || !declared.has(name)) {
|
|
571
|
+
throw new TypeError(
|
|
572
|
+
`${path} references undeclared binding slot '${String(name)}'.`,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
578
|
+
inspectBindingSlotReferences(entry, `${path}.${key}`, declared);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function assertTemplateConsistency(input: {
|
|
583
|
+
readonly runtimeTemplateKey: RuntimeTemplateKey;
|
|
584
|
+
readonly agent: PinnedLaunchResource;
|
|
585
|
+
readonly subagents: readonly PinnedLaunchResource[];
|
|
586
|
+
readonly skills: readonly PinnedLaunchResource[];
|
|
587
|
+
readonly tools: readonly PinnedLaunchResource[];
|
|
588
|
+
readonly mcpDescriptors: readonly PinnedLaunchResource[];
|
|
589
|
+
readonly capabilityDescriptors: readonly PinnedLaunchResource[];
|
|
590
|
+
readonly workspace: CompiledWorkspaceLaunchPlan;
|
|
591
|
+
readonly runtimeRequirements: CompiledRuntimeRequirements;
|
|
592
|
+
readonly policyCompatibility: LaunchPolicyCompatibility;
|
|
593
|
+
}): void {
|
|
594
|
+
const key = input.runtimeTemplateKey;
|
|
595
|
+
assertEqual(
|
|
596
|
+
input.agent.revisionRef,
|
|
597
|
+
key.agentRevision,
|
|
598
|
+
'agent.revisionRef',
|
|
599
|
+
'runtimeTemplateKey.agentRevision',
|
|
600
|
+
);
|
|
601
|
+
assertEqual(
|
|
602
|
+
input.agent.contentHash,
|
|
603
|
+
key.primaryAgentHash,
|
|
604
|
+
'agent.contentHash',
|
|
605
|
+
'runtimeTemplateKey.primaryAgentHash',
|
|
606
|
+
);
|
|
607
|
+
assertContentHash(key.subagentsHash, input.subagents, 'subagents');
|
|
608
|
+
assertContentHash(key.skillsHash, input.skills, 'skills');
|
|
609
|
+
assertContentHash(key.toolsHash, input.tools, 'tools');
|
|
610
|
+
assertContentHash(
|
|
611
|
+
key.mcpDescriptorsHash,
|
|
612
|
+
input.mcpDescriptors,
|
|
613
|
+
'mcpDescriptors',
|
|
614
|
+
);
|
|
615
|
+
assertContentHash(
|
|
616
|
+
key.capabilityDescriptorsHash,
|
|
617
|
+
input.capabilityDescriptors,
|
|
618
|
+
'capabilityDescriptors',
|
|
619
|
+
);
|
|
620
|
+
assertContentHash(
|
|
621
|
+
key.workspacePlanHash,
|
|
622
|
+
input.workspace,
|
|
623
|
+
'runtimeTemplateKey.workspacePlanHash',
|
|
624
|
+
);
|
|
625
|
+
assertEqual(
|
|
626
|
+
input.runtimeRequirements.runtimeRef,
|
|
627
|
+
key.runtimeRef,
|
|
628
|
+
'runtimeRequirements.runtimeRef',
|
|
629
|
+
'runtimeTemplateKey.runtimeRef',
|
|
630
|
+
);
|
|
631
|
+
assertEqual(
|
|
632
|
+
input.runtimeRequirements.runtimeRevision,
|
|
633
|
+
key.runtimeRevision,
|
|
634
|
+
'runtimeRequirements.runtimeRevision',
|
|
635
|
+
'runtimeTemplateKey.runtimeRevision',
|
|
636
|
+
);
|
|
637
|
+
assertEqual(
|
|
638
|
+
input.runtimeRequirements.imageDigest,
|
|
639
|
+
key.imageDigest,
|
|
640
|
+
'runtimeRequirements.imageDigest',
|
|
641
|
+
'runtimeTemplateKey.imageDigest',
|
|
642
|
+
);
|
|
643
|
+
assertEqual(
|
|
644
|
+
input.policyCompatibility.tenantDependency,
|
|
645
|
+
key.tenantDependency,
|
|
646
|
+
'policyCompatibility.tenantDependency',
|
|
647
|
+
'runtimeTemplateKey.tenantDependency',
|
|
648
|
+
);
|
|
649
|
+
assertEqual(
|
|
650
|
+
input.policyCompatibility.trustPolicy,
|
|
651
|
+
key.trustPolicy,
|
|
652
|
+
'policyCompatibility.trustPolicy',
|
|
653
|
+
'runtimeTemplateKey.trustPolicy',
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function assertContentHash(
|
|
658
|
+
expectedHash: string,
|
|
659
|
+
content: unknown,
|
|
660
|
+
path: string,
|
|
661
|
+
): void {
|
|
662
|
+
const actualHash = hashCanonicalContract(content);
|
|
663
|
+
if (actualHash !== expectedHash) {
|
|
664
|
+
throw new TypeError(
|
|
665
|
+
`${path} content hash mismatch: expected '${expectedHash}', computed '${actualHash}'.`,
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function assertEqual(
|
|
671
|
+
actual: string,
|
|
672
|
+
expected: string,
|
|
673
|
+
actualPath: string,
|
|
674
|
+
expectedPath: string,
|
|
675
|
+
): void {
|
|
676
|
+
if (actual !== expected) {
|
|
677
|
+
throw new TypeError(
|
|
678
|
+
`${actualPath} must equal ${expectedPath}; received '${actual}' and '${expected}'.`,
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
}
|