@pentoshi/clai 4.11.5 → 4.11.8

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 (2006) hide show
  1. package/dist/agent/compaction/summary-execution.d.ts +32 -0
  2. package/dist/agent/compaction/summary-execution.js +407 -0
  3. package/dist/agent/compaction/summary-execution.js.map +1 -0
  4. package/dist/agent/compaction-attempt.d.ts +5 -1
  5. package/dist/agent/compaction-attempt.js +22 -12
  6. package/dist/agent/compaction-attempt.js.map +1 -1
  7. package/dist/agent/compaction-executor.d.ts +5 -53
  8. package/dist/agent/compaction-executor.js +11 -442
  9. package/dist/agent/compaction-executor.js.map +1 -1
  10. package/dist/agent/compaction-summary.d.ts +0 -25
  11. package/dist/agent/compaction-summary.js +0 -20
  12. package/dist/agent/compaction-summary.js.map +1 -1
  13. package/dist/agent/confirm-port.d.ts +0 -6
  14. package/dist/agent/confirm-port.js +0 -11
  15. package/dist/agent/confirm-port.js.map +1 -1
  16. package/dist/agent/context/compact-with-summary.d.ts +34 -0
  17. package/dist/agent/context/compact-with-summary.js +381 -0
  18. package/dist/agent/context/compact-with-summary.js.map +1 -0
  19. package/dist/agent/context-breakdown.d.ts +0 -12
  20. package/dist/agent/context-breakdown.js +0 -16
  21. package/dist/agent/context-breakdown.js.map +1 -1
  22. package/dist/agent/context-manager.d.ts +4 -90
  23. package/dist/agent/context-manager.js +6 -464
  24. package/dist/agent/context-manager.js.map +1 -1
  25. package/dist/agent/continue-orient.d.ts +0 -19
  26. package/dist/agent/continue-orient.js +0 -24
  27. package/dist/agent/continue-orient.js.map +1 -1
  28. package/dist/agent/durable-blocks.d.ts +5 -0
  29. package/dist/agent/durable-blocks.js +16 -0
  30. package/dist/agent/durable-blocks.js.map +1 -0
  31. package/dist/agent/durable-envelope.d.ts +0 -2
  32. package/dist/agent/durable-envelope.js +0 -16
  33. package/dist/agent/durable-envelope.js.map +1 -1
  34. package/dist/agent/events.d.ts +6 -17
  35. package/dist/agent/evidence/task-classification.d.ts +25 -0
  36. package/dist/agent/evidence/task-classification.js +124 -0
  37. package/dist/agent/evidence/task-classification.js.map +1 -0
  38. package/dist/agent/evidence/task-selection.d.ts +29 -0
  39. package/dist/agent/evidence/task-selection.js +148 -0
  40. package/dist/agent/evidence/task-selection.js.map +1 -0
  41. package/dist/agent/evidence/tool-budgets.d.ts +12 -0
  42. package/dist/agent/evidence/tool-budgets.js +82 -0
  43. package/dist/agent/evidence/tool-budgets.js.map +1 -0
  44. package/dist/agent/evidence-governor.d.ts +0 -3
  45. package/dist/agent/evidence-governor.js.map +1 -1
  46. package/dist/agent/injected-blocks.d.ts +1 -0
  47. package/dist/agent/injected-blocks.js +14 -4
  48. package/dist/agent/injected-blocks.js.map +1 -1
  49. package/dist/agent/message-slim.d.ts +2 -0
  50. package/dist/agent/message-slim.js +45 -2
  51. package/dist/agent/message-slim.js.map +1 -1
  52. package/dist/agent/outcomes.d.ts +0 -1
  53. package/dist/agent/outcomes.js +0 -11
  54. package/dist/agent/outcomes.js.map +1 -1
  55. package/dist/agent/parser/arg-formatting.d.ts +3 -0
  56. package/dist/agent/parser/arg-formatting.js +99 -0
  57. package/dist/agent/parser/arg-formatting.js.map +1 -0
  58. package/dist/agent/parser/bare-recognition.d.ts +6 -0
  59. package/dist/agent/parser/bare-recognition.js +106 -0
  60. package/dist/agent/parser/bare-recognition.js.map +1 -0
  61. package/dist/agent/parser/parse-entry.d.ts +9 -0
  62. package/dist/agent/parser/parse-entry.js +198 -0
  63. package/dist/agent/parser/parse-entry.js.map +1 -0
  64. package/dist/agent/parser/repetition.d.ts +1 -0
  65. package/dist/agent/parser/repetition.js +72 -0
  66. package/dist/agent/parser/repetition.js.map +1 -0
  67. package/dist/agent/parser/salvage.d.ts +8 -0
  68. package/dist/agent/parser/salvage.js +100 -0
  69. package/dist/agent/parser/salvage.js.map +1 -0
  70. package/dist/agent/parser/vendor-protocols.d.ts +21 -0
  71. package/dist/agent/parser/vendor-protocols.js +265 -0
  72. package/dist/agent/parser/vendor-protocols.js.map +1 -0
  73. package/dist/agent/parser/xml-protocol.d.ts +7 -0
  74. package/dist/agent/parser/xml-protocol.js +455 -0
  75. package/dist/agent/parser/xml-protocol.js.map +1 -0
  76. package/dist/agent/plan/actions/plan-clear.d.ts +4 -0
  77. package/dist/agent/plan/actions/plan-clear.js +46 -0
  78. package/dist/agent/plan/actions/plan-clear.js.map +1 -0
  79. package/dist/agent/plan/actions/plan-create.d.ts +4 -0
  80. package/dist/agent/plan/actions/plan-create.js +371 -0
  81. package/dist/agent/plan/actions/plan-create.js.map +1 -0
  82. package/dist/agent/plan/actions/task-add.d.ts +5 -0
  83. package/dist/agent/plan/actions/task-add.js +131 -0
  84. package/dist/agent/plan/actions/task-add.js.map +1 -0
  85. package/dist/agent/plan/actions/task-move.d.ts +5 -0
  86. package/dist/agent/plan/actions/task-move.js +72 -0
  87. package/dist/agent/plan/actions/task-move.js.map +1 -0
  88. package/dist/agent/plan/context-message.d.ts +2 -0
  89. package/dist/agent/plan/context-message.js +91 -0
  90. package/dist/agent/plan/context-message.js.map +1 -0
  91. package/dist/agent/plan/handle-plan-tool.d.ts +24 -0
  92. package/dist/agent/plan/handle-plan-tool.js +310 -0
  93. package/dist/agent/plan/handle-plan-tool.js.map +1 -0
  94. package/dist/agent/plan/normalization.d.ts +19 -0
  95. package/dist/agent/plan/normalization.js +175 -0
  96. package/dist/agent/plan/normalization.js.map +1 -0
  97. package/dist/agent/plan-implement-compact.d.ts +0 -20
  98. package/dist/agent/plan-implement-compact.js +0 -21
  99. package/dist/agent/plan-implement-compact.js.map +1 -1
  100. package/dist/agent/plan-mode-reminders.d.ts +0 -24
  101. package/dist/agent/plan-mode-reminders.js +0 -21
  102. package/dist/agent/plan-mode-reminders.js.map +1 -1
  103. package/dist/agent/plan-tool.d.ts +5 -60
  104. package/dist/agent/plan-tool.js +7 -1235
  105. package/dist/agent/plan-tool.js.map +1 -1
  106. package/dist/agent/progress-pause-policy.d.ts +0 -1
  107. package/dist/agent/progress-pause-policy.js +1 -5
  108. package/dist/agent/progress-pause-policy.js.map +1 -1
  109. package/dist/agent/progress.d.ts +0 -5
  110. package/dist/agent/progress.js +0 -14
  111. package/dist/agent/progress.js.map +1 -1
  112. package/dist/agent/project-root.d.ts +0 -21
  113. package/dist/agent/project-root.js +0 -36
  114. package/dist/agent/project-root.js.map +1 -1
  115. package/dist/agent/prompt-composer.d.ts +0 -1
  116. package/dist/agent/prompt-composer.js +0 -2
  117. package/dist/agent/prompt-composer.js.map +1 -1
  118. package/dist/agent/reliability-policy.d.ts +0 -38
  119. package/dist/agent/reliability-policy.js +0 -39
  120. package/dist/agent/reliability-policy.js.map +1 -1
  121. package/dist/agent/request-accounting.d.ts +0 -30
  122. package/dist/agent/request-accounting.js +2 -26
  123. package/dist/agent/request-accounting.js.map +1 -1
  124. package/dist/agent/request-budget.d.ts +0 -2
  125. package/dist/agent/request-budget.js +0 -13
  126. package/dist/agent/request-budget.js.map +1 -1
  127. package/dist/agent/responder-context.js +14 -3
  128. package/dist/agent/responder-context.js.map +1 -1
  129. package/dist/agent/responder-parent.d.ts +0 -10
  130. package/dist/agent/responder-parent.js +0 -12
  131. package/dist/agent/responder-parent.js.map +1 -1
  132. package/dist/agent/runner.d.ts +0 -30
  133. package/dist/agent/runner.js +404 -5057
  134. package/dist/agent/runner.js.map +1 -1
  135. package/dist/agent/scope-context.d.ts +0 -1
  136. package/dist/agent/scope-context.js +0 -1
  137. package/dist/agent/scope-context.js.map +1 -1
  138. package/dist/agent/scratch-write.d.ts +0 -1
  139. package/dist/agent/scratch-write.js +0 -1
  140. package/dist/agent/scratch-write.js.map +1 -1
  141. package/dist/agent/session-policy.d.ts +0 -28
  142. package/dist/agent/session-policy.js +0 -34
  143. package/dist/agent/session-policy.js.map +1 -1
  144. package/dist/agent/session-state.d.ts +0 -38
  145. package/dist/agent/session-state.js +4 -41
  146. package/dist/agent/session-state.js.map +1 -1
  147. package/dist/agent/step-budget.d.ts +0 -4
  148. package/dist/agent/step-budget.js +0 -4
  149. package/dist/agent/step-budget.js.map +1 -1
  150. package/dist/agent/stop-summary.d.ts +0 -5
  151. package/dist/agent/stop-summary.js +0 -8
  152. package/dist/agent/stop-summary.js.map +1 -1
  153. package/dist/agent/stream-recovery.d.ts +1 -54
  154. package/dist/agent/stream-recovery.js +4 -53
  155. package/dist/agent/stream-recovery.js.map +1 -1
  156. package/dist/agent/task-evidence.d.ts +10 -159
  157. package/dist/agent/task-evidence.js +10 -477
  158. package/dist/agent/task-evidence.js.map +1 -1
  159. package/dist/agent/task-plan.d.ts +0 -8
  160. package/dist/agent/task-plan.js +0 -6
  161. package/dist/agent/task-plan.js.map +1 -1
  162. package/dist/agent/task-sync.d.ts +0 -25
  163. package/dist/agent/task-sync.js +0 -31
  164. package/dist/agent/task-sync.js.map +1 -1
  165. package/dist/agent/tool-call-parser.d.ts +10 -205
  166. package/dist/agent/tool-call-parser.js +13 -1716
  167. package/dist/agent/tool-call-parser.js.map +1 -1
  168. package/dist/agent/tool-history-projection.d.ts +7 -0
  169. package/dist/agent/tool-history-projection.js +455 -0
  170. package/dist/agent/tool-history-projection.js.map +1 -0
  171. package/dist/agent/tool-history.d.ts +8 -67
  172. package/dist/agent/tool-history.js +156 -219
  173. package/dist/agent/tool-history.js.map +1 -1
  174. package/dist/agent/tool-output-formatting.d.ts +0 -18
  175. package/dist/agent/tool-output-formatting.js +0 -28
  176. package/dist/agent/tool-output-formatting.js.map +1 -1
  177. package/dist/agent/turn/automatic-compaction-execution.d.ts +14 -0
  178. package/dist/agent/turn/automatic-compaction-execution.js +19 -0
  179. package/dist/agent/turn/automatic-compaction-execution.js.map +1 -0
  180. package/dist/agent/turn/compaction-admission.d.ts +25 -0
  181. package/dist/agent/turn/compaction-admission.js +40 -0
  182. package/dist/agent/turn/compaction-admission.js.map +1 -0
  183. package/dist/agent/turn/compaction-candidate.d.ts +10 -0
  184. package/dist/agent/turn/compaction-candidate.js +12 -0
  185. package/dist/agent/turn/compaction-candidate.js.map +1 -0
  186. package/dist/agent/turn/compaction-coordinator.d.ts +42 -0
  187. package/dist/agent/turn/compaction-coordinator.js +169 -0
  188. package/dist/agent/turn/compaction-coordinator.js.map +1 -0
  189. package/dist/agent/turn/compaction-durable-envelope.d.ts +24 -0
  190. package/dist/agent/turn/compaction-durable-envelope.js +54 -0
  191. package/dist/agent/turn/compaction-durable-envelope.js.map +1 -0
  192. package/dist/agent/turn/compaction-final-fit.d.ts +10 -0
  193. package/dist/agent/turn/compaction-final-fit.js +14 -0
  194. package/dist/agent/turn/compaction-final-fit.js.map +1 -0
  195. package/dist/agent/turn/compaction-messages.d.ts +6 -0
  196. package/dist/agent/turn/compaction-messages.js +15 -0
  197. package/dist/agent/turn/compaction-messages.js.map +1 -0
  198. package/dist/agent/turn/compaction-replay-selection.d.ts +10 -0
  199. package/dist/agent/turn/compaction-replay-selection.js +27 -0
  200. package/dist/agent/turn/compaction-replay-selection.js.map +1 -0
  201. package/dist/agent/turn/compaction-request-estimator.d.ts +7 -0
  202. package/dist/agent/turn/compaction-request-estimator.js +13 -0
  203. package/dist/agent/turn/compaction-request-estimator.js.map +1 -0
  204. package/dist/agent/turn/compaction-summarizer.d.ts +21 -0
  205. package/dist/agent/turn/compaction-summarizer.js +41 -0
  206. package/dist/agent/turn/compaction-summarizer.js.map +1 -0
  207. package/dist/agent/turn/continuation-overlap.d.ts +1 -0
  208. package/dist/agent/turn/continuation-overlap.js +35 -0
  209. package/dist/agent/turn/continuation-overlap.js.map +1 -0
  210. package/dist/agent/turn/contracts.d.ts +25 -0
  211. package/dist/agent/turn/contracts.js +2 -0
  212. package/dist/agent/turn/contracts.js.map +1 -0
  213. package/dist/agent/turn/event-emitter.d.ts +21 -0
  214. package/dist/agent/turn/event-emitter.js +116 -0
  215. package/dist/agent/turn/event-emitter.js.map +1 -0
  216. package/dist/agent/turn/evidence-flags.d.ts +16 -0
  217. package/dist/agent/turn/evidence-flags.js +44 -0
  218. package/dist/agent/turn/evidence-flags.js.map +1 -0
  219. package/dist/agent/turn/finalizer.d.ts +28 -0
  220. package/dist/agent/turn/finalizer.js +44 -0
  221. package/dist/agent/turn/finalizer.js.map +1 -0
  222. package/dist/agent/turn/history-writer.d.ts +17 -0
  223. package/dist/agent/turn/history-writer.js +72 -0
  224. package/dist/agent/turn/history-writer.js.map +1 -0
  225. package/dist/agent/turn/inserted-text.d.ts +1 -0
  226. package/dist/agent/turn/inserted-text.js +2 -0
  227. package/dist/agent/turn/inserted-text.js.map +1 -0
  228. package/dist/agent/turn/loop/answer-assessment.d.ts +22 -0
  229. package/dist/agent/turn/loop/answer-assessment.js +30 -0
  230. package/dist/agent/turn/loop/answer-assessment.js.map +1 -0
  231. package/dist/agent/turn/loop/answer-path.d.ts +20 -0
  232. package/dist/agent/turn/loop/answer-path.js +92 -0
  233. package/dist/agent/turn/loop/answer-path.js.map +1 -0
  234. package/dist/agent/turn/loop/call-binding.d.ts +17 -0
  235. package/dist/agent/turn/loop/call-binding.js +42 -0
  236. package/dist/agent/turn/loop/call-binding.js.map +1 -0
  237. package/dist/agent/turn/loop/canonicalize-turn-call.d.ts +5 -0
  238. package/dist/agent/turn/loop/canonicalize-turn-call.js +12 -0
  239. package/dist/agent/turn/loop/canonicalize-turn-call.js.map +1 -0
  240. package/dist/agent/turn/loop/completion-interpretation.d.ts +34 -0
  241. package/dist/agent/turn/loop/completion-interpretation.js +71 -0
  242. package/dist/agent/turn/loop/completion-interpretation.js.map +1 -0
  243. package/dist/agent/turn/loop/deps.d.ts +98 -0
  244. package/dist/agent/turn/loop/deps.js +2 -0
  245. package/dist/agent/turn/loop/deps.js.map +1 -0
  246. package/dist/agent/turn/loop/empty-response.d.ts +22 -0
  247. package/dist/agent/turn/loop/empty-response.js +51 -0
  248. package/dist/agent/turn/loop/empty-response.js.map +1 -0
  249. package/dist/agent/turn/loop/final-outcome.d.ts +15 -0
  250. package/dist/agent/turn/loop/final-outcome.js +49 -0
  251. package/dist/agent/turn/loop/final-outcome.js.map +1 -0
  252. package/dist/agent/turn/loop/group-execution.d.ts +14 -0
  253. package/dist/agent/turn/loop/group-execution.js +44 -0
  254. package/dist/agent/turn/loop/group-execution.js.map +1 -0
  255. package/dist/agent/turn/loop/model-only-rounds.d.ts +31 -0
  256. package/dist/agent/turn/loop/model-only-rounds.js +49 -0
  257. package/dist/agent/turn/loop/model-only-rounds.js.map +1 -0
  258. package/dist/agent/turn/loop/native-tool-calls.d.ts +12 -0
  259. package/dist/agent/turn/loop/native-tool-calls.js +57 -0
  260. package/dist/agent/turn/loop/native-tool-calls.js.map +1 -0
  261. package/dist/agent/turn/loop/native-write-salvage.d.ts +18 -0
  262. package/dist/agent/turn/loop/native-write-salvage.js +92 -0
  263. package/dist/agent/turn/loop/native-write-salvage.js.map +1 -0
  264. package/dist/agent/turn/loop/output-budget.d.ts +40 -0
  265. package/dist/agent/turn/loop/output-budget.js +76 -0
  266. package/dist/agent/turn/loop/output-budget.js.map +1 -0
  267. package/dist/agent/turn/loop/plan-call-deferral.d.ts +12 -0
  268. package/dist/agent/turn/loop/plan-call-deferral.js +32 -0
  269. package/dist/agent/turn/loop/plan-call-deferral.js.map +1 -0
  270. package/dist/agent/turn/loop/request-assembly.d.ts +32 -0
  271. package/dist/agent/turn/loop/request-assembly.js +97 -0
  272. package/dist/agent/turn/loop/request-assembly.js.map +1 -0
  273. package/dist/agent/turn/loop/round-closeout.d.ts +56 -0
  274. package/dist/agent/turn/loop/round-closeout.js +77 -0
  275. package/dist/agent/turn/loop/round-closeout.js.map +1 -0
  276. package/dist/agent/turn/loop/round-recorder.d.ts +38 -0
  277. package/dist/agent/turn/loop/round-recorder.js +71 -0
  278. package/dist/agent/turn/loop/round-recorder.js.map +1 -0
  279. package/dist/agent/turn/loop/round-request.d.ts +19 -0
  280. package/dist/agent/turn/loop/round-request.js +169 -0
  281. package/dist/agent/turn/loop/round-request.js.map +1 -0
  282. package/dist/agent/turn/loop/round-state.d.ts +11 -0
  283. package/dist/agent/turn/loop/round-state.js +11 -0
  284. package/dist/agent/turn/loop/round-state.js.map +1 -0
  285. package/dist/agent/turn/loop/run-rounds.d.ts +5 -0
  286. package/dist/agent/turn/loop/run-rounds.js +664 -0
  287. package/dist/agent/turn/loop/run-rounds.js.map +1 -0
  288. package/dist/agent/turn/loop/sequence-suppression.d.ts +54 -0
  289. package/dist/agent/turn/loop/sequence-suppression.js +112 -0
  290. package/dist/agent/turn/loop/sequence-suppression.js.map +1 -0
  291. package/dist/agent/turn/loop/state.d.ts +38 -0
  292. package/dist/agent/turn/loop/state.js +29 -0
  293. package/dist/agent/turn/loop/state.js.map +1 -0
  294. package/dist/agent/turn/loop/stream-failure.d.ts +55 -0
  295. package/dist/agent/turn/loop/stream-failure.js +149 -0
  296. package/dist/agent/turn/loop/stream-failure.js.map +1 -0
  297. package/dist/agent/turn/loop/stream-request.d.ts +16 -0
  298. package/dist/agent/turn/loop/stream-request.js +21 -0
  299. package/dist/agent/turn/loop/stream-request.js.map +1 -0
  300. package/dist/agent/turn/loop/stream-session.d.ts +41 -0
  301. package/dist/agent/turn/loop/stream-session.js +136 -0
  302. package/dist/agent/turn/loop/stream-session.js.map +1 -0
  303. package/dist/agent/turn/loop/tool-call-recovery.d.ts +25 -0
  304. package/dist/agent/turn/loop/tool-call-recovery.js +162 -0
  305. package/dist/agent/turn/loop/tool-call-recovery.js.map +1 -0
  306. package/dist/agent/turn/loop/unrun-calls.d.ts +12 -0
  307. package/dist/agent/turn/loop/unrun-calls.js +27 -0
  308. package/dist/agent/turn/loop/unrun-calls.js.map +1 -0
  309. package/dist/agent/turn/loop/wire-occurrences.d.ts +31 -0
  310. package/dist/agent/turn/loop/wire-occurrences.js +45 -0
  311. package/dist/agent/turn/loop/wire-occurrences.js.map +1 -0
  312. package/dist/agent/turn/mcp-agent-tools.d.ts +17 -0
  313. package/dist/agent/turn/mcp-agent-tools.js +69 -0
  314. package/dist/agent/turn/mcp-agent-tools.js.map +1 -0
  315. package/dist/agent/turn/message-assembly.d.ts +14 -0
  316. package/dist/agent/turn/message-assembly.js +22 -0
  317. package/dist/agent/turn/message-assembly.js.map +1 -0
  318. package/dist/agent/turn/outcome-accounting.d.ts +27 -0
  319. package/dist/agent/turn/outcome-accounting.js +91 -0
  320. package/dist/agent/turn/outcome-accounting.js.map +1 -0
  321. package/dist/agent/turn/plan-mode-gate.d.ts +16 -0
  322. package/dist/agent/turn/plan-mode-gate.js +36 -0
  323. package/dist/agent/turn/plan-mode-gate.js.map +1 -0
  324. package/dist/agent/turn/plan-persistence.d.ts +28 -0
  325. package/dist/agent/turn/plan-persistence.js +56 -0
  326. package/dist/agent/turn/plan-persistence.js.map +1 -0
  327. package/dist/agent/turn/prompt-sections.d.ts +9 -0
  328. package/dist/agent/turn/prompt-sections.js +67 -0
  329. package/dist/agent/turn/prompt-sections.js.map +1 -0
  330. package/dist/agent/turn/responder-claims.d.ts +16 -0
  331. package/dist/agent/turn/responder-claims.js +37 -0
  332. package/dist/agent/turn/responder-claims.js.map +1 -0
  333. package/dist/agent/turn/responder-dependency.d.ts +3 -0
  334. package/dist/agent/turn/responder-dependency.js +36 -0
  335. package/dist/agent/turn/responder-dependency.js.map +1 -0
  336. package/dist/agent/turn/responder-inbox.d.ts +28 -0
  337. package/dist/agent/turn/responder-inbox.js +57 -0
  338. package/dist/agent/turn/responder-inbox.js.map +1 -0
  339. package/dist/agent/turn/responder-job-linkage.d.ts +30 -0
  340. package/dist/agent/turn/responder-job-linkage.js +124 -0
  341. package/dist/agent/turn/responder-job-linkage.js.map +1 -0
  342. package/dist/agent/turn/responder-read-tool.d.ts +26 -0
  343. package/dist/agent/turn/responder-read-tool.js +83 -0
  344. package/dist/agent/turn/responder-read-tool.js.map +1 -0
  345. package/dist/agent/turn/scaffold-outcome.d.ts +7 -0
  346. package/dist/agent/turn/scaffold-outcome.js +93 -0
  347. package/dist/agent/turn/scaffold-outcome.js.map +1 -0
  348. package/dist/agent/turn/scaffold-preflight.d.ts +8 -0
  349. package/dist/agent/turn/scaffold-preflight.js +31 -0
  350. package/dist/agent/turn/scaffold-preflight.js.map +1 -0
  351. package/dist/agent/turn/session-state-projection.d.ts +18 -0
  352. package/dist/agent/turn/session-state-projection.js +46 -0
  353. package/dist/agent/turn/session-state-projection.js.map +1 -0
  354. package/dist/agent/turn/setup/compaction-services.d.ts +55 -0
  355. package/dist/agent/turn/setup/compaction-services.js +69 -0
  356. package/dist/agent/turn/setup/compaction-services.js.map +1 -0
  357. package/dist/agent/turn/setup/evidence-rehydration.d.ts +3 -0
  358. package/dist/agent/turn/setup/evidence-rehydration.js +22 -0
  359. package/dist/agent/turn/setup/evidence-rehydration.js.map +1 -0
  360. package/dist/agent/turn/setup/mcp-agent-ports.d.ts +29 -0
  361. package/dist/agent/turn/setup/mcp-agent-ports.js +26 -0
  362. package/dist/agent/turn/setup/mcp-agent-ports.js.map +1 -0
  363. package/dist/agent/turn/setup/prompt-classification.d.ts +10 -0
  364. package/dist/agent/turn/setup/prompt-classification.js +18 -0
  365. package/dist/agent/turn/setup/prompt-classification.js.map +1 -0
  366. package/dist/agent/turn/setup/responder-wake.d.ts +16 -0
  367. package/dist/agent/turn/setup/responder-wake.js +18 -0
  368. package/dist/agent/turn/setup/responder-wake.js.map +1 -0
  369. package/dist/agent/turn/setup/session-state.d.ts +20 -0
  370. package/dist/agent/turn/setup/session-state.js +23 -0
  371. package/dist/agent/turn/setup/session-state.js.map +1 -0
  372. package/dist/agent/turn/setup/task-gate-setup.d.ts +19 -0
  373. package/dist/agent/turn/setup/task-gate-setup.js +21 -0
  374. package/dist/agent/turn/setup/task-gate-setup.js.map +1 -0
  375. package/dist/agent/turn/setup/turn-budget.d.ts +19 -0
  376. package/dist/agent/turn/setup/turn-budget.js +34 -0
  377. package/dist/agent/turn/setup/turn-budget.js.map +1 -0
  378. package/dist/agent/turn/setup/turn-messages.d.ts +25 -0
  379. package/dist/agent/turn/setup/turn-messages.js +38 -0
  380. package/dist/agent/turn/setup/turn-messages.js.map +1 -0
  381. package/dist/agent/turn/setup/turn-state-machine.d.ts +13 -0
  382. package/dist/agent/turn/setup/turn-state-machine.js +52 -0
  383. package/dist/agent/turn/setup/turn-state-machine.js.map +1 -0
  384. package/dist/agent/turn/system-sections.d.ts +36 -0
  385. package/dist/agent/turn/system-sections.js +157 -0
  386. package/dist/agent/turn/system-sections.js.map +1 -0
  387. package/dist/agent/turn/task-autostart.d.ts +12 -0
  388. package/dist/agent/turn/task-autostart.js +35 -0
  389. package/dist/agent/turn/task-autostart.js.map +1 -0
  390. package/dist/agent/turn/task-batch-guard.d.ts +18 -0
  391. package/dist/agent/turn/task-batch-guard.js +83 -0
  392. package/dist/agent/turn/task-batch-guard.js.map +1 -0
  393. package/dist/agent/turn/task-credit.d.ts +15 -0
  394. package/dist/agent/turn/task-credit.js +49 -0
  395. package/dist/agent/turn/task-credit.js.map +1 -0
  396. package/dist/agent/turn/task-gate.d.ts +13 -0
  397. package/dist/agent/turn/task-gate.js +34 -0
  398. package/dist/agent/turn/task-gate.js.map +1 -0
  399. package/dist/agent/turn/task-update-gate.d.ts +13 -0
  400. package/dist/agent/turn/task-update-gate.js +40 -0
  401. package/dist/agent/turn/task-update-gate.js.map +1 -0
  402. package/dist/agent/turn/task-work-signals.d.ts +3 -0
  403. package/dist/agent/turn/task-work-signals.js +44 -0
  404. package/dist/agent/turn/task-work-signals.js.map +1 -0
  405. package/dist/agent/turn/tool-call-preparation.d.ts +20 -0
  406. package/dist/agent/turn/tool-call-preparation.js +67 -0
  407. package/dist/agent/turn/tool-call-preparation.js.map +1 -0
  408. package/dist/agent/turn/tool-evidence-signals.d.ts +22 -0
  409. package/dist/agent/turn/tool-evidence-signals.js +101 -0
  410. package/dist/agent/turn/tool-evidence-signals.js.map +1 -0
  411. package/dist/agent/turn/tool-execution/authorization.d.ts +32 -0
  412. package/dist/agent/turn/tool-execution/authorization.js +100 -0
  413. package/dist/agent/turn/tool-execution/authorization.js.map +1 -0
  414. package/dist/agent/turn/tool-execution/deps.d.ts +74 -0
  415. package/dist/agent/turn/tool-execution/deps.js +2 -0
  416. package/dist/agent/turn/tool-execution/deps.js.map +1 -0
  417. package/dist/agent/turn/tool-execution/dispatch.d.ts +27 -0
  418. package/dist/agent/turn/tool-execution/dispatch.js +76 -0
  419. package/dist/agent/turn/tool-execution/dispatch.js.map +1 -0
  420. package/dist/agent/turn/tool-execution/engagement-checkpoint.d.ts +7 -0
  421. package/dist/agent/turn/tool-execution/engagement-checkpoint.js +32 -0
  422. package/dist/agent/turn/tool-execution/engagement-checkpoint.js.map +1 -0
  423. package/dist/agent/turn/tool-execution/engagement-gate.d.ts +16 -0
  424. package/dist/agent/turn/tool-execution/engagement-gate.js +55 -0
  425. package/dist/agent/turn/tool-execution/engagement-gate.js.map +1 -0
  426. package/dist/agent/turn/tool-execution/gates.d.ts +21 -0
  427. package/dist/agent/turn/tool-execution/gates.js +45 -0
  428. package/dist/agent/turn/tool-execution/gates.js.map +1 -0
  429. package/dist/agent/turn/tool-execution/guards.d.ts +42 -0
  430. package/dist/agent/turn/tool-execution/guards.js +62 -0
  431. package/dist/agent/turn/tool-execution/guards.js.map +1 -0
  432. package/dist/agent/turn/tool-execution/meta-tools.d.ts +50 -0
  433. package/dist/agent/turn/tool-execution/meta-tools.js +114 -0
  434. package/dist/agent/turn/tool-execution/meta-tools.js.map +1 -0
  435. package/dist/agent/turn/tool-execution/plan-tool-ledger.d.ts +10 -0
  436. package/dist/agent/turn/tool-execution/plan-tool-ledger.js +50 -0
  437. package/dist/agent/turn/tool-execution/plan-tool-ledger.js.map +1 -0
  438. package/dist/agent/turn/tool-execution/result-framing.d.ts +36 -0
  439. package/dist/agent/turn/tool-execution/result-framing.js +54 -0
  440. package/dist/agent/turn/tool-execution/result-framing.js.map +1 -0
  441. package/dist/agent/turn/tool-execution/run-setup.d.ts +29 -0
  442. package/dist/agent/turn/tool-execution/run-setup.js +64 -0
  443. package/dist/agent/turn/tool-execution/run-setup.js.map +1 -0
  444. package/dist/agent/turn/tool-execution/single-tool.d.ts +4 -0
  445. package/dist/agent/turn/tool-execution/single-tool.js +613 -0
  446. package/dist/agent/turn/tool-execution/single-tool.js.map +1 -0
  447. package/dist/agent/turn/tool-execution/state.d.ts +19 -0
  448. package/dist/agent/turn/tool-execution/state.js +13 -0
  449. package/dist/agent/turn/tool-execution/state.js.map +1 -0
  450. package/dist/agent/turn/tool-execution/supervision.d.ts +20 -0
  451. package/dist/agent/turn/tool-execution/supervision.js +44 -0
  452. package/dist/agent/turn/tool-execution/supervision.js.map +1 -0
  453. package/dist/agent/turn/tool-result-recorder.d.ts +26 -0
  454. package/dist/agent/turn/tool-result-recorder.js +54 -0
  455. package/dist/agent/turn/tool-result-recorder.js.map +1 -0
  456. package/dist/agent/turn/tool-routing.d.ts +23 -0
  457. package/dist/agent/turn/tool-routing.js +58 -0
  458. package/dist/agent/turn/tool-routing.js.map +1 -0
  459. package/dist/agent/turn/tool-watchdog.d.ts +22 -0
  460. package/dist/agent/turn/tool-watchdog.js +135 -0
  461. package/dist/agent/turn/tool-watchdog.js.map +1 -0
  462. package/dist/agent/turn/turn-counters.d.ts +9 -0
  463. package/dist/agent/turn/turn-counters.js +13 -0
  464. package/dist/agent/turn/turn-counters.js.map +1 -0
  465. package/dist/agent/turn/workspace-setup.d.ts +29 -0
  466. package/dist/agent/turn/workspace-setup.js +74 -0
  467. package/dist/agent/turn/workspace-setup.js.map +1 -0
  468. package/dist/agent/workspace-orient.d.ts +0 -45
  469. package/dist/agent/workspace-orient.js +3 -69
  470. package/dist/agent/workspace-orient.js.map +1 -1
  471. package/dist/app/adapters/agent-event-adapter.d.ts +0 -1
  472. package/dist/app/adapters/agent-event-adapter.js +1 -4
  473. package/dist/app/adapters/agent-event-adapter.js.map +1 -1
  474. package/dist/app/adapters/current-interactive-sessions-adapter.d.ts +0 -1
  475. package/dist/app/adapters/current-interactive-sessions-adapter.js +0 -1
  476. package/dist/app/adapters/current-interactive-sessions-adapter.js.map +1 -1
  477. package/dist/app/adapters/current-jobs-adapter.d.ts +0 -1
  478. package/dist/app/adapters/current-jobs-adapter.js +0 -1
  479. package/dist/app/adapters/current-jobs-adapter.js.map +1 -1
  480. package/dist/app/adapters/current-store-adapter.d.ts +0 -1
  481. package/dist/app/adapters/current-store-adapter.js +0 -1
  482. package/dist/app/adapters/current-store-adapter.js.map +1 -1
  483. package/dist/app/adapters/quiet-meta-tools.d.ts +0 -11
  484. package/dist/app/adapters/quiet-meta-tools.js +0 -11
  485. package/dist/app/adapters/quiet-meta-tools.js.map +1 -1
  486. package/dist/app/commands/catalog.d.ts +0 -8
  487. package/dist/app/commands/catalog.js +10 -32
  488. package/dist/app/commands/catalog.js.map +1 -1
  489. package/dist/app/commands/command.d.ts +0 -4
  490. package/dist/app/commands/command.js.map +1 -1
  491. package/dist/app/commands/registry.d.ts +0 -3
  492. package/dist/app/commands/registry.js +1 -7
  493. package/dist/app/commands/registry.js.map +1 -1
  494. package/dist/app/confirm-prompt-text.d.ts +0 -6
  495. package/dist/app/confirm-prompt-text.js +0 -6
  496. package/dist/app/confirm-prompt-text.js.map +1 -1
  497. package/dist/app/controllers/cancel-all-result.d.ts +0 -5
  498. package/dist/app/controllers/cancel-all-result.js +0 -5
  499. package/dist/app/controllers/cancel-all-result.js.map +1 -1
  500. package/dist/app/controllers/plan-controller.d.ts +0 -6
  501. package/dist/app/controllers/plan-controller.js +0 -11
  502. package/dist/app/controllers/plan-controller.js.map +1 -1
  503. package/dist/app/controllers/session-compact-helper.d.ts +0 -9
  504. package/dist/app/controllers/session-compact-helper.js +14 -21
  505. package/dist/app/controllers/session-compact-helper.js.map +1 -1
  506. package/dist/app/controllers/session-context-usage.d.ts +0 -11
  507. package/dist/app/controllers/session-context-usage.js +22 -30
  508. package/dist/app/controllers/session-context-usage.js.map +1 -1
  509. package/dist/app/controllers/session-controller.d.ts +1 -38
  510. package/dist/app/controllers/session-controller.js +11 -49
  511. package/dist/app/controllers/session-controller.js.map +1 -1
  512. package/dist/app/controllers/session-naming.d.ts +0 -4
  513. package/dist/app/controllers/session-naming.js +0 -4
  514. package/dist/app/controllers/session-naming.js.map +1 -1
  515. package/dist/app/controllers/session-persistence.d.ts +0 -6
  516. package/dist/app/controllers/session-persistence.js +0 -10
  517. package/dist/app/controllers/session-persistence.js.map +1 -1
  518. package/dist/app/controllers/session-responder.js +0 -4
  519. package/dist/app/controllers/session-responder.js.map +1 -1
  520. package/dist/app/controllers/session-turn-request.d.ts +0 -1
  521. package/dist/app/controllers/session-turn-request.js +0 -1
  522. package/dist/app/controllers/session-turn-request.js.map +1 -1
  523. package/dist/app/controllers/session-usage-ledger.d.ts +6 -1
  524. package/dist/app/controllers/session-usage-ledger.js +43 -3
  525. package/dist/app/controllers/session-usage-ledger.js.map +1 -1
  526. package/dist/app/controllers/turn-controller.js +2 -6
  527. package/dist/app/controllers/turn-controller.js.map +1 -1
  528. package/dist/app/events/app-event.d.ts +1 -11
  529. package/dist/app/events/app-event.js +0 -1
  530. package/dist/app/events/app-event.js.map +1 -1
  531. package/dist/app/events/event-buffer.d.ts +0 -6
  532. package/dist/app/events/event-buffer.js +0 -6
  533. package/dist/app/events/event-buffer.js.map +1 -1
  534. package/dist/app/events/sequencer.d.ts +0 -2
  535. package/dist/app/events/sequencer.js +0 -1
  536. package/dist/app/events/sequencer.js.map +1 -1
  537. package/dist/app/ports/agent-port.d.ts +0 -19
  538. package/dist/app/ports/interactive-sessions-port.d.ts +0 -13
  539. package/dist/app/ports/interactive-sessions-port.js +0 -7
  540. package/dist/app/ports/interactive-sessions-port.js.map +1 -1
  541. package/dist/app/ports/persistence-port.d.ts +0 -14
  542. package/dist/app/ports/updates-port.d.ts +0 -5
  543. package/dist/classic/app/ClassicApp.js +0 -2
  544. package/dist/classic/app/ClassicApp.js.map +1 -1
  545. package/dist/classic/app/action-handlers.js +0 -4
  546. package/dist/classic/app/action-handlers.js.map +1 -1
  547. package/dist/classic/app/git-branch.js +0 -1
  548. package/dist/classic/app/git-branch.js.map +1 -1
  549. package/dist/classic/app/use-feed.d.ts +0 -7
  550. package/dist/classic/app/use-feed.js +0 -5
  551. package/dist/classic/app/use-feed.js.map +1 -1
  552. package/dist/classic/app/wiring-interactions.js +0 -2
  553. package/dist/classic/app/wiring-interactions.js.map +1 -1
  554. package/dist/classic/blocks/assistant-lines.d.ts +0 -1
  555. package/dist/classic/blocks/assistant-lines.js +0 -1
  556. package/dist/classic/blocks/assistant-lines.js.map +1 -1
  557. package/dist/classic/blocks/batch-lines.d.ts +0 -1
  558. package/dist/classic/blocks/batch-lines.js +0 -1
  559. package/dist/classic/blocks/batch-lines.js.map +1 -1
  560. package/dist/classic/blocks/block-context.d.ts +0 -7
  561. package/dist/classic/blocks/block-context.js +0 -1
  562. package/dist/classic/blocks/block-context.js.map +1 -1
  563. package/dist/classic/blocks/compacted-lines.d.ts +0 -1
  564. package/dist/classic/blocks/compacted-lines.js +0 -1
  565. package/dist/classic/blocks/compacted-lines.js.map +1 -1
  566. package/dist/classic/blocks/diff-lines.d.ts +0 -3
  567. package/dist/classic/blocks/diff-lines.js +0 -4
  568. package/dist/classic/blocks/diff-lines.js.map +1 -1
  569. package/dist/classic/blocks/intro-lines.d.ts +0 -5
  570. package/dist/classic/blocks/intro-lines.js +0 -5
  571. package/dist/classic/blocks/intro-lines.js.map +1 -1
  572. package/dist/classic/blocks/notice-lines.d.ts +0 -4
  573. package/dist/classic/blocks/notice-lines.js +0 -6
  574. package/dist/classic/blocks/notice-lines.js.map +1 -1
  575. package/dist/classic/blocks/thinking-lines.d.ts +0 -1
  576. package/dist/classic/blocks/thinking-lines.js +0 -1
  577. package/dist/classic/blocks/thinking-lines.js.map +1 -1
  578. package/dist/classic/blocks/tool-lines.d.ts +0 -7
  579. package/dist/classic/blocks/tool-lines.js +0 -10
  580. package/dist/classic/blocks/tool-lines.js.map +1 -1
  581. package/dist/classic/blocks/user-lines.d.ts +0 -1
  582. package/dist/classic/blocks/user-lines.js +0 -1
  583. package/dist/classic/blocks/user-lines.js.map +1 -1
  584. package/dist/classic/bootstrap/osc52-renderer.js +0 -1
  585. package/dist/classic/bootstrap/osc52-renderer.js.map +1 -1
  586. package/dist/classic/chrome/Chrome.d.ts +0 -1
  587. package/dist/classic/chrome/Chrome.js.map +1 -1
  588. package/dist/classic/chrome/Composer.d.ts +0 -5
  589. package/dist/classic/chrome/Composer.js +0 -5
  590. package/dist/classic/chrome/Composer.js.map +1 -1
  591. package/dist/classic/chrome/composer-controller.js +0 -4
  592. package/dist/classic/chrome/composer-controller.js.map +1 -1
  593. package/dist/classic/chrome/composer-frame.d.ts +0 -3
  594. package/dist/classic/chrome/composer-frame.js +0 -3
  595. package/dist/classic/chrome/composer-frame.js.map +1 -1
  596. package/dist/classic/chrome/directory-row.d.ts +0 -7
  597. package/dist/classic/chrome/directory-row.js +0 -7
  598. package/dist/classic/chrome/directory-row.js.map +1 -1
  599. package/dist/classic/chrome/row-budget.d.ts +0 -2
  600. package/dist/classic/chrome/row-budget.js +0 -8
  601. package/dist/classic/chrome/row-budget.js.map +1 -1
  602. package/dist/classic/chrome/status-rows.d.ts +0 -12
  603. package/dist/classic/chrome/status-rows.js +0 -16
  604. package/dist/classic/chrome/status-rows.js.map +1 -1
  605. package/dist/classic/chrome/toast-rows.d.ts +0 -4
  606. package/dist/classic/chrome/toast-rows.js +0 -9
  607. package/dist/classic/chrome/toast-rows.js.map +1 -1
  608. package/dist/classic/feed/Feed.d.ts +0 -5
  609. package/dist/classic/feed/Feed.js +0 -4
  610. package/dist/classic/feed/Feed.js.map +1 -1
  611. package/dist/classic/feed/FeedStatic.d.ts +0 -8
  612. package/dist/classic/feed/FeedStatic.js +0 -8
  613. package/dist/classic/feed/FeedStatic.js.map +1 -1
  614. package/dist/classic/feed/ScrollbarGutter.js +0 -1
  615. package/dist/classic/feed/ScrollbarGutter.js.map +1 -1
  616. package/dist/classic/feed/block-height.d.ts +0 -7
  617. package/dist/classic/feed/block-height.js +0 -7
  618. package/dist/classic/feed/block-height.js.map +1 -1
  619. package/dist/classic/feed/commit-ledger.d.ts +0 -12
  620. package/dist/classic/feed/commit-ledger.js +0 -10
  621. package/dist/classic/feed/commit-ledger.js.map +1 -1
  622. package/dist/classic/feed/feed-blocks.d.ts +0 -8
  623. package/dist/classic/feed/feed-blocks.js +0 -6
  624. package/dist/classic/feed/feed-blocks.js.map +1 -1
  625. package/dist/classic/feed/live-tail-policy.d.ts +0 -13
  626. package/dist/classic/feed/live-tail-policy.js +0 -11
  627. package/dist/classic/feed/live-tail-policy.js.map +1 -1
  628. package/dist/classic/feed/scrollbar-rows.d.ts +0 -1
  629. package/dist/classic/feed/scrollbar-rows.js +0 -1
  630. package/dist/classic/feed/scrollbar-rows.js.map +1 -1
  631. package/dist/classic/feed/transcript-window.d.ts +0 -10
  632. package/dist/classic/feed/transcript-window.js +0 -6
  633. package/dist/classic/feed/transcript-window.js.map +1 -1
  634. package/dist/classic/input/input-router.js +0 -2
  635. package/dist/classic/input/input-router.js.map +1 -1
  636. package/dist/classic/panels/completion-rows.js +2 -1
  637. package/dist/classic/panels/completion-rows.js.map +1 -1
  638. package/dist/classic/panels/keys-panel.d.ts +0 -1
  639. package/dist/classic/panels/keys-panel.js +0 -1
  640. package/dist/classic/panels/keys-panel.js.map +1 -1
  641. package/dist/classic/panels/pager-panel.d.ts +0 -5
  642. package/dist/classic/panels/pager-panel.js +0 -11
  643. package/dist/classic/panels/pager-panel.js.map +1 -1
  644. package/dist/classic/panels/panel-controller.d.ts +0 -2
  645. package/dist/classic/panels/panel-controller.js +0 -2
  646. package/dist/classic/panels/panel-controller.js.map +1 -1
  647. package/dist/classic/panels/panel-frame.js +0 -2
  648. package/dist/classic/panels/panel-frame.js.map +1 -1
  649. package/dist/classic/panels/panel-wheel.d.ts +0 -5
  650. package/dist/classic/panels/panel-wheel.js +0 -5
  651. package/dist/classic/panels/panel-wheel.js.map +1 -1
  652. package/dist/classic/panels/secret-panel.d.ts +0 -1
  653. package/dist/classic/panels/secret-panel.js +0 -1
  654. package/dist/classic/panels/secret-panel.js.map +1 -1
  655. package/dist/classic/panels/text-editor-panel.d.ts +0 -1
  656. package/dist/classic/panels/text-editor-panel.js +0 -1
  657. package/dist/classic/panels/text-editor-panel.js.map +1 -1
  658. package/dist/classic/render/ansi-text.d.ts +0 -19
  659. package/dist/classic/render/ansi-text.js +0 -19
  660. package/dist/classic/render/ansi-text.js.map +1 -1
  661. package/dist/classic/render/glyphs.d.ts +0 -4
  662. package/dist/classic/render/glyphs.js +0 -4
  663. package/dist/classic/render/glyphs.js.map +1 -1
  664. package/dist/classic/render/ink-theme.d.ts +0 -10
  665. package/dist/classic/render/ink-theme.js +0 -6
  666. package/dist/classic/render/ink-theme.js.map +1 -1
  667. package/dist/classic/render/measure.d.ts +0 -12
  668. package/dist/classic/render/measure.js +0 -12
  669. package/dist/classic/render/measure.js.map +1 -1
  670. package/dist/classic/render/shell-width.d.ts +0 -8
  671. package/dist/classic/render/shell-width.js +0 -8
  672. package/dist/classic/render/shell-width.js.map +1 -1
  673. package/dist/classic/render/wrap.d.ts +0 -11
  674. package/dist/classic/render/wrap.js +0 -8
  675. package/dist/classic/render/wrap.js.map +1 -1
  676. package/dist/commands/doctor.js +0 -2
  677. package/dist/commands/doctor.js.map +1 -1
  678. package/dist/commands/providers.d.ts +0 -1
  679. package/dist/commands/providers.js +0 -22
  680. package/dist/commands/providers.js.map +1 -1
  681. package/dist/commands/search-providers.d.ts +0 -1
  682. package/dist/commands/search-providers.js +0 -4
  683. package/dist/commands/search-providers.js.map +1 -1
  684. package/dist/commands/update/installers.d.ts +61 -0
  685. package/dist/commands/update/installers.js +505 -0
  686. package/dist/commands/update/installers.js.map +1 -0
  687. package/dist/commands/update-install.d.ts +4 -65
  688. package/dist/commands/update-install.js +6 -506
  689. package/dist/commands/update-install.js.map +1 -1
  690. package/dist/commands/update.d.ts +0 -6
  691. package/dist/commands/update.js +1 -11
  692. package/dist/commands/update.js.map +1 -1
  693. package/dist/index.js +3 -10
  694. package/dist/index.js.map +1 -1
  695. package/dist/interactive-session/artifact-writer.d.ts +0 -1
  696. package/dist/interactive-session/artifact-writer.js +0 -1
  697. package/dist/interactive-session/artifact-writer.js.map +1 -1
  698. package/dist/interactive-session/cleanup.d.ts +0 -10
  699. package/dist/interactive-session/cleanup.js +0 -13
  700. package/dist/interactive-session/cleanup.js.map +1 -1
  701. package/dist/interactive-session/config.d.ts +0 -16
  702. package/dist/interactive-session/config.js +0 -13
  703. package/dist/interactive-session/config.js.map +1 -1
  704. package/dist/interactive-session/manager.d.ts +0 -27
  705. package/dist/interactive-session/manager.js +0 -42
  706. package/dist/interactive-session/manager.js.map +1 -1
  707. package/dist/interactive-session/output-store.d.ts +0 -6
  708. package/dist/interactive-session/output-store.js +0 -5
  709. package/dist/interactive-session/output-store.js.map +1 -1
  710. package/dist/interactive-session/output-view.d.ts +0 -4
  711. package/dist/interactive-session/output-view.js +0 -12
  712. package/dist/interactive-session/output-view.js.map +1 -1
  713. package/dist/interactive-session/recovery-journal.d.ts +0 -7
  714. package/dist/interactive-session/recovery-journal.js +0 -7
  715. package/dist/interactive-session/recovery-journal.js.map +1 -1
  716. package/dist/interactive-session/registry.d.ts +0 -25
  717. package/dist/interactive-session/registry.js +0 -27
  718. package/dist/interactive-session/registry.js.map +1 -1
  719. package/dist/interactive-session/runtime.d.ts +0 -30
  720. package/dist/interactive-session/runtime.js +0 -23
  721. package/dist/interactive-session/runtime.js.map +1 -1
  722. package/dist/interactive-session/session-runtime.d.ts +0 -9
  723. package/dist/interactive-session/session-runtime.js +0 -10
  724. package/dist/interactive-session/session-runtime.js.map +1 -1
  725. package/dist/interactive-session/streaming-redactor.d.ts +0 -14
  726. package/dist/interactive-session/streaming-redactor.js +0 -18
  727. package/dist/interactive-session/streaming-redactor.js.map +1 -1
  728. package/dist/interactive-session/telemetry.d.ts +0 -8
  729. package/dist/interactive-session/telemetry.js +0 -7
  730. package/dist/interactive-session/telemetry.js.map +1 -1
  731. package/dist/interactive-session/transport-factory.d.ts +0 -5
  732. package/dist/interactive-session/transport-factory.js +0 -5
  733. package/dist/interactive-session/transport-factory.js.map +1 -1
  734. package/dist/interactive-session/transport-pipe.d.ts +0 -7
  735. package/dist/interactive-session/transport-pipe.js +0 -14
  736. package/dist/interactive-session/transport-pipe.js.map +1 -1
  737. package/dist/interactive-session/transport.d.ts +0 -26
  738. package/dist/interactive-session/transport.js +0 -20
  739. package/dist/interactive-session/transport.js.map +1 -1
  740. package/dist/interactive-session/types.d.ts +0 -19
  741. package/dist/interactive-session/types.js +0 -22
  742. package/dist/interactive-session/types.js.map +1 -1
  743. package/dist/llm/adapters/anthropic-stream-events.d.ts +38 -0
  744. package/dist/llm/adapters/anthropic-stream-events.js +144 -0
  745. package/dist/llm/adapters/anthropic-stream-events.js.map +1 -0
  746. package/dist/llm/adapters/anthropic-tools.d.ts +5 -55
  747. package/dist/llm/adapters/anthropic-tools.js +6 -208
  748. package/dist/llm/adapters/anthropic-tools.js.map +1 -1
  749. package/dist/llm/adapters/anthropic-wire-blocks.d.ts +9 -0
  750. package/dist/llm/adapters/anthropic-wire-blocks.js +59 -0
  751. package/dist/llm/adapters/anthropic-wire-blocks.js.map +1 -0
  752. package/dist/llm/adapters/gemini-tools.d.ts +0 -6
  753. package/dist/llm/adapters/gemini-tools.js +0 -24
  754. package/dist/llm/adapters/gemini-tools.js.map +1 -1
  755. package/dist/llm/adapters/ollama-tools.js +0 -5
  756. package/dist/llm/adapters/ollama-tools.js.map +1 -1
  757. package/dist/llm/adapters/openai-tools.d.ts +0 -4
  758. package/dist/llm/adapters/openai-tools.js +2 -11
  759. package/dist/llm/adapters/openai-tools.js.map +1 -1
  760. package/dist/llm/agentrouter.d.ts +0 -9
  761. package/dist/llm/agentrouter.js +10 -60
  762. package/dist/llm/agentrouter.js.map +1 -1
  763. package/dist/llm/anthropic.d.ts +0 -7
  764. package/dist/llm/anthropic.js +2 -30
  765. package/dist/llm/anthropic.js.map +1 -1
  766. package/dist/llm/artifacts/legacy-blocks.d.ts +3 -0
  767. package/dist/llm/artifacts/legacy-blocks.js +109 -0
  768. package/dist/llm/artifacts/legacy-blocks.js.map +1 -0
  769. package/dist/llm/artifacts/replay-selection.d.ts +9 -0
  770. package/dist/llm/artifacts/replay-selection.js +48 -0
  771. package/dist/llm/artifacts/replay-selection.js.map +1 -0
  772. package/dist/llm/aws-mantle.js +2 -4
  773. package/dist/llm/aws-mantle.js.map +1 -1
  774. package/dist/llm/bynara.js +2 -0
  775. package/dist/llm/bynara.js.map +1 -1
  776. package/dist/llm/cache-affinity.d.ts +1 -0
  777. package/dist/llm/cache-affinity.js +6 -0
  778. package/dist/llm/cache-affinity.js.map +1 -1
  779. package/dist/llm/capabilities.d.ts +7 -36
  780. package/dist/llm/capabilities.js +11 -502
  781. package/dist/llm/capabilities.js.map +1 -1
  782. package/dist/llm/capability/state.d.ts +25 -0
  783. package/dist/llm/capability/state.js +125 -0
  784. package/dist/llm/capability/state.js.map +1 -0
  785. package/dist/llm/capability/tool-dialect.d.ts +3 -0
  786. package/dist/llm/capability/tool-dialect.js +78 -0
  787. package/dist/llm/capability/tool-dialect.js.map +1 -0
  788. package/dist/llm/capability/vision-patterns.d.ts +4 -0
  789. package/dist/llm/capability/vision-patterns.js +188 -0
  790. package/dist/llm/capability/vision-patterns.js.map +1 -0
  791. package/dist/llm/capability/vision-registry.d.ts +20 -0
  792. package/dist/llm/capability/vision-registry.js +112 -0
  793. package/dist/llm/capability/vision-registry.js.map +1 -0
  794. package/dist/llm/context-snapshot.d.ts +0 -18
  795. package/dist/llm/context-snapshot.js +1 -8
  796. package/dist/llm/context-snapshot.js.map +1 -1
  797. package/dist/llm/context-windows.d.ts +0 -6
  798. package/dist/llm/context-windows.js +0 -30
  799. package/dist/llm/context-windows.js.map +1 -1
  800. package/dist/llm/custom-provider-profile.d.ts +4 -23
  801. package/dist/llm/custom-provider-profile.js +4 -515
  802. package/dist/llm/custom-provider-profile.js.map +1 -1
  803. package/dist/llm/custom-providers.d.ts +0 -23
  804. package/dist/llm/custom-providers.js +2 -27
  805. package/dist/llm/custom-providers.js.map +1 -1
  806. package/dist/llm/effort-fallback.d.ts +0 -38
  807. package/dist/llm/effort-fallback.js +0 -38
  808. package/dist/llm/effort-fallback.js.map +1 -1
  809. package/dist/llm/fireworks.js +2 -0
  810. package/dist/llm/fireworks.js.map +1 -1
  811. package/dist/llm/free.js +7 -2
  812. package/dist/llm/free.js.map +1 -1
  813. package/dist/llm/gemini.d.ts +0 -1
  814. package/dist/llm/gemini.js +2 -19
  815. package/dist/llm/gemini.js.map +1 -1
  816. package/dist/llm/hetzner.js +2 -0
  817. package/dist/llm/hetzner.js.map +1 -1
  818. package/dist/llm/http.d.ts +24 -251
  819. package/dist/llm/http.js +19 -2021
  820. package/dist/llm/http.js.map +1 -1
  821. package/dist/llm/key-rotation.d.ts +0 -32
  822. package/dist/llm/key-rotation.js +6 -37
  823. package/dist/llm/key-rotation.js.map +1 -1
  824. package/dist/llm/lightning.d.ts +0 -8
  825. package/dist/llm/lightning.js +3 -18
  826. package/dist/llm/lightning.js.map +1 -1
  827. package/dist/llm/merge-gateway.d.ts +0 -9
  828. package/dist/llm/merge-gateway.js +2 -44
  829. package/dist/llm/merge-gateway.js.map +1 -1
  830. package/dist/llm/modal.js +3 -15
  831. package/dist/llm/modal.js.map +1 -1
  832. package/dist/llm/model-families.d.ts +0 -5
  833. package/dist/llm/model-families.js +0 -5
  834. package/dist/llm/model-families.js.map +1 -1
  835. package/dist/llm/model-layers/model-patterns.d.ts +7 -0
  836. package/dist/llm/model-layers/model-patterns.js +30 -0
  837. package/dist/llm/model-layers/model-patterns.js.map +1 -0
  838. package/dist/llm/model-layers/model-rules.d.ts +8 -0
  839. package/dist/llm/model-layers/model-rules.js +221 -0
  840. package/dist/llm/model-layers/model-rules.js.map +1 -0
  841. package/dist/llm/model-layers/nvidia-layer.d.ts +2 -0
  842. package/dist/llm/model-layers/nvidia-layer.js +135 -0
  843. package/dist/llm/model-layers/nvidia-layer.js.map +1 -0
  844. package/dist/llm/nvidia.js +3 -11
  845. package/dist/llm/nvidia.js.map +1 -1
  846. package/dist/llm/ollama.js +2 -11
  847. package/dist/llm/ollama.js.map +1 -1
  848. package/dist/llm/openai.js +2 -0
  849. package/dist/llm/openai.js.map +1 -1
  850. package/dist/llm/openrouter.js +3 -1
  851. package/dist/llm/openrouter.js.map +1 -1
  852. package/dist/llm/operation-ledger.d.ts +0 -6
  853. package/dist/llm/operation-ledger.js +0 -6
  854. package/dist/llm/operation-ledger.js.map +1 -1
  855. package/dist/llm/operation-usage.d.ts +2 -0
  856. package/dist/llm/operation-usage.js +27 -0
  857. package/dist/llm/operation-usage.js.map +1 -1
  858. package/dist/llm/orcarouter.d.ts +0 -4
  859. package/dist/llm/orcarouter.js +3 -26
  860. package/dist/llm/orcarouter.js.map +1 -1
  861. package/dist/llm/profile/control-rejections.d.ts +14 -0
  862. package/dist/llm/profile/control-rejections.js +75 -0
  863. package/dist/llm/profile/control-rejections.js.map +1 -0
  864. package/dist/llm/profile/custom-layer.d.ts +3 -0
  865. package/dist/llm/profile/custom-layer.js +83 -0
  866. package/dist/llm/profile/custom-layer.js.map +1 -0
  867. package/dist/llm/profile/layer-merge.d.ts +3 -0
  868. package/dist/llm/profile/layer-merge.js +185 -0
  869. package/dist/llm/profile/layer-merge.js.map +1 -0
  870. package/dist/llm/profile/spec-validation.d.ts +5 -0
  871. package/dist/llm/profile/spec-validation.js +289 -0
  872. package/dist/llm/profile/spec-validation.js.map +1 -0
  873. package/dist/llm/profile/spec-vocabulary.d.ts +21 -0
  874. package/dist/llm/profile/spec-vocabulary.js +142 -0
  875. package/dist/llm/profile/spec-vocabulary.js.map +1 -0
  876. package/dist/llm/provider-identity.d.ts +5 -0
  877. package/dist/llm/provider-identity.js +130 -0
  878. package/dist/llm/provider-identity.js.map +1 -0
  879. package/dist/llm/provider-info-text.d.ts +1 -0
  880. package/dist/llm/provider-info-text.js +587 -0
  881. package/dist/llm/provider-info-text.js.map +1 -0
  882. package/dist/llm/provider-model-layers.d.ts +2 -0
  883. package/dist/llm/provider-model-layers.js +6 -380
  884. package/dist/llm/provider-model-layers.js.map +1 -1
  885. package/dist/llm/provider-profile-layers.js +0 -2
  886. package/dist/llm/provider-profile-layers.js.map +1 -1
  887. package/dist/llm/provider-profile.d.ts +10 -12
  888. package/dist/llm/provider-profile.js +6 -265
  889. package/dist/llm/provider-profile.js.map +1 -1
  890. package/dist/llm/provider.d.ts +4 -16
  891. package/dist/llm/provider.js +6 -760
  892. package/dist/llm/provider.js.map +1 -1
  893. package/dist/llm/qwen-cloud.js +2 -4
  894. package/dist/llm/qwen-cloud.js.map +1 -1
  895. package/dist/llm/reasoning-artifacts.d.ts +5 -50
  896. package/dist/llm/reasoning-artifacts.js +11 -198
  897. package/dist/llm/reasoning-artifacts.js.map +1 -1
  898. package/dist/llm/reasoning-capability.js +0 -16
  899. package/dist/llm/reasoning-capability.js.map +1 -1
  900. package/dist/llm/request-fingerprint.d.ts +0 -4
  901. package/dist/llm/request-fingerprint.js +0 -4
  902. package/dist/llm/request-fingerprint.js.map +1 -1
  903. package/dist/llm/request-plan.d.ts +0 -14
  904. package/dist/llm/request-plan.js +0 -23
  905. package/dist/llm/request-plan.js.map +1 -1
  906. package/dist/llm/responses/item-events.d.ts +3 -0
  907. package/dist/llm/responses/item-events.js +93 -0
  908. package/dist/llm/responses/item-events.js.map +1 -0
  909. package/dist/llm/responses-complete.d.ts +1 -1
  910. package/dist/llm/responses-complete.js +2 -1
  911. package/dist/llm/responses-complete.js.map +1 -1
  912. package/dist/llm/responses-config.js.map +1 -1
  913. package/dist/llm/responses-http.d.ts +1 -0
  914. package/dist/llm/responses-http.js +3 -1
  915. package/dist/llm/responses-http.js.map +1 -1
  916. package/dist/llm/responses-parse.d.ts +3 -0
  917. package/dist/llm/responses-parse.js +19 -6
  918. package/dist/llm/responses-parse.js.map +1 -1
  919. package/dist/llm/responses-request.d.ts +2 -1
  920. package/dist/llm/responses-request.js +7 -2
  921. package/dist/llm/responses-request.js.map +1 -1
  922. package/dist/llm/responses-shape.d.ts +5 -0
  923. package/dist/llm/responses-shape.js +16 -0
  924. package/dist/llm/responses-shape.js.map +1 -0
  925. package/dist/llm/responses-stream-accumulator.d.ts +1 -1
  926. package/dist/llm/responses-stream-accumulator.js +8 -9
  927. package/dist/llm/responses-stream-accumulator.js.map +1 -1
  928. package/dist/llm/responses-stream-events.d.ts +2 -0
  929. package/dist/llm/responses-stream-events.js +34 -102
  930. package/dist/llm/responses-stream-events.js.map +1 -1
  931. package/dist/llm/responses-stream-watchdog.js.map +1 -1
  932. package/dist/llm/responses-stream.js +9 -4
  933. package/dist/llm/responses-stream.js.map +1 -1
  934. package/dist/llm/router.d.ts +7 -44
  935. package/dist/llm/router.js +24 -1145
  936. package/dist/llm/router.js.map +1 -1
  937. package/dist/llm/routing/attempt-complete.d.ts +3 -0
  938. package/dist/llm/routing/attempt-complete.js +120 -0
  939. package/dist/llm/routing/attempt-complete.js.map +1 -0
  940. package/dist/llm/routing/attempt-request.d.ts +21 -0
  941. package/dist/llm/routing/attempt-request.js +99 -0
  942. package/dist/llm/routing/attempt-request.js.map +1 -0
  943. package/dist/llm/routing/attempt-stream.d.ts +3 -0
  944. package/dist/llm/routing/attempt-stream.js +256 -0
  945. package/dist/llm/routing/attempt-stream.js.map +1 -0
  946. package/dist/llm/routing/error-classification.d.ts +15 -0
  947. package/dist/llm/routing/error-classification.js +151 -0
  948. package/dist/llm/routing/error-classification.js.map +1 -0
  949. package/dist/llm/routing/failure-report.d.ts +22 -0
  950. package/dist/llm/routing/failure-report.js +128 -0
  951. package/dist/llm/routing/failure-report.js.map +1 -0
  952. package/dist/llm/routing/key-rotation.d.ts +21 -0
  953. package/dist/llm/routing/key-rotation.js +207 -0
  954. package/dist/llm/routing/key-rotation.js.map +1 -0
  955. package/dist/llm/routing/provider-selection.d.ts +8 -0
  956. package/dist/llm/routing/provider-selection.js +119 -0
  957. package/dist/llm/routing/provider-selection.js.map +1 -0
  958. package/dist/llm/sampling.d.ts +0 -15
  959. package/dist/llm/sampling.js +0 -9
  960. package/dist/llm/sampling.js.map +1 -1
  961. package/dist/llm/session-affinity.d.ts +2 -0
  962. package/dist/llm/session-affinity.js +9 -0
  963. package/dist/llm/session-affinity.js.map +1 -0
  964. package/dist/llm/stream-progress.d.ts +0 -1
  965. package/dist/llm/stream-progress.js +0 -15
  966. package/dist/llm/stream-progress.js.map +1 -1
  967. package/dist/llm/system-messages.d.ts +0 -22
  968. package/dist/llm/system-messages.js +6 -22
  969. package/dist/llm/system-messages.js.map +1 -1
  970. package/dist/llm/token-estimate-calibration.d.ts +0 -6
  971. package/dist/llm/token-estimate-calibration.js +0 -26
  972. package/dist/llm/token-estimate-calibration.js.map +1 -1
  973. package/dist/llm/token-usage.d.ts +8 -69
  974. package/dist/llm/token-usage.js +10 -257
  975. package/dist/llm/token-usage.js.map +1 -1
  976. package/dist/llm/tokenrouter.d.ts +0 -12
  977. package/dist/llm/tokenrouter.js +3 -14
  978. package/dist/llm/tokenrouter.js.map +1 -1
  979. package/dist/llm/tool-protocol.d.ts +3 -22
  980. package/dist/llm/tool-protocol.js +20 -155
  981. package/dist/llm/tool-protocol.js.map +1 -1
  982. package/dist/llm/tool-wire/argument-repair.d.ts +4 -0
  983. package/dist/llm/tool-wire/argument-repair.js +174 -0
  984. package/dist/llm/tool-wire/argument-repair.js.map +1 -0
  985. package/dist/llm/transport-events.d.ts +12 -0
  986. package/dist/llm/transport-events.js +29 -0
  987. package/dist/llm/transport-events.js.map +1 -0
  988. package/dist/llm/usage/provider-parsers.d.ts +11 -0
  989. package/dist/llm/usage/provider-parsers.js +220 -0
  990. package/dist/llm/usage/provider-parsers.js.map +1 -0
  991. package/dist/llm/wire/abort-race.d.ts +1 -0
  992. package/dist/llm/wire/abort-race.js +34 -0
  993. package/dist/llm/wire/abort-race.js.map +1 -0
  994. package/dist/llm/wire/capability-errors.d.ts +11 -0
  995. package/dist/llm/wire/capability-errors.js +92 -0
  996. package/dist/llm/wire/capability-errors.js.map +1 -0
  997. package/dist/llm/wire/chat-body.d.ts +40 -0
  998. package/dist/llm/wire/chat-body.js +172 -0
  999. package/dist/llm/wire/chat-body.js.map +1 -0
  1000. package/dist/llm/wire/model-catalog.d.ts +4 -0
  1001. package/dist/llm/wire/model-catalog.js +34 -0
  1002. package/dist/llm/wire/model-catalog.js.map +1 -0
  1003. package/dist/llm/wire/openai-complete.d.ts +27 -0
  1004. package/dist/llm/wire/openai-complete.js +138 -0
  1005. package/dist/llm/wire/openai-complete.js.map +1 -0
  1006. package/dist/llm/wire/openai-stream.d.ts +36 -0
  1007. package/dist/llm/wire/openai-stream.js +665 -0
  1008. package/dist/llm/wire/openai-stream.js.map +1 -0
  1009. package/dist/llm/wire/reasoning-artifacts.d.ts +45 -0
  1010. package/dist/llm/wire/reasoning-artifacts.js +140 -0
  1011. package/dist/llm/wire/reasoning-artifacts.js.map +1 -0
  1012. package/dist/llm/wire/reasoning-payload.d.ts +9 -0
  1013. package/dist/llm/wire/reasoning-payload.js +212 -0
  1014. package/dist/llm/wire/reasoning-payload.js.map +1 -0
  1015. package/dist/llm/wire/response-errors.d.ts +5 -0
  1016. package/dist/llm/wire/response-errors.js +182 -0
  1017. package/dist/llm/wire/response-errors.js.map +1 -0
  1018. package/dist/llm/wire/responses-first.d.ts +30 -0
  1019. package/dist/llm/wire/responses-first.js +335 -0
  1020. package/dist/llm/wire/responses-first.js.map +1 -0
  1021. package/dist/llm/wire/stream-framing.d.ts +38 -0
  1022. package/dist/llm/wire/stream-framing.js +217 -0
  1023. package/dist/llm/wire/stream-framing.js.map +1 -0
  1024. package/dist/mcp/runtime.d.ts +0 -15
  1025. package/dist/mcp/runtime.js +0 -8
  1026. package/dist/mcp/runtime.js.map +1 -1
  1027. package/dist/modes/ask.d.ts +0 -3
  1028. package/dist/modes/ask.js +0 -22
  1029. package/dist/modes/ask.js.map +1 -1
  1030. package/dist/noninteractive/blocks/tool-blocks.d.ts +35 -0
  1031. package/dist/noninteractive/blocks/tool-blocks.js +206 -0
  1032. package/dist/noninteractive/blocks/tool-blocks.js.map +1 -0
  1033. package/dist/noninteractive/readline-prompts.d.ts +0 -21
  1034. package/dist/noninteractive/readline-prompts.js +0 -31
  1035. package/dist/noninteractive/readline-prompts.js.map +1 -1
  1036. package/dist/noninteractive/stdio-confirm-port.d.ts +0 -9
  1037. package/dist/noninteractive/stdio-confirm-port.js +0 -9
  1038. package/dist/noninteractive/stdio-confirm-port.js.map +1 -1
  1039. package/dist/noninteractive/stream-blocks.d.ts +3 -49
  1040. package/dist/noninteractive/stream-blocks.js +14 -234
  1041. package/dist/noninteractive/stream-blocks.js.map +1 -1
  1042. package/dist/noninteractive/stream-renderer.d.ts +0 -10
  1043. package/dist/noninteractive/stream-renderer.js +0 -10
  1044. package/dist/noninteractive/stream-renderer.js.map +1 -1
  1045. package/dist/noninteractive/stream-spinner.d.ts +0 -8
  1046. package/dist/noninteractive/stream-spinner.js +0 -8
  1047. package/dist/noninteractive/stream-spinner.js.map +1 -1
  1048. package/dist/os/bun-runtime.d.ts +0 -15
  1049. package/dist/os/bun-runtime.js +0 -33
  1050. package/dist/os/bun-runtime.js.map +1 -1
  1051. package/dist/os/command.d.ts +0 -6
  1052. package/dist/os/command.js +0 -13
  1053. package/dist/os/command.js.map +1 -1
  1054. package/dist/os/cwd.d.ts +0 -5
  1055. package/dist/os/cwd.js +0 -6
  1056. package/dist/os/cwd.js.map +1 -1
  1057. package/dist/os/permissions.d.ts +0 -11
  1058. package/dist/os/permissions.js +0 -13
  1059. package/dist/os/permissions.js.map +1 -1
  1060. package/dist/os/process-identity.d.ts +0 -22
  1061. package/dist/os/process-identity.js +0 -23
  1062. package/dist/os/process-identity.js.map +1 -1
  1063. package/dist/os/process-tree.d.ts +0 -7
  1064. package/dist/os/process-tree.js +0 -8
  1065. package/dist/os/process-tree.js.map +1 -1
  1066. package/dist/prompts/embedded.js +1 -1
  1067. package/dist/prompts/embedded.js.map +1 -1
  1068. package/dist/prompts/index.d.ts +0 -36
  1069. package/dist/prompts/index.js +2 -47
  1070. package/dist/prompts/index.js.map +1 -1
  1071. package/dist/prompts/system.agent.md +2 -2
  1072. package/dist/safety/classifier.d.ts +5 -26
  1073. package/dist/safety/classifier.js +5 -573
  1074. package/dist/safety/classifier.js.map +1 -1
  1075. package/dist/safety/engagement-policy.d.ts +0 -13
  1076. package/dist/safety/engagement-policy.js +0 -32
  1077. package/dist/safety/engagement-policy.js.map +1 -1
  1078. package/dist/safety/patterns.d.ts +0 -108
  1079. package/dist/safety/patterns.js +0 -159
  1080. package/dist/safety/patterns.js.map +1 -1
  1081. package/dist/safety/shell-classification.d.ts +19 -0
  1082. package/dist/safety/shell-classification.js +215 -0
  1083. package/dist/safety/shell-classification.js.map +1 -0
  1084. package/dist/safety/tool-classification.d.ts +4 -0
  1085. package/dist/safety/tool-classification.js +260 -0
  1086. package/dist/safety/tool-classification.js.map +1 -0
  1087. package/dist/store/config/endpoints.d.ts +85 -0
  1088. package/dist/store/config/endpoints.js +298 -0
  1089. package/dist/store/config/endpoints.js.map +1 -0
  1090. package/dist/store/config/settings.d.ts +11 -0
  1091. package/dist/store/config/settings.js +52 -0
  1092. package/dist/store/config/settings.js.map +1 -0
  1093. package/dist/store/config.d.ts +6 -169
  1094. package/dist/store/config.js +4 -411
  1095. package/dist/store/config.js.map +1 -1
  1096. package/dist/store/engagement.d.ts +0 -1
  1097. package/dist/store/engagement.js +0 -3
  1098. package/dist/store/engagement.js.map +1 -1
  1099. package/dist/store/history/jsonl-backend.d.ts +7 -0
  1100. package/dist/store/history/jsonl-backend.js +151 -0
  1101. package/dist/store/history/jsonl-backend.js.map +1 -0
  1102. package/dist/store/history/jsonl-lock.d.ts +2 -0
  1103. package/dist/store/history/jsonl-lock.js +100 -0
  1104. package/dist/store/history/jsonl-lock.js.map +1 -0
  1105. package/dist/store/history/lifecycle.d.ts +14 -0
  1106. package/dist/store/history/lifecycle.js +316 -0
  1107. package/dist/store/history/lifecycle.js.map +1 -0
  1108. package/dist/store/history/recovery.d.ts +62 -0
  1109. package/dist/store/history/recovery.js +253 -0
  1110. package/dist/store/history/recovery.js.map +1 -0
  1111. package/dist/store/history/session-queries.d.ts +9 -0
  1112. package/dist/store/history/session-queries.js +142 -0
  1113. package/dist/store/history/session-queries.js.map +1 -0
  1114. package/dist/store/history/sqlite-backend.d.ts +25 -0
  1115. package/dist/store/history/sqlite-backend.js +209 -0
  1116. package/dist/store/history/sqlite-backend.js.map +1 -0
  1117. package/dist/store/history-index.d.ts +0 -5
  1118. package/dist/store/history-index.js +0 -10
  1119. package/dist/store/history-index.js.map +1 -1
  1120. package/dist/store/history.d.ts +12 -97
  1121. package/dist/store/history.js +12 -1214
  1122. package/dist/store/history.js.map +1 -1
  1123. package/dist/store/keys/search-providers.d.ts +33 -0
  1124. package/dist/store/keys/search-providers.js +211 -0
  1125. package/dist/store/keys/search-providers.js.map +1 -0
  1126. package/dist/store/keys/secret-store.d.ts +40 -0
  1127. package/dist/store/keys/secret-store.js +249 -0
  1128. package/dist/store/keys/secret-store.js.map +1 -0
  1129. package/dist/store/keys.d.ts +8 -95
  1130. package/dist/store/keys.js +7 -537
  1131. package/dist/store/keys.js.map +1 -1
  1132. package/dist/store/logs.d.ts +0 -1
  1133. package/dist/store/logs.js +1 -7
  1134. package/dist/store/logs.js.map +1 -1
  1135. package/dist/store/paths.d.ts +0 -12
  1136. package/dist/store/paths.js +0 -12
  1137. package/dist/store/paths.js.map +1 -1
  1138. package/dist/store/plan/jsonl-backend.d.ts +7 -0
  1139. package/dist/store/plan/jsonl-backend.js +115 -0
  1140. package/dist/store/plan/jsonl-backend.js.map +1 -0
  1141. package/dist/store/plan/mutation.d.ts +25 -0
  1142. package/dist/store/plan/mutation.js +270 -0
  1143. package/dist/store/plan/mutation.js.map +1 -0
  1144. package/dist/store/plan/sqlite-backend.d.ts +66 -0
  1145. package/dist/store/plan/sqlite-backend.js +66 -0
  1146. package/dist/store/plan/sqlite-backend.js.map +1 -0
  1147. package/dist/store/plan/task-normalization.d.ts +8 -0
  1148. package/dist/store/plan/task-normalization.js +165 -0
  1149. package/dist/store/plan/task-normalization.js.map +1 -0
  1150. package/dist/store/plan.d.ts +9 -176
  1151. package/dist/store/plan.js +11 -742
  1152. package/dist/store/plan.js.map +1 -1
  1153. package/dist/store/project.js +0 -5
  1154. package/dist/store/project.js.map +1 -1
  1155. package/dist/store/responder-settlement.d.ts +0 -1
  1156. package/dist/store/responder-settlement.js +0 -3
  1157. package/dist/store/responder-settlement.js.map +1 -1
  1158. package/dist/store/scope.d.ts +0 -16
  1159. package/dist/store/scope.js +0 -22
  1160. package/dist/store/scope.js.map +1 -1
  1161. package/dist/store/session-workspace.d.ts +0 -51
  1162. package/dist/store/session-workspace.js +0 -57
  1163. package/dist/store/session-workspace.js.map +1 -1
  1164. package/dist/store/task-transitions.d.ts +0 -7
  1165. package/dist/store/task-transitions.js +0 -6
  1166. package/dist/store/task-transitions.js.map +1 -1
  1167. package/dist/tools/batch/batch-parsing.d.ts +11 -0
  1168. package/dist/tools/batch/batch-parsing.js +78 -0
  1169. package/dist/tools/batch/batch-parsing.js.map +1 -0
  1170. package/dist/tools/batch/limits.d.ts +6 -0
  1171. package/dist/tools/batch/limits.js +17 -0
  1172. package/dist/tools/batch/limits.js.map +1 -0
  1173. package/dist/tools/batch/run-batch.d.ts +3 -0
  1174. package/dist/tools/batch/run-batch.js +402 -0
  1175. package/dist/tools/batch/run-batch.js.map +1 -0
  1176. package/dist/tools/batch-fail-policy.d.ts +0 -29
  1177. package/dist/tools/batch-fail-policy.js +0 -31
  1178. package/dist/tools/batch-fail-policy.js.map +1 -1
  1179. package/dist/tools/call-normalization.d.ts +2 -0
  1180. package/dist/tools/call-normalization.js +165 -0
  1181. package/dist/tools/call-normalization.js.map +1 -0
  1182. package/dist/tools/capabilities.d.ts +0 -1
  1183. package/dist/tools/capabilities.js +0 -28
  1184. package/dist/tools/capabilities.js.map +1 -1
  1185. package/dist/tools/command-intent.d.ts +0 -19
  1186. package/dist/tools/command-intent.js +0 -65
  1187. package/dist/tools/command-intent.js.map +1 -1
  1188. package/dist/tools/definitions/aggregate.d.ts +2 -0
  1189. package/dist/tools/definitions/aggregate.js +263 -0
  1190. package/dist/tools/definitions/aggregate.js.map +1 -0
  1191. package/dist/tools/definitions/context-1.d.ts +2 -0
  1192. package/dist/tools/definitions/context-1.js +8 -0
  1193. package/dist/tools/definitions/context-1.js.map +1 -0
  1194. package/dist/tools/definitions/context-2.d.ts +2 -0
  1195. package/dist/tools/definitions/context-2.js +90 -0
  1196. package/dist/tools/definitions/context-2.js.map +1 -0
  1197. package/dist/tools/definitions/define.d.ts +7 -0
  1198. package/dist/tools/definitions/define.js +53 -0
  1199. package/dist/tools/definitions/define.js.map +1 -0
  1200. package/dist/tools/definitions/files.d.ts +2 -0
  1201. package/dist/tools/definitions/files.js +193 -0
  1202. package/dist/tools/definitions/files.js.map +1 -0
  1203. package/dist/tools/definitions/network-1.d.ts +2 -0
  1204. package/dist/tools/definitions/network-1.js +72 -0
  1205. package/dist/tools/definitions/network-1.js.map +1 -0
  1206. package/dist/tools/definitions/network-2.d.ts +2 -0
  1207. package/dist/tools/definitions/network-2.js +22 -0
  1208. package/dist/tools/definitions/network-2.js.map +1 -0
  1209. package/dist/tools/definitions/orchestration.d.ts +2 -0
  1210. package/dist/tools/definitions/orchestration.js +122 -0
  1211. package/dist/tools/definitions/orchestration.js.map +1 -0
  1212. package/dist/tools/definitions/pentest.d.ts +2 -0
  1213. package/dist/tools/definitions/pentest.js +91 -0
  1214. package/dist/tools/definitions/pentest.js.map +1 -0
  1215. package/dist/tools/definitions/selection.d.ts +9 -0
  1216. package/dist/tools/definitions/selection.js +84 -0
  1217. package/dist/tools/definitions/selection.js.map +1 -0
  1218. package/dist/tools/definitions/shell.d.ts +2 -0
  1219. package/dist/tools/definitions/shell.js +83 -0
  1220. package/dist/tools/definitions/shell.js.map +1 -0
  1221. package/dist/tools/definitions/terminal.d.ts +2 -0
  1222. package/dist/tools/definitions/terminal.js +91 -0
  1223. package/dist/tools/definitions/terminal.js.map +1 -0
  1224. package/dist/tools/definitions/web-1.d.ts +2 -0
  1225. package/dist/tools/definitions/web-1.js +68 -0
  1226. package/dist/tools/definitions/web-1.js.map +1 -0
  1227. package/dist/tools/definitions/web-2.d.ts +2 -0
  1228. package/dist/tools/definitions/web-2.js +59 -0
  1229. package/dist/tools/definitions/web-2.js.map +1 -0
  1230. package/dist/tools/definitions.d.ts +3 -16
  1231. package/dist/tools/definitions.js +8 -1238
  1232. package/dist/tools/definitions.js.map +1 -1
  1233. package/dist/tools/diff/line-ops.d.ts +34 -0
  1234. package/dist/tools/diff/line-ops.js +218 -0
  1235. package/dist/tools/diff/line-ops.js.map +1 -0
  1236. package/dist/tools/dns-native.d.ts +0 -5
  1237. package/dist/tools/dns-native.js +0 -16
  1238. package/dist/tools/dns-native.js.map +1 -1
  1239. package/dist/tools/external-tools.d.ts +0 -8
  1240. package/dist/tools/external-tools.js.map +1 -1
  1241. package/dist/tools/file-diff.d.ts +3 -78
  1242. package/dist/tools/file-diff.js +2 -271
  1243. package/dist/tools/file-diff.js.map +1 -1
  1244. package/dist/tools/fs/internals-2.d.ts +1 -0
  1245. package/dist/tools/fs/internals-2.js +6 -0
  1246. package/dist/tools/fs/internals-2.js.map +1 -0
  1247. package/dist/tools/fs/internals.d.ts +4 -0
  1248. package/dist/tools/fs/internals.js +23 -0
  1249. package/dist/tools/fs/internals.js.map +1 -0
  1250. package/dist/tools/fs/mutations.d.ts +17 -0
  1251. package/dist/tools/fs/mutations.js +396 -0
  1252. package/dist/tools/fs/mutations.js.map +1 -0
  1253. package/dist/tools/fs/read-window.d.ts +14 -0
  1254. package/dist/tools/fs/read-window.js +288 -0
  1255. package/dist/tools/fs/read-window.js.map +1 -0
  1256. package/dist/tools/fs/read.d.ts +7 -0
  1257. package/dist/tools/fs/read.js +164 -0
  1258. package/dist/tools/fs/read.js.map +1 -0
  1259. package/dist/tools/fs/search.d.ts +13 -0
  1260. package/dist/tools/fs/search.js +125 -0
  1261. package/dist/tools/fs/search.js.map +1 -0
  1262. package/dist/tools/fs.d.ts +4 -79
  1263. package/dist/tools/fs.js +26 -1115
  1264. package/dist/tools/fs.js.map +1 -1
  1265. package/dist/tools/handlers/args.d.ts +8 -0
  1266. package/dist/tools/handlers/args.js +50 -0
  1267. package/dist/tools/handlers/args.js.map +1 -0
  1268. package/dist/tools/handlers/context-1.d.ts +2 -0
  1269. package/dist/tools/handlers/context-1.js +7 -0
  1270. package/dist/tools/handlers/context-1.js.map +1 -0
  1271. package/dist/tools/handlers/context-2.d.ts +2 -0
  1272. package/dist/tools/handlers/context-2.js +14 -0
  1273. package/dist/tools/handlers/context-2.js.map +1 -0
  1274. package/dist/tools/handlers/files-1.d.ts +2 -0
  1275. package/dist/tools/handlers/files-1.js +51 -0
  1276. package/dist/tools/handlers/files-1.js.map +1 -0
  1277. package/dist/tools/handlers/files-2.d.ts +2 -0
  1278. package/dist/tools/handlers/files-2.js +31 -0
  1279. package/dist/tools/handlers/files-2.js.map +1 -0
  1280. package/dist/tools/handlers/network-1.d.ts +2 -0
  1281. package/dist/tools/handlers/network-1.js +52 -0
  1282. package/dist/tools/handlers/network-1.js.map +1 -0
  1283. package/dist/tools/handlers/network-2.d.ts +2 -0
  1284. package/dist/tools/handlers/network-2.js +32 -0
  1285. package/dist/tools/handlers/network-2.js.map +1 -0
  1286. package/dist/tools/handlers/network-3.d.ts +2 -0
  1287. package/dist/tools/handlers/network-3.js +17 -0
  1288. package/dist/tools/handlers/network-3.js.map +1 -0
  1289. package/dist/tools/handlers/nmap-preparation.d.ts +13 -0
  1290. package/dist/tools/handlers/nmap-preparation.js +66 -0
  1291. package/dist/tools/handlers/nmap-preparation.js.map +1 -0
  1292. package/dist/tools/handlers/orchestration-1.d.ts +2 -0
  1293. package/dist/tools/handlers/orchestration-1.js +7 -0
  1294. package/dist/tools/handlers/orchestration-1.js.map +1 -0
  1295. package/dist/tools/handlers/orchestration-2.d.ts +2 -0
  1296. package/dist/tools/handlers/orchestration-2.js +16 -0
  1297. package/dist/tools/handlers/orchestration-2.js.map +1 -0
  1298. package/dist/tools/handlers/pentest.d.ts +2 -0
  1299. package/dist/tools/handlers/pentest.js +208 -0
  1300. package/dist/tools/handlers/pentest.js.map +1 -0
  1301. package/dist/tools/handlers/responder-job-options.d.ts +3 -0
  1302. package/dist/tools/handlers/responder-job-options.js +16 -0
  1303. package/dist/tools/handlers/responder-job-options.js.map +1 -0
  1304. package/dist/tools/handlers/shell-1.d.ts +2 -0
  1305. package/dist/tools/handlers/shell-1.js +94 -0
  1306. package/dist/tools/handlers/shell-1.js.map +1 -0
  1307. package/dist/tools/handlers/shell-2.d.ts +2 -0
  1308. package/dist/tools/handlers/shell-2.js +49 -0
  1309. package/dist/tools/handlers/shell-2.js.map +1 -0
  1310. package/dist/tools/handlers/shell-3.d.ts +2 -0
  1311. package/dist/tools/handlers/shell-3.js +47 -0
  1312. package/dist/tools/handlers/shell-3.js.map +1 -0
  1313. package/dist/tools/handlers/web.d.ts +2 -0
  1314. package/dist/tools/handlers/web.js +168 -0
  1315. package/dist/tools/handlers/web.js.map +1 -0
  1316. package/dist/tools/http/agents.d.ts +10 -0
  1317. package/dist/tools/http/agents.js +63 -0
  1318. package/dist/tools/http/agents.js.map +1 -0
  1319. package/dist/tools/http/evidence-format.d.ts +37 -0
  1320. package/dist/tools/http/evidence-format.js +181 -0
  1321. package/dist/tools/http/evidence-format.js.map +1 -0
  1322. package/dist/tools/http/fetch.d.ts +31 -0
  1323. package/dist/tools/http/fetch.js +480 -0
  1324. package/dist/tools/http/fetch.js.map +1 -0
  1325. package/dist/tools/http/retry-policy.d.ts +14 -0
  1326. package/dist/tools/http/retry-policy.js +144 -0
  1327. package/dist/tools/http/retry-policy.js.map +1 -0
  1328. package/dist/tools/http.d.ts +1 -45
  1329. package/dist/tools/http.js +1 -920
  1330. package/dist/tools/http.js.map +1 -1
  1331. package/dist/tools/image.d.ts +0 -15
  1332. package/dist/tools/image.js +0 -21
  1333. package/dist/tools/image.js.map +1 -1
  1334. package/dist/tools/interactive-session-tools.d.ts +0 -7
  1335. package/dist/tools/interactive-session-tools.js +0 -13
  1336. package/dist/tools/interactive-session-tools.js.map +1 -1
  1337. package/dist/tools/jobs/helpers.d.ts +6 -0
  1338. package/dist/tools/jobs/helpers.js +63 -0
  1339. package/dist/tools/jobs/helpers.js.map +1 -0
  1340. package/dist/tools/jobs/limits.d.ts +20 -0
  1341. package/dist/tools/jobs/limits.js +21 -0
  1342. package/dist/tools/jobs/limits.js.map +1 -0
  1343. package/dist/tools/jobs/polling-policy.d.ts +11 -0
  1344. package/dist/tools/jobs/polling-policy.js +33 -0
  1345. package/dist/tools/jobs/polling-policy.js.map +1 -0
  1346. package/dist/tools/jobs/process-identity.d.ts +5 -0
  1347. package/dist/tools/jobs/process-identity.js +80 -0
  1348. package/dist/tools/jobs/process-identity.js.map +1 -0
  1349. package/dist/tools/jobs/redacted-writer.d.ts +25 -0
  1350. package/dist/tools/jobs/redacted-writer.js +134 -0
  1351. package/dist/tools/jobs/redacted-writer.js.map +1 -0
  1352. package/dist/tools/jobs/types.d.ts +152 -0
  1353. package/dist/tools/jobs/types.js +2 -0
  1354. package/dist/tools/jobs/types.js.map +1 -0
  1355. package/dist/tools/jobs.d.ts +8 -210
  1356. package/dist/tools/jobs.js +13 -453
  1357. package/dist/tools/jobs.js.map +1 -1
  1358. package/dist/tools/net-ping-sweep.d.ts +0 -8
  1359. package/dist/tools/net-ping-sweep.js +0 -22
  1360. package/dist/tools/net-ping-sweep.js.map +1 -1
  1361. package/dist/tools/network-context.d.ts +0 -4
  1362. package/dist/tools/network-context.js +0 -8
  1363. package/dist/tools/network-context.js.map +1 -1
  1364. package/dist/tools/nmap-runner.d.ts +0 -21
  1365. package/dist/tools/nmap-runner.js +0 -43
  1366. package/dist/tools/nmap-runner.js.map +1 -1
  1367. package/dist/tools/output-selection.d.ts +0 -1
  1368. package/dist/tools/output-selection.js +0 -3
  1369. package/dist/tools/output-selection.js.map +1 -1
  1370. package/dist/tools/package-binary.js +0 -7
  1371. package/dist/tools/package-binary.js.map +1 -1
  1372. package/dist/tools/pdf/read.d.ts +6 -0
  1373. package/dist/tools/pdf/read.js +529 -0
  1374. package/dist/tools/pdf/read.js.map +1 -0
  1375. package/dist/tools/pdf.d.ts +2 -6
  1376. package/dist/tools/pdf.js +1 -528
  1377. package/dist/tools/pdf.js.map +1 -1
  1378. package/dist/tools/pentest-workflows.js +0 -12
  1379. package/dist/tools/pentest-workflows.js.map +1 -1
  1380. package/dist/tools/policies/output-policy.d.ts +0 -17
  1381. package/dist/tools/policies/output-policy.js +0 -18
  1382. package/dist/tools/policies/output-policy.js.map +1 -1
  1383. package/dist/tools/reducers/ffuf.d.ts +0 -5
  1384. package/dist/tools/reducers/ffuf.js +0 -8
  1385. package/dist/tools/reducers/ffuf.js.map +1 -1
  1386. package/dist/tools/reducers/gobuster.js +0 -1
  1387. package/dist/tools/reducers/gobuster.js.map +1 -1
  1388. package/dist/tools/reducers/httpx.js +0 -1
  1389. package/dist/tools/reducers/httpx.js.map +1 -1
  1390. package/dist/tools/reducers/nmap.d.ts +0 -5
  1391. package/dist/tools/reducers/nmap.js +0 -5
  1392. package/dist/tools/reducers/nmap.js.map +1 -1
  1393. package/dist/tools/reducers/nuclei.js +0 -1
  1394. package/dist/tools/reducers/nuclei.js.map +1 -1
  1395. package/dist/tools/reducers/subdomains.d.ts +0 -4
  1396. package/dist/tools/reducers/subdomains.js +0 -4
  1397. package/dist/tools/reducers/subdomains.js.map +1 -1
  1398. package/dist/tools/reducers/types.d.ts +0 -5
  1399. package/dist/tools/registry.d.ts +4 -20
  1400. package/dist/tools/registry.js +42 -1636
  1401. package/dist/tools/registry.js.map +1 -1
  1402. package/dist/tools/shell/artifact-name.d.ts +1 -0
  1403. package/dist/tools/shell/artifact-name.js +6 -0
  1404. package/dist/tools/shell/artifact-name.js.map +1 -0
  1405. package/dist/tools/shell/capture.d.ts +31 -0
  1406. package/dist/tools/shell/capture.js +135 -0
  1407. package/dist/tools/shell/capture.js.map +1 -0
  1408. package/dist/tools/shell/exec-attempt.d.ts +10 -0
  1409. package/dist/tools/shell/exec-attempt.js +288 -0
  1410. package/dist/tools/shell/exec-attempt.js.map +1 -0
  1411. package/dist/tools/shell/internals-2.d.ts +16 -0
  1412. package/dist/tools/shell/internals-2.js +48 -0
  1413. package/dist/tools/shell/internals-2.js.map +1 -0
  1414. package/dist/tools/shell/internals.d.ts +10 -0
  1415. package/dist/tools/shell/internals.js +51 -0
  1416. package/dist/tools/shell/internals.js.map +1 -0
  1417. package/dist/tools/shell/spawn-argv.d.ts +17 -0
  1418. package/dist/tools/shell/spawn-argv.js +248 -0
  1419. package/dist/tools/shell/spawn-argv.js.map +1 -0
  1420. package/dist/tools/shell-quoting.d.ts +1 -0
  1421. package/dist/tools/shell-quoting.js +7 -0
  1422. package/dist/tools/shell-quoting.js.map +1 -0
  1423. package/dist/tools/shell.d.ts +4 -82
  1424. package/dist/tools/shell.js +7 -845
  1425. package/dist/tools/shell.js.map +1 -1
  1426. package/dist/tools/sudo-session.d.ts +0 -41
  1427. package/dist/tools/sudo-session.js +0 -44
  1428. package/dist/tools/sudo-session.js.map +1 -1
  1429. package/dist/tools/tool-types.d.ts +0 -7
  1430. package/dist/tools/validate.d.ts +0 -35
  1431. package/dist/tools/validate.js +2 -67
  1432. package/dist/tools/validate.js.map +1 -1
  1433. package/dist/tools/web/audit.d.ts +0 -74
  1434. package/dist/tools/web/audit.js +0 -39
  1435. package/dist/tools/web/audit.js.map +1 -1
  1436. package/dist/tools/web/budget.d.ts +0 -35
  1437. package/dist/tools/web/budget.js +0 -75
  1438. package/dist/tools/web/budget.js.map +1 -1
  1439. package/dist/tools/web/capture.d.ts +0 -106
  1440. package/dist/tools/web/capture.js +0 -148
  1441. package/dist/tools/web/capture.js.map +1 -1
  1442. package/dist/tools/web/decode.d.ts +0 -8
  1443. package/dist/tools/web/decode.js +0 -9
  1444. package/dist/tools/web/decode.js.map +1 -1
  1445. package/dist/tools/web/fetch-core.d.ts +2 -32
  1446. package/dist/tools/web/fetch-core.js +4 -1058
  1447. package/dist/tools/web/fetch-core.js.map +1 -1
  1448. package/dist/tools/web/fetch.d.ts +0 -29
  1449. package/dist/tools/web/fetch.js +0 -46
  1450. package/dist/tools/web/fetch.js.map +1 -1
  1451. package/dist/tools/web/issue-hop.d.ts +57 -0
  1452. package/dist/tools/web/issue-hop.js +396 -0
  1453. package/dist/tools/web/issue-hop.js.map +1 -0
  1454. package/dist/tools/web/providers/brave.d.ts +0 -40
  1455. package/dist/tools/web/providers/brave.js +1 -100
  1456. package/dist/tools/web/providers/brave.js.map +1 -1
  1457. package/dist/tools/web/providers/duckduckgo.d.ts +0 -41
  1458. package/dist/tools/web/providers/duckduckgo.js +0 -104
  1459. package/dist/tools/web/providers/duckduckgo.js.map +1 -1
  1460. package/dist/tools/web/providers/exa.d.ts +0 -43
  1461. package/dist/tools/web/providers/exa.js +1 -102
  1462. package/dist/tools/web/providers/exa.js.map +1 -1
  1463. package/dist/tools/web/providers/provider.d.ts +0 -69
  1464. package/dist/tools/web/providers/provider.js +0 -28
  1465. package/dist/tools/web/providers/provider.js.map +1 -1
  1466. package/dist/tools/web/providers/tavily.d.ts +0 -46
  1467. package/dist/tools/web/providers/tavily.js +1 -111
  1468. package/dist/tools/web/providers/tavily.js.map +1 -1
  1469. package/dist/tools/web/readable.d.ts +0 -62
  1470. package/dist/tools/web/readable.js +1 -132
  1471. package/dist/tools/web/readable.js.map +1 -1
  1472. package/dist/tools/web/redact.d.ts +0 -26
  1473. package/dist/tools/web/redact.js +0 -2
  1474. package/dist/tools/web/redact.js.map +1 -1
  1475. package/dist/tools/web/request-loop.d.ts +38 -0
  1476. package/dist/tools/web/request-loop.js +172 -0
  1477. package/dist/tools/web/request-loop.js.map +1 -0
  1478. package/dist/tools/web/response-body.d.ts +41 -0
  1479. package/dist/tools/web/response-body.js +174 -0
  1480. package/dist/tools/web/response-body.js.map +1 -0
  1481. package/dist/tools/web/search-attempts.d.ts +20 -0
  1482. package/dist/tools/web/search-attempts.js +303 -0
  1483. package/dist/tools/web/search-attempts.js.map +1 -0
  1484. package/dist/tools/web/search.d.ts +0 -33
  1485. package/dist/tools/web/search.js +3 -396
  1486. package/dist/tools/web/search.js.map +1 -1
  1487. package/dist/tools/web/ssrf-guard.d.ts +0 -42
  1488. package/dist/tools/web/ssrf-guard.js +0 -57
  1489. package/dist/tools/web/ssrf-guard.js.map +1 -1
  1490. package/dist/tools/web/types.d.ts +0 -197
  1491. package/dist/tools/web/types.js +0 -41
  1492. package/dist/tools/web/types.js.map +1 -1
  1493. package/dist/tools/web/validate-args.d.ts +11 -0
  1494. package/dist/tools/web/validate-args.js +107 -0
  1495. package/dist/tools/web/validate-args.js.map +1 -0
  1496. package/dist/tools/whois-native.d.ts +0 -4
  1497. package/dist/tools/whois-native.js +0 -6
  1498. package/dist/tools/whois-native.js.map +1 -1
  1499. package/dist/tools/wordlists.js +0 -32
  1500. package/dist/tools/wordlists.js.map +1 -1
  1501. package/dist/tui-v2/app/App.d.ts +0 -10
  1502. package/dist/tui-v2/app/App.js +67 -112
  1503. package/dist/tui-v2/app/App.js.map +1 -1
  1504. package/dist/tui-v2/bootstrap/pager-export.d.ts +0 -8
  1505. package/dist/tui-v2/bootstrap/pager-export.js +0 -11
  1506. package/dist/tui-v2/bootstrap/pager-export.js.map +1 -1
  1507. package/dist/tui-v2/bootstrap/patch-opentui-text.d.ts +0 -5
  1508. package/dist/tui-v2/bootstrap/patch-opentui-text.js +0 -5
  1509. package/dist/tui-v2/bootstrap/patch-opentui-text.js.map +1 -1
  1510. package/dist/tui-v2/bootstrap/resize-repaint.d.ts +16 -20
  1511. package/dist/tui-v2/bootstrap/resize-repaint.js +34 -13
  1512. package/dist/tui-v2/bootstrap/resize-repaint.js.map +1 -1
  1513. package/dist/tui-v2/bootstrap/start-tui-v2.d.ts +0 -7
  1514. package/dist/tui-v2/bootstrap/start-tui-v2.js +10 -27
  1515. package/dist/tui-v2/bootstrap/start-tui-v2.js.map +1 -1
  1516. package/dist/tui-v2/components/completion/completion-menu.d.ts +0 -4
  1517. package/dist/tui-v2/components/completion/completion-menu.js +2 -6
  1518. package/dist/tui-v2/components/completion/completion-menu.js.map +1 -1
  1519. package/dist/tui-v2/components/composer/composer-input-box.d.ts +0 -4
  1520. package/dist/tui-v2/components/composer/composer-input-box.js +1 -10
  1521. package/dist/tui-v2/components/composer/composer-input-box.js.map +1 -1
  1522. package/dist/tui-v2/components/composer/paste-chip.d.ts +0 -7
  1523. package/dist/tui-v2/components/composer/paste-chip.js +0 -7
  1524. package/dist/tui-v2/components/composer/paste-chip.js.map +1 -1
  1525. package/dist/tui-v2/components/jobs/jobs-panel.d.ts +0 -12
  1526. package/dist/tui-v2/components/jobs/jobs-panel.js +0 -34
  1527. package/dist/tui-v2/components/jobs/jobs-panel.js.map +1 -1
  1528. package/dist/tui-v2/components/modal/confirm-modal.d.ts +0 -8
  1529. package/dist/tui-v2/components/modal/confirm-modal.js +0 -4
  1530. package/dist/tui-v2/components/modal/confirm-modal.js.map +1 -1
  1531. package/dist/tui-v2/components/modal/keys-modal.d.ts +0 -11
  1532. package/dist/tui-v2/components/modal/keys-modal.js +0 -24
  1533. package/dist/tui-v2/components/modal/keys-modal.js.map +1 -1
  1534. package/dist/tui-v2/components/modal/prompt-actions-modal.d.ts +0 -6
  1535. package/dist/tui-v2/components/modal/prompt-actions-modal.js +4 -13
  1536. package/dist/tui-v2/components/modal/prompt-actions-modal.js.map +1 -1
  1537. package/dist/tui-v2/components/modal/scope-modal.d.ts +0 -5
  1538. package/dist/tui-v2/components/modal/scope-modal.js +0 -12
  1539. package/dist/tui-v2/components/modal/scope-modal.js.map +1 -1
  1540. package/dist/tui-v2/components/modal/secret-modal.d.ts +0 -8
  1541. package/dist/tui-v2/components/modal/secret-modal.js +0 -17
  1542. package/dist/tui-v2/components/modal/secret-modal.js.map +1 -1
  1543. package/dist/tui-v2/components/modal/text-editor-modal.d.ts +0 -6
  1544. package/dist/tui-v2/components/modal/text-editor-modal.js +0 -6
  1545. package/dist/tui-v2/components/modal/text-editor-modal.js.map +1 -1
  1546. package/dist/tui-v2/components/overlay/overlay-host.d.ts +0 -14
  1547. package/dist/tui-v2/components/overlay/overlay-host.js +0 -2
  1548. package/dist/tui-v2/components/overlay/overlay-host.js.map +1 -1
  1549. package/dist/tui-v2/components/pager/pager-line.d.ts +0 -5
  1550. package/dist/tui-v2/components/pager/pager-line.js +0 -10
  1551. package/dist/tui-v2/components/pager/pager-line.js.map +1 -1
  1552. package/dist/tui-v2/components/pager/pager.d.ts +0 -14
  1553. package/dist/tui-v2/components/pager/pager.js +3 -58
  1554. package/dist/tui-v2/components/pager/pager.js.map +1 -1
  1555. package/dist/tui-v2/components/picker/picker.d.ts +0 -6
  1556. package/dist/tui-v2/components/picker/picker.js +3 -12
  1557. package/dist/tui-v2/components/picker/picker.js.map +1 -1
  1558. package/dist/tui-v2/components/plan/plan-pane-anim.d.ts +0 -25
  1559. package/dist/tui-v2/components/plan/plan-pane-anim.js +0 -23
  1560. package/dist/tui-v2/components/plan/plan-pane-anim.js.map +1 -1
  1561. package/dist/tui-v2/components/plan/plan-view.d.ts +0 -7
  1562. package/dist/tui-v2/components/plan/plan-view.js +0 -20
  1563. package/dist/tui-v2/components/plan/plan-view.js.map +1 -1
  1564. package/dist/tui-v2/components/plan/use-pane-presence.d.ts +0 -9
  1565. package/dist/tui-v2/components/plan/use-pane-presence.js +0 -9
  1566. package/dist/tui-v2/components/plan/use-pane-presence.js.map +1 -1
  1567. package/dist/tui-v2/components/queue/queue-panel.d.ts +0 -12
  1568. package/dist/tui-v2/components/queue/queue-panel.js +2 -4
  1569. package/dist/tui-v2/components/queue/queue-panel.js.map +1 -1
  1570. package/dist/tui-v2/components/status/status-line.d.ts +0 -17
  1571. package/dist/tui-v2/components/status/status-line.js +0 -10
  1572. package/dist/tui-v2/components/status/status-line.js.map +1 -1
  1573. package/dist/tui-v2/components/toast/toast-anim.d.ts +0 -20
  1574. package/dist/tui-v2/components/toast/toast-anim.js +0 -15
  1575. package/dist/tui-v2/components/toast/toast-anim.js.map +1 -1
  1576. package/dist/tui-v2/components/toast/toast-host.d.ts +0 -12
  1577. package/dist/tui-v2/components/toast/toast-host.js +1 -29
  1578. package/dist/tui-v2/components/toast/toast-host.js.map +1 -1
  1579. package/dist/tui-v2/components/transcript/assistant-message.d.ts +0 -11
  1580. package/dist/tui-v2/components/transcript/assistant-message.js +3 -24
  1581. package/dist/tui-v2/components/transcript/assistant-message.js.map +1 -1
  1582. package/dist/tui-v2/components/transcript/compacted-row.d.ts +0 -6
  1583. package/dist/tui-v2/components/transcript/compacted-row.js +2 -6
  1584. package/dist/tui-v2/components/transcript/compacted-row.js.map +1 -1
  1585. package/dist/tui-v2/components/transcript/file-diff-card.d.ts +0 -9
  1586. package/dist/tui-v2/components/transcript/file-diff-card.js +0 -16
  1587. package/dist/tui-v2/components/transcript/file-diff-card.js.map +1 -1
  1588. package/dist/tui-v2/components/transcript/intro-card.d.ts +0 -9
  1589. package/dist/tui-v2/components/transcript/intro-card.js +2 -13
  1590. package/dist/tui-v2/components/transcript/intro-card.js.map +1 -1
  1591. package/dist/tui-v2/components/transcript/linkable-text.d.ts +0 -16
  1592. package/dist/tui-v2/components/transcript/linkable-text.js +0 -11
  1593. package/dist/tui-v2/components/transcript/linkable-text.js.map +1 -1
  1594. package/dist/tui-v2/components/transcript/notice-row.d.ts +0 -7
  1595. package/dist/tui-v2/components/transcript/notice-row.js +2 -18
  1596. package/dist/tui-v2/components/transcript/notice-row.js.map +1 -1
  1597. package/dist/tui-v2/components/transcript/search-bar.d.ts +0 -10
  1598. package/dist/tui-v2/components/transcript/search-bar.js +0 -3
  1599. package/dist/tui-v2/components/transcript/search-bar.js.map +1 -1
  1600. package/dist/tui-v2/components/transcript/selectable-line.d.ts +0 -16
  1601. package/dist/tui-v2/components/transcript/selectable-line.js +0 -9
  1602. package/dist/tui-v2/components/transcript/selectable-line.js.map +1 -1
  1603. package/dist/tui-v2/components/transcript/thinking-block.d.ts +0 -18
  1604. package/dist/tui-v2/components/transcript/thinking-block.js +2 -40
  1605. package/dist/tui-v2/components/transcript/thinking-block.js.map +1 -1
  1606. package/dist/tui-v2/components/transcript/tool-card.d.ts +0 -19
  1607. package/dist/tui-v2/components/transcript/tool-card.js +2 -42
  1608. package/dist/tui-v2/components/transcript/tool-card.js.map +1 -1
  1609. package/dist/tui-v2/components/transcript/transcript-row.d.ts +0 -14
  1610. package/dist/tui-v2/components/transcript/transcript-row.js +0 -13
  1611. package/dist/tui-v2/components/transcript/transcript-row.js.map +1 -1
  1612. package/dist/tui-v2/components/transcript/transcript-scroll-port.d.ts +0 -32
  1613. package/dist/tui-v2/components/transcript/transcript-scroll-port.js +0 -22
  1614. package/dist/tui-v2/components/transcript/transcript-scroll-port.js.map +1 -1
  1615. package/dist/tui-v2/components/transcript/transcript-view.d.ts +0 -9
  1616. package/dist/tui-v2/components/transcript/transcript-view.js +4 -67
  1617. package/dist/tui-v2/components/transcript/transcript-view.js.map +1 -1
  1618. package/dist/tui-v2/components/transcript/use-click-without-drag.d.ts +0 -7
  1619. package/dist/tui-v2/components/transcript/use-click-without-drag.js +1 -11
  1620. package/dist/tui-v2/components/transcript/use-click-without-drag.js.map +1 -1
  1621. package/dist/tui-v2/components/transcript/use-native-selection-copy.d.ts +0 -7
  1622. package/dist/tui-v2/components/transcript/use-native-selection-copy.js +0 -9
  1623. package/dist/tui-v2/components/transcript/use-native-selection-copy.js.map +1 -1
  1624. package/dist/tui-v2/components/transcript/use-transcript-selection.d.ts +0 -1
  1625. package/dist/tui-v2/components/transcript/use-transcript-selection.js +0 -14
  1626. package/dist/tui-v2/components/transcript/use-transcript-selection.js.map +1 -1
  1627. package/dist/tui-v2/components/transcript/user-message.d.ts +0 -2
  1628. package/dist/tui-v2/components/transcript/user-message.js +2 -7
  1629. package/dist/tui-v2/components/transcript/user-message.js.map +1 -1
  1630. package/dist/tui-v2/composer/composer-editor.d.ts +0 -20
  1631. package/dist/tui-v2/composer/composer-editor.js +0 -61
  1632. package/dist/tui-v2/composer/composer-editor.js.map +1 -1
  1633. package/dist/tui-v2/composer/composer-wheel.d.ts +0 -17
  1634. package/dist/tui-v2/composer/composer-wheel.js +0 -17
  1635. package/dist/tui-v2/composer/composer-wheel.js.map +1 -1
  1636. package/dist/tui-v2/composer/disable-native-textarea-scroll.d.ts +0 -12
  1637. package/dist/tui-v2/composer/disable-native-textarea-scroll.js +0 -13
  1638. package/dist/tui-v2/composer/disable-native-textarea-scroll.js.map +1 -1
  1639. package/dist/tui-v2/composer/textarea-keybindings.d.ts +0 -19
  1640. package/dist/tui-v2/composer/textarea-keybindings.js +0 -34
  1641. package/dist/tui-v2/composer/textarea-keybindings.js.map +1 -1
  1642. package/dist/tui-v2/composer/use-draft-actions.d.ts +0 -10
  1643. package/dist/tui-v2/composer/use-draft-actions.js +0 -5
  1644. package/dist/tui-v2/composer/use-draft-actions.js.map +1 -1
  1645. package/dist/tui-v2/hooks/terminal-dimensions.d.ts +6 -0
  1646. package/dist/tui-v2/hooks/terminal-dimensions.js +14 -0
  1647. package/dist/tui-v2/hooks/terminal-dimensions.js.map +1 -0
  1648. package/dist/tui-v2/input/chord-from-opentui-key.d.ts +0 -17
  1649. package/dist/tui-v2/input/chord-from-opentui-key.js +0 -17
  1650. package/dist/tui-v2/input/chord-from-opentui-key.js.map +1 -1
  1651. package/dist/tui-v2/rendering/ansi-to-styled.d.ts +0 -12
  1652. package/dist/tui-v2/rendering/ansi-to-styled.js +0 -10
  1653. package/dist/tui-v2/rendering/ansi-to-styled.js.map +1 -1
  1654. package/dist/tui-v2/rendering/pager-markdown.d.ts +0 -18
  1655. package/dist/tui-v2/rendering/pager-markdown.js +0 -14
  1656. package/dist/tui-v2/rendering/pager-markdown.js.map +1 -1
  1657. package/dist/types.d.ts +2 -135
  1658. package/dist/types.js +0 -3
  1659. package/dist/types.js.map +1 -1
  1660. package/dist/ui/mentions/expand.d.ts +26 -0
  1661. package/dist/ui/mentions/expand.js +308 -0
  1662. package/dist/ui/mentions/expand.js.map +1 -0
  1663. package/dist/ui/mentions/file-suggestions.d.ts +7 -0
  1664. package/dist/ui/mentions/file-suggestions.js +106 -0
  1665. package/dist/ui/mentions/file-suggestions.js.map +1 -0
  1666. package/dist/ui/mentions.d.ts +6 -70
  1667. package/dist/ui/mentions.js +8 -482
  1668. package/dist/ui/mentions.js.map +1 -1
  1669. package/dist/ui/plan-pane.d.ts +0 -15
  1670. package/dist/ui/plan-pane.js +1 -16
  1671. package/dist/ui/plan-pane.js.map +1 -1
  1672. package/dist/ui/thinking.d.ts +0 -8
  1673. package/dist/ui/thinking.js +0 -13
  1674. package/dist/ui/thinking.js.map +1 -1
  1675. package/dist/ui-core/actions/action-id.d.ts +0 -8
  1676. package/dist/ui-core/actions/action-id.js +0 -25
  1677. package/dist/ui-core/actions/action-id.js.map +1 -1
  1678. package/dist/ui-core/actions/action-router.d.ts +0 -10
  1679. package/dist/ui-core/actions/action-router.js +0 -16
  1680. package/dist/ui-core/actions/action-router.js.map +1 -1
  1681. package/dist/ui-core/actions/cancel-timing.d.ts +0 -3
  1682. package/dist/ui-core/actions/cancel-timing.js +0 -3
  1683. package/dist/ui-core/actions/cancel-timing.js.map +1 -1
  1684. package/dist/ui-core/actions/format-shortcuts.d.ts +0 -9
  1685. package/dist/ui-core/actions/format-shortcuts.js +0 -9
  1686. package/dist/ui-core/actions/format-shortcuts.js.map +1 -1
  1687. package/dist/ui-core/actions/keymap.d.ts +0 -9
  1688. package/dist/ui-core/actions/keymap.js +0 -39
  1689. package/dist/ui-core/actions/keymap.js.map +1 -1
  1690. package/dist/ui-core/actions/mode-cycle.d.ts +0 -2
  1691. package/dist/ui-core/actions/mode-cycle.js +0 -4
  1692. package/dist/ui-core/actions/mode-cycle.js.map +1 -1
  1693. package/dist/ui-core/bootstrap/can-use-tui.d.ts +0 -6
  1694. package/dist/ui-core/bootstrap/can-use-tui.js +0 -9
  1695. package/dist/ui-core/bootstrap/can-use-tui.js.map +1 -1
  1696. package/dist/ui-core/bootstrap/capabilities.d.ts +0 -8
  1697. package/dist/ui-core/bootstrap/capabilities.js +1 -8
  1698. package/dist/ui-core/bootstrap/capabilities.js.map +1 -1
  1699. package/dist/ui-core/bootstrap/composition-root.d.ts +0 -17
  1700. package/dist/ui-core/bootstrap/composition-root.js +30 -19
  1701. package/dist/ui-core/bootstrap/composition-root.js.map +1 -1
  1702. package/dist/ui-core/bootstrap/console-guard.d.ts +0 -15
  1703. package/dist/ui-core/bootstrap/console-guard.js +32 -0
  1704. package/dist/ui-core/bootstrap/console-guard.js.map +1 -1
  1705. package/dist/ui-core/bootstrap/console-suppress.js +2 -7
  1706. package/dist/ui-core/bootstrap/console-suppress.js.map +1 -1
  1707. package/dist/ui-core/bootstrap/exit-epilogue.d.ts +0 -6
  1708. package/dist/ui-core/bootstrap/exit-epilogue.js +0 -5
  1709. package/dist/ui-core/bootstrap/exit-epilogue.js.map +1 -1
  1710. package/dist/ui-core/bootstrap/lifecycle.d.ts +0 -42
  1711. package/dist/ui-core/bootstrap/lifecycle.js +0 -31
  1712. package/dist/ui-core/bootstrap/lifecycle.js.map +1 -1
  1713. package/dist/ui-core/bootstrap/overlay-ports.d.ts +0 -11
  1714. package/dist/ui-core/bootstrap/overlay-ports.js +0 -13
  1715. package/dist/ui-core/bootstrap/overlay-ports.js.map +1 -1
  1716. package/dist/ui-core/bootstrap/theme-mode-cache.js +0 -5
  1717. package/dist/ui-core/bootstrap/theme-mode-cache.js.map +1 -1
  1718. package/dist/ui-core/commands/command-handlers.d.ts +0 -6
  1719. package/dist/ui-core/commands/command-handlers.js +0 -6
  1720. package/dist/ui-core/commands/command-handlers.js.map +1 -1
  1721. package/dist/ui-core/commands/config-commands.d.ts +0 -3
  1722. package/dist/ui-core/commands/config-commands.js +0 -7
  1723. package/dist/ui-core/commands/config-commands.js.map +1 -1
  1724. package/dist/ui-core/commands/key-commands.d.ts +2 -0
  1725. package/dist/ui-core/commands/key-commands.js +79 -213
  1726. package/dist/ui-core/commands/key-commands.js.map +1 -1
  1727. package/dist/ui-core/commands/keys/editors.d.ts +15 -0
  1728. package/dist/ui-core/commands/keys/editors.js +127 -0
  1729. package/dist/ui-core/commands/keys/editors.js.map +1 -0
  1730. package/dist/ui-core/commands/mcp-commands.js +0 -6
  1731. package/dist/ui-core/commands/mcp-commands.js.map +1 -1
  1732. package/dist/ui-core/commands/picker-commands.d.ts +3 -14
  1733. package/dist/ui-core/commands/picker-commands.js +6 -694
  1734. package/dist/ui-core/commands/picker-commands.js.map +1 -1
  1735. package/dist/ui-core/commands/pickers/custom-provider.d.ts +3 -0
  1736. package/dist/ui-core/commands/pickers/custom-provider.js +170 -0
  1737. package/dist/ui-core/commands/pickers/custom-provider.js.map +1 -0
  1738. package/dist/ui-core/commands/pickers/history.d.ts +3 -0
  1739. package/dist/ui-core/commands/pickers/history.js +185 -0
  1740. package/dist/ui-core/commands/pickers/history.js.map +1 -0
  1741. package/dist/ui-core/commands/pickers/output-pager.d.ts +5 -0
  1742. package/dist/ui-core/commands/pickers/output-pager.js +90 -0
  1743. package/dist/ui-core/commands/pickers/output-pager.js.map +1 -0
  1744. package/dist/ui-core/commands/pickers/search-reasoning.d.ts +4 -0
  1745. package/dist/ui-core/commands/pickers/search-reasoning.js +184 -0
  1746. package/dist/ui-core/commands/pickers/search-reasoning.js.map +1 -0
  1747. package/dist/ui-core/commands/session-commands.d.ts +0 -4
  1748. package/dist/ui-core/commands/session-commands.js +23 -17
  1749. package/dist/ui-core/commands/session-commands.js.map +1 -1
  1750. package/dist/ui-core/commands/startup-update.d.ts +0 -6
  1751. package/dist/ui-core/commands/startup-update.js +0 -6
  1752. package/dist/ui-core/commands/startup-update.js.map +1 -1
  1753. package/dist/ui-core/composer/arrow-intent.d.ts +0 -10
  1754. package/dist/ui-core/composer/arrow-intent.js +0 -14
  1755. package/dist/ui-core/composer/arrow-intent.js.map +1 -1
  1756. package/dist/ui-core/composer/completion.d.ts +0 -9
  1757. package/dist/ui-core/composer/completion.js +1 -13
  1758. package/dist/ui-core/composer/completion.js.map +1 -1
  1759. package/dist/ui-core/composer/composer-action-port.d.ts +0 -10
  1760. package/dist/ui-core/composer/composer-action-port.js +0 -10
  1761. package/dist/ui-core/composer/composer-action-port.js.map +1 -1
  1762. package/dist/ui-core/composer/composer-height.d.ts +0 -12
  1763. package/dist/ui-core/composer/composer-height.js +0 -12
  1764. package/dist/ui-core/composer/composer-height.js.map +1 -1
  1765. package/dist/ui-core/composer/composer-wheel.d.ts +0 -17
  1766. package/dist/ui-core/composer/composer-wheel.js +0 -17
  1767. package/dist/ui-core/composer/composer-wheel.js.map +1 -1
  1768. package/dist/ui-core/composer/draft-actions.d.ts +0 -14
  1769. package/dist/ui-core/composer/draft-actions.js +0 -13
  1770. package/dist/ui-core/composer/draft-actions.js.map +1 -1
  1771. package/dist/ui-core/composer/history-nav.d.ts +0 -9
  1772. package/dist/ui-core/composer/history-nav.js +0 -9
  1773. package/dist/ui-core/composer/history-nav.js.map +1 -1
  1774. package/dist/ui-core/composer/input-history.d.ts +0 -1
  1775. package/dist/ui-core/composer/input-history.js +0 -1
  1776. package/dist/ui-core/composer/input-history.js.map +1 -1
  1777. package/dist/ui-core/composer/newline-hint.d.ts +0 -7
  1778. package/dist/ui-core/composer/newline-hint.js +0 -9
  1779. package/dist/ui-core/composer/newline-hint.js.map +1 -1
  1780. package/dist/ui-core/composer/paste-placeholder.d.ts +0 -23
  1781. package/dist/ui-core/composer/paste-placeholder.js +0 -21
  1782. package/dist/ui-core/composer/paste-placeholder.js.map +1 -1
  1783. package/dist/ui-core/composer/prompt-history.d.ts +0 -11
  1784. package/dist/ui-core/composer/prompt-history.js +0 -11
  1785. package/dist/ui-core/composer/prompt-history.js.map +1 -1
  1786. package/dist/ui-core/composer/secret-buffer.d.ts +0 -8
  1787. package/dist/ui-core/composer/secret-buffer.js +0 -8
  1788. package/dist/ui-core/composer/secret-buffer.js.map +1 -1
  1789. package/dist/ui-core/composer/textarea-keybindings.d.ts +0 -15
  1790. package/dist/ui-core/composer/textarea-keybindings.js +0 -30
  1791. package/dist/ui-core/composer/textarea-keybindings.js.map +1 -1
  1792. package/dist/ui-core/controllers/focus-controller.d.ts +0 -11
  1793. package/dist/ui-core/controllers/focus-controller.js +0 -11
  1794. package/dist/ui-core/controllers/focus-controller.js.map +1 -1
  1795. package/dist/ui-core/controllers/interruptible-controller.d.ts +0 -6
  1796. package/dist/ui-core/controllers/interruptible-controller.js +0 -6
  1797. package/dist/ui-core/controllers/interruptible-controller.js.map +1 -1
  1798. package/dist/ui-core/controllers/overlay-controller.d.ts +1 -81
  1799. package/dist/ui-core/controllers/overlay-controller.js +1 -48
  1800. package/dist/ui-core/controllers/overlay-controller.js.map +1 -1
  1801. package/dist/ui-core/controllers/selection-controller.d.ts +0 -9
  1802. package/dist/ui-core/controllers/selection-controller.js +0 -7
  1803. package/dist/ui-core/controllers/selection-controller.js.map +1 -1
  1804. package/dist/ui-core/controllers/toast-controller.d.ts +0 -24
  1805. package/dist/ui-core/controllers/toast-controller.js +0 -15
  1806. package/dist/ui-core/controllers/toast-controller.js.map +1 -1
  1807. package/dist/ui-core/layout/compute-layout.d.ts +0 -19
  1808. package/dist/ui-core/layout/compute-layout.js +0 -32
  1809. package/dist/ui-core/layout/compute-layout.js.map +1 -1
  1810. package/dist/ui-core/motion/ease.d.ts +0 -6
  1811. package/dist/ui-core/motion/ease.js +0 -6
  1812. package/dist/ui-core/motion/ease.js.map +1 -1
  1813. package/dist/ui-core/notify.d.ts +0 -8
  1814. package/dist/ui-core/notify.js +0 -8
  1815. package/dist/ui-core/notify.js.map +1 -1
  1816. package/dist/ui-core/plan/plan-lifecycle.d.ts +0 -27
  1817. package/dist/ui-core/plan/plan-lifecycle.js +0 -45
  1818. package/dist/ui-core/plan/plan-lifecycle.js.map +1 -1
  1819. package/dist/ui-core/ports/clipboard-osc52.d.ts +0 -8
  1820. package/dist/ui-core/ports/clipboard-osc52.js +0 -7
  1821. package/dist/ui-core/ports/clipboard-osc52.js.map +1 -1
  1822. package/dist/ui-core/ports/pager-export-port.js +0 -2
  1823. package/dist/ui-core/ports/pager-export-port.js.map +1 -1
  1824. package/dist/ui-core/ports/renderer-port.d.ts +0 -6
  1825. package/dist/ui-core/react/providers.d.ts +0 -7
  1826. package/dist/ui-core/react/providers.js +0 -7
  1827. package/dist/ui-core/react/providers.js.map +1 -1
  1828. package/dist/ui-core/react/use-has-draft.d.ts +0 -5
  1829. package/dist/ui-core/react/use-has-draft.js +0 -5
  1830. package/dist/ui-core/react/use-has-draft.js.map +1 -1
  1831. package/dist/ui-core/react/use-overlay.d.ts +0 -1
  1832. package/dist/ui-core/react/use-overlay.js +0 -1
  1833. package/dist/ui-core/react/use-overlay.js.map +1 -1
  1834. package/dist/ui-core/react/use-plan.d.ts +0 -1
  1835. package/dist/ui-core/react/use-plan.js +0 -1
  1836. package/dist/ui-core/react/use-plan.js.map +1 -1
  1837. package/dist/ui-core/react/use-toast.d.ts +0 -1
  1838. package/dist/ui-core/react/use-toast.js +0 -3
  1839. package/dist/ui-core/react/use-toast.js.map +1 -1
  1840. package/dist/ui-core/react/use-transcript-store.d.ts +0 -7
  1841. package/dist/ui-core/react/use-transcript-store.js +0 -7
  1842. package/dist/ui-core/react/use-transcript-store.js.map +1 -1
  1843. package/dist/ui-core/rendering/artifact-pager-source.d.ts +0 -7
  1844. package/dist/ui-core/rendering/artifact-pager-source.js +0 -3
  1845. package/dist/ui-core/rendering/artifact-pager-source.js.map +1 -1
  1846. package/dist/ui-core/rendering/batch-sections.d.ts +0 -38
  1847. package/dist/ui-core/rendering/batch-sections.js +1 -47
  1848. package/dist/ui-core/rendering/batch-sections.js.map +1 -1
  1849. package/dist/ui-core/rendering/code-block.d.ts +0 -25
  1850. package/dist/ui-core/rendering/code-block.js +0 -47
  1851. package/dist/ui-core/rendering/code-block.js.map +1 -1
  1852. package/dist/ui-core/rendering/context-limit.js +0 -2
  1853. package/dist/ui-core/rendering/context-limit.js.map +1 -1
  1854. package/dist/ui-core/rendering/duration.js +0 -3
  1855. package/dist/ui-core/rendering/duration.js.map +1 -1
  1856. package/dist/ui-core/rendering/exit-summary/table.d.ts +23 -0
  1857. package/dist/ui-core/rendering/exit-summary/table.js +194 -0
  1858. package/dist/ui-core/rendering/exit-summary/table.js.map +1 -0
  1859. package/dist/ui-core/rendering/exit-summary.js +1 -210
  1860. package/dist/ui-core/rendering/exit-summary.js.map +1 -1
  1861. package/dist/ui-core/rendering/file-diff-view.d.ts +0 -27
  1862. package/dist/ui-core/rendering/file-diff-view.js +0 -29
  1863. package/dist/ui-core/rendering/file-diff-view.js.map +1 -1
  1864. package/dist/ui-core/rendering/format-help.d.ts +0 -13
  1865. package/dist/ui-core/rendering/format-help.js +0 -18
  1866. package/dist/ui-core/rendering/format-help.js.map +1 -1
  1867. package/dist/ui-core/rendering/format-keys.js +0 -2
  1868. package/dist/ui-core/rendering/format-keys.js.map +1 -1
  1869. package/dist/ui-core/rendering/format-usage.js +18 -5
  1870. package/dist/ui-core/rendering/format-usage.js.map +1 -1
  1871. package/dist/ui-core/rendering/incremental-strip.js +0 -13
  1872. package/dist/ui-core/rendering/incremental-strip.js.map +1 -1
  1873. package/dist/ui-core/rendering/intro-header.js +0 -1
  1874. package/dist/ui-core/rendering/intro-header.js.map +1 -1
  1875. package/dist/ui-core/rendering/job-tail-source.d.ts +0 -9
  1876. package/dist/ui-core/rendering/job-tail-source.js +0 -9
  1877. package/dist/ui-core/rendering/job-tail-source.js.map +1 -1
  1878. package/dist/ui-core/rendering/link-detector.d.ts +0 -8
  1879. package/dist/ui-core/rendering/link-detector.js +0 -10
  1880. package/dist/ui-core/rendering/link-detector.js.map +1 -1
  1881. package/dist/ui-core/rendering/markdown/tables.d.ts +8 -0
  1882. package/dist/ui-core/rendering/markdown/tables.js +276 -0
  1883. package/dist/ui-core/rendering/markdown/tables.js.map +1 -0
  1884. package/dist/ui-core/rendering/markdown.d.ts +4 -9
  1885. package/dist/ui-core/rendering/markdown.js +224 -593
  1886. package/dist/ui-core/rendering/markdown.js.map +1 -1
  1887. package/dist/ui-core/rendering/open-tool-output.d.ts +0 -30
  1888. package/dist/ui-core/rendering/open-tool-output.js +0 -39
  1889. package/dist/ui-core/rendering/open-tool-output.js.map +1 -1
  1890. package/dist/ui-core/rendering/pager-chrome.d.ts +0 -20
  1891. package/dist/ui-core/rendering/pager-chrome.js +0 -24
  1892. package/dist/ui-core/rendering/pager-chrome.js.map +1 -1
  1893. package/dist/ui-core/rendering/pager-source.d.ts +0 -17
  1894. package/dist/ui-core/rendering/pager-source.js +0 -27
  1895. package/dist/ui-core/rendering/pager-source.js.map +1 -1
  1896. package/dist/ui-core/rendering/pager-text.d.ts +0 -21
  1897. package/dist/ui-core/rendering/pager-text.js +0 -31
  1898. package/dist/ui-core/rendering/pager-text.js.map +1 -1
  1899. package/dist/ui-core/rendering/pager-view-policy.d.ts +0 -24
  1900. package/dist/ui-core/rendering/pager-view-policy.js +0 -31
  1901. package/dist/ui-core/rendering/pager-view-policy.js.map +1 -1
  1902. package/dist/ui-core/rendering/picker-filter.d.ts +0 -11
  1903. package/dist/ui-core/rendering/picker-filter.js +0 -11
  1904. package/dist/ui-core/rendering/picker-filter.js.map +1 -1
  1905. package/dist/ui-core/rendering/plan-view.d.ts +0 -39
  1906. package/dist/ui-core/rendering/plan-view.js +0 -37
  1907. package/dist/ui-core/rendering/plan-view.js.map +1 -1
  1908. package/dist/ui-core/rendering/prompt-preview.d.ts +0 -5
  1909. package/dist/ui-core/rendering/prompt-preview.js +0 -5
  1910. package/dist/ui-core/rendering/prompt-preview.js.map +1 -1
  1911. package/dist/ui-core/rendering/sanitize-display.d.ts +0 -10
  1912. package/dist/ui-core/rendering/sanitize-display.js +0 -14
  1913. package/dist/ui-core/rendering/sanitize-display.js.map +1 -1
  1914. package/dist/ui-core/rendering/status-segments.js +3 -3
  1915. package/dist/ui-core/rendering/status-segments.js.map +1 -1
  1916. package/dist/ui-core/rendering/streaming-markdown.js +0 -11
  1917. package/dist/ui-core/rendering/streaming-markdown.js.map +1 -1
  1918. package/dist/ui-core/rendering/syntax/clike.d.ts +22 -0
  1919. package/dist/ui-core/rendering/syntax/clike.js +168 -0
  1920. package/dist/ui-core/rendering/syntax/clike.js.map +1 -0
  1921. package/dist/ui-core/rendering/syntax/keywords.d.ts +24 -0
  1922. package/dist/ui-core/rendering/syntax/keywords.js +169 -0
  1923. package/dist/ui-core/rendering/syntax/keywords.js.map +1 -0
  1924. package/dist/ui-core/rendering/syntax/language-highlighters.d.ts +18 -0
  1925. package/dist/ui-core/rendering/syntax/language-highlighters.js +538 -0
  1926. package/dist/ui-core/rendering/syntax/language-highlighters.js.map +1 -0
  1927. package/dist/ui-core/rendering/syntax/language-table.d.ts +3 -0
  1928. package/dist/ui-core/rendering/syntax/language-table.js +244 -0
  1929. package/dist/ui-core/rendering/syntax/language-table.js.map +1 -0
  1930. package/dist/ui-core/rendering/syntax-highlight.d.ts +6 -28
  1931. package/dist/ui-core/rendering/syntax-highlight.js +5 -1177
  1932. package/dist/ui-core/rendering/syntax-highlight.js.map +1 -1
  1933. package/dist/ui-core/rendering/text-format.d.ts +0 -3
  1934. package/dist/ui-core/rendering/text-format.js +0 -3
  1935. package/dist/ui-core/rendering/text-format.js.map +1 -1
  1936. package/dist/ui-core/rendering/text-width.d.ts +0 -26
  1937. package/dist/ui-core/rendering/text-width.js +0 -26
  1938. package/dist/ui-core/rendering/text-width.js.map +1 -1
  1939. package/dist/ui-core/rendering/theme.d.ts +0 -65
  1940. package/dist/ui-core/rendering/theme.js +0 -24
  1941. package/dist/ui-core/rendering/theme.js.map +1 -1
  1942. package/dist/ui-core/rendering/thinking-tail.js +0 -3
  1943. package/dist/ui-core/rendering/thinking-tail.js.map +1 -1
  1944. package/dist/ui-core/rendering/tool-presenter.d.ts +0 -41
  1945. package/dist/ui-core/rendering/tool-presenter.js +1 -67
  1946. package/dist/ui-core/rendering/tool-presenter.js.map +1 -1
  1947. package/dist/ui-core/rendering/transcript-semantic.d.ts +0 -8
  1948. package/dist/ui-core/rendering/transcript-semantic.js +0 -13
  1949. package/dist/ui-core/rendering/transcript-semantic.js.map +1 -1
  1950. package/dist/ui-core/rendering/user-message-wrap.d.ts +0 -16
  1951. package/dist/ui-core/rendering/user-message-wrap.js +0 -16
  1952. package/dist/ui-core/rendering/user-message-wrap.js.map +1 -1
  1953. package/dist/ui-core/rendering/wordmark.d.ts +0 -8
  1954. package/dist/ui-core/rendering/wordmark.js +0 -21
  1955. package/dist/ui-core/rendering/wordmark.js.map +1 -1
  1956. package/dist/ui-core/state/hydrate/classic-transcript.d.ts +8 -0
  1957. package/dist/ui-core/state/hydrate/classic-transcript.js +168 -0
  1958. package/dist/ui-core/state/hydrate/classic-transcript.js.map +1 -0
  1959. package/dist/ui-core/state/hydrate/from-messages.d.ts +6 -0
  1960. package/dist/ui-core/state/hydrate/from-messages.js +237 -0
  1961. package/dist/ui-core/state/hydrate/from-messages.js.map +1 -0
  1962. package/dist/ui-core/state/pager-search.d.ts +0 -9
  1963. package/dist/ui-core/state/pager-search.js +1 -8
  1964. package/dist/ui-core/state/pager-search.js.map +1 -1
  1965. package/dist/ui-core/state/semantic-document.d.ts +0 -8
  1966. package/dist/ui-core/state/semantic-document.js +0 -8
  1967. package/dist/ui-core/state/semantic-document.js.map +1 -1
  1968. package/dist/ui-core/state/thinking-copy.d.ts +0 -8
  1969. package/dist/ui-core/state/thinking-copy.js +0 -8
  1970. package/dist/ui-core/state/thinking-copy.js.map +1 -1
  1971. package/dist/ui-core/state/transcript/apply-app-event.d.ts +8 -0
  1972. package/dist/ui-core/state/transcript/apply-app-event.js +406 -0
  1973. package/dist/ui-core/state/transcript/apply-app-event.js.map +1 -0
  1974. package/dist/ui-core/state/transcript/message-lifecycle.d.ts +7 -0
  1975. package/dist/ui-core/state/transcript/message-lifecycle.js +285 -0
  1976. package/dist/ui-core/state/transcript/message-lifecycle.js.map +1 -0
  1977. package/dist/ui-core/state/transcript-compaction.d.ts +0 -19
  1978. package/dist/ui-core/state/transcript-compaction.js +0 -21
  1979. package/dist/ui-core/state/transcript-compaction.js.map +1 -1
  1980. package/dist/ui-core/state/transcript-hydrate.d.ts +6 -52
  1981. package/dist/ui-core/state/transcript-hydrate.js +5 -470
  1982. package/dist/ui-core/state/transcript-hydrate.js.map +1 -1
  1983. package/dist/ui-core/state/transcript-reducer.d.ts +1 -15
  1984. package/dist/ui-core/state/transcript-reducer.js +1 -708
  1985. package/dist/ui-core/state/transcript-reducer.js.map +1 -1
  1986. package/dist/ui-core/state/transcript-search.d.ts +0 -8
  1987. package/dist/ui-core/state/transcript-search.js +0 -8
  1988. package/dist/ui-core/state/transcript-search.js.map +1 -1
  1989. package/dist/ui-core/state/transcript-store.d.ts +0 -26
  1990. package/dist/ui-core/state/transcript-store.js +0 -28
  1991. package/dist/ui-core/state/transcript-store.js.map +1 -1
  1992. package/dist/ui-core/state/transcript-types.d.ts +0 -33
  1993. package/dist/ui-core/state/transcript-types.js +0 -17
  1994. package/dist/ui-core/state/transcript-types.js.map +1 -1
  1995. package/dist/ui-core/state/transcript-window.d.ts +0 -8
  1996. package/dist/ui-core/state/transcript-window.js +0 -8
  1997. package/dist/ui-core/state/transcript-window.js.map +1 -1
  1998. package/dist/version.generated.d.ts +2 -2
  1999. package/dist/version.generated.js +2 -2
  2000. package/package.json +19 -2
  2001. package/dist/agent/finalize-gate.d.ts +0 -54
  2002. package/dist/agent/finalize-gate.js +0 -97
  2003. package/dist/agent/finalize-gate.js.map +0 -1
  2004. package/dist/agent/must-continue.d.ts +0 -36
  2005. package/dist/agent/must-continue.js +0 -172
  2006. package/dist/agent/must-continue.js.map +0 -1
