@elie-laloum/outpost 5.0.0 → 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 (647) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +11 -11
  3. package/SECURITY.md +10 -0
  4. package/dist/adapters/agents/antigravity-adapter.d.ts +3 -0
  5. package/dist/adapters/agents/antigravity-adapter.js +41 -0
  6. package/dist/adapters/agents/antigravity-adapter.js.map +1 -0
  7. package/dist/adapters/agents/antigravity-authentication.d.ts +2 -0
  8. package/dist/adapters/agents/antigravity-authentication.js +27 -0
  9. package/dist/adapters/agents/antigravity-authentication.js.map +1 -0
  10. package/dist/adapters/agents/antigravity-diagnostics.d.ts +1 -0
  11. package/dist/adapters/agents/antigravity-diagnostics.js +6 -0
  12. package/dist/adapters/agents/antigravity-diagnostics.js.map +1 -0
  13. package/dist/adapters/agents/antigravity-events.d.ts +2 -0
  14. package/dist/adapters/agents/antigravity-events.js +75 -0
  15. package/dist/adapters/agents/antigravity-events.js.map +1 -0
  16. package/dist/adapters/agents/antigravity-request.d.ts +5 -0
  17. package/dist/adapters/agents/antigravity-request.js +37 -0
  18. package/dist/adapters/agents/antigravity-request.js.map +1 -0
  19. package/dist/adapters/agents/antigravity.constants.d.ts +3 -0
  20. package/dist/adapters/agents/antigravity.constants.js +4 -0
  21. package/dist/adapters/agents/antigravity.constants.js.map +1 -0
  22. package/dist/adapters/agents/{gemini.types.d.ts → antigravity.types.d.ts} +2 -2
  23. package/dist/adapters/agents/antigravity.types.js +2 -0
  24. package/dist/adapters/agents/antigravity.types.js.map +1 -0
  25. package/dist/adapters/agents/authentication.constants.d.ts +19 -9
  26. package/dist/adapters/agents/authentication.constants.js +12 -9
  27. package/dist/adapters/agents/authentication.constants.js.map +1 -1
  28. package/dist/adapters/agents/authentication.d.ts +11 -2
  29. package/dist/adapters/agents/authentication.js +70 -47
  30. package/dist/adapters/agents/authentication.js.map +1 -1
  31. package/dist/adapters/agents/authentication.types.d.ts +20 -0
  32. package/dist/adapters/agents/authentication.types.js +2 -0
  33. package/dist/adapters/agents/authentication.types.js.map +1 -0
  34. package/dist/adapters/agents/claude-adapter.js +4 -2
  35. package/dist/adapters/agents/claude-adapter.js.map +1 -1
  36. package/dist/adapters/agents/claude-authentication.d.ts +2 -0
  37. package/dist/adapters/agents/claude-authentication.js +34 -0
  38. package/dist/adapters/agents/claude-authentication.js.map +1 -0
  39. package/dist/adapters/agents/claude-events.js +52 -9
  40. package/dist/adapters/agents/claude-events.js.map +1 -1
  41. package/dist/adapters/agents/claude-request.js +2 -0
  42. package/dist/adapters/agents/claude-request.js.map +1 -1
  43. package/dist/adapters/agents/cli-diagnostics.constants.d.ts +6 -6
  44. package/dist/adapters/agents/cli-diagnostics.constants.js +6 -6
  45. package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -1
  46. package/dist/adapters/agents/cli-diagnostics.d.ts +1 -0
  47. package/dist/adapters/agents/cli-diagnostics.js +18 -0
  48. package/dist/adapters/agents/cli-diagnostics.js.map +1 -1
  49. package/dist/adapters/agents/codex-adapter.js +4 -2
  50. package/dist/adapters/agents/codex-adapter.js.map +1 -1
  51. package/dist/adapters/agents/codex-authentication.d.ts +3 -0
  52. package/dist/adapters/agents/codex-authentication.js +47 -0
  53. package/dist/adapters/agents/codex-authentication.js.map +1 -0
  54. package/dist/adapters/agents/codex-events.js +28 -2
  55. package/dist/adapters/agents/codex-events.js.map +1 -1
  56. package/dist/adapters/agents/copilot-adapter.d.ts +3 -0
  57. package/dist/adapters/agents/copilot-adapter.js +45 -0
  58. package/dist/adapters/agents/copilot-adapter.js.map +1 -0
  59. package/dist/adapters/agents/copilot-authentication.d.ts +2 -0
  60. package/dist/adapters/agents/copilot-authentication.js +46 -0
  61. package/dist/adapters/agents/copilot-authentication.js.map +1 -0
  62. package/dist/adapters/agents/copilot-diagnostics.d.ts +1 -0
  63. package/dist/adapters/agents/copilot-diagnostics.js +6 -0
  64. package/dist/adapters/agents/copilot-diagnostics.js.map +1 -0
  65. package/dist/adapters/agents/copilot-events.d.ts +2 -0
  66. package/dist/adapters/agents/copilot-events.js +66 -0
  67. package/dist/adapters/agents/copilot-events.js.map +1 -0
  68. package/dist/adapters/agents/copilot-request.d.ts +5 -0
  69. package/dist/adapters/agents/copilot-request.js +24 -0
  70. package/dist/adapters/agents/copilot-request.js.map +1 -0
  71. package/dist/adapters/agents/copilot-usage.d.ts +3 -0
  72. package/dist/adapters/agents/copilot-usage.js +19 -0
  73. package/dist/adapters/agents/copilot-usage.js.map +1 -0
  74. package/dist/adapters/agents/copilot.types.d.ts +6 -0
  75. package/dist/adapters/agents/copilot.types.js +2 -0
  76. package/dist/adapters/agents/copilot.types.js.map +1 -0
  77. package/dist/adapters/agents/event-decoder.d.ts +2 -2
  78. package/dist/adapters/agents/event-decoder.js +6 -5
  79. package/dist/adapters/agents/event-decoder.js.map +1 -1
  80. package/dist/adapters/agents/kimi-adapter.d.ts +3 -0
  81. package/dist/adapters/agents/kimi-adapter.js +51 -0
  82. package/dist/adapters/agents/kimi-adapter.js.map +1 -0
  83. package/dist/adapters/agents/kimi-authentication.d.ts +3 -0
  84. package/dist/adapters/agents/kimi-authentication.js +63 -0
  85. package/dist/adapters/agents/kimi-authentication.js.map +1 -0
  86. package/dist/adapters/agents/kimi-diagnostics.d.ts +2 -0
  87. package/dist/adapters/agents/kimi-diagnostics.js +14 -0
  88. package/dist/adapters/agents/kimi-diagnostics.js.map +1 -0
  89. package/dist/adapters/agents/kimi-events.d.ts +2 -0
  90. package/dist/adapters/agents/kimi-events.js +55 -0
  91. package/dist/adapters/agents/kimi-events.js.map +1 -0
  92. package/dist/adapters/agents/kimi-fork.d.ts +2 -0
  93. package/dist/adapters/agents/kimi-fork.js +11 -0
  94. package/dist/adapters/agents/kimi-fork.js.map +1 -0
  95. package/dist/adapters/agents/{gemini-request.d.ts → kimi-request.d.ts} +2 -2
  96. package/dist/adapters/agents/kimi-request.js +33 -0
  97. package/dist/adapters/agents/kimi-request.js.map +1 -0
  98. package/dist/adapters/agents/kimi-usage.d.ts +2 -0
  99. package/dist/adapters/agents/kimi-usage.js +7 -0
  100. package/dist/adapters/agents/kimi-usage.js.map +1 -0
  101. package/dist/adapters/agents/kimi.constants.d.ts +13 -0
  102. package/dist/adapters/agents/kimi.constants.js +14 -0
  103. package/dist/adapters/agents/kimi.constants.js.map +1 -0
  104. package/dist/adapters/agents/kimi.types.d.ts +7 -0
  105. package/dist/adapters/agents/kimi.types.js +2 -0
  106. package/dist/adapters/agents/kimi.types.js.map +1 -0
  107. package/dist/adapters/agents/model-support.constants.d.ts +3 -1
  108. package/dist/adapters/agents/model-support.constants.js +12 -2
  109. package/dist/adapters/agents/model-support.constants.js.map +1 -1
  110. package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -2
  111. package/dist/adapters/agents/protocol-fixtures.constants.js +131 -9
  112. package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -1
  113. package/dist/adapters/agents/protocol-fixtures.types.d.ts +1 -0
  114. package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -1
  115. package/dist/adapters/agents/protocol.d.ts +1 -0
  116. package/dist/adapters/agents/protocol.js +9 -0
  117. package/dist/adapters/agents/protocol.js.map +1 -1
  118. package/dist/adapters/agents/session-usage.constants.d.ts +10 -0
  119. package/dist/adapters/agents/session-usage.constants.js +110 -0
  120. package/dist/adapters/agents/session-usage.constants.js.map +1 -0
  121. package/dist/adapters/agents/session-usage.d.ts +5 -0
  122. package/dist/adapters/agents/session-usage.js +45 -0
  123. package/dist/adapters/agents/session-usage.js.map +1 -0
  124. package/dist/adapters/agents/settings.types.d.ts +1 -0
  125. package/dist/adapters/agents/settings.types.js.map +1 -1
  126. package/dist/adapters/agents/tool-result.d.ts +2 -0
  127. package/dist/adapters/agents/tool-result.js +17 -0
  128. package/dist/adapters/agents/tool-result.js.map +1 -0
  129. package/dist/adapters/models/anthropic-response.js +3 -0
  130. package/dist/adapters/models/anthropic-response.js.map +1 -1
  131. package/dist/adapters/models/http-provider.js +6 -1
  132. package/dist/adapters/models/http-provider.js.map +1 -1
  133. package/dist/adapters/models/openai-responses.js +10 -0
  134. package/dist/adapters/models/openai-responses.js.map +1 -1
  135. package/dist/adapters/models/retry-after.d.ts +1 -0
  136. package/dist/adapters/models/retry-after.js +16 -0
  137. package/dist/adapters/models/retry-after.js.map +1 -0
  138. package/dist/application/activity-watchdog.js +1 -2
  139. package/dist/application/activity-watchdog.js.map +1 -1
  140. package/dist/application/agent-authentication.d.ts +4 -0
  141. package/dist/application/agent-authentication.js +32 -0
  142. package/dist/application/agent-authentication.js.map +1 -0
  143. package/dist/application/agent-bootstrap.constants.d.ts +2 -5
  144. package/dist/application/agent-bootstrap.constants.js +27 -4
  145. package/dist/application/agent-bootstrap.constants.js.map +1 -1
  146. package/dist/application/agent-bootstrap.js +39 -12
  147. package/dist/application/agent-bootstrap.js.map +1 -1
  148. package/dist/application/agent-bootstrap.types.d.ts +19 -0
  149. package/dist/application/agent-bootstrap.types.js +2 -0
  150. package/dist/application/agent-bootstrap.types.js.map +1 -0
  151. package/dist/application/agent-output.js +74 -8
  152. package/dist/application/agent-output.js.map +1 -1
  153. package/dist/application/agent-request.d.ts +3 -0
  154. package/dist/application/agent-request.js +11 -0
  155. package/dist/application/agent-request.js.map +1 -0
  156. package/dist/application/agent-turn.js +74 -6
  157. package/dist/application/agent-turn.js.map +1 -1
  158. package/dist/application/agent-usage.d.ts +6 -0
  159. package/dist/application/agent-usage.js +57 -0
  160. package/dist/application/agent-usage.js.map +1 -0
  161. package/dist/application/attach.js +2 -0
  162. package/dist/application/attach.js.map +1 -1
  163. package/dist/application/credential-installer.constants.d.ts +1 -0
  164. package/dist/application/credential-installer.constants.js +22 -0
  165. package/dist/application/credential-installer.constants.js.map +1 -0
  166. package/dist/application/custom-turn.js +44 -49
  167. package/dist/application/custom-turn.js.map +1 -1
  168. package/dist/application/dispatch-observation.d.ts +1 -1
  169. package/dist/application/dispatch-observation.js +141 -21
  170. package/dist/application/dispatch-observation.js.map +1 -1
  171. package/dist/application/dispatch-observation.types.d.ts +2 -0
  172. package/dist/application/dispatch-observation.types.js.map +1 -1
  173. package/dist/application/dispatch-validation.js +2 -0
  174. package/dist/application/dispatch-validation.js.map +1 -1
  175. package/dist/application/dispatch.js +1 -1
  176. package/dist/application/dispatch.js.map +1 -1
  177. package/dist/application/doctor-agent.constants.d.ts +2 -8
  178. package/dist/application/doctor-agent.constants.js +43 -6
  179. package/dist/application/doctor-agent.constants.js.map +1 -1
  180. package/dist/application/doctor-agent.d.ts +2 -1
  181. package/dist/application/doctor-agent.js +15 -3
  182. package/dist/application/doctor-agent.js.map +1 -1
  183. package/dist/application/doctor-image.js +4 -6
  184. package/dist/application/doctor-image.js.map +1 -1
  185. package/dist/application/doctor-protocol.js +6 -11
  186. package/dist/application/doctor-protocol.js.map +1 -1
  187. package/dist/application/doctor-protocol.types.d.ts +1 -1
  188. package/dist/application/doctor-protocol.types.js.map +1 -1
  189. package/dist/application/doctor-sandbox.js +2 -5
  190. package/dist/application/doctor-sandbox.js.map +1 -1
  191. package/dist/application/doctor.js +28 -10
  192. package/dist/application/doctor.js.map +1 -1
  193. package/dist/application/doctor.types.d.ts +10 -1
  194. package/dist/application/doctor.types.js.map +1 -1
  195. package/dist/application/execution.constants.d.ts +2 -0
  196. package/dist/application/execution.constants.js +2 -0
  197. package/dist/application/execution.constants.js.map +1 -1
  198. package/dist/application/execution.types.d.ts +8 -0
  199. package/dist/application/execution.types.js.map +1 -1
  200. package/dist/application/harness-budget.d.ts +3 -0
  201. package/dist/application/harness-budget.js +42 -0
  202. package/dist/application/harness-budget.js.map +1 -0
  203. package/dist/application/harness-budget.types.d.ts +5 -0
  204. package/dist/application/harness-budget.types.js +2 -0
  205. package/dist/application/harness-budget.types.js.map +1 -0
  206. package/dist/application/harness-hooks.js +34 -3
  207. package/dist/application/harness-hooks.js.map +1 -1
  208. package/dist/application/harness-loop.js +52 -24
  209. package/dist/application/harness-loop.js.map +1 -1
  210. package/dist/application/harness-model-provider.d.ts +3 -0
  211. package/dist/application/harness-model-provider.js +49 -0
  212. package/dist/application/harness-model-provider.js.map +1 -0
  213. package/dist/application/harness-model-provider.types.d.ts +10 -0
  214. package/dist/application/harness-model-provider.types.js +2 -0
  215. package/dist/application/harness-model-provider.types.js.map +1 -0
  216. package/dist/application/harness-subagent.d.ts +4 -0
  217. package/dist/application/harness-subagent.js +110 -0
  218. package/dist/application/harness-subagent.js.map +1 -0
  219. package/dist/application/harness.types.d.ts +11 -0
  220. package/dist/application/harness.types.js.map +1 -1
  221. package/dist/application/lifecycle-hooks.d.ts +1 -1
  222. package/dist/application/lifecycle-hooks.js +5 -4
  223. package/dist/application/lifecycle-hooks.js.map +1 -1
  224. package/dist/application/observed-lease.d.ts +3 -0
  225. package/dist/application/observed-lease.js +26 -0
  226. package/dist/application/observed-lease.js.map +1 -0
  227. package/dist/application/outpost.types.d.ts +3 -1
  228. package/dist/application/outpost.types.js.map +1 -1
  229. package/dist/application/output-lines.d.ts +4 -0
  230. package/dist/application/output-lines.js +28 -0
  231. package/dist/application/output-lines.js.map +1 -0
  232. package/dist/application/queue-worker.js +1 -1
  233. package/dist/application/queue-worker.js.map +1 -1
  234. package/dist/application/queue-worker.types.d.ts +1 -0
  235. package/dist/application/queue-worker.types.js.map +1 -1
  236. package/dist/application/queued-task.js +24 -5
  237. package/dist/application/queued-task.js.map +1 -1
  238. package/dist/application/recovery-archive.d.ts +3 -2
  239. package/dist/application/recovery-archive.js +9 -2
  240. package/dist/application/recovery-archive.js.map +1 -1
  241. package/dist/application/recovery-restore.d.ts +3 -2
  242. package/dist/application/recovery-restore.js +9 -2
  243. package/dist/application/recovery-restore.js.map +1 -1
  244. package/dist/application/recovery-retention.d.ts +3 -2
  245. package/dist/application/recovery-retention.js +74 -26
  246. package/dist/application/recovery-retention.js.map +1 -1
  247. package/dist/application/remote-workspace.js +5 -4
  248. package/dist/application/remote-workspace.js.map +1 -1
  249. package/dist/application/remote-workspace.types.d.ts +1 -0
  250. package/dist/application/remote-workspace.types.js.map +1 -1
  251. package/dist/application/sandbox-agents.js +19 -19
  252. package/dist/application/sandbox-agents.js.map +1 -1
  253. package/dist/application/sandbox-attach.js +12 -3
  254. package/dist/application/sandbox-attach.js.map +1 -1
  255. package/dist/application/sandbox-dispatch.js +13 -27
  256. package/dist/application/sandbox-dispatch.js.map +1 -1
  257. package/dist/application/sandbox-provision.js +15 -9
  258. package/dist/application/sandbox-provision.js.map +1 -1
  259. package/dist/application/sandbox-session.types.d.ts +7 -2
  260. package/dist/application/sandbox-session.types.js.map +1 -1
  261. package/dist/application/sandbox.js +13 -6
  262. package/dist/application/sandbox.js.map +1 -1
  263. package/dist/application/speculation-checkpoint.d.ts +6 -0
  264. package/dist/application/speculation-checkpoint.js +206 -0
  265. package/dist/application/speculation-checkpoint.js.map +1 -0
  266. package/dist/application/speculation-checkpoint.types.d.ts +24 -0
  267. package/dist/application/speculation-checkpoint.types.js +2 -0
  268. package/dist/application/speculation-checkpoint.types.js.map +1 -0
  269. package/dist/application/speculation-integration.constants.d.ts +4 -0
  270. package/dist/application/speculation-integration.constants.js +5 -0
  271. package/dist/application/speculation-integration.constants.js.map +1 -0
  272. package/dist/application/speculation-integration.d.ts +2 -0
  273. package/dist/application/speculation-integration.js +67 -0
  274. package/dist/application/speculation-integration.js.map +1 -0
  275. package/dist/application/speculation-resume.d.ts +4 -0
  276. package/dist/application/speculation-resume.js +71 -0
  277. package/dist/application/speculation-resume.js.map +1 -0
  278. package/dist/application/speculation-run.d.ts +4 -0
  279. package/dist/application/speculation-run.js +320 -0
  280. package/dist/application/speculation-run.js.map +1 -0
  281. package/dist/application/speculation-timeout.d.ts +1 -0
  282. package/dist/application/speculation-timeout.js +15 -0
  283. package/dist/application/speculation-timeout.js.map +1 -0
  284. package/dist/application/speculation.constants.d.ts +1 -0
  285. package/dist/application/speculation.constants.js +5 -1
  286. package/dist/application/speculation.constants.js.map +1 -1
  287. package/dist/application/speculation.js +41 -149
  288. package/dist/application/speculation.js.map +1 -1
  289. package/dist/application/speculation.types.d.ts +23 -0
  290. package/dist/application/speculation.types.js.map +1 -1
  291. package/dist/application/startup-recovery.js +14 -1
  292. package/dist/application/startup-recovery.js.map +1 -1
  293. package/dist/application/startup-recovery.types.d.ts +1 -0
  294. package/dist/application/startup-recovery.types.js.map +1 -1
  295. package/dist/application/stop-reason.d.ts +2 -0
  296. package/dist/application/stop-reason.js +21 -0
  297. package/dist/application/stop-reason.js.map +1 -0
  298. package/dist/application/stop-reason.types.d.ts +4 -0
  299. package/dist/application/stop-reason.types.js +2 -0
  300. package/dist/application/stop-reason.types.js.map +1 -0
  301. package/dist/application/storage-reservation.js +9 -2
  302. package/dist/application/storage-reservation.js.map +1 -1
  303. package/dist/application/task-observation.d.ts +3 -0
  304. package/dist/application/task-observation.js +22 -0
  305. package/dist/application/task-observation.js.map +1 -0
  306. package/dist/application/task-usage.js +5 -12
  307. package/dist/application/task-usage.js.map +1 -1
  308. package/dist/application/tasks.js +41 -16
  309. package/dist/application/tasks.js.map +1 -1
  310. package/dist/application/tool-execution.js +42 -19
  311. package/dist/application/tool-execution.js.map +1 -1
  312. package/dist/application/workspace.js +6 -4
  313. package/dist/application/workspace.js.map +1 -1
  314. package/dist/cli/doctor-command.js +6 -2
  315. package/dist/cli/doctor-command.js.map +1 -1
  316. package/dist/cli/init-authentication.d.ts +4 -1
  317. package/dist/cli/init-authentication.js +28 -33
  318. package/dist/cli/init-authentication.js.map +1 -1
  319. package/dist/cli/init-command.js +3 -3
  320. package/dist/cli/init-command.js.map +1 -1
  321. package/dist/cli/main.constants.d.ts +50 -13
  322. package/dist/cli/main.constants.js +70 -8
  323. package/dist/cli/main.constants.js.map +1 -1
  324. package/dist/cli/main.js +2 -1
  325. package/dist/cli/main.js.map +1 -1
  326. package/dist/cli/scaffold-files.js +1 -1
  327. package/dist/cli/scaffold-files.js.map +1 -1
  328. package/dist/cli/scaffold-validation.js +29 -22
  329. package/dist/cli/scaffold-validation.js.map +1 -1
  330. package/dist/cli/scaffold.constants.d.ts +0 -1
  331. package/dist/cli/scaffold.constants.js +6 -2
  332. package/dist/cli/scaffold.constants.js.map +1 -1
  333. package/dist/cli/scaffold.types.d.ts +8 -2
  334. package/dist/cli/scaffold.types.js.map +1 -1
  335. package/dist/cli/starters.js +1 -3
  336. package/dist/cli/starters.js.map +1 -1
  337. package/dist/domain/agent-observation.d.ts +4 -0
  338. package/dist/domain/agent-observation.js +27 -0
  339. package/dist/domain/agent-observation.js.map +1 -0
  340. package/dist/domain/agent.types.d.ts +122 -14
  341. package/dist/domain/agent.types.js.map +1 -1
  342. package/dist/domain/authentication.constants.d.ts +3 -0
  343. package/dist/domain/authentication.constants.js +11 -0
  344. package/dist/domain/authentication.constants.js.map +1 -0
  345. package/dist/domain/authentication.d.ts +3 -0
  346. package/dist/domain/authentication.js +22 -0
  347. package/dist/domain/authentication.js.map +1 -0
  348. package/dist/domain/authentication.types.d.ts +5 -0
  349. package/dist/domain/authentication.types.js +2 -0
  350. package/dist/domain/authentication.types.js.map +1 -0
  351. package/dist/domain/harness.d.ts +2 -2
  352. package/dist/domain/harness.js +6 -0
  353. package/dist/domain/harness.js.map +1 -1
  354. package/dist/domain/harness.types.d.ts +4 -3
  355. package/dist/domain/harness.types.js.map +1 -1
  356. package/dist/domain/model.types.d.ts +8 -0
  357. package/dist/domain/model.types.js.map +1 -1
  358. package/dist/domain/observation.constants.d.ts +8 -0
  359. package/dist/domain/observation.constants.js +9 -0
  360. package/dist/domain/observation.constants.js.map +1 -0
  361. package/dist/domain/observation.d.ts +2 -0
  362. package/dist/domain/observation.js +190 -0
  363. package/dist/domain/observation.js.map +1 -0
  364. package/dist/domain/observation.types.d.ts +84 -0
  365. package/dist/domain/observation.types.js +2 -0
  366. package/dist/domain/observation.types.js.map +1 -0
  367. package/dist/domain/observed-operation.d.ts +2 -0
  368. package/dist/domain/observed-operation.js +30 -0
  369. package/dist/domain/observed-operation.js.map +1 -0
  370. package/dist/domain/sandbox.types.d.ts +2 -0
  371. package/dist/domain/sandbox.types.js.map +1 -1
  372. package/dist/domain/subagent.constants.d.ts +13 -0
  373. package/dist/domain/subagent.constants.js +9 -0
  374. package/dist/domain/subagent.constants.js.map +1 -0
  375. package/dist/domain/subagent.d.ts +4 -0
  376. package/dist/domain/subagent.js +28 -0
  377. package/dist/domain/subagent.js.map +1 -0
  378. package/dist/domain/subagent.types.d.ts +13 -0
  379. package/dist/domain/subagent.types.js +2 -0
  380. package/dist/domain/subagent.types.js.map +1 -0
  381. package/dist/domain/transcript.types.d.ts +2 -0
  382. package/dist/domain/transcript.types.js.map +1 -1
  383. package/dist/domain/usage.d.ts +1 -0
  384. package/dist/domain/usage.js +16 -0
  385. package/dist/domain/usage.js.map +1 -1
  386. package/dist/domain/workflow/budget.d.ts +7 -3
  387. package/dist/domain/workflow/budget.js +26 -0
  388. package/dist/domain/workflow/budget.js.map +1 -1
  389. package/dist/domain/workflow/budget.types.d.ts +1 -1
  390. package/dist/domain/workflow/budget.types.js.map +1 -1
  391. package/dist/domain/workflow/checkpoint-validation.js +7 -1
  392. package/dist/domain/workflow/checkpoint-validation.js.map +1 -1
  393. package/dist/domain/workflow/checkpoint.js +3 -0
  394. package/dist/domain/workflow/checkpoint.js.map +1 -1
  395. package/dist/domain/workflow/gate-validation.js +14 -1
  396. package/dist/domain/workflow/gate-validation.js.map +1 -1
  397. package/dist/domain/workflow/gates.d.ts +1 -1
  398. package/dist/domain/workflow/gates.js +52 -4
  399. package/dist/domain/workflow/gates.js.map +1 -1
  400. package/dist/domain/workflow/gates.types.d.ts +15 -1
  401. package/dist/domain/workflow/gates.types.js.map +1 -1
  402. package/dist/domain/workflow/idempotency.d.ts +1 -0
  403. package/dist/domain/workflow/idempotency.js +7 -0
  404. package/dist/domain/workflow/idempotency.js.map +1 -0
  405. package/dist/domain/workflow/retry.constants.d.ts +2 -0
  406. package/dist/domain/workflow/retry.constants.js +3 -0
  407. package/dist/domain/workflow/retry.constants.js.map +1 -0
  408. package/dist/domain/workflow/retry.d.ts +4 -0
  409. package/dist/domain/workflow/retry.js +49 -0
  410. package/dist/domain/workflow/retry.js.map +1 -0
  411. package/dist/domain/workflow/task-runner.js +9 -5
  412. package/dist/domain/workflow/task-runner.js.map +1 -1
  413. package/dist/domain/workflow/task.js +6 -6
  414. package/dist/domain/workflow/task.js.map +1 -1
  415. package/dist/domain/workflow/workflow-scheduler.js +110 -72
  416. package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
  417. package/dist/domain/workflow/workflow-state.js +28 -12
  418. package/dist/domain/workflow/workflow-state.js.map +1 -1
  419. package/dist/domain/workflow.d.ts +1 -1
  420. package/dist/domain/workflow.js +1 -1
  421. package/dist/domain/workflow.js.map +1 -1
  422. package/dist/domain/workflow.types.d.ts +13 -2
  423. package/dist/domain/workflow.types.js.map +1 -1
  424. package/dist/index.d.ts +16 -11
  425. package/dist/index.js +7 -4
  426. package/dist/index.js.map +1 -1
  427. package/dist/infrastructure/conversations/capture.js +10 -0
  428. package/dist/infrastructure/conversations/capture.js.map +1 -1
  429. package/dist/infrastructure/conversations/harness-transcript.js +6 -0
  430. package/dist/infrastructure/conversations/harness-transcript.js.map +1 -1
  431. package/dist/infrastructure/conversations/harness-transcript.types.d.ts +2 -0
  432. package/dist/infrastructure/conversations/harness-transcript.types.js.map +1 -1
  433. package/dist/infrastructure/conversations/layout.js +2 -0
  434. package/dist/infrastructure/conversations/layout.js.map +1 -1
  435. package/dist/infrastructure/conversations/locate.js +7 -1
  436. package/dist/infrastructure/conversations/locate.js.map +1 -1
  437. package/dist/infrastructure/conversations/native-store.js +8 -1
  438. package/dist/infrastructure/conversations/native-store.js.map +1 -1
  439. package/dist/infrastructure/conversations/paths.js +3 -0
  440. package/dist/infrastructure/conversations/paths.js.map +1 -1
  441. package/dist/infrastructure/conversations/restore.js +7 -0
  442. package/dist/infrastructure/conversations/restore.js.map +1 -1
  443. package/dist/infrastructure/conversations/session-bundle.constants.d.ts +5 -0
  444. package/dist/infrastructure/conversations/session-bundle.constants.js +173 -0
  445. package/dist/infrastructure/conversations/session-bundle.constants.js.map +1 -0
  446. package/dist/infrastructure/conversations/session-bundle.d.ts +6 -0
  447. package/dist/infrastructure/conversations/session-bundle.js +98 -0
  448. package/dist/infrastructure/conversations/session-bundle.js.map +1 -0
  449. package/dist/infrastructure/conversations/session-bundle.types.d.ts +1 -0
  450. package/dist/infrastructure/conversations/session-bundle.types.js +2 -0
  451. package/dist/infrastructure/conversations/session-bundle.types.js.map +1 -0
  452. package/dist/infrastructure/conversations.js +4 -2
  453. package/dist/infrastructure/conversations.js.map +1 -1
  454. package/dist/infrastructure/conversations.types.d.ts +1 -1
  455. package/dist/infrastructure/conversations.types.js.map +1 -1
  456. package/dist/infrastructure/custom-reporter.js +32 -24
  457. package/dist/infrastructure/custom-reporter.js.map +1 -1
  458. package/dist/infrastructure/custom-reporter.types.d.ts +2 -0
  459. package/dist/infrastructure/custom-reporter.types.js.map +1 -1
  460. package/dist/infrastructure/git/git.constants.d.ts +1 -1
  461. package/dist/infrastructure/git/git.constants.js +1 -0
  462. package/dist/infrastructure/git/git.constants.js.map +1 -1
  463. package/dist/infrastructure/git/workspace-lease.js +4 -3
  464. package/dist/infrastructure/git/workspace-lease.js.map +1 -1
  465. package/dist/infrastructure/git/workspace.js +7 -6
  466. package/dist/infrastructure/git/workspace.js.map +1 -1
  467. package/dist/infrastructure/git/workspace.types.d.ts +1 -0
  468. package/dist/infrastructure/git/workspace.types.js.map +1 -1
  469. package/dist/infrastructure/host-credentials.constants.d.ts +1 -0
  470. package/dist/infrastructure/host-credentials.constants.js +2 -0
  471. package/dist/infrastructure/host-credentials.constants.js.map +1 -0
  472. package/dist/infrastructure/host-credentials.d.ts +4 -0
  473. package/dist/infrastructure/host-credentials.js +89 -0
  474. package/dist/infrastructure/host-credentials.js.map +1 -0
  475. package/dist/infrastructure/inspection-path.js +4 -3
  476. package/dist/infrastructure/inspection-path.js.map +1 -1
  477. package/dist/infrastructure/journal.constants.js +10 -1
  478. package/dist/infrastructure/journal.constants.js.map +1 -1
  479. package/dist/infrastructure/journal.d.ts +1 -1
  480. package/dist/infrastructure/journal.js +8 -75
  481. package/dist/infrastructure/journal.js.map +1 -1
  482. package/dist/infrastructure/journal.types.d.ts +2 -4
  483. package/dist/infrastructure/journal.types.js.map +1 -1
  484. package/dist/infrastructure/local-transport.js +9 -4
  485. package/dist/infrastructure/local-transport.js.map +1 -1
  486. package/dist/infrastructure/opentelemetry-dispatch.d.ts +3 -3
  487. package/dist/infrastructure/opentelemetry-dispatch.js +5 -4
  488. package/dist/infrastructure/opentelemetry-dispatch.js.map +1 -1
  489. package/dist/infrastructure/opentelemetry-observation.d.ts +5 -0
  490. package/dist/infrastructure/opentelemetry-observation.js +59 -0
  491. package/dist/infrastructure/opentelemetry-observation.js.map +1 -0
  492. package/dist/infrastructure/opentelemetry.js +15 -1
  493. package/dist/infrastructure/opentelemetry.js.map +1 -1
  494. package/dist/infrastructure/opentelemetry.types.d.ts +9 -1
  495. package/dist/infrastructure/opentelemetry.types.js.map +1 -1
  496. package/dist/infrastructure/reporter.d.ts +2 -2
  497. package/dist/infrastructure/reporter.js +5 -1
  498. package/dist/infrastructure/reporter.js.map +1 -1
  499. package/dist/infrastructure/repository-transport.constants.d.ts +1 -0
  500. package/dist/infrastructure/repository-transport.constants.js +2 -0
  501. package/dist/infrastructure/repository-transport.constants.js.map +1 -0
  502. package/dist/infrastructure/repository-transport.d.ts +2 -0
  503. package/dist/infrastructure/repository-transport.js +9 -0
  504. package/dist/infrastructure/repository-transport.js.map +1 -0
  505. package/dist/infrastructure/resource-activity-inspection.js +19 -24
  506. package/dist/infrastructure/resource-activity-inspection.js.map +1 -1
  507. package/dist/infrastructure/resource-activity.constants.d.ts +0 -1
  508. package/dist/infrastructure/resource-activity.constants.js +0 -1
  509. package/dist/infrastructure/resource-activity.constants.js.map +1 -1
  510. package/dist/infrastructure/resource-activity.js +20 -83
  511. package/dist/infrastructure/resource-activity.js.map +1 -1
  512. package/dist/infrastructure/s3-transport.constants.d.ts +2 -0
  513. package/dist/infrastructure/s3-transport.constants.js +3 -0
  514. package/dist/infrastructure/s3-transport.constants.js.map +1 -0
  515. package/dist/infrastructure/s3-transport.js +57 -3
  516. package/dist/infrastructure/s3-transport.js.map +1 -1
  517. package/dist/infrastructure/s3-transport.types.d.ts +1 -0
  518. package/dist/infrastructure/s3-transport.types.js.map +1 -1
  519. package/dist/infrastructure/speculation-store.constants.d.ts +3 -0
  520. package/dist/infrastructure/speculation-store.constants.js +2 -0
  521. package/dist/infrastructure/speculation-store.constants.js.map +1 -0
  522. package/dist/infrastructure/speculation-store.d.ts +4 -0
  523. package/dist/infrastructure/speculation-store.js +73 -0
  524. package/dist/infrastructure/speculation-store.js.map +1 -0
  525. package/dist/infrastructure/speculation-store.types.d.ts +12 -0
  526. package/dist/infrastructure/speculation-store.types.js +2 -0
  527. package/dist/infrastructure/speculation-store.types.js.map +1 -0
  528. package/dist/infrastructure/storage-inventory.constants.js +1 -0
  529. package/dist/infrastructure/storage-inventory.constants.js.map +1 -1
  530. package/dist/infrastructure/storage-inventory.types.d.ts +1 -1
  531. package/dist/infrastructure/storage-inventory.types.js.map +1 -1
  532. package/dist/infrastructure/storage-reservations.types.d.ts +0 -8
  533. package/dist/infrastructure/storage-reservations.types.js.map +1 -1
  534. package/dist/infrastructure/task-queue-bullmq-resources.js +3 -0
  535. package/dist/infrastructure/task-queue-bullmq-resources.js.map +1 -1
  536. package/dist/infrastructure/task-queue-http.js +29 -4
  537. package/dist/infrastructure/task-queue-http.js.map +1 -1
  538. package/dist/infrastructure/task-queue-http.types.d.ts +2 -2
  539. package/dist/infrastructure/task-queue-http.types.js.map +1 -1
  540. package/dist/infrastructure/transport-conversations.js +2 -0
  541. package/dist/infrastructure/transport-conversations.js.map +1 -1
  542. package/dist/infrastructure/transport-journal.d.ts +1 -1
  543. package/dist/infrastructure/transport-journal.js +8 -2
  544. package/dist/infrastructure/transport-journal.js.map +1 -1
  545. package/dist/infrastructure/transport-reservations.d.ts +1 -1
  546. package/dist/infrastructure/transport-reservations.js +14 -8
  547. package/dist/infrastructure/transport-reservations.js.map +1 -1
  548. package/dist/infrastructure/workflow-decision-signature.constants.d.ts +4 -0
  549. package/dist/infrastructure/workflow-decision-signature.constants.js +5 -0
  550. package/dist/infrastructure/workflow-decision-signature.constants.js.map +1 -0
  551. package/dist/infrastructure/workflow-decision-signature.d.ts +4 -0
  552. package/dist/infrastructure/workflow-decision-signature.js +83 -0
  553. package/dist/infrastructure/workflow-decision-signature.js.map +1 -0
  554. package/dist/infrastructure/workflow-decision-signature.types.d.ts +16 -0
  555. package/dist/infrastructure/workflow-decision-signature.types.js +2 -0
  556. package/dist/infrastructure/workflow-decision-signature.types.js.map +1 -0
  557. package/dist/providers/agents.d.ts +7 -2
  558. package/dist/providers/agents.js +4 -1
  559. package/dist/providers/agents.js.map +1 -1
  560. package/dist/providers/antigravity-install.constants.d.ts +2 -0
  561. package/dist/providers/antigravity-install.constants.js +28 -0
  562. package/dist/providers/antigravity-install.constants.js.map +1 -0
  563. package/dist/providers/antigravity-install.d.ts +2 -0
  564. package/dist/providers/antigravity-install.js +29 -0
  565. package/dist/providers/antigravity-install.js.map +1 -0
  566. package/dist/providers/antigravity-install.types.d.ts +4 -0
  567. package/dist/providers/antigravity-install.types.js +2 -0
  568. package/dist/providers/antigravity-install.types.js.map +1 -0
  569. package/dist/providers/container-recovery.d.ts +4 -0
  570. package/dist/providers/container-recovery.js +28 -0
  571. package/dist/providers/container-recovery.js.map +1 -0
  572. package/dist/providers/container.js +8 -0
  573. package/dist/providers/container.js.map +1 -1
  574. package/dist/providers/daytona-network.constants.d.ts +5 -0
  575. package/dist/providers/daytona-network.constants.js +8 -0
  576. package/dist/providers/daytona-network.constants.js.map +1 -0
  577. package/dist/providers/daytona-network.d.ts +4 -0
  578. package/dist/providers/daytona-network.js +33 -0
  579. package/dist/providers/daytona-network.js.map +1 -0
  580. package/dist/providers/daytona.d.ts +1 -0
  581. package/dist/providers/daytona.js +9 -3
  582. package/dist/providers/daytona.js.map +1 -1
  583. package/dist/providers/daytona.types.d.ts +2 -0
  584. package/dist/providers/daytona.types.js.map +1 -1
  585. package/dist/providers/firecracker-command.js +1 -1
  586. package/dist/providers/firecracker-command.js.map +1 -1
  587. package/dist/providers/firecracker-jailer.constants.d.ts +9 -0
  588. package/dist/providers/firecracker-jailer.constants.js +10 -0
  589. package/dist/providers/firecracker-jailer.constants.js.map +1 -0
  590. package/dist/providers/firecracker-jailer.d.ts +4 -0
  591. package/dist/providers/firecracker-jailer.js +171 -0
  592. package/dist/providers/firecracker-jailer.js.map +1 -0
  593. package/dist/providers/firecracker-machine.js +30 -8
  594. package/dist/providers/firecracker-machine.js.map +1 -1
  595. package/dist/providers/firecracker.types.d.ts +16 -0
  596. package/dist/providers/firecracker.types.js.map +1 -1
  597. package/dist/providers/vercel-network.js +1 -1
  598. package/dist/providers/vercel-network.js.map +1 -1
  599. package/dist/providers/vercel.js +6 -3
  600. package/dist/providers/vercel.js.map +1 -1
  601. package/dist/providers/versions.constants.d.ts +3 -1
  602. package/dist/providers/versions.constants.js +3 -1
  603. package/dist/providers/versions.constants.js.map +1 -1
  604. package/package.json +3 -3
  605. package/dist/adapters/agents/gemini-adapter.d.ts +0 -3
  606. package/dist/adapters/agents/gemini-adapter.js +0 -34
  607. package/dist/adapters/agents/gemini-adapter.js.map +0 -1
  608. package/dist/adapters/agents/gemini-diagnostics.d.ts +0 -2
  609. package/dist/adapters/agents/gemini-diagnostics.js +0 -15
  610. package/dist/adapters/agents/gemini-diagnostics.js.map +0 -1
  611. package/dist/adapters/agents/gemini-events.d.ts +0 -2
  612. package/dist/adapters/agents/gemini-events.js +0 -50
  613. package/dist/adapters/agents/gemini-events.js.map +0 -1
  614. package/dist/adapters/agents/gemini-request.js +0 -23
  615. package/dist/adapters/agents/gemini-request.js.map +0 -1
  616. package/dist/adapters/agents/gemini.types.js +0 -2
  617. package/dist/adapters/agents/gemini.types.js.map +0 -1
  618. package/dist/infrastructure/artifact-store.d.ts +0 -3
  619. package/dist/infrastructure/artifact-store.js +0 -110
  620. package/dist/infrastructure/artifact-store.js.map +0 -1
  621. package/dist/infrastructure/artifact-store.types.d.ts +0 -6
  622. package/dist/infrastructure/artifact-store.types.js +0 -2
  623. package/dist/infrastructure/artifact-store.types.js.map +0 -1
  624. package/dist/infrastructure/journal-retention.constants.d.ts +0 -4
  625. package/dist/infrastructure/journal-retention.constants.js +0 -5
  626. package/dist/infrastructure/journal-retention.constants.js.map +0 -1
  627. package/dist/infrastructure/journal-retention.d.ts +0 -2
  628. package/dist/infrastructure/journal-retention.js +0 -51
  629. package/dist/infrastructure/journal-retention.js.map +0 -1
  630. package/dist/infrastructure/storage-mutation-lock.constants.d.ts +0 -5
  631. package/dist/infrastructure/storage-mutation-lock.constants.js +0 -6
  632. package/dist/infrastructure/storage-mutation-lock.constants.js.map +0 -1
  633. package/dist/infrastructure/storage-mutation-lock.d.ts +0 -1
  634. package/dist/infrastructure/storage-mutation-lock.js +0 -21
  635. package/dist/infrastructure/storage-mutation-lock.js.map +0 -1
  636. package/dist/infrastructure/storage-reservations.constants.d.ts +0 -4
  637. package/dist/infrastructure/storage-reservations.constants.js +0 -5
  638. package/dist/infrastructure/storage-reservations.constants.js.map +0 -1
  639. package/dist/infrastructure/storage-reservations.d.ts +0 -2
  640. package/dist/infrastructure/storage-reservations.js +0 -150
  641. package/dist/infrastructure/storage-reservations.js.map +0 -1
  642. package/dist/infrastructure/workflow-checkpoint.d.ts +0 -3
  643. package/dist/infrastructure/workflow-checkpoint.js +0 -84
  644. package/dist/infrastructure/workflow-checkpoint.js.map +0 -1
  645. package/dist/infrastructure/workflow-checkpoint.types.d.ts +0 -6
  646. package/dist/infrastructure/workflow-checkpoint.types.js +0 -2
  647. package/dist/infrastructure/workflow-checkpoint.types.js.map +0 -1
