@elie-laloum/outpost 6.0.1 → 7.0.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 (463) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +3 -3
  3. package/SECURITY.md +9 -1
  4. package/dist/adapters/agents/antigravity-adapter.js +4 -2
  5. package/dist/adapters/agents/antigravity-adapter.js.map +1 -1
  6. package/dist/adapters/agents/antigravity-diagnostics.js +1 -1
  7. package/dist/adapters/agents/antigravity-diagnostics.js.map +1 -1
  8. package/dist/adapters/agents/antigravity-events.js +19 -10
  9. package/dist/adapters/agents/antigravity-events.js.map +1 -1
  10. package/dist/adapters/agents/antigravity-request.js +9 -1
  11. package/dist/adapters/agents/antigravity-request.js.map +1 -1
  12. package/dist/adapters/agents/antigravity.constants.d.ts +3 -0
  13. package/dist/adapters/agents/antigravity.constants.js +4 -0
  14. package/dist/adapters/agents/antigravity.constants.js.map +1 -0
  15. package/dist/adapters/agents/claude-events.js +52 -9
  16. package/dist/adapters/agents/claude-events.js.map +1 -1
  17. package/dist/adapters/agents/claude-request.js +2 -0
  18. package/dist/adapters/agents/claude-request.js.map +1 -1
  19. package/dist/adapters/agents/cli-diagnostics.d.ts +1 -1
  20. package/dist/adapters/agents/cli-diagnostics.js +15 -8
  21. package/dist/adapters/agents/cli-diagnostics.js.map +1 -1
  22. package/dist/adapters/agents/codex-events.js +28 -2
  23. package/dist/adapters/agents/codex-events.js.map +1 -1
  24. package/dist/adapters/agents/copilot-adapter.js +8 -2
  25. package/dist/adapters/agents/copilot-adapter.js.map +1 -1
  26. package/dist/adapters/agents/copilot-authentication.js +2 -1
  27. package/dist/adapters/agents/copilot-authentication.js.map +1 -1
  28. package/dist/adapters/agents/copilot-diagnostics.js +1 -1
  29. package/dist/adapters/agents/copilot-diagnostics.js.map +1 -1
  30. package/dist/adapters/agents/copilot-events.js +16 -0
  31. package/dist/adapters/agents/copilot-events.js.map +1 -1
  32. package/dist/adapters/agents/copilot-request.js +6 -1
  33. package/dist/adapters/agents/copilot-request.js.map +1 -1
  34. package/dist/adapters/agents/copilot-usage.d.ts +3 -0
  35. package/dist/adapters/agents/copilot-usage.js +19 -0
  36. package/dist/adapters/agents/copilot-usage.js.map +1 -0
  37. package/dist/adapters/agents/kimi-adapter.js +19 -3
  38. package/dist/adapters/agents/kimi-adapter.js.map +1 -1
  39. package/dist/adapters/agents/kimi-authentication.d.ts +2 -1
  40. package/dist/adapters/agents/kimi-authentication.js +41 -26
  41. package/dist/adapters/agents/kimi-authentication.js.map +1 -1
  42. package/dist/adapters/agents/kimi-diagnostics.d.ts +2 -1
  43. package/dist/adapters/agents/kimi-diagnostics.js +9 -1
  44. package/dist/adapters/agents/kimi-diagnostics.js.map +1 -1
  45. package/dist/adapters/agents/kimi-events.js +4 -0
  46. package/dist/adapters/agents/kimi-events.js.map +1 -1
  47. package/dist/adapters/agents/kimi-fork.d.ts +2 -0
  48. package/dist/adapters/agents/kimi-fork.js +11 -0
  49. package/dist/adapters/agents/kimi-fork.js.map +1 -0
  50. package/dist/adapters/agents/kimi-request.js +6 -1
  51. package/dist/adapters/agents/kimi-request.js.map +1 -1
  52. package/dist/adapters/agents/kimi-usage.d.ts +2 -0
  53. package/dist/adapters/agents/kimi-usage.js +7 -0
  54. package/dist/adapters/agents/kimi-usage.js.map +1 -0
  55. package/dist/adapters/agents/kimi.constants.d.ts +13 -0
  56. package/dist/adapters/agents/kimi.constants.js +14 -0
  57. package/dist/adapters/agents/kimi.constants.js.map +1 -0
  58. package/dist/adapters/agents/kimi.types.d.ts +1 -0
  59. package/dist/adapters/agents/kimi.types.js.map +1 -1
  60. package/dist/adapters/agents/protocol-fixtures.constants.js +15 -19
  61. package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -1
  62. package/dist/adapters/agents/session-usage.constants.d.ts +10 -0
  63. package/dist/adapters/agents/session-usage.constants.js +110 -0
  64. package/dist/adapters/agents/session-usage.constants.js.map +1 -0
  65. package/dist/adapters/agents/session-usage.d.ts +5 -0
  66. package/dist/adapters/agents/session-usage.js +45 -0
  67. package/dist/adapters/agents/session-usage.js.map +1 -0
  68. package/dist/adapters/agents/settings.types.d.ts +1 -0
  69. package/dist/adapters/agents/settings.types.js.map +1 -1
  70. package/dist/adapters/agents/tool-result.d.ts +2 -0
  71. package/dist/adapters/agents/tool-result.js +17 -0
  72. package/dist/adapters/agents/tool-result.js.map +1 -0
  73. package/dist/adapters/models/anthropic-response.js +3 -0
  74. package/dist/adapters/models/anthropic-response.js.map +1 -1
  75. package/dist/adapters/models/http-provider.js +6 -1
  76. package/dist/adapters/models/http-provider.js.map +1 -1
  77. package/dist/adapters/models/openai-responses.js +10 -0
  78. package/dist/adapters/models/openai-responses.js.map +1 -1
  79. package/dist/adapters/models/retry-after.d.ts +1 -0
  80. package/dist/adapters/models/retry-after.js +16 -0
  81. package/dist/adapters/models/retry-after.js.map +1 -0
  82. package/dist/application/activity-watchdog.js +1 -2
  83. package/dist/application/activity-watchdog.js.map +1 -1
  84. package/dist/application/agent-bootstrap.constants.js +1 -3
  85. package/dist/application/agent-bootstrap.constants.js.map +1 -1
  86. package/dist/application/agent-bootstrap.js +9 -3
  87. package/dist/application/agent-bootstrap.js.map +1 -1
  88. package/dist/application/agent-bootstrap.types.d.ts +1 -2
  89. package/dist/application/agent-bootstrap.types.js.map +1 -1
  90. package/dist/application/agent-output.js +74 -8
  91. package/dist/application/agent-output.js.map +1 -1
  92. package/dist/application/agent-request.d.ts +3 -0
  93. package/dist/application/agent-request.js +11 -0
  94. package/dist/application/agent-request.js.map +1 -0
  95. package/dist/application/agent-turn.js +74 -6
  96. package/dist/application/agent-turn.js.map +1 -1
  97. package/dist/application/agent-usage.d.ts +6 -0
  98. package/dist/application/agent-usage.js +57 -0
  99. package/dist/application/agent-usage.js.map +1 -0
  100. package/dist/application/attach.js +2 -0
  101. package/dist/application/attach.js.map +1 -1
  102. package/dist/application/custom-turn.js +44 -49
  103. package/dist/application/custom-turn.js.map +1 -1
  104. package/dist/application/dispatch-observation.d.ts +1 -1
  105. package/dist/application/dispatch-observation.js +141 -21
  106. package/dist/application/dispatch-observation.js.map +1 -1
  107. package/dist/application/dispatch-observation.types.d.ts +2 -0
  108. package/dist/application/dispatch-observation.types.js.map +1 -1
  109. package/dist/application/dispatch-validation.js +2 -0
  110. package/dist/application/dispatch-validation.js.map +1 -1
  111. package/dist/application/dispatch.js +1 -1
  112. package/dist/application/dispatch.js.map +1 -1
  113. package/dist/application/doctor-agent.constants.js +3 -0
  114. package/dist/application/doctor-agent.constants.js.map +1 -1
  115. package/dist/application/doctor-agent.js +6 -2
  116. package/dist/application/doctor-agent.js.map +1 -1
  117. package/dist/application/doctor.js +26 -6
  118. package/dist/application/doctor.js.map +1 -1
  119. package/dist/application/doctor.types.d.ts +1 -0
  120. package/dist/application/doctor.types.js.map +1 -1
  121. package/dist/application/execution.constants.d.ts +2 -0
  122. package/dist/application/execution.constants.js +2 -0
  123. package/dist/application/execution.constants.js.map +1 -1
  124. package/dist/application/execution.types.d.ts +8 -0
  125. package/dist/application/execution.types.js.map +1 -1
  126. package/dist/application/harness-budget.d.ts +3 -0
  127. package/dist/application/harness-budget.js +42 -0
  128. package/dist/application/harness-budget.js.map +1 -0
  129. package/dist/application/harness-budget.types.d.ts +5 -0
  130. package/dist/application/harness-budget.types.js +2 -0
  131. package/dist/application/harness-budget.types.js.map +1 -0
  132. package/dist/application/harness-hooks.js +34 -3
  133. package/dist/application/harness-hooks.js.map +1 -1
  134. package/dist/application/harness-loop.js +52 -24
  135. package/dist/application/harness-loop.js.map +1 -1
  136. package/dist/application/harness-model-provider.d.ts +3 -0
  137. package/dist/application/harness-model-provider.js +49 -0
  138. package/dist/application/harness-model-provider.js.map +1 -0
  139. package/dist/application/harness-model-provider.types.d.ts +10 -0
  140. package/dist/application/harness-model-provider.types.js +2 -0
  141. package/dist/application/harness-model-provider.types.js.map +1 -0
  142. package/dist/application/harness-subagent.d.ts +4 -0
  143. package/dist/application/harness-subagent.js +110 -0
  144. package/dist/application/harness-subagent.js.map +1 -0
  145. package/dist/application/harness.types.d.ts +11 -0
  146. package/dist/application/harness.types.js.map +1 -1
  147. package/dist/application/lifecycle-hooks.d.ts +1 -1
  148. package/dist/application/lifecycle-hooks.js +5 -4
  149. package/dist/application/lifecycle-hooks.js.map +1 -1
  150. package/dist/application/observed-lease.d.ts +3 -0
  151. package/dist/application/observed-lease.js +26 -0
  152. package/dist/application/observed-lease.js.map +1 -0
  153. package/dist/application/outpost.types.d.ts +3 -0
  154. package/dist/application/outpost.types.js.map +1 -1
  155. package/dist/application/output-lines.d.ts +4 -0
  156. package/dist/application/output-lines.js +28 -0
  157. package/dist/application/output-lines.js.map +1 -0
  158. package/dist/application/queue-worker.js +1 -1
  159. package/dist/application/queue-worker.js.map +1 -1
  160. package/dist/application/queue-worker.types.d.ts +1 -0
  161. package/dist/application/queue-worker.types.js.map +1 -1
  162. package/dist/application/queued-task.js +24 -5
  163. package/dist/application/queued-task.js.map +1 -1
  164. package/dist/application/recovery-archive.d.ts +3 -2
  165. package/dist/application/recovery-archive.js +9 -2
  166. package/dist/application/recovery-archive.js.map +1 -1
  167. package/dist/application/recovery-restore.d.ts +3 -2
  168. package/dist/application/recovery-restore.js +9 -2
  169. package/dist/application/recovery-restore.js.map +1 -1
  170. package/dist/application/recovery-retention.d.ts +3 -2
  171. package/dist/application/recovery-retention.js +9 -2
  172. package/dist/application/recovery-retention.js.map +1 -1
  173. package/dist/application/remote-workspace.js +5 -4
  174. package/dist/application/remote-workspace.js.map +1 -1
  175. package/dist/application/remote-workspace.types.d.ts +1 -0
  176. package/dist/application/remote-workspace.types.js.map +1 -1
  177. package/dist/application/sandbox-agents.js +11 -12
  178. package/dist/application/sandbox-agents.js.map +1 -1
  179. package/dist/application/sandbox-attach.js +12 -3
  180. package/dist/application/sandbox-attach.js.map +1 -1
  181. package/dist/application/sandbox-dispatch.js +13 -25
  182. package/dist/application/sandbox-dispatch.js.map +1 -1
  183. package/dist/application/sandbox-provision.js +15 -9
  184. package/dist/application/sandbox-provision.js.map +1 -1
  185. package/dist/application/sandbox-session.types.d.ts +2 -2
  186. package/dist/application/sandbox-session.types.js.map +1 -1
  187. package/dist/application/sandbox.js +13 -6
  188. package/dist/application/sandbox.js.map +1 -1
  189. package/dist/application/speculation-checkpoint.d.ts +6 -0
  190. package/dist/application/speculation-checkpoint.js +206 -0
  191. package/dist/application/speculation-checkpoint.js.map +1 -0
  192. package/dist/application/speculation-checkpoint.types.d.ts +24 -0
  193. package/dist/application/speculation-checkpoint.types.js +2 -0
  194. package/dist/application/speculation-checkpoint.types.js.map +1 -0
  195. package/dist/application/speculation-integration.constants.d.ts +4 -0
  196. package/dist/application/speculation-integration.constants.js +5 -0
  197. package/dist/application/speculation-integration.constants.js.map +1 -0
  198. package/dist/application/speculation-integration.d.ts +2 -0
  199. package/dist/application/speculation-integration.js +67 -0
  200. package/dist/application/speculation-integration.js.map +1 -0
  201. package/dist/application/speculation-resume.d.ts +4 -0
  202. package/dist/application/speculation-resume.js +71 -0
  203. package/dist/application/speculation-resume.js.map +1 -0
  204. package/dist/application/speculation-run.d.ts +4 -0
  205. package/dist/application/speculation-run.js +320 -0
  206. package/dist/application/speculation-run.js.map +1 -0
  207. package/dist/application/speculation-timeout.d.ts +1 -0
  208. package/dist/application/speculation-timeout.js +15 -0
  209. package/dist/application/speculation-timeout.js.map +1 -0
  210. package/dist/application/speculation.constants.d.ts +1 -0
  211. package/dist/application/speculation.constants.js +5 -1
  212. package/dist/application/speculation.constants.js.map +1 -1
  213. package/dist/application/speculation.js +41 -149
  214. package/dist/application/speculation.js.map +1 -1
  215. package/dist/application/speculation.types.d.ts +23 -0
  216. package/dist/application/speculation.types.js.map +1 -1
  217. package/dist/application/startup-recovery.js +13 -0
  218. package/dist/application/startup-recovery.js.map +1 -1
  219. package/dist/application/startup-recovery.types.d.ts +1 -0
  220. package/dist/application/startup-recovery.types.js.map +1 -1
  221. package/dist/application/stop-reason.d.ts +2 -0
  222. package/dist/application/stop-reason.js +21 -0
  223. package/dist/application/stop-reason.js.map +1 -0
  224. package/dist/application/stop-reason.types.d.ts +4 -0
  225. package/dist/application/stop-reason.types.js +2 -0
  226. package/dist/application/stop-reason.types.js.map +1 -0
  227. package/dist/application/task-observation.d.ts +3 -0
  228. package/dist/application/task-observation.js +22 -0
  229. package/dist/application/task-observation.js.map +1 -0
  230. package/dist/application/task-usage.js +5 -12
  231. package/dist/application/task-usage.js.map +1 -1
  232. package/dist/application/tasks.js +41 -16
  233. package/dist/application/tasks.js.map +1 -1
  234. package/dist/application/tool-execution.js +42 -19
  235. package/dist/application/tool-execution.js.map +1 -1
  236. package/dist/application/workspace.js +6 -4
  237. package/dist/application/workspace.js.map +1 -1
  238. package/dist/cli/doctor-command.js +1 -1
  239. package/dist/cli/doctor-command.js.map +1 -1
  240. package/dist/cli/main.js +2 -1
  241. package/dist/cli/main.js.map +1 -1
  242. package/dist/cli/scaffold.constants.js +3 -2
  243. package/dist/cli/scaffold.constants.js.map +1 -1
  244. package/dist/domain/agent-observation.d.ts +4 -0
  245. package/dist/domain/agent-observation.js +27 -0
  246. package/dist/domain/agent-observation.js.map +1 -0
  247. package/dist/domain/agent.types.d.ts +75 -3
  248. package/dist/domain/agent.types.js.map +1 -1
  249. package/dist/domain/harness.js +6 -0
  250. package/dist/domain/harness.js.map +1 -1
  251. package/dist/domain/harness.types.d.ts +2 -1
  252. package/dist/domain/harness.types.js.map +1 -1
  253. package/dist/domain/model.types.d.ts +8 -0
  254. package/dist/domain/model.types.js.map +1 -1
  255. package/dist/domain/observation.constants.d.ts +8 -0
  256. package/dist/domain/observation.constants.js +9 -0
  257. package/dist/domain/observation.constants.js.map +1 -0
  258. package/dist/domain/observation.d.ts +2 -0
  259. package/dist/domain/observation.js +190 -0
  260. package/dist/domain/observation.js.map +1 -0
  261. package/dist/domain/observation.types.d.ts +84 -0
  262. package/dist/domain/observation.types.js +2 -0
  263. package/dist/domain/observation.types.js.map +1 -0
  264. package/dist/domain/observed-operation.d.ts +2 -0
  265. package/dist/domain/observed-operation.js +30 -0
  266. package/dist/domain/observed-operation.js.map +1 -0
  267. package/dist/domain/sandbox.types.d.ts +2 -0
  268. package/dist/domain/sandbox.types.js.map +1 -1
  269. package/dist/domain/subagent.constants.d.ts +13 -0
  270. package/dist/domain/subagent.constants.js +9 -0
  271. package/dist/domain/subagent.constants.js.map +1 -0
  272. package/dist/domain/subagent.d.ts +4 -0
  273. package/dist/domain/subagent.js +28 -0
  274. package/dist/domain/subagent.js.map +1 -0
  275. package/dist/domain/subagent.types.d.ts +13 -0
  276. package/dist/domain/subagent.types.js +2 -0
  277. package/dist/domain/subagent.types.js.map +1 -0
  278. package/dist/domain/transcript.types.d.ts +2 -0
  279. package/dist/domain/transcript.types.js.map +1 -1
  280. package/dist/domain/usage.d.ts +1 -0
  281. package/dist/domain/usage.js +16 -0
  282. package/dist/domain/usage.js.map +1 -1
  283. package/dist/domain/workflow/budget.d.ts +7 -3
  284. package/dist/domain/workflow/budget.js +26 -0
  285. package/dist/domain/workflow/budget.js.map +1 -1
  286. package/dist/domain/workflow/budget.types.d.ts +1 -1
  287. package/dist/domain/workflow/budget.types.js.map +1 -1
  288. package/dist/domain/workflow/checkpoint-validation.js +7 -1
  289. package/dist/domain/workflow/checkpoint-validation.js.map +1 -1
  290. package/dist/domain/workflow/checkpoint.js +3 -0
  291. package/dist/domain/workflow/checkpoint.js.map +1 -1
  292. package/dist/domain/workflow/gate-validation.js +14 -1
  293. package/dist/domain/workflow/gate-validation.js.map +1 -1
  294. package/dist/domain/workflow/gates.d.ts +1 -1
  295. package/dist/domain/workflow/gates.js +52 -4
  296. package/dist/domain/workflow/gates.js.map +1 -1
  297. package/dist/domain/workflow/gates.types.d.ts +15 -1
  298. package/dist/domain/workflow/gates.types.js.map +1 -1
  299. package/dist/domain/workflow/idempotency.d.ts +1 -0
  300. package/dist/domain/workflow/idempotency.js +7 -0
  301. package/dist/domain/workflow/idempotency.js.map +1 -0
  302. package/dist/domain/workflow/retry.constants.d.ts +2 -0
  303. package/dist/domain/workflow/retry.constants.js +3 -0
  304. package/dist/domain/workflow/retry.constants.js.map +1 -0
  305. package/dist/domain/workflow/retry.d.ts +4 -0
  306. package/dist/domain/workflow/retry.js +49 -0
  307. package/dist/domain/workflow/retry.js.map +1 -0
  308. package/dist/domain/workflow/task-runner.js +9 -5
  309. package/dist/domain/workflow/task-runner.js.map +1 -1
  310. package/dist/domain/workflow/task.js +6 -6
  311. package/dist/domain/workflow/task.js.map +1 -1
  312. package/dist/domain/workflow/workflow-scheduler.js +110 -72
  313. package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
  314. package/dist/domain/workflow/workflow-state.js +28 -12
  315. package/dist/domain/workflow/workflow-state.js.map +1 -1
  316. package/dist/domain/workflow.d.ts +1 -1
  317. package/dist/domain/workflow.js +1 -1
  318. package/dist/domain/workflow.js.map +1 -1
  319. package/dist/domain/workflow.types.d.ts +13 -2
  320. package/dist/domain/workflow.types.js.map +1 -1
  321. package/dist/index.d.ts +12 -3
  322. package/dist/index.js +6 -1
  323. package/dist/index.js.map +1 -1
  324. package/dist/infrastructure/conversations/capture.js +10 -0
  325. package/dist/infrastructure/conversations/capture.js.map +1 -1
  326. package/dist/infrastructure/conversations/harness-transcript.js +6 -0
  327. package/dist/infrastructure/conversations/harness-transcript.js.map +1 -1
  328. package/dist/infrastructure/conversations/harness-transcript.types.d.ts +2 -0
  329. package/dist/infrastructure/conversations/harness-transcript.types.js.map +1 -1
  330. package/dist/infrastructure/conversations/layout.js +2 -0
  331. package/dist/infrastructure/conversations/layout.js.map +1 -1
  332. package/dist/infrastructure/conversations/locate.js +7 -1
  333. package/dist/infrastructure/conversations/locate.js.map +1 -1
  334. package/dist/infrastructure/conversations/native-store.js +8 -1
  335. package/dist/infrastructure/conversations/native-store.js.map +1 -1
  336. package/dist/infrastructure/conversations/paths.js +3 -0
  337. package/dist/infrastructure/conversations/paths.js.map +1 -1
  338. package/dist/infrastructure/conversations/restore.js +7 -0
  339. package/dist/infrastructure/conversations/restore.js.map +1 -1
  340. package/dist/infrastructure/conversations/session-bundle.constants.d.ts +5 -0
  341. package/dist/infrastructure/conversations/session-bundle.constants.js +173 -0
  342. package/dist/infrastructure/conversations/session-bundle.constants.js.map +1 -0
  343. package/dist/infrastructure/conversations/session-bundle.d.ts +6 -0
  344. package/dist/infrastructure/conversations/session-bundle.js +98 -0
  345. package/dist/infrastructure/conversations/session-bundle.js.map +1 -0
  346. package/dist/infrastructure/conversations/session-bundle.types.d.ts +1 -0
  347. package/dist/infrastructure/conversations/session-bundle.types.js +2 -0
  348. package/dist/infrastructure/conversations/session-bundle.types.js.map +1 -0
  349. package/dist/infrastructure/conversations.js +4 -2
  350. package/dist/infrastructure/conversations.js.map +1 -1
  351. package/dist/infrastructure/conversations.types.d.ts +1 -1
  352. package/dist/infrastructure/conversations.types.js.map +1 -1
  353. package/dist/infrastructure/custom-reporter.js +32 -24
  354. package/dist/infrastructure/custom-reporter.js.map +1 -1
  355. package/dist/infrastructure/custom-reporter.types.d.ts +2 -0
  356. package/dist/infrastructure/custom-reporter.types.js.map +1 -1
  357. package/dist/infrastructure/git/workspace-lease.js +4 -3
  358. package/dist/infrastructure/git/workspace-lease.js.map +1 -1
  359. package/dist/infrastructure/git/workspace.js +7 -6
  360. package/dist/infrastructure/git/workspace.js.map +1 -1
  361. package/dist/infrastructure/git/workspace.types.d.ts +1 -0
  362. package/dist/infrastructure/git/workspace.types.js.map +1 -1
  363. package/dist/infrastructure/journal.constants.js +10 -1
  364. package/dist/infrastructure/journal.constants.js.map +1 -1
  365. package/dist/infrastructure/journal.d.ts +1 -1
  366. package/dist/infrastructure/journal.js +2 -2
  367. package/dist/infrastructure/journal.js.map +1 -1
  368. package/dist/infrastructure/journal.types.d.ts +2 -2
  369. package/dist/infrastructure/journal.types.js.map +1 -1
  370. package/dist/infrastructure/opentelemetry-dispatch.d.ts +3 -3
  371. package/dist/infrastructure/opentelemetry-dispatch.js +5 -4
  372. package/dist/infrastructure/opentelemetry-dispatch.js.map +1 -1
  373. package/dist/infrastructure/opentelemetry-observation.d.ts +5 -0
  374. package/dist/infrastructure/opentelemetry-observation.js +59 -0
  375. package/dist/infrastructure/opentelemetry-observation.js.map +1 -0
  376. package/dist/infrastructure/opentelemetry.js +15 -1
  377. package/dist/infrastructure/opentelemetry.js.map +1 -1
  378. package/dist/infrastructure/opentelemetry.types.d.ts +9 -1
  379. package/dist/infrastructure/opentelemetry.types.js.map +1 -1
  380. package/dist/infrastructure/reporter.d.ts +2 -2
  381. package/dist/infrastructure/reporter.js +5 -1
  382. package/dist/infrastructure/reporter.js.map +1 -1
  383. package/dist/infrastructure/s3-transport.constants.d.ts +2 -0
  384. package/dist/infrastructure/s3-transport.constants.js +3 -0
  385. package/dist/infrastructure/s3-transport.constants.js.map +1 -0
  386. package/dist/infrastructure/s3-transport.js +57 -3
  387. package/dist/infrastructure/s3-transport.js.map +1 -1
  388. package/dist/infrastructure/s3-transport.types.d.ts +1 -0
  389. package/dist/infrastructure/s3-transport.types.js.map +1 -1
  390. package/dist/infrastructure/speculation-store.constants.d.ts +3 -0
  391. package/dist/infrastructure/speculation-store.constants.js +2 -0
  392. package/dist/infrastructure/speculation-store.constants.js.map +1 -0
  393. package/dist/infrastructure/speculation-store.d.ts +4 -0
  394. package/dist/infrastructure/speculation-store.js +73 -0
  395. package/dist/infrastructure/speculation-store.js.map +1 -0
  396. package/dist/infrastructure/speculation-store.types.d.ts +12 -0
  397. package/dist/infrastructure/speculation-store.types.js +2 -0
  398. package/dist/infrastructure/speculation-store.types.js.map +1 -0
  399. package/dist/infrastructure/task-queue-bullmq-resources.js +3 -0
  400. package/dist/infrastructure/task-queue-bullmq-resources.js.map +1 -1
  401. package/dist/infrastructure/task-queue-http.js +29 -4
  402. package/dist/infrastructure/task-queue-http.js.map +1 -1
  403. package/dist/infrastructure/task-queue-http.types.d.ts +2 -2
  404. package/dist/infrastructure/task-queue-http.types.js.map +1 -1
  405. package/dist/infrastructure/transport-conversations.js +2 -0
  406. package/dist/infrastructure/transport-conversations.js.map +1 -1
  407. package/dist/infrastructure/transport-journal.d.ts +1 -1
  408. package/dist/infrastructure/transport-journal.js +8 -2
  409. package/dist/infrastructure/transport-journal.js.map +1 -1
  410. package/dist/infrastructure/workflow-decision-signature.constants.d.ts +4 -0
  411. package/dist/infrastructure/workflow-decision-signature.constants.js +5 -0
  412. package/dist/infrastructure/workflow-decision-signature.constants.js.map +1 -0
  413. package/dist/infrastructure/workflow-decision-signature.d.ts +4 -0
  414. package/dist/infrastructure/workflow-decision-signature.js +83 -0
  415. package/dist/infrastructure/workflow-decision-signature.js.map +1 -0
  416. package/dist/infrastructure/workflow-decision-signature.types.d.ts +16 -0
  417. package/dist/infrastructure/workflow-decision-signature.types.js +2 -0
  418. package/dist/infrastructure/workflow-decision-signature.types.js.map +1 -0
  419. package/dist/providers/antigravity-install.constants.d.ts +2 -0
  420. package/dist/providers/antigravity-install.constants.js +28 -0
  421. package/dist/providers/antigravity-install.constants.js.map +1 -0
  422. package/dist/providers/antigravity-install.d.ts +2 -0
  423. package/dist/providers/antigravity-install.js +29 -0
  424. package/dist/providers/antigravity-install.js.map +1 -0
  425. package/dist/providers/antigravity-install.types.d.ts +4 -0
  426. package/dist/providers/antigravity-install.types.js +2 -0
  427. package/dist/providers/antigravity-install.types.js.map +1 -0
  428. package/dist/providers/container-recovery.d.ts +4 -0
  429. package/dist/providers/container-recovery.js +28 -0
  430. package/dist/providers/container-recovery.js.map +1 -0
  431. package/dist/providers/container.js +8 -0
  432. package/dist/providers/container.js.map +1 -1
  433. package/dist/providers/daytona-network.constants.d.ts +5 -0
  434. package/dist/providers/daytona-network.constants.js +8 -0
  435. package/dist/providers/daytona-network.constants.js.map +1 -0
  436. package/dist/providers/daytona-network.d.ts +4 -0
  437. package/dist/providers/daytona-network.js +33 -0
  438. package/dist/providers/daytona-network.js.map +1 -0
  439. package/dist/providers/daytona.d.ts +1 -0
  440. package/dist/providers/daytona.js +9 -3
  441. package/dist/providers/daytona.js.map +1 -1
  442. package/dist/providers/daytona.types.d.ts +2 -0
  443. package/dist/providers/daytona.types.js.map +1 -1
  444. package/dist/providers/firecracker-command.js +1 -1
  445. package/dist/providers/firecracker-command.js.map +1 -1
  446. package/dist/providers/firecracker-jailer.constants.d.ts +9 -0
  447. package/dist/providers/firecracker-jailer.constants.js +10 -0
  448. package/dist/providers/firecracker-jailer.constants.js.map +1 -0
  449. package/dist/providers/firecracker-jailer.d.ts +4 -0
  450. package/dist/providers/firecracker-jailer.js +171 -0
  451. package/dist/providers/firecracker-jailer.js.map +1 -0
  452. package/dist/providers/firecracker-machine.js +30 -8
  453. package/dist/providers/firecracker-machine.js.map +1 -1
  454. package/dist/providers/firecracker.types.d.ts +16 -0
  455. package/dist/providers/firecracker.types.js.map +1 -1
  456. package/dist/providers/vercel-network.js +1 -1
  457. package/dist/providers/vercel-network.js.map +1 -1
  458. package/dist/providers/vercel.js +6 -3
  459. package/dist/providers/vercel.js.map +1 -1
  460. package/dist/providers/versions.constants.d.ts +1 -1
  461. package/dist/providers/versions.constants.js +1 -1
  462. package/dist/providers/versions.constants.js.map +1 -1
  463. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import type { AgentAuthentication } from "../../domain/agent.types.ts";
