stitchkit 0.135.1 → 0.136.1

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 (436) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/README.md +37 -11
  3. package/dist/agent-executor/acp/v1-session-build.d.ts +51 -0
  4. package/dist/agent-executor/acp/v1-session-build.d.ts.map +1 -0
  5. package/dist/agent-executor/acp/v1-session.d.ts +1 -1
  6. package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
  7. package/dist/agent-executor/claude/classify.d.ts +1 -1
  8. package/dist/agent-executor/claude/classify.d.ts.map +1 -1
  9. package/dist/agent-executor/claude/events-wire.d.ts +13 -0
  10. package/dist/agent-executor/claude/events-wire.d.ts.map +1 -0
  11. package/dist/agent-executor/claude/events.d.ts +1 -11
  12. package/dist/agent-executor/claude/events.d.ts.map +1 -1
  13. package/dist/agent-executor/codex/protocol.d.ts +0 -143
  14. package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
  15. package/dist/agent-executor/codex/request-answers.d.ts +1 -1
  16. package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
  17. package/dist/agent-executor/codex/server-requests.d.ts +150 -0
  18. package/dist/agent-executor/codex/server-requests.d.ts.map +1 -0
  19. package/dist/agent-executor/executor-contract.d.ts.map +1 -1
  20. package/dist/agent-executor/image-input.d.ts +10 -3
  21. package/dist/agent-executor/image-input.d.ts.map +1 -1
  22. package/dist/agent-executor/testing/replay-scenarios.d.ts.map +1 -1
  23. package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -1
  24. package/dist/agent-executor/vocabulary.d.ts +80 -0
  25. package/dist/agent-executor/vocabulary.d.ts.map +1 -1
  26. package/dist/agent-parts/model.d.ts +94 -0
  27. package/dist/agent-parts/model.d.ts.map +1 -1
  28. package/dist/agent-parts/parts.d.ts +176 -0
  29. package/dist/agent-parts/parts.d.ts.map +1 -1
  30. package/dist/agent-runtime/browser/browser-control-contract.d.ts +444 -0
  31. package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -1
  32. package/dist/agent-runtime/browser/control-schema.d.ts +532 -0
  33. package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -1
  34. package/dist/agent-runtime/browser/control-view.d.ts.map +1 -1
  35. package/dist/agent-runtime/event-schema.d.ts +720 -3
  36. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  37. package/dist/agent-runtime/history/run-history-parts.d.ts.map +1 -1
  38. package/dist/agent-runtime/loop/deferred-tools.d.ts.map +1 -1
  39. package/dist/agent-runtime/loop/invocation-payload.d.ts.map +1 -1
  40. package/dist/agent-runtime/loop/invocation-stream.d.ts +9 -1
  41. package/dist/agent-runtime/loop/invocation-stream.d.ts.map +1 -1
  42. package/dist/agent-runtime/loop/provider-stream-parts.d.ts +6 -0
  43. package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -1
  44. package/dist/agent-runtime/loop/provider-stream-segments.d.ts +1 -3
  45. package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -1
  46. package/dist/agent-runtime/loop/run-acquisition.d.ts.map +1 -1
  47. package/dist/agent-runtime/loop/run-approval-signature.d.ts +38 -0
  48. package/dist/agent-runtime/loop/run-approval-signature.d.ts.map +1 -0
  49. package/dist/agent-runtime/loop/run-approval.d.ts +0 -28
  50. package/dist/agent-runtime/loop/run-approval.d.ts.map +1 -1
  51. package/dist/agent-runtime/loop/run-complete-port.d.ts +24 -0
  52. package/dist/agent-runtime/loop/run-complete-port.d.ts.map +1 -0
  53. package/dist/agent-runtime/loop/run-complete-stream.d.ts +7 -2
  54. package/dist/agent-runtime/loop/run-complete-stream.d.ts.map +1 -1
  55. package/dist/agent-runtime/loop/run-complete-types.d.ts +14 -1
  56. package/dist/agent-runtime/loop/run-complete-types.d.ts.map +1 -1
  57. package/dist/agent-runtime/loop/run-complete.d.ts +2 -2
  58. package/dist/agent-runtime/loop/run-complete.d.ts.map +1 -1
  59. package/dist/agent-runtime/loop/run-execution-state.d.ts +8 -0
  60. package/dist/agent-runtime/loop/run-execution-state.d.ts.map +1 -1
  61. package/dist/agent-runtime/loop/run-loop-events.d.ts +6 -1
  62. package/dist/agent-runtime/loop/run-loop-events.d.ts.map +1 -1
  63. package/dist/agent-runtime/loop/run-model-call.d.ts +44 -0
  64. package/dist/agent-runtime/loop/run-model-call.d.ts.map +1 -0
  65. package/dist/agent-runtime/loop/run-model-step.d.ts +25 -28
  66. package/dist/agent-runtime/loop/run-model-step.d.ts.map +1 -1
  67. package/dist/agent-runtime/loop/run-model-steps.d.ts +6 -0
  68. package/dist/agent-runtime/loop/run-model-steps.d.ts.map +1 -0
  69. package/dist/agent-runtime/loop/run-model-stream.d.ts +3 -1
  70. package/dist/agent-runtime/loop/run-model-stream.d.ts.map +1 -1
  71. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts +0 -2
  72. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts.map +1 -1
  73. package/dist/agent-runtime/loop/run-step-loop.d.ts +19 -0
  74. package/dist/agent-runtime/loop/run-step-loop.d.ts.map +1 -0
  75. package/dist/agent-runtime/loop/run-step-port.d.ts +175 -0
  76. package/dist/agent-runtime/loop/run-step-port.d.ts.map +1 -0
  77. package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -1
  78. package/dist/agent-runtime/loop/run-stream-recorded.d.ts.map +1 -1
  79. package/dist/agent-runtime/loop/run-stream-step-text.d.ts.map +1 -1
  80. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts +2 -1
  81. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts.map +1 -1
  82. package/dist/agent-runtime/loop/run-tool-call-input.d.ts +39 -0
  83. package/dist/agent-runtime/loop/run-tool-call-input.d.ts.map +1 -0
  84. package/dist/agent-runtime/loop/run-tool-call.d.ts +13 -34
  85. package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -1
  86. package/dist/agent-runtime/loop/run-tool-errors.d.ts +5 -0
  87. package/dist/agent-runtime/loop/run-tool-errors.d.ts.map +1 -1
  88. package/dist/agent-runtime/loop/run-tool-executor.d.ts +1 -1
  89. package/dist/agent-runtime/loop/run-tool-executor.d.ts.map +1 -1
  90. package/dist/agent-runtime/loop/run-tool-slots.d.ts +2 -1
  91. package/dist/agent-runtime/loop/run-tool-slots.d.ts.map +1 -1
  92. package/dist/agent-runtime/loop/runtime-state.d.ts.map +1 -1
  93. package/dist/agent-runtime/loop/runtime.d.ts +0 -5
  94. package/dist/agent-runtime/loop/runtime.d.ts.map +1 -1
  95. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts +1 -5
  96. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts.map +1 -1
  97. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts +15 -0
  98. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts.map +1 -0
  99. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts +11 -0
  100. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts.map +1 -0
  101. package/dist/agent-runtime/providers/ai-sdk.d.ts +1 -9
  102. package/dist/agent-runtime/providers/ai-sdk.d.ts.map +1 -1
  103. package/dist/agent-runtime/providers/anthropic-sse.d.ts.map +1 -1
  104. package/dist/agent-runtime/providers/openrouter-admission.d.ts.map +1 -1
  105. package/dist/agent-runtime/providers/openrouter-audio.d.ts +123 -81
  106. package/dist/agent-runtime/providers/openrouter-audio.d.ts.map +1 -1
  107. package/dist/agent-runtime/providers/openrouter-catalog-cache.d.ts.map +1 -1
  108. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts.map +1 -1
  109. package/dist/agent-runtime/providers/openrouter-catalog.d.ts +2 -2
  110. package/dist/agent-runtime/providers/openrouter-catalog.d.ts.map +1 -1
  111. package/dist/agent-runtime/providers/openrouter-client.d.ts +37 -0
  112. package/dist/agent-runtime/providers/openrouter-client.d.ts.map +1 -0
  113. package/dist/agent-runtime/providers/openrouter-http.d.ts +26 -6
  114. package/dist/agent-runtime/providers/openrouter-http.d.ts.map +1 -1
  115. package/dist/agent-runtime/providers/openrouter-media.d.ts +91 -77
  116. package/dist/agent-runtime/providers/openrouter-media.d.ts.map +1 -1
  117. package/dist/agent-runtime/providers/openrouter-models.d.ts +2 -23
  118. package/dist/agent-runtime/providers/openrouter-models.d.ts.map +1 -1
  119. package/dist/agent-runtime/providers/openrouter-options.d.ts +2 -0
  120. package/dist/agent-runtime/providers/openrouter-options.d.ts.map +1 -1
  121. package/dist/agent-runtime/providers/openrouter-request.d.ts +23 -0
  122. package/dist/agent-runtime/providers/openrouter-request.d.ts.map +1 -0
  123. package/dist/agent-runtime/providers/openrouter-retrieval.d.ts +86 -55
  124. package/dist/agent-runtime/providers/openrouter-retrieval.d.ts.map +1 -1
  125. package/dist/agent-runtime/providers/openrouter-speech.d.ts +90 -0
  126. package/dist/agent-runtime/providers/openrouter-speech.d.ts.map +1 -0
  127. package/dist/agent-runtime/providers/openrouter-spend.d.ts +2 -2
  128. package/dist/agent-runtime/providers/openrouter-spend.d.ts.map +1 -1
  129. package/dist/agent-runtime/providers/openrouter-stream.d.ts.map +1 -1
  130. package/dist/agent-runtime/providers/openrouter-systemone.d.ts +87 -32
  131. package/dist/agent-runtime/providers/openrouter-systemone.d.ts.map +1 -1
  132. package/dist/agent-runtime/providers/openrouter-url.d.ts +7 -1
  133. package/dist/agent-runtime/providers/openrouter-url.d.ts.map +1 -1
  134. package/dist/agent-runtime/providers/openrouter-wire.d.ts +45 -0
  135. package/dist/agent-runtime/providers/openrouter-wire.d.ts.map +1 -0
  136. package/dist/agent-runtime/providers/openrouter.d.ts +1 -3
  137. package/dist/agent-runtime/providers/openrouter.d.ts.map +1 -1
  138. package/dist/agent-runtime/providers/provider-http.d.ts +14 -2
  139. package/dist/agent-runtime/providers/provider-http.d.ts.map +1 -1
  140. package/dist/agent-runtime/providers/provider-json-schema-strip.d.ts.map +1 -1
  141. package/dist/agent-runtime/providers/provider-json-schema.d.ts.map +1 -1
  142. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts.map +1 -1
  143. package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts +42 -0
  144. package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts.map +1 -0
  145. package/dist/agent-runtime/providers/provider-usage.d.ts +9 -0
  146. package/dist/agent-runtime/providers/provider-usage.d.ts.map +1 -1
  147. package/dist/agent-runtime/runtime-internals.d.ts +1 -3
  148. package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
  149. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts +9 -0
  150. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts.map +1 -1
  151. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts +6 -0
  152. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts.map +1 -1
  153. package/dist/agent-runtime/sandbox/sandbox-contract.d.ts.map +1 -1
  154. package/dist/agent-runtime/sandbox/sandbox-process-linux.d.ts.map +1 -1
  155. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts +5 -1
  156. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts.map +1 -1
  157. package/dist/agent-runtime/sandbox/sandbox-process-wrapper.d.ts.map +1 -1
  158. package/dist/agent-runtime/schemas-json-projection.d.ts +29 -0
  159. package/dist/agent-runtime/schemas-json-projection.d.ts.map +1 -0
  160. package/dist/agent-runtime/schemas-message.d.ts +88 -0
  161. package/dist/agent-runtime/schemas-message.d.ts.map +1 -1
  162. package/dist/agent-runtime/schemas-run.d.ts +88 -0
  163. package/dist/agent-runtime/schemas-run.d.ts.map +1 -1
  164. package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -1
  165. package/dist/agent-runtime/stores/branch-observations.d.ts +42 -42
  166. package/dist/agent-runtime/stores/branch-replay.d.ts +264 -0
  167. package/dist/agent-runtime/stores/branch-replay.d.ts.map +1 -1
  168. package/dist/agent-runtime/stores/conversations.d.ts +88 -0
  169. package/dist/agent-runtime/stores/conversations.d.ts.map +1 -1
  170. package/dist/agent-runtime/stores/sql-rows.d.ts +74 -10
  171. package/dist/agent-runtime/stores/sql-rows.d.ts.map +1 -1
  172. package/dist/agent-runtime/stores/store-driver-contract.d.ts +616 -0
  173. package/dist/agent-runtime/stores/store-driver-contract.d.ts.map +1 -1
  174. package/dist/agent-runtime/stores/store-events.d.ts +1056 -0
  175. package/dist/agent-runtime/stores/store-events.d.ts.map +1 -1
  176. package/dist/agent-runtime/stores/store.d.ts +1232 -0
  177. package/dist/agent-runtime/stores/store.d.ts.map +1 -1
  178. package/dist/agent-runtime/terminal-commit.d.ts +74 -10
  179. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  180. package/dist/agent-runtime/testing/fault-bench.d.ts +5 -1
  181. package/dist/agent-runtime/testing/fault-bench.d.ts.map +1 -1
  182. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +158 -30
  183. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts.map +1 -1
  184. package/dist/agent-runtime/testing/store-conformance-support.d.ts +79 -15
  185. package/dist/agent-runtime/testing/store-conformance-support.d.ts.map +1 -1
  186. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  187. package/dist/application/diagnostic-journal-manager.d.ts +1 -1
  188. package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
  189. package/dist/application/notification-delivery.d.ts.map +1 -1
  190. package/dist/browser/client-executors.d.ts.map +1 -1
  191. package/dist/browser/client-url.d.ts.map +1 -1
  192. package/dist/contract/define.d.ts +3 -7
  193. package/dist/contract/define.d.ts.map +1 -1
  194. package/dist/contract/normalize.d.ts +17 -5
  195. package/dist/contract/normalize.d.ts.map +1 -1
  196. package/dist/entrypoints/agent-executor/acp.js +9 -6
  197. package/dist/entrypoints/agent-executor/claude-sdk.js +26 -25
  198. package/dist/entrypoints/agent-executor/claude.js +13 -12
  199. package/dist/entrypoints/agent-executor/codex.d.ts +2 -1
  200. package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
  201. package/dist/entrypoints/agent-executor/codex.js +135 -40
  202. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +5 -4
  203. package/dist/entrypoints/agent-executor/testing.js +23 -18
  204. package/dist/entrypoints/agent-executor.js +8 -8
  205. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +2 -1
  206. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -1
  207. package/dist/entrypoints/agent-runtime/ai-sdk.js +34 -30
  208. package/dist/entrypoints/agent-runtime/anthropic.js +15 -12
  209. package/dist/entrypoints/agent-runtime/browser.js +13 -8
  210. package/dist/entrypoints/agent-runtime/harness.js +26 -27
  211. package/dist/entrypoints/agent-runtime/openai.js +7 -7
  212. package/dist/entrypoints/agent-runtime/openrouter.d.ts +7 -5
  213. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
  214. package/dist/entrypoints/agent-runtime/openrouter.js +1097 -856
  215. package/dist/entrypoints/agent-runtime/postgres.js +9 -9
  216. package/dist/entrypoints/agent-runtime/realtime.js +9 -8
  217. package/dist/entrypoints/agent-runtime/sandbox.js +167 -139
  218. package/dist/entrypoints/agent-runtime/sqlite/bun.js +10 -10
  219. package/dist/entrypoints/agent-runtime/sqlite/node.js +10 -10
  220. package/dist/entrypoints/agent-runtime/testing.js +9 -9
  221. package/dist/entrypoints/agent-runtime.js +261 -375
  222. package/dist/entrypoints/application/diagnostic-journal.js +14 -10
  223. package/dist/entrypoints/application.js +18 -6
  224. package/dist/entrypoints/cli.js +36 -15
  225. package/dist/entrypoints/contract.js +12 -10
  226. package/dist/entrypoints/geo.js +1 -1
  227. package/dist/entrypoints/handler.js +5 -6
  228. package/dist/entrypoints/http.d.ts +2 -0
  229. package/dist/entrypoints/http.d.ts.map +1 -1
  230. package/dist/entrypoints/http.js +16 -4
  231. package/dist/entrypoints/index.js +26 -35
  232. package/dist/entrypoints/live.js +3 -3
  233. package/dist/entrypoints/node.js +7 -7
  234. package/dist/entrypoints/observability.js +9 -7
  235. package/dist/entrypoints/process.js +3 -3
  236. package/dist/entrypoints/remote.js +5 -5
  237. package/dist/entrypoints/server.js +29 -16
  238. package/dist/entrypoints/telegram/grammy.d.ts +1 -1
  239. package/dist/entrypoints/telegram/grammy.d.ts.map +1 -1
  240. package/dist/entrypoints/telegram/grammy.js +39 -5
  241. package/dist/entrypoints/telegram/screens.js +3 -0
  242. package/dist/entrypoints/telegram.d.ts +1 -1
  243. package/dist/entrypoints/telegram.d.ts.map +1 -1
  244. package/dist/entrypoints/telegram.js +19 -6
  245. package/dist/entrypoints/testing.js +10 -11
  246. package/dist/entrypoints/tools/agent.js +9 -10
  247. package/dist/entrypoints/tools/connections.js +27 -57
  248. package/dist/entrypoints/tools/contract.js +4 -4
  249. package/dist/entrypoints/tools/invoker.js +7 -8
  250. package/dist/entrypoints/tools/mcp.js +9 -10
  251. package/dist/entrypoints/tools/toolkit.js +11 -12
  252. package/dist/entrypoints/tools.js +24 -22
  253. package/dist/entrypoints/tracking/contract.js +1 -1
  254. package/dist/entrypoints/tracking/performance.js +1 -1
  255. package/dist/entrypoints/tracking.js +1 -1
  256. package/dist/{index-3czc3ykr.js → index-08a3qfr8.js} +1 -1
  257. package/dist/index-1psbyyhj.js +21 -0
  258. package/dist/{index-pdcbjd6a.js → index-1yky29qg.js} +6 -3
  259. package/dist/{index-b4c9dpzm.js → index-252den5a.js} +10 -11
  260. package/dist/{index-yhwx4fwk.js → index-26v8hjqm.js} +4 -4
  261. package/dist/{index-xtby8rj3.js → index-28kbdn63.js} +5 -47
  262. package/dist/{index-c24bj2r1.js → index-2wm9b9vs.js} +5 -5
  263. package/dist/{index-ht71v1ag.js → index-32ew02z1.js} +60 -45
  264. package/dist/{index-dm84tsd5.js → index-3kb8dw48.js} +1 -1
  265. package/dist/index-3tb82xr7.js +11 -0
  266. package/dist/{index-nr4fhfn4.js → index-4p2zx593.js} +2 -0
  267. package/dist/{index-grhhsrd5.js → index-4q9tmzea.js} +5 -4
  268. package/dist/{index-mcv7b2n0.js → index-63ctzjp4.js} +497 -495
  269. package/dist/{index-y0a4gt1s.js → index-65p8v81y.js} +3 -2
  270. package/dist/{index-z72vazf5.js → index-6y3eae97.js} +27 -83
  271. package/dist/{index-y0mwkgkf.js → index-8cnfgwg8.js} +1212 -1139
  272. package/dist/{index-mkmep637.js → index-9m1m92rg.js} +1 -1
  273. package/dist/{index-5awtbyns.js → index-9vj869rx.js} +1 -1
  274. package/dist/index-a1rjr381.js +114 -0
  275. package/dist/{index-6kwdfb9m.js → index-akesakvj.js} +23 -4
  276. package/dist/{index-5q0qpw3v.js → index-aqm7e864.js} +23 -8
  277. package/dist/{index-d4at0q09.js → index-b9mj31q7.js} +90 -88
  278. package/dist/{index-baba8ehy.js → index-bjrcbcn2.js} +2 -2
  279. package/dist/{index-fsw9wxk9.js → index-c9j8441q.js} +1 -103
  280. package/dist/{index-wdb5jhas.js → index-d1pdv8qc.js} +1 -1
  281. package/dist/{index-v0j22shs.js → index-d5mhgx72.js} +16 -11
  282. package/dist/{index-73wq9abg.js → index-df5xr2f9.js} +13 -59
  283. package/dist/{index-n9358ydy.js → index-dm50x3by.js} +1 -1
  284. package/dist/{index-zyyerdny.js → index-dmrx8xma.js} +3 -0
  285. package/dist/{index-78da4g74.js → index-dwq6a6sq.js} +17 -13
  286. package/dist/{index-9be3tf6r.js → index-e413q2cj.js} +49 -22
  287. package/dist/{index-57sbckhv.js → index-e4w0sfm1.js} +2 -2
  288. package/dist/{index-g4gstmp1.js → index-ednf2cxs.js} +1 -1
  289. package/dist/{index-84tp547a.js → index-edpkm3k7.js} +29 -97
  290. package/dist/{index-gs0jw0hy.js → index-efbzm2se.js} +3 -3
  291. package/dist/{index-asnd4h2k.js → index-f0dzyskg.js} +27 -4
  292. package/dist/{index-xbb8ysmq.js → index-fatke81t.js} +2 -2
  293. package/dist/{index-d3s070eh.js → index-gj4wdts6.js} +1 -1
  294. package/dist/{index-6nzzj7qr.js → index-gq35s3bm.js} +1 -1
  295. package/dist/index-gvgtmt7a.js +102 -0
  296. package/dist/{index-pd9e8rz4.js → index-gvv7y0s4.js} +1 -1
  297. package/dist/{index-m2b49tvc.js → index-h08xqfw9.js} +20 -21
  298. package/dist/{index-gk6dq9ay.js → index-ha1tv70k.js} +3 -26
  299. package/dist/{index-vebzvse6.js → index-jy907kcs.js} +24 -1
  300. package/dist/{index-q86qnzzf.js → index-k5azb3v3.js} +8 -25
  301. package/dist/{index-qcy8et93.js → index-kaq9nb7h.js} +6 -6
  302. package/dist/{index-vse7x1qt.js → index-knqye3gv.js} +1 -1
  303. package/dist/{index-tav72wz5.js → index-ks4rhtcc.js} +5 -0
  304. package/dist/{index-bvpevwt6.js → index-mtpcax6d.js} +210 -205
  305. package/dist/{index-7qza24g1.js → index-px9r6wv1.js} +1 -1
  306. package/dist/{index-x6sp5vpa.js → index-q4tr9vnf.js} +1 -1
  307. package/dist/{index-hce3hbdg.js → index-qj0sq69b.js} +6 -2
  308. package/dist/{index-de7b0kvz.js → index-r9w7wfgn.js} +2 -2
  309. package/dist/{index-8vzh5wpv.js → index-rw1caff2.js} +14 -26
  310. package/dist/index-s8af9jqw.js +6 -0
  311. package/dist/{index-bgj9hbm3.js → index-sdppfbrh.js} +30 -16
  312. package/dist/{index-aacwkve4.js → index-sjq4akrx.js} +3 -5
  313. package/dist/{index-fec05c9k.js → index-ta0e2daw.js} +9 -7
  314. package/dist/{index-5dxgx3yj.js → index-tcv71frn.js} +1 -1
  315. package/dist/{index-1zy31r3b.js → index-v92djygb.js} +1 -1
  316. package/dist/{index-c0yym4a0.js → index-w7e402wx.js} +11 -105
  317. package/dist/{index-9f60gnfn.js → index-xaa3603f.js} +4 -11
  318. package/dist/index-xrbrvn15.js +147 -0
  319. package/dist/{index-ac3rfec5.js → index-y6wzzk2e.js} +21 -1
  320. package/dist/{index-3d2c45jn.js → index-yjx5jna7.js} +2 -2
  321. package/dist/{index-j3r7r1mh.js → index-yv7d6tav.js} +1 -1
  322. package/dist/{index-wsv11dhg.js → index-zagc12j1.js} +5 -5
  323. package/dist/{index-npfdymav.js → index-zqc64g69.js} +3 -3
  324. package/dist/{index-rkphknhx.js → index-zthekmrt.js} +2 -2
  325. package/dist/internal/json-stringify.d.ts +37 -0
  326. package/dist/internal/json-stringify.d.ts.map +1 -0
  327. package/dist/internal/loopback-host.d.ts +8 -0
  328. package/dist/internal/loopback-host.d.ts.map +1 -0
  329. package/dist/internal/own-member.d.ts +7 -0
  330. package/dist/internal/own-member.d.ts.map +1 -0
  331. package/dist/internal/request.d.ts +17 -8
  332. package/dist/internal/request.d.ts.map +1 -1
  333. package/dist/internal/secret-shapes.d.ts +33 -4
  334. package/dist/internal/secret-shapes.d.ts.map +1 -1
  335. package/dist/json-schema/dialect.d.ts.map +1 -1
  336. package/dist/json-schema/keywords.d.ts +25 -6
  337. package/dist/json-schema/keywords.d.ts.map +1 -1
  338. package/dist/json-schema/string-format.d.ts.map +1 -1
  339. package/dist/live/events.d.ts.map +1 -1
  340. package/dist/live/watch-client.d.ts.map +1 -1
  341. package/dist/live/watch-delta.d.ts.map +1 -1
  342. package/dist/observability/context.d.ts +4 -3
  343. package/dist/observability/context.d.ts.map +1 -1
  344. package/dist/observability/sanitize.d.ts.map +1 -1
  345. package/dist/observability/secret-values.d.ts +0 -9
  346. package/dist/observability/secret-values.d.ts.map +1 -1
  347. package/dist/server/context.d.ts +3 -2
  348. package/dist/server/context.d.ts.map +1 -1
  349. package/dist/server/error-hook.d.ts +4 -3
  350. package/dist/server/error-hook.d.ts.map +1 -1
  351. package/dist/server/event-bus.d.ts.map +1 -1
  352. package/dist/server/file.d.ts +11 -3
  353. package/dist/server/file.d.ts.map +1 -1
  354. package/dist/server/handler-state.d.ts +2 -2
  355. package/dist/server/handler-state.d.ts.map +1 -1
  356. package/dist/server/middleware/jwt.d.ts +12 -1
  357. package/dist/server/middleware/jwt.d.ts.map +1 -1
  358. package/dist/server/middleware/trust-fence.d.ts +4 -0
  359. package/dist/server/middleware/trust-fence.d.ts.map +1 -1
  360. package/dist/server/multipart.d.ts +2 -3
  361. package/dist/server/multipart.d.ts.map +1 -1
  362. package/dist/server/raw.d.ts.map +1 -1
  363. package/dist/server/request-body.d.ts +12 -1
  364. package/dist/server/request-body.d.ts.map +1 -1
  365. package/dist/server/request-completion.d.ts.map +1 -1
  366. package/dist/server/types.d.ts +14 -9
  367. package/dist/server/types.d.ts.map +1 -1
  368. package/dist/telegram/crypto.d.ts.map +1 -1
  369. package/dist/telegram/init-data.d.ts +4 -4
  370. package/dist/telegram/init-data.d.ts.map +1 -1
  371. package/dist/telegram/outbound-cost.d.ts.map +1 -1
  372. package/dist/telegram/screens/test-chat.d.ts.map +1 -1
  373. package/dist/telegram/widget-api.d.ts +85 -13
  374. package/dist/telegram/widget-api.d.ts.map +1 -1
  375. package/dist/telegram/widget.d.ts +46 -2
  376. package/dist/telegram/widget.d.ts.map +1 -1
  377. package/dist/tools/cli/args-classify.d.ts +4 -74
  378. package/dist/tools/cli/args-classify.d.ts.map +1 -1
  379. package/dist/tools/cli/args-framework.d.ts +79 -0
  380. package/dist/tools/cli/args-framework.d.ts.map +1 -0
  381. package/dist/tools/cli/args-scan.d.ts.map +1 -1
  382. package/dist/tools/cli/args-tokens.d.ts.map +1 -1
  383. package/dist/tools/cli/checkpoint.d.ts +5 -0
  384. package/dist/tools/cli/checkpoint.d.ts.map +1 -1
  385. package/dist/tools/cli/stream.d.ts.map +1 -1
  386. package/dist/tools/connections/foreign-schema-join.d.ts.map +1 -1
  387. package/dist/tools/connections/openapi.d.ts.map +1 -1
  388. package/dist/tools/connections/runtime.d.ts.map +1 -1
  389. package/dist/tools/execute-handler.d.ts +24 -0
  390. package/dist/tools/execute-handler.d.ts.map +1 -0
  391. package/dist/tools/execute.d.ts.map +1 -1
  392. package/dist/tools/mcp/round.d.ts.map +1 -1
  393. package/dist/tools/schema/coerce.d.ts.map +1 -1
  394. package/dist/tools/schema/flatten.d.ts.map +1 -1
  395. package/dist/tools/schema/inline-references.d.ts.map +1 -1
  396. package/dist/tools/schema/nesting-limit.d.ts.map +1 -1
  397. package/dist/tools/schema/presentation.d.ts.map +1 -1
  398. package/dist/tracking/privacy.d.ts.map +1 -1
  399. package/llms/agent-runtime-openrouter.txt +10 -9
  400. package/llms/agent-runtime-sandbox.txt +50 -11
  401. package/llms/agent-runtime-testing.txt +1 -1
  402. package/llms/agent-runtime.2.txt +9 -6
  403. package/llms/agent-runtime.3.txt +2 -2
  404. package/llms/agent-runtime.4.txt +11 -5
  405. package/llms/agent-runtime.5.txt +2 -2
  406. package/llms/agent-runtime.txt +297 -36
  407. package/llms/application.2.txt +6 -3
  408. package/llms/application.3.txt +2 -1
  409. package/llms/application.txt +7 -2
  410. package/llms/http.txt +1 -1
  411. package/llms/live.txt +3 -1
  412. package/llms/observability.txt +16 -9
  413. package/llms/server.2.txt +13 -8
  414. package/llms/server.4.txt +23 -11
  415. package/llms/server.5.txt +5 -5
  416. package/llms/server.txt +54 -1
  417. package/llms/spend.txt +1 -0
  418. package/llms/stitchkit.2.txt +4 -2
  419. package/llms/stitchkit.txt +113 -93
  420. package/llms/telegram-grammy.txt +3 -2
  421. package/llms/telegram.2.txt +3 -1
  422. package/llms/telegram.txt +35 -10
  423. package/llms/upgrading-0.128.0-0.129.0.txt +175 -0
  424. package/llms/{upgrading-0.128.0-0.135.0.txt → upgrading-0.130.0-0.136.0.txt} +353 -169
  425. package/llms/upgrading.txt +2 -1
  426. package/llms-full.txt +1021 -223
  427. package/llms.txt +14 -13
  428. package/package.json +6 -6
  429. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts +0 -19
  430. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts.map +0 -1
  431. package/dist/agent-runtime/loop/run-complete-retry.d.ts +0 -24
  432. package/dist/agent-runtime/loop/run-complete-retry.d.ts.map +0 -1
  433. package/dist/agent-runtime/loop/run-model-attempts.d.ts +0 -6
  434. package/dist/agent-runtime/loop/run-model-attempts.d.ts.map +0 -1
  435. package/dist/index-sznqf8fx.js +0 -20
  436. /package/dist/{index-fthw8dwa.js → index-4gbybjg6.js} +0 -0
