@tangle-network/agent-runtime 0.295.0 → 0.295.2
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/{activation-DbcZXadv.js → activation-CkulncPi.js} +2 -2
- package/dist/{activation-DbcZXadv.js.map → activation-CkulncPi.js.map} +1 -1
- package/dist/{activation-DYCFEI_o.d.ts → activation-DZMqUGrJ.d.ts} +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/{coordination-driver-Do3g6Qif.js → coordination-driver-B_rF6bAa.js} +2 -2
- package/dist/{coordination-driver-Do3g6Qif.js.map → coordination-driver-B_rF6bAa.js.map} +1 -1
- package/dist/{delegate-CCaU8M4O.js → delegate-_h6a-sZR.js} +2 -2
- package/dist/{delegate-CCaU8M4O.js.map → delegate-_h6a-sZR.js.map} +1 -1
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +2 -2
- package/dist/{graph-dNmpMnzl.js → graph-CN9gCxcw.js} +4 -4
- package/dist/{graph-dNmpMnzl.js.map → graph-CN9gCxcw.js.map} +1 -1
- package/dist/{improvement-cycle-D4hoGlAe.js → improvement-cycle-EMHB3l51.js} +3 -3
- package/dist/{improvement-cycle-D4hoGlAe.js.map → improvement-cycle-EMHB3l51.js.map} +1 -1
- package/dist/{index-nREMiWJP.d.ts → index-CfMzoFhW.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -7
- package/dist/intelligence.d.ts +2 -2
- package/dist/intelligence.js +4 -4
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +8 -8
- package/dist/{loop-runner-bin-cf1xZPC2.d.ts → loop-runner-bin-BnxKYphD.d.ts} +2 -2
- package/dist/{loop-runner-bin-DIf0bbQM.js → loop-runner-bin-C6-NQ7bS.js} +3 -3
- package/dist/{loop-runner-bin-DIf0bbQM.js.map → loop-runner-bin-C6-NQ7bS.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +4 -4
- package/dist/{provision-supervisor-B_3hmSz6.js → provision-supervisor-BJ6-8M97.js} +3 -3
- package/dist/{provision-supervisor-B_3hmSz6.js.map → provision-supervisor-BJ6-8M97.js.map} +1 -1
- package/dist/{runtime-CXKCdGTg.js → runtime-7HtdodVO.js} +75 -59
- package/dist/runtime-7HtdodVO.js.map +1 -0
- package/dist/{search-method-B0VM-hHV.js → search-method-rGfFP5yr.js} +2 -2
- package/dist/{search-method-B0VM-hHV.js.map → search-method-rGfFP5yr.js.map} +1 -1
- package/dist/{server--GKA8T0f.js → server-B-DKa3MD.js} +3 -3
- package/dist/{server--GKA8T0f.js.map → server-B-DKa3MD.js.map} +1 -1
- package/dist/{stream-agent-turn-CwqktoXW.d.ts → stream-agent-turn-D6lDcAYs.d.ts} +8 -2
- package/dist/{supervise-BwfqpTVR.js → supervise-CIyd8B3f.js} +3 -3
- package/dist/{supervise-BwfqpTVR.js.map → supervise-CIyd8B3f.js.map} +1 -1
- package/dist/{supervisor-Da7iAPSw.js → supervisor-DnoT3-_F.js} +246 -228
- package/dist/supervisor-DnoT3-_F.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +12 -12
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/package.json +1 -1
- package/dist/runtime-CXKCdGTg.js.map +0 -1
- package/dist/supervisor-Da7iAPSw.js.map +0 -1
|
@@ -6732,13 +6732,255 @@ async function runAbortable(act, signal, fallback) {
|
|
|
6732
6732
|
});
|
|
6733
6733
|
}
|
|
6734
6734
|
//#endregion
|
|
6735
|
+
//#region src/runtime/supervise/worker-slots.ts
|
|
6736
|
+
/**
|
|
6737
|
+
* Worker slots: the one bound on how many spawned agents work at the same time.
|
|
6738
|
+
*
|
|
6739
|
+
* Every scope of a supervised tree draws from one allocator. A host that runs several trees in one
|
|
6740
|
+
* process can pass the same allocator to each of them, and the bound then holds across all of them.
|
|
6741
|
+
*
|
|
6742
|
+
* A spawn past the bound is never refused. It keeps its reserved budget slice and waits in a queue,
|
|
6743
|
+
* and it starts when a slot frees. The queue releases the deepest spawn first and then the oldest,
|
|
6744
|
+
* so a subtree that is already paid for finishes before the tree grows wider.
|
|
6745
|
+
*
|
|
6746
|
+
* A slot counts a working agent: a spawned agent that runs with no running child of its own. A
|
|
6747
|
+
* manager whose children are all running is waiting on them, so its first running child takes over
|
|
6748
|
+
* the manager's slot and the manager takes it back when its last running child ends. This makes
|
|
6749
|
+
* nested waits deadlock-free: a manager can always run one child on its own slot, so a queued subtree
|
|
6750
|
+
* always keeps a path to completion, whatever the bound and however deep the tree.
|
|
6751
|
+
*
|
|
6752
|
+
* The bound therefore limits working agents, not environments. The environments alive at one time
|
|
6753
|
+
* can exceed it by the number of managers that have a running child. The conserved budget pool and
|
|
6754
|
+
* the deadline bound the total work; this allocator only bounds how much of it runs at once.
|
|
6755
|
+
*
|
|
6756
|
+
* @experimental
|
|
6757
|
+
*/
|
|
6758
|
+
const allocatorStates = /* @__PURE__ */ new WeakMap();
|
|
6759
|
+
/**
|
|
6760
|
+
* Create a worker-slot allocator. `max` omitted, `0`, or negative leaves concurrency bounded by the
|
|
6761
|
+
* budget alone, and every spawn starts at once. Pass the returned allocator as `workerSlots` to each
|
|
6762
|
+
* run that should share one bound.
|
|
6763
|
+
*/
|
|
6764
|
+
function createWorkerSlots(max) {
|
|
6765
|
+
const bound = normalizeWorkerSlotBound(max);
|
|
6766
|
+
const state = {
|
|
6767
|
+
max: bound,
|
|
6768
|
+
working: 0,
|
|
6769
|
+
order: 0,
|
|
6770
|
+
waiters: []
|
|
6771
|
+
};
|
|
6772
|
+
const slots = Object.freeze({
|
|
6773
|
+
max: bound,
|
|
6774
|
+
get working() {
|
|
6775
|
+
return state.working;
|
|
6776
|
+
},
|
|
6777
|
+
get queued() {
|
|
6778
|
+
return state.waiters.length;
|
|
6779
|
+
}
|
|
6780
|
+
});
|
|
6781
|
+
allocatorStates.set(slots, state);
|
|
6782
|
+
return slots;
|
|
6783
|
+
}
|
|
6784
|
+
/** Accept a bound or an allocator; a number creates an allocator for one tree. */
|
|
6785
|
+
function resolveWorkerSlots(value) {
|
|
6786
|
+
if (value === void 0 || typeof value === "number") return createWorkerSlots(value);
|
|
6787
|
+
if (!allocatorStates.has(value)) throw new ValidationError$1("workerSlots must be a number or an allocator from createWorkerSlots");
|
|
6788
|
+
return value;
|
|
6789
|
+
}
|
|
6790
|
+
/** @internal Open the group of one scope's children. */
|
|
6791
|
+
function openSlotGroup(slots, owner) {
|
|
6792
|
+
const state = allocatorStates.get(slots);
|
|
6793
|
+
if (state === void 0) throw new ValidationError$1("openSlotGroup: allocator was not created by createWorkerSlots");
|
|
6794
|
+
const issued = owner === void 0 ? void 0 : deferredPermits.get(owner)?.() ?? owner;
|
|
6795
|
+
const ownerState = issued === void 0 ? void 0 : permitStates.get(issued);
|
|
6796
|
+
if (owner !== void 0 && ownerState === void 0) throw new ValidationError$1("openSlotGroup: owner permit was not issued by this allocator");
|
|
6797
|
+
const group = {
|
|
6798
|
+
owner: ownerState,
|
|
6799
|
+
running: 0,
|
|
6800
|
+
queued: 0
|
|
6801
|
+
};
|
|
6802
|
+
if (ownerState !== void 0) {
|
|
6803
|
+
if (ownerState.children !== void 0) throw new ValidationError$1("openSlotGroup: a permit owns at most one group of children");
|
|
6804
|
+
ownerState.children = group;
|
|
6805
|
+
}
|
|
6806
|
+
return {
|
|
6807
|
+
acquire: (depth, options) => acquire(state, group, depth, options?.force === true),
|
|
6808
|
+
get running() {
|
|
6809
|
+
return group.running;
|
|
6810
|
+
},
|
|
6811
|
+
get queued() {
|
|
6812
|
+
return group.queued;
|
|
6813
|
+
}
|
|
6814
|
+
};
|
|
6815
|
+
}
|
|
6816
|
+
const permitStates = /* @__PURE__ */ new WeakMap();
|
|
6817
|
+
/** Each deferred permit's reader of the permit it acquired, once it has acquired one. */
|
|
6818
|
+
const deferredPermits = /* @__PURE__ */ new WeakMap();
|
|
6819
|
+
/**
|
|
6820
|
+
* @internal A slot requested only once `after` resolves. A spawn that waits for budget takes no
|
|
6821
|
+
* slot while it waits, so it cannot hold a slot that the work it waits on needs. `ready` rejects
|
|
6822
|
+
* when `after` does; `release` before then withdraws the request.
|
|
6823
|
+
*/
|
|
6824
|
+
function deferSlot(after, acquire) {
|
|
6825
|
+
let inner;
|
|
6826
|
+
let released = false;
|
|
6827
|
+
const ready = after.then(() => {
|
|
6828
|
+
if (released) return;
|
|
6829
|
+
inner = acquire();
|
|
6830
|
+
return inner.ready;
|
|
6831
|
+
});
|
|
6832
|
+
ready.catch(() => void 0);
|
|
6833
|
+
const handle = {
|
|
6834
|
+
ready,
|
|
6835
|
+
get granted() {
|
|
6836
|
+
return inner?.granted ?? false;
|
|
6837
|
+
},
|
|
6838
|
+
release() {
|
|
6839
|
+
if (released) return;
|
|
6840
|
+
released = true;
|
|
6841
|
+
inner?.release();
|
|
6842
|
+
}
|
|
6843
|
+
};
|
|
6844
|
+
deferredPermits.set(handle, () => inner);
|
|
6845
|
+
return handle;
|
|
6846
|
+
}
|
|
6847
|
+
function acquire(state, group, depth, force) {
|
|
6848
|
+
if (!Number.isSafeInteger(depth) || depth < 0) throw new ValidationError$1(`worker slots: depth must be a non-negative integer, got ${depth}`);
|
|
6849
|
+
const permit = {
|
|
6850
|
+
group,
|
|
6851
|
+
granted: false,
|
|
6852
|
+
released: false,
|
|
6853
|
+
counted: false
|
|
6854
|
+
};
|
|
6855
|
+
let resolveReady;
|
|
6856
|
+
const ready = new Promise((resolve) => {
|
|
6857
|
+
resolveReady = resolve;
|
|
6858
|
+
});
|
|
6859
|
+
const grant = () => {
|
|
6860
|
+
grantPermit(state, permit);
|
|
6861
|
+
resolveReady();
|
|
6862
|
+
};
|
|
6863
|
+
if (force || costOf(group) === 0 || hasCapacity(state)) grant();
|
|
6864
|
+
else {
|
|
6865
|
+
group.queued += 1;
|
|
6866
|
+
const waiter = {
|
|
6867
|
+
permit,
|
|
6868
|
+
depth,
|
|
6869
|
+
order: state.order++,
|
|
6870
|
+
grant
|
|
6871
|
+
};
|
|
6872
|
+
state.waiters.push(waiter);
|
|
6873
|
+
}
|
|
6874
|
+
const handle = {
|
|
6875
|
+
ready,
|
|
6876
|
+
get granted() {
|
|
6877
|
+
return permit.granted;
|
|
6878
|
+
},
|
|
6879
|
+
release() {
|
|
6880
|
+
if (permit.released) return;
|
|
6881
|
+
permit.released = true;
|
|
6882
|
+
if (!permit.granted) {
|
|
6883
|
+
withdraw(state, permit);
|
|
6884
|
+
return;
|
|
6885
|
+
}
|
|
6886
|
+
releasePermit(state, permit);
|
|
6887
|
+
pump(state);
|
|
6888
|
+
}
|
|
6889
|
+
};
|
|
6890
|
+
permitStates.set(handle, permit);
|
|
6891
|
+
return handle;
|
|
6892
|
+
}
|
|
6893
|
+
/** A child of `group` adds a working unit unless its manager is working on its own slot now, in
|
|
6894
|
+
* which case the child takes that slot over. */
|
|
6895
|
+
function costOf(group) {
|
|
6896
|
+
const owner = group.owner;
|
|
6897
|
+
return owner?.granted && !owner.released && owner.counted ? 0 : 1;
|
|
6898
|
+
}
|
|
6899
|
+
function hasCapacity(state) {
|
|
6900
|
+
return state.max === void 0 || state.working < state.max;
|
|
6901
|
+
}
|
|
6902
|
+
function grantPermit(state, permit) {
|
|
6903
|
+
const group = permit.group;
|
|
6904
|
+
if (costOf(group) === 0) group.owner.counted = false;
|
|
6905
|
+
else state.working += 1;
|
|
6906
|
+
permit.granted = true;
|
|
6907
|
+
permit.counted = true;
|
|
6908
|
+
group.running += 1;
|
|
6909
|
+
}
|
|
6910
|
+
function releasePermit(state, permit) {
|
|
6911
|
+
if ((permit.children?.running ?? 0) > 0) return;
|
|
6912
|
+
const group = permit.group;
|
|
6913
|
+
group.running -= 1;
|
|
6914
|
+
if (group.running < 0) throw new ValidationError$1("worker slots: a group released more than it ran");
|
|
6915
|
+
if (!permit.counted) return;
|
|
6916
|
+
permit.counted = false;
|
|
6917
|
+
const owner = group.owner;
|
|
6918
|
+
if (group.running === 0 && owner !== void 0 && owner.granted) {
|
|
6919
|
+
owner.counted = true;
|
|
6920
|
+
if (owner.released) releasePermit(state, owner);
|
|
6921
|
+
return;
|
|
6922
|
+
}
|
|
6923
|
+
state.working -= 1;
|
|
6924
|
+
if (state.working < 0) throw new ValidationError$1("worker slots: released more than granted");
|
|
6925
|
+
}
|
|
6926
|
+
function withdraw(state, permit) {
|
|
6927
|
+
const index = state.waiters.findIndex((waiter) => waiter.permit === permit);
|
|
6928
|
+
if (index === -1) return;
|
|
6929
|
+
state.waiters.splice(index, 1);
|
|
6930
|
+
permit.group.queued -= 1;
|
|
6931
|
+
}
|
|
6932
|
+
/** Grant every waiter that can run: any waiter whose manager is working on its own slot, and then
|
|
6933
|
+
* the deepest and oldest waiters while capacity remains. */
|
|
6934
|
+
function pump(state) {
|
|
6935
|
+
for (;;) {
|
|
6936
|
+
let chosen;
|
|
6937
|
+
for (let index = 0; index < state.waiters.length; index++) {
|
|
6938
|
+
const waiter = state.waiters[index];
|
|
6939
|
+
if (costOf(waiter.permit.group) === 0) {
|
|
6940
|
+
chosen = index;
|
|
6941
|
+
break;
|
|
6942
|
+
}
|
|
6943
|
+
if (!hasCapacity(state)) continue;
|
|
6944
|
+
const best = chosen === void 0 ? void 0 : state.waiters[chosen];
|
|
6945
|
+
if (best === void 0 || waiter.depth > best.depth || waiter.depth === best.depth && waiter.order < best.order) chosen = index;
|
|
6946
|
+
}
|
|
6947
|
+
if (chosen === void 0) return;
|
|
6948
|
+
const [waiter] = state.waiters.splice(chosen, 1);
|
|
6949
|
+
waiter.permit.group.queued -= 1;
|
|
6950
|
+
waiter.grant();
|
|
6951
|
+
}
|
|
6952
|
+
}
|
|
6953
|
+
function normalizeWorkerSlotBound(value) {
|
|
6954
|
+
if (value === void 0 || value <= 0) return void 0;
|
|
6955
|
+
if (!Number.isSafeInteger(value)) throw new ValidationError$1(`workerSlots must be a positive safe integer, or 0 or less for no bound, got ${String(value)}`);
|
|
6956
|
+
return value;
|
|
6957
|
+
}
|
|
6958
|
+
//#endregion
|
|
6735
6959
|
//#region src/runtime/provider-workspace-retention.ts
|
|
6736
6960
|
/** Validate the executable retention port at the create boundary. */
|
|
6737
6961
|
function assertProviderWorkspaceRetentionPort(port, context) {
|
|
6738
6962
|
if (!Number.isSafeInteger(port.timeoutMs) || port.timeoutMs <= 0) throw new ValidationError$1(`${context}: workspaceRetention.timeoutMs must be a positive safe integer`);
|
|
6963
|
+
if (port.maxConcurrentCaptures !== void 0 && (!Number.isSafeInteger(port.maxConcurrentCaptures) || port.maxConcurrentCaptures <= 0)) throw new ValidationError$1(`${context}: workspaceRetention.maxConcurrentCaptures must be a positive safe integer`);
|
|
6739
6964
|
if (port.artifacts === null || typeof port.artifacts?.read !== "function") throw new ValidationError$1(`${context}: workspaceRetention.artifacts.read is required`);
|
|
6740
6965
|
if (typeof port.capture !== "function") throw new ValidationError$1(`${context}: workspaceRetention.capture is required`);
|
|
6741
6966
|
}
|
|
6967
|
+
const captureGroups = /* @__PURE__ */ new WeakMap();
|
|
6968
|
+
async function withCaptureSlot(port, signal, capture) {
|
|
6969
|
+
if (port.maxConcurrentCaptures === void 0) return capture();
|
|
6970
|
+
let group = captureGroups.get(port);
|
|
6971
|
+
if (group === void 0) {
|
|
6972
|
+
group = openSlotGroup(createWorkerSlots(port.maxConcurrentCaptures));
|
|
6973
|
+
captureGroups.set(port, group);
|
|
6974
|
+
}
|
|
6975
|
+
const permit = group.acquire(0);
|
|
6976
|
+
try {
|
|
6977
|
+
await runAbortable(() => permit.ready, signal, "provider workspace retention queue aborted");
|
|
6978
|
+
signal.throwIfAborted();
|
|
6979
|
+
return await capture();
|
|
6980
|
+
} finally {
|
|
6981
|
+
permit.release();
|
|
6982
|
+
}
|
|
6983
|
+
}
|
|
6742
6984
|
/** Capture, require durable refs, and verify every returned manifest/archive byte. */
|
|
6743
6985
|
async function captureProviderWorkspaceSnapshot(port, context) {
|
|
6744
6986
|
assertProviderWorkspaceRetentionPort(port, "provider workspace retention");
|
|
@@ -6747,7 +6989,7 @@ async function captureProviderWorkspaceSnapshot(port, context) {
|
|
|
6747
6989
|
const controller = new AbortController();
|
|
6748
6990
|
const clearDeadline = armDeadlineTimer(port.timeoutMs, () => controller.abort(/* @__PURE__ */ new Error(`provider workspace retention timed out after ${port.timeoutMs}ms`)), true);
|
|
6749
6991
|
try {
|
|
6750
|
-
return await runAbortable(async () => {
|
|
6992
|
+
return await runAbortable(() => withCaptureSlot(port, controller.signal, async () => {
|
|
6751
6993
|
const result = detachedSnapshot(await port.capture({
|
|
6752
6994
|
...context,
|
|
6753
6995
|
...controlRef === void 0 ? {} : { controlRef: Object.freeze({ ...controlRef }) },
|
|
@@ -6807,7 +7049,7 @@ async function captureProviderWorkspaceSnapshot(port, context) {
|
|
|
6807
7049
|
coverageComplete,
|
|
6808
7050
|
...coverageComplete ? {} : { incompleteReason: `provider workspace retention coverage incomplete: ${coverageGaps.join("; ")}` }
|
|
6809
7051
|
};
|
|
6810
|
-
}, controller.signal, `provider workspace retention timed out after ${port.timeoutMs}ms`);
|
|
7052
|
+
}), controller.signal, `provider workspace retention timed out after ${port.timeoutMs}ms`);
|
|
6811
7053
|
} finally {
|
|
6812
7054
|
clearDeadline();
|
|
6813
7055
|
}
|
|
@@ -23184,230 +23426,6 @@ function defaultSleep$1(ms, signal) {
|
|
|
23184
23426
|
return sleep(ms, signal);
|
|
23185
23427
|
}
|
|
23186
23428
|
//#endregion
|
|
23187
|
-
//#region src/runtime/supervise/worker-slots.ts
|
|
23188
|
-
/**
|
|
23189
|
-
* Worker slots: the one bound on how many spawned agents work at the same time.
|
|
23190
|
-
*
|
|
23191
|
-
* Every scope of a supervised tree draws from one allocator. A host that runs several trees in one
|
|
23192
|
-
* process can pass the same allocator to each of them, and the bound then holds across all of them.
|
|
23193
|
-
*
|
|
23194
|
-
* A spawn past the bound is never refused. It keeps its reserved budget slice and waits in a queue,
|
|
23195
|
-
* and it starts when a slot frees. The queue releases the deepest spawn first and then the oldest,
|
|
23196
|
-
* so a subtree that is already paid for finishes before the tree grows wider.
|
|
23197
|
-
*
|
|
23198
|
-
* A slot counts a working agent: a spawned agent that runs with no running child of its own. A
|
|
23199
|
-
* manager whose children are all running is waiting on them, so its first running child takes over
|
|
23200
|
-
* the manager's slot and the manager takes it back when its last running child ends. This makes
|
|
23201
|
-
* nested waits deadlock-free: a manager can always run one child on its own slot, so a queued subtree
|
|
23202
|
-
* always keeps a path to completion, whatever the bound and however deep the tree.
|
|
23203
|
-
*
|
|
23204
|
-
* The bound therefore limits working agents, not environments. The environments alive at one time
|
|
23205
|
-
* can exceed it by the number of managers that have a running child. The conserved budget pool and
|
|
23206
|
-
* the deadline bound the total work; this allocator only bounds how much of it runs at once.
|
|
23207
|
-
*
|
|
23208
|
-
* @experimental
|
|
23209
|
-
*/
|
|
23210
|
-
const allocatorStates = /* @__PURE__ */ new WeakMap();
|
|
23211
|
-
/**
|
|
23212
|
-
* Create a worker-slot allocator. `max` omitted, `0`, or negative leaves concurrency bounded by the
|
|
23213
|
-
* budget alone, and every spawn starts at once. Pass the returned allocator as `workerSlots` to each
|
|
23214
|
-
* run that should share one bound.
|
|
23215
|
-
*/
|
|
23216
|
-
function createWorkerSlots(max) {
|
|
23217
|
-
const bound = normalizeWorkerSlotBound(max);
|
|
23218
|
-
const state = {
|
|
23219
|
-
max: bound,
|
|
23220
|
-
working: 0,
|
|
23221
|
-
order: 0,
|
|
23222
|
-
waiters: []
|
|
23223
|
-
};
|
|
23224
|
-
const slots = Object.freeze({
|
|
23225
|
-
max: bound,
|
|
23226
|
-
get working() {
|
|
23227
|
-
return state.working;
|
|
23228
|
-
},
|
|
23229
|
-
get queued() {
|
|
23230
|
-
return state.waiters.length;
|
|
23231
|
-
}
|
|
23232
|
-
});
|
|
23233
|
-
allocatorStates.set(slots, state);
|
|
23234
|
-
return slots;
|
|
23235
|
-
}
|
|
23236
|
-
/** Accept a bound or an allocator; a number creates an allocator for one tree. */
|
|
23237
|
-
function resolveWorkerSlots(value) {
|
|
23238
|
-
if (value === void 0 || typeof value === "number") return createWorkerSlots(value);
|
|
23239
|
-
if (!allocatorStates.has(value)) throw new ValidationError$1("workerSlots must be a number or an allocator from createWorkerSlots");
|
|
23240
|
-
return value;
|
|
23241
|
-
}
|
|
23242
|
-
/** @internal Open the group of one scope's children. */
|
|
23243
|
-
function openSlotGroup(slots, owner) {
|
|
23244
|
-
const state = allocatorStates.get(slots);
|
|
23245
|
-
if (state === void 0) throw new ValidationError$1("openSlotGroup: allocator was not created by createWorkerSlots");
|
|
23246
|
-
const issued = owner === void 0 ? void 0 : deferredPermits.get(owner)?.() ?? owner;
|
|
23247
|
-
const ownerState = issued === void 0 ? void 0 : permitStates.get(issued);
|
|
23248
|
-
if (owner !== void 0 && ownerState === void 0) throw new ValidationError$1("openSlotGroup: owner permit was not issued by this allocator");
|
|
23249
|
-
const group = {
|
|
23250
|
-
owner: ownerState,
|
|
23251
|
-
running: 0,
|
|
23252
|
-
queued: 0
|
|
23253
|
-
};
|
|
23254
|
-
if (ownerState !== void 0) {
|
|
23255
|
-
if (ownerState.children !== void 0) throw new ValidationError$1("openSlotGroup: a permit owns at most one group of children");
|
|
23256
|
-
ownerState.children = group;
|
|
23257
|
-
}
|
|
23258
|
-
return {
|
|
23259
|
-
acquire: (depth, options) => acquire(state, group, depth, options?.force === true),
|
|
23260
|
-
get running() {
|
|
23261
|
-
return group.running;
|
|
23262
|
-
},
|
|
23263
|
-
get queued() {
|
|
23264
|
-
return group.queued;
|
|
23265
|
-
}
|
|
23266
|
-
};
|
|
23267
|
-
}
|
|
23268
|
-
const permitStates = /* @__PURE__ */ new WeakMap();
|
|
23269
|
-
/** Each deferred permit's reader of the permit it acquired, once it has acquired one. */
|
|
23270
|
-
const deferredPermits = /* @__PURE__ */ new WeakMap();
|
|
23271
|
-
/**
|
|
23272
|
-
* @internal A slot requested only once `after` resolves. A spawn that waits for budget takes no
|
|
23273
|
-
* slot while it waits, so it cannot hold a slot that the work it waits on needs. `ready` rejects
|
|
23274
|
-
* when `after` does; `release` before then withdraws the request.
|
|
23275
|
-
*/
|
|
23276
|
-
function deferSlot(after, acquire) {
|
|
23277
|
-
let inner;
|
|
23278
|
-
let released = false;
|
|
23279
|
-
const ready = after.then(() => {
|
|
23280
|
-
if (released) return;
|
|
23281
|
-
inner = acquire();
|
|
23282
|
-
return inner.ready;
|
|
23283
|
-
});
|
|
23284
|
-
ready.catch(() => void 0);
|
|
23285
|
-
const handle = {
|
|
23286
|
-
ready,
|
|
23287
|
-
get granted() {
|
|
23288
|
-
return inner?.granted ?? false;
|
|
23289
|
-
},
|
|
23290
|
-
release() {
|
|
23291
|
-
if (released) return;
|
|
23292
|
-
released = true;
|
|
23293
|
-
inner?.release();
|
|
23294
|
-
}
|
|
23295
|
-
};
|
|
23296
|
-
deferredPermits.set(handle, () => inner);
|
|
23297
|
-
return handle;
|
|
23298
|
-
}
|
|
23299
|
-
function acquire(state, group, depth, force) {
|
|
23300
|
-
if (!Number.isSafeInteger(depth) || depth < 0) throw new ValidationError$1(`worker slots: depth must be a non-negative integer, got ${depth}`);
|
|
23301
|
-
const permit = {
|
|
23302
|
-
group,
|
|
23303
|
-
granted: false,
|
|
23304
|
-
released: false,
|
|
23305
|
-
counted: false
|
|
23306
|
-
};
|
|
23307
|
-
let resolveReady;
|
|
23308
|
-
const ready = new Promise((resolve) => {
|
|
23309
|
-
resolveReady = resolve;
|
|
23310
|
-
});
|
|
23311
|
-
const grant = () => {
|
|
23312
|
-
grantPermit(state, permit);
|
|
23313
|
-
resolveReady();
|
|
23314
|
-
};
|
|
23315
|
-
if (force || costOf(group) === 0 || hasCapacity(state)) grant();
|
|
23316
|
-
else {
|
|
23317
|
-
group.queued += 1;
|
|
23318
|
-
const waiter = {
|
|
23319
|
-
permit,
|
|
23320
|
-
depth,
|
|
23321
|
-
order: state.order++,
|
|
23322
|
-
grant
|
|
23323
|
-
};
|
|
23324
|
-
state.waiters.push(waiter);
|
|
23325
|
-
}
|
|
23326
|
-
const handle = {
|
|
23327
|
-
ready,
|
|
23328
|
-
get granted() {
|
|
23329
|
-
return permit.granted;
|
|
23330
|
-
},
|
|
23331
|
-
release() {
|
|
23332
|
-
if (permit.released) return;
|
|
23333
|
-
permit.released = true;
|
|
23334
|
-
if (!permit.granted) {
|
|
23335
|
-
withdraw(state, permit);
|
|
23336
|
-
return;
|
|
23337
|
-
}
|
|
23338
|
-
releasePermit(state, permit);
|
|
23339
|
-
pump(state);
|
|
23340
|
-
}
|
|
23341
|
-
};
|
|
23342
|
-
permitStates.set(handle, permit);
|
|
23343
|
-
return handle;
|
|
23344
|
-
}
|
|
23345
|
-
/** A child of `group` adds a working unit unless its manager is working on its own slot now, in
|
|
23346
|
-
* which case the child takes that slot over. */
|
|
23347
|
-
function costOf(group) {
|
|
23348
|
-
const owner = group.owner;
|
|
23349
|
-
return owner?.granted && !owner.released && owner.counted ? 0 : 1;
|
|
23350
|
-
}
|
|
23351
|
-
function hasCapacity(state) {
|
|
23352
|
-
return state.max === void 0 || state.working < state.max;
|
|
23353
|
-
}
|
|
23354
|
-
function grantPermit(state, permit) {
|
|
23355
|
-
const group = permit.group;
|
|
23356
|
-
if (costOf(group) === 0) group.owner.counted = false;
|
|
23357
|
-
else state.working += 1;
|
|
23358
|
-
permit.granted = true;
|
|
23359
|
-
permit.counted = true;
|
|
23360
|
-
group.running += 1;
|
|
23361
|
-
}
|
|
23362
|
-
function releasePermit(state, permit) {
|
|
23363
|
-
if ((permit.children?.running ?? 0) > 0) return;
|
|
23364
|
-
const group = permit.group;
|
|
23365
|
-
group.running -= 1;
|
|
23366
|
-
if (group.running < 0) throw new ValidationError$1("worker slots: a group released more than it ran");
|
|
23367
|
-
if (!permit.counted) return;
|
|
23368
|
-
permit.counted = false;
|
|
23369
|
-
const owner = group.owner;
|
|
23370
|
-
if (group.running === 0 && owner !== void 0 && owner.granted) {
|
|
23371
|
-
owner.counted = true;
|
|
23372
|
-
if (owner.released) releasePermit(state, owner);
|
|
23373
|
-
return;
|
|
23374
|
-
}
|
|
23375
|
-
state.working -= 1;
|
|
23376
|
-
if (state.working < 0) throw new ValidationError$1("worker slots: released more than granted");
|
|
23377
|
-
}
|
|
23378
|
-
function withdraw(state, permit) {
|
|
23379
|
-
const index = state.waiters.findIndex((waiter) => waiter.permit === permit);
|
|
23380
|
-
if (index === -1) return;
|
|
23381
|
-
state.waiters.splice(index, 1);
|
|
23382
|
-
permit.group.queued -= 1;
|
|
23383
|
-
}
|
|
23384
|
-
/** Grant every waiter that can run: any waiter whose manager is working on its own slot, and then
|
|
23385
|
-
* the deepest and oldest waiters while capacity remains. */
|
|
23386
|
-
function pump(state) {
|
|
23387
|
-
for (;;) {
|
|
23388
|
-
let chosen;
|
|
23389
|
-
for (let index = 0; index < state.waiters.length; index++) {
|
|
23390
|
-
const waiter = state.waiters[index];
|
|
23391
|
-
if (costOf(waiter.permit.group) === 0) {
|
|
23392
|
-
chosen = index;
|
|
23393
|
-
break;
|
|
23394
|
-
}
|
|
23395
|
-
if (!hasCapacity(state)) continue;
|
|
23396
|
-
const best = chosen === void 0 ? void 0 : state.waiters[chosen];
|
|
23397
|
-
if (best === void 0 || waiter.depth > best.depth || waiter.depth === best.depth && waiter.order < best.order) chosen = index;
|
|
23398
|
-
}
|
|
23399
|
-
if (chosen === void 0) return;
|
|
23400
|
-
const [waiter] = state.waiters.splice(chosen, 1);
|
|
23401
|
-
waiter.permit.group.queued -= 1;
|
|
23402
|
-
waiter.grant();
|
|
23403
|
-
}
|
|
23404
|
-
}
|
|
23405
|
-
function normalizeWorkerSlotBound(value) {
|
|
23406
|
-
if (value === void 0 || value <= 0) return void 0;
|
|
23407
|
-
if (!Number.isSafeInteger(value)) throw new ValidationError$1(`workerSlots must be a positive safe integer, or 0 or less for no bound, got ${String(value)}`);
|
|
23408
|
-
return value;
|
|
23409
|
-
}
|
|
23410
|
-
//#endregion
|
|
23411
23429
|
//#region src/runtime/supervise/scope.ts
|
|
23412
23430
|
/**
|
|
23413
23431
|
*
|
|
@@ -28522,6 +28540,6 @@ function isNonEmptySpend(s) {
|
|
|
28522
28540
|
return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0 || s.tokensKnown === false || s.usdKnown === false || Object.values(s.resources ?? {}).some((resource) => resource.amount > 0 || !resource.known);
|
|
28523
28541
|
}
|
|
28524
28542
|
//#endregion
|
|
28525
|
-
export {
|
|
28543
|
+
export { bindScopeRetainedOwnerProvider as $, projectSandboxOutcome as $i, parseWorkerToolTraceArtifact as $n, runWorktreeHarness as $r, isPeerMailEnvelope as $t, driverExecutorFactory as A, withBudgetResources as Aa, writeAllBytes as Ai, resolveAgentEnvironmentProvider as An, mergeTraceEnv as Ar, createExecutor as At, recordScopeOwnerDriverAttempt as B, providerMessageText as Ba, recordRuntimeOwnedDriveHarnessProviderEvidence as Bi, InMemoryResultBlobStore as Bn, createOtelExporter as Br, workerTraceEnv as Bt, createContinuationKeeper as C, throwAbort as Ca, sandboxActProfileMaterialization as Ci, readPromptOptions as Cn, runAbortable as Cr, freeSlots as Ct, passedItems as D, zeroSpend as Da, isNoEntError as Di, createAgentEnvironmentProviderRegistry as Dn, readHarnessTranscript as Dr, captureReusableExecutorConfig as Dt, failedItems as E, withTimeout as Ea, worktreeCliProfileMaterialization as Ei, LEAF_CONTINUATION_TASK as En, persistHarnessTranscript as Er, bindReusableExecutorExecutionId as Et, beginScopeOwnerAttempt as F, armDeadlineTimer as Fa, inheritRuntimeOwnedExecutorAttestation as Fi, sandboxSessionTraceSource as Fn, resolveRedactor as Fr, createSteerableSandboxSession as Ft, settledToIteration as G, runtimeOwnedPendingExecutorMaterialization as Gi, insideCursorNamespace as Gn, padTraceId as Gr, createActivityLog as Gt, recordScopeOwnerPause as H, runtimeOwnedExecutorExecutionBinding as Hi, SpawnEventIndex as Hn, generateSpanId as Hr, workerTraceSeamKey as Ht, createScope as I, teardownExecutor as Ia, knownExecutionBindingReceipt as Ii, registerRetainedExecutorPreparation as In, buildLoopOtelSpans as Ir, createRouterTranscript as It, pollFor as J, unknownMaterializationReceipt as Ji, pendingWaits as Jn, createRuntimeStreamEventCollector as Jr, AUTHORITY_MARKERS as Jt, createWaitProbes as K, runtimeOwnedScopeOwnerRuntime as Ki, loadSpawnForest as Kn, toOtelAttributes as Kr, readWorkerProgress as Kt, deriveNodeExecutionIdentity as L, teardownSurfaces as La, knownMaterializationReceipt as Li, retainedExecutorSeamKey as Ln, buildLoopSpanNodes as Lr, createInPlaceCliExecutor as Lt, withDriverExecutor as M, abortError$2 as Ma, attestRuntimeOwnedScopeOwner as Mi, unavailableSignalOfFailure as Mn, traceContextToEnv as Mr, snapshotExecutorConfig as Mt, SUBTREE_RESULT_LIMIT as N, awaitAbortable$1 as Na, authoredProfileDigest as Ni, createPushTraceSource as Nn, defaultRedactor as Nr, createWorktreeCliExecutor as Nt, verdictFromJudgeScore as O, addResourceSpend as Oa, prepareJsonlAppend as Oi, providerAsExecutor as On, contentAddress as Or, cliInPlaceExecutor as Ot, assertRecursiveReservationPolicy as P, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as Pa, finalizeRuntimeOwnedPendingExecutor as Pi, decodeToolPart as Pn, defaultRedactorIdentityMaterial as Pr, DEFAULT_SANDBOX_STEERING_MAX_TURNS as Pt, bindScopeRetainedOwnerEnvironmentId as Q, detachedSnapshot as Qi, isTraceAnalysisStore as Qn, runSettledCommand as Qr, createPeerMailbox as Qt, meterRuntimeOwnedAccounting as R, promptFromAgentTurnInput as Ra, newExecutionAttemptId as Ri, FileResultBlobStore as Rn, buildRuntimeEventOtelSpans as Rr, WORKER_TRACE_PROPAGATION as Rt, composeContinuationNote as S, stringifySafe as Sa, renderUnsupported as Si, assertBoxlessPromptOptions as Sn, linkAbort as Sr, startRetainedInteractiveRun as St, expandQuestions as T, unmeteredSpend as Ta, validateProfileMaterialization as Ti, runBrainLoop as Tn, harnessTranscriptArtifact as Tr, rollingDispatch as Tt, restoreScopeOwnerAcceptedExecution as U, runtimeOwnedExecutorMaterialization as Ui, assertContentAddress as Un, loopEventToOtelSpan as Ur, taskToPrompt as Ut, recordScopeOwnerMaterialization as V, runtimeOwnedDriveHarnessProviderEvidence as Vi, InMemorySpawnJournal as Vn, flatOtelSpan as Vr, workerTraceHeaders as Vt, scopeOwnerExecutorNodeContext as W, runtimeOwnedExecutorProviderEvidence as Wi, encodeResultBlob as Wn, padSpanId as Wr, DEFAULT_STALL_AFTER_MS as Wt, validateWaitSpec as X, executableAgentSpecSnapshot as Xi, WORKER_TOOL_TRACE_SCHEMA_VERSION as Xn, sanitizeKnowledgeReadinessReport as Xr, PEER_MAIL_WIRE_KEY as Xt, timerAt as Y, executableAgentProfileSnapshot as Yi, replaySpawnTree as Yn, sanitizeAgentRuntimeEvent as Yr, DEFAULT_PEER_MAIL_LIMITS as Yt, waitUntil as Z, detachedFrozen as Zi, captureWorkerTraceEvidence as Zn, sanitizeRuntimeStreamEvent as Zr, claimsAuthority as Zt, CheckUnavailableError as _, hasCompleteCacheBreakdown as _a, promptControlProfileMaterialization as _i, createSandboxLineage as _n, environmentGone as _r, readWorkerInteractiveBinding as _t, collectDelivered as a, extractLlmCallEvent as aa, harnessInvocation as ai, bridgeModelRouteRefusal as an, createBudgetPool as ar, scopeRetainedOwnerPriorSpend as at, bestComposite as b, randomSuffix as ba, promptResourceProfileMaterialization as bi, SandboxEvidenceRetentionError as bn, RunCancellationReason as br, reconnectRetainedInteractiveRun as bt, runTree as c, mapSandboxToolEvent as ca, parseCodexTokenUsage as ci, harnessUsageIsEmpty as cn, spendFromUsageEvents as cr, scopeRetainedOwnerResult as ct, classifyDriverFailure as d, sandboxProgressEvents as da, AGENT_PROFILE_MATERIALIZATION_AXES as di, bridgeStopSignalKey as dn, reconnectRetainedRun as dr, hostDirectoryReader as dt, readSandboxOutcome as ea, captureWorktreeDiff as ei, peerMailTools as en, workerTraceAnalysisStore as er, consumeScopeRetainedOwnerResult as et, runDriverWithRetry as f, sumSandboxUsage as fa, assertProfileMaterialization as fi, TERMINAL_DECISIONS as fn, recoverRetainedRun as fr, resolveSpawnResourcePaths as ft, CONTINUATION_FACTS as g, deleteBoxSafe as ga, profileMaterializationAxes$1 as gi, runAgentRounds as gn, destroyInteractiveEnvironment as gr, attachWorker as gt, CONTINUATIONS_DIR as h, cloneSpend as ha, fullProfileMaterialization as hi, isTerminalDecision as hn, retainedCreateMaterial as hr, workerInteractiveAdmissionFile as ht, bestDelivered as i, createSandboxUsageLedger as ia, LOCAL_HARNESSES as ii, bridgeAdmissionRefusal as in, assertValidBudget as ir, scopeRetainedOwnerContext as it, isDriverSpec as j, decodeHarnessUsage as ja, attestRuntimeOwnedPendingExecutor as ji, unavailablePauseMs as jn, readTraceContextFromEnv as jr, createExecutorRegistry as jt, driverChild as k, resourceTelemetry as ka, readCommittedJsonLines as ki, providerAsSandboxClient as kn, createPropagatingTraceEmitter as kr, cliWorktreeExecutor as kt, DriverAttemptsExhaustedError as l, notifySandboxEventObserver as la, CodexExecutionDiagnosticError as li, readCodexRolloutSession as ln, spendFromUsageTotals as lr, SPAWN_RESOURCE_PATH_MAX_BYTES as lt, upstreamUnavailableSignal as m, chargedTokens as ma, defineProfileMaterializationContract as mi, defaultSelectWinner as mn, startRetainedRunInEnvironment as mr, readWorkerInteractiveAdmissions as mt, createRootHandle as n, canonicalStreamEventFromSandboxEvent as na, removeWorktree as ni, isLiveNodeStatus as nn, BudgetReconcileFault as nr, prepareScopeRetainedOwnerTask as nt, pickBestDelivered as o, isSandboxTerminalEvent as oa, harnessSupportsReasoningEffort as oi, addHarnessUsage as on, meterUsageEvent as or, scopeRetainedOwnerResourceReader as ot, summarizeDriverAttempts as p, addSpend as pa, controlProfileMaterialization as pi, createSandboxForSpec as pn, startRetainedRun as pr, interactiveAdmissionSeamKey as pt, isWaitOutcome as q, unknownExecutionBindingReceipt as qi, materializeTreeView as qn, createRuntimeEventCollector as qr, createInbox as qt, createSupervisor as r, createSandboxToolPartState as ra, DEFAULT_LOCAL_HARNESS as ri, isTerminalNodeStatus as rn, ReservationWaitRefused as rr, reconcileScopeRetainedOwnerEnvironment as rt, runFinalizer as s, mapSandboxEvent as sa, localHarnessExecutable as si, createCodexRolloutStoreReader as sn, newUsageTotals as sr, scopeRetainedOwnerRestorePoint as st, DEFAULT_MAX_DEPTH as t, assertSandboxServedModel as ta, createWorktree as ti, peerMailVerbNames as tn, executorFailure as tr, noteScopeRetainedOwnerCoordination as tt, HarnessTurnFailedError as u, sandboxEventServedBackend as ua, terminateProcessTreeAndConfirm as ui, bridgeRuntimeAttachmentsKey as un, errMessage as ur, environmentReader as ut, admitContinuationPolicy as v, isAbortError$2 as va, promptModelProfileMaterialization as vi, probeSandboxCapabilities as vn, createWorkerSlots as vr, workerInteractiveBindingFile as vt, distillFindings as w, throwIfAborted as wa, unsupportedProfileDimensions as wi, routerBrain as wn, captureHarnessTranscript as wr, queueOf as wt, checkVerdictOf as x, sleep as xa, renderProfileMaterializationIssues as xi, captureBeforeDestroy as xn, abortError as xr, recoverRetainedInteractiveRun as xt, admitFinding as y, promptCacheTokenClasses as ya, promptOnlyProfileMaterialization as yi, acquireSandbox as yn, openSlotGroup as yr, workerInteractiveBindingsDir as yt, meterRuntimeOwnedProviderAttempt as z, promptOptionsFromAgentTurnInput as za, providerAttemptEvidence as zi, FileSpawnJournal as zn, createOpenInferenceFileExporter as zr, readWorkerTraceContext as zt };
|
|
28526
28544
|
|
|
28527
|
-
//# sourceMappingURL=supervisor-
|
|
28545
|
+
//# sourceMappingURL=supervisor-DnoT3-_F.js.map
|