package/dist/llm/http.js CHANGED
@@ -1,21 +1,21 @@
1
- import { cacheAffinityKey } from "./cache-affinity.js";
2
- import { modelAcceptsImages, modelSupportsThinking, isReasoningUnsupported, modelReasoningEfforts, learnModelEmitsReasoning, registerModelCatalog, } from "./capabilities.js";
3
- import { catalogEffortList, catalogEntriesFromPayload, parseCatalogFacts, } from "./catalog-facts.js";
4
- import { resolveSampling } from "./sampling.js";
5
- import { accumulateOpenAiToolCallDelta, finalizeOpenAiToolCalls, fromWireName, parseOpenAiMessageToolCalls, } from "./tool-protocol.js";
6
- import { openAiToolBodyFields, toOpenAiToolMessages, } from "./adapters/openai-tools.js";
7
- import { parseFireworksUsage, parseOpenAiUsage, withReasoningObservation, } from "./token-usage.js";
8
- import { generationFetch } from "./operation-usage.js";
9
- import { isOperationPolicyError } from "./operation-ledger.js";
10
- import { emitStreamReasoningArtifacts, emitStreamReasoningDelta, } from "./stream-events.js";
11
- import { CHAT_COMPLETIONS_STREAM_TERMINAL, requireTerminalProof, } from "./stream-terminal.js";
12
- import { modelMaxOutputTokens } from "./context-windows.js";
13
- import { inBandBadRequestStatus, isMissingReasoningContentError, } from "./reasoning-errors.js";
14
- import { emitReasoningControls, } from "./reasoning-controls.js";
15
- import { createReasoningArtifact, createReasoningArtifactProvenance, reasoningArtifactsObserved, visibleReasoningDetailText, } from "./reasoning-artifacts.js";
16
- import { classifyBynaraModel, classifyNvidiaModel, } from "./model-families.js";
17
- import { compileRequestPlan, } from "./request-plan.js";
18
- import { singleLeadingSystemMessages } from "./system-messages.js";
1
+ import { readJson } from "./wire/response-errors.js";
2
+ import { DEFAULT_STREAM_IDLE_TIMEOUT_MS, STREAM_STALL_MARKER, THINKING_STREAM_IDLE_TIMEOUT_MS, THINKING_STREAM_INITIAL_IDLE_TIMEOUT_MS, createSseFrameAssembler, } from "./wire/stream-framing.js";
3
+ import { buildReasoningPayload, } from "./wire/reasoning-payload.js";
4
+ import { chatCompletionsBodyFromPlan } from "./wire/chat-body.js";
5
+ import { compatibleArtifactPolicyFor, } from "./wire/reasoning-artifacts.js";
6
+ export { openAiCompatibleStream } from "./wire/openai-stream.js";
7
+ export { openAiCompatibleComplete, openAiCompatiblePing, } from "./wire/openai-complete.js";
8
+ export { catalogEntryVision, ingestModelCatalogEntries, ingestOpenAiModelCatalog, } from "./wire/model-catalog.js";
9
+ export { toCompletionResult } from "./wire/reasoning-artifacts.js";
10
+ export { compatibleArtifactPolicyFor };
11
+ export { buildChatBody, isOpenAiReasoningModel, toOpenAiMessages, } from "./wire/chat-body.js";
12
+ export { chatCompletionsBodyFromPlan };
13
+ export { imageCapableMessages, isImageInputUnsupportedError, isReasoningUnsupportedError, isStreamOptionsUnsupportedError, reasoningRejectionAdvice, stripImagesFromMessages, } from "./wire/capability-errors.js";
14
+ export { buildReasoningPayload };
15
+ export { readStreamLines, streamIdleBudgets } from "./wire/stream-framing.js";
16
+ export { DEFAULT_STREAM_IDLE_TIMEOUT_MS, STREAM_STALL_MARKER, THINKING_STREAM_IDLE_TIMEOUT_MS, THINKING_STREAM_INITIAL_IDLE_TIMEOUT_MS, createSseFrameAssembler, };
17
+ export { MAX_ERROR_BODY_CHARS, MAX_ERROR_BODY_IN_MESSAGE_CHARS, bodyAddsInformation, collapseWhitespace, } from "./wire/response-errors.js";
18
+ export { readJson };
19
19
  export class ProviderError extends Error {
20
20
  status;
21
21
  body;
@@ -28,2007 +28,5 @@ export class ProviderError extends Error {
28
28
  this.name = "ProviderError";
29
29
  }
30
30
  }
