strands-darwin 0.0.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 (417) hide show
  1. package/README.md +140 -0
  2. package/README.zh-CN.md +140 -0
  3. package/dist/patches/@strands-agents+sdk+1.16.0.patch +1443 -0
  4. package/dist/src/agent/background-delegation.d.ts +67 -0
  5. package/dist/src/agent/background-delegation.js +159 -0
  6. package/dist/src/agent/background-delegation.js.map +1 -0
  7. package/dist/src/agent/call-stats.d.ts +118 -0
  8. package/dist/src/agent/call-stats.js +128 -0
  9. package/dist/src/agent/call-stats.js.map +1 -0
  10. package/dist/src/agent/compact.d.ts +108 -0
  11. package/dist/src/agent/compact.js +192 -0
  12. package/dist/src/agent/compact.js.map +1 -0
  13. package/dist/src/agent/context-anchor.d.ts +64 -0
  14. package/dist/src/agent/context-anchor.js +43 -0
  15. package/dist/src/agent/context-anchor.js.map +1 -0
  16. package/dist/src/agent/cost.d.ts +56 -0
  17. package/dist/src/agent/cost.js +44 -0
  18. package/dist/src/agent/cost.js.map +1 -0
  19. package/dist/src/agent/diagnostics.d.ts +212 -0
  20. package/dist/src/agent/diagnostics.js +374 -0
  21. package/dist/src/agent/diagnostics.js.map +1 -0
  22. package/dist/src/agent/instructions.d.ts +54 -0
  23. package/dist/src/agent/instructions.js +118 -0
  24. package/dist/src/agent/instructions.js.map +1 -0
  25. package/dist/src/agent/max-tokens-recovery.d.ts +17 -0
  26. package/dist/src/agent/max-tokens-recovery.js +65 -0
  27. package/dist/src/agent/max-tokens-recovery.js.map +1 -0
  28. package/dist/src/agent/model-call-budget.d.ts +8 -0
  29. package/dist/src/agent/model-call-budget.js +24 -0
  30. package/dist/src/agent/model-call-budget.js.map +1 -0
  31. package/dist/src/agent/model-retry.d.ts +134 -0
  32. package/dist/src/agent/model-retry.js +256 -0
  33. package/dist/src/agent/model-retry.js.map +1 -0
  34. package/dist/src/agent/permission-rules.d.ts +47 -0
  35. package/dist/src/agent/permission-rules.js +260 -0
  36. package/dist/src/agent/permission-rules.js.map +1 -0
  37. package/dist/src/agent/permission.d.ts +361 -0
  38. package/dist/src/agent/permission.js +797 -0
  39. package/dist/src/agent/permission.js.map +1 -0
  40. package/dist/src/agent/prompt-cache.d.ts +66 -0
  41. package/dist/src/agent/prompt-cache.js +194 -0
  42. package/dist/src/agent/prompt-cache.js.map +1 -0
  43. package/dist/src/agent/refusal.d.ts +20 -0
  44. package/dist/src/agent/refusal.js +23 -0
  45. package/dist/src/agent/refusal.js.map +1 -0
  46. package/dist/src/agent/retry-guard.d.ts +26 -0
  47. package/dist/src/agent/retry-guard.js +193 -0
  48. package/dist/src/agent/retry-guard.js.map +1 -0
  49. package/dist/src/agent/rewind.d.ts +29 -0
  50. package/dist/src/agent/rewind.js +118 -0
  51. package/dist/src/agent/rewind.js.map +1 -0
  52. package/dist/src/agent/runtime.d.ts +814 -0
  53. package/dist/src/agent/runtime.js +1596 -0
  54. package/dist/src/agent/runtime.js.map +1 -0
  55. package/dist/src/agent/safety-classifier.d.ts +11 -0
  56. package/dist/src/agent/safety-classifier.js +0 -0
  57. package/dist/src/agent/safety-classifier.js.map +1 -0
  58. package/dist/src/agent/sdk-logging.d.ts +49 -0
  59. package/dist/src/agent/sdk-logging.js +110 -0
  60. package/dist/src/agent/sdk-logging.js.map +1 -0
  61. package/dist/src/agent/session.d.ts +102 -0
  62. package/dist/src/agent/session.js +244 -0
  63. package/dist/src/agent/session.js.map +1 -0
  64. package/dist/src/agent/stream-resumption.d.ts +16 -0
  65. package/dist/src/agent/stream-resumption.js +33 -0
  66. package/dist/src/agent/stream-resumption.js.map +1 -0
  67. package/dist/src/agent/system-prompt.d.ts +50 -0
  68. package/dist/src/agent/system-prompt.js +161 -0
  69. package/dist/src/agent/system-prompt.js.map +1 -0
  70. package/dist/src/agent/thinking.d.ts +99 -0
  71. package/dist/src/agent/thinking.js +145 -0
  72. package/dist/src/agent/thinking.js.map +1 -0
  73. package/dist/src/agent/usage.d.ts +132 -0
  74. package/dist/src/agent/usage.js +233 -0
  75. package/dist/src/agent/usage.js.map +1 -0
  76. package/dist/src/agent/working-context.d.ts +51 -0
  77. package/dist/src/agent/working-context.js +160 -0
  78. package/dist/src/agent/working-context.js.map +1 -0
  79. package/dist/src/agents/child-recipe.d.ts +33 -0
  80. package/dist/src/agents/child-recipe.js +98 -0
  81. package/dist/src/agents/child-recipe.js.map +1 -0
  82. package/dist/src/agents/concurrency-limit.d.ts +25 -0
  83. package/dist/src/agents/concurrency-limit.js +43 -0
  84. package/dist/src/agents/concurrency-limit.js.map +1 -0
  85. package/dist/src/agents/dispatch-registry.d.ts +180 -0
  86. package/dist/src/agents/dispatch-registry.js +289 -0
  87. package/dist/src/agents/dispatch-registry.js.map +1 -0
  88. package/dist/src/agents/failed-child-text.d.ts +44 -0
  89. package/dist/src/agents/failed-child-text.js +69 -0
  90. package/dist/src/agents/failed-child-text.js.map +1 -0
  91. package/dist/src/agents/loader.d.ts +26 -0
  92. package/dist/src/agents/loader.js +134 -0
  93. package/dist/src/agents/loader.js.map +1 -0
  94. package/dist/src/agents/report-projection.d.ts +31 -0
  95. package/dist/src/agents/report-projection.js +125 -0
  96. package/dist/src/agents/report-projection.js.map +1 -0
  97. package/dist/src/agents/subagent-tool.d.ts +61 -0
  98. package/dist/src/agents/subagent-tool.js +180 -0
  99. package/dist/src/agents/subagent-tool.js.map +1 -0
  100. package/dist/src/agents/workflow-tool.d.ts +85 -0
  101. package/dist/src/agents/workflow-tool.js +530 -0
  102. package/dist/src/agents/workflow-tool.js.map +1 -0
  103. package/dist/src/cli-args.d.ts +39 -0
  104. package/dist/src/cli-args.js +198 -0
  105. package/dist/src/cli-args.js.map +1 -0
  106. package/dist/src/cli-doctor.d.ts +26 -0
  107. package/dist/src/cli-doctor.js +398 -0
  108. package/dist/src/cli-doctor.js.map +1 -0
  109. package/dist/src/cli-main.d.ts +1 -0
  110. package/dist/src/cli-main.js +279 -0
  111. package/dist/src/cli-main.js.map +1 -0
  112. package/dist/src/cli-sessions.d.ts +17 -0
  113. package/dist/src/cli-sessions.js +136 -0
  114. package/dist/src/cli-sessions.js.map +1 -0
  115. package/dist/src/cli-trajectory.d.ts +37 -0
  116. package/dist/src/cli-trajectory.js +303 -0
  117. package/dist/src/cli-trajectory.js.map +1 -0
  118. package/dist/src/cli-usage.d.ts +18 -0
  119. package/dist/src/cli-usage.js +53 -0
  120. package/dist/src/cli-usage.js.map +1 -0
  121. package/dist/src/cli.d.ts +2 -0
  122. package/dist/src/cli.js +29 -0
  123. package/dist/src/cli.js.map +1 -0
  124. package/dist/src/commands/custom-commands.d.ts +43 -0
  125. package/dist/src/commands/custom-commands.js +155 -0
  126. package/dist/src/commands/custom-commands.js.map +1 -0
  127. package/dist/src/commands/workflow-command.d.ts +26 -0
  128. package/dist/src/commands/workflow-command.js +56 -0
  129. package/dist/src/commands/workflow-command.js.map +1 -0
  130. package/dist/src/config.d.ts +463 -0
  131. package/dist/src/config.js +1457 -0
  132. package/dist/src/config.js.map +1 -0
  133. package/dist/src/context-overflow-error.d.ts +7 -0
  134. package/dist/src/context-overflow-error.js +26 -0
  135. package/dist/src/context-overflow-error.js.map +1 -0
  136. package/dist/src/dev-repl.d.ts +1 -0
  137. package/dist/src/dev-repl.js +365 -0
  138. package/dist/src/dev-repl.js.map +1 -0
  139. package/dist/src/headless-protocol.d.ts +147 -0
  140. package/dist/src/headless-protocol.js +359 -0
  141. package/dist/src/headless-protocol.js.map +1 -0
  142. package/dist/src/headless-runner.d.ts +30 -0
  143. package/dist/src/headless-runner.js +405 -0
  144. package/dist/src/headless-runner.js.map +1 -0
  145. package/dist/src/headless-stdin.d.ts +28 -0
  146. package/dist/src/headless-stdin.js +78 -0
  147. package/dist/src/headless-stdin.js.map +1 -0
  148. package/dist/src/headless.d.ts +106 -0
  149. package/dist/src/headless.js +229 -0
  150. package/dist/src/headless.js.map +1 -0
  151. package/dist/src/hooks/codex-hook-runner.d.ts +92 -0
  152. package/dist/src/hooks/codex-hook-runner.js +446 -0
  153. package/dist/src/hooks/codex-hook-runner.js.map +1 -0
  154. package/dist/src/hooks/codex-hooks.d.ts +23 -0
  155. package/dist/src/hooks/codex-hooks.js +152 -0
  156. package/dist/src/hooks/codex-hooks.js.map +1 -0
  157. package/dist/src/hooks/hook-process.d.ts +23 -0
  158. package/dist/src/hooks/hook-process.js +241 -0
  159. package/dist/src/hooks/hook-process.js.map +1 -0
  160. package/dist/src/hooks/lifecycle-hooks.d.ts +37 -0
  161. package/dist/src/hooks/lifecycle-hooks.js +153 -0
  162. package/dist/src/hooks/lifecycle-hooks.js.map +1 -0
  163. package/dist/src/hooks/tool-hooks.d.ts +63 -0
  164. package/dist/src/hooks/tool-hooks.js +350 -0
  165. package/dist/src/hooks/tool-hooks.js.map +1 -0
  166. package/dist/src/mcp/codegraph-preflight.d.ts +29 -0
  167. package/dist/src/mcp/codegraph-preflight.js +232 -0
  168. package/dist/src/mcp/codegraph-preflight.js.map +1 -0
  169. package/dist/src/mcp/registry.d.ts +133 -0
  170. package/dist/src/mcp/registry.js +209 -0
  171. package/dist/src/mcp/registry.js.map +1 -0
  172. package/dist/src/mcp/web-search-empty-results.d.ts +14 -0
  173. package/dist/src/mcp/web-search-empty-results.js +94 -0
  174. package/dist/src/mcp/web-search-empty-results.js.map +1 -0
  175. package/dist/src/memory/command.d.ts +11 -0
  176. package/dist/src/memory/command.js +253 -0
  177. package/dist/src/memory/command.js.map +1 -0
  178. package/dist/src/memory/controller.d.ts +51 -0
  179. package/dist/src/memory/controller.js +316 -0
  180. package/dist/src/memory/controller.js.map +1 -0
  181. package/dist/src/memory/prompt.d.ts +4 -0
  182. package/dist/src/memory/prompt.js +22 -0
  183. package/dist/src/memory/prompt.js.map +1 -0
  184. package/dist/src/memory/scheduler.d.ts +33 -0
  185. package/dist/src/memory/scheduler.js +134 -0
  186. package/dist/src/memory/scheduler.js.map +1 -0
  187. package/dist/src/memory/state.d.ts +112 -0
  188. package/dist/src/memory/state.js +355 -0
  189. package/dist/src/memory/state.js.map +1 -0
  190. package/dist/src/memory/store.d.ts +19 -0
  191. package/dist/src/memory/store.js +130 -0
  192. package/dist/src/memory/store.js.map +1 -0
  193. package/dist/src/memory/tools.d.ts +29 -0
  194. package/dist/src/memory/tools.js +22 -0
  195. package/dist/src/memory/tools.js.map +1 -0
  196. package/dist/src/memory/validation.d.ts +33 -0
  197. package/dist/src/memory/validation.js +159 -0
  198. package/dist/src/memory/validation.js.map +1 -0
  199. package/dist/src/npm-package/generate-patch.d.ts +23 -0
  200. package/dist/src/npm-package/generate-patch.js +88 -0
  201. package/dist/src/npm-package/generate-patch.js.map +1 -0
  202. package/dist/src/npm-package/patch-package-format.d.ts +43 -0
  203. package/dist/src/npm-package/patch-package-format.js +66 -0
  204. package/dist/src/npm-package/patch-package-format.js.map +1 -0
  205. package/dist/src/paths.d.ts +39 -0
  206. package/dist/src/paths.js +105 -0
  207. package/dist/src/paths.js.map +1 -0
  208. package/dist/src/pricing/cost.d.ts +182 -0
  209. package/dist/src/pricing/cost.js +215 -0
  210. package/dist/src/pricing/cost.js.map +1 -0
  211. package/dist/src/pricing/model-prices.d.ts +112 -0
  212. package/dist/src/pricing/model-prices.js +320 -0
  213. package/dist/src/pricing/model-prices.js.map +1 -0
  214. package/dist/src/sdk-patch-preflight.d.ts +23 -0
  215. package/dist/src/sdk-patch-preflight.js +71 -0
  216. package/dist/src/sdk-patch-preflight.js.map +1 -0
  217. package/dist/src/skills/builtin/commit-message/SKILL.md +45 -0
  218. package/dist/src/skills/builtin/commit-message/references/types.md +8 -0
  219. package/dist/src/skills/builtin/developer/SKILL.md +107 -0
  220. package/dist/src/skills/builtin/self-evolution-research/SKILL.md +150 -0
  221. package/dist/src/skills/builtin/self-evolution-research/scripts/roll-research-path.mjs +208 -0
  222. package/dist/src/skills/builtin/self-reflection/SKILL.md +172 -0
  223. package/dist/src/skills/builtin/self-reflection/references/reflection-template.md +90 -0
  224. package/dist/src/skills/builtin/self-reflection/scripts/locate-trajectory.mjs +175 -0
  225. package/dist/src/skills/loader.d.ts +26 -0
  226. package/dist/src/skills/loader.js +186 -0
  227. package/dist/src/skills/loader.js.map +1 -0
  228. package/dist/src/skills/plugin.d.ts +34 -0
  229. package/dist/src/skills/plugin.js +137 -0
  230. package/dist/src/skills/plugin.js.map +1 -0
  231. package/dist/src/skills/prompt.d.ts +8 -0
  232. package/dist/src/skills/prompt.js +214 -0
  233. package/dist/src/skills/prompt.js.map +1 -0
  234. package/dist/src/skills/resource-safety.d.ts +15 -0
  235. package/dist/src/skills/resource-safety.js +149 -0
  236. package/dist/src/skills/resource-safety.js.map +1 -0
  237. package/dist/src/tools/background-bash.d.ts +95 -0
  238. package/dist/src/tools/background-bash.js +639 -0
  239. package/dist/src/tools/background-bash.js.map +1 -0
  240. package/dist/src/tools/background-tail.d.ts +28 -0
  241. package/dist/src/tools/background-tail.js +75 -0
  242. package/dist/src/tools/background-tail.js.map +1 -0
  243. package/dist/src/tools/background-wait-contract.d.ts +4 -0
  244. package/dist/src/tools/background-wait-contract.js +7 -0
  245. package/dist/src/tools/background-wait-contract.js.map +1 -0
  246. package/dist/src/tools/file-editor-serial.d.ts +24 -0
  247. package/dist/src/tools/file-editor-serial.js +99 -0
  248. package/dist/src/tools/file-editor-serial.js.map +1 -0
  249. package/dist/src/tools/image-viewer.d.ts +43 -0
  250. package/dist/src/tools/image-viewer.js +256 -0
  251. package/dist/src/tools/image-viewer.js.map +1 -0
  252. package/dist/src/tools/update-plan.d.ts +30 -0
  253. package/dist/src/tools/update-plan.js +65 -0
  254. package/dist/src/tools/update-plan.js.map +1 -0
  255. package/dist/src/tools/web-fetch.d.ts +70 -0
  256. package/dist/src/tools/web-fetch.js +667 -0
  257. package/dist/src/tools/web-fetch.js.map +1 -0
  258. package/dist/src/trajectory/export.d.ts +31 -0
  259. package/dist/src/trajectory/export.js +116 -0
  260. package/dist/src/trajectory/export.js.map +1 -0
  261. package/dist/src/trajectory/fork.d.ts +19 -0
  262. package/dist/src/trajectory/fork.js +110 -0
  263. package/dist/src/trajectory/fork.js.map +1 -0
  264. package/dist/src/trajectory/memory-tool.d.ts +20 -0
  265. package/dist/src/trajectory/memory-tool.js +98 -0
  266. package/dist/src/trajectory/memory-tool.js.map +1 -0
  267. package/dist/src/trajectory/prompt-history.d.ts +62 -0
  268. package/dist/src/trajectory/prompt-history.js +256 -0
  269. package/dist/src/trajectory/prompt-history.js.map +1 -0
  270. package/dist/src/trajectory/reader.d.ts +21 -0
  271. package/dist/src/trajectory/reader.js +62 -0
  272. package/dist/src/trajectory/reader.js.map +1 -0
  273. package/dist/src/trajectory/record.d.ts +417 -0
  274. package/dist/src/trajectory/record.js +394 -0
  275. package/dist/src/trajectory/record.js.map +1 -0
  276. package/dist/src/trajectory/replay.d.ts +74 -0
  277. package/dist/src/trajectory/replay.js +285 -0
  278. package/dist/src/trajectory/replay.js.map +1 -0
  279. package/dist/src/trajectory/resume-recap.d.ts +43 -0
  280. package/dist/src/trajectory/resume-recap.js +68 -0
  281. package/dist/src/trajectory/resume-recap.js.map +1 -0
  282. package/dist/src/trajectory/search.d.ts +40 -0
  283. package/dist/src/trajectory/search.js +127 -0
  284. package/dist/src/trajectory/search.js.map +1 -0
  285. package/dist/src/trajectory/spend.d.ts +157 -0
  286. package/dist/src/trajectory/spend.js +264 -0
  287. package/dist/src/trajectory/spend.js.map +1 -0
  288. package/dist/src/trajectory/stream.d.ts +30 -0
  289. package/dist/src/trajectory/stream.js +30 -0
  290. package/dist/src/trajectory/stream.js.map +1 -0
  291. package/dist/src/trajectory/writer.d.ts +310 -0
  292. package/dist/src/trajectory/writer.js +636 -0
  293. package/dist/src/trajectory/writer.js.map +1 -0
  294. package/dist/src/tui/App.d.ts +109 -0
  295. package/dist/src/tui/App.js +2660 -0
  296. package/dist/src/tui/App.js.map +1 -0
  297. package/dist/src/tui/InputBox.d.ts +90 -0
  298. package/dist/src/tui/InputBox.js +129 -0
  299. package/dist/src/tui/InputBox.js.map +1 -0
  300. package/dist/src/tui/MarkdownText.d.ts +16 -0
  301. package/dist/src/tui/MarkdownText.js +117 -0
  302. package/dist/src/tui/MarkdownText.js.map +1 -0
  303. package/dist/src/tui/MessageList.d.ts +27 -0
  304. package/dist/src/tui/MessageList.js +61 -0
  305. package/dist/src/tui/MessageList.js.map +1 -0
  306. package/dist/src/tui/PermissionPrompt.d.ts +18 -0
  307. package/dist/src/tui/PermissionPrompt.js +114 -0
  308. package/dist/src/tui/PermissionPrompt.js.map +1 -0
  309. package/dist/src/tui/PlanChecklist.d.ts +7 -0
  310. package/dist/src/tui/PlanChecklist.js +12 -0
  311. package/dist/src/tui/PlanChecklist.js.map +1 -0
  312. package/dist/src/tui/QueuedMessages.d.ts +8 -0
  313. package/dist/src/tui/QueuedMessages.js +24 -0
  314. package/dist/src/tui/QueuedMessages.js.map +1 -0
  315. package/dist/src/tui/StartupScreen.d.ts +25 -0
  316. package/dist/src/tui/StartupScreen.js +51 -0
  317. package/dist/src/tui/StartupScreen.js.map +1 -0
  318. package/dist/src/tui/ToolCallPanel.d.ts +33 -0
  319. package/dist/src/tui/ToolCallPanel.js +112 -0
  320. package/dist/src/tui/ToolCallPanel.js.map +1 -0
  321. package/dist/src/tui/WelcomeHeader.d.ts +30 -0
  322. package/dist/src/tui/WelcomeHeader.js +69 -0
  323. package/dist/src/tui/WelcomeHeader.js.map +1 -0
  324. package/dist/src/tui/background-tool-presentation.d.ts +22 -0
  325. package/dist/src/tui/background-tool-presentation.js +209 -0
  326. package/dist/src/tui/background-tool-presentation.js.map +1 -0
  327. package/dist/src/tui/busy-suffix.d.ts +37 -0
  328. package/dist/src/tui/busy-suffix.js +39 -0
  329. package/dist/src/tui/busy-suffix.js.map +1 -0
  330. package/dist/src/tui/clipboard-image.d.ts +18 -0
  331. package/dist/src/tui/clipboard-image.js +109 -0
  332. package/dist/src/tui/clipboard-image.js.map +1 -0
  333. package/dist/src/tui/context-format.d.ts +43 -0
  334. package/dist/src/tui/context-format.js +71 -0
  335. package/dist/src/tui/context-format.js.map +1 -0
  336. package/dist/src/tui/copy-command.d.ts +68 -0
  337. package/dist/src/tui/copy-command.js +182 -0
  338. package/dist/src/tui/copy-command.js.map +1 -0
  339. package/dist/src/tui/edit-diff.d.ts +135 -0
  340. package/dist/src/tui/edit-diff.js +356 -0
  341. package/dist/src/tui/edit-diff.js.map +1 -0
  342. package/dist/src/tui/frame-budget.d.ts +351 -0
  343. package/dist/src/tui/frame-budget.js +446 -0
  344. package/dist/src/tui/frame-budget.js.map +1 -0
  345. package/dist/src/tui/help-format.d.ts +17 -0
  346. package/dist/src/tui/help-format.js +38 -0
  347. package/dist/src/tui/help-format.js.map +1 -0
  348. package/dist/src/tui/live-text.d.ts +51 -0
  349. package/dist/src/tui/live-text.js +154 -0
  350. package/dist/src/tui/live-text.js.map +1 -0
  351. package/dist/src/tui/markdown.d.ts +62 -0
  352. package/dist/src/tui/markdown.js +244 -0
  353. package/dist/src/tui/markdown.js.map +1 -0
  354. package/dist/src/tui/mcp-format.d.ts +28 -0
  355. package/dist/src/tui/mcp-format.js +67 -0
  356. package/dist/src/tui/mcp-format.js.map +1 -0
  357. package/dist/src/tui/path-completion.d.ts +119 -0
  358. package/dist/src/tui/path-completion.js +305 -0
  359. package/dist/src/tui/path-completion.js.map +1 -0
  360. package/dist/src/tui/permission-queue.d.ts +61 -0
  361. package/dist/src/tui/permission-queue.js +129 -0
  362. package/dist/src/tui/permission-queue.js.map +1 -0
  363. package/dist/src/tui/plan-format.d.ts +9 -0
  364. package/dist/src/tui/plan-format.js +30 -0
  365. package/dist/src/tui/plan-format.js.map +1 -0
  366. package/dist/src/tui/prompt-completion.d.ts +22 -0
  367. package/dist/src/tui/prompt-completion.js +46 -0
  368. package/dist/src/tui/prompt-completion.js.map +1 -0
  369. package/dist/src/tui/prompt-editor.d.ts +102 -0
  370. package/dist/src/tui/prompt-editor.js +379 -0
  371. package/dist/src/tui/prompt-editor.js.map +1 -0
  372. package/dist/src/tui/prompt-history-search.d.ts +53 -0
  373. package/dist/src/tui/prompt-history-search.js +123 -0
  374. package/dist/src/tui/prompt-history-search.js.map +1 -0
  375. package/dist/src/tui/prompt-queue.d.ts +58 -0
  376. package/dist/src/tui/prompt-queue.js +74 -0
  377. package/dist/src/tui/prompt-queue.js.map +1 -0
  378. package/dist/src/tui/prompt-recall.d.ts +74 -0
  379. package/dist/src/tui/prompt-recall.js +90 -0
  380. package/dist/src/tui/prompt-recall.js.map +1 -0
  381. package/dist/src/tui/react-environment.d.ts +11 -0
  382. package/dist/src/tui/react-environment.js +24 -0
  383. package/dist/src/tui/react-environment.js.map +1 -0
  384. package/dist/src/tui/rewind-search.d.ts +34 -0
  385. package/dist/src/tui/rewind-search.js +68 -0
  386. package/dist/src/tui/rewind-search.js.map +1 -0
  387. package/dist/src/tui/shell-command.d.ts +114 -0
  388. package/dist/src/tui/shell-command.js +310 -0
  389. package/dist/src/tui/shell-command.js.map +1 -0
  390. package/dist/src/tui/spend-advisory.d.ts +52 -0
  391. package/dist/src/tui/spend-advisory.js +64 -0
  392. package/dist/src/tui/spend-advisory.js.map +1 -0
  393. package/dist/src/tui/status-format.d.ts +120 -0
  394. package/dist/src/tui/status-format.js +192 -0
  395. package/dist/src/tui/status-format.js.map +1 -0
  396. package/dist/src/tui/subagent-format.d.ts +49 -0
  397. package/dist/src/tui/subagent-format.js +146 -0
  398. package/dist/src/tui/subagent-format.js.map +1 -0
  399. package/dist/src/tui/task-format.d.ts +29 -0
  400. package/dist/src/tui/task-format.js +87 -0
  401. package/dist/src/tui/task-format.js.map +1 -0
  402. package/dist/src/tui/terminal-bell.d.ts +20 -0
  403. package/dist/src/tui/terminal-bell.js +33 -0
  404. package/dist/src/tui/terminal-bell.js.map +1 -0
  405. package/dist/src/tui/tool-detail-presentation.d.ts +60 -0
  406. package/dist/src/tui/tool-detail-presentation.js +206 -0
  407. package/dist/src/tui/tool-detail-presentation.js.map +1 -0
  408. package/dist/src/tui/turn-state.d.ts +195 -0
  409. package/dist/src/tui/turn-state.js +548 -0
  410. package/dist/src/tui/turn-state.js.map +1 -0
  411. package/dist/src/tui/visual-language.d.ts +45 -0
  412. package/dist/src/tui/visual-language.js +57 -0
  413. package/dist/src/tui/visual-language.js.map +1 -0
  414. package/dist/src/version.d.ts +7 -0
  415. package/dist/src/version.js +38 -0
  416. package/dist/src/version.js.map +1 -0
  417. package/package.json +60 -0
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Cost accounting — the pure arithmetic and rendering, shared by the live surfaces
3
+ * (`/status`, `/usage`, the headless `cost:` record, through `src/agent/cost.ts`) and
4
+ * the offline trajectory readers (`trajectory list`/`replay`, through
5
+ * `src/trajectory/spend.ts`).
6
+ *
7
+ * It lives under `src/pricing/` and imports nothing from `src/agent/**` so that the
8
+ * trajectory readers can price a record while staying as offline as replaying it: no
9
+ * `Agent`, no `Model`, no config, no I/O — only token buckets and per-token rates.
10
+ *
11
+ * The arithmetic is deliberately simple — Σ bucket × base rate, **per model** — and
12
+ * every rendering says so: the figure is approximate (base rates only, no
13
+ * tiered/long-context pricing, no summarization calls) and is labelled as such wherever
14
+ * it appears. Two honesty rules carry over from `usageBuckets`: an unreported bucket is
15
+ * unknown, never 0, and a model whose price is not known is *unpriced*, never free — a
16
+ * total that leaves either out is a floor, rendered `≥`, and names what it left out.
17
+ */
18
+ /** Per-token USD rates for one model, as LiteLLM publishes them (base tier only). */
19
+ export interface ModelRates {
20
+ inputCostPerToken: number;
21
+ outputCostPerToken: number;
22
+ /** Undefined when LiteLLM lists no cache-read rate for the model. */
23
+ cacheReadInputTokenCost?: number;
24
+ /** Undefined when LiteLLM lists no cache-write (creation) rate for the model. */
25
+ cacheCreationInputTokenCost?: number;
26
+ }
27
+ /**
28
+ * What the price cache knows about one model. `priced` carries the rates and the
29
+ * LiteLLM key they were read under (auditable); `none` means LiteLLM was consulted
30
+ * and has no entry for this id; `unavailable` means the table has not been fetched
31
+ * (yet, or at all — offline, timeout, bad payload).
32
+ */
33
+ export type ModelPriceLookup = {
34
+ kind: 'priced';
35
+ litellmKey: string;
36
+ rates: ModelRates;
37
+ } | {
38
+ kind: 'none';
39
+ } | {
40
+ kind: 'unavailable';
41
+ };
42
+ /** The provenance every rendered figure names, so it can never read as an invoice. */
43
+ export declare const COST_BASIS_LABEL = "base rates, LiteLLM";
44
+ export type CostBucket = 'input' | 'output' | 'cacheRead' | 'cacheWrite';
45
+ /**
46
+ * The four mutually exclusive token buckets, each `undefined` when unknown. The live
47
+ * `UsageBuckets` projection and a trajectory `ModelSpend`'s metric totals both fit.
48
+ */
49
+ export interface CostBuckets {
50
+ input: number | undefined;
51
+ output: number | undefined;
52
+ cacheRead: number | undefined;
53
+ cacheWrite: number | undefined;
54
+ }
55
+ /** Why a bucket could not be priced exactly — three different statements. */
56
+ export interface MissingCostBucket {
57
+ bucket: CostBucket;
58
+ /**
59
+ * `not reported`: no count at all; `unpriced`: counted, but LiteLLM lists no rate;
60
+ * `partly reported`: a sum over turns of which some did not report it (the priced
61
+ * part is in the total, as a floor).
62
+ */
63
+ reason: 'not reported' | 'unpriced' | 'partly reported';
64
+ }
65
+ export interface CostEstimate {
66
+ /** USD per bucket; undefined exactly when the bucket is listed in {@link missing}. */
67
+ input: number | undefined;
68
+ output: number | undefined;
69
+ cacheRead: number | undefined;
70
+ cacheWrite: number | undefined;
71
+ /** USD sum of the priced buckets — a floor when {@link missing} is non-empty. */
72
+ total: number;
73
+ /** Buckets excluded from (or only partly in) the total, in fixed bucket order. */
74
+ missing: readonly MissingCostBucket[];
75
+ }
76
+ /**
77
+ * Σ bucket × rate over the four mutually exclusive buckets of **one** model.
78
+ *
79
+ * A bucket nobody reported is missing (`not reported`); a counted bucket whose rate
80
+ * LiteLLM does not list is missing (`unpriced`) — unless its count is 0, in which
81
+ * case it costs a measured $0 whatever the rate would be. `partlyReported` buckets
82
+ * are priced (the reported part is a floor) and listed as such.
83
+ */
84
+ export declare function estimateCost(buckets: CostBuckets, rates: ModelRates, partlyReported?: readonly CostBucket[]): CostEstimate;
85
+ /** `$0.0123` — USD with four decimals, the resolution the base rates justify. */
86
+ export declare function formatUsd(value: number): string;
87
+ /** `0.0123` — the bare four-decimal figure the headless `cost:` record uses. */
88
+ export declare function formatUsdNumber(value: number): string;
89
+ /** The `pricing=` value of the headless record: the audited key, or why there is none. */
90
+ export declare function describePricingSource(lookup: ModelPriceLookup): string;
91
+ /**
92
+ * One model's share of a session's spend, with what the price cache says about it.
93
+ * The unit every surface prices: a session is a list of these, one per model, each
94
+ * priced at its own rates.
95
+ */
96
+ export interface CostShare {
97
+ /** The darwin model id — the price-cache key, and the name a caveat uses. */
98
+ model: string;
99
+ lookup: ModelPriceLookup;
100
+ buckets: CostBuckets;
101
+ /** Buckets whose count is a sum over turns of which some did not report it. */
102
+ partlyReported?: readonly CostBucket[];
103
+ }
104
+ /** A model whose spend is not in the total, and why. */
105
+ export interface UnpricedModel {
106
+ model: string;
107
+ /** `none`: LiteLLM has no entry; `unavailable`: the table was never read. */
108
+ kind: 'none' | 'unavailable';
109
+ }
110
+ /** A bucket of a priced model that is not (fully) in the total. */
111
+ export interface MissingModelBucket extends MissingCostBucket {
112
+ model: string;
113
+ }
114
+ /**
115
+ * A session's cost over its models. `total` sums the priced buckets of the priced
116
+ * models — the exact figure when {@link exact}, a floor otherwise. Everything the
117
+ * floor leaves out is named: {@link unpriced} models (their spend is unknown money,
118
+ * never $0) and {@link missing} buckets of priced models.
119
+ */
120
+ export interface SessionCost {
121
+ total: number;
122
+ /** Distinct model ids, in first-appearance order. */
123
+ models: readonly string[];
124
+ /** Shares priced at their own rates. */
125
+ pricedShares: number;
126
+ unpriced: readonly UnpricedModel[];
127
+ missing: readonly MissingModelBucket[];
128
+ /**
129
+ * USD per bucket summed over the priced shares, undefined when any share left it
130
+ * unknown — an unpriced model leaves every bucket unknown.
131
+ */
132
+ buckets: {
133
+ input: number | undefined;
134
+ output: number | undefined;
135
+ cacheRead: number | undefined;
136
+ cacheWrite: number | undefined;
137
+ };
138
+ /** No unpriced model, no missing bucket: the total is Σ bucket × rate, nothing left out. */
139
+ exact: boolean;
140
+ }
141
+ /**
142
+ * Prices each share at its own rates and folds them into one {@link SessionCost}.
143
+ *
144
+ * Per model, not "live rates × whole meter": a session that switched models
145
+ * mid-way holds two price lists, and the only honest sum prices each model's tokens
146
+ * with its own. A share without a price contributes nothing and is listed under
147
+ * `unpriced`; a priced share's missing buckets are listed under `missing` with the
148
+ * model that owns them. A share that is a duplicate model id is priced separately
149
+ * and counted once in `models`.
150
+ */
151
+ export declare function sessionCost(shares: readonly CostShare[]): SessionCost;
152
+ /**
153
+ * Cap on one rendered model id in a caveat, in code points: a model id is
154
+ * configuration, so it is as unbounded as any other user-supplied string.
155
+ */
156
+ export declare const MAX_COST_MODEL_CHARS = 60;
157
+ /** A bounded, comma-separated list of model ids: at most three named, the rest counted. */
158
+ export declare function formatModelList(models: readonly string[]): string;
159
+ /**
160
+ * The one-line cost statement every human-facing surface prints — bounded, labelled
161
+ * approximate, and honest about what it does not know:
162
+ *
163
+ * - `≈ $0.0123 (base rates, LiteLLM)` when every bucket of every model is priced;
164
+ * - `≈ $0.0123 (2 models; base rates, LiteLLM)` when more than one model contributed;
165
+ * - `≥ $0.0123 (cacheWrite not reported; base rates, LiteLLM)` when a bucket is not
166
+ * (with more than one model, `<id>: cacheWrite not reported`);
167
+ * - `≥ $0.0123 (2 models; no price for <id>; base rates, LiteLLM)` when a model in
168
+ * the mix has no price — its spend is left out and said so;
169
+ * - `unknown (no price for <id>)` / `unknown (price unavailable)` when nothing could
170
+ * be priced at all.
171
+ *
172
+ * `caveats` are extra reasons the total is a floor that the shares cannot carry
173
+ * (the trajectory's `N turn(s) unknown`); any caveat makes the figure `≥`.
174
+ */
175
+ export declare function describeSessionCost(cost: SessionCost, caveats?: readonly string[]): string;
176
+ /**
177
+ * The machine-facing view of the same figure: each field is the four-decimal USD
178
+ * sum or `-` for unknown — never `0` — and `total` is `-` whenever anything is
179
+ * left out or only partly in, because a floor written into a `total=` field would
180
+ * be read as the total.
181
+ */
182
+ export declare function sessionCostFields(cost: SessionCost): Record<CostBucket | 'total', string>;
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Cost accounting — the pure arithmetic and rendering, shared by the live surfaces
3
+ * (`/status`, `/usage`, the headless `cost:` record, through `src/agent/cost.ts`) and
4
+ * the offline trajectory readers (`trajectory list`/`replay`, through
5
+ * `src/trajectory/spend.ts`).
6
+ *
7
+ * It lives under `src/pricing/` and imports nothing from `src/agent/**` so that the
8
+ * trajectory readers can price a record while staying as offline as replaying it: no
9
+ * `Agent`, no `Model`, no config, no I/O — only token buckets and per-token rates.
10
+ *
11
+ * The arithmetic is deliberately simple — Σ bucket × base rate, **per model** — and
12
+ * every rendering says so: the figure is approximate (base rates only, no
13
+ * tiered/long-context pricing, no summarization calls) and is labelled as such wherever
14
+ * it appears. Two honesty rules carry over from `usageBuckets`: an unreported bucket is
15
+ * unknown, never 0, and a model whose price is not known is *unpriced*, never free — a
16
+ * total that leaves either out is a floor, rendered `≥`, and names what it left out.
17
+ */
18
+ /** The provenance every rendered figure names, so it can never read as an invoice. */
19
+ export const COST_BASIS_LABEL = 'base rates, LiteLLM';
20
+ const BUCKET_ORDER = ['input', 'output', 'cacheRead', 'cacheWrite'];
21
+ /**
22
+ * Σ bucket × rate over the four mutually exclusive buckets of **one** model.
23
+ *
24
+ * A bucket nobody reported is missing (`not reported`); a counted bucket whose rate
25
+ * LiteLLM does not list is missing (`unpriced`) — unless its count is 0, in which
26
+ * case it costs a measured $0 whatever the rate would be. `partlyReported` buckets
27
+ * are priced (the reported part is a floor) and listed as such.
28
+ */
29
+ export function estimateCost(buckets, rates, partlyReported = []) {
30
+ const rateOf = {
31
+ input: rates.inputCostPerToken,
32
+ output: rates.outputCostPerToken,
33
+ cacheRead: rates.cacheReadInputTokenCost,
34
+ cacheWrite: rates.cacheCreationInputTokenCost,
35
+ };
36
+ const priced = {
37
+ input: undefined,
38
+ output: undefined,
39
+ cacheRead: undefined,
40
+ cacheWrite: undefined,
41
+ };
42
+ const missing = [];
43
+ let total = 0;
44
+ for (const bucket of BUCKET_ORDER) {
45
+ const tokens = buckets[bucket];
46
+ if (tokens === undefined) {
47
+ missing.push({ bucket, reason: 'not reported' });
48
+ continue;
49
+ }
50
+ const rate = rateOf[bucket];
51
+ if (tokens === 0) {
52
+ priced[bucket] = 0;
53
+ continue;
54
+ }
55
+ if (rate === undefined || !Number.isFinite(rate)) {
56
+ missing.push({ bucket, reason: 'unpriced' });
57
+ continue;
58
+ }
59
+ const cost = tokens * rate;
60
+ priced[bucket] = cost;
61
+ total += cost;
62
+ if (partlyReported.includes(bucket))
63
+ missing.push({ bucket, reason: 'partly reported' });
64
+ }
65
+ return { ...priced, total, missing };
66
+ }
67
+ /** `$0.0123` — USD with four decimals, the resolution the base rates justify. */
68
+ export function formatUsd(value) {
69
+ return `$${formatUsdNumber(value)}`;
70
+ }
71
+ /** `0.0123` — the bare four-decimal figure the headless `cost:` record uses. */
72
+ export function formatUsdNumber(value) {
73
+ return value.toFixed(4);
74
+ }
75
+ /** The `pricing=` value of the headless record: the audited key, or why there is none. */
76
+ export function describePricingSource(lookup) {
77
+ return lookup.kind === 'priced' ? lookup.litellmKey : lookup.kind;
78
+ }
79
+ /**
80
+ * Prices each share at its own rates and folds them into one {@link SessionCost}.
81
+ *
82
+ * Per model, not "live rates × whole meter": a session that switched models
83
+ * mid-way holds two price lists, and the only honest sum prices each model's tokens
84
+ * with its own. A share without a price contributes nothing and is listed under
85
+ * `unpriced`; a priced share's missing buckets are listed under `missing` with the
86
+ * model that owns them. A share that is a duplicate model id is priced separately
87
+ * and counted once in `models`.
88
+ */
89
+ export function sessionCost(shares) {
90
+ const models = [];
91
+ const unpriced = [];
92
+ const missing = [];
93
+ const buckets = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
94
+ const unknownBuckets = new Set();
95
+ let total = 0;
96
+ let pricedShares = 0;
97
+ for (const share of shares) {
98
+ if (!models.includes(share.model))
99
+ models.push(share.model);
100
+ if (share.lookup.kind !== 'priced') {
101
+ unpriced.push({ model: share.model, kind: share.lookup.kind });
102
+ for (const bucket of BUCKET_ORDER)
103
+ unknownBuckets.add(bucket);
104
+ continue;
105
+ }
106
+ pricedShares += 1;
107
+ const estimate = estimateCost(share.buckets, share.lookup.rates, share.partlyReported ?? []);
108
+ total += estimate.total;
109
+ for (const gap of estimate.missing) {
110
+ missing.push({ model: share.model, ...gap });
111
+ unknownBuckets.add(gap.bucket);
112
+ }
113
+ for (const bucket of BUCKET_ORDER) {
114
+ const value = estimate[bucket];
115
+ if (value !== undefined)
116
+ buckets[bucket] = (buckets[bucket] ?? 0) + value;
117
+ }
118
+ }
119
+ for (const bucket of unknownBuckets)
120
+ buckets[bucket] = undefined;
121
+ return {
122
+ total,
123
+ models,
124
+ pricedShares,
125
+ unpriced,
126
+ missing,
127
+ buckets: { ...buckets },
128
+ exact: unpriced.length === 0 && missing.length === 0,
129
+ };
130
+ }
131
+ /** Models named in a caveat before the rest are only counted — the `spend.ts` bound. */
132
+ const LISTED_MODELS = 3;
133
+ /**
134
+ * Cap on one rendered model id in a caveat, in code points: a model id is
135
+ * configuration, so it is as unbounded as any other user-supplied string.
136
+ */
137
+ export const MAX_COST_MODEL_CHARS = 60;
138
+ /** A bounded, comma-separated list of model ids: at most three named, the rest counted. */
139
+ export function formatModelList(models) {
140
+ const named = models.slice(0, LISTED_MODELS).map((model) => boundedWord(model, MAX_COST_MODEL_CHARS));
141
+ const rest = models.length - named.length;
142
+ return `${named.join(', ')}${rest > 0 ? ` +${rest} more` : ''}`;
143
+ }
144
+ function boundedWord(value, limit) {
145
+ const points = [...value.replace(/\s+/gu, ' ').trim()];
146
+ return points.length <= limit ? points.join('') : `${points.slice(0, Math.max(0, limit - 1)).join('')}…`;
147
+ }
148
+ /**
149
+ * The one-line cost statement every human-facing surface prints — bounded, labelled
150
+ * approximate, and honest about what it does not know:
151
+ *
152
+ * - `≈ $0.0123 (base rates, LiteLLM)` when every bucket of every model is priced;
153
+ * - `≈ $0.0123 (2 models; base rates, LiteLLM)` when more than one model contributed;
154
+ * - `≥ $0.0123 (cacheWrite not reported; base rates, LiteLLM)` when a bucket is not
155
+ * (with more than one model, `<id>: cacheWrite not reported`);
156
+ * - `≥ $0.0123 (2 models; no price for <id>; base rates, LiteLLM)` when a model in
157
+ * the mix has no price — its spend is left out and said so;
158
+ * - `unknown (no price for <id>)` / `unknown (price unavailable)` when nothing could
159
+ * be priced at all.
160
+ *
161
+ * `caveats` are extra reasons the total is a floor that the shares cannot carry
162
+ * (the trajectory's `N turn(s) unknown`); any caveat makes the figure `≥`.
163
+ */
164
+ export function describeSessionCost(cost, caveats = []) {
165
+ const none = cost.unpriced.filter((entry) => entry.kind === 'none').map((entry) => entry.model);
166
+ const unavailable = cost.unpriced.filter((entry) => entry.kind === 'unavailable').map((entry) => entry.model);
167
+ const unpricedClauses = [
168
+ ...(none.length === 0 ? [] : [`no price for ${formatModelList(none)}`]),
169
+ ...(unavailable.length === 0
170
+ ? []
171
+ : [cost.models.length === 1 ? 'price unavailable' : `price unavailable for ${formatModelList(unavailable)}`]),
172
+ ];
173
+ if (cost.pricedShares === 0) {
174
+ return `unknown (${unpricedClauses.length === 0 ? 'no spend recorded' : unpricedClauses.join('; ')})`;
175
+ }
176
+ const missingClauses = cost.models.length === 1
177
+ ? cost.missing.length === 0
178
+ ? []
179
+ : [cost.missing.map(({ bucket, reason }) => `${bucket} ${reason}`).join(', ')]
180
+ : cost.models
181
+ .filter((model) => cost.missing.some((gap) => gap.model === model))
182
+ .map((model) => `${boundedWord(model, MAX_COST_MODEL_CHARS)}: ` +
183
+ cost.missing
184
+ .filter((gap) => gap.model === model)
185
+ .map(({ bucket, reason }) => `${bucket} ${reason}`)
186
+ .join(', '));
187
+ const segments = [
188
+ ...(cost.models.length > 1 ? [`${cost.models.length} models`] : []),
189
+ ...unpricedClauses,
190
+ ...missingClauses,
191
+ ...caveats,
192
+ COST_BASIS_LABEL,
193
+ ];
194
+ const floor = !cost.exact || caveats.length > 0;
195
+ return `${floor ? '≥' : '≈'} ${formatUsd(cost.total)} (${segments.join('; ')})`;
196
+ }
197
+ /**
198
+ * The machine-facing view of the same figure: each field is the four-decimal USD
199
+ * sum or `-` for unknown — never `0` — and `total` is `-` whenever anything is
200
+ * left out or only partly in, because a floor written into a `total=` field would
201
+ * be read as the total.
202
+ */
203
+ export function sessionCostFields(cost) {
204
+ const field = (value) => (value === undefined ? '-' : formatUsdNumber(value));
205
+ if (cost.pricedShares === 0)
206
+ return { input: '-', output: '-', cacheRead: '-', cacheWrite: '-', total: '-' };
207
+ return {
208
+ input: field(cost.buckets.input),
209
+ output: field(cost.buckets.output),
210
+ cacheRead: field(cost.buckets.cacheRead),
211
+ cacheWrite: field(cost.buckets.cacheWrite),
212
+ total: cost.exact ? formatUsdNumber(cost.total) : '-',
213
+ };
214
+ }
215
+ //# sourceMappingURL=cost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.js","sourceRoot":"","sources":["../../../src/pricing/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAuBH,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAsCtD,MAAM,YAAY,GAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;AAE3F;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAoB,EACpB,KAAiB,EACjB,cAAc,GAA0B,EAAE;IAE1C,MAAM,MAAM,GAA2C;QACrD,KAAK,EAAE,KAAK,CAAC,iBAAiB;QAC9B,MAAM,EAAE,KAAK,CAAC,kBAAkB;QAChC,SAAS,EAAE,KAAK,CAAC,uBAAuB;QACxC,UAAU,EAAE,KAAK,CAAC,2BAA2B;KAC9C,CAAC;IACF,MAAM,MAAM,GAA2C;QACrD,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE,SAAS;KACtB,CAAC;IACF,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AI,CAAC,OAAO,CAAC,KAAK,CAAC;QAChC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAClC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QACxC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG;KACtD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,112 @@
1
+ import type { ModelPriceLookup, ModelRates } from './cost.js';
2
+ import type { AppConfig } from '../config.js';
3
+ export declare const MODEL_PRICES_SOURCE_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
4
+ export declare const MODEL_PRICES_SCHEMA_VERSION = 1;
5
+ /** The table is ~2.1 MB today; anything past this is not the table. */
6
+ export declare const MODEL_PRICES_MAX_BYTES: number;
7
+ export declare const MODEL_PRICES_FETCH_TIMEOUT_MS = 10000;
8
+ /** One cached mapping. `litellmKey: null` records "LiteLLM has no entry for this id". */
9
+ export interface ModelPriceEntry extends Partial<ModelRates> {
10
+ litellmKey: string | null;
11
+ /** ISO timestamp of the fetch that produced this entry. */
12
+ fetchedAt: string;
13
+ }
14
+ export interface ModelPriceCache {
15
+ version: typeof MODEL_PRICES_SCHEMA_VERSION;
16
+ source: string;
17
+ models: Record<string, ModelPriceEntry>;
18
+ }
19
+ /** The shape of the price table this module needs — the rest of each entry is ignored. */
20
+ type PriceTable = Record<string, unknown>;
21
+ /** A `PriceConfig` is the part of the live config that decides which LiteLLM key applies. */
22
+ export type PriceConfig = Pick<AppConfig, 'provider' | 'model' | 'bedrockMantle'>;
23
+ export declare function emptyModelPriceCache(): ModelPriceCache;
24
+ /**
25
+ * Reads the cache, tolerant by construction: a missing file, unparsable JSON, a
26
+ * foreign schema version or a non-object root all read as empty, and a malformed
27
+ * entry is skipped rather than failing the file. Never throws.
28
+ */
29
+ export declare function readModelPriceCache(file: string): ModelPriceCache;
30
+ /**
31
+ * Writes the whole cache atomically: a sibling temp file, then `rename`, so a
32
+ * reader never sees a half-written file and a crash leaves the previous one intact.
33
+ * Throws on I/O failure; the store catches, because a price is never worth a turn.
34
+ */
35
+ export declare function writeModelPriceCache(file: string, cache: ModelPriceCache): void;
36
+ /**
37
+ * The LiteLLM keys to try for one darwin model id, most specific match first: the
38
+ * exact id (Bedrock inference profiles such as `global.anthropic.claude-sonnet-5`
39
+ * are listed bare), then the provider-prefixed form LiteLLM uses when the bare id
40
+ * is ambiguous — `bedrock/`, `bedrock_mantle/` (OpenAI-compatible Bedrock), `anthropic/`, `openai/`.
41
+ */
42
+ export declare function priceCandidateKeys(config: PriceConfig): readonly string[];
43
+ /**
44
+ * Resolves one model against a fetched table: the first candidate key whose entry
45
+ * carries numeric `input_cost_per_token` and `output_cost_per_token` wins; the
46
+ * cache rates are copied when present. No hit records `litellmKey: null` — a
47
+ * resolved "no price", not an absence, so the id is not fetched again next launch.
48
+ */
49
+ export declare function resolveModelPrice(table: unknown, config: PriceConfig, fetchedAt: string): ModelPriceEntry;
50
+ /** Projects one cache entry (or its absence) into the lookup the surfaces render. */
51
+ export declare function lookupFromEntry(entry: ModelPriceEntry | undefined): ModelPriceLookup;
52
+ export interface FetchPriceTableOptions {
53
+ fetch?: typeof globalThis.fetch;
54
+ timeoutMs?: number;
55
+ maxBytes?: number;
56
+ url?: string;
57
+ }
58
+ /**
59
+ * Fetches the LiteLLM table with a bounded timeout and a bounded body, or returns
60
+ * `undefined` — never throws. Non-2xx, an over-cap body (by `content-length` or by
61
+ * actually counting the streamed bytes), invalid JSON or a non-object root are all
62
+ * "unavailable"; nothing is written by this function.
63
+ */
64
+ export declare function fetchPriceTable(options?: FetchPriceTableOptions): Promise<PriceTable | undefined>;
65
+ export interface ModelPriceStoreOptions {
66
+ /** The cache file; production uses {@link userModelPricesFile}. */
67
+ file: string;
68
+ fetch?: typeof globalThis.fetch;
69
+ now?: () => Date;
70
+ timeoutMs?: number;
71
+ maxBytes?: number;
72
+ url?: string;
73
+ /**
74
+ * `false` makes {@link ModelPriceStore.ensure} a pure cache check: nothing is ever
75
+ * fetched, only what the file already knows is priced. The default store reads it
76
+ * from {@link MODEL_PRICES_FETCH_ENV} (`off`), which is how `pnpm test` keeps the
77
+ * real-runtime suites off the network and how an air-gapped user keeps darwin from
78
+ * calling GitHub at all.
79
+ */
80
+ fetchEnabled?: boolean;
81
+ }
82
+ /** Set to `off` to disable the background price fetch for the process; the cache is still read. */
83
+ export declare const MODEL_PRICES_FETCH_ENV = "DARWIN_MODEL_PRICES_FETCH";
84
+ /**
85
+ * The per-process price store: read-only {@link lookup} for every surface, and
86
+ * {@link ensure} — lookup, fetch once if absent, record — for startup and `/model`.
87
+ */
88
+ export declare class ModelPriceStore {
89
+ private readonly options;
90
+ /** One settled-or-pending attempt per model id: the "one fetch per process per id" rule. */
91
+ private readonly attempts;
92
+ constructor(options: ModelPriceStoreOptions);
93
+ get file(): string;
94
+ /** What the cache says about this model right now. Synchronous; reads the file, writes nothing. */
95
+ lookup(config: PriceConfig): ModelPriceLookup;
96
+ /**
97
+ * Makes sure the cache has an entry for this model if the network can provide one.
98
+ * A mapped id returns without fetching; an unmapped id fetches at most once per
99
+ * process (shared by concurrent callers) and records the result — the resolved
100
+ * rates, or `litellmKey: null`. Never rejects: callers fire and forget it.
101
+ */
102
+ ensure(config: PriceConfig): Promise<void>;
103
+ private fetchAndRecord;
104
+ }
105
+ /**
106
+ * The process-wide store over `~/.darwin/model-prices.json`. One instance per
107
+ * process so a `/clear` successor runtime shares the fetch-once bookkeeping with
108
+ * its predecessor instead of starting a second download of the same table.
109
+ * `DARWIN_MODEL_PRICES_FETCH=off` in the environment keeps it cache-only.
110
+ */
111
+ export declare function defaultModelPriceStore(): ModelPriceStore;
112
+ export {};