evidence-mcp-dev 1.0.28 → 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.
Files changed (2) hide show
  1. package/dist/index.js +88 -65
  2. 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
- try {
250
- const { address, family } = await lookup(host3);
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";
@@ -2734,13 +2757,13 @@ var hostOf2 = (url) => {
2734
2757
  }
2735
2758
  };
2736
2759
  var NCBI = /^https?:\/\/([a-z0-9.-]+\.)?(ncbi\.nlm\.nih\.gov|pubmed\.gov)\//i;
2737
- function order(candidates) {
2760
+ function order(candidates2) {
2738
2761
  const rank = (c) => (c.pdf ? 0 : 2) + (c.host === "publisher" ? 1 : 0);
2739
- return [...candidates].sort((a, b) => rank(a) - rank(b));
2762
+ return [...candidates2].sort((a, b) => rank(a) - rank(b));
2740
2763
  }
2741
- async function download(tier, p, candidates, ctx) {
2742
- const usable = candidates.filter((c) => !NCBI.test(c.url));
2743
- if (!usable.length && candidates.length) return miss(tier, "only pmc copies (covered by the pmc tier)");
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)");
2744
2767
  const ordered = order(usable.map((c) => {
2745
2768
  const u = toHttps(c.url);
2746
2769
  if (u !== c.url) ctx.onTry?.(`http upgraded: ${c.url} \u2192 ${u}`);
@@ -2993,10 +3016,10 @@ function coreTier(apiKey2) {
2993
3016
  } catch (e) {
2994
3017
  return miss(this.name, errMsg(e));
2995
3018
  }
2996
- const candidates = coreCandidates(data);
2997
- if (!candidates.length) return miss(this.name, data.results?.length ? "no full text" : "not in core");
2998
- ctx.onTry?.(`located ${candidates.length} copies`);
2999
- return download(this.name, p, candidates, ctx);
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);
3000
3023
  }
3001
3024
  };
3002
3025
  }
@@ -3030,10 +3053,10 @@ var europepmc = {
3030
3053
  }
3031
3054
  const rec = data.resultList?.result?.[0];
3032
3055
  if (!rec) return miss(this.name, "not in europe pmc");
3033
- const candidates = europepmcCandidates(rec, p.pmcid);
3034
- if (!candidates.length) return miss(this.name, "no free copy");
3035
- ctx.onTry?.(`located ${candidates.length} copies`);
3036
- return download(this.name, p, candidates, ctx);
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);
3037
3060
  }
3038
3061
  };
3039
3062
  function europepmcCandidates(r, pmcid) {
@@ -3071,10 +3094,10 @@ var openalex = {
3071
3094
  } catch (e) {
3072
3095
  return miss(this.name, errMsg(e));
3073
3096
  }
3074
- const candidates = openalexCandidates(data);
3075
- if (!candidates.length) return miss(this.name, data.open_access?.is_oa === false ? "closed" : "no oa copy");
3076
- ctx.onTry?.(`located ${candidates.length} copies`);
3077
- return download(this.name, p, candidates, ctx);
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);
3078
3101
  }
3079
3102
  };
3080
3103
  function openalexCandidates(d) {
@@ -3137,12 +3160,12 @@ var hostOf3 = (url) => {
3137
3160
  function tdmCandidates(work, tokens2 = {}, env = process.env) {
3138
3161
  const links = (work.message?.link ?? []).filter((l) => l["intended-application"] === "text-mining" && l.URL);
3139
3162
  const seen2 = /* @__PURE__ */ new Set();
3140
- const candidates = [];
3163
+ const candidates2 = [];
3141
3164
  const missingTokens = /* @__PURE__ */ new Set();
3142
3165
  for (const l of links) {
3143
3166
  const ct = (l["content-type"] ?? "").toLowerCase();
3144
3167
  if (seen2.has(l.URL)) {
3145
- const prev = candidates.find((c) => c.url === l.URL);
3168
+ const prev = candidates2.find((c) => c.url === l.URL);
3146
3169
  if (prev && /pdf/.test(ct)) prev.pdf = true;
3147
3170
  continue;
3148
3171
  }
@@ -3158,11 +3181,11 @@ function tdmCandidates(work, tokens2 = {}, env = process.env) {
3158
3181
  headers = { [rule.header]: token };
3159
3182
  }
3160
3183
  if (/text\/plain/.test(ct)) continue;
3161
- candidates.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 });
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 });
3162
3185
  }
3163
3186
  const rank = (c) => /\/xml|text\/xml/.test(c.url) ? 0 : c.pdf ? 1 : 2;
3164
- candidates.sort((a, b) => rank(a) - rank(b));
3165
- return { candidates, missingTokens: [...missingTokens] };
3187
+ candidates2.sort((a, b) => rank(a) - rank(b));
3188
+ return { candidates: candidates2, missingTokens: [...missingTokens] };
3166
3189
  }
3167
3190
  function tdmTier(tokens2 = {}) {
3168
3191
  return {
@@ -3176,10 +3199,10 @@ function tdmTier(tokens2 = {}) {
3176
3199
  } catch (e) {
3177
3200
  return miss(this.name, errMsg(e));
3178
3201
  }
3179
- const { candidates, missingTokens } = tdmCandidates(work, tokens2);
3180
- if (!candidates.length) return missingTokens.length ? { ...miss(this.name, `needs ${missingTokens.join("/")} token`), skipped: true } : miss(this.name, "no text-mining links");
3181
- ctx.onTry?.(`${candidates.length} text-mining links${missingTokens.length ? ` (skipped hosts needing ${missingTokens.join("/")} token)` : ""}`);
3182
- return download(this.name, p, candidates, ctx);
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);
3183
3206
  }
3184
3207
  };
3185
3208
  }
@@ -3197,10 +3220,10 @@ var unpaywall = {
3197
3220
  } catch (e) {
3198
3221
  return miss(this.name, errMsg(e));
3199
3222
  }
3200
- const candidates = unpaywallCandidates(data);
3201
- if (!candidates.length) return miss(this.name, data.is_oa === false ? "closed" : "no oa copy");
3202
- ctx.onTry?.(`located ${candidates.length} copies`);
3203
- return download(this.name, p, candidates, ctx);
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);
3204
3227
  }
3205
3228
  };
3206
3229
  function unpaywallCandidates(d) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evidence-mcp-dev",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Internal development build of evidence-mcp. Not for public use.",
5
5
  "type": "module",
6
6
  "bin": {