stitchkit 0.133.2 → 0.134.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 (616) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +14 -11
  3. package/dist/agent-executor/acp/v1-connect.d.ts +3 -0
  4. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  5. package/dist/agent-executor/acp/v1-map.d.ts +13 -3
  6. package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
  7. package/dist/agent-executor/acp/v1-protocol.d.ts +59 -0
  8. package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -1
  9. package/dist/agent-executor/codex/connect.d.ts +2 -0
  10. package/dist/agent-executor/codex/connect.d.ts.map +1 -1
  11. package/dist/agent-executor/codex/driver.d.ts +3 -0
  12. package/dist/agent-executor/codex/driver.d.ts.map +1 -1
  13. package/dist/agent-executor/contract.d.ts +42 -0
  14. package/dist/agent-executor/contract.d.ts.map +1 -1
  15. package/dist/agent-executor/engine-process.d.ts +20 -0
  16. package/dist/agent-executor/engine-process.d.ts.map +1 -1
  17. package/dist/agent-executor/executor-contract.d.ts +42 -0
  18. package/dist/agent-executor/executor-contract.d.ts.map +1 -1
  19. package/dist/agent-executor/handoff-schemas.d.ts +30 -0
  20. package/dist/agent-executor/handoff-schemas.d.ts.map +1 -1
  21. package/dist/agent-executor/projection.d.ts.map +1 -1
  22. package/dist/agent-executor/session-primitives.d.ts +4 -1
  23. package/dist/agent-executor/session-primitives.d.ts.map +1 -1
  24. package/dist/agent-executor/vocabulary.d.ts +100 -0
  25. package/dist/agent-executor/vocabulary.d.ts.map +1 -1
  26. package/dist/agent-parts/model.d.ts +1559 -0
  27. package/dist/agent-parts/model.d.ts.map +1 -0
  28. package/dist/agent-parts/parts.d.ts +21 -0
  29. package/dist/agent-parts/parts.d.ts.map +1 -1
  30. package/dist/agent-runtime/ai-sdk-convert.d.ts +15 -0
  31. package/dist/agent-runtime/ai-sdk-convert.d.ts.map +1 -0
  32. package/dist/agent-runtime/ai-sdk.d.ts +31 -0
  33. package/dist/agent-runtime/ai-sdk.d.ts.map +1 -0
  34. package/dist/agent-runtime/anthropic-media.d.ts +11 -0
  35. package/dist/agent-runtime/anthropic-media.d.ts.map +1 -0
  36. package/dist/agent-runtime/anthropic-messages.d.ts +24 -0
  37. package/dist/agent-runtime/anthropic-messages.d.ts.map +1 -0
  38. package/dist/agent-runtime/anthropic-options.d.ts +79 -0
  39. package/dist/agent-runtime/anthropic-options.d.ts.map +1 -0
  40. package/dist/agent-runtime/anthropic-response.d.ts +19 -0
  41. package/dist/agent-runtime/anthropic-response.d.ts.map +1 -0
  42. package/dist/agent-runtime/anthropic-sse.d.ts +4 -0
  43. package/dist/agent-runtime/anthropic-sse.d.ts.map +1 -0
  44. package/dist/agent-runtime/anthropic.d.ts +27 -0
  45. package/dist/agent-runtime/anthropic.d.ts.map +1 -0
  46. package/dist/agent-runtime/branch-observations.d.ts +25 -25
  47. package/dist/agent-runtime/branch-provider.d.ts +86 -0
  48. package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
  49. package/dist/agent-runtime/branch-replay.d.ts +30 -0
  50. package/dist/agent-runtime/branch-replay.d.ts.map +1 -1
  51. package/dist/agent-runtime/browser-control-contract.d.ts +204 -0
  52. package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -1
  53. package/dist/agent-runtime/browser-controller-view.d.ts +44 -0
  54. package/dist/agent-runtime/browser-controller-view.d.ts.map +1 -0
  55. package/dist/agent-runtime/browser-controller.d.ts +12 -8
  56. package/dist/agent-runtime/browser-controller.d.ts.map +1 -1
  57. package/dist/agent-runtime/child-budget-policy.d.ts +2 -3
  58. package/dist/agent-runtime/child-budget-policy.d.ts.map +1 -1
  59. package/dist/agent-runtime/compaction.d.ts +27 -10
  60. package/dist/agent-runtime/compaction.d.ts.map +1 -1
  61. package/dist/agent-runtime/control-interaction-schema.d.ts +157 -0
  62. package/dist/agent-runtime/control-interaction-schema.d.ts.map +1 -0
  63. package/dist/agent-runtime/control-schema.d.ts +183 -27
  64. package/dist/agent-runtime/control-schema.d.ts.map +1 -1
  65. package/dist/agent-runtime/control-view.d.ts +64 -0
  66. package/dist/agent-runtime/control-view.d.ts.map +1 -0
  67. package/dist/agent-runtime/conversations.d.ts +10 -0
  68. package/dist/agent-runtime/conversations.d.ts.map +1 -1
  69. package/dist/agent-runtime/deferred-tool-selection.d.ts +2 -2
  70. package/dist/agent-runtime/deferred-tool-selection.d.ts.map +1 -1
  71. package/dist/agent-runtime/deferred-tool-types.d.ts +2 -2
  72. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
  73. package/dist/agent-runtime/deferred-tools-internal.d.ts +8 -11
  74. package/dist/agent-runtime/deferred-tools-internal.d.ts.map +1 -1
  75. package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
  76. package/dist/agent-runtime/event-schema.d.ts +80 -0
  77. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  78. package/dist/agent-runtime/harness-contract.d.ts +2 -2
  79. package/dist/agent-runtime/harness-contract.d.ts.map +1 -1
  80. package/dist/agent-runtime/harness-control.d.ts.map +1 -1
  81. package/dist/agent-runtime/harness-realtime.d.ts.map +1 -1
  82. package/dist/agent-runtime/harness.d.ts +2 -2
  83. package/dist/agent-runtime/harness.d.ts.map +1 -1
  84. package/dist/agent-runtime/history.d.ts +25 -16
  85. package/dist/agent-runtime/history.d.ts.map +1 -1
  86. package/dist/agent-runtime/invocation-attempt.d.ts +7 -3
  87. package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
  88. package/dist/agent-runtime/invocation-payload.d.ts +13 -7
  89. package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
  90. package/dist/agent-runtime/invocation-stream.d.ts +20 -0
  91. package/dist/agent-runtime/invocation-stream.d.ts.map +1 -0
  92. package/dist/agent-runtime/invocations.d.ts +2 -2
  93. package/dist/agent-runtime/invocations.d.ts.map +1 -1
  94. package/dist/agent-runtime/models-driver-step.d.ts +212 -0
  95. package/dist/agent-runtime/models-driver-step.d.ts.map +1 -0
  96. package/dist/agent-runtime/models-driver-telemetry.d.ts +42 -0
  97. package/dist/agent-runtime/models-driver-telemetry.d.ts.map +1 -0
  98. package/dist/agent-runtime/models-driver.d.ts +235 -0
  99. package/dist/agent-runtime/models-driver.d.ts.map +1 -0
  100. package/dist/agent-runtime/models.d.ts +3 -26
  101. package/dist/agent-runtime/models.d.ts.map +1 -1
  102. package/dist/agent-runtime/observability.d.ts +64 -0
  103. package/dist/agent-runtime/observability.d.ts.map +1 -1
  104. package/dist/agent-runtime/openai-messages.d.ts +11 -0
  105. package/dist/agent-runtime/openai-messages.d.ts.map +1 -0
  106. package/dist/agent-runtime/openai-options.d.ts +91 -0
  107. package/dist/agent-runtime/openai-options.d.ts.map +1 -0
  108. package/dist/agent-runtime/openai-response.d.ts +77 -0
  109. package/dist/agent-runtime/openai-response.d.ts.map +1 -0
  110. package/dist/agent-runtime/openai-sse-state.d.ts +54 -0
  111. package/dist/agent-runtime/openai-sse-state.d.ts.map +1 -0
  112. package/dist/agent-runtime/openai-sse.d.ts +4 -0
  113. package/dist/agent-runtime/openai-sse.d.ts.map +1 -0
  114. package/dist/agent-runtime/openai.d.ts +31 -0
  115. package/dist/agent-runtime/openai.d.ts.map +1 -0
  116. package/dist/agent-runtime/openrouter-admission.d.ts +3 -0
  117. package/dist/agent-runtime/openrouter-admission.d.ts.map +1 -1
  118. package/dist/agent-runtime/openrouter-benchmarks.d.ts +17 -0
  119. package/dist/agent-runtime/openrouter-benchmarks.d.ts.map +1 -0
  120. package/dist/agent-runtime/openrouter-catalog-cache.d.ts +70 -0
  121. package/dist/agent-runtime/openrouter-catalog-cache.d.ts.map +1 -0
  122. package/dist/agent-runtime/openrouter-catalog-query.d.ts +57 -0
  123. package/dist/agent-runtime/openrouter-catalog-query.d.ts.map +1 -0
  124. package/dist/agent-runtime/openrouter-catalog.d.ts +189 -14
  125. package/dist/agent-runtime/openrouter-catalog.d.ts.map +1 -1
  126. package/dist/agent-runtime/openrouter-models.d.ts +168 -31
  127. package/dist/agent-runtime/openrouter-models.d.ts.map +1 -1
  128. package/dist/agent-runtime/openrouter-options.d.ts +45 -15
  129. package/dist/agent-runtime/openrouter-options.d.ts.map +1 -1
  130. package/dist/agent-runtime/openrouter-response.d.ts +22 -0
  131. package/dist/agent-runtime/openrouter-response.d.ts.map +1 -0
  132. package/dist/agent-runtime/openrouter.d.ts +21 -24
  133. package/dist/agent-runtime/openrouter.d.ts.map +1 -1
  134. package/dist/agent-runtime/owned-provider-stream.d.ts +4 -4
  135. package/dist/agent-runtime/owned-provider-stream.d.ts.map +1 -1
  136. package/dist/agent-runtime/prompt.d.ts +3 -3
  137. package/dist/agent-runtime/prompt.d.ts.map +1 -1
  138. package/dist/agent-runtime/protocol.d.ts +28 -3
  139. package/dist/agent-runtime/protocol.d.ts.map +1 -1
  140. package/dist/agent-runtime/provider-cache.d.ts +30 -0
  141. package/dist/agent-runtime/provider-cache.d.ts.map +1 -0
  142. package/dist/agent-runtime/provider-content.d.ts +147 -0
  143. package/dist/agent-runtime/provider-content.d.ts.map +1 -1
  144. package/dist/agent-runtime/provider-failure.d.ts +51 -26
  145. package/dist/agent-runtime/provider-failure.d.ts.map +1 -1
  146. package/dist/agent-runtime/provider-history.d.ts +13 -0
  147. package/dist/agent-runtime/provider-history.d.ts.map +1 -0
  148. package/dist/agent-runtime/provider-http.d.ts +68 -0
  149. package/dist/agent-runtime/provider-http.d.ts.map +1 -0
  150. package/dist/agent-runtime/provider-journal.d.ts +149 -0
  151. package/dist/agent-runtime/provider-journal.d.ts.map +1 -1
  152. package/dist/agent-runtime/provider-json-schema-strip.d.ts +8 -0
  153. package/dist/agent-runtime/provider-json-schema-strip.d.ts.map +1 -0
  154. package/dist/agent-runtime/provider-json-schema.d.ts +28 -0
  155. package/dist/agent-runtime/provider-json-schema.d.ts.map +1 -0
  156. package/dist/agent-runtime/provider-media.d.ts +49 -0
  157. package/dist/agent-runtime/provider-media.d.ts.map +1 -0
  158. package/dist/agent-runtime/provider-openai-chat-helpers.d.ts +27 -0
  159. package/dist/agent-runtime/provider-openai-chat-helpers.d.ts.map +1 -0
  160. package/dist/agent-runtime/provider-openai-chat-sse.d.ts +25 -0
  161. package/dist/agent-runtime/provider-openai-chat-sse.d.ts.map +1 -0
  162. package/dist/agent-runtime/provider-openai-chat.d.ts +27 -0
  163. package/dist/agent-runtime/provider-openai-chat.d.ts.map +1 -0
  164. package/dist/agent-runtime/provider-origin.d.ts +3 -12
  165. package/dist/agent-runtime/provider-origin.d.ts.map +1 -1
  166. package/dist/agent-runtime/provider-sse.d.ts +30 -0
  167. package/dist/agent-runtime/provider-sse.d.ts.map +1 -0
  168. package/dist/agent-runtime/provider-stream-parts.d.ts +5 -0
  169. package/dist/agent-runtime/provider-stream-parts.d.ts.map +1 -0
  170. package/dist/agent-runtime/provider-stream-segments.d.ts +63 -0
  171. package/dist/agent-runtime/provider-stream-segments.d.ts.map +1 -0
  172. package/dist/agent-runtime/provider-usage.d.ts +24 -0
  173. package/dist/agent-runtime/provider-usage.d.ts.map +1 -0
  174. package/dist/agent-runtime/retry-policy.d.ts +19 -3
  175. package/dist/agent-runtime/retry-policy.d.ts.map +1 -1
  176. package/dist/agent-runtime/run-acquisition.d.ts +4 -4
  177. package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
  178. package/dist/agent-runtime/run-approval.d.ts +82 -0
  179. package/dist/agent-runtime/run-approval.d.ts.map +1 -0
  180. package/dist/agent-runtime/run-complete-retry.d.ts +24 -0
  181. package/dist/agent-runtime/run-complete-retry.d.ts.map +1 -0
  182. package/dist/agent-runtime/run-complete-stream.d.ts +9 -0
  183. package/dist/agent-runtime/run-complete-stream.d.ts.map +1 -0
  184. package/dist/agent-runtime/run-complete-tools.d.ts +21 -0
  185. package/dist/agent-runtime/run-complete-tools.d.ts.map +1 -0
  186. package/dist/agent-runtime/run-complete-types.d.ts +168 -0
  187. package/dist/agent-runtime/run-complete-types.d.ts.map +1 -0
  188. package/dist/agent-runtime/run-complete.d.ts +25 -0
  189. package/dist/agent-runtime/run-complete.d.ts.map +1 -0
  190. package/dist/agent-runtime/run-driver-compose.d.ts +21 -0
  191. package/dist/agent-runtime/run-driver-compose.d.ts.map +1 -0
  192. package/dist/agent-runtime/run-execution-state.d.ts +23 -10
  193. package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
  194. package/dist/agent-runtime/run-execution.d.ts +2 -2
  195. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  196. package/dist/agent-runtime/run-failure.d.ts +2 -2
  197. package/dist/agent-runtime/run-failure.d.ts.map +1 -1
  198. package/dist/agent-runtime/run-history-parts.d.ts +14 -0
  199. package/dist/agent-runtime/run-history-parts.d.ts.map +1 -0
  200. package/dist/agent-runtime/run-loop-events.d.ts +126 -0
  201. package/dist/agent-runtime/run-loop-events.d.ts.map +1 -0
  202. package/dist/agent-runtime/run-model-attempts.d.ts +2 -2
  203. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
  204. package/dist/agent-runtime/run-model-messages.d.ts +9 -0
  205. package/dist/agent-runtime/run-model-messages.d.ts.map +1 -0
  206. package/dist/agent-runtime/run-model-step.d.ts +43 -0
  207. package/dist/agent-runtime/run-model-step.d.ts.map +1 -0
  208. package/dist/agent-runtime/run-model-stream.d.ts +27 -0
  209. package/dist/agent-runtime/run-model-stream.d.ts.map +1 -0
  210. package/dist/agent-runtime/run-operation-lifecycle.d.ts +8 -4
  211. package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +1 -1
  212. package/dist/agent-runtime/run-prompt-history.d.ts +8 -13
  213. package/dist/agent-runtime/run-prompt-history.d.ts.map +1 -1
  214. package/dist/agent-runtime/run-provider-ledger.d.ts +7 -4
  215. package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
  216. package/dist/agent-runtime/run-step-barriers.d.ts +58 -16
  217. package/dist/agent-runtime/run-step-barriers.d.ts.map +1 -1
  218. package/dist/agent-runtime/run-step-helpers.d.ts +49 -0
  219. package/dist/agent-runtime/run-step-helpers.d.ts.map +1 -0
  220. package/dist/agent-runtime/run-step-prepare.d.ts +34 -0
  221. package/dist/agent-runtime/run-step-prepare.d.ts.map +1 -0
  222. package/dist/agent-runtime/run-step-spend.d.ts +85 -10
  223. package/dist/agent-runtime/run-step-spend.d.ts.map +1 -1
  224. package/dist/agent-runtime/run-stream-parts.d.ts +13 -9
  225. package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -1
  226. package/dist/agent-runtime/run-stream-recorded.d.ts +8 -0
  227. package/dist/agent-runtime/run-stream-recorded.d.ts.map +1 -0
  228. package/dist/agent-runtime/run-stream-step-text.d.ts +29 -0
  229. package/dist/agent-runtime/run-stream-step-text.d.ts.map +1 -0
  230. package/dist/agent-runtime/run-terminal.d.ts +3 -3
  231. package/dist/agent-runtime/run-terminal.d.ts.map +1 -1
  232. package/dist/agent-runtime/run-tool-approval-flow.d.ts +36 -0
  233. package/dist/agent-runtime/run-tool-approval-flow.d.ts.map +1 -0
  234. package/dist/agent-runtime/run-tool-approval-records.d.ts +24 -0
  235. package/dist/agent-runtime/run-tool-approval-records.d.ts.map +1 -0
  236. package/dist/agent-runtime/run-tool-call.d.ts +73 -0
  237. package/dist/agent-runtime/run-tool-call.d.ts.map +1 -0
  238. package/dist/agent-runtime/run-tool-errors.d.ts +29 -0
  239. package/dist/agent-runtime/run-tool-errors.d.ts.map +1 -0
  240. package/dist/agent-runtime/run-tool-executor.d.ts +34 -0
  241. package/dist/agent-runtime/run-tool-executor.d.ts.map +1 -0
  242. package/dist/agent-runtime/run-tool-progress.d.ts +2 -2
  243. package/dist/agent-runtime/run-tool-progress.d.ts.map +1 -1
  244. package/dist/agent-runtime/run-turn-preparation.d.ts +7 -6
  245. package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -1
  246. package/dist/agent-runtime/run-unacquired.d.ts +2 -2
  247. package/dist/agent-runtime/run-unacquired.d.ts.map +1 -1
  248. package/dist/agent-runtime/runtime-control.d.ts +4 -4
  249. package/dist/agent-runtime/runtime-control.d.ts.map +1 -1
  250. package/dist/agent-runtime/runtime-internals.d.ts +35 -44
  251. package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
  252. package/dist/agent-runtime/runtime-recovery.d.ts +3 -3
  253. package/dist/agent-runtime/runtime-recovery.d.ts.map +1 -1
  254. package/dist/agent-runtime/runtime-state.d.ts +3 -3
  255. package/dist/agent-runtime/runtime-state.d.ts.map +1 -1
  256. package/dist/agent-runtime/runtime-submit.d.ts +2 -2
  257. package/dist/agent-runtime/runtime-submit.d.ts.map +1 -1
  258. package/dist/agent-runtime/runtime.d.ts +51 -16
  259. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  260. package/dist/agent-runtime/sandbox-process-linux.d.ts +8 -0
  261. package/dist/agent-runtime/sandbox-process-linux.d.ts.map +1 -0
  262. package/dist/agent-runtime/sandbox-process-macos.d.ts +21 -0
  263. package/dist/agent-runtime/sandbox-process-macos.d.ts.map +1 -0
  264. package/dist/agent-runtime/sandbox-process-spec.d.ts +114 -0
  265. package/dist/agent-runtime/sandbox-process-spec.d.ts.map +1 -0
  266. package/dist/agent-runtime/sandbox-process-wrapper.d.ts +19 -0
  267. package/dist/agent-runtime/sandbox-process-wrapper.d.ts.map +1 -0
  268. package/dist/agent-runtime/schemas-message.d.ts +10 -0
  269. package/dist/agent-runtime/schemas-message.d.ts.map +1 -1
  270. package/dist/agent-runtime/schemas-provider.d.ts +2 -0
  271. package/dist/agent-runtime/schemas-provider.d.ts.map +1 -1
  272. package/dist/agent-runtime/schemas-run.d.ts +10 -0
  273. package/dist/agent-runtime/schemas-run.d.ts.map +1 -1
  274. package/dist/agent-runtime/schemas-usage-state.d.ts +6 -0
  275. package/dist/agent-runtime/schemas-usage-state.d.ts.map +1 -0
  276. package/dist/agent-runtime/schemas-usage.d.ts +8 -0
  277. package/dist/agent-runtime/schemas-usage.d.ts.map +1 -1
  278. package/dist/agent-runtime/sql-rows.d.ts +20 -10
  279. package/dist/agent-runtime/sql-rows.d.ts.map +1 -1
  280. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +40 -20
  281. package/dist/agent-runtime/store-conformance-lifecycle.d.ts.map +1 -1
  282. package/dist/agent-runtime/store-conformance-support.d.ts +20 -10
  283. package/dist/agent-runtime/store-conformance-support.d.ts.map +1 -1
  284. package/dist/agent-runtime/store-driver-contract.d.ts +70 -0
  285. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
  286. package/dist/agent-runtime/store-events.d.ts +120 -0
  287. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  288. package/dist/agent-runtime/store.d.ts +140 -0
  289. package/dist/agent-runtime/store.d.ts.map +1 -1
  290. package/dist/agent-runtime/terminal-commit.d.ts +10 -0
  291. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  292. package/dist/agent-runtime/testing.d.ts +20 -0
  293. package/dist/agent-runtime/testing.d.ts.map +1 -1
  294. package/dist/browser/client-call-arguments.d.ts.map +1 -1
  295. package/dist/browser/client-executors.d.ts.map +1 -1
  296. package/dist/browser/client-url.d.ts.map +1 -1
  297. package/dist/browser/client.d.ts +6 -0
  298. package/dist/browser/client.d.ts.map +1 -1
  299. package/dist/browser/device-presence-client.d.ts +42 -0
  300. package/dist/browser/device-presence-client.d.ts.map +1 -0
  301. package/dist/browser/device-presence-ops.d.ts +47 -0
  302. package/dist/browser/device-presence-ops.d.ts.map +1 -0
  303. package/dist/browser/device-presence-relay-adapter.d.ts +37 -0
  304. package/dist/browser/device-presence-relay-adapter.d.ts.map +1 -0
  305. package/dist/browser/http-fetch.d.ts +7 -2
  306. package/dist/browser/http-fetch.d.ts.map +1 -1
  307. package/dist/browser/http-helpers.d.ts +15 -0
  308. package/dist/browser/http-helpers.d.ts.map +1 -0
  309. package/dist/browser/http.d.ts +8 -0
  310. package/dist/browser/http.d.ts.map +1 -1
  311. package/dist/contract/client-types.d.ts +8 -0
  312. package/dist/contract/client-types.d.ts.map +1 -1
  313. package/dist/contract/runtime-context.d.ts +13 -1
  314. package/dist/contract/runtime-context.d.ts.map +1 -1
  315. package/dist/device-relay/agent-handlers.d.ts +45 -0
  316. package/dist/device-relay/agent-handlers.d.ts.map +1 -0
  317. package/dist/device-relay/agent.d.ts +80 -0
  318. package/dist/device-relay/agent.d.ts.map +1 -0
  319. package/dist/device-relay/broker.d.ts +49 -0
  320. package/dist/device-relay/broker.d.ts.map +1 -0
  321. package/dist/device-relay/contract.d.ts +614 -0
  322. package/dist/device-relay/contract.d.ts.map +1 -0
  323. package/dist/device-relay/encoding.d.ts +30 -0
  324. package/dist/device-relay/encoding.d.ts.map +1 -0
  325. package/dist/device-relay/hub-connection.d.ts +43 -0
  326. package/dist/device-relay/hub-connection.d.ts.map +1 -0
  327. package/dist/device-relay/hub-dispatch.d.ts +19 -0
  328. package/dist/device-relay/hub-dispatch.d.ts.map +1 -0
  329. package/dist/device-relay/hub-handshake.d.ts +20 -0
  330. package/dist/device-relay/hub-handshake.d.ts.map +1 -0
  331. package/dist/device-relay/hub-shared-streams.d.ts +24 -0
  332. package/dist/device-relay/hub-shared-streams.d.ts.map +1 -0
  333. package/dist/device-relay/hub-streams.d.ts +57 -0
  334. package/dist/device-relay/hub-streams.d.ts.map +1 -0
  335. package/dist/device-relay/hub.d.ts +117 -0
  336. package/dist/device-relay/hub.d.ts.map +1 -0
  337. package/dist/entrypoints/agent-executor/acp.d.ts +1 -1
  338. package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
  339. package/dist/entrypoints/agent-executor/acp.js +183 -29
  340. package/dist/entrypoints/agent-executor/claude-sdk.js +15 -15
  341. package/dist/entrypoints/agent-executor/claude.js +13 -15
  342. package/dist/entrypoints/agent-executor/codex.js +88 -48
  343. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +5 -5
  344. package/dist/entrypoints/agent-executor/testing.js +31 -30
  345. package/dist/entrypoints/agent-executor.d.ts +2 -2
  346. package/dist/entrypoints/agent-executor.d.ts.map +1 -1
  347. package/dist/entrypoints/agent-executor.js +23 -17
  348. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +9 -0
  349. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -0
  350. package/dist/entrypoints/agent-runtime/ai-sdk.js +821 -0
  351. package/dist/entrypoints/agent-runtime/anthropic.d.ts +4 -0
  352. package/dist/entrypoints/agent-runtime/anthropic.d.ts.map +1 -0
  353. package/dist/entrypoints/agent-runtime/anthropic.js +1260 -0
  354. package/dist/entrypoints/agent-runtime/browser.d.ts +4 -1
  355. package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
  356. package/dist/entrypoints/agent-runtime/browser.js +449 -50
  357. package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
  358. package/dist/entrypoints/agent-runtime/harness.js +24 -19
  359. package/dist/entrypoints/agent-runtime/openai.d.ts +4 -0
  360. package/dist/entrypoints/agent-runtime/openai.d.ts.map +1 -0
  361. package/dist/entrypoints/agent-runtime/openai.js +1246 -0
  362. package/dist/entrypoints/agent-runtime/openrouter.d.ts +5 -2
  363. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
  364. package/dist/entrypoints/agent-runtime/openrouter.js +2355 -371
  365. package/dist/entrypoints/agent-runtime/postgres.js +12 -10
  366. package/dist/entrypoints/agent-runtime/realtime.js +11 -10
  367. package/dist/entrypoints/agent-runtime/sandbox.d.ts +3 -0
  368. package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -1
  369. package/dist/entrypoints/agent-runtime/sandbox.js +530 -7
  370. package/dist/entrypoints/agent-runtime/sqlite/bun.js +13 -11
  371. package/dist/entrypoints/agent-runtime/sqlite/node.js +13 -11
  372. package/dist/entrypoints/agent-runtime/testing.d.ts +1 -1
  373. package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
  374. package/dist/entrypoints/agent-runtime/testing.js +56 -15
  375. package/dist/entrypoints/agent-runtime.d.ts +14 -6
  376. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  377. package/dist/entrypoints/agent-runtime.js +1412 -115
  378. package/dist/entrypoints/application/diagnostic-journal.js +6 -6
  379. package/dist/entrypoints/application/directory-inbox.js +6 -6
  380. package/dist/entrypoints/application/opentelemetry.js +3 -3
  381. package/dist/entrypoints/application.js +17 -17
  382. package/dist/entrypoints/cli/publish.js +8 -8
  383. package/dist/entrypoints/cli.js +14 -15
  384. package/dist/entrypoints/contract.d.ts +1 -0
  385. package/dist/entrypoints/contract.d.ts.map +1 -1
  386. package/dist/entrypoints/contract.js +13 -9
  387. package/dist/entrypoints/device-relay.d.ts +10 -0
  388. package/dist/entrypoints/device-relay.d.ts.map +1 -0
  389. package/dist/entrypoints/device-relay.js +2517 -0
  390. package/dist/entrypoints/files/packaging.js +3 -3
  391. package/dist/entrypoints/files.js +11 -11
  392. package/dist/entrypoints/geo.js +5 -5
  393. package/dist/entrypoints/google.js +1 -1
  394. package/dist/entrypoints/handler.js +6 -6
  395. package/dist/entrypoints/http.js +9 -9
  396. package/dist/entrypoints/index.js +21 -17
  397. package/dist/entrypoints/live.js +4 -4
  398. package/dist/entrypoints/node.js +13 -13
  399. package/dist/entrypoints/observability.js +9 -9
  400. package/dist/entrypoints/process/bootstrap.js +1 -1
  401. package/dist/entrypoints/process.js +5 -5
  402. package/dist/entrypoints/react.js +4 -4
  403. package/dist/entrypoints/realtime.d.ts +3 -0
  404. package/dist/entrypoints/realtime.d.ts.map +1 -1
  405. package/dist/entrypoints/realtime.js +413 -4
  406. package/dist/entrypoints/release.js +1 -1
  407. package/dist/entrypoints/remote.js +10 -10
  408. package/dist/entrypoints/server.d.ts +1 -0
  409. package/dist/entrypoints/server.d.ts.map +1 -1
  410. package/dist/entrypoints/server.js +546 -40
  411. package/dist/entrypoints/service-host/macos.js +10 -10
  412. package/dist/entrypoints/service-host/work.js +7 -7
  413. package/dist/entrypoints/service-host.js +15 -15
  414. package/dist/entrypoints/spend.js +3 -3
  415. package/dist/entrypoints/sync.js +4 -4
  416. package/dist/entrypoints/telegram/screens.js +6 -6
  417. package/dist/entrypoints/telegram.js +20 -20
  418. package/dist/entrypoints/testing.js +14 -14
  419. package/dist/entrypoints/tools/agent.d.ts +2 -1
  420. package/dist/entrypoints/tools/agent.d.ts.map +1 -1
  421. package/dist/entrypoints/tools/agent.js +8 -7
  422. package/dist/entrypoints/tools/connections.js +5 -5
  423. package/dist/entrypoints/tools/invoker.js +3 -4
  424. package/dist/entrypoints/tools/mcp.js +8 -9
  425. package/dist/entrypoints/tools/toolkit.js +32 -13
  426. package/dist/entrypoints/tools.d.ts +3 -1
  427. package/dist/entrypoints/tools.d.ts.map +1 -1
  428. package/dist/entrypoints/tools.js +37 -35
  429. package/dist/entrypoints/tracking/contract.js +1 -1
  430. package/dist/entrypoints/tracking/performance.js +4 -4
  431. package/dist/entrypoints/tracking.js +3 -3
  432. package/dist/{index-09f7w2qq.js → index-02kdtrcd.js} +1 -1
  433. package/dist/{index-y53cqwke.js → index-033tyx59.js} +1 -1
  434. package/dist/{index-9ft4n9j1.js → index-05b65gj4.js} +2 -2
  435. package/dist/{index-d04w81fz.js → index-0sxj3y45.js} +1 -1
  436. package/dist/{index-dm6nxkn1.js → index-18pf56dq.js} +4 -6
  437. package/dist/index-1gmgwfn3.js +439 -0
  438. package/dist/index-23wn8sgf.js +47 -0
  439. package/dist/{index-tqjamnax.js → index-27srek2g.js} +15 -13
  440. package/dist/{index-2nwvn7m2.js → index-29v1p1f4.js} +2 -2
  441. package/dist/index-36dmtzjr.js +194 -0
  442. package/dist/{index-ycr4pk0z.js → index-42n9jycn.js} +3 -3
  443. package/dist/{index-ke02kxsr.js → index-43k180c2.js} +1 -1
  444. package/dist/{index-pbekeqzm.js → index-5c4m8zdf.js} +2 -2
  445. package/dist/{index-qggqqja2.js → index-5dxgx3yj.js} +1 -1
  446. package/dist/{index-x5ayy5bn.js → index-5gdexvke.js} +3 -1
  447. package/dist/{index-t1a2jrg7.js → index-5xsxvk2x.js} +1 -1
  448. package/dist/{index-mbd92r1w.js → index-654rhe5d.js} +1 -1
  449. package/dist/{index-2dzc7mv9.js → index-67pnt4bh.js} +1 -1
  450. package/dist/index-6kpwkpgx.js +415 -0
  451. package/dist/{index-s43tr4my.js → index-6kwdfb9m.js} +18 -3
  452. package/dist/{index-1qwd54n3.js → index-6nzzj7qr.js} +1 -1
  453. package/dist/{index-rkjfzs0a.js → index-6p5pshcd.js} +2 -2
  454. package/dist/{index-118aebbg.js → index-6t4c98gr.js} +1 -1
  455. package/dist/{index-pws5c3x6.js → index-6xw1wf4m.js} +51 -32
  456. package/dist/{index-kwsr7j5k.js → index-6yb4stq3.js} +1 -1
  457. package/dist/{index-8jf4bt7v.js → index-76yhxa41.js} +8 -8
  458. package/dist/{index-7416mhyh.js → index-79vqbjcz.js} +1 -1
  459. package/dist/{index-13wmzpa6.js → index-7an2fs5h.js} +1 -1
  460. package/dist/index-7qza24g1.js +14 -0
  461. package/dist/{index-gtaaxe9d.js → index-8cek82ar.js} +1 -1
  462. package/dist/index-9f60gnfn.js +393 -0
  463. package/dist/{index-stpy56r3.js → index-aacwkve4.js} +209 -10
  464. package/dist/{index-rpyn7geq.js → index-ac3rfec5.js} +2 -2
  465. package/dist/{index-d2drhb9c.js → index-b0mh2t9x.js} +2 -2
  466. package/dist/index-b23s6e2c.js +158 -0
  467. package/dist/{index-an7vcmwf.js → index-bvpevwt6.js} +5 -5
  468. package/dist/{index-msxf2r8x.js → index-by8w2461.js} +1 -1
  469. package/dist/{index-8t9dr41h.js → index-c0yym4a0.js} +4 -4
  470. package/dist/{index-wddcfbng.js → index-c7fj4yw9.js} +1 -1
  471. package/dist/{index-tf70nm22.js → index-cb4nnvfr.js} +8 -6
  472. package/dist/{index-205456mf.js → index-d3s070eh.js} +2 -2
  473. package/dist/{index-apf5g7y9.js → index-dz6tstcp.js} +2 -2
  474. package/dist/{index-agy5fqgf.js → index-e1y74yra.js} +15 -8
  475. package/dist/index-edtg4tak.js +55 -0
  476. package/dist/{index-pq6g1k9t.js → index-ek9w11r0.js} +2 -2
  477. package/dist/{index-x46y9z26.js → index-epyj7ptp.js} +7 -5
  478. package/dist/{index-6kmjcm81.js → index-er483f3w.js} +93 -4
  479. package/dist/{index-827bgv33.js → index-f16b7rze.js} +1 -1
  480. package/dist/{index-gbhj370g.js → index-fec05c9k.js} +21 -21
  481. package/dist/{index-9wdrwx3b.js → index-fjac2w5e.js} +20 -22
  482. package/dist/{index-6918kxbf.js → index-fthw8dwa.js} +1 -0
  483. package/dist/{index-2mz8hj58.js → index-g04hszcm.js} +1 -1
  484. package/dist/{index-rw8ze745.js → index-ga6avd48.js} +1 -1
  485. package/dist/{index-paff5y0r.js → index-grhhsrd5.js} +9 -7
  486. package/dist/{index-mxt0wfjy.js → index-h20qcyh5.js} +5 -2
  487. package/dist/index-j3r7r1mh.js +150 -0
  488. package/dist/{index-vgytj9wp.js → index-jmaw365j.js} +1 -1
  489. package/dist/{index-cjytermm.js → index-jzdbkanz.js} +3 -3
  490. package/dist/index-k137ezb6.js +79 -0
  491. package/dist/{index-tazm4dxf.js → index-kdw0n92g.js} +1 -1
  492. package/dist/{index-wh70tmpd.js → index-ke6jtxkd.js} +1 -1
  493. package/dist/index-kgj8j7bv.js +83 -0
  494. package/dist/{index-9kpxz49v.js → index-kgkevngs.js} +1 -1
  495. package/dist/{index-hab790s6.js → index-kp1j7cc8.js} +4 -4
  496. package/dist/{index-jcge9tx3.js → index-krekhmp7.js} +142 -123
  497. package/dist/{index-3y2tzhr8.js → index-ky79wwgs.js} +4 -4
  498. package/dist/{index-39rmc00v.js → index-mfe9a266.js} +1 -1
  499. package/dist/{index-qpzyahe3.js → index-mgr0mdqp.js} +5 -2
  500. package/dist/{index-n20tybgk.js → index-mh3jdb25.js} +2 -2
  501. package/dist/{index-g5fgeb6v.js → index-mkmep637.js} +1 -1
  502. package/dist/{index-02r5sq9p.js → index-mrng24wq.js} +19 -21
  503. package/dist/index-mx2gya05.js +465 -0
  504. package/dist/{index-8yt3rwe7.js → index-n2t87ggz.js} +5 -5
  505. package/dist/index-nfeafbzh.js +7379 -0
  506. package/dist/{index-j0ef04jw.js → index-nfm15ej7.js} +4 -4
  507. package/dist/index-pd9e8rz4.js +193 -0
  508. package/dist/{index-zwgwyvdt.js → index-pdcbjd6a.js} +1 -1
  509. package/dist/{index-q427q23r.js → index-pjjh91vw.js} +2 -2
  510. package/dist/{index-gnjgkecx.js → index-q46b16xz.js} +1 -1
  511. package/dist/{index-9xr44d2g.js → index-qv5v6w9c.js} +330 -106
  512. package/dist/{index-tmv3ez1h.js → index-qymek778.js} +69 -12
  513. package/dist/{index-yrr3n391.js → index-ry8m2mhg.js} +2 -2
  514. package/dist/{index-93n6jwy0.js → index-s0n0nnz5.js} +3 -3
  515. package/dist/{index-1p8q0yrt.js → index-t5zp1jjj.js} +5 -7
  516. package/dist/{index-2rf33y2h.js → index-tav72wz5.js} +4 -2
  517. package/dist/{index-jpecjm30.js → index-tgehj4bp.js} +1 -1
  518. package/dist/{index-ma26mfnt.js → index-v5hmyef8.js} +1 -1
  519. package/dist/index-vebzvse6.js +230 -0
  520. package/dist/index-vv0hxrmy.js +295 -0
  521. package/dist/index-vxm0ya3f.js +707 -0
  522. package/dist/{index-t3qcac2a.js → index-w3s79kcb.js} +1 -1
  523. package/dist/{index-r97ppg0g.js → index-x1r7kxzd.js} +1 -1
  524. package/dist/{index-kynwa08q.js → index-xrsryvd2.js} +2 -2
  525. package/dist/{index-3mcbr8sx.js → index-xtxxt87z.js} +1 -1
  526. package/dist/index-zk839vzf.js +231 -0
  527. package/dist/{index-9c76vfxf.js → index-zyyerdny.js} +4 -4
  528. package/dist/internal/base64.d.ts +9 -0
  529. package/dist/internal/base64.d.ts.map +1 -0
  530. package/dist/internal/deadline-budget.d.ts +57 -0
  531. package/dist/internal/deadline-budget.d.ts.map +1 -0
  532. package/dist/internal/deadline.d.ts.map +1 -1
  533. package/dist/internal/timers.d.ts +2 -0
  534. package/dist/internal/timers.d.ts.map +1 -1
  535. package/dist/realtime/device-presence-contract.d.ts +194 -0
  536. package/dist/realtime/device-presence-contract.d.ts.map +1 -0
  537. package/dist/server/context-contribution.d.ts.map +1 -1
  538. package/dist/server/contract-method.d.ts.map +1 -1
  539. package/dist/server/device-presence-handlers.d.ts +54 -0
  540. package/dist/server/device-presence-handlers.d.ts.map +1 -0
  541. package/dist/server/device-presence-registry.d.ts +35 -0
  542. package/dist/server/device-presence-registry.d.ts.map +1 -0
  543. package/dist/server/device-presence.d.ts +45 -0
  544. package/dist/server/device-presence.d.ts.map +1 -0
  545. package/dist/server/endpoint-dispatch.d.ts.map +1 -1
  546. package/dist/server/middleware/cors.d.ts +3 -1
  547. package/dist/server/middleware/cors.d.ts.map +1 -1
  548. package/dist/server/types.d.ts +4 -11
  549. package/dist/server/types.d.ts.map +1 -1
  550. package/dist/service-host/systemd-render-shared.d.ts.map +1 -1
  551. package/dist/tools/agent-messages.d.ts +6 -0
  552. package/dist/tools/agent-messages.d.ts.map +1 -0
  553. package/dist/tools/agent-tool-error.d.ts +2 -2
  554. package/dist/tools/agent-tools.d.ts +153 -0
  555. package/dist/tools/agent-tools.d.ts.map +1 -0
  556. package/dist/tools/agent.d.ts +6 -56
  557. package/dist/tools/agent.d.ts.map +1 -1
  558. package/dist/tools/runtime-tool.d.ts +3 -4
  559. package/dist/tools/runtime-tool.d.ts.map +1 -1
  560. package/dist/tools/toolkit.d.ts +3 -1
  561. package/dist/tools/toolkit.d.ts.map +1 -1
  562. package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -1
  563. package/llms/agent-executor-acp.txt +2 -2
  564. package/llms/agent-executor-codex.txt +1 -1
  565. package/llms/agent-executor.txt +7 -3
  566. package/llms/agent-runtime-ai-sdk.txt +26 -0
  567. package/llms/agent-runtime-anthropic.txt +33 -0
  568. package/llms/agent-runtime-browser.txt +22 -8
  569. package/llms/agent-runtime-harness.txt +2 -2
  570. package/llms/agent-runtime-openai.txt +31 -0
  571. package/llms/agent-runtime-openrouter.txt +17 -7
  572. package/llms/agent-runtime-sandbox.txt +53 -1
  573. package/llms/agent-runtime-testing.txt +4 -2
  574. package/llms/agent-runtime.2.txt +158 -271
  575. package/llms/agent-runtime.3.txt +289 -243
  576. package/llms/agent-runtime.4.txt +273 -216
  577. package/llms/agent-runtime.5.txt +209 -2
  578. package/llms/agent-runtime.txt +238 -181
  579. package/llms/contract.txt +2 -1
  580. package/llms/device-relay.txt +34 -0
  581. package/llms/realtime.txt +20 -0
  582. package/llms/server.2.txt +125 -1
  583. package/llms/server.3.txt +111 -122
  584. package/llms/server.4.txt +1 -1
  585. package/llms/server.5.txt +3 -1
  586. package/llms/server.txt +31 -1
  587. package/llms/spend.txt +11 -6
  588. package/llms/stitchkit.2.txt +21 -43
  589. package/llms/stitchkit.3.txt +43 -0
  590. package/llms/stitchkit.txt +93 -84
  591. package/llms/tools-agent.txt +7 -5
  592. package/llms/tools-toolkit.txt +1 -1
  593. package/llms/tools.4.txt +7 -2
  594. package/llms/{upgrading-0.128.0-0.133.0.txt → upgrading-0.128.0-0.134.0.txt} +173 -3
  595. package/llms/upgrading.txt +1 -1
  596. package/llms-full.txt +981 -210
  597. package/llms.txt +21 -17
  598. package/package.json +18 -7
  599. package/dist/index-0p0s5hrj.js +0 -249
  600. package/dist/index-1dn2wjq6.js +0 -135
  601. package/dist/index-1psbyyhj.js +0 -21
  602. package/dist/index-34k82crg.js +0 -3961
  603. package/dist/index-5n3a8hd8.js +0 -102
  604. package/dist/index-97rp94ff.js +0 -8
  605. package/dist/index-bn2baakz.js +0 -336
  606. package/dist/index-eh71zr32.js +0 -14
  607. package/dist/index-emgrmavr.js +0 -1193
  608. package/dist/index-fzd477xk.js +0 -135
  609. package/dist/index-vgzhw2zk.js +0 -304
  610. package/dist/internal/ai-sdk-typed.d.ts +0 -14
  611. package/dist/internal/ai-sdk-typed.d.ts.map +0 -1
  612. package/dist/tools/runtime-call-context.d.ts +0 -15
  613. package/dist/tools/runtime-call-context.d.ts.map +0 -1
  614. package/dist/{index-vmbxj75t.js → index-jwtmw39p.js} +0 -0
  615. package/dist/{index-877e9y8r.js → index-sk03xe0n.js} +3 -3
  616. package/dist/{index-21cfxc4z.js → index-vh4291qh.js} +3 -3
