@tool-bridge/server 0.16.0 → 0.19.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 (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-23JBIM6X.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-ADWBTCIH.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-CYQCYW2Z.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-5P62HDNR.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-54RZUAGW.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-AHJ6FTD5.js} +52 -77
  7. package/dist/{chunk-VK3V2WTY.js → chunk-B4P6YZFS.js} +4 -6
  8. package/dist/{chunk-BB6ZLMTU.js → chunk-CLEZ6YQ6.js} +2600 -481
  9. package/dist/chunk-JXHMDBAY.js +45 -0
  10. package/dist/chunk-LMLX3DJF.js +50 -0
  11. package/dist/{chunk-YB2FLNWI.js → chunk-OKRZPQ3R.js} +2558 -1926
  12. package/dist/chunk-SWBNHIO4.js +977 -0
  13. package/dist/chunk-U67V476Y.js +35 -0
  14. package/dist/chunk-VLOIDU5U.js +283 -0
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-UM3NSQJ3.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-FE5LQ2CZ.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-KEZABKUT.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-4IPJADXP.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-56QEKNQI.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-3QRM5K5T.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-L6G4OND5.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-LGC6HBFG.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-XDMK3BIU.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-4QARMFZU.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-C6JSJKOT.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-6A6TVACJ.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-SIWWW6AA.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-3IJXOKSP.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-L4KDA4DC.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-SDM75H4P.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-6DD436DN.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-SYSGYB3R.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-FZG7ASTF.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-HMRCZBUC.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-FAFSD7I3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-4D3TWENM.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-OSO2FOZS.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-OR4I4RHE.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-5AOPJ63E.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-SOJIJUWH.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-QSKN5TLN.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-R3AIZM7M.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-4CR3QOAX.js} +32 -46
  44. package/dist/index.d.ts +108 -56
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-OBCG6X6J.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-NHH3DTQW.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-7POMCBEC.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-YXVKROV4.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-LADO3VJU.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-XZ6UAQFU.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-P74GLNE7.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-CXJ7D37A.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-EVVHWFLK.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-WG2MRGBD.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-HQWUKG6U.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-SQMJIFOE.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-E27G2DZI.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-MIL63NIT.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-AIZVCBNR.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-XS4DVIQS.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-JEOUSL2Y.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-U4EZVDW2.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-AZSQEYEJ.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-HW3SYMTQ.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-QX74MAEL.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-OXSKYL6N.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-CCQAPDSW.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-6KQPSSCK.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-2TXO7IQE.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-YOO7NULI.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-Q6RIFIFP.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-KUMGCES3.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-VXQHBSMB.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-YLIPF52S.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-CRY7UJN5.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-3Z4T5AM7.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-BP37IGFL.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-HTKICF4K.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-WIVTUXJH.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-JJYPA43D.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-TKHZVG7A.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-FRSZLG5U.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-M5WXGQWE.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-PMXNLLBK.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-HFW4TAOH.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-KXVH2VZQ.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-WWOT2LRX.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-FY635H35.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-HQLBVSA5.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-GJN2GOHB.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BBNZGQU6.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-DPENIBOG.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-L4NONG6H.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-H67MAEZS.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-G2BSP4DX.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-7WMVFDG2.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-ZUAESFC2.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-EYFYIX3B.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-AXAUDUVF.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-UCQAWPLR.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-ZPZ4ASU6.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-4QVKKUD5.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-VGEFJTYC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-JME4TSCN.js} +124 -150
  107. package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
  108. package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-TRGU2MDG.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-WRUKLCZR.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-ZDW4EHS4.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-4VI67CWU.js} +35 -57
  112. package/package.json +3 -3
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. 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-VK3V2WTY.js";
11
+ } from "./chunk-B4P6YZFS.js";
5
12
  import {
6
13
  guardedFetch
7
- } from "./chunk-2O27H4Y2.js";
8
- import "./chunk-GKX72JMJ.js";
14
+ } from "./chunk-SWBNHIO4.js";
9
15
  import {
10
16
  TBError,
11
17
  external_exports
12
- } from "./chunk-YB2FLNWI.js";
13
- import "./chunk-MLKGABMK.js";
18
+ } from "./chunk-OKRZPQ3R.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 = record(value);
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 = text(value);
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 = text(value);
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 = record(value);
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
- const declared = Number(response.headers.get("content-length"));
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 = record(JSON.parse(trimmed));
153
- const direct = text(payload?.error);
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 = text(ctx.upstreamAuth);
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 text(element.attributes[name]);
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) => text(database.linkname) === linkName);
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 = text(value);
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 text(value) ?? null;
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: text(result.querytranslation) ?? null,
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: text(item.pmcid) ?? null,
700
- doi: text(item.doi) ?? null,
701
- mid: text(item.mid) ?? null,
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: text(item.errmsg) ?? null
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-VK3V2WTY.js";
10
+ } from "./chunk-B4P6YZFS.js";
6
11
  import {
7
12
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
13
+ } from "./chunk-SWBNHIO4.js";
10
14
  import {
11
15
  TBError,
12
16
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
17
+ } from "./chunk-OKRZPQ3R.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 = text(value);
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 = record(payload)?.errors;
34
+ const errors = asJsonObject(payload)?.errors;
42
35
  if (!Array.isArray(errors)) return void 0;