2
2
  import type { Variables } from "../../domain/command.types.ts";
3
3
  export interface KimiSettings {
4
+ readonly region?: "mainland-cn" | "global";
4
5
  readonly authentication?: AgentAuthentication;
5
6
  readonly variables?: Variables;
6
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"kimi.types.js","sourceRoot":"","sources":["../../../src/adapters/agents/kimi.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentAuthentication } from \"../../domain/agent.types.ts\";\nimport type { Variables } from \"../../domain/command.types.ts\";\n\nexport interface KimiSettings {\n readonly authentication?: AgentAuthentication;\n readonly variables?: Variables;\n}\n"]}
1
+ {"version":3,"file":"kimi.types.js","sourceRoot":"","sources":["../../../src/adapters/agents/kimi.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentAuthentication } from \"../../domain/agent.types.ts\";\nimport type { Variables } from \"../../domain/command.types.ts\";\n\nexport interface KimiSettings {\n readonly region?: \"mainland-cn\" | \"global\";\n readonly authentication?: AgentAuthentication;\n readonly variables?: Variables;\n}\n"]}
@@ -12,22 +12,18 @@ export const protocolFixtures = {
12
12
  expected: [
13
13
  { kind: "conversation", id: "fixture-conversation" },
14
14
  {
15
- kind: "raw",
16
- value: {
17
- event: "step_update",
18
- step_update: {
19
- conversation_id: "fixture-conversation",
20
- step_index: 1,
21
- state: "ACTIVE",
22
- step_type: "tool",
23
- tool_name: "run_command",
24
- },
25
- },
15
+ kind: "tool",
16
+ name: "run_command",
17
+ input: undefined,
18
+ callId: "fixture-conversation:1",
26
19
  },
27
20
  {
28
- kind: "tool",
21
+ kind: "tool-result",
29
22
  name: "run_command",
30
- input: { command: "fixture-command" },
23
+ callId: "fixture-conversation:1",
24
+ preview: "",
25
+ characters: 0,
26
+ isError: false,
31
27
  },
32
28
  { kind: "text", text: "fixture-result" },
33
29
  { kind: "usage", tokens: { input: 10, cached: 2, output: 4 } },
@@ -135,12 +131,12 @@ export const protocolFixtures = {
135
131
  callId: "call-1",
136
132
  },
137
133
  {
138
- kind: "raw",
139
- value: {
140
- role: "tool",
141
- tool_call_id: "call-1",
142
- content: "fixture-output",
143
- },
134
+ kind: "tool-result",
135
+ callId: "call-1",
136
+ name: "",
137
+ preview: "fixture-output",
138
+ characters: 14,
139
+ isError: false,
144
140
  },
145
141
  { kind: "text", text: "fixture-result" },
146
142
  { kind: "conversation", id: "fixture-conversation" },
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-fixtures.constants.js","sourceRoot":"","sources":["../../../src/adapters/agents/protocol-fixtures.constants.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,gBAAgB,GAEzB;IACF,WAAW,EAAE;QACX;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE;gBACL,+GAA+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,EAAE,iBAAiB,EAAE;gBAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE;gBACxC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE;gBAC1C;oBACE,IAAI,EAAE,OAAO;oBACb,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;iBAC7D;gBACD,EAAE,IAAI,EAAE,UAAU,EAAE;aACrB;SACF;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,8DAA8D,CAAC;YACvE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;SAC5D;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,yBAAyB,EAAE,cAAc,CAAC;YAClD,QAAQ,EAAE;gBACR,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE;gBAChD,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE;aACvC;SACF;KACF;CACF,CAAC","sourcesContent":["import type {\n AgentProtocolFixture,\n ProtocolAgent,\n} from \"./protocol-fixtures.types.ts\";\n\nexport const protocolFixtures: Readonly<\n Record<ProtocolAgent, readonly AgentProtocolFixture[]>\n> = {\n antigravity: [\n {\n name: \"turn\",\n lines: [\n '{\"event\":\"init\",\"conversation_id\":\"fixture-conversation\",\"init\":{\"cwd\":\"/workspace\",\"model\":\"fixture-model\"}}',\n '{\"event\":\"step_update\",\"step_update\":{\"conversation_id\":\"fixture-conversation\",\"step_index\":1,\"state\":\"ACTIVE\",\"step_type\":\"tool\",\"tool_name\":\"run_command\"}}',\n '{\"event\":\"step_update\",\"step_update\":{\"conversation_id\":\"fixture-conversation\",\"step_index\":1,\"state\":\"DONE\",\"step_type\":\"tool\",\"tool_name\":\"run_command\",\"tool_info\":{\"name\":\"run_command\",\"parameters\":{\"command\":\"fixture-command\"}}}}',\n '{\"event\":\"step_update\",\"step_update\":{\"conversation_id\":\"fixture-conversation\",\"step_index\":2,\"state\":\"ACTIVE\",\"step_type\":\"agent_response\",\"text_delta\":\"fixture-result\"}}',\n '{\"event\":\"result\",\"result\":{\"conversation_id\":\"fixture-conversation\",\"status\":\"SUCCESS\",\"response\":\"fixture-result\",\"usage\":{\"input_tokens\":10,\"output_tokens\":3,\"thinking_tokens\":1,\"cache_read_tokens\":2}}}',\n ],\n expected: [\n { kind: \"conversation\", id: \"fixture-conversation\" },\n {\n kind: \"raw\",\n value: {\n event: \"step_update\",\n step_update: {\n conversation_id: \"fixture-conversation\",\n step_index: 1,\n state: \"ACTIVE\",\n step_type: \"tool\",\n tool_name: \"run_command\",\n },\n },\n },\n {\n kind: \"tool\",\n name: \"run_command\",\n input: { command: \"fixture-command\" },\n },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"usage\", tokens: { input: 10, cached: 2, output: 4 } },\n { kind: \"result\", text: \"fixture-result\" },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: [\n '{\"event\":\"result\",\"result\":{\"status\":\"CANCELED\",\"response\":\"\"}}',\n '{\"event\":\"result\",\"result\":{\"status\":\"ERROR\",\"error\":\"fixture-failure\"}}',\n ],\n expected: [\n {\n kind: \"failure\",\n message: \"Antigravity ended the turn with status CANCELED\",\n },\n { kind: \"failure\", message: \"fixture-failure\" },\n ],\n },\n {\n name: \"unknown\",\n lines: ['{\"event\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { event: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n copilot: [\n {\n name: \"turn\",\n lines: [\n '{\"id\":\"1\",\"timestamp\":\"2026-01-01T00:00:00.000Z\",\"parentId\":null,\"type\":\"assistant.turn_start\",\"data\":{\"turnId\":\"t1\"}}',\n '{\"id\":\"2\",\"timestamp\":\"2026-01-01T00:00:01.000Z\",\"parentId\":\"1\",\"type\":\"assistant.message\",\"data\":{\"messageId\":\"m1\",\"content\":\"\",\"toolRequests\":[{\"toolCallId\":\"call-1\",\"name\":\"bash\",\"arguments\":{\"command\":\"fixture-command\"},\"type\":\"function\"}]}}',\n '{\"id\":\"3\",\"timestamp\":\"2026-01-01T00:00:02.000Z\",\"parentId\":\"2\",\"type\":\"assistant.message\",\"data\":{\"messageId\":\"m2\",\"content\":\"fixture-result\",\"toolRequests\":[]}}',\n '{\"type\":\"result\",\"timestamp\":\"2026-01-01T00:00:03.000Z\",\"sessionId\":\"fixture-conversation\",\"exitCode\":0,\"usage\":{\"premiumRequests\":1}}',\n ],\n expected: [\n {\n kind: \"raw\",\n value: {\n id: \"1\",\n timestamp: \"2026-01-01T00:00:00.000Z\",\n parentId: null,\n type: \"assistant.turn_start\",\n data: { turnId: \"t1\" },\n },\n },\n {\n kind: \"tool\",\n name: \"bash\",\n input: { command: \"fixture-command\" },\n callId: \"call-1\",\n },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"conversation\", id: \"fixture-conversation\" },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: [\n '{\"type\":\"session.error\",\"data\":{\"errorType\":\"authentication\",\"message\":\"fixture-warning\",\"statusCode\":401}}',\n '{\"type\":\"result\",\"sessionId\":\"fixture-conversation\",\"exitCode\":1}',\n ],\n expected: [\n { kind: \"warning\", message: \"fixture-warning\" },\n { kind: \"conversation\", id: \"fixture-conversation\" },\n {\n kind: \"failure\",\n message: \"GitHub Copilot CLI ended with exit code 1\",\n },\n ],\n },\n {\n name: \"unknown\",\n lines: ['{\"type\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { type: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n kimi: [\n {\n name: \"turn\",\n lines: [\n '{\"role\":\"meta\",\"type\":\"system.version\",\"version\":\"2.1.1\"}',\n '{\"role\":\"assistant\",\"tool_calls\":[{\"type\":\"function\",\"id\":\"call-1\",\"function\":{\"name\":\"Shell\",\"arguments\":\"{\\\\\"command\\\\\":\\\\\"fixture-command\\\\\"}\"}}]}',\n '{\"role\":\"tool\",\"tool_call_id\":\"call-1\",\"content\":\"fixture-output\"}',\n '{\"role\":\"assistant\",\"content\":\"fixture-result\"}',\n '{\"role\":\"meta\",\"type\":\"session.resume_hint\",\"session_id\":\"fixture-conversation\",\"command\":\"kimi -r fixture-conversation\"}',\n ],\n expected: [\n {\n kind: \"raw\",\n value: { role: \"meta\", type: \"system.version\", version: \"2.1.1\" },\n },\n {\n kind: \"tool\",\n name: \"Shell\",\n input: { command: \"fixture-command\" },\n callId: \"call-1\",\n },\n {\n kind: \"raw\",\n value: {\n role: \"tool\",\n tool_call_id: \"call-1\",\n content: \"fixture-output\",\n },\n },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"conversation\", id: \"fixture-conversation\" },\n ],\n },\n {\n name: \"retry\",\n lines: [\n '{\"role\":\"meta\",\"type\":\"turn.step.retrying\",\"failed_attempt\":1,\"next_attempt\":2,\"error_message\":\"fixture-warning\",\"status_code\":429}',\n ],\n expected: [{ kind: \"warning\", message: \"fixture-warning\" }],\n },\n {\n name: \"unknown\",\n lines: ['{\"role\":\"future\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { role: \"future\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n codex: [\n {\n name: \"turn\",\n lines: [\n '{\"type\":\"thread.started\",\"thread_id\":\"fixture-conversation\"}',\n '{\"type\":\"item.started\",\"item\":{\"type\":\"command_execution\",\"command\":\"fixture-command\"}}',\n '{\"type\":\"item.completed\",\"item\":{\"type\":\"agent_message\",\"text\":\"fixture-result\"}}',\n '{\"type\":\"turn.completed\",\"usage\":{\"input_tokens\":10,\"cached_input_tokens\":2,\"output_tokens\":3}}',\n ],\n expected: [\n { kind: \"conversation\", id: \"fixture-conversation\" },\n { kind: \"tool\", name: \"command\", input: \"fixture-command\" },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"usage\", tokens: { input: 10, cached: 2, output: 3 } },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: ['{\"type\":\"turn.failed\",\"error\":{\"message\":\"fixture-failure\"}}'],\n expected: [{ kind: \"failure\", message: \"fixture-failure\" }],\n },\n {\n name: \"unknown\",\n lines: ['{\"type\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { type: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n claude: [\n {\n name: \"turn\",\n lines: [\n '{\"type\":\"system\",\"session_id\":\"fixture-conversation\"}',\n '{\"type\":\"assistant\",\"message\":{\"content\":[{\"type\":\"tool_use\",\"name\":\"command\",\"input\":\"fixture-command\"},{\"type\":\"text\",\"text\":\"fixture-result\"}]}}',\n '{\"type\":\"result\",\"result\":\"fixture-result\",\"usage\":{\"input_tokens\":10,\"cache_creation_input_tokens\":1,\"cache_read_input_tokens\":2,\"output_tokens\":3}}',\n ],\n expected: [\n { kind: \"conversation\", id: \"fixture-conversation\" },\n { kind: \"tool\", name: \"command\", input: \"fixture-command\" },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"result\", text: \"fixture-result\" },\n {\n kind: \"usage\",\n tokens: { input: 10, cached: 2, cacheCreated: 1, output: 3 },\n },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: ['{\"type\":\"result\",\"is_error\":true,\"result\":\"fixture-failure\"}'],\n expected: [{ kind: \"failure\", message: \"fixture-failure\" }],\n },\n {\n name: \"unknown\",\n lines: ['{\"type\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { type: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n};\n"]}
1
+ {"version":3,"file":"protocol-fixtures.constants.js","sourceRoot":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,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,sBAAsB,EAAE;gBACpD,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,iBAAiB,EAAE;gBAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE;gBACxC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE;gBAC1C;oBACE,IAAI,EAAE,OAAO;oBACb,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;iBAC7D;gBACD,EAAE,IAAI,EAAE,UAAU,EAAE;aACrB;SACF;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,8DAA8D,CAAC;YACvE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;SAC5D;QACD;YACE,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,yBAAyB,EAAE,cAAc,CAAC;YAClD,QAAQ,EAAE;gBACR,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE;gBAChD,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE;aACvC;SACF;KACF;CACF,CAAC","sourcesContent":["import type {\n AgentProtocolFixture,\n ProtocolAgent,\n} from \"./protocol-fixtures.types.ts\";\n\nexport const protocolFixtures: Readonly<\n Record<ProtocolAgent, readonly AgentProtocolFixture[]>\n> = {\n antigravity: [\n {\n name: \"turn\",\n lines: [\n '{\"event\":\"init\",\"conversation_id\":\"fixture-conversation\",\"init\":{\"cwd\":\"/workspace\",\"model\":\"fixture-model\"}}',\n '{\"event\":\"step_update\",\"step_update\":{\"conversation_id\":\"fixture-conversation\",\"step_index\":1,\"state\":\"ACTIVE\",\"step_type\":\"tool\",\"tool_name\":\"run_command\"}}',\n '{\"event\":\"step_update\",\"step_update\":{\"conversation_id\":\"fixture-conversation\",\"step_index\":1,\"state\":\"DONE\",\"step_type\":\"tool\",\"tool_name\":\"run_command\",\"tool_info\":{\"name\":\"run_command\",\"parameters\":{\"command\":\"fixture-command\"}}}}',\n '{\"event\":\"step_update\",\"step_update\":{\"conversation_id\":\"fixture-conversation\",\"step_index\":2,\"state\":\"ACTIVE\",\"step_type\":\"agent_response\",\"text_delta\":\"fixture-result\"}}',\n '{\"event\":\"result\",\"result\":{\"conversation_id\":\"fixture-conversation\",\"status\":\"SUCCESS\",\"response\":\"fixture-result\",\"usage\":{\"input_tokens\":10,\"output_tokens\":3,\"thinking_tokens\":1,\"cache_read_tokens\":2}}}',\n ],\n expected: [\n { kind: \"conversation\", id: \"fixture-conversation\" },\n {\n kind: \"tool\",\n name: \"run_command\",\n input: undefined,\n callId: \"fixture-conversation:1\",\n },\n {\n kind: \"tool-result\",\n name: \"run_command\",\n callId: \"fixture-conversation:1\",\n preview: \"\",\n characters: 0,\n isError: false,\n },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"usage\", tokens: { input: 10, cached: 2, output: 4 } },\n { kind: \"result\", text: \"fixture-result\" },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: [\n '{\"event\":\"result\",\"result\":{\"status\":\"CANCELED\",\"response\":\"\"}}',\n '{\"event\":\"result\",\"result\":{\"status\":\"ERROR\",\"error\":\"fixture-failure\"}}',\n ],\n expected: [\n {\n kind: \"failure\",\n message: \"Antigravity ended the turn with status CANCELED\",\n },\n { kind: \"failure\", message: \"fixture-failure\" },\n ],\n },\n {\n name: \"unknown\",\n lines: ['{\"event\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { event: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n copilot: [\n {\n name: \"turn\",\n lines: [\n '{\"id\":\"1\",\"timestamp\":\"2026-01-01T00:00:00.000Z\",\"parentId\":null,\"type\":\"assistant.turn_start\",\"data\":{\"turnId\":\"t1\"}}',\n '{\"id\":\"2\",\"timestamp\":\"2026-01-01T00:00:01.000Z\",\"parentId\":\"1\",\"type\":\"assistant.message\",\"data\":{\"messageId\":\"m1\",\"content\":\"\",\"toolRequests\":[{\"toolCallId\":\"call-1\",\"name\":\"bash\",\"arguments\":{\"command\":\"fixture-command\"},\"type\":\"function\"}]}}',\n '{\"id\":\"3\",\"timestamp\":\"2026-01-01T00:00:02.000Z\",\"parentId\":\"2\",\"type\":\"assistant.message\",\"data\":{\"messageId\":\"m2\",\"content\":\"fixture-result\",\"toolRequests\":[]}}',\n '{\"type\":\"result\",\"timestamp\":\"2026-01-01T00:00:03.000Z\",\"sessionId\":\"fixture-conversation\",\"exitCode\":0,\"usage\":{\"premiumRequests\":1}}',\n ],\n expected: [\n {\n kind: \"raw\",\n value: {\n id: \"1\",\n timestamp: \"2026-01-01T00:00:00.000Z\",\n parentId: null,\n type: \"assistant.turn_start\",\n data: { turnId: \"t1\" },\n },\n },\n {\n kind: \"tool\",\n name: \"bash\",\n input: { command: \"fixture-command\" },\n callId: \"call-1\",\n },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"conversation\", id: \"fixture-conversation\" },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: [\n '{\"type\":\"session.error\",\"data\":{\"errorType\":\"authentication\",\"message\":\"fixture-warning\",\"statusCode\":401}}',\n '{\"type\":\"result\",\"sessionId\":\"fixture-conversation\",\"exitCode\":1}',\n ],\n expected: [\n { kind: \"warning\", message: \"fixture-warning\" },\n { kind: \"conversation\", id: \"fixture-conversation\" },\n {\n kind: \"failure\",\n message: \"GitHub Copilot CLI ended with exit code 1\",\n },\n ],\n },\n {\n name: \"unknown\",\n lines: ['{\"type\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { type: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n kimi: [\n {\n name: \"turn\",\n lines: [\n '{\"role\":\"meta\",\"type\":\"system.version\",\"version\":\"2.1.1\"}',\n '{\"role\":\"assistant\",\"tool_calls\":[{\"type\":\"function\",\"id\":\"call-1\",\"function\":{\"name\":\"Shell\",\"arguments\":\"{\\\\\"command\\\\\":\\\\\"fixture-command\\\\\"}\"}}]}',\n '{\"role\":\"tool\",\"tool_call_id\":\"call-1\",\"content\":\"fixture-output\"}',\n '{\"role\":\"assistant\",\"content\":\"fixture-result\"}',\n '{\"role\":\"meta\",\"type\":\"session.resume_hint\",\"session_id\":\"fixture-conversation\",\"command\":\"kimi -r fixture-conversation\"}',\n ],\n expected: [\n {\n kind: \"raw\",\n value: { role: \"meta\", type: \"system.version\", version: \"2.1.1\" },\n },\n {\n kind: \"tool\",\n name: \"Shell\",\n input: { command: \"fixture-command\" },\n callId: \"call-1\",\n },\n {\n kind: \"tool-result\",\n callId: \"call-1\",\n name: \"\",\n preview: \"fixture-output\",\n characters: 14,\n isError: false,\n },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"conversation\", id: \"fixture-conversation\" },\n ],\n },\n {\n name: \"retry\",\n lines: [\n '{\"role\":\"meta\",\"type\":\"turn.step.retrying\",\"failed_attempt\":1,\"next_attempt\":2,\"error_message\":\"fixture-warning\",\"status_code\":429}',\n ],\n expected: [{ kind: \"warning\", message: \"fixture-warning\" }],\n },\n {\n name: \"unknown\",\n lines: ['{\"role\":\"future\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { role: \"future\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n codex: [\n {\n name: \"turn\",\n lines: [\n '{\"type\":\"thread.started\",\"thread_id\":\"fixture-conversation\"}',\n '{\"type\":\"item.started\",\"item\":{\"type\":\"command_execution\",\"command\":\"fixture-command\"}}',\n '{\"type\":\"item.completed\",\"item\":{\"type\":\"agent_message\",\"text\":\"fixture-result\"}}',\n '{\"type\":\"turn.completed\",\"usage\":{\"input_tokens\":10,\"cached_input_tokens\":2,\"output_tokens\":3}}',\n ],\n expected: [\n { kind: \"conversation\", id: \"fixture-conversation\" },\n { kind: \"tool\", name: \"command\", input: \"fixture-command\" },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"usage\", tokens: { input: 10, cached: 2, output: 3 } },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: ['{\"type\":\"turn.failed\",\"error\":{\"message\":\"fixture-failure\"}}'],\n expected: [{ kind: \"failure\", message: \"fixture-failure\" }],\n },\n {\n name: \"unknown\",\n lines: ['{\"type\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { type: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n claude: [\n {\n name: \"turn\",\n lines: [\n '{\"type\":\"system\",\"session_id\":\"fixture-conversation\"}',\n '{\"type\":\"assistant\",\"message\":{\"content\":[{\"type\":\"tool_use\",\"name\":\"command\",\"input\":\"fixture-command\"},{\"type\":\"text\",\"text\":\"fixture-result\"}]}}',\n '{\"type\":\"result\",\"result\":\"fixture-result\",\"usage\":{\"input_tokens\":10,\"cache_creation_input_tokens\":1,\"cache_read_input_tokens\":2,\"output_tokens\":3}}',\n ],\n expected: [\n { kind: \"conversation\", id: \"fixture-conversation\" },\n { kind: \"tool\", name: \"command\", input: \"fixture-command\" },\n { kind: \"text\", text: \"fixture-result\" },\n { kind: \"result\", text: \"fixture-result\" },\n {\n kind: \"usage\",\n tokens: { input: 10, cached: 2, cacheCreated: 1, output: 3 },\n },\n { kind: \"finished\" },\n ],\n },\n {\n name: \"failure\",\n lines: ['{\"type\":\"result\",\"is_error\":true,\"result\":\"fixture-failure\"}'],\n expected: [{ kind: \"failure\", message: \"fixture-failure\" }],\n },\n {\n name: \"unknown\",\n lines: ['{\"type\":\"future.event\"}', \"invalid-json\"],\n expected: [\n { kind: \"raw\", value: { type: \"future.event\" } },\n { kind: \"raw\", value: \"invalid-json\" },\n ],\n },\n ],\n};\n"]}
@@ -0,0 +1,10 @@
1
+ export declare const sessionUsageLimits: {
2
+ readonly bytes: number;
3
+ readonly outputBytes: number;
4
+ readonly lineBytes: number;
5
+ readonly records: 4096;
6
+ readonly directories: 4096;
7
+ readonly agents: 128;
8
+ readonly deadlineMs: 5000;
9
+ };
10
+ export declare const sessionUsageScript: string;
@@ -0,0 +1,110 @@
1
+ export const sessionUsageLimits = {
2
+ bytes: 64 * 1024 * 1024,
3
+ outputBytes: 1024 * 1024,
4
+ lineBytes: 1024 * 1024,
5
+ records: 4096,
6
+ directories: 4096,
7
+ agents: 128,
8
+ deadlineMs: 5000,
9
+ };
10
+ export const sessionUsageScript = String.raw `
11
+ const fs = require("node:fs/promises");
12
+ const { createReadStream } = require("node:fs");
13
+ const { createInterface } = require("node:readline");
14
+ const { join, resolve } = require("node:path");
15
+ const { homedir } = require("node:os");
16
+ const [kind, id, encodedLimits] = process.argv.slice(1);
17
+ const limits = JSON.parse(encodedLimits);
18
+ const result = { records: [], complete: true };
19
+ let bytes = 0;
20
+ function project(usage, keys) {
21
+ return Object.fromEntries(keys.map(key => [key,
22
+ typeof usage?.[key] === "number" ? usage[key] : null]));
23
+ }
24
+ async function directory(path) {
25
+ if ((await fs.lstat(path)).isSymbolicLink() || await fs.realpath(path) !== resolve(path))
26
+ throw new Error("Unsafe session directory");
27
+ const entries = await fs.readdir(path, { withFileTypes: true });
28
+ if (entries.length > limits.directories) throw new Error("Too many session directories");
29
+ return entries;
30
+ }
31
+ async function read(path) {
32
+ const stat = await fs.lstat(path);
33
+ if (!stat.isFile() || stat.isSymbolicLink() || await fs.realpath(path) !== resolve(path))
34
+ throw new Error("Unsafe session file");
35
+ bytes += stat.size;
36
+ if (bytes > limits.bytes) throw new Error("Session usage file limit exceeded");
37
+ const stream = createReadStream(path, { encoding: "utf8", start: 0, end: Math.max(0, stat.size - 1) });
38
+ const lines = createInterface({ input: stream, crlfDelay: Infinity });
39
+ stream.on("error", () => lines.close());
40
+ let usageSeen = false;
41
+ try {
42
+ for await (const line of lines) {
43
+ if (Buffer.byteLength(line) > limits.lineBytes) throw new Error("Session line limit exceeded");
44
+ if (!line.trim()) continue;
45
+ const record = JSON.parse(line);
46
+ if (kind === "copilot" && record.type === "session.shutdown") {
47
+ const metrics = record.data?.modelMetrics;
48
+ if (!metrics || typeof metrics !== "object" || Array.isArray(metrics)) {
49
+ result.complete = false;
50
+ continue;
51
+ }
52
+ usageSeen = Object.keys(metrics).length > 0;
53
+ result.records = Object.values(metrics).map(metric => project(metric?.usage,
54
+ ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens"]));
55
+ }
56
+ if (kind === "kimi" && record.type === "usage.record") {
57
+ usageSeen = true;
58
+ result.records.push(project(record.usage,
59
+ ["inputOther", "output", "inputCacheRead", "inputCacheCreation"]));
60
+ }
61
+ if (result.records.length > limits.records) throw new Error("Too many usage records");
62
+ }
63
+ if (!usageSeen) result.complete = false;
64
+ if (stream.errored) throw stream.errored;
65
+ } finally {
66
+ lines.close();
67
+ stream.destroy();
68
+ }
69
+ }
70
+ (async () => {
71
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(id)) throw new Error("Invalid session ID");
72
+ if (kind === "copilot") {
73
+ const home = await fs.realpath(resolve(process.env.COPILOT_HOME || join(homedir(), ".copilot")));
74
+ await read(join(home, "session-state", id, "events.jsonl"));
75
+ return;
76
+ }
77
+ const home = await fs.realpath(resolve(process.env.KIMI_CODE_HOME || join(homedir(), ".kimi-code")));
78
+ const root = join(home, "sessions");
79
+ const buckets = await directory(root);
80
+ const matches = [];
81
+ for (const bucket of buckets) {
82
+ if (!bucket.isDirectory()) continue;
83
+ const path = join(root, bucket.name, id);
84
+ try {
85
+ const stat = await fs.lstat(path);
86
+ if (stat.isSymbolicLink()) throw new Error("Unsafe session directory");
87
+ if (stat.isDirectory()) matches.push(path);
88
+ } catch (error) {
89
+ if (error.code !== "ENOENT") throw error;
90
+ }
91
+ }
92
+ if (matches.length !== 1) throw new Error("Session directory is missing or ambiguous");
93
+ const rootAgents = join(matches[0], "agents");
94
+ const agents = await directory(rootAgents);
95
+ if (agents.length > limits.agents) throw new Error("Too many session agents");
96
+ let foundMain = false;
97
+ for (const agent of agents) {
98
+ if (agent.isSymbolicLink()) throw new Error("Unsafe agent directory");
99
+ if (!agent.isDirectory()) continue;
100
+ if (agent.name === "main") foundMain = true;
101
+ try { await read(join(rootAgents, agent.name, "wire.jsonl")); }
102
+ catch { result.complete = false; }
103
+ }
104
+ if (!foundMain) result.complete = false;
105
+ })().catch(() => { result.complete = false; }).finally(() => {
106
+ if (result.records.length > limits.records) result.records = [];
107
+ process.stdout.write(JSON.stringify(result));
108
+ });
109
+ `;
110
+ //# sourceMappingURL=session-usage.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-usage.constants.js","sourceRoot":"","sources":["../../../src/adapters/agents/session-usage.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,KAAK,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI;IACxB,SAAS,EAAE,IAAI,GAAG,IAAI;IACtB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,IAAI;IACjB,MAAM,EAAE,GAAG;IACX,UAAU,EAAE,IAAI;CACR,CAAC;AAEX,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmG3C,CAAC","sourcesContent":["export const sessionUsageLimits = {\n bytes: 64 * 1024 * 1024,\n outputBytes: 1024 * 1024,\n lineBytes: 1024 * 1024,\n records: 4096,\n directories: 4096,\n agents: 128,\n deadlineMs: 5000,\n} as const;\n\nexport const sessionUsageScript = String.raw`\nconst fs = require(\"node:fs/promises\");\nconst { createReadStream } = require(\"node:fs\");\nconst { createInterface } = require(\"node:readline\");\nconst { join, resolve } = require(\"node:path\");\nconst { homedir } = require(\"node:os\");\nconst [kind, id, encodedLimits] = process.argv.slice(1);\nconst limits = JSON.parse(encodedLimits);\nconst result = { records: [], complete: true };\nlet bytes = 0;\nfunction project(usage, keys) {\n return Object.fromEntries(keys.map(key => [key,\n typeof usage?.[key] === \"number\" ? usage[key] : null]));\n}\nasync function directory(path) {\n if ((await fs.lstat(path)).isSymbolicLink() || await fs.realpath(path) !== resolve(path))\n throw new Error(\"Unsafe session directory\");\n const entries = await fs.readdir(path, { withFileTypes: true });\n if (entries.length > limits.directories) throw new Error(\"Too many session directories\");\n return entries;\n}\nasync function read(path) {\n const stat = await fs.lstat(path);\n if (!stat.isFile() || stat.isSymbolicLink() || await fs.realpath(path) !== resolve(path))\n throw new Error(\"Unsafe session file\");\n bytes += stat.size;\n if (bytes > limits.bytes) throw new Error(\"Session usage file limit exceeded\");\n const stream = createReadStream(path, { encoding: \"utf8\", start: 0, end: Math.max(0, stat.size - 1) });\n const lines = createInterface({ input: stream, crlfDelay: Infinity });\n stream.on(\"error\", () => lines.close());\n let usageSeen = false;\n try {\n for await (const line of lines) {\n if (Buffer.byteLength(line) > limits.lineBytes) throw new Error(\"Session line limit exceeded\");\n if (!line.trim()) continue;\n const record = JSON.parse(line);\n if (kind === \"copilot\" && record.type === \"session.shutdown\") {\n const metrics = record.data?.modelMetrics;\n if (!metrics || typeof metrics !== \"object\" || Array.isArray(metrics)) {\n result.complete = false;\n continue;\n }\n usageSeen = Object.keys(metrics).length > 0;\n result.records = Object.values(metrics).map(metric => project(metric?.usage,\n [\"inputTokens\", \"outputTokens\", \"cacheReadTokens\", \"cacheWriteTokens\"]));\n }\n if (kind === \"kimi\" && record.type === \"usage.record\") {\n usageSeen = true;\n result.records.push(project(record.usage,\n [\"inputOther\", \"output\", \"inputCacheRead\", \"inputCacheCreation\"]));\n }\n if (result.records.length > limits.records) throw new Error(\"Too many usage records\");\n }\n if (!usageSeen) result.complete = false;\n if (stream.errored) throw stream.errored;\n } finally {\n lines.close();\n stream.destroy();\n }\n}\n(async () => {\n if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(id)) throw new Error(\"Invalid session ID\");\n if (kind === \"copilot\") {\n const home = await fs.realpath(resolve(process.env.COPILOT_HOME || join(homedir(), \".copilot\")));\n await read(join(home, \"session-state\", id, \"events.jsonl\"));\n return;\n }\n const home = await fs.realpath(resolve(process.env.KIMI_CODE_HOME || join(homedir(), \".kimi-code\")));\n const root = join(home, \"sessions\");\n const buckets = await directory(root);\n const matches = [];\n for (const bucket of buckets) {\n if (!bucket.isDirectory()) continue;\n const path = join(root, bucket.name, id);\n try {\n const stat = await fs.lstat(path);\n if (stat.isSymbolicLink()) throw new Error(\"Unsafe session directory\");\n if (stat.isDirectory()) matches.push(path);\n } catch (error) {\n if (error.code !== \"ENOENT\") throw error;\n }\n }\n if (matches.length !== 1) throw new Error(\"Session directory is missing or ambiguous\");\n const rootAgents = join(matches[0], \"agents\");\n const agents = await directory(rootAgents);\n if (agents.length > limits.agents) throw new Error(\"Too many session agents\");\n let foundMain = false;\n for (const agent of agents) {\n if (agent.isSymbolicLink()) throw new Error(\"Unsafe agent directory\");\n if (!agent.isDirectory()) continue;\n if (agent.name === \"main\") foundMain = true;\n try { await read(join(rootAgents, agent.name, \"wire.jsonl\")); }\n catch { result.complete = false; }\n }\n if (!foundMain) result.complete = false;\n})().catch(() => { result.complete = false; }).finally(() => {\n if (result.records.length > limits.records) result.records = [];\n process.stdout.write(JSON.stringify(result));\n});\n`;\n"]}
@@ -0,0 +1,5 @@
1
+ import type { Usage } from "../../domain/agent.types.ts";
2
+ import type { Command } from "../../domain/command.types.ts";
3
+ export declare function sessionUsageCommand(kind: "copilot" | "kimi", conversation: string): Command | undefined;
4
+ export declare function usageCounts(input: unknown, output: unknown, cached: unknown, cacheCreated: unknown): Usage;
5
+ export declare function sessionUsageResult(text: string, decode: (value: unknown) => Usage): Usage | undefined;
@@ -0,0 +1,45 @@
1
+ import { addUsage } from "../../domain/usage.js";
2
+ import { asRecord, decodeRecord } from "./protocol.js";
3
+ import { sessionUsageLimits, sessionUsageScript, } from "./session-usage.constants.js";
4
+ export function sessionUsageCommand(kind, conversation) {
5
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(conversation))
6
+ return;
7
+ return {
8
+ executable: "node",
9
+ arguments: [
10
+ "-e",
11
+ sessionUsageScript,
12
+ kind,
13
+ conversation,
14
+ JSON.stringify(sessionUsageLimits),
15
+ ],
16
+ retain: sessionUsageLimits.outputBytes,
17
+ deadlineMs: sessionUsageLimits.deadlineMs,
18
+ };
19
+ }
20
+ export function usageCounts(input, output, cached, cacheCreated) {
21
+ const valid = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
22
+ return {
23
+ input: valid(input) ? input : 0,
24
+ output: valid(output) ? output : 0,
25
+ cached: valid(cached) ? cached : 0,
26
+ cacheCreated: valid(cacheCreated) ? cacheCreated : 0,
27
+ ...([input, output, cached, cacheCreated].every(valid)
28
+ ? {}
29
+ : { complete: false }),
30
+ };
31
+ }
32
+ export function sessionUsageResult(text, decode) {
33
+ const result = decodeRecord(text);
34
+ if (!result || !Array.isArray(result.records))
35
+ return;
36
+ return result.records.reduce((total, value) => addUsage(total, decode(asRecord(value))), {
37
+ input: 0,
38
+ output: 0,
39
+ cached: 0,
40
+ ...(result.complete === true && result.records.length > 0
41
+ ? {}
42
+ : { complete: false }),
43
+ });
44
+ }
45
+ //# sourceMappingURL=session-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-usage.js","sourceRoot":"","sources":["../../../src/adapters/agents/session-usage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;A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ACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,MAAiC;IAEjC,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,OAAO;IACtD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAC1B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAC1D;QACE,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,MAAM,EAAE,CAAC;QACT,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YACvD,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;KACzB,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Usage } from \"../../domain/agent.types.ts\";\nimport type { Command } from \"../../domain/command.types.ts\";\nimport { addUsage } from \"../../domain/usage.ts\";\nimport { asRecord, decodeRecord } from \"./protocol.ts\";\nimport {\n sessionUsageLimits,\n sessionUsageScript,\n} from \"./session-usage.constants.ts\";\n\nexport function sessionUsageCommand(\n kind: \"copilot\" | \"kimi\",\n conversation: string,\n): Command | undefined {\n if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(conversation)) return;\n return {\n executable: \"node\",\n arguments: [\n \"-e\",\n sessionUsageScript,\n kind,\n conversation,\n JSON.stringify(sessionUsageLimits),\n ],\n retain: sessionUsageLimits.outputBytes,\n deadlineMs: sessionUsageLimits.deadlineMs,\n };\n}\n\nexport function usageCounts(\n input: unknown,\n output: unknown,\n cached: unknown,\n cacheCreated: unknown,\n): Usage {\n const valid = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n return {\n input: valid(input) ? input : 0,\n output: valid(output) ? output : 0,\n cached: valid(cached) ? cached : 0,\n cacheCreated: valid(cacheCreated) ? cacheCreated : 0,\n ...([input, output, cached, cacheCreated].every(valid)\n ? {}\n : { complete: false }),\n };\n}\n\nexport function sessionUsageResult(\n text: string,\n decode: (value: unknown) => Usage,\n): Usage | undefined {\n const result = decodeRecord(text);\n if (!result || !Array.isArray(result.records)) return;\n return result.records.reduce<Usage>(\n (total, value) => addUsage(total, decode(asRecord(value))),\n {\n input: 0,\n output: 0,\n cached: 0,\n ...(result.complete === true && result.records.length > 0\n ? {}\n : { complete: false }),\n },\n );\n}\n"]}
@@ -7,6 +7,7 @@ export interface CommonAgentSettings {
7
7
  readonly saveConversations?: boolean;
8
8
  }
