@tool-bridge/server 0.1.0 → 0.3.0

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 (107) hide show
  1. package/dist/airtable-V6446SVY.js +792 -0
  2. package/dist/alt_text_generator_ai-HV7JZPDT.js +72 -0
  3. package/dist/amap-TTTVB6WS.js +755 -0
  4. package/dist/anthropic-JH3RA363.js +224 -0
  5. package/dist/apify-ETNN7ITU.js +262 -0
  6. package/dist/brave_search-3DDR2MMB.js +322 -0
  7. package/dist/chunk-CSJEZHQO.js +252 -0
  8. package/dist/chunk-JLTYA2B3.js +20121 -0
  9. package/dist/chunk-K7FVSFUX.js +333 -0
  10. package/dist/{chunk-6SMIQ6QU.js → chunk-KGYJEEBI.js} +2770 -21574
  11. package/dist/circleci-MX3TX3HC.js +409 -0
  12. package/dist/clerk-MRPORVF4.js +1036 -0
  13. package/dist/cloudflare_dns-OWP7DD7L.js +605 -0
  14. package/dist/cohere-GPECP66S.js +197 -0
  15. package/dist/confluence-BN7LZ6BC.js +436 -0
  16. package/dist/convertapi-SBEOFOFQ.js +161 -0
  17. package/dist/currencyapi-P2YY7Y7P.js +306 -0
  18. package/dist/deepseek-MWB3NYIN.js +205 -0
  19. package/dist/docker_hub-3JSCIGQ3.js +946 -0
  20. package/dist/dropbox-RFIBDAXO.js +1308 -0
  21. package/dist/dub-YVP57ELQ.js +706 -0
  22. package/dist/e2b-NFSUHTZR.js +305 -0
  23. package/dist/exa-KTDY6IV3.js +360 -0
  24. package/dist/fal_ai-OCUENLNQ.js +405 -0
  25. package/dist/feishu-5CWBQ7E5.js +225 -0
  26. package/dist/feishu_custom_bot-ZJR22OK6.js +240 -0
  27. package/dist/figma-YULGANSA.js +798 -0
  28. package/dist/firehydrant-2V6YSYAP.js +573 -0
  29. package/dist/fixer-LTCDB3CJ.js +171 -0
  30. package/dist/fly-IXPKMAML.js +478 -0
  31. package/dist/front-KRFB4M5X.js +379 -0
  32. package/dist/geocodio-VVURKYHQ.js +236 -0
  33. package/dist/ghost-6J2RIOUB.js +341 -0
  34. package/dist/github-5Z6KQRYH.js +5410 -0
  35. package/dist/gmail-KU4NZ7VA.js +1894 -0
  36. package/dist/googlecalendar-X44DFFXG.js +2539 -0
  37. package/dist/googledocs-WSGLPKSF.js +1322 -0
  38. package/dist/grafana-4PKSSDXY.js +817 -0
  39. package/dist/graphhopper-DF65ZNGK.js +336 -0
  40. package/dist/index.d.ts +181 -2
  41. package/dist/index.js +2 -1
  42. package/dist/ip2proxy-UCAQ5P2J.js +118 -0
  43. package/dist/ipgeolocation_io-UX6FCA2S.js +333 -0
  44. package/dist/ipqualityscore-MKTRXIZJ.js +287 -0
  45. package/dist/jina_ai-MRHPCSV5.js +119 -0
  46. package/dist/jira-EG7ZPOIW.js +627 -0
  47. package/dist/langsmith-FNO3RCOZ.js +597 -0
  48. package/dist/lemlist-SN6BJHSG.js +298 -0
  49. package/dist/linear-H3VU4PSD.js +2163 -0
  50. package/dist/logsnag-OY2JJT2H.js +167 -0
  51. package/dist/main.js +246 -2
  52. package/dist/mattermost-C5SQ7PGD.js +320 -0
  53. package/dist/mem0-LMLE5BFC.js +567 -0
  54. package/dist/memos-UWFAMBZC.js +781 -0
  55. package/dist/metabase-SRYDSDJ6.js +365 -0
  56. package/dist/mistral_ai-YNIJ7VDM.js +1195 -0
  57. package/dist/mother_duck-CPGOFEXE.js +322 -0
  58. package/dist/ngrok-CDJFBSOM.js +375 -0
  59. package/dist/notes-DIVFH3P3.js +109 -0
  60. package/dist/notion-HGDKS4HK.js +945 -0
  61. package/dist/open_exchange_rates-COHHYJDD.js +216 -0
  62. package/dist/openai-4TRT66GW.js +795 -0
  63. package/dist/opengraph_io-YKVW4PXI.js +377 -0
  64. package/dist/openrouter-6CV7B7V5.js +444 -0
  65. package/dist/outline-YWDUK5F7.js +604 -0
  66. package/dist/paddle-MEU7HWDZ.js +464 -0
  67. package/dist/perplexity-MRQUDBIC.js +238 -0
  68. package/dist/pinecone-JI7X2TAF.js +599 -0
  69. package/dist/pipedrive-6JQPAW23.js +453 -0
  70. package/dist/polar-7BF56CMC.js +400 -0
  71. package/dist/posthog-YPU5ADEN.js +3462 -0
  72. package/dist/postmark-BEU5OFKU.js +441 -0
  73. package/dist/prerender-UT5GOOZH.js +180 -0
  74. package/dist/pubmed-3SGOE24Q.js +1052 -0
  75. package/dist/railway-CEK4GLRQ.js +452 -0
  76. package/dist/readwise-DXQUQU67.js +482 -0
  77. package/dist/render-7TGAU5AW.js +473 -0
  78. package/dist/replicate-VICFSQ5A.js +347 -0
  79. package/dist/resend-3E76WK3O.js +100 -0
  80. package/dist/rootly-36GY46BY.js +345 -0
  81. package/dist/scrapfly-VDVUYAHX.js +289 -0
  82. package/dist/scrapingbee-3KTPMAVY.js +247 -0
  83. package/dist/screenshot_fyi-LKG62C3J.js +116 -0
  84. package/dist/semantic_scholar-4WREECYO.js +626 -0
  85. package/dist/sentry-HUQTGXOV.js +1139 -0
  86. package/dist/shodan-SGRKU4KS.js +303 -0
  87. package/dist/shopify-YCZ4L5HT.js +620 -0
  88. package/dist/stripe-OEBKMELB.js +583 -0
  89. package/dist/supabase-I3DBY7L4.js +937 -0
  90. package/dist/tavily-B2YHCNRD.js +349 -0
  91. package/dist/telegram-2VYJELZX.js +1773 -0
  92. package/dist/telnyx-HHXD3CXL.js +237 -0
  93. package/dist/todoist-PHFDEEIS.js +672 -0
  94. package/dist/trello-WUSAK6YN.js +1091 -0
  95. package/dist/turso-FW56U2B3.js +432 -0
  96. package/dist/twilio-M5JI7XHA.js +321 -0
  97. package/dist/umami-HAYODRC4.js +411 -0
  98. package/dist/unsplash-EDPTNEHJ.js +364 -0
  99. package/dist/upstash_redis-GC2CLIWD.js +299 -0
  100. package/dist/uptimerobot-XMSNYLIT.js +481 -0
  101. package/dist/v2ex-KU4ECD65.js +672 -0
  102. package/dist/vercel-THPCEFHW.js +1096 -0
  103. package/dist/wolfram_alpha_api-WHHTH4GU.js +212 -0
  104. package/dist/wordpress-O6TQEQNF.js +822 -0
  105. package/dist/workos-A3VHHWI3.js +681 -0
  106. package/dist/zhihu-BJAI64YJ.js +273 -0
  107. package/package.json +5 -4
