@tool-bridge/server 0.16.0 → 0.17.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.
- package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
- package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
- package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
- package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
- package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
- package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
- package/dist/chunk-JXHMDBAY.js +45 -0
- package/dist/chunk-LMLX3DJF.js +50 -0
- package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
- package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
- package/dist/chunk-U5UHT7CX.js +977 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-WW2IMPQK.js +283 -0
- package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
- package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
- package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
- package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
- package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
- package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
- package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
- package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
- package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
- package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
- package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
- package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
- package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
- package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
- package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
- package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
- package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
- package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
- package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
- package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
- package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
- package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
- package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
- package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
- package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
- package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
- package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
- package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
- package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
- package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
- package/dist/index.d.ts +57 -50
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
- package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
- package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
- package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
- package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
- package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
- package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
- package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
- package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
- package/dist/main.js +103 -102
- package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
- package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
- package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
- package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
- package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
- package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
- package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
- package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
- package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
- package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
- package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
- package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
- package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
- package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
- package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
- package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
- package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
- package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
- package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
- package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
- package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
- package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
- package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
- package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
- package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
- package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
- package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
- package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
- package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
- package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
- package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
- package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
- package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
- package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
- package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
- package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
- package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
- package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
- package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
- package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
- package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
- package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
- package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
- package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
- package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
- package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
- package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
- package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
- package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
- package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
- package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.js} +124 -150
- package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
- package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-BNXOJMB6.js} +26 -34
- package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
- package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
- package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
- package/package.json +5 -5
- package/dist/chunk-2O27H4Y2.js +0 -183
- package/dist/chunk-GKX72JMJ.js +0 -378
- package/dist/chunk-MLKGABMK.js +0 -9
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readBoundedResponseBytes
|
|
3
|
+
} from "./chunk-LMLX3DJF.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
trimmedText
|
|
7
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
8
|
import {
|
|
2
9
|
createProviderPlugin,
|
|
3
10
|
upstreamError
|
|
4
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YASUMV2K.js";
|
|
5
12
|
import {
|
|
6
13
|
guardedFetch
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-GKX72JMJ.js";
|
|
14
|
+
} from "./chunk-U5UHT7CX.js";
|
|
9
15
|
import {
|
|
10
16
|
TBError,
|
|
11
17
|
external_exports
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-RVWZN3CI.js";
|
|
19
|
+
import "./chunk-U67V476Y.js";
|
|
14
20
|
|
|
15
21
|
// ../plugins/src/pubmed/api.ts
|
|
16
22
|
var EUTILS_BASE = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/";
|
|
@@ -28,14 +34,6 @@ var SORT_VALUES = {
|
|
|
28
34
|
publication_date: "pub date",
|
|
29
35
|
relevance: "relevance"
|
|
30
36
|
};
|
|
31
|
-
function record(value) {
|
|
32
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
33
|
-
}
|
|
34
|
-
function text(value) {
|
|
35
|
-
if (typeof value !== "string") return void 0;
|
|
36
|
-
const trimmed = value.trim();
|
|
37
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
38
|
-
}
|
|
39
37
|
function invalidInput(message) {
|
|
40
38
|
return new TBError("invalid_argument", message);
|
|
41
39
|
}
|
|
@@ -43,7 +41,7 @@ function invalidResponse(message) {
|
|
|
43
41
|
return new TBError("unavailable", message, { retryable: true });
|
|
44
42
|
}
|
|
45
43
|
function requireRecord(value, label) {
|
|
46
|
-
const result =
|
|
44
|
+
const result = asJsonObject(value);
|
|
47
45
|
if (result === void 0) throw invalidResponse(`${label} \u4E0D\u662F\u5BF9\u8C61`);
|
|
48
46
|
return result;
|
|
49
47
|
}
|
|
@@ -58,7 +56,7 @@ function requireStringArray(value, label) {
|
|
|
58
56
|
return value;
|
|
59
57
|
}
|
|
60
58
|
function requireInputText(value, field) {
|
|
61
|
-
const result =
|
|
59
|
+
const result = trimmedText(value);
|
|
62
60
|
if (result === void 0) throw invalidInput(`${field} is required.`);
|
|
63
61
|
return result;
|
|
64
62
|
}
|
|
@@ -90,14 +88,14 @@ function readIdType(value) {
|
|
|
90
88
|
throw invalidInput("idType must be doi, mid, pmcid, or pmid");
|
|
91
89
|
}
|
|
92
90
|
function readSort(value) {
|
|
93
|
-
const sort =
|
|
91
|
+
const sort = trimmedText(value);
|
|
94
92
|
if (sort === void 0) return void 0;
|
|
95
93
|
const mapped = SORT_VALUES[sort];
|
|
96
94
|
if (mapped === void 0) throw invalidInput("sort is not supported by PubMed");
|
|
97
95
|
return mapped;
|
|
98
96
|
}
|
|
99
97
|
function readPublicationDateRange(value) {
|
|
100
|
-
const range =
|
|
98
|
+
const range = asJsonObject(value);
|
|
101
99
|
if (range === void 0) return void 0;
|
|
102
100
|
const from = requireInputText(range.from, "publicationDateRange.from");
|
|
103
101
|
const to = requireInputText(range.to, "publicationDateRange.to");
|
|
@@ -113,44 +111,14 @@ async function readBoundedText(response, maxBytes, source) {
|
|
|
113
111
|
const tooLarge = () => invalidInput(
|
|
114
112
|
`${source} \u54CD\u5E94\u8D85\u8FC7 ${maxBytes} \u5B57\u8282\u4E0A\u9650:\u628A limit / pmids / ids \u8C03\u5C0F\u540E\u91CD\u8BD5`
|
|
115
113
|
);
|
|
116
|
-
|
|
117
|
-
if (Number.isSafeInteger(declared) && declared > maxBytes) throw tooLarge();
|
|
118
|
-
if (response.body === null) {
|
|
119
|
-
const bytes2 = new Uint8Array(await response.arrayBuffer());
|
|
120
|
-
if (bytes2.byteLength > maxBytes) throw tooLarge();
|
|
121
|
-
return new TextDecoder().decode(bytes2);
|
|
122
|
-
}
|
|
123
|
-
const reader = response.body.getReader();
|
|
124
|
-
const chunks = [];
|
|
125
|
-
let total = 0;
|
|
126
|
-
try {
|
|
127
|
-
for (; ; ) {
|
|
128
|
-
const { done, value } = await reader.read();
|
|
129
|
-
if (done) break;
|
|
130
|
-
total += value.byteLength;
|
|
131
|
-
if (total > maxBytes) {
|
|
132
|
-
await reader.cancel().catch(() => void 0);
|
|
133
|
-
throw tooLarge();
|
|
134
|
-
}
|
|
135
|
-
chunks.push(value);
|
|
136
|
-
}
|
|
137
|
-
} finally {
|
|
138
|
-
reader.releaseLock();
|
|
139
|
-
}
|
|
140
|
-
const bytes = new Uint8Array(total);
|
|
141
|
-
let offset = 0;
|
|
142
|
-
for (const chunk of chunks) {
|
|
143
|
-
bytes.set(chunk, offset);
|
|
144
|
-
offset += chunk.byteLength;
|
|
145
|
-
}
|
|
146
|
-
return new TextDecoder().decode(bytes);
|
|
114
|
+
return new TextDecoder().decode(await readBoundedResponseBytes(response, { maxBytes, tooLarge }));
|
|
147
115
|
}
|
|
148
116
|
function extractError(body) {
|
|
149
117
|
const trimmed = body.trim();
|
|
150
118
|
if (trimmed === "") return void 0;
|
|
151
119
|
try {
|
|
152
|
-
const payload =
|
|
153
|
-
const direct =
|
|
120
|
+
const payload = asJsonObject(JSON.parse(trimmed));
|
|
121
|
+
const direct = trimmedText(payload?.error);
|
|
154
122
|
if (direct !== void 0) return direct;
|
|
155
123
|
const errors = payload?.errors;
|
|
156
124
|
if (Array.isArray(errors)) {
|
|
@@ -204,7 +172,7 @@ async function eutils(ctx, utility, query, options) {
|
|
|
204
172
|
for (const [name, value] of Object.entries(query)) {
|
|
205
173
|
if (value !== void 0) url.searchParams.set(name, value);
|
|
206
174
|
}
|
|
207
|
-
const apiKey =
|
|
175
|
+
const apiKey = trimmedText(ctx.upstreamAuth);
|
|
208
176
|
if (apiKey !== void 0) url.searchParams.set("api_key", apiKey);
|
|
209
177
|
const usePost = utility === "esearch.fcgi" && (query.term?.length ?? 0) > ESEARCH_POST_TERM_LENGTH;
|
|
210
178
|
let body;
|
|
@@ -389,7 +357,7 @@ function firstElement(parent, name) {
|
|
|
389
357
|
return elements(parent, name)[0];
|
|
390
358
|
}
|
|
391
359
|
function attribute(element, name) {
|
|
392
|
-
return
|
|
360
|
+
return trimmedText(element.attributes[name]);
|
|
393
361
|
}
|
|
394
362
|
function textOf(element) {
|
|
395
363
|
if (element === void 0) return "";
|
|
@@ -573,7 +541,7 @@ function readLinkedPmids(payload, linkName, label) {
|
|
|
573
541
|
const linksets = Array.isArray(payload.linksets) ? requireObjectArray(payload.linksets, `${label} linkset`) : [];
|
|
574
542
|
for (const linkset of linksets) {
|
|
575
543
|
const databases = Array.isArray(linkset.linksetdbs) ? requireObjectArray(linkset.linksetdbs, `${label} database`) : [];
|
|
576
|
-
const related = databases.find((database) =>
|
|
544
|
+
const related = databases.find((database) => trimmedText(database.linkname) === linkName);
|
|
577
545
|
if (related !== void 0) return requireStringArray(related.links, label);
|
|
578
546
|
}
|
|
579
547
|
return [];
|
|
@@ -592,14 +560,14 @@ async function linkedArticles(ctx, sourcePmid, linkName, limit) {
|
|
|
592
560
|
};
|
|
593
561
|
}
|
|
594
562
|
function readIntegerString(value, label) {
|
|
595
|
-
const raw =
|
|
563
|
+
const raw = trimmedText(value);
|
|
596
564
|
const parsed = raw === void 0 ? Number.NaN : Number(raw);
|
|
597
565
|
if (!Number.isSafeInteger(parsed) || parsed < 0) throw invalidResponse(`${label} is malformed`);
|
|
598
566
|
return parsed;
|
|
599
567
|
}
|
|
600
568
|
function optionalIdentifier(value) {
|
|
601
569
|
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
|
|
602
|
-
return
|
|
570
|
+
return trimmedText(value) ?? null;
|
|
603
571
|
}
|
|
604
572
|
async function searchArticles(input, ctx) {
|
|
605
573
|
const query = requireInputText(input.query, "query");
|
|
@@ -626,7 +594,7 @@ async function searchArticles(input, ctx) {
|
|
|
626
594
|
total: readIntegerString(result.count, "PubMed search count"),
|
|
627
595
|
offset,
|
|
628
596
|
limit,
|
|
629
|
-
queryTranslation:
|
|
597
|
+
queryTranslation: trimmedText(result.querytranslation) ?? null,
|
|
630
598
|
articles: pmids.length > 0 ? await fetchArticles(ctx, pmids) : []
|
|
631
599
|
};
|
|
632
600
|
}
|
|
@@ -696,11 +664,11 @@ async function convertArticleIds(input) {
|
|
|
696
664
|
return {
|
|
697
665
|
requestedId,
|
|
698
666
|
pmid: optionalIdentifier(item.pmid),
|
|
699
|
-
pmcid:
|
|
700
|
-
doi:
|
|
701
|
-
mid:
|
|
667
|
+
pmcid: trimmedText(item.pmcid) ?? null,
|
|
668
|
+
doi: trimmedText(item.doi) ?? null,
|
|
669
|
+
mid: trimmedText(item.mid) ?? null,
|
|
702
670
|
// PMC 用 `errmsg` 报"这个 id 解析不了",是逐条结果的一部分,不是整体失败。
|
|
703
|
-
error:
|
|
671
|
+
error: trimmedText(item.errmsg) ?? null
|
|
704
672
|
};
|
|
705
673
|
})
|
|
706
674
|
};
|
|
@@ -1,51 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asJsonObject,
|
|
3
|
+
compactDefined,
|
|
4
|
+
trimmedText
|
|
5
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
6
|
import {
|
|
2
7
|
createProviderPlugin,
|
|
3
8
|
requireApiKey,
|
|
4
9
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-YASUMV2K.js";
|
|
6
11
|
import {
|
|
7
12
|
guardedFetch
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
13
|
+
} from "./chunk-U5UHT7CX.js";
|
|
10
14
|
import {
|
|
11
15
|
TBError,
|
|
12
16
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-RVWZN3CI.js";
|
|
18
|
+
import "./chunk-U67V476Y.js";
|
|
15
19
|
|
|
16
20
|
// ../plugins/src/railway/api.ts
|
|
17
21
|
var SERVICE = "railway";
|
|
18
22
|
var GRAPHQL_URL = "https://backboard.railway.com/graphql/v2";
|
|
19
23
|
var DEFAULT_DEPLOYMENT_LIMIT = 20;
|
|
20
24
|
var DEFAULT_LOG_LIMIT = 500;
|
|
21
|
-
function record(value) {
|
|
22
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
23
|
-
}
|
|
24
|
-
function text(value) {
|
|
25
|
-
if (typeof value !== "string") return void 0;
|
|
26
|
-
const trimmed = value.trim();
|
|
27
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
28
|
-
}
|
|
29
|
-
function compact(input) {
|
|
30
|
-
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
31
|
-
}
|
|
32
25
|
function responseError(message) {
|
|
33
26
|
return new TBError("unavailable", message, { retryable: true });
|
|
34
27
|
}
|
|
35
28
|
function required(value, field) {
|
|
36
|
-
const result =
|
|
29
|
+
const result = trimmedText(value);
|
|
37
30
|
if (result === void 0) throw new TBError("invalid_argument", `${field} \u662F\u5FC5\u586B\u7684`);
|
|
38
31
|
return result;
|
|
39
32
|
}
|
|
40
33
|
function errorMessages(payload) {
|
|
41
|
-
const errors =
|
|
34
|
+
const errors = asJsonObject(payload)?.errors;
|
|
42
35
|
if (!Array.isArray(errors)) return void 0;
|
|
43
|
-
const messages = errors.map((error) =>
|
|
36
|
+
const messages = errors.map((error) => trimmedText(asJsonObject(error)?.message)).filter((message) => message !== void 0);
|
|
44
37
|
return messages.length > 0 ? messages.join("; ") : void 0;
|
|
45
38
|
}
|
|
46
39
|
function errorText(payload, status) {
|
|
47
|
-
const body =
|
|
48
|
-
return errorMessages(payload) ??
|
|
40
|
+
const body = asJsonObject(payload);
|
|
41
|
+
return errorMessages(payload) ?? trimmedText(body?.message) ?? trimmedText(body?.error) ?? trimmedText(body?.detail) ?? trimmedText(body?.title) ?? `Railway \u8FD4\u56DE HTTP ${status}`;
|
|
49
42
|
}
|
|
50
43
|
async function graphql(ctx, query, variables) {
|
|
51
44
|
const response = await guardedFetch(GRAPHQL_URL, {
|
|
@@ -67,19 +60,19 @@ async function graphql(ctx, query, variables) {
|
|
|
67
60
|
}
|
|
68
61
|
}
|
|
69
62
|
if (!response.ok) throw upstreamError(response.status, errorText(payload, response.status));
|
|
70
|
-
const envelope =
|
|
63
|
+
const envelope = asJsonObject(payload);
|
|
71
64
|
if (envelope === void 0) throw responseError("Railway GraphQL \u54CD\u5E94\u4E0D\u662F\u5BF9\u8C61");
|
|
72
65
|
const failure = errorMessages(envelope);
|
|
73
66
|
if (failure !== void 0) throw new TBError("invalid_argument", failure);
|
|
74
|
-
const data =
|
|
67
|
+
const data = asJsonObject(envelope.data);
|
|
75
68
|
if (data === void 0) throw responseError("Railway GraphQL \u54CD\u5E94\u7F3A data");
|
|
76
69
|
return data;
|
|
77
70
|
}
|
|
78
71
|
function nodes(value) {
|
|
79
|
-
const edges =
|
|
72
|
+
const edges = asJsonObject(value)?.edges;
|
|
80
73
|
if (!Array.isArray(edges)) return [];
|
|
81
74
|
return edges.flatMap((edge) => {
|
|
82
|
-
const node =
|
|
75
|
+
const node = asJsonObject(asJsonObject(edge)?.node);
|
|
83
76
|
return node === void 0 ? [] : [node];
|
|
84
77
|
});
|
|
85
78
|
}
|
|
@@ -88,7 +81,7 @@ function requireValue(value, message) {
|
|
|
88
81
|
return value;
|
|
89
82
|
}
|
|
90
83
|
function workspaceId(ctx) {
|
|
91
|
-
return
|
|
84
|
+
return trimmedText(ctx.config?.workspaceId);
|
|
92
85
|
}
|
|
93
86
|
var PROJECT_FIELDS = "id name description createdAt updatedAt";
|
|
94
87
|
var DEPLOYMENT_FIELDS = "id status createdAt url staticUrl";
|
|
@@ -116,9 +109,9 @@ async function getProject(input, ctx) {
|
|
|
116
109
|
environments { edges { node { id name } } }
|
|
117
110
|
}
|
|
118
111
|
}`, { id: required(input.projectId, "projectId") });
|
|
119
|
-
const project = requireValue(
|
|
112
|
+
const project = requireValue(asJsonObject(data.project), "Railway \u6CA1\u6709\u8FD4\u56DE project");
|
|
120
113
|
return {
|
|
121
|
-
project:
|
|
114
|
+
project: compactDefined({
|
|
122
115
|
id: project.id,
|
|
123
116
|
name: project.name,
|
|
124
117
|
// 上游把缺席的 description 显式归一成 null(出参声明里它是 nullable 的)。
|
|
@@ -149,7 +142,7 @@ async function getServiceInstance(input, ctx) {
|
|
|
149
142
|
environmentId: required(input.environmentId, "environmentId")
|
|
150
143
|
});
|
|
151
144
|
return {
|
|
152
|
-
serviceInstance: requireValue(
|
|
145
|
+
serviceInstance: requireValue(asJsonObject(data.serviceInstance), "Railway \u6CA1\u6709\u8FD4\u56DE serviceInstance")
|
|
153
146
|
};
|
|
154
147
|
}
|
|
155
148
|
async function listDeployments(input, ctx) {
|
|
@@ -173,7 +166,7 @@ async function getDeployment(input, ctx) {
|
|
|
173
166
|
${DEPLOYMENT_FIELDS} meta canRedeploy canRollback
|
|
174
167
|
}
|
|
175
168
|
}`, { id: required(input.deploymentId, "deploymentId") });
|
|
176
|
-
return { deployment: requireValue(
|
|
169
|
+
return { deployment: requireValue(asJsonObject(data.deployment), "Railway \u6CA1\u6709\u8FD4\u56DE deployment") };
|
|
177
170
|
}
|
|
178
171
|
async function getDeploymentLogs(input, ctx) {
|
|
179
172
|
const data = await graphql(ctx, `query deploymentLogs(
|
|
@@ -192,12 +185,12 @@ async function getDeploymentLogs(input, ctx) {
|
|
|
192
185
|
) {
|
|
193
186
|
timestamp message severity
|
|
194
187
|
}
|
|
195
|
-
}`,
|
|
188
|
+
}`, compactDefined({
|
|
196
189
|
deploymentId: required(input.deploymentId, "deploymentId"),
|
|
197
190
|
limit: input.limit ?? DEFAULT_LOG_LIMIT,
|
|
198
|
-
filter:
|
|
199
|
-
startDate:
|
|
200
|
-
endDate:
|
|
191
|
+
filter: trimmedText(input.filter),
|
|
192
|
+
startDate: trimmedText(input.startDate),
|
|
193
|
+
endDate: trimmedText(input.endDate)
|
|
201
194
|
}));
|
|
202
195
|
return { logs: Array.isArray(data.deploymentLogs) ? data.deploymentLogs : [] };
|
|
203
196
|
}
|
|
@@ -207,10 +200,10 @@ async function deployService(input, ctx) {
|
|
|
207
200
|
`mutation serviceInstanceDeployV2($serviceId: String!, $environmentId: String!, $commitSha: String) {
|
|
208
201
|
serviceInstanceDeployV2(serviceId: $serviceId, environmentId: $environmentId, commitSha: $commitSha)
|
|
209
202
|
}`,
|
|
210
|
-
|
|
203
|
+
compactDefined({
|
|
211
204
|
serviceId: required(input.serviceId, "serviceId"),
|
|
212
205
|
environmentId: required(input.environmentId, "environmentId"),
|
|
213
|
-
commitSha:
|
|
206
|
+
commitSha: trimmedText(input.commitSha)
|
|
214
207
|
})
|
|
215
208
|
);
|
|
216
209
|
return {
|
|
@@ -221,10 +214,10 @@ async function upsertVariable(input, ctx) {
|
|
|
221
214
|
const data = await graphql(ctx, `mutation variableUpsert($input: VariableUpsertInput!) {
|
|
222
215
|
variableUpsert(input: $input)
|
|
223
216
|
}`, {
|
|
224
|
-
input:
|
|
217
|
+
input: compactDefined({
|
|
225
218
|
projectId: required(input.projectId, "projectId"),
|
|
226
219
|
environmentId: required(input.environmentId, "environmentId"),
|
|
227
|
-
serviceId:
|
|
220
|
+
serviceId: trimmedText(input.serviceId),
|
|
228
221
|
name: required(input.name, "name"),
|
|
229
222
|
// 变量值不透明:空串与前后空白都要原样写进去。
|
|
230
223
|
value: input.value,
|
|
@@ -237,7 +230,7 @@ async function rollbackDeployment(input, ctx) {
|
|
|
237
230
|
const data = await graphql(ctx, `mutation deploymentRollback($id: String!) {
|
|
238
231
|
deploymentRollback(id: $id) { ${DEPLOYMENT_FIELDS} }
|
|
239
232
|
}`, { id: required(input.deploymentId, "deploymentId") });
|
|
240
|
-
return { deployment: requireValue(
|
|
233
|
+
return { deployment: requireValue(asJsonObject(data.deploymentRollback), "Railway \u6CA1\u6709\u8FD4\u56DE\u56DE\u6EDA\u540E\u7684 deployment") };
|
|
241
234
|
}
|
|
242
235
|
|
|
243
236
|
// ../plugins/src/railway/schema.ts
|
|
@@ -1,37 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined,
|
|
7
|
+
integerValue,
|
|
8
|
+
trimmedText
|
|
9
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
10
|
import {
|
|
2
11
|
createProviderPlugin,
|
|
3
12
|
requireApiKey,
|
|
4
13
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
14
|
+
} from "./chunk-YASUMV2K.js";
|
|
15
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
16
|
import {
|
|
11
17
|
TBError,
|
|
12
18
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
19
|
+
} from "./chunk-RVWZN3CI.js";
|
|
20
|
+
import "./chunk-U67V476Y.js";
|
|
15
21
|
|
|
16
22
|
// ../plugins/src/readwise/api.ts
|
|
17
23
|
var SERVICE = "readwise";
|
|
18
24
|
var API_BASE = "https://readwise.io/api";
|
|
19
|
-
|
|
20
|
-
return typeof value === "string" ? value.trim() || void 0 : void 0;
|
|
21
|
-
}
|
|
22
|
-
function record(value) {
|
|
23
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
24
|
-
}
|
|
25
|
-
function integer(value) {
|
|
26
|
-
return typeof value === "number" && Number.isInteger(value) ? value : void 0;
|
|
27
|
-
}
|
|
25
|
+
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
28
26
|
function readArray(value) {
|
|
29
27
|
return Array.isArray(value) ? value : [];
|
|
30
28
|
}
|
|
31
29
|
function errorMessage(payload, status) {
|
|
32
|
-
const object =
|
|
30
|
+
const object = asJsonObject(payload);
|
|
33
31
|
if (object !== void 0) {
|
|
34
|
-
const direct =
|
|
32
|
+
const direct = trimmedText(object.detail) ?? trimmedText(object.message) ?? trimmedText(object.error);
|
|
35
33
|
if (direct !== void 0) return direct;
|
|
36
34
|
for (const value of Object.values(object)) {
|
|
37
35
|
if (Array.isArray(value)) {
|
|
@@ -43,40 +41,26 @@ function errorMessage(payload, status) {
|
|
|
43
41
|
return `Readwise request failed with status ${status}`;
|
|
44
42
|
}
|
|
45
43
|
async function request(ctx, input) {
|
|
46
|
-
const
|
|
47
|
-
for (const [key, value] of Object.entries(input.query ?? {})) {
|
|
48
|
-
url.searchParams.set(key, value);
|
|
49
|
-
}
|
|
50
|
-
const response = await guardedFetch(url.toString(), {
|
|
44
|
+
const response = await http.request({
|
|
51
45
|
method: input.method ?? "GET",
|
|
46
|
+
path: input.path,
|
|
47
|
+
query: Object.entries(input.query ?? {}),
|
|
52
48
|
headers: {
|
|
53
49
|
accept: "application/json",
|
|
54
50
|
// Readwise 用的是 `Token <key>`,不是 Bearer —— 写成 Bearer 会一直 401。
|
|
55
|
-
authorization: `Token ${requireApiKey(ctx, SERVICE)}
|
|
56
|
-
...input.body === void 0 ? {} : { "content-type": "application/json" }
|
|
51
|
+
authorization: `Token ${requireApiKey(ctx, SERVICE)}`
|
|
57
52
|
},
|
|
58
|
-
...input.body === void 0 ? {} : {
|
|
53
|
+
...input.body === void 0 ? {} : { json: input.body },
|
|
54
|
+
invalidJsonMessage: "Readwise \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON",
|
|
55
|
+
mapError: ({ bodyKind, data, status }) => bodyKind === "invalid-json" ? new TBError("unavailable", "Readwise \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON", { retryable: true }) : upstreamError(status, errorMessage(data, status))
|
|
59
56
|
});
|
|
60
|
-
|
|
61
|
-
let payload = null;
|
|
62
|
-
if (body.trim() !== "") {
|
|
63
|
-
try {
|
|
64
|
-
payload = JSON.parse(body);
|
|
65
|
-
} catch {
|
|
66
|
-
throw new TBError("unavailable", "Readwise \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON", { retryable: true });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
|
|
70
|
-
return payload ?? {};
|
|
57
|
+
return response.bodyKind === "empty" ? {} : response.data;
|
|
71
58
|
}
|
|
72
59
|
function requireRecord(value, message) {
|
|
73
|
-
const object =
|
|
60
|
+
const object = asJsonObject(value);
|
|
74
61
|
if (object === void 0) throw new TBError("unavailable", message, { retryable: true });
|
|
75
62
|
return object;
|
|
76
63
|
}
|
|
77
|
-
function compact(input) {
|
|
78
|
-
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
79
|
-
}
|
|
80
64
|
function query(input) {
|
|
81
65
|
const output = {};
|
|
82
66
|
for (const [key, value] of Object.entries(input)) {
|
|
@@ -86,58 +70,58 @@ function query(input) {
|
|
|
86
70
|
return output;
|
|
87
71
|
}
|
|
88
72
|
function normalizeHighlight(value) {
|
|
89
|
-
const item =
|
|
73
|
+
const item = asJsonObject(value) ?? {};
|
|
90
74
|
return {
|
|
91
|
-
id:
|
|
92
|
-
text:
|
|
93
|
-
title:
|
|
94
|
-
author:
|
|
75
|
+
id: integerValue(item.id) ?? null,
|
|
76
|
+
text: trimmedText(item.text) ?? "",
|
|
77
|
+
title: trimmedText(item.title) ?? null,
|
|
78
|
+
author: trimmedText(item.author) ?? null,
|
|
95
79
|
// note 保留空串:上游用 typeof 判断而非 optionalString,清空备注要能表达出来。
|
|
96
80
|
note: typeof item.note === "string" ? item.note : null,
|
|
97
|
-
url:
|
|
98
|
-
highlightedAt:
|
|
99
|
-
updatedAt:
|
|
81
|
+
url: trimmedText(item.url) ?? null,
|
|
82
|
+
highlightedAt: trimmedText(item.highlighted_at) ?? trimmedText(item.highlightedAt) ?? null,
|
|
83
|
+
updatedAt: trimmedText(item.updated_at) ?? trimmedText(item.updatedAt) ?? null,
|
|
100
84
|
raw: item
|
|
101
85
|
};
|
|
102
86
|
}
|
|
103
87
|
function normalizeBook(value) {
|
|
104
|
-
const item =
|
|
88
|
+
const item = asJsonObject(value) ?? {};
|
|
105
89
|
return {
|
|
106
90
|
// export 接口回的是 user_book_id,books 接口回的是 id。
|
|
107
|
-
id:
|
|
108
|
-
title:
|
|
109
|
-
author:
|
|
110
|
-
category:
|
|
111
|
-
source:
|
|
112
|
-
numHighlights:
|
|
113
|
-
updatedAt:
|
|
91
|
+
id: integerValue(item.user_book_id) ?? integerValue(item.id) ?? null,
|
|
92
|
+
title: trimmedText(item.title) ?? null,
|
|
93
|
+
author: trimmedText(item.author) ?? null,
|
|
94
|
+
category: trimmedText(item.category) ?? null,
|
|
95
|
+
source: trimmedText(item.source) ?? null,
|
|
96
|
+
numHighlights: integerValue(item.num_highlights) ?? integerValue(item.numHighlights) ?? null,
|
|
97
|
+
updatedAt: trimmedText(item.updated) ?? trimmedText(item.updated_at) ?? null,
|
|
114
98
|
highlights: readArray(item.highlights).map(normalizeHighlight),
|
|
115
99
|
raw: item
|
|
116
100
|
};
|
|
117
101
|
}
|
|
118
102
|
function readTags(value) {
|
|
119
103
|
if (Array.isArray(value)) return value.filter((item) => typeof item === "string");
|
|
120
|
-
const object =
|
|
104
|
+
const object = asJsonObject(value);
|
|
121
105
|
return object === void 0 ? [] : Object.keys(object);
|
|
122
106
|
}
|
|
123
107
|
function normalizeDocument(value) {
|
|
124
|
-
const item =
|
|
108
|
+
const item = asJsonObject(value) ?? {};
|
|
125
109
|
return {
|
|
126
|
-
id:
|
|
127
|
-
url:
|
|
128
|
-
sourceUrl:
|
|
129
|
-
title:
|
|
130
|
-
author:
|
|
131
|
-
category:
|
|
132
|
-
location:
|
|
110
|
+
id: trimmedText(item.id) ?? trimmedText(item.document_id) ?? null,
|
|
111
|
+
url: trimmedText(item.url) ?? null,
|
|
112
|
+
sourceUrl: trimmedText(item.source_url) ?? trimmedText(item.sourceUrl) ?? null,
|
|
113
|
+
title: trimmedText(item.title) ?? null,
|
|
114
|
+
author: trimmedText(item.author) ?? null,
|
|
115
|
+
category: trimmedText(item.category) ?? null,
|
|
116
|
+
location: trimmedText(item.location) ?? null,
|
|
133
117
|
tags: readTags(item.tags),
|
|
134
|
-
createdAt:
|
|
135
|
-
updatedAt:
|
|
118
|
+
createdAt: trimmedText(item.created_at) ?? trimmedText(item.createdAt) ?? null,
|
|
119
|
+
updatedAt: trimmedText(item.updated_at) ?? trimmedText(item.updatedAt) ?? null,
|
|
136
120
|
raw: item
|
|
137
121
|
};
|
|
138
122
|
}
|
|
139
123
|
function readDocumentRecord(payload) {
|
|
140
|
-
return
|
|
124
|
+
return asJsonObject(payload.document) ?? asJsonObject(payload.result) ?? asJsonObject(payload.saved_document) ?? payload;
|
|
141
125
|
}
|
|
142
126
|
async function createHighlights(input, ctx) {
|
|
143
127
|
const payload = await request(ctx, {
|
|
@@ -157,8 +141,8 @@ async function exportHighlights(input, ctx) {
|
|
|
157
141
|
"Readwise \u8FD4\u56DE\u4E86\u975E\u6CD5\u7684 export \u54CD\u5E94"
|
|
158
142
|
);
|
|
159
143
|
return {
|
|
160
|
-
count:
|
|
161
|
-
nextPageCursor:
|
|
144
|
+
count: integerValue(payload.count) ?? null,
|
|
145
|
+
nextPageCursor: trimmedText(payload.nextPageCursor) ?? null,
|
|
162
146
|
books: readArray(payload.results).map(normalizeBook),
|
|
163
147
|
raw: payload
|
|
164
148
|
};
|
|
@@ -178,9 +162,9 @@ async function listBooks(input, ctx) {
|
|
|
178
162
|
"Readwise \u8FD4\u56DE\u4E86\u975E\u6CD5\u7684 books \u54CD\u5E94"
|
|
179
163
|
);
|
|
180
164
|
return {
|
|
181
|
-
count:
|
|
182
|
-
next:
|
|
183
|
-
previous:
|
|
165
|
+
count: integerValue(payload.count) ?? null,
|
|
166
|
+
next: trimmedText(payload.next) ?? null,
|
|
167
|
+
previous: trimmedText(payload.previous) ?? null,
|
|
184
168
|
books: readArray(payload.results).map(normalizeBook),
|
|
185
169
|
raw: payload
|
|
186
170
|
};
|
|
@@ -200,8 +184,8 @@ async function listDocuments(input, ctx) {
|
|
|
200
184
|
"Readwise \u8FD4\u56DE\u4E86\u975E\u6CD5\u7684\u6587\u6863\u5217\u8868"
|
|
201
185
|
);
|
|
202
186
|
return {
|
|
203
|
-
count:
|
|
204
|
-
nextPageCursor:
|
|
187
|
+
count: integerValue(payload.count) ?? null,
|
|
188
|
+
nextPageCursor: trimmedText(payload.nextPageCursor) ?? null,
|
|
205
189
|
documents: readArray(payload.results).map(normalizeDocument),
|
|
206
190
|
raw: payload
|
|
207
191
|
};
|
|
@@ -211,7 +195,7 @@ async function saveDocument(input, ctx) {
|
|
|
211
195
|
await request(ctx, {
|
|
212
196
|
path: "/v3/save/",
|
|
213
197
|
method: "POST",
|
|
214
|
-
body:
|
|
198
|
+
body: compactDefined({
|
|
215
199
|
url: input.url,
|
|
216
200
|
title: input.title,
|
|
217
201
|
author: input.author,
|
|
@@ -230,7 +214,7 @@ async function updateDocument(input, ctx) {
|
|
|
230
214
|
await request(ctx, {
|
|
231
215
|
path: `/v3/update/${encodeURIComponent(input.documentId)}/`,
|
|
232
216
|
method: "PATCH",
|
|
233
|
-
body:
|
|
217
|
+
body: compactDefined({
|
|
234
218
|
location: input.location,
|
|
235
219
|
title: input.title,
|
|
236
220
|
author: input.author,
|