@herbertgao/pi-extensions 2026.10.6 → 2026.10.7
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/README.md +9 -13
- package/THIRD_PARTY_NOTICES.md +1 -53
- package/extensions/clef-format.mjs +113 -0
- package/extensions/clef.mjs +112 -0
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail-debt.md +1 -1
- package/node_modules/@dietrichgebert/ponytail/.opencode/plugins/ponytail.mjs +30 -6
- package/node_modules/@dietrichgebert/ponytail/.qoder-plugin/plugin.json +1 -1
- package/node_modules/@dietrichgebert/ponytail/README.md +5 -1
- package/node_modules/@dietrichgebert/ponytail/hooks/claude-codex-hooks.json +3 -3
- package/node_modules/@dietrichgebert/ponytail/hooks/copilot-hooks.json +4 -4
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-activate.js +158 -127
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-config.js +5 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-map.js +8 -3
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-runtime.js +14 -8
- package/node_modules/@dietrichgebert/ponytail/package.json +1 -1
- package/node_modules/@dietrichgebert/ponytail/pi-extension/index.js +16 -3
- package/node_modules/@dietrichgebert/ponytail/scripts/cursor-hooks.js +13 -3
- package/node_modules/@dietrichgebert/ponytail/scripts/uninstall.js +3 -2
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-debt/SKILL.md +3 -3
- package/node_modules/@herbertgao/pi-agency/package.json +2 -2
- package/node_modules/@herbertgao/pi-bark/package.json +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +283 -136
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +90 -22
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +66 -26
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +5 -5
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +8 -0
- package/node_modules/@herbertgao/pi-subagents/docs/packages.md +211 -0
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +61 -63
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +24 -16
- package/node_modules/@herbertgao/pi-subagents/package.json +5 -5
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +51 -14
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +123 -55
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +144 -13
- package/node_modules/@herbertgao/pi-subagents/src/agent-source-badge.ts +78 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +122 -0
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +171 -79
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +597 -296
- package/node_modules/@herbertgao/pi-subagents/src/package-resources.ts +724 -0
- package/node_modules/@herbertgao/pi-subagents/src/schedule.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +66 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +26 -4
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +354 -32
- package/node_modules/@herbertgao/pi-subagents/src/ui/fleet-list.ts +33 -15
- package/node_modules/@herbertgao/pi-subagents/src/workflow/host.ts +6 -0
- package/node_modules/@herbertgao/pi-subagents/src/workflow/saved.ts +48 -2
- package/node_modules/@herbertgao/sol-pi/package.json +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/README.md +3 -3
- package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +89 -39
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/configuration.md +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/hosts.md +4 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/keyboard.md +56 -23
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/tool-schema.md +6 -3
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/de.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/en.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/es.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/fr.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/pt-BR.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/pt.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/ru.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/uk.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/locales/zh.json +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +5 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/presentation.ts +122 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/rpc-fallback.ts +73 -36
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/build-questionnaire.ts +10 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/key-router.ts +15 -13
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +5 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/derivations.ts +15 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/projections.ts +4 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state-reducer.ts +29 -18
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/format-answer.ts +5 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/normalize-params.ts +46 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/response-envelope.ts +19 -8
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/types.ts +9 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/multi-select-view.ts +4 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-block-renderer.ts +56 -25
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-pane.ts +131 -46
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +94 -106
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-copy.ts +51 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/scroll-window.ts +73 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +31 -10
- package/node_modules/@pi-plugins/fast-mode/dist/index.d.mts.map +1 -1
- package/node_modules/@pi-plugins/fast-mode/dist/index.mjs +474 -93
- package/node_modules/@pi-plugins/fast-mode/dist/index.mjs.map +1 -1
- package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
- package/node_modules/pi-lens/CHANGELOG.md +88 -0
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +3 -1
- package/node_modules/pi-lens/dist/{chunk-BJF25SUG.js → chunk-23WOO7TX.js} +11 -10
- package/node_modules/pi-lens/dist/{chunk-WATC3IQR.js → chunk-2B73ZPOK.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-N2IRDBZI.js → chunk-2BBLFX75.js} +101 -11
- package/node_modules/pi-lens/dist/{chunk-TA5L5KWQ.js → chunk-2CD5RS6M.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-3TTPKMEF.js → chunk-2VUQMUMT.js} +38 -37
- package/node_modules/pi-lens/dist/{chunk-5JHXUETW.js → chunk-3EFKIGZN.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-3JNKMP3B.js +17 -0
- package/node_modules/pi-lens/dist/{chunk-6P54TMWL.js → chunk-3VPVG5SU.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-ZETYB3XG.js → chunk-3W7IEVVL.js} +44 -28
- package/node_modules/pi-lens/dist/chunk-3YN6V5TV.js +85 -0
- package/node_modules/pi-lens/dist/chunk-466Z26MG.js +30 -0
- package/node_modules/pi-lens/dist/{chunk-PCHDGUKT.js → chunk-4UNXBNE2.js} +12 -11
- package/node_modules/pi-lens/dist/{chunk-J7WJZ6W7.js → chunk-4W4VLAPJ.js} +12 -11
- package/node_modules/pi-lens/dist/{chunk-F5VLZHUW.js → chunk-52FUZI6K.js} +4 -2
- package/node_modules/pi-lens/dist/{chunk-H5EV3VMF.js → chunk-5NGR67U5.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-CBD2B5CP.js → chunk-5UCAH366.js} +21 -20
- package/node_modules/pi-lens/dist/{chunk-BHWHXMQ2.js → chunk-67WMNWEE.js} +9 -8
- package/node_modules/pi-lens/dist/{chunk-USHG4DLH.js → chunk-6C7JWPCP.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-VPWKF3GN.js → chunk-6GFRNVYR.js} +11 -10
- package/node_modules/pi-lens/dist/{chunk-3JL6IFD7.js → chunk-6SDEP3AJ.js} +9 -8
- package/node_modules/pi-lens/dist/{chunk-NJF2X5XF.js → chunk-6STA6Z7I.js} +19 -17
- package/node_modules/pi-lens/dist/{chunk-KJCWXUUS.js → chunk-724UL2TJ.js} +6 -4
- package/node_modules/pi-lens/dist/{chunk-MQA2YBAH.js → chunk-76MWC2K6.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-YLN4K6WD.js → chunk-77M37OKR.js} +10 -8
- package/node_modules/pi-lens/dist/{chunk-XHSCVSOL.js → chunk-7DYBLXYA.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-OC7LYAU5.js → chunk-AB3YYG6N.js} +24 -10
- package/node_modules/pi-lens/dist/{chunk-LD7WFTRX.js → chunk-ACXEQZOU.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-VSMJK3ZJ.js → chunk-AOHZU2BM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-T4QZ6FEH.js → chunk-AW7R2GWG.js} +65 -8
- package/node_modules/pi-lens/dist/{chunk-GAYGGICG.js → chunk-BKE7E7TC.js} +10 -9
- package/node_modules/pi-lens/dist/{chunk-EUT3B22Y.js → chunk-BRGDSBJE.js} +13 -12
- package/node_modules/pi-lens/dist/{chunk-T54VJRAD.js → chunk-C34ZXZ7O.js} +55 -11
- package/node_modules/pi-lens/dist/{chunk-UGSMCQ4D.js → chunk-CHOW74WE.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-H2W2AXD3.js → chunk-CMMHNUZ2.js} +66 -58
- package/node_modules/pi-lens/dist/chunk-CSHFH5IN.js +17 -0
- package/node_modules/pi-lens/dist/chunk-EC47DWFA.js +56 -0
- package/node_modules/pi-lens/dist/{chunk-KJN4IOEJ.js → chunk-EJIUXPBX.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-IQZXOZ7S.js → chunk-EU63SDCG.js} +720 -334
- package/node_modules/pi-lens/dist/{chunk-LNOMA3MP.js → chunk-FCSOVF55.js} +107 -3
- package/node_modules/pi-lens/dist/{chunk-CFYISHUW.js → chunk-FLKWCIZH.js} +8 -5
- package/node_modules/pi-lens/dist/{chunk-OYTMZXRF.js → chunk-FMSO6RDZ.js} +16 -14
- package/node_modules/pi-lens/dist/{chunk-IUKPRZER.js → chunk-GAEGEPOC.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6XX5HCLK.js → chunk-GBPP5P7X.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-TQFBZVCG.js → chunk-GXW6K4YJ.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ZZUFZUQZ.js → chunk-H6MF6EVN.js} +331 -107
- package/node_modules/pi-lens/dist/{chunk-3JSEWUWI.js → chunk-IBGIOBEE.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-IZSHAIJ7.js +26 -0
- package/node_modules/pi-lens/dist/{chunk-7ELY2CSM.js → chunk-JAU72XNY.js} +16 -14
- package/node_modules/pi-lens/dist/chunk-JMYYOTQG.js +77 -0
- package/node_modules/pi-lens/dist/{chunk-ELVWJYRV.js → chunk-JSQFTSC6.js} +12 -11
- package/node_modules/pi-lens/dist/{chunk-J6DFZDFA.js → chunk-KBG47GHP.js} +4 -4
- package/node_modules/pi-lens/dist/chunk-KDERNTCQ.js +28 -0
- package/node_modules/pi-lens/dist/chunk-KSX3TXSZ.js +69 -0
- package/node_modules/pi-lens/dist/{chunk-XGUL4SLQ.js → chunk-L3BLXZG7.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-LOP6GRPH.js +31 -0
- package/node_modules/pi-lens/dist/{chunk-MTDRLSI7.js → chunk-M6HSLBWY.js} +1064 -986
- package/node_modules/pi-lens/dist/chunk-MQLUAEOC.js +162 -0
- package/node_modules/pi-lens/dist/{chunk-3MRXIJ6I.js → chunk-MRXKYPCS.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-D65GOCJB.js → chunk-MXGY6KPT.js} +19 -16
- package/node_modules/pi-lens/dist/{chunk-G3RLJYA2.js → chunk-N2H3ZPZY.js} +47 -1
- package/node_modules/pi-lens/dist/{chunk-HREZQCT3.js → chunk-N3X6Q4YT.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-HSIRMK2D.js → chunk-OCAGUNBC.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-ZOEYVXSV.js → chunk-OXXKQCSV.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-S6AMWKPC.js → chunk-P7266HLM.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-64LU2OVH.js → chunk-PHDMFAKM.js} +12 -2
- package/node_modules/pi-lens/dist/{chunk-IMSQR4WO.js → chunk-PNQDPDRC.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-IUR76K6A.js → chunk-Q7DUK4LX.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-CULQYFLU.js → chunk-QGQ5CCCG.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-UEAHAMEI.js → chunk-QHJ6DQ2R.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-BNKLYOOO.js → chunk-QILIYSJF.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VYKKMYVT.js → chunk-QOBUHWHX.js} +11 -6
- package/node_modules/pi-lens/dist/{chunk-3PNFWVHT.js → chunk-QQNQ7SJW.js} +2 -75
- package/node_modules/pi-lens/dist/{chunk-7M4T5N3V.js → chunk-R3PCY3YS.js} +14 -13
- package/node_modules/pi-lens/dist/{chunk-MGIWSROG.js → chunk-RPLINGVB.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-CMU4RMJB.js → chunk-RWWYJ623.js} +10 -1
- package/node_modules/pi-lens/dist/{chunk-3FERWMCH.js → chunk-RXCOMYPY.js} +27 -26
- package/node_modules/pi-lens/dist/{chunk-7BX5DWSA.js → chunk-SAEFPSB6.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-N7YNJE5R.js → chunk-SQ4TVJBR.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-DMS52BEP.js → chunk-SS36ZX4J.js} +9 -7
- package/node_modules/pi-lens/dist/{chunk-JONGANYH.js → chunk-T6CPIZNT.js} +32 -30
- package/node_modules/pi-lens/dist/{chunk-6UYA642J.js → chunk-TYM6OUIT.js} +13 -12
- package/node_modules/pi-lens/dist/{chunk-ALQRYH6O.js → chunk-UXGETRP4.js} +13 -12
- package/node_modules/pi-lens/dist/{chunk-FGALODG3.js → chunk-UZ3TUTRV.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-J3FZR3YY.js → chunk-VCHXCQFG.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-3P4PF2BX.js → chunk-VCO24T4L.js} +34 -22
- package/node_modules/pi-lens/dist/{chunk-O7HZX7CA.js → chunk-VRZP76YM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VZHJS6DR.js → chunk-VSSBEUFT.js} +16 -15
- package/node_modules/pi-lens/dist/{chunk-U52SAGRM.js → chunk-VWCXW2E7.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-WW5BLB74.js → chunk-WOA4LN2R.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-ZMOMPX2Z.js → chunk-WU567RSC.js} +11 -10
- package/node_modules/pi-lens/dist/{chunk-N77WFUL7.js → chunk-XAGLWMJ4.js} +23 -22
- package/node_modules/pi-lens/dist/{chunk-WSEWKCXU.js → chunk-XCJN5IJU.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-IR6XFA5P.js → chunk-XIJZVPD5.js} +16 -14
- package/node_modules/pi-lens/dist/{chunk-OYOB3ZFG.js → chunk-XMSXXAHW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-34OCDWOS.js → chunk-XTMJ7XDT.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-Z6BB4JLQ.js → chunk-XVF2VVXP.js} +5 -3
- package/node_modules/pi-lens/dist/{chunk-AFZYMAIV.js → chunk-YIUAVF7E.js} +37 -35
- package/node_modules/pi-lens/dist/{chunk-NFXP47RV.js → chunk-YSZNHOBY.js} +85 -31
- package/node_modules/pi-lens/dist/{chunk-V5MEBST3.js → chunk-YYOIQFRS.js} +21 -21
- package/node_modules/pi-lens/dist/chunk-Z527N6YQ.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-D6YF5HKX.js → chunk-ZANLILYD.js} +22 -2
- package/node_modules/pi-lens/dist/{chunk-2UMYMRI3.js → chunk-ZGDGW2V3.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6B5I6ICN.js → chunk-ZHFZWTZV.js} +12 -11
- package/node_modules/pi-lens/dist/{chunk-OEX24ECI.js → chunk-ZWFS3OEF.js} +51 -41
- package/node_modules/pi-lens/dist/{chunk-AXKPQ6ZI.js → chunk-ZXYDQ3TZ.js} +5 -5
- package/node_modules/pi-lens/dist/index.js +73783 -71033
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +18 -8
- package/node_modules/pi-lens/dist/mcp/cli.js +48 -37
- package/node_modules/pi-lens/dist/mcp/server.js +568 -397
- package/node_modules/pi-lens/dist/mcp/worker.js +67 -55
- package/node_modules/pi-lens/dist/probes/installer.js +20 -19
- package/node_modules/pi-lens/docs/astplayground.md +1 -1
- package/node_modules/pi-lens/docs/configuration.md +29 -0
- package/node_modules/pi-lens/docs/dependencies.md +3 -0
- package/node_modules/pi-lens/docs/features.md +2 -2
- package/node_modules/pi-lens/docs/globalconfig.md +2 -0
- package/node_modules/pi-lens/docs/language-coverage.md +2 -1
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +29 -7
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +38 -47
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +4 -0
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +17 -4
- package/node_modules/pi-lens/docs/pi-lens-retro.md +2 -1
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +18 -0
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +7 -0
- package/node_modules/pi-lens/docs/real-harness.md +17 -0
- package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +37 -2
- package/node_modules/pi-lens/docs/servercapabilities.md +15 -4
- package/node_modules/pi-lens/docs/settings.md +2 -1
- package/node_modules/pi-lens/package.json +1 -1
- package/node_modules/pi-provider-qoder/dist/index.js +30 -2
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +50 -0
- package/node_modules/pi-web-access/README.md +13 -7
- package/node_modules/pi-web-access/brave.ts +20 -2
- package/node_modules/pi-web-access/content-find.ts +2 -1
- package/node_modules/pi-web-access/dist/index.js +655 -406
- package/node_modules/pi-web-access/dist/mcp-cli.js +653 -416
- package/node_modules/pi-web-access/duckduckgo.ts +5 -1
- package/node_modules/pi-web-access/endpoint-pdf-extract.ts +225 -0
- package/node_modules/pi-web-access/extract.ts +51 -13
- package/node_modules/pi-web-access/fetch-params.ts +10 -0
- package/node_modules/pi-web-access/gemini-api.ts +15 -0
- package/node_modules/pi-web-access/gemini-search.ts +32 -152
- package/node_modules/pi-web-access/github-issue-pr.ts +80 -68
- package/node_modules/pi-web-access/index.ts +3 -0
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/pdf-extract.ts +38 -4
- package/node_modules/pi-web-access/perplexity.ts +19 -2
- package/node_modules/pi-web-access/ssrf-protection.ts +24 -4
- package/node_modules/pi-web-access/summary-review.ts +10 -0
- package/node_modules/pi-web-access/tool-arguments.ts +5 -2
- package/node_modules/pi-web-access/video-extract.ts +6 -2
- package/node_modules/pi-web-access/web-tool-core.ts +53 -13
- package/package.json +19 -24
- package/node_modules/pi-jev-auto-mode/CHANGELOG.md +0 -118
- package/node_modules/pi-jev-auto-mode/LICENSE +0 -21
- package/node_modules/pi-jev-auto-mode/README.md +0 -292
- package/node_modules/pi-jev-auto-mode/SECURITY.md +0 -32
- package/node_modules/pi-jev-auto-mode/docs/calibration.md +0 -154
- package/node_modules/pi-jev-auto-mode/docs/design.md +0 -164
- package/node_modules/pi-jev-auto-mode/docs/security.md +0 -124
- package/node_modules/pi-jev-auto-mode/index.ts +0 -1
- package/node_modules/pi-jev-auto-mode/package.json +0 -72
- package/node_modules/pi-jev-auto-mode/src/call.ts +0 -180
- package/node_modules/pi-jev-auto-mode/src/decide.ts +0 -86
- package/node_modules/pi-jev-auto-mode/src/extension.ts +0 -881
- package/node_modules/pi-jev-auto-mode/src/intent.ts +0 -71
- package/node_modules/pi-jev-auto-mode/src/jev/availability.ts +0 -53
- package/node_modules/pi-jev-auto-mode/src/jev/criteria.ts +0 -19
- package/node_modules/pi-jev-auto-mode/src/jev/decide.ts +0 -187
- package/node_modules/pi-jev-auto-mode/src/jev/engine.ts +0 -165
- package/node_modules/pi-jev-auto-mode/src/jev/index.ts +0 -20
- package/node_modules/pi-jev-auto-mode/src/jev/questions.ts +0 -273
- package/node_modules/pi-jev-auto-mode/src/jev/response.ts +0 -64
- package/node_modules/pi-jev-auto-mode/src/jev/state.ts +0 -20
- package/node_modules/pi-jev-auto-mode/src/jev/transport.ts +0 -117
- package/node_modules/pi-jev-auto-mode/src/jev/types.ts +0 -46
- package/node_modules/pi-jev-auto-mode/src/policy.ts +0 -558
- package/node_modules/pi-jev-auto-mode/src/records.ts +0 -184
- package/node_modules/pi-jev-auto-mode/src/settings.ts +0 -349
- package/node_modules/pi-jev-auto-mode/src/ui.ts +0 -243
- package/node_modules/pi-lens/dist/chunk-2FQ62SPM.js +0 -83
- package/node_modules/pi-lens/dist/chunk-7AXO3ZDF.js +0 -30
- package/node_modules/pi-lens/dist/chunk-KMGPUKFD.js +0 -25
- package/node_modules/pi-lens/dist/chunk-OZJINN4O.js +0 -84
- package/node_modules/pi-lens/dist/chunk-RJFED73B.js +0 -79
- package/node_modules/pi-lens/dist/chunk-RTQNRM5X.js +0 -27
- package/node_modules/pi-lens/dist/chunk-VGEVL5EQ.js +0 -29
- package/node_modules/pi-lens/dist/chunk-WPE5FPGR.js +0 -54
- package/node_modules/pi-lens/dist/chunk-Z7QQA2KT.js +0 -27
- package/node_modules/resume-from/LICENSE +0 -21
- package/node_modules/resume-from/README.md +0 -167
- package/node_modules/resume-from/dist/adapters/claude-code/adapter.d.ts +0 -20
- package/node_modules/resume-from/dist/adapters/claude-code/adapter.js +0 -59
- package/node_modules/resume-from/dist/adapters/claude-code/contract.d.ts +0 -8
- package/node_modules/resume-from/dist/adapters/claude-code/contract.js +0 -4
- package/node_modules/resume-from/dist/adapters/claude-code/entries.d.ts +0 -30
- package/node_modules/resume-from/dist/adapters/claude-code/entries.js +0 -107
- package/node_modules/resume-from/dist/adapters/claude-code/index.d.ts +0 -3
- package/node_modules/resume-from/dist/adapters/claude-code/index.js +0 -2
- package/node_modules/resume-from/dist/adapters/claude-code/layout.d.ts +0 -29
- package/node_modules/resume-from/dist/adapters/claude-code/layout.js +0 -80
- package/node_modules/resume-from/dist/adapters/claude-code/readback.d.ts +0 -9
- package/node_modules/resume-from/dist/adapters/claude-code/readback.js +0 -39
- package/node_modules/resume-from/dist/adapters/claude-code/reader.d.ts +0 -40
- package/node_modules/resume-from/dist/adapters/claude-code/reader.js +0 -436
- package/node_modules/resume-from/dist/adapters/claude-code/redaction.d.ts +0 -26
- package/node_modules/resume-from/dist/adapters/claude-code/redaction.js +0 -145
- package/node_modules/resume-from/dist/adapters/claude-code/validation.d.ts +0 -4
- package/node_modules/resume-from/dist/adapters/claude-code/validation.js +0 -39
- package/node_modules/resume-from/dist/adapters/claude-code/writer.d.ts +0 -21
- package/node_modules/resume-from/dist/adapters/claude-code/writer.js +0 -306
- package/node_modules/resume-from/dist/adapters/codex/contract.d.ts +0 -13
- package/node_modules/resume-from/dist/adapters/codex/contract.js +0 -4
- package/node_modules/resume-from/dist/adapters/codex/index.d.ts +0 -6
- package/node_modules/resume-from/dist/adapters/codex/index.js +0 -43
- package/node_modules/resume-from/dist/adapters/codex/read.d.ts +0 -44
- package/node_modules/resume-from/dist/adapters/codex/read.js +0 -723
- package/node_modules/resume-from/dist/adapters/codex/readback.d.ts +0 -9
- package/node_modules/resume-from/dist/adapters/codex/readback.js +0 -47
- package/node_modules/resume-from/dist/adapters/codex/redaction.d.ts +0 -26
- package/node_modules/resume-from/dist/adapters/codex/redaction.js +0 -145
- package/node_modules/resume-from/dist/adapters/codex/rollout.d.ts +0 -115
- package/node_modules/resume-from/dist/adapters/codex/rollout.js +0 -269
- package/node_modules/resume-from/dist/adapters/codex/validation.d.ts +0 -7
- package/node_modules/resume-from/dist/adapters/codex/validation.js +0 -78
- package/node_modules/resume-from/dist/adapters/codex/write.d.ts +0 -17
- package/node_modules/resume-from/dist/adapters/codex/write.js +0 -141
- package/node_modules/resume-from/dist/adapters/contract.d.ts +0 -78
- package/node_modules/resume-from/dist/adapters/contract.js +0 -4
- package/node_modules/resume-from/dist/adapters/pi/adapter.d.ts +0 -15
- package/node_modules/resume-from/dist/adapters/pi/adapter.js +0 -213
- package/node_modules/resume-from/dist/adapters/pi/contract.d.ts +0 -24
- package/node_modules/resume-from/dist/adapters/pi/contract.js +0 -4
- package/node_modules/resume-from/dist/adapters/pi/format.d.ts +0 -162
- package/node_modules/resume-from/dist/adapters/pi/format.js +0 -223
- package/node_modules/resume-from/dist/adapters/pi/index.d.ts +0 -7
- package/node_modules/resume-from/dist/adapters/pi/index.js +0 -10
- package/node_modules/resume-from/dist/adapters/pi/parse.d.ts +0 -41
- package/node_modules/resume-from/dist/adapters/pi/parse.js +0 -371
- package/node_modules/resume-from/dist/adapters/pi/redaction.d.ts +0 -26
- package/node_modules/resume-from/dist/adapters/pi/redaction.js +0 -145
- package/node_modules/resume-from/dist/adapters/pi/serialize.d.ts +0 -20
- package/node_modules/resume-from/dist/adapters/pi/serialize.js +0 -87
- package/node_modules/resume-from/dist/adapters/pi/validate.d.ts +0 -14
- package/node_modules/resume-from/dist/adapters/pi/validate.js +0 -134
- package/node_modules/resume-from/dist/bin.d.ts +0 -35
- package/node_modules/resume-from/dist/bin.js +0 -135
- package/node_modules/resume-from/dist/contract.d.ts +0 -10
- package/node_modules/resume-from/dist/contract.js +0 -4
- package/node_modules/resume-from/dist/host/agents.d.ts +0 -29
- package/node_modules/resume-from/dist/host/agents.js +0 -20
- package/node_modules/resume-from/dist/host/cli/args.d.ts +0 -21
- package/node_modules/resume-from/dist/host/cli/args.js +0 -187
- package/node_modules/resume-from/dist/host/cli/contract.d.ts +0 -27
- package/node_modules/resume-from/dist/host/cli/contract.js +0 -4
- package/node_modules/resume-from/dist/host/cli/index.d.ts +0 -2
- package/node_modules/resume-from/dist/host/cli/index.js +0 -1
- package/node_modules/resume-from/dist/host/cli/presentation.d.ts +0 -2
- package/node_modules/resume-from/dist/host/cli/presentation.js +0 -11
- package/node_modules/resume-from/dist/host/cli/render.d.ts +0 -3
- package/node_modules/resume-from/dist/host/cli/render.js +0 -70
- package/node_modules/resume-from/dist/host/cli/runner.d.ts +0 -8
- package/node_modules/resume-from/dist/host/cli/runner.js +0 -125
- package/node_modules/resume-from/dist/host/contract.d.ts +0 -42
- package/node_modules/resume-from/dist/host/contract.js +0 -4
- package/node_modules/resume-from/dist/host/entry.d.ts +0 -52
- package/node_modules/resume-from/dist/host/entry.js +0 -91
- package/node_modules/resume-from/dist/host/index.d.ts +0 -11
- package/node_modules/resume-from/dist/host/index.js +0 -10
- package/node_modules/resume-from/dist/host/pi-extension/command.d.ts +0 -18
- package/node_modules/resume-from/dist/host/pi-extension/command.js +0 -126
- package/node_modules/resume-from/dist/host/pi-extension/contract.d.ts +0 -34
- package/node_modules/resume-from/dist/host/pi-extension/contract.js +0 -4
- package/node_modules/resume-from/dist/host/pi-extension/index.d.ts +0 -6
- package/node_modules/resume-from/dist/host/pi-extension/index.js +0 -4
- package/node_modules/resume-from/dist/host/pi-extension/picker.d.ts +0 -16
- package/node_modules/resume-from/dist/host/pi-extension/picker.js +0 -35
- package/node_modules/resume-from/dist/host/pi-extension/presentation.d.ts +0 -2
- package/node_modules/resume-from/dist/host/pi-extension/presentation.js +0 -11
- package/node_modules/resume-from/dist/host/pi-extension/register.d.ts +0 -25
- package/node_modules/resume-from/dist/host/pi-extension/register.js +0 -11
- package/node_modules/resume-from/dist/host/pi-extension/ui.d.ts +0 -20
- package/node_modules/resume-from/dist/host/pi-extension/ui.js +0 -1
- package/node_modules/resume-from/dist/host/profile.d.ts +0 -8
- package/node_modules/resume-from/dist/host/profile.js +0 -31
- package/node_modules/resume-from/dist/host/registry.d.ts +0 -8
- package/node_modules/resume-from/dist/host/registry.js +0 -33
- package/node_modules/resume-from/dist/host/wiring.d.ts +0 -41
- package/node_modules/resume-from/dist/host/wiring.js +0 -66
- package/node_modules/resume-from/dist/import/confirmation.d.ts +0 -9
- package/node_modules/resume-from/dist/import/confirmation.js +0 -27
- package/node_modules/resume-from/dist/import/contract.d.ts +0 -43
- package/node_modules/resume-from/dist/import/contract.js +0 -4
- package/node_modules/resume-from/dist/import/discovery/contract.d.ts +0 -63
- package/node_modules/resume-from/dist/import/discovery/contract.js +0 -4
- package/node_modules/resume-from/dist/import/discovery/errors.d.ts +0 -9
- package/node_modules/resume-from/dist/import/discovery/errors.js +0 -12
- package/node_modules/resume-from/dist/import/discovery/finder.d.ts +0 -11
- package/node_modules/resume-from/dist/import/discovery/finder.js +0 -269
- package/node_modules/resume-from/dist/import/discovery/homes.d.ts +0 -23
- package/node_modules/resume-from/dist/import/discovery/homes.js +0 -83
- package/node_modules/resume-from/dist/import/discovery/index.d.ts +0 -2
- package/node_modules/resume-from/dist/import/discovery/index.js +0 -2
- package/node_modules/resume-from/dist/import/discovery/ordering.d.ts +0 -3
- package/node_modules/resume-from/dist/import/discovery/ordering.js +0 -21
- package/node_modules/resume-from/dist/import/errors.d.ts +0 -22
- package/node_modules/resume-from/dist/import/errors.js +0 -20
- package/node_modules/resume-from/dist/import/index.d.ts +0 -3
- package/node_modules/resume-from/dist/import/index.js +0 -5
- package/node_modules/resume-from/dist/import/landing/contract.d.ts +0 -44
- package/node_modules/resume-from/dist/import/landing/contract.js +0 -4
- package/node_modules/resume-from/dist/import/landing/errors.d.ts +0 -15
- package/node_modules/resume-from/dist/import/landing/errors.js +0 -15
- package/node_modules/resume-from/dist/import/landing/handover.d.ts +0 -5
- package/node_modules/resume-from/dist/import/landing/handover.js +0 -12
- package/node_modules/resume-from/dist/import/landing/index.d.ts +0 -4
- package/node_modules/resume-from/dist/import/landing/index.js +0 -4
- package/node_modules/resume-from/dist/import/landing/lander.d.ts +0 -7
- package/node_modules/resume-from/dist/import/landing/lander.js +0 -133
- package/node_modules/resume-from/dist/import/landing/marker.d.ts +0 -9
- package/node_modules/resume-from/dist/import/landing/marker.js +0 -46
- package/node_modules/resume-from/dist/import/pipeline.d.ts +0 -28
- package/node_modules/resume-from/dist/import/pipeline.js +0 -154
- package/node_modules/resume-from/dist/import/preview/builder.d.ts +0 -6
- package/node_modules/resume-from/dist/import/preview/builder.js +0 -80
- package/node_modules/resume-from/dist/import/preview/contract.d.ts +0 -39
- package/node_modules/resume-from/dist/import/preview/contract.js +0 -4
- package/node_modules/resume-from/dist/import/preview/format.d.ts +0 -19
- package/node_modules/resume-from/dist/import/preview/format.js +0 -45
- package/node_modules/resume-from/dist/import/preview/index.d.ts +0 -2
- package/node_modules/resume-from/dist/import/preview/index.js +0 -1
- package/node_modules/resume-from/dist/import/preview/warnings.d.ts +0 -14
- package/node_modules/resume-from/dist/import/preview/warnings.js +0 -86
- package/node_modules/resume-from/dist/import/transfer/contract.d.ts +0 -48
- package/node_modules/resume-from/dist/import/transfer/contract.js +0 -4
- package/node_modules/resume-from/dist/import/transfer/index.d.ts +0 -2
- package/node_modules/resume-from/dist/import/transfer/index.js +0 -1
- package/node_modules/resume-from/dist/import/transfer/rules.d.ts +0 -3
- package/node_modules/resume-from/dist/import/transfer/rules.js +0 -228
- package/node_modules/resume-from/dist/import/wiring.d.ts +0 -24
- package/node_modules/resume-from/dist/import/wiring.js +0 -37
- package/node_modules/resume-from/dist/index.d.ts +0 -36
- package/node_modules/resume-from/dist/index.js +0 -36
- package/node_modules/resume-from/dist/platform/config/contract.d.ts +0 -35
- package/node_modules/resume-from/dist/platform/config/contract.js +0 -4
- package/node_modules/resume-from/dist/platform/config/defaults.d.ts +0 -16
- package/node_modules/resume-from/dist/platform/config/defaults.js +0 -22
- package/node_modules/resume-from/dist/platform/config/errors.d.ts +0 -9
- package/node_modules/resume-from/dist/platform/config/errors.js +0 -12
- package/node_modules/resume-from/dist/platform/config/index.d.ts +0 -5
- package/node_modules/resume-from/dist/platform/config/index.js +0 -6
- package/node_modules/resume-from/dist/platform/config/loader.d.ts +0 -10
- package/node_modules/resume-from/dist/platform/config/loader.js +0 -47
- package/node_modules/resume-from/dist/platform/config/paths.d.ts +0 -13
- package/node_modules/resume-from/dist/platform/config/paths.js +0 -37
- package/node_modules/resume-from/dist/platform/config/validate.d.ts +0 -9
- package/node_modules/resume-from/dist/platform/config/validate.js +0 -117
- package/node_modules/resume-from/dist/platform/repo/contract.d.ts +0 -36
- package/node_modules/resume-from/dist/platform/repo/contract.js +0 -4
- package/node_modules/resume-from/dist/platform/repo/git.d.ts +0 -21
- package/node_modules/resume-from/dist/platform/repo/git.js +0 -77
- package/node_modules/resume-from/dist/platform/repo/index.d.ts +0 -2
- package/node_modules/resume-from/dist/platform/repo/index.js +0 -1
- package/node_modules/resume-from/dist/platform/repo/reader.d.ts +0 -3
- package/node_modules/resume-from/dist/platform/repo/reader.js +0 -170
- package/node_modules/resume-from/dist/platform/store/contract.d.ts +0 -31
- package/node_modules/resume-from/dist/platform/store/contract.js +0 -4
- package/node_modules/resume-from/dist/platform/store/file-committer.d.ts +0 -3
- package/node_modules/resume-from/dist/platform/store/file-committer.js +0 -391
- package/node_modules/resume-from/dist/platform/store/index.d.ts +0 -2
- package/node_modules/resume-from/dist/platform/store/index.js +0 -2
- package/node_modules/resume-from/dist/platform/tokens/contract.d.ts +0 -12
- package/node_modules/resume-from/dist/platform/tokens/contract.js +0 -4
- package/node_modules/resume-from/dist/platform/tokens/estimator.d.ts +0 -12
- package/node_modules/resume-from/dist/platform/tokens/estimator.js +0 -111
- package/node_modules/resume-from/dist/platform/tokens/index.d.ts +0 -2
- package/node_modules/resume-from/dist/platform/tokens/index.js +0 -1
- package/node_modules/resume-from/dist/session/contract.d.ts +0 -116
- package/node_modules/resume-from/dist/session/contract.js +0 -4
- package/node_modules/resume-from/package.json +0 -83
- package/node_modules/resume-from/shims/pi/extensions/resume-from.js +0 -118
|
@@ -943,6 +943,16 @@ function getVersionedApiBase() {
|
|
|
943
943
|
function getUploadBase() {
|
|
944
944
|
return `${getApiHost()}/upload/${API_VERSION}`;
|
|
945
945
|
}
|
|
946
|
+
function rewriteUploadUrlOrigin(url) {
|
|
947
|
+
try {
|
|
948
|
+
const parsed = new URL(url);
|
|
949
|
+
const base = getApiHost();
|
|
950
|
+
if (parsed.origin === new URL(base).origin) return url;
|
|
951
|
+
return `${base}${parsed.pathname}${parsed.search}`;
|
|
952
|
+
} catch {
|
|
953
|
+
return url;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
946
956
|
function getLegacyCloudflareApiKey() {
|
|
947
957
|
return normalizeApiKey(process.env.CLOUDFLARE_API_KEY) ?? normalizeApiKey(loadConfig2().cloudflareApiKey);
|
|
948
958
|
}
|
|
@@ -2180,6 +2190,9 @@ async function postPerplexity(url, body, options) {
|
|
|
2180
2190
|
windowMs: RATE_LIMIT.windowMs
|
|
2181
2191
|
});
|
|
2182
2192
|
const apiKey = await getApiKey2(options.signal);
|
|
2193
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS);
|
|
2194
|
+
const timedOut = () => timeout.aborted && !options.signal?.aborted;
|
|
2195
|
+
const timeoutError = () => new Error("Perplexity API error 408: request timed out");
|
|
2183
2196
|
let response;
|
|
2184
2197
|
try {
|
|
2185
2198
|
response = await fetch(url, {
|
|
@@ -2189,9 +2202,13 @@ async function postPerplexity(url, body, options) {
|
|
|
2189
2202
|
"Content-Type": "application/json"
|
|
2190
2203
|
},
|
|
2191
2204
|
body: JSON.stringify(body),
|
|
2192
|
-
|
|
2205
|
+
signal: options.signal ? AbortSignal.any([options.signal, timeout]) : timeout
|
|
2193
2206
|
});
|
|
2194
2207
|
} catch (err) {
|
|
2208
|
+
if (timedOut()) {
|
|
2209
|
+
activityMonitor.logError(activityId, "request timed out");
|
|
2210
|
+
throw timeoutError();
|
|
2211
|
+
}
|
|
2195
2212
|
const message = err instanceof Error ? err.message : String(err);
|
|
2196
2213
|
const redactedMessage = redactCredential(message, apiKey);
|
|
2197
2214
|
if (redactedMessage.toLowerCase().includes("abort")) {
|
|
@@ -2206,12 +2223,19 @@ async function postPerplexity(url, body, options) {
|
|
|
2206
2223
|
}
|
|
2207
2224
|
activityMonitor.logComplete(activityId, response.status);
|
|
2208
2225
|
if (!response.ok) {
|
|
2209
|
-
|
|
2226
|
+
let errorText;
|
|
2227
|
+
try {
|
|
2228
|
+
errorText = redactCredential(await response.text(), apiKey);
|
|
2229
|
+
} catch (err) {
|
|
2230
|
+
if (timedOut()) throw timeoutError();
|
|
2231
|
+
throw err;
|
|
2232
|
+
}
|
|
2210
2233
|
throw new Error(`Perplexity API error ${response.status}: ${errorText}`);
|
|
2211
2234
|
}
|
|
2212
2235
|
try {
|
|
2213
2236
|
return await response.json();
|
|
2214
2237
|
} catch (err) {
|
|
2238
|
+
if (timedOut()) throw timeoutError();
|
|
2215
2239
|
const message = err instanceof Error ? err.message : String(err);
|
|
2216
2240
|
throw new Error(`Perplexity API returned invalid JSON: ${message}`);
|
|
2217
2241
|
}
|
|
@@ -2256,7 +2280,7 @@ async function askPerplexity(prompt, options = {}) {
|
|
|
2256
2280
|
const content = data.choices?.[0]?.message?.content;
|
|
2257
2281
|
return typeof content === "string" ? content : "";
|
|
2258
2282
|
}
|
|
2259
|
-
var PERPLEXITY_SEARCH_URL, PERPLEXITY_CHAT_URL, CONFIG_PATH4, RATE_LIMIT, requestTimestamps, cachedConfig4;
|
|
2283
|
+
var PERPLEXITY_SEARCH_URL, PERPLEXITY_CHAT_URL, CONFIG_PATH4, SEARCH_TIMEOUT_MS, RATE_LIMIT, requestTimestamps, cachedConfig4;
|
|
2260
2284
|
var init_perplexity = __esm({
|
|
2261
2285
|
"perplexity.ts"() {
|
|
2262
2286
|
init_activity();
|
|
@@ -2266,6 +2290,7 @@ var init_perplexity = __esm({
|
|
|
2266
2290
|
PERPLEXITY_SEARCH_URL = "https://api.perplexity.ai/search";
|
|
2267
2291
|
PERPLEXITY_CHAT_URL = "https://api.perplexity.ai/chat/completions";
|
|
2268
2292
|
CONFIG_PATH4 = getWebSearchConfigPath();
|
|
2293
|
+
SEARCH_TIMEOUT_MS = 3e4;
|
|
2269
2294
|
RATE_LIMIT = {
|
|
2270
2295
|
maxRequests: 10,
|
|
2271
2296
|
windowMs: 60 * 1e3
|
|
@@ -2378,7 +2403,7 @@ function isParallelAvailable() {
|
|
|
2378
2403
|
return hasParallelApiKey();
|
|
2379
2404
|
}
|
|
2380
2405
|
function requestSignal2(signal) {
|
|
2381
|
-
const timeout = AbortSignal.timeout(
|
|
2406
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS4);
|
|
2382
2407
|
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
2383
2408
|
}
|
|
2384
2409
|
function errorMessage(err) {
|
|
@@ -2572,7 +2597,7 @@ async function parallelFetch(url, body, signal) {
|
|
|
2572
2597
|
throw new Error(`Parallel API returned invalid JSON: ${errorMessage(err)}`);
|
|
2573
2598
|
}
|
|
2574
2599
|
}
|
|
2575
|
-
var PARALLEL_SEARCH_URL, PARALLEL_EXTRACT_URL, CONFIG_PATH8, MIN_PARALLEL_API_KEY_LENGTH, MIN_USEFUL_CONTENT,
|
|
2600
|
+
var PARALLEL_SEARCH_URL, PARALLEL_EXTRACT_URL, CONFIG_PATH8, MIN_PARALLEL_API_KEY_LENGTH, MIN_USEFUL_CONTENT, SEARCH_TIMEOUT_MS4, PLACEHOLDER_API_KEY_DENYLIST, cachedConfig8;
|
|
2576
2601
|
var init_parallel = __esm({
|
|
2577
2602
|
"parallel.ts"() {
|
|
2578
2603
|
init_activity();
|
|
@@ -2584,7 +2609,7 @@ var init_parallel = __esm({
|
|
|
2584
2609
|
CONFIG_PATH8 = getWebSearchConfigPath();
|
|
2585
2610
|
MIN_PARALLEL_API_KEY_LENGTH = 8;
|
|
2586
2611
|
MIN_USEFUL_CONTENT = 500;
|
|
2587
|
-
|
|
2612
|
+
SEARCH_TIMEOUT_MS4 = 6e4;
|
|
2588
2613
|
PLACEHOLDER_API_KEY_DENYLIST = /* @__PURE__ */ new Set([
|
|
2589
2614
|
"replace_with_your_parallel_api_key",
|
|
2590
2615
|
"parallel_api_key",
|
|
@@ -3014,7 +3039,7 @@ async function searchWithTinyFish(query, options = {}) {
|
|
|
3014
3039
|
buildSearchUrl(query, options, page),
|
|
3015
3040
|
apiKey,
|
|
3016
3041
|
{ method: "GET" },
|
|
3017
|
-
|
|
3042
|
+
SEARCH_TIMEOUT_MS5,
|
|
3018
3043
|
options.signal
|
|
3019
3044
|
);
|
|
3020
3045
|
if (!Array.isArray(data.results)) throw new Error("TinyFish Search API returned an unexpected response shape");
|
|
@@ -3072,7 +3097,7 @@ async function extractWithTinyFish(url, signal, options = {}) {
|
|
|
3072
3097
|
throw redactedError;
|
|
3073
3098
|
}
|
|
3074
3099
|
}
|
|
3075
|
-
var TINYFISH_SEARCH_URL, TINYFISH_FETCH_URL, CONFIG_PATH10,
|
|
3100
|
+
var TINYFISH_SEARCH_URL, TINYFISH_FETCH_URL, CONFIG_PATH10, SEARCH_TIMEOUT_MS5, FETCH_TIMEOUT_MS, MAX_FETCH_URLS, MAX_FETCH_PER_URL_TIMEOUT_MS, cachedConfig9;
|
|
3076
3101
|
var init_tinyfish = __esm({
|
|
3077
3102
|
"tinyfish.ts"() {
|
|
3078
3103
|
init_activity();
|
|
@@ -3084,7 +3109,7 @@ var init_tinyfish = __esm({
|
|
|
3084
3109
|
TINYFISH_SEARCH_URL = "https://api.search.tinyfish.ai";
|
|
3085
3110
|
TINYFISH_FETCH_URL = "https://api.fetch.tinyfish.ai";
|
|
3086
3111
|
CONFIG_PATH10 = getWebSearchConfigPath();
|
|
3087
|
-
|
|
3112
|
+
SEARCH_TIMEOUT_MS5 = 6e4;
|
|
3088
3113
|
FETCH_TIMEOUT_MS = 15e4;
|
|
3089
3114
|
MAX_FETCH_URLS = 10;
|
|
3090
3115
|
MAX_FETCH_PER_URL_TIMEOUT_MS = 11e4;
|
|
@@ -3234,7 +3259,7 @@ async function searchWithSearch1API(query, options = {}) {
|
|
|
3234
3259
|
SEARCH1API_SEARCH_URL,
|
|
3235
3260
|
apiKey,
|
|
3236
3261
|
buildSearchBody(query, options),
|
|
3237
|
-
|
|
3262
|
+
SEARCH_TIMEOUT_MS6,
|
|
3238
3263
|
options.signal
|
|
3239
3264
|
);
|
|
3240
3265
|
const results = mapSearchResults3(data.results);
|
|
@@ -3295,7 +3320,7 @@ async function extractWithSearch1API(url, signal, options = {}) {
|
|
|
3295
3320
|
throw redactedError;
|
|
3296
3321
|
}
|
|
3297
3322
|
}
|
|
3298
|
-
var SEARCH1API_SEARCH_URL, SEARCH1API_CRAWL_URL, CONFIG_PATH11,
|
|
3323
|
+
var SEARCH1API_SEARCH_URL, SEARCH1API_CRAWL_URL, CONFIG_PATH11, SEARCH_TIMEOUT_MS6, CRAWL_TIMEOUT_MS, cachedConfig10;
|
|
3299
3324
|
var init_search1api = __esm({
|
|
3300
3325
|
"search1api.ts"() {
|
|
3301
3326
|
init_activity();
|
|
@@ -3307,7 +3332,7 @@ var init_search1api = __esm({
|
|
|
3307
3332
|
SEARCH1API_SEARCH_URL = "https://api.search1api.com/search";
|
|
3308
3333
|
SEARCH1API_CRAWL_URL = "https://api.search1api.com/crawl";
|
|
3309
3334
|
CONFIG_PATH11 = getWebSearchConfigPath();
|
|
3310
|
-
|
|
3335
|
+
SEARCH_TIMEOUT_MS6 = 6e4;
|
|
3311
3336
|
CRAWL_TIMEOUT_MS = 6e4;
|
|
3312
3337
|
cachedConfig10 = null;
|
|
3313
3338
|
}
|
|
@@ -3537,7 +3562,7 @@ async function searchWithQuerit(query, options = {}) {
|
|
|
3537
3562
|
QUERIT_SEARCH_URL,
|
|
3538
3563
|
apiKey,
|
|
3539
3564
|
buildSearchBody3(query, options),
|
|
3540
|
-
|
|
3565
|
+
SEARCH_TIMEOUT_MS8,
|
|
3541
3566
|
options.signal
|
|
3542
3567
|
);
|
|
3543
3568
|
assertApiSuccess("Search", data);
|
|
@@ -3587,7 +3612,7 @@ async function extractWithQuerit(url, signal, options = {}) {
|
|
|
3587
3612
|
throw redactedError;
|
|
3588
3613
|
}
|
|
3589
3614
|
}
|
|
3590
|
-
var QUERIT_SEARCH_URL, QUERIT_CONTENTS_URL, CONFIG_PATH13,
|
|
3615
|
+
var QUERIT_SEARCH_URL, QUERIT_CONTENTS_URL, CONFIG_PATH13, SEARCH_TIMEOUT_MS8, CONTENTS_TIMEOUT_MS, MAX_CONTENT_URLS, cachedConfig12;
|
|
3591
3616
|
var init_querit = __esm({
|
|
3592
3617
|
"querit.ts"() {
|
|
3593
3618
|
init_activity();
|
|
@@ -3599,7 +3624,7 @@ var init_querit = __esm({
|
|
|
3599
3624
|
QUERIT_SEARCH_URL = "https://api.querit.ai/v1/search";
|
|
3600
3625
|
QUERIT_CONTENTS_URL = "https://api.querit.ai/v1/contents";
|
|
3601
3626
|
CONFIG_PATH13 = getWebSearchConfigPath();
|
|
3602
|
-
|
|
3627
|
+
SEARCH_TIMEOUT_MS8 = 6e4;
|
|
3603
3628
|
CONTENTS_TIMEOUT_MS = 6e4;
|
|
3604
3629
|
MAX_CONTENT_URLS = 10;
|
|
3605
3630
|
cachedConfig12 = null;
|
|
@@ -3637,15 +3662,26 @@ function loadConfigRoot() {
|
|
|
3637
3662
|
cachedConfigRoot = { signature, value };
|
|
3638
3663
|
return value;
|
|
3639
3664
|
}
|
|
3640
|
-
function
|
|
3665
|
+
function loadFetchContentConfig() {
|
|
3641
3666
|
const parsed = loadConfigRoot();
|
|
3642
|
-
if (!parsed) return
|
|
3667
|
+
if (!parsed) return void 0;
|
|
3643
3668
|
const fetchContent = parsed.fetchContent;
|
|
3644
|
-
if (fetchContent === void 0 || fetchContent === null) return
|
|
3669
|
+
if (fetchContent === void 0 || fetchContent === null) return void 0;
|
|
3645
3670
|
if (typeof fetchContent !== "object" || Array.isArray(fetchContent)) {
|
|
3646
3671
|
throw new Error(`fetchContent in ${WEB_SEARCH_CONFIG_PATH} must be an object`);
|
|
3647
3672
|
}
|
|
3648
|
-
|
|
3673
|
+
return fetchContent;
|
|
3674
|
+
}
|
|
3675
|
+
function loadFetchContentRedirectPolicy() {
|
|
3676
|
+
const redirects = loadFetchContentConfig()?.redirects;
|
|
3677
|
+
if (redirects === void 0 || redirects === null) return void 0;
|
|
3678
|
+
if (redirects !== "same-origin") {
|
|
3679
|
+
throw new Error(`fetchContent.redirects in ${WEB_SEARCH_CONFIG_PATH} must be "same-origin"`);
|
|
3680
|
+
}
|
|
3681
|
+
return redirects;
|
|
3682
|
+
}
|
|
3683
|
+
function loadFetchContentDomainPolicy() {
|
|
3684
|
+
const policy = loadFetchContentConfig()?.domainPolicy;
|
|
3649
3685
|
if (policy === void 0 || policy === null) return { ...DEFAULT_DOMAIN_POLICY };
|
|
3650
3686
|
if (typeof policy !== "object" || Array.isArray(policy)) {
|
|
3651
3687
|
throw new Error(`fetchContent.domainPolicy in ${WEB_SEARCH_CONFIG_PATH} must be an object`);
|
|
@@ -3759,6 +3795,9 @@ async function fetchRemoteUrl(url, init = {}, options = {}) {
|
|
|
3759
3795
|
if (redirects === maxRedirects) throw new Error(`Too many redirects fetching ${current.toString()}`);
|
|
3760
3796
|
const from = current;
|
|
3761
3797
|
const next = new URL(location, current);
|
|
3798
|
+
if (options.redirects === "same-origin" && next.origin !== configuredOrigin) {
|
|
3799
|
+
throw new Error(`Refused cross-origin redirect by fetch_content redirect policy: ${configuredOrigin} -> ${next.origin}`);
|
|
3800
|
+
}
|
|
3762
3801
|
current = await validateRemoteUrl(next, next.origin === configuredOrigin ? options : { ...options, allowLoopback: false });
|
|
3763
3802
|
if (response.status === 303 || (response.status === 301 || response.status === 302) && requestInit.method?.toUpperCase() === "POST") {
|
|
3764
3803
|
const { body: _body, ...nextInit } = requestInit;
|
|
@@ -4300,7 +4339,7 @@ async function searchWithFirecrawl(query, options = {}) {
|
|
|
4300
4339
|
"search",
|
|
4301
4340
|
searchBody(query, options, numResults, filters),
|
|
4302
4341
|
options.signal,
|
|
4303
|
-
{ ...options, timeoutMs: options.timeoutMs ??
|
|
4342
|
+
{ ...options, timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS11 },
|
|
4304
4343
|
"search",
|
|
4305
4344
|
{ type: "api", query }
|
|
4306
4345
|
);
|
|
@@ -4327,7 +4366,7 @@ async function extractWithFirecrawl(url, signal, options) {
|
|
|
4327
4366
|
const title = typeof metadataTitle === "string" && metadataTitle.trim() ? metadataTitle.trim() : typeof scrape.title === "string" ? scrape.title.trim() : "";
|
|
4328
4367
|
return { url, title, content: withPdfTruncationNotice(content, scrape.metadata), error: null };
|
|
4329
4368
|
}
|
|
4330
|
-
var CONFIG_PATH16, DEFAULT_API_VERSION, EXTRACT_TIMEOUT_MS,
|
|
4369
|
+
var CONFIG_PATH16, DEFAULT_API_VERSION, EXTRACT_TIMEOUT_MS, SEARCH_TIMEOUT_MS11, DEFAULT_MAX_REDIRECTS2, REDIRECT_STATUSES2, SUPPORTED_API_VERSIONS, cachedConfig15;
|
|
4331
4370
|
var init_firecrawl = __esm({
|
|
4332
4371
|
"firecrawl.ts"() {
|
|
4333
4372
|
init_activity();
|
|
@@ -4340,7 +4379,7 @@ var init_firecrawl = __esm({
|
|
|
4340
4379
|
CONFIG_PATH16 = getWebSearchConfigPath();
|
|
4341
4380
|
DEFAULT_API_VERSION = "v2";
|
|
4342
4381
|
EXTRACT_TIMEOUT_MS = 6e4;
|
|
4343
|
-
|
|
4382
|
+
SEARCH_TIMEOUT_MS11 = 6e4;
|
|
4344
4383
|
DEFAULT_MAX_REDIRECTS2 = 5;
|
|
4345
4384
|
REDIRECT_STATUSES2 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
4346
4385
|
SUPPORTED_API_VERSIONS = ["v1", "v2"];
|
|
@@ -4474,7 +4513,7 @@ async function searchWithKagi(query, options = {}) {
|
|
|
4474
4513
|
method: "POST",
|
|
4475
4514
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "application/json" },
|
|
4476
4515
|
body: JSON.stringify({ query, limit: numResults }),
|
|
4477
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
4516
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS14), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS14)
|
|
4478
4517
|
});
|
|
4479
4518
|
} catch (err) {
|
|
4480
4519
|
const message = errorMessage12(err);
|
|
@@ -4529,7 +4568,7 @@ async function extractWithKagi(url, signal, options = {}) {
|
|
|
4529
4568
|
method: "POST",
|
|
4530
4569
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "application/json" },
|
|
4531
4570
|
body: JSON.stringify({ pages: [{ url }] }),
|
|
4532
|
-
signal: signal ? AbortSignal.any([AbortSignal.timeout(options.timeoutMs ??
|
|
4571
|
+
signal: signal ? AbortSignal.any([AbortSignal.timeout(options.timeoutMs ?? SEARCH_TIMEOUT_MS14), signal]) : AbortSignal.timeout(options.timeoutMs ?? SEARCH_TIMEOUT_MS14)
|
|
4533
4572
|
}, {
|
|
4534
4573
|
allowRanges: ssrf.allowRanges,
|
|
4535
4574
|
trustEnvProxy: ssrf.trustEnvProxy,
|
|
@@ -4562,7 +4601,7 @@ async function extractWithKagi(url, signal, options = {}) {
|
|
|
4562
4601
|
activityMonitor.logComplete(activityId, response.status);
|
|
4563
4602
|
return parsed;
|
|
4564
4603
|
}
|
|
4565
|
-
var KAGI_SEARCH_URL, KAGI_EXTRACT_URL, CONFIG_PATH19,
|
|
4604
|
+
var KAGI_SEARCH_URL, KAGI_EXTRACT_URL, CONFIG_PATH19, SEARCH_TIMEOUT_MS14, cachedConfig18;
|
|
4566
4605
|
var init_kagi = __esm({
|
|
4567
4606
|
"kagi.ts"() {
|
|
4568
4607
|
init_activity();
|
|
@@ -4574,7 +4613,7 @@ var init_kagi = __esm({
|
|
|
4574
4613
|
KAGI_SEARCH_URL = "https://kagi.com/api/v1/search";
|
|
4575
4614
|
KAGI_EXTRACT_URL = "https://kagi.com/api/v1/extract";
|
|
4576
4615
|
CONFIG_PATH19 = getWebSearchConfigPath();
|
|
4577
|
-
|
|
4616
|
+
SEARCH_TIMEOUT_MS14 = 6e4;
|
|
4578
4617
|
cachedConfig18 = null;
|
|
4579
4618
|
}
|
|
4580
4619
|
});
|
|
@@ -4666,7 +4705,7 @@ async function searchWithOllama(query, options = {}) {
|
|
|
4666
4705
|
method: "POST",
|
|
4667
4706
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
4668
4707
|
body: JSON.stringify({ query, max_results: numResults }),
|
|
4669
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
4708
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS16), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS16)
|
|
4670
4709
|
});
|
|
4671
4710
|
} catch (err) {
|
|
4672
4711
|
const message = errorMessage14(err);
|
|
@@ -4720,7 +4759,7 @@ async function extractWithOllama(url, signal, options = {}) {
|
|
|
4720
4759
|
method: "POST",
|
|
4721
4760
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
4722
4761
|
body: JSON.stringify({ url }),
|
|
4723
|
-
signal: signal ? AbortSignal.any([AbortSignal.timeout(options.timeoutMs ??
|
|
4762
|
+
signal: signal ? AbortSignal.any([AbortSignal.timeout(options.timeoutMs ?? SEARCH_TIMEOUT_MS16), signal]) : AbortSignal.timeout(options.timeoutMs ?? SEARCH_TIMEOUT_MS16)
|
|
4724
4763
|
}, {
|
|
4725
4764
|
allowRanges: ssrf.allowRanges,
|
|
4726
4765
|
trustEnvProxy: ssrf.trustEnvProxy,
|
|
@@ -4755,7 +4794,7 @@ async function extractWithOllama(url, signal, options = {}) {
|
|
|
4755
4794
|
if (!content) return null;
|
|
4756
4795
|
return { url, title: data.title, content, error: null };
|
|
4757
4796
|
}
|
|
4758
|
-
var OLLAMA_SEARCH_URL, OLLAMA_FETCH_URL, CONFIG_PATH21,
|
|
4797
|
+
var OLLAMA_SEARCH_URL, OLLAMA_FETCH_URL, CONFIG_PATH21, SEARCH_TIMEOUT_MS16, cachedConfig20;
|
|
4759
4798
|
var init_ollama = __esm({
|
|
4760
4799
|
"ollama.ts"() {
|
|
4761
4800
|
init_activity();
|
|
@@ -4766,7 +4805,7 @@ var init_ollama = __esm({
|
|
|
4766
4805
|
OLLAMA_SEARCH_URL = "https://ollama.com/api/web_search";
|
|
4767
4806
|
OLLAMA_FETCH_URL = "https://ollama.com/api/web_fetch";
|
|
4768
4807
|
CONFIG_PATH21 = getWebSearchConfigPath();
|
|
4769
|
-
|
|
4808
|
+
SEARCH_TIMEOUT_MS16 = 6e4;
|
|
4770
4809
|
cachedConfig20 = null;
|
|
4771
4810
|
}
|
|
4772
4811
|
});
|
|
@@ -5600,6 +5639,181 @@ var init_datalab_pdf_extract = __esm({
|
|
|
5600
5639
|
}
|
|
5601
5640
|
});
|
|
5602
5641
|
|
|
5642
|
+
// endpoint-pdf-extract.ts
|
|
5643
|
+
import { existsSync as existsSync43, readFileSync as readFileSync45 } from "node:fs";
|
|
5644
|
+
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
5645
|
+
function pdfSection() {
|
|
5646
|
+
if (!existsSync43(CONFIG_PATH40)) return {};
|
|
5647
|
+
let parsed;
|
|
5648
|
+
try {
|
|
5649
|
+
parsed = JSON.parse(readFileSync45(CONFIG_PATH40, "utf-8"));
|
|
5650
|
+
} catch (err) {
|
|
5651
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
5652
|
+
throw new Error(`Failed to parse ${CONFIG_PATH40}: ${message}`);
|
|
5653
|
+
}
|
|
5654
|
+
const pdf = parsed?.pdf;
|
|
5655
|
+
return pdf && typeof pdf === "object" ? pdf : {};
|
|
5656
|
+
}
|
|
5657
|
+
function normalizeString2(value) {
|
|
5658
|
+
if (typeof value !== "string") return null;
|
|
5659
|
+
const normalized = value.trim();
|
|
5660
|
+
return normalized.length > 0 ? normalized : null;
|
|
5661
|
+
}
|
|
5662
|
+
function getEndpointUrl() {
|
|
5663
|
+
const configured = normalizeString2(process.env.PDF_ENDPOINT_URL) ?? normalizeString2(pdfSection().endpointUrl);
|
|
5664
|
+
if (!configured) return null;
|
|
5665
|
+
const protocol = URL.parse(configured)?.protocol;
|
|
5666
|
+
if (protocol !== "http:" && protocol !== "https:") {
|
|
5667
|
+
throw new Error(
|
|
5668
|
+
`Failed to parse pdf.endpointUrl: expected an absolute http(s) URL, got "${configured}"`
|
|
5669
|
+
);
|
|
5670
|
+
}
|
|
5671
|
+
return configured.replace(/\/+$/, "");
|
|
5672
|
+
}
|
|
5673
|
+
function getEndpointTimeoutMs() {
|
|
5674
|
+
const configured = pdfSection().endpointTimeoutMs;
|
|
5675
|
+
if (typeof configured === "number" && Number.isFinite(configured) && configured > 0) {
|
|
5676
|
+
return Math.min(configured, 3e5);
|
|
5677
|
+
}
|
|
5678
|
+
return DEFAULT_TIMEOUT_MS2;
|
|
5679
|
+
}
|
|
5680
|
+
function isEndpointApiAvailable() {
|
|
5681
|
+
try {
|
|
5682
|
+
return getEndpointUrl() !== null;
|
|
5683
|
+
} catch {
|
|
5684
|
+
return true;
|
|
5685
|
+
}
|
|
5686
|
+
}
|
|
5687
|
+
async function readCapped(response, maxBytes, overflowThrows) {
|
|
5688
|
+
const reader = response.body?.getReader();
|
|
5689
|
+
if (!reader) return "";
|
|
5690
|
+
const decoder = new TextDecoder();
|
|
5691
|
+
let text4 = "";
|
|
5692
|
+
let received = 0;
|
|
5693
|
+
for (; ; ) {
|
|
5694
|
+
const { done, value } = await reader.read();
|
|
5695
|
+
if (done) return text4 + decoder.decode();
|
|
5696
|
+
const room = maxBytes - received;
|
|
5697
|
+
received += value.byteLength;
|
|
5698
|
+
if (received >= maxBytes) {
|
|
5699
|
+
await reader.cancel();
|
|
5700
|
+
if (overflowThrows && received > maxBytes) {
|
|
5701
|
+
throw new Error("PDF parser endpoint returned an oversized response");
|
|
5702
|
+
}
|
|
5703
|
+
return text4 + decoder.decode(value.subarray(0, room));
|
|
5704
|
+
}
|
|
5705
|
+
text4 += decoder.decode(value, { stream: true });
|
|
5706
|
+
}
|
|
5707
|
+
}
|
|
5708
|
+
async function readJson(response) {
|
|
5709
|
+
const text4 = await readCapped(response, MAX_RESPONSE_BYTES2, true);
|
|
5710
|
+
try {
|
|
5711
|
+
const parsed = JSON.parse(text4);
|
|
5712
|
+
if (parsed && typeof parsed === "object") return parsed;
|
|
5713
|
+
} catch {
|
|
5714
|
+
}
|
|
5715
|
+
throw new Error("PDF parser endpoint returned a non-JSON response");
|
|
5716
|
+
}
|
|
5717
|
+
async function errorBody(response) {
|
|
5718
|
+
try {
|
|
5719
|
+
const text4 = await readCapped(response, MAX_ERROR_BODY_BYTES2, false);
|
|
5720
|
+
return text4 ? `: ${text4}` : "";
|
|
5721
|
+
} catch {
|
|
5722
|
+
return "";
|
|
5723
|
+
}
|
|
5724
|
+
}
|
|
5725
|
+
function markdownResult(payload) {
|
|
5726
|
+
const markdown = typeof payload.markdown === "string" ? payload.markdown.replaceAll("\0", "") : "";
|
|
5727
|
+
if (markdown.trim().length === 0) {
|
|
5728
|
+
const error = normalizeString2(payload.error);
|
|
5729
|
+
throw new Error(
|
|
5730
|
+
error ? `PDF parser endpoint failed: ${error}` : "PDF parser endpoint returned no markdown"
|
|
5731
|
+
);
|
|
5732
|
+
}
|
|
5733
|
+
return { markdown, pages: typeof payload.pages === "number" ? payload.pages : void 0 };
|
|
5734
|
+
}
|
|
5735
|
+
async function extractPDFViaEndpoint(buffer, options) {
|
|
5736
|
+
options.signal?.throwIfAborted();
|
|
5737
|
+
const endpointUrl2 = getEndpointUrl();
|
|
5738
|
+
if (!endpointUrl2) {
|
|
5739
|
+
throw new Error("PDF endpoint extraction requires a configured pdf.endpointUrl");
|
|
5740
|
+
}
|
|
5741
|
+
const ssrf = loadSsrfConfig();
|
|
5742
|
+
const guard = {
|
|
5743
|
+
allowRanges: ssrf.allowRanges,
|
|
5744
|
+
trustEnvProxy: ssrf.trustEnvProxy,
|
|
5745
|
+
allowLoopback: isLoopbackHostname(new URL(endpointUrl2).hostname),
|
|
5746
|
+
...options.lookup ? { lookup: options.lookup } : {}
|
|
5747
|
+
};
|
|
5748
|
+
const engine = normalizeString2(pdfSection().endpointEngine);
|
|
5749
|
+
const form = new FormData();
|
|
5750
|
+
form.append("file", new Blob([buffer], { type: "application/pdf" }), "document.pdf");
|
|
5751
|
+
if (engine) form.append("engine", engine);
|
|
5752
|
+
form.append("max_pages", String(options.maxPages));
|
|
5753
|
+
const timeoutMs = options.timeoutMs ?? getEndpointTimeoutMs();
|
|
5754
|
+
const deadline = Date.now() + timeoutMs;
|
|
5755
|
+
const signal = options.signal;
|
|
5756
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
5757
|
+
const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
5758
|
+
const response = await fetchRemoteUrl(
|
|
5759
|
+
endpointUrl2,
|
|
5760
|
+
{ method: "POST", body: form, signal: combined },
|
|
5761
|
+
guard
|
|
5762
|
+
);
|
|
5763
|
+
if (!response.ok) {
|
|
5764
|
+
throw new Error(
|
|
5765
|
+
`PDF parser endpoint returned HTTP ${response.status}${await errorBody(response)}`
|
|
5766
|
+
);
|
|
5767
|
+
}
|
|
5768
|
+
let payload = await readJson(response);
|
|
5769
|
+
const jobId = normalizeString2(payload.job_id);
|
|
5770
|
+
if (typeof payload.markdown === "string" || !jobId) {
|
|
5771
|
+
return markdownResult(payload);
|
|
5772
|
+
}
|
|
5773
|
+
const jobsUrl = new URL(`jobs/${encodeURIComponent(jobId)}`, endpointUrl2).toString();
|
|
5774
|
+
for (let interval = 1e3; Date.now() < deadline; interval = Math.min(interval * 2, MAX_POLL_INTERVAL_MS)) {
|
|
5775
|
+
await sleep2(Math.min(interval, deadline - Date.now()), void 0, { signal });
|
|
5776
|
+
const poll = await fetchRemoteUrl(jobsUrl, { signal: combined }, guard);
|
|
5777
|
+
if (!poll.ok) {
|
|
5778
|
+
throw new Error(
|
|
5779
|
+
`PDF parser job status returned HTTP ${poll.status}${await errorBody(poll)}`
|
|
5780
|
+
);
|
|
5781
|
+
}
|
|
5782
|
+
payload = await readJson(poll);
|
|
5783
|
+
const status = normalizeString2(payload.status)?.toLowerCase();
|
|
5784
|
+
if (status === "error" || status === "failed") {
|
|
5785
|
+
const error = normalizeString2(payload.error) ?? "unknown parser error";
|
|
5786
|
+
throw new Error(`PDF parser endpoint job failed: ${error}`);
|
|
5787
|
+
}
|
|
5788
|
+
if (status === "done") {
|
|
5789
|
+
let result = payload.result;
|
|
5790
|
+
if (typeof result === "string") {
|
|
5791
|
+
const raw = result;
|
|
5792
|
+
try {
|
|
5793
|
+
result = JSON.parse(raw);
|
|
5794
|
+
} catch {
|
|
5795
|
+
return { markdown: raw.replaceAll("\0", "") };
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
if (result && typeof result === "object") return markdownResult(result);
|
|
5799
|
+
throw new Error("PDF parser endpoint job completed without a result");
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5802
|
+
throw new Error("PDF parser endpoint job timed out");
|
|
5803
|
+
}
|
|
5804
|
+
var DEFAULT_TIMEOUT_MS2, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2, CONFIG_PATH40;
|
|
5805
|
+
var init_endpoint_pdf_extract = __esm({
|
|
5806
|
+
"endpoint-pdf-extract.ts"() {
|
|
5807
|
+
init_ssrf_protection();
|
|
5808
|
+
init_utils();
|
|
5809
|
+
DEFAULT_TIMEOUT_MS2 = 12e4;
|
|
5810
|
+
MAX_POLL_INTERVAL_MS = 3e3;
|
|
5811
|
+
MAX_RESPONSE_BYTES2 = 4 * 1024 * 1024;
|
|
5812
|
+
MAX_ERROR_BODY_BYTES2 = 300;
|
|
5813
|
+
CONFIG_PATH40 = getWebSearchConfigPath();
|
|
5814
|
+
}
|
|
5815
|
+
});
|
|
5816
|
+
|
|
5603
5817
|
// gemini-pdf-extract.ts
|
|
5604
5818
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
5605
5819
|
async function extractPDFViaGemini(buffer, options) {
|
|
@@ -5611,7 +5825,7 @@ async function extractPDFViaGemini(buffer, options) {
|
|
|
5611
5825
|
PDF_MIME_TYPE,
|
|
5612
5826
|
{
|
|
5613
5827
|
signal: options.signal,
|
|
5614
|
-
timeoutMs: options.timeoutMs ??
|
|
5828
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS3
|
|
5615
5829
|
}
|
|
5616
5830
|
);
|
|
5617
5831
|
if (result.blockReason) {
|
|
@@ -5675,23 +5889,23 @@ function removeDuplicateInitialTitle(markdown, title) {
|
|
|
5675
5889
|
function normalizeTitle(value) {
|
|
5676
5890
|
return value.normalize("NFKC").toLocaleLowerCase().replace(/[`*_~]/g, "").replace(/[\p{P}\p{S}\s]+/gu, "");
|
|
5677
5891
|
}
|
|
5678
|
-
var PDF_MIME_TYPE,
|
|
5892
|
+
var PDF_MIME_TYPE, DEFAULT_TIMEOUT_MS3, PAGE_MARKER_PATTERN;
|
|
5679
5893
|
var init_gemini_pdf_extract = __esm({
|
|
5680
5894
|
"gemini-pdf-extract.ts"() {
|
|
5681
5895
|
init_gemini_api();
|
|
5682
5896
|
PDF_MIME_TYPE = "application/pdf";
|
|
5683
|
-
|
|
5897
|
+
DEFAULT_TIMEOUT_MS3 = 12e4;
|
|
5684
5898
|
PAGE_MARKER_PATTERN = /^<!-- Page (\d+) -->$/gm;
|
|
5685
5899
|
}
|
|
5686
5900
|
});
|
|
5687
5901
|
|
|
5688
5902
|
// pdf-extract.ts
|
|
5689
|
-
import { existsSync as
|
|
5903
|
+
import { existsSync as existsSync44, readFileSync as readFileSync46 } from "node:fs";
|
|
5690
5904
|
import { writeFile as writeFile2, mkdir } from "node:fs/promises";
|
|
5691
5905
|
import { join as join5, basename as basename2 } from "node:path";
|
|
5692
5906
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
5693
5907
|
function loadPDFConfig() {
|
|
5694
|
-
if (!
|
|
5908
|
+
if (!existsSync44(CONFIG_PATH41)) {
|
|
5695
5909
|
return {
|
|
5696
5910
|
enabled: true,
|
|
5697
5911
|
maxSizeMB: DEFAULT_PDF_MAX_SIZE_MB,
|
|
@@ -5701,13 +5915,13 @@ function loadPDFConfig() {
|
|
|
5701
5915
|
datalabTimeoutMs: DEFAULT_DATALAB_TIMEOUT_MS
|
|
5702
5916
|
};
|
|
5703
5917
|
}
|
|
5704
|
-
const rawText =
|
|
5918
|
+
const rawText = readFileSync46(CONFIG_PATH41, "utf-8");
|
|
5705
5919
|
let raw;
|
|
5706
5920
|
try {
|
|
5707
5921
|
raw = JSON.parse(rawText);
|
|
5708
5922
|
} catch (err) {
|
|
5709
5923
|
const message = err instanceof Error ? err.message : String(err);
|
|
5710
|
-
throw new Error(`Failed to parse ${
|
|
5924
|
+
throw new Error(`Failed to parse ${CONFIG_PATH41}: ${message}`);
|
|
5711
5925
|
}
|
|
5712
5926
|
const root = raw && typeof raw === "object" ? raw : {};
|
|
5713
5927
|
const pdf = root.pdf && typeof root.pdf === "object" ? root.pdf : {};
|
|
@@ -5753,6 +5967,31 @@ async function extractPDFToMarkdown(buffer, url, options = {}) {
|
|
|
5753
5967
|
const safeMaxPages = maxPages === void 0 ? pdfConfig.maxPages : Number.isFinite(maxPages) ? Math.max(1, Math.floor(maxPages)) : DEFAULT_MAX_PAGES;
|
|
5754
5968
|
const urlTitle = extractTitleFromURL(url);
|
|
5755
5969
|
const provider = pdfConfig.provider;
|
|
5970
|
+
if (provider === "auto" || provider === "endpoint") {
|
|
5971
|
+
if (provider === "endpoint" && !isEndpointApiAvailable()) {
|
|
5972
|
+
throw new Error(
|
|
5973
|
+
'PDF provider "endpoint" requires a configured pdf.endpointUrl'
|
|
5974
|
+
);
|
|
5975
|
+
}
|
|
5976
|
+
try {
|
|
5977
|
+
if (isEndpointApiAvailable()) {
|
|
5978
|
+
const result = await extractPDFViaEndpoint(buffer, {
|
|
5979
|
+
maxPages: safeMaxPages,
|
|
5980
|
+
...signal ? { signal } : {}
|
|
5981
|
+
});
|
|
5982
|
+
return writeMarkdownResult({
|
|
5983
|
+
markdownBody: result.markdown,
|
|
5984
|
+
title: urlTitle,
|
|
5985
|
+
pages: result.pages ?? countPageMarkers2(result.markdown),
|
|
5986
|
+
outputDir,
|
|
5987
|
+
filename,
|
|
5988
|
+
url
|
|
5989
|
+
});
|
|
5990
|
+
}
|
|
5991
|
+
} catch (err) {
|
|
5992
|
+
if (shouldRethrowExtractionError(err, signal)) throw err;
|
|
5993
|
+
}
|
|
5994
|
+
}
|
|
5756
5995
|
if (provider === "auto" || provider === "datalab") {
|
|
5757
5996
|
try {
|
|
5758
5997
|
if (isDatalabApiAvailable()) {
|
|
@@ -5847,9 +6086,11 @@ async function writeMarkdownResult(options) {
|
|
|
5847
6086
|
lines.push(`# ${options.title}`);
|
|
5848
6087
|
lines.push("");
|
|
5849
6088
|
lines.push(`> Source: ${options.url}`);
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
6089
|
+
if (options.pages > 0) {
|
|
6090
|
+
lines.push(
|
|
6091
|
+
`> Pages: ${options.pages}${options.truncated ? ` (extracted first ${options.pagesToExtract})` : ""}`
|
|
6092
|
+
);
|
|
6093
|
+
}
|
|
5853
6094
|
if (options.metaAuthor) lines.push(`> Author: ${options.metaAuthor}`);
|
|
5854
6095
|
lines.push("");
|
|
5855
6096
|
lines.push("---");
|
|
@@ -5916,16 +6157,18 @@ function isPDF(url, contentType) {
|
|
|
5916
6157
|
return false;
|
|
5917
6158
|
}
|
|
5918
6159
|
}
|
|
5919
|
-
var PDF_PROVIDER_VALUES, DEFAULT_PDF_MAX_SIZE_MB, MAX_PDF_MAX_SIZE_MB, MAX_DATALAB_TIMEOUT_MS, DEFAULT_MAX_PAGES, DEFAULT_OUTPUT_DIR,
|
|
6160
|
+
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_PATH41, PAGE_MARKER_PATTERN2;
|
|
5920
6161
|
var init_pdf_extract = __esm({
|
|
5921
6162
|
"pdf-extract.ts"() {
|
|
5922
6163
|
init_credential_source();
|
|
5923
6164
|
init_datalab_pdf_extract();
|
|
5924
6165
|
init_gemini_api();
|
|
6166
|
+
init_endpoint_pdf_extract();
|
|
5925
6167
|
init_gemini_pdf_extract();
|
|
5926
6168
|
init_utils();
|
|
5927
6169
|
PDF_PROVIDER_VALUES = /* @__PURE__ */ new Set([
|
|
5928
6170
|
"auto",
|
|
6171
|
+
"endpoint",
|
|
5929
6172
|
"gemini",
|
|
5930
6173
|
"datalab",
|
|
5931
6174
|
"unpdf"
|
|
@@ -5935,7 +6178,7 @@ var init_pdf_extract = __esm({
|
|
|
5935
6178
|
MAX_DATALAB_TIMEOUT_MS = 3e5;
|
|
5936
6179
|
DEFAULT_MAX_PAGES = 100;
|
|
5937
6180
|
DEFAULT_OUTPUT_DIR = join5(tmpdir3(), "pi-web-pdf");
|
|
5938
|
-
|
|
6181
|
+
CONFIG_PATH41 = getWebSearchConfigPath();
|
|
5939
6182
|
PAGE_MARKER_PATTERN2 = /^<!-- Page (\d+) -->$/gm;
|
|
5940
6183
|
}
|
|
5941
6184
|
});
|
|
@@ -6113,7 +6356,7 @@ var init_github_api = __esm({
|
|
|
6113
6356
|
});
|
|
6114
6357
|
|
|
6115
6358
|
// github-extract.ts
|
|
6116
|
-
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as
|
|
6359
|
+
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as existsSync45, lstatSync as lstatSync2, mkdirSync as mkdirSync2, mkdtempSync as mkdtempSync2, openSync as openSync2, readFileSync as readFileSync47, readSync, readdirSync as readdirSync3, realpathSync as realpathSync2, rmSync as rmSync2, statSync as statSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6117
6360
|
import { lstat as lstatAsync, open as openAsync, opendir as opendirAsync, readFile as readFileAsync, realpath as realpathAsync, rm as rmAsync } from "node:fs/promises";
|
|
6118
6361
|
import { execFile as execFile3, spawn as spawn2 } from "node:child_process";
|
|
6119
6362
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -6149,17 +6392,17 @@ function loadGitHubConfig() {
|
|
|
6149
6392
|
cloneTimeoutSeconds: 30,
|
|
6150
6393
|
clonePath: "/tmp/pi-github-repos"
|
|
6151
6394
|
};
|
|
6152
|
-
if (!
|
|
6395
|
+
if (!existsSync45(CONFIG_PATH42)) {
|
|
6153
6396
|
cachedConfig36 = defaults2;
|
|
6154
6397
|
return cachedConfig36;
|
|
6155
6398
|
}
|
|
6156
|
-
const rawText =
|
|
6399
|
+
const rawText = readFileSync47(CONFIG_PATH42, "utf-8");
|
|
6157
6400
|
let raw;
|
|
6158
6401
|
try {
|
|
6159
6402
|
raw = JSON.parse(rawText);
|
|
6160
6403
|
} catch (err) {
|
|
6161
6404
|
const message = err instanceof Error ? err.message : String(err);
|
|
6162
|
-
throw new Error(`Failed to parse ${
|
|
6405
|
+
throw new Error(`Failed to parse ${CONFIG_PATH42}: ${message}`);
|
|
6163
6406
|
}
|
|
6164
6407
|
const gc = raw.githubClone ?? {};
|
|
6165
6408
|
cachedConfig36 = {
|
|
@@ -6219,7 +6462,7 @@ function cacheKey(owner, repo, ref) {
|
|
|
6219
6462
|
}
|
|
6220
6463
|
function readLinuxBootId() {
|
|
6221
6464
|
try {
|
|
6222
|
-
const bootId =
|
|
6465
|
+
const bootId = readFileSync47("/proc/sys/kernel/random/boot_id", "utf-8").trim();
|
|
6223
6466
|
return bootId.length > 0 ? bootId : null;
|
|
6224
6467
|
} catch {
|
|
6225
6468
|
return null;
|
|
@@ -6244,7 +6487,7 @@ function parseLinuxProcessInfo(stat) {
|
|
|
6244
6487
|
}
|
|
6245
6488
|
function readLinuxProcessInfo(pid) {
|
|
6246
6489
|
try {
|
|
6247
|
-
return parseLinuxProcessInfo(
|
|
6490
|
+
return parseLinuxProcessInfo(readFileSync47(`/proc/${pid}/stat`, "utf-8"));
|
|
6248
6491
|
} catch (err) {
|
|
6249
6492
|
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
6250
6493
|
return { state: "", startTime: null, dead: true };
|
|
@@ -6582,7 +6825,7 @@ function resolveWithinRepo(rootPath, relativePath) {
|
|
|
6582
6825
|
const rootPrefix = normalizedRoot.endsWith(pathSep) ? normalizedRoot : normalizedRoot + pathSep;
|
|
6583
6826
|
if (!candidate.startsWith(rootPrefix)) return null;
|
|
6584
6827
|
}
|
|
6585
|
-
if (!
|
|
6828
|
+
if (!existsSync45(candidate)) return candidate;
|
|
6586
6829
|
try {
|
|
6587
6830
|
const realRoot = realpathSync2(normalizedRoot);
|
|
6588
6831
|
const realCandidate = realpathSync2(candidate);
|
|
@@ -6595,7 +6838,7 @@ function resolveWithinRepo(rootPath, relativePath) {
|
|
|
6595
6838
|
}
|
|
6596
6839
|
function readTextFile(path) {
|
|
6597
6840
|
try {
|
|
6598
|
-
return
|
|
6841
|
+
return readFileSync47(path, "utf-8");
|
|
6599
6842
|
} catch {
|
|
6600
6843
|
return null;
|
|
6601
6844
|
}
|
|
@@ -6678,9 +6921,9 @@ function readReadme(localPath) {
|
|
|
6678
6921
|
const candidates = ["README.md", "readme.md", "README", "README.txt", "README.rst"];
|
|
6679
6922
|
for (const name of candidates) {
|
|
6680
6923
|
const readmePath = join6(localPath, name);
|
|
6681
|
-
if (
|
|
6924
|
+
if (existsSync45(readmePath)) {
|
|
6682
6925
|
try {
|
|
6683
|
-
const content =
|
|
6926
|
+
const content = readFileSync47(readmePath, "utf-8");
|
|
6684
6927
|
return content.length > 8192 ? content.slice(0, 8192) + "\n\n[README truncated at 8K chars]" : content;
|
|
6685
6928
|
} catch {
|
|
6686
6929
|
continue;
|
|
@@ -6709,7 +6952,7 @@ function generateContent(localPath, info) {
|
|
|
6709
6952
|
if (info.type === "tree") {
|
|
6710
6953
|
const dirPath = info.path || "";
|
|
6711
6954
|
const fullDirPath = resolveWithinRepo(localPath, dirPath);
|
|
6712
|
-
if (!fullDirPath || !
|
|
6955
|
+
if (!fullDirPath || !existsSync45(fullDirPath)) {
|
|
6713
6956
|
lines.push(`Path \`${dirPath}\` not found in clone. Showing repository root instead.`);
|
|
6714
6957
|
lines.push("");
|
|
6715
6958
|
lines.push("## Structure");
|
|
@@ -6725,7 +6968,7 @@ function generateContent(localPath, info) {
|
|
|
6725
6968
|
if (info.type === "blob") {
|
|
6726
6969
|
const filePath = info.path || "";
|
|
6727
6970
|
const fullFilePath = resolveWithinRepo(localPath, filePath);
|
|
6728
|
-
if (!fullFilePath || !
|
|
6971
|
+
if (!fullFilePath || !existsSync45(fullFilePath)) {
|
|
6729
6972
|
lines.push(`Path \`${filePath}\` not found in clone. Showing repository root instead.`);
|
|
6730
6973
|
lines.push("");
|
|
6731
6974
|
lines.push("## Structure");
|
|
@@ -6887,13 +7130,13 @@ async function extractGitHub(url, signal, forceClone) {
|
|
|
6887
7130
|
const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
|
|
6888
7131
|
return { url, title, content, error: null };
|
|
6889
7132
|
}
|
|
6890
|
-
var
|
|
7133
|
+
var CONFIG_PATH42, 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, cachedConfig36, cloneRuntime, NON_CODE_SEGMENTS, PROCESS_KILL_GRACE_MS;
|
|
6891
7134
|
var init_github_extract = __esm({
|
|
6892
7135
|
"github-extract.ts"() {
|
|
6893
7136
|
init_activity();
|
|
6894
7137
|
init_github_api();
|
|
6895
7138
|
init_utils();
|
|
6896
|
-
|
|
7139
|
+
CONFIG_PATH42 = getWebSearchConfigPath();
|
|
6897
7140
|
BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6898
7141
|
".png",
|
|
6899
7142
|
".jpg",
|
|
@@ -7020,25 +7263,25 @@ var init_github_extract = __esm({
|
|
|
7020
7263
|
|
|
7021
7264
|
// github-issue-pr.ts
|
|
7022
7265
|
import { execFile as execFile4 } from "node:child_process";
|
|
7023
|
-
import { existsSync as
|
|
7266
|
+
import { existsSync as existsSync46, readFileSync as readFileSync48 } from "node:fs";
|
|
7024
7267
|
function loadConfig37() {
|
|
7025
7268
|
if (cachedConfig37) return cachedConfig37;
|
|
7026
7269
|
const defaults2 = { enabled: true };
|
|
7027
|
-
if (!
|
|
7270
|
+
if (!existsSync46(CONFIG_PATH43)) {
|
|
7028
7271
|
cachedConfig37 = defaults2;
|
|
7029
7272
|
return cachedConfig37;
|
|
7030
7273
|
}
|
|
7031
7274
|
let parsed;
|
|
7032
7275
|
try {
|
|
7033
|
-
parsed = JSON.parse(
|
|
7276
|
+
parsed = JSON.parse(readFileSync48(CONFIG_PATH43, "utf-8"));
|
|
7034
7277
|
} catch (err) {
|
|
7035
7278
|
const message = err instanceof Error ? err.message : String(err);
|
|
7036
|
-
throw new Error(`Failed to parse ${
|
|
7279
|
+
throw new Error(`Failed to parse ${CONFIG_PATH43}: ${message}`);
|
|
7037
7280
|
}
|
|
7038
7281
|
const root = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
7039
7282
|
const value = root.githubPrIssue;
|
|
7040
7283
|
if (value !== void 0 && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
7041
|
-
throw new Error(`githubPrIssue in ${
|
|
7284
|
+
throw new Error(`githubPrIssue in ${CONFIG_PATH43} must be an object`);
|
|
7042
7285
|
}
|
|
7043
7286
|
const enabled = typeof value?.enabled === "boolean" ? value.enabled : true;
|
|
7044
7287
|
cachedConfig37 = { enabled };
|
|
@@ -7348,23 +7591,38 @@ function milestoneTitle(value) {
|
|
|
7348
7591
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "none";
|
|
7349
7592
|
return stringValue(value.title) || "none";
|
|
7350
7593
|
}
|
|
7351
|
-
function truncateText(text4, limit, label, appendix) {
|
|
7594
|
+
function truncateText(text4, limit, label, appendix, tool) {
|
|
7352
7595
|
if (text4.length <= limit) return text4;
|
|
7353
|
-
|
|
7596
|
+
const lastSpace = text4.slice(0, limit + 1).search(/\s\S*$/);
|
|
7597
|
+
const cut = lastSpace > limit * 0.8 ? lastSpace : limit;
|
|
7598
|
+
appendix.push(`## ${label} (continued)
|
|
7354
7599
|
|
|
7355
|
-
${text4}`);
|
|
7356
|
-
return `${text4.slice(0,
|
|
7600
|
+
${text4.slice(cut)}`);
|
|
7601
|
+
return `${text4.slice(0, cut)}
|
|
7602
|
+
|
|
7603
|
+
[${label} truncated; ${tool ? `the rest is stored under "${label} (continued)": use ${tool} findText or offset` : "use the gh escalation commands below for the rest"}]`;
|
|
7604
|
+
}
|
|
7605
|
+
function storeOmitted(appendix, section, items) {
|
|
7606
|
+
if (items.length > 0) appendix.push(`## ${section} (continued)
|
|
7357
7607
|
|
|
7358
|
-
|
|
7608
|
+
${items.join("\n")}`);
|
|
7359
7609
|
}
|
|
7360
|
-
function
|
|
7610
|
+
function omissionMarker(section, noun, shown, fetched, atLeast, tool, gh = "the gh command below") {
|
|
7611
|
+
const stored = fetched > shown && tool ? `${fetched - shown} more stored under "${section} (continued)": use ${tool} findText or offset` : "";
|
|
7612
|
+
if (atLeast !== null) return `[${shown} ${noun} shown from at least ${atLeast}; ${stored ? `${stored}; for the rest ` : ""}use ${gh}]`;
|
|
7613
|
+
if (fetched <= shown) return null;
|
|
7614
|
+
return `[${shown} of ${fetched} ${noun} shown; ${stored ? `${stored}, or ${gh}` : `use ${gh}`}]`;
|
|
7615
|
+
}
|
|
7616
|
+
function appendLimitedSection(lines, title, items, max, marker, appendix, tool) {
|
|
7361
7617
|
lines.push(`## ${title}`);
|
|
7362
7618
|
if (items.length === 0) {
|
|
7363
7619
|
lines.push("none", "");
|
|
7364
7620
|
return;
|
|
7365
7621
|
}
|
|
7366
7622
|
lines.push(...items.slice(0, max));
|
|
7367
|
-
|
|
7623
|
+
storeOmitted(appendix, title, items.slice(max));
|
|
7624
|
+
const omitted = omissionMarker(title, marker, max, items.length, null, tool);
|
|
7625
|
+
if (omitted) lines.push(omitted);
|
|
7368
7626
|
lines.push("");
|
|
7369
7627
|
}
|
|
7370
7628
|
function objectArray(value) {
|
|
@@ -7379,26 +7637,21 @@ function anchorMatches(anchor, comment) {
|
|
|
7379
7637
|
const id = commentId(comment);
|
|
7380
7638
|
return anchor === `issuecomment-${id}` || anchor === `discussion_r${id}`;
|
|
7381
7639
|
}
|
|
7382
|
-
function renderComments(comments, anchor, appendix) {
|
|
7640
|
+
function renderComments(comments, anchor, appendix, tool) {
|
|
7383
7641
|
const forced = anchor ? comments.find((comment) => anchorMatches(anchor, comment)) : void 0;
|
|
7384
7642
|
const selected = comments.slice(0, MAX_INLINE_COMMENTS);
|
|
7385
7643
|
if (forced && !selected.includes(forced)) selected.push(forced);
|
|
7386
|
-
const
|
|
7644
|
+
const render = (comment, inline) => {
|
|
7387
7645
|
const body = stringValue(comment.body);
|
|
7388
|
-
const label = `comment ${commentId(comment) ||
|
|
7646
|
+
const label = `comment ${commentId(comment) || comments.indexOf(comment) + 1}`;
|
|
7647
|
+
const text4 = inline ? truncateText(body, COMMENT_INLINE_CHARS, label, appendix, tool) : body;
|
|
7389
7648
|
return `- ${authorLogin(comment.author ?? comment.user)} at ${stringValue(comment.createdAt) || stringValue(comment.created_at)}${forced === comment ? " [anchored]" : ""}:
|
|
7390
|
-
${
|
|
7391
|
-
}
|
|
7649
|
+
${text4.replace(/\n/g, "\n ")}`;
|
|
7650
|
+
};
|
|
7651
|
+
const lines = selected.map((comment) => render(comment, true));
|
|
7652
|
+
storeOmitted(appendix, "Conversation comments", comments.slice(MAX_INLINE_COMMENTS).filter((comment) => comment !== forced).map((comment) => render(comment, false)));
|
|
7392
7653
|
return lines;
|
|
7393
7654
|
}
|
|
7394
|
-
function renderCommentMarker(comments, renderedCount, total) {
|
|
7395
|
-
const knownTotal = numberValue(total);
|
|
7396
|
-
if (knownTotal !== null && knownTotal > comments.length) {
|
|
7397
|
-
return `[${renderedCount} comments shown from at least ${knownTotal}; use get_search_content findText or offset, or gh issue view -c]`;
|
|
7398
|
-
}
|
|
7399
|
-
if (comments.length > renderedCount) return `[${renderedCount} of ${comments.length} comments shown; use get_search_content findText or offset, or gh issue view -c]`;
|
|
7400
|
-
return null;
|
|
7401
|
-
}
|
|
7402
7655
|
function commentCountText(view) {
|
|
7403
7656
|
const comments = objectArray(view.comments).length;
|
|
7404
7657
|
const total = numberValue(view.commentsCount);
|
|
@@ -7412,7 +7665,7 @@ function reviewThreadCountText(comments, total, bounded, unavailable) {
|
|
|
7412
7665
|
if (knownTotal !== null && knownTotal > comments.length) return `at least ${knownTotal}`;
|
|
7413
7666
|
return String(comments.length || knownTotal || 0);
|
|
7414
7667
|
}
|
|
7415
|
-
function renderChecks(value) {
|
|
7668
|
+
function renderChecks(value, appendix, tool) {
|
|
7416
7669
|
const checks = objectArray(value);
|
|
7417
7670
|
if (checks.length === 0) return ["No check rollup data available."];
|
|
7418
7671
|
const rows = checks.map((check) => {
|
|
@@ -7421,19 +7674,21 @@ function renderChecks(value) {
|
|
|
7421
7674
|
return `- ${name}: ${state}`;
|
|
7422
7675
|
});
|
|
7423
7676
|
const failing = rows.filter((row) => !/(success|neutral|skipped|completed)$/i.test(row));
|
|
7424
|
-
|
|
7677
|
+
storeOmitted(appendix, "Checks", rows.slice(MAX_INLINE_CHECKS));
|
|
7678
|
+
const omitted = omissionMarker("Checks", "checks", MAX_INLINE_CHECKS, rows.length, null, tool);
|
|
7679
|
+
return [`Rollup: ${failing.length === 0 ? "no failing checks in shown data" : `${failing.length} non-passing checks in shown data`}`, ...rows.slice(0, MAX_INLINE_CHECKS), ...omitted ? [omitted] : []];
|
|
7425
7680
|
}
|
|
7426
|
-
function renderReviewVerdicts(value, appendix) {
|
|
7681
|
+
function renderReviewVerdicts(value, appendix, tool) {
|
|
7427
7682
|
const latest = /* @__PURE__ */ new Map();
|
|
7428
7683
|
for (const review of objectArray(value)) latest.set(authorLogin(review.author ?? review.user), review);
|
|
7429
7684
|
return [...latest.entries()].map(([author, review]) => {
|
|
7430
7685
|
const state = stringValue(review.state) || "COMMENTED";
|
|
7431
|
-
const body = truncateText(stringValue(review.body), 300, `review by ${author}`, appendix);
|
|
7686
|
+
const body = truncateText(stringValue(review.body), 300, `review by ${author}`, appendix, tool);
|
|
7432
7687
|
return `- ${author}: ${state}${body ? ` \u2014 ${body.replace(/\n/g, " ")}` : ""}`;
|
|
7433
7688
|
});
|
|
7434
7689
|
}
|
|
7435
|
-
function renderReviewVerdictsOrUnavailable(view, appendix) {
|
|
7436
|
-
const rendered = renderReviewVerdicts(view.reviews, appendix);
|
|
7690
|
+
function renderReviewVerdictsOrUnavailable(view, appendix, tool) {
|
|
7691
|
+
const rendered = renderReviewVerdicts(view.reviews, appendix, tool);
|
|
7437
7692
|
if (rendered.length > 0) return rendered;
|
|
7438
7693
|
return view.reviewsUnavailable === true ? ["Unavailable in this GitHub fetch path; use gh for review verdicts."] : [];
|
|
7439
7694
|
}
|
|
@@ -7445,25 +7700,15 @@ function renderFiles(value) {
|
|
|
7445
7700
|
return `- ${path} (+${additions}/\u2212${deletions})`;
|
|
7446
7701
|
});
|
|
7447
7702
|
}
|
|
7448
|
-
function appendFilesSection(lines, view) {
|
|
7703
|
+
function appendFilesSection(lines, view, appendix, tool) {
|
|
7449
7704
|
lines.push("## Files");
|
|
7450
7705
|
const files = renderFiles(view.files);
|
|
7451
|
-
if (files.length === 0) {
|
|
7452
|
-
const total2 = numberValue(view.changedFiles);
|
|
7453
|
-
if (total2 !== null && total2 > 0) {
|
|
7454
|
-
lines.push(`[0 files shown from at least ${total2}; use get_search_content offset or the gh command below for more]`, "");
|
|
7455
|
-
return;
|
|
7456
|
-
}
|
|
7457
|
-
lines.push("none", "");
|
|
7458
|
-
return;
|
|
7459
|
-
}
|
|
7460
|
-
lines.push(...files.slice(0, MAX_INLINE_FILES));
|
|
7461
7706
|
const total = numberValue(view.changedFiles);
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7707
|
+
const omitted = omissionMarker("Files", "files", Math.min(files.length, MAX_INLINE_FILES), files.length, total !== null && total > files.length ? total : null, tool);
|
|
7708
|
+
if (files.length === 0 && !omitted) lines.push("none");
|
|
7709
|
+
lines.push(...files.slice(0, MAX_INLINE_FILES));
|
|
7710
|
+
storeOmitted(appendix, "Files", files.slice(MAX_INLINE_FILES));
|
|
7711
|
+
if (omitted) lines.push(omitted);
|
|
7467
7712
|
lines.push("");
|
|
7468
7713
|
}
|
|
7469
7714
|
function renderCommits(value) {
|
|
@@ -7486,31 +7731,31 @@ function renderLinkedOrUnavailable(view, field, kind) {
|
|
|
7486
7731
|
if (linked.length > 0) return linked;
|
|
7487
7732
|
return view.linkedReferencesUnavailable === true ? ["Unavailable in this GitHub fetch path; use gh for linked references."] : [];
|
|
7488
7733
|
}
|
|
7489
|
-
function renderReviewThreads(comments, anchor, appendix, total, bounded, unavailable) {
|
|
7734
|
+
function renderReviewThreads(comments, anchor, appendix, tool, total, bounded, unavailable) {
|
|
7490
7735
|
if (unavailable) return ["Unavailable in this GitHub fetch path; use gh for review thread comments."];
|
|
7491
7736
|
const forced = anchor ? comments.find((comment) => anchorMatches(anchor, comment)) : void 0;
|
|
7492
7737
|
const selected = comments.slice(0, MAX_INLINE_REVIEW_THREADS);
|
|
7493
7738
|
if (forced && !selected.includes(forced)) selected.push(forced);
|
|
7494
|
-
const
|
|
7739
|
+
const render = (comment, inline) => {
|
|
7495
7740
|
const path = stringValue(comment.path) || "unknown path";
|
|
7496
7741
|
const line = numberValue(comment.line) ?? numberValue(comment.original_line) ?? numberValue(comment.position) ?? "?";
|
|
7497
|
-
const
|
|
7742
|
+
const text4 = stringValue(comment.body);
|
|
7743
|
+
const body = inline ? truncateText(text4, COMMENT_INLINE_CHARS, `review thread comment ${commentId(comment) || comments.indexOf(comment) + 1}`, appendix, tool) : text4;
|
|
7498
7744
|
return `- ${path}:${line} \u2014 ${authorLogin(comment.user ?? comment.author)}${forced === comment ? " [anchored]" : ""} (resolution state unknown):
|
|
7499
7745
|
${body.replace(/\n/g, "\n ")}`;
|
|
7500
|
-
}
|
|
7746
|
+
};
|
|
7747
|
+
const lines = selected.map((comment) => render(comment, true));
|
|
7748
|
+
storeOmitted(appendix, "Review thread comments", comments.slice(MAX_INLINE_REVIEW_THREADS).filter((comment) => comment !== forced).map((comment) => render(comment, false)));
|
|
7501
7749
|
const knownTotal = numberValue(total);
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
lines.push(`[${selected.length} review thread comments shown from at least ${knownTotal}; use get_search_content offset, or gh api repos/<owner>/<repo>/pulls/<number>/comments]`);
|
|
7506
|
-
} else if (comments.length > selected.length) {
|
|
7507
|
-
lines.push(`[${selected.length} of ${comments.length} review thread comments shown; use get_search_content offset, or gh api repos/<owner>/<repo>/pulls/<number>/comments]`);
|
|
7508
|
-
}
|
|
7750
|
+
const atLeast = bounded ? comments.length : knownTotal !== null && knownTotal > comments.length ? knownTotal : null;
|
|
7751
|
+
const omitted = omissionMarker("Review thread comments", "review thread comments", selected.length, comments.length, atLeast, tool, "gh api repos/<owner>/<repo>/pulls/<number>/comments");
|
|
7752
|
+
if (omitted) lines.push(omitted);
|
|
7509
7753
|
return lines;
|
|
7510
7754
|
}
|
|
7511
7755
|
function renderGitHubPrIssue(data) {
|
|
7512
7756
|
const { view } = data;
|
|
7513
7757
|
const appendix = [];
|
|
7758
|
+
const tool = data.retrievalTool === void 0 ? "get_search_content" : data.retrievalTool;
|
|
7514
7759
|
const title = stringValue(view.title) || `${data.owner}/${data.repo}#${data.number}`;
|
|
7515
7760
|
const number = numberValue(view.number) ?? data.number;
|
|
7516
7761
|
const stateParts = [stringValue(view.state) || "unknown"];
|
|
@@ -7538,45 +7783,48 @@ function renderGitHubPrIssue(data) {
|
|
|
7538
7783
|
if (data.anchor) lines.push(`- requested anchor: #${data.anchor}`);
|
|
7539
7784
|
lines.push("");
|
|
7540
7785
|
lines.push("## Body");
|
|
7541
|
-
lines.push(truncateText(stringValue(view.body) || "(empty)", BODY_INLINE_CHARS, "body", appendix), "");
|
|
7786
|
+
lines.push(truncateText(stringValue(view.body) || "(empty)", BODY_INLINE_CHARS, "body", appendix, tool), "");
|
|
7542
7787
|
if (data.kind === "pull") {
|
|
7543
7788
|
lines.push("## Checks");
|
|
7544
|
-
lines.push(...renderChecks(view.statusCheckRollup), "");
|
|
7545
|
-
appendLimitedSection(lines, "Review verdicts", renderReviewVerdictsOrUnavailable(view, appendix), MAX_INLINE_REVIEWS, "review verdicts");
|
|
7546
|
-
appendLimitedSection(lines, "Linked references", renderLinkedOrUnavailable(view, "closingIssuesReferences", "closing"), 20, "linked references");
|
|
7547
|
-
appendFilesSection(lines, view);
|
|
7548
|
-
appendLimitedSection(lines, "Commits", renderCommitsOrUnavailable(view), MAX_INLINE_COMMITS, "commits");
|
|
7789
|
+
lines.push(...renderChecks(view.statusCheckRollup, appendix, tool), "");
|
|
7790
|
+
appendLimitedSection(lines, "Review verdicts", renderReviewVerdictsOrUnavailable(view, appendix, tool), MAX_INLINE_REVIEWS, "review verdicts", appendix, tool);
|
|
7791
|
+
appendLimitedSection(lines, "Linked references", renderLinkedOrUnavailable(view, "closingIssuesReferences", "closing"), 20, "linked references", appendix, tool);
|
|
7792
|
+
appendFilesSection(lines, view, appendix, tool);
|
|
7793
|
+
appendLimitedSection(lines, "Commits", renderCommitsOrUnavailable(view), MAX_INLINE_COMMITS, "commits", appendix, tool);
|
|
7549
7794
|
} else {
|
|
7550
|
-
appendLimitedSection(lines, "Closed by pull requests", renderLinkedOrUnavailable(view, "closedByPullRequestsReferences", "closedBy"), 20, "pull requests");
|
|
7795
|
+
appendLimitedSection(lines, "Closed by pull requests", renderLinkedOrUnavailable(view, "closedByPullRequestsReferences", "closedBy"), 20, "pull requests", appendix, tool);
|
|
7551
7796
|
}
|
|
7552
7797
|
lines.push("## Conversation comments");
|
|
7553
|
-
const
|
|
7554
|
-
const
|
|
7798
|
+
const comments = objectArray(view.comments);
|
|
7799
|
+
const commentLines = renderComments(comments, data.anchor, appendix, tool);
|
|
7800
|
+
const knownCommentTotal = numberValue(view.commentsCount);
|
|
7801
|
+
const commentMarker = omissionMarker("Conversation comments", "comments", commentLines.length, comments.length, knownCommentTotal !== null && knownCommentTotal > comments.length ? knownCommentTotal : null, tool, "gh issue view -c");
|
|
7555
7802
|
if (commentMarker) commentLines.push(commentMarker);
|
|
7556
7803
|
if (view.anchorUnavailable === true && data.anchor?.startsWith("issuecomment-")) commentLines.push("[anchored comment unavailable for this issue or pull request]");
|
|
7557
7804
|
lines.push(...commentLines.length > 0 ? commentLines : ["none"], "");
|
|
7558
7805
|
if (data.kind === "pull") {
|
|
7559
7806
|
lines.push("## Review thread comments");
|
|
7560
|
-
const threadLines = renderReviewThreads(data.reviewThreads, data.anchor, appendix, view.reviewCommentsCount, data.reviewThreadsBounded, data.reviewThreadsUnavailable);
|
|
7807
|
+
const threadLines = renderReviewThreads(data.reviewThreads, data.anchor, appendix, tool, view.reviewCommentsCount, data.reviewThreadsBounded, data.reviewThreadsUnavailable);
|
|
7561
7808
|
if (view.anchorUnavailable === true && data.anchor?.startsWith("discussion_r")) threadLines.push("[anchored review thread comment unavailable for this pull request]");
|
|
7562
7809
|
lines.push(...threadLines.length > 0 ? threadLines : ["none"], "");
|
|
7563
7810
|
}
|
|
7564
7811
|
if (data.fallbackNotes.length > 0) {
|
|
7565
7812
|
lines.push("## Availability notes", ...data.fallbackNotes.map((note) => `- ${note}`), "");
|
|
7566
7813
|
}
|
|
7567
|
-
if (appendix.length > 0) lines.push("## Appendix", ...appendix, "");
|
|
7568
7814
|
const viewCommand = data.kind === "pull" ? `gh pr view ${data.number} --repo ${data.owner}/${data.repo}` : `gh issue view ${data.number} --repo ${data.owner}/${data.repo} -c`;
|
|
7815
|
+
const diffCommand = data.kind === "pull" ? `gh pr diff ${data.number} --repo ${data.owner}/${data.repo}` : "";
|
|
7569
7816
|
lines.push("## Escalation commands");
|
|
7570
7817
|
lines.push(`- Full view: \`${viewCommand}\``);
|
|
7571
|
-
if (
|
|
7572
|
-
lines.push(
|
|
7818
|
+
if (diffCommand) lines.push(`- Complete diff: \`${diffCommand}\``);
|
|
7819
|
+
if (tool) lines.push(`- Stored full document: use \`${tool}\` with \`offset\` or \`findText\`.`);
|
|
7820
|
+
if (appendix.length > 0) lines.push("", "## Appendix", "", appendix.join("\n\n"));
|
|
7573
7821
|
const content = lines.join("\n");
|
|
7574
7822
|
return {
|
|
7575
7823
|
url: data.url,
|
|
7576
7824
|
title: `${data.owner}/${data.repo} ${data.kind} #${data.number}: ${title}`,
|
|
7577
7825
|
content: content.length > MAX_DOC_CHARS ? `${content.slice(0, MAX_DOC_CHARS)}
|
|
7578
7826
|
|
|
7579
|
-
[GitHub document truncated at ${MAX_DOC_CHARS} chars; use
|
|
7827
|
+
[GitHub document truncated at ${MAX_DOC_CHARS} chars; use \`${viewCommand}\`${diffCommand ? ` or \`${diffCommand}\`` : ""} for complete data]` : content,
|
|
7580
7828
|
error: null
|
|
7581
7829
|
};
|
|
7582
7830
|
}
|
|
@@ -7585,6 +7833,7 @@ async function extractGitHubIssuePr(url, signal, options) {
|
|
|
7585
7833
|
if (!info) return null;
|
|
7586
7834
|
if (!loadConfig37().enabled) return null;
|
|
7587
7835
|
if (signal?.aborted) return { url, title: "", content: "", error: "Aborted" };
|
|
7836
|
+
const retrievalTool = options?.toolNames ? options.toolNames.getSearchContent ?? null : void 0;
|
|
7588
7837
|
const ghAvailable2 = await checkGhAvailable(signal);
|
|
7589
7838
|
if (signal?.aborted) return { url, title: "", content: "", error: "Aborted" };
|
|
7590
7839
|
if (ghAvailable2) {
|
|
@@ -7596,23 +7845,23 @@ async function extractGitHubIssuePr(url, signal, options) {
|
|
|
7596
7845
|
if (signal?.aborted) return { url, title: "", content: "", error: "Aborted" };
|
|
7597
7846
|
if (threads.anchorUnavailable) viewed.view.anchorUnavailable = true;
|
|
7598
7847
|
const notes = [...viewed.notes, ...threads.note ? [threads.note] : []];
|
|
7599
|
-
return renderGitHubPrIssue({ url, owner: info.owner, repo: info.repo, kind: info.kind, number: info.number, anchor: info.anchor, view: viewed.view, reviewThreads: threads.comments, reviewThreadsBounded: threads.bounded, reviewThreadsUnavailable: threads.unavailable, fallbackNotes: notes });
|
|
7848
|
+
return renderGitHubPrIssue({ url, owner: info.owner, repo: info.repo, kind: info.kind, number: info.number, anchor: info.anchor, view: viewed.view, reviewThreads: threads.comments, reviewThreadsBounded: threads.bounded, reviewThreadsUnavailable: threads.unavailable, fallbackNotes: notes, retrievalTool });
|
|
7600
7849
|
}
|
|
7601
7850
|
} else {
|
|
7602
7851
|
showGhHint();
|
|
7603
7852
|
}
|
|
7604
7853
|
const fallback = await restFallback(url, info, options, signal);
|
|
7605
7854
|
if (!fallback) return null;
|
|
7606
|
-
if ("data" in fallback) return renderGitHubPrIssue(fallback.data);
|
|
7855
|
+
if ("data" in fallback) return renderGitHubPrIssue({ ...fallback.data, retrievalTool });
|
|
7607
7856
|
return fallback;
|
|
7608
7857
|
}
|
|
7609
|
-
var
|
|
7858
|
+
var CONFIG_PATH43, 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, cachedConfig37;
|
|
7610
7859
|
var init_github_issue_pr = __esm({
|
|
7611
7860
|
"github-issue-pr.ts"() {
|
|
7612
7861
|
init_github_api();
|
|
7613
7862
|
init_ssrf_protection();
|
|
7614
7863
|
init_utils();
|
|
7615
|
-
|
|
7864
|
+
CONFIG_PATH43 = getWebSearchConfigPath();
|
|
7616
7865
|
GH_TIMEOUT_MS = 1e4;
|
|
7617
7866
|
GH_TOTAL_TIMEOUT_MS = 2e4;
|
|
7618
7867
|
MAX_DOC_CHARS = 15e4;
|
|
@@ -7698,15 +7947,15 @@ var init_github_issue_pr = __esm({
|
|
|
7698
7947
|
});
|
|
7699
7948
|
|
|
7700
7949
|
// feature-config.ts
|
|
7701
|
-
import { existsSync as
|
|
7950
|
+
import { existsSync as existsSync47, readFileSync as readFileSync49 } from "node:fs";
|
|
7702
7951
|
function loadFeatureConfig() {
|
|
7703
|
-
if (!
|
|
7952
|
+
if (!existsSync47(CONFIG_PATH44)) return {};
|
|
7704
7953
|
try {
|
|
7705
|
-
const raw = JSON.parse(
|
|
7954
|
+
const raw = JSON.parse(readFileSync49(CONFIG_PATH44, "utf-8"));
|
|
7706
7955
|
return raw && typeof raw === "object" ? raw : {};
|
|
7707
7956
|
} catch (err) {
|
|
7708
7957
|
const message = err instanceof Error ? err.message : String(err);
|
|
7709
|
-
throw new Error(`Failed to parse ${
|
|
7958
|
+
throw new Error(`Failed to parse ${CONFIG_PATH44}: ${message}`);
|
|
7710
7959
|
}
|
|
7711
7960
|
}
|
|
7712
7961
|
function isImageEnabled() {
|
|
@@ -7719,17 +7968,17 @@ function canAttachImages() {
|
|
|
7719
7968
|
return false;
|
|
7720
7969
|
}
|
|
7721
7970
|
}
|
|
7722
|
-
var
|
|
7971
|
+
var CONFIG_PATH44;
|
|
7723
7972
|
var init_feature_config = __esm({
|
|
7724
7973
|
"feature-config.ts"() {
|
|
7725
7974
|
init_utils();
|
|
7726
|
-
|
|
7975
|
+
CONFIG_PATH44 = getWebSearchConfigPath();
|
|
7727
7976
|
}
|
|
7728
7977
|
});
|
|
7729
7978
|
|
|
7730
7979
|
// youtube-extract.ts
|
|
7731
7980
|
import { execFileSync } from "node:child_process";
|
|
7732
|
-
import { existsSync as
|
|
7981
|
+
import { existsSync as existsSync48, readFileSync as readFileSync50 } from "node:fs";
|
|
7733
7982
|
function errorMessage29(err) {
|
|
7734
7983
|
return err instanceof Error ? err.message : String(err);
|
|
7735
7984
|
}
|
|
@@ -7750,17 +7999,17 @@ function normalizeEnabled2(value, fallback) {
|
|
|
7750
7999
|
}
|
|
7751
8000
|
function loadYouTubeConfig() {
|
|
7752
8001
|
if (cachedConfig38) return cachedConfig38;
|
|
7753
|
-
if (!
|
|
8002
|
+
if (!existsSync48(CONFIG_PATH45)) {
|
|
7754
8003
|
cachedConfig38 = { ...defaults };
|
|
7755
8004
|
return cachedConfig38;
|
|
7756
8005
|
}
|
|
7757
|
-
const rawText =
|
|
8006
|
+
const rawText = readFileSync50(CONFIG_PATH45, "utf-8");
|
|
7758
8007
|
let raw;
|
|
7759
8008
|
try {
|
|
7760
8009
|
raw = JSON.parse(rawText);
|
|
7761
8010
|
} catch (err) {
|
|
7762
8011
|
const message = err instanceof Error ? err.message : String(err);
|
|
7763
|
-
throw new Error(`Failed to parse ${
|
|
8012
|
+
throw new Error(`Failed to parse ${CONFIG_PATH45}: ${message}`);
|
|
7764
8013
|
}
|
|
7765
8014
|
const yt = raw.youtube ?? {};
|
|
7766
8015
|
cachedConfig38 = {
|
|
@@ -7959,7 +8208,7 @@ ${answer}
|
|
|
7959
8208
|
return null;
|
|
7960
8209
|
}
|
|
7961
8210
|
}
|
|
7962
|
-
var
|
|
8211
|
+
var CONFIG_PATH45, YOUTUBE_PROMPT, YOUTUBE_REGEX, defaults, cachedConfig38;
|
|
7963
8212
|
var init_youtube_extract = __esm({
|
|
7964
8213
|
"youtube-extract.ts"() {
|
|
7965
8214
|
init_activity();
|
|
@@ -7969,7 +8218,7 @@ var init_youtube_extract = __esm({
|
|
|
7969
8218
|
init_perplexity();
|
|
7970
8219
|
init_extract();
|
|
7971
8220
|
init_utils();
|
|
7972
|
-
|
|
8221
|
+
CONFIG_PATH45 = getWebSearchConfigPath();
|
|
7973
8222
|
YOUTUBE_PROMPT = `Extract the complete content of this YouTube video. Include:
|
|
7974
8223
|
1. Video title, channel name, and duration
|
|
7975
8224
|
2. A brief summary (2-3 sentences)
|
|
@@ -8081,23 +8330,23 @@ URL: `;
|
|
|
8081
8330
|
});
|
|
8082
8331
|
|
|
8083
8332
|
// crawl4ai.ts
|
|
8084
|
-
import { existsSync as
|
|
8333
|
+
import { existsSync as existsSync49, readFileSync as readFileSync51 } from "node:fs";
|
|
8085
8334
|
function loadConfig38() {
|
|
8086
8335
|
if (cachedConfig39) return cachedConfig39;
|
|
8087
|
-
if (!
|
|
8336
|
+
if (!existsSync49(CONFIG_PATH46)) {
|
|
8088
8337
|
cachedConfig39 = {};
|
|
8089
8338
|
return cachedConfig39;
|
|
8090
8339
|
}
|
|
8091
|
-
const raw =
|
|
8340
|
+
const raw = readFileSync51(CONFIG_PATH46, "utf8");
|
|
8092
8341
|
let parsed;
|
|
8093
8342
|
try {
|
|
8094
8343
|
parsed = JSON.parse(raw);
|
|
8095
8344
|
} catch (err) {
|
|
8096
8345
|
const message = err instanceof Error ? err.message : String(err);
|
|
8097
|
-
throw new Error(`Failed to parse ${
|
|
8346
|
+
throw new Error(`Failed to parse ${CONFIG_PATH46}: ${message}`);
|
|
8098
8347
|
}
|
|
8099
8348
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
8100
|
-
throw new Error(`Invalid config in ${
|
|
8349
|
+
throw new Error(`Invalid config in ${CONFIG_PATH46}: expected a JSON object`);
|
|
8101
8350
|
}
|
|
8102
8351
|
cachedConfig39 = parsed;
|
|
8103
8352
|
return cachedConfig39;
|
|
@@ -8110,13 +8359,13 @@ function normalizeBaseUrl5(value) {
|
|
|
8110
8359
|
try {
|
|
8111
8360
|
parsed = new URL(trimmed);
|
|
8112
8361
|
} catch {
|
|
8113
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
8362
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH46}: expected an HTTP or HTTPS URL`);
|
|
8114
8363
|
}
|
|
8115
8364
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
8116
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
8365
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH46}: expected an HTTP or HTTPS URL`);
|
|
8117
8366
|
}
|
|
8118
8367
|
if (parsed.username || parsed.password) {
|
|
8119
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
8368
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH46}: URL credentials are not allowed`);
|
|
8120
8369
|
}
|
|
8121
8370
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
8122
8371
|
parsed.search = "";
|
|
@@ -8131,7 +8380,7 @@ function requireBaseUrl4() {
|
|
|
8131
8380
|
if (!baseUrl) {
|
|
8132
8381
|
throw new Error(
|
|
8133
8382
|
`Crawl4AI base URL not configured. Either:
|
|
8134
|
-
1. Set crawl4aiBaseUrl in ${
|
|
8383
|
+
1. Set crawl4aiBaseUrl in ${CONFIG_PATH46}
|
|
8135
8384
|
2. Set CRAWL4AI_BASE_URL environment variable`
|
|
8136
8385
|
);
|
|
8137
8386
|
}
|
|
@@ -8230,14 +8479,14 @@ async function extractWithCrawl4ai(url, signal, options) {
|
|
|
8230
8479
|
throw err;
|
|
8231
8480
|
}
|
|
8232
8481
|
}
|
|
8233
|
-
var
|
|
8482
|
+
var CONFIG_PATH46, EXTRACT_TIMEOUT_MS2, MARKDOWN_FILTER, cachedConfig39;
|
|
8234
8483
|
var init_crawl4ai = __esm({
|
|
8235
8484
|
"crawl4ai.ts"() {
|
|
8236
8485
|
init_activity();
|
|
8237
8486
|
init_credential_source();
|
|
8238
8487
|
init_ssrf_protection();
|
|
8239
8488
|
init_utils();
|
|
8240
|
-
|
|
8489
|
+
CONFIG_PATH46 = getWebSearchConfigPath();
|
|
8241
8490
|
EXTRACT_TIMEOUT_MS2 = 6e4;
|
|
8242
8491
|
MARKDOWN_FILTER = "fit";
|
|
8243
8492
|
cachedConfig39 = null;
|
|
@@ -8245,7 +8494,7 @@ var init_crawl4ai = __esm({
|
|
|
8245
8494
|
});
|
|
8246
8495
|
|
|
8247
8496
|
// brightdata-unlocker.ts
|
|
8248
|
-
import { existsSync as
|
|
8497
|
+
import { existsSync as existsSync50, readFileSync as readFileSync52 } from "node:fs";
|
|
8249
8498
|
function parseFailureDetail(err) {
|
|
8250
8499
|
const message = err instanceof Error ? err.message : String(err);
|
|
8251
8500
|
const position = message.match(/at position \d+(?: \(line \d+ column \d+\))?/);
|
|
@@ -8253,19 +8502,19 @@ function parseFailureDetail(err) {
|
|
|
8253
8502
|
}
|
|
8254
8503
|
function loadConfig39() {
|
|
8255
8504
|
if (cachedConfig40) return cachedConfig40;
|
|
8256
|
-
if (!
|
|
8505
|
+
if (!existsSync50(CONFIG_PATH47)) {
|
|
8257
8506
|
cachedConfig40 = {};
|
|
8258
8507
|
return cachedConfig40;
|
|
8259
8508
|
}
|
|
8260
|
-
const raw =
|
|
8509
|
+
const raw = readFileSync52(CONFIG_PATH47, "utf8");
|
|
8261
8510
|
let parsed;
|
|
8262
8511
|
try {
|
|
8263
8512
|
parsed = JSON.parse(raw);
|
|
8264
8513
|
} catch (err) {
|
|
8265
|
-
throw new Error(`Failed to parse ${
|
|
8514
|
+
throw new Error(`Failed to parse ${CONFIG_PATH47}: ${parseFailureDetail(err)}`);
|
|
8266
8515
|
}
|
|
8267
8516
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
8268
|
-
throw new Error(`Invalid config in ${
|
|
8517
|
+
throw new Error(`Invalid config in ${CONFIG_PATH47}: expected a JSON object`);
|
|
8269
8518
|
}
|
|
8270
8519
|
cachedConfig40 = parsed;
|
|
8271
8520
|
return cachedConfig40;
|
|
@@ -8280,7 +8529,7 @@ function zoneSetting() {
|
|
|
8280
8529
|
const fromEnv = process.env.BRIGHTDATA_UNLOCKER_ZONE;
|
|
8281
8530
|
if (typeof fromEnv === "string" && fromEnv.trim()) return { raw: fromEnv.trim(), label: "BRIGHTDATA_UNLOCKER_ZONE" };
|
|
8282
8531
|
const configured = loadConfig39().brightdataUnlockerZone;
|
|
8283
|
-
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${
|
|
8532
|
+
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${CONFIG_PATH47}` };
|
|
8284
8533
|
return null;
|
|
8285
8534
|
}
|
|
8286
8535
|
function getZone() {
|
|
@@ -8298,7 +8547,7 @@ function requireZone() {
|
|
|
8298
8547
|
}
|
|
8299
8548
|
throw new Error(
|
|
8300
8549
|
`Bright Data Web Unlocker zone not configured. Either:
|
|
8301
|
-
1. Set brightdataUnlockerZone in ${
|
|
8550
|
+
1. Set brightdataUnlockerZone in ${CONFIG_PATH47}
|
|
8302
8551
|
2. Set BRIGHTDATA_UNLOCKER_ZONE environment variable
|
|
8303
8552
|
The zone must be of type "unblocker"; a SERP zone will not serve Web Unlocker requests.`
|
|
8304
8553
|
);
|
|
@@ -8313,7 +8562,7 @@ async function getApiKey27(signal) {
|
|
|
8313
8562
|
if (!apiKey) {
|
|
8314
8563
|
throw new Error(
|
|
8315
8564
|
`Bright Data API key not found. Either:
|
|
8316
|
-
1. Create ${
|
|
8565
|
+
1. Create ${CONFIG_PATH47} with { "brightdataApiKey": "your-key" }
|
|
8317
8566
|
2. Set BRIGHTDATA_API_KEY environment variable
|
|
8318
8567
|
Get a key at https://brightdata.com/cp/setting/users`
|
|
8319
8568
|
);
|
|
@@ -8422,14 +8671,14 @@ async function extractWithBrightDataUnlocker(url, signal, options) {
|
|
|
8422
8671
|
if (!content) return null;
|
|
8423
8672
|
return { url, title: headingTitle(content), content, error: null };
|
|
8424
8673
|
}
|
|
8425
|
-
var
|
|
8674
|
+
var CONFIG_PATH47, BRIGHTDATA_REQUEST_URL, EXTRACT_TIMEOUT_MS3, DEFAULT_MAX_REDIRECTS3, REDIRECT_STATUSES3, ZONE_PATTERN2, cachedConfig40;
|
|
8426
8675
|
var init_brightdata_unlocker = __esm({
|
|
8427
8676
|
"brightdata-unlocker.ts"() {
|
|
8428
8677
|
init_activity();
|
|
8429
8678
|
init_credential_source();
|
|
8430
8679
|
init_ssrf_protection();
|
|
8431
8680
|
init_utils();
|
|
8432
|
-
|
|
8681
|
+
CONFIG_PATH47 = getWebSearchConfigPath();
|
|
8433
8682
|
BRIGHTDATA_REQUEST_URL = "https://api.brightdata.com/request";
|
|
8434
8683
|
EXTRACT_TIMEOUT_MS3 = 6e4;
|
|
8435
8684
|
DEFAULT_MAX_REDIRECTS3 = 5;
|
|
@@ -8441,7 +8690,7 @@ var init_brightdata_unlocker = __esm({
|
|
|
8441
8690
|
|
|
8442
8691
|
// video-extract.ts
|
|
8443
8692
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
8444
|
-
import { existsSync as
|
|
8693
|
+
import { existsSync as existsSync51, readFileSync as readFileSync53, readdirSync as readdirSync4, statSync as statSync3 } from "node:fs";
|
|
8445
8694
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
8446
8695
|
import { resolve, extname as extname2, basename as basename4, join as join7, dirname as dirname2 } from "node:path";
|
|
8447
8696
|
function shouldRethrow3(err) {
|
|
@@ -8462,17 +8711,17 @@ function normalizeMaxSizeMB(value, fallback) {
|
|
|
8462
8711
|
}
|
|
8463
8712
|
function loadVideoConfig() {
|
|
8464
8713
|
if (cachedVideoConfig) return cachedVideoConfig;
|
|
8465
|
-
if (!
|
|
8714
|
+
if (!existsSync51(CONFIG_PATH48)) {
|
|
8466
8715
|
cachedVideoConfig = { ...VIDEO_CONFIG_DEFAULTS };
|
|
8467
8716
|
return cachedVideoConfig;
|
|
8468
8717
|
}
|
|
8469
|
-
const rawText =
|
|
8718
|
+
const rawText = readFileSync53(CONFIG_PATH48, "utf-8");
|
|
8470
8719
|
let raw;
|
|
8471
8720
|
try {
|
|
8472
8721
|
raw = JSON.parse(rawText);
|
|
8473
8722
|
} catch (err) {
|
|
8474
8723
|
const message = err instanceof Error ? err.message : String(err);
|
|
8475
|
-
throw new Error(`Failed to parse ${
|
|
8724
|
+
throw new Error(`Failed to parse ${CONFIG_PATH48}: ${message}`);
|
|
8476
8725
|
}
|
|
8477
8726
|
const v = raw.video ?? {};
|
|
8478
8727
|
cachedVideoConfig = {
|
|
@@ -8518,10 +8767,10 @@ function isVideoFile(input) {
|
|
|
8518
8767
|
}
|
|
8519
8768
|
function resolveFilePath(filePath) {
|
|
8520
8769
|
const absolutePath = resolve(filePath);
|
|
8521
|
-
if (
|
|
8770
|
+
if (existsSync51(absolutePath)) return absolutePath;
|
|
8522
8771
|
const dir = dirname2(absolutePath);
|
|
8523
8772
|
const base = basename4(absolutePath);
|
|
8524
|
-
if (!
|
|
8773
|
+
if (!existsSync51(dir)) return null;
|
|
8525
8774
|
try {
|
|
8526
8775
|
const normalizedBase = normalizeSpaces(base);
|
|
8527
8776
|
const match = readdirSync4(dir).find((f) => normalizeSpaces(f) === normalizedBase);
|
|
@@ -8679,8 +8928,9 @@ async function uploadToFilesApi(info, apiKey, signal) {
|
|
|
8679
8928
|
}
|
|
8680
8929
|
const uploadUrl = initRes.headers.get("x-goog-upload-url");
|
|
8681
8930
|
if (!uploadUrl) throw new Error("No upload URL in response headers");
|
|
8931
|
+
const routedUploadUrl = rewriteUploadUrlOrigin(uploadUrl);
|
|
8682
8932
|
const fileData = await readFile2(info.absolutePath);
|
|
8683
|
-
const uploadRes = await fetchGeminiApi(
|
|
8933
|
+
const uploadRes = await fetchGeminiApi(routedUploadUrl, {
|
|
8684
8934
|
method: "PUT",
|
|
8685
8935
|
headers: {
|
|
8686
8936
|
"Content-Length": String(info.sizeBytes),
|
|
@@ -8719,7 +8969,7 @@ function deleteGeminiFile(fileName, apiKey) {
|
|
|
8719
8969
|
function extractVideoTitle(text4, filePath) {
|
|
8720
8970
|
return extractHeadingTitle(text4) ?? basename4(filePath, extname2(filePath));
|
|
8721
8971
|
}
|
|
8722
|
-
var
|
|
8972
|
+
var CONFIG_PATH48, DEFAULT_VIDEO_PROMPT, VIDEO_EXTENSIONS, VIDEO_CONFIG_DEFAULTS, cachedVideoConfig;
|
|
8723
8973
|
var init_video_extract = __esm({
|
|
8724
8974
|
"video-extract.ts"() {
|
|
8725
8975
|
init_activity();
|
|
@@ -8728,7 +8978,7 @@ var init_video_extract = __esm({
|
|
|
8728
8978
|
init_gemini_api();
|
|
8729
8979
|
init_extract();
|
|
8730
8980
|
init_utils();
|
|
8731
|
-
|
|
8981
|
+
CONFIG_PATH48 = getWebSearchConfigPath();
|
|
8732
8982
|
DEFAULT_VIDEO_PROMPT = `Extract the complete content of this video. Include:
|
|
8733
8983
|
1. Video title (infer from content if not explicit), duration
|
|
8734
8984
|
2. A brief summary (2-3 sentences)
|
|
@@ -9213,13 +9463,13 @@ __export(extract_exports, {
|
|
|
9213
9463
|
readPDFResponseBuffer: () => readPDFResponseBuffer,
|
|
9214
9464
|
resolveFetchTimeoutMs: () => resolveFetchTimeoutMs
|
|
9215
9465
|
});
|
|
9216
|
-
import { existsSync as
|
|
9466
|
+
import { existsSync as existsSync52, readFileSync as readFileSync54 } from "node:fs";
|
|
9217
9467
|
import pLimit from "p-limit";
|
|
9218
9468
|
function loadFetchTimeoutMs() {
|
|
9219
|
-
if (!
|
|
9469
|
+
if (!existsSync52(WEB_SEARCH_CONFIG_PATH3)) return DEFAULT_TIMEOUT_MS4;
|
|
9220
9470
|
let raw;
|
|
9221
9471
|
try {
|
|
9222
|
-
raw = JSON.parse(
|
|
9472
|
+
raw = JSON.parse(readFileSync54(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
9223
9473
|
} catch (err) {
|
|
9224
9474
|
const message = err instanceof Error ? err.message : String(err);
|
|
9225
9475
|
throw new Error(`Failed to parse ${WEB_SEARCH_CONFIG_PATH3}: ${message}`);
|
|
@@ -9228,12 +9478,12 @@ function loadFetchTimeoutMs() {
|
|
|
9228
9478
|
throw new Error(`Invalid config in ${WEB_SEARCH_CONFIG_PATH3}: expected a JSON object`);
|
|
9229
9479
|
}
|
|
9230
9480
|
const fetchConfig = raw.fetch;
|
|
9231
|
-
if (fetchConfig === void 0) return
|
|
9481
|
+
if (fetchConfig === void 0) return DEFAULT_TIMEOUT_MS4;
|
|
9232
9482
|
if (!fetchConfig || typeof fetchConfig !== "object" || Array.isArray(fetchConfig)) {
|
|
9233
9483
|
throw new Error(`fetch in ${WEB_SEARCH_CONFIG_PATH3} must be an object`);
|
|
9234
9484
|
}
|
|
9235
9485
|
const value = fetchConfig.timeout;
|
|
9236
|
-
if (value === void 0) return
|
|
9486
|
+
if (value === void 0) return DEFAULT_TIMEOUT_MS4;
|
|
9237
9487
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
9238
9488
|
throw new Error(`Invalid fetch.timeout in ${WEB_SEARCH_CONFIG_PATH3}: expected a positive finite number of seconds, got ${JSON.stringify(value)}`);
|
|
9239
9489
|
}
|
|
@@ -9294,7 +9544,7 @@ function isAbortException2(err) {
|
|
|
9294
9544
|
return err instanceof DOMException && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
9295
9545
|
}
|
|
9296
9546
|
function isRedirectPolicyError(message) {
|
|
9297
|
-
return message.startsWith("Authenticated fetch refused cross-origin redirect") || message.startsWith("Blocked internal ") || message.startsWith("Blocked hostname by fetch_content domain policy") || message.startsWith("Hostname not allowed by fetch_content domain policy") || message.startsWith("Too many redirects fetching ") || message === "Only HTTP and HTTPS URLs can be fetched remotely" || message === "URL must include a hostname" || message.startsWith("Failed to resolve ");
|
|
9547
|
+
return message.startsWith("Authenticated fetch refused cross-origin redirect") || message.startsWith("Refused cross-origin redirect by fetch_content redirect policy") || message.startsWith("Blocked internal ") || message.startsWith("Blocked hostname by fetch_content domain policy") || message.startsWith("Hostname not allowed by fetch_content domain policy") || message.startsWith("Too many redirects fetching ") || message === "Only HTTP and HTTPS URLs can be fetched remotely" || message === "URL must include a hostname" || message.startsWith("Failed to resolve ");
|
|
9298
9548
|
}
|
|
9299
9549
|
function isNonRecoverableHttpError(error) {
|
|
9300
9550
|
return !!error && (NON_RECOVERABLE_ERRORS.some((prefix) => error.startsWith(prefix)) || isRedirectPolicyError(error) || isConfigParseError(error));
|
|
@@ -9306,6 +9556,9 @@ function imageGateError() {
|
|
|
9306
9556
|
return errorMessage32(err);
|
|
9307
9557
|
}
|
|
9308
9558
|
}
|
|
9559
|
+
function redirectPolicyRouteRefusal(url, path) {
|
|
9560
|
+
return { url, title: "", content: "", error: `Extraction path ${path} is disabled by the fetch_content same-origin redirect policy because its redirect chain cannot be observed` };
|
|
9561
|
+
}
|
|
9309
9562
|
async function resolveAuthCookieHeader(url, profile) {
|
|
9310
9563
|
const parsed = assertAuthFetchUrl(profile, url.toString());
|
|
9311
9564
|
const result = await getBrowserCookiesForHosts({ hosts: [parsed.hostname], profile: profile.chromeProfile, requestUrl: parsed });
|
|
@@ -9324,6 +9577,7 @@ async function fetchAuthenticatedRemoteUrl(url, init, validationOptions, profile
|
|
|
9324
9577
|
proxy: validationOptions.proxy,
|
|
9325
9578
|
...validationOptions.lookup ? { lookup: validationOptions.lookup } : {}
|
|
9326
9579
|
});
|
|
9580
|
+
const originalOrigin = current.origin;
|
|
9327
9581
|
let requestInit = init;
|
|
9328
9582
|
for (let redirects = 0; redirects <= 5; redirects++) {
|
|
9329
9583
|
const cookieHeader = await resolveAuthCookieHeader(current, profile);
|
|
@@ -9334,7 +9588,11 @@ async function fetchAuthenticatedRemoteUrl(url, init, validationOptions, profile
|
|
|
9334
9588
|
if (!location) return response;
|
|
9335
9589
|
if (redirects === 5) throw new Error(`Too many redirects fetching ${current.toString()}`);
|
|
9336
9590
|
const from = current;
|
|
9337
|
-
|
|
9591
|
+
const next = new URL(location, current);
|
|
9592
|
+
if (validationOptions.redirects === "same-origin" && next.origin !== originalOrigin) {
|
|
9593
|
+
throw new Error(`Refused cross-origin redirect by fetch_content redirect policy: ${originalOrigin} -> ${next.origin}`);
|
|
9594
|
+
}
|
|
9595
|
+
current = await validateRemoteUrl(next, {
|
|
9338
9596
|
allowRanges: validationOptions.ssrf.allowRanges,
|
|
9339
9597
|
trustEnvProxy: validationOptions.ssrf.trustEnvProxy,
|
|
9340
9598
|
domainPolicy: validationOptions.domainPolicy,
|
|
@@ -9350,12 +9608,12 @@ async function fetchAuthenticatedRemoteUrl(url, init, validationOptions, profile
|
|
|
9350
9608
|
throw new Error(`Too many redirects fetching ${current.toString()}`);
|
|
9351
9609
|
}
|
|
9352
9610
|
function loadFetchRouting() {
|
|
9353
|
-
if (!
|
|
9611
|
+
if (!existsSync52(WEB_SEARCH_CONFIG_PATH3)) {
|
|
9354
9612
|
return { providers: DEFAULT_FETCH_PROVIDER_ORDER, allowRemoteHostedProviders: false };
|
|
9355
9613
|
}
|
|
9356
9614
|
let raw;
|
|
9357
9615
|
try {
|
|
9358
|
-
const parsed = JSON.parse(
|
|
9616
|
+
const parsed = JSON.parse(readFileSync54(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
9359
9617
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9360
9618
|
throw new Error("expected a JSON object");
|
|
9361
9619
|
}
|
|
@@ -9553,6 +9811,12 @@ async function extractContent(url, signal, options) {
|
|
|
9553
9811
|
if (signal?.aborted) {
|
|
9554
9812
|
return { url, title: "", content: "", error: "Aborted" };
|
|
9555
9813
|
}
|
|
9814
|
+
let redirectPolicy;
|
|
9815
|
+
try {
|
|
9816
|
+
redirectPolicy = options?.redirects ?? loadFetchContentRedirectPolicy();
|
|
9817
|
+
} catch (err) {
|
|
9818
|
+
return { url, title: "", content: "", error: errorMessage32(err) };
|
|
9819
|
+
}
|
|
9556
9820
|
let remoteUrl = null;
|
|
9557
9821
|
try {
|
|
9558
9822
|
const parsed = new URL(url);
|
|
@@ -9581,6 +9845,11 @@ async function extractContent(url, signal, options) {
|
|
|
9581
9845
|
return { url, title: "", content: "", error: errorMessage32(err) };
|
|
9582
9846
|
}
|
|
9583
9847
|
}
|
|
9848
|
+
if (redirectPolicy) {
|
|
9849
|
+
if (parseGitHubIssuePrUrl(url)) return redirectPolicyRouteRefusal(url, "GitHub issue/PR");
|
|
9850
|
+
if (parseGitHubUrl(url)) return redirectPolicyRouteRefusal(url, "GitHub repository");
|
|
9851
|
+
if (isYouTubeURL(url).isYouTube) return redirectPolicyRouteRefusal(url, "YouTube");
|
|
9852
|
+
}
|
|
9584
9853
|
if (options?.frames || options?.timestamp) {
|
|
9585
9854
|
const disabled = imageGateError();
|
|
9586
9855
|
if (disabled) return { url, title: "", content: "", error: disabled };
|
|
@@ -9675,7 +9944,7 @@ async function extractContent(url, signal, options) {
|
|
|
9675
9944
|
if ("error" in frame) {
|
|
9676
9945
|
return { url, title: `Frame at ${options.timestamp}`, content: frame.error, error: frame.error };
|
|
9677
9946
|
}
|
|
9678
|
-
return { url, title: `Frame at ${options.timestamp}`, content: `Video frame at ${options.timestamp}`, error: null, thumbnail: frame };
|
|
9947
|
+
return { url, title: `Frame at ${options.timestamp}`, content: `Video frame at ${options.timestamp}`, error: null, thumbnail: frame, mimeType: frame.mimeType };
|
|
9679
9948
|
}
|
|
9680
9949
|
const localVideo2 = safeVideoInfo(url);
|
|
9681
9950
|
if (localVideo2.status === "invalid") {
|
|
@@ -9699,7 +9968,7 @@ async function extractContent(url, signal, options) {
|
|
|
9699
9968
|
if ("error" in frame) {
|
|
9700
9969
|
return { url, title: `Frame at ${options.timestamp}`, content: frame.error, error: frame.error };
|
|
9701
9970
|
}
|
|
9702
|
-
return { url, title: `Frame at ${options.timestamp}`, content: `Video frame at ${options.timestamp}`, error: null, thumbnail: frame };
|
|
9971
|
+
return { url, title: `Frame at ${options.timestamp}`, content: `Video frame at ${options.timestamp}`, error: null, thumbnail: frame, mimeType: frame.mimeType };
|
|
9703
9972
|
}
|
|
9704
9973
|
return { url, title: "", content: "", error: "Timestamp extraction only works with YouTube and local video files" };
|
|
9705
9974
|
}
|
|
@@ -9783,7 +10052,10 @@ async function extractContent(url, signal, options) {
|
|
|
9783
10052
|
} catch (err) {
|
|
9784
10053
|
return { url, title: "", content: "", error: errorMessage32(err) };
|
|
9785
10054
|
}
|
|
9786
|
-
|
|
10055
|
+
if (redirectPolicy && !fetchRouting.providers.includes("http")) {
|
|
10056
|
+
return redirectPolicyRouteRefusal(url, fetchRouting.providers[0]);
|
|
10057
|
+
}
|
|
10058
|
+
const providerOrder = redirectPolicy ? ["http"] : remoteUrl && !fetchRouting.allowRemoteHostedProviders ? fetchRouting.providers.filter((provider) => !REMOTE_HOSTED_FETCH_PROVIDERS.has(provider)) : fetchRouting.providers;
|
|
9787
10059
|
if (providerOrder.length === 0) {
|
|
9788
10060
|
return {
|
|
9789
10061
|
url,
|
|
@@ -10008,6 +10280,7 @@ async function extractContent(url, signal, options) {
|
|
|
10008
10280
|
if (finalHttpResult?.status === 404 || finalHttpResult?.status === 410) {
|
|
10009
10281
|
return { ...finalHttpResult, error: notFoundGuidance(finalHttpResult, options?.toolNames) };
|
|
10010
10282
|
}
|
|
10283
|
+
if (redirectPolicy && finalHttpResult) return finalHttpResult;
|
|
10011
10284
|
const searchToolName = options?.toolNames?.webSearch;
|
|
10012
10285
|
const jinaHint = jinaReaderGuidance(fetchRouting, providerOrder, Boolean(remoteUrl) && !fetchRouting.allowRemoteHostedProviders);
|
|
10013
10286
|
const guidance = [
|
|
@@ -10118,6 +10391,7 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
10118
10391
|
try {
|
|
10119
10392
|
const ssrf = loadSsrfConfig();
|
|
10120
10393
|
const domainPolicy = loadFetchContentDomainPolicy();
|
|
10394
|
+
const redirects = options?.redirects ?? loadFetchContentRedirectPolicy();
|
|
10121
10395
|
const authProfile = options?.authFetchProfile;
|
|
10122
10396
|
const requestInit = {
|
|
10123
10397
|
signal: controller.signal,
|
|
@@ -10134,13 +10408,14 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
10134
10408
|
"Upgrade-Insecure-Requests": "1"
|
|
10135
10409
|
}
|
|
10136
10410
|
};
|
|
10137
|
-
const response = authProfile ? await fetchAuthenticatedRemoteUrl(url, requestInit, { ssrf, domainPolicy, proxy: options?.proxy, ...options?.lookup ? { lookup: options.lookup } : {} }, authProfile) : await fetchRemoteUrl(
|
|
10411
|
+
const response = authProfile ? await fetchAuthenticatedRemoteUrl(url, requestInit, { ssrf, domainPolicy, redirects, proxy: options?.proxy, ...options?.lookup ? { lookup: options.lookup } : {} }, authProfile) : await fetchRemoteUrl(
|
|
10138
10412
|
url,
|
|
10139
10413
|
requestInit,
|
|
10140
10414
|
{
|
|
10141
10415
|
allowRanges: ssrf.allowRanges,
|
|
10142
10416
|
trustEnvProxy: ssrf.trustEnvProxy,
|
|
10143
10417
|
domainPolicy,
|
|
10418
|
+
redirects,
|
|
10144
10419
|
proxy: options?.proxy,
|
|
10145
10420
|
...options?.lookup ? { lookup: options.lookup } : {}
|
|
10146
10421
|
}
|
|
@@ -10180,7 +10455,8 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
10180
10455
|
if (options?.mode === "raw") {
|
|
10181
10456
|
if (!isTextContentType(contentType)) {
|
|
10182
10457
|
activityMonitor.logComplete(activityId, response.status);
|
|
10183
|
-
|
|
10458
|
+
const hint = isPDFContent ? '; retry without mode for Markdown, or with mode "answer" and a prompt' : "";
|
|
10459
|
+
return { url, title: "", content: "", error: `Unsupported content type in raw mode: ${mimeType || "missing"}${hint}`, mimeType, status: response.status };
|
|
10184
10460
|
}
|
|
10185
10461
|
const text5 = await readTextResponseWithLimit(response, maxResponseSize);
|
|
10186
10462
|
activityMonitor.logComplete(activityId, response.status);
|
|
@@ -10229,8 +10505,8 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
10229
10505
|
title: result.title,
|
|
10230
10506
|
content: options?.mode === "answer" ? result.content : `PDF extracted and saved to: ${result.outputPath}
|
|
10231
10507
|
|
|
10232
|
-
Pages: ${result.pages}
|
|
10233
|
-
Characters: ${result.chars}`,
|
|
10508
|
+
${result.pages > 0 ? `Pages: ${result.pages}
|
|
10509
|
+
` : ""}Characters: ${result.chars}`,
|
|
10234
10510
|
error: null
|
|
10235
10511
|
};
|
|
10236
10512
|
} catch (err) {
|
|
@@ -10403,7 +10679,7 @@ async function fetchAllContent(urls, signal, options) {
|
|
|
10403
10679
|
return sanitized.omissions.length > 0 ? { ...result, content: sanitized.text } : result;
|
|
10404
10680
|
});
|
|
10405
10681
|
}
|
|
10406
|
-
var
|
|
10682
|
+
var DEFAULT_TIMEOUT_MS4, MAX_CONFIGURED_TIMEOUT_MS, CONCURRENT_LIMIT, WEB_SEARCH_CONFIG_PATH3, NON_RECOVERABLE_ERRORS, MIN_USEFUL_CONTENT2, SUPPORTED_IMAGE_TYPES, FETCH_PROVIDERS, DEFAULT_FETCH_PROVIDER_ORDER, REMOTE_HOSTED_FETCH_PROVIDERS, REDIRECT_STATUSES4, turndownInstance, fetchLimit, JINA_READER_BASE, DEFAULT_RANGE_FRAMES, MIN_FRAME_INTERVAL, BROWSER_ACCEPT, MARKDOWN_FIRST_ACCEPT;
|
|
10407
10683
|
var init_extract = __esm({
|
|
10408
10684
|
"extract.ts"() {
|
|
10409
10685
|
init_activity();
|
|
@@ -10433,7 +10709,7 @@ var init_extract = __esm({
|
|
|
10433
10709
|
init_chrome_cookies();
|
|
10434
10710
|
init_data_uri_sanitize();
|
|
10435
10711
|
init_ssrf_protection();
|
|
10436
|
-
|
|
10712
|
+
DEFAULT_TIMEOUT_MS4 = 3e4;
|
|
10437
10713
|
MAX_CONFIGURED_TIMEOUT_MS = 2147483647;
|
|
10438
10714
|
CONCURRENT_LIMIT = 3;
|
|
10439
10715
|
WEB_SEARCH_CONFIG_PATH3 = getWebSearchConfigPath();
|
|
@@ -10459,7 +10735,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
10459
10735
|
// package.json
|
|
10460
10736
|
var package_default = {
|
|
10461
10737
|
name: "pi-web-access",
|
|
10462
|
-
version: "0.
|
|
10738
|
+
version: "0.40.0",
|
|
10463
10739
|
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, You.com, SearXNG, degoog, Exa, Perplexity, Gemini, Kimi, and Mistral.",
|
|
10464
10740
|
type: "module",
|
|
10465
10741
|
bin: {
|
|
@@ -19560,7 +19836,7 @@ init_credential_source();
|
|
|
19560
19836
|
init_utils();
|
|
19561
19837
|
var BRAVE_API_BASE_URL = "https://api.search.brave.com/res/v1";
|
|
19562
19838
|
var CONFIG_PATH6 = getWebSearchConfigPath();
|
|
19563
|
-
var
|
|
19839
|
+
var SEARCH_TIMEOUT_MS2 = 3e4;
|
|
19564
19840
|
var braveRateLimit = new BraveRateLimitCoordinator();
|
|
19565
19841
|
var cachedConfig6 = null;
|
|
19566
19842
|
function loadConfig6() {
|
|
@@ -19635,6 +19911,31 @@ function matchesDomainFilters(url, filters) {
|
|
|
19635
19911
|
}
|
|
19636
19912
|
return !filters.blocked.some((domain) => hostMatchesDomain(hostname2, domain));
|
|
19637
19913
|
}
|
|
19914
|
+
var HTML_ENTITIES = {
|
|
19915
|
+
"&": "&",
|
|
19916
|
+
"<": "<",
|
|
19917
|
+
">": ">",
|
|
19918
|
+
""": '"',
|
|
19919
|
+
"'": "'",
|
|
19920
|
+
" ": " ",
|
|
19921
|
+
"—": "\u2014",
|
|
19922
|
+
"–": "\u2013",
|
|
19923
|
+
"…": "\u2026",
|
|
19924
|
+
"’": "\u2019",
|
|
19925
|
+
"‘": "\u2018",
|
|
19926
|
+
"”": "\u201D",
|
|
19927
|
+
"“": "\u201C",
|
|
19928
|
+
"·": "\xB7",
|
|
19929
|
+
"•": "\u2022",
|
|
19930
|
+
"°": "\xB0"
|
|
19931
|
+
};
|
|
19932
|
+
function stripHtml(value) {
|
|
19933
|
+
return value.replace(/<[^>]*>/g, "").replace(/&(?:#(x?)([0-9a-f]+)|[a-z]+);/gi, (entity, hex, digits) => {
|
|
19934
|
+
if (!digits) return HTML_ENTITIES[entity.toLowerCase()] ?? entity;
|
|
19935
|
+
const code = Number.parseInt(digits, hex ? 16 : 10);
|
|
19936
|
+
return code <= 1114111 && (code < 55296 || code > 57343) ? String.fromCodePoint(code) : entity;
|
|
19937
|
+
}).trim();
|
|
19938
|
+
}
|
|
19638
19939
|
function isBraveAvailable() {
|
|
19639
19940
|
return hasCredentialSource({
|
|
19640
19941
|
provider: "Brave",
|
|
@@ -19672,7 +19973,7 @@ Get a key at https://brave.com/search/api/`
|
|
|
19672
19973
|
if (freshness) params.set("freshness", freshness);
|
|
19673
19974
|
}
|
|
19674
19975
|
try {
|
|
19675
|
-
const searchDeadline = AbortSignal.timeout(
|
|
19976
|
+
const searchDeadline = AbortSignal.timeout(SEARCH_TIMEOUT_MS2);
|
|
19676
19977
|
const searchSignal = options.signal ? AbortSignal.any([searchDeadline, options.signal]) : searchDeadline;
|
|
19677
19978
|
const response = await braveRateLimit.run(async () => {
|
|
19678
19979
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
@@ -19706,9 +20007,9 @@ Get a key at https://brave.com/search/api/`
|
|
|
19706
20007
|
for (const item of data.web?.results ?? []) {
|
|
19707
20008
|
if (!item.url || !matchesDomainFilters(item.url, domainFilters)) continue;
|
|
19708
20009
|
results.push({
|
|
19709
|
-
title: item.title || item.url,
|
|
20010
|
+
title: stripHtml(item.title || "") || item.url,
|
|
19710
20011
|
url: item.url,
|
|
19711
|
-
snippet: item.description || ""
|
|
20012
|
+
snippet: stripHtml(item.description || "")
|
|
19712
20013
|
});
|
|
19713
20014
|
if (results.length >= numResults) break;
|
|
19714
20015
|
}
|
|
@@ -19743,7 +20044,7 @@ import { existsSync as existsSync9, readFileSync as readFileSync10 } from "node:
|
|
|
19743
20044
|
var OPENAI_RESPONSES_URL = "https://api.openai.com/v1/responses";
|
|
19744
20045
|
var CODEX_RESPONSES_URL = "https://chatgpt.com/backend-api/codex/responses";
|
|
19745
20046
|
var CONFIG_PATH7 = getWebSearchConfigPath();
|
|
19746
|
-
var
|
|
20047
|
+
var SEARCH_TIMEOUT_MS3 = 6e4;
|
|
19747
20048
|
var EXCLUDED_MODEL_SEGMENTS = /* @__PURE__ */ new Set(["pro", "ultra"]);
|
|
19748
20049
|
var MODEL_PREFERENCE = [
|
|
19749
20050
|
(id) => id.includes("luna"),
|
|
@@ -20345,7 +20646,7 @@ async function runOpenAISearch(query, options, auth, ctx) {
|
|
|
20345
20646
|
method: "POST",
|
|
20346
20647
|
headers: requestHeaders,
|
|
20347
20648
|
body: JSON.stringify(body),
|
|
20348
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
20649
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS3), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS3)
|
|
20349
20650
|
}, ["Authorization", "x-opencode-session", "x-opencode-client", "chatgpt-account-id", ...Object.keys(auth.headers)]);
|
|
20350
20651
|
if (!response.ok) {
|
|
20351
20652
|
activityMonitor.logError(activityId, `HTTP ${response.status}`);
|
|
@@ -20416,7 +20717,7 @@ init_utils();
|
|
|
20416
20717
|
import { existsSync as existsSync13, readFileSync as readFileSync14 } from "node:fs";
|
|
20417
20718
|
var SEARCHINFINITY_SEARCH_URL = "https://torchlight.byteintlapi.com/search_api/web_search";
|
|
20418
20719
|
var CONFIG_PATH12 = getWebSearchConfigPath();
|
|
20419
|
-
var
|
|
20720
|
+
var SEARCH_TIMEOUT_MS7 = 3e4;
|
|
20420
20721
|
var cachedConfig11 = null;
|
|
20421
20722
|
function loadConfig11() {
|
|
20422
20723
|
if (cachedConfig11) return cachedConfig11;
|
|
@@ -20514,7 +20815,7 @@ async function searchinfinityJsonRequest(apiKey, body, signal) {
|
|
|
20514
20815
|
"Content-Type": "application/json"
|
|
20515
20816
|
},
|
|
20516
20817
|
body: JSON.stringify(body),
|
|
20517
|
-
signal: requestSignal6(signal,
|
|
20818
|
+
signal: requestSignal6(signal, SEARCH_TIMEOUT_MS7)
|
|
20518
20819
|
});
|
|
20519
20820
|
} catch (err) {
|
|
20520
20821
|
const message = errorMessage5(err);
|
|
@@ -20595,7 +20896,7 @@ init_utils();
|
|
|
20595
20896
|
import { existsSync as existsSync15, readFileSync as readFileSync16 } from "node:fs";
|
|
20596
20897
|
var TAVILY_API_BASE_URL = "https://api.tavily.com";
|
|
20597
20898
|
var CONFIG_PATH14 = getWebSearchConfigPath();
|
|
20598
|
-
var
|
|
20899
|
+
var SEARCH_TIMEOUT_MS9 = 6e4;
|
|
20599
20900
|
var cachedConfig13 = null;
|
|
20600
20901
|
function loadConfig13() {
|
|
20601
20902
|
if (cachedConfig13) return cachedConfig13;
|
|
@@ -20668,7 +20969,7 @@ function mapDomainFilter6(domainFilter) {
|
|
|
20668
20969
|
};
|
|
20669
20970
|
}
|
|
20670
20971
|
function requestSignal8(signal) {
|
|
20671
|
-
const timeout = AbortSignal.timeout(
|
|
20972
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS9);
|
|
20672
20973
|
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
20673
20974
|
}
|
|
20674
20975
|
function errorMessage7(err) {
|
|
@@ -20806,7 +21107,7 @@ init_utils();
|
|
|
20806
21107
|
import { existsSync as existsSync16, readFileSync as readFileSync17 } from "node:fs";
|
|
20807
21108
|
var YOU_SEARCH_URL = "https://ydc-index.io/v1/search";
|
|
20808
21109
|
var CONFIG_PATH15 = getWebSearchConfigPath();
|
|
20809
|
-
var
|
|
21110
|
+
var SEARCH_TIMEOUT_MS10 = 6e4;
|
|
20810
21111
|
var cachedConfig14 = null;
|
|
20811
21112
|
function loadConfig14() {
|
|
20812
21113
|
if (cachedConfig14) return cachedConfig14;
|
|
@@ -20881,7 +21182,7 @@ async function searchWithYou(query, options = {}) {
|
|
|
20881
21182
|
...mapDomainFilter7(options.domainFilter)
|
|
20882
21183
|
};
|
|
20883
21184
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
20884
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
21185
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS10);
|
|
20885
21186
|
let response;
|
|
20886
21187
|
let entries;
|
|
20887
21188
|
try {
|
|
@@ -20910,7 +21211,7 @@ async function searchWithYou(query, options = {}) {
|
|
|
20910
21211
|
}
|
|
20911
21212
|
const message = errorMessage8(err);
|
|
20912
21213
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
20913
|
-
const outgoing = providerTimeout ? new Error(`You.com request timed out after ${Math.round(
|
|
21214
|
+
const outgoing = providerTimeout ? new Error(`You.com request timed out after ${Math.round(SEARCH_TIMEOUT_MS10 / 1e3)}s`) : (() => {
|
|
20914
21215
|
const redactedMessage = redactCredential(message, apiKey);
|
|
20915
21216
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
20916
21217
|
const redactedError = new Error(redactedMessage);
|
|
@@ -20956,7 +21257,7 @@ init_utils();
|
|
|
20956
21257
|
import { existsSync as existsSync19, readFileSync as readFileSync20 } from "node:fs";
|
|
20957
21258
|
var JINA_SEARCH_BASE_URL = "https://s.jina.ai/";
|
|
20958
21259
|
var CONFIG_PATH17 = getWebSearchConfigPath();
|
|
20959
|
-
var
|
|
21260
|
+
var SEARCH_TIMEOUT_MS12 = 6e4;
|
|
20960
21261
|
var cachedConfig16 = null;
|
|
20961
21262
|
function loadConfig16() {
|
|
20962
21263
|
if (cachedConfig16) return cachedConfig16;
|
|
@@ -21032,7 +21333,7 @@ function buildSearchRequest(query, options, numResults) {
|
|
|
21032
21333
|
return { url: url.toString(), filters };
|
|
21033
21334
|
}
|
|
21034
21335
|
function requestSignal10(signal) {
|
|
21035
|
-
const timeout = AbortSignal.timeout(
|
|
21336
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS12);
|
|
21036
21337
|
return {
|
|
21037
21338
|
timeout,
|
|
21038
21339
|
signal: signal ? AbortSignal.any([signal, timeout]) : timeout
|
|
@@ -21176,7 +21477,7 @@ init_utils();
|
|
|
21176
21477
|
import { existsSync as existsSync20, readFileSync as readFileSync21 } from "node:fs";
|
|
21177
21478
|
var SERPDIVE_API_URL = "https://api.serpdive.com/v1/search";
|
|
21178
21479
|
var CONFIG_PATH18 = getWebSearchConfigPath();
|
|
21179
|
-
var
|
|
21480
|
+
var SEARCH_TIMEOUT_MS13 = 6e4;
|
|
21180
21481
|
var MODELS = ["krill", "mako", "moby"];
|
|
21181
21482
|
var DEFAULT_MODEL2 = "krill";
|
|
21182
21483
|
var cachedConfig17 = null;
|
|
@@ -21259,7 +21560,7 @@ function applyRecencyHint(query, recencyFilter) {
|
|
|
21259
21560
|
return hint ? `${query} ${hint}` : query;
|
|
21260
21561
|
}
|
|
21261
21562
|
function requestSignal11(signal) {
|
|
21262
|
-
const timeout = AbortSignal.timeout(
|
|
21563
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS13);
|
|
21263
21564
|
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
21264
21565
|
}
|
|
21265
21566
|
function errorMessage11(err) {
|
|
@@ -21381,7 +21682,7 @@ init_utils();
|
|
|
21381
21682
|
import { existsSync as existsSync22, readFileSync as readFileSync23 } from "node:fs";
|
|
21382
21683
|
var BOCHA_SEARCH_URL = "https://api.bochaai.com/v1/web-search";
|
|
21383
21684
|
var CONFIG_PATH20 = getWebSearchConfigPath();
|
|
21384
|
-
var
|
|
21685
|
+
var SEARCH_TIMEOUT_MS15 = 6e4;
|
|
21385
21686
|
var cachedConfig19 = null;
|
|
21386
21687
|
function loadConfig19() {
|
|
21387
21688
|
if (cachedConfig19) return cachedConfig19;
|
|
@@ -21511,7 +21812,7 @@ async function searchWithBocha(query, options = {}) {
|
|
|
21511
21812
|
method: "POST",
|
|
21512
21813
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "application/json" },
|
|
21513
21814
|
body: JSON.stringify({ query, count: numResults, freshness: mapFreshness(options.recencyFilter), summary: true }),
|
|
21514
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
21815
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS15), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS15)
|
|
21515
21816
|
});
|
|
21516
21817
|
} catch (err) {
|
|
21517
21818
|
const message = errorMessage13(err);
|
|
@@ -21563,7 +21864,7 @@ init_search_result_count_normalization();
|
|
|
21563
21864
|
init_utils();
|
|
21564
21865
|
import { existsSync as existsSync24, readFileSync as readFileSync25 } from "node:fs";
|
|
21565
21866
|
var CONFIG_PATH22 = getWebSearchConfigPath();
|
|
21566
|
-
var
|
|
21867
|
+
var SEARCH_TIMEOUT_MS17 = 3e4;
|
|
21567
21868
|
var cachedConfig21 = null;
|
|
21568
21869
|
function loadConfig21() {
|
|
21569
21870
|
if (cachedConfig21) return cachedConfig21;
|
|
@@ -21703,7 +22004,7 @@ async function searchWithSearXNG(query, options = {}) {
|
|
|
21703
22004
|
const response = await fetchRemoteUrl(url, {
|
|
21704
22005
|
method: "GET",
|
|
21705
22006
|
headers,
|
|
21706
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
22007
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS17), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS17)
|
|
21707
22008
|
}, {
|
|
21708
22009
|
...loadSsrfConfig(),
|
|
21709
22010
|
onRedirect: ({ from, to, init }) => from.origin === to.origin ? init : { ...init, headers: { Accept: "application/json" } }
|
|
@@ -21750,7 +22051,7 @@ init_utils();
|
|
|
21750
22051
|
import { existsSync as existsSync25, readFileSync as readFileSync26 } from "node:fs";
|
|
21751
22052
|
var CONFIG_PATH23 = getWebSearchConfigPath();
|
|
21752
22053
|
var DEFAULT_BASE_URL = "https://degoog.org";
|
|
21753
|
-
var
|
|
22054
|
+
var SEARCH_TIMEOUT_MS18 = 3e4;
|
|
21754
22055
|
var cachedConfig22 = null;
|
|
21755
22056
|
function loadConfig22() {
|
|
21756
22057
|
if (cachedConfig22) return cachedConfig22;
|
|
@@ -21924,7 +22225,7 @@ async function searchWithDegoog(query, options = {}) {
|
|
|
21924
22225
|
if (engines.length > 0) body.engines = engines;
|
|
21925
22226
|
const url = new URL(`${baseUrl}/api/search`);
|
|
21926
22227
|
const activityId = activityMonitor.logStart({ type: "api", query: searchQuery });
|
|
21927
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
22228
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS18);
|
|
21928
22229
|
let response;
|
|
21929
22230
|
let entries;
|
|
21930
22231
|
try {
|
|
@@ -21962,7 +22263,7 @@ async function searchWithDegoog(query, options = {}) {
|
|
|
21962
22263
|
}
|
|
21963
22264
|
const message = errorMessage15(err);
|
|
21964
22265
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
21965
|
-
const outgoing = providerTimeout ? new Error(`degoog request timed out after ${Math.round(
|
|
22266
|
+
const outgoing = providerTimeout ? new Error(`degoog request timed out after ${Math.round(SEARCH_TIMEOUT_MS18 / 1e3)}s`) : (() => {
|
|
21966
22267
|
const redactedMessage = redactSecrets(message, secrets);
|
|
21967
22268
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
21968
22269
|
const redactedError = new Error(redactedMessage);
|
|
@@ -22004,7 +22305,7 @@ init_activity();
|
|
|
22004
22305
|
init_domain_filter_normalization();
|
|
22005
22306
|
init_search_result_count_normalization();
|
|
22006
22307
|
var SEARCH_URL = "https://html.duckduckgo.com/html/";
|
|
22007
|
-
var
|
|
22308
|
+
var SEARCH_TIMEOUT_MS19 = 3e4;
|
|
22008
22309
|
function normalizeDomainFilters5(domainFilter) {
|
|
22009
22310
|
const filters = { allowed: [], blocked: [] };
|
|
22010
22311
|
for (const raw of domainFilter ?? []) {
|
|
@@ -22048,7 +22349,7 @@ async function searchWithDuckDuckGo(query, options = {}) {
|
|
|
22048
22349
|
Accept: "text/html",
|
|
22049
22350
|
"User-Agent": "Mozilla/5.0 (compatible; pi-web-access/1.0; +https://github.com/nicobailon/pi-web-access)"
|
|
22050
22351
|
},
|
|
22051
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
22352
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS19), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS19)
|
|
22052
22353
|
});
|
|
22053
22354
|
if (!response.ok) {
|
|
22054
22355
|
const body = await response.text();
|
|
@@ -22056,6 +22357,9 @@ async function searchWithDuckDuckGo(query, options = {}) {
|
|
|
22056
22357
|
}
|
|
22057
22358
|
const { parseHTML } = await import("linkedom");
|
|
22058
22359
|
const { document } = parseHTML(await response.text());
|
|
22360
|
+
if (response.status === 202 || document.querySelector(".anomaly-modal__box, #challenge-form")) {
|
|
22361
|
+
throw new Error(`DuckDuckGo blocked the request with a bot check (HTTP ${response.status}, rate limited); use another search provider`);
|
|
22362
|
+
}
|
|
22059
22363
|
const filters = normalizeDomainFilters5(options.domainFilter);
|
|
22060
22364
|
const results = [];
|
|
22061
22365
|
let parseableResults = 0;
|
|
@@ -22072,7 +22376,7 @@ async function searchWithDuckDuckGo(query, options = {}) {
|
|
|
22072
22376
|
results.push({ title, url: resultUrl, snippet });
|
|
22073
22377
|
if (results.length >= normalizeSearchResultCount(options.numResults)) break;
|
|
22074
22378
|
}
|
|
22075
|
-
if (parseableResults === 0) {
|
|
22379
|
+
if (parseableResults === 0 && !document.querySelector(".no-results__message")) {
|
|
22076
22380
|
throw new Error("DuckDuckGo returned no parseable results (invalid response)");
|
|
22077
22381
|
}
|
|
22078
22382
|
activityMonitor.logComplete(activityId, response.status);
|
|
@@ -22096,7 +22400,7 @@ init_utils();
|
|
|
22096
22400
|
import { existsSync as existsSync26, readFileSync as readFileSync27 } from "node:fs";
|
|
22097
22401
|
var ANYSEARCH_API_URL = "https://api.anysearch.com/v1/search";
|
|
22098
22402
|
var CONFIG_PATH24 = getWebSearchConfigPath();
|
|
22099
|
-
var
|
|
22403
|
+
var SEARCH_TIMEOUT_MS20 = 3e4;
|
|
22100
22404
|
var cachedConfig23 = null;
|
|
22101
22405
|
function loadConfig23() {
|
|
22102
22406
|
if (cachedConfig23) return cachedConfig23;
|
|
@@ -22181,7 +22485,7 @@ async function searchWithAnySearch(query, options = {}) {
|
|
|
22181
22485
|
"Content-Type": "application/json"
|
|
22182
22486
|
},
|
|
22183
22487
|
body: JSON.stringify(body),
|
|
22184
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
22488
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS20), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS20)
|
|
22185
22489
|
});
|
|
22186
22490
|
} catch (err) {
|
|
22187
22491
|
const message = errorMessage16(err);
|
|
@@ -22236,7 +22540,7 @@ init_utils();
|
|
|
22236
22540
|
import { existsSync as existsSync27, readFileSync as readFileSync28 } from "node:fs";
|
|
22237
22541
|
var XCRAWL_API_URL = "https://run.xcrawl.com/v1/serp";
|
|
22238
22542
|
var CONFIG_PATH25 = getWebSearchConfigPath();
|
|
22239
|
-
var
|
|
22543
|
+
var SEARCH_TIMEOUT_MS21 = 6e4;
|
|
22240
22544
|
var cachedConfig24 = null;
|
|
22241
22545
|
function loadConfig24() {
|
|
22242
22546
|
if (cachedConfig24) return cachedConfig24;
|
|
@@ -22356,7 +22660,7 @@ async function searchWithXCrawl(query, options = {}) {
|
|
|
22356
22660
|
}
|
|
22357
22661
|
const body = { engine: "google_search", q: query };
|
|
22358
22662
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
22359
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
22663
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS21);
|
|
22360
22664
|
let response;
|
|
22361
22665
|
try {
|
|
22362
22666
|
response = await fetch(XCRAWL_API_URL, {
|
|
@@ -22377,7 +22681,7 @@ async function searchWithXCrawl(query, options = {}) {
|
|
|
22377
22681
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
22378
22682
|
let outgoing;
|
|
22379
22683
|
if (providerTimeout) {
|
|
22380
|
-
outgoing = new Error(`XCrawl search request timed out after ${Math.round(
|
|
22684
|
+
outgoing = new Error(`XCrawl search request timed out after ${Math.round(SEARCH_TIMEOUT_MS21 / 1e3)}s`);
|
|
22381
22685
|
} else {
|
|
22382
22686
|
const redactedMessage = redactCredential(message, apiKey);
|
|
22383
22687
|
outgoing = redactedMessage === message && err instanceof Error ? err : new Error(redactedMessage);
|
|
@@ -22421,7 +22725,7 @@ init_utils();
|
|
|
22421
22725
|
import { existsSync as existsSync28, readFileSync as readFileSync29 } from "node:fs";
|
|
22422
22726
|
var XAI_RESPONSES_URL = "https://api.x.ai/v1/responses";
|
|
22423
22727
|
var CONFIG_PATH26 = getWebSearchConfigPath();
|
|
22424
|
-
var
|
|
22728
|
+
var SEARCH_TIMEOUT_MS22 = 6e4;
|
|
22425
22729
|
var WEB_SEARCH_AUTH_MODEL_CANDIDATES = ["grok-4.5", "grok-4.3", "grok-build-0.1"];
|
|
22426
22730
|
var X_SEARCH_AUTH_MODEL_CANDIDATES = ["grok-4.6", ...WEB_SEARCH_AUTH_MODEL_CANDIDATES];
|
|
22427
22731
|
var DEFAULT_XAI_SEARCH_TOOLS = ["web_search"];
|
|
@@ -22674,7 +22978,7 @@ async function searchWithXai(query, options = {}, ctx) {
|
|
|
22674
22978
|
input: buildInput(query, options, tools),
|
|
22675
22979
|
tools: tools.map((type) => ({ type }))
|
|
22676
22980
|
}),
|
|
22677
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
22981
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS22), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS22)
|
|
22678
22982
|
});
|
|
22679
22983
|
if (!response.ok) {
|
|
22680
22984
|
activityMonitor.logError(activityId, `HTTP ${response.status}`);
|
|
@@ -22721,7 +23025,7 @@ init_utils();
|
|
|
22721
23025
|
import { existsSync as existsSync29, readFileSync as readFileSync30 } from "node:fs";
|
|
22722
23026
|
var BRIGHTDATA_API_URL = "https://api.brightdata.com/request";
|
|
22723
23027
|
var CONFIG_PATH27 = getWebSearchConfigPath();
|
|
22724
|
-
var
|
|
23028
|
+
var SEARCH_TIMEOUT_MS23 = 6e4;
|
|
22725
23029
|
var ZONE_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
22726
23030
|
var RECENCY_TBS = {
|
|
22727
23031
|
day: "qdr:d",
|
|
@@ -22860,7 +23164,7 @@ function passesDomainFilters4(url, filters) {
|
|
|
22860
23164
|
return filters.include.some((domain) => domainMatches4(hostname2, domain));
|
|
22861
23165
|
}
|
|
22862
23166
|
function requestSignal12(signal) {
|
|
22863
|
-
const timeout = AbortSignal.timeout(
|
|
23167
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS23);
|
|
22864
23168
|
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
22865
23169
|
}
|
|
22866
23170
|
function errorMessage18(err) {
|
|
@@ -23018,7 +23322,7 @@ init_utils();
|
|
|
23018
23322
|
import { existsSync as existsSync30, readFileSync as readFileSync31 } from "node:fs";
|
|
23019
23323
|
var SERPBASE_API_URL = "https://api.serpbase.dev/google/search";
|
|
23020
23324
|
var CONFIG_PATH28 = getWebSearchConfigPath();
|
|
23021
|
-
var
|
|
23325
|
+
var SEARCH_TIMEOUT_MS24 = 6e4;
|
|
23022
23326
|
var RECENCY_TBS2 = {
|
|
23023
23327
|
day: "qdr:d",
|
|
23024
23328
|
week: "qdr:w",
|
|
@@ -23137,7 +23441,7 @@ async function searchWithSerpBase(query, options = {}) {
|
|
|
23137
23441
|
try {
|
|
23138
23442
|
response = await fetch(url, {
|
|
23139
23443
|
headers: { Accept: "application/json" },
|
|
23140
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
23444
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS24), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS24)
|
|
23141
23445
|
});
|
|
23142
23446
|
} catch (err) {
|
|
23143
23447
|
const message = errorMessage19(err);
|
|
@@ -23187,7 +23491,7 @@ init_utils();
|
|
|
23187
23491
|
import { existsSync as existsSync31, readFileSync as readFileSync32 } from "node:fs";
|
|
23188
23492
|
var SERPAPI_SEARCH_URL = "https://serpapi.com/search.json";
|
|
23189
23493
|
var CONFIG_PATH29 = getWebSearchConfigPath();
|
|
23190
|
-
var
|
|
23494
|
+
var SEARCH_TIMEOUT_MS25 = 6e4;
|
|
23191
23495
|
var RECENCY_TBS3 = {
|
|
23192
23496
|
day: "qdr:d",
|
|
23193
23497
|
week: "qdr:w",
|
|
@@ -23292,7 +23596,7 @@ async function searchWithSerpApi(query, options = {}) {
|
|
|
23292
23596
|
url.searchParams.set("num", String(requestCount));
|
|
23293
23597
|
if (options.recencyFilter) url.searchParams.set("tbs", RECENCY_TBS3[options.recencyFilter]);
|
|
23294
23598
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
23295
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
23599
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS25);
|
|
23296
23600
|
let response;
|
|
23297
23601
|
let entries;
|
|
23298
23602
|
try {
|
|
@@ -23319,7 +23623,7 @@ async function searchWithSerpApi(query, options = {}) {
|
|
|
23319
23623
|
}
|
|
23320
23624
|
const message = errorMessage20(err);
|
|
23321
23625
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
23322
|
-
const outgoing = providerTimeout ? new Error(`SerpApi request timed out after ${Math.round(
|
|
23626
|
+
const outgoing = providerTimeout ? new Error(`SerpApi request timed out after ${Math.round(SEARCH_TIMEOUT_MS25 / 1e3)}s`) : (() => {
|
|
23323
23627
|
const redactedMessage = redactCredential(message, apiKey);
|
|
23324
23628
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
23325
23629
|
const redactedError = new Error(redactedMessage);
|
|
@@ -23355,7 +23659,7 @@ init_utils();
|
|
|
23355
23659
|
import { existsSync as existsSync32, readFileSync as readFileSync33 } from "node:fs";
|
|
23356
23660
|
var SERPER_SEARCH_URL = "https://google.serper.dev/search";
|
|
23357
23661
|
var CONFIG_PATH30 = getWebSearchConfigPath();
|
|
23358
|
-
var
|
|
23662
|
+
var SEARCH_TIMEOUT_MS26 = 6e4;
|
|
23359
23663
|
var RECENCY_TBS4 = {
|
|
23360
23664
|
day: "qdr:d",
|
|
23361
23665
|
week: "qdr:w",
|
|
@@ -23459,7 +23763,7 @@ async function searchWithSerper(query, options = {}) {
|
|
|
23459
23763
|
method: "POST",
|
|
23460
23764
|
headers: { "X-API-KEY": apiKey, "Content-Type": "application/json", Accept: "application/json" },
|
|
23461
23765
|
body: JSON.stringify({ q: buildQuery4(query, filters), num: requestCount, ...options.recencyFilter ? { tbs: RECENCY_TBS4[options.recencyFilter] } : {} }),
|
|
23462
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
23766
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS26), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS26)
|
|
23463
23767
|
});
|
|
23464
23768
|
} catch (err) {
|
|
23465
23769
|
const message = errorMessage21(err);
|
|
@@ -23516,7 +23820,7 @@ init_utils();
|
|
|
23516
23820
|
import { existsSync as existsSync33, readFileSync as readFileSync34 } from "node:fs";
|
|
23517
23821
|
var SERPLY_SEARCH_URL = "https://api.serply.io/v1/search";
|
|
23518
23822
|
var CONFIG_PATH31 = getWebSearchConfigPath();
|
|
23519
|
-
var
|
|
23823
|
+
var SEARCH_TIMEOUT_MS27 = 6e4;
|
|
23520
23824
|
var RECENCY_TBS5 = {
|
|
23521
23825
|
day: "qdr:d",
|
|
23522
23826
|
week: "qdr:w",
|
|
@@ -23614,7 +23918,7 @@ async function searchWithSerply(query, options = {}) {
|
|
|
23614
23918
|
url.searchParams.set("num", String(requestCount));
|
|
23615
23919
|
if (options.recencyFilter) url.searchParams.set("tbs", RECENCY_TBS5[options.recencyFilter]);
|
|
23616
23920
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
23617
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
23921
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS27);
|
|
23618
23922
|
let response;
|
|
23619
23923
|
let entries;
|
|
23620
23924
|
try {
|
|
@@ -23641,7 +23945,7 @@ async function searchWithSerply(query, options = {}) {
|
|
|
23641
23945
|
}
|
|
23642
23946
|
const message = errorMessage22(err);
|
|
23643
23947
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
23644
|
-
const outgoing = providerTimeout ? new Error(`Serply request timed out after ${Math.round(
|
|
23948
|
+
const outgoing = providerTimeout ? new Error(`Serply request timed out after ${Math.round(SEARCH_TIMEOUT_MS27 / 1e3)}s`) : (() => {
|
|
23645
23949
|
const redactedMessage = redactCredential(message, apiKey);
|
|
23646
23950
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
23647
23951
|
const redactedError = new Error(redactedMessage);
|
|
@@ -23683,7 +23987,7 @@ init_utils();
|
|
|
23683
23987
|
import { existsSync as existsSync34, readFileSync as readFileSync35 } from "node:fs";
|
|
23684
23988
|
import { isIP as isIP2 } from "node:net";
|
|
23685
23989
|
var MCP_URL = "https://agent-toolkit.app.baizhi.cloud/mcp";
|
|
23686
|
-
var
|
|
23990
|
+
var SEARCH_TIMEOUT_MS28 = 6e4;
|
|
23687
23991
|
var CONFIG_PATH32 = getWebSearchConfigPath();
|
|
23688
23992
|
function credentialOptions() {
|
|
23689
23993
|
let config = {};
|
|
@@ -23726,7 +24030,7 @@ function searchArguments(query, options) {
|
|
|
23726
24030
|
}
|
|
23727
24031
|
async function searchWithBaizhi(query, options = {}) {
|
|
23728
24032
|
const args = searchArguments(query, options);
|
|
23729
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
24033
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS28);
|
|
23730
24034
|
const signal = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal;
|
|
23731
24035
|
if (signal.aborted) throw new Error("Aborted");
|
|
23732
24036
|
const apiKey = await resolveCredential({ ...credentialOptions(), signal });
|
|
@@ -23754,8 +24058,8 @@ async function searchWithBaizhi(query, options = {}) {
|
|
|
23754
24058
|
const client = new Client({ name: "pi-web-access-baizhi", version: "1.0.0" });
|
|
23755
24059
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
23756
24060
|
try {
|
|
23757
|
-
await client.connect(transport2, { signal, timeout:
|
|
23758
|
-
const result = await client.callTool({ name: "websearch_search", arguments: args }, void 0, { signal, timeout:
|
|
24061
|
+
await client.connect(transport2, { signal, timeout: SEARCH_TIMEOUT_MS28 });
|
|
24062
|
+
const result = await client.callTool({ name: "websearch_search", arguments: args }, void 0, { signal, timeout: SEARCH_TIMEOUT_MS28 });
|
|
23759
24063
|
if (result.isError) throw new Error("Baizhi search tool returned an error");
|
|
23760
24064
|
const parts = [];
|
|
23761
24065
|
if (result.structuredContent !== void 0) parts.push(JSON.stringify(result.structuredContent, null, 2));
|
|
@@ -23799,7 +24103,7 @@ var MCP_URLS = {
|
|
|
23799
24103
|
china: "https://open.bigmodel.cn/api/mcp/web_search_prime/mcp"
|
|
23800
24104
|
};
|
|
23801
24105
|
var RECENCY = { day: "oneDay", week: "oneWeek", month: "oneMonth", year: "oneYear" };
|
|
23802
|
-
var
|
|
24106
|
+
var SEARCH_TIMEOUT_MS29 = 6e4;
|
|
23803
24107
|
var CONFIG_PATH33 = getWebSearchConfigPath();
|
|
23804
24108
|
function loadConfig31() {
|
|
23805
24109
|
if (!existsSync35(CONFIG_PATH33)) return {};
|
|
@@ -23870,7 +24174,7 @@ async function searchWithZai(query, options = {}) {
|
|
|
23870
24174
|
const mcpUrl = endpointUrl(config);
|
|
23871
24175
|
const args = searchArguments2(query, options);
|
|
23872
24176
|
const limit = normalizeSearchResultCount(options.numResults);
|
|
23873
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
24177
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS29);
|
|
23874
24178
|
const signal = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal;
|
|
23875
24179
|
if (signal.aborted) throw new Error("Aborted");
|
|
23876
24180
|
const apiKey = await resolveCredential({ ...credentialOptions2(config), signal });
|
|
@@ -23898,11 +24202,11 @@ async function searchWithZai(query, options = {}) {
|
|
|
23898
24202
|
const client = new Client({ name: "pi-web-access-zai", version: "1.0.0" });
|
|
23899
24203
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
23900
24204
|
try {
|
|
23901
|
-
await client.connect(transport2, { signal, timeout:
|
|
23902
|
-
const { tools } = await client.listTools(void 0, { signal, timeout:
|
|
24205
|
+
await client.connect(transport2, { signal, timeout: SEARCH_TIMEOUT_MS29 });
|
|
24206
|
+
const { tools } = await client.listTools(void 0, { signal, timeout: SEARCH_TIMEOUT_MS29 });
|
|
23903
24207
|
const toolName = tools.find((tool) => tool.name === "web_search_prime" || tool.name === "webSearchPrime")?.name;
|
|
23904
24208
|
if (!toolName) throw new Error("Z.ai returned invalid response: web search tool not listed");
|
|
23905
|
-
const result = await client.callTool({ name: toolName, arguments: args }, void 0, { signal, timeout:
|
|
24209
|
+
const result = await client.callTool({ name: toolName, arguments: args }, void 0, { signal, timeout: SEARCH_TIMEOUT_MS29 });
|
|
23906
24210
|
if (result.isError) throw new Error("Z.ai search tool returned an error");
|
|
23907
24211
|
const text4 = (Array.isArray(result.content) ? result.content : []).find((item) => item.type === "text" && typeof item.text === "string");
|
|
23908
24212
|
if (!text4) throw new Error("Z.ai returned invalid response: no search text");
|
|
@@ -23939,7 +24243,7 @@ init_utils();
|
|
|
23939
24243
|
import { existsSync as existsSync36, readFileSync as readFileSync37 } from "node:fs";
|
|
23940
24244
|
var VALYU_SEARCH_URL = "https://api.valyu.ai/v1/search";
|
|
23941
24245
|
var CONFIG_PATH34 = getWebSearchConfigPath();
|
|
23942
|
-
var
|
|
24246
|
+
var SEARCH_TIMEOUT_MS30 = 6e4;
|
|
23943
24247
|
var MAX_SNIPPET_CHARS = 2500;
|
|
23944
24248
|
var MAX_CONTENT_CHARS = 4e3;
|
|
23945
24249
|
var cachedConfig31 = null;
|
|
@@ -24033,7 +24337,7 @@ async function searchWithValyu(query, options = {}) {
|
|
|
24033
24337
|
method: "POST",
|
|
24034
24338
|
headers: { "x-api-key": apiKey, "Content-Type": "application/json", Accept: "application/json" },
|
|
24035
24339
|
body: JSON.stringify({ query, max_num_results: numResults, ...mapDomainFilter9(options.domainFilter), ...startDate ? { start_date: startDate } : {} }),
|
|
24036
|
-
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
24340
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS30), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS30)
|
|
24037
24341
|
});
|
|
24038
24342
|
} catch (err) {
|
|
24039
24343
|
const message = errorMessage23(err);
|
|
@@ -24093,7 +24397,7 @@ var KEENABLE_SEARCH_URL = "https://api.keenable.ai/v1/search";
|
|
|
24093
24397
|
var KEENABLE_PUBLIC_SEARCH_URL = "https://api.keenable.ai/v1/search/public";
|
|
24094
24398
|
var KEENABLE_CLIENT_TITLE = "pi-web-access";
|
|
24095
24399
|
var CONFIG_PATH35 = getWebSearchConfigPath();
|
|
24096
|
-
var
|
|
24400
|
+
var SEARCH_TIMEOUT_MS31 = 3e4;
|
|
24097
24401
|
var MAX_REQUEST_RESULTS = 50;
|
|
24098
24402
|
var MAX_SNIPPET_CHARS2 = 500;
|
|
24099
24403
|
var RECENCY_DAYS = {
|
|
@@ -24195,7 +24499,7 @@ async function searchWithKeenable(query, options = {}) {
|
|
|
24195
24499
|
...apiKey ? { "X-API-Key": apiKey } : {}
|
|
24196
24500
|
};
|
|
24197
24501
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
24198
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
24502
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS31);
|
|
24199
24503
|
let response;
|
|
24200
24504
|
let entries;
|
|
24201
24505
|
try {
|
|
@@ -24225,7 +24529,7 @@ async function searchWithKeenable(query, options = {}) {
|
|
|
24225
24529
|
}
|
|
24226
24530
|
const message = errorMessage24(err);
|
|
24227
24531
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
24228
|
-
const outgoing = providerTimeout ? new Error(`Keenable request timed out after ${Math.round(
|
|
24532
|
+
const outgoing = providerTimeout ? new Error(`Keenable request timed out after ${Math.round(SEARCH_TIMEOUT_MS31 / 1e3)}s`) : (() => {
|
|
24229
24533
|
const redactedMessage = redactCredential(message, apiKey);
|
|
24230
24534
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
24231
24535
|
const redactedError = new Error(redactedMessage);
|
|
@@ -24272,7 +24576,7 @@ init_utils();
|
|
|
24272
24576
|
import { existsSync as existsSync38, readFileSync as readFileSync39 } from "node:fs";
|
|
24273
24577
|
var CERAMIC_SEARCH_URL = "https://api.ceramic.ai/search";
|
|
24274
24578
|
var CONFIG_PATH36 = getWebSearchConfigPath();
|
|
24275
|
-
var
|
|
24579
|
+
var SEARCH_TIMEOUT_MS32 = 3e4;
|
|
24276
24580
|
var MAX_REQUEST_RESULTS2 = 20;
|
|
24277
24581
|
var REQUEST_DESCRIPTION_CHARS = 1e3;
|
|
24278
24582
|
var MAX_SNIPPET_CHARS3 = 500;
|
|
@@ -24376,7 +24680,7 @@ async function searchWithCeramic(query, options = {}) {
|
|
|
24376
24680
|
maxDescriptionLength: REQUEST_DESCRIPTION_CHARS
|
|
24377
24681
|
};
|
|
24378
24682
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
24379
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
24683
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS32);
|
|
24380
24684
|
let response;
|
|
24381
24685
|
let entries;
|
|
24382
24686
|
try {
|
|
@@ -24409,7 +24713,7 @@ async function searchWithCeramic(query, options = {}) {
|
|
|
24409
24713
|
}
|
|
24410
24714
|
const message = errorMessage25(err);
|
|
24411
24715
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
24412
|
-
const outgoing = providerTimeout ? new Error(`Ceramic request timed out after ${Math.round(
|
|
24716
|
+
const outgoing = providerTimeout ? new Error(`Ceramic request timed out after ${Math.round(SEARCH_TIMEOUT_MS32 / 1e3)}s`) : (() => {
|
|
24413
24717
|
const redactedMessage = redactCredential(message, apiKey);
|
|
24414
24718
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
24415
24719
|
const redactedError = new Error(redactedMessage);
|
|
@@ -24454,7 +24758,7 @@ init_search_result_count_normalization();
|
|
|
24454
24758
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
24455
24759
|
var KIMI_SEARCH_URL = "https://api.kimi.com/coding/v1/search";
|
|
24456
24760
|
var KIMI_PROVIDERS = ["kimi-coding", "kimi-code"];
|
|
24457
|
-
var
|
|
24761
|
+
var SEARCH_TIMEOUT_MS33 = 3e4;
|
|
24458
24762
|
function buildRequestHeaders(auth) {
|
|
24459
24763
|
const headers = new Headers();
|
|
24460
24764
|
for (const [name, value] of Object.entries(auth.headers)) {
|
|
@@ -24569,7 +24873,7 @@ async function searchWithKimi(query, options = {}, ctx) {
|
|
|
24569
24873
|
throw new Error("Kimi Code web search unavailable. Run /login kimi-coding to authenticate a Kimi Code Plan account.");
|
|
24570
24874
|
}
|
|
24571
24875
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
24572
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
24876
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS33);
|
|
24573
24877
|
const requestSignal15 = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal;
|
|
24574
24878
|
try {
|
|
24575
24879
|
const response = await fetch(KIMI_SEARCH_URL, {
|
|
@@ -24624,7 +24928,7 @@ init_utils();
|
|
|
24624
24928
|
import { existsSync as existsSync39, readFileSync as readFileSync40 } from "node:fs";
|
|
24625
24929
|
var MISTRAL_CONVERSATIONS_URL = "https://api.mistral.ai/v1/conversations";
|
|
24626
24930
|
var CONFIG_PATH37 = getWebSearchConfigPath();
|
|
24627
|
-
var
|
|
24931
|
+
var SEARCH_TIMEOUT_MS34 = 6e4;
|
|
24628
24932
|
var DEFAULT_SEARCH_MODEL = "mistral-small-latest";
|
|
24629
24933
|
var DEFAULT_SEARCH_TOOL = "web_search";
|
|
24630
24934
|
var MAX_RESULTS = 20;
|
|
@@ -24800,7 +25104,7 @@ async function searchWithMistral(query, options = {}) {
|
|
|
24800
25104
|
const tool = resolveSearchTool(config.mistralSearchTool);
|
|
24801
25105
|
const numResults = normalizeCount4(options.numResults);
|
|
24802
25106
|
const apiKey = await getApiKey26(options.signal);
|
|
24803
|
-
const requestSignal15 = options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
25107
|
+
const requestSignal15 = options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS34), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS34);
|
|
24804
25108
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
24805
25109
|
try {
|
|
24806
25110
|
const response = await fetch(MISTRAL_CONVERSATIONS_URL, {
|
|
@@ -24985,11 +25289,11 @@ function errorMessage27(err) {
|
|
|
24985
25289
|
function isAbortError2(err) {
|
|
24986
25290
|
return errorMessage27(err).toLowerCase().includes("abort");
|
|
24987
25291
|
}
|
|
24988
|
-
async function tryOpenAIInAuto(query, options, fallbackErrors) {
|
|
25292
|
+
async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
24989
25293
|
try {
|
|
24990
25294
|
if (await isOpenAISearchAvailable(options.extensionContext)) {
|
|
24991
25295
|
const result = await searchWithOpenAI(query, options, options.extensionContext);
|
|
24992
|
-
return
|
|
25296
|
+
return take(result, "openai");
|
|
24993
25297
|
}
|
|
24994
25298
|
} catch (err) {
|
|
24995
25299
|
if (isAbortError2(err)) throw err;
|
|
@@ -25311,168 +25615,58 @@ async function search(query, options = {}) {
|
|
|
25311
25615
|
return searchWithConfiguredRouting(query, options, config.searchRouting);
|
|
25312
25616
|
}
|
|
25313
25617
|
const fallbackErrors = [];
|
|
25618
|
+
let firstEmpty;
|
|
25619
|
+
const take = (result, provider2) => {
|
|
25620
|
+
if (!result) return null;
|
|
25621
|
+
const response = { ...result, provider: provider2 };
|
|
25622
|
+
if (result.results.length || result.answer.trim()) return response;
|
|
25623
|
+
firstEmpty ??= response;
|
|
25624
|
+
return null;
|
|
25625
|
+
};
|
|
25314
25626
|
const allowed = new Set(config.allowedProviders ?? RESOLVED_SEARCH_PROVIDERS);
|
|
25315
|
-
|
|
25627
|
+
const attempt = async (provider2) => {
|
|
25628
|
+
if (!allowed.has(provider2) || !await isResolvedProviderAvailable(provider2, options)) return null;
|
|
25316
25629
|
try {
|
|
25317
|
-
|
|
25318
|
-
return { ...result, provider: "searxng" };
|
|
25630
|
+
return take(await searchWithResolvedProvider(provider2, query, options), provider2);
|
|
25319
25631
|
} catch (err) {
|
|
25320
25632
|
if (isAbortError2(err)) throw err;
|
|
25321
|
-
fallbackErrors.push(
|
|
25633
|
+
fallbackErrors.push(`${providerLabel(provider2)}: ${errorMessage27(err)}`);
|
|
25634
|
+
return null;
|
|
25322
25635
|
}
|
|
25323
|
-
}
|
|
25636
|
+
};
|
|
25637
|
+
const searxng = await attempt("searxng");
|
|
25638
|
+
if (searxng) return searxng;
|
|
25324
25639
|
let triedOpenAI = false;
|
|
25325
25640
|
if (allowed.has("openai") && (!options.extensionContext || isOpenAISubscriptionModelSelected(options.extensionContext))) {
|
|
25326
25641
|
triedOpenAI = true;
|
|
25327
|
-
const result = await tryOpenAIInAuto(query, options, fallbackErrors);
|
|
25642
|
+
const result = await tryOpenAIInAuto(query, options, fallbackErrors, take);
|
|
25328
25643
|
if (result) return result;
|
|
25329
25644
|
}
|
|
25330
25645
|
if (allowed.has("exa") && isExaAvailable()) {
|
|
25331
25646
|
try {
|
|
25332
|
-
const
|
|
25333
|
-
if (
|
|
25647
|
+
const response = take(await searchWithExa(query, options), "exa");
|
|
25648
|
+
if (response) return response;
|
|
25334
25649
|
} catch (err) {
|
|
25335
25650
|
if (err instanceof CredentialResolutionError || isAbortError2(err)) throw err;
|
|
25336
25651
|
fallbackErrors.push(`Exa: ${errorMessage27(err)}`);
|
|
25337
25652
|
}
|
|
25338
25653
|
}
|
|
25339
25654
|
if (allowed.has("openai") && !triedOpenAI) {
|
|
25340
|
-
const result = await tryOpenAIInAuto(query, options, fallbackErrors);
|
|
25655
|
+
const result = await tryOpenAIInAuto(query, options, fallbackErrors, take);
|
|
25341
25656
|
if (result) return result;
|
|
25342
25657
|
}
|
|
25343
|
-
|
|
25344
|
-
|
|
25345
|
-
|
|
25346
|
-
return { ...result, provider: "brave" };
|
|
25347
|
-
} catch (err) {
|
|
25348
|
-
if (isAbortError2(err)) throw err;
|
|
25349
|
-
fallbackErrors.push(`Brave: ${errorMessage27(err)}`);
|
|
25350
|
-
}
|
|
25351
|
-
}
|
|
25352
|
-
if (allowed.has("parallel") && isParallelAvailable()) {
|
|
25353
|
-
try {
|
|
25354
|
-
const result = await searchWithParallel(query, options);
|
|
25355
|
-
return { ...result, provider: "parallel" };
|
|
25356
|
-
} catch (err) {
|
|
25357
|
-
if (isAbortError2(err)) throw err;
|
|
25358
|
-
fallbackErrors.push(`Parallel: ${errorMessage27(err)}`);
|
|
25359
|
-
}
|
|
25360
|
-
}
|
|
25361
|
-
if (allowed.has("tinyfish") && isTinyFishAvailable()) {
|
|
25362
|
-
try {
|
|
25363
|
-
const result = await searchWithTinyFish(query, options);
|
|
25364
|
-
return { ...result, provider: "tinyfish" };
|
|
25365
|
-
} catch (err) {
|
|
25366
|
-
if (isAbortError2(err)) throw err;
|
|
25367
|
-
fallbackErrors.push(`TinyFish: ${errorMessage27(err)}`);
|
|
25368
|
-
}
|
|
25369
|
-
}
|
|
25370
|
-
if (allowed.has("search1api") && isSearch1APIAvailable()) {
|
|
25371
|
-
try {
|
|
25372
|
-
const result = await searchWithSearch1API(query, options);
|
|
25373
|
-
return { ...result, provider: "search1api" };
|
|
25374
|
-
} catch (err) {
|
|
25375
|
-
if (isAbortError2(err)) throw err;
|
|
25376
|
-
fallbackErrors.push(`Search1API: ${errorMessage27(err)}`);
|
|
25377
|
-
}
|
|
25378
|
-
}
|
|
25379
|
-
if (allowed.has("searchinfinity") && isSearchinfinityAvailable()) {
|
|
25380
|
-
try {
|
|
25381
|
-
const result = await searchWithSearchinfinity(query, options);
|
|
25382
|
-
return { ...result, provider: "searchinfinity" };
|
|
25383
|
-
} catch (err) {
|
|
25384
|
-
if (isAbortError2(err)) throw err;
|
|
25385
|
-
fallbackErrors.push(`Searchinfinity: ${errorMessage27(err)}`);
|
|
25386
|
-
}
|
|
25387
|
-
}
|
|
25388
|
-
if (allowed.has("querit") && isQueritAvailable()) {
|
|
25389
|
-
try {
|
|
25390
|
-
const result = await searchWithQuerit(query, options);
|
|
25391
|
-
return { ...result, provider: "querit" };
|
|
25392
|
-
} catch (err) {
|
|
25393
|
-
if (isAbortError2(err)) throw err;
|
|
25394
|
-
fallbackErrors.push(`Querit: ${errorMessage27(err)}`);
|
|
25395
|
-
}
|
|
25396
|
-
}
|
|
25397
|
-
if (allowed.has("tavily") && isTavilyAvailable()) {
|
|
25398
|
-
try {
|
|
25399
|
-
const result = await searchWithTavily(query, options);
|
|
25400
|
-
return { ...result, provider: "tavily" };
|
|
25401
|
-
} catch (err) {
|
|
25402
|
-
if (isAbortError2(err)) throw err;
|
|
25403
|
-
fallbackErrors.push(`Tavily: ${errorMessage27(err)}`);
|
|
25404
|
-
}
|
|
25405
|
-
}
|
|
25406
|
-
if (allowed.has("firecrawl") && isFirecrawlAvailable()) {
|
|
25407
|
-
try {
|
|
25408
|
-
const result = await searchWithFirecrawl(query, options);
|
|
25409
|
-
return { ...result, provider: "firecrawl" };
|
|
25410
|
-
} catch (err) {
|
|
25411
|
-
if (isAbortError2(err)) throw err;
|
|
25412
|
-
fallbackErrors.push(`Firecrawl: ${errorMessage27(err)}`);
|
|
25413
|
-
}
|
|
25414
|
-
}
|
|
25415
|
-
if (allowed.has("jina") && isJinaSearchAvailable()) {
|
|
25416
|
-
try {
|
|
25417
|
-
const result = await searchWithJina(query, options);
|
|
25418
|
-
return { ...result, provider: "jina" };
|
|
25419
|
-
} catch (err) {
|
|
25420
|
-
if (isAbortError2(err)) throw err;
|
|
25421
|
-
fallbackErrors.push(`Jina: ${errorMessage27(err)}`);
|
|
25422
|
-
}
|
|
25423
|
-
}
|
|
25424
|
-
if (allowed.has("serpdive") && isSerpdiveAvailable()) {
|
|
25425
|
-
try {
|
|
25426
|
-
const result = await searchWithSerpdive(query, options);
|
|
25427
|
-
return { ...result, provider: "serpdive" };
|
|
25428
|
-
} catch (err) {
|
|
25429
|
-
if (isAbortError2(err)) throw err;
|
|
25430
|
-
fallbackErrors.push(`SERPdive: ${errorMessage27(err)}`);
|
|
25431
|
-
}
|
|
25432
|
-
}
|
|
25433
|
-
if (allowed.has("kagi") && isKagiAvailable()) {
|
|
25434
|
-
try {
|
|
25435
|
-
const result = await searchWithKagi(query, options);
|
|
25436
|
-
return { ...result, provider: "kagi" };
|
|
25437
|
-
} catch (err) {
|
|
25438
|
-
if (isAbortError2(err)) throw err;
|
|
25439
|
-
fallbackErrors.push(`Kagi: ${errorMessage27(err)}`);
|
|
25440
|
-
}
|
|
25441
|
-
}
|
|
25442
|
-
if (allowed.has("bocha") && isBochaAvailable()) {
|
|
25443
|
-
try {
|
|
25444
|
-
const result = await searchWithBocha(query, options);
|
|
25445
|
-
return { ...result, provider: "bocha" };
|
|
25446
|
-
} catch (err) {
|
|
25447
|
-
if (isAbortError2(err)) throw err;
|
|
25448
|
-
fallbackErrors.push(`Bocha: ${errorMessage27(err)}`);
|
|
25449
|
-
}
|
|
25450
|
-
}
|
|
25451
|
-
if (allowed.has("ollama") && isOllamaAvailable()) {
|
|
25452
|
-
try {
|
|
25453
|
-
const result = await searchWithOllama(query, options);
|
|
25454
|
-
return { ...result, provider: "ollama" };
|
|
25455
|
-
} catch (err) {
|
|
25456
|
-
if (isAbortError2(err)) throw err;
|
|
25457
|
-
fallbackErrors.push(`Ollama: ${errorMessage27(err)}`);
|
|
25458
|
-
}
|
|
25459
|
-
}
|
|
25460
|
-
if (allowed.has("perplexity") && isPerplexityAvailable()) {
|
|
25461
|
-
try {
|
|
25462
|
-
const result = await searchWithPerplexity(query, options);
|
|
25463
|
-
return { ...result, provider: "perplexity" };
|
|
25464
|
-
} catch (err) {
|
|
25465
|
-
if (isAbortError2(err)) throw err;
|
|
25466
|
-
fallbackErrors.push(`Perplexity: ${errorMessage27(err)}`);
|
|
25467
|
-
}
|
|
25658
|
+
for (const provider2 of ["brave", "parallel", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "bocha", "ollama", "perplexity"]) {
|
|
25659
|
+
const response = await attempt(provider2);
|
|
25660
|
+
if (response) return response;
|
|
25468
25661
|
}
|
|
25469
25662
|
if (allowed.has("gemini")) try {
|
|
25470
|
-
const
|
|
25471
|
-
if (
|
|
25663
|
+
const response = take(await searchWithGemini(query, options, false), "gemini");
|
|
25664
|
+
if (response) return response;
|
|
25472
25665
|
} catch (err) {
|
|
25473
25666
|
if (isAbortError2(err)) throw err;
|
|
25474
25667
|
fallbackErrors.push(`Gemini: ${errorMessage27(err)}`);
|
|
25475
25668
|
}
|
|
25669
|
+
if (firstEmpty) return firstEmpty;
|
|
25476
25670
|
if (fallbackErrors.length > 0) {
|
|
25477
25671
|
throw new Error(`Auto provider search failed:
|
|
25478
25672
|
- ${fallbackErrors.join("\n - ")}`);
|
|
@@ -25757,7 +25951,7 @@ function createMcpServer(core2, info, enabledTools) {
|
|
|
25757
25951
|
}
|
|
25758
25952
|
|
|
25759
25953
|
// web-tool-core.ts
|
|
25760
|
-
import { existsSync as
|
|
25954
|
+
import { existsSync as existsSync53, readFileSync as readFileSync55 } from "node:fs";
|
|
25761
25955
|
import pLimit2 from "p-limit";
|
|
25762
25956
|
|
|
25763
25957
|
// fetch-params.ts
|
|
@@ -25775,6 +25969,7 @@ function normalizeFetchContentParams(params) {
|
|
|
25775
25969
|
const answerModel = normalizeOptionalString(params.answerModel);
|
|
25776
25970
|
const auth = normalizeAuth(params.auth);
|
|
25777
25971
|
const proxy = normalizeProxy(params.proxy);
|
|
25972
|
+
const redirects = normalizeRedirects(params.redirects);
|
|
25778
25973
|
return {
|
|
25779
25974
|
urlList,
|
|
25780
25975
|
options: {
|
|
@@ -25786,7 +25981,8 @@ function normalizeFetchContentParams(params) {
|
|
|
25786
25981
|
...mode !== void 0 ? { mode } : {},
|
|
25787
25982
|
...answerModel !== void 0 ? { answerModel } : {},
|
|
25788
25983
|
...auth !== void 0 ? { auth } : {},
|
|
25789
|
-
...proxy !== void 0 ? { proxy } : {}
|
|
25984
|
+
...proxy !== void 0 ? { proxy } : {},
|
|
25985
|
+
...redirects !== void 0 ? { redirects } : {}
|
|
25790
25986
|
}
|
|
25791
25987
|
};
|
|
25792
25988
|
}
|
|
@@ -25809,6 +26005,11 @@ function normalizeMode(value) {
|
|
|
25809
26005
|
if (value === "readable" || value === "raw" || value === "answer") return value;
|
|
25810
26006
|
throw new Error('mode must be "readable", "raw", or "answer"');
|
|
25811
26007
|
}
|
|
26008
|
+
function normalizeRedirects(value) {
|
|
26009
|
+
if (value === void 0) return void 0;
|
|
26010
|
+
if (value === "same-origin") return value;
|
|
26011
|
+
throw new Error('redirects must be "same-origin"');
|
|
26012
|
+
}
|
|
25812
26013
|
function normalizeAuth(value) {
|
|
25813
26014
|
if (value === void 0 || value === false) return void 0;
|
|
25814
26015
|
if (value === true) return true;
|
|
@@ -26000,7 +26201,7 @@ function findContent(text4, queries, mode) {
|
|
|
26000
26201
|
if (contained.length === 0) continue;
|
|
26001
26202
|
const prefix = range.start > 0 ? "\u2026" : "";
|
|
26002
26203
|
const suffix = range.end < text4.length ? "\u2026" : "";
|
|
26003
|
-
const snippet = `${prefix}${text4.slice(range.start, range.end).replace(/\s+/g, " ").trim()}${suffix}`;
|
|
26204
|
+
const snippet = `${prefix}${text4.slice(range.start, range.end).replace(/[\uD800-\uDFFF]/gu, "\uFFFD").replace(/\s+/g, " ").trim()}${suffix}`;
|
|
26004
26205
|
const counts = contained.map((result) => `${overflow ? result.id : `"${result.query}"`} \xD7${result.count}`).join(", ");
|
|
26005
26206
|
sections.push(`${index + 1}. ${counts}
|
|
26006
26207
|
${snippet}`);
|
|
@@ -26452,8 +26653,8 @@ function parseConfigRoot(raw) {
|
|
|
26452
26653
|
return parsed;
|
|
26453
26654
|
}
|
|
26454
26655
|
function loadConfig40() {
|
|
26455
|
-
if (!
|
|
26456
|
-
return parseConfigRoot(
|
|
26656
|
+
if (!existsSync53(WEB_SEARCH_CONFIG_PATH4)) return {};
|
|
26657
|
+
return parseConfigRoot(readFileSync55(WEB_SEARCH_CONFIG_PATH4, "utf-8"));
|
|
26457
26658
|
}
|
|
26458
26659
|
var DEFAULT_TOOL_NAMES = {
|
|
26459
26660
|
webSearch: "web_search",
|
|
@@ -26598,7 +26799,7 @@ function fetchStructuredContent(responseId, results) {
|
|
|
26598
26799
|
};
|
|
26599
26800
|
}
|
|
26600
26801
|
function initialContentSlice(content, maxChars) {
|
|
26601
|
-
let endOffset = Math.min(content.length, maxChars);
|
|
26802
|
+
let endOffset = pageEnd(content, 0, Math.min(content.length, maxChars));
|
|
26602
26803
|
if (endOffset < content.length) {
|
|
26603
26804
|
const lineBreak = content.lastIndexOf("\n", endOffset);
|
|
26604
26805
|
if (lineBreak >= Math.floor(maxChars * 0.8)) endOffset = lineBreak + 1;
|
|
@@ -26751,7 +26952,8 @@ function boundSearchPresentation(text4, guidance, truncationGuidance, maxChars)
|
|
|
26751
26952
|
function registeredFetchToolNames(settings2) {
|
|
26752
26953
|
return {
|
|
26753
26954
|
...settings2.enabledTools.webSearch ? { webSearch: settings2.toolNames.webSearch } : {},
|
|
26754
|
-
...settings2.enabledTools.fetchContent ? { fetchContent: settings2.toolNames.fetchContent } : {}
|
|
26955
|
+
...settings2.enabledTools.fetchContent ? { fetchContent: settings2.toolNames.fetchContent } : {},
|
|
26956
|
+
...settings2.enabledTools.getSearchContent ? { getSearchContent: settings2.toolNames.getSearchContent } : {}
|
|
26755
26957
|
};
|
|
26756
26958
|
}
|
|
26757
26959
|
function storedContentSourceNames(settings2) {
|
|
@@ -26761,14 +26963,21 @@ function storedContentSourceNames(settings2) {
|
|
|
26761
26963
|
...settings2.enabledTools.fetchContent ? [settings2.toolNames.fetchContent] : []
|
|
26762
26964
|
]);
|
|
26763
26965
|
}
|
|
26966
|
+
function pageEnd(content, offset, end) {
|
|
26967
|
+
if (end <= offset || end >= content.length) return end;
|
|
26968
|
+
const high = content.charCodeAt(end - 1);
|
|
26969
|
+
const low = content.charCodeAt(end);
|
|
26970
|
+
if (high < 55296 || high > 56319 || low < 56320 || low > 57343) return end;
|
|
26971
|
+
return end - 1 > offset ? end - 1 : end + 1;
|
|
26972
|
+
}
|
|
26764
26973
|
function sliceWithContinuation(content, offset, limit, maxChars, continuationAt) {
|
|
26765
|
-
let endOffset = offset + Math.min(limit, content.length - offset);
|
|
26974
|
+
let endOffset = pageEnd(content, offset, offset + Math.min(limit, content.length - offset));
|
|
26766
26975
|
let continuation = "";
|
|
26767
26976
|
while (endOffset < content.length) {
|
|
26768
26977
|
continuation = continuationAt(endOffset);
|
|
26769
26978
|
const overflow = endOffset - offset + continuation.length - maxChars;
|
|
26770
26979
|
if (overflow <= 0) break;
|
|
26771
|
-
endOffset
|
|
26980
|
+
endOffset = pageEnd(content, offset, endOffset - overflow);
|
|
26772
26981
|
}
|
|
26773
26982
|
return { endOffset, text: content.slice(offset, endOffset) + (endOffset < content.length ? continuation : "") };
|
|
26774
26983
|
}
|
|
@@ -26872,8 +27081,12 @@ Full search results are stored as responseId "${searchId}". `;
|
|
|
26872
27081
|
return value;
|
|
26873
27082
|
};
|
|
26874
27083
|
const presentation = hasApprovedSummary ? { text: unboundedPresentation, truncated: false, originalChars: unboundedPresentation.length, returnedChars: unboundedPresentation.length, omittedChars: 0 } : boundSearchPresentation(unboundedPresentation, buildGuidance(false), buildGuidance(true), maxInlineContentChars);
|
|
27084
|
+
const summaryGuidance = hasApprovedSummary ? buildGuidance(false) : "";
|
|
26875
27085
|
return {
|
|
26876
|
-
content: [
|
|
27086
|
+
content: [
|
|
27087
|
+
{ type: "text", text: presentation.text },
|
|
27088
|
+
...summaryGuidance ? [{ type: "text", text: summaryGuidance }] : []
|
|
27089
|
+
],
|
|
26877
27090
|
structuredContent: searchStructuredContent(searchId, fetchId, opts.results),
|
|
26878
27091
|
details: {
|
|
26879
27092
|
queries: opts.queryList,
|
|
@@ -27138,7 +27351,7 @@ Full search results are stored as responseId "${searchId}". `;
|
|
|
27138
27351
|
const fetchResults = await fetchAllContent2(urlList, signal, fetchOptions(requestOptions, options.proxy));
|
|
27139
27352
|
const presentedResults = mode === "answer" ? await Promise.all(fetchResults.map(async (result) => {
|
|
27140
27353
|
if (result.error) return result;
|
|
27141
|
-
if (result.
|
|
27354
|
+
if (result.mimeType?.startsWith("image/") || result.frames?.length) {
|
|
27142
27355
|
return { ...result, error: "Page answer requires textual fetched content" };
|
|
27143
27356
|
}
|
|
27144
27357
|
try {
|
|
@@ -27184,7 +27397,8 @@ Full search results are stored as responseId "${searchId}". `;
|
|
|
27184
27397
|
|
|
27185
27398
|
---
|
|
27186
27399
|
Showing ${slice.endOffset} of ${fullLength} chars, ${slice.shownBytes} of ${slice.totalBytes} bytes, and ${slice.shownLines} of ${slice.totalLines} lines. `;
|
|
27187
|
-
|
|
27400
|
+
if (mode === "answer") output2 += "Stored content is the original source, not the remaining answer. ";
|
|
27401
|
+
output2 += storedContent ? getSearchContentEnabled ? mode === "answer" ? `Use ${toolNames.getSearchContent}({ responseId: "${responseId}", urlIndex: 0, offset: 0 }) to read the original source from the beginning.` : `Use ${toolNames.getSearchContent}({ responseId: "${responseId}", urlIndex: 0, offset: ${slice.endOffset} }) for the next slice.` : "Content retrieval is not registered." : "Authenticated fetch cache is off; repeat the fetch to read more.";
|
|
27188
27402
|
}
|
|
27189
27403
|
const content = [];
|
|
27190
27404
|
if (result.frames?.length) {
|
|
@@ -27196,6 +27410,15 @@ Showing ${slice.endOffset} of ${fullLength} chars, ${slice.shownBytes} of ${slic
|
|
|
27196
27410
|
content.push({ type: "image", data: result.thumbnail.data, mimeType: result.thumbnail.mimeType });
|
|
27197
27411
|
}
|
|
27198
27412
|
content.push({ type: "text", text: output2 });
|
|
27413
|
+
if (!truncated && storedContent && getSearchContentEnabled) {
|
|
27414
|
+
const storedLabel = mode === "answer" ? "Original source content" : "Full content";
|
|
27415
|
+
content.push({
|
|
27416
|
+
type: "text",
|
|
27417
|
+
text: `
|
|
27418
|
+
---
|
|
27419
|
+
${storedLabel} is stored as responseId "${responseId}". Use ${toolNames.getSearchContent}({ responseId: "${responseId}", urlIndex: 0, offset: 0 }) to retrieve it.`
|
|
27420
|
+
});
|
|
27421
|
+
}
|
|
27199
27422
|
const imageCount = (result.frames?.length ?? 0) + (result.thumbnail ? 1 : 0);
|
|
27200
27423
|
return {
|
|
27201
27424
|
content,
|
|
@@ -27224,19 +27447,33 @@ Showing ${slice.endOffset} of ${fullLength} chars, ${slice.shownBytes} of ${slic
|
|
|
27224
27447
|
}
|
|
27225
27448
|
};
|
|
27226
27449
|
}
|
|
27227
|
-
let
|
|
27450
|
+
let budget = mode === "answer" ? getMaxInlineContentChars() : 0;
|
|
27451
|
+
let output = mode === "answer" ? "## Page answers\n" : "## Fetched URLs\n\n";
|
|
27228
27452
|
for (const { url, title, content, error } of presentedResults) {
|
|
27229
|
-
if (
|
|
27230
|
-
output += `- ${url}: Error - ${error}
|
|
27453
|
+
if (mode !== "answer") {
|
|
27454
|
+
output += error ? `- ${url}: Error - ${error}
|
|
27455
|
+
` : `- ${title || url} (${content.length} chars)
|
|
27456
|
+
`;
|
|
27457
|
+
} else if (error) {
|
|
27458
|
+
output += `
|
|
27459
|
+
### ${url}
|
|
27460
|
+
Error: ${error}
|
|
27231
27461
|
`;
|
|
27232
27462
|
} else {
|
|
27233
|
-
|
|
27463
|
+
const shown = content.slice(0, budget);
|
|
27464
|
+
budget -= shown.length;
|
|
27465
|
+
const marker = shown.length === content.length ? "" : `
|
|
27466
|
+
[answer ${shown.length ? "truncated at the output limit;" : "omitted; earlier answers used the output limit,"} fetch fewer URLs per call for complete answers]`;
|
|
27467
|
+
output += `
|
|
27468
|
+
### ${title || url}
|
|
27469
|
+
${shown}${marker}
|
|
27234
27470
|
`;
|
|
27235
27471
|
}
|
|
27236
27472
|
}
|
|
27473
|
+
const retrievalHint = mode === "answer" ? `Stored content is the original source pages, not the answers. Use ${toolNames.getSearchContent}({ responseId: "${responseId}", urlIndex: 0, offset: 0 }) to read the first source; urlIndex follows the order above.` : `Use ${toolNames.getSearchContent}({ responseId: "${responseId}", urlIndex: 0 }) to retrieve bounded content slices.`;
|
|
27237
27474
|
output += storedContent ? getSearchContentEnabled ? `
|
|
27238
27475
|
---
|
|
27239
|
-
|
|
27476
|
+
${retrievalHint}` : "\n---\nContent retrieval is not registered." : "\n---\nAuthenticated fetch cache is off; repeat the fetch to read content.";
|
|
27240
27477
|
return {
|
|
27241
27478
|
...successful === 0 ? { isError: true } : {},
|
|
27242
27479
|
content: [{ type: "text", text: output }],
|
|
@@ -27490,7 +27727,7 @@ ${text5}` }],
|
|
|
27490
27727
|
details: { error: "Offset out of range", offset, contentLength: urlData.content.length }
|
|
27491
27728
|
};
|
|
27492
27729
|
}
|
|
27493
|
-
const endOffset = Math.min(offset + limit, urlData.content.length);
|
|
27730
|
+
const endOffset = pageEnd(urlData.content, offset, Math.min(offset + limit, urlData.content.length));
|
|
27494
27731
|
const contentSlice = urlData.content.slice(offset, endOffset);
|
|
27495
27732
|
const hasMore = endOffset < urlData.content.length;
|
|
27496
27733
|
let text4 = `# ${urlData.title || urlData.url}
|