@herbertgao/pi-extensions 2026.11.10 → 2026.11.12
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.
- package/CHANGELOG.md +31 -0
- package/README.md +10 -10
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +16 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +3 -4
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -4
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/core.ts +22 -15
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/index.ts +22 -8
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +0 -29
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +5 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +73 -47
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +3 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/codemode.ts +0 -40
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-parse.ts +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +79 -18
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/tool-io.ts +0 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/ansi-text.ts +18 -4
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/format.ts +15 -0
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/node_modules/@herbertgao/pi-impeccable/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-impeccable/README.md +2 -2
- package/node_modules/@herbertgao/pi-impeccable/package.json +4 -4
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/SKILL.md +4 -2
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/adapt.md +2 -2
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/animate.md +17 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/audit.md +12 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/audit.native.md +4 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/critique-rubric.md +496 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/critique.md +13 -505
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/degraded/documenter.md +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/degraded/finish-reviewer.md +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/degraded/motion-reviewer.md +29 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/distill.md +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/document.md +3 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/foundations.md +44 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/hooks.md +3 -3
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/live-setup.md +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/live.md +26 -12
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/new-work-comp.md +24 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/new-work-world.md +20 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/new-work.md +9 -37
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/onboard.md +7 -6
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/overdrive.md +2 -2
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/quieter.md +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/typeset.md +6 -0
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/reference/visualize.md +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/VERSION +1 -1
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/engine-checksums.txt +5 -5
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/impeccable +69 -16
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/impeccable.cmd +55 -7
- package/node_modules/@herbertgao/pi-impeccable/skills/impeccable/scripts/live-browser.js +51 -22
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +27 -9
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +11 -11
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +13 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +51 -32
- package/node_modules/@herbertgao/pi-subagents/src/default-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +334 -893
- package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +4 -1
- package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +13 -0
- package/node_modules/@herbertgao/pi-subagents/src/schedule-store.ts +18 -13
- package/node_modules/@herbertgao/pi-subagents/src/schedule.ts +25 -5
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +215 -69
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +17 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/agents-menu.ts +705 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/settings-menu.ts +361 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/viewer-keys.ts +1 -1
- package/node_modules/pi-antigravity/README.md +58 -9
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +35 -0
- package/node_modules/pi-antigravity/package.json +15 -6
- package/node_modules/pi-antigravity/src/client/client.ts +63 -14
- package/node_modules/pi-antigravity/src/client/enterprise.ts +150 -0
- package/node_modules/pi-antigravity/src/client/index.ts +1 -0
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +7 -0
- package/node_modules/pi-antigravity/src/features/generate-image.ts +56 -2
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +124 -0
- package/node_modules/pi-antigravity/src/image/image.ts +16 -2
- package/node_modules/pi-antigravity/src/index.ts +145 -2
- package/node_modules/pi-antigravity/src/models/discovery.ts +3 -4
- package/node_modules/pi-antigravity/src/models/grouping.ts +39 -15
- package/node_modules/pi-antigravity/src/models/models.ts +126 -14
- package/node_modules/pi-antigravity/src/stream/stream.ts +189 -30
- package/node_modules/pi-antigravity/src/types/types.ts +30 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +58 -0
- package/node_modules/pi-antigravity/src/utils/address.ts +180 -0
- package/node_modules/pi-antigravity/src/utils/credits.ts +149 -0
- package/node_modules/pi-antigravity/src/utils/html.ts +31 -0
- package/node_modules/pi-antigravity/src/utils/index.ts +2 -0
- package/node_modules/pi-antigravity/src/utils/security.ts +172 -13
- package/node_modules/pi-antigravity/src/utils/text.ts +66 -0
- package/node_modules/pi-antigravity/src/utils/util.ts +5 -4
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +83 -0
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +24 -0
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +97 -0
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +3 -0
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +328 -0
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +4 -0
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +744 -0
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +164 -0
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +11 -0
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +9 -0
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +93 -0
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +71 -0
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +138 -0
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +9 -0
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +957 -0
- package/node_modules/pi-antigravity/tsconfig.json +2 -2
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +21 -1
- package/node_modules/pi-commandcode-provider/README.md +2 -2
- package/node_modules/pi-commandcode-provider/index.ts +2 -1
- package/node_modules/pi-commandcode-provider/package.json +5 -4
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +15 -9
- package/node_modules/pi-commandcode-provider/src/oauth.ts +69 -12
- package/node_modules/pi-commandcode-provider/src/pricing.ts +8 -1
- package/node_modules/pi-commandcode-provider/src/responses-compat.ts +137 -0
- package/node_modules/pi-lens/CHANGELOG-USER.md +6 -6
- package/node_modules/pi-lens/CHANGELOG.md +172 -0
- package/node_modules/pi-lens/README.md +103 -217
- package/node_modules/pi-lens/dist/{chunk-KXDQD34C.js → chunk-27JQHK7Y.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-W6VLB6LL.js → chunk-2APSZHHI.js} +61 -3
- package/node_modules/pi-lens/dist/{chunk-5EEWCJG7.js → chunk-2H5GHZKC.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-TS5EIWEF.js → chunk-2H7NFZ4Q.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-6GWCYEP7.js → chunk-37IDWT6O.js} +64 -16
- package/node_modules/pi-lens/dist/{chunk-OEPWTSUG.js → chunk-3PAS2ERX.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-ET3DSSFZ.js → chunk-3PO4YYOX.js} +9 -17
- package/node_modules/pi-lens/dist/{chunk-C6V2DSZZ.js → chunk-3QXFUP6T.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-HWMNTQBJ.js → chunk-3TSMQZG6.js} +32 -11
- package/node_modules/pi-lens/dist/{chunk-QY6J2FTK.js → chunk-4DAHGU3V.js} +15 -14
- package/node_modules/pi-lens/dist/{chunk-PCREZ4HJ.js → chunk-4IZZEN63.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-OYXD2MOM.js → chunk-5HBQL7DH.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-B4FAFEBP.js → chunk-5JB4WENL.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-5YJXF2IS.js +56 -0
- package/node_modules/pi-lens/dist/{chunk-GHATCG2A.js → chunk-6CFSDLHE.js} +22 -18
- package/node_modules/pi-lens/dist/{chunk-FVQKX5KI.js → chunk-6E5QLMWI.js} +24 -22
- package/node_modules/pi-lens/dist/{chunk-AVBEPUCD.js → chunk-6GLMMGCX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-YTXFNCVN.js → chunk-74AMPWNC.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-K2GV34T2.js → chunk-7CLWC2UH.js} +26 -37
- package/node_modules/pi-lens/dist/{chunk-MOEWCPMC.js → chunk-7DPXUPRF.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7BEADGAZ.js → chunk-7U36VQL6.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-PPYUBO6Y.js → chunk-7WKVCZI4.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ILC2B7IJ.js → chunk-7ZVTFLCC.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-IT7MFVGP.js → chunk-ADYQRETD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-NCDH2JB7.js → chunk-ARTYCUGF.js} +25 -10
- package/node_modules/pi-lens/dist/{chunk-Z6WTLVUL.js → chunk-AXAR5ZW2.js} +225 -104
- package/node_modules/pi-lens/dist/{chunk-PK3GDU4M.js → chunk-AZG5UJYY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-NRVWLTOY.js → chunk-B2OXE4AH.js} +60 -21
- package/node_modules/pi-lens/dist/{chunk-ORYQGVC3.js → chunk-B42AIWPJ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-IC4L65U7.js → chunk-BBSDJTOV.js} +12 -13
- package/node_modules/pi-lens/dist/{chunk-HJWF7CGW.js → chunk-BKWFDWYM.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-D2ZYRI7M.js → chunk-C5PLBTNR.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-SRXYSLMW.js → chunk-CQY2HEH7.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-7424ANRU.js → chunk-CXQYK4YT.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-HYR25MV3.js → chunk-CZJGAOKL.js} +8 -7
- package/node_modules/pi-lens/dist/{chunk-DIIDMDZU.js → chunk-DCA2MXVQ.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-K2LD6YNH.js → chunk-DFKOA74L.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-AYDE7RFV.js → chunk-DI4AZZNY.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6EXGCXM5.js → chunk-G53LBDNU.js} +99 -5
- package/node_modules/pi-lens/dist/chunk-GCSDF5IE.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-5KLRCUDT.js → chunk-H5API74E.js} +6 -6
- package/node_modules/pi-lens/dist/chunk-HBX55MWO.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-JRSS6KM4.js → chunk-HIJ4CHFF.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-3MHY4BQY.js → chunk-HIRBC72R.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-F7AMFFVK.js → chunk-HRLF35WL.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-HSTN27NR.js → chunk-I2FYOZNW.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-5FDUKJZO.js → chunk-I3NZVAMN.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-NZINZCHB.js → chunk-INBK3HIT.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-PXGVB2CY.js → chunk-J2ZB5MDS.js} +20 -18
- package/node_modules/pi-lens/dist/{chunk-HYDJUVOE.js → chunk-JGUDT5KD.js} +4 -4
- package/node_modules/pi-lens/dist/chunk-JOIKBUQN.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-AZXTLZHE.js → chunk-K4Z7MK6T.js} +169 -165
- package/node_modules/pi-lens/dist/{chunk-WTSQKJAR.js → chunk-K7O6AHSJ.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-S6ZQFPOX.js → chunk-KNJH6WJQ.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-SUIZOCSY.js → chunk-KNSOA43J.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-3QMLB4TI.js → chunk-KXGTLAUW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-OHEUOWYT.js → chunk-KZ732ZVW.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-G3LR6V6N.js → chunk-L6BDRYUK.js} +19 -17
- package/node_modules/pi-lens/dist/{chunk-OVPR3GQ6.js → chunk-LGH2HHZG.js} +24 -6
- package/node_modules/pi-lens/dist/{chunk-3R3Z54J7.js → chunk-LOEJFTF2.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-HGEE5LDW.js → chunk-LQQNFCQJ.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-LVLPA32Q.js +810 -0
- package/node_modules/pi-lens/dist/chunk-M2YMBT5G.js +73 -0
- package/node_modules/pi-lens/dist/{chunk-Z2W5YJBW.js → chunk-MJRGPEQ5.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-3EIZMRXI.js → chunk-MOAVEPC4.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-TOOXNL6M.js → chunk-NGNBJIUO.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-AGEQRJ5A.js → chunk-NHA5K226.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-YLW26OHX.js → chunk-NNEQOC3U.js} +31 -59
- package/node_modules/pi-lens/dist/{chunk-ZWZD4TJ5.js → chunk-O2MHF7QM.js} +35 -36
- package/node_modules/pi-lens/dist/{chunk-PTJXMYRY.js → chunk-OLWGYBYT.js} +15 -16
- package/node_modules/pi-lens/dist/{chunk-JKAVKTMY.js → chunk-OZQQ3AIR.js} +17 -20
- package/node_modules/pi-lens/dist/{chunk-6JLNZ6DP.js → chunk-P5MSLVUW.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-OF2YGDUE.js → chunk-PFJLYRO3.js} +37 -38
- package/node_modules/pi-lens/dist/chunk-PKWEBMCA.js +2957 -0
- package/node_modules/pi-lens/dist/{chunk-JLMS7EMD.js → chunk-PPQHMSPH.js} +16 -15
- package/node_modules/pi-lens/dist/{chunk-6EIV3H7O.js → chunk-PQF6YGYB.js} +12 -5
- package/node_modules/pi-lens/dist/{chunk-VU2PRGRI.js → chunk-PQXUZYTQ.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-MV6ST2KT.js → chunk-Q7J3JYJ2.js} +13 -12
- package/node_modules/pi-lens/dist/{chunk-BMMRLJA4.js → chunk-QE5DJ7MX.js} +27 -10
- package/node_modules/pi-lens/dist/{chunk-IZ36G463.js → chunk-QE7BJQ6K.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-E5SSUV2A.js → chunk-QMWKSYWB.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-QJ4T73J5.js → chunk-QV3JPCMK.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-3PMLYGJN.js → chunk-R4L7KZ7R.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-7ZVEFWOE.js → chunk-RIH3UBK4.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-T5EGSBM2.js → chunk-RJ3APNIP.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-AAIVSSUU.js → chunk-S6MCMD27.js} +35 -12
- package/node_modules/pi-lens/dist/{chunk-SF7KSXB5.js → chunk-SCU62JLX.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-FDLGJFAE.js → chunk-SDYLT45T.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-TFKN5EIR.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-Y7XMKBFP.js → chunk-TKOFTLGB.js} +34 -26
- package/node_modules/pi-lens/dist/chunk-TQWRH25U.js +35 -0
- package/node_modules/pi-lens/dist/{chunk-DZSQXG66.js → chunk-TWEOJE3D.js} +277 -62
- package/node_modules/pi-lens/dist/{chunk-R67WQ5RY.js → chunk-UN72ZAJ5.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-AD7JDEI6.js → chunk-UNP6Y4JV.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-D6ANA6YU.js → chunk-VGRGW4UL.js} +63 -55
- package/node_modules/pi-lens/dist/{chunk-DFAY7JUN.js → chunk-VSQT6IHZ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7T64QA5D.js → chunk-VWEBZ2JV.js} +39 -38
- package/node_modules/pi-lens/dist/{chunk-HRQTYU2T.js → chunk-W26QZ3OM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-2HWVG3IM.js → chunk-XDNWR7SG.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-75TVYCQW.js → chunk-XSC3BCN3.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-ME6MF2N2.js → chunk-YCR6ZYTE.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-LD7SXICE.js → chunk-ZI7YHV6I.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-E3PNZDPH.js → chunk-ZQSSO7LO.js} +33 -1
- package/node_modules/pi-lens/dist/{chunk-T6PPK3T6.js → chunk-ZULZS2I6.js} +385 -407
- package/node_modules/pi-lens/dist/index.js +6508 -5413
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +9 -9
- package/node_modules/pi-lens/dist/mcp/cli.js +39 -38
- package/node_modules/pi-lens/dist/mcp/server.js +602 -345
- package/node_modules/pi-lens/dist/mcp/worker.js +57 -58
- package/node_modules/pi-lens/dist/probes/installer.js +19 -17
- package/node_modules/pi-lens/docs/architecture.md +113 -0
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +2 -2
- package/node_modules/pi-lens/docs/ci.md +18 -4
- package/node_modules/pi-lens/docs/defect-shapes.md +41 -3
- package/node_modules/pi-lens/docs/dependencies.md +10 -10
- package/node_modules/pi-lens/docs/features.md +3 -3
- package/node_modules/pi-lens/docs/invariants/dispatch-runners.md +13 -1
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +19 -0
- package/node_modules/pi-lens/docs/language-coverage.md +39 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +10 -4
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +4 -0
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +4 -5
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +5 -2
- package/node_modules/pi-lens/docs/prose-standard.md +112 -0
- package/node_modules/pi-lens/docs/servercapabilities.md +1 -1
- package/node_modules/pi-lens/docs/usage.md +50 -0
- package/node_modules/pi-lens/package.json +1 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/array-callback-return-js-test.yml +23 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/array-callback-return-test.yml +23 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-negation-in-equality-check-js-test.yml +8 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-negation-in-equality-check-test.yml +8 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/unchecked-throwing-call-js-test.yml +16 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/unchecked-throwing-call-test.yml +16 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/array-callback-return-js.yml +8 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/array-callback-return.yml +8 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-negation-in-equality-check-js.yml +17 -5
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-negation-in-equality-check.yml +17 -5
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/unchecked-throwing-call-js.yml +8 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/unchecked-throwing-call.yml +8 -1
- package/node_modules/pi-lens/rules/tree-sitter-queries/typescript/ts-react-antipatterns.yml +8 -0
- package/node_modules/pi-web-access/CHANGELOG.md +29 -0
- package/node_modules/pi-web-access/README.md +35 -15
- package/node_modules/pi-web-access/anysearch.ts +7 -3
- package/node_modules/pi-web-access/autom.ts +196 -0
- package/node_modules/pi-web-access/cloro.ts +254 -0
- package/node_modules/pi-web-access/curator-page.ts +7 -1
- package/node_modules/pi-web-access/curator-server.ts +3 -0
- package/node_modules/pi-web-access/dist/index.js +12931 -12111
- package/node_modules/pi-web-access/dist/mcp-cli.js +1188 -416
- package/node_modules/pi-web-access/domain-filter-normalization.ts +30 -0
- package/node_modules/pi-web-access/duckduckgo-rate-limit.ts +144 -34
- package/node_modules/pi-web-access/duckduckgo.ts +11 -3
- package/node_modules/pi-web-access/extract.ts +60 -4
- package/node_modules/pi-web-access/gemini-search.ts +25 -5
- package/node_modules/pi-web-access/index.ts +9 -1
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/pi-web-access/page-query.ts +12 -3
- package/node_modules/pi-web-access/specstream.ts +276 -0
- package/node_modules/pi-web-access/tool-activation.ts +21 -6
- package/node_modules/pi-web-access/utils.ts +4 -0
- package/node_modules/pi-web-access/video-extract.ts +2 -2
- package/node_modules/pi-web-access/web-tool-core.ts +24 -5
- package/node_modules/pi-web-access/youtube-extract.ts +2 -2
- package/package.json +11 -8
- package/node_modules/pi-lens/dist/chunk-3VWEZ6H2.js +0 -72
- package/node_modules/pi-lens/dist/chunk-7KWI5UHL.js +0 -28
- package/node_modules/pi-lens/dist/chunk-7M64NTAK.js +0 -38
- package/node_modules/pi-lens/dist/chunk-BEIPWPVR.js +0 -1037
- package/node_modules/pi-lens/dist/chunk-D7OEGXDX.js +0 -2417
- package/node_modules/pi-lens/dist/chunk-KUDUKKQE.js +0 -89
- package/node_modules/pi-lens/dist/chunk-TM3A3K7T.js +0 -28
- package/node_modules/pi-lens/dist/chunk-VD7MQFEV.js +0 -56
- package/node_modules/pi-lens/dist/chunk-YLHJWAQS.js +0 -256
- package/node_modules/pi-lens/dist/chunk-YULIERZW.js +0 -27
|
@@ -761,13 +761,14 @@ async function fetchViaCurlOnce(url, init, { command, proxy, notFound, maxBytes
|
|
|
761
761
|
Object.defineProperty(response, "redirected", { value: redirected, configurable: true });
|
|
762
762
|
return response;
|
|
763
763
|
}
|
|
764
|
-
var cachedWebSearchConfigDir, PI_PREFIXED_ENVIRONMENT_STEMS, API_REDIRECT_STATUSES, API_REQUEST_BODY_HEADERS, MAX_API_REDIRECTS, sharedProxyState, proxyStorage, CurlTransportError;
|
|
764
|
+
var cachedWebSearchConfigDir, PI_PREFIXED_ENVIRONMENT_STEMS, API_REDIRECT_STATUSES, API_REQUEST_BODY_HEADERS, MAX_API_REDIRECTS, FRAME_SCALE_FILTER, sharedProxyState, proxyStorage, CurlTransportError;
|
|
765
765
|
var init_utils = __esm({
|
|
766
766
|
"utils.ts"() {
|
|
767
767
|
PI_PREFIXED_ENVIRONMENT_STEMS = /* @__PURE__ */ new Set(["ollama", "deepseek", "tabstack"]);
|
|
768
768
|
API_REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
769
769
|
API_REQUEST_BODY_HEADERS = ["Content-Encoding", "Content-Language", "Content-Location", "Content-Type"];
|
|
770
770
|
MAX_API_REDIRECTS = 5;
|
|
771
|
+
FRAME_SCALE_FILTER = "scale=w='min(2000,iw)':h='min(2000,ih)':force_original_aspect_ratio=decrease";
|
|
771
772
|
sharedProxyState = globalThis;
|
|
772
773
|
proxyStorage = sharedProxyState[/* @__PURE__ */ Symbol.for("pi-web-access.proxyStorage")] ??= new AsyncLocalStorage();
|
|
773
774
|
CurlTransportError = class extends Error {
|
|
@@ -2477,6 +2478,30 @@ function normalizeDomain(value) {
|
|
|
2477
2478
|
input = input.replace(/^\.+|\.+$/g, "");
|
|
2478
2479
|
return /^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$/i.test(input) ? input : null;
|
|
2479
2480
|
}
|
|
2481
|
+
function applyDomainFilter(results, domainFilter) {
|
|
2482
|
+
if (!domainFilter?.length) return results;
|
|
2483
|
+
const includes = [];
|
|
2484
|
+
const excludes = [];
|
|
2485
|
+
for (const raw of domainFilter) {
|
|
2486
|
+
const normalized = normalizeDomain(raw);
|
|
2487
|
+
if (!normalized) continue;
|
|
2488
|
+
if (raw.trim().startsWith("-")) excludes.push(normalized);
|
|
2489
|
+
else includes.push(normalized);
|
|
2490
|
+
}
|
|
2491
|
+
if (!includes.length && !excludes.length) return results;
|
|
2492
|
+
return results.filter((result) => {
|
|
2493
|
+
let host;
|
|
2494
|
+
try {
|
|
2495
|
+
host = new URL(result.url).hostname.toLowerCase();
|
|
2496
|
+
} catch {
|
|
2497
|
+
return false;
|
|
2498
|
+
}
|
|
2499
|
+
const matches = (domain) => host === domain || host.endsWith(`.${domain}`);
|
|
2500
|
+
if (excludes.some(matches)) return false;
|
|
2501
|
+
if (includes.length && !includes.some(matches)) return false;
|
|
2502
|
+
return true;
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2480
2505
|
var init_domain_filter_normalization = __esm({
|
|
2481
2506
|
"domain-filter-normalization.ts"() {
|
|
2482
2507
|
}
|
|
@@ -5702,46 +5727,271 @@ var init_ollama = __esm({
|
|
|
5702
5727
|
}
|
|
5703
5728
|
});
|
|
5704
5729
|
|
|
5730
|
+
// specstream.ts
|
|
5731
|
+
import { existsSync as existsSync49, readFileSync as readFileSync50 } from "node:fs";
|
|
5732
|
+
function loadConfig44() {
|
|
5733
|
+
if (cachedConfig42) return cachedConfig42;
|
|
5734
|
+
if (!existsSync49(CONFIG_PATH46)) {
|
|
5735
|
+
cachedConfig42 = {};
|
|
5736
|
+
return cachedConfig42;
|
|
5737
|
+
}
|
|
5738
|
+
const raw = readFileSync50(CONFIG_PATH46, "utf-8");
|
|
5739
|
+
let parsed;
|
|
5740
|
+
try {
|
|
5741
|
+
parsed = JSON.parse(raw);
|
|
5742
|
+
} catch (err) {
|
|
5743
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
5744
|
+
throw new Error(`Failed to parse ${CONFIG_PATH46}: ${message}`);
|
|
5745
|
+
}
|
|
5746
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
5747
|
+
throw new Error(`Invalid config in ${CONFIG_PATH46}: expected a JSON object`);
|
|
5748
|
+
}
|
|
5749
|
+
cachedConfig42 = parsed;
|
|
5750
|
+
return cachedConfig42;
|
|
5751
|
+
}
|
|
5752
|
+
async function getApiKey32(signal) {
|
|
5753
|
+
return resolveCredential({
|
|
5754
|
+
provider: "SpecStream",
|
|
5755
|
+
configuredValue: loadConfig44().specstreamApiKey,
|
|
5756
|
+
environmentValue: process.env.SPECSTREAM_API_KEY,
|
|
5757
|
+
signal
|
|
5758
|
+
});
|
|
5759
|
+
}
|
|
5760
|
+
async function requireApiKey20(signal) {
|
|
5761
|
+
const apiKey = await getApiKey32(signal);
|
|
5762
|
+
if (!apiKey) {
|
|
5763
|
+
throw new Error(
|
|
5764
|
+
`SpecStream API key not found. Either:
|
|
5765
|
+
1. Create ${CONFIG_PATH46} with { "specstreamApiKey": "your-key" }
|
|
5766
|
+
2. Set SPECSTREAM_API_KEY environment variable
|
|
5767
|
+
Get a key at https://specstream.ai`
|
|
5768
|
+
);
|
|
5769
|
+
}
|
|
5770
|
+
return apiKey;
|
|
5771
|
+
}
|
|
5772
|
+
function parseDomainFilter17(domainFilter) {
|
|
5773
|
+
const filters = { include: [], exclude: [] };
|
|
5774
|
+
for (const raw of domainFilter ?? []) {
|
|
5775
|
+
const domain = normalizeDomain(raw);
|
|
5776
|
+
if (!domain) continue;
|
|
5777
|
+
const target = raw.trim().startsWith("-") ? filters.exclude : filters.include;
|
|
5778
|
+
if (!target.includes(domain)) target.push(domain);
|
|
5779
|
+
}
|
|
5780
|
+
return filters;
|
|
5781
|
+
}
|
|
5782
|
+
function passesDomainFilters17(url, filters) {
|
|
5783
|
+
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
5784
|
+
const hostname2 = url.hostname.toLowerCase();
|
|
5785
|
+
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
5786
|
+
if (filters.exclude.some(matches)) return false;
|
|
5787
|
+
return filters.include.length === 0 || filters.include.some(matches);
|
|
5788
|
+
}
|
|
5789
|
+
function errorMessage32(err) {
|
|
5790
|
+
return err instanceof Error ? err.message : String(err);
|
|
5791
|
+
}
|
|
5792
|
+
function invalidResponse20(message) {
|
|
5793
|
+
return new Error(`SpecStream returned invalid response: ${message}`);
|
|
5794
|
+
}
|
|
5795
|
+
function redactError(err, apiKey) {
|
|
5796
|
+
const message = errorMessage32(err);
|
|
5797
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
5798
|
+
if (redactedMessage === message && err instanceof Error) return err;
|
|
5799
|
+
const redactedError = new Error(redactedMessage);
|
|
5800
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
5801
|
+
return redactedError;
|
|
5802
|
+
}
|
|
5803
|
+
async function readJson(response) {
|
|
5804
|
+
try {
|
|
5805
|
+
return await response.json();
|
|
5806
|
+
} catch (err) {
|
|
5807
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
5808
|
+
throw new Error(`SpecStream returned invalid JSON: ${errorMessage32(err)}`);
|
|
5809
|
+
}
|
|
5810
|
+
}
|
|
5811
|
+
function unwrapEnvelope(value) {
|
|
5812
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalidResponse20("expected an object envelope");
|
|
5813
|
+
const envelope = value;
|
|
5814
|
+
const data = envelope.data;
|
|
5815
|
+
if (data && typeof data === "object" && !Array.isArray(data)) return data;
|
|
5816
|
+
const error = envelope.error;
|
|
5817
|
+
if (data === null && error && typeof error === "object") {
|
|
5818
|
+
const message = error.message;
|
|
5819
|
+
throw new Error(`SpecStream error: ${typeof message === "string" && message ? message : "request failed"}`);
|
|
5820
|
+
}
|
|
5821
|
+
return envelope;
|
|
5822
|
+
}
|
|
5823
|
+
function parseSearchResponse4(value) {
|
|
5824
|
+
const data = unwrapEnvelope(value);
|
|
5825
|
+
if (!Array.isArray(data.sources)) throw invalidResponse20("expected sources array");
|
|
5826
|
+
return data.sources;
|
|
5827
|
+
}
|
|
5828
|
+
function parseExtractResponse2(value) {
|
|
5829
|
+
const data = unwrapEnvelope(value);
|
|
5830
|
+
if (!Array.isArray(data.results)) throw invalidResponse20("expected results array");
|
|
5831
|
+
return data.results;
|
|
5832
|
+
}
|
|
5833
|
+
function isSpecStreamAvailable() {
|
|
5834
|
+
return hasCredentialSource({ provider: "SpecStream", configuredValue: loadConfig44().specstreamApiKey, environmentValue: process.env.SPECSTREAM_API_KEY });
|
|
5835
|
+
}
|
|
5836
|
+
async function searchWithSpecStream(query, options = {}) {
|
|
5837
|
+
const apiKey = await requireApiKey20(options.signal);
|
|
5838
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
5839
|
+
const filters = parseDomainFilter17(options.domainFilter);
|
|
5840
|
+
const endpoint = new URL(resolveProviderApiUrl("specstream", SPECSTREAM_SEARCH_URL, loadConfig44().specstreamBaseUrl));
|
|
5841
|
+
endpoint.searchParams.set("q", query.slice(0, MAX_QUERY_CHARS2));
|
|
5842
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
5843
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS39);
|
|
5844
|
+
let response;
|
|
5845
|
+
let entries;
|
|
5846
|
+
try {
|
|
5847
|
+
response = await fetchWithCredentialRedirects(endpoint.toString(), {
|
|
5848
|
+
method: "GET",
|
|
5849
|
+
headers: {
|
|
5850
|
+
Accept: "application/json",
|
|
5851
|
+
Authorization: `Bearer ${apiKey}`,
|
|
5852
|
+
"User-Agent": "pi-web-access"
|
|
5853
|
+
},
|
|
5854
|
+
signal: options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal
|
|
5855
|
+
}, ["Authorization"]);
|
|
5856
|
+
if (!response.ok) {
|
|
5857
|
+
const errorText = await response.text();
|
|
5858
|
+
throw new Error(`SpecStream error ${response.status}: ${redactCredential(errorText, apiKey).slice(0, 300)}`);
|
|
5859
|
+
}
|
|
5860
|
+
entries = parseSearchResponse4(await readJson(response));
|
|
5861
|
+
} catch (err) {
|
|
5862
|
+
if (options.signal?.aborted) {
|
|
5863
|
+
activityMonitor.logComplete(activityId, 0);
|
|
5864
|
+
throw new Error("Aborted");
|
|
5865
|
+
}
|
|
5866
|
+
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
5867
|
+
const outgoing = providerTimeout ? new Error(`SpecStream request timed out after ${Math.round(SEARCH_TIMEOUT_MS39 / 1e3)}s`) : redactError(err, apiKey);
|
|
5868
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage32(outgoing), apiKey));
|
|
5869
|
+
throw outgoing;
|
|
5870
|
+
}
|
|
5871
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
5872
|
+
const results = [];
|
|
5873
|
+
for (const entry of entries) {
|
|
5874
|
+
if (!entry || typeof entry !== "object") continue;
|
|
5875
|
+
if (typeof entry.url !== "string" || !entry.url) continue;
|
|
5876
|
+
let resultUrl;
|
|
5877
|
+
try {
|
|
5878
|
+
resultUrl = new URL(entry.url);
|
|
5879
|
+
} catch {
|
|
5880
|
+
continue;
|
|
5881
|
+
}
|
|
5882
|
+
if (resultUrl.protocol !== "http:" && resultUrl.protocol !== "https:") continue;
|
|
5883
|
+
if (!passesDomainFilters17(resultUrl, filters)) continue;
|
|
5884
|
+
results.push({
|
|
5885
|
+
title: typeof entry.title === "string" && entry.title.trim() ? entry.title.trim() : `Source ${results.length + 1}`,
|
|
5886
|
+
url: resultUrl.href,
|
|
5887
|
+
snippet: typeof entry.snippet === "string" ? entry.snippet : ""
|
|
5888
|
+
});
|
|
5889
|
+
if (results.length >= numResults) break;
|
|
5890
|
+
}
|
|
5891
|
+
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
5892
|
+
}
|
|
5893
|
+
async function extractWithSpecStream(url, signal, options = {}) {
|
|
5894
|
+
const apiKey = await requireApiKey20(signal);
|
|
5895
|
+
const timeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) ? Math.max(1, Math.floor(options.timeoutMs)) : EXTRACT_TIMEOUT_MS3;
|
|
5896
|
+
const activityId = activityMonitor.logStart({ type: "fetch", url });
|
|
5897
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
5898
|
+
try {
|
|
5899
|
+
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("specstream", SPECSTREAM_EXTRACT_URL, loadConfig44().specstreamBaseUrl), {
|
|
5900
|
+
method: "POST",
|
|
5901
|
+
headers: {
|
|
5902
|
+
Accept: "application/json",
|
|
5903
|
+
Authorization: `Bearer ${apiKey}`,
|
|
5904
|
+
"Content-Type": "application/json",
|
|
5905
|
+
"User-Agent": "pi-web-access"
|
|
5906
|
+
},
|
|
5907
|
+
body: JSON.stringify({ urls: [url], format: "markdown" }),
|
|
5908
|
+
signal: signal ? AbortSignal.any([timeoutSignal, signal]) : timeoutSignal
|
|
5909
|
+
}, ["Authorization"]);
|
|
5910
|
+
if (!response.ok) {
|
|
5911
|
+
const errorText = await response.text();
|
|
5912
|
+
throw new Error(`SpecStream Extract error ${response.status}: ${redactCredential(errorText, apiKey).slice(0, 300)}`);
|
|
5913
|
+
}
|
|
5914
|
+
const [result] = parseExtractResponse2(await readJson(response));
|
|
5915
|
+
if (!result || typeof result !== "object") throw invalidResponse20("expected one result for the URL");
|
|
5916
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
5917
|
+
if (result.status !== "ok") {
|
|
5918
|
+
if (result.status === "failed" || result.status === "blocked") {
|
|
5919
|
+
throw new Error(`SpecStream Extract could not read the page: ${String(result.status)}`);
|
|
5920
|
+
}
|
|
5921
|
+
return null;
|
|
5922
|
+
}
|
|
5923
|
+
const content = typeof result.text === "string" ? result.text.trim() : "";
|
|
5924
|
+
if (!content) return null;
|
|
5925
|
+
return { url, title: typeof result.title === "string" ? result.title.trim() : "", content, error: null };
|
|
5926
|
+
} catch (err) {
|
|
5927
|
+
if (signal?.aborted) {
|
|
5928
|
+
activityMonitor.logComplete(activityId, 0);
|
|
5929
|
+
throw err;
|
|
5930
|
+
}
|
|
5931
|
+
const outgoing = timeoutSignal.aborted ? new Error(`SpecStream Extract request timed out after ${Math.round(timeoutMs / 1e3)}s`) : redactError(err, apiKey);
|
|
5932
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage32(outgoing), apiKey));
|
|
5933
|
+
throw outgoing;
|
|
5934
|
+
}
|
|
5935
|
+
}
|
|
5936
|
+
var SPECSTREAM_SEARCH_URL, SPECSTREAM_EXTRACT_URL, CONFIG_PATH46, SEARCH_TIMEOUT_MS39, EXTRACT_TIMEOUT_MS3, MAX_QUERY_CHARS2, cachedConfig42;
|
|
5937
|
+
var init_specstream = __esm({
|
|
5938
|
+
"specstream.ts"() {
|
|
5939
|
+
init_activity();
|
|
5940
|
+
init_domain_filter_normalization();
|
|
5941
|
+
init_search_answer_formatting();
|
|
5942
|
+
init_search_result_count_normalization();
|
|
5943
|
+
init_credential_source();
|
|
5944
|
+
init_utils();
|
|
5945
|
+
SPECSTREAM_SEARCH_URL = "https://api.specstream.ai/v1/web-search";
|
|
5946
|
+
SPECSTREAM_EXTRACT_URL = "https://api.specstream.ai/v1/extract";
|
|
5947
|
+
CONFIG_PATH46 = getWebSearchConfigPath();
|
|
5948
|
+
SEARCH_TIMEOUT_MS39 = 6e4;
|
|
5949
|
+
EXTRACT_TIMEOUT_MS3 = 6e4;
|
|
5950
|
+
MAX_QUERY_CHARS2 = 2e3;
|
|
5951
|
+
cachedConfig42 = null;
|
|
5952
|
+
}
|
|
5953
|
+
});
|
|
5954
|
+
|
|
5705
5955
|
// deepseek.ts
|
|
5706
|
-
import { existsSync as
|
|
5707
|
-
function
|
|
5708
|
-
if (
|
|
5709
|
-
if (!
|
|
5710
|
-
|
|
5711
|
-
return
|
|
5956
|
+
import { existsSync as existsSync50, readFileSync as readFileSync51 } from "node:fs";
|
|
5957
|
+
function loadConfig45() {
|
|
5958
|
+
if (cachedConfig43) return cachedConfig43;
|
|
5959
|
+
if (!existsSync50(CONFIG_PATH47)) {
|
|
5960
|
+
cachedConfig43 = {};
|
|
5961
|
+
return cachedConfig43;
|
|
5712
5962
|
}
|
|
5713
|
-
const raw =
|
|
5963
|
+
const raw = readFileSync51(CONFIG_PATH47, "utf-8");
|
|
5714
5964
|
let parsed;
|
|
5715
5965
|
try {
|
|
5716
5966
|
parsed = JSON.parse(raw);
|
|
5717
5967
|
} catch (err) {
|
|
5718
5968
|
const message = err instanceof Error ? err.message : String(err);
|
|
5719
|
-
throw new Error(`Failed to parse ${
|
|
5969
|
+
throw new Error(`Failed to parse ${CONFIG_PATH47}: ${message}`);
|
|
5720
5970
|
}
|
|
5721
5971
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
5722
|
-
throw new Error(`Invalid config in ${
|
|
5972
|
+
throw new Error(`Invalid config in ${CONFIG_PATH47}: expected a JSON object`);
|
|
5723
5973
|
}
|
|
5724
|
-
|
|
5725
|
-
return
|
|
5974
|
+
cachedConfig43 = parsed;
|
|
5975
|
+
return cachedConfig43;
|
|
5726
5976
|
}
|
|
5727
|
-
async function
|
|
5977
|
+
async function requireApiKey21(signal) {
|
|
5728
5978
|
const apiKey = await resolveCredential({
|
|
5729
5979
|
provider: "DeepSeek",
|
|
5730
|
-
configuredValue:
|
|
5980
|
+
configuredValue: loadConfig45().deepseekApiKey,
|
|
5731
5981
|
environmentValue: process.env.DEEPSEEK_API_KEY,
|
|
5732
5982
|
signal
|
|
5733
5983
|
});
|
|
5734
5984
|
if (!apiKey) {
|
|
5735
5985
|
throw new Error(
|
|
5736
5986
|
`DeepSeek API key not found. Either:
|
|
5737
|
-
1. Create ${
|
|
5987
|
+
1. Create ${CONFIG_PATH47} with { "deepseekApiKey": "your-key" }
|
|
5738
5988
|
2. Set DEEPSEEK_API_KEY environment variable
|
|
5739
5989
|
Get a key at https://platform.deepseek.com/api_keys`
|
|
5740
5990
|
);
|
|
5741
5991
|
}
|
|
5742
5992
|
return apiKey;
|
|
5743
5993
|
}
|
|
5744
|
-
function
|
|
5994
|
+
function buildQuery13(query, options) {
|
|
5745
5995
|
const include = [];
|
|
5746
5996
|
const exclude = [];
|
|
5747
5997
|
for (const raw of options.domainFilter ?? []) {
|
|
@@ -5759,15 +6009,15 @@ function buildQuery11(query, options) {
|
|
|
5759
6009
|
}
|
|
5760
6010
|
const built = parts.join(" ");
|
|
5761
6011
|
const length = [...built].length;
|
|
5762
|
-
if (length >
|
|
5763
|
-
throw new Error(`DeepSeek invalid request: the query is ${length} characters with domain and date filters; DeepSeek accepts at most ${
|
|
6012
|
+
if (length > MAX_QUERY_CHARS3) {
|
|
6013
|
+
throw new Error(`DeepSeek invalid request: the query is ${length} characters with domain and date filters; DeepSeek accepts at most ${MAX_QUERY_CHARS3}`);
|
|
5764
6014
|
}
|
|
5765
6015
|
return built;
|
|
5766
6016
|
}
|
|
5767
6017
|
function text6(value) {
|
|
5768
6018
|
return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
5769
6019
|
}
|
|
5770
|
-
function
|
|
6020
|
+
function errorMessage33(err) {
|
|
5771
6021
|
return err instanceof Error ? err.message : String(err);
|
|
5772
6022
|
}
|
|
5773
6023
|
function unescapeMarkdownSegment(segment) {
|
|
@@ -5820,7 +6070,7 @@ function isUnusableDeepSeekPage(title, content) {
|
|
|
5820
6070
|
if (heading !== "" && ERROR_TITLE.test(heading)) return true;
|
|
5821
6071
|
return ERROR_TITLE.test(text6(title)) && /\b(?:404|page not found|not found)\b/i.test(content.slice(0, 200));
|
|
5822
6072
|
}
|
|
5823
|
-
function
|
|
6073
|
+
function parseResponse17(value) {
|
|
5824
6074
|
const results = value && typeof value === "object" && !Array.isArray(value) ? value.results : void 0;
|
|
5825
6075
|
if (!Array.isArray(results)) throw new Error("DeepSeek returned invalid response: expected a results array");
|
|
5826
6076
|
return results;
|
|
@@ -5835,18 +6085,18 @@ function describeError3(body) {
|
|
|
5835
6085
|
return body;
|
|
5836
6086
|
}
|
|
5837
6087
|
function isDeepSeekAvailable() {
|
|
5838
|
-
return hasCredentialSource({ provider: "DeepSeek", configuredValue:
|
|
6088
|
+
return hasCredentialSource({ provider: "DeepSeek", configuredValue: loadConfig45().deepseekApiKey, environmentValue: process.env.DEEPSEEK_API_KEY });
|
|
5839
6089
|
}
|
|
5840
6090
|
async function searchWithDeepSeek(query, options = {}) {
|
|
5841
|
-
const builtQuery =
|
|
5842
|
-
const apiKey = await
|
|
6091
|
+
const builtQuery = buildQuery13(query, options);
|
|
6092
|
+
const apiKey = await requireApiKey21(options.signal);
|
|
5843
6093
|
const numResults = normalizeSearchResultCount(options.numResults);
|
|
5844
6094
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
5845
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
6095
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS40);
|
|
5846
6096
|
let response;
|
|
5847
6097
|
let entries;
|
|
5848
6098
|
try {
|
|
5849
|
-
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_SEARCH_URL,
|
|
6099
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_SEARCH_URL, loadConfig45().deepseekBaseUrl), {
|
|
5850
6100
|
method: "POST",
|
|
5851
6101
|
headers: {
|
|
5852
6102
|
Accept: "application/json",
|
|
@@ -5865,24 +6115,24 @@ async function searchWithDeepSeek(query, options = {}) {
|
|
|
5865
6115
|
rawData = await response.json();
|
|
5866
6116
|
} catch (err) {
|
|
5867
6117
|
if (err instanceof Error && err.name === "TimeoutError") throw err;
|
|
5868
|
-
throw new Error(`DeepSeek returned invalid JSON: ${
|
|
6118
|
+
throw new Error(`DeepSeek returned invalid JSON: ${errorMessage33(err)}`);
|
|
5869
6119
|
}
|
|
5870
|
-
entries =
|
|
6120
|
+
entries = parseResponse17(rawData);
|
|
5871
6121
|
} catch (err) {
|
|
5872
6122
|
if (options.signal?.aborted) {
|
|
5873
6123
|
activityMonitor.logComplete(activityId, 0);
|
|
5874
6124
|
throw new Error("Aborted");
|
|
5875
6125
|
}
|
|
5876
|
-
const message =
|
|
6126
|
+
const message = errorMessage33(err);
|
|
5877
6127
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
5878
|
-
const outgoing = providerTimeout ? new Error(`DeepSeek request timed out after ${Math.round(
|
|
6128
|
+
const outgoing = providerTimeout ? new Error(`DeepSeek request timed out after ${Math.round(SEARCH_TIMEOUT_MS40 / 1e3)}s`) : (() => {
|
|
5879
6129
|
const redactedMessage = redactCredential(message, apiKey);
|
|
5880
6130
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
5881
6131
|
const redactedError = new Error(redactedMessage);
|
|
5882
6132
|
if (err instanceof Error) redactedError.name = err.name;
|
|
5883
6133
|
return redactedError;
|
|
5884
6134
|
})();
|
|
5885
|
-
activityMonitor.logError(activityId, redactCredential(
|
|
6135
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage33(outgoing), apiKey));
|
|
5886
6136
|
throw outgoing;
|
|
5887
6137
|
}
|
|
5888
6138
|
activityMonitor.logComplete(activityId, response.status);
|
|
@@ -5919,7 +6169,7 @@ async function searchWithDeepSeek(query, options = {}) {
|
|
|
5919
6169
|
return searchResponse;
|
|
5920
6170
|
}
|
|
5921
6171
|
async function extractWithDeepSeek(url, signal, options = {}) {
|
|
5922
|
-
const apiKey = await
|
|
6172
|
+
const apiKey = await requireApiKey21(signal);
|
|
5923
6173
|
const activityId = activityMonitor.logStart({ type: "fetch", url });
|
|
5924
6174
|
const timeoutMs = options.timeoutMs ?? FETCH_TIMEOUT_MS2;
|
|
5925
6175
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
@@ -5931,7 +6181,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
5931
6181
|
domainPolicy: loadFetchContentDomainPolicy(),
|
|
5932
6182
|
...options.lookup ? { lookup: options.lookup } : {}
|
|
5933
6183
|
});
|
|
5934
|
-
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_FETCH_URL,
|
|
6184
|
+
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_FETCH_URL, loadConfig45().deepseekBaseUrl), {
|
|
5935
6185
|
method: "POST",
|
|
5936
6186
|
headers: {
|
|
5937
6187
|
Accept: "application/json",
|
|
@@ -5950,7 +6200,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
5950
6200
|
rawData = await response.json();
|
|
5951
6201
|
} catch (err) {
|
|
5952
6202
|
if (err instanceof Error && err.name === "TimeoutError") throw err;
|
|
5953
|
-
throw new Error(`DeepSeek Fetch returned invalid JSON: ${
|
|
6203
|
+
throw new Error(`DeepSeek Fetch returned invalid JSON: ${errorMessage33(err)}`);
|
|
5954
6204
|
}
|
|
5955
6205
|
if (!rawData || typeof rawData !== "object" || Array.isArray(rawData)) {
|
|
5956
6206
|
throw new Error("DeepSeek Fetch returned an unexpected response shape");
|
|
@@ -5970,7 +6220,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
5970
6220
|
error: null
|
|
5971
6221
|
};
|
|
5972
6222
|
} catch (err) {
|
|
5973
|
-
const message =
|
|
6223
|
+
const message = errorMessage33(err);
|
|
5974
6224
|
if (signal?.aborted) {
|
|
5975
6225
|
activityMonitor.logComplete(activityId, 0);
|
|
5976
6226
|
throw new Error("Aborted");
|
|
@@ -5986,7 +6236,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
5986
6236
|
throw redactedError;
|
|
5987
6237
|
}
|
|
5988
6238
|
}
|
|
5989
|
-
var DEEPSEEK_SEARCH_URL, DEEPSEEK_FETCH_URL,
|
|
6239
|
+
var DEEPSEEK_SEARCH_URL, DEEPSEEK_FETCH_URL, CONFIG_PATH47, SEARCH_TIMEOUT_MS40, FETCH_TIMEOUT_MS2, MAX_QUERY_CHARS3, MAX_SNIPPET_CHARS6, RECENCY_DAYS2, cachedConfig43, ERROR_TITLE;
|
|
5990
6240
|
var init_deepseek = __esm({
|
|
5991
6241
|
"deepseek.ts"() {
|
|
5992
6242
|
init_activity();
|
|
@@ -5998,10 +6248,10 @@ var init_deepseek = __esm({
|
|
|
5998
6248
|
init_utils();
|
|
5999
6249
|
DEEPSEEK_SEARCH_URL = "https://api.deepseek.com/v1/tools/search";
|
|
6000
6250
|
DEEPSEEK_FETCH_URL = "https://api.deepseek.com/v1/tools/fetch";
|
|
6001
|
-
|
|
6002
|
-
|
|
6251
|
+
CONFIG_PATH47 = getWebSearchConfigPath();
|
|
6252
|
+
SEARCH_TIMEOUT_MS40 = 3e4;
|
|
6003
6253
|
FETCH_TIMEOUT_MS2 = 6e4;
|
|
6004
|
-
|
|
6254
|
+
MAX_QUERY_CHARS3 = 128;
|
|
6005
6255
|
MAX_SNIPPET_CHARS6 = 800;
|
|
6006
6256
|
RECENCY_DAYS2 = {
|
|
6007
6257
|
day: 1,
|
|
@@ -6009,13 +6259,13 @@ var init_deepseek = __esm({
|
|
|
6009
6259
|
month: 30,
|
|
6010
6260
|
year: 365
|
|
6011
6261
|
};
|
|
6012
|
-
|
|
6262
|
+
cachedConfig43 = null;
|
|
6013
6263
|
ERROR_TITLE = /^(?:404\b|page not found\b|not found\b)/i;
|
|
6014
6264
|
}
|
|
6015
6265
|
});
|
|
6016
6266
|
|
|
6017
6267
|
// auth-fetch.ts
|
|
6018
|
-
import { existsSync as
|
|
6268
|
+
import { existsSync as existsSync53, readFileSync as readFileSync54 } from "node:fs";
|
|
6019
6269
|
function resolveAuthFetchProfile(request) {
|
|
6020
6270
|
const profiles = loadAuthFetchProfiles();
|
|
6021
6271
|
if (profiles.length === 0) {
|
|
@@ -6053,8 +6303,8 @@ function authFetchRedirectGuard(profile, from, to) {
|
|
|
6053
6303
|
}
|
|
6054
6304
|
}
|
|
6055
6305
|
function loadAuthFetchProfiles() {
|
|
6056
|
-
if (!
|
|
6057
|
-
const raw =
|
|
6306
|
+
if (!existsSync53(WEB_SEARCH_CONFIG_PATH2)) return [];
|
|
6307
|
+
const raw = readFileSync54(WEB_SEARCH_CONFIG_PATH2, "utf-8");
|
|
6058
6308
|
let parsed;
|
|
6059
6309
|
try {
|
|
6060
6310
|
const value = JSON.parse(raw);
|
|
@@ -6454,20 +6704,20 @@ var init_rsc_extract = __esm({
|
|
|
6454
6704
|
});
|
|
6455
6705
|
|
|
6456
6706
|
// datalab-pdf-extract.ts
|
|
6457
|
-
import { existsSync as
|
|
6458
|
-
function
|
|
6459
|
-
if (
|
|
6460
|
-
if (!
|
|
6461
|
-
|
|
6462
|
-
return
|
|
6707
|
+
import { existsSync as existsSync54, readFileSync as readFileSync56 } from "node:fs";
|
|
6708
|
+
function loadConfig47() {
|
|
6709
|
+
if (cachedConfig45) return cachedConfig45;
|
|
6710
|
+
if (!existsSync54(CONFIG_PATH50)) {
|
|
6711
|
+
cachedConfig45 = {};
|
|
6712
|
+
return cachedConfig45;
|
|
6463
6713
|
}
|
|
6464
|
-
const rawText =
|
|
6714
|
+
const rawText = readFileSync56(CONFIG_PATH50, "utf-8");
|
|
6465
6715
|
try {
|
|
6466
|
-
|
|
6467
|
-
return
|
|
6716
|
+
cachedConfig45 = JSON.parse(rawText);
|
|
6717
|
+
return cachedConfig45;
|
|
6468
6718
|
} catch (err) {
|
|
6469
6719
|
const message = err instanceof Error ? err.message : String(err);
|
|
6470
|
-
throw new Error(`Failed to parse ${
|
|
6720
|
+
throw new Error(`Failed to parse ${CONFIG_PATH50}: ${message}`);
|
|
6471
6721
|
}
|
|
6472
6722
|
}
|
|
6473
6723
|
function normalizeString(value) {
|
|
@@ -6482,14 +6732,14 @@ function normalizeFileId(value) {
|
|
|
6482
6732
|
function isDatalabApiAvailable() {
|
|
6483
6733
|
return hasCredentialSource({
|
|
6484
6734
|
provider: "Datalab",
|
|
6485
|
-
configuredValue:
|
|
6735
|
+
configuredValue: loadConfig47().datalabApiKey,
|
|
6486
6736
|
environmentValue: process.env.DATALAB_API_KEY
|
|
6487
6737
|
});
|
|
6488
6738
|
}
|
|
6489
6739
|
async function getDatalabApiKey(signal) {
|
|
6490
6740
|
return resolveCredential({
|
|
6491
6741
|
provider: "Datalab",
|
|
6492
|
-
configuredValue:
|
|
6742
|
+
configuredValue: loadConfig47().datalabApiKey,
|
|
6493
6743
|
environmentValue: process.env.DATALAB_API_KEY,
|
|
6494
6744
|
signal
|
|
6495
6745
|
});
|
|
@@ -6814,7 +7064,7 @@ async function readResponseText(response) {
|
|
|
6814
7064
|
function datalabFilename(title) {
|
|
6815
7065
|
return title.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "document";
|
|
6816
7066
|
}
|
|
6817
|
-
var DEFAULT_API_HOST2, API_PREFIX, DEFAULT_TIMEOUT_MS2, DEFAULT_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES, MAX_ERROR_BODY_BYTES, CLEANUP_TIMEOUT_MS,
|
|
7067
|
+
var DEFAULT_API_HOST2, API_PREFIX, DEFAULT_TIMEOUT_MS2, DEFAULT_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES, MAX_ERROR_BODY_BYTES, CLEANUP_TIMEOUT_MS, CONFIG_PATH50, DATALAB_MODE_VALUES, DATALAB_LOCATION_VALUES, DEFAULT_DATALAB_MODE, DEFAULT_PROCESSING_LOCATION, DEFAULT_DATALAB_TIMEOUT_MS, cachedConfig45;
|
|
6818
7068
|
var init_datalab_pdf_extract = __esm({
|
|
6819
7069
|
"datalab-pdf-extract.ts"() {
|
|
6820
7070
|
init_credential_source();
|
|
@@ -6826,7 +7076,7 @@ var init_datalab_pdf_extract = __esm({
|
|
|
6826
7076
|
MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
6827
7077
|
MAX_ERROR_BODY_BYTES = 300;
|
|
6828
7078
|
CLEANUP_TIMEOUT_MS = 5e3;
|
|
6829
|
-
|
|
7079
|
+
CONFIG_PATH50 = getWebSearchConfigPath();
|
|
6830
7080
|
DATALAB_MODE_VALUES = /* @__PURE__ */ new Set([
|
|
6831
7081
|
"fast",
|
|
6832
7082
|
"balanced",
|
|
@@ -6839,21 +7089,21 @@ var init_datalab_pdf_extract = __esm({
|
|
|
6839
7089
|
DEFAULT_DATALAB_MODE = "balanced";
|
|
6840
7090
|
DEFAULT_PROCESSING_LOCATION = "us";
|
|
6841
7091
|
DEFAULT_DATALAB_TIMEOUT_MS = DEFAULT_TIMEOUT_MS2;
|
|
6842
|
-
|
|
7092
|
+
cachedConfig45 = null;
|
|
6843
7093
|
}
|
|
6844
7094
|
});
|
|
6845
7095
|
|
|
6846
7096
|
// endpoint-pdf-extract.ts
|
|
6847
|
-
import { existsSync as
|
|
7097
|
+
import { existsSync as existsSync55, readFileSync as readFileSync57 } from "node:fs";
|
|
6848
7098
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
6849
7099
|
function pdfSection() {
|
|
6850
|
-
if (!
|
|
7100
|
+
if (!existsSync55(CONFIG_PATH51)) return {};
|
|
6851
7101
|
let parsed;
|
|
6852
7102
|
try {
|
|
6853
|
-
parsed = JSON.parse(
|
|
7103
|
+
parsed = JSON.parse(readFileSync57(CONFIG_PATH51, "utf-8"));
|
|
6854
7104
|
} catch (err) {
|
|
6855
7105
|
const message = err instanceof Error ? err.message : String(err);
|
|
6856
|
-
throw new Error(`Failed to parse ${
|
|
7106
|
+
throw new Error(`Failed to parse ${CONFIG_PATH51}: ${message}`);
|
|
6857
7107
|
}
|
|
6858
7108
|
const pdf = parsed?.pdf;
|
|
6859
7109
|
return pdf && typeof pdf === "object" ? pdf : {};
|
|
@@ -6909,7 +7159,7 @@ async function readCapped(response, maxBytes, overflowThrows) {
|
|
|
6909
7159
|
text7 += decoder.decode(value, { stream: true });
|
|
6910
7160
|
}
|
|
6911
7161
|
}
|
|
6912
|
-
async function
|
|
7162
|
+
async function readJson2(response) {
|
|
6913
7163
|
const text7 = await readCapped(response, MAX_RESPONSE_BYTES2, true);
|
|
6914
7164
|
try {
|
|
6915
7165
|
const parsed = JSON.parse(text7);
|
|
@@ -6969,7 +7219,7 @@ async function extractPDFViaEndpoint(buffer, options) {
|
|
|
6969
7219
|
`PDF parser endpoint returned HTTP ${response.status}${await errorBody(response)}`
|
|
6970
7220
|
);
|
|
6971
7221
|
}
|
|
6972
|
-
let payload = await
|
|
7222
|
+
let payload = await readJson2(response);
|
|
6973
7223
|
const jobId = normalizeString2(payload.job_id);
|
|
6974
7224
|
if (typeof payload.markdown === "string" || !jobId) {
|
|
6975
7225
|
return markdownResult(payload);
|
|
@@ -6983,7 +7233,7 @@ async function extractPDFViaEndpoint(buffer, options) {
|
|
|
6983
7233
|
`PDF parser job status returned HTTP ${poll.status}${await errorBody(poll)}`
|
|
6984
7234
|
);
|
|
6985
7235
|
}
|
|
6986
|
-
payload = await
|
|
7236
|
+
payload = await readJson2(poll);
|
|
6987
7237
|
const status = normalizeString2(payload.status)?.toLowerCase();
|
|
6988
7238
|
if (status === "error" || status === "failed") {
|
|
6989
7239
|
const error = normalizeString2(payload.error) ?? "unknown parser error";
|
|
@@ -7005,7 +7255,7 @@ async function extractPDFViaEndpoint(buffer, options) {
|
|
|
7005
7255
|
}
|
|
7006
7256
|
throw new Error("PDF parser endpoint job timed out");
|
|
7007
7257
|
}
|
|
7008
|
-
var DEFAULT_TIMEOUT_MS3, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2,
|
|
7258
|
+
var DEFAULT_TIMEOUT_MS3, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2, CONFIG_PATH51;
|
|
7009
7259
|
var init_endpoint_pdf_extract = __esm({
|
|
7010
7260
|
"endpoint-pdf-extract.ts"() {
|
|
7011
7261
|
init_ssrf_protection();
|
|
@@ -7014,7 +7264,7 @@ var init_endpoint_pdf_extract = __esm({
|
|
|
7014
7264
|
MAX_POLL_INTERVAL_MS = 3e3;
|
|
7015
7265
|
MAX_RESPONSE_BYTES2 = 4 * 1024 * 1024;
|
|
7016
7266
|
MAX_ERROR_BODY_BYTES2 = 300;
|
|
7017
|
-
|
|
7267
|
+
CONFIG_PATH51 = getWebSearchConfigPath();
|
|
7018
7268
|
}
|
|
7019
7269
|
});
|
|
7020
7270
|
|
|
@@ -7104,12 +7354,12 @@ var init_gemini_pdf_extract = __esm({
|
|
|
7104
7354
|
});
|
|
7105
7355
|
|
|
7106
7356
|
// pdf-extract.ts
|
|
7107
|
-
import { existsSync as
|
|
7357
|
+
import { existsSync as existsSync56, readFileSync as readFileSync58 } from "node:fs";
|
|
7108
7358
|
import { writeFile as writeFile2, mkdir } from "node:fs/promises";
|
|
7109
|
-
import { join as
|
|
7359
|
+
import { join as join6, basename as basename2 } from "node:path";
|
|
7110
7360
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
7111
7361
|
function loadPDFConfig() {
|
|
7112
|
-
if (!
|
|
7362
|
+
if (!existsSync56(CONFIG_PATH52)) {
|
|
7113
7363
|
return {
|
|
7114
7364
|
enabled: true,
|
|
7115
7365
|
maxSizeMB: DEFAULT_PDF_MAX_SIZE_MB,
|
|
@@ -7119,13 +7369,13 @@ function loadPDFConfig() {
|
|
|
7119
7369
|
datalabTimeoutMs: DEFAULT_DATALAB_TIMEOUT_MS
|
|
7120
7370
|
};
|
|
7121
7371
|
}
|
|
7122
|
-
const rawText =
|
|
7372
|
+
const rawText = readFileSync58(CONFIG_PATH52, "utf-8");
|
|
7123
7373
|
let raw;
|
|
7124
7374
|
try {
|
|
7125
7375
|
raw = JSON.parse(rawText);
|
|
7126
7376
|
} catch (err) {
|
|
7127
7377
|
const message = err instanceof Error ? err.message : String(err);
|
|
7128
|
-
throw new Error(`Failed to parse ${
|
|
7378
|
+
throw new Error(`Failed to parse ${CONFIG_PATH52}: ${message}`);
|
|
7129
7379
|
}
|
|
7130
7380
|
const root = raw && typeof raw === "object" ? raw : {};
|
|
7131
7381
|
const pdf = root.pdf && typeof root.pdf === "object" ? root.pdf : {};
|
|
@@ -7310,7 +7560,7 @@ async function writeMarkdownResult(options) {
|
|
|
7310
7560
|
}
|
|
7311
7561
|
const content = lines.join("\n");
|
|
7312
7562
|
const outputFilename = options.filename || sanitizeFilename(options.title) + ".md";
|
|
7313
|
-
const outputPath =
|
|
7563
|
+
const outputPath = join6(options.outputDir, outputFilename);
|
|
7314
7564
|
await mkdir(options.outputDir, { recursive: true });
|
|
7315
7565
|
await writeFile2(outputPath, content, "utf-8");
|
|
7316
7566
|
return {
|
|
@@ -7359,7 +7609,7 @@ function isPDF(url, contentType) {
|
|
|
7359
7609
|
return false;
|
|
7360
7610
|
}
|
|
7361
7611
|
}
|
|
7362
|
-
var PDF_PROVIDER_VALUES, DEFAULT_PDF_MAX_SIZE_MB, MAX_PDF_MAX_SIZE_MB, MAX_DATALAB_TIMEOUT_MS, DEFAULT_MAX_PAGES, DEFAULT_OUTPUT_DIR,
|
|
7612
|
+
var PDF_PROVIDER_VALUES, DEFAULT_PDF_MAX_SIZE_MB, MAX_PDF_MAX_SIZE_MB, MAX_DATALAB_TIMEOUT_MS, DEFAULT_MAX_PAGES, DEFAULT_OUTPUT_DIR, CONFIG_PATH52, PAGE_MARKER_PATTERN2;
|
|
7363
7613
|
var init_pdf_extract = __esm({
|
|
7364
7614
|
"pdf-extract.ts"() {
|
|
7365
7615
|
init_credential_source();
|
|
@@ -7379,8 +7629,8 @@ var init_pdf_extract = __esm({
|
|
|
7379
7629
|
MAX_PDF_MAX_SIZE_MB = 50;
|
|
7380
7630
|
MAX_DATALAB_TIMEOUT_MS = 3e5;
|
|
7381
7631
|
DEFAULT_MAX_PAGES = 100;
|
|
7382
|
-
DEFAULT_OUTPUT_DIR =
|
|
7383
|
-
|
|
7632
|
+
DEFAULT_OUTPUT_DIR = join6(tmpdir3(), "pi-web-pdf");
|
|
7633
|
+
CONFIG_PATH52 = getWebSearchConfigPath();
|
|
7384
7634
|
PAGE_MARKER_PATTERN2 = /^<!-- Page (\d+) -->$/gm;
|
|
7385
7635
|
}
|
|
7386
7636
|
});
|
|
@@ -7560,11 +7810,11 @@ var init_github_api = __esm({
|
|
|
7560
7810
|
});
|
|
7561
7811
|
|
|
7562
7812
|
// github-extract.ts
|
|
7563
|
-
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as
|
|
7813
|
+
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as existsSync57, lstatSync as lstatSync2, mkdirSync as mkdirSync3, mkdtempSync as mkdtempSync2, openSync as openSync2, readFileSync as readFileSync59, readSync, readdirSync as readdirSync3, realpathSync as realpathSync2, rmSync as rmSync2, statSync as statSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
7564
7814
|
import { lstat as lstatAsync, open as openAsync, opendir as opendirAsync, readFile as readFileAsync, realpath as realpathAsync, rm as rmAsync } from "node:fs/promises";
|
|
7565
7815
|
import { execFile as execFile4, spawn as spawn2 } from "node:child_process";
|
|
7566
7816
|
import { createHash as createHash2 } from "node:crypto";
|
|
7567
|
-
import { basename as basename3, dirname, extname, join as
|
|
7817
|
+
import { basename as basename3, dirname as dirname2, extname, join as join7, resolve as resolvePath, sep as pathSep } from "node:path";
|
|
7568
7818
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
7569
7819
|
function normalizeEnabled(value, fallback) {
|
|
7570
7820
|
return typeof value === "boolean" ? value : fallback;
|
|
@@ -7590,33 +7840,33 @@ function normalizeClonePath(value, fallback) {
|
|
|
7590
7840
|
return expandPath(normalized);
|
|
7591
7841
|
}
|
|
7592
7842
|
function loadGitHubConfig() {
|
|
7593
|
-
if (
|
|
7843
|
+
if (cachedConfig46) return cachedConfig46;
|
|
7594
7844
|
const defaults2 = {
|
|
7595
7845
|
enabled: true,
|
|
7596
7846
|
maxRepoSizeMB: 350,
|
|
7597
7847
|
cloneTimeoutSeconds: 30,
|
|
7598
|
-
clonePath:
|
|
7848
|
+
clonePath: join7(tmpdir4(), "pi-github-repos")
|
|
7599
7849
|
};
|
|
7600
|
-
if (!
|
|
7601
|
-
|
|
7602
|
-
return
|
|
7850
|
+
if (!existsSync57(CONFIG_PATH53)) {
|
|
7851
|
+
cachedConfig46 = defaults2;
|
|
7852
|
+
return cachedConfig46;
|
|
7603
7853
|
}
|
|
7604
|
-
const rawText =
|
|
7854
|
+
const rawText = readFileSync59(CONFIG_PATH53, "utf-8");
|
|
7605
7855
|
let raw;
|
|
7606
7856
|
try {
|
|
7607
7857
|
raw = JSON.parse(rawText);
|
|
7608
7858
|
} catch (err) {
|
|
7609
7859
|
const message = err instanceof Error ? err.message : String(err);
|
|
7610
|
-
throw new Error(`Failed to parse ${
|
|
7860
|
+
throw new Error(`Failed to parse ${CONFIG_PATH53}: ${message}`);
|
|
7611
7861
|
}
|
|
7612
7862
|
const gc = raw.githubClone ?? {};
|
|
7613
|
-
|
|
7863
|
+
cachedConfig46 = {
|
|
7614
7864
|
enabled: normalizeEnabled(gc.enabled, defaults2.enabled),
|
|
7615
7865
|
maxRepoSizeMB: normalizePositiveNumber(gc.maxRepoSizeMB, defaults2.maxRepoSizeMB),
|
|
7616
7866
|
cloneTimeoutSeconds: normalizePositiveNumber(gc.cloneTimeoutSeconds, defaults2.cloneTimeoutSeconds),
|
|
7617
7867
|
clonePath: normalizeClonePath(gc.clonePath, defaults2.clonePath)
|
|
7618
7868
|
};
|
|
7619
|
-
return
|
|
7869
|
+
return cachedConfig46;
|
|
7620
7870
|
}
|
|
7621
7871
|
function parseGitHubUrl(url) {
|
|
7622
7872
|
let parsed;
|
|
@@ -7667,7 +7917,7 @@ function cacheKey(owner, repo, ref) {
|
|
|
7667
7917
|
}
|
|
7668
7918
|
function readLinuxBootId() {
|
|
7669
7919
|
try {
|
|
7670
|
-
const bootId =
|
|
7920
|
+
const bootId = readFileSync59("/proc/sys/kernel/random/boot_id", "utf-8").trim();
|
|
7671
7921
|
return bootId.length > 0 ? bootId : null;
|
|
7672
7922
|
} catch {
|
|
7673
7923
|
return null;
|
|
@@ -7692,7 +7942,7 @@ function parseLinuxProcessInfo(stat) {
|
|
|
7692
7942
|
}
|
|
7693
7943
|
function readLinuxProcessInfo(pid) {
|
|
7694
7944
|
try {
|
|
7695
|
-
return parseLinuxProcessInfo(
|
|
7945
|
+
return parseLinuxProcessInfo(readFileSync59(`/proc/${pid}/stat`, "utf-8"));
|
|
7696
7946
|
} catch (err) {
|
|
7697
7947
|
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
7698
7948
|
return { state: "", startTime: null, dead: true };
|
|
@@ -7727,8 +7977,8 @@ function currentCloneRuntimeOwner() {
|
|
|
7727
7977
|
return owner;
|
|
7728
7978
|
}
|
|
7729
7979
|
function writeCloneRuntimeOwner(runtimePath) {
|
|
7730
|
-
const ownerPath =
|
|
7731
|
-
|
|
7980
|
+
const ownerPath = join7(runtimePath, CLONE_RUNTIME_OWNER_FILENAME);
|
|
7981
|
+
writeFileSync3(ownerPath, JSON.stringify(currentCloneRuntimeOwner()), {
|
|
7732
7982
|
encoding: "utf-8",
|
|
7733
7983
|
flag: "wx",
|
|
7734
7984
|
mode: 384
|
|
@@ -7762,7 +8012,7 @@ function parseCloneRuntimeOwner(text7) {
|
|
|
7762
8012
|
return owner;
|
|
7763
8013
|
}
|
|
7764
8014
|
async function readCloneRuntimeOwner(runtimePath) {
|
|
7765
|
-
const ownerPath =
|
|
8015
|
+
const ownerPath = join7(runtimePath, CLONE_RUNTIME_OWNER_FILENAME);
|
|
7766
8016
|
let file;
|
|
7767
8017
|
try {
|
|
7768
8018
|
const entry = await lstatAsync(ownerPath);
|
|
@@ -7805,10 +8055,10 @@ async function cloneRuntimeOwnerIsDead(owner, bootId) {
|
|
|
7805
8055
|
async function removeCloneRuntimeAsync(parentPath, runtimePath) {
|
|
7806
8056
|
const normalizedParentPath = resolvePath(parentPath);
|
|
7807
8057
|
const normalizedRuntimePath = resolvePath(runtimePath);
|
|
7808
|
-
if (
|
|
8058
|
+
if (dirname2(normalizedRuntimePath) !== normalizedParentPath || !basename3(normalizedRuntimePath).startsWith("runtime-")) return;
|
|
7809
8059
|
try {
|
|
7810
8060
|
const realRuntimePath = await realpathAsync(normalizedRuntimePath);
|
|
7811
|
-
if (
|
|
8061
|
+
if (dirname2(realRuntimePath) !== normalizedParentPath || basename3(realRuntimePath) !== basename3(normalizedRuntimePath)) return;
|
|
7812
8062
|
const entry = await lstatAsync(normalizedRuntimePath);
|
|
7813
8063
|
if (entry.isSymbolicLink() || !entry.isDirectory()) return;
|
|
7814
8064
|
await rmAsync(normalizedRuntimePath, { recursive: true, force: true });
|
|
@@ -7825,11 +8075,11 @@ async function sweepStaleCloneRuntimes(parentPath) {
|
|
|
7825
8075
|
try {
|
|
7826
8076
|
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
|
|
7827
8077
|
const runtimePath = resolvePath(normalizedParentPath, entry.name);
|
|
7828
|
-
if (
|
|
8078
|
+
if (dirname2(runtimePath) !== normalizedParentPath) continue;
|
|
7829
8079
|
const runtimeEntry = await lstatAsync(runtimePath);
|
|
7830
8080
|
if (!runtimeEntry.isDirectory() || runtimeEntry.isSymbolicLink()) continue;
|
|
7831
8081
|
const realRuntimePath = await realpathAsync(runtimePath);
|
|
7832
|
-
if (
|
|
8082
|
+
if (dirname2(realRuntimePath) !== normalizedParentPath || basename3(realRuntimePath) !== basename3(runtimePath)) continue;
|
|
7833
8083
|
const owner = await readCloneRuntimeOwner(runtimePath);
|
|
7834
8084
|
if (!owner || !await cloneRuntimeOwnerIsDead(owner, bootId)) continue;
|
|
7835
8085
|
await removeCloneRuntimeAsync(normalizedParentPath, runtimePath);
|
|
@@ -7849,7 +8099,7 @@ function startStaleCloneRuntimeCleanup(parentPath) {
|
|
|
7849
8099
|
function removeCloneRuntime(parentPath, runtimePath) {
|
|
7850
8100
|
const normalizedParentPath = resolvePath(parentPath);
|
|
7851
8101
|
const normalizedRuntimePath = resolvePath(runtimePath);
|
|
7852
|
-
if (
|
|
8102
|
+
if (dirname2(normalizedRuntimePath) !== normalizedParentPath || !basename3(normalizedRuntimePath).startsWith("runtime-")) return;
|
|
7853
8103
|
try {
|
|
7854
8104
|
const entry = lstatSync2(normalizedRuntimePath);
|
|
7855
8105
|
if (entry.isSymbolicLink()) unlinkSync2(normalizedRuntimePath);
|
|
@@ -7863,13 +8113,13 @@ function getCloneRuntimeRoot(config) {
|
|
|
7863
8113
|
let runtimePath = null;
|
|
7864
8114
|
try {
|
|
7865
8115
|
const configuredPath = resolvePath(config.clonePath);
|
|
7866
|
-
|
|
8116
|
+
mkdirSync3(configuredPath, { recursive: true });
|
|
7867
8117
|
parentPath = realpathSync2(configuredPath);
|
|
7868
8118
|
startStaleCloneRuntimeCleanup(parentPath);
|
|
7869
|
-
runtimePath = mkdtempSync2(
|
|
8119
|
+
runtimePath = mkdtempSync2(join7(parentPath, "runtime-"));
|
|
7870
8120
|
chmodSync(runtimePath, 448);
|
|
7871
8121
|
const rootPath = realpathSync2(runtimePath);
|
|
7872
|
-
if (
|
|
8122
|
+
if (dirname2(rootPath) !== parentPath) {
|
|
7873
8123
|
removeCloneRuntime(parentPath, runtimePath);
|
|
7874
8124
|
return null;
|
|
7875
8125
|
}
|
|
@@ -7887,7 +8137,7 @@ function cloneDestination(config, owner, repo, ref) {
|
|
|
7887
8137
|
if (!rootPath) return null;
|
|
7888
8138
|
const digest = createHash2("sha256").update(JSON.stringify([owner, repo, ref ?? null])).digest("hex");
|
|
7889
8139
|
const localPath = resolvePath(rootPath, digest);
|
|
7890
|
-
if (
|
|
8140
|
+
if (dirname2(localPath) !== rootPath) return null;
|
|
7891
8141
|
return { rootPath, localPath };
|
|
7892
8142
|
} catch {
|
|
7893
8143
|
return null;
|
|
@@ -7896,7 +8146,7 @@ function cloneDestination(config, owner, repo, ref) {
|
|
|
7896
8146
|
function removeCloneDestination(destination) {
|
|
7897
8147
|
const rootPath = resolvePath(destination.rootPath);
|
|
7898
8148
|
const localPath = resolvePath(destination.localPath);
|
|
7899
|
-
if (
|
|
8149
|
+
if (dirname2(localPath) !== rootPath || !/^[0-9a-f]{64}$/.test(basename3(localPath))) return false;
|
|
7900
8150
|
try {
|
|
7901
8151
|
const entry = lstatSync2(localPath);
|
|
7902
8152
|
if (entry.isSymbolicLink()) unlinkSync2(localPath);
|
|
@@ -8030,7 +8280,7 @@ function resolveWithinRepo(rootPath, relativePath) {
|
|
|
8030
8280
|
const rootPrefix = normalizedRoot.endsWith(pathSep) ? normalizedRoot : normalizedRoot + pathSep;
|
|
8031
8281
|
if (!candidate.startsWith(rootPrefix)) return null;
|
|
8032
8282
|
}
|
|
8033
|
-
if (!
|
|
8283
|
+
if (!existsSync57(candidate)) return candidate;
|
|
8034
8284
|
try {
|
|
8035
8285
|
const realRoot = realpathSync2(normalizedRoot);
|
|
8036
8286
|
const realCandidate = realpathSync2(candidate);
|
|
@@ -8043,7 +8293,7 @@ function resolveWithinRepo(rootPath, relativePath) {
|
|
|
8043
8293
|
}
|
|
8044
8294
|
function readTextFile(path) {
|
|
8045
8295
|
try {
|
|
8046
|
-
return
|
|
8296
|
+
return readFileSync59(path, "utf-8");
|
|
8047
8297
|
} catch {
|
|
8048
8298
|
return null;
|
|
8049
8299
|
}
|
|
@@ -8125,10 +8375,10 @@ function buildDirListing(rootPath, subPath) {
|
|
|
8125
8375
|
function readReadme(localPath) {
|
|
8126
8376
|
const candidates = ["README.md", "readme.md", "README", "README.txt", "README.rst"];
|
|
8127
8377
|
for (const name of candidates) {
|
|
8128
|
-
const readmePath =
|
|
8129
|
-
if (
|
|
8378
|
+
const readmePath = join7(localPath, name);
|
|
8379
|
+
if (existsSync57(readmePath)) {
|
|
8130
8380
|
try {
|
|
8131
|
-
const content =
|
|
8381
|
+
const content = readFileSync59(readmePath, "utf-8");
|
|
8132
8382
|
return content.length > MAX_INLINE_FILE_CHARS2 ? `${content.slice(0, MAX_INLINE_FILE_CHARS2)}
|
|
8133
8383
|
|
|
8134
8384
|
[README truncated at 100K chars. Full file: ${readmePath}]` : content;
|
|
@@ -8159,7 +8409,7 @@ function generateContent(localPath, info) {
|
|
|
8159
8409
|
if (info.type === "tree") {
|
|
8160
8410
|
const dirPath = info.path || "";
|
|
8161
8411
|
const fullDirPath = resolveWithinRepo(localPath, dirPath);
|
|
8162
|
-
if (!fullDirPath || !
|
|
8412
|
+
if (!fullDirPath || !existsSync57(fullDirPath)) {
|
|
8163
8413
|
lines.push(`Path \`${dirPath}\` not found in clone. Showing repository root instead.`);
|
|
8164
8414
|
lines.push("");
|
|
8165
8415
|
lines.push("## Structure");
|
|
@@ -8175,7 +8425,7 @@ function generateContent(localPath, info) {
|
|
|
8175
8425
|
if (info.type === "blob") {
|
|
8176
8426
|
const filePath = info.path || "";
|
|
8177
8427
|
const fullFilePath = resolveWithinRepo(localPath, filePath);
|
|
8178
|
-
if (!fullFilePath || !
|
|
8428
|
+
if (!fullFilePath || !existsSync57(fullFilePath)) {
|
|
8179
8429
|
lines.push(`Path \`${filePath}\` not found in clone. Showing repository root instead.`);
|
|
8180
8430
|
lines.push("");
|
|
8181
8431
|
lines.push("## Structure");
|
|
@@ -8337,13 +8587,13 @@ async function extractGitHub(url, signal, forceClone) {
|
|
|
8337
8587
|
const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
|
|
8338
8588
|
return { url, title, content, error: null };
|
|
8339
8589
|
}
|
|
8340
|
-
var
|
|
8590
|
+
var CONFIG_PATH53, BINARY_EXTENSIONS, NOISE_DIRS, MAX_INLINE_FILE_CHARS2, MAX_TREE_ENTRIES2, CLONE_RUNTIME_OWNER_FILENAME, CLONE_RUNTIME_OWNER_VERSION, MAX_CLONE_RUNTIME_OWNER_BYTES, cloneCache, startedCloneRuntimeCleanups, cachedConfig46, cloneRuntime, NON_CODE_SEGMENTS, PROCESS_KILL_GRACE_MS;
|
|
8341
8591
|
var init_github_extract = __esm({
|
|
8342
8592
|
"github-extract.ts"() {
|
|
8343
8593
|
init_activity();
|
|
8344
8594
|
init_github_api();
|
|
8345
8595
|
init_utils();
|
|
8346
|
-
|
|
8596
|
+
CONFIG_PATH53 = getWebSearchConfigPath();
|
|
8347
8597
|
BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
8348
8598
|
".png",
|
|
8349
8599
|
".jpg",
|
|
@@ -8431,7 +8681,7 @@ var init_github_extract = __esm({
|
|
|
8431
8681
|
MAX_CLONE_RUNTIME_OWNER_BYTES = 1024;
|
|
8432
8682
|
cloneCache = /* @__PURE__ */ new Map();
|
|
8433
8683
|
startedCloneRuntimeCleanups = /* @__PURE__ */ new Set();
|
|
8434
|
-
|
|
8684
|
+
cachedConfig46 = null;
|
|
8435
8685
|
cloneRuntime = null;
|
|
8436
8686
|
NON_CODE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
8437
8687
|
"issues",
|
|
@@ -8470,29 +8720,29 @@ var init_github_extract = __esm({
|
|
|
8470
8720
|
|
|
8471
8721
|
// github-issue-pr.ts
|
|
8472
8722
|
import { execFile as execFile5 } from "node:child_process";
|
|
8473
|
-
import { existsSync as
|
|
8474
|
-
function
|
|
8475
|
-
if (
|
|
8723
|
+
import { existsSync as existsSync58, readFileSync as readFileSync60 } from "node:fs";
|
|
8724
|
+
function loadConfig48() {
|
|
8725
|
+
if (cachedConfig47) return cachedConfig47;
|
|
8476
8726
|
const defaults2 = { enabled: true };
|
|
8477
|
-
if (!
|
|
8478
|
-
|
|
8479
|
-
return
|
|
8727
|
+
if (!existsSync58(CONFIG_PATH54)) {
|
|
8728
|
+
cachedConfig47 = defaults2;
|
|
8729
|
+
return cachedConfig47;
|
|
8480
8730
|
}
|
|
8481
8731
|
let parsed;
|
|
8482
8732
|
try {
|
|
8483
|
-
parsed = JSON.parse(
|
|
8733
|
+
parsed = JSON.parse(readFileSync60(CONFIG_PATH54, "utf-8"));
|
|
8484
8734
|
} catch (err) {
|
|
8485
8735
|
const message = err instanceof Error ? err.message : String(err);
|
|
8486
|
-
throw new Error(`Failed to parse ${
|
|
8736
|
+
throw new Error(`Failed to parse ${CONFIG_PATH54}: ${message}`);
|
|
8487
8737
|
}
|
|
8488
8738
|
const root = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
8489
8739
|
const value = root.githubPrIssue;
|
|
8490
8740
|
if (value !== void 0 && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
8491
|
-
throw new Error(`githubPrIssue in ${
|
|
8741
|
+
throw new Error(`githubPrIssue in ${CONFIG_PATH54} must be an object`);
|
|
8492
8742
|
}
|
|
8493
8743
|
const enabled = typeof value?.enabled === "boolean" ? value.enabled : true;
|
|
8494
|
-
|
|
8495
|
-
return
|
|
8744
|
+
cachedConfig47 = { enabled };
|
|
8745
|
+
return cachedConfig47;
|
|
8496
8746
|
}
|
|
8497
8747
|
function validOwner(owner) {
|
|
8498
8748
|
return /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/.test(owner) && !owner.includes("--");
|
|
@@ -8500,11 +8750,11 @@ function validOwner(owner) {
|
|
|
8500
8750
|
function validRepo(repo) {
|
|
8501
8751
|
return /^[A-Za-z0-9._-]{1,100}$/.test(repo) && repo !== "." && repo !== "..";
|
|
8502
8752
|
}
|
|
8503
|
-
function
|
|
8753
|
+
function errorMessage36(err) {
|
|
8504
8754
|
return err instanceof Error ? err.message : String(err);
|
|
8505
8755
|
}
|
|
8506
8756
|
function isAbortError3(err) {
|
|
8507
|
-
return
|
|
8757
|
+
return errorMessage36(err).toLowerCase().includes("abort");
|
|
8508
8758
|
}
|
|
8509
8759
|
function parseGitHubIssuePrUrl(url) {
|
|
8510
8760
|
let parsed;
|
|
@@ -8740,7 +8990,7 @@ async function restFallback(url, info, options, signal) {
|
|
|
8740
8990
|
return { data: { url, owner: info.owner, repo: info.repo, kind: info.kind, number: info.number, anchor: info.anchor, view, reviewThreads, fallbackNotes: notes } };
|
|
8741
8991
|
} catch (err) {
|
|
8742
8992
|
if (signal?.aborted || isAbortError3(err)) return { url, title: "", content: "", error: "Aborted" };
|
|
8743
|
-
const message =
|
|
8993
|
+
const message = errorMessage36(err);
|
|
8744
8994
|
return { url, title: `${info.owner}/${info.repo}#${info.number}`, content: message, error: `GitHub REST fallback failed: ${message}` };
|
|
8745
8995
|
}
|
|
8746
8996
|
}
|
|
@@ -9038,7 +9288,7 @@ function renderGitHubPrIssue(data) {
|
|
|
9038
9288
|
async function extractGitHubIssuePr(url, signal, options) {
|
|
9039
9289
|
const info = parseGitHubIssuePrUrl(url);
|
|
9040
9290
|
if (!info) return null;
|
|
9041
|
-
if (!
|
|
9291
|
+
if (!loadConfig48().enabled) return null;
|
|
9042
9292
|
if (signal?.aborted) return { url, title: "", content: "", error: "Aborted" };
|
|
9043
9293
|
const retrievalTool = options?.toolNames ? options.toolNames.getSearchContent ?? null : void 0;
|
|
9044
9294
|
const ghAvailable2 = await checkGhAvailable(signal);
|
|
@@ -9062,13 +9312,13 @@ async function extractGitHubIssuePr(url, signal, options) {
|
|
|
9062
9312
|
if ("data" in fallback) return renderGitHubPrIssue({ ...fallback.data, retrievalTool });
|
|
9063
9313
|
return fallback;
|
|
9064
9314
|
}
|
|
9065
|
-
var
|
|
9315
|
+
var CONFIG_PATH54, GH_TIMEOUT_MS, GH_TOTAL_TIMEOUT_MS, MAX_DOC_CHARS, BODY_INLINE_CHARS, COMMENT_INLINE_CHARS, MAX_INLINE_COMMENTS, MAX_INLINE_REVIEWS, MAX_INLINE_CHECKS, MAX_INLINE_FILES, MAX_INLINE_COMMITS, MAX_INLINE_REVIEW_THREADS, REST_HEADERS, PR_SUBPATHS, PR_FIELDS, PR_CORE_FIELDS, ISSUE_FIELDS, ISSUE_CORE_FIELDS, cachedConfig47;
|
|
9066
9316
|
var init_github_issue_pr = __esm({
|
|
9067
9317
|
"github-issue-pr.ts"() {
|
|
9068
9318
|
init_github_api();
|
|
9069
9319
|
init_ssrf_protection();
|
|
9070
9320
|
init_utils();
|
|
9071
|
-
|
|
9321
|
+
CONFIG_PATH54 = getWebSearchConfigPath();
|
|
9072
9322
|
GH_TIMEOUT_MS = 1e4;
|
|
9073
9323
|
GH_TOTAL_TIMEOUT_MS = 2e4;
|
|
9074
9324
|
MAX_DOC_CHARS = 15e4;
|
|
@@ -9149,20 +9399,20 @@ var init_github_issue_pr = __esm({
|
|
|
9149
9399
|
"url"
|
|
9150
9400
|
];
|
|
9151
9401
|
ISSUE_CORE_FIELDS = ["title", "number", "state", "author", "createdAt", "closedAt", "labels", "assignees", "milestone", "comments", "body", "url"];
|
|
9152
|
-
|
|
9402
|
+
cachedConfig47 = null;
|
|
9153
9403
|
}
|
|
9154
9404
|
});
|
|
9155
9405
|
|
|
9156
9406
|
// feature-config.ts
|
|
9157
|
-
import { existsSync as
|
|
9407
|
+
import { existsSync as existsSync59, readFileSync as readFileSync61 } from "node:fs";
|
|
9158
9408
|
function loadFeatureConfig() {
|
|
9159
|
-
if (!
|
|
9409
|
+
if (!existsSync59(CONFIG_PATH55)) return {};
|
|
9160
9410
|
try {
|
|
9161
|
-
const raw = JSON.parse(
|
|
9411
|
+
const raw = JSON.parse(readFileSync61(CONFIG_PATH55, "utf-8"));
|
|
9162
9412
|
return raw && typeof raw === "object" ? raw : {};
|
|
9163
9413
|
} catch (err) {
|
|
9164
9414
|
const message = err instanceof Error ? err.message : String(err);
|
|
9165
|
-
throw new Error(`Failed to parse ${
|
|
9415
|
+
throw new Error(`Failed to parse ${CONFIG_PATH55}: ${message}`);
|
|
9166
9416
|
}
|
|
9167
9417
|
}
|
|
9168
9418
|
function isImageEnabled() {
|
|
@@ -9175,25 +9425,25 @@ function canAttachImages() {
|
|
|
9175
9425
|
return false;
|
|
9176
9426
|
}
|
|
9177
9427
|
}
|
|
9178
|
-
var
|
|
9428
|
+
var CONFIG_PATH55;
|
|
9179
9429
|
var init_feature_config = __esm({
|
|
9180
9430
|
"feature-config.ts"() {
|
|
9181
9431
|
init_utils();
|
|
9182
|
-
|
|
9432
|
+
CONFIG_PATH55 = getWebSearchConfigPath();
|
|
9183
9433
|
}
|
|
9184
9434
|
});
|
|
9185
9435
|
|
|
9186
9436
|
// youtube-extract.ts
|
|
9187
9437
|
import { execFileSync } from "node:child_process";
|
|
9188
|
-
import { existsSync as
|
|
9189
|
-
function
|
|
9438
|
+
import { existsSync as existsSync60, readFileSync as readFileSync62 } from "node:fs";
|
|
9439
|
+
function errorMessage37(err) {
|
|
9190
9440
|
return err instanceof Error ? err.message : String(err);
|
|
9191
9441
|
}
|
|
9192
9442
|
function shouldRethrow(err) {
|
|
9193
|
-
return
|
|
9443
|
+
return errorMessage37(err).startsWith("Failed to parse ");
|
|
9194
9444
|
}
|
|
9195
9445
|
function addAttemptError(errors, label, err) {
|
|
9196
|
-
const message =
|
|
9446
|
+
const message = errorMessage37(err).replace(/\s+/g, " ").trim();
|
|
9197
9447
|
if (message) errors.push(`${label}: ${message}`);
|
|
9198
9448
|
}
|
|
9199
9449
|
function normalizePreferredModel(value, fallback) {
|
|
@@ -9205,25 +9455,25 @@ function normalizeEnabled2(value, fallback) {
|
|
|
9205
9455
|
return typeof value === "boolean" ? value : fallback;
|
|
9206
9456
|
}
|
|
9207
9457
|
function loadYouTubeConfig() {
|
|
9208
|
-
if (
|
|
9209
|
-
if (!
|
|
9210
|
-
|
|
9211
|
-
return
|
|
9458
|
+
if (cachedConfig48) return cachedConfig48;
|
|
9459
|
+
if (!existsSync60(CONFIG_PATH56)) {
|
|
9460
|
+
cachedConfig48 = { ...defaults };
|
|
9461
|
+
return cachedConfig48;
|
|
9212
9462
|
}
|
|
9213
|
-
const rawText =
|
|
9463
|
+
const rawText = readFileSync62(CONFIG_PATH56, "utf-8");
|
|
9214
9464
|
let raw;
|
|
9215
9465
|
try {
|
|
9216
9466
|
raw = JSON.parse(rawText);
|
|
9217
9467
|
} catch (err) {
|
|
9218
9468
|
const message = err instanceof Error ? err.message : String(err);
|
|
9219
|
-
throw new Error(`Failed to parse ${
|
|
9469
|
+
throw new Error(`Failed to parse ${CONFIG_PATH56}: ${message}`);
|
|
9220
9470
|
}
|
|
9221
9471
|
const yt = raw.youtube ?? {};
|
|
9222
|
-
|
|
9472
|
+
cachedConfig48 = {
|
|
9223
9473
|
enabled: normalizeEnabled2(yt.enabled, defaults.enabled),
|
|
9224
9474
|
preferredModel: normalizePreferredModel(yt.preferredModel, defaults.preferredModel)
|
|
9225
9475
|
};
|
|
9226
|
-
return
|
|
9476
|
+
return cachedConfig48;
|
|
9227
9477
|
}
|
|
9228
9478
|
function isYouTubeURL(url) {
|
|
9229
9479
|
try {
|
|
@@ -9306,6 +9556,8 @@ async function extractFrameFromStream(streamUrl, seconds) {
|
|
|
9306
9556
|
streamUrl,
|
|
9307
9557
|
"-frames:v",
|
|
9308
9558
|
"1",
|
|
9559
|
+
"-vf",
|
|
9560
|
+
FRAME_SCALE_FILTER,
|
|
9309
9561
|
"-f",
|
|
9310
9562
|
"image2pipe",
|
|
9311
9563
|
"-vcodec",
|
|
@@ -9415,7 +9667,7 @@ ${answer}
|
|
|
9415
9667
|
return null;
|
|
9416
9668
|
}
|
|
9417
9669
|
}
|
|
9418
|
-
var
|
|
9670
|
+
var CONFIG_PATH56, YOUTUBE_PROMPT, YOUTUBE_REGEX, defaults, cachedConfig48;
|
|
9419
9671
|
var init_youtube_extract = __esm({
|
|
9420
9672
|
"youtube-extract.ts"() {
|
|
9421
9673
|
init_activity();
|
|
@@ -9425,7 +9677,7 @@ var init_youtube_extract = __esm({
|
|
|
9425
9677
|
init_perplexity();
|
|
9426
9678
|
init_extract();
|
|
9427
9679
|
init_utils();
|
|
9428
|
-
|
|
9680
|
+
CONFIG_PATH56 = getWebSearchConfigPath();
|
|
9429
9681
|
YOUTUBE_PROMPT = `Extract the complete content of this YouTube video. Include:
|
|
9430
9682
|
1. Video title, channel name, and duration
|
|
9431
9683
|
2. A brief summary (2-3 sentences)
|
|
@@ -9435,7 +9687,7 @@ var init_youtube_extract = __esm({
|
|
|
9435
9687
|
Format as markdown.`;
|
|
9436
9688
|
YOUTUBE_REGEX = /(?:(?:www\.|m\.)?youtube\.com\/(?:watch\?.*v=|shorts\/|live\/|embed\/|v\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
|
|
9437
9689
|
defaults = { enabled: true, preferredModel: "gemini-3.6-flash" };
|
|
9438
|
-
|
|
9690
|
+
cachedConfig48 = null;
|
|
9439
9691
|
}
|
|
9440
9692
|
});
|
|
9441
9693
|
|
|
@@ -9537,26 +9789,26 @@ URL: `;
|
|
|
9537
9789
|
});
|
|
9538
9790
|
|
|
9539
9791
|
// crawl4ai.ts
|
|
9540
|
-
import { existsSync as
|
|
9541
|
-
function
|
|
9542
|
-
if (
|
|
9543
|
-
if (!
|
|
9544
|
-
|
|
9545
|
-
return
|
|
9546
|
-
}
|
|
9547
|
-
const raw =
|
|
9792
|
+
import { existsSync as existsSync61, readFileSync as readFileSync63 } from "node:fs";
|
|
9793
|
+
function loadConfig49() {
|
|
9794
|
+
if (cachedConfig49) return cachedConfig49;
|
|
9795
|
+
if (!existsSync61(CONFIG_PATH57)) {
|
|
9796
|
+
cachedConfig49 = {};
|
|
9797
|
+
return cachedConfig49;
|
|
9798
|
+
}
|
|
9799
|
+
const raw = readFileSync63(CONFIG_PATH57, "utf8");
|
|
9548
9800
|
let parsed;
|
|
9549
9801
|
try {
|
|
9550
9802
|
parsed = JSON.parse(raw);
|
|
9551
9803
|
} catch (err) {
|
|
9552
9804
|
const message = err instanceof Error ? err.message : String(err);
|
|
9553
|
-
throw new Error(`Failed to parse ${
|
|
9805
|
+
throw new Error(`Failed to parse ${CONFIG_PATH57}: ${message}`);
|
|
9554
9806
|
}
|
|
9555
9807
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9556
|
-
throw new Error(`Invalid config in ${
|
|
9808
|
+
throw new Error(`Invalid config in ${CONFIG_PATH57}: expected a JSON object`);
|
|
9557
9809
|
}
|
|
9558
|
-
|
|
9559
|
-
return
|
|
9810
|
+
cachedConfig49 = parsed;
|
|
9811
|
+
return cachedConfig49;
|
|
9560
9812
|
}
|
|
9561
9813
|
function normalizeBaseUrl5(value) {
|
|
9562
9814
|
if (typeof value !== "string") return null;
|
|
@@ -9566,13 +9818,13 @@ function normalizeBaseUrl5(value) {
|
|
|
9566
9818
|
try {
|
|
9567
9819
|
parsed = new URL(trimmed);
|
|
9568
9820
|
} catch {
|
|
9569
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
9821
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH57}: expected an HTTP or HTTPS URL`);
|
|
9570
9822
|
}
|
|
9571
9823
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
9572
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
9824
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH57}: expected an HTTP or HTTPS URL`);
|
|
9573
9825
|
}
|
|
9574
9826
|
if (parsed.username || parsed.password) {
|
|
9575
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
9827
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH57}: URL credentials are not allowed`);
|
|
9576
9828
|
}
|
|
9577
9829
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
9578
9830
|
parsed.search = "";
|
|
@@ -9580,14 +9832,14 @@ function normalizeBaseUrl5(value) {
|
|
|
9580
9832
|
return parsed.toString().replace(/\/+$/, "");
|
|
9581
9833
|
}
|
|
9582
9834
|
function getBaseUrl4() {
|
|
9583
|
-
return normalizeBaseUrl5(process.env.CRAWL4AI_BASE_URL) ?? normalizeBaseUrl5(
|
|
9835
|
+
return normalizeBaseUrl5(process.env.CRAWL4AI_BASE_URL) ?? normalizeBaseUrl5(loadConfig49().crawl4aiBaseUrl);
|
|
9584
9836
|
}
|
|
9585
9837
|
function requireBaseUrl4() {
|
|
9586
9838
|
const baseUrl = getBaseUrl4();
|
|
9587
9839
|
if (!baseUrl) {
|
|
9588
9840
|
throw new Error(
|
|
9589
9841
|
`Crawl4AI base URL not configured. Either:
|
|
9590
|
-
1. Set crawl4aiBaseUrl in ${
|
|
9842
|
+
1. Set crawl4aiBaseUrl in ${CONFIG_PATH57}
|
|
9591
9843
|
2. Set CRAWL4AI_BASE_URL environment variable`
|
|
9592
9844
|
);
|
|
9593
9845
|
}
|
|
@@ -9596,7 +9848,7 @@ function requireBaseUrl4() {
|
|
|
9596
9848
|
async function getApiToken(signal) {
|
|
9597
9849
|
return resolveCredential({
|
|
9598
9850
|
provider: "Crawl4AI",
|
|
9599
|
-
configuredValue:
|
|
9851
|
+
configuredValue: loadConfig49().crawl4aiApiToken,
|
|
9600
9852
|
environmentValue: process.env.CRAWL4AI_API_TOKEN,
|
|
9601
9853
|
signal
|
|
9602
9854
|
});
|
|
@@ -9605,7 +9857,7 @@ function requestSignal14(timeoutMs, signal) {
|
|
|
9605
9857
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
9606
9858
|
return signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
9607
9859
|
}
|
|
9608
|
-
function
|
|
9860
|
+
function errorMessage38(err) {
|
|
9609
9861
|
return err instanceof Error ? err.message : String(err);
|
|
9610
9862
|
}
|
|
9611
9863
|
function isAbortException(err) {
|
|
@@ -9635,7 +9887,7 @@ async function extractWithCrawl4ai(url, signal, options) {
|
|
|
9635
9887
|
method: "POST",
|
|
9636
9888
|
headers,
|
|
9637
9889
|
body: JSON.stringify({ url, f: MARKDOWN_FILTER }),
|
|
9638
|
-
signal: requestSignal14(options?.timeoutMs ??
|
|
9890
|
+
signal: requestSignal14(options?.timeoutMs ?? EXTRACT_TIMEOUT_MS4, signal)
|
|
9639
9891
|
};
|
|
9640
9892
|
let seeOther = false;
|
|
9641
9893
|
const activityId = activityMonitor.logStart({ type: "fetch", url: requestUrl.toString() });
|
|
@@ -9682,49 +9934,49 @@ async function extractWithCrawl4ai(url, signal, options) {
|
|
|
9682
9934
|
return { url, title: firstHeadingTitle(content), content, error: null };
|
|
9683
9935
|
} catch (err) {
|
|
9684
9936
|
if (signal?.aborted || isAbortException(err)) activityMonitor.logComplete(activityId, 0);
|
|
9685
|
-
else activityMonitor.logError(activityId,
|
|
9937
|
+
else activityMonitor.logError(activityId, errorMessage38(err));
|
|
9686
9938
|
throw err;
|
|
9687
9939
|
}
|
|
9688
9940
|
}
|
|
9689
|
-
var
|
|
9941
|
+
var CONFIG_PATH57, EXTRACT_TIMEOUT_MS4, MARKDOWN_FILTER, cachedConfig49;
|
|
9690
9942
|
var init_crawl4ai = __esm({
|
|
9691
9943
|
"crawl4ai.ts"() {
|
|
9692
9944
|
init_activity();
|
|
9693
9945
|
init_credential_source();
|
|
9694
9946
|
init_ssrf_protection();
|
|
9695
9947
|
init_utils();
|
|
9696
|
-
|
|
9697
|
-
|
|
9948
|
+
CONFIG_PATH57 = getWebSearchConfigPath();
|
|
9949
|
+
EXTRACT_TIMEOUT_MS4 = 6e4;
|
|
9698
9950
|
MARKDOWN_FILTER = "fit";
|
|
9699
|
-
|
|
9951
|
+
cachedConfig49 = null;
|
|
9700
9952
|
}
|
|
9701
9953
|
});
|
|
9702
9954
|
|
|
9703
9955
|
// brightdata-unlocker.ts
|
|
9704
|
-
import { existsSync as
|
|
9956
|
+
import { existsSync as existsSync62, readFileSync as readFileSync64 } from "node:fs";
|
|
9705
9957
|
function parseFailureDetail(err) {
|
|
9706
9958
|
const message = err instanceof Error ? err.message : String(err);
|
|
9707
9959
|
const position = message.match(/at position \d+(?: \(line \d+ column \d+\))?/);
|
|
9708
9960
|
return position ? `invalid JSON ${position[0]}` : "invalid JSON";
|
|
9709
9961
|
}
|
|
9710
|
-
function
|
|
9711
|
-
if (
|
|
9712
|
-
if (!
|
|
9713
|
-
|
|
9714
|
-
return
|
|
9962
|
+
function loadConfig50() {
|
|
9963
|
+
if (cachedConfig50) return cachedConfig50;
|
|
9964
|
+
if (!existsSync62(CONFIG_PATH58)) {
|
|
9965
|
+
cachedConfig50 = {};
|
|
9966
|
+
return cachedConfig50;
|
|
9715
9967
|
}
|
|
9716
|
-
const raw =
|
|
9968
|
+
const raw = readFileSync64(CONFIG_PATH58, "utf8");
|
|
9717
9969
|
let parsed;
|
|
9718
9970
|
try {
|
|
9719
9971
|
parsed = JSON.parse(raw);
|
|
9720
9972
|
} catch (err) {
|
|
9721
|
-
throw new Error(`Failed to parse ${
|
|
9973
|
+
throw new Error(`Failed to parse ${CONFIG_PATH58}: ${parseFailureDetail(err)}`);
|
|
9722
9974
|
}
|
|
9723
9975
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9724
|
-
throw new Error(`Invalid config in ${
|
|
9976
|
+
throw new Error(`Invalid config in ${CONFIG_PATH58}: expected a JSON object`);
|
|
9725
9977
|
}
|
|
9726
|
-
|
|
9727
|
-
return
|
|
9978
|
+
cachedConfig50 = parsed;
|
|
9979
|
+
return cachedConfig50;
|
|
9728
9980
|
}
|
|
9729
9981
|
function normalizeZone2(value) {
|
|
9730
9982
|
if (typeof value !== "string") return null;
|
|
@@ -9735,8 +9987,8 @@ function normalizeZone2(value) {
|
|
|
9735
9987
|
function zoneSetting() {
|
|
9736
9988
|
const fromEnv = process.env.BRIGHTDATA_UNLOCKER_ZONE;
|
|
9737
9989
|
if (typeof fromEnv === "string" && fromEnv.trim()) return { raw: fromEnv.trim(), label: "BRIGHTDATA_UNLOCKER_ZONE" };
|
|
9738
|
-
const configured =
|
|
9739
|
-
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${
|
|
9990
|
+
const configured = loadConfig50().brightdataUnlockerZone;
|
|
9991
|
+
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${CONFIG_PATH58}` };
|
|
9740
9992
|
return null;
|
|
9741
9993
|
}
|
|
9742
9994
|
function getZone() {
|
|
@@ -9754,22 +10006,22 @@ function requireZone() {
|
|
|
9754
10006
|
}
|
|
9755
10007
|
throw new Error(
|
|
9756
10008
|
`Bright Data Web Unlocker zone not configured. Either:
|
|
9757
|
-
1. Set brightdataUnlockerZone in ${
|
|
10009
|
+
1. Set brightdataUnlockerZone in ${CONFIG_PATH58}
|
|
9758
10010
|
2. Set BRIGHTDATA_UNLOCKER_ZONE environment variable
|
|
9759
10011
|
The zone must be of type "unblocker"; a SERP zone will not serve Web Unlocker requests.`
|
|
9760
10012
|
);
|
|
9761
10013
|
}
|
|
9762
|
-
async function
|
|
10014
|
+
async function getApiKey34(signal) {
|
|
9763
10015
|
const apiKey = await resolveCredential({
|
|
9764
10016
|
provider: "Bright Data",
|
|
9765
|
-
configuredValue:
|
|
10017
|
+
configuredValue: loadConfig50().brightdataApiKey,
|
|
9766
10018
|
environmentValue: process.env.BRIGHTDATA_API_KEY,
|
|
9767
10019
|
signal
|
|
9768
10020
|
});
|
|
9769
10021
|
if (!apiKey) {
|
|
9770
10022
|
throw new Error(
|
|
9771
10023
|
`Bright Data API key not found. Either:
|
|
9772
|
-
1. Create ${
|
|
10024
|
+
1. Create ${CONFIG_PATH58} with { "brightdataApiKey": "your-key" }
|
|
9773
10025
|
2. Set BRIGHTDATA_API_KEY environment variable
|
|
9774
10026
|
Get a key at https://brightdata.com/cp/setting/users`
|
|
9775
10027
|
);
|
|
@@ -9780,11 +10032,11 @@ function requestSignal15(timeoutMs, signal) {
|
|
|
9780
10032
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
9781
10033
|
return signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
9782
10034
|
}
|
|
9783
|
-
function
|
|
10035
|
+
function errorMessage39(err) {
|
|
9784
10036
|
return err instanceof Error ? err.message : String(err);
|
|
9785
10037
|
}
|
|
9786
10038
|
function isAbortError4(err) {
|
|
9787
|
-
return
|
|
10039
|
+
return errorMessage39(err).toLowerCase().includes("abort");
|
|
9788
10040
|
}
|
|
9789
10041
|
function ssrfOptions3(options) {
|
|
9790
10042
|
return {
|
|
@@ -9826,18 +10078,18 @@ function unlockerBody(url, zone) {
|
|
|
9826
10078
|
};
|
|
9827
10079
|
}
|
|
9828
10080
|
async function brightDataRequest(url, zone, signal, options) {
|
|
9829
|
-
const apiKey = await
|
|
10081
|
+
const apiKey = await getApiKey34(signal);
|
|
9830
10082
|
const headers = {
|
|
9831
10083
|
"Content-Type": "application/json",
|
|
9832
10084
|
Authorization: `Bearer ${apiKey}`
|
|
9833
10085
|
};
|
|
9834
10086
|
const activityId = activityMonitor.logStart({ type: "fetch", url });
|
|
9835
10087
|
try {
|
|
9836
|
-
const response = await fetchBrightDataApi(resolveProviderApiUrl("brightdata", BRIGHTDATA_REQUEST_URL,
|
|
10088
|
+
const response = await fetchBrightDataApi(resolveProviderApiUrl("brightdata", BRIGHTDATA_REQUEST_URL, loadConfig50().brightdataBaseUrl), {
|
|
9837
10089
|
method: "POST",
|
|
9838
10090
|
headers,
|
|
9839
10091
|
body: JSON.stringify(unlockerBody(url, zone)),
|
|
9840
|
-
signal: requestSignal15(options?.timeoutMs ??
|
|
10092
|
+
signal: requestSignal15(options?.timeoutMs ?? EXTRACT_TIMEOUT_MS5, signal)
|
|
9841
10093
|
}, options);
|
|
9842
10094
|
if (!response.ok) {
|
|
9843
10095
|
const errorText = await response.text().catch(() => "");
|
|
@@ -9847,7 +10099,7 @@ async function brightDataRequest(url, zone, signal, options) {
|
|
|
9847
10099
|
activityMonitor.logComplete(activityId, response.status);
|
|
9848
10100
|
return text7;
|
|
9849
10101
|
} catch (err) {
|
|
9850
|
-
const message =
|
|
10102
|
+
const message = errorMessage39(err);
|
|
9851
10103
|
const redactedMessage = redactCredential(message, apiKey);
|
|
9852
10104
|
if (isAbortError4(err)) activityMonitor.logComplete(activityId, 0);
|
|
9853
10105
|
else activityMonitor.logError(activityId, redactedMessage);
|
|
@@ -9866,7 +10118,7 @@ function isBrightDataUnlockerAvailable() {
|
|
|
9866
10118
|
if (getZone() === null) return false;
|
|
9867
10119
|
return hasCredentialSource({
|
|
9868
10120
|
provider: "Bright Data",
|
|
9869
|
-
configuredValue:
|
|
10121
|
+
configuredValue: loadConfig50().brightdataApiKey,
|
|
9870
10122
|
environmentValue: process.env.BRIGHTDATA_API_KEY
|
|
9871
10123
|
});
|
|
9872
10124
|
}
|
|
@@ -9878,28 +10130,28 @@ async function extractWithBrightDataUnlocker(url, signal, options) {
|
|
|
9878
10130
|
if (!content) return null;
|
|
9879
10131
|
return { url, title: headingTitle(content), content, error: null };
|
|
9880
10132
|
}
|
|
9881
|
-
var
|
|
10133
|
+
var CONFIG_PATH58, BRIGHTDATA_REQUEST_URL, EXTRACT_TIMEOUT_MS5, DEFAULT_MAX_REDIRECTS3, REDIRECT_STATUSES3, ZONE_PATTERN2, cachedConfig50;
|
|
9882
10134
|
var init_brightdata_unlocker = __esm({
|
|
9883
10135
|
"brightdata-unlocker.ts"() {
|
|
9884
10136
|
init_activity();
|
|
9885
10137
|
init_credential_source();
|
|
9886
10138
|
init_ssrf_protection();
|
|
9887
10139
|
init_utils();
|
|
9888
|
-
|
|
10140
|
+
CONFIG_PATH58 = getWebSearchConfigPath();
|
|
9889
10141
|
BRIGHTDATA_REQUEST_URL = "https://api.brightdata.com/request";
|
|
9890
|
-
|
|
10142
|
+
EXTRACT_TIMEOUT_MS5 = 6e4;
|
|
9891
10143
|
DEFAULT_MAX_REDIRECTS3 = 5;
|
|
9892
10144
|
REDIRECT_STATUSES3 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
9893
10145
|
ZONE_PATTERN2 = /^[a-z0-9_-]+$/i;
|
|
9894
|
-
|
|
10146
|
+
cachedConfig50 = null;
|
|
9895
10147
|
}
|
|
9896
10148
|
});
|
|
9897
10149
|
|
|
9898
10150
|
// video-extract.ts
|
|
9899
10151
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
9900
|
-
import { existsSync as
|
|
10152
|
+
import { existsSync as existsSync63, readFileSync as readFileSync65, readdirSync as readdirSync4, statSync as statSync3 } from "node:fs";
|
|
9901
10153
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
9902
|
-
import { resolve, extname as extname2, basename as basename4, join as
|
|
10154
|
+
import { resolve, extname as extname2, basename as basename4, join as join8, dirname as dirname3 } from "node:path";
|
|
9903
10155
|
function shouldRethrow3(err) {
|
|
9904
10156
|
const message = err instanceof Error ? err.message : String(err);
|
|
9905
10157
|
return message.startsWith("Failed to parse ");
|
|
@@ -9918,17 +10170,17 @@ function normalizeMaxSizeMB(value, fallback) {
|
|
|
9918
10170
|
}
|
|
9919
10171
|
function loadVideoConfig() {
|
|
9920
10172
|
if (cachedVideoConfig) return cachedVideoConfig;
|
|
9921
|
-
if (!
|
|
10173
|
+
if (!existsSync63(CONFIG_PATH59)) {
|
|
9922
10174
|
cachedVideoConfig = { ...VIDEO_CONFIG_DEFAULTS };
|
|
9923
10175
|
return cachedVideoConfig;
|
|
9924
10176
|
}
|
|
9925
|
-
const rawText =
|
|
10177
|
+
const rawText = readFileSync65(CONFIG_PATH59, "utf-8");
|
|
9926
10178
|
let raw;
|
|
9927
10179
|
try {
|
|
9928
10180
|
raw = JSON.parse(rawText);
|
|
9929
10181
|
} catch (err) {
|
|
9930
10182
|
const message = err instanceof Error ? err.message : String(err);
|
|
9931
|
-
throw new Error(`Failed to parse ${
|
|
10183
|
+
throw new Error(`Failed to parse ${CONFIG_PATH59}: ${message}`);
|
|
9932
10184
|
}
|
|
9933
10185
|
const v = raw.video ?? {};
|
|
9934
10186
|
cachedVideoConfig = {
|
|
@@ -9974,14 +10226,14 @@ function isVideoFile(input) {
|
|
|
9974
10226
|
}
|
|
9975
10227
|
function resolveFilePath(filePath) {
|
|
9976
10228
|
const absolutePath = resolve(filePath);
|
|
9977
|
-
if (
|
|
9978
|
-
const dir =
|
|
10229
|
+
if (existsSync63(absolutePath)) return absolutePath;
|
|
10230
|
+
const dir = dirname3(absolutePath);
|
|
9979
10231
|
const base = basename4(absolutePath);
|
|
9980
|
-
if (!
|
|
10232
|
+
if (!existsSync63(dir)) return null;
|
|
9981
10233
|
try {
|
|
9982
10234
|
const normalizedBase = normalizeSpaces(base);
|
|
9983
10235
|
const match = readdirSync4(dir).find((f) => normalizeSpaces(f) === normalizedBase);
|
|
9984
|
-
return match ?
|
|
10236
|
+
return match ? join8(dir, match) : null;
|
|
9985
10237
|
} catch {
|
|
9986
10238
|
return null;
|
|
9987
10239
|
}
|
|
@@ -10034,6 +10286,8 @@ async function extractVideoFrame(filePath, seconds = 1) {
|
|
|
10034
10286
|
filePath,
|
|
10035
10287
|
"-frames:v",
|
|
10036
10288
|
"1",
|
|
10289
|
+
"-vf",
|
|
10290
|
+
FRAME_SCALE_FILTER,
|
|
10037
10291
|
"-f",
|
|
10038
10292
|
"image2pipe",
|
|
10039
10293
|
"-vcodec",
|
|
@@ -10176,7 +10430,7 @@ function deleteGeminiFile(fileName, apiKey) {
|
|
|
10176
10430
|
function extractVideoTitle(text7, filePath) {
|
|
10177
10431
|
return extractHeadingTitle(text7) ?? basename4(filePath, extname2(filePath));
|
|
10178
10432
|
}
|
|
10179
|
-
var
|
|
10433
|
+
var CONFIG_PATH59, DEFAULT_VIDEO_PROMPT, VIDEO_EXTENSIONS, VIDEO_CONFIG_DEFAULTS, cachedVideoConfig;
|
|
10180
10434
|
var init_video_extract = __esm({
|
|
10181
10435
|
"video-extract.ts"() {
|
|
10182
10436
|
init_activity();
|
|
@@ -10185,7 +10439,7 @@ var init_video_extract = __esm({
|
|
|
10185
10439
|
init_gemini_api();
|
|
10186
10440
|
init_extract();
|
|
10187
10441
|
init_utils();
|
|
10188
|
-
|
|
10442
|
+
CONFIG_PATH59 = getWebSearchConfigPath();
|
|
10189
10443
|
DEFAULT_VIDEO_PROMPT = `Extract the complete content of this video. Include:
|
|
10190
10444
|
1. Video title (infer from content if not explicit), duration
|
|
10191
10445
|
2. A brief summary (2-3 sentences)
|
|
@@ -10670,13 +10924,13 @@ __export(extract_exports, {
|
|
|
10670
10924
|
readPDFResponseBuffer: () => readPDFResponseBuffer,
|
|
10671
10925
|
resolveFetchTimeoutMs: () => resolveFetchTimeoutMs
|
|
10672
10926
|
});
|
|
10673
|
-
import { existsSync as
|
|
10927
|
+
import { existsSync as existsSync64, readFileSync as readFileSync66 } from "node:fs";
|
|
10674
10928
|
import pLimit from "p-limit";
|
|
10675
10929
|
function loadFetchTimeoutMs() {
|
|
10676
|
-
if (!
|
|
10930
|
+
if (!existsSync64(WEB_SEARCH_CONFIG_PATH3)) return DEFAULT_TIMEOUT_MS5;
|
|
10677
10931
|
let raw;
|
|
10678
10932
|
try {
|
|
10679
|
-
raw = JSON.parse(
|
|
10933
|
+
raw = JSON.parse(readFileSync66(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
10680
10934
|
} catch (err) {
|
|
10681
10935
|
const message = err instanceof Error ? err.message : String(err);
|
|
10682
10936
|
throw new Error(`Failed to parse ${WEB_SEARCH_CONFIG_PATH3}: ${message}`);
|
|
@@ -10731,21 +10985,21 @@ async function extractWithDefuddle(text7, url) {
|
|
|
10731
10985
|
}
|
|
10732
10986
|
const result = await resultPromise;
|
|
10733
10987
|
if (processingError !== void 0) {
|
|
10734
|
-
throw new Error(`Defuddle failed to process document: ${
|
|
10988
|
+
throw new Error(`Defuddle failed to process document: ${errorMessage40(processingError)}`);
|
|
10735
10989
|
}
|
|
10736
10990
|
return typeof result.content === "string" ? { title: result.title, content: result.content } : null;
|
|
10737
10991
|
}
|
|
10738
10992
|
function loadSsrfAllowRanges() {
|
|
10739
10993
|
return loadSsrfConfig().allowRanges;
|
|
10740
10994
|
}
|
|
10741
|
-
function
|
|
10995
|
+
function errorMessage40(err) {
|
|
10742
10996
|
return err instanceof Error ? err.message : String(err);
|
|
10743
10997
|
}
|
|
10744
10998
|
function isConfigParseError(err) {
|
|
10745
|
-
return
|
|
10999
|
+
return errorMessage40(err).startsWith("Failed to parse ");
|
|
10746
11000
|
}
|
|
10747
11001
|
function isAbortError5(err) {
|
|
10748
|
-
return
|
|
11002
|
+
return errorMessage40(err).toLowerCase().includes("abort");
|
|
10749
11003
|
}
|
|
10750
11004
|
function isAbortException2(err) {
|
|
10751
11005
|
return err instanceof DOMException && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
@@ -10760,7 +11014,7 @@ function imageGateError() {
|
|
|
10760
11014
|
try {
|
|
10761
11015
|
return isImageEnabled() ? null : "Image fetching is disabled by image.enabled";
|
|
10762
11016
|
} catch (err) {
|
|
10763
|
-
return
|
|
11017
|
+
return errorMessage40(err);
|
|
10764
11018
|
}
|
|
10765
11019
|
}
|
|
10766
11020
|
function redirectPolicyRouteRefusal(url, path) {
|
|
@@ -10815,12 +11069,12 @@ async function fetchAuthenticatedRemoteUrl(url, init, validationOptions, profile
|
|
|
10815
11069
|
throw new Error(`Too many redirects fetching ${current.toString()}`);
|
|
10816
11070
|
}
|
|
10817
11071
|
function loadFetchRouting() {
|
|
10818
|
-
if (!
|
|
11072
|
+
if (!existsSync64(WEB_SEARCH_CONFIG_PATH3)) {
|
|
10819
11073
|
return { providers: DEFAULT_FETCH_PROVIDER_ORDER, allowRemoteHostedProviders: false };
|
|
10820
11074
|
}
|
|
10821
11075
|
let raw;
|
|
10822
11076
|
try {
|
|
10823
|
-
const parsed = JSON.parse(
|
|
11077
|
+
const parsed = JSON.parse(readFileSync66(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
10824
11078
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
10825
11079
|
throw new Error("expected a JSON object");
|
|
10826
11080
|
}
|
|
@@ -11011,7 +11265,7 @@ function safeVideoInfo(url) {
|
|
|
11011
11265
|
const info = isVideoFile(url);
|
|
11012
11266
|
return info ? { status: "video", info } : { status: "not-video" };
|
|
11013
11267
|
} catch (err) {
|
|
11014
|
-
return { status: "invalid", error:
|
|
11268
|
+
return { status: "invalid", error: errorMessage40(err) };
|
|
11015
11269
|
}
|
|
11016
11270
|
}
|
|
11017
11271
|
async function extractContent(url, signal, options) {
|
|
@@ -11022,7 +11276,7 @@ async function extractContent(url, signal, options) {
|
|
|
11022
11276
|
try {
|
|
11023
11277
|
redirectPolicy = options?.redirects ?? loadFetchContentRedirectPolicy();
|
|
11024
11278
|
} catch (err) {
|
|
11025
|
-
return { url, title: "", content: "", error:
|
|
11279
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11026
11280
|
}
|
|
11027
11281
|
let remoteUrl = null;
|
|
11028
11282
|
try {
|
|
@@ -11044,14 +11298,14 @@ async function extractContent(url, signal, options) {
|
|
|
11044
11298
|
...options?.lookup ? { lookup: options.lookup } : {}
|
|
11045
11299
|
});
|
|
11046
11300
|
} catch (err) {
|
|
11047
|
-
return { url, title: "", content: "", error:
|
|
11301
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11048
11302
|
}
|
|
11049
11303
|
}
|
|
11050
11304
|
if (options?.authFetchProfile || options?.mode === "raw") {
|
|
11051
11305
|
try {
|
|
11052
11306
|
return await extractViaHttp(url, resolveFetchTimeoutMs(options), signal, options);
|
|
11053
11307
|
} catch (err) {
|
|
11054
|
-
return { url, title: "", content: "", error:
|
|
11308
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11055
11309
|
}
|
|
11056
11310
|
}
|
|
11057
11311
|
if (redirectPolicy) {
|
|
@@ -11194,20 +11448,20 @@ async function extractContent(url, signal, options) {
|
|
|
11194
11448
|
2. Set GEMINI_API_KEY in ${WEB_SEARCH_CONFIG_PATH3}` };
|
|
11195
11449
|
} catch (err) {
|
|
11196
11450
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11197
|
-
return { url, title: "", content: "", error:
|
|
11451
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11198
11452
|
}
|
|
11199
11453
|
}
|
|
11200
11454
|
try {
|
|
11201
11455
|
if (!remoteUrl) new URL(url);
|
|
11202
11456
|
} catch (err) {
|
|
11203
|
-
return { url, title: "", content: "", error:
|
|
11457
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11204
11458
|
}
|
|
11205
11459
|
try {
|
|
11206
11460
|
const ghIssuePrResult = await extractGitHubIssuePr(url, signal, options);
|
|
11207
11461
|
if (ghIssuePrResult) return ghIssuePrResult;
|
|
11208
11462
|
if (signal?.aborted) return abortedResult(url);
|
|
11209
11463
|
} catch (err) {
|
|
11210
|
-
const message =
|
|
11464
|
+
const message = errorMessage40(err);
|
|
11211
11465
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11212
11466
|
if (isConfigParseError(err)) {
|
|
11213
11467
|
return { url, title: "", content: "", error: message };
|
|
@@ -11218,7 +11472,7 @@ async function extractContent(url, signal, options) {
|
|
|
11218
11472
|
if (ghResult) return ghResult;
|
|
11219
11473
|
if (signal?.aborted) return abortedResult(url);
|
|
11220
11474
|
} catch (err) {
|
|
11221
|
-
const message =
|
|
11475
|
+
const message = errorMessage40(err);
|
|
11222
11476
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11223
11477
|
if (isConfigParseError(err)) {
|
|
11224
11478
|
return { url, title: "", content: "", error: message };
|
|
@@ -11229,7 +11483,7 @@ async function extractContent(url, signal, options) {
|
|
|
11229
11483
|
try {
|
|
11230
11484
|
youtubeEnabled = isYouTubeEnabled();
|
|
11231
11485
|
} catch (err) {
|
|
11232
|
-
return { url, title: "", content: "", error:
|
|
11486
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11233
11487
|
}
|
|
11234
11488
|
if (ytInfo.isYouTube && youtubeEnabled) {
|
|
11235
11489
|
try {
|
|
@@ -11237,7 +11491,7 @@ async function extractContent(url, signal, options) {
|
|
|
11237
11491
|
if (ytResult) return ytResult;
|
|
11238
11492
|
if (signal?.aborted) return abortedResult(url);
|
|
11239
11493
|
} catch (err) {
|
|
11240
|
-
const message =
|
|
11494
|
+
const message = errorMessage40(err);
|
|
11241
11495
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11242
11496
|
return { url, title: "", content: "", error: message };
|
|
11243
11497
|
}
|
|
@@ -11253,13 +11507,13 @@ async function extractContent(url, signal, options) {
|
|
|
11253
11507
|
try {
|
|
11254
11508
|
fetchTimeoutMs = resolveFetchTimeoutMs(options);
|
|
11255
11509
|
} catch (err) {
|
|
11256
|
-
return { url, title: "", content: "", error:
|
|
11510
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11257
11511
|
}
|
|
11258
11512
|
let fetchRouting;
|
|
11259
11513
|
try {
|
|
11260
11514
|
fetchRouting = loadFetchRouting();
|
|
11261
11515
|
} catch (err) {
|
|
11262
|
-
return { url, title: "", content: "", error:
|
|
11516
|
+
return { url, title: "", content: "", error: errorMessage40(err) };
|
|
11263
11517
|
}
|
|
11264
11518
|
if (redirectPolicy && !fetchRouting.providers.includes("http")) {
|
|
11265
11519
|
return redirectPolicyRouteRefusal(url, fetchRouting.providers[0]);
|
|
@@ -11297,6 +11551,7 @@ async function extractContent(url, signal, options) {
|
|
|
11297
11551
|
let search1apiError = null;
|
|
11298
11552
|
let queritError = null;
|
|
11299
11553
|
let tabstackError = null;
|
|
11554
|
+
let specstreamError = null;
|
|
11300
11555
|
let kagiError = null;
|
|
11301
11556
|
let ollamaError = null;
|
|
11302
11557
|
let parallelError = null;
|
|
@@ -11328,7 +11583,7 @@ async function extractContent(url, signal, options) {
|
|
|
11328
11583
|
}
|
|
11329
11584
|
} catch (err) {
|
|
11330
11585
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11331
|
-
firecrawlError =
|
|
11586
|
+
firecrawlError = errorMessage40(err);
|
|
11332
11587
|
if (isConfigParseError(err)) return parseErrorResult(firecrawlError);
|
|
11333
11588
|
}
|
|
11334
11589
|
continue;
|
|
@@ -11346,7 +11601,7 @@ async function extractContent(url, signal, options) {
|
|
|
11346
11601
|
}
|
|
11347
11602
|
} catch (err) {
|
|
11348
11603
|
if (signal?.aborted || isAbortException2(err)) return abortedResult(url);
|
|
11349
|
-
crawl4aiError =
|
|
11604
|
+
crawl4aiError = errorMessage40(err);
|
|
11350
11605
|
if (isConfigParseError(err)) return parseErrorResult(crawl4aiError);
|
|
11351
11606
|
}
|
|
11352
11607
|
continue;
|
|
@@ -11364,7 +11619,7 @@ async function extractContent(url, signal, options) {
|
|
|
11364
11619
|
}
|
|
11365
11620
|
} catch (err) {
|
|
11366
11621
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11367
|
-
tinyfishError =
|
|
11622
|
+
tinyfishError = errorMessage40(err);
|
|
11368
11623
|
if (isConfigParseError(err)) return parseErrorResult(tinyfishError);
|
|
11369
11624
|
}
|
|
11370
11625
|
continue;
|
|
@@ -11377,7 +11632,7 @@ async function extractContent(url, signal, options) {
|
|
|
11377
11632
|
}
|
|
11378
11633
|
} catch (err) {
|
|
11379
11634
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11380
|
-
search1apiError =
|
|
11635
|
+
search1apiError = errorMessage40(err);
|
|
11381
11636
|
if (isConfigParseError(err)) return parseErrorResult(search1apiError);
|
|
11382
11637
|
}
|
|
11383
11638
|
continue;
|
|
@@ -11390,7 +11645,7 @@ async function extractContent(url, signal, options) {
|
|
|
11390
11645
|
}
|
|
11391
11646
|
} catch (err) {
|
|
11392
11647
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11393
|
-
queritError =
|
|
11648
|
+
queritError = errorMessage40(err);
|
|
11394
11649
|
if (isConfigParseError(err)) return parseErrorResult(queritError);
|
|
11395
11650
|
}
|
|
11396
11651
|
continue;
|
|
@@ -11403,11 +11658,24 @@ async function extractContent(url, signal, options) {
|
|
|
11403
11658
|
}
|
|
11404
11659
|
} catch (err) {
|
|
11405
11660
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11406
|
-
tabstackError =
|
|
11661
|
+
tabstackError = errorMessage40(err);
|
|
11407
11662
|
if (isConfigParseError(err)) return parseErrorResult(tabstackError);
|
|
11408
11663
|
}
|
|
11409
11664
|
continue;
|
|
11410
11665
|
}
|
|
11666
|
+
if (provider === "specstream") {
|
|
11667
|
+
try {
|
|
11668
|
+
if (isSpecStreamAvailable()) {
|
|
11669
|
+
const specstreamResult = await extractWithSpecStream(url, signal, options);
|
|
11670
|
+
if (specstreamResult) return withDeclaredLinks(specstreamResult);
|
|
11671
|
+
}
|
|
11672
|
+
} catch (err) {
|
|
11673
|
+
if (isAbortError5(err)) return abortedResult(url);
|
|
11674
|
+
specstreamError = errorMessage40(err);
|
|
11675
|
+
if (isConfigParseError(err)) return parseErrorResult(specstreamError);
|
|
11676
|
+
}
|
|
11677
|
+
continue;
|
|
11678
|
+
}
|
|
11411
11679
|
if (provider === "kagi") {
|
|
11412
11680
|
try {
|
|
11413
11681
|
if (isKagiExtractAvailable()) {
|
|
@@ -11421,7 +11689,7 @@ async function extractContent(url, signal, options) {
|
|
|
11421
11689
|
}
|
|
11422
11690
|
} catch (err) {
|
|
11423
11691
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11424
|
-
kagiError =
|
|
11692
|
+
kagiError = errorMessage40(err);
|
|
11425
11693
|
if (isConfigParseError(err)) return parseErrorResult(kagiError);
|
|
11426
11694
|
}
|
|
11427
11695
|
continue;
|
|
@@ -11439,7 +11707,7 @@ async function extractContent(url, signal, options) {
|
|
|
11439
11707
|
}
|
|
11440
11708
|
} catch (err) {
|
|
11441
11709
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11442
|
-
ollamaError =
|
|
11710
|
+
ollamaError = errorMessage40(err);
|
|
11443
11711
|
if (isConfigParseError(err)) return parseErrorResult(ollamaError);
|
|
11444
11712
|
}
|
|
11445
11713
|
continue;
|
|
@@ -11452,7 +11720,7 @@ async function extractContent(url, signal, options) {
|
|
|
11452
11720
|
}
|
|
11453
11721
|
} catch (err) {
|
|
11454
11722
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11455
|
-
parallelError =
|
|
11723
|
+
parallelError = errorMessage40(err);
|
|
11456
11724
|
if (isConfigParseError(err)) return parseErrorResult(parallelError);
|
|
11457
11725
|
}
|
|
11458
11726
|
continue;
|
|
@@ -11463,7 +11731,7 @@ async function extractContent(url, signal, options) {
|
|
|
11463
11731
|
if (parallelMcpResult) return withDeclaredLinks(parallelMcpResult);
|
|
11464
11732
|
} catch (err) {
|
|
11465
11733
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11466
|
-
parallelMcpError =
|
|
11734
|
+
parallelMcpError = errorMessage40(err);
|
|
11467
11735
|
if (isConfigParseError(err)) return parseErrorResult(parallelMcpError);
|
|
11468
11736
|
}
|
|
11469
11737
|
continue;
|
|
@@ -11481,7 +11749,7 @@ async function extractContent(url, signal, options) {
|
|
|
11481
11749
|
}
|
|
11482
11750
|
} catch (err) {
|
|
11483
11751
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11484
|
-
brightdataError =
|
|
11752
|
+
brightdataError = errorMessage40(err);
|
|
11485
11753
|
if (isConfigParseError(err)) return parseErrorResult(brightdataError);
|
|
11486
11754
|
}
|
|
11487
11755
|
continue;
|
|
@@ -11493,7 +11761,7 @@ async function extractContent(url, signal, options) {
|
|
|
11493
11761
|
} catch (err) {
|
|
11494
11762
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11495
11763
|
if (err instanceof CredentialResolutionError || isConfigParseError(err)) {
|
|
11496
|
-
return parseErrorResult(
|
|
11764
|
+
return parseErrorResult(errorMessage40(err));
|
|
11497
11765
|
}
|
|
11498
11766
|
}
|
|
11499
11767
|
if (geminiResult) return withDeclaredLinks(geminiResult);
|
|
@@ -11509,7 +11777,7 @@ async function extractContent(url, signal, options) {
|
|
|
11509
11777
|
}
|
|
11510
11778
|
} catch (err) {
|
|
11511
11779
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11512
|
-
deepseekError =
|
|
11780
|
+
deepseekError = errorMessage40(err);
|
|
11513
11781
|
if (isConfigParseError(err)) return parseErrorResult(deepseekError);
|
|
11514
11782
|
}
|
|
11515
11783
|
continue;
|
|
@@ -11525,7 +11793,7 @@ async function extractContent(url, signal, options) {
|
|
|
11525
11793
|
}
|
|
11526
11794
|
} catch (err) {
|
|
11527
11795
|
if (isAbortError5(err)) return abortedResult(url);
|
|
11528
|
-
exaError =
|
|
11796
|
+
exaError = errorMessage40(err);
|
|
11529
11797
|
if (isConfigParseError(err)) return parseErrorResult(exaError);
|
|
11530
11798
|
}
|
|
11531
11799
|
continue;
|
|
@@ -11555,6 +11823,7 @@ async function extractContent(url, signal, options) {
|
|
|
11555
11823
|
...deepseekError ? [`DeepSeek fallback failed: ${deepseekError}`] : [],
|
|
11556
11824
|
...exaError ? [`Exa fallback failed: ${exaError}`] : [],
|
|
11557
11825
|
...tabstackError ? [`Tabstack fallback failed: ${tabstackError}`] : [],
|
|
11826
|
+
...specstreamError ? [`SpecStream fallback failed: ${specstreamError}`] : [],
|
|
11558
11827
|
"",
|
|
11559
11828
|
"Fallback options:",
|
|
11560
11829
|
...jinaHint ? [jinaHint] : [],
|
|
@@ -11570,6 +11839,7 @@ async function extractContent(url, signal, options) {
|
|
|
11570
11839
|
` \u2022 Set deepseekApiKey in ${WEB_SEARCH_CONFIG_PATH3} or DEEPSEEK_API_KEY and add "deepseek" to fetchRouting.providers`,
|
|
11571
11840
|
` \u2022 Set exaApiKey in ${WEB_SEARCH_CONFIG_PATH3} or EXA_API_KEY and add "exa" to fetchRouting.providers`,
|
|
11572
11841
|
` \u2022 Set tabstackApiKey in ${WEB_SEARCH_CONFIG_PATH3} or TABSTACK_API_KEY and add "tabstack" to fetchRouting.providers`,
|
|
11842
|
+
` \u2022 Set specstreamApiKey in ${WEB_SEARCH_CONFIG_PATH3} or SPECSTREAM_API_KEY and add "specstream" to fetchRouting.providers`,
|
|
11573
11843
|
` \u2022 Set GEMINI_API_KEY in ${WEB_SEARCH_CONFIG_PATH3}`,
|
|
11574
11844
|
" \u2022 Sign into gemini.google.com in Chrome",
|
|
11575
11845
|
...searchToolName ? [` \u2022 Use ${searchToolName} to find content about this topic`] : []
|
|
@@ -11585,6 +11855,13 @@ function isExecutableScriptType(type) {
|
|
|
11585
11855
|
const mime = (type ?? "").split(";")[0].trim().toLowerCase();
|
|
11586
11856
|
return mime === "" || mime === "module" || JAVASCRIPT_MIME_TYPES.has(mime);
|
|
11587
11857
|
}
|
|
11858
|
+
function visibleTextLength(document) {
|
|
11859
|
+
for (const node of document.querySelectorAll("script, style, noscript, template")) node.remove();
|
|
11860
|
+
return (document.body?.textContent ?? "").replace(/\s+/g, " ").trim().length;
|
|
11861
|
+
}
|
|
11862
|
+
function markdownTextLength(markdown) {
|
|
11863
|
+
return markdown.replace(/\]\([^)\s]*\)?/g, "]").replace(/!\[[^\]]*\]?/g, "").replace(/\s+/g, " ").trim().length;
|
|
11864
|
+
}
|
|
11588
11865
|
function isLikelyJSRendered(html) {
|
|
11589
11866
|
const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
|
|
11590
11867
|
if (!bodyMatch) return false;
|
|
@@ -11766,7 +12043,7 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
11766
12043
|
status: response.status
|
|
11767
12044
|
};
|
|
11768
12045
|
} catch (err) {
|
|
11769
|
-
const message =
|
|
12046
|
+
const message = errorMessage40(err);
|
|
11770
12047
|
activityMonitor.logError(activityId, message);
|
|
11771
12048
|
return { url, title: "", content: "", error: message, mimeType, status: response.status };
|
|
11772
12049
|
}
|
|
@@ -11909,8 +12186,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
11909
12186
|
if (!isLikelyJSRendered(text7)) {
|
|
11910
12187
|
const { document: original } = parseHTML(text7);
|
|
11911
12188
|
const hasExecutableScript = [...original.querySelectorAll("script")].some((script) => isExecutableScriptType(script.getAttribute("type")));
|
|
11912
|
-
|
|
11913
|
-
const visibleChars = (original.body?.textContent ?? "").replace(/\s+/g, " ").trim().length;
|
|
12189
|
+
const visibleChars = visibleTextLength(original);
|
|
11914
12190
|
const extractedChars = markdown.trim().length;
|
|
11915
12191
|
const counts = `Extracted content appears incomplete: extracted ${extractedChars} characters from a page with ${visibleChars} characters of visible text`;
|
|
11916
12192
|
if (visibleChars >= MIN_USEFUL_CONTENT2) error = counts;
|
|
@@ -11925,6 +12201,21 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
11925
12201
|
declaredLinks
|
|
11926
12202
|
};
|
|
11927
12203
|
}
|
|
12204
|
+
const extractedText = markdownTextLength(markdown);
|
|
12205
|
+
if (extractedText < visibleTextLength(parseHTML(text7).document) * 0.5) {
|
|
12206
|
+
controller.signal.throwIfAborted();
|
|
12207
|
+
const defuddleResult = await extractWithDefuddle(text7, response.url || url).catch(() => null);
|
|
12208
|
+
controller.signal.throwIfAborted();
|
|
12209
|
+
if (defuddleResult && defuddleResult.content.length >= MIN_USEFUL_CONTENT2 && markdownTextLength(defuddleResult.content) >= extractedText * 1.5) {
|
|
12210
|
+
return {
|
|
12211
|
+
url,
|
|
12212
|
+
title: article.title || documentTitle || defuddleResult.title,
|
|
12213
|
+
content: appendDeclaredWebLinks(defuddleResult.content, declaredLinks),
|
|
12214
|
+
error: null,
|
|
12215
|
+
declaredLinks
|
|
12216
|
+
};
|
|
12217
|
+
}
|
|
12218
|
+
}
|
|
11928
12219
|
return {
|
|
11929
12220
|
url,
|
|
11930
12221
|
title: article.title || documentTitle,
|
|
@@ -11986,6 +12277,7 @@ var init_extract = __esm({
|
|
|
11986
12277
|
init_search1api();
|
|
11987
12278
|
init_querit();
|
|
11988
12279
|
init_tabstack();
|
|
12280
|
+
init_specstream();
|
|
11989
12281
|
init_kagi();
|
|
11990
12282
|
init_ollama();
|
|
11991
12283
|
init_firecrawl();
|
|
@@ -12007,9 +12299,9 @@ var init_extract = __esm({
|
|
|
12007
12299
|
NON_RECOVERABLE_ERRORS = ["Unsupported content type", "Response too large", "PDF extraction is disabled", "Image fetching is disabled", "fetchContent.curl command not found"];
|
|
12008
12300
|
MIN_USEFUL_CONTENT2 = 500;
|
|
12009
12301
|
SUPPORTED_IMAGE_TYPES = /* @__PURE__ */ new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
12010
|
-
FETCH_PROVIDERS = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack"];
|
|
12302
|
+
FETCH_PROVIDERS = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack", "specstream"];
|
|
12011
12303
|
DEFAULT_FETCH_PROVIDER_ORDER = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "brightdata", "gemini"];
|
|
12012
|
-
REMOTE_HOSTED_FETCH_PROVIDERS = /* @__PURE__ */ new Set(["jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack"]);
|
|
12304
|
+
REMOTE_HOSTED_FETCH_PROVIDERS = /* @__PURE__ */ new Set(["jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek", "exa", "tabstack", "specstream"]);
|
|
12013
12305
|
REDIRECT_STATUSES4 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
12014
12306
|
fetchLimit = pLimit(CONCURRENT_LIMIT);
|
|
12015
12307
|
JINA_READER_BASE = "https://r.jina.ai/";
|
|
@@ -12044,8 +12336,8 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
12044
12336
|
// package.json
|
|
12045
12337
|
var package_default = {
|
|
12046
12338
|
name: "pi-web-access",
|
|
12047
|
-
version: "0.
|
|
12048
|
-
description: "Web search, URL fetching, GitHub repo cloning, PDF extraction, YouTube video understanding, and local video analysis for Pi coding agent. Supports OpenAI, Brave, Parallel, TinyFish, Search1API, Searchinfinity, Querit, Tavily, Firecrawl, Crawl4AI, Jina, SERPdive, Kagi, Ollama, AnySearch, Bright Data SERP, SerpBase, SerpApi, Serply, SearchApi, Outcrawl, Sofya, You.com, SearXNG, degoog, Exa, Perplexity, Gemini, Kimi, Mistral, and Tabstack.",
|
|
12339
|
+
version: "0.48.0",
|
|
12340
|
+
description: "Web search, URL fetching, GitHub repo cloning, PDF extraction, YouTube video understanding, and local video analysis for Pi coding agent. Supports OpenAI, Brave, Parallel, TinyFish, Search1API, Searchinfinity, Querit, Tavily, Firecrawl, Crawl4AI, Jina, SERPdive, Kagi, Ollama, AnySearch, Bright Data SERP, SerpBase, SerpApi, Serply, SearchApi, Outcrawl, Sofya, cloro, Autom, SpecStream, You.com, SearXNG, degoog, Exa, Perplexity, Gemini, Kimi, Mistral, and Tabstack.",
|
|
12049
12341
|
type: "module",
|
|
12050
12342
|
bin: {
|
|
12051
12343
|
"pi-web-access-mcp": "dist/mcp-cli.js"
|
|
@@ -20616,7 +20908,7 @@ __export(value_exports, {
|
|
|
20616
20908
|
});
|
|
20617
20909
|
|
|
20618
20910
|
// gemini-search.ts
|
|
20619
|
-
import { existsSync as
|
|
20911
|
+
import { existsSync as existsSync52, readFileSync as readFileSync53 } from "node:fs";
|
|
20620
20912
|
|
|
20621
20913
|
// abortable.ts
|
|
20622
20914
|
async function awaitWithAbort(operation, signal) {
|
|
@@ -23344,81 +23636,178 @@ async function searchWithDegoog(query, options = {}) {
|
|
|
23344
23636
|
// duckduckgo.ts
|
|
23345
23637
|
init_activity();
|
|
23346
23638
|
init_domain_filter_normalization();
|
|
23639
|
+
import { join as join4 } from "node:path";
|
|
23347
23640
|
|
|
23348
23641
|
// duckduckgo-rate-limit.ts
|
|
23349
|
-
|
|
23350
|
-
|
|
23351
|
-
var
|
|
23642
|
+
import { mkdirSync, readFileSync as readFileSync28, renameSync, writeFileSync } from "node:fs";
|
|
23643
|
+
import { dirname } from "node:path";
|
|
23644
|
+
var DEFAULT_MIN_INTERVAL_MS = 1e4;
|
|
23645
|
+
var DEFAULT_WINDOW_MS = 10 * 6e4;
|
|
23646
|
+
var DEFAULT_MAX_STARTS = 10;
|
|
23647
|
+
var DEFAULT_COOLDOWN_MS = 30 * 6e4;
|
|
23648
|
+
var DEFAULT_MAX_COOLDOWN_MS = 2 * 60 * 6e4;
|
|
23352
23649
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
23650
|
+
var REQUEST_ALLOWANCE_MS = 1e4;
|
|
23353
23651
|
var DuckDuckGoBotCheckError = class extends Error {
|
|
23354
23652
|
constructor(status) {
|
|
23355
23653
|
super(`DuckDuckGo blocked the request with a bot check (HTTP ${status}, rate limited); use another search provider`);
|
|
23356
23654
|
this.name = "DuckDuckGoBotCheckError";
|
|
23357
23655
|
}
|
|
23358
23656
|
};
|
|
23657
|
+
function cooldownError(remainingMs) {
|
|
23658
|
+
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`);
|
|
23659
|
+
}
|
|
23359
23660
|
var DuckDuckGoRateLimit = class {
|
|
23360
23661
|
queue = Promise.resolve();
|
|
23361
|
-
|
|
23362
|
-
|
|
23363
|
-
|
|
23662
|
+
/** Searches queued that have not started yet. */
|
|
23663
|
+
waiting = 0;
|
|
23664
|
+
/** Actual start times of the latest `maxStarts` searches, oldest first. */
|
|
23665
|
+
starts = [];
|
|
23666
|
+
cooldown;
|
|
23364
23667
|
now;
|
|
23365
23668
|
sleep;
|
|
23366
23669
|
minIntervalMs;
|
|
23670
|
+
windowMs;
|
|
23671
|
+
maxStarts;
|
|
23367
23672
|
cooldownMs;
|
|
23368
23673
|
maxCooldownMs;
|
|
23369
23674
|
timeoutMs;
|
|
23675
|
+
statePath;
|
|
23370
23676
|
constructor(options = {}) {
|
|
23371
23677
|
this.now = options.now ?? Date.now;
|
|
23372
23678
|
this.sleep = options.sleep ?? defaultSleep;
|
|
23373
23679
|
this.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;
|
|
23680
|
+
this.windowMs = options.windowMs ?? DEFAULT_WINDOW_MS;
|
|
23681
|
+
this.maxStarts = Math.max(1, options.maxStarts ?? DEFAULT_MAX_STARTS);
|
|
23374
23682
|
this.cooldownMs = options.cooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
23375
23683
|
this.maxCooldownMs = options.maxCooldownMs ?? DEFAULT_MAX_COOLDOWN_MS;
|
|
23376
|
-
this.nextCooldownMs = this.cooldownMs;
|
|
23377
23684
|
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
23685
|
+
this.statePath = options.statePath;
|
|
23686
|
+
this.cooldown = { blockedUntil: 0, nextCooldownMs: this.cooldownMs };
|
|
23378
23687
|
}
|
|
23379
23688
|
/**
|
|
23380
|
-
* Queues `operation` and
|
|
23381
|
-
* the deadline passes. A
|
|
23382
|
-
*
|
|
23689
|
+
* Queues `operation` behind earlier searches and runs it with a signal that fires on the
|
|
23690
|
+
* caller's abort or when the deadline passes. A search that cannot start before its
|
|
23691
|
+
* deadline fails at once as rate limited, so routing moves on without waiting. A passed
|
|
23692
|
+
* deadline rejects with a "timed out" error rather than an abort, so search routing
|
|
23693
|
+
* treats it as a network failure and can fall back.
|
|
23383
23694
|
*/
|
|
23384
|
-
run(operation, callerSignal) {
|
|
23385
|
-
if (callerSignal?.aborted)
|
|
23695
|
+
async run(operation, callerSignal) {
|
|
23696
|
+
if (callerSignal?.aborted) throw new Error("Aborted");
|
|
23697
|
+
const now = this.now();
|
|
23698
|
+
const latestStart = now + Math.max(0, this.timeoutMs - REQUEST_ALLOWANCE_MS);
|
|
23699
|
+
this.throwIfBlocked(now);
|
|
23700
|
+
const slot = this.nextSlot(now, this.waiting + 1);
|
|
23701
|
+
if (slot > latestStart) throw this.busyError(slot - now);
|
|
23386
23702
|
const deadline = AbortSignal.timeout(this.timeoutMs);
|
|
23387
23703
|
const signal = callerSignal ? AbortSignal.any([deadline, callerSignal]) : deadline;
|
|
23388
|
-
|
|
23389
|
-
|
|
23390
|
-
|
|
23704
|
+
this.waiting++;
|
|
23705
|
+
const started = this.queue.then(() => this.waitForSlot(signal, latestStart)).finally(() => {
|
|
23706
|
+
this.waiting--;
|
|
23707
|
+
});
|
|
23708
|
+
this.queue = started.then(() => void 0, () => void 0);
|
|
23709
|
+
try {
|
|
23710
|
+
return await awaitWithAbort(started.then(() => this.attempt(operation, signal)), signal);
|
|
23711
|
+
} catch (error) {
|
|
23391
23712
|
if (deadline.aborted && !callerSignal?.aborted) {
|
|
23392
23713
|
throw new Error(`DuckDuckGo request timed out after ${formatWait(this.timeoutMs)}`);
|
|
23393
23714
|
}
|
|
23394
23715
|
throw error;
|
|
23395
|
-
}
|
|
23716
|
+
}
|
|
23396
23717
|
}
|
|
23397
|
-
|
|
23398
|
-
|
|
23399
|
-
const
|
|
23400
|
-
|
|
23401
|
-
|
|
23402
|
-
|
|
23403
|
-
|
|
23718
|
+
/** Start time of the `count`th search from now, given the searches already started. */
|
|
23719
|
+
nextSlot(now, count) {
|
|
23720
|
+
const starts = [...this.starts];
|
|
23721
|
+
let slot = now;
|
|
23722
|
+
for (let i = 0; i < count; i++) {
|
|
23723
|
+
slot = Math.max(now, (starts.at(-1) ?? Number.NEGATIVE_INFINITY) + this.minIntervalMs);
|
|
23724
|
+
if (starts.length >= this.maxStarts) slot = Math.max(slot, starts[starts.length - this.maxStarts] + this.windowMs);
|
|
23725
|
+
starts.push(slot);
|
|
23726
|
+
}
|
|
23727
|
+
return slot;
|
|
23728
|
+
}
|
|
23729
|
+
/** Runs at the head of the queue, so spacing is measured from the previous search's actual start. */
|
|
23730
|
+
async waitForSlot(signal, latestStart) {
|
|
23731
|
+
for (; ; ) {
|
|
23732
|
+
if (signal.aborted) throw new Error("Aborted");
|
|
23733
|
+
const now = this.now();
|
|
23734
|
+
this.throwIfBlocked(now);
|
|
23735
|
+
const slot = this.nextSlot(now, 1);
|
|
23736
|
+
if (slot <= now) {
|
|
23737
|
+
this.starts.push(now);
|
|
23738
|
+
if (this.starts.length > this.maxStarts) this.starts.shift();
|
|
23739
|
+
return;
|
|
23740
|
+
}
|
|
23741
|
+
if (slot > latestStart) throw this.busyError(slot - now);
|
|
23742
|
+
await this.sleep(slot - now, signal);
|
|
23743
|
+
}
|
|
23744
|
+
}
|
|
23745
|
+
busyError(waitMs) {
|
|
23746
|
+
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`);
|
|
23747
|
+
}
|
|
23748
|
+
throwIfBlocked(now) {
|
|
23749
|
+
this.loadSharedCooldown();
|
|
23750
|
+
const remainingMs = this.cooldown.blockedUntil - now;
|
|
23751
|
+
if (remainingMs > 0) throw cooldownError(remainingMs);
|
|
23752
|
+
}
|
|
23753
|
+
async attempt(operation, signal) {
|
|
23404
23754
|
try {
|
|
23405
23755
|
const result = await operation(signal);
|
|
23406
|
-
this.
|
|
23756
|
+
this.loadSharedCooldown();
|
|
23757
|
+
if (this.cooldown.nextCooldownMs !== this.cooldownMs && this.cooldown.blockedUntil <= this.now()) {
|
|
23758
|
+
this.cooldown = { ...this.cooldown, nextCooldownMs: this.cooldownMs };
|
|
23759
|
+
this.saveSharedCooldown();
|
|
23760
|
+
}
|
|
23407
23761
|
return result;
|
|
23408
23762
|
} catch (error) {
|
|
23409
23763
|
if (error instanceof DuckDuckGoBotCheckError) {
|
|
23410
|
-
this.
|
|
23411
|
-
|
|
23764
|
+
this.loadSharedCooldown();
|
|
23765
|
+
const now = this.now();
|
|
23766
|
+
if (this.cooldown.blockedUntil <= now) {
|
|
23767
|
+
const pauseMs = this.cooldown.nextCooldownMs;
|
|
23768
|
+
this.cooldown = { blockedUntil: now + pauseMs, nextCooldownMs: Math.min(pauseMs * 2, this.maxCooldownMs) };
|
|
23769
|
+
this.saveSharedCooldown();
|
|
23770
|
+
}
|
|
23412
23771
|
}
|
|
23413
23772
|
throw error;
|
|
23414
23773
|
}
|
|
23415
23774
|
}
|
|
23775
|
+
// The state file is best effort: if it cannot be read or written, this process keeps
|
|
23776
|
+
// its own pause, and a search never fails or loses its result because of the file.
|
|
23777
|
+
loadSharedCooldown() {
|
|
23778
|
+
if (!this.statePath) return;
|
|
23779
|
+
try {
|
|
23780
|
+
const saved = JSON.parse(readFileSync28(this.statePath, "utf8"));
|
|
23781
|
+
const { blockedUntil, nextCooldownMs } = saved;
|
|
23782
|
+
if (typeof blockedUntil !== "number" || typeof nextCooldownMs !== "number" || !(nextCooldownMs > 0)) return;
|
|
23783
|
+
if (!(blockedUntil <= this.now() + this.maxCooldownMs)) return;
|
|
23784
|
+
if (blockedUntil >= this.cooldown.blockedUntil) {
|
|
23785
|
+
this.cooldown = { blockedUntil, nextCooldownMs: Math.min(nextCooldownMs, this.maxCooldownMs) };
|
|
23786
|
+
}
|
|
23787
|
+
} catch {
|
|
23788
|
+
}
|
|
23789
|
+
}
|
|
23790
|
+
saveSharedCooldown() {
|
|
23791
|
+
if (!this.statePath) return;
|
|
23792
|
+
try {
|
|
23793
|
+
mkdirSync(dirname(this.statePath), { recursive: true, mode: 448 });
|
|
23794
|
+
const tmpPath = `${this.statePath}.${process.pid}.tmp`;
|
|
23795
|
+
writeFileSync(tmpPath, JSON.stringify(this.cooldown), { mode: 384 });
|
|
23796
|
+
renameSync(tmpPath, this.statePath);
|
|
23797
|
+
} catch {
|
|
23798
|
+
}
|
|
23799
|
+
}
|
|
23416
23800
|
};
|
|
23417
23801
|
|
|
23418
23802
|
// duckduckgo.ts
|
|
23419
23803
|
init_search_result_count_normalization();
|
|
23804
|
+
init_utils();
|
|
23420
23805
|
var SEARCH_URL = "https://html.duckduckgo.com/html/";
|
|
23421
|
-
var
|
|
23806
|
+
var STATE_FILE = "duckduckgo-cooldown.json";
|
|
23807
|
+
var rateLimit = null;
|
|
23808
|
+
function getRateLimit() {
|
|
23809
|
+
return rateLimit ??= new DuckDuckGoRateLimit({ statePath: join4(getWebSearchConfigDir(), STATE_FILE) });
|
|
23810
|
+
}
|
|
23422
23811
|
function normalizeDomainFilters5(domainFilter) {
|
|
23423
23812
|
const filters = { allowed: [], blocked: [] };
|
|
23424
23813
|
for (const raw of domainFilter ?? []) {
|
|
@@ -23456,7 +23845,7 @@ async function searchWithDuckDuckGo(query, options = {}) {
|
|
|
23456
23845
|
url.searchParams.set("q", query);
|
|
23457
23846
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
23458
23847
|
try {
|
|
23459
|
-
return await
|
|
23848
|
+
return await getRateLimit().run(async (signal) => {
|
|
23460
23849
|
const response = await fetch(url, {
|
|
23461
23850
|
method: "GET",
|
|
23462
23851
|
headers: {
|
|
@@ -23511,9 +23900,11 @@ init_activity();
|
|
|
23511
23900
|
init_search_answer_formatting();
|
|
23512
23901
|
init_search_result_count_normalization();
|
|
23513
23902
|
init_credential_source();
|
|
23903
|
+
init_domain_filter_normalization();
|
|
23514
23904
|
init_utils();
|
|
23515
|
-
import { existsSync as existsSync28, readFileSync as
|
|
23905
|
+
import { existsSync as existsSync28, readFileSync as readFileSync29 } from "node:fs";
|
|
23516
23906
|
var ANYSEARCH_API_URL = "https://api.anysearch.com/v1/search";
|
|
23907
|
+
var ANYSEARCH_MAX_RESULTS = 10;
|
|
23517
23908
|
var CONFIG_PATH25 = getWebSearchConfigPath();
|
|
23518
23909
|
var SEARCH_TIMEOUT_MS19 = 3e4;
|
|
23519
23910
|
var cachedConfig24 = null;
|
|
@@ -23523,7 +23914,7 @@ function loadConfig24() {
|
|
|
23523
23914
|
cachedConfig24 = {};
|
|
23524
23915
|
return cachedConfig24;
|
|
23525
23916
|
}
|
|
23526
|
-
const raw =
|
|
23917
|
+
const raw = readFileSync29(CONFIG_PATH25, "utf-8");
|
|
23527
23918
|
let parsed;
|
|
23528
23919
|
try {
|
|
23529
23920
|
parsed = JSON.parse(raw);
|
|
@@ -23588,7 +23979,7 @@ function isAnySearchAvailable() {
|
|
|
23588
23979
|
}
|
|
23589
23980
|
async function searchWithAnySearch(query, options = {}) {
|
|
23590
23981
|
const apiKey = await getApiKey18(options.signal);
|
|
23591
|
-
const numResults = normalizeSearchResultCount(options.numResults);
|
|
23982
|
+
const numResults = Math.min(normalizeSearchResultCount(options.numResults), ANYSEARCH_MAX_RESULTS);
|
|
23592
23983
|
const body = { query, max_results: numResults };
|
|
23593
23984
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
23594
23985
|
let response;
|
|
@@ -23632,14 +24023,15 @@ async function searchWithAnySearch(query, options = {}) {
|
|
|
23632
24023
|
throw err;
|
|
23633
24024
|
}
|
|
23634
24025
|
activityMonitor.logComplete(activityId, response.status);
|
|
23635
|
-
const
|
|
24026
|
+
const filtered = applyDomainFilter(data.data.results, options.domainFilter).slice(0, numResults);
|
|
24027
|
+
const results = filtered.map((result) => ({
|
|
23636
24028
|
title: result.title,
|
|
23637
24029
|
url: result.url,
|
|
23638
24030
|
snippet: result.snippet
|
|
23639
24031
|
}));
|
|
23640
24032
|
const mapped = { answer: formatSearchResultsAsAnswer(results), results };
|
|
23641
24033
|
if (options.includeContent) {
|
|
23642
|
-
const inlineContent =
|
|
24034
|
+
const inlineContent = filtered.filter((result) => result.content.length > 0).map((result) => ({ url: result.url, title: result.title, content: result.content, error: null }));
|
|
23643
24035
|
if (inlineContent.length > 0) mapped.inlineContent = inlineContent;
|
|
23644
24036
|
}
|
|
23645
24037
|
return mapped;
|
|
@@ -23652,7 +24044,7 @@ init_search_answer_formatting();
|
|
|
23652
24044
|
init_search_result_count_normalization();
|
|
23653
24045
|
init_credential_source();
|
|
23654
24046
|
init_utils();
|
|
23655
|
-
import { existsSync as existsSync29, readFileSync as
|
|
24047
|
+
import { existsSync as existsSync29, readFileSync as readFileSync30 } from "node:fs";
|
|
23656
24048
|
var XCRAWL_API_URL = "https://run.xcrawl.com/v1/serp";
|
|
23657
24049
|
var CONFIG_PATH26 = getWebSearchConfigPath();
|
|
23658
24050
|
var SEARCH_TIMEOUT_MS20 = 6e4;
|
|
@@ -23663,7 +24055,7 @@ function loadConfig25() {
|
|
|
23663
24055
|
cachedConfig25 = {};
|
|
23664
24056
|
return cachedConfig25;
|
|
23665
24057
|
}
|
|
23666
|
-
const raw =
|
|
24058
|
+
const raw = readFileSync30(CONFIG_PATH26, "utf-8");
|
|
23667
24059
|
let parsed;
|
|
23668
24060
|
try {
|
|
23669
24061
|
parsed = JSON.parse(raw);
|
|
@@ -23709,7 +24101,7 @@ function absolutizeLink(link) {
|
|
|
23709
24101
|
return link;
|
|
23710
24102
|
}
|
|
23711
24103
|
}
|
|
23712
|
-
function
|
|
24104
|
+
function applyDomainFilter2(results, domainFilter) {
|
|
23713
24105
|
const includes = [];
|
|
23714
24106
|
const excludes = [];
|
|
23715
24107
|
for (const raw of domainFilter) {
|
|
@@ -23825,7 +24217,7 @@ async function searchWithXCrawl(query, options = {}) {
|
|
|
23825
24217
|
throw invalidResponse6(`response body is not valid JSON: ${errorMessage18(err)}`);
|
|
23826
24218
|
}
|
|
23827
24219
|
const results = parseResponse3(payload);
|
|
23828
|
-
const filtered = (options.domainFilter?.length ?
|
|
24220
|
+
const filtered = (options.domainFilter?.length ? applyDomainFilter2(results, options.domainFilter) : results).slice(0, numResults);
|
|
23829
24221
|
return {
|
|
23830
24222
|
answer: formatSearchResultsAsAnswer(filtered),
|
|
23831
24223
|
results: filtered
|
|
@@ -23837,7 +24229,7 @@ init_activity();
|
|
|
23837
24229
|
init_domain_filter_normalization();
|
|
23838
24230
|
init_credential_source();
|
|
23839
24231
|
init_utils();
|
|
23840
|
-
import { existsSync as existsSync30, readFileSync as
|
|
24232
|
+
import { existsSync as existsSync30, readFileSync as readFileSync31 } from "node:fs";
|
|
23841
24233
|
var XAI_RESPONSES_URL = "https://api.x.ai/v1/responses";
|
|
23842
24234
|
var CONFIG_PATH27 = getWebSearchConfigPath();
|
|
23843
24235
|
var DEFAULT_SEARCH_TIMEOUT_MS = 6e4;
|
|
@@ -23852,7 +24244,7 @@ function loadConfig26() {
|
|
|
23852
24244
|
cachedConfig26 = {};
|
|
23853
24245
|
return cachedConfig26;
|
|
23854
24246
|
}
|
|
23855
|
-
const raw =
|
|
24247
|
+
const raw = readFileSync31(CONFIG_PATH27, "utf-8");
|
|
23856
24248
|
try {
|
|
23857
24249
|
cachedConfig26 = JSON.parse(raw);
|
|
23858
24250
|
return cachedConfig26;
|
|
@@ -24174,7 +24566,7 @@ init_search_answer_formatting();
|
|
|
24174
24566
|
init_search_result_count_normalization();
|
|
24175
24567
|
init_credential_source();
|
|
24176
24568
|
init_utils();
|
|
24177
|
-
import { existsSync as existsSync31, readFileSync as
|
|
24569
|
+
import { existsSync as existsSync31, readFileSync as readFileSync32 } from "node:fs";
|
|
24178
24570
|
var BRIGHTDATA_API_URL = "https://api.brightdata.com/request";
|
|
24179
24571
|
var CONFIG_PATH28 = getWebSearchConfigPath();
|
|
24180
24572
|
var SEARCH_TIMEOUT_MS21 = 6e4;
|
|
@@ -24196,7 +24588,7 @@ function loadConfig27() {
|
|
|
24196
24588
|
cachedConfig27 = {};
|
|
24197
24589
|
return cachedConfig27;
|
|
24198
24590
|
}
|
|
24199
|
-
const raw =
|
|
24591
|
+
const raw = readFileSync32(CONFIG_PATH28, "utf-8");
|
|
24200
24592
|
let parsed;
|
|
24201
24593
|
try {
|
|
24202
24594
|
parsed = JSON.parse(raw);
|
|
@@ -24471,7 +24863,7 @@ init_domain_filter_normalization();
|
|
|
24471
24863
|
init_search_answer_formatting();
|
|
24472
24864
|
init_credential_source();
|
|
24473
24865
|
init_utils();
|
|
24474
|
-
import { existsSync as existsSync32, readFileSync as
|
|
24866
|
+
import { existsSync as existsSync32, readFileSync as readFileSync33 } from "node:fs";
|
|
24475
24867
|
var SERPBASE_API_URL = "https://api.serpbase.dev/google/search";
|
|
24476
24868
|
var CONFIG_PATH29 = getWebSearchConfigPath();
|
|
24477
24869
|
var SEARCH_TIMEOUT_MS22 = 6e4;
|
|
@@ -24488,7 +24880,7 @@ function loadConfig28() {
|
|
|
24488
24880
|
cachedConfig28 = {};
|
|
24489
24881
|
return cachedConfig28;
|
|
24490
24882
|
}
|
|
24491
|
-
const raw =
|
|
24883
|
+
const raw = readFileSync33(CONFIG_PATH29, "utf-8");
|
|
24492
24884
|
let parsed;
|
|
24493
24885
|
try {
|
|
24494
24886
|
parsed = JSON.parse(raw);
|
|
@@ -24640,7 +25032,7 @@ init_search_answer_formatting();
|
|
|
24640
25032
|
init_search_result_count_normalization();
|
|
24641
25033
|
init_credential_source();
|
|
24642
25034
|
init_utils();
|
|
24643
|
-
import { existsSync as existsSync33, readFileSync as
|
|
25035
|
+
import { existsSync as existsSync33, readFileSync as readFileSync34 } from "node:fs";
|
|
24644
25036
|
var SERPAPI_API_BASE_URL = "https://serpapi.com";
|
|
24645
25037
|
var CONFIG_PATH30 = getWebSearchConfigPath();
|
|
24646
25038
|
var SEARCH_TIMEOUT_MS23 = 6e4;
|
|
@@ -24657,7 +25049,7 @@ function loadConfig29() {
|
|
|
24657
25049
|
cachedConfig29 = {};
|
|
24658
25050
|
return cachedConfig29;
|
|
24659
25051
|
}
|
|
24660
|
-
const raw =
|
|
25052
|
+
const raw = readFileSync34(CONFIG_PATH30, "utf-8");
|
|
24661
25053
|
let parsed;
|
|
24662
25054
|
try {
|
|
24663
25055
|
parsed = JSON.parse(raw);
|
|
@@ -24809,7 +25201,7 @@ init_search_answer_formatting();
|
|
|
24809
25201
|
init_search_result_count_normalization();
|
|
24810
25202
|
init_credential_source();
|
|
24811
25203
|
init_utils();
|
|
24812
|
-
import { existsSync as existsSync34, readFileSync as
|
|
25204
|
+
import { existsSync as existsSync34, readFileSync as readFileSync35 } from "node:fs";
|
|
24813
25205
|
var SERPER_API_BASE_URL = "https://google.serper.dev";
|
|
24814
25206
|
var CONFIG_PATH31 = getWebSearchConfigPath();
|
|
24815
25207
|
var SEARCH_TIMEOUT_MS24 = 6e4;
|
|
@@ -24826,7 +25218,7 @@ function loadConfig30() {
|
|
|
24826
25218
|
cachedConfig30 = {};
|
|
24827
25219
|
return cachedConfig30;
|
|
24828
25220
|
}
|
|
24829
|
-
const raw =
|
|
25221
|
+
const raw = readFileSync35(CONFIG_PATH31, "utf-8");
|
|
24830
25222
|
let parsed;
|
|
24831
25223
|
try {
|
|
24832
25224
|
parsed = JSON.parse(raw);
|
|
@@ -24971,7 +25363,7 @@ init_search_answer_formatting();
|
|
|
24971
25363
|
init_search_result_count_normalization();
|
|
24972
25364
|
init_credential_source();
|
|
24973
25365
|
init_utils();
|
|
24974
|
-
import { existsSync as existsSync35, readFileSync as
|
|
25366
|
+
import { existsSync as existsSync35, readFileSync as readFileSync36 } from "node:fs";
|
|
24975
25367
|
var SERPLY_SEARCH_URL = "https://api.serply.io/v1/search";
|
|
24976
25368
|
var CONFIG_PATH32 = getWebSearchConfigPath();
|
|
24977
25369
|
var SEARCH_TIMEOUT_MS25 = 6e4;
|
|
@@ -24988,7 +25380,7 @@ function loadConfig31() {
|
|
|
24988
25380
|
cachedConfig31 = {};
|
|
24989
25381
|
return cachedConfig31;
|
|
24990
25382
|
}
|
|
24991
|
-
const raw =
|
|
25383
|
+
const raw = readFileSync36(CONFIG_PATH32, "utf-8");
|
|
24992
25384
|
let parsed;
|
|
24993
25385
|
try {
|
|
24994
25386
|
parsed = JSON.parse(raw);
|
|
@@ -25138,7 +25530,7 @@ init_credential_source();
|
|
|
25138
25530
|
init_domain_filter_normalization();
|
|
25139
25531
|
init_search_result_count_normalization();
|
|
25140
25532
|
init_utils();
|
|
25141
|
-
import { existsSync as existsSync36, readFileSync as
|
|
25533
|
+
import { existsSync as existsSync36, readFileSync as readFileSync37 } from "node:fs";
|
|
25142
25534
|
import { isIP as isIP2 } from "node:net";
|
|
25143
25535
|
var MCP_URL = "https://agent-toolkit.app.baizhi.cloud/mcp";
|
|
25144
25536
|
var SEARCH_TIMEOUT_MS26 = 6e4;
|
|
@@ -25147,7 +25539,7 @@ function credentialOptions() {
|
|
|
25147
25539
|
let config = {};
|
|
25148
25540
|
if (existsSync36(CONFIG_PATH33)) {
|
|
25149
25541
|
try {
|
|
25150
|
-
const parsed = JSON.parse(
|
|
25542
|
+
const parsed = JSON.parse(readFileSync37(CONFIG_PATH33, "utf8"));
|
|
25151
25543
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
|
|
25152
25544
|
config = parsed;
|
|
25153
25545
|
} catch {
|
|
@@ -25251,7 +25643,7 @@ init_domain_filter_normalization();
|
|
|
25251
25643
|
init_search_answer_formatting();
|
|
25252
25644
|
init_search_result_count_normalization();
|
|
25253
25645
|
init_utils();
|
|
25254
|
-
import { existsSync as existsSync37, readFileSync as
|
|
25646
|
+
import { existsSync as existsSync37, readFileSync as readFileSync38 } from "node:fs";
|
|
25255
25647
|
var MCP_URLS = {
|
|
25256
25648
|
global: "https://api.z.ai/api/mcp/web_search_prime/mcp",
|
|
25257
25649
|
china: "https://open.bigmodel.cn/api/mcp/web_search_prime/mcp"
|
|
@@ -25262,7 +25654,7 @@ var CONFIG_PATH34 = getWebSearchConfigPath();
|
|
|
25262
25654
|
function loadConfig32() {
|
|
25263
25655
|
if (!existsSync37(CONFIG_PATH34)) return {};
|
|
25264
25656
|
try {
|
|
25265
|
-
const parsed = JSON.parse(
|
|
25657
|
+
const parsed = JSON.parse(readFileSync38(CONFIG_PATH34, "utf8"));
|
|
25266
25658
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
|
|
25267
25659
|
return parsed;
|
|
25268
25660
|
} catch {
|
|
@@ -25394,7 +25786,7 @@ init_search_answer_formatting();
|
|
|
25394
25786
|
init_search_result_count_normalization();
|
|
25395
25787
|
init_credential_source();
|
|
25396
25788
|
init_utils();
|
|
25397
|
-
import { existsSync as existsSync38, readFileSync as
|
|
25789
|
+
import { existsSync as existsSync38, readFileSync as readFileSync39 } from "node:fs";
|
|
25398
25790
|
var VALYU_SEARCH_URL = "https://api.valyu.ai/v1/search";
|
|
25399
25791
|
var CONFIG_PATH35 = getWebSearchConfigPath();
|
|
25400
25792
|
var SEARCH_TIMEOUT_MS28 = 6e4;
|
|
@@ -25407,7 +25799,7 @@ function loadConfig33() {
|
|
|
25407
25799
|
cachedConfig32 = {};
|
|
25408
25800
|
return cachedConfig32;
|
|
25409
25801
|
}
|
|
25410
|
-
const raw =
|
|
25802
|
+
const raw = readFileSync39(CONFIG_PATH35, "utf-8");
|
|
25411
25803
|
let parsed;
|
|
25412
25804
|
try {
|
|
25413
25805
|
parsed = JSON.parse(raw);
|
|
@@ -25546,7 +25938,7 @@ init_search_answer_formatting();
|
|
|
25546
25938
|
init_search_result_count_normalization();
|
|
25547
25939
|
init_credential_source();
|
|
25548
25940
|
init_utils();
|
|
25549
|
-
import { existsSync as existsSync39, readFileSync as
|
|
25941
|
+
import { existsSync as existsSync39, readFileSync as readFileSync40 } from "node:fs";
|
|
25550
25942
|
var KEENABLE_SEARCH_URL = "https://api.keenable.ai/v1/search";
|
|
25551
25943
|
var KEENABLE_PUBLIC_SEARCH_URL = "https://api.keenable.ai/v1/search/public";
|
|
25552
25944
|
var KEENABLE_CLIENT_TITLE = "pi-web-access";
|
|
@@ -25567,7 +25959,7 @@ function loadConfig34() {
|
|
|
25567
25959
|
cachedConfig33 = {};
|
|
25568
25960
|
return cachedConfig33;
|
|
25569
25961
|
}
|
|
25570
|
-
const raw =
|
|
25962
|
+
const raw = readFileSync40(CONFIG_PATH36, "utf-8");
|
|
25571
25963
|
let parsed;
|
|
25572
25964
|
try {
|
|
25573
25965
|
parsed = JSON.parse(raw);
|
|
@@ -25727,7 +26119,7 @@ init_search_answer_formatting();
|
|
|
25727
26119
|
init_search_result_count_normalization();
|
|
25728
26120
|
init_credential_source();
|
|
25729
26121
|
init_utils();
|
|
25730
|
-
import { existsSync as existsSync40, readFileSync as
|
|
26122
|
+
import { existsSync as existsSync40, readFileSync as readFileSync41 } from "node:fs";
|
|
25731
26123
|
var CERAMIC_SEARCH_URL = "https://api.ceramic.ai/search";
|
|
25732
26124
|
var CONFIG_PATH37 = getWebSearchConfigPath();
|
|
25733
26125
|
var SEARCH_TIMEOUT_MS30 = 3e4;
|
|
@@ -25741,7 +26133,7 @@ function loadConfig35() {
|
|
|
25741
26133
|
cachedConfig34 = {};
|
|
25742
26134
|
return cachedConfig34;
|
|
25743
26135
|
}
|
|
25744
|
-
const raw =
|
|
26136
|
+
const raw = readFileSync41(CONFIG_PATH37, "utf-8");
|
|
25745
26137
|
let parsed;
|
|
25746
26138
|
try {
|
|
25747
26139
|
parsed = JSON.parse(raw);
|
|
@@ -25910,7 +26302,7 @@ init_domain_filter_normalization();
|
|
|
25910
26302
|
init_search_answer_formatting();
|
|
25911
26303
|
init_search_result_count_normalization();
|
|
25912
26304
|
init_utils();
|
|
25913
|
-
import { existsSync as existsSync41, readFileSync as
|
|
26305
|
+
import { existsSync as existsSync41, readFileSync as readFileSync42 } from "node:fs";
|
|
25914
26306
|
var LINKUP_SEARCH_URL = "https://api.linkup.so/v1/search";
|
|
25915
26307
|
var CONFIG_PATH38 = getWebSearchConfigPath();
|
|
25916
26308
|
var SEARCH_TIMEOUT_MS31 = 6e4;
|
|
@@ -25921,7 +26313,7 @@ function loadConfig36() {
|
|
|
25921
26313
|
if (!existsSync41(CONFIG_PATH38)) return cachedConfig35 = {};
|
|
25922
26314
|
let parsed;
|
|
25923
26315
|
try {
|
|
25924
|
-
parsed = JSON.parse(
|
|
26316
|
+
parsed = JSON.parse(readFileSync42(CONFIG_PATH38, "utf-8"));
|
|
25925
26317
|
} catch {
|
|
25926
26318
|
throw new Error(`Failed to parse ${CONFIG_PATH38}: expected valid JSON`);
|
|
25927
26319
|
}
|
|
@@ -26058,14 +26450,14 @@ init_domain_filter_normalization();
|
|
|
26058
26450
|
init_search_answer_formatting();
|
|
26059
26451
|
init_search_result_count_normalization();
|
|
26060
26452
|
init_utils();
|
|
26061
|
-
import { existsSync as existsSync42, readFileSync as
|
|
26453
|
+
import { existsSync as existsSync42, readFileSync as readFileSync43 } from "node:fs";
|
|
26062
26454
|
var CONFIG_PATH39 = getWebSearchConfigPath();
|
|
26063
26455
|
var SEARCH_TIMEOUT_MS32 = 3e4;
|
|
26064
26456
|
function loadConfig37() {
|
|
26065
26457
|
if (!existsSync42(CONFIG_PATH39)) return {};
|
|
26066
26458
|
let parsed;
|
|
26067
26459
|
try {
|
|
26068
|
-
parsed = JSON.parse(
|
|
26460
|
+
parsed = JSON.parse(readFileSync43(CONFIG_PATH39, "utf-8"));
|
|
26069
26461
|
} catch {
|
|
26070
26462
|
parsed = void 0;
|
|
26071
26463
|
}
|
|
@@ -26149,7 +26541,7 @@ init_domain_filter_normalization();
|
|
|
26149
26541
|
init_search_answer_formatting();
|
|
26150
26542
|
init_search_result_count_normalization();
|
|
26151
26543
|
init_utils();
|
|
26152
|
-
import { existsSync as existsSync43, readFileSync as
|
|
26544
|
+
import { existsSync as existsSync43, readFileSync as readFileSync44 } from "node:fs";
|
|
26153
26545
|
var CONFIG_PATH40 = getWebSearchConfigPath();
|
|
26154
26546
|
var SEARCH_TIMEOUT_MS33 = 3e4;
|
|
26155
26547
|
var MAX_REQUEST_RESULTS3 = 10;
|
|
@@ -26166,7 +26558,7 @@ function loadConfig38() {
|
|
|
26166
26558
|
}
|
|
26167
26559
|
let parsed;
|
|
26168
26560
|
try {
|
|
26169
|
-
parsed = JSON.parse(
|
|
26561
|
+
parsed = JSON.parse(readFileSync44(CONFIG_PATH40, "utf-8"));
|
|
26170
26562
|
} catch {
|
|
26171
26563
|
parsed = void 0;
|
|
26172
26564
|
}
|
|
@@ -26345,7 +26737,7 @@ init_search_answer_formatting();
|
|
|
26345
26737
|
init_search_result_count_normalization();
|
|
26346
26738
|
init_credential_source();
|
|
26347
26739
|
init_utils();
|
|
26348
|
-
import { existsSync as existsSync44, readFileSync as
|
|
26740
|
+
import { existsSync as existsSync44, readFileSync as readFileSync45 } from "node:fs";
|
|
26349
26741
|
var SEARCHAPI_SEARCH_URL = "https://www.searchapi.io/api/v1/search";
|
|
26350
26742
|
var CONFIG_PATH41 = getWebSearchConfigPath();
|
|
26351
26743
|
var SEARCH_TIMEOUT_MS34 = 6e4;
|
|
@@ -26362,7 +26754,7 @@ function loadConfig39() {
|
|
|
26362
26754
|
cachedConfig37 = {};
|
|
26363
26755
|
return cachedConfig37;
|
|
26364
26756
|
}
|
|
26365
|
-
const raw =
|
|
26757
|
+
const raw = readFileSync45(CONFIG_PATH41, "utf-8");
|
|
26366
26758
|
let parsed;
|
|
26367
26759
|
try {
|
|
26368
26760
|
parsed = JSON.parse(raw);
|
|
@@ -26512,7 +26904,7 @@ init_search_answer_formatting();
|
|
|
26512
26904
|
init_search_result_count_normalization();
|
|
26513
26905
|
init_credential_source();
|
|
26514
26906
|
init_utils();
|
|
26515
|
-
import { existsSync as existsSync45, readFileSync as
|
|
26907
|
+
import { existsSync as existsSync45, readFileSync as readFileSync46 } from "node:fs";
|
|
26516
26908
|
var OUTCRAWL_SEARCH_URL = "https://api.outcrawl.ai/v1/search";
|
|
26517
26909
|
var CONFIG_PATH42 = getWebSearchConfigPath();
|
|
26518
26910
|
var SEARCH_TIMEOUT_MS35 = 6e4;
|
|
@@ -26524,7 +26916,7 @@ function loadConfig40() {
|
|
|
26524
26916
|
cachedConfig38 = {};
|
|
26525
26917
|
return cachedConfig38;
|
|
26526
26918
|
}
|
|
26527
|
-
const raw =
|
|
26919
|
+
const raw = readFileSync46(CONFIG_PATH42, "utf-8");
|
|
26528
26920
|
let parsed;
|
|
26529
26921
|
try {
|
|
26530
26922
|
parsed = JSON.parse(raw);
|
|
@@ -26682,7 +27074,7 @@ init_search_answer_formatting();
|
|
|
26682
27074
|
init_search_result_count_normalization();
|
|
26683
27075
|
init_credential_source();
|
|
26684
27076
|
init_utils();
|
|
26685
|
-
import { existsSync as existsSync46, readFileSync as
|
|
27077
|
+
import { existsSync as existsSync46, readFileSync as readFileSync47 } from "node:fs";
|
|
26686
27078
|
var SOFYA_SEARCH_URL = "https://sofya.co/v1/search";
|
|
26687
27079
|
var CONFIG_PATH43 = getWebSearchConfigPath();
|
|
26688
27080
|
var SEARCH_TIMEOUT_MS36 = 6e4;
|
|
@@ -26695,7 +27087,7 @@ function loadConfig41() {
|
|
|
26695
27087
|
cachedConfig39 = {};
|
|
26696
27088
|
return cachedConfig39;
|
|
26697
27089
|
}
|
|
26698
|
-
const raw =
|
|
27090
|
+
const raw = readFileSync47(CONFIG_PATH43, "utf-8");
|
|
26699
27091
|
let parsed;
|
|
26700
27092
|
try {
|
|
26701
27093
|
parsed = JSON.parse(raw);
|
|
@@ -26842,7 +27234,371 @@ async function searchWithSofya(query, options = {}) {
|
|
|
26842
27234
|
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
26843
27235
|
}
|
|
26844
27236
|
|
|
27237
|
+
// cloro.ts
|
|
27238
|
+
init_activity();
|
|
27239
|
+
init_domain_filter_normalization();
|
|
27240
|
+
init_search_answer_formatting();
|
|
27241
|
+
init_search_result_count_normalization();
|
|
27242
|
+
init_credential_source();
|
|
27243
|
+
init_utils();
|
|
27244
|
+
import { existsSync as existsSync47, readFileSync as readFileSync48 } from "node:fs";
|
|
27245
|
+
var CLORO_GOOGLE_URL = "https://api.cloro.dev/v1/monitor/google";
|
|
27246
|
+
var CLORO_AIMODE_URL = "https://api.cloro.dev/v1/monitor/aimode";
|
|
27247
|
+
var CLORO_BING_AIMODE_URL = "https://api.cloro.dev/v1/monitor/bing/aimode";
|
|
27248
|
+
var CONFIG_PATH44 = getWebSearchConfigPath();
|
|
27249
|
+
var SEARCH_TIMEOUT_MS37 = 12e4;
|
|
27250
|
+
var COUNTRY = "US";
|
|
27251
|
+
var MODES = ["google", "aimode", "bing_aimode"];
|
|
27252
|
+
var cachedConfig40 = null;
|
|
27253
|
+
function loadConfig42() {
|
|
27254
|
+
if (cachedConfig40) return cachedConfig40;
|
|
27255
|
+
if (!existsSync47(CONFIG_PATH44)) {
|
|
27256
|
+
cachedConfig40 = {};
|
|
27257
|
+
return cachedConfig40;
|
|
27258
|
+
}
|
|
27259
|
+
const raw = readFileSync48(CONFIG_PATH44, "utf-8");
|
|
27260
|
+
let parsed;
|
|
27261
|
+
try {
|
|
27262
|
+
parsed = JSON.parse(raw);
|
|
27263
|
+
} catch (err) {
|
|
27264
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
27265
|
+
throw new Error(`Failed to parse ${CONFIG_PATH44}: ${message}`);
|
|
27266
|
+
}
|
|
27267
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
27268
|
+
throw new Error(`Invalid config in ${CONFIG_PATH44}: expected a JSON object`);
|
|
27269
|
+
}
|
|
27270
|
+
cachedConfig40 = parsed;
|
|
27271
|
+
return cachedConfig40;
|
|
27272
|
+
}
|
|
27273
|
+
function getMode() {
|
|
27274
|
+
const value = loadConfig42().cloroMode;
|
|
27275
|
+
if (value === void 0) return "google";
|
|
27276
|
+
if (typeof value !== "string" || !MODES.includes(value)) {
|
|
27277
|
+
throw new Error(`cloroMode in ${CONFIG_PATH44} must be one of: ${MODES.join(", ")}`);
|
|
27278
|
+
}
|
|
27279
|
+
return value;
|
|
27280
|
+
}
|
|
27281
|
+
async function getApiKey30(signal) {
|
|
27282
|
+
return resolveCredential({
|
|
27283
|
+
provider: "cloro",
|
|
27284
|
+
configuredValue: loadConfig42().cloroApiKey,
|
|
27285
|
+
environmentValue: process.env.CLORO_API_KEY,
|
|
27286
|
+
signal
|
|
27287
|
+
});
|
|
27288
|
+
}
|
|
27289
|
+
async function requireApiKey18(signal) {
|
|
27290
|
+
const apiKey = await getApiKey30(signal);
|
|
27291
|
+
if (!apiKey) {
|
|
27292
|
+
throw new Error(
|
|
27293
|
+
`cloro API key not found. Either:
|
|
27294
|
+
1. Create ${CONFIG_PATH44} with { "cloroApiKey": "your-key" }
|
|
27295
|
+
2. Set CLORO_API_KEY environment variable
|
|
27296
|
+
Get a key at https://dashboard.cloro.dev/api-keys`
|
|
27297
|
+
);
|
|
27298
|
+
}
|
|
27299
|
+
return apiKey;
|
|
27300
|
+
}
|
|
27301
|
+
function parseDomainFilter15(domainFilter) {
|
|
27302
|
+
const filters = { include: [], exclude: [] };
|
|
27303
|
+
for (const raw of domainFilter ?? []) {
|
|
27304
|
+
const domain = normalizeDomain(raw);
|
|
27305
|
+
if (!domain) continue;
|
|
27306
|
+
const target = raw.trim().startsWith("-") ? filters.exclude : filters.include;
|
|
27307
|
+
if (!target.includes(domain)) target.push(domain);
|
|
27308
|
+
}
|
|
27309
|
+
return filters;
|
|
27310
|
+
}
|
|
27311
|
+
function passesDomainFilters15(url, filters) {
|
|
27312
|
+
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
27313
|
+
const hostname2 = url.hostname.toLowerCase();
|
|
27314
|
+
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
27315
|
+
if (filters.exclude.some(matches)) return false;
|
|
27316
|
+
return filters.include.length === 0 || filters.include.some(matches);
|
|
27317
|
+
}
|
|
27318
|
+
function buildQuery11(query, filters) {
|
|
27319
|
+
const parts = [query];
|
|
27320
|
+
if (filters.include.length === 1) parts.push(`site:${filters.include[0]}`);
|
|
27321
|
+
if (filters.include.length > 1) parts.push(`(${filters.include.map((domain) => `site:${domain}`).join(" OR ")})`);
|
|
27322
|
+
for (const domain of filters.exclude) parts.push(`-site:${domain}`);
|
|
27323
|
+
return parts.join(" ");
|
|
27324
|
+
}
|
|
27325
|
+
function isUnresolvedGoogleRedirect(url) {
|
|
27326
|
+
const hostname2 = url.hostname.toLowerCase();
|
|
27327
|
+
return url.pathname === "/goto" && (hostname2 === "google.com" || hostname2.endsWith(".google.com"));
|
|
27328
|
+
}
|
|
27329
|
+
function errorMessage30(err) {
|
|
27330
|
+
return err instanceof Error ? err.message : String(err);
|
|
27331
|
+
}
|
|
27332
|
+
function invalidResponse18(message) {
|
|
27333
|
+
return new Error(`cloro returned invalid response: ${message}`);
|
|
27334
|
+
}
|
|
27335
|
+
function parseResponse15(value, mode) {
|
|
27336
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalidResponse18("expected an object envelope");
|
|
27337
|
+
const envelope = value;
|
|
27338
|
+
const error = envelope.error;
|
|
27339
|
+
if (error && typeof error === "object" && typeof error.message === "string" && error.message.trim()) {
|
|
27340
|
+
throw invalidResponse18(error.message.trim());
|
|
27341
|
+
}
|
|
27342
|
+
const result = envelope.result;
|
|
27343
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) throw invalidResponse18("expected result object");
|
|
27344
|
+
const fields = result;
|
|
27345
|
+
if (mode === "google") {
|
|
27346
|
+
if (!Array.isArray(fields.organicResults)) throw invalidResponse18("expected result.organicResults array");
|
|
27347
|
+
return { entries: fields.organicResults };
|
|
27348
|
+
}
|
|
27349
|
+
const answer = typeof fields.markdown === "string" && fields.markdown.trim() ? fields.markdown : fields.text;
|
|
27350
|
+
if (typeof answer !== "string") throw invalidResponse18("expected result.markdown or result.text string");
|
|
27351
|
+
return { entries: Array.isArray(fields.sources) ? fields.sources : [], text: answer.trim() };
|
|
27352
|
+
}
|
|
27353
|
+
function isCloroAvailable() {
|
|
27354
|
+
return hasCredentialSource({ provider: "cloro", configuredValue: loadConfig42().cloroApiKey, environmentValue: process.env.CLORO_API_KEY });
|
|
27355
|
+
}
|
|
27356
|
+
async function searchWithCloro(query, options = {}) {
|
|
27357
|
+
const mode = getMode();
|
|
27358
|
+
const apiKey = await requireApiKey18(options.signal);
|
|
27359
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
27360
|
+
const filters = parseDomainFilter15(options.domainFilter);
|
|
27361
|
+
const endpoint = mode === "google" ? CLORO_GOOGLE_URL : mode === "aimode" ? CLORO_AIMODE_URL : CLORO_BING_AIMODE_URL;
|
|
27362
|
+
const body = mode === "google" ? { query: buildQuery11(query, filters), country: COUNTRY } : { prompt: query, country: COUNTRY, include: { markdown: true } };
|
|
27363
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
27364
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS37);
|
|
27365
|
+
let response;
|
|
27366
|
+
let parsed;
|
|
27367
|
+
try {
|
|
27368
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("cloro", endpoint, loadConfig42().cloroBaseUrl), {
|
|
27369
|
+
method: "POST",
|
|
27370
|
+
headers: {
|
|
27371
|
+
Accept: "application/json",
|
|
27372
|
+
Authorization: `Bearer ${apiKey}`,
|
|
27373
|
+
"Content-Type": "application/json",
|
|
27374
|
+
"User-Agent": "pi-web-access"
|
|
27375
|
+
},
|
|
27376
|
+
body: JSON.stringify(body),
|
|
27377
|
+
signal: options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal
|
|
27378
|
+
}, ["Authorization"]);
|
|
27379
|
+
if (!response.ok) {
|
|
27380
|
+
const errorText = await response.text();
|
|
27381
|
+
throw new Error(`cloro error ${response.status}: ${redactCredential(errorText, apiKey).slice(0, 300)}`);
|
|
27382
|
+
}
|
|
27383
|
+
let rawData;
|
|
27384
|
+
try {
|
|
27385
|
+
rawData = await response.json();
|
|
27386
|
+
} catch (err) {
|
|
27387
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
27388
|
+
throw new Error(`cloro returned invalid JSON: ${errorMessage30(err)}`);
|
|
27389
|
+
}
|
|
27390
|
+
parsed = parseResponse15(rawData, mode);
|
|
27391
|
+
} catch (err) {
|
|
27392
|
+
if (options.signal?.aborted) {
|
|
27393
|
+
activityMonitor.logComplete(activityId, 0);
|
|
27394
|
+
throw new Error("Aborted");
|
|
27395
|
+
}
|
|
27396
|
+
const message = errorMessage30(err);
|
|
27397
|
+
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
27398
|
+
const outgoing = providerTimeout ? new Error(`cloro request timed out after ${Math.round(SEARCH_TIMEOUT_MS37 / 1e3)}s`) : (() => {
|
|
27399
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
27400
|
+
if (redactedMessage === message && err instanceof Error) return err;
|
|
27401
|
+
const redactedError = new Error(redactedMessage);
|
|
27402
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
27403
|
+
return redactedError;
|
|
27404
|
+
})();
|
|
27405
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage30(outgoing), apiKey));
|
|
27406
|
+
throw outgoing;
|
|
27407
|
+
}
|
|
27408
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
27409
|
+
const results = [];
|
|
27410
|
+
for (const entry of parsed.entries) {
|
|
27411
|
+
if (!entry || typeof entry !== "object") continue;
|
|
27412
|
+
const link = mode === "google" ? entry.link : entry.url;
|
|
27413
|
+
if (typeof link !== "string" || !link) continue;
|
|
27414
|
+
let resultUrl;
|
|
27415
|
+
try {
|
|
27416
|
+
resultUrl = new URL(link);
|
|
27417
|
+
} catch {
|
|
27418
|
+
continue;
|
|
27419
|
+
}
|
|
27420
|
+
if (resultUrl.protocol !== "http:" && resultUrl.protocol !== "https:") continue;
|
|
27421
|
+
if (isUnresolvedGoogleRedirect(resultUrl)) continue;
|
|
27422
|
+
if (!passesDomainFilters15(resultUrl, filters)) continue;
|
|
27423
|
+
const title = mode === "google" ? entry.title : entry.label;
|
|
27424
|
+
const snippet = mode === "google" ? entry.snippet : entry.description;
|
|
27425
|
+
results.push({
|
|
27426
|
+
title: typeof title === "string" && title.trim() ? title.trim() : `Source ${results.length + 1}`,
|
|
27427
|
+
url: resultUrl.href,
|
|
27428
|
+
snippet: typeof snippet === "string" ? snippet : ""
|
|
27429
|
+
});
|
|
27430
|
+
if (results.length >= numResults) break;
|
|
27431
|
+
}
|
|
27432
|
+
const answer = parsed.text || formatSearchResultsAsAnswer(results);
|
|
27433
|
+
return { answer, results };
|
|
27434
|
+
}
|
|
27435
|
+
|
|
27436
|
+
// autom.ts
|
|
27437
|
+
init_activity();
|
|
27438
|
+
init_domain_filter_normalization();
|
|
27439
|
+
init_search_answer_formatting();
|
|
27440
|
+
init_search_result_count_normalization();
|
|
27441
|
+
init_credential_source();
|
|
27442
|
+
init_utils();
|
|
27443
|
+
import { existsSync as existsSync48, readFileSync as readFileSync49 } from "node:fs";
|
|
27444
|
+
var AUTOM_GOOGLE_URL = "https://api.autom.dev/v1/google/search";
|
|
27445
|
+
var CONFIG_PATH45 = getWebSearchConfigPath();
|
|
27446
|
+
var SEARCH_TIMEOUT_MS38 = 6e4;
|
|
27447
|
+
var RECENCY_TBS6 = {
|
|
27448
|
+
day: "qdr:d",
|
|
27449
|
+
week: "qdr:w",
|
|
27450
|
+
month: "qdr:m",
|
|
27451
|
+
year: "qdr:y"
|
|
27452
|
+
};
|
|
27453
|
+
var cachedConfig41 = null;
|
|
27454
|
+
function loadConfig43() {
|
|
27455
|
+
if (cachedConfig41) return cachedConfig41;
|
|
27456
|
+
if (!existsSync48(CONFIG_PATH45)) {
|
|
27457
|
+
cachedConfig41 = {};
|
|
27458
|
+
return cachedConfig41;
|
|
27459
|
+
}
|
|
27460
|
+
const raw = readFileSync49(CONFIG_PATH45, "utf-8");
|
|
27461
|
+
let parsed;
|
|
27462
|
+
try {
|
|
27463
|
+
parsed = JSON.parse(raw);
|
|
27464
|
+
} catch (err) {
|
|
27465
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
27466
|
+
throw new Error(`Failed to parse ${CONFIG_PATH45}: ${message}`);
|
|
27467
|
+
}
|
|
27468
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
27469
|
+
throw new Error(`Invalid config in ${CONFIG_PATH45}: expected a JSON object`);
|
|
27470
|
+
}
|
|
27471
|
+
cachedConfig41 = parsed;
|
|
27472
|
+
return cachedConfig41;
|
|
27473
|
+
}
|
|
27474
|
+
async function getApiKey31(signal) {
|
|
27475
|
+
return resolveCredential({
|
|
27476
|
+
provider: "Autom",
|
|
27477
|
+
configuredValue: loadConfig43().automApiKey,
|
|
27478
|
+
environmentValue: process.env.AUTOM_API_KEY,
|
|
27479
|
+
signal
|
|
27480
|
+
});
|
|
27481
|
+
}
|
|
27482
|
+
async function requireApiKey19(signal) {
|
|
27483
|
+
const apiKey = await getApiKey31(signal);
|
|
27484
|
+
if (!apiKey) {
|
|
27485
|
+
throw new Error(
|
|
27486
|
+
`Autom API key not found. Either:
|
|
27487
|
+
1. Create ${CONFIG_PATH45} with { "automApiKey": "your-key" }
|
|
27488
|
+
2. Set AUTOM_API_KEY environment variable
|
|
27489
|
+
Get a key at https://app.autom.dev`
|
|
27490
|
+
);
|
|
27491
|
+
}
|
|
27492
|
+
return apiKey;
|
|
27493
|
+
}
|
|
27494
|
+
function parseDomainFilter16(domainFilter) {
|
|
27495
|
+
const filters = { include: [], exclude: [] };
|
|
27496
|
+
for (const raw of domainFilter ?? []) {
|
|
27497
|
+
const domain = normalizeDomain(raw);
|
|
27498
|
+
if (!domain) continue;
|
|
27499
|
+
const target = raw.trim().startsWith("-") ? filters.exclude : filters.include;
|
|
27500
|
+
if (!target.includes(domain)) target.push(domain);
|
|
27501
|
+
}
|
|
27502
|
+
return filters;
|
|
27503
|
+
}
|
|
27504
|
+
function passesDomainFilters16(url, filters) {
|
|
27505
|
+
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
27506
|
+
let hostname2;
|
|
27507
|
+
try {
|
|
27508
|
+
hostname2 = new URL(url).hostname.toLowerCase();
|
|
27509
|
+
} catch {
|
|
27510
|
+
return false;
|
|
27511
|
+
}
|
|
27512
|
+
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
27513
|
+
if (filters.exclude.some(matches)) return false;
|
|
27514
|
+
return filters.include.length === 0 || filters.include.some(matches);
|
|
27515
|
+
}
|
|
27516
|
+
function buildQuery12(query, filters) {
|
|
27517
|
+
const parts = [query];
|
|
27518
|
+
if (filters.include.length === 1) parts.push(`site:${filters.include[0]}`);
|
|
27519
|
+
if (filters.include.length > 1) parts.push(`(${filters.include.map((domain) => `site:${domain}`).join(" OR ")})`);
|
|
27520
|
+
for (const domain of filters.exclude) parts.push(`-site:${domain}`);
|
|
27521
|
+
return parts.join(" ");
|
|
27522
|
+
}
|
|
27523
|
+
function errorMessage31(err) {
|
|
27524
|
+
return err instanceof Error ? err.message : String(err);
|
|
27525
|
+
}
|
|
27526
|
+
function invalidResponse19(message) {
|
|
27527
|
+
return new Error(`Autom API returned invalid response: ${message}`);
|
|
27528
|
+
}
|
|
27529
|
+
function parseResponse16(value) {
|
|
27530
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalidResponse19("expected an object envelope");
|
|
27531
|
+
const envelope = value;
|
|
27532
|
+
if (envelope.organic_results === void 0) return [];
|
|
27533
|
+
if (!Array.isArray(envelope.organic_results)) throw invalidResponse19("expected organic_results array");
|
|
27534
|
+
return envelope.organic_results;
|
|
27535
|
+
}
|
|
27536
|
+
function isAutomAvailable() {
|
|
27537
|
+
return hasCredentialSource({ provider: "Autom", configuredValue: loadConfig43().automApiKey, environmentValue: process.env.AUTOM_API_KEY });
|
|
27538
|
+
}
|
|
27539
|
+
async function searchWithAutom(query, options = {}) {
|
|
27540
|
+
const apiUrl = new URL(resolveProviderApiUrl("autom", AUTOM_GOOGLE_URL, loadConfig43().automBaseUrl));
|
|
27541
|
+
const apiKey = await requireApiKey19(options.signal);
|
|
27542
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
27543
|
+
const filters = parseDomainFilter16(options.domainFilter);
|
|
27544
|
+
apiUrl.searchParams.set("query", buildQuery12(query, filters));
|
|
27545
|
+
if (options.recencyFilter) apiUrl.searchParams.set("tbs", RECENCY_TBS6[options.recencyFilter]);
|
|
27546
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
27547
|
+
let response;
|
|
27548
|
+
try {
|
|
27549
|
+
response = await fetchWithCredentialRedirects(apiUrl.toString(), {
|
|
27550
|
+
method: "GET",
|
|
27551
|
+
headers: { "x-api-key": apiKey, Accept: "application/json" },
|
|
27552
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS38), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS38)
|
|
27553
|
+
}, ["x-api-key"]);
|
|
27554
|
+
} catch (err) {
|
|
27555
|
+
const message = errorMessage31(err);
|
|
27556
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
27557
|
+
if (redactedMessage.toLowerCase().includes("abort")) activityMonitor.logComplete(activityId, 0);
|
|
27558
|
+
else activityMonitor.logError(activityId, redactedMessage);
|
|
27559
|
+
if (redactedMessage === message) throw err;
|
|
27560
|
+
const redactedError = new Error(redactedMessage);
|
|
27561
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
27562
|
+
throw redactedError;
|
|
27563
|
+
}
|
|
27564
|
+
if (!response.ok) {
|
|
27565
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
27566
|
+
const errorText = redactCredential(await response.text(), apiKey);
|
|
27567
|
+
throw new Error(`Autom API error ${response.status}: ${errorText.slice(0, 300)}`);
|
|
27568
|
+
}
|
|
27569
|
+
let rawData;
|
|
27570
|
+
try {
|
|
27571
|
+
rawData = await response.json();
|
|
27572
|
+
} catch (err) {
|
|
27573
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
27574
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
27575
|
+
throw new Error(`Autom API returned invalid JSON: ${redactCredential(errorMessage31(err), apiKey)}`);
|
|
27576
|
+
}
|
|
27577
|
+
let entries;
|
|
27578
|
+
try {
|
|
27579
|
+
entries = parseResponse16(rawData);
|
|
27580
|
+
} catch (err) {
|
|
27581
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
27582
|
+
throw err;
|
|
27583
|
+
}
|
|
27584
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
27585
|
+
const results = [];
|
|
27586
|
+
for (const entry of entries) {
|
|
27587
|
+
if (!entry || typeof entry !== "object") continue;
|
|
27588
|
+
if (typeof entry.link !== "string" || !/^https?:\/\//i.test(entry.link)) continue;
|
|
27589
|
+
if (!passesDomainFilters16(entry.link, filters)) continue;
|
|
27590
|
+
results.push({
|
|
27591
|
+
title: typeof entry.title === "string" && entry.title.trim() ? entry.title.trim() : `Source ${results.length + 1}`,
|
|
27592
|
+
url: entry.link,
|
|
27593
|
+
snippet: typeof entry.snippet === "string" ? entry.snippet : ""
|
|
27594
|
+
});
|
|
27595
|
+
if (results.length >= numResults) break;
|
|
27596
|
+
}
|
|
27597
|
+
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
27598
|
+
}
|
|
27599
|
+
|
|
26845
27600
|
// gemini-search.ts
|
|
27601
|
+
init_specstream();
|
|
26846
27602
|
init_deepseek();
|
|
26847
27603
|
|
|
26848
27604
|
// kimi-search.ts
|
|
@@ -26854,7 +27610,7 @@ init_search_result_count_normalization();
|
|
|
26854
27610
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
26855
27611
|
var KIMI_SEARCH_URL = "https://api.kimi.com/coding/v1/search";
|
|
26856
27612
|
var KIMI_PROVIDERS = ["kimi-coding", "kimi-code"];
|
|
26857
|
-
var
|
|
27613
|
+
var SEARCH_TIMEOUT_MS41 = 3e4;
|
|
26858
27614
|
function buildRequestHeaders(auth) {
|
|
26859
27615
|
const headers = new Headers();
|
|
26860
27616
|
for (const [name, value] of Object.entries(auth.headers)) {
|
|
@@ -26969,7 +27725,7 @@ async function searchWithKimi(query, options = {}, ctx) {
|
|
|
26969
27725
|
throw new Error("Kimi Code web search unavailable. Run /login kimi-coding to authenticate a Kimi Code Plan account.");
|
|
26970
27726
|
}
|
|
26971
27727
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
26972
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
27728
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS41);
|
|
26973
27729
|
const requestSignal16 = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal;
|
|
26974
27730
|
try {
|
|
26975
27731
|
const response = await fetch(KIMI_SEARCH_URL, {
|
|
@@ -27021,45 +27777,45 @@ init_activity();
|
|
|
27021
27777
|
init_domain_filter_normalization();
|
|
27022
27778
|
init_credential_source();
|
|
27023
27779
|
init_utils();
|
|
27024
|
-
import { existsSync as
|
|
27780
|
+
import { existsSync as existsSync51, readFileSync as readFileSync52 } from "node:fs";
|
|
27025
27781
|
var MISTRAL_CONVERSATIONS_URL = "https://api.mistral.ai/v1/conversations";
|
|
27026
|
-
var
|
|
27027
|
-
var
|
|
27782
|
+
var CONFIG_PATH48 = getWebSearchConfigPath();
|
|
27783
|
+
var SEARCH_TIMEOUT_MS42 = 6e4;
|
|
27028
27784
|
var DEFAULT_SEARCH_MODEL = "mistral-small-latest";
|
|
27029
27785
|
var DEFAULT_SEARCH_TOOL = "web_search";
|
|
27030
27786
|
var MAX_RESULTS2 = 20;
|
|
27031
|
-
var
|
|
27032
|
-
function
|
|
27033
|
-
if (
|
|
27034
|
-
if (!
|
|
27035
|
-
|
|
27036
|
-
return
|
|
27787
|
+
var cachedConfig44 = null;
|
|
27788
|
+
function loadConfig46() {
|
|
27789
|
+
if (cachedConfig44) return cachedConfig44;
|
|
27790
|
+
if (!existsSync51(CONFIG_PATH48)) {
|
|
27791
|
+
cachedConfig44 = {};
|
|
27792
|
+
return cachedConfig44;
|
|
27037
27793
|
}
|
|
27038
|
-
const raw =
|
|
27794
|
+
const raw = readFileSync52(CONFIG_PATH48, "utf-8");
|
|
27039
27795
|
let parsed;
|
|
27040
27796
|
try {
|
|
27041
27797
|
parsed = JSON.parse(raw);
|
|
27042
27798
|
} catch (err) {
|
|
27043
27799
|
const message = err instanceof Error ? err.message : String(err);
|
|
27044
|
-
throw new Error(`Failed to parse ${
|
|
27800
|
+
throw new Error(`Failed to parse ${CONFIG_PATH48}: ${message}`);
|
|
27045
27801
|
}
|
|
27046
27802
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
27047
|
-
throw new Error(`Invalid config in ${
|
|
27803
|
+
throw new Error(`Invalid config in ${CONFIG_PATH48}: expected a JSON object`);
|
|
27048
27804
|
}
|
|
27049
|
-
|
|
27050
|
-
return
|
|
27805
|
+
cachedConfig44 = parsed;
|
|
27806
|
+
return cachedConfig44;
|
|
27051
27807
|
}
|
|
27052
27808
|
function resolveSearchModel(value) {
|
|
27053
27809
|
if (value === void 0) return DEFAULT_SEARCH_MODEL;
|
|
27054
27810
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
27055
|
-
throw new Error(`mistralSearchModel in ${
|
|
27811
|
+
throw new Error(`mistralSearchModel in ${CONFIG_PATH48} must be a non-empty string`);
|
|
27056
27812
|
}
|
|
27057
27813
|
return value.trim();
|
|
27058
27814
|
}
|
|
27059
27815
|
function resolveSearchTool(value) {
|
|
27060
27816
|
if (value === void 0) return DEFAULT_SEARCH_TOOL;
|
|
27061
27817
|
if (value !== "web_search" && value !== "web_search_premium") {
|
|
27062
|
-
throw new Error(`mistralSearchTool in ${
|
|
27818
|
+
throw new Error(`mistralSearchTool in ${CONFIG_PATH48} must be either web_search or web_search_premium`);
|
|
27063
27819
|
}
|
|
27064
27820
|
return value;
|
|
27065
27821
|
}
|
|
@@ -27077,7 +27833,7 @@ function parseDomainFilters(domainFilter) {
|
|
|
27077
27833
|
}
|
|
27078
27834
|
return filters;
|
|
27079
27835
|
}
|
|
27080
|
-
function
|
|
27836
|
+
function passesDomainFilters18(url, filters) {
|
|
27081
27837
|
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
27082
27838
|
const hostname2 = new URL(url).hostname.toLowerCase();
|
|
27083
27839
|
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
@@ -27117,18 +27873,18 @@ function buildSearchPrompt(query, options, numResults) {
|
|
|
27117
27873
|
|
|
27118
27874
|
${query}` : query;
|
|
27119
27875
|
}
|
|
27120
|
-
function
|
|
27876
|
+
function errorMessage34(err) {
|
|
27121
27877
|
return err instanceof Error ? err.message : String(err);
|
|
27122
27878
|
}
|
|
27123
|
-
function
|
|
27879
|
+
function invalidResponse21(message) {
|
|
27124
27880
|
return new Error(`Mistral API returned invalid response: ${message}`);
|
|
27125
27881
|
}
|
|
27126
27882
|
function parseConversationResponse(value, options, numResults) {
|
|
27127
27883
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
27128
|
-
throw
|
|
27884
|
+
throw invalidResponse21("expected an object envelope");
|
|
27129
27885
|
}
|
|
27130
27886
|
const outputs = value.outputs;
|
|
27131
|
-
if (!Array.isArray(outputs)) throw
|
|
27887
|
+
if (!Array.isArray(outputs)) throw invalidResponse21("outputs must be an array");
|
|
27132
27888
|
const answerParts = [];
|
|
27133
27889
|
const results = [];
|
|
27134
27890
|
const seenUrls = /* @__PURE__ */ new Set();
|
|
@@ -27152,7 +27908,7 @@ function parseConversationResponse(value, options, numResults) {
|
|
|
27152
27908
|
}
|
|
27153
27909
|
if (part.type !== "tool_reference" || results.length >= numResults) continue;
|
|
27154
27910
|
const url = normalizeResultUrl2(part.url);
|
|
27155
|
-
if (!url || !
|
|
27911
|
+
if (!url || !passesDomainFilters18(url, domainFilters2) || seenUrls.has(url)) continue;
|
|
27156
27912
|
seenUrls.add(url);
|
|
27157
27913
|
const title = typeof part.title === "string" && part.title.trim() ? part.title.trim() : url;
|
|
27158
27914
|
const snippet = typeof part.description === "string" ? part.description : "";
|
|
@@ -27160,20 +27916,20 @@ function parseConversationResponse(value, options, numResults) {
|
|
|
27160
27916
|
}
|
|
27161
27917
|
}
|
|
27162
27918
|
const answer = answerParts.join("\n").trim();
|
|
27163
|
-
if (!answer && results.length === 0) throw
|
|
27919
|
+
if (!answer && results.length === 0) throw invalidResponse21("no answer or sources");
|
|
27164
27920
|
return { answer, results };
|
|
27165
27921
|
}
|
|
27166
|
-
async function
|
|
27922
|
+
async function getApiKey33(signal) {
|
|
27167
27923
|
const apiKey = await resolveCredential({
|
|
27168
27924
|
provider: "Mistral",
|
|
27169
|
-
configuredValue:
|
|
27925
|
+
configuredValue: loadConfig46().mistralApiKey,
|
|
27170
27926
|
environmentValue: process.env.MISTRAL_API_KEY,
|
|
27171
27927
|
signal
|
|
27172
27928
|
});
|
|
27173
27929
|
if (!apiKey) {
|
|
27174
27930
|
throw new Error(
|
|
27175
27931
|
`Mistral API key not found. Either:
|
|
27176
|
-
1. Create ${
|
|
27932
|
+
1. Create ${CONFIG_PATH48} with { "mistralApiKey": "your-key" }
|
|
27177
27933
|
2. Set MISTRAL_API_KEY environment variable
|
|
27178
27934
|
Get a key at https://console.mistral.ai/api-keys`
|
|
27179
27935
|
);
|
|
@@ -27182,7 +27938,7 @@ Get a key at https://console.mistral.ai/api-keys`
|
|
|
27182
27938
|
}
|
|
27183
27939
|
function isMistralAvailable() {
|
|
27184
27940
|
try {
|
|
27185
|
-
const config =
|
|
27941
|
+
const config = loadConfig46();
|
|
27186
27942
|
resolveSearchModel(config.mistralSearchModel);
|
|
27187
27943
|
resolveSearchTool(config.mistralSearchTool);
|
|
27188
27944
|
return hasCredentialSource({
|
|
@@ -27195,15 +27951,15 @@ function isMistralAvailable() {
|
|
|
27195
27951
|
}
|
|
27196
27952
|
}
|
|
27197
27953
|
async function searchWithMistral(query, options = {}) {
|
|
27198
|
-
const config =
|
|
27954
|
+
const config = loadConfig46();
|
|
27199
27955
|
const model = options.model ?? resolveSearchModel(config.mistralSearchModel);
|
|
27200
27956
|
const tool = resolveSearchTool(config.mistralSearchTool);
|
|
27201
27957
|
const numResults = normalizeCount4(options.numResults);
|
|
27202
|
-
const apiKey = await
|
|
27203
|
-
const requestSignal16 = options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
27958
|
+
const apiKey = await getApiKey33(options.signal);
|
|
27959
|
+
const requestSignal16 = options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS42), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS42);
|
|
27204
27960
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
27205
27961
|
try {
|
|
27206
|
-
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("mistralSearch", MISTRAL_CONVERSATIONS_URL,
|
|
27962
|
+
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("mistralSearch", MISTRAL_CONVERSATIONS_URL, loadConfig46().mistralSearchBaseUrl), {
|
|
27207
27963
|
method: "POST",
|
|
27208
27964
|
headers: {
|
|
27209
27965
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -27225,13 +27981,13 @@ async function searchWithMistral(query, options = {}) {
|
|
|
27225
27981
|
try {
|
|
27226
27982
|
parsed = await response.json();
|
|
27227
27983
|
} catch (err) {
|
|
27228
|
-
throw new Error(`Mistral API returned invalid JSON: ${
|
|
27984
|
+
throw new Error(`Mistral API returned invalid JSON: ${errorMessage34(err)}`);
|
|
27229
27985
|
}
|
|
27230
27986
|
const result = parseConversationResponse(parsed, options, numResults);
|
|
27231
27987
|
activityMonitor.logComplete(activityId, response.status);
|
|
27232
27988
|
return result;
|
|
27233
27989
|
} catch (err) {
|
|
27234
|
-
const message =
|
|
27990
|
+
const message = errorMessage34(err);
|
|
27235
27991
|
const redactedMessage = redactCredential(message, apiKey);
|
|
27236
27992
|
if (redactedMessage.toLowerCase().includes("abort")) {
|
|
27237
27993
|
activityMonitor.logComplete(activityId, 0);
|
|
@@ -27247,7 +28003,7 @@ async function searchWithMistral(query, options = {}) {
|
|
|
27247
28003
|
|
|
27248
28004
|
// gemini-search.ts
|
|
27249
28005
|
init_utils();
|
|
27250
|
-
var RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek", "linkup", "ninerouter", "cloudflare", "searchapi", "outcrawl", "sofya", "tabstack"];
|
|
28006
|
+
var RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek", "linkup", "ninerouter", "cloudflare", "searchapi", "outcrawl", "sofya", "cloro", "autom", "specstream", "tabstack"];
|
|
27251
28007
|
var SEARCH_PROVIDERS = ["auto", "all", ...RESOLVED_SEARCH_PROVIDERS];
|
|
27252
28008
|
var SearchProviderError = class extends Error {
|
|
27253
28009
|
provider;
|
|
@@ -27263,7 +28019,7 @@ var SearchProviderError = class extends Error {
|
|
|
27263
28019
|
this.causeError = cause;
|
|
27264
28020
|
}
|
|
27265
28021
|
};
|
|
27266
|
-
var
|
|
28022
|
+
var CONFIG_PATH49 = getWebSearchConfigPath();
|
|
27267
28023
|
var DEFAULT_SEARCH_MODEL2 = "gemini-3.6-flash";
|
|
27268
28024
|
var ALL_SEARCH_PROVIDERS = ["searxng", "openai", "exa", "brave", "parallel", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "ollama", "perplexity", "gemini", "bocha"];
|
|
27269
28025
|
var VALID_ROUTING_KINDS = ["transient", "quota", "network", "invalid-response", "unsupported", "empty", "domain-miss", "off-topic"];
|
|
@@ -27271,11 +28027,11 @@ var MAX_ROUTING_TIMEOUT_MS = 6e5;
|
|
|
27271
28027
|
var cachedSearchConfig = null;
|
|
27272
28028
|
function getSearchConfig() {
|
|
27273
28029
|
if (cachedSearchConfig) return cachedSearchConfig;
|
|
27274
|
-
if (!
|
|
28030
|
+
if (!existsSync52(CONFIG_PATH49)) {
|
|
27275
28031
|
cachedSearchConfig = { searchProvider: "auto", searchProviderConfigured: false };
|
|
27276
28032
|
return cachedSearchConfig;
|
|
27277
28033
|
}
|
|
27278
|
-
const rawText =
|
|
28034
|
+
const rawText = readFileSync53(CONFIG_PATH49, "utf-8");
|
|
27279
28035
|
let raw;
|
|
27280
28036
|
try {
|
|
27281
28037
|
const parsed = JSON.parse(rawText);
|
|
@@ -27285,25 +28041,25 @@ function getSearchConfig() {
|
|
|
27285
28041
|
raw = parsed;
|
|
27286
28042
|
} catch (err) {
|
|
27287
28043
|
const message = err instanceof Error ? err.message : String(err);
|
|
27288
|
-
throw new Error(`Failed to parse ${
|
|
28044
|
+
throw new Error(`Failed to parse ${CONFIG_PATH49}: ${message}`);
|
|
27289
28045
|
}
|
|
27290
28046
|
const searchModel = normalizeSearchModel(raw.searchModel);
|
|
27291
28047
|
const webSearch = raw.webSearch;
|
|
27292
28048
|
if (webSearch !== void 0 && (!webSearch || typeof webSearch !== "object" || Array.isArray(webSearch))) {
|
|
27293
|
-
throw new Error(`webSearch in ${
|
|
28049
|
+
throw new Error(`webSearch in ${CONFIG_PATH49} must be an object`);
|
|
27294
28050
|
}
|
|
27295
|
-
const allowedProviders = webSearch && Object.hasOwn(webSearch, "allowedProviders") ? normalizeResolvedProviderList(webSearch.allowedProviders, `webSearch.allowedProviders in ${
|
|
28051
|
+
const allowedProviders = webSearch && Object.hasOwn(webSearch, "allowedProviders") ? normalizeResolvedProviderList(webSearch.allowedProviders, `webSearch.allowedProviders in ${CONFIG_PATH49}`) : void 0;
|
|
27296
28052
|
const searchProviderConfigured = Object.hasOwn(raw, "searchProvider") || Object.hasOwn(raw, "provider");
|
|
27297
|
-
const searchProvider2 = normalizeSearchProviderSelection(raw.searchProvider ?? raw.provider, `provider in ${
|
|
28053
|
+
const searchProvider2 = normalizeSearchProviderSelection(raw.searchProvider ?? raw.provider, `provider in ${CONFIG_PATH49}`);
|
|
27298
28054
|
const searchRouting = Object.hasOwn(raw, "searchRouting") ? normalizeSearchRouting(raw.searchRouting) : void 0;
|
|
27299
28055
|
if (allowedProviders) {
|
|
27300
28056
|
if (Object.hasOwn(raw, "searchProvider")) {
|
|
27301
|
-
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.searchProvider), `searchProvider in ${
|
|
28057
|
+
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.searchProvider), `searchProvider in ${CONFIG_PATH49}`, allowedProviders);
|
|
27302
28058
|
}
|
|
27303
28059
|
if (Object.hasOwn(raw, "provider")) {
|
|
27304
|
-
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.provider), `provider in ${
|
|
28060
|
+
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.provider), `provider in ${CONFIG_PATH49}`, allowedProviders);
|
|
27305
28061
|
}
|
|
27306
|
-
if (searchRouting) assertSearchProviderSelectionAllowed(searchRouting.providers, `searchRouting.providers in ${
|
|
28062
|
+
if (searchRouting) assertSearchProviderSelectionAllowed(searchRouting.providers, `searchRouting.providers in ${CONFIG_PATH49}`, allowedProviders);
|
|
27307
28063
|
}
|
|
27308
28064
|
cachedSearchConfig = {
|
|
27309
28065
|
searchProvider: searchProvider2,
|
|
@@ -27316,21 +28072,21 @@ function getSearchConfig() {
|
|
|
27316
28072
|
}
|
|
27317
28073
|
function normalizeSearchRouting(value) {
|
|
27318
28074
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
27319
|
-
throw new Error(`searchRouting in ${
|
|
28075
|
+
throw new Error(`searchRouting in ${CONFIG_PATH49} must be an object`);
|
|
27320
28076
|
}
|
|
27321
28077
|
const raw = value;
|
|
27322
|
-
const providers = normalizeResolvedProviderList(raw.providers, `searchRouting.providers in ${
|
|
28078
|
+
const providers = normalizeResolvedProviderList(raw.providers, `searchRouting.providers in ${CONFIG_PATH49}`);
|
|
27323
28079
|
const useCurrentModel = raw.useCurrentModel;
|
|
27324
28080
|
if (useCurrentModel !== void 0 && typeof useCurrentModel !== "boolean") {
|
|
27325
|
-
throw new Error(`searchRouting.useCurrentModel in ${
|
|
28081
|
+
throw new Error(`searchRouting.useCurrentModel in ${CONFIG_PATH49} must be a boolean`);
|
|
27326
28082
|
}
|
|
27327
28083
|
if (!Array.isArray(raw.fallbackOn) || raw.fallbackOn.length === 0) {
|
|
27328
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
28084
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH49} must be a non-empty array`);
|
|
27329
28085
|
}
|
|
27330
28086
|
const fallbackOn = [];
|
|
27331
28087
|
for (const kind of raw.fallbackOn) {
|
|
27332
28088
|
if (typeof kind !== "string" || !VALID_ROUTING_KINDS.includes(kind)) {
|
|
27333
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
28089
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH49} may only contain transient, quota, network, invalid-response, unsupported, empty, domain-miss, or off-topic`);
|
|
27334
28090
|
}
|
|
27335
28091
|
if (!fallbackOn.includes(kind)) {
|
|
27336
28092
|
fallbackOn.push(kind);
|
|
@@ -27338,14 +28094,14 @@ function normalizeSearchRouting(value) {
|
|
|
27338
28094
|
}
|
|
27339
28095
|
const timeoutMs = raw.timeoutMs;
|
|
27340
28096
|
if (timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > MAX_ROUTING_TIMEOUT_MS)) {
|
|
27341
|
-
throw new Error(`searchRouting.timeoutMs in ${
|
|
28097
|
+
throw new Error(`searchRouting.timeoutMs in ${CONFIG_PATH49} must be an integer from 1 through ${MAX_ROUTING_TIMEOUT_MS}`);
|
|
27342
28098
|
}
|
|
27343
28099
|
const offTopicModel = raw.offTopicModel;
|
|
27344
28100
|
if (offTopicModel !== void 0 && (typeof offTopicModel !== "string" || !Object.hasOwn(OFFTOPIC_JUDGE_MODELS, offTopicModel))) {
|
|
27345
|
-
throw new Error(`searchRouting.offTopicModel in ${
|
|
28101
|
+
throw new Error(`searchRouting.offTopicModel in ${CONFIG_PATH49} must be one of ${Object.keys(OFFTOPIC_JUDGE_MODELS).join(", ")}`);
|
|
27346
28102
|
}
|
|
27347
28103
|
if (fallbackOn.includes("off-topic") && offTopicModel === void 0) {
|
|
27348
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
28104
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH49} lists off-topic, which needs searchRouting.offTopicModel`);
|
|
27349
28105
|
}
|
|
27350
28106
|
return {
|
|
27351
28107
|
providers,
|
|
@@ -27438,11 +28194,12 @@ function validateSearchModelOverride(provider, model) {
|
|
|
27438
28194
|
assertSearchProviderSelectionAllowed(selected, "Requested provider");
|
|
27439
28195
|
return model.trim();
|
|
27440
28196
|
}
|
|
27441
|
-
function
|
|
28197
|
+
function errorMessage35(err) {
|
|
27442
28198
|
return err instanceof Error ? err.message : String(err);
|
|
27443
28199
|
}
|
|
27444
28200
|
function isAbortError2(err) {
|
|
27445
|
-
|
|
28201
|
+
const message = errorMessage35(err).toLowerCase();
|
|
28202
|
+
return message.includes("abort") && !message.includes("aborted due to timeout");
|
|
27446
28203
|
}
|
|
27447
28204
|
async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
27448
28205
|
try {
|
|
@@ -27452,7 +28209,7 @@ async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
|
27452
28209
|
}
|
|
27453
28210
|
} catch (err) {
|
|
27454
28211
|
if (isAbortError2(err)) throw err;
|
|
27455
|
-
fallbackErrors.push(`OpenAI: ${
|
|
28212
|
+
fallbackErrors.push(`OpenAI: ${errorMessage35(err)}`);
|
|
27456
28213
|
}
|
|
27457
28214
|
return null;
|
|
27458
28215
|
}
|
|
@@ -27468,7 +28225,7 @@ async function searchWithGemini(query, options, strictErrors) {
|
|
|
27468
28225
|
if (apiResult) return apiResult;
|
|
27469
28226
|
} catch (err) {
|
|
27470
28227
|
if (err instanceof CredentialResolutionError || isAbortError2(err)) throw err;
|
|
27471
|
-
errors.push(`Gemini API: ${
|
|
28228
|
+
errors.push(`Gemini API: ${errorMessage35(err)}`);
|
|
27472
28229
|
}
|
|
27473
28230
|
try {
|
|
27474
28231
|
const webResult = await searchWithGeminiWeb(query, options);
|
|
@@ -27477,7 +28234,7 @@ async function searchWithGemini(query, options, strictErrors) {
|
|
|
27477
28234
|
if (diagnostic) errors.push(`Gemini Web: ${diagnostic}`);
|
|
27478
28235
|
} catch (err) {
|
|
27479
28236
|
if (isAbortError2(err)) throw err;
|
|
27480
|
-
errors.push(`Gemini Web: ${
|
|
28237
|
+
errors.push(`Gemini Web: ${errorMessage35(err)}`);
|
|
27481
28238
|
}
|
|
27482
28239
|
if (strictErrors && errors.length > 0) {
|
|
27483
28240
|
throw new Error(`Gemini search failed:
|
|
@@ -27492,7 +28249,7 @@ function providerErrorStatus(message) {
|
|
|
27492
28249
|
}
|
|
27493
28250
|
function classifyProviderError(provider, err) {
|
|
27494
28251
|
if (err instanceof SearchProviderError) return err;
|
|
27495
|
-
const message =
|
|
28252
|
+
const message = errorMessage35(err);
|
|
27496
28253
|
const lower = message.toLowerCase();
|
|
27497
28254
|
const status = providerErrorStatus(message);
|
|
27498
28255
|
const openAIStreamError = provider === "openai" && lower.includes("openai api stream error");
|
|
@@ -27503,6 +28260,8 @@ function classifyProviderError(provider, err) {
|
|
|
27503
28260
|
kind = "credential";
|
|
27504
28261
|
} else if (isAbortError2(err)) {
|
|
27505
28262
|
kind = "aborted";
|
|
28263
|
+
} else if (lower.includes("aborted due to timeout")) {
|
|
28264
|
+
kind = "network";
|
|
27506
28265
|
} else if (err instanceof OpenAIAlphaSearchUnsupportedError) {
|
|
27507
28266
|
kind = "unsupported";
|
|
27508
28267
|
} else if (provider === "xai" && status === 403 && /spending[- ]limit|(?:no|out of) credits?|insufficient quota|quota (?:exceeded|exhausted)|credits? (?:exhausted|depleted|used up)/.test(lower)) {
|
|
@@ -27576,6 +28335,9 @@ async function searchWithResolvedProvider(provider, query, options, useCurrentMo
|
|
|
27576
28335
|
if (provider === "searchapi") return { ...await searchWithSearchApi(query, options), provider };
|
|
27577
28336
|
if (provider === "outcrawl") return { ...await searchWithOutcrawl(query, options), provider };
|
|
27578
28337
|
if (provider === "sofya") return { ...await searchWithSofya(query, options), provider };
|
|
28338
|
+
if (provider === "cloro") return { ...await searchWithCloro(query, options), provider };
|
|
28339
|
+
if (provider === "autom") return { ...await searchWithAutom(query, options), provider };
|
|
28340
|
+
if (provider === "specstream") return { ...await searchWithSpecStream(query, options), provider };
|
|
27579
28341
|
if (provider === "deepseek") return { ...await searchWithDeepSeek(query, options), provider };
|
|
27580
28342
|
if (provider === "xcrawl") return { ...await searchWithXCrawl(query, options), provider };
|
|
27581
28343
|
if (provider === "perplexity") return { ...await searchWithPerplexity(query, options), provider };
|
|
@@ -27588,7 +28350,7 @@ async function searchWithResolvedProvider(provider, query, options, useCurrentMo
|
|
|
27588
28350
|
if (result) return { ...result, provider };
|
|
27589
28351
|
throw new Error(
|
|
27590
28352
|
`Gemini search unavailable. Either:
|
|
27591
|
-
1. Configure geminiApiKey in ${
|
|
28353
|
+
1. Configure geminiApiKey in ${CONFIG_PATH49} or set GEMINI_API_KEY
|
|
27592
28354
|
2. Set GOOGLE_GEMINI_BASE_URL + CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing
|
|
27593
28355
|
3. Set geminiAuth to "adc" in web-search.json with a Google Cloud ADC + project/location
|
|
27594
28356
|
4. Sign into gemini.google.com in a supported Chromium-based browser`
|
|
@@ -27635,6 +28397,9 @@ async function isResolvedProviderAvailable(provider, options, useCurrentModel =
|
|
|
27635
28397
|
if (provider === "searchapi") return isSearchApiAvailable();
|
|
27636
28398
|
if (provider === "outcrawl") return isOutcrawlAvailable();
|
|
27637
28399
|
if (provider === "sofya") return isSofyaAvailable();
|
|
28400
|
+
if (provider === "cloro") return isCloroAvailable();
|
|
28401
|
+
if (provider === "autom") return isAutomAvailable();
|
|
28402
|
+
if (provider === "specstream") return isSpecStreamAvailable();
|
|
27638
28403
|
if (provider === "deepseek") return isDeepSeekAvailable();
|
|
27639
28404
|
if (provider === "xcrawl") return isXcrawlAvailable();
|
|
27640
28405
|
if (provider === "perplexity") return isPerplexityAvailable();
|
|
@@ -27689,6 +28454,9 @@ function providerLabel(provider) {
|
|
|
27689
28454
|
if (provider === "searchapi") return "SearchApi";
|
|
27690
28455
|
if (provider === "outcrawl") return "Outcrawl";
|
|
27691
28456
|
if (provider === "sofya") return "Sofya";
|
|
28457
|
+
if (provider === "cloro") return "cloro";
|
|
28458
|
+
if (provider === "autom") return "Autom";
|
|
28459
|
+
if (provider === "specstream") return "SpecStream";
|
|
27692
28460
|
if (provider === "deepseek") return "DeepSeek";
|
|
27693
28461
|
return provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
27694
28462
|
}
|
|
@@ -27705,7 +28473,7 @@ async function searchWithProviders(query, options, selectedProviders, routing) {
|
|
|
27705
28473
|
available: provider === "gemini" ? isGeminiApiAvailable() : await isResolvedProviderAvailable(provider, options)
|
|
27706
28474
|
})))).filter((entry) => entry.available).map((entry) => entry.provider);
|
|
27707
28475
|
if (providers.length === 0) {
|
|
27708
|
-
throw new Error('No configured search provider available for provider "all". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, DeepSeek, Linkup, 9router, Cloudflare, SearchApi, Outcrawl, Sofya, and Tabstack are excluded.');
|
|
28476
|
+
throw new Error('No configured search provider available for provider "all". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, DeepSeek, Linkup, 9router, Cloudflare, SearchApi, Outcrawl, Sofya, cloro, Autom, SpecStream, and Tabstack are excluded.');
|
|
27709
28477
|
}
|
|
27710
28478
|
const settled = await Promise.allSettled(
|
|
27711
28479
|
providers.map((provider) => selectedProviders ? searchWithResolvedProvider(provider, query, options) : searchWithAllProvider(provider, query, options))
|
|
@@ -27718,7 +28486,7 @@ async function searchWithProviders(query, options, selectedProviders, routing) {
|
|
|
27718
28486
|
if (outcome.status === "fulfilled") {
|
|
27719
28487
|
successes.push(outcome.value);
|
|
27720
28488
|
} else {
|
|
27721
|
-
failures.push({ provider: providers[index], error:
|
|
28489
|
+
failures.push({ provider: providers[index], error: errorMessage35(outcome.reason) });
|
|
27722
28490
|
}
|
|
27723
28491
|
}
|
|
27724
28492
|
if (successes.length === 0) {
|
|
@@ -27735,7 +28503,7 @@ async function searchWithProviders(query, options, selectedProviders, routing) {
|
|
|
27735
28503
|
} catch (err) {
|
|
27736
28504
|
if (isAbortError2(err)) throw err;
|
|
27737
28505
|
throw new Error(`${failureMessage}
|
|
27738
|
-
${
|
|
28506
|
+
${errorMessage35(err)}`);
|
|
27739
28507
|
}
|
|
27740
28508
|
}
|
|
27741
28509
|
const results = [];
|
|
@@ -27835,7 +28603,7 @@ async function searchWithConfiguredRouting(query, callerOptions, routing) {
|
|
|
27835
28603
|
break;
|
|
27836
28604
|
}
|
|
27837
28605
|
const classified = classifyProviderError(provider, err);
|
|
27838
|
-
diagnostics.push(`${provider} [${classified.kind}]: ${
|
|
28606
|
+
diagnostics.push(`${provider} [${classified.kind}]: ${errorMessage35(err)}`);
|
|
27839
28607
|
if (!routing.fallbackOn.includes(classified.kind)) {
|
|
27840
28608
|
throw classified;
|
|
27841
28609
|
}
|
|
@@ -27875,7 +28643,7 @@ async function search(query, options = {}) {
|
|
|
27875
28643
|
return take(await searchWithResolvedProvider(provider2, query, options), provider2);
|
|
27876
28644
|
} catch (err) {
|
|
27877
28645
|
if (isAbortError2(err)) throw err;
|
|
27878
|
-
fallbackErrors.push(`${providerLabel(provider2)}: ${
|
|
28646
|
+
fallbackErrors.push(`${providerLabel(provider2)}: ${errorMessage35(err)}`);
|
|
27879
28647
|
return null;
|
|
27880
28648
|
}
|
|
27881
28649
|
};
|
|
@@ -27893,7 +28661,7 @@ async function search(query, options = {}) {
|
|
|
27893
28661
|
if (response) return response;
|
|
27894
28662
|
} catch (err) {
|
|
27895
28663
|
if (err instanceof CredentialResolutionError || isAbortError2(err)) throw err;
|
|
27896
|
-
fallbackErrors.push(`Exa: ${
|
|
28664
|
+
fallbackErrors.push(`Exa: ${errorMessage35(err)}`);
|
|
27897
28665
|
}
|
|
27898
28666
|
}
|
|
27899
28667
|
if (allowed.has("openai") && !triedOpenAI) {
|
|
@@ -27909,7 +28677,7 @@ async function search(query, options = {}) {
|
|
|
27909
28677
|
if (response) return response;
|
|
27910
28678
|
} catch (err) {
|
|
27911
28679
|
if (isAbortError2(err)) throw err;
|
|
27912
|
-
fallbackErrors.push(`Gemini: ${
|
|
28680
|
+
fallbackErrors.push(`Gemini: ${errorMessage35(err)}`);
|
|
27913
28681
|
}
|
|
27914
28682
|
if (firstEmpty) return firstEmpty;
|
|
27915
28683
|
if (fallbackErrors.length > 0) {
|
|
@@ -27919,11 +28687,11 @@ async function search(query, options = {}) {
|
|
|
27919
28687
|
throw new Error(
|
|
27920
28688
|
`No search provider available. Either:
|
|
27921
28689
|
1. Use /login to sign in with a Codex subscription for OpenAI web search
|
|
27922
|
-
2. Set openaiApiKey, braveApiKey, parallelApiKey, tinyfishApiKey, search1apiApiKey, searchinfinityApiKey, queritApiKey, tavilyApiKey, firecrawlBaseUrl, jinaApiKey, serpdiveApiKey, kagiApiKey, ollamaApiKey, searxngBaseUrl, perplexityApiKey, exaApiKey, geminiApiKey, bochaApiKey, or cloudflareApiKey in ${
|
|
28690
|
+
2. Set openaiApiKey, braveApiKey, parallelApiKey, tinyfishApiKey, search1apiApiKey, searchinfinityApiKey, queritApiKey, tavilyApiKey, firecrawlBaseUrl, jinaApiKey, serpdiveApiKey, kagiApiKey, ollamaApiKey, searxngBaseUrl, perplexityApiKey, exaApiKey, geminiApiKey, bochaApiKey, or cloudflareApiKey in ${CONFIG_PATH49}
|
|
27923
28691
|
3. Set OPENAI_API_KEY, BRAVE_API_KEY, PARALLEL_API_KEY, TINYFISH_API_KEY, SEARCH1API_KEY, SEARCHINFINITY_API_KEY, QUERIT_API_KEY, TAVILY_API_KEY, FIRECRAWL_BASE_URL, JINA_API_KEY, SERPDIVE_API_KEY, KAGI_API_KEY, BOCHA_API_KEY, OLLAMA_API_KEY, SEARXNG_BASE_URL, EXA_API_KEY, PERPLEXITY_API_KEY, GEMINI_API_KEY, or CLOUDFLARE_API_KEY env vars
|
|
27924
28692
|
4. Set GOOGLE_GEMINI_BASE_URL with CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing
|
|
27925
28693
|
5. Sign into gemini.google.com in a supported Chromium-based browser
|
|
27926
|
-
6. Explicitly select provider: "anysearch" for anonymous AnySearch, "xcrawl" for XCrawl, "xai" for Grok, "mistral" for Mistral Conversations web search, "brightdata" with brightdataSerpZone for paid Bright Data SERP, "serpbase", "serpapi", "serper", or "serply" for Google SERP, "you" for You.com, "zai" for Z.ai GLM Coding Plan search, "valyu" for research search, "keenable" for keyless Keenable search, "ceramic" for Ceramic search, "deepseek" for DeepSeek search, "linkup" for Linkup search, "ninerouter" for a 9router gateway, "cloudflare" for the Cloudflare Web Search API, "searchapi" for SearchApi Google search, "outcrawl" for Outcrawl search, "sofya" for Sofya search, or "tabstack" for Tabstack Research`
|
|
28694
|
+
6. Explicitly select provider: "anysearch" for anonymous AnySearch, "xcrawl" for XCrawl, "xai" for Grok, "mistral" for Mistral Conversations web search, "brightdata" with brightdataSerpZone for paid Bright Data SERP, "serpbase", "serpapi", "serper", or "serply" for Google SERP, "you" for You.com, "zai" for Z.ai GLM Coding Plan search, "valyu" for research search, "keenable" for keyless Keenable search, "ceramic" for Ceramic search, "deepseek" for DeepSeek search, "linkup" for Linkup search, "ninerouter" for a 9router gateway, "cloudflare" for the Cloudflare Web Search API, "searchapi" for SearchApi Google search, "outcrawl" for Outcrawl search, "sofya" for Sofya search, "cloro" for cloro Google search or AI Mode, "autom" for Autom Google search, "specstream" for SpecStream Search API, or "tabstack" for Tabstack Research`
|
|
27927
28695
|
);
|
|
27928
28696
|
}
|
|
27929
28697
|
async function searchWithGeminiApi(query, options = {}) {
|
|
@@ -28208,7 +28976,7 @@ function createMcpServer(core2, info, enabledTools) {
|
|
|
28208
28976
|
}
|
|
28209
28977
|
|
|
28210
28978
|
// web-tool-core.ts
|
|
28211
|
-
import { existsSync as
|
|
28979
|
+
import { existsSync as existsSync65, readFileSync as readFileSync67 } from "node:fs";
|
|
28212
28980
|
import pLimit2 from "p-limit";
|
|
28213
28981
|
|
|
28214
28982
|
// fetch-params.ts
|
|
@@ -28802,9 +29570,9 @@ function formatPageExtraction(extraction) {
|
|
|
28802
29570
|
init_utils();
|
|
28803
29571
|
|
|
28804
29572
|
// storage.ts
|
|
28805
|
-
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync as
|
|
29573
|
+
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync as mkdirSync2, openSync, readFileSync as readFileSync55, readdirSync as readdirSync2, renameSync as renameSync2, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
28806
29574
|
init_utils();
|
|
28807
|
-
import { join as
|
|
29575
|
+
import { join as join5 } from "node:path";
|
|
28808
29576
|
var CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
28809
29577
|
var FETCH_CACHE_DIR = "web-search-cache";
|
|
28810
29578
|
var FETCH_CACHE_VERSION = 1;
|
|
@@ -28819,11 +29587,11 @@ function generateId() {
|
|
|
28819
29587
|
return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
|
28820
29588
|
}
|
|
28821
29589
|
function getFetchCacheDir() {
|
|
28822
|
-
return
|
|
29590
|
+
return join5(process.env.PI_WEB_ACCESS_CACHE_ROOT || getWebSearchConfigDir(), FETCH_CACHE_DIR);
|
|
28823
29591
|
}
|
|
28824
29592
|
function fetchCachePath(key) {
|
|
28825
29593
|
if (!CACHE_KEY_PATTERN.test(key)) return null;
|
|
28826
|
-
return
|
|
29594
|
+
return join5(getFetchCacheDir(), key);
|
|
28827
29595
|
}
|
|
28828
29596
|
function truncateMetadataText(value) {
|
|
28829
29597
|
if (!value) return "";
|
|
@@ -28867,7 +29635,7 @@ function enforceMode(fd, mode) {
|
|
|
28867
29635
|
}
|
|
28868
29636
|
function safeFetchCacheDir(create) {
|
|
28869
29637
|
const dir = getFetchCacheDir();
|
|
28870
|
-
if (create)
|
|
29638
|
+
if (create) mkdirSync2(dir, { recursive: true, mode: 448 });
|
|
28871
29639
|
let before;
|
|
28872
29640
|
try {
|
|
28873
29641
|
before = lstatSync(dir);
|
|
@@ -28919,7 +29687,7 @@ function unlinkCacheFile(dir, file) {
|
|
|
28919
29687
|
return false;
|
|
28920
29688
|
}
|
|
28921
29689
|
try {
|
|
28922
|
-
const path =
|
|
29690
|
+
const path = join5(dir, file.name);
|
|
28923
29691
|
const current = lstatSync(path);
|
|
28924
29692
|
if (current.isSymbolicLink() || !current.isFile() || current.dev !== file.dev || current.ino !== file.ino) return false;
|
|
28925
29693
|
unlinkSync(path);
|
|
@@ -28963,7 +29731,7 @@ function readCachedFetchData(data) {
|
|
|
28963
29731
|
const opened = openRegularFile(path);
|
|
28964
29732
|
fd = opened.fd;
|
|
28965
29733
|
enforceMode(fd, 384);
|
|
28966
|
-
const parsed = JSON.parse(
|
|
29734
|
+
const parsed = JSON.parse(readFileSync55(fd, "utf8"));
|
|
28967
29735
|
if (!isValidStoredData(parsed) || parsed.type !== "fetch" || parsed.id !== data.id || !isInlineFetchData(parsed)) {
|
|
28968
29736
|
return unavailableFetchData(data, "Cached fetched content is invalid");
|
|
28969
29737
|
}
|
|
@@ -29203,9 +29971,9 @@ function parseConfigRoot(raw) {
|
|
|
29203
29971
|
}
|
|
29204
29972
|
return parsed;
|
|
29205
29973
|
}
|
|
29206
|
-
function
|
|
29207
|
-
if (!
|
|
29208
|
-
return parseConfigRoot(
|
|
29974
|
+
function loadConfig51() {
|
|
29975
|
+
if (!existsSync65(WEB_SEARCH_CONFIG_PATH4)) return {};
|
|
29976
|
+
return parseConfigRoot(readFileSync67(WEB_SEARCH_CONFIG_PATH4, "utf-8"));
|
|
29209
29977
|
}
|
|
29210
29978
|
var DEFAULT_TOOL_NAMES = {
|
|
29211
29979
|
webSearch: "web_search",
|
|
@@ -29260,7 +30028,7 @@ function resolveRequestedProvider(requested) {
|
|
|
29260
30028
|
assertSearchProviderSelectionAllowed(normalizedRequested, "Requested provider");
|
|
29261
30029
|
return normalizedRequested;
|
|
29262
30030
|
}
|
|
29263
|
-
const config =
|
|
30031
|
+
const config = loadConfig51();
|
|
29264
30032
|
const provider = normalizeProviderInput(config.searchProvider ?? config.provider, `provider in ${WEB_SEARCH_CONFIG_PATH4}`) ?? "auto";
|
|
29265
30033
|
assertSearchProviderSelectionAllowed(provider, `configured provider in ${WEB_SEARCH_CONFIG_PATH4}`);
|
|
29266
30034
|
return provider;
|
|
@@ -29323,7 +30091,7 @@ function isAbortError6(err) {
|
|
|
29323
30091
|
var DEFAULT_MAX_INLINE_CONTENT_CHARS = 3e4;
|
|
29324
30092
|
var MIN_INLINE_CONTENT_CHARS = 1e3;
|
|
29325
30093
|
var MAX_INLINE_CONTENT_CHARS = 2e5;
|
|
29326
|
-
function getMaxInlineContentChars(config =
|
|
30094
|
+
function getMaxInlineContentChars(config = loadConfig51()) {
|
|
29327
30095
|
const value = config.maxInlineContentChars;
|
|
29328
30096
|
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < MIN_INLINE_CONTENT_CHARS) {
|
|
29329
30097
|
return DEFAULT_MAX_INLINE_CONTENT_CHARS;
|
|
@@ -29935,18 +30703,22 @@ Full search results are stored as responseId "${searchId}". `;
|
|
|
29935
30703
|
...authFetchProfile ? { authFetchProfile } : {}
|
|
29936
30704
|
};
|
|
29937
30705
|
const fetchResults = await fetchAllContent2(urlList, signal, fetchOptions(requestOptions, options.proxy));
|
|
29938
|
-
const textResults = mode === "
|
|
30706
|
+
const textResults = mode === "extract" ? fetchResults.map((result) => !result.error && (result.mimeType?.startsWith("image/") || result.frames?.length) ? { ...result, error: "Field extraction requires textual fetched content" } : result) : fetchResults;
|
|
29939
30707
|
const presentedResults = mode === "answer" ? await Promise.all(textResults.map(async (result) => {
|
|
29940
30708
|
if (result.error) return result;
|
|
29941
30709
|
try {
|
|
29942
30710
|
if (!host.answerFromPage) throw new Error("this host cannot answer from fetched pages");
|
|
30711
|
+
const images = result.frames?.length ? result.frames.map((frame) => ({ data: frame.data, mimeType: frame.mimeType, label: `Frame at ${frame.timestamp}` })) : result.mimeType?.startsWith("image/") && result.thumbnail ? [{ ...result.thumbnail, label: result.title }] : void 0;
|
|
29943
30712
|
const answer = await host.answerFromPage({
|
|
29944
30713
|
question: options.prompt,
|
|
29945
30714
|
pageText: result.content,
|
|
29946
30715
|
sourceUrl: result.url,
|
|
29947
|
-
...options.answerModel ? { model: options.answerModel } : {}
|
|
30716
|
+
...options.answerModel ? { model: options.answerModel } : {},
|
|
30717
|
+
...images ? { images } : {}
|
|
29948
30718
|
}, ctx, signal);
|
|
29949
|
-
return { ...result, content: answer.text };
|
|
30719
|
+
if (!images) return { ...result, content: answer.text };
|
|
30720
|
+
const { frames: _frames, thumbnail: _thumbnail, ...rest } = result;
|
|
30721
|
+
return { ...rest, content: answer.text };
|
|
29950
30722
|
} catch (err) {
|
|
29951
30723
|
return { ...result, error: `Page answer failed: ${err instanceof Error ? err.message : String(err)}` };
|
|
29952
30724
|
}
|
|
@@ -30437,7 +31209,7 @@ function standaloneFetchRejection(params, fetchModes) {
|
|
|
30437
31209
|
return void 0;
|
|
30438
31210
|
}
|
|
30439
31211
|
function createStandaloneWebToolCore() {
|
|
30440
|
-
const config =
|
|
31212
|
+
const config = loadConfig51();
|
|
30441
31213
|
const settings2 = {
|
|
30442
31214
|
toolNames: { ...DEFAULT_TOOL_NAMES },
|
|
30443
31215
|
enabledTools: {
|