stitchkit 0.93.0 → 0.94.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 (791) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/README.md +5 -2
  3. package/dist/agent-runtime/children-control.d.ts +6 -0
  4. package/dist/agent-runtime/children-control.d.ts.map +1 -0
  5. package/dist/agent-runtime/children-spawn.d.ts +6 -0
  6. package/dist/agent-runtime/children-spawn.d.ts.map +1 -0
  7. package/dist/agent-runtime/children-state.d.ts +46 -0
  8. package/dist/agent-runtime/children-state.d.ts.map +1 -0
  9. package/dist/agent-runtime/children-usage.d.ts +8 -0
  10. package/dist/agent-runtime/children-usage.d.ts.map +1 -0
  11. package/dist/agent-runtime/children.d.ts +11 -14
  12. package/dist/agent-runtime/children.d.ts.map +1 -1
  13. package/dist/agent-runtime/coding-tool-contract.d.ts +2 -1
  14. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
  15. package/dist/agent-runtime/deferred-tool-types.d.ts +2 -2
  16. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
  17. package/dist/agent-runtime/events.d.ts +1 -1
  18. package/dist/agent-runtime/events.d.ts.map +1 -1
  19. package/dist/agent-runtime/managed-tools.d.ts +1 -1
  20. package/dist/agent-runtime/managed-tools.d.ts.map +1 -1
  21. package/dist/agent-runtime/observability.d.ts +1 -1
  22. package/dist/agent-runtime/observability.d.ts.map +1 -1
  23. package/dist/{agent-runtime-openrouter.d.ts → agent-runtime/openrouter.d.ts} +3 -3
  24. package/dist/agent-runtime/openrouter.d.ts.map +1 -0
  25. package/dist/agent-runtime/projections.d.ts +1 -1
  26. package/dist/agent-runtime/projections.d.ts.map +1 -1
  27. package/dist/agent-runtime/run-acquisition.d.ts +17 -0
  28. package/dist/agent-runtime/run-acquisition.d.ts.map +1 -0
  29. package/dist/agent-runtime/run-execution-state.d.ts +133 -0
  30. package/dist/agent-runtime/run-execution-state.d.ts.map +1 -0
  31. package/dist/agent-runtime/run-execution.d.ts +17 -33
  32. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  33. package/dist/agent-runtime/run-failure.d.ts +18 -0
  34. package/dist/agent-runtime/run-failure.d.ts.map +1 -0
  35. package/dist/agent-runtime/run-model-attempts.d.ts +6 -0
  36. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -0
  37. package/dist/agent-runtime/run-prompt-history.d.ts +58 -0
  38. package/dist/agent-runtime/run-prompt-history.d.ts.map +1 -0
  39. package/dist/agent-runtime/run-provider-ledger.d.ts +26 -0
  40. package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -0
  41. package/dist/agent-runtime/run-stream-parts.d.ts +17 -0
  42. package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -0
  43. package/dist/agent-runtime/run-terminal.d.ts +11 -0
  44. package/dist/agent-runtime/run-terminal.d.ts.map +1 -0
  45. package/dist/agent-runtime/run-turn-preparation.d.ts +22 -0
  46. package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -0
  47. package/dist/agent-runtime/runtime-admission-gate.d.ts +29 -0
  48. package/dist/agent-runtime/runtime-admission-gate.d.ts.map +1 -0
  49. package/dist/agent-runtime/runtime-control.d.ts +9 -0
  50. package/dist/agent-runtime/runtime-control.d.ts.map +1 -0
  51. package/dist/agent-runtime/runtime-recovery.d.ts +10 -0
  52. package/dist/agent-runtime/runtime-recovery.d.ts.map +1 -0
  53. package/dist/agent-runtime/runtime-state.d.ts +36 -0
  54. package/dist/agent-runtime/runtime-state.d.ts.map +1 -0
  55. package/dist/agent-runtime/runtime-submit.d.ts +5 -0
  56. package/dist/agent-runtime/runtime-submit.d.ts.map +1 -0
  57. package/dist/agent-runtime/runtime.d.ts +9 -4
  58. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  59. package/dist/{agent-runtime-sqlite-bun.d.ts → agent-runtime/sqlite-bun.d.ts} +5 -4
  60. package/dist/agent-runtime/sqlite-bun.d.ts.map +1 -0
  61. package/dist/agent-runtime/sqlite-events.d.ts +5 -0
  62. package/dist/agent-runtime/sqlite-events.d.ts.map +1 -0
  63. package/dist/agent-runtime/sqlite-history.d.ts +7 -0
  64. package/dist/agent-runtime/sqlite-history.d.ts.map +1 -0
  65. package/dist/agent-runtime/sqlite-ledger.d.ts +7 -0
  66. package/dist/agent-runtime/sqlite-ledger.d.ts.map +1 -0
  67. package/dist/{agent-runtime-sqlite-node.d.ts → agent-runtime/sqlite-node.d.ts} +5 -4
  68. package/dist/agent-runtime/sqlite-node.d.ts.map +1 -0
  69. package/dist/agent-runtime/sqlite-reads.d.ts +14 -0
  70. package/dist/agent-runtime/sqlite-reads.d.ts.map +1 -0
  71. package/dist/agent-runtime/sqlite-rows.d.ts +178 -0
  72. package/dist/agent-runtime/sqlite-rows.d.ts.map +1 -0
  73. package/dist/agent-runtime/sqlite-schema.d.ts +7 -0
  74. package/dist/agent-runtime/sqlite-schema.d.ts.map +1 -0
  75. package/dist/agent-runtime/sqlite-transactions.d.ts +25 -0
  76. package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -0
  77. package/dist/agent-runtime/sqlite.d.ts +10 -6
  78. package/dist/agent-runtime/sqlite.d.ts.map +1 -1
  79. package/dist/agent-runtime/store-archive.d.ts +16 -0
  80. package/dist/agent-runtime/store-archive.d.ts.map +1 -0
  81. package/dist/{testing/agent-store-conformance.d.ts → agent-runtime/store-conformance.d.ts} +2 -2
  82. package/dist/agent-runtime/store-conformance.d.ts.map +1 -0
  83. package/dist/agent-runtime/store-create.d.ts +11 -0
  84. package/dist/agent-runtime/store-create.d.ts.map +1 -0
  85. package/dist/agent-runtime/{store-driver.d.ts → store-driver-contract.d.ts} +7 -7
  86. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -0
  87. package/dist/agent-runtime/store-events.d.ts +7 -89
  88. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  89. package/dist/agent-runtime/store-memory.d.ts +4 -0
  90. package/dist/agent-runtime/store-memory.d.ts.map +1 -0
  91. package/dist/agent-runtime/store-mutate.d.ts +13 -0
  92. package/dist/agent-runtime/store-mutate.d.ts.map +1 -0
  93. package/dist/agent-runtime/store-purge.d.ts +1 -1
  94. package/dist/agent-runtime/store-purge.d.ts.map +1 -1
  95. package/dist/agent-runtime/store-reads.d.ts +29 -0
  96. package/dist/agent-runtime/store-reads.d.ts.map +1 -0
  97. package/dist/agent-runtime/store-reduce-history.d.ts +10 -0
  98. package/dist/agent-runtime/store-reduce-history.d.ts.map +1 -0
  99. package/dist/agent-runtime/store-reduce-run.d.ts +14 -0
  100. package/dist/agent-runtime/store-reduce-run.d.ts.map +1 -0
  101. package/dist/agent-runtime/store-reduce-shared.d.ts +76 -0
  102. package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -0
  103. package/dist/agent-runtime/store-reduce-terminal.d.ts +6 -0
  104. package/dist/agent-runtime/store-reduce-terminal.d.ts.map +1 -0
  105. package/dist/agent-runtime/store-reducer.d.ts +24 -0
  106. package/dist/agent-runtime/store-reducer.d.ts.map +1 -0
  107. package/dist/agent-runtime/store-snapshot.d.ts +19 -0
  108. package/dist/agent-runtime/store-snapshot.d.ts.map +1 -0
  109. package/dist/agent-runtime/store.d.ts +1 -1
  110. package/dist/agent-runtime/store.d.ts.map +1 -1
  111. package/dist/application/admission.d.ts +1 -1
  112. package/dist/application/admission.d.ts.map +1 -1
  113. package/dist/application/events.d.ts +1 -1
  114. package/dist/application/events.d.ts.map +1 -1
  115. package/dist/{server → application}/file-state-store.d.ts +1 -1
  116. package/dist/application/file-state-store.d.ts.map +1 -0
  117. package/dist/application/health.d.ts +1 -1
  118. package/dist/application/health.d.ts.map +1 -1
  119. package/dist/application/kernel-admission.d.ts +8 -0
  120. package/dist/application/kernel-admission.d.ts.map +1 -0
  121. package/dist/application/kernel-contract.d.ts +142 -0
  122. package/dist/application/kernel-contract.d.ts.map +1 -0
  123. package/dist/application/kernel-resource-context.d.ts +24 -0
  124. package/dist/application/kernel-resource-context.d.ts.map +1 -0
  125. package/dist/application/kernel-restart.d.ts +5 -0
  126. package/dist/application/kernel-restart.d.ts.map +1 -0
  127. package/dist/application/kernel-rollback.d.ts +4 -0
  128. package/dist/application/kernel-rollback.d.ts.map +1 -0
  129. package/dist/application/kernel-shutdown.d.ts +6 -0
  130. package/dist/application/kernel-shutdown.d.ts.map +1 -0
  131. package/dist/application/kernel-start.d.ts +20 -0
  132. package/dist/application/kernel-start.d.ts.map +1 -0
  133. package/dist/application/kernel-state.d.ts +116 -0
  134. package/dist/application/kernel-state.d.ts.map +1 -0
  135. package/dist/application/kernel.d.ts +9 -140
  136. package/dist/application/kernel.d.ts.map +1 -1
  137. package/dist/application/latest-sink.d.ts +1 -1
  138. package/dist/application/latest-sink.d.ts.map +1 -1
  139. package/dist/application/opentelemetry.d.ts +1 -1
  140. package/dist/application/opentelemetry.d.ts.map +1 -1
  141. package/dist/application/watch-hub.d.ts +2 -2
  142. package/dist/application/watch-hub.d.ts.map +1 -1
  143. package/dist/browser/client-multipart.d.ts +1 -1
  144. package/dist/browser/client-multipart.d.ts.map +1 -1
  145. package/dist/browser/client-url.d.ts +1 -1
  146. package/dist/browser/client-url.d.ts.map +1 -1
  147. package/dist/browser/client.d.ts +1 -1
  148. package/dist/browser/client.d.ts.map +1 -1
  149. package/dist/browser/contract-stream.d.ts +1 -1
  150. package/dist/browser/contract-stream.d.ts.map +1 -1
  151. package/dist/browser/http.d.ts +1 -1
  152. package/dist/browser/http.d.ts.map +1 -1
  153. package/dist/browser/resumable.d.ts +1 -28
  154. package/dist/browser/resumable.d.ts.map +1 -1
  155. package/dist/browser/retained.d.ts.map +1 -0
  156. package/dist/browser/socket-io.d.ts +23 -1
  157. package/dist/browser/socket-io.d.ts.map +1 -1
  158. package/dist/browser/stream.d.ts +14 -2
  159. package/dist/browser/stream.d.ts.map +1 -1
  160. package/dist/contract/define.d.ts +72 -65
  161. package/dist/contract/define.d.ts.map +1 -1
  162. package/dist/{internal/errors.d.ts → contract/normalize.d.ts} +3 -39
  163. package/dist/contract/normalize.d.ts.map +1 -0
  164. package/dist/contract/tool-view.d.ts +135 -0
  165. package/dist/contract/tool-view.d.ts.map +1 -0
  166. package/dist/declaration/declaration.d.ts.map +1 -0
  167. package/dist/{agent-runtime/durability-contract.d.ts → durability/contract.d.ts} +2 -2
  168. package/dist/durability/contract.d.ts.map +1 -0
  169. package/dist/{agent-runtime/durability.d.ts → durability/engine.d.ts} +4 -4
  170. package/dist/durability/engine.d.ts.map +1 -0
  171. package/dist/durability/events.d.ts +101 -0
  172. package/dist/durability/events.d.ts.map +1 -0
  173. package/dist/{agent-runtime/durability-json.d.ts → durability/json.d.ts} +1 -1
  174. package/dist/durability/json.d.ts.map +1 -0
  175. package/dist/{agent-runtime/durability-ledger.d.ts → durability/ledger.d.ts} +2 -2
  176. package/dist/durability/ledger.d.ts.map +1 -0
  177. package/dist/{agent-runtime/durability-scheduler.d.ts → durability/scheduler.d.ts} +2 -2
  178. package/dist/durability/scheduler.d.ts.map +1 -0
  179. package/dist/entrypoints/agent-runtime/browser.d.ts +5 -0
  180. package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -0
  181. package/dist/{agent-runtime-browser.js → entrypoints/agent-runtime/browser.js} +3 -3
  182. package/dist/{agent-runtime-coding-tools.d.ts → entrypoints/agent-runtime/coding-tools.d.ts} +2 -2
  183. package/dist/entrypoints/agent-runtime/coding-tools.d.ts.map +1 -0
  184. package/dist/entrypoints/agent-runtime/coding-tools.js +22 -0
  185. package/dist/{agent-runtime-harness.d.ts → entrypoints/agent-runtime/harness.d.ts} +2 -2
  186. package/dist/entrypoints/agent-runtime/harness.d.ts.map +1 -0
  187. package/dist/{agent-runtime-harness.js → entrypoints/agent-runtime/harness.js} +24 -25
  188. package/dist/entrypoints/agent-runtime/openrouter.d.ts +2 -0
  189. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -0
  190. package/dist/{agent-runtime-openrouter.js → entrypoints/agent-runtime/openrouter.js} +3 -3
  191. package/dist/{agent-runtime-sandbox.d.ts → entrypoints/agent-runtime/sandbox.d.ts} +5 -5
  192. package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -0
  193. package/dist/{agent-runtime-sandbox.js → entrypoints/agent-runtime/sandbox.js} +11 -12
  194. package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts +2 -0
  195. package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts.map +1 -0
  196. package/dist/{agent-runtime-sqlite-bun.js → entrypoints/agent-runtime/sqlite/bun.js} +8 -6
  197. package/dist/entrypoints/agent-runtime/sqlite/node.d.ts +2 -0
  198. package/dist/entrypoints/agent-runtime/sqlite/node.d.ts.map +1 -0
  199. package/dist/{agent-runtime-sqlite-node.js → entrypoints/agent-runtime/sqlite/node.js} +8 -6
  200. package/dist/entrypoints/agent-runtime/testing.d.ts +4 -0
  201. package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -0
  202. package/dist/entrypoints/agent-runtime/testing.js +1084 -0
  203. package/dist/{agent-runtime.d.ts → entrypoints/agent-runtime.d.ts} +41 -37
  204. package/dist/entrypoints/agent-runtime.d.ts.map +1 -0
  205. package/dist/{agent-runtime.js → entrypoints/agent-runtime.js} +408 -366
  206. package/dist/{application-diagnostic-journal.d.ts → entrypoints/application/diagnostic-journal.d.ts} +2 -2
  207. package/dist/entrypoints/application/diagnostic-journal.d.ts.map +1 -0
  208. package/dist/{application-diagnostic-journal.js → entrypoints/application/diagnostic-journal.js} +3 -3
  209. package/dist/{application-grammy.d.ts → entrypoints/application/grammy.d.ts} +2 -2
  210. package/dist/entrypoints/application/grammy.d.ts.map +1 -0
  211. package/dist/{application-grammy.js → entrypoints/application/grammy.js} +2 -2
  212. package/dist/{application-opentelemetry.d.ts → entrypoints/application/opentelemetry.d.ts} +2 -2
  213. package/dist/entrypoints/application/opentelemetry.d.ts.map +1 -0
  214. package/dist/{application-opentelemetry.js → entrypoints/application/opentelemetry.js} +4 -4
  215. package/dist/{application-schemas.d.ts → entrypoints/application/schemas.d.ts} +2 -2
  216. package/dist/entrypoints/application/schemas.d.ts.map +1 -0
  217. package/dist/{application-schemas.js → entrypoints/application/schemas.js} +2 -2
  218. package/dist/{application.d.ts → entrypoints/application.d.ts} +22 -21
  219. package/dist/entrypoints/application.d.ts.map +1 -0
  220. package/dist/{application.js → entrypoints/application.js} +24 -22
  221. package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -0
  222. package/dist/{upgrade-cli.js → entrypoints/bin/upgrade-cli.js} +3 -3
  223. package/dist/{cli.d.ts → entrypoints/cli.d.ts} +15 -15
  224. package/dist/entrypoints/cli.d.ts.map +1 -0
  225. package/dist/{cli.js → entrypoints/cli.js} +30 -32
  226. package/dist/entrypoints/contract.d.ts +9 -0
  227. package/dist/entrypoints/contract.d.ts.map +1 -0
  228. package/dist/{contract/index.js → entrypoints/contract.js} +14 -6
  229. package/dist/entrypoints/declaration.d.ts +2 -0
  230. package/dist/entrypoints/declaration.d.ts.map +1 -0
  231. package/dist/{declaration.js → entrypoints/declaration.js} +1 -1
  232. package/dist/{files.d.ts → entrypoints/files.d.ts} +2 -2
  233. package/dist/entrypoints/files.d.ts.map +1 -0
  234. package/dist/{files.js → entrypoints/files.js} +3 -3
  235. package/dist/{geo.d.ts → entrypoints/geo.d.ts} +1 -1
  236. package/dist/entrypoints/geo.d.ts.map +1 -0
  237. package/dist/{geo.js → entrypoints/geo.js} +4 -4
  238. package/dist/entrypoints/google.d.ts +2 -0
  239. package/dist/entrypoints/google.d.ts.map +1 -0
  240. package/dist/{google.js → entrypoints/google.js} +1 -1
  241. package/dist/{index.d.ts → entrypoints/index.d.ts} +14 -13
  242. package/dist/entrypoints/index.d.ts.map +1 -0
  243. package/dist/{index.js → entrypoints/index.js} +99 -33
  244. package/dist/{live.d.ts → entrypoints/live.d.ts} +4 -4
  245. package/dist/entrypoints/live.d.ts.map +1 -0
  246. package/dist/{live.js → entrypoints/live.js} +6 -4
  247. package/dist/{node.d.ts → entrypoints/node.d.ts} +11 -11
  248. package/dist/entrypoints/node.d.ts.map +1 -0
  249. package/dist/{node.js → entrypoints/node.js} +20 -16
  250. package/dist/entrypoints/oauth.d.ts +2 -0
  251. package/dist/entrypoints/oauth.d.ts.map +1 -0
  252. package/dist/{oauth.js → entrypoints/oauth.js} +3 -3
  253. package/dist/{observability/index.d.ts → entrypoints/observability.d.ts} +11 -11
  254. package/dist/entrypoints/observability.d.ts.map +1 -0
  255. package/dist/{observability/index.js → entrypoints/observability.js} +9 -11
  256. package/dist/entrypoints/primitives.d.ts +3 -0
  257. package/dist/entrypoints/primitives.d.ts.map +1 -0
  258. package/dist/{primitives.js → entrypoints/primitives.js} +1 -6
  259. package/dist/{react.d.ts → entrypoints/react.d.ts} +4 -4
  260. package/dist/entrypoints/react.d.ts.map +1 -0
  261. package/dist/{react.js → entrypoints/react.js} +3 -3
  262. package/dist/{release.d.ts → entrypoints/release.d.ts} +4 -4
  263. package/dist/entrypoints/release.d.ts.map +1 -0
  264. package/dist/{release.js → entrypoints/release.js} +1 -1
  265. package/dist/{remote.d.ts → entrypoints/remote.d.ts} +1 -1
  266. package/dist/entrypoints/remote.d.ts.map +1 -0
  267. package/dist/entrypoints/remote.js +66 -0
  268. package/dist/{server/index.d.ts → entrypoints/server.d.ts} +35 -34
  269. package/dist/entrypoints/server.d.ts.map +1 -0
  270. package/dist/{server/index.js → entrypoints/server.js} +294 -244
  271. package/dist/{telegram.d.ts → entrypoints/telegram.d.ts} +2 -2
  272. package/dist/entrypoints/telegram.d.ts.map +1 -0
  273. package/dist/{telegram.js → entrypoints/telegram.js} +1 -1
  274. package/dist/entrypoints/testing.d.ts +9 -0
  275. package/dist/entrypoints/testing.d.ts.map +1 -0
  276. package/dist/{testing.js → entrypoints/testing.js} +80 -919
  277. package/dist/{tools/connections/index.d.ts → entrypoints/tools/connections.d.ts} +6 -7
  278. package/dist/entrypoints/tools/connections.d.ts.map +1 -0
  279. package/dist/{tools/connections/index.js → entrypoints/tools/connections.js} +7 -4
  280. package/dist/{tools-contract.d.ts → entrypoints/tools/contract.d.ts} +5 -5
  281. package/dist/entrypoints/tools/contract.d.ts.map +1 -0
  282. package/dist/{tools-contract.js → entrypoints/tools/contract.js} +4 -4
  283. package/dist/{tool-invoker.d.ts → entrypoints/tools/invoker.d.ts} +2 -2
  284. package/dist/entrypoints/tools/invoker.d.ts.map +1 -0
  285. package/dist/entrypoints/tools/invoker.js +20 -0
  286. package/dist/entrypoints/tools.d.ts +51 -0
  287. package/dist/entrypoints/tools.d.ts.map +1 -0
  288. package/dist/{tools.js → entrypoints/tools.js} +1787 -1751
  289. package/dist/{tracking-server.d.ts → entrypoints/tracking/server.d.ts} +8 -8
  290. package/dist/entrypoints/tracking/server.d.ts.map +1 -0
  291. package/dist/{tracking.d.ts → entrypoints/tracking.d.ts} +15 -15
  292. package/dist/entrypoints/tracking.d.ts.map +1 -0
  293. package/dist/{tracking.js → entrypoints/tracking.js} +5 -8
  294. package/dist/google/google.d.ts.map +1 -0
  295. package/dist/{index-a916km3r.js → index-0b1ess5e.js} +6 -13
  296. package/dist/{index-zwkgfq1s.js → index-1nd48tm9.js} +113 -118
  297. package/dist/{index-7zbps32p.js → index-1zbbzgfh.js} +2 -2
  298. package/dist/{index-mzvgxp0n.js → index-2cr1cqhn.js} +16 -4
  299. package/dist/{index-f9mb610r.js → index-35mh5bhj.js} +2 -2
  300. package/dist/index-48ffdxgk.js +6 -0
  301. package/dist/index-58k4fp34.js +1023 -0
  302. package/dist/{index-p13mwz16.js → index-83bdg97s.js} +1 -1
  303. package/dist/index-97ac4gph.js +3618 -0
  304. package/dist/{index-kw9t5ayn.js → index-cq4qfycf.js} +5 -5
  305. package/dist/{index-7gnkny4z.js → index-d9pk3td4.js} +1 -1
  306. package/dist/{index-e42wzzz5.js → index-dcpdvjsc.js} +7 -7
  307. package/dist/{index-h9etkkyk.js → index-dydjcp8z.js} +102 -25
  308. package/dist/{index-sr93cwf9.js → index-e2z3ahw9.js} +2 -2
  309. package/dist/{index-yewwh1w4.js → index-e87kakm4.js} +96 -11
  310. package/dist/{index-cby4ar3v.js → index-eqqvgdb3.js} +1 -1
  311. package/dist/index-fdp6hdxn.js +942 -0
  312. package/dist/{index-0a349c33.js → index-gyr48nzg.js} +125 -198
  313. package/dist/{index-wnfk50r0.js → index-h6eeys1v.js} +1 -1
  314. package/dist/{index-77fekveh.js → index-hffjpmq9.js} +1 -15
  315. package/dist/{index-yn8remb1.js → index-j05z5gn4.js} +50 -14
  316. package/dist/index-k5hsfc3j.js +31 -0
  317. package/dist/{index-fq77yfzc.js → index-kj2wbeta.js} +1 -1
  318. package/dist/index-kvj7f4hq.js +39 -0
  319. package/dist/{index-4fpa9dy2.js → index-m9zn6cpq.js} +2 -2
  320. package/dist/{index-2na0qrfn.js → index-mdzh02yc.js} +7 -7
  321. package/dist/{index-ywd0y6m1.js → index-mkm15s49.js} +1 -1
  322. package/dist/index-mp5sn43f.js +1084 -0
  323. package/dist/{index-3bmnp41g.js → index-n6hxg8as.js} +507 -419
  324. package/dist/index-ngfhvfpd.js +30 -0
  325. package/dist/{index-e0znv5gn.js → index-p5r7qpdd.js} +2 -93
  326. package/dist/{index-n0f51dfn.js → index-p81267c2.js} +608 -549
  327. package/dist/{index-wc4x00bn.js → index-qwhynv6x.js} +1 -1
  328. package/dist/index-r7nmqpsg.js +154 -0
  329. package/dist/{index-bx75zwt7.js → index-rewkc2hj.js} +5 -4
  330. package/dist/{index-9f8ztey6.js → index-sees8yf8.js} +2 -2
  331. package/dist/{index-vjpvjqpn.js → index-v38qyerb.js} +16 -2
  332. package/dist/{index-2c2bjw3s.js → index-vcvkq30w.js} +3 -3
  333. package/dist/index-wqgjfstn.js +18 -0
  334. package/dist/{index-f477k430.js → index-x4799c19.js} +1 -1
  335. package/dist/{index-cxqhvq21.js → index-xnj9bgxe.js} +142 -129
  336. package/dist/index-xsqjkha9.js +281 -0
  337. package/dist/{index-6kyksz9y.js → index-yw4fzmdz.js} +1 -1
  338. package/dist/{index-3xwxfj4z.js → index-zeemqhqx.js} +1 -1
  339. package/dist/{index-tmwcrptx.js → index-zfrhfn82.js} +1 -1
  340. package/dist/index-znfs20ss.js +98 -0
  341. package/dist/internal/backoff.d.ts +29 -0
  342. package/dist/internal/backoff.d.ts.map +1 -0
  343. package/dist/internal/canonical-json.d.ts +21 -11
  344. package/dist/internal/canonical-json.d.ts.map +1 -1
  345. package/dist/internal/channel.d.ts.map +1 -0
  346. package/dist/internal/logger.d.ts.map +1 -0
  347. package/dist/internal/request.d.ts.map +1 -0
  348. package/dist/internal/stable-digest.d.ts +0 -43
  349. package/dist/internal/stable-digest.d.ts.map +1 -1
  350. package/dist/internal/typed.d.ts +0 -8
  351. package/dist/internal/typed.d.ts.map +1 -1
  352. package/dist/internal/zod-issues.d.ts +38 -0
  353. package/dist/internal/zod-issues.d.ts.map +1 -0
  354. package/dist/{tools/json-schema-dialect.d.ts → json-schema/dialect.d.ts} +1 -1
  355. package/dist/json-schema/dialect.d.ts.map +1 -0
  356. package/dist/json-schema/json-schema.d.ts.map +1 -0
  357. package/dist/live/watch-delta.d.ts.map +1 -1
  358. package/dist/{oauth.d.ts → oauth/authorization-code.d.ts} +1 -1
  359. package/dist/oauth/authorization-code.d.ts.map +1 -0
  360. package/dist/observability/audit.d.ts +2 -2
  361. package/dist/observability/audit.d.ts.map +1 -1
  362. package/dist/observability/bounded-logger.d.ts +1 -1
  363. package/dist/observability/bounded-logger.d.ts.map +1 -1
  364. package/dist/{internal/observability-sink.d.ts → observability/bounded-sink.d.ts} +2 -2
  365. package/dist/observability/bounded-sink.d.ts.map +1 -0
  366. package/dist/observability/context.d.ts +1 -1
  367. package/dist/observability/context.d.ts.map +1 -1
  368. package/dist/observability/event.d.ts +1 -1
  369. package/dist/observability/event.d.ts.map +1 -1
  370. package/dist/observability/work.d.ts +1 -1
  371. package/dist/observability/work.d.ts.map +1 -1
  372. package/dist/primitives/audit.d.ts +1 -1
  373. package/dist/primitives/audit.d.ts.map +1 -1
  374. package/dist/primitives/export-operation.d.ts +4 -2
  375. package/dist/primitives/export-operation.d.ts.map +1 -1
  376. package/dist/realtime/socket.d.ts +1 -1
  377. package/dist/realtime/socket.d.ts.map +1 -1
  378. package/dist/server/context-contribution.d.ts +1 -1
  379. package/dist/server/context-contribution.d.ts.map +1 -1
  380. package/dist/server/context.d.ts +2 -2
  381. package/dist/server/context.d.ts.map +1 -1
  382. package/dist/server/contract-method.d.ts +15 -0
  383. package/dist/server/contract-method.d.ts.map +1 -0
  384. package/dist/server/contract-stream.d.ts +1 -1
  385. package/dist/server/contract-stream.d.ts.map +1 -1
  386. package/dist/server/create.d.ts +8 -0
  387. package/dist/server/create.d.ts.map +1 -1
  388. package/dist/server/endpoint-dispatch.d.ts +10 -0
  389. package/dist/server/endpoint-dispatch.d.ts.map +1 -0
  390. package/dist/server/endpoint-response.d.ts +18 -0
  391. package/dist/server/endpoint-response.d.ts.map +1 -0
  392. package/dist/server/error-dispatch.d.ts +17 -1
  393. package/dist/server/error-dispatch.d.ts.map +1 -1
  394. package/dist/server/error-hook.d.ts +2 -2
  395. package/dist/server/error-hook.d.ts.map +1 -1
  396. package/dist/server/handler-state.d.ts +44 -0
  397. package/dist/server/handler-state.d.ts.map +1 -0
  398. package/dist/server/implement.d.ts +1 -1
  399. package/dist/server/implement.d.ts.map +1 -1
  400. package/dist/server/middleware/auth.d.ts +1 -1
  401. package/dist/server/middleware/auth.d.ts.map +1 -1
  402. package/dist/server/middleware/cors.d.ts +17 -0
  403. package/dist/server/middleware/cors.d.ts.map +1 -1
  404. package/dist/server/middleware/trust-fence.d.ts +1 -1
  405. package/dist/server/middleware/trust-fence.d.ts.map +1 -1
  406. package/dist/server/multipart.d.ts +1 -1
  407. package/dist/server/multipart.d.ts.map +1 -1
  408. package/dist/{tools/oauth-metadata.d.ts → server/oauth/metadata.d.ts} +2 -2
  409. package/dist/server/oauth/metadata.d.ts.map +1 -0
  410. package/dist/{tools/oauth-provider.d.ts → server/oauth/provider.d.ts} +2 -2
  411. package/dist/server/oauth/provider.d.ts.map +1 -0
  412. package/dist/server/realtime.d.ts +1 -1
  413. package/dist/server/realtime.d.ts.map +1 -1
  414. package/dist/server/request-completion.d.ts +16 -0
  415. package/dist/server/request-completion.d.ts.map +1 -0
  416. package/dist/server/response-metadata.d.ts +1 -1
  417. package/dist/server/response-metadata.d.ts.map +1 -1
  418. package/dist/server/route-table.d.ts +9 -0
  419. package/dist/server/route-table.d.ts.map +1 -0
  420. package/dist/server/stream.d.ts +0 -13
  421. package/dist/server/stream.d.ts.map +1 -1
  422. package/dist/server/types.d.ts +7 -4
  423. package/dist/server/types.d.ts.map +1 -1
  424. package/dist/testing/handler-clients.d.ts +31 -0
  425. package/dist/testing/handler-clients.d.ts.map +1 -0
  426. package/dist/testing/managed-resource-conformance-scenarios.d.ts.map +1 -1
  427. package/dist/testing/surface-conformance.d.ts +2 -1
  428. package/dist/testing/surface-conformance.d.ts.map +1 -1
  429. package/dist/testing/surface-manifest.d.ts +30 -4
  430. package/dist/testing/surface-manifest.d.ts.map +1 -1
  431. package/dist/tools/{cli-args.d.ts → cli/args.d.ts} +1 -1
  432. package/dist/tools/cli/args.d.ts.map +1 -0
  433. package/dist/tools/{cli-checkpoint.d.ts → cli/checkpoint.d.ts} +1 -1
  434. package/dist/tools/cli/checkpoint.d.ts.map +1 -0
  435. package/dist/tools/{cli-command.d.ts → cli/command.d.ts} +4 -4
  436. package/dist/tools/cli/command.d.ts.map +1 -0
  437. package/dist/tools/{cli.d.ts → cli/config.d.ts} +5 -9
  438. package/dist/tools/cli/config.d.ts.map +1 -0
  439. package/dist/tools/cli/create-cli.d.ts +36 -0
  440. package/dist/tools/cli/create-cli.d.ts.map +1 -0
  441. package/dist/tools/cli/download.d.ts +8 -0
  442. package/dist/tools/cli/download.d.ts.map +1 -0
  443. package/dist/tools/{cli-format.d.ts → cli/format.d.ts} +2 -2
  444. package/dist/tools/cli/format.d.ts.map +1 -0
  445. package/dist/tools/cli/help.d.ts +24 -0
  446. package/dist/tools/cli/help.d.ts.map +1 -0
  447. package/dist/tools/{cli-installer.d.ts → cli/installer.d.ts} +2 -2
  448. package/dist/tools/cli/installer.d.ts.map +1 -0
  449. package/dist/tools/{cli-invoke.d.ts → cli/invoke.d.ts} +8 -8
  450. package/dist/tools/cli/invoke.d.ts.map +1 -0
  451. package/dist/tools/cli/io.d.ts +10 -0
  452. package/dist/tools/cli/io.d.ts.map +1 -0
  453. package/dist/tools/cli/managed-surface.d.ts +30 -0
  454. package/dist/tools/cli/managed-surface.d.ts.map +1 -0
  455. package/dist/tools/{cli-manifest.d.ts → cli/manifest.d.ts} +1 -1
  456. package/dist/tools/cli/manifest.d.ts.map +1 -0
  457. package/dist/tools/{cli-policy.d.ts → cli/policy.d.ts} +2 -2
  458. package/dist/tools/cli/policy.d.ts.map +1 -0
  459. package/dist/tools/cli/prepare.d.ts +14 -0
  460. package/dist/tools/cli/prepare.d.ts.map +1 -0
  461. package/dist/tools/{cli-profile.d.ts → cli/profile.d.ts} +2 -2
  462. package/dist/tools/cli/profile.d.ts.map +1 -0
  463. package/dist/tools/cli/run-managed.d.ts +5 -0
  464. package/dist/tools/cli/run-managed.d.ts.map +1 -0
  465. package/dist/tools/cli/run-native.d.ts +9 -0
  466. package/dist/tools/cli/run-native.d.ts.map +1 -0
  467. package/dist/tools/cli/session.d.ts +40 -0
  468. package/dist/tools/cli/session.d.ts.map +1 -0
  469. package/dist/tools/{cli-signature.d.ts → cli/signature.d.ts} +2 -2
  470. package/dist/tools/cli/signature.d.ts.map +1 -0
  471. package/dist/tools/{cli-stream.d.ts → cli/stream.d.ts} +4 -4
  472. package/dist/tools/cli/stream.d.ts.map +1 -0
  473. package/dist/tools/{cli-update.d.ts → cli/update.d.ts} +3 -3
  474. package/dist/tools/cli/update.d.ts.map +1 -0
  475. package/dist/tools/{cli-view.d.ts → cli/view.d.ts} +2 -2
  476. package/dist/tools/cli/view.d.ts.map +1 -0
  477. package/dist/tools/{cli-wait.d.ts → cli/wait.d.ts} +2 -2
  478. package/dist/tools/cli/wait.d.ts.map +1 -0
  479. package/dist/tools/connections/runtime.d.ts +1 -1
  480. package/dist/tools/connections/runtime.d.ts.map +1 -1
  481. package/dist/tools/connections/types.d.ts +3 -3
  482. package/dist/tools/connections/types.d.ts.map +1 -1
  483. package/dist/tools/durability-context.d.ts +1 -1
  484. package/dist/tools/durability-context.d.ts.map +1 -1
  485. package/dist/tools/execute.d.ts +30 -3
  486. package/dist/tools/execute.d.ts.map +1 -1
  487. package/dist/tools/internal/surface-projector.d.ts +8 -6
  488. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  489. package/dist/tools/internal/tool-view.d.ts +41 -0
  490. package/dist/tools/internal/tool-view.d.ts.map +1 -0
  491. package/dist/tools/invoker.d.ts +11 -3
  492. package/dist/tools/invoker.d.ts.map +1 -1
  493. package/dist/tools/list-names.d.ts +3 -3
  494. package/dist/tools/list-names.d.ts.map +1 -1
  495. package/dist/tools/manifest.d.ts +2 -2
  496. package/dist/tools/manifest.d.ts.map +1 -1
  497. package/dist/tools/{mcp-app.d.ts → mcp/app.d.ts} +1 -1
  498. package/dist/tools/mcp/app.d.ts.map +1 -0
  499. package/dist/tools/{mcp-catalog.d.ts → mcp/catalog.d.ts} +2 -2
  500. package/dist/tools/mcp/catalog.d.ts.map +1 -0
  501. package/dist/tools/{mcp-handler.d.ts → mcp/handler.d.ts} +5 -5
  502. package/dist/tools/mcp/handler.d.ts.map +1 -0
  503. package/dist/tools/{mcp.d.ts → mcp/mount.d.ts} +9 -9
  504. package/dist/tools/mcp/mount.d.ts.map +1 -0
  505. package/dist/tools/{mcp-prepare.d.ts → mcp/prepare.d.ts} +9 -9
  506. package/dist/tools/mcp/prepare.d.ts.map +1 -0
  507. package/dist/tools/{mcp-progress.d.ts → mcp/progress.d.ts} +2 -2
  508. package/dist/tools/mcp/progress.d.ts.map +1 -0
  509. package/dist/tools/mcp/register.d.ts +35 -0
  510. package/dist/tools/mcp/register.d.ts.map +1 -0
  511. package/dist/tools/{mcp-round-policy.d.ts → mcp/round-policy.d.ts} +2 -2
  512. package/dist/tools/mcp/round-policy.d.ts.map +1 -0
  513. package/dist/tools/{mcp-round.d.ts → mcp/round.d.ts} +4 -4
  514. package/dist/tools/mcp/round.d.ts.map +1 -0
  515. package/dist/tools/mcp/runtime-tools.d.ts +24 -0
  516. package/dist/tools/mcp/runtime-tools.d.ts.map +1 -0
  517. package/dist/tools/{mcp-stdio-signals.d.ts → mcp/stdio-signals.d.ts} +3 -3
  518. package/dist/tools/mcp/stdio-signals.d.ts.map +1 -0
  519. package/dist/tools/{mcp-stdio.d.ts → mcp/stdio.d.ts} +4 -4
  520. package/dist/tools/mcp/stdio.d.ts.map +1 -0
  521. package/dist/tools/{mcp-trace.d.ts → mcp/trace.d.ts} +1 -1
  522. package/dist/tools/mcp/trace.d.ts.map +1 -0
  523. package/dist/tools/mount.d.ts +12 -7
  524. package/dist/tools/mount.d.ts.map +1 -1
  525. package/dist/tools/native-definition.d.ts +3 -3
  526. package/dist/tools/native-definition.d.ts.map +1 -1
  527. package/dist/tools/operations/async-operation-binding-types.d.ts +127 -0
  528. package/dist/tools/operations/async-operation-binding-types.d.ts.map +1 -0
  529. package/dist/tools/operations/async-operation-binding.d.ts +28 -0
  530. package/dist/tools/operations/async-operation-binding.d.ts.map +1 -0
  531. package/dist/tools/operations/async-operation-canonical-types.d.ts +110 -0
  532. package/dist/tools/operations/async-operation-canonical-types.d.ts.map +1 -0
  533. package/dist/tools/operations/async-operation-canonical.d.ts +7 -0
  534. package/dist/tools/operations/async-operation-canonical.d.ts.map +1 -0
  535. package/dist/tools/operations/async-operation-contract.d.ts.map +1 -0
  536. package/dist/tools/operations/async-operation-id.d.ts +23 -0
  537. package/dist/tools/operations/async-operation-id.d.ts.map +1 -0
  538. package/dist/tools/operations/async-operation-runtime-tools.d.ts +40 -0
  539. package/dist/tools/operations/async-operation-runtime-tools.d.ts.map +1 -0
  540. package/dist/tools/operations/async-operation-runtime-types.d.ts +68 -0
  541. package/dist/tools/operations/async-operation-runtime-types.d.ts.map +1 -0
  542. package/dist/tools/operations/async-operation-runtime.d.ts +5 -0
  543. package/dist/tools/operations/async-operation-runtime.d.ts.map +1 -0
  544. package/dist/tools/{define-wait-tool.d.ts → operations/define-wait-tool.d.ts} +2 -2
  545. package/dist/tools/operations/define-wait-tool.d.ts.map +1 -0
  546. package/dist/tools/operations/mount-wait.d.ts.map +1 -0
  547. package/dist/tools/operations/wait-core.d.ts.map +1 -0
  548. package/dist/tools/remote.d.ts +1 -1
  549. package/dist/tools/remote.d.ts.map +1 -1
  550. package/dist/tools/runtime-tool.d.ts +11 -4
  551. package/dist/tools/runtime-tool.d.ts.map +1 -1
  552. package/dist/tools/schema/coerce.d.ts.map +1 -0
  553. package/dist/tools/schema/flatten-join.d.ts.map +1 -0
  554. package/dist/tools/schema/flatten.d.ts.map +1 -0
  555. package/dist/tools/schema/portable-formats.d.ts.map +1 -0
  556. package/dist/tools/{presentation.d.ts → schema/presentation.d.ts} +2 -0
  557. package/dist/tools/schema/presentation.d.ts.map +1 -0
  558. package/dist/tools/schema/schema.d.ts.map +1 -0
  559. package/dist/tools/schema/untyped-properties.d.ts.map +1 -0
  560. package/dist/tools/surface.d.ts +2 -3
  561. package/dist/tools/surface.d.ts.map +1 -1
  562. package/dist/tools/toolkit.d.ts +4 -4
  563. package/dist/tools/toolkit.d.ts.map +1 -1
  564. package/dist/tools/{define-download-tool.d.ts → transfer/define-download-tool.d.ts} +4 -4
  565. package/dist/tools/transfer/define-download-tool.d.ts.map +1 -0
  566. package/dist/tools/{define-upload-tool.d.ts → transfer/define-upload-tool.d.ts} +3 -3
  567. package/dist/tools/transfer/define-upload-tool.d.ts.map +1 -0
  568. package/dist/tools/{define-view-file-tool.d.ts → transfer/define-view-file-tool.d.ts} +2 -2
  569. package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -0
  570. package/dist/tools/{download-core.d.ts → transfer/download-core.d.ts} +2 -2
  571. package/dist/tools/transfer/download-core.d.ts.map +1 -0
  572. package/dist/tools/{managed-file-error.d.ts → transfer/managed-file-error.d.ts} +1 -1
  573. package/dist/tools/transfer/managed-file-error.d.ts.map +1 -0
  574. package/dist/tools/{mount-download.d.ts → transfer/mount-download.d.ts} +1 -1
  575. package/dist/tools/transfer/mount-download.d.ts.map +1 -0
  576. package/dist/tools/{mount-upload.d.ts → transfer/mount-upload.d.ts} +1 -1
  577. package/dist/tools/transfer/mount-upload.d.ts.map +1 -0
  578. package/dist/tools/transfer/native-result.d.ts.map +1 -0
  579. package/dist/tools/{upload-core.d.ts → transfer/upload-core.d.ts} +1 -1
  580. package/dist/tools/transfer/upload-core.d.ts.map +1 -0
  581. package/dist/tools/transfer/view-file-contract.d.ts.map +1 -0
  582. package/dist/tools/{view-file.d.ts → transfer/view-file.d.ts} +1 -1
  583. package/dist/tools/transfer/view-file.d.ts.map +1 -0
  584. package/dist/tools/transports.d.ts +1 -1
  585. package/dist/tools/transports.d.ts.map +1 -1
  586. package/dist/tracking/contract.d.ts +1 -1
  587. package/dist/tracking/contract.d.ts.map +1 -1
  588. package/llms/agent-runtime-browser.txt +33 -0
  589. package/llms/agent-runtime-coding-tools.txt +58 -0
  590. package/llms/agent-runtime-harness.txt +45 -0
  591. package/llms/agent-runtime-openrouter.txt +22 -0
  592. package/llms/agent-runtime-sandbox.txt +159 -0
  593. package/llms/agent-runtime-sqlite-bun.txt +29 -0
  594. package/llms/agent-runtime-sqlite-node.txt +26 -0
  595. package/llms/agent-runtime-testing.txt +30 -0
  596. package/llms/agent-runtime.2.txt +550 -0
  597. package/llms/agent-runtime.3.txt +311 -0
  598. package/llms/agent-runtime.txt +893 -0
  599. package/llms/application-diagnostic-journal.txt +30 -0
  600. package/llms/application-grammy.txt +27 -0
  601. package/llms/application-opentelemetry.txt +27 -0
  602. package/llms/application-schemas.txt +42 -0
  603. package/llms/application.2.txt +223 -0
  604. package/llms/application.txt +1144 -0
  605. package/llms/cli.txt +977 -0
  606. package/llms/contract.txt +606 -0
  607. package/llms/declaration.txt +286 -0
  608. package/llms/files.txt +30 -0
  609. package/llms/geo.txt +114 -0
  610. package/llms/google.txt +27 -0
  611. package/llms/live.txt +471 -0
  612. package/llms/node.txt +43 -0
  613. package/llms/oauth.txt +136 -0
  614. package/llms/observability.txt +893 -0
  615. package/llms/primitives.txt +158 -0
  616. package/llms/react.txt +184 -0
  617. package/llms/release.txt +176 -0
  618. package/llms/remote.txt +25 -0
  619. package/llms/server.2.txt +361 -0
  620. package/llms/server.3.txt +1031 -0
  621. package/llms/server.4.txt +905 -0
  622. package/llms/server.5.txt +250 -0
  623. package/llms/server.txt +996 -0
  624. package/llms/stitchkit.2.txt +836 -0
  625. package/llms/stitchkit.3.txt +147 -0
  626. package/llms/stitchkit.txt +260 -0
  627. package/llms/telegram.txt +30 -0
  628. package/llms/testing.txt +676 -0
  629. package/llms/tools-connections.txt +45 -0
  630. package/llms/tools-contract.txt +9 -0
  631. package/llms/tools-invoker.txt +9 -0
  632. package/llms/tools.2.txt +838 -0
  633. package/llms/tools.txt +1004 -0
  634. package/llms/tracking-server.txt +32 -0
  635. package/llms/tracking.txt +263 -0
  636. package/llms/upgrading-0.37.0-0.50.0.txt +947 -0
  637. package/llms/upgrading-0.53.0-0.67.0.txt +1174 -0
  638. package/llms/upgrading-0.68.0-0.94.0.txt +1159 -0
  639. package/llms/upgrading.txt +215 -0
  640. package/llms-full.txt +214 -75
  641. package/llms.txt +54 -5
  642. package/package.json +84 -83
  643. package/dist/agent-runtime/durability-contract.d.ts.map +0 -1
  644. package/dist/agent-runtime/durability-json.d.ts.map +0 -1
  645. package/dist/agent-runtime/durability-ledger.d.ts.map +0 -1
  646. package/dist/agent-runtime/durability-scheduler.d.ts.map +0 -1
  647. package/dist/agent-runtime/durability.d.ts.map +0 -1
  648. package/dist/agent-runtime/store-driver.d.ts.map +0 -1
  649. package/dist/agent-runtime-browser.d.ts +0 -5
  650. package/dist/agent-runtime-browser.d.ts.map +0 -1
  651. package/dist/agent-runtime-coding-tools.d.ts.map +0 -1
  652. package/dist/agent-runtime-coding-tools.js +0 -23
  653. package/dist/agent-runtime-harness.d.ts.map +0 -1
  654. package/dist/agent-runtime-openrouter.d.ts.map +0 -1
  655. package/dist/agent-runtime-sandbox.d.ts.map +0 -1
  656. package/dist/agent-runtime-sqlite-bun.d.ts.map +0 -1
  657. package/dist/agent-runtime-sqlite-node.d.ts.map +0 -1
  658. package/dist/agent-runtime-testing.d.ts +0 -3
  659. package/dist/agent-runtime-testing.d.ts.map +0 -1
  660. package/dist/agent-runtime-testing.js +0 -156
  661. package/dist/agent-runtime.d.ts.map +0 -1
  662. package/dist/application/channel.d.ts.map +0 -1
  663. package/dist/application-diagnostic-journal.d.ts.map +0 -1
  664. package/dist/application-grammy.d.ts.map +0 -1
  665. package/dist/application-opentelemetry.d.ts.map +0 -1
  666. package/dist/application-schemas.d.ts.map +0 -1
  667. package/dist/application.d.ts.map +0 -1
  668. package/dist/cli.d.ts.map +0 -1
  669. package/dist/contract/index.d.ts +0 -8
  670. package/dist/contract/index.d.ts.map +0 -1
  671. package/dist/declaration.d.ts.map +0 -1
  672. package/dist/files.d.ts.map +0 -1
  673. package/dist/geo.d.ts.map +0 -1
  674. package/dist/google.d.ts.map +0 -1
  675. package/dist/index-0j3vcp5m.js +0 -28
  676. package/dist/index-a11g2kry.js +0 -866
  677. package/dist/index-cnyk6te3.js +0 -77
  678. package/dist/index-fadnxwna.js +0 -1046
  679. package/dist/index-hrbajay7.js +0 -1196
  680. package/dist/index-s8cnx02s.js +0 -90
  681. package/dist/index-v5573g1k.js +0 -142
  682. package/dist/index-vk3kq9sb.js +0 -3344
  683. package/dist/index.d.ts.map +0 -1
  684. package/dist/internal/errors.d.ts.map +0 -1
  685. package/dist/internal/observability-sink.d.ts.map +0 -1
  686. package/dist/live.d.ts.map +0 -1
  687. package/dist/logger.d.ts.map +0 -1
  688. package/dist/node.d.ts.map +0 -1
  689. package/dist/oauth.d.ts.map +0 -1
  690. package/dist/observability/index.d.ts.map +0 -1
  691. package/dist/primitives.d.ts +0 -3
  692. package/dist/primitives.d.ts.map +0 -1
  693. package/dist/react.d.ts.map +0 -1
  694. package/dist/release.d.ts.map +0 -1
  695. package/dist/remote.d.ts.map +0 -1
  696. package/dist/remote.js +0 -88
  697. package/dist/retained.d.ts.map +0 -1
  698. package/dist/server/file-state-store.d.ts.map +0 -1
  699. package/dist/server/index.d.ts.map +0 -1
  700. package/dist/server/request.d.ts.map +0 -1
  701. package/dist/telegram.d.ts.map +0 -1
  702. package/dist/testing/agent-store-conformance.d.ts.map +0 -1
  703. package/dist/testing.d.ts +0 -39
  704. package/dist/testing.d.ts.map +0 -1
  705. package/dist/tool-invoker.d.ts.map +0 -1
  706. package/dist/tool-invoker.js +0 -21
  707. package/dist/tools/async-operation-contract.d.ts.map +0 -1
  708. package/dist/tools/async-operation.d.ts +0 -332
  709. package/dist/tools/async-operation.d.ts.map +0 -1
  710. package/dist/tools/cli-args.d.ts.map +0 -1
  711. package/dist/tools/cli-checkpoint.d.ts.map +0 -1
  712. package/dist/tools/cli-command.d.ts.map +0 -1
  713. package/dist/tools/cli-format.d.ts.map +0 -1
  714. package/dist/tools/cli-installer.d.ts.map +0 -1
  715. package/dist/tools/cli-invoke.d.ts.map +0 -1
  716. package/dist/tools/cli-manifest.d.ts.map +0 -1
  717. package/dist/tools/cli-policy.d.ts.map +0 -1
  718. package/dist/tools/cli-profile.d.ts.map +0 -1
  719. package/dist/tools/cli-signature.d.ts.map +0 -1
  720. package/dist/tools/cli-stream.d.ts.map +0 -1
  721. package/dist/tools/cli-update.d.ts.map +0 -1
  722. package/dist/tools/cli-view.d.ts.map +0 -1
  723. package/dist/tools/cli-wait.d.ts.map +0 -1
  724. package/dist/tools/cli.d.ts.map +0 -1
  725. package/dist/tools/coerce.d.ts.map +0 -1
  726. package/dist/tools/connections/index.d.ts.map +0 -1
  727. package/dist/tools/define-download-tool.d.ts.map +0 -1
  728. package/dist/tools/define-upload-tool.d.ts.map +0 -1
  729. package/dist/tools/define-view-file-tool.d.ts.map +0 -1
  730. package/dist/tools/define-wait-tool.d.ts.map +0 -1
  731. package/dist/tools/download-core.d.ts.map +0 -1
  732. package/dist/tools/flatten-join.d.ts.map +0 -1
  733. package/dist/tools/flatten.d.ts.map +0 -1
  734. package/dist/tools/json-schema-dialect.d.ts.map +0 -1
  735. package/dist/tools/json-schema.d.ts.map +0 -1
  736. package/dist/tools/managed-file-error.d.ts.map +0 -1
  737. package/dist/tools/mcp-app.d.ts.map +0 -1
  738. package/dist/tools/mcp-catalog.d.ts.map +0 -1
  739. package/dist/tools/mcp-handler.d.ts.map +0 -1
  740. package/dist/tools/mcp-prepare.d.ts.map +0 -1
  741. package/dist/tools/mcp-progress.d.ts.map +0 -1
  742. package/dist/tools/mcp-round-policy.d.ts.map +0 -1
  743. package/dist/tools/mcp-round.d.ts.map +0 -1
  744. package/dist/tools/mcp-stdio-signals.d.ts.map +0 -1
  745. package/dist/tools/mcp-stdio.d.ts.map +0 -1
  746. package/dist/tools/mcp-trace.d.ts.map +0 -1
  747. package/dist/tools/mcp.d.ts.map +0 -1
  748. package/dist/tools/mount-download.d.ts.map +0 -1
  749. package/dist/tools/mount-upload.d.ts.map +0 -1
  750. package/dist/tools/mount-wait.d.ts.map +0 -1
  751. package/dist/tools/native-mcp.d.ts +0 -20
  752. package/dist/tools/native-mcp.d.ts.map +0 -1
  753. package/dist/tools/native-result.d.ts.map +0 -1
  754. package/dist/tools/oauth-metadata.d.ts.map +0 -1
  755. package/dist/tools/oauth-provider.d.ts.map +0 -1
  756. package/dist/tools/portable-formats.d.ts.map +0 -1
  757. package/dist/tools/presentation.d.ts.map +0 -1
  758. package/dist/tools/schema.d.ts.map +0 -1
  759. package/dist/tools/untyped-properties.d.ts.map +0 -1
  760. package/dist/tools/upload-core.d.ts.map +0 -1
  761. package/dist/tools/view-file-contract.d.ts.map +0 -1
  762. package/dist/tools/view-file.d.ts.map +0 -1
  763. package/dist/tools/wait-core.d.ts.map +0 -1
  764. package/dist/tools-contract.d.ts.map +0 -1
  765. package/dist/tools.d.ts +0 -50
  766. package/dist/tools.d.ts.map +0 -1
  767. package/dist/tracking-server.d.ts.map +0 -1
  768. package/dist/tracking.d.ts.map +0 -1
  769. package/dist/upgrade-cli.d.ts.map +0 -1
  770. package/dist/{retained.d.ts → browser/retained.d.ts} +0 -0
  771. package/dist/{declaration.d.ts → declaration/declaration.d.ts} +0 -0
  772. package/dist/{upgrade-cli.d.ts → entrypoints/bin/upgrade-cli.d.ts} +0 -0
  773. package/dist/{tracking-server.js → entrypoints/tracking/server.js} +0 -0
  774. package/dist/{google.d.ts → google/google.d.ts} +0 -0
  775. package/dist/{index-pq95qkbf.js → index-5jm36zv1.js} +0 -0
  776. package/dist/{index-actkayzn.js → index-70yj2ebz.js} +3 -3
  777. /package/dist/{application → internal}/channel.d.ts +0 -0
  778. /package/dist/{logger.d.ts → internal/logger.d.ts} +0 -0
  779. /package/dist/{server → internal}/request.d.ts +0 -0
  780. /package/dist/{tools → json-schema}/json-schema.d.ts +0 -0
  781. /package/dist/tools/{async-operation-contract.d.ts → operations/async-operation-contract.d.ts} +0 -0
  782. /package/dist/tools/{mount-wait.d.ts → operations/mount-wait.d.ts} +0 -0
  783. /package/dist/tools/{wait-core.d.ts → operations/wait-core.d.ts} +0 -0
  784. /package/dist/tools/{coerce.d.ts → schema/coerce.d.ts} +0 -0
  785. /package/dist/tools/{flatten-join.d.ts → schema/flatten-join.d.ts} +0 -0
  786. /package/dist/tools/{flatten.d.ts → schema/flatten.d.ts} +0 -0
  787. /package/dist/tools/{portable-formats.d.ts → schema/portable-formats.d.ts} +0 -0
  788. /package/dist/tools/{schema.d.ts → schema/schema.d.ts} +0 -0
  789. /package/dist/tools/{untyped-properties.d.ts → schema/untyped-properties.d.ts} +0 -0
  790. /package/dist/tools/{native-result.d.ts → transfer/native-result.d.ts} +0 -0
  791. /package/dist/tools/{view-file-contract.d.ts → transfer/view-file-contract.d.ts} +0 -0
