@humain/humain-code 0.7.0 → 0.8.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 (650) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +2 -2
  3. package/dist/bundle/agent-monitor.js +1 -1
  4. package/dist/bundle/chunks/anthropic-messages-UZB5HJE3.js +77 -0
  5. package/dist/bundle/chunks/anthropic.js +25 -24
  6. package/dist/bundle/chunks/azure-openai-responses-J3LCMWPQ.js +15 -0
  7. package/dist/bundle/chunks/bedrock-converse-stream.js +460 -431
  8. package/dist/bundle/chunks/bowser-DXKSTXFQ.js +89 -0
  9. package/dist/bundle/chunks/{chunk-HTA325LJ.js → chunk-2NVGOSBN.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-5B25YXF7.js → chunk-3CGMVKHA.js} +13 -3
  11. package/dist/bundle/chunks/{chunk-SCINMV4X.js → chunk-46C6D7UC.js} +22 -21
  12. package/dist/bundle/chunks/{chunk-RS6PZK35.js → chunk-4EV7CK26.js} +249 -216
  13. package/dist/bundle/chunks/{chunk-T7BXP46S.js → chunk-4SFWYKL5.js} +1848 -1662
  14. package/dist/bundle/chunks/{chunk-TGDPZCSW.js → chunk-4TDNOR36.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-C6VERWRZ.js → chunk-4XF5JX7X.js} +1 -1
  16. package/dist/bundle/chunks/chunk-6HTHDVJC.js +4 -0
  17. package/dist/bundle/chunks/{chunk-2G7YVAVF.js → chunk-7EONJCBE.js} +1 -1
  18. package/dist/bundle/chunks/chunk-7H2WNBX7.js +11 -0
  19. package/dist/bundle/chunks/{chunk-2FYYW6FY.js → chunk-7OZNMWAJ.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-R6YQR7TZ.js → chunk-7WE77IE3.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-Z5YLKK3S.js → chunk-7WETECIB.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-EIC7CQX3.js → chunk-AI7EHDAX.js} +1 -1
  23. package/dist/bundle/chunks/{chunk-KRCX3ZBA.js → chunk-APNPBT7Y.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-4HTVBBJD.js → chunk-ATFZAFMS.js} +2 -2
  25. package/dist/bundle/chunks/{chunk-R5OOX7RW.js → chunk-B47PNNLL.js} +9 -2
  26. package/dist/bundle/chunks/{chunk-AZXVJN6E.js → chunk-C4DHVDYT.js} +1 -1
  27. package/dist/bundle/chunks/{chunk-4PRNKB6V.js → chunk-CET2MXXN.js} +7 -7
  28. package/dist/bundle/chunks/{chunk-66FZJO75.js → chunk-CU6KU7JK.js} +472 -3924
  29. package/dist/bundle/chunks/{chunk-MD7K7RPN.js → chunk-D3KYOSQY.js} +1 -1
  30. package/dist/bundle/chunks/{chunk-I3NDOUHE.js → chunk-DCXHRP6C.js} +1 -1
  31. package/dist/bundle/chunks/{chunk-OB332KMV.js → chunk-DD5UT56Y.js} +46 -32
  32. package/dist/bundle/chunks/{chunk-G4QPSFBF.js → chunk-EMBIUIQ2.js} +216 -223
  33. package/dist/bundle/chunks/{chunk-Q7VXYXY3.js → chunk-ENBDASDN.js} +2 -2
  34. package/dist/bundle/chunks/{chunk-2H3LUS62.js → chunk-FJIISX5W.js} +241 -229
  35. package/dist/bundle/chunks/{chunk-WQOOJP7U.js → chunk-GV5OVRKK.js} +1 -1
  36. package/dist/bundle/chunks/{chunk-KTSJYIYC.js → chunk-HHWVVNGG.js} +1 -1
  37. package/dist/bundle/chunks/{chunk-4JRER4XK.js → chunk-HQMUDHC3.js} +19 -19
  38. package/dist/bundle/chunks/{chunk-WQ7EJQIT.js → chunk-IOLLZXQN.js} +225 -239
  39. package/dist/bundle/chunks/chunk-IXQYPQRQ.js +2079 -0
  40. package/dist/bundle/chunks/{chunk-RU7ADKA7.js → chunk-J4GII2EE.js} +112 -96
  41. package/dist/bundle/chunks/chunk-J5TSAJGC.js +22 -0
  42. package/dist/bundle/chunks/{chunk-QT6ZHDMP.js → chunk-JBSWWCT5.js} +1 -1
  43. package/dist/bundle/chunks/{chunk-P6AXBESH.js → chunk-JV7VHOAY.js} +1119 -1098
  44. package/dist/bundle/chunks/{chunk-PWUDFU5V.js → chunk-JWOPWHVH.js} +4 -4
  45. package/dist/bundle/chunks/{chunk-4V5VL2BO.js → chunk-KLSRGGOH.js} +131 -154
  46. package/dist/bundle/chunks/{chunk-JF7FYXAI.js → chunk-KONLZKPL.js} +7 -6
  47. package/dist/bundle/chunks/{chunk-32QLLD2P.js → chunk-KQXXBQ57.js} +360 -332
  48. package/dist/bundle/chunks/{chunk-UZNIPOGS.js → chunk-L4J7SMJB.js} +1 -1
  49. package/dist/bundle/chunks/chunk-MPRAQ6ZI.js +41 -0
  50. package/dist/bundle/chunks/{chunk-GUHNFZ2Q.js → chunk-NNWNIBLG.js} +20 -19
  51. package/dist/bundle/chunks/{chunk-TWAHPPXN.js → chunk-OVDMYBIT.js} +1307 -1194
  52. package/dist/bundle/chunks/{chunk-WAPZN4KP.js → chunk-P2Y2H7SD.js} +2 -2
  53. package/dist/bundle/chunks/{chunk-PPBDDQHP.js → chunk-PGVDL4KB.js} +7 -6
  54. package/dist/bundle/chunks/{chunk-XHDVDJM7.js → chunk-PVNXN2TC.js} +7 -7
  55. package/dist/bundle/chunks/{chunk-RNBZBCH2.js → chunk-QJB5YI3I.js} +1 -1
  56. package/dist/bundle/chunks/{chunk-I5E7RQ5V.js → chunk-QRYDGY5I.js} +5 -5
  57. package/dist/bundle/chunks/{chunk-4QAXV5T6.js → chunk-R3VDXQW2.js} +9 -9
  58. package/dist/bundle/chunks/chunk-SKCJ25SX.js +24 -0
  59. package/dist/bundle/chunks/chunk-SQ7NTRLJ.js +77 -0
  60. package/dist/bundle/chunks/{chunk-SSRCVJZK.js → chunk-TYN46EVI.js} +5 -5
  61. package/dist/bundle/chunks/{chunk-6E6RHNOU.js → chunk-UXM4WFLH.js} +12 -11
  62. package/dist/bundle/chunks/{chunk-LB4CIS4F.js → chunk-VCMXBP5S.js} +17 -17
  63. package/dist/bundle/chunks/{chunk-N2SNMUD3.js → chunk-VKQNYZUA.js} +1 -1
  64. package/dist/bundle/chunks/{chunk-JYWUOKOI.js → chunk-WBSGWISD.js} +367 -353
  65. package/dist/bundle/chunks/{chunk-3EDMWQ35.js → chunk-WGXMYMPE.js} +17 -15
  66. package/dist/bundle/chunks/chunk-WRYGY5XG.js +24 -0
  67. package/dist/bundle/chunks/{chunk-GRJUKEE3.js → chunk-XVIQYONJ.js} +4 -4
  68. package/dist/bundle/chunks/chunk-YSWDFV2L.js +11 -0
  69. package/dist/bundle/chunks/{chunk-AEWYICBL.js → chunk-Z5UFSRO4.js} +2 -2
  70. package/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
  71. package/dist/bundle/chunks/chunk-ZTG5OKI7.js +3 -0
  72. package/dist/bundle/chunks/{cli-H4LJNE2V.js → cli-6DJO467D.js} +2 -2
  73. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-T5R2RVFQ.js → cloudflare-workers-ai-system-one-ETKC6B2S.js} +1 -1
  74. package/dist/bundle/chunks/codemode-worker.js +68 -68
  75. package/dist/bundle/chunks/compat-HS4ARZK3.js +15 -0
  76. package/dist/bundle/chunks/curator-server-TC7RVVN2.js +3600 -0
  77. package/dist/bundle/chunks/dist-35STTNYA.js +37 -0
  78. package/dist/bundle/chunks/{dist-FMWWM4H7.js → dist-5AQPJ2TI.js} +2 -2
  79. package/dist/bundle/chunks/{dist-NHQTBDHT.js → dist-DYB3AR7C.js} +91 -257
  80. package/dist/bundle/chunks/dist-NMEXYUP3.js +11 -0
  81. package/dist/bundle/chunks/dist-cjs-EROMDUKS.js +193 -0
  82. package/dist/bundle/chunks/{easter-egg-3d-BUEOC3NO.js → easter-egg-3d-VVUF3C3X.js} +1 -1
  83. package/dist/bundle/chunks/entry-2GZ3PTWQ.js +2 -0
  84. package/dist/bundle/chunks/{entry-A2CSLKHC.js → entry-SRYLSS5P.js} +3 -3
  85. package/dist/bundle/chunks/{event-streams-7YGFEPBZ.js → event-streams-F67JLS6B.js} +1 -1
  86. package/dist/bundle/chunks/{execute-MY5JSEPV.js → execute-I3WGGPWL.js} +2 -2
  87. package/dist/bundle/chunks/{extract-PTGACPGP.js → extract-QHZTEVJP.js} +68 -65
  88. package/dist/bundle/chunks/{flow-implementer-APJFY4YI.js → flow-implementer-QMN3HKE2.js} +8 -9
  89. package/dist/bundle/chunks/github-copilot.js +55 -45
  90. package/dist/bundle/chunks/google-generative-ai-ZND73WDQ.js +22 -0
  91. package/dist/bundle/chunks/google-vertex-YAH62YRM.js +25 -0
  92. package/dist/bundle/chunks/host-Q565BCXB.js +3 -0
  93. package/dist/bundle/chunks/image-resize-worker.js +3 -3
  94. package/dist/bundle/chunks/{index.bundle-THL4EUSU.js → index.bundle-HONF3PUD.js} +177 -176
  95. package/dist/bundle/chunks/{inprocess-5NP5VJHZ.js → inprocess-453SLFL5.js} +6 -6
  96. package/dist/bundle/chunks/interactive-mode-MVZOJ5OU.js +5 -0
  97. package/dist/bundle/chunks/{llama-cpp-classify-GJAXULWL.js → llama-cpp-classify-Z4GZY4GC.js} +1 -1
  98. package/dist/bundle/chunks/mistral-conversations-7I5JURDP.js +43 -0
  99. package/dist/bundle/chunks/{node-ZFIIS5IM.js → node-IMSYVRPL.js} +53 -30
  100. package/dist/bundle/chunks/{node-UNHECG4X.js → node-MHHE76P4.js} +475 -440
  101. package/dist/bundle/chunks/{openai-codex-responses-S7CMCAOY.js → openai-codex-responses-LTHOMN37.js} +30 -29
  102. package/dist/bundle/chunks/openai-codex.js +9 -8
  103. package/dist/bundle/chunks/{openai-completions-2Z57N7PC.js → openai-completions-W2X635EE.js} +22 -22
  104. package/dist/bundle/chunks/{openai-decisions-JIOJDB4C.js → openai-decisions-TN2GNOYI.js} +1 -1
  105. package/dist/bundle/chunks/{openai-responses-5VBZSTHL.js → openai-responses-DVY4QXOG.js} +4 -5
  106. package/dist/bundle/chunks/{openrouter-images-S6O7DBEJ.js → openrouter-images-SE2JMS44.js} +1 -1
  107. package/dist/bundle/chunks/openrouter.js +9 -8
  108. package/dist/bundle/chunks/pdfjs-FE3L72A6.js +3662 -0
  109. package/dist/bundle/chunks/{pdfjs-decoders-OFXX4HDZ.js → pdfjs-decoders-VCMCTQJ2.js} +1 -1
  110. package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-I4K6AIV4.js +295 -0
  111. package/dist/bundle/chunks/pdfjs-openjpeg-PYQCV6CM.js +590 -0
  112. package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-G363SGDI.js +775 -0
  113. package/dist/bundle/chunks/{pi-messages-SMLN5J2W.js → pi-messages-WAS6Z5L5.js} +11 -11
  114. package/dist/bundle/chunks/radius.js +8 -7
  115. package/dist/bundle/chunks/{runtime-OYTWXIUM.js → runtime-H7LYNKCZ.js} +1 -1
  116. package/dist/bundle/chunks/session-picker-XNVLSJ22.js +4 -0
  117. package/dist/bundle/chunks/startup-ui-3TCT465D.js +3 -0
  118. package/dist/bundle/chunks/{trace-command-YLDYCL55.js → trace-command-7ORDQ3JS.js} +4 -4
  119. package/dist/bundle/chunks/{typesafe-system-one-7BEL3H5N.js → typesafe-system-one-AAZH6S3I.js} +1 -1
  120. package/dist/bundle/chunks/{undici-C6S56CGI.js → undici-WVNE45GY.js} +1 -1
  121. package/dist/bundle/chunks/virtual-modules-CIVXCEAN.js +28 -0
  122. package/dist/bundle/cli-runtime.js +5 -5
  123. package/dist/bundle/flow/package.json +5 -5
  124. package/dist/bundle/index.js +13 -13
  125. package/dist/bundle/orchestrate/package.json +22 -6
  126. package/dist/bundle/rpc-entry.js +4 -5
  127. package/dist/cli/args.d.ts.map +1 -1
  128. package/dist/cli/args.js +4 -3
  129. package/dist/cli/args.js.map +1 -1
  130. package/dist/cli/config-selector.d.ts.map +1 -1
  131. package/dist/cli/config-selector.js +9 -6
  132. package/dist/cli/config-selector.js.map +1 -1
  133. package/dist/cli/session-picker.d.ts.map +1 -1
  134. package/dist/cli/session-picker.js +9 -6
  135. package/dist/cli/session-picker.js.map +1 -1
  136. package/dist/cli/startup-ui.d.ts.map +1 -1
  137. package/dist/cli/startup-ui.js +8 -4
  138. package/dist/cli/startup-ui.js.map +1 -1
  139. package/dist/cli.js.map +1 -1
  140. package/dist/core/agent-session-runtime.d.ts +11 -0
  141. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  142. package/dist/core/agent-session-runtime.js +19 -0
  143. package/dist/core/agent-session-runtime.js.map +1 -1
  144. package/dist/core/agent-session-services.d.ts +0 -2
  145. package/dist/core/agent-session-services.d.ts.map +1 -1
  146. package/dist/core/agent-session-services.js +0 -2
  147. package/dist/core/agent-session-services.js.map +1 -1
  148. package/dist/core/agent-session.d.ts +31 -39
  149. package/dist/core/agent-session.d.ts.map +1 -1
  150. package/dist/core/agent-session.js +231 -535
  151. package/dist/core/agent-session.js.map +1 -1
  152. package/dist/core/anthropic-subscription-usage.d.ts +4 -2
  153. package/dist/core/anthropic-subscription-usage.d.ts.map +1 -1
  154. package/dist/core/anthropic-subscription-usage.js +32 -16
  155. package/dist/core/anthropic-subscription-usage.js.map +1 -1
  156. package/dist/core/auto-session-namer.js +1 -1
  157. package/dist/core/auto-session-namer.js.map +1 -1
  158. package/dist/core/cache-warmer.d.ts.map +1 -1
  159. package/dist/core/cache-warmer.js +2 -0
  160. package/dist/core/cache-warmer.js.map +1 -1
  161. package/dist/core/exec.d.ts +1 -0
  162. package/dist/core/exec.d.ts.map +1 -1
  163. package/dist/core/exec.js +4 -1
  164. package/dist/core/exec.js.map +1 -1
  165. package/dist/core/export-html/ansi-to-html.d.ts +6 -1
  166. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  167. package/dist/core/export-html/ansi-to-html.js +57 -20
  168. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  169. package/dist/core/export-html/template.js +1 -1
  170. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  171. package/dist/core/export-html/tool-renderer.js +2 -3
  172. package/dist/core/export-html/tool-renderer.js.map +1 -1
  173. package/dist/core/extensions/loader.d.ts.map +1 -1
  174. package/dist/core/extensions/loader.js +18 -1
  175. package/dist/core/extensions/loader.js.map +1 -1
  176. package/dist/core/extensions/runner.d.ts.map +1 -1
  177. package/dist/core/extensions/runner.js +5 -0
  178. package/dist/core/extensions/runner.js.map +1 -1
  179. package/dist/core/extensions/types.d.ts +5 -0
  180. package/dist/core/extensions/types.d.ts.map +1 -1
  181. package/dist/core/extensions/types.js.map +1 -1
  182. package/dist/core/flow-implementer.d.ts.map +1 -1
  183. package/dist/core/flow-implementer.js +3 -9
  184. package/dist/core/flow-implementer.js.map +1 -1
  185. package/dist/core/keybindings.d.ts +40 -0
  186. package/dist/core/keybindings.d.ts.map +1 -1
  187. package/dist/core/keybindings.js +5 -0
  188. package/dist/core/keybindings.js.map +1 -1
  189. package/dist/core/model-config.d.ts +13 -0
  190. package/dist/core/model-config.d.ts.map +1 -1
  191. package/dist/core/model-registry.d.ts +3 -0
  192. package/dist/core/model-registry.d.ts.map +1 -1
  193. package/dist/core/model-registry.js +32 -8
  194. package/dist/core/model-registry.js.map +1 -1
  195. package/dist/core/model-resolver.d.ts +0 -1
  196. package/dist/core/model-resolver.d.ts.map +1 -1
  197. package/dist/core/model-resolver.js +3 -10
  198. package/dist/core/model-resolver.js.map +1 -1
  199. package/dist/core/model-runtime.d.ts +18 -7
  200. package/dist/core/model-runtime.d.ts.map +1 -1
  201. package/dist/core/model-runtime.js +41 -8
  202. package/dist/core/model-runtime.js.map +1 -1
  203. package/dist/core/oauth-account-pool.d.ts +5 -0
  204. package/dist/core/oauth-account-pool.d.ts.map +1 -1
  205. package/dist/core/oauth-account-pool.js +34 -3
  206. package/dist/core/oauth-account-pool.js.map +1 -1
  207. package/dist/core/package-manager.d.ts +16 -0
  208. package/dist/core/package-manager.d.ts.map +1 -1
  209. package/dist/core/package-manager.js +46 -3
  210. package/dist/core/package-manager.js.map +1 -1
  211. package/dist/core/pi-ai-schemas.d.ts +1 -0
  212. package/dist/core/pi-ai-schemas.d.ts.map +1 -1
  213. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  214. package/dist/core/remote-catalog-provider.js +7 -0
  215. package/dist/core/remote-catalog-provider.js.map +1 -1
  216. package/dist/core/resource-loader.d.ts +5 -1
  217. package/dist/core/resource-loader.d.ts.map +1 -1
  218. package/dist/core/resource-loader.js +2 -0
  219. package/dist/core/resource-loader.js.map +1 -1
  220. package/dist/core/run-outcome.d.ts +6 -3
  221. package/dist/core/run-outcome.d.ts.map +1 -1
  222. package/dist/core/run-outcome.js +36 -9
  223. package/dist/core/run-outcome.js.map +1 -1
  224. package/dist/core/run-preflight.d.ts +1 -1
  225. package/dist/core/run-preflight.d.ts.map +1 -1
  226. package/dist/core/run-preflight.js +19 -11
  227. package/dist/core/run-preflight.js.map +1 -1
  228. package/dist/core/sdk.d.ts +0 -6
  229. package/dist/core/sdk.d.ts.map +1 -1
  230. package/dist/core/sdk.js +7 -16
  231. package/dist/core/sdk.js.map +1 -1
  232. package/dist/core/settings-manager.d.ts +0 -5
  233. package/dist/core/settings-manager.d.ts.map +1 -1
  234. package/dist/core/settings-manager.js +0 -9
  235. package/dist/core/settings-manager.js.map +1 -1
  236. package/dist/core/settings-schema.d.ts +0 -4
  237. package/dist/core/settings-schema.d.ts.map +1 -1
  238. package/dist/core/settings-schema.js +0 -1
  239. package/dist/core/settings-schema.js.map +1 -1
  240. package/dist/core/tools/bash-jobs.d.ts.map +1 -1
  241. package/dist/core/tools/bash-jobs.js +2 -9
  242. package/dist/core/tools/bash-jobs.js.map +1 -1
  243. package/dist/core/tools/find.d.ts.map +1 -1
  244. package/dist/core/tools/find.js +28 -16
  245. package/dist/core/tools/find.js.map +1 -1
  246. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  247. package/dist/core/tools/output-accumulator.js +4 -1
  248. package/dist/core/tools/output-accumulator.js.map +1 -1
  249. package/dist/core/tools/read.d.ts +8 -4
  250. package/dist/core/tools/read.d.ts.map +1 -1
  251. package/dist/core/tools/read.js +10 -15
  252. package/dist/core/tools/read.js.map +1 -1
  253. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  254. package/dist/core/tools/renderers/read.js +6 -2
  255. package/dist/core/tools/renderers/read.js.map +1 -1
  256. package/dist/core/tools/subagent-worktree.d.ts.map +1 -1
  257. package/dist/core/tools/subagent-worktree.js +2 -10
  258. package/dist/core/tools/subagent-worktree.js.map +1 -1
  259. package/dist/core/trace-client/credential-store.d.ts.map +1 -1
  260. package/dist/core/trace-client/credential-store.js +9 -5
  261. package/dist/core/trace-client/credential-store.js.map +1 -1
  262. package/dist/extensions/codemode/execute.js +2 -2
  263. package/dist/extensions/codemode/execute.js.map +1 -1
  264. package/dist/extensions/llama/provider.d.ts +1 -1
  265. package/dist/extensions/llama/provider.d.ts.map +1 -1
  266. package/dist/extensions/llama/provider.js +6 -4
  267. package/dist/extensions/llama/provider.js.map +1 -1
  268. package/dist/extensions/usage/account-reconnect.d.ts +5 -0
  269. package/dist/extensions/usage/account-reconnect.d.ts.map +1 -0
  270. package/dist/extensions/usage/account-reconnect.js +12 -0
  271. package/dist/extensions/usage/account-reconnect.js.map +1 -0
  272. package/dist/extensions/usage/hcode-overview.d.ts +6 -19
  273. package/dist/extensions/usage/hcode-overview.d.ts.map +1 -1
  274. package/dist/extensions/usage/hcode-overview.js +86 -100
  275. package/dist/extensions/usage/hcode-overview.js.map +1 -1
  276. package/dist/extensions/usage/index.d.ts.map +1 -1
  277. package/dist/extensions/usage/index.js +74 -98
  278. package/dist/extensions/usage/index.js.map +1 -1
  279. package/dist/extensions/usage/overview.d.ts +22 -17
  280. package/dist/extensions/usage/overview.d.ts.map +1 -1
  281. package/dist/extensions/usage/overview.js +98 -13
  282. package/dist/extensions/usage/overview.js.map +1 -1
  283. package/dist/extensions/usage/popup.d.ts +9 -14
  284. package/dist/extensions/usage/popup.d.ts.map +1 -1
  285. package/dist/extensions/usage/popup.js +78 -165
  286. package/dist/extensions/usage/popup.js.map +1 -1
  287. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +4 -1
  288. package/dist/humain/flow-command.js +1 -1
  289. package/dist/humain/flow-command.js.map +1 -1
  290. package/dist/humain/flow-loader.d.ts +9 -4
  291. package/dist/humain/flow-loader.d.ts.map +1 -1
  292. package/dist/humain/flow-loader.js +30 -21
  293. package/dist/humain/flow-loader.js.map +1 -1
  294. package/dist/humain/gateway/client.d.ts +3 -1
  295. package/dist/humain/gateway/client.d.ts.map +1 -1
  296. package/dist/humain/gateway/client.js +10 -5
  297. package/dist/humain/gateway/client.js.map +1 -1
  298. package/dist/humain/gateway/login.d.ts.map +1 -1
  299. package/dist/humain/gateway/login.js +160 -53
  300. package/dist/humain/gateway/login.js.map +1 -1
  301. package/dist/humain/hcode/account-store.d.ts +29 -5
  302. package/dist/humain/hcode/account-store.d.ts.map +1 -1
  303. package/dist/humain/hcode/account-store.js +224 -124
  304. package/dist/humain/hcode/account-store.js.map +1 -1
  305. package/dist/humain/hcode/account.d.ts +6 -0
  306. package/dist/humain/hcode/account.d.ts.map +1 -1
  307. package/dist/humain/hcode/account.js +348 -129
  308. package/dist/humain/hcode/account.js.map +1 -1
  309. package/dist/humain/hcode/catalog-watch.d.ts +21 -0
  310. package/dist/humain/hcode/catalog-watch.d.ts.map +1 -0
  311. package/dist/humain/hcode/catalog-watch.js +46 -0
  312. package/dist/humain/hcode/catalog-watch.js.map +1 -0
  313. package/dist/humain/hcode/contracts.d.ts +16 -1
  314. package/dist/humain/hcode/contracts.d.ts.map +1 -1
  315. package/dist/humain/hcode/contracts.js +122 -128
  316. package/dist/humain/hcode/contracts.js.map +1 -1
  317. package/dist/humain/hcode/environment.d.ts +3 -1
  318. package/dist/humain/hcode/environment.d.ts.map +1 -1
  319. package/dist/humain/hcode/environment.js +12 -2
  320. package/dist/humain/hcode/environment.js.map +1 -1
  321. package/dist/humain/hcode/facade.d.ts +26 -6
  322. package/dist/humain/hcode/facade.d.ts.map +1 -1
  323. package/dist/humain/hcode/facade.js +148 -38
  324. package/dist/humain/hcode/facade.js.map +1 -1
  325. package/dist/humain/hcode/http.d.ts +3 -1
  326. package/dist/humain/hcode/http.d.ts.map +1 -1
  327. package/dist/humain/hcode/http.js +44 -23
  328. package/dist/humain/hcode/http.js.map +1 -1
  329. package/dist/humain/hcode/images.d.ts +67 -0
  330. package/dist/humain/hcode/images.d.ts.map +1 -0
  331. package/dist/humain/hcode/images.js +463 -0
  332. package/dist/humain/hcode/images.js.map +1 -0
  333. package/dist/humain/hcode/login-copy.d.ts +28 -0
  334. package/dist/humain/hcode/login-copy.d.ts.map +1 -0
  335. package/dist/humain/hcode/login-copy.js +74 -0
  336. package/dist/humain/hcode/login-copy.js.map +1 -0
  337. package/dist/humain/hcode/login-failure.d.ts +26 -0
  338. package/dist/humain/hcode/login-failure.d.ts.map +1 -0
  339. package/dist/humain/hcode/login-failure.js +50 -0
  340. package/dist/humain/hcode/login-failure.js.map +1 -0
  341. package/dist/humain/hcode/notices.d.ts +24 -1
  342. package/dist/humain/hcode/notices.d.ts.map +1 -1
  343. package/dist/humain/hcode/notices.js +93 -7
  344. package/dist/humain/hcode/notices.js.map +1 -1
  345. package/dist/humain/hcode/provider.d.ts +7 -3
  346. package/dist/humain/hcode/provider.d.ts.map +1 -1
  347. package/dist/humain/hcode/provider.js +123 -19
  348. package/dist/humain/hcode/provider.js.map +1 -1
  349. package/dist/humain/hcode/selection.d.ts +2 -0
  350. package/dist/humain/hcode/selection.d.ts.map +1 -1
  351. package/dist/humain/hcode/selection.js +8 -1
  352. package/dist/humain/hcode/selection.js.map +1 -1
  353. package/dist/humain/hcode/transport.d.ts +13 -10
  354. package/dist/humain/hcode/transport.d.ts.map +1 -1
  355. package/dist/humain/hcode/transport.js +103 -148
  356. package/dist/humain/hcode/transport.js.map +1 -1
  357. package/dist/humain/hcode/wire.d.ts +3 -0
  358. package/dist/humain/hcode/wire.d.ts.map +1 -1
  359. package/dist/humain/hcode/wire.js +11 -0
  360. package/dist/humain/hcode/wire.js.map +1 -1
  361. package/dist/humain/metadata/contracts.d.ts +1 -0
  362. package/dist/humain/metadata/contracts.d.ts.map +1 -1
  363. package/dist/humain/metadata/contracts.js +2 -1
  364. package/dist/humain/metadata/contracts.js.map +1 -1
  365. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
  366. package/dist/humain/web-access/vendor/anysearch.js +7 -3
  367. package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
  368. package/dist/humain/web-access/vendor/autom.d.ts +4 -0
  369. package/dist/humain/web-access/vendor/autom.d.ts.map +1 -0
  370. package/dist/humain/web-access/vendor/autom.js +191 -0
  371. package/dist/humain/web-access/vendor/autom.js.map +1 -0
  372. package/dist/humain/web-access/vendor/cloro.d.ts +4 -0
  373. package/dist/humain/web-access/vendor/cloro.d.ts.map +1 -0
  374. package/dist/humain/web-access/vendor/cloro.js +236 -0
  375. package/dist/humain/web-access/vendor/cloro.js.map +1 -0
  376. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  377. package/dist/humain/web-access/vendor/curator-page.js +7 -1
  378. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  379. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  380. package/dist/humain/web-access/vendor/curator-server.js +6 -0
  381. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  382. package/dist/humain/web-access/vendor/domain-filter-normalization.d.ts +8 -0
  383. package/dist/humain/web-access/vendor/domain-filter-normalization.d.ts.map +1 -1
  384. package/dist/humain/web-access/vendor/domain-filter-normalization.js +37 -0
  385. package/dist/humain/web-access/vendor/domain-filter-normalization.js.map +1 -1
  386. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts +28 -8
  387. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts.map +1 -1
  388. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js +135 -34
  389. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js.map +1 -1
  390. package/dist/humain/web-access/vendor/duckduckgo.d.ts +1 -1
  391. package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
  392. package/dist/humain/web-access/vendor/duckduckgo.js +10 -3
  393. package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
  394. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  395. package/dist/humain/web-access/vendor/extract.js +61 -5
  396. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  397. package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
  398. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  399. package/dist/humain/web-access/vendor/gemini-search.js +35 -5
  400. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  401. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  402. package/dist/humain/web-access/vendor/index.js +8 -1
  403. package/dist/humain/web-access/vendor/index.js.map +1 -1
  404. package/dist/humain/web-access/vendor/page-query.d.ts +5 -0
  405. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  406. package/dist/humain/web-access/vendor/page-query.js +12 -2
  407. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  408. package/dist/humain/web-access/vendor/specstream.d.ts +6 -0
  409. package/dist/humain/web-access/vendor/specstream.d.ts.map +1 -0
  410. package/dist/humain/web-access/vendor/specstream.js +253 -0
  411. package/dist/humain/web-access/vendor/specstream.js.map +1 -0
  412. package/dist/humain/web-access/vendor/tool-activation.d.ts.map +1 -1
  413. package/dist/humain/web-access/vendor/tool-activation.js +21 -5
  414. package/dist/humain/web-access/vendor/tool-activation.js.map +1 -1
  415. package/dist/humain/web-access/vendor/upgrade-notice.d.ts +1 -1
  416. package/dist/humain/web-access/vendor/upgrade-notice.js +1 -1
  417. package/dist/humain/web-access/vendor/upgrade-notice.js.map +1 -1
  418. package/dist/humain/web-access/vendor/utils.d.ts +1 -0
  419. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  420. package/dist/humain/web-access/vendor/utils.js +3 -0
  421. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  422. package/dist/humain/web-access/vendor/video-extract.js +2 -2
  423. package/dist/humain/web-access/vendor/video-extract.js.map +1 -1
  424. package/dist/humain/web-access/vendor/web-tool-core.d.ts +13 -0
  425. package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
  426. package/dist/humain/web-access/vendor/web-tool-core.js +16 -5
  427. package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
  428. package/dist/humain/web-access/vendor/youtube-extract.js +2 -2
  429. package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -1
  430. package/dist/index.d.ts +0 -2
  431. package/dist/index.d.ts.map +1 -1
  432. package/dist/index.js.map +1 -1
  433. package/dist/main.d.ts.map +1 -1
  434. package/dist/main.js +96 -28
  435. package/dist/main.js.map +1 -1
  436. package/dist/modes/diagnostics-stderr.d.ts +4 -0
  437. package/dist/modes/diagnostics-stderr.d.ts.map +1 -0
  438. package/dist/modes/diagnostics-stderr.js +11 -0
  439. package/dist/modes/diagnostics-stderr.js.map +1 -0
  440. package/dist/modes/interactive/components/assistant-message.d.ts +1 -1
  441. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  442. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  443. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  444. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  445. package/dist/modes/interactive/components/config-selector.js +5 -2
  446. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  447. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  448. package/dist/modes/interactive/components/extension-selector.js +14 -5
  449. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  450. package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
  451. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  452. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  453. package/dist/modes/interactive/components/keybinding-hints.d.ts +2 -0
  454. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  455. package/dist/modes/interactive/components/keybinding-hints.js +6 -0
  456. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  457. package/dist/modes/interactive/components/model-selector.d.ts +10 -0
  458. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  459. package/dist/modes/interactive/components/model-selector.js +101 -23
  460. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  461. package/dist/modes/interactive/components/oauth-selector.d.ts +5 -0
  462. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  463. package/dist/modes/interactive/components/oauth-selector.js +17 -6
  464. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  465. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
  466. package/dist/modes/interactive/components/radius-login-selector.js +2 -1
  467. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
  468. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  469. package/dist/modes/interactive/components/scoped-models-selector.js +13 -6
  470. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  471. package/dist/modes/interactive/components/session-selector.d.ts +8 -1
  472. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  473. package/dist/modes/interactive/components/session-selector.js +41 -9
  474. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  475. package/dist/modes/interactive/components/settings-submenu.d.ts +1 -1
  476. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  477. package/dist/modes/interactive/components/settings-submenu.js +5 -1
  478. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  479. package/dist/modes/interactive/components/status-indicator.d.ts +0 -17
  480. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  481. package/dist/modes/interactive/components/status-indicator.js +1 -78
  482. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  483. package/dist/modes/interactive/components/themed-text.d.ts +1 -1
  484. package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
  485. package/dist/modes/interactive/components/themed-text.js.map +1 -1
  486. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  487. package/dist/modes/interactive/components/thinking-selector.js +5 -1
  488. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  489. package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  490. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  491. package/dist/modes/interactive/components/tool-execution.js +3 -1
  492. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  493. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  494. package/dist/modes/interactive/components/trust-selector.js +14 -5
  495. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  496. package/dist/modes/interactive/components/user-message.d.ts +1 -1
  497. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  498. package/dist/modes/interactive/components/user-message.js.map +1 -1
  499. package/dist/modes/interactive/components/visual-truncate.d.ts +2 -2
  500. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  501. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  502. package/dist/modes/interactive/interactive-mode.d.ts +20 -2
  503. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  504. package/dist/modes/interactive/interactive-mode.js +605 -223
  505. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  506. package/dist/modes/interactive/model-catalog-refresh.d.ts +4 -0
  507. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -1
  508. package/dist/modes/interactive/model-catalog-refresh.js +40 -1
  509. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -1
  510. package/dist/modes/interactive/oauth-account-format.d.ts +6 -2
  511. package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
  512. package/dist/modes/interactive/oauth-account-format.js +12 -3
  513. package/dist/modes/interactive/oauth-account-format.js.map +1 -1
  514. package/dist/modes/interactive/session-share.js +2 -0
  515. package/dist/modes/interactive/session-share.js.map +1 -1
  516. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  517. package/dist/modes/interactive/theme/theme.js +1 -0
  518. package/dist/modes/interactive/theme/theme.js.map +1 -1
  519. package/dist/modes/print-mode.d.ts.map +1 -1
  520. package/dist/modes/print-mode.js +30 -32
  521. package/dist/modes/print-mode.js.map +1 -1
  522. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  523. package/dist/modes/rpc/rpc-mode.js +26 -39
  524. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  525. package/dist/modes/rpc/rpc-types.d.ts +1 -0
  526. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  527. package/dist/modes/rpc/rpc-types.js.map +1 -1
  528. package/dist/package-manager-cli.d.ts.map +1 -1
  529. package/dist/package-manager-cli.js +14 -1
  530. package/dist/package-manager-cli.js.map +1 -1
  531. package/dist/utils/abort.d.ts +5 -0
  532. package/dist/utils/abort.d.ts.map +1 -1
  533. package/dist/utils/abort.js +9 -0
  534. package/dist/utils/abort.js.map +1 -1
  535. package/dist/utils/changelog.d.ts.map +1 -1
  536. package/dist/utils/changelog.js +3 -2
  537. package/dist/utils/changelog.js.map +1 -1
  538. package/dist/utils/flush-stdout.d.ts +8 -0
  539. package/dist/utils/flush-stdout.d.ts.map +1 -0
  540. package/dist/utils/flush-stdout.js +23 -0
  541. package/dist/utils/flush-stdout.js.map +1 -0
  542. package/dist/utils/image-process.d.ts +2 -0
  543. package/dist/utils/image-process.d.ts.map +1 -1
  544. package/dist/utils/image-process.js +3 -3
  545. package/dist/utils/image-process.js.map +1 -1
  546. package/dist/utils/image-resize-core.js +2 -2
  547. package/dist/utils/image-resize-core.js.map +1 -1
  548. package/dist/utils/shell.d.ts +2 -0
  549. package/dist/utils/shell.d.ts.map +1 -1
  550. package/dist/utils/shell.js +19 -0
  551. package/dist/utils/shell.js.map +1 -1
  552. package/docs/cli.md +1 -1
  553. package/docs/development.md +0 -13
  554. package/docs/extensions.md +6 -4
  555. package/docs/flow.md +4 -62
  556. package/docs/humain-code-forge-architecture.md +1 -47
  557. package/docs/humain-code-forge-flow-walkthrough.md +1 -1
  558. package/docs/humain-code.md +1 -1
  559. package/docs/keybindings.md +2 -0
  560. package/docs/llama-cpp.md +5 -5
  561. package/docs/models-configuration.md +4 -2
  562. package/docs/nvidia-rtx-llama-cpp.md +5 -5
  563. package/docs/providers.md +14 -9
  564. package/docs/rpc-commands.md +1 -1
  565. package/docs/run-preflight.md +1 -1
  566. package/docs/slash-commands.md +1 -1
  567. package/docs/tui.md +2 -0
  568. package/examples/README.md +0 -3
  569. package/examples/extensions/custom-provider-anthropic/package-lock.json +4 -4
  570. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  571. package/examples/extensions/gondolin/index.ts +4 -7
  572. package/examples/tsconfig.json +96 -76
  573. package/npm-shrinkwrap.json +285 -764
  574. package/package.json +24 -37
  575. package/schemas/keybindings.schema.json +20 -0
  576. package/schemas/models.schema.json +5 -1
  577. package/schemas/settings.schema.json +0 -13
  578. package/src/humain/web-access/UPSTREAM.md +52 -1
  579. package/src/humain/web-access/upstream.json +5 -5
  580. package/src/humain/web-access/vendor/CHANGELOG.md +29 -0
  581. package/dist/bundle/chunks/adaptive-peer-worker-X2ZNZE3S.js +0 -8
  582. package/dist/bundle/chunks/adaptive-session-host-7KDSQV5I.js +0 -162
  583. package/dist/bundle/chunks/anthropic-messages-TQK3FUV3.js +0 -68
  584. package/dist/bundle/chunks/azure-openai-responses-JY7OSLH2.js +0 -15
  585. package/dist/bundle/chunks/chunk-5L4PBYC7.js +0 -11
  586. package/dist/bundle/chunks/chunk-6PNQYO6A.js +0 -10
  587. package/dist/bundle/chunks/chunk-CRN54O4D.js +0 -24
  588. package/dist/bundle/chunks/chunk-CTU2ECLD.js +0 -7
  589. package/dist/bundle/chunks/chunk-DBL35X7L.js +0 -3
  590. package/dist/bundle/chunks/chunk-GME4AWDG.js +0 -23
  591. package/dist/bundle/chunks/chunk-GTILMMUF.js +0 -12
  592. package/dist/bundle/chunks/chunk-J57HOSWD.js +0 -21
  593. package/dist/bundle/chunks/chunk-KQM7ZGL6.js +0 -11
  594. package/dist/bundle/chunks/chunk-MX4Q4W6H.js +0 -214
  595. package/dist/bundle/chunks/chunk-NXA6NEHE.js +0 -54
  596. package/dist/bundle/chunks/chunk-PJACZCIR.js +0 -2
  597. package/dist/bundle/chunks/chunk-T5A6T24H.js +0 -93
  598. package/dist/bundle/chunks/chunk-WCFHG6NO.js +0 -16
  599. package/dist/bundle/chunks/chunk-ZJUU6WOV.js +0 -2052
  600. package/dist/bundle/chunks/compat-ZK2DIW3P.js +0 -15
  601. package/dist/bundle/chunks/dist-EY7YKQHB.js +0 -11
  602. package/dist/bundle/chunks/dist-J5IUPLMH.js +0 -37
  603. package/dist/bundle/chunks/dist-cjs-2SKN226B.js +0 -184
  604. package/dist/bundle/chunks/entry-AL54ZGYO.js +0 -2
  605. package/dist/bundle/chunks/es5-GYTRHFKS.js +0 -77
  606. package/dist/bundle/chunks/google-generative-ai-UL7YEQ6J.js +0 -21
  607. package/dist/bundle/chunks/google-vertex-OTMSPUYH.js +0 -26
  608. package/dist/bundle/chunks/host-75YAHLDR.js +0 -3
  609. package/dist/bundle/chunks/interactive-mode-IW4PIVAQ.js +0 -5
  610. package/dist/bundle/chunks/mistral-conversations-E72Y6OC3.js +0 -43
  611. package/dist/bundle/chunks/pdfjs-AKD6EBKN.js +0 -3614
  612. package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-FH3KJM4H.js +0 -326
  613. package/dist/bundle/chunks/pdfjs-openjpeg-SKR7C34X.js +0 -671
  614. package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-VUBL7UEE.js +0 -974
  615. package/dist/bundle/chunks/session-picker-DM6S37IF.js +0 -4
  616. package/dist/bundle/chunks/startup-ui-4GGLWNSU.js +0 -3
  617. package/dist/bundle/chunks/virtual-modules-TI3W24YL.js +0 -28
  618. package/dist/core/internal-process.d.ts +0 -23
  619. package/dist/core/internal-process.d.ts.map +0 -1
  620. package/dist/core/internal-process.js +0 -88
  621. package/dist/core/internal-process.js.map +0 -1
  622. package/dist/humain/adaptive-execution.d.ts +0 -51
  623. package/dist/humain/adaptive-execution.d.ts.map +0 -1
  624. package/dist/humain/adaptive-execution.js +0 -100
  625. package/dist/humain/adaptive-execution.js.map +0 -1
  626. package/dist/humain/adaptive-peer-process.d.ts +0 -44
  627. package/dist/humain/adaptive-peer-process.d.ts.map +0 -1
  628. package/dist/humain/adaptive-peer-process.js +0 -159
  629. package/dist/humain/adaptive-peer-process.js.map +0 -1
  630. package/dist/humain/adaptive-peer-worker.d.ts +0 -3
  631. package/dist/humain/adaptive-peer-worker.d.ts.map +0 -1
  632. package/dist/humain/adaptive-peer-worker.js +0 -122
  633. package/dist/humain/adaptive-peer-worker.js.map +0 -1
  634. package/dist/humain/adaptive-runtime-types.d.ts +0 -621
  635. package/dist/humain/adaptive-runtime-types.d.ts.map +0 -1
  636. package/dist/humain/adaptive-runtime-types.js +0 -3
  637. package/dist/humain/adaptive-runtime-types.js.map +0 -1
  638. package/dist/humain/adaptive-session-host.d.ts +0 -113
  639. package/dist/humain/adaptive-session-host.d.ts.map +0 -1
  640. package/dist/humain/adaptive-session-host.js +0 -1838
  641. package/dist/humain/adaptive-session-host.js.map +0 -1
  642. package/dist/utils/deprecation.d.ts +0 -4
  643. package/dist/utils/deprecation.d.ts.map +0 -1
  644. package/dist/utils/deprecation.js +0 -13
  645. package/dist/utils/deprecation.js.map +0 -1
  646. package/examples/plugins/pi-example-plugin/README.md +0 -38
  647. package/examples/plugins/pi-example-plugin/package.json +0 -10
  648. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  649. package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
  650. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