@@ -8,8 +8,237 @@ Parts of this slice:
8
8
  - `llms/agent-runtime.txt`: Guide: Agent application runtime (docs/guide/agent-runtime.md)
9
9
  - `llms/agent-runtime.2.txt`: Guide: Agent application runtime (docs/guide/agent-runtime.md)
10
10
  - `llms/agent-runtime.3.txt`: Guide: Agent application runtime (docs/guide/agent-runtime.md)
11
- - `llms/agent-runtime.4.txt`: API reference: `stitchkit/agent-runtime` (docs/api/reference.md)
12
- - `llms/agent-runtime.5.txt`: API reference: `stitchkit-tui` (docs/api/reference.md)
11
+ - `llms/agent-runtime.4.txt`: Guide: Agent application runtime (docs/guide/agent-runtime.md) · API reference: `stitchkit/agent-runtime` (docs/api/reference.md)
12
+ - `llms/agent-runtime.5.txt`: API reference: `stitchkit/agent-runtime` (docs/api/reference.md) · API reference: `stitchkit-tui` (docs/api/reference.md)
13
+
14
+ ==============================================================================
15
+ # Guide: Agent application runtime (docs/guide/agent-runtime.md) (continued)
16
+ ==============================================================================
17
+
18
+ ## Observability
19
+
20
+ `createAgentObservability` emits a separate operator-only `AgentRunEvent`. It
21
+ reuses the same bounded sink lifecycle as request/tool observability without
22
+ sending new event kinds to existing request sinks. Product events omit provider
23
+ causes. Operator `internalCause` is also redacted by default; an operator-only sink must explicitly
24
+ set `includeInternalCause` and own its retention policy.
25
+
26
+ ### What a run says it spent
27
+
28
+ Usage values carry `provider-reported`, `computed`, `estimated` or `unavailable`
29
+ provenance, **per field**. Cost additionally carries an ISO currency code;
30
+ OpenRouter-reported cost is normalized as USD.
31
+
32
+ Read the provenance before the number (→ ADR 0109):
33
+
34
+ - **`provider-reported`** — the provider handed us exactly this. On
35
+ `step-finished`, that is what a step's figures are.
36
+ - **`computed`** — a total, added up over steps. **Every figure on a terminal
37
+ event is this**, tokens included: the run sums step usage across steps rather
38
+ than reporting one provider-stated total for the whole run. It is not a figure
39
+ to bill against unchanged.
40
+ - **`unavailable`** — nobody reported it. Not zero.
41
+
42
+ Two rules follow from that last one, and they differ by field on purpose:
43
+
44
+ - **A token total with an unreported step is a floor**, labelled `computed`. A
45
+ token count is a diagnostic, and a floor is a useful one.
46
+ - **A cost with an unreported step is `unavailable`, not a floor.** Money is what
47
+ people bill against, and "at least $1.00" reported as `$1.00` is the same class
48
+ of lie this whole section exists to remove. One step that did not report its
49
+ cost makes the run's cost unknown — not smaller. It also stays unknown: later
50
+ steps reporting normally cannot revive it.
51
+
52
+ **A terminal event always carries `usage`.** A run that ended before the provider
53
+ reported anything — superseded, interrupted, timed out, shut down, failed —
54
+ carries every field `unavailable`. That is deliberately different from a run that
55
+ spent nothing, and an omitted object could not tell you which one you had.
56
+
57
+ Two costs in different currencies do not add: the sum reports `unavailable`
58
+ rather than picking a label. The core records a currency and never converts one.
59
+
60
+ `step-finished.response` identifies the provider response for that one step. The terminal event
61
+ does not copy the last response: response identity remains per-step, while every terminal usage
62
+ figure remains a `computed` aggregate.
63
+
64
+ **A run's figure is durable, and that is where to read it when a channel loses
65
+ it.** `AgentRun.usage` is written at every checkpoint and again with the terminal
66
+ record, so a crashed process leaves behind what it had already spent and a
67
+ dropped event is not a lost number:
68
+
69
+ ```ts
70
+ const snapshot = await store.loadSnapshot(conversationId)
71
+ const spent = snapshot.runs.find((run) => run.id === runId)?.usage
72
+ ```
73
+
74
+ Two gaps are open and are stated rather than left to be discovered:
75
+
76
+ - **Both event sinks are bounded and drop under load**, by arrival order — the
77
+ event carrying the money is exactly as droppable as the one carrying nothing.
78
+ The run record is the recovery, and this paragraph is the only place that says
79
+ so.
80
+ - **`AgentRuntimeResult.metrics` is `undefined` when this executor did not win
81
+ the terminal race.** Read `result.run.usage` — the durable figure — rather than
82
+ `result.metrics`, which is the channel that can go missing.
83
+ - **Compaction spend is invisible unless you report it.** `config.history.compact`
84
+ calls a model inside the turn and produces no step and no event of its own.
85
+ Return `usage` from `AgentCompactionResult` and it joins the run's figure;
86
+ omit it and the run under-reports by whatever summarising cost.
87
+
88
+ What stitchkit does **not** keep is a ledger: one figure, on the run that
89
+ produced it, never aggregated and never reconciled against a provider invoice
90
+ (→ ADR 0110).
91
+
92
+ ### Reconciling with the provider's own accounting
93
+
94
+ Whether a provider bills for a call that was aborted mid-flight cannot be known
95
+ inside the process: the authoritative number arrives later, from the provider's
96
+ accounting. **stitchkit does not accept it back** (→ ADR 0110) — a terminal run
97
+ is an absorbing state, and a write that reached it through the conversation
98
+ aggregate could conflict a concurrent compaction into discarding a summary it had
99
+ just paid a model to produce.
100
+
101
+ The join is yours, and `runId` is the key:
102
+
103
+ ```ts
104
+ // when the run terminates — write what the runtime observed
105
+ await ledger.record({
106
+ runId: terminal.run.id,
107
+ conversationId: terminal.run.conversationId,
108
+ // The durable figure, not `terminal.metrics` — that one is absent whenever
109
+ // this executor did not win the terminal race.
110
+ costUsd: terminal.run.usage?.cost?.value ?? null, // null when `unavailable`
111
+ provenance: terminal.run.usage?.cost?.provenance ?? 'unavailable',
112
+ })
113
+
114
+ // later — the provider's accounting names the same generation
115
+ await ledger.reconcile({ runId, costUsd: billed, provenance: 'provider-reported' })
116
+ ```
117
+
118
+ Record the row even when the figure is `unavailable`: that row is the evidence
119
+ that a run happened and cost something nobody has counted yet, and it is what the
120
+ provider's later figure attaches to. A run with no row is a run you cannot
121
+ reconcile.
122
+
123
+ The sink deduplicates stable event IDs by default. Cross-crash exactly-once still requires a durable
124
+ outbox.
125
+
126
+ ## Deterministic race and adapter proof
127
+
128
+ `stitchkit/agent-runtime/testing` exports `createAgentRaceBarrier`, `createAgentRaceDriver`,
129
+ `createAgentRaceTrace` and `runAgentStoreConformance` — agent testing tools live beside the agent
130
+ runtime, and `stitchkit/testing` imports none of it. Barriers have bounded teardown, traces assert exact partial order, and the
131
+ helpers are exercised from packed Bun and Node consumers. `runAgentStoreConformance` runs duplicate,
132
+ coalescing, collision, stale checkpoint, replay safety, terminal race, absorption, bounded reads,
133
+ causal queued-history order, durable interrupt priority, compaction and recovery invariants against
134
+ any fresh durable adapter.
135
+
136
+ It picks its conversation identities itself and passes them to `createStore(context)` **before the
137
+ first mutation**, so an adapter whose runtime rows reference an application-owned conversation row
138
+ can provision those parents; the optional `cleanup(context)` removes them again, and runs once
139
+ whether the scenario passed or failed. A factory that owns no fixture state ignores the argument and
140
+ keeps working unchanged.
141
+
142
+ ## Plain completions and shared invocation receipts
143
+
144
+ Use `createModelInvocationLedger` from `stitchkit/agent-runtime` when a direct text
145
+ completion and an agent must share causal provider evidence. It uses the existing
146
+ runtime store, not a second database. The completion path sends exactly one user
147
+ prompt, no framework instructions and no tools. It never starts an agent loop.
148
+
149
+ ```ts
150
+ import { createModelInvocationLedger } from 'stitchkit/agent-runtime';
151
+
152
+ const invocations = createModelInvocationLedger({
153
+ store, // the same AgentRuntimeStore object passed to createAgentRuntime
154
+ models, // an existing defineModelRegistry result
155
+ payloadKey, // 32 bytes from the host's secret store; retain separately from archives
156
+ authorize: async ({ context, conversationId, action, trace }) => {
157
+ const session = await authenticate(context);
158
+ await authorizeConversation(session, conversationId, action, trace);
159
+ return { subject: session.subject }; // verified identity, never a body field
160
+ },
161
+ });
162
+
163
+ const completion = await invocations.complete({
164
+ conversationId: 'evaluation-42',
165
+ idempotencyKey: 'summary-case-3',
166
+ trace: {
167
+ operationId: 'summary-42', purpose: 'summarize', project: 'example',
168
+ parent: { traceId: 'trace-42' }, experiment: 'evaluation', case: 'case-3',
169
+ },
170
+ prompt: 'Summarize these supplied facts.',
171
+ models: ['primary', 'fallback'], // registry keys; repeat a key for an explicit retry
172
+ settings: { maxOutputTokens: 500 },
173
+ timeoutMs: 30_000,
174
+ }, authenticatedContext);
175
+
176
+ // Add to the existing createAgentRuntime configuration:
177
+ const receiptConfig = {
178
+ ledger: invocations,
179
+ trace: ({ run }) => ({
180
+ operationId: run.id, purpose: 'assistant-turn', project: 'example',
181
+ }),
182
+ };
183
+ // createAgentRuntime({ ...existingConfig, invocations: receiptConfig });
184
+
185
+ const page = await invocations.read({
186
+ conversationId: 'evaluation-42', limit: 100,
187
+ }, authenticatedContext);
188
+ // Continue with fromSeq: page.nextSeq while it is defined.
189
+ ```
190
+
191
+ `complete` returns `invocationId`, `outcome` and, on success, `text`. `duplicate`
192
+ returns the existing ID without provider execution or replaying plaintext. Changed
193
+ input, trace or caller under the same key is a conflict. Model attempts are explicit
194
+ and bounded to eight; SDK retries are disabled. Only provider failures trigger the
195
+ next attempt. Abort, audit refusal and configuration errors do not. An admitted call
196
+ whose process died stays claimed: inspect the receipt before choosing a new key.
197
+
198
+ The agent retains its existing prompt, tools and loop. Both modes produce
199
+ `invocation/started`, `provider/request`, `provider/response` and
200
+ `invocation/finished` records through `read`. Each attempt has its own ID; response
201
+ usage is counted once and keeps `unavailable` distinct from measured zero. Requested
202
+ registry selection, sent adapter identity and effective provider identity are
203
+ separate. Effective identity is null when not reported. A gateway's hidden retries
204
+ are not visible as additional attempts.
205
+
206
+ `currentModelInvocationAttempt()` returns the causal context inside a provider's
207
+ `fetch` callback or streamed read. Use it to join a host transport audit to
208
+ `operationId`, `invocationId`, `attemptId`, optional `runId` and `step`.
209
+ `onAttempt` is an awaited admission hook; a rejected hook prevents the provider call.
210
+ SDK payload hashes are not represented as hashes of HTTP wire bytes.
211
+
212
+ Prompts and output are AES-256-GCM payload artifacts. `read` returns references and
213
+ hashes; `readPayload({ conversationId, artifactId }, context)` separately authorizes
214
+ `read-payload` and checks authentication tags and hashes. `payloadKey` must be 32
215
+ bytes and is copied at construction. Keep it outside the event store/backups; retain
216
+ the appropriate key when restoring an archive. `maxPayloadBytes` defaults to 4 MiB
217
+ (range 1 KiB–64 MiB). Streaming output evidence keeps parts up to half of it; past
218
+ that the evidence carries `truncated: { parts, sha256 }` over the whole stream, and
219
+ the answer itself is never cut. A receipt that cannot be written never changes an
220
+ outcome: `complete()` returns it with `receiptError` beside it, and a succeeded
221
+ answer keeps its `text`. Request headers
222
+ are excluded. Protect existing agent history independently: enabling receipts does
223
+ not encrypt its ordinary conversation records.
224
+
225
+ The built-in memory and SQLite stores implement `appendEventOnce`. Custom stores
226
+ must implement its once-only check and append atomically, returning the original
227
+ event on a duplicate key scoped by conversation and kind. A factory without this
228
+ capability refuses receipt setup. The driver-backed implementation finds the keyed
229
+ event by its identity through the driver's `events.find` — one index probe
230
+ in SQLite — so admission costs the same on a long conversation as on a new one.
231
+ `store.findEventOnce({ conversationId, kind, key })` reads the same event back.
232
+ Invocation payload artifacts are keyed by their artifact id the same way.
233
+
234
+ ### Migration from direct provider completions
235
+
236
+ **Who must act:** applications opting into shared completion/agent receipts.
237
+ Replace direct unlogged model calls with `invocations.complete` (or `completeText` /
238
+ `completeObject` when no durable receipt ledger is needed), configure host
239
+ authorization and a retained payload key, and pass the same ledger in the agent's
240
+ `invocations` option. Use the returned invocation ID and the paginated `read` method
241
+ for receipt queries; do not import runtime internals.
13
242
 
