evidence-mcp-dev 1.0.27 → 1.0.29
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/dist/index.js +148 -91
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -159,7 +159,63 @@ var openalexParams = (env = process.env) => {
|
|
|
159
159
|
import { ProxyAgent } from "undici";
|
|
160
160
|
|
|
161
161
|
// src/browser.ts
|
|
162
|
+
import { isIP as isIP2 } from "net";
|
|
163
|
+
|
|
164
|
+
// src/hosts.ts
|
|
162
165
|
import { lookup } from "dns/promises";
|
|
166
|
+
import { connect, isIP } from "net";
|
|
167
|
+
var UP_MS = 6e4;
|
|
168
|
+
var DOWN_MS = 5 * 6e4;
|
|
169
|
+
var PROBE_MS = 3e3;
|
|
170
|
+
var seen = /* @__PURE__ */ new Map();
|
|
171
|
+
var key = (host3, port) => `${host3}:${port}`;
|
|
172
|
+
function connectOnce(address, port, timeoutMs) {
|
|
173
|
+
return new Promise((resolve4) => {
|
|
174
|
+
const s = connect({ host: address, port });
|
|
175
|
+
const done = (error) => {
|
|
176
|
+
s.destroy();
|
|
177
|
+
resolve4(error);
|
|
178
|
+
};
|
|
179
|
+
s.setTimeout(timeoutMs, () => done(`no answer within ${timeoutMs / 1e3} s`));
|
|
180
|
+
s.once("connect", () => done(null));
|
|
181
|
+
s.once("error", (e) => done(e.code ?? e.message));
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async function candidates(host3, lookupImpl = lookup) {
|
|
185
|
+
if (host3 === "localhost" || isIP(host3)) return [host3];
|
|
186
|
+
const all = await lookupImpl(host3, { all: true, order: "verbatim" });
|
|
187
|
+
const usable = all.map((a) => a.address).filter((a) => !/^fe[89ab]/i.test(a));
|
|
188
|
+
return usable.length ? usable : [host3];
|
|
189
|
+
}
|
|
190
|
+
async function probe(host3, port, timeoutMs = PROBE_MS) {
|
|
191
|
+
const t0 = Date.now();
|
|
192
|
+
let list5;
|
|
193
|
+
try {
|
|
194
|
+
list5 = await candidates(host3);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
return { up: false, ms: Date.now() - t0, at: Date.now(), error: e.code ?? String(e) };
|
|
197
|
+
}
|
|
198
|
+
let first = null;
|
|
199
|
+
for (const address of list5) {
|
|
200
|
+
const left = timeoutMs - (Date.now() - t0);
|
|
201
|
+
if (left <= 0) break;
|
|
202
|
+
const error = await connectOnce(address, port, left);
|
|
203
|
+
if (!error) return { up: true, ms: Date.now() - t0, at: Date.now(), error: null, address };
|
|
204
|
+
first ??= error;
|
|
205
|
+
}
|
|
206
|
+
return { up: false, ms: Date.now() - t0, at: Date.now(), error: first ?? `no answer within ${timeoutMs / 1e3} s` };
|
|
207
|
+
}
|
|
208
|
+
async function hostState(host3, port, onDown) {
|
|
209
|
+
const k = key(host3, port), now2 = Date.now(), old = seen.get(k);
|
|
210
|
+
if (old && now2 - old.at < (old.up ? UP_MS : DOWN_MS)) return old;
|
|
211
|
+
const s = await probe(host3, port);
|
|
212
|
+
seen.set(k, s);
|
|
213
|
+
if (!s.up && (!old || old.up)) onDown?.(s);
|
|
214
|
+
return s;
|
|
215
|
+
}
|
|
216
|
+
var downNote = (s) => `host down (${s.error}, since ${new Date(s.at).toTimeString().slice(0, 5)})`;
|
|
217
|
+
|
|
218
|
+
// src/browser.ts
|
|
163
219
|
import { existsSync as existsSync3, mkdirSync } from "fs";
|
|
164
220
|
import { createRequire } from "module";
|
|
165
221
|
import { join as join3 } from "path";
|
|
@@ -246,11 +302,8 @@ async function cdpUrl(endpoint) {
|
|
|
246
302
|
const u = new URL(cdpHttp(endpoint));
|
|
247
303
|
const host3 = u.hostname.replace(/^\[|\]$/g, "");
|
|
248
304
|
if (host3 === "localhost" || /^[\d.]+$/.test(host3) || host3.includes(":")) return u.toString().replace(/\/$/, "");
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
u.hostname = family === 6 ? `[${address}]` : address;
|
|
252
|
-
} catch {
|
|
253
|
-
}
|
|
305
|
+
const h = await hostState(host3, Number(u.port) || 9222);
|
|
306
|
+
if (h.address) u.hostname = isIP2(h.address) === 6 ? `[${h.address}]` : h.address;
|
|
254
307
|
return u.toString().replace(/\/$/, "");
|
|
255
308
|
}
|
|
256
309
|
var stageKind = (endpoint) => isCdp(endpoint) ? "chrome" : "playwright";
|
|
@@ -597,36 +650,6 @@ function checkFulltext(md, title, titleSource, doi, trusted = false, pdf = false
|
|
|
597
650
|
return { ok: true };
|
|
598
651
|
}
|
|
599
652
|
|
|
600
|
-
// src/hosts.ts
|
|
601
|
-
import { connect } from "net";
|
|
602
|
-
var UP_MS = 6e4;
|
|
603
|
-
var DOWN_MS = 5 * 6e4;
|
|
604
|
-
var PROBE_MS = 3e3;
|
|
605
|
-
var seen = /* @__PURE__ */ new Map();
|
|
606
|
-
var key = (host3, port) => `${host3}:${port}`;
|
|
607
|
-
function probe(host3, port, timeoutMs = PROBE_MS) {
|
|
608
|
-
const t0 = Date.now();
|
|
609
|
-
return new Promise((resolve4) => {
|
|
610
|
-
const s = connect({ host: host3, port });
|
|
611
|
-
const done = (error) => {
|
|
612
|
-
s.destroy();
|
|
613
|
-
resolve4({ up: !error, ms: Date.now() - t0, at: Date.now(), error });
|
|
614
|
-
};
|
|
615
|
-
s.setTimeout(timeoutMs, () => done(`no answer within ${timeoutMs / 1e3} s`));
|
|
616
|
-
s.once("connect", () => done(null));
|
|
617
|
-
s.once("error", (e) => done(e.code ?? e.message));
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
async function hostState(host3, port, onDown) {
|
|
621
|
-
const k = key(host3, port), now2 = Date.now(), old = seen.get(k);
|
|
622
|
-
if (old && now2 - old.at < (old.up ? UP_MS : DOWN_MS)) return old;
|
|
623
|
-
const s = await probe(host3, port);
|
|
624
|
-
seen.set(k, s);
|
|
625
|
-
if (!s.up && (!old || old.up)) onDown?.(s);
|
|
626
|
-
return s;
|
|
627
|
-
}
|
|
628
|
-
var downNote = (s) => `host down (${s.error}, since ${new Date(s.at).toTimeString().slice(0, 5)})`;
|
|
629
|
-
|
|
630
653
|
// src/html.ts
|
|
631
654
|
import TurndownService from "turndown";
|
|
632
655
|
import { gfm } from "@joplin/turndown-plugin-gfm";
|
|
@@ -884,7 +907,7 @@ function renderCitation(nodes2) {
|
|
|
884
907
|
const el = nodes2.find((x) => ["element-citation", "mixed-citation", "citation", "nlm-citation"].includes(tagOf(x)));
|
|
885
908
|
if (!el) return squash(inlineText(nodes2));
|
|
886
909
|
const f = kids(el);
|
|
887
|
-
const
|
|
910
|
+
const get5 = (tag) => f.filter((x) => tagOf(x) === tag).map((x) => squash(inlineText(kids(x))));
|
|
888
911
|
const names2 = f.filter((x) => tagOf(x) === "person-group").flatMap((g) => kids(g)).map((x) => {
|
|
889
912
|
const t = tagOf(x);
|
|
890
913
|
if (t === "etal") return "et al";
|
|
@@ -896,11 +919,11 @@ function renderCitation(nodes2) {
|
|
|
896
919
|
}
|
|
897
920
|
return "";
|
|
898
921
|
}).filter(Boolean);
|
|
899
|
-
const vol =
|
|
900
|
-
const pages = fp ? lp ? `${fp}-${lp}` : fp :
|
|
901
|
-
const where2 = [
|
|
922
|
+
const vol = get5("volume")[0], issue = get5("issue")[0], fp = get5("fpage")[0], lp = get5("lpage")[0];
|
|
923
|
+
const pages = fp ? lp ? `${fp}-${lp}` : fp : get5("elocation-id")[0];
|
|
924
|
+
const where2 = [get5("source")[0], get5("year")[0] ? `${get5("year")[0]};` : "", vol ? `${vol}${issue ? `(${issue})` : ""}` : "", pages ? `:${pages}` : ""].filter(Boolean).join("").replace(/;$/, "");
|
|
902
925
|
const ids = f.filter((x) => tagOf(x) === "pub-id").map((x) => `${attr(x, "pub-id-type")}:${squash(plainText(kids(x)))}`);
|
|
903
|
-
return [names2.join(", "), [...
|
|
926
|
+
return [names2.join(", "), [...get5("article-title"), ...get5("chapter-title")][0], where2, ...ids].filter(Boolean).join(". ").replace(/\.\./g, ".");
|
|
904
927
|
}
|
|
905
928
|
var FN_LABELS = {
|
|
906
929
|
"conflict": "Conflicts of interest",
|
|
@@ -1417,7 +1440,7 @@ async function get(url, postImpl = post, signal) {
|
|
|
1417
1440
|
}
|
|
1418
1441
|
var brightdata = { name: "brightdata", keyVar: "FH_BRIGHTDATA_API_KEY", get: (url, signal) => get(url, post, signal) };
|
|
1419
1442
|
|
|
1420
|
-
// src/unlock/
|
|
1443
|
+
// src/unlock/firecrawl.ts
|
|
1421
1444
|
var TIMEOUT_MS3 = 6e4;
|
|
1422
1445
|
var ACCOUNT = /* @__PURE__ */ new Set([401, 402, 403, 429]);
|
|
1423
1446
|
async function get2(url, fetchImpl = fetch, signal) {
|
|
@@ -1428,9 +1451,42 @@ async function get2(url, fetchImpl = fetch, signal) {
|
|
|
1428
1451
|
}
|
|
1429
1452
|
}
|
|
1430
1453
|
async function request(url, fetchImpl, signal) {
|
|
1454
|
+
const key2 = process.env.FH_FIRECRAWL_API_KEY?.trim();
|
|
1455
|
+
if (!key2) throw new Error("not configured");
|
|
1456
|
+
const r = await fetchImpl("https://api.firecrawl.dev/v2/scrape", {
|
|
1457
|
+
method: "POST",
|
|
1458
|
+
signal: timeoutOr(TIMEOUT_MS3, signal),
|
|
1459
|
+
headers: { authorization: `Bearer ${key2}`, "content-type": "application/json" },
|
|
1460
|
+
body: JSON.stringify({ url, formats: ["rawHtml"], parsers: [], proxy: "auto", timeout: TIMEOUT_MS3 - 5e3 })
|
|
1461
|
+
});
|
|
1462
|
+
const j = await r.json().catch(() => ({}));
|
|
1463
|
+
if (!r.ok || !j.success) {
|
|
1464
|
+
const why = (j.error ?? "").replace(/\s+/g, " ").slice(0, 200);
|
|
1465
|
+
throw new Error(ACCOUNT.has(r.status) ? `unlocker HTTP ${r.status}${why ? `: ${why}` : ""}` : `HTTP ${r.status}${why ? ` ${why}` : ""}`);
|
|
1466
|
+
}
|
|
1467
|
+
const m = j.data?.metadata;
|
|
1468
|
+
if (m?.statusCode && m.statusCode >= 400) throw new Error(`HTTP ${m.statusCode}`);
|
|
1469
|
+
const contentType = m?.contentType ?? "";
|
|
1470
|
+
const raw = j.data?.rawHtml ?? "";
|
|
1471
|
+
const binary = /pdf|octet-stream/i.test(contentType) || raw.startsWith("JVBERi");
|
|
1472
|
+
return { bytes: binary ? Buffer.from(raw, "base64") : Buffer.from(raw, "utf8"), contentType };
|
|
1473
|
+
}
|
|
1474
|
+
var firecrawl = { name: "firecrawl", keyVar: "FH_FIRECRAWL_API_KEY", get: (url, signal) => get2(url, fetch, signal) };
|
|
1475
|
+
|
|
1476
|
+
// src/unlock/zenrows.ts
|
|
1477
|
+
var TIMEOUT_MS4 = 6e4;
|
|
1478
|
+
var ACCOUNT2 = /* @__PURE__ */ new Set([401, 402, 403, 429]);
|
|
1479
|
+
async function get3(url, fetchImpl = fetch, signal) {
|
|
1480
|
+
try {
|
|
1481
|
+
return await request2(url, fetchImpl, signal);
|
|
1482
|
+
} catch (e) {
|
|
1483
|
+
throw e?.name === "TimeoutError" ? new Error("timeout") : e;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
async function request2(url, fetchImpl, signal) {
|
|
1431
1487
|
const key2 = process.env.FH_ZENROWS_API_KEY?.trim();
|
|
1432
1488
|
if (!key2) throw new Error("not configured");
|
|
1433
|
-
const r = await fetchImpl(`https://api.zenrows.com/v1/?apikey=${encodeURIComponent(key2)}&url=${encodeURIComponent(url)}&mode=auto`, { signal: timeoutOr(
|
|
1489
|
+
const r = await fetchImpl(`https://api.zenrows.com/v1/?apikey=${encodeURIComponent(key2)}&url=${encodeURIComponent(url)}&mode=auto`, { signal: timeoutOr(TIMEOUT_MS4, signal) });
|
|
1434
1490
|
const bytes = Buffer.from(await r.arrayBuffer());
|
|
1435
1491
|
if (!r.ok) {
|
|
1436
1492
|
let why = "";
|
|
@@ -1440,44 +1496,44 @@ async function request(url, fetchImpl, signal) {
|
|
|
1440
1496
|
} catch {
|
|
1441
1497
|
why = bytes.toString("utf8").slice(0, 120).trim();
|
|
1442
1498
|
}
|
|
1443
|
-
throw new Error(
|
|
1499
|
+
throw new Error(ACCOUNT2.has(r.status) ? `unlocker HTTP ${r.status}${why ? `: ${why}` : ""}` : `HTTP ${r.status}${why ? ` ${why}` : ""}`);
|
|
1444
1500
|
}
|
|
1445
1501
|
return { bytes, contentType: r.headers.get("content-type") ?? "" };
|
|
1446
1502
|
}
|
|
1447
|
-
var zenrows = { name: "zenrows", keyVar: "FH_ZENROWS_API_KEY", get: (url, signal) =>
|
|
1503
|
+
var zenrows = { name: "zenrows", keyVar: "FH_ZENROWS_API_KEY", get: (url, signal) => get3(url, fetch, signal) };
|
|
1448
1504
|
|
|
1449
1505
|
// src/unlock/zyte.ts
|
|
1450
|
-
var
|
|
1451
|
-
var
|
|
1452
|
-
async function
|
|
1506
|
+
var TIMEOUT_MS5 = 6e4;
|
|
1507
|
+
var ACCOUNT3 = /* @__PURE__ */ new Set([401, 402, 403, 429]);
|
|
1508
|
+
async function get4(url, fetchImpl = fetch, signal) {
|
|
1453
1509
|
try {
|
|
1454
|
-
return await
|
|
1510
|
+
return await request3(url, fetchImpl, signal);
|
|
1455
1511
|
} catch (e) {
|
|
1456
1512
|
throw e?.name === "TimeoutError" ? new Error("timeout") : e;
|
|
1457
1513
|
}
|
|
1458
1514
|
}
|
|
1459
|
-
async function
|
|
1515
|
+
async function request3(url, fetchImpl, signal) {
|
|
1460
1516
|
const key2 = process.env.FH_ZYTE_API_KEY?.trim();
|
|
1461
1517
|
if (!key2) throw new Error("not configured");
|
|
1462
1518
|
const r = await fetchImpl("https://api.zyte.com/v1/extract", {
|
|
1463
1519
|
method: "POST",
|
|
1464
|
-
signal: timeoutOr(
|
|
1520
|
+
signal: timeoutOr(TIMEOUT_MS5, signal),
|
|
1465
1521
|
headers: { authorization: `Basic ${Buffer.from(`${key2}:`).toString("base64")}`, "content-type": "application/json" },
|
|
1466
1522
|
body: JSON.stringify({ url, httpResponseBody: true, httpResponseHeaders: true })
|
|
1467
1523
|
});
|
|
1468
1524
|
const j = await r.json().catch(() => ({}));
|
|
1469
1525
|
if (!r.ok) {
|
|
1470
1526
|
const why = j.title || j.detail || "";
|
|
1471
|
-
throw new Error(
|
|
1527
|
+
throw new Error(ACCOUNT3.has(r.status) ? `unlocker HTTP ${r.status}${why ? `: ${why}` : ""}` : `HTTP ${r.status}${why ? ` ${why}` : ""}`);
|
|
1472
1528
|
}
|
|
1473
1529
|
if (j.statusCode && j.statusCode >= 400) throw new Error(`HTTP ${j.statusCode}`);
|
|
1474
1530
|
const contentType = j.httpResponseHeaders?.find((h) => h.name.toLowerCase() === "content-type")?.value ?? "";
|
|
1475
1531
|
return { bytes: Buffer.from(j.httpResponseBody ?? "", "base64"), contentType };
|
|
1476
1532
|
}
|
|
1477
|
-
var zyte = { name: "zyte", keyVar: "FH_ZYTE_API_KEY", get: (url, signal) =>
|
|
1533
|
+
var zyte = { name: "zyte", keyVar: "FH_ZYTE_API_KEY", get: (url, signal) => get4(url, fetch, signal) };
|
|
1478
1534
|
|
|
1479
1535
|
// src/unlock.ts
|
|
1480
|
-
var SERVICES = [zenrows, zyte, brightdata];
|
|
1536
|
+
var SERVICES = [firecrawl, zenrows, zyte, brightdata];
|
|
1481
1537
|
var UNLOCKER_NAMES = SERVICES.map((s) => s.name);
|
|
1482
1538
|
var UNLOCKER_PREFIX = new RegExp(`^(${UNLOCKER_NAMES.join("|")}): `);
|
|
1483
1539
|
var accountProblem = (reason) => /^unlocker (HTTP 4\d\d|refused)/.test(reason);
|
|
@@ -2701,13 +2757,13 @@ var hostOf2 = (url) => {
|
|
|
2701
2757
|
}
|
|
2702
2758
|
};
|
|
2703
2759
|
var NCBI = /^https?:\/\/([a-z0-9.-]+\.)?(ncbi\.nlm\.nih\.gov|pubmed\.gov)\//i;
|
|
2704
|
-
function order(
|
|
2760
|
+
function order(candidates2) {
|
|
2705
2761
|
const rank = (c) => (c.pdf ? 0 : 2) + (c.host === "publisher" ? 1 : 0);
|
|
2706
|
-
return [...
|
|
2762
|
+
return [...candidates2].sort((a, b) => rank(a) - rank(b));
|
|
2707
2763
|
}
|
|
2708
|
-
async function download(tier, p,
|
|
2709
|
-
const usable =
|
|
2710
|
-
if (!usable.length &&
|
|
2764
|
+
async function download(tier, p, candidates2, ctx) {
|
|
2765
|
+
const usable = candidates2.filter((c) => !NCBI.test(c.url));
|
|
2766
|
+
if (!usable.length && candidates2.length) return miss(tier, "only pmc copies (covered by the pmc tier)");
|
|
2711
2767
|
const ordered = order(usable.map((c) => {
|
|
2712
2768
|
const u = toHttps(c.url);
|
|
2713
2769
|
if (u !== c.url) ctx.onTry?.(`http upgraded: ${c.url} \u2192 ${u}`);
|
|
@@ -2921,7 +2977,7 @@ function elsevierToJats(xml) {
|
|
|
2921
2977
|
var WINDOW_MS = 6e4;
|
|
2922
2978
|
var PER_WINDOW = 10;
|
|
2923
2979
|
var MAX_WAIT_MS = 65e3;
|
|
2924
|
-
var
|
|
2980
|
+
var TIMEOUT_MS6 = 1e4;
|
|
2925
2981
|
var calls = [];
|
|
2926
2982
|
async function pace() {
|
|
2927
2983
|
const now2 = Date.now();
|
|
@@ -2933,7 +2989,7 @@ async function coreFetch(url, key2) {
|
|
|
2933
2989
|
const headers = { "User-Agent": LIBRARY_UA, Authorization: `Bearer ${key2}` };
|
|
2934
2990
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
2935
2991
|
await pace();
|
|
2936
|
-
const res = await fetch(url, { headers, signal: AbortSignal.timeout(
|
|
2992
|
+
const res = await fetch(url, { headers, signal: AbortSignal.timeout(TIMEOUT_MS6), redirect: "follow" });
|
|
2937
2993
|
if (res.ok) return await res.text();
|
|
2938
2994
|
const body = await res.text().catch(() => "");
|
|
2939
2995
|
if (res.status === 429 && attempt === 0) {
|
|
@@ -2960,10 +3016,10 @@ function coreTier(apiKey2) {
|
|
|
2960
3016
|
} catch (e) {
|
|
2961
3017
|
return miss(this.name, errMsg(e));
|
|
2962
3018
|
}
|
|
2963
|
-
const
|
|
2964
|
-
if (!
|
|
2965
|
-
ctx.onTry?.(`located ${
|
|
2966
|
-
return download(this.name, p,
|
|
3019
|
+
const candidates2 = coreCandidates(data);
|
|
3020
|
+
if (!candidates2.length) return miss(this.name, data.results?.length ? "no full text" : "not in core");
|
|
3021
|
+
ctx.onTry?.(`located ${candidates2.length} copies`);
|
|
3022
|
+
return download(this.name, p, candidates2, ctx);
|
|
2967
3023
|
}
|
|
2968
3024
|
};
|
|
2969
3025
|
}
|
|
@@ -2997,10 +3053,10 @@ var europepmc = {
|
|
|
2997
3053
|
}
|
|
2998
3054
|
const rec = data.resultList?.result?.[0];
|
|
2999
3055
|
if (!rec) return miss(this.name, "not in europe pmc");
|
|
3000
|
-
const
|
|
3001
|
-
if (!
|
|
3002
|
-
ctx.onTry?.(`located ${
|
|
3003
|
-
return download(this.name, p,
|
|
3056
|
+
const candidates2 = europepmcCandidates(rec, p.pmcid);
|
|
3057
|
+
if (!candidates2.length) return miss(this.name, "no free copy");
|
|
3058
|
+
ctx.onTry?.(`located ${candidates2.length} copies`);
|
|
3059
|
+
return download(this.name, p, candidates2, ctx);
|
|
3004
3060
|
}
|
|
3005
3061
|
};
|
|
3006
3062
|
function europepmcCandidates(r, pmcid) {
|
|
@@ -3038,10 +3094,10 @@ var openalex = {
|
|
|
3038
3094
|
} catch (e) {
|
|
3039
3095
|
return miss(this.name, errMsg(e));
|
|
3040
3096
|
}
|
|
3041
|
-
const
|
|
3042
|
-
if (!
|
|
3043
|
-
ctx.onTry?.(`located ${
|
|
3044
|
-
return download(this.name, p,
|
|
3097
|
+
const candidates2 = openalexCandidates(data);
|
|
3098
|
+
if (!candidates2.length) return miss(this.name, data.open_access?.is_oa === false ? "closed" : "no oa copy");
|
|
3099
|
+
ctx.onTry?.(`located ${candidates2.length} copies`);
|
|
3100
|
+
return download(this.name, p, candidates2, ctx);
|
|
3045
3101
|
}
|
|
3046
3102
|
};
|
|
3047
3103
|
function openalexCandidates(d) {
|
|
@@ -3104,12 +3160,12 @@ var hostOf3 = (url) => {
|
|
|
3104
3160
|
function tdmCandidates(work, tokens2 = {}, env = process.env) {
|
|
3105
3161
|
const links = (work.message?.link ?? []).filter((l) => l["intended-application"] === "text-mining" && l.URL);
|
|
3106
3162
|
const seen2 = /* @__PURE__ */ new Set();
|
|
3107
|
-
const
|
|
3163
|
+
const candidates2 = [];
|
|
3108
3164
|
const missingTokens = /* @__PURE__ */ new Set();
|
|
3109
3165
|
for (const l of links) {
|
|
3110
3166
|
const ct = (l["content-type"] ?? "").toLowerCase();
|
|
3111
3167
|
if (seen2.has(l.URL)) {
|
|
3112
|
-
const prev =
|
|
3168
|
+
const prev = candidates2.find((c) => c.url === l.URL);
|
|
3113
3169
|
if (prev && /pdf/.test(ct)) prev.pdf = true;
|
|
3114
3170
|
continue;
|
|
3115
3171
|
}
|
|
@@ -3125,11 +3181,11 @@ function tdmCandidates(work, tokens2 = {}, env = process.env) {
|
|
|
3125
3181
|
headers = { [rule.header]: token };
|
|
3126
3182
|
}
|
|
3127
3183
|
if (/text\/plain/.test(ct)) continue;
|
|
3128
|
-
|
|
3184
|
+
candidates2.push({ url: l.URL, version: "published", source: "tdm", host: work.message?.publisher ?? hostOf3(l.URL), pdf: /pdf/.test(ct) || /\.pdf(\?|$)/i.test(l.URL), headers });
|
|
3129
3185
|
}
|
|
3130
3186
|
const rank = (c) => /\/xml|text\/xml/.test(c.url) ? 0 : c.pdf ? 1 : 2;
|
|
3131
|
-
|
|
3132
|
-
return { candidates, missingTokens: [...missingTokens] };
|
|
3187
|
+
candidates2.sort((a, b) => rank(a) - rank(b));
|
|
3188
|
+
return { candidates: candidates2, missingTokens: [...missingTokens] };
|
|
3133
3189
|
}
|
|
3134
3190
|
function tdmTier(tokens2 = {}) {
|
|
3135
3191
|
return {
|
|
@@ -3143,10 +3199,10 @@ function tdmTier(tokens2 = {}) {
|
|
|
3143
3199
|
} catch (e) {
|
|
3144
3200
|
return miss(this.name, errMsg(e));
|
|
3145
3201
|
}
|
|
3146
|
-
const { candidates, missingTokens } = tdmCandidates(work, tokens2);
|
|
3147
|
-
if (!
|
|
3148
|
-
ctx.onTry?.(`${
|
|
3149
|
-
return download(this.name, p,
|
|
3202
|
+
const { candidates: candidates2, missingTokens } = tdmCandidates(work, tokens2);
|
|
3203
|
+
if (!candidates2.length) return missingTokens.length ? { ...miss(this.name, `needs ${missingTokens.join("/")} token`), skipped: true } : miss(this.name, "no text-mining links");
|
|
3204
|
+
ctx.onTry?.(`${candidates2.length} text-mining links${missingTokens.length ? ` (skipped hosts needing ${missingTokens.join("/")} token)` : ""}`);
|
|
3205
|
+
return download(this.name, p, candidates2, ctx);
|
|
3150
3206
|
}
|
|
3151
3207
|
};
|
|
3152
3208
|
}
|
|
@@ -3164,10 +3220,10 @@ var unpaywall = {
|
|
|
3164
3220
|
} catch (e) {
|
|
3165
3221
|
return miss(this.name, errMsg(e));
|
|
3166
3222
|
}
|
|
3167
|
-
const
|
|
3168
|
-
if (!
|
|
3169
|
-
ctx.onTry?.(`located ${
|
|
3170
|
-
return download(this.name, p,
|
|
3223
|
+
const candidates2 = unpaywallCandidates(data);
|
|
3224
|
+
if (!candidates2.length) return miss(this.name, data.is_oa === false ? "closed" : "no oa copy");
|
|
3225
|
+
ctx.onTry?.(`located ${candidates2.length} copies`);
|
|
3226
|
+
return download(this.name, p, candidates2, ctx);
|
|
3171
3227
|
}
|
|
3172
3228
|
};
|
|
3173
3229
|
function unpaywallCandidates(d) {
|
|
@@ -3261,6 +3317,7 @@ var VARIABLES = [
|
|
|
3261
3317
|
"FH_CITATIONS_ENABLED",
|
|
3262
3318
|
"FH_OPENALEX_API_KEY",
|
|
3263
3319
|
"FH_ZENROWS_API_KEY",
|
|
3320
|
+
"FH_FIRECRAWL_API_KEY",
|
|
3264
3321
|
"FH_ZYTE_API_KEY",
|
|
3265
3322
|
"FH_BRIGHTDATA_API_KEY",
|
|
3266
3323
|
"FH_BRIGHTDATA_ZONE",
|
|
@@ -4143,8 +4200,8 @@ function readMissing(p) {
|
|
|
4143
4200
|
const f = missingFile(p);
|
|
4144
4201
|
if (!existsSync7(f)) return null;
|
|
4145
4202
|
const md = readFileSync5(f, "utf8");
|
|
4146
|
-
const
|
|
4147
|
-
const checked =
|
|
4203
|
+
const get5 = (k) => /^$/.test(k) ? "" : (new RegExp(`^${k}:[ \\t]*(.*)$`, "m").exec(md)?.[1] ?? "").trim();
|
|
4204
|
+
const checked = get5("checked"), reason = get5("reason");
|
|
4148
4205
|
return checked ? { checked, reason: reason || "not found" } : null;
|
|
4149
4206
|
}
|
|
4150
4207
|
function freshMissing(p, retryDays) {
|
|
@@ -5058,13 +5115,13 @@ async function bigSearch(lib, query2, max) {
|
|
|
5058
5115
|
} catch {
|
|
5059
5116
|
}
|
|
5060
5117
|
}
|
|
5061
|
-
const
|
|
5118
|
+
const get5 = (url) => fetchText(url, { "User-Agent": "evidence-mcp", Accept: "application/json" });
|
|
5062
5119
|
try {
|
|
5063
|
-
const { total, ids } = parseEsearch(await
|
|
5120
|
+
const { total, ids } = parseEsearch(await get5(esearchUrl(q)));
|
|
5064
5121
|
const rows = [];
|
|
5065
5122
|
for (let i = 0; i < ids.length; i += 200) {
|
|
5066
5123
|
const chunk = ids.slice(i, i + 200);
|
|
5067
|
-
rows.push(...parseEsummary(await
|
|
5124
|
+
rows.push(...parseEsummary(await get5(esummaryUrl(chunk)), chunk, lib));
|
|
5068
5125
|
}
|
|
5069
5126
|
const result = { source: "pubmed", query: q, total, columns: ["pmid", "title", "first_author", "year", "journal", "publication_types", "pmcid", "level"], rows, searched: today() };
|
|
5070
5127
|
try {
|
|
@@ -5367,7 +5424,7 @@ import { z } from "zod";
|
|
|
5367
5424
|
// src/cascade.ts
|
|
5368
5425
|
var PERMANENT = /^(no pmcid|no doi|no pmid|no pmid or doi|no body|closed|no oa copy|no free copy|not in core|no full text|xml without body|template has no placeholder|title missing|title not in text|no methods\/results|no article body|scanned pdf|not a pdf|only copies already tried|only pmc copies|nothing located|unknown content|no text-mining links|needs [a-z/]+ token)/i;
|
|
5369
5426
|
var BLOCKED = /^(challenge not cleared|empty response)/i;
|
|
5370
|
-
var STAGE = /^((?:playwright|chrome|browser|fetch-proxy) [^:]+|brightdata|zenrows|zyte|unlocker): /;
|
|
5427
|
+
var STAGE = /^((?:playwright|chrome|browser|fetch-proxy) [^:]+|brightdata|firecrawl|zenrows|zyte|unlocker): /;
|
|
5371
5428
|
function isPermanent(reason, retryBlocked = false) {
|
|
5372
5429
|
return reason.split(";").every((r) => {
|
|
5373
5430
|
const b = r.trim().replace(STAGE, "");
|