@humain/terminal 0.0.2 → 0.0.3-beta.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 (680) hide show
  1. package/CHANGELOG.md +241 -24
  2. package/README.md +143 -119
  3. package/dist/cli/args.d.ts +4 -2
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +37 -39
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/auth-check.d.ts +19 -0
  8. package/dist/cli/auth-check.d.ts.map +1 -0
  9. package/dist/cli/auth-check.js +50 -0
  10. package/dist/cli/auth-check.js.map +1 -0
  11. package/dist/cli/auth-command.d.ts +24 -0
  12. package/dist/cli/auth-command.d.ts.map +1 -0
  13. package/dist/cli/auth-command.js +103 -0
  14. package/dist/cli/auth-command.js.map +1 -0
  15. package/dist/cli/config-selector.d.ts.map +1 -1
  16. package/dist/cli/config-selector.js +2 -2
  17. package/dist/cli/config-selector.js.map +1 -1
  18. package/dist/cli/credential-print.d.ts +5 -15
  19. package/dist/cli/credential-print.d.ts.map +1 -1
  20. package/dist/cli/credential-print.js +42 -83
  21. package/dist/cli/credential-print.js.map +1 -1
  22. package/dist/cli/experimental/auth.d.ts +16 -0
  23. package/dist/cli/experimental/auth.d.ts.map +1 -0
  24. package/dist/cli/experimental/auth.js +13 -0
  25. package/dist/cli/experimental/auth.js.map +1 -0
  26. package/dist/cli/experimental/cli.d.ts +6 -0
  27. package/dist/cli/experimental/cli.d.ts.map +1 -0
  28. package/dist/cli/experimental/cli.js +5 -0
  29. package/dist/cli/experimental/cli.js.map +1 -0
  30. package/dist/cli/experimental/command-options.d.ts +17 -0
  31. package/dist/cli/experimental/command-options.d.ts.map +1 -0
  32. package/dist/cli/experimental/command-options.js +35 -0
  33. package/dist/cli/experimental/command-options.js.map +1 -0
  34. package/dist/cli/experimental/command.d.ts +63 -0
  35. package/dist/cli/experimental/command.d.ts.map +1 -0
  36. package/dist/cli/experimental/command.js +130 -0
  37. package/dist/cli/experimental/command.js.map +1 -0
  38. package/dist/cli/experimental/commands/client.d.ts +13 -0
  39. package/dist/cli/experimental/commands/client.d.ts.map +1 -0
  40. package/dist/cli/experimental/commands/client.js +25 -0
  41. package/dist/cli/experimental/commands/client.js.map +1 -0
  42. package/dist/cli/experimental/commands/pi.d.ts +15 -0
  43. package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
  44. package/dist/cli/experimental/commands/pi.js +28 -0
  45. package/dist/cli/experimental/commands/pi.js.map +1 -0
  46. package/dist/cli/experimental/commands/server.d.ts +13 -0
  47. package/dist/cli/experimental/commands/server.d.ts.map +1 -0
  48. package/dist/cli/experimental/commands/server.js +25 -0
  49. package/dist/cli/experimental/commands/server.js.map +1 -0
  50. package/dist/cli/experimental/transport-address.d.ts +10 -0
  51. package/dist/cli/experimental/transport-address.d.ts.map +1 -0
  52. package/dist/cli/experimental/transport-address.js +38 -0
  53. package/dist/cli/experimental/transport-address.js.map +1 -0
  54. package/dist/cli/list-models.d.ts +1 -1
  55. package/dist/cli/list-models.d.ts.map +1 -1
  56. package/dist/cli/list-models.js +2 -2
  57. package/dist/cli/list-models.js.map +1 -1
  58. package/dist/cli/startup-ui.d.ts +1 -1
  59. package/dist/cli/startup-ui.d.ts.map +1 -1
  60. package/dist/cli/startup-ui.js +2 -2
  61. package/dist/cli/startup-ui.js.map +1 -1
  62. package/dist/client/index.d.ts +3 -0
  63. package/dist/client/index.d.ts.map +1 -0
  64. package/dist/client/index.js +3 -0
  65. package/dist/client/index.js.map +1 -0
  66. package/dist/client/remote-session.d.ts +53 -0
  67. package/dist/client/remote-session.d.ts.map +1 -0
  68. package/dist/client/remote-session.js +340 -0
  69. package/dist/client/remote-session.js.map +1 -0
  70. package/dist/client/transcript.d.ts +12 -0
  71. package/dist/client/transcript.d.ts.map +1 -0
  72. package/dist/client/transcript.js +98 -0
  73. package/dist/client/transcript.js.map +1 -0
  74. package/dist/core/agent-session-services.d.ts +1 -0
  75. package/dist/core/agent-session-services.d.ts.map +1 -1
  76. package/dist/core/agent-session-services.js +1 -0
  77. package/dist/core/agent-session-services.js.map +1 -1
  78. package/dist/core/agent-session.d.ts +1 -10
  79. package/dist/core/agent-session.d.ts.map +1 -1
  80. package/dist/core/agent-session.js +72 -70
  81. package/dist/core/agent-session.js.map +1 -1
  82. package/dist/core/auth-storage.d.ts +25 -9
  83. package/dist/core/auth-storage.d.ts.map +1 -1
  84. package/dist/core/auth-storage.js +237 -39
  85. package/dist/core/auth-storage.js.map +1 -1
  86. package/dist/core/extensions/index.d.ts +1 -1
  87. package/dist/core/extensions/index.d.ts.map +1 -1
  88. package/dist/core/extensions/index.js.map +1 -1
  89. package/dist/core/extensions/loader.d.ts.map +1 -1
  90. package/dist/core/extensions/loader.js +60 -41
  91. package/dist/core/extensions/loader.js.map +1 -1
  92. package/dist/core/extensions/runner.d.ts +2 -1
  93. package/dist/core/extensions/runner.d.ts.map +1 -1
  94. package/dist/core/extensions/runner.js +3 -0
  95. package/dist/core/extensions/runner.js.map +1 -1
  96. package/dist/core/extensions/types.d.ts +27 -4
  97. package/dist/core/extensions/types.d.ts.map +1 -1
  98. package/dist/core/extensions/types.js.map +1 -1
  99. package/dist/core/http-dispatcher.d.ts.map +1 -1
  100. package/dist/core/http-dispatcher.js +5 -0
  101. package/dist/core/http-dispatcher.js.map +1 -1
  102. package/dist/core/keybindings.d.ts +45 -5
  103. package/dist/core/keybindings.d.ts.map +1 -1
  104. package/dist/core/keybindings.js.map +1 -1
  105. package/dist/core/model-config.d.ts +29 -5
  106. package/dist/core/model-config.d.ts.map +1 -1
  107. package/dist/core/model-config.js +4 -0
  108. package/dist/core/model-config.js.map +1 -1
  109. package/dist/core/model-registry.d.ts +5 -3
  110. package/dist/core/model-registry.d.ts.map +1 -1
  111. package/dist/core/model-registry.js +13 -10
  112. package/dist/core/model-registry.js.map +1 -1
  113. package/dist/core/model-resolver.d.ts +4 -3
  114. package/dist/core/model-resolver.d.ts.map +1 -1
  115. package/dist/core/model-resolver.js +42 -10
  116. package/dist/core/model-resolver.js.map +1 -1
  117. package/dist/core/model-runtime.d.ts +30 -13
  118. package/dist/core/model-runtime.d.ts.map +1 -1
  119. package/dist/core/model-runtime.js +233 -73
  120. package/dist/core/model-runtime.js.map +1 -1
  121. package/dist/core/models-store.d.ts +12 -7
  122. package/dist/core/models-store.d.ts.map +1 -1
  123. package/dist/core/models-store.js +83 -14
  124. package/dist/core/models-store.js.map +1 -1
  125. package/dist/core/package-manager.d.ts +6 -3
  126. package/dist/core/package-manager.d.ts.map +1 -1
  127. package/dist/core/package-manager.js +80 -61
  128. package/dist/core/package-manager.js.map +1 -1
  129. package/dist/core/pi-manifest.d.ts +8 -0
  130. package/dist/core/pi-manifest.d.ts.map +1 -0
  131. package/dist/core/pi-manifest.js +28 -0
  132. package/dist/core/pi-manifest.js.map +1 -0
  133. package/dist/core/provider-composer.d.ts +4 -1
  134. package/dist/core/provider-composer.d.ts.map +1 -1
  135. package/dist/core/provider-composer.js +36 -15
  136. package/dist/core/provider-composer.js.map +1 -1
  137. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  138. package/dist/core/remote-catalog-provider.js +73 -67
  139. package/dist/core/remote-catalog-provider.js.map +1 -1
  140. package/dist/core/resource-loader.d.ts.map +1 -1
  141. package/dist/core/resource-loader.js +2 -2
  142. package/dist/core/resource-loader.js.map +1 -1
  143. package/dist/core/runtime-credentials.d.ts +5 -5
  144. package/dist/core/runtime-credentials.d.ts.map +1 -1
  145. package/dist/core/runtime-credentials.js +11 -8
  146. package/dist/core/runtime-credentials.js.map +1 -1
  147. package/dist/core/sdk.d.ts +1 -1
  148. package/dist/core/sdk.d.ts.map +1 -1
  149. package/dist/core/sdk.js +2 -2
  150. package/dist/core/sdk.js.map +1 -1
  151. package/dist/core/session-manager.d.ts.map +1 -1
  152. package/dist/core/session-manager.js +3 -1
  153. package/dist/core/session-manager.js.map +1 -1
  154. package/dist/core/settings-manager.d.ts +12 -0
  155. package/dist/core/settings-manager.d.ts.map +1 -1
  156. package/dist/core/settings-manager.js +40 -16
  157. package/dist/core/settings-manager.js.map +1 -1
  158. package/dist/core/system-prompt.d.ts.map +1 -1
  159. package/dist/core/system-prompt.js +8 -0
  160. package/dist/core/system-prompt.js.map +1 -1
  161. package/dist/core/tools/bash.d.ts +5 -1
  162. package/dist/core/tools/bash.d.ts.map +1 -1
  163. package/dist/core/tools/bash.js +16 -15
  164. package/dist/core/tools/bash.js.map +1 -1
  165. package/dist/core/tools/edit.d.ts +4 -0
  166. package/dist/core/tools/edit.d.ts.map +1 -1
  167. package/dist/core/tools/edit.js +11 -7
  168. package/dist/core/tools/edit.js.map +1 -1
  169. package/dist/core/tools/find.d.ts +7 -0
  170. package/dist/core/tools/find.d.ts.map +1 -1
  171. package/dist/core/tools/find.js +16 -19
  172. package/dist/core/tools/find.js.map +1 -1
  173. package/dist/core/tools/grep.d.ts +4 -0
  174. package/dist/core/tools/grep.d.ts.map +1 -1
  175. package/dist/core/tools/grep.js +5 -1
  176. package/dist/core/tools/grep.js.map +1 -1
  177. package/dist/core/tools/ls.d.ts +4 -0
  178. package/dist/core/tools/ls.d.ts.map +1 -1
  179. package/dist/core/tools/ls.js +5 -1
  180. package/dist/core/tools/ls.js.map +1 -1
  181. package/dist/core/tools/read.d.ts +4 -0
  182. package/dist/core/tools/read.d.ts.map +1 -1
  183. package/dist/core/tools/read.js +7 -3
  184. package/dist/core/tools/read.js.map +1 -1
  185. package/dist/core/tools/write.d.ts +4 -0
  186. package/dist/core/tools/write.d.ts.map +1 -1
  187. package/dist/core/tools/write.js +6 -2
  188. package/dist/core/tools/write.js.map +1 -1
  189. package/dist/extensions/llama/index.d.ts.map +1 -1
  190. package/dist/extensions/llama/index.js +11 -2
  191. package/dist/extensions/llama/index.js.map +1 -1
  192. package/dist/extensions/llama/provider.d.ts.map +1 -1
  193. package/dist/extensions/llama/provider.js +21 -7
  194. package/dist/extensions/llama/provider.js.map +1 -1
  195. package/dist/humain/agent-execution-protocol.d.ts +218 -0
  196. package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
  197. package/dist/humain/agent-execution-protocol.js +204 -0
  198. package/dist/humain/agent-execution-protocol.js.map +1 -0
  199. package/dist/humain/agent-execution-runtime.d.ts +35 -0
  200. package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
  201. package/dist/humain/agent-execution-runtime.js +170 -0
  202. package/dist/humain/agent-execution-runtime.js.map +1 -0
  203. package/dist/humain/index.d.ts.map +1 -1
  204. package/dist/humain/index.js +8 -7
  205. package/dist/humain/index.js.map +1 -1
  206. package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +660 -0
  207. package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
  208. package/dist/humain/mcp-adapter/vendor/README.md +733 -0
  209. package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
  210. package/dist/humain/mcp-adapter/vendor/agent-dir.ts +60 -0
  211. package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
  212. package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
  213. package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
  214. package/dist/humain/mcp-adapter/vendor/cli.js +209 -0
  215. package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
  216. package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
  217. package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
  218. package/dist/humain/mcp-adapter/vendor/direct-tools.ts +604 -0
  219. package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
  220. package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
  221. package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
  222. package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
  223. package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
  224. package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
  225. package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +15923 -0
  226. package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
  227. package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
  228. package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
  229. package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
  230. package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
  231. package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
  232. package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
  233. package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
  234. package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
  235. package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
  236. package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
  237. package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
  238. package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
  239. package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
  240. package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
  241. package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +666 -0
  242. package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
  243. package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
  244. package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +353 -0
  245. package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
  246. package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
  247. package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
  248. package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
  249. package/dist/humain/mcp-adapter/vendor/package.json +178 -0
  250. package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
  251. package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
  252. package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
  253. package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
  254. package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
  255. package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
  256. package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
  257. package/dist/humain/mcp-adapter/vendor/server-manager.ts +1124 -0
  258. package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
  259. package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
  260. package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
  261. package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
  262. package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +276 -0
  263. package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
  264. package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
  265. package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
  266. package/dist/humain/mcp-adapter/vendor/types.ts +859 -0
  267. package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
  268. package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
  269. package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
  270. package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
  271. package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
  272. package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
  273. package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
  274. package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
  275. package/dist/humain/mcp-adapter.d.ts +3 -0
  276. package/dist/humain/mcp-adapter.d.ts.map +1 -0
  277. package/dist/humain/mcp-adapter.js +5 -0
  278. package/dist/humain/mcp-adapter.js.map +1 -0
  279. package/dist/humain/pi-agent-execution-host.d.ts +34 -0
  280. package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
  281. package/dist/humain/pi-agent-execution-host.js +77 -0
  282. package/dist/humain/pi-agent-execution-host.js.map +1 -0
  283. package/dist/humain/web-access/host.d.ts +4 -0
  284. package/dist/humain/web-access/host.d.ts.map +1 -0
  285. package/dist/humain/web-access/host.js +3 -0
  286. package/dist/humain/web-access/host.js.map +1 -0
  287. package/dist/humain/web-access/index.d.ts +3 -0
  288. package/dist/humain/web-access/index.d.ts.map +1 -0
  289. package/dist/humain/web-access/index.js +5 -0
  290. package/dist/humain/web-access/index.js.map +1 -0
  291. package/dist/humain/web-access/vendor/activity.d.ts +34 -0
  292. package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
  293. package/dist/humain/web-access/vendor/activity.js +68 -0
  294. package/dist/humain/web-access/vendor/activity.js.map +1 -0
  295. package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
  296. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
  297. package/dist/humain/web-access/vendor/anysearch.js +167 -0
  298. package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
  299. package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
  300. package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
  301. package/dist/humain/web-access/vendor/bocha.js +219 -0
  302. package/dist/humain/web-access/vendor/bocha.js.map +1 -0
  303. package/dist/humain/web-access/vendor/brave.d.ts +4 -0
  304. package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
  305. package/dist/humain/web-access/vendor/brave.js +194 -0
  306. package/dist/humain/web-access/vendor/brave.js.map +1 -0
  307. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
  308. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
  309. package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
  310. package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
  311. package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
  312. package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
  313. package/dist/humain/web-access/vendor/brightdata.js +519 -0
  314. package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
  315. package/dist/humain/web-access/vendor/chrome-cookies.d.ts +10 -0
  316. package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
  317. package/dist/humain/web-access/vendor/chrome-cookies.js +438 -0
  318. package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
  319. package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
  320. package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
  321. package/dist/humain/web-access/vendor/content-find.js +117 -0
  322. package/dist/humain/web-access/vendor/content-find.js.map +1 -0
  323. package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
  324. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
  325. package/dist/humain/web-access/vendor/credential-source.js +151 -0
  326. package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
  327. package/dist/humain/web-access/vendor/curator-page.d.ts +29 -0
  328. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
  329. package/dist/humain/web-access/vendor/curator-page.js +3554 -0
  330. package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
  331. package/dist/humain/web-access/vendor/curator-server.d.ts +93 -0
  332. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
  333. package/dist/humain/web-access/vendor/curator-server.js +688 -0
  334. package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
  335. package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
  336. package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
  337. package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
  338. package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
  339. package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
  340. package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
  341. package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
  342. package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
  343. package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
  344. package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
  345. package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
  346. package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
  347. package/dist/humain/web-access/vendor/exa.d.ts +10 -0
  348. package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
  349. package/dist/humain/web-access/vendor/exa.js +426 -0
  350. package/dist/humain/web-access/vendor/exa.js.map +1 -0
  351. package/dist/humain/web-access/vendor/extract.d.ts +46 -0
  352. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
  353. package/dist/humain/web-access/vendor/extract.js +1064 -0
  354. package/dist/humain/web-access/vendor/extract.js.map +1 -0
  355. package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
  356. package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
  357. package/dist/humain/web-access/vendor/feature-config.js +27 -0
  358. package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
  359. package/dist/humain/web-access/vendor/fetch-params.d.ts +25 -0
  360. package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
  361. package/dist/humain/web-access/vendor/fetch-params.js +57 -0
  362. package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
  363. package/dist/humain/web-access/vendor/firecrawl.d.ts +12 -0
  364. package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
  365. package/dist/humain/web-access/vendor/firecrawl.js +239 -0
  366. package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
  367. package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
  368. package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
  369. package/dist/humain/web-access/vendor/gemini-api.js +230 -0
  370. package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
  371. package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
  372. package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
  373. package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
  374. package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
  375. package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
  376. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
  377. package/dist/humain/web-access/vendor/gemini-search.js +814 -0
  378. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
  379. package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
  380. package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
  381. package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
  382. package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
  383. package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
  384. package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
  385. package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
  386. package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
  387. package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
  388. package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
  389. package/dist/humain/web-access/vendor/gemini-web.js +385 -0
  390. package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
  391. package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
  392. package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
  393. package/dist/humain/web-access/vendor/github-api.js +160 -0
  394. package/dist/humain/web-access/vendor/github-api.js.map +1 -0
  395. package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
  396. package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
  397. package/dist/humain/web-access/vendor/github-extract.js +635 -0
  398. package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
  399. package/dist/humain/web-access/vendor/index.d.ts +4 -0
  400. package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
  401. package/dist/humain/web-access/vendor/index.js +3002 -0
  402. package/dist/humain/web-access/vendor/index.js.map +1 -0
  403. package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
  404. package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
  405. package/dist/humain/web-access/vendor/jina-search.js +255 -0
  406. package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
  407. package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
  408. package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
  409. package/dist/humain/web-access/vendor/kagi.js +262 -0
  410. package/dist/humain/web-access/vendor/kagi.js.map +1 -0
  411. package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
  412. package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
  413. package/dist/humain/web-access/vendor/ollama.js +216 -0
  414. package/dist/humain/web-access/vendor/ollama.js.map +1 -0
  415. package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
  416. package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
  417. package/dist/humain/web-access/vendor/openai-search.js +459 -0
  418. package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
  419. package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
  420. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
  421. package/dist/humain/web-access/vendor/page-query.js +79 -0
  422. package/dist/humain/web-access/vendor/page-query.js.map +1 -0
  423. package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
  424. package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
  425. package/dist/humain/web-access/vendor/parallel.js +343 -0
  426. package/dist/humain/web-access/vendor/parallel.js.map +1 -0
  427. package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
  428. package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
  429. package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
  430. package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
  431. package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
  432. package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
  433. package/dist/humain/web-access/vendor/perplexity.js +159 -0
  434. package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
  435. package/dist/humain/web-access/vendor/querit.d.ts +10 -0
  436. package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
  437. package/dist/humain/web-access/vendor/querit.js +335 -0
  438. package/dist/humain/web-access/vendor/querit.js.map +1 -0
  439. package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
  440. package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
  441. package/dist/humain/web-access/vendor/render-search-error.js +130 -0
  442. package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
  443. package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
  444. package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
  445. package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
  446. package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
  447. package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
  448. package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
  449. package/dist/humain/web-access/vendor/search1api.js +251 -0
  450. package/dist/humain/web-access/vendor/search1api.js.map +1 -0
  451. package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
  452. package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
  453. package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
  454. package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
  455. package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
  456. package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
  457. package/dist/humain/web-access/vendor/searxng.js +238 -0
  458. package/dist/humain/web-access/vendor/searxng.js.map +1 -0
  459. package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
  460. package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
  461. package/dist/humain/web-access/vendor/serpbase.js +211 -0
  462. package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
  463. package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
  464. package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
  465. package/dist/humain/web-access/vendor/serpdive.js +267 -0
  466. package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
  467. package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
  468. package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
  469. package/dist/humain/web-access/vendor/source-check.js +205 -0
  470. package/dist/humain/web-access/vendor/source-check.js.map +1 -0
  471. package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
  472. package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
  473. package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
  474. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
  475. package/dist/humain/web-access/vendor/storage.d.ts +55 -0
  476. package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
  477. package/dist/humain/web-access/vendor/storage.js +485 -0
  478. package/dist/humain/web-access/vendor/storage.js.map +1 -0
  479. package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
  480. package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
  481. package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
  482. package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
  483. package/dist/humain/web-access/vendor/summary-review.d.ts +24 -0
  484. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
  485. package/dist/humain/web-access/vendor/summary-review.js +341 -0
  486. package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
  487. package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
  488. package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
  489. package/dist/humain/web-access/vendor/tavily.js +194 -0
  490. package/dist/humain/web-access/vendor/tavily.js.map +1 -0
  491. package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
  492. package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
  493. package/dist/humain/web-access/vendor/tinyfish.js +331 -0
  494. package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
  495. package/dist/humain/web-access/vendor/utils.d.ts +20 -0
  496. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
  497. package/dist/humain/web-access/vendor/utils.js +91 -0
  498. package/dist/humain/web-access/vendor/utils.js.map +1 -0
  499. package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
  500. package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
  501. package/dist/humain/web-access/vendor/video-extract.js +335 -0
  502. package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
  503. package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
  504. package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
  505. package/dist/humain/web-access/vendor/xai-search.js +331 -0
  506. package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
  507. package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
  508. package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
  509. package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
  510. package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
  511. package/dist/index.d.ts +7 -4
  512. package/dist/index.d.ts.map +1 -1
  513. package/dist/index.js +5 -2
  514. package/dist/index.js.map +1 -1
  515. package/dist/main.d.ts +2 -2
  516. package/dist/main.d.ts.map +1 -1
  517. package/dist/main.js +169 -102
  518. package/dist/main.js.map +1 -1
  519. package/dist/modes/agent-exec-mode.d.ts +14 -0
  520. package/dist/modes/agent-exec-mode.d.ts.map +1 -0
  521. package/dist/modes/agent-exec-mode.js +92 -0
  522. package/dist/modes/agent-exec-mode.js.map +1 -0
  523. package/dist/modes/index.d.ts +4 -2
  524. package/dist/modes/index.d.ts.map +1 -1
  525. package/dist/modes/index.js +2 -1
  526. package/dist/modes/index.js.map +1 -1
  527. package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
  528. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  529. package/dist/modes/interactive/components/assistant-message.js +13 -4
  530. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  531. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  532. package/dist/modes/interactive/components/custom-editor.js +7 -0
  533. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  534. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  535. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  536. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  537. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  538. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  539. package/dist/modes/interactive/components/footer.js +1 -1
  540. package/dist/modes/interactive/components/footer.js.map +1 -1
  541. package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
  542. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  543. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  544. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  545. package/dist/modes/interactive/components/mermaid.d.ts +11 -0
  546. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  547. package/dist/modes/interactive/components/mermaid.js +75 -0
  548. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  549. package/dist/modes/interactive/components/model-selector.d.ts +1 -1
  550. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  551. package/dist/modes/interactive/components/model-selector.js +16 -4
  552. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  553. package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
  554. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  555. package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
  556. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  557. package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
  558. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  559. package/dist/modes/interactive/components/settings-selector.js +30 -0
  560. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  561. package/dist/modes/interactive/components/user-message.d.ts +3 -1
  562. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  563. package/dist/modes/interactive/components/user-message.js +9 -2
  564. package/dist/modes/interactive/components/user-message.js.map +1 -1
  565. package/dist/modes/interactive/interactive-mode.d.ts +45 -9
  566. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  567. package/dist/modes/interactive/interactive-mode.js +581 -211
  568. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  569. package/dist/modes/interactive/theme/dark.json +1 -0
  570. package/dist/modes/interactive/theme/light.json +1 -0
  571. package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
  572. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  573. package/dist/modes/interactive/theme/theme-controller.js +10 -1
  574. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  575. package/dist/modes/interactive/theme/theme-schema.json +5 -1
  576. package/dist/modes/interactive/theme/theme.d.ts +2 -2
  577. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  578. package/dist/modes/interactive/theme/theme.js +24 -6
  579. package/dist/modes/interactive/theme/theme.js.map +1 -1
  580. package/dist/modes/json-event.d.ts +28 -0
  581. package/dist/modes/json-event.d.ts.map +1 -0
  582. package/dist/modes/json-event.js +12 -0
  583. package/dist/modes/json-event.js.map +1 -0
  584. package/dist/modes/print-mode.d.ts.map +1 -1
  585. package/dist/modes/print-mode.js +12 -2
  586. package/dist/modes/print-mode.js.map +1 -1
  587. package/dist/modes/rpc/rpc-client.d.ts +12 -5
  588. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  589. package/dist/modes/rpc/rpc-client.js +55 -1
  590. package/dist/modes/rpc/rpc-client.js.map +1 -1
  591. package/dist/modes/rpc/rpc-mode.d.ts +1 -1
  592. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  593. package/dist/modes/rpc/rpc-mode.js +13 -3
  594. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  595. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  596. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  597. package/dist/modes/rpc/rpc-types.js.map +1 -1
  598. package/dist/package-manager-cli.d.ts.map +1 -1
  599. package/dist/package-manager-cli.js +11 -9
  600. package/dist/package-manager-cli.js.map +1 -1
  601. package/dist/rpc-entry.d.ts.map +1 -1
  602. package/dist/rpc-entry.js +3 -2
  603. package/dist/rpc-entry.js.map +1 -1
  604. package/dist/server/create-harness.d.ts +26 -0
  605. package/dist/server/create-harness.d.ts.map +1 -0
  606. package/dist/server/create-harness.js +104 -0
  607. package/dist/server/create-harness.js.map +1 -0
  608. package/dist/utils/abort.d.ts +5 -0
  609. package/dist/utils/abort.d.ts.map +1 -0
  610. package/dist/utils/abort.js +48 -0
  611. package/dist/utils/abort.js.map +1 -0
  612. package/dist/utils/clipboard.d.ts +1 -1
  613. package/dist/utils/clipboard.d.ts.map +1 -1
  614. package/dist/utils/clipboard.js +22 -2
  615. package/dist/utils/clipboard.js.map +1 -1
  616. package/dist/utils/management-http.d.ts +23 -0
  617. package/dist/utils/management-http.d.ts.map +1 -0
  618. package/dist/utils/management-http.js +50 -0
  619. package/dist/utils/management-http.js.map +1 -0
  620. package/dist/utils/paths.d.ts +3 -0
  621. package/dist/utils/paths.d.ts.map +1 -1
  622. package/dist/utils/paths.js +23 -1
  623. package/dist/utils/paths.js.map +1 -1
  624. package/dist/utils/tool-result-images.d.ts +19 -0
  625. package/dist/utils/tool-result-images.d.ts.map +1 -0
  626. package/dist/utils/tool-result-images.js +45 -0
  627. package/dist/utils/tool-result-images.js.map +1 -0
  628. package/dist/utils/tools-manager.d.ts.map +1 -1
  629. package/dist/utils/tools-manager.js +13 -25
  630. package/dist/utils/tools-manager.js.map +1 -1
  631. package/dist/utils/version-check.d.ts +4 -0
  632. package/dist/utils/version-check.d.ts.map +1 -1
  633. package/dist/utils/version-check.js +23 -5
  634. package/dist/utils/version-check.js.map +1 -1
  635. package/docs/compaction.md +2 -2
  636. package/docs/custom-provider.md +7 -5
  637. package/docs/extensions.md +30 -5
  638. package/docs/humain-terminal.md +21 -1
  639. package/docs/json.md +24 -19
  640. package/docs/keybindings.md +46 -14
  641. package/docs/models.md +32 -11
  642. package/docs/providers.md +9 -1
  643. package/docs/quickstart.md +39 -37
  644. package/docs/rpc.md +31 -11
  645. package/docs/sdk.md +21 -2
  646. package/docs/security.md +21 -21
  647. package/docs/session-format.md +14 -14
  648. package/docs/settings.md +4 -1
  649. package/docs/themes.md +5 -3
  650. package/docs/usage.md +7 -0
  651. package/examples/extensions/custom-compaction.ts +3 -18
  652. package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
  653. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  654. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  655. package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
  656. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  657. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  658. package/examples/extensions/gondolin/package-lock.json +2 -2
  659. package/examples/extensions/gondolin/package.json +1 -1
  660. package/examples/extensions/handoff.ts +4 -13
  661. package/examples/extensions/qna.ts +5 -9
  662. package/examples/extensions/sandbox/package-lock.json +2 -2
  663. package/examples/extensions/sandbox/package.json +1 -1
  664. package/examples/extensions/summarize.ts +9 -20
  665. package/examples/extensions/with-deps/package-lock.json +2 -2
  666. package/examples/extensions/with-deps/package.json +1 -1
  667. package/examples/rpc-extension-ui.ts +11 -2
  668. package/examples/sdk/02-custom-model.ts +2 -3
  669. package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
  670. package/examples/sdk/12-full-control.ts +1 -1
  671. package/examples/sdk/README.md +1 -1
  672. package/npm-shrinkwrap.json +2771 -535
  673. package/package.json +40 -11
  674. package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
  675. package/src/humain/mcp-adapter/upstream.json +7 -0
  676. package/src/humain/mcp-adapter/vendor/CHANGELOG.md +660 -0
  677. package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
  678. package/src/humain/web-access/UPSTREAM.md +17 -0
  679. package/src/humain/web-access/upstream.json +23 -0
  680. package/src/humain/web-access/vendor/LICENSE +21 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-check.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/source-check.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA+DlE,MAAM,mBAAmB,GAAG,2DAA2D,CAAC;AACxF,MAAM,mBAAmB,GAAG,6BAA6B,CAAC;AAC1D,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AACvD,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AACpD,MAAM,UAAU,GAAG,iDAAiD,CAAC;AACrE,MAAM,UAAU,GAAG,aAAa,CAAC;AACjC,MAAM,WAAW,GAAG,+EAA+E,CAAC;AACpG,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAClD,MAAM,UAAU,GAAG,+GAA+G,CAAC;AACnI,MAAM,UAAU,GAAG,eAAe,CAAC;AAEnC,MAAM,UAAU,cAAc,CAAC,GAAW,EAAiB;IAC1D,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC;QACvB,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC;IACrD,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,IAAI,CAA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EAAE,aAAa;SAC7B;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,mBAAmB,CAAC,QAA0B,EAAE,MAAgB,EAAoB;IACnG,OAAO,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;AAAA,CAC7F;AAED,MAAM,UAAU,qBAAqB,CAAC,QAA0B,EAAQ;IACvE,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5E,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;AAAA,CACzG;AAED,MAAM,UAAU,mBAAmB,CAAC,EAAU,EAA2B;IACxE,MAAM,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;IAC3B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1G,OAAO,IAAI,CAAC,QAA4B,CAAC;AAAA,CACzC","sourcesContent":["// Structured source checking and machine-readable research artifacts.\nimport { createHash } from \"node:crypto\";\nimport { generateId, getResult, storeResult } from \"./storage.ts\";\nimport type { SearchResult } from \"./perplexity.ts\";\nimport type { ExtractedContent } from \"./extract.ts\";\n\nexport type SourceQuality = \"official_docs\" | \"vendor_docs\" | \"repo_issue\" | \"blog\" | \"forum\" | \"news\" | \"unknown\";\nexport type ClaimStatus = \"supported\" | \"contradicted\" | \"unclear\" | \"missing-evidence\";\nexport type RecencyFilter = \"day\" | \"week\" | \"month\" | \"year\";\n\nexport interface ResearchSource {\n\trank: number;\n\turl: string;\n\ttitle: string;\n\tsnippet?: string;\n\tfetch_timestamp?: number;\n\tcontent_hash?: string;\n\tquality: SourceQuality;\n\tfetched?: boolean;\n\tfetch_error?: string;\n}\n\nexport interface ResearchPassage {\n\tpassage_id: string;\n\tsource_url: string;\n\tsource_rank: number;\n\ttext: string;\n\textraction_span?: { start: number; end: number };\n\tcontent_hash?: string;\n}\n\nexport interface ClaimAssessment {\n\tclaim: string;\n\tstatus: ClaimStatus;\n\tsupporting_passages: string[];\n\tcontradicting_passages: string[];\n\trationale: string;\n\tconfidence: number;\n}\n\nexport interface ResearchArtifact {\n\tid: string;\n\ttype: \"research\";\n\ttimestamp: number;\n\tquery: string;\n\tsources: ResearchSource[];\n\tpassages: ResearchPassage[];\n\tclaims?: ClaimAssessment[];\n\tprovider?: string;\n\tsummary?: string;\n\tcontent_hash?: string;\n\tfilters?: { recency?: RecencyFilter; domain_include?: string[]; domain_exclude?: string[] };\n\terrors?: Array<{ query: string; error: string }>;\n}\n\nexport interface ResearchSearchRequest {\n\tquery: string;\n\tnumResults: number;\n\trecencyFilter?: RecencyFilter;\n\tdomainFilter?: string[];\n}\nexport interface ResearchSearchResult { url: string; title: string; snippet: string; rank: number }\nexport interface ResearchSearchResponse { provider: string; results: ResearchSearchResult[]; summary?: string }\nexport interface ResearchProvider { name: string; search(req: ResearchSearchRequest): Promise<ResearchSearchResponse> }\n\nconst OFFICIAL_DOCS_HOSTS = /^(developers\\.|docs\\.|learn\\.|reference\\.)|\\.github\\.io$/i;\nconst OFFICIAL_DOCS_PATHS = /\\/(docs?|reference)(\\/|\\b)/i;\nconst VENDOR_DOCS_PATHS = /\\/(documentation|docs?)\\//i;\nconst REPO_ISSUE_PATHS = /\\/(issues|pull|pulls)\\//i;\nconst BLOG_HOSTS = /(medium\\.com|substack\\.com|dev\\.to|hashnode\\.)/i;\nconst BLOG_PATHS = /\\/blogs?\\//i;\nconst FORUM_HOSTS = /(stackoverflow\\.com|serverfault\\.com|superuser\\.com|discourse\\.|community\\.)/i;\nconst FORUM_PATHS = /\\/(forum|forums|threads)\\//i;\nconst NEWS_HOSTS = /(reuters\\.com|bloomberg\\.com|techcrunch\\.com|theverge\\.com|arstechnica\\.com|wired\\.com|cnet\\.com|zdnet\\.com)/i;\nconst NEWS_PATHS = /\\/news(\\/|$)/i;\n\nexport function classifySource(url: string): SourceQuality {\n\tlet host = \"\";\n\tlet path = \"\";\n\ttry {\n\t\tconst parsed = new URL(url);\n\t\thost = parsed.hostname;\n\t\tpath = parsed.pathname;\n\t} catch {\n\t\treturn \"unknown\";\n\t}\n\tif (REPO_ISSUE_PATHS.test(path)) return \"repo_issue\";\n\tif (OFFICIAL_DOCS_HOSTS.test(host) || OFFICIAL_DOCS_PATHS.test(path)) return \"official_docs\";\n\tif (VENDOR_DOCS_PATHS.test(path)) return \"vendor_docs\";\n\tif (NEWS_HOSTS.test(host) || NEWS_PATHS.test(path)) return \"news\";\n\tif (FORUM_HOSTS.test(host) || FORUM_PATHS.test(path)) return \"forum\";\n\tif (BLOG_HOSTS.test(host) || BLOG_PATHS.test(path)) return \"blog\";\n\treturn \"unknown\";\n}\n\nexport function hashContent(text: string): string {\n\treturn `sha256:${createHash(\"sha256\").update(text, \"utf8\").digest(\"hex\")}`;\n}\n\ninterface Span { text: string; start: number; end: number }\n\nfunction tokenize(value: string): string[] {\n\treturn [...new Set(value.toLowerCase().split(/[^a-z0-9]+/).filter((term) => term.length > 3))];\n}\n\nfunction extractRelevantSpans(content: string, hint: string): Span[] {\n\tconst sentences: Span[] = [];\n\tconst sentencePattern = /[^.!?]+(?:[.!?]+(?=\\s|$)|$)/g;\n\tfor (const match of content.matchAll(sentencePattern)) {\n\t\tconst raw = match[0];\n\t\tconst text = raw.trim();\n\t\tif (text.length > 0 && text.length <= 400) {\n\t\t\tconst start = (match.index ?? 0) + raw.indexOf(text);\n\t\t\tsentences.push({ text, start, end: start + text.length });\n\t\t}\n\t}\n\tconst terms = tokenize(hint);\n\tif (terms.length === 0) return [];\n\treturn sentences\n\t\t.map((sentence, index) => ({ sentence, index, score: terms.filter((term) => sentence.text.toLowerCase().includes(term)).length }))\n\t\t.filter((item) => item.score > 0)\n\t\t.sort((a, b) => b.score - a.score || a.index - b.index)\n\t\t.slice(0, 3)\n\t\t.map(({ sentence }) => sentence);\n}\n\nfunction passageId(sourceRank: number, index: number): string {\n\treturn `p-${sourceRank}-${index}`;\n}\n\nexport function buildPassages(sources: ResearchSource[], fetched: ExtractedContent[] = [], hint = \"\"): ResearchPassage[] {\n\tconst passages: ResearchPassage[] = [];\n\tconst fetchedByUrl = new Map(fetched.map((item) => [item.url, item]));\n\tfor (const source of sources) {\n\t\tif (source.snippet) {\n\t\t\tpassages.push({\n\t\t\t\tpassage_id: passageId(source.rank, 0),\n\t\t\t\tsource_url: source.url,\n\t\t\t\tsource_rank: source.rank,\n\t\t\t\ttext: source.snippet,\n\t\t\t\tcontent_hash: hashContent(source.snippet),\n\t\t\t});\n\t\t}\n\t\tconst page = fetchedByUrl.get(source.url);\n\t\tif (page && !page.error && page.content) {\n\t\t\tconst passageHint = source.snippet?.trim() || hint;\n\t\t\tfor (const [index, span] of extractRelevantSpans(page.content, passageHint).entries()) {\n\t\t\t\tpassages.push({\n\t\t\t\t\tpassage_id: passageId(source.rank, index + 1),\n\t\t\t\t\tsource_url: source.url,\n\t\t\t\t\tsource_rank: source.rank,\n\t\t\t\t\ttext: span.text,\n\t\t\t\t\textraction_span: { start: span.start, end: span.end },\n\t\t\t\t\tcontent_hash: hashContent(span.text),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\treturn passages;\n}\n\nconst CONTRADICTION_MARKERS = [\"not true\", \"false\", \"incorrect\", \"debunked\", \"retracted\", \"no longer\", \"never\", \"denied\", \"contrary\", \"misleading\"];\nconst SUPPORT_MARKERS = [\"yes\", \"true\", \"correct\", \"confirmed\", \"according to\", \"shows that\", \"demonstrates\", \"reported\", \"verified\", \"established\"];\n\nfunction containsPhrase(value: string, phrase: string): boolean {\n\tconst escaped = phrase.trim().toLowerCase().split(/\\s+/).map((term) => term.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).join(\"\\\\s+\");\n\treturn new RegExp(`(?:^|[^a-z0-9])${escaped}(?=$|[^a-z0-9])`, \"i\").test(value);\n}\n\nfunction markerIsNegated(value: string, marker: string): boolean {\n\tconst escaped = marker.trim().toLowerCase().split(/\\s+/).map((term) => term.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).join(\"\\\\s+\");\n\tconst markerPattern = new RegExp(`(?:^|[^a-z0-9])${escaped}(?=$|[^a-z0-9])`, \"i\");\n\tconst match = markerPattern.exec(value);\n\tif (!match || match.index === undefined) return false;\n\tconst matchedMarker = match[0].replace(/^[^a-z0-9]+/i, \"\");\n\tconst beforeMarker = value.slice(0, match.index + match[0].length - matchedMarker.length);\n\treturn /(?:^|[^a-z0-9])(?:not|no|never|without)\\s+$/i.test(beforeMarker);\n}\n\nfunction hasPolarityMarker(value: string, markers: string[], allowNegated = false): boolean {\n\treturn markers.some((marker) => containsPhrase(value, marker) && (allowNegated || !markerIsNegated(value, marker)));\n}\n\nexport function assessClaim(claim: string, passages: ResearchPassage[]): ClaimAssessment {\n\tconst terms = tokenize(claim);\n\tif (terms.length === 0 || passages.length === 0) {\n\t\treturn { claim, status: \"missing-evidence\", supporting_passages: [], contradicting_passages: [], rationale: \"No passages available that discuss the claim's terms.\", confidence: 0.2 };\n\t}\n\tconst supporting: string[] = [];\n\tconst contradicting: string[] = [];\n\tfor (const passage of passages) {\n\t\tconst lower = passage.text.toLowerCase();\n\t\tconst overlap = terms.filter((term) => containsPhrase(lower, term)).length;\n\t\tif (overlap < Math.max(2, Math.ceil(terms.length / 4))) continue;\n\t\tconst contra = hasPolarityMarker(lower, CONTRADICTION_MARKERS);\n\t\tconst support = hasPolarityMarker(lower, SUPPORT_MARKERS);\n\t\tif (contra && !support) contradicting.push(passage.passage_id);\n\t\telse if (support && !contra) supporting.push(passage.passage_id);\n\t}\n\tif (contradicting.length > 0 && supporting.length === 0) {\n\t\treturn { claim, status: \"contradicted\", supporting_passages: [], contradicting_passages: contradicting, rationale: `${contradicting.length} passage(s) contradict the claim; none support it.`, confidence: Math.min(0.85, 0.5 + contradicting.length * 0.1) };\n\t}\n\tif (supporting.length > 0 && contradicting.length === 0) {\n\t\treturn { claim, status: \"supported\", supporting_passages: supporting, contradicting_passages: [], rationale: `${supporting.length} passage(s) support the claim; none contradict it.`, confidence: Math.min(0.85, 0.5 + supporting.length * 0.1) };\n\t}\n\tif (supporting.length > 0 || contradicting.length > 0) {\n\t\treturn { claim, status: \"unclear\", supporting_passages: supporting, contradicting_passages: contradicting, rationale: `${supporting.length} supporting and ${contradicting.length} contradicting passage(s); evidence is mixed.`, confidence: 0.4 };\n\t}\n\treturn { claim, status: \"unclear\", supporting_passages: [], contradicting_passages: [], rationale: \"Passages mention the claim's terms but contain no clear support or contradiction markers.\", confidence: 0.3 };\n}\n\ninterface RankedSearchResult extends SearchResult {\n\trank?: number;\n}\n\nexport interface BuildArtifactInput {\n\tquery: string;\n\tprovider?: string;\n\tsummary?: string;\n\tresults: RankedSearchResult[];\n\tfetched?: ExtractedContent[];\n\trecency?: RecencyFilter;\n\tdomainFilter?: string[];\n}\n\nexport function buildResearchArtifact(input: BuildArtifactInput): ResearchArtifact {\n\tconst filters = input.domainFilter ?? [];\n\tconst fetchedByUrl = new Map((input.fetched ?? []).map((page) => [page.url, page]));\n\tconst sources: ResearchSource[] = [];\n\tconst seen = new Set<string>();\n\tfor (const [index, result] of input.results.entries()) {\n\t\tif (seen.has(result.url)) continue;\n\t\tseen.add(result.url);\n\t\tconst page = fetchedByUrl.get(result.url);\n\t\tconst fetched = Boolean(page && !page.error);\n\t\tsources.push({\n\t\t\trank: result.rank ?? index + 1,\n\t\t\turl: result.url,\n\t\t\ttitle: result.title,\n\t\t\tsnippet: result.snippet,\n\t\t\tquality: classifySource(result.url),\n\t\t\tfetched,\n\t\t\t...(page ? { fetch_timestamp: Date.now() } : {}),\n\t\t\t...(page && !page.error ? { content_hash: hashContent(page.content) } : {}),\n\t\t\t...(page?.error ? { fetch_error: page.error } : {}),\n\t\t});\n\t}\n\tconst passages = buildPassages(sources, input.fetched, input.query);\n\tconst domainInclude = filters.filter((domain) => !domain.startsWith(\"-\"));\n\tconst domainExclude = filters.filter((domain) => domain.startsWith(\"-\")).map((domain) => domain.slice(1));\n\treturn {\n\t\tid: generateId(),\n\t\ttype: \"research\",\n\t\ttimestamp: Date.now(),\n\t\tquery: input.query,\n\t\tsources,\n\t\tpassages,\n\t\t...(input.provider !== undefined ? { provider: input.provider } : {}),\n\t\t...(input.summary !== undefined ? { summary: input.summary } : {}),\n\t\t...(passages.length > 0 ? { content_hash: hashContent(passages.map((passage) => passage.text).join(\"\\n\")) } : {}),\n\t\tfilters: {\n\t\t\t...(input.recency !== undefined ? { recency: input.recency } : {}),\n\t\t\tdomain_include: domainInclude,\n\t\t\tdomain_exclude: domainExclude,\n\t\t},\n\t};\n}\n\nexport function withClaimAssessment(artifact: ResearchArtifact, claims: string[]): ResearchArtifact {\n\treturn { ...artifact, claims: claims.map((claim) => assessClaim(claim, artifact.passages)) };\n}\n\nexport function storeResearchArtifact(artifact: ResearchArtifact): void {\n\tif (!artifact.id) throw new Error(\"Research artifact id must not be empty\");\n\tstoreResult(artifact.id, { id: artifact.id, type: \"research\", timestamp: artifact.timestamp, artifact });\n}\n\nexport function getResearchArtifact(id: string): ResearchArtifact | null {\n\tconst data = getResult(id);\n\tif (!data || data.type !== \"research\" || !data.artifact || typeof data.artifact !== \"object\") return null;\n\treturn data.artifact as ResearchArtifact;\n}\n"]}
