@tangle-network/agent-runtime 0.239.0 → 0.246.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{activation-CUhkPtm0.js → activation-C6d-NTWk.js} +3 -3
- package/dist/{activation-CUhkPtm0.js.map → activation-C6d-NTWk.js.map} +1 -1
- package/dist/{activation-CRDZUoUE.d.ts → activation-Df-ae5Uq.d.ts} +115 -5
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/candidate-execution/index.js +7 -7
- package/dist/candidate-execution/index.js.map +1 -1
- package/dist/{coordination-driver-m-2dzvu6.js → coordination-driver-De8pyM57.js} +25 -12
- package/dist/coordination-driver-De8pyM57.js.map +1 -0
- package/dist/{delegate-DRQtaWF1.js → delegate-DE6hNhbD.js} +2 -2
- package/dist/{delegate-DRQtaWF1.js.map → delegate-DE6hNhbD.js.map} +1 -1
- package/dist/{durable-file-D24y9zg7.js → durable-file-DWQA4ooo.js} +2 -2
- package/dist/{durable-file-D24y9zg7.js.map → durable-file-DWQA4ooo.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +3 -3
- package/dist/{graph-B17RjVhE.js → graph-s57f-VCR.js} +3 -3
- package/dist/{graph-B17RjVhE.js.map → graph-s57f-VCR.js.map} +1 -1
- package/dist/{improvement-cycle-BP4rDivU.js → improvement-cycle-BE3gIJwL.js} +458 -60
- package/dist/improvement-cycle-BE3gIJwL.js.map +1 -0
- package/dist/{index-DTGWDyrF.d.ts → index-CAG31NtK.d.ts} +7 -7
- package/dist/index.d.ts +11 -8
- package/dist/index.js +27 -17
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +3 -3
- package/dist/intelligence.js +9 -6
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-BGi5UT85.d.ts → loop-runner-bin-B_oSVrE7.d.ts} +3 -3
- package/dist/{loop-runner-bin-mrOuv9SU.js → loop-runner-bin-Bp8Mih20.js} +3 -3
- package/dist/{loop-runner-bin-mrOuv9SU.js.map → loop-runner-bin-Bp8Mih20.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 +5 -5
- package/dist/mcp/index.js +4 -4
- package/dist/{openai-tools-BPPAXxP2.d.ts → openai-tools-B1GMKDjW.d.ts} +2 -2
- package/dist/{prepare-Dc30WRB0.js → prepare-CibQrhfi.js} +28 -28
- package/dist/prepare-CibQrhfi.js.map +1 -0
- package/dist/profiles.d.ts +2 -2
- package/dist/{protected-model-port-D5gDcnrH.js → protected-model-port-Dhdi5mDl.js} +3 -3
- package/dist/{protected-model-port-D5gDcnrH.js.map → protected-model-port-Dhdi5mDl.js.map} +1 -1
- package/dist/{protected-redaction-wGo44k2K.js → protected-redaction-Fn1ETfJ-.js} +6 -6
- package/dist/protected-redaction-Fn1ETfJ-.js.map +1 -0
- package/dist/{provision-supervisor-CNdrsjvc.js → provision-supervisor-D0X9KUv-.js} +5 -5
- package/dist/{provision-supervisor-CNdrsjvc.js.map → provision-supervisor-D0X9KUv-.js.map} +1 -1
- package/dist/{run-layout-hZREkcfu.js → run-layout-B8-Gqhpg.js} +2 -2
- package/dist/{run-layout-hZREkcfu.js.map → run-layout-B8-Gqhpg.js.map} +1 -1
- package/dist/{runtime-BsPY_v8H.js → runtime-CHbVv5UI.js} +16 -13
- package/dist/{runtime-BsPY_v8H.js.map → runtime-CHbVv5UI.js.map} +1 -1
- package/dist/{server-b8uEBoK0.js → server-DwsC_FyV.js} +3 -3
- package/dist/{server-b8uEBoK0.js.map → server-DwsC_FyV.js.map} +1 -1
- package/dist/{stream-agent-turn-xgmm-M55.d.ts → stream-agent-turn-DQ-W8mHf.d.ts} +2 -2
- package/dist/{structural-rollout-sy2sH_7-.js → structural-rollout-DasmuuUp.js} +2 -2
- package/dist/{structural-rollout-sy2sH_7-.js.map → structural-rollout-DasmuuUp.js.map} +1 -1
- package/dist/{substrate-B_9stFWH.d.ts → substrate-DJOnuoa_.d.ts} +2 -2
- package/dist/{supervise-CBd3FyCS.js → supervise-o6CzD2Rt.js} +142 -35
- package/dist/supervise-o6CzD2Rt.js.map +1 -0
- package/dist/{supervisor-De0lytFU.js → supervisor-tGq-TPIv.js} +162 -103
- package/dist/supervisor-tGq-TPIv.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +398 -398
- package/dist/{top-app-CMMd8DgR.js → top-app-DL-sjv7K.js} +2 -2
- package/dist/{top-app-CMMd8DgR.js.map → top-app-DL-sjv7K.js.map} +1 -1
- package/dist/tui/bin.js +1 -1
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{types-CE7ES_TD.d.ts → types-BoEzH8V6.d.ts} +18 -2
- package/dist/{workspace-archive-CBX0hwL_.js → workspace-archive-DSRT4Tro.js} +8 -8
- package/dist/workspace-archive-DSRT4Tro.js.map +1 -0
- package/package.json +6 -6
- package/dist/coordination-driver-m-2dzvu6.js.map +0 -1
- package/dist/improvement-cycle-BP4rDivU.js.map +0 -1
- package/dist/prepare-Dc30WRB0.js.map +0 -1
- package/dist/protected-redaction-wGo44k2K.js.map +0 -1
- package/dist/supervise-CBd3FyCS.js.map +0 -1
- package/dist/supervisor-De0lytFU.js.map +0 -1
- package/dist/workspace-archive-CBX0hwL_.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as RetainedInteractiveAdmissionError, d as RetainedRunDispatchBindingError, f as RuntimeRunStateError, i as ConfigError, l as RetainedInteractiveBindingError, m as ValidationError$1, r as BackendTransportError, t as AgentEvalError$1, u as RetainedRunAdmissionError } from "./errors-DodWX-cb.js";
|
|
2
2
|
import { a as concreteProfileModel, c as profileModelExecutionSettings, d as agentHarness, l as profileProviderModel, o as enforceTokenLimits, s as profileBridgeWireModel, t as assertExecutableAgentProfile, u as resolveRouterRetryPolicy } from "./model-policy-BbSCSak0.js";
|
|
3
3
|
import { i as notifyRuntimeHookEvent } from "./runtime-hooks-tXpAarhW.js";
|
|
4
|
-
import { n as assertNoSymlinkDescendant, r as publishExclusiveDurableFile } from "./durable-file-
|
|
4
|
+
import { n as assertNoSymlinkDescendant, r as publishExclusiveDurableFile } from "./durable-file-DWQA4ooo.js";
|
|
5
5
|
import { AGENT_PROFILE_MATERIALIZATION_AXES, AgentEnvironmentCapabilitiesSchema, AgentExactRunControlRefSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStatusSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentNativeContextContinuationResultSchema, AgentRunCancellationAcknowledgementSchema, AgentRunCancellationRequestSchema, AgentTurnInputSchema, AgentTurnResultSchema, CanonicalStreamEventSchema, ContextTransferRequestSchema, InteractionAcknowledgementSchema, InteractionResponseCommandSchema, NativeContextBoundaryProofSchema, NativeContextContinuationRequestSchema, REASONING_EFFORTS, RuntimeEventEnvelopeSchema, TerminalReplayWindowSchema, TerminalSessionRefSchema, WorkspaceRequestSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionRunRef, agentInteractiveSessionStatusMatchesRef, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentNativeContextContinuationResultMatchesRequest, agentProfileSchema, agentRunCancellationAcknowledgementMatchesRequest, agentRunCancellationRequestDigest, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalWorkspaceCwd, exactAgentInteractiveSessionStart, harnessSystemPromptIntents, harnessTypeSchema, nativeContextContinuationTurnDigest, nativeReasoningControl, profileMaterializationAxes, profileMaterializationAxes as profileMaterializationAxes$1, renderInputPartsAsText, sha256DigestSchema, workspaceCwdPathForBase } from "@tangle-network/agent-interface";
|
|
6
6
|
import { estimateCost, isModelPriced, isToolSpan, toolSpansToTraceAnalysisStore } from "@tangle-network/agent-eval";
|
|
7
7
|
import { createAgentRunOutcomeTracker } from "@tangle-network/sandbox/runtime";
|
|
@@ -2797,6 +2797,57 @@ function isAxisSupported(axis, supported) {
|
|
|
2797
2797
|
return supported.has(axis);
|
|
2798
2798
|
}
|
|
2799
2799
|
//#endregion
|
|
2800
|
+
//#region src/runtime/process-tree.ts
|
|
2801
|
+
const processKillGraceMs = 250;
|
|
2802
|
+
const processGroupExitConfirmMs = 1e3;
|
|
2803
|
+
const processGroupExitPollMs = 10;
|
|
2804
|
+
function signalProcessTree(child, signal) {
|
|
2805
|
+
if (process.platform !== "win32" && typeof child.pid === "number") try {
|
|
2806
|
+
process.kill(-child.pid, signal);
|
|
2807
|
+
return;
|
|
2808
|
+
} catch (err) {
|
|
2809
|
+
if (err.code === "ESRCH") return;
|
|
2810
|
+
}
|
|
2811
|
+
try {
|
|
2812
|
+
child.kill(signal);
|
|
2813
|
+
} catch {}
|
|
2814
|
+
}
|
|
2815
|
+
/** Terminate one owned process group and confirm its disappearance; detached sessions are outside it. */
|
|
2816
|
+
async function terminateProcessTreeAndConfirm(child, leaderClosed, context = "runLocalHarness") {
|
|
2817
|
+
signalProcessTree(child, "SIGTERM");
|
|
2818
|
+
if (process.platform === "win32" || typeof child.pid !== "number") {
|
|
2819
|
+
const graceDeadline = Date.now() + processKillGraceMs;
|
|
2820
|
+
while (!leaderClosed() && Date.now() < graceDeadline) await delayUntilNextProcessCheck(graceDeadline);
|
|
2821
|
+
if (!leaderClosed()) signalProcessTree(child, "SIGKILL");
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
const processGroupId = child.pid;
|
|
2825
|
+
if (await waitForProcessGroupExit(processGroupId, Date.now() + processKillGraceMs)) return;
|
|
2826
|
+
signalProcessTree(child, "SIGKILL");
|
|
2827
|
+
if (await waitForProcessGroupExit(processGroupId, Date.now() + processGroupExitConfirmMs)) return;
|
|
2828
|
+
throw new Error(`${context}: process group ${processGroupId} survived SIGKILL`);
|
|
2829
|
+
}
|
|
2830
|
+
async function waitForProcessGroupExit(processGroupId, deadline) {
|
|
2831
|
+
while (processGroupExists(processGroupId)) {
|
|
2832
|
+
if (Date.now() >= deadline) return false;
|
|
2833
|
+
await delayUntilNextProcessCheck(deadline);
|
|
2834
|
+
}
|
|
2835
|
+
return true;
|
|
2836
|
+
}
|
|
2837
|
+
async function delayUntilNextProcessCheck(deadline) {
|
|
2838
|
+
const delayMs = Math.min(processGroupExitPollMs, Math.max(0, deadline - Date.now()));
|
|
2839
|
+
if (delayMs > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
2840
|
+
}
|
|
2841
|
+
function processGroupExists(processGroupId) {
|
|
2842
|
+
try {
|
|
2843
|
+
process.kill(-processGroupId, 0);
|
|
2844
|
+
return true;
|
|
2845
|
+
} catch (err) {
|
|
2846
|
+
if (err.code === "ESRCH") return false;
|
|
2847
|
+
return true;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
//#endregion
|
|
2800
2851
|
//#region src/mcp/codex-diagnostics.ts
|
|
2801
2852
|
/** Thrown when reproducible Codex exits without one valid terminal usage event. */
|
|
2802
2853
|
var CodexExecutionDiagnosticError = class extends Error {
|
|
@@ -3127,9 +3178,6 @@ function harnessProfileModel(harness, profile) {
|
|
|
3127
3178
|
return model;
|
|
3128
3179
|
}
|
|
3129
3180
|
const DEFAULT_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
|
|
3130
|
-
const processKillGraceMs = 250;
|
|
3131
|
-
const processGroupExitConfirmMs = 1e3;
|
|
3132
|
-
const processGroupExitPollMs = 10;
|
|
3133
3181
|
var RollingByteCapture = class {
|
|
3134
3182
|
maxBytes;
|
|
3135
3183
|
chunks = [];
|
|
@@ -3979,51 +4027,6 @@ function sha256File(path) {
|
|
|
3979
4027
|
stream.on("end", () => resolveDigest(hash.digest("hex")));
|
|
3980
4028
|
});
|
|
3981
4029
|
}
|
|
3982
|
-
function signalProcessTree(child, signal) {
|
|
3983
|
-
if (process.platform !== "win32" && typeof child.pid === "number") try {
|
|
3984
|
-
process.kill(-child.pid, signal);
|
|
3985
|
-
return;
|
|
3986
|
-
} catch (err) {
|
|
3987
|
-
if (err.code === "ESRCH") return;
|
|
3988
|
-
}
|
|
3989
|
-
try {
|
|
3990
|
-
child.kill(signal);
|
|
3991
|
-
} catch {}
|
|
3992
|
-
}
|
|
3993
|
-
async function terminateProcessTreeAndConfirm(child, leaderClosed, context = "runLocalHarness") {
|
|
3994
|
-
signalProcessTree(child, "SIGTERM");
|
|
3995
|
-
if (process.platform === "win32" || typeof child.pid !== "number") {
|
|
3996
|
-
const graceDeadline = Date.now() + processKillGraceMs;
|
|
3997
|
-
while (!leaderClosed() && Date.now() < graceDeadline) await delayUntilNextProcessCheck(graceDeadline);
|
|
3998
|
-
if (!leaderClosed()) signalProcessTree(child, "SIGKILL");
|
|
3999
|
-
return;
|
|
4000
|
-
}
|
|
4001
|
-
const processGroupId = child.pid;
|
|
4002
|
-
if (await waitForProcessGroupExit(processGroupId, Date.now() + processKillGraceMs)) return;
|
|
4003
|
-
signalProcessTree(child, "SIGKILL");
|
|
4004
|
-
if (await waitForProcessGroupExit(processGroupId, Date.now() + processGroupExitConfirmMs)) return;
|
|
4005
|
-
throw new Error(`${context}: process group ${processGroupId} survived SIGKILL`);
|
|
4006
|
-
}
|
|
4007
|
-
async function waitForProcessGroupExit(processGroupId, deadline) {
|
|
4008
|
-
while (processGroupExists(processGroupId)) {
|
|
4009
|
-
if (Date.now() >= deadline) return false;
|
|
4010
|
-
await delayUntilNextProcessCheck(deadline);
|
|
4011
|
-
}
|
|
4012
|
-
return true;
|
|
4013
|
-
}
|
|
4014
|
-
async function delayUntilNextProcessCheck(deadline) {
|
|
4015
|
-
const delayMs = Math.min(processGroupExitPollMs, Math.max(0, deadline - Date.now()));
|
|
4016
|
-
if (delayMs > 0) await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
4017
|
-
}
|
|
4018
|
-
function processGroupExists(processGroupId) {
|
|
4019
|
-
try {
|
|
4020
|
-
process.kill(-processGroupId, 0);
|
|
4021
|
-
return true;
|
|
4022
|
-
} catch (err) {
|
|
4023
|
-
if (err.code === "ESRCH") return false;
|
|
4024
|
-
return true;
|
|
4025
|
-
}
|
|
4026
|
-
}
|
|
4027
4030
|
/**
|
|
4028
4031
|
* Parse and validate the one terminal usage event emitted by `codex exec --json`.
|
|
4029
4032
|
*
|
|
@@ -5622,7 +5625,8 @@ const DEFAULT_INTELLIGENCE_BASE = "https://intelligence.tangle.tools";
|
|
|
5622
5625
|
* Ship self-improvement eval-run events to Tangle Intelligence. Unlike the
|
|
5623
5626
|
* best-effort span exporter, this RESOLVES with the ingest verdict (accepted /
|
|
5624
5627
|
* rejected per event) so a consumer's loop can assert its provenance landed.
|
|
5625
|
-
*
|
|
5628
|
+
* Success requires a complete, valid acknowledgement accepting every event.
|
|
5629
|
+
* Throws on a missing key, network failure, or unreadable/inconsistent acknowledgement.
|
|
5626
5630
|
*/
|
|
5627
5631
|
async function exportEvalRuns(events, config) {
|
|
5628
5632
|
if (events.length === 0) return {
|
|
@@ -5632,8 +5636,9 @@ async function exportEvalRuns(events, config) {
|
|
|
5632
5636
|
rejected: []
|
|
5633
5637
|
};
|
|
5634
5638
|
const apiKey = config?.apiKey ?? (typeof process !== "undefined" ? process.env.TANGLE_API_KEY : void 0);
|
|
5635
|
-
if (!apiKey) throw new Error("exportEvalRuns: apiKey required (pass config.apiKey or set TANGLE_API_KEY)");
|
|
5639
|
+
if (!apiKey?.trim()) throw new Error("exportEvalRuns: apiKey required (pass config.apiKey or set TANGLE_API_KEY)");
|
|
5636
5640
|
const url = `${(config?.base ?? (typeof process !== "undefined" ? process.env.TANGLE_INTELLIGENCE_URL : void 0) ?? DEFAULT_INTELLIGENCE_BASE).replace(/\/+$/, "")}/v1/ingest/eval-runs`;
|
|
5641
|
+
const count = events.length;
|
|
5637
5642
|
const res = await fetch(url, {
|
|
5638
5643
|
method: "POST",
|
|
5639
5644
|
headers: {
|
|
@@ -5647,15 +5652,35 @@ async function exportEvalRuns(events, config) {
|
|
|
5647
5652
|
events
|
|
5648
5653
|
})
|
|
5649
5654
|
});
|
|
5650
|
-
|
|
5655
|
+
const invalid = (reason) => {
|
|
5656
|
+
throw new Error(`exportEvalRuns: ${reason} (HTTP ${res.status})`);
|
|
5657
|
+
};
|
|
5658
|
+
let parsed;
|
|
5651
5659
|
try {
|
|
5652
5660
|
parsed = await res.json();
|
|
5653
|
-
} catch {
|
|
5661
|
+
} catch {
|
|
5662
|
+
return invalid("Unreadable eval-runs acknowledgement");
|
|
5663
|
+
}
|
|
5664
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return invalid("Invalid eval-runs acknowledgement");
|
|
5665
|
+
const { accepted, rejected } = parsed;
|
|
5666
|
+
if (!Number.isSafeInteger(accepted) || accepted < 0 || accepted > count || !Array.isArray(rejected)) return invalid("Invalid eval-runs acknowledgement counts");
|
|
5667
|
+
const indices = /* @__PURE__ */ new Set();
|
|
5668
|
+
const validated = [];
|
|
5669
|
+
for (const item of rejected) {
|
|
5670
|
+
if (item === null || typeof item !== "object" || Array.isArray(item) || !Number.isSafeInteger(item.index) || item.index < 0 || item.index >= count || indices.has(item.index) || typeof item.reason !== "string" || !item.reason.trim()) return invalid("Invalid eval-runs acknowledgement rejection");
|
|
5671
|
+
indices.add(item.index);
|
|
5672
|
+
validated.push({
|
|
5673
|
+
index: item.index,
|
|
5674
|
+
reason: item.reason
|
|
5675
|
+
});
|
|
5676
|
+
}
|
|
5677
|
+
if (accepted + validated.length !== count) return invalid("Incomplete eval-runs acknowledgement");
|
|
5678
|
+
if (!res.ok && accepted !== 0) return invalid("Failed HTTP response claimed accepted eval-runs");
|
|
5654
5679
|
return {
|
|
5655
|
-
ok: res.ok,
|
|
5680
|
+
ok: res.ok && accepted === count && validated.length === 0,
|
|
5656
5681
|
status: res.status,
|
|
5657
|
-
accepted
|
|
5658
|
-
rejected:
|
|
5682
|
+
accepted,
|
|
5683
|
+
rejected: validated
|
|
5659
5684
|
};
|
|
5660
5685
|
}
|
|
5661
5686
|
//#endregion
|
|
@@ -7264,6 +7289,46 @@ async function runAbortable(act, signal, fallback) {
|
|
|
7264
7289
|
});
|
|
7265
7290
|
}
|
|
7266
7291
|
//#endregion
|
|
7292
|
+
//#region src/runtime/supervise/cost-estimate.ts
|
|
7293
|
+
/**
|
|
7294
|
+
* Pricing for work that arrived without a provider receipt.
|
|
7295
|
+
*
|
|
7296
|
+
* A turn whose provider reported no billed dollars used to reach the dollar channel as a
|
|
7297
|
+
* known `$0`, so a run that certainly spent money reported a dollar total of zero. A catalog
|
|
7298
|
+
* price is not a receipt, so what this module produces is always marked, never promoted.
|
|
7299
|
+
*/
|
|
7300
|
+
/**
|
|
7301
|
+
* Price one unit of work that no provider receipt covered.
|
|
7302
|
+
*
|
|
7303
|
+
* The event always carries `usdKnown: false`: a catalog price approximates what a provider
|
|
7304
|
+
* WOULD bill, never measures what it did. The priced amount is repeated in `usdEstimated` so
|
|
7305
|
+
* a consumer can subtract it from `usd` and recover the dollars a provider actually billed.
|
|
7306
|
+
*
|
|
7307
|
+
* A model with no catalog entry yields `usd: 0` with `usdKnown: false` and no `usdEstimated`.
|
|
7308
|
+
* The turn then reads as unknown dollars, which is true, rather than as a free turn.
|
|
7309
|
+
*/
|
|
7310
|
+
function priceUnreceiptedWork(work) {
|
|
7311
|
+
const unknown = {
|
|
7312
|
+
kind: "cost",
|
|
7313
|
+
usd: 0,
|
|
7314
|
+
usdKnown: false,
|
|
7315
|
+
provenance: "uncaptured"
|
|
7316
|
+
};
|
|
7317
|
+
const { inputTokens, outputTokens, model } = work;
|
|
7318
|
+
if (model === void 0 || !isModelPriced(model)) return unknown;
|
|
7319
|
+
if (!Number.isFinite(inputTokens) || !Number.isFinite(outputTokens)) return unknown;
|
|
7320
|
+
if (inputTokens < 0 || outputTokens < 0) return unknown;
|
|
7321
|
+
const usd = estimateCost(inputTokens, outputTokens, model);
|
|
7322
|
+
if (!Number.isFinite(usd) || usd <= 0) return unknown;
|
|
7323
|
+
return {
|
|
7324
|
+
kind: "cost",
|
|
7325
|
+
usd,
|
|
7326
|
+
usdKnown: false,
|
|
7327
|
+
usdEstimated: usd,
|
|
7328
|
+
provenance: "catalog-estimate"
|
|
7329
|
+
};
|
|
7330
|
+
}
|
|
7331
|
+
//#endregion
|
|
7267
7332
|
//#region src/runtime/supervise/retained-executor.ts
|
|
7268
7333
|
/** Scope owns the durable writer; provider executors only publish sanitized admissions. */
|
|
7269
7334
|
const retainedExecutorSeamKey = "runtime.retainedExecutor";
|
|
@@ -8045,6 +8110,9 @@ async function* streamProviderExecutor(args) {
|
|
|
8045
8110
|
let sawCostEstimate = false;
|
|
8046
8111
|
let pendingUnpricedWork = false;
|
|
8047
8112
|
let pendingEstimate;
|
|
8113
|
+
/** The model id a usage receipt reported, when it reported one. Only a catalog can price a run
|
|
8114
|
+
* the provider never billed, and only a model id can address a catalog. */
|
|
8115
|
+
let observedModel;
|
|
8048
8116
|
let usdEstimated = 0;
|
|
8049
8117
|
let usd = 0;
|
|
8050
8118
|
let text = "";
|
|
@@ -8085,10 +8153,11 @@ async function* streamProviderExecutor(args) {
|
|
|
8085
8153
|
}
|
|
8086
8154
|
yield* creditUsage(usageLedger.settleTurn(args.profile.name ?? "agent"));
|
|
8087
8155
|
if (pendingUnpricedWork) {
|
|
8088
|
-
const
|
|
8156
|
+
const estimated = pendingEstimate ?? (usd === 0 ? catalogPrice() : void 0);
|
|
8157
|
+
const estimate = estimated ?? 0;
|
|
8089
8158
|
sawUnknownCostReceipt = true;
|
|
8090
8159
|
usd += estimate;
|
|
8091
|
-
if (
|
|
8160
|
+
if (estimated !== void 0) {
|
|
8092
8161
|
sawCostEstimate = true;
|
|
8093
8162
|
usdEstimated += estimate;
|
|
8094
8163
|
}
|
|
@@ -8096,8 +8165,8 @@ async function* streamProviderExecutor(args) {
|
|
|
8096
8165
|
kind: "cost",
|
|
8097
8166
|
usd: estimate,
|
|
8098
8167
|
usdKnown: false,
|
|
8099
|
-
...
|
|
8100
|
-
provenance:
|
|
8168
|
+
...estimated === void 0 ? {} : { usdEstimated: estimate },
|
|
8169
|
+
provenance: estimated === void 0 ? "uncaptured" : "catalog-estimate"
|
|
8101
8170
|
};
|
|
8102
8171
|
}
|
|
8103
8172
|
if ((args.options.requireTerminalEvent ?? true) && !terminal) throw new ValidationError(`providerAsExecutor(${args.provider.name}): stream ended without a terminal result/done/status event`);
|
|
@@ -8162,8 +8231,33 @@ async function* streamProviderExecutor(args) {
|
|
|
8162
8231
|
}
|
|
8163
8232
|
}
|
|
8164
8233
|
if (failed) throw failure;
|
|
8234
|
+
/**
|
|
8235
|
+
* The catalog price of this execution's whole token total, under the first model id the catalog
|
|
8236
|
+
* knows. Undefined when none prices, so an unpriced model settles with no estimate at all rather
|
|
8237
|
+
* than a zero one — absence says "nothing could be priced", a zero would say "priced at nothing".
|
|
8238
|
+
*
|
|
8239
|
+
* Candidates run most specific first: the id a usage receipt reported, then the turn's own
|
|
8240
|
+
* model, then the profile's. A provider that selected its own default declares no profile model,
|
|
8241
|
+
* so a reported id is then the only one a catalog can match.
|
|
8242
|
+
*/
|
|
8243
|
+
function catalogPrice() {
|
|
8244
|
+
for (const model of [
|
|
8245
|
+
observedModel,
|
|
8246
|
+
turn.model,
|
|
8247
|
+
concreteProfileModel(args.createProfile)
|
|
8248
|
+
]) {
|
|
8249
|
+
if (model === void 0) continue;
|
|
8250
|
+
const priced = priceUnreceiptedWork({
|
|
8251
|
+
inputTokens: tokens.input,
|
|
8252
|
+
outputTokens: tokens.output,
|
|
8253
|
+
model
|
|
8254
|
+
});
|
|
8255
|
+
if (priced.usdKnown === false && priced.usdEstimated !== void 0) return priced.usdEstimated;
|
|
8256
|
+
}
|
|
8257
|
+
}
|
|
8165
8258
|
function* creditUsage(receipt, event) {
|
|
8166
8259
|
if (receipt === void 0) return;
|
|
8260
|
+
if (receipt.model !== (args.profile.name ?? "agent")) observedModel = receipt.model;
|
|
8167
8261
|
const hasTokens = receipt.tokensIn !== void 0 || receipt.tokensOut !== void 0;
|
|
8168
8262
|
if (hasTokens && receipt.tokensIn !== void 0 && receipt.tokensOut !== void 0 && receipt.tokensKnown !== false) sawCompleteTokenReceipt = true;
|
|
8169
8263
|
else if (hasTokens || receipt.tokensKnown === false || receipt.tokensUnknownReason) sawIncompleteTokenReceipt = true;
|
|
@@ -9654,7 +9748,11 @@ async function runBrainLoop(opts) {
|
|
|
9654
9748
|
for (let turn = 1; maxTurns === 0 || turn <= maxTurns; turn += 1) {
|
|
9655
9749
|
if (opts.hooks?.stopBefore?.(turn)) break;
|
|
9656
9750
|
await opts.hooks?.beforeTurn?.(turn, messages);
|
|
9657
|
-
if (opts.
|
|
9751
|
+
if (opts.hooks?.stopBefore?.(turn)) break;
|
|
9752
|
+
if (opts.compaction) {
|
|
9753
|
+
await maybeCompact(messages, opts.compaction, turn);
|
|
9754
|
+
if (opts.hooks?.stopBefore?.(turn)) break;
|
|
9755
|
+
}
|
|
9658
9756
|
const r = await opts.chat(messages, opts.tools);
|
|
9659
9757
|
completedTurns = turn;
|
|
9660
9758
|
if (r.usage) {
|
|
@@ -13293,46 +13391,6 @@ function providerDispatchFromErrorBody(body) {
|
|
|
13293
13391
|
return error.provider_dispatch === "not_started" ? "not_started" : void 0;
|
|
13294
13392
|
}
|
|
13295
13393
|
//#endregion
|
|
13296
|
-
//#region src/runtime/supervise/cost-estimate.ts
|
|
13297
|
-
/**
|
|
13298
|
-
* Pricing for work that arrived without a provider receipt.
|
|
13299
|
-
*
|
|
13300
|
-
* A turn whose provider reported no billed dollars used to reach the dollar channel as a
|
|
13301
|
-
* known `$0`, so a run that certainly spent money reported a dollar total of zero. A catalog
|
|
13302
|
-
* price is not a receipt, so what this module produces is always marked, never promoted.
|
|
13303
|
-
*/
|
|
13304
|
-
/**
|
|
13305
|
-
* Price one unit of work that no provider receipt covered.
|
|
13306
|
-
*
|
|
13307
|
-
* The event always carries `usdKnown: false`: a catalog price approximates what a provider
|
|
13308
|
-
* WOULD bill, never measures what it did. The priced amount is repeated in `usdEstimated` so
|
|
13309
|
-
* a consumer can subtract it from `usd` and recover the dollars a provider actually billed.
|
|
13310
|
-
*
|
|
13311
|
-
* A model with no catalog entry yields `usd: 0` with `usdKnown: false` and no `usdEstimated`.
|
|
13312
|
-
* The turn then reads as unknown dollars, which is true, rather than as a free turn.
|
|
13313
|
-
*/
|
|
13314
|
-
function priceUnreceiptedWork(work) {
|
|
13315
|
-
const unknown = {
|
|
13316
|
-
kind: "cost",
|
|
13317
|
-
usd: 0,
|
|
13318
|
-
usdKnown: false,
|
|
13319
|
-
provenance: "uncaptured"
|
|
13320
|
-
};
|
|
13321
|
-
const { inputTokens, outputTokens, model } = work;
|
|
13322
|
-
if (model === void 0 || !isModelPriced(model)) return unknown;
|
|
13323
|
-
if (!Number.isFinite(inputTokens) || !Number.isFinite(outputTokens)) return unknown;
|
|
13324
|
-
if (inputTokens < 0 || outputTokens < 0) return unknown;
|
|
13325
|
-
const usd = estimateCost(inputTokens, outputTokens, model);
|
|
13326
|
-
if (!Number.isFinite(usd) || usd <= 0) return unknown;
|
|
13327
|
-
return {
|
|
13328
|
-
kind: "cost",
|
|
13329
|
-
usd,
|
|
13330
|
-
usdKnown: false,
|
|
13331
|
-
usdEstimated: usd,
|
|
13332
|
-
provenance: "catalog-estimate"
|
|
13333
|
-
};
|
|
13334
|
-
}
|
|
13335
|
-
//#endregion
|
|
13336
13394
|
//#region src/runtime/supervise/executor-outcome.ts
|
|
13337
13395
|
const outcomeSchema = AgentTurnResultSchema.pick({
|
|
13338
13396
|
success: true,
|
|
@@ -23148,6 +23206,7 @@ function makeTreeView(root, children) {
|
|
|
23148
23206
|
...c.materialization ? { materialization: c.materialization } : {},
|
|
23149
23207
|
...c.executionBindings.length > 0 ? { executionBindings: Object.freeze([...c.executionBindings]) } : {},
|
|
23150
23208
|
spent: c.spent,
|
|
23209
|
+
...c.resolved !== void 0 && !c.delivered ? { settlementPending: { kind: c.resolved.kind } } : {},
|
|
23151
23210
|
...c.settledAt === void 0 ? {} : { settledAt: c.settledAt },
|
|
23152
23211
|
...c.outRef ? { outRef: c.outRef } : {},
|
|
23153
23212
|
...c.trace ? { trace: c.trace } : {},
|
|
@@ -25046,6 +25105,6 @@ function isNonEmptySpend(s) {
|
|
|
25046
25105
|
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);
|
|
25047
25106
|
}
|
|
25048
25107
|
//#endregion
|
|
25049
|
-
export { startRetainedInteractiveRun as $,
|
|
25108
|
+
export { startRetainedInteractiveRun as $, withBudgetResources as $i, contentAddress as $n, writeAllBytes as $r, isPeerMailEnvelope as $t, validateWaitSpec as A, mapSandboxEvent as Ai, providerAsSandboxClient as An, localHarnessExecutable as Ar, workerTraceAnalysisStore as At, SPAWN_RESOURCE_PATH_MAX_BYTES as B, hasCompleteCacheBreakdown as Bi, linkAbort as Bn, promptControlProfileMaterialization as Br, workerTraceEnv as Bt, restoreScopeOwnerAcceptedExecution as C, readSandboxOutcome as Ci, routerBrain as Cn, runWorktreeHarness as Cr, materializeTreeView as Ct, isWaitOutcome as D, createSandboxUsageLedger as Di, DEFAULT_SANDBOX_IDLE_TIMEOUT_SECONDS as Dn, DEFAULT_LOCAL_HARNESS as Dr, captureWorkerTraceEvidence as Dt, createWaitProbes as E, createSandboxToolPartState as Ei, observedModelMatchesDeclared as En, removeWorktree as Er, WORKER_TOOL_TRACE_SCHEMA_VERSION as Et, prepareScopeRetainedOwnerTask as F, sumSandboxUsage as Fi, sandboxSessionTraceSource as Fn, assertProfileMaterialization as Fr, newUsageTotals as Ft, readWorkerInteractiveAdmissions as G, stringifySafe as Gi, startRetainedRunInEnvironment as Gn, renderUnsupported as Gr, createActivityLog as Gt, hostDirectoryReader as H, promptCacheTokenClasses as Hi, reconnectRetainedRun as Hn, promptOnlyProfileMaterialization as Hr, workerTraceSeamKey as Ht, scopeRetainedOwnerContext as I, addSpend as Ii, registerRetainedExecutorPreparation as In, controlProfileMaterialization as Ir, spendFromUsageEvents as It, readWorkerInteractiveBinding as J, unmeteredSpend as Ji, defaultRedactorIdentityMaterial as Jn, validateProfileMaterialization as Jr, AUTHORITY_MARKERS as Jt, workerInteractiveAdmissionFile as K, throwAbort as Ki, retainedCreateMaterial as Kn, sandboxActProfileMaterialization as Kr, readWorkerProgress as Kt, scopeRetainedOwnerPriorSpend as L, chargedTokens as Li, retainedExecutorSeamKey as Ln, defineProfileMaterializationContract as Lr, spendFromUsageTotals as Lt, bindScopeRetainedOwnerEnvironmentId as M, notifySandboxEventObserver as Mi, sandboxClientAsProvider as Mn, CodexExecutionDiagnosticError as Mr, assertValidBudget as Mt, bindScopeRetainedOwnerProvider as N, sandboxEventServedBackend as Ni, createPushTraceSource as Nn, terminateProcessTreeAndConfirm as Nr, createBudgetPool as Nt, pollFor as O, extractLlmCallEvent as Oi, createAgentEnvironmentProviderRegistry as On, LOCAL_HARNESSES as Or, isTraceAnalysisStore as Ot, consumeScopeRetainedOwnerResult as P, sandboxProgressEvents as Pi, decodeToolPart as Pn, AGENT_PROFILE_MATERIALIZATION_AXES as Pr, meterUsageEvent as Pt, recoverRetainedInteractiveRun as Q, resourceTelemetry as Qi, persistHarnessTranscript as Qn, readCommittedJsonLines as Qr, createPeerMailbox as Qt, scopeRetainedOwnerResourceReader as R, cloneSpend as Ri, RunCancellationReason as Rn, fullProfileMaterialization as Rr, WORKER_TRACE_PROPAGATION as Rt, recordScopeOwnerMaterialization as S, projectSandboxOutcome as Si, readPromptOptions as Sn, runSettledCommand as Sr, loadSpawnForest as St, settledToIteration as T, canonicalStreamEventFromSandboxEvent as Ti, canonicalObservedModelParts as Tn, createWorktree as Tr, replaySpawnTree as Tt, resolveSpawnResourcePaths as U, randomSuffix as Ui, recoverRetainedRun as Un, promptResourceProfileMaterialization as Ur, taskToPrompt as Ut, environmentReader as V, isAbortError$2 as Vi, runAbortable as Vn, promptModelProfileMaterialization as Vr, workerTraceHeaders as Vt, interactiveAdmissionSeamKey as W, sleep as Wi, startRetainedRun as Wn, renderProfileMaterializationIssues as Wr, DEFAULT_STALL_AFTER_MS as Wt, workerInteractiveBindingsDir as X, zeroSpend as Xi, captureHarnessTranscript as Xn, isNoEntError as Xr, PEER_MAIL_WIRE_KEY as Xt, workerInteractiveBindingFile as Y, withTimeout as Yi, resolveRedactor as Yn, worktreeCliProfileMaterialization as Yr, DEFAULT_PEER_MAIL_LIMITS as Yt, reconnectRetainedInteractiveRun as Z, addResourceSpend as Zi, harnessTranscriptArtifact as Zn, prepareJsonlAppend as Zr, claimsAuthority as Zt, beginScopeOwnerAttempt as _, unknownMaterializationReceipt as _i, runAgentRounds as _n, createRuntimeEventCollector as _r, FileResultBlobStore as _t, pickBestDelivered as a, teardownExecutor as aa, knownExecutionBindingReceipt as ai, bridgeAdmissionRefusal as an, buildLoopOtelSpans as ar, rollingDispatch as at, meterRuntimeOwnedAccounting as b, detachedFrozen as bi, acquireSandbox as bn, sanitizeKnowledgeReadinessReport as br, InMemorySpawnJournal as bt, DriverAttemptsExhaustedError as c, providerMessageText as ca, providerAttemptEvidence as ci, createCodexRolloutStoreReader as cn, createOpenInferenceFileExporter as cr, cliInPlaceExecutor as ct, defaultUnmetContractSteer as d, runtimeOwnedExecutorExecutionBinding as di, bridgeRuntimeAttachmentsKey as dn, flatOtelSpan as dr, createExecutorRegistry as dt, decodeHarnessUsage as ea, attestRuntimeOwnedPendingExecutor as ei, peerMailTools as en, createPropagatingTraceEmitter as er, destroyInteractiveEnvironment as et, runDriverWithRetry as f, runtimeOwnedExecutorMaterialization as fi, bridgeStopSignalKey as fn, generateSpanId as fr, snapshotExecutorConfig as ft, withDriverExecutor as g, unknownExecutionBindingReceipt as gi, isTerminalDecision as gn, toOtelAttributes as gr, createInPlaceCliExecutor as gt, isDriverSpec as h, runtimeOwnedScopeOwnerRuntime as hi, defaultSelectWinner as hn, padTraceId as hr, createSteerableSandboxSession as ht, collectDelivered as i, armDeadlineTimer as ia, inheritRuntimeOwnedExecutorAttestation as ii, executorFailure as in, INTELLIGENCE_WIRE_VERSION as ir, queueOf as it, waitUntil as j, mapSandboxToolEvent as ji, resolveAgentEnvironmentProvider as jn, parseCodexTokenUsage as jr, BudgetReconcileFault as jt, timerAt as k, isSandboxTerminalEvent as ki, providerAsExecutor as kn, harnessSupportsReasoningEffort as kr, parseWorkerToolTraceArtifact as kt, HarnessTurnFailedError as l, recordRuntimeOwnedDriveHarnessProviderEvidence as li, harnessUsageIsEmpty as ln, createOtelExporter as lr, cliWorktreeExecutor as lt, driverExecutorFactory as m, runtimeOwnedPendingExecutorMaterialization as mi, createSandboxForSpec as mn, padSpanId as mr, DEFAULT_SANDBOX_STEERING_MAX_TURNS as mt, createSupervisor as n, awaitAbortable$1 as na, authoredProfileDigest as ni, isLiveNodeStatus as nn, readTraceContextFromEnv as nr, effectiveConcurrency as nt, runFinalizer as o, promptFromAgentTurnInput as oa, knownMaterializationReceipt as oi, bridgeModelRouteRefusal as on, buildLoopSpanNodes as or, bindReusableExecutorExecutionId as ot, driverChild as p, runtimeOwnedExecutorProviderEvidence as pi, TERMINAL_DECISIONS as pn, loopEventToOtelSpan as pr, createWorktreeCliExecutor as pt, attachWorker as q, throwIfAborted as qi, defaultRedactor as qn, unsupportedProfileDimensions as qr, createInbox as qt, bestDelivered as r, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as ra, finalizeRuntimeOwnedPendingExecutor as ri, isTerminalNodeStatus as rn, traceContextToEnv as rr, freeSlots as rt, runTree as s, promptOptionsFromAgentTurnInput as sa, newExecutionAttemptId as si, addHarnessUsage as sn, buildRuntimeEventOtelSpans as sr, captureReusableExecutorConfig as st, createRootHandle as t, abortError$2 as ta, attestRuntimeOwnedScopeOwner as ti, peerMailVerbNames as tn, mergeTraceEnv as tr, errMessage as tt, classifyDriverFailure as u, runtimeOwnedDriveHarnessProviderEvidence as ui, readCodexRolloutSession as un, exportEvalRuns as ur, createExecutor as ut, createScope as v, executableAgentProfileSnapshot as vi, createSandboxLineage as vn, createRuntimeStreamEventCollector as vr, FileSpawnJournal as vt, scopeOwnerExecutorNodeContext as w, assertSandboxServedModel as wi, runBrainLoop as wn, captureWorktreeDiff as wr, pendingWaits as wt, meterRuntimeOwnedProviderAttempt as x, detachedSnapshot as xi, assertBoxlessPromptOptions as xn, sanitizeRuntimeStreamEvent as xr, insideCursorNamespace as xt, deriveNodeExecutionIdentity as y, executableAgentSpecSnapshot as yi, probeSandboxCapabilities as yn, sanitizeAgentRuntimeEvent as yr, InMemoryResultBlobStore as yt, scopeRetainedOwnerResult as z, deleteBoxSafe as zi, abortError as zn, profileMaterializationAxes$1 as zr, readWorkerTraceContext as zt };
|
|
25050
25109
|
|
|
25051
|
-
//# sourceMappingURL=supervisor-
|
|
25110
|
+
//# sourceMappingURL=supervisor-tGq-TPIv.js.map
|