wicked-crew 0.16.12 → 0.17.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 (728) hide show
  1. package/README.md +3 -2
  2. package/dist/api/audit-view.d.ts +24 -0
  3. package/dist/api/audit-view.d.ts.map +1 -0
  4. package/dist/api/audit-view.js +70 -0
  5. package/dist/api/audit-view.js.map +1 -0
  6. package/dist/api/auth.d.ts +42 -2
  7. package/dist/api/auth.d.ts.map +1 -1
  8. package/dist/api/auth.js +157 -18
  9. package/dist/api/auth.js.map +1 -1
  10. package/dist/api/capture.d.ts +12 -59
  11. package/dist/api/capture.d.ts.map +1 -1
  12. package/dist/api/capture.js +9 -17
  13. package/dist/api/capture.js.map +1 -1
  14. package/dist/api/chat-context.d.ts +6 -62
  15. package/dist/api/chat-context.d.ts.map +1 -1
  16. package/dist/api/chat-context.js +6 -12
  17. package/dist/api/chat-context.js.map +1 -1
  18. package/dist/api/chat-history.d.ts +6 -0
  19. package/dist/api/chat-history.d.ts.map +1 -1
  20. package/dist/api/chat-history.js +21 -0
  21. package/dist/api/chat-history.js.map +1 -1
  22. package/dist/api/chat-mcp.d.ts +37 -0
  23. package/dist/api/chat-mcp.d.ts.map +1 -1
  24. package/dist/api/chat-mcp.js +118 -2
  25. package/dist/api/chat-mcp.js.map +1 -1
  26. package/dist/api/chat-proposals.d.ts +82 -155
  27. package/dist/api/chat-proposals.d.ts.map +1 -1
  28. package/dist/api/chat-proposals.js +254 -28
  29. package/dist/api/chat-proposals.js.map +1 -1
  30. package/dist/api/delivery-assurance.d.ts +3 -1
  31. package/dist/api/delivery-assurance.d.ts.map +1 -1
  32. package/dist/api/delivery-assurance.js +17 -0
  33. package/dist/api/delivery-assurance.js.map +1 -1
  34. package/dist/api/delivery-freeze.d.ts +2 -8
  35. package/dist/api/delivery-freeze.d.ts.map +1 -1
  36. package/dist/api/delivery-freeze.js +2 -4
  37. package/dist/api/delivery-freeze.js.map +1 -1
  38. package/dist/api/eval-sample.d.ts +18 -114
  39. package/dist/api/eval-sample.d.ts.map +1 -1
  40. package/dist/api/eval-sample.js +7 -13
  41. package/dist/api/eval-sample.js.map +1 -1
  42. package/dist/api/governance-steering.d.ts +27 -71
  43. package/dist/api/governance-steering.d.ts.map +1 -1
  44. package/dist/api/governance-steering.js +11 -19
  45. package/dist/api/governance-steering.js.map +1 -1
  46. package/dist/api/mcp.d.ts +159 -199
  47. package/dist/api/mcp.d.ts.map +1 -1
  48. package/dist/api/mcp.js +433 -68
  49. package/dist/api/mcp.js.map +1 -1
  50. package/dist/api/needs.d.ts +10 -0
  51. package/dist/api/needs.d.ts.map +1 -1
  52. package/dist/api/needs.js +77 -0
  53. package/dist/api/needs.js.map +1 -1
  54. package/dist/api/open-path.d.ts +10 -0
  55. package/dist/api/open-path.d.ts.map +1 -1
  56. package/dist/api/open-path.js +58 -1
  57. package/dist/api/open-path.js.map +1 -1
  58. package/dist/api/plan-schema.d.ts +8 -51
  59. package/dist/api/plan-schema.d.ts.map +1 -1
  60. package/dist/api/plan-schema.js +6 -6
  61. package/dist/api/plan-schema.js.map +1 -1
  62. package/dist/api/product.d.ts +3 -22
  63. package/dist/api/product.d.ts.map +1 -1
  64. package/dist/api/product.js +4 -6
  65. package/dist/api/product.js.map +1 -1
  66. package/dist/api/project-aggregates.d.ts +12 -20
  67. package/dist/api/project-aggregates.d.ts.map +1 -1
  68. package/dist/api/project-aggregates.js +3 -3
  69. package/dist/api/project-aggregates.js.map +1 -1
  70. package/dist/api/recording.d.ts +10 -37
  71. package/dist/api/recording.d.ts.map +1 -1
  72. package/dist/api/recording.js +9 -11
  73. package/dist/api/recording.js.map +1 -1
  74. package/dist/api/routes.d.ts +173 -1507
  75. package/dist/api/routes.d.ts.map +1 -1
  76. package/dist/api/routes.js +660 -139
  77. package/dist/api/routes.js.map +1 -1
  78. package/dist/api/run-timing-index.d.ts +18 -0
  79. package/dist/api/run-timing-index.d.ts.map +1 -1
  80. package/dist/api/run-timing-index.js +34 -0
  81. package/dist/api/run-timing-index.js.map +1 -1
  82. package/dist/api/seat-images.d.ts +10 -0
  83. package/dist/api/seat-images.d.ts.map +1 -1
  84. package/dist/api/seat-images.js +16 -3
  85. package/dist/api/seat-images.js.map +1 -1
  86. package/dist/api/server-error-body.d.ts +44 -0
  87. package/dist/api/server-error-body.d.ts.map +1 -0
  88. package/dist/api/server-error-body.js +206 -0
  89. package/dist/api/server-error-body.js.map +1 -0
  90. package/dist/api/server.d.ts.map +1 -1
  91. package/dist/api/server.js +276 -4
  92. package/dist/api/server.js.map +1 -1
  93. package/dist/api/skills.d.ts +12 -36
  94. package/dist/api/skills.d.ts.map +1 -1
  95. package/dist/api/skills.js +12 -15
  96. package/dist/api/skills.js.map +1 -1
  97. package/dist/api/system-snapshot.d.ts +1 -5
  98. package/dist/api/system-snapshot.d.ts.map +1 -1
  99. package/dist/api/system-snapshot.js +7 -15
  100. package/dist/api/system-snapshot.js.map +1 -1
  101. package/dist/api/testing.d.ts +29 -50
  102. package/dist/api/testing.d.ts.map +1 -1
  103. package/dist/api/testing.js +7 -13
  104. package/dist/api/testing.js.map +1 -1
  105. package/dist/apps/actions/api-action.d.ts +47 -0
  106. package/dist/apps/actions/api-action.d.ts.map +1 -0
  107. package/dist/apps/actions/api-action.js +135 -0
  108. package/dist/apps/actions/api-action.js.map +1 -0
  109. package/dist/apps/actions/pg-fit.d.ts +27 -0
  110. package/dist/apps/actions/pg-fit.d.ts.map +1 -0
  111. package/dist/apps/actions/pg-fit.js +35 -0
  112. package/dist/apps/actions/pg-fit.js.map +1 -0
  113. package/dist/apps/actions/pg-write.d.ts +84 -0
  114. package/dist/apps/actions/pg-write.d.ts.map +1 -0
  115. package/dist/apps/actions/pg-write.js +161 -0
  116. package/dist/apps/actions/pg-write.js.map +1 -0
  117. package/dist/apps/actions/store.d.ts +109 -0
  118. package/dist/apps/actions/store.d.ts.map +1 -0
  119. package/dist/apps/actions/store.js +182 -0
  120. package/dist/apps/actions/store.js.map +1 -0
  121. package/dist/apps/actions/values.d.ts +59 -0
  122. package/dist/apps/actions/values.d.ts.map +1 -0
  123. package/dist/apps/actions/values.js +315 -0
  124. package/dist/apps/actions/values.js.map +1 -0
  125. package/dist/apps/actions/write-path.d.ts +103 -0
  126. package/dist/apps/actions/write-path.d.ts.map +1 -0
  127. package/dist/apps/actions/write-path.js +576 -0
  128. package/dist/apps/actions/write-path.js.map +1 -0
  129. package/dist/apps/check.d.ts +112 -0
  130. package/dist/apps/check.d.ts.map +1 -0
  131. package/dist/apps/check.js +358 -0
  132. package/dist/apps/check.js.map +1 -0
  133. package/dist/apps/exec/arg-types.d.ts +56 -0
  134. package/dist/apps/exec/arg-types.d.ts.map +1 -0
  135. package/dist/apps/exec/arg-types.js +234 -0
  136. package/dist/apps/exec/arg-types.js.map +1 -0
  137. package/dist/apps/exec/cache.d.ts +46 -0
  138. package/dist/apps/exec/cache.d.ts.map +1 -0
  139. package/dist/apps/exec/cache.js +93 -0
  140. package/dist/apps/exec/cache.js.map +1 -0
  141. package/dist/apps/exec/contract.d.ts +83 -0
  142. package/dist/apps/exec/contract.d.ts.map +1 -0
  143. package/dist/apps/exec/contract.js +220 -0
  144. package/dist/apps/exec/contract.js.map +1 -0
  145. package/dist/apps/exec/executor.d.ts +122 -0
  146. package/dist/apps/exec/executor.d.ts.map +1 -0
  147. package/dist/apps/exec/executor.js +455 -0
  148. package/dist/apps/exec/executor.js.map +1 -0
  149. package/dist/apps/exec/limits.d.ts +25 -0
  150. package/dist/apps/exec/limits.d.ts.map +1 -0
  151. package/dist/apps/exec/limits.js +71 -0
  152. package/dist/apps/exec/limits.js.map +1 -0
  153. package/dist/apps/exec/params.d.ts +34 -0
  154. package/dist/apps/exec/params.d.ts.map +1 -0
  155. package/dist/apps/exec/params.js +97 -0
  156. package/dist/apps/exec/params.js.map +1 -0
  157. package/dist/apps/exec/project.d.ts +67 -0
  158. package/dist/apps/exec/project.d.ts.map +1 -0
  159. package/dist/apps/exec/project.js +299 -0
  160. package/dist/apps/exec/project.js.map +1 -0
  161. package/dist/apps/exec/recall.d.ts +88 -0
  162. package/dist/apps/exec/recall.d.ts.map +1 -0
  163. package/dist/apps/exec/recall.js +301 -0
  164. package/dist/apps/exec/recall.js.map +1 -0
  165. package/dist/apps/exec/source-stage.d.ts +61 -0
  166. package/dist/apps/exec/source-stage.d.ts.map +1 -0
  167. package/dist/apps/exec/source-stage.js +540 -0
  168. package/dist/apps/exec/source-stage.js.map +1 -0
  169. package/dist/apps/exec/sources.d.ts +65 -0
  170. package/dist/apps/exec/sources.d.ts.map +1 -0
  171. package/dist/apps/exec/sources.js +77 -0
  172. package/dist/apps/exec/sources.js.map +1 -0
  173. package/dist/apps/exec/texts.d.ts +140 -0
  174. package/dist/apps/exec/texts.d.ts.map +1 -0
  175. package/dist/apps/exec/texts.js +76 -0
  176. package/dist/apps/exec/texts.js.map +1 -0
  177. package/dist/apps/exec/viewer.d.ts +11 -0
  178. package/dist/apps/exec/viewer.d.ts.map +1 -0
  179. package/dist/apps/exec/viewer.js +26 -0
  180. package/dist/apps/exec/viewer.js.map +1 -0
  181. package/dist/apps/git.d.ts +109 -0
  182. package/dist/apps/git.d.ts.map +1 -0
  183. package/dist/apps/git.js +361 -0
  184. package/dist/apps/git.js.map +1 -0
  185. package/dist/apps/publish/image.d.ts +25 -0
  186. package/dist/apps/publish/image.d.ts.map +1 -0
  187. package/dist/apps/publish/image.js +86 -0
  188. package/dist/apps/publish/image.js.map +1 -0
  189. package/dist/apps/publish/layout.d.ts +41 -0
  190. package/dist/apps/publish/layout.d.ts.map +1 -0
  191. package/dist/apps/publish/layout.js +31 -0
  192. package/dist/apps/publish/layout.js.map +1 -0
  193. package/dist/apps/publish/manifest.d.ts +64 -0
  194. package/dist/apps/publish/manifest.d.ts.map +1 -0
  195. package/dist/apps/publish/manifest.js +282 -0
  196. package/dist/apps/publish/manifest.js.map +1 -0
  197. package/dist/apps/publish/pack.d.ts +40 -0
  198. package/dist/apps/publish/pack.d.ts.map +1 -0
  199. package/dist/apps/publish/pack.js +78 -0
  200. package/dist/apps/publish/pack.js.map +1 -0
  201. package/dist/apps/routes.d.ts +103 -0
  202. package/dist/apps/routes.d.ts.map +1 -0
  203. package/dist/apps/routes.js +440 -0
  204. package/dist/apps/routes.js.map +1 -0
  205. package/dist/apps/spec.d.ts +691 -0
  206. package/dist/apps/spec.d.ts.map +1 -0
  207. package/dist/apps/spec.js +839 -0
  208. package/dist/apps/spec.js.map +1 -0
  209. package/dist/apps/store.d.ts +341 -0
  210. package/dist/apps/store.d.ts.map +1 -0
  211. package/dist/apps/store.js +905 -0
  212. package/dist/apps/store.js.map +1 -0
  213. package/dist/apps/turns.d.ts +169 -0
  214. package/dist/apps/turns.d.ts.map +1 -0
  215. package/dist/apps/turns.js +556 -0
  216. package/dist/apps/turns.js.map +1 -0
  217. package/dist/apps/views.d.ts +44 -0
  218. package/dist/apps/views.d.ts.map +1 -0
  219. package/dist/apps/views.js +53 -0
  220. package/dist/apps/views.js.map +1 -0
  221. package/dist/campaigns/routes.d.ts +22 -94
  222. package/dist/campaigns/routes.d.ts.map +1 -1
  223. package/dist/campaigns/routes.js +8 -14
  224. package/dist/campaigns/routes.js.map +1 -1
  225. package/dist/cli/apps-check.d.ts +43 -0
  226. package/dist/cli/apps-check.d.ts.map +1 -0
  227. package/dist/cli/apps-check.js +166 -0
  228. package/dist/cli/apps-check.js.map +1 -0
  229. package/dist/cli/index.d.ts.map +1 -1
  230. package/dist/cli/index.js +9 -4
  231. package/dist/cli/index.js.map +1 -1
  232. package/dist/cli/mcp.js +2 -2
  233. package/dist/cli/mcp.js.map +1 -1
  234. package/dist/core/adapter.d.ts +23 -0
  235. package/dist/core/adapter.d.ts.map +1 -1
  236. package/dist/core/adapter.js +49 -1
  237. package/dist/core/adapter.js.map +1 -1
  238. package/dist/core/deliver-text.d.ts +25 -0
  239. package/dist/core/deliver-text.d.ts.map +1 -1
  240. package/dist/core/deliver-text.js +50 -5
  241. package/dist/core/deliver-text.js.map +1 -1
  242. package/dist/core/deliver.d.ts.map +1 -1
  243. package/dist/core/deliver.js +6 -0
  244. package/dist/core/deliver.js.map +1 -1
  245. package/dist/core/estate-mcp-client.d.ts +9 -0
  246. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  247. package/dist/core/estate-mcp-client.js +31 -3
  248. package/dist/core/estate-mcp-client.js.map +1 -1
  249. package/dist/core/linked-issues.d.ts +51 -3
  250. package/dist/core/linked-issues.d.ts.map +1 -1
  251. package/dist/core/linked-issues.js +59 -14
  252. package/dist/core/linked-issues.js.map +1 -1
  253. package/dist/core/run-boot-resume.d.ts +4 -1
  254. package/dist/core/run-boot-resume.d.ts.map +1 -1
  255. package/dist/core/run-boot-resume.js +6 -1
  256. package/dist/core/run-boot-resume.js.map +1 -1
  257. package/dist/decisions/chat-recorder.js +1 -1
  258. package/dist/decisions/chat-recorder.js.map +1 -1
  259. package/dist/decisions/routes.d.ts.map +1 -1
  260. package/dist/decisions/routes.js +5 -9
  261. package/dist/decisions/routes.js.map +1 -1
  262. package/dist/decisions/rules-brief.d.ts +76 -0
  263. package/dist/decisions/rules-brief.d.ts.map +1 -0
  264. package/dist/decisions/rules-brief.js +179 -0
  265. package/dist/decisions/rules-brief.js.map +1 -0
  266. package/dist/editors/csp.d.ts +24 -4
  267. package/dist/editors/csp.d.ts.map +1 -1
  268. package/dist/editors/csp.js +35 -8
  269. package/dist/editors/csp.js.map +1 -1
  270. package/dist/editors/registry.d.ts +97 -258
  271. package/dist/editors/registry.d.ts.map +1 -1
  272. package/dist/editors/registry.js +11 -11
  273. package/dist/editors/registry.js.map +1 -1
  274. package/dist/editors/routes.d.ts +4 -1
  275. package/dist/editors/routes.d.ts.map +1 -1
  276. package/dist/editors/routes.js +33 -6
  277. package/dist/editors/routes.js.map +1 -1
  278. package/dist/editors/webrtc-guard.d.ts +94 -0
  279. package/dist/editors/webrtc-guard.d.ts.map +1 -0
  280. package/dist/editors/webrtc-guard.js +506 -0
  281. package/dist/editors/webrtc-guard.js.map +1 -0
  282. package/dist/evals/routes.d.ts.map +1 -1
  283. package/dist/evals/routes.js +3 -5
  284. package/dist/evals/routes.js.map +1 -1
  285. package/dist/insights/routes.js +2 -2
  286. package/dist/insights/routes.js.map +1 -1
  287. package/dist/interactive/bridge-pool.d.ts +11 -2
  288. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  289. package/dist/interactive/bridge-pool.js +10 -1
  290. package/dist/interactive/bridge-pool.js.map +1 -1
  291. package/dist/interactive/doc-binding.d.ts +156 -0
  292. package/dist/interactive/doc-binding.d.ts.map +1 -0
  293. package/dist/interactive/doc-binding.js +277 -0
  294. package/dist/interactive/doc-binding.js.map +1 -0
  295. package/dist/interactive/doc-delete-routes.d.ts +3 -0
  296. package/dist/interactive/doc-delete-routes.d.ts.map +1 -1
  297. package/dist/interactive/doc-delete-routes.js +4 -0
  298. package/dist/interactive/doc-delete-routes.js.map +1 -1
  299. package/dist/interactive/draft-events.d.ts +89 -3
  300. package/dist/interactive/draft-events.d.ts.map +1 -1
  301. package/dist/interactive/draft-events.js +438 -27
  302. package/dist/interactive/draft-events.js.map +1 -1
  303. package/dist/interactive/edit-events.d.ts +2 -0
  304. package/dist/interactive/edit-events.d.ts.map +1 -1
  305. package/dist/interactive/edit-events.js +11 -0
  306. package/dist/interactive/edit-events.js.map +1 -1
  307. package/dist/interactive/proposal-create.d.ts +143 -0
  308. package/dist/interactive/proposal-create.d.ts.map +1 -0
  309. package/dist/interactive/proposal-create.js +318 -0
  310. package/dist/interactive/proposal-create.js.map +1 -0
  311. package/dist/interactive/proxy-routes.d.ts +60 -3
  312. package/dist/interactive/proxy-routes.d.ts.map +1 -1
  313. package/dist/interactive/proxy-routes.js +285 -10
  314. package/dist/interactive/proxy-routes.js.map +1 -1
  315. package/dist/interactive/source-packet.d.ts +126 -0
  316. package/dist/interactive/source-packet.d.ts.map +1 -0
  317. package/dist/interactive/source-packet.js +482 -0
  318. package/dist/interactive/source-packet.js.map +1 -0
  319. package/dist/interactive/ws-relay.d.ts +3 -9
  320. package/dist/interactive/ws-relay.d.ts.map +1 -1
  321. package/dist/interactive/ws-relay.js +4 -6
  322. package/dist/interactive/ws-relay.js.map +1 -1
  323. package/dist/knowledge/adapters/native.d.ts +44 -0
  324. package/dist/knowledge/adapters/native.d.ts.map +1 -0
  325. package/dist/knowledge/adapters/native.js +60 -0
  326. package/dist/knowledge/adapters/native.js.map +1 -0
  327. package/dist/knowledge/adapters/toolbox/binary.d.ts +48 -0
  328. package/dist/knowledge/adapters/toolbox/binary.d.ts.map +1 -0
  329. package/dist/knowledge/adapters/toolbox/binary.js +145 -0
  330. package/dist/knowledge/adapters/toolbox/binary.js.map +1 -0
  331. package/dist/knowledge/adapters/toolbox/catalog.d.ts +22 -0
  332. package/dist/knowledge/adapters/toolbox/catalog.d.ts.map +1 -0
  333. package/dist/knowledge/adapters/toolbox/catalog.js +87 -0
  334. package/dist/knowledge/adapters/toolbox/catalog.js.map +1 -0
  335. package/dist/knowledge/adapters/toolbox/document.d.ts +71 -0
  336. package/dist/knowledge/adapters/toolbox/document.d.ts.map +1 -0
  337. package/dist/knowledge/adapters/toolbox/document.js +165 -0
  338. package/dist/knowledge/adapters/toolbox/document.js.map +1 -0
  339. package/dist/knowledge/adapters/toolbox/supervisor.d.ts +142 -0
  340. package/dist/knowledge/adapters/toolbox/supervisor.d.ts.map +1 -0
  341. package/dist/knowledge/adapters/toolbox/supervisor.js +438 -0
  342. package/dist/knowledge/adapters/toolbox/supervisor.js.map +1 -0
  343. package/dist/knowledge/gate/access.d.ts +36 -0
  344. package/dist/knowledge/gate/access.d.ts.map +1 -0
  345. package/dist/knowledge/gate/access.js +46 -0
  346. package/dist/knowledge/gate/access.js.map +1 -0
  347. package/dist/knowledge/gate/envelope.d.ts +67 -0
  348. package/dist/knowledge/gate/envelope.d.ts.map +1 -0
  349. package/dist/knowledge/gate/envelope.js +96 -0
  350. package/dist/knowledge/gate/envelope.js.map +1 -0
  351. package/dist/knowledge/gate/gate.d.ts +238 -0
  352. package/dist/knowledge/gate/gate.d.ts.map +1 -0
  353. package/dist/knowledge/gate/gate.js +782 -0
  354. package/dist/knowledge/gate/gate.js.map +1 -0
  355. package/dist/knowledge/gate/pg.d.ts +57 -0
  356. package/dist/knowledge/gate/pg.d.ts.map +1 -0
  357. package/dist/knowledge/gate/pg.js +94 -0
  358. package/dist/knowledge/gate/pg.js.map +1 -0
  359. package/dist/knowledge/gate/record.d.ts +77 -0
  360. package/dist/knowledge/gate/record.d.ts.map +1 -0
  361. package/dist/knowledge/gate/record.js +205 -0
  362. package/dist/knowledge/gate/record.js.map +1 -0
  363. package/dist/knowledge/gate/routes.d.ts +38 -0
  364. package/dist/knowledge/gate/routes.d.ts.map +1 -0
  365. package/dist/knowledge/gate/routes.js +102 -0
  366. package/dist/knowledge/gate/routes.js.map +1 -0
  367. package/dist/knowledge/gate/scheduler.d.ts +90 -0
  368. package/dist/knowledge/gate/scheduler.d.ts.map +1 -0
  369. package/dist/knowledge/gate/scheduler.js +224 -0
  370. package/dist/knowledge/gate/scheduler.js.map +1 -0
  371. package/dist/knowledge/gate/sources.d.ts +69 -0
  372. package/dist/knowledge/gate/sources.d.ts.map +1 -0
  373. package/dist/knowledge/gate/sources.js +135 -0
  374. package/dist/knowledge/gate/sources.js.map +1 -0
  375. package/dist/knowledge/package.d.ts +136 -0
  376. package/dist/knowledge/package.d.ts.map +1 -0
  377. package/dist/knowledge/package.js +148 -0
  378. package/dist/knowledge/package.js.map +1 -0
  379. package/dist/knowledge/projector.d.ts +144 -0
  380. package/dist/knowledge/projector.d.ts.map +1 -0
  381. package/dist/knowledge/projector.js +287 -0
  382. package/dist/knowledge/projector.js.map +1 -0
  383. package/dist/knowledge/registry/entry.d.ts +177 -0
  384. package/dist/knowledge/registry/entry.d.ts.map +1 -0
  385. package/dist/knowledge/registry/entry.js +126 -0
  386. package/dist/knowledge/registry/entry.js.map +1 -0
  387. package/dist/knowledge/registry/policy.d.ts +79 -0
  388. package/dist/knowledge/registry/policy.d.ts.map +1 -0
  389. package/dist/knowledge/registry/policy.js +139 -0
  390. package/dist/knowledge/registry/policy.js.map +1 -0
  391. package/dist/knowledge/shapes/code-search.d.ts +55 -0
  392. package/dist/knowledge/shapes/code-search.d.ts.map +1 -0
  393. package/dist/knowledge/shapes/code-search.js +88 -0
  394. package/dist/knowledge/shapes/code-search.js.map +1 -0
  395. package/dist/knowledge/shapes/map.d.ts +25 -0
  396. package/dist/knowledge/shapes/map.d.ts.map +1 -0
  397. package/dist/knowledge/shapes/map.js +187 -0
  398. package/dist/knowledge/shapes/map.js.map +1 -0
  399. package/dist/knowledge/shapes/profile.d.ts +117 -0
  400. package/dist/knowledge/shapes/profile.d.ts.map +1 -0
  401. package/dist/knowledge/shapes/profile.js +264 -0
  402. package/dist/knowledge/shapes/profile.js.map +1 -0
  403. package/dist/knowledge/shapes/routes.d.ts +69 -0
  404. package/dist/knowledge/shapes/routes.d.ts.map +1 -0
  405. package/dist/knowledge/shapes/routes.js +270 -0
  406. package/dist/knowledge/shapes/routes.js.map +1 -0
  407. package/dist/knowledge/shapes/shapes.d.ts +144 -0
  408. package/dist/knowledge/shapes/shapes.d.ts.map +1 -0
  409. package/dist/knowledge/shapes/shapes.js +280 -0
  410. package/dist/knowledge/shapes/shapes.js.map +1 -0
  411. package/dist/knowledge/shapes/verified.d.ts +36 -0
  412. package/dist/knowledge/shapes/verified.d.ts.map +1 -0
  413. package/dist/knowledge/shapes/verified.js +73 -0
  414. package/dist/knowledge/shapes/verified.js.map +1 -0
  415. package/dist/knowledge/summary.d.ts +45 -0
  416. package/dist/knowledge/summary.d.ts.map +1 -0
  417. package/dist/knowledge/summary.js +119 -0
  418. package/dist/knowledge/summary.js.map +1 -0
  419. package/dist/knowledge/trackers/actions.d.ts +55 -0
  420. package/dist/knowledge/trackers/actions.d.ts.map +1 -0
  421. package/dist/knowledge/trackers/actions.js +327 -0
  422. package/dist/knowledge/trackers/actions.js.map +1 -0
  423. package/dist/knowledge/trackers/addresses.d.ts +45 -0
  424. package/dist/knowledge/trackers/addresses.d.ts.map +1 -0
  425. package/dist/knowledge/trackers/addresses.js +59 -0
  426. package/dist/knowledge/trackers/addresses.js.map +1 -0
  427. package/dist/knowledge/trackers/bindings.d.ts +190 -0
  428. package/dist/knowledge/trackers/bindings.d.ts.map +1 -0
  429. package/dist/knowledge/trackers/bindings.js +970 -0
  430. package/dist/knowledge/trackers/bindings.js.map +1 -0
  431. package/dist/knowledge/trackers/gate-pm.d.ts +160 -0
  432. package/dist/knowledge/trackers/gate-pm.d.ts.map +1 -0
  433. package/dist/knowledge/trackers/gate-pm.js +427 -0
  434. package/dist/knowledge/trackers/gate-pm.js.map +1 -0
  435. package/dist/knowledge/trackers/issues.d.ts +69 -0
  436. package/dist/knowledge/trackers/issues.d.ts.map +1 -0
  437. package/dist/knowledge/trackers/issues.js +193 -0
  438. package/dist/knowledge/trackers/issues.js.map +1 -0
  439. package/dist/knowledge/trackers/map.d.ts +23 -0
  440. package/dist/knowledge/trackers/map.d.ts.map +1 -0
  441. package/dist/knowledge/trackers/map.js +130 -0
  442. package/dist/knowledge/trackers/map.js.map +1 -0
  443. package/dist/knowledge/trackers/projector.d.ts +113 -0
  444. package/dist/knowledge/trackers/projector.d.ts.map +1 -0
  445. package/dist/knowledge/trackers/projector.js +274 -0
  446. package/dist/knowledge/trackers/projector.js.map +1 -0
  447. package/dist/knowledge/trackers/routes.d.ts +107 -0
  448. package/dist/knowledge/trackers/routes.d.ts.map +1 -0
  449. package/dist/knowledge/trackers/routes.js +563 -0
  450. package/dist/knowledge/trackers/routes.js.map +1 -0
  451. package/dist/knowledge/trackers/set.d.ts +61 -0
  452. package/dist/knowledge/trackers/set.d.ts.map +1 -0
  453. package/dist/knowledge/trackers/set.js +77 -0
  454. package/dist/knowledge/trackers/set.js.map +1 -0
  455. package/dist/knowledge/trackers/view.d.ts +22 -0
  456. package/dist/knowledge/trackers/view.d.ts.map +1 -0
  457. package/dist/knowledge/trackers/view.js +31 -0
  458. package/dist/knowledge/trackers/view.js.map +1 -0
  459. package/dist/knowledge/trackers/visible.d.ts +9 -0
  460. package/dist/knowledge/trackers/visible.d.ts.map +1 -0
  461. package/dist/knowledge/trackers/visible.js +10 -0
  462. package/dist/knowledge/trackers/visible.js.map +1 -0
  463. package/dist/learn/routes.d.ts +3 -17
  464. package/dist/learn/routes.d.ts.map +1 -1
  465. package/dist/learn/routes.js +4 -6
  466. package/dist/learn/routes.js.map +1 -1
  467. package/dist/mcp/ask-server.d.ts +6 -0
  468. package/dist/mcp/ask-server.d.ts.map +1 -1
  469. package/dist/mcp/ask-server.js +15 -9
  470. package/dist/mcp/ask-server.js.map +1 -1
  471. package/dist/mcp/broker.d.ts +16 -0
  472. package/dist/mcp/broker.d.ts.map +1 -1
  473. package/dist/mcp/broker.js +137 -3
  474. package/dist/mcp/broker.js.map +1 -1
  475. package/dist/mcp/estate-relay.d.ts +50 -2
  476. package/dist/mcp/estate-relay.d.ts.map +1 -1
  477. package/dist/mcp/estate-relay.js +126 -4
  478. package/dist/mcp/estate-relay.js.map +1 -1
  479. package/dist/mcp/invoke.d.ts +12 -1
  480. package/dist/mcp/invoke.d.ts.map +1 -1
  481. package/dist/mcp/invoke.js +5 -2
  482. package/dist/mcp/invoke.js.map +1 -1
  483. package/dist/mcp/probe.d.ts +34 -2
  484. package/dist/mcp/probe.d.ts.map +1 -1
  485. package/dist/mcp/probe.js +51 -9
  486. package/dist/mcp/probe.js.map +1 -1
  487. package/dist/mcp/registry-store.d.ts +91 -0
  488. package/dist/mcp/registry-store.d.ts.map +1 -1
  489. package/dist/mcp/registry-store.js +116 -9
  490. package/dist/mcp/registry-store.js.map +1 -1
  491. package/dist/mcp/registry.d.ts +249 -6
  492. package/dist/mcp/registry.d.ts.map +1 -1
  493. package/dist/mcp/registry.js +735 -35
  494. package/dist/mcp/registry.js.map +1 -1
  495. package/dist/mcp/rest.d.ts +36 -10
  496. package/dist/mcp/rest.d.ts.map +1 -1
  497. package/dist/mcp/rest.js +71 -73
  498. package/dist/mcp/rest.js.map +1 -1
  499. package/dist/mcp/tool-list.d.ts +7 -0
  500. package/dist/mcp/tool-list.d.ts.map +1 -1
  501. package/dist/mcp/tool-list.js +32 -4
  502. package/dist/mcp/tool-list.js.map +1 -1
  503. package/dist/mcp-inspect/routes.d.ts +3 -0
  504. package/dist/mcp-inspect/routes.d.ts.map +1 -1
  505. package/dist/mcp-inspect/routes.js +31 -18
  506. package/dist/mcp-inspect/routes.js.map +1 -1
  507. package/dist/persona/routes.d.ts +14 -69
  508. package/dist/persona/routes.d.ts.map +1 -1
  509. package/dist/persona/routes.js +2 -2
  510. package/dist/persona/routes.js.map +1 -1
  511. package/dist/persona/store.d.ts +13 -40
  512. package/dist/persona/store.d.ts.map +1 -1
  513. package/dist/persona/store.js +9 -11
  514. package/dist/persona/store.js.map +1 -1
  515. package/dist/presets/routes.d.ts +3 -21
  516. package/dist/presets/routes.d.ts.map +1 -1
  517. package/dist/presets/routes.js +5 -7
  518. package/dist/presets/routes.js.map +1 -1
  519. package/dist/projects/repo-guard.d.ts +32 -0
  520. package/dist/projects/repo-guard.d.ts.map +1 -0
  521. package/dist/projects/repo-guard.js +46 -0
  522. package/dist/projects/repo-guard.js.map +1 -0
  523. package/dist/projects/routes.d.ts +16 -44
  524. package/dist/projects/routes.d.ts.map +1 -1
  525. package/dist/projects/routes.js +15 -18
  526. package/dist/projects/routes.js.map +1 -1
  527. package/dist/schedules/routes.d.ts +4 -18
  528. package/dist/schedules/routes.d.ts.map +1 -1
  529. package/dist/schedules/routes.js +4 -6
  530. package/dist/schedules/routes.js.map +1 -1
  531. package/dist/skills/plugin-source.d.ts +6 -5
  532. package/dist/skills/plugin-source.d.ts.map +1 -1
  533. package/dist/skills/plugin-source.js +6 -5
  534. package/dist/skills/plugin-source.js.map +1 -1
  535. package/dist/sources/ask.d.ts +108 -0
  536. package/dist/sources/ask.d.ts.map +1 -0
  537. package/dist/sources/ask.js +251 -0
  538. package/dist/sources/ask.js.map +1 -0
  539. package/dist/sources/catalog/mysql.d.ts +9 -0
  540. package/dist/sources/catalog/mysql.d.ts.map +1 -0
  541. package/dist/sources/catalog/mysql.js +77 -0
  542. package/dist/sources/catalog/mysql.js.map +1 -0
  543. package/dist/sources/catalog/postgres.d.ts +68 -0
  544. package/dist/sources/catalog/postgres.d.ts.map +1 -0
  545. package/dist/sources/catalog/postgres.js +164 -0
  546. package/dist/sources/catalog/postgres.js.map +1 -0
  547. package/dist/sources/catalog/types.d.ts +53 -0
  548. package/dist/sources/catalog/types.d.ts.map +1 -0
  549. package/dist/sources/catalog/types.js +30 -0
  550. package/dist/sources/catalog/types.js.map +1 -0
  551. package/dist/sources/connection-test.d.ts +37 -0
  552. package/dist/sources/connection-test.d.ts.map +1 -0
  553. package/dist/sources/connection-test.js +101 -0
  554. package/dist/sources/connection-test.js.map +1 -0
  555. package/dist/sources/crew-source.d.ts +31 -0
  556. package/dist/sources/crew-source.d.ts.map +1 -0
  557. package/dist/sources/crew-source.js +48 -0
  558. package/dist/sources/crew-source.js.map +1 -0
  559. package/dist/sources/dialer.d.ts +169 -0
  560. package/dist/sources/dialer.d.ts.map +1 -0
  561. package/dist/sources/dialer.js +761 -0
  562. package/dist/sources/dialer.js.map +1 -0
  563. package/dist/sources/drivers/mysql.d.ts +52 -0
  564. package/dist/sources/drivers/mysql.d.ts.map +1 -0
  565. package/dist/sources/drivers/mysql.js +348 -0
  566. package/dist/sources/drivers/mysql.js.map +1 -0
  567. package/dist/sources/drivers/postgres.d.ts +84 -0
  568. package/dist/sources/drivers/postgres.d.ts.map +1 -0
  569. package/dist/sources/drivers/postgres.js +381 -0
  570. package/dist/sources/drivers/postgres.js.map +1 -0
  571. package/dist/sources/drivers/sqlite.d.ts +47 -0
  572. package/dist/sources/drivers/sqlite.d.ts.map +1 -0
  573. package/dist/sources/drivers/sqlite.js +156 -0
  574. package/dist/sources/drivers/sqlite.js.map +1 -0
  575. package/dist/sources/drivers/types.d.ts +79 -0
  576. package/dist/sources/drivers/types.d.ts.map +1 -0
  577. package/dist/sources/drivers/types.js +31 -0
  578. package/dist/sources/drivers/types.js.map +1 -0
  579. package/dist/sources/graphql.d.ts +85 -0
  580. package/dist/sources/graphql.d.ts.map +1 -0
  581. package/dist/sources/graphql.js +155 -0
  582. package/dist/sources/graphql.js.map +1 -0
  583. package/dist/sources/kinds.d.ts +79 -0
  584. package/dist/sources/kinds.d.ts.map +1 -0
  585. package/dist/sources/kinds.js +145 -0
  586. package/dist/sources/kinds.js.map +1 -0
  587. package/dist/sources/policy/allowlists.d.ts +30 -0
  588. package/dist/sources/policy/allowlists.d.ts.map +1 -0
  589. package/dist/sources/policy/allowlists.js +104 -0
  590. package/dist/sources/policy/allowlists.js.map +1 -0
  591. package/dist/sources/policy/index.d.ts +20 -0
  592. package/dist/sources/policy/index.d.ts.map +1 -0
  593. package/dist/sources/policy/index.js +34 -0
  594. package/dist/sources/policy/index.js.map +1 -0
  595. package/dist/sources/policy/mysql.d.ts +21 -0
  596. package/dist/sources/policy/mysql.d.ts.map +1 -0
  597. package/dist/sources/policy/mysql.js +834 -0
  598. package/dist/sources/policy/mysql.js.map +1 -0
  599. package/dist/sources/policy/pg.d.ts +37 -0
  600. package/dist/sources/policy/pg.d.ts.map +1 -0
  601. package/dist/sources/policy/pg.js +572 -0
  602. package/dist/sources/policy/pg.js.map +1 -0
  603. package/dist/sources/policy/sqlite.d.ts +37 -0
  604. package/dist/sources/policy/sqlite.d.ts.map +1 -0
  605. package/dist/sources/policy/sqlite.js +94 -0
  606. package/dist/sources/policy/sqlite.js.map +1 -0
  607. package/dist/sources/policy/types.d.ts +46 -0
  608. package/dist/sources/policy/types.d.ts.map +1 -0
  609. package/dist/sources/policy/types.js +13 -0
  610. package/dist/sources/policy/types.js.map +1 -0
  611. package/dist/sources/routes.d.ts +154 -0
  612. package/dist/sources/routes.d.ts.map +1 -0
  613. package/dist/sources/routes.js +745 -0
  614. package/dist/sources/routes.js.map +1 -0
  615. package/dist/sources/safety/postgres.d.ts +87 -0
  616. package/dist/sources/safety/postgres.d.ts.map +1 -0
  617. package/dist/sources/safety/postgres.js +349 -0
  618. package/dist/sources/safety/postgres.js.map +1 -0
  619. package/dist/sources/sql.d.ts +51 -0
  620. package/dist/sources/sql.d.ts.map +1 -0
  621. package/dist/sources/sql.js +89 -0
  622. package/dist/sources/sql.js.map +1 -0
  623. package/dist/sources/store.d.ts +25 -0
  624. package/dist/sources/store.d.ts.map +1 -0
  625. package/dist/sources/store.js +59 -0
  626. package/dist/sources/store.js.map +1 -0
  627. package/dist/sources/uploads.d.ts +70 -0
  628. package/dist/sources/uploads.d.ts.map +1 -0
  629. package/dist/sources/uploads.js +636 -0
  630. package/dist/sources/uploads.js.map +1 -0
  631. package/dist/standing-orders/parse.d.ts +38 -0
  632. package/dist/standing-orders/parse.d.ts.map +1 -1
  633. package/dist/standing-orders/parse.js +104 -43
  634. package/dist/standing-orders/parse.js.map +1 -1
  635. package/dist/standing-orders/routes.d.ts +25 -126
  636. package/dist/standing-orders/routes.d.ts.map +1 -1
  637. package/dist/standing-orders/routes.js +4 -6
  638. package/dist/standing-orders/routes.js.map +1 -1
  639. package/dist/standing-orders/store.d.ts +22 -73
  640. package/dist/standing-orders/store.d.ts.map +1 -1
  641. package/dist/standing-orders/store.js +8 -12
  642. package/dist/standing-orders/store.js.map +1 -1
  643. package/dist/studio/assets/KnowledgeGraph-Cpm46tEp.js +1 -0
  644. package/dist/studio/assets/WickedSansA-Regular-CGPJLyb8.woff2 +0 -0
  645. package/dist/studio/assets/WickedSansA-SemiBold-Bk9KXUaV.woff2 +0 -0
  646. package/dist/studio/assets/favicon-BJA6hF2f.svg +1 -0
  647. package/dist/studio/assets/index-BRBwWQMH.css +32 -0
  648. package/dist/studio/assets/index-CVrWDGRP.js +1097 -0
  649. package/dist/studio/assets/wicked-studio-lettering-small-CBwSGqop.svg +2 -0
  650. package/dist/studio/assets/wicked-studio-wordmark-small-gF5xn6IC.svg +2 -0
  651. package/dist/studio/editors/wicked-apps/editor.json +45 -0
  652. package/dist/studio/editors/wicked-apps/icon.svg +1 -0
  653. package/dist/studio/editors/wicked-apps/index.html +151 -0
  654. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  655. package/dist/studio/editors/wicked-deck/index.html +12 -8
  656. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  657. package/dist/studio/editors/wicked-doc/index.html +12 -8
  658. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  659. package/dist/studio/editors/wicked-insights/index.html +1 -1
  660. package/dist/studio/editors/wicked-page/editor.json +1 -1
  661. package/dist/studio/editors/wicked-page/index.html +12 -8
  662. package/dist/studio/editors/wicked-video/editor.json +1 -1
  663. package/dist/studio/editors/wicked-video/index.html +1 -1
  664. package/dist/studio/fonts/LICENSE-WickedSans.txt +97 -0
  665. package/dist/studio/index.html +3 -2
  666. package/dist/studio/testid-inventory.json +10850 -6700
  667. package/dist/team/routes.d.ts +21 -172
  668. package/dist/team/routes.d.ts.map +1 -1
  669. package/dist/team/routes.js +4 -8
  670. package/dist/team/routes.js.map +1 -1
  671. package/dist/voice/dashboard.d.ts +35 -313
  672. package/dist/voice/dashboard.d.ts.map +1 -1
  673. package/dist/voice/dashboard.js +10 -10
  674. package/dist/voice/dashboard.js.map +1 -1
  675. package/dist/voice/routes.d.ts +2 -6
  676. package/dist/voice/routes.d.ts.map +1 -1
  677. package/dist/voice/routes.js +2 -2
  678. package/dist/voice/routes.js.map +1 -1
  679. package/dist/watch/checks/check-failed.d.ts +4 -10
  680. package/dist/watch/checks/check-failed.d.ts.map +1 -1
  681. package/dist/watch/checks/check-failed.js +6 -8
  682. package/dist/watch/checks/check-failed.js.map +1 -1
  683. package/dist/watch/checks/claim-vs-evidence.js +3 -3
  684. package/dist/watch/checks/claim-vs-evidence.js.map +1 -1
  685. package/dist/watch/checks/deliver-audit.js +3 -3
  686. package/dist/watch/checks/deliver-audit.js.map +1 -1
  687. package/dist/watch/checks/discovery.d.ts.map +1 -1
  688. package/dist/watch/checks/discovery.js +5 -7
  689. package/dist/watch/checks/discovery.js.map +1 -1
  690. package/dist/watch/checks/lag.d.ts +4 -10
  691. package/dist/watch/checks/lag.d.ts.map +1 -1
  692. package/dist/watch/checks/lag.js +6 -8
  693. package/dist/watch/checks/lag.js.map +1 -1
  694. package/dist/watch/checks/quiet-after-claim.js +3 -3
  695. package/dist/watch/checks/quiet-after-claim.js.map +1 -1
  696. package/dist/watch/checks/scope-drift.js +3 -3
  697. package/dist/watch/checks/scope-drift.js.map +1 -1
  698. package/dist/watch/checks/team-path.js +2 -2
  699. package/dist/watch/checks/team-path.js.map +1 -1
  700. package/dist/watch/checks/ungated.js +3 -3
  701. package/dist/watch/checks/ungated.js.map +1 -1
  702. package/dist/watch/checks/warned-rule.js +3 -3
  703. package/dist/watch/checks/warned-rule.js.map +1 -1
  704. package/dist/watch/loader.d.ts.map +1 -1
  705. package/dist/watch/loader.js +12 -16
  706. package/dist/watch/loader.js.map +1 -1
  707. package/dist/workflow-catalog/build.d.ts +2 -0
  708. package/dist/workflow-catalog/build.d.ts.map +1 -1
  709. package/dist/workflow-catalog/build.js +8 -4
  710. package/dist/workflow-catalog/build.js.map +1 -1
  711. package/dist/workflow-catalog/catalog-data.d.ts +7 -1
  712. package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
  713. package/dist/workflow-catalog/catalog-data.js +36 -7
  714. package/dist/workflow-catalog/catalog-data.js.map +1 -1
  715. package/dist/working-doc/service.d.ts.map +1 -1
  716. package/dist/working-doc/service.js +2 -1
  717. package/dist/working-doc/service.js.map +1 -1
  718. package/dist/zod.d.ts +39 -0
  719. package/dist/zod.d.ts.map +1 -0
  720. package/dist/zod.js +197 -0
  721. package/dist/zod.js.map +1 -0
  722. package/endpoint-manifest.json +617 -7
  723. package/package.json +11 -5
  724. package/runners/sqlite-runner.mjs +110 -0
  725. package/dist/studio/assets/WickedSans-Regular-fb698rcD.woff2 +0 -0
  726. package/dist/studio/assets/WickedSans-SemiBold-CD53n1AC.woff2 +0 -0
  727. package/dist/studio/assets/index-BUZ_-Syk.css +0 -32
  728. package/dist/studio/assets/index-C_UIgTiy.js +0 -986
