@sema-agent/core 7.55.0 → 7.57.0

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 (502) hide show
  1. package/CHANGELOG.md +1054 -0
  2. package/LICENSE +1 -1
  3. package/dist/agents/cascade.js +1 -1
  4. package/dist/agents/cc-peer-directory.js +1 -0
  5. package/dist/agents/child-model-seat.d.ts +0 -11
  6. package/dist/agents/child-model-seat.js +0 -3
  7. package/dist/agents/list-agents-tool.d.ts +3 -1
  8. package/dist/agents/list-agents-tool.js +7 -7
  9. package/dist/agents/org-delivery-gate.js +3 -4
  10. package/dist/agents/peer-directory.d.ts +22 -4
  11. package/dist/agents/peer-directory.js +24 -2
  12. package/dist/agents/peer-held-queue.d.ts +69 -49
  13. package/dist/agents/peer-held-queue.js +255 -106
  14. package/dist/agents/peer-session-drain.js +65 -45
  15. package/dist/agents/repair-loop.js +2 -2
  16. package/dist/agents/send-message-tool.js +7 -6
  17. package/dist/agents/subagent.d.ts +6 -4
  18. package/dist/agents/subagent.js +72 -68
  19. package/dist/agents/tool-filter.d.ts +7 -5
  20. package/dist/agents/tool-filter.js +12 -9
  21. package/dist/agents/verify.d.ts +3 -2
  22. package/dist/agents/verify.js +3 -3
  23. package/dist/brain/anthropic.js +45 -80
  24. package/dist/brain/media-degrade.d.ts +18 -7
  25. package/dist/brain/media-degrade.js +13 -2
  26. package/dist/brain/model-capability.d.ts +37 -0
  27. package/dist/brain/model-capability.js +34 -0
  28. package/dist/brain/model-presets.d.ts +2 -8
  29. package/dist/brain/model-presets.js +1 -6
  30. package/dist/brain/open-responses.js +23 -34
  31. package/dist/brain/openai.js +25 -96
  32. package/dist/brain/provider-dialect.d.ts +3 -2
  33. package/dist/brain/provider-dialect.js +2 -2
  34. package/dist/brain/reasoning-request.d.ts +96 -0
  35. package/dist/brain/reasoning-request.js +174 -0
  36. package/dist/brain/reasoning.d.ts +11 -11
  37. package/dist/brain/reasoning.js +4 -3
  38. package/dist/brain/request-params.d.ts +13 -4
  39. package/dist/brain/request-params.js +21 -5
  40. package/dist/brain/status-sink.d.ts +20 -0
  41. package/dist/brain/status-sink.js +7 -0
  42. package/dist/brain/stream-engine.d.ts +9 -0
  43. package/dist/brain/stream-engine.js +24 -10
  44. package/dist/brain/stream-shared.d.ts +5 -4
  45. package/dist/brain/stream-shared.js +4 -4
  46. package/dist/core/a2a.d.ts +2 -1
  47. package/dist/core/a2a.js +19 -13
  48. package/dist/core/agent-definition.d.ts +10 -0
  49. package/dist/core/allow-entry.d.ts +23 -23
  50. package/dist/core/allow-entry.js +42 -46
  51. package/dist/core/allow-rule-shadow.d.ts +3 -3
  52. package/dist/core/approval-object.d.ts +21 -5
  53. package/dist/core/approval-object.js +44 -17
  54. package/dist/core/ask-origin.d.ts +66 -20
  55. package/dist/core/ask-origin.js +63 -23
  56. package/dist/core/ask-question.d.ts +51 -8
  57. package/dist/core/ask-question.js +3 -4
  58. package/dist/core/ask-unresolvable-notice.d.ts +8 -3
  59. package/dist/core/ask-unresolvable-notice.js +16 -2
  60. package/dist/core/auto-compaction.d.ts +71 -6
  61. package/dist/core/auto-compaction.js +42 -26
  62. package/dist/core/background-agent-store.d.ts +6 -2
  63. package/dist/core/background-agent-store.js +1 -1
  64. package/dist/core/checkpoint-generation.d.ts +53 -0
  65. package/dist/core/checkpoint-generation.js +35 -0
  66. package/dist/core/checkpoint-queries.d.ts +180 -0
  67. package/dist/core/checkpoint-queries.js +272 -0
  68. package/dist/core/checkpoint-requirements.d.ts +19 -1
  69. package/dist/core/checkpoint-requirements.js +6 -0
  70. package/dist/core/checkpoint-store.d.ts +105 -53
  71. package/dist/core/checkpoint-store.js +43 -20
  72. package/dist/core/cross-boundary-taint.d.ts +6 -5
  73. package/dist/core/cross-boundary-taint.js +5 -5
  74. package/dist/core/decision-receipt.d.ts +37 -3
  75. package/dist/core/decision-receipt.js +17 -17
  76. package/dist/core/delegation-not-started.d.ts +6 -0
  77. package/dist/core/delegation-not-started.js +17 -0
  78. package/dist/core/engine-attestation.d.ts +93 -0
  79. package/dist/core/engine-attestation.js +70 -0
  80. package/dist/core/engine-capabilities.d.ts +4 -1
  81. package/dist/core/engine-capabilities.js +1 -1
  82. package/dist/core/engine-notice.d.ts +32 -12
  83. package/dist/core/engine-notice.js +6 -0
  84. package/dist/core/file-history-store.d.ts +104 -22
  85. package/dist/core/file-history-store.js +37 -19
  86. package/dist/core/gate-fold.d.ts +1 -1
  87. package/dist/core/gate-fold.js +22 -10
  88. package/dist/core/gate-lanes.js +73 -65
  89. package/dist/core/gate-outcome.d.ts +26 -5
  90. package/dist/core/gate-outcome.js +26 -0
  91. package/dist/core/governance-codes.d.ts +5 -1
  92. package/dist/core/governance-codes.js +6 -0
  93. package/dist/core/hooks.d.ts +19 -18
  94. package/dist/core/hooks.js +3 -1
  95. package/dist/core/host-floor.d.ts +128 -0
  96. package/dist/core/host-floor.js +206 -0
  97. package/dist/core/host-target.d.ts +38 -3
  98. package/dist/core/host-target.js +38 -5
  99. package/dist/core/mailbox-store.d.ts +62 -1
  100. package/dist/core/mailbox-store.js +59 -0
  101. package/dist/core/mcp-name-judge.d.ts +46 -0
  102. package/dist/core/mcp-name-judge.js +61 -0
  103. package/dist/core/mcp-probe.d.ts +1 -1
  104. package/dist/core/mcp-probe.js +2 -5
  105. package/dist/core/mcp.d.ts +5 -1
  106. package/dist/core/mcp.js +70 -64
  107. package/dist/core/memory-engine/consolidation-driver.js +4 -3
  108. package/dist/core/memory-engine/delegation-settlement.js +15 -24
  109. package/dist/core/memory-engine/distiller.js +26 -17
  110. package/dist/core/memory-engine/engine.js +4 -4
  111. package/dist/core/memory-engine/layout.d.ts +60 -8
  112. package/dist/core/memory-engine/layout.js +70 -8
  113. package/dist/core/model-seat.d.ts +10 -3
  114. package/dist/core/mods/classic-events.d.ts +67 -0
  115. package/dist/core/mods/classic-events.js +1 -0
  116. package/dist/core/mods/dollar.d.ts +13 -0
  117. package/dist/core/mods/extension-call.d.ts +31 -0
  118. package/dist/core/mods/extension-call.js +43 -0
  119. package/dist/core/mods/kernel/dispatch.d.ts +20 -3
  120. package/dist/core/mods/kernel/dispatch.js +140 -69
  121. package/dist/core/mods/kernel/events.d.ts +47 -11
  122. package/dist/core/mods/kernel/events.js +66 -42
  123. package/dist/core/mods/kernel/index.d.ts +4 -4
  124. package/dist/core/mods/kernel/index.js +2 -2
  125. package/dist/core/mods/kernel/receive.d.ts +39 -5
  126. package/dist/core/mods/kernel/receive.js +290 -17
  127. package/dist/core/mods/kernel/registration.d.ts +33 -2
  128. package/dist/core/mods/kernel/registration.js +6 -7
  129. package/dist/core/mods/kernel/site-rules.d.ts +44 -16
  130. package/dist/core/mods/kernel/site-rules.js +24 -42
  131. package/dist/core/mods/spec-seats.d.ts +69 -0
  132. package/dist/core/mods/spec-seats.js +114 -0
  133. package/dist/core/mods/stations.d.ts +28 -8
  134. package/dist/core/mods/stations.js +29 -13
  135. package/dist/core/mods/tool-call.d.ts +79 -0
  136. package/dist/core/mods/tool-call.js +152 -0
  137. package/dist/core/namespaced-rule-name.d.ts +32 -38
  138. package/dist/core/namespaced-rule-name.js +29 -36
  139. package/dist/core/parent-spec-seat.d.ts +6 -1
  140. package/dist/core/parent-spec-seat.js +2 -0
  141. package/dist/core/park-selfcheck.js +3 -0
  142. package/dist/core/permission-rule-consent.d.ts +24 -3
  143. package/dist/core/permission-rule-consent.js +136 -41
  144. package/dist/core/permission-rule-model.d.ts +57 -5
  145. package/dist/core/permission-rule-model.js +90 -31
  146. package/dist/core/permission-rule-org.d.ts +6 -2
  147. package/dist/core/permission-rule-org.js +8 -4
  148. package/dist/core/permission-rule-provider.d.ts +5 -2
  149. package/dist/core/permission-rule-provider.js +41 -11
  150. package/dist/core/permission-rule-store.d.ts +3 -2
  151. package/dist/core/permission-rule-store.js +11 -2
  152. package/dist/core/permission-rule-sync.js +3 -2
  153. package/dist/core/permission-rule-syntax.d.ts +5 -4
  154. package/dist/core/permission-rule-syntax.js +2 -2
  155. package/dist/core/permission-rules.d.ts +4 -4
  156. package/dist/core/permission-rules.js +11 -20
  157. package/dist/core/persisted-rule-arms.d.ts +2 -2
  158. package/dist/core/persisted-rule-arms.js +10 -12
  159. package/dist/core/principal-name.d.ts +20 -0
  160. package/dist/core/principal-name.js +22 -0
  161. package/dist/core/prompt-section-seat.js +4 -6
  162. package/dist/core/protocol-http-auth.d.ts +40 -5
  163. package/dist/core/protocol-http-auth.js +168 -4
  164. package/dist/core/protocol-naming.d.ts +20 -0
  165. package/dist/core/protocol-naming.js +20 -3
  166. package/dist/core/read-only-shell.d.ts +20 -5
  167. package/dist/core/read-only-shell.js +29 -14
  168. package/dist/core/remote-env.d.ts +37 -1
  169. package/dist/core/remote-env.js +11 -0
  170. package/dist/core/resume-startup-cause.d.ts +24 -2
  171. package/dist/core/resume-startup-cause.js +20 -1
  172. package/dist/core/retired-keys.d.ts +16 -0
  173. package/dist/core/retired-keys.js +16 -4
  174. package/dist/core/rewrite-rejudge.d.ts +60 -0
  175. package/dist/core/rewrite-rejudge.js +36 -0
  176. package/dist/core/roles.d.ts +28 -1
  177. package/dist/core/roles.js +81 -26
  178. package/dist/core/rule-lane-reads.d.ts +20 -15
  179. package/dist/core/rule-lane-reads.js +45 -17
  180. package/dist/core/rule-owner.d.ts +3 -3
  181. package/dist/core/rule-owner.js +3 -2
  182. package/dist/core/runner/announce-once-ledger.d.ts +14 -0
  183. package/dist/core/runner/announce-once-ledger.js +5 -0
  184. package/dist/core/runner/assemble-result.d.ts +1 -0
  185. package/dist/core/runner/assemble-result.js +1 -1
  186. package/dist/core/runner/call-hook-stations.d.ts +3 -2
  187. package/dist/core/runner/caller-roster.d.ts +16 -4
  188. package/dist/core/runner/caller-roster.js +33 -6
  189. package/dist/core/runner/capability-withheld-seat.d.ts +5 -0
  190. package/dist/core/runner/capability-withheld-seat.js +24 -0
  191. package/dist/core/runner/classifier-ladder.d.ts +7 -9
  192. package/dist/core/runner/classifier-ladder.js +3 -3
  193. package/dist/core/runner/compact-session.d.ts +10 -0
  194. package/dist/core/runner/compact-session.js +202 -0
  195. package/dist/core/runner/compaction-call-options.d.ts +2 -2
  196. package/dist/core/runner/compaction-seams.d.ts +21 -1
  197. package/dist/core/runner/compaction-seams.js +11 -8
  198. package/dist/core/runner/construction-doors.js +3 -0
  199. package/dist/core/runner/contracts.d.ts +50 -40
  200. package/dist/core/runner/cross-boundary-lane.d.ts +17 -13
  201. package/dist/core/runner/cross-boundary-lane.js +40 -27
  202. package/dist/core/runner/denial-limit-arms.d.ts +2 -2
  203. package/dist/core/runner/denial-limit-arms.js +1 -1
  204. package/dist/core/runner/derived-route-fallback.d.ts +13 -0
  205. package/dist/core/runner/derived-route-fallback.js +6 -0
  206. package/dist/core/runner/env-capability-census.d.ts +3 -2
  207. package/dist/core/runner/env-capability-census.js +9 -3
  208. package/dist/core/runner/file-history-request.d.ts +18 -0
  209. package/dist/core/runner/file-history-request.js +21 -13
  210. package/dist/core/runner/file-history-restore.d.ts +45 -0
  211. package/dist/core/runner/file-history-restore.js +46 -0
  212. package/dist/core/runner/gate-exit.d.ts +3 -3
  213. package/dist/core/runner/gate-exit.js +4 -3
  214. package/dist/core/runner/image.d.ts +7 -17
  215. package/dist/core/runner/image.js +9 -60
  216. package/dist/core/runner/permission-rule-lanes.d.ts +11 -11
  217. package/dist/core/runner/permission-rule-lanes.js +39 -17
  218. package/dist/core/runner/person-path-rows.d.ts +12 -9
  219. package/dist/core/runner/person-path-rows.js +18 -7
  220. package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
  221. package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
  222. package/dist/core/runner/prepare-ask-lane.d.ts +2 -2
  223. package/dist/core/runner/prepare-ask-lane.js +5 -2
  224. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -6
  225. package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
  226. package/dist/core/runner/prepare-config-doors.d.ts +35 -38
  227. package/dist/core/runner/prepare-config-doors.js +46 -28
  228. package/dist/core/runner/prepare-defer-classify.d.ts +4 -3
  229. package/dist/core/runner/prepare-defer-classify.js +7 -8
  230. package/dist/core/runner/prepare-file-history.d.ts +48 -8
  231. package/dist/core/runner/prepare-file-history.js +7 -39
  232. package/dist/core/runner/prepare-gate-stations.d.ts +1 -1
  233. package/dist/core/runner/prepare-gate-stations.js +10 -1
  234. package/dist/core/runner/prepare-hands-readface.d.ts +5 -9
  235. package/dist/core/runner/prepare-hands-readface.js +17 -14
  236. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
  237. package/dist/core/runner/prepare-inherited-gate.js +5 -3
  238. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  239. package/dist/core/runner/prepare-park-ask.d.ts +2 -0
  240. package/dist/core/runner/prepare-park-ask.js +7 -7
  241. package/dist/core/runner/prepare-policy-chain.d.ts +6 -3
  242. package/dist/core/runner/prepare-policy-chain.js +67 -76
  243. package/dist/core/runner/prepare-prompt-assembly.d.ts +5 -7
  244. package/dist/core/runner/prepare-prompt-assembly.js +10 -8
  245. package/dist/core/runner/prepare-prompt-inputs.d.ts +11 -9
  246. package/dist/core/runner/prepare-prompt-inputs.js +3 -5
  247. package/dist/core/runner/prepare-protocol-tools.d.ts +2 -0
  248. package/dist/core/runner/prepare-protocol-tools.js +3 -3
  249. package/dist/core/runner/prepare-safety-scan.d.ts +1 -1
  250. package/dist/core/runner/prepare-safety-scan.js +0 -17
  251. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  252. package/dist/core/runner/prepare-suspend-saga.js +5 -6
  253. package/dist/core/runner/prepare-task.d.ts +5 -2
  254. package/dist/core/runner/prepare-task.js +48 -43
  255. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +20 -4
  256. package/dist/core/runner/prepare-tool-disclosure-mount.js +33 -23
  257. package/dist/core/runner/prepare-turn-wiring.d.ts +0 -4
  258. package/dist/core/runner/prepare-turn-wiring.js +2 -7
  259. package/dist/core/runner/prepare-wiring-manifest.d.ts +6 -2
  260. package/dist/core/runner/prepare-wiring-manifest.js +3 -3
  261. package/dist/core/runner/resume-admission.js +1 -1
  262. package/dist/core/runner/resume-apply.js +11 -12
  263. package/dist/core/runner/resume-checkpoint-screen.js +3 -0
  264. package/dist/core/runner/resume-claim.d.ts +4 -2
  265. package/dist/core/runner/resume-claim.js +15 -8
  266. package/dist/core/runner/retired-runner-deps.js +1 -0
  267. package/dist/core/runner/rewind-files.d.ts +12 -0
  268. package/dist/core/runner/rewind-files.js +90 -0
  269. package/dist/core/runner/run-attachment-seats.js +2 -1
  270. package/dist/core/runner/run-brain-sinks.d.ts +4 -1
  271. package/dist/core/runner/run-brain-sinks.js +4 -2
  272. package/dist/core/runner/run-harness-handlers.js +12 -4
  273. package/dist/core/runner/run-leg.d.ts +1 -1
  274. package/dist/core/runner/run-leg.js +40 -39
  275. package/dist/core/runner/run-notification-lane.d.ts +2 -0
  276. package/dist/core/runner/run-notification-lane.js +2 -2
  277. package/dist/core/runner/run-recovery-lanes.js +3 -4
  278. package/dist/core/runner/run-settle-and-teardown.js +7 -12
  279. package/dist/core/runner/run-terminal-adoption.js +3 -4
  280. package/dist/core/runner/run-turn-boundary.js +4 -15
  281. package/dist/core/runner/runtask.d.ts +10 -0
  282. package/dist/core/runner/runtask.js +35 -42
  283. package/dist/core/runner/send-message-continuation.js +1 -1
  284. package/dist/core/runner/session-read-file-states.d.ts +15 -0
  285. package/dist/core/runner/session-read-file-states.js +28 -0
  286. package/dist/core/runner/session-rule-policy.js +4 -3
  287. package/dist/core/runner/session-verb-doors.d.ts +28 -0
  288. package/dist/core/runner/session-verb-doors.js +48 -0
  289. package/dist/core/runner/session-write-ledger.d.ts +30 -0
  290. package/dist/core/runner/session-write-ledger.js +101 -0
  291. package/dist/core/runner/shell-env-withheld.d.ts +33 -0
  292. package/dist/core/runner/shell-env-withheld.js +51 -0
  293. package/dist/core/runner/skills-seat.js +6 -2
  294. package/dist/core/runner/stream-settle-backstop.js +12 -15
  295. package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
  296. package/dist/core/runner/sub-agent-deny-lists.js +25 -17
  297. package/dist/core/runner/synthetic-tools.d.ts +6 -0
  298. package/dist/core/runner/synthetic-tools.js +4 -1
  299. package/dist/core/runner/teardown-bounded.d.ts +1 -0
  300. package/dist/core/runner/teardown-bounded.js +1 -0
  301. package/dist/core/runner/tool-disclosure.d.ts +10 -12
  302. package/dist/core/runner/tool-disclosure.js +1 -3
  303. package/dist/core/runner/tool-end-body.d.ts +1 -1
  304. package/dist/core/runner/tool-end-body.js +10 -9
  305. package/dist/core/runner/tool-not-executed.d.ts +5 -0
  306. package/dist/core/runner/tool-not-executed.js +11 -0
  307. package/dist/core/runner/tool-occurrence.d.ts +8 -0
  308. package/dist/core/runner/tool-occurrence.js +7 -0
  309. package/dist/core/runner/turn-attachments.d.ts +33 -15
  310. package/dist/core/runner/turn-attachments.js +62 -37
  311. package/dist/core/runner-deps.d.ts +7 -7
  312. package/dist/core/safety-axis-vocab.d.ts +6 -4
  313. package/dist/core/safety-axis-vocab.js +6 -5
  314. package/dist/core/safety-merge-corpus.js +11 -3
  315. package/dist/core/secret-env.d.ts +30 -3
  316. package/dist/core/secret-env.js +47 -8
  317. package/dist/core/select-model.js +3 -3
  318. package/dist/core/session-policy-store.d.ts +32 -15
  319. package/dist/core/session-policy-store.js +156 -36
  320. package/dist/core/session-store.d.ts +29 -10
  321. package/dist/core/session-store.js +51 -19
  322. package/dist/core/session.d.ts +82 -16
  323. package/dist/core/session.js +53 -0
  324. package/dist/core/shell-read-silence.d.ts +11 -12
  325. package/dist/core/shell-read-silence.js +9 -5
  326. package/dist/core/shell-run-candidates.js +3 -1
  327. package/dist/core/shell-wrapper-projection.d.ts +1 -1
  328. package/dist/core/shell-wrapper-projection.js +1 -1
  329. package/dist/core/shell-wrapper-table.d.ts +14 -7
  330. package/dist/core/shell-wrapper-table.js +5 -4
  331. package/dist/core/side-query.js +10 -1
  332. package/dist/core/skill-grant.d.ts +7 -2
  333. package/dist/core/skill-grant.js +5 -0
  334. package/dist/core/skills-directory.js +6 -2
  335. package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
  336. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +11 -1
  337. package/dist/core/store-contracts/checkpoint-store-contract.js +141 -2
  338. package/dist/core/store-contracts/file-history-store-contract.js +40 -1
  339. package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
  340. package/dist/core/store-contracts/peer-directory-contract.d.ts +7 -2
  341. package/dist/core/store-contracts/peer-directory-contract.js +14 -2
  342. package/dist/core/store-contracts/session-repo-contract.js +51 -0
  343. package/dist/core/store-contracts/session-store-contract.d.ts +2 -1
  344. package/dist/core/store-contracts/session-store-contract.js +150 -14
  345. package/dist/core/stub-env.d.ts +2 -0
  346. package/dist/core/stub-env.js +1 -0
  347. package/dist/core/synthetic-read-verdict.js +3 -3
  348. package/dist/core/task-event.d.ts +32 -4
  349. package/dist/core/task-notification.d.ts +16 -12
  350. package/dist/core/task-registry-agent.d.ts +8 -4
  351. package/dist/core/task-registry-agent.js +14 -8
  352. package/dist/core/task-registry-shared.d.ts +35 -6
  353. package/dist/core/task-registry-shared.js +11 -0
  354. package/dist/core/task-registry.d.ts +10 -1
  355. package/dist/core/task-registry.js +12 -2
  356. package/dist/core/task-result.d.ts +18 -0
  357. package/dist/core/task-spec.d.ts +18 -13
  358. package/dist/core/tighten-task-spec.js +2 -1
  359. package/dist/core/tool-catalog-entries.d.ts +23 -0
  360. package/dist/core/tool-catalog-entries.js +14 -2
  361. package/dist/core/tool-check-reading.d.ts +11 -0
  362. package/dist/core/tool-check-reading.js +11 -6
  363. package/dist/core/tool-model-gate.d.ts +2 -2
  364. package/dist/core/tool-name-aliases.d.ts +48 -18
  365. package/dist/core/tool-name-aliases.js +36 -19
  366. package/dist/core/tool-name-readings.d.ts +6 -32
  367. package/dist/core/tool-name-readings.js +2 -9
  368. package/dist/core/tool-policy.d.ts +78 -204
  369. package/dist/core/tool-policy.js +152 -204
  370. package/dist/core/tool-result-store.js +3 -0
  371. package/dist/core/tool-roster.d.ts +14 -19
  372. package/dist/core/tool-roster.js +11 -44
  373. package/dist/core/tool-spec-members.js +7 -2
  374. package/dist/core/tool-spec.d.ts +19 -11
  375. package/dist/core/tools.js +49 -9
  376. package/dist/core/trace.d.ts +6 -3
  377. package/dist/core/trace.js +2 -1
  378. package/dist/core/types.d.ts +1 -1
  379. package/dist/core/untrusted-egress.d.ts +20 -0
  380. package/dist/core/untrusted-egress.js +77 -3
  381. package/dist/core/user-attachment.d.ts +8 -1
  382. package/dist/core/user-attachment.js +64 -4
  383. package/dist/core/wiring-manifest.d.ts +9 -0
  384. package/dist/core/wiring-manifest.js +1 -0
  385. package/dist/core/workflow-journal-store.js +1 -1
  386. package/dist/engine/compaction/compaction.js +3 -2
  387. package/dist/engine/execution-env/node-execution-env.d.ts +7 -3
  388. package/dist/engine/execution-env/node-execution-env.js +11 -2
  389. package/dist/engine/harness/agent-harness.d.ts +32 -6
  390. package/dist/engine/harness/agent-harness.js +65 -9
  391. package/dist/engine/harness/types.d.ts +29 -2
  392. package/dist/engine/llm/types.d.ts +28 -11
  393. package/dist/engine/loop/agent-loop.d.ts +23 -4
  394. package/dist/engine/loop/agent-loop.js +42 -30
  395. package/dist/engine/loop/types.d.ts +16 -6
  396. package/dist/engine/session/memory-repo.d.ts +9 -2
  397. package/dist/engine/session/memory-repo.js +11 -1
  398. package/dist/engine/session/repo-utils.d.ts +6 -5
  399. package/dist/engine/session/repo-utils.js +14 -6
  400. package/dist/index.d.ts +34 -17
  401. package/dist/index.js +22 -11
  402. package/dist/internal/harness-types.d.ts +1 -1
  403. package/dist/internal/harness.d.ts +2 -1
  404. package/dist/internal/harness.js +1 -0
  405. package/dist/internal/llm.d.ts +1 -1
  406. package/dist/orchestration/run-workflow-tool.d.ts +6 -4
  407. package/dist/orchestration/run-workflow-tool.js +5 -3
  408. package/dist/orchestration/workflow.d.ts +3 -0
  409. package/dist/orchestration/workflow.js +36 -18
  410. package/dist/primitives/credential-ref.d.ts +89 -0
  411. package/dist/primitives/credential-ref.js +125 -0
  412. package/dist/primitives/index.d.ts +2 -0
  413. package/dist/primitives/index.js +1 -0
  414. package/dist/prompt-assembly/artifact.d.ts +2 -2
  415. package/dist/prompt-assembly/artifact.js +5 -3
  416. package/dist/prompt-assembly/assemble.d.ts +3 -2
  417. package/dist/prompt-assembly/assemble.js +1 -1
  418. package/dist/prompt-assembly/catalog/schema.d.ts +43 -12
  419. package/dist/prompt-assembly/catalog/schema.js +34 -2
  420. package/dist/prompt-assembly/catalog/sections.js +0 -1
  421. package/dist/prompt-assembly/composer.d.ts +3 -1
  422. package/dist/prompt-assembly/composer.js +1 -1
  423. package/dist/prompt-assembly/event-registry.js +1 -0
  424. package/dist/prompt-assembly/overlay.js +3 -3
  425. package/dist/prompt-assembly/renderers.d.ts +1 -1
  426. package/dist/prompt-assembly/renderers.js +0 -3
  427. package/dist/prompt-assembly/role-base.d.ts +15 -0
  428. package/dist/prompt-assembly/role-base.js +9 -0
  429. package/dist/prompt-assembly/select.d.ts +39 -14
  430. package/dist/prompt-assembly/select.js +47 -16
  431. package/dist/prompt-assembly/sugar.d.ts +17 -11
  432. package/dist/prompt-assembly/sugar.js +8 -3
  433. package/dist/prompt-assembly/tool-catalog.d.ts +37 -3
  434. package/dist/prompt-assembly/tool-catalog.js +114 -4
  435. package/dist/prompt-assembly/turn-snapshot.d.ts +4 -10
  436. package/dist/prompt-assembly/turn-snapshot.js +0 -3
  437. package/dist/prompt-assembly/types.d.ts +0 -7
  438. package/dist/scenarios/full-body.d.ts +11 -11
  439. package/dist/scenarios/full-body.js +4 -3
  440. package/dist/shell/lex.js +10 -1
  441. package/dist/stores/file/adoption/adopt.js +4 -3
  442. package/dist/stores/file/adoption/marker.js +3 -2
  443. package/dist/stores/file/checkpoint-store.d.ts +21 -4
  444. package/dist/stores/file/checkpoint-store.js +38 -7
  445. package/dist/stores/file/file-history-store.js +18 -11
  446. package/dist/stores/file/index.js +2 -1
  447. package/dist/stores/file/mailbox-store.d.ts +2 -1
  448. package/dist/stores/file/mailbox-store.js +26 -1
  449. package/dist/stores/file/permission-rule-adopt.js +4 -3
  450. package/dist/stores/file/permission-rule-store.js +11 -5
  451. package/dist/stores/file/session-store.d.ts +29 -6
  452. package/dist/stores/file/session-store.js +42 -50
  453. package/dist/tools/artifact/artifact-tool.js +3 -2
  454. package/dist/tools/fs/bash-program-position.d.ts +19 -2
  455. package/dist/tools/fs/bash-program-position.js +56 -9
  456. package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
  457. package/dist/tools/fs/bash-readonly-classifier.js +5 -10
  458. package/dist/tools/fs/fs-bash.js +15 -8
  459. package/dist/tools/fs/fs-glob.d.ts +86 -0
  460. package/dist/tools/fs/fs-glob.js +226 -0
  461. package/dist/tools/fs/fs-read.js +14 -14
  462. package/dist/tools/fs/fs-search-tools.js +7 -7
  463. package/dist/tools/fs/pattern-kill-guard.d.ts +23 -0
  464. package/dist/tools/fs/pattern-kill-guard.js +429 -0
  465. package/dist/tools/fs/pdf.d.ts +9 -6
  466. package/dist/tools/fs/pdf.js +3 -3
  467. package/dist/tools/fs/program-read-model.d.ts +57 -7
  468. package/dist/tools/fs/program-read-model.js +11 -1
  469. package/dist/tools/fs/program-read-model.rows.js +78 -21
  470. package/dist/tools/fs/read-deny-home.js +3 -2
  471. package/dist/tools/fs/removal-targets.d.ts +17 -7
  472. package/dist/tools/fs/removal-targets.js +47 -20
  473. package/dist/tools/fs/search.d.ts +10 -0
  474. package/dist/tools/fs/search.js +20 -26
  475. package/dist/tools/fs/shell-read-argv.js +89 -12
  476. package/dist/tools/fs/shell-read-bindings.d.ts +31 -0
  477. package/dist/tools/fs/shell-read-bindings.js +41 -0
  478. package/dist/tools/fs/shell-read-check.d.ts +10 -0
  479. package/dist/tools/fs/shell-read-check.js +13 -20
  480. package/dist/tools/fs/shell-read-environment.d.ts +5 -1
  481. package/dist/tools/fs/shell-read-environment.js +3 -2
  482. package/dist/tools/fs/shell-read-establish.d.ts +15 -0
  483. package/dist/tools/fs/shell-read-establish.js +19 -20
  484. package/dist/tools/fs/shell-read-identity.d.ts +12 -9
  485. package/dist/tools/fs/shell-read-identity.js +9 -4
  486. package/dist/tools/fs/shell-read-plan.js +24 -16
  487. package/dist/tools/fs/shell-read-start.d.ts +6 -1
  488. package/dist/tools/fs/shell-read-write-targets.d.ts +5 -1
  489. package/dist/tools/fs/shell-read-write-targets.js +2 -3
  490. package/dist/tools/fs/shell-reentry-text.d.ts +9 -0
  491. package/dist/tools/fs/shell-reentry-text.js +40 -2
  492. package/dist/tools/todo.js +63 -63
  493. package/dist/tools/web.d.ts +19 -14
  494. package/dist/tools/web.js +46 -61
  495. package/package.json +1 -1
  496. package/test/export-surface.snapshot.json +221 -7
  497. package/wire-changes/core-stores-sql@7.57.0.json +29 -0
  498. package/wire-changes/core@7.56.0.json +3891 -0
  499. package/wire-changes/core@7.57.0.json +1487 -0
  500. package/wire-changes/mods-kernel@7.56.0.json +303 -0
  501. package/wire-changes/mods-kernel@7.57.0.json +29 -0
  502. package/wire-changes/primitives@7.57.0.json +245 -0
