@herbertgao/pi-extensions 2026.10.14 → 2026.10.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/THIRD_PARTY_NOTICES.md +3 -3
- 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/config/config.ts +38 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +13 -9
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/default-mode.ts +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-highlight.ts +41 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/write-execution.ts +42 -25
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/node_modules/@narumitw/pi-btw/README.md +1 -1
- package/node_modules/@narumitw/pi-btw/dist/index.ts +77 -64
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +2 -2
- package/node_modules/@narumitw/pi-btw/docs/core-alignment.md +10 -2
- package/node_modules/@narumitw/pi-btw/package.json +5 -5
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +83 -63
- package/node_modules/@narumitw/pi-caffeinate/package.json +3 -3
- package/node_modules/pi-lens/CHANGELOG.md +37 -0
- package/node_modules/pi-lens/README.md +32 -0
- package/node_modules/pi-lens/config/biome/core.jsonc +3 -3
- package/node_modules/pi-lens/dist/{chunk-K2GUZ4DN.js → chunk-2DDDCJDL.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-DS2USX5G.js → chunk-2DMLM3ZO.js} +11 -11
- package/node_modules/pi-lens/dist/chunk-2F47TQOA.js +73 -0
- package/node_modules/pi-lens/dist/{chunk-YXDCRUKQ.js → chunk-2PHMIAKO.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-PP2A5V2T.js → chunk-2RLWJO5K.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-T4NGVFYI.js → chunk-2X4VLOCC.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-QT66NEYN.js → chunk-3MYEA7QD.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-7ZS7MC24.js → chunk-3WEPUD2V.js} +22 -22
- package/node_modules/pi-lens/dist/{chunk-TL2TCJYL.js → chunk-4AVZ3TG7.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-SNEUMLM7.js → chunk-4PCQCU47.js} +4 -4
- package/node_modules/pi-lens/dist/chunk-4WX4CTUE.js +57 -0
- package/node_modules/pi-lens/dist/{chunk-5LRUKYFA.js → chunk-5APMQ2IJ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-4U7GDSZQ.js → chunk-5CV5ITZF.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-VUAVE3QC.js → chunk-5ZR3APIM.js} +36 -36
- package/node_modules/pi-lens/dist/{chunk-CPZ5JJW6.js → chunk-63RIVFQI.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-EDMLIW6W.js → chunk-75SY4F24.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-RCHO5W7M.js → chunk-7RQXA5GG.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-XHDBJODR.js → chunk-A3YNG5KP.js} +21 -21
- package/node_modules/pi-lens/dist/{chunk-3WCEHYOI.js → chunk-AE37FEGH.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-KPVLQHCZ.js → chunk-AMXIUN2R.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-XI34NWDI.js → chunk-ARD426WI.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-RG3MXTRI.js → chunk-BHUWL2Y3.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-4ODSZ35Z.js → chunk-BI5LAQ3Y.js} +44 -44
- package/node_modules/pi-lens/dist/{chunk-Q42LJANT.js → chunk-BM5GS6ZH.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-CG5V25HX.js → chunk-BWYQUPOS.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-HYVXA3BB.js → chunk-CFRQMBGP.js} +23 -23
- package/node_modules/pi-lens/dist/{chunk-NLIVE7L6.js → chunk-CJYKEW2L.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-MEFLGBCS.js → chunk-DC4CFXM5.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-ASRAO7KG.js → chunk-DMSLNKF7.js} +27 -27
- package/node_modules/pi-lens/dist/{chunk-YSDPVDFC.js → chunk-DQXSPYRI.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-YKVDBNPO.js → chunk-EVDGNG4F.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2LDMXL2M.js → chunk-F5Z6URKM.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-72J27ICO.js → chunk-F6X3YJWD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-YXGRRORB.js → chunk-FA5LDARD.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-OMJ3OFBJ.js → chunk-FFL3A2VP.js} +6 -6
- package/node_modules/pi-lens/dist/chunk-FJIVKLPH.js +31 -0
- package/node_modules/pi-lens/dist/chunk-G2B7F6ZU.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-YWWG4AQA.js → chunk-GAACZY6R.js} +24 -25
- package/node_modules/pi-lens/dist/{chunk-F7BO6FWH.js → chunk-GMTFDAOK.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-UVY4TOJH.js → chunk-GNSIWBAT.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-GTAI2J6U.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-SJHC3BCZ.js → chunk-GZE7WOI4.js} +98 -111
- package/node_modules/pi-lens/dist/{chunk-ZAPSUBLU.js → chunk-H7HTEQUZ.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-ZPJM7DID.js → chunk-HK6JVFZC.js} +3 -3
- package/node_modules/pi-lens/dist/chunk-IPDG45G5.js +26 -0
- package/node_modules/pi-lens/dist/{chunk-ZSUX7KEM.js → chunk-J6JP25XU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6XSESGWD.js → chunk-JL6CXUMW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-Y5KTA2OB.js → chunk-K2YGBXOA.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-AHWA4AKM.js → chunk-KLQVC3XC.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-27VWVB23.js → chunk-KSR7RGQY.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-N3PLNNCW.js → chunk-KXF5R4UN.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-GLW3YDZZ.js → chunk-LEJOJDXL.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-Y2TPADJR.js → chunk-MA77RSFN.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-IL7K66ZQ.js → chunk-MKVZQUEG.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-EIKRZ32J.js → chunk-MN7MHUXQ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-4FHUGDKU.js → chunk-MT6BVNFW.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-3SNDVPOR.js → chunk-NDMCVUYK.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-63NMUNYP.js → chunk-NIU2IPC5.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-APFJKOP6.js → chunk-NNKXDXXS.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-FEDWAYDS.js → chunk-OJLTLYHB.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-KJJAVH3X.js → chunk-OLAWH5UQ.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-G224FADB.js → chunk-OOU2WZZE.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-NFNVDDGB.js → chunk-OSTKYB55.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-P4QNXS6I.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-7IYC4ENJ.js → chunk-PKES3ISE.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-UCVMSOXF.js → chunk-PO45POGF.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-JWOVP5BL.js → chunk-PPIBVH4R.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-EWXXLS26.js → chunk-PQJFG24Z.js} +82 -12
- package/node_modules/pi-lens/dist/{chunk-TPYYEDP5.js → chunk-Q3UZHW6N.js} +45 -22
- package/node_modules/pi-lens/dist/{chunk-5DKE4HGX.js → chunk-Q4EMRFNA.js} +34 -34
- package/node_modules/pi-lens/dist/{chunk-XHLK33VM.js → chunk-Q4FCYCRE.js} +16 -16
- package/node_modules/pi-lens/dist/chunk-Q6D6VMI4.js +22 -0
- package/node_modules/pi-lens/dist/{chunk-Q4BKKOVC.js → chunk-QGSTQH4D.js} +8 -8
- package/node_modules/pi-lens/dist/{chunk-GYRZ72R4.js → chunk-RZOXUSPC.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-EN5AM7PX.js → chunk-S67UJDGQ.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-YWNO5Q4R.js → chunk-SCIUNBPF.js} +17 -17
- package/node_modules/pi-lens/dist/{chunk-VIDEKABZ.js → chunk-SJJYRZB4.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-SXGD4ANG.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-THEXI2QO.js → chunk-T7FTXGS3.js} +42 -42
- package/node_modules/pi-lens/dist/{chunk-WUY4BZEP.js → chunk-TIQJPRDD.js} +106 -50
- package/node_modules/pi-lens/dist/{chunk-EXVXBSGN.js → chunk-TIYGSODX.js} +17 -17
- package/node_modules/pi-lens/dist/{chunk-2FYKETQJ.js → chunk-U2SDMG7C.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-PJXNTPB2.js → chunk-U6OC3QEM.js} +21 -21
- package/node_modules/pi-lens/dist/{chunk-LMCTHJ2H.js → chunk-UCGQT677.js} +18 -18
- package/node_modules/pi-lens/dist/{chunk-UL5SXQVX.js → chunk-UHGF5UT5.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-AI3GP74G.js → chunk-UN4TEBWN.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-2SDHYHHO.js → chunk-V3APN3DY.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-7FLRUH6B.js → chunk-V63BC55Q.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-S55TEC7I.js → chunk-VG5JS5SW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-IEBJF3PN.js → chunk-VPBIMOAQ.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-EX4EXBW7.js → chunk-VQH24FIP.js} +15 -15
- package/node_modules/pi-lens/dist/{chunk-TVZRLTG6.js → chunk-VSFLRN5Y.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-KCBRHV5E.js → chunk-W2V54OCL.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-VITFDI3O.js → chunk-W5LGKNET.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-OZNCKLOX.js → chunk-W5R5SABV.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-ELZRSR5N.js → chunk-WIZWZR4C.js} +38 -38
- package/node_modules/pi-lens/dist/{chunk-MKPCELNI.js → chunk-WQOIR3QY.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-COOUUC5W.js → chunk-XAIT2YGS.js} +6 -6
- package/node_modules/pi-lens/dist/chunk-XCUHKYCQ.js +23 -0
- package/node_modules/pi-lens/dist/{chunk-KFXCL4OV.js → chunk-XQCSWV2G.js} +22 -23
- package/node_modules/pi-lens/dist/{chunk-RU34BA4D.js → chunk-YBSONGSZ.js} +34 -34
- package/node_modules/pi-lens/dist/{chunk-GTDSYEA2.js → chunk-YISME6ON.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-YRD4ISED.js +30 -0
- package/node_modules/pi-lens/dist/{chunk-X3UTCXAA.js → chunk-YSBHPOY6.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-XWFIHYCH.js → chunk-Z2XAOKHK.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-K4SZB56V.js → chunk-Z7IGUAXL.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-KX56K73G.js → chunk-ZKXQKGWZ.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-FWZRGGGY.js → chunk-ZQ6NZZTB.js} +6 -4
- package/node_modules/pi-lens/dist/{chunk-2Y6OJRSI.js → chunk-ZUUI3ZSA.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-UO66IMVP.js → chunk-ZYNI26MI.js} +2 -2
- package/node_modules/pi-lens/dist/index.js +571 -409
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -10
- package/node_modules/pi-lens/dist/mcp/cli.js +42 -42
- package/node_modules/pi-lens/dist/mcp/server.js +108 -108
- package/node_modules/pi-lens/dist/mcp/worker.js +61 -61
- package/node_modules/pi-lens/dist/probes/installer.js +19 -19
- package/node_modules/pi-lens/docs/agent-tools.md +28 -7
- package/node_modules/pi-lens/docs/configuration.md +3 -1
- package/node_modules/pi-lens/docs/defect-shapes.md +738 -0
- package/node_modules/pi-lens/docs/invariants/caches-stores.md +30 -0
- package/node_modules/pi-lens/docs/invariants/dispatch-runners.md +164 -0
- package/node_modules/pi-lens/docs/invariants/git-guard-host.md +53 -0
- package/node_modules/pi-lens/docs/invariants/language-config.md +31 -0
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +286 -0
- package/node_modules/pi-lens/docs/invariants/paths-os.md +59 -0
- package/node_modules/pi-lens/docs/invariants/session-telemetry.md +74 -0
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +2 -1
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +10 -8
- package/node_modules/pi-lens/docs/pi-lens-monitor.md +2 -2
- package/node_modules/pi-lens/docs/pi-lens-orchestration.md +41 -0
- package/node_modules/pi-lens/docs/pi-lens-release.md +20 -0
- package/node_modules/pi-lens/docs/pi-lens-retro.md +3 -2
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +6 -6
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +2 -2
- package/node_modules/pi-lens/package.json +3 -2
- package/node_modules/pi-provider-qoder/dist/index.js +27 -5
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/client.js +43 -1
- package/node_modules/pi-typesafe/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +40 -0
- package/node_modules/pi-web-access/README.md +96 -22
- package/node_modules/pi-web-access/brave-rate-limit.ts +2 -2
- package/node_modules/pi-web-access/curator-page.ts +3 -1
- package/node_modules/pi-web-access/curator-server.ts +1 -0
- package/node_modules/pi-web-access/dist/index.js +2607 -1674
- package/node_modules/pi-web-access/dist/mcp-cli.js +1119 -327
- package/node_modules/pi-web-access/duckduckgo-rate-limit.ts +95 -0
- package/node_modules/pi-web-access/duckduckgo.ts +51 -45
- package/node_modules/pi-web-access/exa.ts +48 -6
- package/node_modules/pi-web-access/extract.ts +2 -2
- package/node_modules/pi-web-access/fetch-params.ts +5 -4
- package/node_modules/pi-web-access/field-extract.ts +347 -0
- package/node_modules/pi-web-access/gemini-search.ts +151 -13
- package/node_modules/pi-web-access/index.ts +128 -125
- package/node_modules/pi-web-access/mistral-search.ts +1 -1
- package/node_modules/pi-web-access/ninerouter.ts +92 -0
- package/node_modules/pi-web-access/offtopic-judge.ts +72 -0
- package/node_modules/pi-web-access/openai-search.ts +36 -10
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/perplexity.ts +1 -0
- package/node_modules/pi-web-access/query-rewrite.ts +39 -13
- package/node_modules/pi-web-access/source-check.ts +31 -15
- package/node_modules/pi-web-access/summary-model-scope.ts +19 -1
- package/node_modules/pi-web-access/summary-review.ts +13 -20
- package/node_modules/pi-web-access/tool-arguments.ts +1 -1
- package/node_modules/pi-web-access/upgrade-notice.ts +47 -0
- package/node_modules/pi-web-access/utils.ts +26 -1
- package/node_modules/pi-web-access/web-tool-contract.ts +4 -1
- package/node_modules/pi-web-access/web-tool-core.ts +99 -19
- package/node_modules/pi-web-access/xai-search.ts +3 -3
- package/package.json +10 -10
- package/node_modules/pi-lens/dist/chunk-22Y2BM7H.js +0 -23
- package/node_modules/pi-lens/dist/chunk-44X7VIKR.js +0 -73
- package/node_modules/pi-lens/dist/chunk-54NIOJJZ.js +0 -25
- package/node_modules/pi-lens/dist/chunk-7WWQAW5P.js +0 -30
- package/node_modules/pi-lens/dist/chunk-EA2ZRG44.js +0 -27
- package/node_modules/pi-lens/dist/chunk-EKNWOL2I.js +0 -27
- package/node_modules/pi-lens/dist/chunk-G5UCJFT7.js +0 -26
- package/node_modules/pi-lens/dist/chunk-N5FBM25N.js +0 -22
- package/node_modules/pi-lens/dist/chunk-P5XUGPIX.js +0 -31
- package/node_modules/pi-lens/dist/chunk-PKOXJIVT.js +0 -88
- package/node_modules/pi-lens/dist/chunk-RG7OODGM.js +0 -57
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { awaitWithAbort } from "./abortable.ts";
|
|
2
|
+
import { defaultSleep, formatWait } from "./brave-rate-limit.ts";
|
|
3
|
+
|
|
4
|
+
// DuckDuckGo has no API quota, but it shows its bot check to the whole client IP
|
|
5
|
+
// (browsers included) when requests arrive in bursts, and keeps it up for 10-15
|
|
6
|
+
// minutes, longer after repeated blocks. Requests spaced about 2s apart pass. So
|
|
7
|
+
// searches run one at a time with a minimum gap, and after a bot check this process
|
|
8
|
+
// stops asking for a while instead of retrying, since retries only keep the block in
|
|
9
|
+
// place.
|
|
10
|
+
|
|
11
|
+
const DEFAULT_MIN_INTERVAL_MS = 2_000;
|
|
12
|
+
const DEFAULT_COOLDOWN_MS = 5 * 60_000;
|
|
13
|
+
const DEFAULT_MAX_COOLDOWN_MS = 60 * 60_000;
|
|
14
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
15
|
+
|
|
16
|
+
export class DuckDuckGoBotCheckError extends Error {
|
|
17
|
+
constructor(status: number) {
|
|
18
|
+
// "rate limited" makes search routing classify this as quota.
|
|
19
|
+
super(`DuckDuckGo blocked the request with a bot check (HTTP ${status}, rate limited); use another search provider`);
|
|
20
|
+
this.name = "DuckDuckGoBotCheckError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface DuckDuckGoRateLimitOptions {
|
|
25
|
+
now?: () => number;
|
|
26
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
27
|
+
minIntervalMs?: number;
|
|
28
|
+
cooldownMs?: number;
|
|
29
|
+
maxCooldownMs?: number;
|
|
30
|
+
/** Deadline per search, counted from when it is queued. */
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class DuckDuckGoRateLimit {
|
|
35
|
+
private queue: Promise<void> = Promise.resolve();
|
|
36
|
+
private lastStart = Number.NEGATIVE_INFINITY;
|
|
37
|
+
private blockedUntil = 0;
|
|
38
|
+
private nextCooldownMs: number;
|
|
39
|
+
private readonly now: () => number;
|
|
40
|
+
private readonly sleep: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
41
|
+
private readonly minIntervalMs: number;
|
|
42
|
+
private readonly cooldownMs: number;
|
|
43
|
+
private readonly maxCooldownMs: number;
|
|
44
|
+
private readonly timeoutMs: number;
|
|
45
|
+
|
|
46
|
+
constructor(options: DuckDuckGoRateLimitOptions = {}) {
|
|
47
|
+
this.now = options.now ?? Date.now;
|
|
48
|
+
this.sleep = options.sleep ?? defaultSleep;
|
|
49
|
+
this.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;
|
|
50
|
+
this.cooldownMs = options.cooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
51
|
+
this.maxCooldownMs = options.maxCooldownMs ?? DEFAULT_MAX_COOLDOWN_MS;
|
|
52
|
+
this.nextCooldownMs = this.cooldownMs;
|
|
53
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Queues `operation` and passes it a signal that fires on the caller's abort or when
|
|
58
|
+
* the deadline passes. A passed deadline rejects with a "timed out" error rather than
|
|
59
|
+
* an abort, so search routing treats it as a network failure and can fall back.
|
|
60
|
+
*/
|
|
61
|
+
run<T>(operation: (signal: AbortSignal) => Promise<T>, callerSignal?: AbortSignal): Promise<T> {
|
|
62
|
+
if (callerSignal?.aborted) return Promise.reject(new Error("Aborted"));
|
|
63
|
+
const deadline = AbortSignal.timeout(this.timeoutMs);
|
|
64
|
+
const signal = callerSignal ? AbortSignal.any([deadline, callerSignal]) : deadline;
|
|
65
|
+
const scheduled = this.queue.then(() => this.runNow(operation, signal));
|
|
66
|
+
this.queue = scheduled.then(() => undefined, () => undefined);
|
|
67
|
+
// Let a search give up while still queued without unblocking the queue early.
|
|
68
|
+
return awaitWithAbort(scheduled, signal).catch(error => {
|
|
69
|
+
if (deadline.aborted && !callerSignal?.aborted) {
|
|
70
|
+
throw new Error(`DuckDuckGo request timed out after ${formatWait(this.timeoutMs)}`);
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private async runNow<T>(operation: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> {
|
|
77
|
+
if (signal.aborted) throw new Error("Aborted");
|
|
78
|
+
const remainingMs = this.blockedUntil - this.now();
|
|
79
|
+
if (remainingMs > 0) throw new Error(`DuckDuckGo showed a bot check recently; not retrying for ${formatWait(remainingMs)} (rate limited); use another search provider`);
|
|
80
|
+
const waitMs = this.lastStart + this.minIntervalMs - this.now();
|
|
81
|
+
if (waitMs > 0) await this.sleep(waitMs, signal);
|
|
82
|
+
this.lastStart = this.now();
|
|
83
|
+
try {
|
|
84
|
+
const result = await operation(signal);
|
|
85
|
+
this.nextCooldownMs = this.cooldownMs;
|
|
86
|
+
return result;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof DuckDuckGoBotCheckError) {
|
|
89
|
+
this.blockedUntil = this.now() + this.nextCooldownMs;
|
|
90
|
+
this.nextCooldownMs = Math.min(this.nextCooldownMs * 2, this.maxCooldownMs);
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { activityMonitor } from "./activity.ts";
|
|
2
2
|
import { normalizeDomain } from "./domain-filter-normalization.ts";
|
|
3
|
+
import { DuckDuckGoBotCheckError, DuckDuckGoRateLimit, type DuckDuckGoRateLimitOptions } from "./duckduckgo-rate-limit.ts";
|
|
3
4
|
import type { SearchOptions, SearchResult, SearchResponse } from "./perplexity.ts";
|
|
4
5
|
import { normalizeSearchResultCount } from "./search-result-count-normalization.ts";
|
|
5
6
|
|
|
6
7
|
const SEARCH_URL = "https://html.duckduckgo.com/html/";
|
|
7
|
-
|
|
8
|
+
let rateLimit = new DuckDuckGoRateLimit();
|
|
9
|
+
|
|
10
|
+
/** Replace the shared request spacing and bot-check cooldown state (for tests). */
|
|
11
|
+
export function resetDuckDuckGoRateLimit(options?: DuckDuckGoRateLimitOptions): void {
|
|
12
|
+
rateLimit = new DuckDuckGoRateLimit(options);
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
interface NormalizedDomainFilters {
|
|
10
16
|
allowed: string[];
|
|
@@ -54,52 +60,52 @@ export async function searchWithDuckDuckGo(query: string, options: SearchOptions
|
|
|
54
60
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
55
61
|
|
|
56
62
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
63
|
+
return await rateLimit.run(async signal => {
|
|
64
|
+
const response = await fetch(url, {
|
|
65
|
+
method: "GET",
|
|
66
|
+
headers: {
|
|
67
|
+
Accept: "text/html",
|
|
68
|
+
"User-Agent": "Mozilla/5.0 (compatible; pi-web-access/1.0; +https://github.com/nicobailon/pi-web-access)",
|
|
69
|
+
},
|
|
70
|
+
signal,
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const body = await response.text();
|
|
74
|
+
throw new Error(`DuckDuckGo search error ${response.status}: ${body.slice(0, 300)}`);
|
|
75
|
+
}
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
77
|
+
const { parseHTML } = await import("linkedom");
|
|
78
|
+
const { document } = parseHTML(await response.text());
|
|
79
|
+
// The bot check answers 202 or a challenge page.
|
|
80
|
+
if (response.status === 202 || document.querySelector(".anomaly-modal__box, #challenge-form")) {
|
|
81
|
+
throw new DuckDuckGoBotCheckError(response.status);
|
|
82
|
+
}
|
|
83
|
+
const filters = normalizeDomainFilters(options.domainFilter);
|
|
84
|
+
const results: SearchResult[] = [];
|
|
85
|
+
let parseableResults = 0;
|
|
86
|
+
for (const container of document.querySelectorAll(".result")) {
|
|
87
|
+
if (container.classList.contains("result--ad")) continue;
|
|
88
|
+
const anchor = container.querySelector(".result__a");
|
|
89
|
+
const title = anchor?.textContent?.trim() ?? "";
|
|
90
|
+
const href = anchor?.getAttribute("href")?.trim() ?? "";
|
|
91
|
+
const resultUrl = href ? decodeResultUrl(href) : null;
|
|
92
|
+
if (!title || !resultUrl) continue;
|
|
93
|
+
parseableResults++;
|
|
94
|
+
if (!matchesDomainFilters(resultUrl, filters)) continue;
|
|
95
|
+
const snippet = container.querySelector(".result__snippet")?.textContent?.trim() ?? "";
|
|
96
|
+
results.push({ title, url: resultUrl, snippet });
|
|
97
|
+
if (results.length >= normalizeSearchResultCount(options.numResults)) break;
|
|
98
|
+
}
|
|
99
|
+
if (parseableResults === 0 && !document.querySelector(".no-results__message")) {
|
|
100
|
+
throw new Error("DuckDuckGo returned no parseable results (invalid response)");
|
|
101
|
+
}
|
|
97
102
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
104
|
+
const answer = results.map(result => result.snippet
|
|
105
|
+
? `${result.snippet}\nSource: ${result.title} (${result.url})`
|
|
106
|
+
: `Source: ${result.title} (${result.url})`).join("\n\n");
|
|
107
|
+
return { answer, results };
|
|
108
|
+
}, options.signal);
|
|
103
109
|
} catch (err) {
|
|
104
110
|
const message = err instanceof Error ? err.message : String(err);
|
|
105
111
|
if (message.toLowerCase().includes("abort")) activityMonitor.logComplete(activityId, 0);
|
|
@@ -3,7 +3,7 @@ import { activityMonitor } from "./activity.ts";
|
|
|
3
3
|
import type { ExtractedContent } from "./extract.ts";
|
|
4
4
|
import type { SearchOptions, SearchResponse } from "./perplexity.ts";
|
|
5
5
|
import { hasCredentialSource, redactCredential, resolveCredential } from "./credential-source.ts";
|
|
6
|
-
import { fetchWithCredentialRedirects, getWebSearchConfigPath, resolveApiBaseUrl } from "./utils.ts";
|
|
6
|
+
import { fetchWithCredentialRedirects, getWebSearchConfigPath, isRecord, resolveApiBaseUrl } from "./utils.ts";
|
|
7
7
|
|
|
8
8
|
const EXA_API_BASE_URL = "https://api.exa.ai";
|
|
9
9
|
const EXA_MCP_URL = "https://mcp.exa.ai/mcp";
|
|
@@ -25,6 +25,7 @@ interface ExaSearchResponse {
|
|
|
25
25
|
text?: string;
|
|
26
26
|
highlights?: unknown;
|
|
27
27
|
highlightScores?: number[];
|
|
28
|
+
entities?: unknown;
|
|
28
29
|
}>;
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -43,11 +44,13 @@ export type ExaSearchResult = SearchResponse | null;
|
|
|
43
44
|
|
|
44
45
|
export interface ExaSearchOptions extends SearchOptions {
|
|
45
46
|
includeContent?: boolean;
|
|
46
|
-
/** Restrict results to an Exa content category (e.g. "
|
|
47
|
+
/** Restrict results to an Exa content category (e.g. "publication", "news", "company"). */
|
|
47
48
|
category?: string;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
type McpParsedResult = { title: string; url: string; content: string };
|
|
51
|
+
type McpParsedResult = { title: string; url: string; content: string; publishedDate?: string; author?: string };
|
|
52
|
+
|
|
53
|
+
const MAX_LISTED_AUTHORS = 3;
|
|
51
54
|
|
|
52
55
|
let cachedConfig: WebSearchConfig | null = null;
|
|
53
56
|
|
|
@@ -154,6 +157,38 @@ function fallbackSourceLabel(url: string | undefined, index: number): string {
|
|
|
154
157
|
return `Source ${index + 1}`;
|
|
155
158
|
}
|
|
156
159
|
|
|
160
|
+
function nonEmptyString(value: unknown): string | null {
|
|
161
|
+
return typeof value === "string" && value.trim().length > 0 && value.trim() !== "N/A" ? value.trim() : null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function publicationProperties(entities: unknown): Record<string, unknown> | null {
|
|
165
|
+
const entity: unknown = Array.isArray(entities) ? entities.find(item => isRecord(item) && item.type === "publication") : undefined;
|
|
166
|
+
return isRecord(entity) && isRecord(entity.properties) ? entity.properties : null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function listAuthors(names: string[]): string | null {
|
|
170
|
+
if (names.length === 0) return null;
|
|
171
|
+
const listed = names.slice(0, MAX_LISTED_AUTHORS).join(", ");
|
|
172
|
+
return names.length > MAX_LISTED_AUTHORS ? `${listed} et al.` : listed;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** One line of the date, authors and, for Exa's `publication` category, the citation count and DOI. */
|
|
176
|
+
function formatResultMetadata(item: { publishedDate?: string; author?: string; entities?: unknown }): string {
|
|
177
|
+
const paper = publicationProperties(item.entities);
|
|
178
|
+
const parts: string[] = [];
|
|
179
|
+
const date = (nonEmptyString(item.publishedDate) ?? nonEmptyString(paper?.date))?.slice(0, 10)
|
|
180
|
+
?? (typeof paper?.year === "number" ? String(paper.year) : null);
|
|
181
|
+
if (date) parts.push(`Published: ${date}`);
|
|
182
|
+
const paperAuthors = Array.isArray(paper?.authors) ? paper.authors.flatMap(author => nonEmptyString(isRecord(author) ? author.name : null) ?? []) : [];
|
|
183
|
+
// Exa's top-level `author` joins every paper author with ", ".
|
|
184
|
+
const authors = listAuthors(paperAuthors) ?? listAuthors(nonEmptyString(item.author)?.split(", ").map(name => name.trim()).filter(Boolean) ?? []);
|
|
185
|
+
if (authors) parts.push(`Authors: ${authors}`);
|
|
186
|
+
if (typeof paper?.citationCount === "number") parts.push(`Citations: ${paper.citationCount}`);
|
|
187
|
+
const doi = nonEmptyString(paper?.doi);
|
|
188
|
+
if (doi) parts.push(`DOI: ${doi}`);
|
|
189
|
+
return parts.length > 0 ? `\n${parts.join(" | ")}` : "";
|
|
190
|
+
}
|
|
191
|
+
|
|
157
192
|
function buildAnswerFromSearchResults(results: ExaSearchResponse["results"]): string {
|
|
158
193
|
if (!results?.length) return "";
|
|
159
194
|
const parts: string[] = [];
|
|
@@ -166,7 +201,7 @@ function buildAnswerFromSearchResults(results: ExaSearchResponse["results"]): st
|
|
|
166
201
|
: typeof item.text === "string" ? item.text.trim().slice(0, 1000) : "";
|
|
167
202
|
if (!content) continue;
|
|
168
203
|
const sourceTitle = item.title || fallbackSourceLabel(item.url, i);
|
|
169
|
-
parts.push(`${content}\nSource: ${sourceTitle} (${item.url})`);
|
|
204
|
+
parts.push(`${content}\nSource: ${sourceTitle} (${item.url})${formatResultMetadata(item)}`);
|
|
170
205
|
}
|
|
171
206
|
return parts.join("\n\n");
|
|
172
207
|
}
|
|
@@ -298,17 +333,24 @@ function parseMcpResults(text: string): McpParsedResult[] | null {
|
|
|
298
333
|
const title = block.match(/^Title: (.+)/m)?.[1]?.trim() ?? "";
|
|
299
334
|
const url = block.match(/^URL: (.+)/m)?.[1]?.trim() ?? "";
|
|
300
335
|
let content = "";
|
|
336
|
+
let contentStart = block.length;
|
|
301
337
|
const textStart = block.indexOf("\nText: ");
|
|
302
338
|
if (textStart >= 0) {
|
|
303
339
|
content = block.slice(textStart + 7).trim();
|
|
340
|
+
contentStart = textStart;
|
|
304
341
|
} else {
|
|
305
342
|
const hlMatch = block.match(/\nHighlights:\s*\n/);
|
|
306
343
|
if (hlMatch?.index != null) {
|
|
307
344
|
content = block.slice(hlMatch.index + hlMatch[0].length).trim();
|
|
345
|
+
contentStart = hlMatch.index;
|
|
308
346
|
}
|
|
309
347
|
}
|
|
310
348
|
content = content.replace(/\n---\s*$/, "").trim();
|
|
311
|
-
|
|
349
|
+
// Read metadata from the header only, so a quoted "Author:" line in the page text is not taken as the source's.
|
|
350
|
+
const header = block.slice(0, contentStart);
|
|
351
|
+
const publishedDate = header.match(/^Published: (.+)/m)?.[1]?.trim();
|
|
352
|
+
const author = header.match(/^Author: (.+)/m)?.[1]?.trim();
|
|
353
|
+
return { title, url, content, publishedDate, author };
|
|
312
354
|
}).filter(result => result.url.length > 0);
|
|
313
355
|
return parsed.length > 0 ? parsed : null;
|
|
314
356
|
}
|
|
@@ -321,7 +363,7 @@ function buildAnswerFromMcpResults(results: McpParsedResult[]): string {
|
|
|
321
363
|
const snippet = result.content.replace(/\s+/g, " ").trim().slice(0, 500);
|
|
322
364
|
if (!snippet) continue;
|
|
323
365
|
const sourceTitle = result.title || fallbackSourceLabel(result.url, i);
|
|
324
|
-
parts.push(`${snippet}\nSource: ${sourceTitle} (${result.url})`);
|
|
366
|
+
parts.push(`${snippet}\nSource: ${sourceTitle} (${result.url})${formatResultMetadata(result)}`);
|
|
325
367
|
}
|
|
326
368
|
return parts.join("\n\n");
|
|
327
369
|
}
|
|
@@ -372,7 +372,7 @@ export interface ExtractOptions {
|
|
|
372
372
|
timestamp?: string;
|
|
373
373
|
frames?: number;
|
|
374
374
|
model?: string;
|
|
375
|
-
mode?: "readable" | "raw" | "answer";
|
|
375
|
+
mode?: "readable" | "raw" | "answer" | "extract";
|
|
376
376
|
answerModel?: string;
|
|
377
377
|
authFetchProfile?: AuthFetchProfile;
|
|
378
378
|
toolNames?: RegisteredToolNames;
|
|
@@ -1405,7 +1405,7 @@ async function extractViaHttp(
|
|
|
1405
1405
|
return {
|
|
1406
1406
|
url,
|
|
1407
1407
|
title: result.title,
|
|
1408
|
-
content: options?.mode === "answer"
|
|
1408
|
+
content: options?.mode === "answer" || options?.mode === "extract"
|
|
1409
1409
|
? result.content
|
|
1410
1410
|
: `PDF extracted and saved to: ${result.outputPath}\n\n${result.pages > 0 ? `Pages: ${result.pages}\n` : ""}Characters: ${result.chars}`,
|
|
1411
1411
|
error: null,
|
|
@@ -10,6 +10,7 @@ export interface FetchContentParams {
|
|
|
10
10
|
model?: unknown;
|
|
11
11
|
mode?: unknown;
|
|
12
12
|
answerModel?: unknown;
|
|
13
|
+
fields?: unknown;
|
|
13
14
|
auth?: unknown;
|
|
14
15
|
proxy?: unknown;
|
|
15
16
|
redirects?: unknown;
|
|
@@ -23,7 +24,7 @@ export interface NormalizedFetchContentParams {
|
|
|
23
24
|
timestamp?: string;
|
|
24
25
|
frames?: number;
|
|
25
26
|
model?: string;
|
|
26
|
-
mode?: "readable" | "raw" | "answer";
|
|
27
|
+
mode?: "readable" | "raw" | "answer" | "extract";
|
|
27
28
|
answerModel?: string;
|
|
28
29
|
auth?: true | string;
|
|
29
30
|
proxy?: string;
|
|
@@ -82,10 +83,10 @@ function normalizeOptionalString(value: unknown): string | undefined {
|
|
|
82
83
|
return trimmed || undefined;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
function normalizeMode(value: unknown): "readable" | "raw" | "answer" | undefined {
|
|
86
|
+
function normalizeMode(value: unknown): "readable" | "raw" | "answer" | "extract" | undefined {
|
|
86
87
|
if (value === undefined) return undefined;
|
|
87
|
-
if (value === "readable" || value === "raw" || value === "answer") return value;
|
|
88
|
-
throw new Error('mode must be "readable", "raw", or "
|
|
88
|
+
if (value === "readable" || value === "raw" || value === "answer" || value === "extract") return value;
|
|
89
|
+
throw new Error('mode must be "readable", "raw", "answer", or "extract"');
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
function normalizeRedirects(value: unknown): "same-origin" | undefined {
|