@@ -0,0 +1,1052 @@
1
+ import {
2
+ createProviderPlugin,
3
+ guardedFetch,
4
+ upstreamError
5
+ } from "./chunk-CSJEZHQO.js";
6
+ import "./chunk-K7FVSFUX.js";
7
+ import {
8
+ TBError,
9
+ external_exports
10
+ } from "./chunk-JLTYA2B3.js";
11
+ import "./chunk-MLKGABMK.js";
12
+
13
+ // ../plugins/src/pubmed/api.ts
14
+ var EUTILS_BASE = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/";
15
+ var CITATION_MATCHER_URL = "https://pubmed.ncbi.nlm.nih.gov/api/citmatch/";
16
+ var ID_CONVERTER_URL = "https://pmc.ncbi.nlm.nih.gov/tools/idconv/api/v1/articles/";
17
+ var TOOL_NAME = "tool-bridge";
18
+ var REQUEST_TIMEOUT_MS = 3e4;
19
+ var MAX_JSON_RESPONSE_BYTES = 1024 * 1024;
20
+ var MAX_XML_RESPONSE_BYTES = 10 * 1024 * 1024;
21
+ var ESEARCH_POST_TERM_LENGTH = 500;
22
+ var MAX_SEARCH_WINDOW = 1e4;
23
+ var SORT_VALUES = {
24
+ first_author: "Author",
25
+ journal: "JournalName",
26
+ publication_date: "pub date",
27
+ relevance: "relevance"
28
+ };
29
+ function record(value) {
30
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
31
+ }
32
+ function text(value) {
33
+ if (typeof value !== "string") return void 0;
34
+ const trimmed = value.trim();
35
+ return trimmed === "" ? void 0 : trimmed;
36
+ }
37
+ function invalidInput(message) {
38
+ return new TBError("invalid_argument", message);
39
+ }
40
+ function invalidResponse(message) {
41
+ return new TBError("unavailable", message, { retryable: true });
42
+ }
43
+ function requireRecord(value, label) {
44
+ const result = record(value);
45
+ if (result === void 0) throw invalidResponse(`${label} \u4E0D\u662F\u5BF9\u8C61`);
46
+ return result;
47
+ }
48
+ function requireObjectArray(value, label) {
49
+ if (!Array.isArray(value)) throw invalidResponse(`${label} \u4E0D\u662F\u6570\u7EC4`);
50
+ return value.map((item, index) => requireRecord(item, `${label}[${index}]`));
51
+ }
52
+ function requireStringArray(value, label) {
53
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
54
+ throw invalidResponse(`${label} \u4E0D\u662F\u5B57\u7B26\u4E32\u6570\u7EC4`);
55
+ }
56
+ return value;
57
+ }
58
+ function requireInputText(value, field) {
59
+ const result = text(value);
60
+ if (result === void 0) throw invalidInput(`${field} is required.`);
61
+ return result;
62
+ }
63
+ function readPmid(value, field) {
64
+ const pmid = requireInputText(value, field);
65
+ if (!/^\d+$/u.test(pmid)) throw invalidInput(`${field} must contain only digits`);
66
+ return pmid;
67
+ }
68
+ function readPmidArray(value) {
69
+ if (!Array.isArray(value) || value.length === 0 || value.length > 50) {
70
+ throw invalidInput("pmids must contain between 1 and 50 PubMed IDs");
71
+ }
72
+ return value.map((pmid, index) => readPmid(pmid, `pmids[${index}]`));
73
+ }
74
+ function readLimit(value) {
75
+ const limit = typeof value === "number" && Number.isInteger(value) ? value : 10;
76
+ if (limit < 1 || limit > 50) throw invalidInput("limit must be between 1 and 50");
77
+ return limit;
78
+ }
79
+ function readArticleIds(value) {
80
+ if (!Array.isArray(value) || value.length === 0 || value.length > 200) {
81
+ throw invalidInput("ids must contain between 1 and 200 article identifiers");
82
+ }
83
+ return value.map((id, index) => requireInputText(id, `ids[${index}]`));
84
+ }
85
+ function readIdType(value) {
86
+ const idType = requireInputText(value, "idType");
87
+ if (idType === "doi" || idType === "mid" || idType === "pmcid" || idType === "pmid") return idType;
88
+ throw invalidInput("idType must be doi, mid, pmcid, or pmid");
89
+ }
90
+ function readSort(value) {
91
+ const sort = text(value);
92
+ if (sort === void 0) return void 0;
93
+ const mapped = SORT_VALUES[sort];
94
+ if (mapped === void 0) throw invalidInput("sort is not supported by PubMed");
95
+ return mapped;
96
+ }
97
+ function readPublicationDateRange(value) {
98
+ const range = record(value);
99
+ if (range === void 0) return void 0;
100
+ const from = requireInputText(range.from, "publicationDateRange.from");
101
+ const to = requireInputText(range.to, "publicationDateRange.to");
102
+ if (from > to) {
103
+ throw invalidInput("publicationDateRange.from must not be after publicationDateRange.to");
104
+ }
105
+ return { from, to };
106
+ }
107
+ function ncbiDate(value) {
108
+ return value?.replaceAll("-", "/");
109
+ }
110
+ async function readBoundedText(response, maxBytes, source) {
111
+ const tooLarge = () => invalidInput(
112
+ `${source} \u54CD\u5E94\u8D85\u8FC7 ${maxBytes} \u5B57\u8282\u4E0A\u9650:\u628A limit / pmids / ids \u8C03\u5C0F\u540E\u91CD\u8BD5`
113
+ );
114
+ const declared = Number(response.headers.get("content-length"));
115
+ if (Number.isSafeInteger(declared) && declared > maxBytes) throw tooLarge();
116
+ if (response.body === null) {
117
+ const bytes2 = new Uint8Array(await response.arrayBuffer());
118
+ if (bytes2.byteLength > maxBytes) throw tooLarge();
119
+ return new TextDecoder().decode(bytes2);
120
+ }
121
+ const reader = response.body.getReader();
122
+ const chunks = [];
123
+ let total = 0;
124
+ try {
125
+ for (; ; ) {
126
+ const { done, value } = await reader.read();
127
+ if (done) break;
128
+ total += value.byteLength;
129
+ if (total > maxBytes) {
130
+ await reader.cancel().catch(() => void 0);
131
+ throw tooLarge();
132
+ }
133
+ chunks.push(value);
134
+ }
135
+ } finally {
136
+ reader.releaseLock();
137
+ }
138
+ const bytes = new Uint8Array(total);
139
+ let offset = 0;
140
+ for (const chunk of chunks) {
141
+ bytes.set(chunk, offset);
142
+ offset += chunk.byteLength;
143
+ }
144
+ return new TextDecoder().decode(bytes);
145
+ }
146
+ function extractError(body) {
147
+ const trimmed = body.trim();
148
+ if (trimmed === "") return void 0;
149
+ try {
150
+ const payload = record(JSON.parse(trimmed));
151
+ const direct = text(payload?.error);
152
+ if (direct !== void 0) return direct;
153
+ const errors = payload?.errors;
154
+ if (Array.isArray(errors)) {
155
+ return errors.filter((item) => typeof item === "string").join("; ") || void 0;
156
+ }
157
+ } catch {
158
+ return trimmed.slice(0, 500);
159
+ }
160
+ return trimmed.slice(0, 500);
161
+ }
162
+ async function requestText(input) {
163
+ const headers = { accept: input.accept };
164
+ if (input.body !== void 0) headers["content-type"] = "application/x-www-form-urlencoded";
165
+ let response;
166
+ try {
167
+ response = await guardedFetch(input.url.toString(), {
168
+ method: input.body === void 0 ? "GET" : "POST",
169
+ headers,
170
+ body: input.body,
171
+ // 不设超时会让一个挂死的 NCBI 端点拖住整个调用;上游同样给了 30s 的独立预算。
172
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
173
+ });
174
+ } catch (error) {
175
+ if (error instanceof TBError) throw error;
176
+ if (error instanceof Error && error.name === "TimeoutError") {
177
+ throw upstreamError(504, `${input.source} request timed out`);
178
+ }
179
+ const message = error instanceof Error ? error.message : "unknown network error";
180
+ throw upstreamError(502, `${input.source} request failed: ${message}`);
181
+ }
182
+ const body = await readBoundedText(response, input.maxBytes, input.source);
183
+ if (!response.ok) {
184
+ throw upstreamError(
185
+ response.status,
186
+ extractError(body) ?? `${input.source} request failed with HTTP ${response.status}`
187
+ );
188
+ }
189
+ return body;
190
+ }
191
+ function parseJson(body, source) {
192
+ try {
193
+ return JSON.parse(body);
194
+ } catch {
195
+ throw invalidResponse(`${source} returned malformed JSON`);
196
+ }
197
+ }
198
+ async function eutils(ctx, utility, query, options) {
199
+ const url = new URL(utility, EUTILS_BASE);
200
+ url.searchParams.set("db", "pubmed");
201
+ url.searchParams.set("tool", TOOL_NAME);
202
+ for (const [name, value] of Object.entries(query)) {
203
+ if (value !== void 0) url.searchParams.set(name, value);
204
+ }
205
+ const apiKey = text(ctx.upstreamAuth);
206
+ if (apiKey !== void 0) url.searchParams.set("api_key", apiKey);
207
+ const usePost = utility === "esearch.fcgi" && (query.term?.length ?? 0) > ESEARCH_POST_TERM_LENGTH;
208
+ let body;
209
+ if (usePost) {
210
+ body = new URLSearchParams(url.searchParams);
211
+ url.search = "";
212
+ }
213
+ return requestText({ url, body, source: "PubMed", accept: options.accept, maxBytes: options.maxBytes });
214
+ }
215
+ async function eutilsJson(ctx, utility, query) {
216
+ const body = await eutils(ctx, utility, { ...query, retmode: "json" }, {
217
+ accept: "application/json",
218
+ maxBytes: MAX_JSON_RESPONSE_BYTES
219
+ });
220
+ return requireRecord(parseJson(body, `PubMed ${utility}`), `PubMed ${utility} \u54CD\u5E94`);
221
+ }
222
+ async function ncbiJson(url, source) {
223
+ const body = await requestText({
224
+ url,
225
+ source,
226
+ accept: "application/json",
227
+ maxBytes: MAX_JSON_RESPONSE_BYTES
228
+ });
229
+ return requireRecord(parseJson(body, source), `${source} \u54CD\u5E94`);
230
+ }
231
+ function malformedXml() {
232
+ return invalidResponse("PubMed returned malformed article XML");
233
+ }
234
+ var NAMED_ENTITIES = {
235
+ amp: "&",
236
+ apos: "'",
237
+ gt: ">",
238
+ lt: "<",
239
+ quot: '"'
240
+ };
241
+ function decodeEntities(value) {
242
+ return value.replace(/&(?:#(?:x([\da-f]+)|(\d+))|([a-z]+));/giu, (reference, hex, decimal, name) => {
243
+ if (typeof name === "string") return NAMED_ENTITIES[name.toLowerCase()] ?? reference;
244
+ const codePoint = Number.parseInt(hex ?? decimal, hex === void 0 ? 10 : 16);
245
+ return Number.isInteger(codePoint) && codePoint >= 0 && codePoint <= 1114111 ? String.fromCodePoint(codePoint) : reference;
246
+ });
247
+ }
248
+ function decodeNumericEntities(value) {
249
+ return value.replace(/&#(?:x([\da-f]+)|(\d+));/giu, (reference, hex, decimal) => {
250
+ const codePoint = Number.parseInt(hex ?? decimal, hex === void 0 ? 10 : 16);
251
+ return Number.isInteger(codePoint) && codePoint >= 0 && codePoint <= 1114111 ? String.fromCodePoint(codePoint) : reference;
252
+ });
253
+ }
254
+ function isNameChar(char) {
255
+ return !/[\s/>=]/u.test(char);
256
+ }
257
+ function skipWhitespace(cursor) {
258
+ while (cursor.index < cursor.source.length && /\s/u.test(cursor.source[cursor.index])) cursor.index += 1;
259
+ }
260
+ function skipProlog(cursor) {
261
+ for (; ; ) {
262
+ skipWhitespace(cursor);
263
+ const rest = cursor.source.slice(cursor.index);
264
+ if (rest.startsWith("<?")) {
265
+ const end = cursor.source.indexOf("?>", cursor.index);
266
+ if (end < 0) throw malformedXml();
267
+ cursor.index = end + 2;
268
+ continue;
269
+ }
270
+ if (rest.startsWith("<!--")) {
271
+ const end = cursor.source.indexOf("-->", cursor.index);
272
+ if (end < 0) throw malformedXml();
273
+ cursor.index = end + 3;
274
+ continue;
275
+ }
276
+ if (rest.startsWith("<!")) {
277
+ let depth = 0;
278
+ let index = cursor.index + 2;
279
+ for (; index < cursor.source.length; index += 1) {
280
+ const char = cursor.source[index];
281
+ if (char === "[") depth += 1;
282
+ else if (char === "]") depth -= 1;
283
+ else if (char === ">" && depth <= 0) break;
284
+ }
285
+ if (index >= cursor.source.length) throw malformedXml();
286
+ cursor.index = index + 1;
287
+ continue;
288
+ }
289
+ return;
290
+ }
291
+ }
292
+ function readName(cursor) {
293
+ const start = cursor.index;
294
+ while (cursor.index < cursor.source.length && isNameChar(cursor.source[cursor.index])) cursor.index += 1;
295
+ const name = cursor.source.slice(start, cursor.index);
296
+ if (name === "") throw malformedXml();
297
+ return name;
298
+ }
299
+ function readAttributes(cursor) {
300
+ const attributes = {};
301
+ for (; ; ) {
302
+ skipWhitespace(cursor);
303
+ const rest = cursor.source.slice(cursor.index);
304
+ if (rest.startsWith("/>")) {
305
+ cursor.index += 2;
306
+ return { attributes, selfClosing: true };
307
+ }
308
+ if (rest.startsWith(">")) {
309
+ cursor.index += 1;
310
+ return { attributes, selfClosing: false };
311
+ }
312
+ if (cursor.index >= cursor.source.length) throw malformedXml();
313
+ const name = readName(cursor);
314
+ skipWhitespace(cursor);
315
+ if (cursor.source[cursor.index] !== "=") throw malformedXml();
316
+ cursor.index += 1;
317
+ skipWhitespace(cursor);
318
+ const quote = cursor.source[cursor.index];
319
+ if (quote !== '"' && quote !== "'") throw malformedXml();
320
+ cursor.index += 1;
321
+ const end = cursor.source.indexOf(quote, cursor.index);
322
+ if (end < 0) throw malformedXml();
323
+ attributes[name] = decodeEntities(cursor.source.slice(cursor.index, end));
324
+ cursor.index = end + 1;
325
+ }
326
+ }
327
+ function parseElement(cursor) {
328
+ if (cursor.source[cursor.index] !== "<") throw malformedXml();
329
+ cursor.index += 1;
330
+ const name = readName(cursor);
331
+ const { attributes, selfClosing } = readAttributes(cursor);
332
+ const element = { name, attributes, children: [] };
333
+ if (selfClosing) return element;
334
+ for (; ; ) {
335
+ if (cursor.index >= cursor.source.length) throw malformedXml();
336
+ const rest = cursor.source.slice(cursor.index);
337
+ if (rest.startsWith("</")) {
338
+ cursor.index += 2;
339
+ const closing = readName(cursor);
340
+ skipWhitespace(cursor);
341
+ if (closing !== name || cursor.source[cursor.index] !== ">") throw malformedXml();
342
+ cursor.index += 1;
343
+ return element;
344
+ }
345
+ if (rest.startsWith("<![CDATA[")) {
346
+ const end2 = cursor.source.indexOf("]]>", cursor.index);
347
+ if (end2 < 0) throw malformedXml();
348
+ element.children.push(cursor.source.slice(cursor.index + 9, end2));
349
+ cursor.index = end2 + 3;
350
+ continue;
351
+ }
352
+ if (rest.startsWith("<!--")) {
353
+ const end2 = cursor.source.indexOf("-->", cursor.index);
354
+ if (end2 < 0) throw malformedXml();
355
+ cursor.index = end2 + 3;
356
+ continue;
357
+ }
358
+ if (rest.startsWith("<?")) {
359
+ const end2 = cursor.source.indexOf("?>", cursor.index);
360
+ if (end2 < 0) throw malformedXml();
361
+ cursor.index = end2 + 2;
362
+ continue;
363
+ }
364
+ if (rest.startsWith("<")) {
365
+ element.children.push(parseElement(cursor));
366
+ continue;
367
+ }
368
+ const next = cursor.source.indexOf("<", cursor.index);
369
+ const end = next < 0 ? cursor.source.length : next;
370
+ element.children.push(decodeEntities(cursor.source.slice(cursor.index, end)));
371
+ cursor.index = end;
372
+ }
373
+ }
374
+ function parseXml(source) {
375
+ const cursor = { source, index: 0 };
376
+ skipProlog(cursor);
377
+ const root = parseElement(cursor);
378
+ return root;
379
+ }
380
+ function elements(parent, name) {
381
+ if (parent === void 0) return [];
382
+ return parent.children.filter(
383
+ (child) => typeof child !== "string" && child.name === name
384
+ );
385
+ }
386
+ function firstElement(parent, name) {
387
+ return elements(parent, name)[0];
388
+ }
389
+ function attribute(element, name) {
390
+ return text(element.attributes[name]);
391
+ }
392
+ function textOf(element) {
393
+ if (element === void 0) return "";
394
+ const collect = (node) => typeof node === "string" ? node : node.children.map(collect).join("");
395
+ const raw = element.children.map(collect).join("");
396
+ return decodeNumericEntities(raw).replace(/\s+/gu, " ").trim();
397
+ }
398
+ function childText(parent, name) {
399
+ const value = textOf(firstElement(parent, name));
400
+ return value === "" ? void 0 : value;
401
+ }
402
+ function childTexts(parent, name) {
403
+ return elements(parent, name).map((child) => textOf(child)).filter((value) => value !== "");
404
+ }
405
+ function requireChild(parent, name, source) {
406
+ const child = firstElement(parent, name);
407
+ if (child === void 0) throw invalidResponse(`${source} is missing ${name}`);
408
+ return child;
409
+ }
410
+ function requireChildText(parent, name, source) {
411
+ const value = childText(parent, name);
412
+ if (value === void 0) throw invalidResponse(`${source} is missing ${name}`);
413
+ return value;
414
+ }
415
+ var MONTH_NUMBERS = {
416
+ apr: "04",
417
+ aug: "08",
418
+ dec: "12",
419
+ feb: "02",
420
+ jan: "01",
421
+ jul: "07",
422
+ jun: "06",
423
+ mar: "03",
424
+ may: "05",
425
+ nov: "11",
426
+ oct: "10",
427
+ sep: "09"
428
+ };
429
+ function normalizeMonth(value) {
430
+ if (value === void 0) return void 0;
431
+ if (/^\d{1,2}$/u.test(value)) return value.padStart(2, "0");
432
+ return MONTH_NUMBERS[value.slice(0, 3).toLowerCase()];
433
+ }
434
+ function normalizeDay(value) {
435
+ return value !== void 0 && /^\d{1,2}$/u.test(value) ? value.padStart(2, "0") : void 0;
436
+ }
437
+ function readDate(pubDate) {
438
+ if (pubDate === void 0) return null;
439
+ const medlineDate = childText(pubDate, "MedlineDate");
440
+ if (medlineDate !== void 0) return medlineDate;
441
+ const year = childText(pubDate, "Year");
442
+ if (year === void 0) return null;
443
+ const season = childText(pubDate, "Season");
444
+ if (season !== void 0) return `${year} ${season}`;
445
+ const month = normalizeMonth(childText(pubDate, "Month"));
446
+ const day = normalizeDay(childText(pubDate, "Day"));
447
+ return [year, month, day].filter((value) => value !== void 0).join("-");
448
+ }
449
+ function readAbstract(parent) {
450
+ return elements(firstElement(parent, "Abstract"), "AbstractText").map((section) => ({
451
+ label: attribute(section, "Label") ?? attribute(section, "NlmCategory") ?? null,
452
+ text: textOf(section)
453
+ })).filter((section) => section.text.length > 0);
454
+ }
455
+ function readAuthors(parent) {
456
+ return elements(firstElement(parent, "AuthorList"), "Author").flatMap((author) => {
457
+ const collectiveName = childText(author, "CollectiveName");
458
+ const familyName = childText(author, "LastName");
459
+ const givenName = childText(author, "ForeName") ?? childText(author, "Initials");
460
+ const name = collectiveName ?? [givenName, familyName].filter(Boolean).join(" ");
461
+ if (name === "") return [];
462
+ const orcid = elements(author, "Identifier").find((identifier) => attribute(identifier, "Source")?.toLowerCase() === "orcid");
463
+ return [{
464
+ name,
465
+ orcid: orcid === void 0 ? null : textOf(orcid) || null,
466
+ affiliations: elements(author, "AffiliationInfo").map((info) => childText(info, "Affiliation")).filter((value) => value !== void 0)
467
+ }];
468
+ });
469
+ }
470
+ function readJournal(journal) {
471
+ const issue = firstElement(journal, "JournalIssue");
472
+ return {
473
+ title: childText(journal, "Title") ?? null,
474
+ abbreviation: childText(journal, "ISOAbbreviation") ?? null,
475
+ issn: childText(journal, "ISSN") ?? null,
476
+ volume: childText(issue, "Volume") ?? null,
477
+ issue: childText(issue, "Issue") ?? null
478
+ };
479
+ }
480
+ function addIdentifiers(identifiers, list) {
481
+ for (const identifier of elements(list, "ArticleId")) {
482
+ const type = attribute(identifier, "IdType")?.toLowerCase();
483
+ const value = textOf(identifier);
484
+ if (type !== void 0 && value !== "") identifiers.set(type, value);
485
+ }
486
+ }
487
+ function readElectronicDoi(parent) {
488
+ const location = elements(parent, "ELocationID").find((identifier) => attribute(identifier, "EIdType")?.toLowerCase() === "doi");
489
+ return location === void 0 ? null : textOf(location) || null;
490
+ }
491
+ function articleUrls(pmid, pmcid) {
492
+ return {
493
+ pubmedUrl: `https://pubmed.ncbi.nlm.nih.gov/${pmid}/`,
494
+ pmcUrl: pmcid === null ? null : `https://pmc.ncbi.nlm.nih.gov/articles/${pmcid}/`
495
+ };
496
+ }
497
+ function parseArticle(pubmedArticle) {
498
+ const citation = requireChild(pubmedArticle, "MedlineCitation", "PubMed article");
499
+ const article = requireChild(citation, "Article", "PubMed citation");
500
+ const pmid = requireChildText(citation, "PMID", "PubMed citation");
501
+ const journal = firstElement(article, "Journal");
502
+ const identifiers = /* @__PURE__ */ new Map();
503
+ addIdentifiers(identifiers, firstElement(firstElement(pubmedArticle, "PubmedData"), "ArticleIdList"));
504
+ const pmcid = identifiers.get("pmc") ?? null;
505
+ return {
506
+ pmid,
507
+ title: childText(article, "ArticleTitle") ?? "",
508
+ abstract: readAbstract(article),
509
+ authors: readAuthors(article),
510
+ journal: readJournal(journal),
511
+ publicationDate: readDate(firstElement(firstElement(journal, "JournalIssue"), "PubDate")),
512
+ publicationTypes: childTexts(firstElement(article, "PublicationTypeList"), "PublicationType"),
513
+ meshTerms: elements(firstElement(citation, "MeshHeadingList"), "MeshHeading").map((heading) => childText(heading, "DescriptorName")).filter((value) => value !== void 0),
514
+ keywords: elements(citation, "KeywordList").flatMap((list) => childTexts(list, "Keyword")),
515
+ languages: childTexts(article, "Language"),
516
+ doi: identifiers.get("doi") ?? readElectronicDoi(article),
517
+ pmcid,
518
+ ...articleUrls(pmid, pmcid)
519
+ };
520
+ }
521
+ function parseBookArticle(pubmedBookArticle) {
522
+ const document = requireChild(pubmedBookArticle, "BookDocument", "PubMed book article");
523
+ const book = requireChild(document, "Book", "PubMed book document");
524
+ const pmid = requireChildText(document, "PMID", "PubMed book document");
525
+ const identifiers = /* @__PURE__ */ new Map();
526
+ addIdentifiers(identifiers, firstElement(document, "ArticleIdList"));
527
+ addIdentifiers(identifiers, firstElement(firstElement(pubmedBookArticle, "PubmedBookData"), "ArticleIdList"));
528
+ const pmcid = identifiers.get("pmc") ?? null;
529
+ return {
530
+ pmid,
531
+ title: childText(document, "ArticleTitle") ?? childText(book, "BookTitle") ?? "",
532
+ abstract: readAbstract(document),
533
+ authors: readAuthors(document),
534
+ journal: {
535
+ title: childText(book, "BookTitle") ?? null,
536
+ abbreviation: null,
537
+ issn: null,
538
+ volume: childText(book, "Volume") ?? null,
539
+ issue: null
540
+ },
541
+ publicationDate: readDate(firstElement(book, "PubDate")),
542
+ publicationTypes: childTexts(document, "PublicationType"),
543
+ meshTerms: [],
544
+ keywords: elements(document, "KeywordList").flatMap((list) => childTexts(list, "Keyword")),
545
+ languages: childTexts(document, "Language"),
546
+ doi: identifiers.get("doi") ?? readElectronicDoi(book),
547
+ pmcid,
548
+ ...articleUrls(pmid, pmcid)
549
+ };
550
+ }
551
+ function parseArticleSet(xml) {
552
+ const root = parseXml(xml);
553
+ if (root.name !== "PubmedArticleSet") {
554
+ throw invalidResponse("PubMed returned an article response without PubmedArticleSet");
555
+ }
556
+ return root.children.flatMap((node) => {
557
+ if (typeof node === "string") return [];
558
+ if (node.name === "PubmedArticle") return [parseArticle(node)];
559
+ if (node.name === "PubmedBookArticle") return [parseBookArticle(node)];
560
+ return [];
561
+ });
562
+ }
563
+ async function fetchArticles(ctx, pmids) {
564
+ const xml = await eutils(ctx, "efetch.fcgi", { id: pmids.join(","), retmode: "xml" }, {
565
+ accept: "application/xml, text/xml",
566
+ maxBytes: MAX_XML_RESPONSE_BYTES
567
+ });
568
+ return parseArticleSet(xml);
569
+ }
570
+ function readLinkedPmids(payload, linkName, label) {
571
+ const linksets = Array.isArray(payload.linksets) ? requireObjectArray(payload.linksets, `${label} linkset`) : [];
572
+ for (const linkset of linksets) {
573
+ const databases = Array.isArray(linkset.linksetdbs) ? requireObjectArray(linkset.linksetdbs, `${label} database`) : [];
574
+ const related = databases.find((database) => text(database.linkname) === linkName);
575
+ if (related !== void 0) return requireStringArray(related.links, label);
576
+ }
577
+ return [];
578
+ }
579
+ async function linkedArticles(ctx, sourcePmid, linkName, limit) {
580
+ const payload = await eutilsJson(ctx, "elink.fcgi", {
581
+ dbfrom: "pubmed",
582
+ id: sourcePmid,
583
+ linkname: linkName,
584
+ cmd: "neighbor"
585
+ });
586
+ const pmids = readLinkedPmids(payload, linkName, `PubMed ${linkName} links`).slice(0, limit);
587
+ return {
588
+ sourcePmid,
589
+ articles: pmids.length > 0 ? await fetchArticles(ctx, pmids) : []
590
+ };
591
+ }
592
+ function readIntegerString(value, label) {
593
+ const raw = text(value);
594
+ const parsed = raw === void 0 ? Number.NaN : Number(raw);
595
+ if (!Number.isSafeInteger(parsed) || parsed < 0) throw invalidResponse(`${label} is malformed`);
596
+ return parsed;
597
+ }
598
+ function optionalIdentifier(value) {
599
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
600
+ return text(value) ?? null;
601
+ }
602
+ async function searchArticles(input, ctx) {
603
+ const query = requireInputText(input.query, "query");
604
+ const offset = input.offset ?? 0;
605
+ const limit = input.limit ?? 10;
606
+ if (offset + limit > MAX_SEARCH_WINDOW) {
607
+ throw invalidInput(`offset plus limit must not exceed ${MAX_SEARCH_WINDOW} for PubMed searches`);
608
+ }
609
+ const sort = readSort(input.sort);
610
+ const range = readPublicationDateRange(input.publicationDateRange);
611
+ const payload = await eutilsJson(ctx, "esearch.fcgi", {
612
+ term: query,
613
+ retstart: String(offset),
614
+ retmax: String(limit),
615
+ sort,
616
+ // datetype 只在给了区间时才发,否则 NCBI 会按默认日期字段过滤掉本该命中的记录。
617
+ datetype: range === void 0 ? void 0 : "pdat",
618
+ mindate: ncbiDate(range?.from),
619
+ maxdate: ncbiDate(range?.to)
620
+ });
621
+ const result = requireRecord(payload.esearchresult, "PubMed esearchresult");
622
+ const pmids = requireStringArray(result.idlist, "PubMed search idlist");
623
+ return {
624
+ total: readIntegerString(result.count, "PubMed search count"),
625
+ offset,
626
+ limit,
627
+ queryTranslation: text(result.querytranslation) ?? null,
628
+ articles: pmids.length > 0 ? await fetchArticles(ctx, pmids) : []
629
+ };
630
+ }
631
+ async function getArticle(input, ctx) {
632
+ const articles = await fetchArticles(ctx, [readPmid(input.pmid, "pmid")]);
633
+ return { found: articles.length > 0, article: articles[0] ?? null };
634
+ }
635
+ async function getArticles(input, ctx) {
636
+ const pmids = readPmidArray(input.pmids);
637
+ const articles = await fetchArticles(ctx, pmids);
638
+ const returned = new Set(articles.map((article) => article.pmid));
639
+ return { articles, notFoundPmids: pmids.filter((pmid) => !returned.has(pmid)) };
640
+ }
641
+ async function findRelatedArticles(input, ctx) {
642
+ const sourcePmid = readPmid(input.pmid, "pmid");
643
+ const limit = readLimit(input.limit);
644
+ const payload = await eutilsJson(ctx, "elink.fcgi", {
645
+ dbfrom: "pubmed",
646
+ id: sourcePmid,
647
+ linkname: "pubmed_pubmed",
648
+ cmd: "neighbor"
649
+ });
650
+ const related = readLinkedPmids(payload, "pubmed_pubmed", "PubMed related article links").filter((pmid) => pmid !== sourcePmid).slice(0, limit);
651
+ return {
652
+ sourcePmid,
653
+ articles: related.length > 0 ? await fetchArticles(ctx, related) : []
654
+ };
655
+ }
656
+ async function getCitingArticles(input, ctx) {
657
+ return linkedArticles(ctx, readPmid(input.pmid, "pmid"), "pubmed_pubmed_citedin", readLimit(input.limit));
658
+ }
659
+ async function getArticleReferences(input, ctx) {
660
+ return linkedArticles(ctx, readPmid(input.pmid, "pmid"), "pubmed_pubmed_refs", readLimit(input.limit));
661
+ }
662
+ async function matchCitation(input, ctx) {
663
+ const citation = requireInputText(input.citation, "citation");
664
+ const url = new URL(CITATION_MATCHER_URL);
665
+ url.searchParams.set("method", "heuristic");
666
+ url.searchParams.set("raw-text", citation);
667
+ const payload = await ncbiJson(url, "PubMed Citation Matcher");
668
+ if (payload.success !== true) {
669
+ throw invalidResponse("PubMed Citation Matcher reported an unsuccessful response");
670
+ }
671
+ const result = requireRecord(payload.result, "PubMed Citation Matcher result");
672
+ const pmids = requireObjectArray(result.uids, "PubMed Citation Matcher UIDs").map((uid, index) => readPmid(uid.pubmed, `PubMed Citation Matcher UIDs[${index}].pubmed`));
673
+ return {
674
+ matched: pmids.length > 0,
675
+ articles: pmids.length > 0 ? await fetchArticles(ctx, pmids) : []
676
+ };
677
+ }
678
+ async function convertArticleIds(input) {
679
+ const ids = readArticleIds(input.ids);
680
+ const idType = readIdType(input.idType);
681
+ const url = new URL(ID_CONVERTER_URL);
682
+ url.searchParams.set("ids", ids.join(","));
683
+ url.searchParams.set("idtype", idType);
684
+ url.searchParams.set("format", "json");
685
+ url.searchParams.set("tool", TOOL_NAME);
686
+ const payload = await ncbiJson(url, "PMC ID Converter");
687
+ const records = requireObjectArray(payload.records, "PMC ID Converter records");
688
+ return {
689
+ records: records.map((item, index) => {
690
+ const requestedId = optionalIdentifier(item["requested-id"]);
691
+ if (requestedId === null) {
692
+ throw invalidResponse(`PMC ID Converter records[${index}].requested-id is malformed`);
693
+ }
694
+ return {
695
+ requestedId,
696
+ pmid: optionalIdentifier(item.pmid),
697
+ pmcid: text(item.pmcid) ?? null,
698
+ doi: text(item.doi) ?? null,
699
+ mid: text(item.mid) ?? null,
700
+ // PMC 用 `errmsg` 报"这个 id 解析不了",是逐条结果的一部分,不是整体失败。
701
+ error: text(item.errmsg) ?? null
702
+ };
703
+ })
704
+ };
705
+ }
706
+
707
+ // ../plugins/src/pubmed/schema.ts
708
+ var searchArticlesInput = external_exports.strictObject({
709
+ query: external_exports.string().min(1).describe("The PubMed query, including optional official field tags and Boolean operators such as cancer[Title] AND 2025[pdat]."),
710
+ offset: external_exports.int().min(0).max(9999).default(0).describe("The zero-based search result offset.").optional(),
711
+ limit: external_exports.int().min(1).max(50).default(10).describe("The maximum number of articles to return.").optional(),
712
+ sort: external_exports.enum(["relevance", "publication_date", "first_author", "journal"]).describe("The PubMed result sort order.").optional(),
713
+ publicationDateRange: external_exports.strictObject({
714
+ from: external_exports.iso.date().describe("The earliest publication date to include.").optional(),
715
+ to: external_exports.iso.date().describe("The latest publication date to include.").optional()
716
+ }).describe("An inclusive PubMed publication date range.").optional()
717
+ }).describe("Input parameters for searching PubMed articles.");
718
+ var searchArticlesOutput = external_exports.strictObject({
719
+ total: external_exports.int().min(0).describe("The total number of matching PubMed records.").optional(),
720
+ offset: external_exports.int().min(0).describe("The zero-based result offset.").optional(),
721
+ limit: external_exports.int().min(1).describe("The requested page size.").optional(),
722
+ queryTranslation: external_exports.string().describe("The query translation reported by PubMed.").nullable().optional(),
723
+ articles: external_exports.array(external_exports.strictObject({
724
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
725
+ title: external_exports.string().describe("The article title.").optional(),
726
+ abstract: external_exports.array(external_exports.strictObject({
727
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
728
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
729
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
730
+ authors: external_exports.array(external_exports.strictObject({
731
+ name: external_exports.string().describe("The author or collective author name.").optional(),
732
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
733
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
734
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
735
+ journal: external_exports.strictObject({
736
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
737
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
738
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
739
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
740
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
741
+ }).describe("The journal information attached to a PubMed record.").optional(),
742
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
743
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
744
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
745
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
746
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
747
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
748
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
749
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
750
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
751
+ }).describe("A normalized PubMed article record.")).describe("The normalized articles in this page.").optional()
752
+ }).describe("A page of normalized PubMed search results.");
753
+ var matchCitationInput = external_exports.strictObject({
754
+ citation: external_exports.string().min(1).describe("The citation text to match, such as an article title followed by its journal, year, volume, and pages.").optional()
755
+ }).describe("Input parameters for matching one citation.");
756
+ var matchCitationOutput = external_exports.strictObject({
757
+ matched: external_exports.boolean().describe("Whether PubMed returned at least one candidate article.").optional(),
758
+ articles: external_exports.array(external_exports.strictObject({
759
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
760
+ title: external_exports.string().describe("The article title.").optional(),
761
+ abstract: external_exports.array(external_exports.strictObject({
762
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
763
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
764
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
765
+ authors: external_exports.array(external_exports.strictObject({
766
+ name: external_exports.string().describe("The author or collective author name.").optional(),
767
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
768
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
769
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
770
+ journal: external_exports.strictObject({
771
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
772
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
773
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
774
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
775
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
776
+ }).describe("The journal information attached to a PubMed record.").optional(),
777
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
778
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
779
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
780
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
781
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
782
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
783
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
784
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
785
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
786
+ }).describe("A normalized PubMed article record.")).describe("The normalized candidate articles returned by PubMed.").optional()
787
+ }).describe("The PubMed articles matched from the citation text.");
788
+ var getArticleInput = external_exports.strictObject({
789
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional()
790
+ }).describe("Input parameters for getting one PubMed article.");
791
+ var getArticleOutput = external_exports.strictObject({
792
+ found: external_exports.boolean().describe("Whether PubMed returned the requested record.").optional(),
793
+ article: external_exports.strictObject({
794
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
795
+ title: external_exports.string().describe("The article title.").optional(),
796
+ abstract: external_exports.array(external_exports.strictObject({
797
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
798
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
799
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
800
+ authors: external_exports.array(external_exports.strictObject({
801
+ name: external_exports.string().describe("The author or collective author name.").optional(),
802
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
803
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
804
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
805
+ journal: external_exports.strictObject({
806
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
807
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
808
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
809
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
810
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
811
+ }).describe("The journal information attached to a PubMed record.").optional(),
812
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
813
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
814
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
815
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
816
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
817
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
818
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
819
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
820
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
821
+ }).describe("A normalized PubMed article record.").nullable().optional()
822
+ }).describe("The result of retrieving one PubMed article.");
823
+ var getArticlesInput = external_exports.strictObject({
824
+ pmids: external_exports.array(external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).")).min(1).max(50).describe("The PubMed identifiers to retrieve.").optional()
825
+ }).describe("Input parameters for getting multiple PubMed articles.");
826
+ var getArticlesOutput = external_exports.strictObject({
827
+ articles: external_exports.array(external_exports.strictObject({
828
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
829
+ title: external_exports.string().describe("The article title.").optional(),
830
+ abstract: external_exports.array(external_exports.strictObject({
831
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
832
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
833
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
834
+ authors: external_exports.array(external_exports.strictObject({
835
+ name: external_exports.string().describe("The author or collective author name.").optional(),
836
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
837
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
838
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
839
+ journal: external_exports.strictObject({
840
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
841
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
842
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
843
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
844
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
845
+ }).describe("The journal information attached to a PubMed record.").optional(),
846
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
847
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
848
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
849
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
850
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
851
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
852
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
853
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
854
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
855
+ }).describe("A normalized PubMed article record.")).describe("The PubMed records that were found.").optional(),
856
+ notFoundPmids: external_exports.array(external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).")).describe("The requested PMIDs that PubMed did not return.").optional()
857
+ }).describe("The result of retrieving multiple PubMed articles.");
858
+ var findRelatedArticlesInput = external_exports.strictObject({
859
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID)."),
860
+ limit: external_exports.int().min(1).max(50).default(10).describe("The maximum number of articles to return.").optional()
861
+ }).describe("Input parameters for finding related PubMed articles.");
862
+ var findRelatedArticlesOutput = external_exports.strictObject({
863
+ sourcePmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
864
+ articles: external_exports.array(external_exports.strictObject({
865
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
866
+ title: external_exports.string().describe("The article title.").optional(),
867
+ abstract: external_exports.array(external_exports.strictObject({
868
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
869
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
870
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
871
+ authors: external_exports.array(external_exports.strictObject({
872
+ name: external_exports.string().describe("The author or collective author name.").optional(),
873
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
874
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
875
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
876
+ journal: external_exports.strictObject({
877
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
878
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
879
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
880
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
881
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
882
+ }).describe("The journal information attached to a PubMed record.").optional(),
883
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
884
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
885
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
886
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
887
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
888
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
889
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
890
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
891
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
892
+ }).describe("A normalized PubMed article record.")).describe("The normalized related PubMed articles.").optional()
893
+ }).describe("The related PubMed articles returned for one source record.");
894
+ var getCitingArticlesInput = external_exports.strictObject({
895
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID)."),
896
+ limit: external_exports.int().min(1).max(50).default(10).describe("The maximum number of articles to return.").optional()
897
+ }).describe("Input parameters for getting articles that cite a source PubMed record.");
898
+ var getCitingArticlesOutput = external_exports.strictObject({
899
+ sourcePmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
900
+ articles: external_exports.array(external_exports.strictObject({
901
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
902
+ title: external_exports.string().describe("The article title.").optional(),
903
+ abstract: external_exports.array(external_exports.strictObject({
904
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
905
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
906
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
907
+ authors: external_exports.array(external_exports.strictObject({
908
+ name: external_exports.string().describe("The author or collective author name.").optional(),
909
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
910
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
911
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
912
+ journal: external_exports.strictObject({
913
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
914
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
915
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
916
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
917
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
918
+ }).describe("The journal information attached to a PubMed record.").optional(),
919
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
920
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
921
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
922
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
923
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
924
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
925
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
926
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
927
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
928
+ }).describe("A normalized PubMed article record.")).describe("The normalized articles known to cite the source record.").optional()
929
+ }).describe("The citing PubMed articles returned for one source record.");
930
+ var getArticleReferencesInput = external_exports.strictObject({
931
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID)."),
932
+ limit: external_exports.int().min(1).max(50).default(10).describe("The maximum number of articles to return.").optional()
933
+ }).describe("Input parameters for getting references from a source PubMed record.");
934
+ var getArticleReferencesOutput = external_exports.strictObject({
935
+ sourcePmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
936
+ articles: external_exports.array(external_exports.strictObject({
937
+ pmid: external_exports.string().min(1).regex(new RegExp("^[0-9]+$")).describe("The numeric PubMed identifier (PMID).").optional(),
938
+ title: external_exports.string().describe("The article title.").optional(),
939
+ abstract: external_exports.array(external_exports.strictObject({
940
+ label: external_exports.string().describe("The structured abstract section label when present.").nullable().optional(),
941
+ text: external_exports.string().describe("The normalized abstract section text.").optional()
942
+ }).describe("One section of a PubMed abstract.")).describe("The structured or unstructured abstract sections.").optional(),
943
+ authors: external_exports.array(external_exports.strictObject({
944
+ name: external_exports.string().describe("The author or collective author name.").optional(),
945
+ orcid: external_exports.string().describe("The author's ORCID when present.").nullable().optional(),
946
+ affiliations: external_exports.array(external_exports.string().describe("One affiliation.")).describe("The author's affiliations.").optional()
947
+ }).describe("A normalized PubMed author or author group.")).describe("The article authors.").optional(),
948
+ journal: external_exports.strictObject({
949
+ title: external_exports.string().describe("The full journal title.").nullable().optional(),
950
+ abbreviation: external_exports.string().describe("The NLM journal abbreviation.").nullable().optional(),
951
+ issn: external_exports.string().describe("The journal ISSN returned by PubMed.").nullable().optional(),
952
+ volume: external_exports.string().describe("The journal volume.").nullable().optional(),
953
+ issue: external_exports.string().describe("The journal issue.").nullable().optional()
954
+ }).describe("The journal information attached to a PubMed record.").optional(),
955
+ publicationDate: external_exports.string().describe("The publication date or source Medline date.").nullable().optional(),
956
+ publicationTypes: external_exports.array(external_exports.string().describe("One publication type.")).describe("The PubMed publication types.").optional(),
957
+ meshTerms: external_exports.array(external_exports.string().describe("One MeSH descriptor.")).describe("The assigned Medical Subject Headings.").optional(),
958
+ keywords: external_exports.array(external_exports.string().describe("One keyword.")).describe("The keywords attached to the PubMed record.").optional(),
959
+ languages: external_exports.array(external_exports.string().describe("One language code.")).describe("The article language codes returned by PubMed.").optional(),
960
+ doi: external_exports.string().describe("The article DOI when present.").nullable().optional(),
961
+ pmcid: external_exports.string().describe("The PubMed Central identifier when present.").nullable().optional(),
962
+ pubmedUrl: external_exports.url().describe("The canonical PubMed record URL.").optional(),
963
+ pmcUrl: external_exports.url().describe("The PubMed Central article URL when available.").nullable().optional()
964
+ }).describe("A normalized PubMed article record.")).describe("The normalized PubMed articles referenced by the source record.").optional()
965
+ }).describe("The PubMed references returned for one source record.");
966
+ var convertArticleIdsInput = external_exports.strictObject({
967
+ ids: external_exports.array(external_exports.string().min(1).describe("One PMID, PMCID, DOI, or author manuscript identifier.")).min(1).max(200).describe("The article identifiers to convert. Every identifier must have the same idType.").optional(),
968
+ idType: external_exports.enum(["pmid", "pmcid", "doi", "mid"]).describe("The type shared by every input article identifier.").optional()
969
+ }).describe("Input parameters for converting article identifiers.");
970
+ var convertArticleIdsOutput = external_exports.strictObject({
971
+ records: external_exports.array(external_exports.strictObject({
972
+ requestedId: external_exports.string().describe("The original identifier from the request.").optional(),
973
+ pmid: external_exports.string().describe("The PubMed identifier when the article has one.").nullable().optional(),
974
+ pmcid: external_exports.string().describe("The PubMed Central identifier when the article is represented in PMC.").nullable().optional(),
975
+ doi: external_exports.string().describe("The DOI when PMC reports one.").nullable().optional(),
976
+ mid: external_exports.string().describe("The author manuscript identifier when PMC reports one.").nullable().optional(),
977
+ error: external_exports.string().describe("The PMC ID Converter error when the requested identifier could not be resolved.").nullable().optional()
978
+ }).describe("The available identifiers for one requested article.")).describe("One conversion result for each identifier returned by PMC.").optional()
979
+ }).describe("The available identifier mappings returned by PMC.");
980
+ var pubmedActions = {
981
+ search_articles: {
982
+ description: "Search PubMed with the official query syntax and return normalized article records.",
983
+ effect: "read",
984
+ inputSchema: searchArticlesInput,
985
+ outputSchema: external_exports.toJSONSchema(searchArticlesOutput, { io: "output", unrepresentable: "any" })
986
+ },
987
+ match_citation: {
988
+ description: "Match one raw biomedical citation to PubMed and return normalized candidate articles.",
989
+ effect: "write",
990
+ inputSchema: matchCitationInput,
991
+ outputSchema: external_exports.toJSONSchema(matchCitationOutput, { io: "output", unrepresentable: "any" })
992
+ },
993
+ get_article: {
994
+ description: "Get one normalized PubMed article by PMID.",
995
+ effect: "read",
996
+ inputSchema: getArticleInput,
997
+ outputSchema: external_exports.toJSONSchema(getArticleOutput, { io: "output", unrepresentable: "any" })
998
+ },
999
+ get_articles: {
1000
+ description: "Get multiple normalized PubMed articles by PMID in one request.",
1001
+ effect: "read",
1002
+ inputSchema: getArticlesInput,
1003
+ outputSchema: external_exports.toJSONSchema(getArticlesOutput, { io: "output", unrepresentable: "any" })
1004
+ },
1005
+ find_related_articles: {
1006
+ description: "Find normalized PubMed articles related to one source PMID.",
1007
+ effect: "read",
1008
+ inputSchema: findRelatedArticlesInput,
1009
+ outputSchema: external_exports.toJSONSchema(findRelatedArticlesOutput, { io: "output", unrepresentable: "any" })
1010
+ },
1011
+ get_citing_articles: {
1012
+ description: "Get normalized PubMed articles known to cite one source PMID. PubMed citation coverage depends on data supplied by publishers and NCBI sources and may be incomplete.",
1013
+ effect: "read",
1014
+ inputSchema: getCitingArticlesInput,
1015
+ outputSchema: external_exports.toJSONSchema(getCitingArticlesOutput, { io: "output", unrepresentable: "any" })
1016
+ },
1017
+ get_article_references: {
1018
+ description: "Get normalized PubMed references for one source PMID. References are available only when supplied by publishers or recoverable from PMC data.",
1019
+ effect: "read",
1020
+ inputSchema: getArticleReferencesInput,
1021
+ outputSchema: external_exports.toJSONSchema(getArticleReferencesOutput, { io: "output", unrepresentable: "any" })
1022
+ },
1023
+ convert_article_ids: {
1024
+ description: "Convert PMID, PMCID, DOI, or author manuscript identifiers with the PMC ID Converter. Complete mappings are available only for articles represented in PubMed Central.",
1025
+ effect: "write",
1026
+ inputSchema: convertArticleIdsInput,
1027
+ outputSchema: external_exports.toJSONSchema(convertArticleIdsOutput, { io: "output", unrepresentable: "any" })
1028
+ }
1029
+ };
1030
+
1031
+ // ../plugins/src/pubmed/index.ts
1032
+ function createPubmedPlugin() {
1033
+ return createProviderPlugin({
1034
+ description: "PubMed",
1035
+ actions: pubmedActions,
1036
+ handlers: {
1037
+ search_articles: searchArticles,
1038
+ match_citation: matchCitation,
1039
+ get_article: getArticle,
1040
+ get_articles: getArticles,
1041
+ find_related_articles: findRelatedArticles,
1042
+ get_citing_articles: getCitingArticles,
1043
+ get_article_references: getArticleReferences,
1044
+ convert_article_ids: convertArticleIds
1045
+ }
1046
+ });
1047
+ }
1048
+ var pubmed_default = createPubmedPlugin();
1049
+ export {
1050
+ createPubmedPlugin,
1051
+ pubmed_default as default
1052
+ };