package/llms/server.4.txt CHANGED
@@ -311,7 +311,11 @@ Use it as `createMcpHandler`'s `auth`, or inside `createAuthHook`'s `resolve`.
311
311
 
312
312
  `verifyJwt(token, secret)` verifies an HS256 JWT and returns its payload, or
313
313
  throws `unauthorized`. It pins the algorithm (the token's own `alg` can never
314
- pick the scheme), and checks `exp` and `nbf`.
314
+ pick the scheme), checks `exp` and `nbf`, and **requires `exp`**: a token
315
+ without one would stay valid for as long as the secret does. Pass
316
+ `expiration: 'optional'` only for tokens whose lifetime you bound elsewhere (a
317
+ session row, a revocation list); a present `exp` is still enforced. Sign with
318
+ `signJwt(payload, secret, { expiresInSec })`.
315
319
 
316
320
  ```ts
317
321
  import { verifyJwt, extractToken } from 'stitchkit/server'
@@ -378,7 +382,7 @@ import { env } from './env'
378
382
  const result = await verifyTelegramInitData({
379
383
  initData,
380
384
  botToken: env.BOT_TOKEN,
381
- maxAgeSeconds: 3600, // a signed string is otherwise valid forever
385
+ maxAgeSeconds: 3600, // default: one day
382
386
  })
383
387
  if (!result.valid) {
384
388
  // 'missing-hash' | 'signature-mismatch' | 'malformed' | 'expired'
@@ -401,9 +405,10 @@ A bot meets the same person as grammY's `ctx.from`, in Telegram's `snake_case`;
401
405
  `parseTelegramUser(ctx.from)` gives the same `TelegramUser`, so one
402
406
  `ensureAccount(user)` serves the Mini App and the chat.
403
407
 
404
- `maxAgeSeconds` is optional and there is no default: only the application knows
405
- how long its own session is worth. Omitting it means the string never expires,
406
- which is a decision rather than an oversight.
408
+ `maxAgeSeconds` defaults to one day (`86400`): a signed string is otherwise a
409
+ credential that never expires, so there is no unbounded mode. Set the lifetime
410
+ your session is worth — shorter for a sign-in exchange, longer for a Mini App
411
+ kept open for days.
407
412
 
408
413
  The module is server-only and pulls in no bot library — the token never belongs
409
414
  in a browser bundle. `stitchkit/application/grammy` remains the lifecycle
@@ -866,21 +871,28 @@ const onError = createErrorHook({
866
871
  Synchronous callbacks and renderers that declare fewer parameters continue to
867
872
  work normally.
868
873
 
869
- Invalid input (a `ZodError`) is classified as `VALIDATION_ERROR` 400 before it
870
- reaches `render` — a client fault is an honest 400, not a 500 — and the
874
+ Input that fails the contract's `params` / `input` schema reaches `render` as
875
+ `VALIDATION_ERROR` 400 — a client fault is an honest 400, not a 500 — and the
871
876
  offending fields arrive as structured `info.details.issues`, so your `render`
872
877
  can surface them to a machine client without parsing the message.
873
878
 
879
+ Only the contract boundary produces `VALIDATION_ERROR`. A `ZodError` your
880
+ handler throws — parsing an upstream answer, a database row, a config value —
881
+ is the server's own schema failing: it is answered as `INTERNAL_SERVER_ERROR`
882
+ 500 with the generic message, and the `ZodError` text goes to the log and the
883
+ audit row, never to the caller. To refuse the caller's input from inside a
884
+ handler, throw `badRequest(message, details)` (or an `AppError`) yourself.
885
+
874
886
  If you write a **bespoke** `onError` instead of using `createErrorHook`, run the
875
- thrown value through the exported `normalizeError` to get the same classification
876
- (a raw `ZodError` reaches your hook untouched, so the framework can inspect it —
877
- call `zodIssues(err)` yourself if you want the structured fields):
887
+ thrown value through the exported `normalizeError` to get the same classification.
888
+ Invalid input reaches your hook as an `AppError` with code `VALIDATION_ERROR`,
889
+ its `details.issues` and the `ZodError` as `cause`:
878
890
 
879
891
  ```ts