@@ -0,0 +1,50 @@
1
+ export type LookupAddress = {
2
+ address: string;
3
+ family: number;
4
+ };
5
+ export type Lookup = (hostname: string) => Promise<LookupAddress[]>;
6
+ type Fetch = typeof fetch;
7
+ export interface SsrfConfig {
8
+ allowRanges: string[];
9
+ trustEnvProxy: boolean;
10
+ }
11
+ export interface DomainPolicy {
12
+ allow: string[];
13
+ deny: string[];
14
+ }
15
+ export declare function loadFetchContentDomainPolicy(): DomainPolicy;
16
+ export declare function loadSsrfConfig(): SsrfConfig;
17
+ interface ValidationOptions {
18
+ lookup?: Lookup;
19
+ /** Optional hostname policy for fetch_content target URLs. */
20
+ domainPolicy?: DomainPolicy;
21
+ /**
22
+ * CIDR ranges (e.g. "198.18.0.0/15") to exempt from the SSRF guard.
23
+ * Useful when a host runs a TUN/fake-IP proxy (Surge, Clash, Mihomo, ...)
24
+ * that resolves public domains into a reserved range. Entries are validated
25
+ * strictly; an invalid entry throws so misconfiguration is not silent.
26
+ */
27
+ allowRanges?: string[];
28
+ /**
29
+ * When true, trust an explicitly-configured HTTP(S) proxy for hostname
30
+ * resolution instead of performing local DNS lookups inside the sandbox.
31
+ * Literal IPs and localhost remain blocked, and NO_PROXY hosts still use
32
+ * the local SSRF preflight. This does not configure proxy transport.
33
+ */
34
+ trustEnvProxy?: boolean;
35
+ }
36
+ interface RedirectRequestInitArgs {
37
+ from: URL;
38
+ to: URL;
39
+ init: RequestInit;
40
+ response: Response;
41
+ }
42
+ interface FetchRemoteOptions extends ValidationOptions {
43
+ fetch?: Fetch;
44
+ maxRedirects?: number;
45
+ onRedirect?: (args: RedirectRequestInitArgs) => RequestInit;
46
+ }
47
+ export declare function validateRemoteUrl(rawUrl: string | URL, options?: ValidationOptions): Promise<URL>;
48
+ export declare function fetchRemoteUrl(url: string | URL, init?: RequestInit, options?: FetchRemoteOptions): Promise<Response>;
49
+ export {};
50
+ //# sourceMappingURL=ssrf-protection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrf-protection.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/ssrf-protection.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;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O,CAAC,QAAQ,CAAC,CAwBnB","sourcesContent":["import { lookup as dnsLookup } from \"node:dns/promises\";\nimport { existsSync, readFileSync, statSync } from \"node:fs\";\nimport net from \"node:net\";\nimport { getWebSearchConfigPath } from \"./utils.ts\";\n\nconst DEFAULT_MAX_REDIRECTS = 5;\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\nexport type LookupAddress = { address: string; family: number };\nexport type Lookup = (hostname: string) => Promise<LookupAddress[]>;\ntype Fetch = typeof fetch;\n\nconst WEB_SEARCH_CONFIG_PATH = getWebSearchConfigPath();\n\nlet cachedConfigRoot: { signature: string; value: Record<string, unknown> | null } | null = null;\n\nfunction loadConfigRoot(): Record<string, unknown> | null {\n\tif (!existsSync(WEB_SEARCH_CONFIG_PATH)) return null;\n\n\tlet signature: string;\n\ttry {\n\t\tconst stat = statSync(WEB_SEARCH_CONFIG_PATH);\n\t\tsignature = `${stat.mtimeMs}:${stat.size}`;\n\t} catch {\n\t\treturn null;\n\t}\n\n\tif (cachedConfigRoot?.signature === signature) return cachedConfigRoot.value;\n\n\tlet raw: string;\n\ttry {\n\t\traw = readFileSync(WEB_SEARCH_CONFIG_PATH, \"utf-8\");\n\t} catch {\n\t\t// Do not memoize read failures: a chmod fix changes neither mtime nor size,\n\t\t// so a cached failure would permanently fail-open the domain policy.\n\t\treturn null;\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(`Failed to parse ${WEB_SEARCH_CONFIG_PATH}: ${message}`);\n\t}\n\n\tconst value = parsed && typeof parsed === \"object\" && !Array.isArray(parsed)\n\t\t? parsed as Record<string, unknown>\n\t\t: null;\n\tcachedConfigRoot = { signature, value };\n\treturn value;\n}\n\nexport interface SsrfConfig {\n\tallowRanges: string[];\n\ttrustEnvProxy: boolean;\n}\n\nexport interface DomainPolicy {\n\tallow: string[];\n\tdeny: string[];\n}\n\nconst DEFAULT_DOMAIN_POLICY: DomainPolicy = { allow: [], deny: [] };\n\nexport function loadFetchContentDomainPolicy(): DomainPolicy {\n\tconst parsed = loadConfigRoot();\n\tif (!parsed) return { ...DEFAULT_DOMAIN_POLICY };\n\tconst fetchContent = parsed.fetchContent;\n\tif (fetchContent === undefined || fetchContent === null) return { ...DEFAULT_DOMAIN_POLICY };\n\tif (typeof fetchContent !== \"object\" || Array.isArray(fetchContent)) {\n\t\tthrow new Error(`fetchContent in ${WEB_SEARCH_CONFIG_PATH} must be an object`);\n\t}\n\tconst policy = (fetchContent as { domainPolicy?: unknown }).domainPolicy;\n\tif (policy === undefined || policy === null) return { ...DEFAULT_DOMAIN_POLICY };\n\tif (typeof policy !== \"object\" || Array.isArray(policy)) {\n\t\tthrow new Error(`fetchContent.domainPolicy in ${WEB_SEARCH_CONFIG_PATH} must be an object`);\n\t}\n\tconst config = policy as { allow?: unknown; deny?: unknown };\n\treturn {\n\t\tallow: parseDomainEntries(config.allow, \"allow\"),\n\t\tdeny: parseDomainEntries(config.deny, \"deny\"),\n\t};\n}\n\nfunction parseDomainEntries(value: unknown, field: \"allow\" | \"deny\"): string[] {\n\tif (value === undefined || value === null) return [];\n\tif (!Array.isArray(value)) {\n\t\tthrow new Error(`fetchContent.domainPolicy.${field} in ${WEB_SEARCH_CONFIG_PATH} must be an array of hostnames`);\n\t}\n\treturn value.map((entry, index) => {\n\t\tif (typeof entry !== \"string\") {\n\t\t\tthrow new Error(`fetchContent.domainPolicy.${field} in ${WEB_SEARCH_CONFIG_PATH} must contain only hostnames; entry ${index + 1} is ${typeof entry}`);\n\t\t}\n\t\tconst hostname = normalizeDomainEntry(entry);\n\t\tif (!hostname) {\n\t\t\tthrow new Error(`fetchContent.domainPolicy.${field} in ${WEB_SEARCH_CONFIG_PATH} contains an invalid hostname: ${JSON.stringify(entry)}`);\n\t\t}\n\t\treturn hostname;\n\t});\n}\n\nfunction normalizeDomainEntry(entry: string): string | null {\n\tconst hostname = normalizeHostname(entry.trim());\n\tif (!hostname || /\\s|[\\\\/?:#@]/.test(hostname)) return null;\n\tif (net.isIP(hostname)) return hostname;\n\tif (hostname.length > 253 || !/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(hostname)) return null;\n\treturn hostname;\n}\n\nexport function loadSsrfConfig(): SsrfConfig {\n\tconst parsed = loadConfigRoot();\n\tif (!parsed) return { allowRanges: [], trustEnvProxy: false };\n\tconst ssrf = parsed.ssrf;\n\tif (ssrf === undefined || ssrf === null) return { allowRanges: [], trustEnvProxy: false };\n\tif (typeof ssrf !== \"object\" || Array.isArray(ssrf)) {\n\t\tthrow new Error(`ssrf in ${WEB_SEARCH_CONFIG_PATH} must be an object`);\n\t}\n\tconst config = ssrf as { allowRanges?: unknown; trustEnvProxy?: unknown };\n\tif (config.allowRanges !== undefined && config.allowRanges !== null && !Array.isArray(config.allowRanges)) {\n\t\tthrow new Error(`ssrf.allowRanges in ${WEB_SEARCH_CONFIG_PATH} must be an array of CIDR strings`);\n\t}\n\tif (config.trustEnvProxy !== undefined && typeof config.trustEnvProxy !== \"boolean\") {\n\t\tthrow new Error(`ssrf.trustEnvProxy in ${WEB_SEARCH_CONFIG_PATH} must be a boolean`);\n\t}\n\tconst allowRangesValue: unknown[] = Array.isArray(config.allowRanges) ? config.allowRanges : [];\n\tconst allowRanges = allowRangesValue.map((entry, index) => {\n\t\tif (typeof entry !== \"string\") {\n\t\t\tthrow new Error(`ssrf.allowRanges in ${WEB_SEARCH_CONFIG_PATH} must contain only CIDR strings; entry ${index + 1} is ${typeof entry}`);\n\t\t}\n\t\treturn entry.trim();\n\t}).filter(Boolean);\n\tparseAllowRanges(allowRanges);\n\treturn { allowRanges, trustEnvProxy: config.trustEnvProxy === true };\n}\n\ninterface ValidationOptions {\n\tlookup?: Lookup;\n\t/** Optional hostname policy for fetch_content target URLs. */\n\tdomainPolicy?: DomainPolicy;\n\t/**\n\t * CIDR ranges (e.g. \"198.18.0.0/15\") to exempt from the SSRF guard.\n\t * Useful when a host runs a TUN/fake-IP proxy (Surge, Clash, Mihomo, ...)\n\t * that resolves public domains into a reserved range. Entries are validated\n\t * strictly; an invalid entry throws so misconfiguration is not silent.\n\t */\n\tallowRanges?: string[];\n\t/**\n\t * When true, trust an explicitly-configured HTTP(S) proxy for hostname\n\t * resolution instead of performing local DNS lookups inside the sandbox.\n\t * Literal IPs and localhost remain blocked, and NO_PROXY hosts still use\n\t * the local SSRF preflight. This does not configure proxy transport.\n\t */\n\ttrustEnvProxy?: boolean;\n}\n\n/** Parsed entry from `allowRanges`: a network address (4 or 16 bytes) + prefix length. */\ninterface ParsedCidr {\n\tbytes: Uint8Array;\n\tprefix: number;\n}\n\ninterface RedirectRequestInitArgs {\n\tfrom: URL;\n\tto: URL;\n\tinit: RequestInit;\n\tresponse: Response;\n}\n\ninterface FetchRemoteOptions extends ValidationOptions {\n\tfetch?: Fetch;\n\tmaxRedirects?: number;\n\tonRedirect?: (args: RedirectRequestInitArgs) => RequestInit;\n}\n\nasync function defaultLookup(hostname: string): Promise<LookupAddress[]> {\n\treturn dnsLookup(hostname, { all: true, verbatim: true });\n}\n\nexport async function validateRemoteUrl(rawUrl: string | URL, options: ValidationOptions = {}): Promise<URL> {\n\tconst url = rawUrl instanceof URL ? rawUrl : new URL(rawUrl);\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\"Only HTTP and HTTPS URLs can be fetched remotely\");\n\t}\n\n\tconst hostname = normalizeHostname(url.hostname);\n\tif (!hostname) throw new Error(\"URL must include a hostname\");\n\tif (hostname === \"localhost\" || hostname.endsWith(\".localhost\")) {\n\t\tthrow new Error(`Blocked internal hostname: ${hostname}`);\n\t}\n\n\tconst allowRanges = parseAllowRanges(options.allowRanges);\n\tassertDomainPolicy(hostname, options.domainPolicy);\n\n\tif (net.isIP(hostname)) {\n\t\tassertPublicAddress(hostname, hostname, allowRanges);\n\t\treturn url;\n\t}\n\n\tif (shouldTrustEnvProxy(url, options.trustEnvProxy === true)) return url;\n\n\tlet addresses: LookupAddress[];\n\ttry {\n\t\taddresses = await (options.lookup ?? defaultLookup)(hostname);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(`Failed to resolve ${hostname}: ${message}`);\n\t}\n\n\tif (addresses.length === 0) throw new Error(`Failed to resolve ${hostname}: no addresses returned`);\n\tfor (const { address } of addresses) {\n\t\tassertPublicAddress(address, hostname, allowRanges);\n\t}\n\treturn url;\n}\n\nexport async function fetchRemoteUrl(\n\turl: string | URL,\n\tinit: RequestInit = {},\n\toptions: FetchRemoteOptions = {},\n): Promise<Response> {\n\tconst fetchImpl = options.fetch ?? fetch;\n\tconst maxRedirects = options.maxRedirects ?? DEFAULT_MAX_REDIRECTS;\n\tlet current = await validateRemoteUrl(url, options);\n\tlet requestInit = init;\n\n\tfor (let redirects = 0; redirects <= maxRedirects; redirects++) {\n\t\tconst response = await fetchImpl(current, { ...requestInit, redirect: \"manual\" });\n\t\tif (!REDIRECT_STATUSES.has(response.status)) return response;\n\n\t\tconst location = response.headers.get(\"location\");\n\t\tif (!location) return response;\n\t\tif (redirects === maxRedirects) throw new Error(`Too many redirects fetching ${current.toString()}`);\n\n\t\tconst from = current;\n\t\tcurrent = await validateRemoteUrl(new URL(location, current), options);\n\t\tif (response.status === 303 || ((response.status === 301 || response.status === 302) && requestInit.method?.toUpperCase() === \"POST\")) {\n\t\t\tconst { body: _body, ...nextInit } = requestInit;\n\t\t\trequestInit = { ...nextInit, method: \"GET\" };\n\t\t}\n\t\tif (options.onRedirect) requestInit = options.onRedirect({ from, to: current, init: requestInit, response });\n\t}\n\n\tthrow new Error(`Too many redirects fetching ${current.toString()}`);\n}\n\nfunction normalizeHostname(hostname: string): string {\n\treturn hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\").replace(/\\.$/, \"\");\n}\n\nfunction assertDomainPolicy(hostname: string, policy?: DomainPolicy): void {\n\tif (!policy) return;\n\tif (policy.deny.some((entry) => domainMatches(hostname, entry))) {\n\t\tthrow new Error(`Blocked hostname by fetch_content domain policy: ${hostname}`);\n\t}\n\tif (policy.allow.length > 0 && !policy.allow.some((entry) => domainMatches(hostname, entry))) {\n\t\tthrow new Error(`Hostname not allowed by fetch_content domain policy: ${hostname}`);\n\t}\n}\n\nfunction domainMatches(hostname: string, entry: string): boolean {\n\treturn hostname === entry || hostname.endsWith(`.${entry}`);\n}\n\nfunction getProxyForProtocol(protocol: string): string {\n\tconst candidates = protocol === \"http:\"\n\t\t? [process.env.HTTP_PROXY, process.env.http_proxy, process.env.ALL_PROXY, process.env.all_proxy]\n\t\t: protocol === \"https:\"\n\t\t\t? [process.env.HTTPS_PROXY, process.env.https_proxy, process.env.HTTP_PROXY, process.env.http_proxy, process.env.ALL_PROXY, process.env.all_proxy]\n\t\t\t: [];\n\tfor (const candidate of candidates) {\n\t\tconst value = candidate?.trim();\n\t\tif (!value) continue;\n\t\ttry {\n\t\t\tconst proxyUrl = new URL(value);\n\t\t\tif ((proxyUrl.protocol === \"http:\" || proxyUrl.protocol === \"https:\") && proxyUrl.hostname) return value;\n\t\t} catch {\n\t\t\t// Invalid proxy env vars should not weaken local DNS SSRF checks.\n\t\t}\n\t}\n\treturn \"\";\n}\n\nfunction hostnameMatchesNoProxy(hostname: string, port: string, entry: string): boolean {\n\tconst trimmed = entry.trim();\n\tif (!trimmed) return false;\n\tif (trimmed === \"*\") return true;\n\n\t// NO_PROXY entries may include a port. Strip it only after handling\n\t// bracketed IPv6 literals, which can contain several colons.\n\tlet hostEntry = trimmed;\n\tlet entryPort: string | undefined;\n\tif (hostEntry.startsWith(\"[\")) {\n\t\tconst closingBracket = hostEntry.indexOf(\"]\");\n\t\tif (closingBracket >= 0) {\n\t\t\tconst suffix = hostEntry.slice(closingBracket + 1);\n\t\t\tif (/^:\\\\d+$/.test(suffix)) entryPort = suffix.slice(1);\n\t\t\thostEntry = hostEntry.slice(0, closingBracket + 1);\n\t\t}\n\t} else {\n\t\tconst colon = hostEntry.lastIndexOf(\":\");\n\t\tif (colon > -1 && /^\\d+$/.test(hostEntry.slice(colon + 1))) {\n\t\t\tentryPort = hostEntry.slice(colon + 1);\n\t\t\thostEntry = hostEntry.slice(0, colon);\n\t\t}\n\t}\n\tif (entryPort !== undefined && entryPort !== port) return false;\n\n\tconst normalizedEntry = normalizeHostname(hostEntry);\n\tif (!normalizedEntry) return false;\n\tif (normalizedEntry === hostname) return true;\n\tconst suffix = normalizedEntry.startsWith(\"*.\")\n\t\t? normalizedEntry.slice(1)\n\t\t: normalizedEntry.startsWith(\".\")\n\t\t\t? normalizedEntry\n\t\t\t: `.${normalizedEntry}`;\n\treturn hostname.endsWith(suffix);\n}\n\nfunction shouldTrustEnvProxy(url: URL, enabled: boolean): boolean {\n\tif (!enabled || !getProxyForProtocol(url.protocol)) return false;\n\tconst hostname = normalizeHostname(url.hostname);\n\tconst port = url.port || (url.protocol === \"https:\" ? \"443\" : \"80\");\n\tconst noProxy = process.env.NO_PROXY || process.env.no_proxy || \"\";\n\treturn !noProxy.split(\",\").some(entry => hostnameMatchesNoProxy(hostname, port, entry));\n}\n\nfunction assertPublicAddress(address: string, hostname: string, allowRanges: ParsedCidr[] = []): void {\n\tconst normalized = normalizeHostname(address);\n\tconst ipVersion = net.isIP(normalized);\n\tif (ipVersion === 0) throw new Error(`Resolved non-IP address for ${hostname}: ${address}`);\n\t// Explicitly-allowed ranges bypass the private/reserved checks below. This lets\n\t// users exempt synthetic ranges produced by TUN/fake-IP proxies (e.g. 198.18/15).\n\tif (isInAllowedRange(normalized, ipVersion, allowRanges)) return;\n\tif (ipVersion === 4 && isBlockedIPv4(normalized)) {\n\t\tconst hint = isFakeIpProxyAddress(normalized)\n\t\t\t? '. This address is in 198.18.0.0/15, commonly used by TUN/fake-IP proxies. If that matches your setup, configure ssrf.allowRanges with [\"198.18.0.0/15\"] in web-search.json.'\n\t\t\t: \"\";\n\t\tthrow new Error(`Blocked internal address for ${hostname}: ${normalized}${hint}`);\n\t}\n\tif (ipVersion === 6 && isBlockedIPv6(normalized)) {\n\t\tthrow new Error(`Blocked internal address for ${hostname}: ${normalized}`);\n\t}\n}\n\nfunction isFakeIpProxyAddress(address: string): boolean {\n\tconst [a, b] = address.split(\".\").map(part => Number(part));\n\treturn a === 198 && (b === 18 || b === 19);\n}\n\nfunction isBlockedIPv4(address: string): boolean {\n\tconst parts = address.split(\".\").map(part => Number(part));\n\tif (parts.length !== 4 || parts.some(part => !Number.isInteger(part) || part < 0 || part > 255)) return true;\n\tconst [a, b] = parts;\n\treturn a === 0 ||\n\t\ta === 10 ||\n\t\ta === 127 ||\n\t\t(a === 100 && b >= 64 && b <= 127) ||\n\t\t(a === 169 && b === 254) ||\n\t\t(a === 172 && b >= 16 && b <= 31) ||\n\t\t(a === 192 && b === 168) ||\n\t\tisFakeIpProxyAddress(address) ||\n\t\ta >= 224;\n}\n\nfunction isBlockedIPv6(address: string): boolean {\n\tconst groups = parseIPv6(address);\n\tif (!groups) return true;\n\n\tconst first = groups[0];\n\tif (groups.every(group => group === 0)) return true;\n\tif (groups.slice(0, 7).every(group => group === 0) && groups[7] === 1) return true;\n\tif ((first & 0xfe00) === 0xfc00) return true;\n\tif ((first & 0xffc0) === 0xfe80) return true;\n\n\tconst isMappedIPv4 = groups.slice(0, 5).every(group => group === 0) && groups[5] === 0xffff;\n\tif (isMappedIPv4) {\n\t\tconst ipv4 = [groups[6] >> 8, groups[6] & 0xff, groups[7] >> 8, groups[7] & 0xff].join(\".\");\n\t\treturn isBlockedIPv4(ipv4);\n\t}\n\n\treturn false;\n}\n\nfunction parseIPv6(address: string): number[] | null {\n\tif (address.includes(\".\")) {\n\t\tconst lastColon = address.lastIndexOf(\":\");\n\t\tconst ipv4 = address.slice(lastColon + 1);\n\t\tif (net.isIP(ipv4) !== 4) return null;\n\t\tconst octets = ipv4.split(\".\").map(part => Number(part));\n\t\taddress = `${address.slice(0, lastColon)}:${((octets[0] << 8) | octets[1]).toString(16)}:${((octets[2] << 8) | octets[3]).toString(16)}`;\n\t}\n\n\tconst pieces = address.split(\"::\");\n\tif (pieces.length > 2) return null;\n\n\tconst left = pieces[0] ? pieces[0].split(\":\") : [];\n\tconst right = pieces.length === 2 && pieces[1] ? pieces[1].split(\":\") : [];\n\tconst missing = 8 - left.length - right.length;\n\tif (pieces.length === 1 && missing !== 0) return null;\n\tif (pieces.length === 2 && missing < 0) return null;\n\n\tconst groups = [...left, ...Array(missing).fill(\"0\"), ...right].map(part => {\n\t\tif (!/^[0-9a-f]{1,4}$/i.test(part)) return -1;\n\t\treturn parseInt(part, 16);\n\t});\n\treturn groups.length === 8 && groups.every(group => group >= 0 && group <= 0xffff) ? groups : null;\n}\n\n/** Parse `allowRanges` config value into validated CIDR rules. Throws on malformed entries. */\nfunction parseAllowRanges(input: unknown): ParsedCidr[] {\n\tif (input === undefined || input === null) return [];\n\tif (!Array.isArray(input)) {\n\t\tthrow new Error(\"ssrf.allowRanges must be an array of CIDR strings\");\n\t}\n\tconst rules: ParsedCidr[] = [];\n\tfor (const entry of input) {\n\t\tif (typeof entry !== \"string\") {\n\t\t\tthrow new Error(`ssrf.allowRanges entries must be strings, got ${typeof entry}`);\n\t\t}\n\t\tconst rule = parseCidr(entry.trim());\n\t\tif (!rule) {\n\t\t\tthrow new Error(`Invalid CIDR notation in ssrf.allowRanges: \"${entry}\"`);\n\t\t}\n\t\trules.push(rule);\n\t}\n\treturn rules;\n}\n\n/** Parse a single CIDR (e.g. \"198.18.0.0/15\", \"fd00::/8\") or bare host (\"1.2.3.4\"). Returns null if invalid. */\nfunction parseCidr(raw: string): ParsedCidr | null {\n\tif (!raw) return null;\n\tconst slash = raw.lastIndexOf(\"/\");\n\tconst addrPart = slash >= 0 ? raw.slice(0, slash) : raw;\n\tconst prefixPart = slash >= 0 ? raw.slice(slash + 1) : null;\n\t// A slash must be followed by digits. Number(\"\")/Number(\" \") are 0, which\n\t// would silently turn \"198.18.0.0/\" into /0 and exempt every address.\n\tif (prefixPart !== null && !/^\\d+$/.test(prefixPart)) return null;\n\tconst version = net.isIP(addrPart);\n\n\tif (version === 4) {\n\t\tconst bytes = ipv4ToBytes(addrPart);\n\t\tif (!bytes) return null;\n\t\tconst prefix = prefixPart === null ? 32 : Number(prefixPart);\n\t\tif (!Number.isInteger(prefix) || prefix < 1 || prefix > 32) return null;\n\t\treturn { bytes, prefix };\n\t}\n\tif (version === 6) {\n\t\tconst groups = parseIPv6(addrPart);\n\t\tif (!groups) return null;\n\t\tconst prefix = prefixPart === null ? 128 : Number(prefixPart);\n\t\tif (!Number.isInteger(prefix) || prefix < 1 || prefix > 128) return null;\n\t\treturn { bytes: ipv6GroupsToBytes(groups), prefix };\n\t}\n\treturn null;\n}\n\nfunction ipv4ToBytes(address: string): Uint8Array | null {\n\tconst parts = address.split(\".\");\n\tif (parts.length !== 4) return null;\n\tconst bytes = new Uint8Array(4);\n\tfor (let i = 0; i < 4; i++) {\n\t\tconst octet = Number(parts[i]);\n\t\tif (!Number.isInteger(octet) || octet < 0 || octet > 255) return null;\n\t\tbytes[i] = octet;\n\t}\n\treturn bytes;\n}\n\nfunction ipv6GroupsToBytes(groups: number[]): Uint8Array {\n\tconst bytes = new Uint8Array(16);\n\tfor (let i = 0; i < 8; i++) {\n\t\tbytes[i * 2] = groups[i] >> 8;\n\t\tbytes[i * 2 + 1] = groups[i] & 0xff;\n\t}\n\treturn bytes;\n}\n\nfunction ipToBytes(address: string, version: number): Uint8Array | null {\n\tif (version === 4) return ipv4ToBytes(address);\n\tif (version === 6) {\n\t\tconst groups = parseIPv6(address);\n\t\treturn groups ? ipv6GroupsToBytes(groups) : null;\n\t}\n\treturn null;\n}\n\n/** True if `address` (already validated as `ipVersion`) falls within any allowed CIDR. */\nfunction isInAllowedRange(address: string, ipVersion: number, allowRanges: ParsedCidr[]): boolean {\n\tif (allowRanges.length === 0) return false;\n\tconst addrBytes = ipToBytes(address, ipVersion);\n\tif (!addrBytes) return false;\n\tfor (const rule of allowRanges) {\n\t\t// Only compare same-family rules (4-byte IPv4 vs 16-byte IPv6).\n\t\tif (rule.bytes.length !== addrBytes.length) continue;\n\t\tif (bytesMatchPrefix(addrBytes, rule.bytes, rule.prefix)) return true;\n\t}\n\treturn false;\n}\n\n/** Compare the leading `prefix` bits of two equal-length byte arrays. */\nfunction bytesMatchPrefix(addr: Uint8Array, network: Uint8Array, prefix: number): boolean {\n\tconst fullBytes = prefix >> 3;\n\tconst remBits = prefix & 7;\n\tfor (let i = 0; i < fullBytes; i++) {\n\t\tif (addr[i] !== network[i]) return false;\n\t}\n\tif (remBits > 0 && fullBytes < addr.length) {\n\t\tconst mask = (0xff << (8 - remBits)) & 0xff;\n\t\tif ((addr[fullBytes] & mask) !== (network[fullBytes] & mask)) return false;\n\t}\n\treturn true;\n}\n"]}
@@ -0,0 +1,466 @@
1
+ import { lookup as dnsLookup } from "node:dns/promises";
2
+ import { existsSync, readFileSync, statSync } from "node:fs";
3
+ import net from "node:net";
4
+ import { getWebSearchConfigPath } from "./utils.js";
5
+ const DEFAULT_MAX_REDIRECTS = 5;
6
+ const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
7
+ const WEB_SEARCH_CONFIG_PATH = getWebSearchConfigPath();
8
+ let cachedConfigRoot = null;
9
+ function loadConfigRoot() {
10
+ if (!existsSync(WEB_SEARCH_CONFIG_PATH))
11
+ return null;
12
+ let signature;
13
+ try {
14
+ const stat = statSync(WEB_SEARCH_CONFIG_PATH);
15
+ signature = `${stat.mtimeMs}:${stat.size}`;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ if (cachedConfigRoot?.signature === signature)
21
+ return cachedConfigRoot.value;
22
+ let raw;
23
+ try {
24
+ raw = readFileSync(WEB_SEARCH_CONFIG_PATH, "utf-8");
25
+ }
26
+ catch {
27
+ // Do not memoize read failures: a chmod fix changes neither mtime nor size,
28
+ // so a cached failure would permanently fail-open the domain policy.
29
+ return null;
30
+ }
31
+ let parsed;
32
+ try {
33
+ parsed = JSON.parse(raw);
34
+ }
35
+ catch (err) {
36
+ const message = err instanceof Error ? err.message : String(err);
37
+ throw new Error(`Failed to parse ${WEB_SEARCH_CONFIG_PATH}: ${message}`);
38
+ }
39
+ const value = parsed && typeof parsed === "object" && !Array.isArray(parsed)
40
+ ? parsed
41
+ : null;
42
+ cachedConfigRoot = { signature, value };
43
+ return value;
44
+ }
45
+ const DEFAULT_DOMAIN_POLICY = { allow: [], deny: [] };
46
+ export function loadFetchContentDomainPolicy() {
47
+ const parsed = loadConfigRoot();
48
+ if (!parsed)
49
+ return { ...DEFAULT_DOMAIN_POLICY };
50
+ const fetchContent = parsed.fetchContent;
51
+ if (fetchContent === undefined || fetchContent === null)
52
+ return { ...DEFAULT_DOMAIN_POLICY };
53
+ if (typeof fetchContent !== "object" || Array.isArray(fetchContent)) {
54
+ throw new Error(`fetchContent in ${WEB_SEARCH_CONFIG_PATH} must be an object`);
55
+ }
56
+ const policy = fetchContent.domainPolicy;
57
+ if (policy === undefined || policy === null)
58
+ return { ...DEFAULT_DOMAIN_POLICY };
59
+ if (typeof policy !== "object" || Array.isArray(policy)) {
60
+ throw new Error(`fetchContent.domainPolicy in ${WEB_SEARCH_CONFIG_PATH} must be an object`);
61
+ }
62
+ const config = policy;
63
+ return {
64
+ allow: parseDomainEntries(config.allow, "allow"),
65
+ deny: parseDomainEntries(config.deny, "deny"),
66
+ };
67
+ }
68
+ function parseDomainEntries(value, field) {
69
+ if (value === undefined || value === null)
70
+ return [];
71
+ if (!Array.isArray(value)) {
72
+ throw new Error(`fetchContent.domainPolicy.${field} in ${WEB_SEARCH_CONFIG_PATH} must be an array of hostnames`);
73
+ }
74
+ return value.map((entry, index) => {
75
+ if (typeof entry !== "string") {
76
+ throw new Error(`fetchContent.domainPolicy.${field} in ${WEB_SEARCH_CONFIG_PATH} must contain only hostnames; entry ${index + 1} is ${typeof entry}`);
77
+ }
78
+ const hostname = normalizeDomainEntry(entry);
79
+ if (!hostname) {
80
+ throw new Error(`fetchContent.domainPolicy.${field} in ${WEB_SEARCH_CONFIG_PATH} contains an invalid hostname: ${JSON.stringify(entry)}`);
81
+ }
82
+ return hostname;
83
+ });
84
+ }
85
+ function normalizeDomainEntry(entry) {
86
+ const hostname = normalizeHostname(entry.trim());
87
+ if (!hostname || /\s|[\\/?:#@]/.test(hostname))
88
+ return null;
89
+ if (net.isIP(hostname))
90
+ return hostname;
91
+ if (hostname.length > 253 || !/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(hostname))
92
+ return null;
93
+ return hostname;
94
+ }
95
+ export function loadSsrfConfig() {
96
+ const parsed = loadConfigRoot();
97
+ if (!parsed)
98
+ return { allowRanges: [], trustEnvProxy: false };
99
+ const ssrf = parsed.ssrf;
100
+ if (ssrf === undefined || ssrf === null)
101
+ return { allowRanges: [], trustEnvProxy: false };
102
+ if (typeof ssrf !== "object" || Array.isArray(ssrf)) {
103
+ throw new Error(`ssrf in ${WEB_SEARCH_CONFIG_PATH} must be an object`);
104
+ }
105
+ const config = ssrf;
106
+ if (config.allowRanges !== undefined && config.allowRanges !== null && !Array.isArray(config.allowRanges)) {
107
+ throw new Error(`ssrf.allowRanges in ${WEB_SEARCH_CONFIG_PATH} must be an array of CIDR strings`);
108
+ }
109
+ if (config.trustEnvProxy !== undefined && typeof config.trustEnvProxy !== "boolean") {
110
+ throw new Error(`ssrf.trustEnvProxy in ${WEB_SEARCH_CONFIG_PATH} must be a boolean`);
111
+ }
112
+ const allowRangesValue = Array.isArray(config.allowRanges) ? config.allowRanges : [];
113
+ const allowRanges = allowRangesValue.map((entry, index) => {
114
+ if (typeof entry !== "string") {
115
+ throw new Error(`ssrf.allowRanges in ${WEB_SEARCH_CONFIG_PATH} must contain only CIDR strings; entry ${index + 1} is ${typeof entry}`);
116
+ }
117
+ return entry.trim();
118
+ }).filter(Boolean);
119
+ parseAllowRanges(allowRanges);
120
+ return { allowRanges, trustEnvProxy: config.trustEnvProxy === true };
121
+ }
122
+ async function defaultLookup(hostname) {
123
+ return dnsLookup(hostname, { all: true, verbatim: true });
124
+ }
125
+ export async function validateRemoteUrl(rawUrl, options = {}) {
126
+ const url = rawUrl instanceof URL ? rawUrl : new URL(rawUrl);
127
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
128
+ throw new Error("Only HTTP and HTTPS URLs can be fetched remotely");
129
+ }
130
+ const hostname = normalizeHostname(url.hostname);
131
+ if (!hostname)
132
+ throw new Error("URL must include a hostname");
133
+ if (hostname === "localhost" || hostname.endsWith(".localhost")) {
134
+ throw new Error(`Blocked internal hostname: ${hostname}`);
135
+ }
136
+ const allowRanges = parseAllowRanges(options.allowRanges);
137
+ assertDomainPolicy(hostname, options.domainPolicy);
138
+ if (net.isIP(hostname)) {
139
+ assertPublicAddress(hostname, hostname, allowRanges);
140
+ return url;
141
+ }
142
+ if (shouldTrustEnvProxy(url, options.trustEnvProxy === true))
143
+ return url;
144
+ let addresses;
145
+ try {
146
+ addresses = await (options.lookup ?? defaultLookup)(hostname);
147
+ }
148
+ catch (err) {
149
+ const message = err instanceof Error ? err.message : String(err);
150
+ throw new Error(`Failed to resolve ${hostname}: ${message}`);
151
+ }
152
+ if (addresses.length === 0)
153
+ throw new Error(`Failed to resolve ${hostname}: no addresses returned`);
154
+ for (const { address } of addresses) {
155
+ assertPublicAddress(address, hostname, allowRanges);
156
+ }
157
+ return url;
158
+ }
159
+ export async function fetchRemoteUrl(url, init = {}, options = {}) {
160
+ const fetchImpl = options.fetch ?? fetch;
161
+ const maxRedirects = options.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
162
+ let current = await validateRemoteUrl(url, options);
163
+ let requestInit = init;
164
+ for (let redirects = 0; redirects <= maxRedirects; redirects++) {
165
+ const response = await fetchImpl(current, { ...requestInit, redirect: "manual" });
166
+ if (!REDIRECT_STATUSES.has(response.status))
167
+ return response;
168
+ const location = response.headers.get("location");
169
+ if (!location)
170
+ return response;
171
+ if (redirects === maxRedirects)
172
+ throw new Error(`Too many redirects fetching ${current.toString()}`);
173
+ const from = current;
174
+ current = await validateRemoteUrl(new URL(location, current), options);
175
+ if (response.status === 303 || ((response.status === 301 || response.status === 302) && requestInit.method?.toUpperCase() === "POST")) {
176
+ const { body: _body, ...nextInit } = requestInit;
177
+ requestInit = { ...nextInit, method: "GET" };
178
+ }
179
+ if (options.onRedirect)
180
+ requestInit = options.onRedirect({ from, to: current, init: requestInit, response });
181
+ }
182
+ throw new Error(`Too many redirects fetching ${current.toString()}`);
183
+ }
184
+ function normalizeHostname(hostname) {
185
+ return hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
186
+ }
187
+ function assertDomainPolicy(hostname, policy) {
188
+ if (!policy)
189
+ return;
190
+ if (policy.deny.some((entry) => domainMatches(hostname, entry))) {
191
+ throw new Error(`Blocked hostname by fetch_content domain policy: ${hostname}`);
192
+ }
193
+ if (policy.allow.length > 0 && !policy.allow.some((entry) => domainMatches(hostname, entry))) {
194
+ throw new Error(`Hostname not allowed by fetch_content domain policy: ${hostname}`);
195
+ }
196
+ }
197
+ function domainMatches(hostname, entry) {
198
+ return hostname === entry || hostname.endsWith(`.${entry}`);
199
+ }
200
+ function getProxyForProtocol(protocol) {
201
+ const candidates = protocol === "http:"
202
+ ? [process.env.HTTP_PROXY, process.env.http_proxy, process.env.ALL_PROXY, process.env.all_proxy]
203
+ : protocol === "https:"
204
+ ? [process.env.HTTPS_PROXY, process.env.https_proxy, process.env.HTTP_PROXY, process.env.http_proxy, process.env.ALL_PROXY, process.env.all_proxy]
205
+ : [];
206
+ for (const candidate of candidates) {
207
+ const value = candidate?.trim();
208
+ if (!value)
209
+ continue;
210
+ try {
211
+ const proxyUrl = new URL(value);
212
+ if ((proxyUrl.protocol === "http:" || proxyUrl.protocol === "https:") && proxyUrl.hostname)
213
+ return value;
214
+ }
215
+ catch {
216
+ // Invalid proxy env vars should not weaken local DNS SSRF checks.
217
+ }
218
+ }
219
+ return "";
220
+ }
221
+ function hostnameMatchesNoProxy(hostname, port, entry) {
222
+ const trimmed = entry.trim();
223
+ if (!trimmed)
224
+ return false;
225
+ if (trimmed === "*")
226
+ return true;
227
+ // NO_PROXY entries may include a port. Strip it only after handling
228
+ // bracketed IPv6 literals, which can contain several colons.
229
+ let hostEntry = trimmed;
230
+ let entryPort;
231
+ if (hostEntry.startsWith("[")) {
232
+ const closingBracket = hostEntry.indexOf("]");
233
+ if (closingBracket >= 0) {
234
+ const suffix = hostEntry.slice(closingBracket + 1);
235
+ if (/^:\\d+$/.test(suffix))
236
+ entryPort = suffix.slice(1);
237
+ hostEntry = hostEntry.slice(0, closingBracket + 1);
238
+ }
239
+ }
240
+ else {
241
+ const colon = hostEntry.lastIndexOf(":");
242
+ if (colon > -1 && /^\d+$/.test(hostEntry.slice(colon + 1))) {
243
+ entryPort = hostEntry.slice(colon + 1);
244
+ hostEntry = hostEntry.slice(0, colon);
245
+ }
246
+ }
247
+ if (entryPort !== undefined && entryPort !== port)
248
+ return false;
249
+ const normalizedEntry = normalizeHostname(hostEntry);
250
+ if (!normalizedEntry)
251
+ return false;
252
+ if (normalizedEntry === hostname)
253
+ return true;
254
+ const suffix = normalizedEntry.startsWith("*.")
255
+ ? normalizedEntry.slice(1)
256
+ : normalizedEntry.startsWith(".")
257
+ ? normalizedEntry
258
+ : `.${normalizedEntry}`;
259
+ return hostname.endsWith(suffix);
260
+ }
261
+ function shouldTrustEnvProxy(url, enabled) {
262
+ if (!enabled || !getProxyForProtocol(url.protocol))
263
+ return false;
264
+ const hostname = normalizeHostname(url.hostname);
265
+ const port = url.port || (url.protocol === "https:" ? "443" : "80");
266
+ const noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
267
+ return !noProxy.split(",").some(entry => hostnameMatchesNoProxy(hostname, port, entry));
268
+ }
269
+ function assertPublicAddress(address, hostname, allowRanges = []) {
270
+ const normalized = normalizeHostname(address);
271
+ const ipVersion = net.isIP(normalized);
272
+ if (ipVersion === 0)
273
+ throw new Error(`Resolved non-IP address for ${hostname}: ${address}`);
274
+ // Explicitly-allowed ranges bypass the private/reserved checks below. This lets
275
+ // users exempt synthetic ranges produced by TUN/fake-IP proxies (e.g. 198.18/15).
276
+ if (isInAllowedRange(normalized, ipVersion, allowRanges))
277
+ return;
278
+ if (ipVersion === 4 && isBlockedIPv4(normalized)) {
279
+ const hint = isFakeIpProxyAddress(normalized)
280
+ ? '. This address is in 198.18.0.0/15, commonly used by TUN/fake-IP proxies. If that matches your setup, configure ssrf.allowRanges with ["198.18.0.0/15"] in web-search.json.'
281
+ : "";
282
+ throw new Error(`Blocked internal address for ${hostname}: ${normalized}${hint}`);
283
+ }
284
+ if (ipVersion === 6 && isBlockedIPv6(normalized)) {
285
+ throw new Error(`Blocked internal address for ${hostname}: ${normalized}`);
286
+ }
287
+ }
288
+ function isFakeIpProxyAddress(address) {
289
+ const [a, b] = address.split(".").map(part => Number(part));
290
+ return a === 198 && (b === 18 || b === 19);
291
+ }
292
+ function isBlockedIPv4(address) {
293
+ const parts = address.split(".").map(part => Number(part));
294
+ if (parts.length !== 4 || parts.some(part => !Number.isInteger(part) || part < 0 || part > 255))
295
+ return true;
296
+ const [a, b] = parts;
297
+ return a === 0 ||
298
+ a === 10 ||
299
+ a === 127 ||
300
+ (a === 100 && b >= 64 && b <= 127) ||
301
+ (a === 169 && b === 254) ||
302
+ (a === 172 && b >= 16 && b <= 31) ||
303
+ (a === 192 && b === 168) ||
304
+ isFakeIpProxyAddress(address) ||
305
+ a >= 224;
306
+ }
307
+ function isBlockedIPv6(address) {
308
+ const groups = parseIPv6(address);
309
+ if (!groups)
310
+ return true;
311
+ const first = groups[0];
312
+ if (groups.every(group => group === 0))
313
+ return true;
314
+ if (groups.slice(0, 7).every(group => group === 0) && groups[7] === 1)
315
+ return true;
316
+ if ((first & 0xfe00) === 0xfc00)
317
+ return true;
318
+ if ((first & 0xffc0) === 0xfe80)
319
+ return true;
320
+ const isMappedIPv4 = groups.slice(0, 5).every(group => group === 0) && groups[5] === 0xffff;
321
+ if (isMappedIPv4) {
322
+ const ipv4 = [groups[6] >> 8, groups[6] & 0xff, groups[7] >> 8, groups[7] & 0xff].join(".");
323
+ return isBlockedIPv4(ipv4);
324
+ }
325
+ return false;
326
+ }
327
+ function parseIPv6(address) {
328
+ if (address.includes(".")) {
329
+ const lastColon = address.lastIndexOf(":");
330
+ const ipv4 = address.slice(lastColon + 1);
331
+ if (net.isIP(ipv4) !== 4)
332
+ return null;
333
+ const octets = ipv4.split(".").map(part => Number(part));
334
+ address = `${address.slice(0, lastColon)}:${((octets[0] << 8) | octets[1]).toString(16)}:${((octets[2] << 8) | octets[3]).toString(16)}`;
335
+ }
336
+ const pieces = address.split("::");
337
+ if (pieces.length > 2)
338
+ return null;
339
+ const left = pieces[0] ? pieces[0].split(":") : [];
340
+ const right = pieces.length === 2 && pieces[1] ? pieces[1].split(":") : [];
341
+ const missing = 8 - left.length - right.length;
342
+ if (pieces.length === 1 && missing !== 0)
343
+ return null;
344
+ if (pieces.length === 2 && missing < 0)
345
+ return null;
346
+ const groups = [...left, ...Array(missing).fill("0"), ...right].map(part => {
347
+ if (!/^[0-9a-f]{1,4}$/i.test(part))
348
+ return -1;
349
+ return parseInt(part, 16);
350
+ });
351
+ return groups.length === 8 && groups.every(group => group >= 0 && group <= 0xffff) ? groups : null;
352
+ }
353
+ /** Parse `allowRanges` config value into validated CIDR rules. Throws on malformed entries. */
354
+ function parseAllowRanges(input) {
355
+ if (input === undefined || input === null)
356
+ return [];
357
+ if (!Array.isArray(input)) {
358
+ throw new Error("ssrf.allowRanges must be an array of CIDR strings");
359
+ }
360
+ const rules = [];
361
+ for (const entry of input) {
362
+ if (typeof entry !== "string") {
363
+ throw new Error(`ssrf.allowRanges entries must be strings, got ${typeof entry}`);
364
+ }
365
+ const rule = parseCidr(entry.trim());
366
+ if (!rule) {
367
+ throw new Error(`Invalid CIDR notation in ssrf.allowRanges: "${entry}"`);
368
+ }
369
+ rules.push(rule);
370
+ }
371
+ return rules;
372
+ }
373
+ /** Parse a single CIDR (e.g. "198.18.0.0/15", "fd00::/8") or bare host ("1.2.3.4"). Returns null if invalid. */
374
+ function parseCidr(raw) {
375
+ if (!raw)
376
+ return null;
377
+ const slash = raw.lastIndexOf("/");
378
+ const addrPart = slash >= 0 ? raw.slice(0, slash) : raw;
379
+ const prefixPart = slash >= 0 ? raw.slice(slash + 1) : null;
380
+ // A slash must be followed by digits. Number("")/Number(" ") are 0, which
381
+ // would silently turn "198.18.0.0/" into /0 and exempt every address.
382
+ if (prefixPart !== null && !/^\d+$/.test(prefixPart))
383
+ return null;
384
+ const version = net.isIP(addrPart);
385
+ if (version === 4) {
386
+ const bytes = ipv4ToBytes(addrPart);
387
+ if (!bytes)
388
+ return null;
389
+ const prefix = prefixPart === null ? 32 : Number(prefixPart);
390
+ if (!Number.isInteger(prefix) || prefix < 1 || prefix > 32)
391
+ return null;
392
+ return { bytes, prefix };
393
+ }
394
+ if (version === 6) {
395
+ const groups = parseIPv6(addrPart);
396
+ if (!groups)
397
+ return null;
398
+ const prefix = prefixPart === null ? 128 : Number(prefixPart);
399
+ if (!Number.isInteger(prefix) || prefix < 1 || prefix > 128)
400
+ return null;
401
+ return { bytes: ipv6GroupsToBytes(groups), prefix };
402
+ }
403
+ return null;
404
+ }
405
+ function ipv4ToBytes(address) {
406
+ const parts = address.split(".");
407
+ if (parts.length !== 4)
408
+ return null;
409
+ const bytes = new Uint8Array(4);
410
+ for (let i = 0; i < 4; i++) {
411
+ const octet = Number(parts[i]);
412
+ if (!Number.isInteger(octet) || octet < 0 || octet > 255)
413
+ return null;
414
+ bytes[i] = octet;
415
+ }
416
+ return bytes;
417
+ }
418
+ function ipv6GroupsToBytes(groups) {
419
+ const bytes = new Uint8Array(16);
420
+ for (let i = 0; i < 8; i++) {
421
+ bytes[i * 2] = groups[i] >> 8;
422
+ bytes[i * 2 + 1] = groups[i] & 0xff;
423
+ }
424
+ return bytes;
425
+ }
426
+ function ipToBytes(address, version) {
427
+ if (version === 4)
428
+ return ipv4ToBytes(address);
429
+ if (version === 6) {
430
+ const groups = parseIPv6(address);
431
+ return groups ? ipv6GroupsToBytes(groups) : null;
432
+ }
433
+ return null;
434
+ }
435
+ /** True if `address` (already validated as `ipVersion`) falls within any allowed CIDR. */
436
+ function isInAllowedRange(address, ipVersion, allowRanges) {
437
+ if (allowRanges.length === 0)
438
+ return false;
439
+ const addrBytes = ipToBytes(address, ipVersion);
440
+ if (!addrBytes)
441
+ return false;
442
+ for (const rule of allowRanges) {
443
+ // Only compare same-family rules (4-byte IPv4 vs 16-byte IPv6).
444
+ if (rule.bytes.length !== addrBytes.length)
445
+ continue;
446
+ if (bytesMatchPrefix(addrBytes, rule.bytes, rule.prefix))
447
+ return true;
448
+ }
449
+ return false;
450
+ }
451
+ /** Compare the leading `prefix` bits of two equal-length byte arrays. */
452
+ function bytesMatchPrefix(addr, network, prefix) {
453
+ const fullBytes = prefix >> 3;
454
+ const remBits = prefix & 7;
455
+ for (let i = 0; i < fullBytes; i++) {
456
+ if (addr[i] !== network[i])
457
+ return false;
458
+ }
459
+ if (remBits > 0 && fullBytes < addr.length) {
460
+ const mask = (0xff << (8 - remBits)) & 0xff;
461
+ if ((addr[fullBytes] & mask) !== (network[fullBytes] & mask))
462
+ return false;
463
+ }
464
+ return true;
465
+ }
466
+ //# sourceMappingURL=ssrf-protection.js.map