stitchkit 0.135.0 → 0.136.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +25 -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/image-input.d.ts +10 -3
  20. package/dist/agent-executor/image-input.d.ts.map +1 -1
  21. package/dist/agent-executor/testing/replay-scenarios.d.ts.map +1 -1
  22. package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -1
  23. package/dist/agent-runtime/browser/browser-control-contract.d.ts +4 -0
  24. package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -1
  25. package/dist/agent-runtime/browser/control-schema.d.ts +4 -0
  26. package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -1
  27. package/dist/agent-runtime/browser/control-view.d.ts.map +1 -1
  28. package/dist/agent-runtime/event-schema.d.ts +16 -3
  29. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  30. package/dist/agent-runtime/loop/deferred-tools.d.ts.map +1 -1
  31. package/dist/agent-runtime/loop/invocation-payload.d.ts.map +1 -1
  32. package/dist/agent-runtime/loop/invocation-stream.d.ts +9 -1
  33. package/dist/agent-runtime/loop/invocation-stream.d.ts.map +1 -1
  34. package/dist/agent-runtime/loop/provider-stream-parts.d.ts +6 -0
  35. package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -1
  36. package/dist/agent-runtime/loop/provider-stream-segments.d.ts +1 -1
  37. package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -1
  38. package/dist/agent-runtime/loop/run-acquisition.d.ts.map +1 -1
  39. package/dist/agent-runtime/loop/run-approval-signature.d.ts +34 -0
  40. package/dist/agent-runtime/loop/run-approval-signature.d.ts.map +1 -0
  41. package/dist/agent-runtime/loop/run-approval.d.ts +0 -28
  42. package/dist/agent-runtime/loop/run-approval.d.ts.map +1 -1
  43. package/dist/agent-runtime/loop/run-complete-port.d.ts +24 -0
  44. package/dist/agent-runtime/loop/run-complete-port.d.ts.map +1 -0
  45. package/dist/agent-runtime/loop/run-complete-stream.d.ts +7 -2
  46. package/dist/agent-runtime/loop/run-complete-stream.d.ts.map +1 -1
  47. package/dist/agent-runtime/loop/run-complete-types.d.ts +14 -1
  48. package/dist/agent-runtime/loop/run-complete-types.d.ts.map +1 -1
  49. package/dist/agent-runtime/loop/run-complete.d.ts +2 -2
  50. package/dist/agent-runtime/loop/run-complete.d.ts.map +1 -1
  51. package/dist/agent-runtime/loop/run-execution-state.d.ts +8 -0
  52. package/dist/agent-runtime/loop/run-execution-state.d.ts.map +1 -1
  53. package/dist/agent-runtime/loop/run-model-call.d.ts +44 -0
  54. package/dist/agent-runtime/loop/run-model-call.d.ts.map +1 -0
  55. package/dist/agent-runtime/loop/run-model-step.d.ts +25 -28
  56. package/dist/agent-runtime/loop/run-model-step.d.ts.map +1 -1
  57. package/dist/agent-runtime/loop/run-model-steps.d.ts +6 -0
  58. package/dist/agent-runtime/loop/run-model-steps.d.ts.map +1 -0
  59. package/dist/agent-runtime/loop/run-model-stream.d.ts +3 -1
  60. package/dist/agent-runtime/loop/run-model-stream.d.ts.map +1 -1
  61. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts +0 -2
  62. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts.map +1 -1
  63. package/dist/agent-runtime/loop/run-step-loop.d.ts +19 -0
  64. package/dist/agent-runtime/loop/run-step-loop.d.ts.map +1 -0
  65. package/dist/agent-runtime/loop/run-step-port.d.ts +175 -0
  66. package/dist/agent-runtime/loop/run-step-port.d.ts.map +1 -0
  67. package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -1
  68. package/dist/agent-runtime/loop/run-stream-step-text.d.ts.map +1 -1
  69. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts +2 -1
  70. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts.map +1 -1
  71. package/dist/agent-runtime/loop/run-tool-call-input.d.ts +39 -0
  72. package/dist/agent-runtime/loop/run-tool-call-input.d.ts.map +1 -0
  73. package/dist/agent-runtime/loop/run-tool-call.d.ts +2 -31
  74. package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -1
  75. package/dist/agent-runtime/loop/run-tool-errors.d.ts +5 -0
  76. package/dist/agent-runtime/loop/run-tool-errors.d.ts.map +1 -1
  77. package/dist/agent-runtime/loop/run-tool-executor.d.ts +1 -1
  78. package/dist/agent-runtime/loop/run-tool-executor.d.ts.map +1 -1
  79. package/dist/agent-runtime/loop/run-tool-slots.d.ts +2 -1
  80. package/dist/agent-runtime/loop/run-tool-slots.d.ts.map +1 -1
  81. package/dist/agent-runtime/loop/runtime-state.d.ts.map +1 -1
  82. package/dist/agent-runtime/loop/runtime.d.ts +0 -5
  83. package/dist/agent-runtime/loop/runtime.d.ts.map +1 -1
  84. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts +1 -5
  85. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts.map +1 -1
  86. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts +11 -0
  87. package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts.map +1 -0
  88. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts +11 -0
  89. package/dist/agent-runtime/providers/ai-sdk-tools.d.ts.map +1 -0
  90. package/dist/agent-runtime/providers/ai-sdk.d.ts +1 -9
  91. package/dist/agent-runtime/providers/ai-sdk.d.ts.map +1 -1
  92. package/dist/agent-runtime/providers/anthropic-sse.d.ts.map +1 -1
  93. package/dist/agent-runtime/providers/openrouter-admission.d.ts.map +1 -1
  94. package/dist/agent-runtime/providers/openrouter-audio.d.ts +164 -0
  95. package/dist/agent-runtime/providers/openrouter-audio.d.ts.map +1 -0
  96. package/dist/agent-runtime/providers/openrouter-catalog-cache.d.ts.map +1 -1
  97. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts.map +1 -1
  98. package/dist/agent-runtime/providers/openrouter-catalog.d.ts +4 -2
  99. package/dist/agent-runtime/providers/openrouter-catalog.d.ts.map +1 -1
  100. package/dist/agent-runtime/providers/openrouter-client.d.ts +37 -0
  101. package/dist/agent-runtime/providers/openrouter-client.d.ts.map +1 -0
  102. package/dist/agent-runtime/providers/openrouter-http.d.ts +120 -0
  103. package/dist/agent-runtime/providers/openrouter-http.d.ts.map +1 -0
  104. package/dist/agent-runtime/providers/openrouter-media.d.ts +174 -0
  105. package/dist/agent-runtime/providers/openrouter-media.d.ts.map +1 -0
  106. package/dist/agent-runtime/providers/openrouter-models.d.ts +2 -23
  107. package/dist/agent-runtime/providers/openrouter-models.d.ts.map +1 -1
  108. package/dist/agent-runtime/providers/openrouter-options.d.ts +4 -0
  109. package/dist/agent-runtime/providers/openrouter-options.d.ts.map +1 -1
  110. package/dist/agent-runtime/providers/openrouter-request.d.ts +23 -0
  111. package/dist/agent-runtime/providers/openrouter-request.d.ts.map +1 -0
  112. package/dist/agent-runtime/providers/openrouter-response.d.ts.map +1 -1
  113. package/dist/agent-runtime/providers/openrouter-retrieval.d.ts +145 -0
  114. package/dist/agent-runtime/providers/openrouter-retrieval.d.ts.map +1 -0
  115. package/dist/agent-runtime/providers/openrouter-speech.d.ts +90 -0
  116. package/dist/agent-runtime/providers/openrouter-speech.d.ts.map +1 -0
  117. package/dist/agent-runtime/providers/openrouter-spend.d.ts +7 -3
  118. package/dist/agent-runtime/providers/openrouter-spend.d.ts.map +1 -1
  119. package/dist/agent-runtime/providers/openrouter-stream.d.ts +29 -0
  120. package/dist/agent-runtime/providers/openrouter-stream.d.ts.map +1 -0
  121. package/dist/agent-runtime/providers/openrouter-systemone.d.ts +137 -0
  122. package/dist/agent-runtime/providers/openrouter-systemone.d.ts.map +1 -0
  123. package/dist/agent-runtime/providers/openrouter-url.d.ts +19 -0
  124. package/dist/agent-runtime/providers/openrouter-url.d.ts.map +1 -0
  125. package/dist/agent-runtime/providers/openrouter-wire.d.ts +45 -0
  126. package/dist/agent-runtime/providers/openrouter-wire.d.ts.map +1 -0
  127. package/dist/agent-runtime/providers/openrouter.d.ts +5 -4
  128. package/dist/agent-runtime/providers/openrouter.d.ts.map +1 -1
  129. package/dist/agent-runtime/providers/provider-http.d.ts +29 -3
  130. package/dist/agent-runtime/providers/provider-http.d.ts.map +1 -1
  131. package/dist/agent-runtime/providers/provider-json-schema-strip.d.ts.map +1 -1
  132. package/dist/agent-runtime/providers/provider-json-schema.d.ts.map +1 -1
  133. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts.map +1 -1
  134. package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts +42 -0
  135. package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts.map +1 -0
  136. package/dist/agent-runtime/providers/provider-usage.d.ts +9 -0
  137. package/dist/agent-runtime/providers/provider-usage.d.ts.map +1 -1
  138. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts +9 -0
  139. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts.map +1 -1
  140. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts +6 -0
  141. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts.map +1 -1
  142. package/dist/agent-runtime/sandbox/sandbox-contract.d.ts.map +1 -1
  143. package/dist/agent-runtime/sandbox/sandbox-process-linux.d.ts.map +1 -1
  144. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts +5 -1
  145. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts.map +1 -1
  146. package/dist/agent-runtime/sandbox/sandbox-process-wrapper.d.ts.map +1 -1
  147. package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -1
  148. package/dist/agent-runtime/stores/sql-rows.d.ts +10 -10
  149. package/dist/agent-runtime/terminal-commit.d.ts +10 -10
  150. package/dist/agent-runtime/testing/fault-bench.d.ts +5 -1
  151. package/dist/agent-runtime/testing/fault-bench.d.ts.map +1 -1
  152. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  153. package/dist/browser/client-executors.d.ts.map +1 -1
  154. package/dist/browser/client-url.d.ts.map +1 -1
  155. package/dist/contract/define.d.ts +3 -7
  156. package/dist/contract/define.d.ts.map +1 -1
  157. package/dist/contract/normalize.d.ts +17 -5
  158. package/dist/contract/normalize.d.ts.map +1 -1
  159. package/dist/entrypoints/agent-executor/acp.js +4 -2
  160. package/dist/entrypoints/agent-executor/claude-sdk.js +20 -20
  161. package/dist/entrypoints/agent-executor/claude.js +7 -7
  162. package/dist/entrypoints/agent-executor/codex.d.ts +2 -1
  163. package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
  164. package/dist/entrypoints/agent-executor/codex.js +129 -35
  165. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +2 -2
  166. package/dist/entrypoints/agent-executor/testing.js +17 -13
  167. package/dist/entrypoints/agent-executor.js +1 -1
  168. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +2 -1
  169. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -1
  170. package/dist/entrypoints/agent-runtime/ai-sdk.js +10 -12
  171. package/dist/entrypoints/agent-runtime/anthropic.js +13 -10
  172. package/dist/entrypoints/agent-runtime/browser.js +8 -4
  173. package/dist/entrypoints/agent-runtime/harness.js +18 -19
  174. package/dist/entrypoints/agent-runtime/openai.js +5 -5
  175. package/dist/entrypoints/agent-runtime/openrouter.d.ts +11 -2
  176. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
  177. package/dist/entrypoints/agent-runtime/openrouter.js +1940 -496
  178. package/dist/entrypoints/agent-runtime/postgres.js +2 -2
  179. package/dist/entrypoints/agent-runtime/realtime.js +5 -5
  180. package/dist/entrypoints/agent-runtime/sandbox.js +167 -139
  181. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  182. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  183. package/dist/entrypoints/agent-runtime/testing.js +3 -3
  184. package/dist/entrypoints/agent-runtime.js +246 -360
  185. package/dist/entrypoints/application.js +2 -2
  186. package/dist/entrypoints/cli.js +36 -15
  187. package/dist/entrypoints/contract.js +12 -10
  188. package/dist/entrypoints/geo.js +1 -1
  189. package/dist/entrypoints/handler.js +5 -6
  190. package/dist/entrypoints/http.d.ts +2 -0
  191. package/dist/entrypoints/http.d.ts.map +1 -1
  192. package/dist/entrypoints/http.js +16 -4
  193. package/dist/entrypoints/index.js +26 -35
  194. package/dist/entrypoints/live.js +3 -3
  195. package/dist/entrypoints/node.js +7 -7
  196. package/dist/entrypoints/observability.js +9 -7
  197. package/dist/entrypoints/process.js +3 -3
  198. package/dist/entrypoints/remote.js +5 -5
  199. package/dist/entrypoints/server.js +29 -16
  200. package/dist/entrypoints/telegram/grammy.d.ts +1 -1
  201. package/dist/entrypoints/telegram/grammy.d.ts.map +1 -1
  202. package/dist/entrypoints/telegram/grammy.js +39 -5
  203. package/dist/entrypoints/telegram/screens.js +3 -0
  204. package/dist/entrypoints/telegram.d.ts +1 -1
  205. package/dist/entrypoints/telegram.d.ts.map +1 -1
  206. package/dist/entrypoints/telegram.js +19 -6
  207. package/dist/entrypoints/testing.js +10 -11
  208. package/dist/entrypoints/tools/agent.js +8 -9
  209. package/dist/entrypoints/tools/connections.js +27 -57
  210. package/dist/entrypoints/tools/contract.js +4 -4
  211. package/dist/entrypoints/tools/invoker.js +7 -8
  212. package/dist/entrypoints/tools/mcp.js +9 -10
  213. package/dist/entrypoints/tools/toolkit.js +11 -12
  214. package/dist/entrypoints/tools.js +20 -20
  215. package/dist/entrypoints/tracking/contract.js +1 -1
  216. package/dist/entrypoints/tracking/performance.js +1 -1
  217. package/dist/entrypoints/tracking.js +1 -1
  218. package/dist/{index-3czc3ykr.js → index-08a3qfr8.js} +1 -1
  219. package/dist/{index-grhhsrd5.js → index-1en7k3q5.js} +2 -1
  220. package/dist/{index-pdcbjd6a.js → index-1yky29qg.js} +6 -3
  221. package/dist/{index-b4c9dpzm.js → index-252den5a.js} +10 -11
  222. package/dist/{index-xtby8rj3.js → index-28kbdn63.js} +5 -47
  223. package/dist/{index-57sbckhv.js → index-36mtj8xm.js} +2 -2
  224. package/dist/{index-dm84tsd5.js → index-3kb8dw48.js} +1 -1
  225. package/dist/index-3tb82xr7.js +11 -0
  226. package/dist/{index-c24bj2r1.js → index-4243301z.js} +2 -2
  227. package/dist/{index-nr4fhfn4.js → index-4p2zx593.js} +2 -0
  228. package/dist/{index-q86qnzzf.js → index-54wp467c.js} +4 -4
  229. package/dist/{index-mcv7b2n0.js → index-63ctzjp4.js} +497 -495
  230. package/dist/{index-y0a4gt1s.js → index-65p8v81y.js} +3 -2
  231. package/dist/{index-z72vazf5.js → index-6y3eae97.js} +27 -83
  232. package/dist/{index-5awtbyns.js → index-9vj869rx.js} +1 -1
  233. package/dist/{index-5q0qpw3v.js → index-aqm7e864.js} +23 -8
  234. package/dist/{index-d4at0q09.js → index-b9mj31q7.js} +90 -88
  235. package/dist/{index-baba8ehy.js → index-bjrcbcn2.js} +2 -2
  236. package/dist/{index-fsw9wxk9.js → index-c9j8441q.js} +1 -103
  237. package/dist/{index-wdb5jhas.js → index-d1pdv8qc.js} +1 -1
  238. package/dist/{index-73wq9abg.js → index-df5xr2f9.js} +13 -59
  239. package/dist/{index-n9358ydy.js → index-dm50x3by.js} +1 -1
  240. package/dist/{index-zyyerdny.js → index-dmrx8xma.js} +3 -0
  241. package/dist/{index-78da4g74.js → index-dwq6a6sq.js} +17 -13
  242. package/dist/{index-9be3tf6r.js → index-e413q2cj.js} +49 -22
  243. package/dist/{index-g4gstmp1.js → index-ednf2cxs.js} +1 -1
  244. package/dist/{index-84tp547a.js → index-edpkm3k7.js} +29 -97
  245. package/dist/{index-gs0jw0hy.js → index-efbzm2se.js} +3 -3
  246. package/dist/{index-de7b0kvz.js → index-epwvp88y.js} +1 -1
  247. package/dist/{index-asnd4h2k.js → index-f0dzyskg.js} +27 -4
  248. package/dist/{index-xbb8ysmq.js → index-fatke81t.js} +2 -2
  249. package/dist/{index-6nzzj7qr.js → index-gq35s3bm.js} +1 -1
  250. package/dist/index-gvgtmt7a.js +102 -0
  251. package/dist/{index-m2b49tvc.js → index-h08xqfw9.js} +20 -21
  252. package/dist/{index-gk6dq9ay.js → index-ha1tv70k.js} +3 -26
  253. package/dist/{index-wsv11dhg.js → index-hberxns4.js} +1 -1
  254. package/dist/{index-rkphknhx.js → index-hpzhz1vm.js} +1 -1
  255. package/dist/{index-npfdymav.js → index-j5vzhj3d.js} +1 -1
  256. package/dist/{index-d3s070eh.js → index-jperyn0c.js} +1 -1
  257. package/dist/{index-yhwx4fwk.js → index-kzsetgh9.js} +1 -1
  258. package/dist/{index-x6sp5vpa.js → index-q4tr9vnf.js} +1 -1
  259. package/dist/{index-hce3hbdg.js → index-qj0sq69b.js} +6 -2
  260. package/dist/{index-v0j22shs.js → index-rg08syp1.js} +9 -6
  261. package/dist/{index-8vzh5wpv.js → index-rw1caff2.js} +14 -26
  262. package/dist/index-s8af9jqw.js +6 -0
  263. package/dist/{index-bgj9hbm3.js → index-sdppfbrh.js} +30 -16
  264. package/dist/{index-y0mwkgkf.js → index-shte29pg.js} +1086 -1055
  265. package/dist/{index-fec05c9k.js → index-ta0e2daw.js} +9 -7
  266. package/dist/{index-zfrysr1e.js → index-tb36xawm.js} +110 -75
  267. package/dist/{index-c0yym4a0.js → index-w7e402wx.js} +11 -105
  268. package/dist/{index-bvpevwt6.js → index-xnqab06h.js} +207 -202
  269. package/dist/index-xrbrvn15.js +147 -0
  270. package/dist/{index-ac3rfec5.js → index-y6wzzk2e.js} +21 -1
  271. package/dist/{index-3d2c45jn.js → index-yjx5jna7.js} +2 -2
  272. package/dist/internal/loopback-host.d.ts +8 -0
  273. package/dist/internal/loopback-host.d.ts.map +1 -0
  274. package/dist/internal/own-member.d.ts +7 -0
  275. package/dist/internal/own-member.d.ts.map +1 -0
  276. package/dist/internal/request.d.ts +17 -8
  277. package/dist/internal/request.d.ts.map +1 -1
  278. package/dist/internal/secret-shapes.d.ts +33 -4
  279. package/dist/internal/secret-shapes.d.ts.map +1 -1
  280. package/dist/json-schema/dialect.d.ts.map +1 -1
  281. package/dist/json-schema/keywords.d.ts +25 -6
  282. package/dist/json-schema/keywords.d.ts.map +1 -1
  283. package/dist/json-schema/string-format.d.ts.map +1 -1
  284. package/dist/live/events.d.ts.map +1 -1
  285. package/dist/live/watch-client.d.ts.map +1 -1
  286. package/dist/live/watch-delta.d.ts.map +1 -1
  287. package/dist/observability/context.d.ts +4 -3
  288. package/dist/observability/context.d.ts.map +1 -1
  289. package/dist/observability/sanitize.d.ts.map +1 -1
  290. package/dist/observability/secret-values.d.ts +0 -9
  291. package/dist/observability/secret-values.d.ts.map +1 -1
  292. package/dist/server/context.d.ts +3 -2
  293. package/dist/server/context.d.ts.map +1 -1
  294. package/dist/server/error-hook.d.ts +4 -3
  295. package/dist/server/error-hook.d.ts.map +1 -1
  296. package/dist/server/event-bus.d.ts.map +1 -1
  297. package/dist/server/file.d.ts +11 -3
  298. package/dist/server/file.d.ts.map +1 -1
  299. package/dist/server/handler-state.d.ts +2 -2
  300. package/dist/server/handler-state.d.ts.map +1 -1
  301. package/dist/server/middleware/jwt.d.ts +12 -1
  302. package/dist/server/middleware/jwt.d.ts.map +1 -1
  303. package/dist/server/middleware/trust-fence.d.ts +4 -0
  304. package/dist/server/middleware/trust-fence.d.ts.map +1 -1
  305. package/dist/server/multipart.d.ts +2 -3
  306. package/dist/server/multipart.d.ts.map +1 -1
  307. package/dist/server/raw.d.ts.map +1 -1
  308. package/dist/server/request-body.d.ts +12 -1
  309. package/dist/server/request-body.d.ts.map +1 -1
  310. package/dist/server/request-completion.d.ts.map +1 -1
  311. package/dist/server/types.d.ts +14 -9
  312. package/dist/server/types.d.ts.map +1 -1
  313. package/dist/telegram/crypto.d.ts.map +1 -1
  314. package/dist/telegram/init-data.d.ts +4 -4
  315. package/dist/telegram/init-data.d.ts.map +1 -1
  316. package/dist/telegram/outbound-cost.d.ts.map +1 -1
  317. package/dist/telegram/screens/test-chat.d.ts.map +1 -1
  318. package/dist/telegram/widget-api.d.ts +85 -13
  319. package/dist/telegram/widget-api.d.ts.map +1 -1
  320. package/dist/telegram/widget.d.ts +46 -2
  321. package/dist/telegram/widget.d.ts.map +1 -1
  322. package/dist/tools/cli/args-classify.d.ts +4 -74
  323. package/dist/tools/cli/args-classify.d.ts.map +1 -1
  324. package/dist/tools/cli/args-framework.d.ts +79 -0
  325. package/dist/tools/cli/args-framework.d.ts.map +1 -0
  326. package/dist/tools/cli/args-scan.d.ts.map +1 -1
  327. package/dist/tools/cli/args-tokens.d.ts.map +1 -1
  328. package/dist/tools/cli/checkpoint.d.ts +5 -0
  329. package/dist/tools/cli/checkpoint.d.ts.map +1 -1
  330. package/dist/tools/cli/stream.d.ts.map +1 -1
  331. package/dist/tools/connections/foreign-schema-join.d.ts.map +1 -1
  332. package/dist/tools/connections/openapi.d.ts.map +1 -1
  333. package/dist/tools/connections/runtime.d.ts.map +1 -1
  334. package/dist/tools/execute-handler.d.ts +24 -0
  335. package/dist/tools/execute-handler.d.ts.map +1 -0
  336. package/dist/tools/execute.d.ts.map +1 -1
  337. package/dist/tools/mcp/round.d.ts.map +1 -1
  338. package/dist/tools/schema/coerce.d.ts.map +1 -1
  339. package/dist/tools/schema/flatten.d.ts.map +1 -1
  340. package/dist/tools/schema/inline-references.d.ts.map +1 -1
  341. package/dist/tools/schema/nesting-limit.d.ts.map +1 -1
  342. package/dist/tools/schema/presentation.d.ts.map +1 -1
  343. package/dist/tracking/privacy.d.ts.map +1 -1
  344. package/llms/agent-runtime-openrouter.txt +14 -5
  345. package/llms/agent-runtime-sandbox.txt +50 -11
  346. package/llms/agent-runtime-testing.txt +1 -1
  347. package/llms/agent-runtime.2.txt +342 -230
  348. package/llms/agent-runtime.3.txt +225 -380
  349. package/llms/agent-runtime.4.txt +387 -158
  350. package/llms/agent-runtime.5.txt +157 -152
  351. package/llms/agent-runtime.6.txt +164 -0
  352. package/llms/agent-runtime.txt +307 -362
  353. package/llms/application.txt +3 -1
  354. package/llms/http.txt +1 -1
  355. package/llms/live.txt +3 -1
  356. package/llms/observability.txt +16 -9
  357. package/llms/server.2.txt +13 -8
  358. package/llms/server.4.txt +23 -11
  359. package/llms/server.5.txt +5 -5
  360. package/llms/server.txt +54 -1
  361. package/llms/spend.txt +18 -1
  362. package/llms/stitchkit.2.txt +4 -2
  363. package/llms/stitchkit.txt +113 -93
  364. package/llms/telegram-grammy.txt +3 -2
  365. package/llms/telegram.2.txt +3 -1
  366. package/llms/telegram.txt +35 -10
  367. package/llms/upgrading-0.128.0-0.129.0.txt +175 -0
  368. package/llms/{upgrading-0.128.0-0.135.0.txt → upgrading-0.130.0-0.136.0.txt} +353 -169
  369. package/llms/upgrading.txt +2 -1
  370. package/llms-full.txt +1035 -208
  371. package/llms.txt +14 -13
  372. package/package.json +6 -6
  373. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts +0 -19
  374. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts.map +0 -1
  375. package/dist/agent-runtime/loop/run-complete-retry.d.ts +0 -24
  376. package/dist/agent-runtime/loop/run-complete-retry.d.ts.map +0 -1
  377. package/dist/agent-runtime/loop/run-model-attempts.d.ts +0 -6
  378. package/dist/agent-runtime/loop/run-model-attempts.d.ts.map +0 -1
  379. package/dist/index-sznqf8fx.js +0 -20
  380. /package/dist/{index-fthw8dwa.js → index-4gbybjg6.js} +0 -0