880
892
  import { normalizeError } from 'stitchkit/server'
881
893
 
882
894
  onError: (ctx, err) => {
883
- const e = normalizeError(err) // ZodError → VALIDATION_ERROR 400, else generic 500
895
+ const e = normalizeError(err) // AppError as is (VALIDATION_ERROR 400 for input), else generic 500
884
896
  return jsonError(e.code, e.status, e.message)
885
897
  }
886
898
  ```
package/llms/server.5.txt CHANGED
@@ -52,7 +52,7 @@ Also re-exports the error helpers from `stitchkit/contract`.
52
52
  | `RegistryHandlers` | _type_ | exact backend handler registry inferred from a contract registry |
53
53
  | `ExactRegistryHandlers` | _type_ | fail-first handler shape that rejects extra registry and endpoint keys |
54
54
  | `staticRoute` | function | a raw route that serves a contained directory through `serveFile` (`Range` / `304` / validators) |
55
- | `StaticRouteOptions` | _type_ | `{ cacheControl }` — what `staticRoute` adds to every file it serves |
55
+ | `StaticRouteOptions` | _type_ | `{ cacheControl, allowedDotNames }` — what `staticRoute` adds to every file it serves, and which dot-segment names it serves (none by default) |
56
56
  | `serveFile` | function | serve a file with `Range` / `304` / `HEAD` — [guide](../guide/server.md#serving-files--range-requests) |
57
57
  | `parseByteRange` | function | parse a single `Range` header → range / `unsatisfiable` / `null` |
58
58
  | `isWithinDir` | function | path containment — `(root, resolvedTarget) => boolean`; call it before `serveFile` on any URL-derived path |
@@ -61,7 +61,7 @@ Also re-exports the error helpers from `stitchkit/contract`.
61
61
  | `ByteRange` | _type_ | an inclusive `{ start, end }` byte range |
62
62
  | `respondJson` | function | a raw route's JSON response (`204` for null/undefined) |
63
63
  | `errorResponse` | function | any thrown value → the framework error envelope + `x-request-id` |
64
- | `normalizeError` | function | any thrown value → an `AppError` (`ZodError` → `VALIDATION_ERROR` 400 with structured `details.issues`, else generic 500) — the framework's canonical classification, for a bespoke `onError` |
64
+ | `normalizeError` | function | any thrown value → an `AppError` (an `AppError` as is — contract input failures arrive as `VALIDATION_ERROR` 400 with structured `details.issues`; anything else, a `ZodError` from handler code included, generic 500) — the framework's canonical classification, for a bespoke `onError` |
65
65
  | `NormalizeErrorOptions` | _type_ | `logUnexpected` defaults to logging the raw server-side cause; tool adapters disable process dumps while their existing observers retain that cause |
66
66
  | `errorCode` | function | the stable error code for a thrown value (side-effect-free — for log attribution) |
67
67
  | `formatZodError` | function | a `ZodError` → a readable, field-summarised string |
@@ -110,7 +110,7 @@ Also re-exports the error helpers from `stitchkit/contract`.
110
110
  | `ResolvedError` | _type_ | the normalised error handed to `createErrorHook`'s `render` |
111
111
  | `createBearerResolver` | function | a bearer-token identity resolver |
112
112
  | `signJwt` | function | sign an HS256 JWT |
113
- | `VerifyJwtOptions` | _type_ | options for `verifyJwt` |
113
+ | `VerifyJwtOptions` | _type_ | options for `verifyJwt` — `leewaySeconds`, `issuer`, `audience`, `expiration` (`'required'` by default) |
114
114
  | `verifyJwt` | function | verify an HS256 JWT |
115
115
  | `signLink` / `SignLinkOptions` | function / _type_ | a short-lived link for a request that cannot carry a header (`<audio src>`, `<img src>`): appends `expires` and an HMAC-SHA-256 `signature` over the method, path and every query parameter — [guide](../guide/auth-and-errors.md#signed-links) |
116
116
  | `verifySignedLink` / `VerifySignedLinkOptions` | function / _type_ | check a request against its link (signature compared with a constant-time comparison, then expiry); call it from `createAuthHook`'s `resolve` or a raw route |
@@ -221,11 +221,11 @@ Also re-exports the error helpers from `stitchkit/contract`.
221
221
  | `resolveTraceId` | function | the default per-request trace-id resolver |
222
222
  | `extractIp` | function | the caller IP from a request |
223
223
  | `isPublicIp` | function | whether an address belongs to the public internet; anything unparseable is not |
224
- | `resolveSocketIp` | function | the caller IP for a Socket.IO handshake (proxy-aware) |
224
+ | `resolveSocketIp` | function | the real socket peer IP from the runtime (`server.requestIP` on Bun, `req.ip` under `srvx`); headers are not read |
225
225
  | `getClientInfo` | function | caller IP + user-agent |
226
226
  | `EventBus` | _type_ | the `createEventBus` handle |
227
227
  | `RateLimitConfig` | _type_ | config for `createRateLimiter` |
228
- | `ClientIpOptions` | _type_ | trusted-proxy config for `extractIp` / `resolveSocketIp` |
228
+ | `ClientIpOptions` | _type_ | socket peer and trusted-proxy config for `extractIp` / `getClientInfo` |
229
229
  | `StreamingRouteOptions` | _type_ | options for `streamingRoute` / `ndjsonRoute` / `sseRoute` |
230
230
  | `StreamingSourceContext` | _type_ | what a streaming source is given, including the cancellation `signal` |
231
231
  | `StreamingFormat` | _type_ | `'ndjson' \| 'sse'` |
package/llms/server.txt CHANGED
@@ -151,8 +151,10 @@ To type `ctx` with your app's extras (the user an auth hook injects), fix the
151
151
  context type once:
152
152
 
153
153
  ```ts