14
243
  ==============================================================================
15
244
  # API reference: `stitchkit/agent-runtime` (docs/api/reference.md)
@@ -17,20 +246,22 @@ Parts of this slice:
17
246
 
18
247
  ## `stitchkit/agent-runtime`
19
248
 
20
- Server-only optional application runtime. See the
249
+ Server-only, peer-free optional application runtime. Runs models exclusively through `AgentModelDriver` (one provider call per step) with no AI SDK dependency. See the
21
250
  [agent runtime guide](../guide/agent-runtime.md).
22
251
 
23
252
  | Export | Kind | Summary |
24
253
  |--------|------|---------|
25
- | `createAgentRuntime` | function | compose durable acceptance, stream loop, checkpoints, coordination, managed tools and winner-only terminal publication; reconciles same-owner terminal/interrupt/head CAS races before releasing the lane |
26
- | `createDeferredAgentToolSurface` | function | bounded canonical catalog search plus durable same-run activation of direct `mountAgent` tools; supports one immutable surface or a finite identity-specific registry |
254
+ | `createAgentRuntime` | function | compose durable acceptance, native `AgentModelDriver` step loop, tool parsing/validation, WebCrypto HMAC-SHA256 tool approvals, `beforeStepToolCalls`, bounded terminal continuations (`maxContinuations`), `onAttemptDiscarded`, `onToolInputStart`, checkpoints, coordination, managed tools and winner-only terminal publication; reconciles same-owner terminal/interrupt/head CAS races before releasing the lane |
255
+ | `createDeferredAgentToolSurface` | function | bounded canonical catalog search plus durable same-run activation of direct `mountAgentTools` tools; supports one immutable surface or a finite identity-specific registry |
27
256
  | `DeferredAgentToolSearchInputSchema` / `DeferredAgentToolMatchSchema` / `DeferredAgentToolReceiptSchema` | schema | bounded search input, public match and versioned durable selection receipt |
