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,1084 @@
1
+ import {
2
+ AgentConversationMessagePageSchema,
3
+ AgentConversationPageSchema
4
+ } from "./index-crykmqkr.js";
5
+ import {
6
+ AgentAdmissionReceiptSchema,
7
+ AgentHistoryMutationSchema,
8
+ AgentRuntimeHeadSchema,
9
+ AgentSeedReceiptSchema,
10
+ AgentStoredRunSchema,
11
+ appendEventIn,
12
+ createAgentRuntimeStore
13
+ } from "./index-58k4fp34.js";
14
+ import {
15
+ AgentRecoverableDescriptorSchema,
16
+ AgentRecoverablePageSchema,
17
+ AgentStoreEventEnvelopeSchema,
18
+ AgentStoreEventPageSchema,
19
+ AppendAgentStoreEventSchema,
20
+ canonicalAgentJson
21
+ } from "./index-1nd48tm9.js";
22
+ import {
23
+ AgentMessageSchema,
24
+ AgentRunSchema
25
+ } from "./index-gtj3zc53.js";
26
+
27
+ // src/agent-runtime/sqlite-schema.ts
28
+ import { z as z3 } from "zod";
29
+
30
+ // src/agent-runtime/sqlite-purge.ts
31
+ var OWNED_TABLES = [
32
+ "stitchkit_agent_runtime_spills",
33
+ "stitchkit_agent_runtime_schedules",
34
+ "stitchkit_agent_runtime_projections",
35
+ "stitchkit_agent_runtime_events",
36
+ "stitchkit_agent_runtime_messages",
37
+ "stitchkit_agent_runtime_seeds",
38
+ "stitchkit_agent_runtime_admissions",
39
+ "stitchkit_agent_runtime_runs",
40
+ "stitchkit_agent_runtime_heads"
41
+ ];
42
+ function initializeSqliteConversationPurge(database) {
43
+ database.exec(`
44
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_purged (
45
+ conversation_id TEXT PRIMARY KEY
46
+ );
47
+ `);
48
+ for (const table of OWNED_TABLES) {
49
+ for (const operation of ["INSERT", "UPDATE"]) {
50
+ database.exec(`
51
+ CREATE TRIGGER IF NOT EXISTS ${table}_purge_${operation.toLowerCase()}
52
+ BEFORE ${operation} ON ${table}
53
+ WHEN EXISTS (
54
+ SELECT 1 FROM stitchkit_agent_runtime_purged WHERE conversation_id = NEW.conversation_id
55
+ )
56
+ BEGIN SELECT RAISE(ABORT, 'Agent conversation has been purged'); END;
57
+ `);
58
+ }
59
+ }
60
+ }
61
+ function sqliteConversationPurge(database) {
62
+ const table = database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'stitchkit_agent_runtime_purged'").get();
63
+ if (table === null || table === undefined)
64
+ return;
65
+ return {
66
+ async isPurged(transaction, conversationId) {
67
+ const row = transaction.prepare("SELECT conversation_id FROM stitchkit_agent_runtime_purged WHERE conversation_id = ?").get(conversationId);
68
+ return row !== null && row !== undefined;
69
+ },
70
+ async remove(transaction, conversationId) {
71
+ transaction.prepare("INSERT INTO stitchkit_agent_runtime_purged (conversation_id) VALUES (?)").run(conversationId);
72
+ for (const table2 of OWNED_TABLES) {
73
+ transaction.prepare(`DELETE FROM ${table2} WHERE conversation_id = ?`).run(conversationId);
74
+ }
75
+ transaction.prepare("DELETE FROM stitchkit_agent_runtime_children WHERE parent_conversation_id = ? OR child_conversation_id = ?").run(conversationId, conversationId);
76
+ }
77
+ };
78
+ }
79
+
80
+ // src/agent-runtime/sqlite-rows.ts
81
+ import { z } from "zod";
82
+ var HeadRowSchema = z.object({ version: z.number().int().nonnegative() });
83
+ var RunRowSchema = z.object({
84
+ payload: z.string(),
85
+ terminal_assistant_payload: z.string().nullable()
86
+ });
87
+ var MessageRowSchema = z.object({ payload: z.string() });
88
+ var PositionedMessageRowSchema = z.object({
89
+ position: z.number().int().nonnegative()
90
+ });
91
+ var CountRowSchema = z.object({ count: z.number().int().nonnegative() });
92
+ var EventRowSchema = z.object({
93
+ event_id: z.string(),
94
+ conversation_id: z.string(),
95
+ seq: z.int().positive(),
96
+ schema_version: z.int().positive(),
97
+ kind: z.string(),
98
+ occurred_at: z.string(),
99
+ ignorable: z.union([z.literal(0), z.literal(1)]),
100
+ payload: z.string()
101
+ });
102
+ function parseJson(value) {
103
+ return JSON.parse(value);
104
+ }
105
+ function encodeJson(value) {
106
+ return JSON.stringify(value);
107
+ }
108
+ function missing(value) {
109
+ return value === null || value === undefined;
110
+ }
111
+ function placeholders(count) {
112
+ return Array.from({ length: count }, () => "?").join(", ");
113
+ }
114
+ function parseRunRow(value) {
115
+ const row = RunRowSchema.parse(value);
116
+ return AgentStoredRunSchema.parse({
117
+ schemaVersion: 1,
118
+ run: AgentRunSchema.parse(parseJson(row.payload)),
119
+ ...row.terminal_assistant_payload === null ? {} : {
120
+ terminalAssistant: AgentMessageSchema.parse(parseJson(row.terminal_assistant_payload))
121
+ }
122
+ });
123
+ }
124
+ function parseEventRow(value) {
125
+ const row = EventRowSchema.parse(value);
126
+ return AgentStoreEventEnvelopeSchema.parse({
127
+ schemaVersion: row.schema_version,
128
+ eventId: row.event_id,
129
+ conversationId: row.conversation_id,
130
+ seq: row.seq,
131
+ kind: row.kind,
132
+ occurredAt: row.occurred_at,
133
+ payload: parseJson(row.payload),
134
+ ...row.ignorable === 1 && { ignorable: true }
135
+ });
136
+ }
137
+
138
+ // src/agent-runtime/store-migrations/v1-to-v2.ts
139
+ import { randomUUID } from "node:crypto";
140
+ import { z as z2 } from "zod";
141
+ var ConversationRowSchema = z2.object({
142
+ conversation_id: z2.string().min(1),
143
+ version: z2.int().nonnegative()
144
+ });
145
+ var PayloadRowSchema = z2.object({
146
+ payload: z2.string(),
147
+ terminal_assistant_payload: z2.string().nullable().optional()
148
+ });
149
+ var HistoryRowSchema = z2.object({
150
+ payload: z2.string(),
151
+ active: z2.union([z2.literal(0), z2.literal(1)])
152
+ });
153
+ var AdmissionRowSchema = z2.object({
154
+ conversation_id: z2.string(),
155
+ idempotency_key: z2.string(),
156
+ input_payload: z2.string(),
157
+ run_id: z2.string(),
158
+ assistant_message_id: z2.string()
159
+ });
160
+ function parseJson2(value) {
161
+ return JSON.parse(value);
162
+ }
163
+ function createDurableTables(database) {
164
+ database.exec(`
165
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_events (
166
+ row_id INTEGER PRIMARY KEY AUTOINCREMENT,
167
+ conversation_id TEXT NOT NULL,
168
+ seq INTEGER NOT NULL CHECK (seq > 0),
169
+ event_id TEXT NOT NULL UNIQUE,
170
+ schema_version INTEGER NOT NULL CHECK (schema_version > 0),
171
+ kind TEXT NOT NULL,
172
+ occurred_at TEXT NOT NULL,
173
+ ignorable INTEGER NOT NULL DEFAULT 0 CHECK (ignorable IN (0, 1)),
174
+ payload TEXT NOT NULL,
175
+ UNIQUE (conversation_id, seq)
176
+ );
177
+ CREATE INDEX IF NOT EXISTS stitchkit_agent_runtime_events_time
178
+ ON stitchkit_agent_runtime_events (conversation_id, occurred_at, seq);
179
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_projections (
180
+ conversation_id TEXT NOT NULL,
181
+ name TEXT NOT NULL,
182
+ version INTEGER NOT NULL CHECK (version > 0),
183
+ upto_seq INTEGER NOT NULL CHECK (upto_seq >= 0),
184
+ payload TEXT NOT NULL,
185
+ updated_at TEXT NOT NULL,
186
+ PRIMARY KEY (conversation_id, name)
187
+ );
188
+ CREATE INDEX IF NOT EXISTS stitchkit_agent_runtime_projection_updates
189
+ ON stitchkit_agent_runtime_projections (name, updated_at, conversation_id);
190
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_spills (
191
+ reference_id TEXT PRIMARY KEY,
192
+ conversation_id TEXT NOT NULL,
193
+ run_id TEXT,
194
+ tool_call_id TEXT,
195
+ media_type TEXT NOT NULL,
196
+ bytes INTEGER NOT NULL CHECK (bytes >= 0),
197
+ sha256 TEXT NOT NULL,
198
+ created_at TEXT NOT NULL,
199
+ expires_at TEXT,
200
+ authorization_payload TEXT,
201
+ payload BLOB NOT NULL
202
+ );
203
+ CREATE INDEX IF NOT EXISTS stitchkit_agent_runtime_spills_owner
204
+ ON stitchkit_agent_runtime_spills (conversation_id, created_at);
205
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_schedules (
206
+ id TEXT PRIMARY KEY,
207
+ conversation_id TEXT NOT NULL,
208
+ kind TEXT NOT NULL,
209
+ next_at TEXT NOT NULL,
210
+ interval_ms INTEGER,
211
+ time_zone TEXT,
212
+ input_payload TEXT NOT NULL,
213
+ state TEXT NOT NULL,
214
+ occurrence INTEGER NOT NULL DEFAULT 0 CHECK (occurrence >= 0),
215
+ claim_owner TEXT,
216
+ claim_until TEXT,
217
+ created_at TEXT NOT NULL,
218
+ updated_at TEXT NOT NULL
219
+ );
220
+ CREATE INDEX IF NOT EXISTS stitchkit_agent_runtime_schedules_due
221
+ ON stitchkit_agent_runtime_schedules (state, next_at);
222
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_children (
223
+ parent_conversation_id TEXT NOT NULL,
224
+ child_conversation_id TEXT NOT NULL UNIQUE,
225
+ seed_upto_seq INTEGER,
226
+ state TEXT NOT NULL,
227
+ budget_payload TEXT NOT NULL,
228
+ usage_payload TEXT NOT NULL,
229
+ result_reference TEXT,
230
+ created_at TEXT NOT NULL,
231
+ updated_at TEXT NOT NULL,
232
+ PRIMARY KEY (parent_conversation_id, child_conversation_id)
233
+ );
234
+ `);
235
+ try {
236
+ database.exec(`
237
+ CREATE VIRTUAL TABLE IF NOT EXISTS stitchkit_agent_runtime_events_fts
238
+ USING fts5(
239
+ conversation_id UNINDEXED,
240
+ event_seq UNINDEXED,
241
+ occurred_at UNINDEXED,
242
+ body,
243
+ tokenize = 'unicode61 remove_diacritics 2'
244
+ );
245
+ CREATE TRIGGER IF NOT EXISTS stitchkit_agent_runtime_events_fts_insert
246
+ AFTER INSERT ON stitchkit_agent_runtime_events BEGIN
247
+ INSERT INTO stitchkit_agent_runtime_events_fts(
248
+ rowid, conversation_id, event_seq, occurred_at, body
249
+ ) VALUES (new.row_id, new.conversation_id, new.seq, new.occurred_at, new.payload);
250
+ END;
251
+ CREATE TRIGGER IF NOT EXISTS stitchkit_agent_runtime_events_fts_delete
252
+ AFTER DELETE ON stitchkit_agent_runtime_events BEGIN
253
+ DELETE FROM stitchkit_agent_runtime_events_fts WHERE rowid = old.row_id;
254
+ END;
255
+ `);
256
+ } catch (error) {
257
+ throw new Error("SQLite agent-runtime requires FTS5 support", { cause: error });
258
+ }
259
+ }
260
+ function writeBaselines(database, migratedAt) {
261
+ const conversations = database.prepare("SELECT conversation_id, version FROM stitchkit_agent_runtime_heads ORDER BY conversation_id").all().map((row) => ConversationRowSchema.parse(row));
262
+ const insert = database.prepare(`
263
+ INSERT INTO stitchkit_agent_runtime_events (
264
+ conversation_id, seq, event_id, schema_version, kind, occurred_at, ignorable, payload
265
+ ) VALUES (?, 1, ?, 1, 'runtime/baseline', ?, 0, ?)
266
+ `);
267
+ for (const conversation of conversations) {
268
+ const rows = database.prepare("SELECT payload, active FROM stitchkit_agent_runtime_messages WHERE conversation_id = ? ORDER BY position, rowid").all(conversation.conversation_id).map((row) => {
269
+ const parsed = HistoryRowSchema.parse(row);
270
+ return {
271
+ message: AgentMessageSchema.parse(parseJson2(parsed.payload)),
272
+ active: parsed.active === 1
273
+ };
274
+ });
275
+ const messages = rows.map((row) => row.message);
276
+ const compacted = rows.filter((row) => !row.active).map((row) => row.message.id);
277
+ const runs = database.prepare("SELECT payload, terminal_assistant_payload FROM stitchkit_agent_runtime_runs WHERE conversation_id = ? ORDER BY created_at, run_id").all(conversation.conversation_id).map((value) => {
278
+ const row = PayloadRowSchema.parse(value);
279
+ return {
280
+ schemaVersion: 1,
281
+ run: AgentRunSchema.parse(parseJson2(row.payload)),
282
+ ...row.terminal_assistant_payload ? {
283
+ terminalAssistant: AgentMessageSchema.parse(parseJson2(row.terminal_assistant_payload))
284
+ } : {}
285
+ };
286
+ });
287
+ const admissions = database.prepare("SELECT conversation_id, idempotency_key, input_payload, run_id, assistant_message_id FROM stitchkit_agent_runtime_admissions WHERE conversation_id = ? ORDER BY idempotency_key").all(conversation.conversation_id).map((value) => {
288
+ const row = AdmissionRowSchema.parse(value);
289
+ return {
290
+ schemaVersion: 1,
291
+ conversationId: row.conversation_id,
292
+ idempotencyKey: row.idempotency_key,
293
+ input: AgentMessageSchema.parse(parseJson2(row.input_payload)),
294
+ runId: row.run_id,
295
+ assistantMessageId: row.assistant_message_id
296
+ };
297
+ });
298
+ const asOf = messages.at(-1)?.createdAt ?? runs.at(-1)?.run.createdAt;
299
+ insert.run(conversation.conversation_id, randomUUID(), migratedAt, canonicalAgentJson({
300
+ migratedAt,
301
+ ...asOf !== undefined && { asOf },
302
+ head: {
303
+ schemaVersion: 1,
304
+ conversationId: conversation.conversation_id,
305
+ version: conversation.version
306
+ },
307
+ messages,
308
+ ...compacted.length > 0 && { compacted },
309
+ runs,
310
+ admissions
311
+ }));
312
+ }
313
+ }
314
+ function migrateAgentRuntimeSqliteV1ToV2(database, migratedAt = new Date().toISOString()) {
315
+ createDurableTables(database);
316
+ writeBaselines(database, migratedAt);
317
+ database.prepare("UPDATE stitchkit_agent_runtime_meta SET value = '2' WHERE key = 'schema_version'").run();
318
+ }
319
+ function createAgentRuntimeSqliteV2Tables(database) {
320
+ createDurableTables(database);
321
+ }
322
+
323
+ // src/agent-runtime/store-migrations/v2-to-v3.ts
324
+ function createAgentRuntimeSqliteV3Tables(database) {
325
+ database.exec(`
326
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_seeds (
327
+ conversation_id TEXT NOT NULL,
328
+ seed_key TEXT NOT NULL,
329
+ message_ids TEXT NOT NULL,
330
+ created_at TEXT NOT NULL,
331
+ PRIMARY KEY (conversation_id, seed_key)
332
+ );
333
+ `);
334
+ }
335
+ function migrateAgentRuntimeSqliteV2ToV3(database) {
336
+ createAgentRuntimeSqliteV3Tables(database);
337
+ database.prepare("UPDATE stitchkit_agent_runtime_meta SET value = '3' WHERE key = 'schema_version'").run();
338
+ }
339
+
340
+ // src/agent-runtime/sqlite-schema.ts
341
+ var MetaRowSchema = z3.object({ value: z3.string() });
342
+ var TableRowSchema = z3.object({ name: z3.string() });
343
+ var SCHEMA_VERSION = 3;
344
+ var TABLES = [
345
+ "stitchkit_agent_runtime_heads",
346
+ "stitchkit_agent_runtime_runs",
347
+ "stitchkit_agent_runtime_admissions",
348
+ "stitchkit_agent_runtime_messages",
349
+ "stitchkit_agent_runtime_seeds",
350
+ "stitchkit_agent_runtime_events",
351
+ "stitchkit_agent_runtime_projections",
352
+ "stitchkit_agent_runtime_spills",
353
+ "stitchkit_agent_runtime_schedules",
354
+ "stitchkit_agent_runtime_children"
355
+ ];
356
+ function initializeAgentRuntimeSqlite(database) {
357
+ database.exec("BEGIN IMMEDIATE");
358
+ try {
359
+ const existing = database.prepare(`SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE 'stitchkit_agent_runtime_%' ORDER BY name`).all().map((row) => TableRowSchema.parse(row).name);
360
+ const hasMeta = existing.includes("stitchkit_agent_runtime_meta");
361
+ if (!hasMeta && existing.length > 0) {
362
+ throw new Error("Refusing an unversioned partial Stitchkit agent-runtime SQLite schema");
363
+ }
364
+ database.exec(`
365
+ CREATE TABLE IF NOT EXISTS stitchkit_agent_runtime_meta (
366
+ key TEXT PRIMARY KEY,
367
+ value TEXT NOT NULL
368
+ );
369
+ `);
370
+ const versionRow = database.prepare("SELECT value FROM stitchkit_agent_runtime_meta WHERE key = 'schema_version'").get();
371
+ if (!missing(versionRow)) {
372
+ const version = Number(MetaRowSchema.parse(versionRow).value);
373
+ if (version === 1) {
374
+ migrateAgentRuntimeSqliteV1ToV2(database);
375
+ migrateAgentRuntimeSqliteV2ToV3(database);
376
+ initializeSqliteConversationPurge(database);
377
+ database.exec("COMMIT");
378
+ return;
379
+ }
380
+ if (version === 2) {
381
+ migrateAgentRuntimeSqliteV2ToV3(database);
382
+ initializeSqliteConversationPurge(database);
383
+ database.exec("COMMIT");
384
+ return;
385
+ }
386
+ if (version !== SCHEMA_VERSION) {
387
+ throw new Error(`Unsupported Stitchkit agent-runtime SQLite schema version ${version}; expected ${SCHEMA_VERSION}`);
388
+ }
389
+ const missingTables = TABLES.filter((table) => !existing.includes(table));
390
+ if (missingTables.length > 0) {
391
+ throw new Error(`Refusing a partial Stitchkit agent-runtime SQLite schema; missing ${missingTables.join(", ")}`);
392
+ }
393
+ initializeSqliteConversationPurge(database);
394
+ database.exec("COMMIT");
395
+ return;
396
+ }
397
+ if (existing.some((table) => table !== "stitchkit_agent_runtime_meta")) {
398
+ throw new Error("Refusing an unversioned partial Stitchkit agent-runtime SQLite schema");
399
+ }
400
+ database.exec(`
401
+ CREATE TABLE stitchkit_agent_runtime_heads (
402
+ conversation_id TEXT PRIMARY KEY,
403
+ version INTEGER NOT NULL CHECK (version >= 0)
404
+ );
405
+ CREATE TABLE stitchkit_agent_runtime_runs (
406
+ conversation_id TEXT NOT NULL,
407
+ run_id TEXT NOT NULL,
408
+ assistant_message_id TEXT NOT NULL,
409
+ state TEXT NOT NULL,
410
+ created_at TEXT NOT NULL,
411
+ payload TEXT NOT NULL,
412
+ terminal_assistant_payload TEXT,
413
+ PRIMARY KEY (conversation_id, run_id),
414
+ UNIQUE (conversation_id, assistant_message_id)
415
+ );
416
+ CREATE INDEX stitchkit_agent_runtime_recoverable
417
+ ON stitchkit_agent_runtime_runs (state, conversation_id, run_id);
418
+ CREATE TABLE stitchkit_agent_runtime_admissions (
419
+ conversation_id TEXT NOT NULL,
420
+ idempotency_key TEXT NOT NULL,
421
+ input_message_id TEXT NOT NULL,
422
+ run_id TEXT NOT NULL,
423
+ assistant_message_id TEXT NOT NULL,
424
+ input_payload TEXT NOT NULL,
425
+ PRIMARY KEY (conversation_id, idempotency_key),
426
+ UNIQUE (conversation_id, input_message_id)
427
+ );
428
+ CREATE TABLE stitchkit_agent_runtime_messages (
429
+ conversation_id TEXT NOT NULL,
430
+ id TEXT NOT NULL,
431
+ position INTEGER NOT NULL CHECK (position >= 0),
432
+ active INTEGER NOT NULL DEFAULT 1 CHECK (active IN (0, 1)),
433
+ payload TEXT NOT NULL,
434
+ PRIMARY KEY (conversation_id, id)
435
+ );
436
+ `);
437
+ createAgentRuntimeSqliteV2Tables(database);
438
+ createAgentRuntimeSqliteV3Tables(database);
439
+ database.prepare("INSERT INTO stitchkit_agent_runtime_meta (key, value) VALUES ('schema_version', '3')").run();
440
+ initializeSqliteConversationPurge(database);
441
+ database.exec("COMMIT");
442
+ } catch (error) {
443
+ database.exec("ROLLBACK");
444
+ throw error;
445
+ }
446
+ }
447
+
448
+ // src/agent-runtime/sqlite-events.ts
449
+ import { createHash } from "node:crypto";
450
+ import { z as z4 } from "zod";
451
+ var ArchiveProjectionRowSchema = z4.object({
452
+ name: z4.string(),
453
+ version: z4.int().positive(),
454
+ upto_seq: z4.int().nonnegative(),
455
+ payload: z4.string(),
456
+ updated_at: z4.string()
457
+ });
458
+ var ArchiveSpillRowSchema = z4.object({
459
+ reference_id: z4.string(),
460
+ run_id: z4.string().nullable(),
461
+ tool_call_id: z4.string().nullable(),
462
+ media_type: z4.string(),
463
+ bytes: z4.int().nonnegative(),
464
+ sha256: z4.string(),
465
+ created_at: z4.string(),
466
+ expires_at: z4.string().nullable(),
467
+ authorization_payload: z4.string().nullable(),
468
+ payload: z4.instanceof(Uint8Array)
469
+ });
470
+ var sqliteEvents = {
471
+ async append(transaction, rawEvent) {
472
+ const event = rawEvent;
473
+ const last = transaction.prepare("SELECT COALESCE(MAX(seq), 0) AS count FROM stitchkit_agent_runtime_events WHERE conversation_id = ?").get(event.conversationId);
474
+ const seq = CountRowSchema.parse(last).count + 1;
475
+ transaction.prepare(`
476
+ INSERT INTO stitchkit_agent_runtime_events (
477
+ conversation_id, seq, event_id, schema_version, kind, occurred_at, ignorable, payload
478
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
479
+ `).run(event.conversationId, seq, event.eventId, event.schemaVersion, event.kind, event.occurredAt, event.ignorable ? 1 : 0, encodeJson(event.payload));
480
+ return AgentStoreEventEnvelopeSchema.parse({ ...event, seq });
481
+ },
482
+ async list(transaction, input) {
483
+ const clauses = ["conversation_id = ?"];
484
+ const values = [input.conversationId];
485
+ if (input.fromSeq !== undefined) {
486
+ clauses.push("seq >= ?");
487
+ values.push(input.fromSeq);
488
+ }
489
+ if (input.toSeq !== undefined) {
490
+ clauses.push("seq <= ?");
491
+ values.push(input.toSeq);
492
+ }
493
+ const rows = transaction.prepare(`
494
+ SELECT event_id, conversation_id, seq, schema_version, kind, occurred_at,
495
+ ignorable, payload
496
+ FROM stitchkit_agent_runtime_events
497
+ WHERE ${clauses.join(" AND ")}
498
+ ORDER BY seq ASC LIMIT ?
499
+ `).all(...values, input.limit + 1).map(parseEventRow);
500
+ const hasMore = rows.length > input.limit;
501
+ const items = rows.slice(0, input.limit);
502
+ const lastEvent = items.at(-1);
503
+ return AgentStoreEventPageSchema.parse({
504
+ items,
505
+ ...hasMore && lastEvent ? { nextSeq: lastEvent.seq + 1 } : {}
506
+ });
507
+ }
508
+ };
509
+ var sqliteArchive = {
510
+ async export(transaction, conversationId) {
511
+ const projections = transaction.prepare(`
512
+ SELECT name, version, upto_seq, payload, updated_at
513
+ FROM stitchkit_agent_runtime_projections
514
+ WHERE conversation_id = ? ORDER BY name
515
+ `).all(conversationId).map((raw) => {
516
+ const row = ArchiveProjectionRowSchema.parse(raw);
517
+ return {
518
+ name: row.name,
519
+ version: row.version,
520
+ uptoSeq: row.upto_seq,
521
+ value: z4.json().parse(parseJson(row.payload)),
522
+ updatedAt: row.updated_at
523
+ };
524
+ });
525
+ const spills = transaction.prepare(`
526
+ SELECT reference_id, run_id, tool_call_id, media_type, bytes, sha256,
527
+ created_at, expires_at, authorization_payload, payload
528
+ FROM stitchkit_agent_runtime_spills
529
+ WHERE conversation_id = ? ORDER BY created_at, reference_id
530
+ `).all(conversationId).map((raw) => {
531
+ const row = ArchiveSpillRowSchema.parse(raw);
532
+ return {
533
+ reference: row.reference_id,
534
+ ...row.run_id && { runId: row.run_id },
535
+ ...row.tool_call_id && { toolCallId: row.tool_call_id },
536
+ mediaType: row.media_type,
537
+ bytes: row.bytes,
538
+ sha256: row.sha256,
539
+ createdAt: row.created_at,
540
+ ...row.expires_at && { expiresAt: row.expires_at },
541
+ ...row.authorization_payload && {
542
+ authorization: z4.json().parse(parseJson(row.authorization_payload))
543
+ },
544
+ base64: Buffer.from(row.payload).toString("base64")
545
+ };
546
+ });
547
+ return { projections, spills };
548
+ },
549
+ async import(transaction, archive) {
550
+ for (const raw of archive.projections) {
551
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.archiveType === "runtime-snapshot") {
552
+ continue;
553
+ }
554
+ const projection = z4.object({
555
+ name: z4.string(),
556
+ version: z4.int().positive(),
557
+ uptoSeq: z4.int().nonnegative(),
558
+ value: z4.json(),
559
+ updatedAt: z4.string()
560
+ }).strict().parse(raw);
561
+ transaction.prepare(`
562
+ INSERT INTO stitchkit_agent_runtime_projections
563
+ (conversation_id, name, version, upto_seq, payload, updated_at)
564
+ VALUES (?, ?, ?, ?, ?, ?)
565
+ `).run(archive.conversationId, projection.name, projection.version, projection.uptoSeq, encodeJson(projection.value), projection.updatedAt);
566
+ }
567
+ for (const raw of archive.spills) {
568
+ const spill = z4.object({
569
+ reference: z4.string(),
570
+ runId: z4.string().optional(),
571
+ toolCallId: z4.string().optional(),
572
+ mediaType: z4.string(),
573
+ bytes: z4.int().nonnegative(),
574
+ sha256: z4.string(),
575
+ createdAt: z4.string(),
576
+ expiresAt: z4.string().optional(),
577
+ authorization: z4.json().optional(),
578
+ base64: z4.string()
579
+ }).strict().parse(raw);
580
+ const payload = Buffer.from(spill.base64, "base64");
581
+ if (payload.byteLength !== spill.bytes) {
582
+ throw new TypeError("Conversation archive spill byte count is inconsistent");
583
+ }
584
+ if (createHash("sha256").update(payload).digest("hex") !== spill.sha256) {
585
+ throw new TypeError("Conversation archive spill digest is inconsistent");
586
+ }
587
+ transaction.prepare(`
588
+ INSERT INTO stitchkit_agent_runtime_spills (
589
+ reference_id, conversation_id, run_id, tool_call_id, media_type,
590
+ bytes, sha256, created_at, expires_at, authorization_payload, payload
591
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
592
+ `).run(spill.reference, archive.conversationId, spill.runId ?? null, spill.toolCallId ?? null, spill.mediaType, spill.bytes, spill.sha256, spill.createdAt, spill.expiresAt ?? null, spill.authorization ? encodeJson(spill.authorization) : null, payload);
593
+ }
594
+ }
595
+ };
596
+
597
+ // src/agent-runtime/sqlite-history.ts
598
+ var sqliteHistory = {
599
+ async load(transaction, conversationId) {
600
+ return transaction.prepare(`
601
+ SELECT payload FROM stitchkit_agent_runtime_messages
602
+ WHERE conversation_id = ? AND active = 1 ORDER BY position ASC
603
+ `).all(conversationId).map((value) => AgentMessageSchema.parse(parseJson(MessageRowSchema.parse(value).payload)));
604
+ },
605
+ async hasMessage(transaction, input) {
606
+ const row = transaction.prepare(`
607
+ SELECT count(*) AS count FROM stitchkit_agent_runtime_messages
608
+ WHERE conversation_id = ? AND id = ?
609
+ `).get(input.conversationId, input.messageId);
610
+ return CountRowSchema.parse(row).count > 0;
611
+ },
612
+ async apply(transaction, rawMutation) {
613
+ const mutation = AgentHistoryMutationSchema.parse(rawMutation);
614
+ const message = mutation.type === "admit" ? mutation.input : mutation.type === "upsert-assistant" ? mutation.message : mutation.type === "seed" ? mutation.message : mutation.summary;
615
+ if (mutation.type === "seed") {
616
+ transaction.prepare(`
617
+ UPDATE stitchkit_agent_runtime_messages SET position = position + 1
618
+ WHERE conversation_id = ?
619
+ `).run(mutation.message.conversationId);
620
+ transaction.prepare(`
621
+ INSERT INTO stitchkit_agent_runtime_messages
622
+ (conversation_id, id, position, active, payload)
623
+ VALUES (?, ?, 0, 1, ?)
624
+ ON CONFLICT (conversation_id, id) DO UPDATE SET
625
+ position = excluded.position,
626
+ active = excluded.active,
627
+ payload = excluded.payload
628
+ `).run(mutation.message.conversationId, mutation.message.id, encodeJson(mutation.message));
629
+ return;
630
+ }
631
+ if (mutation.type === "replace-compacted-range") {
632
+ const parameters = mutation.replacedMessageIds;
633
+ const rows = transaction.prepare(`
634
+ SELECT position FROM stitchkit_agent_runtime_messages
635
+ WHERE conversation_id = ? AND active = 1
636
+ AND id IN (${placeholders(parameters.length)})
637
+ ORDER BY position ASC
638
+ `).all(message.conversationId, ...parameters).map((row) => PositionedMessageRowSchema.parse(row));
639
+ const anchor = rows.at(-1);
640
+ if (!anchor || rows.length !== parameters.length) {
641
+ throw new Error("Compaction range changed inside the transaction");
642
+ }
643
+ transaction.prepare(`
644
+ UPDATE stitchkit_agent_runtime_messages SET active = 0
645
+ WHERE conversation_id = ? AND id IN (${placeholders(parameters.length)})
646
+ `).run(message.conversationId, ...parameters);
647
+ transaction.prepare(`
648
+ INSERT INTO stitchkit_agent_runtime_messages
649
+ (conversation_id, id, position, active, payload)
650
+ VALUES (?, ?, ?, 1, ?)
651
+ `).run(message.conversationId, message.id, anchor.position, encodeJson(message));
652
+ return;
653
+ }
654
+ const existing = transaction.prepare(`
655
+ SELECT position FROM stitchkit_agent_runtime_messages
656
+ WHERE conversation_id = ? AND id = ?
657
+ `).get(message.conversationId, message.id);
658
+ if (!missing(existing)) {
659
+ transaction.prepare(`
660
+ UPDATE stitchkit_agent_runtime_messages SET payload = ?, active = 1
661
+ WHERE conversation_id = ? AND id = ?
662
+ `).run(encodeJson(message), message.conversationId, message.id);
663
+ return;
664
+ }
665
+ const last = transaction.prepare(`
666
+ SELECT position FROM stitchkit_agent_runtime_messages
667
+ WHERE conversation_id = ? ORDER BY position DESC LIMIT 1
668
+ `).get(message.conversationId);
669
+ const position = missing(last) ? 0 : PositionedMessageRowSchema.parse(last).position + 1;
670
+ transaction.prepare(`
671
+ INSERT INTO stitchkit_agent_runtime_messages
672
+ (conversation_id, id, position, active, payload)
673
+ VALUES (?, ?, ?, 1, ?)
674
+ `).run(message.conversationId, message.id, position, encodeJson(message));
675
+ }
676
+ };
677
+
678
+ // src/agent-runtime/sqlite-ledger.ts
679
+ import { z as z5 } from "zod";
680
+ var AdmissionRowSchema2 = z5.object({
681
+ conversation_id: z5.string(),
682
+ idempotency_key: z5.string(),
683
+ input_payload: z5.string(),
684
+ run_id: z5.string(),
685
+ assistant_message_id: z5.string()
686
+ });
687
+ var SeedRowSchema = z5.object({
688
+ conversation_id: z5.string(),
689
+ seed_key: z5.string(),
690
+ message_ids: z5.string()
691
+ });
692
+ function parseAdmissionRow(value) {
693
+ const row = AdmissionRowSchema2.parse(value);
694
+ return AgentAdmissionReceiptSchema.parse({
695
+ schemaVersion: 1,
696
+ conversationId: row.conversation_id,
697
+ idempotencyKey: row.idempotency_key,
698
+ input: AgentMessageSchema.parse(parseJson(row.input_payload)),
699
+ runId: row.run_id,
700
+ assistantMessageId: row.assistant_message_id
701
+ });
702
+ }
703
+ var sqliteHeads = {
704
+ async load(transaction, conversationId) {
705
+ const value = transaction.prepare("SELECT version FROM stitchkit_agent_runtime_heads WHERE conversation_id = ?").get(conversationId);
706
+ if (missing(value))
707
+ return;
708
+ const row = HeadRowSchema.parse(value);
709
+ return AgentRuntimeHeadSchema.parse({
710
+ schemaVersion: 1,
711
+ conversationId,
712
+ version: row.version
713
+ });
714
+ },
715
+ async compareAndSwap(transaction, input) {
716
+ const current = transaction.prepare("SELECT version FROM stitchkit_agent_runtime_heads WHERE conversation_id = ?").get(input.conversationId);
717
+ const actualVersion = missing(current) ? 0 : HeadRowSchema.parse(current).version;
718
+ if (actualVersion !== input.expectedVersion)
719
+ return { outcome: "conflict", actualVersion };
720
+ transaction.prepare(`
721
+ INSERT INTO stitchkit_agent_runtime_heads (conversation_id, version)
722
+ VALUES (?, ?)
723
+ ON CONFLICT (conversation_id) DO UPDATE SET version = excluded.version
724
+ `).run(input.conversationId, input.next.version);
725
+ return { outcome: "applied" };
726
+ }
727
+ };
728
+ var sqliteRuns = {
729
+ async load(transaction, input) {
730
+ const row = transaction.prepare(`
731
+ SELECT payload, terminal_assistant_payload
732
+ FROM stitchkit_agent_runtime_runs
733
+ WHERE conversation_id = ? AND run_id = ?
734
+ `).get(input.conversationId, input.runId);
735
+ return missing(row) ? undefined : parseRunRow(row);
736
+ },
737
+ async loadByAssistantMessageId(transaction, input) {
738
+ const row = transaction.prepare(`
739
+ SELECT payload, terminal_assistant_payload
740
+ FROM stitchkit_agent_runtime_runs
741
+ WHERE conversation_id = ? AND assistant_message_id = ?
742
+ `).get(input.conversationId, input.assistantMessageId);
743
+ return missing(row) ? undefined : parseRunRow(row);
744
+ },
745
+ async loadMany(transaction, input) {
746
+ if (input.runIds.length === 0)
747
+ return [];
748
+ return transaction.prepare(`
749
+ SELECT payload, terminal_assistant_payload
750
+ FROM stitchkit_agent_runtime_runs
751
+ WHERE conversation_id = ? AND run_id IN (${placeholders(input.runIds.length)})
752
+ `).all(input.conversationId, ...input.runIds).map(parseRunRow);
753
+ },
754
+ async listActive(transaction, conversationId) {
755
+ return transaction.prepare(`
756
+ SELECT payload, terminal_assistant_payload
757
+ FROM stitchkit_agent_runtime_runs
758
+ WHERE conversation_id = ? AND state IN ('queued', 'running', 'interrupt_requested')
759
+ `).all(conversationId).map(parseRunRow);
760
+ },
761
+ async save(transaction, rawRecord) {
762
+ const record = AgentStoredRunSchema.parse(rawRecord);
763
+ transaction.prepare(`
764
+ INSERT INTO stitchkit_agent_runtime_runs (
765
+ conversation_id, run_id, assistant_message_id, state, created_at, payload,
766
+ terminal_assistant_payload
767
+ ) VALUES (?, ?, ?, ?, ?, ?, ?)
768
+ ON CONFLICT (conversation_id, run_id) DO UPDATE SET
769
+ assistant_message_id = excluded.assistant_message_id,
770
+ state = excluded.state,
771
+ created_at = excluded.created_at,
772
+ payload = excluded.payload,
773
+ terminal_assistant_payload = excluded.terminal_assistant_payload
774
+ `).run(record.run.conversationId, record.run.id, record.run.assistantMessageId, record.run.state, record.run.createdAt, encodeJson(record.run), record.terminalAssistant ? encodeJson(record.terminalAssistant) : null);
775
+ }
776
+ };
777
+ var sqliteAdmissions = {
778
+ async load(transaction, input) {
779
+ const value = transaction.prepare(`
780
+ SELECT conversation_id, idempotency_key, input_payload, run_id, assistant_message_id
781
+ FROM stitchkit_agent_runtime_admissions
782
+ WHERE conversation_id = ? AND idempotency_key = ?
783
+ `).get(input.conversationId, input.idempotencyKey);
784
+ return missing(value) ? undefined : parseAdmissionRow(value);
785
+ },
786
+ async loadByInputMessageId(transaction, input) {
787
+ const value = transaction.prepare(`
788
+ SELECT conversation_id, idempotency_key, input_payload, run_id, assistant_message_id
789
+ FROM stitchkit_agent_runtime_admissions
790
+ WHERE conversation_id = ? AND input_message_id = ?
791
+ `).get(input.conversationId, input.inputMessageId);
792
+ return missing(value) ? undefined : parseAdmissionRow(value);
793
+ },
794
+ async create(transaction, rawReceipt) {
795
+ const receipt = AgentAdmissionReceiptSchema.parse(rawReceipt);
796
+ transaction.prepare(`
797
+ INSERT INTO stitchkit_agent_runtime_admissions (
798
+ conversation_id, idempotency_key, input_message_id, run_id,
799
+ assistant_message_id, input_payload
800
+ ) VALUES (?, ?, ?, ?, ?, ?)
801
+ `).run(receipt.conversationId, receipt.idempotencyKey, receipt.input.id, receipt.runId, receipt.assistantMessageId, encodeJson(receipt.input));
802
+ }
803
+ };
804
+ var sqliteSeeds = {
805
+ async load(transaction, input) {
806
+ const value = transaction.prepare(`
807
+ SELECT conversation_id, seed_key, message_ids
808
+ FROM stitchkit_agent_runtime_seeds
809
+ WHERE conversation_id = ? AND seed_key = ?
810
+ `).get(input.conversationId, input.seedKey);
811
+ if (missing(value))
812
+ return;
813
+ const row = SeedRowSchema.parse(value);
814
+ return AgentSeedReceiptSchema.parse({
815
+ schemaVersion: 1,
816
+ conversationId: row.conversation_id,
817
+ seedKey: row.seed_key,
818
+ messageIds: z5.array(z5.string().min(1)).parse(parseJson(row.message_ids))
819
+ });
820
+ },
821
+ async create(transaction, rawReceipt) {
822
+ const receipt = AgentSeedReceiptSchema.parse(rawReceipt);
823
+ transaction.prepare(`
824
+ INSERT INTO stitchkit_agent_runtime_seeds (
825
+ conversation_id, seed_key, message_ids, created_at
826
+ ) VALUES (?, ?, ?, ?)
827
+ `).run(receipt.conversationId, receipt.seedKey, encodeJson(receipt.messageIds), new Date().toISOString());
828
+ }
829
+ };
830
+
831
+ // src/agent-runtime/sqlite-reads.ts
832
+ import { z as z6 } from "zod";
833
+
834
+ // src/agent-runtime/sqlite-transactions.ts
835
+ import { AsyncLocalStorage } from "node:async_hooks";
836
+ function createSqliteStoreState(database) {
837
+ return {
838
+ database,
839
+ closing: false,
840
+ closed: false,
841
+ tail: Promise.resolve(),
842
+ insideScope: new AsyncLocalStorage
843
+ };
844
+ }
845
+ function serial(state, work) {
846
+ if (state.closing || state.closed) {
847
+ return Promise.reject(new Error("SQLite agent-runtime store is closing"));
848
+ }
849
+ if (state.insideScope.getStore()) {
850
+ return Promise.reject(new Error("SQLite agent-runtime store called from inside its own transaction scope; use scope.database and scope.appendEvent"));
851
+ }
852
+ const result = state.tail.then(work, work);
853
+ state.tail = result.then(() => {
854
+ return;
855
+ }, () => {
856
+ return;
857
+ });
858
+ return result;
859
+ }
860
+ function runSqliteTransaction(state, access, work) {
861
+ const database = state.database;
862
+ return serial(state, async () => {
863
+ database.exec(access === "read" ? "BEGIN" : "BEGIN IMMEDIATE");
864
+ try {
865
+ const result = await work(database);
866
+ database.exec("COMMIT");
867
+ return result;
868
+ } catch (error) {
869
+ database.exec("ROLLBACK");
870
+ throw error;
871
+ }
872
+ });
873
+ }
874
+ function runSqliteStoreScope(state, driver, work) {
875
+ return runSqliteTransaction(state, "write", (transaction) => state.insideScope.run(true, () => work({
876
+ database: transaction,
877
+ appendEvent: (input) => appendEventIn(driver, transaction, AppendAgentStoreEventSchema.parse(input))
878
+ })));
879
+ }
880
+ async function closeSqliteStore(state) {
881
+ if (state.closed)
882
+ return;
883
+ state.closing = true;
884
+ await state.tail;
885
+ state.database.close();
886
+ state.closed = true;
887
+ }
888
+
889
+ // src/agent-runtime/sqlite-reads.ts
890
+ var RecoverableRowSchema = z6.object({
891
+ conversation_id: z6.string(),
892
+ run_id: z6.string(),
893
+ payload: z6.string()
894
+ });
895
+ var ConversationHeadRowSchema = z6.object({
896
+ conversation_id: z6.string(),
897
+ version: z6.number().int().nonnegative()
898
+ });
899
+ var MessagePageRowSchema = z6.object({
900
+ row_id: z6.number().int().positive(),
901
+ position: z6.number().int().nonnegative(),
902
+ active: z6.union([z6.literal(0), z6.literal(1)]),
903
+ payload: z6.string()
904
+ });
905
+ function recoveryCursor(conversationId, runId) {
906
+ return encodeJson([conversationId, runId]);
907
+ }
908
+ function parseRecoveryCursor(cursor) {
909
+ return z6.tuple([z6.string().min(1), z6.string().min(1)]).parse(parseJson(cursor));
910
+ }
911
+ function conversationCursor(conversationId) {
912
+ return encodeJson([conversationId]);
913
+ }
914
+ function parseConversationCursor(cursor) {
915
+ return z6.tuple([z6.string().min(1)]).parse(parseJson(cursor))[0];
916
+ }
917
+ function messageCursor(position, rowId) {
918
+ return encodeJson([position, rowId]);
919
+ }
920
+ function parseMessageCursor(cursor) {
921
+ const parsed = z6.union([
922
+ z6.tuple([z6.int().nonnegative(), z6.int().positive()]),
923
+ z6.tuple([z6.int().nonnegative()])
924
+ ]).parse(parseJson(cursor));
925
+ const [position, rowId] = parsed;
926
+ return { position, ...rowId !== undefined && { rowId } };
927
+ }
928
+ function messagePreview(message) {
929
+ const text = message.parts.find((part) => part.type === "text");
930
+ return text?.type === "text" ? text.text.slice(0, 160) : message.role;
931
+ }
932
+ function scanSqliteRecoverable(state, input) {
933
+ const database = state.database;
934
+ return runSqliteTransaction(state, "read", async () => {
935
+ const cursor = input.cursor ? parseRecoveryCursor(input.cursor) : undefined;
936
+ const values = cursor ? [cursor[0], cursor[0], cursor[1], input.limit + 1] : [input.limit + 1];
937
+ const rows = database.prepare(`
938
+ SELECT conversation_id, run_id, payload
939
+ FROM stitchkit_agent_runtime_runs
940
+ WHERE state IN ('queued', 'running', 'interrupt_requested')
941
+ ${cursor ? "AND (conversation_id > ? OR (conversation_id = ? AND run_id > ?))" : ""}
942
+ ORDER BY conversation_id ASC, run_id ASC LIMIT ?
943
+ `).all(...values).map((row) => RecoverableRowSchema.parse(row));
944
+ const hasMore = rows.length > input.limit;
945
+ const pageRows = rows.slice(0, input.limit);
946
+ const items = pageRows.map((row) => {
947
+ const run = AgentRunSchema.parse(parseJson(row.payload));
948
+ return AgentRecoverableDescriptorSchema.parse({
949
+ conversationId: row.conversation_id,
950
+ run
951
+ });
952
+ });
953
+ const last = pageRows.at(-1);
954
+ return AgentRecoverablePageSchema.parse({
955
+ items,
956
+ ...hasMore && last ? { nextCursor: recoveryCursor(last.conversation_id, last.run_id) } : {}
957
+ });
958
+ });
959
+ }
960
+ function listSqliteConversations(state, input) {
961
+ const database = state.database;
962
+ return runSqliteTransaction(state, "read", async () => {
963
+ if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 1000) {
964
+ throw new TypeError("Conversation page limit must be between 1 and 1000");
965
+ }
966
+ const cursor = input.cursor ? parseConversationCursor(input.cursor) : undefined;
967
+ const search = input.search?.trim();
968
+ const clauses = [
969
+ ...cursor ? ["conversation_id > ?"] : [],
970
+ ...search ? ["instr(conversation_id, ?) > 0"] : []
971
+ ];
972
+ const parameters = [
973
+ ...cursor ? [cursor] : [],
974
+ ...search ? [search] : [],
975
+ input.limit + 1
976
+ ];
977
+ const rows = database.prepare(`
978
+ SELECT conversation_id, version FROM stitchkit_agent_runtime_heads
979
+ ${clauses.length > 0 ? `WHERE ${clauses.join(" AND ")}` : ""}
980
+ ORDER BY conversation_id ASC LIMIT ?
981
+ `).all(...parameters).map((row) => ConversationHeadRowSchema.parse(row));
982
+ const hasMore = rows.length > input.limit;
983
+ const pageRows = rows.slice(0, input.limit);
984
+ const items = pageRows.map((row) => {
985
+ const latestRaw = database.prepare(`
986
+ SELECT payload FROM stitchkit_agent_runtime_messages
987
+ WHERE conversation_id = ? AND active = 1
988
+ ORDER BY position DESC LIMIT 1
989
+ `).get(row.conversation_id);
990
+ if (missing(latestRaw)) {
991
+ throw new Error("Agent conversation head has no active history");
992
+ }
993
+ const latest = AgentMessageSchema.parse(parseJson(MessageRowSchema.parse(latestRaw).payload));
994
+ const active = CountRowSchema.parse(database.prepare(`
995
+ SELECT count(*) AS count FROM stitchkit_agent_runtime_runs
996
+ WHERE conversation_id = ?
997
+ AND state IN ('queued', 'running', 'interrupt_requested')
998
+ `).get(row.conversation_id));
999
+ return {
1000
+ conversationId: row.conversation_id,
1001
+ version: row.version,
1002
+ updatedAt: latest.updatedAt,
1003
+ preview: messagePreview(latest),
1004
+ activeRuns: active.count
1005
+ };
1006
+ });
1007
+ const last = pageRows.at(-1);
1008
+ return AgentConversationPageSchema.parse({
1009
+ items,
1010
+ ...hasMore && last ? { nextCursor: conversationCursor(last.conversation_id) } : {}
1011
+ });
1012
+ });
1013
+ }
1014
+ function pageSqliteConversationMessages(state, input) {
1015
+ const database = state.database;
1016
+ return runSqliteTransaction(state, "read", async () => {
1017
+ if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 1000) {
1018
+ throw new TypeError("Conversation message page limit must be between 1 and 1000");
1019
+ }
1020
+ const cursor = input.cursor ? parseMessageCursor(input.cursor) : undefined;
1021
+ const before = input.direction === "before";
1022
+ const direction = before ? "DESC" : "ASC";
1023
+ const comparison = cursor === undefined ? "" : cursor.rowId === undefined ? `AND position ${before ? "<" : ">"} ?` : `AND (position, rowid) ${before ? "<" : ">"} (?, ?)`;
1024
+ const rows = database.prepare(`
1025
+ SELECT rowid AS row_id, position, active, payload
1026
+ FROM stitchkit_agent_runtime_messages
1027
+ WHERE conversation_id = ?
1028
+ ${input.includeCompacted === true ? "" : "AND active = 1"}
1029
+ ${comparison}
1030
+ ORDER BY position ${direction}, rowid ${direction} LIMIT ?
1031
+ `).all(input.conversationId, ...cursor === undefined ? [] : cursor.rowId === undefined ? [cursor.position] : [cursor.position, cursor.rowId], input.limit + 1).map((row) => MessagePageRowSchema.parse(row));
1032
+ const hasMore = rows.length > input.limit;
1033
+ const pageRows = rows.slice(0, input.limit);
1034
+ const ordered = before ? [...pageRows].reverse() : pageRows;
1035
+ const boundary = pageRows.at(-1);
1036
+ const items = ordered.map((row) => ({
1037
+ message: AgentMessageSchema.parse(parseJson(row.payload)),
1038
+ active: row.active === 1
1039
+ }));
1040
+ return AgentConversationMessagePageSchema.parse({
1041
+ items: items.map((entry) => entry.message),
1042
+ compacted: items.filter((entry) => !entry.active).map((entry) => entry.message.id),
1043
+ ...hasMore && boundary ? { nextCursor: messageCursor(boundary.position, boundary.row_id) } : {}
1044
+ });
1045
+ });
1046
+ }
1047
+
1048
+ // src/agent-runtime/sqlite.ts
1049
+ function createSqliteAgentRuntimeStore(config) {
1050
+ const database = config.database;
1051
+ if (config.initialize !== false) {
1052
+ try {
1053
+ initializeAgentRuntimeSqlite(database);
1054
+ } catch (error) {
1055
+ database.close();
1056
+ throw error;
1057
+ }
1058
+ }
1059
+ const state = createSqliteStoreState(database);
1060
+ const driver = {
1061
+ conversations: sqliteConversationPurge(database),
1062
+ transaction: (work, options) => runSqliteTransaction(state, options?.access ?? "write", work),
1063
+ head: sqliteHeads,
1064
+ runs: sqliteRuns,
1065
+ admissions: sqliteAdmissions,
1066
+ seeds: sqliteSeeds,
1067
+ history: sqliteHistory,
1068
+ events: sqliteEvents,
1069
+ archive: sqliteArchive,
1070
+ scanRecoverable: (input) => scanSqliteRecoverable(state, input)
1071
+ };
1072
+ return {
1073
+ store: createAgentRuntimeStore(driver),
1074
+ database,
1075
+ transaction: (work) => runSqliteStoreScope(state, driver, work),
1076
+ conversations: {
1077
+ list: (input) => listSqliteConversations(state, input),
1078
+ messages: (input) => pageSqliteConversationMessages(state, input)
1079
+ },
1080
+ close: () => closeSqliteStore(state)
1081
+ };
1082
+ }
1083
+
1084
+ export { initializeAgentRuntimeSqlite, createSqliteAgentRuntimeStore };