@assemblyline-agents/runtime 5.0.10 → 6.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 (443) hide show
  1. package/README.md +18 -5
  2. package/dist/a2a-client.d.ts +1 -3
  3. package/dist/a2a-client.d.ts.map +1 -1
  4. package/dist/a2a-client.js +1 -4
  5. package/dist/a2a-client.js.map +1 -1
  6. package/dist/agent-event-handlers.d.ts +2 -0
  7. package/dist/agent-event-handlers.d.ts.map +1 -1
  8. package/dist/agent-event-handlers.js +1 -1
  9. package/dist/agent-event-handlers.js.map +1 -1
  10. package/dist/agent-hook-context.d.ts.map +1 -1
  11. package/dist/agent-hook-context.js +3 -1
  12. package/dist/agent-hook-context.js.map +1 -1
  13. package/dist/agent-hook-controller-factory.d.ts +5 -1
  14. package/dist/agent-hook-controller-factory.d.ts.map +1 -1
  15. package/dist/agent-hook-controller-factory.js +11 -9
  16. package/dist/agent-hook-controller-factory.js.map +1 -1
  17. package/dist/agent-hook-evaluation.d.ts +0 -2
  18. package/dist/agent-hook-evaluation.d.ts.map +1 -1
  19. package/dist/agent-hook-evaluation.js +10 -10
  20. package/dist/agent-hook-evaluation.js.map +1 -1
  21. package/dist/agent-hook-run-lifecycle.d.ts +1 -2
  22. package/dist/agent-hook-run-lifecycle.d.ts.map +1 -1
  23. package/dist/agent-hook-run-lifecycle.js +1 -2
  24. package/dist/agent-hook-run-lifecycle.js.map +1 -1
  25. package/dist/agent-surface.d.ts +5 -2
  26. package/dist/agent-surface.d.ts.map +1 -1
  27. package/dist/agent-surface.js +11 -3
  28. package/dist/agent-surface.js.map +1 -1
  29. package/dist/artifact-selection.js +1 -1
  30. package/dist/artifact-selection.js.map +1 -1
  31. package/dist/assembly-line-runtime.d.ts +9 -0
  32. package/dist/assembly-line-runtime.d.ts.map +1 -0
  33. package/dist/assembly-line-runtime.js +9 -0
  34. package/dist/assembly-line-runtime.js.map +1 -0
  35. package/dist/attachment-download.d.ts +17 -0
  36. package/dist/attachment-download.d.ts.map +1 -0
  37. package/dist/attachment-download.js +51 -0
  38. package/dist/attachment-download.js.map +1 -0
  39. package/dist/attachments.d.ts +2 -14
  40. package/dist/attachments.d.ts.map +1 -1
  41. package/dist/attachments.js +8 -80
  42. package/dist/attachments.js.map +1 -1
  43. package/dist/background-review-types.d.ts +2 -0
  44. package/dist/background-review-types.d.ts.map +1 -1
  45. package/dist/background-review.d.ts.map +1 -1
  46. package/dist/background-review.js +13 -0
  47. package/dist/background-review.js.map +1 -1
  48. package/dist/background-subagents.d.ts +1 -1
  49. package/dist/background-subagents.d.ts.map +1 -1
  50. package/dist/blob-storage.d.ts +12 -0
  51. package/dist/blob-storage.d.ts.map +1 -0
  52. package/dist/blob-storage.js +86 -0
  53. package/dist/blob-storage.js.map +1 -0
  54. package/dist/builtin-tool-executors.d.ts.map +1 -1
  55. package/dist/builtin-tool-executors.js +14 -18
  56. package/dist/builtin-tool-executors.js.map +1 -1
  57. package/dist/builtin-tools.d.ts +1 -2
  58. package/dist/builtin-tools.d.ts.map +1 -1
  59. package/dist/builtin-tools.js +0 -8
  60. package/dist/builtin-tools.js.map +1 -1
  61. package/dist/capability-inspection.d.ts +4 -0
  62. package/dist/capability-inspection.d.ts.map +1 -1
  63. package/dist/capability-inspection.js +10 -11
  64. package/dist/capability-inspection.js.map +1 -1
  65. package/dist/channel-credential-environment.d.ts +1 -1
  66. package/dist/channel-credential-environment.d.ts.map +1 -1
  67. package/dist/channel-credential-environment.js +1 -6
  68. package/dist/channel-credential-environment.js.map +1 -1
  69. package/dist/channel-ingress.d.ts +1 -2
  70. package/dist/channel-ingress.d.ts.map +1 -1
  71. package/dist/channel-ingress.js +2 -2
  72. package/dist/channel-ingress.js.map +1 -1
  73. package/dist/channel-operation.d.ts +0 -1
  74. package/dist/channel-operation.d.ts.map +1 -1
  75. package/dist/channel-operation.js +1 -2
  76. package/dist/channel-operation.js.map +1 -1
  77. package/dist/channel.d.ts +32 -3
  78. package/dist/channel.d.ts.map +1 -1
  79. package/dist/connection-assets.d.ts.map +1 -1
  80. package/dist/connection-assets.js.map +1 -1
  81. package/dist/connection-authorization-service.d.ts +52 -0
  82. package/dist/connection-authorization-service.d.ts.map +1 -0
  83. package/dist/connection-authorization-service.js +417 -0
  84. package/dist/connection-authorization-service.js.map +1 -0
  85. package/dist/connection-credential-materialization.d.ts +23 -0
  86. package/dist/connection-credential-materialization.d.ts.map +1 -0
  87. package/dist/connection-credential-materialization.js +223 -0
  88. package/dist/connection-credential-materialization.js.map +1 -0
  89. package/dist/connection-definition-loader.d.ts +6 -0
  90. package/dist/connection-definition-loader.d.ts.map +1 -0
  91. package/dist/connection-definition-loader.js +102 -0
  92. package/dist/connection-definition-loader.js.map +1 -0
  93. package/dist/connection-discovery.d.ts +11 -0
  94. package/dist/connection-discovery.d.ts.map +1 -0
  95. package/dist/connection-discovery.js +105 -0
  96. package/dist/connection-discovery.js.map +1 -0
  97. package/dist/connection-events.d.ts.map +1 -1
  98. package/dist/connection-events.js.map +1 -1
  99. package/dist/connection-oauth-client.d.ts +3 -0
  100. package/dist/connection-oauth-client.d.ts.map +1 -0
  101. package/dist/connection-oauth-client.js +64 -0
  102. package/dist/connection-oauth-client.js.map +1 -0
  103. package/dist/connection-runtime-types.d.ts +78 -0
  104. package/dist/connection-runtime-types.d.ts.map +1 -0
  105. package/dist/connection-runtime-types.js +31 -0
  106. package/dist/connection-runtime-types.js.map +1 -0
  107. package/dist/connections.d.ts +18 -167
  108. package/dist/connections.d.ts.map +1 -1
  109. package/dist/connections.js +71 -1017
  110. package/dist/connections.js.map +1 -1
  111. package/dist/context-policy-util.d.ts +0 -4
  112. package/dist/context-policy-util.d.ts.map +1 -1
  113. package/dist/context-policy-util.js +0 -10
  114. package/dist/context-policy-util.js.map +1 -1
  115. package/dist/conversation-context.d.ts +1 -1
  116. package/dist/conversation-context.d.ts.map +1 -1
  117. package/dist/conversation-context.js +12 -9
  118. package/dist/conversation-context.js.map +1 -1
  119. package/dist/default-outbound-route.d.ts +1 -0
  120. package/dist/default-outbound-route.d.ts.map +1 -1
  121. package/dist/default-outbound-route.js +1 -1
  122. package/dist/default-outbound-route.js.map +1 -1
  123. package/dist/delivery-queue.d.ts +1 -1
  124. package/dist/delivery-send.d.ts.map +1 -1
  125. package/dist/delivery-send.js +3 -2
  126. package/dist/delivery-send.js.map +1 -1
  127. package/dist/dynamic-schedule-execution.d.ts +4 -0
  128. package/dist/dynamic-schedule-execution.d.ts.map +1 -0
  129. package/dist/dynamic-schedule-execution.js +136 -0
  130. package/dist/dynamic-schedule-execution.js.map +1 -0
  131. package/dist/dynamic-schedule-runtime.d.ts +11 -20
  132. package/dist/dynamic-schedule-runtime.d.ts.map +1 -1
  133. package/dist/dynamic-schedule-runtime.js +27 -39
  134. package/dist/dynamic-schedule-runtime.js.map +1 -1
  135. package/dist/evolution-tracker.d.ts +52 -0
  136. package/dist/evolution-tracker.d.ts.map +1 -0
  137. package/dist/evolution-tracker.js +179 -0
  138. package/dist/evolution-tracker.js.map +1 -0
  139. package/dist/harness-capabilities.d.ts +7 -0
  140. package/dist/harness-capabilities.d.ts.map +1 -0
  141. package/dist/harness-capabilities.js +56 -0
  142. package/dist/harness-capabilities.js.map +1 -0
  143. package/dist/harness-continuation-persistence.d.ts +6 -0
  144. package/dist/harness-continuation-persistence.d.ts.map +1 -0
  145. package/dist/harness-continuation-persistence.js +11 -0
  146. package/dist/harness-continuation-persistence.js.map +1 -0
  147. package/dist/harness-execution-context.d.ts +10 -0
  148. package/dist/harness-execution-context.d.ts.map +1 -0
  149. package/dist/harness-execution-context.js +193 -0
  150. package/dist/harness-execution-context.js.map +1 -0
  151. package/dist/harness-loop-types.d.ts +67 -0
  152. package/dist/harness-loop-types.d.ts.map +1 -0
  153. package/dist/harness-loop-types.js +2 -0
  154. package/dist/harness-loop-types.js.map +1 -0
  155. package/dist/harness-loop.d.ts +13 -94
  156. package/dist/harness-loop.d.ts.map +1 -1
  157. package/dist/harness-loop.js +19 -551
  158. package/dist/harness-loop.js.map +1 -1
  159. package/dist/harness-tool-execution.d.ts +30 -0
  160. package/dist/harness-tool-execution.d.ts.map +1 -0
  161. package/dist/harness-tool-execution.js +397 -0
  162. package/dist/harness-tool-execution.js.map +1 -0
  163. package/dist/harness-transcript-resume.d.ts +18 -0
  164. package/dist/harness-transcript-resume.d.ts.map +1 -0
  165. package/dist/harness-transcript-resume.js +102 -0
  166. package/dist/harness-transcript-resume.js.map +1 -0
  167. package/dist/harness-turn-execution.d.ts +11 -0
  168. package/dist/harness-turn-execution.d.ts.map +1 -0
  169. package/dist/harness-turn-execution.js +157 -0
  170. package/dist/harness-turn-execution.js.map +1 -0
  171. package/dist/index.d.ts +10 -499
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +9 -2139
  174. package/dist/index.js.map +1 -1
  175. package/dist/local-sandbox.d.ts +2 -1
  176. package/dist/local-sandbox.d.ts.map +1 -1
  177. package/dist/mcp-client.d.ts +11 -1
  178. package/dist/mcp-client.d.ts.map +1 -1
  179. package/dist/mcp-client.js +39 -7
  180. package/dist/mcp-client.js.map +1 -1
  181. package/dist/media-processor.d.ts +3 -1
  182. package/dist/media-processor.d.ts.map +1 -1
  183. package/dist/media-processor.js +15 -1
  184. package/dist/media-processor.js.map +1 -1
  185. package/dist/memory-storage.d.ts +51 -0
  186. package/dist/memory-storage.d.ts.map +1 -0
  187. package/dist/memory-storage.js +324 -0
  188. package/dist/memory-storage.js.map +1 -0
  189. package/dist/model-credential-stores.d.ts.map +1 -1
  190. package/dist/model-credential-stores.js +6 -12
  191. package/dist/model-credential-stores.js.map +1 -1
  192. package/dist/model-provider-environment.d.ts +4 -0
  193. package/dist/model-provider-environment.d.ts.map +1 -0
  194. package/dist/model-provider-environment.js +36 -0
  195. package/dist/model-provider-environment.js.map +1 -0
  196. package/dist/plugin-embeddings.d.ts +4 -0
  197. package/dist/plugin-embeddings.d.ts.map +1 -0
  198. package/dist/plugin-embeddings.js +75 -0
  199. package/dist/plugin-embeddings.js.map +1 -0
  200. package/dist/public-api.d.ts +8 -5
  201. package/dist/public-api.d.ts.map +1 -1
  202. package/dist/public-api.js +6 -4
  203. package/dist/public-api.js.map +1 -1
  204. package/dist/relay-mcp-client.js +1 -1
  205. package/dist/relay-mcp-client.js.map +1 -1
  206. package/dist/replay-resume-authorization.d.ts +8 -0
  207. package/dist/replay-resume-authorization.d.ts.map +1 -0
  208. package/dist/replay-resume-authorization.js +181 -0
  209. package/dist/replay-resume-authorization.js.map +1 -0
  210. package/dist/replay-resume-connection.d.ts +6 -0
  211. package/dist/replay-resume-connection.d.ts.map +1 -0
  212. package/dist/replay-resume-connection.js +75 -0
  213. package/dist/replay-resume-connection.js.map +1 -0
  214. package/dist/replay-resume-controls.d.ts +6 -0
  215. package/dist/replay-resume-controls.d.ts.map +1 -0
  216. package/dist/replay-resume-controls.js +157 -0
  217. package/dist/replay-resume-controls.js.map +1 -0
  218. package/dist/replay-resume-harness.d.ts +14 -0
  219. package/dist/replay-resume-harness.d.ts.map +1 -0
  220. package/dist/replay-resume-harness.js +158 -0
  221. package/dist/replay-resume-harness.js.map +1 -0
  222. package/dist/replay-resume-recovery.d.ts +10 -0
  223. package/dist/replay-resume-recovery.d.ts.map +1 -0
  224. package/dist/replay-resume-recovery.js +62 -0
  225. package/dist/replay-resume-recovery.js.map +1 -0
  226. package/dist/replay-resume-shared.d.ts +16 -0
  227. package/dist/replay-resume-shared.d.ts.map +1 -0
  228. package/dist/replay-resume-shared.js +55 -0
  229. package/dist/replay-resume-shared.js.map +1 -0
  230. package/dist/replay-resume-types.d.ts +85 -0
  231. package/dist/replay-resume-types.d.ts.map +1 -0
  232. package/dist/replay-resume-types.js +2 -0
  233. package/dist/replay-resume-types.js.map +1 -0
  234. package/dist/replay-resume.d.ts +7 -119
  235. package/dist/replay-resume.d.ts.map +1 -1
  236. package/dist/replay-resume.js +5 -715
  237. package/dist/replay-resume.js.map +1 -1
  238. package/dist/resource-projection-util.d.ts +1 -2
  239. package/dist/resource-projection-util.d.ts.map +1 -1
  240. package/dist/resource-projection-util.js +2 -11
  241. package/dist/resource-projection-util.js.map +1 -1
  242. package/dist/resource-projection.d.ts.map +1 -1
  243. package/dist/resource-projection.js +67 -22
  244. package/dist/resource-projection.js.map +1 -1
  245. package/dist/run-execution-host.d.ts +98 -0
  246. package/dist/run-execution-host.d.ts.map +1 -0
  247. package/dist/run-execution-host.js +2 -0
  248. package/dist/run-execution-host.js.map +1 -0
  249. package/dist/run-execution.d.ts +6 -0
  250. package/dist/run-execution.d.ts.map +1 -0
  251. package/dist/run-execution.js +313 -0
  252. package/dist/run-execution.js.map +1 -0
  253. package/dist/run-initialization.d.ts +19 -0
  254. package/dist/run-initialization.d.ts.map +1 -0
  255. package/dist/run-initialization.js +171 -0
  256. package/dist/run-initialization.js.map +1 -0
  257. package/dist/run-recovery.d.ts +1 -1
  258. package/dist/run-recovery.js.map +1 -1
  259. package/dist/runtime-connection-definitions.d.ts +35 -0
  260. package/dist/runtime-connection-definitions.d.ts.map +1 -0
  261. package/dist/runtime-connection-definitions.js +97 -0
  262. package/dist/runtime-connection-definitions.js.map +1 -0
  263. package/dist/runtime-engine-background.d.ts +64 -0
  264. package/dist/runtime-engine-background.d.ts.map +1 -0
  265. package/dist/runtime-engine-background.js +136 -0
  266. package/dist/runtime-engine-background.js.map +1 -0
  267. package/dist/runtime-engine-base.d.ts +60 -0
  268. package/dist/runtime-engine-base.d.ts.map +1 -0
  269. package/dist/runtime-engine-base.js +192 -0
  270. package/dist/runtime-engine-base.js.map +1 -0
  271. package/dist/runtime-engine-capabilities.d.ts +81 -0
  272. package/dist/runtime-engine-capabilities.d.ts.map +1 -0
  273. package/dist/runtime-engine-capabilities.js +198 -0
  274. package/dist/runtime-engine-capabilities.js.map +1 -0
  275. package/dist/runtime-engine-config.d.ts +77 -0
  276. package/dist/runtime-engine-config.d.ts.map +1 -0
  277. package/dist/runtime-engine-config.js +187 -0
  278. package/dist/runtime-engine-config.js.map +1 -0
  279. package/dist/runtime-engine-foundation.d.ts +11 -0
  280. package/dist/runtime-engine-foundation.d.ts.map +1 -0
  281. package/dist/runtime-engine-foundation.js +121 -0
  282. package/dist/runtime-engine-foundation.js.map +1 -0
  283. package/dist/runtime-engine-hooks.d.ts +33 -0
  284. package/dist/runtime-engine-hooks.d.ts.map +1 -0
  285. package/dist/runtime-engine-hooks.js +149 -0
  286. package/dist/runtime-engine-hooks.js.map +1 -0
  287. package/dist/runtime-engine-integrations.d.ts +16 -0
  288. package/dist/runtime-engine-integrations.d.ts.map +1 -0
  289. package/dist/runtime-engine-integrations.js +177 -0
  290. package/dist/runtime-engine-integrations.js.map +1 -0
  291. package/dist/runtime-engine-operations.d.ts +87 -0
  292. package/dist/runtime-engine-operations.d.ts.map +1 -0
  293. package/dist/runtime-engine-operations.js +204 -0
  294. package/dist/runtime-engine-operations.js.map +1 -0
  295. package/dist/runtime-engine-resources.d.ts +18 -0
  296. package/dist/runtime-engine-resources.d.ts.map +1 -0
  297. package/dist/runtime-engine-resources.js +49 -0
  298. package/dist/runtime-engine-resources.js.map +1 -0
  299. package/dist/runtime-engine-run.d.ts +70 -0
  300. package/dist/runtime-engine-run.d.ts.map +1 -0
  301. package/dist/runtime-engine-run.js +202 -0
  302. package/dist/runtime-engine-run.js.map +1 -0
  303. package/dist/runtime-engine-scheduling.d.ts +22 -0
  304. package/dist/runtime-engine-scheduling.d.ts.map +1 -0
  305. package/dist/runtime-engine-scheduling.js +45 -0
  306. package/dist/runtime-engine-scheduling.js.map +1 -0
  307. package/dist/runtime-engine-tools.d.ts +8 -0
  308. package/dist/runtime-engine-tools.d.ts.map +1 -0
  309. package/dist/runtime-engine-tools.js +80 -0
  310. package/dist/runtime-engine-tools.js.map +1 -0
  311. package/dist/runtime-evolution.d.ts +17 -0
  312. package/dist/runtime-evolution.d.ts.map +1 -0
  313. package/dist/runtime-evolution.js +51 -0
  314. package/dist/runtime-evolution.js.map +1 -0
  315. package/dist/runtime-learning.d.ts +4 -6
  316. package/dist/runtime-learning.d.ts.map +1 -1
  317. package/dist/runtime-learning.js +109 -99
  318. package/dist/runtime-learning.js.map +1 -1
  319. package/dist/runtime-types.d.ts +21 -7
  320. package/dist/runtime-types.d.ts.map +1 -1
  321. package/dist/runtime-util.d.ts +4 -3
  322. package/dist/runtime-util.d.ts.map +1 -1
  323. package/dist/runtime-util.js +0 -7
  324. package/dist/runtime-util.js.map +1 -1
  325. package/dist/sandbox-fs.d.ts +2 -7
  326. package/dist/sandbox-fs.d.ts.map +1 -1
  327. package/dist/sandbox-fs.js +6 -37
  328. package/dist/sandbox-fs.js.map +1 -1
  329. package/dist/sandbox-handle.d.ts +1 -3
  330. package/dist/sandbox-handle.d.ts.map +1 -1
  331. package/dist/sandbox-handle.js +2 -5
  332. package/dist/sandbox-handle.js.map +1 -1
  333. package/dist/sandbox-state-sync.d.ts +2 -0
  334. package/dist/sandbox-state-sync.d.ts.map +1 -1
  335. package/dist/sandbox-state-sync.js +26 -2
  336. package/dist/sandbox-state-sync.js.map +1 -1
  337. package/dist/sandbox-tool-bridge.js +2 -3
  338. package/dist/sandbox-tool-bridge.js.map +1 -1
  339. package/dist/schedule-execution.d.ts +4 -4
  340. package/dist/schedule-execution.d.ts.map +1 -1
  341. package/dist/schedule-execution.js +45 -440
  342. package/dist/schedule-execution.js.map +1 -1
  343. package/dist/schedule-trigger-context.d.ts +18 -0
  344. package/dist/schedule-trigger-context.d.ts.map +1 -0
  345. package/dist/schedule-trigger-context.js +276 -0
  346. package/dist/schedule-trigger-context.js.map +1 -0
  347. package/dist/scheduler.d.ts +1 -14
  348. package/dist/scheduler.d.ts.map +1 -1
  349. package/dist/scheduler.js +1 -37
  350. package/dist/scheduler.js.map +1 -1
  351. package/dist/security.d.ts +0 -4
  352. package/dist/security.d.ts.map +1 -1
  353. package/dist/security.js +0 -22
  354. package/dist/security.js.map +1 -1
  355. package/dist/self-improvement.d.ts +5 -21
  356. package/dist/self-improvement.d.ts.map +1 -1
  357. package/dist/self-improvement.js +10 -40
  358. package/dist/self-improvement.js.map +1 -1
  359. package/dist/source-loader.d.ts +0 -3
  360. package/dist/source-loader.d.ts.map +1 -1
  361. package/dist/source-loader.js +1 -10
  362. package/dist/source-loader.js.map +1 -1
  363. package/dist/state/conversation-state.d.ts +117 -0
  364. package/dist/state/conversation-state.d.ts.map +1 -0
  365. package/dist/state/conversation-state.js +2 -0
  366. package/dist/state/conversation-state.js.map +1 -0
  367. package/dist/state/run-state.d.ts +129 -0
  368. package/dist/state/run-state.d.ts.map +1 -0
  369. package/dist/state/run-state.js +3 -0
  370. package/dist/state/run-state.js.map +1 -0
  371. package/dist/state/sandbox-memory-state.d.ts +159 -0
  372. package/dist/state/sandbox-memory-state.d.ts.map +1 -0
  373. package/dist/state/sandbox-memory-state.js +2 -0
  374. package/dist/state/sandbox-memory-state.js.map +1 -0
  375. package/dist/state/store-contracts.d.ts +329 -0
  376. package/dist/state/store-contracts.d.ts.map +1 -0
  377. package/dist/state/store-contracts.js +26 -0
  378. package/dist/state/store-contracts.js.map +1 -0
  379. package/dist/state/usage-state.d.ts +111 -0
  380. package/dist/state/usage-state.d.ts.map +1 -0
  381. package/dist/state/usage-state.js +2 -0
  382. package/dist/state/usage-state.js.map +1 -0
  383. package/dist/state/workspace-state.d.ts +126 -0
  384. package/dist/state/workspace-state.d.ts.map +1 -0
  385. package/dist/state/workspace-state.js +16 -0
  386. package/dist/state/workspace-state.js.map +1 -0
  387. package/dist/state-stores.d.ts +3 -15
  388. package/dist/state-stores.d.ts.map +1 -1
  389. package/dist/state-stores.js +36 -82
  390. package/dist/state-stores.js.map +1 -1
  391. package/dist/state.d.ts +7 -1075
  392. package/dist/state.d.ts.map +1 -1
  393. package/dist/state.js +7 -88
  394. package/dist/state.js.map +1 -1
  395. package/dist/storage.d.ts +4 -64
  396. package/dist/storage.d.ts.map +1 -1
  397. package/dist/storage.js +5 -408
  398. package/dist/storage.js.map +1 -1
  399. package/dist/subagent-execution.d.ts +1 -2
  400. package/dist/subagent-execution.d.ts.map +1 -1
  401. package/dist/subagent-execution.js +2 -26
  402. package/dist/subagent-execution.js.map +1 -1
  403. package/dist/subagent-handoff.d.ts +13 -0
  404. package/dist/subagent-handoff.d.ts.map +1 -1
  405. package/dist/subagent-handoff.js +74 -9
  406. package/dist/subagent-handoff.js.map +1 -1
  407. package/dist/tool-apis.d.ts +2 -2
  408. package/dist/tool-apis.d.ts.map +1 -1
  409. package/dist/tool-apis.js +26 -14
  410. package/dist/tool-apis.js.map +1 -1
  411. package/dist/tool-execution-host.d.ts +121 -0
  412. package/dist/tool-execution-host.d.ts.map +1 -0
  413. package/dist/tool-execution-host.js +2 -0
  414. package/dist/tool-execution-host.js.map +1 -0
  415. package/dist/tool-execution.d.ts +5 -141
  416. package/dist/tool-execution.d.ts.map +1 -1
  417. package/dist/tool-execution.js +6 -395
  418. package/dist/tool-execution.js.map +1 -1
  419. package/dist/usage-reconciliation-support.d.ts +20 -0
  420. package/dist/usage-reconciliation-support.d.ts.map +1 -0
  421. package/dist/usage-reconciliation-support.js +95 -0
  422. package/dist/usage-reconciliation-support.js.map +1 -0
  423. package/dist/usage-reconciliation.d.ts +14 -35
  424. package/dist/usage-reconciliation.d.ts.map +1 -1
  425. package/dist/usage-reconciliation.js +17 -394
  426. package/dist/usage-reconciliation.js.map +1 -1
  427. package/dist/workspace-paths.d.ts +3 -0
  428. package/dist/workspace-paths.d.ts.map +1 -0
  429. package/dist/workspace-paths.js +13 -0
  430. package/dist/workspace-paths.js.map +1 -0
  431. package/dist/workspace-service.d.ts +0 -1
  432. package/dist/workspace-service.d.ts.map +1 -1
  433. package/dist/workspace-service.js +1 -4
  434. package/dist/workspace-service.js.map +1 -1
  435. package/package.json +3 -3
  436. package/dist/run-timeline.d.ts +0 -11
  437. package/dist/run-timeline.d.ts.map +0 -1
  438. package/dist/run-timeline.js +0 -2
  439. package/dist/run-timeline.js.map +0 -1
  440. package/dist/trusted-attachments.d.ts +0 -20
  441. package/dist/trusted-attachments.d.ts.map +0 -1
  442. package/dist/trusted-attachments.js +0 -276
  443. package/dist/trusted-attachments.js.map +0 -1