9
9
  export interface ClaudeSettings extends CommonAgentSettings {
10
+ readonly partialMessages?: boolean;
10
11
  readonly permissions?: "default" | "acceptEdits" | "plan" | "auto" | "dontAsk" | "bypassPermissions";
11
12
  }
12
13
  export interface CodexModelProvider {
@@ -1 +1 @@
1
- {"version":3,"file":"settings.types.js","sourceRoot":"","sources":["../../../src/adapters/agents/settings.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentAuthentication } from \"../../domain/agent.types.ts\";\nimport type { Variables } from \"../../domain/command.types.ts\";\nimport type { AgentModel, ModelReasoning } from \"../../domain/model.types.ts\";\n\nexport interface CommonAgentSettings {\n readonly authentication?: AgentAuthentication;\n readonly variables?: Variables;\n readonly saveConversations?: boolean;\n}\n\nexport interface ClaudeSettings extends CommonAgentSettings {\n readonly permissions?:\n | \"default\"\n | \"acceptEdits\"\n | \"plan\"\n | \"auto\"\n | \"dontAsk\"\n | \"bypassPermissions\";\n}\n\nexport interface CodexModelProvider {\n readonly baseUrl: string;\n readonly apiKeyEnvironment?: string | false;\n}\n\nexport interface CodexSettings extends CommonAgentSettings {\n readonly modelProvider?: CodexModelProvider;\n readonly approvalReviewer?: \"user\" | \"auto_review\";\n}\n\nexport type Bound<Settings> = Settings & { readonly model?: AgentModel };\n\nexport interface CliModelSupport {\n readonly agent: string;\n readonly reasoning: ReadonlySet<ModelReasoning>;\n readonly maxOutputTokens: boolean;\n}\n"]}
1
+ {"version":3,"file":"settings.types.js","sourceRoot":"","sources":["../../../src/adapters/agents/settings.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentAuthentication } from \"../../domain/agent.types.ts\";\nimport type { Variables } from \"../../domain/command.types.ts\";\nimport type { AgentModel, ModelReasoning } from \"../../domain/model.types.ts\";\n\nexport interface CommonAgentSettings {\n readonly authentication?: AgentAuthentication;\n readonly variables?: Variables;\n readonly saveConversations?: boolean;\n}\n\nexport interface ClaudeSettings extends CommonAgentSettings {\n readonly partialMessages?: boolean;\n readonly permissions?:\n | \"default\"\n | \"acceptEdits\"\n | \"plan\"\n | \"auto\"\n | \"dontAsk\"\n | \"bypassPermissions\";\n}\n\nexport interface CodexModelProvider {\n readonly baseUrl: string;\n readonly apiKeyEnvironment?: string | false;\n}\n\nexport interface CodexSettings extends CommonAgentSettings {\n readonly modelProvider?: CodexModelProvider;\n readonly approvalReviewer?: \"user\" | \"auto_review\";\n}\n\nexport type Bound<Settings> = Settings & { readonly model?: AgentModel };\n\nexport interface CliModelSupport {\n readonly agent: string;\n readonly reasoning: ReadonlySet<ModelReasoning>;\n readonly maxOutputTokens: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { AgentEvent } from "../../domain/agent.types.ts";
2
+ export declare function toolResult(callId: unknown, name: unknown, value: unknown, isError?: boolean): AgentEvent[];
@@ -0,0 +1,17 @@
1
+ import { observationDefaults } from "../../domain/observation.constants.js";
2
+ export function toolResult(callId, name, value, isError = false) {
3
+ if (typeof callId !== "string" || !callId)
4
+ return [];
5
+ const content = typeof value === "string" ? value : (JSON.stringify(value) ?? "");
6
+ return [
7
+ {
8
+ kind: "tool-result",
9
+ callId,
10
+ name: typeof name === "string" ? name : "",
11
+ isError,
12
+ preview: content.slice(0, observationDefaults.previewCharacters),
13
+ characters: content.length,
14
+ },
15
+ ];
16
+ }
17
+ //# sourceMappingURL=tool-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result.js","sourceRoot":"","sources":["../../../src/adapters/agents/tool-result.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE5E,MAAM,UAAU,UAAU,CACxB,MAAe,EACf,IAAa,EACb,KAAc,EACd,OAAO,GAAG,KAAK;IAEf,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACrD,MAAM,OAAO,GACX,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,OAAO;QACL;YACE,IAAI,EAAE,aAAa;YACnB,MAAM;YACN,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC1C,OAAO;YACP,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC,iBAAiB,CAAC;YAChE,UAAU,EAAE,OAAO,CAAC,MAAM;SAC3B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentEvent } from \"../../domain/agent.types.ts\";\nimport { observationDefaults } from \"../../domain/observation.constants.ts\";\n\nexport function toolResult(\n callId: unknown,\n name: unknown,\n value: unknown,\n isError = false,\n): AgentEvent[] {\n if (typeof callId !== \"string\" || !callId) return [];\n const content =\n typeof value === \"string\" ? value : (JSON.stringify(value) ?? \"\");\n return [\n {\n kind: \"tool-result\",\n callId,\n name: typeof name === \"string\" ? name : \"\",\n isError,\n preview: content.slice(0, observationDefaults.previewCharacters),\n characters: content.length,\n },\n ];\n}\n"]}
@@ -35,6 +35,9 @@ function reasoning(block, context) {
35
35
  provider: context.identity,
36
36
  model: context.model,
37
37
  data: block,
38
+ ...(typeof block.thinking === "string" && block.thinking
39
+ ? { text: block.thinking }
40
+ : {}),
38
41
  };
39
42
  }
40
43
  function usage(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-response.js","sourceRoot":"","sources":["../../../src/adapters/models/anthropic-response.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,MAAM,EACN,eAAe,EACf,UAAU,EACV,MAAM,EACN,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,QAAQ,GAQV;IACF,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;QACd,eAAe,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;QAChD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC;IACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;QAClB,eAAe,CACb,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC/D,CAAC;QACF,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;SAC9B,CAAC;IACJ,CAAC;IACD,QAAQ,EAAE,SAAS;IACnB,iBAAiB,EAAE,SAAS;CAC7B,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,KAAc,EACd,UAA2B,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE;IAE/D,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,eAAe,CAAC,IAAI,CAAC,IAAI,KAAK,SA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AG,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM,GAAG,YAAY,CAAC;IACpE,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,OAAO;QACL,KAAK;QACL,MAAM;QACN,YAAY;QACZ,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ModelContentBlock,\n ModelResult,\n} from \"../../domain/model.types.ts\";\nimport type { ProtocolContext } from \"./model-protocol.types.ts\";\nimport {\n modelResult,\n object,\n requireResponse,\n stopReason,\n tokens,\n toolInput,\n} from \"./model-response.ts\";\nimport { ANTHROPIC_STOP_REASONS } from \"./stop-reasons.constants.ts\";\n\nconst decoders: Readonly<\n Record<\n string,\n (\n block: Record<string, unknown>,\n context: ProtocolContext,\n ) => ModelContentBlock\n >\n> = {\n text: (block) => {\n requireResponse(typeof block.text === \"string\");\n return { type: \"text\", text: block.text };\n },\n tool_use: (block) => {\n requireResponse(\n typeof block.id === \"string\" && typeof block.name === \"string\",\n );\n return {\n type: \"tool-call\",\n id: block.id,\n name: block.name,\n input: toolInput(block.input),\n };\n },\n thinking: reasoning,\n redacted_thinking: reasoning,\n};\n\nexport function readAnthropicResponse(\n value: unknown,\n context: ProtocolContext = { identity: \"anthropic\", model: \"\" },\n): ModelResult {\n const data = object(value);\n requireResponse(data.type === \"message\" && data.role === \"assistant\");\n const reason = stopReason(ANTHROPIC_STOP_REASONS, data.stop_reason);\n requireResponse(Array.isArray(data.content));\n const content = data.content.map((value) => {\n const block = object(value);\n requireResponse(\n typeof block.type === \"string\" && Object.hasOwn(decoders, block.type),\n );\n return decoders[block.type]!(block, context);\n });\n return modelResult(content, reason, usage(data.usage));\n}\n\nfunction reasoning(\n block: Record<string, unknown>,\n context: ProtocolContext,\n): ModelContentBlock {\n return {\n type: \"reasoning\",\n provider: context.identity,\n model: context.model,\n data: block,\n };\n}\n\nfunction usage(value: unknown): ModelResult[\"usage\"] {\n if (value === undefined) return undefined;\n const reported = object(value);\n const cached = tokens(reported.cache_read_input_tokens ?? 0);\n const cacheCreated = tokens(reported.cache_creation_input_tokens ?? 0);\n const input = tokens(reported.input_tokens) + cached + cacheCreated;\n requireResponse(Number.isSafeInteger(input));\n return {\n input,\n cached,\n cacheCreated,\n output: tokens(reported.output_tokens),\n };\n}\n"]}
