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.
Files changed (96) hide show
  1. package/dist/browser.d.cts +26 -21
  2. package/dist/browser.d.ts +26 -21
  3. package/dist/chunk-4OITUYFC.js +37 -0
  4. package/dist/chunk-4OITUYFC.js.map +1 -0
  5. package/dist/{chunk-HY3U3GLE.js → chunk-5EUJNLVW.js} +1 -1
  6. package/dist/chunk-5EUJNLVW.js.map +1 -0
  7. package/dist/{chunk-KXVZQLJL.js → chunk-645GZGNM.js} +3 -2
  8. package/dist/chunk-645GZGNM.js.map +1 -0
  9. package/dist/{chunk-EPHRIRAL.js → chunk-6OLAL5CW.js} +16 -1
  10. package/dist/chunk-6OLAL5CW.js.map +1 -0
  11. package/dist/{chunk-LGUGYRR4.js → chunk-HVLCOJWI.js} +11 -6
  12. package/dist/{chunk-LGUGYRR4.js.map → chunk-HVLCOJWI.js.map} +1 -1
  13. package/dist/{chunk-5VYZV33O.js → chunk-KTZDDC7M.js} +64 -79
  14. package/dist/chunk-KTZDDC7M.js.map +1 -0
  15. package/dist/{chunk-K5KZJNDP.js → chunk-ROPAEJIM.js} +2 -2
  16. package/dist/{chunk-GYIOMQMY.js → chunk-UB77WKAU.js} +305 -429
  17. package/dist/chunk-UB77WKAU.js.map +1 -0
  18. package/dist/{chunk-KV6TC5UJ.js → chunk-XIEXGFPY.js} +3 -3
  19. package/dist/conversation.d.cts +4 -3
  20. package/dist/conversation.d.ts +4 -3
  21. package/dist/device-network-portable.cjs +2 -1
  22. package/dist/device-network-portable.cjs.map +1 -1
  23. package/dist/device-network-portable.d.cts +9 -7
  24. package/dist/device-network-portable.d.ts +9 -7
  25. package/dist/device-network-portable.js +1 -1
  26. package/dist/device-network.cjs +17 -1
  27. package/dist/device-network.cjs.map +1 -1
  28. package/dist/device-network.d.cts +6 -5
  29. package/dist/device-network.d.ts +6 -5
  30. package/dist/device-network.js +2 -2
  31. package/dist/{fetchProvider-B_vva3b3.d.ts → fetchProvider-Do8Hf1BN.d.ts} +1 -1
  32. package/dist/{fetchProvider-Bz4CE3_R.d.cts → fetchProvider-tMo6gc6N.d.cts} +1 -1
  33. package/dist/index.cjs +465 -537
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +20 -26
  36. package/dist/index.d.ts +20 -26
  37. package/dist/index.js +47 -52
  38. package/dist/index.js.map +1 -1
  39. package/dist/{interface-3C3eG8Hn.d.cts → interface-C54gkLA3.d.ts} +3 -110
  40. package/dist/{interface-3C3eG8Hn.d.ts → interface-CECFnbzR.d.cts} +3 -110
  41. package/dist/llm-providers.cjs.map +1 -1
  42. package/dist/llm-providers.d.cts +3 -2
  43. package/dist/llm-providers.d.ts +3 -2
  44. package/dist/llm-providers.js +1 -1
  45. package/dist/llm-providers.js.map +1 -1
  46. package/dist/loop-api.cjs +88 -89
  47. package/dist/loop-api.cjs.map +1 -1
  48. package/dist/loop-api.d.cts +8 -7
  49. package/dist/loop-api.d.ts +8 -7
  50. package/dist/loop-api.js +5 -5
  51. package/dist/mobile.cjs +10 -5
  52. package/dist/mobile.cjs.map +1 -1
  53. package/dist/mobile.d.cts +6 -5
  54. package/dist/mobile.d.ts +6 -5
  55. package/dist/mobile.js +3 -3
  56. package/dist/{orchestration-portable-B4udCSVd.d.ts → orchestration-portable-CQRrnoEw.d.ts} +15 -5
  57. package/dist/{orchestration-portable-BWaCsCGK.d.cts → orchestration-portable-D4KBEYQb.d.cts} +15 -5
  58. package/dist/orchestration-portable.cjs +201 -343
  59. package/dist/orchestration-portable.cjs.map +1 -1
  60. package/dist/orchestration-portable.d.cts +6 -5
  61. package/dist/orchestration-portable.d.ts +6 -5
  62. package/dist/orchestration-portable.js +1 -1
  63. package/dist/{pairingInvite-C12n-7Ak.d.cts → pairingInvite-BmCQ-bHt.d.cts} +3 -3
  64. package/dist/{pairingInvite-CPQkuhLQ.d.ts → pairingInvite-CsfsexXC.d.ts} +3 -3
  65. package/dist/{promptConcat-VLe5SEN4.d.cts → promptConcat-BqImJtVh.d.cts} +7 -4
  66. package/dist/{promptConcat-CUEIA_3T.d.ts → promptConcat-C5SEgESi.d.ts} +7 -4
  67. package/dist/{providerRegistry-CaFK_aUd.d.ts → providerRegistry-BGrwd7Zl.d.cts} +2 -2
  68. package/dist/{providerRegistry-BDGGs5gz.d.cts → providerRegistry-Bs2lJpj9.d.ts} +2 -2
  69. package/dist/{registry-DNSEVYug.d.cts → registry-CelnriUR.d.cts} +3 -3
  70. package/dist/{registry-yGnYHWhq.d.ts → registry-DVv_RVPZ.d.ts} +3 -3
  71. package/dist/{remoteClient-DwBCoHpc.d.ts → remoteClient-D1gPizds.d.ts} +1 -1
  72. package/dist/{remoteClient-DFIyCZEv.d.cts → remoteClient-DxCHC4_Z.d.cts} +1 -1
  73. package/dist/{runtime-6EELHWVB.js → runtime-SASMRN4I.js} +3 -3
  74. package/dist/{scriptDeploymentPipeline-B1q-UhrO.d.ts → scriptDeploymentPipeline-CdDLEDMS.d.cts} +10 -1
  75. package/dist/{scriptDeploymentPipeline-XJzQyYys.d.cts → scriptDeploymentPipeline-DU6sor6Y.d.ts} +10 -1
  76. package/dist/{syncCloudDevices-C8fCUhnX.d.ts → syncCloudDevices-3RmB41sA.d.cts} +6 -2
  77. package/dist/{syncCloudDevices-BFw_c1g5.d.cts → syncCloudDevices-CSLbMESm.d.ts} +6 -2
  78. package/dist/tools.cjs +63 -0
  79. package/dist/tools.cjs.map +1 -0
  80. package/dist/tools.d.cts +12 -0
  81. package/dist/tools.d.ts +12 -0
  82. package/dist/tools.js +7 -0
  83. package/dist/tools.js.map +1 -0
  84. package/dist/{types-CcFFIk8W.d.ts → types-C29NBZ2w.d.ts} +1 -1
  85. package/dist/types-CcoJ_fdH.d.cts +110 -0
  86. package/dist/types-CcoJ_fdH.d.ts +110 -0
  87. package/dist/{types-C8gnhG9M.d.cts → types-D1rAJy9l.d.cts} +1 -1
  88. package/package.json +6 -1
  89. package/dist/chunk-5VYZV33O.js.map +0 -1
  90. package/dist/chunk-EPHRIRAL.js.map +0 -1
  91. package/dist/chunk-GYIOMQMY.js.map +0 -1
  92. package/dist/chunk-HY3U3GLE.js.map +0 -1
  93. package/dist/chunk-KXVZQLJL.js.map +0 -1
  94. /package/dist/{chunk-K5KZJNDP.js.map → chunk-ROPAEJIM.js.map} +0 -0
  95. /package/dist/{chunk-KV6TC5UJ.js.map → chunk-XIEXGFPY.js.map} +0 -0
  96. /package/dist/{runtime-6EELHWVB.js.map → runtime-SASMRN4I.js.map} +0 -0
@@ -1222,6 +1222,74 @@ function createArtifactManagementConformanceSuite(options) {
1222
1222
  };
1223
1223
  }
1224
1224
 
