@wrongstack/core 0.313.1 → 0.316.2

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 (290) hide show
  1. package/dist/chronicle/index.js +31 -31
  2. package/dist/chronicle/legacy-journal-import.d.ts +0 -6
  3. package/dist/chronicle/metrics-ingest.d.ts +14 -0
  4. package/dist/chronicle/metrics-schema.d.ts +10 -1
  5. package/dist/chronicle/metrics-store.d.ts +20 -2
  6. package/dist/chronicle/project-server.js +39 -31
  7. package/dist/chronicle/sink.d.ts +13 -0
  8. package/dist/chronicle/sqlite-journal.d.ts +20 -2
  9. package/dist/{chunk-WOEZV3Q4.js → chunk-25LSLC3G.js} +2 -1
  10. package/dist/{chunk-AI4LLQ2U.js → chunk-27QIURLN.js} +229 -12
  11. package/dist/{chunk-I45KAW2N.js → chunk-3AGWVSS7.js} +38 -450
  12. package/dist/chunk-3BDV7RL3.js +211 -0
  13. package/dist/{chunk-NFAYHPRH.js → chunk-3ECENVHL.js} +10 -8
  14. package/dist/{chunk-FW5LDDMJ.js → chunk-45WI72ZB.js} +1576 -1156
  15. package/dist/{chunk-AT4V4XGI.js → chunk-4BMVPOHO.js} +539 -313
  16. package/dist/{chunk-YBUJCZ57.js → chunk-4I7HGVVA.js} +17 -5
  17. package/dist/{chunk-JVGPR3TS.js → chunk-4LCZVJVF.js} +7 -55
  18. package/dist/{chunk-4ZHTKJHM.js → chunk-4SJNS7OB.js} +36 -2
  19. package/dist/{chunk-AD7ZFZCS.js → chunk-5BMIE7QG.js} +3 -3
  20. package/dist/{chunk-IQ35HMQL.js → chunk-5YPSXQXM.js} +71 -24
  21. package/dist/chunk-6FHWXLPT.js +10 -0
  22. package/dist/{chunk-FIV4IJL7.js → chunk-6H5GEOET.js} +163 -20
  23. package/dist/{chunk-VB3H5WWB.js → chunk-6NWEVFEL.js} +2 -2
  24. package/dist/{chunk-E6I5RXVK.js → chunk-AYW5YINX.js} +2 -2
  25. package/dist/{chunk-DEIQMBD2.js → chunk-B7F4WVP4.js} +2 -2
  26. package/dist/{chunk-XQ2XGIBF.js → chunk-BPBKKBUK.js} +6 -7
  27. package/dist/{chunk-K4YUNKU7.js → chunk-BYD345OX.js} +2 -2
  28. package/dist/{chunk-LZDDLNCZ.js → chunk-C27KDLOX.js} +4 -4
  29. package/dist/{chunk-6AKOTGLM.js → chunk-CU546ESW.js} +7 -7
  30. package/dist/{chunk-ZZ4V3WIZ.js → chunk-DLHHXUAM.js} +10 -1
  31. package/dist/{chunk-BAKVJLEV.js → chunk-DOTHQSJ2.js} +28 -16
  32. package/dist/{chunk-KBZGE6LN.js → chunk-DYLPMV4Q.js} +4 -3
  33. package/dist/{chunk-52RTVH4M.js → chunk-F3JWNST7.js} +2 -2
  34. package/dist/{chunk-WEBMSQP2.js → chunk-FC2ZGRF3.js} +21 -4
  35. package/dist/{chunk-FHAMQS7Q.js → chunk-FCBTO76Z.js} +76 -146
  36. package/dist/{chunk-4LJJYBAU.js → chunk-FHZVFYSL.js} +9 -1
  37. package/dist/{chunk-W4A6QA3D.js → chunk-FWNLEZYG.js} +4 -3
  38. package/dist/{chunk-OJZEX73F.js → chunk-GDQ7CZRQ.js} +5 -1
  39. package/dist/{chunk-QVOVMXJR.js → chunk-GJJGJB2R.js} +32 -9
  40. package/dist/{chunk-4XV6IR37.js → chunk-HI3JGZR2.js} +7 -6
  41. package/dist/{chunk-FSWCWSTS.js → chunk-HMLIGAU7.js} +26 -26
  42. package/dist/{chunk-PFXFQQRT.js → chunk-HXKZ7OBQ.js} +7 -43
  43. package/dist/{chunk-2FQL4PDC.js → chunk-I7DALG7J.js} +5 -5
  44. package/dist/{chunk-GM54GJBU.js → chunk-IRUTEHCE.js} +3 -3
  45. package/dist/{chunk-TYW2GI5I.js → chunk-J2WRWR37.js} +40 -13
  46. package/dist/{chunk-ZEHUCJHY.js → chunk-JFPJ6LLQ.js} +2 -2
  47. package/dist/chunk-JMULFFLN.js +9 -0
  48. package/dist/{chunk-RD6DEE36.js → chunk-JO4MGB6Z.js} +94 -8
  49. package/dist/{chunk-5DSMEVA4.js → chunk-K6BXGITA.js} +7 -7
  50. package/dist/{chunk-O74MJHXU.js → chunk-KZMSZV32.js} +2 -2
  51. package/dist/{chunk-GFJOMSHG.js → chunk-LA7CLDRW.js} +6 -2
  52. package/dist/{chunk-M2WF6AXG.js → chunk-LSMMOS2Z.js} +7 -3
  53. package/dist/{chunk-ASX6AW36.js → chunk-LXWCMQNJ.js} +3 -3
  54. package/dist/{chunk-WZO23AWO.js → chunk-M27LIEKV.js} +72 -22
  55. package/dist/{chunk-JTHKOYWU.js → chunk-MJPHJRAL.js} +15 -15
  56. package/dist/{chunk-G5AAKEEZ.js → chunk-MTL4O5YR.js} +5 -5
  57. package/dist/chunk-NHJ75HXY.js +1 -0
  58. package/dist/{chunk-ZYU2YOJ6.js → chunk-NIOAGFPB.js} +29 -15
  59. package/dist/{chunk-Y2GE5TSI.js → chunk-NS52ISWS.js} +2 -2
  60. package/dist/{chunk-UIWONWVG.js → chunk-NSOFPKGT.js} +541 -148
  61. package/dist/{chunk-RCQYT2I4.js → chunk-NVIZG63R.js} +2 -2
  62. package/dist/{chunk-EPC3GZD4.js → chunk-OOYZPOXM.js} +2 -2
  63. package/dist/{chunk-7ZHZE5EO.js → chunk-OSGLYW5J.js} +2 -2
  64. package/dist/{chunk-CE4ZOCOI.js → chunk-PFCMSSUF.js} +9 -9
  65. package/dist/{chunk-GFXZTHNI.js → chunk-PGRVXIMY.js} +5 -5
  66. package/dist/{chunk-JJPMWPB6.js → chunk-PISBFBJN.js} +6 -6
  67. package/dist/chunk-POOOIWE5.js +9 -0
  68. package/dist/{chunk-5RP3QTRL.js → chunk-PQNS3U7Z.js} +20 -3
  69. package/dist/{chunk-3E244UDA.js → chunk-QSTSJOCK.js} +52 -6
  70. package/dist/{chunk-YUPMXOGP.js → chunk-RFQMOKWK.js} +3 -3
  71. package/dist/chunk-RTOTNK3P.js +484 -0
  72. package/dist/{chunk-SN2DQRL6.js → chunk-RXKSDUAU.js} +7 -7
  73. package/dist/{chunk-T3KGZBU5.js → chunk-S45JPKQN.js} +189 -43
  74. package/dist/{chunk-YNCVSFGF.js → chunk-SAFHACFA.js} +4 -1
  75. package/dist/{chunk-KI4L2DUL.js → chunk-TCCHINEF.js} +114 -19
  76. package/dist/{chunk-AWNQ6ED6.js → chunk-THEGTRAG.js} +7 -2
  77. package/dist/{chunk-2KKODIQU.js → chunk-TR4LQE7L.js} +15 -15
  78. package/dist/{chunk-GPQ3NJPR.js → chunk-TWJMGXCI.js} +3 -3
  79. package/dist/{chunk-H72H4XDU.js → chunk-U45AXT5D.js} +9 -9
  80. package/dist/{chunk-62V2AFVG.js → chunk-U4FWBSO3.js} +160 -73
  81. package/dist/{chunk-A455ATZB.js → chunk-UBGDX6FI.js} +8 -1
  82. package/dist/chunk-UJILKYES.js +75 -0
  83. package/dist/{chunk-KSJ5UTP7.js → chunk-ULMAQV3T.js} +84 -4
  84. package/dist/{chunk-CB2HFKTP.js → chunk-VVBP6KGT.js} +1 -1
  85. package/dist/{chunk-RPOA7IAE.js → chunk-W5VITDM2.js} +43 -25
  86. package/dist/{chunk-QRTG4XTI.js → chunk-WAHQVNWT.js} +7 -1
  87. package/dist/{chunk-SQP64RCS.js → chunk-WGGYRBXH.js} +3019 -2976
  88. package/dist/{chunk-K3G6JBUC.js → chunk-WLYKU45P.js} +679 -141
  89. package/dist/chunk-WP7BVANJ.js +53 -0
  90. package/dist/{chunk-GAZEWQEZ.js → chunk-XF4VUMKW.js} +2 -2
  91. package/dist/{chunk-PAAWLLZX.js → chunk-Y5YXDM7D.js} +2 -2
  92. package/dist/{chunk-65RDIOR2.js → chunk-YOPAUVU4.js} +162 -44
  93. package/dist/{chunk-FFSX2QDQ.js → chunk-YPT4A46F.js} +3 -3
  94. package/dist/chunk-YWXT3JNM.js +425 -0
  95. package/dist/{chunk-EFEHDQGY.js → chunk-ZHZ2Y2DH.js} +64 -10
  96. package/dist/{chunk-CQQL4ZOQ.js → chunk-ZT7JNIGX.js} +4 -3
  97. package/dist/coordination/agent-monitor.d.ts +9 -1
  98. package/dist/coordination/agent-subagent-runner.d.ts +1 -1
  99. package/dist/coordination/agents/agent-prompts.d.ts +8 -0
  100. package/dist/coordination/agents/index.d.ts +33 -1
  101. package/dist/coordination/agents/index.js +52 -22
  102. package/dist/coordination/agents/phase3-wave1-platform.d.ts +1 -3
  103. package/dist/coordination/agents/phase3-wave2-meta.d.ts +1 -3
  104. package/dist/coordination/agents/phase8-wave3-products.d.ts +1 -3
  105. package/dist/coordination/agents/phase9-wave4-platform-meta.d.ts +1 -3
  106. package/dist/coordination/agents/project-agent-identity.d.ts +11 -11
  107. package/dist/coordination/agents/types.d.ts +13 -2
  108. package/dist/coordination/brain-monitor.d.ts +30 -7
  109. package/dist/coordination/collab-debug.d.ts +1 -1
  110. package/dist/coordination/collab-pause.d.ts +1 -1
  111. package/dist/coordination/delegate-tool.d.ts +7 -5
  112. package/dist/coordination/director-kanban-queue-helpers.d.ts +1 -0
  113. package/dist/coordination/director-options.d.ts +7 -0
  114. package/dist/coordination/director-spawn-model.d.ts +17 -0
  115. package/dist/coordination/director-tools.d.ts +2 -2
  116. package/dist/coordination/director.d.ts +12 -0
  117. package/dist/coordination/dispatcher.d.ts +8 -0
  118. package/dist/coordination/fleet-bus.d.ts +35 -4
  119. package/dist/coordination/fleet-supervisor.d.ts +10 -2
  120. package/dist/coordination/fleet.d.ts +16 -7
  121. package/dist/coordination/index.d.ts +4 -0
  122. package/dist/coordination/index.js +86 -49
  123. package/dist/coordination/kanban-dispatch-port.d.ts +2 -2
  124. package/dist/coordination/mailbox-http-router.d.ts +4 -3
  125. package/dist/coordination/mailbox-http-validation.d.ts +1 -1
  126. package/dist/coordination/mailbox-project-server.js +15 -15
  127. package/dist/coordination/mailbox-types.d.ts +24 -6
  128. package/dist/coordination/model-tier-leader.d.ts +122 -0
  129. package/dist/coordination/model-tier.d.ts +122 -0
  130. package/dist/coordination/multi-agent-coordinator.d.ts +24 -0
  131. package/dist/coordination/origin-session.d.ts +16 -0
  132. package/dist/coordination/provider-status-tracker.d.ts +37 -5
  133. package/dist/coordination/session-note-hub.d.ts +44 -0
  134. package/dist/coordination/session-note-tool.d.ts +10 -0
  135. package/dist/core/agent.d.ts +1 -1
  136. package/dist/core/context.d.ts +22 -3
  137. package/dist/core/index.d.ts +2 -0
  138. package/dist/core/index.js +130 -38
  139. package/dist/core/request-conversation-binding.d.ts +37 -0
  140. package/dist/core/session-notes.d.ts +25 -0
  141. package/dist/core/system-prompt-builder.d.ts +11 -2
  142. package/dist/core/system-prompt-variants.d.ts +78 -0
  143. package/dist/design/index.js +3 -3
  144. package/dist/execution/auto-compaction-middleware.d.ts +11 -0
  145. package/dist/execution/autonomy-brain.d.ts +2 -1
  146. package/dist/execution/autonomy-prompt-contributor.d.ts +7 -2
  147. package/dist/execution/compaction-core.d.ts +4 -4
  148. package/dist/execution/eternal-autonomy.d.ts +1 -1
  149. package/dist/execution/index.js +138 -129
  150. package/dist/execution/model-runtime.d.ts +0 -7
  151. package/dist/execution/parallel-eternal-engine.d.ts +7 -7
  152. package/dist/extension/index.js +3 -3
  153. package/dist/goal/index.js +6 -6
  154. package/dist/hooks/index.js +3 -3
  155. package/dist/hq/index.js +14 -12
  156. package/dist/hq/persistence/event-log.d.ts +0 -1
  157. package/dist/hq/persistence.d.ts +4 -4
  158. package/dist/hq/publisher.d.ts +2 -0
  159. package/dist/index.d.ts +14 -11
  160. package/dist/index.js +728 -635
  161. package/dist/infrastructure/index.d.ts +4 -4
  162. package/dist/infrastructure/index.js +281 -260
  163. package/dist/infrastructure/token-counter.d.ts +9 -0
  164. package/dist/kernel/events/agent-events.d.ts +77 -3
  165. package/dist/kernel/events/brain-events.d.ts +12 -0
  166. package/dist/kernel/events/provider-events.d.ts +7 -1
  167. package/dist/kernel/events/session-events.d.ts +14 -0
  168. package/dist/kernel/events/tool-events.d.ts +13 -0
  169. package/dist/kernel/index.js +4 -4
  170. package/dist/mailbox-attach.d.ts +1 -1
  171. package/dist/models/index.js +10 -9
  172. package/dist/observability/event-bridge.d.ts +25 -5
  173. package/dist/observability/index.d.ts +9 -8
  174. package/dist/observability/index.js +459 -351
  175. package/dist/observability/tool-usage-source.d.ts +65 -0
  176. package/dist/plugin/index.d.ts +5 -0
  177. package/dist/plugin/index.js +66 -50
  178. package/dist/plugins/auto-review-plugin.d.ts +3 -2
  179. package/dist/plugins/review-finding-commands.d.ts +0 -8
  180. package/dist/{review-finding-store-DKAV3AS6.js → plugins/review-finding-store.js} +7 -6
  181. package/dist/plugins/review-finding-types.js +19 -0
  182. package/dist/plugins/review-report-integration.js +21 -0
  183. package/dist/{review-report-store-OWY3EC3N.js → plugins/review-report-store.js} +7 -6
  184. package/dist/plugins/review-report-types.js +13 -0
  185. package/dist/prompts/index.js +5 -5
  186. package/dist/registry/index.js +3 -3
  187. package/dist/registry/tool-registry.d.ts +59 -9
  188. package/dist/{registry-R23UBE7H.js → registry-7N4O3E7W.js} +5 -5
  189. package/dist/security/capabilities.d.ts +6 -0
  190. package/dist/security/file-permissions.d.ts +1 -1
  191. package/dist/security/index.js +47 -33
  192. package/dist/security/permission-policy.d.ts +12 -1
  193. package/dist/security/secret-scrubber.d.ts +15 -0
  194. package/dist/session-catalog/index.d.ts +1 -0
  195. package/dist/session-catalog/index.js +19 -14
  196. package/dist/session-catalog/project-server.js +30 -13
  197. package/dist/session-catalog/protocol.d.ts +32 -1
  198. package/dist/session-catalog/registry.d.ts +17 -1
  199. package/dist/session-catalog/session-agents.d.ts +56 -0
  200. package/dist/session-catalog/store-rebuild.d.ts +14 -0
  201. package/dist/session-catalog/store-schema.d.ts +26 -0
  202. package/dist/session-catalog/store.d.ts +27 -1
  203. package/dist/session-note-attach.d.ts +9 -0
  204. package/dist/skills/index.js +5 -5
  205. package/dist/statusline/index.d.ts +43 -0
  206. package/dist/statusline/index.js +102 -0
  207. package/dist/storage/board-store-port.d.ts +2 -2
  208. package/dist/storage/config-loader/in-project-policy.d.ts +29 -0
  209. package/dist/storage/config-loader.d.ts +3 -2
  210. package/dist/storage/file-session-writer.d.ts +4 -2
  211. package/dist/storage/goal-coordination.d.ts +6 -1
  212. package/dist/storage/goal-kanban.d.ts +4 -1
  213. package/dist/storage/index.d.ts +12 -4
  214. package/dist/storage/index.js +76 -61
  215. package/dist/storage/input-history-store.d.ts +2 -4
  216. package/dist/storage/memory-curator.d.ts +133 -0
  217. package/dist/storage/session-agent-attribution.d.ts +39 -0
  218. package/dist/storage/session-doctor.d.ts +109 -0
  219. package/dist/storage/session-event-bridge.d.ts +5 -7
  220. package/dist/storage/session-outcome.d.ts +42 -0
  221. package/dist/storage/session-recovery.d.ts +55 -0
  222. package/dist/storage/session-store/load-session-data.d.ts +11 -0
  223. package/dist/storage/session-store/prune-helpers.d.ts +1 -1
  224. package/dist/storage/session-store/resume-session.d.ts +0 -2
  225. package/dist/storage/session-store/types.d.ts +8 -0
  226. package/dist/storage/session-store.d.ts +3 -3
  227. package/dist/storage/session-summary-tracker.d.ts +8 -1
  228. package/dist/storage/session-write-buffer.d.ts +18 -0
  229. package/dist/storage/session-writer-truncate.d.ts +2 -0
  230. package/dist/tasking/index.js +2 -2
  231. package/dist/tools/fallback-manage-tools.d.ts +6 -4
  232. package/dist/tools/index.js +21 -21
  233. package/dist/tools/model-tier-set-tool.d.ts +66 -0
  234. package/dist/types/agent-bridge.d.ts +2 -1
  235. package/dist/types/config/mcp-features.d.ts +7 -0
  236. package/dist/types/config/model-tiers.d.ts +148 -0
  237. package/dist/types/config/root.d.ts +9 -0
  238. package/dist/types/config/tools.d.ts +73 -0
  239. package/dist/types/config.d.ts +1 -0
  240. package/dist/types/context.d.ts +2 -0
  241. package/dist/types/default-config.d.ts +6 -0
  242. package/dist/types/errors.d.ts +2 -1
  243. package/dist/types/index.d.ts +11 -9
  244. package/dist/types/index.js +25 -15
  245. package/dist/types/multi-agent.d.ts +43 -0
  246. package/dist/types/plugin.d.ts +1 -1
  247. package/dist/types/provider.d.ts +15 -0
  248. package/dist/types/runtime-capability-manifest.d.ts +1 -1
  249. package/dist/types/secret-scrubber.d.ts +15 -0
  250. package/dist/types/session-markers.d.ts +37 -10
  251. package/dist/types/session-markers.js +1 -1
  252. package/dist/types/session-timeline.d.ts +197 -0
  253. package/dist/types/session-timeline.js +12 -0
  254. package/dist/types/session.d.ts +172 -11
  255. package/dist/types/system-prompt.d.ts +27 -0
  256. package/dist/utils/config-backup.d.ts +9 -1
  257. package/dist/utils/heap-watchdog.js +2 -2
  258. package/dist/utils/index.js +50 -48
  259. package/dist/utils/message-invariants.d.ts +4 -1
  260. package/dist/utils/regex-guard.d.ts +1 -1
  261. package/dist/utils/socket-path.d.ts +1 -1
  262. package/dist/utils/token-estimate.d.ts +6 -2
  263. package/dist/utils/wstack-paths.d.ts +2 -0
  264. package/dist/wiring/proxy-rewrite.d.ts +28 -0
  265. package/dist/wiring/proxy-rewrite.js +7 -1
  266. package/dist/worktree/index.js +2 -2
  267. package/instructions/agents/explore-companion.md +45 -18
  268. package/instructions/agents/memory-curator.md +34 -22
  269. package/instructions/coordination/director-preamble.md +12 -7
  270. package/instructions/coordination/subagent-baseline.md +26 -5
  271. package/instructions/leader-after-task.md +4 -1
  272. package/instructions/llm/chimera-review.md +30 -9
  273. package/instructions/llm/memory-curator.md +31 -0
  274. package/instructions/sections/tool/delegation-compact.md +2 -0
  275. package/instructions/sections/tool/delegation-full.md +5 -1
  276. package/instructions/sections/tool/mailbox-compact.md +5 -1
  277. package/instructions/sections/tool/mailbox-full.md +3 -0
  278. package/instructions/sections/tool/session-note-compact.md +3 -0
  279. package/instructions/sections/tool/session-note-full.md +15 -0
  280. package/instructions/system-lite.md +9 -4
  281. package/instructions/system-pro.md +66 -143
  282. package/instructions/system.md +73 -175
  283. package/package.json +33 -5
  284. package/dist/chunk-2BUUIMQB.js +0 -225
  285. package/dist/chunk-FAYRX2AD.js +0 -13
  286. package/dist/chunk-H5E77KUJ.js +0 -15
  287. package/dist/chunk-M7BS2K6U.js +0 -1
  288. package/dist/coordination/agents.d.ts +0 -8
  289. package/dist/coordination/transport.d.ts +0 -2
  290. package/dist/storage/session-writer/session-writer-summary-tracker.d.ts +0 -28
