@tangle-network/agent-runtime 0.131.6 → 0.131.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/{activation-D-gsrgSq.js → activation-CDKatOlp.js} +3 -3
  2. package/dist/{activation-D-gsrgSq.js.map → activation-CDKatOlp.js.map} +1 -1
  3. package/dist/agent.d.ts +2 -2
  4. package/dist/agent.js +2 -2
  5. package/dist/analyst-loop.d.ts +1 -1
  6. package/dist/{authoring-DI778qK7.js → authoring-B-Oe8VUf.js} +2 -2
  7. package/dist/{authoring-DI778qK7.js.map → authoring-B-Oe8VUf.js.map} +1 -1
  8. package/dist/candidate-execution/index.js +4 -4
  9. package/dist/{candidate-execution-BNxKr-Bu.js → candidate-execution-DxL_I3xx.js} +4 -4
  10. package/dist/{candidate-execution-BNxKr-Bu.js.map → candidate-execution-DxL_I3xx.js.map} +1 -1
  11. package/dist/conversation.d.ts +1 -1
  12. package/dist/{environment-provider-CxvSd1W6.d.ts → environment-provider-DZihBZx6.d.ts} +3 -3
  13. package/dist/{environment-provider-Dyg8DtLK.js → environment-provider-mDsjfGjY.js} +2 -2
  14. package/dist/{environment-provider-Dyg8DtLK.js.map → environment-provider-mDsjfGjY.js.map} +1 -1
  15. package/dist/environment-provider.d.ts +1 -1
  16. package/dist/environment-provider.js +1 -1
  17. package/dist/{graph-CoN60QtH.js → graph-DOfL9TLn.js} +3 -3
  18. package/dist/{graph-CoN60QtH.js.map → graph-DOfL9TLn.js.map} +1 -1
  19. package/dist/{improvement-cycle-BGF0osPC.js → improvement-cycle-XtFD7dCv.js} +4 -4
  20. package/dist/{improvement-cycle-BGF0osPC.js.map → improvement-cycle-XtFD7dCv.js.map} +1 -1
  21. package/dist/{index-DwGtu9nc.d.ts → index-C-IJR7pR.d.ts} +4 -4
  22. package/dist/{index-CoO7atyo.d.ts → index-D7UJIX2x.d.ts} +3087 -3064
  23. package/dist/{index-qYHpsmG2.d.ts → index-qKm5g7mI.d.ts} +3 -3
  24. package/dist/index.d.ts +9 -9
  25. package/dist/index.js +12 -12
  26. package/dist/index.js.map +1 -1
  27. package/dist/intelligence.d.ts +5 -5
  28. package/dist/intelligence.js +6 -6
  29. package/dist/kernel.d.ts +7 -7
  30. package/dist/kernel.js +9 -9
  31. package/dist/{knowledge-D4zNvxw5.js → knowledge-DPDhKnOz.js} +5 -5
  32. package/dist/{knowledge-D4zNvxw5.js.map → knowledge-DPDhKnOz.js.map} +1 -1
  33. package/dist/knowledge.d.ts +1 -1
  34. package/dist/knowledge.js +1 -1
  35. package/dist/{loop-runner-bin-BwgZ8m_7.d.ts → loop-runner-bin-B6g4vOil.d.ts} +3 -3
  36. package/dist/{loop-runner-bin-CI9Y0sxT.js → loop-runner-bin-DCBho3GJ.js} +3 -3
  37. package/dist/{loop-runner-bin-CI9Y0sxT.js.map → loop-runner-bin-DCBho3GJ.js.map} +1 -1
  38. package/dist/loop-runner-bin.d.ts +1 -1
  39. package/dist/loop-runner-bin.js +1 -1
  40. package/dist/mcp/bin.js +3 -3
  41. package/dist/mcp/index.d.ts +5 -5
  42. package/dist/mcp/index.js +5 -5
  43. package/dist/{openai-tools-CupeHJEv.js → openai-tools-BeVFVJlX.js} +2 -2
  44. package/dist/{openai-tools-CupeHJEv.js.map → openai-tools-BeVFVJlX.js.map} +1 -1
  45. package/dist/{openai-tools-D3oMyVGl.d.ts → openai-tools-CzEiSbPW.d.ts} +2 -2
  46. package/dist/{prepare-DYWjVcPx.js → prepare-BQ82nG06.js} +2 -2
  47. package/dist/{prepare-DYWjVcPx.js.map → prepare-BQ82nG06.js.map} +1 -1
  48. package/dist/primeintellect/index.d.ts +1 -1
  49. package/dist/profiles.d.ts +1 -1
  50. package/dist/{protected-model-port-48ALLGxT.js → protected-model-port-BAOj4gQN.js} +2 -2
  51. package/dist/{protected-model-port-48ALLGxT.js.map → protected-model-port-BAOj4gQN.js.map} +1 -1
  52. package/dist/{redact-9_Gf-8m3.d.ts → redact-CwupS9H2.d.ts} +3 -3
  53. package/dist/{runtime-ZNVnT8h1.js → runtime-BVKEU5jc.js} +131 -28
  54. package/dist/runtime-BVKEU5jc.js.map +1 -0
  55. package/dist/{runtime-D-QfLbSd.d.ts → runtime-DgJZUxql.d.ts} +4 -4
  56. package/dist/{spawn-journal-saHQzqYi.js → spawn-journal-Cd5L-Ie9.js} +20 -9
  57. package/dist/spawn-journal-Cd5L-Ie9.js.map +1 -0
  58. package/dist/{stream-agent-turn-C852AgMT.d.ts → stream-agent-turn-DcDznEnq.d.ts} +3 -3
  59. package/dist/{structural-rollout-n089ZP33.js → structural-rollout-v8o_EO8_.js} +3 -3
  60. package/dist/{structural-rollout-n089ZP33.js.map → structural-rollout-v8o_EO8_.js.map} +1 -1
  61. package/dist/{supervise-msTRhTN7.js → supervise-DzLi985l.js} +24 -6
  62. package/dist/supervise-DzLi985l.js.map +1 -0
  63. package/dist/{supervisor-C16p9KqO.js → supervisor-CMtutocL.js} +92 -81
  64. package/dist/supervisor-CMtutocL.js.map +1 -0
  65. package/dist/testing.d.ts +2 -2
  66. package/dist/testing.js +12 -12
  67. package/dist/{types-ebIY0dMG.d.ts → types-6zHo67jn.d.ts} +13 -1
  68. package/dist/{types-C6Q-J0Dt.d.ts → types-CIg5DBNF.d.ts} +12 -3
  69. package/dist/{util-Bw6srryQ.js → util-Dr--8wAL.js} +32 -3
  70. package/dist/util-Dr--8wAL.js.map +1 -0
  71. package/dist/{workspace-archive-aOfJ47ms.js → workspace-archive-CGcXL3zA.js} +2 -2
  72. package/dist/{workspace-archive-aOfJ47ms.js.map → workspace-archive-CGcXL3zA.js.map} +1 -1
  73. package/package.json +4 -4
  74. package/dist/runtime-ZNVnT8h1.js.map +0 -1
  75. package/dist/spawn-journal-saHQzqYi.js.map +0 -1
  76. package/dist/supervise-msTRhTN7.js.map +0 -1
  77. package/dist/supervisor-C16p9KqO.js.map +0 -1
  78. package/dist/util-Bw6srryQ.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  import { c as RuntimeRunStateError, r as BackendTransportError, u as ValidationError } from "./errors-DEAvWQPy.js";
