evidence-mcp-dev 0.2.41 → 0.2.43
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 +41 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -164,9 +164,9 @@ async function cdpUrl(endpoint) {
|
|
|
164
164
|
}
|
|
165
165
|
return u.toString().replace(/\/$/, "");
|
|
166
166
|
}
|
|
167
|
-
var
|
|
168
|
-
var
|
|
169
|
-
var
|
|
167
|
+
var stageKind = (endpoint) => isCdp(endpoint) ? "chrome" : "playwright";
|
|
168
|
+
var stageName = (b) => `${b.kind} ${b.label}`;
|
|
169
|
+
var STAGE_PREFIX = /^(?:playwright|chrome|browser|fetch-proxy) [^:]+: /;
|
|
170
170
|
var hostOf = (endpoint) => {
|
|
171
171
|
try {
|
|
172
172
|
return new URL(isCdp(endpoint) ? cdpHttp(endpoint) : endpoint);
|
|
@@ -183,10 +183,10 @@ function browserHeadless(endpoint, cfg = browserConfig()) {
|
|
|
183
183
|
if (isCdp(endpoint)) return false;
|
|
184
184
|
return cfg.headless === "auto" ? false : cfg.headless;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function browserStages(cfg = browserConfig()) {
|
|
187
187
|
return cfg.browsers.map((endpoint) => {
|
|
188
188
|
const u = hostOf(endpoint);
|
|
189
|
-
return { kind:
|
|
189
|
+
return { kind: stageKind(endpoint), host: u?.hostname ?? endpoint, port: Number(u?.port) || (isCdp(endpoint) ? CHROME_PORT : PLAYWRIGHT_PORT), label: browserLabel(endpoint), endpoint, headless: browserHeadless(endpoint, cfg) };
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
var CHALLENGE = /just a moment|nur einen moment|attention required|verify you are human|human verification|checking your browser|access denied/i;
|
|
@@ -233,7 +233,7 @@ async function context(endpoint, cfg) {
|
|
|
233
233
|
const ctx = await browser.newContext({ ...CONTEXT_OPTS, ...existsSync3(state) ? { storageState: state } : {} });
|
|
234
234
|
return { ctx, browser };
|
|
235
235
|
}
|
|
236
|
-
throw new Error(`not a browser
|
|
236
|
+
throw new Error(`not a browser stage: ${endpoint}`);
|
|
237
237
|
})();
|
|
238
238
|
ctxs.set(endpoint, p);
|
|
239
239
|
p.catch(() => {
|
|
@@ -2379,7 +2379,7 @@ var host = (url) => {
|
|
|
2379
2379
|
}
|
|
2380
2380
|
};
|
|
2381
2381
|
var file = (dir, h) => join5(dir, "walls", `${h.replace(/[^a-z0-9.-]/g, "_")}.json`);
|
|
2382
|
-
var legacy = (
|
|
2382
|
+
var legacy = (stage2) => stage2.replace(/^(playwright|chrome) /, "browser ");
|
|
2383
2383
|
function read(dir, h) {
|
|
2384
2384
|
try {
|
|
2385
2385
|
return JSON.parse(readFileSync3(file(dir, h), "utf8"));
|
|
@@ -2387,28 +2387,28 @@ function read(dir, h) {
|
|
|
2387
2387
|
return {};
|
|
2388
2388
|
}
|
|
2389
2389
|
}
|
|
2390
|
-
function walled(url,
|
|
2390
|
+
function walled(url, stage2, dir = FH_EVIDENCE_DIR) {
|
|
2391
2391
|
const h = host(url);
|
|
2392
2392
|
if (!h) return null;
|
|
2393
2393
|
const all = read(dir, h);
|
|
2394
|
-
const r = all[
|
|
2394
|
+
const r = all[stage2] ?? all[legacy(stage2)];
|
|
2395
2395
|
return r && r.streak >= WALL_STREAK && daysSince(r.date) < settings().retry_after_days ? r : null;
|
|
2396
2396
|
}
|
|
2397
|
-
function
|
|
2397
|
+
function recordStage(url, stage2, ok, reason = "", dir = FH_EVIDENCE_DIR) {
|
|
2398
2398
|
const h = host(url);
|
|
2399
2399
|
if (!h) return;
|
|
2400
2400
|
const why = reason.replace(/^((?:playwright|chrome|browser|fetch-proxy) [^:]+|brightdata): /, "");
|
|
2401
2401
|
if (!ok && !WALL2.test(why)) return;
|
|
2402
2402
|
const all = read(dir, h);
|
|
2403
|
-
const lk = legacy(
|
|
2404
|
-
if (lk !==
|
|
2405
|
-
all[
|
|
2403
|
+
const lk = legacy(stage2);
|
|
2404
|
+
if (lk !== stage2 && all[lk]) {
|
|
2405
|
+
all[stage2] ??= all[lk];
|
|
2406
2406
|
delete all[lk];
|
|
2407
2407
|
}
|
|
2408
2408
|
if (ok) {
|
|
2409
|
-
if (!all[
|
|
2410
|
-
delete all[
|
|
2411
|
-
} else all[
|
|
2409
|
+
if (!all[stage2]) return;
|
|
2410
|
+
delete all[stage2];
|
|
2411
|
+
} else all[stage2] = { streak: (all[stage2]?.streak ?? 0) + 1, date: now(), reason: why };
|
|
2412
2412
|
try {
|
|
2413
2413
|
mkdirSync3(join5(dir, "walls"), { recursive: true });
|
|
2414
2414
|
writeAtomic(file(dir, h), JSON.stringify(all) + "\n");
|
|
@@ -2469,25 +2469,25 @@ async function download(tier, p, candidates, ctx) {
|
|
|
2469
2469
|
if (w) ctx.onTry?.(`${target.url} skipped ${name}: ${wallNote(w)}`);
|
|
2470
2470
|
else {
|
|
2471
2471
|
r = note(await tryOne(p, target, tier, { proxy: f.proxy, label: f.label }));
|
|
2472
|
-
|
|
2472
|
+
recordStage(target.url, name, r.ok, r.ok ? "" : r.reason);
|
|
2473
2473
|
ctx.onTry?.(r.ok ? `${target.url} ok ${name}` : `${target.url} failed ${name}: ${bare(r.reason)}`);
|
|
2474
2474
|
}
|
|
2475
2475
|
}
|
|
2476
2476
|
const UNLOCK = /^(HTTP 403|wall page)/;
|
|
2477
2477
|
let browsed = false;
|
|
2478
|
-
for (const b of
|
|
2478
|
+
for (const b of browserStages()) {
|
|
2479
2479
|
if (r.ok) break;
|
|
2480
2480
|
const climbs = browsed ? climbsOn(r.reason, true) : climbsOn(plainReason) || climbsOn(bare(r.reason));
|
|
2481
2481
|
if (c.headers || c.service || !climbs) break;
|
|
2482
2482
|
browsed = true;
|
|
2483
|
-
const name =
|
|
2483
|
+
const name = stageName(b);
|
|
2484
2484
|
const w = walled(target.url, name);
|
|
2485
2485
|
if (w) {
|
|
2486
2486
|
ctx.onTry?.(`${target.url} skipped ${name}: ${wallNote(w)}`);
|
|
2487
2487
|
continue;
|
|
2488
2488
|
}
|
|
2489
2489
|
r = note(await tryOne(p, target, tier, { browser: b.endpoint, label: b.label }));
|
|
2490
|
-
|
|
2490
|
+
recordStage(target.url, name, r.ok, r.ok ? "" : r.reason);
|
|
2491
2491
|
ctx.onTry?.(r.ok ? `${target.url} ok ${name}` : `${target.url} failed ${name}: ${bare(r.reason)}`);
|
|
2492
2492
|
if (!r.ok && bare(r.reason).startsWith(MISMATCH)) ctx.onAlert?.(`${name}: ${bare(r.reason)}`);
|
|
2493
2493
|
}
|
|
@@ -2495,7 +2495,7 @@ async function download(tier, p, candidates, ctx) {
|
|
|
2495
2495
|
if (uw && !r.ok && !c.headers && !c.service && unlockerConfigured()) ctx.onTry?.(`${target.url} skipped brightdata: ${wallNote(uw)}`);
|
|
2496
2496
|
else if (!r.ok && !c.headers && !c.service && unlockerConfigured() && (browsed ? /^(HTTP 403|wall page|playwright |chrome |browser )/.test(why(r.reason)) : UNLOCK.test(plainReason) || UNLOCK.test(why(bare(r.reason))))) {
|
|
2497
2497
|
r = note(await tryOne(p, target, tier, "unlocker"));
|
|
2498
|
-
|
|
2498
|
+
recordStage(target.url, "brightdata", r.ok, r.ok ? "" : r.reason);
|
|
2499
2499
|
ctx.onTry?.(r.ok ? `${target.url} ok brightdata` : `${target.url} failed brightdata: ${bare(r.reason)}`);
|
|
2500
2500
|
if (!r.ok && /^unlocker HTTP 4\d\d/.test(bare(r.reason))) ctx.onAlert?.(`brightdata: ${bare(r.reason)}`);
|
|
2501
2501
|
}
|
|
@@ -2513,8 +2513,8 @@ function climbsOn(reason, afterBrowser = false) {
|
|
|
2513
2513
|
const r = reason.replace(/^not a pdf \((.*)\)$/, "$1");
|
|
2514
2514
|
return CLIMB.test(r) || afterBrowser && /^(playwright|chrome|browser) /.test(r);
|
|
2515
2515
|
}
|
|
2516
|
-
var viaPrefix = (via) => via === "plain" ? "" : via === "unlocker" ? "brightdata: " : "proxy" in via ? `${fetchProxyName(via)}: ` : `${
|
|
2517
|
-
var bare = (reason) => reason.replace(/^brightdata: /, "").replace(
|
|
2516
|
+
var viaPrefix = (via) => via === "plain" ? "" : via === "unlocker" ? "brightdata: " : "proxy" in via ? `${fetchProxyName(via)}: ` : `${stageName({ kind: stageKind(via.browser), label: via.label })}: `;
|
|
2517
|
+
var bare = (reason) => reason.replace(/^brightdata: /, "").replace(STAGE_PREFIX, "");
|
|
2518
2518
|
async function tryOne(p, c, tier, via = "plain") {
|
|
2519
2519
|
let got;
|
|
2520
2520
|
try {
|
|
@@ -3120,10 +3120,10 @@ import { z } from "zod";
|
|
|
3120
3120
|
// src/cascade.ts
|
|
3121
3121
|
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;
|
|
3122
3122
|
var BLOCKED = /^(challenge not cleared|empty response)/i;
|
|
3123
|
-
var
|
|
3123
|
+
var STAGE = /^((?:playwright|chrome|browser|fetch-proxy) [^:]+|brightdata|unlocker): /;
|
|
3124
3124
|
function isPermanent(reason, retryBlocked = false) {
|
|
3125
3125
|
return reason.split(";").every((r) => {
|
|
3126
|
-
const b = r.trim().replace(
|
|
3126
|
+
const b = r.trim().replace(STAGE, "");
|
|
3127
3127
|
return PERMANENT.test(b) || !retryBlocked && BLOCKED.test(b);
|
|
3128
3128
|
});
|
|
3129
3129
|
}
|
|
@@ -3496,8 +3496,8 @@ function verifyInfo() {
|
|
|
3496
3496
|
return v ? { model: v.model, base_url: v.base_url, local: isLocal(v.base_url) } : null;
|
|
3497
3497
|
}
|
|
3498
3498
|
function downloadInfo() {
|
|
3499
|
-
const
|
|
3500
|
-
return { fetch: true, fetch_proxy: fetchProxy(), playwright: { version: PLAYWRIGHT_VERSION, servers:
|
|
3499
|
+
const stages = browserStages();
|
|
3500
|
+
return { fetch: true, fetch_proxy: fetchProxy(), playwright: { version: PLAYWRIGHT_VERSION, servers: stages.filter((b) => b.kind === "playwright") }, chrome: stages.filter((b) => b.kind === "chrome"), unlocker: unlockerConfigured() };
|
|
3501
3501
|
}
|
|
3502
3502
|
|
|
3503
3503
|
// src/read.ts
|
|
@@ -4078,8 +4078,8 @@ function isScriptShell(markdownOrHtml) {
|
|
|
4078
4078
|
const words3 = text4.split(/\s+/).filter((w) => /[\p{L}\p{N}]/u.test(w)).length;
|
|
4079
4079
|
return { shell: words3 < EMPTY_WORDS || words3 < SHELL_WORDS && SHELL_PHRASE.test(text4), words: words3 };
|
|
4080
4080
|
}
|
|
4081
|
-
var viaName = (via) => typeof via === "object" ? "proxy" in via ? fetchProxyName(via) :
|
|
4082
|
-
async function
|
|
4081
|
+
var viaName = (via) => typeof via === "object" ? "proxy" in via ? fetchProxyName(via) : stageName({ kind: stageKind(via.browser), label: via.label }) : via;
|
|
4082
|
+
async function stage(url, via) {
|
|
4083
4083
|
const name = viaName(via);
|
|
4084
4084
|
let got;
|
|
4085
4085
|
try {
|
|
@@ -4105,7 +4105,7 @@ async function rung(url, via) {
|
|
|
4105
4105
|
return r;
|
|
4106
4106
|
}
|
|
4107
4107
|
var climb = async (url, onTry, onAlert) => {
|
|
4108
|
-
let r = await
|
|
4108
|
+
let r = await stage(url, "fetch");
|
|
4109
4109
|
const firstReason = r.ok ? void 0 : r.reason;
|
|
4110
4110
|
let gone;
|
|
4111
4111
|
const seen = (g) => {
|
|
@@ -4126,22 +4126,22 @@ var climb = async (url, onTry, onAlert) => {
|
|
|
4126
4126
|
const w = walled(target, name);
|
|
4127
4127
|
if (w) onTry?.(`skipped ${name}: ${wallNote(w)}`);
|
|
4128
4128
|
else {
|
|
4129
|
-
r = seen(await
|
|
4130
|
-
|
|
4129
|
+
r = seen(await stage(target, { proxy: f.proxy, label: f.label }));
|
|
4130
|
+
recordStage(target, name, r.ok, r.ok ? "" : r.reason);
|
|
4131
4131
|
if (!r.ok && r.shell && !shell) shell = r.shell;
|
|
4132
4132
|
onTry?.(r.ok ? `ok ${name}` : `failed ${name}: ${r.reason}`);
|
|
4133
4133
|
}
|
|
4134
4134
|
}
|
|
4135
|
-
for (const b of
|
|
4135
|
+
for (const b of browserStages()) {
|
|
4136
4136
|
if (!escalates(r)) break;
|
|
4137
|
-
const name =
|
|
4137
|
+
const name = stageName(b);
|
|
4138
4138
|
const w = walled(target, name);
|
|
4139
4139
|
if (w) {
|
|
4140
4140
|
onTry?.(`skipped ${name}: ${wallNote(w)}`);
|
|
4141
4141
|
continue;
|
|
4142
4142
|
}
|
|
4143
|
-
r = seen(await
|
|
4144
|
-
|
|
4143
|
+
r = seen(await stage(target, { browser: b.endpoint, label: b.label }));
|
|
4144
|
+
recordStage(target, name, r.ok, r.ok ? "" : r.reason);
|
|
4145
4145
|
if (!r.ok && r.shell && !shell) shell = r.shell;
|
|
4146
4146
|
onTry?.(r.ok ? `ok ${name}` : `failed ${name}: ${r.reason}`);
|
|
4147
4147
|
if (!r.ok && r.reason.startsWith(MISMATCH)) onAlert?.(`${name}: ${r.reason}`);
|
|
@@ -4149,13 +4149,13 @@ var climb = async (url, onTry, onAlert) => {
|
|
|
4149
4149
|
const uw = !r.ok && unlockerConfigured() ? walled(target, "brightdata") : null;
|
|
4150
4150
|
if (uw) onTry?.(`skipped brightdata: ${wallNote(uw)}`);
|
|
4151
4151
|
else if (!r.ok && unlockerConfigured() && (!plainVia(r) || met(r, /^(HTTP 403|wall page|script shell)/))) {
|
|
4152
|
-
r = seen(await
|
|
4153
|
-
|
|
4152
|
+
r = seen(await stage(target, "brightdata"));
|
|
4153
|
+
recordStage(target, "brightdata", r.ok, r.ok ? "" : r.reason);
|
|
4154
4154
|
onTry?.(r.ok ? "ok brightdata" : `failed brightdata: ${r.reason}`);
|
|
4155
4155
|
if (!r.ok && /^unlocker HTTP 4\d\d/.test(r.reason)) onAlert?.(`brightdata: ${r.reason}`);
|
|
4156
4156
|
}
|
|
4157
4157
|
if (!r.ok && shell) {
|
|
4158
|
-
onTry?.("shell kept: no
|
|
4158
|
+
onTry?.("shell kept: no stage rendered the page, the script shell is served");
|
|
4159
4159
|
return shell;
|
|
4160
4160
|
}
|
|
4161
4161
|
return r.ok || r.via === "fetch" ? r : { ...r, first: gone ?? firstReason };
|
|
@@ -4978,7 +4978,7 @@ Tools
|
|
|
4978
4978
|
- fh_clinicaltrials_search_studies(query | intervention | condition, status?, sort?, max_results?) \u2014 search ClinicalTrials.gov: the total and rows in columns order (NCT ID, title, status, phase, enrollment, dates, primary outcome, conditions, interventions, has_results). Cached a week.
|
|
4979
4979
|
- fh_clinicaltrials_get_study_record(nct) \u2014 one trial as a review needs it (status, design, enrollment, dates, outcomes, eligibility, result publications, summary), from the stored record; added first when missing.
|
|
4980
4980
|
- fh_clinicaltrials_get_study_results(nct, max_chars?) \u2014 a trial's posted results as Markdown, capped; the outcome titles listed for fh_library_read.
|
|
4981
|
-
- fh_fetch_url(url, max_length?, start_index?, raw?, title_only?) \u2014 a web page as Markdown, same call and same answer as the standard fetch tool ("Contents of <url>:" and the page, cut at max_length with a note on how to continue). Prefer it for every URL: a cached page answers from disk, a walled or script-rendered page
|
|
4981
|
+
- fh_fetch_url(url, max_length?, start_index?, raw?, title_only?) \u2014 a web page as Markdown, same call and same answer as the standard fetch tool ("Contents of <url>:" and the page, cut at max_length with a note on how to continue). Prefer it for every URL: a cached page answers from disk, a walled or script-rendered page runs through the browser and unlocker stages in one call. PDFs as Markdown. title_only returns the title line alone \u2014 enough to verify a link, at a few tokens.
|
|
4982
4982
|
|
|
4983
4983
|
Hints
|
|
4984
4984
|
- fh_library_read and fh_verify_claim store a missing record themselves; the fh_library_read answer then carries added: true. No fh_library_add necessary first.
|
|
@@ -5436,7 +5436,7 @@ ${st.funding.map((f) => `- ${f}`).join("\n")}` : ""].filter(Boolean).join("\n\n"
|
|
|
5436
5436
|
);
|
|
5437
5437
|
server2.tool(
|
|
5438
5438
|
"fh_info",
|
|
5439
|
-
"The server and the whole library as JSON: this server's package name and version (which build is loaded), its log file; evidence directory (evidence_dir) and host; entry count and size on disk; per type (pmid, doi, dailymed, nct) the entries by level (full_text, abstract, title) and retractions; counts of retracted and not-citable entries and of errata, expressions of concern and updates; the retrieval sources in run order and which are off (tiers); the download
|
|
5439
|
+
"The server and the whole library as JSON: this server's package name and version (which build is loaded), its log file; evidence directory (evidence_dir) and host; entry count and size on disk; per type (pmid, doi, dailymed, nct) the entries by level (full_text, abstract, title) and retractions; counts of retracted and not-citable entries and of errata, expressions of concern and updates; the retrieval sources in run order and which are off (tiers); the multi-stage download (download): the Playwright servers with the version they must run, the Chrome stages, the Bright Data unlocker; the configuration and where each value came from \u2014 environment, .env or default, never the value (config); the decision model behind fh_verify_claim and whether it answers right now (verify); this server's cache hits and misses for fh_verify_claim and fh_fetch_url since it started (cache).",
|
|
5440
5440
|
{},
|
|
5441
5441
|
async () => {
|
|
5442
5442
|
const info = libraryInfo(FH_EVIDENCE_DIR, HOST);
|