1225
+ // src/orchestration/drivers/driverState.ts
1226
+ function assertFencedDriverRequestEnvelope(request, options) {
1227
+ assertDriverRequestEnvelope(request, {
1228
+ now: options.now,
1229
+ requireRun: options.requireRun,
1230
+ requireFencing: true,
1231
+ requireCapability: true,
1232
+ expectedMethod: options.expectedMethod
1233
+ });
1234
+ if (options.actorKinds && !options.actorKinds.includes(request.actor.kind)) {
1235
+ throw new OrchestrationError({
1236
+ code: "FORBIDDEN",
1237
+ message: options.forbiddenMessage?.(request.actor.kind) ?? `actor kind '${request.actor.kind}' cannot call ${options.expectedMethod}`,
1238
+ retryable: false
1239
+ });
1240
+ }
1241
+ const epoch = request.fencingEpoch;
1242
+ const current = options.fences.get(request.resource.uid) ?? 0;
1243
+ if (epoch < current) {
1244
+ throw new OrchestrationError({
1245
+ code: "STALE_EPOCH",
1246
+ message: `stale ${options.fenceName} fencing epoch ${epoch}; current epoch is ${current}`,
1247
+ retryable: false
1248
+ });
1249
+ }
1250
+ options.fences.set(request.resource.uid, epoch);
1251
+ return epoch;
1252
+ }
1253
+ function driverOperationKey(request, operation) {
1254
+ return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
1255
+ }
1256
+ function findIdempotentDriverHandle(state, request, operation, driverName) {
1257
+ const key = driverOperationKey(request, operation);
1258
+ const handle = state.idempotency.get(key);
1259
+ if (handle === void 0) return void 0;
1260
+ if (state.idempotencyFingerprints.get(key) !== canonicalDriverValue(request.payload)) {
1261
+ throw new OrchestrationError({
1262
+ code: "CONFLICT",
1263
+ message: `${driverName} ${operation} idempotency key was reused with different input`,
1264
+ retryable: false
1265
+ });
1266
+ }
1267
+ return handle;
1268
+ }
1269
+ function rememberIdempotentDriverHandle(state, request, operation, handle) {
1270
+ const key = driverOperationKey(request, operation);
1271
+ state.idempotency.set(key, handle);
1272
+ state.idempotencyFingerprints.set(key, canonicalDriverValue(request.payload));
1273
+ }
1274
+ function getOwnedDriverValue(collection, handle, resourceUid, kind) {
1275
+ const value = collection.get(handle);
1276
+ if (!value) {
1277
+ throw new OrchestrationError({
1278
+ code: "NOT_FOUND",
1279
+ message: `${kind} handle '${handle}' was not found`,
1280
+ retryable: false
1281
+ });
1282
+ }
1283
+ if (value.resourceUid !== resourceUid) {
1284
+ throw new OrchestrationError({
1285
+ code: "FORBIDDEN",
1286
+ message: `${kind} handle '${handle}' belongs to another resource`,
1287
+ retryable: false
1288
+ });
1289
+ }
1290
+ return value;
1291
+ }
1292
+
1225
1293
  // src/orchestration/drivers/auditTelemetryManagement.ts