@@ -4,3 +4,4 @@ export interface AgentProtocolFixture {
4
4
  readonly lines: readonly string[];
5
5
  readonly expected: readonly AgentEvent[];
6
6
  }
7
+ export type ProtocolAgent = "claude" | "codex" | "antigravity" | "copilot" | "kimi";
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-fixtures.types.js","sourceRoot":"","sources":["../../../src/adapters/agents/protocol-fixtures.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentEvent } from \"../../domain/agent.types.ts\";\n\nexport interface AgentProtocolFixture {\n readonly name: string;\n readonly lines: readonly string[];\n readonly expected: readonly AgentEvent[];\n}\n"]}
1
+ {"version":3,"file":"protocol-fixtures.types.js","sourceRoot":"","sources":["../../../src/adapters/agents/protocol-fixtures.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentEvent } from \"../../domain/agent.types.ts\";\n\nexport interface AgentProtocolFixture {\n readonly name: string;\n readonly lines: readonly string[];\n readonly expected: readonly AgentEvent[];\n}\n\nexport type ProtocolAgent =\n \"claude\" | \"codex\" | \"antigravity\" | \"copilot\" | \"kimi\";\n"]}
@@ -1,3 +1,4 @@
1
1
  export declare function asRecord(value: unknown): Record<string, unknown>;