@@ -1,15 +1,8 @@
1
- import { runtimeToolsForSurface } from "./builtin-tools.js";
2
- import { connectionAuthorizationPrompt, parseQualifiedName, RuntimeConnectionRegistry } from "./connections.js";
3
- import { storedHarnessContinuation } from "./harness-continuation.js";
4
- import { persistConversationTranscriptImpl } from "./conversation-transcript.js";
5
- import { capabilitySystemPrompt, capabilityPromptKey, capabilityToolNames, replaceCapabilitySet } from "./harness-loop.js";
6
- import { isJsonObject, redactedToolCallRecord } from "./json-util.js";
7
- import { prepareToolModelOutput } from "./model-media.js";
8
- import { crashResumeReport } from "./run-recovery.js";
9
- import { applyCoreToolPolicy } from "./security.js";
10
- import { surfaceForRun } from "./agent-surface.js";
11
- import { runUsesChannelReplyForHumanInput } from "./human-input-routing.js";
12
- import { normalizeAgentAudience } from "./audience.js";
1
+ import { redactedToolCallRecord } from "./json-util.js";
2
+ export { completeConnectionAuthorizationCallbackImpl } from "./replay-resume-authorization.js";
3
+ export { resumeApprovalNowImpl, resumeInputNowImpl, resumeSuspendedNowImpl } from "./replay-resume-controls.js";
4
+ export { resumeHarnessLoopImpl } from "./replay-resume-harness.js";
5
+ export { resumeRunFromContinuationImpl } from "./replay-resume-recovery.js";
13
6
  export async function replayImpl(host, runId) {
14
7
  const run = await host.state.getRun(runId);
15
8
  if (!run)
@@ -23,707 +16,4 @@ export async function replayImpl(host, runId) {
23
16
  usage: await host.state.listUsage(runId)
24
17
  };
25
18
  }