28
257
  | `DeferredAgentToolSurfaceConfig` / `DeferredAgentToolCommonConfig` / `DeferredAgentToolSurfaceDefinition` / `DeferredAgentToolController` | _type_ | finite catalogs, selector, pin, budget and `mount`/`prepareStep` composition contracts |
29
258
  | `DeferredAgentRuntimeToolDefinition` / `DeferredAgentToolMountConfig` | _type_ | peer-free Agent-only runtime definition and canonical mount configuration accepted by the controller |
30
259
  | `DeferredAgentToolManifestEntry` / `DeferredAgentToolSearchContext` / `DeferredAgentToolReceipt` | _type_ | canonical selector input and inferred durable receipt records |
31
260
  | `DeferredAgentToolEvent` | _type_ | PII-free search/step evidence with surface, provenance, counts, canonical schema bytes and ceilings |
32
- | `defineAgentProtocol` | function | declare context, input metadata, canonical parts and optional pre-CAS terminal acceptance (`allow-empty`, `require-output` or callback) |
261
+ | `defineAgentProtocol` | function | declare context, input metadata, canonical parts and optional pre-CAS terminal acceptance (`allow-empty`, `require-output` or callback returning `AgentTerminalAcceptanceDecision`) |
33
262
  | `hasAgentTerminalOutput` | function | generic `require-output` predicate for non-blank text, generated files, structured provider parts and explicit tool-only policy stops |
