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
package/dist/index.cjs
CHANGED
|
@@ -1567,12 +1567,13 @@ function createFleetRolloutController(_store, options) {
|
|
|
1567
1567
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
1568
1568
|
async function reconcileRollout(request) {
|
|
1569
1569
|
const rollout = request.resource;
|
|
1570
|
-
const
|
|
1570
|
+
const previousStatus = rollout.status;
|
|
1571
|
+
const status = previousStatus?.observedGeneration !== void 0 && previousStatus.observedGeneration !== rollout.metadata.generation ? void 0 : previousStatus;
|
|
1571
1572
|
const spec = rollout.spec;
|
|
1572
|
-
if (status
|
|
1573
|
-
return { ready: true };
|
|
1573
|
+
if (status?.phase === "Completed" || status?.phase === "Failed" || status?.phase === "RolledBack") {
|
|
1574
|
+
return status.observedGeneration === rollout.metadata.generation ? { ready: true } : { status, ready: true };
|
|
1574
1575
|
}
|
|
1575
|
-
if (!status.phase) {
|
|
1576
|
+
if (!status || status.phase === "Pending") {
|
|
1576
1577
|
return {
|
|
1577
1578
|
status: {
|
|
1578
1579
|
...status,
|
|
@@ -1907,6 +1908,7 @@ function createFleetRolloutController(_store, options) {
|
|
|
1907
1908
|
if (result.status) {
|
|
1908
1909
|
result.status = {
|
|
1909
1910
|
...result.status,
|
|
1911
|
+
observedGeneration: request.resource.metadata.generation,
|
|
1910
1912
|
consumedBudget: sumEvidenceUsage(result.status.evidence)
|
|
1911
1913
|
};
|
|
1912
1914
|
}
|
|
@@ -3522,6 +3524,81 @@ var init_secretRedaction = __esm({
|
|
|
3522
3524
|
}
|
|
3523
3525
|
});
|
|
3524
3526
|
|
|
3527
|
+
// src/orchestration/drivers/driverState.ts
|
|
3528
|
+
function assertFencedDriverRequestEnvelope(request, options) {
|
|
3529
|
+
assertDriverRequestEnvelope(request, {
|
|
3530
|
+
now: options.now,
|
|
3531
|
+
requireRun: options.requireRun,
|
|
3532
|
+
requireFencing: true,
|
|
3533
|
+
requireCapability: true,
|
|
3534
|
+
expectedMethod: options.expectedMethod
|
|
3535
|
+
});
|
|
3536
|
+
if (options.actorKinds && !options.actorKinds.includes(request.actor.kind)) {
|
|
3537
|
+
throw new OrchestrationError({
|
|
3538
|
+
code: "FORBIDDEN",
|
|
3539
|
+
message: options.forbiddenMessage?.(request.actor.kind) ?? `actor kind '${request.actor.kind}' cannot call ${options.expectedMethod}`,
|
|
3540
|
+
retryable: false
|
|
3541
|
+
});
|
|
3542
|
+
}
|
|
3543
|
+
const epoch = request.fencingEpoch;
|
|
3544
|
+
const current = options.fences.get(request.resource.uid) ?? 0;
|
|
3545
|
+
if (epoch < current) {
|
|
3546
|
+
throw new OrchestrationError({
|
|
3547
|
+
code: "STALE_EPOCH",
|
|
3548
|
+
message: `stale ${options.fenceName} fencing epoch ${epoch}; current epoch is ${current}`,
|
|
3549
|
+
retryable: false
|
|
3550
|
+
});
|
|
3551
|
+
}
|
|
3552
|
+
options.fences.set(request.resource.uid, epoch);
|
|
3553
|
+
return epoch;
|
|
3554
|
+
}
|
|
3555
|
+
function driverOperationKey(request, operation) {
|
|
3556
|
+
return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
3557
|
+
}
|
|
3558
|
+
function findIdempotentDriverHandle(state, request, operation, driverName) {
|
|
3559
|
+
const key = driverOperationKey(request, operation);
|
|
3560
|
+
const handle = state.idempotency.get(key);
|
|
3561
|
+
if (handle === void 0) return void 0;
|
|
3562
|
+
if (state.idempotencyFingerprints.get(key) !== canonicalDriverValue(request.payload)) {
|
|
3563
|
+
throw new OrchestrationError({
|
|
3564
|
+
code: "CONFLICT",
|
|
3565
|
+
message: `${driverName} ${operation} idempotency key was reused with different input`,
|
|
3566
|
+
retryable: false
|
|
3567
|
+
});
|
|
3568
|
+
}
|
|
3569
|
+
return handle;
|
|
3570
|
+
}
|
|
3571
|
+
function rememberIdempotentDriverHandle(state, request, operation, handle) {
|
|
3572
|
+
const key = driverOperationKey(request, operation);
|
|
3573
|
+
state.idempotency.set(key, handle);
|
|
3574
|
+
state.idempotencyFingerprints.set(key, canonicalDriverValue(request.payload));
|
|
3575
|
+
}
|
|
3576
|
+
function getOwnedDriverValue(collection, handle, resourceUid, kind) {
|
|
3577
|
+
const value = collection.get(handle);
|
|
3578
|
+
if (!value) {
|
|
3579
|
+
throw new OrchestrationError({
|
|
3580
|
+
code: "NOT_FOUND",
|
|
3581
|
+
message: `${kind} handle '${handle}' was not found`,
|
|
3582
|
+
retryable: false
|
|
3583
|
+
});
|
|
3584
|
+
}
|
|
3585
|
+
if (value.resourceUid !== resourceUid) {
|
|
3586
|
+
throw new OrchestrationError({
|
|
3587
|
+
code: "FORBIDDEN",
|
|
3588
|
+
message: `${kind} handle '${handle}' belongs to another resource`,
|
|
3589
|
+
retryable: false
|
|
3590
|
+
});
|
|
3591
|
+
}
|
|
3592
|
+
return value;
|
|
3593
|
+
}
|
|
3594
|
+
var init_driverState = __esm({
|
|
3595
|
+
"src/orchestration/drivers/driverState.ts"() {
|
|
3596
|
+
"use strict";
|
|
3597
|
+
init_errors();
|
|
3598
|
+
init_driverRequest();
|
|
3599
|
+
}
|
|
3600
|
+
});
|
|
3601
|
+
|
|
3525
3602
|
// src/orchestration/drivers/auditTelemetryManagement.ts
|
|
3526
3603
|
function createFakeAuditTelemetryState() {
|
|
3527
3604
|
return {
|
|
@@ -3535,16 +3612,8 @@ function createFakeAuditTelemetryState() {
|
|
|
3535
3612
|
function invalid3(message) {
|
|
3536
3613
|
throw new OrchestrationError({ code: "INVALID", message, retryable: false });
|
|
3537
3614
|
}
|
|
3538
|
-
function stable(value) {
|
|
3539
|
-
if (value === void 0) return "undefined";
|
|
3540
|
-
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
3541
|
-
if (value !== null && typeof value === "object") {
|
|
3542
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable(item)}`).join(",")}}`;
|
|
3543
|
-
}
|
|
3544
|
-
return JSON.stringify(value) ?? typeof value;
|
|
3545
|
-
}
|
|
3546
3615
|
async function digest(value) {
|
|
3547
|
-
const bytes = new TextEncoder().encode(
|
|
3616
|
+
const bytes = new TextEncoder().encode(canonicalDriverValue(value));
|
|
3548
3617
|
const result = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
3549
3618
|
return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
3550
3619
|
}
|
|
@@ -3562,29 +3631,13 @@ function createFakeAuditTelemetryManagementDriver(options = {}) {
|
|
|
3562
3631
|
const maxRecordsPerResource = options.maxRecordsPerResource ?? 1e4;
|
|
3563
3632
|
const maxAttributes = options.maxAttributes ?? 16;
|
|
3564
3633
|
function validate(request, expectedMethod, actorKinds) {
|
|
3565
|
-
|
|
3634
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
3566
3635
|
now,
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3636
|
+
fences: state.fences,
|
|
3637
|
+
expectedMethod,
|
|
3638
|
+
fenceName: "audit",
|
|
3639
|
+
actorKinds
|
|
3570
3640
|
});
|
|
3571
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
3572
|
-
throw new OrchestrationError({
|
|
3573
|
-
code: "FORBIDDEN",
|
|
3574
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
3575
|
-
retryable: false
|
|
3576
|
-
});
|
|
3577
|
-
}
|
|
3578
|
-
const epoch = request.fencingEpoch;
|
|
3579
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
3580
|
-
if (epoch < current) {
|
|
3581
|
-
throw new OrchestrationError({
|
|
3582
|
-
code: "STALE_EPOCH",
|
|
3583
|
-
message: `stale audit fencing epoch ${epoch}; current epoch is ${current}`,
|
|
3584
|
-
retryable: false
|
|
3585
|
-
});
|
|
3586
|
-
}
|
|
3587
|
-
state.fences.set(request.resource.uid, epoch);
|
|
3588
3641
|
}
|
|
3589
3642
|
function common(request) {
|
|
3590
3643
|
const policyDigest = requiredString2(request.payload, "policyDigest", 80);
|
|
@@ -3614,7 +3667,7 @@ function createFakeAuditTelemetryManagementDriver(options = {}) {
|
|
|
3614
3667
|
}
|
|
3615
3668
|
async function append(request, kind, data) {
|
|
3616
3669
|
const idempotencyKey = `${request.resource.uid}:${request.method}:${request.idempotencyKey}`;
|
|
3617
|
-
const fingerprint =
|
|
3670
|
+
const fingerprint = canonicalDriverValue(request.payload);
|
|
3618
3671
|
let release;
|
|
3619
3672
|
const previousAppend = state.appendTail;
|
|
3620
3673
|
state.appendTail = new Promise((resolve) => {
|
|
@@ -3953,6 +4006,7 @@ var init_auditTelemetryManagement = __esm({
|
|
|
3953
4006
|
init_errors();
|
|
3954
4007
|
init_secretRedaction();
|
|
3955
4008
|
init_driverRequest();
|
|
4009
|
+
init_driverState();
|
|
3956
4010
|
SHA256 = /^sha256:[a-f0-9]{64}$/;
|
|
3957
4011
|
FORBIDDEN_ATTRIBUTE = /(?:secret|token|password|credential|authorization|cookie|private[-_]?key)/i;
|
|
3958
4012
|
}
|
|
@@ -6399,24 +6453,6 @@ function requiredString4(payload, field) {
|
|
|
6399
6453
|
if (payload === null || typeof payload !== "object" || typeof payload[field] !== "string" || !payload[field]) invalid9(`identity payload '${field}' is required`);
|
|
6400
6454
|
return payload[field];
|
|
6401
6455
|
}
|
|
6402
|
-
function owned(collection, handle, resourceUid, kind) {
|
|
6403
|
-
const value = collection.get(handle);
|
|
6404
|
-
if (!value) {
|
|
6405
|
-
throw new OrchestrationError({
|
|
6406
|
-
code: "NOT_FOUND",
|
|
6407
|
-
message: `${kind} handle '${handle}' was not found`,
|
|
6408
|
-
retryable: false
|
|
6409
|
-
});
|
|
6410
|
-
}
|
|
6411
|
-
if (value.resourceUid !== resourceUid) {
|
|
6412
|
-
throw new OrchestrationError({
|
|
6413
|
-
code: "FORBIDDEN",
|
|
6414
|
-
message: `${kind} handle '${handle}' belongs to another resource`,
|
|
6415
|
-
retryable: false
|
|
6416
|
-
});
|
|
6417
|
-
}
|
|
6418
|
-
return value;
|
|
6419
|
-
}
|
|
6420
6456
|
function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
6421
6457
|
const state = options.state ?? createFakeIdentityAttestationState();
|
|
6422
6458
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
@@ -6433,29 +6469,13 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6433
6469
|
`sha256:${"a".repeat(64)}`
|
|
6434
6470
|
];
|
|
6435
6471
|
function validate(request, expectedMethod, actorKinds) {
|
|
6436
|
-
|
|
6472
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
6437
6473
|
now,
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6474
|
+
fences: state.fences,
|
|
6475
|
+
expectedMethod,
|
|
6476
|
+
fenceName: "identity",
|
|
6477
|
+
actorKinds
|
|
6441
6478
|
});
|
|
6442
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
6443
|
-
throw new OrchestrationError({
|
|
6444
|
-
code: "FORBIDDEN",
|
|
6445
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
6446
|
-
retryable: false
|
|
6447
|
-
});
|
|
6448
|
-
}
|
|
6449
|
-
const fence = request.fencingEpoch;
|
|
6450
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
6451
|
-
if (fence < current) {
|
|
6452
|
-
throw new OrchestrationError({
|
|
6453
|
-
code: "STALE_EPOCH",
|
|
6454
|
-
message: `stale identity fencing epoch ${fence}; current epoch is ${current}`,
|
|
6455
|
-
retryable: false
|
|
6456
|
-
});
|
|
6457
|
-
}
|
|
6458
|
-
state.fences.set(request.resource.uid, fence);
|
|
6459
6479
|
}
|
|
6460
6480
|
function ttl(payload, field, maximum) {
|
|
6461
6481
|
if (payload === null || typeof payload !== "object") {
|
|
@@ -6470,34 +6490,11 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6470
6490
|
state.nextHandle += 1;
|
|
6471
6491
|
return handle;
|
|
6472
6492
|
}
|
|
6473
|
-
function key(request, operation) {
|
|
6474
|
-
return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
6475
|
-
}
|
|
6476
|
-
function stable6(value) {
|
|
6477
|
-
if (value === void 0) return "undefined";
|
|
6478
|
-
if (Array.isArray(value)) return `[${value.map(stable6).join(",")}]`;
|
|
6479
|
-
if (value !== null && typeof value === "object") {
|
|
6480
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([name, item]) => `${JSON.stringify(name)}:${stable6(item)}`).join(",")}}`;
|
|
6481
|
-
}
|
|
6482
|
-
return JSON.stringify(value) ?? typeof value;
|
|
6483
|
-
}
|
|
6484
6493
|
function previous(request, operation) {
|
|
6485
|
-
|
|
6486
|
-
const handle = state.idempotency.get(idempotency);
|
|
6487
|
-
if (!handle) return void 0;
|
|
6488
|
-
if (state.idempotencyFingerprints.get(idempotency) !== stable6(request.payload)) {
|
|
6489
|
-
throw new OrchestrationError({
|
|
6490
|
-
code: "CONFLICT",
|
|
6491
|
-
message: `identity ${operation} idempotency key was reused with different input`,
|
|
6492
|
-
retryable: false
|
|
6493
|
-
});
|
|
6494
|
-
}
|
|
6495
|
-
return handle;
|
|
6494
|
+
return findIdempotentDriverHandle(state, request, operation, "identity");
|
|
6496
6495
|
}
|
|
6497
6496
|
function remember(request, operation, handle) {
|
|
6498
|
-
|
|
6499
|
-
state.idempotency.set(idempotency, handle);
|
|
6500
|
-
state.idempotencyFingerprints.set(idempotency, stable6(request.payload));
|
|
6497
|
+
rememberIdempotentDriverHandle(state, request, operation, handle);
|
|
6501
6498
|
}
|
|
6502
6499
|
function assertActiveIdentity(identity) {
|
|
6503
6500
|
if (identity.revoked) {
|
|
@@ -6541,7 +6538,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6541
6538
|
const ttlMs = ttl(request.payload, "ttlMs", maxSessionTtlMs);
|
|
6542
6539
|
const existing = previous(request, "enroll");
|
|
6543
6540
|
if (existing) {
|
|
6544
|
-
return structuredClone(
|
|
6541
|
+
return structuredClone(getOwnedDriverValue(
|
|
6545
6542
|
state.enrollments,
|
|
6546
6543
|
existing,
|
|
6547
6544
|
request.resource.uid,
|
|
@@ -6565,7 +6562,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6565
6562
|
},
|
|
6566
6563
|
async challenge(request) {
|
|
6567
6564
|
validate(request, "identity.challenge", ["controller", "admin"]);
|
|
6568
|
-
const enrollment =
|
|
6565
|
+
const enrollment = getOwnedDriverValue(
|
|
6569
6566
|
state.enrollments,
|
|
6570
6567
|
requiredString4(request.payload, "enrollmentHandle"),
|
|
6571
6568
|
request.resource.uid,
|
|
@@ -6578,7 +6575,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6578
6575
|
const ttlMs = ttl(request.payload, "ttlMs", maxChallengeTtlMs);
|
|
6579
6576
|
const existing = previous(request, "challenge");
|
|
6580
6577
|
if (existing) {
|
|
6581
|
-
return structuredClone(
|
|
6578
|
+
return structuredClone(getOwnedDriverValue(
|
|
6582
6579
|
state.challenges,
|
|
6583
6580
|
existing,
|
|
6584
6581
|
request.resource.uid,
|
|
@@ -6608,13 +6605,13 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6608
6605
|
},
|
|
6609
6606
|
async attest(request) {
|
|
6610
6607
|
validate(request, "identity.attest", ["controller", "verifier"]);
|
|
6611
|
-
const challenge =
|
|
6608
|
+
const challenge = getOwnedDriverValue(
|
|
6612
6609
|
state.challenges,
|
|
6613
6610
|
requiredString4(request.payload, "challengeHandle"),
|
|
6614
6611
|
request.resource.uid,
|
|
6615
6612
|
"challenge"
|
|
6616
6613
|
);
|
|
6617
|
-
const enrollment =
|
|
6614
|
+
const enrollment = getOwnedDriverValue(
|
|
6618
6615
|
state.enrollments,
|
|
6619
6616
|
challenge.enrollmentHandle,
|
|
6620
6617
|
request.resource.uid,
|
|
@@ -6650,7 +6647,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6650
6647
|
}
|
|
6651
6648
|
const existing = previous(request, "attest");
|
|
6652
6649
|
if (existing) {
|
|
6653
|
-
return structuredClone(
|
|
6650
|
+
return structuredClone(getOwnedDriverValue(
|
|
6654
6651
|
state.identities,
|
|
6655
6652
|
existing,
|
|
6656
6653
|
request.resource.uid,
|
|
@@ -6685,7 +6682,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6685
6682
|
},
|
|
6686
6683
|
async issueSession(request) {
|
|
6687
6684
|
validate(request, "identity.issue-session", ["controller", "admin"]);
|
|
6688
|
-
const identity =
|
|
6685
|
+
const identity = getOwnedDriverValue(
|
|
6689
6686
|
state.identities,
|
|
6690
6687
|
requiredString4(request.payload, "identityHandle"),
|
|
6691
6688
|
request.resource.uid,
|
|
@@ -6714,7 +6711,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6714
6711
|
const ttlMs = ttl(request.payload, "ttlMs", maxSessionTtlMs);
|
|
6715
6712
|
const existing = previous(request, "issue-session");
|
|
6716
6713
|
if (existing) {
|
|
6717
|
-
return structuredClone(
|
|
6714
|
+
return structuredClone(getOwnedDriverValue(
|
|
6718
6715
|
state.sessions,
|
|
6719
6716
|
existing,
|
|
6720
6717
|
request.resource.uid,
|
|
@@ -6738,7 +6735,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6738
6735
|
},
|
|
6739
6736
|
async rotate(request) {
|
|
6740
6737
|
validate(request, "identity.rotate", ["controller", "admin"]);
|
|
6741
|
-
const identity =
|
|
6738
|
+
const identity = getOwnedDriverValue(
|
|
6742
6739
|
state.identities,
|
|
6743
6740
|
requiredString4(request.payload, "identityHandle"),
|
|
6744
6741
|
request.resource.uid,
|
|
@@ -6755,7 +6752,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6755
6752
|
);
|
|
6756
6753
|
const existing = previous(request, "rotate");
|
|
6757
6754
|
if (existing) {
|
|
6758
|
-
return structuredClone(
|
|
6755
|
+
return structuredClone(getOwnedDriverValue(
|
|
6759
6756
|
state.identities,
|
|
6760
6757
|
existing,
|
|
6761
6758
|
request.resource.uid,
|
|
@@ -6783,7 +6780,7 @@ function createFakeIdentityAttestationManagementDriver(options = {}) {
|
|
|
6783
6780
|
},
|
|
6784
6781
|
async revoke(request) {
|
|
6785
6782
|
validate(request, "identity.revoke", ["controller", "admin"]);
|
|
6786
|
-
const identity =
|
|
6783
|
+
const identity = getOwnedDriverValue(
|
|
6787
6784
|
state.identities,
|
|
6788
6785
|
requiredString4(request.payload, "identityHandle"),
|
|
6789
6786
|
request.resource.uid,
|
|
@@ -7139,7 +7136,113 @@ var init_identityAttestationManagement = __esm({
|
|
|
7139
7136
|
"src/orchestration/drivers/identityAttestationManagement.ts"() {
|
|
7140
7137
|
"use strict";
|
|
7141
7138
|
init_errors();
|
|
7142
|
-
|
|
7139
|
+
init_driverState();
|
|
7140
|
+
}
|
|
7141
|
+
});
|
|
7142
|
+
|
|
7143
|
+
// src/orchestration/drivers/modelProviderDriver.ts
|
|
7144
|
+
function classificationRank(value) {
|
|
7145
|
+
return CLASSIFICATION_ORDER[value];
|
|
7146
|
+
}
|
|
7147
|
+
function assertClassificationAllowed(policy, classification) {
|
|
7148
|
+
if (!policy?.maxInputClassification || !classification) return;
|
|
7149
|
+
if (classificationRank(classification) > classificationRank(policy.maxInputClassification)) {
|
|
7150
|
+
throw new OrchestrationError({
|
|
7151
|
+
code: "FORBIDDEN",
|
|
7152
|
+
message: `input classification '${classification}' exceeds endpoint limit '${policy.maxInputClassification}'`,
|
|
7153
|
+
retryable: false,
|
|
7154
|
+
details: { classification, maxInputClassification: policy.maxInputClassification }
|
|
7155
|
+
});
|
|
7156
|
+
}
|
|
7157
|
+
}
|
|
7158
|
+
function modelClassNameForSpec(model) {
|
|
7159
|
+
return `${model.provider}-${model.model}`.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^-+|-+$/g, "") || "model";
|
|
7160
|
+
}
|
|
7161
|
+
function createModelProviderDriverFromLLMProvider(provider, options) {
|
|
7162
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
7163
|
+
const toLegacyRequest = options.toLegacyRequest ?? ((request) => {
|
|
7164
|
+
const candidates = options.models.filter(
|
|
7165
|
+
(model) => modelClassNameForSpec(model) === request.modelClassRef.name || model.model === request.modelClassRef.name
|
|
7166
|
+
);
|
|
7167
|
+
if (candidates.length !== 1) {
|
|
7168
|
+
throw new OrchestrationError({
|
|
7169
|
+
code: "INVALID",
|
|
7170
|
+
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}'`,
|
|
7171
|
+
retryable: false
|
|
7172
|
+
});
|
|
7173
|
+
}
|
|
7174
|
+
return {
|
|
7175
|
+
model: candidates[0].model,
|
|
7176
|
+
messages: request.messages,
|
|
7177
|
+
max_tokens: request.maxOutputTokens,
|
|
7178
|
+
temperature: request.temperature,
|
|
7179
|
+
topP: request.topP,
|
|
7180
|
+
providerOptions: request.providerOptions,
|
|
7181
|
+
abortSignal: request.signal
|
|
7182
|
+
};
|
|
7183
|
+
});
|
|
7184
|
+
const toDelta = options.toDelta ?? ((chunk) => typeof chunk === "string" ? chunk : void 0);
|
|
7185
|
+
return {
|
|
7186
|
+
async listModels() {
|
|
7187
|
+
return options.models;
|
|
7188
|
+
},
|
|
7189
|
+
async getHealth() {
|
|
7190
|
+
return {
|
|
7191
|
+
healthy: true,
|
|
7192
|
+
detail: `legacy provider ${provider.name}`,
|
|
7193
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7194
|
+
};
|
|
7195
|
+
},
|
|
7196
|
+
async *generate(request) {
|
|
7197
|
+
assertClassificationAllowed(options.dataPolicy, request.inputClassification);
|
|
7198
|
+
const controller = new AbortController();
|
|
7199
|
+
inFlight.set(request.callId, controller);
|
|
7200
|
+
const onExternalAbort = () => {
|
|
7201
|
+
controller.abort();
|
|
7202
|
+
};
|
|
7203
|
+
request.signal?.addEventListener("abort", onExternalAbort);
|
|
7204
|
+
try {
|
|
7205
|
+
const legacy = toLegacyRequest({ ...request, signal: controller.signal });
|
|
7206
|
+
const output = await provider.chat(legacy);
|
|
7207
|
+
if (output != null && typeof output === "object" && Symbol.asyncIterator in output) {
|
|
7208
|
+
for await (const chunk of output) {
|
|
7209
|
+
if (controller.signal.aborted) {
|
|
7210
|
+
yield {
|
|
7211
|
+
type: "error",
|
|
7212
|
+
error: { code: "CANCELLED", message: "generate cancelled", retryable: false }
|
|
7213
|
+
};
|
|
7214
|
+
return;
|
|
7215
|
+
}
|
|
7216
|
+
const delta = toDelta(chunk);
|
|
7217
|
+
if (delta !== void 0) {
|
|
7218
|
+
yield { type: "delta", delta };
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
} else if (typeof output === "string") {
|
|
7222
|
+
yield { type: "delta", delta: output };
|
|
7223
|
+
}
|
|
7224
|
+
yield { type: "done" };
|
|
7225
|
+
} finally {
|
|
7226
|
+
request.signal?.removeEventListener("abort", onExternalAbort);
|
|
7227
|
+
inFlight.delete(request.callId);
|
|
7228
|
+
}
|
|
7229
|
+
},
|
|
7230
|
+
async cancel(callId) {
|
|
7231
|
+
inFlight.get(callId)?.abort();
|
|
7232
|
+
}
|
|
7233
|
+
};
|
|
7234
|
+
}
|
|
7235
|
+
var CLASSIFICATION_ORDER;
|
|
7236
|
+
var init_modelProviderDriver = __esm({
|
|
7237
|
+
"src/orchestration/drivers/modelProviderDriver.ts"() {
|
|
7238
|
+
"use strict";
|
|
7239
|
+
init_errors();
|
|
7240
|
+
CLASSIFICATION_ORDER = {
|
|
7241
|
+
public: 0,
|
|
7242
|
+
internal: 1,
|
|
7243
|
+
confidential: 2,
|
|
7244
|
+
restricted: 3
|
|
7245
|
+
};
|
|
7143
7246
|
}
|
|
7144
7247
|
});
|
|
7145
7248
|
|
|
@@ -7153,7 +7256,7 @@ async function describeLocalModelEndpoints(driver, options) {
|
|
|
7153
7256
|
const modelClasses = [];
|
|
7154
7257
|
const endpoints = [];
|
|
7155
7258
|
for (const model of models) {
|
|
7156
|
-
const baseName =
|
|
7259
|
+
const baseName = modelClassNameForSpec(model);
|
|
7157
7260
|
modelClasses.push(createModelClassManifest(baseName, model));
|
|
7158
7261
|
endpoints.push(createModelEndpointManifest(`${baseName}-${sanitizeModelName(options.nodeId)}`, {
|
|
7159
7262
|
modelClassRef: { apiVersion: MODEL_CLASS_API_VERSION, kind: MODEL_CLASS_KIND, name: baseName },
|
|
@@ -7190,6 +7293,7 @@ var init_localModelRegistration = __esm({
|
|
|
7190
7293
|
"src/orchestration/drivers/localModelRegistration.ts"() {
|
|
7191
7294
|
"use strict";
|
|
7192
7295
|
init_resources();
|
|
7296
|
+
init_modelProviderDriver();
|
|
7193
7297
|
TRUST_RANK2 = {
|
|
7194
7298
|
quarantine: 0,
|
|
7195
7299
|
restricted: 1,
|
|
@@ -8238,12 +8342,12 @@ function createManagedCredentialBrokerAdapter(broker, options) {
|
|
|
8238
8342
|
retryable: false
|
|
8239
8343
|
});
|
|
8240
8344
|
}
|
|
8241
|
-
const
|
|
8242
|
-
if (!
|
|
8345
|
+
const stable = options.stableHandleFor?.(request) ?? stableHandle();
|
|
8346
|
+
if (!stable || stable.length > 2048) {
|
|
8243
8347
|
invalid11("credential stable handle is empty or too long");
|
|
8244
8348
|
}
|
|
8245
8349
|
if (options.handleStore) {
|
|
8246
|
-
const adopted = await options.handleStore.get(
|
|
8350
|
+
const adopted = await options.handleStore.get(stable);
|
|
8247
8351
|
if (adopted) {
|
|
8248
8352
|
const inspection = await broker.inspect(adopted.token);
|
|
8249
8353
|
const exact = inspection.grantId === request.resource.uid && canonicalDriverValue(inspection.scope) === canonicalDriverValue({
|
|
@@ -8263,13 +8367,13 @@ function createManagedCredentialBrokerAdapter(broker, options) {
|
|
|
8263
8367
|
});
|
|
8264
8368
|
}
|
|
8265
8369
|
const adoptedRecord = {
|
|
8266
|
-
stableHandle:
|
|
8370
|
+
stableHandle: stable,
|
|
8267
8371
|
token: adopted.token,
|
|
8268
8372
|
resourceUid: request.resource.uid,
|
|
8269
8373
|
targetDriver: request.payload.targetDriver
|
|
8270
8374
|
};
|
|
8271
|
-
records.set(
|
|
8272
|
-
await rememberIdempotency(key, request,
|
|
8375
|
+
records.set(stable, adoptedRecord);
|
|
8376
|
+
await rememberIdempotency(key, request, stable);
|
|
8273
8377
|
return managed(adoptedRecord, inspection);
|
|
8274
8378
|
}
|
|
8275
8379
|
}
|
|
@@ -8285,7 +8389,7 @@ function createManagedCredentialBrokerAdapter(broker, options) {
|
|
|
8285
8389
|
grantId: request.resource.uid
|
|
8286
8390
|
});
|
|
8287
8391
|
const record2 = {
|
|
8288
|
-
stableHandle:
|
|
8392
|
+
stableHandle: stable,
|
|
8289
8393
|
token: issued.token,
|
|
8290
8394
|
resourceUid: request.resource.uid,
|
|
8291
8395
|
targetDriver: request.payload.targetDriver
|
|
@@ -8952,95 +9056,6 @@ var init_managedLoopRuntimeAdapter = __esm({
|
|
|
8952
9056
|
}
|
|
8953
9057
|
});
|
|
8954
9058
|
|
|
8955
|
-
// src/orchestration/drivers/modelProviderDriver.ts
|
|
8956
|
-
function classificationRank(value) {
|
|
8957
|
-
return CLASSIFICATION_ORDER[value];
|
|
8958
|
-
}
|
|
8959
|
-
function assertClassificationAllowed(policy, classification) {
|
|
8960
|
-
if (!policy?.maxInputClassification || !classification) return;
|
|
8961
|
-
if (classificationRank(classification) > classificationRank(policy.maxInputClassification)) {
|
|
8962
|
-
throw new OrchestrationError({
|
|
8963
|
-
code: "FORBIDDEN",
|
|
8964
|
-
message: `input classification '${classification}' exceeds endpoint limit '${policy.maxInputClassification}'`,
|
|
8965
|
-
retryable: false,
|
|
8966
|
-
details: { classification, maxInputClassification: policy.maxInputClassification }
|
|
8967
|
-
});
|
|
8968
|
-
}
|
|
8969
|
-
}
|
|
8970
|
-
function createModelProviderDriverFromLLMProvider(provider, options) {
|
|
8971
|
-
const inFlight = /* @__PURE__ */ new Map();
|
|
8972
|
-
const toLegacyRequest = options.toLegacyRequest ?? ((request) => ({
|
|
8973
|
-
...provider.modelId !== void 0 ? { model: provider.modelId } : {},
|
|
8974
|
-
messages: request.messages,
|
|
8975
|
-
max_tokens: request.maxOutputTokens,
|
|
8976
|
-
temperature: request.temperature,
|
|
8977
|
-
abortSignal: request.signal
|
|
8978
|
-
}));
|
|
8979
|
-
const toDelta = options.toDelta ?? ((chunk) => typeof chunk === "string" ? chunk : void 0);
|
|
8980
|
-
return {
|
|
8981
|
-
async listModels() {
|
|
8982
|
-
return options.models;
|
|
8983
|
-
},
|
|
8984
|
-
async getHealth() {
|
|
8985
|
-
return {
|
|
8986
|
-
healthy: true,
|
|
8987
|
-
detail: `legacy provider ${provider.name}`,
|
|
8988
|
-
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8989
|
-
};
|
|
8990
|
-
},
|
|
8991
|
-
async *generate(request) {
|
|
8992
|
-
assertClassificationAllowed(options.dataPolicy, request.inputClassification);
|
|
8993
|
-
const controller = new AbortController();
|
|
8994
|
-
inFlight.set(request.callId, controller);
|
|
8995
|
-
const onExternalAbort = () => {
|
|
8996
|
-
controller.abort();
|
|
8997
|
-
};
|
|
8998
|
-
request.signal?.addEventListener("abort", onExternalAbort);
|
|
8999
|
-
try {
|
|
9000
|
-
const legacy = toLegacyRequest({ ...request, signal: controller.signal });
|
|
9001
|
-
const output = await provider.chat(legacy);
|
|
9002
|
-
if (output != null && typeof output === "object" && Symbol.asyncIterator in output) {
|
|
9003
|
-
for await (const chunk of output) {
|
|
9004
|
-
if (controller.signal.aborted) {
|
|
9005
|
-
yield {
|
|
9006
|
-
type: "error",
|
|
9007
|
-
error: { code: "CANCELLED", message: "generate cancelled", retryable: false }
|
|
9008
|
-
};
|
|
9009
|
-
return;
|
|
9010
|
-
}
|
|
9011
|
-
const delta = toDelta(chunk);
|
|
9012
|
-
if (delta !== void 0) {
|
|
9013
|
-
yield { type: "delta", delta };
|
|
9014
|
-
}
|
|
9015
|
-
}
|
|
9016
|
-
} else if (typeof output === "string") {
|
|
9017
|
-
yield { type: "delta", delta: output };
|
|
9018
|
-
}
|
|
9019
|
-
yield { type: "done" };
|
|
9020
|
-
} finally {
|
|
9021
|
-
request.signal?.removeEventListener("abort", onExternalAbort);
|
|
9022
|
-
inFlight.delete(request.callId);
|
|
9023
|
-
}
|
|
9024
|
-
},
|
|
9025
|
-
async cancel(callId) {
|
|
9026
|
-
inFlight.get(callId)?.abort();
|
|
9027
|
-
}
|
|
9028
|
-
};
|
|
9029
|
-
}
|
|
9030
|
-
var CLASSIFICATION_ORDER;
|
|
9031
|
-
var init_modelProviderDriver = __esm({
|
|
9032
|
-
"src/orchestration/drivers/modelProviderDriver.ts"() {
|
|
9033
|
-
"use strict";
|
|
9034
|
-
init_errors();
|
|
9035
|
-
CLASSIFICATION_ORDER = {
|
|
9036
|
-
public: 0,
|
|
9037
|
-
internal: 1,
|
|
9038
|
-
confidential: 2,
|
|
9039
|
-
restricted: 3
|
|
9040
|
-
};
|
|
9041
|
-
}
|
|
9042
|
-
});
|
|
9043
|
-
|
|
9044
9059
|
// src/orchestration/drivers/managedModelGatewayAdapter.ts
|
|
9045
9060
|
function fail(code, message, retryable = false) {
|
|
9046
9061
|
throw new OrchestrationError({ code, message, retryable });
|
|
@@ -9526,13 +9541,6 @@ function createFakeNetworkManagementState() {
|
|
|
9526
9541
|
nextHandle: 1
|
|
9527
9542
|
};
|
|
9528
9543
|
}
|
|
9529
|
-
function stable2(value) {
|
|
9530
|
-
if (Array.isArray(value)) return `[${value.map(stable2).join(",")}]`;
|
|
9531
|
-
if (value !== null && typeof value === "object") {
|
|
9532
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable2(item)}`).join(",")}}`;
|
|
9533
|
-
}
|
|
9534
|
-
return JSON.stringify(value) ?? typeof value;
|
|
9535
|
-
}
|
|
9536
9544
|
function invalid12(message) {
|
|
9537
9545
|
throw new OrchestrationError({ code: "INVALID", message, retryable: false });
|
|
9538
9546
|
}
|
|
@@ -9732,32 +9740,16 @@ function createFakeNetworkManagementDriver(options = {}) {
|
|
|
9732
9740
|
],
|
|
9733
9741
|
...options.capabilities
|
|
9734
9742
|
};
|
|
9735
|
-
function validate(request, method) {
|
|
9736
|
-
|
|
9737
|
-
now,
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
code: "FORBIDDEN",
|
|
9746
|
-
message: "network lifecycle requires a controller or admin actor",
|
|
9747
|
-
retryable: false
|
|
9748
|
-
});
|
|
9749
|
-
}
|
|
9750
|
-
const fence = request.fencingEpoch;
|
|
9751
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
9752
|
-
if (fence < current) {
|
|
9753
|
-
throw new OrchestrationError({
|
|
9754
|
-
code: "STALE_EPOCH",
|
|
9755
|
-
message: `stale network fencing epoch ${fence}; current epoch is ${current}`,
|
|
9756
|
-
retryable: false
|
|
9757
|
-
});
|
|
9758
|
-
}
|
|
9759
|
-
state.fences.set(request.resource.uid, fence);
|
|
9760
|
-
return fence;
|
|
9743
|
+
function validate(request, method) {
|
|
9744
|
+
return assertFencedDriverRequestEnvelope(request, {
|
|
9745
|
+
now,
|
|
9746
|
+
fences: state.fences,
|
|
9747
|
+
requireRun: true,
|
|
9748
|
+
expectedMethod: method,
|
|
9749
|
+
fenceName: "network",
|
|
9750
|
+
actorKinds: ["controller", "admin"],
|
|
9751
|
+
forbiddenMessage: () => "network lifecycle requires a controller or admin actor"
|
|
9752
|
+
});
|
|
9761
9753
|
}
|
|
9762
9754
|
function nextHandle(prefix) {
|
|
9763
9755
|
const handle = `${prefix}:${state.nextHandle}`;
|
|
@@ -9821,7 +9813,7 @@ function createFakeNetworkManagementDriver(options = {}) {
|
|
|
9821
9813
|
}
|
|
9822
9814
|
function idempotent(request, operation) {
|
|
9823
9815
|
const key = `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
9824
|
-
const fingerprint =
|
|
9816
|
+
const fingerprint = canonicalDriverValue(request.payload);
|
|
9825
9817
|
const existing = state.idempotency.get(key);
|
|
9826
9818
|
if (existing) {
|
|
9827
9819
|
if (existing.fingerprint !== fingerprint) {
|
|
@@ -9838,7 +9830,7 @@ function createFakeNetworkManagementDriver(options = {}) {
|
|
|
9838
9830
|
function remember(request, operation, resultHandle) {
|
|
9839
9831
|
state.idempotency.set(
|
|
9840
9832
|
`${request.resource.uid}:${operation}:${request.idempotencyKey}`,
|
|
9841
|
-
{ fingerprint:
|
|
9833
|
+
{ fingerprint: canonicalDriverValue(request.payload), resultHandle }
|
|
9842
9834
|
);
|
|
9843
9835
|
}
|
|
9844
9836
|
return {
|
|
@@ -10133,6 +10125,7 @@ var init_networkManagement = __esm({
|
|
|
10133
10125
|
"use strict";
|
|
10134
10126
|
init_errors();
|
|
10135
10127
|
init_driverRequest();
|
|
10128
|
+
init_driverState();
|
|
10136
10129
|
ENFORCEMENT_RANK = {
|
|
10137
10130
|
none: 0,
|
|
10138
10131
|
process: 1,
|
|
@@ -10922,18 +10915,10 @@ function requiredString6(value, field, maximum = 256) {
|
|
|
10922
10915
|
if (!result || result.length > maximum) invalid14(`tool payload '${field}' is invalid`);
|
|
10923
10916
|
return result;
|
|
10924
10917
|
}
|
|
10925
|
-
function stable3(value) {
|
|
10926
|
-
if (value === void 0) return "undefined";
|
|
10927
|
-
if (Array.isArray(value)) return `[${value.map(stable3).join(",")}]`;
|
|
10928
|
-
if (value !== null && typeof value === "object") {
|
|
10929
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable3(item)}`).join(",")}}`;
|
|
10930
|
-
}
|
|
10931
|
-
return JSON.stringify(value) ?? typeof value;
|
|
10932
|
-
}
|
|
10933
10918
|
async function digest3(value) {
|
|
10934
10919
|
const result = await globalThis.crypto.subtle.digest(
|
|
10935
10920
|
"SHA-256",
|
|
10936
|
-
new TextEncoder().encode(
|
|
10921
|
+
new TextEncoder().encode(canonicalDriverValue(value))
|
|
10937
10922
|
);
|
|
10938
10923
|
return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
10939
10924
|
}
|
|
@@ -11016,37 +11001,21 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11016
11001
|
if (!SHA2567.test(descriptor.schemaDigest) || descriptor.schemaDigest !== actualSchemaDigest || !descriptor.name || !descriptor.version || !descriptor.targets.length) invalid14(`tool catalog descriptor '${descriptor.name}' is invalid`);
|
|
11017
11002
|
}
|
|
11018
11003
|
return digest3(
|
|
11019
|
-
tools.map(descriptorInput).sort((left, right) =>
|
|
11004
|
+
tools.map(descriptorInput).sort((left, right) => canonicalDriverValue(left).localeCompare(canonicalDriverValue(right)))
|
|
11020
11005
|
);
|
|
11021
11006
|
})();
|
|
11022
11007
|
return catalogDigestPromise;
|
|
11023
11008
|
}
|
|
11024
11009
|
function validate(request, expectedMethod, actorKinds = ["controller"]) {
|
|
11025
|
-
|
|
11010
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
11026
11011
|
now,
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11012
|
+
fences: state.fences,
|
|
11013
|
+
expectedMethod,
|
|
11014
|
+
fenceName: "tool",
|
|
11015
|
+
actorKinds
|
|
11030
11016
|
});
|
|
11031
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
11032
|
-
throw new OrchestrationError({
|
|
11033
|
-
code: "FORBIDDEN",
|
|
11034
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
11035
|
-
retryable: false
|
|
11036
|
-
});
|
|
11037
|
-
}
|
|
11038
|
-
const epoch = request.fencingEpoch;
|
|
11039
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
11040
|
-
if (epoch < current) {
|
|
11041
|
-
throw new OrchestrationError({
|
|
11042
|
-
code: "STALE_EPOCH",
|
|
11043
|
-
message: `stale tool fencing epoch ${epoch}; current epoch is ${current}`,
|
|
11044
|
-
retryable: false
|
|
11045
|
-
});
|
|
11046
|
-
}
|
|
11047
|
-
state.fences.set(request.resource.uid, epoch);
|
|
11048
11017
|
}
|
|
11049
|
-
function
|
|
11018
|
+
function owned(collection, handle, resourceUid, kind) {
|
|
11050
11019
|
const value = collection.get(handle);
|
|
11051
11020
|
if (!value) {
|
|
11052
11021
|
throw new OrchestrationError({
|
|
@@ -11071,21 +11040,10 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11071
11040
|
return `${prefix}:${state.nextHandle++}`;
|
|
11072
11041
|
}
|
|
11073
11042
|
function idempotency(request, operation) {
|
|
11074
|
-
|
|
11075
|
-
const previous = state.idempotency.get(key);
|
|
11076
|
-
if (previous && state.idempotencyFingerprints.get(key) !== stable3(request.payload)) {
|
|
11077
|
-
throw new OrchestrationError({
|
|
11078
|
-
code: "CONFLICT",
|
|
11079
|
-
message: `tool ${operation} idempotency key was reused with different input`,
|
|
11080
|
-
retryable: false
|
|
11081
|
-
});
|
|
11082
|
-
}
|
|
11083
|
-
return previous;
|
|
11043
|
+
return findIdempotentDriverHandle(state, request, operation, "tool");
|
|
11084
11044
|
}
|
|
11085
11045
|
function remember(request, operation, handle) {
|
|
11086
|
-
|
|
11087
|
-
state.idempotency.set(key, handle);
|
|
11088
|
-
state.idempotencyFingerprints.set(key, stable3(request.payload));
|
|
11046
|
+
rememberIdempotentDriverHandle(state, request, operation, handle);
|
|
11089
11047
|
}
|
|
11090
11048
|
async function* defaultExecutor(descriptor, target, arguments_) {
|
|
11091
11049
|
yield JSON.stringify({ tool: descriptor.name, target, arguments: arguments_ });
|
|
@@ -11168,7 +11126,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11168
11126
|
if (request.payload.operationIdempotencyKey && !descriptor.supportsIdempotency) invalid14("tool does not support operation idempotency");
|
|
11169
11127
|
const previous = idempotency(request, "prepare");
|
|
11170
11128
|
if (previous) {
|
|
11171
|
-
return structuredClone(
|
|
11129
|
+
return structuredClone(owned(
|
|
11172
11130
|
state.preparations,
|
|
11173
11131
|
previous,
|
|
11174
11132
|
request.resource.uid,
|
|
@@ -11193,7 +11151,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11193
11151
|
},
|
|
11194
11152
|
async authorize(request) {
|
|
11195
11153
|
validate(request, "tool.authorize", ["controller", "admin"]);
|
|
11196
|
-
const preparation =
|
|
11154
|
+
const preparation = owned(
|
|
11197
11155
|
state.preparations,
|
|
11198
11156
|
requiredString6(request.payload, "preparationHandle"),
|
|
11199
11157
|
request.resource.uid,
|
|
@@ -11224,7 +11182,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11224
11182
|
}
|
|
11225
11183
|
const previous = idempotency(request, "authorize");
|
|
11226
11184
|
if (previous) {
|
|
11227
|
-
return structuredClone(
|
|
11185
|
+
return structuredClone(owned(
|
|
11228
11186
|
state.authorizations,
|
|
11229
11187
|
previous,
|
|
11230
11188
|
request.resource.uid,
|
|
@@ -11246,13 +11204,13 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11246
11204
|
},
|
|
11247
11205
|
async *invoke(request, invokeOptions = {}) {
|
|
11248
11206
|
validate(request, "tool.invoke");
|
|
11249
|
-
const preparation =
|
|
11207
|
+
const preparation = owned(
|
|
11250
11208
|
state.preparations,
|
|
11251
11209
|
requiredString6(request.payload, "preparationHandle"),
|
|
11252
11210
|
request.resource.uid,
|
|
11253
11211
|
"tool preparation"
|
|
11254
11212
|
);
|
|
11255
|
-
const authorization =
|
|
11213
|
+
const authorization = owned(
|
|
11256
11214
|
state.authorizations,
|
|
11257
11215
|
requiredString6(request.payload, "authorizationHandle"),
|
|
11258
11216
|
request.resource.uid,
|
|
@@ -11272,7 +11230,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11272
11230
|
}
|
|
11273
11231
|
const previous = idempotency(request, "invoke");
|
|
11274
11232
|
if (previous) {
|
|
11275
|
-
const execution2 =
|
|
11233
|
+
const execution2 = owned(
|
|
11276
11234
|
state.executions,
|
|
11277
11235
|
previous,
|
|
11278
11236
|
request.resource.uid,
|
|
@@ -11377,14 +11335,14 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11377
11335
|
},
|
|
11378
11336
|
async reconcileUnknownEffect(request) {
|
|
11379
11337
|
validate(request, "tool.reconcile-unknown", ["controller", "verifier", "admin"]);
|
|
11380
|
-
const execution =
|
|
11338
|
+
const execution = owned(
|
|
11381
11339
|
state.executions,
|
|
11382
11340
|
requiredString6(request.payload, "executionHandle"),
|
|
11383
11341
|
request.resource.uid,
|
|
11384
11342
|
"tool execution"
|
|
11385
11343
|
);
|
|
11386
11344
|
if (execution.phase !== "Unknown") return structuredClone(execution);
|
|
11387
|
-
const preparation =
|
|
11345
|
+
const preparation = owned(
|
|
11388
11346
|
state.preparations,
|
|
11389
11347
|
execution.preparationHandle,
|
|
11390
11348
|
request.resource.uid,
|
|
@@ -11410,14 +11368,14 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11410
11368
|
},
|
|
11411
11369
|
async collectEvidence(request) {
|
|
11412
11370
|
validate(request, "tool.collect-evidence", ["controller", "verifier", "admin"]);
|
|
11413
|
-
const execution =
|
|
11371
|
+
const execution = owned(
|
|
11414
11372
|
state.executions,
|
|
11415
11373
|
requiredString6(request.payload, "executionHandle"),
|
|
11416
11374
|
request.resource.uid,
|
|
11417
11375
|
"tool execution"
|
|
11418
11376
|
);
|
|
11419
11377
|
const descriptor = tool(
|
|
11420
|
-
|
|
11378
|
+
owned(
|
|
11421
11379
|
state.preparations,
|
|
11422
11380
|
execution.preparationHandle,
|
|
11423
11381
|
request.resource.uid,
|
|
@@ -11427,7 +11385,7 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11427
11385
|
if (!descriptor?.supportsEvidence) invalid14("tool does not support evidence");
|
|
11428
11386
|
const previous = idempotency(request, "evidence");
|
|
11429
11387
|
if (previous) {
|
|
11430
|
-
return structuredClone(
|
|
11388
|
+
return structuredClone(owned(
|
|
11431
11389
|
state.evidence,
|
|
11432
11390
|
previous,
|
|
11433
11391
|
request.resource.uid,
|
|
@@ -11448,14 +11406,14 @@ function createFakeToolManagementDriver(options = {}) {
|
|
|
11448
11406
|
},
|
|
11449
11407
|
async cleanup(request) {
|
|
11450
11408
|
validate(request, "tool.cleanup");
|
|
11451
|
-
const preparation =
|
|
11409
|
+
const preparation = owned(
|
|
11452
11410
|
state.preparations,
|
|
11453
11411
|
requiredString6(request.payload, "preparationHandle"),
|
|
11454
11412
|
request.resource.uid,
|
|
11455
11413
|
"tool preparation"
|
|
11456
11414
|
);
|
|
11457
11415
|
if (request.payload.executionHandle) {
|
|
11458
|
-
const execution =
|
|
11416
|
+
const execution = owned(
|
|
11459
11417
|
state.executions,
|
|
11460
11418
|
request.payload.executionHandle,
|
|
11461
11419
|
request.resource.uid,
|
|
@@ -11614,7 +11572,7 @@ function createToolManagementConformanceSuite(options) {
|
|
|
11614
11572
|
{ executionHandle: first[0].executionHandle },
|
|
11615
11573
|
"inspect-invoke"
|
|
11616
11574
|
));
|
|
11617
|
-
if (!first.at(-1)?.final ||
|
|
11575
|
+
if (!first.at(-1)?.final || canonicalDriverValue(first) !== canonicalDriverValue(replay) || execution?.phase !== "Completed") throw new Error("tool streaming or retry did not converge");
|
|
11618
11576
|
}
|
|
11619
11577
|
},
|
|
11620
11578
|
{
|
|
@@ -11786,6 +11744,7 @@ var init_toolManagement = __esm({
|
|
|
11786
11744
|
import__4 = require("ajv/dist/2020.js");
|
|
11787
11745
|
init_errors();
|
|
11788
11746
|
init_driverRequest();
|
|
11747
|
+
init_driverState();
|
|
11789
11748
|
SHA2567 = /^sha256:[a-f0-9]{64}$/;
|
|
11790
11749
|
}
|
|
11791
11750
|
});
|
|
@@ -12452,7 +12411,7 @@ function createManagedWorkerIdentityAdapter(options) {
|
|
|
12452
12411
|
fences.set(request.resource.uid, fence);
|
|
12453
12412
|
return resource;
|
|
12454
12413
|
}
|
|
12455
|
-
function
|
|
12414
|
+
function owned(values, handle, resourceUid, kind) {
|
|
12456
12415
|
const value = values.get(handle);
|
|
12457
12416
|
if (!value) {
|
|
12458
12417
|
throw new OrchestrationError({
|
|
@@ -12522,7 +12481,7 @@ function createManagedWorkerIdentityAdapter(options) {
|
|
|
12522
12481
|
"channelBinding",
|
|
12523
12482
|
"ttlMs"
|
|
12524
12483
|
]);
|
|
12525
|
-
const enrollment =
|
|
12484
|
+
const enrollment = owned(
|
|
12526
12485
|
enrollments,
|
|
12527
12486
|
requireBoundedString2(
|
|
12528
12487
|
request.payload.enrollmentHandle,
|
|
@@ -12571,7 +12530,7 @@ function createManagedWorkerIdentityAdapter(options) {
|
|
|
12571
12530
|
["format", "evidenceDigest"],
|
|
12572
12531
|
"attestation"
|
|
12573
12532
|
);
|
|
12574
|
-
const challenge =
|
|
12533
|
+
const challenge = owned(
|
|
12575
12534
|
challenges,
|
|
12576
12535
|
requireBoundedString2(
|
|
12577
12536
|
request.payload.challengeHandle,
|
|
@@ -12629,7 +12588,7 @@ function createManagedWorkerIdentityAdapter(options) {
|
|
|
12629
12588
|
"channelBinding",
|
|
12630
12589
|
"ttlMs"
|
|
12631
12590
|
]);
|
|
12632
|
-
const identity =
|
|
12591
|
+
const identity = owned(
|
|
12633
12592
|
identities,
|
|
12634
12593
|
requireBoundedString2(request.payload.identityHandle, "identityHandle"),
|
|
12635
12594
|
resource.metadata.uid,
|
|
@@ -12694,7 +12653,7 @@ function createManagedWorkerIdentityAdapter(options) {
|
|
|
12694
12653
|
"identityHandle",
|
|
12695
12654
|
"reason"
|
|
12696
12655
|
]);
|
|
12697
|
-
const identity =
|
|
12656
|
+
const identity = owned(
|
|
12698
12657
|
identities,
|
|
12699
12658
|
requireBoundedString2(request.payload.identityHandle, "identityHandle"),
|
|
12700
12659
|
resource.metadata.uid,
|
|
@@ -13244,9 +13203,13 @@ function createGatewayMediatedLLMProvider(options) {
|
|
|
13244
13203
|
const messages = Array.isArray(record2.messages) ? record2.messages : [];
|
|
13245
13204
|
const runReference = options.runRefForRequest?.(request) ?? options.runRef;
|
|
13246
13205
|
return (async function* () {
|
|
13247
|
-
const
|
|
13206
|
+
const selectedModel = options.resolveModelForRequest?.(request) ?? {
|
|
13248
13207
|
modelClassRef: options.modelClassRef,
|
|
13249
|
-
...options.modelDigest !== void 0 ? { modelDigest: options.modelDigest } : {}
|
|
13208
|
+
...options.modelDigest !== void 0 ? { modelDigest: options.modelDigest } : {}
|
|
13209
|
+
};
|
|
13210
|
+
const handle = await options.broker.issueModelAccessHandle({
|
|
13211
|
+
modelClassRef: selectedModel.modelClassRef,
|
|
13212
|
+
...selectedModel.modelDigest !== void 0 ? { modelDigest: selectedModel.modelDigest } : {},
|
|
13250
13213
|
...options.policyDigest !== void 0 ? { policyDigest: options.policyDigest } : {},
|
|
13251
13214
|
...runReference ? { runRef: runReference } : {},
|
|
13252
13215
|
...runReference && options.attempt !== void 0 ? { attempt: options.attempt } : {},
|
|
@@ -13257,12 +13220,18 @@ function createGatewayMediatedLLMProvider(options) {
|
|
|
13257
13220
|
try {
|
|
13258
13221
|
for await (const chunk of options.gateway.generate({
|
|
13259
13222
|
callId,
|
|
13260
|
-
modelClassRef:
|
|
13261
|
-
...
|
|
13223
|
+
modelClassRef: selectedModel.modelClassRef,
|
|
13224
|
+
...selectedModel.modelDigest !== void 0 ? { modelDigest: selectedModel.modelDigest } : {},
|
|
13262
13225
|
messages,
|
|
13226
|
+
...typeof record2.maxOutputTokens === "number" ? { maxOutputTokens: record2.maxOutputTokens } : typeof record2.max_tokens === "number" ? { maxOutputTokens: record2.max_tokens } : {},
|
|
13227
|
+
...typeof record2.temperature === "number" ? { temperature: record2.temperature } : {},
|
|
13228
|
+
...typeof record2.topP === "number" ? { topP: record2.topP } : {},
|
|
13229
|
+
...record2.providerOptions !== null && typeof record2.providerOptions === "object" ? {
|
|
13230
|
+
providerOptions: record2.providerOptions
|
|
13231
|
+
} : {},
|
|
13263
13232
|
accessHandle: handle.token,
|
|
13264
13233
|
...options.workerKey !== void 0 ? { workerKey: options.workerKey } : {},
|
|
13265
|
-
...record2.
|
|
13234
|
+
...record2.abortSignal ?? record2.signal ? { signal: record2.abortSignal ?? record2.signal } : {}
|
|
13266
13235
|
})) {
|
|
13267
13236
|
if (chunk.type === "delta" && chunk.delta !== void 0) {
|
|
13268
13237
|
yield chunk.delta;
|
|
@@ -13299,14 +13268,6 @@ function createFakeModelManagementState() {
|
|
|
13299
13268
|
nextHandle: 1
|
|
13300
13269
|
};
|
|
13301
13270
|
}
|
|
13302
|
-
function stable4(value) {
|
|
13303
|
-
if (value === void 0) return "undefined";
|
|
13304
|
-
if (Array.isArray(value)) return `[${value.map(stable4).join(",")}]`;
|
|
13305
|
-
if (value !== null && typeof value === "object") {
|
|
13306
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable4(item)}`).join(",")}}`;
|
|
13307
|
-
}
|
|
13308
|
-
return JSON.stringify(value) ?? typeof value;
|
|
13309
|
-
}
|
|
13310
13271
|
function invalid17(message) {
|
|
13311
13272
|
throw new OrchestrationError({ code: "INVALID", message, retryable: false });
|
|
13312
13273
|
}
|
|
@@ -13365,31 +13326,15 @@ function createFakeModelManagementDriver(options = {}) {
|
|
|
13365
13326
|
};
|
|
13366
13327
|
const active = /* @__PURE__ */ new Map();
|
|
13367
13328
|
function validate(request, method) {
|
|
13368
|
-
|
|
13329
|
+
return assertFencedDriverRequestEnvelope(request, {
|
|
13369
13330
|
now,
|
|
13331
|
+
fences: state.fences,
|
|
13370
13332
|
requireRun: true,
|
|
13371
|
-
|
|
13372
|
-
|
|
13373
|
-
|
|
13333
|
+
expectedMethod: method,
|
|
13334
|
+
fenceName: "model",
|
|
13335
|
+
actorKinds: ["controller", "admin"],
|
|
13336
|
+
forbiddenMessage: () => "model provider access requires a controller or admin actor"
|
|
13374
13337
|
});
|
|
13375
|
-
if (request.actor.kind !== "controller" && request.actor.kind !== "admin") {
|
|
13376
|
-
throw new OrchestrationError({
|
|
13377
|
-
code: "FORBIDDEN",
|
|
13378
|
-
message: "model provider access requires a controller or admin actor",
|
|
13379
|
-
retryable: false
|
|
13380
|
-
});
|
|
13381
|
-
}
|
|
13382
|
-
const fence = request.fencingEpoch;
|
|
13383
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
13384
|
-
if (fence < current) {
|
|
13385
|
-
throw new OrchestrationError({
|
|
13386
|
-
code: "STALE_EPOCH",
|
|
13387
|
-
message: `stale model fencing epoch ${fence}; current epoch is ${current}`,
|
|
13388
|
-
retryable: false
|
|
13389
|
-
});
|
|
13390
|
-
}
|
|
13391
|
-
state.fences.set(request.resource.uid, fence);
|
|
13392
|
-
return fence;
|
|
13393
13338
|
}
|
|
13394
13339
|
function modelFor(payload) {
|
|
13395
13340
|
assertOnlyFields2(
|
|
@@ -13516,7 +13461,7 @@ function createFakeModelManagementDriver(options = {}) {
|
|
|
13516
13461
|
const fence = validate(request, "model.generate");
|
|
13517
13462
|
const model = modelFor(request.payload);
|
|
13518
13463
|
await authorize(request, model);
|
|
13519
|
-
const inputFingerprint =
|
|
13464
|
+
const inputFingerprint = canonicalDriverValue({
|
|
13520
13465
|
payload: request.payload,
|
|
13521
13466
|
run: request.run,
|
|
13522
13467
|
session: request.session,
|
|
@@ -13755,7 +13700,9 @@ function createModelManagementConformanceSuite(options) {
|
|
|
13755
13700
|
);
|
|
13756
13701
|
const first = await collect(driver, request);
|
|
13757
13702
|
const second = await collect(driver, request);
|
|
13758
|
-
if (
|
|
13703
|
+
if (canonicalDriverValue(first) !== canonicalDriverValue(second)) {
|
|
13704
|
+
throw new Error("model generation did not replay");
|
|
13705
|
+
}
|
|
13759
13706
|
if (first.at(-1)?.type !== "done") throw new Error("model stream did not complete");
|
|
13760
13707
|
let driftRejected = false;
|
|
13761
13708
|
try {
|
|
@@ -13871,6 +13818,7 @@ var init_modelManagement = __esm({
|
|
|
13871
13818
|
"use strict";
|
|
13872
13819
|
init_errors();
|
|
13873
13820
|
init_driverRequest();
|
|
13821
|
+
init_driverState();
|
|
13874
13822
|
init_modelProviderDriver();
|
|
13875
13823
|
SHA2568 = /^sha256:[a-f0-9]{64}$/;
|
|
13876
13824
|
}
|
|
@@ -13893,16 +13841,8 @@ function requiredString7(value, field) {
|
|
|
13893
13841
|
if (value === null || typeof value !== "object" || typeof value[field] !== "string" || !value[field]) invalid18(`policy payload '${field}' is required`);
|
|
13894
13842
|
return value[field];
|
|
13895
13843
|
}
|
|
13896
|
-
function stable5(value) {
|
|
13897
|
-
if (value === void 0) return "undefined";
|
|
13898
|
-
if (Array.isArray(value)) return `[${value.map(stable5).join(",")}]`;
|
|
13899
|
-
if (value !== null && typeof value === "object") {
|
|
13900
|
-
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stable5(item)}`).join(",")}}`;
|
|
13901
|
-
}
|
|
13902
|
-
return JSON.stringify(value) ?? typeof value;
|
|
13903
|
-
}
|
|
13904
13844
|
async function digest6(value) {
|
|
13905
|
-
const bytes = new TextEncoder().encode(
|
|
13845
|
+
const bytes = new TextEncoder().encode(canonicalDriverValue(value));
|
|
13906
13846
|
const result = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
13907
13847
|
return `sha256:${[...new Uint8Array(result)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
13908
13848
|
}
|
|
@@ -13923,34 +13863,18 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
13923
13863
|
]
|
|
13924
13864
|
);
|
|
13925
13865
|
function validate(request, expectedMethod, actorKinds) {
|
|
13926
|
-
|
|
13866
|
+
assertFencedDriverRequestEnvelope(request, {
|
|
13927
13867
|
now,
|
|
13928
|
-
|
|
13929
|
-
|
|
13930
|
-
|
|
13868
|
+
fences: state.fences,
|
|
13869
|
+
expectedMethod,
|
|
13870
|
+
fenceName: "policy",
|
|
13871
|
+
actorKinds
|
|
13931
13872
|
});
|
|
13932
|
-
if (!actorKinds.includes(request.actor.kind)) {
|
|
13933
|
-
throw new OrchestrationError({
|
|
13934
|
-
code: "FORBIDDEN",
|
|
13935
|
-
message: `actor kind '${request.actor.kind}' cannot call ${expectedMethod}`,
|
|
13936
|
-
retryable: false
|
|
13937
|
-
});
|
|
13938
|
-
}
|
|
13939
|
-
const epoch = request.fencingEpoch;
|
|
13940
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
13941
|
-
if (epoch < current) {
|
|
13942
|
-
throw new OrchestrationError({
|
|
13943
|
-
code: "STALE_EPOCH",
|
|
13944
|
-
message: `stale policy fencing epoch ${epoch}; current epoch is ${current}`,
|
|
13945
|
-
retryable: false
|
|
13946
|
-
});
|
|
13947
|
-
}
|
|
13948
|
-
state.fences.set(request.resource.uid, epoch);
|
|
13949
13873
|
}
|
|
13950
13874
|
function assertPolicyDigest(value) {
|
|
13951
13875
|
if (!SHA2569.test(value)) invalid18("policyDigest must be a canonical sha256 digest");
|
|
13952
13876
|
}
|
|
13953
|
-
function
|
|
13877
|
+
function owned(handle, resourceUid) {
|
|
13954
13878
|
const decision = state.decisions.get(handle);
|
|
13955
13879
|
if (!decision) {
|
|
13956
13880
|
throw new OrchestrationError({
|
|
@@ -13970,18 +13894,14 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
13970
13894
|
}
|
|
13971
13895
|
async function decide(request, operation, kind, outcome, policyDigest, reasons, obligations = [], approval) {
|
|
13972
13896
|
assertPolicyDigest(policyDigest);
|
|
13973
|
-
const
|
|
13974
|
-
|
|
13975
|
-
|
|
13897
|
+
const previousHandle = findIdempotentDriverHandle(
|
|
13898
|
+
state,
|
|
13899
|
+
request,
|
|
13900
|
+
operation,
|
|
13901
|
+
"policy"
|
|
13902
|
+
);
|
|
13976
13903
|
if (previousHandle) {
|
|
13977
|
-
|
|
13978
|
-
throw new OrchestrationError({
|
|
13979
|
-
code: "CONFLICT",
|
|
13980
|
-
message: `policy ${operation} idempotency key was reused with different input`,
|
|
13981
|
-
retryable: false
|
|
13982
|
-
});
|
|
13983
|
-
}
|
|
13984
|
-
return structuredClone(owned2(previousHandle, request.resource.uid));
|
|
13904
|
+
return structuredClone(owned(previousHandle, request.resource.uid));
|
|
13985
13905
|
}
|
|
13986
13906
|
const decision = {
|
|
13987
13907
|
decisionHandle: `policy-decision:${state.nextHandle++}`,
|
|
@@ -13997,8 +13917,12 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
13997
13917
|
approval
|
|
13998
13918
|
};
|
|
13999
13919
|
state.decisions.set(decision.decisionHandle, decision);
|
|
14000
|
-
|
|
14001
|
-
|
|
13920
|
+
rememberIdempotentDriverHandle(
|
|
13921
|
+
state,
|
|
13922
|
+
request,
|
|
13923
|
+
operation,
|
|
13924
|
+
decision.decisionHandle
|
|
13925
|
+
);
|
|
14002
13926
|
return structuredClone(decision);
|
|
14003
13927
|
}
|
|
14004
13928
|
return {
|
|
@@ -14071,7 +13995,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
14071
13995
|
}
|
|
14072
13996
|
let approval;
|
|
14073
13997
|
if (request.payload.approvalDecisionHandle) {
|
|
14074
|
-
approval =
|
|
13998
|
+
approval = owned(request.payload.approvalDecisionHandle, request.resource.uid);
|
|
14075
13999
|
}
|
|
14076
14000
|
const needsApproval = effect !== "read";
|
|
14077
14001
|
const approvalValid = !needsApproval || approval?.kind === "approval" && approval.outcome === "allow" && approval.policyDigest === policyDigest && approval.approval?.subjectDigest === operationDigest && Date.parse(approval.approval.expiresAt) > now().getTime();
|
|
@@ -14119,7 +14043,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
14119
14043
|
if (!["allow", "deny"].includes(request.payload.outcome)) {
|
|
14120
14044
|
invalid18("approval outcome must be allow or deny");
|
|
14121
14045
|
}
|
|
14122
|
-
const decision =
|
|
14046
|
+
const decision = owned(handle, request.resource.uid);
|
|
14123
14047
|
if (decision.kind !== "approval") invalid18("decision is not an approval");
|
|
14124
14048
|
if (decision.approval && Date.parse(decision.approval.expiresAt) <= now().getTime()) {
|
|
14125
14049
|
decision.outcome = "deny";
|
|
@@ -14182,7 +14106,7 @@ function createFakePolicyApprovalManagementDriver(options = {}) {
|
|
|
14182
14106
|
"verifier",
|
|
14183
14107
|
"admin"
|
|
14184
14108
|
]);
|
|
14185
|
-
const decision =
|
|
14109
|
+
const decision = owned(
|
|
14186
14110
|
requiredString7(request.payload, "decisionHandle"),
|
|
14187
14111
|
request.resource.uid
|
|
14188
14112
|
);
|
|
@@ -14415,6 +14339,7 @@ var init_policyApprovalManagement = __esm({
|
|
|
14415
14339
|
"use strict";
|
|
14416
14340
|
init_errors();
|
|
14417
14341
|
init_driverRequest();
|
|
14342
|
+
init_driverState();
|
|
14418
14343
|
SHA2569 = /^sha256:[a-f0-9]{64}$/;
|
|
14419
14344
|
TRUST_RANK3 = {
|
|
14420
14345
|
quarantine: 0,
|
|
@@ -14433,6 +14358,7 @@ function createFakeStorageManagementState() {
|
|
|
14433
14358
|
stages: /* @__PURE__ */ new Map(),
|
|
14434
14359
|
publications: /* @__PURE__ */ new Map(),
|
|
14435
14360
|
idempotency: /* @__PURE__ */ new Map(),
|
|
14361
|
+
idempotencyFingerprints: /* @__PURE__ */ new Map(),
|
|
14436
14362
|
fences: /* @__PURE__ */ new Map(),
|
|
14437
14363
|
nextHandle: 1
|
|
14438
14364
|
};
|
|
@@ -14460,32 +14386,18 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14460
14386
|
const state = options.state ?? createFakeStorageManagementState();
|
|
14461
14387
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
14462
14388
|
function validate(request, expectedMethod) {
|
|
14463
|
-
|
|
14389
|
+
return assertFencedDriverRequestEnvelope(request, {
|
|
14464
14390
|
now,
|
|
14465
|
-
|
|
14466
|
-
|
|
14467
|
-
|
|
14391
|
+
fences: state.fences,
|
|
14392
|
+
expectedMethod,
|
|
14393
|
+
fenceName: "storage"
|
|
14468
14394
|
});
|
|
14469
|
-
const fence = request.fencingEpoch;
|
|
14470
|
-
const current = state.fences.get(request.resource.uid) ?? 0;
|
|
14471
|
-
if (fence < current) {
|
|
14472
|
-
throw new OrchestrationError({
|
|
14473
|
-
code: "STALE_EPOCH",
|
|
14474
|
-
message: `stale storage fencing epoch ${fence}; current epoch is ${current}`,
|
|
14475
|
-
retryable: false
|
|
14476
|
-
});
|
|
14477
|
-
}
|
|
14478
|
-
state.fences.set(request.resource.uid, fence);
|
|
14479
|
-
return fence;
|
|
14480
14395
|
}
|
|
14481
14396
|
function nextHandle(prefix) {
|
|
14482
14397
|
const handle = `${prefix}:${state.nextHandle}`;
|
|
14483
14398
|
state.nextHandle += 1;
|
|
14484
14399
|
return handle;
|
|
14485
14400
|
}
|
|
14486
|
-
function operationKey2(request, operation) {
|
|
14487
|
-
return `${request.resource.uid}:${operation}:${request.idempotencyKey}`;
|
|
14488
|
-
}
|
|
14489
14401
|
function getVolume(handle, resourceUid) {
|
|
14490
14402
|
const record2 = state.volumes.get(handle);
|
|
14491
14403
|
if (!record2 || record2.volume.phase === "Deleted") {
|
|
@@ -14504,27 +14416,8 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14504
14416
|
}
|
|
14505
14417
|
return record2;
|
|
14506
14418
|
}
|
|
14507
|
-
function owned2(collection, handle, resourceUid, kind) {
|
|
14508
|
-
const value = collection.get(handle);
|
|
14509
|
-
if (!value) {
|
|
14510
|
-
throw new OrchestrationError({
|
|
14511
|
-
code: "NOT_FOUND",
|
|
14512
|
-
message: `${kind} handle '${handle}' was not found`,
|
|
14513
|
-
retryable: false
|
|
14514
|
-
});
|
|
14515
|
-
}
|
|
14516
|
-
if (value.resourceUid !== resourceUid) {
|
|
14517
|
-
throw new OrchestrationError({
|
|
14518
|
-
code: "FORBIDDEN",
|
|
14519
|
-
message: `${kind} handle '${handle}' belongs to another resource`,
|
|
14520
|
-
retryable: false
|
|
14521
|
-
});
|
|
14522
|
-
}
|
|
14523
|
-
return value;
|
|
14524
|
-
}
|
|
14525
14419
|
function createVolume(request, capacityBytes, accessMode, replicaCount, operation) {
|
|
14526
|
-
const
|
|
14527
|
-
const existing = state.idempotency.get(key);
|
|
14420
|
+
const existing = findIdempotentDriverHandle(state, request, operation, "storage");
|
|
14528
14421
|
if (existing) return getVolume(existing, request.resource.uid).volume;
|
|
14529
14422
|
const volume = {
|
|
14530
14423
|
volumeHandle: nextHandle("volume"),
|
|
@@ -14535,7 +14428,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14535
14428
|
phase: "Available"
|
|
14536
14429
|
};
|
|
14537
14430
|
state.volumes.set(volume.volumeHandle, { volume, desiredReplicas: replicaCount });
|
|
14538
|
-
state
|
|
14431
|
+
rememberIdempotentDriverHandle(state, request, operation, volume.volumeHandle);
|
|
14539
14432
|
return volume;
|
|
14540
14433
|
}
|
|
14541
14434
|
return {
|
|
@@ -14591,9 +14484,10 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14591
14484
|
validate(request, "storage.snapshot");
|
|
14592
14485
|
const volumeHandle = requiredString8(request.payload, "volumeHandle");
|
|
14593
14486
|
getVolume(volumeHandle, request.resource.uid);
|
|
14594
|
-
const
|
|
14595
|
-
|
|
14596
|
-
|
|
14487
|
+
const existing = findIdempotentDriverHandle(state, request, "snapshot", "storage");
|
|
14488
|
+
if (existing) {
|
|
14489
|
+
return getOwnedDriverValue(state.snapshots, existing, request.resource.uid, "snapshot");
|
|
14490
|
+
}
|
|
14597
14491
|
const snapshot = {
|
|
14598
14492
|
snapshotHandle: nextHandle("snapshot"),
|
|
14599
14493
|
volumeHandle,
|
|
@@ -14601,12 +14495,12 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14601
14495
|
createdAt: now().toISOString()
|
|
14602
14496
|
};
|
|
14603
14497
|
state.snapshots.set(snapshot.snapshotHandle, snapshot);
|
|
14604
|
-
state
|
|
14498
|
+
rememberIdempotentDriverHandle(state, request, "snapshot", snapshot.snapshotHandle);
|
|
14605
14499
|
return snapshot;
|
|
14606
14500
|
},
|
|
14607
14501
|
async restoreSnapshot(request) {
|
|
14608
14502
|
validate(request, "storage.restore");
|
|
14609
|
-
const snapshot =
|
|
14503
|
+
const snapshot = getOwnedDriverValue(
|
|
14610
14504
|
state.snapshots,
|
|
14611
14505
|
requiredString8(request.payload, "snapshotHandle"),
|
|
14612
14506
|
request.resource.uid,
|
|
@@ -14669,9 +14563,10 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14669
14563
|
validate(request, "storage.backup");
|
|
14670
14564
|
const volumeHandle = requiredString8(request.payload, "volumeHandle");
|
|
14671
14565
|
getVolume(volumeHandle, request.resource.uid);
|
|
14672
|
-
const
|
|
14673
|
-
|
|
14674
|
-
|
|
14566
|
+
const existing = findIdempotentDriverHandle(state, request, "backup", "storage");
|
|
14567
|
+
if (existing) {
|
|
14568
|
+
return getOwnedDriverValue(state.backups, existing, request.resource.uid, "backup");
|
|
14569
|
+
}
|
|
14675
14570
|
const backup = {
|
|
14676
14571
|
backupHandle: nextHandle("backup"),
|
|
14677
14572
|
volumeHandle,
|
|
@@ -14679,7 +14574,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14679
14574
|
createdAt: now().toISOString()
|
|
14680
14575
|
};
|
|
14681
14576
|
state.backups.set(backup.backupHandle, backup);
|
|
14682
|
-
state
|
|
14577
|
+
rememberIdempotentDriverHandle(state, request, "backup", backup.backupHandle);
|
|
14683
14578
|
return backup;
|
|
14684
14579
|
},
|
|
14685
14580
|
async stage(request) {
|
|
@@ -14687,9 +14582,10 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14687
14582
|
const volumeHandle = requiredString8(request.payload, "volumeHandle");
|
|
14688
14583
|
getVolume(volumeHandle, request.resource.uid);
|
|
14689
14584
|
const nodeId = requiredString8(request.payload, "nodeId");
|
|
14690
|
-
const
|
|
14691
|
-
|
|
14692
|
-
|
|
14585
|
+
const existing = findIdempotentDriverHandle(state, request, "stage", "storage");
|
|
14586
|
+
if (existing) {
|
|
14587
|
+
return getOwnedDriverValue(state.stages, existing, request.resource.uid, "stage");
|
|
14588
|
+
}
|
|
14693
14589
|
const stage = {
|
|
14694
14590
|
stageHandle: nextHandle("stage"),
|
|
14695
14591
|
volumeHandle,
|
|
@@ -14697,12 +14593,12 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14697
14593
|
nodeId
|
|
14698
14594
|
};
|
|
14699
14595
|
state.stages.set(stage.stageHandle, stage);
|
|
14700
|
-
state
|
|
14596
|
+
rememberIdempotentDriverHandle(state, request, "stage", stage.stageHandle);
|
|
14701
14597
|
return stage;
|
|
14702
14598
|
},
|
|
14703
14599
|
async publish(request) {
|
|
14704
14600
|
validate(request, "storage.publish");
|
|
14705
|
-
const stage =
|
|
14601
|
+
const stage = getOwnedDriverValue(
|
|
14706
14602
|
state.stages,
|
|
14707
14603
|
requiredString8(request.payload, "stageHandle"),
|
|
14708
14604
|
request.resource.uid,
|
|
@@ -14711,10 +14607,14 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14711
14607
|
getVolume(stage.volumeHandle, request.resource.uid);
|
|
14712
14608
|
const workloadUid = requiredString8(request.payload, "workloadUid");
|
|
14713
14609
|
if (typeof request.payload.readOnly !== "boolean") invalid19("publish readOnly is required");
|
|
14714
|
-
const
|
|
14715
|
-
const existing = state.idempotency.get(key);
|
|
14610
|
+
const existing = findIdempotentDriverHandle(state, request, "publish", "storage");
|
|
14716
14611
|
if (existing) {
|
|
14717
|
-
return
|
|
14612
|
+
return getOwnedDriverValue(
|
|
14613
|
+
state.publications,
|
|
14614
|
+
existing,
|
|
14615
|
+
request.resource.uid,
|
|
14616
|
+
"publication"
|
|
14617
|
+
);
|
|
14718
14618
|
}
|
|
14719
14619
|
const publication = {
|
|
14720
14620
|
publishHandle: nextHandle("publication"),
|
|
@@ -14724,7 +14624,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14724
14624
|
readOnly: request.payload.readOnly
|
|
14725
14625
|
};
|
|
14726
14626
|
state.publications.set(publication.publishHandle, publication);
|
|
14727
|
-
state
|
|
14627
|
+
rememberIdempotentDriverHandle(state, request, "publish", publication.publishHandle);
|
|
14728
14628
|
return publication;
|
|
14729
14629
|
},
|
|
14730
14630
|
async unpublish(request) {
|
|
@@ -14732,7 +14632,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14732
14632
|
const handle = requiredString8(request.payload, "publishHandle");
|
|
14733
14633
|
const publication = state.publications.get(handle);
|
|
14734
14634
|
if (!publication) return;
|
|
14735
|
-
|
|
14635
|
+
getOwnedDriverValue(state.publications, handle, request.resource.uid, "publication");
|
|
14736
14636
|
state.publications.delete(handle);
|
|
14737
14637
|
},
|
|
14738
14638
|
async unstage(request) {
|
|
@@ -14740,7 +14640,7 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14740
14640
|
const handle = requiredString8(request.payload, "stageHandle");
|
|
14741
14641
|
const stage = state.stages.get(handle);
|
|
14742
14642
|
if (!stage) return;
|
|
14743
|
-
|
|
14643
|
+
getOwnedDriverValue(state.stages, handle, request.resource.uid, "stage");
|
|
14744
14644
|
if ([...state.publications.values()].some(
|
|
14745
14645
|
(publication) => publication.stageHandle === handle
|
|
14746
14646
|
)) {
|
|
@@ -14754,13 +14654,13 @@ function createFakeStorageManagementDriver(options = {}) {
|
|
|
14754
14654
|
},
|
|
14755
14655
|
async getStats(request) {
|
|
14756
14656
|
validate(request, "storage.stats");
|
|
14757
|
-
const publication =
|
|
14657
|
+
const publication = getOwnedDriverValue(
|
|
14758
14658
|
state.publications,
|
|
14759
14659
|
requiredString8(request.payload, "publishHandle"),
|
|
14760
14660
|
request.resource.uid,
|
|
14761
14661
|
"publication"
|
|
14762
14662
|
);
|
|
14763
|
-
const stage =
|
|
14663
|
+
const stage = getOwnedDriverValue(
|
|
14764
14664
|
state.stages,
|
|
14765
14665
|
publication.stageHandle,
|
|
14766
14666
|
request.resource.uid,
|
|
@@ -14962,7 +14862,7 @@ var init_storageManagement = __esm({
|
|
|
14962
14862
|
"src/orchestration/drivers/storageManagement.ts"() {
|
|
14963
14863
|
"use strict";
|
|
14964
14864
|
init_errors();
|
|
14965
|
-
|
|
14865
|
+
init_driverState();
|
|
14966
14866
|
}
|
|
14967
14867
|
});
|
|
14968
14868
|
|
|
@@ -17745,6 +17645,9 @@ function resolveMaxIterations(context) {
|
|
|
17745
17645
|
const configured = context.agentToolLoop?.maxIterations;
|
|
17746
17646
|
return configured != null && configured > 0 ? configured : DEFAULT_MAX_ITERATIONS;
|
|
17747
17647
|
}
|
|
17648
|
+
function resolveLocalNodeId(context, input) {
|
|
17649
|
+
return context.localNodeId?.trim() || input?.userMessage?.originNodeId?.trim() || "local";
|
|
17650
|
+
}
|
|
17748
17651
|
function pluginToolCallSignature(calls) {
|
|
17749
17652
|
return calls.map((call) => `${call.toolId}:${JSON.stringify(call.parameters)}`).join("|");
|
|
17750
17653
|
}
|
|
@@ -17766,7 +17669,7 @@ async function blockRepeatedPluginToolCalls(context, input, state, calls, hookCo
|
|
|
17766
17669
|
const toolMessage = createChatMessage({
|
|
17767
17670
|
messageId: `${input.conversationId}:t:doom-loop:${state.iteration}:${Date.now().toString(36)}`,
|
|
17768
17671
|
conversationId: input.conversationId,
|
|
17769
|
-
originNodeId:
|
|
17672
|
+
originNodeId: resolveLocalNodeId(context, input),
|
|
17770
17673
|
lamportClock,
|
|
17771
17674
|
role: "tool",
|
|
17772
17675
|
parts: [{
|
|
@@ -17811,11 +17714,12 @@ async function startAgentToolLoopTurn(context, input, state) {
|
|
|
17811
17714
|
input.conversationId
|
|
17812
17715
|
);
|
|
17813
17716
|
const hostUserMessage = input.userMessage;
|
|
17717
|
+
const localNodeId = resolveLocalNodeId(context, input);
|
|
17814
17718
|
const userMessage = context.normalizeMessage?.({
|
|
17815
17719
|
...hostUserMessage,
|
|
17816
17720
|
messageId: hostUserMessage?.messageId ?? `${input.conversationId}:${now.toString(36)}`,
|
|
17817
17721
|
conversationId: input.conversationId,
|
|
17818
|
-
originNodeId: hostUserMessage?.originNodeId ??
|
|
17722
|
+
originNodeId: hostUserMessage?.originNodeId ?? localNodeId,
|
|
17819
17723
|
timestamp: hostUserMessage?.timestamp ?? now,
|
|
17820
17724
|
lamportClock: hostUserMessage?.lamportClock ?? lamportClock,
|
|
17821
17725
|
role: "user",
|
|
@@ -17824,7 +17728,7 @@ async function startAgentToolLoopTurn(context, input, state) {
|
|
|
17824
17728
|
...hostUserMessage,
|
|
17825
17729
|
messageId: hostUserMessage?.messageId ?? `${input.conversationId}:${now.toString(36)}`,
|
|
17826
17730
|
conversationId: input.conversationId,
|
|
17827
|
-
originNodeId: hostUserMessage?.originNodeId ??
|
|
17731
|
+
originNodeId: hostUserMessage?.originNodeId ?? localNodeId,
|
|
17828
17732
|
timestamp: hostUserMessage?.timestamp ?? now,
|
|
17829
17733
|
lamportClock: hostUserMessage?.lamportClock ?? lamportClock,
|
|
17830
17734
|
role: "user",
|
|
@@ -17935,10 +17839,11 @@ async function* runAgentToolLoopIteration(context, input, state) {
|
|
|
17935
17839
|
context.storage,
|
|
17936
17840
|
input.conversationId
|
|
17937
17841
|
);
|
|
17842
|
+
const localNodeId = resolveLocalNodeId(context, input);
|
|
17938
17843
|
const buildAssistantMessage = (content) => context.normalizeMessage?.({
|
|
17939
17844
|
messageId: assistantMessageId,
|
|
17940
17845
|
conversationId: input.conversationId,
|
|
17941
|
-
originNodeId:
|
|
17846
|
+
originNodeId: localNodeId,
|
|
17942
17847
|
timestamp: Date.now(),
|
|
17943
17848
|
lamportClock: assistantLamportClock,
|
|
17944
17849
|
role: "assistant",
|
|
@@ -17946,7 +17851,7 @@ async function* runAgentToolLoopIteration(context, input, state) {
|
|
|
17946
17851
|
}) ?? {
|
|
17947
17852
|
messageId: assistantMessageId,
|
|
17948
17853
|
conversationId: input.conversationId,
|
|
17949
|
-
originNodeId:
|
|
17854
|
+
originNodeId: localNodeId,
|
|
17950
17855
|
timestamp: Date.now(),
|
|
17951
17856
|
lamportClock: assistantLamportClock,
|
|
17952
17857
|
role: "assistant",
|
|
@@ -18164,6 +18069,44 @@ var init_directRunner = __esm({
|
|
|
18164
18069
|
}
|
|
18165
18070
|
});
|
|
18166
18071
|
|
|
18072
|
+
// src/loopAPI/scriptRuntime.ts
|
|
18073
|
+
function messageStep(message) {
|
|
18074
|
+
return { type: "message", data: message };
|
|
18075
|
+
}
|
|
18076
|
+
function createScriptStepEmitter(emittedSteps, onEmit) {
|
|
18077
|
+
return (step) => {
|
|
18078
|
+
emittedSteps.push(step);
|
|
18079
|
+
onEmit?.(step);
|
|
18080
|
+
};
|
|
18081
|
+
}
|
|
18082
|
+
function isAsyncIterable3(value) {
|
|
18083
|
+
return Boolean(value && typeof value === "object" && Symbol.asyncIterator in value);
|
|
18084
|
+
}
|
|
18085
|
+
async function* drainEmittedSteps(steps) {
|
|
18086
|
+
while (steps.length > 0) {
|
|
18087
|
+
const step = steps.shift();
|
|
18088
|
+
if (step) yield step;
|
|
18089
|
+
}
|
|
18090
|
+
}
|
|
18091
|
+
async function* yieldScriptResult(result, emittedSteps) {
|
|
18092
|
+
yield* drainEmittedSteps(emittedSteps);
|
|
18093
|
+
if (isAsyncIterable3(result)) {
|
|
18094
|
+
yield* result;
|
|
18095
|
+
yield* drainEmittedSteps(emittedSteps);
|
|
18096
|
+
} else if (typeof result === "string") {
|
|
18097
|
+
yield messageStep(result);
|
|
18098
|
+
} else if (Array.isArray(result)) {
|
|
18099
|
+
yield* result;
|
|
18100
|
+
} else if (result) {
|
|
18101
|
+
yield result;
|
|
18102
|
+
}
|
|
18103
|
+
}
|
|
18104
|
+
var init_scriptRuntime2 = __esm({
|
|
18105
|
+
"src/loopAPI/scriptRuntime.ts"() {
|
|
18106
|
+
"use strict";
|
|
18107
|
+
}
|
|
18108
|
+
});
|
|
18109
|
+
|
|
18167
18110
|
// src/loops/agent-tool-loop/builtinLoopSources.ts
|
|
18168
18111
|
function getBuiltinAgentToolLoopSource(id) {
|
|
18169
18112
|
return builtinAgentToolLoopSources[id];
|
|
@@ -18382,6 +18325,18 @@ var init_scriptValidation = __esm({
|
|
|
18382
18325
|
});
|
|
18383
18326
|
|
|
18384
18327
|
// src/loopAPI/scriptLoader.ts
|
|
18328
|
+
function createBuiltinAgentLoopScriptLoader(loaderOptions) {
|
|
18329
|
+
let builtinDigestsRegistered;
|
|
18330
|
+
return async (scriptReference, policy = {}) => {
|
|
18331
|
+
builtinDigestsRegistered ??= registerBuiltinScriptSources(loaderOptions.sources);
|
|
18332
|
+
await builtinDigestsRegistered;
|
|
18333
|
+
return loadAgentLoopScript(scriptReference, {
|
|
18334
|
+
...policy,
|
|
18335
|
+
getBuiltinScriptSource: loaderOptions.getBuiltinScriptSource,
|
|
18336
|
+
scriptType: loaderOptions.scriptType
|
|
18337
|
+
});
|
|
18338
|
+
};
|
|
18339
|
+
}
|
|
18385
18340
|
function isLoadedScriptFunction(value) {
|
|
18386
18341
|
return typeof value === "function";
|
|
18387
18342
|
}
|
|
@@ -18563,40 +18518,24 @@ var init_scriptLoader = __esm({
|
|
|
18563
18518
|
});
|
|
18564
18519
|
|
|
18565
18520
|
// src/loopAPI/agent-tool-loop/scriptLoader.ts
|
|
18566
|
-
function ensureBuiltinDigestsRegistered() {
|
|
18567
|
-
builtinDigestsRegistered ??= registerBuiltinScriptSources(builtinAgentToolLoopSources);
|
|
18568
|
-
return builtinDigestsRegistered;
|
|
18569
|
-
}
|
|
18570
18521
|
async function loadAgentToolLoopScript(scriptReference, options = {}) {
|
|
18571
|
-
|
|
18572
|
-
return loadAgentLoopScript(scriptReference, {
|
|
18573
|
-
...options,
|
|
18574
|
-
getBuiltinScriptSource: getBuiltinAgentToolLoopSource,
|
|
18575
|
-
scriptType: "AgentToolLoop script"
|
|
18576
|
-
});
|
|
18522
|
+
return loadScript(scriptReference, options);
|
|
18577
18523
|
}
|
|
18578
|
-
var
|
|
18524
|
+
var loadScript;
|
|
18579
18525
|
var init_scriptLoader2 = __esm({
|
|
18580
18526
|
"src/loopAPI/agent-tool-loop/scriptLoader.ts"() {
|
|
18581
18527
|
"use strict";
|
|
18582
18528
|
init_builtinLoopSources2();
|
|
18583
18529
|
init_scriptLoader();
|
|
18530
|
+
loadScript = createBuiltinAgentLoopScriptLoader({
|
|
18531
|
+
sources: builtinAgentToolLoopSources,
|
|
18532
|
+
getBuiltinScriptSource: getBuiltinAgentToolLoopSource,
|
|
18533
|
+
scriptType: "AgentToolLoop script"
|
|
18534
|
+
});
|
|
18584
18535
|
}
|
|
18585
18536
|
});
|
|
18586
18537
|
|
|
18587
18538
|
// src/loopAPI/agent-tool-loop/scriptRunner.ts
|
|
18588
|
-
function isAsyncIterable3(value) {
|
|
18589
|
-
return Boolean(value && typeof value === "object" && Symbol.asyncIterator in value);
|
|
18590
|
-
}
|
|
18591
|
-
function messageStep(message) {
|
|
18592
|
-
return { type: "message", data: message };
|
|
18593
|
-
}
|
|
18594
|
-
async function* drainEmittedSteps(steps) {
|
|
18595
|
-
while (steps.length > 0) {
|
|
18596
|
-
const step = steps.shift();
|
|
18597
|
-
if (step) yield step;
|
|
18598
|
-
}
|
|
18599
|
-
}
|
|
18600
18539
|
function asAgentToolLoopContext(rawContext) {
|
|
18601
18540
|
return rawContext;
|
|
18602
18541
|
}
|
|
@@ -18608,10 +18547,7 @@ async function resolveAgentToolLoopScript(context) {
|
|
|
18608
18547
|
return loadAgentToolLoopScript(scriptReference, context.scriptPolicy);
|
|
18609
18548
|
}
|
|
18610
18549
|
function createAgentToolLoopScriptContext(input, context, emittedSteps) {
|
|
18611
|
-
const emit = (
|
|
18612
|
-
emittedSteps.push(step);
|
|
18613
|
-
context.runtime?.emit?.(step);
|
|
18614
|
-
};
|
|
18550
|
+
const emit = createScriptStepEmitter(emittedSteps, context.runtime?.emit);
|
|
18615
18551
|
return {
|
|
18616
18552
|
input,
|
|
18617
18553
|
context,
|
|
@@ -18634,21 +18570,12 @@ function createAgentToolLoopScriptContext(input, context, emittedSteps) {
|
|
|
18634
18570
|
async function* runAgentToolLoopScript(script, input, context) {
|
|
18635
18571
|
const emittedSteps = [];
|
|
18636
18572
|
const result = await script(createAgentToolLoopScriptContext(input, context, emittedSteps));
|
|
18637
|
-
yield*
|
|
18638
|
-
if (isAsyncIterable3(result)) {
|
|
18639
|
-
yield* result;
|
|
18640
|
-
yield* drainEmittedSteps(emittedSteps);
|
|
18641
|
-
} else if (typeof result === "string") {
|
|
18642
|
-
yield messageStep(result);
|
|
18643
|
-
} else if (Array.isArray(result)) {
|
|
18644
|
-
yield* result;
|
|
18645
|
-
} else if (result) {
|
|
18646
|
-
yield result;
|
|
18647
|
-
}
|
|
18573
|
+
yield* yieldScriptResult(result, emittedSteps);
|
|
18648
18574
|
}
|
|
18649
18575
|
var init_scriptRunner = __esm({
|
|
18650
18576
|
"src/loopAPI/agent-tool-loop/scriptRunner.ts"() {
|
|
18651
18577
|
"use strict";
|
|
18578
|
+
init_scriptRuntime2();
|
|
18652
18579
|
init_scriptLoader2();
|
|
18653
18580
|
init_turnPrimitives();
|
|
18654
18581
|
}
|
|
@@ -23898,6 +23825,16 @@ function createWorkerProtocolGateway(options) {
|
|
|
23898
23825
|
const rateLimit = options.maxRequestsPerMinute ?? DEFAULT_RATE_PER_MINUTE2;
|
|
23899
23826
|
const maxResponseBytes = options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
|
|
23900
23827
|
const requestLog = /* @__PURE__ */ new Map();
|
|
23828
|
+
let nextRequestLogSweepAt = 0;
|
|
23829
|
+
function pruneInactiveRequestLogs(windowStart, receivedAtMs) {
|
|
23830
|
+
if (receivedAtMs < nextRequestLogSweepAt) return;
|
|
23831
|
+
for (const [sessionName, timestamps] of requestLog) {
|
|
23832
|
+
if (timestamps.length === 0 || timestamps[timestamps.length - 1] < windowStart) {
|
|
23833
|
+
requestLog.delete(sessionName);
|
|
23834
|
+
}
|
|
23835
|
+
}
|
|
23836
|
+
nextRequestLogSweepAt = receivedAtMs + 6e4;
|
|
23837
|
+
}
|
|
23901
23838
|
async function audit(request, accepted, receivedAt, code) {
|
|
23902
23839
|
try {
|
|
23903
23840
|
await options.onAudit?.({
|
|
@@ -23956,6 +23893,7 @@ function createWorkerProtocolGateway(options) {
|
|
|
23956
23893
|
throw protocolError("CONFLICT", "worker request sequence or nonce was already consumed");
|
|
23957
23894
|
}
|
|
23958
23895
|
const windowStart = received.getTime() - 6e4;
|
|
23896
|
+
pruneInactiveRequestLogs(windowStart, received.getTime());
|
|
23959
23897
|
const log = (requestLog.get(session.name) ?? []).filter((time) => time >= windowStart);
|
|
23960
23898
|
if (log.length >= rateLimit) {
|
|
23961
23899
|
throw new OrchestrationError({
|
|
@@ -26137,34 +26075,24 @@ var init_orchestration2 = __esm({
|
|
|
26137
26075
|
});
|
|
26138
26076
|
|
|
26139
26077
|
// src/loopAPI/agent-agent-loop/scriptLoader.ts
|
|
26140
|
-
function ensureBuiltinDigestsRegistered2() {
|
|
26141
|
-
builtinDigestsRegistered2 ??= registerBuiltinScriptSources(builtinAgentAgentLoopSources);
|
|
26142
|
-
return builtinDigestsRegistered2;
|
|
26143
|
-
}
|
|
26144
26078
|
async function loadAgentAgentLoopScript(scriptReference, options = {}) {
|
|
26145
|
-
|
|
26146
|
-
return loadAgentLoopScript(scriptReference, {
|
|
26147
|
-
...options,
|
|
26148
|
-
getBuiltinScriptSource: getBuiltinAgentAgentLoopSource,
|
|
26149
|
-
scriptType: "AgentAgentLoop script"
|
|
26150
|
-
});
|
|
26079
|
+
return loadScript2(scriptReference, options);
|
|
26151
26080
|
}
|
|
26152
|
-
var
|
|
26081
|
+
var loadScript2;
|
|
26153
26082
|
var init_scriptLoader3 = __esm({
|
|
26154
26083
|
"src/loopAPI/agent-agent-loop/scriptLoader.ts"() {
|
|
26155
26084
|
"use strict";
|
|
26156
26085
|
init_builtinLoopSources();
|
|
26157
26086
|
init_scriptLoader();
|
|
26087
|
+
loadScript2 = createBuiltinAgentLoopScriptLoader({
|
|
26088
|
+
sources: builtinAgentAgentLoopSources,
|
|
26089
|
+
getBuiltinScriptSource: getBuiltinAgentAgentLoopSource,
|
|
26090
|
+
scriptType: "AgentAgentLoop script"
|
|
26091
|
+
});
|
|
26158
26092
|
}
|
|
26159
26093
|
});
|
|
26160
26094
|
|
|
26161
26095
|
// src/loopAPI/agent-agent-loop/loop.ts
|
|
26162
|
-
function isAsyncIterable4(value) {
|
|
26163
|
-
return Boolean(value && typeof value === "object" && Symbol.asyncIterator in value);
|
|
26164
|
-
}
|
|
26165
|
-
function messageStep2(message) {
|
|
26166
|
-
return { type: "message", data: message };
|
|
26167
|
-
}
|
|
26168
26096
|
function stepText(step) {
|
|
26169
26097
|
if (step.type !== "message") return void 0;
|
|
26170
26098
|
if (typeof step.data === "string") return step.data;
|
|
@@ -26218,10 +26146,7 @@ function createScriptArguments(input, context, emittedSteps) {
|
|
|
26218
26146
|
if (key === "agents") return agentEntries;
|
|
26219
26147
|
return readProfileAgentEntries(context.profile, key) ?? [];
|
|
26220
26148
|
};
|
|
26221
|
-
const emit = (
|
|
26222
|
-
emittedSteps.push(step);
|
|
26223
|
-
context.runtime?.emit?.(step);
|
|
26224
|
-
};
|
|
26149
|
+
const emit = createScriptStepEmitter(emittedSteps, context.runtime?.emit);
|
|
26225
26150
|
const log = (event, data) => {
|
|
26226
26151
|
context.runtime?.log?.(event, data);
|
|
26227
26152
|
};
|
|
@@ -26319,11 +26244,11 @@ function createScriptArguments(input, context, emittedSteps) {
|
|
|
26319
26244
|
runParallel: (batchInput) => runBatch(batchInput, "parallel"),
|
|
26320
26245
|
formatAgentResults,
|
|
26321
26246
|
finishAgentResults: (result, options) => {
|
|
26322
|
-
emit(
|
|
26247
|
+
emit(messageStep(formatAgentResults(result, options)));
|
|
26323
26248
|
},
|
|
26324
26249
|
emit,
|
|
26325
26250
|
finish: (message) => {
|
|
26326
|
-
emit(typeof message === "string" ?
|
|
26251
|
+
emit(typeof message === "string" ? messageStep(message) : message);
|
|
26327
26252
|
},
|
|
26328
26253
|
isCancelled,
|
|
26329
26254
|
log,
|
|
@@ -26336,27 +26261,11 @@ function createScriptArguments(input, context, emittedSteps) {
|
|
|
26336
26261
|
loadCheckpoint: context.runtime?.loadCheckpoint ?? (async () => void 0)
|
|
26337
26262
|
};
|
|
26338
26263
|
}
|
|
26339
|
-
async function* drainEmittedSteps2(steps) {
|
|
26340
|
-
while (steps.length > 0) {
|
|
26341
|
-
const step = steps.shift();
|
|
26342
|
-
if (step) yield step;
|
|
26343
|
-
}
|
|
26344
|
-
}
|
|
26345
26264
|
async function* runScript(script, input, context) {
|
|
26346
26265
|
const emittedSteps = [];
|
|
26347
26266
|
const scriptArguments = createScriptArguments(input, context, emittedSteps);
|
|
26348
26267
|
const result = await script(scriptArguments);
|
|
26349
|
-
yield*
|
|
26350
|
-
if (isAsyncIterable4(result)) {
|
|
26351
|
-
yield* result;
|
|
26352
|
-
yield* drainEmittedSteps2(emittedSteps);
|
|
26353
|
-
} else if (typeof result === "string") {
|
|
26354
|
-
yield messageStep2(result);
|
|
26355
|
-
} else if (Array.isArray(result)) {
|
|
26356
|
-
yield* result;
|
|
26357
|
-
} else if (result) {
|
|
26358
|
-
yield result;
|
|
26359
|
-
}
|
|
26268
|
+
yield* yieldScriptResult(result, emittedSteps);
|
|
26360
26269
|
}
|
|
26361
26270
|
function asAgentAgentContext(context) {
|
|
26362
26271
|
return context;
|
|
@@ -26419,6 +26328,7 @@ var init_loop2 = __esm({
|
|
|
26419
26328
|
"src/loopAPI/agent-agent-loop/loop.ts"() {
|
|
26420
26329
|
"use strict";
|
|
26421
26330
|
init_orchestration2();
|
|
26331
|
+
init_scriptRuntime2();
|
|
26422
26332
|
init_scriptLoader3();
|
|
26423
26333
|
LOOP_ID = "agent-agent-loop";
|
|
26424
26334
|
LOOP_NAME = "AgentAgent Loop";
|
|
@@ -26875,6 +26785,7 @@ __export(src_exports, {
|
|
|
26875
26785
|
mcpForwardImpl: () => mcpForwardImpl,
|
|
26876
26786
|
mergeAgentToolsIntoFrameworkConfig: () => mergeAgentToolsIntoFrameworkConfig,
|
|
26877
26787
|
mergePermissionSets: () => mergePermissionSets,
|
|
26788
|
+
modelClassNameForSpec: () => modelClassNameForSpec,
|
|
26878
26789
|
negotiateCapabilities: () => negotiateCapabilities,
|
|
26879
26790
|
normalizeScript: () => normalizeScript,
|
|
26880
26791
|
onApprovalRequest: () => onApprovalRequest,
|
|
@@ -27264,7 +27175,8 @@ var ChatSyncEngine = class {
|
|
|
27264
27175
|
}
|
|
27265
27176
|
}
|
|
27266
27177
|
/**
|
|
27267
|
-
* Anti-entropy
|
|
27178
|
+
* Anti-entropy 的定期对账入口。`syncOnce` 本身已经遍历全部已知会话,
|
|
27179
|
+
* 并在 metadata 对账后向各 peer 拉取缺失消息,因此这里无需第二次重复拉取。
|
|
27268
27180
|
*/
|
|
27269
27181
|
async antiEntropyOnce() {
|
|
27270
27182
|
await this.syncOnce();
|
|
@@ -30202,6 +30114,18 @@ function createPeerDriverRpcHandler(handlers) {
|
|
|
30202
30114
|
}
|
|
30203
30115
|
|
|
30204
30116
|
// src/device-network/syncCloudDevices.ts
|
|
30117
|
+
function warnAboutCloudKeyRotation(logger3, record2) {
|
|
30118
|
+
const message = "[device-network] Cloud directory rotated a cloud-account device public key";
|
|
30119
|
+
const details = {
|
|
30120
|
+
peerId: record2.peerId,
|
|
30121
|
+
accountId: record2.accountId
|
|
30122
|
+
};
|
|
30123
|
+
if (logger3) {
|
|
30124
|
+
logger3.warn(message, details);
|
|
30125
|
+
return;
|
|
30126
|
+
}
|
|
30127
|
+
console.warn(message, details);
|
|
30128
|
+
}
|
|
30205
30129
|
async function syncCloudDevices(input) {
|
|
30206
30130
|
const cloudDevices = await input.cloudClient.listDevices();
|
|
30207
30131
|
const existingRecords = await input.trustStore.loadTrustedDevices();
|
|
@@ -30219,6 +30143,9 @@ async function syncCloudDevices(input) {
|
|
|
30219
30143
|
for (const cloudDevice of activeCloudDevices) {
|
|
30220
30144
|
const existing = existingByPeerId.get(cloudDevice.peerId);
|
|
30221
30145
|
if (existing?.trustMode === "local-pairing") continue;
|
|
30146
|
+
if (existing?.trustMode === "cloud-account" && existing.publicKeyMultibase !== cloudDevice.publicKeyMultibase) {
|
|
30147
|
+
warnAboutCloudKeyRotation(input.logger, existing);
|
|
30148
|
+
}
|
|
30222
30149
|
const record2 = {
|
|
30223
30150
|
peerId: cloudDevice.peerId,
|
|
30224
30151
|
publicKeyMultibase: cloudDevice.publicKeyMultibase,
|
|
@@ -32160,6 +32087,7 @@ function getToolDefinition(toolId) {
|
|
|
32160
32087
|
mcpForwardImpl,
|
|
32161
32088
|
mergeAgentToolsIntoFrameworkConfig,
|
|
32162
32089
|
mergePermissionSets,
|
|
32090
|
+
modelClassNameForSpec,
|
|
32163
32091
|
negotiateCapabilities,
|
|
32164
32092
|
normalizeScript,
|
|
32165
32093
|
onApprovalRequest,
|