1
+ {"version":3,"file":"anthropic-response.js","sourceRoot":"","sources":["../../../src/adapters/models/anthropic-response.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,MAAM,EACN,eAAe,EACf,UAAU,EACV,MAAM,EACN,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,QAAQ,GAQV;IACF,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;QACd,eAAe,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;QAChD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC;IACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;QAClB,eAAe,CACb,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC/D,CAAC;QACF,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;SAC9B,CAAC;IACJ,CAAC;IACD,QAAQ,EAAE,SAAS;IACnB,iBAAiB,EAAE,SAAS;CAC7B,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,KAAc,EACd,UAA2B,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE;I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AAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,uBAAuB,IAAI,CAAC,CAAC,CAAC;IAC7D,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,2BAA2B,IAAI,CAAC,CAAC,CAAC;IACvE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM,GAAG,YAAY,CAAC;IACpE,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,OAAO;QACL,KAAK;QACL,MAAM;QACN,YAAY;QACZ,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ModelContentBlock,\n ModelResult,\n} from \"../../domain/model.types.ts\";\nimport type { ProtocolContext } from \"./model-protocol.types.ts\";\nimport {\n modelResult,\n object,\n requireResponse,\n stopReason,\n tokens,\n toolInput,\n} from \"./model-response.ts\";\nimport { ANTHROPIC_STOP_REASONS } from \"./stop-reasons.constants.ts\";\n\nconst decoders: Readonly<\n Record<\n string,\n (\n block: Record<string, unknown>,\n context: ProtocolContext,\n ) => ModelContentBlock\n >\n> = {\n text: (block) => {\n requireResponse(typeof block.text === \"string\");\n return { type: \"text\", text: block.text };\n },\n tool_use: (block) => {\n requireResponse(\n typeof block.id === \"string\" && typeof block.name === \"string\",\n );\n return {\n type: \"tool-call\",\n id: block.id,\n name: block.name,\n input: toolInput(block.input),\n };\n },\n thinking: reasoning,\n redacted_thinking: reasoning,\n};\n\nexport function readAnthropicResponse(\n value: unknown,\n context: ProtocolContext = { identity: \"anthropic\", model: \"\" },\n): ModelResult {\n const data = object(value);\n requireResponse(data.type === \"message\" && data.role === \"assistant\");\n const reason = stopReason(ANTHROPIC_STOP_REASONS, data.stop_reason);\n requireResponse(Array.isArray(data.content));\n const content = data.content.map((value) => {\n const block = object(value);\n requireResponse(\n typeof block.type === \"string\" && Object.hasOwn(decoders, block.type),\n );\n return decoders[block.type]!(block, context);\n });\n return modelResult(content, reason, usage(data.usage));\n}\n\nfunction reasoning(\n block: Record<string, unknown>,\n context: ProtocolContext,\n): ModelContentBlock {\n return {\n type: \"reasoning\",\n provider: context.identity,\n model: context.model,\n data: block,\n ...(typeof block.thinking === \"string\" && block.thinking\n ? { text: block.thinking }\n : {}),\n };\n}\n\nfunction usage(value: unknown): ModelResult[\"usage\"] {\n if (value === undefined) return undefined;\n const reported = object(value);\n const cached = tokens(reported.cache_read_input_tokens ?? 0);\n const cacheCreated = tokens(reported.cache_creation_input_tokens ?? 0);\n const input = tokens(reported.input_tokens) + cached + cacheCreated;\n requireResponse(Number.isSafeInteger(input));\n return {\n input,\n cached,\n cacheCreated,\n output: tokens(reported.output_tokens),\n };\n}\n"]}
@@ -2,6 +2,7 @@ import { invariant, OutpostError, positive } from "../../domain/errors.js";
2
2
  import { serverSentEvents } from "../../infrastructure/sse.js";
