@tangle-network/agent-runtime 0.134.1 → 0.134.3

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 (88) hide show
  1. package/dist/{activation-BaxUkhEf.js → activation-BJS5eud7.js} +3 -3
  2. package/dist/{activation-BaxUkhEf.js.map → activation-BJS5eud7.js.map} +1 -1
  3. package/dist/agent.d.ts +2 -2
  4. package/dist/agent.js +3 -3
  5. package/dist/{analyst-loop-BKWqQhVI.js → analyst-loop-Dk6_xfhI.js} +2 -2
  6. package/dist/{analyst-loop-BKWqQhVI.js.map → analyst-loop-Dk6_xfhI.js.map} +1 -1
  7. package/dist/analyst-loop.d.ts +1 -1
  8. package/dist/analyst-loop.js +1 -1
  9. package/dist/{authoring-BlbRLEOS.js → authoring-zj6jq4HE.js} +2 -2
  10. package/dist/{authoring-BlbRLEOS.js.map → authoring-zj6jq4HE.js.map} +1 -1
  11. package/dist/candidate-execution/index.js +4 -4
  12. package/dist/{candidate-execution-CJRP9CcZ.js → candidate-execution-DDOdYrRO.js} +4 -4
  13. package/dist/{candidate-execution-CJRP9CcZ.js.map → candidate-execution-DDOdYrRO.js.map} +1 -1
  14. package/dist/{conversation-CrWcNPQg.js → conversation-DYVSghi8.js} +2 -2
  15. package/dist/{conversation-CrWcNPQg.js.map → conversation-DYVSghi8.js.map} +1 -1
  16. package/dist/conversation.d.ts +1 -1
  17. package/dist/conversation.js +1 -1
  18. package/dist/{environment-provider-qDOhdE9M.d.ts → environment-provider-CCASQ5FA.d.ts} +3 -3
  19. package/dist/{environment-provider-CwvY-Zeq.js → environment-provider-CLNVqp6H.js} +2 -2
  20. package/dist/{environment-provider-CwvY-Zeq.js.map → environment-provider-CLNVqp6H.js.map} +1 -1
  21. package/dist/environment-provider.d.ts +1 -1
  22. package/dist/environment-provider.js +1 -1
  23. package/dist/{graph-CKNenH2a.js → graph-D0bln4rR.js} +3 -3
  24. package/dist/{graph-CKNenH2a.js.map → graph-D0bln4rR.js.map} +1 -1
  25. package/dist/{improvement-cycle-CSBantKB.js → improvement-cycle-fezPL8Th.js} +6 -6
  26. package/dist/{improvement-cycle-CSBantKB.js.map → improvement-cycle-fezPL8Th.js.map} +1 -1
  27. package/dist/{index-Cz4qKBxm.d.ts → index-BDPN51IH.d.ts} +4 -4
  28. package/dist/{index-CgBJtAzI.d.ts → index-Dg4MfLHq.d.ts} +3 -3
  29. package/dist/{index-De10l_EU.d.ts → index-gevMEHnE.d.ts} +13 -11
  30. package/dist/index.d.ts +9 -9
  31. package/dist/index.js +13 -13
  32. package/dist/intelligence.d.ts +5 -5
  33. package/dist/intelligence.js +6 -6
  34. package/dist/kernel.d.ts +6 -6
  35. package/dist/kernel.js +10 -10
  36. package/dist/{knowledge-B2C9t1Z4.js → knowledge-BXtZD-pC.js} +5 -5
  37. package/dist/{knowledge-B2C9t1Z4.js.map → knowledge-BXtZD-pC.js.map} +1 -1
  38. package/dist/knowledge.d.ts +1 -1
  39. package/dist/knowledge.js +1 -1
  40. package/dist/{loop-runner-bin-C0ymKYU7.js → loop-runner-bin-CjDcX5ua.js} +4 -4
  41. package/dist/{loop-runner-bin-C0ymKYU7.js.map → loop-runner-bin-CjDcX5ua.js.map} +1 -1
  42. package/dist/{loop-runner-bin-D-tgbSPx.d.ts → loop-runner-bin-DvaXefJJ.d.ts} +3 -3
  43. package/dist/loop-runner-bin.d.ts +1 -1
  44. package/dist/loop-runner-bin.js +1 -1
  45. package/dist/mcp/bin.js +3 -3
  46. package/dist/mcp/index.d.ts +5 -5
  47. package/dist/mcp/index.js +5 -5
  48. package/dist/{openai-tools-CzEiSbPW.d.ts → openai-tools-CF2RMD7_.d.ts} +2 -2
  49. package/dist/{openai-tools-ClOkPIi0.js → openai-tools-CycyI0v2.js} +2 -2
  50. package/dist/{openai-tools-ClOkPIi0.js.map → openai-tools-CycyI0v2.js.map} +1 -1
  51. package/dist/{prepare-BXEtLOj9.js → prepare-Cv7NzRZl.js} +2 -2
  52. package/dist/{prepare-BXEtLOj9.js.map → prepare-Cv7NzRZl.js.map} +1 -1
  53. package/dist/primeintellect/index.d.ts +1 -1
  54. package/dist/profiles.d.ts +1 -1
  55. package/dist/{protected-model-port-B7PAmTGi.js → protected-model-port-RnAK2ZrP.js} +2 -2
  56. package/dist/{protected-model-port-B7PAmTGi.js.map → protected-model-port-RnAK2ZrP.js.map} +1 -1
  57. package/dist/{redact-6UE6pdNi.d.ts → redact-8ssmxJ0J.d.ts} +3 -3
  58. package/dist/{runtime-Bisfbn3_.js → runtime-Btwztu5V.js} +14 -11
  59. package/dist/runtime-Btwztu5V.js.map +1 -0
  60. package/dist/{runtime-DlxoqEj2.d.ts → runtime-CFD7S185.d.ts} +4 -4
  61. package/dist/{sandbox-events-vIwmuPdl.js → sandbox-events-CA2amHoA.js} +98 -3
  62. package/dist/sandbox-events-CA2amHoA.js.map +1 -0
  63. package/dist/{spawn-journal-B856eA8e.js → spawn-journal-ZKEKel8N.js} +10 -4
  64. package/dist/spawn-journal-ZKEKel8N.js.map +1 -0
  65. package/dist/{stream-agent-turn-CJog3ebs.d.ts → stream-agent-turn-8rmaOWtn.d.ts} +3 -3
  66. package/dist/{stream-agent-turn-CdIcf-bn.js → stream-agent-turn-DYBpzMmq.js} +2 -2
  67. package/dist/{stream-agent-turn-CdIcf-bn.js.map → stream-agent-turn-DYBpzMmq.js.map} +1 -1
  68. package/dist/{structural-rollout-DKEP5i__.js → structural-rollout-BHluS9JC.js} +4 -4
  69. package/dist/{structural-rollout-DKEP5i__.js.map → structural-rollout-BHluS9JC.js.map} +1 -1
  70. package/dist/{supervise-DhghNvl6.js → supervise-BvjQqKsp.js} +17 -6
  71. package/dist/{supervise-DhghNvl6.js.map → supervise-BvjQqKsp.js.map} +1 -1
  72. package/dist/{supervisor-CMlIOkJP.js → supervisor-BsniJxSa.js} +113 -29
  73. package/dist/supervisor-BsniJxSa.js.map +1 -0
  74. package/dist/testing.d.ts +2 -2
  75. package/dist/testing.js +12 -12
  76. package/dist/{types-6zHo67jn.d.ts → types-Cz4m4Iv6.d.ts} +3 -3
  77. package/dist/{types-D4BfurNs.d.ts → types-XtB9WZzr.d.ts} +26 -5
  78. package/dist/util-C1bv6yog.js +282 -0
  79. package/dist/util-C1bv6yog.js.map +1 -0
  80. package/dist/{workspace-archive-B5oJu5mZ.js → workspace-archive-DFwzVhbk.js} +2 -2
  81. package/dist/{workspace-archive-B5oJu5mZ.js.map → workspace-archive-DFwzVhbk.js.map} +1 -1
  82. package/package.json +1 -1
  83. package/dist/runtime-Bisfbn3_.js.map +0 -1
  84. package/dist/sandbox-events-vIwmuPdl.js.map +0 -1
  85. package/dist/spawn-journal-B856eA8e.js.map +0 -1
  86. package/dist/supervisor-CMlIOkJP.js.map +0 -1
  87. package/dist/util-DD8bRWPL.js +0 -194
  88. package/dist/util-DD8bRWPL.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  import { f as ValidationError, r as BackendTransportError, u as RuntimeRunStateError } from "./errors-CVIDr7GQ.js";