2
2
  import { t as detachedSnapshot } from "./snapshot-CXiiuHhL.js";
3
- import { _ as captureWorkerTraceEvidence, c as replaySpawnTree, f as attestNestedDriverTreeOwner, h as runtimeOwnedNestedDriverTreeRoot, m as nestedDriverTreeRoot, o as materializeTreeView, p as driverRuntime, s as pendingWaits, x as contentAddress } from "./spawn-journal-saHQzqYi.js";
4
- import { a as randomSuffix, c as stringifySafe, d as withTimeout, f as zeroTokenUsage, i as mapWithConcurrency, l as throwAbort, n as deleteBoxSafe, o as randomUuid, s as sleep, t as addTokenUsage, u as throwIfAborted } from "./util-Bw6srryQ.js";
3
+ import { _ as captureWorkerTraceEvidence, c as replaySpawnTree, f as attestNestedDriverTreeOwner, h as runtimeOwnedNestedDriverTreeRoot, m as nestedDriverTreeRoot, o as materializeTreeView, p as driverRuntime, s as pendingWaits, x as contentAddress } from "./spawn-journal-Cd5L-Ie9.js";
4
+ import { c as randomUuid, d as throwAbort, f as throwIfAborted, l as sleep, m as zeroTokenUsage, n as cloneTokenUsage, o as mapWithConcurrency, p as withTimeout, r as deleteBoxSafe, s as randomSuffix, t as addTokenUsage, u as stringifySafe } from "./util-Dr--8wAL.js";
5
5
  import { a as notifySandboxEventObserver, n as extractLlmCallEvent } from "./sandbox-events-CRDwc5WN.js";