3
3
  import { MODEL_MAX_TIMEOUT_MS, MODEL_RESPONSE_BYTES, MODEL_TIMEOUT_MS, } from "./model.constants.js";
4
4
  import { validateModelRequest } from "./model-request.js";
5
+ import { retryAfterMs } from "./retry-after.js";
5
6
  import { modelJson } from "./model-http.js";
6
7
  export function httpModelProvider(options, protocol, name, headers) {
7
8
  let base;
@@ -36,8 +37,12 @@ export function httpModelProvider(options, protocol, name, headers) {
36
37
  });
37
38
  if (response.ok)
38
39
  return response;
40
+ const retryAfter = retryAfterMs(response.headers.get("Retry-After"));
39
41
  await response.body?.cancel();
40
- throw new OutpostError("provider", `Model request failed with HTTP ${response.status}`, { status: response.status });
42
+ throw new OutpostError("provider", `Model request failed with HTTP ${response.status}`, {
43
+ status: response.status,
44
+ ...(retryAfter === undefined ? {} : { retryAfterMs: retryAfter }),
45
+ });
41
46
  };
42
47
  const failure = (error, signal, deadline, request) => {
43
48
  if (signal.aborted) {
@@ -1 +1 @@
1
- {"version":3,"file":"http-provider.js","sourceRoot":"","sources":["../../../src/adapters/models/http-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAM3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAK/D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,UAAU,iBAAiB,CAC/B,OAAyB,EACzB,QAAuB,EACvB,IAAY,EACZ,OAAyC;IAEzC,IAAI,IAAS,CAAC;IACd,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,YAAY,CACpB,eAAe,EACf,+CAA+C,CAChD,CAAC;IACJ,CAAC;IACD,SAAS,CACP,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzC,CAAC,IAAI,CAAC,QAAQ;QACd,CAAC,IAAI,CAAC,QAAQ;QACd,CAAC,IAAI,CAAC,MAAM;QACZ,CAAC,IAAI,CAAC,IAAI,EACZ,uEAAuE,CACxE,CAAC;IACF,SAAS,CACP,OAAO,CAAC,MAAM,KAAK,KAAK;QACtB,CAAC,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;YACjC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;YACrB,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EACnC,4EAA4E,CAC7E,CAAC;IACF,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,IAAI,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EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,KAAK,CAAC,OAAO,CAAC,OAAqB;YACjC,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAC9B,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM;gBAC3B,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACpD,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;YACpB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;YAC5D,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;gBACtE,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAClD,MAAM,CAAC,cAAc,EAAE,CAAC;gBACxB,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACzD,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { invariant, OutpostError, positive } from \"../../domain/errors.ts\";\nimport type {\n ModelProvider,\n ModelRequest,\n ModelStreamEvent,\n} from \"../../domain/model.types.ts\";\nimport { serverSentEvents } from \"../../infrastructure/sse.ts\";\nimport type {\n HttpModelOptions,\n ModelProtocol,\n} from \"./model-protocol.types.ts\";\nimport {\n MODEL_MAX_TIMEOUT_MS,\n MODEL_RESPONSE_BYTES,\n MODEL_TIMEOUT_MS,\n} from \"./model.constants.ts\";\nimport { validateModelRequest } from \"./model-request.ts\";\nimport { modelJson } from \"./model-http.ts\";\n\nexport function httpModelProvider(\n options: HttpModelOptions,\n protocol: ModelProtocol,\n name: string,\n headers: Readonly<Record<string, string>>,\n): ModelProvider {\n let base: URL;\n try {\n base = new URL(options.baseUrl);\n } catch {\n throw new OutpostError(\n \"configuration\",\n \"Model baseUrl must be an absolute HTTP(S) URL\",\n );\n }\n invariant(\n [\"http:\", \"https:\"].includes(base.protocol) &&\n !base.username &&\n !base.password &&\n !base.search &&\n !base.hash,\n \"Model baseUrl must use HTTP(S) without credentials, query or fragment\",\n );\n invariant(\n options.apiKey === false ||\n (typeof options.apiKey === \"string\" &&\n options.apiKey.trim() &&\n !/[\\r\\n]/.test(options.apiKey)),\n \"Model apiKey must be a nonempty key or false for unauthenticated endpoints\",\n );\n const endpoint = `${base.href.replace(/\\/+$/, \"\")}/${protocol.path}`;\n const timeoutMs = positive(\n options.timeoutMs ?? MODEL_TIMEOUT_MS,\n \"Model timeoutMs\",\n );\n invariant(\n timeoutMs <= MODEL_MAX_TIMEOUT_MS,\n \"Model timeoutMs exceeds the supported timer range\",\n );\n const maxBytes = positive(\n options.maxResponseBytes ?? MODEL_RESPONSE_BYTES,\n \"Model maxResponseBytes\",\n );\n const identity = `${name}:${protocol.path}:${base.origin}${base.pathname.replace(/\\/+$/, \"\")}`;\n const post = async (body: unknown, signal: AbortSignal) => {\n signal.throwIfAborted();\n const response = await fetch(endpoint, {\n method: \"POST\",\n redirect: \"error\",\n headers: { \"Content-Type\": \"application/json\", ...headers },\n body: JSON.stringify(body),\n signal,\n });\n if (response.ok) return response;\n await response.body?.cancel();\n throw new OutpostError(\n \"provider\",\n `Model request failed with HTTP ${response.status}`,\n { status: response.status },\n );\n };\n const failure = (\n error: unknown,\n signal: AbortSignal,\n deadline: AbortSignal,\n request: ModelRequest,\n ): OutpostError => {\n if (signal.aborted) {\n const timedOut = deadline.aborted && !request.signal?.aborted;\n return new OutpostError(\n timedOut ? \"timeout\" : \"aborted\",\n timedOut ? \"Model request timed out\" : \"Model request was cancelled\",\n );\n }\n if (error instanceof OutpostError) return error;\n return new OutpostError(\n \"provider\",\n \"Model request failed during HTTP transport\",\n );\n };\n async function* stream(\n request: ModelRequest,\n ): AsyncGenerator<ModelStreamEvent> {\n validateModelRequest(request);\n const streaming = protocol.stream!;\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n let timer = setTimeout(() => deadline.abort(), timeoutMs);\n const refresh = () => {\n clearTimeout(timer);\n timer = setTimeout(() => deadline.abort(), timeoutMs);\n };\n try {\n const response = await post(\n { ...protocol.build(request, context), ...streaming.body },\n signal,\n );\n if (!response.body)\n throw new OutpostError(\"response\", \"Model response has no body\");\n const decoder = streaming.decoder();\n for await (const event of serverSentEvents(\n response.body,\n maxBytes,\n refresh,\n )) {\n signal.throwIfAborted();\n const text = decoder.push(event);\n if (text) yield { type: \"text-delta\", text };\n }\n signal.throwIfAborted();\n yield { type: \"result\", result: protocol.read(decoder.final(), context) };\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n }\n return Object.freeze({\n name,\n identity,\n ...(protocol.validate ? { validate: protocol.validate } : {}),\n ...(protocol.stream ? { stream } : {}),\n async request(request: ModelRequest) {\n validateModelRequest(request);\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n const timer = setTimeout(() => deadline.abort(), timeoutMs);\n try {\n const response = await post(protocol.build(request, context), signal);\n const value = await modelJson(response, maxBytes);\n signal.throwIfAborted();\n return protocol.read(value, context);\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n },\n });\n}\n"]}
1
+ {"version":3,"file":"http-provider.js","sourceRoot":"","sources":["../../../src/adapters/models/http-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAM3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAK/D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,UAAU,iBAAiB,CAC/B,OAAyB,EACzB,QAAuB,EACvB,IAAY,EACZ,OAAyC;IAEzC,IAAI,IAAS,CAAC;IACd,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,YAAY,CACpB,eAAe,EACf,+CAA+C,CAChD,CAAC;IACJ,CAAC;IACD,SAAS,CACP,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzC,CAAC,IAAI,CAAC,QAAQ;QACd,CAAC,IAAI,CAAC,QAAQ;QACd,CAAC,IAAI,CAAC,MAAM;QACZ,CAAC,IAAI,CAAC,IAAI,EACZ,uEAAuE,CACxE,CAAC;IACF,SAAS,CACP,OAAO,CAAC,MAAM,KAAK,KAAK;QACtB,CAAC,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;YACjC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;YACrB,CAAC,QAAQ,CAAC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AAE,CAAC;gBACf,MAAM,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACzD,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { invariant, OutpostError, positive } from \"../../domain/errors.ts\";\nimport type {\n ModelProvider,\n ModelRequest,\n ModelStreamEvent,\n} from \"../../domain/model.types.ts\";\nimport { serverSentEvents } from \"../../infrastructure/sse.ts\";\nimport type {\n HttpModelOptions,\n ModelProtocol,\n} from \"./model-protocol.types.ts\";\nimport {\n MODEL_MAX_TIMEOUT_MS,\n MODEL_RESPONSE_BYTES,\n MODEL_TIMEOUT_MS,\n} from \"./model.constants.ts\";\nimport { validateModelRequest } from \"./model-request.ts\";\nimport { retryAfterMs } from \"./retry-after.ts\";\nimport { modelJson } from \"./model-http.ts\";\n\nexport function httpModelProvider(\n options: HttpModelOptions,\n protocol: ModelProtocol,\n name: string,\n headers: Readonly<Record<string, string>>,\n): ModelProvider {\n let base: URL;\n try {\n base = new URL(options.baseUrl);\n } catch {\n throw new OutpostError(\n \"configuration\",\n \"Model baseUrl must be an absolute HTTP(S) URL\",\n );\n }\n invariant(\n [\"http:\", \"https:\"].includes(base.protocol) &&\n !base.username &&\n !base.password &&\n !base.search &&\n !base.hash,\n \"Model baseUrl must use HTTP(S) without credentials, query or fragment\",\n );\n invariant(\n options.apiKey === false ||\n (typeof options.apiKey === \"string\" &&\n options.apiKey.trim() &&\n !/[\\r\\n]/.test(options.apiKey)),\n \"Model apiKey must be a nonempty key or false for unauthenticated endpoints\",\n );\n const endpoint = `${base.href.replace(/\\/+$/, \"\")}/${protocol.path}`;\n const timeoutMs = positive(\n options.timeoutMs ?? MODEL_TIMEOUT_MS,\n \"Model timeoutMs\",\n );\n invariant(\n timeoutMs <= MODEL_MAX_TIMEOUT_MS,\n \"Model timeoutMs exceeds the supported timer range\",\n );\n const maxBytes = positive(\n options.maxResponseBytes ?? MODEL_RESPONSE_BYTES,\n \"Model maxResponseBytes\",\n );\n const identity = `${name}:${protocol.path}:${base.origin}${base.pathname.replace(/\\/+$/, \"\")}`;\n const post = async (body: unknown, signal: AbortSignal) => {\n signal.throwIfAborted();\n const response = await fetch(endpoint, {\n method: \"POST\",\n redirect: \"error\",\n headers: { \"Content-Type\": \"application/json\", ...headers },\n body: JSON.stringify(body),\n signal,\n });\n if (response.ok) return response;\n const retryAfter = retryAfterMs(response.headers.get(\"Retry-After\"));\n await response.body?.cancel();\n throw new OutpostError(\n \"provider\",\n `Model request failed with HTTP ${response.status}`,\n {\n status: response.status,\n ...(retryAfter === undefined ? {} : { retryAfterMs: retryAfter }),\n },\n );\n };\n const failure = (\n error: unknown,\n signal: AbortSignal,\n deadline: AbortSignal,\n request: ModelRequest,\n ): OutpostError => {\n if (signal.aborted) {\n const timedOut = deadline.aborted && !request.signal?.aborted;\n return new OutpostError(\n timedOut ? \"timeout\" : \"aborted\",\n timedOut ? \"Model request timed out\" : \"Model request was cancelled\",\n );\n }\n if (error instanceof OutpostError) return error;\n return new OutpostError(\n \"provider\",\n \"Model request failed during HTTP transport\",\n );\n };\n async function* stream(\n request: ModelRequest,\n ): AsyncGenerator<ModelStreamEvent> {\n validateModelRequest(request);\n const streaming = protocol.stream!;\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n let timer = setTimeout(() => deadline.abort(), timeoutMs);\n const refresh = () => {\n clearTimeout(timer);\n timer = setTimeout(() => deadline.abort(), timeoutMs);\n };\n try {\n const response = await post(\n { ...protocol.build(request, context), ...streaming.body },\n signal,\n );\n if (!response.body)\n throw new OutpostError(\"response\", \"Model response has no body\");\n const decoder = streaming.decoder();\n for await (const event of serverSentEvents(\n response.body,\n maxBytes,\n refresh,\n )) {\n signal.throwIfAborted();\n const text = decoder.push(event);\n if (text) yield { type: \"text-delta\", text };\n }\n signal.throwIfAborted();\n yield { type: \"result\", result: protocol.read(decoder.final(), context) };\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n }\n return Object.freeze({\n name,\n identity,\n ...(protocol.validate ? { validate: protocol.validate } : {}),\n ...(protocol.stream ? { stream } : {}),\n async request(request: ModelRequest) {\n validateModelRequest(request);\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n const timer = setTimeout(() => deadline.abort(), timeoutMs);\n try {\n const response = await post(protocol.build(request, context), signal);\n const value = await modelJson(response, maxBytes);\n signal.throwIfAborted();\n return protocol.read(value, context);\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n },\n });\n}\n"]}
@@ -43,6 +43,16 @@ export function readModelResponse(value, context = { identity: "openai", model:
43
43
  provider: context.identity,
44
44
  model: context.model,
45
45
  data: item,
46
+ ...(Array.isArray(item.summary)
47
+ ? {
48
+ text: item.summary
49
+ .flatMap((value) => {
50
+ const entry = object(value);
51
+ return typeof entry.text === "string" ? [entry.text] : [];
52
+ })
53
+ .join("\n"),
54
+ }
55
+ : {}),
46
56
  },
47
57
  ];
48
58
  if (item.type === "function_call")
@@ -1 +1 @@
1
- {"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../../src/adapters/models/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAS7E,OAAO,EACL,WAAW,EACX,MAAM,EACN,eAAe,EACf,UAAU,EACV,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,UAAU,aAAa,CAC3B,OAAq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;IACF,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI;CACjC,CAAC","sourcesContent":["import { replayable, requestMessages } from \"../../domain/model-messages.ts\";\nimport type {\n ModelContentBlock,\n ModelMessage,\n ModelRequest,\n ModelResult,\n ModelStopReason,\n} from \"../../domain/model.types.ts\";\nimport type { BlockEncoders, ProtocolContext } from \"./model-protocol.types.ts\";\nimport {\n modelResult,\n object,\n requireResponse,\n stopReason,\n toolInput,\n} from \"./model-response.ts\";\nimport { openaiUsage, toolArguments } from \"./openai-usage.ts\";\nimport { RESPONSES_INCOMPLETE_REASONS } from \"./stop-reasons.constants.ts\";\n\nexport function responsesBody(\n request: ModelRequest,\n context: ProtocolContext,\n): Record<string, unknown> {\n const items = requestMessages(request).flatMap((message) =>\n responseItems(message, context),\n );\n return {\n model: context.model,\n input: request.messages === undefined ? request.prompt : items,\n ...(request.system === undefined ? {} : { instructions: request.system }),\n ...(request.tools?.length\n ? {\n tools: request.tools.map((tool) => ({\n type: \"function\",\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n })),\n }\n : {}),\n stream: false,\n store: false,\n ...(request.maxOutputTokens === undefined\n ? {}\n : { max_output_tokens: request.maxOutputTokens }),\n ...(request.reasoning === undefined\n ? {}\n : { reasoning: { effort: request.reasoning } }),\n };\n}\n\nexport function readModelResponse(\n value: unknown,\n context: ProtocolContext = { identity: \"openai\", model: \"\" },\n): ModelResult {\n const data = object(value);\n requireResponse(data.error == null && Array.isArray(data.output));\n const incomplete = data.status === \"incomplete\";\n requireResponse(incomplete || data.status === \"completed\");\n let refused = false;\n const content = data.output.flatMap((value): ModelContentBlock[] => {\n const item = object(value);\n if (item.type === \"reasoning\")\n return [\n {\n type: \"reasoning\",\n provider: context.identity,\n model: context.model,\n data: item,\n },\n ];\n if (item.type === \"function_call\") return [functionCall(item)];\n requireResponse(item.type === \"message\" && item.role === \"assistant\");\n requireResponse(item.status === \"completed\" || incomplete);\n requireResponse(Array.isArray(item.content));\n return item.content.flatMap((value): ModelContentBlock[] => {\n const part = object(value);\n if (part.type === \"refusal\") {\n requireResponse(typeof part.refusal === \"string\");\n refused = true;\n return [];\n }\n requireResponse(\n part.type === \"output_text\" && typeof part.text === \"string\",\n );\n return [{ type: \"text\", text: part.text }];\n });\n });\n const reason = refused ? \"refusal\" : completion(data, incomplete);\n return modelResult(\n content,\n reason,\n openaiUsage(\n data.usage,\n \"input_tokens\",\n \"output_tokens\",\n \"input_tokens_details\",\n ),\n );\n}\n\nfunction completion(\n data: Record<string, unknown>,\n incomplete: boolean,\n): ModelStopReason {\n if (!incomplete) return \"end\";\n return stopReason(\n RESPONSES_INCOMPLETE_REASONS,\n object(data.incomplete_details).reason,\n );\n}\n\nfunction functionCall(item: Record<string, unknown>): ModelContentBlock {\n requireResponse(\n typeof item.call_id === \"string\" &&\n typeof item.name === \"string\" &&\n typeof item.arguments === \"string\",\n );\n return {\n type: \"tool-call\",\n id: item.call_id,\n name: item.name,\n input: toolInput(item.arguments),\n };\n}\n\nfunction responseItems(message: ModelMessage, context: ProtocolContext) {\n return message.content\n .filter((block) => replayable(block, context.identity, context.model))\n .toSorted((left, right) => order(message, left) - order(message, right))\n .map((block) => itemEncoders[block.type](block as never, message.role));\n}\n\nfunction order(message: ModelMessage, block: ModelContentBlock): number {\n return message.role === \"user\" && block.type !== \"tool-result\" ? 1 : 0;\n}\n\nconst itemEncoders: BlockEncoders<[role: ModelMessage[\"role\"]]> = {\n text: (block, role) => ({ role, content: block.text }),\n \"tool-call\": (block) => ({\n type: \"function_call\",\n call_id: block.id,\n name: block.name,\n arguments: toolArguments(block.input),\n }),\n \"tool-result\": (block) => ({\n type: \"function_call_output\",\n call_id: block.callId,\n output: block.content,\n }),\n reasoning: (block) => block.data,\n};\n"]}
1
+ {"version":3,"file":"openai-responses.js","sourceRoot":"","sources":["../../../src/adapters/models/openai-responses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,M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,CAAC,OAAqB,EAAE,KAAwB;IAC5D,OAAO,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,YAAY,GAAgD;IAChE,IAAI,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IACtD,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,KAAK,CAAC,EAAE;QACjB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;KACtC,CAAC;IACF,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACzB,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,KAAK,CAAC,MAAM;QACrB,MAAM,EAAE,KAAK,CAAC,OAAO;KACtB,CAAC;IACF,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI;CACjC,CAAC","sourcesContent":["import { replayable, requestMessages } from \"../../domain/model-messages.ts\";\nimport type {\n ModelContentBlock,\n ModelMessage,\n ModelRequest,\n ModelResult,\n ModelStopReason,\n} from \"../../domain/model.types.ts\";\nimport type { BlockEncoders, ProtocolContext } from \"./model-protocol.types.ts\";\nimport {\n modelResult,\n object,\n requireResponse,\n stopReason,\n toolInput,\n} from \"./model-response.ts\";\nimport { openaiUsage, toolArguments } from \"./openai-usage.ts\";\nimport { RESPONSES_INCOMPLETE_REASONS } from \"./stop-reasons.constants.ts\";\n\nexport function responsesBody(\n request: ModelRequest,\n context: ProtocolContext,\n): Record<string, unknown> {\n const items = requestMessages(request).flatMap((message) =>\n responseItems(message, context),\n );\n return {\n model: context.model,\n input: request.messages === undefined ? request.prompt : items,\n ...(request.system === undefined ? {} : { instructions: request.system }),\n ...(request.tools?.length\n ? {\n tools: request.tools.map((tool) => ({\n type: \"function\",\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n })),\n }\n : {}),\n stream: false,\n store: false,\n ...(request.maxOutputTokens === undefined\n ? {}\n : { max_output_tokens: request.maxOutputTokens }),\n ...(request.reasoning === undefined\n ? {}\n : { reasoning: { effort: request.reasoning } }),\n };\n}\n\nexport function readModelResponse(\n value: unknown,\n context: ProtocolContext = { identity: \"openai\", model: \"\" },\n): ModelResult {\n const data = object(value);\n requireResponse(data.error == null && Array.isArray(data.output));\n const incomplete = data.status === \"incomplete\";\n requireResponse(incomplete || data.status === \"completed\");\n let refused = false;\n const content = data.output.flatMap((value): ModelContentBlock[] => {\n const item = object(value);\n if (item.type === \"reasoning\")\n return [\n {\n type: \"reasoning\",\n provider: context.identity,\n model: context.model,\n data: item,\n ...(Array.isArray(item.summary)\n ? {\n text: item.summary\n .flatMap((value) => {\n const entry = object(value);\n return typeof entry.text === \"string\" ? [entry.text] : [];\n })\n .join(\"\\n\"),\n }\n : {}),\n },\n ];\n if (item.type === \"function_call\") return [functionCall(item)];\n requireResponse(item.type === \"message\" && item.role === \"assistant\");\n requireResponse(item.status === \"completed\" || incomplete);\n requireResponse(Array.isArray(item.content));\n return item.content.flatMap((value): ModelContentBlock[] => {\n const part = object(value);\n if (part.type === \"refusal\") {\n requireResponse(typeof part.refusal === \"string\");\n refused = true;\n return [];\n }\n requireResponse(\n part.type === \"output_text\" && typeof part.text === \"string\",\n );\n return [{ type: \"text\", text: part.text }];\n });\n });\n const reason = refused ? \"refusal\" : completion(data, incomplete);\n return modelResult(\n content,\n reason,\n openaiUsage(\n data.usage,\n \"input_tokens\",\n \"output_tokens\",\n \"input_tokens_details\",\n ),\n );\n}\n\nfunction completion(\n data: Record<string, unknown>,\n incomplete: boolean,\n): ModelStopReason {\n if (!incomplete) return \"end\";\n return stopReason(\n RESPONSES_INCOMPLETE_REASONS,\n object(data.incomplete_details).reason,\n );\n}\n\nfunction functionCall(item: Record<string, unknown>): ModelContentBlock {\n requireResponse(\n typeof item.call_id === \"string\" &&\n typeof item.name === \"string\" &&\n typeof item.arguments === \"string\",\n );\n return {\n type: \"tool-call\",\n id: item.call_id,\n name: item.name,\n input: toolInput(item.arguments),\n };\n}\n\nfunction responseItems(message: ModelMessage, context: ProtocolContext) {\n return message.content\n .filter((block) => replayable(block, context.identity, context.model))\n .toSorted((left, right) => order(message, left) - order(message, right))\n .map((block) => itemEncoders[block.type](block as never, message.role));\n}\n\nfunction order(message: ModelMessage, block: ModelContentBlock): number {\n return message.role === \"user\" && block.type !== \"tool-result\" ? 1 : 0;\n}\n\nconst itemEncoders: BlockEncoders<[role: ModelMessage[\"role\"]]> = {\n text: (block, role) => ({ role, content: block.text }),\n \"tool-call\": (block) => ({\n type: \"function_call\",\n call_id: block.id,\n name: block.name,\n arguments: toolArguments(block.input),\n }),\n \"tool-result\": (block) => ({\n type: \"function_call_output\",\n call_id: block.callId,\n output: block.content,\n }),\n reasoning: (block) => block.data,\n};\n"]}
@@ -0,0 +1 @@
1
+ export declare function retryAfterMs(value: string | null, now?: number): number | undefined;
@@ -0,0 +1,16 @@
1
+ export function retryAfterMs(value, now = Date.now()) {
2
+ if (value === null)
3
+ return undefined;
4
+ const text = value.trim();
5
+ if (/^\d+$/.test(text)) {
6
+ const duration = Number(text) * 1000;
7
+ return Number.isSafeInteger(duration) ? duration : undefined;
8
+ }
9
+ if (!/^(?:[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT|[A-Za-z]+, \d{2}-[A-Za-z]{3}-\d{2} \d{2}:\d{2}:\d{2} GMT|[A-Za-z]{3} [A-Za-z]{3} [ \d]\d \d{2}:\d{2}:\d{2} \d{4})$/.test(text))
10
+ return undefined;
11
+ const date = Date.parse(text.endsWith("GMT") ? text : `${text} GMT`);
12
+ if (!Number.isFinite(date))
13
+ return undefined;
14
+ return Math.max(0, date - now);
15
+ }
16
+ //# sourceMappingURL=retry-after.js.map