154
+ import type { RuntimeContext } from 'stitchkit'
154
155
  import { createImplement } from 'stitchkit/server'
155
156
 
157
+ interface User { id: string; name: string }
156
158
  interface AppContext extends RuntimeContext { user: User | null }
157
159
 
158
160
  export const implement = createImplement<AppContext>()
@@ -168,7 +170,20 @@ there. `createScopedImplement` types each handler by its endpoint's **effective*
168
170
  scope instead — the endpoint's own `scope`, else the contract's:
169
171
 
170
172
  ```ts
173
+ import { defineContract } from 'stitchkit'
171
174
  import { createScopedImplement } from 'stitchkit/server'
175
+ import { z } from 'zod'
176
+
177
+ const Post = z.object({ id: z.string(), title: z.string() })
178
+
179
+ const postsContract = defineContract({ prefix: 'posts', scope: 'user' }, {
180
+ list: { method: 'GET', path: '/', desc: 'List my posts', output: z.array(Post) },
181
+ purge: { method: 'DELETE', path: '/', desc: 'Purge all posts', scope: 'admin', output: z.array(Post) },
182
+ ping: { method: 'GET', path: '/ping', desc: 'Health check', scope: 'public', output: z.object({ ok: z.boolean() }) },
183
+ })
184
+
185
+ declare function listPosts(userId: string): Array<z.infer<typeof Post>>
186
+ declare function purge(): Array<z.infer<typeof Post>>
172
187
 
173
188
  export const implementFor = createScopedImplement<{
174
189
  public: object // no extra fields
@@ -344,7 +359,7 @@ server. See [Testing & deployment](./testing-and-deployment.md).
344
359
  | `groups` | route groups — a shared path prefix and hooks (see below) |
345
360
  | `scopePrefixes` | `scope → path prefix` map — mount `services` by `service.scope` (see below) |
346
361
  | `rawRoutes` | non-contract routes (see below) |
347
- | `maxJsonBodyBytes` | optional JSON body cap (bytes); per-route value overrides; unset preserves existing behaviour |
362
+ | `maxJsonBodyBytes` | JSON body cap in bytes, **1 MiB by default**; a per-route value overrides it; a larger body is refused with `400 BAD_REQUEST` before it is buffered or parsed |
348
363
  | `port` / `hostname` | listen address — port defaults to `3000` |
349
364
  | `unix` | listen on a unix domain socket instead of TCP — `'/run/app.sock'` or `{ path, mode }` (see below) |
350
365
  | `cors` | CORS policy — `{ origin, credentials, methods, headers, exposeHeaders }`. `origin` is **required** when `cors` is present: pass an explicit origin (or list), or `'*'` to deliberately allow every origin — an origin-less config is a construction error, never a silent wildcard. `origin` may also be a function that answers each request origin with or without credentials ([below](#cors-decided-per-request)). Omit `cors` entirely to emit no CORS headers. |
@@ -352,6 +367,7 @@ server. See [Testing & deployment](./testing-and-deployment.md).
352
367
  | `logging` | `true` for built-in request logs, or a `LoggingConfig` (see below) |
353
368
  | `traceId` | override per-request trace-id resolution — may return `undefined` to fall back |
354
369
  | `wrapFetch` | compose wrappers around the finished handler (request context, audit) |
370
+ | `trustProxy` | client IP behind proxies you run: `{ trustedPeer(address) }`; `x-forwarded-for` is read right to left from a trusted socket peer ([below](#client-ip-behind-a-proxy)); unset, `ctx.ipAddress` is the socket peer |
355
371
  | `proxyOrigin` | Bun TCP ingress policy: `{ trustedPeer(socketIp) }` restores the external scheme before all composition; independent of client-IP `trustProxy` |
356
372
  | `socket` | full StitchKit Socket.IO handle; route, default WebSocket handler and shutdown are mounted once |
357
373
  | `websocket` | custom Bun WebSocket handler; with `socket`, this is the explicit composed handler |
@@ -402,6 +418,43 @@ createServer({
402
418
  - A `safelistedBody` endpoint reads a `text/plain` body only from an origin
403
419
  granted with credentials ([below](#safelisted-request-bodies-beacons)).
404
420
 
421
+ ### Client IP behind a proxy
422
+
423
+ Without `trustProxy`, `ctx.ipAddress` is the real socket peer and no header can
424
+ change it. Behind a reverse proxy that peer is the proxy, so name the proxies you
425
+ run:
426
+
427
+ ```ts
428
+ import { createServer, isLoopbackAddress } from 'stitchkit/server'
429
+
430
+ const server = createServer({
431
+ hostname: '127.0.0.1',
432
+ trustProxy: { trustedPeer: isLoopbackAddress }, // nginx on this host
433
+ services,
434
+ })
435
+ ```
436
+
437
+ `x-forwarded-for` is read only when the socket peer is a trusted proxy, and then
438
+ from the **right**: each proxy appends the address it received the request from,
439
+ so the rightmost entries are written by your proxies and the leftmost by the
440
+ client. The first address `trustedPeer` does not accept is the client; when every
441
+ hop is trusted, the leftmost one is. A hop that is not an IP address makes the
442
+ client unknown (`ctx.ipAddress` is `undefined`), never a guess. `x-real-ip` is
443
+ not read — it carries no chain to check.
444
+
445
+ The proxy must **append** (nginx: `proxy_set_header X-Forwarded-For
446
+ $proxy_add_x_forwarded_for;`). For a chain of proxies, `trustedPeer` accepts each
447
+ of them — a CIDR check for an internal network, for example. The same option
448
+ exists on `wrapInRequestContext` and on `extractIp` / `getClientInfo`, which also
449
+ need the real peer: pass `socketIp: resolveSocketIp(req, server)`; without it the
450
+ header is ignored and the answer is `''`.
451
+
452
+ ⚠️ **A proxy on the same host makes every request loopback.** Without
453
+ `trustProxy`, a server behind nginx on `127.0.0.1` sees `127.0.0.1` as the peer of
454
+ every visitor, so a rule like `isLoopbackAddress(ctx.ipAddress)` admits the whole
455
+ internet. Either configure `trustProxy` so the visitor's address is resolved, or
456
+ listen where the proxy cannot forward the privileged operation.
457
+
405
458
  ### External origin behind a trusted proxy
406
459
 
407
460
  An HTTPS ingress often forwards plain HTTP to Bun. `trustProxy` trusts client-IP
package/llms/spend.txt CHANGED
@@ -142,6 +142,7 @@ test('every model call goes through the spend gateway', async () => {
142
142
  module: 'stitchkit/agent-runtime/openrouter',
143
143
  symbols: [
144
144
  'openRouterProvider',
145
+ 'createOpenRouterClient',
145
146
  'openRouterRequestJson',
146
147
  'openRouterRequestStream',
147
148
  'openRouterSystemOne',
@@ -712,7 +712,7 @@ call, over HTTP or a Unix socket alike:
712
712
  import { withContractIdentity } from 'stitchkit/server'
713
713
  createServer({ services: withContractIdentity(services) })
714
714
 
715
- // client
715
+ // client (`stitchkit/http` exports the same function for React Native/Hermes)
716
716
  import { readContractIdentity } from 'stitchkit'
717
717
  const { client, server } = await readContractIdentity(contracts, config)
718
718
  if (server === undefined) {
@@ -1049,7 +1049,9 @@ character split across chunks is never torn. A line that crosses `maxLineBytes`
1049
1049
  retains at most the limit, however long the line. With `finalLine: 'require-newline'`, a source
1050
1050
  that ends inside a line throws `StreamTruncatedLineError` (`lineBytes`) instead of yielding the
1051
1051
  fragment as a value — the right policy for a socket or a child process, where a missing newline
1052
- means the writer died. Both errors extend the `RangeError` / `SyntaxError` they replace.
1052
+ means the writer died. Both errors extend the `RangeError` / `SyntaxError` they replace, and
1053
+ both are exported from `stitchkit` and `stitchkit/http`, so a React Native client checks a contract
1054
+ stream's failure without importing the root entry.
1053
1055
 
1054
1056
  ## Reading a body up to a byte limit
1055
1057
 
@@ -56,87 +56,87 @@ own, recorded as an ADR.
56
56
 
57
57
  | Import | Use in | Maturity | Holds |
58
58
  |--------|--------|----------|-------|
59
- | `stitchkit` | browser **and** server | stable<br>_redefined in 6 of the 42 minors since 0.94.0, most recently 0.135.0_ | `defineContract`, `createClient`, `createHttpClient`, `createSocketIOClient`, `parseSSE`, the error model |
60
- | `stitchkit/http` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.135.0_ | typed HTTP client factories and `ApiError`, without optional realtime peers |
61
- | `stitchkit/realtime` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | typed realtime clients, binding to an existing socket and retained topics with a required explicit Socket.IO peer loader |
62
- | `stitchkit/device-relay` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 0 of the 2 minors since 0.134.0_ | peer-free User Device Relay over realtime — `createDeviceRelayHub`, `createDeviceRelayAgent`, `createMemoryRelayBroker`, `deviceRelayRealtimeContract`, Fetch-compatible unary RPC and credit-paced cursor streams |
63
- | `stitchkit/contract` | browser **and** server | stable<br>_redefined in 5 of the 42 minors since 0.94.0, most recently 0.127.0_ | the contract layer alone — `defineContract`, errors, pagination |
64
- | `stitchkit/live` | browser **and** server | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.127.0_ | `defineEvents` — topic declarations beside the operation contract — and watched reads: `createWatchClient`, the value/difference frame and its reassembly |
65
- | `stitchkit/primitives` | browser **and** server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | generic values and declarations for lifecycle, access, audit, delivery and exports, exact money and rounding tables |
66
- | `stitchkit/handler` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | portable `createHandler`, `implement`, errors and `serveBridge` over a string `postMessage` port, with no Node built-ins |
67
- | `stitchkit/server` | server (Bun) | stable<br>_redefined in 5 of the 42 minors since 0.94.0, most recently 0.127.0_ | `createServer`, `implement`, hooks, auth, Socket.IO server, server primitives |
68
- | `stitchkit/node` | server (Node ≥ 22.3) | stable<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.127.0_ | `serveNode` + the runtime-agnostic core — the Node mirror of `/server` |
69
- | `stitchkit/tools` | server | stable<br>_redefined in 12 of the 42 minors since 0.94.0, most recently 0.135.0_ | the transport-neutral tool layer — `mountAgentTools`, `defineAgentTool`, registry, tool names and manifest, runtime tools, native tools, the OAuth provider, the durability engine; loads no optional peer at runtime |
70
- | `stitchkit/tools/mcp` | server (Bun or Node) | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | the canonical MCP HTTP/stdio server, schemas and typed MCP presenters; only Zod and the MCP server SDK peers |
71
- | `stitchkit/tools/agent` | server (Bun or Node) | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.134.0_ | `mountAgent` — thin AI SDK `ToolSet` adapter over `mountAgentTools` for apps driving their own SDK loop; only Zod and the `ai` peer |
72
- | `stitchkit/tools/toolkit` | server (Bun or Node) | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.135.0_ | `createToolkit` — context-pinned MCP, peer-free agent (`mountAgentTools`), and CLI mounts; only the MCP server SDK peer (no `ai` peer) |
73
- | `stitchkit/tools/contract` | browser + server | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.124.0_ | the shapes a tool surface speaks — async-operation contract, snapshot and cancel schemas, view-file input/output — without the runtime that serves them |
74
- | `stitchkit/tools/invoker` | server | stable<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | peer-free `createToolInvoker` over the canonical contract tool runner |
75
- | `stitchkit/tools/connections` | server (Bun or Node) | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | consume external MCP servers and a bounded OpenAPI subset — typed reauthorization, a per-request host fence and per-call credentials |
76
- | `stitchkit/cli` | server | stable<br>_redefined in 12 of the 42 minors since 0.94.0, most recently 0.128.0_ | `createCli` / `createCliInvoker` — runtime and strict NodeNext declarations without MCP SDK / `ai` |
77
- | `stitchkit/cli/publish` | build and release tooling (Bun or Node, POSIX) | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | `publishCli` — commit a verified CLI distribution and move its public manifest last; see [CLI guide](cli.md#publishing-a-complete-version) |
78
- | `stitchkit/remote` | browser **and** server | stable<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.104.0_ | peer-free `implementRemote` for thin HTTP proxy processes |
79
- | `stitchkit/process` | server (Bun or Node, POSIX) | evolving<br>_redefined in 4 of the 42 minors since 0.94.0, most recently 0.133.0_ | finite native commands, byte sinks, bounded capture, process-group cancellation and opt-in Linux/Darwin owner-loss cleanup; contract operations executed in one-call child processes |
80
- | `stitchkit/process/bootstrap` | bundled server entry (Bun, POSIX) | evolving<br>_redefined in 0 of the 3 minors since 0.133.0_ | narrow bootstrap that keeps the process runner lazy while carrying the package's own invocations — the owner-loss guard and the process root of launched work — in a single-file bundle |
81
- | `stitchkit/files/packaging` | build time (Bun or Node) | evolving<br>_redefined in 4 of the 42 minors since 0.94.0, most recently 0.133.0_ | installed native asset graph, integrity, Bun packaging plugin and the artifact loader check; a client bundled into one self-contained, hashed file; a typed client built into a proven npm package with several entries, declarations and external peers; no runtime install policy |
82
- | `stitchkit/files` | server (Bun or Node) | stable<br>_redefined in 5 of the 42 minors since 0.94.0, most recently 0.133.0_ | peer-free managed local-file boundary |
83
- | `stitchkit/spend` | server (Bun or Node) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | peer-free spend gateway for paid model APIs: the attempt recorded before the call and closed on every outcome, credentials only for the provider's origin, a spooled ledger, rank-merged receipts and a reconciler |
84
- | `stitchkit/spend/testing` | tests on Bun or Node | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | the coverage guard: red on a model SDK import, a provider key or a provider host outside the gateway files |
85
- | `stitchkit/service-host` | server (Bun or Node) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | peer-free host service supervision — verified versioned artifact activation, Linux `systemd` and macOS `launchd` units (`plutil`, `bootout`/`bootstrap`, rollback), live process/Unix-socket identity verification, and an in-process config-watched reloader |
86
- | `stitchkit/service-host/macos` | server (Bun or Node, macOS) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | peer-free macOS daemon bundle toolkit — fail-closed Developer ID `codesign`, strict C11 launcher `.app` bundles with atomic `RENAME_SWAP` install/rollback, Apple 824×824 squircle `AppIcon.icns`, streaming `lsregister` maintenance, and TCC responsibility inspection |
87
- | `stitchkit/service-host/work` | server (Bun or Node; Linux with systemd ≥ 254, or a process root on Linux and macOS) | evolving<br>_redefined in 0 of the 3 minors since 0.133.0_ | peer-free launch of work in its own boundary with a declared owner — a transient systemd scope or a recorded process root, the typed owner record, the one inherited variable that names the boundary, and the membership check that asks the boundary; see [native I/O](native-io.md#work-in-its-own-boundary) |
88
- | `stitchkit/telegram` | server (Bun or Node) | evolving<br>_redefined in 8 of the 42 minors since 0.94.0, most recently 0.127.0_ | peer-free Telegram platform primitives — Mini App `initData` verification, widget limits and the `widget_query` and widget message schemas, send-failure classification, one outbound budget per bot token with weighted albums and per-chat 429 pauses, resumable broadcasts, the operator channel with dedupe, a Bot API transport that separates a request that never left from an unknown outcome, local Bot API files, the waveform of a voice message read from its PCM, webhook ownership and durable webhook update intake |
89
- | `stitchkit/telegram/grammy` | server (Bun or Node) | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the token's outbound budget as one grammY client transformer — a 429 that comes back as a response pauses its chat, and a cancelled wait is a request that never left; the widget methods over the same client |
90
- | `stitchkit/telegram/html` | browser and server | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | Telegram's HTML as a tree — compile GFM Markdown to Telegram HTML with fence-aware splitting, clean any markup to what Telegram accepts, cut long text into valid parts by what the reader sees, check markup before it is sent |
91
- | `stitchkit/telegram/voice` | browser and server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the waveform of a voice message as one format — packed for `sendVoice` the way Telegram Desktop scales it, unpacked to draw it, a `getMe` read of whether the server takes it |
92
- | `stitchkit/telegram/screens` | server (Bun or Node) | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | a bot's menus as declared screens over grammY — typed paths, actions and input, message reconciliation, state in any `StorageAdapter`, a test chat |
93
- | `stitchkit/tracking` | browser **and** server | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | visitor-tracking mechanics — `createTrackingClient`, the tab-shared outbox, the page-leave beacon, attribution, the contract factory; no event vocabulary, no React |
94
- | `stitchkit/tracking/contract` | browser **and** server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the wire shapes — the contract factory, event and visit schemas, the performance sample and its trust threshold; brings `zod` |
95
- | `stitchkit/tracking/performance` | browser **and** server | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | Web Vitals from real visitors, collected after load through the optional peer `web-vitals`; no `zod` |
96
- | `stitchkit/tracking/server` | server (Bun or Node) | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the decisions a tracking backend makes — dispositions, visit lease over an application-owned store, active intervals, presence; no database |
97
- | `stitchkit/release` | browser **and** server | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | a page follows the release it was built for — `createReleaseMarker` on the server, `createReleaseWatcher` in the browser, the `X-Build-Id` header and a socket event between them |
98
- | `stitchkit/voice` | browser **and** server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the mechanics of a live voice reply — `SentenceCutter`, `speakableText`, a `SpeechQueue` that synthesises ahead and stops on interruption, the conversation phases |
99
- | `stitchkit/sync` | browser **and** server | evolving<br>_redefined in 1 of the 9 minors since 0.127.0, most recently 0.132.0_ | the client half of an offline-first sync — which outbox rows leave next, pending edits on top of remote rows, deletes that win until acknowledged, the cursor session, the push and page wire with an open outcome vocabulary; no driver, runs in Hermes |
100
- | `stitchkit/sync/postgres` | server (Bun or Node) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | the server half — versions that commit in order, a ledger that runs each change once, a feed of what changed, inside the app's own transaction; a memory store and `checkSyncStore` |
101
- | `stitchkit/geo` | server (Bun or Node) | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.127.0_ | managed GeoIP reader generations, last-known-good reload and the optional MaxMind adapter |
102
- | `stitchkit/geo/contract` | browser **and** server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the place snapshot schema, for a shared contract that stores or sends `GeoAttribution`; brings `zod` |
103
- | `stitchkit/xlsx` | browser **and** server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | a workbook from rows and typed columns, with no dependency; text never runs as a formula |
104
- | `stitchkit/oauth` | browser **and** server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | provider-neutral Authorization Code + PKCE request and one-shot callback transaction mechanics |
105
- | `stitchkit/google` | server (Bun or Node) | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | optional Google code exchange and verified OIDC identity adapter |
106
- | `stitchkit/observability` | server | stable<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | request/tool event projections — `createObservability`, trace context, sanitisation |
107
- | `stitchkit/testing` | tests on Bun or Node | stable<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | in-process generated clients over a real Fetch handler, the managed-resource conformance kit and manual time for schedules and retries |
108
- | `stitchkit/declaration` | browser + build and deployment tooling (Bun or Node) | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.128.0_ | `ProjectDeclarationSchema` — the one machine-readable statement a repository makes about itself |
109
- | `stitchkit/react` | browser + server rendering | stable<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.127.0_ | `createCursorQuery`, `createCacheBridge`, QueryClient and `ApiError` retry policy |
110
- | `stitchkit/react/keyboard` | browser | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.115.0_ | which part of a screen gets a key — ordered layers, one Escape per level, list zones with real focus; see [keyboard guide](keyboard.md) |
111
- | `stitchkit/react/keyboard/testing` | server (Bun or Node) | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the keyboard layers and zones without a DOM — fakes for the window, elements and key events beside the two engines, to test the order of layers, `scope`/`inert` and the edges of a zone in milliseconds |
112
- | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 11 of the 42 minors since 0.94.0, most recently 0.135.0_ | peer-free durable conversation/run loop over `AgentModelDriver`, stateless `completeText`/`completeObject`, driver composition, history, models, prompts, fencing and events |
113
- | `stitchkit/agent-runtime/sandbox` | server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | optional Linux Bubblewrap sessions, long-lived OS process sandboxes (`createProcessSandbox`, `probeProcessSandbox`, `buildSeatbeltProfile`), durable workspaces and a host HTTP credential gateway; see [sandbox guide](sandbox.md) |
114
- | `stitchkit/agent-runtime/testing` | tests on Bun or Node | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.134.0_ | peer-free `createScriptedModelDriver`, credential-free replay, scripted provider faults, deterministic race controls and the agent-store conformance kit |
115
- | `stitchkit/agent-runtime/harness` | server | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.134.0_ | peer-free resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
116
- | `stitchkit/agent-runtime/coding-tools` | server (Bun or Node) | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | bounded host-authorized direct file and shell tools; a root boundary, not an OS sandbox |
117
- | `stitchkit/agent-runtime/openrouter` | server | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.135.0_ | peer-free native OpenRouter Chat Completions SSE driver, catalog, admission, route pinning and spend reconciliation |
118
- | `stitchkit/agent-runtime/openai` | server | evolving<br>_redefined in 0 of the 2 minors since 0.134.0_ | peer-free native OpenAI Responses API (`POST /v1/responses`) driver, policy schemas and provenance-aware usage normalization |
119
- | `stitchkit/agent-runtime/anthropic` | server | evolving<br>_redefined in 0 of the 2 minors since 0.134.0_ | peer-free native Anthropic Messages API (`POST /v1/messages`) driver, thinking/cache policy schemas and provenance-aware usage normalization |
120
- | `stitchkit/agent-runtime/ai-sdk` | server | evolving<br>_redefined in 0 of the 2 minors since 0.134.0_ | thin optional-peer adapter (`fromAiSdkModel`, `fromAiSdkTools`) bridging AI SDK (`LanguageModelV4` from `ai@7`) models and `ToolSet`s onto `AgentModelDriver` and `AgentToolSet`; requires `ai` |
121
- | `stitchkit/agent-runtime/browser` | browser + server | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.127.0_ | canonical agent records, events, reconnect cursor, interactive approval/input/permission-mode/host-status state (`deriveAgentConversationActivity`, `deriveAgentConversationState`, `delivery: 'unknown'` reconciliation) and optional conversation controller |
122
- | `stitchkit/agent-runtime/react` | browser + server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | React subscription to an application-owned agent controller |
123
- | `stitchkit/agent-runtime/realtime` | server (Bun or Node) | evolving<br>_redefined in 2 of the 42 minors since 0.94.0, most recently 0.127.0_ | authorized agent control over the existing Socket.IO server |
124
- | `stitchkit/agent-executor` | server (Bun or Node) | evolving<br>_redefined in 4 of the 9 minors since 0.127.0, most recently 0.133.0_ | the executor ↔ server contract for external coding agents (Claude Code, Codex, ACP): delta vocabulary (including `ExecutorPlanDelta`) over the shared message parts, thread leases with a fence, turn phases and their reports |
125
- | `stitchkit/agent-executor/claude` | server (Bun or Node) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | the Claude Code driver: the unmodified CLI over `stream-json`, permission requests answered by the host, reconcile by the input's id in the profile's transcript |
126
- | `stitchkit/agent-executor/claude-sdk` | server (Bun or Node) | evolving<br>_redefined in 1 of the 9 minors since 0.127.0, most recently 0.131.0_ | Claude through the Agent SDK: the application's `query` (optional peer `@anthropic-ai/claude-agent-sdk`), the CLI's classifier, `canUseTool` asked of the host |
127
- | `stitchkit/agent-executor/acp` | server (Bun or Node) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | an Agent Client Protocol v1 agent over stdio: settings by category, images, MCP servers, tool metadata (`title`/`kind`/`locations`), meaningful `tool_call_update` progress updates, typed `plan` deltas, `session/resume`/`load`/`list`, `session/cancel`; no reconcile |
128
- | `stitchkit/agent-executor/codex` | server (Bun or Node) | evolving<br>_redefined in 3 of the 9 minors since 0.127.0, most recently 0.133.0_ | the Codex driver: `codex app-server` over stdio or Unix-socket WebSocket (`unix-listen` / `unix-connect`), thread policy and live controls, approval and input requests answered by the host, unknown server requests refused, reconcile by the client id in `thread/turns/list` |
129
- | `stitchkit/agent-executor/testing` | server (Bun or Node) | evolving<br>_redefined in 1 of the 9 minors since 0.127.0, most recently 0.133.0_ | the engine conformance kit, deterministic replay driver, portable fake Codex app-server, fail-loud consumer stub factories, and schema-validated test fixtures; no optional peer |
130
- | `stitchkit/agent-executor/testing/claude-sdk` | server (Bun or Node) | evolving<br>_redefined in 0 of the 3 minors since 0.133.0_ | the multi-turn fake Claude SDK query harness and the Claude SDK session stub, typed by the optional peer `@anthropic-ai/claude-agent-sdk` |
131
- | `stitchkit/agent-runtime/postgres` | server (Bun or Node) | evolving<br>_redefined in 0 of the 9 minors since 0.127.0_ | the agent store, conversation reader and companion host on Postgres, over the application's own client (Bun SQL, Prisma, `pg`) |
132
- | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | durable built-in SQLite store for the agent runtime |
133
- | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving<br>_redefined in 1 of the 42 minors since 0.94.0, most recently 0.127.0_ | durable built-in SQLite store for the agent runtime |
59
+ | `stitchkit` | browser **and** server | stable<br>_redefined in 6 of the 43 minors since 0.94.0, most recently 0.135.0_ | `defineContract`, `createClient`, `createHttpClient`, `createSocketIOClient`, `parseSSE`, the error model |
60
+ | `stitchkit/http` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.135.0_ | typed HTTP client factories, `ApiError`, `readContractIdentity` and the stream line errors, without optional realtime peers |
61
+ | `stitchkit/realtime` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | typed realtime clients, binding to an existing socket and retained topics with a required explicit Socket.IO peer loader |
62
+ | `stitchkit/device-relay` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 0 of the 3 minors since 0.134.0_ | peer-free User Device Relay over realtime — `createDeviceRelayHub`, `createDeviceRelayAgent`, `createMemoryRelayBroker`, `deviceRelayRealtimeContract`, Fetch-compatible unary RPC and credit-paced cursor streams |
63
+ | `stitchkit/contract` | browser **and** server | stable<br>_redefined in 6 of the 43 minors since 0.94.0, most recently 0.136.0_ | the contract layer alone — `defineContract`, errors, pagination |
64
+ | `stitchkit/live` | browser **and** server | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.127.0_ | `defineEvents` — topic declarations beside the operation contract — and watched reads: `createWatchClient`, the value/difference frame and its reassembly |
65
+ | `stitchkit/primitives` | browser **and** server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | generic values and declarations for lifecycle, access, audit, delivery and exports, exact money and rounding tables |
66
+ | `stitchkit/handler` | browser, React Native/Hermes **and** server | evolving<br>_redefined in 1 of the 10 minors since 0.127.0, most recently 0.136.0_ | portable `createHandler`, `implement`, errors and `serveBridge` over a string `postMessage` port, with no Node built-ins |
67
+ | `stitchkit/server` | server (Bun) | stable<br>_redefined in 6 of the 43 minors since 0.94.0, most recently 0.136.0_ | `createServer`, `implement`, hooks, auth, Socket.IO server, server primitives |
68
+ | `stitchkit/node` | server (Node ≥ 22.3) | stable<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.136.0_ | `serveNode` + the runtime-agnostic core — the Node mirror of `/server` |
69
+ | `stitchkit/tools` | server | stable<br>_redefined in 13 of the 43 minors since 0.94.0, most recently 0.136.0_ | the transport-neutral tool layer — `mountAgentTools`, `defineAgentTool`, registry, tool names and manifest, runtime tools, native tools, the OAuth provider, the durability engine; loads no optional peer at runtime |
70
+ | `stitchkit/tools/mcp` | server (Bun or Node) | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | the canonical MCP HTTP/stdio server, schemas and typed MCP presenters; only Zod and the MCP server SDK peers |
71
+ | `stitchkit/tools/agent` | server (Bun or Node) | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.134.0_ | `mountAgent` — thin AI SDK `ToolSet` adapter over `mountAgentTools` for apps driving their own SDK loop; only Zod and the `ai` peer |
72
+ | `stitchkit/tools/toolkit` | server (Bun or Node) | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.135.0_ | `createToolkit` — context-pinned MCP, peer-free agent (`mountAgentTools`), and CLI mounts; only the MCP server SDK peer (no `ai` peer) |
73
+ | `stitchkit/tools/contract` | browser + server | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.124.0_ | the shapes a tool surface speaks — async-operation contract, snapshot and cancel schemas, view-file input/output — without the runtime that serves them |
74
+ | `stitchkit/tools/invoker` | server | stable<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | peer-free `createToolInvoker` over the canonical contract tool runner |
75
+ | `stitchkit/tools/connections` | server (Bun or Node) | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | consume external MCP servers and a bounded OpenAPI subset — typed reauthorization, a per-request host fence and per-call credentials |
76
+ | `stitchkit/cli` | server | stable<br>_redefined in 12 of the 43 minors since 0.94.0, most recently 0.128.0_ | `createCli` / `createCliInvoker` — runtime and strict NodeNext declarations without MCP SDK / `ai` |
77
+ | `stitchkit/cli/publish` | build and release tooling (Bun or Node, POSIX) | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | `publishCli` — commit a verified CLI distribution and move its public manifest last; see [CLI guide](cli.md#publishing-a-complete-version) |
78
+ | `stitchkit/remote` | browser **and** server | stable<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.104.0_ | peer-free `implementRemote` for thin HTTP proxy processes |
79
+ | `stitchkit/process` | server (Bun or Node, POSIX) | evolving<br>_redefined in 4 of the 43 minors since 0.94.0, most recently 0.133.0_ | finite native commands, byte sinks, bounded capture, process-group cancellation and opt-in Linux/Darwin owner-loss cleanup; contract operations executed in one-call child processes |
80
+ | `stitchkit/process/bootstrap` | bundled server entry (Bun, POSIX) | evolving<br>_redefined in 0 of the 4 minors since 0.133.0_ | narrow bootstrap that keeps the process runner lazy while carrying the package's own invocations — the owner-loss guard and the process root of launched work — in a single-file bundle |
81
+ | `stitchkit/files/packaging` | build time (Bun or Node) | evolving<br>_redefined in 4 of the 43 minors since 0.94.0, most recently 0.133.0_ | installed native asset graph, integrity, Bun packaging plugin and the artifact loader check; a client bundled into one self-contained, hashed file; a typed client built into a proven npm package with several entries, declarations and external peers; no runtime install policy |
82
+ | `stitchkit/files` | server (Bun or Node) | stable<br>_redefined in 5 of the 43 minors since 0.94.0, most recently 0.133.0_ | peer-free managed local-file boundary |
83
+ | `stitchkit/spend` | server (Bun or Node) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | peer-free spend gateway for paid model APIs: the attempt recorded before the call and closed on every outcome, credentials only for the provider's origin, a spooled ledger, rank-merged receipts and a reconciler |
84
+ | `stitchkit/spend/testing` | tests on Bun or Node | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | the coverage guard: red on a model SDK import, a provider key or a provider host outside the gateway files |
85
+ | `stitchkit/service-host` | server (Bun or Node) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | peer-free host service supervision — verified versioned artifact activation, Linux `systemd` and macOS `launchd` units (`plutil`, `bootout`/`bootstrap`, rollback), live process/Unix-socket identity verification, and an in-process config-watched reloader |
86
+ | `stitchkit/service-host/macos` | server (Bun or Node, macOS) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | peer-free macOS daemon bundle toolkit — fail-closed Developer ID `codesign`, strict C11 launcher `.app` bundles with atomic `RENAME_SWAP` install/rollback, Apple 824×824 squircle `AppIcon.icns`, streaming `lsregister` maintenance, and TCC responsibility inspection |
87
+ | `stitchkit/service-host/work` | server (Bun or Node; Linux with systemd ≥ 254, or a process root on Linux and macOS) | evolving<br>_redefined in 0 of the 4 minors since 0.133.0_ | peer-free launch of work in its own boundary with a declared owner — a transient systemd scope or a recorded process root, the typed owner record, the one inherited variable that names the boundary, and the membership check that asks the boundary; see [native I/O](native-io.md#work-in-its-own-boundary) |
88
+ | `stitchkit/telegram` | server (Bun or Node) | evolving<br>_redefined in 9 of the 43 minors since 0.94.0, most recently 0.136.0_ | peer-free Telegram platform primitives — Mini App `initData` verification, widget limits and the `widget_query`, `shared_widget_query` and widget message schemas, send-failure classification, one outbound budget per bot token with weighted albums and per-chat 429 pauses, resumable broadcasts, the operator channel with dedupe, a Bot API transport that separates a request that never left from an unknown outcome, local Bot API files, the waveform of a voice message read from its PCM, webhook ownership and durable webhook update intake |
89
+ | `stitchkit/telegram/grammy` | server (Bun or Node) | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the token's outbound budget as one grammY client transformer — a 429 that comes back as a response pauses its chat, and a cancelled wait is a request that never left; the widget methods over the same client |
90
+ | `stitchkit/telegram/html` | browser and server | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | Telegram's HTML as a tree — compile GFM Markdown to Telegram HTML with fence-aware splitting, clean any markup to what Telegram accepts, cut long text into valid parts by what the reader sees, check markup before it is sent |
91
+ | `stitchkit/telegram/voice` | browser and server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the waveform of a voice message as one format — packed for `sendVoice` the way Telegram Desktop scales it, unpacked to draw it, a `getMe` read of whether the server takes it |
92
+ | `stitchkit/telegram/screens` | server (Bun or Node) | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | a bot's menus as declared screens over grammY — typed paths, actions and input, message reconciliation, state in any `StorageAdapter`, a test chat |
93
+ | `stitchkit/tracking` | browser **and** server | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | visitor-tracking mechanics — `createTrackingClient`, the tab-shared outbox, the page-leave beacon, attribution, the contract factory; no event vocabulary, no React |
94
+ | `stitchkit/tracking/contract` | browser **and** server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the wire shapes — the contract factory, event and visit schemas, the performance sample and its trust threshold; brings `zod` |
95
+ | `stitchkit/tracking/performance` | browser **and** server | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | Web Vitals from real visitors, collected after load through the optional peer `web-vitals`; no `zod` |
96
+ | `stitchkit/tracking/server` | server (Bun or Node) | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the decisions a tracking backend makes — dispositions, visit lease over an application-owned store, active intervals, presence; no database |
97
+ | `stitchkit/release` | browser **and** server | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | a page follows the release it was built for — `createReleaseMarker` on the server, `createReleaseWatcher` in the browser, the `X-Build-Id` header and a socket event between them |
98
+ | `stitchkit/voice` | browser **and** server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the mechanics of a live voice reply — `SentenceCutter`, `speakableText`, a `SpeechQueue` that synthesises ahead and stops on interruption, the conversation phases |
99
+ | `stitchkit/sync` | browser **and** server | evolving<br>_redefined in 1 of the 10 minors since 0.127.0, most recently 0.132.0_ | the client half of an offline-first sync — which outbox rows leave next, pending edits on top of remote rows, deletes that win until acknowledged, the cursor session, the push and page wire with an open outcome vocabulary; no driver, runs in Hermes |
100
+ | `stitchkit/sync/postgres` | server (Bun or Node) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | the server half — versions that commit in order, a ledger that runs each change once, a feed of what changed, inside the app's own transaction; a memory store and `checkSyncStore` |
101
+ | `stitchkit/geo` | server (Bun or Node) | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.127.0_ | managed GeoIP reader generations, last-known-good reload and the optional MaxMind adapter |
102
+ | `stitchkit/geo/contract` | browser **and** server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the place snapshot schema, for a shared contract that stores or sends `GeoAttribution`; brings `zod` |
103
+ | `stitchkit/xlsx` | browser **and** server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | a workbook from rows and typed columns, with no dependency; text never runs as a formula |
104
+ | `stitchkit/oauth` | browser **and** server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | provider-neutral Authorization Code + PKCE request and one-shot callback transaction mechanics |
105
+ | `stitchkit/google` | server (Bun or Node) | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | optional Google code exchange and verified OIDC identity adapter |
106
+ | `stitchkit/observability` | server | stable<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.136.0_ | request/tool event projections — `createObservability`, trace context, sanitisation |
107
+ | `stitchkit/testing` | tests on Bun or Node | stable<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | in-process generated clients over a real Fetch handler, the managed-resource conformance kit and manual time for schedules and retries |
108
+ | `stitchkit/declaration` | browser + build and deployment tooling (Bun or Node) | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.128.0_ | `ProjectDeclarationSchema` — the one machine-readable statement a repository makes about itself |
109
+ | `stitchkit/react` | browser + server rendering | stable<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.136.0_ | `createCursorQuery`, `createCacheBridge`, QueryClient and `ApiError` retry policy |
110
+ | `stitchkit/react/keyboard` | browser | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.115.0_ | which part of a screen gets a key — ordered layers, one Escape per level, list zones with real focus; see [keyboard guide](keyboard.md) |
111
+ | `stitchkit/react/keyboard/testing` | server (Bun or Node) | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the keyboard layers and zones without a DOM — fakes for the window, elements and key events beside the two engines, to test the order of layers, `scope`/`inert` and the edges of a zone in milliseconds |
112
+ | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 12 of the 43 minors since 0.94.0, most recently 0.136.0_ | peer-free durable conversation/run loop over `AgentModelDriver`, stateless `completeText`/`completeObject`, driver composition, history, models, prompts, fencing and events |
113
+ | `stitchkit/agent-runtime/sandbox` | server | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.136.0_ | optional Linux Bubblewrap sessions, long-lived OS process sandboxes (`createProcessSandbox`, `probeProcessSandbox`, `buildSeatbeltProfile`), durable workspaces and a host HTTP credential gateway; see [sandbox guide](sandbox.md) |
114
+ | `stitchkit/agent-runtime/testing` | tests on Bun or Node | evolving<br>_redefined in 4 of the 43 minors since 0.94.0, most recently 0.136.0_ | peer-free `createScriptedModelDriver`, credential-free replay, scripted provider faults, deterministic race controls and the agent-store conformance kit |
115
+ | `stitchkit/agent-runtime/harness` | server | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.134.0_ | peer-free resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
116
+ | `stitchkit/agent-runtime/coding-tools` | server (Bun or Node) | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | bounded host-authorized direct file and shell tools; a root boundary, not an OS sandbox |
117
+ | `stitchkit/agent-runtime/openrouter` | server | evolving<br>_redefined in 4 of the 43 minors since 0.94.0, most recently 0.136.0_ | peer-free native OpenRouter Chat Completions SSE driver, catalog, admission, route pinning and spend reconciliation, plus typed non-chat clients (speech-to-text, text-to-speech, images, video, embeddings, rerank, System One, any endpoint through `openRouterRequestJson`) bound once by `createOpenRouterClient`; see [agent runtime guide](agent-runtime.md#openrouter-non-chat-endpoints-and-shared-transport) |
118
+ | `stitchkit/agent-runtime/openai` | server | evolving<br>_redefined in 0 of the 3 minors since 0.134.0_ | peer-free native OpenAI Responses API (`POST /v1/responses`) driver, policy schemas and provenance-aware usage normalization |
119
+ | `stitchkit/agent-runtime/anthropic` | server | evolving<br>_redefined in 0 of the 3 minors since 0.134.0_ | peer-free native Anthropic Messages API (`POST /v1/messages`) driver, thinking/cache policy schemas and provenance-aware usage normalization |
120
+ | `stitchkit/agent-runtime/ai-sdk` | server | evolving<br>_redefined in 0 of the 3 minors since 0.134.0_ | thin optional-peer adapter (`fromAiSdkModel`, `fromAiSdkTools`) bridging AI SDK (`LanguageModelV4` from `ai@7`) models and `ToolSet`s onto `AgentModelDriver` and `AgentToolSet`; requires `ai` |
121
+ | `stitchkit/agent-runtime/browser` | browser + server | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.127.0_ | canonical agent records, events, reconnect cursor, interactive approval/input/permission-mode/host-status state (`deriveAgentConversationActivity`, `deriveAgentConversationState`, `delivery: 'unknown'` reconciliation) and optional conversation controller |
122
+ | `stitchkit/agent-runtime/react` | browser + server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | React subscription to an application-owned agent controller |
123
+ | `stitchkit/agent-runtime/realtime` | server (Bun or Node) | evolving<br>_redefined in 2 of the 43 minors since 0.94.0, most recently 0.127.0_ | authorized agent control over the existing Socket.IO server |
124
+ | `stitchkit/agent-executor` | server (Bun or Node) | evolving<br>_redefined in 4 of the 10 minors since 0.127.0, most recently 0.133.0_ | the executor ↔ server contract for external coding agents (Claude Code, Codex, ACP): delta vocabulary (including `ExecutorPlanDelta`) over the shared message parts, thread leases with a fence, turn phases and their reports |
125
+ | `stitchkit/agent-executor/claude` | server (Bun or Node) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | the Claude Code driver: the unmodified CLI over `stream-json`, permission requests answered by the host, reconcile by the input's id in the profile's transcript |
126
+ | `stitchkit/agent-executor/claude-sdk` | server (Bun or Node) | evolving<br>_redefined in 1 of the 10 minors since 0.127.0, most recently 0.131.0_ | Claude through the Agent SDK: the application's `query` (optional peer `@anthropic-ai/claude-agent-sdk`), the CLI's classifier, `canUseTool` asked of the host |
127
+ | `stitchkit/agent-executor/acp` | server (Bun or Node) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | an Agent Client Protocol v1 agent over stdio: settings by category, images, MCP servers, tool metadata (`title`/`kind`/`locations`), meaningful `tool_call_update` progress updates, typed `plan` deltas, `session/resume`/`load`/`list`, `session/cancel`; no reconcile |
128
+ | `stitchkit/agent-executor/codex` | server (Bun or Node) | evolving<br>_redefined in 3 of the 10 minors since 0.127.0, most recently 0.133.0_ | the Codex driver: `codex app-server` over stdio or Unix-socket WebSocket (`unix-listen` / `unix-connect`), thread policy and live controls, approval and input requests answered by the host, unknown server requests refused, reconcile by the client id in `thread/turns/list` |
129
+ | `stitchkit/agent-executor/testing` | server (Bun or Node) | evolving<br>_redefined in 1 of the 10 minors since 0.127.0, most recently 0.133.0_ | the engine conformance kit, deterministic replay driver, portable fake Codex app-server, fail-loud consumer stub factories, and schema-validated test fixtures; no optional peer |
130
+ | `stitchkit/agent-executor/testing/claude-sdk` | server (Bun or Node) | evolving<br>_redefined in 0 of the 4 minors since 0.133.0_ | the multi-turn fake Claude SDK query harness and the Claude SDK session stub, typed by the optional peer `@anthropic-ai/claude-agent-sdk` |
131
+ | `stitchkit/agent-runtime/postgres` | server (Bun or Node) | evolving<br>_redefined in 0 of the 10 minors since 0.127.0_ | the agent store, conversation reader and companion host on Postgres, over the application's own client (Bun SQL, Prisma, `pg`) |
132
+ | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | durable built-in SQLite store for the agent runtime |
133
+ | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving<br>_redefined in 1 of the 43 minors since 0.94.0, most recently 0.127.0_ | durable built-in SQLite store for the agent runtime |
134
134
  | `stitchkit-tui` | terminal (Bun) | evolving | optional official OpenTUI host over a caller-composed headless runtime |
135
- | `stitchkit/application` | browser + server | evolving<br>_redefined in 9 of the 42 minors since 0.94.0, most recently 0.127.0_ | managed resource graph, readiness, admission, schedules, subtree restart and bounded shutdown |
136
- | `stitchkit/application/grammy` | server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | a grammY bot as application resources — configuration, then polling with updates admitted by batch — and the webhook adapter |
137
- | `stitchkit/application/opentelemetry` | server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | maps application snapshots onto an injected OpenTelemetry `Meter` |
138
- | `stitchkit/application/diagnostic-journal` | server | evolving<br>_redefined in 3 of the 42 minors since 0.94.0, most recently 0.127.0_ | the local diagnostic journal — an exclusive bounded writer and snapshot reader with explicit anomalies |
139
- | `stitchkit/application/directory-inbox` | server | evolving<br>_redefined in 0 of the 42 minors since 0.94.0_ | the directory inbox — entries another program drops into a directory, delivered to the application at least once |
135
+ | `stitchkit/application` | browser + server | evolving<br>_redefined in 9 of the 43 minors since 0.94.0, most recently 0.127.0_ | managed resource graph, readiness, admission, schedules, subtree restart and bounded shutdown |
136
+ | `stitchkit/application/grammy` | server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | a grammY bot as application resources — configuration, then polling with updates admitted by batch — and the webhook adapter |
137
+ | `stitchkit/application/opentelemetry` | server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | maps application snapshots onto an injected OpenTelemetry `Meter` |
138
+ | `stitchkit/application/diagnostic-journal` | server | evolving<br>_redefined in 3 of the 43 minors since 0.94.0, most recently 0.127.0_ | the local diagnostic journal — an exclusive bounded writer and snapshot reader with explicit anomalies |
139
+ | `stitchkit/application/directory-inbox` | server | evolving<br>_redefined in 0 of the 43 minors since 0.94.0_ | the directory inbox — entries another program drops into a directory, delivered to the application at least once |
140
140
 
141
141
  Rule of thumb: browser code imports `stitchkit` and `stitchkit/react`; server
142
142
  code adds `stitchkit/server` (or `stitchkit/node` on Node) and opts into
@@ -176,18 +176,28 @@ export const notes = defineContract({ prefix: 'notes' }, {
176
176
 
177
177
  ```ts