6
6
  import { a as concreteProfileModel, l as resolveRouterRetryPolicy, o as profileBridgeWireModel, s as profileModelExecutionSettings, t as assertExecutableAgentProfile, u as agentHarness } from "./model-policy-mWSoToiQ.js";
7
7
  import { _ as unknownMaterializationReceipt, a as authoredProfileDigest, c as knownExecutionBindingReceipt, d as runtimeOwnedDeferredExecutorRuntime, f as runtimeOwnedExecutorExecutionBinding, g as unknownExecutionBindingReceipt, h as runtimeOwnedScopeOwnerRuntime, l as knownMaterializationReceipt, m as runtimeOwnedPendingExecutorMaterialization, n as attestRuntimeOwnedExecutor, o as finalizeRuntimeOwnedPendingExecutor, p as runtimeOwnedExecutorMaterialization, r as attestRuntimeOwnedPendingExecutor, t as attestRuntimeOwnedDeferredExecutor, u as newExecutionAttemptId, v as executableAgentProfileSnapshot, y as executableAgentSpecSnapshot } from "./materialization-DBXuH34A.js";
8
- import { i as resolveAgentEnvironmentProvider, n as providerAsExecutor, r as providerAsSandboxClient } from "./environment-provider-Dyg8DtLK.js";
8
+ import { i as resolveAgentEnvironmentProvider, n as providerAsExecutor, r as providerAsSandboxClient } from "./environment-provider-mDsjfGjY.js";
9
9
  import { i as notifyRuntimeHookEvent } from "./runtime-hooks-C7iJOWm3.js";
10
10
  import { estimateCost, isModelPriced } from "@tangle-network/agent-eval";
11
11
  import { AGENT_PROFILE_MATERIALIZATION_AXES, REASONING_EFFORTS, agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, profileMaterializationAxes, profileMaterializationAxes as profileMaterializationAxes$1, sha256DigestSchema } from "@tangle-network/agent-interface";
@@ -6030,10 +6030,11 @@ const routerInlineExecutor = (spec, ctx) => {
6030
6030
  }));
6031
6031
  const spent = {
6032
6032
  iterations: 1,
6033
- tokens: r.usage ? {
6033
+ tokens: r.usage ? cloneTokenUsage({
6034
6034
  input: r.usage.input,
6035
- output: r.usage.output
6036
- } : zeroTokenUsage(),
6035
+ output: r.usage.output,
6036
+ ...routerPromptCacheUsage(r.usage.input, r.cache)
6037
+ }) : zeroTokenUsage(),
6037
6038
  usd: r.billedCostUsd ?? 0,
6038
6039
  ...r.usage ? {} : { tokensKnown: false },
6039
6040
  ...r.billedCostUsd === void 0 ? { usdKnown: false } : {},
@@ -6126,6 +6127,22 @@ function mergePromptCache(target, cache) {
6126
6127
  }
6127
6128
  if (cache.status !== void 0) target.status = cache.status;
6128
6129
  }
