evidence-mcp-dev 1.0.23 → 1.0.24
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 +28 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4529,13 +4529,13 @@ var FIELDS2 = ["relevance", "population", "design", "n", "outcome", "finding", "
|
|
|
4529
4529
|
var SCHEMA = {
|
|
4530
4530
|
type: "object",
|
|
4531
4531
|
properties: {
|
|
4532
|
-
relevance: { type: "string", enum: ["direct", "indirect", "background", "off-topic"], description: "direct: the intervention
|
|
4532
|
+
relevance: { type: "string", enum: ["direct", "indirect", "background", "off-topic"], description: "direct: the topic's intervention itself studied in humans, any outcome, with or without comparators; indirect: a broader category it belongs to, a related intervention, or it pooled with others without its own result; background: animal, in vitro, mechanism, epidemiology; off-topic: not about the topic" },
|
|
4533
4533
|
population: { type: "string", enum: ["humans", "animals", "in vitro", "none"] },
|
|
4534
4534
|
design: { type: "string", description: "study design, e.g. meta-analysis, systematic review, RCT, cohort, case-control, case report, review, animal study, in vitro" },
|
|
4535
4535
|
n: { type: ["integer", "null"], description: "participants, if the abstract states it" },
|
|
4536
4536
|
outcome: { type: "string", enum: ["hard", "surrogate", "none"], description: "hard: death, incidence, clinical events; surrogate: biomarker, imaging" },
|
|
4537
|
-
finding: { type: "string", enum: ["benefit", "no effect", "harm", "mixed", "none"] },
|
|
4538
|
-
aspect: { type: "string", enum: ["efficacy", "safety", "mechanism", "dosing", "interaction", "other"] },
|
|
4537
|
+
finding: { type: "string", enum: ["benefit", "no effect", "harm", "mixed", "none"], description: "the intervention's effect; harm: caused by the intervention, not by the effect it achieved" },
|
|
4538
|
+
aspect: { type: "string", enum: ["efficacy", "safety", "mechanism", "dosing", "interaction", "other"], description: "efficacy: any benefit outcome, null results too; safety: adverse effects" },
|
|
4539
4539
|
reason: { type: "string", description: "one sentence: what the paper adds to the topic" }
|
|
4540
4540
|
},
|
|
4541
4541
|
required: [...FIELDS2],
|
|
@@ -4551,6 +4551,11 @@ var ScreenError = class extends Error {
|
|
|
4551
4551
|
}
|
|
4552
4552
|
status;
|
|
4553
4553
|
};
|
|
4554
|
+
var Refusal = class extends Error {
|
|
4555
|
+
constructor() {
|
|
4556
|
+
super("refusal");
|
|
4557
|
+
}
|
|
4558
|
+
};
|
|
4554
4559
|
var PLAIN = { key: "FH_EVMAP_SCREEN_API_KEY", model: "FH_EVMAP_SCREEN_MODEL", url: "FH_EVMAP_SCREEN_URL" };
|
|
4555
4560
|
function hint(status, message, v = PLAIN) {
|
|
4556
4561
|
if (status === 401 || status === 403 || /api key|api_key|x-api-key|unauthori[sz]ed|permission/i.test(message)) return `the API key is missing, wrong or has no access to the model \u2014 ${v.key} in the server's .env`;
|
|
@@ -4584,7 +4589,7 @@ function askFor(c) {
|
|
|
4584
4589
|
try {
|
|
4585
4590
|
return await ask(text4);
|
|
4586
4591
|
} catch (e) {
|
|
4587
|
-
throw new Error(describe2(e, where(c), c.vars));
|
|
4592
|
+
throw e instanceof Refusal ? e : new Error(describe2(e, where(c), c.vars));
|
|
4588
4593
|
}
|
|
4589
4594
|
};
|
|
4590
4595
|
}
|
|
@@ -4597,7 +4602,7 @@ function anthropicAsk(apiKey2, model, baseURL) {
|
|
|
4597
4602
|
output_config: { effort: "low", format: { type: "json_schema", schema: SCHEMA } },
|
|
4598
4603
|
messages: [{ role: "user", content: text4 }]
|
|
4599
4604
|
});
|
|
4600
|
-
if (r.stop_reason === "refusal") throw new
|
|
4605
|
+
if (r.stop_reason === "refusal") throw new Refusal();
|
|
4601
4606
|
if (r.stop_reason === "max_tokens") throw new Error("max_tokens: the answer was cut off");
|
|
4602
4607
|
const block = r.content.find((b) => b.type === "text");
|
|
4603
4608
|
if (!block) throw new Error("no answer");
|
|
@@ -4627,7 +4632,7 @@ function openaiAsk(baseUrl, apiKey2, model, fetchImpl = fetch) {
|
|
|
4627
4632
|
const choice = body?.choices?.[0];
|
|
4628
4633
|
if (choice?.finish_reason === "length") throw new Error("max_tokens: the answer was cut off");
|
|
4629
4634
|
const content = choice?.message?.content;
|
|
4630
|
-
if (typeof content !== "string") throw
|
|
4635
|
+
if (typeof content !== "string") throw choice?.message?.refusal ? new Refusal() : new Error("no answer");
|
|
4631
4636
|
return parseAnswer(content);
|
|
4632
4637
|
}
|
|
4633
4638
|
};
|
|
@@ -4640,6 +4645,7 @@ function parseAnswer(text4) {
|
|
|
4640
4645
|
throw new Error(`the answer is not JSON: ${text4.slice(0, 80)}`);
|
|
4641
4646
|
}
|
|
4642
4647
|
if (!a || typeof a !== "object" || !SCHEMA.properties.relevance.enum.includes(a.relevance)) throw new Error(`the answer has no valid relevance: ${text4.slice(0, 80)}`);
|
|
4648
|
+
if (typeof a.reason === "string") a.reason = a.reason.replace(/[\s{}[\]"]+$/, "");
|
|
4643
4649
|
return a;
|
|
4644
4650
|
}
|
|
4645
4651
|
async function screenAll(lib, pmids, prompt, topic, paper, ask, model, parallel, note = () => {
|
|
@@ -4654,7 +4660,8 @@ async function screenAll(lib, pmids, prompt, topic, paper, ask, model, parallel,
|
|
|
4654
4660
|
const file3 = join9(dir, `${pmid}.json`);
|
|
4655
4661
|
if (existsSync10(file3)) {
|
|
4656
4662
|
try {
|
|
4657
|
-
|
|
4663
|
+
const c = JSON.parse(readFileSync8(file3, "utf8"));
|
|
4664
|
+
out[i] = c?.refused === true ? { pmid, refused: true, cached: true } : { pmid, screened: c, cached: true };
|
|
4658
4665
|
continue;
|
|
4659
4666
|
} catch {
|
|
4660
4667
|
}
|
|
@@ -4672,7 +4679,11 @@ async function screenAll(lib, pmids, prompt, topic, paper, ask, model, parallel,
|
|
|
4672
4679
|
writeAtomic(file3, JSON.stringify(s) + "\n");
|
|
4673
4680
|
out[i] = { pmid, screened: s, cached: false };
|
|
4674
4681
|
} catch (e) {
|
|
4675
|
-
|
|
4682
|
+
if (e instanceof Refusal) {
|
|
4683
|
+
mkdirSync8(dirname4(file3), { recursive: true });
|
|
4684
|
+
writeAtomic(file3, '{"refused":true}\n');
|
|
4685
|
+
out[i] = { pmid, refused: true, cached: false };
|
|
4686
|
+
} else out[i] = { pmid, error: e instanceof Error ? e.message : String(e), cached: false };
|
|
4676
4687
|
}
|
|
4677
4688
|
note(out[i], Date.now() - t);
|
|
4678
4689
|
}
|
|
@@ -4692,6 +4703,7 @@ function score(s, types, queries, citesPerYear = 0, inReviews = 0) {
|
|
|
4692
4703
|
}
|
|
4693
4704
|
function screenLine(r, ms, model) {
|
|
4694
4705
|
const secs = `${(ms / 1e3).toFixed(1)}s`;
|
|
4706
|
+
if (r.refused) return `refused screen ${model} ${secs}`;
|
|
4695
4707
|
if (!r.screened) return `failed screen ${model} ${secs}: ${r.error}`;
|
|
4696
4708
|
const f = r.screened;
|
|
4697
4709
|
return `screened ${f.relevance} \xB7 ${f.population} \xB7 ${f.design} \xB7 n=${f.n ?? "-"} \xB7 ${f.outcome} \xB7 ${f.finding} \xB7 ${f.aspect} \xB7 ${model} ${secs} \xB7 ${f.reason}`;
|
|
@@ -4923,7 +4935,7 @@ var RANK_MODELS = { anthropic: "claude-opus-5-5", openai: "gpt-5.5", google: "ge
|
|
|
4923
4935
|
var RANK_TIMEOUT_MS = 18e4;
|
|
4924
4936
|
function rankPrompt(topic, rows, picks) {
|
|
4925
4937
|
const list5 = rows.map((x, i) => `${i + 1}. ${x.title ?? "(no title)"} (${x.year ?? "-"}; ${x.design || "-"}; n=${x.n ?? "-"}; ${x.relevance}; ${x.aspect}; ${x.signals})`).join("\n");
|
|
4926
|
-
return `Below are ${rows.length} candidate articles on the topic "${topic}". Pick the ${picks} that matter most \u2014 the key trials and meta-analyses for each important question, including safety and the null results. Answer with their numbers, most important first.
|
|
4938
|
+
return `Below are ${rows.length} candidate articles on the topic "${topic}". Pick the ${picks} that matter most \u2014 the key trials and meta-analyses for each important question, including safety and the null results; only articles that study the topic's intervention itself. Answer with their numbers, most important first.
|
|
4927
4939
|
|
|
4928
4940
|
${list5}`;
|
|
4929
4941
|
}
|
|
@@ -5199,7 +5211,7 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
|
|
|
5199
5211
|
}
|
|
5200
5212
|
scored = kept.map(scoreOf);
|
|
5201
5213
|
}
|
|
5202
|
-
const screenedCsv = [["pmid", "kept", "error", ...FIELDS2].join(","), ...scored.map(({ p, f, sc }) => [p.pmid, sc === null ? "" : sc > 0 ? "yes" : "no", by.get(p.pmid)?.error ?? "", ...FIELDS2.map((k) => f?.[k] ?? "")].map(csvCell).join(","))].join("\n") + "\n";
|
|
5214
|
+
const screenedCsv = [["pmid", "kept", "error", ...FIELDS2].join(","), ...scored.map(({ p, f, sc }) => [p.pmid, sc === null ? "" : sc > 0 ? "yes" : "no", by.get(p.pmid)?.error ?? (by.get(p.pmid)?.refused ? "refused" : ""), ...FIELDS2.map((k) => f?.[k] ?? "")].map(csvCell).join(","))].join("\n") + "\n";
|
|
5203
5215
|
let ranked = scored.filter(({ sc }) => sc !== 0).sort((a, b) => (b.sc ?? -1) - (a.sc ?? -1));
|
|
5204
5216
|
const pick = /* @__PURE__ */ new Map();
|
|
5205
5217
|
let rankRun = { off: true };
|
|
@@ -5221,7 +5233,8 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
|
|
|
5221
5233
|
const lines = ranked.map(({ p, f, sc }) => row3(p, sc ?? "", pick.get(p.pmid) ?? "", signals(p), f));
|
|
5222
5234
|
const count = (k) => results2.filter((r) => r.screened?.relevance === k).length;
|
|
5223
5235
|
const failures = results2.filter((r) => r.error);
|
|
5224
|
-
const
|
|
5236
|
+
const refused = results2.filter((r) => r.refused).length;
|
|
5237
|
+
const screenRun = { screened: results2.filter((r) => r.screened).length, not_screened: failures.length, refused, ...failures.length ? { first_error: failures[0].error } : {}, excluded: count("off-topic"), relevance: { direct: count("direct"), indirect: count("indirect"), background: count("background") }, cached: results2.filter((r) => r.cached).length, citations: { counted: cites.size, failed: counted.failed }, citation_searching: { reviews: K, identified: fromReviews, failed: refsFailed }, ranking: rankRun, seconds: Math.round((Date.now() - t) / 1e3) };
|
|
5225
5238
|
const hash = cacheKey(model, screening, topic);
|
|
5226
5239
|
const state = "screened";
|
|
5227
5240
|
const finished = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -5245,7 +5258,7 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
|
|
|
5245
5258
|
const sUp = db.prepare("UPDATE articles SET relevance = ?, population = ?, design = ?, n = ?, outcome = ?, finding = ?, aspect = ?, reason = ?, error = ? WHERE pmid = ?");
|
|
5246
5259
|
for (const r of results2) {
|
|
5247
5260
|
const f = r.screened;
|
|
5248
|
-
sUp.run(f?.relevance ?? null, f?.population ?? null, f?.design ?? null, typeof f?.n === "number" ? f.n : null, f?.outcome ?? null, f?.finding ?? null, f?.aspect ?? null, f?.reason ?? null, r.error ?? null, r.pmid);
|
|
5261
|
+
sUp.run(f?.relevance ?? null, f?.population ?? null, f?.design ?? null, typeof f?.n === "number" ? f.n : null, f?.outcome ?? null, f?.finding ?? null, f?.aspect ?? null, f?.reason ?? null, r.error ?? (r.refused ? "refused" : null), r.pmid);
|
|
5249
5262
|
}
|
|
5250
5263
|
db.exec("UPDATE articles SET score = NULL, pick = NULL");
|
|
5251
5264
|
const rUp = db.prepare("UPDATE articles SET score = ?, pick = ? WHERE pmid = ?");
|
|
@@ -5267,9 +5280,10 @@ Publication types: ${papers.get(pmid).types ?? "none listed"}`;
|
|
|
5267
5280
|
db.close();
|
|
5268
5281
|
const partial = failures.length ? { screening_errors: failures.length, first_error: failures[0].error, note: `${failures.length} of ${results2.length} papers could not be screened; they stay in the map, unscored, at the end. Call again to retry only those: screened papers answer from the cache.` } : {};
|
|
5269
5282
|
const rankFailed = typeof rankRun.error === "string" ? { ranking_error: `the map is in score order: the re-ranking failed (${rankRun.error})` } : {};
|
|
5283
|
+
const citesFailed = counted.failed || refsFailed ? { citations_error: `citation counts failed for ${counted.failed} of ${kept.length} articles, reference lists for ${refsFailed} of ${reviewIds.length} reviews${counted.error ? ` (${counted.error})` : ""}: the order is weaker. Call again later with the evid and the same queries: searches and screening answer from the cache.` } : {};
|
|
5270
5284
|
const failedQueries = runs.filter((r) => r.error).map((r) => ({ query: r.query, error: r.error }));
|
|
5271
5285
|
const emptyQueries = runs.filter((r) => !r.error && r.total === 0).map((r) => r.query);
|
|
5272
|
-
return { ok: true, evid: o.evid, included: lines.length, ...failedQueries.length ? { failed_queries: failedQueries } : {}, ...emptyQueries.length ? { empty_queries: emptyQueries } : {}, ...partial, ...rankFailed };
|
|
5286
|
+
return { ok: true, evid: o.evid, included: lines.length, ...failedQueries.length ? { failed_queries: failedQueries } : {}, ...emptyQueries.length ? { empty_queries: emptyQueries } : {}, ...partial, ...rankFailed, ...citesFailed };
|
|
5273
5287
|
}
|
|
5274
5288
|
var MAX_ROWS = 500;
|
|
5275
5289
|
function getMap(lib, evid, opts = {}) {
|
|
@@ -7725,7 +7739,7 @@ Citations from OpenAlex. Cached ${searchCacheDays()} days.`,
|
|
|
7725
7739
|
log("evid", evid, `create topic=${topic.trim()}`);
|
|
7726
7740
|
}
|
|
7727
7741
|
const r = await doResearch(FH_EVIDENCE_DIR, evid, queries, screening);
|
|
7728
|
-
log("evmap", evid, r.ok ? `created queries=${queries.length} articles=${r.included}${r.failed_queries ? ` failed_queries=${r.failed_queries.length}` : ""}${r.empty_queries ? ` empty_queries=${r.empty_queries.length}` : ""}${r.screening_errors ? ` screening_errors=${r.screening_errors}` : ""}` : `${r.failed ? "failed" : "error"} ${r.error}`);
|
|
7742
|
+
log("evmap", evid, r.ok ? `created queries=${queries.length} articles=${r.included}${r.failed_queries ? ` failed_queries=${r.failed_queries.length}` : ""}${r.empty_queries ? ` empty_queries=${r.empty_queries.length}` : ""}${r.screening_errors ? ` screening_errors=${r.screening_errors}` : ""}${r.citations_error ? " citations_failed" : ""}` : `${r.failed ? "failed" : "error"} ${r.error}`);
|
|
7729
7743
|
const { ok, ...rest } = r;
|
|
7730
7744
|
return { content: [{ type: "text", text: compact2(rest) }], ...ok ? {} : { isError: true } };
|
|
7731
7745
|
}
|