@@ -0,0 +1,761 @@
1
+ /**
2
+ * The ONE dialer (DES-APPS-001 §5.2, S10): every outbound connection crew makes to a source — a spec
3
+ * download, a describe, a test call, a query, an action, an `mcp-http` server's calls, OIDC discovery
4
+ * and keys — goes through here. `mcp-stdio` is outside it by design: a local program the person
5
+ * installed, whose own network use is trusted like any program they run.
6
+ *
7
+ * What it does, in order, for every connection:
8
+ *
9
+ * 1. **Resolve once.** A name is resolved exactly once per connection (all addresses, verbatim).
10
+ * 2. **Normalize.** An IPv4-mapped IPv6 address (`::ffff:127.0.0.1`, `::ffff:7f00:1`) is judged and
11
+ * dialled as the IPv4 address it is. Forms that embed an IPv4 address the dialer cannot judge
12
+ * (IPv4-compatible `::a.b.c.d`, SIIT `::ffff:0:a.b.c.d`, NAT64 `64:ff9b::/96` and
13
+ * `64:ff9b:1::/48`, 6to4 `2002::/16`, Teredo `2001::/32`) are refused, as are zone ids.
14
+ * 3. **Check every address.** One refused address refuses the connection, so a name that answers a
15
+ * public and a metadata address cannot be steered between them. The default is global unicast
16
+ * only. A loopback or private range (127/8, ::1, 10/8, 172.16/12, 192.168/16, fc00::/7) is allowed
17
+ * only when the person confirmed a range covering it for THIS source ({@link AddressPolicy}).
18
+ * "This network" (0/8), link-local (169.254/16 and fe80::/10, which hold the cloud metadata
19
+ * address 169.254.169.254), CGNAT (100.64/10), the AWS IPv6 metadata address `fd00:ec2::254`,
20
+ * multicast, documentation, benchmarking and reserved ranges are ALWAYS refused and cannot be
21
+ * confirmed.
22
+ * 4. **Connect to the checked address**, never to the name again: TCP goes to that address (a
23
+ * pinned `lookup` for HTTP), while the hostname is kept for TLS (SNI and certificate checks), so a
24
+ * record that re-resolves between the check and the connection (DNS rebinding) changes nothing.
25
+ * 5. **Refuse redirects.** Any 3xx is refused, never followed.
26
+ * 6. **TLS by default.** HTTPS only; plaintext `http:` only to loopback, or to a private range the
27
+ * person confirmed as plaintext. Certificates are verified (Node's defaults, TLS 1.2 or later).
28
+ */
29
+ import { lookup as dnsLookup } from 'node:dns/promises';
30
+ import { request as httpRequest } from 'node:http';
31
+ import { request as httpsRequest } from 'node:https';
32
+ import { connect as netConnect, isIP } from 'node:net';
33
+ import { pipeline, Readable } from 'node:stream';
34
+ import { constants as zlibConstants, createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib';
35
+ import { UpstreamCallError } from '../mcp/upstream-error.js';
36
+ const V4_ALWAYS_REFUSED = [
37
+ ['0.0.0.0', 8, '"this network" (0.0.0.0/8)'],
38
+ ['169.254.0.0', 16, 'link-local (169.254.0.0/16, where cloud metadata lives)'],
39
+ ['100.64.0.0', 10, 'carrier-grade NAT (100.64.0.0/10)'],
40
+ ['192.0.0.0', 24, 'IETF protocol assignments (192.0.0.0/24)'],
41
+ ['192.0.2.0', 24, 'documentation (192.0.2.0/24)'],
42
+ ['192.88.99.0', 24, 'the 6to4 relay anycast (192.88.99.0/24)'],
43
+ ['198.18.0.0', 15, 'benchmarking (198.18.0.0/15)'],
44
+ ['198.51.100.0', 24, 'documentation (198.51.100.0/24)'],
45
+ ['203.0.113.0', 24, 'documentation (203.0.113.0/24)'],
46
+ ['224.0.0.0', 4, 'multicast (224.0.0.0/4)'],
47
+ ['240.0.0.0', 4, 'reserved (240.0.0.0/4)'],
48
+ ];
49
+ const V4_LOOPBACK = [['127.0.0.0', 8]];
50
+ const V4_PRIVATE = [['10.0.0.0', 8], ['172.16.0.0', 12], ['192.168.0.0', 16]];
51
+ const V6_ALWAYS_REFUSED = [
52
+ ['fd00:ec2::254', 128, 'the cloud metadata address (fd00:ec2::254)'],
53
+ ['fd20:ce::254', 128, 'the cloud metadata address (fd20:ce::254)'],
54
+ ['::', 128, 'the unspecified address (::)'],
55
+ ['::', 96, 'an IPv4-compatible address (::/96, deprecated)'],
56
+ ['::ffff:0:0:0', 96, 'an SIIT IPv4-translated address (::ffff:0:0:0/96)'],
57
+ ['64:ff9b::', 96, 'a NAT64 address (64:ff9b::/96), which can reach any IPv4 address'],
58
+ ['64:ff9b:1::', 48, 'a local-use NAT64 address (64:ff9b:1::/48), which can reach any IPv4 address'],
59
+ ['100::', 64, 'the discard prefix (100::/64)'],
60
+ // IETF protocol assignments (2001::/23): Teredo (which embeds an IPv4 address), benchmarking,
61
+ // ORCHID, AMT, AS112 and the rest. No source lives there, so the whole block is refused.
62
+ ['2001::', 23, 'IETF protocol assignments (2001::/23: Teredo, benchmarking, ORCHID, …)'],
63
+ ['2001:db8::', 32, 'documentation (2001:db8::/32)'],
64
+ ['3fff::', 20, 'documentation (3fff::/20)'],
65
+ ['5f00::', 16, 'SRv6 SIDs (5f00::/16)'],
66
+ ['2002::', 16, '6to4 (2002::/16), which embeds an IPv4 address'],
67
+ ['fe80::', 10, 'link-local (fe80::/10)'],
68
+ ['fec0::', 10, 'site-local (fec0::/10, deprecated)'],
69
+ ['ff00::', 8, 'multicast (ff00::/8)'],
70
+ ];
71
+ const V6_LOOPBACK = [['::1', 128]];
72
+ const V6_PRIVATE = [['fc00::', 7]];
73
+ const V6_GLOBAL = ['2000::', 3];
74
+ function v4ToBig(ip) {
75
+ const parts = ip.split('.').map((p) => Number(p));
76
+ return parts.reduce((acc, p) => (acc << 8n) | BigInt(p), 0n);
77
+ }
78
+ function bigToV4(n) {
79
+ return [24n, 16n, 8n, 0n].map((s) => String(Number((n >> s) & 0xffn))).join('.');
80
+ }
81
+ /** Parse an IPv6 literal (no brackets, no zone) to its 128-bit value; `null` = not one. */
82
+ function v6ToBig(ip) {
83
+ if (isIP(ip) !== 6)
84
+ return null;
85
+ let text = ip.toLowerCase();
86
+ // An embedded dotted quad (`::ffff:1.2.3.4`) becomes two hex groups.
87
+ const dotted = /(\d+\.\d+\.\d+\.\d+)$/.exec(text);
88
+ if (dotted !== null) {
89
+ const v4 = v4ToBig(dotted[1]);
90
+ text = `${text.slice(0, -dotted[1].length)}${((v4 >> 16n) & 0xffffn).toString(16)}:${(v4 & 0xffffn).toString(16)}`;
91
+ }
92
+ const halves = text.split('::');
93
+ if (halves.length > 2)
94
+ return null;
95
+ const head = halves[0] === '' ? [] : halves[0].split(':');
96
+ const tail = halves.length === 2 ? (halves[1] === '' ? [] : halves[1].split(':')) : [];
97
+ const fill = halves.length === 2 ? 8 - head.length - tail.length : 0;
98
+ if (fill < 0)
99
+ return null;
100
+ const groups = [...head, ...Array(fill).fill('0'), ...tail];
101
+ if (groups.length !== 8)
102
+ return null;
103
+ let n = 0n;
104
+ for (const g of groups) {
105
+ if (!/^[0-9a-f]{1,4}$/.test(g))
106
+ return null;
107
+ n = (n << 16n) | BigInt(parseInt(g, 16));
108
+ }
109
+ return n;
110
+ }
111
+ function inPrefix(addr, net, prefix, bits) {
112
+ const shift = BigInt(bits - prefix);
113
+ return addr >> shift === net >> shift;
114
+ }
115
+ const v4In = (a, list) => list.find(([net, p]) => inPrefix(a, v4ToBig(net), p, 32));
116
+ const v6In = (a, list) => list.find(([net, p]) => inPrefix(a, v6ToBig(net), p, 128));
117
+ /**
118
+ * Normalize and class one address. An IPv4-mapped IPv6 address is classed (and dialled) as its
119
+ * IPv4 address; every other embedding of IPv4 in IPv6 is refused. Anything that is not an IP
120
+ * literal (a name, a zone id, garbage) is `refused`.
121
+ */
122
+ export function classifyAddress(raw) {
123
+ const ip = raw.replace(/^\[|\]$/g, '');
124
+ if (ip.includes('%'))
125
+ return { address: ip, family: 6, cls: 'refused', why: 'an address with a zone id' };
126
+ const family = isIP(ip);
127
+ if (family === 4) {
128
+ const a = v4ToBig(ip);
129
+ const refused = V4_ALWAYS_REFUSED.find(([net, p]) => inPrefix(a, v4ToBig(net), p, 32));
130
+ if (refused !== undefined)
131
+ return { address: ip, family: 4, cls: 'refused', why: refused[2] };
132
+ if (v4In(a, V4_LOOPBACK) !== undefined)
133
+ return { address: ip, family: 4, cls: 'loopback', why: null };
134
+ if (v4In(a, V4_PRIVATE) !== undefined)
135
+ return { address: ip, family: 4, cls: 'private', why: null };
136
+ return { address: ip, family: 4, cls: 'global', why: null };
137
+ }
138
+ if (family === 6) {
139
+ const a = v6ToBig(ip);
140
+ if (a === null)
141
+ return { address: ip, family: 6, cls: 'refused', why: 'an unparseable IPv6 address' };
142
+ // IPv4-mapped (::ffff:0:0/96): judged and dialled as the IPv4 address it carries.
143
+ if (inPrefix(a, 0xffff00000000n, 96, 128))
144
+ return classifyAddress(bigToV4(a & 0xffffffffn));
145
+ if (a === 1n)
146
+ return { address: '::1', family: 6, cls: 'loopback', why: null };
147
+ const refused = V6_ALWAYS_REFUSED.find(([net, p]) => inPrefix(a, v6ToBig(net), p, 128));
148
+ if (refused !== undefined)
149
+ return { address: ip.toLowerCase(), family: 6, cls: 'refused', why: refused[2] };
150
+ if (v6In(a, V6_LOOPBACK) !== undefined)
151
+ return { address: ip.toLowerCase(), family: 6, cls: 'loopback', why: null };
152
+ if (v6In(a, V6_PRIVATE) !== undefined)
153
+ return { address: ip.toLowerCase(), family: 6, cls: 'private', why: null };
154
+ if (!inPrefix(a, v6ToBig(V6_GLOBAL[0]), V6_GLOBAL[1], 128)) {
155
+ return { address: ip.toLowerCase(), family: 6, cls: 'refused', why: 'outside IPv6 global unicast (2000::/3)' };
156
+ }
157
+ return { address: ip.toLowerCase(), family: 6, cls: 'global', why: null };
158
+ }
159
+ return { address: ip, family: 4, cls: 'refused', why: 'not an IP address' };
160
+ }
161
+ export const NO_CONFIRMATION = Object.freeze({ allow: Object.freeze([]), plaintext: false });
162
+ /** A source's policy: what it carries, or nothing confirmed. */
163
+ export function addressPolicyOf(config) {
164
+ return config.address ?? NO_CONFIRMATION;
165
+ }
166
+ /**
167
+ * The ranges a URL the person TYPED confirms by itself, and nothing more: an IP literal in a loopback
168
+ * or private range confirms exactly that address (`/32` or `/128`: there is no name to re-resolve);
169
+ * `localhost` confirms loopback (RFC 6761). A private host NAME confirms nothing: what it resolves
170
+ * to can change, so its range must be confirmed explicitly.
171
+ */
172
+ export function exactRangesFor(raw) {
173
+ let url;
174
+ try {
175
+ url = new URL(raw ?? '');
176
+ }
177
+ catch {
178
+ return [];
179
+ }
180
+ const host = url.hostname.replace(/^\[|\]$/g, '').toLowerCase().replace(/\.$/, '');
181
+ if (host === 'localhost' || host.endsWith('.localhost'))
182
+ return ['127.0.0.0/8', '::1/128'];
183
+ if (isIP(host) === 0)
184
+ return [];
185
+ const c = classifyAddress(host);
186
+ if (c.cls !== 'loopback' && c.cls !== 'private')
187
+ return [];
188
+ return [`${c.address}/${c.family === 4 ? 32 : 128}`];
189
+ }
190
+ function parseRange(cidr) {
191
+ const m = /^([^/]+)\/(\d{1,3})$/.exec(cidr.trim());
192
+ if (m === null)
193
+ return null;
194
+ const ip = m[1];
195
+ const prefix = Number(m[2]);
196
+ const family = isIP(ip);
197
+ if (family === 4 && prefix <= 32)
198
+ return { family: 4, net: v4ToBig(ip), prefix };
199
+ if (family === 6 && prefix <= 128) {
200
+ const net = v6ToBig(ip);
201
+ return net === null ? null : { family: 6, net, prefix };
202
+ }
203
+ return null;
204
+ }
205
+ /**
206
+ * Check a confirmation's ranges: each a CIDR lying wholly inside loopback (127/8, ::1/128) or a
207
+ * private range (10/8, 172.16/12, 192.168/16, fc00::/7). Answers the problem, or `null` when every
208
+ * range is acceptable. Global addresses need no confirmation; refused ones can never have one.
209
+ */
210
+ export function validateAllowRanges(ranges) {
211
+ for (const r of ranges) {
212
+ const p = parseRange(r);
213
+ if (p === null)
214
+ return `${JSON.stringify(r)} is not a CIDR range (like 10.0.0.0/8 or fc00::/7)`;
215
+ const within = (list, bits, toBig) => list.some(([net, prefix]) => p.prefix >= prefix && inPrefix(p.net, toBig(net), prefix, bits));
216
+ const ok = p.family === 4
217
+ ? within([...V4_LOOPBACK, ...V4_PRIVATE], 32, v4ToBig)
218
+ : within([...V6_LOOPBACK, ...V6_PRIVATE], 128, (s) => v6ToBig(s));
219
+ if (!ok) {
220
+ return `${r} is not inside a loopback or private range (127.0.0.0/8, ::1/128, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7); only those can be confirmed`;
221
+ }
222
+ // A range lying wholly inside an always-refused one (the IPv6 metadata address inside fc00::/7)
223
+ // confirms nothing the dialer would ever allow: refused, so no record or audit claims it.
224
+ const isLoopbackV6 = p.family === 6 && p.prefix === 128 && p.net === 1n;
225
+ const refusedList = p.family === 4 ? V4_ALWAYS_REFUSED : isLoopbackV6 ? [] : V6_ALWAYS_REFUSED;
226
+ const toBig = p.family === 4 ? v4ToBig : (x) => v6ToBig(x);
227
+ const inside = refusedList.find(([net, prefix]) => p.prefix >= prefix && inPrefix(p.net, toBig(net), prefix, p.family === 4 ? 32 : 128));
228
+ if (inside !== undefined)
229
+ return `${r} lies inside ${inside[2]}, which is always refused and can never be confirmed`;
230
+ }
231
+ return null;
232
+ }
233
+ /** Whether two addresses are the same address, whatever their spelling (IPv4-mapped included). */
234
+ export function sameAddress(a, b) {
235
+ const ca = classifyAddress(a);
236
+ const cb = classifyAddress(b);
237
+ if (ca.family !== cb.family)
238
+ return false;
239
+ if (ca.family === 4)
240
+ return ca.address === cb.address;
241
+ return v6ToBig(ca.address) !== null && v6ToBig(ca.address) === v6ToBig(cb.address);
242
+ }
243
+ /** Whether `address` (normalized) lies in one of the confirmed ranges. */
244
+ function confirmed(address, policy) {
245
+ const a = address.family === 4 ? v4ToBig(address.address) : v6ToBig(address.address);
246
+ if (a === null)
247
+ return false;
248
+ return policy.allow.some((r) => {
249
+ const p = parseRange(r);
250
+ return p !== null && p.family === address.family && inPrefix(a, p.net, p.prefix, address.family === 4 ? 32 : 128);
251
+ });
252
+ }
253
+ /** Whether plaintext (no TLS) may be used to an address of this class under `policy`. */
254
+ export function plaintextAllowed(cls, policy) {
255
+ return cls === 'loopback' || (cls === 'private' && policy.plaintext);
256
+ }
257
+ /**
258
+ * A connection the dialer refused, before any byte left (or, for a redirect, before it was
259
+ * followed). An {@link UpstreamCallError} of class `boundary`: never retried, recorded as a
260
+ * `guard_error` by the broker.
261
+ */
262
+ export class DialRefusedError extends UpstreamCallError {
263
+ code;
264
+ constructor(code, message) {
265
+ super('boundary', false, message);
266
+ this.code = code;
267
+ this.name = 'DialRefusedError';
268
+ }
269
+ }
270
+ /** A 3xx answer: refused, never followed. Carries what was answered so a caller can say more. */
271
+ export class DialRedirectRefusedError extends DialRefusedError {
272
+ status;
273
+ location;
274
+ constructor(status, location, message) {
275
+ super('redirect_refused', message);
276
+ this.status = status;
277
+ this.location = location;
278
+ this.name = 'DialRedirectRefusedError';
279
+ }
280
+ }
281
+ const RESOLVE_TIMEOUT_MS = 3_000;
282
+ export const systemResolver = async (hostname) => {
283
+ let timer;
284
+ try {
285
+ const found = await Promise.race([
286
+ dnsLookup(hostname, { all: true, verbatim: true }),
287
+ new Promise((_r, reject) => {
288
+ timer = setTimeout(() => reject(new Error('timeout')), RESOLVE_TIMEOUT_MS);
289
+ }),
290
+ ]);
291
+ return found.map((a) => a.address);
292
+ }
293
+ catch {
294
+ return [];
295
+ }
296
+ finally {
297
+ clearTimeout(timer);
298
+ }
299
+ };
300
+ /** Read through a call, so TypeScript does not keep an earlier narrowing across an await. */
301
+ function isAborted(signal) {
302
+ return signal?.aborted === true;
303
+ }
304
+ function abortError(signal) {
305
+ return signal.reason instanceof Error ? signal.reason : new DOMException('aborted', 'AbortError');
306
+ }
307
+ /**
308
+ * Resolve `host` once and check every address against `policy`. Throws {@link DialRefusedError}
309
+ * naming the first address refused. An abort during resolution rejects at once and nothing dials.
310
+ */
311
+ export async function resolveTarget(host, policy, resolver = systemResolver, signal) {
312
+ const hostname = host.replace(/^\[|\]$/g, '');
313
+ if (hostname === '')
314
+ throw new DialRefusedError('url_refused', 'the connection names no host');
315
+ if (signal?.aborted === true)
316
+ throw abortError(signal);
317
+ const literal = isIP(hostname) !== 0 || hostname.includes('%');
318
+ let answers;
319
+ if (literal)
320
+ answers = [hostname];
321
+ else if (signal === undefined)
322
+ answers = await resolver(hostname);
323
+ else {
324
+ let onAbort;
325
+ try {
326
+ answers = await Promise.race([
327
+ resolver(hostname),
328
+ new Promise((_r, reject) => {
329
+ onAbort = () => reject(abortError(signal));
330
+ signal.addEventListener('abort', onAbort, { once: true });
331
+ }),
332
+ ]);
333
+ }
334
+ finally {
335
+ if (onAbort !== undefined)
336
+ signal.removeEventListener('abort', onAbort);
337
+ }
338
+ }
339
+ if (signal !== undefined && isAborted(signal))
340
+ throw abortError(signal);
341
+ if (answers.length === 0)
342
+ throw new DialRefusedError('unresolved', `${hostname} did not resolve, so crew could not check where it goes`);
343
+ const checked = answers.map((a) => classifyAddress(a));
344
+ for (const c of checked) {
345
+ const named = literal ? c.address : `${hostname} (${c.address})`;
346
+ if (c.cls === 'refused')
347
+ throw new DialRefusedError('address_refused', `${named} is refused: ${c.why ?? 'not allowed'}; crew never connects there`);
348
+ if ((c.cls === 'loopback' || c.cls === 'private') && !confirmed(c, policy)) {
349
+ throw new DialRefusedError('address_unconfirmed', `${named} is a ${c.cls} address, which a source reaches only when the person confirms a range covering it for that source (e.g. ${suggestRange(c)})`);
350
+ }
351
+ }
352
+ const unique = checked.filter((c, i) => checked.findIndex((d) => sameAddress(d.address, c.address)) === i);
353
+ const first = unique[0];
354
+ return { hostname, address: first.address, family: first.family, cls: first.cls, addresses: unique.map((c) => ({ address: c.address, family: c.family, cls: c.cls })) };
355
+ }
356
+ /** Whether `remote` is one of the addresses the target was checked at. */
357
+ function isCheckedAddress(target, remote) {
358
+ return remote !== undefined && target.addresses.some((a) => sameAddress(a.address, remote));
359
+ }
360
+ /**
361
+ * Refuse a scheme the target may not use: https always; plaintext http only where
362
+ * {@link plaintextAllowed} for EVERY address the name resolved to. Used before any byte is sent, and
363
+ * by a preview that only checks a base URL (so a preview never accepts what every call would refuse).
364
+ */
365
+ export function checkScheme(url, target, policy) {
366
+ if (url.protocol === 'https:')
367
+ return;
368
+ if (url.protocol !== 'http:')
369
+ throw new DialRefusedError('url_refused', `${url.protocol} URLs are not dialled; https only`);
370
+ const blocked = target.addresses.find((a) => !plaintextAllowed(a.cls, policy));
371
+ if (blocked === undefined)
372
+ return;
373
+ throw new DialRefusedError('plaintext_refused', blocked.cls === 'private'
374
+ ? `plaintext http to ${url.host} (${blocked.address}) is refused: confirm this private range as plaintext for the source, or use https`
375
+ : `plaintext http to ${url.host} is refused: use https (plaintext is only for loopback, or a private range the person confirmed as plaintext)`);
376
+ }
377
+ /** The range a person would confirm for an address: its private or loopback block. */
378
+ export function suggestRange(c) {
379
+ if (c.family === 6)
380
+ return c.cls === 'loopback' ? '::1/128' : 'fc00::/7';
381
+ const a = v4ToBig(c.address);
382
+ const block = [...V4_LOOPBACK, ...V4_PRIVATE].find(([net, p]) => inPrefix(a, v4ToBig(net), p, 32));
383
+ return block === undefined ? `${c.address}/32` : `${block[0]}/${block[1]}`;
384
+ }
385
+ const CONNECT_TIMEOUT_MS = 10_000;
386
+ /**
387
+ * A TCP connection to `host:port` under `policy`: resolved once, every address checked, connected
388
+ * to a checked address (trying each in turn, as dual-stack fallback, never resolving again). The
389
+ * database drivers run their own TLS over it with the hostname as the server name (`tls.ts`).
390
+ */
391
+ export async function dialTcp(host, port, policy, opts = {}) {
392
+ if (!Number.isInteger(port) || port < 1 || port > 65_535)
393
+ throw new DialRefusedError('url_refused', `port ${port} is not a TCP port`);
394
+ const target = await resolveTarget(host, policy, opts.resolver, opts.signal);
395
+ let last = null;
396
+ for (const a of target.addresses) {
397
+ if (opts.signal?.aborted === true)
398
+ throw abortError(opts.signal);
399
+ const socket = netConnect({ host: a.address, port, family: a.family });
400
+ socket.setNoDelay(true);
401
+ let aborted = false;
402
+ try {
403
+ await new Promise((resolve, reject) => {
404
+ const done = () => {
405
+ clearTimeout(timer);
406
+ opts.signal?.removeEventListener('abort', onAbort);
407
+ };
408
+ const onAbort = () => {
409
+ aborted = true;
410
+ done();
411
+ socket.destroy();
412
+ reject(abortError(opts.signal));
413
+ };
414
+ const timer = setTimeout(() => {
415
+ done();
416
+ socket.destroy();
417
+ reject(new UpstreamCallError('timeout', false, `connecting to ${host}:${port} timed out`));
418
+ }, opts.connectTimeoutMs ?? CONNECT_TIMEOUT_MS);
419
+ opts.signal?.addEventListener('abort', onAbort, { once: true });
420
+ socket.once('connect', () => {
421
+ done();
422
+ resolve();
423
+ });
424
+ socket.once('error', (err) => {
425
+ done();
426
+ reject(new UpstreamCallError('transport', true, `connecting to ${host}:${port} (${a.address}) failed: ${err.message}`));
427
+ });
428
+ });
429
+ }
430
+ catch (err) {
431
+ if (aborted)
432
+ throw err;
433
+ last = err;
434
+ continue;
435
+ }
436
+ // Belt and braces: the socket is where the check said.
437
+ if (!isCheckedAddress(target, socket.remoteAddress)) {
438
+ socket.destroy();
439
+ throw new DialRefusedError('address_refused', `the connection to ${host} reached ${socket.remoteAddress ?? 'nothing'}, not a checked address`);
440
+ }
441
+ return { socket, target: { ...target, address: a.address, family: a.family, cls: a.cls } };
442
+ }
443
+ throw last instanceof Error ? last : new UpstreamCallError('transport', true, `connecting to ${host}:${port} failed`);
444
+ }
445
+ function bodyBytes(body) {
446
+ if (body === undefined || body === null)
447
+ return null;
448
+ if (typeof body === 'string')
449
+ return Buffer.from(body, 'utf8');
450
+ if (body instanceof ArrayBuffer)
451
+ return Buffer.from(body);
452
+ if (body instanceof Uint8Array)
453
+ return Buffer.from(body.buffer, body.byteOffset, body.byteLength);
454
+ throw new DialRefusedError('url_refused', 'the dialer sends a string or bytes as a request body, nothing else');
455
+ }
456
+ const NULL_BODY_STATUSES = new Set([204, 205, 304]);
457
+ /** zlib options as fetch (undici) uses them: a truncated or empty compressed body is not an error. */
458
+ const ZLIB_LENIENT = { flush: zlibConstants.Z_SYNC_FLUSH, finishFlush: zlibConstants.Z_SYNC_FLUSH };
459
+ /** The most content codings undone on one answer (fetch/undici's limit). */
460
+ const MAX_CODINGS = 5;
461
+ /** The first byte of a stream, put back unread; `null` = the stream ended empty. */
462
+ async function peekFirstByte(src) {
463
+ for (;;) {
464
+ const chunk = src.read();
465
+ if (chunk !== null) {
466
+ src.unshift(chunk);
467
+ return chunk[0] ?? null;
468
+ }
469
+ if (src.readableEnded || src.destroyed)
470
+ return null;
471
+ await new Promise((resolve) => {
472
+ const done = () => {
473
+ src.off('readable', done);
474
+ src.off('end', done);
475
+ src.off('error', done);
476
+ src.off('close', done);
477
+ resolve();
478
+ };
479
+ src.on('readable', done);
480
+ src.on('end', done);
481
+ src.on('error', done);
482
+ src.on('close', done);
483
+ });
484
+ }
485
+ }
486
+ /**
487
+ * The body as the server meant it: each coding of `Content-Encoding` (gzip, x-gzip, deflate, br,
488
+ * identity) is undone in reverse order, streamed with backpressure (a consumer that stops reading
489
+ * stops the decoders), torn down together; callers still cap what they read. `deflate` is decoded
490
+ * as fetch does: zlib-wrapped when its first byte says so, raw deflate otherwise.
491
+ */
492
+ async function decoded(res) {
493
+ const codings = String(res.headers['content-encoding'] ?? '')
494
+ .split(',')
495
+ .map((c) => c.trim().toLowerCase())
496
+ .filter((c) => c !== '' && c !== 'identity')
497
+ .reverse();
498
+ if (codings.length === 0)
499
+ return { stream: res, encoded: false };
500
+ if (codings.length > MAX_CODINGS)
501
+ throw new UpstreamCallError('protocol', false, `the answer is encoded ${codings.length} times; crew decodes at most ${MAX_CODINGS} codings`);
502
+ for (const c of codings)
503
+ if (!['gzip', 'x-gzip', 'deflate', 'br'].includes(c))
504
+ throw new UpstreamCallError('protocol', false, `the answer is encoded as ${c}, which crew does not decode`);
505
+ let current = res;
506
+ for (const c of codings) {
507
+ let decoder;
508
+ if (c === 'gzip' || c === 'x-gzip')
509
+ decoder = createGunzip(ZLIB_LENIENT);
510
+ else if (c === 'br')
511
+ decoder = createBrotliDecompress({ flush: zlibConstants.BROTLI_OPERATION_FLUSH, finishFlush: zlibConstants.BROTLI_OPERATION_FLUSH });
512
+ else {
513
+ const first = await peekFirstByte(current);
514
+ decoder = first !== null && (first & 0x0f) !== 0x08 ? createInflateRaw(ZLIB_LENIENT) : createInflate(ZLIB_LENIENT);
515
+ }
516
+ // pipeline: backpressure end to end, and an error or destroy anywhere tears every stage down.
517
+ pipeline(current, decoder, () => undefined);
518
+ current = decoder;
519
+ }
520
+ return { stream: current, encoded: true };
521
+ }
522
+ /** A transport failure as one non-empty message carrying its codes (dual-stack attempts end in an AggregateError). */
523
+ function transportError(host, err) {
524
+ if (err instanceof UpstreamCallError || (err instanceof Error && (err.name === 'AbortError' || err.name === 'TimeoutError')))
525
+ return err;
526
+ const parts = [];
527
+ const add = (e) => {
528
+ const x = e;
529
+ if (Array.isArray(x?.errors))
530
+ for (const inner of x.errors)
531
+ add(inner);
532
+ const code = typeof x?.code === 'string' ? x.code : '';
533
+ const msg = typeof x?.message === 'string' ? x.message : '';
534
+ const text = [code, msg].filter((v) => v !== '' && !msg.includes(code)).join(' ') || msg || code;
535
+ if (text !== '' && !parts.includes(text))
536
+ parts.push(text);
537
+ };
538
+ add(err);
539
+ return new UpstreamCallError('transport', true, `connecting to ${host} failed: ${parts.join('; ') || 'the connection failed'}`);
540
+ }
541
+ /**
542
+ * One HTTP(S) request under `policy`, answered as a WHATWG `Response` whose body streams (callers cap
543
+ * it; nothing here buffers it whole) and is decoded (gzip, deflate, br). https always; http only where
544
+ * {@link plaintextAllowed}. Any 3xx is a {@link DialRedirectRefusedError}; an upgrade (101) or a
545
+ * connection that closes before an answer is a refusal, never a hang. The URL may carry no credentials.
546
+ */
547
+ export async function dialFetch(input, init = {}, policy, opts = {}) {
548
+ let url;
549
+ try {
550
+ url = new URL(typeof input === 'string' ? input : input.href);
551
+ }
552
+ catch {
553
+ throw new DialRefusedError('url_refused', `${String(input)} is not a URL`);
554
+ }
555
+ if (url.protocol !== 'https:' && url.protocol !== 'http:')
556
+ throw new DialRefusedError('url_refused', `${url.protocol} URLs are not dialled; https only`);
557
+ if (url.username !== '' || url.password !== '')
558
+ throw new DialRefusedError('url_refused', 'a URL carrying credentials is refused; reference a secret instead');
559
+ const signal = init.signal ?? undefined;
560
+ const target = await resolveTarget(url.hostname, policy, opts.resolver, signal);
561
+ checkScheme(url, target, policy);
562
+ const headers = {};
563
+ new Headers(init.headers ?? {}).forEach((v, k) => {
564
+ headers[k] = v;
565
+ });
566
+ // The Host header is the URL's own: Node derives the TLS server name from it, so a caller's Host
567
+ // would move the certificate check off the name that was resolved and checked.
568
+ delete headers['host'];
569
+ headers['accept-encoding'] = 'gzip, deflate, br';
570
+ const body = bodyBytes(init.body);
571
+ if (body !== null)
572
+ headers['content-length'] = String(body.byteLength);
573
+ const method = (init.method ?? 'GET').toUpperCase();
574
+ if (method === 'CONNECT')
575
+ throw new DialRefusedError('url_refused', 'CONNECT is never sent');
576
+ const pinnedLookup = (hostname, options, cb) => {
577
+ if (hostname !== target.hostname) {
578
+ cb(new DialRefusedError('address_refused', `the connection asked to resolve ${hostname}, not the checked ${target.hostname}`));
579
+ return;
580
+ }
581
+ if (options?.all === true)
582
+ cb(null, target.addresses.map((a) => ({ address: a.address, family: a.family })));
583
+ else
584
+ cb(null, target.address, target.family);
585
+ };
586
+ const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
587
+ if (signal?.aborted === true)
588
+ throw abortError(signal);
589
+ const res = await new Promise((resolve, reject) => {
590
+ let settled = false;
591
+ const settle = (err, r) => {
592
+ if (settled)
593
+ return;
594
+ settled = true;
595
+ signal?.removeEventListener('abort', onAbort);
596
+ if (err !== null)
597
+ reject(err);
598
+ else
599
+ resolve(r);
600
+ };
601
+ const options = {
602
+ method,
603
+ headers,
604
+ agent: false,
605
+ lookup: pinnedLookup,
606
+ // Try every checked address in turn (Node's connect-multiple walks the whole list the lookup
607
+ // answers, interleaving families), whatever the process default says.
608
+ autoSelectFamily: true,
609
+ // An IP-literal host is never looked up: it is dialled as written, which is what was checked.
610
+ ...(url.protocol === 'https:' ? { minVersion: 'TLSv1.2', rejectUnauthorized: true, ...(opts.tls?.ca !== undefined ? { ca: opts.tls.ca } : {}) } : {}),
611
+ timeout: opts.connectTimeoutMs ?? CONNECT_TIMEOUT_MS,
612
+ };
613
+ const req = send(url, options);
614
+ function onAbort() {
615
+ const err = abortError(signal);
616
+ req.destroy(err);
617
+ settle(err);
618
+ }
619
+ signal?.addEventListener('abort', onAbort, { once: true });
620
+ req.once('timeout', () => req.destroy(new UpstreamCallError('timeout', false, `connecting to ${url.host} timed out`)));
621
+ req.once('error', (err) => settle(transportError(url.host, err)));
622
+ // A protocol switch is never followed: the socket is closed and the call refused, not left pending.
623
+ req.once('upgrade', (_r, socket) => {
624
+ socket.destroy();
625
+ settle(new UpstreamCallError('protocol', false, `${url.host} answered HTTP 101 (an upgrade); crew does not switch protocols`));
626
+ });
627
+ req.once('close', () => settle(new UpstreamCallError('transport', true, `the connection to ${url.host} closed before an answer`)));
628
+ req.once('response', (r) => {
629
+ req.setTimeout(0);
630
+ // The pinned lookup decided the address; this confirms the socket agrees.
631
+ if (!isCheckedAddress(target, r.socket?.remoteAddress)) {
632
+ r.destroy();
633
+ req.destroy();
634
+ settle(new DialRefusedError('address_refused', `the response for ${url.host} came from ${r.socket?.remoteAddress ?? 'nowhere'}, not a checked address`));
635
+ return;
636
+ }
637
+ settle(null, r);
638
+ });
639
+ req.end(body ?? undefined);
640
+ });
641
+ const status = res.statusCode ?? 0;
642
+ if (status >= 300 && status < 400) {
643
+ const location = typeof res.headers.location === 'string' ? res.headers.location : null;
644
+ res.destroy();
645
+ // The Location is the upstream's text (it can carry anything): kept on the error for a caller that
646
+ // shows a person, never in the message, which agents and health can see.
647
+ throw new DialRedirectRefusedError(status, location, `${url.host} answered HTTP ${status} (a redirect); redirects are never followed`);
648
+ }
649
+ if (status < 200 || status > 599) {
650
+ res.destroy();
651
+ throw new UpstreamCallError('protocol', false, `${url.host} answered an HTTP status crew does not accept (${status})`);
652
+ }
653
+ const out = new Headers();
654
+ for (const [k, v] of Object.entries(res.headers)) {
655
+ if (Array.isArray(v))
656
+ for (const x of v)
657
+ out.append(k, x);
658
+ else if (v !== undefined)
659
+ out.set(k, v);
660
+ }
661
+ if (NULL_BODY_STATUSES.has(status) || method === 'HEAD') {
662
+ // No body is read: the connection is closed now, never left open on a body that never ends.
663
+ res.destroy();
664
+ return new Response(null, { status, statusText: res.statusMessage ?? '', headers: out });
665
+ }
666
+ let stream;
667
+ // An abort while the decoders are being set up (a deflate answer's first byte may be slow to come)
668
+ // tears the wire down at once; the body's own abort handling takes over after.
669
+ const onEarlyAbort = () => {
670
+ res.destroy(abortError(signal));
671
+ };
672
+ signal?.addEventListener('abort', onEarlyAbort, { once: true });
673
+ try {
674
+ // An abort that landed between the answer and this point fired no listener (none was attached):
675
+ // it is seen here, before anything waits on the body.
676
+ if (signal !== undefined && isAborted(signal))
677
+ throw abortError(signal);
678
+ const d = await decoded(res);
679
+ if (signal !== undefined && isAborted(signal))
680
+ throw abortError(signal);
681
+ stream = d.stream;
682
+ if (d.encoded) {
683
+ // The body below is the decoded one; its encoding and length are not the wire's any more.
684
+ out.delete('content-encoding');
685
+ out.delete('content-length');
686
+ }
687
+ }
688
+ catch (err) {
689
+ res.destroy();
690
+ throw err;
691
+ }
692
+ finally {
693
+ signal?.removeEventListener('abort', onEarlyAbort);
694
+ }
695
+ return new Response(exposedBody(res, stream, signal), { status, statusText: res.statusMessage ?? '', headers: out });
696
+ }
697
+ /**
698
+ * The body a caller reads. It pulls from the decoded stream on demand (nothing is queued ahead of the
699
+ * reader), and an abort at any moment until the caller has read it all — even after the wire has
700
+ * finished — errors it and tears down the wire and the decoders, as fetch does.
701
+ */
702
+ function exposedBody(res, stream, signal) {
703
+ const reader = Readable.toWeb(stream).getReader();
704
+ let controller = null;
705
+ let finished = false;
706
+ const onAbort = () => {
707
+ if (finished)
708
+ return;
709
+ finished = true;
710
+ const err = abortError(signal);
711
+ res.destroy(err);
712
+ stream.destroy(err);
713
+ controller?.error(err);
714
+ void reader.cancel(err).catch(() => undefined);
715
+ };
716
+ const finish = () => {
717
+ finished = true;
718
+ signal?.removeEventListener('abort', onAbort);
719
+ };
720
+ return new ReadableStream({
721
+ start(c) {
722
+ controller = c;
723
+ if (signal === undefined)
724
+ return;
725
+ if (signal.aborted)
726
+ onAbort();
727
+ else
728
+ signal.addEventListener('abort', onAbort, { once: true });
729
+ },
730
+ async pull(c) {
731
+ try {
732
+ const { done, value } = await reader.read();
733
+ if (finished)
734
+ return;
735
+ if (done) {
736
+ finish();
737
+ c.close();
738
+ }
739
+ else
740
+ c.enqueue(value);
741
+ }
742
+ catch (err) {
743
+ if (finished)
744
+ return;
745
+ finish();
746
+ c.error(err);
747
+ }
748
+ },
749
+ cancel(reason) {
750
+ finish();
751
+ res.destroy();
752
+ stream.destroy();
753
+ return reader.cancel(reason).catch(() => undefined);
754
+ },
755
+ }, { highWaterMark: 0 });
756
+ }
757
+ /** A `fetch`-shaped function bound to one source's policy: for the MCP SDK's transport, and callers. */
758
+ export function boundFetch(policy, opts = {}) {
759
+ return (input, init) => dialFetch(input, init ?? {}, policy, opts);
760
+ }
761
+ //# sourceMappingURL=dialer.js.map