43
- const messages = errors.map((error) => text(record(error)?.message)).filter((message) => message !== void 0);
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 = record(payload);
48
- return errorMessages(payload) ?? text(body?.message) ?? text(body?.error) ?? text(body?.detail) ?? text(body?.title) ?? `Railway \u8FD4\u56DE HTTP ${status}`;
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 = record(payload);
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 = record(envelope.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 = record(value)?.edges;
72
+ const edges = asJsonObject(value)?.edges;
80
73
  if (!Array.isArray(edges)) return [];
81
74
  return edges.flatMap((edge) => {
82
- const node = record(record(edge)?.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 text(ctx.config?.workspaceId);
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(record(data.project), "Railway \u6CA1\u6709\u8FD4\u56DE project");
112
+ const project = requireValue(asJsonObject(data.project), "Railway \u6CA1\u6709\u8FD4\u56DE project");
120
113
  return {
121
- project: compact({
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(record(data.serviceInstance), "Railway \u6CA1\u6709\u8FD4\u56DE serviceInstance")
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(record(data.deployment), "Railway \u6CA1\u6709\u8FD4\u56DE deployment") };
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
- }`, compact({
188
+ }`, compactDefined({
196
189
  deploymentId: required(input.deploymentId, "deploymentId"),
197
190
  limit: input.limit ?? DEFAULT_LOG_LIMIT,
198
- filter: text(input.filter),
199
- startDate: text(input.startDate),
200
- endDate: text(input.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
- compact({
203
+ compactDefined({
211
204
  serviceId: required(input.serviceId, "serviceId"),
212
205
  environmentId: required(input.environmentId, "environmentId"),
213
- commitSha: text(input.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: compact({
217
+ input: compactDefined({
225
218
  projectId: required(input.projectId, "projectId"),
226
219
  environmentId: required(input.environmentId, "environmentId"),
227
- serviceId: text(input.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(record(data.deploymentRollback), "Railway \u6CA1\u6709\u8FD4\u56DE\u56DE\u6EDA\u540E\u7684 deployment") };
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-VLOIDU5U.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-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
14
+ } from "./chunk-B4P6YZFS.js";
15
+ import "./chunk-SWBNHIO4.js";
10
16
  import {
11
17
  TBError,
12
18
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
19
+ } from "./chunk-OKRZPQ3R.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
- function text(value) {
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 = record(payload);
30
+ const object = asJsonObject(payload);
33
31
  if (object !== void 0) {
34
- const direct = text(object.detail) ?? text(object.message) ?? text(object.error);
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 url = new URL(`${API_BASE}${input.path}`);
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 ? {} : { body: JSON.stringify(input.body) }
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
- const body = await response.text();
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 = record(value);
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 = record(value) ?? {};
73
+ const item = asJsonObject(value) ?? {};
90
74
  return {
91
- id: integer(item.id) ?? null,
92
- text: text(item.text) ?? "",
93
- title: text(item.title) ?? null,
94
- author: text(item.author) ?? null,
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: text(item.url) ?? null,
98
- highlightedAt: text(item.highlighted_at) ?? text(item.highlightedAt) ?? null,
99
- updatedAt: text(item.updated_at) ?? text(item.updatedAt) ?? null,
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 = record(value) ?? {};
88
+ const item = asJsonObject(value) ?? {};
105
89
  return {
106
90
  // export 接口回的是 user_book_id,books 接口回的是 id。
107
- id: integer(item.user_book_id) ?? integer(item.id) ?? null,
108
- title: text(item.title) ?? null,
109
- author: text(item.author) ?? null,
110
- category: text(item.category) ?? null,
111
- source: text(item.source) ?? null,
112
- numHighlights: integer(item.num_highlights) ?? integer(item.numHighlights) ?? null,
113
- updatedAt: text(item.updated) ?? text(item.updated_at) ?? null,
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 = record(value);
104
+ const object = asJsonObject(value);
121
105
  return object === void 0 ? [] : Object.keys(object);
122
106
  }
123
107
  function normalizeDocument(value) {
124
- const item = record(value) ?? {};
108
+ const item = asJsonObject(value) ?? {};
125
109
  return {
126
- id: text(item.id) ?? text(item.document_id) ?? null,
127
- url: text(item.url) ?? null,
128
- sourceUrl: text(item.source_url) ?? text(item.sourceUrl) ?? null,
129
- title: text(item.title) ?? null,
130
- author: text(item.author) ?? null,
131
- category: text(item.category) ?? null,
132
- location: text(item.location) ?? null,
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: text(item.created_at) ?? text(item.createdAt) ?? null,
135
- updatedAt: text(item.updated_at) ?? text(item.updatedAt) ?? null,
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 record(payload.document) ?? record(payload.result) ?? record(payload.saved_document) ?? payload;
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: integer(payload.count) ?? null,
161
- nextPageCursor: text(payload.nextPageCursor) ?? null,
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: integer(payload.count) ?? null,
182
- next: text(payload.next) ?? null,
183
- previous: text(payload.previous) ?? null,
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: integer(payload.count) ?? null,
204
- nextPageCursor: text(payload.nextPageCursor) ?? null,
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: compact({
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: compact({
217
+ body: compactDefined({
234
218
  location: input.location,
235
219
  title: input.title,
236
220
  author: input.author,