@herbertgao/pi-extensions 2026.11.2 → 2026.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +13 -13
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +109 -16
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +33 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +72 -17
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/write-execution.ts +5 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/tool-io.ts +16 -7
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +7 -5
- package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-dark-hc.json +92 -0
- package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-light-hc.json +92 -0
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +12 -10
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-record-entry.ts +22 -6
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +9 -4
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +167 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/viewer-keys.ts +8 -4
- package/node_modules/@narumitw/pi-btw/CHANGELOG.md +259 -0
- package/node_modules/@narumitw/pi-btw/package.json +6 -5
- package/node_modules/@narumitw/pi-caffeinate/CHANGELOG.md +70 -0
- package/node_modules/@narumitw/pi-caffeinate/package.json +5 -4
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +48 -0
- package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +64 -5
- package/node_modules/pi-commandcode-provider/README.md +44 -18
- package/node_modules/pi-commandcode-provider/RELEASE.md +25 -0
- package/node_modules/pi-commandcode-provider/index.ts +222 -42
- package/node_modules/pi-commandcode-provider/package.json +9 -8
- package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +6 -13
- package/node_modules/pi-commandcode-provider/scripts/typecheck-entrypoint.mjs +88 -0
- package/node_modules/pi-commandcode-provider/src/api-key.ts +67 -10
- package/node_modules/pi-commandcode-provider/src/auth-server.ts +33 -24
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +9 -2
- package/node_modules/pi-commandcode-provider/src/cost.ts +29 -43
- package/node_modules/pi-commandcode-provider/src/diagnostics.ts +215 -0
- package/node_modules/pi-commandcode-provider/src/oauth.ts +41 -7
- package/node_modules/pi-commandcode-provider/src/pricing.ts +5 -3
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/routing.ts +166 -0
- package/node_modules/pi-commandcode-provider/src/runtime.ts +23 -10
- package/node_modules/pi-commandcode-provider/src/transport.ts +82 -85
- package/node_modules/pi-commandcode-provider/src/types.ts +20 -39
- package/node_modules/pi-commandcode-provider/src/usage.ts +1 -1
- package/node_modules/pi-lens/CHANGELOG-USER.md +31 -0
- package/node_modules/pi-lens/CHANGELOG.md +178 -0
- package/node_modules/pi-lens/README.md +2 -1
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -1
- package/node_modules/pi-lens/dist/{chunk-3O5EII3W.js → chunk-2VZ3VN3N.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-SDFKOLSF.js → chunk-3HTZDY3C.js} +8 -6
- package/node_modules/pi-lens/dist/{chunk-A5GRLYPZ.js → chunk-3NPWO5UO.js} +7 -13
- package/node_modules/pi-lens/dist/{chunk-AGGUWKRK.js → chunk-47UCC4MM.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-4ENEJHF4.js +198 -0
- package/node_modules/pi-lens/dist/{chunk-WXUDRAG6.js → chunk-5GEYJJHG.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-HHR7WGCI.js → chunk-5YSEQHJN.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-L3CLUGDY.js → chunk-6GPB3JLL.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-5F3XF3SX.js → chunk-7R5GZIA6.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-CUDD35TW.js → chunk-7UTSNTWM.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-DYRZGUMA.js → chunk-7YTRG6YW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-JZRP4DGP.js → chunk-AACN5GNE.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7ANZ7XDD.js → chunk-ACRJ2GZ5.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6FIRFP6A.js → chunk-C3YRO3EU.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-GMROJJRN.js → chunk-CB7PEVOJ.js} +9 -1
- package/node_modules/pi-lens/dist/{chunk-BBET6HD6.js → chunk-CDFJF5YD.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-NSPVR3FN.js → chunk-CJS6WE66.js} +17 -19
- package/node_modules/pi-lens/dist/{chunk-6YUNI7B5.js → chunk-CM6BDY4E.js} +14 -60
- package/node_modules/pi-lens/dist/{chunk-G5GV2Q7K.js → chunk-CZCAZVTD.js} +16 -2
- package/node_modules/pi-lens/dist/chunk-DGKFWQK4.js +23 -0
- package/node_modules/pi-lens/dist/{chunk-VOP4PJKA.js → chunk-E65WJVI5.js} +7 -9
- package/node_modules/pi-lens/dist/{chunk-TV6RXRYH.js → chunk-EKNYSXFB.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-4LL2VRNY.js → chunk-EY6LY2HO.js} +16 -18
- package/node_modules/pi-lens/dist/{chunk-MC6VB2E5.js → chunk-F6BEQWAK.js} +17 -5
- package/node_modules/pi-lens/dist/{chunk-R2QQC33W.js → chunk-FGNSESAC.js} +12 -14
- package/node_modules/pi-lens/dist/{chunk-OC7VWJBZ.js → chunk-FRUBVFXV.js} +35 -37
- package/node_modules/pi-lens/dist/{chunk-7CGIDRIK.js → chunk-G22UNQID.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-L4NEVZ4T.js → chunk-GQTQUNCG.js} +25 -27
- package/node_modules/pi-lens/dist/{chunk-ZKLTNLAW.js → chunk-H3BVMK47.js} +6 -6
- package/node_modules/pi-lens/dist/chunk-H6FLQ5NW.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-2ZE3AUJQ.js → chunk-HEA3EM23.js} +13 -15
- package/node_modules/pi-lens/dist/{chunk-CZL44WFN.js → chunk-HSOBIN22.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-PKSUMEPT.js → chunk-HYSKJMZK.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-VN3L2JWZ.js → chunk-IICERRFF.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-O4N5BQ3T.js → chunk-IILEH3ZC.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-WC6WRNQT.js → chunk-J3Q2NYJR.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-SFLHSL5R.js → chunk-JUZ67QZQ.js} +18 -7
- package/node_modules/pi-lens/dist/chunk-KR5VGMVT.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-UHHLR2VY.js → chunk-KV6GQOGN.js} +38 -41
- package/node_modules/pi-lens/dist/{chunk-HUAM7QG3.js → chunk-KXMJLOZF.js} +25 -23
- package/node_modules/pi-lens/dist/{chunk-BUZIQDFS.js → chunk-L4Y3ROKQ.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-JBP7KESM.js → chunk-L6WBJGQS.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-35WKJWO5.js → chunk-L7O774U7.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-BOPDQ7AZ.js → chunk-LAHHGNAY.js} +19 -21
- package/node_modules/pi-lens/dist/{chunk-RGGH6M34.js → chunk-LT62P654.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-5T5A6YAJ.js → chunk-LWOM6LVS.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-JYLOYTZD.js → chunk-MKPDIAZH.js} +5 -1
- package/node_modules/pi-lens/dist/{chunk-CM73PPGD.js → chunk-MN635QYA.js} +3 -4
- package/node_modules/pi-lens/dist/{chunk-BQG2QFVO.js → chunk-MQ4PPCJB.js} +21 -29
- package/node_modules/pi-lens/dist/{chunk-HXFUTMX2.js → chunk-MRLH4MYU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-XOMGO63G.js → chunk-N56BNAA6.js} +19 -21
- package/node_modules/pi-lens/dist/{chunk-7MAD5ZAY.js → chunk-N5CEGQPG.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-ZFORSIED.js → chunk-NCLO6E6N.js} +13 -33
- package/node_modules/pi-lens/dist/{chunk-SQC7K3SP.js → chunk-NL5LSKVD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-I22THIHI.js → chunk-NMUSOZ2D.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-4NBWFYWW.js → chunk-NOWH2VA2.js} +8 -33
- package/node_modules/pi-lens/dist/{chunk-NM2NWH55.js → chunk-NUSXS6YB.js} +6 -5
- package/node_modules/pi-lens/dist/{chunk-OZWXLJMX.js → chunk-OSEKJEUU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-2BKUFQKR.js → chunk-OUYAUXAT.js} +405 -181
- package/node_modules/pi-lens/dist/{chunk-JPRDTY5S.js → chunk-PBZNYHMM.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-JE6HKLC7.js → chunk-PIIUNJIT.js} +2 -4
- package/node_modules/pi-lens/dist/{chunk-ZZDIOAAJ.js → chunk-PRHYIA6X.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-4W52ZKZX.js → chunk-PXQ45SGD.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-Q6JQKWPK.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-PIQQM32Y.js → chunk-QB7T2PHK.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-HKIL6DCL.js → chunk-QGITU23N.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-QJJKOHLH.js +57 -0
- package/node_modules/pi-lens/dist/{chunk-6LJOJ6EO.js → chunk-QP33NKYC.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-DIWK3LBC.js → chunk-QVBOXT3L.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-IYVYZQRL.js → chunk-RNJFRXEN.js} +5 -7
- package/node_modules/pi-lens/dist/{chunk-G6JKM4O7.js → chunk-RNXOWDM6.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-5RNB4HVK.js → chunk-RTFMDIKV.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-XWIME22V.js → chunk-SIQHOB6P.js} +11 -13
- package/node_modules/pi-lens/dist/{chunk-T2S3FNNJ.js → chunk-SLSMJPEF.js} +41 -42
- package/node_modules/pi-lens/dist/chunk-T5QSLSMM.js +50 -0
- package/node_modules/pi-lens/dist/chunk-TGQDAG4B.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-6GMGEKQN.js → chunk-THYHUIDR.js} +39 -12
- package/node_modules/pi-lens/dist/{chunk-WMDUT4KH.js → chunk-TMNUTMT5.js} +72 -89
- package/node_modules/pi-lens/dist/{chunk-7TNILKGY.js → chunk-TOE2RRCS.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-TYHPVE5H.js +25 -0
- package/node_modules/pi-lens/dist/chunk-UAKO2M6B.js +73 -0
- package/node_modules/pi-lens/dist/chunk-UC5AXW5Z.js +20 -0
- package/node_modules/pi-lens/dist/chunk-UTJP6WOS.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-FRLAUP2B.js → chunk-UXTQ3QPD.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-4QG55RRC.js → chunk-V2WDBOLZ.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-FHEV6T4L.js → chunk-V67D6TMU.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-VLQ7UKZH.js → chunk-VCRVNLE7.js} +135 -2
- package/node_modules/pi-lens/dist/{chunk-KZ4ALBCH.js → chunk-VO4JFPTV.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-GIRBSBGL.js → chunk-VWLSU3XV.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2453RRJ2.js → chunk-W5E72HJA.js} +59 -22
- package/node_modules/pi-lens/dist/{chunk-VPLBLWFO.js → chunk-W7TY6HYX.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-SP4TFY5F.js → chunk-WSSLVMDA.js} +11 -13
- package/node_modules/pi-lens/dist/{chunk-PPKECBPP.js → chunk-WTB4GKMH.js} +10 -1
- package/node_modules/pi-lens/dist/{chunk-X35S7HSB.js → chunk-X5BJ3G2P.js} +41 -30
- package/node_modules/pi-lens/dist/{chunk-X66YJ2SS.js → chunk-XKFO2SZV.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-OWTG6UMO.js → chunk-XLAI7UYY.js} +75 -22
- package/node_modules/pi-lens/dist/{chunk-4B2YFN4U.js → chunk-XO756WE5.js} +45 -33
- package/node_modules/pi-lens/dist/{chunk-VOXTCULR.js → chunk-XVB3Q2PG.js} +2 -4
- package/node_modules/pi-lens/dist/{chunk-XYLC35E4.js → chunk-YOXCCJDF.js} +517 -308
- package/node_modules/pi-lens/dist/{chunk-O2ARHQKF.js → chunk-ZCQBNPRH.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-ZD4KVFXI.js +234 -0
- package/node_modules/pi-lens/dist/{chunk-LSFXZLPW.js → chunk-ZDMFGACN.js} +184 -235
- package/node_modules/pi-lens/dist/{chunk-4BKU7PV3.js → chunk-ZMMHHXSW.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-OY7WZI7Q.js → chunk-ZPM7ZIFL.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-R4QWJQ2H.js → chunk-ZVCDHYWZ.js} +9 -11
- package/node_modules/pi-lens/dist/{chunk-RZG472YW.js → chunk-ZZN74OGD.js} +83 -46
- package/node_modules/pi-lens/dist/{chunk-BHWW6FAX.js → chunk-ZZSJAR76.js} +37 -19
- package/node_modules/pi-lens/dist/index.js +4910 -4218
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +12 -17
- package/node_modules/pi-lens/dist/mcp/cli.js +41 -42
- package/node_modules/pi-lens/dist/mcp/server.js +1451 -648
- package/node_modules/pi-lens/dist/mcp/worker.js +59 -60
- package/node_modules/pi-lens/dist/probes/installer.js +17 -19
- package/node_modules/pi-lens/docs/agent-tools.md +40 -8
- package/node_modules/pi-lens/docs/analysisall.md +1 -1
- package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +7 -5
- package/node_modules/pi-lens/docs/configuration.md +51 -9
- package/node_modules/pi-lens/docs/defect-shapes.md +52 -3
- package/node_modules/pi-lens/docs/environment-variables.md +18 -1
- package/node_modules/pi-lens/docs/features.md +12 -5
- package/node_modules/pi-lens/docs/globalconfig.md +11 -3
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +9 -2
- package/node_modules/pi-lens/docs/invariants/session-telemetry.md +2 -2
- package/node_modules/pi-lens/docs/language-coverage.md +1 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +57 -35
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +4 -1
- package/node_modules/pi-lens/docs/merge-queue-rollout.md +10 -8
- package/node_modules/pi-lens/docs/module-report-read-symbol.md +34 -23
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +11 -1
- package/node_modules/pi-lens/docs/pi-lens-investigator.md +3 -0
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +15 -7
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +13 -0
- package/node_modules/pi-lens/docs/public-api-stability.md +39 -5
- package/node_modules/pi-lens/docs/release-qa-baseline.md +7 -4
- package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +11 -2
- package/node_modules/pi-lens/docs/servercapabilities.md +3 -1
- package/node_modules/pi-lens/docs/settings.md +2 -2
- package/node_modules/pi-lens/docs/word-index.md +3 -2
- package/node_modules/pi-lens/package.json +8 -3
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +1 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +1 -2
- package/node_modules/pi-lens/scripts/download-grammars.js +3 -2
- package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +5 -1
- package/node_modules/pi-provider-qoder/dist/index.js +473 -62
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +22 -0
- package/node_modules/pi-web-access/README.md +31 -12
- package/node_modules/pi-web-access/curator-page.ts +5 -1
- package/node_modules/pi-web-access/curator-server.ts +2 -0
- package/node_modules/pi-web-access/dist/index.js +673 -308
- package/node_modules/pi-web-access/dist/mcp-cli.js +666 -309
- package/node_modules/pi-web-access/gemini-search.ts +12 -4
- package/node_modules/pi-web-access/github-api.ts +1 -1
- package/node_modules/pi-web-access/github-extract.ts +3 -2
- package/node_modules/pi-web-access/index.ts +7 -3
- package/node_modules/pi-web-access/mcp-tool-definitions.ts +1 -1
- package/node_modules/pi-web-access/outcrawl.ts +204 -0
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/pi-web-access/sofya.ts +201 -0
- package/node_modules/pi-web-access/utils.ts +16 -6
- package/node_modules/pi-web-access/web-tool-core.ts +4 -0
- package/package.json +16 -14
- package/node_modules/pi-commandcode-provider/src/converters.ts +0 -477
- package/node_modules/pi-commandcode-provider/src/core.ts +0 -836
- package/node_modules/pi-commandcode-provider/src/json-schema.ts +0 -417
- package/node_modules/pi-commandcode-provider/src/transcript.ts +0 -56
- package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +0 -31
- package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +0 -27
- package/node_modules/pi-lens/dist/chunk-447YZL4S.js +0 -25
- package/node_modules/pi-lens/dist/chunk-565VRUP4.js +0 -136
- package/node_modules/pi-lens/dist/chunk-57X2CDRX.js +0 -49
- package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +0 -27
- package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +0 -58
- package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +0 -22
- package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +0 -89
- package/node_modules/pi-lens/dist/chunk-U3AS2FR6.js +0 -106
- package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +0 -27
- package/node_modules/pi-lens/dist/chunk-WQV6BI4Q.js +0 -48
- package/node_modules/pi-lens/dist/chunk-YHGYAEFH.js +0 -443
- package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +0 -74
- package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +0 -30
|
@@ -230,8 +230,8 @@ function redactProxyUrl(value) {
|
|
|
230
230
|
if (parsed.password) parsed.password = "redacted";
|
|
231
231
|
return parsed.toString();
|
|
232
232
|
}
|
|
233
|
-
function
|
|
234
|
-
let
|
|
233
|
+
function loadProxyConfig() {
|
|
234
|
+
let config = {};
|
|
235
235
|
const path = getWebSearchConfigPath();
|
|
236
236
|
if (existsSync(path)) {
|
|
237
237
|
let raw;
|
|
@@ -241,19 +241,28 @@ function loadConfiguredProxy() {
|
|
|
241
241
|
const message = err instanceof Error ? err.message : String(err);
|
|
242
242
|
throw new Error(`Failed to load proxy config from ${path}: ${message}`);
|
|
243
243
|
}
|
|
244
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw))
|
|
244
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) config = raw;
|
|
245
245
|
}
|
|
246
|
-
if (
|
|
247
|
-
|
|
246
|
+
if (config.lockProxy !== void 0 && typeof config.lockProxy !== "boolean") throw new Error(`lockProxy in ${path} must be true or false`);
|
|
247
|
+
const locked = config.lockProxy === true;
|
|
248
|
+
const proxy = config.proxy === void 0 ? null : normalizeProxyUrl(config.proxy, `proxy in ${path}`);
|
|
249
|
+
if (locked && proxy === null) throw new Error(`lockProxy is set in ${path} but no proxy is configured there; set proxy or remove lockProxy`);
|
|
250
|
+
return { proxy, locked };
|
|
251
|
+
}
|
|
252
|
+
function loadConfiguredProxy() {
|
|
253
|
+
return loadProxyConfig().proxy;
|
|
248
254
|
}
|
|
249
255
|
function runWithProxy(proxy, fn) {
|
|
256
|
+
const { proxy: configured, locked } = loadProxyConfig();
|
|
250
257
|
if (proxy === void 0) {
|
|
251
|
-
const configured = loadConfiguredProxy();
|
|
252
258
|
if (configured === null) return fn();
|
|
253
259
|
installGlobalProxyFetch();
|
|
254
260
|
return proxyStorage.run(configured, fn);
|
|
255
261
|
}
|
|
256
262
|
const normalized = normalizeProxyUrl(proxy, "proxy");
|
|
263
|
+
if (locked && normalized !== configured) {
|
|
264
|
+
throw new Error(`proxy argument rejected: lockProxy is set in ${getWebSearchConfigPath()}; omit proxy to use the configured proxy`);
|
|
265
|
+
}
|
|
257
266
|
if (normalized !== null) installGlobalProxyFetch();
|
|
258
267
|
return proxyStorage.run(normalized, fn);
|
|
259
268
|
}
|
|
@@ -696,7 +705,9 @@ async function fetchReadmeViaApi(owner, repo, ref) {
|
|
|
696
705
|
}
|
|
697
706
|
try {
|
|
698
707
|
const decoded = Buffer.from(stdout.trim(), "base64").toString("utf-8");
|
|
699
|
-
resolve2(decoded.length >
|
|
708
|
+
resolve2(decoded.length > MAX_INLINE_FILE_CHARS ? `${decoded.slice(0, MAX_INLINE_FILE_CHARS)}
|
|
709
|
+
|
|
710
|
+
[README truncated at 100K chars]` : decoded);
|
|
700
711
|
} catch {
|
|
701
712
|
resolve2(null);
|
|
702
713
|
}
|
|
@@ -791,6 +802,7 @@ import { lstat as lstatAsync, open as openAsync, opendir as opendirAsync, readFi
|
|
|
791
802
|
import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
|
|
792
803
|
import { createHash } from "node:crypto";
|
|
793
804
|
import { basename, dirname, extname, join as join2, resolve as resolvePath, sep as pathSep } from "node:path";
|
|
805
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
794
806
|
function normalizeEnabled(value, fallback) {
|
|
795
807
|
return typeof value === "boolean" ? value : fallback;
|
|
796
808
|
}
|
|
@@ -820,7 +832,7 @@ function loadGitHubConfig() {
|
|
|
820
832
|
enabled: true,
|
|
821
833
|
maxRepoSizeMB: 350,
|
|
822
834
|
cloneTimeoutSeconds: 30,
|
|
823
|
-
clonePath: "
|
|
835
|
+
clonePath: join2(tmpdir2(), "pi-github-repos")
|
|
824
836
|
};
|
|
825
837
|
if (!existsSync3(CONFIG_PATH)) {
|
|
826
838
|
cachedConfig = defaults2;
|
|
@@ -1354,7 +1366,9 @@ function readReadme(localPath) {
|
|
|
1354
1366
|
if (existsSync3(readmePath)) {
|
|
1355
1367
|
try {
|
|
1356
1368
|
const content = readFileSync3(readmePath, "utf-8");
|
|
1357
|
-
return content.length >
|
|
1369
|
+
return content.length > MAX_INLINE_FILE_CHARS2 ? `${content.slice(0, MAX_INLINE_FILE_CHARS2)}
|
|
1370
|
+
|
|
1371
|
+
[README truncated at 100K chars. Full file: ${readmePath}]` : content;
|
|
1358
1372
|
} catch {
|
|
1359
1373
|
continue;
|
|
1360
1374
|
}
|
|
@@ -2519,7 +2533,7 @@ var init_gemini_web_config = __esm({
|
|
|
2519
2533
|
import { execFile as execFile4 } from "node:child_process";
|
|
2520
2534
|
import { pbkdf2Sync, createDecipheriv } from "node:crypto";
|
|
2521
2535
|
import { copyFileSync, existsSync as existsSync8, mkdtempSync as mkdtempSync2, readdirSync as readdirSync2, readFileSync as readFileSync7, realpathSync as realpathSync2, rmSync as rmSync2 } from "node:fs";
|
|
2522
|
-
import { tmpdir as
|
|
2536
|
+
import { tmpdir as tmpdir3, homedir as homedir3 } from "node:os";
|
|
2523
2537
|
import { isAbsolute, join as join4, sep } from "node:path";
|
|
2524
2538
|
function getLastGoogleCookieDiagnostic() {
|
|
2525
2539
|
return lastCookieDiagnostic;
|
|
@@ -2600,7 +2614,7 @@ async function getBrowserCookiesForHosts(options) {
|
|
|
2600
2614
|
continue;
|
|
2601
2615
|
}
|
|
2602
2616
|
sawCookieDatabase = true;
|
|
2603
|
-
const tempDir = mkdtempSync2(join4(
|
|
2617
|
+
const tempDir = mkdtempSync2(join4(tmpdir3(), "pi-chrome-cookies-"));
|
|
2604
2618
|
try {
|
|
2605
2619
|
const tempDb = join4(tempDir, "Cookies");
|
|
2606
2620
|
copyFileSync(cookiesPath, tempDb);
|
|
@@ -6917,45 +6931,45 @@ var init_ollama = __esm({
|
|
|
6917
6931
|
});
|
|
6918
6932
|
|
|
6919
6933
|
// deepseek.ts
|
|
6920
|
-
import { existsSync as
|
|
6921
|
-
function
|
|
6922
|
-
if (
|
|
6923
|
-
if (!
|
|
6924
|
-
|
|
6925
|
-
return
|
|
6934
|
+
import { existsSync as existsSync49, readFileSync as readFileSync49 } from "node:fs";
|
|
6935
|
+
function loadConfig42() {
|
|
6936
|
+
if (cachedConfig41) return cachedConfig41;
|
|
6937
|
+
if (!existsSync49(CONFIG_PATH45)) {
|
|
6938
|
+
cachedConfig41 = {};
|
|
6939
|
+
return cachedConfig41;
|
|
6926
6940
|
}
|
|
6927
|
-
const raw =
|
|
6941
|
+
const raw = readFileSync49(CONFIG_PATH45, "utf-8");
|
|
6928
6942
|
let parsed;
|
|
6929
6943
|
try {
|
|
6930
6944
|
parsed = JSON.parse(raw);
|
|
6931
6945
|
} catch (err) {
|
|
6932
6946
|
const message = err instanceof Error ? err.message : String(err);
|
|
6933
|
-
throw new Error(`Failed to parse ${
|
|
6947
|
+
throw new Error(`Failed to parse ${CONFIG_PATH45}: ${message}`);
|
|
6934
6948
|
}
|
|
6935
6949
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
6936
|
-
throw new Error(`Invalid config in ${
|
|
6950
|
+
throw new Error(`Invalid config in ${CONFIG_PATH45}: expected a JSON object`);
|
|
6937
6951
|
}
|
|
6938
|
-
|
|
6939
|
-
return
|
|
6952
|
+
cachedConfig41 = parsed;
|
|
6953
|
+
return cachedConfig41;
|
|
6940
6954
|
}
|
|
6941
|
-
async function
|
|
6955
|
+
async function requireApiKey18(signal) {
|
|
6942
6956
|
const apiKey = await resolveCredential({
|
|
6943
6957
|
provider: "DeepSeek",
|
|
6944
|
-
configuredValue:
|
|
6958
|
+
configuredValue: loadConfig42().deepseekApiKey,
|
|
6945
6959
|
environmentValue: process.env.DEEPSEEK_API_KEY,
|
|
6946
6960
|
signal
|
|
6947
6961
|
});
|
|
6948
6962
|
if (!apiKey) {
|
|
6949
6963
|
throw new Error(
|
|
6950
6964
|
`DeepSeek API key not found. Either:
|
|
6951
|
-
1. Create ${
|
|
6965
|
+
1. Create ${CONFIG_PATH45} with { "deepseekApiKey": "your-key" }
|
|
6952
6966
|
2. Set DEEPSEEK_API_KEY environment variable
|
|
6953
6967
|
Get a key at https://platform.deepseek.com/api_keys`
|
|
6954
6968
|
);
|
|
6955
6969
|
}
|
|
6956
6970
|
return apiKey;
|
|
6957
6971
|
}
|
|
6958
|
-
function
|
|
6972
|
+
function buildQuery11(query, options) {
|
|
6959
6973
|
const include = [];
|
|
6960
6974
|
const exclude = [];
|
|
6961
6975
|
for (const raw of options.domainFilter ?? []) {
|
|
@@ -6981,7 +6995,7 @@ function buildQuery10(query, options) {
|
|
|
6981
6995
|
function text6(value) {
|
|
6982
6996
|
return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
6983
6997
|
}
|
|
6984
|
-
function
|
|
6998
|
+
function errorMessage30(err) {
|
|
6985
6999
|
return err instanceof Error ? err.message : String(err);
|
|
6986
7000
|
}
|
|
6987
7001
|
function unescapeMarkdownSegment(segment) {
|
|
@@ -7034,7 +7048,7 @@ function isUnusableDeepSeekPage(title, content) {
|
|
|
7034
7048
|
if (heading !== "" && ERROR_TITLE.test(heading)) return true;
|
|
7035
7049
|
return ERROR_TITLE.test(text6(title)) && /\b(?:404|page not found|not found)\b/i.test(content.slice(0, 200));
|
|
7036
7050
|
}
|
|
7037
|
-
function
|
|
7051
|
+
function parseResponse15(value) {
|
|
7038
7052
|
const results = value && typeof value === "object" && !Array.isArray(value) ? value.results : void 0;
|
|
7039
7053
|
if (!Array.isArray(results)) throw new Error("DeepSeek returned invalid response: expected a results array");
|
|
7040
7054
|
return results;
|
|
@@ -7049,18 +7063,18 @@ function describeError3(body) {
|
|
|
7049
7063
|
return body;
|
|
7050
7064
|
}
|
|
7051
7065
|
function isDeepSeekAvailable() {
|
|
7052
|
-
return hasCredentialSource({ provider: "DeepSeek", configuredValue:
|
|
7066
|
+
return hasCredentialSource({ provider: "DeepSeek", configuredValue: loadConfig42().deepseekApiKey, environmentValue: process.env.DEEPSEEK_API_KEY });
|
|
7053
7067
|
}
|
|
7054
7068
|
async function searchWithDeepSeek(query, options = {}) {
|
|
7055
|
-
const builtQuery =
|
|
7056
|
-
const apiKey = await
|
|
7069
|
+
const builtQuery = buildQuery11(query, options);
|
|
7070
|
+
const apiKey = await requireApiKey18(options.signal);
|
|
7057
7071
|
const numResults = normalizeSearchResultCount(options.numResults);
|
|
7058
7072
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
7059
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
7073
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS37);
|
|
7060
7074
|
let response;
|
|
7061
7075
|
let entries;
|
|
7062
7076
|
try {
|
|
7063
|
-
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_SEARCH_URL,
|
|
7077
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_SEARCH_URL, loadConfig42().deepseekBaseUrl), {
|
|
7064
7078
|
method: "POST",
|
|
7065
7079
|
headers: {
|
|
7066
7080
|
Accept: "application/json",
|
|
@@ -7079,24 +7093,24 @@ async function searchWithDeepSeek(query, options = {}) {
|
|
|
7079
7093
|
rawData = await response.json();
|
|
7080
7094
|
} catch (err) {
|
|
7081
7095
|
if (err instanceof Error && err.name === "TimeoutError") throw err;
|
|
7082
|
-
throw new Error(`DeepSeek returned invalid JSON: ${
|
|
7096
|
+
throw new Error(`DeepSeek returned invalid JSON: ${errorMessage30(err)}`);
|
|
7083
7097
|
}
|
|
7084
|
-
entries =
|
|
7098
|
+
entries = parseResponse15(rawData);
|
|
7085
7099
|
} catch (err) {
|
|
7086
7100
|
if (options.signal?.aborted) {
|
|
7087
7101
|
activityMonitor.logComplete(activityId, 0);
|
|
7088
7102
|
throw new Error("Aborted");
|
|
7089
7103
|
}
|
|
7090
|
-
const message =
|
|
7104
|
+
const message = errorMessage30(err);
|
|
7091
7105
|
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
7092
|
-
const outgoing = providerTimeout ? new Error(`DeepSeek request timed out after ${Math.round(
|
|
7106
|
+
const outgoing = providerTimeout ? new Error(`DeepSeek request timed out after ${Math.round(SEARCH_TIMEOUT_MS37 / 1e3)}s`) : (() => {
|
|
7093
7107
|
const redactedMessage = redactCredential(message, apiKey);
|
|
7094
7108
|
if (redactedMessage === message && err instanceof Error) return err;
|
|
7095
7109
|
const redactedError = new Error(redactedMessage);
|
|
7096
7110
|
if (err instanceof Error) redactedError.name = err.name;
|
|
7097
7111
|
return redactedError;
|
|
7098
7112
|
})();
|
|
7099
|
-
activityMonitor.logError(activityId, redactCredential(
|
|
7113
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage30(outgoing), apiKey));
|
|
7100
7114
|
throw outgoing;
|
|
7101
7115
|
}
|
|
7102
7116
|
activityMonitor.logComplete(activityId, response.status);
|
|
@@ -7133,7 +7147,7 @@ async function searchWithDeepSeek(query, options = {}) {
|
|
|
7133
7147
|
return searchResponse;
|
|
7134
7148
|
}
|
|
7135
7149
|
async function extractWithDeepSeek(url, signal, options = {}) {
|
|
7136
|
-
const apiKey = await
|
|
7150
|
+
const apiKey = await requireApiKey18(signal);
|
|
7137
7151
|
const activityId = activityMonitor.logStart({ type: "fetch", url });
|
|
7138
7152
|
const timeoutMs = options.timeoutMs ?? FETCH_TIMEOUT_MS2;
|
|
7139
7153
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
@@ -7145,7 +7159,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
7145
7159
|
domainPolicy: loadFetchContentDomainPolicy(),
|
|
7146
7160
|
...options.lookup ? { lookup: options.lookup } : {}
|
|
7147
7161
|
});
|
|
7148
|
-
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_FETCH_URL,
|
|
7162
|
+
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("deepseek", DEEPSEEK_FETCH_URL, loadConfig42().deepseekBaseUrl), {
|
|
7149
7163
|
method: "POST",
|
|
7150
7164
|
headers: {
|
|
7151
7165
|
Accept: "application/json",
|
|
@@ -7164,7 +7178,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
7164
7178
|
rawData = await response.json();
|
|
7165
7179
|
} catch (err) {
|
|
7166
7180
|
if (err instanceof Error && err.name === "TimeoutError") throw err;
|
|
7167
|
-
throw new Error(`DeepSeek Fetch returned invalid JSON: ${
|
|
7181
|
+
throw new Error(`DeepSeek Fetch returned invalid JSON: ${errorMessage30(err)}`);
|
|
7168
7182
|
}
|
|
7169
7183
|
if (!rawData || typeof rawData !== "object" || Array.isArray(rawData)) {
|
|
7170
7184
|
throw new Error("DeepSeek Fetch returned an unexpected response shape");
|
|
@@ -7184,7 +7198,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
7184
7198
|
error: null
|
|
7185
7199
|
};
|
|
7186
7200
|
} catch (err) {
|
|
7187
|
-
const message =
|
|
7201
|
+
const message = errorMessage30(err);
|
|
7188
7202
|
if (signal?.aborted) {
|
|
7189
7203
|
activityMonitor.logComplete(activityId, 0);
|
|
7190
7204
|
throw new Error("Aborted");
|
|
@@ -7200,7 +7214,7 @@ async function extractWithDeepSeek(url, signal, options = {}) {
|
|
|
7200
7214
|
throw redactedError;
|
|
7201
7215
|
}
|
|
7202
7216
|
}
|
|
7203
|
-
var DEEPSEEK_SEARCH_URL, DEEPSEEK_FETCH_URL,
|
|
7217
|
+
var DEEPSEEK_SEARCH_URL, DEEPSEEK_FETCH_URL, CONFIG_PATH45, SEARCH_TIMEOUT_MS37, FETCH_TIMEOUT_MS2, MAX_QUERY_CHARS2, MAX_SNIPPET_CHARS6, RECENCY_DAYS2, cachedConfig41, ERROR_TITLE;
|
|
7204
7218
|
var init_deepseek = __esm({
|
|
7205
7219
|
"deepseek.ts"() {
|
|
7206
7220
|
init_activity();
|
|
@@ -7212,8 +7226,8 @@ var init_deepseek = __esm({
|
|
|
7212
7226
|
init_utils();
|
|
7213
7227
|
DEEPSEEK_SEARCH_URL = "https://api.deepseek.com/v1/tools/search";
|
|
7214
7228
|
DEEPSEEK_FETCH_URL = "https://api.deepseek.com/v1/tools/fetch";
|
|
7215
|
-
|
|
7216
|
-
|
|
7229
|
+
CONFIG_PATH45 = getWebSearchConfigPath();
|
|
7230
|
+
SEARCH_TIMEOUT_MS37 = 3e4;
|
|
7217
7231
|
FETCH_TIMEOUT_MS2 = 6e4;
|
|
7218
7232
|
MAX_QUERY_CHARS2 = 128;
|
|
7219
7233
|
MAX_SNIPPET_CHARS6 = 800;
|
|
@@ -7223,13 +7237,13 @@ var init_deepseek = __esm({
|
|
|
7223
7237
|
month: 30,
|
|
7224
7238
|
year: 365
|
|
7225
7239
|
};
|
|
7226
|
-
|
|
7240
|
+
cachedConfig41 = null;
|
|
7227
7241
|
ERROR_TITLE = /^(?:404\b|page not found\b|not found\b)/i;
|
|
7228
7242
|
}
|
|
7229
7243
|
});
|
|
7230
7244
|
|
|
7231
7245
|
// auth-fetch.ts
|
|
7232
|
-
import { existsSync as
|
|
7246
|
+
import { existsSync as existsSync52, readFileSync as readFileSync53 } from "node:fs";
|
|
7233
7247
|
function resolveAuthFetchProfile(request) {
|
|
7234
7248
|
const profiles = loadAuthFetchProfiles();
|
|
7235
7249
|
if (profiles.length === 0) {
|
|
@@ -7267,8 +7281,8 @@ function authFetchRedirectGuard(profile, from, to) {
|
|
|
7267
7281
|
}
|
|
7268
7282
|
}
|
|
7269
7283
|
function loadAuthFetchProfiles() {
|
|
7270
|
-
if (!
|
|
7271
|
-
const raw =
|
|
7284
|
+
if (!existsSync52(WEB_SEARCH_CONFIG_PATH2)) return [];
|
|
7285
|
+
const raw = readFileSync53(WEB_SEARCH_CONFIG_PATH2, "utf-8");
|
|
7272
7286
|
let parsed;
|
|
7273
7287
|
try {
|
|
7274
7288
|
const value = JSON.parse(raw);
|
|
@@ -7668,20 +7682,20 @@ var init_rsc_extract = __esm({
|
|
|
7668
7682
|
});
|
|
7669
7683
|
|
|
7670
7684
|
// datalab-pdf-extract.ts
|
|
7671
|
-
import { existsSync as
|
|
7672
|
-
function
|
|
7673
|
-
if (
|
|
7674
|
-
if (!
|
|
7675
|
-
|
|
7676
|
-
return
|
|
7685
|
+
import { existsSync as existsSync53, readFileSync as readFileSync54 } from "node:fs";
|
|
7686
|
+
function loadConfig44() {
|
|
7687
|
+
if (cachedConfig43) return cachedConfig43;
|
|
7688
|
+
if (!existsSync53(CONFIG_PATH48)) {
|
|
7689
|
+
cachedConfig43 = {};
|
|
7690
|
+
return cachedConfig43;
|
|
7677
7691
|
}
|
|
7678
|
-
const rawText =
|
|
7692
|
+
const rawText = readFileSync54(CONFIG_PATH48, "utf-8");
|
|
7679
7693
|
try {
|
|
7680
|
-
|
|
7681
|
-
return
|
|
7694
|
+
cachedConfig43 = JSON.parse(rawText);
|
|
7695
|
+
return cachedConfig43;
|
|
7682
7696
|
} catch (err) {
|
|
7683
7697
|
const message = err instanceof Error ? err.message : String(err);
|
|
7684
|
-
throw new Error(`Failed to parse ${
|
|
7698
|
+
throw new Error(`Failed to parse ${CONFIG_PATH48}: ${message}`);
|
|
7685
7699
|
}
|
|
7686
7700
|
}
|
|
7687
7701
|
function normalizeString(value) {
|
|
@@ -7696,14 +7710,14 @@ function normalizeFileId(value) {
|
|
|
7696
7710
|
function isDatalabApiAvailable() {
|
|
7697
7711
|
return hasCredentialSource({
|
|
7698
7712
|
provider: "Datalab",
|
|
7699
|
-
configuredValue:
|
|
7713
|
+
configuredValue: loadConfig44().datalabApiKey,
|
|
7700
7714
|
environmentValue: process.env.DATALAB_API_KEY
|
|
7701
7715
|
});
|
|
7702
7716
|
}
|
|
7703
7717
|
async function getDatalabApiKey(signal) {
|
|
7704
7718
|
return resolveCredential({
|
|
7705
7719
|
provider: "Datalab",
|
|
7706
|
-
configuredValue:
|
|
7720
|
+
configuredValue: loadConfig44().datalabApiKey,
|
|
7707
7721
|
environmentValue: process.env.DATALAB_API_KEY,
|
|
7708
7722
|
signal
|
|
7709
7723
|
});
|
|
@@ -8028,7 +8042,7 @@ async function readResponseText(response) {
|
|
|
8028
8042
|
function datalabFilename(title) {
|
|
8029
8043
|
return title.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "document";
|
|
8030
8044
|
}
|
|
8031
|
-
var DEFAULT_API_HOST2, API_PREFIX, DEFAULT_TIMEOUT_MS2, DEFAULT_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES, MAX_ERROR_BODY_BYTES, CLEANUP_TIMEOUT_MS,
|
|
8045
|
+
var DEFAULT_API_HOST2, API_PREFIX, DEFAULT_TIMEOUT_MS2, DEFAULT_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES, MAX_ERROR_BODY_BYTES, CLEANUP_TIMEOUT_MS, CONFIG_PATH48, DATALAB_MODE_VALUES, DATALAB_LOCATION_VALUES, DEFAULT_DATALAB_MODE, DEFAULT_PROCESSING_LOCATION, DEFAULT_DATALAB_TIMEOUT_MS, cachedConfig43;
|
|
8032
8046
|
var init_datalab_pdf_extract = __esm({
|
|
8033
8047
|
"datalab-pdf-extract.ts"() {
|
|
8034
8048
|
init_credential_source();
|
|
@@ -8040,7 +8054,7 @@ var init_datalab_pdf_extract = __esm({
|
|
|
8040
8054
|
MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
8041
8055
|
MAX_ERROR_BODY_BYTES = 300;
|
|
8042
8056
|
CLEANUP_TIMEOUT_MS = 5e3;
|
|
8043
|
-
|
|
8057
|
+
CONFIG_PATH48 = getWebSearchConfigPath();
|
|
8044
8058
|
DATALAB_MODE_VALUES = /* @__PURE__ */ new Set([
|
|
8045
8059
|
"fast",
|
|
8046
8060
|
"balanced",
|
|
@@ -8053,21 +8067,21 @@ var init_datalab_pdf_extract = __esm({
|
|
|
8053
8067
|
DEFAULT_DATALAB_MODE = "balanced";
|
|
8054
8068
|
DEFAULT_PROCESSING_LOCATION = "us";
|
|
8055
8069
|
DEFAULT_DATALAB_TIMEOUT_MS = DEFAULT_TIMEOUT_MS2;
|
|
8056
|
-
|
|
8070
|
+
cachedConfig43 = null;
|
|
8057
8071
|
}
|
|
8058
8072
|
});
|
|
8059
8073
|
|
|
8060
8074
|
// endpoint-pdf-extract.ts
|
|
8061
|
-
import { existsSync as
|
|
8075
|
+
import { existsSync as existsSync54, readFileSync as readFileSync55 } from "node:fs";
|
|
8062
8076
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
8063
8077
|
function pdfSection() {
|
|
8064
|
-
if (!
|
|
8078
|
+
if (!existsSync54(CONFIG_PATH49)) return {};
|
|
8065
8079
|
let parsed;
|
|
8066
8080
|
try {
|
|
8067
|
-
parsed = JSON.parse(
|
|
8081
|
+
parsed = JSON.parse(readFileSync55(CONFIG_PATH49, "utf-8"));
|
|
8068
8082
|
} catch (err) {
|
|
8069
8083
|
const message = err instanceof Error ? err.message : String(err);
|
|
8070
|
-
throw new Error(`Failed to parse ${
|
|
8084
|
+
throw new Error(`Failed to parse ${CONFIG_PATH49}: ${message}`);
|
|
8071
8085
|
}
|
|
8072
8086
|
const pdf = parsed?.pdf;
|
|
8073
8087
|
return pdf && typeof pdf === "object" ? pdf : {};
|
|
@@ -8219,7 +8233,7 @@ async function extractPDFViaEndpoint(buffer, options) {
|
|
|
8219
8233
|
}
|
|
8220
8234
|
throw new Error("PDF parser endpoint job timed out");
|
|
8221
8235
|
}
|
|
8222
|
-
var DEFAULT_TIMEOUT_MS3, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2,
|
|
8236
|
+
var DEFAULT_TIMEOUT_MS3, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2, CONFIG_PATH49;
|
|
8223
8237
|
var init_endpoint_pdf_extract = __esm({
|
|
8224
8238
|
"endpoint-pdf-extract.ts"() {
|
|
8225
8239
|
init_ssrf_protection();
|
|
@@ -8228,7 +8242,7 @@ var init_endpoint_pdf_extract = __esm({
|
|
|
8228
8242
|
MAX_POLL_INTERVAL_MS = 3e3;
|
|
8229
8243
|
MAX_RESPONSE_BYTES2 = 4 * 1024 * 1024;
|
|
8230
8244
|
MAX_ERROR_BODY_BYTES2 = 300;
|
|
8231
|
-
|
|
8245
|
+
CONFIG_PATH49 = getWebSearchConfigPath();
|
|
8232
8246
|
}
|
|
8233
8247
|
});
|
|
8234
8248
|
|
|
@@ -8318,12 +8332,12 @@ var init_gemini_pdf_extract = __esm({
|
|
|
8318
8332
|
});
|
|
8319
8333
|
|
|
8320
8334
|
// pdf-extract.ts
|
|
8321
|
-
import { existsSync as
|
|
8335
|
+
import { existsSync as existsSync55, readFileSync as readFileSync56 } from "node:fs";
|
|
8322
8336
|
import { writeFile as writeFile2, mkdir } from "node:fs/promises";
|
|
8323
8337
|
import { join as join7, basename as basename3 } from "node:path";
|
|
8324
|
-
import { tmpdir as
|
|
8338
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
8325
8339
|
function loadPDFConfig() {
|
|
8326
|
-
if (!
|
|
8340
|
+
if (!existsSync55(CONFIG_PATH50)) {
|
|
8327
8341
|
return {
|
|
8328
8342
|
enabled: true,
|
|
8329
8343
|
maxSizeMB: DEFAULT_PDF_MAX_SIZE_MB,
|
|
@@ -8333,13 +8347,13 @@ function loadPDFConfig() {
|
|
|
8333
8347
|
datalabTimeoutMs: DEFAULT_DATALAB_TIMEOUT_MS
|
|
8334
8348
|
};
|
|
8335
8349
|
}
|
|
8336
|
-
const rawText =
|
|
8350
|
+
const rawText = readFileSync56(CONFIG_PATH50, "utf-8");
|
|
8337
8351
|
let raw;
|
|
8338
8352
|
try {
|
|
8339
8353
|
raw = JSON.parse(rawText);
|
|
8340
8354
|
} catch (err) {
|
|
8341
8355
|
const message = err instanceof Error ? err.message : String(err);
|
|
8342
|
-
throw new Error(`Failed to parse ${
|
|
8356
|
+
throw new Error(`Failed to parse ${CONFIG_PATH50}: ${message}`);
|
|
8343
8357
|
}
|
|
8344
8358
|
const root = raw && typeof raw === "object" ? raw : {};
|
|
8345
8359
|
const pdf = root.pdf && typeof root.pdf === "object" ? root.pdf : {};
|
|
@@ -8573,7 +8587,7 @@ function isPDF(url, contentType) {
|
|
|
8573
8587
|
return false;
|
|
8574
8588
|
}
|
|
8575
8589
|
}
|
|
8576
|
-
var PDF_PROVIDER_VALUES, DEFAULT_PDF_MAX_SIZE_MB, MAX_PDF_MAX_SIZE_MB, MAX_DATALAB_TIMEOUT_MS, DEFAULT_MAX_PAGES, DEFAULT_OUTPUT_DIR,
|
|
8590
|
+
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_PATH50, PAGE_MARKER_PATTERN2;
|
|
8577
8591
|
var init_pdf_extract = __esm({
|
|
8578
8592
|
"pdf-extract.ts"() {
|
|
8579
8593
|
init_credential_source();
|
|
@@ -8593,37 +8607,37 @@ var init_pdf_extract = __esm({
|
|
|
8593
8607
|
MAX_PDF_MAX_SIZE_MB = 50;
|
|
8594
8608
|
MAX_DATALAB_TIMEOUT_MS = 3e5;
|
|
8595
8609
|
DEFAULT_MAX_PAGES = 100;
|
|
8596
|
-
DEFAULT_OUTPUT_DIR = join7(
|
|
8597
|
-
|
|
8610
|
+
DEFAULT_OUTPUT_DIR = join7(tmpdir4(), "pi-web-pdf");
|
|
8611
|
+
CONFIG_PATH50 = getWebSearchConfigPath();
|
|
8598
8612
|
PAGE_MARKER_PATTERN2 = /^<!-- Page (\d+) -->$/gm;
|
|
8599
8613
|
}
|
|
8600
8614
|
});
|
|
8601
8615
|
|
|
8602
8616
|
// github-issue-pr.ts
|
|
8603
8617
|
import { execFile as execFile5 } from "node:child_process";
|
|
8604
|
-
import { existsSync as
|
|
8605
|
-
function
|
|
8606
|
-
if (
|
|
8618
|
+
import { existsSync as existsSync56, readFileSync as readFileSync57 } from "node:fs";
|
|
8619
|
+
function loadConfig45() {
|
|
8620
|
+
if (cachedConfig44) return cachedConfig44;
|
|
8607
8621
|
const defaults2 = { enabled: true };
|
|
8608
|
-
if (!
|
|
8609
|
-
|
|
8610
|
-
return
|
|
8622
|
+
if (!existsSync56(CONFIG_PATH51)) {
|
|
8623
|
+
cachedConfig44 = defaults2;
|
|
8624
|
+
return cachedConfig44;
|
|
8611
8625
|
}
|
|
8612
8626
|
let parsed;
|
|
8613
8627
|
try {
|
|
8614
|
-
parsed = JSON.parse(
|
|
8628
|
+
parsed = JSON.parse(readFileSync57(CONFIG_PATH51, "utf-8"));
|
|
8615
8629
|
} catch (err) {
|
|
8616
8630
|
const message = err instanceof Error ? err.message : String(err);
|
|
8617
|
-
throw new Error(`Failed to parse ${
|
|
8631
|
+
throw new Error(`Failed to parse ${CONFIG_PATH51}: ${message}`);
|
|
8618
8632
|
}
|
|
8619
8633
|
const root = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
8620
8634
|
const value = root.githubPrIssue;
|
|
8621
8635
|
if (value !== void 0 && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
8622
|
-
throw new Error(`githubPrIssue in ${
|
|
8636
|
+
throw new Error(`githubPrIssue in ${CONFIG_PATH51} must be an object`);
|
|
8623
8637
|
}
|
|
8624
8638
|
const enabled = typeof value?.enabled === "boolean" ? value.enabled : true;
|
|
8625
|
-
|
|
8626
|
-
return
|
|
8639
|
+
cachedConfig44 = { enabled };
|
|
8640
|
+
return cachedConfig44;
|
|
8627
8641
|
}
|
|
8628
8642
|
function validOwner(owner) {
|
|
8629
8643
|
return /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/.test(owner) && !owner.includes("--");
|
|
@@ -8631,11 +8645,11 @@ function validOwner(owner) {
|
|
|
8631
8645
|
function validRepo(repo) {
|
|
8632
8646
|
return /^[A-Za-z0-9._-]{1,100}$/.test(repo) && repo !== "." && repo !== "..";
|
|
8633
8647
|
}
|
|
8634
|
-
function
|
|
8648
|
+
function errorMessage33(err) {
|
|
8635
8649
|
return err instanceof Error ? err.message : String(err);
|
|
8636
8650
|
}
|
|
8637
8651
|
function isAbortError4(err) {
|
|
8638
|
-
return
|
|
8652
|
+
return errorMessage33(err).toLowerCase().includes("abort");
|
|
8639
8653
|
}
|
|
8640
8654
|
function parseGitHubIssuePrUrl(url) {
|
|
8641
8655
|
let parsed;
|
|
@@ -8871,7 +8885,7 @@ async function restFallback(url, info, options, signal) {
|
|
|
8871
8885
|
return { data: { url, owner: info.owner, repo: info.repo, kind: info.kind, number: info.number, anchor: info.anchor, view, reviewThreads, fallbackNotes: notes } };
|
|
8872
8886
|
} catch (err) {
|
|
8873
8887
|
if (signal?.aborted || isAbortError4(err)) return { url, title: "", content: "", error: "Aborted" };
|
|
8874
|
-
const message =
|
|
8888
|
+
const message = errorMessage33(err);
|
|
8875
8889
|
return { url, title: `${info.owner}/${info.repo}#${info.number}`, content: message, error: `GitHub REST fallback failed: ${message}` };
|
|
8876
8890
|
}
|
|
8877
8891
|
}
|
|
@@ -9169,7 +9183,7 @@ function renderGitHubPrIssue(data) {
|
|
|
9169
9183
|
async function extractGitHubIssuePr(url, signal, options) {
|
|
9170
9184
|
const info = parseGitHubIssuePrUrl(url);
|
|
9171
9185
|
if (!info) return null;
|
|
9172
|
-
if (!
|
|
9186
|
+
if (!loadConfig45().enabled) return null;
|
|
9173
9187
|
if (signal?.aborted) return { url, title: "", content: "", error: "Aborted" };
|
|
9174
9188
|
const retrievalTool = options?.toolNames ? options.toolNames.getSearchContent ?? null : void 0;
|
|
9175
9189
|
const ghAvailable2 = await checkGhAvailable(signal);
|
|
@@ -9193,13 +9207,13 @@ async function extractGitHubIssuePr(url, signal, options) {
|
|
|
9193
9207
|
if ("data" in fallback) return renderGitHubPrIssue({ ...fallback.data, retrievalTool });
|
|
9194
9208
|
return fallback;
|
|
9195
9209
|
}
|
|
9196
|
-
var
|
|
9210
|
+
var CONFIG_PATH51, 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, cachedConfig44;
|
|
9197
9211
|
var init_github_issue_pr = __esm({
|
|
9198
9212
|
"github-issue-pr.ts"() {
|
|
9199
9213
|
init_github_api();
|
|
9200
9214
|
init_ssrf_protection();
|
|
9201
9215
|
init_utils();
|
|
9202
|
-
|
|
9216
|
+
CONFIG_PATH51 = getWebSearchConfigPath();
|
|
9203
9217
|
GH_TIMEOUT_MS = 1e4;
|
|
9204
9218
|
GH_TOTAL_TIMEOUT_MS = 2e4;
|
|
9205
9219
|
MAX_DOC_CHARS = 15e4;
|
|
@@ -9280,20 +9294,20 @@ var init_github_issue_pr = __esm({
|
|
|
9280
9294
|
"url"
|
|
9281
9295
|
];
|
|
9282
9296
|
ISSUE_CORE_FIELDS = ["title", "number", "state", "author", "createdAt", "closedAt", "labels", "assignees", "milestone", "comments", "body", "url"];
|
|
9283
|
-
|
|
9297
|
+
cachedConfig44 = null;
|
|
9284
9298
|
}
|
|
9285
9299
|
});
|
|
9286
9300
|
|
|
9287
9301
|
// feature-config.ts
|
|
9288
|
-
import { existsSync as
|
|
9302
|
+
import { existsSync as existsSync57, readFileSync as readFileSync58 } from "node:fs";
|
|
9289
9303
|
function loadFeatureConfig() {
|
|
9290
|
-
if (!
|
|
9304
|
+
if (!existsSync57(CONFIG_PATH52)) return {};
|
|
9291
9305
|
try {
|
|
9292
|
-
const raw = JSON.parse(
|
|
9306
|
+
const raw = JSON.parse(readFileSync58(CONFIG_PATH52, "utf-8"));
|
|
9293
9307
|
return raw && typeof raw === "object" ? raw : {};
|
|
9294
9308
|
} catch (err) {
|
|
9295
9309
|
const message = err instanceof Error ? err.message : String(err);
|
|
9296
|
-
throw new Error(`Failed to parse ${
|
|
9310
|
+
throw new Error(`Failed to parse ${CONFIG_PATH52}: ${message}`);
|
|
9297
9311
|
}
|
|
9298
9312
|
}
|
|
9299
9313
|
function isImageEnabled() {
|
|
@@ -9306,25 +9320,25 @@ function canAttachImages() {
|
|
|
9306
9320
|
return false;
|
|
9307
9321
|
}
|
|
9308
9322
|
}
|
|
9309
|
-
var
|
|
9323
|
+
var CONFIG_PATH52;
|
|
9310
9324
|
var init_feature_config = __esm({
|
|
9311
9325
|
"feature-config.ts"() {
|
|
9312
9326
|
init_utils();
|
|
9313
|
-
|
|
9327
|
+
CONFIG_PATH52 = getWebSearchConfigPath();
|
|
9314
9328
|
}
|
|
9315
9329
|
});
|
|
9316
9330
|
|
|
9317
9331
|
// youtube-extract.ts
|
|
9318
9332
|
import { execFileSync } from "node:child_process";
|
|
9319
|
-
import { existsSync as
|
|
9320
|
-
function
|
|
9333
|
+
import { existsSync as existsSync58, readFileSync as readFileSync59 } from "node:fs";
|
|
9334
|
+
function errorMessage34(err) {
|
|
9321
9335
|
return err instanceof Error ? err.message : String(err);
|
|
9322
9336
|
}
|
|
9323
9337
|
function shouldRethrow(err) {
|
|
9324
|
-
return
|
|
9338
|
+
return errorMessage34(err).startsWith("Failed to parse ");
|
|
9325
9339
|
}
|
|
9326
9340
|
function addAttemptError(errors, label, err) {
|
|
9327
|
-
const message =
|
|
9341
|
+
const message = errorMessage34(err).replace(/\s+/g, " ").trim();
|
|
9328
9342
|
if (message) errors.push(`${label}: ${message}`);
|
|
9329
9343
|
}
|
|
9330
9344
|
function normalizePreferredModel(value, fallback) {
|
|
@@ -9336,25 +9350,25 @@ function normalizeEnabled2(value, fallback) {
|
|
|
9336
9350
|
return typeof value === "boolean" ? value : fallback;
|
|
9337
9351
|
}
|
|
9338
9352
|
function loadYouTubeConfig() {
|
|
9339
|
-
if (
|
|
9340
|
-
if (!
|
|
9341
|
-
|
|
9342
|
-
return
|
|
9353
|
+
if (cachedConfig45) return cachedConfig45;
|
|
9354
|
+
if (!existsSync58(CONFIG_PATH53)) {
|
|
9355
|
+
cachedConfig45 = { ...defaults };
|
|
9356
|
+
return cachedConfig45;
|
|
9343
9357
|
}
|
|
9344
|
-
const rawText =
|
|
9358
|
+
const rawText = readFileSync59(CONFIG_PATH53, "utf-8");
|
|
9345
9359
|
let raw;
|
|
9346
9360
|
try {
|
|
9347
9361
|
raw = JSON.parse(rawText);
|
|
9348
9362
|
} catch (err) {
|
|
9349
9363
|
const message = err instanceof Error ? err.message : String(err);
|
|
9350
|
-
throw new Error(`Failed to parse ${
|
|
9364
|
+
throw new Error(`Failed to parse ${CONFIG_PATH53}: ${message}`);
|
|
9351
9365
|
}
|
|
9352
9366
|
const yt = raw.youtube ?? {};
|
|
9353
|
-
|
|
9367
|
+
cachedConfig45 = {
|
|
9354
9368
|
enabled: normalizeEnabled2(yt.enabled, defaults.enabled),
|
|
9355
9369
|
preferredModel: normalizePreferredModel(yt.preferredModel, defaults.preferredModel)
|
|
9356
9370
|
};
|
|
9357
|
-
return
|
|
9371
|
+
return cachedConfig45;
|
|
9358
9372
|
}
|
|
9359
9373
|
function isYouTubeURL(url) {
|
|
9360
9374
|
try {
|
|
@@ -9546,7 +9560,7 @@ ${answer}
|
|
|
9546
9560
|
return null;
|
|
9547
9561
|
}
|
|
9548
9562
|
}
|
|
9549
|
-
var
|
|
9563
|
+
var CONFIG_PATH53, YOUTUBE_PROMPT, YOUTUBE_REGEX, defaults, cachedConfig45;
|
|
9550
9564
|
var init_youtube_extract = __esm({
|
|
9551
9565
|
"youtube-extract.ts"() {
|
|
9552
9566
|
init_activity();
|
|
@@ -9556,7 +9570,7 @@ var init_youtube_extract = __esm({
|
|
|
9556
9570
|
init_perplexity();
|
|
9557
9571
|
init_extract();
|
|
9558
9572
|
init_utils();
|
|
9559
|
-
|
|
9573
|
+
CONFIG_PATH53 = getWebSearchConfigPath();
|
|
9560
9574
|
YOUTUBE_PROMPT = `Extract the complete content of this YouTube video. Include:
|
|
9561
9575
|
1. Video title, channel name, and duration
|
|
9562
9576
|
2. A brief summary (2-3 sentences)
|
|
@@ -9566,7 +9580,7 @@ var init_youtube_extract = __esm({
|
|
|
9566
9580
|
Format as markdown.`;
|
|
9567
9581
|
YOUTUBE_REGEX = /(?:(?:www\.|m\.)?youtube\.com\/(?:watch\?.*v=|shorts\/|live\/|embed\/|v\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
|
|
9568
9582
|
defaults = { enabled: true, preferredModel: "gemini-3.6-flash" };
|
|
9569
|
-
|
|
9583
|
+
cachedConfig45 = null;
|
|
9570
9584
|
}
|
|
9571
9585
|
});
|
|
9572
9586
|
|
|
@@ -9668,26 +9682,26 @@ URL: `;
|
|
|
9668
9682
|
});
|
|
9669
9683
|
|
|
9670
9684
|
// crawl4ai.ts
|
|
9671
|
-
import { existsSync as
|
|
9672
|
-
function
|
|
9673
|
-
if (
|
|
9674
|
-
if (!
|
|
9675
|
-
|
|
9676
|
-
return
|
|
9685
|
+
import { existsSync as existsSync59, readFileSync as readFileSync60 } from "node:fs";
|
|
9686
|
+
function loadConfig46() {
|
|
9687
|
+
if (cachedConfig46) return cachedConfig46;
|
|
9688
|
+
if (!existsSync59(CONFIG_PATH54)) {
|
|
9689
|
+
cachedConfig46 = {};
|
|
9690
|
+
return cachedConfig46;
|
|
9677
9691
|
}
|
|
9678
|
-
const raw =
|
|
9692
|
+
const raw = readFileSync60(CONFIG_PATH54, "utf8");
|
|
9679
9693
|
let parsed;
|
|
9680
9694
|
try {
|
|
9681
9695
|
parsed = JSON.parse(raw);
|
|
9682
9696
|
} catch (err) {
|
|
9683
9697
|
const message = err instanceof Error ? err.message : String(err);
|
|
9684
|
-
throw new Error(`Failed to parse ${
|
|
9698
|
+
throw new Error(`Failed to parse ${CONFIG_PATH54}: ${message}`);
|
|
9685
9699
|
}
|
|
9686
9700
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9687
|
-
throw new Error(`Invalid config in ${
|
|
9701
|
+
throw new Error(`Invalid config in ${CONFIG_PATH54}: expected a JSON object`);
|
|
9688
9702
|
}
|
|
9689
|
-
|
|
9690
|
-
return
|
|
9703
|
+
cachedConfig46 = parsed;
|
|
9704
|
+
return cachedConfig46;
|
|
9691
9705
|
}
|
|
9692
9706
|
function normalizeBaseUrl5(value) {
|
|
9693
9707
|
if (typeof value !== "string") return null;
|
|
@@ -9697,13 +9711,13 @@ function normalizeBaseUrl5(value) {
|
|
|
9697
9711
|
try {
|
|
9698
9712
|
parsed = new URL(trimmed);
|
|
9699
9713
|
} catch {
|
|
9700
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
9714
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH54}: expected an HTTP or HTTPS URL`);
|
|
9701
9715
|
}
|
|
9702
9716
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
9703
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
9717
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH54}: expected an HTTP or HTTPS URL`);
|
|
9704
9718
|
}
|
|
9705
9719
|
if (parsed.username || parsed.password) {
|
|
9706
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
9720
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH54}: URL credentials are not allowed`);
|
|
9707
9721
|
}
|
|
9708
9722
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
9709
9723
|
parsed.search = "";
|
|
@@ -9711,14 +9725,14 @@ function normalizeBaseUrl5(value) {
|
|
|
9711
9725
|
return parsed.toString().replace(/\/+$/, "");
|
|
9712
9726
|
}
|
|
9713
9727
|
function getBaseUrl4() {
|
|
9714
|
-
return normalizeBaseUrl5(process.env.CRAWL4AI_BASE_URL) ?? normalizeBaseUrl5(
|
|
9728
|
+
return normalizeBaseUrl5(process.env.CRAWL4AI_BASE_URL) ?? normalizeBaseUrl5(loadConfig46().crawl4aiBaseUrl);
|
|
9715
9729
|
}
|
|
9716
9730
|
function requireBaseUrl4() {
|
|
9717
9731
|
const baseUrl = getBaseUrl4();
|
|
9718
9732
|
if (!baseUrl) {
|
|
9719
9733
|
throw new Error(
|
|
9720
9734
|
`Crawl4AI base URL not configured. Either:
|
|
9721
|
-
1. Set crawl4aiBaseUrl in ${
|
|
9735
|
+
1. Set crawl4aiBaseUrl in ${CONFIG_PATH54}
|
|
9722
9736
|
2. Set CRAWL4AI_BASE_URL environment variable`
|
|
9723
9737
|
);
|
|
9724
9738
|
}
|
|
@@ -9727,7 +9741,7 @@ function requireBaseUrl4() {
|
|
|
9727
9741
|
async function getApiToken(signal) {
|
|
9728
9742
|
return resolveCredential({
|
|
9729
9743
|
provider: "Crawl4AI",
|
|
9730
|
-
configuredValue:
|
|
9744
|
+
configuredValue: loadConfig46().crawl4aiApiToken,
|
|
9731
9745
|
environmentValue: process.env.CRAWL4AI_API_TOKEN,
|
|
9732
9746
|
signal
|
|
9733
9747
|
});
|
|
@@ -9736,7 +9750,7 @@ function requestSignal14(timeoutMs, signal) {
|
|
|
9736
9750
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
9737
9751
|
return signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
9738
9752
|
}
|
|
9739
|
-
function
|
|
9753
|
+
function errorMessage35(err) {
|
|
9740
9754
|
return err instanceof Error ? err.message : String(err);
|
|
9741
9755
|
}
|
|
9742
9756
|
function isAbortException(err) {
|
|
@@ -9813,49 +9827,49 @@ async function extractWithCrawl4ai(url, signal, options) {
|
|
|
9813
9827
|
return { url, title: firstHeadingTitle(content), content, error: null };
|
|
9814
9828
|
} catch (err) {
|
|
9815
9829
|
if (signal?.aborted || isAbortException(err)) activityMonitor.logComplete(activityId, 0);
|
|
9816
|
-
else activityMonitor.logError(activityId,
|
|
9830
|
+
else activityMonitor.logError(activityId, errorMessage35(err));
|
|
9817
9831
|
throw err;
|
|
9818
9832
|
}
|
|
9819
9833
|
}
|
|
9820
|
-
var
|
|
9834
|
+
var CONFIG_PATH54, EXTRACT_TIMEOUT_MS3, MARKDOWN_FILTER, cachedConfig46;
|
|
9821
9835
|
var init_crawl4ai = __esm({
|
|
9822
9836
|
"crawl4ai.ts"() {
|
|
9823
9837
|
init_activity();
|
|
9824
9838
|
init_credential_source();
|
|
9825
9839
|
init_ssrf_protection();
|
|
9826
9840
|
init_utils();
|
|
9827
|
-
|
|
9841
|
+
CONFIG_PATH54 = getWebSearchConfigPath();
|
|
9828
9842
|
EXTRACT_TIMEOUT_MS3 = 6e4;
|
|
9829
9843
|
MARKDOWN_FILTER = "fit";
|
|
9830
|
-
|
|
9844
|
+
cachedConfig46 = null;
|
|
9831
9845
|
}
|
|
9832
9846
|
});
|
|
9833
9847
|
|
|
9834
9848
|
// brightdata-unlocker.ts
|
|
9835
|
-
import { existsSync as
|
|
9849
|
+
import { existsSync as existsSync60, readFileSync as readFileSync61 } from "node:fs";
|
|
9836
9850
|
function parseFailureDetail(err) {
|
|
9837
9851
|
const message = err instanceof Error ? err.message : String(err);
|
|
9838
9852
|
const position = message.match(/at position \d+(?: \(line \d+ column \d+\))?/);
|
|
9839
9853
|
return position ? `invalid JSON ${position[0]}` : "invalid JSON";
|
|
9840
9854
|
}
|
|
9841
|
-
function
|
|
9842
|
-
if (
|
|
9843
|
-
if (!
|
|
9844
|
-
|
|
9845
|
-
return
|
|
9855
|
+
function loadConfig47() {
|
|
9856
|
+
if (cachedConfig47) return cachedConfig47;
|
|
9857
|
+
if (!existsSync60(CONFIG_PATH55)) {
|
|
9858
|
+
cachedConfig47 = {};
|
|
9859
|
+
return cachedConfig47;
|
|
9846
9860
|
}
|
|
9847
|
-
const raw =
|
|
9861
|
+
const raw = readFileSync61(CONFIG_PATH55, "utf8");
|
|
9848
9862
|
let parsed;
|
|
9849
9863
|
try {
|
|
9850
9864
|
parsed = JSON.parse(raw);
|
|
9851
9865
|
} catch (err) {
|
|
9852
|
-
throw new Error(`Failed to parse ${
|
|
9866
|
+
throw new Error(`Failed to parse ${CONFIG_PATH55}: ${parseFailureDetail(err)}`);
|
|
9853
9867
|
}
|
|
9854
9868
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9855
|
-
throw new Error(`Invalid config in ${
|
|
9869
|
+
throw new Error(`Invalid config in ${CONFIG_PATH55}: expected a JSON object`);
|
|
9856
9870
|
}
|
|
9857
|
-
|
|
9858
|
-
return
|
|
9871
|
+
cachedConfig47 = parsed;
|
|
9872
|
+
return cachedConfig47;
|
|
9859
9873
|
}
|
|
9860
9874
|
function normalizeZone2(value) {
|
|
9861
9875
|
if (typeof value !== "string") return null;
|
|
@@ -9866,8 +9880,8 @@ function normalizeZone2(value) {
|
|
|
9866
9880
|
function zoneSetting() {
|
|
9867
9881
|
const fromEnv = process.env.BRIGHTDATA_UNLOCKER_ZONE;
|
|
9868
9882
|
if (typeof fromEnv === "string" && fromEnv.trim()) return { raw: fromEnv.trim(), label: "BRIGHTDATA_UNLOCKER_ZONE" };
|
|
9869
|
-
const configured =
|
|
9870
|
-
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${
|
|
9883
|
+
const configured = loadConfig47().brightdataUnlockerZone;
|
|
9884
|
+
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${CONFIG_PATH55}` };
|
|
9871
9885
|
return null;
|
|
9872
9886
|
}
|
|
9873
9887
|
function getZone() {
|
|
@@ -9885,22 +9899,22 @@ function requireZone() {
|
|
|
9885
9899
|
}
|
|
9886
9900
|
throw new Error(
|
|
9887
9901
|
`Bright Data Web Unlocker zone not configured. Either:
|
|
9888
|
-
1. Set brightdataUnlockerZone in ${
|
|
9902
|
+
1. Set brightdataUnlockerZone in ${CONFIG_PATH55}
|
|
9889
9903
|
2. Set BRIGHTDATA_UNLOCKER_ZONE environment variable
|
|
9890
9904
|
The zone must be of type "unblocker"; a SERP zone will not serve Web Unlocker requests.`
|
|
9891
9905
|
);
|
|
9892
9906
|
}
|
|
9893
|
-
async function
|
|
9907
|
+
async function getApiKey31(signal) {
|
|
9894
9908
|
const apiKey = await resolveCredential({
|
|
9895
9909
|
provider: "Bright Data",
|
|
9896
|
-
configuredValue:
|
|
9910
|
+
configuredValue: loadConfig47().brightdataApiKey,
|
|
9897
9911
|
environmentValue: process.env.BRIGHTDATA_API_KEY,
|
|
9898
9912
|
signal
|
|
9899
9913
|
});
|
|
9900
9914
|
if (!apiKey) {
|
|
9901
9915
|
throw new Error(
|
|
9902
9916
|
`Bright Data API key not found. Either:
|
|
9903
|
-
1. Create ${
|
|
9917
|
+
1. Create ${CONFIG_PATH55} with { "brightdataApiKey": "your-key" }
|
|
9904
9918
|
2. Set BRIGHTDATA_API_KEY environment variable
|
|
9905
9919
|
Get a key at https://brightdata.com/cp/setting/users`
|
|
9906
9920
|
);
|
|
@@ -9911,11 +9925,11 @@ function requestSignal15(timeoutMs, signal) {
|
|
|
9911
9925
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
9912
9926
|
return signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
9913
9927
|
}
|
|
9914
|
-
function
|
|
9928
|
+
function errorMessage36(err) {
|
|
9915
9929
|
return err instanceof Error ? err.message : String(err);
|
|
9916
9930
|
}
|
|
9917
9931
|
function isAbortError5(err) {
|
|
9918
|
-
return
|
|
9932
|
+
return errorMessage36(err).toLowerCase().includes("abort");
|
|
9919
9933
|
}
|
|
9920
9934
|
function ssrfOptions3(options) {
|
|
9921
9935
|
return {
|
|
@@ -9957,14 +9971,14 @@ function unlockerBody(url, zone) {
|
|
|
9957
9971
|
};
|
|
9958
9972
|
}
|
|
9959
9973
|
async function brightDataRequest(url, zone, signal, options) {
|
|
9960
|
-
const apiKey = await
|
|
9974
|
+
const apiKey = await getApiKey31(signal);
|
|
9961
9975
|
const headers = {
|
|
9962
9976
|
"Content-Type": "application/json",
|
|
9963
9977
|
Authorization: `Bearer ${apiKey}`
|
|
9964
9978
|
};
|
|
9965
9979
|
const activityId = activityMonitor.logStart({ type: "fetch", url });
|
|
9966
9980
|
try {
|
|
9967
|
-
const response = await fetchBrightDataApi(resolveProviderApiUrl("brightdata", BRIGHTDATA_REQUEST_URL,
|
|
9981
|
+
const response = await fetchBrightDataApi(resolveProviderApiUrl("brightdata", BRIGHTDATA_REQUEST_URL, loadConfig47().brightdataBaseUrl), {
|
|
9968
9982
|
method: "POST",
|
|
9969
9983
|
headers,
|
|
9970
9984
|
body: JSON.stringify(unlockerBody(url, zone)),
|
|
@@ -9978,7 +9992,7 @@ async function brightDataRequest(url, zone, signal, options) {
|
|
|
9978
9992
|
activityMonitor.logComplete(activityId, response.status);
|
|
9979
9993
|
return text7;
|
|
9980
9994
|
} catch (err) {
|
|
9981
|
-
const message =
|
|
9995
|
+
const message = errorMessage36(err);
|
|
9982
9996
|
const redactedMessage = redactCredential(message, apiKey);
|
|
9983
9997
|
if (isAbortError5(err)) activityMonitor.logComplete(activityId, 0);
|
|
9984
9998
|
else activityMonitor.logError(activityId, redactedMessage);
|
|
@@ -9997,7 +10011,7 @@ function isBrightDataUnlockerAvailable() {
|
|
|
9997
10011
|
if (getZone() === null) return false;
|
|
9998
10012
|
return hasCredentialSource({
|
|
9999
10013
|
provider: "Bright Data",
|
|
10000
|
-
configuredValue:
|
|
10014
|
+
configuredValue: loadConfig47().brightdataApiKey,
|
|
10001
10015
|
environmentValue: process.env.BRIGHTDATA_API_KEY
|
|
10002
10016
|
});
|
|
10003
10017
|
}
|
|
@@ -10009,26 +10023,26 @@ async function extractWithBrightDataUnlocker(url, signal, options) {
|
|
|
10009
10023
|
if (!content) return null;
|
|
10010
10024
|
return { url, title: headingTitle(content), content, error: null };
|
|
10011
10025
|
}
|
|
10012
|
-
var
|
|
10026
|
+
var CONFIG_PATH55, BRIGHTDATA_REQUEST_URL, EXTRACT_TIMEOUT_MS4, DEFAULT_MAX_REDIRECTS3, REDIRECT_STATUSES3, ZONE_PATTERN2, cachedConfig47;
|
|
10013
10027
|
var init_brightdata_unlocker = __esm({
|
|
10014
10028
|
"brightdata-unlocker.ts"() {
|
|
10015
10029
|
init_activity();
|
|
10016
10030
|
init_credential_source();
|
|
10017
10031
|
init_ssrf_protection();
|
|
10018
10032
|
init_utils();
|
|
10019
|
-
|
|
10033
|
+
CONFIG_PATH55 = getWebSearchConfigPath();
|
|
10020
10034
|
BRIGHTDATA_REQUEST_URL = "https://api.brightdata.com/request";
|
|
10021
10035
|
EXTRACT_TIMEOUT_MS4 = 6e4;
|
|
10022
10036
|
DEFAULT_MAX_REDIRECTS3 = 5;
|
|
10023
10037
|
REDIRECT_STATUSES3 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
10024
10038
|
ZONE_PATTERN2 = /^[a-z0-9_-]+$/i;
|
|
10025
|
-
|
|
10039
|
+
cachedConfig47 = null;
|
|
10026
10040
|
}
|
|
10027
10041
|
});
|
|
10028
10042
|
|
|
10029
10043
|
// video-extract.ts
|
|
10030
10044
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
10031
|
-
import { existsSync as
|
|
10045
|
+
import { existsSync as existsSync61, readFileSync as readFileSync62, readdirSync as readdirSync4, statSync as statSync3 } from "node:fs";
|
|
10032
10046
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
10033
10047
|
import { resolve, extname as extname2, basename as basename4, join as join8, dirname as dirname2 } from "node:path";
|
|
10034
10048
|
function shouldRethrow3(err) {
|
|
@@ -10049,17 +10063,17 @@ function normalizeMaxSizeMB(value, fallback) {
|
|
|
10049
10063
|
}
|
|
10050
10064
|
function loadVideoConfig() {
|
|
10051
10065
|
if (cachedVideoConfig) return cachedVideoConfig;
|
|
10052
|
-
if (!
|
|
10066
|
+
if (!existsSync61(CONFIG_PATH56)) {
|
|
10053
10067
|
cachedVideoConfig = { ...VIDEO_CONFIG_DEFAULTS };
|
|
10054
10068
|
return cachedVideoConfig;
|
|
10055
10069
|
}
|
|
10056
|
-
const rawText =
|
|
10070
|
+
const rawText = readFileSync62(CONFIG_PATH56, "utf-8");
|
|
10057
10071
|
let raw;
|
|
10058
10072
|
try {
|
|
10059
10073
|
raw = JSON.parse(rawText);
|
|
10060
10074
|
} catch (err) {
|
|
10061
10075
|
const message = err instanceof Error ? err.message : String(err);
|
|
10062
|
-
throw new Error(`Failed to parse ${
|
|
10076
|
+
throw new Error(`Failed to parse ${CONFIG_PATH56}: ${message}`);
|
|
10063
10077
|
}
|
|
10064
10078
|
const v = raw.video ?? {};
|
|
10065
10079
|
cachedVideoConfig = {
|
|
@@ -10105,10 +10119,10 @@ function isVideoFile(input) {
|
|
|
10105
10119
|
}
|
|
10106
10120
|
function resolveFilePath(filePath) {
|
|
10107
10121
|
const absolutePath = resolve(filePath);
|
|
10108
|
-
if (
|
|
10122
|
+
if (existsSync61(absolutePath)) return absolutePath;
|
|
10109
10123
|
const dir = dirname2(absolutePath);
|
|
10110
10124
|
const base = basename4(absolutePath);
|
|
10111
|
-
if (!
|
|
10125
|
+
if (!existsSync61(dir)) return null;
|
|
10112
10126
|
try {
|
|
10113
10127
|
const normalizedBase = normalizeSpaces(base);
|
|
10114
10128
|
const match = readdirSync4(dir).find((f) => normalizeSpaces(f) === normalizedBase);
|
|
@@ -10307,7 +10321,7 @@ function deleteGeminiFile(fileName, apiKey) {
|
|
|
10307
10321
|
function extractVideoTitle(text7, filePath) {
|
|
10308
10322
|
return extractHeadingTitle(text7) ?? basename4(filePath, extname2(filePath));
|
|
10309
10323
|
}
|
|
10310
|
-
var
|
|
10324
|
+
var CONFIG_PATH56, DEFAULT_VIDEO_PROMPT, VIDEO_EXTENSIONS, VIDEO_CONFIG_DEFAULTS, cachedVideoConfig;
|
|
10311
10325
|
var init_video_extract = __esm({
|
|
10312
10326
|
"video-extract.ts"() {
|
|
10313
10327
|
init_activity();
|
|
@@ -10316,7 +10330,7 @@ var init_video_extract = __esm({
|
|
|
10316
10330
|
init_gemini_api();
|
|
10317
10331
|
init_extract();
|
|
10318
10332
|
init_utils();
|
|
10319
|
-
|
|
10333
|
+
CONFIG_PATH56 = getWebSearchConfigPath();
|
|
10320
10334
|
DEFAULT_VIDEO_PROMPT = `Extract the complete content of this video. Include:
|
|
10321
10335
|
1. Video title (infer from content if not explicit), duration
|
|
10322
10336
|
2. A brief summary (2-3 sentences)
|
|
@@ -10801,13 +10815,13 @@ __export(extract_exports, {
|
|
|
10801
10815
|
readPDFResponseBuffer: () => readPDFResponseBuffer,
|
|
10802
10816
|
resolveFetchTimeoutMs: () => resolveFetchTimeoutMs
|
|
10803
10817
|
});
|
|
10804
|
-
import { existsSync as
|
|
10818
|
+
import { existsSync as existsSync62, readFileSync as readFileSync63 } from "node:fs";
|
|
10805
10819
|
import pLimit from "p-limit";
|
|
10806
10820
|
function loadFetchTimeoutMs() {
|
|
10807
|
-
if (!
|
|
10821
|
+
if (!existsSync62(WEB_SEARCH_CONFIG_PATH3)) return DEFAULT_TIMEOUT_MS5;
|
|
10808
10822
|
let raw;
|
|
10809
10823
|
try {
|
|
10810
|
-
raw = JSON.parse(
|
|
10824
|
+
raw = JSON.parse(readFileSync63(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
10811
10825
|
} catch (err) {
|
|
10812
10826
|
const message = err instanceof Error ? err.message : String(err);
|
|
10813
10827
|
throw new Error(`Failed to parse ${WEB_SEARCH_CONFIG_PATH3}: ${message}`);
|
|
@@ -10862,21 +10876,21 @@ async function extractWithDefuddle(text7, url) {
|
|
|
10862
10876
|
}
|
|
10863
10877
|
const result = await resultPromise;
|
|
10864
10878
|
if (processingError !== void 0) {
|
|
10865
|
-
throw new Error(`Defuddle failed to process document: ${
|
|
10879
|
+
throw new Error(`Defuddle failed to process document: ${errorMessage37(processingError)}`);
|
|
10866
10880
|
}
|
|
10867
10881
|
return typeof result.content === "string" ? { title: result.title, content: result.content } : null;
|
|
10868
10882
|
}
|
|
10869
10883
|
function loadSsrfAllowRanges() {
|
|
10870
10884
|
return loadSsrfConfig().allowRanges;
|
|
10871
10885
|
}
|
|
10872
|
-
function
|
|
10886
|
+
function errorMessage37(err) {
|
|
10873
10887
|
return err instanceof Error ? err.message : String(err);
|
|
10874
10888
|
}
|
|
10875
10889
|
function isConfigParseError(err) {
|
|
10876
|
-
return
|
|
10890
|
+
return errorMessage37(err).startsWith("Failed to parse ");
|
|
10877
10891
|
}
|
|
10878
10892
|
function isAbortError6(err) {
|
|
10879
|
-
return
|
|
10893
|
+
return errorMessage37(err).toLowerCase().includes("abort");
|
|
10880
10894
|
}
|
|
10881
10895
|
function isAbortException2(err) {
|
|
10882
10896
|
return err instanceof DOMException && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
@@ -10891,7 +10905,7 @@ function imageGateError() {
|
|
|
10891
10905
|
try {
|
|
10892
10906
|
return isImageEnabled() ? null : "Image fetching is disabled by image.enabled";
|
|
10893
10907
|
} catch (err) {
|
|
10894
|
-
return
|
|
10908
|
+
return errorMessage37(err);
|
|
10895
10909
|
}
|
|
10896
10910
|
}
|
|
10897
10911
|
function redirectPolicyRouteRefusal(url, path) {
|
|
@@ -10946,12 +10960,12 @@ async function fetchAuthenticatedRemoteUrl(url, init, validationOptions, profile
|
|
|
10946
10960
|
throw new Error(`Too many redirects fetching ${current.toString()}`);
|
|
10947
10961
|
}
|
|
10948
10962
|
function loadFetchRouting() {
|
|
10949
|
-
if (!
|
|
10963
|
+
if (!existsSync62(WEB_SEARCH_CONFIG_PATH3)) {
|
|
10950
10964
|
return { providers: DEFAULT_FETCH_PROVIDER_ORDER, allowRemoteHostedProviders: false };
|
|
10951
10965
|
}
|
|
10952
10966
|
let raw;
|
|
10953
10967
|
try {
|
|
10954
|
-
const parsed = JSON.parse(
|
|
10968
|
+
const parsed = JSON.parse(readFileSync63(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
10955
10969
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
10956
10970
|
throw new Error("expected a JSON object");
|
|
10957
10971
|
}
|
|
@@ -11142,7 +11156,7 @@ function safeVideoInfo(url) {
|
|
|
11142
11156
|
const info = isVideoFile(url);
|
|
11143
11157
|
return info ? { status: "video", info } : { status: "not-video" };
|
|
11144
11158
|
} catch (err) {
|
|
11145
|
-
return { status: "invalid", error:
|
|
11159
|
+
return { status: "invalid", error: errorMessage37(err) };
|
|
11146
11160
|
}
|
|
11147
11161
|
}
|
|
11148
11162
|
async function extractContent(url, signal, options) {
|
|
@@ -11153,7 +11167,7 @@ async function extractContent(url, signal, options) {
|
|
|
11153
11167
|
try {
|
|
11154
11168
|
redirectPolicy = options?.redirects ?? loadFetchContentRedirectPolicy();
|
|
11155
11169
|
} catch (err) {
|
|
11156
|
-
return { url, title: "", content: "", error:
|
|
11170
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11157
11171
|
}
|
|
11158
11172
|
let remoteUrl = null;
|
|
11159
11173
|
try {
|
|
@@ -11175,14 +11189,14 @@ async function extractContent(url, signal, options) {
|
|
|
11175
11189
|
...options?.lookup ? { lookup: options.lookup } : {}
|
|
11176
11190
|
});
|
|
11177
11191
|
} catch (err) {
|
|
11178
|
-
return { url, title: "", content: "", error:
|
|
11192
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11179
11193
|
}
|
|
11180
11194
|
}
|
|
11181
11195
|
if (options?.authFetchProfile || options?.mode === "raw") {
|
|
11182
11196
|
try {
|
|
11183
11197
|
return await extractViaHttp(url, resolveFetchTimeoutMs(options), signal, options);
|
|
11184
11198
|
} catch (err) {
|
|
11185
|
-
return { url, title: "", content: "", error:
|
|
11199
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11186
11200
|
}
|
|
11187
11201
|
}
|
|
11188
11202
|
if (redirectPolicy) {
|
|
@@ -11325,20 +11339,20 @@ async function extractContent(url, signal, options) {
|
|
|
11325
11339
|
2. Set GEMINI_API_KEY in ${WEB_SEARCH_CONFIG_PATH3}` };
|
|
11326
11340
|
} catch (err) {
|
|
11327
11341
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11328
|
-
return { url, title: "", content: "", error:
|
|
11342
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11329
11343
|
}
|
|
11330
11344
|
}
|
|
11331
11345
|
try {
|
|
11332
11346
|
if (!remoteUrl) new URL(url);
|
|
11333
11347
|
} catch (err) {
|
|
11334
|
-
return { url, title: "", content: "", error:
|
|
11348
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11335
11349
|
}
|
|
11336
11350
|
try {
|
|
11337
11351
|
const ghIssuePrResult = await extractGitHubIssuePr(url, signal, options);
|
|
11338
11352
|
if (ghIssuePrResult) return ghIssuePrResult;
|
|
11339
11353
|
if (signal?.aborted) return abortedResult(url);
|
|
11340
11354
|
} catch (err) {
|
|
11341
|
-
const message =
|
|
11355
|
+
const message = errorMessage37(err);
|
|
11342
11356
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11343
11357
|
if (isConfigParseError(err)) {
|
|
11344
11358
|
return { url, title: "", content: "", error: message };
|
|
@@ -11349,7 +11363,7 @@ async function extractContent(url, signal, options) {
|
|
|
11349
11363
|
if (ghResult) return ghResult;
|
|
11350
11364
|
if (signal?.aborted) return abortedResult(url);
|
|
11351
11365
|
} catch (err) {
|
|
11352
|
-
const message =
|
|
11366
|
+
const message = errorMessage37(err);
|
|
11353
11367
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11354
11368
|
if (isConfigParseError(err)) {
|
|
11355
11369
|
return { url, title: "", content: "", error: message };
|
|
@@ -11360,7 +11374,7 @@ async function extractContent(url, signal, options) {
|
|
|
11360
11374
|
try {
|
|
11361
11375
|
youtubeEnabled = isYouTubeEnabled();
|
|
11362
11376
|
} catch (err) {
|
|
11363
|
-
return { url, title: "", content: "", error:
|
|
11377
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11364
11378
|
}
|
|
11365
11379
|
if (ytInfo.isYouTube && youtubeEnabled) {
|
|
11366
11380
|
try {
|
|
@@ -11368,7 +11382,7 @@ async function extractContent(url, signal, options) {
|
|
|
11368
11382
|
if (ytResult) return ytResult;
|
|
11369
11383
|
if (signal?.aborted) return abortedResult(url);
|
|
11370
11384
|
} catch (err) {
|
|
11371
|
-
const message =
|
|
11385
|
+
const message = errorMessage37(err);
|
|
11372
11386
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11373
11387
|
return { url, title: "", content: "", error: message };
|
|
11374
11388
|
}
|
|
@@ -11384,13 +11398,13 @@ async function extractContent(url, signal, options) {
|
|
|
11384
11398
|
try {
|
|
11385
11399
|
fetchTimeoutMs = resolveFetchTimeoutMs(options);
|
|
11386
11400
|
} catch (err) {
|
|
11387
|
-
return { url, title: "", content: "", error:
|
|
11401
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11388
11402
|
}
|
|
11389
11403
|
let fetchRouting;
|
|
11390
11404
|
try {
|
|
11391
11405
|
fetchRouting = loadFetchRouting();
|
|
11392
11406
|
} catch (err) {
|
|
11393
|
-
return { url, title: "", content: "", error:
|
|
11407
|
+
return { url, title: "", content: "", error: errorMessage37(err) };
|
|
11394
11408
|
}
|
|
11395
11409
|
if (redirectPolicy && !fetchRouting.providers.includes("http")) {
|
|
11396
11410
|
return redirectPolicyRouteRefusal(url, fetchRouting.providers[0]);
|
|
@@ -11459,7 +11473,7 @@ async function extractContent(url, signal, options) {
|
|
|
11459
11473
|
}
|
|
11460
11474
|
} catch (err) {
|
|
11461
11475
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11462
|
-
firecrawlError =
|
|
11476
|
+
firecrawlError = errorMessage37(err);
|
|
11463
11477
|
if (isConfigParseError(err)) return parseErrorResult(firecrawlError);
|
|
11464
11478
|
}
|
|
11465
11479
|
continue;
|
|
@@ -11477,7 +11491,7 @@ async function extractContent(url, signal, options) {
|
|
|
11477
11491
|
}
|
|
11478
11492
|
} catch (err) {
|
|
11479
11493
|
if (signal?.aborted || isAbortException2(err)) return abortedResult(url);
|
|
11480
|
-
crawl4aiError =
|
|
11494
|
+
crawl4aiError = errorMessage37(err);
|
|
11481
11495
|
if (isConfigParseError(err)) return parseErrorResult(crawl4aiError);
|
|
11482
11496
|
}
|
|
11483
11497
|
continue;
|
|
@@ -11495,7 +11509,7 @@ async function extractContent(url, signal, options) {
|
|
|
11495
11509
|
}
|
|
11496
11510
|
} catch (err) {
|
|
11497
11511
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11498
|
-
tinyfishError =
|
|
11512
|
+
tinyfishError = errorMessage37(err);
|
|
11499
11513
|
if (isConfigParseError(err)) return parseErrorResult(tinyfishError);
|
|
11500
11514
|
}
|
|
11501
11515
|
continue;
|
|
@@ -11508,7 +11522,7 @@ async function extractContent(url, signal, options) {
|
|
|
11508
11522
|
}
|
|
11509
11523
|
} catch (err) {
|
|
11510
11524
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11511
|
-
search1apiError =
|
|
11525
|
+
search1apiError = errorMessage37(err);
|
|
11512
11526
|
if (isConfigParseError(err)) return parseErrorResult(search1apiError);
|
|
11513
11527
|
}
|
|
11514
11528
|
continue;
|
|
@@ -11521,7 +11535,7 @@ async function extractContent(url, signal, options) {
|
|
|
11521
11535
|
}
|
|
11522
11536
|
} catch (err) {
|
|
11523
11537
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11524
|
-
queritError =
|
|
11538
|
+
queritError = errorMessage37(err);
|
|
11525
11539
|
if (isConfigParseError(err)) return parseErrorResult(queritError);
|
|
11526
11540
|
}
|
|
11527
11541
|
continue;
|
|
@@ -11534,7 +11548,7 @@ async function extractContent(url, signal, options) {
|
|
|
11534
11548
|
}
|
|
11535
11549
|
} catch (err) {
|
|
11536
11550
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11537
|
-
tabstackError =
|
|
11551
|
+
tabstackError = errorMessage37(err);
|
|
11538
11552
|
if (isConfigParseError(err)) return parseErrorResult(tabstackError);
|
|
11539
11553
|
}
|
|
11540
11554
|
continue;
|
|
@@ -11552,7 +11566,7 @@ async function extractContent(url, signal, options) {
|
|
|
11552
11566
|
}
|
|
11553
11567
|
} catch (err) {
|
|
11554
11568
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11555
|
-
kagiError =
|
|
11569
|
+
kagiError = errorMessage37(err);
|
|
11556
11570
|
if (isConfigParseError(err)) return parseErrorResult(kagiError);
|
|
11557
11571
|
}
|
|
11558
11572
|
continue;
|
|
@@ -11570,7 +11584,7 @@ async function extractContent(url, signal, options) {
|
|
|
11570
11584
|
}
|
|
11571
11585
|
} catch (err) {
|
|
11572
11586
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11573
|
-
ollamaError =
|
|
11587
|
+
ollamaError = errorMessage37(err);
|
|
11574
11588
|
if (isConfigParseError(err)) return parseErrorResult(ollamaError);
|
|
11575
11589
|
}
|
|
11576
11590
|
continue;
|
|
@@ -11583,7 +11597,7 @@ async function extractContent(url, signal, options) {
|
|
|
11583
11597
|
}
|
|
11584
11598
|
} catch (err) {
|
|
11585
11599
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11586
|
-
parallelError =
|
|
11600
|
+
parallelError = errorMessage37(err);
|
|
11587
11601
|
if (isConfigParseError(err)) return parseErrorResult(parallelError);
|
|
11588
11602
|
}
|
|
11589
11603
|
continue;
|
|
@@ -11594,7 +11608,7 @@ async function extractContent(url, signal, options) {
|
|
|
11594
11608
|
if (parallelMcpResult) return withDeclaredLinks(parallelMcpResult);
|
|
11595
11609
|
} catch (err) {
|
|
11596
11610
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11597
|
-
parallelMcpError =
|
|
11611
|
+
parallelMcpError = errorMessage37(err);
|
|
11598
11612
|
if (isConfigParseError(err)) return parseErrorResult(parallelMcpError);
|
|
11599
11613
|
}
|
|
11600
11614
|
continue;
|
|
@@ -11612,7 +11626,7 @@ async function extractContent(url, signal, options) {
|
|
|
11612
11626
|
}
|
|
11613
11627
|
} catch (err) {
|
|
11614
11628
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11615
|
-
brightdataError =
|
|
11629
|
+
brightdataError = errorMessage37(err);
|
|
11616
11630
|
if (isConfigParseError(err)) return parseErrorResult(brightdataError);
|
|
11617
11631
|
}
|
|
11618
11632
|
continue;
|
|
@@ -11624,7 +11638,7 @@ async function extractContent(url, signal, options) {
|
|
|
11624
11638
|
} catch (err) {
|
|
11625
11639
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11626
11640
|
if (err instanceof CredentialResolutionError || isConfigParseError(err)) {
|
|
11627
|
-
return parseErrorResult(
|
|
11641
|
+
return parseErrorResult(errorMessage37(err));
|
|
11628
11642
|
}
|
|
11629
11643
|
}
|
|
11630
11644
|
if (geminiResult) return withDeclaredLinks(geminiResult);
|
|
@@ -11640,7 +11654,7 @@ async function extractContent(url, signal, options) {
|
|
|
11640
11654
|
}
|
|
11641
11655
|
} catch (err) {
|
|
11642
11656
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11643
|
-
deepseekError =
|
|
11657
|
+
deepseekError = errorMessage37(err);
|
|
11644
11658
|
if (isConfigParseError(err)) return parseErrorResult(deepseekError);
|
|
11645
11659
|
}
|
|
11646
11660
|
continue;
|
|
@@ -11656,7 +11670,7 @@ async function extractContent(url, signal, options) {
|
|
|
11656
11670
|
}
|
|
11657
11671
|
} catch (err) {
|
|
11658
11672
|
if (isAbortError6(err)) return abortedResult(url);
|
|
11659
|
-
exaError =
|
|
11673
|
+
exaError = errorMessage37(err);
|
|
11660
11674
|
if (isConfigParseError(err)) return parseErrorResult(exaError);
|
|
11661
11675
|
}
|
|
11662
11676
|
continue;
|
|
@@ -11897,7 +11911,7 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
11897
11911
|
status: response.status
|
|
11898
11912
|
};
|
|
11899
11913
|
} catch (err) {
|
|
11900
|
-
const message =
|
|
11914
|
+
const message = errorMessage37(err);
|
|
11901
11915
|
activityMonitor.logError(activityId, message);
|
|
11902
11916
|
return { url, title: "", content: "", error: message, mimeType, status: response.status };
|
|
11903
11917
|
}
|
|
@@ -12850,7 +12864,7 @@ Query: ${query}` }],
|
|
|
12850
12864
|
init_github_extract();
|
|
12851
12865
|
|
|
12852
12866
|
// gemini-search.ts
|
|
12853
|
-
import { existsSync as
|
|
12867
|
+
import { existsSync as existsSync51, readFileSync as readFileSync51 } from "node:fs";
|
|
12854
12868
|
init_activity();
|
|
12855
12869
|
init_credential_source();
|
|
12856
12870
|
init_gemini_api();
|
|
@@ -18718,6 +18732,343 @@ async function searchWithSearchApi(query, options = {}) {
|
|
|
18718
18732
|
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
18719
18733
|
}
|
|
18720
18734
|
|
|
18735
|
+
// outcrawl.ts
|
|
18736
|
+
init_activity();
|
|
18737
|
+
init_domain_filter_normalization();
|
|
18738
|
+
init_search_answer_formatting();
|
|
18739
|
+
init_search_result_count_normalization();
|
|
18740
|
+
init_credential_source();
|
|
18741
|
+
init_utils();
|
|
18742
|
+
import { existsSync as existsSync47, readFileSync as readFileSync47 } from "node:fs";
|
|
18743
|
+
var OUTCRAWL_SEARCH_URL = "https://api.outcrawl.ai/v1/search";
|
|
18744
|
+
var CONFIG_PATH43 = getWebSearchConfigPath();
|
|
18745
|
+
var SEARCH_TIMEOUT_MS35 = 6e4;
|
|
18746
|
+
var MAX_REQUEST_RESULTS4 = 20;
|
|
18747
|
+
var cachedConfig39 = null;
|
|
18748
|
+
function loadConfig40() {
|
|
18749
|
+
if (cachedConfig39) return cachedConfig39;
|
|
18750
|
+
if (!existsSync47(CONFIG_PATH43)) {
|
|
18751
|
+
cachedConfig39 = {};
|
|
18752
|
+
return cachedConfig39;
|
|
18753
|
+
}
|
|
18754
|
+
const raw = readFileSync47(CONFIG_PATH43, "utf-8");
|
|
18755
|
+
let parsed;
|
|
18756
|
+
try {
|
|
18757
|
+
parsed = JSON.parse(raw);
|
|
18758
|
+
} catch (err) {
|
|
18759
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
18760
|
+
throw new Error(`Failed to parse ${CONFIG_PATH43}: ${message}`);
|
|
18761
|
+
}
|
|
18762
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
18763
|
+
throw new Error(`Invalid config in ${CONFIG_PATH43}: expected a JSON object`);
|
|
18764
|
+
}
|
|
18765
|
+
cachedConfig39 = parsed;
|
|
18766
|
+
return cachedConfig39;
|
|
18767
|
+
}
|
|
18768
|
+
async function getApiKey28(signal) {
|
|
18769
|
+
return resolveCredential({
|
|
18770
|
+
provider: "Outcrawl",
|
|
18771
|
+
configuredValue: loadConfig40().outcrawlApiKey,
|
|
18772
|
+
environmentValue: process.env.OUTCRAWL_API_KEY,
|
|
18773
|
+
signal
|
|
18774
|
+
});
|
|
18775
|
+
}
|
|
18776
|
+
async function requireApiKey16(signal) {
|
|
18777
|
+
const apiKey = await getApiKey28(signal);
|
|
18778
|
+
if (!apiKey) {
|
|
18779
|
+
throw new Error(
|
|
18780
|
+
`Outcrawl API key not found. Either:
|
|
18781
|
+
1. Create ${CONFIG_PATH43} with { "outcrawlApiKey": "your-key" }
|
|
18782
|
+
2. Set OUTCRAWL_API_KEY environment variable
|
|
18783
|
+
Get a key at https://outcrawl.ai`
|
|
18784
|
+
);
|
|
18785
|
+
}
|
|
18786
|
+
return apiKey;
|
|
18787
|
+
}
|
|
18788
|
+
function parseDomainFilter13(domainFilter) {
|
|
18789
|
+
const filters = { include: [], exclude: [] };
|
|
18790
|
+
for (const raw of domainFilter ?? []) {
|
|
18791
|
+
const domain = normalizeDomain(raw);
|
|
18792
|
+
if (!domain) continue;
|
|
18793
|
+
const target = raw.trim().startsWith("-") ? filters.exclude : filters.include;
|
|
18794
|
+
if (!target.includes(domain)) target.push(domain);
|
|
18795
|
+
}
|
|
18796
|
+
return filters;
|
|
18797
|
+
}
|
|
18798
|
+
function passesDomainFilters13(url, filters) {
|
|
18799
|
+
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
18800
|
+
const hostname2 = url.hostname.toLowerCase();
|
|
18801
|
+
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
18802
|
+
if (filters.exclude.some(matches)) return false;
|
|
18803
|
+
return filters.include.length === 0 || filters.include.some(matches);
|
|
18804
|
+
}
|
|
18805
|
+
function buildQuery10(query, filters) {
|
|
18806
|
+
const parts = [query];
|
|
18807
|
+
if (filters.include.length === 1) parts.push(`site:${filters.include[0]}`);
|
|
18808
|
+
if (filters.include.length > 1) parts.push(`(${filters.include.map((domain) => `site:${domain}`).join(" OR ")})`);
|
|
18809
|
+
for (const domain of filters.exclude) parts.push(`-site:${domain}`);
|
|
18810
|
+
return parts.join(" ");
|
|
18811
|
+
}
|
|
18812
|
+
function errorMessage28(err) {
|
|
18813
|
+
return err instanceof Error ? err.message : String(err);
|
|
18814
|
+
}
|
|
18815
|
+
function invalidResponse16(message) {
|
|
18816
|
+
return new Error(`Outcrawl returned invalid response: ${message}`);
|
|
18817
|
+
}
|
|
18818
|
+
function parseResponse13(value) {
|
|
18819
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalidResponse16("expected an object envelope");
|
|
18820
|
+
const envelope = value;
|
|
18821
|
+
if (typeof envelope.error === "string" && envelope.error.trim()) throw invalidResponse16(envelope.error.trim());
|
|
18822
|
+
if (!Array.isArray(envelope.hits)) throw invalidResponse16("expected hits array");
|
|
18823
|
+
return envelope.hits;
|
|
18824
|
+
}
|
|
18825
|
+
function isOutcrawlAvailable() {
|
|
18826
|
+
return hasCredentialSource({ provider: "Outcrawl", configuredValue: loadConfig40().outcrawlApiKey, environmentValue: process.env.OUTCRAWL_API_KEY });
|
|
18827
|
+
}
|
|
18828
|
+
async function searchWithOutcrawl(query, options = {}) {
|
|
18829
|
+
const apiKey = await requireApiKey16(options.signal);
|
|
18830
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
18831
|
+
const filters = parseDomainFilter13(options.domainFilter);
|
|
18832
|
+
const hasDomainClauses = filters.include.length > 0 || filters.exclude.length > 0;
|
|
18833
|
+
const body = {
|
|
18834
|
+
query: buildQuery10(query, filters),
|
|
18835
|
+
limit: hasDomainClauses ? Math.min(MAX_REQUEST_RESULTS4, numResults + 5) : numResults
|
|
18836
|
+
};
|
|
18837
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
18838
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS35);
|
|
18839
|
+
let response;
|
|
18840
|
+
let entries;
|
|
18841
|
+
try {
|
|
18842
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("outcrawl", OUTCRAWL_SEARCH_URL, loadConfig40().outcrawlBaseUrl), {
|
|
18843
|
+
method: "POST",
|
|
18844
|
+
headers: {
|
|
18845
|
+
Accept: "application/json",
|
|
18846
|
+
Authorization: `Bearer ${apiKey}`,
|
|
18847
|
+
"Content-Type": "application/json",
|
|
18848
|
+
"User-Agent": "pi-web-access"
|
|
18849
|
+
},
|
|
18850
|
+
body: JSON.stringify(body),
|
|
18851
|
+
signal: options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal
|
|
18852
|
+
}, ["Authorization"]);
|
|
18853
|
+
if (!response.ok) {
|
|
18854
|
+
const errorText = await response.text();
|
|
18855
|
+
throw new Error(`Outcrawl error ${response.status}: ${redactCredential(errorText, apiKey).slice(0, 300)}`);
|
|
18856
|
+
}
|
|
18857
|
+
let rawData;
|
|
18858
|
+
try {
|
|
18859
|
+
rawData = await response.json();
|
|
18860
|
+
} catch (err) {
|
|
18861
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
18862
|
+
throw new Error(`Outcrawl returned invalid JSON: ${errorMessage28(err)}`);
|
|
18863
|
+
}
|
|
18864
|
+
entries = parseResponse13(rawData);
|
|
18865
|
+
} catch (err) {
|
|
18866
|
+
if (options.signal?.aborted) {
|
|
18867
|
+
activityMonitor.logComplete(activityId, 0);
|
|
18868
|
+
throw new Error("Aborted");
|
|
18869
|
+
}
|
|
18870
|
+
const message = errorMessage28(err);
|
|
18871
|
+
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
18872
|
+
const outgoing = providerTimeout ? new Error(`Outcrawl request timed out after ${Math.round(SEARCH_TIMEOUT_MS35 / 1e3)}s`) : (() => {
|
|
18873
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
18874
|
+
if (redactedMessage === message && err instanceof Error) return err;
|
|
18875
|
+
const redactedError = new Error(redactedMessage);
|
|
18876
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
18877
|
+
return redactedError;
|
|
18878
|
+
})();
|
|
18879
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage28(outgoing), apiKey));
|
|
18880
|
+
throw outgoing;
|
|
18881
|
+
}
|
|
18882
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
18883
|
+
const results = [];
|
|
18884
|
+
for (const entry of entries) {
|
|
18885
|
+
if (!entry || typeof entry !== "object") continue;
|
|
18886
|
+
if (typeof entry.url !== "string" || !entry.url) continue;
|
|
18887
|
+
let resultUrl;
|
|
18888
|
+
try {
|
|
18889
|
+
resultUrl = new URL(entry.url);
|
|
18890
|
+
} catch {
|
|
18891
|
+
continue;
|
|
18892
|
+
}
|
|
18893
|
+
if (resultUrl.protocol !== "http:" && resultUrl.protocol !== "https:") continue;
|
|
18894
|
+
if (!passesDomainFilters13(resultUrl, filters)) continue;
|
|
18895
|
+
results.push({
|
|
18896
|
+
title: typeof entry.title === "string" && entry.title.trim() ? entry.title.trim() : `Source ${results.length + 1}`,
|
|
18897
|
+
url: resultUrl.href,
|
|
18898
|
+
snippet: typeof entry.snippet === "string" ? entry.snippet : ""
|
|
18899
|
+
});
|
|
18900
|
+
if (results.length >= numResults) break;
|
|
18901
|
+
}
|
|
18902
|
+
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
18903
|
+
}
|
|
18904
|
+
|
|
18905
|
+
// sofya.ts
|
|
18906
|
+
init_activity();
|
|
18907
|
+
init_domain_filter_normalization();
|
|
18908
|
+
init_search_answer_formatting();
|
|
18909
|
+
init_search_result_count_normalization();
|
|
18910
|
+
init_credential_source();
|
|
18911
|
+
init_utils();
|
|
18912
|
+
import { existsSync as existsSync48, readFileSync as readFileSync48 } from "node:fs";
|
|
18913
|
+
var SOFYA_SEARCH_URL = "https://sofya.co/v1/search";
|
|
18914
|
+
var CONFIG_PATH44 = getWebSearchConfigPath();
|
|
18915
|
+
var SEARCH_TIMEOUT_MS36 = 6e4;
|
|
18916
|
+
var MAX_REQUEST_RESULTS5 = 20;
|
|
18917
|
+
var MAX_DOMAIN_FILTERS = 10;
|
|
18918
|
+
var cachedConfig40 = null;
|
|
18919
|
+
function loadConfig41() {
|
|
18920
|
+
if (cachedConfig40) return cachedConfig40;
|
|
18921
|
+
if (!existsSync48(CONFIG_PATH44)) {
|
|
18922
|
+
cachedConfig40 = {};
|
|
18923
|
+
return cachedConfig40;
|
|
18924
|
+
}
|
|
18925
|
+
const raw = readFileSync48(CONFIG_PATH44, "utf-8");
|
|
18926
|
+
let parsed;
|
|
18927
|
+
try {
|
|
18928
|
+
parsed = JSON.parse(raw);
|
|
18929
|
+
} catch (err) {
|
|
18930
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
18931
|
+
throw new Error(`Failed to parse ${CONFIG_PATH44}: ${message}`);
|
|
18932
|
+
}
|
|
18933
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
18934
|
+
throw new Error(`Invalid config in ${CONFIG_PATH44}: expected a JSON object`);
|
|
18935
|
+
}
|
|
18936
|
+
cachedConfig40 = parsed;
|
|
18937
|
+
return cachedConfig40;
|
|
18938
|
+
}
|
|
18939
|
+
async function getApiKey29(signal) {
|
|
18940
|
+
return resolveCredential({
|
|
18941
|
+
provider: "Sofya",
|
|
18942
|
+
configuredValue: loadConfig41().sofyaApiKey,
|
|
18943
|
+
environmentValue: process.env.SOFYA_API_KEY,
|
|
18944
|
+
signal
|
|
18945
|
+
});
|
|
18946
|
+
}
|
|
18947
|
+
async function requireApiKey17(signal) {
|
|
18948
|
+
const apiKey = await getApiKey29(signal);
|
|
18949
|
+
if (!apiKey) {
|
|
18950
|
+
throw new Error(
|
|
18951
|
+
`Sofya API key not found. Either:
|
|
18952
|
+
1. Create ${CONFIG_PATH44} with { "sofyaApiKey": "your-key" }
|
|
18953
|
+
2. Set SOFYA_API_KEY environment variable
|
|
18954
|
+
Get a key at https://sofya.co/dashboard`
|
|
18955
|
+
);
|
|
18956
|
+
}
|
|
18957
|
+
return apiKey;
|
|
18958
|
+
}
|
|
18959
|
+
function parseDomainFilter14(domainFilter) {
|
|
18960
|
+
const filters = { include: [], exclude: [] };
|
|
18961
|
+
for (const raw of domainFilter ?? []) {
|
|
18962
|
+
const domain = normalizeDomain(raw);
|
|
18963
|
+
if (!domain) continue;
|
|
18964
|
+
const target = raw.trim().startsWith("-") ? filters.exclude : filters.include;
|
|
18965
|
+
if (!target.includes(domain)) target.push(domain);
|
|
18966
|
+
}
|
|
18967
|
+
return filters;
|
|
18968
|
+
}
|
|
18969
|
+
function passesDomainFilters14(url, filters) {
|
|
18970
|
+
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
18971
|
+
const hostname2 = url.hostname.toLowerCase();
|
|
18972
|
+
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
18973
|
+
if (filters.exclude.some(matches)) return false;
|
|
18974
|
+
return filters.include.length === 0 || filters.include.some(matches);
|
|
18975
|
+
}
|
|
18976
|
+
function errorMessage29(err) {
|
|
18977
|
+
return err instanceof Error ? err.message : String(err);
|
|
18978
|
+
}
|
|
18979
|
+
function invalidResponse17(message) {
|
|
18980
|
+
return new Error(`Sofya returned invalid response: ${message}`);
|
|
18981
|
+
}
|
|
18982
|
+
function parseResponse14(value) {
|
|
18983
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalidResponse17("expected an object envelope");
|
|
18984
|
+
const envelope = value;
|
|
18985
|
+
if (typeof envelope.detail === "string" && envelope.detail.trim()) throw invalidResponse17(envelope.detail.trim());
|
|
18986
|
+
if (!Array.isArray(envelope.results)) throw invalidResponse17("expected results array");
|
|
18987
|
+
return envelope.results;
|
|
18988
|
+
}
|
|
18989
|
+
function isSofyaAvailable() {
|
|
18990
|
+
return hasCredentialSource({ provider: "Sofya", configuredValue: loadConfig41().sofyaApiKey, environmentValue: process.env.SOFYA_API_KEY });
|
|
18991
|
+
}
|
|
18992
|
+
async function searchWithSofya(query, options = {}) {
|
|
18993
|
+
const apiKey = await requireApiKey17(options.signal);
|
|
18994
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
18995
|
+
const filters = parseDomainFilter14(options.domainFilter);
|
|
18996
|
+
const body = {
|
|
18997
|
+
query,
|
|
18998
|
+
search_depth: "snippets",
|
|
18999
|
+
max_results: Math.min(MAX_REQUEST_RESULTS5, numResults)
|
|
19000
|
+
};
|
|
19001
|
+
if (filters.include.length > 0) body.include_domains = filters.include.slice(0, MAX_DOMAIN_FILTERS);
|
|
19002
|
+
if (filters.exclude.length > 0) body.exclude_domains = filters.exclude.slice(0, MAX_DOMAIN_FILTERS);
|
|
19003
|
+
if (options.recencyFilter) body.freshness = options.recencyFilter;
|
|
19004
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
19005
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS36);
|
|
19006
|
+
let response;
|
|
19007
|
+
let entries;
|
|
19008
|
+
try {
|
|
19009
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("sofya", SOFYA_SEARCH_URL, loadConfig41().sofyaBaseUrl), {
|
|
19010
|
+
method: "POST",
|
|
19011
|
+
headers: {
|
|
19012
|
+
Accept: "application/json",
|
|
19013
|
+
Authorization: `Bearer ${apiKey}`,
|
|
19014
|
+
"Content-Type": "application/json",
|
|
19015
|
+
"User-Agent": "pi-web-access"
|
|
19016
|
+
},
|
|
19017
|
+
body: JSON.stringify(body),
|
|
19018
|
+
signal: options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal
|
|
19019
|
+
}, ["Authorization"]);
|
|
19020
|
+
if (!response.ok) {
|
|
19021
|
+
const errorText = await response.text();
|
|
19022
|
+
throw new Error(`Sofya error ${response.status}: ${redactCredential(errorText, apiKey).slice(0, 300)}`);
|
|
19023
|
+
}
|
|
19024
|
+
let rawData;
|
|
19025
|
+
try {
|
|
19026
|
+
rawData = await response.json();
|
|
19027
|
+
} catch (err) {
|
|
19028
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
19029
|
+
throw new Error(`Sofya returned invalid JSON: ${errorMessage29(err)}`);
|
|
19030
|
+
}
|
|
19031
|
+
entries = parseResponse14(rawData);
|
|
19032
|
+
} catch (err) {
|
|
19033
|
+
if (options.signal?.aborted) {
|
|
19034
|
+
activityMonitor.logComplete(activityId, 0);
|
|
19035
|
+
throw new Error("Aborted");
|
|
19036
|
+
}
|
|
19037
|
+
const message = errorMessage29(err);
|
|
19038
|
+
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
19039
|
+
const outgoing = providerTimeout ? new Error(`Sofya request timed out after ${Math.round(SEARCH_TIMEOUT_MS36 / 1e3)}s`) : (() => {
|
|
19040
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
19041
|
+
if (redactedMessage === message && err instanceof Error) return err;
|
|
19042
|
+
const redactedError = new Error(redactedMessage);
|
|
19043
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
19044
|
+
return redactedError;
|
|
19045
|
+
})();
|
|
19046
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage29(outgoing), apiKey));
|
|
19047
|
+
throw outgoing;
|
|
19048
|
+
}
|
|
19049
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
19050
|
+
const results = [];
|
|
19051
|
+
for (const entry of entries) {
|
|
19052
|
+
if (!entry || typeof entry !== "object") continue;
|
|
19053
|
+
if (typeof entry.url !== "string" || !entry.url) continue;
|
|
19054
|
+
let resultUrl;
|
|
19055
|
+
try {
|
|
19056
|
+
resultUrl = new URL(entry.url);
|
|
19057
|
+
} catch {
|
|
19058
|
+
continue;
|
|
19059
|
+
}
|
|
19060
|
+
if (resultUrl.protocol !== "http:" && resultUrl.protocol !== "https:") continue;
|
|
19061
|
+
if (!passesDomainFilters14(resultUrl, filters)) continue;
|
|
19062
|
+
results.push({
|
|
19063
|
+
title: typeof entry.title === "string" && entry.title.trim() ? entry.title.trim() : `Source ${results.length + 1}`,
|
|
19064
|
+
url: resultUrl.href,
|
|
19065
|
+
snippet: typeof entry.content === "string" && entry.content ? entry.content : typeof entry.description === "string" ? entry.description : ""
|
|
19066
|
+
});
|
|
19067
|
+
if (results.length >= numResults) break;
|
|
19068
|
+
}
|
|
19069
|
+
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
19070
|
+
}
|
|
19071
|
+
|
|
18721
19072
|
// gemini-search.ts
|
|
18722
19073
|
init_deepseek();
|
|
18723
19074
|
|
|
@@ -18730,7 +19081,7 @@ init_search_result_count_normalization();
|
|
|
18730
19081
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
18731
19082
|
var KIMI_SEARCH_URL = "https://api.kimi.com/coding/v1/search";
|
|
18732
19083
|
var KIMI_PROVIDERS = ["kimi-coding", "kimi-code"];
|
|
18733
|
-
var
|
|
19084
|
+
var SEARCH_TIMEOUT_MS38 = 3e4;
|
|
18734
19085
|
function buildRequestHeaders(auth) {
|
|
18735
19086
|
const headers = new Headers();
|
|
18736
19087
|
for (const [name, value] of Object.entries(auth.headers)) {
|
|
@@ -18845,7 +19196,7 @@ async function searchWithKimi(query, options = {}, ctx) {
|
|
|
18845
19196
|
throw new Error("Kimi Code web search unavailable. Run /login kimi-coding to authenticate a Kimi Code Plan account.");
|
|
18846
19197
|
}
|
|
18847
19198
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
18848
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
19199
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS38);
|
|
18849
19200
|
const requestSignal16 = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal;
|
|
18850
19201
|
try {
|
|
18851
19202
|
const response = await fetch(KIMI_SEARCH_URL, {
|
|
@@ -18897,45 +19248,45 @@ init_activity();
|
|
|
18897
19248
|
init_domain_filter_normalization();
|
|
18898
19249
|
init_credential_source();
|
|
18899
19250
|
init_utils();
|
|
18900
|
-
import { existsSync as
|
|
19251
|
+
import { existsSync as existsSync50, readFileSync as readFileSync50 } from "node:fs";
|
|
18901
19252
|
var MISTRAL_CONVERSATIONS_URL = "https://api.mistral.ai/v1/conversations";
|
|
18902
|
-
var
|
|
18903
|
-
var
|
|
19253
|
+
var CONFIG_PATH46 = getWebSearchConfigPath();
|
|
19254
|
+
var SEARCH_TIMEOUT_MS39 = 6e4;
|
|
18904
19255
|
var DEFAULT_SEARCH_MODEL = "mistral-small-latest";
|
|
18905
19256
|
var DEFAULT_SEARCH_TOOL = "web_search";
|
|
18906
19257
|
var MAX_RESULTS2 = 20;
|
|
18907
|
-
var
|
|
18908
|
-
function
|
|
18909
|
-
if (
|
|
18910
|
-
if (!
|
|
18911
|
-
|
|
18912
|
-
return
|
|
19258
|
+
var cachedConfig42 = null;
|
|
19259
|
+
function loadConfig43() {
|
|
19260
|
+
if (cachedConfig42) return cachedConfig42;
|
|
19261
|
+
if (!existsSync50(CONFIG_PATH46)) {
|
|
19262
|
+
cachedConfig42 = {};
|
|
19263
|
+
return cachedConfig42;
|
|
18913
19264
|
}
|
|
18914
|
-
const raw =
|
|
19265
|
+
const raw = readFileSync50(CONFIG_PATH46, "utf-8");
|
|
18915
19266
|
let parsed;
|
|
18916
19267
|
try {
|
|
18917
19268
|
parsed = JSON.parse(raw);
|
|
18918
19269
|
} catch (err) {
|
|
18919
19270
|
const message = err instanceof Error ? err.message : String(err);
|
|
18920
|
-
throw new Error(`Failed to parse ${
|
|
19271
|
+
throw new Error(`Failed to parse ${CONFIG_PATH46}: ${message}`);
|
|
18921
19272
|
}
|
|
18922
19273
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
18923
|
-
throw new Error(`Invalid config in ${
|
|
19274
|
+
throw new Error(`Invalid config in ${CONFIG_PATH46}: expected a JSON object`);
|
|
18924
19275
|
}
|
|
18925
|
-
|
|
18926
|
-
return
|
|
19276
|
+
cachedConfig42 = parsed;
|
|
19277
|
+
return cachedConfig42;
|
|
18927
19278
|
}
|
|
18928
19279
|
function resolveSearchModel(value) {
|
|
18929
19280
|
if (value === void 0) return DEFAULT_SEARCH_MODEL;
|
|
18930
19281
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
18931
|
-
throw new Error(`mistralSearchModel in ${
|
|
19282
|
+
throw new Error(`mistralSearchModel in ${CONFIG_PATH46} must be a non-empty string`);
|
|
18932
19283
|
}
|
|
18933
19284
|
return value.trim();
|
|
18934
19285
|
}
|
|
18935
19286
|
function resolveSearchTool(value) {
|
|
18936
19287
|
if (value === void 0) return DEFAULT_SEARCH_TOOL;
|
|
18937
19288
|
if (value !== "web_search" && value !== "web_search_premium") {
|
|
18938
|
-
throw new Error(`mistralSearchTool in ${
|
|
19289
|
+
throw new Error(`mistralSearchTool in ${CONFIG_PATH46} must be either web_search or web_search_premium`);
|
|
18939
19290
|
}
|
|
18940
19291
|
return value;
|
|
18941
19292
|
}
|
|
@@ -18953,7 +19304,7 @@ function parseDomainFilters(domainFilter) {
|
|
|
18953
19304
|
}
|
|
18954
19305
|
return filters;
|
|
18955
19306
|
}
|
|
18956
|
-
function
|
|
19307
|
+
function passesDomainFilters15(url, filters) {
|
|
18957
19308
|
if (filters.include.length === 0 && filters.exclude.length === 0) return true;
|
|
18958
19309
|
const hostname2 = new URL(url).hostname.toLowerCase();
|
|
18959
19310
|
const matches = (domain) => hostname2 === domain || hostname2.endsWith(`.${domain}`);
|
|
@@ -18993,18 +19344,18 @@ function buildSearchPrompt(query, options, numResults) {
|
|
|
18993
19344
|
|
|
18994
19345
|
${query}` : query;
|
|
18995
19346
|
}
|
|
18996
|
-
function
|
|
19347
|
+
function errorMessage31(err) {
|
|
18997
19348
|
return err instanceof Error ? err.message : String(err);
|
|
18998
19349
|
}
|
|
18999
|
-
function
|
|
19350
|
+
function invalidResponse18(message) {
|
|
19000
19351
|
return new Error(`Mistral API returned invalid response: ${message}`);
|
|
19001
19352
|
}
|
|
19002
19353
|
function parseConversationResponse(value, options, numResults) {
|
|
19003
19354
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
19004
|
-
throw
|
|
19355
|
+
throw invalidResponse18("expected an object envelope");
|
|
19005
19356
|
}
|
|
19006
19357
|
const outputs = value.outputs;
|
|
19007
|
-
if (!Array.isArray(outputs)) throw
|
|
19358
|
+
if (!Array.isArray(outputs)) throw invalidResponse18("outputs must be an array");
|
|
19008
19359
|
const answerParts = [];
|
|
19009
19360
|
const results = [];
|
|
19010
19361
|
const seenUrls = /* @__PURE__ */ new Set();
|
|
@@ -19028,7 +19379,7 @@ function parseConversationResponse(value, options, numResults) {
|
|
|
19028
19379
|
}
|
|
19029
19380
|
if (part.type !== "tool_reference" || results.length >= numResults) continue;
|
|
19030
19381
|
const url = normalizeResultUrl2(part.url);
|
|
19031
|
-
if (!url || !
|
|
19382
|
+
if (!url || !passesDomainFilters15(url, domainFilters2) || seenUrls.has(url)) continue;
|
|
19032
19383
|
seenUrls.add(url);
|
|
19033
19384
|
const title = typeof part.title === "string" && part.title.trim() ? part.title.trim() : url;
|
|
19034
19385
|
const snippet = typeof part.description === "string" ? part.description : "";
|
|
@@ -19036,20 +19387,20 @@ function parseConversationResponse(value, options, numResults) {
|
|
|
19036
19387
|
}
|
|
19037
19388
|
}
|
|
19038
19389
|
const answer = answerParts.join("\n").trim();
|
|
19039
|
-
if (!answer && results.length === 0) throw
|
|
19390
|
+
if (!answer && results.length === 0) throw invalidResponse18("no answer or sources");
|
|
19040
19391
|
return { answer, results };
|
|
19041
19392
|
}
|
|
19042
|
-
async function
|
|
19393
|
+
async function getApiKey30(signal) {
|
|
19043
19394
|
const apiKey = await resolveCredential({
|
|
19044
19395
|
provider: "Mistral",
|
|
19045
|
-
configuredValue:
|
|
19396
|
+
configuredValue: loadConfig43().mistralApiKey,
|
|
19046
19397
|
environmentValue: process.env.MISTRAL_API_KEY,
|
|
19047
19398
|
signal
|
|
19048
19399
|
});
|
|
19049
19400
|
if (!apiKey) {
|
|
19050
19401
|
throw new Error(
|
|
19051
19402
|
`Mistral API key not found. Either:
|
|
19052
|
-
1. Create ${
|
|
19403
|
+
1. Create ${CONFIG_PATH46} with { "mistralApiKey": "your-key" }
|
|
19053
19404
|
2. Set MISTRAL_API_KEY environment variable
|
|
19054
19405
|
Get a key at https://console.mistral.ai/api-keys`
|
|
19055
19406
|
);
|
|
@@ -19058,7 +19409,7 @@ Get a key at https://console.mistral.ai/api-keys`
|
|
|
19058
19409
|
}
|
|
19059
19410
|
function isMistralAvailable() {
|
|
19060
19411
|
try {
|
|
19061
|
-
const config =
|
|
19412
|
+
const config = loadConfig43();
|
|
19062
19413
|
resolveSearchModel(config.mistralSearchModel);
|
|
19063
19414
|
resolveSearchTool(config.mistralSearchTool);
|
|
19064
19415
|
return hasCredentialSource({
|
|
@@ -19071,15 +19422,15 @@ function isMistralAvailable() {
|
|
|
19071
19422
|
}
|
|
19072
19423
|
}
|
|
19073
19424
|
async function searchWithMistral(query, options = {}) {
|
|
19074
|
-
const config =
|
|
19425
|
+
const config = loadConfig43();
|
|
19075
19426
|
const model = options.model ?? resolveSearchModel(config.mistralSearchModel);
|
|
19076
19427
|
const tool = resolveSearchTool(config.mistralSearchTool);
|
|
19077
19428
|
const numResults = normalizeCount4(options.numResults);
|
|
19078
|
-
const apiKey = await
|
|
19079
|
-
const requestSignal16 = options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
19429
|
+
const apiKey = await getApiKey30(options.signal);
|
|
19430
|
+
const requestSignal16 = options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS39), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS39);
|
|
19080
19431
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
19081
19432
|
try {
|
|
19082
|
-
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("mistralSearch", MISTRAL_CONVERSATIONS_URL,
|
|
19433
|
+
const response = await fetchWithCredentialRedirects(resolveProviderApiUrl("mistralSearch", MISTRAL_CONVERSATIONS_URL, loadConfig43().mistralSearchBaseUrl), {
|
|
19083
19434
|
method: "POST",
|
|
19084
19435
|
headers: {
|
|
19085
19436
|
Authorization: `Bearer ${apiKey}`,
|
|
@@ -19101,13 +19452,13 @@ async function searchWithMistral(query, options = {}) {
|
|
|
19101
19452
|
try {
|
|
19102
19453
|
parsed = await response.json();
|
|
19103
19454
|
} catch (err) {
|
|
19104
|
-
throw new Error(`Mistral API returned invalid JSON: ${
|
|
19455
|
+
throw new Error(`Mistral API returned invalid JSON: ${errorMessage31(err)}`);
|
|
19105
19456
|
}
|
|
19106
19457
|
const result = parseConversationResponse(parsed, options, numResults);
|
|
19107
19458
|
activityMonitor.logComplete(activityId, response.status);
|
|
19108
19459
|
return result;
|
|
19109
19460
|
} catch (err) {
|
|
19110
|
-
const message =
|
|
19461
|
+
const message = errorMessage31(err);
|
|
19111
19462
|
const redactedMessage = redactCredential(message, apiKey);
|
|
19112
19463
|
if (redactedMessage.toLowerCase().includes("abort")) {
|
|
19113
19464
|
activityMonitor.logComplete(activityId, 0);
|
|
@@ -19123,7 +19474,7 @@ async function searchWithMistral(query, options = {}) {
|
|
|
19123
19474
|
|
|
19124
19475
|
// gemini-search.ts
|
|
19125
19476
|
init_utils();
|
|
19126
|
-
var RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek", "linkup", "ninerouter", "cloudflare", "searchapi", "tabstack"];
|
|
19477
|
+
var RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek", "linkup", "ninerouter", "cloudflare", "searchapi", "outcrawl", "sofya", "tabstack"];
|
|
19127
19478
|
var SEARCH_PROVIDERS = ["auto", "all", ...RESOLVED_SEARCH_PROVIDERS];
|
|
19128
19479
|
var SearchProviderError = class extends Error {
|
|
19129
19480
|
provider;
|
|
@@ -19139,7 +19490,7 @@ var SearchProviderError = class extends Error {
|
|
|
19139
19490
|
this.causeError = cause;
|
|
19140
19491
|
}
|
|
19141
19492
|
};
|
|
19142
|
-
var
|
|
19493
|
+
var CONFIG_PATH47 = getWebSearchConfigPath();
|
|
19143
19494
|
var DEFAULT_SEARCH_MODEL2 = "gemini-3.6-flash";
|
|
19144
19495
|
var ALL_SEARCH_PROVIDERS = ["searxng", "openai", "exa", "brave", "parallel", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "ollama", "perplexity", "gemini", "bocha"];
|
|
19145
19496
|
var VALID_ROUTING_KINDS = ["transient", "quota", "network", "invalid-response", "unsupported", "empty", "domain-miss", "off-topic"];
|
|
@@ -19147,11 +19498,11 @@ var MAX_ROUTING_TIMEOUT_MS = 6e5;
|
|
|
19147
19498
|
var cachedSearchConfig = null;
|
|
19148
19499
|
function getSearchConfig() {
|
|
19149
19500
|
if (cachedSearchConfig) return cachedSearchConfig;
|
|
19150
|
-
if (!
|
|
19501
|
+
if (!existsSync51(CONFIG_PATH47)) {
|
|
19151
19502
|
cachedSearchConfig = { searchProvider: "auto", searchProviderConfigured: false };
|
|
19152
19503
|
return cachedSearchConfig;
|
|
19153
19504
|
}
|
|
19154
|
-
const rawText =
|
|
19505
|
+
const rawText = readFileSync51(CONFIG_PATH47, "utf-8");
|
|
19155
19506
|
let raw;
|
|
19156
19507
|
try {
|
|
19157
19508
|
const parsed = JSON.parse(rawText);
|
|
@@ -19161,25 +19512,25 @@ function getSearchConfig() {
|
|
|
19161
19512
|
raw = parsed;
|
|
19162
19513
|
} catch (err) {
|
|
19163
19514
|
const message = err instanceof Error ? err.message : String(err);
|
|
19164
|
-
throw new Error(`Failed to parse ${
|
|
19515
|
+
throw new Error(`Failed to parse ${CONFIG_PATH47}: ${message}`);
|
|
19165
19516
|
}
|
|
19166
19517
|
const searchModel = normalizeSearchModel(raw.searchModel);
|
|
19167
19518
|
const webSearch = raw.webSearch;
|
|
19168
19519
|
if (webSearch !== void 0 && (!webSearch || typeof webSearch !== "object" || Array.isArray(webSearch))) {
|
|
19169
|
-
throw new Error(`webSearch in ${
|
|
19520
|
+
throw new Error(`webSearch in ${CONFIG_PATH47} must be an object`);
|
|
19170
19521
|
}
|
|
19171
|
-
const allowedProviders = webSearch && Object.hasOwn(webSearch, "allowedProviders") ? normalizeResolvedProviderList(webSearch.allowedProviders, `webSearch.allowedProviders in ${
|
|
19522
|
+
const allowedProviders = webSearch && Object.hasOwn(webSearch, "allowedProviders") ? normalizeResolvedProviderList(webSearch.allowedProviders, `webSearch.allowedProviders in ${CONFIG_PATH47}`) : void 0;
|
|
19172
19523
|
const searchProviderConfigured = Object.hasOwn(raw, "searchProvider") || Object.hasOwn(raw, "provider");
|
|
19173
|
-
const searchProvider2 = normalizeSearchProviderSelection(raw.searchProvider ?? raw.provider, `provider in ${
|
|
19524
|
+
const searchProvider2 = normalizeSearchProviderSelection(raw.searchProvider ?? raw.provider, `provider in ${CONFIG_PATH47}`);
|
|
19174
19525
|
const searchRouting = Object.hasOwn(raw, "searchRouting") ? normalizeSearchRouting(raw.searchRouting) : void 0;
|
|
19175
19526
|
if (allowedProviders) {
|
|
19176
19527
|
if (Object.hasOwn(raw, "searchProvider")) {
|
|
19177
|
-
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.searchProvider), `searchProvider in ${
|
|
19528
|
+
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.searchProvider), `searchProvider in ${CONFIG_PATH47}`, allowedProviders);
|
|
19178
19529
|
}
|
|
19179
19530
|
if (Object.hasOwn(raw, "provider")) {
|
|
19180
|
-
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.provider), `provider in ${
|
|
19531
|
+
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.provider), `provider in ${CONFIG_PATH47}`, allowedProviders);
|
|
19181
19532
|
}
|
|
19182
|
-
if (searchRouting) assertSearchProviderSelectionAllowed(searchRouting.providers, `searchRouting.providers in ${
|
|
19533
|
+
if (searchRouting) assertSearchProviderSelectionAllowed(searchRouting.providers, `searchRouting.providers in ${CONFIG_PATH47}`, allowedProviders);
|
|
19183
19534
|
}
|
|
19184
19535
|
cachedSearchConfig = {
|
|
19185
19536
|
searchProvider: searchProvider2,
|
|
@@ -19192,21 +19543,21 @@ function getSearchConfig() {
|
|
|
19192
19543
|
}
|
|
19193
19544
|
function normalizeSearchRouting(value) {
|
|
19194
19545
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
19195
|
-
throw new Error(`searchRouting in ${
|
|
19546
|
+
throw new Error(`searchRouting in ${CONFIG_PATH47} must be an object`);
|
|
19196
19547
|
}
|
|
19197
19548
|
const raw = value;
|
|
19198
|
-
const providers = normalizeResolvedProviderList(raw.providers, `searchRouting.providers in ${
|
|
19549
|
+
const providers = normalizeResolvedProviderList(raw.providers, `searchRouting.providers in ${CONFIG_PATH47}`);
|
|
19199
19550
|
const useCurrentModel = raw.useCurrentModel;
|
|
19200
19551
|
if (useCurrentModel !== void 0 && typeof useCurrentModel !== "boolean") {
|
|
19201
|
-
throw new Error(`searchRouting.useCurrentModel in ${
|
|
19552
|
+
throw new Error(`searchRouting.useCurrentModel in ${CONFIG_PATH47} must be a boolean`);
|
|
19202
19553
|
}
|
|
19203
19554
|
if (!Array.isArray(raw.fallbackOn) || raw.fallbackOn.length === 0) {
|
|
19204
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
19555
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH47} must be a non-empty array`);
|
|
19205
19556
|
}
|
|
19206
19557
|
const fallbackOn = [];
|
|
19207
19558
|
for (const kind of raw.fallbackOn) {
|
|
19208
19559
|
if (typeof kind !== "string" || !VALID_ROUTING_KINDS.includes(kind)) {
|
|
19209
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
19560
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH47} may only contain transient, quota, network, invalid-response, unsupported, empty, domain-miss, or off-topic`);
|
|
19210
19561
|
}
|
|
19211
19562
|
if (!fallbackOn.includes(kind)) {
|
|
19212
19563
|
fallbackOn.push(kind);
|
|
@@ -19214,14 +19565,14 @@ function normalizeSearchRouting(value) {
|
|
|
19214
19565
|
}
|
|
19215
19566
|
const timeoutMs = raw.timeoutMs;
|
|
19216
19567
|
if (timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > MAX_ROUTING_TIMEOUT_MS)) {
|
|
19217
|
-
throw new Error(`searchRouting.timeoutMs in ${
|
|
19568
|
+
throw new Error(`searchRouting.timeoutMs in ${CONFIG_PATH47} must be an integer from 1 through ${MAX_ROUTING_TIMEOUT_MS}`);
|
|
19218
19569
|
}
|
|
19219
19570
|
const offTopicModel = raw.offTopicModel;
|
|
19220
19571
|
if (offTopicModel !== void 0 && (typeof offTopicModel !== "string" || !Object.hasOwn(OFFTOPIC_JUDGE_MODELS, offTopicModel))) {
|
|
19221
|
-
throw new Error(`searchRouting.offTopicModel in ${
|
|
19572
|
+
throw new Error(`searchRouting.offTopicModel in ${CONFIG_PATH47} must be one of ${Object.keys(OFFTOPIC_JUDGE_MODELS).join(", ")}`);
|
|
19222
19573
|
}
|
|
19223
19574
|
if (fallbackOn.includes("off-topic") && offTopicModel === void 0) {
|
|
19224
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
19575
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH47} lists off-topic, which needs searchRouting.offTopicModel`);
|
|
19225
19576
|
}
|
|
19226
19577
|
return {
|
|
19227
19578
|
providers,
|
|
@@ -19318,11 +19669,11 @@ function validateSearchModelOverride(provider, model) {
|
|
|
19318
19669
|
assertSearchProviderSelectionAllowed(selected, "Requested provider");
|
|
19319
19670
|
return model.trim();
|
|
19320
19671
|
}
|
|
19321
|
-
function
|
|
19672
|
+
function errorMessage32(err) {
|
|
19322
19673
|
return err instanceof Error ? err.message : String(err);
|
|
19323
19674
|
}
|
|
19324
19675
|
function isAbortError3(err) {
|
|
19325
|
-
return
|
|
19676
|
+
return errorMessage32(err).toLowerCase().includes("abort");
|
|
19326
19677
|
}
|
|
19327
19678
|
async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
19328
19679
|
try {
|
|
@@ -19332,7 +19683,7 @@ async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
|
19332
19683
|
}
|
|
19333
19684
|
} catch (err) {
|
|
19334
19685
|
if (isAbortError3(err)) throw err;
|
|
19335
|
-
fallbackErrors.push(`OpenAI: ${
|
|
19686
|
+
fallbackErrors.push(`OpenAI: ${errorMessage32(err)}`);
|
|
19336
19687
|
}
|
|
19337
19688
|
return null;
|
|
19338
19689
|
}
|
|
@@ -19348,7 +19699,7 @@ async function searchWithGemini(query, options, strictErrors) {
|
|
|
19348
19699
|
if (apiResult) return apiResult;
|
|
19349
19700
|
} catch (err) {
|
|
19350
19701
|
if (err instanceof CredentialResolutionError || isAbortError3(err)) throw err;
|
|
19351
|
-
errors.push(`Gemini API: ${
|
|
19702
|
+
errors.push(`Gemini API: ${errorMessage32(err)}`);
|
|
19352
19703
|
}
|
|
19353
19704
|
try {
|
|
19354
19705
|
const webResult = await searchWithGeminiWeb(query, options);
|
|
@@ -19357,7 +19708,7 @@ async function searchWithGemini(query, options, strictErrors) {
|
|
|
19357
19708
|
if (diagnostic) errors.push(`Gemini Web: ${diagnostic}`);
|
|
19358
19709
|
} catch (err) {
|
|
19359
19710
|
if (isAbortError3(err)) throw err;
|
|
19360
|
-
errors.push(`Gemini Web: ${
|
|
19711
|
+
errors.push(`Gemini Web: ${errorMessage32(err)}`);
|
|
19361
19712
|
}
|
|
19362
19713
|
if (strictErrors && errors.length > 0) {
|
|
19363
19714
|
throw new Error(`Gemini search failed:
|
|
@@ -19372,7 +19723,7 @@ function providerErrorStatus(message) {
|
|
|
19372
19723
|
}
|
|
19373
19724
|
function classifyProviderError(provider, err) {
|
|
19374
19725
|
if (err instanceof SearchProviderError) return err;
|
|
19375
|
-
const message =
|
|
19726
|
+
const message = errorMessage32(err);
|
|
19376
19727
|
const lower = message.toLowerCase();
|
|
19377
19728
|
const status = providerErrorStatus(message);
|
|
19378
19729
|
const openAIStreamError = provider === "openai" && lower.includes("openai api stream error");
|
|
@@ -19454,6 +19805,8 @@ async function searchWithResolvedProvider(provider, query, options, useCurrentMo
|
|
|
19454
19805
|
if (provider === "ninerouter") return { ...await searchWithNineRouter(query, options), provider };
|
|
19455
19806
|
if (provider === "cloudflare") return { ...await searchWithCloudflare(query, options), provider };
|
|
19456
19807
|
if (provider === "searchapi") return { ...await searchWithSearchApi(query, options), provider };
|
|
19808
|
+
if (provider === "outcrawl") return { ...await searchWithOutcrawl(query, options), provider };
|
|
19809
|
+
if (provider === "sofya") return { ...await searchWithSofya(query, options), provider };
|
|
19457
19810
|
if (provider === "deepseek") return { ...await searchWithDeepSeek(query, options), provider };
|
|
19458
19811
|
if (provider === "xcrawl") return { ...await searchWithXCrawl(query, options), provider };
|
|
19459
19812
|
if (provider === "perplexity") return { ...await searchWithPerplexity(query, options), provider };
|
|
@@ -19466,7 +19819,7 @@ async function searchWithResolvedProvider(provider, query, options, useCurrentMo
|
|
|
19466
19819
|
if (result) return { ...result, provider };
|
|
19467
19820
|
throw new Error(
|
|
19468
19821
|
`Gemini search unavailable. Either:
|
|
19469
|
-
1. Configure geminiApiKey in ${
|
|
19822
|
+
1. Configure geminiApiKey in ${CONFIG_PATH47} or set GEMINI_API_KEY
|
|
19470
19823
|
2. Set GOOGLE_GEMINI_BASE_URL + CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing
|
|
19471
19824
|
3. Set geminiAuth to "adc" in web-search.json with a Google Cloud ADC + project/location
|
|
19472
19825
|
4. Sign into gemini.google.com in a supported Chromium-based browser`
|
|
@@ -19511,6 +19864,8 @@ async function isResolvedProviderAvailable(provider, options, useCurrentModel =
|
|
|
19511
19864
|
if (provider === "ninerouter") return isNineRouterAvailable();
|
|
19512
19865
|
if (provider === "cloudflare") return isCloudflareSearchAvailable();
|
|
19513
19866
|
if (provider === "searchapi") return isSearchApiAvailable();
|
|
19867
|
+
if (provider === "outcrawl") return isOutcrawlAvailable();
|
|
19868
|
+
if (provider === "sofya") return isSofyaAvailable();
|
|
19514
19869
|
if (provider === "deepseek") return isDeepSeekAvailable();
|
|
19515
19870
|
if (provider === "xcrawl") return isXcrawlAvailable();
|
|
19516
19871
|
if (provider === "perplexity") return isPerplexityAvailable();
|
|
@@ -19563,6 +19918,8 @@ function providerLabel(provider) {
|
|
|
19563
19918
|
if (provider === "ninerouter") return "9router";
|
|
19564
19919
|
if (provider === "cloudflare") return "Cloudflare";
|
|
19565
19920
|
if (provider === "searchapi") return "SearchApi";
|
|
19921
|
+
if (provider === "outcrawl") return "Outcrawl";
|
|
19922
|
+
if (provider === "sofya") return "Sofya";
|
|
19566
19923
|
if (provider === "deepseek") return "DeepSeek";
|
|
19567
19924
|
return provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
19568
19925
|
}
|
|
@@ -19579,7 +19936,7 @@ async function searchWithProviders(query, options, selectedProviders, routing) {
|
|
|
19579
19936
|
available: provider === "gemini" ? isGeminiApiAvailable() : await isResolvedProviderAvailable(provider, options)
|
|
19580
19937
|
})))).filter((entry) => entry.available).map((entry) => entry.provider);
|
|
19581
19938
|
if (providers.length === 0) {
|
|
19582
|
-
throw new Error('No configured search provider available for provider "all". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, DeepSeek, Linkup, 9router, Cloudflare, SearchApi, and Tabstack are excluded.');
|
|
19939
|
+
throw new Error('No configured search provider available for provider "all". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, DeepSeek, Linkup, 9router, Cloudflare, SearchApi, Outcrawl, Sofya, and Tabstack are excluded.');
|
|
19583
19940
|
}
|
|
19584
19941
|
const settled = await Promise.allSettled(
|
|
19585
19942
|
providers.map((provider) => selectedProviders ? searchWithResolvedProvider(provider, query, options) : searchWithAllProvider(provider, query, options))
|
|
@@ -19592,7 +19949,7 @@ async function searchWithProviders(query, options, selectedProviders, routing) {
|
|
|
19592
19949
|
if (outcome.status === "fulfilled") {
|
|
19593
19950
|
successes.push(outcome.value);
|
|
19594
19951
|
} else {
|
|
19595
|
-
failures.push({ provider: providers[index], error:
|
|
19952
|
+
failures.push({ provider: providers[index], error: errorMessage32(outcome.reason) });
|
|
19596
19953
|
}
|
|
19597
19954
|
}
|
|
19598
19955
|
if (successes.length === 0) {
|
|
@@ -19609,7 +19966,7 @@ async function searchWithProviders(query, options, selectedProviders, routing) {
|
|
|
19609
19966
|
} catch (err) {
|
|
19610
19967
|
if (isAbortError3(err)) throw err;
|
|
19611
19968
|
throw new Error(`${failureMessage}
|
|
19612
|
-
${
|
|
19969
|
+
${errorMessage32(err)}`);
|
|
19613
19970
|
}
|
|
19614
19971
|
}
|
|
19615
19972
|
const results = [];
|
|
@@ -19709,7 +20066,7 @@ async function searchWithConfiguredRouting(query, callerOptions, routing) {
|
|
|
19709
20066
|
break;
|
|
19710
20067
|
}
|
|
19711
20068
|
const classified = classifyProviderError(provider, err);
|
|
19712
|
-
diagnostics.push(`${provider} [${classified.kind}]: ${
|
|
20069
|
+
diagnostics.push(`${provider} [${classified.kind}]: ${errorMessage32(err)}`);
|
|
19713
20070
|
if (!routing.fallbackOn.includes(classified.kind)) {
|
|
19714
20071
|
throw classified;
|
|
19715
20072
|
}
|
|
@@ -19749,7 +20106,7 @@ async function search(query, options = {}) {
|
|
|
19749
20106
|
return take(await searchWithResolvedProvider(provider2, query, options), provider2);
|
|
19750
20107
|
} catch (err) {
|
|
19751
20108
|
if (isAbortError3(err)) throw err;
|
|
19752
|
-
fallbackErrors.push(`${providerLabel(provider2)}: ${
|
|
20109
|
+
fallbackErrors.push(`${providerLabel(provider2)}: ${errorMessage32(err)}`);
|
|
19753
20110
|
return null;
|
|
19754
20111
|
}
|
|
19755
20112
|
};
|
|
@@ -19767,7 +20124,7 @@ async function search(query, options = {}) {
|
|
|
19767
20124
|
if (response) return response;
|
|
19768
20125
|
} catch (err) {
|
|
19769
20126
|
if (err instanceof CredentialResolutionError || isAbortError3(err)) throw err;
|
|
19770
|
-
fallbackErrors.push(`Exa: ${
|
|
20127
|
+
fallbackErrors.push(`Exa: ${errorMessage32(err)}`);
|
|
19771
20128
|
}
|
|
19772
20129
|
}
|
|
19773
20130
|
if (allowed.has("openai") && !triedOpenAI) {
|
|
@@ -19783,7 +20140,7 @@ async function search(query, options = {}) {
|
|
|
19783
20140
|
if (response) return response;
|
|
19784
20141
|
} catch (err) {
|
|
19785
20142
|
if (isAbortError3(err)) throw err;
|
|
19786
|
-
fallbackErrors.push(`Gemini: ${
|
|
20143
|
+
fallbackErrors.push(`Gemini: ${errorMessage32(err)}`);
|
|
19787
20144
|
}
|
|
19788
20145
|
if (firstEmpty) return firstEmpty;
|
|
19789
20146
|
if (fallbackErrors.length > 0) {
|
|
@@ -19793,11 +20150,11 @@ async function search(query, options = {}) {
|
|
|
19793
20150
|
throw new Error(
|
|
19794
20151
|
`No search provider available. Either:
|
|
19795
20152
|
1. Use /login to sign in with a Codex subscription for OpenAI web search
|
|
19796
|
-
2. Set openaiApiKey, braveApiKey, parallelApiKey, tinyfishApiKey, search1apiApiKey, searchinfinityApiKey, queritApiKey, tavilyApiKey, firecrawlBaseUrl, jinaApiKey, serpdiveApiKey, kagiApiKey, ollamaApiKey, searxngBaseUrl, perplexityApiKey, exaApiKey, geminiApiKey, bochaApiKey, or cloudflareApiKey in ${
|
|
20153
|
+
2. Set openaiApiKey, braveApiKey, parallelApiKey, tinyfishApiKey, search1apiApiKey, searchinfinityApiKey, queritApiKey, tavilyApiKey, firecrawlBaseUrl, jinaApiKey, serpdiveApiKey, kagiApiKey, ollamaApiKey, searxngBaseUrl, perplexityApiKey, exaApiKey, geminiApiKey, bochaApiKey, or cloudflareApiKey in ${CONFIG_PATH47}
|
|
19797
20154
|
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
|
|
19798
20155
|
4. Set GOOGLE_GEMINI_BASE_URL with CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing
|
|
19799
20156
|
5. Sign into gemini.google.com in a supported Chromium-based browser
|
|
19800
|
-
6. Explicitly select provider: "anysearch" for anonymous AnySearch, "xcrawl" for XCrawl, "xai" for Grok, "mistral" for Mistral Conversations web search, "brightdata" with brightdataSerpZone for paid Bright Data SERP, "serpbase", "serpapi", "serper", or "serply" for Google SERP, "you" for You.com, "zai" for Z.ai GLM Coding Plan search, "valyu" for research search, "keenable" for keyless Keenable search, "ceramic" for Ceramic search, "deepseek" for DeepSeek search, "linkup" for Linkup search, "ninerouter" for a 9router gateway, "cloudflare" for the Cloudflare Web Search API, "searchapi" for SearchApi Google search, or "tabstack" for Tabstack Research`
|
|
20157
|
+
6. Explicitly select provider: "anysearch" for anonymous AnySearch, "xcrawl" for XCrawl, "xai" for Grok, "mistral" for Mistral Conversations web search, "brightdata" with brightdataSerpZone for paid Bright Data SERP, "serpbase", "serpapi", "serper", or "serply" for Google SERP, "you" for You.com, "zai" for Z.ai GLM Coding Plan search, "valyu" for research search, "keenable" for keyless Keenable search, "ceramic" for Ceramic search, "deepseek" for DeepSeek search, "linkup" for Linkup search, "ninerouter" for a 9router gateway, "cloudflare" for the Cloudflare Web Search API, "searchapi" for SearchApi Google search, "outcrawl" for Outcrawl search, "sofya" for Sofya search, or "tabstack" for Tabstack Research`
|
|
19801
20158
|
);
|
|
19802
20159
|
}
|
|
19803
20160
|
async function searchWithGeminiApi(query, options = {}) {
|
|
@@ -19945,7 +20302,7 @@ init_utils();
|
|
|
19945
20302
|
|
|
19946
20303
|
// storage.ts
|
|
19947
20304
|
init_utils();
|
|
19948
|
-
import { closeSync as closeSync2, constants, fchmodSync, fstatSync as fstatSync2, fsyncSync, lstatSync as lstatSync2, mkdirSync as mkdirSync2, openSync as openSync2, readFileSync as
|
|
20305
|
+
import { closeSync as closeSync2, constants, fchmodSync, fstatSync as fstatSync2, fsyncSync, lstatSync as lstatSync2, mkdirSync as mkdirSync2, openSync as openSync2, readFileSync as readFileSync52, readdirSync as readdirSync3, renameSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
19949
20306
|
import { randomBytes } from "node:crypto";
|
|
19950
20307
|
import { join as join5 } from "node:path";
|
|
19951
20308
|
var CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
@@ -20235,7 +20592,7 @@ function readCachedFetchData(data) {
|
|
|
20235
20592
|
const opened = openRegularFile(path);
|
|
20236
20593
|
fd = opened.fd;
|
|
20237
20594
|
enforceMode(fd, 384);
|
|
20238
|
-
const parsed = JSON.parse(
|
|
20595
|
+
const parsed = JSON.parse(readFileSync52(fd, "utf8"));
|
|
20239
20596
|
if (!isValidStoredData(parsed) || parsed.type !== "fetch" || parsed.id !== data.id || !isInlineFetchData(parsed)) {
|
|
20240
20597
|
return unavailableFetchData(data, "Cached fetched content is invalid");
|
|
20241
20598
|
}
|
|
@@ -20419,6 +20776,8 @@ function buildProviderButtons(available, selected, hasInitialQueries) {
|
|
|
20419
20776
|
{ value: "ninerouter", label: "9router", available: available.ninerouter },
|
|
20420
20777
|
{ value: "cloudflare", label: "Cloudflare", available: available.cloudflare },
|
|
20421
20778
|
{ value: "searchapi", label: "SearchApi", available: available.searchapi },
|
|
20779
|
+
{ value: "outcrawl", label: "Outcrawl", available: available.outcrawl },
|
|
20780
|
+
{ value: "sofya", label: "Sofya", available: available.sofya },
|
|
20422
20781
|
{ value: "tabstack", label: "Tabstack", available: available.tabstack },
|
|
20423
20782
|
{ value: "deepseek", label: "DeepSeek", available: available.deepseek }
|
|
20424
20783
|
];
|
|
@@ -21835,7 +22194,7 @@ var SCRIPT = `(function() {
|
|
|
21835
22194
|
var token = DATA.sessionToken;
|
|
21836
22195
|
var timeoutSec = DATA.timeout;
|
|
21837
22196
|
var queries = Array.isArray(DATA.queries) ? DATA.queries : [];
|
|
21838
|
-
var providers = ["auto", "all", "openai", "exa", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "bocha", "ollama", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "anysearch", "xcrawl", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "baizhi", "you", "zai", "keenable", "ceramic", "deepseek", "linkup", "ninerouter", "cloudflare", "searchapi", "tabstack"];
|
|
22197
|
+
var providers = ["auto", "all", "openai", "exa", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "bocha", "ollama", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "anysearch", "xcrawl", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "baizhi", "you", "zai", "keenable", "ceramic", "deepseek", "linkup", "ninerouter", "cloudflare", "searchapi", "outcrawl", "sofya", "tabstack"];
|
|
21839
22198
|
var availProviders = DATA.availableProviders && typeof DATA.availableProviders === "object" ? DATA.availableProviders : {};
|
|
21840
22199
|
var workflow = "summary-review";
|
|
21841
22200
|
var initialDefaultProvider = typeof DATA.defaultProvider === "string" ? DATA.defaultProvider : "exa";
|
|
@@ -22082,6 +22441,8 @@ var SCRIPT = `(function() {
|
|
|
22082
22441
|
if (provider === "ninerouter") return "9router";
|
|
22083
22442
|
if (provider === "cloudflare") return "Cloudflare";
|
|
22084
22443
|
if (provider === "searchapi") return "SearchApi";
|
|
22444
|
+
if (provider === "outcrawl") return "Outcrawl";
|
|
22445
|
+
if (provider === "sofya") return "Sofya";
|
|
22085
22446
|
if (provider === "deepseek") return "DeepSeek";
|
|
22086
22447
|
return "Unknown";
|
|
22087
22448
|
}
|
|
@@ -24201,6 +24562,8 @@ function startCuratorServer(options, callbacks) {
|
|
|
24201
24562
|
if (provider === "ninerouter") return availableProviders.ninerouter;
|
|
24202
24563
|
if (provider === "cloudflare") return availableProviders.cloudflare;
|
|
24203
24564
|
if (provider === "searchapi") return availableProviders.searchapi;
|
|
24565
|
+
if (provider === "outcrawl") return availableProviders.outcrawl;
|
|
24566
|
+
if (provider === "sofya") return availableProviders.sofya;
|
|
24204
24567
|
if (provider === "deepseek") return availableProviders.deepseek;
|
|
24205
24568
|
return false;
|
|
24206
24569
|
}
|
|
@@ -24640,7 +25003,7 @@ import { randomUUID as randomUUID3 } from "node:crypto";
|
|
|
24640
25003
|
import { execFileSync as execFileSync3, spawn as spawn3 } from "node:child_process";
|
|
24641
25004
|
import { createRequire } from "node:module";
|
|
24642
25005
|
import { platform } from "node:os";
|
|
24643
|
-
import { existsSync as
|
|
25006
|
+
import { existsSync as existsSync64, readFileSync as readFileSync65, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4 } from "node:fs";
|
|
24644
25007
|
import { join as join9 } from "node:path";
|
|
24645
25008
|
init_parallel();
|
|
24646
25009
|
init_parallel_mcp();
|
|
@@ -24925,8 +25288,8 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
|
24925
25288
|
// package.json
|
|
24926
25289
|
var package_default = {
|
|
24927
25290
|
name: "pi-web-access",
|
|
24928
|
-
version: "0.
|
|
24929
|
-
description: "Web search, URL fetching, GitHub repo cloning, PDF extraction, YouTube video understanding, and local video analysis for Pi coding agent. Supports OpenAI, Brave, Parallel, TinyFish, Search1API, Searchinfinity, Querit, Tavily, Firecrawl, Crawl4AI, Jina, SERPdive, Kagi, Ollama, AnySearch, Bright Data SERP, SerpBase, SerpApi, Serply, SearchApi, You.com, SearXNG, degoog, Exa, Perplexity, Gemini, Kimi, Mistral, and Tabstack.",
|
|
25291
|
+
version: "0.47.0",
|
|
25292
|
+
description: "Web search, URL fetching, GitHub repo cloning, PDF extraction, YouTube video understanding, and local video analysis for Pi coding agent. Supports OpenAI, Brave, Parallel, TinyFish, Search1API, Searchinfinity, Querit, Tavily, Firecrawl, Crawl4AI, Jina, SERPdive, Kagi, Ollama, AnySearch, Bright Data SERP, SerpBase, SerpApi, Serply, SearchApi, Outcrawl, Sofya, You.com, SearXNG, degoog, Exa, Perplexity, Gemini, Kimi, Mistral, and Tabstack.",
|
|
24930
25293
|
type: "module",
|
|
24931
25294
|
bin: {
|
|
24932
25295
|
"pi-web-access-mcp": "dist/mcp-cli.js"
|
|
@@ -25053,7 +25416,7 @@ async function showUpgradeNotice(ctx, stateDir = join6(getAgentDir(), "pi-web-ac
|
|
|
25053
25416
|
}
|
|
25054
25417
|
|
|
25055
25418
|
// web-tool-core.ts
|
|
25056
|
-
import { existsSync as
|
|
25419
|
+
import { existsSync as existsSync63, readFileSync as readFileSync64 } from "node:fs";
|
|
25057
25420
|
import pLimit2 from "p-limit";
|
|
25058
25421
|
init_auth_fetch();
|
|
25059
25422
|
|
|
@@ -25743,9 +26106,9 @@ function parseConfigRoot(raw) {
|
|
|
25743
26106
|
}
|
|
25744
26107
|
return parsed;
|
|
25745
26108
|
}
|
|
25746
|
-
function
|
|
25747
|
-
if (!
|
|
25748
|
-
return parseConfigRoot(
|
|
26109
|
+
function loadConfig48() {
|
|
26110
|
+
if (!existsSync63(WEB_SEARCH_CONFIG_PATH4)) return {};
|
|
26111
|
+
return parseConfigRoot(readFileSync64(WEB_SEARCH_CONFIG_PATH4, "utf-8"));
|
|
25749
26112
|
}
|
|
25750
26113
|
var DEFAULT_TOOL_NAMES = {
|
|
25751
26114
|
webSearch: "web_search",
|
|
@@ -25800,7 +26163,7 @@ function resolveRequestedProvider(requested) {
|
|
|
25800
26163
|
assertSearchProviderSelectionAllowed(normalizedRequested, "Requested provider");
|
|
25801
26164
|
return normalizedRequested;
|
|
25802
26165
|
}
|
|
25803
|
-
const config =
|
|
26166
|
+
const config = loadConfig48();
|
|
25804
26167
|
const provider = normalizeProviderInput(config.searchProvider ?? config.provider, `provider in ${WEB_SEARCH_CONFIG_PATH4}`) ?? "auto";
|
|
25805
26168
|
assertSearchProviderSelectionAllowed(provider, `configured provider in ${WEB_SEARCH_CONFIG_PATH4}`);
|
|
25806
26169
|
return provider;
|
|
@@ -25863,7 +26226,7 @@ function isAbortError7(err) {
|
|
|
25863
26226
|
var DEFAULT_MAX_INLINE_CONTENT_CHARS = 3e4;
|
|
25864
26227
|
var MIN_INLINE_CONTENT_CHARS = 1e3;
|
|
25865
26228
|
var MAX_INLINE_CONTENT_CHARS = 2e5;
|
|
25866
|
-
function getMaxInlineContentChars(config =
|
|
26229
|
+
function getMaxInlineContentChars(config = loadConfig48()) {
|
|
25867
26230
|
const value = config.maxInlineContentChars;
|
|
25868
26231
|
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < MIN_INLINE_CONTENT_CHARS) {
|
|
25869
26232
|
return DEFAULT_MAX_INLINE_CONTENT_CHARS;
|
|
@@ -27003,12 +27366,12 @@ function renderSearchErrorPlan(plan, expanded, theme) {
|
|
|
27003
27366
|
}
|
|
27004
27367
|
function saveConfig(updates) {
|
|
27005
27368
|
let config = {};
|
|
27006
|
-
if (
|
|
27007
|
-
config = parseConfigRoot(
|
|
27369
|
+
if (existsSync64(WEB_SEARCH_CONFIG_PATH4)) {
|
|
27370
|
+
config = parseConfigRoot(readFileSync65(WEB_SEARCH_CONFIG_PATH4, "utf-8"));
|
|
27008
27371
|
}
|
|
27009
27372
|
Object.assign(config, updates);
|
|
27010
27373
|
const dir = getWebSearchConfigDir();
|
|
27011
|
-
if (!
|
|
27374
|
+
if (!existsSync64(dir)) mkdirSync4(dir, { recursive: true });
|
|
27012
27375
|
writeFileSync4(WEB_SEARCH_CONFIG_PATH4, JSON.stringify(config, null, 2) + "\n");
|
|
27013
27376
|
}
|
|
27014
27377
|
var TOOL_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
@@ -27060,7 +27423,7 @@ function resolveToolNames(config) {
|
|
|
27060
27423
|
}
|
|
27061
27424
|
function loadConfigForExtensionInit() {
|
|
27062
27425
|
try {
|
|
27063
|
-
return
|
|
27426
|
+
return loadConfig48();
|
|
27064
27427
|
} catch (err) {
|
|
27065
27428
|
const message = err instanceof Error ? err.message : String(err);
|
|
27066
27429
|
console.error(`[pi-web-access] ${message}`);
|
|
@@ -27079,26 +27442,26 @@ function normalizeCuratorTimeoutSeconds(value) {
|
|
|
27079
27442
|
return Math.min(normalized, MAX_CURATOR_TIMEOUT_SECONDS);
|
|
27080
27443
|
}
|
|
27081
27444
|
function getCuratorTimeoutSeconds() {
|
|
27082
|
-
const source =
|
|
27445
|
+
const source = loadConfig48();
|
|
27083
27446
|
const explicit = normalizeCuratorTimeoutSeconds(source.curatorTimeoutSeconds);
|
|
27084
27447
|
if (explicit !== void 0) return explicit;
|
|
27085
27448
|
return resolveCuratorNetworkConfig().enabled ? DEFAULT_REMOTE_CURATOR_TIMEOUT_SECONDS : DEFAULT_CURATOR_TIMEOUT_SECONDS;
|
|
27086
27449
|
}
|
|
27087
27450
|
function getSummaryGenerationDeadlineMs() {
|
|
27088
|
-
const value =
|
|
27451
|
+
const value = loadConfig48().summaryGenerationDeadlineMs;
|
|
27089
27452
|
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {
|
|
27090
27453
|
return SUMMARY_GENERATION_DEADLINE_MS;
|
|
27091
27454
|
}
|
|
27092
27455
|
return Math.min(value, MAX_SUMMARY_GENERATION_DEADLINE_MS);
|
|
27093
27456
|
}
|
|
27094
27457
|
function getSummaryInstructions() {
|
|
27095
|
-
const value =
|
|
27458
|
+
const value = loadConfig48().summaryInstructions;
|
|
27096
27459
|
if (typeof value !== "string") return void 0;
|
|
27097
27460
|
const trimmed = value.trim();
|
|
27098
27461
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
27099
27462
|
}
|
|
27100
27463
|
function readHelperModelKey(key) {
|
|
27101
|
-
const value =
|
|
27464
|
+
const value = loadConfig48()[key];
|
|
27102
27465
|
if (value === void 0) return void 0;
|
|
27103
27466
|
const message = `${key} in ${WEB_SEARCH_CONFIG_PATH4} must be "current", "current:<level>", or "provider/model-id[:<level>]"`;
|
|
27104
27467
|
if (typeof value !== "string") throw new Error(message);
|
|
@@ -27161,6 +27524,8 @@ async function getProviderAvailability(ctx) {
|
|
|
27161
27524
|
ninerouter: allowedProviders.has("ninerouter") && isNineRouterAvailable(),
|
|
27162
27525
|
cloudflare: allowedProviders.has("cloudflare") && isCloudflareSearchAvailable(),
|
|
27163
27526
|
searchapi: allowedProviders.has("searchapi") && isSearchApiAvailable(),
|
|
27527
|
+
outcrawl: allowedProviders.has("outcrawl") && isOutcrawlAvailable(),
|
|
27528
|
+
sofya: allowedProviders.has("sofya") && isSofyaAvailable(),
|
|
27164
27529
|
deepseek: allowedProviders.has("deepseek") && isDeepSeekAvailable()
|
|
27165
27530
|
};
|
|
27166
27531
|
return {
|
|
@@ -27307,7 +27672,7 @@ function findGlimpseMjs() {
|
|
|
27307
27672
|
try {
|
|
27308
27673
|
const globalRoot = execFileSync3("npm", ["root", "-g"], { encoding: "utf-8" }).trim();
|
|
27309
27674
|
const entry = join9(globalRoot, "glimpseui", "src", "glimpse.mjs");
|
|
27310
|
-
if (
|
|
27675
|
+
if (existsSync64(entry)) return entry;
|
|
27311
27676
|
} catch {
|
|
27312
27677
|
}
|
|
27313
27678
|
return null;
|
|
@@ -27942,7 +28307,7 @@ Open manually: ${handle.url}` }],
|
|
|
27942
28307
|
shortcut: curateKey
|
|
27943
28308
|
}
|
|
27944
28309
|
});
|
|
27945
|
-
if (!shouldAutoOpenCuratorBrowser(
|
|
28310
|
+
if (!shouldAutoOpenCuratorBrowser(loadConfig48())) {
|
|
27946
28311
|
sendCuratorFallbackUpdate("Search curator is running. Open the curator URL manually.");
|
|
27947
28312
|
return;
|
|
27948
28313
|
}
|
|
@@ -28046,7 +28411,7 @@ Open manually: ${handle.url}` }],
|
|
|
28046
28411
|
description: "Default none; summary-review opens the curator; auto-summary summarizes"
|
|
28047
28412
|
})
|
|
28048
28413
|
),
|
|
28049
|
-
proxy: Type2.Optional(Type2.String({ description: '
|
|
28414
|
+
proxy: Type2.Optional(Type2.String({ description: 'Proxy URL; omit by default (env proxy vars ignored); "" forces direct' }))
|
|
28050
28415
|
}),
|
|
28051
28416
|
outputSchema: webSearchOutputSchema,
|
|
28052
28417
|
exposure: toolExposure,
|
|
@@ -28505,7 +28870,7 @@ Open manually: ${handle.url}` }],
|
|
|
28505
28870
|
recencyFilter: Type2.Optional(StringEnum(["day", "week", "month", "year"])),
|
|
28506
28871
|
domainFilter: Type2.Optional(Type2.Array(Type2.String(), { description: "Prefix - to exclude" })),
|
|
28507
28872
|
provider: Type2.Optional(Type2.String({ description: providerDescription })),
|
|
28508
|
-
proxy: Type2.Optional(Type2.String({ description: '
|
|
28873
|
+
proxy: Type2.Optional(Type2.String({ description: 'Proxy URL; omit by default; "" forces direct' }))
|
|
28509
28874
|
}),
|
|
28510
28875
|
exposure: toolExposure,
|
|
28511
28876
|
async execute(_callId, params, signal, _onUpdate, ctx) {
|
|
@@ -28549,7 +28914,7 @@ Open manually: ${handle.url}` }],
|
|
|
28549
28914
|
auth: Type2.Optional(Type2.Union([Type2.String(), Type2.Boolean()], {
|
|
28550
28915
|
description: "authFetch profile name, or true for the only one"
|
|
28551
28916
|
})),
|
|
28552
|
-
proxy: Type2.Optional(Type2.String({ description: '
|
|
28917
|
+
proxy: Type2.Optional(Type2.String({ description: 'Proxy URL; omit by default; "" forces direct' })),
|
|
28553
28918
|
redirects: Type2.Optional(StringEnum(["same-origin"], {
|
|
28554
28919
|
description: "Refuse cross-origin redirects"
|
|
28555
28920
|
}))
|
|
@@ -28767,7 +29132,7 @@ Open manually: ${handle.url}` }],
|
|
|
28767
29132
|
const initialProvider = bootstrap.defaultProvider;
|
|
28768
29133
|
const curatorTimeoutSeconds = bootstrap.timeoutSeconds;
|
|
28769
29134
|
let currentProvider = initialProvider;
|
|
28770
|
-
const commandConfig =
|
|
29135
|
+
const commandConfig = loadConfig48();
|
|
28771
29136
|
const rawSearchProvider = normalizeProviderInput(
|
|
28772
29137
|
commandConfig.searchProvider ?? commandConfig.provider ?? "auto",
|
|
28773
29138
|
`provider in ${WEB_SEARCH_CONFIG_PATH4}`
|
|
@@ -28913,7 +29278,7 @@ Open manually: ${handle.url}` }],
|
|
|
28913
29278
|
commandHandle = handle;
|
|
28914
29279
|
activeCurators.set(commandCallId, handle);
|
|
28915
29280
|
let browserOpenError = null;
|
|
28916
|
-
if (!shouldAutoOpenCuratorBrowser(
|
|
29281
|
+
if (!shouldAutoOpenCuratorBrowser(loadConfig48())) {
|
|
28917
29282
|
ctx.ui.notify(`Search curator is running. Open manually: ${handle.url}`, "info");
|
|
28918
29283
|
} else {
|
|
28919
29284
|
const open = platform() === "darwin" ? await getGlimpseOpen() : null;
|