@@ -4,13 +4,14 @@ import { DEGENERATE_MESSAGE, trimDegenerateTail } from "./repetition.js";
4
4
  import { STREAM_TORN_WARNING, createRepetitionPoll, createStreamEndLedger, echoFoldedWord, modelOutputInvalidOf, noteResponseModel, nameMissingCause, parseStreamedToolArgs, placeTurnNotes, truncationCauseClause } from "./stream-shared.js";
5
5
  import { admitToolCallId, providerResultIds, providerToolCallId, responseToolCallIds } from "./tool-call-id.js";
6
6
  import { emitBrainTelemetry } from "./status-sink.js";
7
- import { errorResultMediaNote, IMAGE_OMITTED_NO_VISION, imagesOmittedNoVisionNote, modelSupportsVision, sendableImages } from "./media-degrade.js";
8
- import { OPENAI_RESERVED, OUTPUT_CAP_KEYS, applyExtraBody, effectiveOutputCap, headerBagOnce, lockHeader, mergeHeaders } from "./request-params.js";
7
+ import { errorResultMediaNote, IMAGE_OMITTED_NO_VISION, imageWithholdOf, imagesOmittedNoVisionNote, reportImagesWithheld, sendableImages } from "./media-degrade.js";
8
+ import { capabilityHeld } from "./model-capability.js";
9
+ import { OPENAI_RESERVED, OUTPUT_CAP_KEYS, applyExtraBody, declaredRequestValues, effectiveOutputCap, headerBagOnce, lockHeader, mergeHeaders } from "./request-params.js";
9
10
  import { BrainError, providerErrorWord } from "./errors.js";