31
- const USAGE_INPUT_KEYS = [
32
- "prompt_tokens",
33
- "promptTokens",
34
- "input_tokens",
35
- "inputTokens",
36
- ];
37
- const USAGE_OUTPUT_KEYS = [
38
- "completion_tokens",
39
- "completionTokens",
40
- "output_tokens",
41
- "outputTokens",
42
- ];
43
- function isFinalUsageFrame(parsed) {
44
- if (Array.isArray(parsed.choices) && parsed.choices.length > 0)
45
- return false;
46
- const usage = parsed.usage;
47
- if (!usage || typeof usage !== "object" || Array.isArray(usage))
48
- return false;
49
- const raw = usage;
50
- const reported = (keys) => keys.some((key) => {
51
- const value = raw[key];
52
- return typeof value === "number" && Number.isFinite(value);
53
- });
54
- return reported(USAGE_INPUT_KEYS) && reported(USAGE_OUTPUT_KEYS);
55
- }
56
- function parseRetryAfterHeader(value) {
57
- if (!value)
58
- return undefined;
59
- const seconds = Number.parseFloat(value);
60
- if (Number.isFinite(seconds) && seconds >= 0)
61
- return seconds;
62
- // HTTP-date form: "Wed, 21 Oct 2015 07:28:00 GMT"
63
- const date = Date.parse(value);
64
- if (Number.isFinite(date)) {
65
- const diff = (date - Date.now()) / 1000;
66
- if (diff > 0)
67
- return diff;
68
- }
69
- return undefined;
70
- }
71
- function parseRetryHintFromBody(text) {
72
- const match = text.match(/try again in\s+([0-9.]+)\s*s/i);
73
- if (match) {
74
- const seconds = Number.parseFloat(match[1]);
75
- if (Number.isFinite(seconds) && seconds >= 0)
76
- return seconds;
77
- }
78
- return undefined;
79
- }
80
- function statusCodeHint(status) {
81
- if (status === 401) {
82
- return " — check that the API key is valid (run `clai providers` to inspect)";
83
- }
84
- if (status === 403) {
85
- return " — the key was rejected (insufficient permissions, billing, or region restriction)";
86
- }
87
- if (status === 404) {
88
- return " — endpoint or model not found (try `/model list` to see supported names)";
89
- }
90
- if (status === 422) {
91
- return " — the provider rejected the request body (model name or parameter mismatch)";
92
- }
93
- if (status === 413) {
94
- return " — request exceeded the provider input limit; retry with a compact prompt or pick another model";
95
- }
96
- if (status >= 500 && status < 600) {
97
- return " — upstream provider error; try again or switch with `/provider`";
98
- }
99
- return "";
100
- }
101
- export function catalogEntryVision(entry) {
102
- return parseCatalogFacts(entry)?.vision;
103
- }
104
- export function ingestModelCatalogEntries(provider, entries) {
105
- const models = [];
106
- const seen = new Set();
107
- for (const entry of entries) {
108
- const facts = parseCatalogFacts(entry);
109
- if (!facts)
110
- continue;
111
- const id = facts.id;
112
- if (seen.has(id))
113
- continue;
114
- seen.add(id);
115
- const reasoning = facts.reasoning?.supported;
116
- const reasoningEfforts = catalogEffortList(facts.reasoning?.supportedEfforts);
117
- models.push({
118
- id,
119
- facts,
120
- ...(facts.vision === undefined ? {} : { vision: facts.vision }),
121
- ...(reasoning === undefined ? {} : { reasoning }),
122
- ...(reasoningEfforts === undefined ? {} : { reasoningEfforts }),
123
- });
124
- }
125
- if (models.length > 0)
126
- registerModelCatalog(provider, models);
127
- return models.map((model) => model.id).sort();
128
- }
129
- export function ingestOpenAiModelCatalog(provider, payload) {
130
- return ingestModelCatalogEntries(provider, catalogEntriesFromPayload(payload));
131
- }
132
- export async function readJson(response, signal) {
133
- const text = await readBodyCapped(response, MAX_JSON_RESPONSE_BYTES, signal);
134
- if (!response.ok) {
135
- let detail = "";
136
- let extractedMessage = "";
137
- try {
138
- const body = JSON.parse(text);
139
- const error = body.error;
140
- let msg = "";
141
- if (typeof error === "string") {
142
- msg = error;
143
- }
144
- else if (error && typeof error === "object") {
145
- const errObj = error;
146
- msg = errObj.message ?? "";
147
- if (!msg && (errObj.type || errObj.code)) {
148
- msg = errObj.type ?? errObj.code ?? "";
149
- }
150
- }
151
- if (!msg) {
152
- msg =
153
- body.message ??
154
- body.detail ??
155
- "";
156
- }
157
- if (msg) {
158
- // Detect NVIDIA DEGRADED function errors and enrich the message.
159
- if (/DEGRADED/i.test(msg)) {
160
- detail = ` — ${msg} (model is temporarily unavailable on this provider; try a different model with \`/model\`)`;
161
- }
162
- else {
163
- detail = ` — ${msg}`;
164
- }
165
- }
166
- extractedMessage = msg;
167
- }
168
- catch {
169
- // Non-JSON body — the raw text is surfaced via the full-response rule
170
- // below, so nothing is lost here.
171
- }
172
- // Show the full error received from the request: the extracted
173
- // `error.message` alone routinely hides the actionable part of a gateway
174
- // error (upstream detail, codes, validation fields). Append the complete
175
- // body whenever it carries anything beyond that extracted message.
176
- const bodyText = text.slice(0, MAX_ERROR_BODY_CHARS);
177
- if (bodyAddsInformation(bodyText, extractedMessage)) {
178
- const shown = collapseWhitespace(bodyText);
179
- const capped = shown.length > MAX_ERROR_BODY_IN_MESSAGE_CHARS
180
- ? `${shown.slice(0, MAX_ERROR_BODY_IN_MESSAGE_CHARS)}…`
181
- : shown;
182
- detail = `${detail} — full response: ${capped}`;
183
- }
184
- const retryAfterSeconds = parseRetryAfterHeader(response.headers.get("retry-after")) ??
185
- parseRetryHintFromBody(text);
186
- const retryHint = retryAfterSeconds !== undefined
187
- ? ` (retry after ${Math.ceil(retryAfterSeconds)}s)`
188
- : "";
189
- const codeHint = statusCodeHint(response.status);
190
- throw new ProviderError(`Provider request failed with HTTP ${response.status}${retryHint}${detail}${codeHint}`, response.status, bodyText, retryAfterSeconds);
191
- }
192
- return JSON.parse(text);
193
- }
194
- /** Hard cap on a JSON response body so a misbehaving provider can't OOM us. */
195
- const MAX_JSON_RESPONSE_BYTES = 4 * 1024 * 1024;
196
- /** How much of a provider error body we retain on the ProviderError. */
197
- export const MAX_ERROR_BODY_CHARS = 8_000;
198
- /** How much of that body is embedded in the user-visible error message. */
199
- export const MAX_ERROR_BODY_IN_MESSAGE_CHARS = 2_000;
200
- export function collapseWhitespace(text) {
201
- return text.replace(/\s+/g, " ").trim();
202
- }
203
- /**
204
- * True when the raw response body carries information beyond the message we
205
- * already extracted from it (extra JSON fields, non-JSON payloads, …). Pure
206
- * `{"error":{"message": …}}` envelopes are redundant and stay compact.
207
- */
208
- export function bodyAddsInformation(bodyText, extracted) {
209
- const collapsed = collapseWhitespace(bodyText);
210
- if (!collapsed)
211
- return false;
212
- if (!extracted)
213
- return true;
214
- const normalizedExtracted = collapseWhitespace(extracted);
215
- // The user-facing text already carries the entire body verbatim.
216
- if (normalizedExtracted.includes(collapsed))
217
- return false;
218
- if (!collapsed.includes(normalizedExtracted))
219
- return true;
220
- const rest = collapsed
221
- .replace(normalizedExtracted, " ")
222
- .replace(/\b(errors?|message|msg|detail|details|type|code|status)\b/gi, " ")
223
- .replace(/[{}\[\]":,]/g, " ")
224
- .trim();
225
- return rest.length > 0;
226
- }
227
- async function readBodyCapped(response, maxBytes, signal) {
228
- const reader = response.body?.getReader();
229
- if (!reader) {
230
- if (signal?.aborted) {
231
- throw signal.reason ?? new Error("Response body read aborted");
232
- }
233
- const text = await response.text();
234
- return text.length > maxBytes ? text.slice(0, maxBytes) : text;
235
- }
236
- const decoder = new TextDecoder("utf-8", { fatal: false });
237
- let collected = "";
238
- let bytesRead = 0;
239
- const cancelOnAbort = () => {
240
- void reader.cancel(signal?.reason).catch(() => undefined);
241
- };
242
- signal?.addEventListener("abort", cancelOnAbort, { once: true });
243
- try {
244
- while (bytesRead < maxBytes) {
245
- const { done, value } = signal
246
- ? await readWithAbort(reader, signal)
247
- : await reader.read();
248
- if (signal?.aborted) {
249
- throw signal.reason ?? new Error("Response body read aborted");
250
- }
251
- if (done)
252
- break;
253
- if (!value)
254
- continue;
255
- const remaining = maxBytes - bytesRead;
256
- if (value.byteLength > remaining) {
257
- collected += decoder.decode(value.subarray(0, remaining), {
258
- stream: true,
259
- });
260
- bytesRead += remaining;
261
- try {
262
- await reader.cancel();
263
- }
264
- catch {
265
- // ignore — we're abandoning the body deliberately
266
- }
267
- break;
268
- }
269
- collected += decoder.decode(value, { stream: true });
270
- bytesRead += value.byteLength;
271
- }
272
- collected += decoder.decode();
273
- }
274
- finally {
275
- signal?.removeEventListener("abort", cancelOnAbort);
276
- try {
277
- reader.releaseLock();
278
- }
279
- catch {
280
- // already released
281
- }
282
- }
283
- return collected;
284
- }
285
- /**
286
- * Mid-stream silence budget.
287
- *
288
- * This is deliberately generous because "no bytes" does **not** mean "dead
289
- * socket" on an OpenAI-compatible endpoint. Most self-hosted runtimes (vLLM /
290
- * SGLang and the tool-call parsers layered on top of them) buffer an entire
291
- * `tool_calls` delta before emitting it, so a model writing a large file goes
292
- * completely silent on the wire for as long as the generation takes. A 90s
293
- * budget aborted those healthy streams at `firstToken + 90s`, reported the
294
- * abort as a network failure, and burned three identical retries that each
295
- * re-generated the same prefix before one happened to finish inside the window.
296
- */
297
- export const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 240_000;
298
- export const THINKING_STREAM_IDLE_TIMEOUT_MS = 900_000;
299
- export const THINKING_STREAM_INITIAL_IDLE_TIMEOUT_MS = 900_000;
300
- export function streamIdleBudgets(reasoningEnabled) {
301
- const idleTimeoutMs = reasoningEnabled
302
- ? THINKING_STREAM_IDLE_TIMEOUT_MS
303
- : DEFAULT_STREAM_IDLE_TIMEOUT_MS;
304
- return {
305
- idleTimeoutMs,
306
- outputIdleTimeoutMs: Math.round(idleTimeoutMs * 1.5),
307
- };
308
- }
309
- /**
310
- * Marker appended to the message of a stall that happened on a **live**
311
- * connection (bytes/keepalives were still arriving, or output had already
312
- * started and simply stopped). Such a stall is not a transport failure, so the
313
- * recovery layer must not classify it as `network` and retry the identical
314
- * request against the identical route.
315
- */
316
- export const STREAM_STALL_MARKER = "no model output";
317
- function readWithAbort(reader, signal) {
318
- if (signal.aborted) {
319
- return Promise.reject(signal.reason ?? new Error("Stream aborted"));
320
- }
321
- return new Promise((resolve, reject) => {
322
- let settled = false;
323
- const cleanup = () => signal.removeEventListener("abort", abort);
324
- const succeed = (value) => {
325
- if (settled)
326
- return;
327
- settled = true;
328
- cleanup();
329
- resolve(value);
330
- };
331
- const fail = (error) => {
332
- if (settled)
333
- return;
334
- settled = true;
335
- cleanup();
336
- reject(error);
337
- };
338
- const abort = () => {
339
- fail(signal.reason ?? new Error("Stream aborted"));
340
- };
341
- signal.addEventListener("abort", abort, { once: true });
342
- try {
343
- void reader.read().then(succeed, fail);
344
- }
345
- catch (error) {
346
- fail(error);
347
- }
348
- });
349
- }
350
- export async function* readStreamLines(response, options = {}) {
351
- if (!response.body)
352
- return;
353
- const idleTimeoutMs = options.idleTimeoutMs ?? DEFAULT_STREAM_IDLE_TIMEOUT_MS;
354
- const outputIdleTimeoutMs = options.outputIdleTimeoutMs ?? Math.round(idleTimeoutMs * 1.5);
355
- const trackOutput = typeof options.outputProgress === "function";
356
- const maxBytes = options.maxBytes ?? 16 * 1024 * 1024;
357
- const idleController = new AbortController();
358
- let idleTimer;
359
- let outputTimer;
360
- let idleFired = false;
361
- let firedWatchdog = "transport";
362
- let lastOutputProgress = trackOutput ? options.outputProgress() : 0;
363
- const fireStall = (watchdog) => {
364
- if (idleFired)
365
- return;
366
- idleFired = true;
367
- firedWatchdog = watchdog;
368
- idleController.abort();
369
- };
370
- const clearIdleTimers = () => {
371
- if (idleTimer)
372
- clearTimeout(idleTimer);
373
- if (outputTimer)
374
- clearTimeout(outputTimer);
375
- idleTimer = undefined;
376
- outputTimer = undefined;
377
- };
378
- const armOutputTimer = () => {
379
- if (!trackOutput)
380
- return;
381
- if (outputTimer)
382
- clearTimeout(outputTimer);
383
- outputTimer = setTimeout(() => fireStall("output"), outputIdleTimeoutMs);
384
- };
385
- const resetIdleTimer = () => {
386
- if (idleTimer)
387
- clearTimeout(idleTimer);
388
- idleTimer = setTimeout(() => fireStall("transport"), idleTimeoutMs);
389
- };
390
- const noteOutputProgress = () => {
391
- if (!trackOutput)
392
- return;
393
- const current = options.outputProgress();
394
- if (current <= lastOutputProgress)
395
- return;
396
- lastOutputProgress = current;
397
- armOutputTimer();
398
- };
399
- const stallError = () => firedWatchdog === "output"
400
- ? new ProviderError(`Provider stream stalled — ${STREAM_STALL_MARKER} for ${Math.round(outputIdleTimeoutMs / 1000)}s.`)
401
- : new ProviderError(`Provider stream stalled — no data for ${Math.round(idleTimeoutMs / 1000)}s.`);
402
- resetIdleTimer();
403
- armOutputTimer();
404
- const onCallerAbort = () => idleController.abort(options.signal?.reason);
405
- options.signal?.addEventListener("abort", onCallerAbort, { once: true });
406
- // A caller abort must surface as an abort error, not as a clean
407
- // end-of-stream — otherwise the partial text is returned as a successful
408
- // completion and enters history as the model's final answer.
409
- const callerAbortError = () => options.signal?.reason ??
410
- new DOMException("The operation was aborted.", "AbortError");
411
- if (options.signal?.aborted) {
412
- clearIdleTimers();
413
- throw callerAbortError();
414
- }
415
- // If the idle watchdog already fired, bail before starting the loop.
416
- if (idleController.signal.aborted) {
417
- clearIdleTimers();
418
- return;
419
- }
420
- const reader = response.body.getReader();
421
- const decoder = new TextDecoder();
422
- let buffer = "";
423
- let bytesRead = 0;
424
- const cancelReaderOnAbort = () => {
425
- reader.cancel().catch(() => undefined);
426
- };
427
- idleController.signal.addEventListener("abort", cancelReaderOnAbort, {
428
- once: true,
429
- });
430
- try {
431
- while (true) {
432
- noteOutputProgress();
433
- if (idleController.signal.aborted) {
434
- if (idleFired)
435
- throw stallError();
436
- throw callerAbortError();
437
- }
438
- let readResult;
439
- try {
440
- readResult = await readWithAbort(reader, idleController.signal);
441
- }
442
- catch (error) {
443
- if (idleFired)
444
- throw stallError();
445
- throw error;
446
- }
447
- const { done, value } = readResult;
448
- if (done) {
449
- if (idleFired)
450
- throw stallError();
451
- break;
452
- }
453
- if (value) {
454
- bytesRead += value.byteLength;
455
- if (bytesRead > maxBytes) {
456
- throw new ProviderError(`Provider stream exceeded ${maxBytes.toLocaleString()} bytes — aborting.`);
457
- }
458
- }
459
- resetIdleTimer();
460
- options.onActivity?.();
461
- buffer += decoder.decode(value, { stream: true });
462
- const lines = buffer.split("\n");
463
- buffer = lines.pop() ?? "";
464
- for (const line of lines)
465
- yield line;
466
- }
467
- if (buffer.length > 0)
468
- yield buffer;
469
- }
470
- finally {
471
- clearIdleTimers();
472
- options.signal?.removeEventListener("abort", onCallerAbort);
473
- idleController.signal.removeEventListener("abort", cancelReaderOnAbort);
474
- void reader.cancel().catch(() => undefined);
475
- try {
476
- reader.releaseLock();
477
- }
478
- catch {
479
- // already released
480
- }
481
- }
482
- }
483
- const DEFAULT_COMPATIBLE_REASONING_ARTIFACT_POLICY = {
484
- scope: "all-history",
485
- persistence: "tool-turn",
486
- };
487
- const PRESERVED_FINAL_TURN_ARTIFACT_POLICY = {
488
- scope: "all-history",
489
- persistence: "all-turns",
490
- };
491
- export function compatibleArtifactPolicyFor(preservation) {
492
- return preservation === "required"
493
- ? PRESERVED_FINAL_TURN_ARTIFACT_POLICY
494
- : DEFAULT_COMPATIBLE_REASONING_ARTIFACT_POLICY;
495
- }
496
- function artifactRaw(value) {
497
- if (typeof value === "string")
498
- return value;
499
- if (Array.isArray(value))
500
- return value;
501
- if (value && typeof value === "object") {
502
- return value;
503
- }
504
- return undefined;
505
- }
506
- /**
507
- * Reads the reasoning text off an OpenAI-compatible `message`/`delta`.
508
- *
509
- * Most routes use `reasoning_content` (DeepSeek/vLLM style) or `reasoning`
510
- * (OpenRouter style). Merge Gateway normalizes every upstream vendor onto a
511
- * third field, `thinking` (+ `thinking_signature`), on both its
512
- * chat.completion messages and its chat.completion.chunk deltas — verified live
513
- * against api-gateway.merge.dev/v1/openai for qwen/qwen3.8-max,
514
- * zai/glm-5.3-flash and deepseek/deepseek-v4-flash-0731. Without this branch the
515
- * chain of thought arrives on the wire and is silently dropped, which looks
516
- * exactly like a model that never reasoned.
517
- *
518
- * Only strings are accepted: Anthropic-shaped `thinking` request/response
519
- * objects (`{type:"disabled"}`, content blocks) must not be treated as text.
520
- */
521
- function openAiReasoningText(channel) {
522
- const primary = channel?.reasoning_content ?? channel?.reasoning;
523
- if (typeof primary === "string" && primary)
524
- return primary;
525
- const thinking = channel?.thinking;
526
- return typeof thinking === "string" && thinking ? thinking : undefined;
527
- }
528
- function compatibleReasoningArtifacts(input) {
529
- const policy = input.policy ?? DEFAULT_COMPATIBLE_REASONING_ARTIFACT_POLICY;
530
- const provenance = createReasoningArtifactProvenance({
531
- provider: input.providerId,
532
- model: input.model,
533
- dialect: "openai-compatible",
534
- endpoint: input.baseUrl,
535
- });
536
- const artifacts = [];
537
- const primaryToolPosition = input.toolCalls.length > 0 ? 0 : undefined;
538
- if (input.reasoning?.text) {
539
- artifacts.push(createReasoningArtifact({
540
- kind: "plaintext",
541
- raw: input.reasoning.text,
542
- displaySummary: input.reasoning.text,
543
- provenance,
544
- replay: policy,
545
- position: {
546
- sequence: input.reasoning.sequence,
547
- placement: primaryToolPosition === undefined ? "assistant" : "before-tool-call",
548
- ...(primaryToolPosition === undefined
549
- ? {}
550
- : { toolCallIndex: primaryToolPosition }),
551
- },
552
- }));
553
- }
554
- for (const detail of input.details ?? []) {
555
- const visible = visibleReasoningDetailText(detail.raw);
556
- artifacts.push(createReasoningArtifact({
557
- kind: "structured-details",
558
- raw: detail.raw,
559
- ...(visible ? { displaySummary: visible } : {}),
560
- provenance,
561
- replay: policy,
562
- position: {
563
- sequence: detail.sequence,
564
- placement: primaryToolPosition === undefined ? "assistant" : "before-tool-call",
565
- ...(primaryToolPosition === undefined
566
- ? {}
567
- : { toolCallIndex: primaryToolPosition }),
568
- },
569
- }));
570
- }
571
- for (const signature of input.thoughtSignatures ?? []) {
572
- const toolCallIndex = signature.toolCallIndex;
573
- artifacts.push(createReasoningArtifact({
574
- kind: "thought-signature",
575
- raw: signature.raw,
576
- provenance,
577
- replay: toolCallIndex === undefined
578
- ? { scope: "none", persistence: "never" }
579
- : { scope: "tool-turn", persistence: "tool-turn" },
580
- position: {
581
- sequence: signature.sequence,
582
- placement: toolCallIndex === undefined ? "assistant" : "on-tool-call",
583
- ...(toolCallIndex === undefined ? {} : { toolCallIndex }),
584
- },
585
- }));
586
- }
587
- return artifacts.length ? artifacts : undefined;
588
- }
589
- /** Map shared OpenAI-compatible payload → CompletionResult (includes usage). */
590
- export function toCompletionResult(provider, model, payload) {
591
- const usage = withReasoningObservation(payload.usage, Boolean(payload.reasoningBlock?.text.trim()) ||
592
- reasoningArtifactsObserved(payload.reasoningArtifacts));
593
- return {
594
- text: payload.text,
595
- provider,
596
- model,
597
- ...(payload.toolCalls?.length ? { toolCalls: payload.toolCalls } : {}),
598
- ...(payload.finishReason ? { finishReason: payload.finishReason } : {}),
599
- ...(usage ? { usage } : {}),
600
- ...(payload.reasoningBlock ? { reasoningBlock: payload.reasoningBlock } : {}),
601
- ...(payload.reasoningArtifacts
602
- ? { reasoningArtifacts: payload.reasoningArtifacts }
603
- : {}),
604
- };
605
- }
606
- /**
607
- * Reassembles SSE `data:` frames.
608
- *
609
- * Per the SSE spec a single event's payload may be split across several `data:`
610
- * lines that the client must concatenate before parsing; each fragment was
611
- * previously parsed on its own, failed `JSON.parse`, and was dropped as a
612
- * malformed keepalive — losing content without a trace.
613
- *
614
- * A payload is released as soon as it is syntactically complete, so
615
- * single-line frames behave exactly as before. A blank line (frame terminator)
616
- * discards an incomplete remainder, and a runaway fragment is dropped rather
617
- * than corrupting later frames.
618
- */
619
- export function createSseFrameAssembler(options) {
620
- const maxBufferedBytes = options?.maxBufferedBytes ?? 1_000_000;
621
- let buffered = "";
622
- const complete = (payload) => {
623
- if (payload === "[DONE]")
624
- return true;
625
- try {
626
- JSON.parse(payload);
627
- return true;
628
- }
629
- catch {
630
- return false;
631
- }
632
- };
633
- return {
634
- pushLine(line) {
635
- const trimmed = line.trim();
636
- if (trimmed === "") {
637
- // End of event: an incomplete remainder was malformed.
638
- buffered = "";
639
- return undefined;
640
- }
641
- if (!trimmed.startsWith("data:"))
642
- return undefined;
643
- const chunk = trimmed.slice(5).trim();
644
- buffered = buffered ? `${buffered}\n${chunk}` : chunk;
645
- if (complete(buffered)) {
646
- const payload = buffered;
647
- buffered = "";
648
- return payload;
649
- }
650
- if (buffered.length > maxBufferedBytes)
651
- buffered = "";
652
- return undefined;
653
- },
654
- };
655
- }
656
- export function toOpenAiMessages(messages, supportsVision = true, replay) {
657
- return toOpenAiToolMessages(messages, (message) => {
658
- if (supportsVision &&
659
- message.images &&
660
- message.images.length > 0) {
661
- const parts = [];
662
- if (message.content)
663
- parts.push({ type: "text", text: message.content });
664
- for (const img of message.images) {
665
- parts.push({
666
- type: "image_url",
667
- image_url: {
668
- url: `data:${img.mediaType};base64,${img.dataBase64}`,
669
- detail: "high",
670
- },
671
- });
672
- }
673
- return parts;
674
- }
675
- return message.content;
676
- }, replay);
677
- }
678
- export { classifyBynaraModel, classifyNvidiaModel, } from "./model-families.js";
679
- function supportsOpenRouterReasoning(model) {
680
- return /:thinking|deepseek-r1|qwen3|kimi-k2|claude-(?:opus|sonnet|haiku)-4|gpt-5|(?:^|\/)o[134]|grok.*reasoner/i.test(model);
681
- }
682
- const MODAL_DEFAULT_EFFORTS = ["low", "high", "max"];
683
- const MODAL_EFFORT_PREFERENCE = {
684
- minimal: ["minimal", "low", "medium", "high", "max"],
685
- low: ["low", "minimal", "medium", "high", "max"],
686
- medium: ["medium", "high", "low", "max"],
687
- high: ["high", "max", "medium", "low"],
688
- xhigh: ["xhigh", "max", "high", "medium", "low"],
689
- max: ["max", "xhigh", "high", "medium", "low"],
690
- };
691
- function pickAdvertisedEffort(effort, advertised) {
692
- const order = MODAL_EFFORT_PREFERENCE[effort] ?? MODAL_EFFORT_PREFERENCE.medium;
693
- return (order.find((candidate) => advertised.includes(candidate)) ??
694
- advertised[advertised.length - 1]);
695
- }
696
- export function buildReasoningPayload(reasoning, style, model, providerId, control) {
697
- if (control) {
698
- return {
699
- ...emitReasoningControls({
700
- profile: control.profile,
701
- preference: reasoning,
702
- willReplayReasoning: control.willReplayReasoning,
703
- }),
704
- };
705
- }
706
- if (style === "none")
707
- return {};
708
- const enabled = Boolean(reasoning?.enabled);
709
- const effort = reasoning?.effort ?? "medium";
710
- // Map expanded effort levels to the classic low/medium/high subset for
711
- // providers that only understand the smaller set.
712
- const clampEffort = (e) => {
713
- if (e === "none" || e === "minimal" || e === "low")
714
- return "low";
715
- if (e === "max" || e === "xhigh" || e === "high")
716
- return "high";
717
- return "medium";
718
- };
719
- switch (style) {
720
- case "meta": {
721
- const metaEffort = (e) => {
722
- if (e === "none" || e === "minimal")
723
- return "minimal";
724
- if (e === "max" || e === "xhigh")
725
- return "xhigh";
726
- return e;
727
- };
728
- if (!enabled)
729
- return { reasoning_effort: "minimal" };
730
- return { reasoning_effort: metaEffort(effort) };
731
- }
732
- case "openai": {
733
- if (!enabled) {
734
- return effort === "none" ? { reasoning_effort: "none" } : {};
735
- }
736
- // `reasoning_effort` is the Chat Completions knob. The nested
737
- // `reasoning` object belongs to the Responses API; strict gateways reject
738
- // unknown top-level fields with a hard 400.
739
- return { reasoning_effort: clampEffort(effort) };
740
- }
741
- case "bynara": {
742
- const kind = classifyBynaraModel(model ?? "");
743
- const noThinking = !enabled || effort === "none" || effort === "minimal";
744
- switch (kind) {
745
- case "kimi":
746
- if (noThinking)
747
- return { chat_template_kwargs: { thinking: false } };
748
- if (effort === "high" || effort === "xhigh" || effort === "max") {
749
- return {
750
- chat_template_kwargs: { thinking: true },
751
- reasoning_effort: "high",
752
- };
753
- }
754
- if (effort === "low") {
755
- return {
756
- chat_template_kwargs: { thinking: true },
757
- reasoning_effort: "low",
758
- };
759
- }
760
- return { chat_template_kwargs: { thinking: true } };
761
- case "deepseek":
762
- case "agnes":
763
- if (noThinking)
764
- return { reasoning_effort: "none" };
765
- return { reasoning_effort: clampEffort(effort) };
766
- case "stepfun":
767
- if (noThinking)
768
- return {};
769
- return { reasoning_effort: clampEffort(effort) };
770
- case "none":
771
- return {};
772
- }
773
- return {};
774
- }
775
- case "agentrouter": {
776
- // AgentRouter proxies three families, each with a *different* reasoning
777
- // contract (verified live against agentrouter.org/v1, 2026-07). We send
778
- // only the standard top-level knob each one honours — no redundant
779
- // `reasoning` object (none of the routed models read it).
780
- const m = (model ?? "").toLowerCase();
781
- const clamped = clampEffort(effort);
782
- // OpenAI gpt-5.x / o-series: top-level `reasoning_effort`, and it uniquely
783
- // supports "minimal". These models can't be fully disabled, so "off"
784
- // degrades to the cheapest "minimal" rather than the medium default.
785
- if (/(?:^|\/)gpt-5|(?:^|\/)o[134](?:\b|-)/.test(m)) {
786
- if (!enabled)
787
- return { reasoning_effort: "minimal" };
788
- const gptEffort = effort === "none"
789
- ? "minimal"
790
- : effort === "xhigh" || effort === "max"
791
- ? "high"
792
- : effort; // minimal | low | medium | high
793
- return { reasoning_effort: gptEffort };
794
- }
795
- // Zhipu GLM thinks by DEFAULT; `reasoning_effort` only modulates depth and
796
- // cannot turn it off. The one knob that actually disables it on this
797
- // gateway is `thinking.type=disabled` — so "off" must send that.
798
- if (/glm/.test(m)) {
799
- if (!enabled)
800
- return { thinking: { type: "disabled" } };
801
- return { reasoning_effort: clamped };
802
- }
803
- // Anthropic Claude: `reasoning_effort` enables extended thinking (the
804
- // gateway maps it to a thinking budget). Thinking is OFF by default, so
805
- // "off" simply omits the knob. `buildChatBody` floors max_tokens above the
806
- // budget so enabling it never trips the gateway's budget precondition.
807
- if (/claude/.test(m)) {
808
- if (!enabled)
809
- return {};
810
- return { reasoning_effort: clamped };
811
- }
812
- // Unknown model routed by AgentRouter → plain OpenAI-compatible behavior.
813
- if (!enabled)
814
- return {};
815
- return { reasoning_effort: clamped };
816
- }
817
- case "openrouter":
818
- if (!enabled)
819
- return {};
820
- if (!supportsOpenRouterReasoning(model ?? ""))
821
- return {};
822
- return { reasoning: { enabled: true, effort: clampEffort(effort) } };
823
- case "modal": {
824
- const advertised = providerId !== undefined && model
825
- ? modelReasoningEfforts(providerId, model)
826
- : undefined;
827
- if (!advertised &&
828
- providerId !== undefined &&
829
- model &&
830
- !modelSupportsThinking(providerId, model)) {
831
- return {};
832
- }
833
- if (!enabled || effort === "none")
834
- return { reasoning_effort: "none" };
835
- return {
836
- reasoning_effort: pickAdvertisedEffort(effort, advertised ?? MODAL_DEFAULT_EFFORTS),
837
- };
838
- }
839
- case "stepfun":
840
- // Step 3.5/3.7 Flash enables a <think> block by default on compatible
841
- // hosts. Omitting an OpenAI reasoning field does not turn that default
842
- // off, so compaction would still buy hidden reasoning tokens. vLLM's
843
- // StepFun template honours this explicit per-request switch.
844
- return { chat_template_kwargs: { enable_thinking: enabled } };
845
- case "nvidia": {
846
- const kind = classifyNvidiaModel(model ?? "");
847
- switch (kind) {
848
- case "kimi-thinking":
849
- return {
850
- chat_template_kwargs: {
851
- thinking: enabled,
852
- },
853
- };
854
- case "deepseek-v4":
855
- // NVIDIA's DeepSeek V4 API accepts none/high/max. Map expanded
856
- // effort levels: none/minimal/low → none; medium/high/xhigh → high.
857
- return {
858
- chat_template_kwargs: {
859
- thinking: enabled,
860
- reasoning_effort: enabled
861
- ? clampEffort(effort) === "low"
862
- ? "none"
863
- : "high"
864
- : "none",
865
- },
866
- };
867
- case "thinking":
868
- return {
869
- chat_template_kwargs: {
870
- thinking: enabled,
871
- },
872
- };
873
- case "nemotron-3": {
874
- // Nemotron-3 supports both `enable_thinking` and an optional
875
- // `reasoning_budget` cap. Map expanded effort to budget values.
876
- if (!enabled) {
877
- return {
878
- chat_template_kwargs: { enable_thinking: false },
879
- };
880
- }
881
- const clamped = clampEffort(effort);
882
- const budget = clamped === "low" ? 4_096 : clamped === "high" ? 16_384 : 8_192;
883
- return {
884
- reasoning_budget: budget,
885
- chat_template_kwargs: { enable_thinking: true },
886
- };
887
- }
888
- case "glm-thinking":
889
- // GLM-5 / 4.5 expects `clear_thinking:false` alongside
890
- // `enable_thinking:true` per the NIM docs example.
891
- return {
892
- chat_template_kwargs: enabled
893
- ? { enable_thinking: true, clear_thinking: false }
894
- : { enable_thinking: false },
895
- };
896
- case "enable-thinking":
897
- // Gemma 3/4 only documents `enable_thinking`; do not add
898
- // `clear_thinking` here since the chat template doesn't accept it.
899
- return {
900
- chat_template_kwargs: { enable_thinking: enabled },
901
- };
902
- case "effort-only":
903
- // NVIDIA GPT-OSS accepts only low/medium/high, so a retry cannot
904
- // fully disable it. Keep it at the lowest supported effort instead
905
- // of omitting the field and reverting to NVIDIA's medium default.
906
- if (!enabled && /gpt-oss/i.test(model ?? "")) {
907
- return { reasoning_effort: "low" };
908
- }
909
- if (!enabled && /qwen3|mistral-/i.test(model ?? "")) {
910
- return { reasoning_effort: "none" };
911
- }
912
- return { reasoning_effort: clampEffort(effort) };
913
- case "none":
914
- default:
915
- return {};
916
- }
917
- }
918
- default:
919
- return {};
920
- }
921
- }
922
- /**
923
- * Detects provider errors that mean the model rejected one of our
924
- * reasoning/thinking knobs (chat_template_kwargs, enable_thinking,
925
- * clear_thinking, reasoning_effort, reasoning_budget, thinking). NVIDIA NIM and
926
- * other OpenAI-compatible gateways return a 400/422 for chat templates that do
927
- * not accept these fields. When this matches, the router strips the reasoning
928
- * payload and retries so an unsupported option never fails the whole request.
929
- */
930
- export function isReasoningUnsupportedError(error) {
931
- if (isMissingReasoningContentError(error))
932
- return false;
933
- const status = error && typeof error === "object" && "status" in error
934
- ? Number(error.status)
935
- : undefined;
936
- const body = error && typeof error === "object" && "body" in error
937
- ? String(error.body ?? "")
938
- : "";
939
- const message = error instanceof Error ? error.message : String(error);
940
- const hay = `${message}\n${body}`.toLowerCase();
941
- const mentionsReasoningKnob =
942
- // `\breasoning\b` catches bodies like "Unrecognized request argument
943
- // supplied: reasoning" so a bare reasoning-field rejection also degrades.
944
- /chat_template_kwargs|enable_thinking|clear_thinking|reasoning_effort|reasoning_budget|reasoning_content|\breasoning\b|\bthinking\b/.test(hay);
945
- if (!mentionsReasoningKnob)
946
- return false;
947
- // A 4xx that names a reasoning field is a parameter rejection — strip it.
948
- if (status === 400 || status === 422)
949
- return true;
950
- // Any status: explicit "not supported / unknown / invalid parameter" wording.
951
- return /not support|unsupported|unknown|unrecognized|not a valid|not allowed|unexpected keyword|does not accept|extra fields not permitted|additional propert|invalid[_ ]?(?:request[_ ]?)?(?:argument|parameter|field)/.test(hay);
952
- }
953
- const EFFORT_VOCABULARY = [
954
- "none",
955
- "minimal",
956
- "low",
957
- "medium",
958
- "high",
959
- "xhigh",
960
- "max",
961
- ];
962
- export function reasoningRejectionAdvice(error) {
963
- const body = error && typeof error === "object" && "body" in error
964
- ? String(error.body ?? "")
965
- : "";
966
- const message = error instanceof Error ? error.message : String(error);
967
- const hay = `${message}\n${body}`.toLowerCase();
968
- const mandatory = /always\s+(?:engages?\s+in|uses?|performs?)\s+(?:thinking|reasoning)|(?:thinking|reasoning)\s+cannot\s+be\s+disabled|cannot\s+be\s+disabled|can(?:no|')t\s+be\s+(?:disabled|turned\s+off)/.test(hay);
969
- const clause = /(?:please\s+use|must\s+be\s+one\s+of|must\s+be|one\s+of|supported\s+values?(?:\s+are)?|valid\s+values?(?:\s+are)?|allowed\s+values?(?:\s+are)?|use)\s*:?\s*([^.;\n}"]{0,120})/.exec(hay);
970
- const acceptedEfforts = clause
971
- ? EFFORT_VOCABULARY.filter((effort) => new RegExp(`\\b${effort}\\b`).test(clause[1] ?? ""))
972
- : [];
973
- if (!mandatory && acceptedEfforts.length === 0)
974
- return undefined;
975
- return { mandatory, acceptedEfforts };
976
- }
977
- export function isStreamOptionsUnsupportedError(error) {
978
- const status = error && typeof error === "object" && "status" in error
979
- ? Number(error.status)
980
- : undefined;
981
- if (status !== 400 && status !== 422)
982
- return false;
983
- const body = error && typeof error === "object" && "body" in error
984
- ? String(error.body ?? "")
985
- : "";
986
- const message = error instanceof Error ? error.message : String(error);
987
- const hay = `${message}\n${body}`.toLowerCase();
988
- return (/stream_options|stream options/.test(hay) &&
989
- /not support|unsupported|unknown|unrecognized|not a valid|not allowed|unexpected keyword|does not accept|extra fields not permitted|additional propert|invalid[_ ]?(?:request[_ ]?)?(?:argument|parameter|field)/.test(hay));
990
- }
991
- export function isImageInputUnsupportedError(error) {
992
- const status = error && typeof error === "object" && "status" in error
993
- ? Number(error.status)
994
- : undefined;
995
- const body = error && typeof error === "object" && "body" in error
996
- ? String(error.body ?? "")
997
- : "";
998
- const message = error instanceof Error ? error.message : String(error);
999
- const hay = `${message}\n${body}`.toLowerCase();
1000
- const mentionsImageInput = /image_url|image url|inlinedata|inline_data|\bimages?\b|multimodal|\bvision\b|media_type|image content|content\[\d+\]|content\.\d+|parts\[\d+\]/.test(hay);
1001
- if (!mentionsImageInput)
1002
- return false;
1003
- if (status !== undefined && status !== 400 && status !== 415 && status !== 422) {
1004
- return false;
1005
- }
1006
- return /not support|unsupported|does not accept|cannot process|invalid[_ ]?(?:request[_ ]?)?(?:argument|parameter|field|type|value)?|unknown|unrecognized|not a valid|not allowed|only text|text[- ]only|expected a string|must be a string|additional propert/.test(hay);
1007
- }
1008
- export function stripImagesFromMessages(messages) {
1009
- return messages.map((message) => {
1010
- if (!message.images?.length)
1011
- return message;
1012
- const { images: _images, ...rest } = message;
1013
- return rest;
1014
- });
1015
- }
1016
- export function imageCapableMessages(provider, model, messages) {
1017
- if (modelAcceptsImages(provider, model))
1018
- return messages;
1019
- return stripImagesFromMessages(messages);
1020
- }
1021
- /**
1022
- * legacy Chat Completions sampling knobs: `max_tokens` must be
1023
- * `max_completion_tokens`, and `temperature`/`top_p` must be omitted or left
1024
- * at their default (non-default values return HTTP 400 "Unsupported
1025
- * parameter"). Matched by model name (not provider) since OpenAI-compatible
1026
- * gateways that pass these model IDs through to the real OpenAI API hit the
1027
- * same restriction.
1028
- * https://help.openai.com/en/articles/5072518 (Chat Completions section).
1029
- */
1030
- export function isOpenAiReasoningModel(model) {
1031
- const m = model.toLowerCase();
1032
- return (/(?:^|\/)gpt-5(?:\.|-|$)/.test(m) ||
1033
- /(?:^|\/)o[134](?:\.|-|$)/.test(m) ||
1034
- /muse-spark/.test(m));
1035
- }
1036
- const DEFAULT_REASONING_OUTPUT_FLOOR = 16_384;
1037
- function outputBudgetWithReasoning(requested, options) {
1038
- const floor = options.control?.profile.reasoning.minOutputTokens ??
1039
- DEFAULT_REASONING_OUTPUT_FLOOR;
1040
- const ceiling = modelMaxOutputTokens(options.providerId, options.model, options.outputTokenLimit);
1041
- const floored = Math.max(requested, floor);
1042
- return ceiling !== undefined ? Math.min(floored, ceiling) : floored;
1043
- }
1044
- function emitChatCompletionsBody(options) {
1045
- // Skip reasoning knobs entirely for models observed to reject them this
1046
- // session (see isReasoningUnsupportedError). This is how thinking degrades
1047
- // gracefully: the request still runs, just without the unsupported option.
1048
- const capabilityDeniesThinking = options.control === undefined &&
1049
- options.providerId !== undefined &&
1050
- Boolean(options.reasoning?.enabled) &&
1051
- !modelSupportsThinking(options.providerId, options.model);
1052
- const legacyControlDenied = options.control === undefined &&
1053
- options.providerId !== undefined &&
1054
- isReasoningUnsupported(options.providerId, options.model);
1055
- const reasoning = legacyControlDenied ||
1056
- capabilityDeniesThinking ||
1057
- options.control?.suppressed === true
1058
- ? {}
1059
- : buildReasoningPayload(options.reasoning, options.reasoningStyle ?? "none", options.model, options.providerId, options.control);
1060
- const reasoningOn = Boolean(options.reasoning?.enabled);
1061
- // Kimchi exposes this model as `minimax-m3`; NVIDIA uses the longer
1062
- // `minimaxai/minimax-m3` ID. Both need the larger default output budget.
1063
- const isMinimaxM3 = /minimax-m3/i.test(options.model);
1064
- const defaultMaxTokens = isMinimaxM3 ? 8_192 : reasoningOn ? 8_192 : 4_096;
1065
- // One declarative sampling policy; explicit caller value wins.
1066
- const sampling = options.resolvedSampling ?? {
1067
- ...resolveSampling({
1068
- model: options.model,
1069
- reasoningEnabled: reasoningOn,
1070
- requestedTemperature: options.temperature,
1071
- }),
1072
- };
1073
- const reasoningModel = isOpenAiReasoningModel(options.model);
1074
- const emitTemperature = sampling.temperature !== undefined &&
1075
- (options.resolvedSampling !== undefined || !reasoningModel);
1076
- // Claude extended thinking via AgentRouter maps reasoning_effort to an
1077
- // Anthropic `thinking.budget_tokens`, and the gateway (Bedrock) rejects the
1078
- // request with HTTP 400 unless `max_tokens > budget_tokens`. Some upstream
1079
- // nodes enforce this intermittently, so whenever Claude reasoning is enabled
1080
- // we guarantee a ceiling that clears the largest effort budget (32000 was
1081
- // verified live to succeed while staying within Opus's output cap). This is a
1082
- // ceiling, not a forced length — Claude still stops at its natural stop.
1083
- const claudeThinking = reasoningOn &&
1084
- options.reasoningStyle === "agentrouter" &&
1085
- /claude/i.test(options.model);
1086
- const requestedMaxTokens = options.maxTokens ?? defaultMaxTokens;
1087
- const claudeFloored = claudeThinking
1088
- ? Math.max(requestedMaxTokens, 32_000)
1089
- : requestedMaxTokens;
1090
- const effectiveMaxTokens = reasoningOn
1091
- ? outputBudgetWithReasoning(claudeFloored, options)
1092
- : claudeFloored;
1093
- const affinityKey = options.providerId === "openrouter" || options.providerId === "fireworks"
1094
- ? cacheAffinityKey(options.providerId, options.model, options.messages)
1095
- : undefined;
1096
- const body = {
1097
- model: options.model,
1098
- messages: toOpenAiMessages(singleLeadingSystemMessages(options.messages), options.supportsVision, options.replayTarget
1099
- ? {
1100
- target: options.replayTarget,
1101
- observe: options.reasoningArtifactReplayObserver,
1102
- ...(options.forceReasoningReplay ? { forceScope: true } : {}),
1103
- }
1104
- : undefined),
1105
- stream: options.stream,
1106
- ...(options.providerId === "openrouter" && affinityKey
1107
- ? { session_id: affinityKey }
1108
- : {}),
1109
- ...(options.providerId === "fireworks"
1110
- ? {
1111
- perf_metrics_in_response: true,
1112
- ...(affinityKey
1113
- ? {
1114
- prompt_cache_key: affinityKey,
1115
- prompt_cache_isolation_key: affinityKey,
1116
- }
1117
- : {}),
1118
- }
1119
- : {}),
1120
- ...(reasoningModel
1121
- ? { max_completion_tokens: effectiveMaxTokens }
1122
- : { max_tokens: effectiveMaxTokens }),
1123
- // gpt-5.x / o1 / o3 / o4 only accept the default temperature (1) and
1124
- // reject any explicit value — omit the field entirely rather than send
1125
- // our 0.2 default and get a 400.
1126
- ...(emitTemperature ? { temperature: sampling.temperature } : {}),
1127
- ...reasoning,
1128
- ...openAiToolBodyFields({
1129
- tools: options.tools,
1130
- toolChoice: options.toolChoice,
1131
- parallelToolCalls: options.parallelToolCalls,
1132
- }),
1133
- };
1134
- if (emitTemperature && sampling.topP !== undefined) {
1135
- body.top_p = sampling.topP;
1136
- }
1137
- // OpenAI + many OpenAI-compatible gateways attach usage on the final SSE
1138
- // chunk when this is set (non-stream responses always include usage).
1139
- if (options.stream && options.includeStreamUsage !== false) {
1140
- body.stream_options = { include_usage: true };
1141
- }
1142
- return JSON.stringify(body);
1143
- }
1144
- export function buildChatBody(options) {
1145
- return emitChatCompletionsBody(options);
1146
- }
1147
- /**
1148
- * Serializes a compiled canonical plan onto the Chat Completions wire. Wire
1149
- * dialect knobs that the plan intentionally does not model (gateway reasoning
1150
- * style, stream-usage flag, replay observer) stay serializer-side extras.
1151
- */
1152
- export function chatCompletionsBodyFromPlan(plan, extras = {}) {
1153
- return emitChatCompletionsBody({
1154
- model: plan.route.model,
1155
- providerId: plan.route.provider,
1156
- messages: [...plan.timeline.messages],
1157
- maxTokens: plan.controls.requestedMaxTokens,
1158
- temperature: plan.controls.temperature,
1159
- stream: plan.controls.stream,
1160
- includeStreamUsage: extras.includeStreamUsage,
1161
- reasoning: plan.controls.reasoning,
1162
- reasoningStyle: extras.reasoningStyle,
1163
- supportsVision: plan.images.visionAccepted,
1164
- control: {
1165
- profile: {
1166
- reasoning: plan.policy.reasoning,
1167
- capabilities: { acceptedParameters: plan.policy.acceptedParameters },
1168
- },
1169
- willReplayReasoning: plan.replay.decisions.some((entry) => entry.decision.action === "replayed"),
1170
- suppressed: plan.controls.controlSuppression !== undefined,
1171
- },
1172
- resolvedSampling: {
1173
- temperature: plan.controls.temperature,
1174
- topP: plan.controls.topP,
1175
- },
1176
- ...(plan.policy.limits.outputTokens !== undefined
1177
- ? { outputTokenLimit: plan.policy.limits.outputTokens }
1178
- : {}),
1179
- tools: plan.tools.definitions.length
1180
- ? [...plan.tools.definitions]
1181
- : undefined,
1182
- toolChoice: plan.tools.choice,
1183
- parallelToolCalls: plan.tools.parallelToolCalls,
1184
- replayTarget: plan.replay.target,
1185
- reasoningArtifactReplayObserver: extras.reasoningArtifactReplayObserver,
1186
- ...(extras.forceReasoningReplay ? { forceReasoningReplay: true } : {}),
1187
- });
1188
- }
1189
- function sentReasoningEffort(requestBody) {
1190
- try {
1191
- const body = JSON.parse(requestBody);
1192
- if (typeof body.reasoning_effort === "string" && body.reasoning_effort) {
1193
- return body.reasoning_effort;
1194
- }
1195
- const nested = body.reasoning;
1196
- if (nested && typeof nested === "object" && !Array.isArray(nested)) {
1197
- const effort = nested.effort;
1198
- if (typeof effort === "string" && effort)
1199
- return effort;
1200
- }
1201
- }
1202
- catch {
1203
- return undefined;
1204
- }
1205
- return undefined;
1206
- }
1207
- function privateReasoningNote(provider, requestBody, reasoningTokens) {
1208
- const effort = sentReasoningEffort(requestBody);
1209
- const effortText = effort ? ` at ${effort} effort` : "";
1210
- return `Reasoning is private on ${provider}: the model reasoned${effortText} and used ${reasoningTokens.toLocaleString("en-US")} reasoning tokens, but the API returns no reasoning text to display.`;
1211
- }
1212
- export async function openAiCompatibleComplete(options) {
1213
- const plan = compileRequestPlan({
1214
- provider: options.providerId,
1215
- model: options.model,
1216
- messages: options.messages,
1217
- stream: false,
1218
- endpoint: options.baseUrl,
1219
- reasoning: options.reasoning,
1220
- tools: options.tools,
1221
- toolChoice: options.toolChoice,
1222
- parallelToolCalls: options.parallelToolCalls,
1223
- temperature: options.temperature,
1224
- maxTokens: options.maxTokens,
1225
- });
1226
- const requestBody = chatCompletionsBodyFromPlan(plan, {
1227
- reasoningStyle: options.reasoningStyle,
1228
- reasoningArtifactReplayObserver: options.reasoningArtifactReplayObserver,
1229
- ...(options.forceReasoningReplay ? { forceReasoningReplay: true } : {}),
1230
- });
1231
- let response;
1232
- try {
1233
- response = await generationFetch(`${options.baseUrl}/chat/completions`, {
1234
- method: "POST",
1235
- signal: options.signal ?? null,
1236
- headers: {
1237
- "content-type": "application/json",
1238
- accept: "application/json",
1239
- ...(options.apiKey
1240
- ? { authorization: `Bearer ${options.apiKey}` }
1241
- : {}),
1242
- ...options.headers,
1243
- },
1244
- body: requestBody,
1245
- verbose: process.env.CLAI_VERBOSE === "true",
1246
- });
1247
- }
1248
- catch (error) {
1249
- if (error instanceof Error && error.name === "AbortError")
1250
- throw error;
1251
- if (isOperationPolicyError(error))
1252
- throw error;
1253
- const msg = error instanceof Error ? error.message : String(error);
1254
- throw new ProviderError(`${options.provider} request could not be sent (${msg}). Check connectivity to ${options.baseUrl}.`);
1255
- }
1256
- let data;
1257
- try {
1258
- data = await readJson(response);
1259
- }
1260
- catch (error) {
1261
- if (error instanceof ProviderError) {
1262
- throw new ProviderError(`${options.provider} (model=${options.model}): ${error.message}`, error.status, error.body, error.retryAfterSeconds);
1263
- }
1264
- throw error;
1265
- }
1266
- const choice = data.choices?.[0];
1267
- const message = choice?.message;
1268
- const toolCalls = parseOpenAiMessageToolCalls(message?.tool_calls);
1269
- const text = message?.content ?? "";
1270
- if (!text && toolCalls.length === 0) {
1271
- throw new ProviderError(`${options.provider} returned no completion text (model=${options.model}). The response was empty — try /effort off, raise max_tokens, or pick another model with /model.`);
1272
- }
1273
- // If the API returns reasoning separately, prepend it inside <think>
1274
- // tags so the existing thinking parser can pick it up uniformly.
1275
- // Fireworks exposes cache metrics in headers for complete calls and can also
1276
- // include them in perf_metrics. Other compatible routes use their standard
1277
- // usage object plus any explicitly configured aliases.
1278
- const usage = options.providerId === "fireworks"
1279
- ? parseFireworksUsage(data.usage, data.perf_metrics, response.headers)
1280
- : parseOpenAiUsage(data.usage, options.usageAliases);
1281
- const reasoning = openAiReasoningText(message);
1282
- const detailsRaw = artifactRaw(message?.reasoning_details);
1283
- const thoughtSignature = message?.extra_content?.google?.thought_signature;
1284
- const reasoningArtifacts = compatibleReasoningArtifacts({
1285
- providerId: options.providerId,
1286
- model: options.model,
1287
- baseUrl: options.baseUrl,
1288
- toolCalls,
1289
- policy: options.reasoningArtifactPolicy ??
1290
- compatibleArtifactPolicyFor(plan.policy.reasoning.finalTurnPreservation),
1291
- ...(typeof reasoning === "string" && reasoning
1292
- ? { reasoning: { text: reasoning, sequence: 0 } }
1293
- : {}),
1294
- ...(detailsRaw ? { details: [{ raw: detailsRaw, sequence: 1 }] } : {}),
1295
- ...(thoughtSignature
1296
- ? {
1297
- thoughtSignatures: [
1298
- {
1299
- raw: thoughtSignature,
1300
- sequence: 2,
1301
- ...(toolCalls.length ? { toolCallIndex: 0 } : {}),
1302
- },
1303
- ],
1304
- }
1305
- : {}),
1306
- });
1307
- if (typeof reasoning === "string" && reasoning.trim()) {
1308
- learnModelEmitsReasoning(options.providerId, options.model);
1309
- }
1310
- const displayReasoning = typeof reasoning === "string" && reasoning
1311
- ? reasoning
1312
- : (visibleReasoningDetailText(detailsRaw) ?? "");
1313
- return {
1314
- text,
1315
- ...(toolCalls.length ? { toolCalls } : {}),
1316
- ...(choice?.finish_reason
1317
- ? { finishReason: choice.finish_reason }
1318
- : toolCalls.length
1319
- ? { finishReason: "tool_calls" }
1320
- : {}),
1321
- ...(usage ? { usage } : {}),
1322
- ...(displayReasoning ? { reasoningBlock: { text: displayReasoning } } : {}),
1323
- ...(reasoningArtifacts ? { reasoningArtifacts } : {}),
1324
- };
1325
- }
1326
- export async function openAiCompatibleStream(options) {
1327
- // Combine the caller's abort signal with an idle watchdog so a stuck
1328
- // connection can't wedge the REPL forever. Thinking models get a much
1329
- // longer first-byte budget and a longer mid-stream silence budget —
1330
- // the old 30s default aborted healthy Bynara/OpenRouter streams that
1331
- // were still "thinking" without tokens.
1332
- const reasoningOn = Boolean(options.reasoning?.enabled);
1333
- const idleTimeoutMs = options.idleTimeoutMs ??
1334
- (reasoningOn
1335
- ? THINKING_STREAM_IDLE_TIMEOUT_MS
1336
- : DEFAULT_STREAM_IDLE_TIMEOUT_MS);
1337
- const initialIdleTimeoutMs = options.initialIdleTimeoutMs ??
1338
- (reasoningOn
1339
- ? THINKING_STREAM_INITIAL_IDLE_TIMEOUT_MS
1340
- : idleTimeoutMs);
1341
- // "No bytes" and "no output" are different failures and need separate
1342
- // budgets. The transport watchdog is re-armed by every read, so an SSE
1343
- // keepalive comment, a `delta:{}` heartbeat, a role-only opening delta, or a
1344
- // multi-line frame still being assembled all count as proof that the
1345
- // connection is healthy. The output watchdog is re-armed only by real model
1346
- // progress, so a stream that keepalives forever without ever producing
1347
- // anything still fails instead of hanging.
1348
- const outputIdleTimeoutMs = options.outputIdleTimeoutMs ??
1349
- Math.round(Math.max(idleTimeoutMs, initialIdleTimeoutMs) * 1.5);
1350
- const idleController = new AbortController();
1351
- let transportTimer;
1352
- let outputTimer;
1353
- let idleFired = false;
1354
- let firedWatchdog;
1355
- /** Budget of whichever watchdog fired, for the error message. */
1356
- let firedBudgetMs = initialIdleTimeoutMs;
1357
- /**
1358
- * Any bytes at all read off the socket, whether or not the frame carried
1359
- * model output. Separates "the route never answered" (retry the request) from
1360
- * "the model was working and went quiet" (a retry replays all of that work).
1361
- */
1362
- let sawTransportActivity = false;
1363
- /** Model-visible progress: content, reasoning, tool-call delta, or usage. */
1364
- let sawStreamProgress = false;
1365
- const fireStall = (watchdog, budgetMs) => {
1366
- // The two timers can expire in the same event-loop turn. Preserve the first
1367
- // cause so a transport outage is never relabeled by the output watchdog.
1368
- if (idleFired)
1369
- return;
1370
- idleFired = true;
1371
- firedWatchdog = watchdog;
1372
- firedBudgetMs = budgetMs;
1373
- idleController.abort();
1374
- };
1375
- const armTransportTimer = (budgetMs) => {
1376
- if (transportTimer)
1377
- clearTimeout(transportTimer);
1378
- transportTimer = setTimeout(() => fireStall("transport", budgetMs), budgetMs);
1379
- };
1380
- /** Bytes arrived — the connection is alive; re-arm the mid-stream budget. */
1381
- const noteTransportActivity = () => {
1382
- sawTransportActivity = true;
1383
- armTransportTimer(idleTimeoutMs);
1384
- };
1385
- const resetIdleTimer = () => {
1386
- sawStreamProgress = true;
1387
- noteTransportActivity();
1388
- if (outputTimer)
1389
- clearTimeout(outputTimer);
1390
- outputTimer = setTimeout(() => fireStall("output", outputIdleTimeoutMs), outputIdleTimeoutMs);
1391
- };
1392
- armTransportTimer(initialIdleTimeoutMs);
1393
- outputTimer = setTimeout(() => fireStall("output", outputIdleTimeoutMs), outputIdleTimeoutMs);
1394
- const clearIdleTimers = () => {
1395
- if (transportTimer)
1396
- clearTimeout(transportTimer);
1397
- if (outputTimer)
1398
- clearTimeout(outputTimer);
1399
- transportTimer = undefined;
1400
- outputTimer = undefined;
1401
- };
1402
- const onCallerAbort = () => idleController.abort(options.signal?.reason);
1403
- options.signal?.addEventListener("abort", onCallerAbort, { once: true });
1404
- const plan = compileRequestPlan({
1405
- provider: options.providerId,
1406
- model: options.model,
1407
- messages: options.messages,
1408
- stream: true,
1409
- endpoint: options.baseUrl,
1410
- reasoning: options.reasoning,
1411
- tools: options.tools,
1412
- toolChoice: options.toolChoice,
1413
- parallelToolCalls: options.parallelToolCalls,
1414
- temperature: options.temperature,
1415
- maxTokens: options.maxTokens,
1416
- });
1417
- const requestBody = chatCompletionsBodyFromPlan(plan, {
1418
- reasoningStyle: options.reasoningStyle,
1419
- includeStreamUsage: options.includeStreamUsage,
1420
- reasoningArtifactReplayObserver: options.reasoningArtifactReplayObserver,
1421
- ...(options.forceReasoningReplay ? { forceReasoningReplay: true } : {}),
1422
- });
1423
- let response;
1424
- try {
1425
- response = await generationFetch(`${options.baseUrl}/chat/completions`, {
1426
- method: "POST",
1427
- signal: idleController.signal,
1428
- headers: {
1429
- "content-type": "application/json",
1430
- accept: "text/event-stream",
1431
- ...(options.apiKey
1432
- ? { authorization: `Bearer ${options.apiKey}` }
1433
- : {}),
1434
- ...options.headers,
1435
- },
1436
- body: requestBody,
1437
- verbose: process.env.CLAI_VERBOSE === "true",
1438
- });
1439
- }
1440
- catch (error) {
1441
- clearIdleTimers();
1442
- options.signal?.removeEventListener("abort", onCallerAbort);
1443
- if (idleFired) {
1444
- throw new ProviderError(`${options.provider} request timed out before any response (${Math.round(firedBudgetMs / 1000)}s)`);
1445
- }
1446
- throw error;
1447
- }
1448
- if (!response.ok) {
1449
- clearIdleTimers();
1450
- options.signal?.removeEventListener("abort", onCallerAbort);
1451
- try {
1452
- await readJson(response);
1453
- }
1454
- catch (error) {
1455
- if (error instanceof ProviderError) {
1456
- throw new ProviderError(`${options.provider} (model=${options.model}): ${error.message}`, error.status, error.body, error.retryAfterSeconds);
1457
- }
1458
- throw error;
1459
- }
1460
- }
1461
- if (!response.body) {
1462
- clearIdleTimers();
1463
- options.signal?.removeEventListener("abort", onCallerAbort);
1464
- throw new ProviderError(`${options.provider} returned no stream body`);
1465
- }
1466
- const contentType = response.headers.get("content-type") ?? "";
1467
- if (response.status === 202 || /\bapplication\/json\b/i.test(contentType)) {
1468
- try {
1469
- const data = await readJson(response, idleController.signal);
1470
- if (response.status === 202) {
1471
- const requestId = data.requestId ?? data.id;
1472
- throw new ProviderError(`${options.provider} returned a pending async response${requestId ? ` (${requestId})` : ""}; streaming did not start.`, response.status, JSON.stringify(data).slice(0, 1_000));
1473
- }
1474
- const choice = data.choices?.[0];
1475
- const message = choice?.message;
1476
- const toolCalls = parseOpenAiMessageToolCalls(message?.tool_calls);
1477
- const text = message?.content ?? "";
1478
- const jsonUsage = options.providerId === "fireworks"
1479
- ? parseFireworksUsage(data.usage, data.perf_metrics, response.headers)
1480
- : parseOpenAiUsage(data.usage, options.usageAliases);
1481
- const reasoning = openAiReasoningText(message);
1482
- const detailsRaw = artifactRaw(message?.reasoning_details);
1483
- const thoughtSignature = message?.extra_content?.google?.thought_signature;
1484
- const reasoningArtifacts = compatibleReasoningArtifacts({
1485
- providerId: options.providerId,
1486
- model: options.model,
1487
- baseUrl: options.baseUrl,
1488
- toolCalls,
1489
- policy: options.reasoningArtifactPolicy ??
1490
- compatibleArtifactPolicyFor(plan.policy.reasoning.finalTurnPreservation),
1491
- ...(typeof reasoning === "string" && reasoning
1492
- ? { reasoning: { text: reasoning, sequence: 0 } }
1493
- : {}),
1494
- ...(detailsRaw ? { details: [{ raw: detailsRaw, sequence: 1 }] } : {}),
1495
- ...(thoughtSignature
1496
- ? {
1497
- thoughtSignatures: [
1498
- {
1499
- raw: thoughtSignature,
1500
- sequence: 2,
1501
- ...(toolCalls.length ? { toolCallIndex: 0 } : {}),
1502
- },
1503
- ],
1504
- }
1505
- : {}),
1506
- });
1507
- if (text.trim() ||
1508
- toolCalls.length > 0 ||
1509
- (typeof reasoning === "string" && reasoning.trim())) {
1510
- emitStreamReasoningArtifacts(options.onStreamEvent, reasoningArtifacts);
1511
- if (text)
1512
- options.onToken(text);
1513
- return {
1514
- text,
1515
- ...(toolCalls.length ? { toolCalls } : {}),
1516
- ...(choice?.finish_reason
1517
- ? { finishReason: choice.finish_reason }
1518
- : toolCalls.length
1519
- ? { finishReason: "tool_calls" }
1520
- : {}),
1521
- ...(jsonUsage ? { usage: jsonUsage } : {}),
1522
- ...(typeof reasoning === "string" && reasoning
1523
- ? { reasoningBlock: { text: reasoning } }
1524
- : visibleReasoningDetailText(detailsRaw)
1525
- ? {
1526
- reasoningBlock: {
1527
- text: visibleReasoningDetailText(detailsRaw),
1528
- },
1529
- }
1530
- : {}),
1531
- ...(reasoningArtifacts ? { reasoningArtifacts } : {}),
1532
- };
1533
- }
1534
- throw new ProviderError(`${options.provider} returned JSON instead of an SSE stream, but no completion text was present.`, response.status, JSON.stringify(data).slice(0, 1_000));
1535
- }
1536
- catch (error) {
1537
- if (idleFired) {
1538
- const seconds = Math.round(firedBudgetMs / 1000);
1539
- if (firedWatchdog === "transport" || !sawTransportActivity) {
1540
- if (!sawTransportActivity) {
1541
- throw new ProviderError(`${options.provider} request timed out before any response (${seconds}s) — no data arrived on the connection.`);
1542
- }
1543
- throw new ProviderError(`${options.provider} stream transport timeout (${seconds}s) — no data arrived on the connection after it had started.`);
1544
- }
1545
- throw new ProviderError(`${options.provider} stream stalled — ${STREAM_STALL_MARKER} for ${seconds}s`);
1546
- }
1547
- throw error;
1548
- }
1549
- finally {
1550
- clearIdleTimers();
1551
- options.signal?.removeEventListener("abort", onCallerAbort);
1552
- }
1553
- }
1554
- const decoder = new TextDecoder();
1555
- const reader = response.body.getReader();
1556
- let buffer = "";
1557
- let full = "";
1558
- let visible = "";
1559
- let reasoningSeen = "";
1560
- let contentWireSeen = "";
1561
- let reasoningWireSeen = "";
1562
- let finishReason;
1563
- let terminalSignal;
1564
- const terminalPolicy = options.streamTerminal ??
1565
- (plan.policy.terminal.proofs.length > 0
1566
- ? plan.policy.terminal
1567
- : CHAT_COMPLETIONS_STREAM_TERMINAL);
1568
- const emittedByteCounts = () => {
1569
- let toolArgumentBytes = 0;
1570
- for (const state of toolCallState.values()) {
1571
- toolArgumentBytes += state.arguments.length;
1572
- }
1573
- return {
1574
- answerBytes: visible.length,
1575
- reasoningBytes: reasoningSeen.length,
1576
- toolArgumentBytes,
1577
- };
1578
- };
1579
- let streamUsage = options.providerId === "fireworks"
1580
- ? parseFireworksUsage(undefined, undefined, response.headers)
1581
- : undefined;
1582
- const toolCallState = new Map();
1583
- let reasoningArtifactSequence;
1584
- let nextArtifactSequence = 0;
1585
- let lastToolCallIndex;
1586
- const structuredDetails = [];
1587
- const thoughtSignatures = [];
1588
- const pendingThoughtSignatures = [];
1589
- const finalReasoningArtifacts = (toolCalls) => {
1590
- if (pendingThoughtSignatures.length) {
1591
- const toolCallIndex = toolCalls.length ? 0 : undefined;
1592
- for (const capture of pendingThoughtSignatures.splice(0)) {
1593
- thoughtSignatures.push(toolCallIndex === undefined
1594
- ? capture
1595
- : { ...capture, toolCallIndex });
1596
- }
1597
- }
1598
- return compatibleReasoningArtifacts({
1599
- providerId: options.providerId,
1600
- model: options.model,
1601
- baseUrl: options.baseUrl,
1602
- toolCalls,
1603
- policy: options.reasoningArtifactPolicy ??
1604
- compatibleArtifactPolicyFor(plan.policy.reasoning.finalTurnPreservation),
1605
- ...(reasoningSeen
1606
- ? {
1607
- reasoning: {
1608
- text: reasoningSeen,
1609
- sequence: reasoningArtifactSequence ?? 0,
1610
- },
1611
- }
1612
- : {}),
1613
- ...(structuredDetails.length ? { details: structuredDetails } : {}),
1614
- ...(thoughtSignatures.length ? { thoughtSignatures } : {}),
1615
- });
1616
- };
1617
- const displayReasoningText = () => {
1618
- if (reasoningSeen)
1619
- return reasoningSeen;
1620
- return structuredDetails
1621
- .map((detail) => visibleReasoningDetailText(detail.raw) ?? "")
1622
- .join("");
1623
- };
1624
- const normalizeChannelDelta = (token, seen, snapshotThreshold = 64) => {
1625
- const extendsSnapshot = token.length > seen.length && token.startsWith(seen);
1626
- const repeatsEstablishedSnapshot = seen.length >= 64 && token.length === seen.length && token === seen;
1627
- if (seen.length >= snapshotThreshold &&
1628
- (extendsSnapshot || repeatsEstablishedSnapshot)) {
1629
- return { delta: token.slice(seen.length), seen: token };
1630
- }
1631
- return { delta: token, seen: seen + token };
1632
- };
1633
- const emitPrivateReasoningNote = (hasToolCalls) => {
1634
- if (reasoningSeen.trim())
1635
- return;
1636
- if (!visible.trim() && !hasToolCalls)
1637
- return;
1638
- const tokens = streamUsage?.reasoningTokens ?? 0;
1639
- if (tokens <= 0)
1640
- return;
1641
- const note = privateReasoningNote(options.provider, requestBody, tokens);
1642
- emitStreamReasoningDelta(options.onStreamEvent, note);
1643
- };
1644
- /**
1645
- * Reasoning-echo suppression.
1646
- *
1647
- * Some gateways/models stream the chain of thought on `reasoning_content` and
1648
- * then replay it verbatim at the start of `content` before the real answer
1649
- * (observed with MiniMax M3 and GLM). Untagged, that replay is
1650
- * indistinguishable from an answer, so it was rendered as the response — the
1651
- * user saw the model's reasoning as its reply even with thinking off.
1652
- *
1653
- * While the leading `content` still matches reasoning we already received, it
1654
- * is kept inside the `<think>` region: never a visible answer, still visible
1655
- * under Ctrl+T, and stripped from history. Only the first
1656
- * ECHO_CONFIRM_CHARS are held back before deciding, so a normal answer is
1657
- * emitted with no perceptible delay.
1658
- */
1659
- const ECHO_CONFIRM_CHARS = 64;
1660
- let echoState = "idle";
1661
- let echoBuffer = "";
1662
- let echoPos = 0;
1663
- const emitVisible = (text) => {
1664
- if (!text)
1665
- return;
1666
- visible += text;
1667
- full += text;
1668
- options.onToken(text);
1669
- };
1670
- /**
1671
- * Route replayed text back into the reasoning region. Deliberately does NOT
1672
- * extend `reasoningSeen`: that string is the comparison baseline, and growing
1673
- * it with the replay would let the echo match itself past the real reasoning.
1674
- */
1675
- const emitReasoningEcho = (text) => {
1676
- if (!text)
1677
- return;
1678
- emitStreamReasoningDelta(options.onStreamEvent, text);
1679
- };
1680
- /** Release a still-undecided hold-back as the answer (stream ended early). */
1681
- const flushEchoBuffer = () => {
1682
- if (!echoBuffer)
1683
- return;
1684
- const held = echoBuffer;
1685
- echoBuffer = "";
1686
- echoState = "done";
1687
- emitVisible(held);
1688
- };
1689
- const handleContentToken = (token) => {
1690
- if (echoState === "done") {
1691
- emitVisible(token);
1692
- return;
1693
- }
1694
- if (echoState === "idle") {
1695
- // A replay is only plausible once a meaningful amount of reasoning came
1696
- // through the separate channel.
1697
- if (reasoningSeen.length < ECHO_CONFIRM_CHARS) {
1698
- echoState = "done";
1699
- emitVisible(token);
1700
- return;
1701
- }
1702
- echoState = "buffering";
1703
- }
1704
- if (echoState === "buffering") {
1705
- echoBuffer += token;
1706
- if (reasoningSeen.startsWith(echoBuffer)) {
1707
- if (echoBuffer.length >= ECHO_CONFIRM_CHARS) {
1708
- const confirmed = echoBuffer;
1709
- echoBuffer = "";
1710
- echoPos = confirmed.length;
1711
- echoState = "echoing";
1712
- emitReasoningEcho(confirmed);
1713
- }
1714
- return;
1715
- }
1716
- flushEchoBuffer();
1717
- return;
1718
- }
1719
- // Confirmed replay: consume the matching run, then hand over the answer.
1720
- let matched = 0;
1721
- while (matched < token.length &&
1722
- reasoningSeen[echoPos + matched] === token[matched]) {
1723
- matched += 1;
1724
- }
1725
- if (matched > 0) {
1726
- emitReasoningEcho(token.slice(0, matched));
1727
- echoPos += matched;
1728
- }
1729
- if (matched < token.length) {
1730
- echoState = "done";
1731
- emitVisible(token.slice(matched));
1732
- }
1733
- };
1734
- const cleanup = () => {
1735
- clearIdleTimers();
1736
- options.signal?.removeEventListener("abort", onCallerAbort);
1737
- idleController.signal.removeEventListener("abort", cancelReaderOnAbort);
1738
- };
1739
- const cancelReaderOnAbort = () => {
1740
- reader.cancel().catch(() => undefined);
1741
- };
1742
- idleController.signal.addEventListener("abort", cancelReaderOnAbort, {
1743
- once: true,
1744
- });
1745
- const sseFrames = createSseFrameAssembler();
1746
- try {
1747
- while (true) {
1748
- options.signal?.throwIfAborted();
1749
- if (idleController.signal.aborted) {
1750
- throw new Error("Stream aborted");
1751
- }
1752
- const { done, value } = await readWithAbort(reader, idleController.signal);
1753
- options.signal?.throwIfAborted();
1754
- if (idleController.signal.aborted) {
1755
- throw new Error("Stream aborted");
1756
- }
1757
- if (done)
1758
- break;
1759
- // Bytes off the wire re-arm the watchdog before anything is parsed.
1760
- // Keepalives and empty deltas are proof of a live connection, so they
1761
- // must not be allowed to age out a stream that is merely quiet.
1762
- if (value && value.byteLength > 0)
1763
- noteTransportActivity();
1764
- buffer += decoder.decode(value, { stream: true });
1765
- const lines = buffer.split("\n");
1766
- buffer = lines.pop() ?? "";
1767
- for (const line of lines) {
1768
- const payload = sseFrames.pushLine(line);
1769
- if (payload === undefined)
1770
- continue;
1771
- if (payload === "[DONE]") {
1772
- terminalSignal = "done-sentinel";
1773
- requireTerminalProof({
1774
- provider: options.provider,
1775
- policy: terminalPolicy,
1776
- signal: terminalSignal,
1777
- ...emittedByteCounts(),
1778
- });
1779
- flushEchoBuffer();
1780
- cleanup();
1781
- const toolCalls = finalizeOpenAiToolCalls(toolCallState);
1782
- emitPrivateReasoningNote(toolCalls.length > 0);
1783
- const reasoningArtifacts = finalReasoningArtifacts(toolCalls);
1784
- emitStreamReasoningArtifacts(options.onStreamEvent, reasoningArtifacts);
1785
- if (!visible.trim() && toolCalls.length === 0) {
1786
- // Thinking models (Kimi/Moonshot via Mantle, etc.) often emit only
1787
- // reasoning, sometimes with tool sentinels inside <think>. Returning
1788
- // the full text lets the agent runner recover tool calls from
1789
- // thinkContent instead of failing the whole stream as an error.
1790
- if (reasoningSeen.trim()) {
1791
- return {
1792
- text: full,
1793
- ...(finishReason ? { finishReason } : { finishReason: "stop" }),
1794
- ...(streamUsage ? { usage: streamUsage } : {}),
1795
- ...(displayReasoningText() ? { reasoningBlock: { text: displayReasoningText() } } : {}),
1796
- ...(reasoningArtifacts ? { reasoningArtifacts } : {}),
1797
- };
1798
- }
1799
- throw new ProviderError(`${options.provider} completed without a visible answer.`);
1800
- }
1801
- return {
1802
- text: full,
1803
- ...(toolCalls.length ? { toolCalls } : {}),
1804
- ...(finishReason
1805
- ? { finishReason }
1806
- : toolCalls.length
1807
- ? { finishReason: "tool_calls" }
1808
- : {}),
1809
- ...(streamUsage ? { usage: streamUsage } : {}),
1810
- ...(displayReasoningText() ? { reasoningBlock: { text: displayReasoningText() } } : {}),
1811
- ...(reasoningArtifacts ? { reasoningArtifacts } : {}),
1812
- };
1813
- }
1814
- let parsed;
1815
- try {
1816
- // Only JSON.parse is allowed to fail silently here. The
1817
- // delta handlers below (tool-arg size guard, UI callbacks) used to be
1818
- // inside this try and had their errors swallowed as "keepalives".
1819
- parsed = JSON.parse(payload);
1820
- }
1821
- catch {
1822
- // Malformed keepalive / comment line.
1823
- continue;
1824
- }
1825
- // Gateways report mid-stream failures as an error frame; that
1826
- // used to be dropped, so an upstream overload looked like a complete
1827
- // (but truncated) answer.
1828
- if (parsed.error) {
1829
- const detail = typeof parsed.error === "string"
1830
- ? parsed.error
1831
- : (parsed.error.message ?? parsed.error.type ?? "unknown error");
1832
- throw new ProviderError(`${options.provider} stream error: ${detail}`, inBandBadRequestStatus(parsed.error), payload.slice(0, 500));
1833
- }
1834
- {
1835
- const chunkUsage = options.providerId === "fireworks"
1836
- ? parseFireworksUsage(parsed.usage, parsed.perf_metrics, response.headers)
1837
- : parseOpenAiUsage(parsed.usage, options.usageAliases);
1838
- if (chunkUsage)
1839
- streamUsage = chunkUsage;
1840
- const finalUsageFrame = isFinalUsageFrame(parsed);
1841
- const choice = parsed.choices?.[0];
1842
- const delta = choice?.delta;
1843
- const reasoningToken = openAiReasoningText(delta);
1844
- const token = delta?.content;
1845
- const detailRaw = artifactRaw(delta?.reasoning_details);
1846
- const thoughtSignature = delta?.extra_content?.google?.thought_signature;
1847
- const artifactSequence = nextArtifactSequence++;
1848
- const toolProgress = delta?.tool_calls?.some((toolCall) => Boolean(toolCall.id ||
1849
- toolCall.function?.name ||
1850
- toolCall.function?.arguments));
1851
- if (choice?.finish_reason ||
1852
- chunkUsage ||
1853
- reasoningToken ||
1854
- token ||
1855
- detailRaw ||
1856
- thoughtSignature ||
1857
- toolProgress) {
1858
- resetIdleTimer();
1859
- }
1860
- if (terminalSignal === "usage-chunk" &&
1861
- (token || reasoningToken || toolProgress)) {
1862
- terminalSignal = undefined;
1863
- }
1864
- if (choice?.finish_reason) {
1865
- finishReason = choice.finish_reason;
1866
- terminalSignal = "finish-reason";
1867
- }
1868
- else if (finalUsageFrame && terminalSignal === undefined) {
1869
- terminalSignal = "usage-chunk";
1870
- }
1871
- if (reasoningToken) {
1872
- const normalized = normalizeChannelDelta(reasoningToken, reasoningWireSeen, options.providerId === "bynara" ? 1 : 64);
1873
- reasoningWireSeen = normalized.seen;
1874
- if (normalized.delta) {
1875
- reasoningArtifactSequence ??= artifactSequence;
1876
- if (!reasoningSeen) {
1877
- learnModelEmitsReasoning(options.providerId, options.model);
1878
- }
1879
- reasoningSeen += normalized.delta;
1880
- emitStreamReasoningDelta(options.onStreamEvent, normalized.delta);
1881
- }
1882
- }
1883
- if (detailRaw) {
1884
- structuredDetails.push({ raw: detailRaw, sequence: artifactSequence });
1885
- }
1886
- if (token) {
1887
- const normalized = normalizeChannelDelta(token, contentWireSeen);
1888
- contentWireSeen = normalized.seen;
1889
- if (normalized.delta)
1890
- handleContentToken(normalized.delta);
1891
- }
1892
- const deltaToolCallIndices = [];
1893
- if (delta?.tool_calls?.length) {
1894
- for (const tc of delta.tool_calls) {
1895
- const accInfo = accumulateOpenAiToolCallDelta(toolCallState, tc);
1896
- deltaToolCallIndices.push(accInfo.index);
1897
- lastToolCallIndex = accInfo.index;
1898
- if (options.onToolCallDelta) {
1899
- const wire = accInfo.name;
1900
- const canonical = wire
1901
- ? (fromWireName(wire) ?? wire)
1902
- : undefined;
1903
- const largeArgTick = !accInfo.nameBecameKnown &&
1904
- accInfo.argumentsBytes > 0 &&
1905
- accInfo.argumentsBytes % 4096 <
1906
- (typeof tc.function?.arguments === "string"
1907
- ? tc.function.arguments.length
1908
- : 0);
1909
- if (accInfo.nameBecameKnown || largeArgTick) {
1910
- options.onToolCallDelta({
1911
- index: accInfo.index,
1912
- ...(accInfo.id !== undefined ? { id: accInfo.id } : {}),
1913
- ...(canonical !== undefined ? { name: canonical } : {}),
1914
- argumentsBytes: accInfo.argumentsBytes,
1915
- });
1916
- }
1917
- }
1918
- }
1919
- }
1920
- const signatureToolCallIndex = deltaToolCallIndices[0] ?? lastToolCallIndex;
1921
- if (thoughtSignature) {
1922
- const capture = {
1923
- raw: thoughtSignature,
1924
- sequence: artifactSequence,
1925
- ...(signatureToolCallIndex === undefined
1926
- ? {}
1927
- : { toolCallIndex: signatureToolCallIndex }),
1928
- };
1929
- if (signatureToolCallIndex === undefined) {
1930
- pendingThoughtSignatures.push(capture);
1931
- }
1932
- else {
1933
- thoughtSignatures.push(capture);
1934
- }
1935
- }
1936
- if (deltaToolCallIndices.length && pendingThoughtSignatures.length) {
1937
- const toolCallIndex = deltaToolCallIndices[0];
1938
- for (const capture of pendingThoughtSignatures.splice(0)) {
1939
- thoughtSignatures.push({ ...capture, toolCallIndex });
1940
- }
1941
- }
1942
- }
1943
- }
1944
- }
1945
- flushEchoBuffer();
1946
- cleanup();
1947
- requireTerminalProof({
1948
- provider: options.provider,
1949
- policy: terminalPolicy,
1950
- signal: terminalSignal,
1951
- ...emittedByteCounts(),
1952
- });
1953
- const toolCalls = finalizeOpenAiToolCalls(toolCallState);
1954
- emitPrivateReasoningNote(toolCalls.length > 0);
1955
- const reasoningArtifacts = finalReasoningArtifacts(toolCalls);
1956
- emitStreamReasoningArtifacts(options.onStreamEvent, reasoningArtifacts);
1957
- if (!visible.trim() && toolCalls.length === 0) {
1958
- // See [DONE] branch — hand thinking-only streams to the runner so it can
1959
- // salvage sentinel tool blocks (or nudge) instead of hard-failing.
1960
- if (reasoningSeen.trim()) {
1961
- return {
1962
- text: full,
1963
- ...(finishReason ? { finishReason } : { finishReason: "stop" }),
1964
- ...(streamUsage ? { usage: streamUsage } : {}),
1965
- ...(displayReasoningText() ? { reasoningBlock: { text: displayReasoningText() } } : {}),
1966
- ...(reasoningArtifacts ? { reasoningArtifacts } : {}),
1967
- };
1968
- }
1969
- throw new ProviderError(`${options.provider} completed without a visible answer.`);
1970
- }
1971
- return {
1972
- text: full,
1973
- ...(toolCalls.length ? { toolCalls } : {}),
1974
- ...(finishReason
1975
- ? { finishReason }
1976
- : toolCalls.length
1977
- ? { finishReason: "tool_calls" }
1978
- : {}),
1979
- ...(streamUsage ? { usage: streamUsage } : {}),
1980
- ...(displayReasoningText() ? { reasoningBlock: { text: displayReasoningText() } } : {}),
1981
- ...(reasoningArtifacts ? { reasoningArtifacts } : {}),
1982
- };
1983
- }
1984
- catch (error) {
1985
- if (idleFired) {
1986
- const seconds = Math.round(firedBudgetMs / 1000);
1987
- // Preserve the actual watchdog source. Any byte proves the route admitted
1988
- // the request, but a later byte-silence timeout is still a transport
1989
- // failure; only the output watchdog denotes a live keepalive-only/model
1990
- // stall and receives STREAM_STALL_MARKER.
1991
- if (firedWatchdog === "transport" || !sawTransportActivity) {
1992
- if (!sawTransportActivity) {
1993
- // Keep the established wording: both the router's transparent-retry
1994
- // check and classifyStreamFailure key off this phrase to treat a route
1995
- // that never answered as a retriable transport failure.
1996
- throw new ProviderError(`${options.provider} request timed out before any response (${seconds}s) — no data arrived on the connection.`);
1997
- }
1998
- throw new ProviderError(`${options.provider} stream transport timeout (${seconds}s) — no data arrived on the connection after it had started.`);
1999
- }
2000
- throw new ProviderError(`${options.provider} stream stalled — ${STREAM_STALL_MARKER} for ${seconds}s` +
2001
- (sawStreamProgress
2002
- ? " after it had already started producing output. " +
2003
- "The connection stayed open, so the model was most likely buffering one very large tool call. " +
2004
- "Split large writes into smaller sequential calls, or try a smaller model / disable thinking with /effort off."
2005
- : " — the connection stayed open but the model never produced anything. " +
2006
- "Try another model, or disable thinking with /effort off."));
2007
- }
2008
- throw error;
2009
- }
2010
- finally {
2011
- // The success paths used to return without releasing the body, so
2012
- // the socket stayed locked until GC — dozens of leaked connections per
2013
- // long agent turn.
2014
- cleanup();
2015
- void reader.cancel().catch(() => undefined);
2016
- try {
2017
- reader.releaseLock();
2018
- }
2019
- catch {
2020
- // already released
2021
- }
2022
- }
2023
- }
2024
- export async function openAiCompatiblePing(baseUrl, apiKey, headers) {
2025
- const response = await fetch(`${baseUrl}/models`, {
2026
- headers: {
2027
- ...(apiKey ? { authorization: `Bearer ${apiKey}` } : {}),
2028
- ...headers,
2029
- },
2030
- verbose: process.env.CLAI_VERBOSE === "true",
2031
- });
2032
- await readJson(response);
2033
- }
31
+ export { classifyBynaraModel, classifyNvidiaModel } from "./model-families.js";
2034
32
  //# sourceMappingURL=http.js.map