263
+ | `carriedToolWork` | function | pure helper returning whether any completed `AgentStepResult` performed client or provider tool work |
264
+ | `AgentTerminalAcceptanceDecision` | _type_ | `boolean \| { action: 'accept' } \| { action: 'reject' } \| { action: 'continue', message, instructions? }` returned by `protocol.acceptTerminal` for bounded continuations (capped by `loop.maxContinuations`, default 3) |
34
265
  | `AgentMessageSchema` / `AgentRunSchema` / `AgentSnapshotSchema` | schema | versioned canonical engine records |
35
266
  | `AgentRunQueuePrioritySchema` | schema | durable opt-in priority for queued `interrupt-next` runs |
36
267
  | `AgentRuntimeStore` | _type_ | aggregate CAS transaction boundary for message, run and compaction mutations |
@@ -55,8 +286,8 @@ Server-only optional application runtime. See the
55
286
  | `AgentConversationPurgeResultSchema` / `AgentConversationPurgeResult` | schema / _type_ | typed deletion/refusal outcomes; active refusal includes run IDs |
56
287
  | `AgentConversationPurgedError` | class | runtime mutation rejected because its conversation ID is permanently purged |
57
288
  | `AgentConversationPurgeDriver` | _type_ | optional `driver.conversations` capability: serialized tombstone read and atomic removal of all owned records |