@@ -1,15 +1,22 @@
1
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
1
3
  import { awaitWithAbort } from "./abortable.js";
2
4
  import { defaultSleep, formatWait } from "./brave-rate-limit.js";
3
5
  // DuckDuckGo has no API quota, but it shows its bot check to the whole client IP
4
- // (browsers included) when requests arrive in bursts, and keeps it up for 10-15
5
- // minutes, longer after repeated blocks. Requests spaced about 2s apart pass. So
6
- // searches run one at a time with a minimum gap, and after a bot check this process
7
- // stops asking for a while instead of retrying, since retries only keep the block in
8
- // place.
9
- const DEFAULT_MIN_INTERVAL_MS = 2_000;
10
- const DEFAULT_COOLDOWN_MS = 5 * 60_000;
11
- const DEFAULT_MAX_COOLDOWN_MS = 60 * 60_000;
6
+ // (browsers included) once too many requests come from it, and keeps it up for 7 to 30
7
+ // minutes. Changing the User-Agent, TLS fingerprint or endpoint does not help. Tests from
8
+ // one home IP: 2s apart was blocked after 3 to 34 searches, 5s apart after 22 searches in
9
+ // 10 minutes, 10s apart back to back after 47 searches; 10s apart with at most 10 per 10
10
+ // minutes ran 60 searches in 54 minutes from three processes sharing one budget with no
11
+ // bot check. A retry soon after a block brings it back, hence the long, doubling pause.
12
+ const DEFAULT_MIN_INTERVAL_MS = 10_000;
13
+ const DEFAULT_WINDOW_MS = 10 * 60_000;
14
+ const DEFAULT_MAX_STARTS = 10;
15
+ const DEFAULT_COOLDOWN_MS = 30 * 60_000;
16
+ const DEFAULT_MAX_COOLDOWN_MS = 2 * 60 * 60_000;
12
17
  const DEFAULT_TIMEOUT_MS = 30_000;
