@herbertgao/pi-extensions 2026.10.11 → 2026.10.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/node_modules/@herbertgao/pi-agency/README.md +5 -3
- package/node_modules/@herbertgao/pi-agency/package.json +1 -1
- package/node_modules/@herbertgao/pi-agency/src/index.ts +51 -7
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/agent-color.ts +11 -2
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +10 -5
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/ui/fleet-list.ts +1 -0
- package/node_modules/@herbertgao/sol-pi/README.md +1 -1
- package/node_modules/@herbertgao/sol-pi/agents-install.md +2 -2
- package/node_modules/@narumitw/pi-btw/README.md +14 -5
- package/node_modules/@narumitw/pi-btw/dist/index.ts +1067 -560
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
- package/node_modules/@narumitw/pi-btw/docs/core-alignment.md +277 -0
- package/node_modules/@narumitw/pi-btw/docs/native-appearance.md +857 -0
- package/node_modules/@narumitw/pi-btw/docs/workflows.md +34 -13
- package/node_modules/@narumitw/pi-btw/package.json +4 -4
- package/node_modules/@narumitw/pi-btw/src/btw.ts +152 -108
- package/node_modules/@narumitw/pi-btw/src/conversation-chrome.ts +93 -0
- package/node_modules/@narumitw/pi-btw/src/fullscreen-renderer.ts +329 -0
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +109 -315
- package/node_modules/@narumitw/pi-btw/src/keybindings.ts +100 -22
- package/node_modules/@narumitw/pi-btw/src/menu.ts +42 -27
- package/node_modules/@narumitw/pi-btw/src/session-lifetime.ts +66 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +366 -164
- package/node_modules/@narumitw/pi-btw/src/workspace-layout.ts +96 -36
- package/node_modules/pi-lens/CHANGELOG.md +281 -0
- package/node_modules/pi-lens/README.md +13 -1
- package/node_modules/pi-lens/dist/{chunk-SS36ZX4J.js → chunk-24AKHFGP.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-JSQFTSC6.js → chunk-2FN63LPV.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-5UCAH366.js → chunk-2KXTHF3M.js} +20 -20
- package/node_modules/pi-lens/dist/{chunk-EU63SDCG.js → chunk-3DA2JDOL.js} +367 -281
- package/node_modules/pi-lens/dist/{chunk-RWWYJ623.js → chunk-3KAZU3VR.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-3PTHXJXR.js +28 -0
- package/node_modules/pi-lens/dist/chunk-3QED2P4V.js +31 -0
- package/node_modules/pi-lens/dist/{chunk-N2H3ZPZY.js → chunk-3RKP3FMS.js} +1 -0
- package/node_modules/pi-lens/dist/{chunk-XVF2VVXP.js → chunk-5HSRT26B.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-MXGY6KPT.js → chunk-5IUSNGOC.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-EJIUXPBX.js → chunk-5OFV52AM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-AW7R2GWG.js → chunk-5VSF4UUQ.js} +12 -7
- package/node_modules/pi-lens/dist/{chunk-6STA6Z7I.js → chunk-5WRPDP2A.js} +18 -18
- package/node_modules/pi-lens/dist/{chunk-YIUAVF7E.js → chunk-6DLWKFEX.js} +35 -34
- package/node_modules/pi-lens/dist/{chunk-WOA4LN2R.js → chunk-7D6L4MTX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-GAEGEPOC.js → chunk-7HXE67BN.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-AGSS7277.js +84 -0
- package/node_modules/pi-lens/dist/{chunk-R3PCY3YS.js → chunk-AMERCH6V.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-WU567RSC.js → chunk-ATKJFDQN.js} +14 -10
- package/node_modules/pi-lens/dist/{chunk-VSSBEUFT.js → chunk-AWSCPCN2.js} +16 -16
- package/node_modules/pi-lens/dist/{chunk-VCHXCQFG.js → chunk-BWD5EPKO.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-H6MF6EVN.js → chunk-CT4MN5IU.js} +1200 -230
- package/node_modules/pi-lens/dist/{chunk-FCSOVF55.js → chunk-CUHSHSB6.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-CHOW74WE.js → chunk-CYRKQRPM.js} +7 -10
- package/node_modules/pi-lens/dist/{chunk-Q7DUK4LX.js → chunk-DEL2U6CM.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-6C7JWPCP.js → chunk-DGUKIYSI.js} +26 -23
- package/node_modules/pi-lens/dist/{chunk-PHDMFAKM.js → chunk-DUO2TU77.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-MRXKYPCS.js → chunk-EBC36LNN.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-CSHFH5IN.js → chunk-ED36RF6Y.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-76MWC2K6.js → chunk-EUXZEFTV.js} +90 -97
- package/node_modules/pi-lens/dist/{chunk-QOZXJ4NA.js → chunk-FM4RDMKT.js} +11 -8
- package/node_modules/pi-lens/dist/{chunk-ACXEQZOU.js → chunk-GAQ7OQG6.js} +31 -28
- package/node_modules/pi-lens/dist/{chunk-XAGLWMJ4.js → chunk-GL5LUMZE.js} +23 -23
- package/node_modules/pi-lens/dist/{chunk-BKE7E7TC.js → chunk-GMX5OS7B.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-ZHFZWTZV.js → chunk-GSLNCYGG.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-3W7IEVVL.js → chunk-GSM5UU7A.js} +26 -34
- package/node_modules/pi-lens/dist/{chunk-724UL2TJ.js → chunk-GXFV6MYU.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-HAD7QRQI.js +30 -0
- package/node_modules/pi-lens/dist/{chunk-QOBUHWHX.js → chunk-HRNHZA3N.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-VWCXW2E7.js → chunk-HWCCCQNX.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-7DYBLXYA.js → chunk-HYGZEMX6.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-IJYGIDF4.js +186 -0
- package/node_modules/pi-lens/dist/{chunk-4W4VLAPJ.js → chunk-IQWN5JCP.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-SQ4TVJBR.js → chunk-IUE7SSKV.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-IBGIOBEE.js → chunk-IWDLU6K3.js} +68 -5
- package/node_modules/pi-lens/dist/{chunk-XCJN5IJU.js → chunk-IYNJ6YPZ.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-JAU72XNY.js → chunk-J64T55EI.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2BBLFX75.js → chunk-J6MPGQTS.js} +5 -5
- package/node_modules/pi-lens/dist/chunk-JORED7EX.js +44 -0
- package/node_modules/pi-lens/dist/{chunk-6SDEP3AJ.js → chunk-JUKMK5Y4.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-FMSO6RDZ.js → chunk-JW3YWBVB.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-L3BLXZG7.js → chunk-KAPJINKN.js} +30 -69
- package/node_modules/pi-lens/dist/{chunk-2B73ZPOK.js → chunk-KN35K52N.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-C34ZXZ7O.js → chunk-KUA4OJ5Y.js} +24 -11
- package/node_modules/pi-lens/dist/chunk-KYUB6QDC.js +72 -0
- package/node_modules/pi-lens/dist/{chunk-67WMNWEE.js → chunk-LLJNQKQW.js} +12 -10
- package/node_modules/pi-lens/dist/chunk-LZSEQW6A.js +57 -0
- package/node_modules/pi-lens/dist/{chunk-ZANLILYD.js → chunk-M2IFVFWU.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-M2UD3LPU.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-XIJZVPD5.js → chunk-MBKQHGA7.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-P7266HLM.js → chunk-MPNJLASA.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6GFRNVYR.js → chunk-MZGQNL3Y.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-ZWFS3OEF.js → chunk-N5FLEO7W.js} +33 -32
- package/node_modules/pi-lens/dist/{chunk-3JNKMP3B.js → chunk-O4NWQT6I.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-T6CPIZNT.js → chunk-OHKJ7PQF.js} +33 -32
- package/node_modules/pi-lens/dist/{chunk-VRZP76YM.js → chunk-P63GXC37.js} +4 -1
- package/node_modules/pi-lens/dist/{chunk-XTMJ7XDT.js → chunk-POMLXPMY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-QQNQ7SJW.js → chunk-QBFBRV2B.js} +10 -4
- package/node_modules/pi-lens/dist/{chunk-CMMHNUZ2.js → chunk-R3T7CLQ2.js} +60 -38
- package/node_modules/pi-lens/dist/{chunk-23WOO7TX.js → chunk-R7YOCSNV.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-2CD5RS6M.js → chunk-RKBXZN3A.js} +23 -2
- package/node_modules/pi-lens/dist/{chunk-OCAGUNBC.js → chunk-RKKOYPRA.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-52FUZI6K.js → chunk-RMLC67LF.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-XMSXXAHW.js → chunk-ROYSX2S5.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-M6HSLBWY.js → chunk-RVK72CZX.js} +6507 -7514
- package/node_modules/pi-lens/dist/{chunk-FLKWCIZH.js → chunk-S2HEXIWI.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-UZ3TUTRV.js → chunk-S67KYG37.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VCO24T4L.js → chunk-SD4I7ZO4.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-Z527N6YQ.js → chunk-SKAMFC7A.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-MQLUAEOC.js → chunk-SRYEJNES.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-BRGDSBJE.js → chunk-SYE6T2EB.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-GXW6K4YJ.js → chunk-T57LYLZT.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ZXYDQ3TZ.js → chunk-T7FEBKXN.js} +48 -15
- package/node_modules/pi-lens/dist/{chunk-3EFKIGZN.js → chunk-TIQ2PKDW.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-QILIYSJF.js → chunk-TLX72JTG.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-TYM6OUIT.js → chunk-TOY6QKOH.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-IZSHAIJ7.js → chunk-TRETHTQO.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-3VPVG5SU.js → chunk-U44DJXQP.js} +10 -6
- package/node_modules/pi-lens/dist/{chunk-PNQDPDRC.js → chunk-UA7ZXYDR.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-OXXKQCSV.js → chunk-UBOQLVT2.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-QGQ5CCCG.js → chunk-UMS2MFPZ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-QHJ6DQ2R.js → chunk-US7ECLD7.js} +55 -13
- package/node_modules/pi-lens/dist/{chunk-AB3YYG6N.js → chunk-UZ2XCLYS.js} +8 -8
- package/node_modules/pi-lens/dist/chunk-V35JG4JB.js +2667 -0
- package/node_modules/pi-lens/dist/{chunk-N3X6Q4YT.js → chunk-VOOAPROD.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-SAEFPSB6.js → chunk-W66O5E25.js} +21 -11
- package/node_modules/pi-lens/dist/{chunk-KBG47GHP.js → chunk-WMYE35PX.js} +15 -11
- package/node_modules/pi-lens/dist/{chunk-5NGR67U5.js → chunk-XBJVAEEO.js} +32 -5
- package/node_modules/pi-lens/dist/{chunk-YYOIQFRS.js → chunk-XHJBS436.js} +122 -44
- package/node_modules/pi-lens/dist/{chunk-GBPP5P7X.js → chunk-XTBDCR27.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-4UNXBNE2.js → chunk-XTFDJI3T.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-UXGETRP4.js → chunk-XYURS6EN.js} +13 -12
- package/node_modules/pi-lens/dist/{chunk-RPLINGVB.js → chunk-Y6GZHWSJ.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-2VUQMUMT.js → chunk-YCWYO6TQ.js} +41 -38
- package/node_modules/pi-lens/dist/{chunk-77M37OKR.js → chunk-YH5MVY2U.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-AOHZU2BM.js → chunk-YNE3RP52.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-YSZNHOBY.js → chunk-ZHH37KZL.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-ZGDGW2V3.js → chunk-ZIVJBOO3.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-RXCOMYPY.js → chunk-ZVUL7QYY.js} +29 -28
- package/node_modules/pi-lens/dist/index.js +11052 -5852
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -9
- package/node_modules/pi-lens/dist/mcp/cli.js +41 -38
- package/node_modules/pi-lens/dist/mcp/server.js +1120 -474
- package/node_modules/pi-lens/dist/mcp/worker.js +61 -58
- package/node_modules/pi-lens/dist/probes/installer.js +19 -19
- package/node_modules/pi-lens/dist/workers/project-snapshot-persist-worker.js +28 -9
- package/node_modules/pi-lens/dist/workers/review-graph-persist-worker.js +1 -1
- package/node_modules/pi-lens/docs/configuration.md +11 -0
- package/node_modules/pi-lens/docs/engineering-principles.md +32 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +1 -1
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +15 -26
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +117 -13
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +97 -7
- package/node_modules/pi-lens/docs/pi-lens-monitor.md +8 -2
- package/node_modules/pi-lens/docs/pi-lens-retro.md +4 -1
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +112 -4
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +22 -14
- package/node_modules/pi-lens/docs/release-qa-baseline.md +3 -1
- package/node_modules/pi-lens/docs/servercapabilities.md +9 -19
- package/node_modules/pi-lens/package.json +7 -5
- package/node_modules/pi-lens/scripts/download-grammars.js +40 -7
- package/node_modules/pi-lens/scripts/lib/latency-log-phases.mjs +95 -0
- package/node_modules/pi-lens/scripts/rpc-load-check.mjs +570 -81
- package/node_modules/pi-provider-qoder/dist/index.js +323 -154
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +39 -0
- package/node_modules/pi-web-access/README.md +83 -12
- package/node_modules/pi-web-access/anysearch.ts +4 -3
- package/node_modules/pi-web-access/bocha.ts +4 -3
- package/node_modules/pi-web-access/brightdata-unlocker.ts +3 -2
- package/node_modules/pi-web-access/brightdata.ts +4 -3
- package/node_modules/pi-web-access/ceramic.ts +3 -2
- package/node_modules/pi-web-access/curator-page.ts +3 -1
- package/node_modules/pi-web-access/curator-server.ts +1 -0
- package/node_modules/pi-web-access/deepseek.ts +179 -6
- package/node_modules/pi-web-access/dist/index.js +1118 -688
- package/node_modules/pi-web-access/dist/mcp-cli.js +1081 -667
- package/node_modules/pi-web-access/extract.ts +58 -6
- package/node_modules/pi-web-access/gemini-search.ts +29 -6
- package/node_modules/pi-web-access/index.ts +20 -3
- package/node_modules/pi-web-access/jina-search.ts +6 -4
- package/node_modules/pi-web-access/kagi.ts +5 -4
- package/node_modules/pi-web-access/keenable.ts +3 -2
- package/node_modules/pi-web-access/linkup.ts +170 -0
- package/node_modules/pi-web-access/mistral-search.ts +4 -3
- package/node_modules/pi-web-access/ollama.ts +5 -4
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/parallel.ts +7 -7
- package/node_modules/pi-web-access/perplexity.ts +5 -3
- package/node_modules/pi-web-access/querit.ts +4 -3
- package/node_modules/pi-web-access/search1api.ts +4 -3
- package/node_modules/pi-web-access/searchinfinity.ts +4 -3
- package/node_modules/pi-web-access/serpapi.ts +7 -5
- package/node_modules/pi-web-access/serpbase.ts +5 -4
- package/node_modules/pi-web-access/serpdive.ts +4 -3
- package/node_modules/pi-web-access/serper.ts +6 -4
- package/node_modules/pi-web-access/serply.ts +3 -2
- package/node_modules/pi-web-access/utils.ts +24 -1
- package/node_modules/pi-web-access/valyu.ts +4 -3
- package/node_modules/pi-web-access/web-tool-core.ts +5 -0
- package/node_modules/pi-web-access/xai-search.ts +49 -7
- package/node_modules/pi-web-access/xcrawl.ts +4 -3
- package/node_modules/pi-web-access/you.ts +3 -2
- package/package.json +9 -9
- package/node_modules/pi-lens/dist/chunk-3YN6V5TV.js +0 -85
- package/node_modules/pi-lens/dist/chunk-466Z26MG.js +0 -30
- package/node_modules/pi-lens/dist/chunk-EC47DWFA.js +0 -56
- package/node_modules/pi-lens/dist/chunk-KDERNTCQ.js +0 -28
- package/node_modules/pi-lens/dist/chunk-KSX3TXSZ.js +0 -69
- package/node_modules/pi-lens/dist/chunk-LOP6GRPH.js +0 -31
- package/node_modules/pi-lens/dist/chunk-UOPVJQ4N.js +0 -103
- /package/node_modules/pi-lens/dist/{chunk-FC4RP4I2.js → chunk-6HWVI6MI.js} +0 -0
|
@@ -12,6 +12,7 @@ import { extractWithUrlContext, extractWithGeminiWeb } from "./gemini-url-contex
|
|
|
12
12
|
import { extractWithParallel, isParallelAvailable } from "./parallel.ts";
|
|
13
13
|
import { extractWithParallelMcp } from "./parallel-mcp.ts";
|
|
14
14
|
import { extractWithTinyFish, isTinyFishAvailable } from "./tinyfish.ts";
|
|
15
|
+
import { extractWithDeepSeek, isDeepSeekAvailable } from "./deepseek.ts";
|
|
15
16
|
import { extractWithSearch1API, isSearch1APIAvailable } from "./search1api.ts";
|
|
16
17
|
import { extractWithQuerit, isQueritAvailable } from "./querit.ts";
|
|
17
18
|
import { extractWithKagi, isKagiExtractAvailable } from "./kagi.ts";
|
|
@@ -68,11 +69,11 @@ function loadFetchTimeoutMs(): number {
|
|
|
68
69
|
const NON_RECOVERABLE_ERRORS = ["Unsupported content type", "Response too large", "PDF extraction is disabled", "Image fetching is disabled"];
|
|
69
70
|
const MIN_USEFUL_CONTENT = 500;
|
|
70
71
|
const SUPPORTED_IMAGE_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
71
|
-
const FETCH_PROVIDERS = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini"] as const;
|
|
72
|
+
const FETCH_PROVIDERS = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek"] as const;
|
|
72
73
|
type FetchProvider = typeof FETCH_PROVIDERS[number];
|
|
73
74
|
type FetchRouting = { providers: FetchProvider[]; allowRemoteHostedProviders: boolean };
|
|
74
75
|
const DEFAULT_FETCH_PROVIDER_ORDER: FetchProvider[] = ["http", "firecrawl", "crawl4ai", "jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "brightdata", "gemini"];
|
|
75
|
-
const REMOTE_HOSTED_FETCH_PROVIDERS = new Set<FetchProvider>(["jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini"]);
|
|
76
|
+
const REMOTE_HOSTED_FETCH_PROVIDERS = new Set<FetchProvider>(["jina", "tinyfish", "search1api", "querit", "kagi", "ollama", "parallel", "parallel-mcp", "brightdata", "gemini", "deepseek"]);
|
|
76
77
|
|
|
77
78
|
function isDefuddleConsoleError(args: Parameters<typeof console.error>): boolean {
|
|
78
79
|
const prefix = args[0];
|
|
@@ -871,6 +872,7 @@ export async function extractContent(
|
|
|
871
872
|
let parallelError: string | null = null;
|
|
872
873
|
let parallelMcpError: string | null = null;
|
|
873
874
|
let brightdataError: string | null = null;
|
|
875
|
+
let deepseekError: string | null = null;
|
|
874
876
|
|
|
875
877
|
if (remoteUrl && providerOrder[0] !== "http") {
|
|
876
878
|
const httpGateResult = await runHttpProvider();
|
|
@@ -1068,6 +1070,23 @@ export async function extractContent(
|
|
|
1068
1070
|
}
|
|
1069
1071
|
if (geminiResult) return withDeclaredLinks(geminiResult);
|
|
1070
1072
|
}
|
|
1073
|
+
|
|
1074
|
+
if (provider === "deepseek") {
|
|
1075
|
+
try {
|
|
1076
|
+
if (isDeepSeekAvailable()) {
|
|
1077
|
+
const deepseekResult = await extractWithDeepSeek(url, signal, {
|
|
1078
|
+
timeoutMs: options?.timeoutMs,
|
|
1079
|
+
...(options?.lookup ? { lookup: options.lookup } : {}),
|
|
1080
|
+
});
|
|
1081
|
+
if (deepseekResult) return withDeclaredLinks(deepseekResult);
|
|
1082
|
+
}
|
|
1083
|
+
} catch (err) {
|
|
1084
|
+
if (isAbortError(err)) return abortedResult(url);
|
|
1085
|
+
deepseekError = errorMessage(err);
|
|
1086
|
+
if (isConfigParseError(err)) return parseErrorResult(deepseekError);
|
|
1087
|
+
}
|
|
1088
|
+
continue;
|
|
1089
|
+
}
|
|
1071
1090
|
}
|
|
1072
1091
|
|
|
1073
1092
|
if (signal?.aborted) return abortedResult(url);
|
|
@@ -1097,6 +1116,7 @@ export async function extractContent(
|
|
|
1097
1116
|
...(parallelError ? [`Parallel fallback failed: ${parallelError}`] : []),
|
|
1098
1117
|
...(parallelMcpError ? [`Parallel MCP fallback failed: ${parallelMcpError}`] : []),
|
|
1099
1118
|
...(brightdataError ? [`Bright Data fallback failed: ${brightdataError}`] : []),
|
|
1119
|
+
...(deepseekError ? [`DeepSeek fallback failed: ${deepseekError}`] : []),
|
|
1100
1120
|
"",
|
|
1101
1121
|
"Fallback options:",
|
|
1102
1122
|
...(jinaHint ? [jinaHint] : []),
|
|
@@ -1109,6 +1129,7 @@ export async function extractContent(
|
|
|
1109
1129
|
` • Set ollamaApiKey in ${WEB_SEARCH_CONFIG_PATH} or OLLAMA_API_KEY`,
|
|
1110
1130
|
` • Set parallelApiKey in ${WEB_SEARCH_CONFIG_PATH} or PARALLEL_API_KEY`,
|
|
1111
1131
|
` • Set brightdataApiKey and brightdataUnlockerZone in ${WEB_SEARCH_CONFIG_PATH} or BRIGHTDATA_API_KEY and BRIGHTDATA_UNLOCKER_ZONE`,
|
|
1132
|
+
` • Set deepseekApiKey in ${WEB_SEARCH_CONFIG_PATH} or DEEPSEEK_API_KEY and add "deepseek" to fetchRouting.providers`,
|
|
1112
1133
|
` • Set GEMINI_API_KEY in ${WEB_SEARCH_CONFIG_PATH}`,
|
|
1113
1134
|
" • Sign into gemini.google.com in Chrome",
|
|
1114
1135
|
...(searchToolName ? [` • Use ${searchToolName} to find content about this topic`] : []),
|
|
@@ -1128,6 +1149,20 @@ function isCloudflareChallenge(response: Response, text: string, isHTML: boolean
|
|
|
1128
1149
|
text.includes("/cdn-cgi/challenge-platform/");
|
|
1129
1150
|
}
|
|
1130
1151
|
|
|
1152
|
+
// The HTML spec's JavaScript MIME type essences; any other type (JSON-LD,
|
|
1153
|
+
// text/template, ...) is a data block that never runs.
|
|
1154
|
+
const JAVASCRIPT_MIME_TYPES = new Set([
|
|
1155
|
+
"application/ecmascript", "application/javascript", "application/x-ecmascript", "application/x-javascript",
|
|
1156
|
+
"text/ecmascript", "text/javascript", "text/javascript1.0", "text/javascript1.1", "text/javascript1.2",
|
|
1157
|
+
"text/javascript1.3", "text/javascript1.4", "text/javascript1.5", "text/jscript", "text/livescript",
|
|
1158
|
+
"text/x-ecmascript", "text/x-javascript",
|
|
1159
|
+
]);
|
|
1160
|
+
|
|
1161
|
+
function isExecutableScriptType(type: string | null): boolean {
|
|
1162
|
+
const mime = (type ?? "").split(";")[0].trim().toLowerCase();
|
|
1163
|
+
return mime === "" || mime === "module" || JAVASCRIPT_MIME_TYPES.has(mime);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1131
1166
|
function isLikelyJSRendered(html: string): boolean {
|
|
1132
1167
|
const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
|
|
1133
1168
|
if (!bodyMatch) return false;
|
|
@@ -1141,7 +1176,9 @@ function isLikelyJSRendered(html: string): boolean {
|
|
|
1141
1176
|
.replace(/\s+/g, " ")
|
|
1142
1177
|
.trim();
|
|
1143
1178
|
|
|
1144
|
-
const scriptCount =
|
|
1179
|
+
const scriptCount = [...html.matchAll(/<script\b([^>]*)>/gi)]
|
|
1180
|
+
.filter(([, attrs]) => isExecutableScriptType(attrs.match(/\btype\s*=\s*["']?([^"'\s>]+)/i)?.[1] ?? null))
|
|
1181
|
+
.length;
|
|
1145
1182
|
|
|
1146
1183
|
return textContent.length < 500 && scriptCount > 3;
|
|
1147
1184
|
}
|
|
@@ -1513,13 +1550,28 @@ async function extractViaHttp(
|
|
|
1513
1550
|
declaredLinks,
|
|
1514
1551
|
};
|
|
1515
1552
|
}
|
|
1553
|
+
let error: string | null = "Page appears to be JavaScript-rendered (content loads dynamically)";
|
|
1554
|
+
if (!isLikelyJSRendered(text)) {
|
|
1555
|
+
// Readability mutated `document`, so measure the page's own visible text
|
|
1556
|
+
// from a fresh parse. A static page whose whole body is under the floor
|
|
1557
|
+
// is complete once something was extracted from it; any executable
|
|
1558
|
+
// script means the text may be a placeholder for client rendering.
|
|
1559
|
+
const { document: original } = parseHTML(text);
|
|
1560
|
+
const hasExecutableScript = [...original.querySelectorAll("script")]
|
|
1561
|
+
.some((script) => isExecutableScriptType(script.getAttribute("type")));
|
|
1562
|
+
for (const node of original.querySelectorAll("script, style, noscript, template")) node.remove();
|
|
1563
|
+
const visibleChars = (original.body?.textContent ?? "").replace(/\s+/g, " ").trim().length;
|
|
1564
|
+
const extractedChars = markdown.trim().length;
|
|
1565
|
+
const counts = `Extracted content appears incomplete: extracted ${extractedChars} characters from a page with ${visibleChars} characters of visible text`;
|
|
1566
|
+
if (visibleChars >= MIN_USEFUL_CONTENT) error = counts;
|
|
1567
|
+
else if (hasExecutableScript) error = `Extracted content appears incomplete: the page has only ${visibleChars} characters of visible text and runs scripts, so content may load dynamically`;
|
|
1568
|
+
else error = extractedChars > 0 ? null : counts;
|
|
1569
|
+
}
|
|
1516
1570
|
return {
|
|
1517
1571
|
url,
|
|
1518
1572
|
title: article.title || documentTitle,
|
|
1519
1573
|
content: appendDeclaredWebLinks(markdown, declaredLinks),
|
|
1520
|
-
error
|
|
1521
|
-
? "Page appears to be JavaScript-rendered (content loads dynamically)"
|
|
1522
|
-
: "Extracted content appears incomplete",
|
|
1574
|
+
error,
|
|
1523
1575
|
declaredLinks,
|
|
1524
1576
|
};
|
|
1525
1577
|
}
|
|
@@ -46,12 +46,13 @@ import { isZaiAvailable, searchWithZai } from "./zai.ts";
|
|
|
46
46
|
import { isValyuAvailable, searchWithValyu } from "./valyu.ts";
|
|
47
47
|
import { isKeenableAvailable, searchWithKeenable } from "./keenable.ts";
|
|
48
48
|
import { isCeramicAvailable, searchWithCeramic } from "./ceramic.ts";
|
|
49
|
+
import { isLinkupAvailable, searchWithLinkup } from "./linkup.ts";
|
|
49
50
|
import { isDeepSeekAvailable, searchWithDeepSeek } from "./deepseek.ts";
|
|
50
51
|
import { isKimiSearchAvailable, searchWithKimi } from "./kimi-search.ts";
|
|
51
52
|
import { isMistralAvailable, searchWithMistral } from "./mistral-search.ts";
|
|
52
53
|
import { getWebSearchConfigPath } from "./utils.ts";
|
|
53
54
|
|
|
54
|
-
export const RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek"] as const;
|
|
55
|
+
export const RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek", "linkup"] as const;
|
|
55
56
|
export const SEARCH_PROVIDERS = ["auto", "all", ...RESOLVED_SEARCH_PROVIDERS] as const;
|
|
56
57
|
|
|
57
58
|
export type ResolvedSearchProvider = typeof RESOLVED_SEARCH_PROVIDERS[number];
|
|
@@ -116,7 +117,7 @@ export interface AttributedSearchResponse extends SearchResponse {
|
|
|
116
117
|
|
|
117
118
|
const CONFIG_PATH = getWebSearchConfigPath();
|
|
118
119
|
const DEFAULT_SEARCH_MODEL = "gemini-3.6-flash";
|
|
119
|
-
// Explicit-only providers (Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, XCrawl, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, Keenable, Ceramic, DeepSeek) are deliberately absent:
|
|
120
|
+
// Explicit-only providers (Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, XCrawl, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, Keenable, Ceramic, DeepSeek, Linkup) are deliberately absent:
|
|
120
121
|
// `all` must never fan out to an opt-in or paid provider without the user asking for it.
|
|
121
122
|
export const ALL_SEARCH_PROVIDERS: ResolvedSearchProvider[] = ["searxng", "openai", "exa", "brave", "parallel", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "ollama", "perplexity", "gemini", "bocha"];
|
|
122
123
|
const VALID_ROUTING_KINDS = ["transient", "quota", "network", "invalid-response", "unsupported"] as const;
|
|
@@ -266,6 +267,8 @@ export function normalizeSearchProviderSelection(value: unknown, label = "provid
|
|
|
266
267
|
|
|
267
268
|
export interface FullSearchOptions extends SearchOptions {
|
|
268
269
|
provider?: SearchProviderSelection;
|
|
270
|
+
/** The caller already substituted the configured default for an omitted or "auto" provider. */
|
|
271
|
+
providerFromConfig?: boolean;
|
|
269
272
|
includeContent?: boolean;
|
|
270
273
|
extensionContext?: ExtensionContext;
|
|
271
274
|
/** Forwarded to providers that understand it (currently Exa); ignored elsewhere. */
|
|
@@ -429,6 +432,7 @@ async function searchWithResolvedProvider(
|
|
|
429
432
|
if (provider === "valyu") return { ...(await searchWithValyu(query, options)), provider };
|
|
430
433
|
if (provider === "keenable") return { ...(await searchWithKeenable(query, options)), provider };
|
|
431
434
|
if (provider === "ceramic") return { ...(await searchWithCeramic(query, options)), provider };
|
|
435
|
+
if (provider === "linkup") return { ...(await searchWithLinkup(query, options)), provider };
|
|
432
436
|
if (provider === "deepseek") return { ...(await searchWithDeepSeek(query, options)), provider };
|
|
433
437
|
if (provider === "xcrawl") return { ...(await searchWithXCrawl(query, options)), provider };
|
|
434
438
|
if (provider === "perplexity") return { ...(await searchWithPerplexity(query, options)), provider };
|
|
@@ -486,6 +490,7 @@ async function isResolvedProviderAvailable(provider: ResolvedSearchProvider, opt
|
|
|
486
490
|
if (provider === "valyu") return isValyuAvailable();
|
|
487
491
|
if (provider === "keenable") return isKeenableAvailable();
|
|
488
492
|
if (provider === "ceramic") return isCeramicAvailable();
|
|
493
|
+
if (provider === "linkup") return isLinkupAvailable();
|
|
489
494
|
if (provider === "deepseek") return isDeepSeekAvailable();
|
|
490
495
|
if (provider === "xcrawl") return isXcrawlAvailable();
|
|
491
496
|
if (provider === "perplexity") return isPerplexityAvailable();
|
|
@@ -535,6 +540,7 @@ export function providerLabel(provider: ResolvedSearchProvider): string {
|
|
|
535
540
|
if (provider === "valyu") return "Valyu";
|
|
536
541
|
if (provider === "keenable") return "Keenable";
|
|
537
542
|
if (provider === "ceramic") return "Ceramic";
|
|
543
|
+
if (provider === "linkup") return "Linkup";
|
|
538
544
|
if (provider === "deepseek") return "DeepSeek";
|
|
539
545
|
return provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
540
546
|
}
|
|
@@ -554,6 +560,7 @@ async function searchWithProviders(
|
|
|
554
560
|
query: string,
|
|
555
561
|
options: FullSearchOptions,
|
|
556
562
|
selectedProviders?: ResolvedSearchProvider[],
|
|
563
|
+
routing?: SearchRoutingConfig,
|
|
557
564
|
): Promise<AttributedSearchResponse> {
|
|
558
565
|
const allowed = getAllowedSearchProviders();
|
|
559
566
|
const providers = selectedProviders ?? (await Promise.all(ALL_SEARCH_PROVIDERS.filter(provider => allowed.includes(provider)).map(async (provider) => ({
|
|
@@ -563,7 +570,7 @@ async function searchWithProviders(
|
|
|
563
570
|
: await isResolvedProviderAvailable(provider, options),
|
|
564
571
|
})))).filter((entry) => entry.available).map((entry) => entry.provider);
|
|
565
572
|
if (providers.length === 0) {
|
|
566
|
-
throw new Error("No configured search provider available for provider \"all\". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, and
|
|
573
|
+
throw new Error("No configured search provider available for provider \"all\". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, DeepSeek, and Linkup are excluded.");
|
|
567
574
|
}
|
|
568
575
|
|
|
569
576
|
const settled = await Promise.allSettled(
|
|
@@ -585,7 +592,20 @@ async function searchWithProviders(
|
|
|
585
592
|
}
|
|
586
593
|
if (successes.length === 0) {
|
|
587
594
|
const label = selectedProviders ? "Selected-provider" : "All-provider";
|
|
588
|
-
|
|
595
|
+
const failureMessage = `${label} search failed:\n - ${failures.map(({ provider, error }) => `${providerLabel(provider)}: ${error}`).join("\n - ")}`;
|
|
596
|
+
// Routing continues only when every array failure is a kind it would itself fall back on.
|
|
597
|
+
if (!routing || !settled.every((outcome, index) => outcome.status === "rejected" &&
|
|
598
|
+
routing.fallbackOn.includes(classifyProviderError(providers[index], outcome.reason).kind as SearchRoutingConfig["fallbackOn"][number]))) {
|
|
599
|
+
throw new Error(failureMessage);
|
|
600
|
+
}
|
|
601
|
+
const untried = routing.providers.filter((provider) => !providers.includes(provider));
|
|
602
|
+
try {
|
|
603
|
+
if (untried.length === 0) throw new Error("Configured search routing has no untried providers");
|
|
604
|
+
return await searchWithConfiguredRouting(query, options, { ...routing, providers: untried });
|
|
605
|
+
} catch (err) {
|
|
606
|
+
if (isAbortError(err)) throw err;
|
|
607
|
+
throw new Error(`${failureMessage}\n${errorMessage(err)}`);
|
|
608
|
+
}
|
|
589
609
|
}
|
|
590
610
|
|
|
591
611
|
const results: SearchResult[] = [];
|
|
@@ -656,7 +676,10 @@ export async function search(query: string, options: FullSearchOptions = {}): Pr
|
|
|
656
676
|
: options.provider;
|
|
657
677
|
assertSearchProviderSelectionAllowed(provider, "Requested provider");
|
|
658
678
|
if (Array.isArray(provider)) {
|
|
659
|
-
|
|
679
|
+
// Only a config-default array falls back to searchRouting; a per-call array stays strict.
|
|
680
|
+
const fromConfig = options.providerFromConfig === true || options.provider === undefined || options.provider === "auto";
|
|
681
|
+
const routing = fromConfig ? config.searchRouting : undefined;
|
|
682
|
+
return searchWithProviders(query, options, normalizeResolvedProviderList(provider, "provider"), routing);
|
|
660
683
|
}
|
|
661
684
|
if (provider === "all") return searchWithProviders(query, options);
|
|
662
685
|
if (provider !== "auto") return searchWithResolvedProvider(provider, query, options);
|
|
@@ -736,7 +759,7 @@ export async function search(query: string, options: FullSearchOptions = {}): Pr
|
|
|
736
759
|
" 3. Set OPENAI_API_KEY, BRAVE_API_KEY, PARALLEL_API_KEY, TINYFISH_API_KEY, SEARCH1API_KEY, SEARCHINFINITY_API_KEY, QUERIT_API_KEY, TAVILY_API_KEY, FIRECRAWL_BASE_URL, JINA_API_KEY, SERPDIVE_API_KEY, KAGI_API_KEY, BOCHA_API_KEY, OLLAMA_API_KEY, SEARXNG_BASE_URL, EXA_API_KEY, PERPLEXITY_API_KEY, GEMINI_API_KEY, or CLOUDFLARE_API_KEY env vars\n" +
|
|
737
760
|
" 4. Set GOOGLE_GEMINI_BASE_URL with CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing\n" +
|
|
738
761
|
" 5. Sign into gemini.google.com in a supported Chromium-based browser\n" +
|
|
739
|
-
" 6. Explicitly select provider: \"anysearch\" for anonymous AnySearch, \"xcrawl\" for XCrawl, \"xai\" for Grok, \"mistral\" for Mistral Conversations web search, \"brightdata\" with brightdataSerpZone for paid Bright Data SERP, \"serpbase\", \"serpapi\", \"serper\", or \"serply\" for Google SERP, \"you\" for You.com, \"zai\" for Z.ai GLM Coding Plan search, \"valyu\" for research search, \"keenable\" for keyless Keenable search, \"ceramic\" for Ceramic search,
|
|
762
|
+
" 6. Explicitly select provider: \"anysearch\" for anonymous AnySearch, \"xcrawl\" for XCrawl, \"xai\" for Grok, \"mistral\" for Mistral Conversations web search, \"brightdata\" with brightdataSerpZone for paid Bright Data SERP, \"serpbase\", \"serpapi\", \"serper\", or \"serply\" for Google SERP, \"you\" for You.com, \"zai\" for Z.ai GLM Coding Plan search, \"valyu\" for research search, \"keenable\" for keyless Keenable search, \"ceramic\" for Ceramic search, \"deepseek\" for DeepSeek search, or \"linkup\" for Linkup search"
|
|
740
763
|
);
|
|
741
764
|
}
|
|
742
765
|
|
|
@@ -71,6 +71,7 @@ import { isSerperAvailable } from "./serper.ts";
|
|
|
71
71
|
import { isSerplyAvailable } from "./serply.ts";
|
|
72
72
|
import { isKeenableAvailable } from "./keenable.ts";
|
|
73
73
|
import { isCeramicAvailable } from "./ceramic.ts";
|
|
74
|
+
import { isLinkupAvailable } from "./linkup.ts";
|
|
74
75
|
import { isDeepSeekAvailable } from "./deepseek.ts";
|
|
75
76
|
import { isBaizhiAvailable } from "./baizhi.ts";
|
|
76
77
|
import { isZaiAvailable } from "./zai.ts";
|
|
@@ -346,6 +347,7 @@ async function getProviderAvailability(ctx: ExtensionContext): Promise<ProviderA
|
|
|
346
347
|
valyu: allowedProviders.has("valyu") && isValyuAvailable(),
|
|
347
348
|
keenable: allowedProviders.has("keenable") && isKeenableAvailable(),
|
|
348
349
|
ceramic: allowedProviders.has("ceramic") && isCeramicAvailable(),
|
|
350
|
+
linkup: allowedProviders.has("linkup") && isLinkupAvailable(),
|
|
349
351
|
deepseek: allowedProviders.has("deepseek") && isDeepSeekAvailable(),
|
|
350
352
|
};
|
|
351
353
|
return {
|
|
@@ -458,6 +460,8 @@ interface PendingCurate {
|
|
|
458
460
|
availableProviders: ProviderAvailability;
|
|
459
461
|
defaultProvider: SearchProvider;
|
|
460
462
|
searchProvider: SearchProviderSelection;
|
|
463
|
+
// The provider resolved from config when the call named none; searches still using it may fall back to searchRouting.
|
|
464
|
+
configDefaultProvider?: SearchProviderSelection;
|
|
461
465
|
summaryModels: Array<{ value: string; label: string }>;
|
|
462
466
|
defaultSummaryModel: string | null;
|
|
463
467
|
timeoutSeconds: number;
|
|
@@ -724,8 +728,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
724
728
|
const initConfig = loadConfigForExtensionInit();
|
|
725
729
|
const fetchModeConfig = resolveFetchModeConfig(initConfig);
|
|
726
730
|
const toolActivation = initConfig.toolActivation ?? "auto";
|
|
727
|
-
if (toolActivation !== "auto" && toolActivation !== "dynamic" && toolActivation !== "eager") {
|
|
728
|
-
throw new Error(`toolActivation in ${WEB_SEARCH_CONFIG_PATH} must be "auto", "dynamic", or "
|
|
731
|
+
if (toolActivation !== "auto" && toolActivation !== "dynamic" && toolActivation !== "eager" && toolActivation !== "none") {
|
|
732
|
+
throw new Error(`toolActivation in ${WEB_SEARCH_CONFIG_PATH} must be "auto", "dynamic", "eager", or "none"`);
|
|
729
733
|
}
|
|
730
734
|
const toolExposure = initConfig.toolExposure ?? "direct";
|
|
731
735
|
if (toolExposure !== "direct" && toolExposure !== "deferred") {
|
|
@@ -734,6 +738,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
734
738
|
if (toolExposure === "deferred" && toolActivation === "eager") {
|
|
735
739
|
throw new Error(`toolExposure "deferred" in ${WEB_SEARCH_CONFIG_PATH} cannot be combined with toolActivation "eager"`);
|
|
736
740
|
}
|
|
741
|
+
if (toolActivation === "none" && toolExposure !== "deferred") {
|
|
742
|
+
throw new Error(`toolActivation "none" in ${WEB_SEARCH_CONFIG_PATH} requires toolExposure "deferred"`);
|
|
743
|
+
}
|
|
737
744
|
const allowedSearchProviders = initConfig.webSearch?.allowedProviders === undefined ? RESOLVED_SEARCH_PROVIDERS : getAllowedSearchProviders();
|
|
738
745
|
const allEligibleProviders = allowedSearchProviders.filter(provider => ALL_SEARCH_PROVIDERS.includes(provider));
|
|
739
746
|
const allExcludedProviders = allowedSearchProviders.filter(provider => !ALL_SEARCH_PROVIDERS.includes(provider));
|
|
@@ -1260,6 +1267,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1260
1267
|
const requestedProvider = resolveCuratorSearchProvider(provider, pc.searchProvider);
|
|
1261
1268
|
const response = await search(query, {
|
|
1262
1269
|
provider: requestedProvider,
|
|
1270
|
+
providerFromConfig: requestedProvider === pc.configDefaultProvider,
|
|
1263
1271
|
numResults: pc.numResults,
|
|
1264
1272
|
recencyFilter: pc.recencyFilter,
|
|
1265
1273
|
domainFilter: pc.domainFilter,
|
|
@@ -1489,6 +1497,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1489
1497
|
let cancelled = false;
|
|
1490
1498
|
|
|
1491
1499
|
const requestedProvider = resolveRequestedProvider(params.provider);
|
|
1500
|
+
const providerFromConfig = (normalizeProviderInput(params.provider) ?? "auto") === "auto";
|
|
1492
1501
|
const bootstrap = await loadCuratorBootstrap(requestedProvider, ctx, {
|
|
1493
1502
|
numResults: params.numResults,
|
|
1494
1503
|
recencyFilter,
|
|
@@ -1523,6 +1532,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1523
1532
|
availableProviders,
|
|
1524
1533
|
defaultProvider,
|
|
1525
1534
|
searchProvider,
|
|
1535
|
+
configDefaultProvider: providerFromConfig ? searchProvider : undefined,
|
|
1526
1536
|
summaryModels: summaryModelChoices.summaryModels,
|
|
1527
1537
|
defaultSummaryModel: summaryModelChoices.defaultSummaryModel,
|
|
1528
1538
|
timeoutSeconds: curatorTimeoutSeconds,
|
|
@@ -1577,6 +1587,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1577
1587
|
try {
|
|
1578
1588
|
const response = await search(query, {
|
|
1579
1589
|
provider: requestedProvider,
|
|
1590
|
+
// A provider picked in the curator UI replaces this value and stays strict.
|
|
1591
|
+
providerFromConfig: requestedProvider === pc.configDefaultProvider,
|
|
1580
1592
|
numResults: params.numResults,
|
|
1581
1593
|
recencyFilter,
|
|
1582
1594
|
domainFilter: params.domainFilter,
|
|
@@ -2274,7 +2286,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
2274
2286
|
|
|
2275
2287
|
// Deferred tools are never declared on registration, so web_enable must stay the model's route
|
|
2276
2288
|
// to them: auto's eager path would leave a session with neither the tools nor the loader.
|
|
2277
|
-
|
|
2289
|
+
// "none" skips it on purpose: codemode scripts and tool_search still reach deferred tools.
|
|
2290
|
+
if (toolActivation !== "eager" && toolActivation !== "none") registerWebToolActivation(pi, [
|
|
2278
2291
|
...(webSearchEnabled ? [{ name: toolNames.webSearch, capability: "search" as const }] : []),
|
|
2279
2292
|
...(sourceCheckEnabled ? [{ name: toolNames.sourceCheck, capability: "source-check" as const }] : []),
|
|
2280
2293
|
...(fetchContentEnabled ? [{ name: toolNames.fetchContent, capability: "fetch" as const }] : []),
|
|
@@ -2313,6 +2326,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
2313
2326
|
let currentSearchProvider: SearchProviderSelection = Array.isArray(rawSearchProvider)
|
|
2314
2327
|
? rawSearchProvider
|
|
2315
2328
|
: rawSearchProvider === "auto" ? "auto" : initialProvider;
|
|
2329
|
+
// A curator provider pick replaces currentSearchProvider with a string, which stays strict.
|
|
2330
|
+
const configDefaultProvider = currentSearchProvider;
|
|
2316
2331
|
const summaryContext: SummaryGenerationContext = {
|
|
2317
2332
|
model: ctx.model,
|
|
2318
2333
|
modelRegistry: ctx.modelRegistry,
|
|
@@ -2431,6 +2446,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2431
2446
|
const requestedProvider = resolveCuratorSearchProvider(provider, currentSearchProvider);
|
|
2432
2447
|
const response = await search(query, {
|
|
2433
2448
|
provider: requestedProvider,
|
|
2449
|
+
providerFromConfig: requestedProvider === configDefaultProvider,
|
|
2434
2450
|
signal: searchAbort.signal,
|
|
2435
2451
|
extensionContext: ctx,
|
|
2436
2452
|
});
|
|
@@ -2503,6 +2519,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2503
2519
|
try {
|
|
2504
2520
|
const response = await runWithProxy(undefined, () => search(query, {
|
|
2505
2521
|
provider: requestedProvider,
|
|
2522
|
+
providerFromConfig: requestedProvider === configDefaultProvider,
|
|
2506
2523
|
signal: searchAbort.signal,
|
|
2507
2524
|
extensionContext: ctx,
|
|
2508
2525
|
}));
|
|
@@ -5,13 +5,14 @@ import type { ExtractedContent } from "./extract.ts";
|
|
|
5
5
|
import type { SearchOptions, SearchResponse } from "./perplexity.ts";
|
|
6
6
|
import { formatSearchResultsAsAnswer } from "./search-answer-formatting.ts";
|
|
7
7
|
import { normalizeSearchResultCount } from "./search-result-count-normalization.ts";
|
|
8
|
-
import { getWebSearchConfigPath } from "./utils.ts";
|
|
8
|
+
import { getWebSearchConfigPath, resolveProviderApiUrl, fetchWithCredentialRedirects } from "./utils.ts";
|
|
9
9
|
|
|
10
10
|
const JINA_SEARCH_BASE_URL = "https://s.jina.ai/";
|
|
11
11
|
const CONFIG_PATH = getWebSearchConfigPath();
|
|
12
12
|
const SEARCH_TIMEOUT_MS = 60_000;
|
|
13
13
|
|
|
14
14
|
interface WebSearchConfig {
|
|
15
|
+
jinaSearchBaseUrl?: unknown;
|
|
15
16
|
jinaApiKey?: unknown;
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -107,7 +108,8 @@ function buildSearchRequest(query: string, options: JinaSearchOptions, numResult
|
|
|
107
108
|
const recency = options.recencyFilter ? ` published in the past ${options.recencyFilter}` : "";
|
|
108
109
|
const exclusions = filters.excludes.map((domain) => ` -site:${domain}`).join("");
|
|
109
110
|
const constrainedQuery = `${query.trim()}${exclusions}${recency}`.trim();
|
|
110
|
-
|
|
111
|
+
if (/^\.{1,2}$/.test(constrainedQuery)) throw new Error("Jina Search query must not be a dot path segment");
|
|
112
|
+
const url = new URL(encodeURIComponent(constrainedQuery), resolveProviderApiUrl("jinaSearch", JINA_SEARCH_BASE_URL, loadConfig().jinaSearchBaseUrl));
|
|
111
113
|
url.searchParams.set("count", String(numResults));
|
|
112
114
|
for (const domain of filters.includes) url.searchParams.append("site", domain);
|
|
113
115
|
return { url: url.toString(), filters };
|
|
@@ -215,7 +217,7 @@ export async function searchWithJina(query: string, options: JinaSearchOptions =
|
|
|
215
217
|
const request = requestSignal(options.signal);
|
|
216
218
|
let response: Response;
|
|
217
219
|
try {
|
|
218
|
-
response = await
|
|
220
|
+
response = await fetchWithCredentialRedirects(String(url), {
|
|
219
221
|
headers: {
|
|
220
222
|
"Accept": "application/json",
|
|
221
223
|
"Authorization": `Bearer ${apiKey}`,
|
|
@@ -224,7 +226,7 @@ export async function searchWithJina(query: string, options: JinaSearchOptions =
|
|
|
224
226
|
"X-Retain-Images": "none",
|
|
225
227
|
},
|
|
226
228
|
signal: request.signal,
|
|
227
|
-
});
|
|
229
|
+
}, ["Authorization"]);
|
|
228
230
|
} catch (err) {
|
|
229
231
|
rethrowRequestError(err, apiKey, activityId, request, options.signal);
|
|
230
232
|
}
|
|
@@ -6,7 +6,7 @@ import { formatSearchResultsAsAnswer } from "./search-answer-formatting.ts";
|
|
|
6
6
|
import { normalizeSearchResultCount } from "./search-result-count-normalization.ts";
|
|
7
7
|
import { hasCredentialSource, redactCredential, resolveCredential } from "./credential-source.ts";
|
|
8
8
|
import { fetchRemoteUrl, loadFetchContentDomainPolicy, loadSsrfConfig, validateRemoteUrl, type SsrfConfig } from "./ssrf-protection.ts";
|
|
9
|
-
import { getWebSearchConfigPath } from "./utils.ts";
|
|
9
|
+
import { getWebSearchConfigPath, resolveProviderApiUrl, fetchWithCredentialRedirects } from "./utils.ts";
|
|
10
10
|
|
|
11
11
|
const KAGI_SEARCH_URL = "https://kagi.com/api/v1/search";
|
|
12
12
|
const KAGI_EXTRACT_URL = "https://kagi.com/api/v1/extract";
|
|
@@ -14,6 +14,7 @@ const CONFIG_PATH = getWebSearchConfigPath();
|
|
|
14
14
|
const SEARCH_TIMEOUT_MS = 60_000;
|
|
15
15
|
|
|
16
16
|
interface WebSearchConfig {
|
|
17
|
+
kagiBaseUrl?: unknown;
|
|
17
18
|
kagiApiKey?: unknown;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -160,12 +161,12 @@ export async function searchWithKagi(query: string, options: KagiSearchOptions =
|
|
|
160
161
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
161
162
|
let response: Response;
|
|
162
163
|
try {
|
|
163
|
-
response = await
|
|
164
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("kagi", KAGI_SEARCH_URL, loadConfig().kagiBaseUrl), {
|
|
164
165
|
method: "POST",
|
|
165
166
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "application/json" },
|
|
166
167
|
body: JSON.stringify({ query, limit: numResults }),
|
|
167
168
|
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS),
|
|
168
|
-
});
|
|
169
|
+
}, ["Authorization"]);
|
|
169
170
|
} catch (err) {
|
|
170
171
|
const message = errorMessage(err);
|
|
171
172
|
const redactedMessage = redactCredential(message, apiKey);
|
|
@@ -217,7 +218,7 @@ export async function extractWithKagi(url: string, signal?: AbortSignal, options
|
|
|
217
218
|
const activityId = activityMonitor.logStart({ type: "api", query: `kagi extract: ${url}` });
|
|
218
219
|
let response: Response;
|
|
219
220
|
try {
|
|
220
|
-
response = await fetchRemoteUrl(KAGI_EXTRACT_URL, {
|
|
221
|
+
response = await fetchRemoteUrl(resolveProviderApiUrl("kagi", KAGI_EXTRACT_URL, loadConfig().kagiBaseUrl), {
|
|
221
222
|
method: "POST",
|
|
222
223
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "application/json" },
|
|
223
224
|
body: JSON.stringify({ pages: [{ url }] }),
|
|
@@ -5,7 +5,7 @@ import type { SearchOptions, SearchResponse } from "./perplexity.ts";
|
|
|
5
5
|
import { formatSearchResultsAsAnswer } from "./search-answer-formatting.ts";
|
|
6
6
|
import { normalizeSearchResultCount } from "./search-result-count-normalization.ts";
|
|
7
7
|
import { redactCredential, resolveCredential } from "./credential-source.ts";
|
|
8
|
-
import { fetchWithCredentialRedirects, getWebSearchConfigPath } from "./utils.ts";
|
|
8
|
+
import { fetchWithCredentialRedirects, getWebSearchConfigPath, resolveProviderApiUrl } from "./utils.ts";
|
|
9
9
|
|
|
10
10
|
const KEENABLE_SEARCH_URL = "https://api.keenable.ai/v1/search";
|
|
11
11
|
// Without a key the request goes to the public endpoint, which identifies the caller
|
|
@@ -24,6 +24,7 @@ const RECENCY_DAYS: Record<NonNullable<SearchOptions["recencyFilter"]>, number>
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
interface WebSearchConfig {
|
|
27
|
+
keenableBaseUrl?: unknown;
|
|
27
28
|
keenableApiKey?: unknown;
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -152,7 +153,7 @@ export async function searchWithKeenable(query: string, options: SearchOptions =
|
|
|
152
153
|
let response: Response;
|
|
153
154
|
let entries: KeenableResult[];
|
|
154
155
|
try {
|
|
155
|
-
response = await fetchWithCredentialRedirects(apiKey ? KEENABLE_SEARCH_URL : KEENABLE_PUBLIC_SEARCH_URL, {
|
|
156
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("keenable", apiKey ? KEENABLE_SEARCH_URL : KEENABLE_PUBLIC_SEARCH_URL, loadConfig().keenableBaseUrl), {
|
|
156
157
|
method: "POST",
|
|
157
158
|
headers,
|
|
158
159
|
body: JSON.stringify(body),
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { activityMonitor } from "./activity.ts";
|
|
3
|
+
import { hasCredentialSource, redactCredential, resolveCredential } from "./credential-source.ts";
|
|
4
|
+
import { normalizeDomain } from "./domain-filter-normalization.ts";
|
|
5
|
+
import type { ExtractedContent } from "./extract.ts";
|
|
6
|
+
import type { SearchOptions, SearchResponse } from "./perplexity.ts";
|
|
7
|
+
import { formatSearchResultsAsAnswer } from "./search-answer-formatting.ts";
|
|
8
|
+
import { normalizeSearchResultCount } from "./search-result-count-normalization.ts";
|
|
9
|
+
import { fetchWithCredentialRedirects, getWebSearchConfigPath, resolveProviderApiUrl } from "./utils.ts";
|
|
10
|
+
|
|
11
|
+
const LINKUP_SEARCH_URL = "https://api.linkup.so/v1/search";
|
|
12
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
13
|
+
const SEARCH_TIMEOUT_MS = 60_000;
|
|
14
|
+
const DEPTHS = ["flash", "fast", "standard", "deep"] as const;
|
|
15
|
+
type LinkupDepth = typeof DEPTHS[number];
|
|
16
|
+
|
|
17
|
+
interface LinkupConfig {
|
|
18
|
+
linkupBaseUrl?: unknown;
|
|
19
|
+
linkupApiKey?: unknown;
|
|
20
|
+
linkupDepth?: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface LinkupResult {
|
|
24
|
+
type?: unknown;
|
|
25
|
+
name?: unknown;
|
|
26
|
+
url?: unknown;
|
|
27
|
+
content?: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let cachedConfig: LinkupConfig | undefined;
|
|
31
|
+
|
|
32
|
+
function loadConfig(): LinkupConfig {
|
|
33
|
+
if (cachedConfig) return cachedConfig;
|
|
34
|
+
if (!existsSync(CONFIG_PATH)) return cachedConfig = {};
|
|
35
|
+
let parsed: unknown;
|
|
36
|
+
try {
|
|
37
|
+
parsed = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
38
|
+
} catch {
|
|
39
|
+
// JSON parse errors can quote credentials from the config file.
|
|
40
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: expected valid JSON`);
|
|
41
|
+
}
|
|
42
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
43
|
+
throw new Error(`Invalid config in ${CONFIG_PATH}: expected a JSON object`);
|
|
44
|
+
}
|
|
45
|
+
return cachedConfig = parsed as LinkupConfig;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getDepth(): LinkupDepth {
|
|
49
|
+
const value = loadConfig().linkupDepth;
|
|
50
|
+
if (value === undefined) return "fast";
|
|
51
|
+
if (typeof value !== "string" || !DEPTHS.includes(value as LinkupDepth)) {
|
|
52
|
+
throw new Error(`linkupDepth in ${CONFIG_PATH} must be one of: ${DEPTHS.join(", ")}`);
|
|
53
|
+
}
|
|
54
|
+
return value as LinkupDepth;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function domainFilters(values: string[] | undefined): { include: string[]; exclude: string[] } {
|
|
58
|
+
const include: string[] = [];
|
|
59
|
+
const exclude: string[] = [];
|
|
60
|
+
for (const raw of values ?? []) {
|
|
61
|
+
const domain = normalizeDomain(raw);
|
|
62
|
+
if (!domain) continue;
|
|
63
|
+
const target = raw.trim().startsWith("-") ? exclude : include;
|
|
64
|
+
if (!target.includes(domain)) target.push(domain);
|
|
65
|
+
}
|
|
66
|
+
if (include.length > 100 || exclude.length > 100) {
|
|
67
|
+
throw new Error("Linkup domainFilter must contain at most 100 included and 100 excluded domains");
|
|
68
|
+
}
|
|
69
|
+
return { include, exclude };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function recencyToDate(filter: SearchOptions["recencyFilter"]): string | undefined {
|
|
73
|
+
if (!filter) return undefined;
|
|
74
|
+
const days = { day: 1, week: 7, month: 30, year: 365 }[filter];
|
|
75
|
+
return new Date(Date.now() - days * 86_400_000).toISOString().slice(0, 10);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function text(value: unknown): string {
|
|
79
|
+
return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function parseResponse(value: unknown): LinkupResult[] {
|
|
83
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || !Array.isArray((value as Record<string, unknown>).results)) {
|
|
84
|
+
throw new Error("Linkup returned invalid response: expected results array");
|
|
85
|
+
}
|
|
86
|
+
return (value as { results: LinkupResult[] }).results;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function isLinkupAvailable(): boolean {
|
|
90
|
+
return hasCredentialSource({ provider: "Linkup", configuredValue: loadConfig().linkupApiKey, environmentValue: process.env.LINKUP_API_KEY });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function searchWithLinkup(query: string, options: SearchOptions & { includeContent?: boolean } = {}): Promise<SearchResponse> {
|
|
94
|
+
const depth = getDepth();
|
|
95
|
+
const filters = domainFilters(options.domainFilter);
|
|
96
|
+
const apiKey = await resolveCredential({
|
|
97
|
+
provider: "Linkup",
|
|
98
|
+
configuredValue: loadConfig().linkupApiKey,
|
|
99
|
+
environmentValue: process.env.LINKUP_API_KEY,
|
|
100
|
+
signal: options.signal,
|
|
101
|
+
});
|
|
102
|
+
if (!apiKey) {
|
|
103
|
+
throw new Error(`Linkup API key not found. Set linkupApiKey in ${CONFIG_PATH} or LINKUP_API_KEY. Get a key at https://app.linkup.so`);
|
|
104
|
+
}
|
|
105
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
106
|
+
const fromDate = recencyToDate(options.recencyFilter);
|
|
107
|
+
const timeout = AbortSignal.timeout(SEARCH_TIMEOUT_MS);
|
|
108
|
+
const signal = options.signal ? AbortSignal.any([timeout, options.signal]) : timeout;
|
|
109
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
110
|
+
let entries: LinkupResult[];
|
|
111
|
+
try {
|
|
112
|
+
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("linkup", LINKUP_SEARCH_URL, loadConfig().linkupBaseUrl), {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", Accept: "application/json" },
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
q: query, depth, outputType: "searchResults", maxResults: numResults,
|
|
117
|
+
...(fromDate ? { fromDate } : {}),
|
|
118
|
+
...(filters.include.length ? { includeDomains: filters.include } : {}),
|
|
119
|
+
...(filters.exclude.length ? { excludeDomains: filters.exclude } : {}),
|
|
120
|
+
}),
|
|
121
|
+
signal,
|
|
122
|
+
}, ["Authorization"]);
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
const body = redactCredential(await response.text(), apiKey).slice(0, 300);
|
|
125
|
+
throw new Error(`Linkup error ${response.status}: ${body}`);
|
|
126
|
+
}
|
|
127
|
+
let data: unknown;
|
|
128
|
+
try {
|
|
129
|
+
data = await response.json();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
// Preserve transport and cancellation errors for routing. Syntax errors
|
|
132
|
+
// can quote response content, so do not echo their messages.
|
|
133
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
134
|
+
throw new Error("Linkup returned invalid JSON");
|
|
135
|
+
}
|
|
136
|
+
entries = parseResponse(data);
|
|
137
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (options.signal?.aborted) {
|
|
140
|
+
activityMonitor.logComplete(activityId, 0);
|
|
141
|
+
throw new Error("Aborted");
|
|
142
|
+
}
|
|
143
|
+
const message = timeout.aborted || (err instanceof Error && err.name === "TimeoutError")
|
|
144
|
+
? "Linkup request timed out after 60s"
|
|
145
|
+
: redactCredential(err instanceof Error ? err.message : String(err), apiKey);
|
|
146
|
+
activityMonitor.logError(activityId, message);
|
|
147
|
+
const outgoing = err instanceof TypeError ? new TypeError(message) : new Error(message);
|
|
148
|
+
if (err instanceof Error && !timeout.aborted) outgoing.name = err.name;
|
|
149
|
+
throw outgoing;
|
|
150
|
+
}
|
|
151
|
+
const results: SearchResponse["results"] = [];
|
|
152
|
+
const inlineContent: ExtractedContent[] = [];
|
|
153
|
+
const seen = new Set<string>();
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
if (!entry || typeof entry !== "object" || entry.type !== "text" || typeof entry.url !== "string") continue;
|
|
156
|
+
let url: URL;
|
|
157
|
+
try { url = new URL(entry.url); } catch { continue; }
|
|
158
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") continue;
|
|
159
|
+
const matches = (domain: string) => url.hostname === domain || url.hostname.endsWith(`.${domain}`);
|
|
160
|
+
if (filters.exclude.some(matches) || (filters.include.length && !filters.include.some(matches))) continue;
|
|
161
|
+
if (seen.has(url.href)) continue;
|
|
162
|
+
seen.add(url.href);
|
|
163
|
+
const title = text(entry.name) || `Source ${results.length + 1}`;
|
|
164
|
+
const content = typeof entry.content === "string" ? entry.content.trim().slice(0, 4_000) : "";
|
|
165
|
+
results.push({ title, url: url.href, snippet: text(content).slice(0, 500) });
|
|
166
|
+
if (options.includeContent && content) inlineContent.push({ url: url.href, title, content, error: null });
|
|
167
|
+
if (results.length >= numResults) break;
|
|
168
|
+
}
|
|
169
|
+
return { answer: formatSearchResultsAsAnswer(results), results, ...(inlineContent.length ? { inlineContent } : {}) };
|
|
170
|
+
}
|