58
- | `projectAgentHistory` | function | asynchronously project canonical records and resolved multimodal files into provider-valid AI SDK messages |
59
- | `defineModelRegistry` | function | typed language-model descriptors, capabilities and provider construction |
289
+ | `projectAgentHistory` | function | asynchronously project canonical records and resolved multimodal files into provider-valid peer-free `AgentModelMessage[]` |
290
+ | `defineModelRegistry` | function | typed language-model descriptors, capabilities and `AgentModelDriverFactory` construction |
60
291
  | `AgentModelCatalogSchema` / `AgentModelCatalog` | schema / _type_ | provider-neutral complete/partial model catalog with separately sourced popularity, metrics, prices and observation time |
61
292
  | `AgentModelCatalogEntrySchema` / `AgentModelCatalogEntry` | schema / _type_ | one canonical provider model descriptor with optional price, popularity and metric evidence |
62
293
  | `AgentModelPriceSchema` / `AgentModelPrice` | schema / _type_ | normalized per-token input/output pricing and source currency |
@@ -82,7 +313,7 @@ Server-only optional application runtime. See the
82
313
  | `selectCompactableHistory` | function | which oldest whole complete turns may be summarised away — the half of compaction that needs no store (→ ADR 0142) |
83
314
  | `SelectCompactableHistoryOptions` / `CompactableHistory` | _type_ | message list, retained-turn count and evidence policy in; `leadingSummary`, `compactable` and `retained` out |
84
315
  | `createAgentSessionCoordinator` | function | strict process-local queue/interrupt/supersede lifecycle |
85
- | `AgentRuntimeStopPolicy` | _type_ | named stop rule persisted and published on policy stop; `when` receives the AI SDK `steps` plus the run context `prepareStep` gets (`context`, `run`, `signal`, `toolFenceLifecycle`, `contextUsage`) |
316
+ | `AgentRuntimeStopPolicy` | _type_ | named stop rule `AgentRuntimeStopPolicy<CONTEXT = unknown>` persisted and published on policy stop; `when` receives `AgentStepResult[]` plus the run context `prepareStep` gets (`context`, `run`, `signal`, `toolFenceLifecycle`, `contextUsage`) |
86
317
  | `AgentRuntimePrepareStep` | _type_ | per-run controlled step callback with typed domain context and managed run signal/fence |
87
318
  | `AgentContextOverflowError` | class | deliberate application budget refusal thrown from `loop.prepareStep`; terminalizes as `context_overflow` without classifying arbitrary error text |
88
319
  | `AgentRuntimeRecordIds` | _type_ | optional caller-provided input, run and assistant IDs for stable application records |
@@ -96,7 +327,7 @@ Server-only optional application runtime. See the
96
327
  | `AgentSessionCloseOptions` | _type_ | `gracePeriodMs` for natural settlement, then abort, then `forceTimeoutMs` for bounded settlement after it |
97
328
  | `AgentSessionCloseResult` | _type_ | what `close()` achieved: `settled`, or `timedOut` with `remaining` runs still in flight. Only omitting `forceTimeoutMs` guarantees nothing is in flight on return |
98
329
  | `AgentHistoryProjectionOptions` | _type_ | storage-neutral file resolver, explicit unresolved-file behavior, and how an interrupted turn reaches the model (`interruptedAssistant`) |