@@ -1,8 +1,8 @@
1
+ export { assertProjectRootOutsideStateDir, type BootConfigOptions, type BootConfigResult, bootConfig, flagsToConfigPatch, } from '../boot.js';
2
+ export { CONTEXT_MANAGER_TOOL_NAME, type ContextManagerAction, type ContextManagerInput, type ContextManagerResult, type ContextManagerToolOptions, contextManagerTool, createContextManagerTool, } from './context-manager.js';
1
3
  export { DefaultLogger, type DefaultLoggerOptions, type LogFormat } from './logger.js';
4
+ export { allServers, awsServer, blockServer, braveSearchServer, context7Server, everArtServer, filesystemServer, githubServer, googleMapsServer, miniMaxVisionServer, playwrightServer, sentinelServer, slackServer, sshManagerServer, zaiVisionServer, } from './mcp-servers.js';
2
5
  export { DefaultPathResolver } from './path-resolver.js';
3
- export { DefaultTokenCounter } from './token-counter.js';
4
6
  export { ProviderCacheLedger } from './provider-cache-ledger.js';
5
- export { filesystemServer, githubServer, context7Server, braveSearchServer, blockServer, everArtServer, slackServer, awsServer, googleMapsServer, sentinelServer, zaiVisionServer, miniMaxVisionServer, playwrightServer, sshManagerServer, allServers, } from './mcp-servers.js';
6
- export { contextManagerTool, createContextManagerTool, type ContextManagerInput, type ContextManagerResult, type ContextManagerAction, type ContextManagerToolOptions, } from './context-manager.js';
7
- export { assertProjectRootOutsideStateDir, bootConfig, flagsToConfigPatch, type BootConfigOptions, type BootConfigResult, } from '../boot.js';
7
+ export { DefaultTokenCounter } from './token-counter.js';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -4,9 +4,9 @@ import {
4
4
  assertProjectRootOutsideStateDir,
5
5
  bootConfig,
6
6
  flagsToConfigPatch
7
- } from "../chunk-JTHKOYWU.js";
8
- import "../chunk-IQ35HMQL.js";
9
- import "../chunk-6AKOTGLM.js";
7
+ } from "../chunk-MJPHJRAL.js";
8
+ import "../chunk-5YPSXQXM.js";
9
+ import "../chunk-CU546ESW.js";
10
10
  import {
11
11
  allServers,
12
12
  awsServer,
@@ -28,272 +28,30 @@ import "../chunk-YY6APYUM.js";
28
28
  import {
29
29
  DefaultLogger
30
30
  } from "../chunk-WBPVKEEE.js";
31
- import "../chunk-H5E77KUJ.js";
32
- import "../chunk-ZZ4V3WIZ.js";
33
- import {
34
- promptCacheHitRatio
35
- } from "../chunk-NFAYHPRH.js";
36
- import "../chunk-CQQL4ZOQ.js";
37
- import "../chunk-RPOA7IAE.js";
38
- import "../chunk-DEIQMBD2.js";
31
+ import "../chunk-ZT7JNIGX.js";
32
+ import "../chunk-W5VITDM2.js";
33
+ import "../chunk-B7F4WVP4.js";
34
+ import "../chunk-6FHWXLPT.js";
39
35
  import {
40
36
  repairToolUseAdjacency
41
- } from "../chunk-M2WF6AXG.js";
42
- import "../chunk-4XV6IR37.js";
37
+ } from "../chunk-LSMMOS2Z.js";
43
38
  import "../chunk-4VWO3ZXL.js";