1226
1294
  function createFakeAuditTelemetryState() {
1227
1295
  return {
@@ -1237,16 +1305,8 @@ var FORBIDDEN_ATTRIBUTE = /(?:secret|token|password|credential|authorization|coo
1237
1305
  function invalid3(message) {
1238
1306
  throw new OrchestrationError({ code: "INVALID", message, retryable: false });
1239
1307
  }
1240
- function stable(value) {
1241
- if (value === void 0) return "undefined";
1242
- if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
1243
- if (value !== null && typeof value === "object") {
1244
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable(item)}`).join(",")}}`;
1245
- }
1246
- return JSON.stringify(value) ?? typeof value;
1247
- }
1248
1308
  async function digest(value) {
1249
- const bytes = new TextEncoder().encode(stable(value));
1309
+ const bytes = new TextEncoder().encode(canonicalDriverValue(value));
1250
1310
  const result = await globalThis.crypto.subtle.digest("SHA-256", bytes);
1251
1311
  return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
1252
1312
  }
@@ -1264,29 +1324,13 @@ function createFakeAuditTelemetryManagementDriver(options = {}) {
1264
1324
  const maxRecordsPerResource = options.maxRecordsPerResource ?? 1e4;
1265
1325
  const maxAttributes = options.maxAttributes ?? 16;
1266
1326
  function validate(request, expectedMethod, actorKinds) {
1267
- assertDriverRequestEnvelope(request, {
1327
+ assertFencedDriverRequestEnvelope(request, {
1268
1328
  now,
1269
- requireFencing: true,
1270
- requireCapability: true,
1271
- expectedMethod
1329
+ fences: state.fences,
1330
+ expectedMethod,
1331
+ fenceName: "audit",
1332
+ actorKinds
1272
1333
  });
1273
- if (!actorKinds.includes(request.actor.kind)) {
1274
- throw new OrchestrationError({
1275
- code: "FORBIDDEN",
1276
- message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
1277
- retryable: false
1278
- });
1279
- }
1280
- const epoch = request.fencingEpoch;
1281
- const current = state.fences.get(request.resource.uid) ?? 0;
1282
- if (epoch < current) {
1283
- throw new OrchestrationError({
1284
- code: "STALE_EPOCH",
1285
- message: `stale audit fencing epoch ${epoch}; current epoch is ${current}`,
1286
- retryable: false
1287
- });
1288
- }
1289
- state.fences.set(request.resource.uid, epoch);
1290
1334
  }
1291
1335
  function common(request) {
1292
1336
  const policyDigest = requiredString2(request.payload, "policyDigest", 80);
@@ -1316,7 +1360,7 @@ function createFakeAuditTelemetryManagementDriver(options = {}) {
1316
1360
  }
1317
1361
  async function append(request, kind, data) {
1318
1362
  const idempotencyKey = `${request.resource.uid}:${request.method}:${request.idempotencyKey}`;
1319
- const fingerprint = stable(request.payload);
1363
+ const fingerprint = canonicalDriverValue(request.payload);
1320
1364
  let release;
1321
1365
  const previousAppend = state.appendTail;
1322
1366
  state.appendTail = new Promise((resolve) => {
@@ -2437,24 +2481,6 @@ function requiredString4(payload, field) {
2437
2481
  if (payload === null || typeof payload !== "object" || typeof payload[field] !== "string" || !payload[field]) invalid5(`identity payload '${field}' is required`);
2438
2482
  return payload[field];
2439
2483
  }
2440
- function owned(collection, handle, resourceUid, kind) {
2441
- const value = collection.get(handle);
2442
- if (!value) {
2443
- throw new OrchestrationError({
2444
- code: "NOT_FOUND",
2445
- message: `${kind} handle '${handle}' was not found`,
2446
- retryable: false
2447
- });
2448
- }
2449
- if (value.resourceUid !== resourceUid) {
2450
- throw new OrchestrationError({
2451
- code: "FORBIDDEN",
2452
- message: `${kind} handle '${handle}' belongs to another resource`,
2453
- retryable: false
2454
- });
2455
- }
2456
- return value;
2457
- }
2458
2484
  function createFakeIdentityAttestationManagementDriver(options = {}) {
2459
2485
  const state = options.state ?? createFakeIdentityAttestationState();
2460
2486
  const now = options.now ?? (() => /* @__PURE__ */ new Date());
@@ -2471,29 +2497,13 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2471
2497
  `sha256:${"a".repeat(64)}`
2472
2498
  ];
2473
2499
  function validate(request, expectedMethod, actorKinds) {
2474
- assertDriverRequestEnvelope(request, {
2500
+ assertFencedDriverRequestEnvelope(request, {
2475
2501
  now,
2476
- requireFencing: true,
2477
- requireCapability: true,
2478
- expectedMethod
2502
+ fences: state.fences,
2503
+ expectedMethod,
2504
+ fenceName: "identity",
2505
+ actorKinds
2479
2506
  });
2480
- if (!actorKinds.includes(request.actor.kind)) {
2481
- throw new OrchestrationError({
2482
- code: "FORBIDDEN",
2483
- message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
2484
- retryable: false
2485
- });
2486
- }
2487
- const fence = request.fencingEpoch;
2488
- const current = state.fences.get(request.resource.uid) ?? 0;
2489
- if (fence < current) {
2490
- throw new OrchestrationError({
2491
- code: "STALE_EPOCH",
2492
- message: `stale identity fencing epoch ${fence}; current epoch is ${current}`,
2493
- retryable: false
2494
- });
2495
- }
2496
- state.fences.set(request.resource.uid, fence);
2497
2507
  }
2498
2508
  function ttl(payload, field, maximum) {
2499
2509
  if (payload === null || typeof payload !== "object") {
@@ -2508,34 +2518,11 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2508
2518
  state.nextHandle += 1;
2509
2519
  return handle;
2510
2520
  }
2511
- function key(request, operation) {
2512
- return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
2513
- }
2514
- function stable6(value) {
2515
- if (value === void 0) return "undefined";
2516
- if (Array.isArray(value)) return `[${value.map(stable6).join(",")}]`;
2517
- if (value !== null && typeof value === "object") {
2518
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([name, item]) => `${JSON.stringify(name)}:${stable6(item)}`).join(",")}}`;
2519
- }
2520
- return JSON.stringify(value) ?? typeof value;
2521
- }
2522
2521
  function previous(request, operation) {
2523
- const idempotency = key(request, operation);
2524
- const handle = state.idempotency.get(idempotency);
2525
- if (!handle) return void 0;
2526
- if (state.idempotencyFingerprints.get(idempotency) !== stable6(request.payload)) {
2527
- throw new OrchestrationError({
2528
- code: "CONFLICT",
2529
- message: `identity ${operation} idempotency key was reused with different input`,
2530
- retryable: false
2531
- });
2532
- }
2533
- return handle;
2522
+ return findIdempotentDriverHandle(state, request, operation, "identity");
2534
2523
  }
2535
2524
  function remember(request, operation, handle) {
2536
- const idempotency = key(request, operation);
2537
- state.idempotency.set(idempotency, handle);
2538
- state.idempotencyFingerprints.set(idempotency, stable6(request.payload));
2525
+ rememberIdempotentDriverHandle(state, request, operation, handle);
2539
2526
  }
2540
2527
  function assertActiveIdentity(identity) {
2541
2528
  if (identity.revoked) {
@@ -2579,7 +2566,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2579
2566
  const ttlMs = ttl(request.payload, "ttlMs", maxSessionTtlMs);
2580
2567
  const existing = previous(request, "enroll");
2581
2568
  if (existing) {
2582
- return structuredClone(owned(
2569
+ return structuredClone(getOwnedDriverValue(
2583
2570
  state.enrollments,
2584
2571
  existing,
2585
2572
  request.resource.uid,
@@ -2603,7 +2590,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2603
2590
  },
2604
2591
  async challenge(request) {
2605
2592
  validate(request, "identity.challenge", ["controller", "admin"]);
2606
- const enrollment = owned(
2593
+ const enrollment = getOwnedDriverValue(
2607
2594
  state.enrollments,
2608
2595
  requiredString4(request.payload, "enrollmentHandle"),
2609
2596
  request.resource.uid,
@@ -2616,7 +2603,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2616
2603
  const ttlMs = ttl(request.payload, "ttlMs", maxChallengeTtlMs);
2617
2604
  const existing = previous(request, "challenge");
2618
2605
  if (existing) {
2619
- return structuredClone(owned(
2606
+ return structuredClone(getOwnedDriverValue(
2620
2607
  state.challenges,
2621
2608
  existing,
2622
2609
  request.resource.uid,
@@ -2646,13 +2633,13 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2646
2633
  },
2647
2634
  async attest(request) {
2648
2635
  validate(request, "identity.attest", ["controller", "verifier"]);
2649
- const challenge = owned(
2636
+ const challenge = getOwnedDriverValue(
2650
2637
  state.challenges,
2651
2638
  requiredString4(request.payload, "challengeHandle"),
2652
2639
  request.resource.uid,
2653
2640
  "challenge"
2654
2641
  );
2655
- const enrollment = owned(
2642
+ const enrollment = getOwnedDriverValue(
2656
2643
  state.enrollments,
2657
2644
  challenge.enrollmentHandle,
2658
2645
  request.resource.uid,
@@ -2688,7 +2675,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2688
2675
  }
2689
2676
  const existing = previous(request, "attest");
2690
2677
  if (existing) {
2691
- return structuredClone(owned(
2678
+ return structuredClone(getOwnedDriverValue(
2692
2679
  state.identities,
2693
2680
  existing,
2694
2681
  request.resource.uid,
@@ -2723,7 +2710,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2723
2710
  },
2724
2711
  async issueSession(request) {
2725
2712
  validate(request, "identity.issue-session", ["controller", "admin"]);
2726
- const identity = owned(
2713
+ const identity = getOwnedDriverValue(
2727
2714
  state.identities,
2728
2715
  requiredString4(request.payload, "identityHandle"),
2729
2716
  request.resource.uid,
@@ -2752,7 +2739,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2752
2739
  const ttlMs = ttl(request.payload, "ttlMs", maxSessionTtlMs);
2753
2740
  const existing = previous(request, "issue-session");
2754
2741
  if (existing) {
2755
- return structuredClone(owned(
2742
+ return structuredClone(getOwnedDriverValue(
2756
2743
  state.sessions,
2757
2744
  existing,
2758
2745
  request.resource.uid,
@@ -2776,7 +2763,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2776
2763
  },
2777
2764
  async rotate(request) {
2778
2765
  validate(request, "identity.rotate", ["controller", "admin"]);
2779
- const identity = owned(
2766
+ const identity = getOwnedDriverValue(
2780
2767
  state.identities,
2781
2768
  requiredString4(request.payload, "identityHandle"),
2782
2769
  request.resource.uid,
@@ -2793,7 +2780,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2793
2780
  );
2794
2781
  const existing = previous(request, "rotate");
2795
2782
  if (existing) {
2796
- return structuredClone(owned(
2783
+ return structuredClone(getOwnedDriverValue(
2797
2784
  state.identities,
2798
2785
  existing,
2799
2786
  request.resource.uid,
@@ -2821,7 +2808,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
2821
2808
  },
2822
2809
  async revoke(request) {
2823
2810
  validate(request, "identity.revoke", ["controller", "admin"]);
2824
- const identity = owned(
2811
+ const identity = getOwnedDriverValue(
2825
2812
  state.identities,
2826
2813
  requiredString4(request.payload, "identityHandle"),
2827
2814
  request.resource.uid,
@@ -3174,6 +3161,105 @@ function createIdentityAttestationConformanceSuite(options) {
3174
3161
  };
3175
3162
  }
3176
3163
 
3164
+ // src/orchestration/drivers/modelProviderDriver.ts
3165
+ var CLASSIFICATION_ORDER = {
3166
+ public: 0,
3167
+ internal: 1,
3168
+ confidential: 2,
3169
+ restricted: 3
3170
+ };
3171
+ function classificationRank(value) {
3172
+ return CLASSIFICATION_ORDER[value];
3173
+ }
3174
+ function assertClassificationAllowed(policy, classification) {
3175
+ if (!policy?.maxInputClassification || !classification) return;
3176
+ if (classificationRank(classification) > classificationRank(policy.maxInputClassification)) {
3177
+ throw new OrchestrationError({
3178
+ code: "FORBIDDEN",
3179
+ message: `input classification '${classification}' exceeds endpoint limit '${policy.maxInputClassification}'`,
3180
+ retryable: false,
3181
+ details: { classification, maxInputClassification: policy.maxInputClassification }
3182
+ });
3183
+ }
3184
+ }
3185
+ function modelClassNameForSpec(model) {
3186
+ return `${model.provider}-${model.model}`.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^-+|-+$/g, "") || "model";
3187
+ }
3188
+ function createModelProviderDriverFromLLMProvider(provider, options) {
3189
+ const inFlight = /* @__PURE__ */ new Map();
3190
+ const toLegacyRequest = options.toLegacyRequest ?? ((request) => {
3191
+ const candidates = options.models.filter(
3192
+ (model) => modelClassNameForSpec(model) === request.modelClassRef.name || model.model === request.modelClassRef.name
3193
+ );
3194
+ if (candidates.length !== 1) {
3195
+ throw new OrchestrationError({
3196
+ code: "INVALID",
3197
+ message: candidates.length === 0 ? `model class '${request.modelClassRef.name}' is not served by provider '${provider.name}'` : `model class '${request.modelClassRef.name}' is ambiguous for provider '${provider.name}'`,
3198
+ retryable: false
3199
+ });
3200
+ }
3201
+ return {
3202
+ model: candidates[0].model,
3203
+ messages: request.messages,
3204
+ max_tokens: request.maxOutputTokens,
3205
+ temperature: request.temperature,
3206
+ topP: request.topP,
3207
+ providerOptions: request.providerOptions,
3208
+ abortSignal: request.signal
3209
+ };
3210
+ });
3211
+ const toDelta = options.toDelta ?? ((chunk) => typeof chunk === "string" ? chunk : void 0);
3212
+ return {
3213
+ async listModels() {
3214
+ return options.models;
3215
+ },
3216
+ async getHealth() {
3217
+ return {
3218
+ healthy: true,
3219
+ detail: `legacy provider ${provider.name}`,
3220
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
3221
+ };
3222
+ },
3223
+ async *generate(request) {
3224
+ assertClassificationAllowed(options.dataPolicy, request.inputClassification);
3225
+ const controller = new AbortController();
3226
+ inFlight.set(request.callId, controller);
3227
+ const onExternalAbort = () => {
3228
+ controller.abort();
3229
+ };
3230
+ request.signal?.addEventListener("abort", onExternalAbort);
3231
+ try {
3232
+ const legacy = toLegacyRequest({ ...request, signal: controller.signal });
3233
+ const output = await provider.chat(legacy);
3234
+ if (output != null && typeof output === "object" && Symbol.asyncIterator in output) {
3235
+ for await (const chunk of output) {
3236
+ if (controller.signal.aborted) {
3237
+ yield {
3238
+ type: "error",
3239
+ error: { code: "CANCELLED", message: "generate cancelled", retryable: false }
3240
+ };
3241
+ return;
3242
+ }
3243
+ const delta = toDelta(chunk);
3244
+ if (delta !== void 0) {
3245
+ yield { type: "delta", delta };
3246
+ }
3247
+ }
3248
+ } else if (typeof output === "string") {
3249
+ yield { type: "delta", delta: output };
3250
+ }
3251
+ yield { type: "done" };
3252
+ } finally {
3253
+ request.signal?.removeEventListener("abort", onExternalAbort);
3254
+ inFlight.delete(request.callId);
3255
+ }
3256
+ },
3257
+ async cancel(callId) {
3258
+ inFlight.get(callId)?.abort();
3259
+ }
3260
+ };
3261
+ }
3262
+
3177
3263
  // src/orchestration/drivers/loopRuntimeManagement.ts
3178
3264
  function createFakeLoopRuntimeState() {
3179
3265
  return {
@@ -4001,12 +4087,12 @@ function createManagedCredentialBrokerAdapter(broker, options) {
4001
4087
  retryable: false
4002
4088
  });
4003
4089
  }
4004
- const stable6 = options.stableHandleFor?.(request) ?? stableHandle();
4005
- if (!stable6 || stable6.length > 2048) {
4090
+ const stable = options.stableHandleFor?.(request) ?? stableHandle();
4091
+ if (!stable || stable.length > 2048) {
4006
4092
  invalid6("credential stable handle is empty or too long");
4007
4093
  }
4008
4094
  if (options.handleStore) {
4009
- const adopted = await options.handleStore.get(stable6);
4095
+ const adopted = await options.handleStore.get(stable);
4010
4096
  if (adopted) {
4011
4097
  const inspection = await broker.inspect(adopted.token);
4012
4098
  const exact = inspection.grantId === request.resource.uid && canonicalDriverValue(inspection.scope) === canonicalDriverValue({
@@ -4026,13 +4112,13 @@ function createManagedCredentialBrokerAdapter(broker, options) {
4026
4112
  });
4027
4113
  }
4028
4114
  const adoptedRecord = {
4029
- stableHandle: stable6,
4115
+ stableHandle: stable,
4030
4116
  token: adopted.token,
4031
4117
  resourceUid: request.resource.uid,
4032
4118
  targetDriver: request.payload.targetDriver
4033
4119
  };
4034
- records.set(stable6, adoptedRecord);
4035
- await rememberIdempotency(key, request, stable6);
4120
+ records.set(stable, adoptedRecord);
4121
+ await rememberIdempotency(key, request, stable);
4036
4122
  return managed(adoptedRecord, inspection);
4037
4123
  }
4038
4124
  }
@@ -4048,7 +4134,7 @@ function createManagedCredentialBrokerAdapter(broker, options) {
4048
4134
  grantId: request.resource.uid
4049
4135
  });
4050
4136
  const record2 = {
4051
- stableHandle: stable6,
4137
+ stableHandle: stable,
4052
4138
  token: issued.token,
4053
4139
  resourceUid: request.resource.uid,
4054
4140
  targetDriver: request.payload.targetDriver
@@ -4700,88 +4786,6 @@ function createManagedLoopRuntimeExecutionRoute(executionDriver, options) {
4700
4786
  };
4701
4787
  }
4702
4788
 
4703
- // src/orchestration/drivers/modelProviderDriver.ts
4704
- var CLASSIFICATION_ORDER = {
4705
- public: 0,
4706
- internal: 1,
4707
- confidential: 2,
4708
- restricted: 3
4709
- };
4710
- function classificationRank(value) {
4711
- return CLASSIFICATION_ORDER[value];
4712
- }
4713
- function assertClassificationAllowed(policy, classification) {
4714
- if (!policy?.maxInputClassification || !classification) return;
4715
- if (classificationRank(classification) > classificationRank(policy.maxInputClassification)) {
4716
- throw new OrchestrationError({
4717
- code: "FORBIDDEN",
4718
- message: `input classification '${classification}' exceeds endpoint limit '${policy.maxInputClassification}'`,
4719
- retryable: false,
4720
- details: { classification, maxInputClassification: policy.maxInputClassification }
4721
- });
4722
- }
4723
- }
4724
- function createModelProviderDriverFromLLMProvider(provider, options) {
4725
- const inFlight = /* @__PURE__ */ new Map();
4726
- const toLegacyRequest = options.toLegacyRequest ?? ((request) => ({
4727
- ...provider.modelId !== void 0 ? { model: provider.modelId } : {},
4728
- messages: request.messages,
4729
- max_tokens: request.maxOutputTokens,
4730
- temperature: request.temperature,
4731
- abortSignal: request.signal
4732
- }));
4733
- const toDelta = options.toDelta ?? ((chunk) => typeof chunk === "string" ? chunk : void 0);
4734
- return {
4735
- async listModels() {
4736
- return options.models;
4737
- },
4738
- async getHealth() {
4739
- return {
4740
- healthy: true,
4741
- detail: `legacy provider ${provider.name}`,
4742
- checkedAt: (/* @__PURE__ */ new Date()).toISOString()
4743
- };
4744
- },
4745
- async *generate(request) {
4746
- assertClassificationAllowed(options.dataPolicy, request.inputClassification);
4747
- const controller = new AbortController();
4748
- inFlight.set(request.callId, controller);
4749
- const onExternalAbort = () => {
4750
- controller.abort();
4751
- };
4752
- request.signal?.addEventListener("abort", onExternalAbort);
4753
- try {
4754
- const legacy = toLegacyRequest({ ...request, signal: controller.signal });
4755
- const output = await provider.chat(legacy);
4756
- if (output != null && typeof output === "object" && Symbol.asyncIterator in output) {
4757
- for await (const chunk of output) {
4758
- if (controller.signal.aborted) {
4759
- yield {
4760
- type: "error",
4761
- error: { code: "CANCELLED", message: "generate cancelled", retryable: false }
4762
- };
4763
- return;
4764
- }
4765
- const delta = toDelta(chunk);
4766
- if (delta !== void 0) {
4767
- yield { type: "delta", delta };
4768
- }
4769
- }
4770
- } else if (typeof output === "string") {
4771
- yield { type: "delta", delta: output };
4772
- }
4773
- yield { type: "done" };
4774
- } finally {
4775
- request.signal?.removeEventListener("abort", onExternalAbort);
4776
- inFlight.delete(request.callId);
4777
- }
4778
- },
4779
- async cancel(callId) {
4780
- inFlight.get(callId)?.abort();
4781
- }
4782
- };
4783
- }
4784
-
4785
4789
  // src/orchestration/drivers/managedModelGatewayAdapter.ts
4786
4790
  var SHA2562 = /^sha256:[a-f0-9]{64}$/;
4787
4791
  var CLASSIFICATIONS = ["public", "internal", "confidential", "restricted"];
@@ -5269,13 +5273,6 @@ function createFakeNetworkManagementState() {
5269
5273
  nextHandle: 1
5270
5274
  };
5271
5275
  }
5272
- function stable2(value) {
5273
- if (Array.isArray(value)) return `[${value.map(stable2).join(",")}]`;
5274
- if (value !== null && typeof value === "object") {
5275
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable2(item)}`).join(",")}}`;
5276
- }
5277
- return JSON.stringify(value) ?? typeof value;
5278
- }
5279
5276
  function invalid7(message) {
5280
5277
  throw new OrchestrationError({ code: "INVALID", message, retryable: false });
5281
5278
  }
@@ -5476,31 +5473,15 @@ function createFakeNetworkManagementDriver(options = {}) {
5476
5473
  ...options.capabilities
5477
5474
  };
5478
5475
  function validate(request, method) {
5479
- assertDriverRequestEnvelope(request, {
5476
+ return assertFencedDriverRequestEnvelope(request, {
5480
5477
  now,
5478
+ fences: state.fences,
5481
5479
  requireRun: true,
5482
- requireFencing: true,
5483
- requireCapability: true,
5484
- expectedMethod: method
5480
+ expectedMethod: method,
5481
+ fenceName: "network",
5482
+ actorKinds: ["controller", "admin"],
5483
+ forbiddenMessage: () => "network lifecycle requires a controller or admin actor"
5485
5484
  });
5486
- if (request.actor.kind !== "controller" && request.actor.kind !== "admin") {
5487
- throw new OrchestrationError({
5488
- code: "FORBIDDEN",
5489
- message: "network lifecycle requires a controller or admin actor",
5490
- retryable: false
5491
- });
5492
- }
5493
- const fence = request.fencingEpoch;
5494
- const current = state.fences.get(request.resource.uid) ?? 0;
5495
- if (fence < current) {
5496
- throw new OrchestrationError({
5497
- code: "STALE_EPOCH",
5498
- message: `stale network fencing epoch ${fence}; current epoch is ${current}`,
5499
- retryable: false
5500
- });
5501
- }
5502
- state.fences.set(request.resource.uid, fence);
5503
- return fence;
5504
5485
  }
5505
5486
  function nextHandle(prefix) {
5506
5487
  const handle = `${prefix}:${state.nextHandle}`;
@@ -5564,7 +5545,7 @@ function createFakeNetworkManagementDriver(options = {}) {
5564
5545
  }
5565
5546
  function idempotent(request, operation) {
5566
5547
  const key = `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
5567
- const fingerprint = stable2(request.payload);
5548
+ const fingerprint = canonicalDriverValue(request.payload);
5568
5549
  const existing = state.idempotency.get(key);
5569
5550
  if (existing) {
5570
5551
  if (existing.fingerprint !== fingerprint) {
@@ -5581,7 +5562,7 @@ function createFakeNetworkManagementDriver(options = {}) {
5581
5562
  function remember(request, operation, resultHandle) {
5582
5563
  state.idempotency.set(
5583
5564
  `${request.resource.uid}:${operation}:${request.idempotencyKey}`,
5584
- { fingerprint: stable2(request.payload), resultHandle }
5565
+ { fingerprint: canonicalDriverValue(request.payload), resultHandle }
5585
5566
  );
5586
5567
  }
5587
5568
  return {
@@ -6146,18 +6127,10 @@ function requiredString6(value, field, maximum = 256) {
6146
6127
  if (!result || result.length > maximum) invalid8(`tool payload '${field}' is invalid`);
6147
6128
  return result;
6148
6129
  }
6149
- function stable3(value) {
6150
- if (value === void 0) return "undefined";
6151
- if (Array.isArray(value)) return `[${value.map(stable3).join(",")}]`;
6152
- if (value !== null && typeof value === "object") {
6153
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable3(item)}`).join(",")}}`;
6154
- }
6155
- return JSON.stringify(value) ?? typeof value;
6156
- }
6157
6130
  async function digest2(value) {
6158
6131
  const result = await globalThis.crypto.subtle.digest(
6159
6132
  "SHA-256",
6160
- new TextEncoder().encode(stable3(value))
6133
+ new TextEncoder().encode(canonicalDriverValue(value))
6161
6134
  );
6162
6135
  return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
6163
6136
  }
@@ -6240,37 +6213,21 @@ function createFakeToolManagementDriver(options = {}) {
6240
6213
  if (!SHA2565.test(descriptor.schemaDigest) || descriptor.schemaDigest !== actualSchemaDigest || !descriptor.name || !descriptor.version || !descriptor.targets.length) invalid8(`tool catalog descriptor '${descriptor.name}' is invalid`);
6241
6214
  }
6242
6215
  return digest2(
6243
- tools.map(descriptorInput).sort((left, right) => stable3(left).localeCompare(stable3(right)))
6216
+ tools.map(descriptorInput).sort((left, right) => canonicalDriverValue(left).localeCompare(canonicalDriverValue(right)))
6244
6217
  );
6245
6218
  })();
6246
6219
  return catalogDigestPromise;
6247
6220
  }
6248
6221
  function validate(request, expectedMethod, actorKinds = ["controller"]) {
6249
- assertDriverRequestEnvelope(request, {
6222
+ assertFencedDriverRequestEnvelope(request, {
6250
6223
  now,
6251
- requireFencing: true,
6252
- requireCapability: true,
6253
- expectedMethod
6224
+ fences: state.fences,
6225
+ expectedMethod,
6226
+ fenceName: "tool",
6227
+ actorKinds
6254
6228
  });
6255
- if (!actorKinds.includes(request.actor.kind)) {
6256
- throw new OrchestrationError({
6257
- code: "FORBIDDEN",
6258
- message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
6259
- retryable: false
6260
- });
6261
- }
6262
- const epoch = request.fencingEpoch;
6263
- const current = state.fences.get(request.resource.uid) ?? 0;
6264
- if (epoch < current) {
6265
- throw new OrchestrationError({
6266
- code: "STALE_EPOCH",
6267
- message: `stale tool fencing epoch ${epoch}; current epoch is ${current}`,
6268
- retryable: false
6269
- });
6270
- }
6271
- state.fences.set(request.resource.uid, epoch);
6272
6229
  }
6273
- function owned2(collection, handle, resourceUid, kind) {
6230
+ function owned(collection, handle, resourceUid, kind) {
6274
6231
  const value = collection.get(handle);
6275
6232
  if (!value) {
6276
6233
  throw new OrchestrationError({
@@ -6295,21 +6252,10 @@ function createFakeToolManagementDriver(options = {}) {
6295
6252
  return `${prefix}:${state.nextHandle++}`;
6296
6253
  }
6297
6254
  function idempotency(request, operation) {
6298
- const key = `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
6299
- const previous = state.idempotency.get(key);
6300
- if (previous && state.idempotencyFingerprints.get(key) !== stable3(request.payload)) {
6301
- throw new OrchestrationError({
6302
- code: "CONFLICT",
6303
- message: `tool ${operation} idempotency key was reused with different input`,
6304
- retryable: false
6305
- });
6306
- }
6307
- return previous;
6255
+ return findIdempotentDriverHandle(state, request, operation, "tool");
6308
6256
  }
6309
6257
  function remember(request, operation, handle) {
6310
- const key = `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
6311
- state.idempotency.set(key, handle);
6312
- state.idempotencyFingerprints.set(key, stable3(request.payload));
6258
+ rememberIdempotentDriverHandle(state, request, operation, handle);
6313
6259
  }
6314
6260
  async function* defaultExecutor(descriptor, target, arguments_) {
6315
6261
  yield JSON.stringify({ tool: descriptor.name, target, arguments: arguments_ });
@@ -6392,7 +6338,7 @@ function createFakeToolManagementDriver(options = {}) {
6392
6338
  if (request.payload.operationIdempotencyKey && !descriptor.supportsIdempotency) invalid8("tool does not support operation idempotency");
6393
6339
  const previous = idempotency(request, "prepare");
6394
6340
  if (previous) {
6395
- return structuredClone(owned2(
6341
+ return structuredClone(owned(
6396
6342
  state.preparations,
6397
6343
  previous,
6398
6344
  request.resource.uid,
@@ -6417,7 +6363,7 @@ function createFakeToolManagementDriver(options = {}) {
6417
6363
  },
6418
6364
  async authorize(request) {
6419
6365
  validate(request, "tool.authorize", ["controller", "admin"]);
6420
- const preparation = owned2(
6366
+ const preparation = owned(
6421
6367
  state.preparations,
6422
6368
  requiredString6(request.payload, "preparationHandle"),
6423
6369
  request.resource.uid,
@@ -6448,7 +6394,7 @@ function createFakeToolManagementDriver(options = {}) {
6448
6394
  }
6449
6395
  const previous = idempotency(request, "authorize");
6450
6396
  if (previous) {
6451
- return structuredClone(owned2(
6397
+ return structuredClone(owned(
6452
6398
  state.authorizations,
6453
6399
  previous,
6454
6400
  request.resource.uid,
@@ -6470,13 +6416,13 @@ function createFakeToolManagementDriver(options = {}) {
6470
6416
  },
6471
6417
  async *invoke(request, invokeOptions = {}) {
6472
6418
  validate(request, "tool.invoke");
6473
- const preparation = owned2(
6419
+ const preparation = owned(
6474
6420
  state.preparations,
6475
6421
  requiredString6(request.payload, "preparationHandle"),
6476
6422
  request.resource.uid,
6477
6423
  "tool preparation"
6478
6424
  );
6479
- const authorization = owned2(
6425
+ const authorization = owned(
6480
6426
  state.authorizations,
6481
6427
  requiredString6(request.payload, "authorizationHandle"),
6482
6428
  request.resource.uid,
@@ -6496,7 +6442,7 @@ function createFakeToolManagementDriver(options = {}) {
6496
6442
  }
6497
6443
  const previous = idempotency(request, "invoke");
6498
6444
  if (previous) {
6499
- const execution2 = owned2(
6445
+ const execution2 = owned(
6500
6446
  state.executions,
6501
6447
  previous,
6502
6448
  request.resource.uid,
@@ -6601,14 +6547,14 @@ function createFakeToolManagementDriver(options = {}) {
6601
6547
  },
6602
6548
  async reconcileUnknownEffect(request) {
6603
6549
  validate(request, "tool.reconcile-unknown", ["controller", "verifier", "admin"]);
6604
- const execution = owned2(
6550
+ const execution = owned(
6605
6551
  state.executions,
6606
6552
  requiredString6(request.payload, "executionHandle"),
6607
6553
  request.resource.uid,
6608
6554
  "tool execution"
6609
6555
  );
6610
6556
  if (execution.phase !== "Unknown") return structuredClone(execution);
6611
- const preparation = owned2(
6557
+ const preparation = owned(
6612
6558
  state.preparations,
6613
6559
  execution.preparationHandle,
6614
6560
  request.resource.uid,
@@ -6634,14 +6580,14 @@ function createFakeToolManagementDriver(options = {}) {
6634
6580
  },
6635
6581
  async collectEvidence(request) {
6636
6582
  validate(request, "tool.collect-evidence", ["controller", "verifier", "admin"]);
6637
- const execution = owned2(
6583
+ const execution = owned(
6638
6584
  state.executions,
6639
6585
  requiredString6(request.payload, "executionHandle"),
6640
6586
  request.resource.uid,
6641
6587
  "tool execution"
6642
6588
  );
6643
6589
  const descriptor = tool(
6644
- owned2(
6590
+ owned(
6645
6591
  state.preparations,
6646
6592
  execution.preparationHandle,
6647
6593
  request.resource.uid,
@@ -6651,7 +6597,7 @@ function createFakeToolManagementDriver(options = {}) {
6651
6597
  if (!descriptor?.supportsEvidence) invalid8("tool does not support evidence");
6652
6598
  const previous = idempotency(request, "evidence");
6653
6599
  if (previous) {
6654
- return structuredClone(owned2(
6600
+ return structuredClone(owned(
6655
6601
  state.evidence,
6656
6602
  previous,
6657
6603
  request.resource.uid,
@@ -6672,14 +6618,14 @@ function createFakeToolManagementDriver(options = {}) {
6672
6618
  },
6673
6619
  async cleanup(request) {
6674
6620
  validate(request, "tool.cleanup");
6675
- const preparation = owned2(
6621
+ const preparation = owned(
6676
6622
  state.preparations,
6677
6623
  requiredString6(request.payload, "preparationHandle"),
6678
6624
  request.resource.uid,
6679
6625
  "tool preparation"
6680
6626
  );
6681
6627
  if (request.payload.executionHandle) {
6682
- const execution = owned2(
6628
+ const execution = owned(
6683
6629
  state.executions,
6684
6630
  request.payload.executionHandle,
6685
6631
  request.resource.uid,
@@ -6838,7 +6784,7 @@ function createToolManagementConformanceSuite(options) {
6838
6784
  { executionHandle: first[0].executionHandle },
6839
6785
  "inspect-invoke"
6840
6786
  ));
6841
- if (!first.at(-1)?.final || stable3(first) !== stable3(replay) || execution?.phase !== "Completed") throw new Error("tool streaming or retry did not converge");
6787
+ if (!first.at(-1)?.final || canonicalDriverValue(first) !== canonicalDriverValue(replay) || execution?.phase !== "Completed") throw new Error("tool streaming or retry did not converge");
6842
6788
  }
6843
6789
  },
6844
6790
  {
@@ -7012,14 +6958,6 @@ function createFakeModelManagementState() {
7012
6958
  nextHandle: 1
7013
6959
  };
7014
6960
  }
7015
- function stable4(value) {
7016
- if (value === void 0) return "undefined";
7017
- if (Array.isArray(value)) return `[${value.map(stable4).join(",")}]`;
7018
- if (value !== null && typeof value === "object") {
7019
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable4(item)}`).join(",")}}`;
7020
- }
7021
- return JSON.stringify(value) ?? typeof value;
7022
- }
7023
6961
  function invalid9(message) {
7024
6962
  throw new OrchestrationError({ code: "INVALID", message, retryable: false });
7025
6963
  }
@@ -7078,31 +7016,15 @@ function createFakeModelManagementDriver(options = {}) {
7078
7016
  };
7079
7017
  const active = /* @__PURE__ */ new Map();
7080
7018
  function validate(request, method) {
7081
- assertDriverRequestEnvelope(request, {
7019
+ return assertFencedDriverRequestEnvelope(request, {
7082
7020
  now,
7021
+ fences: state.fences,
7083
7022
  requireRun: true,
7084
- requireFencing: true,
7085
- requireCapability: true,
7086
- expectedMethod: method
7023
+ expectedMethod: method,
7024
+ fenceName: "model",
7025
+ actorKinds: ["controller", "admin"],
7026
+ forbiddenMessage: () => "model provider access requires a controller or admin actor"
7087
7027
  });
7088
- if (request.actor.kind !== "controller" && request.actor.kind !== "admin") {
7089
- throw new OrchestrationError({
7090
- code: "FORBIDDEN",
7091
- message: "model provider access requires a controller or admin actor",
7092
- retryable: false
7093
- });
7094
- }
7095
- const fence = request.fencingEpoch;
7096
- const current = state.fences.get(request.resource.uid) ?? 0;
7097
- if (fence < current) {
7098
- throw new OrchestrationError({
7099
- code: "STALE_EPOCH",
7100
- message: `stale model fencing epoch ${fence}; current epoch is ${current}`,
7101
- retryable: false
7102
- });
7103
- }
7104
- state.fences.set(request.resource.uid, fence);
7105
- return fence;
7106
7028
  }
7107
7029
  function modelFor(payload) {
7108
7030
  assertOnlyFields2(
@@ -7229,7 +7151,7 @@ function createFakeModelManagementDriver(options = {}) {
7229
7151
  const fence = validate(request, "model.generate");
7230
7152
  const model = modelFor(request.payload);
7231
7153
  await authorize(request, model);
7232
- const inputFingerprint = stable4({
7154
+ const inputFingerprint = canonicalDriverValue({
7233
7155
  payload: request.payload,
7234
7156
  run: request.run,
7235
7157
  session: request.session,
@@ -7468,7 +7390,9 @@ function createModelManagementConformanceSuite(options) {
7468
7390
  );
7469
7391
  const first = await collect(driver, request);
7470
7392
  const second = await collect(driver, request);
7471
- if (stable4(first) !== stable4(second)) throw new Error("model generation did not replay");
7393
+ if (canonicalDriverValue(first) !== canonicalDriverValue(second)) {
7394
+ throw new Error("model generation did not replay");
7395
+ }
7472
7396
  if (first.at(-1)?.type !== "done") throw new Error("model stream did not complete");
7473
7397
  let driftRejected = false;
7474
7398
  try {
@@ -7602,16 +7526,8 @@ function requiredString7(value, field) {
7602
7526
  if (value === null || typeof value !== "object" || typeof value[field] !== "string" || !value[field]) invalid10(`policy payload '${field}' is required`);
7603
7527
  return value[field];
7604
7528
  }
7605
- function stable5(value) {
7606
- if (value === void 0) return "undefined";
7607
- if (Array.isArray(value)) return `[${value.map(stable5).join(",")}]`;
7608
- if (value !== null && typeof value === "object") {
7609
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable5(item)}`).join(",")}}`;
7610
- }
7611
- return JSON.stringify(value) ?? typeof value;
7612
- }
7613
7529
  async function digest3(value) {
7614
- const bytes = new TextEncoder().encode(stable5(value));
7530
+ const bytes = new TextEncoder().encode(canonicalDriverValue(value));
7615
7531
  const result = await globalThis.crypto.subtle.digest("SHA-256", bytes);
7616
7532
  return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
7617
7533
  }
@@ -7632,34 +7548,18 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
7632
7548
  ]
7633
7549
  );
7634
7550
  function validate(request, expectedMethod, actorKinds) {
7635
- assertDriverRequestEnvelope(request, {
7551
+ assertFencedDriverRequestEnvelope(request, {
7636
7552
  now,
7637
- requireFencing: true,
7638
- requireCapability: true,
7639
- expectedMethod
7553
+ fences: state.fences,
7554
+ expectedMethod,
7555
+ fenceName: "policy",
7556
+ actorKinds
7640
7557
  });
7641
- if (!actorKinds.includes(request.actor.kind)) {
7642
- throw new OrchestrationError({
7643
- code: "FORBIDDEN",
7644
- message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
7645
- retryable: false
7646
- });
7647
- }
7648
- const epoch = request.fencingEpoch;
7649
- const current = state.fences.get(request.resource.uid) ?? 0;
7650
- if (epoch < current) {
7651
- throw new OrchestrationError({
7652
- code: "STALE_EPOCH",
7653
- message: `stale policy fencing epoch ${epoch}; current epoch is ${current}`,
7654
- retryable: false
7655
- });
7656
- }
7657
- state.fences.set(request.resource.uid, epoch);
7658
7558
  }
7659
7559
  function assertPolicyDigest(value) {
7660
7560
  if (!SHA2567.test(value)) invalid10("policyDigest must be a canonical sha256 digest");
7661
7561
  }
7662
- function owned2(handle, resourceUid) {
7562
+ function owned(handle, resourceUid) {
7663
7563
  const decision = state.decisions.get(handle);
7664
7564
  if (!decision) {
7665
7565
  throw new OrchestrationError({
@@ -7679,18 +7579,14 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
7679
7579
  }
7680
7580
  async function decide(request, operation, kind, outcome, policyDigest, reasons, obligations = [], approval) {
7681
7581
  assertPolicyDigest(policyDigest);
7682
- const key = `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
7683
- const fingerprint = stable5(request.payload);
7684
- const previousHandle = state.idempotency.get(key);
7582
+ const previousHandle = findIdempotentDriverHandle(
7583
+ state,
7584
+ request,
7585
+ operation,
7586
+ "policy"
7587
+ );
7685
7588
  if (previousHandle) {
7686
- if (state.idempotencyFingerprints.get(key) !== fingerprint) {
7687
- throw new OrchestrationError({
7688
- code: "CONFLICT",
7689
- message: `policy ${operation} idempotency key was reused with different input`,
7690
- retryable: false
7691
- });
7692
- }
7693
- return structuredClone(owned2(previousHandle, request.resource.uid));
7589
+ return structuredClone(owned(previousHandle, request.resource.uid));
7694
7590
  }
7695
7591
  const decision = {
7696
7592
  decisionHandle: `policy-decision:${state.nextHandle++}`,
@@ -7706,8 +7602,12 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
7706
7602
  approval
7707
7603
  };
7708
7604
  state.decisions.set(decision.decisionHandle, decision);
7709
- state.idempotency.set(key, decision.decisionHandle);
7710
- state.idempotencyFingerprints.set(key, fingerprint);
7605
+ rememberIdempotentDriverHandle(
7606
+ state,
7607
+ request,
7608
+ operation,
7609
+ decision.decisionHandle
7610
+ );
7711
7611
  return structuredClone(decision);
7712
7612
  }
7713
7613
  return {
@@ -7780,7 +7680,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
7780
7680
  }
7781
7681
  let approval;
7782
7682
  if (request.payload.approvalDecisionHandle) {
7783
- approval = owned2(request.payload.approvalDecisionHandle, request.resource.uid);
7683
+ approval = owned(request.payload.approvalDecisionHandle, request.resource.uid);
7784
7684
  }
7785
7685
  const needsApproval = effect !== "read";
7786
7686
  const approvalValid = !needsApproval || approval?.kind === "approval" && approval.outcome === "allow" && approval.policyDigest === policyDigest && approval.approval?.subjectDigest === operationDigest && Date.parse(approval.approval.expiresAt) > now().getTime();
@@ -7828,7 +7728,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
7828
7728
  if (!["allow", "deny"].includes(request.payload.outcome)) {
7829
7729
  invalid10("approval outcome must be allow or deny");
7830
7730
  }
7831
- const decision = owned2(handle, request.resource.uid);
7731
+ const decision = owned(handle, request.resource.uid);
7832
7732
  if (decision.kind !== "approval") invalid10("decision is not an approval");
7833
7733
  if (decision.approval && Date.parse(decision.approval.expiresAt) <= now().getTime()) {
7834
7734
  decision.outcome = "deny";
@@ -7891,7 +7791,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
7891
7791
  "verifier",
7892
7792
  "admin"
7893
7793
  ]);
7894
- const decision = owned2(
7794
+ const decision = owned(
7895
7795
  requiredString7(request.payload, "decisionHandle"),
7896
7796
  request.resource.uid
7897
7797
  );
@@ -8128,6 +8028,7 @@ function createFakeStorageManagementState() {
8128
8028
  stages: /* @__PURE__ */ new Map(),
8129
8029
  publications: /* @__PURE__ */ new Map(),
8130
8030
  idempotency: /* @__PURE__ */ new Map(),
8031
+ idempotencyFingerprints: /* @__PURE__ */ new Map(),
8131
8032
  fences: /* @__PURE__ */ new Map(),
8132
8033
  nextHandle: 1
8133
8034
  };
@@ -8155,32 +8056,18 @@ function createFakeStorageManagementDriver(options = {}) {
8155
8056
  const state = options.state ?? createFakeStorageManagementState();
8156
8057
  const now = options.now ?? (() => /* @__PURE__ */ new Date());
8157
8058
  function validate(request, expectedMethod) {
8158
- assertDriverRequestEnvelope(request, {
8059
+ return assertFencedDriverRequestEnvelope(request, {
8159
8060
  now,
8160
- requireFencing: true,
8161
- requireCapability: true,
8162
- expectedMethod
8061
+ fences: state.fences,
8062
+ expectedMethod,
8063
+ fenceName: "storage"
8163
8064
  });
8164
- const fence = request.fencingEpoch;
8165
- const current = state.fences.get(request.resource.uid) ?? 0;
8166
- if (fence < current) {
8167
- throw new OrchestrationError({
8168
- code: "STALE_EPOCH",
8169
- message: `stale storage fencing epoch ${fence}; current epoch is ${current}`,
8170
- retryable: false
8171
- });
8172
- }
8173
- state.fences.set(request.resource.uid, fence);
8174
- return fence;
8175
8065
  }
8176
8066
  function nextHandle(prefix) {
8177
8067
  const handle = `${prefix}:${state.nextHandle}`;
8178
8068
  state.nextHandle += 1;
8179
8069
  return handle;
8180
8070
  }
8181
- function operationKey(request, operation) {
8182
- return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
8183
- }
8184
8071
  function getVolume(handle, resourceUid) {
8185
8072
  const record2 = state.volumes.get(handle);
8186
8073
  if (!record2 || record2.volume.phase === "Deleted") {
@@ -8199,27 +8086,8 @@ function createFakeStorageManagementDriver(options = {}) {
8199
8086
  }
8200
8087
  return record2;
8201
8088
  }
8202
- function owned2(collection, handle, resourceUid, kind) {
8203
- const value = collection.get(handle);
8204
- if (!value) {
8205
- throw new OrchestrationError({
8206
- code: "NOT_FOUND",
8207
- message: `${kind} handle '${handle}' was not found`,
8208
- retryable: false
8209
- });
8210
- }
8211
- if (value.resourceUid !== resourceUid) {
8212
- throw new OrchestrationError({
8213
- code: "FORBIDDEN",
8214
- message: `${kind} handle '${handle}' belongs to another resource`,
8215
- retryable: false
8216
- });
8217
- }
8218
- return value;
8219
- }
8220
8089
  function createVolume(request, capacityBytes, accessMode, replicaCount, operation) {
8221
- const key = operationKey(request, operation);
8222
- const existing = state.idempotency.get(key);
8090
+ const existing = findIdempotentDriverHandle(state, request, operation, "storage");
8223
8091
  if (existing) return getVolume(existing, request.resource.uid).volume;
8224
8092
  const volume = {
8225
8093
  volumeHandle: nextHandle("volume"),
@@ -8230,7 +8098,7 @@ function createFakeStorageManagementDriver(options = {}) {
8230
8098
  phase: "Available"
8231
8099
  };
8232
8100
  state.volumes.set(volume.volumeHandle, { volume, desiredReplicas: replicaCount });
8233
- state.idempotency.set(key, volume.volumeHandle);
8101
+ rememberIdempotentDriverHandle(state, request, operation, volume.volumeHandle);
8234
8102
  return volume;
8235
8103
  }
8236
8104
  return {
@@ -8286,9 +8154,10 @@ function createFakeStorageManagementDriver(options = {}) {
8286
8154
  validate(request, "storage.snapshot");
8287
8155
  const volumeHandle = requiredString8(request.payload, "volumeHandle");
8288
8156
  getVolume(volumeHandle, request.resource.uid);
8289
- const key = operationKey(request, "snapshot");
8290
- const existing = state.idempotency.get(key);
8291
- if (existing) return owned2(state.snapshots, existing, request.resource.uid, "snapshot");
8157
+ const existing = findIdempotentDriverHandle(state, request, "snapshot", "storage");
8158
+ if (existing) {
8159
+ return getOwnedDriverValue(state.snapshots, existing, request.resource.uid, "snapshot");
8160
+ }
8292
8161
  const snapshot = {
8293
8162
  snapshotHandle: nextHandle("snapshot"),
8294
8163
  volumeHandle,
@@ -8296,12 +8165,12 @@ function createFakeStorageManagementDriver(options = {}) {
8296
8165
  createdAt: now().toISOString()
8297
8166
  };
8298
8167
  state.snapshots.set(snapshot.snapshotHandle, snapshot);
8299
- state.idempotency.set(key, snapshot.snapshotHandle);
8168
+ rememberIdempotentDriverHandle(state, request, "snapshot", snapshot.snapshotHandle);
8300
8169
  return snapshot;
8301
8170
  },
8302
8171
  async restoreSnapshot(request) {
8303
8172
  validate(request, "storage.restore");
8304
- const snapshot = owned2(
8173
+ const snapshot = getOwnedDriverValue(
8305
8174
  state.snapshots,
8306
8175
  requiredString8(request.payload, "snapshotHandle"),
8307
8176
  request.resource.uid,
@@ -8364,9 +8233,10 @@ function createFakeStorageManagementDriver(options = {}) {
8364
8233
  validate(request, "storage.backup");
8365
8234
  const volumeHandle = requiredString8(request.payload, "volumeHandle");
8366
8235
  getVolume(volumeHandle, request.resource.uid);
8367
- const key = operationKey(request, "backup");
8368
- const existing = state.idempotency.get(key);
8369
- if (existing) return owned2(state.backups, existing, request.resource.uid, "backup");
8236
+ const existing = findIdempotentDriverHandle(state, request, "backup", "storage");
8237
+ if (existing) {
8238
+ return getOwnedDriverValue(state.backups, existing, request.resource.uid, "backup");
8239
+ }
8370
8240
  const backup = {
8371
8241
  backupHandle: nextHandle("backup"),
8372
8242
  volumeHandle,
@@ -8374,7 +8244,7 @@ function createFakeStorageManagementDriver(options = {}) {
8374
8244
  createdAt: now().toISOString()
8375
8245
  };
8376
8246
  state.backups.set(backup.backupHandle, backup);
8377
- state.idempotency.set(key, backup.backupHandle);
8247
+ rememberIdempotentDriverHandle(state, request, "backup", backup.backupHandle);
8378
8248
  return backup;
8379
8249
  },
8380
8250
  async stage(request) {
@@ -8382,9 +8252,10 @@ function createFakeStorageManagementDriver(options = {}) {
8382
8252
  const volumeHandle = requiredString8(request.payload, "volumeHandle");
8383
8253
  getVolume(volumeHandle, request.resource.uid);
8384
8254
  const nodeId = requiredString8(request.payload, "nodeId");
8385
- const key = operationKey(request, "stage");
8386
- const existing = state.idempotency.get(key);
8387
- if (existing) return owned2(state.stages, existing, request.resource.uid, "stage");
8255
+ const existing = findIdempotentDriverHandle(state, request, "stage", "storage");
8256
+ if (existing) {
8257
+ return getOwnedDriverValue(state.stages, existing, request.resource.uid, "stage");
8258
+ }
8388
8259
  const stage = {
8389
8260
  stageHandle: nextHandle("stage"),
8390
8261
  volumeHandle,
@@ -8392,12 +8263,12 @@ function createFakeStorageManagementDriver(options = {}) {
8392
8263
  nodeId
8393
8264
  };
8394
8265
  state.stages.set(stage.stageHandle, stage);
8395
- state.idempotency.set(key, stage.stageHandle);
8266
+ rememberIdempotentDriverHandle(state, request, "stage", stage.stageHandle);
8396
8267
  return stage;
8397
8268
  },
8398
8269
  async publish(request) {
8399
8270
  validate(request, "storage.publish");
8400
- const stage = owned2(
8271
+ const stage = getOwnedDriverValue(
8401
8272
  state.stages,
8402
8273
  requiredString8(request.payload, "stageHandle"),
8403
8274
  request.resource.uid,
@@ -8406,10 +8277,14 @@ function createFakeStorageManagementDriver(options = {}) {
8406
8277
  getVolume(stage.volumeHandle, request.resource.uid);
8407
8278
  const workloadUid = requiredString8(request.payload, "workloadUid");
8408
8279
  if (typeof request.payload.readOnly !== "boolean") invalid11("publish readOnly is required");
8409
- const key = operationKey(request, "publish");
8410
- const existing = state.idempotency.get(key);
8280
+ const existing = findIdempotentDriverHandle(state, request, "publish", "storage");
8411
8281
  if (existing) {
8412
- return owned2(state.publications, existing, request.resource.uid, "publication");
8282
+ return getOwnedDriverValue(
8283
+ state.publications,
8284
+ existing,
8285
+ request.resource.uid,
8286
+ "publication"
8287
+ );
8413
8288
  }
8414
8289
  const publication = {
8415
8290
  publishHandle: nextHandle("publication"),
@@ -8419,7 +8294,7 @@ function createFakeStorageManagementDriver(options = {}) {
8419
8294
  readOnly: request.payload.readOnly
8420
8295
  };
8421
8296
  state.publications.set(publication.publishHandle, publication);
8422
- state.idempotency.set(key, publication.publishHandle);
8297
+ rememberIdempotentDriverHandle(state, request, "publish", publication.publishHandle);
8423
8298
  return publication;
8424
8299
  },
8425
8300
  async unpublish(request) {
@@ -8427,7 +8302,7 @@ function createFakeStorageManagementDriver(options = {}) {
8427
8302
  const handle = requiredString8(request.payload, "publishHandle");
8428
8303
  const publication = state.publications.get(handle);
8429
8304
  if (!publication) return;
8430
- owned2(state.publications, handle, request.resource.uid, "publication");
8305
+ getOwnedDriverValue(state.publications, handle, request.resource.uid, "publication");
8431
8306
  state.publications.delete(handle);
8432
8307
  },
8433
8308
  async unstage(request) {
@@ -8435,7 +8310,7 @@ function createFakeStorageManagementDriver(options = {}) {
8435
8310
  const handle = requiredString8(request.payload, "stageHandle");
8436
8311
  const stage = state.stages.get(handle);
8437
8312
  if (!stage) return;
8438
- owned2(state.stages, handle, request.resource.uid, "stage");
8313
+ getOwnedDriverValue(state.stages, handle, request.resource.uid, "stage");
8439
8314
  if ([...state.publications.values()].some(
8440
8315
  (publication) => publication.stageHandle === handle
8441
8316
  )) {
@@ -8449,13 +8324,13 @@ function createFakeStorageManagementDriver(options = {}) {
8449
8324
  },
8450
8325
  async getStats(request) {
8451
8326
  validate(request, "storage.stats");
8452
- const publication = owned2(
8327
+ const publication = getOwnedDriverValue(
8453
8328
  state.publications,
8454
8329
  requiredString8(request.payload, "publishHandle"),
8455
8330
  request.resource.uid,
8456
8331
  "publication"
8457
8332
  );
8458
- const stage = owned2(
8333
+ const stage = getOwnedDriverValue(
8459
8334
  state.stages,
8460
8335
  publication.stageHandle,
8461
8336
  request.resource.uid,
@@ -8686,6 +8561,10 @@ export {
8686
8561
  createFakeIdentityAttestationState,
8687
8562
  createFakeIdentityAttestationManagementDriver,
8688
8563
  createIdentityAttestationConformanceSuite,
8564
+ classificationRank,
8565
+ assertClassificationAllowed,
8566
+ modelClassNameForSpec,
8567
+ createModelProviderDriverFromLLMProvider,
8689
8568
  createFakeLoopRuntimeState,
8690
8569
  createFakeLoopRuntimeManagementDriver,
8691
8570
  createLoopRuntimeManagementConformanceSuite,
@@ -8695,9 +8574,6 @@ export {
8695
8574
  createManagedCredentialBrokerAdapter,
8696
8575
  createManagedLoopRuntimeAdapter,
8697
8576
  createManagedLoopRuntimeExecutionRoute,
8698
- classificationRank,
8699
- assertClassificationAllowed,
8700
- createModelProviderDriverFromLLMProvider,
8701
8577
  createManagedModelGatewayAdapter,
8702
8578
  featuresRequiredByClass,
8703
8579
  canDriverSatisfyClass,
@@ -8723,4 +8599,4 @@ export {
8723
8599
  createFakeStorageManagementDriver,
8724
8600
  createStorageManagementConformanceSuite
8725
8601
  };
8726
- //# sourceMappingURL=chunk-GYIOMQMY.js.map
8602
+ //# sourceMappingURL=chunk-UB77WKAU.js.map