@namzu/sdk 30.2.0 → 31.1.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 (718) hide show
  1. package/CHANGELOG.md +562 -0
  2. package/README.md +43 -2
  3. package/dist/advisory/executor.d.ts +2 -1
  4. package/dist/advisory/executor.d.ts.map +1 -1
  5. package/dist/advisory/executor.js +4 -1
  6. package/dist/advisory/executor.js.map +1 -1
  7. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  8. package/dist/agents/ReactiveAgent.js +12 -0
  9. package/dist/agents/ReactiveAgent.js.map +1 -1
  10. package/dist/agents/RouterAgent.d.ts.map +1 -1
  11. package/dist/agents/RouterAgent.js +21 -3
  12. package/dist/agents/RouterAgent.js.map +1 -1
  13. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  14. package/dist/agents/SupervisorAgent.js +34 -11
  15. package/dist/agents/SupervisorAgent.js.map +1 -1
  16. package/dist/agents/runAgent.d.ts +12 -0
  17. package/dist/agents/runAgent.d.ts.map +1 -1
  18. package/dist/agents/runAgent.js +26 -2
  19. package/dist/agents/runAgent.js.map +1 -1
  20. package/dist/authorization/command-line.d.ts +81 -0
  21. package/dist/authorization/command-line.d.ts.map +1 -0
  22. package/dist/authorization/command-line.js +347 -0
  23. package/dist/authorization/command-line.js.map +1 -0
  24. package/dist/authorization/rules.d.ts.map +1 -1
  25. package/dist/authorization/rules.js +22 -1
  26. package/dist/authorization/rules.js.map +1 -1
  27. package/dist/bridge/a2a/client.d.ts +23 -5
  28. package/dist/bridge/a2a/client.d.ts.map +1 -1
  29. package/dist/bridge/a2a/client.js +320 -73
  30. package/dist/bridge/a2a/client.js.map +1 -1
  31. package/dist/bridge/a2a/mapper.d.ts.map +1 -1
  32. package/dist/bridge/a2a/mapper.js +4 -0
  33. package/dist/bridge/a2a/mapper.js.map +1 -1
  34. package/dist/bridge/acp/server.d.ts +13 -1
  35. package/dist/bridge/acp/server.d.ts.map +1 -1
  36. package/dist/bridge/acp/server.js +150 -44
  37. package/dist/bridge/acp/server.js.map +1 -1
  38. package/dist/bridge/mcp/connector/adapter.d.ts +3 -2
  39. package/dist/bridge/mcp/connector/adapter.d.ts.map +1 -1
  40. package/dist/bridge/mcp/connector/adapter.js +17 -21
  41. package/dist/bridge/mcp/connector/adapter.js.map +1 -1
  42. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  43. package/dist/bridge/sse/mapper.js +3 -0
  44. package/dist/bridge/sse/mapper.js.map +1 -1
  45. package/dist/compaction/dangling.d.ts +29 -2
  46. package/dist/compaction/dangling.d.ts.map +1 -1
  47. package/dist/compaction/dangling.js +172 -35
  48. package/dist/compaction/dangling.js.map +1 -1
  49. package/dist/compaction/index.d.ts +3 -2
  50. package/dist/compaction/index.d.ts.map +1 -1
  51. package/dist/compaction/index.js +1 -1
  52. package/dist/compaction/index.js.map +1 -1
  53. package/dist/compaction/manual.d.ts +11 -1
  54. package/dist/compaction/manual.d.ts.map +1 -1
  55. package/dist/compaction/manual.js +89 -14
  56. package/dist/compaction/manual.js.map +1 -1
  57. package/dist/compaction/plan.d.ts +19 -6
  58. package/dist/compaction/plan.d.ts.map +1 -1
  59. package/dist/compaction/plan.js +18 -4
  60. package/dist/compaction/plan.js.map +1 -1
  61. package/dist/compaction/retention.d.ts +10 -7
  62. package/dist/compaction/retention.d.ts.map +1 -1
  63. package/dist/compaction/retention.js +26 -8
  64. package/dist/compaction/retention.js.map +1 -1
  65. package/dist/compaction/summary.d.ts +4 -4
  66. package/dist/compaction/summary.js +4 -4
  67. package/dist/compaction/verifier.d.ts +19 -1
  68. package/dist/compaction/verifier.d.ts.map +1 -1
  69. package/dist/compaction/verifier.js +20 -1
  70. package/dist/compaction/verifier.js.map +1 -1
  71. package/dist/config/runtime.d.ts +6 -6
  72. package/dist/connector/BaseConnector.d.ts +6 -4
  73. package/dist/connector/BaseConnector.d.ts.map +1 -1
  74. package/dist/connector/BaseConnector.js +8 -2
  75. package/dist/connector/BaseConnector.js.map +1 -1
  76. package/dist/connector/builtins/http.d.ts +16 -4
  77. package/dist/connector/builtins/http.d.ts.map +1 -1
  78. package/dist/connector/builtins/http.js +177 -44
  79. package/dist/connector/builtins/http.js.map +1 -1
  80. package/dist/connector/builtins/webhook.d.ts +15 -4
  81. package/dist/connector/builtins/webhook.d.ts.map +1 -1
  82. package/dist/connector/builtins/webhook.js +165 -45
  83. package/dist/connector/builtins/webhook.js.map +1 -1
  84. package/dist/connector/execution-contract.d.ts +11 -0
  85. package/dist/connector/execution-contract.d.ts.map +1 -0
  86. package/dist/connector/execution-contract.js +14 -0
  87. package/dist/connector/execution-contract.js.map +1 -0
  88. package/dist/connector/http-operation.d.ts +48 -0
  89. package/dist/connector/http-operation.d.ts.map +1 -0
  90. package/dist/connector/http-operation.js +205 -0
  91. package/dist/connector/http-operation.js.map +1 -0
  92. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  93. package/dist/connector/mcp/adapter.js +8 -3
  94. package/dist/connector/mcp/adapter.js.map +1 -1
  95. package/dist/connector/mcp/client.d.ts +14 -8
  96. package/dist/connector/mcp/client.d.ts.map +1 -1
  97. package/dist/connector/mcp/client.js +160 -44
  98. package/dist/connector/mcp/client.js.map +1 -1
  99. package/dist/connector/mcp/http-sse.d.ts +8 -2
  100. package/dist/connector/mcp/http-sse.d.ts.map +1 -1
  101. package/dist/connector/mcp/http-sse.js +70 -17
  102. package/dist/connector/mcp/http-sse.js.map +1 -1
  103. package/dist/connector/mcp/prompt-adapter.d.ts.map +1 -1
  104. package/dist/connector/mcp/prompt-adapter.js +9 -2
  105. package/dist/connector/mcp/prompt-adapter.js.map +1 -1
  106. package/dist/connector/mcp/stdio.d.ts +2 -2
  107. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  108. package/dist/connector/mcp/stdio.js +14 -50
  109. package/dist/connector/mcp/stdio.js.map +1 -1
  110. package/dist/connector/mcp/streamable-http.d.ts +7 -2
  111. package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
  112. package/dist/connector/mcp/streamable-http.js +66 -18
  113. package/dist/connector/mcp/streamable-http.js.map +1 -1
  114. package/dist/connector/tools/adapter.d.ts +2 -2
  115. package/dist/connector/tools/adapter.d.ts.map +1 -1
  116. package/dist/connector/tools/adapter.js +23 -14
  117. package/dist/connector/tools/adapter.js.map +1 -1
  118. package/dist/connector/tools/definitions.d.ts.map +1 -1
  119. package/dist/connector/tools/definitions.js +5 -2
  120. package/dist/connector/tools/definitions.js.map +1 -1
  121. package/dist/connector/tools/result.d.ts +4 -0
  122. package/dist/connector/tools/result.d.ts.map +1 -0
  123. package/dist/connector/tools/result.js +20 -0
  124. package/dist/connector/tools/result.js.map +1 -0
  125. package/dist/connector/web/guarded-fetch.d.ts +4 -2
  126. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  127. package/dist/connector/web/guarded-fetch.js +157 -43
  128. package/dist/connector/web/guarded-fetch.js.map +1 -1
  129. package/dist/constants/sandbox/index.d.ts +3 -2
  130. package/dist/constants/sandbox/index.d.ts.map +1 -1
  131. package/dist/constants/sandbox/index.js +3 -2
  132. package/dist/constants/sandbox/index.js.map +1 -1
  133. package/dist/contracts/api.d.ts +2 -0
  134. package/dist/contracts/api.d.ts.map +1 -1
  135. package/dist/contracts/schemas.d.ts +38 -12
  136. package/dist/contracts/schemas.d.ts.map +1 -1
  137. package/dist/contracts/schemas.js +7 -0
  138. package/dist/contracts/schemas.js.map +1 -1
  139. package/dist/directory/derive-supervisor.d.ts.map +1 -1
  140. package/dist/directory/derive-supervisor.js +8 -0
  141. package/dist/directory/derive-supervisor.js.map +1 -1
  142. package/dist/directory/derive.d.ts.map +1 -1
  143. package/dist/directory/derive.js +8 -0
  144. package/dist/directory/derive.js.map +1 -1
  145. package/dist/directory/load.d.ts.map +1 -1
  146. package/dist/directory/load.js +2 -0
  147. package/dist/directory/load.js.map +1 -1
  148. package/dist/directory/types.d.ts +4 -0
  149. package/dist/directory/types.d.ts.map +1 -1
  150. package/dist/eval/experiment.d.ts +10 -10
  151. package/dist/eval/experiment.d.ts.map +1 -1
  152. package/dist/eval/experiment.js +121 -91
  153. package/dist/eval/experiment.js.map +1 -1
  154. package/dist/eval/judge.d.ts +6 -0
  155. package/dist/eval/judge.d.ts.map +1 -1
  156. package/dist/eval/judge.js +7 -2
  157. package/dist/eval/judge.js.map +1 -1
  158. package/dist/eval/types.d.ts +7 -1
  159. package/dist/eval/types.d.ts.map +1 -1
  160. package/dist/manager/agent/lifecycle.d.ts +12 -10
  161. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  162. package/dist/manager/agent/lifecycle.js +16 -3
  163. package/dist/manager/agent/lifecycle.js.map +1 -1
  164. package/dist/manager/connector/environment.d.ts +2 -2
  165. package/dist/manager/connector/environment.d.ts.map +1 -1
  166. package/dist/manager/connector/environment.js +2 -2
  167. package/dist/manager/connector/environment.js.map +1 -1
  168. package/dist/manager/connector/lifecycle.d.ts +10 -2
  169. package/dist/manager/connector/lifecycle.d.ts.map +1 -1
  170. package/dist/manager/connector/lifecycle.js +273 -24
  171. package/dist/manager/connector/lifecycle.js.map +1 -1
  172. package/dist/manager/connector/tenant.d.ts +5 -4
  173. package/dist/manager/connector/tenant.d.ts.map +1 -1
  174. package/dist/manager/connector/tenant.js +47 -22
  175. package/dist/manager/connector/tenant.js.map +1 -1
  176. package/dist/manager/goal/activation.d.ts +23 -0
  177. package/dist/manager/goal/activation.d.ts.map +1 -0
  178. package/dist/manager/goal/activation.js +41 -0
  179. package/dist/manager/goal/activation.js.map +1 -0
  180. package/dist/manager/index.d.ts +3 -2
  181. package/dist/manager/index.d.ts.map +1 -1
  182. package/dist/manager/index.js.map +1 -1
  183. package/dist/manager/run/persistence.d.ts +2 -0
  184. package/dist/manager/run/persistence.d.ts.map +1 -1
  185. package/dist/manager/run/persistence.js +5 -1
  186. package/dist/manager/run/persistence.js.map +1 -1
  187. package/dist/manager/topic/dependency.d.ts +24 -0
  188. package/dist/manager/topic/dependency.d.ts.map +1 -0
  189. package/dist/manager/topic/dependency.js +13 -0
  190. package/dist/manager/topic/dependency.js.map +1 -0
  191. package/dist/manager/topic/lifecycle.d.ts +9 -21
  192. package/dist/manager/topic/lifecycle.d.ts.map +1 -1
  193. package/dist/manager/topic/lifecycle.js +17 -29
  194. package/dist/manager/topic/lifecycle.js.map +1 -1
  195. package/dist/plugin/index.d.ts +1 -0
  196. package/dist/plugin/index.d.ts.map +1 -1
  197. package/dist/plugin/index.js.map +1 -1
  198. package/dist/plugin/lifecycle.d.ts +15 -0
  199. package/dist/plugin/lifecycle.d.ts.map +1 -1
  200. package/dist/plugin/lifecycle.js +144 -38
  201. package/dist/plugin/lifecycle.js.map +1 -1
  202. package/dist/plugin/loader.d.ts +3 -3
  203. package/dist/plugin/loader.d.ts.map +1 -1
  204. package/dist/plugin/loader.js +58 -12
  205. package/dist/plugin/loader.js.map +1 -1
  206. package/dist/provider/collect-chat-completion.d.ts.map +1 -1
  207. package/dist/provider/collect-chat-completion.js +4 -0
  208. package/dist/provider/collect-chat-completion.js.map +1 -1
  209. package/dist/provider/fallback.d.ts +3 -1
  210. package/dist/provider/fallback.d.ts.map +1 -1
  211. package/dist/provider/fallback.js +62 -10
  212. package/dist/provider/fallback.js.map +1 -1
  213. package/dist/provider/idle-timeout.d.ts +4 -0
  214. package/dist/provider/idle-timeout.d.ts.map +1 -1
  215. package/dist/provider/idle-timeout.js +131 -15
  216. package/dist/provider/idle-timeout.js.map +1 -1
  217. package/dist/provider/index.d.ts +2 -0
  218. package/dist/provider/index.d.ts.map +1 -1
  219. package/dist/provider/index.js +1 -0
  220. package/dist/provider/index.js.map +1 -1
  221. package/dist/provider/instrumentation.d.ts.map +1 -1
  222. package/dist/provider/instrumentation.js +1 -0
  223. package/dist/provider/instrumentation.js.map +1 -1
  224. package/dist/provider/retry.d.ts.map +1 -1
  225. package/dist/provider/retry.js +13 -1
  226. package/dist/provider/retry.js.map +1 -1
  227. package/dist/public-runtime.d.ts +57 -24
  228. package/dist/public-runtime.d.ts.map +1 -1
  229. package/dist/public-runtime.js +42 -35
  230. package/dist/public-runtime.js.map +1 -1
  231. package/dist/public-tools.d.ts +1 -0
  232. package/dist/public-tools.d.ts.map +1 -1
  233. package/dist/public-tools.js +5 -0
  234. package/dist/public-tools.js.map +1 -1
  235. package/dist/public-types.d.ts +33 -12
  236. package/dist/public-types.d.ts.map +1 -1
  237. package/dist/rag/embedding.d.ts +8 -3
  238. package/dist/rag/embedding.d.ts.map +1 -1
  239. package/dist/rag/embedding.js +120 -9
  240. package/dist/rag/embedding.js.map +1 -1
  241. package/dist/rag/index.d.ts +1 -1
  242. package/dist/rag/index.d.ts.map +1 -1
  243. package/dist/rag/index.js +1 -1
  244. package/dist/rag/index.js.map +1 -1
  245. package/dist/rag/ingestion.d.ts +2 -2
  246. package/dist/rag/ingestion.d.ts.map +1 -1
  247. package/dist/rag/ingestion.js +15 -3
  248. package/dist/rag/ingestion.js.map +1 -1
  249. package/dist/rag/knowledge-base.d.ts +3 -3
  250. package/dist/rag/knowledge-base.d.ts.map +1 -1
  251. package/dist/rag/knowledge-base.js +8 -4
  252. package/dist/rag/knowledge-base.js.map +1 -1
  253. package/dist/rag/operation.d.ts +10 -0
  254. package/dist/rag/operation.d.ts.map +1 -0
  255. package/dist/rag/operation.js +26 -0
  256. package/dist/rag/operation.js.map +1 -0
  257. package/dist/rag/rag-tool.d.ts.map +1 -1
  258. package/dist/rag/rag-tool.js +6 -3
  259. package/dist/rag/rag-tool.js.map +1 -1
  260. package/dist/rag/retriever.d.ts +2 -2
  261. package/dist/rag/retriever.d.ts.map +1 -1
  262. package/dist/rag/retriever.js +31 -15
  263. package/dist/rag/retriever.js.map +1 -1
  264. package/dist/rag/vector-store.d.ts +3 -3
  265. package/dist/rag/vector-store.d.ts.map +1 -1
  266. package/dist/rag/vector-store.js +4 -2
  267. package/dist/rag/vector-store.js.map +1 -1
  268. package/dist/registry/command/kernel-commands.d.ts +16 -4
  269. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  270. package/dist/registry/command/kernel-commands.js +171 -0
  271. package/dist/registry/command/kernel-commands.js.map +1 -1
  272. package/dist/run/reporter.d.ts.map +1 -1
  273. package/dist/run/reporter.js +9 -0
  274. package/dist/run/reporter.js.map +1 -1
  275. package/dist/run-query/index.d.ts +15 -1
  276. package/dist/run-query/index.d.ts.map +1 -1
  277. package/dist/run-query/index.js +69 -15
  278. package/dist/run-query/index.js.map +1 -1
  279. package/dist/runtime/query/context.d.ts.map +1 -1
  280. package/dist/runtime/query/context.js +10 -3
  281. package/dist/runtime/query/context.js.map +1 -1
  282. package/dist/runtime/query/executor.d.ts +3 -0
  283. package/dist/runtime/query/executor.d.ts.map +1 -1
  284. package/dist/runtime/query/executor.js +80 -18
  285. package/dist/runtime/query/executor.js.map +1 -1
  286. package/dist/runtime/query/guard.d.ts +9 -0
  287. package/dist/runtime/query/guard.d.ts.map +1 -1
  288. package/dist/runtime/query/guard.js +11 -0
  289. package/dist/runtime/query/guard.js.map +1 -1
  290. package/dist/runtime/query/index.d.ts +30 -1
  291. package/dist/runtime/query/index.d.ts.map +1 -1
  292. package/dist/runtime/query/index.js +548 -95
  293. package/dist/runtime/query/index.js.map +1 -1
  294. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  295. package/dist/runtime/query/iteration/index.js +74 -14
  296. package/dist/runtime/query/iteration/index.js.map +1 -1
  297. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  298. package/dist/runtime/query/iteration/phases/compaction.js +94 -53
  299. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  300. package/dist/runtime/query/iteration/phases/context.d.ts +3 -0
  301. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  302. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  303. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  304. package/dist/runtime/query/iteration/phases/tool-review.js +21 -0
  305. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  306. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  307. package/dist/runtime/query/iteration/stream-turn.js +4 -0
  308. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  309. package/dist/runtime/query/project-instructions.d.ts +69 -0
  310. package/dist/runtime/query/project-instructions.d.ts.map +1 -0
  311. package/dist/runtime/query/project-instructions.js +137 -0
  312. package/dist/runtime/query/project-instructions.js.map +1 -0
  313. package/dist/runtime/query/request-rich-content.d.ts +22 -0
  314. package/dist/runtime/query/request-rich-content.d.ts.map +1 -0
  315. package/dist/runtime/query/request-rich-content.js +122 -0
  316. package/dist/runtime/query/request-rich-content.js.map +1 -0
  317. package/dist/runtime/query/result.d.ts.map +1 -1
  318. package/dist/runtime/query/result.js +12 -1
  319. package/dist/runtime/query/result.js.map +1 -1
  320. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  321. package/dist/runtime/query/resume-pending.js +19 -20
  322. package/dist/runtime/query/resume-pending.js.map +1 -1
  323. package/dist/runtime/query/resume-run.d.ts.map +1 -1
  324. package/dist/runtime/query/resume-run.js +54 -8
  325. package/dist/runtime/query/resume-run.js.map +1 -1
  326. package/dist/runtime/query/run-state.d.ts +5 -0
  327. package/dist/runtime/query/run-state.d.ts.map +1 -1
  328. package/dist/runtime/query/run-state.js +6 -1
  329. package/dist/runtime/query/run-state.js.map +1 -1
  330. package/dist/runtime/query/sandbox-lifecycle.d.ts +54 -0
  331. package/dist/runtime/query/sandbox-lifecycle.d.ts.map +1 -0
  332. package/dist/runtime/query/sandbox-lifecycle.js +167 -0
  333. package/dist/runtime/query/sandbox-lifecycle.js.map +1 -0
  334. package/dist/sandbox/isolation.d.ts.map +1 -1
  335. package/dist/sandbox/isolation.js +9 -0
  336. package/dist/sandbox/isolation.js.map +1 -1
  337. package/dist/sandbox/provider/local.d.ts +56 -6
  338. package/dist/sandbox/provider/local.d.ts.map +1 -1
  339. package/dist/sandbox/provider/local.js +181 -76
  340. package/dist/sandbox/provider/local.js.map +1 -1
  341. package/dist/sandbox/terminal.d.ts +13 -5
  342. package/dist/sandbox/terminal.d.ts.map +1 -1
  343. package/dist/sandbox/terminal.js +11 -3
  344. package/dist/sandbox/terminal.js.map +1 -1
  345. package/dist/session/errors.d.ts +28 -29
  346. package/dist/session/errors.d.ts.map +1 -1
  347. package/dist/session/errors.js +28 -29
  348. package/dist/session/errors.js.map +1 -1
  349. package/dist/session/handoff/broadcast.d.ts +5 -8
  350. package/dist/session/handoff/broadcast.d.ts.map +1 -1
  351. package/dist/session/handoff/broadcast.js +16 -6
  352. package/dist/session/handoff/broadcast.js.map +1 -1
  353. package/dist/session/handoff/single.d.ts +5 -8
  354. package/dist/session/handoff/single.d.ts.map +1 -1
  355. package/dist/session/handoff/single.js +7 -4
  356. package/dist/session/handoff/single.js.map +1 -1
  357. package/dist/store/attachment/index.d.ts +11 -3
  358. package/dist/store/attachment/index.d.ts.map +1 -1
  359. package/dist/store/attachment/index.js +49 -4
  360. package/dist/store/attachment/index.js.map +1 -1
  361. package/dist/store/feedback/conformance.d.ts.map +1 -1
  362. package/dist/store/feedback/conformance.js +32 -0
  363. package/dist/store/feedback/conformance.js.map +1 -1
  364. package/dist/store/feedback/disk.d.ts +8 -6
  365. package/dist/store/feedback/disk.d.ts.map +1 -1
  366. package/dist/store/feedback/disk.js +111 -76
  367. package/dist/store/feedback/disk.js.map +1 -1
  368. package/dist/store/goal/index.d.ts +111 -0
  369. package/dist/store/goal/index.d.ts.map +1 -0
  370. package/dist/store/goal/index.js +436 -0
  371. package/dist/store/goal/index.js.map +1 -0
  372. package/dist/store/index.d.ts +1 -1
  373. package/dist/store/index.d.ts.map +1 -1
  374. package/dist/store/index.js +1 -1
  375. package/dist/store/index.js.map +1 -1
  376. package/dist/store/kv/revision-record-store.d.ts +70 -0
  377. package/dist/store/kv/revision-record-store.d.ts.map +1 -0
  378. package/dist/store/kv/revision-record-store.js +290 -0
  379. package/dist/store/kv/revision-record-store.js.map +1 -0
  380. package/dist/store/memory/disk.d.ts +9 -7
  381. package/dist/store/memory/disk.d.ts.map +1 -1
  382. package/dist/store/memory/disk.js +256 -98
  383. package/dist/store/memory/disk.js.map +1 -1
  384. package/dist/store/run/disk.d.ts +10 -2
  385. package/dist/store/run/disk.d.ts.map +1 -1
  386. package/dist/store/run/disk.js +70 -4
  387. package/dist/store/run/disk.js.map +1 -1
  388. package/dist/store/run/memory.d.ts +4 -2
  389. package/dist/store/run/memory.d.ts.map +1 -1
  390. package/dist/store/run/memory.js +15 -1
  391. package/dist/store/run/memory.js.map +1 -1
  392. package/dist/store/session/disk.d.ts +9 -0
  393. package/dist/store/session/disk.d.ts.map +1 -1
  394. package/dist/store/session/disk.js +57 -5
  395. package/dist/store/session/disk.js.map +1 -1
  396. package/dist/store/session/memory.d.ts +1 -0
  397. package/dist/store/session/memory.d.ts.map +1 -1
  398. package/dist/store/session/memory.js +14 -0
  399. package/dist/store/session/memory.js.map +1 -1
  400. package/dist/store/topic/memory.d.ts +1 -2
  401. package/dist/store/topic/memory.d.ts.map +1 -1
  402. package/dist/store/topic/memory.js +4 -5
  403. package/dist/store/topic/memory.js.map +1 -1
  404. package/dist/store/topic/objective.d.ts +8 -4
  405. package/dist/store/topic/objective.d.ts.map +1 -1
  406. package/dist/store/topic/objective.js +185 -100
  407. package/dist/store/topic/objective.js.map +1 -1
  408. package/dist/store/topic/state.d.ts +1 -2
  409. package/dist/store/topic/state.d.ts.map +1 -1
  410. package/dist/store/topic/state.js +50 -62
  411. package/dist/store/topic/state.js.map +1 -1
  412. package/dist/tools/builtins/bash.d.ts.map +1 -1
  413. package/dist/tools/builtins/bash.js +20 -0
  414. package/dist/tools/builtins/bash.js.map +1 -1
  415. package/dist/tools/builtins/computer-use.d.ts +9 -1
  416. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  417. package/dist/tools/builtins/computer-use.js.map +1 -1
  418. package/dist/tools/builtins/content-fingerprint.d.ts +8 -7
  419. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  420. package/dist/tools/builtins/content-fingerprint.js +9 -10
  421. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  422. package/dist/tools/builtins/edit.d.ts +6 -1
  423. package/dist/tools/builtins/edit.d.ts.map +1 -1
  424. package/dist/tools/builtins/edit.js +166 -27
  425. package/dist/tools/builtins/edit.js.map +1 -1
  426. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  427. package/dist/tools/builtins/write-file.js +45 -19
  428. package/dist/tools/builtins/write-file.js.map +1 -1
  429. package/dist/tools/command-arguments.d.ts +43 -0
  430. package/dist/tools/command-arguments.d.ts.map +1 -0
  431. package/dist/tools/command-arguments.js +52 -0
  432. package/dist/tools/command-arguments.js.map +1 -0
  433. package/dist/tools/coordinator/index.d.ts +2 -0
  434. package/dist/tools/coordinator/index.d.ts.map +1 -1
  435. package/dist/tools/coordinator/index.js +3 -1
  436. package/dist/tools/coordinator/index.js.map +1 -1
  437. package/dist/tools/defineTool.d.ts +10 -0
  438. package/dist/tools/defineTool.d.ts.map +1 -1
  439. package/dist/tools/defineTool.js +1 -0
  440. package/dist/tools/defineTool.js.map +1 -1
  441. package/dist/tools/env-scrub.d.ts +7 -5
  442. package/dist/tools/env-scrub.d.ts.map +1 -1
  443. package/dist/tools/env-scrub.js +7 -5
  444. package/dist/tools/env-scrub.js.map +1 -1
  445. package/dist/tools/goal/index.d.ts +20 -0
  446. package/dist/tools/goal/index.d.ts.map +1 -0
  447. package/dist/tools/goal/index.js +104 -0
  448. package/dist/tools/goal/index.js.map +1 -0
  449. package/dist/tools/memory/index.d.ts +16 -0
  450. package/dist/tools/memory/index.d.ts.map +1 -1
  451. package/dist/tools/memory/index.js +6 -2
  452. package/dist/tools/memory/index.js.map +1 -1
  453. package/dist/tools/memory/search.d.ts +4 -1
  454. package/dist/tools/memory/search.d.ts.map +1 -1
  455. package/dist/tools/memory/search.js +10 -2
  456. package/dist/tools/memory/search.js.map +1 -1
  457. package/dist/types/agent/base.d.ts +11 -3
  458. package/dist/types/agent/base.d.ts.map +1 -1
  459. package/dist/types/agent/factory.d.ts +2 -0
  460. package/dist/types/agent/factory.d.ts.map +1 -1
  461. package/dist/types/agent/reactive.d.ts +2 -0
  462. package/dist/types/agent/reactive.d.ts.map +1 -1
  463. package/dist/types/agent/supervisor.d.ts +6 -0
  464. package/dist/types/agent/supervisor.d.ts.map +1 -1
  465. package/dist/types/agent/task.d.ts +6 -2
  466. package/dist/types/agent/task.d.ts.map +1 -1
  467. package/dist/types/connector/core.d.ts +13 -8
  468. package/dist/types/connector/core.d.ts.map +1 -1
  469. package/dist/types/connector/definition.d.ts +37 -18
  470. package/dist/types/connector/definition.d.ts.map +1 -1
  471. package/dist/types/connector/http.d.ts +6 -0
  472. package/dist/types/connector/http.d.ts.map +1 -1
  473. package/dist/types/connector/mcp.d.ts +24 -6
  474. package/dist/types/connector/mcp.d.ts.map +1 -1
  475. package/dist/types/connector/tenant.d.ts +17 -7
  476. package/dist/types/connector/tenant.d.ts.map +1 -1
  477. package/dist/types/connector/webhook.d.ts +6 -0
  478. package/dist/types/connector/webhook.d.ts.map +1 -1
  479. package/dist/types/goal/index.d.ts +46 -0
  480. package/dist/types/goal/index.d.ts.map +1 -0
  481. package/dist/types/goal/index.js +2 -0
  482. package/dist/types/goal/index.js.map +1 -0
  483. package/dist/types/ids/index.d.ts +2 -0
  484. package/dist/types/ids/index.d.ts.map +1 -1
  485. package/dist/types/ids/index.js.map +1 -1
  486. package/dist/types/message/index.d.ts +79 -13
  487. package/dist/types/message/index.d.ts.map +1 -1
  488. package/dist/types/message/index.js +49 -3
  489. package/dist/types/message/index.js.map +1 -1
  490. package/dist/types/plugin/index.d.ts +7 -5
  491. package/dist/types/plugin/index.d.ts.map +1 -1
  492. package/dist/types/plugin/index.js.map +1 -1
  493. package/dist/types/provider/chat.d.ts +27 -4
  494. package/dist/types/provider/chat.d.ts.map +1 -1
  495. package/dist/types/provider/index.d.ts +1 -1
  496. package/dist/types/provider/index.d.ts.map +1 -1
  497. package/dist/types/provider/interface.d.ts +18 -7
  498. package/dist/types/provider/interface.d.ts.map +1 -1
  499. package/dist/types/provider/model.d.ts +12 -0
  500. package/dist/types/provider/model.d.ts.map +1 -1
  501. package/dist/types/provider/stream.d.ts +6 -0
  502. package/dist/types/provider/stream.d.ts.map +1 -1
  503. package/dist/types/rag/embedding.d.ts +15 -2
  504. package/dist/types/rag/embedding.d.ts.map +1 -1
  505. package/dist/types/rag/ingestion.d.ts +2 -2
  506. package/dist/types/rag/ingestion.d.ts.map +1 -1
  507. package/dist/types/rag/knowledge-base.d.ts +3 -3
  508. package/dist/types/rag/knowledge-base.d.ts.map +1 -1
  509. package/dist/types/rag/retrieval.d.ts +2 -2
  510. package/dist/types/rag/retrieval.d.ts.map +1 -1
  511. package/dist/types/rag/scope.d.ts +4 -0
  512. package/dist/types/rag/scope.d.ts.map +1 -1
  513. package/dist/types/rag/vector.d.ts +5 -2
  514. package/dist/types/rag/vector.d.ts.map +1 -1
  515. package/dist/types/run/config.d.ts +20 -0
  516. package/dist/types/run/config.d.ts.map +1 -1
  517. package/dist/types/run/events.d.ts +25 -1
  518. package/dist/types/run/events.d.ts.map +1 -1
  519. package/dist/types/run/events.js.map +1 -1
  520. package/dist/types/run/metadata.d.ts +2 -0
  521. package/dist/types/run/metadata.d.ts.map +1 -1
  522. package/dist/types/run/step.d.ts +2 -6
  523. package/dist/types/run/step.d.ts.map +1 -1
  524. package/dist/types/run/step.js.map +1 -1
  525. package/dist/types/run/store.d.ts +55 -2
  526. package/dist/types/run/store.d.ts.map +1 -1
  527. package/dist/types/sandbox/index.d.ts +47 -6
  528. package/dist/types/sandbox/index.d.ts.map +1 -1
  529. package/dist/types/sandbox/index.js +23 -10
  530. package/dist/types/sandbox/index.js.map +1 -1
  531. package/dist/types/session/store.d.ts +13 -0
  532. package/dist/types/session/store.d.ts.map +1 -1
  533. package/dist/types/tool/index.d.ts +33 -11
  534. package/dist/types/tool/index.d.ts.map +1 -1
  535. package/dist/types/tool/index.js.map +1 -1
  536. package/dist/types/topic/entity.d.ts +3 -4
  537. package/dist/types/topic/entity.d.ts.map +1 -1
  538. package/dist/types/topic/store.d.ts +3 -3
  539. package/dist/utils/id.d.ts +3 -1
  540. package/dist/utils/id.d.ts.map +1 -1
  541. package/dist/utils/id.js +4 -0
  542. package/dist/utils/id.js.map +1 -1
  543. package/dist/utils/process-environment.d.ts +26 -0
  544. package/dist/utils/process-environment.d.ts.map +1 -0
  545. package/dist/utils/process-environment.js +78 -0
  546. package/dist/utils/process-environment.js.map +1 -0
  547. package/dist/vault/InMemoryCredentialVault.d.ts +2 -0
  548. package/dist/vault/InMemoryCredentialVault.d.ts.map +1 -1
  549. package/dist/vault/InMemoryCredentialVault.js +24 -4
  550. package/dist/vault/InMemoryCredentialVault.js.map +1 -1
  551. package/dist/vault/instrumentation.d.ts.map +1 -1
  552. package/dist/vault/instrumentation.js +15 -0
  553. package/dist/vault/instrumentation.js.map +1 -1
  554. package/package.json +1 -1
  555. package/src/advisory/executor.ts +4 -1
  556. package/src/agents/ReactiveAgent.ts +12 -0
  557. package/src/agents/RouterAgent.ts +25 -3
  558. package/src/agents/SupervisorAgent.ts +33 -11
  559. package/src/agents/runAgent.ts +38 -2
  560. package/src/authorization/command-line.ts +390 -0
  561. package/src/authorization/rules.ts +22 -1
  562. package/src/bridge/a2a/client.ts +384 -97
  563. package/src/bridge/a2a/mapper.ts +5 -0
  564. package/src/bridge/acp/server.ts +184 -42
  565. package/src/bridge/mcp/connector/adapter.ts +28 -20
  566. package/src/bridge/sse/mapper.ts +3 -0
  567. package/src/compaction/dangling.ts +203 -38
  568. package/src/compaction/index.ts +9 -2
  569. package/src/compaction/manual.ts +125 -18
  570. package/src/compaction/plan.ts +42 -11
  571. package/src/compaction/retention.ts +23 -8
  572. package/src/compaction/summary.ts +4 -4
  573. package/src/compaction/verifier.ts +66 -0
  574. package/src/connector/BaseConnector.ts +19 -4
  575. package/src/connector/builtins/http.ts +236 -46
  576. package/src/connector/builtins/webhook.ts +207 -47
  577. package/src/connector/execution-contract.ts +27 -0
  578. package/src/connector/http-operation.ts +238 -0
  579. package/src/connector/mcp/adapter.ts +8 -3
  580. package/src/connector/mcp/client.ts +207 -58
  581. package/src/connector/mcp/http-sse.ts +91 -23
  582. package/src/connector/mcp/prompt-adapter.ts +8 -2
  583. package/src/connector/mcp/stdio.ts +21 -46
  584. package/src/connector/mcp/streamable-http.ts +86 -22
  585. package/src/connector/tools/adapter.ts +23 -14
  586. package/src/connector/tools/definitions.ts +5 -2
  587. package/src/connector/tools/result.ts +21 -0
  588. package/src/connector/web/guarded-fetch.ts +188 -48
  589. package/src/constants/sandbox/index.ts +3 -2
  590. package/src/contracts/api.ts +2 -0
  591. package/src/contracts/schemas.ts +7 -0
  592. package/src/directory/derive-supervisor.ts +8 -0
  593. package/src/directory/derive.ts +8 -0
  594. package/src/directory/load.ts +2 -0
  595. package/src/directory/types.ts +4 -0
  596. package/src/eval/experiment.ts +160 -111
  597. package/src/eval/judge.ts +13 -2
  598. package/src/eval/types.ts +7 -1
  599. package/src/manager/agent/lifecycle.ts +28 -12
  600. package/src/manager/connector/environment.ts +3 -1
  601. package/src/manager/connector/lifecycle.ts +364 -24
  602. package/src/manager/connector/tenant.ts +56 -23
  603. package/src/manager/goal/activation.ts +52 -0
  604. package/src/manager/index.ts +10 -2
  605. package/src/manager/run/persistence.ts +6 -1
  606. package/src/manager/topic/dependency.ts +39 -0
  607. package/src/manager/topic/lifecycle.ts +19 -31
  608. package/src/plugin/index.ts +1 -0
  609. package/src/plugin/lifecycle.ts +180 -39
  610. package/src/plugin/loader.ts +70 -13
  611. package/src/provider/collect-chat-completion.ts +3 -0
  612. package/src/provider/fallback.ts +79 -11
  613. package/src/provider/idle-timeout.ts +143 -17
  614. package/src/provider/index.ts +2 -0
  615. package/src/provider/instrumentation.ts +1 -0
  616. package/src/provider/retry.ts +16 -1
  617. package/src/public-runtime.ts +190 -32
  618. package/src/public-tools.ts +5 -0
  619. package/src/public-types.ts +85 -11
  620. package/src/rag/embedding.ts +147 -19
  621. package/src/rag/index.ts +1 -1
  622. package/src/rag/ingestion.ts +16 -2
  623. package/src/rag/knowledge-base.ts +13 -4
  624. package/src/rag/operation.ts +28 -0
  625. package/src/rag/rag-tool.ts +6 -3
  626. package/src/rag/retriever.ts +62 -11
  627. package/src/rag/vector-store.ts +8 -2
  628. package/src/registry/command/kernel-commands.ts +223 -4
  629. package/src/run/reporter.ts +10 -0
  630. package/src/run-query/index.ts +84 -15
  631. package/src/runtime/query/context.ts +13 -3
  632. package/src/runtime/query/executor.ts +90 -17
  633. package/src/runtime/query/guard.ts +12 -0
  634. package/src/runtime/query/index.ts +652 -103
  635. package/src/runtime/query/iteration/index.ts +89 -13
  636. package/src/runtime/query/iteration/phases/compaction.ts +120 -55
  637. package/src/runtime/query/iteration/phases/context.ts +4 -0
  638. package/src/runtime/query/iteration/phases/tool-review.ts +28 -0
  639. package/src/runtime/query/iteration/stream-turn.ts +3 -0
  640. package/src/runtime/query/project-instructions.ts +212 -0
  641. package/src/runtime/query/request-rich-content.ts +153 -0
  642. package/src/runtime/query/result.ts +12 -1
  643. package/src/runtime/query/resume-pending.ts +20 -18
  644. package/src/runtime/query/resume-run.ts +52 -8
  645. package/src/runtime/query/run-state.ts +11 -1
  646. package/src/runtime/query/sandbox-lifecycle.ts +210 -0
  647. package/src/sandbox/isolation.ts +9 -0
  648. package/src/sandbox/provider/local.ts +255 -90
  649. package/src/sandbox/terminal.ts +13 -5
  650. package/src/session/errors.ts +68 -42
  651. package/src/session/handoff/broadcast.ts +20 -14
  652. package/src/session/handoff/single.ts +14 -13
  653. package/src/store/attachment/index.ts +65 -3
  654. package/src/store/feedback/conformance.ts +39 -0
  655. package/src/store/feedback/disk.ts +128 -82
  656. package/src/store/goal/index.ts +594 -0
  657. package/src/store/index.ts +1 -1
  658. package/src/store/kv/revision-record-store.ts +346 -0
  659. package/src/store/memory/disk.ts +288 -113
  660. package/src/store/run/disk.ts +96 -5
  661. package/src/store/run/memory.ts +22 -2
  662. package/src/store/session/disk.ts +93 -6
  663. package/src/store/session/memory.ts +22 -0
  664. package/src/store/topic/memory.ts +4 -5
  665. package/src/store/topic/objective.ts +215 -100
  666. package/src/store/topic/state.ts +100 -63
  667. package/src/tools/builtins/bash.ts +21 -0
  668. package/src/tools/builtins/computer-use.ts +9 -1
  669. package/src/tools/builtins/content-fingerprint.ts +9 -12
  670. package/src/tools/builtins/edit.ts +190 -27
  671. package/src/tools/builtins/write-file.ts +55 -19
  672. package/src/tools/command-arguments.ts +54 -0
  673. package/src/tools/coordinator/index.ts +4 -1
  674. package/src/tools/defineTool.ts +11 -0
  675. package/src/tools/env-scrub.ts +7 -5
  676. package/src/tools/goal/index.ts +129 -0
  677. package/src/tools/memory/index.ts +26 -3
  678. package/src/tools/memory/search.ts +20 -3
  679. package/src/types/agent/base.ts +12 -3
  680. package/src/types/agent/factory.ts +2 -0
  681. package/src/types/agent/reactive.ts +2 -0
  682. package/src/types/agent/supervisor.ts +6 -0
  683. package/src/types/agent/task.ts +6 -2
  684. package/src/types/connector/core.ts +13 -8
  685. package/src/types/connector/definition.ts +54 -20
  686. package/src/types/connector/http.ts +7 -0
  687. package/src/types/connector/mcp.ts +27 -6
  688. package/src/types/connector/tenant.ts +21 -7
  689. package/src/types/connector/webhook.ts +7 -0
  690. package/src/types/goal/index.ts +50 -0
  691. package/src/types/ids/index.ts +2 -0
  692. package/src/types/message/index.ts +147 -12
  693. package/src/types/plugin/index.ts +7 -5
  694. package/src/types/provider/chat.ts +35 -4
  695. package/src/types/provider/index.ts +1 -1
  696. package/src/types/provider/interface.ts +22 -7
  697. package/src/types/provider/model.ts +13 -0
  698. package/src/types/provider/stream.ts +6 -0
  699. package/src/types/rag/embedding.ts +16 -2
  700. package/src/types/rag/ingestion.ts +2 -1
  701. package/src/types/rag/knowledge-base.ts +7 -3
  702. package/src/types/rag/retrieval.ts +2 -1
  703. package/src/types/rag/scope.ts +5 -0
  704. package/src/types/rag/vector.ts +5 -2
  705. package/src/types/run/config.ts +20 -0
  706. package/src/types/run/events.ts +28 -3
  707. package/src/types/run/metadata.ts +2 -0
  708. package/src/types/run/step.ts +2 -7
  709. package/src/types/run/store.ts +60 -2
  710. package/src/types/sandbox/index.ts +57 -14
  711. package/src/types/session/store.ts +18 -0
  712. package/src/types/tool/index.ts +33 -11
  713. package/src/types/topic/entity.ts +3 -4
  714. package/src/types/topic/store.ts +3 -3
  715. package/src/utils/id.ts +6 -0
  716. package/src/utils/process-environment.ts +101 -0
  717. package/src/vault/InMemoryCredentialVault.ts +29 -4
  718. package/src/vault/instrumentation.ts +24 -0