39
+ import "../chunk-HI3JGZR2.js";
44
40
  import {
45
41
  estimateMessageTokens,
46
42
  estimateRequestTokens
47
- } from "../chunk-FSWCWSTS.js";
48
- import "../chunk-7ZHZE5EO.js";
49
- import "../chunk-YNCVSFGF.js";
43
+ } from "../chunk-HMLIGAU7.js";
44
+ import "../chunk-OSGLYW5J.js";
45
+ import "../chunk-SAFHACFA.js";
46
+ import "../chunk-DLHHXUAM.js";
47
+ import {
48
+ promptCacheHitRatio
49
+ } from "../chunk-3ECENVHL.js";
50
50
  import "../chunk-KJ2ZTQSL.js";
51
51
  import "../chunk-B4AMLZPB.js";
52
- import "../chunk-WOEZV3Q4.js";
53
- import "../chunk-TBRL2RCC.js";
54
52
  import "../chunk-PFZO3C6H.js";
55
-
56
- // src/infrastructure/token-counter.ts
57
- var PRICE_CACHE_MAX_SIZE = 100;
58
- var DefaultTokenCounter = class {
59
- input = 0;
60
- output = 0;
61
- cacheRead = 0;
62
- cacheWrite = 0;
63
- cacheWrite5m = 0;
64
- cacheWrite1h = 0;
65
- costInput = 0;
66
- costOutput = 0;
67
- cacheSaved = 0;
68
- cacheByProvider = /* @__PURE__ */ new Map();
69
- registry;
70
- providerId;
71
- events;
72
- sessionId;
73
- priceCache = /* @__PURE__ */ new Map();
74
- /** Most recently accounted request's tokens. Used for per-request context pressure. */
75
- lastInput = 0;
76
- lastCacheRead = 0;
77
- lastCacheWrite = 0;
78
- constructor(opts = {}) {
79
- this.registry = opts.registry;
80
- this.providerId = opts.providerId;
81
- this.events = opts.events;
82
- this.sessionId = opts.sessionId;
83
- }
84
- setSessionId(sessionId) {
85
- this.sessionId = sessionId;
86
- }
87
- account(usage, model, providerId = this.currentProviderId()) {
88
- const eventSessionId = this.currentSessionId();
89
- this.input += usage.input;
90
- this.output += usage.output;
91
- this.cacheRead += usage.cacheRead ?? 0;
92
- const ttlAggregate = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0 ? (usage.cacheWrite5m ?? 0) + (usage.cacheWrite1h ?? 0) : 0;
93
- const cacheWriteTotal = usage.cacheWrite ?? ttlAggregate;
94
- this.cacheWrite += cacheWriteTotal;
95
- this.cacheWrite5m += usage.cacheWrite5m ?? 0;
96
- this.cacheWrite1h += usage.cacheWrite1h ?? 0;
97
- this.recordProviderCache(usage, providerId, cacheWriteTotal);
98
- this.lastInput = usage.input;
99
- this.lastCacheRead = usage.cacheRead ?? 0;
100
- this.lastCacheWrite = cacheWriteTotal;
101
- const priceKey = providerId && model ? `${providerId}\0${model}` : void 0;
102
- const price = priceKey ? this.priceCache.get(priceKey) : void 0;
103
- if (price) {
104
- this.applyPrice(usage, price);
105
- this.emitAccounted(eventSessionId, model, providerId, usage);
106
- return;
107
- }
108
- if (this.registry && providerId && model) {
109
- if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
110
- const keys = [...this.priceCache.keys()];
111
- this.priceCache.delete(keys[0] ?? "");
112
- }
113
- void this.registry.getModel(providerId, model).then((m) => {
114
- if (m) {
115
- const p = priceFromModel(m);
116
- this.priceCache.set(priceKey, p);
117
- this.applyPrice(usage, p);
118
- }
119
- this.emitAccounted(eventSessionId, model, providerId, usage);
120
- }).catch(() => {
121
- this.events?.emit("token.cost_estimate_unavailable", {
122
- ...eventSessionId ? { sessionId: eventSessionId } : {},
123
- model: model ?? "<unknown>"
124
- });
125
- this.emitAccounted(eventSessionId, model, providerId, usage);
126
- return void 0;
127
- });
128
- return;
129
- }
130
- this.emitAccounted(eventSessionId, model, providerId, usage);
131
- }
132
- /** Synchronous variant for code paths that have already resolved the model. */
133
- accountWithModel(usage, resolved) {
134
- const eventSessionId = this.currentSessionId();
135
- this.input += usage.input;
136
- this.output += usage.output;
137
- this.cacheRead += usage.cacheRead ?? 0;
138
- const ttlAggregate = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0 ? (usage.cacheWrite5m ?? 0) + (usage.cacheWrite1h ?? 0) : 0;
139
- const cacheWriteTotal = usage.cacheWrite ?? ttlAggregate;
140
- this.cacheWrite += cacheWriteTotal;
141
- this.cacheWrite5m += usage.cacheWrite5m ?? 0;
142
- this.cacheWrite1h += usage.cacheWrite1h ?? 0;
143
- this.recordProviderCache(usage, resolved.providerId, cacheWriteTotal);
144
- this.lastInput = usage.input;
145
- this.lastCacheRead = usage.cacheRead ?? 0;
146
- this.lastCacheWrite = cacheWriteTotal;
147
- const price = priceFromModel(resolved);
148
- if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
149
- const keys = [...this.priceCache.keys()];
150
- this.priceCache.delete(keys[0] ?? "");
151
- }
152
- this.priceCache.set(`${resolved.providerId}\0${resolved.modelId}`, price);
153
- this.applyPrice(usage, price);
154
- this.emitAccounted(eventSessionId, resolved.modelId, resolved.providerId, usage);
155
- }
156
- total() {
157
- return {
158
- input: this.input,
159
- output: this.output,
160
- cacheRead: this.cacheRead,
161
- cacheWrite: this.cacheWrite
162
- };
163
- }
164
- currentRequestTokens() {
165
- return {
166
- input: this.lastInput,
167
- cacheRead: this.lastCacheRead,
168
- cacheWrite: this.lastCacheWrite
169
- };
170
- }
171
- setCurrentRequestTokens(input, cacheRead, cacheWrite) {
172
- this.lastInput = input;
173
- this.lastCacheRead = cacheRead ?? 0;
174
- this.lastCacheWrite = cacheWrite ?? 0;
175
- }
176
- estimateCost() {
177
- return {
178
- input: round4(this.costInput),
179
- output: round4(this.costOutput),
180
- total: round4(this.costInput + this.costOutput),
181
- currency: "USD"
182
- };
183
- }
184
- cacheStats() {
185
- const exposeTtlSplit = this.cacheWrite5m > 0 || this.cacheWrite1h > 0;
186
- return {
187
- readTokens: this.cacheRead,
188
- writeTokens: this.cacheWrite,
189
- ...exposeTtlSplit ? { cacheWrite5m: this.cacheWrite5m, cacheWrite1h: this.cacheWrite1h } : {},
190
- hitRatio: promptCacheHitRatio({
191
- input: this.input,
192
- output: this.output,
193
- cacheRead: this.cacheRead,
194
- cacheWrite: this.cacheWrite
195
- }),
196
- savedUsd: round4(this.cacheSaved),
197
- providers: [...this.cacheByProvider.entries()].map(([provider, usage]) => ({
198
- provider,
199
- input: usage.input,
200
- cacheRead: usage.cacheRead,
201
- cacheWrite: usage.cacheWrite,
202
- ...usage.cacheWrite5m > 0 || usage.cacheWrite1h > 0 ? { cacheWrite5m: usage.cacheWrite5m, cacheWrite1h: usage.cacheWrite1h } : {},
203
- hitRatio: promptCacheHitRatio({ ...usage, output: 0 })
204
- })).sort((a, b) => b.cacheRead - a.cacheRead)
205
- };
206
- }
207
- /** Invalidate cached prices so the next account() call fetches fresh data. */
208
- invalidateCache() {
209
- this.priceCache.clear();
210
- }
211
- emitAccounted(sessionId = this.currentSessionId(), model, providerId = this.currentProviderId(), deltaUsage) {
212
- this.events?.emit("token.accounted", {
213
- ...sessionId ? { sessionId } : {},
214
- usage: this.total(),
215
- ...deltaUsage ? { deltaUsage: { ...deltaUsage } } : {},
216
- cost: {
217
- input: this.costInput,
218
- output: this.costOutput,
219
- total: this.costInput + this.costOutput
220
- },
221
- ...providerId ? { provider: providerId } : {},
222
- ...model ? { model } : {}
223
- });
224
- }
225
- currentSessionId() {
226
- const value = typeof this.sessionId === "function" ? this.sessionId() : this.sessionId;
227
- return typeof value === "string" && value.length > 0 ? value : void 0;
228
- }
229
- currentProviderId() {
230
- const value = typeof this.providerId === "function" ? this.providerId() : this.providerId;
231
- return typeof value === "string" && value.length > 0 ? value : void 0;
232
- }
233
- reset() {
234
- this.input = 0;
235
- this.output = 0;
236
- this.cacheRead = 0;
237
- this.cacheWrite = 0;
238
- this.cacheWrite5m = 0;
239
- this.cacheWrite1h = 0;
240
- this.costInput = 0;
241
- this.costOutput = 0;
242
- this.cacheSaved = 0;
243
- this.cacheByProvider.clear();
244
- this.lastInput = 0;
245
- this.lastCacheRead = 0;
246
- this.lastCacheWrite = 0;
247
- this.emitAccounted(void 0, void 0, void 0, {
248
- input: 0,
249
- output: 0,
250
- cacheRead: 0,
251
- cacheWrite: 0
252
- });
253
- }
254
- recordProviderCache(usage, providerId, derivedCacheWrite) {
255
- const key = providerId ?? "unknown";
256
- const current = this.cacheByProvider.get(key) ?? { input: 0, cacheRead: 0, cacheWrite: 0, cacheWrite5m: 0, cacheWrite1h: 0 };
257
- current.input += usage.input;
258
- current.cacheRead += usage.cacheRead ?? 0;
259
- current.cacheWrite += derivedCacheWrite;
260
- current.cacheWrite5m += usage.cacheWrite5m ?? 0;
261
- current.cacheWrite1h += usage.cacheWrite1h ?? 0;
262
- this.cacheByProvider.set(key, current);
263
- }
264
- applyPrice(usage, price) {
265
- if (price.input) this.costInput += usage.input / 1e6 * price.input;
266
- if (price.output) this.costOutput += usage.output / 1e6 * price.output;
267
- if (usage.cacheRead && price.cacheRead) {
268
- this.costInput += usage.cacheRead / 1e6 * price.cacheRead;
269
- }
270
- if (usage.cacheRead && price.input !== void 0) {
271
- this.cacheSaved += usage.cacheRead / 1e6 * (price.input - (price.cacheRead ?? 0));
272
- }
273
- const hasCacheWriteSplit = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0;
274
- const cacheWrite5m = usage.cacheWrite5m ?? (hasCacheWriteSplit ? 0 : usage.cacheWrite);
275
- const cacheWrite1h = usage.cacheWrite1h ?? 0;
276
- if (cacheWrite5m && (price.cacheWrite5m ?? price.cacheWrite)) {
277
- this.costInput += cacheWrite5m / 1e6 * (price.cacheWrite5m ?? price.cacheWrite ?? 0);
278
- }
279
- if (cacheWrite1h && (price.cacheWrite1h ?? price.cacheWrite)) {
280
- this.costInput += cacheWrite1h / 1e6 * (price.cacheWrite1h ?? price.cacheWrite ?? 0);
281
- }
282
- }
283
- };
284
- function priceFromModel(m) {
285
- return {
286
- input: m.cost?.input,
287
- output: m.cost?.output,
288
- cacheRead: m.cost?.cache_read,
289
- cacheWrite: m.cost?.cache_write,
290
- cacheWrite5m: m.cost?.cache_write_5m ?? m.cost?.cache_write,
291
- cacheWrite1h: m.cost?.cache_write_1h ?? (m.cost?.input !== void 0 ? m.cost.input * 2 : void 0)
292
- };
293
- }
294
- function round4(n) {
295
- return Math.round(n * 1e4) / 1e4;
296
- }
53
+ import "../chunk-25LSLC3G.js";
54
+ import "../chunk-TBRL2RCC.js";
297
55
 