99
- | `createAgentToolFenceLifecycle` | function | pre-effect and post-effect run ownership fence for `mountAgent`; compose beside application idempotency for [durable operations](../guide/mcp-and-agents.md#durable-application-owned-execution) |
330
+ | `createAgentToolFenceLifecycle` | function | pre-effect and post-effect run ownership fence for `mountAgentTools` / `mountAgent`; compose beside application idempotency for [durable operations](../guide/mcp-and-agents.md#durable-application-owned-execution) |
100
331
  | `AgentRuntimeEventSchema` | schema | transient stream lifecycle plus post-commit admission/checkpoint/run-state/run-operation/terminal projections |
101
332
  | `AgentRunOperationKindSchema` / `AgentRunOperationPhaseSchema` / `AgentRunOperationSchema` / `AgentRunOperation` | schemas / _type_ | latest durable model-request or compaction phase with operation/step identity and original timestamps; request admission is awaited before provider invocation |
102
333
  | `RecordRunOperationSchema` / `RecordRunOperation` | schema / _type_ | owner/fencing/revision-checked mutation of `AgentRun.lastOperation` |
@@ -131,209 +362,35 @@ Server-only optional application runtime. See the
131
362
  | `AgentChildHandle` / `AgentChildManager` / `AgentChildManagerConfig` / `AgentChildRemainingBudget` / `createAgentChildManager` / `createAgentChildTools` / `AgentChildToolsConfig` / `AGENT_CHILD_TOOL_DESCRIPTORS` / `agentChildBudgetStopPolicy` | _types_ / functions / constant | host execution port, child lifecycle with required `remainingBudget` and `maxActiveChildren`, cascade (given to `createAgentRuntime` as `children`), messaging, Agent tools bound to the parent conversation of the run context `tools()` receives (plus their deeply frozen static catalog descriptors), and the child runtime's own budget stop policy — `recordStepUsage` at every step boundary, `policy_stop` as `child-budget` when spent |
132
363
  | `AgentCompanionHost` / `AgentCompanionScope` / `AgentSqlSession` / `AgentSqlTables` / `AgentSqlValue` | _types_ | the store's companion host — one store transaction with the purge check and the event append (`transaction(conversationId, work)`), a read transaction (`read(work)`), the companion tables — given by the SQLite and Postgres stores and taken by every companion |
133
364
  | `AgentToolDefinition` / `AgentToolDescriptor` | _types_ | peer-neutral executable shape returned by the bound agent-only tool factories and its non-executable static catalog descriptor shape (assignable to `SurfaceRuntimeToolDefinition` without an active run) |
134
- | `AgentProviderStreamCutError` | class | explicit retryable provider stream truncation evidence |
135
-
136
- ### Complete runtime inventory
137
-
138
- The entrypoint deliberately exports the schemas beside their inferred types so persistence and
139
- transport adapters validate the same records. Runtime composition types are `AgentRuntime`,
140
- `AgentRuntimeConfig`, `AgentRuntimeInput`, `AgentRuntimeProtocolInput`, `AgentRuntimeRunContext`,
141
- `AgentRuntimeResult`, `AgentRuntimeInterruptInput`, `AgentRuntimeAbandonInput`, `AgentRuntimeRecoveryInput`,
142
- `AgentRuntimeRecoveryDecision`, `AgentRuntimeRecoveryOutcome`, `AgentRuntimePublisher`,
143
- `AgentInputPolicy`, `AgentStopReason`, `AgentCoordinatedRun`, `AgentRunTicket`,
144
- `AgentSessionCoordinator`, `AgentCompactionContext`, `AgentCompactionResult` and
145
- `StructuredCompactionConfig`.
146
-
147
- A provider refusal is classified rather than phrased. `classifyProviderFailure` returns an
148
- `AgentProviderFailure` — an `AgentProviderFailureReason` (`insufficient-credits`, `rate-limited`,
149
- `model-unavailable`, `context-overflow`, `timeout`, `cancelled`, `unknown`), the provider's `status`
150
- when it supplied one, whether the same request is `retryable` unchanged, and the `evidence` the
151
- answer rests on: `status` is the provider stating its own answer, `message` is us reading its prose,
152
- and `none` is an honest refusal to guess. The sentence a user reads stays with the application —
153
- its tone and its decision about what to admit are not the core's to make. `isToolResultFailure`
154
- recognises a failure carried inside a *successful* tool result, in both the bare and the
155
- `{ value: … }` envelope. Both are plain functions and need no runtime. → ADR 0141
156
-
157
- `normalizeOpenRouterUsage` is the same normalisation `openRouterProvider`
158
- applies, exported so an application calling the SDK directly gets provenance-correct numbers
159
- without adopting the runtime. Pass each completed SDK step's usage, including `raw`.
160
- Token provenance comes from the original OpenRouter fields: missing fields remain
161
- `unavailable`, even when the SDK substitutes zero. Aggregate usage without `raw` cannot
162
- establish reported token counts. Explicit zero remains `provider-reported`; cost is never
163
- estimated from token prices.
164
-
165
- `AgentContextUsage` reaches every step through `AgentRuntimeRunContext.contextUsage`: how full the
166
- model's context is, as `usedTokens` (an `AgentUsageValue`, so it carries the provenance that says
167
- where the number came from) beside the model's declared `contextWindow`. It is the **last completed
168
- step's prompt size**, not the run's cumulative input tokens — cumulative counts every step's prompt
169
- again and is a multiple of the real fill. Before the first step lands there is no provider-reported
170
- number and the provenance is `unavailable`, which is a different fact from zero. No fraction is
171
- exposed: dividing is one line where it is rendered, and the output reserve belongs to the
172
- consumer's prompt budget rather than to this layer.
173
-
174
- Canonical protocol exports are `AgentProtocol`, `AgentProtocolConfig`, `AgentTerminalAcceptance`,
175
- `AgentTerminalAcceptanceInput`, `hasAgentTerminalOutput`, `AgentRecordIdSchema`, `AgentRecordVersionSchema`,
176
- `AgentTimestampSchema`, `AgentJsonObjectSchema`, `AgentProviderEnvelopeSchema`,
177
- `AgentProviderEnvelope`, `AgentMessagePartSchema`, `AgentMessagePart`, `AgentTextPartSchema`,
178
- `AgentReasoningPartSchema`, `AgentFilePartSchema`, `AgentSourcePartSchema`,
179
- `AgentToolCallPartSchema`, `AgentToolResultPartSchema`, `AgentOpaquePartSchema`,
180
- `AgentControlPartSchema`, `AgentMessageRoleSchema`, `AgentMessageStatusSchema`, `AgentMessage`,
181
- `AgentAssistantPlaceholderSchema`, `AgentAssistantPlaceholder`, `AgentRunStateSchema`,
182
- `AgentTerminalReasonSchema`, `AgentTerminalReason`, `AgentRunQueuePrioritySchema`,
183
- `AgentRunQueuePriority`, `AgentRun`, `AgentSnapshot`,
184
- `AgentUsageValueSchema`, `AgentCostValueSchema`, `AgentUsageSchema`, `AgentUsage` and
185
- `AgentRunMetrics`.
186
-
187
- `AgentProvenanceSchema` / `AgentProvenance` is the entrypoint's single vocabulary for **how a
188
- number came to be known**: `provider-reported` (the provider stated it about a request it served),
189
- `measured` (this process counted it exactly, before any request was made), `computed` (arithmetic
190
- over other values — a sum of exact numbers is still `computed`), `estimated` (a heuristic) and
191
- `unavailable` (not known, so `value` is absent, which is a different fact from a reported zero).
192
- Each surface declares the subset it can produce: `AgentUsageValueSchema` and `AgentCostValueSchema`
193
- describe a request that has already happened and never say `measured`; `AgentTokenCountSchema`
194
- describes a prompt being composed and never says `provider-reported`. Every token count is an
195
- integer — `AgentUsageValueSchema` and `AgentTokenCountSchema` refuse a fractional `value`, and a
196
- provider figure that is not a whole number is normalised to `unavailable` rather than thrown.
197
- `AgentCostValueSchema.value` stays fractional, because money is.
198
-
199
- `runs.inputPolicy` takes `queue` (default), `inject`, `interrupt`, `interrupt-next` or `supersede`, or a function of
200
- the raw input returning one. `inject` lets a run in flight take a newly arrived input into its prompt
201
- at a step boundary and answer it too; the absorption is committed in the **same transaction** as that
202
- run's terminal record, via `CommitRunTerminal.absorb`, so a run that ends any other way leaves an
203
- ordinary queued successor. The absorbed run ends with `terminalReason: 'absorbed'`, run state
204
- `'superseded'`, `absorbedIntoRunId` naming the run that answered it, and **no assistant message of
205
- its own**; a submission on its idempotency key resolves through that pointer to the answer
206
- (→ ADR 0113).
207
-
208
- `interrupt-next` interrupts the active run, waits for its real settlement and then executes the new
209
- input before ordinary pending work. Ordinary work is not dropped or re-admitted, and urgent work is
210
- FIFO within its own class. `AgentRun.queuePriority` persists the pending class;
211
- `AgentRun.executionSequence` persists the actual first-acquisition order, so recovery and canonical
212
- history preserve the same `A → C → B` order across equal timestamps and scan pages (→ ADR 0127).
213
-
214
- With `queue`, a durable successor admission is not prompt eligibility: the current executor sees
215
- only records through its own run boundary. Snapshot history is normalized to causal turn order
216
- (assigned input(s), assistant, then successor input(s)) even when the storage codec physically
217
- appended the successor before the predecessor checkpoint.
218
-
219
- `AgentRuntimeStore` has two **bounded** reads beside `loadSnapshot`:
220
- `loadRun({ conversationId, runId })` returns an `AgentRunView` — the run, the conversation version it
221
- was read at, and the retained answer once the run is terminal — or `undefined`; `listActiveRuns(conversationId)`
222
- returns the runs that have not ended in durable execution/priority order. Neither reads history, so
223
- neither grows with the length of the conversation, and neither needs anything new from
224
- `AgentRuntimeStoreDriver`. `loadSnapshot` and every mutation result still carry the whole
225
- conversation — that is what the store's reducer validates against, and what the runtime builds a
226
- prompt from (→ ADR 0112).
227
-
228
- `AgentRuntimeStore.purgeConversation` is optional; `purgeAgentConversation(store, input)` explicitly
229
- handles unsupported stores. Official memory and initialized SQLite stores refuse active runs,
230
- remove every owned payload and reserve the conversation ID permanently. Empty snapshots are not
231
- deletion receipts. Consumer metadata, files, event logs and UI cache invalidation remain outside
232
- the transaction. See [purging a conversation](../guide/agent-runtime.md#purging-a-conversation).
233
-
234
- Store command/result exports are `AcceptInputAndAssignRun`, `AcceptInputAndAssignRunSchema`,
235
- `AcquireAgentRun`, `AcquireAgentRunSchema`, `CheckpointRunAssistant`,
236
- `CheckpointRunAssistantSchema`, `CommitRunTerminal`, `CommitRunTerminalSchema`,
237
- `RequestRunInterrupt`, `RequestRunInterruptSchema`, `AgentRunView`, `AgentRunViewSchema`,
238
- `runStateForTerminalReason`,
239
- `ACTIVE_AGENT_RUN_STATES`, `RecoverAgentRun`, `ReplaceCompactedRange`,
240
- `ReplaceCompactedRangeSchema`, `AgentStoreMutationResult`, `AgentStoreMutationResultSchema`,
241
- `AgentStoreAppliedSchema`, `AgentStoreConflictSchema`, `AgentStoreDuplicateSchema`,
242
- `AgentStoreNotFoundSchema`, `AgentAdmissionReceipt`, `AgentAdmissionReceiptSchema`,
243
- `AgentRuntimeHead`, `AgentStoredRun`, `AgentStoreCompareAndSwapResult`, `AgentHistoryMutation`,
244
- `AgentRecoverableDescriptor`, `AgentRecoverableDescriptorSchema`, `AgentRecoverablePage` and
245
- `AgentRecoverablePageSchema`.
246
-
247
- History and context-budget exports are `projectAgentHistoryDetailed`,
248
- `AgentHistoryProjectionDecision`, `AgentHistoryProjectionResult`, `selectAgentHistory`,
249
- `SelectAgentHistoryOptions`, `AgentHistoryBudgetDecision`, `AgentHistoryBudgetResult`,
250
- `AgentPromptBudget`, `AgentPromptSection`, `AgentPromptSectionContext`, `AgentTokenCount`,
251
- `AgentTokenCountSchema`, `ComposeAgentPromptOptions` and `ComposedAgentPrompt`. Whole-turn history
252
- selection never splits a tool chronology and reports why every canonical record was retained or
253
- removed. `AgentHistoryEvidencePolicy` is the shared opt-in for marked failed-assistant evidence in
254
- projection, budgeting and structured compaction; `isAssistantHistoryEvidence` applies it. The
255
- compatibility default omits it. Approval message schemas are
256
- `AgentToolApprovalRequestPartSchema` and `AgentToolApprovalResponsePartSchema`.
257
-
258
- With `failedAssistant: 'assistant-marked'`, `selectCompactableHistory` and
259
- `structuredCompaction` admit a failed prefix only when the entire turn's tool chronology
260
- is complete. `eligibleMessages` stays raw: the summarizer must use the same policy in
261
- `projectAgentHistoryDetailed` and preserve non-success/uncertain outcomes in its summary.
262
- Even an empty opted-in failed assistant carries a non-success marker in that projection.
263
- Use `incompleteToolTurn: 'error'` to refuse a range the projector cannot represent.
264
- Compaction never deletes canonical effect events or the retained terminal receipt;
265
- chronological completeness does not settle an external effect. See the
266
- [failed-prefix recovery contract](../guide/agent-runtime.md#recovering-a-prefix-after-a-failed-turn).
267
-
268
- Model exports are `AgentLanguageModelProvider`, `AgentModelCapability`,
269
- `AgentModelCapabilitySchema`, `AgentModelDescriptor`,
270
- `AgentModelDescriptorSchema`, `AgentModelRegistry`, `AgentModelRegistryConfig`,
271
- `AgentModelRegistrySnapshot`, `AgentModelRegistrySnapshotSchema`, `AgentModelSnapshotPolicy`,
272
- `AgentResolvedModel` and `validateAgentModelSnapshot`. Registry `preflight` validates availability,
273
- provider and required capabilities without constructing the model; runtime `models.preflight`
274
- runs before durable admission.
275
-
276
- Delivery exports are `AgentAdmissionEventSchema`, `AgentAttemptResetEventSchema`, `AgentCheckpointEventSchema`,
277
- `AgentRunStateEventSchema`, `AgentRunOperationEventSchema`, `AgentTerminalEventSchema`,
278
- `AgentTransientDeltaEventSchema`,
279
- `AgentReasoningStartEventSchema`, `AgentReasoningDeltaEventSchema`,
280
- `AgentReasoningEndEventSchema`, `AgentToolStatusEventSchema`, `AgentToolProgressEventSchema` (what a
281
- running tool reported through `ctx.reportProgress`, transient and never part of the model's input),
282
- `AgentRuntimeEvent`,
283
- `AgentRuntimeEventCursor`, `AgentRuntimeEventCursorSchema`, `AgentRuntimeCursorAdvance`,
284
- `advanceAgentRuntimeEventCursor`, `agentDurableEventId`, `AgentRuntimeEventSink`,
285
- `AgentRuntimeEventSinkConfig` and `createAgentRuntimeEventSink`. Cursor gaps require a canonical
286
- snapshot reload; the bounded sink isolates transport failure and supports a typed projection step.
287
-
288
- Managed effects and operator telemetry additionally export `AgentToolFenceConfig`,
289
- `AgentToolFenceContext`, `AgentObservability`, `AgentRunEvent`, `AgentRunEventSchema`,
290
- `AgentRunStartedEvent`, `AgentRunStartedEventSchema`, `AgentStepFinishedEvent`,
291
- `AgentStepFinishedEventSchema`, `AgentRunTerminalEvent`, `AgentRunTerminalEventSchema`,
292
- `AgentRunSinkConfig`, `AgentRunSinkDrop` and `AgentRunSinkError`. A monotonic run `fencingToken`
293
- may accompany checkpoint/terminal writes and tool context; internal causes are redacted unless an
294
- operator-only observability sink explicitly opts in.
295
-
296
- ### Completion and agent invocation receipts
297
-
298
- `createModelInvocationLedger` constructs a `ModelInvocationLedger` from
299
- `ModelInvocationConfig`: the existing store and model registry, a 32-byte payload
300
- key, required host authorization, optional bounded payload size and `onAttempt`.
301
- `complete(input, context, signal?)` executes only the supplied prompt, with no tools
302
- or framework instructions; repeated keys return the existing invocation ID. It
303
- resolves `{ invocationId, outcome, text?, receiptError? }`: `receiptError` says a
304
- receipt could not be written and never changes `outcome` or drops `text`.
305
- `read(input, context)` returns a bounded event page shared by agent and completion;
306
- `readPayload(input, context)` requires a separate authorization action and returns a
307
- discriminated `ModelInvocationPayloadRead` (`available` with decrypted payload or `expired`
308
- with `expiredAt` once redacted); `purgePayloads(input, context)` redacts expired ciphertext
309
- in-place across the store and search indexes while retaining receipt metadata and digests.
310
- When a request or response payload exceeds `maxPayloadBytes`, the provider call still succeeds
311
- while recording `payloadOmitted: 'max-payload-bytes'` (with `artifactId` omitted and `payloadSha256`
312
- preserved) and reporting `InvocationPayloadTooLargeError` through `complete().receiptError`. See the
313
- [guide and migration example](../guide/agent-runtime.md#plain-completions-and-shared-invocation-receipts).
314
-
315
- | Export | Kind | Purpose |
316
- | --- | --- | --- |
317
- | `CompletionInvocationInputSchema` / `CompletionInvocationInput` | schema/type | strict prompt, model-attempt list, deadline, idempotency key and trace input |
318
- | `ModelInvocationTraceSchema` / `ModelInvocationTrace` | schema/type | operation, purpose, project, parent trace and optional experiment/case/profile |
319
- | `ModelInvocationRecordSchema` / `ModelInvocationRecord` | schema/type | discriminated invocation start/finish and per-attempt requested/sent/effective evidence (with optional `artifactId` and `payloadOmitted` when oversized, keeping `payloadSha256`) |
320
- | `InvocationPayloadTooLargeError` | class | `RangeError` carrying `{ bytes, maxBytes, sha256 }` when a recorded invocation payload exceeds `maxPayloadBytes` without aborting the provider call |
321
- | `InvocationPayloadOmissionReasonSchema` / `InvocationPayloadOmissionReason` | schema/type | reason a payload body was not stored (`'max-payload-bytes'`) |
322
- | `ModelInvocationPayloadReadSchema` / `ModelInvocationPayloadRead` | schema/type | discriminated result of `readPayload`: `{ status: 'available', payload, ... }` or `{ status: 'expired', expiredAt, ... }` |
323
- | `PurgeInvocationPayloadsInputSchema` / `PurgeInvocationPayloadsInput` | schema/type | input for `purgePayloads` / `store.purgeExpiredPayloads`: `before`, optional `conversationId` and `limit` |
324
- | `PurgeInvocationPayloadsResultSchema` / `PurgeInvocationPayloadsResult` | schema/type | result of `purgePayloads`: `purged`, `freedBytes`, and `hasMore` |
325
- | `ModelInvocationAuthorizationInput` | type | discriminated authorization payload passed to `ModelInvocationConfig.authorize` (`'complete'`, `'agent'`, `'read'`, `'read-payload'`, or `'purge-payloads'`) |
326
- | `ModelInvocationAttemptContext` | type | conversation, operation, invocation, attempt, step and optional agent run identity |
327
- | `currentModelInvocationAttempt` | function | returns causal IDs inside the provider transport; undefined outside an invocation |
328
- | `modelInvocationSpendAttribution` | function | the current attempt as `stitchkit/spend` attribution fields (conversation, run, invocation, attempt, step) — a spend gateway's `context` |
329
- | `AgentStepBarriers` / `AgentToolCallDependencies` | _type_ | `loop.stepBarriers`, guards on each model step, checked by `createAgentRuntime`: `maxToolCallsPerStep` (a call past it is refused to the model as a `STEP_TOOL_CALL_LIMIT` tool error, without asking for its approval), `toolDependencies` (in the order the model made the calls, a read of an entity waits for the step's earlier writes of it and a write for its earlier reads and writes), `maxReasoningCharsPerStep` (past it the run stops as `policy_stop`), `stepText: 'after-tools'` (a step's text is held to its end and shown only if none of its tool calls failed; held text of an interrupted step is not shown); a streaming tool still streams, a deferred tool catalog survives the wrapping |
330
- | `AgentStepBarrierError` | class | the run stopped at a step bound: `bound` is `reasoning` |
331
- | `createToolDependencyResolver` | function | `toolDependencies` from operation effects — the `effect` of each endpoint of `contracts`, under its mounted tool name, and `effects` (by tool name) for tools of no contract — and the application's `entityOf(toolName, input)`: a `write` tool writes its entity, a `read` tool reads it |
332
-
333
- The runtime `invocations` option takes this ledger and a trace callback; it requires
334
- the same store and preserves the existing tool loop. `AgentRuntimeStore.appendEventOnce`
335
- is an optional atomic capability required by receipt admission, and
336
- `AgentRuntimeStore.findEventOnce` reads the event it wrote by kind and key. Built-in
337
- stores supply both; custom adapters must honor the once-only transaction contract.
338
- A driver's optional `events.find(transaction, { conversationId, eventId })` makes
339
- both one lookup instead of a scan of the conversation log.
365
+ | `AgentProviderStreamCutError` / `AgentProviderStreamCutErrorOptions` | class / _type_ | explicit retryable provider stream truncation evidence and constructor options |
366
+
367
+ ### Native model port, driver composition and peer-free completions
368
+
369
+ `stitchkit/agent-runtime` executes models through `AgentModelDriver` — one provider call per step,
370
+ no SDK retries and no tool execution inside the driver. `completeText` and `completeObject` reuse
371
+ the same native step execution without requiring a store. → ADR 0336.
372
+
373
+ | Export | Kind | Summary |
374
+ |--------|------|---------|
375
+ | `AgentModelDriver` / `AgentModelDriverFactory` | _type_ | single-step model port (`stream(request, signal)`) and provider factory registered in `defineModelRegistry` |
376
+ | `AgentModelRequest` / `AgentModelStream` / `AgentModelStreamPart` | _type_ | normalized single-step request (`instructions`, `messages`, `tools`, `toolChoice`, `responseFormat`, `cacheControl`, `settings`, `providerOptions`, `headers`, `correlation`) and ordered stream event union (including keepalive `ping`, multi-block reasoning/text/tool events with unified `toolCallId`, `file` with optional `filename`, and terminal `finish`) |
377
+ | `AgentModelToolSpec` / `AgentModelFunctionToolSpec` / `AgentModelProviderToolSpec` / `AgentModelJsonValue` / `AgentModelToolChoice` / `AgentModelCallSettings` / `AgentModelCorrelation` | _type_ | union of client function tool specs (JSON Schema 2020-12) and provider-native tool specs (`type: 'provider'` with `AgentModelJsonValue` config), tool-choice directive, call sampling settings and non-secret request correlation (`conversationId`, `runId`, `invocationId`, `attemptId`, `step`) |
378
+ | `AgentModelFinishReason` / `AgentModelResponseMetadata` / `AgentModelCostDetails` / `AgentStepTimings` / `AgentStepChunkIntervals` | _type_ | normalized step finish reason, response metadata (including server `modelId` and `timestamp`), optional provider-reported cost/BYOK breakdown (`promptCostUsd`, `outputCostUsd`, `isByok`), and measured step/response/tool/TTFT timings with optional inter-chunk interval percentiles (`min`, `p10`, `median`, `avg`, `p90`, `max`) |
379
+ | `wrapModelDriver` / `composeModelDrivers` | function | wrap one `AgentModelDriver` with one or an ordered outer-to-inner list of lifecycle decorators whose `onClose` runs once on finish, error, early stream cancellation, or abort |
380
+ | `AgentModelDriverDecorator` / `AgentModelDriverStreamOutcome` | _type_ | generic per-stream interceptor (`beforeStream`, `transformRequest`, `transformSignal`, `onPart`, `onClose`) and terminal stream outcome (`finished`, `errored`, `cancelled`) |
381
+ | `completeText` / `streamComplete` / `CompleteTextInput` / `CompleteTextOptions` / `CompletePromptInput` / `CompleteTextResult` / `CompleteTextStream` / `CompleteStreamPart` / `CompletePrepareStep` / `AgentCompleteStopPolicy` | functions / _types_ | peer-free single- or multi-step completion and standalone async-iterable streaming over any `AgentModelDriver` (no store required), with compile-time XOR on `prompt` vs `messages`, `retry`, `stopPolicies`, `idleTimeoutMs`, `onPart`, `headers`, tools, `prepareStep`, `repairToolCall`, timings and usage |
382
+ | `completeObject` / `CompleteObjectInput` / `CompleteObjectResult` | function / _types_ | peer-free structured-output completion emitting strict JSON Schema (`draft-2020-12` via `toJsonSchema(..., 'input')`), stripping strict-mode optional `null`s prior to Zod validation, and supporting multi-step tool loops |
383
+ | `AgentStructuredOutputError` / `AgentStructuredOutputErrorReason` / `AgentStructuredOutputErrorDetails` | class / _types_ | typed error thrown by `completeObject` with `reason` (`'truncated' \| 'tool-calls' \| 'content-filter' \| 'provider-error' \| 'interrupted' \| 'empty' \| 'invalid-json' \| 'schema-mismatch'`), `finishReason`, `rawText`, `steps`, and `usage` |
384
+ | `AgentRetryExhaustedError` / `AgentRetryExhaustedErrorDetails` / `AgentRetryAttemptRecord` | class / _types_ | typed error thrown when stateless completion retries exhaust `retry.maxAttempts` or `maxRetryDurationMs`, carrying every failed attempt, `lastError`, and accumulated billable `usage` |
385
+ | `AgentProviderError` / `AgentProviderErrorDetails` / `isAgentProviderError` | class / _type_ / function | canonical provider HTTP/envelope error carrying `provider`, `statusCode`, `code`, `errorType`, `requestId`, `retryAfterMs`, `failureReason`, redacted safe message, and runtime type guard |
386
+ | `AgentUnknownToolError` / `AgentInvalidToolInputError` | class | PII-safe tool-dispatch errors for unknown/inactive tools and invalid JSON or Zod tool inputs |
387
+ | `AgentToolApprovalError` / `AgentToolApprovalErrorReason` / `AgentInvalidToolApprovalSignatureError` / `AgentToolCallNotFoundForApprovalError` | class / _type_ | typed failures and machine reason codes (`'invalid-signature' \| 'call-not-found' \| 'input-validation-failed' \| 'input-mutated' \| 'invalid-policy-decision' \| 'approval-unsupported'`) for invalid approval payloads, WebCrypto HMAC-SHA256 signature verification failure, unresolved approval call IDs, or standalone fail-closed `needsApproval` refusal |
388
+ | `AgentToolApprovalConfiguration` / `AgentToolApprovalDecision` / `AgentToolApprovalCallOptions` / `AgentToolApprovalToolRule` | _type_ | per-call or per-tool approval policy evaluated by the native step loop |
389
+ | `AgentStepToolCallBatchHook` / `AgentStepToolCallBatchInput` / `AgentStepToolCallBatchDecision` | _type_ | `loop.beforeStepToolCalls` whole-step batch policy invoked once all tool calls of a step are parsed and validated, able to refuse selected calls by `toolCallId` |
390
+ | `AgentToolCallRepairFunction` / `AgentToolCallRepairInput` | _type_ | first-class `repairToolCall` hook that rewrites an unknown, inactive, or invalid tool call before execution |
391
+ | `AgentPrepareStepInput` / `AgentPrepareStepResult` | _type_ | step-preparation input and per-step overrides (`driver`, `instructions`, `messages`, `activeTools`, `toolChoice`, `responseFormat`, `cacheControl`, sampling settings, `providerOptions`, `headers`) |
392
+ | `AgentStepResult` / `AgentStepContentPart` / `AgentStepToolCall` / `AgentStepToolResult` | _type_ | peer-free completed step record delivered to `prepareStep`, `stopPolicies`, and `onStepFinish` |
393
+ | `AgentModelMessageSchema` / `AgentModelMessage` / `AgentModelSystemMessageSchema` / `AgentModelSystemMessage` / `AgentModelUserMessageSchema` / `AgentModelUserMessage` / `AgentModelAssistantMessageSchema` / `AgentModelAssistantMessage` / `AgentModelToolMessageSchema` / `AgentModelToolMessage` / `AgentInstructions` | schemas / _types_ | canonical peer-free model-exchange message schemas and normalized instruction input |
394
+ | `AgentModelUserContentPartSchema` / `AgentModelUserContentPart` / `AgentModelAssistantContentPartSchema` / `AgentModelAssistantContentPart` / `AgentModelToolContentPartSchema` / `AgentModelToolContentPart` / `AgentToolModelContentPart` / `AgentToolModelOutputSchema` | schemas / _types_ | non-deprecated content part schemas (`text`, `reasoning`, `file`, `reasoning-file`, `tool-call`, `tool-result`, approvals, `custom`) and structured tool-output schema |
395
+ | `AgentModelFileDataSchema` / `AgentModelFileData` / `AgentGeneratedFile` / `AgentGeneratedFileData` | schema / _types_ | tagged file payload (`data`, `url`, `reference`, `text`) and generated model file (`mediaType`, `data`, optional `filename`, `url?`, lazy `base64`/`uint8Array`, `providerMetadata?`) handed to `persistGeneratedFile` |
396
+ | `AgentModelResponseFormatSchema` / `AgentModelResponseFormat` / `AgentCacheControlSchema` / `AgentCacheControl` / `AgentModelProviderOptionsSchema` / `AgentModelProviderOptions` / `AgentModelProviderOptionValue` | schemas / _types_ | portable structured-output format (`text`, `json-object`, `json-schema`), prompt-cache breakpoint directive (`ephemeral`, optional `'5m' \| '1h'` TTL), and namespaced provider options with recursive `AgentModelProviderOptionValue` supporting optional `undefined` keys under `exactOptionalPropertyTypes` |