2
2
  export declare function numberOrZero(value: unknown): number;
3
3
  export declare function decodeRecord(line: string): Record<string, unknown> | undefined;
4
+ export declare function parseCredential(content: string, agent: string): unknown;
@@ -1,3 +1,4 @@
1
+ import { OutpostError } from "../../domain/errors.js";
1
2
  export function asRecord(value) {
2
3
  return value !== null && typeof value === "object"
3
4
  ? value
@@ -14,4 +15,12 @@ export function decodeRecord(line) {
14
15
  return undefined;
15
16
  }
16
17
  }
18
+ export function parseCredential(content, agent) {
19
+ try {
20
+ return JSON.parse(content);
21
+ }
22
+ catch {
23
+ throw new OutpostError("configuration", `The ${agent} credential file is not valid JSON`);
24
+ }
25
+ }
17
26
  //# sourceMappingURL=protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/adapters/agents/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAChD,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,IAAY;IAEZ,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["export function asRecord(value: unknown): Record<string, unknown> {\n return value !== null && typeof value === \"object\"\n ? (value as Record<string, unknown>)\n : {};\n}\n\nexport function numberOrZero(value: unknown): number {\n return typeof value === \"number\" ? value : 0;\n}\n\nexport function decodeRecord(\n line: string,\n): Record<string, unknown> | undefined {\n try {\n return asRecord(JSON.parse(line));\n } catch {\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/adapters/agents/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAChD,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,IAAY;IAEZ,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,KAAa;IAC5D,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,YAAY,CACpB,eAAe,EACf,OAAO,KAAK,oCAAoC,CACjD,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { OutpostError } from \"../../domain/errors.ts\";\n\nexport function asRecord(value: unknown): Record<string, unknown> {\n return value !== null && typeof value === \"object\"\n ? (value as Record<string, unknown>)\n : {};\n}\n\nexport function numberOrZero(value: unknown): number {\n return typeof value === \"number\" ? value : 0;\n}\n\nexport function decodeRecord(\n line: string,\n): Record<string, unknown> | undefined {\n try {\n return asRecord(JSON.parse(line));\n } catch {\n return undefined;\n }\n}\n\nexport function parseCredential(content: string, agent: string): unknown {\n try {\n return JSON.parse(content);\n } catch {\n throw new OutpostError(\n \"configuration\",\n `The ${agent} credential file is not valid JSON`,\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;AACvD,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,UAAU,mBAAmB,CACjC,IAAwB,EACxB,YAAoB;IAEpB,IAAI,CAAC,mCAAmC,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO;IACpE,OAAO;QACL,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE;YACT,IAAI;YACJ,kBAAkB;YAClB,IAAI;YACJ,YAAY;YACZ,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC;SACnC;QACD,MAAM,EAAE,kBAAkB,CAAC,WAAW;QACtC,UAAU,EAAE,kBAAkB,CAAC,UAAU;KAC1C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,KAAc,EACd,MAAe,EACf,MAAe,EACf,YAAqB;IAErB,MAAM,KAAK,G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C,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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E,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,SAAS,CAChB,KAA8B,EAC9B,OAAwB;IAExB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,KAAK;KACZ,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,KAAc;IAC3B,IAAI,KAAK,KAAK,SAAS;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 };\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,E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AC","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;I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,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,iB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,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 { 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,OAAqB,EACrB,OAAwB;IAExB,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CACzD,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAChC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;QAC9D,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACzE,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM;YACvB,CAAC,CAAC;gBACE,KAA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AAC,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 },\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,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,OAAqB,EACrB,OAAwB;IAExB,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CACzD,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAChC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CA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tC,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-after.js","sourceRoot":"","sources":["../../../src/adapters/models/retry-after.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAC1B,KAAoB,EACpB,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IAEhB,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACrC,OAAO,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/D,CAAC;IACD,IACE,CAAC,mLAAmL,CAAC,IAAI,CACvL,IAAI,CACL;QAED,OAAO,SAAS,CAAC;IACnB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;IACrE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,GAAG,CAAC,CAAC;AACjC,CAAC","sourcesContent":["export function retryAfterMs(\n value: string | null,\n now = Date.now(),\n): number | undefined {\n if (value === null) return undefined;\n const text = value.trim();\n if (/^\\d+$/.test(text)) {\n const duration = Number(text) * 1000;\n return Number.isSafeInteger(duration) ? duration : undefined;\n }\n if (\n !/^(?:[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(\n text,\n )\n )\n return undefined;\n const date = Date.parse(text.endsWith(\"GMT\") ? text : `${text} GMT`);\n if (!Number.isFinite(date)) return undefined;\n return Math.max(0, date - now);\n}\n"]}
