stitchkit 0.134.1 → 0.135.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 (1169) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +7 -7
  3. package/dist/agent-executor/acp/v1-connect.d.ts +1 -1
  4. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  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/json-rpc-peer.d.ts +1 -1
  8. package/dist/agent-executor/json-rpc-peer.d.ts.map +1 -1
  9. package/dist/agent-runtime/browser/browser-control-contract.d.ts +1364 -0
  10. package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -0
  11. package/dist/agent-runtime/browser/browser-controller-view.d.ts +44 -0
  12. package/dist/agent-runtime/browser/browser-controller-view.d.ts.map +1 -0
  13. package/dist/agent-runtime/browser/browser-controller.d.ts +53 -0
  14. package/dist/agent-runtime/browser/browser-controller.d.ts.map +1 -0
  15. package/dist/agent-runtime/browser/control-interaction-schema.d.ts.map +1 -0
  16. package/dist/agent-runtime/browser/control-schema.d.ts +1378 -0
  17. package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -0
  18. package/dist/agent-runtime/browser/control-view.d.ts +64 -0
  19. package/dist/agent-runtime/browser/control-view.d.ts.map +1 -0
  20. package/dist/agent-runtime/browser/react.d.ts.map +1 -0
  21. package/dist/agent-runtime/coding/coding-discovery.d.ts +25 -0
  22. package/dist/agent-runtime/coding/coding-discovery.d.ts.map +1 -0
  23. package/dist/agent-runtime/coding/coding-sandbox.d.ts +8 -0
  24. package/dist/agent-runtime/coding/coding-sandbox.d.ts.map +1 -0
  25. package/dist/agent-runtime/coding/coding-search-automaton.d.ts.map +1 -0
  26. package/dist/agent-runtime/coding/coding-search-case-fold.d.ts.map +1 -0
  27. package/dist/agent-runtime/coding/coding-search-class-ranges.d.ts.map +1 -0
  28. package/dist/agent-runtime/coding/coding-search-contract.d.ts.map +1 -0
  29. package/dist/agent-runtime/coding/coding-search-limits.d.ts.map +1 -0
  30. package/dist/agent-runtime/coding/coding-search-matcher.d.ts.map +1 -0
  31. package/dist/agent-runtime/coding/coding-search-output.d.ts.map +1 -0
  32. package/dist/agent-runtime/coding/coding-search-regex-syntax.d.ts.map +1 -0
  33. package/dist/agent-runtime/coding/coding-search-unit-classes.d.ts.map +1 -0
  34. package/dist/agent-runtime/coding/coding-shell-process.d.ts +36 -0
  35. package/dist/agent-runtime/coding/coding-shell-process.d.ts.map +1 -0
  36. package/dist/agent-runtime/coding/coding-tool-contract.d.ts +261 -0
  37. package/dist/agent-runtime/coding/coding-tool-contract.d.ts.map +1 -0
  38. package/dist/agent-runtime/coding/coding-tool-files.d.ts.map +1 -0
  39. package/dist/agent-runtime/coding/coding-tool-listing.d.ts.map +1 -0
  40. package/dist/agent-runtime/coding/coding-tool-paths.d.ts +53 -0
  41. package/dist/agent-runtime/coding/coding-tool-paths.d.ts.map +1 -0
  42. package/dist/agent-runtime/coding/coding-tool-refusals.d.ts.map +1 -0
  43. package/dist/agent-runtime/coding/coding-tool-search-patch.d.ts.map +1 -0
  44. package/dist/agent-runtime/coding/coding-tool-search.d.ts +113 -0
  45. package/dist/agent-runtime/coding/coding-tool-search.d.ts.map +1 -0
  46. package/dist/agent-runtime/coding/coding-tool-shell.d.ts.map +1 -0
  47. package/dist/agent-runtime/coding/coding-tool-utf8.d.ts.map +1 -0
  48. package/dist/agent-runtime/coding/coding-tools.d.ts.map +1 -0
  49. package/dist/agent-runtime/coding/contained-scan-budget.d.ts.map +1 -0
  50. package/dist/agent-runtime/coding/contained-scan-contract.d.ts.map +1 -0
  51. package/dist/agent-runtime/coding/contained-scan.d.ts +56 -0
  52. package/dist/agent-runtime/coding/contained-scan.d.ts.map +1 -0
  53. package/dist/agent-runtime/coding/workspace-glob.d.ts.map +1 -0
  54. package/dist/agent-runtime/context-issue.d.ts +1 -1
  55. package/dist/agent-runtime/context-issue.d.ts.map +1 -1
  56. package/dist/agent-runtime/deferred-tool-types.d.ts +3 -1
  57. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
  58. package/dist/agent-runtime/harness/harness-contract.d.ts +206 -0
  59. package/dist/agent-runtime/harness/harness-contract.d.ts.map +1 -0
  60. package/dist/agent-runtime/harness/harness-control.d.ts +34 -0
  61. package/dist/agent-runtime/harness/harness-control.d.ts.map +1 -0
  62. package/dist/agent-runtime/harness/harness-file-resources.d.ts +33 -0
  63. package/dist/agent-runtime/harness/harness-file-resources.d.ts.map +1 -0
  64. package/dist/agent-runtime/harness/harness-resources.d.ts.map +1 -0
  65. package/dist/agent-runtime/harness/harness.d.ts +15 -0
  66. package/dist/agent-runtime/harness/harness.d.ts.map +1 -0
  67. package/dist/agent-runtime/history/compaction.d.ts +103 -0
  68. package/dist/agent-runtime/history/compaction.d.ts.map +1 -0
  69. package/dist/agent-runtime/history/history.d.ts +93 -0
  70. package/dist/agent-runtime/history/history.d.ts.map +1 -0
  71. package/dist/agent-runtime/history/run-history-parts.d.ts +14 -0
  72. package/dist/agent-runtime/history/run-history-parts.d.ts.map +1 -0
  73. package/dist/agent-runtime/loop/admission-lanes.d.ts +35 -0
  74. package/dist/agent-runtime/loop/admission-lanes.d.ts.map +1 -0
  75. package/dist/agent-runtime/loop/coordinator.d.ts.map +1 -0
  76. package/dist/agent-runtime/loop/deferred-tool-search.d.ts +9 -0
  77. package/dist/agent-runtime/loop/deferred-tool-search.d.ts.map +1 -0
  78. package/dist/agent-runtime/loop/deferred-tool-selection.d.ts +32 -0
  79. package/dist/agent-runtime/loop/deferred-tool-selection.d.ts.map +1 -0
  80. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts +19 -0
  81. package/dist/agent-runtime/loop/deferred-tools-internal.d.ts.map +1 -0
  82. package/dist/agent-runtime/loop/deferred-tools.d.ts +4 -0
  83. package/dist/agent-runtime/loop/deferred-tools.d.ts.map +1 -0
  84. package/dist/agent-runtime/loop/injection.d.ts +28 -0
  85. package/dist/agent-runtime/loop/injection.d.ts.map +1 -0
  86. package/dist/agent-runtime/loop/invocation-attempt.d.ts +32 -0
  87. package/dist/agent-runtime/loop/invocation-attempt.d.ts.map +1 -0
  88. package/dist/agent-runtime/loop/invocation-failure.d.ts.map +1 -0
  89. package/dist/agent-runtime/loop/invocation-payload.d.ts +38 -0
  90. package/dist/agent-runtime/loop/invocation-payload.d.ts.map +1 -0
  91. package/dist/agent-runtime/loop/invocation-read.d.ts +134 -0
  92. package/dist/agent-runtime/loop/invocation-read.d.ts.map +1 -0
  93. package/dist/agent-runtime/loop/invocation-spend.d.ts +9 -0
  94. package/dist/agent-runtime/loop/invocation-spend.d.ts.map +1 -0
  95. package/dist/agent-runtime/loop/invocation-stream.d.ts +20 -0
  96. package/dist/agent-runtime/loop/invocation-stream.d.ts.map +1 -0
  97. package/dist/agent-runtime/loop/invocations.d.ts +63 -0
  98. package/dist/agent-runtime/loop/invocations.d.ts.map +1 -0
  99. package/dist/agent-runtime/loop/managed-tools.d.ts +20 -0
  100. package/dist/agent-runtime/loop/managed-tools.d.ts.map +1 -0
  101. package/dist/agent-runtime/loop/observability.d.ts +579 -0
  102. package/dist/agent-runtime/loop/observability.d.ts.map +1 -0
  103. package/dist/agent-runtime/loop/owned-provider-stream.d.ts.map +1 -0
  104. package/dist/agent-runtime/loop/provider-origin.d.ts +17 -0
  105. package/dist/agent-runtime/loop/provider-origin.d.ts.map +1 -0
  106. package/dist/agent-runtime/loop/provider-stream-parts.d.ts +5 -0
  107. package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -0
  108. package/dist/agent-runtime/loop/provider-stream-segments.d.ts +63 -0
  109. package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -0
  110. package/dist/agent-runtime/loop/retry-policy.d.ts +49 -0
  111. package/dist/agent-runtime/loop/retry-policy.d.ts.map +1 -0
  112. package/dist/agent-runtime/loop/run-acquisition.d.ts +24 -0
  113. package/dist/agent-runtime/loop/run-acquisition.d.ts.map +1 -0
  114. package/dist/agent-runtime/loop/run-approval.d.ts +82 -0
  115. package/dist/agent-runtime/loop/run-approval.d.ts.map +1 -0
  116. package/dist/agent-runtime/loop/run-complete-retry.d.ts +24 -0
  117. package/dist/agent-runtime/loop/run-complete-retry.d.ts.map +1 -0
  118. package/dist/agent-runtime/loop/run-complete-stream.d.ts +9 -0
  119. package/dist/agent-runtime/loop/run-complete-stream.d.ts.map +1 -0
  120. package/dist/agent-runtime/loop/run-complete-types.d.ts +171 -0
  121. package/dist/agent-runtime/loop/run-complete-types.d.ts.map +1 -0
  122. package/dist/agent-runtime/loop/run-complete.d.ts +25 -0
  123. package/dist/agent-runtime/loop/run-complete.d.ts.map +1 -0
  124. package/dist/agent-runtime/loop/run-driver-compose.d.ts +21 -0
  125. package/dist/agent-runtime/loop/run-driver-compose.d.ts.map +1 -0
  126. package/dist/agent-runtime/loop/run-execution-state.d.ts +177 -0
  127. package/dist/agent-runtime/loop/run-execution-state.d.ts.map +1 -0
  128. package/dist/agent-runtime/loop/run-execution.d.ts +22 -0
  129. package/dist/agent-runtime/loop/run-execution.d.ts.map +1 -0
  130. package/dist/agent-runtime/loop/run-failure.d.ts +21 -0
  131. package/dist/agent-runtime/loop/run-failure.d.ts.map +1 -0
  132. package/dist/agent-runtime/loop/run-loop-events.d.ts +126 -0
  133. package/dist/agent-runtime/loop/run-loop-events.d.ts.map +1 -0
  134. package/dist/agent-runtime/loop/run-model-attempts.d.ts +6 -0
  135. package/dist/agent-runtime/loop/run-model-attempts.d.ts.map +1 -0
  136. package/dist/agent-runtime/loop/run-model-messages.d.ts +9 -0
  137. package/dist/agent-runtime/loop/run-model-messages.d.ts.map +1 -0
  138. package/dist/agent-runtime/loop/run-model-step.d.ts +43 -0
  139. package/dist/agent-runtime/loop/run-model-step.d.ts.map +1 -0
  140. package/dist/agent-runtime/loop/run-model-stream.d.ts +27 -0
  141. package/dist/agent-runtime/loop/run-model-stream.d.ts.map +1 -0
  142. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts +32 -0
  143. package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts.map +1 -0
  144. package/dist/agent-runtime/loop/run-prompt-history.d.ts +53 -0
  145. package/dist/agent-runtime/loop/run-prompt-history.d.ts.map +1 -0
  146. package/dist/agent-runtime/loop/run-provider-ledger.d.ts +32 -0
  147. package/dist/agent-runtime/loop/run-provider-ledger.d.ts.map +1 -0
  148. package/dist/agent-runtime/loop/run-step-barriers.d.ts +120 -0
  149. package/dist/agent-runtime/loop/run-step-barriers.d.ts.map +1 -0
  150. package/dist/agent-runtime/loop/run-step-helpers.d.ts +50 -0
  151. package/dist/agent-runtime/loop/run-step-helpers.d.ts.map +1 -0
  152. package/dist/agent-runtime/loop/run-step-prepare.d.ts +34 -0
  153. package/dist/agent-runtime/loop/run-step-prepare.d.ts.map +1 -0
  154. package/dist/agent-runtime/loop/run-step-spend.d.ts +394 -0
  155. package/dist/agent-runtime/loop/run-step-spend.d.ts.map +1 -0
  156. package/dist/agent-runtime/loop/run-stream-parts.d.ts +34 -0
  157. package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -0
  158. package/dist/agent-runtime/loop/run-stream-recorded.d.ts +8 -0
  159. package/dist/agent-runtime/loop/run-stream-recorded.d.ts.map +1 -0
  160. package/dist/agent-runtime/loop/run-stream-step-text.d.ts +47 -0
  161. package/dist/agent-runtime/loop/run-stream-step-text.d.ts.map +1 -0
  162. package/dist/agent-runtime/loop/run-terminal.d.ts +11 -0
  163. package/dist/agent-runtime/loop/run-terminal.d.ts.map +1 -0
  164. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts +36 -0
  165. package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts.map +1 -0
  166. package/dist/agent-runtime/loop/run-tool-approval-records.d.ts +24 -0
  167. package/dist/agent-runtime/loop/run-tool-approval-records.d.ts.map +1 -0
  168. package/dist/agent-runtime/loop/run-tool-call.d.ts +119 -0
  169. package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -0
  170. package/dist/agent-runtime/loop/run-tool-errors.d.ts.map +1 -0
  171. package/dist/agent-runtime/loop/run-tool-executor.d.ts +42 -0
  172. package/dist/agent-runtime/loop/run-tool-executor.d.ts.map +1 -0
  173. package/dist/agent-runtime/loop/run-tool-progress.d.ts +21 -0
  174. package/dist/agent-runtime/loop/run-tool-progress.d.ts.map +1 -0
  175. package/dist/agent-runtime/loop/run-tool-slots.d.ts +114 -0
  176. package/dist/agent-runtime/loop/run-tool-slots.d.ts.map +1 -0
  177. package/dist/agent-runtime/loop/run-turn-preparation.d.ts +25 -0
  178. package/dist/agent-runtime/loop/run-turn-preparation.d.ts.map +1 -0
  179. package/dist/agent-runtime/loop/run-unacquired.d.ts +19 -0
  180. package/dist/agent-runtime/loop/run-unacquired.d.ts.map +1 -0
  181. package/dist/agent-runtime/loop/runtime-admission-gate.d.ts.map +1 -0
  182. package/dist/agent-runtime/loop/runtime-control.d.ts +9 -0
  183. package/dist/agent-runtime/loop/runtime-control.d.ts.map +1 -0
  184. package/dist/agent-runtime/loop/runtime-recovery.d.ts +10 -0
  185. package/dist/agent-runtime/loop/runtime-recovery.d.ts.map +1 -0
  186. package/dist/agent-runtime/loop/runtime-state.d.ts +36 -0
  187. package/dist/agent-runtime/loop/runtime-state.d.ts.map +1 -0
  188. package/dist/agent-runtime/loop/runtime-submit.d.ts +5 -0
  189. package/dist/agent-runtime/loop/runtime-submit.d.ts.map +1 -0
  190. package/dist/agent-runtime/loop/runtime.d.ts +352 -0
  191. package/dist/agent-runtime/loop/runtime.d.ts.map +1 -0
  192. package/dist/agent-runtime/loop/state-slots.d.ts +48 -0
  193. package/dist/agent-runtime/loop/state-slots.d.ts.map +1 -0
  194. package/dist/agent-runtime/loop/state-tools.d.ts +117 -0
  195. package/dist/agent-runtime/loop/state-tools.d.ts.map +1 -0
  196. package/dist/agent-runtime/protocol.d.ts +1 -1
  197. package/dist/agent-runtime/protocol.d.ts.map +1 -1
  198. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts +15 -0
  199. package/dist/agent-runtime/providers/ai-sdk-convert.d.ts.map +1 -0
  200. package/dist/agent-runtime/providers/ai-sdk.d.ts +31 -0
  201. package/dist/agent-runtime/providers/ai-sdk.d.ts.map +1 -0
  202. package/dist/agent-runtime/providers/anthropic-media.d.ts +11 -0
  203. package/dist/agent-runtime/providers/anthropic-media.d.ts.map +1 -0
  204. package/dist/agent-runtime/providers/anthropic-messages.d.ts +25 -0
  205. package/dist/agent-runtime/providers/anthropic-messages.d.ts.map +1 -0
  206. package/dist/agent-runtime/providers/anthropic-options.d.ts +80 -0
  207. package/dist/agent-runtime/providers/anthropic-options.d.ts.map +1 -0
  208. package/dist/agent-runtime/providers/anthropic-response.d.ts +19 -0
  209. package/dist/agent-runtime/providers/anthropic-response.d.ts.map +1 -0
  210. package/dist/agent-runtime/providers/anthropic-sse.d.ts.map +1 -0
  211. package/dist/agent-runtime/providers/anthropic.d.ts.map +1 -0
  212. package/dist/agent-runtime/providers/models-driver-step.d.ts +212 -0
  213. package/dist/agent-runtime/providers/models-driver-step.d.ts.map +1 -0
  214. package/dist/agent-runtime/providers/models-driver-telemetry.d.ts.map +1 -0
  215. package/dist/agent-runtime/providers/models-driver.d.ts +235 -0
  216. package/dist/agent-runtime/providers/models-driver.d.ts.map +1 -0
  217. package/dist/agent-runtime/providers/models.d.ts.map +1 -0
  218. package/dist/agent-runtime/providers/openai-messages.d.ts.map +1 -0
  219. package/dist/agent-runtime/providers/openai-options.d.ts +91 -0
  220. package/dist/agent-runtime/providers/openai-options.d.ts.map +1 -0
  221. package/dist/agent-runtime/providers/openai-response.d.ts +77 -0
  222. package/dist/agent-runtime/providers/openai-response.d.ts.map +1 -0
  223. package/dist/agent-runtime/providers/openai-sse-state.d.ts.map +1 -0
  224. package/dist/agent-runtime/providers/openai-sse.d.ts.map +1 -0
  225. package/dist/agent-runtime/providers/openai.d.ts.map +1 -0
  226. package/dist/agent-runtime/providers/openrouter-admission.d.ts +85 -0
  227. package/dist/agent-runtime/providers/openrouter-admission.d.ts.map +1 -0
  228. package/dist/agent-runtime/providers/openrouter-benchmarks.d.ts.map +1 -0
  229. package/dist/agent-runtime/providers/openrouter-catalog-cache.d.ts.map +1 -0
  230. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts +82 -0
  231. package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts.map +1 -0
  232. package/dist/agent-runtime/providers/openrouter-catalog.d.ts.map +1 -0
  233. package/dist/agent-runtime/providers/openrouter-models.d.ts.map +1 -0
  234. package/dist/agent-runtime/providers/openrouter-options.d.ts +136 -0
  235. package/dist/agent-runtime/providers/openrouter-options.d.ts.map +1 -0
  236. package/dist/agent-runtime/providers/openrouter-response.d.ts +22 -0
  237. package/dist/agent-runtime/providers/openrouter-response.d.ts.map +1 -0
  238. package/dist/agent-runtime/providers/openrouter-route.d.ts.map +1 -0
  239. package/dist/agent-runtime/providers/openrouter-spend.d.ts +24 -0
  240. package/dist/agent-runtime/providers/openrouter-spend.d.ts.map +1 -0
  241. package/dist/agent-runtime/providers/openrouter.d.ts.map +1 -0
  242. package/dist/agent-runtime/providers/provider-cache.d.ts +30 -0
  243. package/dist/agent-runtime/providers/provider-cache.d.ts.map +1 -0
  244. package/dist/agent-runtime/providers/provider-content.d.ts.map +1 -0
  245. package/dist/agent-runtime/providers/provider-failure.d.ts +97 -0
  246. package/dist/agent-runtime/providers/provider-failure.d.ts.map +1 -0
  247. package/dist/agent-runtime/providers/provider-history.d.ts +13 -0
  248. package/dist/agent-runtime/providers/provider-history.d.ts.map +1 -0
  249. package/dist/agent-runtime/providers/provider-http.d.ts.map +1 -0
  250. package/dist/agent-runtime/providers/provider-journal.d.ts.map +1 -0
  251. package/dist/agent-runtime/providers/provider-json-schema-strip.d.ts.map +1 -0
  252. package/dist/agent-runtime/providers/provider-json-schema.d.ts +31 -0
  253. package/dist/agent-runtime/providers/provider-json-schema.d.ts.map +1 -0
  254. package/dist/agent-runtime/providers/provider-media.d.ts +49 -0
  255. package/dist/agent-runtime/providers/provider-media.d.ts.map +1 -0
  256. package/dist/agent-runtime/providers/provider-openai-chat-helpers.d.ts +27 -0
  257. package/dist/agent-runtime/providers/provider-openai-chat-helpers.d.ts.map +1 -0
  258. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts +25 -0
  259. package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts.map +1 -0
  260. package/dist/agent-runtime/providers/provider-openai-chat.d.ts +27 -0
  261. package/dist/agent-runtime/providers/provider-openai-chat.d.ts.map +1 -0
  262. package/dist/agent-runtime/providers/provider-sse.d.ts.map +1 -0
  263. package/dist/agent-runtime/providers/provider-usage.d.ts +24 -0
  264. package/dist/agent-runtime/providers/provider-usage.d.ts.map +1 -0
  265. package/dist/agent-runtime/realtime/harness-realtime.d.ts +53 -0
  266. package/dist/agent-runtime/realtime/harness-realtime.d.ts.map +1 -0
  267. package/dist/agent-runtime/sandbox/sandbox-binding.d.ts.map +1 -0
  268. package/dist/agent-runtime/sandbox/sandbox-broker.d.ts.map +1 -0
  269. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts.map +1 -0
  270. package/dist/agent-runtime/sandbox/sandbox-bubblewrap-storage.d.ts.map +1 -0
  271. package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts.map +1 -0
  272. package/dist/agent-runtime/sandbox/sandbox-coding-adapter.d.ts.map +1 -0
  273. package/dist/agent-runtime/sandbox/sandbox-contract.d.ts.map +1 -0
  274. package/dist/agent-runtime/sandbox/sandbox-process-linux.d.ts.map +1 -0
  275. package/dist/agent-runtime/sandbox/sandbox-process-macos.d.ts.map +1 -0
  276. package/dist/agent-runtime/sandbox/sandbox-process-owner.d.ts +19 -0
  277. package/dist/agent-runtime/sandbox/sandbox-process-owner.d.ts.map +1 -0
  278. package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts.map +1 -0
  279. package/dist/agent-runtime/sandbox/sandbox-process-wrapper.d.ts.map +1 -0
  280. package/dist/agent-runtime/sandbox/sandbox-process.d.ts +8 -0
  281. package/dist/agent-runtime/sandbox/sandbox-process.d.ts.map +1 -0
  282. package/dist/agent-runtime/sandbox/sandbox-session.d.ts.map +1 -0
  283. package/dist/agent-runtime/sandbox/sandbox.d.ts +125 -0
  284. package/dist/agent-runtime/sandbox/sandbox.d.ts.map +1 -0
  285. package/dist/agent-runtime/stores/archive-projection.d.ts.map +1 -0
  286. package/dist/agent-runtime/stores/archive-spill.d.ts.map +1 -0
  287. package/dist/agent-runtime/stores/branch-contract.d.ts.map +1 -0
  288. package/dist/agent-runtime/stores/branch-events.d.ts +25 -0
  289. package/dist/agent-runtime/stores/branch-events.d.ts.map +1 -0
  290. package/dist/agent-runtime/stores/branch-identities.d.ts +75 -0
  291. package/dist/agent-runtime/stores/branch-identities.d.ts.map +1 -0
  292. package/dist/agent-runtime/stores/branch-messages.d.ts +21 -0
  293. package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -0
  294. package/dist/agent-runtime/stores/branch-observations.d.ts +227 -0
  295. package/dist/agent-runtime/stores/branch-observations.d.ts.map +1 -0
  296. package/dist/agent-runtime/stores/branch-provider.d.ts.map +1 -0
  297. package/dist/agent-runtime/stores/branch-refusal.d.ts.map +1 -0
  298. package/dist/agent-runtime/stores/branch-replay.d.ts +456 -0
  299. package/dist/agent-runtime/stores/branch-replay.d.ts.map +1 -0
  300. package/dist/agent-runtime/stores/branch-runtime-tools.d.ts.map +1 -0
  301. package/dist/agent-runtime/stores/branch-source.d.ts +33 -0
  302. package/dist/agent-runtime/stores/branch-source.d.ts.map +1 -0
  303. package/dist/agent-runtime/stores/branch-transitions.d.ts.map +1 -0
  304. package/dist/agent-runtime/stores/child-blocking.d.ts.map +1 -0
  305. package/dist/agent-runtime/stores/child-budget-policy.d.ts +17 -0
  306. package/dist/agent-runtime/stores/child-budget-policy.d.ts.map +1 -0
  307. package/dist/agent-runtime/stores/child-tools.d.ts +144 -0
  308. package/dist/agent-runtime/stores/child-tools.d.ts.map +1 -0
  309. package/dist/agent-runtime/stores/children-contract.d.ts +236 -0
  310. package/dist/agent-runtime/stores/children-contract.d.ts.map +1 -0
  311. package/dist/agent-runtime/stores/children-control.d.ts.map +1 -0
  312. package/dist/agent-runtime/stores/children-spawn.d.ts.map +1 -0
  313. package/dist/agent-runtime/stores/children-state.d.ts.map +1 -0
  314. package/dist/agent-runtime/stores/children-usage.d.ts.map +1 -0
  315. package/dist/agent-runtime/stores/children.d.ts.map +1 -0
  316. package/dist/agent-runtime/stores/companion-host.d.ts +38 -0
  317. package/dist/agent-runtime/stores/companion-host.d.ts.map +1 -0
  318. package/dist/agent-runtime/stores/conversations.d.ts.map +1 -0
  319. package/dist/agent-runtime/stores/event-search-postgres.d.ts.map +1 -0
  320. package/dist/agent-runtime/stores/event-search-terms.d.ts.map +1 -0
  321. package/dist/agent-runtime/stores/event-search-tools.d.ts +190 -0
  322. package/dist/agent-runtime/stores/event-search-tools.d.ts.map +1 -0
  323. package/dist/agent-runtime/stores/event-search.d.ts.map +1 -0
  324. package/dist/agent-runtime/stores/postgres-schema.d.ts.map +1 -0
  325. package/dist/agent-runtime/stores/postgres-transactions.d.ts +54 -0
  326. package/dist/agent-runtime/stores/postgres-transactions.d.ts.map +1 -0
  327. package/dist/agent-runtime/stores/postgres.d.ts +72 -0
  328. package/dist/agent-runtime/stores/postgres.d.ts.map +1 -0
  329. package/dist/agent-runtime/stores/projections.d.ts +109 -0
  330. package/dist/agent-runtime/stores/projections.d.ts.map +1 -0
  331. package/dist/agent-runtime/stores/purge.d.ts.map +1 -0
  332. package/dist/agent-runtime/stores/schedule-contract.d.ts.map +1 -0
  333. package/dist/agent-runtime/stores/schedule-dispatch.d.ts.map +1 -0
  334. package/dist/agent-runtime/stores/schedule-records.d.ts.map +1 -0
  335. package/dist/agent-runtime/stores/schedule-tools.d.ts +76 -0
  336. package/dist/agent-runtime/stores/schedule-tools.d.ts.map +1 -0
  337. package/dist/agent-runtime/stores/schedules.d.ts.map +1 -0
  338. package/dist/agent-runtime/stores/spill.d.ts +26 -0
  339. package/dist/agent-runtime/stores/spill.d.ts.map +1 -0
  340. package/dist/agent-runtime/stores/sql-events.d.ts.map +1 -0
  341. package/dist/agent-runtime/stores/sql-history.d.ts.map +1 -0
  342. package/dist/agent-runtime/stores/sql-ledger.d.ts.map +1 -0
  343. package/dist/agent-runtime/stores/sql-purge.d.ts.map +1 -0
  344. package/dist/agent-runtime/stores/sql-reads.d.ts.map +1 -0
  345. package/dist/agent-runtime/stores/sql-rows.d.ts +202 -0
  346. package/dist/agent-runtime/stores/sql-rows.d.ts.map +1 -0
  347. package/dist/agent-runtime/stores/sql-session.d.ts.map +1 -0
  348. package/dist/agent-runtime/stores/sqlite-bun.d.ts.map +1 -0
  349. package/dist/agent-runtime/stores/sqlite-node.d.ts.map +1 -0
  350. package/dist/agent-runtime/stores/sqlite-purge.d.ts +6 -0
  351. package/dist/agent-runtime/stores/sqlite-purge.d.ts.map +1 -0
  352. package/dist/agent-runtime/stores/sqlite-schema.d.ts +7 -0
  353. package/dist/agent-runtime/stores/sqlite-schema.d.ts.map +1 -0
  354. package/dist/agent-runtime/stores/sqlite-transactions.d.ts +29 -0
  355. package/dist/agent-runtime/stores/sqlite-transactions.d.ts.map +1 -0
  356. package/dist/agent-runtime/stores/sqlite.d.ts +33 -0
  357. package/dist/agent-runtime/stores/sqlite.d.ts.map +1 -0
  358. package/dist/agent-runtime/stores/store-archive.d.ts.map +1 -0
  359. package/dist/agent-runtime/stores/store-branch.d.ts.map +1 -0
  360. package/dist/agent-runtime/stores/store-capabilities.d.ts.map +1 -0
  361. package/dist/agent-runtime/stores/store-create.d.ts.map +1 -0
  362. package/dist/agent-runtime/stores/store-driver-contract.d.ts +1016 -0
  363. package/dist/agent-runtime/stores/store-driver-contract.d.ts.map +1 -0
  364. package/dist/agent-runtime/stores/store-event-once.d.ts +37 -0
  365. package/dist/agent-runtime/stores/store-event-once.d.ts.map +1 -0
  366. package/dist/agent-runtime/stores/store-events.d.ts +2231 -0
  367. package/dist/agent-runtime/stores/store-events.d.ts.map +1 -0
  368. package/dist/agent-runtime/stores/store-memory-archive.d.ts.map +1 -0
  369. package/dist/agent-runtime/stores/store-memory-events.d.ts +7 -0
  370. package/dist/agent-runtime/stores/store-memory-events.d.ts.map +1 -0
  371. package/dist/agent-runtime/stores/store-memory.d.ts.map +1 -0
  372. package/dist/agent-runtime/stores/store-migrations/v1-to-v2.d.ts +6 -0
  373. package/dist/agent-runtime/stores/store-migrations/v1-to-v2.d.ts.map +1 -0
  374. package/dist/agent-runtime/stores/store-migrations/v2-to-v3.d.ts +14 -0
  375. package/dist/agent-runtime/stores/store-migrations/v2-to-v3.d.ts.map +1 -0
  376. package/dist/agent-runtime/stores/store-migrations/v3-to-v4.d.ts +4 -0
  377. package/dist/agent-runtime/stores/store-migrations/v3-to-v4.d.ts.map +1 -0
  378. package/dist/agent-runtime/stores/store-mutate.d.ts.map +1 -0
  379. package/dist/agent-runtime/stores/store-purge.d.ts.map +1 -0
  380. package/dist/agent-runtime/stores/store-reads.d.ts +29 -0
  381. package/dist/agent-runtime/stores/store-reads.d.ts.map +1 -0
  382. package/dist/agent-runtime/stores/store-reduce-history.d.ts +10 -0
  383. package/dist/agent-runtime/stores/store-reduce-history.d.ts.map +1 -0
  384. package/dist/agent-runtime/stores/store-reduce-run.d.ts +14 -0
  385. package/dist/agent-runtime/stores/store-reduce-run.d.ts.map +1 -0
  386. package/dist/agent-runtime/stores/store-reduce-shared.d.ts +78 -0
  387. package/dist/agent-runtime/stores/store-reduce-shared.d.ts.map +1 -0
  388. package/dist/agent-runtime/stores/store-reduce-terminal.d.ts +6 -0
  389. package/dist/agent-runtime/stores/store-reduce-terminal.d.ts.map +1 -0
  390. package/dist/agent-runtime/stores/store-reducer.d.ts +24 -0
  391. package/dist/agent-runtime/stores/store-reducer.d.ts.map +1 -0
  392. package/dist/agent-runtime/stores/store-replay.d.ts.map +1 -0
  393. package/dist/agent-runtime/stores/store-snapshot.d.ts +19 -0
  394. package/dist/agent-runtime/stores/store-snapshot.d.ts.map +1 -0
  395. package/dist/agent-runtime/stores/store.d.ts +3032 -0
  396. package/dist/agent-runtime/stores/store.d.ts.map +1 -0
  397. package/dist/agent-runtime/terminal-commit.d.ts +11 -11
  398. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  399. package/dist/agent-runtime/testing/fault-bench.d.ts.map +1 -0
  400. package/dist/agent-runtime/testing/run-assertions.d.ts +63 -0
  401. package/dist/agent-runtime/testing/run-assertions.d.ts.map +1 -0
  402. package/dist/agent-runtime/testing/store-conformance-branch.d.ts +7 -0
  403. package/dist/agent-runtime/testing/store-conformance-branch.d.ts.map +1 -0
  404. package/dist/agent-runtime/testing/store-conformance-capabilities.d.ts +6 -0
  405. package/dist/agent-runtime/testing/store-conformance-capabilities.d.ts.map +1 -0
  406. package/dist/agent-runtime/testing/store-conformance-event-once.d.ts +12 -0
  407. package/dist/agent-runtime/testing/store-conformance-event-once.d.ts.map +1 -0
  408. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +454 -0
  409. package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts.map +1 -0
  410. package/dist/agent-runtime/testing/store-conformance-ordering.d.ts +18 -0
  411. package/dist/agent-runtime/testing/store-conformance-ordering.d.ts.map +1 -0
  412. package/dist/agent-runtime/testing/store-conformance-seed.d.ts +8 -0
  413. package/dist/agent-runtime/testing/store-conformance-seed.d.ts.map +1 -0
  414. package/dist/agent-runtime/testing/store-conformance-support.d.ts +140 -0
  415. package/dist/agent-runtime/testing/store-conformance-support.d.ts.map +1 -0
  416. package/dist/agent-runtime/testing/store-conformance-terminal.d.ts +12 -0
  417. package/dist/agent-runtime/testing/store-conformance-terminal.d.ts.map +1 -0
  418. package/dist/agent-runtime/testing/store-conformance.d.ts +71 -0
  419. package/dist/agent-runtime/testing/store-conformance.d.ts.map +1 -0
  420. package/dist/agent-runtime/testing/testing.d.ts +46 -0
  421. package/dist/agent-runtime/testing/testing.d.ts.map +1 -0
  422. package/dist/application/grammy.d.ts +1 -1
  423. package/dist/browser/client-executors.d.ts.map +1 -1
  424. package/dist/browser/client.d.ts +3 -2
  425. package/dist/browser/client.d.ts.map +1 -1
  426. package/dist/browser/contract-identity.d.ts +1 -1
  427. package/dist/browser/http-fetch.d.ts +1 -1
  428. package/dist/browser/http.d.ts +6 -3
  429. package/dist/browser/http.d.ts.map +1 -1
  430. package/dist/browser/socket-io-contract.d.ts +1 -1
  431. package/dist/contract/bridge-envelope.d.ts +1 -1
  432. package/dist/contract/client-types.d.ts +4 -3
  433. package/dist/contract/client-types.d.ts.map +1 -1
  434. package/dist/contract/define.d.ts +2 -2
  435. package/dist/contract/errors-factory.d.ts +1 -1
  436. package/dist/contract/fingerprint.d.ts +1 -1
  437. package/dist/device-relay/hub.d.ts +1 -1
  438. package/dist/entrypoints/agent-executor/acp.js +38 -12
  439. package/dist/entrypoints/agent-executor/claude-sdk.js +1 -1
  440. package/dist/entrypoints/agent-executor/codex.js +2 -2
  441. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +3 -3
  442. package/dist/entrypoints/agent-executor/testing.js +3 -3
  443. package/dist/entrypoints/agent-executor.js +1 -1
  444. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +3 -3
  445. package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -1
  446. package/dist/entrypoints/agent-runtime/ai-sdk.js +9 -8
  447. package/dist/entrypoints/agent-runtime/anthropic.d.ts +3 -3
  448. package/dist/entrypoints/agent-runtime/anthropic.d.ts.map +1 -1
  449. package/dist/entrypoints/agent-runtime/anthropic.js +72 -18
  450. package/dist/entrypoints/agent-runtime/browser.d.ts +6 -6
  451. package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
  452. package/dist/entrypoints/agent-runtime/browser.js +39 -39
  453. package/dist/entrypoints/agent-runtime/coding-tools.d.ts +1 -1
  454. package/dist/entrypoints/agent-runtime/coding-tools.d.ts.map +1 -1
  455. package/dist/entrypoints/agent-runtime/coding-tools.js +2 -2
  456. package/dist/entrypoints/agent-runtime/harness.d.ts +1 -1
  457. package/dist/entrypoints/agent-runtime/harness.d.ts.map +1 -1
  458. package/dist/entrypoints/agent-runtime/harness.js +27 -28
  459. package/dist/entrypoints/agent-runtime/openai.d.ts +3 -3
  460. package/dist/entrypoints/agent-runtime/openai.d.ts.map +1 -1
  461. package/dist/entrypoints/agent-runtime/openai.js +9 -9
  462. package/dist/entrypoints/agent-runtime/openrouter.d.ts +10 -10
  463. package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
  464. package/dist/entrypoints/agent-runtime/openrouter.js +167 -113
  465. package/dist/entrypoints/agent-runtime/postgres.d.ts +2 -2
  466. package/dist/entrypoints/agent-runtime/postgres.d.ts.map +1 -1
  467. package/dist/entrypoints/agent-runtime/postgres.js +11 -11
  468. package/dist/entrypoints/agent-runtime/react.d.ts +1 -1
  469. package/dist/entrypoints/agent-runtime/react.d.ts.map +1 -1
  470. package/dist/entrypoints/agent-runtime/react.js +1 -1
  471. package/dist/entrypoints/agent-runtime/realtime.d.ts +1 -1
  472. package/dist/entrypoints/agent-runtime/realtime.d.ts.map +1 -1
  473. package/dist/entrypoints/agent-runtime/realtime.js +5 -5
  474. package/dist/entrypoints/agent-runtime/sandbox.d.ts +9 -9
  475. package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -1
  476. package/dist/entrypoints/agent-runtime/sandbox.js +220 -93
  477. package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts +1 -1
  478. package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts.map +1 -1
  479. package/dist/entrypoints/agent-runtime/sqlite/bun.js +8 -8
  480. package/dist/entrypoints/agent-runtime/sqlite/node.d.ts +1 -1
  481. package/dist/entrypoints/agent-runtime/sqlite/node.d.ts.map +1 -1
  482. package/dist/entrypoints/agent-runtime/sqlite/node.js +8 -8
  483. package/dist/entrypoints/agent-runtime/testing.d.ts +4 -4
  484. package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
  485. package/dist/entrypoints/agent-runtime/testing.js +21 -21
  486. package/dist/entrypoints/agent-runtime.d.ts +50 -50
  487. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  488. package/dist/entrypoints/agent-runtime.js +2853 -3107
  489. package/dist/entrypoints/bin/upgrade-cli.js +1 -1
  490. package/dist/entrypoints/cli.js +8 -9
  491. package/dist/entrypoints/files/packaging.js +2 -2
  492. package/dist/entrypoints/handler.js +2 -2
  493. package/dist/entrypoints/http.js +2 -2
  494. package/dist/entrypoints/index.js +2 -2
  495. package/dist/entrypoints/node.js +2 -2
  496. package/dist/entrypoints/react.js +1 -1
  497. package/dist/entrypoints/remote.js +2 -2
  498. package/dist/entrypoints/server.js +4 -4
  499. package/dist/entrypoints/testing.js +7 -9
  500. package/dist/entrypoints/tools/agent.js +476 -13
  501. package/dist/entrypoints/tools/connections.js +9 -7
  502. package/dist/entrypoints/tools/contract.js +4 -4
  503. package/dist/entrypoints/tools/invoker.js +7 -8
  504. package/dist/entrypoints/tools/mcp.js +11 -13
  505. package/dist/entrypoints/tools/toolkit.d.ts +6 -4
  506. package/dist/entrypoints/tools/toolkit.d.ts.map +1 -1
  507. package/dist/entrypoints/tools/toolkit.js +13 -20
  508. package/dist/entrypoints/tools.js +14 -15
  509. package/dist/files/native-packaging-layout.d.ts +1 -1
  510. package/dist/index-125ks2ec.js +17 -0
  511. package/dist/index-1w69rj9f.js +224 -0
  512. package/dist/index-1zy31r3b.js +26 -0
  513. package/dist/index-3czc3ykr.js +53 -0
  514. package/dist/index-3d2c45jn.js +77 -0
  515. package/dist/index-57sbckhv.js +271 -0
  516. package/dist/index-64t6pheq.js +2872 -0
  517. package/dist/index-73wq9abg.js +367 -0
  518. package/dist/index-7mjsb7zv.js +163 -0
  519. package/dist/index-84tp547a.js +981 -0
  520. package/dist/index-9be3tf6r.js +196 -0
  521. package/dist/index-a09r9ff0.js +76 -0
  522. package/dist/index-asnd4h2k.js +969 -0
  523. package/dist/index-b4c9dpzm.js +1210 -0
  524. package/dist/index-baba8ehy.js +53 -0
  525. package/dist/index-c24bj2r1.js +510 -0
  526. package/dist/index-cgjtj8zh.js +707 -0
  527. package/dist/index-d4at0q09.js +601 -0
  528. package/dist/index-de7b0kvz.js +215 -0
  529. package/dist/index-dm84tsd5.js +164 -0
  530. package/dist/index-fsw9wxk9.js +349 -0
  531. package/dist/index-gk6dq9ay.js +124 -0
  532. package/dist/index-gs0jw0hy.js +174 -0
  533. package/dist/index-hce3hbdg.js +121 -0
  534. package/dist/index-m2b49tvc.js +2343 -0
  535. package/dist/index-mcv7b2n0.js +3545 -0
  536. package/dist/index-n9358ydy.js +63 -0
  537. package/dist/index-npfdymav.js +409 -0
  538. package/dist/index-p9cab61p.js +305 -0
  539. package/dist/index-q86qnzzf.js +231 -0
  540. package/dist/index-qcy8et93.js +698 -0
  541. package/dist/index-refgnzy0.js +158 -0
  542. package/dist/index-rkphknhx.js +40 -0
  543. package/dist/index-v0j22shs.js +3781 -0
  544. package/dist/index-vse7x1qt.js +460 -0
  545. package/dist/index-wdb5jhas.js +51 -0
  546. package/dist/index-ws0awmzq.js +47 -0
  547. package/dist/index-wsv11dhg.js +725 -0
  548. package/dist/index-xbb8ysmq.js +40 -0
  549. package/dist/index-y0mwkgkf.js +7812 -0
  550. package/dist/index-yhwx4fwk.js +295 -0
  551. package/dist/index-z72vazf5.js +502 -0
  552. package/dist/index-zfrysr1e.js +710 -0
  553. package/dist/internal/postgres-query.d.ts +1 -1
  554. package/dist/json-schema/dialect.d.ts.map +1 -1
  555. package/dist/json-schema/string-format.d.ts.map +1 -1
  556. package/dist/react/query-client.d.ts +1 -1
  557. package/dist/server/bridge-host.d.ts +1 -1
  558. package/dist/server/bun.d.ts +1 -1
  559. package/dist/server/endpoint-dispatch.d.ts.map +1 -1
  560. package/dist/server/middleware/cors.d.ts +3 -3
  561. package/dist/server/middleware/cors.d.ts.map +1 -1
  562. package/dist/server/socket-io-config.d.ts +1 -1
  563. package/dist/service-host/identity.d.ts +1 -1
  564. package/dist/service-host/systemd-inspect.d.ts +1 -1
  565. package/dist/testing/manual-clock.d.ts +1 -1
  566. package/dist/tools/agent-call-context.d.ts +23 -0
  567. package/dist/tools/agent-call-context.d.ts.map +1 -0
  568. package/dist/tools/agent.d.ts.map +1 -1
  569. package/dist/tools/connections/types.d.ts +1 -1
  570. package/dist/tools/mcp/handler.d.ts +1 -1
  571. package/dist/tools/mcp/lazy-discovery.d.ts +1 -1
  572. package/dist/tools/mcp/mount.d.ts +1 -1
  573. package/dist/tools/mcp/stdio.d.ts +1 -1
  574. package/dist/tools/schema/flatten.d.ts.map +1 -1
  575. package/dist/tools/toolkit.d.ts +8 -6
  576. package/dist/tools/toolkit.d.ts.map +1 -1
  577. package/llms/agent-runtime-ai-sdk.txt +2 -2
  578. package/llms/agent-runtime-anthropic.txt +8 -4
  579. package/llms/agent-runtime-browser.txt +1 -1
  580. package/llms/agent-runtime-openrouter.txt +4 -4
  581. package/llms/agent-runtime-sandbox.txt +20 -7
  582. package/llms/agent-runtime-sqlite-bun.txt +1 -1
  583. package/llms/agent-runtime.2.txt +1 -1
  584. package/llms/agent-runtime.3.txt +23 -7
  585. package/llms/agent-runtime.4.txt +2 -2
  586. package/llms/agent-runtime.txt +23 -10
  587. package/llms/application.2.txt +4 -4
  588. package/llms/application.txt +4 -4
  589. package/llms/cli.2.txt +30 -6
  590. package/llms/cli.txt +2 -2
  591. package/llms/contract.txt +2 -2
  592. package/llms/files-packaging.txt +1 -1
  593. package/llms/geo.txt +1 -1
  594. package/llms/live.txt +1 -1
  595. package/llms/oauth.txt +4 -4
  596. package/llms/observability.txt +3 -3
  597. package/llms/primitives.txt +1 -1
  598. package/llms/process.2.txt +7 -7
  599. package/llms/react.txt +4 -4
  600. package/llms/server.2.txt +7 -7
  601. package/llms/server.3.txt +5 -5
  602. package/llms/server.4.txt +6 -6
  603. package/llms/server.txt +23 -11
  604. package/llms/stitchkit.2.txt +21 -14
  605. package/llms/stitchkit.3.txt +1 -1
  606. package/llms/stitchkit.txt +87 -87
  607. package/llms/telegram.txt +1 -1
  608. package/llms/testing.txt +4 -4
  609. package/llms/tools-connections.txt +1 -1
  610. package/llms/tools-toolkit.txt +3 -4
  611. package/llms/tools.2.txt +6 -6
  612. package/llms/tools.3.txt +8 -8
  613. package/llms/tools.4.txt +3 -3
  614. package/llms/upgrading-0.106.0-0.126.0.txt +1 -1
  615. package/llms/upgrading-0.128.0-0.135.0.txt +700 -0
  616. package/llms/upgrading-0.37.0-0.53.0.txt +7 -7
  617. package/llms/upgrading-0.69.0-0.95.0.txt +1 -1
  618. package/llms/upgrading-0.96.0-0.105.0.txt +1 -1
  619. package/llms/upgrading.txt +1 -1
  620. package/llms-full.txt +403 -248
  621. package/llms.txt +12 -12
  622. package/package.json +1 -1
  623. package/dist/agent-runtime/admission-lanes.d.ts +0 -35
  624. package/dist/agent-runtime/admission-lanes.d.ts.map +0 -1
  625. package/dist/agent-runtime/ai-sdk-convert.d.ts +0 -15
  626. package/dist/agent-runtime/ai-sdk-convert.d.ts.map +0 -1
  627. package/dist/agent-runtime/ai-sdk.d.ts +0 -31
  628. package/dist/agent-runtime/ai-sdk.d.ts.map +0 -1
  629. package/dist/agent-runtime/anthropic-media.d.ts +0 -11
  630. package/dist/agent-runtime/anthropic-media.d.ts.map +0 -1
  631. package/dist/agent-runtime/anthropic-messages.d.ts +0 -24
  632. package/dist/agent-runtime/anthropic-messages.d.ts.map +0 -1
  633. package/dist/agent-runtime/anthropic-options.d.ts +0 -79
  634. package/dist/agent-runtime/anthropic-options.d.ts.map +0 -1
  635. package/dist/agent-runtime/anthropic-response.d.ts +0 -19
  636. package/dist/agent-runtime/anthropic-response.d.ts.map +0 -1
  637. package/dist/agent-runtime/anthropic-sse.d.ts.map +0 -1
  638. package/dist/agent-runtime/anthropic.d.ts.map +0 -1
  639. package/dist/agent-runtime/archive-projection.d.ts.map +0 -1
  640. package/dist/agent-runtime/archive-spill.d.ts.map +0 -1
  641. package/dist/agent-runtime/branch-contract.d.ts.map +0 -1
  642. package/dist/agent-runtime/branch-events.d.ts +0 -25
  643. package/dist/agent-runtime/branch-events.d.ts.map +0 -1
  644. package/dist/agent-runtime/branch-identities.d.ts +0 -75
  645. package/dist/agent-runtime/branch-identities.d.ts.map +0 -1
  646. package/dist/agent-runtime/branch-messages.d.ts +0 -21
  647. package/dist/agent-runtime/branch-messages.d.ts.map +0 -1
  648. package/dist/agent-runtime/branch-observations.d.ts +0 -227
  649. package/dist/agent-runtime/branch-observations.d.ts.map +0 -1
  650. package/dist/agent-runtime/branch-provider.d.ts.map +0 -1
  651. package/dist/agent-runtime/branch-refusal.d.ts.map +0 -1
  652. package/dist/agent-runtime/branch-replay.d.ts +0 -456
  653. package/dist/agent-runtime/branch-replay.d.ts.map +0 -1
  654. package/dist/agent-runtime/branch-runtime-tools.d.ts.map +0 -1
  655. package/dist/agent-runtime/branch-source.d.ts +0 -33
  656. package/dist/agent-runtime/branch-source.d.ts.map +0 -1
  657. package/dist/agent-runtime/branch-transitions.d.ts.map +0 -1
  658. package/dist/agent-runtime/browser-control-contract.d.ts +0 -1364
  659. package/dist/agent-runtime/browser-control-contract.d.ts.map +0 -1
  660. package/dist/agent-runtime/browser-controller-view.d.ts +0 -44
  661. package/dist/agent-runtime/browser-controller-view.d.ts.map +0 -1
  662. package/dist/agent-runtime/browser-controller.d.ts +0 -53
  663. package/dist/agent-runtime/browser-controller.d.ts.map +0 -1
  664. package/dist/agent-runtime/child-blocking.d.ts.map +0 -1
  665. package/dist/agent-runtime/child-budget-policy.d.ts +0 -17
  666. package/dist/agent-runtime/child-budget-policy.d.ts.map +0 -1
  667. package/dist/agent-runtime/child-tools.d.ts +0 -144
  668. package/dist/agent-runtime/child-tools.d.ts.map +0 -1
  669. package/dist/agent-runtime/children-contract.d.ts +0 -236
  670. package/dist/agent-runtime/children-contract.d.ts.map +0 -1
  671. package/dist/agent-runtime/children-control.d.ts.map +0 -1
  672. package/dist/agent-runtime/children-spawn.d.ts.map +0 -1
  673. package/dist/agent-runtime/children-state.d.ts.map +0 -1
  674. package/dist/agent-runtime/children-usage.d.ts.map +0 -1
  675. package/dist/agent-runtime/children.d.ts.map +0 -1
  676. package/dist/agent-runtime/coding-discovery.d.ts +0 -25
  677. package/dist/agent-runtime/coding-discovery.d.ts.map +0 -1
  678. package/dist/agent-runtime/coding-sandbox.d.ts +0 -8
  679. package/dist/agent-runtime/coding-sandbox.d.ts.map +0 -1
  680. package/dist/agent-runtime/coding-search-automaton.d.ts.map +0 -1
  681. package/dist/agent-runtime/coding-search-case-fold.d.ts.map +0 -1
  682. package/dist/agent-runtime/coding-search-class-ranges.d.ts.map +0 -1
  683. package/dist/agent-runtime/coding-search-contract.d.ts.map +0 -1
  684. package/dist/agent-runtime/coding-search-limits.d.ts.map +0 -1
  685. package/dist/agent-runtime/coding-search-matcher.d.ts.map +0 -1
  686. package/dist/agent-runtime/coding-search-output.d.ts.map +0 -1
  687. package/dist/agent-runtime/coding-search-regex-syntax.d.ts.map +0 -1
  688. package/dist/agent-runtime/coding-search-unit-classes.d.ts.map +0 -1
  689. package/dist/agent-runtime/coding-shell-process.d.ts +0 -36
  690. package/dist/agent-runtime/coding-shell-process.d.ts.map +0 -1
  691. package/dist/agent-runtime/coding-tool-contract.d.ts +0 -261
  692. package/dist/agent-runtime/coding-tool-contract.d.ts.map +0 -1
  693. package/dist/agent-runtime/coding-tool-files.d.ts.map +0 -1
  694. package/dist/agent-runtime/coding-tool-listing.d.ts.map +0 -1
  695. package/dist/agent-runtime/coding-tool-paths.d.ts +0 -53
  696. package/dist/agent-runtime/coding-tool-paths.d.ts.map +0 -1
  697. package/dist/agent-runtime/coding-tool-refusals.d.ts.map +0 -1
  698. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +0 -1
  699. package/dist/agent-runtime/coding-tool-search.d.ts +0 -113
  700. package/dist/agent-runtime/coding-tool-search.d.ts.map +0 -1
  701. package/dist/agent-runtime/coding-tool-shell.d.ts.map +0 -1
  702. package/dist/agent-runtime/coding-tool-utf8.d.ts.map +0 -1
  703. package/dist/agent-runtime/coding-tools.d.ts.map +0 -1
  704. package/dist/agent-runtime/compaction.d.ts +0 -103
  705. package/dist/agent-runtime/compaction.d.ts.map +0 -1
  706. package/dist/agent-runtime/companion-host.d.ts +0 -38
  707. package/dist/agent-runtime/companion-host.d.ts.map +0 -1
  708. package/dist/agent-runtime/contained-scan-budget.d.ts.map +0 -1
  709. package/dist/agent-runtime/contained-scan-contract.d.ts.map +0 -1
  710. package/dist/agent-runtime/contained-scan.d.ts +0 -56
  711. package/dist/agent-runtime/contained-scan.d.ts.map +0 -1
  712. package/dist/agent-runtime/control-interaction-schema.d.ts.map +0 -1
  713. package/dist/agent-runtime/control-schema.d.ts +0 -1378
  714. package/dist/agent-runtime/control-schema.d.ts.map +0 -1
  715. package/dist/agent-runtime/control-view.d.ts +0 -64
  716. package/dist/agent-runtime/control-view.d.ts.map +0 -1
  717. package/dist/agent-runtime/conversations.d.ts.map +0 -1
  718. package/dist/agent-runtime/coordinator.d.ts.map +0 -1
  719. package/dist/agent-runtime/deferred-tool-search.d.ts +0 -9
  720. package/dist/agent-runtime/deferred-tool-search.d.ts.map +0 -1
  721. package/dist/agent-runtime/deferred-tool-selection.d.ts +0 -32
  722. package/dist/agent-runtime/deferred-tool-selection.d.ts.map +0 -1
  723. package/dist/agent-runtime/deferred-tools-internal.d.ts +0 -9
  724. package/dist/agent-runtime/deferred-tools-internal.d.ts.map +0 -1
  725. package/dist/agent-runtime/deferred-tools.d.ts +0 -4
  726. package/dist/agent-runtime/deferred-tools.d.ts.map +0 -1
  727. package/dist/agent-runtime/event-search-postgres.d.ts.map +0 -1
  728. package/dist/agent-runtime/event-search-terms.d.ts.map +0 -1
  729. package/dist/agent-runtime/event-search-tools.d.ts +0 -190
  730. package/dist/agent-runtime/event-search-tools.d.ts.map +0 -1
  731. package/dist/agent-runtime/event-search.d.ts.map +0 -1
  732. package/dist/agent-runtime/fault-bench.d.ts.map +0 -1
  733. package/dist/agent-runtime/harness-contract.d.ts +0 -206
  734. package/dist/agent-runtime/harness-contract.d.ts.map +0 -1
  735. package/dist/agent-runtime/harness-control.d.ts +0 -34
  736. package/dist/agent-runtime/harness-control.d.ts.map +0 -1
  737. package/dist/agent-runtime/harness-file-resources.d.ts +0 -33
  738. package/dist/agent-runtime/harness-file-resources.d.ts.map +0 -1
  739. package/dist/agent-runtime/harness-realtime.d.ts +0 -53
  740. package/dist/agent-runtime/harness-realtime.d.ts.map +0 -1
  741. package/dist/agent-runtime/harness-resources.d.ts.map +0 -1
  742. package/dist/agent-runtime/harness.d.ts +0 -15
  743. package/dist/agent-runtime/harness.d.ts.map +0 -1
  744. package/dist/agent-runtime/history.d.ts +0 -93
  745. package/dist/agent-runtime/history.d.ts.map +0 -1
  746. package/dist/agent-runtime/injection.d.ts +0 -28
  747. package/dist/agent-runtime/injection.d.ts.map +0 -1
  748. package/dist/agent-runtime/invocation-attempt.d.ts +0 -32
  749. package/dist/agent-runtime/invocation-attempt.d.ts.map +0 -1
  750. package/dist/agent-runtime/invocation-failure.d.ts.map +0 -1
  751. package/dist/agent-runtime/invocation-payload.d.ts +0 -38
  752. package/dist/agent-runtime/invocation-payload.d.ts.map +0 -1
  753. package/dist/agent-runtime/invocation-read.d.ts +0 -134
  754. package/dist/agent-runtime/invocation-read.d.ts.map +0 -1
  755. package/dist/agent-runtime/invocation-spend.d.ts +0 -9
  756. package/dist/agent-runtime/invocation-spend.d.ts.map +0 -1
  757. package/dist/agent-runtime/invocation-stream.d.ts +0 -20
  758. package/dist/agent-runtime/invocation-stream.d.ts.map +0 -1
  759. package/dist/agent-runtime/invocations.d.ts +0 -63
  760. package/dist/agent-runtime/invocations.d.ts.map +0 -1
  761. package/dist/agent-runtime/managed-tools.d.ts +0 -20
  762. package/dist/agent-runtime/managed-tools.d.ts.map +0 -1
  763. package/dist/agent-runtime/models-driver-step.d.ts +0 -212
  764. package/dist/agent-runtime/models-driver-step.d.ts.map +0 -1
  765. package/dist/agent-runtime/models-driver-telemetry.d.ts.map +0 -1
  766. package/dist/agent-runtime/models-driver.d.ts +0 -235
  767. package/dist/agent-runtime/models-driver.d.ts.map +0 -1
  768. package/dist/agent-runtime/models.d.ts.map +0 -1
  769. package/dist/agent-runtime/observability.d.ts +0 -579
  770. package/dist/agent-runtime/observability.d.ts.map +0 -1
  771. package/dist/agent-runtime/openai-messages.d.ts.map +0 -1
  772. package/dist/agent-runtime/openai-options.d.ts +0 -91
  773. package/dist/agent-runtime/openai-options.d.ts.map +0 -1
  774. package/dist/agent-runtime/openai-response.d.ts +0 -77
  775. package/dist/agent-runtime/openai-response.d.ts.map +0 -1
  776. package/dist/agent-runtime/openai-sse-state.d.ts.map +0 -1
  777. package/dist/agent-runtime/openai-sse.d.ts.map +0 -1
  778. package/dist/agent-runtime/openai.d.ts.map +0 -1
  779. package/dist/agent-runtime/openrouter-admission.d.ts +0 -84
  780. package/dist/agent-runtime/openrouter-admission.d.ts.map +0 -1
  781. package/dist/agent-runtime/openrouter-benchmarks.d.ts.map +0 -1
  782. package/dist/agent-runtime/openrouter-catalog-cache.d.ts.map +0 -1
  783. package/dist/agent-runtime/openrouter-catalog-query.d.ts +0 -57
  784. package/dist/agent-runtime/openrouter-catalog-query.d.ts.map +0 -1
  785. package/dist/agent-runtime/openrouter-catalog.d.ts.map +0 -1
  786. package/dist/agent-runtime/openrouter-models.d.ts.map +0 -1
  787. package/dist/agent-runtime/openrouter-options.d.ts +0 -136
  788. package/dist/agent-runtime/openrouter-options.d.ts.map +0 -1
  789. package/dist/agent-runtime/openrouter-response.d.ts +0 -22
  790. package/dist/agent-runtime/openrouter-response.d.ts.map +0 -1
  791. package/dist/agent-runtime/openrouter-route.d.ts.map +0 -1
  792. package/dist/agent-runtime/openrouter-spend.d.ts +0 -24
  793. package/dist/agent-runtime/openrouter-spend.d.ts.map +0 -1
  794. package/dist/agent-runtime/openrouter.d.ts.map +0 -1
  795. package/dist/agent-runtime/owned-provider-stream.d.ts.map +0 -1
  796. package/dist/agent-runtime/postgres-schema.d.ts.map +0 -1
  797. package/dist/agent-runtime/postgres-transactions.d.ts +0 -54
  798. package/dist/agent-runtime/postgres-transactions.d.ts.map +0 -1
  799. package/dist/agent-runtime/postgres.d.ts +0 -72
  800. package/dist/agent-runtime/postgres.d.ts.map +0 -1
  801. package/dist/agent-runtime/projections.d.ts +0 -109
  802. package/dist/agent-runtime/projections.d.ts.map +0 -1
  803. package/dist/agent-runtime/provider-cache.d.ts +0 -30
  804. package/dist/agent-runtime/provider-cache.d.ts.map +0 -1
  805. package/dist/agent-runtime/provider-content.d.ts.map +0 -1
  806. package/dist/agent-runtime/provider-failure.d.ts +0 -95
  807. package/dist/agent-runtime/provider-failure.d.ts.map +0 -1
  808. package/dist/agent-runtime/provider-history.d.ts +0 -13
  809. package/dist/agent-runtime/provider-history.d.ts.map +0 -1
  810. package/dist/agent-runtime/provider-http.d.ts.map +0 -1
  811. package/dist/agent-runtime/provider-journal.d.ts.map +0 -1
  812. package/dist/agent-runtime/provider-json-schema-strip.d.ts.map +0 -1
  813. package/dist/agent-runtime/provider-json-schema.d.ts +0 -28
  814. package/dist/agent-runtime/provider-json-schema.d.ts.map +0 -1
  815. package/dist/agent-runtime/provider-media.d.ts +0 -49
  816. package/dist/agent-runtime/provider-media.d.ts.map +0 -1
  817. package/dist/agent-runtime/provider-openai-chat-helpers.d.ts +0 -27
  818. package/dist/agent-runtime/provider-openai-chat-helpers.d.ts.map +0 -1
  819. package/dist/agent-runtime/provider-openai-chat-sse.d.ts +0 -25
  820. package/dist/agent-runtime/provider-openai-chat-sse.d.ts.map +0 -1
  821. package/dist/agent-runtime/provider-openai-chat.d.ts +0 -27
  822. package/dist/agent-runtime/provider-openai-chat.d.ts.map +0 -1
  823. package/dist/agent-runtime/provider-origin.d.ts +0 -10
  824. package/dist/agent-runtime/provider-origin.d.ts.map +0 -1
  825. package/dist/agent-runtime/provider-sse.d.ts.map +0 -1
  826. package/dist/agent-runtime/provider-stream-parts.d.ts +0 -5
  827. package/dist/agent-runtime/provider-stream-parts.d.ts.map +0 -1
  828. package/dist/agent-runtime/provider-stream-segments.d.ts +0 -63
  829. package/dist/agent-runtime/provider-stream-segments.d.ts.map +0 -1
  830. package/dist/agent-runtime/provider-usage.d.ts +0 -24
  831. package/dist/agent-runtime/provider-usage.d.ts.map +0 -1
  832. package/dist/agent-runtime/purge.d.ts.map +0 -1
  833. package/dist/agent-runtime/react.d.ts.map +0 -1
  834. package/dist/agent-runtime/retry-policy.d.ts +0 -49
  835. package/dist/agent-runtime/retry-policy.d.ts.map +0 -1
  836. package/dist/agent-runtime/run-acquisition.d.ts +0 -24
  837. package/dist/agent-runtime/run-acquisition.d.ts.map +0 -1
  838. package/dist/agent-runtime/run-approval.d.ts +0 -82
  839. package/dist/agent-runtime/run-approval.d.ts.map +0 -1
  840. package/dist/agent-runtime/run-assertions.d.ts +0 -63
  841. package/dist/agent-runtime/run-assertions.d.ts.map +0 -1
  842. package/dist/agent-runtime/run-complete-retry.d.ts +0 -24
  843. package/dist/agent-runtime/run-complete-retry.d.ts.map +0 -1
  844. package/dist/agent-runtime/run-complete-stream.d.ts +0 -9
  845. package/dist/agent-runtime/run-complete-stream.d.ts.map +0 -1
  846. package/dist/agent-runtime/run-complete-tools.d.ts +0 -21
  847. package/dist/agent-runtime/run-complete-tools.d.ts.map +0 -1
  848. package/dist/agent-runtime/run-complete-types.d.ts +0 -168
  849. package/dist/agent-runtime/run-complete-types.d.ts.map +0 -1
  850. package/dist/agent-runtime/run-complete.d.ts +0 -25
  851. package/dist/agent-runtime/run-complete.d.ts.map +0 -1
  852. package/dist/agent-runtime/run-driver-compose.d.ts +0 -21
  853. package/dist/agent-runtime/run-driver-compose.d.ts.map +0 -1
  854. package/dist/agent-runtime/run-execution-state.d.ts +0 -178
  855. package/dist/agent-runtime/run-execution-state.d.ts.map +0 -1
  856. package/dist/agent-runtime/run-execution.d.ts +0 -22
  857. package/dist/agent-runtime/run-execution.d.ts.map +0 -1
  858. package/dist/agent-runtime/run-failure.d.ts +0 -21
  859. package/dist/agent-runtime/run-failure.d.ts.map +0 -1
  860. package/dist/agent-runtime/run-history-parts.d.ts +0 -14
  861. package/dist/agent-runtime/run-history-parts.d.ts.map +0 -1
  862. package/dist/agent-runtime/run-loop-events.d.ts +0 -126
  863. package/dist/agent-runtime/run-loop-events.d.ts.map +0 -1
  864. package/dist/agent-runtime/run-model-attempts.d.ts +0 -6
  865. package/dist/agent-runtime/run-model-attempts.d.ts.map +0 -1
  866. package/dist/agent-runtime/run-model-messages.d.ts +0 -9
  867. package/dist/agent-runtime/run-model-messages.d.ts.map +0 -1
  868. package/dist/agent-runtime/run-model-step.d.ts +0 -43
  869. package/dist/agent-runtime/run-model-step.d.ts.map +0 -1
  870. package/dist/agent-runtime/run-model-stream.d.ts +0 -27
  871. package/dist/agent-runtime/run-model-stream.d.ts.map +0 -1
  872. package/dist/agent-runtime/run-operation-lifecycle.d.ts +0 -32
  873. package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +0 -1
  874. package/dist/agent-runtime/run-prompt-history.d.ts +0 -53
  875. package/dist/agent-runtime/run-prompt-history.d.ts.map +0 -1
  876. package/dist/agent-runtime/run-provider-ledger.d.ts +0 -32
  877. package/dist/agent-runtime/run-provider-ledger.d.ts.map +0 -1
  878. package/dist/agent-runtime/run-step-barriers.d.ts +0 -114
  879. package/dist/agent-runtime/run-step-barriers.d.ts.map +0 -1
  880. package/dist/agent-runtime/run-step-helpers.d.ts +0 -49
  881. package/dist/agent-runtime/run-step-helpers.d.ts.map +0 -1
  882. package/dist/agent-runtime/run-step-prepare.d.ts +0 -34
  883. package/dist/agent-runtime/run-step-prepare.d.ts.map +0 -1
  884. package/dist/agent-runtime/run-step-spend.d.ts +0 -394
  885. package/dist/agent-runtime/run-step-spend.d.ts.map +0 -1
  886. package/dist/agent-runtime/run-stream-parts.d.ts +0 -34
  887. package/dist/agent-runtime/run-stream-parts.d.ts.map +0 -1
  888. package/dist/agent-runtime/run-stream-recorded.d.ts +0 -8
  889. package/dist/agent-runtime/run-stream-recorded.d.ts.map +0 -1
  890. package/dist/agent-runtime/run-stream-step-text.d.ts +0 -29
  891. package/dist/agent-runtime/run-stream-step-text.d.ts.map +0 -1
  892. package/dist/agent-runtime/run-terminal.d.ts +0 -11
  893. package/dist/agent-runtime/run-terminal.d.ts.map +0 -1
  894. package/dist/agent-runtime/run-tool-approval-flow.d.ts +0 -36
  895. package/dist/agent-runtime/run-tool-approval-flow.d.ts.map +0 -1
  896. package/dist/agent-runtime/run-tool-approval-records.d.ts +0 -24
  897. package/dist/agent-runtime/run-tool-approval-records.d.ts.map +0 -1
  898. package/dist/agent-runtime/run-tool-call.d.ts +0 -73
  899. package/dist/agent-runtime/run-tool-call.d.ts.map +0 -1
  900. package/dist/agent-runtime/run-tool-errors.d.ts.map +0 -1
  901. package/dist/agent-runtime/run-tool-executor.d.ts +0 -34
  902. package/dist/agent-runtime/run-tool-executor.d.ts.map +0 -1
  903. package/dist/agent-runtime/run-tool-progress.d.ts +0 -21
  904. package/dist/agent-runtime/run-tool-progress.d.ts.map +0 -1
  905. package/dist/agent-runtime/run-turn-preparation.d.ts +0 -25
  906. package/dist/agent-runtime/run-turn-preparation.d.ts.map +0 -1
  907. package/dist/agent-runtime/run-unacquired.d.ts +0 -19
  908. package/dist/agent-runtime/run-unacquired.d.ts.map +0 -1
  909. package/dist/agent-runtime/runtime-admission-gate.d.ts.map +0 -1
  910. package/dist/agent-runtime/runtime-control.d.ts +0 -9
  911. package/dist/agent-runtime/runtime-control.d.ts.map +0 -1
  912. package/dist/agent-runtime/runtime-recovery.d.ts +0 -10
  913. package/dist/agent-runtime/runtime-recovery.d.ts.map +0 -1
  914. package/dist/agent-runtime/runtime-state.d.ts +0 -36
  915. package/dist/agent-runtime/runtime-state.d.ts.map +0 -1
  916. package/dist/agent-runtime/runtime-submit.d.ts +0 -5
  917. package/dist/agent-runtime/runtime-submit.d.ts.map +0 -1
  918. package/dist/agent-runtime/runtime.d.ts +0 -352
  919. package/dist/agent-runtime/runtime.d.ts.map +0 -1
  920. package/dist/agent-runtime/sandbox-binding.d.ts.map +0 -1
  921. package/dist/agent-runtime/sandbox-broker.d.ts.map +0 -1
  922. package/dist/agent-runtime/sandbox-bubblewrap-args.d.ts.map +0 -1
  923. package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts.map +0 -1
  924. package/dist/agent-runtime/sandbox-bubblewrap.d.ts.map +0 -1
  925. package/dist/agent-runtime/sandbox-coding-adapter.d.ts.map +0 -1
  926. package/dist/agent-runtime/sandbox-contract.d.ts.map +0 -1
  927. package/dist/agent-runtime/sandbox-process-linux.d.ts.map +0 -1
  928. package/dist/agent-runtime/sandbox-process-macos.d.ts.map +0 -1
  929. package/dist/agent-runtime/sandbox-process-owner.d.ts +0 -19
  930. package/dist/agent-runtime/sandbox-process-owner.d.ts.map +0 -1
  931. package/dist/agent-runtime/sandbox-process-spec.d.ts.map +0 -1
  932. package/dist/agent-runtime/sandbox-process-wrapper.d.ts.map +0 -1
  933. package/dist/agent-runtime/sandbox-process.d.ts +0 -8
  934. package/dist/agent-runtime/sandbox-process.d.ts.map +0 -1
  935. package/dist/agent-runtime/sandbox-session.d.ts.map +0 -1
  936. package/dist/agent-runtime/sandbox.d.ts +0 -125
  937. package/dist/agent-runtime/sandbox.d.ts.map +0 -1
  938. package/dist/agent-runtime/schedule-contract.d.ts.map +0 -1
  939. package/dist/agent-runtime/schedule-dispatch.d.ts.map +0 -1
  940. package/dist/agent-runtime/schedule-records.d.ts.map +0 -1
  941. package/dist/agent-runtime/schedule-tools.d.ts +0 -76
  942. package/dist/agent-runtime/schedule-tools.d.ts.map +0 -1
  943. package/dist/agent-runtime/schedules.d.ts.map +0 -1
  944. package/dist/agent-runtime/spill.d.ts +0 -26
  945. package/dist/agent-runtime/spill.d.ts.map +0 -1
  946. package/dist/agent-runtime/sql-events.d.ts.map +0 -1
  947. package/dist/agent-runtime/sql-history.d.ts.map +0 -1
  948. package/dist/agent-runtime/sql-ledger.d.ts.map +0 -1
  949. package/dist/agent-runtime/sql-purge.d.ts.map +0 -1
  950. package/dist/agent-runtime/sql-reads.d.ts.map +0 -1
  951. package/dist/agent-runtime/sql-rows.d.ts +0 -202
  952. package/dist/agent-runtime/sql-rows.d.ts.map +0 -1
  953. package/dist/agent-runtime/sql-session.d.ts.map +0 -1
  954. package/dist/agent-runtime/sqlite-bun.d.ts.map +0 -1
  955. package/dist/agent-runtime/sqlite-node.d.ts.map +0 -1
  956. package/dist/agent-runtime/sqlite-purge.d.ts +0 -6
  957. package/dist/agent-runtime/sqlite-purge.d.ts.map +0 -1
  958. package/dist/agent-runtime/sqlite-schema.d.ts +0 -7
  959. package/dist/agent-runtime/sqlite-schema.d.ts.map +0 -1
  960. package/dist/agent-runtime/sqlite-transactions.d.ts +0 -29
  961. package/dist/agent-runtime/sqlite-transactions.d.ts.map +0 -1
  962. package/dist/agent-runtime/sqlite.d.ts +0 -33
  963. package/dist/agent-runtime/sqlite.d.ts.map +0 -1
  964. package/dist/agent-runtime/state-slots.d.ts +0 -48
  965. package/dist/agent-runtime/state-slots.d.ts.map +0 -1
  966. package/dist/agent-runtime/state-tools.d.ts +0 -117
  967. package/dist/agent-runtime/state-tools.d.ts.map +0 -1
  968. package/dist/agent-runtime/store-archive.d.ts.map +0 -1
  969. package/dist/agent-runtime/store-branch.d.ts.map +0 -1
  970. package/dist/agent-runtime/store-capabilities.d.ts.map +0 -1
  971. package/dist/agent-runtime/store-conformance-branch.d.ts +0 -7
  972. package/dist/agent-runtime/store-conformance-branch.d.ts.map +0 -1
  973. package/dist/agent-runtime/store-conformance-capabilities.d.ts +0 -6
  974. package/dist/agent-runtime/store-conformance-capabilities.d.ts.map +0 -1
  975. package/dist/agent-runtime/store-conformance-event-once.d.ts +0 -12
  976. package/dist/agent-runtime/store-conformance-event-once.d.ts.map +0 -1
  977. package/dist/agent-runtime/store-conformance-lifecycle.d.ts +0 -454
  978. package/dist/agent-runtime/store-conformance-lifecycle.d.ts.map +0 -1
  979. package/dist/agent-runtime/store-conformance-ordering.d.ts +0 -18
  980. package/dist/agent-runtime/store-conformance-ordering.d.ts.map +0 -1
  981. package/dist/agent-runtime/store-conformance-seed.d.ts +0 -8
  982. package/dist/agent-runtime/store-conformance-seed.d.ts.map +0 -1
  983. package/dist/agent-runtime/store-conformance-support.d.ts +0 -140
  984. package/dist/agent-runtime/store-conformance-support.d.ts.map +0 -1
  985. package/dist/agent-runtime/store-conformance-terminal.d.ts +0 -12
  986. package/dist/agent-runtime/store-conformance-terminal.d.ts.map +0 -1
  987. package/dist/agent-runtime/store-conformance.d.ts +0 -71
  988. package/dist/agent-runtime/store-conformance.d.ts.map +0 -1
  989. package/dist/agent-runtime/store-create.d.ts.map +0 -1
  990. package/dist/agent-runtime/store-driver-contract.d.ts +0 -1016
  991. package/dist/agent-runtime/store-driver-contract.d.ts.map +0 -1
  992. package/dist/agent-runtime/store-event-once.d.ts +0 -37
  993. package/dist/agent-runtime/store-event-once.d.ts.map +0 -1
  994. package/dist/agent-runtime/store-events.d.ts +0 -2231
  995. package/dist/agent-runtime/store-events.d.ts.map +0 -1
  996. package/dist/agent-runtime/store-memory-archive.d.ts.map +0 -1
  997. package/dist/agent-runtime/store-memory-events.d.ts +0 -7
  998. package/dist/agent-runtime/store-memory-events.d.ts.map +0 -1
  999. package/dist/agent-runtime/store-memory.d.ts.map +0 -1
  1000. package/dist/agent-runtime/store-migrations/v1-to-v2.d.ts +0 -6
  1001. package/dist/agent-runtime/store-migrations/v1-to-v2.d.ts.map +0 -1
  1002. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts +0 -14
  1003. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts.map +0 -1
  1004. package/dist/agent-runtime/store-migrations/v3-to-v4.d.ts +0 -4
  1005. package/dist/agent-runtime/store-migrations/v3-to-v4.d.ts.map +0 -1
  1006. package/dist/agent-runtime/store-mutate.d.ts.map +0 -1
  1007. package/dist/agent-runtime/store-purge.d.ts.map +0 -1
  1008. package/dist/agent-runtime/store-reads.d.ts +0 -29
  1009. package/dist/agent-runtime/store-reads.d.ts.map +0 -1
  1010. package/dist/agent-runtime/store-reduce-history.d.ts +0 -10
  1011. package/dist/agent-runtime/store-reduce-history.d.ts.map +0 -1
  1012. package/dist/agent-runtime/store-reduce-run.d.ts +0 -14
  1013. package/dist/agent-runtime/store-reduce-run.d.ts.map +0 -1
  1014. package/dist/agent-runtime/store-reduce-shared.d.ts +0 -78
  1015. package/dist/agent-runtime/store-reduce-shared.d.ts.map +0 -1
  1016. package/dist/agent-runtime/store-reduce-terminal.d.ts +0 -6
  1017. package/dist/agent-runtime/store-reduce-terminal.d.ts.map +0 -1
  1018. package/dist/agent-runtime/store-reducer.d.ts +0 -24
  1019. package/dist/agent-runtime/store-reducer.d.ts.map +0 -1
  1020. package/dist/agent-runtime/store-replay.d.ts.map +0 -1
  1021. package/dist/agent-runtime/store-snapshot.d.ts +0 -19
  1022. package/dist/agent-runtime/store-snapshot.d.ts.map +0 -1
  1023. package/dist/agent-runtime/store.d.ts +0 -3032
  1024. package/dist/agent-runtime/store.d.ts.map +0 -1
  1025. package/dist/agent-runtime/testing.d.ts +0 -46
  1026. package/dist/agent-runtime/testing.d.ts.map +0 -1
  1027. package/dist/agent-runtime/workspace-glob.d.ts.map +0 -1
  1028. package/dist/index-18pf56dq.js +0 -409
  1029. package/dist/index-1gmgwfn3.js +0 -439
  1030. package/dist/index-23wn8sgf.js +0 -47
  1031. package/dist/index-27hck3z2.js +0 -307
  1032. package/dist/index-27srek2g.js +0 -3781
  1033. package/dist/index-360j58vb.js +0 -63
  1034. package/dist/index-654rhe5d.js +0 -159
  1035. package/dist/index-67pnt4bh.js +0 -174
  1036. package/dist/index-6kpwkpgx.js +0 -415
  1037. package/dist/index-6xw1wf4m.js +0 -969
  1038. package/dist/index-6yb4stq3.js +0 -224
  1039. package/dist/index-76yhxa41.js +0 -725
  1040. package/dist/index-79vqbjcz.js +0 -26
  1041. package/dist/index-b23s6e2c.js +0 -158
  1042. package/dist/index-cb4nnvfr.js +0 -40
  1043. package/dist/index-ek9w11r0.js +0 -40
  1044. package/dist/index-epyj7ptp.js +0 -510
  1045. package/dist/index-er483f3w.js +0 -601
  1046. package/dist/index-fjac2w5e.js +0 -3543
  1047. package/dist/index-ga6avd48.js +0 -53
  1048. package/dist/index-hy4653g4.js +0 -345
  1049. package/dist/index-j903yhp4.js +0 -121
  1050. package/dist/index-jzdbkanz.js +0 -215
  1051. package/dist/index-k9g061ma.js +0 -164
  1052. package/dist/index-kdw0n92g.js +0 -76
  1053. package/dist/index-krekhmp7.js +0 -707
  1054. package/dist/index-ky79wwgs.js +0 -2872
  1055. package/dist/index-mgr0mdqp.js +0 -271
  1056. package/dist/index-mrng24wq.js +0 -1210
  1057. package/dist/index-mx2gya05.js +0 -465
  1058. package/dist/index-nfeafbzh.js +0 -7379
  1059. package/dist/index-ngwf1s3c.js +0 -51
  1060. package/dist/index-pjjh91vw.js +0 -53
  1061. package/dist/index-qv5v6w9c.js +0 -696
  1062. package/dist/index-qymek778.js +0 -2289
  1063. package/dist/index-rj32hkkp.js +0 -305
  1064. package/dist/index-t5zp1jjj.js +0 -77
  1065. package/dist/index-v5hmyef8.js +0 -951
  1066. package/dist/index-vv0hxrmy.js +0 -295
  1067. package/dist/index-vxm0ya3f.js +0 -707
  1068. package/dist/index-xtxxt87z.js +0 -349
  1069. package/dist/index-zk839vzf.js +0 -231
  1070. package/llms/upgrading-0.128.0-0.134.0.txt +0 -633
  1071. /package/dist/agent-runtime/{control-interaction-schema.d.ts → browser/control-interaction-schema.d.ts} +0 -0
  1072. /package/dist/agent-runtime/{react.d.ts → browser/react.d.ts} +0 -0
  1073. /package/dist/agent-runtime/{coding-search-automaton.d.ts → coding/coding-search-automaton.d.ts} +0 -0
  1074. /package/dist/agent-runtime/{coding-search-case-fold.d.ts → coding/coding-search-case-fold.d.ts} +0 -0
  1075. /package/dist/agent-runtime/{coding-search-class-ranges.d.ts → coding/coding-search-class-ranges.d.ts} +0 -0
  1076. /package/dist/agent-runtime/{coding-search-contract.d.ts → coding/coding-search-contract.d.ts} +0 -0
  1077. /package/dist/agent-runtime/{coding-search-limits.d.ts → coding/coding-search-limits.d.ts} +0 -0
  1078. /package/dist/agent-runtime/{coding-search-matcher.d.ts → coding/coding-search-matcher.d.ts} +0 -0
  1079. /package/dist/agent-runtime/{coding-search-output.d.ts → coding/coding-search-output.d.ts} +0 -0
  1080. /package/dist/agent-runtime/{coding-search-regex-syntax.d.ts → coding/coding-search-regex-syntax.d.ts} +0 -0
  1081. /package/dist/agent-runtime/{coding-search-unit-classes.d.ts → coding/coding-search-unit-classes.d.ts} +0 -0
  1082. /package/dist/agent-runtime/{coding-tool-files.d.ts → coding/coding-tool-files.d.ts} +0 -0
  1083. /package/dist/agent-runtime/{coding-tool-listing.d.ts → coding/coding-tool-listing.d.ts} +0 -0
  1084. /package/dist/agent-runtime/{coding-tool-refusals.d.ts → coding/coding-tool-refusals.d.ts} +0 -0
  1085. /package/dist/agent-runtime/{coding-tool-search-patch.d.ts → coding/coding-tool-search-patch.d.ts} +0 -0
  1086. /package/dist/agent-runtime/{coding-tool-shell.d.ts → coding/coding-tool-shell.d.ts} +0 -0
  1087. /package/dist/agent-runtime/{coding-tool-utf8.d.ts → coding/coding-tool-utf8.d.ts} +0 -0
  1088. /package/dist/agent-runtime/{coding-tools.d.ts → coding/coding-tools.d.ts} +0 -0
  1089. /package/dist/agent-runtime/{contained-scan-budget.d.ts → coding/contained-scan-budget.d.ts} +0 -0
  1090. /package/dist/agent-runtime/{contained-scan-contract.d.ts → coding/contained-scan-contract.d.ts} +0 -0
  1091. /package/dist/agent-runtime/{workspace-glob.d.ts → coding/workspace-glob.d.ts} +0 -0
  1092. /package/dist/agent-runtime/{harness-resources.d.ts → harness/harness-resources.d.ts} +0 -0
  1093. /package/dist/agent-runtime/{coordinator.d.ts → loop/coordinator.d.ts} +0 -0
  1094. /package/dist/agent-runtime/{invocation-failure.d.ts → loop/invocation-failure.d.ts} +0 -0
  1095. /package/dist/agent-runtime/{owned-provider-stream.d.ts → loop/owned-provider-stream.d.ts} +0 -0
  1096. /package/dist/agent-runtime/{run-tool-errors.d.ts → loop/run-tool-errors.d.ts} +0 -0
  1097. /package/dist/agent-runtime/{runtime-admission-gate.d.ts → loop/runtime-admission-gate.d.ts} +0 -0
  1098. /package/dist/agent-runtime/{anthropic-sse.d.ts → providers/anthropic-sse.d.ts} +0 -0
  1099. /package/dist/agent-runtime/{anthropic.d.ts → providers/anthropic.d.ts} +0 -0
  1100. /package/dist/agent-runtime/{models-driver-telemetry.d.ts → providers/models-driver-telemetry.d.ts} +0 -0
  1101. /package/dist/agent-runtime/{models.d.ts → providers/models.d.ts} +0 -0
  1102. /package/dist/agent-runtime/{openai-messages.d.ts → providers/openai-messages.d.ts} +0 -0
  1103. /package/dist/agent-runtime/{openai-sse-state.d.ts → providers/openai-sse-state.d.ts} +0 -0
  1104. /package/dist/agent-runtime/{openai-sse.d.ts → providers/openai-sse.d.ts} +0 -0
  1105. /package/dist/agent-runtime/{openai.d.ts → providers/openai.d.ts} +0 -0
  1106. /package/dist/agent-runtime/{openrouter-benchmarks.d.ts → providers/openrouter-benchmarks.d.ts} +0 -0
  1107. /package/dist/agent-runtime/{openrouter-catalog-cache.d.ts → providers/openrouter-catalog-cache.d.ts} +0 -0
  1108. /package/dist/agent-runtime/{openrouter-catalog.d.ts → providers/openrouter-catalog.d.ts} +0 -0
  1109. /package/dist/agent-runtime/{openrouter-models.d.ts → providers/openrouter-models.d.ts} +0 -0
  1110. /package/dist/agent-runtime/{openrouter-route.d.ts → providers/openrouter-route.d.ts} +0 -0
  1111. /package/dist/agent-runtime/{openrouter.d.ts → providers/openrouter.d.ts} +0 -0
  1112. /package/dist/agent-runtime/{provider-content.d.ts → providers/provider-content.d.ts} +0 -0
  1113. /package/dist/agent-runtime/{provider-http.d.ts → providers/provider-http.d.ts} +0 -0
  1114. /package/dist/agent-runtime/{provider-journal.d.ts → providers/provider-journal.d.ts} +0 -0
  1115. /package/dist/agent-runtime/{provider-json-schema-strip.d.ts → providers/provider-json-schema-strip.d.ts} +0 -0
  1116. /package/dist/agent-runtime/{provider-sse.d.ts → providers/provider-sse.d.ts} +0 -0
  1117. /package/dist/agent-runtime/{sandbox-binding.d.ts → sandbox/sandbox-binding.d.ts} +0 -0
  1118. /package/dist/agent-runtime/{sandbox-broker.d.ts → sandbox/sandbox-broker.d.ts} +0 -0
  1119. /package/dist/agent-runtime/{sandbox-bubblewrap-args.d.ts → sandbox/sandbox-bubblewrap-args.d.ts} +0 -0
  1120. /package/dist/agent-runtime/{sandbox-bubblewrap-storage.d.ts → sandbox/sandbox-bubblewrap-storage.d.ts} +0 -0
  1121. /package/dist/agent-runtime/{sandbox-bubblewrap.d.ts → sandbox/sandbox-bubblewrap.d.ts} +0 -0
  1122. /package/dist/agent-runtime/{sandbox-coding-adapter.d.ts → sandbox/sandbox-coding-adapter.d.ts} +0 -0
  1123. /package/dist/agent-runtime/{sandbox-contract.d.ts → sandbox/sandbox-contract.d.ts} +0 -0
  1124. /package/dist/agent-runtime/{sandbox-process-linux.d.ts → sandbox/sandbox-process-linux.d.ts} +0 -0
  1125. /package/dist/agent-runtime/{sandbox-process-macos.d.ts → sandbox/sandbox-process-macos.d.ts} +0 -0
  1126. /package/dist/agent-runtime/{sandbox-process-spec.d.ts → sandbox/sandbox-process-spec.d.ts} +0 -0
  1127. /package/dist/agent-runtime/{sandbox-process-wrapper.d.ts → sandbox/sandbox-process-wrapper.d.ts} +0 -0
  1128. /package/dist/agent-runtime/{sandbox-session.d.ts → sandbox/sandbox-session.d.ts} +0 -0
  1129. /package/dist/agent-runtime/{archive-projection.d.ts → stores/archive-projection.d.ts} +0 -0
  1130. /package/dist/agent-runtime/{archive-spill.d.ts → stores/archive-spill.d.ts} +0 -0
  1131. /package/dist/agent-runtime/{branch-contract.d.ts → stores/branch-contract.d.ts} +0 -0
  1132. /package/dist/agent-runtime/{branch-provider.d.ts → stores/branch-provider.d.ts} +0 -0
  1133. /package/dist/agent-runtime/{branch-refusal.d.ts → stores/branch-refusal.d.ts} +0 -0
  1134. /package/dist/agent-runtime/{branch-runtime-tools.d.ts → stores/branch-runtime-tools.d.ts} +0 -0
  1135. /package/dist/agent-runtime/{branch-transitions.d.ts → stores/branch-transitions.d.ts} +0 -0
  1136. /package/dist/agent-runtime/{child-blocking.d.ts → stores/child-blocking.d.ts} +0 -0
  1137. /package/dist/agent-runtime/{children-control.d.ts → stores/children-control.d.ts} +0 -0
  1138. /package/dist/agent-runtime/{children-spawn.d.ts → stores/children-spawn.d.ts} +0 -0
  1139. /package/dist/agent-runtime/{children-state.d.ts → stores/children-state.d.ts} +0 -0
  1140. /package/dist/agent-runtime/{children-usage.d.ts → stores/children-usage.d.ts} +0 -0
  1141. /package/dist/agent-runtime/{children.d.ts → stores/children.d.ts} +0 -0
  1142. /package/dist/agent-runtime/{conversations.d.ts → stores/conversations.d.ts} +0 -0
  1143. /package/dist/agent-runtime/{event-search-postgres.d.ts → stores/event-search-postgres.d.ts} +0 -0
  1144. /package/dist/agent-runtime/{event-search-terms.d.ts → stores/event-search-terms.d.ts} +0 -0
  1145. /package/dist/agent-runtime/{event-search.d.ts → stores/event-search.d.ts} +0 -0
  1146. /package/dist/agent-runtime/{postgres-schema.d.ts → stores/postgres-schema.d.ts} +0 -0
  1147. /package/dist/agent-runtime/{purge.d.ts → stores/purge.d.ts} +0 -0
  1148. /package/dist/agent-runtime/{schedule-contract.d.ts → stores/schedule-contract.d.ts} +0 -0
  1149. /package/dist/agent-runtime/{schedule-dispatch.d.ts → stores/schedule-dispatch.d.ts} +0 -0
  1150. /package/dist/agent-runtime/{schedule-records.d.ts → stores/schedule-records.d.ts} +0 -0
  1151. /package/dist/agent-runtime/{schedules.d.ts → stores/schedules.d.ts} +0 -0
  1152. /package/dist/agent-runtime/{sql-events.d.ts → stores/sql-events.d.ts} +0 -0
  1153. /package/dist/agent-runtime/{sql-history.d.ts → stores/sql-history.d.ts} +0 -0
  1154. /package/dist/agent-runtime/{sql-ledger.d.ts → stores/sql-ledger.d.ts} +0 -0
  1155. /package/dist/agent-runtime/{sql-purge.d.ts → stores/sql-purge.d.ts} +0 -0
  1156. /package/dist/agent-runtime/{sql-reads.d.ts → stores/sql-reads.d.ts} +0 -0
  1157. /package/dist/agent-runtime/{sql-session.d.ts → stores/sql-session.d.ts} +0 -0
  1158. /package/dist/agent-runtime/{sqlite-bun.d.ts → stores/sqlite-bun.d.ts} +0 -0
  1159. /package/dist/agent-runtime/{sqlite-node.d.ts → stores/sqlite-node.d.ts} +0 -0
  1160. /package/dist/agent-runtime/{store-archive.d.ts → stores/store-archive.d.ts} +0 -0
  1161. /package/dist/agent-runtime/{store-branch.d.ts → stores/store-branch.d.ts} +0 -0
  1162. /package/dist/agent-runtime/{store-capabilities.d.ts → stores/store-capabilities.d.ts} +0 -0
  1163. /package/dist/agent-runtime/{store-create.d.ts → stores/store-create.d.ts} +0 -0
  1164. /package/dist/agent-runtime/{store-memory-archive.d.ts → stores/store-memory-archive.d.ts} +0 -0
  1165. /package/dist/agent-runtime/{store-memory.d.ts → stores/store-memory.d.ts} +0 -0
  1166. /package/dist/agent-runtime/{store-mutate.d.ts → stores/store-mutate.d.ts} +0 -0
  1167. /package/dist/agent-runtime/{store-purge.d.ts → stores/store-purge.d.ts} +0 -0
  1168. /package/dist/agent-runtime/{store-replay.d.ts → stores/store-replay.d.ts} +0 -0
  1169. /package/dist/agent-runtime/{fault-bench.d.ts → testing/fault-bench.d.ts} +0 -0