298
56
  // src/infrastructure/context-manager.ts
299
57
  var CONTEXT_MANAGER_TOOL_NAME = "context_manager";
@@ -554,7 +312,270 @@ function createContextManagerTool(opts = {}) {
554
312
  };
555
313
  }
556
314
  var contextManagerTool = createContextManagerTool();
315
+
316
+ // src/infrastructure/token-counter.ts
317
+ var PRICE_CACHE_MAX_SIZE = 100;
318
+ var DefaultTokenCounter = class {
319
+ input = 0;
320
+ output = 0;
321
+ cacheRead = 0;
322
+ cacheWrite = 0;
323
+ cacheWrite5m = 0;
324
+ cacheWrite1h = 0;
325
+ costInput = 0;
326
+ costOutput = 0;
327
+ cacheSaved = 0;
328
+ cacheByProvider = /* @__PURE__ */ new Map();
329
+ registry;
330
+ providerId;
331
+ events;
332
+ sessionId;
333
+ /**
334
+ * Agent this counter belongs to, stamped onto every `token.accounted`.
335
+ * Undefined for the leader. Subagent counters are constructed with the HOST
336
+ * session id (so live cost UIs stay on one row), which makes this the only
337
+ * thing separating a subagent's tokens from the leader's downstream.
338
+ */
339
+ agentId;
340
+ priceCache = /* @__PURE__ */ new Map();
341
+ /** Most recently accounted request's tokens. Used for per-request context pressure. */
342
+ lastInput = 0;
343
+ lastCacheRead = 0;
344
+ lastCacheWrite = 0;
345
+ constructor(opts = {}) {
346
+ this.registry = opts.registry;
347
+ this.providerId = opts.providerId;
348
+ this.events = opts.events;
349
+ this.sessionId = opts.sessionId;
350
+ this.agentId = opts.agentId;
351
+ }
352
+ setSessionId(sessionId) {
353
+ this.sessionId = sessionId;
354
+ }
355
+ account(usage, model, providerId = this.currentProviderId()) {
356
+ const eventSessionId = this.currentSessionId();
357
+ this.input += usage.input;
358
+ this.output += usage.output;
359
+ this.cacheRead += usage.cacheRead ?? 0;
360
+ const ttlAggregate = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0 ? (usage.cacheWrite5m ?? 0) + (usage.cacheWrite1h ?? 0) : 0;
361
+ const cacheWriteTotal = usage.cacheWrite ?? ttlAggregate;
362
+ this.cacheWrite += cacheWriteTotal;
363
+ this.cacheWrite5m += usage.cacheWrite5m ?? 0;
364
+ this.cacheWrite1h += usage.cacheWrite1h ?? 0;
365
+ this.recordProviderCache(usage, providerId, cacheWriteTotal);
366
+ this.lastInput = usage.input;
367
+ this.lastCacheRead = usage.cacheRead ?? 0;
368
+ this.lastCacheWrite = cacheWriteTotal;
369
+ const priceKey = providerId && model ? `${providerId}\0${model}` : void 0;
370
+ const price = priceKey ? this.priceCache.get(priceKey) : void 0;
371
+ if (price) {
372
+ this.applyPrice(usage, price);
373
+ this.emitAccounted(eventSessionId, model, providerId, usage);
374
+ return;
375
+ }
376
+ if (this.registry && providerId && model) {
377
+ if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
378
+ const keys = [...this.priceCache.keys()];
379
+ this.priceCache.delete(keys[0] ?? "");
380
+ }
381
+ void this.registry.getModel(providerId, model).then((m) => {
382
+ if (m) {
383
+ const p = priceFromModel(m);
384
+ this.priceCache.set(priceKey, p);
385
+ this.applyPrice(usage, p);
386
+ }
387
+ this.emitAccounted(eventSessionId, model, providerId, usage);
388
+ }).catch(() => {
389
+ this.events?.emit("token.cost_estimate_unavailable", {
390
+ ...eventSessionId ? { sessionId: eventSessionId } : {},
391
+ model: model ?? "<unknown>"
392
+ });
393
+ this.emitAccounted(eventSessionId, model, providerId, usage);
394
+ return void 0;
395
+ });
396
+ return;
397
+ }
398
+ this.emitAccounted(eventSessionId, model, providerId, usage);
399
+ }
400
+ /** Synchronous variant for code paths that have already resolved the model. */
401
+ accountWithModel(usage, resolved) {
402
+ const eventSessionId = this.currentSessionId();
403
+ this.input += usage.input;
404
+ this.output += usage.output;
405
+ this.cacheRead += usage.cacheRead ?? 0;
406
+ const ttlAggregate = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0 ? (usage.cacheWrite5m ?? 0) + (usage.cacheWrite1h ?? 0) : 0;
407
+ const cacheWriteTotal = usage.cacheWrite ?? ttlAggregate;
408
+ this.cacheWrite += cacheWriteTotal;
409
+ this.cacheWrite5m += usage.cacheWrite5m ?? 0;
410
+ this.cacheWrite1h += usage.cacheWrite1h ?? 0;
411
+ this.recordProviderCache(usage, resolved.providerId, cacheWriteTotal);
412
+ this.lastInput = usage.input;
413
+ this.lastCacheRead = usage.cacheRead ?? 0;
414
+ this.lastCacheWrite = cacheWriteTotal;
415
+ const price = priceFromModel(resolved);
416
+ if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
417
+ const keys = [...this.priceCache.keys()];
418
+ this.priceCache.delete(keys[0] ?? "");
419
+ }
420
+ this.priceCache.set(`${resolved.providerId}\0${resolved.modelId}`, price);
421
+ this.applyPrice(usage, price);
422
+ this.emitAccounted(eventSessionId, resolved.modelId, resolved.providerId, usage);
423
+ }
424
+ total() {
425
+ return {
426
+ input: this.input,
427
+ output: this.output,
428
+ cacheRead: this.cacheRead,
429
+ cacheWrite: this.cacheWrite
430
+ };
431
+ }
432
+ currentRequestTokens() {
433
+ return {
434
+ input: this.lastInput,
435
+ cacheRead: this.lastCacheRead,
436
+ cacheWrite: this.lastCacheWrite
437
+ };
438
+ }
439
+ setCurrentRequestTokens(input, cacheRead, cacheWrite) {
440
+ this.lastInput = input;
441
+ this.lastCacheRead = cacheRead ?? 0;
442
+ this.lastCacheWrite = cacheWrite ?? 0;
443
+ }
444
+ estimateCost() {
445
+ return {
446
+ input: round4(this.costInput),
447
+ output: round4(this.costOutput),
448
+ total: round4(this.costInput + this.costOutput),
449
+ currency: "USD"
450
+ };
451
+ }
452
+ cacheStats() {
453
+ const exposeTtlSplit = this.cacheWrite5m > 0 || this.cacheWrite1h > 0;
454
+ return {
455
+ readTokens: this.cacheRead,
456
+ writeTokens: this.cacheWrite,
457
+ ...exposeTtlSplit ? { cacheWrite5m: this.cacheWrite5m, cacheWrite1h: this.cacheWrite1h } : {},
458
+ hitRatio: promptCacheHitRatio({
459
+ input: this.input,
460
+ output: this.output,
461
+ cacheRead: this.cacheRead,
462
+ cacheWrite: this.cacheWrite
463
+ }),
464
+ savedUsd: round4(this.cacheSaved),
465
+ providers: [...this.cacheByProvider.entries()].map(([provider, usage]) => ({
466
+ provider,
467
+ input: usage.input,
468
+ cacheRead: usage.cacheRead,
469
+ cacheWrite: usage.cacheWrite,
470
+ ...usage.cacheWrite5m > 0 || usage.cacheWrite1h > 0 ? { cacheWrite5m: usage.cacheWrite5m, cacheWrite1h: usage.cacheWrite1h } : {},
471
+ hitRatio: promptCacheHitRatio({ ...usage, output: 0 })
472
+ })).sort((a, b) => b.cacheRead - a.cacheRead)
473
+ };
474
+ }
475
+ /** Invalidate cached prices so the next account() call fetches fresh data. */
476
+ invalidateCache() {
477
+ this.priceCache.clear();
478
+ }
479
+ emitAccounted(sessionId = this.currentSessionId(), model, providerId = this.currentProviderId(), deltaUsage) {
480
+ const agentId = this.currentAgentId();
481
+ this.events?.emit("token.accounted", {
482
+ ...sessionId ? { sessionId } : {},
483
+ ...agentId ? { agentId } : {},
484
+ usage: this.total(),
485
+ ...deltaUsage ? { deltaUsage: { ...deltaUsage } } : {},
486
+ cost: {
487
+ input: this.costInput,
488
+ output: this.costOutput,
489
+ total: this.costInput + this.costOutput
490
+ },
491
+ ...providerId ? { provider: providerId } : {},
492
+ ...model ? { model } : {}
493
+ });
494
+ }
495
+ currentSessionId() {
496
+ const value = typeof this.sessionId === "function" ? this.sessionId() : this.sessionId;
497
+ return typeof value === "string" && value.length > 0 ? value : void 0;
498
+ }
499
+ currentProviderId() {
500
+ const value = typeof this.providerId === "function" ? this.providerId() : this.providerId;
501
+ return typeof value === "string" && value.length > 0 ? value : void 0;
502
+ }
503
+ currentAgentId() {
504
+ const value = typeof this.agentId === "function" ? this.agentId() : this.agentId;
505
+ return typeof value === "string" && value.length > 0 ? value : void 0;
506
+ }
507
+ reset() {
508
+ this.input = 0;
509
+ this.output = 0;
510
+ this.cacheRead = 0;
511
+ this.cacheWrite = 0;
512
+ this.cacheWrite5m = 0;
513
+ this.cacheWrite1h = 0;
514
+ this.costInput = 0;
515
+ this.costOutput = 0;
516
+ this.cacheSaved = 0;
517
+ this.cacheByProvider.clear();
518
+ this.lastInput = 0;
519
+ this.lastCacheRead = 0;
520
+ this.lastCacheWrite = 0;
521
+ this.emitAccounted(void 0, void 0, void 0, {
522
+ input: 0,
523
+ output: 0,
524
+ cacheRead: 0,
525
+ cacheWrite: 0
526
+ });
527
+ }
528
+ recordProviderCache(usage, providerId, derivedCacheWrite) {
529
+ const key = providerId ?? "unknown";
530
+ const current = this.cacheByProvider.get(key) ?? {
531
+ input: 0,
532
+ cacheRead: 0,
533
+ cacheWrite: 0,
534
+ cacheWrite5m: 0,
535
+ cacheWrite1h: 0
536
+ };
537
+ current.input += usage.input;
538
+ current.cacheRead += usage.cacheRead ?? 0;
539
+ current.cacheWrite += derivedCacheWrite;
540
+ current.cacheWrite5m += usage.cacheWrite5m ?? 0;
541
+ current.cacheWrite1h += usage.cacheWrite1h ?? 0;
542
+ this.cacheByProvider.set(key, current);
543
+ }
544
+ applyPrice(usage, price) {
545
+ if (price.input) this.costInput += usage.input / 1e6 * price.input;
546
+ if (price.output) this.costOutput += usage.output / 1e6 * price.output;
547
+ if (usage.cacheRead && price.cacheRead) {
548
+ this.costInput += usage.cacheRead / 1e6 * price.cacheRead;
549
+ }
550
+ if (usage.cacheRead && price.input !== void 0) {
551
+ this.cacheSaved += usage.cacheRead / 1e6 * (price.input - (price.cacheRead ?? 0));
552
+ }
553
+ const hasCacheWriteSplit = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0;
554
+ const cacheWrite5m = usage.cacheWrite5m ?? (hasCacheWriteSplit ? 0 : usage.cacheWrite);
555
+ const cacheWrite1h = usage.cacheWrite1h ?? 0;
556
+ if (cacheWrite5m && (price.cacheWrite5m ?? price.cacheWrite)) {
557
+ this.costInput += cacheWrite5m / 1e6 * (price.cacheWrite5m ?? price.cacheWrite ?? 0);
558
+ }
559
+ if (cacheWrite1h && (price.cacheWrite1h ?? price.cacheWrite)) {
560
+ this.costInput += cacheWrite1h / 1e6 * (price.cacheWrite1h ?? price.cacheWrite ?? 0);
561
+ }
562
+ }
563
+ };
564
+ function priceFromModel(m) {
565
+ return {
566
+ input: m.cost?.input,
567
+ output: m.cost?.output,
568
+ cacheRead: m.cost?.cache_read,
569
+ cacheWrite: m.cost?.cache_write,
570
+ cacheWrite5m: m.cost?.cache_write_5m ?? m.cost?.cache_write,
571
+ cacheWrite1h: m.cost?.cache_write_1h ?? (m.cost?.input !== void 0 ? m.cost.input * 2 : void 0)
572
+ };
573
+ }
574
+ function round4(n) {
575
+ return Math.round(n * 1e4) / 1e4;
576
+ }
557
577
  export {
578
+ CONTEXT_MANAGER_TOOL_NAME,
558
579
  DefaultLogger,
559
580
  DefaultPathResolver,
560
581
  DefaultTokenCounter,
@@ -22,6 +22,13 @@ export declare class DefaultTokenCounter implements TokenCounter {
22
22
  private readonly providerId?;
23
23
  private readonly events?;
24
24
  private sessionId?;
25
+ /**
26
+ * Agent this counter belongs to, stamped onto every `token.accounted`.
27
+ * Undefined for the leader. Subagent counters are constructed with the HOST
28
+ * session id (so live cost UIs stay on one row), which makes this the only
29
+ * thing separating a subagent's tokens from the leader's downstream.
30
+ */
31
+ private readonly agentId?;
25
32
  private priceCache;
26
33
  /** Most recently accounted request's tokens. Used for per-request context pressure. */
27
34
  private lastInput;
@@ -32,6 +39,7 @@ export declare class DefaultTokenCounter implements TokenCounter {
32
39
  providerId?: string | (() => string | undefined) | undefined;
33
40
  events?: EventBus | undefined;
34
41
  sessionId?: string | (() => string | undefined) | undefined;
42
+ agentId?: string | (() => string | undefined) | undefined;
35
43
  });
36
44
  setSessionId(sessionId: string | (() => string | undefined) | undefined): void;
37
45
  account(usage: Usage, model?: string, providerId?: string | undefined): void;
@@ -56,6 +64,7 @@ export declare class DefaultTokenCounter implements TokenCounter {
56
64
  private emitAccounted;
57
65
  private currentSessionId;
58
66
  private currentProviderId;
67
+ private currentAgentId;
59
68
  reset(): void;
60
69
  private recordProviderCache;
61
70
  private applyPrice;