@@ -10,7 +10,7 @@ export function activityWatchdog(controller, options, pass) {
10
10
  clearTimeout(idle);
11
11
  clearTimeout(settle);
12
12
  if (!completed && holds === 0)
13
- idle = setTimeout(() => controller.abort(new OutpostError("timeout", "Agent produced no output before the idle deadline")), options.idleMs ?? executionDefaults.idleMs);
13
+ idle = setTimeout(() => controller.abort(new OutpostError("timeout", "Agent produced no output before the idle deadline", { stopReason: "idle-timeout" })), options.idleMs ?? executionDefaults.idleMs);
14
14
  if (completed)
15
15
  settle = setTimeout(() => controller.abort("completion"), options.settleMs ?? executionDefaults.settleMs);
16
16
  };
@@ -18,7 +18,6 @@ export function activityWatchdog(controller, options, pass) {
18
18
  const warnings = setInterval(() => {
19
19
  if (holds === 0 && Date.now() - lastActivity >= warningInterval) {
20
20
  const message = `Agent has been idle for ${Math.floor((Date.now() - lastActivity) / 1000)} seconds`;
21
- notify(options.warn, message);
22
21
  notify(options.observe, {
23
22
  kind: "warning",
24
23
  message,
@@ -1 +1 @@
1
- {"version":3,"file":"activity-watchdog.js","sourceRoot":"","sources":["../../src/application/activity-watchdog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,UAAU,gBAAgB,CAC9B,UAA2B,EAC3B,OAAiC,EACjC,IAAY;IAEZ,IAAI,IAAgC,EAAE,MAAkC,CAAC;IACzE,IAAI,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,OAAO,GAAG,CAAC,SAAkB,EAAE,EAAE;QACrC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1B,YAAY,CAAC,IAAI,CAAC,CAAC;QACnB,YAAY,CAAC,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,SAAS,IAAI,KAAK,KAAK,CAAC;YAC3B,IAAI,GAAG,UAAU,CACf,GAAG,EAAE,CACH,UAAU,CAAC,KAAK,CACd,IAAI,YAAY,CACd,SAAS,EACT,mDAAmD,CACpD,CACF,EACH,OAAO,CAAC,MAAM,IAAI,iBAAiB,CAAC,MAAM,CAC3C,CAAC;QACJ,IAAI,SAAS;YACX,MAAM,GA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C;AACJ,CAAC","sourcesContent":["import { OutpostError } from \"../domain/errors.ts\";\nimport { executionDefaults } from \"./execution.constants.ts\";\nimport type { ActivityWatchdog, DispatchOptions } from \"./execution.types.ts\";\nimport { notify } from \"./observation.ts\";\n\nexport function activityWatchdog(\n controller: AbortController,\n options: DispatchOptions<unknown>,\n pass: number,\n): ActivityWatchdog {\n let idle: NodeJS.Timeout | undefined, settle: NodeJS.Timeout | undefined;\n let lastActivity = Date.now();\n let holds = 0;\n const refresh = (completed: boolean) => {\n lastActivity = Date.now();\n clearTimeout(idle);\n clearTimeout(settle);\n if (!completed && holds === 0)\n idle = setTimeout(\n () =>\n controller.abort(\n new OutpostError(\n \"timeout\",\n \"Agent produced no output before the idle deadline\",\n ),\n ),\n options.idleMs ?? executionDefaults.idleMs,\n );\n if (completed)\n settle = setTimeout(\n () => controller.abort(\"completion\"),\n options.settleMs ?? executionDefaults.settleMs,\n );\n };\n\n const warningInterval =\n options.idleWarningMs ?? executionDefaults.idleWarningMs;\n const warnings = setInterval(() => {\n if (holds === 0 && Date.now() - lastActivity >= warningInterval) {\n const message = `Agent has been idle for ${Math.floor((Date.now() - lastActivity) / 1000)} seconds`;\n notify(options.warn, message);\n notify(options.observe, {\n kind: \"warning\",\n message,\n pass,\n at: new Date().toISOString(),\n });\n }\n }, warningInterval);\n\n return {\n refresh,\n hold() {\n holds++;\n refresh(false);\n let released = false;\n return () => {\n if (released) return;\n released = true;\n holds--;\n refresh(false);\n };\n },\n close() {\n clearTimeout(idle);\n clearTimeout(settle);\n clearInterval(warnings);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"activity-watchdog.js","sourceRoot":"","sources":["../../src/application/activity-watchdog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,UAA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AAO;gBACP,IAAI;gBACJ,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aAC7B,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,eAAe,CAAC,CAAC;IAEpB,OAAO;QACL,OAAO;QACP,IAAI;YACF,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,IAAI,QAAQ,GAAG,KAAK,CAAC;YACrB,OAAO,GAAG,EAAE;gBACV,IAAI,QAAQ;oBAAE,OAAO;gBACrB,QAAQ,GAAG,IAAI,CAAC;gBAChB,KAAK,EAAE,CAAC;gBACR,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC;QACJ,CAAC;QACD,KAAK;YACH,YAAY,CAAC,IAAI,CAAC,CAAC;YACnB,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { OutpostError } from \"../domain/errors.ts\";\nimport { executionDefaults } from \"./execution.constants.ts\";\nimport type { ActivityWatchdog, DispatchOptions } from \"./execution.types.ts\";\nimport { notify } from \"./observation.ts\";\n\nexport function activityWatchdog(\n controller: AbortController,\n options: DispatchOptions<unknown>,\n pass: number,\n): ActivityWatchdog {\n let idle: NodeJS.Timeout | undefined, settle: NodeJS.Timeout | undefined;\n let lastActivity = Date.now();\n let holds = 0;\n const refresh = (completed: boolean) => {\n lastActivity = Date.now();\n clearTimeout(idle);\n clearTimeout(settle);\n if (!completed && holds === 0)\n idle = setTimeout(\n () =>\n controller.abort(\n new OutpostError(\n \"timeout\",\n \"Agent produced no output before the idle deadline\",\n { stopReason: \"idle-timeout\" },\n ),\n ),\n options.idleMs ?? executionDefaults.idleMs,\n );\n if (completed)\n settle = setTimeout(\n () => controller.abort(\"completion\"),\n options.settleMs ?? executionDefaults.settleMs,\n );\n };\n\n const warningInterval =\n options.idleWarningMs ?? executionDefaults.idleWarningMs;\n const warnings = setInterval(() => {\n if (holds === 0 && Date.now() - lastActivity >= warningInterval) {\n const message = `Agent has been idle for ${Math.floor((Date.now() - lastActivity) / 1000)} seconds`;\n notify(options.observe, {\n kind: \"warning\",\n message,\n pass,\n at: new Date().toISOString(),\n });\n }\n }, warningInterval);\n\n return {\n refresh,\n hold() {\n holds++;\n refresh(false);\n let released = false;\n return () => {\n if (released) return;\n released = true;\n holds--;\n refresh(false);\n };\n },\n close() {\n clearTimeout(idle);\n clearTimeout(settle);\n clearInterval(warnings);\n },\n };\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { AgentAdapter } from "../domain/agent.types.ts";
2
+ import type { Variables } from "../domain/command.types.ts";
3
+ import type { SandboxLease, SandboxProvider } from "../domain/sandbox.types.ts";
4
+ export declare function authenticateAgent(adapter: AgentAdapter, variables: Variables, lease: SandboxLease, placement: SandboxProvider["placement"], signal: AbortSignal): Promise<Variables>;
@@ -0,0 +1,32 @@
1
+ import { readHostCredential } from "../infrastructure/host-credentials.js";
2
+ import { requireSuccess } from "../infrastructure/process.js";
3
+ import { credentialInstaller } from "./credential-installer.constants.js";
4
+ export async function authenticateAgent(adapter, variables, lease, placement, signal) {
5
+ const plan = adapter.credentials?.(variables);
6
+ if (!plan)
7
+ return {};
8
+ if (placement === "host")
9
+ return plan.variables;
10
+ const files = [...plan.files];
11
+ const derived = {};
12
+ for (const credential of plan.host) {
13
+ const content = await readHostCredential(credential);
14
+ if ("file" in credential.destination)
15
+ files.push({ path: credential.destination.file, content });
16
+ else
17
+ derived[credential.destination.variable] = content;
18
+ }
19
+ const invoke = lease.invoke.bind(lease);
20
+ if (files.length)
21
+ await requireSuccess({
22
+ executable: "node",
23
+ arguments: ["-e", credentialInstaller],
24
+ stdin: JSON.stringify({ home: lease.home, files }),
25
+ signal,
26
+ }, invoke);
27
+ const credentials = Object.freeze({ ...plan.variables, ...derived });
28
+ for (const command of plan.commands)
29
+ await requireSuccess({ ...command, variables: { ...variables, ...credentials }, signal }, invoke);
30
+ return credentials;
31
+ }
32
+ //# sourceMappingURL=agent-authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-authentication.js","sourceRoot":"","sources":["../../src/application/agent-authentication.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAqB,EACrB,SAAoB,EACpB,KAAmB,EACnB,SAAuC,EACvC,MAAmB;IAEnB,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,IAAI,SAAS,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC;IAChD,MAAM,KAAK,GAA0B,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACrD,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,MAAM,IAAI,UAAU,CAAC,WAAW;YAClC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;;YACxD,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;IAC1D,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,MAAM;QACd,MAAM,cAAc,CAClB;YACE,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC;YACtC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;YAClD,MAAM;SACP,EACD,MAAM,CACP,CAAC;IACJ,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACrE,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ;QACjC,MAAM,cAAc,CAClB,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,GAAG,WAAW,EAAE,EAAE,MAAM,EAAE,EACnE,MAAM,CACP,CAAC;IACJ,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import type {\n AgentAdapter,\n GeneratedCredential,\n} from \"../domain/agent.types.ts\";\nimport type { Variables } from \"../domain/command.types.ts\";\nimport type { SandboxLease, SandboxProvider } from \"../domain/sandbox.types.ts\";\nimport { readHostCredential } from \"../infrastructure/host-credentials.ts\";\nimport { requireSuccess } from \"../infrastructure/process.ts\";\nimport { credentialInstaller } from \"./credential-installer.constants.ts\";\n\nexport async function authenticateAgent(\n adapter: AgentAdapter,\n variables: Variables,\n lease: SandboxLease,\n placement: SandboxProvider[\"placement\"],\n signal: AbortSignal,\n): Promise<Variables> {\n const plan = adapter.credentials?.(variables);\n if (!plan) return {};\n if (placement === \"host\") return plan.variables;\n const files: GeneratedCredential[] = [...plan.files];\n const derived: Record<string, string> = {};\n for (const credential of plan.host) {\n const content = await readHostCredential(credential);\n if (\"file\" in credential.destination)\n files.push({ path: credential.destination.file, content });\n else derived[credential.destination.variable] = content;\n }\n const invoke = lease.invoke.bind(lease);\n if (files.length)\n await requireSuccess(\n {\n executable: \"node\",\n arguments: [\"-e\", credentialInstaller],\n stdin: JSON.stringify({ home: lease.home, files }),\n signal,\n },\n invoke,\n );\n const credentials = Object.freeze({ ...plan.variables, ...derived });\n for (const command of plan.commands)\n await requireSuccess(\n { ...command, variables: { ...variables, ...credentials }, signal },\n invoke,\n );\n return credentials;\n}\n"]}
@@ -1,5 +1,2 @@
1
- export declare const agentPackages: Readonly<{
2
- claude: "@anthropic-ai/claude-code@2.1.280";
3
- gemini: "@google/gemini-cli@0.61.0";
4
- codex: "@openai/codex@0.156.1";
5
- }>;
1
+ import type { AgentInstaller } from "./agent-bootstrap.types.ts";
2
+ export declare const agentInstallers: Readonly<Record<string, AgentInstaller>>;