@tangle-network/agent-runtime 0.134.2 → 0.134.4

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-CY_v6Ia7.js → activation-q9Zo4NRy.js} +3 -3
  2. package/dist/{activation-CY_v6Ia7.js.map → activation-q9Zo4NRy.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-BDICoQby.js → authoring-CmzMOTKX.js} +2 -2
  10. package/dist/{authoring-BDICoQby.js.map → authoring-CmzMOTKX.js.map} +1 -1
  11. package/dist/candidate-execution/index.js +4 -4
  12. package/dist/{candidate-execution-CWMkOz7g.js → candidate-execution-CyCLYLfK.js} +4 -4
  13. package/dist/{candidate-execution-CWMkOz7g.js.map → candidate-execution-CyCLYLfK.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-CPHwqLLm.js → environment-provider-CLNVqp6H.js} +2 -2
  19. package/dist/{environment-provider-CPHwqLLm.js.map → environment-provider-CLNVqp6H.js.map} +1 -1
  20. package/dist/{environment-provider-qDOhdE9M.d.ts → environment-provider-DIRm41xB.d.ts} +3 -3
  21. package/dist/environment-provider.d.ts +1 -1
  22. package/dist/environment-provider.js +1 -1
  23. package/dist/{graph-D5TKFG8R.js → graph-B0wXX8Pr.js} +3 -3
  24. package/dist/{graph-D5TKFG8R.js.map → graph-B0wXX8Pr.js.map} +1 -1
  25. package/dist/{improvement-cycle-XLPktFtP.js → improvement-cycle-4dO93TTE.js} +6 -6
  26. package/dist/{improvement-cycle-XLPktFtP.js.map → improvement-cycle-4dO93TTE.js.map} +1 -1
  27. package/dist/{index-DBZTN4ci.d.ts → index-7VFw3_z0.d.ts} +4 -4
  28. package/dist/{index-CgBJtAzI.d.ts → index-BbdLlSh6.d.ts} +3 -3
  29. package/dist/{index-DiUDbnk-.d.ts → index-SWNlB0Hv.d.ts} +29 -23
  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 +7 -7
  35. package/dist/kernel.js +10 -10
  36. package/dist/{knowledge-Dv2HMnE6.js → knowledge-EDOC3wEs.js} +5 -5
  37. package/dist/{knowledge-Dv2HMnE6.js.map → knowledge-EDOC3wEs.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-Bieu4QO4.js → loop-runner-bin-CoBcsxpe.js} +4 -4
  41. package/dist/{loop-runner-bin-Bieu4QO4.js.map → loop-runner-bin-CoBcsxpe.js.map} +1 -1
  42. package/dist/{loop-runner-bin-D5JXvb_l.d.ts → loop-runner-bin-DXqzpr4i.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-D4Rf0Ciu.js → openai-tools-BQHlv-Ex.js} +2 -2
  49. package/dist/{openai-tools-D4Rf0Ciu.js.map → openai-tools-BQHlv-Ex.js.map} +1 -1
  50. package/dist/{openai-tools-CzEiSbPW.d.ts → openai-tools-BulrPqjW.d.ts} +2 -2
  51. package/dist/{prepare-BxP7Hq1l.js → prepare-Czki1LBy.js} +4 -2
  52. package/dist/{prepare-BxP7Hq1l.js.map → prepare-Czki1LBy.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-B82zDDu5.js → protected-model-port-OhS0l_6m.js} +2 -2
  56. package/dist/{protected-model-port-B82zDDu5.js.map → protected-model-port-OhS0l_6m.js.map} +1 -1
  57. package/dist/{redact-6UE6pdNi.d.ts → redact-DTVIFTeR.d.ts} +3 -3
  58. package/dist/{runtime-DlxoqEj2.d.ts → runtime-C60zv0Q4.d.ts} +4 -4
  59. package/dist/{runtime-Ox-uvtni.js → runtime-DJMlvPY7.js} +14 -11
  60. package/dist/runtime-DJMlvPY7.js.map +1 -0
  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-TJSlDa2J.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-BLuTjcvw.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-CnHKUCVM.js → structural-rollout-GX7EzxeM.js} +4 -4
  69. package/dist/{structural-rollout-CnHKUCVM.js.map → structural-rollout-GX7EzxeM.js.map} +1 -1
  70. package/dist/{supervise-BNOccEtp.js → supervise-7JtBc_eW.js} +6 -6
  71. package/dist/{supervise-BNOccEtp.js.map → supervise-7JtBc_eW.js.map} +1 -1
  72. package/dist/{supervisor-4r4BYSti.js → supervisor-Bfh5Gq_P.js} +147 -33
  73. package/dist/supervisor-Bfh5Gq_P.js.map +1 -0
  74. package/dist/testing.d.ts +2 -2
  75. package/dist/testing.js +108 -96
  76. package/dist/testing.js.map +1 -1
  77. package/dist/{types-D4BfurNs.d.ts → types-CfQbuWgo.d.ts} +26 -5
  78. package/dist/{types-6zHo67jn.d.ts → types-DzZCZcwI.d.ts} +14 -14
  79. package/dist/{util-CG3ghHfb.js → util-C1bv6yog.js} +60 -2
  80. package/dist/util-C1bv6yog.js.map +1 -0
  81. package/dist/{workspace-archive-BwJQSvGi.js → workspace-archive-B_JDld25.js} +2 -2
  82. package/dist/{workspace-archive-BwJQSvGi.js.map → workspace-archive-B_JDld25.js.map} +1 -1
  83. package/package.json +10 -10
  84. package/dist/runtime-Ox-uvtni.js.map +0 -1
  85. package/dist/sandbox-events-vIwmuPdl.js.map +0 -1
  86. package/dist/spawn-journal-TJSlDa2J.js.map +0 -1
  87. package/dist/supervisor-4r4BYSti.js.map +0 -1
  88. package/dist/util-CG3ghHfb.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-TJSlDa2J.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-CG3ghHfb.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-CPHwqLLm.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";
