@tangle-network/agent-runtime 0.114.0 → 0.115.1

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 (46) hide show
  1. package/dist/{activation-DlKl7-1o.js → activation-Bt_XVkjK.js} +2 -2
  2. package/dist/{activation-DlKl7-1o.js.map → activation-Bt_XVkjK.js.map} +1 -1
  3. package/dist/agent.d.ts +1 -1
  4. package/dist/agent.js +2 -2
  5. package/dist/{improvement-cycle-vLye8pYb.js → improvement-cycle-tEswzEPr.js} +3 -3
  6. package/dist/{improvement-cycle-vLye8pYb.js.map → improvement-cycle-tEswzEPr.js.map} +1 -1
  7. package/dist/{index-D-lNUfea.d.ts → index-BUWd8QJq.d.ts} +108 -2
  8. package/dist/{index-YpvLKzIX.d.ts → index-DZukewLl.d.ts} +2 -2
  9. package/dist/{index-BLf-SZ2b.d.ts → index-K7nucOmw.d.ts} +4 -4
  10. package/dist/index.d.ts +5 -5
  11. package/dist/index.js +9 -9
  12. package/dist/intelligence.js +3 -3
  13. package/dist/kernel.d.ts +2 -2
  14. package/dist/kernel.js +5 -5
  15. package/dist/{knowledge-BTsA9n6L.js → knowledge-CUXQE8Sq.js} +3 -3
  16. package/dist/{knowledge-BTsA9n6L.js.map → knowledge-CUXQE8Sq.js.map} +1 -1
  17. package/dist/knowledge.d.ts +1 -1
  18. package/dist/knowledge.js +1 -1
  19. package/dist/{loop-runner-bin-Cg_8UKZR.d.ts → loop-runner-bin-BZl5vp7t.d.ts} +2 -2
  20. package/dist/{loop-runner-bin-CuBMmlMJ.js → loop-runner-bin-DzJz48Fb.js} +3 -3
  21. package/dist/{loop-runner-bin-CuBMmlMJ.js.map → loop-runner-bin-DzJz48Fb.js.map} +1 -1
  22. package/dist/loop-runner-bin.d.ts +1 -1
  23. package/dist/loop-runner-bin.js +1 -1
  24. package/dist/mcp/bin.js +2 -2
  25. package/dist/mcp/index.d.ts +1 -1
  26. package/dist/mcp/index.js +5 -5
  27. package/dist/{openai-tools-VAbzps5G.js → openai-tools-CynwZMZd.js} +2 -2
  28. package/dist/{openai-tools-VAbzps5G.js.map → openai-tools-CynwZMZd.js.map} +1 -1
  29. package/dist/{otel-export-D34IQW1C.js → otel-export-CPZTSADj.js} +16 -7
  30. package/dist/otel-export-CPZTSADj.js.map +1 -0
  31. package/dist/primeintellect/index.d.ts +1 -1
  32. package/dist/{runtime-DQ5seHEu.js → runtime-BatQajPB.js} +4 -4
  33. package/dist/{runtime-DQ5seHEu.js.map → runtime-BatQajPB.js.map} +1 -1
  34. package/dist/{structural-rollout-C7vF83fV.js → structural-rollout-DEf37yQy.js} +2 -2
  35. package/dist/{structural-rollout-C7vF83fV.js.map → structural-rollout-DEf37yQy.js.map} +1 -1
  36. package/dist/{supervise-tdxMJYem.js → supervise-B7TIJR3D.js} +336 -9
  37. package/dist/supervise-B7TIJR3D.js.map +1 -0
  38. package/dist/{supervisor-DKqolBGI.js → supervisor-DzQu5Ydu.js} +36 -9
  39. package/dist/supervisor-DzQu5Ydu.js.map +1 -0
  40. package/dist/testing.js +8 -8
  41. package/dist/{trace-propagation-CJJC7SVB.js → trace-propagation-B-pL7xn_.js} +2 -2
  42. package/dist/{trace-propagation-CJJC7SVB.js.map → trace-propagation-B-pL7xn_.js.map} +1 -1
  43. package/package.json +1 -1
  44. package/dist/otel-export-D34IQW1C.js.map +0 -1
  45. package/dist/supervise-tdxMJYem.js.map +0 -1
  46. package/dist/supervisor-DKqolBGI.js.map +0 -1
@@ -1968,10 +1968,28 @@ function meterTurn(raw, model) {
1968
1968
  output: raw.completion_tokens
1969
1969
  } : void 0;
1970
1970
  if (!usage) return {};
1971
- const costUsd = isModelPriced(model) ? estimateCost(usage.input, usage.output, model) : void 0;
1971
+ const localEstimate = isModelPriced(model) ? estimateCost(usage.input, usage.output, model) : void 0;
1972
+ const cache = readPromptCache(raw?.prompt_cache);
1973
+ const costUsd = localEstimate !== void 0 && cache?.readSavingsUsd !== void 0 ? Math.max(0, localEstimate - cache.readSavingsUsd) : localEstimate;
1972
1974
  return {
1973
1975
  usage,
1974
- ...costUsd !== void 0 ? { costUsd } : {}
1976
+ ...costUsd !== void 0 ? { costUsd } : {},
1977
+ ...cache ? { cache } : {}
1978
+ };
1979
+ }
1980
+ function readPromptCache(raw) {
1981
+ if (!raw || typeof raw !== "object") return void 0;
1982
+ const o = raw;
1983
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
1984
+ const readTokens = num(o.read_tokens);
1985
+ const writeTokens = num(o.write_tokens);
1986
+ if (readTokens === void 0 && writeTokens === void 0) return void 0;
1987
+ const savings = num(o.read_savings_usd);
1988
+ return {
1989
+ readTokens: readTokens ?? 0,
1990
+ writeTokens: writeTokens ?? 0,
1991
+ ...savings !== void 0 ? { readSavingsUsd: savings } : {},
1992
+ ...typeof o.status === "string" ? { status: o.status } : {}
1975
1993
  };
1976
1994
  }