26
- /** How long a claimed-but-unprogressed resume must sit before it may be reclaimed. */
27
- const RESUME_RECLAIM_STALE_MS = 5 * 60_000;
28
- /**
29
- * A resume claim was already taken, but resume claims are not leases: if the
30
- * claimer crashed between the claim and the run's status transition, the pause
31
- * would be permanently un-resumable. A run that is still parked and has not
32
- * been touched for RESUME_RECLAIM_STALE_MS has no live resumer (a live one
33
- * bumps `updatedAt` immediately and heartbeats after), so a retry generation
34
- * may be claimed. The reclaim bumps `updatedAt` first, keeping later retry
35
- * generations distinct if this one also dies.
36
- */
37
- async function reclaimStaleResume(host, run, baseKey, kind) {
38
- const inProgress = new Error(`Run ${run.id} ${kind} resume is already in progress.`);
39
- if (Date.parse(run.updatedAt) > Date.now() - RESUME_RECLAIM_STALE_MS)
40
- throw inProgress;
41
- const reclaimed = await host.state.reserveIdempotencyKey("resume", `${baseKey}:retry:${run.updatedAt}`, run.id);
42
- if (!reclaimed)
43
- throw inProgress;
44
- await host.state.updateRun(run.id, {});
45
- }
46
- export async function resumeApprovalNowImpl(host, runId) {
47
- host.boot();
48
- await host.initializeInstrumentation();
49
- let run = await host.state.getRun(runId);
50
- if (!run)
51
- throw new Error(`Run not found: ${runId}`);
52
- if (run.status !== "waiting_for_approval")
53
- throw new Error(`Run ${runId} is not waiting for approval.`);
54
- const toolCall = (await host.state.listToolCalls(runId)).find((candidate) => candidate.status === "waiting_for_approval");
55
- if (!toolCall)
56
- throw new Error(`Run ${runId} has no approval-gated tool call to resume.`);
57
- // Per-pause-generation claim: a double-clicked approval (or a concurrent
58
- // replica) must execute the gated tool exactly once. `updatedAt` changes
59
- // on every pause, so later legitimate pauses of the same tool call get a
60
- // fresh key.
61
- const resumeClaimed = await host.state.reserveIdempotencyKey("resume", `${run.id}:${toolCall.id}:${toolCall.updatedAt}`, run.id);
62
- if (!resumeClaimed) {
63
- await reclaimStaleResume(host, run, `${run.id}:${toolCall.id}:${toolCall.updatedAt}`, "approval");
64
- }
65
- if (parseQualifiedName(toolCall.toolName)) {
66
- await host.state.appendEvent(run.id, "tool.approval_resumed", { toolCallId: toolCall.id, toolName: toolCall.toolName });
67
- return resumeConnectionToolContinuation(host, run, toolCall);
68
- }
69
- const tool = runtimeToolsForSurface(surfaceForRun(host.manifest, run).tools)
70
- .find((candidate) => candidate.name === toolCall.toolName);
71
- if (!tool)
72
- throw new Error(`Tool not found: ${toolCall.toolName}`);
73
- const policyTool = applyCoreToolPolicy(tool, host.coreToolPolicy);
74
- if (!policyTool)
75
- throw new Error(`Core tool ${tool.name} is disabled by the Assembly Line core tool policy.`);
76
- let currentRun = await host.state.updateRun(run.id, { status: "running" });
77
- await host.state.appendEvent(currentRun.id, "tool.approval_resumed", { toolCallId: toolCall.id, toolName: policyTool.name });
78
- const hookController = await host.ensureAgentHookController(currentRun);
79
- const approvalCapabilities = hookController.current.declaration;
80
- let bundle = await host.buildContextBundle({
81
- message: "approval resume",
82
- channel: "local",
83
- capabilities: approvalCapabilities,
84
- run: currentRun
85
- });
86
- bundle = {
87
- ...bundle,
88
- instructions: host.resolvedInstructionsForRun(currentRun, bundle, approvalCapabilities)
89
- };
90
- const sandboxHandle = host.createSandboxHandle(() => currentRun, (nextRun) => {
91
- currentRun = nextRun;
92
- }, () => bundle);
93
- // The approved tool may run for minutes; without a heartbeat the orphan
94
- // sweep would claim this run as crashed mid-execution.
95
- const heartbeat = host.startRunHeartbeat(currentRun.id);
96
- const outcome = await host
97
- .executeToolWithRecord(currentRun, policyTool, toolCall, toolCall.input, sandboxHandle, true)
98
- .finally(() => heartbeat.stop());
99
- if (outcome.waitingForInput) {
100
- return host.result(outcome.run, "Human input required.", false, true);
101
- }
102
- // Feed the approved tool's result back into the model loop so the agent
103
- // can continue reasoning, instead of ending the run with raw tool output.
104
- const resumable = await restoreMatchingContinuation(host, run.id, toolCall.toolName);
105
- if (resumable) {
106
- const toolResult = preparedResumeToolResult(toolCall.toolName, outcome.modelOutput, host.env);
107
- return resumeHarnessLoopImpl(host, outcome.run, resumable.harness, resumable.restored, {
108
- toolResult
109
- });
110
- }
111
- // No usable continuation (pre-upgrade run or non-resumable harness):
112
- // degrade to completing with the tool output, observably.
113
- await host.state.appendEvent(run.id, "harness.resume_degraded", {
114
- reason: "approval-resume-without-continuation",
115
- toolCallId: toolCall.id,
116
- toolName: toolCall.toolName
117
- });
118
- const response = typeof outcome.modelOutput === "string" ? outcome.modelOutput : JSON.stringify(outcome.modelOutput);
119
- return host.completeRun(outcome.run, sandboxHandle, response, host.runDeliveryChannel(outcome.run));
120
- }
121
- /** Restore the latest continuation checkpoint if it matches the resolved harness. */
122
- async function restoreMatchingContinuation(host, runId, toolName) {
123
- const restored = readHarnessContinuation(undefined, await host.listHydratedCheckpoints(runId), toolName);
124
- if (!restored)
125
- return undefined;
126
- const harness = await host.resolveAgentHarness(restored.runtime.modelSpec);
127
- if (restored.continuation.harness !== harness.id || restored.continuation.version !== harness.continuationVersion) {
128
- await host.state.appendEvent(runId, "harness.continuation_mismatch", {
129
- expectedHarness: harness.id,
130
- expectedVersion: harness.continuationVersion,
131
- storedHarness: restored.continuation.harness,
132
- storedVersion: restored.continuation.version
133
- });
134
- return undefined;
135
- }
136
- return { harness, restored };
137
- }
138
- export async function completeConnectionAuthorizationCallbackImpl(host, callback) {
139
- host.boot();
140
- await host.initializeInstrumentation();
141
- await host.ensureDynamicConnections();
142
- const registry = new RuntimeConnectionRegistry({
143
- connections: host.mergedConnections(),
144
- config: host.env,
145
- credentialBroker: host.credentialBroker,
146
- fetch: host.fetch,
147
- session: { channel: "authorization" },
148
- grantStore: host.connectionGrantStore,
149
- authorizationSessionStore: host.connectionAuthorizationSessionStore,
150
- ...(host.connectionCallbackBaseUrl ? { callbackBaseUrl: host.connectionCallbackBaseUrl } : {}),
151
- loadDefinition: async (connection) => host.loadConnectionDefinition(connection)
152
- });
153
- const session = await registry.completeAuthorization(callback);
154
- if (!session.runId || !session.toolCallId) {
155
- return {
156
- status: 200,
157
- body: {
158
- ok: true,
159
- connection: session.connectionName,
160
- status: session.status
161
- }
162
- };
163
- }
164
- const run = await host.state.getRun(session.runId);
165
- if (!run)
166
- throw new Error(`Run not found for authorization callback: ${session.runId}`);
167
- const toolCall = (await host.state.listToolCalls(run.id)).find((candidate) => candidate.id === session.toolCallId);
168
- if (!toolCall)
169
- throw new Error(`Tool call not found for authorization callback: ${session.toolCallId}`);
170
- await host.state.appendEvent(run.id, "authorization.completed", {
171
- connectionName: session.connectionName,
172
- authorizationSessionId: session.id,
173
- toolCallId: toolCall.id
174
- });
175
- if (runUsesChannelReplyForHumanInput(run)) {
176
- if (run.status === "running" || run.status === "created") {
177
- await host.state.appendEvent(run.id, "authorization.available_to_active_run", {
178
- connectionName: session.connectionName,
179
- authorizationSessionId: session.id,
180
- toolCallId: toolCall.id
181
- });
182
- return {
183
- status: 200,
184
- body: {
185
- ok: true,
186
- connection: session.connectionName,
187
- runId: run.id,
188
- runStatus: run.status,
189
- continuation: "active_run"
190
- }
191
- };
192
- }
193
- if (run.status !== "completed" && run.status !== "waiting_for_connection") {
194
- return {
195
- status: 200,
196
- body: {
197
- ok: true,
198
- connection: session.connectionName,
199
- runId: run.id,
200
- runStatus: run.status,
201
- continuation: "not_resumed"
202
- }
203
- };
204
- }
205
- const turn = authorizationContinuationTurn(run, session);
206
- if (!turn) {
207
- return {
208
- status: 200,
209
- body: {
210
- ok: true,
211
- connection: session.connectionName,
212
- runId: run.id,
213
- runStatus: run.status,
214
- continuation: "unavailable"
215
- }
216
- };
217
- }
218
- const queued = await host.enqueueConversationTurn({
219
- turn,
220
- idempotencyScope: "connection:authorization-continuation",
221
- idempotencyKey: session.id
222
- });
223
- let detachedRun = run;
224
- if (run.status === "waiting_for_connection") {
225
- detachedRun = await host.state.updateRun(run.id, { status: "completed" });
226
- await host.state.appendEvent(run.id, "run.completed", {
227
- response: "",
228
- detachedAuthorization: true
229
- });
230
- }
231
- await host.state.appendEvent(run.id, "authorization.continuation_queued", {
232
- connectionName: session.connectionName,
233
- authorizationSessionId: session.id,
234
- toolCallId: toolCall.id,
235
- inserted: queued.inserted
236
- });
237
- return {
238
- status: 202,
239
- body: {
240
- ok: true,
241
- connection: session.connectionName,
242
- runId: detachedRun.id,
243
- runStatus: detachedRun.status,
244
- continuation: queued.inserted ? "queued" : "already_queued"
245
- }
246
- };
247
- }
248
- // Protocol-owned waits resume in place. Claim this pause generation before
249
- // executing the gated tool so replayed callbacks cannot repeat side effects.
250
- const resumeClaimed = await host.state.reserveIdempotencyKey("resume", `${run.id}:${toolCall.id}:${toolCall.updatedAt}`, run.id);
251
- if (!resumeClaimed) {
252
- return {
253
- status: 200,
254
- body: {
255
- ok: true,
256
- connection: session.connectionName,
257
- runId: run.id,
258
- runStatus: run.status,
259
- response: "Authorization already processed."
260
- }
261
- };
262
- }
263
- const runResult = await host.withRunAdmission(() => resumeConnectionToolContinuation(host, run, toolCall, session));
264
- return {
265
- status: 200,
266
- body: {
267
- ok: true,
268
- connection: session.connectionName,
269
- runId: runResult.run.id,
270
- runStatus: runResult.run.status,
271
- response: runResult.response ?? ""
272
- },
273
- runResult
274
- };
275
- }
276
- function authorizationContinuationTurn(run, session) {
277
- const channel = typeof run.input.channel === "string" ? run.input.channel : undefined;
278
- const conversationId = typeof run.input.conversationId === "string" ? run.input.conversationId : undefined;
279
- if (!channel || !conversationId)
280
- return undefined;
281
- const turn = {
282
- eventId: `connection-authorization:${run.id}:${session.toolCallId ?? session.connectionName}`,
283
- channel,
284
- conversationId,
285
- message: [
286
- `Authorization for ${session.connectionName} completed.`,
287
- `Continue the prior user request from conversation history and retry ${session.toolName ?? "the connection operation"} if it is still appropriate.`,
288
- "Do not repeat side effects that already completed."
289
- ].join(" ")
290
- };
291
- if (typeof run.input.userId === "string")
292
- turn.userId = run.input.userId;
293
- if (isJsonObject(run.input.principal))
294
- turn.principal = run.input.principal;
295
- if (isJsonObject(run.input.initiator))
296
- turn.initiator = run.input.initiator;
297
- const audience = normalizeAgentAudience(run.input.audience);
298
- if (audience)
299
- turn.audience = audience;
300
- if (isJsonObject(run.input.delivery))
301
- turn.delivery = run.input.delivery;
302
- turn.metadata = {
303
- ...(isJsonObject(run.input.metadata) ? run.input.metadata : {}),
304
- assemblyLine: {
305
- kind: "connection_authorization_continuation",
306
- sourceRunId: run.id,
307
- connectionName: session.connectionName
308
- }
309
- };
310
- return turn;
311
- }
312
- export async function resumeInputNowImpl(host, runId, answer) {
313
- host.boot();
314
- await host.initializeInstrumentation();
315
- const run = await host.state.getRun(runId);
316
- if (!run)
317
- throw new Error(`Run not found: ${runId}`);
318
- if (run.status !== "waiting_for_input")
319
- throw new Error(`Run ${runId} is not waiting for input.`);
320
- // The pending question is the tool call parked by HumanInputRequired.
321
- const toolCall = (await host.state.listToolCalls(runId)).find((candidate) => candidate.status === "waiting_for_approval");
322
- // Per-pause-generation claim so a double-submitted answer resumes once.
323
- const resumeClaimed = await host.state.reserveIdempotencyKey("resume", toolCall ? `${run.id}:${toolCall.id}:${toolCall.updatedAt}` : `${run.id}:input:${run.updatedAt}`, run.id);
324
- if (!resumeClaimed) {
325
- await reclaimStaleResume(host, run, toolCall ? `${run.id}:${toolCall.id}:${toolCall.updatedAt}` : `${run.id}:input:${run.updatedAt}`, "input");
326
- }
327
- let running = await host.state.updateRun(run.id, { status: "running" });
328
- await host.state.appendEvent(run.id, "human_input.received", { answer });
329
- if (toolCall) {
330
- await host.state.updateToolCall(toolCall.id, {
331
- status: "completed",
332
- result: { answer },
333
- modelOutput: { answer }
334
- });
335
- }
336
- // Feed the human's answer back into the model loop as the pending tool's
337
- // result so the agent that asked actually sees it and continues.
338
- const toolName = toolCall?.toolName ?? "human_input";
339
- const resumable = await restoreMatchingContinuation(host, run.id, toolName);
340
- if (resumable) {
341
- return resumeHarnessLoopImpl(host, running, resumable.harness, resumable.restored, {
342
- toolResult: { toolName, output: { answer } }
343
- });
344
- }
345
- await host.state.appendEvent(run.id, "harness.resume_degraded", {
346
- reason: "input-resume-without-continuation",
347
- toolCallId: toolCall?.id ?? null,
348
- toolName
349
- });
350
- const hookController = await host.ensureAgentHookController(running);
351
- const inputCapabilities = hookController.current.declaration;
352
- let bundle = await host.buildContextBundle({
353
- message: answer,
354
- channel: "local",
355
- capabilities: inputCapabilities,
356
- run: running
357
- });
358
- bundle = {
359
- ...bundle,
360
- instructions: host.resolvedInstructionsForRun(running, bundle, inputCapabilities)
361
- };
362
- const sandboxHandle = host.createSandboxHandle(() => running, (nextRun) => {
363
- running = nextRun;
364
- }, () => bundle);
365
- return host.completeRun(running, sandboxHandle, `Received input: ${answer}`, host.runDeliveryChannel(running));
366
- }
367
- export async function resumeSuspendedNowImpl(host, runId) {
368
- host.boot();
369
- await host.initializeInstrumentation();
370
- await host.ensureDynamicConnections();
371
- const run = await host.state.getRun(runId);
372
- if (!run)
373
- throw new Error(`Run not found: ${runId}`);
374
- if (run.status !== "suspended")
375
- throw new Error(`Run ${runId} is not suspended.`);
376
- const resumeClaimed = await host.state.reserveIdempotencyKey("resume:suspended", `${run.id}:${run.updatedAt}`, run.id);
377
- if (!resumeClaimed)
378
- throw new Error(`Run ${runId} suspended resume is already in progress.`);
379
- const restored = readHarnessContinuation(undefined, await host.listHydratedCheckpoints(runId));
380
- if (!restored)
381
- throw new Error(`Run ${runId} has no harness continuation to resume.`);
382
- const harness = await host.resolveAgentHarness(restored.runtime.modelSpec);
383
- if (restored.continuation.harness !== harness.id || restored.continuation.version !== harness.continuationVersion) {
384
- await host.state.appendEvent(run.id, "harness.continuation_mismatch", {
385
- expectedHarness: harness.id,
386
- expectedVersion: harness.continuationVersion,
387
- storedHarness: restored.continuation.harness,
388
- storedVersion: restored.continuation.version
389
- });
390
- throw new Error(`Run ${runId} harness continuation is incompatible with the configured harness.`);
391
- }
392
- const running = await host.state.updateRun(run.id, { status: "running" });
393
- await host.state.appendEvent(run.id, "run.resumed", { from: "suspended" });
394
- return resumeHarnessLoopImpl(host, running, harness, restored, {});
395
- }
396
- async function resumeConnectionToolContinuation(host, run, toolCall, authorizationSession) {
397
- const running = await host.state.updateRun(run.id, { status: "running" });
398
- const hookController = await host.ensureAgentHookController(running);
399
- const capabilities = hookController.current.declaration;
400
- const fallbackChannel = typeof run.input.channel === "string" ? run.input.channel : "local";
401
- const parsed = parseQualifiedName(toolCall.toolName);
402
- if (parsed && !capabilities.connections.includes(parsed.connectionName)) {
403
- throw new Error(`Connection ${parsed.connectionName} is no longer active on the current agent surface.`);
404
- }
405
- const sandboxCli = parsed
406
- ? host.mergedConnections().find((connection) => connection.name === parsed.connectionName)?.protocol === "cli"
407
- : false;
408
- let sandboxRun = running;
409
- let sandboxHandle;
410
- if (sandboxCli) {
411
- const bundle = await host.buildContextBundle({
412
- message: "connection approval resume",
413
- channel: fallbackChannel,
414
- capabilities,
415
- run: sandboxRun
416
- });
417
- sandboxHandle = host.createSandboxHandle(() => sandboxRun, (nextRun) => {
418
- sandboxRun = nextRun;
419
- }, () => bundle);
420
- }
421
- const registry = sandboxHandle
422
- ? host.createConnectionRegistryForRun(running, fallbackChannel, sandboxHandle, new Set(capabilities.connections))
423
- : authorizationSession
424
- ? host.createConnectionRegistryForSession(authorizationSession)
425
- : host.createConnectionRegistry(fallbackChannel);
426
- // The resumed connection tool may run for minutes; without a heartbeat the
427
- // orphan sweep would claim this run as crashed mid-execution.
428
- const heartbeat = host.startRunHeartbeat(running.id);
429
- const outcome = await host
430
- .executeConnectionToolWithRecord(running, registry, toolCall.toolName, toolCall, toolCall.input)
431
- .finally(() => heartbeat.stop());
432
- sandboxRun = outcome.run;
433
- if (outcome.waitingForConnection) {
434
- await sandboxHandle?.dispose();
435
- return host.result(outcome.run, await connectionAuthorizationPrompt(host.connectionAuthorizationSessionStore, outcome.authorizationSessionId, ""), false, false, true);
436
- }
437
- let restored = readHarnessContinuation(authorizationSession?.continuation, await host.listHydratedCheckpoints(run.id), toolCall.toolName);
438
- const harness = await host.resolveAgentHarness(restored?.runtime.modelSpec);
439
- if (restored && (restored.continuation.harness !== harness.id || restored.continuation.version !== harness.continuationVersion)) {
440
- await host.state.appendEvent(run.id, "harness.continuation_mismatch", {
441
- expectedHarness: harness.id,
442
- expectedVersion: harness.continuationVersion,
443
- storedHarness: restored.continuation.harness,
444
- storedVersion: restored.continuation.version
445
- });
446
- restored = undefined;
447
- }
448
- if (!restored) {
449
- const response = typeof outcome.modelOutput === "string" ? outcome.modelOutput : JSON.stringify(outcome.modelOutput ?? {});
450
- if (sandboxHandle) {
451
- return host.completeRun(sandboxRun, sandboxHandle, response, host.runDeliveryChannel(sandboxRun));
452
- }
453
- let fallbackRun = outcome.run;
454
- const bundle = await host.buildContextBundle({
455
- message: "connection resume",
456
- channel: "local",
457
- capabilities,
458
- run: fallbackRun
459
- });
460
- const fallbackSandboxHandle = host.createSandboxHandle(() => fallbackRun, (nextRun) => {
461
- fallbackRun = nextRun;
462
- }, () => bundle);
463
- return host.completeRun(fallbackRun, fallbackSandboxHandle, response, host.runDeliveryChannel(fallbackRun));
464
- }
465
- const toolResult = preparedResumeToolResult(toolCall.toolName, outcome.modelOutput, host.env);
466
- await sandboxHandle?.dispose();
467
- return resumeHarnessLoopImpl(host, outcome.run, harness, restored, { toolResult });
468
- }
469
- /** Resume an orphaned run in place from its latest persisted continuation checkpoint. */
470
- export async function resumeRunFromContinuationImpl(host, run, context) {
471
- const checkpoints = await host.listHydratedCheckpoints(run.id);
472
- let restored;
473
- let checkpointCreatedAt;
474
- for (let index = checkpoints.length - 1; index >= 0 && !restored; index -= 1) {
475
- const checkpoint = checkpoints[index];
476
- if (!checkpoint || checkpoint.name !== "harness.continuation")
477
- continue;
478
- restored = storedHarnessContinuation(checkpoint.data);
479
- if (restored)
480
- checkpointCreatedAt = checkpoint.createdAt;
481
- }
482
- if (!restored)
483
- return undefined;
484
- const harness = await host.resolveAgentHarness(restored.runtime.modelSpec);
485
- if (restored.continuation.harness !== harness.id || restored.continuation.version !== harness.continuationVersion) {
486
- await host.state.appendEvent(run.id, "harness.continuation_mismatch", {
487
- expectedHarness: harness.id,
488
- expectedVersion: harness.continuationVersion,
489
- storedHarness: restored.continuation.harness,
490
- storedVersion: restored.continuation.version
491
- });
492
- return undefined;
493
- }
494
- await host.state.appendEvent(run.id, "run.recovery_resume_attempted", { harness: harness.id });
495
- const running = await host.state.updateRun(run.id, { status: "running" });
496
- // If the continuation is parked on a tool that was mid-execution at crash
497
- // time, resume with an explicit interrupted result so the model knows the
498
- // side effects are indeterminate instead of silently re-requesting the
499
- // tool. Otherwise resume from the iteration boundary as-is.
500
- const pendingToolName = restored.runtime.pendingToolName;
501
- const interrupted = context?.interruptedTools?.find((tool) => tool.toolName === pendingToolName);
502
- const resume = interrupted
503
- ? {
504
- toolResult: {
505
- toolName: interrupted.toolName,
506
- output: {
507
- interrupted: true,
508
- error: "This tool execution was interrupted by a runtime restart; its side effects may or may not have happened. Verify before re-running side-effecting operations."
509
- }
510
- }
511
- }
512
- : {};
513
- // Crash mid-tool-batch: the restored checkpoint predates the batch's tool
514
- // calls, so surface their durable outcomes as a follow-up message rather
515
- // than letting the model silently re-execute completed side effects.
516
- // (The pause path above splices the pending tool directly and needs no report.)
517
- if (!interrupted) {
518
- const report = crashResumeReport(await host.state.listToolCalls(run.id), checkpointCreatedAt, context?.interruptedTools ?? []);
519
- if (report)
520
- resume.message = report;
521
- }
522
- try {
523
- const result = await resumeHarnessLoopImpl(host, running, harness, restored, resume);
524
- return result.run;
525
- }
526
- catch (error) {
527
- // A continuation parked on a completed assistant turn (or empty context)
528
- // has nothing to resume; the harness signals this by refusing to continue.
529
- // That is not a resume failure — it means the run already produced its
530
- // final response — so degrade to "no usable continuation" and let recovery
531
- // deliver the completed response instead of logging a spurious failure.
532
- const message = error instanceof Error ? error.message : String(error);
533
- if (/continue from message role/iu.test(message) || /no messages in context/iu.test(message)) {
534
- await host.state.appendEvent(run.id, "run.recovery_resume_unavailable", { reason: message });
535
- return undefined;
536
- }
537
- throw error;
538
- }
539
- }
540
- export async function resumeHarnessLoopImpl(host, run, harness, restored, resume) {
541
- let currentRun = run;
542
- const controller = await host.ensureAgentHookController(currentRun);
543
- let appliedSnapshotId = controller.current.id;
544
- const capabilities = controller.current.declaration;
545
- let appliedPromptKey = capabilityPromptKey(capabilities);
546
- harness = await host.resolveAgentHarness(capabilities.model);
547
- if (restored.continuation.harness !== harness.id || restored.continuation.version !== harness.continuationVersion) {
548
- throw new Error(`Recovered capabilities select harness "${harness.id}" v${harness.continuationVersion}, which cannot read the stored ${restored.continuation.harness} v${restored.continuation.version} continuation.`);
549
- }
550
- const activeSkills = new Set(capabilities.skills);
551
- const rootSurface = currentRun.input.agentSurface === "root";
552
- const defaultToolNames = new Set(capabilityToolNames(capabilities, rootSurface));
553
- const discoveredConnectionTools = new Map();
554
- let pause;
555
- let bundle = await host.buildContextBundle({
556
- message: "harness resume",
557
- channel: restored.runtime.channel,
558
- capabilities,
559
- run: currentRun
560
- });
561
- bundle = {
562
- ...bundle,
563
- instructions: host.resolvedInstructionsForRun(currentRun, bundle, capabilities)
564
- };
565
- const sandboxHandle = host.createSandboxHandle(() => currentRun, (nextRun) => {
566
- currentRun = nextRun;
567
- }, () => bundle);
568
- const connectionRegistry = host.createConnectionRegistryForRun(run, restored.runtime.channel, sandboxHandle, new Set(capabilities.connections));
569
- const session = {
570
- modelSpec: capabilities.model,
571
- reasoning: capabilities.reasoning,
572
- systemPrompt: capabilitySystemPrompt(bundle, capabilities.outputSchema, ""),
573
- outputSchema: capabilities.outputSchema,
574
- maxIterations: restored.runtime.maxIterations,
575
- sessionId: restored.runtime.sessionId,
576
- channel: restored.runtime.channel,
577
- activeSkills,
578
- defaultToolNames,
579
- discoveredConnectionTools
580
- };
581
- if (restored.runtime.conversationId)
582
- session.conversationId = restored.runtime.conversationId;
583
- const loopState = {
584
- run: () => currentRun,
585
- setRun: (nextRun) => {
586
- currentRun = nextRun;
587
- },
588
- sandboxHandle,
589
- activeSkills,
590
- defaultToolNames,
591
- connectionRegistry,
592
- discoveredConnectionTools,
593
- exposedDeferredToolNames: new Set(),
594
- setPause: (nextPause) => {
595
- // First pause wins: in a tool batch where several calls pause, the
596
- // run parks on the first one and later pauses must not repoint the
597
- // resume bookkeeping mid-flight.
598
- pause ??= nextPause;
599
- }
600
- };
601
- const refreshCapabilities = async () => {
602
- const snapshot = await controller.refreshIfDirty();
603
- if (snapshot.id !== appliedSnapshotId) {
604
- const nextSandbox = snapshot.declaration.sandbox ?? null;
605
- const sandboxChanged = (currentRun.input.agentSandbox ?? null) !== nextSandbox;
606
- if (sandboxChanged)
607
- await sandboxHandle.reset();
608
- currentRun = await host.state.updateRun(currentRun.id, {
609
- input: {
610
- ...currentRun.input,
611
- model: snapshot.declaration.model,
612
- agentSandbox: nextSandbox,
613
- agentConnections: snapshot.declaration.connections,
614
- agentSubagents: snapshot.declaration.subagents
615
- }
616
- });
617
- loopState.setRun(currentRun);
618
- const nextPromptKey = capabilityPromptKey(snapshot.declaration);
619
- const promptChanged = nextPromptKey !== appliedPromptKey;
620
- if (promptChanged) {
621
- bundle = await host.buildContextBundle({
622
- message: "harness resume",
623
- channel: restored.runtime.channel,
624
- capabilities: snapshot.declaration,
625
- run: currentRun
626
- });
627
- bundle = {
628
- ...bundle,
629
- instructions: host.resolvedInstructionsForRun(currentRun, bundle, snapshot.declaration)
630
- };
631
- appliedPromptKey = nextPromptKey;
632
- }
633
- appliedSnapshotId = snapshot.id;
634
- replaceCapabilitySet(activeSkills, snapshot.declaration.skills);
635
- replaceCapabilitySet(defaultToolNames, capabilityToolNames(snapshot.declaration, rootSurface));
636
- loopState.connectionRegistry = host.createConnectionRegistryForRun(currentRun, restored.runtime.channel, sandboxHandle, new Set(snapshot.declaration.connections));
637
- discoveredConnectionTools.clear();
638
- loopState.exposedDeferredToolNames.clear();
639
- session.modelSpec = snapshot.declaration.model;
640
- session.reasoning = snapshot.declaration.reasoning;
641
- session.outputSchema = snapshot.declaration.outputSchema;
642
- if (promptChanged) {
643
- session.systemPrompt = capabilitySystemPrompt(bundle, snapshot.declaration.outputSchema, "");
644
- }
645
- }
646
- return {
647
- modelSpec: session.modelSpec,
648
- systemPrompt: session.systemPrompt,
649
- ...(session.reasoning !== undefined ? { reasoning: session.reasoning } : {}),
650
- ...(session.outputSchema !== undefined ? { outputSchema: session.outputSchema } : {})
651
- };
652
- };
653
- const heartbeat = host.startRunHeartbeat(run.id);
654
- let policy;
655
- try {
656
- policy = await host.executeHarnessTurn(harness, {
657
- kind: "resume",
658
- continuation: restored.continuation,
659
- ...(resume.toolResult ? { toolResult: resume.toolResult } : {}),
660
- ...(resume.message !== undefined ? { message: resume.message } : {})
661
- }, session, loopState, true, refreshCapabilities);
662
- }
663
- finally {
664
- heartbeat.stop();
665
- }
666
- const result = policy.result;
667
- if (pause) {
668
- await host.persistHarnessContinuation(pause.run.id, session, result.continuation, pause);
669
- return host.result(pause.run, result.response, pause.waitingForApproval, pause.waitingForInput, pause.waitingForConnection);
670
- }
671
- if (policy.failed || policy.controlStopped) {
672
- await sandboxHandle.dispose();
673
- return host.result(currentRun, result.response, false, false, false);
674
- }
675
- const completed = await host.completeRun(currentRun, sandboxHandle, result.response, restored.runtime.channel, undefined, restored.runtime.conversationId);
676
- if (policy.output !== undefined)
677
- completed.output = policy.output;
678
- // Keep the conversation's transcript pointer current: a paused turn that
679
- // completed here would otherwise leave the pointer at the pre-pause run and
680
- // the next conversation turn would resume a transcript missing this one.
681
- if (restored.runtime.conversationId && result.continuation && !policy.failed && !policy.controlStopped) {
682
- try {
683
- await persistConversationTranscriptImpl({
684
- state: host.state,
685
- createCheckpoint: (input) => host.createCheckpoint(input),
686
- hydrateCheckpointData: (data) => host.hydrateCheckpointData(data)
687
- }, {
688
- runId: run.id,
689
- conversationId: restored.runtime.conversationId,
690
- session,
691
- continuation: result.continuation,
692
- ...(session.lastInputTokens !== undefined ? { lastInputTokens: session.lastInputTokens } : {})
693
- });
694
- }
695
- catch {
696
- // Best-effort acceleration layer; the durable history is unaffected.
697
- }
698
- }
699
- return completed;
700
- }
701
- function preparedResumeToolResult(toolName, output, env) {
702
- const prepared = prepareToolModelOutput(output, env);
703
- const result = {
704
- toolName,
705
- output: prepared.output
706
- };
707
- if (prepared.media.length > 0)
708
- result.media = prepared.media;
709
- return result;
710
- }
711
- function readHarnessContinuation(stored, checkpoints, toolName) {
712
- if (stored)
713
- return storedHarnessContinuation(stored);
714
- for (let index = checkpoints.length - 1; index >= 0; index -= 1) {
715
- const checkpoint = checkpoints[index];
716
- if (!checkpoint)
717
- continue;
718
- if (checkpoint.name !== "harness.continuation")
719
- continue;
720
- const restored = storedHarnessContinuation(checkpoint.data);
721
- if (!restored)
722
- continue;
723
- const pendingToolName = restored.runtime.pendingToolName;
724
- if (toolName === undefined || typeof pendingToolName !== "string" || pendingToolName === toolName)
725
- return restored;
726
- }
727
- return undefined;
728
- }
729
19
  //# sourceMappingURL=replay-resume.js.map