178
178
  // src/server/index.ts
179
- import { implement, createServer } from 'stitchkit/server'
179
+ import { createServer, implement, notFound } from 'stitchkit/server'
180
180
  import { notes } from '../shared/contracts'
181
181
 
182
+ const db = new Map<string, { id: string; text: string }>() // your database here
183
+
182
184
  const service = implement(notes, {
183
- list: () => db.list(),
184
- create: (ctx) => db.create(ctx.input.text), // ctx.input is typed
185
- get: (ctx) => db.get(ctx.params.id), // ctx.params is typed
185
+ list: () => [...db.values()],
186
+ create: (ctx) => { // ctx.input is typed
187
+ const note = { id: String(db.size + 1), text: ctx.input.text }
188
+ db.set(note.id, note)
189
+ return note
190
+ },
191
+ get: (ctx) => db.get(ctx.params.id) ?? notFound(), // ctx.params is typed
186
192
  })
187
193
 
188
- createServer({ services: [service], port: 3000 })
194
+ const server = createServer({ services: [service], port: 3000 })
195
+ console.log(`Listening on ${server.url}`)
189
196
  ```
190
197
 
198
+ Each contract is served under its prefix: `notes` answers at `/notes` and
199
+ `/notes/:id`, with no other path in front.
200
+
191
201
  ### 3. Call it, typed
192
202
 
193
203
  ```ts