@@ -4164,6 +4164,28 @@ function createSandboxLineage(client, capabilities, options = {}) {
4164
4164
  async fork(parent, prompts, specs, signal) {
4165
4165
  if (prompts.length === 0) throw new ValidationError("SandboxLineage.fork: prompts must be non-empty");
4166
4166
  if (signal.aborted) throwAbort();
4167
+ const branched = await branchParent(parent.box, prompts.length, forkConcurrency, signal);
4168
+ if (branched !== void 0) {
4169
+ owned.push(...branched);
4170
+ if (branched.length !== prompts.length) throw new ValidationError(`SandboxLineage.fork: Sandbox returned ${branched.length} of ${prompts.length} requested children`);
4171
+ return mapWithConcurrency(branched, forkConcurrency, async (box, i) => {
4172
+ throwIfAborted(signal);
4173
+ const spec = specs[i % specs.length];
4174
+ if (!spec) throw new ValidationError("SandboxLineage.fork: no AgentRunSpec for branch");
4175
+ await spec.prepareBox?.(box, {
4176
+ signal,
4177
+ recordMount
4178
+ });
4179
+ const sessionId = mintSessionId();
4180
+ return {
4181
+ handle: {
4182
+ box,
4183
+ sessionId
4184
+ },
4185
+ events: promptEvents(streaming, box, prompts[i], sessionId, signal)
4186
+ };
4187
+ });
4188
+ }
4167
4189
  const checkpointId = capabilities.canFork ? await checkpointForFork(parent.box, signal) : void 0;
4168
4190
  return mapWithConcurrency(prompts, forkConcurrency, async (prompt, i) => {
4169
4191
  throwIfAborted(signal);
@@ -4218,10 +4240,28 @@ function mintSessionId() {
4218
4240
  return `loop-sess-${randomUuid()}`;
4219
4241
  }
4220
4242
  /**
4243
+ * Branch a running parent through the current Sandbox SDK, in bounded waves.
4244
+ * `undefined` means the box exposes only the legacy checkpoint API (or no
4245
+ * branching API), so the caller may try the legacy capability-gated path.
4246
+ */
4247
+ async function branchParent(box, count, concurrency, signal) {
4248
+ const branch = box.branch;
4249
+ if (typeof branch !== "function") return void 0;
4250
+ const children = [];
4251
+ for (let offset = 0; offset < count; offset += concurrency) {
4252
+ throwIfAborted(signal);
4253
+ const requested = Math.min(concurrency, count - offset);
4254
+ const batch = await branch.call(box, requested);
4255
+ children.push(...batch);
4256
+ if (batch.length !== requested) return children;
4257
+ }
4258
+ return children;
4259
+ }
4260
+ /**
4221
4261
  * Checkpoint the parent leaving it running, returning the checkpoint id to fork
4222
- * from, or `undefined` when the box exposes no `checkpoint` (the loop's fakes)
4223
- * or the call produced no id. `undefined` makes the caller degrade to fresh
4224
- * boxes — a fork that can't checkpoint must not pretend to share context.
4262
+ * from, or `undefined` when the box exposes no legacy `checkpoint` method or
4263
+ * the call produced no id. `undefined` makes the caller use fresh boxes — a
4264
+ * fork that cannot preserve context must not pretend to share it.
4225
4265
  */
4226
4266
  async function checkpointForFork(box, signal) {
4227
4267
  const checkpoint = box.checkpoint;
@@ -4235,10 +4275,9 @@ async function checkpointForFork(box, signal) {
4235
4275
  * platform advertised `canFork`; a missing `fork` here is a contract violation
4236
4276
  * (probe said yes, box says no) and fails loud rather than silently degrading.
4237
4277
  *
4238
- * `signal` gates entry only: the SDK's `fork(checkpointId, options)` takes no
4239
- * abort signal (`ForkOptions` is name/env/resources/metadata), so an in-flight
4240
- * fork cannot be interrupted. The caller (`fork`) checks abort per branch, so
4241
- * cancellation is responsive at branch boundaries, not mid-fork.
4278
+ * `signal` gates entry only: the legacy SDK's `fork(checkpointId, options)`
4279
+ * takes no abort signal, so an in-flight fork cannot be interrupted. The
4280
+ * caller checks abort per branch, so cancellation is responsive at boundaries.
4242
4281
  */
4243
4282
  async function forkFromCheckpoint(box, checkpointId, signal) {
4244
4283
  const fork = box.fork;
@@ -4460,8 +4499,8 @@ async function runAgentRounds(options) {
4460
4499
  }
4461
4500
  }
4462
4501
  /**
4463
- * Build the lineage when either lineage flag is set. Probes the platform's fork
4464
- * capability once per run (the lineage degrades gracefully when it's absent).
4502
+ * Build the lineage when either lineage flag is set. Probes the legacy fork
4503
+ * capability once per run (live branching is detected on each box).
4465
4504
  * Rejects the lineage + `onWorkerBox` combination: both claim the same
4466
4505
  * box-ownership channel, and silently honoring one would leak or double-free.
4467
4506
  */
@@ -4485,9 +4524,9 @@ async function setUpLineage(options, maxConcurrency, recordMount) {
4485
4524
  * Decide, for one round, how each iteration acquires its sandbox stream:
4486
4525
  * - refine (1 task) + `sessionContinuity` + a live parent handle ⇒ continue
4487
4526
  * the parent session on its box.
4488
- * - fanout (N tasks) + `forkFanout` + a live parent handle ⇒ fork the parent
4489
- * checkpoint once and stream each branch from a child box (degrades to fresh
4490
- * boxes inside the lineage when the platform can't fork).
4527
+ * - fanout (N tasks) + `forkFanout` + a live parent handle ⇒ branch the parent
4528
+ * box once and stream each branch from a child box (legacy CRIU or fresh-box
4529
+ * fallback is handled inside the lineage).
4491
4530
  * - otherwise (round 0, no parent, the off flag) ⇒ start a fresh box per
4492
4531
  * iteration THROUGH the lineage so it's owned + a handle is recorded for a
4493
4532
  * later round to descend from.
@@ -4661,7 +4700,8 @@ async function executeIteration(args) {
4661
4700
  addTokenUsage(slot.tokenUsage, {
4662
4701
  input: llmCall.tokensIn,
4663
4702
  output: llmCall.tokensOut,
4664
- ...llmCall.tokensKnown === false ? { tokensKnown: false } : {}
4703
+ ...llmCall.tokensKnown === false ? { tokensKnown: false } : {},
4704
+ ...promptCacheTokenClasses(llmCall.tokensIn, llmCall.promptCache)
4665
4705
  });
4666
4706
  args.ctx.runHandle?.observe(llmCall);
4667
4707
  }
@@ -5033,6 +5073,44 @@ function hashJson(value) {
5033
5073
  return (h >>> 0).toString(16).padStart(8, "0");
5034
5074
  }
5035
5075
  //#endregion
5076
+ //#region src/runtime/supervise/cost-estimate.ts
5077
+ /**
5078
+ * Pricing for work that arrived without a provider receipt.
5079
+ *
5080
+ * A turn whose provider reported no billed dollars used to reach the dollar channel as a
5081
+ * known `$0`, so a run that certainly spent money reported a dollar total of zero. A catalog
5082
+ * price is not a receipt, so what this module produces is always marked, never promoted.
5083
+ */
5084
+ /**
5085
+ * Price one unit of work that no provider receipt covered.
5086
+ *
5087
+ * The event always carries `usdKnown: false`: a catalog price approximates what a provider
5088
+ * WOULD bill, never measures what it did. The priced amount is repeated in `usdEstimated` so
5089
+ * a consumer can subtract it from `usd` and recover the dollars a provider actually billed.
5090
+ *
5091
+ * A model with no catalog entry yields `usd: 0` with `usdKnown: false` and no `usdEstimated`.
5092
+ * The turn then reads as unknown dollars, which is true, rather than as a free turn.
5093
+ */
5094
+ function priceUnreceiptedWork(work) {
5095
+ const unknown = {
5096
+ kind: "cost",
5097
+ usd: 0,
5098
+ usdKnown: false
5099
+ };
5100
+ const { inputTokens, outputTokens, model } = work;
5101
+ if (model === void 0 || !isModelPriced(model)) return unknown;
5102
+ if (!Number.isFinite(inputTokens) || !Number.isFinite(outputTokens)) return unknown;
5103
+ if (inputTokens < 0 || outputTokens < 0) return unknown;
5104
+ const usd = estimateCost(inputTokens, outputTokens, model);
5105
+ if (!Number.isFinite(usd) || usd <= 0) return unknown;
5106
+ return {
5107
+ kind: "cost",
5108
+ usd,
5109
+ usdKnown: false,
5110
+ usdEstimated: usd
5111
+ };
5112
+ }
5113
+ //#endregion
5036
5114
  //#region src/runtime/supervise/inbox.ts
5037
5115
  function parseDown(msg) {
5038
5116
  if (!msg || typeof msg !== "object") return void 0;
@@ -5473,14 +5551,15 @@ function createSteerableSandboxSession(args) {
5473
5551
  const input = call.tokensIn ?? 0;
5474
5552
  const output = call.tokensOut ?? 0;
5475
5553
  if (input || output || !callTokensKnown) {
5476
- tokens.input += input;
5477
- tokens.output += output;
5478
- yield {
5554
+ const usage = {
5479
5555
  kind: "tokens",
5480
5556
  input,
5481
5557
  output,
5482
- ...callTokensKnown ? {} : { tokensKnown: false }
5558
+ ...callTokensKnown ? {} : { tokensKnown: false },
5559
+ ...promptCacheTokenClasses(call.tokensIn, call.promptCache)
5483
5560
  };
5561
+ addTokenUsage(tokens, usage);
5562
+ yield usage;
5484
5563
  }
5485
5564
  if (typeof call.costUsd === "number" && call.costUsd > 0) {
5486
5565
  usd += call.costUsd;
@@ -7288,6 +7367,7 @@ async function* streamBridgeSession(args) {
7288
7367
  let tokensKnown = true;
7289
7368
  let usd = 0;
7290
7369
  let usdKnown = true;
7370
+ let estimatedUsdCharged = 0;
7291
7371
  let estimatedUsd = 0;
7292
7372
  let sawEstimatedUsd = false;
7293
7373
  let turns = 0;
@@ -7365,6 +7445,8 @@ async function* streamBridgeSession(args) {
7365
7445
  let turnUsdKnown = true;
7366
7446
  let turnKnownCostSubtotal = 0;
7367
7447
  let turnEstimatedCostSubtotal = 0;
7448
+ let turnInputTokens = 0;
7449
+ let turnOutputTokens = 0;
7368
7450
  let interrupted = false;
7369
7451
  let profileMaterializationPublished = false;
7370
7452
  const publishProfileMaterialization = () => {
@@ -7423,6 +7505,8 @@ async function* streamBridgeSession(args) {
7423
7505
  if (chunk.usage) {
7424
7506
  sawTurnTokenUsage = true;
7425
7507
  if (!chunk.usage.known) turnTokensKnown = false;
7508
+ turnInputTokens += chunk.usage.input;
7509
+ turnOutputTokens += chunk.usage.output;
7426
7510
  const usageEvent = {
7427
7511
  kind: "tokens",
7428
7512
  input: chunk.usage.input,
@@ -7436,8 +7520,8 @@ async function* streamBridgeSession(args) {
7436
7520
  yield usageEvent;
7437
7521
  if (chunk.usage.promptCache) {
7438
7522
  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;
7523
+ if (chunk.usage.promptCache.readInput !== void 0) promptCache.readTokens = (promptCache.readTokens ?? 0) + chunk.usage.promptCache.readInput;
7524
+ if (chunk.usage.promptCache.writeInput !== void 0) promptCache.writeTokens = (promptCache.writeTokens ?? 0) + chunk.usage.promptCache.writeInput;
7441
7525
  }
7442
7526
  }
7443
7527
  if (chunk.costKnown !== void 0) {
@@ -7490,11 +7574,20 @@ async function* streamBridgeSession(args) {
7490
7574
  });
7491
7575
  if (!sawTurnTokenUsage || !turnTokensKnown) tokensKnown = false;
7492
7576
  if (!sawTurnCostStatus || !turnUsdKnown) usdKnown = false;
7493
- if (!sawTurnCostStatus || !turnUsdKnown) yield {
7494
- kind: "cost",
7495
- usd: 0,
7496
- usdKnown: false
7497
- };
7577
+ if (!sawTurnCostStatus || !turnUsdKnown) {
7578
+ const priced = turnKnownCostSubtotal === 0 ? priceUnreceiptedWork({
7579
+ inputTokens: turnInputTokens,
7580
+ outputTokens: turnOutputTokens,
7581
+ model: observedModel ?? seam.providerModel
7582
+ }) : {
7583
+ kind: "cost",
7584
+ usd: 0,
7585
+ usdKnown: false
7586
+ };
7587
+ if (priced.usdEstimated !== void 0) estimatedUsdCharged += priced.usdEstimated;
7588
+ usd += priced.usd;
7589
+ yield priced;
7590
+ }
7498
7591
  yield { kind: "iteration" };
7499
7592
  if (!interrupted && turnText) lastText = turnText;
7500
7593
  if (interrupted) {
@@ -7514,6 +7607,7 @@ async function* streamBridgeSession(args) {
7514
7607
  ...tokensKnown ? {} : { tokensKnown: false },
7515
7608
  usd,
7516
7609
  ...usdKnown ? {} : { usdKnown: false },
7610
+ ...estimatedUsdCharged > 0 ? { usdEstimated: estimatedUsdCharged } : {},
7517
7611
  ms: Date.now() - started
7518
7612
  };
7519
7613
  const out = {
@@ -9046,6 +9140,11 @@ function assertValidSpend(spend, label) {
9046
9140
  } else if (classified > spend.tokens.input) throw new Error(`${label}.tokens cache classes must not exceed input`);
9047
9141
  }
9048
9142
  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`);
9143
+ if (spend.usdEstimated !== void 0) {
9144
+ if (!Number.isFinite(spend.usdEstimated) || spend.usdEstimated < 0) throw new Error(`${label}.usdEstimated must be a non-negative finite number`);
9145
+ if (spend.usdEstimated > spend.usd) throw new Error(`${label}.usdEstimated must not exceed ${label}.usd`);
9146
+ if (spend.usdKnown !== false) throw new Error(`${label}.usdEstimated requires ${label}.usdKnown false`);
9147
+ }
9049
9148
  }
9050
9149
  /** Fold a normalized `UsageEvent` array into a `Spend`. Tokens and usd are separate
9051
9150
  * channels; iterations come from `'iteration'` events. Pure; `ms` stays zero (the
@@ -9054,6 +9153,7 @@ function spendFromUsageEvents(events) {
9054
9153
  const tokens = zeroTokenUsage();
9055
9154
  let tokensKnown = true;
9056
9155
  let usd = 0;
9156
+ let usdEstimated = 0;
9057
9157
  let usdKnown = true;
9058
9158
  let iterations = 0;
9059
9159
  for (const ev of events) if (ev.kind === "tokens") {
@@ -9061,6 +9161,7 @@ function spendFromUsageEvents(events) {
9061
9161
  if (ev.tokensKnown === false) tokensKnown = false;
9062
9162
  } else if (ev.kind === "cost") {
9063
9163
  usd += ev.usd;
9164
+ usdEstimated += ev.usdEstimated ?? 0;
9064
9165
  if (ev.usdKnown === false) usdKnown = false;
9065
9166
  } else iterations += 1;
9066
9167
  return {
@@ -9069,6 +9170,7 @@ function spendFromUsageEvents(events) {
9069
9170
  ...tokensKnown ? {} : { tokensKnown: false },
9070
9171
  usd,
9071
9172
  ...usdKnown ? {} : { usdKnown: false },
9173
+ ...usdEstimated > 0 ? { usdEstimated } : {},
9072
9174
  ms: 0
9073
9175
  };
9074
9176
  }
@@ -9077,6 +9179,7 @@ async function foldUsage(events) {
9077
9179
  const tokens = zeroTokenUsage();
9078
9180
  let tokensKnown = true;
9079
9181
  let usd = 0;
9182
+ let usdEstimated = 0;
9080
9183
  let usdKnown = true;
9081
9184
  let iterations = 0;
9082
9185
  for await (const ev of events) if (ev.kind === "tokens") {
@@ -9084,6 +9187,7 @@ async function foldUsage(events) {
9084
9187
  if (ev.tokensKnown === false) tokensKnown = false;
9085
9188
  } else if (ev.kind === "cost") {
9086
9189
  usd += ev.usd;
9190
+ usdEstimated += ev.usdEstimated ?? 0;
9087
9191
  if (ev.usdKnown === false) usdKnown = false;
9088
9192
  } else iterations += 1;
9089
9193
  return {
@@ -9092,6 +9196,7 @@ async function foldUsage(events) {
9092
9196
  ...tokensKnown ? {} : { tokensKnown: false },
9093
9197
  usd,
9094
9198
  ...usdKnown ? {} : { usdKnown: false },
9199
+ ...usdEstimated > 0 ? { usdEstimated } : {},
9095
9200
  ms: 0
9096
9201
  };
9097
9202
  }
@@ -9180,8 +9285,8 @@ function createBudgetPool(root, now = Date.now, restore = {}) {
9180
9285
  let violation;
9181
9286
  if (spentTokens > rTokens) violation = `ticket ${ticket.id} spent ${spentTokens} tokens > reserved ${rTokens}`;
9182
9287
  else if (spent.iterations > rIterations) violation = `ticket ${ticket.id} spent ${spent.iterations} iterations > reserved ${rIterations}`;
9183
- else if (usdCapped && usdBudgeted && spent.usd > rUsd) violation = `ticket ${ticket.id} spent $${spent.usd} > reserved $${rUsd}`;
9184
9288
  else if (unknownUnderCap) violation = `ticket ${ticket.id} reported unknown dollar cost under a dollar-capped budget`;
9289
+ else if (usdCapped && usdBudgeted && spent.usd > rUsd) violation = `ticket ${ticket.id} spent $${spent.usd} > reserved $${rUsd}`;
9185
9290
  open.delete(ticket.id);
9186
9291
  if (spent.tokensKnown === false) tokensTainted = true;
9187
9292
  if (!hasCompleteCacheBreakdown(spent.tokens)) cacheBreakdownTainted = true;
@@ -10392,7 +10497,7 @@ function createScope(args) {
10392
10497
  return;
10393
10498
  }
10394
10499
  }
10395
- async function meterInternal(spend, detail, providerModel) {
10500
+ async function meterInternal(spend, detail, providerModel, accountingOnly = false) {
10396
10501
  if (args.signal.aborted) throw new ValidationError("scope.meter: cannot record new driver work after scope abort");
10397
10502
  const seq = meterSeq++;
10398
10503
  let observeError;
@@ -10405,6 +10510,7 @@ function createScope(args) {
10405
10510
  kind: "metered",
10406
10511
  id: args.parentId,
10407
10512
  spend,
10513
+ ...accountingOnly ? { accountingOnly: true } : {},
10408
10514
  ...providerModel === void 0 ? {} : { providerModel: detachedSnapshot(providerModel, "runtime provider model evidence") },
10409
10515
  seq,
10410
10516
  at: new Date(now()).toISOString()
@@ -10454,7 +10560,7 @@ function createScope(args) {
10454
10560
  };
10455
10561
  }
10456
10562
  };
10457
- runtimeOwnedProviderMeters.set(scope, async (spend, providerModel, detail) => meterInternal(spend, detail, providerModel));
10563
+ runtimeOwnedProviderMeters.set(scope, async (spend, providerModel, detail, accountingOnly) => meterInternal(spend, detail, providerModel, accountingOnly));
10458
10564
  if (args.ownerMaterialization !== void 0) {
10459
10565
  const authoredProfile = args.ownerMaterialization.authoredProfile === void 0 ? void 0 : detachedSnapshot(args.ownerMaterialization.authoredProfile, "scope owner authored profile");
10460
10566
  ownerMaterializationStates.set(scope, {
@@ -10482,6 +10588,12 @@ function meterRuntimeOwnedProviderAttempt(scope, spend, providerModel, detail) {
10482
10588
  if (meter === void 0) throw new ValidationError("scope: Runtime-owned provider meter is not bound to this scope");
10483
10589
  return meter(spend, providerModel, detail);
10484
10590
  }
10591
+ /** @internal Meter Runtime-owned accounting that does not represent provider execution. */
10592
+ function meterRuntimeOwnedAccounting(scope, spend, detail) {
10593
+ const meter = runtimeOwnedProviderMeters.get(scope);
10594
+ if (meter === void 0) throw new ValidationError("scope: Runtime-owned provider meter is not bound to this scope");
10595
+ return meter(spend, void 0, detail, true);
10596
+ }
10485
10597
  const ownerMaterializationStates = /* @__PURE__ */ new WeakMap();
10486
10598
  /**
10487
10599
  * @internal Publish exact root-manager materialization from a runtime-owned adapter after dynamic
@@ -12422,6 +12534,7 @@ function accumulate(a, b) {
12422
12534
  if (b.tokensKnown === false) a.tokensKnown = false;
12423
12535
  a.usd += b.usd;
12424
12536
  if (b.usdKnown === false) a.usdKnown = false;
12537
+ if (b.usdEstimated !== void 0) a.usdEstimated = (a.usdEstimated ?? 0) + b.usdEstimated;
12425
12538
  a.ms += b.ms;
12426
12539
  }
12427
12540
  /** Sum two conserved-spend tallies per channel — the child-work journal sum + the drivers' own
@@ -12437,6 +12550,7 @@ function addSpend(a, b) {
12437
12550
  ...a.tokensKnown === false || b.tokensKnown === false ? { tokensKnown: false } : {},
12438
12551
  usd: a.usd + b.usd,
12439
12552
  ...a.usdKnown === false || b.usdKnown === false ? { usdKnown: false } : {},
12553
+ ...usdEstimatedOf(a, b),
12440
12554
  ms: a.ms + b.ms
12441
12555
  };
12442
12556
  }
@@ -12447,6 +12561,6 @@ function isNonEmptySpend(s) {
12447
12561
  return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0 || s.tokensKnown === false || s.usdKnown === false;
12448
12562
  }
12449
12563
  //#endregion
12450
- 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 };
12564
+ 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 };
12451
12565
 
12452
- //# sourceMappingURL=supervisor-4r4BYSti.js.map
12566
+ //# sourceMappingURL=supervisor-Bfh5Gq_P.js.map