memeloop 0.2.3 → 0.2.5
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/dist/browser.d.cts +26 -21
- package/dist/browser.d.ts +26 -21
- package/dist/chunk-4OITUYFC.js +37 -0
- package/dist/chunk-4OITUYFC.js.map +1 -0
- package/dist/{chunk-HY3U3GLE.js → chunk-5EUJNLVW.js} +1 -1
- package/dist/chunk-5EUJNLVW.js.map +1 -0
- package/dist/{chunk-KXVZQLJL.js → chunk-645GZGNM.js} +3 -2
- package/dist/chunk-645GZGNM.js.map +1 -0
- package/dist/{chunk-EPHRIRAL.js → chunk-6OLAL5CW.js} +16 -1
- package/dist/chunk-6OLAL5CW.js.map +1 -0
- package/dist/{chunk-LGUGYRR4.js → chunk-HVLCOJWI.js} +11 -6
- package/dist/{chunk-LGUGYRR4.js.map → chunk-HVLCOJWI.js.map} +1 -1
- package/dist/{chunk-5VYZV33O.js → chunk-KTZDDC7M.js} +64 -79
- package/dist/chunk-KTZDDC7M.js.map +1 -0
- package/dist/{chunk-K5KZJNDP.js → chunk-ROPAEJIM.js} +2 -2
- package/dist/{chunk-GYIOMQMY.js → chunk-UB77WKAU.js} +305 -429
- package/dist/chunk-UB77WKAU.js.map +1 -0
- package/dist/{chunk-KV6TC5UJ.js → chunk-XIEXGFPY.js} +3 -3
- package/dist/conversation.d.cts +4 -3
- package/dist/conversation.d.ts +4 -3
- package/dist/device-network-portable.cjs +2 -1
- package/dist/device-network-portable.cjs.map +1 -1
- package/dist/device-network-portable.d.cts +9 -7
- package/dist/device-network-portable.d.ts +9 -7
- package/dist/device-network-portable.js +1 -1
- package/dist/device-network.cjs +17 -1
- package/dist/device-network.cjs.map +1 -1
- package/dist/device-network.d.cts +6 -5
- package/dist/device-network.d.ts +6 -5
- package/dist/device-network.js +2 -2
- package/dist/{fetchProvider-B_vva3b3.d.ts → fetchProvider-Do8Hf1BN.d.ts} +1 -1
- package/dist/{fetchProvider-Bz4CE3_R.d.cts → fetchProvider-tMo6gc6N.d.cts} +1 -1
- package/dist/index.cjs +465 -537
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -26
- package/dist/index.d.ts +20 -26
- package/dist/index.js +47 -52
- package/dist/index.js.map +1 -1
- package/dist/{interface-3C3eG8Hn.d.cts → interface-C54gkLA3.d.ts} +3 -110
- package/dist/{interface-3C3eG8Hn.d.ts → interface-CECFnbzR.d.cts} +3 -110
- package/dist/llm-providers.cjs.map +1 -1
- package/dist/llm-providers.d.cts +3 -2
- package/dist/llm-providers.d.ts +3 -2
- package/dist/llm-providers.js +1 -1
- package/dist/llm-providers.js.map +1 -1
- package/dist/loop-api.cjs +88 -89
- package/dist/loop-api.cjs.map +1 -1
- package/dist/loop-api.d.cts +8 -7
- package/dist/loop-api.d.ts +8 -7
- package/dist/loop-api.js +5 -5
- package/dist/mobile.cjs +10 -5
- package/dist/mobile.cjs.map +1 -1
- package/dist/mobile.d.cts +6 -5
- package/dist/mobile.d.ts +6 -5
- package/dist/mobile.js +3 -3
- package/dist/{orchestration-portable-B4udCSVd.d.ts → orchestration-portable-CQRrnoEw.d.ts} +15 -5
- package/dist/{orchestration-portable-BWaCsCGK.d.cts → orchestration-portable-D4KBEYQb.d.cts} +15 -5
- package/dist/orchestration-portable.cjs +201 -343
- package/dist/orchestration-portable.cjs.map +1 -1
- package/dist/orchestration-portable.d.cts +6 -5
- package/dist/orchestration-portable.d.ts +6 -5
- package/dist/orchestration-portable.js +1 -1
- package/dist/{pairingInvite-C12n-7Ak.d.cts → pairingInvite-BmCQ-bHt.d.cts} +3 -3
- package/dist/{pairingInvite-CPQkuhLQ.d.ts → pairingInvite-CsfsexXC.d.ts} +3 -3
- package/dist/{promptConcat-VLe5SEN4.d.cts → promptConcat-BqImJtVh.d.cts} +7 -4
- package/dist/{promptConcat-CUEIA_3T.d.ts → promptConcat-C5SEgESi.d.ts} +7 -4
- package/dist/{providerRegistry-CaFK_aUd.d.ts → providerRegistry-BGrwd7Zl.d.cts} +2 -2
- package/dist/{providerRegistry-BDGGs5gz.d.cts → providerRegistry-Bs2lJpj9.d.ts} +2 -2
- package/dist/{registry-DNSEVYug.d.cts → registry-CelnriUR.d.cts} +3 -3
- package/dist/{registry-yGnYHWhq.d.ts → registry-DVv_RVPZ.d.ts} +3 -3
- package/dist/{remoteClient-DwBCoHpc.d.ts → remoteClient-D1gPizds.d.ts} +1 -1
- package/dist/{remoteClient-DFIyCZEv.d.cts → remoteClient-DxCHC4_Z.d.cts} +1 -1
- package/dist/{runtime-6EELHWVB.js → runtime-SASMRN4I.js} +3 -3
- package/dist/{scriptDeploymentPipeline-B1q-UhrO.d.ts → scriptDeploymentPipeline-CdDLEDMS.d.cts} +10 -1
- package/dist/{scriptDeploymentPipeline-XJzQyYys.d.cts → scriptDeploymentPipeline-DU6sor6Y.d.ts} +10 -1
- package/dist/{syncCloudDevices-C8fCUhnX.d.ts → syncCloudDevices-3RmB41sA.d.cts} +6 -2
- package/dist/{syncCloudDevices-BFw_c1g5.d.cts → syncCloudDevices-CSLbMESm.d.ts} +6 -2
- package/dist/tools.cjs +63 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.d.cts +12 -0
- package/dist/tools.d.ts +12 -0
- package/dist/tools.js +7 -0
- package/dist/tools.js.map +1 -0
- package/dist/{types-CcFFIk8W.d.ts → types-C29NBZ2w.d.ts} +1 -1
- package/dist/types-CcoJ_fdH.d.cts +110 -0
- package/dist/types-CcoJ_fdH.d.ts +110 -0
- package/dist/{types-C8gnhG9M.d.cts → types-D1rAJy9l.d.cts} +1 -1
- package/package.json +6 -1
- package/dist/chunk-5VYZV33O.js.map +0 -1
- package/dist/chunk-EPHRIRAL.js.map +0 -1
- package/dist/chunk-GYIOMQMY.js.map +0 -1
- package/dist/chunk-HY3U3GLE.js.map +0 -1
- package/dist/chunk-KXVZQLJL.js.map +0 -1
- /package/dist/{chunk-K5KZJNDP.js.map → chunk-ROPAEJIM.js.map} +0 -0
- /package/dist/{chunk-KV6TC5UJ.js.map → chunk-XIEXGFPY.js.map} +0 -0
- /package/dist/{runtime-6EELHWVB.js.map → runtime-SASMRN4I.js.map} +0 -0
|
@@ -1397,6 +1397,74 @@ function containsSecrets(value, options = {}) {
|
|
|
1397
1397
|
return walk(value);
|
|
1398
1398
|
}
|
|
1399
1399
|
|
|
1400
|
+
// src/orchestration/drivers/driverState.ts
|
|
1401
|
+
function assertFencedDriverRequestEnvelope(request, options) {
|
|
1402
|
+
assertDriverRequestEnvelope(request, {
|
|
1403
|
+
now: options.now,
|
|
1404
|
+
requireRun: options.requireRun,
|
|
1405
|
+
requireFencing: true,
|
|
1406
|
+
requireCapability: true,
|
|
1407
|
+
expectedMethod: options.expectedMethod
|
|
1408
|
+
});
|
|
1409
|
+
if (options.actorKinds && !options.actorKinds.includes(request.actor.kind)) {
|
|
1410
|
+
throw new OrchestrationError({
|
|
1411
|
+
code: "FORBIDDEN",
|
|
1412
|
+
message: options.forbiddenMessage?.(request.actor.kind) ?? `actor kind '${request.actor.kind}' cannot call ${options.expectedMethod}`,
|
|
1413
|
+
retryable: false
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
const epoch = request.fencingEpoch;
|
|
1417
|
+
const current = options.fences.get(request.resource.uid) ?? 0;
|
|
1418
|
+
if (epoch < current) {
|
|
1419
|
+
throw new OrchestrationError({
|
|
1420
|
+
code: "STALE_EPOCH",
|
|
1421
|
+
message: `stale ${options.fenceName} fencing epoch ${epoch}; current epoch is ${current}`,
|
|
1422
|
+
retryable: false
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
options.fences.set(request.resource.uid, epoch);
|
|
1426
|
+
return epoch;
|
|
1427
|
+
}
|
|
1428
|
+
function driverOperationKey(request, operation) {
|
|
1429
|
+
return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
1430
|
+
}
|
|
1431
|
+
function findIdempotentDriverHandle(state, request, operation, driverName) {
|
|
1432
|
+
const key = driverOperationKey(request, operation);
|
|
1433
|
+
const handle = state.idempotency.get(key);
|
|
1434
|
+
if (handle === void 0) return void 0;
|
|
1435
|
+
if (state.idempotencyFingerprints.get(key) !== canonicalDriverValue(request.payload)) {
|
|
1436
|
+
throw new OrchestrationError({
|
|
1437
|
+
code: "CONFLICT",
|
|
1438
|
+
message: `${driverName} ${operation} idempotency key was reused with different input`,
|
|
1439
|
+
retryable: false
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
return handle;
|
|
1443
|
+
}
|
|
1444
|
+
function rememberIdempotentDriverHandle(state, request, operation, handle) {
|
|
1445
|
+
const key = driverOperationKey(request, operation);
|
|
1446
|
+
state.idempotency.set(key, handle);
|
|
1447
|
+
state.idempotencyFingerprints.set(key, canonicalDriverValue(request.payload));
|
|
1448
|
+
}
|
|
1449
|
+
function getOwnedDriverValue(collection, handle, resourceUid, kind) {
|
|
1450
|
+
const value = collection.get(handle);
|
|
1451
|
+
if (!value) {
|
|
1452
|
+
throw new OrchestrationError({
|
|
1453
|
+
code: "NOT_FOUND",
|
|
1454
|
+
message: `${kind} handle '${handle}' was not found`,
|
|
1455
|
+
retryable: false
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
if (value.resourceUid !== resourceUid) {
|
|
1459
|
+
throw new OrchestrationError({
|
|
1460
|
+
code: "FORBIDDEN",
|
|
1461
|
+
message: `${kind} handle '${handle}' belongs to another resource`,
|
|
1462
|
+
retryable: false
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
return value;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1400
1468
|
// src/orchestration/drivers/auditTelemetryManagement.ts
|
|
1401
1469
|
function createFakeAuditTelemetryState() {
|
|
1402
1470
|
return {
|
|
@@ -1412,16 +1480,8 @@ var FORBIDDEN_ATTRIBUTE = /(?:secret|token|password|credential|authorization|coo
|
|
|
1412
1480
|
function invalid3(message) {
|
|
1413
1481
|
throw new OrchestrationError({ code: "INVALID", message, retryable: false });
|
|
1414
1482
|
}
|
|
1415
|
-
function stable(value) {
|
|
1416
|
-
if (value === void 0) return "undefined";
|
|
1417
|
-
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
1418
|
-
if (value !== null && typeof value === "object") {
|
|
1419
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable(item)}`).join(",")}}`;
|
|
1420
|
-
}
|
|
1421
|
-
return JSON.stringify(value) ?? typeof value;
|
|
1422
|
-
}
|
|
1423
1483
|
async function digest(value) {
|
|
1424
|
-
const bytes = new TextEncoder().encode(
|
|
1484
|
+
const bytes = new TextEncoder().encode(canonicalDriverValue(value));
|
|
1425
1485
|
const result = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
1426
1486
|
return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
1427
1487
|
}
|
|
@@ -1439,29 +1499,13 @@ function createFakeAuditTelemetryManagementDriver(options = {}) {
|
|
|
1439
1499
|
const maxRecordsPerResource = options.maxRecordsPerResource ?? 1e4;
|
|
1440
1500
|
const maxAttributes = options.maxAttributes ?? 16;
|
|
1441
1501
|
function validate(request, expectedMethod, actorKinds) {
|
|
1442
|
-
|
|
1502
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
1443
1503
|
now,
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1504
|
+
fences: state.fences,
|
|
1505
|
+
expectedMethod,
|
|
1506
|
+
fenceName: "audit",
|
|
1507
|
+
actorKinds
|
|
1447
1508
|
});
|
|
1448
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
1449
|
-
throw new OrchestrationError({
|
|
1450
|
-
code: "FORBIDDEN",
|
|
1451
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
1452
|
-
retryable: false
|
|
1453
|
-
});
|
|
1454
|
-
}
|
|
1455
|
-
const epoch = request.fencingEpoch;
|
|
1456
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
1457
|
-
if (epoch < current) {
|
|
1458
|
-
throw new OrchestrationError({
|
|
1459
|
-
code: "STALE_EPOCH",
|
|
1460
|
-
message: `stale audit fencing epoch ${epoch}; current epoch is ${current}`,
|
|
1461
|
-
retryable: false
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
state.fences.set(request.resource.uid, epoch);
|
|
1465
1509
|
}
|
|
1466
1510
|
function common(request) {
|
|
1467
1511
|
const policyDigest = requiredString2(request.payload, "policyDigest", 80);
|
|
@@ -1491,7 +1535,7 @@ function createFakeAuditTelemetryManagementDriver(options = {}) {
|
|
|
1491
1535
|
}
|
|
1492
1536
|
async function append(request, kind, data) {
|
|
1493
1537
|
const idempotencyKey = `${request.resource.uid}:${request.method}:${request.idempotencyKey}`;
|
|
1494
|
-
const fingerprint =
|
|
1538
|
+
const fingerprint = canonicalDriverValue(request.payload);
|
|
1495
1539
|
let release;
|
|
1496
1540
|
const previousAppend = state.appendTail;
|
|
1497
1541
|
state.appendTail = new Promise((resolve) => {
|
|
@@ -2612,24 +2656,6 @@ function requiredString4(payload, field) {
|
|
|
2612
2656
|
if (payload === null || typeof payload !== "object" || typeof payload[field] !== "string" || !payload[field]) invalid5(`identity payload '${field}' is required`);
|
|
2613
2657
|
return payload[field];
|
|
2614
2658
|
}
|
|
2615
|
-
function owned(collection, handle, resourceUid, kind) {
|
|
2616
|
-
const value = collection.get(handle);
|
|
2617
|
-
if (!value) {
|
|
2618
|
-
throw new OrchestrationError({
|
|
2619
|
-
code: "NOT_FOUND",
|
|
2620
|
-
message: `${kind} handle '${handle}' was not found`,
|
|
2621
|
-
retryable: false
|
|
2622
|
-
});
|
|
2623
|
-
}
|
|
2624
|
-
if (value.resourceUid !== resourceUid) {
|
|
2625
|
-
throw new OrchestrationError({
|
|
2626
|
-
code: "FORBIDDEN",
|
|
2627
|
-
message: `${kind} handle '${handle}' belongs to another resource`,
|
|
2628
|
-
retryable: false
|
|
2629
|
-
});
|
|
2630
|
-
}
|
|
2631
|
-
return value;
|
|
2632
|
-
}
|
|
2633
2659
|
function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
2634
2660
|
const state = options.state ?? createFakeIdentityAttestationState();
|
|
2635
2661
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
@@ -2646,29 +2672,13 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2646
2672
|
`sha256:${"a".repeat(64)}`
|
|
2647
2673
|
];
|
|
2648
2674
|
function validate(request, expectedMethod, actorKinds) {
|
|
2649
|
-
|
|
2675
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
2650
2676
|
now,
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2677
|
+
fences: state.fences,
|
|
2678
|
+
expectedMethod,
|
|
2679
|
+
fenceName: "identity",
|
|
2680
|
+
actorKinds
|
|
2654
2681
|
});
|
|
2655
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
2656
|
-
throw new OrchestrationError({
|
|
2657
|
-
code: "FORBIDDEN",
|
|
2658
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
2659
|
-
retryable: false
|
|
2660
|
-
});
|
|
2661
|
-
}
|
|
2662
|
-
const fence = request.fencingEpoch;
|
|
2663
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
2664
|
-
if (fence < current) {
|
|
2665
|
-
throw new OrchestrationError({
|
|
2666
|
-
code: "STALE_EPOCH",
|
|
2667
|
-
message: `stale identity fencing epoch ${fence}; current epoch is ${current}`,
|
|
2668
|
-
retryable: false
|
|
2669
|
-
});
|
|
2670
|
-
}
|
|
2671
|
-
state.fences.set(request.resource.uid, fence);
|
|
2672
2682
|
}
|
|
2673
2683
|
function ttl(payload, field, maximum) {
|
|
2674
2684
|
if (payload === null || typeof payload !== "object") {
|
|
@@ -2683,34 +2693,11 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2683
2693
|
state.nextHandle += 1;
|
|
2684
2694
|
return handle;
|
|
2685
2695
|
}
|
|
2686
|
-
function key(request, operation) {
|
|
2687
|
-
return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
2688
|
-
}
|
|
2689
|
-
function stable6(value) {
|
|
2690
|
-
if (value === void 0) return "undefined";
|
|
2691
|
-
if (Array.isArray(value)) return `[${value.map(stable6).join(",")}]`;
|
|
2692
|
-
if (value !== null && typeof value === "object") {
|
|
2693
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([name, item]) => `${JSON.stringify(name)}:${stable6(item)}`).join(",")}}`;
|
|
2694
|
-
}
|
|
2695
|
-
return JSON.stringify(value) ?? typeof value;
|
|
2696
|
-
}
|
|
2697
2696
|
function previous(request, operation) {
|
|
2698
|
-
|
|
2699
|
-
const handle = state.idempotency.get(idempotency);
|
|
2700
|
-
if (!handle) return void 0;
|
|
2701
|
-
if (state.idempotencyFingerprints.get(idempotency) !== stable6(request.payload)) {
|
|
2702
|
-
throw new OrchestrationError({
|
|
2703
|
-
code: "CONFLICT",
|
|
2704
|
-
message: `identity ${operation} idempotency key was reused with different input`,
|
|
2705
|
-
retryable: false
|
|
2706
|
-
});
|
|
2707
|
-
}
|
|
2708
|
-
return handle;
|
|
2697
|
+
return findIdempotentDriverHandle(state, request, operation, "identity");
|
|
2709
2698
|
}
|
|
2710
2699
|
function remember(request, operation, handle) {
|
|
2711
|
-
|
|
2712
|
-
state.idempotency.set(idempotency, handle);
|
|
2713
|
-
state.idempotencyFingerprints.set(idempotency, stable6(request.payload));
|
|
2700
|
+
rememberIdempotentDriverHandle(state, request, operation, handle);
|
|
2714
2701
|
}
|
|
2715
2702
|
function assertActiveIdentity(identity) {
|
|
2716
2703
|
if (identity.revoked) {
|
|
@@ -2754,7 +2741,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2754
2741
|
const ttlMs = ttl(request.payload, "ttlMs", maxSessionTtlMs);
|
|
2755
2742
|
const existing = previous(request, "enroll");
|
|
2756
2743
|
if (existing) {
|
|
2757
|
-
return structuredClone(
|
|
2744
|
+
return structuredClone(getOwnedDriverValue(
|
|
2758
2745
|
state.enrollments,
|
|
2759
2746
|
existing,
|
|
2760
2747
|
request.resource.uid,
|
|
@@ -2778,7 +2765,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2778
2765
|
},
|
|
2779
2766
|
async challenge(request) {
|
|
2780
2767
|
validate(request, "identity.challenge", ["controller", "admin"]);
|
|
2781
|
-
const enrollment =
|
|
2768
|
+
const enrollment = getOwnedDriverValue(
|
|
2782
2769
|
state.enrollments,
|
|
2783
2770
|
requiredString4(request.payload, "enrollmentHandle"),
|
|
2784
2771
|
request.resource.uid,
|
|
@@ -2791,7 +2778,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2791
2778
|
const ttlMs = ttl(request.payload, "ttlMs", maxChallengeTtlMs);
|
|
2792
2779
|
const existing = previous(request, "challenge");
|
|
2793
2780
|
if (existing) {
|
|
2794
|
-
return structuredClone(
|
|
2781
|
+
return structuredClone(getOwnedDriverValue(
|
|
2795
2782
|
state.challenges,
|
|
2796
2783
|
existing,
|
|
2797
2784
|
request.resource.uid,
|
|
@@ -2821,13 +2808,13 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2821
2808
|
},
|
|
2822
2809
|
async attest(request) {
|
|
2823
2810
|
validate(request, "identity.attest", ["controller", "verifier"]);
|
|
2824
|
-
const challenge =
|
|
2811
|
+
const challenge = getOwnedDriverValue(
|
|
2825
2812
|
state.challenges,
|
|
2826
2813
|
requiredString4(request.payload, "challengeHandle"),
|
|
2827
2814
|
request.resource.uid,
|
|
2828
2815
|
"challenge"
|
|
2829
2816
|
);
|
|
2830
|
-
const enrollment =
|
|
2817
|
+
const enrollment = getOwnedDriverValue(
|
|
2831
2818
|
state.enrollments,
|
|
2832
2819
|
challenge.enrollmentHandle,
|
|
2833
2820
|
request.resource.uid,
|
|
@@ -2863,7 +2850,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2863
2850
|
}
|
|
2864
2851
|
const existing = previous(request, "attest");
|
|
2865
2852
|
if (existing) {
|
|
2866
|
-
return structuredClone(
|
|
2853
|
+
return structuredClone(getOwnedDriverValue(
|
|
2867
2854
|
state.identities,
|
|
2868
2855
|
existing,
|
|
2869
2856
|
request.resource.uid,
|
|
@@ -2898,7 +2885,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2898
2885
|
},
|
|
2899
2886
|
async issueSession(request) {
|
|
2900
2887
|
validate(request, "identity.issue-session", ["controller", "admin"]);
|
|
2901
|
-
const identity =
|
|
2888
|
+
const identity = getOwnedDriverValue(
|
|
2902
2889
|
state.identities,
|
|
2903
2890
|
requiredString4(request.payload, "identityHandle"),
|
|
2904
2891
|
request.resource.uid,
|
|
@@ -2927,7 +2914,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2927
2914
|
const ttlMs = ttl(request.payload, "ttlMs", maxSessionTtlMs);
|
|
2928
2915
|
const existing = previous(request, "issue-session");
|
|
2929
2916
|
if (existing) {
|
|
2930
|
-
return structuredClone(
|
|
2917
|
+
return structuredClone(getOwnedDriverValue(
|
|
2931
2918
|
state.sessions,
|
|
2932
2919
|
existing,
|
|
2933
2920
|
request.resource.uid,
|
|
@@ -2951,7 +2938,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2951
2938
|
},
|
|
2952
2939
|
async rotate(request) {
|
|
2953
2940
|
validate(request, "identity.rotate", ["controller", "admin"]);
|
|
2954
|
-
const identity =
|
|
2941
|
+
const identity = getOwnedDriverValue(
|
|
2955
2942
|
state.identities,
|
|
2956
2943
|
requiredString4(request.payload, "identityHandle"),
|
|
2957
2944
|
request.resource.uid,
|
|
@@ -2968,7 +2955,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2968
2955
|
);
|
|
2969
2956
|
const existing = previous(request, "rotate");
|
|
2970
2957
|
if (existing) {
|
|
2971
|
-
return structuredClone(
|
|
2958
|
+
return structuredClone(getOwnedDriverValue(
|
|
2972
2959
|
state.identities,
|
|
2973
2960
|
existing,
|
|
2974
2961
|
request.resource.uid,
|
|
@@ -2996,7 +2983,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
2996
2983
|
},
|
|
2997
2984
|
async revoke(request) {
|
|
2998
2985
|
validate(request, "identity.revoke", ["controller", "admin"]);
|
|
2999
|
-
const identity =
|
|
2986
|
+
const identity = getOwnedDriverValue(
|
|
3000
2987
|
state.identities,
|
|
3001
2988
|
requiredString4(request.payload, "identityHandle"),
|
|
3002
2989
|
request.resource.uid,
|
|
@@ -4063,12 +4050,12 @@ function createManagedCredentialBrokerAdapter(broker, options) {
|
|
|
4063
4050
|
retryable: false
|
|
4064
4051
|
});
|
|
4065
4052
|
}
|
|
4066
|
-
const
|
|
4067
|
-
if (!
|
|
4053
|
+
const stable = options.stableHandleFor?.(request) ?? stableHandle();
|
|
4054
|
+
if (!stable || stable.length > 2048) {
|
|
4068
4055
|
invalid6("credential stable handle is empty or too long");
|
|
4069
4056
|
}
|
|
4070
4057
|
if (options.handleStore) {
|
|
4071
|
-
const adopted = await options.handleStore.get(
|
|
4058
|
+
const adopted = await options.handleStore.get(stable);
|
|
4072
4059
|
if (adopted) {
|
|
4073
4060
|
const inspection = await broker.inspect(adopted.token);
|
|
4074
4061
|
const exact = inspection.grantId === request.resource.uid && canonicalDriverValue(inspection.scope) === canonicalDriverValue({
|
|
@@ -4088,13 +4075,13 @@ function createManagedCredentialBrokerAdapter(broker, options) {
|
|
|
4088
4075
|
});
|
|
4089
4076
|
}
|
|
4090
4077
|
const adoptedRecord = {
|
|
4091
|
-
stableHandle:
|
|
4078
|
+
stableHandle: stable,
|
|
4092
4079
|
token: adopted.token,
|
|
4093
4080
|
resourceUid: request.resource.uid,
|
|
4094
4081
|
targetDriver: request.payload.targetDriver
|
|
4095
4082
|
};
|
|
4096
|
-
records.set(
|
|
4097
|
-
await rememberIdempotency(key, request,
|
|
4083
|
+
records.set(stable, adoptedRecord);
|
|
4084
|
+
await rememberIdempotency(key, request, stable);
|
|
4098
4085
|
return managed(adoptedRecord, inspection);
|
|
4099
4086
|
}
|
|
4100
4087
|
}
|
|
@@ -4110,7 +4097,7 @@ function createManagedCredentialBrokerAdapter(broker, options) {
|
|
|
4110
4097
|
grantId: request.resource.uid
|
|
4111
4098
|
});
|
|
4112
4099
|
const record2 = {
|
|
4113
|
-
stableHandle:
|
|
4100
|
+
stableHandle: stable,
|
|
4114
4101
|
token: issued.token,
|
|
4115
4102
|
resourceUid: request.resource.uid,
|
|
4116
4103
|
targetDriver: request.payload.targetDriver
|
|
@@ -5260,13 +5247,6 @@ function createFakeNetworkManagementState() {
|
|
|
5260
5247
|
nextHandle: 1
|
|
5261
5248
|
};
|
|
5262
5249
|
}
|
|
5263
|
-
function stable2(value) {
|
|
5264
|
-
if (Array.isArray(value)) return `[${value.map(stable2).join(",")}]`;
|
|
5265
|
-
if (value !== null && typeof value === "object") {
|
|
5266
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable2(item)}`).join(",")}}`;
|
|
5267
|
-
}
|
|
5268
|
-
return JSON.stringify(value) ?? typeof value;
|
|
5269
|
-
}
|
|
5270
5250
|
function invalid7(message) {
|
|
5271
5251
|
throw new OrchestrationError({ code: "INVALID", message, retryable: false });
|
|
5272
5252
|
}
|
|
@@ -5467,31 +5447,15 @@ function createFakeNetworkManagementDriver(options = {}) {
|
|
|
5467
5447
|
...options.capabilities
|
|
5468
5448
|
};
|
|
5469
5449
|
function validate(request, method) {
|
|
5470
|
-
|
|
5450
|
+
return assertFencedDriverRequestEnvelope(request, {
|
|
5471
5451
|
now,
|
|
5452
|
+
fences: state.fences,
|
|
5472
5453
|
requireRun: true,
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5454
|
+
expectedMethod: method,
|
|
5455
|
+
fenceName: "network",
|
|
5456
|
+
actorKinds: ["controller", "admin"],
|
|
5457
|
+
forbiddenMessage: () => "network lifecycle requires a controller or admin actor"
|
|
5476
5458
|
});
|
|
5477
|
-
if (request.actor.kind !== "controller" && request.actor.kind !== "admin") {
|
|
5478
|
-
throw new OrchestrationError({
|
|
5479
|
-
code: "FORBIDDEN",
|
|
5480
|
-
message: "network lifecycle requires a controller or admin actor",
|
|
5481
|
-
retryable: false
|
|
5482
|
-
});
|
|
5483
|
-
}
|
|
5484
|
-
const fence = request.fencingEpoch;
|
|
5485
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
5486
|
-
if (fence < current) {
|
|
5487
|
-
throw new OrchestrationError({
|
|
5488
|
-
code: "STALE_EPOCH",
|
|
5489
|
-
message: `stale network fencing epoch ${fence}; current epoch is ${current}`,
|
|
5490
|
-
retryable: false
|
|
5491
|
-
});
|
|
5492
|
-
}
|
|
5493
|
-
state.fences.set(request.resource.uid, fence);
|
|
5494
|
-
return fence;
|
|
5495
5459
|
}
|
|
5496
5460
|
function nextHandle(prefix) {
|
|
5497
5461
|
const handle = `${prefix}:${state.nextHandle}`;
|
|
@@ -5555,7 +5519,7 @@ function createFakeNetworkManagementDriver(options = {}) {
|
|
|
5555
5519
|
}
|
|
5556
5520
|
function idempotent(request, operation) {
|
|
5557
5521
|
const key = `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
5558
|
-
const fingerprint =
|
|
5522
|
+
const fingerprint = canonicalDriverValue(request.payload);
|
|
5559
5523
|
const existing = state.idempotency.get(key);
|
|
5560
5524
|
if (existing) {
|
|
5561
5525
|
if (existing.fingerprint !== fingerprint) {
|
|
@@ -5572,7 +5536,7 @@ function createFakeNetworkManagementDriver(options = {}) {
|
|
|
5572
5536
|
function remember(request, operation, resultHandle) {
|
|
5573
5537
|
state.idempotency.set(
|
|
5574
5538
|
`${request.resource.uid}:${operation}:${request.idempotencyKey}`,
|
|
5575
|
-
{ fingerprint:
|
|
5539
|
+
{ fingerprint: canonicalDriverValue(request.payload), resultHandle }
|
|
5576
5540
|
);
|
|
5577
5541
|
}
|
|
5578
5542
|
return {
|
|
@@ -6120,14 +6084,6 @@ function createFakeModelManagementState() {
|
|
|
6120
6084
|
nextHandle: 1
|
|
6121
6085
|
};
|
|
6122
6086
|
}
|
|
6123
|
-
function stable3(value) {
|
|
6124
|
-
if (value === void 0) return "undefined";
|
|
6125
|
-
if (Array.isArray(value)) return `[${value.map(stable3).join(",")}]`;
|
|
6126
|
-
if (value !== null && typeof value === "object") {
|
|
6127
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable3(item)}`).join(",")}}`;
|
|
6128
|
-
}
|
|
6129
|
-
return JSON.stringify(value) ?? typeof value;
|
|
6130
|
-
}
|
|
6131
6087
|
function invalid8(message) {
|
|
6132
6088
|
throw new OrchestrationError({ code: "INVALID", message, retryable: false });
|
|
6133
6089
|
}
|
|
@@ -6186,31 +6142,15 @@ function createFakeModelManagementDriver(options = {}) {
|
|
|
6186
6142
|
};
|
|
6187
6143
|
const active = /* @__PURE__ */ new Map();
|
|
6188
6144
|
function validate(request, method) {
|
|
6189
|
-
|
|
6145
|
+
return assertFencedDriverRequestEnvelope(request, {
|
|
6190
6146
|
now,
|
|
6147
|
+
fences: state.fences,
|
|
6191
6148
|
requireRun: true,
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6149
|
+
expectedMethod: method,
|
|
6150
|
+
fenceName: "model",
|
|
6151
|
+
actorKinds: ["controller", "admin"],
|
|
6152
|
+
forbiddenMessage: () => "model provider access requires a controller or admin actor"
|
|
6195
6153
|
});
|
|
6196
|
-
if (request.actor.kind !== "controller" && request.actor.kind !== "admin") {
|
|
6197
|
-
throw new OrchestrationError({
|
|
6198
|
-
code: "FORBIDDEN",
|
|
6199
|
-
message: "model provider access requires a controller or admin actor",
|
|
6200
|
-
retryable: false
|
|
6201
|
-
});
|
|
6202
|
-
}
|
|
6203
|
-
const fence = request.fencingEpoch;
|
|
6204
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
6205
|
-
if (fence < current) {
|
|
6206
|
-
throw new OrchestrationError({
|
|
6207
|
-
code: "STALE_EPOCH",
|
|
6208
|
-
message: `stale model fencing epoch ${fence}; current epoch is ${current}`,
|
|
6209
|
-
retryable: false
|
|
6210
|
-
});
|
|
6211
|
-
}
|
|
6212
|
-
state.fences.set(request.resource.uid, fence);
|
|
6213
|
-
return fence;
|
|
6214
6154
|
}
|
|
6215
6155
|
function modelFor(payload) {
|
|
6216
6156
|
assertOnlyFields2(
|
|
@@ -6337,7 +6277,7 @@ function createFakeModelManagementDriver(options = {}) {
|
|
|
6337
6277
|
const fence = validate(request, "model.generate");
|
|
6338
6278
|
const model = modelFor(request.payload);
|
|
6339
6279
|
await authorize(request, model);
|
|
6340
|
-
const inputFingerprint =
|
|
6280
|
+
const inputFingerprint = canonicalDriverValue({
|
|
6341
6281
|
payload: request.payload,
|
|
6342
6282
|
run: request.run,
|
|
6343
6283
|
session: request.session,
|
|
@@ -6576,7 +6516,9 @@ function createModelManagementConformanceSuite(options) {
|
|
|
6576
6516
|
);
|
|
6577
6517
|
const first = await collect(driver, request);
|
|
6578
6518
|
const second = await collect(driver, request);
|
|
6579
|
-
if (
|
|
6519
|
+
if (canonicalDriverValue(first) !== canonicalDriverValue(second)) {
|
|
6520
|
+
throw new Error("model generation did not replay");
|
|
6521
|
+
}
|
|
6580
6522
|
if (first.at(-1)?.type !== "done") throw new Error("model stream did not complete");
|
|
6581
6523
|
let driftRejected = false;
|
|
6582
6524
|
try {
|
|
@@ -6710,16 +6652,8 @@ function requiredString6(value, field) {
|
|
|
6710
6652
|
if (value === null || typeof value !== "object" || typeof value[field] !== "string" || !value[field]) invalid9(`policy payload '${field}' is required`);
|
|
6711
6653
|
return value[field];
|
|
6712
6654
|
}
|
|
6713
|
-
function stable4(value) {
|
|
6714
|
-
if (value === void 0) return "undefined";
|
|
6715
|
-
if (Array.isArray(value)) return `[${value.map(stable4).join(",")}]`;
|
|
6716
|
-
if (value !== null && typeof value === "object") {
|
|
6717
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable4(item)}`).join(",")}}`;
|
|
6718
|
-
}
|
|
6719
|
-
return JSON.stringify(value) ?? typeof value;
|
|
6720
|
-
}
|
|
6721
6655
|
async function digest2(value) {
|
|
6722
|
-
const bytes = new TextEncoder().encode(
|
|
6656
|
+
const bytes = new TextEncoder().encode(canonicalDriverValue(value));
|
|
6723
6657
|
const result = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
6724
6658
|
return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
6725
6659
|
}
|
|
@@ -6740,34 +6674,18 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
6740
6674
|
]
|
|
6741
6675
|
);
|
|
6742
6676
|
function validate(request, expectedMethod, actorKinds) {
|
|
6743
|
-
|
|
6677
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
6744
6678
|
now,
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6679
|
+
fences: state.fences,
|
|
6680
|
+
expectedMethod,
|
|
6681
|
+
fenceName: "policy",
|
|
6682
|
+
actorKinds
|
|
6748
6683
|
});
|
|
6749
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
6750
|
-
throw new OrchestrationError({
|
|
6751
|
-
code: "FORBIDDEN",
|
|
6752
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
6753
|
-
retryable: false
|
|
6754
|
-
});
|
|
6755
|
-
}
|
|
6756
|
-
const epoch = request.fencingEpoch;
|
|
6757
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
6758
|
-
if (epoch < current) {
|
|
6759
|
-
throw new OrchestrationError({
|
|
6760
|
-
code: "STALE_EPOCH",
|
|
6761
|
-
message: `stale policy fencing epoch ${epoch}; current epoch is ${current}`,
|
|
6762
|
-
retryable: false
|
|
6763
|
-
});
|
|
6764
|
-
}
|
|
6765
|
-
state.fences.set(request.resource.uid, epoch);
|
|
6766
6684
|
}
|
|
6767
6685
|
function assertPolicyDigest(value) {
|
|
6768
6686
|
if (!SHA2566.test(value)) invalid9("policyDigest must be a canonical sha256 digest");
|
|
6769
6687
|
}
|
|
6770
|
-
function
|
|
6688
|
+
function owned(handle, resourceUid) {
|
|
6771
6689
|
const decision = state.decisions.get(handle);
|
|
6772
6690
|
if (!decision) {
|
|
6773
6691
|
throw new OrchestrationError({
|
|
@@ -6787,18 +6705,14 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
6787
6705
|
}
|
|
6788
6706
|
async function decide(request, operation, kind, outcome, policyDigest, reasons, obligations = [], approval) {
|
|
6789
6707
|
assertPolicyDigest(policyDigest);
|
|
6790
|
-
const
|
|
6791
|
-
|
|
6792
|
-
|
|
6708
|
+
const previousHandle = findIdempotentDriverHandle(
|
|
6709
|
+
state,
|
|
6710
|
+
request,
|
|
6711
|
+
operation,
|
|
6712
|
+
"policy"
|
|
6713
|
+
);
|
|
6793
6714
|
if (previousHandle) {
|
|
6794
|
-
|
|
6795
|
-
throw new OrchestrationError({
|
|
6796
|
-
code: "CONFLICT",
|
|
6797
|
-
message: `policy ${operation} idempotency key was reused with different input`,
|
|
6798
|
-
retryable: false
|
|
6799
|
-
});
|
|
6800
|
-
}
|
|
6801
|
-
return structuredClone(owned2(previousHandle, request.resource.uid));
|
|
6715
|
+
return structuredClone(owned(previousHandle, request.resource.uid));
|
|
6802
6716
|
}
|
|
6803
6717
|
const decision = {
|
|
6804
6718
|
decisionHandle: `policy-decision:${state.nextHandle++}`,
|
|
@@ -6814,8 +6728,12 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
6814
6728
|
approval
|
|
6815
6729
|
};
|
|
6816
6730
|
state.decisions.set(decision.decisionHandle, decision);
|
|
6817
|
-
|
|
6818
|
-
|
|
6731
|
+
rememberIdempotentDriverHandle(
|
|
6732
|
+
state,
|
|
6733
|
+
request,
|
|
6734
|
+
operation,
|
|
6735
|
+
decision.decisionHandle
|
|
6736
|
+
);
|
|
6819
6737
|
return structuredClone(decision);
|
|
6820
6738
|
}
|
|
6821
6739
|
return {
|
|
@@ -6888,7 +6806,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
6888
6806
|
}
|
|
6889
6807
|
let approval;
|
|
6890
6808
|
if (request.payload.approvalDecisionHandle) {
|
|
6891
|
-
approval =
|
|
6809
|
+
approval = owned(request.payload.approvalDecisionHandle, request.resource.uid);
|
|
6892
6810
|
}
|
|
6893
6811
|
const needsApproval = effect !== "read";
|
|
6894
6812
|
const approvalValid = !needsApproval || approval?.kind === "approval" && approval.outcome === "allow" && approval.policyDigest === policyDigest && approval.approval?.subjectDigest === operationDigest && Date.parse(approval.approval.expiresAt) > now().getTime();
|
|
@@ -6936,7 +6854,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
6936
6854
|
if (!["allow", "deny"].includes(request.payload.outcome)) {
|
|
6937
6855
|
invalid9("approval outcome must be allow or deny");
|
|
6938
6856
|
}
|
|
6939
|
-
const decision =
|
|
6857
|
+
const decision = owned(handle, request.resource.uid);
|
|
6940
6858
|
if (decision.kind !== "approval") invalid9("decision is not an approval");
|
|
6941
6859
|
if (decision.approval && Date.parse(decision.approval.expiresAt) <= now().getTime()) {
|
|
6942
6860
|
decision.outcome = "deny";
|
|
@@ -6999,7 +6917,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
6999
6917
|
"verifier",
|
|
7000
6918
|
"admin"
|
|
7001
6919
|
]);
|
|
7002
|
-
const decision =
|
|
6920
|
+
const decision = owned(
|
|
7003
6921
|
requiredString6(request.payload, "decisionHandle"),
|
|
7004
6922
|
request.resource.uid
|
|
7005
6923
|
);
|
|
@@ -7236,6 +7154,7 @@ function createFakeStorageManagementState() {
|
|
|
7236
7154
|
stages: /* @__PURE__ */ new Map(),
|
|
7237
7155
|
publications: /* @__PURE__ */ new Map(),
|
|
7238
7156
|
idempotency: /* @__PURE__ */ new Map(),
|
|
7157
|
+
idempotencyFingerprints: /* @__PURE__ */ new Map(),
|
|
7239
7158
|
fences: /* @__PURE__ */ new Map(),
|
|
7240
7159
|
nextHandle: 1
|
|
7241
7160
|
};
|
|
@@ -7263,32 +7182,18 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7263
7182
|
const state = options.state ?? createFakeStorageManagementState();
|
|
7264
7183
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
7265
7184
|
function validate(request, expectedMethod) {
|
|
7266
|
-
|
|
7185
|
+
return assertFencedDriverRequestEnvelope(request, {
|
|
7267
7186
|
now,
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7187
|
+
fences: state.fences,
|
|
7188
|
+
expectedMethod,
|
|
7189
|
+
fenceName: "storage"
|
|
7271
7190
|
});
|
|
7272
|
-
const fence = request.fencingEpoch;
|
|
7273
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
7274
|
-
if (fence < current) {
|
|
7275
|
-
throw new OrchestrationError({
|
|
7276
|
-
code: "STALE_EPOCH",
|
|
7277
|
-
message: `stale storage fencing epoch ${fence}; current epoch is ${current}`,
|
|
7278
|
-
retryable: false
|
|
7279
|
-
});
|
|
7280
|
-
}
|
|
7281
|
-
state.fences.set(request.resource.uid, fence);
|
|
7282
|
-
return fence;
|
|
7283
7191
|
}
|
|
7284
7192
|
function nextHandle(prefix) {
|
|
7285
7193
|
const handle = `${prefix}:${state.nextHandle}`;
|
|
7286
7194
|
state.nextHandle += 1;
|
|
7287
7195
|
return handle;
|
|
7288
7196
|
}
|
|
7289
|
-
function operationKey(request, operation) {
|
|
7290
|
-
return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
7291
|
-
}
|
|
7292
7197
|
function getVolume(handle, resourceUid) {
|
|
7293
7198
|
const record2 = state.volumes.get(handle);
|
|
7294
7199
|
if (!record2 || record2.volume.phase === "Deleted") {
|
|
@@ -7307,27 +7212,8 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7307
7212
|
}
|
|
7308
7213
|
return record2;
|
|
7309
7214
|
}
|
|
7310
|
-
function owned2(collection, handle, resourceUid, kind) {
|
|
7311
|
-
const value = collection.get(handle);
|
|
7312
|
-
if (!value) {
|
|
7313
|
-
throw new OrchestrationError({
|
|
7314
|
-
code: "NOT_FOUND",
|
|
7315
|
-
message: `${kind} handle '${handle}' was not found`,
|
|
7316
|
-
retryable: false
|
|
7317
|
-
});
|
|
7318
|
-
}
|
|
7319
|
-
if (value.resourceUid !== resourceUid) {
|
|
7320
|
-
throw new OrchestrationError({
|
|
7321
|
-
code: "FORBIDDEN",
|
|
7322
|
-
message: `${kind} handle '${handle}' belongs to another resource`,
|
|
7323
|
-
retryable: false
|
|
7324
|
-
});
|
|
7325
|
-
}
|
|
7326
|
-
return value;
|
|
7327
|
-
}
|
|
7328
7215
|
function createVolume(request, capacityBytes, accessMode, replicaCount, operation) {
|
|
7329
|
-
const
|
|
7330
|
-
const existing = state.idempotency.get(key);
|
|
7216
|
+
const existing = findIdempotentDriverHandle(state, request, operation, "storage");
|
|
7331
7217
|
if (existing) return getVolume(existing, request.resource.uid).volume;
|
|
7332
7218
|
const volume = {
|
|
7333
7219
|
volumeHandle: nextHandle("volume"),
|
|
@@ -7338,7 +7224,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7338
7224
|
phase: "Available"
|
|
7339
7225
|
};
|
|
7340
7226
|
state.volumes.set(volume.volumeHandle, { volume, desiredReplicas: replicaCount });
|
|
7341
|
-
state
|
|
7227
|
+
rememberIdempotentDriverHandle(state, request, operation, volume.volumeHandle);
|
|
7342
7228
|
return volume;
|
|
7343
7229
|
}
|
|
7344
7230
|
return {
|
|
@@ -7394,9 +7280,10 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7394
7280
|
validate(request, "storage.snapshot");
|
|
7395
7281
|
const volumeHandle = requiredString7(request.payload, "volumeHandle");
|
|
7396
7282
|
getVolume(volumeHandle, request.resource.uid);
|
|
7397
|
-
const
|
|
7398
|
-
|
|
7399
|
-
|
|
7283
|
+
const existing = findIdempotentDriverHandle(state, request, "snapshot", "storage");
|
|
7284
|
+
if (existing) {
|
|
7285
|
+
return getOwnedDriverValue(state.snapshots, existing, request.resource.uid, "snapshot");
|
|
7286
|
+
}
|
|
7400
7287
|
const snapshot = {
|
|
7401
7288
|
snapshotHandle: nextHandle("snapshot"),
|
|
7402
7289
|
volumeHandle,
|
|
@@ -7404,12 +7291,12 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7404
7291
|
createdAt: now().toISOString()
|
|
7405
7292
|
};
|
|
7406
7293
|
state.snapshots.set(snapshot.snapshotHandle, snapshot);
|
|
7407
|
-
state
|
|
7294
|
+
rememberIdempotentDriverHandle(state, request, "snapshot", snapshot.snapshotHandle);
|
|
7408
7295
|
return snapshot;
|
|
7409
7296
|
},
|
|
7410
7297
|
async restoreSnapshot(request) {
|
|
7411
7298
|
validate(request, "storage.restore");
|
|
7412
|
-
const snapshot =
|
|
7299
|
+
const snapshot = getOwnedDriverValue(
|
|
7413
7300
|
state.snapshots,
|
|
7414
7301
|
requiredString7(request.payload, "snapshotHandle"),
|
|
7415
7302
|
request.resource.uid,
|
|
@@ -7472,9 +7359,10 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7472
7359
|
validate(request, "storage.backup");
|
|
7473
7360
|
const volumeHandle = requiredString7(request.payload, "volumeHandle");
|
|
7474
7361
|
getVolume(volumeHandle, request.resource.uid);
|
|
7475
|
-
const
|
|
7476
|
-
|
|
7477
|
-
|
|
7362
|
+
const existing = findIdempotentDriverHandle(state, request, "backup", "storage");
|
|
7363
|
+
if (existing) {
|
|
7364
|
+
return getOwnedDriverValue(state.backups, existing, request.resource.uid, "backup");
|
|
7365
|
+
}
|
|
7478
7366
|
const backup = {
|
|
7479
7367
|
backupHandle: nextHandle("backup"),
|
|
7480
7368
|
volumeHandle,
|
|
@@ -7482,7 +7370,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7482
7370
|
createdAt: now().toISOString()
|
|
7483
7371
|
};
|
|
7484
7372
|
state.backups.set(backup.backupHandle, backup);
|
|
7485
|
-
state
|
|
7373
|
+
rememberIdempotentDriverHandle(state, request, "backup", backup.backupHandle);
|
|
7486
7374
|
return backup;
|
|
7487
7375
|
},
|
|
7488
7376
|
async stage(request) {
|
|
@@ -7490,9 +7378,10 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7490
7378
|
const volumeHandle = requiredString7(request.payload, "volumeHandle");
|
|
7491
7379
|
getVolume(volumeHandle, request.resource.uid);
|
|
7492
7380
|
const nodeId = requiredString7(request.payload, "nodeId");
|
|
7493
|
-
const
|
|
7494
|
-
|
|
7495
|
-
|
|
7381
|
+
const existing = findIdempotentDriverHandle(state, request, "stage", "storage");
|
|
7382
|
+
if (existing) {
|
|
7383
|
+
return getOwnedDriverValue(state.stages, existing, request.resource.uid, "stage");
|
|
7384
|
+
}
|
|
7496
7385
|
const stage = {
|
|
7497
7386
|
stageHandle: nextHandle("stage"),
|
|
7498
7387
|
volumeHandle,
|
|
@@ -7500,12 +7389,12 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7500
7389
|
nodeId
|
|
7501
7390
|
};
|
|
7502
7391
|
state.stages.set(stage.stageHandle, stage);
|
|
7503
|
-
state
|
|
7392
|
+
rememberIdempotentDriverHandle(state, request, "stage", stage.stageHandle);
|
|
7504
7393
|
return stage;
|
|
7505
7394
|
},
|
|
7506
7395
|
async publish(request) {
|
|
7507
7396
|
validate(request, "storage.publish");
|
|
7508
|
-
const stage =
|
|
7397
|
+
const stage = getOwnedDriverValue(
|
|
7509
7398
|
state.stages,
|
|
7510
7399
|
requiredString7(request.payload, "stageHandle"),
|
|
7511
7400
|
request.resource.uid,
|
|
@@ -7514,10 +7403,14 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7514
7403
|
getVolume(stage.volumeHandle, request.resource.uid);
|
|
7515
7404
|
const workloadUid = requiredString7(request.payload, "workloadUid");
|
|
7516
7405
|
if (typeof request.payload.readOnly !== "boolean") invalid10("publish readOnly is required");
|
|
7517
|
-
const
|
|
7518
|
-
const existing = state.idempotency.get(key);
|
|
7406
|
+
const existing = findIdempotentDriverHandle(state, request, "publish", "storage");
|
|
7519
7407
|
if (existing) {
|
|
7520
|
-
return
|
|
7408
|
+
return getOwnedDriverValue(
|
|
7409
|
+
state.publications,
|
|
7410
|
+
existing,
|
|
7411
|
+
request.resource.uid,
|
|
7412
|
+
"publication"
|
|
7413
|
+
);
|
|
7521
7414
|
}
|
|
7522
7415
|
const publication = {
|
|
7523
7416
|
publishHandle: nextHandle("publication"),
|
|
@@ -7527,7 +7420,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7527
7420
|
readOnly: request.payload.readOnly
|
|
7528
7421
|
};
|
|
7529
7422
|
state.publications.set(publication.publishHandle, publication);
|
|
7530
|
-
state
|
|
7423
|
+
rememberIdempotentDriverHandle(state, request, "publish", publication.publishHandle);
|
|
7531
7424
|
return publication;
|
|
7532
7425
|
},
|
|
7533
7426
|
async unpublish(request) {
|
|
@@ -7535,7 +7428,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7535
7428
|
const handle = requiredString7(request.payload, "publishHandle");
|
|
7536
7429
|
const publication = state.publications.get(handle);
|
|
7537
7430
|
if (!publication) return;
|
|
7538
|
-
|
|
7431
|
+
getOwnedDriverValue(state.publications, handle, request.resource.uid, "publication");
|
|
7539
7432
|
state.publications.delete(handle);
|
|
7540
7433
|
},
|
|
7541
7434
|
async unstage(request) {
|
|
@@ -7543,7 +7436,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7543
7436
|
const handle = requiredString7(request.payload, "stageHandle");
|
|
7544
7437
|
const stage = state.stages.get(handle);
|
|
7545
7438
|
if (!stage) return;
|
|
7546
|
-
|
|
7439
|
+
getOwnedDriverValue(state.stages, handle, request.resource.uid, "stage");
|
|
7547
7440
|
if ([...state.publications.values()].some(
|
|
7548
7441
|
(publication) => publication.stageHandle === handle
|
|
7549
7442
|
)) {
|
|
@@ -7557,13 +7450,13 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
7557
7450
|
},
|
|
7558
7451
|
async getStats(request) {
|
|
7559
7452
|
validate(request, "storage.stats");
|
|
7560
|
-
const publication =
|
|
7453
|
+
const publication = getOwnedDriverValue(
|
|
7561
7454
|
state.publications,
|
|
7562
7455
|
requiredString7(request.payload, "publishHandle"),
|
|
7563
7456
|
request.resource.uid,
|
|
7564
7457
|
"publication"
|
|
7565
7458
|
);
|
|
7566
|
-
const stage =
|
|
7459
|
+
const stage = getOwnedDriverValue(
|
|
7567
7460
|
state.stages,
|
|
7568
7461
|
publication.stageHandle,
|
|
7569
7462
|
request.resource.uid,
|
|
@@ -7789,18 +7682,10 @@ function requiredString8(value, field, maximum = 256) {
|
|
|
7789
7682
|
if (!result || result.length > maximum) invalid11(`tool payload '${field}' is invalid`);
|
|
7790
7683
|
return result;
|
|
7791
7684
|
}
|
|
7792
|
-
function stable5(value) {
|
|
7793
|
-
if (value === void 0) return "undefined";
|
|
7794
|
-
if (Array.isArray(value)) return `[${value.map(stable5).join(",")}]`;
|
|
7795
|
-
if (value !== null && typeof value === "object") {
|
|
7796
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable5(item)}`).join(",")}}`;
|
|
7797
|
-
}
|
|
7798
|
-
return JSON.stringify(value) ?? typeof value;
|
|
7799
|
-
}
|
|
7800
7685
|
async function digest3(value) {
|
|
7801
7686
|
const result = await globalThis.crypto.subtle.digest(
|
|
7802
7687
|
"SHA-256",
|
|
7803
|
-
new TextEncoder().encode(
|
|
7688
|
+
new TextEncoder().encode(canonicalDriverValue(value))
|
|
7804
7689
|
);
|
|
7805
7690
|
return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
7806
7691
|
}
|
|
@@ -7883,37 +7768,21 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
7883
7768
|
if (!SHA2567.test(descriptor.schemaDigest) || descriptor.schemaDigest !== actualSchemaDigest || !descriptor.name || !descriptor.version || !descriptor.targets.length) invalid11(`tool catalog descriptor '${descriptor.name}' is invalid`);
|
|
7884
7769
|
}
|
|
7885
7770
|
return digest3(
|
|
7886
|
-
tools.map(descriptorInput).sort((left, right) =>
|
|
7771
|
+
tools.map(descriptorInput).sort((left, right) => canonicalDriverValue(left).localeCompare(canonicalDriverValue(right)))
|
|
7887
7772
|
);
|
|
7888
7773
|
})();
|
|
7889
7774
|
return catalogDigestPromise;
|
|
7890
7775
|
}
|
|
7891
7776
|
function validate(request, expectedMethod, actorKinds = ["controller"]) {
|
|
7892
|
-
|
|
7777
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
7893
7778
|
now,
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7779
|
+
fences: state.fences,
|
|
7780
|
+
expectedMethod,
|
|
7781
|
+
fenceName: "tool",
|
|
7782
|
+
actorKinds
|
|
7897
7783
|
});
|
|
7898
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
7899
|
-
throw new OrchestrationError({
|
|
7900
|
-
code: "FORBIDDEN",
|
|
7901
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
7902
|
-
retryable: false
|
|
7903
|
-
});
|
|
7904
|
-
}
|
|
7905
|
-
const epoch = request.fencingEpoch;
|
|
7906
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
7907
|
-
if (epoch < current) {
|
|
7908
|
-
throw new OrchestrationError({
|
|
7909
|
-
code: "STALE_EPOCH",
|
|
7910
|
-
message: `stale tool fencing epoch ${epoch}; current epoch is ${current}`,
|
|
7911
|
-
retryable: false
|
|
7912
|
-
});
|
|
7913
|
-
}
|
|
7914
|
-
state.fences.set(request.resource.uid, epoch);
|
|
7915
7784
|
}
|
|
7916
|
-
function
|
|
7785
|
+
function owned(collection, handle, resourceUid, kind) {
|
|
7917
7786
|
const value = collection.get(handle);
|
|
7918
7787
|
if (!value) {
|
|
7919
7788
|
throw new OrchestrationError({
|
|
@@ -7938,21 +7807,10 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
7938
7807
|
return `${prefix}:${state.nextHandle++}`;
|
|
7939
7808
|
}
|
|
7940
7809
|
function idempotency(request, operation) {
|
|
7941
|
-
|
|
7942
|
-
const previous = state.idempotency.get(key);
|
|
7943
|
-
if (previous && state.idempotencyFingerprints.get(key) !== stable5(request.payload)) {
|
|
7944
|
-
throw new OrchestrationError({
|
|
7945
|
-
code: "CONFLICT",
|
|
7946
|
-
message: `tool ${operation} idempotency key was reused with different input`,
|
|
7947
|
-
retryable: false
|
|
7948
|
-
});
|
|
7949
|
-
}
|
|
7950
|
-
return previous;
|
|
7810
|
+
return findIdempotentDriverHandle(state, request, operation, "tool");
|
|
7951
7811
|
}
|
|
7952
7812
|
function remember(request, operation, handle) {
|
|
7953
|
-
|
|
7954
|
-
state.idempotency.set(key, handle);
|
|
7955
|
-
state.idempotencyFingerprints.set(key, stable5(request.payload));
|
|
7813
|
+
rememberIdempotentDriverHandle(state, request, operation, handle);
|
|
7956
7814
|
}
|
|
7957
7815
|
async function* defaultExecutor(descriptor, target, arguments_) {
|
|
7958
7816
|
yield JSON.stringify({ tool: descriptor.name, target, arguments: arguments_ });
|
|
@@ -8035,7 +7893,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8035
7893
|
if (request.payload.operationIdempotencyKey && !descriptor.supportsIdempotency) invalid11("tool does not support operation idempotency");
|
|
8036
7894
|
const previous = idempotency(request, "prepare");
|
|
8037
7895
|
if (previous) {
|
|
8038
|
-
return structuredClone(
|
|
7896
|
+
return structuredClone(owned(
|
|
8039
7897
|
state.preparations,
|
|
8040
7898
|
previous,
|
|
8041
7899
|
request.resource.uid,
|
|
@@ -8060,7 +7918,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8060
7918
|
},
|
|
8061
7919
|
async authorize(request) {
|
|
8062
7920
|
validate(request, "tool.authorize", ["controller", "admin"]);
|
|
8063
|
-
const preparation =
|
|
7921
|
+
const preparation = owned(
|
|
8064
7922
|
state.preparations,
|
|
8065
7923
|
requiredString8(request.payload, "preparationHandle"),
|
|
8066
7924
|
request.resource.uid,
|
|
@@ -8091,7 +7949,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8091
7949
|
}
|
|
8092
7950
|
const previous = idempotency(request, "authorize");
|
|
8093
7951
|
if (previous) {
|
|
8094
|
-
return structuredClone(
|
|
7952
|
+
return structuredClone(owned(
|
|
8095
7953
|
state.authorizations,
|
|
8096
7954
|
previous,
|
|
8097
7955
|
request.resource.uid,
|
|
@@ -8113,13 +7971,13 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8113
7971
|
},
|
|
8114
7972
|
async *invoke(request, invokeOptions = {}) {
|
|
8115
7973
|
validate(request, "tool.invoke");
|
|
8116
|
-
const preparation =
|
|
7974
|
+
const preparation = owned(
|
|
8117
7975
|
state.preparations,
|
|
8118
7976
|
requiredString8(request.payload, "preparationHandle"),
|
|
8119
7977
|
request.resource.uid,
|
|
8120
7978
|
"tool preparation"
|
|
8121
7979
|
);
|
|
8122
|
-
const authorization =
|
|
7980
|
+
const authorization = owned(
|
|
8123
7981
|
state.authorizations,
|
|
8124
7982
|
requiredString8(request.payload, "authorizationHandle"),
|
|
8125
7983
|
request.resource.uid,
|
|
@@ -8139,7 +7997,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8139
7997
|
}
|
|
8140
7998
|
const previous = idempotency(request, "invoke");
|
|
8141
7999
|
if (previous) {
|
|
8142
|
-
const execution2 =
|
|
8000
|
+
const execution2 = owned(
|
|
8143
8001
|
state.executions,
|
|
8144
8002
|
previous,
|
|
8145
8003
|
request.resource.uid,
|
|
@@ -8244,14 +8102,14 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8244
8102
|
},
|
|
8245
8103
|
async reconcileUnknownEffect(request) {
|
|
8246
8104
|
validate(request, "tool.reconcile-unknown", ["controller", "verifier", "admin"]);
|
|
8247
|
-
const execution =
|
|
8105
|
+
const execution = owned(
|
|
8248
8106
|
state.executions,
|
|
8249
8107
|
requiredString8(request.payload, "executionHandle"),
|
|
8250
8108
|
request.resource.uid,
|
|
8251
8109
|
"tool execution"
|
|
8252
8110
|
);
|
|
8253
8111
|
if (execution.phase !== "Unknown") return structuredClone(execution);
|
|
8254
|
-
const preparation =
|
|
8112
|
+
const preparation = owned(
|
|
8255
8113
|
state.preparations,
|
|
8256
8114
|
execution.preparationHandle,
|
|
8257
8115
|
request.resource.uid,
|
|
@@ -8277,14 +8135,14 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8277
8135
|
},
|
|
8278
8136
|
async collectEvidence(request) {
|
|
8279
8137
|
validate(request, "tool.collect-evidence", ["controller", "verifier", "admin"]);
|
|
8280
|
-
const execution =
|
|
8138
|
+
const execution = owned(
|
|
8281
8139
|
state.executions,
|
|
8282
8140
|
requiredString8(request.payload, "executionHandle"),
|
|
8283
8141
|
request.resource.uid,
|
|
8284
8142
|
"tool execution"
|
|
8285
8143
|
);
|
|
8286
8144
|
const descriptor = tool(
|
|
8287
|
-
|
|
8145
|
+
owned(
|
|
8288
8146
|
state.preparations,
|
|
8289
8147
|
execution.preparationHandle,
|
|
8290
8148
|
request.resource.uid,
|
|
@@ -8294,7 +8152,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8294
8152
|
if (!descriptor?.supportsEvidence) invalid11("tool does not support evidence");
|
|
8295
8153
|
const previous = idempotency(request, "evidence");
|
|
8296
8154
|
if (previous) {
|
|
8297
|
-
return structuredClone(
|
|
8155
|
+
return structuredClone(owned(
|
|
8298
8156
|
state.evidence,
|
|
8299
8157
|
previous,
|
|
8300
8158
|
request.resource.uid,
|
|
@@ -8315,14 +8173,14 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
8315
8173
|
},
|
|
8316
8174
|
async cleanup(request) {
|
|
8317
8175
|
validate(request, "tool.cleanup");
|
|
8318
|
-
const preparation =
|
|
8176
|
+
const preparation = owned(
|
|
8319
8177
|
state.preparations,
|
|
8320
8178
|
requiredString8(request.payload, "preparationHandle"),
|
|
8321
8179
|
request.resource.uid,
|
|
8322
8180
|
"tool preparation"
|
|
8323
8181
|
);
|
|
8324
8182
|
if (request.payload.executionHandle) {
|
|
8325
|
-
const execution =
|
|
8183
|
+
const execution = owned(
|
|
8326
8184
|
state.executions,
|
|
8327
8185
|
request.payload.executionHandle,
|
|
8328
8186
|
request.resource.uid,
|
|
@@ -8481,7 +8339,7 @@ function createToolManagementConformanceSuite(options) {
|
|
|
8481
8339
|
{ executionHandle: first[0].executionHandle },
|
|
8482
8340
|
"inspect-invoke"
|
|
8483
8341
|
));
|
|
8484
|
-
if (!first.at(-1)?.final ||
|
|
8342
|
+
if (!first.at(-1)?.final || canonicalDriverValue(first) !== canonicalDriverValue(replay) || execution?.phase !== "Completed") throw new Error("tool streaming or retry did not converge");
|
|
8485
8343
|
}
|
|
8486
8344
|
},
|
|
8487
8345
|
{
|