@@ -195,16 +205,19 @@ createServer({ services: [service], port: 3000 })
195
205
  import { createClient, createHttpClient } from 'stitchkit'
196
206
  import { notes } from '../shared/contracts'
197
207
 
198
- export const api = createClient(notes, createHttpClient({ baseUrl: '/api' }))
208
+ export const api = createClient(notes, createHttpClient({ baseUrl: 'http://localhost:3000' }))
199
209
 
200
- await api.list() // GET /notes → Note[]
201
- await api.create({ text: 'hi' }) // POST /notes → Note
202
- await api.get({ id: '1' }) // GET /notes/1 → Note
210
+ console.log(await api.create({ text: 'hi' })) // POST http://localhost:3000/notes → Note
211
+ console.log(await api.list()) // GET http://localhost:3000/notes → Note[]
212
+ console.log(await api.get({ id: '1' })) // GET http://localhost:3000/notes/1 → Note
203
213
  ```
204
214
 
205
- Run the server with `bun run src/server/index.ts`. The contract is the single
206
- source of truth — change it and both the handler and the client are re-typed at
207
- once.
215
+ Start the server with `bun run src/server/index.ts`, then run the client in a
216
+ second terminal with `bun run src/client/api.ts`. `baseUrl` is where the server
217
+ listens; a browser app served from the same origin can pass its own origin, or
218
+ mount the services under a prefix (`groups: [{ pathPrefix: '/api', services: [service] }]`)
219
+ and call `baseUrl: '/api'`. The contract is the single source of truth — change it
220
+ and both the handler and the client are re-typed at once.
208
221
 
209
222
  #### On Node
210
223
 
@@ -277,7 +290,7 @@ bun add socket.io @socket.io/bun-engine # e.g. the Socket.IO server on Bun
277
290
  Dynamic optional-peer adapters fail with an actionable error naming the package
278
291
  and install command. Static entrypoints such as `stitchkit/tools/mcp` fail during
279
292
  ESM resolution by naming the exact missing package; the feature-to-peer matrix
280
- below is the canonical install command.
293
+ above is the canonical install command.
281
294
 
282
295
  `stitchkit/tools` itself loads no optional peer, and `stitchkit/tools/toolkit`
283
296
  stays free of `ai` (ADR 0338). Install only the peer of the adapter you import:
@@ -319,6 +332,13 @@ durable SQLite history, lazy skills, direct coding tools, approval continuations
319
332
  and recovery stay framework-owned primitives, while model choice, permissions,
320
333
  executables and OS isolation remain application policy.
321
334
 
335
+ For a long-polling Telegram bot, run
336
+ `bun create stitchkit my-bot --template telegram-bot`, copy `.env.example` to
337
+ `.env`, set `BOT_TOKEN`, then run `bun run dev`. The bot is a managed
338
+ application (`stitchkit/application` with `stitchkit/application/grammy`): its
339
+ handlers live in `src/handlers.ts`, and the entry point turns signals and a
340
+ poller that ended on its own into a bounded shutdown.
341
+
322
342
  ==============================================================================
323
343
  # Guide: Typed client (docs/guide/client.md)
324
344
  ==============================================================================
@@ -22,8 +22,9 @@ declarations and is never imported at run time — the bot brings it. → ADR 02
22
22
  | Export | Kind | Summary |
23
23
  |--------|------|---------|
24
24
  | `telegramBudgetTransformer` | function | `bot.api.config.use(telegramBudgetTransformer(budget))`: every Bot API call runs under the token's `telegramOutboundBudget`; a 429 that comes back as a response pauses the token, a cancellation before the request was handed on throws `TelegramNotDispatchedError`, a cancellation in flight stays the client's own error; it never retries |
25
- | `telegramWidgetApi` / `TelegramWidgetApi` | function / _type_ | `telegramWidgetApi(bot.api)`: `sendWidget`, `editMessageWidgetData` and `answerWidgetQuery` through the client's `api.raw`, so its transformers — the outbound budget among them — run each call; input over a limit throws `ZodError` before any request, an already aborted signal throws `TelegramNotDispatchedError`, a request is handed on once and never repeated, `message is not modified` is success, and an unexpected successful answer is an error whose outcome is unknown |
26
- | `TelegramSendWidgetParams` / `TelegramEditMessageWidgetDataParams` / `TelegramAnswerWidgetQueryParams` | _type_ | the methods' Bot API parameters by their Bot API names; an edit names `chat_id` with `message_id` or `inline_message_id`, and `chat_data` or `public_data` (`''` removes it, an omitted field keeps it) |
25
+ | `telegramWidgetApi` / `TelegramWidgetApi` | function / _type_ | `telegramWidgetApi(bot.api)`: `sendWidget`, `sendSharedWidget`, `editMessageWidgetData`, `editSharedWidgetData` and `answerWidgetQuery` through the client's `api.raw`, so its transformers — the outbound budget among them — run each call; input over a limit throws `ZodError` before any request, an already aborted signal throws `TelegramNotDispatchedError`, a request is handed on once and never repeated, `message is not modified` is success, and an unexpected successful answer is an error whose outcome is unknown |
26
+ | `TelegramSendWidgetParams` / `TelegramEditMessageWidgetDataParams` / `TelegramAnswerWidgetQueryParams` | _type_ | the methods' Bot API parameters by their Bot API names; `is_shared: true` creates a shared widget, whose message must carry `widget.id`; an edit names `chat_id` with `message_id` or `inline_message_id`, and `chat_data` or `public_data` (`''` removes it, an omitted field keeps it) |
27
+ | `TelegramSendSharedWidgetParams` / `TelegramEditSharedWidgetDataParams` | _type_ | `sendSharedWidget` sends an existing shared widget by `widget_id` again, costs one message, and its message must carry that id; `editSharedWidgetData` changes `public_data` (`''` removes it) of every message with the widget, with an optional `cache_time` of 5–3600 s, and costs no message |
27
28
  | `TelegramWidgetCallOptions` | _type_ | `signal` for one call: aborted before the request leaves, the call is not dispatched |
28
29
 
29
30
  ---
@@ -71,6 +71,8 @@ injected grammY bot. → ADR 0143, ADR 0201, ADR 0274 — [guide](../guide/teleg
71
71
  | `TelegramWidgetHtmlSchema` / `TelegramWidgetDataSchema` | schema | widget HTML (1–32768 bytes, at most 4096 compressed) and widget data (0–1024 bytes), counted in UTF-8 bytes; NUL and an unpaired surrogate are refused, an empty data string is a value |
72
72
  | `TelegramWidgetMessageSchema` / `TelegramWidgetMessage` | schema / _type_ | the message `sendWidget` returns — `message_id`, `chat`, `widget` with `html` and its data; parsed loosely, so fields Telegram adds pass through |
73
73
  | `TelegramWidgetQuerySchema` / `TelegramWidgetQuery` | schema / _type_ | `Update.widget_query`: `id`, `from`, `chat` with `message_id` or `inline_message_id`, `chat_instance`, `type` (`data` / `sign_data` / `sent_transaction`), `data` of 1–64 bytes, `widget_id` |
74
- | `parseTelegramWidgetQuery` / `TelegramWidgetQueryParse` | function / _type_ | read `update.widget_query`: `{ query }`, or `{ id, error }` for a query that does not parse — its id is enough to answer it with a refusal — or `undefined` without an id |
74
+ | `parseTelegramWidgetQuery` / `TelegramWidgetQueryParse` | function / _type_ | read `update.widget_query`: `{ query }`, or `{ id, error }` for a query that does not parse — its id is enough to answer it with a refusal — or `undefined` without an id; `TelegramWidgetQueryParse<Query>` is the same result for another query type |
75
+ | `TelegramSharedWidgetQuerySchema` / `TelegramSharedWidgetQuery` | schema / _type_ | `Update.shared_widget_query`, a query from a forwarded shared widget: `id`, `from`, `type`, `data` of 1–64 bytes and the shared widget's `widget_id` — no chat and no message |
76
+ | `parseTelegramSharedWidgetQuery` | function | read `update.shared_widget_query` as `parseTelegramWidgetQuery` reads `update.widget_query`: `{ query }`, `{ id, error }` or `undefined` |
75
77
 
76
78
  ---