1977
1995
  /**
@@ -3560,7 +3578,12 @@ function isAgent(value) {
3560
3578
  *
3561
3579
  * Pure and deterministic: `now()` is injected, there is no I/O, and no wall-clock or
3562
3580
  * RNG read. A `reserve`/`reconcile` ticket is single-use (fail-loud on double or
3563
- * unknown reconcile) so a child can never refund twice. If dollar cost is unknowable under a
3581
+ * unknown reconcile) so a child can never refund twice. Reconciling an OPEN ticket always
3582
+ * closes it: a fail-loud condition settles the reservation first and throws afterwards, so no
3583
+ * error path can strand a reservation past the join barrier's `assertNoOpenTickets`.
3584
+ * A child that declared no `maxUsd` reserved no dollar allocation, so its real dollars are
3585
+ * committed as observed spend and debited from the root's balance rather than treated as an
3586
+ * overspend of a $0 ceiling it never asked for. If dollar cost is unknowable under a
3564
3587
  * dollar limit, reconciliation closes the known token/iteration work, marks the dollar channel
3565
3588
  * unusable, and refuses later reservations; inventing a numeric dollar total would be worse.
3566
3589
  * If a TOKEN count is unknowable (a provider that reported no usage for work that ran), the pool
@@ -3682,7 +3705,8 @@ function createBudgetPool(root, now = Date.now) {
3682
3705
  reserved: {
3683
3706
  tokens: wantTokens,
3684
3707
  usd: wantUsd,
3685
- iterations: wantIterations
3708
+ iterations: wantIterations,
3709
+ usdBudgeted: b.maxUsd !== void 0
3686
3710
  }
3687
3711
  }
3688
3712
  };
@@ -3692,9 +3716,12 @@ function createBudgetPool(root, now = Date.now) {
3692
3716
  const { tokens: rTokens, usd: rUsd, iterations: rIterations } = ticket.reserved;
3693
3717
  const unknownUnderCap = usdCapped && spent.usdKnown === false;
3694
3718
  const spentTokens = totalTokens(spent.tokens);
3695
- if (spentTokens > rTokens) throw new Error(`budget pool: ticket ${ticket.id} spent ${spentTokens} tokens > reserved ${rTokens}`);
3696
- if (spent.iterations > rIterations) throw new Error(`budget pool: ticket ${ticket.id} spent ${spent.iterations} iterations > reserved ${rIterations}`);
3697
- if (usdCapped && spent.usd > rUsd) throw new Error(`budget pool: ticket ${ticket.id} spent $${spent.usd} > reserved $${rUsd}`);
3719
+ const usdBudgeted = ticket.reserved.usdBudgeted !== false;
3720
+ let violation;
3721
+ if (spentTokens > rTokens) violation = `ticket ${ticket.id} spent ${spentTokens} tokens > reserved ${rTokens}`;
3722
+ else if (spent.iterations > rIterations) violation = `ticket ${ticket.id} spent ${spent.iterations} iterations > reserved ${rIterations}`;
3723
+ else if (usdCapped && usdBudgeted && spent.usd > rUsd) violation = `ticket ${ticket.id} spent $${spent.usd} > reserved $${rUsd}`;
3724
+ else if (unknownUnderCap) violation = `ticket ${ticket.id} reported unknown dollar cost under a dollar-capped budget`;
3698
3725
  open.delete(ticket.id);
3699
3726
  if (spent.tokensKnown === false) tokensTainted = true;
3700
3727
  reservedTokens -= rTokens;
@@ -3711,7 +3738,7 @@ function createBudgetPool(root, now = Date.now) {
3711
3738
  freeUsd = 0;
3712
3739
  } else freeUsd += rUsd - spent.usd;
3713
3740
  } else committedUsd += spent.usd;
3714
- if (unknownUnderCap) throw new Error(`budget pool: ticket ${ticket.id} reported unknown dollar cost under a dollar-capped budget`);
3741
+ if (violation !== void 0) throw new Error(`budget pool: ${violation}`);
3715
3742
  }
3716
3743
  function observe(spend) {
3717
3744
  if (usdCapped && spend.usdKnown === false) throw new Error("budget pool: cannot observe unknown dollar cost under a dollar-capped budget");
@@ -4248,4 +4275,4 @@ function isNonEmptySpend(s) {
4248
4275
  //#endregion
4249
4276
  export { captureWorktreeDiff as A, routerChatWithUsage as C, runSettledCommand as D, runBrainLoop as E, runLocalHarness as F, CodexExecutionDiagnosticError as I, removeWorktree as M, harnessInvocation as N, runWorktreeChecks as O, parseCodexTokenUsage as P, routerChatWithTools as S, streamRouterChatWithTools as T, waitUntil as _, runFinalizer as a, readWorkerProgress as b, spendFromUsageEvents as c, settledToIteration as d, createWaitProbes as f, validateWaitSpec as g, timerAt as h, pickBestDelivered as i, createWorktree as j, runWorktreeHarness as k, withDriverExecutor as l, pollFor as m, bestDelivered as n, runTree as o, isWaitOutcome as p, collectDelivered as r, createBudgetPool as s, createSupervisor as t, createScope as u, DEFAULT_STALL_AFTER_MS as v, routerToolLoop as w, routerBrain as x, createActivityLog as y };
4250
4277
 
4251
- //# sourceMappingURL=supervisor-DKqolBGI.js.map
4278
+ //# sourceMappingURL=supervisor-DzQu5Ydu.js.map