@@ -872,7 +872,9 @@ bot.catch(({ error }) => logger.error('Telegram handler failed', { error }))
872
872
  const telegram = grammyBotResources({
873
873
  bot,
874
874
  dependsOn: [database, http], // what handlers need before the first update
875
- configure: () => bot.api.setMyCommands([{ command: 'start', description: 'Start' }]),
875
+ configure: async () => {
876
+ await bot.api.setMyCommands([{ command: 'start', description: 'Start' }])
877
+ },
876
878
  onEnded: ({ error }) => stopProcess(error), // see below
877
879
  })
878
880
 
package/llms/http.txt CHANGED
@@ -14,7 +14,7 @@ Also read:
14
14
 
15
15
  ## `stitchkit/http`
16
16
 
17
- An HTTP-only entrypoint for browsers, React Native/Hermes and servers. It exports the same `createClient`, `createClients`, `createHttpClient`, URL builders, client configuration types and `ApiError` as the root, without loading its optional Socket.IO graph, plus the `postMessage` bridge `ClientFetch` adapter and envelope schemas. Import shared contracts from `stitchkit/contract`.
17
+ An HTTP-only entrypoint for browsers, React Native/Hermes and servers. It exports the same `createClient`, `createClients`, `createHttpClient`, URL builders, client configuration types, `ApiError`, `readContractIdentity` (with its `ContractIdentity` result) and the stream line errors `StreamLineLimitError` / `StreamTruncatedLineError` as the root, without loading its optional Socket.IO graph, plus the `postMessage` bridge `ClientFetch` adapter and envelope schemas. Import shared contracts from `stitchkit/contract`.
18
18
 