6130
+ /** Preserve a complete Router cache split; an incomplete provider receipt stays unknown. */
6131
+ function routerPromptCacheUsage(input, cache) {
6132
+ if (cache === void 0) return {};
6133
+ const read = cache.readTokens;
6134
+ const write = cache.writeTokens;
6135
+ if (read === void 0 && write === void 0) return {};
6136
+ if (input === void 0 || !isCacheTokenCount(read) || !isCacheTokenCount(write) || read + write > input) return { cacheBreakdownKnown: false };
6137
+ return {
6138
+ freshInput: input - read - write,
6139
+ cacheRead: read,
6140
+ cacheWrite: write
6141
+ };
6142
+ }
6143
+ function isCacheTokenCount(value) {
6144
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
6145
+ }
6129
6146
  async function runRouterTransport(context, call) {
6130
6147
  try {
6131
6148
  return await call();
@@ -6239,11 +6256,15 @@ const routerToolsInlineExecutor = (spec, ctx) => {
6239
6256
  if (res.model !== void 0) observedModel = res.model;
6240
6257
  mergePromptCache(promptCache, res.cache);
6241
6258
  if (res.usage) {
6242
- tokens.input += res.usage.input;
6243
- tokens.output += res.usage.output;
6259
+ addTokenUsage(tokens, {
6260
+ input: res.usage.input,
6261
+ output: res.usage.output,
6262
+ ...routerPromptCacheUsage(res.usage.input, res.cache)
6263
+ });
6244
6264
  if (res.usage.reasoning !== void 0) reasoningTokens += res.usage.reasoning;
6245
6265
  else reasoningKnown = false;
6246
6266
  } else {
6267
+ addTokenUsage(tokens, routerPromptCacheUsage(void 0, res.cache));
6247
6268
  tokensKnown = false;
6248
6269
  reasoningKnown = false;
6249
6270
  }
@@ -6610,10 +6631,7 @@ async function* streamSandboxLeaf(args) {
6610
6631
  };
6611
6632
  const spent = {
6612
6633
  iterations: result.iterations.length,
6613
- tokens: {
6614
- input: result.tokenUsage.input,
6615
- output: result.tokenUsage.output
6616
- },
6634
+ tokens: cloneTokenUsage(result.tokenUsage),
6617
6635
  ...tokensKnown ? {} : { tokensKnown: false },
6618
6636
  usd: result.costUsd,
6619
6637
  ...usdKnown ? {} : { usdKnown: false },
@@ -6633,7 +6651,11 @@ async function* streamSandboxLeaf(args) {
6633
6651
  kind: "tokens",
6634
6652
  input: result.tokenUsage.input,
6635
6653
  output: result.tokenUsage.output,
6636
- ...tokensKnown ? {} : { tokensKnown: false }
6654
+ ...tokensKnown ? {} : { tokensKnown: false },
6655
+ ...result.tokenUsage.freshInput !== void 0 ? { freshInput: result.tokenUsage.freshInput } : {},
6656
+ ...result.tokenUsage.cacheRead !== void 0 ? { cacheRead: result.tokenUsage.cacheRead } : {},
6657
+ ...result.tokenUsage.cacheWrite !== void 0 ? { cacheWrite: result.tokenUsage.cacheWrite } : {},
6658
+ ...result.tokenUsage.cacheBreakdownKnown === false ? { cacheBreakdownKnown: false } : {}
6637
6659
  };
6638
6660
  if (result.iterations.length > 0 || result.costUsd) yield {
6639
6661
  kind: "cost",
@@ -7194,14 +7216,17 @@ async function* streamBridgeSession(args) {
7194
7216
  if (chunk.usage) {
7195
7217
  sawTurnTokenUsage = true;
7196
7218
  if (!chunk.usage.known) turnTokensKnown = false;
7197
- tokens.input += chunk.usage.input;
7198
- tokens.output += chunk.usage.output;
7199
- yield {
7219
+ const usageEvent = {
7200
7220
  kind: "tokens",
7201
7221
  input: chunk.usage.input,
7202
7222
  output: chunk.usage.output,
7203
- ...chunk.usage.known ? {} : { tokensKnown: false }
7223
+ ...chunk.usage.known ? {} : { tokensKnown: false },
7224
+ ...chunk.usage.promptCache?.freshInput !== void 0 ? { freshInput: chunk.usage.promptCache.freshInput } : {},
7225
+ ...chunk.usage.promptCache?.readInput !== void 0 ? { cacheRead: chunk.usage.promptCache.readInput } : {},
7226
+ ...chunk.usage.promptCache?.writeInput !== void 0 ? { cacheWrite: chunk.usage.promptCache.writeInput } : {}
7204
7227
  };
7228
+ addTokenUsage(tokens, usageEvent);
7229
+ yield usageEvent;
7205
7230
  if (chunk.usage.promptCache) {
7206
7231
  if (chunk.usage.promptCache.freshInput !== void 0) promptCache.freshInput = (promptCache.freshInput ?? 0) + chunk.usage.promptCache.freshInput;
7207
7232
  if (chunk.usage.promptCache.readInput !== void 0) promptCache.readInput = (promptCache.readInput ?? 0) + chunk.usage.promptCache.readInput;
@@ -7909,9 +7934,9 @@ function parseSseFrame(frame) {
7909
7934
  if (u) {
7910
7935
  const input = optionalBridgeTokenCount(u.prompt_tokens, "prompt_tokens");
7911
7936
  const output = optionalBridgeTokenCount(u.completion_tokens, "completion_tokens");
7912
- const freshInput = optionalBridgeTokenCount(u.fresh_input_tokens, "fresh_input_tokens");
7913
- const readInput = optionalBridgeTokenCount(u.cache_read_input_tokens, "cache_read_input_tokens");
7914
- const writeInput = optionalBridgeTokenCount(u.cache_write_input_tokens, "cache_write_input_tokens");
7937
+ const readInput = optionalBridgeTokenCount(u.cache_read_input_tokens ?? u.prompt_cache?.read_tokens ?? u.prompt_cache_hit_tokens ?? u.prompt_tokens_details?.cached_tokens, "cache read input tokens");
7938
+ const writeInput = optionalBridgeTokenCount(u.cache_write_input_tokens ?? u.prompt_cache?.write_tokens, "cache write input tokens");
7939
+ const freshInput = optionalBridgeTokenCount(u.fresh_input_tokens, "fresh_input_tokens") ?? (input !== void 0 && readInput !== void 0 && writeInput !== void 0 && input >= readInput + writeInput ? input - readInput - writeInput : void 0);
7915
7940
  if (input !== void 0 || output !== void 0 || freshInput !== void 0 || readInput !== void 0 || writeInput !== void 0) out.usage = {
7916
7941
  input: input ?? 0,
7917
7942
  output: output ?? 0,
@@ -8696,7 +8721,19 @@ function assertValidBudget(budget, label = "budget") {
8696
8721
  }
8697
8722
  function assertValidSpend(spend, label) {
8698
8723
  if (!Number.isSafeInteger(spend.iterations) || spend.iterations < 0) throw new Error(`${label}.iterations must be a non-negative safe integer`);
8699
- for (const [field, value] of Object.entries(spend.tokens)) if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${label}.tokens.${field} must be a non-negative safe integer`);
8724
+ for (const [field, value] of [
8725
+ ["input", spend.tokens.input],
8726
+ ["output", spend.tokens.output],
8727
+ ["freshInput", spend.tokens.freshInput],
8728
+ ["cacheRead", spend.tokens.cacheRead],
8729
+ ["cacheWrite", spend.tokens.cacheWrite]
8730
+ ]) {
8731
+ if (value === void 0) continue;
8732
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${label}.tokens.${field} must be a non-negative safe integer`);
8733
+ }
8734
+ for (const [field, value] of [["tokensKnown", spend.tokens.tokensKnown], ["cacheBreakdownKnown", spend.tokens.cacheBreakdownKnown]]) if (value !== void 0 && value !== false) throw new Error(`${label}.tokens.${field} must be false when present`);
8735
+ const { freshInput, cacheRead, cacheWrite } = spend.tokens;
8736
+ if (freshInput !== void 0 && cacheRead !== void 0 && cacheWrite !== void 0 && freshInput + cacheRead + cacheWrite !== spend.tokens.input) throw new Error(`${label}.tokens cache classes must sum to input`);
8700
8737
  for (const [field, value] of [["usd", spend.usd], ["ms", spend.ms]]) if (!Number.isFinite(value) || value < 0) throw new Error(`${label}.${field} must be a non-negative finite number`);
8701
8738
  }
8702
8739
  /** Fold a normalized `UsageEvent` array into a `Spend`. Tokens and usd are separate
@@ -8709,10 +8746,7 @@ function spendFromUsageEvents(events) {
8709
8746
  let usdKnown = true;
8710
8747
  let iterations = 0;
8711
8748
  for (const ev of events) if (ev.kind === "tokens") {
8712
- addTokenUsage(tokens, {
8713
- input: ev.input,
8714
- output: ev.output
8715
- });
8749
+ addTokenUsage(tokens, ev);
8716
8750
  if (ev.tokensKnown === false) tokensKnown = false;
8717
8751
  } else if (ev.kind === "cost") {
8718
8752
  usd += ev.usd;
@@ -8735,10 +8769,7 @@ async function foldUsage(events) {
8735
8769
  let usdKnown = true;
8736
8770
  let iterations = 0;
8737
8771
  for await (const ev of events) if (ev.kind === "tokens") {
8738
- addTokenUsage(tokens, {
8739
- input: ev.input,
8740
- output: ev.output
8741
- });
8772
+ addTokenUsage(tokens, ev);
8742
8773
  if (ev.tokensKnown === false) tokensKnown = false;
8743
8774
  } else if (ev.kind === "cost") {
8744
8775
  usd += ev.usd;
@@ -10595,10 +10626,7 @@ function settledToIteration(settled) {
10595
10626
  startedAt: 0,
10596
10627
  endedAt: settled.spent.ms,
10597
10628
  costUsd: settled.spent.usd,
10598
- tokenUsage: {
10599
- input: settled.spent.tokens.input,
10600
- output: settled.spent.tokens.output
10601
- }
10629
+ tokenUsage: cloneTokenUsage(settled.spent.tokens)
10602
10630
  };
10603
10631
  }
10604
10632
  function normalizeLiveWorkerLimit(value) {
@@ -10704,10 +10732,7 @@ function freezeCorrelation(value) {
10704
10732
  * now reconciles its real partial spend instead of refunding work the provider already billed.
10705
10733
  */
10706
10734
  async function foldStream(stream, onProgress, signal) {
10707
- const tokens = {
10708
- input: 0,
10709
- output: 0
10710
- };
10735
+ const tokens = zeroTokenUsage();
10711
10736
  let tokensKnown = true;
10712
10737
  let usd = 0;
10713
10738
  let usdKnown = true;
@@ -10719,8 +10744,7 @@ async function foldStream(stream, onProgress, signal) {
10719
10744
  if (next.done) break;
10720
10745
  const ev = next.value;
10721
10746
  if (ev.kind === "tokens") {
10722
- tokens.input += ev.input;
10723
- tokens.output += ev.output;
10747
+ addTokenUsage(tokens, ev);
10724
10748
  if (ev.tokensKnown === false) tokensKnown = false;
10725
10749
  } else if (ev.kind === "cost") {
10726
10750
  usd += ev.usd;
@@ -10728,7 +10752,7 @@ async function foldStream(stream, onProgress, signal) {
10728
10752
  } else iterations += 1;
10729
10753
  onProgress?.({
10730
10754
  iterations,
10731
- tokens: { ...tokens },
10755
+ tokens: cloneTokenUsage(tokens),
10732
10756
  ...tokensKnown ? {} : { tokensKnown: false },
10733
10757
  usd,
10734
10758
  ...usdKnown ? {} : { usdKnown: false },
@@ -10751,8 +10775,16 @@ async function foldStream(stream, onProgress, signal) {
10751
10775
  /** Usage events carry measured increments; the terminal artifact carries whether a provider omitted
10752
10776
  * a whole accounting channel. Preserve those unknowns on the common streaming path. */
10753
10777
  function preserveUnknownTelemetry(streamed, terminal) {
10778
+ const terminalTokens = cloneTokenUsage(terminal.tokens);
10754
10779
  return {
10755
10780
  ...streamed,
10781
+ tokens: {
10782
+ ...streamed.tokens,
10783
+ ...streamed.tokens.freshInput === void 0 && terminalTokens.freshInput !== void 0 ? { freshInput: terminalTokens.freshInput } : {},
10784
+ ...streamed.tokens.cacheRead === void 0 && terminalTokens.cacheRead !== void 0 ? { cacheRead: terminalTokens.cacheRead } : {},
10785
+ ...streamed.tokens.cacheWrite === void 0 && terminalTokens.cacheWrite !== void 0 ? { cacheWrite: terminalTokens.cacheWrite } : {},
10786
+ ...streamed.tokens.cacheBreakdownKnown === false || terminalTokens.cacheBreakdownKnown === false ? { cacheBreakdownKnown: false } : {}
10787
+ },
10756
10788
  ...terminal.tokensKnown === false ? { tokensKnown: false } : {},
10757
10789
  ...terminal.usdKnown === false ? { usdKnown: false } : {},
10758
10790
  ms: terminal.ms
@@ -10807,10 +10839,7 @@ function downRecord(reason, infra, trace, metered) {
10807
10839
  function zeroSpend$1() {
10808
10840
  return {
10809
10841
  iterations: 0,
10810
- tokens: {
10811
- input: 0,
10812
- output: 0
10813
- },
10842
+ tokens: zeroTokenUsage(),
10814
10843
  usd: 0,
10815
10844
  ms: 0
10816
10845
  };
@@ -11059,20 +11088,15 @@ function isSettled(ev) {
11059
11088
  function sumSpend(settled) {
11060
11089
  const total = {
11061
11090
  iterations: 0,
11062
- tokens: {
11063
- input: 0,
11064
- output: 0
11065
- },
11091
+ tokens: zeroTokenUsage(),
11066
11092
  usd: 0,
11067
11093
  ms: 0
11068
11094
  };
11069
11095
  for (const ev of settled) {
11070
11096
  total.iterations += ev.spent.iterations;
11071
- total.tokens.input += ev.spent.tokens.input;
11072
- total.tokens.output += ev.spent.tokens.output;
11097
+ addTokenUsage(total.tokens, ev.spent.tokens);
11073
11098
  if (ev.spent.tokensKnown === false) total.tokensKnown = false;
11074
11099
  total.usd += ev.spent.usd;
11075
- if (ev.spent.tokensKnown === false) total.tokensKnown = false;
11076
11100
  if (ev.spent.usdKnown === false) total.usdKnown = false;
11077
11101
  total.ms += ev.spent.ms;
11078
11102
  }
@@ -11084,21 +11108,16 @@ function sumSpend(settled) {
11084
11108
  function sumMetered(events) {
11085
11109
  const total = {
11086
11110
  iterations: 0,
11087
- tokens: {
11088
- input: 0,
11089
- output: 0
11090
- },
11111
+ tokens: zeroTokenUsage(),
11091
11112
  usd: 0,
11092
11113
  ms: 0
11093
11114
  };
11094
11115
  for (const ev of events) {
11095
11116
  if (ev.kind !== "metered") continue;
11096
11117
  total.iterations += ev.spend.iterations;
11097
- total.tokens.input += ev.spend.tokens.input;
11098
- total.tokens.output += ev.spend.tokens.output;
11118
+ addTokenUsage(total.tokens, ev.spend.tokens);
11099
11119
  if (ev.spend.tokensKnown === false) total.tokensKnown = false;
11100
11120
  total.usd += ev.spend.usd;
11101
- if (ev.spend.tokensKnown === false) total.tokensKnown = false;
11102
11121
  if (ev.spend.usdKnown === false) total.usdKnown = false;
11103
11122
  total.ms += ev.spend.ms;
11104
11123
  }
@@ -11107,10 +11126,7 @@ function sumMetered(events) {
11107
11126
  function zeroSpend() {
11108
11127
  return {
11109
11128
  iterations: 0,
11110
- tokens: {
11111
- input: 0,
11112
- output: 0
11113
- },
11129
+ tokens: zeroTokenUsage(),
11114
11130
  usd: 0,
11115
11131
  ms: 0
11116
11132
  };
@@ -11118,10 +11134,11 @@ function zeroSpend() {
11118
11134
  function addSpend$1(a, b) {
11119
11135
  return {
11120
11136
  iterations: a.iterations + b.iterations,
11121
- tokens: {
11122
- input: a.tokens.input + b.tokens.input,
11123
- output: a.tokens.output + b.tokens.output
11124
- },
11137
+ tokens: (() => {
11138
+ const tokens = cloneTokenUsage(a.tokens);
11139
+ addTokenUsage(tokens, b.tokens);
11140
+ return tokens;
11141
+ })(),
11125
11142
  ...a.tokensKnown === false || b.tokensKnown === false ? { tokensKnown: false } : {},
11126
11143
  usd: a.usd + b.usd,
11127
11144
  ...a.usdKnown === false || b.usdKnown === false ? { usdKnown: false } : {},
@@ -11969,19 +11986,13 @@ function sumSpendFromEvents(events) {
11969
11986
  function sumMeasuredSpendFromEvents(events) {
11970
11987
  const childWork = {
11971
11988
  iterations: 0,
11972
- tokens: {
11973
- input: 0,
11974
- output: 0
11975
- },
11989
+ tokens: zeroTokenUsage(),
11976
11990
  usd: 0,
11977
11991
  ms: 0
11978
11992
  };
11979
11993
  const driverInference = {
11980
11994
  iterations: 0,
11981
- tokens: {
11982
- input: 0,
11983
- output: 0
11984
- },
11995
+ tokens: zeroTokenUsage(),
11985
11996
  usd: 0,
11986
11997
  ms: 0
11987
11998
  };
@@ -11995,8 +12006,7 @@ function sumMeasuredSpendFromEvents(events) {
11995
12006
  /** Add `b` into `a` in place, per channel. */
11996
12007
  function accumulate(a, b) {
11997
12008
  a.iterations += b.iterations;
11998
- a.tokens.input += b.tokens.input;
11999
- a.tokens.output += b.tokens.output;
12009
+ addTokenUsage(a.tokens, b.tokens);
12000
12010
  if (b.tokensKnown === false) a.tokensKnown = false;
12001
12011
  a.usd += b.usd;
12002
12012
  if (b.usdKnown === false) a.usdKnown = false;
@@ -12007,10 +12017,11 @@ function accumulate(a, b) {
12007
12017
  function addSpend(a, b) {
12008
12018
  return {
12009
12019
  iterations: a.iterations + b.iterations,
12010
- tokens: {
12011
- input: a.tokens.input + b.tokens.input,
12012
- output: a.tokens.output + b.tokens.output
12013
- },
12020
+ tokens: (() => {
12021
+ const tokens = cloneTokenUsage(a.tokens);
12022
+ addTokenUsage(tokens, b.tokens);
12023
+ return tokens;
12024
+ })(),
12014
12025
  ...a.tokensKnown === false || b.tokensKnown === false ? { tokensKnown: false } : {},
12015
12026
  usd: a.usd + b.usd,
12016
12027
  ...a.usdKnown === false || b.usdKnown === false ? { usdKnown: false } : {},
@@ -12026,4 +12037,4 @@ function isNonEmptySpend(s) {
12026
12037
  //#endregion
12027
12038
  export { createSandboxLineage as $, bindReusableExecutorExecutionId as A, removeWorktree as At, workerTraceSeamKey as B, defineProfileMaterializationContract as Bt, queueOf as C, sanitizeAgentRuntimeEvent as Ct, assertValidBudget as D, runWorktreeHarness as Dt, teardownExecutor as E, runSettledCommand as Et, snapshotExecutorConfig as F, parseCodexTokenUsage as Ft, sandboxSessionTraceSource as G, promptOnlyProfileMaterialization as Gt, createSteerableSandboxSession as H, profileMaterializationAxes$1 as Ht, createWorktreeCliExecutor as I, CodexExecutionDiagnosticError as It, readWorkerProgress as J, sandboxActProfileMaterialization as Jt, DEFAULT_STALL_AFTER_MS as K, promptResourceProfileMaterialization as Kt, WORKER_TRACE_PROPAGATION as L, AGENT_PROFILE_MATERIALIZATION_AXES as Lt, cliWorktreeExecutor as M, LOCAL_HARNESSES as Mt, createExecutor as N, harnessSupportsReasoningEffort as Nt, createBudgetPool as O, captureWorktreeDiff as Ot, createExecutorRegistry as P, localHarnessExecutable as Pt, runAgentRounds as Q, readWorkerTraceContext as R, assertProfileMaterialization as Rt, freeSlots as S, createRuntimeStreamEventCollector as St, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as T, sanitizeRuntimeStreamEvent as Tt, createPushTraceSource as U, promptControlProfileMaterialization as Ut, DEFAULT_SANDBOX_STEERING_MAX_TURNS as V, fullProfileMaterialization as Vt, decodeToolPart as W, promptModelProfileMaterialization as Wt, createSandboxForSpec as X, worktreeCliProfileMaterialization as Xt, createInbox as Y, validateProfileMaterialization as Yt, defaultSelectWinner as Z, pollFor as _, loopEventToOtelSpan as _t, pickBestDelivered as a, mergeTraceEnv as at, waitUntil as b, toOtelAttributes as bt, driverChild as c, INTELLIGENCE_WIRE_VERSION as ct, deriveNodeExecutionIdentity as d, buildRuntimeEventOtelSpans as dt, probeSandboxCapabilities as et, recordScopeOwnerMaterialization as f, createOpenInferenceFileExporter as ft, isWaitOutcome as g, generateSpanId as gt, createWaitProbes as h, flatOtelSpan as ht, collectDelivered as i, createPropagatingTraceEmitter as it, captureReusableExecutorConfig as j, DEFAULT_LOCAL_HARNESS as jt, spendFromUsageEvents as k, createWorktree as kt, withDriverExecutor as l, buildLoopOtelSpans as lt, settledToIteration as m, exportEvalRuns as mt, createSupervisor as n, routerBrain as nt, runFinalizer as o, readTraceContextFromEnv as ot, scopeOwnerExecutorNodeContext as p, createOtelExporter as pt, createActivityLog as q, renderProfileMaterializationIssues as qt, bestDelivered as r, runBrainLoop as rt, runTree as s, traceContextToEnv as st, createRootHandle as t, acquireSandbox as tt, createScope as u, buildLoopSpanNodes as ut, timerAt as v, padSpanId as vt, rollingDispatch as w, sanitizeKnowledgeReadinessReport as wt, effectiveConcurrency as x, createRuntimeEventCollector as xt, validateWaitSpec as y, padTraceId as yt, workerTraceEnv as z, controlProfileMaterialization as zt };
12028
12039
 
12029
- //# sourceMappingURL=supervisor-C16p9KqO.js.map
12040
+ //# sourceMappingURL=supervisor-CMtutocL.js.map