2
2
  import { t as detachedSnapshot } from "./snapshot-BOIprwBk.js";
3
- import { S as contentAddress, a as aggregateProviderModelEvidence, c as pendingWaits, g as runtimeOwnedNestedDriverTreeRoot, h as nestedDriverTreeRoot, l as replaySpawnTree, m as driverRuntime, o as loadSpawnForest, p as attestNestedDriverTreeOwner, s as materializeTreeView, v as captureWorkerTraceEvidence } from "./spawn-journal-B856eA8e.js";
4
- import { a as hasCompleteCacheBreakdown, c as randomSuffix, d as stringifySafe, f as throwAbort, h as zeroTokenUsage, i as deleteBoxSafe, l as randomUuid, m as withTimeout, n as chargedTokens, p as throwIfAborted, r as cloneTokenUsage, s as mapWithConcurrency, t as addTokenUsage, u as sleep } from "./util-DD8bRWPL.js";
5
- import { a as notifySandboxEventObserver, n as extractLlmCallEvent } from "./sandbox-events-vIwmuPdl.js";
3
+ import { S as contentAddress, a as aggregateProviderModelEvidence, c as pendingWaits, g as runtimeOwnedNestedDriverTreeRoot, h as nestedDriverTreeRoot, l as replaySpawnTree, m as driverRuntime, o as loadSpawnForest, p as attestNestedDriverTreeOwner, s as materializeTreeView, v as captureWorkerTraceEvidence } from "./spawn-journal-ZKEKel8N.js";
4
+ import { _ as zeroTokenUsage, a as hasCompleteCacheBreakdown, c as promptCacheTokenClasses, d as sleep, f as stringifySafe, g as withTimeout, h as usdEstimatedOf, i as deleteBoxSafe, l as randomSuffix, m as throwIfAborted, n as chargedTokens, p as throwAbort, r as cloneTokenUsage, s as mapWithConcurrency, t as addTokenUsage, u as randomUuid } from "./util-C1bv6yog.js";
5
+ import { a as notifySandboxEventObserver, n as extractLlmCallEvent } from "./sandbox-events-CA2amHoA.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-UTTc9Z-A.js";
7
7
  import { C as unknownExecutionBindingReceipt, E as executableAgentSpecSnapshot, S as runtimeOwnedScopeOwnerRuntime, T as executableAgentProfileSnapshot, a as authoredProfileDigest, b as runtimeOwnedExecutorProviderEvidence, c as knownExecutionBindingReceipt, f as recordRuntimeOwnedProviderAttemptStart, g as runtimeOwnedDeferredExecutorRuntime, h as recordRuntimeOwnedProviderModel, l as knownMaterializationReceipt, m as recordRuntimeOwnedProviderIdentityConflict, n as attestRuntimeOwnedExecutor, o as finalizeRuntimeOwnedPendingExecutor, p as recordRuntimeOwnedProviderDispatchNotStarted, r as attestRuntimeOwnedPendingExecutor, t as attestRuntimeOwnedDeferredExecutor, u as newExecutionAttemptId, v as runtimeOwnedExecutorExecutionBinding, w as unknownMaterializationReceipt, x as runtimeOwnedPendingExecutorMaterialization, y as runtimeOwnedExecutorMaterialization } from "./materialization-BP5zspr2.js";