19
19
  ```ts
20
20
  import { createClients, createHttpClient } from 'stitchkit/http';
package/llms/live.txt CHANGED
@@ -432,7 +432,9 @@ never runs.
432
432
  - **It does not gate operations.** "Only from this machine" is a property of an
433
433
  operation, and an operation is known after routing, not before it. Write it as
434
434
  an auth rule over `ctx.ipAddress` — `isLoopbackAddress` is exported for
435
- exactly that — where it composes with your other rules.
435
+ exactly that — where it composes with your other rules. Behind a proxy on the
436
+ same host every peer is loopback: resolve the visitor with `trustProxy` first
437
+ ([server guide](./server.md#client-ip-behind-a-proxy)).
436
438
  - **It does not re-check an open connection.** Both lanes check at admission.
437
439
  - **It does not see an `OPTIONS` preflight** when `cors` is configured; that is
438
440
  answered earlier. The preflight carries no operation and no body, and the
@@ -601,18 +601,25 @@ each request.
601
601
  A payload goes into an audit row only after `sanitizePayload`:
602
602
 
603
603
  - **secret-named keys are masked** — a key whose words include a secret term is
604
- redacted (`password`, `sessionToken`, `X-Api-Key`, `authorization`, `cookie`,
605
- …), while identifiers that merely contain one (`authorId`, `sessionCount`,
606
- `tokenizer`) survive. This applies wherever a key exists — an object field and
604
+ redacted (`password`, `passphrase`, `sessionToken`, `X-Api-Key`, `accessKey`,
605
+ `authorization`, `cookie`, …), a key written as one lowercase run that ends in
606
+ one (`newpassword`, `accesstoken`), and a key that ENDS in `auth`, `signature`,
607
+ `jwt`, `otp`, `pin` or `dsn` (`basicAuth`, `webhookSignature`, `SENTRY_DSN`),
608
+ while identifiers that merely contain one (`authorId`, `sessionCount`,
609
+ `tokenizer`, `pinned`) or only describe it (`signatureVersion`, `auth_date`,
610
+ a model token count such as `maxTokens` or `usage.total_tokens`)
611
+ survive. This applies wherever a key exists — an object field and
607
612
  a `Map` entry alike, at any depth. A `Set` member has no key, so nothing there
608
613
  is masked by name;
609
614
  - **secrets are masked by their shape** in every string, whatever key holds
610
615
  it — the secret half of a Telegram bot token (`123456:[redacted]`: the bot's
611
616
  id stays, it tells two bots apart), the password in
612
- `postgresql://user:password@host` (user, host and path stay), and the value
613
- of a query parameter named as a secret (`?access_token=`, `?api-key=`,
614
- `?key=`, `?sig=`). A URL in an error message or a request log line is the
615
- usual way a token reaches a journal;
617
+ `postgresql://user:password@host` (user, host and path stay), the user of an
618
+ `http(s)` / `ws(s)` address with no password (a Sentry DSN's key — a database
619
+ or SSH user stays), the credential after `Bearer`, a provider key (`sk-…`, `or-v1-…`, `AIza…`), a
620
+ JSON Web Token (`eyJ….eyJ….…`), and the value of a query parameter named as a
621
+ secret (`?access_token=`, `?api-key=`, `?key=`, `?sig=`). A URL in an error
622
+ message or a request log line is the usual way a token reaches a journal;
616
623
  - **an error keeps what it says about itself** — its own fields (`error_code`,
617
624
  `parameters`, a provider's `status`) are written beside `name`, `message`,
618
625
  `stack` and `cause`, masked by the same rules; a field holding a class
@@ -791,8 +798,8 @@ use; future optional fields do not change callback arity.
791
798
 
792
799
  `createObservability({ tools })` uses it already. Where the envelope was scrubbed to
793
800
  `INTERNAL_SERVER_ERROR`, the row's `errorMessage` becomes the real message
794
- instead of the placeholder; a truthful envelope (a thrown `AppError`, a
795
- `ZodError`) is left alone, `errorCode` and `errorDetail` are untouched, and the
801
+ instead of the placeholder (a `ZodError` from handler code is one of these); a
802
+ truthful envelope (a thrown `AppError`, invalid input) is left alone, `errorCode` and `errorDetail` are untouched, and the
796
803
  stack is not written — that is `onToolError`'s job, for a tracker that wants it.
797
804
  The caller still receives the scrubbed envelope in every case: the raw text
798
805
  reaches your server-side record, never the response. → ADR 0042
package/llms/server.2.txt CHANGED
@@ -103,7 +103,7 @@ Runtime requirements and boundaries:
103
103
  - **Origin trust and navigation lock-down.** A `postMessage` bridge has no loopback `Host` header,
104
104
  so `createLocalHostGuard` does not apply. `serveBridge` validates the native container-reported
105
105
  `origin` against the exact `origins` allow-list, strips `host`, `origin`, `x-forwarded-for`,
106
- `x-real-ip` and `forwarded` from every frame, refuses a handler with `trustProxy: true`, and
106
+ `x-real-ip` and `forwarded` from every frame, refuses a handler configured with `trustProxy`, and
107
107
  optionally verifies a per-start `secret` in constant time. Refusal reasons are logged on the host
108
108
  and never disclosed to the window. Because any page a WebView navigates to receives
109
109
  `window.ReactNativeWebView`, always lock navigation down in the WebView itself
@@ -147,8 +147,8 @@ This endpoint is HTTP-only and cannot be multipart or exposed as a tool. The
147
147
  router sets `ctx.rawBody` before JSON/Zod validation, so `onError` can inspect it
148
148
  after malformed JSON or a schema failure. Endpoints without `rawBody: true` do
149
149
  not retain the text. `maxJsonBodyBytes` may also be set once on `createServer` /
150
- `createHandler`; a route value wins. Both limits are opt-in and abort an
151
- oversized stream before it is fully buffered. → ADR 0051
150
+ `createHandler`; a route value wins. Without either the ceiling is 1 MiB; every
151
+ limit aborts an oversized stream before it is fully buffered. → ADR 0051, ADR 0340
152
152
 
153
153
  ## Safelisted request bodies (beacons)
154
154
 
@@ -452,11 +452,16 @@ contract route does.
452
452
 
453
453
  ### Serving files & Range requests
454
454
 
455
- `staticRoute(prefix, dir, { cacheControl })` serves a directory: it checks
456
- containment, then answers the file through `serveFile`, so a static image or
457
- video carries `ETag`, `Last-Modified` and `Accept-Ranges`, revalidates to `304`
458
- and seeks with `206`. `cacheControl` sets `Cache-Control` on every answer; by
459
- default none is sent.
455
+ `staticRoute(prefix, dir, { cacheControl, allowedDotNames })` serves a directory:
456
+ it checks containment, then answers the file through `serveFile`, so a static
457
+ image or video carries `ETag`, `Last-Modified` and `Accept-Ranges`, revalidates
458
+ to `304` and seeks with `206`. `cacheControl` sets `Cache-Control` on every
459
+ answer; by default none is sent.
460
+
461
+ A path with a segment that starts with a dot — `/.env`, `/.git/config`,
462
+ `/assets/.npmrc` — answers `404`, so a hidden file that ends up in the served
463
+ directory never leaves it. Name the ones you mean to publish:
464
+ `allowedDotNames: ['.well-known']`.
460
465
 
461
466
  ```ts
462
467
  import { createServer, staticRoute } from 'stitchkit/server'
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
@@ -138,7 +138,24 @@ test('every model call goes through the spend gateway', async () => {
138
138
  root: 'src',
139
139
  policy: {
140
140
  modules: [
141
- { module: 'stitchkit/agent-runtime/openrouter', symbols: ['openRouterProvider'] },
141
+ {
142
+ module: 'stitchkit/agent-runtime/openrouter',
143
+ symbols: [
144
+ 'openRouterProvider',
145
+ 'createOpenRouterClient',
146
+ 'openRouterRequestJson',
147
+ 'openRouterRequestStream',
148
+ 'openRouterSystemOne',
149
+ 'openRouterAudioTranscription',
150
+ 'openRouterAudioSpeech',
151
+ 'openRouterGenerateImages',
152
+ 'openRouterSubmitVideo',
153
+ 'openRouterGetVideo',
154
+ 'openRouterDownloadVideo',
155
+ 'openRouterEmbeddings',
156
+ 'openRouterRerank',
157
+ ],
158
+ },
142
159
  { module: 'stitchkit/agent-runtime/openai', symbols: ['openAiProvider'] },
143
160
  { module: 'stitchkit/agent-runtime/anthropic', symbols: ['anthropicProvider'] },
144
161
  ],
@@ -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