10
11
  import { NAMES_AS_WRITTEN, inBandProviderError, resolveProviderDialect, endpointToolNames } from "./provider-dialect.js";
11
12
  import { admitRouteRequest, applyRouteCredentialHeaders, assertServableRequestRoot, brainConfigSnapshot, createBrainRouteJudge, joinRequestUrl, resolveRequestRootOf, resolveRouteCredential } from "./route-adjudicator.js";
12
13
  import { requestRouteOf } from "./request-route.js";
13
- import { declaredOffSpelling, mintEffortWireValue, reasoningRequestCarried } from "./reasoning.js";
14
+ import { applyReasoningToRequest } from "./reasoning-request.js";
14
15
  import { runStreamingBrain } from "./stream-engine.js";
15
16
  import { refuseRetiredTimeoutKnobs } from "./timeout.js";
16
17
  import { resolveFetch } from "./transport.js";
@@ -38,7 +39,7 @@ function textOf(content) {
38
39
  }
39
40
  const NO_CONTENT = "(no content)";
40
41
  const DOCUMENT_OMITTED = "[PDF document omitted: PDF direct read requires an Anthropic-family model; re-Read the file (the engine will extract text/render pages when possible) or extract the text via Bash instead (e.g. `pdftotext`).]";
41
- function toUserContent(content, supportsVision = true) {
42
+ function toUserContent(content, withhold) {
42
43
  if (typeof content === "string") {
43
44
  return content;
44
45
  }
@@ -52,9 +53,9 @@ function toUserContent(content, supportsVision = true) {
52
53
  return base;
53
54
  return base ? `${base}\n${DOCUMENT_OMITTED}` : DOCUMENT_OMITTED;
54
55
  }
55
- if (!supportsVision) {
56
+ if (withhold !== undefined) {
56
57
  const n = content.filter((c) => c.type === "image").length;
57
- emitBrainTelemetry({ kind: "vision_placeholder", count: n });
58
+ reportImagesWithheld(withhold, n);
58
59
  const base = textOf(content);
59
60
  const note = imagesOmittedNoVisionNote(n);
60
61
  const withNote = base ? `${base}\n${note}` : note;
@@ -80,85 +81,11 @@ function toUserContent(content, supportsVision = true) {
80
81
  function thinkingCompat(model) {
81
82
  return (model.compat ?? {});
82
83
  }
83
- function applyThinking(body, model, reasoning) {
84
- if (model.reasoning && reasoning === "off") {
85
- const offCompat = thinkingCompat(model);
86
- const offFormat = offCompat.thinkingFormat ?? "openai";
87
- switch (offFormat) {
88
- case "qwen":
89
- case "zai":
90
- body.enable_thinking = false;
91
- break;
92
- case "qwen-chat-template": {
93
- const k = (typeof body.chat_template_kwargs === "object" && body.chat_template_kwargs) || {};
94
- body.chat_template_kwargs = { ...k, enable_thinking: false };
95
- break;
96
- }
97
- case "deepseek":
98
- body.thinking = { type: "disabled" };
99
- break;
100
- case "openrouter":
101
- case "together":
102
- body.reasoning = { enabled: false };
103
- break;
104
- case "openai": {
105
- const offSpelling = declaredOffSpelling(model);
106
- if (offSpelling !== undefined)
107
- body.reasoning_effort = offSpelling;
108
- break;
109
- }
110
- default: {
111
- const _exhaustive = offFormat;
112
- void _exhaustive;
113
- break;
114
- }
115
- }
116
- return;
117
- }
118
- if (!reasoningRequestCarried(model, reasoning))
119
- return;
120
- const compat = thinkingCompat(model);
121
- const supportsEffort = compat.supportsReasoningEffort ?? true;
122
- const effortWire = mintEffortWireValue(reasoning, model, compat.reasoningEffortLevels).wireValue;
123
- const format = compat.thinkingFormat ?? "openai";
124
- switch (format) {
125
- case "openai":
126
- if (supportsEffort && effortWire !== undefined)
127
- body.reasoning_effort = effortWire;
128
- break;
129
- case "openrouter":
130
- body.reasoning = { effort: effortWire };
131
- break;
132
- case "deepseek":
133
- body.thinking = { type: "enabled" };
134
- if (supportsEffort && effortWire !== undefined)
135
- body.reasoning_effort = effortWire;
136
- break;
137
- case "together":
138
- body.reasoning = { enabled: true };
139
- if (supportsEffort && effortWire !== undefined)
140
- body.reasoning_effort = effortWire;
141
- break;
142
- case "qwen":
143
- case "zai":
144
- body.enable_thinking = true;
145
- break;
146
- case "qwen-chat-template": {
147
- const k = (typeof body.chat_template_kwargs === "object" && body.chat_template_kwargs) || {};
148
- body.chat_template_kwargs = { ...k, enable_thinking: true };
149
- break;
150
- }
151
- default: {
152
- const _exhaustive = format;
153
- void _exhaustive;
154
- break;
155
- }
156
- }
157
- }
158
84
  function toOpenAIMessages(ctx, replayThinking = true, model, toolNames) {
159
- const supportsVision = modelSupportsVision(model);
85
+ const imageWithhold = imageWithholdOf(model);
86
+ const supportsVision = imageWithhold === undefined;
160
87
  const out = [];
161
- const needsEmptyReasoningField = !!model?.reasoning && thinkingCompat(model).requiresReasoningContentOnAssistantMessages === true;
88
+ const needsEmptyReasoningField = model !== undefined && capabilityHeld(model, "reasoning") && thinkingCompat(model).requiresReasoningContentOnAssistantMessages === true;
162
89
  if (ctx.systemPrompt) {
163
90
  out.push({ role: "system", content: ctx.systemPrompt });
164
91
  }
@@ -181,7 +108,7 @@ function toOpenAIMessages(ctx, replayThinking = true, model, toolNames) {
181
108
  if (m.role !== "toolResult")
182
109
  flushImages();
183
110
  if (m.role === "user") {
184
- const uc = toUserContent(m.content, supportsVision);
111
+ const uc = toUserContent(m.content, imageWithhold);
185
112
  const empty = uc === "" || (Array.isArray(uc) && uc.length === 0);
186
113
  out.push({ role: "user", content: empty ? NO_CONTENT : uc });
187
114
  }
@@ -215,8 +142,8 @@ function toOpenAIMessages(ctx, replayThinking = true, model, toolNames) {
215
142
  const mediaImages = sendableImages(Array.isArray(m.content) ? m.content : []);
216
143
  const rawImages = m.isError ? [] : mediaImages;
217
144
  const images = supportsVision ? rawImages : [];
218
- if (!supportsVision && rawImages.length > 0)
219
- emitBrainTelemetry({ kind: "vision_placeholder", count: rawImages.length });
145
+ if (imageWithhold !== undefined)
146
+ reportImagesWithheld(imageWithhold, rawImages.length);
220
147
  const nDocs = Array.isArray(m.content) ? m.content.filter((c) => c.type === "document").length : 0;
221
148
  if (nDocs > 0)
222
149
  emitBrainTelemetry({ kind: "document_placeholder", count: nDocs });
@@ -390,16 +317,18 @@ export function createOpenAIBrain(given = {}) {
390
317
  }
391
318
  if (options?.stop)
392
319
  body.stop = options.stop;
393
- applyThinking(body, model, options?.reasoning);
320
+ const { body: reasoningBody } = applyReasoningToRequest({ api: "openai-completions", model, level: options?.reasoning, body });
394
321
  const headers = mergeHeaders(modelHeaders, config.headers, optionsHeaders);
395
322
  applyRouteCredentialHeaders(headers, routeCredential);
323
+ const declaredValues = declaredRequestValues([modelHeaders, config.headers, optionsHeaders, headers], [], apiKey);
396
324
  lockHeader(headers, "content-type", "application/json");
397
325
  if (apiKey)
398
326
  lockHeader(headers, OPENAI_KEY_HEADER, `Bearer ${apiKey}`);
399
- const { body: wire, dropped: extraBodyDropped } = applyExtraBody(body, model, OPENAI_RESERVED);
327
+ const { body: wire, dropped: extraBodyDropped } = applyExtraBody(reasoningBody, model, OPENAI_RESERVED);
400
328
  return {
401
329
  url,
402
330
  headers,
331
+ declared: declaredValues,
403
332
  body: JSON.stringify(wire),
404
333
  extraBodyDropped,
405
334
  route: requestRouteOf(routeCredential, rootOrigin),
@@ -432,7 +361,7 @@ export function createOpenAIBrain(given = {}) {
432
361
  const responseIds = responseToolCallIds();
433
362
  let finishReason = null;
434
363
  let inBandError;
435
- const afterEnd = createStreamEndLedger();
364
+ const afterEnd = createStreamEndLedger(ctrl.providerWords);
436
365
  const terminalFrameSeen = () => finishReason != null || inBandError !== undefined;
437
366
  let usageRaw;
438
367
  let malformedFrames = 0;
@@ -520,7 +449,7 @@ export function createOpenAIBrain(given = {}) {
520
449
  }
521
450
  catch {
522
451
  malformedFrames++;
523
- malformedSample ??= data.slice(0, 160);
452
+ malformedSample ??= ctrl.providerWords(data).slice(0, 160);
524
453
  return;
525
454
  }
526
455
  const stated = chunk.error;
@@ -529,7 +458,7 @@ export function createOpenAIBrain(given = {}) {
529
458
  afterEnd.note("error", providerErrorWord(stated) ?? "?");
530
459
  return;
531
460
  }
532
- inBandError = inBandProviderError(ctrl.dialect, stated, "gateway");
461
+ inBandError = inBandProviderError(ctrl.dialect, stated, "gateway", ctrl.providerWords);
533
462
  ctrl.cancel();
534
463
  return;
535
464
  }
@@ -610,7 +539,7 @@ export function createOpenAIBrain(given = {}) {
610
539
  emptyPlaceholders++;
611
540
  continue;
612
541
  }
613
- (nameMissingCause(!endedCut) === "truncated" ? malformed : unnamed).push(`id="${acc.id || "?"}"(${acc.args.slice(0, 200)})`);
542
+ (nameMissingCause(!endedCut) === "truncated" ? malformed : unnamed).push(`id="${ctrl.providerWords(acc.id || "?")}"(${ctrl.providerWords(acc.args).slice(0, 200)})`);
614
543
  continue;
615
544
  }
616
545
  const tc = closeToolCallAccum(acc, responseIds, !endedCut);
@@ -619,7 +548,7 @@ export function createOpenAIBrain(given = {}) {
619
548
  finalContent.push(tc);
620
549
  }
621
550
  else {
622
- malformed.push(`${acc.name}(${acc.args.slice(0, 200)})`);
551
+ malformed.push(`${ctrl.providerWords(acc.name)}(${ctrl.providerWords(acc.args).slice(0, 200)})`);
623
552
  }
624
553
  }
625
554
  if (config.repairTextToolCalls && toolCalls.length === 0 && textFace && context.tools && context.tools.length > 0) {
@@ -677,8 +606,8 @@ export function createOpenAIBrain(given = {}) {
677
606
  const safetyCut = finishReading?.kind === "refusal";
678
607
  const contextWindowExceeded = finishReading?.kind === "input_too_long";
679
608
  const providerCut = finishReading?.kind === "provider_cut" ? finishReading : undefined;
680
- const finishReasonUnknown = finishReading?.kind === "unrecognized" ? echoFoldedWord(finishReason ?? "") : undefined;
681
- const finishQuoted = JSON.stringify((finishReason ?? "").slice(0, 64));
609
+ const finishReasonUnknown = finishReading?.kind === "unrecognized" ? echoFoldedWord(finishReason ?? "", ctrl.providerWords) : undefined;
610
+ const finishQuoted = JSON.stringify(ctrl.providerWords(finishReason ?? "").slice(0, 64));
682
611
  const refused = accumRefusal.trim().length > 0;
683
612
  const emptyNoFinish = noUsableContent && finishReason == null && !degenerate;
684
613
  const maxTokensNote = sentMaxTokens !== undefined
@@ -693,7 +622,7 @@ export function createOpenAIBrain(given = {}) {
693
622
  : safetyCut
694
623
  ? `[refusal] response cut by the provider content filter (finish_reason=${finishQuoted}) — the output was censored/truncated for policy and is unreliable`
695
624
  : refused
696
- ? `[refusal] response refused by the model for policy reasons: ${accumRefusal.trim()}`
625
+ ? `[refusal] response refused by the model for policy reasons: ${ctrl.providerWords(accumRefusal.trim())}`
697
626
  : contextWindowExceeded
698
627
  ? `[invalid_request] model context window exceeded (finish_reason=${finishQuoted}) — the conversation no longer fits the model's context window`
699
628
  : providerCut !== undefined
@@ -240,11 +240,12 @@ export declare function judgeInBandError(dialect: ProviderDialect | undefined, e
240
240
  * The failure an in-band error frame states, as the brain error the stream's terminal carries: the code its
241
241
  * condition reads as ({@link PROVIDER_CONDITION_TRAITS}), the provider's word and sentence in the message, the word
242
242
  * on the echo seat, the verdict, and the context-limit reading of the same row. A frame the provider sent on its
243
- * own stream is a provider failure by construction (`apiError`); it states no status.
243
+ * own stream is a provider failure by construction (`apiError`); it states no status. The message carries the
244
+ * provider's words as the stream's mint (`providerWords`) renders them; the verdict reads the frame as it came.
244
245
  */
245
246
  export declare function inBandProviderError(dialect: ProviderDialect | undefined, envelope: {
246
247
  message?: unknown;
247
248
  code?: unknown;
248
249
  type?: unknown;
249
- }, label: string): BrainError;
250
+ }, label: string, providerWords: (words: string) => string): BrainError;
250
251
  export {};
@@ -201,11 +201,11 @@ export function judgeHttpFailure(args) {
201
201
  export function judgeInBandError(dialect, envelope) {
202
202
  return verdictOf(dialect, undefined, statementOf(envelope), true);
203
203
  }
204
- export function inBandProviderError(dialect, envelope, label) {
204
+ export function inBandProviderError(dialect, envelope, label, providerWords) {
205
205
  const v = judgeInBandError(dialect, envelope);
206
206
  const word = carriedProviderWord(envelope);
207
207
  const sentence = typeof envelope.message === "string" ? envelope.message : "";
208
- return new BrainError(PROVIDER_CONDITION_TRAITS[v.condition].inBandCode, `${label} stream error (${word ?? "unknown"}): ${sentence}`, undefined, {
208
+ return new BrainError(PROVIDER_CONDITION_TRAITS[v.condition].inBandCode, `${label} stream error ${providerWords(`(${word ?? "unknown"}): ${sentence}`)}`, undefined, {
209
209
  apiError: true,
210
210
  ...(v.inputTooLong === "yes" ? { inputTooLong: true } : v.inputTooLong === "no" ? { inputTooLongRuledOut: true } : {}),
211
211
  ...(word !== undefined ? { providerCode: word } : {}),
@@ -0,0 +1,96 @@
1
+ import { type OffCapabilityModel, type ReasoningWireFacts } from "./reasoning.js";
2
+ /**
3
+ * THE reasoning WIRE applier — the one place that knows how a requested thinking tier is spelled on each
4
+ * wire family. The three brains (completions, Responses, Messages) build their requests through
5
+ * {@link applyReasoningToRequest}, and a host that sends its own request to one of those endpoints (a title
6
+ * generator, a side query) calls the same function with the same model entry, so the keys it puts on the wire
7
+ * are the keys the engine would have put there — nothing is re-spelled per caller.
8
+ *
9
+ * What is decided elsewhere and only READ here: whether the request carries thinking at all
10
+ * ({@link reasoningRequestCarried}), the tier clamp and the `thinkingLevelMap` translation
11
+ * ({@link mintEffortWireValue}), and whether "off" has a deployment-declared spelling ({@link declaredOffSpelling}).
12
+ */
13
+ /** The tiers a request for the answer alone can ask for: `off` where the wire spells it, `low` where it cannot. */
14
+ export type ReasoningSeat = "off" | "low";
15
+ /**
16
+ * The lowest reasoning tier a request for the answer alone can take on this model's wire — one predicate: does the wire
17
+ * spell off ({@link thinkingOffSpelled})? Yes ⇒ `"off"`, and the output cap needs room for the answer only. No ⇒ `"low"`:
18
+ * a model whose thinking the wire cannot turn off is asked for the least it can grade, and the cap needs room for that
19
+ * thinking too — `AUTO_MODE_CLASSIFIER_LOW_REASONING_BUDGET_TOKENS` is the allowance the engine's own side requests add.
20
+ * A model that declares no reasoning is on the `low` seat as well: its wire carries nothing either way, so the request is
21
+ * the gateway's default, and a default-on gateway thinks.
22
+ *
23
+ * Callers pass the seat as `level` to {@link applyReasoningToRequest}; the classifier's seat tier is this verdict.
24
+ */
25
+ export declare function lowestReasoningSeat(model: OffCapabilityModel): ReasoningSeat;
26
+ /** The model entry the applier reads. A `Model` satisfies it; `id` only names the model in a refusal. */
27
+ export interface ReasoningRequestModel extends OffCapabilityModel {
28
+ readonly id?: string;
29
+ }
30
+ /** The Messages-family knobs a host may set (the engine's own lane sets them from its construction config). */
31
+ export interface ReasoningBudgetKnobs {
32
+ /**
33
+ * Whether `body.max_tokens` is a bound the caller set. `true` (the default): the cap is never raised, and thinking
34
+ * is skipped when the cap cannot host a legal budget plus answer room. `false`: the cap is a default the lane
35
+ * raises to host one.
36
+ */
37
+ capIsHard?: boolean;
38
+ /** The share of `max_tokens` the thinking budget takes; absent = the tier's own share. */
39
+ share?: number;
40
+ /** A fixed budget in tokens; overrides `share`. */
41
+ tokens?: number;
42
+ }
43
+ export interface ApplyReasoningInput {
44
+ /**
45
+ * The wire family of the request: `"anthropic-messages"` (Messages), one of the Open Responses apis
46
+ * (`openai-responses`, `azure-openai-responses`, `openai-chatgpt-responses`), anything else = the chat-completions
47
+ * family, whose `model.compat.thinkingFormat` picks the dialect. A host passes the model entry's own `api`.
48
+ */
49
+ api: string;
50
+ model: ReasoningRequestModel;
51
+ /** The requested tier. `"off"` is spelled where the wire has an off spelling; `undefined` and any value that is
52
+ * not a {@link ThinkingLevel} write nothing (the provider's default). */
53
+ level: string | undefined;
54
+ /** The request body so far. Never mutated — the result carries a copy. */
55
+ body: Readonly<Record<string, unknown>>;
56
+ /** Messages family only: a body with no numeric `max_tokens` is refused where the budget needs one. */
57
+ budget?: ReasoningBudgetKnobs;
58
+ }
59
+ export interface AppliedReasoning {
60
+ /** A copy of the input body with the thinking keys written (and, on Messages, `temperature` dropped when thinking is on). */
61
+ body: Record<string, unknown>;
62
+ /**
63
+ * The request headers the thinking keys need, to be folded into the request's own with
64
+ * {@link mergeReasoningHeaders}: the Messages family's `anthropic-beta` list (effort, context management,
65
+ * interleaved thinking — whichever the model entry declares). `{}` where the wire needs none.
66
+ */
67
+ headers: Record<string, string>;
68
+ /** The effort value the request carries (completions `reasoning_effort`, Responses `reasoning.effort`), or `undefined`. */
69
+ effort: string | undefined;
70
+ /** Messages budget form only: the output-cap facts the thinking decision weighed (see {@link ReasoningWireFacts}). */
71
+ wireFacts: ReasoningWireFacts | undefined;
72
+ }
73
+ /**
74
+ * Write the thinking keys a requested tier needs onto a request body, in the dialect of the model's wire family, and
75
+ * say which headers the keys need. A pure function of (api, model entry, level, body): the input body is not mutated,
76
+ * the result carries the body to send and the headers to fold into the request's own.
77
+ *
78
+ * It answers the question a host that builds its own request has — "which keys does THIS model take for THIS tier?" —
79
+ * from the same table the engine's brains read, so a host never keeps a copy of a dialect. Absence is meaningful:
80
+ * a model that does not declare `reasoning`, a `level` that is `undefined` or not a real tier, and a tier the wire
81
+ * cannot carry write nothing, and the provider's default governs.
82
+ *
83
+ * @example
84
+ * const { body, headers } = applyReasoningToRequest({ api: model.api, model, level: "low", body: { model: model.id, max_tokens: 2304, messages } });
85
+ * mergeReasoningHeaders(requestHeaders, headers);
86
+ */
87
+ export declare function applyReasoningToRequest(input: ApplyReasoningInput): AppliedReasoning;
88
+ /**
89
+ * Fold the header patch {@link applyReasoningToRequest} returned into a request's headers, in place. A beta LIST
90
+ * (`anthropic-beta`) is unioned with whatever the request already sends under that name in any letter case and in any
91
+ * number of spellings (a spelling that holds no string contributes none and is claimed all the same) — the existing
92
+ * entries first, as given, then each new entry not already there, written under the lowercase name; any other name
93
+ * replaces its case variants. Assigning the patch over the headers instead would drop a beta the request already carries.
94
+ * This is the ONE reading of the beta list: the Messages brain folds its own header layers through it too.
95
+ */
96
+ export declare function mergeReasoningHeaders(headers: Record<string, string>, patch: Readonly<Record<string, string>>): void;
@@ -0,0 +1,174 @@
1
+ import { capabilityHeld } from "./model-capability.js";
2
+ import { headerListEntries, lockHeader, takeHeaderSpellings } from "./request-params.js";
3
+ import { MIN_THINKING_TOKENS, RESPONSES_APIS, budgetCapSkipsThinking, declaredEffortLevels, declaredOffSpelling, mintEffortWireValue, reasoningBudgetShare, reasoningRequestCarried, resolveEffort, thinkingOffSpelled, } from "./reasoning.js";
4
+ export function lowestReasoningSeat(model) {
5
+ return thinkingOffSpelled(model) ? "off" : "low";
6
+ }
7
+ const BETA_EFFORT = "effort-2025-11-24";
8
+ const BETA_CONTEXT_MANAGEMENT = "context-management-2025-06-27";
9
+ const BETA_INTERLEAVED_THINKING = "interleaved-thinking-2025-05-14";
10
+ function put(body, key, value) {
11
+ body[key] = value;
12
+ return undefined;
13
+ }
14
+ function withTemplateKwarg(body, enabled) {
15
+ const kwargs = (typeof body.chat_template_kwargs === "object" && body.chat_template_kwargs) || {};
16
+ return put(body, "chat_template_kwargs", { ...kwargs, enable_thinking: enabled });
17
+ }
18
+ function withEffort(body, effort, supportsEffort) {
19
+ if (!supportsEffort || effort === undefined)
20
+ return undefined;
21
+ body.reasoning_effort = effort;
22
+ return effort;
23
+ }
24
+ const COMPLETIONS_DIALECT = {
25
+ openai: {
26
+ off: (body, model) => {
27
+ const spelling = declaredOffSpelling(model);
28
+ return spelling === undefined ? undefined : withEffort(body, spelling, true);
29
+ },
30
+ on: withEffort,
31
+ },
32
+ openrouter: {
33
+ off: (body) => put(body, "reasoning", { enabled: false }),
34
+ on: (body, effort) => {
35
+ put(body, "reasoning", { effort });
36
+ return effort;
37
+ },
38
+ },
39
+ deepseek: {
40
+ off: (body) => put(body, "thinking", { type: "disabled" }),
41
+ on: (body, effort, supportsEffort) => {
42
+ put(body, "thinking", { type: "enabled" });
43
+ return withEffort(body, effort, supportsEffort);
44
+ },
45
+ },
46
+ together: {
47
+ off: (body) => put(body, "reasoning", { enabled: false }),
48
+ on: (body, effort, supportsEffort) => {
49
+ put(body, "reasoning", { enabled: true });
50
+ return withEffort(body, effort, supportsEffort);
51
+ },
52
+ },
53
+ qwen: { off: (body) => put(body, "enable_thinking", false), on: (body) => put(body, "enable_thinking", true) },
54
+ zai: { off: (body) => put(body, "enable_thinking", false), on: (body) => put(body, "enable_thinking", true) },
55
+ "qwen-chat-template": { off: (body) => withTemplateKwarg(body, false), on: (body) => withTemplateKwarg(body, true) },
56
+ };
57
+ function completionsDialectOf(format) {
58
+ return typeof format === "string" && Object.prototype.hasOwnProperty.call(COMPLETIONS_DIALECT, format) ? COMPLETIONS_DIALECT[format] : undefined;
59
+ }
60
+ const bodyOnly = (body, effort) => ({ body, headers: {}, effort, wireFacts: undefined });
61
+ function applyCompletions(input, body) {
62
+ const { model, level } = input;
63
+ const compat = (model.compat ?? {});
64
+ const dialect = completionsDialectOf(compat.thinkingFormat ?? "openai");
65
+ if (capabilityHeld(model, "reasoning") && level === "off")
66
+ return bodyOnly(body, dialect?.off(body, model));
67
+ if (!reasoningRequestCarried(model, level))
68
+ return bodyOnly(body);
69
+ const supportsEffort = compat.supportsReasoningEffort ?? true;
70
+ const wire = mintEffortWireValue(level, model, compat.reasoningEffortLevels).wireValue;
71
+ return bodyOnly(body, dialect?.on(body, wire, supportsEffort));
72
+ }
73
+ function applyResponses(input, body) {
74
+ const { model, level } = input;
75
+ const effort = responsesEffort(model, level);
76
+ if (effort !== undefined)
77
+ body.reasoning = { effort };
78
+ return bodyOnly(body, effort);
79
+ }
80
+ function responsesEffort(model, level) {
81
+ if (capabilityHeld(model, "reasoning") && level === "off")
82
+ return declaredOffSpelling(model);
83
+ const compat = (model.compat ?? {});
84
+ if (compat.supportsReasoningEffort === false)
85
+ return undefined;
86
+ if (!reasoningRequestCarried(model, level))
87
+ return undefined;
88
+ return mintEffortWireValue(level, model, compat.reasoningEffortLevels).wireValue;
89
+ }
90
+ function thinkingBudget(maxTokens, share, fixed, hardCap) {
91
+ const max = hardCap ? maxTokens : Math.max(maxTokens, MIN_THINKING_TOKENS * 2);
92
+ const want = fixed ?? Math.floor(max * share);
93
+ const budget = Math.min(Math.max(MIN_THINKING_TOKENS, want), max - 1);
94
+ return { max, budget };
95
+ }
96
+ function applyMessages(input, body) {
97
+ const { model, level } = input;
98
+ const compat = (model.compat ?? {});
99
+ let wireFacts;
100
+ let thinkingOn = false;
101
+ if (reasoningRequestCarried(model, level)) {
102
+ if (compat.thinkingMode === "adaptive") {
103
+ body.thinking = { type: "adaptive" };
104
+ thinkingOn = true;
105
+ }
106
+ else {
107
+ if (body.max_tokens === undefined || body.max_tokens === null) {
108
+ throw new TypeError("applyReasoningToRequest: the Messages budget form needs a body.max_tokens (it sizes the thinking budget)");
109
+ }
110
+ const maxTokens = body.max_tokens;
111
+ const hardCap = input.budget?.capIsHard ?? true;
112
+ wireFacts = { outputCapTokens: maxTokens, hardOutputCap: hardCap };
113
+ if (budgetCapSkipsThinking(wireFacts.outputCapTokens, wireFacts.hardOutputCap)) {
114
+ delete body.thinking;
115
+ }
116
+ else {
117
+ const share = input.budget?.share ?? reasoningBudgetShare(level);
118
+ const { max, budget } = thinkingBudget(maxTokens, share, input.budget?.tokens, hardCap);
119
+ if (!Number.isFinite(Number(max)) || !Number.isFinite(budget)) {
120
+ const shown = (value) => (typeof value === "string" ? JSON.stringify(value) : String(value));
121
+ throw new TypeError(`applyReasoningToRequest: the Messages budget form cannot size a thinking budget from body.max_tokens ${shown(body.max_tokens)}, ` +
122
+ `budget.share ${shown(share)}, budget.tokens ${shown(input.budget?.tokens)} (cap ${shown(max)}, budget ${shown(budget)}); each must read as a finite number`);
123
+ }
124
+ body.max_tokens = max;
125
+ body.thinking = { type: "enabled", budget_tokens: budget };
126
+ thinkingOn = true;
127
+ }
128
+ }
129
+ if (thinkingOn)
130
+ delete body.temperature;
131
+ }
132
+ else if (capabilityHeld(model, "reasoning") && level === "off" && compat.thinkingMode !== "adaptive") {
133
+ body.thinking = { type: "disabled" };
134
+ }
135
+ const betas = [];
136
+ let effort;
137
+ const declaredEffort = declaredEffortLevels(compat.effortLevels);
138
+ if (declaredEffort !== undefined && reasoningRequestCarried(model, level)) {
139
+ const { effective } = resolveEffort(level, declaredEffort);
140
+ effort = effective === "minimal" ? "low" : effective;
141
+ body.output_config = { effort };
142
+ betas.push(BETA_EFFORT);
143
+ }
144
+ if (compat.contextManagement && thinkingOn) {
145
+ body.context_management = { edits: [{ type: "clear_thinking_20251015", keep: "all" }] };
146
+ betas.push(BETA_CONTEXT_MANAGEMENT);
147
+ }
148
+ if (compat.interleavedThinking)
149
+ betas.push(BETA_INTERLEAVED_THINKING);
150
+ return { body, headers: betas.length > 0 ? { "anthropic-beta": betas.join(",") } : {}, effort, wireFacts };
151
+ }
152
+ export function applyReasoningToRequest(input) {
153
+ const body = { ...input.body };
154
+ if (input.api === "anthropic-messages")
155
+ return applyMessages(input, body);
156
+ if (RESPONSES_APIS.has(input.api))
157
+ return applyResponses(input, body);
158
+ return applyCompletions(input, body);
159
+ }
160
+ export function mergeReasoningHeaders(headers, patch) {
161
+ for (const [name, value] of Object.entries(patch)) {
162
+ const lower = name.toLowerCase();
163
+ if (lower !== "anthropic-beta") {
164
+ lockHeader(headers, lower, value);
165
+ continue;
166
+ }
167
+ const present = takeHeaderSpellings(headers, lower).flatMap((held) => headerListEntries(held));
168
+ for (const beta of headerListEntries(value)) {
169
+ if (!present.includes(beta))
170
+ present.push(beta);
171
+ }
172
+ headers[lower] = present.join(",");
173
+ }
174
+ }
@@ -18,8 +18,8 @@ export type ReasoningIntensity = ThinkingLevel;
18
18
  export declare function isThinkingLevel(v: unknown): v is ThinkingLevel;
19
19
  /**
20
20
  * THE thinking-request ENTRY predicate — does this request enter an applier's emission path at all?
21
- * One conjunction, three arms: the model declares reasoning (TRUTHINESS — the adapters' own
22
- * judgment, see the r5 note in {@link resolveReasoning}), the requested value is a real
21
+ * One conjunction, three arms: the model holds reasoning (`capabilityHeld`, the one capability reading —
22
+ * a declaration of the wrong shape throws there instead of reading by truthiness), the requested value is a real
23
23
  * {@link ThinkingLevel} (an out-of-contract value — a typo'd tier, a caller's own enum — reads as
24
24
  * ABSENCE, never as a declared tier), and it is not the explicit `"off"`.
25
25
  *
@@ -29,8 +29,8 @@ export declare function isThinkingLevel(v: unknown): v is ThinkingLevel;
29
29
  * their own reporting shape (the `graded:false` intent-echo family, each pinned with its rationale
30
30
  * where it lives); this predicate only closes the gate the three appliers used to re-spell.
31
31
  *
32
- * Single-sourced here because every wire applier (openai.ts `applyThinking`, anthropic.ts's thinking
33
- * + effort arms, open-responses.ts `resolveWireEffort`) would otherwise re-spell the same three
32
+ * Single-sourced here because every wire applier (the completions, Messages and Responses arms of
33
+ * `applyReasoningToRequest`, in reasoning-request.ts) would otherwise re-spell the same three
34
34
  * conjuncts while the REPORTING resolver ({@link resolveReasoning}) mirrored one of them, so a
35
35
  * garbage tier puts ZERO parameters on the wire while the resolution claims a clamped-to-minimal
36
36
  * gradient. A predicate the appliers and the reporter both call cannot drift.
@@ -58,7 +58,7 @@ export type ReasoningFormat = "openai" | "openrouter" | "deepseek" | "together"
58
58
  * `reasoning_effort` path (thinking FORM is `thinkingMode`; effort carries the intensity). */
59
59
  | "effort"
60
60
  /** OpenAI Responses API (`openai-responses` / `azure-openai-responses`, design/163): the tier rides
61
- * the NESTED `reasoning: { effort }` request field (open-responses.ts `resolveWireEffort`), clamped
61
+ * the NESTED `reasoning: { effort }` request field (the Responses arm of `applyReasoningToRequest`), clamped
62
62
  * by the same {@link resolveEffort} against `compat.reasoningEffortLevels` — NOT the completions
63
63
  * top-level `reasoning_effort` the `"openai"` tag names. #325 review r3: before this member the
64
64
  * resolver fell through to the completions default and labeled Responses resolutions `"openai"`. */
@@ -127,7 +127,7 @@ export declare function declaredOffSpelling(model: OffCapabilityModel): string |
127
127
  * `reasoning:{enabled:false}` all spell it; the effort-only wires (stock openai completions, the Responses
128
128
  * lane) spell it only through a deployment-declared off spelling ({@link declaredOffSpelling}).
129
129
  *
130
- * A model whose `reasoning` is FALSY spells NOTHING: every applier returns before writing any key for it, so
130
+ * A model that does not hold reasoning (declared false, or undeclared — `capabilityHeld`) spells NOTHING: every applier returns before writing any key for it, so
131
131
  * the request is the gateway's own default — and a default-on gateway thinks regardless (three of four live
132
132
  * endpoints, 2026-09-15). This arm used to answer `true` ("a non-reasoning model never thinks"): the engine
133
133
  * may size a request by what it SENT, never by what it hopes a gateway does when told nothing. What this
@@ -172,8 +172,8 @@ export interface ReasoningWireFacts {
172
172
  export declare function declaredEffortLevels(v: unknown): readonly ThinkingLevel[] | undefined;
173
173
  /**
174
174
  * The effort-lane WIRE-VALUE mint — clamp ({@link resolveEffort}) + the `Model.thinkingLevelMap`
175
- * translation in ONE place, consumed by both completions-family appliers (openai.ts `applyThinking`,
176
- * open-responses.ts `resolveWireEffort`) AND the reporting dispatch ({@link resolveReasoning}'s
175
+ * translation in ONE place, consumed by both effort-lane arms of `applyReasoningToRequest` (completions,
176
+ * Responses) AND the reporting dispatch ({@link resolveReasoning}'s
177
177
  * arms), so the value that reaches the wire and the resolution a trace/result face claims are two
178
178
  * reads of one computation, never parallel re-derivations. Map semantics (the field's contract): a
179
179
  * MISSING key ⇒ provider default (the clamped tier name as-is); a STRING ⇒ that provider-specific
@@ -200,7 +200,7 @@ export interface ResolvedReasoning extends ReasoningResolution {
200
200
  endpoint: string;
201
201
  /**
202
202
  * Present (true) only when the request never CARRIES at all: {@link reasoningRequestCarried} false
203
- * on a non-"off" request — the model declares NO reasoning capability (`Model.reasoning` falsy),
203
+ * on a non-"off" request — the model does not hold reasoning (`capabilityHeld`: declared false or undeclared),
204
204
  * OR the requested value is not a valid {@link ThinkingLevel} (an out-of-contract tier every wire
205
205
  * applier reads as ABSENCE — the same three-conjunct gate all of them share) — or, with
206
206
  * {@link ReasoningWireFacts} supplied, the anthropic budget path's cap-wins skip
@@ -212,7 +212,7 @@ export interface ResolvedReasoning extends ReasoningResolution {
212
212
  * reason at its own tier — the brains deliberately send no disable key for a model declared
213
213
  * non-reasoning, so the engine cannot claim a measured off there; `format` tells a consumer which
214
214
  * family applies (on every other format, absence is the closest the wire has to off — see
215
- * applyThinking's own contract). `format`/`endpoint` report the family that WOULD have carried the
215
+ * the completions arm's own contract). `format`/`endpoint` report the family that WOULD have carried the
216
216
  * tier (the why-shape a consumer diagnoses with, not a claim about the request). Absent on every
217
217
  * reasoning-capable resolution, so existing consumers see byte-identical objects. Loud-bad-values
218
218
  * rule: the one arm where the request evaporates must not be the one arm with no report.
@@ -240,7 +240,7 @@ export interface ResolvedReasoning extends ReasoningResolution {
240
240
  * drops the value — trace/result-face drift.
241
241
  *
242
242
  * - A request that never CARRIES ({@link reasoningRequestCarried} false on a non-"off" value: the model's
243
- * `reasoning` capability flag is FALSY, or the requested value is not a valid tier — no brain emits any
243
+ * `reasoning` capability is not held, or the requested value is not a valid tier — no brain emits any
244
244
  * thinking parameter for either, whatever the format) → `effective:"off"`, `graded:false`, `clamped:true`,
245
245
  * `dropped:true` — the loud-drop arm. Describing the capability dispatch instead would report a
246
246
  * resolution the request never carried, leaving the one arm where the request evaporates as the one
@@ -1,3 +1,4 @@
1
+ import { capabilityHeld } from "./model-capability.js";
1
2
  const RANK = {
2
3
  off: 0,
3
4
  minimal: 1,
@@ -11,7 +12,7 @@ export function isThinkingLevel(v) {
11
12
  return typeof v === "string" && Object.prototype.hasOwnProperty.call(RANK, v);
12
13
  }
13
14
  export function reasoningRequestCarried(model, reasoning) {
14
- return !!model.reasoning && isThinkingLevel(reasoning) && reasoning !== "off";
15
+ return capabilityHeld(model, "reasoning") && isThinkingLevel(reasoning) && reasoning !== "off";
15
16
  }
16
17
  export function rankOf(level) {
17
18
  return RANK[level];
@@ -31,7 +32,7 @@ export function declaredOffSpelling(model) {
31
32
  return typeof mapped === "string" && mapped !== "" ? mapped : undefined;
32
33
  }
33
34
  export function thinkingOffSpelled(model) {
34
- if (!model.reasoning)
35
+ if (!capabilityHeld(model, "reasoning"))
35
36
  return false;
36
37
  const compat = (model.compat ?? {});
37
38
  if (model.api === "anthropic-messages")
@@ -101,7 +102,7 @@ function dispatchReasoning(requested, model, facts) {
101
102
  return { ...mint.resolution, format, endpoint };
102
103
  }
103
104
  export function reasoningEffortLevelsOf(model) {
104
- if (!model.reasoning)
105
+ if (!capabilityHeld(model, "reasoning"))
105
106
  return undefined;
106
107
  const compat = (model.compat ?? {});
107
108
  if (model.api === "anthropic-messages") {