8
- import { i as resolveAgentEnvironmentProvider, n as providerAsExecutor, r as providerAsSandboxClient } from "./environment-provider-CwvY-Zeq.js";
8
+ import { i as resolveAgentEnvironmentProvider, n as providerAsExecutor, r as providerAsSandboxClient } from "./environment-provider-CLNVqp6H.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";
@@ -4661,7 +4661,8 @@ async function executeIteration(args) {
4661
4661
  addTokenUsage(slot.tokenUsage, {
4662
4662
  input: llmCall.tokensIn,
4663
4663
  output: llmCall.tokensOut,
4664
- ...llmCall.tokensKnown === false ? { tokensKnown: false } : {}
4664
+ ...llmCall.tokensKnown === false ? { tokensKnown: false } : {},
4665
+ ...promptCacheTokenClasses(llmCall.tokensIn, llmCall.promptCache)
4665
4666
  });
4666
4667
  args.ctx.runHandle?.observe(llmCall);
4667
4668
  }
@@ -5033,6 +5034,44 @@ function hashJson(value) {
5033
5034
  return (h >>> 0).toString(16).padStart(8, "0");
5034
5035
  }
5035
5036
  //#endregion
5037
+ //#region src/runtime/supervise/cost-estimate.ts
5038
+ /**
5039
+ * Pricing for work that arrived without a provider receipt.
5040
+ *
5041
+ * A turn whose provider reported no billed dollars used to reach the dollar channel as a
5042
+ * known `$0`, so a run that certainly spent money reported a dollar total of zero. A catalog
5043
+ * price is not a receipt, so what this module produces is always marked, never promoted.
5044
+ */
5045
+ /**
5046
+ * Price one unit of work that no provider receipt covered.
5047
+ *
5048
+ * The event always carries `usdKnown: false`: a catalog price approximates what a provider
5049
+ * WOULD bill, never measures what it did. The priced amount is repeated in `usdEstimated` so
5050
+ * a consumer can subtract it from `usd` and recover the dollars a provider actually billed.
5051
+ *
5052
+ * A model with no catalog entry yields `usd: 0` with `usdKnown: false` and no `usdEstimated`.
5053
+ * The turn then reads as unknown dollars, which is true, rather than as a free turn.
5054
+ */
5055
+ function priceUnreceiptedWork(work) {
5056
+ const unknown = {
5057
+ kind: "cost",
5058
+ usd: 0,
5059
+ usdKnown: false
5060
+ };
5061
+ const { inputTokens, outputTokens, model } = work;
5062
+ if (model === void 0 || !isModelPriced(model)) return unknown;
5063
+ if (!Number.isFinite(inputTokens) || !Number.isFinite(outputTokens)) return unknown;
5064
+ if (inputTokens < 0 || outputTokens < 0) return unknown;
5065
+ const usd = estimateCost(inputTokens, outputTokens, model);
5066
+ if (!Number.isFinite(usd) || usd <= 0) return unknown;
5067
+ return {
5068
+ kind: "cost",
5069
+ usd,
5070
+ usdKnown: false,
5071
+ usdEstimated: usd
5072
+ };
5073
+ }
5074
+ //#endregion
5036
5075
  //#region src/runtime/supervise/inbox.ts