18
+ /** Part of the deadline kept for the request itself; a search that would start later fails at once. */
19
+ const REQUEST_ALLOWANCE_MS = 10_000;
13
20
  export class DuckDuckGoBotCheckError extends Error {
14
21
  constructor(status) {
15
22
  // "rate limited" makes search routing classify this as quota.
@@ -17,68 +24,162 @@ export class DuckDuckGoBotCheckError extends Error {
17
24
  this.name = "DuckDuckGoBotCheckError";
18
25
  }
19
26
  }
27
+ function cooldownError(remainingMs) {
28
+ return new Error(`DuckDuckGo showed a bot check recently; not retrying for ${formatWait(remainingMs)} so the block can clear (rate limited); use another search provider`);
29
+ }
20
30
  export class DuckDuckGoRateLimit {
21
31
  queue = Promise.resolve();
22
- lastStart = Number.NEGATIVE_INFINITY;
23
- blockedUntil = 0;
24
- nextCooldownMs;
32
+ /** Searches queued that have not started yet. */
33
+ waiting = 0;
34
+ /** Actual start times of the latest `maxStarts` searches, oldest first. */
35
+ starts = [];
36
+ cooldown;
25
37
  now;
26
38
  sleep;
27
39
  minIntervalMs;
40
+ windowMs;
41
+ maxStarts;
28
42
  cooldownMs;
29
43
  maxCooldownMs;
30
44
  timeoutMs;
45
+ statePath;
31
46
  constructor(options = {}) {
32
47
  this.now = options.now ?? Date.now;
33
48
  this.sleep = options.sleep ?? defaultSleep;
34
49
  this.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;
50
+ this.windowMs = options.windowMs ?? DEFAULT_WINDOW_MS;
51
+ this.maxStarts = Math.max(1, options.maxStarts ?? DEFAULT_MAX_STARTS);
35
52
  this.cooldownMs = options.cooldownMs ?? DEFAULT_COOLDOWN_MS;
36
53
  this.maxCooldownMs = options.maxCooldownMs ?? DEFAULT_MAX_COOLDOWN_MS;
37
- this.nextCooldownMs = this.cooldownMs;
38
54
  this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
55
+ this.statePath = options.statePath;
56
+ this.cooldown = { blockedUntil: 0, nextCooldownMs: this.cooldownMs };
39
57
  }
40
58
  /**
41
- * Queues `operation` and passes it a signal that fires on the caller's abort or when
42
- * the deadline passes. A passed deadline rejects with a "timed out" error rather than
43
- * an abort, so search routing treats it as a network failure and can fall back.
59
+ * Queues `operation` behind earlier searches and runs it with a signal that fires on the
60
+ * caller's abort or when the deadline passes. A search that cannot start before its
61
+ * deadline fails at once as rate limited, so routing moves on without waiting. A passed
62
+ * deadline rejects with a "timed out" error rather than an abort, so search routing
63
+ * treats it as a network failure and can fall back.
44
64
  */
45
- run(operation, callerSignal) {
65
+ async run(operation, callerSignal) {
46
66
  if (callerSignal?.aborted)
47
- return Promise.reject(new Error("Aborted"));
67
+ throw new Error("Aborted");
68
+ const now = this.now();
69
+ const latestStart = now + Math.max(0, this.timeoutMs - REQUEST_ALLOWANCE_MS);
70
+ this.throwIfBlocked(now);
71
+ const slot = this.nextSlot(now, this.waiting + 1);
72
+ if (slot > latestStart)
73
+ throw this.busyError(slot - now);
48
74
  const deadline = AbortSignal.timeout(this.timeoutMs);
49
75
  const signal = callerSignal ? AbortSignal.any([deadline, callerSignal]) : deadline;
50
- const scheduled = this.queue.then(() => this.runNow(operation, signal));
51
- this.queue = scheduled.then(() => undefined, () => undefined);
52
- // Let a search give up while still queued without unblocking the queue early.
53
- return awaitWithAbort(scheduled, signal).catch(error => {
76
+ this.waiting++;
77
+ const started = this.queue.then(() => this.waitForSlot(signal, latestStart)).finally(() => { this.waiting--; });
78
+ this.queue = started.then(() => undefined, () => undefined);
79
+ try {
80
+ // Let a search give up while still queued without unblocking the queue early.
81
+ return await awaitWithAbort(started.then(() => this.attempt(operation, signal)), signal);
82
+ }
83
+ catch (error) {
54
84
  if (deadline.aborted && !callerSignal?.aborted) {
55
85
  throw new Error(`DuckDuckGo request timed out after ${formatWait(this.timeoutMs)}`);
56
86
  }
57
87
  throw error;
58
- });
88
+ }
59
89
  }
60
- async runNow(operation, signal) {
61
- if (signal.aborted)
62
- throw new Error("Aborted");
63
- const remainingMs = this.blockedUntil - this.now();
90
+ /** Start time of the `count`th search from now, given the searches already started. */
91
+ nextSlot(now, count) {
92
+ const starts = [...this.starts];
93
+ let slot = now;
94
+ for (let i = 0; i < count; i++) {
95
+ slot = Math.max(now, (starts.at(-1) ?? Number.NEGATIVE_INFINITY) + this.minIntervalMs);
96
+ if (starts.length >= this.maxStarts)
97
+ slot = Math.max(slot, starts[starts.length - this.maxStarts] + this.windowMs);
98
+ starts.push(slot);
99
+ }
100
+ return slot;
101
+ }
102
+ /** Runs at the head of the queue, so spacing is measured from the previous search's actual start. */
103
+ async waitForSlot(signal, latestStart) {
104
+ for (;;) {
105
+ if (signal.aborted)
106
+ throw new Error("Aborted");
107
+ const now = this.now();
108
+ this.throwIfBlocked(now);
109
+ const slot = this.nextSlot(now, 1);
110
+ if (slot <= now) {
111
+ this.starts.push(now);
112
+ if (this.starts.length > this.maxStarts)
113
+ this.starts.shift();
114
+ return;
115
+ }
116
+ if (slot > latestStart)
117
+ throw this.busyError(slot - now);
118
+ await this.sleep(slot - now, signal);
119
+ }
120
+ }
121
+ busyError(waitMs) {
122
+ return new Error(`DuckDuckGo is limited to one search every ${formatWait(this.minIntervalMs)} and ${this.maxStarts} every ${formatWait(this.windowMs)} in this process to avoid its bot check; the next free slot is in ${formatWait(waitMs)} (rate limited); use another search provider`);
123
+ }
124
+ throwIfBlocked(now) {
125
+ this.loadSharedCooldown();
126
+ const remainingMs = this.cooldown.blockedUntil - now;
64
127
  if (remainingMs > 0)
65
- throw new Error(`DuckDuckGo showed a bot check recently; not retrying for ${formatWait(remainingMs)} (rate limited); use another search provider`);
66
- const waitMs = this.lastStart + this.minIntervalMs - this.now();
67
- if (waitMs > 0)
68
- await this.sleep(waitMs, signal);
69
- this.lastStart = this.now();
128
+ throw cooldownError(remainingMs);
129
+ }
130
+ async attempt(operation, signal) {
70
131
  try {
71
132
  const result = await operation(signal);
72
- this.nextCooldownMs = this.cooldownMs;
133
+ this.loadSharedCooldown();
134
+ if (this.cooldown.nextCooldownMs !== this.cooldownMs && this.cooldown.blockedUntil <= this.now()) {
135
+ this.cooldown = { ...this.cooldown, nextCooldownMs: this.cooldownMs };
136
+ this.saveSharedCooldown();
137
+ }
73
138
  return result;
74
139
  }
75
140
  catch (error) {
76
141
  if (error instanceof DuckDuckGoBotCheckError) {
77
- this.blockedUntil = this.now() + this.nextCooldownMs;
78
- this.nextCooldownMs = Math.min(this.nextCooldownMs * 2, this.maxCooldownMs);
142
+ this.loadSharedCooldown();
143
+ const now = this.now();
144
+ // Searches already in flight see the same block; count it once.
145
+ if (this.cooldown.blockedUntil <= now) {
146
+ const pauseMs = this.cooldown.nextCooldownMs;
147
+ this.cooldown = { blockedUntil: now + pauseMs, nextCooldownMs: Math.min(pauseMs * 2, this.maxCooldownMs) };
148
+ this.saveSharedCooldown();
149
+ }
79
150
  }
80
151
  throw error;
81
152
  }
82
153
  }
154
+ // The state file is best effort: if it cannot be read or written, this process keeps
155
+ // its own pause, and a search never fails or loses its result because of the file.
156
+ loadSharedCooldown() {
157
+ if (!this.statePath)
158
+ return;
159
+ try {
160
+ const saved = JSON.parse(readFileSync(this.statePath, "utf8"));
161
+ const { blockedUntil, nextCooldownMs } = saved;
162
+ if (typeof blockedUntil !== "number" || typeof nextCooldownMs !== "number" || !(nextCooldownMs > 0))
163
+ return;
164
+ // A pause longer than the cap comes from a clock that has since moved back, or a damaged file.
165
+ if (!(blockedUntil <= this.now() + this.maxCooldownMs))
166
+ return;
167
+ if (blockedUntil >= this.cooldown.blockedUntil) {
168
+ this.cooldown = { blockedUntil, nextCooldownMs: Math.min(nextCooldownMs, this.maxCooldownMs) };
169
+ }
170
+ }
171
+ catch { }
172
+ }
173
+ saveSharedCooldown() {
174
+ if (!this.statePath)
175
+ return;
176
+ try {
177
+ mkdirSync(dirname(this.statePath), { recursive: true, mode: 0o700 });
178
+ const tmpPath = `${this.statePath}.${process.pid}.tmp`;
179
+ writeFileSync(tmpPath, JSON.stringify(this.cooldown), { mode: 0o600 });
180
+ renameSync(tmpPath, this.statePath);
181
+ }
182
+ catch { }
183
+ }
83
184
  }
84
185
  //# sourceMappingURL=duckduckgo-rate-limit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"duckduckgo-rate-limit.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/duckduckgo-rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEjE,iFAAiF;AACjF,gFAAgF;AAChF,iFAAiF;AACjF,oFAAoF;AACpF,qFAAqF;AACrF,SAAS;AAET,MAAM,uBAAuB,GAAG,KAAK,CAAC;AACtC,MAAM,mBAAmB,GAAG,CAAC,GAAG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AI,CAAC,GAAG,EAAE,CAAC;QAChE,IAAI,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;YACvC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC;YACtC,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,KAAK,YAAY,uBAAuB,EAAE,CAAC;gBAC9C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC;gBACrD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YAC7E,CAAC;YACD,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;CACD","sourcesContent":["import { awaitWithAbort } from \"./abortable.ts\";\nimport { defaultSleep, formatWait } from \"./brave-rate-limit.ts\";\n\n// DuckDuckGo has no API quota, but it shows its bot check to the whole client IP\n// (browsers included) when requests arrive in bursts, and keeps it up for 10-15\n// minutes, longer after repeated blocks. Requests spaced about 2s apart pass. So\n// searches run one at a time with a minimum gap, and after a bot check this process\n// stops asking for a while instead of retrying, since retries only keep the block in\n// place.\n\nconst DEFAULT_MIN_INTERVAL_MS = 2_000;\nconst DEFAULT_COOLDOWN_MS = 5 * 60_000;\nconst DEFAULT_MAX_COOLDOWN_MS = 60 * 60_000;\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nexport class DuckDuckGoBotCheckError extends Error {\n\tconstructor(status: number) {\n\t\t// \"rate limited\" makes search routing classify this as quota.\n\t\tsuper(`DuckDuckGo blocked the request with a bot check (HTTP ${status}, rate limited); use another search provider`);\n\t\tthis.name = \"DuckDuckGoBotCheckError\";\n\t}\n}\n\nexport interface DuckDuckGoRateLimitOptions {\n\tnow?: () => number;\n\tsleep?: (ms: number, signal?: AbortSignal) => Promise<void>;\n\tminIntervalMs?: number;\n\tcooldownMs?: number;\n\tmaxCooldownMs?: number;\n\t/** Deadline per search, counted from when it is queued. */\n\ttimeoutMs?: number;\n}\n\nexport class DuckDuckGoRateLimit {\n\tprivate queue: Promise<void> = Promise.resolve();\n\tprivate lastStart = Number.NEGATIVE_INFINITY;\n\tprivate blockedUntil = 0;\n\tprivate nextCooldownMs: number;\n\tprivate readonly now: () => number;\n\tprivate readonly sleep: (ms: number, signal?: AbortSignal) => Promise<void>;\n\tprivate readonly minIntervalMs: number;\n\tprivate readonly cooldownMs: number;\n\tprivate readonly maxCooldownMs: number;\n\tprivate readonly timeoutMs: number;\n\n\tconstructor(options: DuckDuckGoRateLimitOptions = {}) {\n\t\tthis.now = options.now ?? Date.now;\n\t\tthis.sleep = options.sleep ?? defaultSleep;\n\t\tthis.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;\n\t\tthis.cooldownMs = options.cooldownMs ?? DEFAULT_COOLDOWN_MS;\n\t\tthis.maxCooldownMs = options.maxCooldownMs ?? DEFAULT_MAX_COOLDOWN_MS;\n\t\tthis.nextCooldownMs = this.cooldownMs;\n\t\tthis.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\t}\n\n\t/**\n\t * Queues `operation` and passes it a signal that fires on the caller's abort or when\n\t * the deadline passes. A passed deadline rejects with a \"timed out\" error rather than\n\t * an abort, so search routing treats it as a network failure and can fall back.\n\t */\n\trun<T>(operation: (signal: AbortSignal) => Promise<T>, callerSignal?: AbortSignal): Promise<T> {\n\t\tif (callerSignal?.aborted) return Promise.reject(new Error(\"Aborted\"));\n\t\tconst deadline = AbortSignal.timeout(this.timeoutMs);\n\t\tconst signal = callerSignal ? AbortSignal.any([deadline, callerSignal]) : deadline;\n\t\tconst scheduled = this.queue.then(() => this.runNow(operation, signal));\n\t\tthis.queue = scheduled.then(() => undefined, () => undefined);\n\t\t// Let a search give up while still queued without unblocking the queue early.\n\t\treturn awaitWithAbort(scheduled, signal).catch(error => {\n\t\t\tif (deadline.aborted && !callerSignal?.aborted) {\n\t\t\t\tthrow new Error(`DuckDuckGo request timed out after ${formatWait(this.timeoutMs)}`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\t}\n\n\tprivate async runNow<T>(operation: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> {\n\t\tif (signal.aborted) throw new Error(\"Aborted\");\n\t\tconst remainingMs = this.blockedUntil - this.now();\n\t\tif (remainingMs > 0) throw new Error(`DuckDuckGo showed a bot check recently; not retrying for ${formatWait(remainingMs)} (rate limited); use another search provider`);\n\t\tconst waitMs = this.lastStart + this.minIntervalMs - this.now();\n\t\tif (waitMs > 0) await this.sleep(waitMs, signal);\n\t\tthis.lastStart = this.now();\n\t\ttry {\n\t\t\tconst result = await operation(signal);\n\t\t\tthis.nextCooldownMs = this.cooldownMs;\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (error instanceof DuckDuckGoBotCheckError) {\n\t\t\t\tthis.blockedUntil = this.now() + this.nextCooldownMs;\n\t\t\t\tthis.nextCooldownMs = Math.min(this.nextCooldownMs * 2, this.maxCooldownMs);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"duckduckgo-rate-limit.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/duckduckgo-rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY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QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAEO,kBAAkB;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,OAAO;QAC5B,IAAI,CAAC;YACJ,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACrE,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;YACvD,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACvE,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;CACD","sourcesContent":["import { mkdirSync, readFileSync, renameSync, writeFileSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { awaitWithAbort } from \"./abortable.ts\";\nimport { defaultSleep, formatWait } from \"./brave-rate-limit.ts\";\n\n// DuckDuckGo has no API quota, but it shows its bot check to the whole client IP\n// (browsers included) once too many requests come from it, and keeps it up for 7 to 30\n// minutes. Changing the User-Agent, TLS fingerprint or endpoint does not help. Tests from\n// one home IP: 2s apart was blocked after 3 to 34 searches, 5s apart after 22 searches in\n// 10 minutes, 10s apart back to back after 47 searches; 10s apart with at most 10 per 10\n// minutes ran 60 searches in 54 minutes from three processes sharing one budget with no\n// bot check. A retry soon after a block brings it back, hence the long, doubling pause.\n\nconst DEFAULT_MIN_INTERVAL_MS = 10_000;\nconst DEFAULT_WINDOW_MS = 10 * 60_000;\nconst DEFAULT_MAX_STARTS = 10;\nconst DEFAULT_COOLDOWN_MS = 30 * 60_000;\nconst DEFAULT_MAX_COOLDOWN_MS = 2 * 60 * 60_000;\nconst DEFAULT_TIMEOUT_MS = 30_000;\n/** Part of the deadline kept for the request itself; a search that would start later fails at once. */\nconst REQUEST_ALLOWANCE_MS = 10_000;\n\nexport class DuckDuckGoBotCheckError extends Error {\n\tconstructor(status: number) {\n\t\t// \"rate limited\" makes search routing classify this as quota.\n\t\tsuper(`DuckDuckGo blocked the request with a bot check (HTTP ${status}, rate limited); use another search provider`);\n\t\tthis.name = \"DuckDuckGoBotCheckError\";\n\t}\n}\n\nexport interface DuckDuckGoRateLimitOptions {\n\tnow?: () => number;\n\tsleep?: (ms: number, signal?: AbortSignal) => Promise<void>;\n\tminIntervalMs?: number;\n\t/** At most `maxStarts` searches start in any `windowMs`. */\n\twindowMs?: number;\n\tmaxStarts?: number;\n\tcooldownMs?: number;\n\tmaxCooldownMs?: number;\n\t/** Deadline per search, counted from when it is called. */\n\ttimeoutMs?: number;\n\t/** File that shares the bot-check pause with other processes; unset keeps it in this process. */\n\tstatePath?: string;\n}\n\ninterface Cooldown {\n\tblockedUntil: number;\n\t/** Pause to apply after the next bot check. */\n\tnextCooldownMs: number;\n}\n\nfunction cooldownError(remainingMs: number): Error {\n\treturn new Error(`DuckDuckGo showed a bot check recently; not retrying for ${formatWait(remainingMs)} so the block can clear (rate limited); use another search provider`);\n}\n\nexport class DuckDuckGoRateLimit {\n\tprivate queue: Promise<void> = Promise.resolve();\n\t/** Searches queued that have not started yet. */\n\tprivate waiting = 0;\n\t/** Actual start times of the latest `maxStarts` searches, oldest first. */\n\tprivate starts: number[] = [];\n\tprivate cooldown: Cooldown;\n\tprivate readonly now: () => number;\n\tprivate readonly sleep: (ms: number, signal?: AbortSignal) => Promise<void>;\n\tprivate readonly minIntervalMs: number;\n\tprivate readonly windowMs: number;\n\tprivate readonly maxStarts: number;\n\tprivate readonly cooldownMs: number;\n\tprivate readonly maxCooldownMs: number;\n\tprivate readonly timeoutMs: number;\n\tprivate readonly statePath: string | undefined;\n\n\tconstructor(options: DuckDuckGoRateLimitOptions = {}) {\n\t\tthis.now = options.now ?? Date.now;\n\t\tthis.sleep = options.sleep ?? defaultSleep;\n\t\tthis.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;\n\t\tthis.windowMs = options.windowMs ?? DEFAULT_WINDOW_MS;\n\t\tthis.maxStarts = Math.max(1, options.maxStarts ?? DEFAULT_MAX_STARTS);\n\t\tthis.cooldownMs = options.cooldownMs ?? DEFAULT_COOLDOWN_MS;\n\t\tthis.maxCooldownMs = options.maxCooldownMs ?? DEFAULT_MAX_COOLDOWN_MS;\n\t\tthis.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\t\tthis.statePath = options.statePath;\n\t\tthis.cooldown = { blockedUntil: 0, nextCooldownMs: this.cooldownMs };\n\t}\n\n\t/**\n\t * Queues `operation` behind earlier searches and runs it with a signal that fires on the\n\t * caller's abort or when the deadline passes. A search that cannot start before its\n\t * deadline fails at once as rate limited, so routing moves on without waiting. A passed\n\t * deadline rejects with a \"timed out\" error rather than an abort, so search routing\n\t * treats it as a network failure and can fall back.\n\t */\n\tasync run<T>(operation: (signal: AbortSignal) => Promise<T>, callerSignal?: AbortSignal): Promise<T> {\n\t\tif (callerSignal?.aborted) throw new Error(\"Aborted\");\n\t\tconst now = this.now();\n\t\tconst latestStart = now + Math.max(0, this.timeoutMs - REQUEST_ALLOWANCE_MS);\n\t\tthis.throwIfBlocked(now);\n\t\tconst slot = this.nextSlot(now, this.waiting + 1);\n\t\tif (slot > latestStart) throw this.busyError(slot - now);\n\n\t\tconst deadline = AbortSignal.timeout(this.timeoutMs);\n\t\tconst signal = callerSignal ? AbortSignal.any([deadline, callerSignal]) : deadline;\n\t\tthis.waiting++;\n\t\tconst started = this.queue.then(() => this.waitForSlot(signal, latestStart)).finally(() => { this.waiting--; });\n\t\tthis.queue = started.then(() => undefined, () => undefined);\n\t\ttry {\n\t\t\t// Let a search give up while still queued without unblocking the queue early.\n\t\t\treturn await awaitWithAbort(started.then(() => this.attempt(operation, signal)), signal);\n\t\t} catch (error) {\n\t\t\tif (deadline.aborted && !callerSignal?.aborted) {\n\t\t\t\tthrow new Error(`DuckDuckGo request timed out after ${formatWait(this.timeoutMs)}`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Start time of the `count`th search from now, given the searches already started. */\n\tprivate nextSlot(now: number, count: number): number {\n\t\tconst starts = [...this.starts];\n\t\tlet slot = now;\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tslot = Math.max(now, (starts.at(-1) ?? Number.NEGATIVE_INFINITY) + this.minIntervalMs);\n\t\t\tif (starts.length >= this.maxStarts) slot = Math.max(slot, starts[starts.length - this.maxStarts] + this.windowMs);\n\t\t\tstarts.push(slot);\n\t\t}\n\t\treturn slot;\n\t}\n\n\t/** Runs at the head of the queue, so spacing is measured from the previous search's actual start. */\n\tprivate async waitForSlot(signal: AbortSignal, latestStart: number): Promise<void> {\n\t\tfor (;;) {\n\t\t\tif (signal.aborted) throw new Error(\"Aborted\");\n\t\t\tconst now = this.now();\n\t\t\tthis.throwIfBlocked(now);\n\t\t\tconst slot = this.nextSlot(now, 1);\n\t\t\tif (slot <= now) {\n\t\t\t\tthis.starts.push(now);\n\t\t\t\tif (this.starts.length > this.maxStarts) this.starts.shift();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (slot > latestStart) throw this.busyError(slot - now);\n\t\t\tawait this.sleep(slot - now, signal);\n\t\t}\n\t}\n\n\tprivate busyError(waitMs: number): Error {\n\t\treturn new Error(`DuckDuckGo is limited to one search every ${formatWait(this.minIntervalMs)} and ${this.maxStarts} every ${formatWait(this.windowMs)} in this process to avoid its bot check; the next free slot is in ${formatWait(waitMs)} (rate limited); use another search provider`);\n\t}\n\n\tprivate throwIfBlocked(now: number): void {\n\t\tthis.loadSharedCooldown();\n\t\tconst remainingMs = this.cooldown.blockedUntil - now;\n\t\tif (remainingMs > 0) throw cooldownError(remainingMs);\n\t}\n\n\tprivate async attempt<T>(operation: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> {\n\t\ttry {\n\t\t\tconst result = await operation(signal);\n\t\t\tthis.loadSharedCooldown();\n\t\t\tif (this.cooldown.nextCooldownMs !== this.cooldownMs && this.cooldown.blockedUntil <= this.now()) {\n\t\t\t\tthis.cooldown = { ...this.cooldown, nextCooldownMs: this.cooldownMs };\n\t\t\t\tthis.saveSharedCooldown();\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (error instanceof DuckDuckGoBotCheckError) {\n\t\t\t\tthis.loadSharedCooldown();\n\t\t\t\tconst now = this.now();\n\t\t\t\t// Searches already in flight see the same block; count it once.\n\t\t\t\tif (this.cooldown.blockedUntil <= now) {\n\t\t\t\t\tconst pauseMs = this.cooldown.nextCooldownMs;\n\t\t\t\t\tthis.cooldown = { blockedUntil: now + pauseMs, nextCooldownMs: Math.min(pauseMs * 2, this.maxCooldownMs) };\n\t\t\t\t\tthis.saveSharedCooldown();\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// The state file is best effort: if it cannot be read or written, this process keeps\n\t// its own pause, and a search never fails or loses its result because of the file.\n\tprivate loadSharedCooldown(): void {\n\t\tif (!this.statePath) return;\n\t\ttry {\n\t\t\tconst saved = JSON.parse(readFileSync(this.statePath, \"utf8\")) as Partial<Cooldown>;\n\t\t\tconst { blockedUntil, nextCooldownMs } = saved;\n\t\t\tif (typeof blockedUntil !== \"number\" || typeof nextCooldownMs !== \"number\" || !(nextCooldownMs > 0)) return;\n\t\t\t// A pause longer than the cap comes from a clock that has since moved back, or a damaged file.\n\t\t\tif (!(blockedUntil <= this.now() + this.maxCooldownMs)) return;\n\t\t\tif (blockedUntil >= this.cooldown.blockedUntil) {\n\t\t\t\tthis.cooldown = { blockedUntil, nextCooldownMs: Math.min(nextCooldownMs, this.maxCooldownMs) };\n\t\t\t}\n\t\t} catch {}\n\t}\n\n\tprivate saveSharedCooldown(): void {\n\t\tif (!this.statePath) return;\n\t\ttry {\n\t\t\tmkdirSync(dirname(this.statePath), { recursive: true, mode: 0o700 });\n\t\t\tconst tmpPath = `${this.statePath}.${process.pid}.tmp`;\n\t\t\twriteFileSync(tmpPath, JSON.stringify(this.cooldown), { mode: 0o600 });\n\t\t\trenameSync(tmpPath, this.statePath);\n\t\t} catch {}\n\t}\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { type DuckDuckGoRateLimitOptions } from "./duckduckgo-rate-limit.ts";
2
2
  import type { SearchOptions, SearchResponse } from "./perplexity.ts";
3
- /** Replace the shared request spacing and bot-check cooldown state (for tests). */
3
+ /** Replace the request spacing and bot-check cooldown state (for tests); without `statePath` nothing is shared. */
4
4
  export declare function resetDuckDuckGoRateLimit(options?: DuckDuckGoRateLimitOptions): void;
5
5
  export declare function isDuckDuckGoAvailable(): boolean;
6
6
  export declare function searchWithDuckDuckGo(query: string, options?: SearchOptions): Promise<SearchResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"duckduckgo.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/duckduckgo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgD,KAAK,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC3H,OAAO,KAAK,EAAE,aAAa,EAAgB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMnF,mFAAmF;AACnF,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,IAAI,CAEnF;AAwCD,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAED,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CA0D9G"}
1
+ {"version":3,"file":"duckduckgo.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/duckduckgo.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgD,KAAK,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC3H,OAAO,KAAK,EAAE,aAAa,EAAgB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAanF,mHAAmH;AACnH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,IAAI,CAEnF;AAwCD,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAED,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CA0D9G"}
@@ -1,10 +1,17 @@
1
1
  import { activityMonitor } from "./activity.js";
2
2
  import { normalizeDomain } from "./domain-filter-normalization.js";
3
+ import { join } from "node:path";
3
4
  import { DuckDuckGoBotCheckError, DuckDuckGoRateLimit } from "./duckduckgo-rate-limit.js";
4
5
  import { normalizeSearchResultCount } from "./search-result-count-normalization.js";
6
+ import { getWebSearchConfigDir } from "./utils.js";
5
7
  const SEARCH_URL = "https://html.duckduckgo.com/html/";
6
- let rateLimit = new DuckDuckGoRateLimit();
7
- /** Replace the shared request spacing and bot-check cooldown state (for tests). */
8
+ /** Bot-check pause, shared by every Pi process using this config directory. */
9
+ const STATE_FILE = "duckduckgo-cooldown.json";
10
+ let rateLimit = null;
11
+ function getRateLimit() {
12
+ return rateLimit ??= new DuckDuckGoRateLimit({ statePath: join(getWebSearchConfigDir(), STATE_FILE) });
13
+ }
14
+ /** Replace the request spacing and bot-check cooldown state (for tests); without `statePath` nothing is shared. */
8
15
  export function resetDuckDuckGoRateLimit(options) {
9
16
  rateLimit = new DuckDuckGoRateLimit(options);
10
17
  }
@@ -50,7 +57,7 @@ export async function searchWithDuckDuckGo(query, options = {}) {
50
57
  url.searchParams.set("q", query);
51
58
  const activityId = activityMonitor.logStart({ type: "api", query });
52
59
  try {
53
- return await rateLimit.run(async (signal) => {
60
+ return await getRateLimit().run(async (signal) => {
54
61
  const response = await fetch(url, {
55
62
  method: "GET",
56
63
  headers: {
@@ -1 +1 @@
1
- {"version":3,"file":"duckduckgo.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/duck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AM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO;gBAClD,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,aAAa,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,GAAG,GAAG;gBAC9D,CAAC,CAAC,WAAW,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QAC5B,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,eAAe,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;;YACnF,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACnD,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["import { activityMonitor } from \"./activity.ts\";\nimport { normalizeDomain } from \"./domain-filter-normalization.ts\";\nimport { DuckDuckGoBotCheckError, DuckDuckGoRateLimit, type DuckDuckGoRateLimitOptions } from \"./duckduckgo-rate-limit.ts\";\nimport type { SearchOptions, SearchResult, SearchResponse } from \"./perplexity.ts\";\nimport { normalizeSearchResultCount } from \"./search-result-count-normalization.ts\";\n\nconst SEARCH_URL = \"https://html.duckduckgo.com/html/\";\nlet rateLimit = new DuckDuckGoRateLimit();\n\n/** Replace the shared request spacing and bot-check cooldown state (for tests). */\nexport function resetDuckDuckGoRateLimit(options?: DuckDuckGoRateLimitOptions): void {\n\trateLimit = new DuckDuckGoRateLimit(options);\n}\n\ninterface NormalizedDomainFilters {\n\tallowed: string[];\n\tblocked: string[];\n}\n\nfunction normalizeDomainFilters(domainFilter: string[] | undefined): NormalizedDomainFilters {\n\tconst filters: NormalizedDomainFilters = { allowed: [], blocked: [] };\n\tfor (const raw of domainFilter ?? []) {\n\t\tconst domain = normalizeDomain(raw);\n\t\tif (!domain) continue;\n\t\tconst target = raw.trim().startsWith(\"-\") ? filters.blocked : filters.allowed;\n\t\tif (!target.includes(domain)) target.push(domain);\n\t}\n\treturn filters;\n}\n\nfunction hostMatchesDomain(hostname: string, domain: string): boolean {\n\treturn hostname === domain || hostname.endsWith(`.${domain}`);\n}\n\nfunction matchesDomainFilters(url: string, filters: NormalizedDomainFilters): boolean {\n\tif (filters.allowed.length === 0 && filters.blocked.length === 0) return true;\n\tconst hostname = new URL(url).hostname.toLowerCase();\n\tif (filters.allowed.length > 0 && !filters.allowed.some(domain => hostMatchesDomain(hostname, domain))) return false;\n\treturn !filters.blocked.some(domain => hostMatchesDomain(hostname, domain));\n}\n\nfunction decodeResultUrl(href: string): string | null {\n\ttry {\n\t\tconst link = new URL(href, SEARCH_URL);\n\t\tconst destination = link.searchParams.get(\"uddg\") ?? link.href;\n\t\tconst url = new URL(destination);\n\t\treturn url.protocol === \"http:\" || url.protocol === \"https:\" ? url.href : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function isDuckDuckGoAvailable(): boolean {\n\treturn true;\n}\n\nexport async function searchWithDuckDuckGo(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n\tconst url = new URL(SEARCH_URL);\n\turl.searchParams.set(\"q\", query);\n\tconst activityId = activityMonitor.logStart({ type: \"api\", query });\n\n\ttry {\n\t\treturn await rateLimit.run(async signal => {\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tmethod: \"GET\",\n\t\t\t\theaders: {\n\t\t\t\t\tAccept: \"text/html\",\n\t\t\t\t\t\"User-Agent\": \"Mozilla/5.0 (compatible; pi-web-access/1.0; +https://github.com/nicobailon/pi-web-access)\",\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tconst body = await response.text();\n\t\t\t\tthrow new Error(`DuckDuckGo search error ${response.status}: ${body.slice(0, 300)}`);\n\t\t\t}\n\n\t\t\tconst { parseHTML } = await import(\"linkedom\");\n\t\t\tconst { document } = parseHTML(await response.text());\n\t\t\t// The bot check answers 202 or a challenge page.\n\t\t\tif (response.status === 202 || document.querySelector(\".anomaly-modal__box, #challenge-form\")) {\n\t\t\t\tthrow new DuckDuckGoBotCheckError(response.status);\n\t\t\t}\n\t\t\tconst filters = normalizeDomainFilters(options.domainFilter);\n\t\t\tconst results: SearchResult[] = [];\n\t\t\tlet parseableResults = 0;\n\t\t\tfor (const container of document.querySelectorAll(\".result\")) {\n\t\t\t\tif (container.classList.contains(\"result--ad\")) continue;\n\t\t\t\tconst anchor = container.querySelector(\".result__a\");\n\t\t\t\tconst title = anchor?.textContent?.trim() ?? \"\";\n\t\t\t\tconst href = anchor?.getAttribute(\"href\")?.trim() ?? \"\";\n\t\t\t\tconst resultUrl = href ? decodeResultUrl(href) : null;\n\t\t\t\tif (!title || !resultUrl) continue;\n\t\t\t\tparseableResults++;\n\t\t\t\tif (!matchesDomainFilters(resultUrl, filters)) continue;\n\t\t\t\tconst snippet = container.querySelector(\".result__snippet\")?.textContent?.trim() ?? \"\";\n\t\t\t\tresults.push({ title, url: resultUrl, snippet });\n\t\t\t\tif (results.length >= normalizeSearchResultCount(options.numResults)) break;\n\t\t\t}\n\t\t\tif (parseableResults === 0 && !document.querySelector(\".no-results__message\")) {\n\t\t\t\tthrow new Error(\"DuckDuckGo returned no parseable results (invalid response)\");\n\t\t\t}\n\n\t\t\tactivityMonitor.logComplete(activityId, response.status);\n\t\t\tconst answer = results.map(result => result.snippet\n\t\t\t\t? `${result.snippet}\\nSource: ${result.title} (${result.url})`\n\t\t\t\t: `Source: ${result.title} (${result.url})`).join(\"\\n\\n\");\n\t\t\treturn { answer, results };\n\t\t}, options.signal);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tif (message.toLowerCase().includes(\"abort\")) activityMonitor.logComplete(activityId, 0);\n\t\telse activityMonitor.logError(activityId, message);\n\t\tthrow err;\n\t}\n}\n"]}
1
+ {"version":3,"file":"duckduckgo.js","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/duckduckgo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAmC,MAAM,4BAA4B,CAAC;AAE3H,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,UAAU,GAAG,mCAAmC,CAAC;AACvD,+EAA+E;AAC/E,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAC9C,IAAI,SAAS,GAA+B,IAAI,CAAC;AAEjD,SAAS,YAAY;IACpB,OAAO,SAAS,KAAK,IAAI,mBAAmB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,qBAAqB,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;AACxG,CAAC;AAED,mHAAmH;AACnH,MAAM,UAAU,wBAAwB,CAAC,OAAoC;IAC5E,SAAS,GAAG,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC;AAOD,SAAS,sBAAsB,CAAC,YAAkC;IACjE,MAAM,OAAO,GAA4B,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACtE,KAAK,MAAM,GAAG,IAAI,YAAY,IAAI,EAAE,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,C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CAAC;;YACnF,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACnD,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["import { activityMonitor } from \"./activity.ts\";\nimport { normalizeDomain } from \"./domain-filter-normalization.ts\";\nimport { join } from \"node:path\";\nimport { DuckDuckGoBotCheckError, DuckDuckGoRateLimit, type DuckDuckGoRateLimitOptions } from \"./duckduckgo-rate-limit.ts\";\nimport type { SearchOptions, SearchResult, SearchResponse } from \"./perplexity.ts\";\nimport { normalizeSearchResultCount } from \"./search-result-count-normalization.ts\";\nimport { getWebSearchConfigDir } from \"./utils.ts\";\n\nconst SEARCH_URL = \"https://html.duckduckgo.com/html/\";\n/** Bot-check pause, shared by every Pi process using this config directory. */\nconst STATE_FILE = \"duckduckgo-cooldown.json\";\nlet rateLimit: DuckDuckGoRateLimit | null = null;\n\nfunction getRateLimit(): DuckDuckGoRateLimit {\n\treturn rateLimit ??= new DuckDuckGoRateLimit({ statePath: join(getWebSearchConfigDir(), STATE_FILE) });\n}\n\n/** Replace the request spacing and bot-check cooldown state (for tests); without `statePath` nothing is shared. */\nexport function resetDuckDuckGoRateLimit(options?: DuckDuckGoRateLimitOptions): void {\n\trateLimit = new DuckDuckGoRateLimit(options);\n}\n\ninterface NormalizedDomainFilters {\n\tallowed: string[];\n\tblocked: string[];\n}\n\nfunction normalizeDomainFilters(domainFilter: string[] | undefined): NormalizedDomainFilters {\n\tconst filters: NormalizedDomainFilters = { allowed: [], blocked: [] };\n\tfor (const raw of domainFilter ?? []) {\n\t\tconst domain = normalizeDomain(raw);\n\t\tif (!domain) continue;\n\t\tconst target = raw.trim().startsWith(\"-\") ? filters.blocked : filters.allowed;\n\t\tif (!target.includes(domain)) target.push(domain);\n\t}\n\treturn filters;\n}\n\nfunction hostMatchesDomain(hostname: string, domain: string): boolean {\n\treturn hostname === domain || hostname.endsWith(`.${domain}`);\n}\n\nfunction matchesDomainFilters(url: string, filters: NormalizedDomainFilters): boolean {\n\tif (filters.allowed.length === 0 && filters.blocked.length === 0) return true;\n\tconst hostname = new URL(url).hostname.toLowerCase();\n\tif (filters.allowed.length > 0 && !filters.allowed.some(domain => hostMatchesDomain(hostname, domain))) return false;\n\treturn !filters.blocked.some(domain => hostMatchesDomain(hostname, domain));\n}\n\nfunction decodeResultUrl(href: string): string | null {\n\ttry {\n\t\tconst link = new URL(href, SEARCH_URL);\n\t\tconst destination = link.searchParams.get(\"uddg\") ?? link.href;\n\t\tconst url = new URL(destination);\n\t\treturn url.protocol === \"http:\" || url.protocol === \"https:\" ? url.href : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function isDuckDuckGoAvailable(): boolean {\n\treturn true;\n}\n\nexport async function searchWithDuckDuckGo(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n\tconst url = new URL(SEARCH_URL);\n\turl.searchParams.set(\"q\", query);\n\tconst activityId = activityMonitor.logStart({ type: \"api\", query });\n\n\ttry {\n\t\treturn await getRateLimit().run(async signal => {\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tmethod: \"GET\",\n\t\t\t\theaders: {\n\t\t\t\t\tAccept: \"text/html\",\n\t\t\t\t\t\"User-Agent\": \"Mozilla/5.0 (compatible; pi-web-access/1.0; +https://github.com/nicobailon/pi-web-access)\",\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tconst body = await response.text();\n\t\t\t\tthrow new Error(`DuckDuckGo search error ${response.status}: ${body.slice(0, 300)}`);\n\t\t\t}\n\n\t\t\tconst { parseHTML } = await import(\"linkedom\");\n\t\t\tconst { document } = parseHTML(await response.text());\n\t\t\t// The bot check answers 202 or a challenge page.\n\t\t\tif (response.status === 202 || document.querySelector(\".anomaly-modal__box, #challenge-form\")) {\n\t\t\t\tthrow new DuckDuckGoBotCheckError(response.status);\n\t\t\t}\n\t\t\tconst filters = normalizeDomainFilters(options.domainFilter);\n\t\t\tconst results: SearchResult[] = [];\n\t\t\tlet parseableResults = 0;\n\t\t\tfor (const container of document.querySelectorAll(\".result\")) {\n\t\t\t\tif (container.classList.contains(\"result--ad\")) continue;\n\t\t\t\tconst anchor = container.querySelector(\".result__a\");\n\t\t\t\tconst title = anchor?.textContent?.trim() ?? \"\";\n\t\t\t\tconst href = anchor?.getAttribute(\"href\")?.trim() ?? \"\";\n\t\t\t\tconst resultUrl = href ? decodeResultUrl(href) : null;\n\t\t\t\tif (!title || !resultUrl) continue;\n\t\t\t\tparseableResults++;\n\t\t\t\tif (!matchesDomainFilters(resultUrl, filters)) continue;\n\t\t\t\tconst snippet = container.querySelector(\".result__snippet\")?.textContent?.trim() ?? \"\";\n\t\t\t\tresults.push({ title, url: resultUrl, snippet });\n\t\t\t\tif (results.length >= normalizeSearchResultCount(options.numResults)) break;\n\t\t\t}\n\t\t\tif (parseableResults === 0 && !document.querySelector(\".no-results__message\")) {\n\t\t\t\tthrow new Error(\"DuckDuckGo returned no parseable results (invalid response)\");\n\t\t\t}\n\n\t\t\tactivityMonitor.logComplete(activityId, response.status);\n\t\t\tconst answer = results.map(result => result.snippet\n\t\t\t\t? `${result.snippet}\\nSource: ${result.title} (${result.url})`\n\t\t\t\t: `Source: ${result.title} (${result.url})`).join(\"\\n\\n\");\n\t\t\treturn { answer, results };\n\t\t}, options.signal);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tif (message.toLowerCase().includes(\"abort\")) activityMonitor.logComplete(activityId, 0);\n\t\telse activityMonitor.logError(activityId, message);\n\t\tthrow err;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../src/humain/web-access/vendor/extract.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAgP,KAAK,MAAM,EAAE,KAAK,cAAc,EAAmB,MAAM,sBAAsB,CAAC;AAGvU,OAAO,EAA8C,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA+FpG,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AI,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;+EAC2E;IAC3E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;gFAC4E;IAC5E,SAAS,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED,6FAA6F;AAC7F,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,GAAG,MAAM,CAEzF;AA0JD,wBAAsB,cAAc,CACnC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAioB3B;AAkED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAGvG;AAqcD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK/D;AAMD,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAW7B"}
@@ -16,6 +16,7 @@ import { extractWithExa, hasExaApiKey } from "./exa.js";
16
16
  import { extractWithSearch1API, isSearch1APIAvailable } from "./search1api.js";
17
17
  import { extractWithQuerit, isQueritAvailable } from "./querit.js";
18
18
  import { extractWithTabstack, isTabstackAvailable } from "./tabstack.js";
19
+ import { extractWithSpecStream, isSpecStreamAvailable } from "./specstream.js";
19
20
  import { extractWithKagi, isKagiExtractAvailable } from "./kagi.js";
20
21
  import { extractWithOllama, isOllamaFetchAvailable } from "./ollama.js";
21
22
  import { extractWithFirecrawl, isFirecrawlAvailable } from "./firecrawl.js";
@@ -68,9 +69,9 @@ function loadFetchTimeoutMs() {
68
69
  const NON_RECOVERABLE_ERRORS = ["Unsupported content type", "Response too large", "PDF extraction is disabled", "Image fetching is disabled", "fetchContent.curl command not found"];
69
70
  const MIN_USEFUL_CONTENT = 500;
70
71
  const SUPPORTED_IMAGE_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
71
- const FETCH_PROVIDERS = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack"];
72
+ const FETCH_PROVIDERS = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack", "specstream"];
72
73
  const DEFAULT_FETCH_PROVIDER_ORDER = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "brightdata", "gemini"];
73
- const REMOTE_HOSTED_FETCH_PROVIDERS = new Set(["jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack"]);
74
+ const REMOTE_HOSTED_FETCH_PROVIDERS = new Set(["jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack", "specstream"]);
74
75
  function isDefuddleConsoleError(args) {
75
76
  const prefix = args[0];
76
77
  return prefix === "Defuddle" || (typeof prefix === "string" && /^Defuddle(?:\s|:)/.test(prefix));
@@ -765,6 +766,7 @@ export async function extractContent(url, signal, options) {
765
766
  let search1apiError = null;
766
767
  let queritError = null;
767
768
  let tabstackError = null;
769
+ let specstreamError = null;
768
770
  let kagiError = null;
769
771
  let ollamaError = null;
770
772
  let parallelError = null;
@@ -904,6 +906,23 @@ export async function extractContent(url, signal, options) {
904
906
  }
905
907
  continue;
906
908
  }
909
+ if (provider === "specstream") {
910
+ try {
911
+ if (isSpecStreamAvailable()) {
912
+ const specstreamResult = await extractWithSpecStream(url, signal, options);
913
+ if (specstreamResult)
914
+ return withDeclaredLinks(specstreamResult);
915
+ }
916
+ }
917
+ catch (err) {
918
+ if (isAbortError(err))
919
+ return abortedResult(url);
920
+ specstreamError = errorMessage(err);
921
+ if (isConfigParseError(err))
922
+ return parseErrorResult(specstreamError);
923
+ }
924
+ continue;
925
+ }
907
926
  if (provider === "kagi") {
908
927
  try {
909
928
  if (isKagiExtractAvailable()) {
@@ -1090,6 +1109,7 @@ export async function extractContent(url, signal, options) {
1090
1109
  ...(deepseekError ? [`DeepSeek fallback failed: ${deepseekError}`] : []),
1091
1110
  ...(exaError ? [`Exa fallback failed: ${exaError}`] : []),
1092
1111
  ...(tabstackError ? [`Tabstack fallback failed: ${tabstackError}`] : []),
1112
+ ...(specstreamError ? [`SpecStream fallback failed: ${specstreamError}`] : []),
1093
1113
  "",
1094
1114
  "Fallback options:",
1095
1115
  ...(jinaHint ? [jinaHint] : []),
@@ -1105,6 +1125,7 @@ export async function extractContent(url, signal, options) {
1105
1125
  ` • Set deepseekApiKey in ${WEB_SEARCH_CONFIG_PATH} or DEEPSEEK_API_KEY and add "deepseek" to fetchRouting.providers`,
1106
1126
  ` • Set exaApiKey in ${WEB_SEARCH_CONFIG_PATH} or EXA_API_KEY and add "exa" to fetchRouting.providers`,
1107
1127
  ` • Set tabstackApiKey in ${WEB_SEARCH_CONFIG_PATH} or TABSTACK_API_KEY and add "tabstack" to fetchRouting.providers`,
1128
+ ` • Set specstreamApiKey in ${WEB_SEARCH_CONFIG_PATH} or SPECSTREAM_API_KEY and add "specstream" to fetchRouting.providers`,
1108
1129
  ` • Set GEMINI_API_KEY in ${WEB_SEARCH_CONFIG_PATH}`,
1109
1130
  " • Sign into gemini.google.com in Chrome",
1110
1131
  ...(searchToolName ? [` • Use ${searchToolName} to find content about this topic`] : []),
@@ -1136,6 +1157,23 @@ function isExecutableScriptType(type) {
1136
1157
  const mime = (type ?? "").split(";")[0].trim().toLowerCase();
1137
1158
  return mime === "" || mime === "module" || JAVASCRIPT_MIME_TYPES.has(mime);
1138
1159
  }
1160
+ /** Removes non-rendered nodes, so pass a fresh parse. */
1161
+ function visibleTextLength(document) {
1162
+ for (const node of document.querySelectorAll("script, style, noscript, template"))
1163
+ node.remove();
1164
+ return (document.body?.textContent ?? "").replace(/\s+/g, " ").trim().length;
1165
+ }
1166
+ /** Markdown length as text, without images and link targets, which would
1167
+ * otherwise count long URLs as content. Each pattern always matches once
1168
+ * started, which keeps the scan linear on unbalanced brackets. */
1169
+ function markdownTextLength(markdown) {
1170
+ return markdown
1171
+ .replace(/\]\([^)\s]*\)?/g, "]")
1172
+ .replace(/!\[[^\]]*\]?/g, "")
1173
+ .replace(/\s+/g, " ")
1174
+ .trim()
1175
+ .length;
1176
+ }
1139
1177
  function isLikelyJSRendered(html) {
1140
1178
  const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
1141
1179
  if (!bodyMatch)
@@ -1509,9 +1547,7 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
1509
1547
  const { document: original } = parseHTML(text);
1510
1548
  const hasExecutableScript = [...original.querySelectorAll("script")]
1511
1549
  .some((script) => isExecutableScriptType(script.getAttribute("type")));
1512
- for (const node of original.querySelectorAll("script, style, noscript, template"))
1513
- node.remove();
1514
- const visibleChars = (original.body?.textContent ?? "").replace(/\s+/g, " ").trim().length;
1550
+ const visibleChars = visibleTextLength(original);
1515
1551
  const extractedChars = markdown.trim().length;
1516
1552
  const counts = `Extracted content appears incomplete: extracted ${extractedChars} characters from a page with ${visibleChars} characters of visible text`;
1517
1553
  if (visibleChars >= MIN_USEFUL_CONTENT)
@@ -1529,6 +1565,26 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
1529
1565
  declaredLinks,
1530
1566
  };
1531
1567
  }
1568
+ // Readability can keep one block of a page (one section of a guide, a
1569
+ // product page's cart drawer) and still clear the length floor. The
1570
+ // thresholds were measured on #673's examples (coverage <= 0.25, gain
1571
+ // >= 1.9x) and ordinary articles and docs (coverage >= 0.55, gain <= 1.2x).
1572
+ // Readability's result already stands, so a Defuddle failure keeps it.
1573
+ const extractedText = markdownTextLength(markdown);
1574
+ if (extractedText < visibleTextLength(parseHTML(text).document) * 0.5) {
1575
+ controller.signal.throwIfAborted();
1576
+ const defuddleResult = await extractWithDefuddle(text, response.url || url).catch(() => null);
1577
+ controller.signal.throwIfAborted();
1578
+ if (defuddleResult && defuddleResult.content.length >= MIN_USEFUL_CONTENT && markdownTextLength(defuddleResult.content) >= extractedText * 1.5) {
1579
+ return {
1580
+ url,
1581
+ title: article.title || documentTitle || defuddleResult.title,
1582
+ content: appendDeclaredWebLinks(defuddleResult.content, declaredLinks),
1583
+ error: null,
1584
+ declaredLinks,
1585
+ };
1586
+ }
1587
+ }
1532
1588
  return {
1533
1589
  url,
1534
1590
  title: article.title || documentTitle,