@@ -0,0 +1,1023 @@
1
+ import {
2
+ AcceptInputAndAssignRunSchema,
3
+ AcquireAgentRunSchema,
4
+ AgentRecoverablePageSchema,
5
+ AgentRunViewSchema,
6
+ AgentStoreEventPageSchema,
7
+ AgentStoreTransitionSchema,
8
+ AppendAgentStoreEventSchema,
9
+ CheckpointRunAssistantSchema,
10
+ CommitRunTerminalSchema,
11
+ ReadAgentStoreEventsSchema,
12
+ RecordRunOperationSchema,
13
+ RecoverAgentRunSchema,
14
+ ReplaceCompactedRangeSchema,
15
+ RequestRunInterruptSchema,
16
+ SeedConversationInputSchema,
17
+ agentStoreEventDraft,
18
+ assistantStatus,
19
+ canonicalAgentJson,
20
+ decodeAgentConversationArchive,
21
+ encodeAgentConversationArchive
22
+ } from "./index-1nd48tm9.js";
23
+ import {
24
+ AgentMessageSchema,
25
+ AgentRecordIdSchema,
26
+ AgentRecordVersionSchema,
27
+ AgentRunSchema,
28
+ AgentSnapshotSchema,
29
+ runStateForTerminalReason
30
+ } from "./index-gtj3zc53.js";
31
+
32
+ // src/agent-runtime/purge.ts
33
+ import { z } from "zod";
34
+ var AgentConversationPurgeInputSchema = z.strictObject({
35
+ conversationId: AgentRecordIdSchema,
36
+ expectedVersion: AgentRecordVersionSchema.optional()
37
+ });
38
+ var AgentConversationPurgeResultSchema = z.discriminatedUnion("outcome", [
39
+ z.strictObject({ outcome: z.literal("purged") }),
40
+ z.strictObject({ outcome: z.literal("already_purged") }),
41
+ z.strictObject({ outcome: z.literal("unsupported") }),
42
+ z.strictObject({
43
+ outcome: z.literal("active"),
44
+ runIds: z.array(AgentRecordIdSchema).min(1)
45
+ }),
46
+ z.strictObject({ outcome: z.literal("conflict"), actualVersion: AgentRecordVersionSchema })
47
+ ]);
48
+
49
+ class AgentConversationPurgedError extends Error {
50
+ constructor() {
51
+ super("Agent conversation has been purged; use a new conversation ID");
52
+ this.name = "AgentConversationPurgedError";
53
+ }
54
+ }
55
+ async function purgeAgentConversation(store, input) {
56
+ const parsed = AgentConversationPurgeInputSchema.parse(input);
57
+ if (!store.purgeConversation)
58
+ return { outcome: "unsupported" };
59
+ return AgentConversationPurgeResultSchema.parse(await store.purgeConversation(parsed));
60
+ }
61
+
62
+ // src/agent-runtime/store-driver-contract.ts
63
+ import { z as z2 } from "zod";
64
+ var AgentRuntimeHeadSchema = z2.object({
65
+ schemaVersion: z2.literal(1),
66
+ conversationId: AgentRecordIdSchema,
67
+ version: AgentRecordVersionSchema
68
+ });
69
+ var AgentStoredRunSchema = z2.object({
70
+ schemaVersion: z2.literal(1),
71
+ run: AgentRunSchema,
72
+ terminalAssistant: AgentMessageSchema.optional()
73
+ });
74
+ var AgentAdmissionReceiptSchema = z2.object({
75
+ schemaVersion: z2.literal(1),
76
+ conversationId: AgentRecordIdSchema,
77
+ idempotencyKey: z2.string().min(1),
78
+ input: AgentMessageSchema,
79
+ runId: AgentRecordIdSchema,
80
+ assistantMessageId: AgentRecordIdSchema
81
+ });
82
+ var AgentSeedReceiptSchema = z2.object({
83
+ schemaVersion: z2.literal(1),
84
+ conversationId: AgentRecordIdSchema,
85
+ seedKey: z2.string().min(1),
86
+ messageIds: z2.array(AgentRecordIdSchema).min(1)
87
+ });
88
+ var AgentHistoryMutationSchema = z2.discriminatedUnion("type", [
89
+ z2.object({ type: z2.literal("admit"), input: AgentMessageSchema }),
90
+ z2.object({
91
+ type: z2.literal("upsert-assistant"),
92
+ message: AgentMessageSchema
93
+ }),
94
+ z2.object({
95
+ type: z2.literal("replace-compacted-range"),
96
+ replacedMessageIds: z2.array(AgentRecordIdSchema).min(1),
97
+ summary: AgentMessageSchema
98
+ }),
99
+ z2.object({
100
+ type: z2.literal("seed"),
101
+ message: AgentMessageSchema
102
+ })
103
+ ]);
104
+ var ACTIVE_AGENT_RUN_STATES = [
105
+ "queued",
106
+ "running",
107
+ "interrupt_requested"
108
+ ];
109
+ function isActiveRunState(state) {
110
+ return ACTIVE_AGENT_RUN_STATES.includes(state);
111
+ }
112
+ function emptyHead(conversationId) {
113
+ return AgentRuntimeHeadSchema.parse({
114
+ schemaVersion: 1,
115
+ conversationId,
116
+ version: 0
117
+ });
118
+ }
119
+
120
+ // src/agent-runtime/store-create.ts
121
+ import { z as z5 } from "zod";
122
+
123
+ // src/agent-runtime/store-archive.ts
124
+ import { z as z3 } from "zod";
125
+
126
+ // src/agent-runtime/store-snapshot.ts
127
+ function historyPositions(messages) {
128
+ const positions = new Map;
129
+ messages.forEach((message, index) => {
130
+ if (!positions.has(message.id))
131
+ positions.set(message.id, index);
132
+ });
133
+ return (run) => {
134
+ let earliest = Number.MAX_SAFE_INTEGER;
135
+ for (const id of [...run.inputMessageIds, run.assistantMessageId]) {
136
+ const position = positions.get(id);
137
+ if (position !== undefined && position < earliest)
138
+ earliest = position;
139
+ }
140
+ return earliest;
141
+ };
142
+ }
143
+ function orderRuns(messages, runs) {
144
+ const positionOf = historyPositions(messages);
145
+ const fallback = (left, right) => left.createdAt.localeCompare(right.createdAt) || positionOf(left) - positionOf(right) || left.id.localeCompare(right.id);
146
+ return [...runs].sort((left, right) => {
147
+ if (left.executionSequence !== undefined && right.executionSequence !== undefined && left.executionSequence !== right.executionSequence) {
148
+ return left.executionSequence - right.executionSequence;
149
+ }
150
+ const leftStarted = left.executionSequence !== undefined || left.state !== "queued";
151
+ const rightStarted = right.executionSequence !== undefined || right.state !== "queued";
152
+ if (leftStarted !== rightStarted)
153
+ return leftStarted ? -1 : 1;
154
+ if (!leftStarted && !rightStarted) {
155
+ const priority = Number(right.queuePriority !== undefined) - Number(left.queuePriority !== undefined);
156
+ if (priority !== 0)
157
+ return priority;
158
+ }
159
+ return fallback(left, right);
160
+ });
161
+ }
162
+ function orderRunMessages(messages, runs) {
163
+ const byId = new Map(messages.map((message) => [message.id, message]));
164
+ const ownedIds = new Set(runs.flatMap((run) => [...run.inputMessageIds, run.assistantMessageId]));
165
+ const orderedOwned = runs.flatMap((run) => [...run.inputMessageIds, run.assistantMessageId].flatMap((id) => {
166
+ const message = byId.get(id);
167
+ return message ? [message] : [];
168
+ }));
169
+ let ownedIndex = 0;
170
+ return messages.map((message) => {
171
+ if (!ownedIds.has(message.id))
172
+ return message;
173
+ const ordered = orderedOwned[ownedIndex];
174
+ if (!ordered)
175
+ throw new TypeError("Stored agent history lost a run-owned message");
176
+ ownedIndex += 1;
177
+ return ordered;
178
+ });
179
+ }
180
+ function snapshotOf(head, messages, records) {
181
+ validateSnapshot(head, messages, records);
182
+ const runs = orderRuns(messages, records.map((record) => record.run));
183
+ return AgentSnapshotSchema.parse({
184
+ schemaVersion: 1,
185
+ conversationId: head.conversationId,
186
+ version: head.version,
187
+ messages: orderRunMessages(messages, runs),
188
+ runs
189
+ });
190
+ }
191
+ function validateSnapshot(head, messages, records) {
192
+ const runIds = new Set;
193
+ const assistantIds = new Set;
194
+ const messageIds = new Set;
195
+ for (const record of records) {
196
+ const run = record.run;
197
+ if (run.conversationId !== head.conversationId || runIds.has(run.id) || assistantIds.has(run.assistantMessageId)) {
198
+ throw new TypeError("Stored agent runs contain inconsistent identities");
199
+ }
200
+ if (record.terminalAssistant && (record.terminalAssistant.id !== run.assistantMessageId || record.terminalAssistant.conversationId !== run.conversationId || record.terminalAssistant.runId !== run.id || record.terminalAssistant.role !== "assistant" || run.terminalReason === undefined)) {
201
+ throw new TypeError("Retained terminal assistant does not match its run");
202
+ }
203
+ runIds.add(run.id);
204
+ assistantIds.add(run.assistantMessageId);
205
+ }
206
+ for (const message of messages) {
207
+ if (message.conversationId !== head.conversationId || messageIds.has(message.id)) {
208
+ throw new TypeError("Stored agent history contains inconsistent message identities");
209
+ }
210
+ messageIds.add(message.id);
211
+ if (assistantIds.has(message.id) && message.runId === undefined) {
212
+ throw new TypeError("Stored history occupies a reserved assistant identity");
213
+ }
214
+ if (message.runId !== undefined) {
215
+ const run = records.find((candidate) => candidate.run.id === message.runId)?.run;
216
+ if (!run || message.role !== "assistant" || run.assistantMessageId !== message.id) {
217
+ throw new TypeError("Stored assistant history does not match its reserved run identity");
218
+ }
219
+ }
220
+ }
221
+ }
222
+ function replaceRun(runs, next) {
223
+ return runs.map((run) => run.id === next.id ? next : run);
224
+ }
225
+ function replaceMessage(messages, next) {
226
+ return messages.some((message) => message.id === next.id) ? messages.map((message) => message.id === next.id ? next : message) : [...messages, next];
227
+ }
228
+ function mergeRunRecords(...groups) {
229
+ const records = new Map;
230
+ for (const group of groups) {
231
+ for (const rawRecord of group) {
232
+ const record = AgentStoredRunSchema.parse(rawRecord);
233
+ const previous = records.get(record.run.id);
234
+ if (previous && previous.run.assistantMessageId !== record.run.assistantMessageId) {
235
+ throw new TypeError("Stored agent run identity changed across normalized records");
236
+ }
237
+ records.set(record.run.id, record);
238
+ }
239
+ }
240
+ return [...records.values()];
241
+ }
242
+ function referencedRunIds(messages) {
243
+ return [...new Set(messages.flatMap((message) => message.runId ? [message.runId] : []))];
244
+ }
245
+
246
+ // src/agent-runtime/store-reads.ts
247
+ async function snapshotIn(driver, transaction, conversationId) {
248
+ const [stored, messages, activeRecords] = await Promise.all([
249
+ driver.head.load(transaction, conversationId),
250
+ driver.history.load(transaction, conversationId),
251
+ driver.runs.listActive(transaction, conversationId)
252
+ ]);
253
+ const head = AgentRuntimeHeadSchema.parse(stored ?? emptyHead(conversationId));
254
+ const referencedRecords = await driver.runs.loadMany(transaction, {
255
+ conversationId,
256
+ runIds: referencedRunIds(messages)
257
+ });
258
+ return snapshotOf(head, messages, mergeRunRecords(activeRecords, referencedRecords));
259
+ }
260
+ function loadSnapshot(driver, conversationId) {
261
+ return driver.transaction((transaction) => snapshotIn(driver, transaction, conversationId), {
262
+ access: "read"
263
+ });
264
+ }
265
+ function loadRun(driver, input) {
266
+ return driver.transaction(async (transaction) => {
267
+ const [stored, record] = await Promise.all([
268
+ driver.head.load(transaction, input.conversationId),
269
+ driver.runs.load(transaction, input)
270
+ ]);
271
+ if (!record)
272
+ return;
273
+ const parsed = AgentStoredRunSchema.parse(record);
274
+ if (parsed.run.conversationId !== input.conversationId || parsed.run.id !== input.runId) {
275
+ throw new TypeError("Stored run does not match the identity it was loaded by");
276
+ }
277
+ const head = AgentRuntimeHeadSchema.parse(stored ?? emptyHead(input.conversationId));
278
+ return AgentRunViewSchema.parse({
279
+ snapshotVersion: head.version,
280
+ run: parsed.run,
281
+ ...parsed.terminalAssistant && { assistant: parsed.terminalAssistant }
282
+ });
283
+ }, { access: "read" });
284
+ }
285
+ function listActiveRuns(driver, conversationId) {
286
+ return driver.transaction(async (transaction) => {
287
+ const [records, messages] = await Promise.all([
288
+ driver.runs.listActive(transaction, conversationId),
289
+ driver.history.load(transaction, conversationId)
290
+ ]);
291
+ const runs = records.map((record) => AgentStoredRunSchema.parse(record).run);
292
+ for (const run of runs) {
293
+ if (run.conversationId !== conversationId) {
294
+ throw new TypeError("Active run belongs to another conversation");
295
+ }
296
+ if (!isActiveRunState(run.state)) {
297
+ throw new TypeError("Active run listing returned a terminal run");
298
+ }
299
+ }
300
+ return orderRuns(messages, runs);
301
+ }, { access: "read" });
302
+ }
303
+ function appendEvent(driver, input) {
304
+ const parsed = AppendAgentStoreEventSchema.parse(input);
305
+ return driver.transaction((transaction) => appendEventIn(driver, transaction, parsed));
306
+ }
307
+ async function appendEventIn(driver, transaction, parsed) {
308
+ if (await driver.conversations?.isPurged(transaction, parsed.conversationId)) {
309
+ throw new AgentConversationPurgedError;
310
+ }
311
+ return driver.events.append(transaction, agentStoreEventDraft(parsed));
312
+ }
313
+ function readEvents(driver, input) {
314
+ const parsed = ReadAgentStoreEventsSchema.parse(input);
315
+ return driver.transaction(async (transaction) => AgentStoreEventPageSchema.parse(await driver.events.list(transaction, parsed)), { access: "read" });
316
+ }
317
+
318
+ // src/agent-runtime/store-archive.ts
319
+ function exportConversation(driver, conversationId) {
320
+ return driver.transaction(async (transaction) => {
321
+ const events = [];
322
+ let fromSeq;
323
+ do {
324
+ const page = AgentStoreEventPageSchema.parse(await driver.events.list(transaction, ReadAgentStoreEventsSchema.parse({
325
+ conversationId,
326
+ ...fromSeq && { fromSeq },
327
+ limit: 1e4
328
+ })));
329
+ events.push(...page.items);
330
+ fromSeq = page.nextSeq;
331
+ } while (fromSeq !== undefined);
332
+ const durable = await driver.archive?.export(transaction, conversationId) ?? {
333
+ projections: [],
334
+ spills: []
335
+ };
336
+ const snapshot = await snapshotIn(driver, transaction, conversationId);
337
+ return encodeAgentConversationArchive({
338
+ format: "stitchkit.agent-conversation",
339
+ formatVersion: 1,
340
+ conversationId,
341
+ events,
342
+ projections: [
343
+ { archiveType: "runtime-snapshot", snapshot: z3.json().parse(snapshot) },
344
+ ...durable.projections
345
+ ],
346
+ spills: durable.spills
347
+ });
348
+ }, { access: "read" });
349
+ }
350
+ async function importConversation(driver, bytes) {
351
+ const archive = decodeAgentConversationArchive(bytes);
352
+ return driver.transaction(async (transaction) => {
353
+ const existing = await driver.events.list(transaction, {
354
+ conversationId: archive.conversationId,
355
+ limit: 1
356
+ });
357
+ if (existing.items.length > 0) {
358
+ throw new TypeError("Conversation event log must be empty before import");
359
+ }
360
+ for (const event of archive.events) {
361
+ const appended = await driver.events.append(transaction, {
362
+ schemaVersion: event.schemaVersion,
363
+ eventId: event.eventId,
364
+ conversationId: event.conversationId,
365
+ kind: event.kind,
366
+ occurredAt: event.occurredAt,
367
+ payload: event.payload,
368
+ ...event.ignorable && { ignorable: true }
369
+ });
370
+ if (appended.seq !== event.seq) {
371
+ throw new TypeError("Conversation archive event sequence is not contiguous");
372
+ }
373
+ }
374
+ const snapshotEntry = archive.projections.find((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry) && entry.archiveType === "runtime-snapshot");
375
+ if (snapshotEntry && typeof snapshotEntry === "object" && !Array.isArray(snapshotEntry)) {
376
+ const snapshot = AgentSnapshotSchema.parse(snapshotEntry.snapshot);
377
+ if (snapshot.conversationId !== archive.conversationId) {
378
+ throw new TypeError("Conversation archive snapshot belongs to another conversation");
379
+ }
380
+ if (snapshot.version > 0 || snapshot.messages.length > 0 || snapshot.runs.length > 0) {
381
+ const outcome = await driver.head.compareAndSwap(transaction, {
382
+ conversationId: snapshot.conversationId,
383
+ expectedVersion: 0,
384
+ next: AgentRuntimeHeadSchema.parse({
385
+ schemaVersion: 1,
386
+ conversationId: snapshot.conversationId,
387
+ version: snapshot.version
388
+ })
389
+ });
390
+ if (outcome.outcome !== "applied") {
391
+ throw new TypeError("Conversation archive snapshot target is not empty");
392
+ }
393
+ }
394
+ for (const run of snapshot.runs) {
395
+ const terminalAssistant = snapshot.messages.find((message) => message.id === run.assistantMessageId);
396
+ await driver.runs.save(transaction, AgentStoredRunSchema.parse({
397
+ schemaVersion: 1,
398
+ run,
399
+ ...terminalAssistant && { terminalAssistant }
400
+ }));
401
+ }
402
+ for (const message of snapshot.messages) {
403
+ await driver.history.apply(transaction, { type: "admit", input: message });
404
+ }
405
+ for (const event of archive.events) {
406
+ if (event.kind !== "runtime/transition")
407
+ continue;
408
+ const transition = AgentStoreTransitionSchema.parse(event.payload);
409
+ if (transition.type !== "accept")
410
+ continue;
411
+ const assigned = snapshot.runs.find((run) => run.inputMessageIds.includes(transition.input.input.id));
412
+ if (!assigned) {
413
+ throw new TypeError("Conversation archive admission has no assigned run");
414
+ }
415
+ await driver.admissions.create(transaction, AgentAdmissionReceiptSchema.parse({
416
+ schemaVersion: 1,
417
+ conversationId: archive.conversationId,
418
+ idempotencyKey: transition.input.idempotencyKey,
419
+ input: transition.input.input,
420
+ runId: assigned.id,
421
+ assistantMessageId: assigned.assistantMessageId
422
+ }));
423
+ }
424
+ }
425
+ await driver.archive?.import(transaction, archive);
426
+ return { conversationId: archive.conversationId, events: archive.events.length };
427
+ });
428
+ }
429
+
430
+ // src/agent-runtime/store-mutate.ts
431
+ import { z as z4 } from "zod";
432
+
433
+ // src/agent-runtime/store-reduce-shared.ts
434
+ function conflict(actualVersion) {
435
+ return { outcome: "conflict", actualVersion };
436
+ }
437
+ function applied(current, input, effects) {
438
+ const runs = input.runs ?? current.runs;
439
+ const messages = input.messages ?? current.messages;
440
+ return {
441
+ outcome: "applied",
442
+ snapshot: AgentSnapshotSchema.parse({
443
+ ...current,
444
+ version: current.version + 1,
445
+ runs,
446
+ messages: orderRunMessages(messages, runs)
447
+ }),
448
+ ...effects?.runRecords?.length && { runRecords: effects.runRecords },
449
+ ...effects?.admissionReceipt && { admissionReceipt: effects.admissionReceipt },
450
+ ...effects?.seedReceipt && { seedReceipt: effects.seedReceipt },
451
+ ...effects?.historyMutations?.length && { historyMutations: effects.historyMutations }
452
+ };
453
+ }
454
+
455
+ // src/agent-runtime/store-reducer.ts
456
+ import { createHash } from "node:crypto";
457
+
458
+ // src/agent-runtime/store-reduce-history.ts
459
+ function reduceAccept(current, input) {
460
+ if (input.expectedVersion !== undefined && input.expectedVersion !== current.version) {
461
+ return conflict(current.version);
462
+ }
463
+ const coalescedRun = input.coalesceIntoRunId ? current.runs.find((candidate) => candidate.id === input.coalesceIntoRunId) : undefined;
464
+ if (input.coalesceIntoRunId !== undefined && (!coalescedRun || coalescedRun.conversationId !== input.input.conversationId || coalescedRun.state !== "queued" || coalescedRun.ownerId !== undefined || coalescedRun.terminalReason !== undefined)) {
465
+ return coalescedRun ? conflict(coalescedRun.revision) : { outcome: "not_found" };
466
+ }
467
+ if (input.run.conversationId !== input.input.conversationId || input.run.inputMessageIds.length !== 1 || input.run.inputMessageIds[0] !== input.input.id || input.run.state !== "queued" || input.run.revision !== 0 || input.run.executionSequence !== undefined || input.run.ownerId !== undefined || input.run.terminalReason !== undefined || input.run.terminalPolicyName !== undefined || input.input.role !== "user" && input.input.role !== "tool" || input.input.status !== "committed" || input.input.runId !== undefined || current.messages.some((message) => message.id === input.input.id) || coalescedRun !== undefined && input.input.id === coalescedRun.assistantMessageId || !coalescedRun && (input.run.assistantMessageId === input.input.id || current.runs.some((candidate) => candidate.id === input.run.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.run.assistantMessageId) || current.messages.some((message) => message.id === input.run.assistantMessageId))) {
468
+ throw new TypeError("Input and queued run do not form one valid assignment");
469
+ }
470
+ const assignedRun = coalescedRun ? AgentRunSchema.parse({
471
+ ...coalescedRun,
472
+ inputMessageIds: [...coalescedRun.inputMessageIds, input.input.id],
473
+ revision: coalescedRun.revision + 1,
474
+ updatedAt: new Date().toISOString()
475
+ }) : input.run;
476
+ const admissionReceipt = AgentAdmissionReceiptSchema.parse({
477
+ schemaVersion: 1,
478
+ conversationId: input.input.conversationId,
479
+ idempotencyKey: input.idempotencyKey,
480
+ input: input.input,
481
+ runId: assignedRun.id,
482
+ assistantMessageId: assignedRun.assistantMessageId
483
+ });
484
+ return applied(current, {
485
+ messages: [...current.messages, input.input],
486
+ runs: coalescedRun ? replaceRun(current.runs, assignedRun) : [...current.runs, assignedRun]
487
+ }, {
488
+ runRecords: [AgentStoredRunSchema.parse({ schemaVersion: 1, run: assignedRun })],
489
+ admissionReceipt,
490
+ historyMutations: [{ type: "admit", input: input.input }]
491
+ });
492
+ }
493
+ function reduceSeed(current, input) {
494
+ const conversationId = input.conversationId;
495
+ if (current.conversationId !== conversationId)
496
+ return { outcome: "not_found" };
497
+ for (const message of input.inputs) {
498
+ if (message.conversationId !== conversationId || message.role !== "user" || message.status !== "committed" || message.runId !== undefined) {
499
+ throw new TypeError("Seeded conversation input must be committed unowned user messages");
500
+ }
501
+ }
502
+ return applied(current, { messages: [...input.inputs, ...current.messages] }, {
503
+ seedReceipt: AgentSeedReceiptSchema.parse({
504
+ schemaVersion: 1,
505
+ conversationId,
506
+ seedKey: input.seedKey,
507
+ messageIds: input.inputs.map((message) => message.id)
508
+ }),
509
+ historyMutations: [...input.inputs].reverse().map((message) => ({
510
+ type: "seed",
511
+ message
512
+ }))
513
+ });
514
+ }
515
+ function reduceCompact(current, input) {
516
+ if (current.conversationId !== input.conversationId)
517
+ return { outcome: "not_found" };
518
+ if (current.version !== input.expectedVersion)
519
+ return conflict(current.version);
520
+ const replaced = new Set(input.replacedMessageIds);
521
+ if (!input.replacedMessageIds.every((id) => current.messages.some((m) => m.id === id))) {
522
+ return { outcome: "not_found" };
523
+ }
524
+ const liveAssistant = current.runs.find((candidate) => isActiveRunState(candidate.state) && replaced.has(candidate.assistantMessageId));
525
+ if (liveAssistant) {
526
+ throw new TypeError(`Compaction may not replace the assistant message of run ${liveAssistant.id}, which has not finished`);
527
+ }
528
+ const positions = current.messages.map((message, index) => replaced.has(message.id) ? index : undefined).filter((index) => index !== undefined);
529
+ const first = positions[0];
530
+ if (first === undefined || positions.some((position, offset) => position !== first + offset) || input.summary.conversationId !== input.conversationId || input.summary.runId !== undefined || input.summary.role !== "summary" || input.summary.status !== "committed" || current.messages.some((message) => message.id === input.summary.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.summary.id)) {
531
+ throw new TypeError("Compaction replacement must be one valid contiguous history range");
532
+ }
533
+ const messages = [
534
+ ...current.messages.slice(0, first),
535
+ input.summary,
536
+ ...current.messages.slice(first + positions.length)
537
+ ];
538
+ return applied(current, { messages }, {
539
+ historyMutations: [
540
+ {
541
+ type: "replace-compacted-range",
542
+ replacedMessageIds: input.replacedMessageIds,
543
+ summary: input.summary
544
+ }
545
+ ]
546
+ });
547
+ }
548
+
549
+ // src/agent-runtime/store-reduce-run.ts
550
+ function reduceAcquire(current, run, input) {
551
+ const runPosition = current.runs.findIndex((candidate) => candidate.id === run.id);
552
+ const acquisitionBlocked = current.runs.some((candidate, index) => candidate.id !== run.id && (candidate.state === "running" || candidate.state === "interrupt_requested" || index < runPosition && candidate.state === "queued"));
553
+ if (run.revision !== input.expectedRevision || run.state !== "queued" || acquisitionBlocked) {
554
+ return conflict(run.revision);
555
+ }
556
+ const next = AgentRunSchema.parse({
557
+ ...run,
558
+ state: "running",
559
+ executionSequence: run.executionSequence ?? current.version + 1,
560
+ ownerId: input.ownerId,
561
+ fencingToken: (run.fencingToken ?? 0) + 1,
562
+ revision: run.revision + 1,
563
+ updatedAt: new Date().toISOString()
564
+ });
565
+ return applied(current, { runs: replaceRun(current.runs, next) }, {
566
+ runRecords: [AgentStoredRunSchema.parse({ schemaVersion: 1, run: next })]
567
+ });
568
+ }
569
+ function reduceCheckpoint(current, run, input) {
570
+ if (run.revision !== input.expectedRevision || run.state !== "running" || run.ownerId !== input.ownerId || input.fencingToken !== undefined && run.fencingToken !== input.fencingToken || input.assistant.runId !== run.id || input.assistant.id !== run.assistantMessageId || input.assistant.conversationId !== run.conversationId || input.assistant.role !== "assistant" || input.assistant.status !== "streaming") {
571
+ return conflict(run.revision);
572
+ }
573
+ const next = AgentRunSchema.parse({
574
+ ...run,
575
+ ...input.usage && { usage: input.usage },
576
+ revision: run.revision + 1,
577
+ updatedAt: new Date().toISOString()
578
+ });
579
+ return applied(current, {
580
+ runs: replaceRun(current.runs, next),
581
+ messages: replaceMessage(current.messages, input.assistant)
582
+ }, {
583
+ runRecords: [AgentStoredRunSchema.parse({ schemaVersion: 1, run: next })],
584
+ historyMutations: [{ type: "upsert-assistant", message: input.assistant }]
585
+ });
586
+ }
587
+ function reduceOperation(current, run, input) {
588
+ if (run.revision !== input.expectedRevision || run.state !== "running" && run.state !== "interrupt_requested" || run.ownerId !== input.ownerId || input.fencingToken !== undefined && run.fencingToken !== input.fencingToken) {
589
+ return conflict(run.revision);
590
+ }
591
+ const next = AgentRunSchema.parse({
592
+ ...run,
593
+ lastOperation: input.operation,
594
+ revision: run.revision + 1,
595
+ updatedAt: new Date().toISOString()
596
+ });
597
+ return applied(current, { runs: replaceRun(current.runs, next) }, { runRecords: [AgentStoredRunSchema.parse({ schemaVersion: 1, run: next })] });
598
+ }
599
+ function reduceInterrupt(current, run, input) {
600
+ if (run.revision !== input.expectedRevision || run.state !== "running") {
601
+ return conflict(run.revision);
602
+ }
603
+ const next = AgentRunSchema.parse({
604
+ ...run,
605
+ state: "interrupt_requested",
606
+ revision: run.revision + 1,
607
+ updatedAt: new Date().toISOString()
608
+ });
609
+ return applied(current, { runs: replaceRun(current.runs, next) }, {
610
+ runRecords: [AgentStoredRunSchema.parse({ schemaVersion: 1, run: next })]
611
+ });
612
+ }
613
+ function reduceRecover(current, run, input) {
614
+ if (run.revision !== input.expectedRevision || !isActiveRunState(run.state)) {
615
+ return conflict(run.revision);
616
+ }
617
+ if (input.action === "requeue" && run.state !== "queued" && input.replaySafe !== true) {
618
+ throw new TypeError("Recovering an acquired run requires explicit replaySafe evidence");
619
+ }
620
+ const { ownerId: _released, ...carried } = run;
621
+ const next = AgentRunSchema.parse({
622
+ ...carried,
623
+ state: input.action === "requeue" ? "queued" : "abandoned",
624
+ revision: run.revision + 1,
625
+ ...input.action === "abandon" && { terminalReason: "abandoned" },
626
+ updatedAt: new Date().toISOString()
627
+ });
628
+ if (input.action === "abandon") {
629
+ const existingAssistant = current.messages.find((message) => message.id === run.assistantMessageId);
630
+ const assistant = AgentMessageSchema.parse({
631
+ ...existingAssistant ?? {
632
+ schemaVersion: 1,
633
+ id: run.assistantMessageId,
634
+ conversationId: run.conversationId,
635
+ runId: run.id,
636
+ role: "assistant",
637
+ parts: [],
638
+ createdAt: run.createdAt
639
+ },
640
+ status: "failed",
641
+ updatedAt: new Date().toISOString()
642
+ });
643
+ return applied(current, {
644
+ runs: replaceRun(current.runs, next),
645
+ messages: replaceMessage(current.messages, assistant)
646
+ }, {
647
+ runRecords: [
648
+ AgentStoredRunSchema.parse({
649
+ schemaVersion: 1,
650
+ run: next,
651
+ terminalAssistant: assistant
652
+ })
653
+ ],
654
+ historyMutations: [{ type: "upsert-assistant", message: assistant }]
655
+ });
656
+ }
657
+ return applied(current, { runs: replaceRun(current.runs, next) }, {
658
+ runRecords: [AgentStoredRunSchema.parse({ schemaVersion: 1, run: next })]
659
+ });
660
+ }
661
+
662
+ // src/agent-runtime/store-reduce-terminal.ts
663
+ function reduceTerminal(current, run, input) {
664
+ if (input.reason === "absorbed") {
665
+ throw new TypeError("A run is absorbed by another run, never terminalized as absorbed");
666
+ }
667
+ if (run.revision !== input.expectedRevision || run.state !== "running" && run.state !== "interrupt_requested" || run.ownerId !== input.ownerId || input.fencingToken !== undefined && run.fencingToken !== input.fencingToken || input.assistant.runId !== run.id || input.assistant.id !== run.assistantMessageId || input.assistant.conversationId !== run.conversationId || input.assistant.role !== "assistant" || input.assistant.status !== assistantStatus(input.reason)) {
668
+ return conflict(run.revision);
669
+ }
670
+ if (input.absorb && runStateForTerminalReason(input.reason) !== "completed") {
671
+ throw new TypeError("Only a completing run may absorb a queued successor");
672
+ }
673
+ const named = new Set((input.absorb ?? []).map((entry) => entry.runId));
674
+ if (named.size !== (input.absorb ?? []).length || named.has(run.id)) {
675
+ throw new TypeError("An absorption names each successor once, and never the absorbing run");
676
+ }
677
+ const absorbable = (input.absorb ?? []).filter((entry) => {
678
+ const candidate = current.runs.find((item) => item.id === entry.runId);
679
+ return candidate !== undefined && candidate.id !== run.id && candidate.state === "queued" && candidate.conversationId === run.conversationId && candidate.inputMessageIds.length === entry.inputMessageIds.length && candidate.inputMessageIds.every((id, index) => id === entry.inputMessageIds[index]);
680
+ });
681
+ const absorbedIds = new Set(absorbable.flatMap((entry) => entry.inputMessageIds));
682
+ const next = AgentRunSchema.parse({
683
+ ...run,
684
+ state: runStateForTerminalReason(input.reason),
685
+ terminalReason: input.reason,
686
+ ...input.policyName && { terminalPolicyName: input.policyName },
687
+ ...input.usage && { usage: input.usage },
688
+ ...absorbedIds.size > 0 && {
689
+ inputMessageIds: [
690
+ ...run.inputMessageIds,
691
+ ...[...absorbedIds].filter((id) => !run.inputMessageIds.includes(id))
692
+ ]
693
+ },
694
+ revision: run.revision + 1,
695
+ updatedAt: new Date().toISOString()
696
+ });
697
+ const absorbedRuns = absorbable.map((entry) => {
698
+ const candidate = current.runs.find((item) => item.id === entry.runId);
699
+ if (!candidate)
700
+ throw new TypeError("Absorbed run disappeared inside the reducer");
701
+ return AgentRunSchema.parse({
702
+ ...candidate,
703
+ state: runStateForTerminalReason("absorbed"),
704
+ terminalReason: "absorbed",
705
+ absorbedIntoRunId: next.id,
706
+ revision: candidate.revision + 1,
707
+ updatedAt: new Date().toISOString()
708
+ });
709
+ });
710
+ const runs = absorbedRuns.reduce((accumulated, absorbed) => replaceRun(accumulated, absorbed), replaceRun(current.runs, next));
711
+ return applied(current, {
712
+ runs,
713
+ messages: replaceMessage(current.messages, input.assistant)
714
+ }, {
715
+ runRecords: [
716
+ AgentStoredRunSchema.parse({
717
+ schemaVersion: 1,
718
+ run: next,
719
+ terminalAssistant: input.assistant
720
+ }),
721
+ ...absorbedRuns.map((absorbed) => AgentStoredRunSchema.parse({ schemaVersion: 1, run: absorbed }))
722
+ ],
723
+ historyMutations: [{ type: "upsert-assistant", message: input.assistant }]
724
+ });
725
+ }
726
+
727
+ // src/agent-runtime/store-reducer.ts
728
+ function transitionRecord(operation) {
729
+ if (operation.type !== "checkpoint")
730
+ return operation;
731
+ const { assistant, ...rest } = operation.input;
732
+ const body = canonicalAgentJson(assistant);
733
+ return {
734
+ type: operation.type,
735
+ input: {
736
+ ...rest,
737
+ assistant: {
738
+ id: assistant.id,
739
+ status: assistant.status,
740
+ sha256: createHash("sha256").update(body).digest("hex"),
741
+ parts: assistant.parts.length,
742
+ bytes: Buffer.byteLength(body)
743
+ }
744
+ }
745
+ };
746
+ }
747
+ function reduceStore(current, operation) {
748
+ if (operation.type === "accept")
749
+ return reduceAccept(current, operation.input);
750
+ if (operation.type === "seed")
751
+ return reduceSeed(current, operation.input);
752
+ if (operation.type === "compact")
753
+ return reduceCompact(current, operation.input);
754
+ const run = current.runs.find((candidate) => candidate.id === operation.input.runId);
755
+ if (!run)
756
+ return { outcome: "not_found" };
757
+ switch (operation.type) {
758
+ case "acquire":
759
+ return reduceAcquire(current, run, operation.input);
760
+ case "checkpoint":
761
+ return reduceCheckpoint(current, run, operation.input);
762
+ case "operation":
763
+ return reduceOperation(current, run, operation.input);
764
+ case "interrupt":
765
+ return reduceInterrupt(current, run, operation.input);
766
+ case "recover":
767
+ return reduceRecover(current, run, operation.input);
768
+ case "terminal":
769
+ return reduceTerminal(current, run, operation.input);
770
+ }
771
+ }
772
+ function operationConversationId(operation) {
773
+ return operation.type === "accept" ? operation.input.input.conversationId : operation.input.conversationId;
774
+ }
775
+
776
+ // src/agent-runtime/store-mutate.ts
777
+ function validateAdmissionReceipt(receipt, record, conversationId) {
778
+ const input = receipt.input;
779
+ const run = record.run;
780
+ if (receipt.conversationId !== conversationId || input.conversationId !== conversationId || input.role !== "user" || input.status !== "committed" || input.runId !== undefined || receipt.runId !== run.id || receipt.assistantMessageId !== run.assistantMessageId || !run.inputMessageIds.includes(input.id)) {
781
+ throw new TypeError("Admission receipt does not match its canonical run assignment");
782
+ }
783
+ }
784
+ async function readForMutation(driver, transaction, operation) {
785
+ const conversationId = operationConversationId(operation);
786
+ if (await driver.conversations?.isPurged(transaction, conversationId)) {
787
+ throw new AgentConversationPurgedError;
788
+ }
789
+ const operationRunId = operation.type === "accept" ? operation.input.coalesceIntoRunId : operation.type === "compact" || operation.type === "seed" ? undefined : operation.input.runId;
790
+ const [stored, messages, activeRecords, operationRecord, duplicateReceipt] = await Promise.all([
791
+ driver.head.load(transaction, conversationId),
792
+ driver.history.load(transaction, conversationId),
793
+ driver.runs.listActive(transaction, conversationId),
794
+ operationRunId ? driver.runs.load(transaction, { conversationId, runId: operationRunId }) : undefined,
795
+ operation.type === "accept" ? driver.admissions.load(transaction, {
796
+ conversationId,
797
+ idempotencyKey: operation.input.idempotencyKey
798
+ }) : undefined
799
+ ]);
800
+ const head = AgentRuntimeHeadSchema.parse(stored ?? emptyHead(conversationId));
801
+ const referencedRecords = await driver.runs.loadMany(transaction, {
802
+ conversationId,
803
+ runIds: referencedRunIds(messages)
804
+ });
805
+ const records = mergeRunRecords(activeRecords, referencedRecords, operationRecord ? [operationRecord] : []);
806
+ const current = snapshotOf(head, messages, records);
807
+ return { conversationId, head, messages, records, current, duplicateReceipt };
808
+ }
809
+ async function settledSeed(driver, transaction, read, input) {
810
+ const { conversationId, current } = read;
811
+ const existing = await driver.seeds.load(transaction, {
812
+ conversationId,
813
+ seedKey: input.seedKey
814
+ });
815
+ if (existing)
816
+ return { outcome: "applied", snapshot: current };
817
+ let collisions = 0;
818
+ for (const message of input.inputs) {
819
+ if (current.messages.some((candidate) => candidate.id === message.id) || driver.history.hasMessage && await driver.history.hasMessage(transaction, {
820
+ conversationId,
821
+ messageId: message.id
822
+ }))
823
+ collisions++;
824
+ }
825
+ if (collisions > 0 && collisions < input.inputs.length) {
826
+ throw new TypeError("Partial instruction seed collision: restore the complete seed before retrying");
827
+ }
828
+ if (collisions > 0) {
829
+ await driver.seeds.create(transaction, AgentSeedReceiptSchema.parse({
830
+ schemaVersion: 1,
831
+ conversationId,
832
+ seedKey: input.seedKey,
833
+ messageIds: input.inputs.map((message) => message.id)
834
+ }));
835
+ return { outcome: "applied", snapshot: current };
836
+ }
837
+ return;
838
+ }
839
+ async function duplicateAdmission(driver, transaction, read, duplicateReceipt) {
840
+ const { conversationId, head, messages, records } = read;
841
+ const duplicateRecord = await driver.runs.load(transaction, {
842
+ conversationId,
843
+ runId: duplicateReceipt.runId
844
+ });
845
+ if (!duplicateRecord) {
846
+ throw new TypeError("Admission receipt points to a missing canonical run");
847
+ }
848
+ validateAdmissionReceipt(duplicateReceipt, duplicateRecord, conversationId);
849
+ const answering = duplicateRecord.run.absorbedIntoRunId ? await driver.runs.load(transaction, {
850
+ conversationId,
851
+ runId: duplicateRecord.run.absorbedIntoRunId
852
+ }) : undefined;
853
+ if (duplicateRecord.run.absorbedIntoRunId && !answering) {
854
+ throw new TypeError("Absorbed run points to a missing absorbing run");
855
+ }
856
+ const canonical = answering ?? duplicateRecord;
857
+ return {
858
+ outcome: "duplicate",
859
+ input: duplicateReceipt.input,
860
+ inputMessageId: duplicateReceipt.input.id,
861
+ runId: canonical.run.id,
862
+ assistantMessageId: canonical.run.assistantMessageId,
863
+ run: canonical.run,
864
+ ...canonical.terminalAssistant && {
865
+ assistant: canonical.terminalAssistant
866
+ },
867
+ snapshot: snapshotOf(head, messages, mergeRunRecords(records, [duplicateRecord], answering ? [answering] : []))
868
+ };
869
+ }
870
+ async function assertAdmissionIdentitiesFree(driver, transaction, conversationId, input) {
871
+ const inputCollision = await driver.admissions.loadByInputMessageId(transaction, {
872
+ conversationId,
873
+ inputMessageId: input.input.id
874
+ });
875
+ if (inputCollision) {
876
+ throw new TypeError("Input message identity is already assigned to an admission");
877
+ }
878
+ if (!input.coalesceIntoRunId) {
879
+ const [runCollision, assistantCollision] = await Promise.all([
880
+ driver.runs.load(transaction, {
881
+ conversationId,
882
+ runId: input.run.id
883
+ }),
884
+ driver.runs.loadByAssistantMessageId(transaction, {
885
+ conversationId,
886
+ assistantMessageId: input.run.assistantMessageId
887
+ })
888
+ ]);
889
+ if (runCollision || assistantCollision) {
890
+ throw new TypeError("Queued run identities are already reserved");
891
+ }
892
+ }
893
+ }
894
+ async function persistApplied(driver, transaction, read, operation, reduced) {
895
+ const { conversationId, current } = read;
896
+ const nextHead = AgentRuntimeHeadSchema.parse({
897
+ schemaVersion: 1,
898
+ conversationId,
899
+ version: reduced.snapshot.version
900
+ });
901
+ const outcome = await driver.head.compareAndSwap(transaction, {
902
+ conversationId,
903
+ expectedVersion: current.version,
904
+ next: nextHead
905
+ });
906
+ if (outcome.outcome === "conflict")
907
+ return conflict(outcome.actualVersion);
908
+ for (const record of reduced.runRecords ?? []) {
909
+ await driver.runs.save(transaction, record);
910
+ }
911
+ if (reduced.admissionReceipt) {
912
+ await driver.admissions.create(transaction, reduced.admissionReceipt);
913
+ }
914
+ if (reduced.seedReceipt) {
915
+ await driver.seeds.create(transaction, reduced.seedReceipt);
916
+ }
917
+ for (const mutation of reduced.historyMutations ?? []) {
918
+ await driver.history.apply(transaction, mutation);
919
+ }
920
+ await driver.events.append(transaction, agentStoreEventDraft({
921
+ conversationId,
922
+ kind: "runtime/transition",
923
+ payload: z4.json().parse(transitionRecord(operation))
924
+ }));
925
+ return { outcome: "applied", snapshot: reduced.snapshot };
926
+ }
927
+ function mutateStore(driver, operation) {
928
+ return driver.transaction(async (transaction) => {
929
+ const read = await readForMutation(driver, transaction, operation);
930
+ if (operation.type === "seed") {
931
+ const settled = await settledSeed(driver, transaction, read, operation.input);
932
+ if (settled)
933
+ return settled;
934
+ }
935
+ if (read.duplicateReceipt) {
936
+ return duplicateAdmission(driver, transaction, read, read.duplicateReceipt);
937
+ }
938
+ if (operation.type === "accept") {
939
+ await assertAdmissionIdentitiesFree(driver, transaction, read.conversationId, operation.input);
940
+ }
941
+ const reduced = reduceStore(read.current, operation);
942
+ if (reduced.outcome !== "applied")
943
+ return reduced;
944
+ return persistApplied(driver, transaction, read, operation, reduced);
945
+ });
946
+ }
947
+
948
+ // src/agent-runtime/store-purge.ts
949
+ function createStoreConversationPurge(driver, conversations) {
950
+ return async (input) => {
951
+ const { conversationId, expectedVersion } = AgentConversationPurgeInputSchema.parse(input);
952
+ return driver.transaction(async (transaction) => {
953
+ if (await conversations.isPurged(transaction, conversationId)) {
954
+ return { outcome: "already_purged" };
955
+ }
956
+ const head = await driver.head.load(transaction, conversationId);
957
+ const actualVersion = head?.version ?? 0;
958
+ if (expectedVersion !== undefined && expectedVersion !== actualVersion) {
959
+ return { outcome: "conflict", actualVersion };
960
+ }
961
+ const active = await driver.runs.listActive(transaction, conversationId);
962
+ if (active.length > 0) {
963
+ return { outcome: "active", runIds: active.map((record) => record.run.id) };
964
+ }
965
+ await conversations.remove(transaction, conversationId);
966
+ return { outcome: "purged" };
967
+ });
968
+ };
969
+ }
970
+
971
+ // src/agent-runtime/store-create.ts
972
+ var AgentRecoverableScanInputSchema = z5.object({
973
+ cursor: z5.string().min(1).optional(),
974
+ limit: z5.number().int().min(1).max(1000)
975
+ });
976
+ function createAgentRuntimeStore(driver) {
977
+ const mutate = (operation) => mutateStore(driver, operation);
978
+ return {
979
+ loadSnapshot: (conversationId) => loadSnapshot(driver, conversationId),
980
+ loadRun: (input) => loadRun(driver, input),
981
+ listActiveRuns: (conversationId) => listActiveRuns(driver, conversationId),
982
+ appendEvent: (input) => appendEvent(driver, input),
983
+ readEvents: (input) => readEvents(driver, input),
984
+ exportConversation: (conversationId) => exportConversation(driver, conversationId),
985
+ importConversation: (bytes) => importConversation(driver, bytes),
986
+ ...driver.conversations && {
987
+ purgeConversation: createStoreConversationPurge(driver, driver.conversations)
988
+ },
989
+ acceptInputAndAssignRun: (input) => mutate({
990
+ type: "accept",
991
+ input: AcceptInputAndAssignRunSchema.parse(input)
992
+ }),
993
+ acquireRun: (input) => mutate({ type: "acquire", input: AcquireAgentRunSchema.parse(input) }),
994
+ checkpointRunAssistant: (input) => mutate({
995
+ type: "checkpoint",
996
+ input: CheckpointRunAssistantSchema.parse(input)
997
+ }),
998
+ recordRunOperation: (input) => mutate({
999
+ type: "operation",
1000
+ input: RecordRunOperationSchema.parse(input)
1001
+ }),
1002
+ requestRunInterrupt: (input) => mutate({
1003
+ type: "interrupt",
1004
+ input: RequestRunInterruptSchema.parse(input)
1005
+ }),
1006
+ recoverRun: (input) => mutate({ type: "recover", input: RecoverAgentRunSchema.parse(input) }),
1007
+ commitRunTerminal: (input) => mutate({ type: "terminal", input: CommitRunTerminalSchema.parse(input) }),
1008
+ replaceCompactedRange: (input) => mutate({
1009
+ type: "compact",
1010
+ input: ReplaceCompactedRangeSchema.parse(input)
1011
+ }),
1012
+ seedConversationInput: (input) => mutate({
1013
+ type: "seed",
1014
+ input: SeedConversationInputSchema.parse(input)
1015
+ }),
1016
+ async scanRecoverable(input) {
1017
+ const parsed = AgentRecoverableScanInputSchema.parse(input);
1018
+ return AgentRecoverablePageSchema.parse(await driver.scanRecoverable(parsed));
1019
+ }
1020
+ };
1021
+ }
1022
+
1023
+ export { AgentConversationPurgeInputSchema, AgentConversationPurgeResultSchema, AgentConversationPurgedError, purgeAgentConversation, AgentRuntimeHeadSchema, AgentStoredRunSchema, AgentAdmissionReceiptSchema, AgentSeedReceiptSchema, AgentHistoryMutationSchema, ACTIVE_AGENT_RUN_STATES, isActiveRunState, replaceMessage, appendEventIn, createAgentRuntimeStore };