@@ -0,0 +1,2343 @@
1
+ import {
2
+ resolveRequestCors,
3
+ deniedRequestCors,
4
+ assertCorsConfig,
5
+ requestCorsHeaders,
6
+ applyCors
7
+ } from "./index-7mjsb7zv.js";
8
+ import {
9
+ joinRoutePath,
10
+ parseTrailingWildcard
11
+ } from "./index-m38ej7e5.js";
12
+ import {
13
+ errorCode2,
14
+ recordedErrorMessage,
15
+ normalizeError2,
16
+ validateDeclaredOutput
17
+ } from "./index-78da4g74.js";
18
+ import {
19
+ DEFAULT_CONTRACT_STREAM_FRAME_BYTES2,
20
+ readContractStreamItems,
21
+ contractStreamLifetimeExceeded
22
+ } from "./index-yrhw10ef.js";
23
+ import {
24
+ RELEASE_HEADER2
25
+ } from "./index-n15jny5b.js";
26
+ import {
27
+ isStreamCancellation,
28
+ ownHttpStream,
29
+ settleStreamCleanup
30
+ } from "./index-4ynw5ktx.js";
31
+ import {
32
+ isProtocolOutcome
33
+ } from "./index-cfnmvcq8.js";
34
+ import {
35
+ jsonResponse
36
+ } from "./index-kyejf658.js";
37
+ import {
38
+ runWithRequestContext2,
39
+ getRequestContext2,
40
+ setRequestEndpoint2
41
+ } from "./index-x6sp5vpa.js";
42
+ import {
43
+ resolveTraceId2,
44
+ resolveSocketIp2,
45
+ extractIp2,
46
+ getClientInfo2,
47
+ MalformedQueryError,
48
+ parseQueryParams
49
+ } from "./index-5q0qpw3v.js";
50
+ import {
51
+ mediaTypeEssence
52
+ } from "./index-zs8cze4j.js";
53
+ import {
54
+ isUnsafeKey,
55
+ safeJsonParse
56
+ } from "./index-zsarb5xp.js";
57
+ import {
58
+ AppError2,
59
+ badRequest2,
60
+ forbidden2
61
+ } from "./index-7fjbdga8.js";
62
+ import {
63
+ DEADLINE_BUDGET_HEADER2,
64
+ resolveServerDeadlineBudget,
65
+ createRemainingTimeoutReader
66
+ } from "./index-k137ezb6.js";
67
+ import {
68
+ resolveTraceContext2
69
+ } from "./index-y7sy1xdp.js";
70
+ import {
71
+ readBoundedChunks,
72
+ concatChunks,
73
+ readBoundedText
74
+ } from "./index-f16b7rze.js";
75
+ import {
76
+ assertPositiveSafeInteger
77
+ } from "./index-gr0kxymw.js";
78
+ import {
79
+ assertTimerMs
80
+ } from "./index-e1y74yra.js";
81
+ import {
82
+ abortReason,
83
+ linkAbortSignals
84
+ } from "./index-rptj3qnc.js";
85
+ import {
86
+ abortError
87
+ } from "./index-wz392jyz.js";
88
+ import {
89
+ isRecord,
90
+ isAsyncIterable
91
+ } from "./index-ps3djm8d.js";
92
+
93
+ // src/server/logging.ts
94
+ var LOGGER_METHODS = ["info", "warn", "error", "debug"];
95
+ function isBareLogger(value) {
96
+ if (value.logger !== undefined || value.skip !== undefined || value.enrich !== undefined) {
97
+ return false;
98
+ }
99
+ return LOGGER_METHODS.every((method) => typeof value[method] === "function");
100
+ }
101
+ function resolveLoggingConfig(logging) {
102
+ if (logging === false)
103
+ return null;
104
+ if (logging === true)
105
+ return {};
106
+ if (isRecord(logging) && isBareLogger(logging)) {
107
+ throw new Error("[stitchkit] `logging` no longer takes a StitchLogger directly — nest it: " + "`logging: { logger: myLogger }`.");
108
+ }
109
+ return logging;
110
+ }
111
+ function shouldSkipLog(config, req, url) {
112
+ if (!config.skip)
113
+ return false;
114
+ try {
115
+ return config.skip(req, url);
116
+ } catch {
117
+ return false;
118
+ }
119
+ }
120
+ function collectExtraLogFields(config, req, url, outcome, requestContext) {
121
+ const fields = {};
122
+ const enrichKeys = [];
123
+ const ctx = requestContext ?? getRequestContext2();
124
+ if (ctx) {
125
+ if (ctx.userId)
126
+ fields.userId = ctx.userId;
127
+ if (ctx.serviceName)
128
+ fields.serviceName = ctx.serviceName;
129
+ if (ctx.action)
130
+ fields.action = ctx.action;
131
+ if (ctx.dimensions)
132
+ fields.dimensions = ctx.dimensions;
133
+ }
134
+ if (config.enrich) {
135
+ try {
136
+ const extra = config.enrich(req, url, outcome);
137
+ if (extra) {
138
+ enrichKeys.push(...Object.keys(extra));
139
+ Object.assign(fields, extra);
140
+ }
141
+ } catch {}
142
+ }
143
+ return { fields, enrichKeys };
144
+ }
145
+
146
+ // src/server/router.ts
147
+ function routeSegments(path) {
148
+ return path.split("/").filter(Boolean);
149
+ }
150
+ function rawRouteShape(path) {
151
+ parseTrailingWildcard(path);
152
+ const segments = routeSegments(path).map((segment) => {
153
+ if (segment.startsWith(":"))
154
+ return { kind: "param" };
155
+ if (segment.startsWith("*"))
156
+ return { kind: "wildcard" };
157
+ return { kind: "static", value: segment };
158
+ });
159
+ return {
160
+ segments,
161
+ signature: segments.map((segment) => segment.kind === "static" ? segment.value : `:${segment.kind}`).join("/"),
162
+ wildcard: segments.at(-1)?.kind === "wildcard"
163
+ };
164
+ }
165
+ function segmentCovers(earlier, later) {
166
+ if (earlier.kind === "param")
167
+ return later.kind !== "wildcard";
168
+ if (earlier.kind === "wildcard")
169
+ return true;
170
+ return later.kind === "static" && earlier.value === later.value;
171
+ }
172
+ function routeShapeCovers(earlier, later) {
173
+ const earlierPrefixLength = earlier.wildcard ? earlier.segments.length - 1 : earlier.segments.length;
174
+ const laterPrefixLength = later.wildcard ? later.segments.length - 1 : later.segments.length;
175
+ if (earlier.wildcard) {
176
+ if (earlierPrefixLength > laterPrefixLength)
177
+ return false;
178
+ } else {
179
+ if (later.wildcard || earlierPrefixLength !== laterPrefixLength)
180
+ return false;
181
+ }
182
+ for (let index = 0;index < earlierPrefixLength; index++) {
183
+ const earlierSegment = earlier.segments[index];
184
+ const laterSegment = later.segments[index];
185
+ if (!earlierSegment || !laterSegment || !segmentCovers(earlierSegment, laterSegment)) {
186
+ return false;
187
+ }
188
+ }
189
+ return true;
190
+ }
191
+ function matchSegments(patternSegments, requestSegments) {
192
+ const wildcardSegment = patternSegments.at(-1);
193
+ const wildcardName = wildcardSegment?.startsWith("*") ? wildcardSegment.slice(1) : null;
194
+ const prefixLength = wildcardName ? patternSegments.length - 1 : patternSegments.length;
195
+ if (wildcardName) {
196
+ if (requestSegments.length < prefixLength)
197
+ return null;
198
+ } else if (patternSegments.length !== requestSegments.length) {
199
+ return null;
200
+ }
201
+ const params = {};
202
+ for (const [i, pattern] of patternSegments.slice(0, prefixLength).entries()) {
203
+ const actual = requestSegments[i];
204
+ if (actual === undefined)
205
+ return null;
206
+ if (pattern.startsWith(":")) {
207
+ const decoded = decodeSegment(actual);
208
+ if (decoded === null)
209
+ return null;
210
+ params[pattern.slice(1)] = decoded;
211
+ } else if (pattern !== actual) {
212
+ return null;
213
+ }
214
+ }
215
+ if (wildcardName) {
216
+ const decoded = requestSegments.slice(prefixLength).map(decodeSegment);
217
+ if (decoded.some((segment) => segment === null))
218
+ return null;
219
+ params[wildcardName] = decoded.join("/");
220
+ }
221
+ return params;
222
+ }
223
+ function decodeSegment(segment) {
224
+ try {
225
+ return decodeURIComponent(segment);
226
+ } catch {
227
+ return null;
228
+ }
229
+ }
230
+ function segmentRank(segment) {
231
+ if (segment?.startsWith("*"))
232
+ return 2;
233
+ if (segment?.startsWith(":"))
234
+ return 1;
235
+ return 0;
236
+ }
237
+ function buildRouteMap(groups) {
238
+ const map = new Map;
239
+ for (const { prefix, service, hooks } of groups) {
240
+ for (const [, method] of Object.entries(service.methods)) {
241
+ if (method.expose && !method.expose.includes("HTTP"))
242
+ continue;
243
+ const servicePath = joinRoutePath("/", service.prefix, method.path === "/" ? "" : method.path);
244
+ const fullPath = prefix ? joinRoutePath(prefix, servicePath) : servicePath;
245
+ const segments = routeSegments(fullPath);
246
+ const entries = map.get(method.method) ?? [];
247
+ entries.push({ method, pattern: fullPath, segments, groupHooks: hooks });
248
+ map.set(method.method, entries);
249
+ }
250
+ }
251
+ for (const [, entries] of map) {
252
+ entries.sort((a, b) => {
253
+ const len = Math.min(a.segments.length, b.segments.length);
254
+ for (let i = 0;i < len; i++) {
255
+ const rankDifference = segmentRank(a.segments[i]) - segmentRank(b.segments[i]);
256
+ if (rankDifference !== 0)
257
+ return rankDifference;
258
+ }
259
+ return a.segments.length - b.segments.length;
260
+ });
261
+ }
262
+ return map;
263
+ }
264
+ function matchRoute(routeMap, httpMethod, pathname) {
265
+ const entries = routeMap.get(httpMethod);
266
+ if (!entries)
267
+ return null;
268
+ const requestSegments = routeSegments(pathname);
269
+ for (const entry of entries) {
270
+ const pathParams = matchSegments(entry.segments, requestSegments);
271
+ if (pathParams) {
272
+ return {
273
+ method: entry.method,
274
+ pathParams,
275
+ groupHooks: entry.groupHooks
276
+ };
277
+ }
278
+ }
279
+ return null;
280
+ }
281
+ function allowedMethods(routeMap, pathname) {
282
+ const requestSegments = routeSegments(pathname);
283
+ const methods = [];
284
+ for (const [method, entries] of routeMap) {
285
+ for (const entry of entries) {
286
+ if (matchSegments(entry.segments, requestSegments)) {
287
+ methods.push(method);
288
+ break;
289
+ }
290
+ }
291
+ }
292
+ return methods;
293
+ }
294
+ function validateRoutes(routeMap) {
295
+ for (const [method, entries] of routeMap) {
296
+ const seen = new Map;
297
+ for (const entry of entries) {
298
+ parseTrailingWildcard(entry.pattern);
299
+ const normalized = entry.segments.map((s) => s.startsWith(":") ? ":param" : s.startsWith("*") ? "*wildcard" : s).join("/");
300
+ const key = `${method} /${normalized}`;
301
+ const existing = seen.get(key);
302
+ if (existing) {
303
+ throw new Error(`Duplicate route: ${method} ${entry.pattern} conflicts with ${existing}`);
304
+ }
305
+ seen.set(key, entry.pattern);
306
+ }
307
+ }
308
+ }
309
+ function findShadowedRoutes(routeMap, rawRoutes) {
310
+ if (!rawRoutes || rawRoutes.length === 0)
311
+ return [];
312
+ const shadowed = [];
313
+ for (const [httpMethod, entries] of routeMap) {
314
+ for (const entry of entries) {
315
+ const probe = `/${entry.segments.map((segment) => {
316
+ if (segment.startsWith(":"))
317
+ return "__param__";
318
+ if (segment.startsWith("*"))
319
+ return "__wildcard__";
320
+ return segment;
321
+ }).join("/")}`;
322
+ const match = matchRawRoute(rawRoutes, httpMethod, probe);
323
+ if (!match)
324
+ continue;
325
+ shadowed.push({
326
+ pattern: `${httpMethod} ${entry.pattern}`,
327
+ endpoint: `${entry.method.serviceName}.${entry.method.key}`,
328
+ rawRoute: `${match.route.method} ${match.route.path}`,
329
+ scope: entry.method.scope
330
+ });
331
+ }
332
+ }
333
+ return shadowed;
334
+ }
335
+ function matchRawRoute(rawRoutes, httpMethod, pathname) {
336
+ for (const route of rawRoutes) {
337
+ if (route.method !== "ALL" && route.method !== httpMethod)
338
+ continue;
339
+ if (parseTrailingWildcard(route.path)) {
340
+ const routeSegs = routeSegments(route.path);
341
+ const pathSegs = routeSegments(pathname);
342
+ const params = matchSegments(routeSegs, pathSegs);
343
+ if (params)
344
+ return { route, params };
345
+ continue;
346
+ }
347
+ if (route.path.includes("/:")) {
348
+ const routeSegs = routeSegments(route.path);
349
+ const pathSegs = routeSegments(pathname);
350
+ const params = matchSegments(routeSegs, pathSegs);
351
+ if (params)
352
+ return { route, params };
353
+ continue;
354
+ }
355
+ if (route.path === pathname)
356
+ return { route, params: {} };
357
+ }
358
+ return null;
359
+ }
360
+ function validateRawRoutes(rawRoutes) {
361
+ const routes = rawRoutes ?? [];
362
+ for (const route of routes) {
363
+ if (route.serviceName !== undefined && route.serviceName.trim().length === 0) {
364
+ throw new Error(`Raw route ${route.method} ${route.path} has an empty serviceName`);
365
+ }
366
+ if (route.action !== undefined && route.action.trim().length === 0) {
367
+ throw new Error(`Raw route ${route.method} ${route.path} has an empty action`);
368
+ }
369
+ if (route.action !== undefined && route.serviceName === undefined) {
370
+ throw new Error(`Raw route ${route.method} ${route.path} declares action without serviceName`);
371
+ }
372
+ }
373
+ const shapes = routes.map((route) => rawRouteShape(route.path));
374
+ const conflicts = [];
375
+ for (const [laterIndex, later] of routes.entries()) {
376
+ const laterShape = shapes[laterIndex];
377
+ if (!laterShape)
378
+ continue;
379
+ for (let earlierIndex = 0;earlierIndex < laterIndex; earlierIndex++) {
380
+ const earlier = routes[earlierIndex];
381
+ const earlierShape = shapes[earlierIndex];
382
+ if (!earlier || !earlierShape)
383
+ continue;
384
+ if (earlier.method === later.method && earlier.path === later.path) {
385
+ conflicts.push(`${later.method} ${later.path} duplicates earlier ${earlier.method} ${earlier.path}`);
386
+ continue;
387
+ }
388
+ if (earlier.method === later.method && earlierShape.signature === laterShape.signature) {
389
+ conflicts.push(`${later.method} ${later.path} has the same parameter shape as earlier ${earlier.method} ${earlier.path}`);
390
+ continue;
391
+ }
392
+ const methodCovered = earlier.method === "ALL" || earlier.method === later.method;
393
+ if (methodCovered && routeShapeCovers(earlierShape, laterShape)) {
394
+ conflicts.push(`${later.method} ${later.path} is unreachable because earlier ${earlier.method} ${earlier.path} matches every request it could receive`);
395
+ }
396
+ }
397
+ }
398
+ if (conflicts.length > 0) {
399
+ throw new Error(`[stitchkit] conflicting raw routes:
400
+ - ${conflicts.join(`
401
+ - `)}`);
402
+ }
403
+ }
404
+
405
+ // src/server/route-table.ts
406
+ function compileRouteTable(config, warn) {
407
+ for (const group of config.groups ?? []) {
408
+ if (group.hooks && "onRequest" in group.hooks) {
409
+ throw new Error("[stitchkit] a route group cannot declare `onRequest` — it runs before routing, so the group it belongs to is not known yet and the hook would never be dispatched. Refuse before dispatch with the server-level `hooks.onRequest`, or gate the group with its `authorize`, which runs once the endpoint is known.");
410
+ }
411
+ }
412
+ const routeMap = buildRouteMap(normalizeGroups(config));
413
+ validateRoutes(routeMap);
414
+ validateRawRoutes(config.rawRoutes);
415
+ for (const shadow of findShadowedRoutes(routeMap, config.rawRoutes)) {
416
+ const gate = shadow.scope && shadow.scope !== "public" ? ` (scope "${shadow.scope}")` : "";
417
+ const line = `[stitchkit] raw route ${shadow.rawRoute} shadows contract route ${shadow.pattern}` + ` → ${shadow.endpoint}${gate} will never run, and its hooks never apply`;
418
+ warn(line);
419
+ }
420
+ return routeMap;
421
+ }
422
+ function normalizeGroups(config) {
423
+ const result = [];
424
+ if (config.services) {
425
+ for (const service of config.services) {
426
+ const prefix = config.scopePrefixes?.[service.scope] ?? "";
427
+ result.push({ prefix, service });
428
+ }
429
+ }
430
+ if (config.groups) {
431
+ for (const group of config.groups) {
432
+ for (const service of group.services) {
433
+ result.push({ prefix: group.pathPrefix ?? "", service, hooks: group.hooks });
434
+ }
435
+ }
436
+ }
437
+ return result;
438
+ }
439
+
440
+ // src/server/handler-state.ts
441
+ var trustProxyHandlers = new WeakSet;
442
+ function markTrustProxyHandler(handler) {
443
+ trustProxyHandlers.add(handler);
444
+ }
445
+ function isTrustProxyHandler(handler) {
446
+ return trustProxyHandlers.has(handler);
447
+ }
448
+ function assertRandomValuesAvailable() {
449
+ const cryptoGlobal = Reflect.get(globalThis, "crypto");
450
+ if (!isRecord(cryptoGlobal) || typeof cryptoGlobal.getRandomValues !== "function") {
451
+ throw new Error("[stitchkit] createHandler requires crypto.getRandomValues (on React Native, install a Web Crypto getRandomValues polyfill before creating the handler)");
452
+ }
453
+ }
454
+ function assertRuntimeCapabilities(routeMap) {
455
+ assertRandomValuesAvailable();
456
+ if (typeof Reflect.get(globalThis, "ReadableStream") === "function")
457
+ return;
458
+ const unsupported = [];
459
+ for (const entries of routeMap.values()) {
460
+ for (const { method } of entries) {
461
+ if (method.stream !== undefined) {
462
+ unsupported.push(`${method.serviceName}.${method.key} (stream)`);
463
+ } else if (method.multipart !== undefined) {
464
+ unsupported.push(`${method.serviceName}.${method.key} (multipart)`);
465
+ }
466
+ }
467
+ }
468
+ if (unsupported.length > 0) {
469
+ throw new Error(`[stitchkit] createHandler: this runtime does not provide ReadableStream, which is required by: ${unsupported.join(", ")}`);
470
+ }
471
+ }
472
+ function createHandlerState(config) {
473
+ const { cors, hooks, logging = false, observability } = config;
474
+ if (cors)
475
+ assertCorsConfig(cors);
476
+ assertPositiveSafeInteger("HandlerConfig.maxJsonBodyBytes", config.maxJsonBodyBytes, Error);
477
+ const logConfig = resolveLoggingConfig(logging);
478
+ const customLogger = logConfig?.logger ?? null;
479
+ const useDefaultLog = logConfig !== null && !logConfig.logger;
480
+ const warn = (line) => {
481
+ try {
482
+ if (customLogger)
483
+ customLogger.warn(line);
484
+ else
485
+ console.warn(line);
486
+ } catch {}
487
+ };
488
+ const routeMap = compileRouteTable(config, warn);
489
+ assertRuntimeCapabilities(routeMap);
490
+ return {
491
+ config,
492
+ cors,
493
+ hooks,
494
+ observability,
495
+ logConfig,
496
+ customLogger,
497
+ useDefaultLog,
498
+ warnedEnrichKeys: new Set,
499
+ warn,
500
+ resolveId: createTraceIdResolver(config.traceId, warn),
501
+ routeMap
502
+ };
503
+ }
504
+ function createTraceIdResolver(customTraceId, warn) {
505
+ let traceResolverBroken = false;
506
+ return (req, fallback) => {
507
+ if (!customTraceId)
508
+ return fallback ?? resolveTraceId2(req);
509
+ try {
510
+ return customTraceId(req) ?? fallback ?? resolveTraceId2(req);
511
+ } catch (err) {
512
+ if (!traceResolverBroken) {
513
+ traceResolverBroken = true;
514
+ warn("[stitchkit] `traceId` resolver threw — falling back to the framework resolver. " + "Ids will not match your observability context until it is fixed: " + `${err instanceof Error ? err.message : String(err)}`);
515
+ }
516
+ return fallback ?? resolveTraceId2(req);
517
+ }
518
+ };
519
+ }
520
+
521
+ // src/server/context-contribution.ts
522
+ var RUNTIME_CONTEXT_RESERVED_KEYS = new Set([
523
+ "params",
524
+ "input",
525
+ "files",
526
+ "rawBody",
527
+ "source",
528
+ "req",
529
+ "url",
530
+ "headers",
531
+ "traceId",
532
+ "spanId",
533
+ "ipAddress",
534
+ "userAgent",
535
+ "signal",
536
+ "remainingTimeoutMs",
537
+ "toolCallId",
538
+ "mcp",
539
+ "reportProgress"
540
+ ]);
541
+ function contributionError(scope, reason) {
542
+ return new TypeError(`[stitchkit] auth: invalid context contribution for scope ${JSON.stringify(scope)}: ${reason}`);
543
+ }
544
+ function descriptorsEqual(left, right) {
545
+ if (!left || !right)
546
+ return left === right;
547
+ if (left.enumerable !== right.enumerable || left.configurable !== right.configurable || left.writable !== right.writable) {
548
+ return false;
549
+ }
550
+ if ("value" in left || "value" in right) {
551
+ return "value" in left && "value" in right && Object.is(left.value, right.value);
552
+ }
553
+ return left.get === right.get && left.set === right.set;
554
+ }
555
+ function contextContributionDelta(original, shadow, scope) {
556
+ if (Object.getPrototypeOf(shadow) !== Object.getPrototypeOf(original)) {
557
+ throw contributionError(scope, "context prototype changes are not supported");
558
+ }
559
+ const originalKeys = Reflect.ownKeys(original);
560
+ const shadowKeys = Reflect.ownKeys(shadow);
561
+ const shadowKeySet = new Set(shadowKeys);
562
+ for (const key of originalKeys) {
563
+ if (!shadowKeySet.has(key)) {
564
+ const printable = typeof key === "string" ? JSON.stringify(key) : "a symbol key";
565
+ throw contributionError(scope, `context key ${printable} may not be deleted`);
566
+ }
567
+ }
568
+ const contribution = Object.create(null);
569
+ for (const key of shadowKeys) {
570
+ const originalDescriptor = Object.getOwnPropertyDescriptor(original, key);
571
+ const shadowDescriptor = Object.getOwnPropertyDescriptor(shadow, key);
572
+ if (!shadowDescriptor || descriptorsEqual(originalDescriptor, shadowDescriptor))
573
+ continue;
574
+ Object.defineProperty(contribution, key, shadowDescriptor);
575
+ }
576
+ return contribution;
577
+ }
578
+ function prepareContextContribution(value, scope) {
579
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
580
+ throw contributionError(scope, "expected a plain record");
581
+ }
582
+ let prototype;
583
+ let descriptors;
584
+ let keys;
585
+ try {
586
+ prototype = Object.getPrototypeOf(value);
587
+ descriptors = Object.getOwnPropertyDescriptors(value);
588
+ keys = Reflect.ownKeys(value);
589
+ } catch {
590
+ throw contributionError(scope, "record inspection failed");
591
+ }
592
+ if (prototype !== Object.prototype && prototype !== null) {
593
+ throw contributionError(scope, "expected Object.prototype or null prototype");
594
+ }
595
+ const prepared = Object.create(null);
596
+ for (const key of keys) {
597
+ if (typeof key !== "string") {
598
+ throw contributionError(scope, "symbol keys are not supported");
599
+ }
600
+ if (isUnsafeKey(key)) {
601
+ throw contributionError(scope, `unsafe key ${JSON.stringify(key)}`);
602
+ }
603
+ if (RUNTIME_CONTEXT_RESERVED_KEYS.has(key)) {
604
+ throw contributionError(scope, `reserved key ${JSON.stringify(key)}`);
605
+ }
606
+ const descriptor = descriptors[key];
607
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
608
+ throw contributionError(scope, `key ${JSON.stringify(key)} must be enumerable data`);
609
+ }
610
+ prepared[key] = descriptor.value;
611
+ }
612
+ return prepared;
613
+ }
614
+ function mergeContextContribution(ctx, value, scope) {
615
+ Object.assign(ctx, prepareContextContribution(value, scope));
616
+ }
617
+
618
+ // src/server/multipart-reader.ts
619
+ var DEFAULT_MAX_HEADER_BYTES = 64 * 1024;
620
+ var CRLF = new Uint8Array([13, 10]);
621
+ var HEADER_END = new Uint8Array([13, 10, 13, 10]);
622
+ var cachedDecoder;
623
+ var cachedHeaderDecoder;
624
+ var cachedEncoder;
625
+ function getDecoder() {
626
+ cachedDecoder ??= new TextDecoder;
627
+ return cachedDecoder;
628
+ }
629
+ function getHeaderDecoder() {
630
+ cachedHeaderDecoder ??= new TextDecoder("utf-8", { fatal: true });
631
+ return cachedHeaderDecoder;
632
+ }
633
+ function getEncoder() {
634
+ cachedEncoder ??= new TextEncoder;
635
+ return cachedEncoder;
636
+ }
637
+ var decoder = {
638
+ decode: (input, options) => getDecoder().decode(input, options)
639
+ };
640
+ var TOKEN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
641
+ function hasControl(value, allowTab = false) {
642
+ for (let index = 0;index < value.length; index++) {
643
+ const code = value.charCodeAt(index);
644
+ if (code < 32 && !(allowTab && code === 9) || code === 127)
645
+ return true;
646
+ }
647
+ return false;
648
+ }
649
+ function trimWhitespace(value) {
650
+ return value.replace(/^[ \t]+|[ \t]+$/g, "");
651
+ }
652
+ function indexOfBytes(haystack, needle) {
653
+ outer:
654
+ for (let index = 0;index <= haystack.length - needle.length; index += 1) {
655
+ for (let offset = 0;offset < needle.length; offset += 1) {
656
+ if (haystack[index + offset] !== needle[offset])
657
+ continue outer;
658
+ }
659
+ return index;
660
+ }
661
+ return -1;
662
+ }
663
+ function startsWithBytes(value, prefix) {
664
+ if (value.length < prefix.length)
665
+ return false;
666
+ for (let index = 0;index < prefix.length; index += 1) {
667
+ if (value[index] !== prefix[index])
668
+ return false;
669
+ }
670
+ return true;
671
+ }
672
+ function concatBytes(left, right) {
673
+ if (left.length === 0)
674
+ return right.slice();
675
+ if (right.length === 0)
676
+ return left.slice();
677
+ const joined = new Uint8Array(left.length + right.length);
678
+ joined.set(left);
679
+ joined.set(right, left.length);
680
+ return joined;
681
+ }
682
+ function parseBoundary(req) {
683
+ const contentType = req.headers.get("content-type") ?? "";
684
+ if (!contentType.toLowerCase().startsWith("multipart/form-data")) {
685
+ badRequest2("Request body must be multipart/form-data");
686
+ }
687
+ const match = /(?:^|;)\s*boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
688
+ const boundary = match?.[1] ?? match?.[2];
689
+ if (!boundary || boundary.length > 200)
690
+ badRequest2("Invalid multipart boundary");
691
+ return boundary;
692
+ }
693
+ function parseDisposition(value) {
694
+ if (!value)
695
+ badRequest2("Invalid multipart disposition");
696
+ const separator = value.indexOf(";");
697
+ const kind = separator < 0 ? value : value.slice(0, separator);
698
+ if (trimWhitespace(kind).toLowerCase() !== "form-data") {
699
+ badRequest2("Invalid multipart disposition");
700
+ }
701
+ const parameters = new Map;
702
+ let rest = separator < 0 ? "" : value.slice(separator);
703
+ while (rest.length > 0) {
704
+ const match = /^;[ \t]*([^=; \t]+)[ \t]*=[ \t]*(?:"((?:[^"\\]|\\.)*)"|([^; \t]+))[ \t]*/.exec(rest);
705
+ if (!match?.[1])
706
+ badRequest2("Invalid multipart disposition parameter");
707
+ const key = match[1].toLowerCase();
708
+ if (!TOKEN.test(key) || parameters.has(key)) {
709
+ badRequest2("Invalid or duplicate multipart disposition parameter");
710
+ }
711
+ const quoted = match[2];
712
+ const raw = match[3] ?? "";
713
+ if (quoted === undefined && !TOKEN.test(raw)) {
714
+ badRequest2("Invalid multipart disposition parameter");
715
+ }
716
+ const decoded = quoted === undefined ? raw : quoted.replace(/\\(.)/g, "$1");
717
+ if (hasControl(decoded))
718
+ badRequest2("Invalid multipart disposition parameter");
719
+ parameters.set(key, decoded);
720
+ rest = rest.slice(match[0].length);
721
+ }
722
+ const name = parameters.get("name");
723
+ let filename = parameters.get("filename");
724
+ const extended = parameters.get("filename*");
725
+ if (extended !== undefined) {
726
+ const match = /^utf-8'[A-Za-z0-9-]*'((?:[!#$&+.^_`|~0-9A-Za-z-]|%[0-9A-Fa-f]{2})*)$/i.exec(extended);
727
+ if (!match)
728
+ badRequest2("Invalid multipart extended filename");
729
+ try {
730
+ filename = decodeURIComponent(match[1] ?? "");
731
+ } catch {
732
+ badRequest2("Invalid multipart extended filename");
733
+ }
734
+ if (hasControl(filename))
735
+ badRequest2("Invalid multipart extended filename");
736
+ }
737
+ if (!name || isUnsafeKey(name))
738
+ badRequest2("Invalid multipart field name");
739
+ return filename === undefined ? { name } : { name, filename };
740
+ }
741
+ function parsePartHeaders(bytes) {
742
+ let text;
743
+ try {
744
+ text = getHeaderDecoder().decode(bytes);
745
+ } catch {
746
+ badRequest2("Invalid multipart headers");
747
+ }
748
+ const headers = new Map;
749
+ for (const line of text.split(`\r
750
+ `)) {
751
+ const separator = line.indexOf(":");
752
+ if (separator <= 0)
753
+ badRequest2("Invalid multipart header");
754
+ const name = line.slice(0, separator).toLowerCase();
755
+ const value = trimWhitespace(line.slice(separator + 1));
756
+ if (!TOKEN.test(name) || hasControl(value, true)) {
757
+ badRequest2("Invalid multipart header");
758
+ }
759
+ if (headers.has(name))
760
+ badRequest2("Duplicate multipart header");
761
+ headers.set(name, value);
762
+ }
763
+ const disposition = parseDisposition(headers.get("content-disposition") ?? undefined);
764
+ const rawContentType = headers.get("content-type");
765
+ const contentType = rawContentType?.split(";", 1)[0]?.trim().toLowerCase();
766
+ const rawSize = headers.get("content-length");
767
+ if (rawSize !== undefined && !/^[0-9]+$/.test(rawSize)) {
768
+ badRequest2("Invalid multipart part content-length");
769
+ }
770
+ const declaredSize = rawSize === undefined ? undefined : Number(rawSize);
771
+ if (declaredSize !== undefined && (!Number.isSafeInteger(declaredSize) || declaredSize < 0)) {
772
+ badRequest2("Invalid multipart part content-length");
773
+ }
774
+ return { ...disposition, contentType, declaredSize };
775
+ }
776
+
777
+ class MultipartStreamReader {
778
+ #reader;
779
+ #delimiter;
780
+ #initialBoundary;
781
+ #maxRequestBytes;
782
+ #buffer = new Uint8Array;
783
+ #readBytes = 0;
784
+ #sourceDone = false;
785
+ #terminal = false;
786
+ #activePart = false;
787
+ constructor(req, boundary, maxRequestBytes) {
788
+ if (!req.body)
789
+ badRequest2("Multipart request body is empty");
790
+ this.#reader = req.body.getReader();
791
+ const enc = getEncoder();
792
+ this.#delimiter = enc.encode(`\r
793
+ --${boundary}`);
794
+ this.#initialBoundary = enc.encode(`--${boundary}`);
795
+ this.#maxRequestBytes = maxRequestBytes;
796
+ }
797
+ async start() {
798
+ await this.#ensure(this.#initialBoundary.length + 2);
799
+ if (!startsWithBytes(this.#buffer, this.#initialBoundary)) {
800
+ badRequest2("Malformed multipart body");
801
+ }
802
+ this.#consume(this.#initialBoundary.length);
803
+ await this.#consumeBoundarySuffix();
804
+ }
805
+ async nextPart() {
806
+ if (this.#activePart)
807
+ badRequest2("Multipart part stream was not fully consumed");
808
+ if (this.#terminal)
809
+ return null;
810
+ const header = await this.#readUntil(HEADER_END, DEFAULT_MAX_HEADER_BYTES);
811
+ const parsed = parsePartHeaders(header);
812
+ this.#activePart = true;
813
+ let ended = false;
814
+ const stream = new ReadableStream({
815
+ pull: async (controller) => {
816
+ if (ended) {
817
+ controller.close();
818
+ return;
819
+ }
820
+ try {
821
+ const chunk = await this.#readPartChunk();
822
+ if (chunk.value.length > 0)
823
+ controller.enqueue(chunk.value);
824
+ if (chunk.end) {
825
+ ended = true;
826
+ controller.close();
827
+ }
828
+ } catch (error) {
829
+ controller.error(error);
830
+ this.cancel(error);
831
+ }
832
+ },
833
+ cancel: (reason) => {
834
+ this.cancel(reason);
835
+ }
836
+ });
837
+ return { ...parsed, stream, consumed: () => ended };
838
+ }
839
+ cancel(reason) {
840
+ this.#reader.cancel(reason).catch(() => {});
841
+ }
842
+ release() {
843
+ this.#reader.releaseLock();
844
+ }
845
+ async#readPartChunk() {
846
+ while (true) {
847
+ const boundaryIndex = indexOfBytes(this.#buffer, this.#delimiter);
848
+ if (boundaryIndex >= 0) {
849
+ const value = this.#buffer.slice(0, boundaryIndex);
850
+ this.#consume(boundaryIndex + this.#delimiter.length);
851
+ await this.#consumeBoundarySuffix();
852
+ this.#activePart = false;
853
+ return { value, end: true };
854
+ }
855
+ const retained = this.#delimiter.length - 1;
856
+ if (this.#buffer.length > retained) {
857
+ const emitLength = this.#buffer.length - retained;
858
+ const value = this.#buffer.slice(0, emitLength);
859
+ this.#consume(emitLength);
860
+ return { value, end: false };
861
+ }
862
+ if (this.#sourceDone)
863
+ badRequest2("Incomplete multipart body");
864
+ await this.#readMore();
865
+ }
866
+ }
867
+ async#consumeBoundarySuffix() {
868
+ await this.#ensure(2);
869
+ if (this.#buffer[0] === 45 && this.#buffer[1] === 45) {
870
+ this.#consume(2);
871
+ this.#terminal = true;
872
+ if (startsWithBytes(this.#buffer, CRLF))
873
+ this.#consume(2);
874
+ return;
875
+ }
876
+ if (!startsWithBytes(this.#buffer, CRLF))
877
+ badRequest2("Malformed multipart boundary");
878
+ this.#consume(2);
879
+ }
880
+ async#readUntil(marker, maxBytes) {
881
+ while (true) {
882
+ const index = indexOfBytes(this.#buffer, marker);
883
+ if (index >= 0) {
884
+ if (index > maxBytes)
885
+ badRequest2("Multipart part headers are too large");
886
+ const value = this.#buffer.slice(0, index);
887
+ this.#consume(index + marker.length);
888
+ return value;
889
+ }
890
+ if (this.#buffer.length > maxBytes)
891
+ badRequest2("Multipart part headers are too large");
892
+ if (this.#sourceDone)
893
+ badRequest2("Incomplete multipart headers");
894
+ await this.#readMore();
895
+ }
896
+ }
897
+ async#ensure(length) {
898
+ while (this.#buffer.length < length && !this.#sourceDone)
899
+ await this.#readMore();
900
+ if (this.#buffer.length < length)
901
+ badRequest2("Incomplete multipart body");
902
+ }
903
+ async#readMore() {
904
+ const result = await this.#reader.read();
905
+ if (result.done) {
906
+ this.#sourceDone = true;
907
+ return;
908
+ }
909
+ this.#readBytes += result.value.length;
910
+ if (this.#readBytes > this.#maxRequestBytes) {
911
+ this.cancel();
912
+ badRequest2(`Multipart request exceeds ${this.#maxRequestBytes} bytes`);
913
+ }
914
+ this.#buffer = concatBytes(this.#buffer, result.value);
915
+ }
916
+ #consume(length) {
917
+ this.#buffer = this.#buffer.slice(length);
918
+ }
919
+ }
920
+
921
+ // src/server/multipart.ts
922
+ var DEFAULT_MAX_REQUEST_BYTES = 25 * 1024 * 1024;
923
+ var DEFAULT_MAX_FIELD_BYTES = 1024 * 1024;
924
+ var DEFAULT_MAX_PARTS = 1000;
925
+ function matchesContentType(contentType, accepted) {
926
+ const normalized = contentType.toLowerCase();
927
+ return accepted.some((candidate) => {
928
+ const policy = candidate.toLowerCase();
929
+ return policy.endsWith("/*") ? normalized.startsWith(policy.slice(0, -1)) : normalized === policy;
930
+ });
931
+ }
932
+ function limitedStream(stream, maxBytes, label, signal) {
933
+ const reader = stream.getReader();
934
+ let total = 0;
935
+ const cancelReader = (reason) => {
936
+ reader.cancel(reason).catch(() => {});
937
+ };
938
+ return new ReadableStream({
939
+ async pull(controller) {
940
+ if (signal.aborted) {
941
+ cancelReader(signal.reason);
942
+ controller.error(abortReason(signal));
943
+ return;
944
+ }
945
+ try {
946
+ const result = await reader.read();
947
+ if (result.done) {
948
+ controller.close();
949
+ reader.releaseLock();
950
+ return;
951
+ }
952
+ total += result.value.length;
953
+ if (total > maxBytes) {
954
+ cancelReader();
955
+ badRequest2(`${label} exceeds ${maxBytes} bytes`);
956
+ }
957
+ controller.enqueue(result.value);
958
+ } catch (error) {
959
+ controller.error(error);
960
+ }
961
+ },
962
+ cancel(reason) {
963
+ cancelReader(reason);
964
+ }
965
+ });
966
+ }
967
+ async function collectFile(part, stream) {
968
+ const chunks = [];
969
+ const reader = stream.getReader();
970
+ while (true) {
971
+ const result = await reader.read();
972
+ if (result.done)
973
+ break;
974
+ chunks.push(Uint8Array.from(result.value).buffer);
975
+ }
976
+ return new File(chunks, part.filename ?? "upload", {
977
+ type: part.contentType ?? "application/octet-stream"
978
+ });
979
+ }
980
+ async function readText(stream, maxBytes) {
981
+ const result = await readBoundedChunks(stream, { maxBytes });
982
+ if (result.kind === "over-limit")
983
+ badRequest2(`Multipart text field exceeds ${maxBytes} bytes`);
984
+ return decoder.decode(concatChunks(result.chunks, result.total));
985
+ }
986
+ function required(policy) {
987
+ return policy.required !== false;
988
+ }
989
+ async function parseMultipart2(req, descriptor, fieldsSchema, receivers) {
990
+ const maxRequestBytes = descriptor.maxRequestBytes ?? DEFAULT_MAX_REQUEST_BYTES;
991
+ const contentLength = Number(req.headers.get("content-length"));
992
+ if (Number.isFinite(contentLength) && contentLength > maxRequestBytes) {
993
+ badRequest2(`Multipart request exceeds ${maxRequestBytes} bytes`);
994
+ }
995
+ const boundary = parseBoundary(req);
996
+ const parser = new MultipartStreamReader(req, boundary, maxRequestBytes);
997
+ const fields = {};
998
+ const files = {};
999
+ const counts = new Map;
1000
+ const cleanups = [];
1001
+ let rolledBack = false;
1002
+ const rollback = async () => {
1003
+ if (rolledBack)
1004
+ return;
1005
+ rolledBack = true;
1006
+ for (let index = cleanups.length - 1;index >= 0; index -= 1) {
1007
+ try {
1008
+ await cleanups[index]?.();
1009
+ } catch (error) {
1010
+ console.error("[stitchkit] multipart receiver cleanup failed", error);
1011
+ }
1012
+ }
1013
+ };
1014
+ try {
1015
+ await parser.start();
1016
+ let partCount = 0;
1017
+ while (true) {
1018
+ const part = await parser.nextPart();
1019
+ if (!part)
1020
+ break;
1021
+ partCount += 1;
1022
+ if (partCount > DEFAULT_MAX_PARTS)
1023
+ badRequest2("Too many multipart parts");
1024
+ const policy = descriptor.files[part.name];
1025
+ const isFile = part.filename !== undefined || part.contentType !== undefined;
1026
+ if (!isFile) {
1027
+ if (policy)
1028
+ badRequest2(`Multipart file field "${part.name}" must contain a file`);
1029
+ if (Object.hasOwn(fields, part.name)) {
1030
+ badRequest2(`Duplicate multipart text field: ${part.name}`);
1031
+ }
1032
+ fields[part.name] = await readText(part.stream, descriptor.maxFieldBytes ?? DEFAULT_MAX_FIELD_BYTES);
1033
+ continue;
1034
+ }
1035
+ if (!policy)
1036
+ badRequest2(`Unexpected multipart file field: ${part.name}`);
1037
+ const count = (counts.get(part.name) ?? 0) + 1;
1038
+ counts.set(part.name, count);
1039
+ const maxFiles = policy.multiple === true ? policy.maxFiles ?? DEFAULT_MAX_PARTS : 1;
1040
+ if (count > maxFiles)
1041
+ badRequest2(`Too many files for multipart field: ${part.name}`);
1042
+ const contentType = part.contentType ?? "";
1043
+ if (policy.contentTypes && !matchesContentType(contentType, policy.contentTypes)) {
1044
+ badRequest2(`Unsupported content type for multipart field "${part.name}"`);
1045
+ }
1046
+ const maxFileBytes = policy.maxBytes ?? maxRequestBytes;
1047
+ if (part.declaredSize !== undefined && part.declaredSize > maxFileBytes) {
1048
+ badRequest2(`Multipart field "${part.name}" exceeds ${maxFileBytes} bytes`);
1049
+ }
1050
+ const stream = limitedStream(part.stream, maxFileBytes, `Multipart field "${part.name}"`, req.signal);
1051
+ let value;
1052
+ if (descriptor.delivery === "stream") {
1053
+ const receiver = receivers?.[part.name];
1054
+ if (!receiver)
1055
+ badRequest2(`Missing multipart receiver for field: ${part.name}`);
1056
+ const result = await receiver({
1057
+ metadata: {
1058
+ field: part.name,
1059
+ filename: part.filename ?? "upload",
1060
+ contentType: contentType || "application/octet-stream",
1061
+ size: part.declaredSize
1062
+ },
1063
+ stream,
1064
+ signal: req.signal
1065
+ });
1066
+ cleanups.push(result.cleanup);
1067
+ if (!part.consumed()) {
1068
+ await stream.cancel();
1069
+ badRequest2(`Multipart receiver for "${part.name}" did not consume its stream`);
1070
+ }
1071
+ value = result.value;
1072
+ } else {
1073
+ value = await collectFile(part, stream);
1074
+ }
1075
+ if (policy.multiple === true) {
1076
+ const existing = files[part.name];
1077
+ if (Array.isArray(existing))
1078
+ existing.push(value);
1079
+ else
1080
+ files[part.name] = [value];
1081
+ } else {
1082
+ files[part.name] = value;
1083
+ }
1084
+ }
1085
+ for (const [field, policy] of Object.entries(descriptor.files)) {
1086
+ const count = counts.get(field) ?? 0;
1087
+ if (required(policy) && count === 0)
1088
+ badRequest2(`Missing multipart file field: ${field}`);
1089
+ if (policy.multiple === true && count === 0 && !required(policy))
1090
+ files[field] = [];
1091
+ }
1092
+ return {
1093
+ files,
1094
+ fields: fieldsSchema ? fieldsSchema.parse(fields) : fields,
1095
+ rollback
1096
+ };
1097
+ } catch (error) {
1098
+ parser.cancel(error);
1099
+ await rollback();
1100
+ throw error;
1101
+ } finally {
1102
+ parser.release();
1103
+ }
1104
+ }
1105
+
1106
+ // src/server/request-body.ts
1107
+ async function readRequestText(req, maxBytes) {
1108
+ if (req.signal.aborted)
1109
+ throw abortReason(req.signal);
1110
+ if (maxBytes === undefined)
1111
+ return req.text();
1112
+ assertPositiveSafeInteger("maxJsonBodyBytes", maxBytes, Error);
1113
+ const result = await readBoundedText(req, { maxBytes, signal: req.signal });
1114
+ if (result.kind === "over-limit")
1115
+ badRequest2(`JSON body exceeds the ${maxBytes}-byte limit`);
1116
+ return result.text;
1117
+ }
1118
+
1119
+ // src/server/context.ts
1120
+ function parseJsonBody(req, text, method, cors) {
1121
+ if (text.trim() === "")
1122
+ return {};
1123
+ const essence = mediaTypeEssence(req.headers.get("content-type"));
1124
+ if (essence !== "application/json") {
1125
+ if (!method.safelistedBody || essence !== "text/plain") {
1126
+ badRequest2("Request body must be application/json");
1127
+ }
1128
+ const origin = req.headers.get("origin");
1129
+ if (!cors || cors.safelistedBody === "no-allow-list") {
1130
+ forbidden2("A text/plain body requires an explicit cors.origin allow-list on the server");
1131
+ }
1132
+ if (!origin)
1133
+ forbidden2("A text/plain body requires an Origin header");
1134
+ if (cors.safelistedBody !== "allowed") {
1135
+ forbidden2("A text/plain body is accepted only from an allowed origin");
1136
+ }
1137
+ }
1138
+ try {
1139
+ return safeJsonParse(text);
1140
+ } catch {
1141
+ badRequest2("Invalid JSON body");
1142
+ }
1143
+ }
1144
+ function buildBaseContext(req, url, pathParams, traceId, clientIp) {
1145
+ const safePathParams = {};
1146
+ for (const [k, v] of Object.entries(pathParams)) {
1147
+ if (!RUNTIME_CONTEXT_RESERVED_KEYS.has(k) && !isUnsafeKey(k))
1148
+ safePathParams[k] = v;
1149
+ }
1150
+ return {
1151
+ params: pathParams,
1152
+ input: undefined,
1153
+ source: "http",
1154
+ req,
1155
+ url,
1156
+ headers: req.headers,
1157
+ signal: req.signal,
1158
+ ...safePathParams,
1159
+ traceId,
1160
+ ...getClientInfo2(req, clientIp)
1161
+ };
1162
+ }
1163
+ function parsePathParamsInto(ctx, method) {
1164
+ if (method.paramsSchema) {
1165
+ ctx.params = method.paramsSchema.parse(ctx.params);
1166
+ }
1167
+ }
1168
+ async function parseRequestPayloadInto(ctx, req, url, method, maxJsonBodyBytes, cors) {
1169
+ if (method.multipart) {
1170
+ const multipart = await parseMultipart2(req, method.multipart, method.inputSchema, method.multipartReceivers);
1171
+ ctx.input = multipart.fields;
1172
+ ctx.files = multipart.files;
1173
+ return multipart;
1174
+ }
1175
+ if (method.inputSchema) {
1176
+ if (req.method === "GET") {
1177
+ ctx.input = method.inputSchema.parse(parseQueryParams(url));
1178
+ } else if (req.method === "DELETE") {
1179
+ if (mediaTypeEssence(req.headers.get("content-type")) === "application/json") {
1180
+ const text = await readRequestText(req, method.maxJsonBodyBytes ?? maxJsonBodyBytes);
1181
+ if (method.rawBody)
1182
+ ctx.rawBody = text;
1183
+ ctx.input = method.inputSchema.parse(parseJsonBody(req, text, method, cors));
1184
+ } else {
1185
+ ctx.input = method.inputSchema.parse(parseQueryParams(url));
1186
+ }
1187
+ } else {
1188
+ const text = await readRequestText(req, method.maxJsonBodyBytes ?? maxJsonBodyBytes);
1189
+ if (method.rawBody)
1190
+ ctx.rawBody = text;
1191
+ ctx.input = method.inputSchema.parse(parseJsonBody(req, text, method, cors));
1192
+ }
1193
+ }
1194
+ return;
1195
+ }
1196
+ function buildErrorContext(req, url, traceId, clientIp) {
1197
+ return {
1198
+ params: undefined,
1199
+ input: undefined,
1200
+ source: "http",
1201
+ req,
1202
+ url,
1203
+ headers: req.headers,
1204
+ signal: req.signal,
1205
+ traceId,
1206
+ ...getClientInfo2(req, clientIp)
1207
+ };
1208
+ }
1209
+
1210
+ // src/server/streaming-pump.ts
1211
+ async function pumpFrames(p) {
1212
+ let sinceYield = 0;
1213
+ try {
1214
+ for (;; ) {
1215
+ await p.awaitDemand();
1216
+ if (p.isClosed())
1217
+ return;
1218
+ const next = await p.iterator.next();
1219
+ if (p.isClosed())
1220
+ return;
1221
+ if (next.done)
1222
+ break;
1223
+ if (!p.send(p.framing.frame(next.value)))
1224
+ return;
1225
+ sinceYield += 1;
1226
+ if (sinceYield >= MAX_BUFFERED_FRAMES) {
1227
+ sinceYield = 0;
1228
+ await new Promise((resolve) => {
1229
+ setTimeout(resolve, 0);
1230
+ });
1231
+ if (p.isClosed())
1232
+ return;
1233
+ }
1234
+ }
1235
+ if (p.framing.done)
1236
+ p.send(p.framing.done);
1237
+ } catch (error) {
1238
+ if (p.isClosed()) {
1239
+ if (!isStreamCancellation(error, p.departed))
1240
+ p.pumped.reject(error);
1241
+ } else
1242
+ p.send(p.framing.frame(normalizeError2(error).toJSON()));
1243
+ } finally {
1244
+ p.pumped.resolve();
1245
+ p.end();
1246
+ }
1247
+ }
1248
+
1249
+ // src/server/streaming-route.ts
1250
+ var DEFAULT_STREAM_HEARTBEAT_MS2 = 5000;
1251
+ var FRAMINGS = {
1252
+ ndjson: {
1253
+ contentType: "application/x-ndjson",
1254
+ keepAlive: `
1255
+ `,
1256
+ frame: (value) => `${JSON.stringify(value)}
1257
+ `
1258
+ },
1259
+ sse: {
1260
+ contentType: "text/event-stream",
1261
+ keepAlive: `: keep-alive
1262
+
1263
+ `,
1264
+ frame: (value) => `data: ${JSON.stringify(value)}
1265
+
1266
+ `,
1267
+ done: `data: [DONE]
1268
+
1269
+ `
1270
+ }
1271
+ };
1272
+ function applyIdleTimeout(server, request, seconds) {
1273
+ if (typeof server !== "object" || server === null)
1274
+ return;
1275
+ const timeout = Reflect.get(server, "timeout");
1276
+ if (typeof timeout !== "function")
1277
+ return;
1278
+ try {
1279
+ Reflect.apply(timeout, server, [request, seconds]);
1280
+ } catch {}
1281
+ }
1282
+ function unrefTimer(timer) {
1283
+ if (typeof timer !== "object" || timer === null)
1284
+ return;
1285
+ const unref = Reflect.get(timer, "unref");
1286
+ if (typeof unref === "function")
1287
+ Reflect.apply(unref, timer, []);
1288
+ }
1289
+ var MAX_BUFFERED_FRAMES = 16;
1290
+ function responseHeaders(framing, extra) {
1291
+ const headers = new Headers(extra);
1292
+ headers.set("Content-Type", framing.contentType);
1293
+ headers.set("Cache-Control", "no-cache");
1294
+ headers.set("Connection", "keep-alive");
1295
+ headers.set("X-Accel-Buffering", "no");
1296
+ return headers;
1297
+ }
1298
+ function streamingTimings(options) {
1299
+ const heartbeatMs = options.heartbeatMs ?? DEFAULT_STREAM_HEARTBEAT_MS2;
1300
+ assertTimerMs("heartbeatMs", heartbeatMs);
1301
+ const idleTimeoutSeconds = options.idleTimeoutSeconds ?? 0;
1302
+ if (!Number.isInteger(idleTimeoutSeconds) || idleTimeoutSeconds < 0) {
1303
+ throw new TypeError("idleTimeoutSeconds must be a non-negative integer");
1304
+ }
1305
+ return { heartbeatMs, idleTimeoutSeconds };
1306
+ }
1307
+ function streamingRoute2(options) {
1308
+ const { heartbeatMs, idleTimeoutSeconds } = streamingTimings(options);
1309
+ const framing = FRAMINGS[options.format ?? "ndjson"];
1310
+ return {
1311
+ method: options.method ?? "GET",
1312
+ path: options.path,
1313
+ handler: async (request, context) => {
1314
+ applyIdleTimeout(context.server, request, idleTimeoutSeconds);
1315
+ const departed = new AbortController;
1316
+ const settled = Promise.withResolvers();
1317
+ settled.promise.catch(() => {
1318
+ return;
1319
+ });
1320
+ const pumped = Promise.withResolvers();
1321
+ pumped.promise.catch(() => {
1322
+ return;
1323
+ });
1324
+ let cancel = () => departed.abort();
1325
+ ownHttpStream(request, { cancel: () => cancel(), settled: settled.promise });
1326
+ let iterator;
1327
+ try {
1328
+ const iterable = await options.source(request, {
1329
+ ...context,
1330
+ signal: departed.signal
1331
+ });
1332
+ iterator = iterable[Symbol.asyncIterator]();
1333
+ } catch (error) {
1334
+ departed.abort();
1335
+ settled.reject(error);
1336
+ throw error;
1337
+ }
1338
+ const encoder = new TextEncoder;
1339
+ let heartbeat = null;
1340
+ let closed = false;
1341
+ const stopHeartbeat = () => {
1342
+ if (heartbeat === null)
1343
+ return;
1344
+ clearInterval(heartbeat);
1345
+ heartbeat = null;
1346
+ };
1347
+ const release = () => {
1348
+ if (closed)
1349
+ return;
1350
+ closed = true;
1351
+ stopHeartbeat();
1352
+ signalDemand();
1353
+ request.signal.removeEventListener("abort", onRequestAbort);
1354
+ departed.abort();
1355
+ const hook = Promise.withResolvers();
1356
+ try {
1357
+ options.onClose?.();
1358
+ hook.resolve();
1359
+ } catch (error) {
1360
+ hook.reject(error);
1361
+ }
1362
+ settleStreamCleanup([
1363
+ hook.promise,
1364
+ pumped.promise,
1365
+ Promise.resolve().then(() => iterator.return?.(undefined))
1366
+ ]).then(() => settled.resolve(), (error) => settled.reject(error));
1367
+ };
1368
+ let demand = null;
1369
+ const signalDemand = () => {
1370
+ const resolve = demand;
1371
+ demand = null;
1372
+ resolve?.();
1373
+ };
1374
+ const onRequestAbort = () => cancel();
1375
+ const stream = new ReadableStream({
1376
+ start(controller) {
1377
+ const send = (text) => {
1378
+ if (closed)
1379
+ return false;
1380
+ try {
1381
+ controller.enqueue(encoder.encode(text));
1382
+ return true;
1383
+ } catch {
1384
+ release();
1385
+ return false;
1386
+ }
1387
+ };
1388
+ const finish = () => {
1389
+ try {
1390
+ controller.close();
1391
+ } catch {}
1392
+ };
1393
+ cancel = () => {
1394
+ release();
1395
+ finish();
1396
+ };
1397
+ if (request.signal.aborted || departed.signal.aborted) {
1398
+ pumped.resolve();
1399
+ cancel();
1400
+ return;
1401
+ }
1402
+ request.signal.addEventListener("abort", onRequestAbort, { once: true });
1403
+ send(framing.keepAlive);
1404
+ heartbeat = setInterval(() => {
1405
+ if ((controller.desiredSize ?? 1) > 0)
1406
+ send(framing.keepAlive);
1407
+ }, heartbeatMs);
1408
+ unrefTimer(heartbeat);
1409
+ const awaitDemand = async () => {
1410
+ while (!closed && (controller.desiredSize ?? 1) <= 0) {
1411
+ await new Promise((resolve) => {
1412
+ demand = resolve;
1413
+ });
1414
+ }
1415
+ };
1416
+ pumpFrames({
1417
+ iterator,
1418
+ framing,
1419
+ send,
1420
+ awaitDemand,
1421
+ isClosed: () => closed,
1422
+ departed: departed.signal,
1423
+ pumped,
1424
+ end: () => {
1425
+ release();
1426
+ finish();
1427
+ }
1428
+ });
1429
+ },
1430
+ pull() {
1431
+ signalDemand();
1432
+ },
1433
+ cancel() {
1434
+ release();
1435
+ }
1436
+ }, { highWaterMark: MAX_BUFFERED_FRAMES });
1437
+ return new Response(stream, { headers: responseHeaders(framing, options.headers) });
1438
+ }
1439
+ };
1440
+ }
1441
+ function ndjsonRoute2(options) {
1442
+ return streamingRoute2({ ...options, format: "ndjson" });
1443
+ }
1444
+ function sseRoute2(options) {
1445
+ return streamingRoute2({ ...options, format: "sse" });
1446
+ }
1447
+
1448
+ // src/server/contract-stream.ts
1449
+ function encodedBytes(value, format) {
1450
+ const json = JSON.stringify(value);
1451
+ if (json === undefined)
1452
+ throw new TypeError("Streaming item is not JSON serializable");
1453
+ const framing = format === "sse" ? `data: ${json}
1454
+
1455
+ ` : `${json}
1456
+ `;
1457
+ return new TextEncoder().encode(framing).byteLength;
1458
+ }
1459
+ function contractStreamResponse(request, context, source, descriptor, operationAbort) {
1460
+ const format = descriptor.format ?? "ndjson";
1461
+ const maxFrameBytes = descriptor.maxFrameBytes ?? DEFAULT_CONTRACT_STREAM_FRAME_BYTES2;
1462
+ const iterator = source[Symbol.asyncIterator]();
1463
+ let pendingNext;
1464
+ const settled = Promise.withResolvers();
1465
+ settled.promise.catch(() => {
1466
+ return;
1467
+ });
1468
+ let lifetime;
1469
+ let lifetimeExpired = false;
1470
+ let closing = false;
1471
+ const closeSource = (cancelled = operationAbort.signal.aborted) => {
1472
+ if (closing)
1473
+ return;
1474
+ closing = true;
1475
+ if (lifetime !== undefined)
1476
+ clearTimeout(lifetime);
1477
+ operationAbort.abort();
1478
+ settleStreamCleanup([
1479
+ Promise.resolve(pendingNext).catch((error) => {
1480
+ if (cancelled && !isStreamCancellation(error, operationAbort.signal))
1481
+ throw error;
1482
+ }),
1483
+ Promise.resolve().then(() => iterator.return?.(undefined))
1484
+ ]).then(() => settled.resolve(), (error) => settled.reject(error));
1485
+ };
1486
+ ownHttpStream(request, { cancel: () => closeSource(true), settled: settled.promise });
1487
+ if (descriptor.lifetimeMs !== undefined && !closing) {
1488
+ lifetime = setTimeout(() => {
1489
+ lifetimeExpired = true;
1490
+ operationAbort.abort(new Error("Stream lifetime expired"));
1491
+ }, descriptor.lifetimeMs);
1492
+ lifetime.unref?.();
1493
+ }
1494
+ const frames = async function* () {
1495
+ if (closing)
1496
+ return;
1497
+ try {
1498
+ const items = readContractStreamItems(iterator, descriptor, operationAbort.signal, (pending) => {
1499
+ pendingNext = pending;
1500
+ });
1501
+ for await (const { item, terminal } of items) {
1502
+ const frame = descriptor.framing === "item" ? item : { type: "data", data: item };
1503
+ if (encodedBytes(frame, format) > maxFrameBytes) {
1504
+ console.error(`[stitchkit] contract stream frame exceeded its ${maxFrameBytes} byte limit`);
1505
+ throw new AppError2("STREAM_FRAME_TOO_LARGE", {
1506
+ message: "Stream item exceeded its declared frame limit",
1507
+ status: 500
1508
+ });
1509
+ }
1510
+ yield frame;
1511
+ if (terminal && descriptor.completion === "terminal")
1512
+ return;
1513
+ }
1514
+ if (descriptor.framing !== "item")
1515
+ yield { type: "end" };
1516
+ } catch (error) {
1517
+ if (operationAbort.signal.aborted && !lifetimeExpired)
1518
+ return;
1519
+ if (lifetimeExpired) {
1520
+ if (descriptor.framing === "item")
1521
+ return;
1522
+ yield {
1523
+ type: "error",
1524
+ error: contractStreamLifetimeExceeded().toJSON().error
1525
+ };
1526
+ return;
1527
+ }
1528
+ if (descriptor.framing === "item") {
1529
+ console.error("[stitchkit] item-framed contract stream failed:", normalizeError2(error));
1530
+ return;
1531
+ }
1532
+ yield { type: "error", error: normalizeError2(error).toJSON().error };
1533
+ } finally {
1534
+ if (lifetime !== undefined)
1535
+ clearTimeout(lifetime);
1536
+ closeSource();
1537
+ }
1538
+ };
1539
+ const route = streamingRoute2({
1540
+ path: "/",
1541
+ format,
1542
+ heartbeatMs: descriptor.heartbeatMs,
1543
+ idleTimeoutSeconds: descriptor.idleTimeoutSeconds,
1544
+ source: () => frames(),
1545
+ onClose: () => operationAbort.abort()
1546
+ });
1547
+ return Promise.resolve(route.handler(request, context));
1548
+ }
1549
+
1550
+ // src/server/response-metadata.ts
1551
+ var RESERVED_HEADERS = new Set(["content-type", "content-length", "x-request-id"]);
1552
+ function hasGetSetCookie(headers) {
1553
+ return "getSetCookie" in headers && typeof headers.getSetCookie === "function";
1554
+ }
1555
+ function isReservedHeader(name) {
1556
+ const normalized = name.toLowerCase();
1557
+ return RESERVED_HEADERS.has(normalized) || normalized.startsWith("access-control-");
1558
+ }
1559
+ function createResponseMetadata() {
1560
+ return { headers: new Headers };
1561
+ }
1562
+ function applyResponseMetadata(target, metadata, endpointIdentity) {
1563
+ if (!metadata)
1564
+ return;
1565
+ for (const [name] of metadata.headers) {
1566
+ if (isReservedHeader(name)) {
1567
+ throw new Error(`${endpointIdentity} cannot set framework-owned response header "${name}"`);
1568
+ }
1569
+ }
1570
+ const preservesSetCookie = hasGetSetCookie(metadata.headers);
1571
+ for (const [name, value] of metadata.headers) {
1572
+ if (name.toLowerCase() === "set-cookie" && preservesSetCookie)
1573
+ continue;
1574
+ target.append(name, value);
1575
+ }
1576
+ if (preservesSetCookie) {
1577
+ for (const cookie of metadata.headers.getSetCookie()) {
1578
+ target.append("Set-Cookie", cookie);
1579
+ }
1580
+ }
1581
+ }
1582
+
1583
+ // src/server/endpoint-response.ts
1584
+ async function endpointResponse(state, request, outcome) {
1585
+ const { method } = outcome.match;
1586
+ if (method.rawResponse)
1587
+ return rawEndpointResponse(request, outcome);
1588
+ if (method.stream)
1589
+ return streamEndpointResponse(request, outcome);
1590
+ return dataEndpointResponse(state, request, outcome);
1591
+ }
1592
+ function rawEndpointResponse(request, { match: { method }, result }) {
1593
+ if (!(result instanceof Response)) {
1594
+ throw new AppError2("INTERNAL_SERVER_ERROR", {
1595
+ message: `Raw endpoint ${method.serviceName}.${method.key} must return a Response`,
1596
+ status: 500
1597
+ });
1598
+ }
1599
+ const response = method.method === "HEAD" ? new Response(null, {
1600
+ status: result.status,
1601
+ statusText: result.statusText,
1602
+ headers: result.headers
1603
+ }) : result;
1604
+ const rawRes = applyCors(response, request.cors);
1605
+ request.complete(result);
1606
+ return rawRes;
1607
+ }
1608
+ async function streamEndpointResponse(request, { match: { method, pathParams }, result, streamAbort }) {
1609
+ const { req, server, clientIp } = request;
1610
+ if (!method.stream || !streamAbort || !isAsyncIterable(result)) {
1611
+ streamAbort?.abort();
1612
+ throw new AppError2("INTERNAL_SERVER_ERROR", {
1613
+ message: `Streaming endpoint ${method.serviceName}.${method.key} must return an AsyncIterable`,
1614
+ status: 500
1615
+ });
1616
+ }
1617
+ const response = await contractStreamResponse(req, { params: pathParams, server, ipAddress: clientIp.socketIp }, result, method.stream, streamAbort);
1618
+ const withCors = applyCors(response, request.cors);
1619
+ request.complete(withCors.status);
1620
+ return withCors;
1621
+ }
1622
+ async function dataEndpointResponse(state, request, {
1623
+ ctx,
1624
+ match: { method, groupHooks },
1625
+ result: handlerResult,
1626
+ responseMetadata
1627
+ }) {
1628
+ const { hooks, config, warn } = state;
1629
+ let result = handlerResult;
1630
+ if (groupHooks?.afterHandle) {
1631
+ const transformed = await groupHooks.afterHandle(ctx, result, method);
1632
+ if (transformed !== undefined)
1633
+ result = transformed;
1634
+ }
1635
+ if (hooks?.afterHandle) {
1636
+ const transformed = await hooks.afterHandle(ctx, result, method);
1637
+ if (transformed !== undefined)
1638
+ result = transformed;
1639
+ }
1640
+ if (result instanceof Response) {
1641
+ throw new AppError2("INTERNAL_SERVER_ERROR", {
1642
+ message: `${method.serviceName}.${method.key} produced a Response on the data path — only a \`rawResponse: true\` endpoint may return one (an afterHandle hook must return data)`,
1643
+ status: 500
1644
+ });
1645
+ }
1646
+ const checked = validateDeclaredOutput(method.outputSchema, result, config.warnOnOutputStrip && method.outputSchema ? (paths) => {
1647
+ warn(`[stitchkit] output strip ${method.serviceName}.${method.key}: ${paths.join(", ")}`);
1648
+ } : undefined);
1649
+ if (!checked.ok) {
1650
+ throw new AppError2("INTERNAL_SERVER_ERROR", { message: checked.message, status: 500 });
1651
+ }
1652
+ result = checked.data;
1653
+ const responseStatus = method.responseMeta?.status ?? (method.outputSchema ? 200 : 204);
1654
+ if (method.outputSchema && (responseStatus === 204 || responseStatus === 205)) {
1655
+ throw new AppError2("INTERNAL_SERVER_ERROR", {
1656
+ message: `${method.serviceName}.${method.key} cannot combine output with bodyless status ${responseStatus}`,
1657
+ status: 500
1658
+ });
1659
+ }
1660
+ const responseHeaders = new Headers(requestCorsHeaders(request.cors));
1661
+ applyResponseMetadata(responseHeaders, responseMetadata, `${method.serviceName}.${method.key}`);
1662
+ if (!method.outputSchema) {
1663
+ const empty = new Response(null, { status: responseStatus, headers: responseHeaders });
1664
+ request.complete(responseStatus);
1665
+ return empty;
1666
+ }
1667
+ const body = jsonResponse(result, { status: responseStatus, headers: responseHeaders });
1668
+ request.complete(responseStatus);
1669
+ return body;
1670
+ }
1671
+
1672
+ // src/server/endpoint-dispatch.ts
1673
+ function forwardAbortSignal(sourceSignal, target) {
1674
+ if (sourceSignal.aborted) {
1675
+ target.abort(sourceSignal.reason);
1676
+ return () => {
1677
+ return;
1678
+ };
1679
+ }
1680
+ const onAbort = () => {
1681
+ target.abort(sourceSignal.reason);
1682
+ };
1683
+ sourceSignal.addEventListener("abort", onAbort, { once: true });
1684
+ return () => sourceSignal.removeEventListener("abort", onAbort);
1685
+ }
1686
+ function closeLateStreamSource(value) {
1687
+ if (!isAsyncIterable(value))
1688
+ return;
1689
+ try {
1690
+ const iterator = value[Symbol.asyncIterator]();
1691
+ Promise.resolve(iterator.return?.(undefined)).catch(() => {
1692
+ return;
1693
+ });
1694
+ } catch {}
1695
+ }
1696
+ async function dispatchEndpoint(state, request, match) {
1697
+ const { hooks, config } = state;
1698
+ const { req, url, traceId, clientIp } = request;
1699
+ const { method, pathParams, groupHooks } = match;
1700
+ const ctx = buildBaseContext(req, url, pathParams, traceId, clientIp);
1701
+ const activeContext = request.context ?? getRequestContext2();
1702
+ if (activeContext) {
1703
+ activeContext.serviceName = method.serviceName;
1704
+ activeContext.action = method.key;
1705
+ }
1706
+ let deadlineTimer;
1707
+ let deadlineLink;
1708
+ let deadlineController;
1709
+ let releaseStreamReq;
1710
+ let releaseStreamOpenDeadline;
1711
+ let streamOpened = false;
1712
+ let keepRawBodySignalLink = false;
1713
+ const disarmDeadlineTimer = () => {
1714
+ if (deadlineTimer !== undefined) {
1715
+ clearTimeout(deadlineTimer);
1716
+ deadlineTimer = undefined;
1717
+ }
1718
+ };
1719
+ const releaseOpenDeadline = () => {
1720
+ disarmDeadlineTimer();
1721
+ if (!keepRawBodySignalLink) {
1722
+ deadlineLink?.release();
1723
+ deadlineLink = undefined;
1724
+ }
1725
+ releaseStreamOpenDeadline?.();
1726
+ releaseStreamOpenDeadline = undefined;
1727
+ };
1728
+ let multipartLifecycle;
1729
+ try {
1730
+ const budget = resolveServerDeadlineBudget({
1731
+ headerValue: req.headers.get(DEADLINE_BUDGET_HEADER2),
1732
+ endpointTimeoutMs: method.timeout
1733
+ });
1734
+ let activeDeadlineReader;
1735
+ if (budget.kind === "bounded") {
1736
+ const deadlineAt = performance.now() + budget.budgetMs;
1737
+ deadlineController = new AbortController;
1738
+ deadlineTimer = setTimeout(() => {
1739
+ deadlineController?.abort(abortError("Request deadline exceeded", "TimeoutError"));
1740
+ }, budget.budgetMs);
1741
+ deadlineTimer.unref?.();
1742
+ deadlineLink = linkAbortSignals(req.signal, deadlineController.signal);
1743
+ ctx.signal = deadlineLink.signal;
1744
+ activeDeadlineReader = createRemainingTimeoutReader(deadlineAt);
1745
+ ctx.remainingTimeoutMs = (reserveMs) => activeDeadlineReader?.(reserveMs);
1746
+ } else if (budget.kind === "expired") {
1747
+ ctx.remainingTimeoutMs = () => 0;
1748
+ } else {
1749
+ ctx.remainingTimeoutMs = (reserveMs) => activeDeadlineReader?.(reserveMs);
1750
+ }
1751
+ parsePathParamsInto(ctx, method);
1752
+ if (hooks?.authorize) {
1753
+ await hooks.authorize(ctx, method);
1754
+ }
1755
+ if (groupHooks?.authorize) {
1756
+ await groupHooks.authorize(ctx, method);
1757
+ }
1758
+ if (budget.kind === "expired") {
1759
+ throw new AppError2("REQUEST_TIMEOUT", {
1760
+ status: 408,
1761
+ message: "Request deadline budget exhausted"
1762
+ });
1763
+ }
1764
+ try {
1765
+ multipartLifecycle = await parseRequestPayloadInto(ctx, req, url, method, config.maxJsonBodyBytes, request.cors);
1766
+ } catch (payloadError) {
1767
+ if (payloadError instanceof MalformedQueryError) {
1768
+ badRequest2(payloadError.message);
1769
+ }
1770
+ throw payloadError;
1771
+ }
1772
+ if (hooks?.beforeHandle) {
1773
+ await hooks.beforeHandle(ctx, method);
1774
+ }
1775
+ if (groupHooks?.beforeHandle) {
1776
+ await groupHooks.beforeHandle(ctx, method);
1777
+ }
1778
+ const responseMetadata = method.responseMeta ? createResponseMetadata() : undefined;
1779
+ if (responseMetadata)
1780
+ ctx.response = responseMetadata;
1781
+ const streamAbort = method.stream ? new AbortController : undefined;
1782
+ if (streamAbort) {
1783
+ releaseStreamReq = forwardAbortSignal(req.signal, streamAbort);
1784
+ if (deadlineController && !streamAbort.signal.aborted) {
1785
+ releaseStreamOpenDeadline = forwardAbortSignal(deadlineController.signal, streamAbort);
1786
+ }
1787
+ streamAbort.signal.addEventListener("abort", () => {
1788
+ releaseStreamReq?.();
1789
+ releaseStreamReq = undefined;
1790
+ releaseStreamOpenDeadline?.();
1791
+ releaseStreamOpenDeadline = undefined;
1792
+ }, { once: true });
1793
+ ctx.signal = streamAbort.signal;
1794
+ }
1795
+ const result = await method.handler(ctx);
1796
+ if (method.stream) {
1797
+ if (deadlineController?.signal.aborted && !req.signal.aborted) {
1798
+ closeLateStreamSource(result);
1799
+ throw new AppError2("REQUEST_TIMEOUT", {
1800
+ status: 408,
1801
+ message: "Request deadline exceeded"
1802
+ });
1803
+ }
1804
+ releaseOpenDeadline();
1805
+ activeDeadlineReader = method.stream.lifetimeMs !== undefined ? createRemainingTimeoutReader(performance.now() + method.stream.lifetimeMs) : undefined;
1806
+ }
1807
+ const response = await endpointResponse(state, request, {
1808
+ ctx,
1809
+ match,
1810
+ result,
1811
+ responseMetadata,
1812
+ streamAbort
1813
+ });
1814
+ if (streamAbort && !streamAbort.signal.aborted) {
1815
+ streamOpened = true;
1816
+ }
1817
+ if (method.rawResponse && response.body !== null && !req.signal.aborted && !deadlineController?.signal.aborted) {
1818
+ disarmDeadlineTimer();
1819
+ activeDeadlineReader = undefined;
1820
+ keepRawBodySignalLink = true;
1821
+ }
1822
+ return response;
1823
+ } catch (err) {
1824
+ await multipartLifecycle?.rollback();
1825
+ return request.respondError(err, ctx, method, groupHooks);
1826
+ } finally {
1827
+ releaseOpenDeadline();
1828
+ if (!streamOpened) {
1829
+ releaseStreamReq?.();
1830
+ releaseStreamReq = undefined;
1831
+ }
1832
+ }
1833
+ }
1834
+
1835
+ // src/server/error-dispatch.ts
1836
+ var MAX_REQUEST_ABORT_CAUSE_DEPTH = 8;
1837
+ function containsRequestAbortReason(error, reason) {
1838
+ let current = error;
1839
+ const visited = new Set;
1840
+ for (let depth = 0;depth <= MAX_REQUEST_ABORT_CAUSE_DEPTH; depth += 1) {
1841
+ if (current === reason)
1842
+ return true;
1843
+ if (depth === MAX_REQUEST_ABORT_CAUSE_DEPTH || !isRecord(current))
1844
+ return false;
1845
+ if (visited.has(current))
1846
+ return false;
1847
+ visited.add(current);
1848
+ current = current.cause;
1849
+ }
1850
+ return false;
1851
+ }
1852
+ function isClientClosedRequest(req, error) {
1853
+ if (!req.signal.aborted)
1854
+ return false;
1855
+ if (isRecord(error) && error.name === "AbortError")
1856
+ return true;
1857
+ return req.signal.reason !== undefined && containsRequestAbortReason(error, req.signal.reason);
1858
+ }
1859
+ function createErrorResponder(state, request) {
1860
+ const { hooks, customLogger } = state;
1861
+ const { req, url, traceId, clientIp, complete, cors, context } = request;
1862
+ return async (err, errCtx, endpoint, group) => {
1863
+ if (isClientClosedRequest(req, err)) {
1864
+ const response = applyCors(new Response(null, { status: 499, statusText: "Client Closed Request" }), cors);
1865
+ complete(response.status, undefined, "cancelled");
1866
+ return response;
1867
+ }
1868
+ const recordFailure = (normalized) => {
1869
+ const activeContext = context ?? getRequestContext2();
1870
+ if (!activeContext || activeContext.error !== undefined)
1871
+ return;
1872
+ const known = AppError2.is(err) ? err : normalized;
1873
+ const code = known?.code ?? errorCode2(err) ?? "INTERNAL_SERVER_ERROR";
1874
+ activeContext.error = {
1875
+ code,
1876
+ message: recordedErrorMessage(code, known?.message, err),
1877
+ details: known?.details
1878
+ };
1879
+ };
1880
+ const customResponse = await dispatchErrorHooks({
1881
+ context: errCtx ?? buildErrorContext(req, url, traceId, clientIp),
1882
+ error: err,
1883
+ endpoint,
1884
+ group,
1885
+ global: hooks,
1886
+ logger: customLogger,
1887
+ respond: (response) => {
1888
+ recordFailure();
1889
+ const withCors = applyCors(response, cors);
1890
+ complete(withCors.status, errorCode2(err));
1891
+ return withCors;
1892
+ }
1893
+ });
1894
+ if (customResponse)
1895
+ return customResponse;
1896
+ const appErr = normalizeError2(err);
1897
+ recordFailure(appErr);
1898
+ complete(appErr.status, appErr.code);
1899
+ return jsonResponse(appErr.toJSON(), {
1900
+ status: appErr.status,
1901
+ headers: requestCorsHeaders(cors)
1902
+ });
1903
+ };
1904
+ }
1905
+ async function dispatchErrorHooks(config) {
1906
+ for (const [scope, hooks] of [
1907
+ ["group", config.group],
1908
+ ["global", config.global]
1909
+ ]) {
1910
+ if (!hooks?.onError)
1911
+ continue;
1912
+ try {
1913
+ const response = await hooks.onError(config.context, config.error, config.endpoint);
1914
+ if (response instanceof Response)
1915
+ return config.respond(response);
1916
+ } catch (error) {
1917
+ const message = `[stitchkit] ${scope} onError failed`;
1918
+ try {
1919
+ if (config.logger) {
1920
+ config.logger.error(message, { error, traceId: config.context.traceId });
1921
+ } else
1922
+ console.error(message, error);
1923
+ } catch {}
1924
+ }
1925
+ }
1926
+ return;
1927
+ }
1928
+
1929
+ // src/server/logger.ts
1930
+ var c = {
1931
+ reset: "\x1B[0m",
1932
+ dim: "\x1B[2m",
1933
+ red: "\x1B[31m",
1934
+ green: "\x1B[32m",
1935
+ yellow: "\x1B[33m",
1936
+ blue: "\x1B[34m",
1937
+ magenta: "\x1B[35m",
1938
+ cyan: "\x1B[36m",
1939
+ gray: "\x1B[90m"
1940
+ };
1941
+ var METHOD_COLOR = {
1942
+ GET: c.green,
1943
+ POST: c.yellow,
1944
+ PUT: c.blue,
1945
+ PATCH: c.cyan,
1946
+ DELETE: c.red,
1947
+ OPTIONS: c.gray
1948
+ };
1949
+ function resolveLogFormat(preference) {
1950
+ if (preference)
1951
+ return preference;
1952
+ const env = globalThis.process?.env ?? {};
1953
+ return env.NODE_ENV === "production" ? "json" : "pretty";
1954
+ }
1955
+ function timestamp() {
1956
+ const now = new Date;
1957
+ const t = now.toLocaleTimeString("en-US", {
1958
+ hour12: false,
1959
+ hour: "2-digit",
1960
+ minute: "2-digit",
1961
+ second: "2-digit"
1962
+ });
1963
+ return `${t}.${now.getMilliseconds().toString().padStart(3, "0")}`;
1964
+ }
1965
+ function safePath(pathname) {
1966
+ let out = "";
1967
+ for (let i = 0;i < pathname.length; i++) {
1968
+ const code = pathname.charCodeAt(i);
1969
+ if (code > 31 && code !== 127)
1970
+ out += pathname.charAt(i);
1971
+ }
1972
+ return out;
1973
+ }
1974
+ function levelForStatus(status, outcome) {
1975
+ if (status >= 500)
1976
+ return "error";
1977
+ if (status === 499 || status >= 400 && outcome === "protocol")
1978
+ return "info";
1979
+ if (status >= 400)
1980
+ return "warn";
1981
+ return "info";
1982
+ }
1983
+ function buildLogFields(method, path, status, durationMs, traceId, errorCode) {
1984
+ const fields = { traceId, method, path, status, durationMs };
1985
+ if (errorCode === undefined && status >= 400)
1986
+ return fields;
1987
+ return { ...fields, errorCode };
1988
+ }
1989
+ function formatMs(ms) {
1990
+ if (ms >= 1000)
1991
+ return `${(ms / 1000).toFixed(2)}s`;
1992
+ if (ms >= 1)
1993
+ return `${Math.round(ms)}ms`;
1994
+ return `${Math.round(ms * 1000)}µs`;
1995
+ }
1996
+ function durationColor(ms) {
1997
+ if (ms >= 1000)
1998
+ return c.red;
1999
+ if (ms > 300)
2000
+ return c.yellow;
2001
+ return c.green;
2002
+ }
2003
+ function statusColor(status) {
2004
+ if (status >= 500)
2005
+ return c.red;
2006
+ if (status >= 400)
2007
+ return c.yellow;
2008
+ if (status >= 300)
2009
+ return c.cyan;
2010
+ return c.green;
2011
+ }
2012
+ function ipLabel(ip) {
2013
+ if (!ip || ip === "::1" || ip === "127.0.0.1")
2014
+ return `${c.magenta}local${c.reset}`;
2015
+ return `${c.dim}${ip}${c.reset}`;
2016
+ }
2017
+ var SKIP_PREFIXES = ["/_bun/", "/_bundle", "/favicon"];
2018
+ function shouldLog(pathname, method) {
2019
+ if (method === "OPTIONS")
2020
+ return false;
2021
+ return !SKIP_PREFIXES.some((prefix) => pathname.startsWith(prefix));
2022
+ }
2023
+ function logIncoming(req, pathname, traceId, format, ipAddress) {
2024
+ const log = { traceId };
2025
+ if (format === "pretty") {
2026
+ const mc = METHOD_COLOR[req.method] ?? c.dim;
2027
+ console.log(`${c.gray}[${timestamp()}]${c.reset} ${mc}${req.method}${c.reset} ${c.dim}${traceId}${c.reset} ${c.cyan}→${c.reset} ${safePath(pathname)} ${ipLabel(ipAddress ?? "")}`);
2028
+ }
2029
+ return log;
2030
+ }
2031
+ function structuredLine(own, extra) {
2032
+ try {
2033
+ return JSON.stringify({ ...extra, ...own });
2034
+ } catch {
2035
+ return JSON.stringify(own);
2036
+ }
2037
+ }
2038
+ function logOutgoing(entry) {
2039
+ const {
2040
+ req,
2041
+ pathname,
2042
+ status,
2043
+ level,
2044
+ log,
2045
+ ipAddress,
2046
+ errorCode,
2047
+ durationMs,
2048
+ format,
2049
+ extra
2050
+ } = entry;
2051
+ const ms = durationMs;
2052
+ if (format === "json") {
2053
+ const own = {
2054
+ ts: new Date().toISOString(),
2055
+ level,
2056
+ msg: `${req.method} ${pathname} ${status}`,
2057
+ ...buildLogFields(req.method, pathname, status, durationMs, log.traceId, errorCode),
2058
+ ip: ipAddress
2059
+ };
2060
+ console.log(structuredLine(own, extra));
2061
+ return;
2062
+ }
2063
+ const mc = METHOD_COLOR[req.method] ?? c.dim;
2064
+ const code = errorCode ? ` ${c.red}${errorCode}${c.reset}` : "";
2065
+ console.log(`${c.gray}[${timestamp()}]${c.reset} ${mc}${req.method}${c.reset} ${c.dim}${log.traceId}${c.reset} ${c.cyan}←${c.reset} ${safePath(pathname)} ${statusColor(status)}${status}${c.reset}${code} ${durationColor(ms)}${formatMs(ms)}${c.reset} ${ipLabel(ipAddress ?? "")}`);
2066
+ }
2067
+
2068
+ // src/server/request-completion.ts
2069
+ var BODY_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
2070
+ var DEFAULT_PAYLOAD_LOG_BYTES = 1024 * 1024;
2071
+ async function readPayload(clone, maxBytes) {
2072
+ try {
2073
+ const result = await readBoundedText(clone, { maxBytes, signal: clone.signal });
2074
+ if (result.kind === "over-limit")
2075
+ return { value: undefined, truncated: true };
2076
+ return { value: JSON.parse(result.text), truncated: false };
2077
+ } catch {
2078
+ return { value: undefined, truncated: false };
2079
+ }
2080
+ }
2081
+ function openRequestCompletion(state, window) {
2082
+ const { logConfig, customLogger, useDefaultLog, observability } = state;
2083
+ const { req, url, traceId, startedAt, ipAddress } = window;
2084
+ const shouldLogRequest = logConfig !== null && shouldLog(url.pathname, req.method) && !shouldSkipLog(logConfig, req, url);
2085
+ const payloadRead = observability?.includePayload && BODY_METHODS.has(req.method) ? readPayload(req.clone(), observability.payloadMaxBytes ?? state.config.maxJsonBodyBytes ?? DEFAULT_PAYLOAD_LOG_BYTES) : undefined;
2086
+ const logFormat = resolveLogFormat(logConfig?.format);
2087
+ let reqLog;
2088
+ if (shouldLogRequest && useDefaultLog) {
2089
+ reqLog = logIncoming(req, url.pathname, traceId, logFormat, ipAddress);
2090
+ }
2091
+ if (shouldLogRequest && customLogger) {
2092
+ reqLog = { traceId };
2093
+ try {
2094
+ customLogger.debug(`${req.method} ${url.pathname}`, {
2095
+ traceId,
2096
+ method: req.method,
2097
+ path: url.pathname,
2098
+ ip: ipAddress
2099
+ });
2100
+ } catch {}
2101
+ }
2102
+ let completed = false;
2103
+ return (answer, errorCode, outcome) => {
2104
+ if (completed)
2105
+ return;
2106
+ completed = true;
2107
+ const status = typeof answer === "number" ? answer : answer.status;
2108
+ const durationMs = Math.max(0, Math.round(performance.now() - startedAt));
2109
+ if (reqLog && logConfig) {
2110
+ try {
2111
+ writeCompletionLine(state, logConfig, window, {
2112
+ reqLog,
2113
+ status,
2114
+ level: answerLevel(answer, status),
2115
+ durationMs,
2116
+ errorCode,
2117
+ logFormat
2118
+ });
2119
+ } catch {}
2120
+ }
2121
+ const context = window.context ?? getRequestContext2();
2122
+ if (observability && context) {
2123
+ try {
2124
+ observability.complete({
2125
+ context,
2126
+ statusCode: status,
2127
+ durationMs,
2128
+ ...payloadRead && {
2129
+ payload: payloadRead.then((read) => read.value),
2130
+ payloadTruncated: payloadRead.then((read) => read.truncated)
2131
+ },
2132
+ ...outcome !== undefined && { outcome }
2133
+ });
2134
+ } catch {}
2135
+ }
2136
+ };
2137
+ }
2138
+ function answerLevel(answer, status) {
2139
+ const marked = typeof answer !== "number" && isProtocolOutcome(answer);
2140
+ return levelForStatus(status, marked ? "protocol" : undefined);
2141
+ }
2142
+ function writeCompletionLine(state, logConfig, window, line) {
2143
+ const { customLogger, useDefaultLog, warnedEnrichKeys, warn } = state;
2144
+ const { req, url, ipAddress } = window;
2145
+ const { reqLog, status, level, durationMs, errorCode, logFormat } = line;
2146
+ const collected = collectExtraLogFields(logConfig, req, url, {
2147
+ status,
2148
+ durationMs,
2149
+ errorCode
2150
+ }, window.context);
2151
+ const frameworkFields = buildLogFields(req.method, url.pathname, status, durationMs, reqLog.traceId, errorCode);
2152
+ const ownedFields = { ...frameworkFields, ip: ipAddress };
2153
+ for (const key of collected.enrichKeys) {
2154
+ const ownedByActiveSink = Object.hasOwn(ownedFields, key) || useDefaultLog && (key === "ts" || key === "level" || key === "msg");
2155
+ if (ownedByActiveSink && !warnedEnrichKeys.has(key)) {
2156
+ warnedEnrichKeys.add(key);
2157
+ warn(`[stitchkit] logging.enrich field "${key}" was discarded because the framework owns it`);
2158
+ }
2159
+ }
2160
+ const extra = collected.fields;
2161
+ if (useDefaultLog) {
2162
+ logOutgoing({
2163
+ req,
2164
+ pathname: url.pathname,
2165
+ status,
2166
+ level,
2167
+ log: reqLog,
2168
+ ipAddress,
2169
+ errorCode,
2170
+ durationMs,
2171
+ format: logFormat,
2172
+ extra
2173
+ });
2174
+ }
2175
+ if (customLogger) {
2176
+ customLogger[level](`${req.method} ${url.pathname} ${status}${errorCode ? ` ${errorCode}` : ""} ${durationMs}ms`, {
2177
+ ...extra,
2178
+ ...frameworkFields,
2179
+ ip: ipAddress
2180
+ });
2181
+ }
2182
+ }
2183
+
2184
+ // src/server/create.ts
2185
+ function createHandler2(config) {
2186
+ const { trustProxy = false, observability } = config;
2187
+ const state = createHandlerState(config);
2188
+ const handler = async (req, server) => {
2189
+ const url = new URL(req.url, "http://localhost");
2190
+ const requestStartedAt = performance.now();
2191
+ const clientIp = {
2192
+ trustProxy,
2193
+ socketIp: resolveSocketIp2(req, server)
2194
+ };
2195
+ const run = async (traceId, startedAt, context) => {
2196
+ const response = await dispatch(state, req, url, traceId, server, clientIp, startedAt, context);
2197
+ try {
2198
+ response.headers.set("x-request-id", traceId);
2199
+ const buildId = config.release?.current();
2200
+ if (buildId)
2201
+ response.headers.set(RELEASE_HEADER2, buildId);
2202
+ } catch {}
2203
+ return response;
2204
+ };
2205
+ const activeContext = getRequestContext2();
2206
+ if (activeContext) {
2207
+ return run(activeContext.trace.traceId, activeContext.startedAt, activeContext);
2208
+ }
2209
+ if (!observability)
2210
+ return run(state.resolveId(req), requestStartedAt, undefined);
2211
+ const trace = resolveTraceContext2(req);
2212
+ const traceId = state.resolveId(req, trace.traceId);
2213
+ const ipAddress = extractIp2(req, clientIp) || undefined;
2214
+ const userAgent = req.headers.get("user-agent") ?? undefined;
2215
+ const requestContext = {
2216
+ source: "http",
2217
+ method: req.method,
2218
+ path: url.pathname,
2219
+ startedAt: requestStartedAt,
2220
+ trace: { ...trace, traceId },
2221
+ ...ipAddress !== undefined && { ipAddress },
2222
+ ...userAgent !== undefined && { userAgent }
2223
+ };
2224
+ return runWithRequestContext2(requestContext, () => run(traceId, requestStartedAt, requestContext));
2225
+ };
2226
+ if (trustProxy)
2227
+ markTrustProxyHandler(handler);
2228
+ return handler;
2229
+ }
2230
+ async function dispatch(state, req, url, traceId, server, clientIp, startedAt, context) {
2231
+ const { hooks, config, routeMap } = state;
2232
+ const ipAddress = extractIp2(req, clientIp) || undefined;
2233
+ const complete = openRequestCompletion(state, {
2234
+ req,
2235
+ url,
2236
+ traceId,
2237
+ startedAt,
2238
+ ipAddress,
2239
+ context
2240
+ });
2241
+ let cors;
2242
+ let corsFailed = false;
2243
+ let corsFailure;
2244
+ if (state.cors) {
2245
+ try {
2246
+ const decided = resolveRequestCors(state.cors, req.headers.get("origin"));
2247
+ cors = decided instanceof Promise ? await decided : decided;
2248
+ } catch (error) {
2249
+ corsFailed = true;
2250
+ corsFailure = error;
2251
+ cors = deniedRequestCors(state.cors);
2252
+ }
2253
+ }
2254
+ const respondError = createErrorResponder(state, {
2255
+ req,
2256
+ url,
2257
+ traceId,
2258
+ clientIp,
2259
+ complete,
2260
+ cors,
2261
+ context
2262
+ });
2263
+ if (corsFailed) {
2264
+ return respondError(new Error("The CORS origin resolver failed", { cause: corsFailure }));
2265
+ }
2266
+ const request = {
2267
+ req,
2268
+ url,
2269
+ traceId,
2270
+ server,
2271
+ clientIp,
2272
+ ipAddress,
2273
+ complete,
2274
+ respondError,
2275
+ cors,
2276
+ context
2277
+ };
2278
+ if (cors && req.method === "OPTIONS") {
2279
+ const response = new Response(null, { status: 204, headers: cors.headers });
2280
+ complete(response.status);
2281
+ return response;
2282
+ }
2283
+ try {
2284
+ if (hooks?.onRequest) {
2285
+ const earlyResponse = await hooks.onRequest(req);
2286
+ if (earlyResponse instanceof Response) {
2287
+ const withCors = applyCors(earlyResponse, cors);
2288
+ complete(earlyResponse);
2289
+ return withCors;
2290
+ }
2291
+ }
2292
+ } catch (err) {
2293
+ return respondError(err);
2294
+ }
2295
+ if (config.rawRoutes) {
2296
+ const rawMatch = matchRawRoute(config.rawRoutes, req.method, url.pathname);
2297
+ if (rawMatch) {
2298
+ if (rawMatch.route.serviceName !== undefined) {
2299
+ if (request.context) {
2300
+ request.context.serviceName = rawMatch.route.serviceName;
2301
+ if (rawMatch.route.action !== undefined) {
2302
+ request.context.action = rawMatch.route.action;
2303
+ }
2304
+ } else {
2305
+ setRequestEndpoint2(rawMatch.route.serviceName, rawMatch.route.action);
2306
+ }
2307
+ }
2308
+ try {
2309
+ const res = await rawMatch.route.handler(req, {
2310
+ params: rawMatch.params,
2311
+ server,
2312
+ ipAddress
2313
+ });
2314
+ const withCors = applyCors(res, cors);
2315
+ complete(res);
2316
+ return withCors;
2317
+ } catch (err) {
2318
+ return respondError(err);
2319
+ }
2320
+ }
2321
+ }
2322
+ const match = matchRoute(routeMap, req.method, url.pathname);
2323
+ if (!match) {
2324
+ const allow = allowedMethods(routeMap, url.pathname);
2325
+ if (allow.length > 0) {
2326
+ const res = await respondError(new AppError2("METHOD_NOT_ALLOWED", {
2327
+ message: `Method ${req.method} not allowed`,
2328
+ status: 405,
2329
+ details: { method: req.method, path: url.pathname, allow }
2330
+ }));
2331
+ res.headers.set("Allow", allow.join(", "));
2332
+ return res;
2333
+ }
2334
+ return respondError(new AppError2("UNKNOWN_OPERATION", {
2335
+ message: `No operation at ${req.method} ${url.pathname}`,
2336
+ status: 404,
2337
+ details: { method: req.method, path: url.pathname }
2338
+ }));
2339
+ }
2340
+ return dispatchEndpoint(state, request, match);
2341
+ }
2342
+
2343
+ export { isTrustProxyHandler, contextContributionDelta, prepareContextContribution, mergeContextContribution, parseMultipart2, DEFAULT_STREAM_HEARTBEAT_MS2, streamingRoute2, ndjsonRoute2, sseRoute2, createHandler2 };