@@ -45,6 +45,10 @@ import { stableDigest } from '../../../utils/hash.js'
45
45
  import { generateMessageId } from '../../../utils/id.js'
46
46
  import type { ToolCallOutcome } from '../executor.js'
47
47
  import { applyLifecycleHookResults } from '../plugin-hooks.js'
48
+ import {
49
+ DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
50
+ projectRequestRichContent,
51
+ } from '../request-rich-content.js'
48
52
  import { formatSteeringNote } from '../steering.js'
49
53
  import { runAdvisoryPhase } from './phases/advisory.js'
50
54
  import { runIterationCheckpoint } from './phases/checkpoint.js'
@@ -220,7 +224,9 @@ export class IterationOrchestrator {
220
224
 
221
225
  if (guardResult.shouldStop) {
222
226
  if (guardResult.isCancelled) {
223
- this.ctx.log.info('Run cancelled by signal', { [NAMZU.RUN_ID]: runMgr.id })
227
+ this.ctx.log.info('Run cancelled by signal', {
228
+ [NAMZU.RUN_ID]: runMgr.id,
229
+ })
224
230
  runMgr.setStopReason('cancelled')
225
231
  runMgr.markCancelled()
226
232
  break
@@ -336,7 +342,11 @@ export class IterationOrchestrator {
336
342
  if (this.ctx.pluginManager) {
337
343
  const hookResults = await this.ctx.pluginManager.executeHooks(
338
344
  'iteration_start',
339
- { runId: runMgr.id, iteration: iterationNum },
345
+ {
346
+ runId: runMgr.id,
347
+ iteration: iterationNum,
348
+ signal: this.ctx.abortController.signal,
349
+ },
340
350
  this.ctx.emitEvent,
341
351
  )
342
352
  applyLifecycleHookResults('iteration_start', hookResults)
@@ -348,6 +358,11 @@ export class IterationOrchestrator {
348
358
  // compaction preserves). No-op when no provider is configured.
349
359
  await refreshWorkingMemory(this.ctx)
350
360
  await runCompactionCheck(this.ctx)
361
+ // A context edit is a host-visible state transition, not a prelude
362
+ // whose events may wait behind the next network call. In particular,
363
+ // a slow or failing provider must not leave the host displaying the
364
+ // pre-compaction context after Run.messages already shrank.
365
+ yield* this.ctx.drainPending()
351
366
 
352
367
  // Cache discipline: keep the tools param byte-stable even on the
353
368
  // forced-final iteration and forbid tool use via tool_choice
@@ -426,14 +441,20 @@ export class IterationOrchestrator {
426
441
  // a standing instruction, and either way the state they
427
442
  // exist to report goes stale silently.
428
443
  const turnSections =
429
- this.ctx.promptContributions?.render('turn', { iteration: iterationNum }) ?? []
444
+ this.ctx.promptContributions?.render('turn', {
445
+ iteration: iterationNum,
446
+ }) ?? []
430
447
 
431
448
  const stepPreamble = [step.system, stepSkills, policyNotice, ...turnSections]
432
449
  .filter(Boolean)
433
450
  .join('\n\n')
434
- const messages = stepPreamble
451
+ const requestHistory = stepPreamble
435
452
  ? [...baseMessages, createSystemMessage(stepPreamble)]
436
453
  : [...baseMessages]
454
+ const messages = projectRequestRichContent(
455
+ requestHistory,
456
+ this.ctx.runConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
457
+ )
437
458
 
438
459
  // What the model is about to be ASKED, recorded when it
439
460
  // changed. `run_started` carries one system prompt and tool
@@ -484,6 +505,7 @@ export class IterationOrchestrator {
484
505
  {
485
506
  runId: runMgr.id,
486
507
  iteration: iterationNum,
508
+ signal: this.ctx.abortController.signal,
487
509
  // Built inside the guard: a run with no plugins installed
488
510
  // pays nothing for a projection nobody reads.
489
511
  request: Object.freeze({
@@ -521,10 +543,20 @@ export class IterationOrchestrator {
521
543
  // `message_completed` under this id, which is the trail a
522
544
  // reader wants most on exactly that turn.
523
545
  stepMessageId = generateMessageId()
546
+ const requestedMember = this.ctx.servingMember?.() ?? {
547
+ index: 0,
548
+ providerId: this.ctx.provider.id,
549
+ }
550
+ const requestedRoute: StepProvenance = {
551
+ providerId: requestedMember.providerId,
552
+ model: requestedMember.model ?? stepModel,
553
+ chainIndex: requestedMember.index,
554
+ }
524
555
  const { response, messageId } = yield* streamProviderTurn(
525
556
  this.ctx.provider,
526
557
  {
527
558
  model: stepModel,
559
+ providerRoute: requestedRoute,
528
560
  messages,
529
561
  tools: llmTools.length > 0 ? llmTools : undefined,
530
562
  ...(enforceToolInputSchema ? { enforceToolInputSchema } : {}),
@@ -618,6 +650,7 @@ export class IterationOrchestrator {
618
650
  {
619
651
  runId: runMgr.id,
620
652
  iteration: iterationNum,
653
+ signal: this.ctx.abortController.signal,
621
654
  response: Object.freeze({
622
655
  content: response.message.content,
623
656
  toolNames: Object.freeze(
@@ -681,10 +714,10 @@ export class IterationOrchestrator {
681
714
  ...contextFigures,
682
715
  })
683
716
 
684
- // Reasoning rides along with the turn it belongs to, so the
685
- // replay contract holds automatically: trimming or compacting
686
- // the assistant message takes its thinking blocks with it,
687
- // and no separate atomicity rule is needed.
717
+ // Durable reasoning and its adapter-private replay envelope ride
718
+ // with the turn they belong to. Trimming therefore removes both;
719
+ // retaining them gives the target adapter enough evidence to
720
+ // validate native replay against the exact serving route.
688
721
  const assistantMsg = createAssistantMessage(
689
722
  response.message.content,
690
723
  forceFinalize ? undefined : response.message.toolCalls,
@@ -693,6 +726,13 @@ export class IterationOrchestrator {
693
726
  // trimming or compacting the turn takes its evidence with it
694
727
  // rather than leaving citations pointing at prose that is gone.
695
728
  response.message.citations,
729
+ {
730
+ type: 'model',
731
+ ...servedBy,
732
+ ...(response.message.replayState !== undefined
733
+ ? { replayState: response.message.replayState }
734
+ : {}),
735
+ },
696
736
  )
697
737
  runMgr.pushMessage(assistantMsg)
698
738
 
@@ -1162,7 +1202,11 @@ export class IterationOrchestrator {
1162
1202
  if (this.ctx.pluginManager) {
1163
1203
  const hookResults = await this.ctx.pluginManager.executeHooks(
1164
1204
  'iteration_end',
1165
- { runId: runMgr.id, iteration: iterationNum },
1205
+ {
1206
+ runId: runMgr.id,
1207
+ iteration: iterationNum,
1208
+ signal: this.ctx.abortController.signal,
1209
+ },
1166
1210
  this.ctx.emitEvent,
1167
1211
  )
1168
1212
  applyLifecycleHookResults('iteration_end', hookResults)
@@ -1895,21 +1939,35 @@ export class IterationOrchestrator {
1895
1939
  })
1896
1940
 
1897
1941
  try {
1898
- const finalMessages = [
1942
+ const finalHistory = [
1899
1943
  ...this.ctx.runMgr.messages,
1900
1944
  createUserMessage(
1901
1945
  `[SYSTEM] Run is ending due to ${reason}. You MUST provide a final response now summarizing all your findings and work so far. Do not use any tools.`,
1902
1946
  ),
1903
1947
  ]
1948
+ const finalMessages = projectRequestRichContent(
1949
+ finalHistory,
1950
+ this.ctx.runConfig.maxRequestRichContentBytes ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES,
1951
+ )
1904
1952
 
1905
1953
  // Same cache discipline as the forced-final iteration: keep the
1906
1954
  // tools param identical to prior iterations (cache prefix intact,
1907
1955
  // no 400 on tool blocks in history) and forbid use via tool_choice.
1908
1956
  const finalTools = this.ctx.tools.toLLMTools(this.ctx.allowedTools)
1909
1957
  const finalEnforced = enforcedModelInputToolNames(this.ctx.tools, finalTools)
1958
+ const requestedMember = this.ctx.servingMember?.() ?? {
1959
+ index: 0,
1960
+ providerId: this.ctx.provider.id,
1961
+ }
1962
+ const requestedRoute: StepProvenance = {
1963
+ providerId: requestedMember.providerId,
1964
+ model: requestedMember.model ?? model,
1965
+ chainIndex: requestedMember.index,
1966
+ }
1910
1967
  const response = await collectChatCompletion(
1911
1968
  this.ctx.provider.chatStream({
1912
1969
  model,
1970
+ providerRoute: requestedRoute,
1913
1971
  messages: finalMessages,
1914
1972
  tools: finalTools.length > 0 ? finalTools : undefined,
1915
1973
  ...(finalEnforced ? { enforceToolInputSchema: finalEnforced } : {}),
@@ -1928,12 +1986,30 @@ export class IterationOrchestrator {
1928
1986
  }),
1929
1987
  )
1930
1988
 
1989
+ const servingMember = this.ctx.servingMember?.() ?? requestedMember
1990
+ const servedBy: StepProvenance = {
1991
+ providerId: servingMember.providerId,
1992
+ model: servingMember.model ?? model,
1993
+ chainIndex: servingMember.index,
1994
+ }
1931
1995
  this.ctx.runMgr.accumulateUsage(response.usage, {
1932
- providerId: this.ctx.runMgr.servingProviderId,
1933
- model,
1996
+ providerId: servedBy.providerId,
1997
+ model: servedBy.model,
1934
1998
  })
1935
1999
 
1936
- const assistantMsg = createAssistantMessage(response.message.content)
2000
+ const assistantMsg = createAssistantMessage(
2001
+ response.message.content,
2002
+ undefined,
2003
+ response.message.reasoning,
2004
+ response.message.citations,
2005
+ {
2006
+ type: 'model',
2007
+ ...servedBy,
2008
+ ...(response.message.replayState !== undefined
2009
+ ? { replayState: response.message.replayState }
2010
+ : {}),
2011
+ },
2012
+ )
1937
2013
  this.ctx.runMgr.pushMessage(assistantMsg)
1938
2014
 
1939
2015
  const finalMessageId = generateMessageId()
@@ -1,12 +1,12 @@
1
1
  import { resolveContextWindow } from '../../../../compaction/context-window.js'
2
2
  import { findDanglingMessages } from '../../../../compaction/dangling.js'
3
- import { planCompaction } from '../../../../compaction/plan.js'
3
+ import { type CompactionPlan, planCompaction } from '../../../../compaction/plan.js'
4
4
  import type { ContextReducer, ContextReduction } from '../../../../compaction/reducer.js'
5
5
  import { createSlidingWindowReducer } from '../../../../compaction/reducer.js'
6
6
  import { findRetainedIndices } from '../../../../compaction/retention.js'
7
7
  import { serializeState } from '../../../../compaction/serializer.js'
8
8
  import { buildCompactionMessage, isCompactionMessage } from '../../../../compaction/summary.js'
9
- import { buildVerifiedSummary } from '../../../../compaction/verifier.js'
9
+ import { buildVerifiedSummaryWithBoundedProvider } from '../../../../compaction/verifier.js'
10
10
  import { CHARS_PER_TOKEN } from '../../../../constants/limits.js'
11
11
  import { NAMZU } from '../../../../constants/telemetry/index.js'
12
12
  import { invariants } from '../../../../invariants/index.js'
@@ -97,6 +97,78 @@ function estimateTokens(ctx: IterationContext): number {
97
97
  return estimateMessageTokens(ctx.runMgr.messages) + estimateToolCatalogTokens(ctx)
98
98
  }
99
99
 
100
+ type ToolResultClearPlan = Extract<CompactionPlan, { kind: 'cleared' }>
101
+
102
+ /** Replace the contents while preserving the live array identity. */
103
+ function installMessages(live: Message[], next: readonly Message[]): void {
104
+ live.length = 0
105
+ for (const message of next) live.push(message)
106
+ }
107
+
108
+ /**
109
+ * Publish a status snapshot for a context edit that has already committed.
110
+ *
111
+ * Cumulative usage and cost do not fall when history is shed. The context
112
+ * does, and until the next provider response there is no more authoritative
113
+ * number than the post-edit estimate. Emitting the existing state event at
114
+ * this boundary lets hosts update immediately without inventing a second
115
+ * accounting channel.
116
+ */
117
+ async function emitContextUsageSnapshot(
118
+ ctx: IterationContext,
119
+ contextTokens: number,
120
+ contextWindowTokens: number,
121
+ windowSource: 'config' | 'provider' | 'model-table' | 'default',
122
+ ): Promise<void> {
123
+ await ctx.emitEvent?.({
124
+ type: 'token_usage_updated',
125
+ runId: ctx.runMgr.id,
126
+ usage: { ...ctx.runMgr.tokenUsage },
127
+ cost: { ...ctx.runMgr.costInfo },
128
+ contextTokens,
129
+ contextMeasuredBy: 'estimate',
130
+ contextWindowTokens,
131
+ windowSource,
132
+ })
133
+ }
134
+
135
+ async function emitToolResultClear(
136
+ ctx: IterationContext,
137
+ plan: ToolResultClearPlan,
138
+ ): Promise<void> {
139
+ ctx.log.info('Cleared stale tool results instead of compacting', {
140
+ [NAMZU.RUN_ID]: ctx.runMgr.id,
141
+ 'namzu.runtime.cleared': plan.clearedCount,
142
+ 'namzu.runtime.chars_reclaimed': plan.charsReclaimed,
143
+ 'namzu.runtime.reclaimed_tokens': plan.reclaimedTokens,
144
+ })
145
+
146
+ await ctx.emitEvent?.({
147
+ type: 'compaction_tool_results_cleared',
148
+ runId: ctx.runMgr.id,
149
+ iteration: ctx.runMgr.currentIteration,
150
+ clearedCount: plan.clearedCount,
151
+ charsReclaimed: plan.charsReclaimed,
152
+ reclaimedTokens: plan.reclaimedTokens,
153
+ reliefWasEnough: plan.reliefWasEnough,
154
+ })
155
+ }
156
+
157
+ /** Install a clear-only pass and publish the state it established. */
158
+ async function commitToolResultClear(
159
+ ctx: IterationContext,
160
+ plan: ToolResultClearPlan,
161
+ contextWindowTokens: number,
162
+ windowSource: 'config' | 'provider' | 'model-table' | 'default',
163
+ ): Promise<void> {
164
+ installMessages(ctx.runMgr.messages, plan.messages)
165
+ // The provider counted the pre-edit prompt. Leaving that measurement live
166
+ // makes the next trigger compare the old prompt against the new history.
167
+ ctx.runMgr.clearLastPromptTokens?.()
168
+ await emitToolResultClear(ctx, plan)
169
+ await emitContextUsageSnapshot(ctx, estimateTokens(ctx), contextWindowTokens, windowSource)
170
+ }
171
+
100
172
  /**
101
173
  * How full the context is, in tokens.
102
174
  *
@@ -335,8 +407,7 @@ async function applyReducer(
335
407
 
336
408
  await recordShed(ctx, [...messages], next, reduction.reason)
337
409
 
338
- messages.length = 0
339
- for (const message of next) messages.push(message)
410
+ installMessages(messages, next)
340
411
 
341
412
  // The provider's count described the pre-reduction prompt. Same reasoning
342
413
  // as the structured path: leaving it would have the next trigger check
@@ -360,6 +431,7 @@ async function applyReducer(
360
431
  //
361
432
  // Found by a test written for the decline paths asserting that success does
362
433
  // NOT report a failure, which is the only reason anybody looked here.
434
+ const tokensAfter = estimateTokens(ctx)
363
435
  await ctx.emitEvent?.({
364
436
  type: 'compaction_completed',
365
437
  runId: ctx.runMgr.id,
@@ -367,11 +439,17 @@ async function applyReducer(
367
439
  messagesBefore: before,
368
440
  messagesAfter: messages.length,
369
441
  tokensBefore: reduction.estimatedTokens,
370
- tokensAfter: estimateMessageTokens(messages),
442
+ tokensAfter,
371
443
  measuredBy: measurement.measuredBy,
372
444
  contextWindowTokens: reduction.contextWindowTokens,
373
445
  windowSource: measurement.windowSource,
374
446
  })
447
+ await emitContextUsageSnapshot(
448
+ ctx,
449
+ tokensAfter,
450
+ reduction.contextWindowTokens,
451
+ measurement.windowSource,
452
+ )
375
453
  }
376
454
 
377
455
  /**
@@ -502,46 +580,22 @@ export async function runCompactionCheck(
502
580
  })
503
581
 
504
582
  if (clearPlan.kind === 'cleared') {
505
- // Element-wise, not a rebuild: the edit is length-preserving by
506
- // construction (only `content` changes), so writing entries back
507
- // keeps the live array identity the rest of the run holds.
508
- const live = ctx.runMgr.messages
509
- clearPlan.messages.forEach((msg, i) => {
510
- live[i] = msg
511
- })
512
-
513
- ctx.log.info('Cleared stale tool results instead of compacting', {
514
- [NAMZU.RUN_ID]: ctx.runMgr.id,
515
- 'namzu.runtime.cleared': clearPlan.clearedCount,
516
- 'namzu.runtime.chars_reclaimed': clearPlan.charsReclaimed,
517
- 'namzu.runtime.reclaimed_tokens': clearPlan.reclaimedTokens,
518
- })
519
-
520
- // Emitted BEFORE the return so the insufficient branch is not the
521
- // silent one: a clear that fell through to summarization edited the
522
- // history exactly as much as one that did not.
523
- await ctx.emitEvent?.({
524
- type: 'compaction_tool_results_cleared',
525
- runId: ctx.runMgr.id,
526
- iteration: ctx.runMgr.currentIteration,
527
- clearedCount: clearPlan.clearedCount,
528
- charsReclaimed: clearPlan.charsReclaimed,
529
- reclaimedTokens: clearPlan.reclaimedTokens,
530
- reliefWasEnough: clearPlan.reliefWasEnough,
531
- })
532
-
533
583
  // If that was enough, stop here and keep the history verbatim. The
534
584
  // measurement is an estimate either way; the provider's own count for
535
585
  // the NEXT turn will correct it, and an over-eager summarization is
536
586
  // far more costly than one late pass.
537
- if (clearPlan.reliefWasEnough) return
587
+ if (clearPlan.reliefWasEnough) {
588
+ await commitToolResultClear(ctx, clearPlan, budget, window.source)
589
+ return
590
+ }
538
591
  }
539
592
 
540
- // Second call, over the history the clear above may have just edited.
541
- // `skipToolResultClear` because that step already ran and installed its
542
- // result; asking again would clear nothing and say so as a `cleared`
543
- // with a zero count, which is a shape this branch would have to ignore.
544
- const messages = ctx.runMgr.messages
593
+ // Second call, over the cleared CANDIDATE when there is one. An
594
+ // insufficient clear stays off the live Run until summary verification
595
+ // succeeds. If that side call stalls, fails or is cancelled, the run keeps
596
+ // one coherent pre-edit history instead of publishing half a pass.
597
+ const stagedClear = clearPlan.kind === 'cleared' ? clearPlan : undefined
598
+ const messages = stagedClear?.messages ?? ctx.runMgr.messages
545
599
  const plan = planCompaction({
546
600
  messages,
547
601
  config,
@@ -579,6 +633,12 @@ export async function runCompactionCheck(
579
633
  break
580
634
  }
581
635
  }
636
+ // Clearing may have been useful even though no safe summary cut exists.
637
+ // There is no opaque provider wait on this path, so publish that single
638
+ // complete edit now rather than discarding it.
639
+ if (stagedClear) {
640
+ await commitToolResultClear(ctx, stagedClear, budget, window.source)
641
+ }
582
642
  return
583
643
  }
584
644
 
@@ -593,7 +653,7 @@ export async function runCompactionCheck(
593
653
  // to a cheap model while the bill is written against the expensive one
594
654
  // is a mistake with no symptom.
595
655
  const compactionModel = resolveTaskModel('compaction', ctx.taskRouter, ctx.runConfig.model)
596
- compactedContent = await buildVerifiedSummary(
656
+ compactedContent = await buildVerifiedSummaryWithBoundedProvider(
597
657
  manager,
598
658
  olderMessages as Message[],
599
659
  ctx.provider,
@@ -610,6 +670,7 @@ export async function runCompactionCheck(
610
670
  // been accepted, validated and threaded through four types since it
611
671
  // was added, and nothing ever consulted it.
612
672
  compactionModel,
673
+ ctx.abortController.signal,
613
674
  )
614
675
  } else {
615
676
  compactedContent = serializeState(manager.getState())
@@ -617,13 +678,14 @@ export async function runCompactionCheck(
617
678
 
618
679
  const compactionMessage = buildCompactionMessage(compactedContent)
619
680
 
620
- // Drop any PRIOR `[COMPACTED CONTEXT]` summary from the leading floor —
621
- // `serializeState` is cumulative, so the new summary supersedes it.
622
- // Without this the never-trimmed floor accumulates one redundant summary
623
- // per pass, unbounded. Unconditional now, for the reason given at the
624
- // thrash guard above.
681
+ // Drop a replaceable PRIOR `[COMPACTED CONTEXT]` summary from this run's
682
+ // leading floor — `serializeState` is cumulative, so the new summary
683
+ // supersedes it. A retained summary came from outside this manager's state
684
+ // horizon (for example a host-triggered pass between runs) and remains
685
+ // opaque; deleting it would erase the only surviving record of that span.
625
686
  const preservedSystem = systemMessages.filter(
626
- (m) => !isCompactionMessage(typeof m.content === 'string' ? m.content : null),
687
+ (m) =>
688
+ !isCompactionMessage(typeof m.content === 'string' ? m.content : null) || m.retain === true,
627
689
  )
628
690
 
629
691
  // Pinned turns from the older window survive verbatim, in order, between
@@ -660,13 +722,11 @@ export async function runCompactionCheck(
660
722
  }
661
723
  }
662
724
 
663
- const oldCount = messages.length
664
- await recordShed(ctx, [...messages], newMessages, options?.force ? 'overflow' : 'threshold')
725
+ const live = ctx.runMgr.messages
726
+ const oldCount = live.length
727
+ await recordShed(ctx, [...live], newMessages, options?.force ? 'overflow' : 'threshold')
665
728
 
666
- messages.length = 0
667
- for (const msg of newMessages) {
668
- messages.push(msg)
669
- }
729
+ installMessages(live, newMessages)
670
730
 
671
731
  const newEstimate = estimateTokens(ctx)
672
732
 
@@ -676,6 +736,10 @@ export async function runCompactionCheck(
676
736
  // trigger check does not compare the old prompt size against the new
677
737
  // context and compact again immediately.
678
738
  ctx.runMgr.clearLastPromptTokens?.()
739
+ // The clear and the summary were one staged state transition. Publish the
740
+ // clear first for chronological audit semantics, but only now that both
741
+ // edits are installed and no verifier can still fail between them.
742
+ if (stagedClear) await emitToolResultClear(ctx, stagedClear)
679
743
 
680
744
  // Hysteresis. A pass that only gets the context from 0.72 to 0.71 of the
681
745
  // window leaves the trigger armed, so the next iteration compacts again
@@ -697,8 +761,8 @@ export async function runCompactionCheck(
697
761
  ctx.log.info('Context compacted', {
698
762
  [NAMZU.RUN_ID]: ctx.runMgr.id,
699
763
  'namzu.runtime.old_message_count': oldCount,
700
- 'namzu.runtime.new_message_count': messages.length,
701
- 'namzu.runtime.removed_messages': oldCount - messages.length,
764
+ 'namzu.runtime.new_message_count': live.length,
765
+ 'namzu.runtime.removed_messages': oldCount - live.length,
702
766
  'namzu.runtime.old_token_estimate': estimatedTokens,
703
767
  'namzu.runtime.new_token_estimate': newEstimate,
704
768
  'namzu.runtime.reduction_percent': Math.round((1 - newEstimate / estimatedTokens) * 100),
@@ -714,7 +778,7 @@ export async function runCompactionCheck(
714
778
  runId: ctx.runMgr.id,
715
779
  iteration: ctx.runMgr.currentIteration,
716
780
  messagesBefore: oldCount,
717
- messagesAfter: messages.length,
781
+ messagesAfter: live.length,
718
782
  tokensBefore: estimatedTokens,
719
783
  tokensAfter: newEstimate,
720
784
  measuredBy: measured.source,
@@ -722,4 +786,5 @@ export async function runCompactionCheck(
722
786
  windowSource: window.source,
723
787
  reachedResetThreshold: reachedReset,
724
788
  })
789
+ await emitContextUsageSnapshot(ctx, newEstimate, budget, window.source)
725
790
  }
@@ -37,6 +37,7 @@ import type { CheckpointManager } from '../../checkpoint.js'
37
37
  import type { EmitEvent } from '../../events.js'
38
38
  import type { ToolExecutor } from '../../executor.js'
39
39
  import type { GuardCoordinator } from '../../guard.js'
40
+ import type { ProjectInstructionContext } from '../../project-instructions.js'
40
41
  import type { RepeatCallTracker } from '../../repeat-call.js'
41
42
  import type { SteeringChannel } from '../../steering.js'
42
43
  import type { ToolGrantSet } from '../../tool-grants.js'
@@ -181,6 +182,9 @@ export interface IterationContext {
181
182
  */
182
183
  readonly inboundMessages?: () => readonly import('../../../../types/message/index.js').Message[]
183
184
 
185
+ /** Live project policy; separate from human inbound continuation. */
186
+ readonly projectInstructionContext?: ProjectInstructionContext
187
+
184
188
  readonly workingStateManager?: WorkingStateManager
185
189
 
186
190
  /**
@@ -2,6 +2,10 @@ import type { AuthorizationGate } from '../../../../authorization/index.js'
2
2
  import type { ChatCompletionResponse } from '../../../../types/provider/index.js'
3
3
  import type { RunEvent } from '../../../../types/run/index.js'
4
4
  import type { ToolCallDenials } from '../../executor.js'
5
+ import {
6
+ awaitProjectInstructionCallback,
7
+ replaceProjectInstructionSnapshot,
8
+ } from '../../project-instructions.js'
5
9
  import { attachRepeatNotice } from '../../repeat-call.js'
6
10
  import { attachSteering } from '../../steering.js'
7
11
  import { type IterationContext, awaitDecisionDurably } from './context.js'
@@ -100,6 +104,30 @@ export async function* runToolReview(
100
104
  for (const msg of attachRepeatNotice(attachSteering(batch.messages, ctx.steering), notices)) {
101
105
  ctx.runMgr.pushMessage(msg)
102
106
  }
107
+ // The complete tool-result batch is already in history before host policy
108
+ // may react, so a replacement cannot split provider-required adjacency.
109
+ // Commit each accepted observation before entering the next one. A single
110
+ // batch-end drain loses the accepted prefix when a later observer aborts.
111
+ // Nested registry dispatches are carried in this same ordered list.
112
+ if (ctx.projectInstructionContext) {
113
+ for (const observation of batch.observations) {
114
+ const signal = ctx.abortController.signal
115
+ const snapshot = await awaitProjectInstructionCallback(signal, () =>
116
+ ctx.projectInstructionContext?.observeToolResult(observation, {
117
+ messages: [...ctx.runMgr.messages],
118
+ signal,
119
+ }),
120
+ )
121
+ // Callback settlement and snapshot publication are distinct
122
+ // microtasks. Authority may be withdrawn between them.
123
+ signal.throwIfAborted()
124
+ if (snapshot !== undefined) {
125
+ ctx.runMgr.replaceMessages(
126
+ replaceProjectInstructionSnapshot(ctx.runMgr.messages, snapshot),
127
+ )
128
+ }
129
+ }
130
+ }
103
131
  }
104
132
 
105
133
  /** Every call denied for the same reason (human rejection, gate stop). */
@@ -219,6 +219,7 @@ export async function* streamProviderTurn(
219
219
  // them, and are collected verbatim: they are evidence, so reordering or
220
220
  // de-duplicating them would edit the record the reader checks against.
221
221
  const citations: Citation[] = []
222
+ let replayState: unknown
222
223
 
223
224
  let streamError: string | undefined
224
225
  let streamCause: unknown
@@ -310,6 +311,7 @@ export async function* streamProviderTurn(
310
311
  break
311
312
  }
312
313
  if (!id && chunk.id) id = chunk.id
314
+ if (chunk.replayState !== undefined) replayState = chunk.replayState
313
315
 
314
316
  // The first delta of the turn, of ANY kind — text, reasoning or a
315
317
  // tool call. namzu streams, so perceived latency is dominated by
@@ -686,6 +688,7 @@ export async function* streamProviderTurn(
686
688
  content: textBuf.length > 0 ? textBuf : null,
687
689
  toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
688
690
  ...(reasoningBlocks.length > 0 ? { reasoning: reasoningBlocks } : {}),
691
+ ...(replayState !== undefined ? { replayState } : {}),
689
692
  ...(citations.length > 0 ? { citations } : {}),
690
693
  },
691
694
  finishReason: effectiveFinishReason,