5037
5076
  function parseDown(msg) {
5038
5077
  if (!msg || typeof msg !== "object") return void 0;
@@ -5473,14 +5512,15 @@ function createSteerableSandboxSession(args) {
5473
5512
  const input = call.tokensIn ?? 0;
5474
5513
  const output = call.tokensOut ?? 0;
5475
5514
  if (input || output || !callTokensKnown) {
5476
- tokens.input += input;
5477
- tokens.output += output;
5478
- yield {
5515
+ const usage = {
5479
5516
  kind: "tokens",
5480
5517
  input,
5481
5518
  output,
5482
- ...callTokensKnown ? {} : { tokensKnown: false }
5519
+ ...callTokensKnown ? {} : { tokensKnown: false },
5520
+ ...promptCacheTokenClasses(call.tokensIn, call.promptCache)
5483
5521
  };
5522
+ addTokenUsage(tokens, usage);
5523
+ yield usage;
5484
5524
  }
5485
5525
  if (typeof call.costUsd === "number" && call.costUsd > 0) {
5486
5526
  usd += call.costUsd;
@@ -7288,6 +7328,7 @@ async function* streamBridgeSession(args) {
7288
7328
  let tokensKnown = true;
7289
7329
  let usd = 0;
7290
7330
  let usdKnown = true;
7331
+ let estimatedUsdCharged = 0;
7291
7332
  let estimatedUsd = 0;
7292
7333
  let sawEstimatedUsd = false;
7293
7334
  let turns = 0;
@@ -7365,6 +7406,8 @@ async function* streamBridgeSession(args) {
7365
7406
  let turnUsdKnown = true;
7366
7407
  let turnKnownCostSubtotal = 0;
7367
7408
  let turnEstimatedCostSubtotal = 0;
7409
+ let turnInputTokens = 0;
7410
+ let turnOutputTokens = 0;
7368
7411
  let interrupted = false;
7369
7412
  let profileMaterializationPublished = false;
7370
7413
  const publishProfileMaterialization = () => {
@@ -7423,6 +7466,8 @@ async function* streamBridgeSession(args) {
7423
7466
  if (chunk.usage) {
7424
7467
  sawTurnTokenUsage = true;
7425
7468
  if (!chunk.usage.known) turnTokensKnown = false;
7469
+ turnInputTokens += chunk.usage.input;
7470
+ turnOutputTokens += chunk.usage.output;
7426
7471
  const usageEvent = {
7427
7472
  kind: "tokens",
7428
7473
  input: chunk.usage.input,
@@ -7436,8 +7481,8 @@ async function* streamBridgeSession(args) {
7436
7481
  yield usageEvent;
7437
7482
  if (chunk.usage.promptCache) {
7438
7483
  if (chunk.usage.promptCache.freshInput !== void 0) promptCache.freshInput = (promptCache.freshInput ?? 0) + chunk.usage.promptCache.freshInput;
7439
- if (chunk.usage.promptCache.readInput !== void 0) promptCache.readInput = (promptCache.readInput ?? 0) + chunk.usage.promptCache.readInput;
7440
- if (chunk.usage.promptCache.writeInput !== void 0) promptCache.writeInput = (promptCache.writeInput ?? 0) + chunk.usage.promptCache.writeInput;
7484
+ if (chunk.usage.promptCache.readInput !== void 0) promptCache.readTokens = (promptCache.readTokens ?? 0) + chunk.usage.promptCache.readInput;
7485
+ if (chunk.usage.promptCache.writeInput !== void 0) promptCache.writeTokens = (promptCache.writeTokens ?? 0) + chunk.usage.promptCache.writeInput;
7441
7486
  }
7442
7487
  }
7443
7488
  if (chunk.costKnown !== void 0) {
@@ -7490,11 +7535,20 @@ async function* streamBridgeSession(args) {
7490
7535
  });
7491
7536
  if (!sawTurnTokenUsage || !turnTokensKnown) tokensKnown = false;
7492
7537
  if (!sawTurnCostStatus || !turnUsdKnown) usdKnown = false;
7493
- if (!sawTurnCostStatus || !turnUsdKnown) yield {
7494
- kind: "cost",
7495
- usd: 0,
7496
- usdKnown: false
7497
- };
7538
+ if (!sawTurnCostStatus || !turnUsdKnown) {
7539
+ const priced = turnKnownCostSubtotal === 0 ? priceUnreceiptedWork({
7540
+ inputTokens: turnInputTokens,
7541
+ outputTokens: turnOutputTokens,
7542
+ model: observedModel ?? seam.providerModel
7543
+ }) : {
7544
+ kind: "cost",
7545
+ usd: 0,
7546
+ usdKnown: false
7547
+ };
7548
+ if (priced.usdEstimated !== void 0) estimatedUsdCharged += priced.usdEstimated;
7549
+ usd += priced.usd;
7550
+ yield priced;
7551
+ }
7498
7552
  yield { kind: "iteration" };
7499
7553
  if (!interrupted && turnText) lastText = turnText;
7500
7554
  if (interrupted) {
@@ -7514,6 +7568,7 @@ async function* streamBridgeSession(args) {
7514
7568
  ...tokensKnown ? {} : { tokensKnown: false },
7515
7569
  usd,
7516
7570
  ...usdKnown ? {} : { usdKnown: false },
7571
+ ...estimatedUsdCharged > 0 ? { usdEstimated: estimatedUsdCharged } : {},
7517
7572
  ms: Date.now() - started
7518
7573
  };
7519
7574
  const out = {
@@ -8978,13 +9033,17 @@ function mergeAbortSignals(...signals) {
8978
9033
  * channels (`LoopTokenUsage` has no `usd`); iterations are conserved alongside them.
8979
9034
  *
8980
9035
  * The token unit is `chargedTokens`: every token counted ONCE, when it first enters the context
8981
- * (`freshInput + cacheWrite + output`). A cached prefix is re-presented content that was already
8982
- * charged when it was written, so charging a cache read again would charge the same tokens twice —
8983
- * on a real fleet cache is 98% of the rolled-up prompt total, which made a declared cap bite about
8984
- * 56x early. No price weight enters the token channel; money is budgeted separately on `maxUsd`.
8985
- * When a provider reports no usable cache split the pool keeps charging the rolled-up
8986
- * `input + output` and marks `readout().cacheBreakdownKnown` false, so the balance reads as an
8987
- * upper bound on newly-presented work rather than a measurement.
9036
+ * (`input cacheRead + output`, which is `freshInput + cacheWrite + output` under a complete
9037
+ * split). A cached prefix is re-presented content that was already charged when it was written, so
9038
+ * charging a cache read again would charge the same tokens twice on a real fleet cache is 98% of
9039
+ * the rolled-up prompt total, which made a declared cap bite about 56x early. No price weight
9040
+ * enters the token channel; money is budgeted separately on `maxUsd`. The unit is additive, so a
9041
+ * child's settlement charges what its turns charged and a rolled-up report agrees with the pool.
9042
+ * Prompt tokens the provider never classified are charged in full, and
9043
+ * `readout().cacheBreakdownKnown` then reads false, so the balance reads as an upper bound on
9044
+ * newly-presented work rather than a measurement. The pool trusts a reported cache read the same way
9045
+ * it trusts a reported `input`: the token channel is an accounting unit, not a trust boundary
9046
+ * against a provider that misreports its own usage.
8988
9047
  *
8989
9048
  * Pure and deterministic: `now()` is injected, there is no I/O, and no wall-clock or
8990
9049
  * RNG read. A `reserve`/`reconcile` ticket is single-use (fail-loud on double or
@@ -9035,8 +9094,18 @@ function assertValidSpend(spend, label) {
9035
9094
  }
9036
9095
  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`);
9037
9096
  const { freshInput, cacheRead, cacheWrite } = spend.tokens;
9038
- 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`);
9097
+ if (freshInput !== void 0 && cacheRead !== void 0 && cacheWrite !== void 0) {
9098
+ const classified = freshInput + cacheRead + cacheWrite;
9099
+ if (spend.tokens.cacheBreakdownKnown !== false) {
9100
+ if (classified !== spend.tokens.input) throw new Error(`${label}.tokens cache classes must sum to input`);
9101
+ } else if (classified > spend.tokens.input) throw new Error(`${label}.tokens cache classes must not exceed input`);
9102
+ }
9039
9103
  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`);
9104
+ if (spend.usdEstimated !== void 0) {
9105
+ if (!Number.isFinite(spend.usdEstimated) || spend.usdEstimated < 0) throw new Error(`${label}.usdEstimated must be a non-negative finite number`);
9106
+ if (spend.usdEstimated > spend.usd) throw new Error(`${label}.usdEstimated must not exceed ${label}.usd`);
9107
+ if (spend.usdKnown !== false) throw new Error(`${label}.usdEstimated requires ${label}.usdKnown false`);
9108
+ }
9040
9109
  }
9041
9110
  /** Fold a normalized `UsageEvent` array into a `Spend`. Tokens and usd are separate
9042
9111
  * channels; iterations come from `'iteration'` events. Pure; `ms` stays zero (the
@@ -9045,6 +9114,7 @@ function spendFromUsageEvents(events) {
9045
9114
  const tokens = zeroTokenUsage();
9046
9115
  let tokensKnown = true;
9047
9116
  let usd = 0;
9117
+ let usdEstimated = 0;
9048
9118
  let usdKnown = true;
9049
9119
  let iterations = 0;
9050
9120
  for (const ev of events) if (ev.kind === "tokens") {
@@ -9052,6 +9122,7 @@ function spendFromUsageEvents(events) {
9052
9122
  if (ev.tokensKnown === false) tokensKnown = false;
9053
9123
  } else if (ev.kind === "cost") {
9054
9124
  usd += ev.usd;
9125
+ usdEstimated += ev.usdEstimated ?? 0;
9055
9126
  if (ev.usdKnown === false) usdKnown = false;
9056
9127
  } else iterations += 1;
9057
9128
  return {
@@ -9060,6 +9131,7 @@ function spendFromUsageEvents(events) {
9060
9131
  ...tokensKnown ? {} : { tokensKnown: false },
9061
9132
  usd,
9062
9133
  ...usdKnown ? {} : { usdKnown: false },
9134
+ ...usdEstimated > 0 ? { usdEstimated } : {},
9063
9135
  ms: 0
9064
9136
  };
9065
9137
  }
@@ -9068,6 +9140,7 @@ async function foldUsage(events) {
9068
9140
  const tokens = zeroTokenUsage();
9069
9141
  let tokensKnown = true;
9070
9142
  let usd = 0;
9143
+ let usdEstimated = 0;
9071
9144
  let usdKnown = true;
9072
9145
  let iterations = 0;
9073
9146
  for await (const ev of events) if (ev.kind === "tokens") {
@@ -9075,6 +9148,7 @@ async function foldUsage(events) {
9075
9148
  if (ev.tokensKnown === false) tokensKnown = false;
9076
9149
  } else if (ev.kind === "cost") {
9077
9150
  usd += ev.usd;
9151
+ usdEstimated += ev.usdEstimated ?? 0;
9078
9152
  if (ev.usdKnown === false) usdKnown = false;
9079
9153
  } else iterations += 1;
9080
9154
  return {
@@ -9083,6 +9157,7 @@ async function foldUsage(events) {
9083
9157
  ...tokensKnown ? {} : { tokensKnown: false },
9084
9158
  usd,
9085
9159
  ...usdKnown ? {} : { usdKnown: false },
9160
+ ...usdEstimated > 0 ? { usdEstimated } : {},
9086
9161
  ms: 0
9087
9162
  };
9088
9163
  }
@@ -9171,8 +9246,8 @@ function createBudgetPool(root, now = Date.now, restore = {}) {
9171
9246
  let violation;
9172
9247
  if (spentTokens > rTokens) violation = `ticket ${ticket.id} spent ${spentTokens} tokens > reserved ${rTokens}`;
9173
9248
  else if (spent.iterations > rIterations) violation = `ticket ${ticket.id} spent ${spent.iterations} iterations > reserved ${rIterations}`;
9174
- else if (usdCapped && usdBudgeted && spent.usd > rUsd) violation = `ticket ${ticket.id} spent $${spent.usd} > reserved $${rUsd}`;
9175
9249
  else if (unknownUnderCap) violation = `ticket ${ticket.id} reported unknown dollar cost under a dollar-capped budget`;
9250
+ else if (usdCapped && usdBudgeted && spent.usd > rUsd) violation = `ticket ${ticket.id} spent $${spent.usd} > reserved $${rUsd}`;
9176
9251
  open.delete(ticket.id);
9177
9252
  if (spent.tokensKnown === false) tokensTainted = true;
9178
9253
  if (!hasCompleteCacheBreakdown(spent.tokens)) cacheBreakdownTainted = true;
@@ -10383,7 +10458,7 @@ function createScope(args) {
10383
10458
  return;
10384
10459
  }
10385
10460
  }
10386
- async function meterInternal(spend, detail, providerModel) {
10461
+ async function meterInternal(spend, detail, providerModel, accountingOnly = false) {
10387
10462
  if (args.signal.aborted) throw new ValidationError("scope.meter: cannot record new driver work after scope abort");
10388
10463
  const seq = meterSeq++;
10389
10464
  let observeError;
@@ -10396,6 +10471,7 @@ function createScope(args) {
10396
10471
  kind: "metered",
10397
10472
  id: args.parentId,
10398
10473
  spend,
10474
+ ...accountingOnly ? { accountingOnly: true } : {},
10399
10475
  ...providerModel === void 0 ? {} : { providerModel: detachedSnapshot(providerModel, "runtime provider model evidence") },
10400
10476
  seq,
10401
10477
  at: new Date(now()).toISOString()
@@ -10445,7 +10521,7 @@ function createScope(args) {
10445
10521
  };
10446
10522
  }
10447
10523
  };
10448
- runtimeOwnedProviderMeters.set(scope, async (spend, providerModel, detail) => meterInternal(spend, detail, providerModel));
10524
+ runtimeOwnedProviderMeters.set(scope, async (spend, providerModel, detail, accountingOnly) => meterInternal(spend, detail, providerModel, accountingOnly));
10449
10525
  if (args.ownerMaterialization !== void 0) {
10450
10526
  const authoredProfile = args.ownerMaterialization.authoredProfile === void 0 ? void 0 : detachedSnapshot(args.ownerMaterialization.authoredProfile, "scope owner authored profile");
10451
10527
  ownerMaterializationStates.set(scope, {
@@ -10473,6 +10549,12 @@ function meterRuntimeOwnedProviderAttempt(scope, spend, providerModel, detail) {
10473
10549
  if (meter === void 0) throw new ValidationError("scope: Runtime-owned provider meter is not bound to this scope");
10474
10550
  return meter(spend, providerModel, detail);
10475
10551
  }
10552
+ /** @internal Meter Runtime-owned accounting that does not represent provider execution. */
10553
+ function meterRuntimeOwnedAccounting(scope, spend, detail) {
10554
+ const meter = runtimeOwnedProviderMeters.get(scope);
10555
+ if (meter === void 0) throw new ValidationError("scope: Runtime-owned provider meter is not bound to this scope");
10556
+ return meter(spend, void 0, detail, true);
10557
+ }
10476
10558
  const ownerMaterializationStates = /* @__PURE__ */ new WeakMap();
10477
10559
  /**
10478
10560
  * @internal Publish exact root-manager materialization from a runtime-owned adapter after dynamic
@@ -12413,6 +12495,7 @@ function accumulate(a, b) {
12413
12495
  if (b.tokensKnown === false) a.tokensKnown = false;
12414
12496
  a.usd += b.usd;
12415
12497
  if (b.usdKnown === false) a.usdKnown = false;
12498
+ if (b.usdEstimated !== void 0) a.usdEstimated = (a.usdEstimated ?? 0) + b.usdEstimated;
12416
12499
  a.ms += b.ms;
12417
12500
  }
12418
12501
  /** Sum two conserved-spend tallies per channel — the child-work journal sum + the drivers' own
@@ -12428,6 +12511,7 @@ function addSpend(a, b) {
12428
12511
  ...a.tokensKnown === false || b.tokensKnown === false ? { tokensKnown: false } : {},
12429
12512
  usd: a.usd + b.usd,
12430
12513
  ...a.usdKnown === false || b.usdKnown === false ? { usdKnown: false } : {},
12514
+ ...usdEstimatedOf(a, b),
12431
12515
  ms: a.ms + b.ms
12432
12516
  };
12433
12517
  }
@@ -12438,6 +12522,6 @@ function isNonEmptySpend(s) {
12438
12522
  return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0 || s.tokensKnown === false || s.usdKnown === false;
12439
12523
  }
12440
12524
  //#endregion
12441
- export { createSandboxForSpec as $, sandboxActProfileMaterialization as $t, spendFromUsageEvents as A, sanitizeRuntimeStreamEvent as At, readWorkerTraceContext as B, parseCodexTokenUsage as Bt, freeSlots as C, padSpanId as Ct, teardownExecutor as D, createRuntimeStreamEventCollector as Dt, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as E, createRuntimeEventCollector as Et, createExecutor as F, removeWorktree as Ft, createSteerableSandboxSession as G, defineProfileMaterializationContract as Gt, workerTraceHeaders as H, AGENT_PROFILE_MATERIALIZATION_AXES as Ht, createExecutorRegistry as I, DEFAULT_LOCAL_HARNESS as It, sandboxSessionTraceSource as J, promptControlProfileMaterialization as Jt, createPushTraceSource as K, fullProfileMaterialization as Kt, snapshotExecutorConfig as L, LOCAL_HARNESSES as Lt, bridgeStopSignalKey as M, runWorktreeHarness as Mt, captureReusableExecutorConfig as N, captureWorktreeDiff as Nt, assertValidBudget as O, sanitizeAgentRuntimeEvent as Ot, cliWorktreeExecutor as P, createWorktree as Pt, createInbox as Q, renderProfileMaterializationIssues as Qt, createWorktreeCliExecutor as R, harnessSupportsReasoningEffort as Rt, effectiveConcurrency as S, loopEventToOtelSpan as St, rollingDispatch as T, toOtelAttributes as Tt, workerTraceSeamKey as U, assertProfileMaterialization as Ut, workerTraceEnv as V, CodexExecutionDiagnosticError as Vt, DEFAULT_SANDBOX_STEERING_MAX_TURNS as W, controlProfileMaterialization as Wt, createActivityLog as X, promptOnlyProfileMaterialization as Xt, DEFAULT_STALL_AFTER_MS as Y, promptModelProfileMaterialization as Yt, readWorkerProgress as Z, promptResourceProfileMaterialization as Zt, isWaitOutcome as _, createOpenInferenceFileExporter as _t, pickBestDelivered as a, routerBrain as at, validateWaitSpec as b, flatOtelSpan as bt, driverChild as c, observedModelMatchesDeclared as ct, deriveNodeExecutionIdentity as d, readTraceContextFromEnv as dt, validateProfileMaterialization as en, defaultSelectWinner as et, meterRuntimeOwnedProviderAttempt as f, traceContextToEnv as ft, createWaitProbes as g, buildRuntimeEventOtelSpans as gt, settledToIteration as h, buildLoopSpanNodes as ht, collectDelivered as i, acquireSandbox as it, bindReusableExecutorExecutionId as j, runSettledCommand as jt, createBudgetPool as k, sanitizeKnowledgeReadinessReport as kt, withDriverExecutor as l, createPropagatingTraceEmitter as lt, scopeOwnerExecutorNodeContext as m, buildLoopOtelSpans as mt, createSupervisor as n, createSandboxLineage as nt, runFinalizer as o, runBrainLoop as ot, recordScopeOwnerMaterialization as p, INTELLIGENCE_WIRE_VERSION as pt, decodeToolPart as q, profileMaterializationAxes$1 as qt, bestDelivered as r, probeSandboxCapabilities as rt, runTree as s, canonicalObservedModel as st, createRootHandle as t, worktreeCliProfileMaterialization as tn, runAgentRounds as tt, createScope as u, mergeTraceEnv as ut, pollFor as v, createOtelExporter as vt, queueOf as w, padTraceId as wt, waitUntil as x, generateSpanId as xt, timerAt as y, exportEvalRuns as yt, WORKER_TRACE_PROPAGATION as z, localHarnessExecutable as zt };
12525
+ export { createInbox as $, renderProfileMaterializationIssues as $t, createBudgetPool as A, sanitizeKnowledgeReadinessReport as At, WORKER_TRACE_PROPAGATION as B, localHarnessExecutable as Bt, effectiveConcurrency as C, loopEventToOtelSpan as Ct, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as D, createRuntimeEventCollector as Dt, rollingDispatch as E, toOtelAttributes as Et, cliWorktreeExecutor as F, createWorktree as Ft, DEFAULT_SANDBOX_STEERING_MAX_TURNS as G, controlProfileMaterialization as Gt, workerTraceEnv as H, CodexExecutionDiagnosticError as Ht, createExecutor as I, removeWorktree as It, decodeToolPart as J, profileMaterializationAxes$1 as Jt, createSteerableSandboxSession as K, defineProfileMaterializationContract as Kt, createExecutorRegistry as L, DEFAULT_LOCAL_HARNESS as Lt, bindReusableExecutorExecutionId as M, runSettledCommand as Mt, bridgeStopSignalKey as N, runWorktreeHarness as Nt, teardownExecutor as O, createRuntimeStreamEventCollector as Ot, captureReusableExecutorConfig as P, captureWorktreeDiff as Pt, readWorkerProgress as Q, promptResourceProfileMaterialization as Qt, snapshotExecutorConfig as R, LOCAL_HARNESSES as Rt, waitUntil as S, generateSpanId as St, queueOf as T, padTraceId as Tt, workerTraceHeaders as U, AGENT_PROFILE_MATERIALIZATION_AXES as Ut, readWorkerTraceContext as V, parseCodexTokenUsage as Vt, workerTraceSeamKey as W, assertProfileMaterialization as Wt, DEFAULT_STALL_AFTER_MS as X, promptModelProfileMaterialization as Xt, sandboxSessionTraceSource as Y, promptControlProfileMaterialization as Yt, createActivityLog as Z, promptOnlyProfileMaterialization as Zt, createWaitProbes as _, buildRuntimeEventOtelSpans as _t, pickBestDelivered as a, acquireSandbox as at, timerAt as b, exportEvalRuns as bt, driverChild as c, canonicalObservedModel as ct, deriveNodeExecutionIdentity as d, mergeTraceEnv as dt, sandboxActProfileMaterialization as en, createSandboxForSpec as et, meterRuntimeOwnedAccounting as f, readTraceContextFromEnv as ft, settledToIteration as g, buildLoopSpanNodes as gt, scopeOwnerExecutorNodeContext as h, buildLoopOtelSpans as ht, collectDelivered as i, probeSandboxCapabilities as it, spendFromUsageEvents as j, sanitizeRuntimeStreamEvent as jt, assertValidBudget as k, sanitizeAgentRuntimeEvent as kt, withDriverExecutor as l, observedModelMatchesDeclared as lt, recordScopeOwnerMaterialization as m, INTELLIGENCE_WIRE_VERSION as mt, createSupervisor as n, worktreeCliProfileMaterialization as nn, runAgentRounds as nt, runFinalizer as o, routerBrain as ot, meterRuntimeOwnedProviderAttempt as p, traceContextToEnv as pt, createPushTraceSource as q, fullProfileMaterialization as qt, bestDelivered as r, createSandboxLineage as rt, runTree as s, runBrainLoop as st, createRootHandle as t, validateProfileMaterialization as tn, defaultSelectWinner as tt, createScope as u, createPropagatingTraceEmitter as ut, isWaitOutcome as v, createOpenInferenceFileExporter as vt, freeSlots as w, padSpanId as wt, validateWaitSpec as x, flatOtelSpan as xt, pollFor as y, createOtelExporter as yt, createWorktreeCliExecutor as z, harnessSupportsReasoningEffort as zt };
12442
12526
 
12443
- //# sourceMappingURL=supervisor-CMlIOkJP.js.map
12527
+ //# sourceMappingURL=supervisor-BsniJxSa.js.map