@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,39 +1,36 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined,
7
+ trimmedText
8
+ } from "./chunk-JXHMDBAY.js";
1
9
  import {
2
10
  createProviderPlugin,
3
11
  requireApiKey,
4
12
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
13
+ } from "./chunk-B4P6YZFS.js";
6
14
  import {
7
15
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
16
+ } from "./chunk-SWBNHIO4.js";
10
17
  import {
11
18
  TBError,
12
19
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
20
+ } from "./chunk-OKRZPQ3R.js";
21
+ import "./chunk-U67V476Y.js";
15
22
 
16
23
  // ../plugins/src/fal_ai/api.ts
17
24
  var SERVICE = "fal_ai";
18
25
  var PLATFORM_BASE = "https://api.fal.ai";
19
26
  var QUEUE_BASE = "https://queue.fal.run";
20
- function text(value) {
21
- if (typeof value !== "string") return void 0;
22
- const trimmed = value.trim();
23
- return trimmed === "" ? void 0 : trimmed;
24
- }
27
+ var http = createProviderHttpClient({ service: SERVICE });
25
28
  function str(value) {
26
29
  return typeof value === "string" ? value : void 0;
27
30
  }
28
- function record(value) {
29
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
30
- }
31
- function compact(input) {
32
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
33
- }
34
31
  function objectArray(value) {
35
32
  if (!Array.isArray(value)) return [];
36
- return value.map((item) => record(item)).filter((item) => item !== void 0);
33
+ return value.map((item) => asJsonObject(item)).filter((item) => item !== void 0);
37
34
  }
38
35
  function stringOrArray(value) {
39
36
  if (value === void 0 || typeof value === "string") return value;
@@ -57,40 +54,36 @@ function buildUrl(base, path, query) {
57
54
  return url.toString();
58
55
  }
59
56
  function errorMessage(payload, status) {
60
- const body = record(payload);
57
+ const body = asJsonObject(payload);
61
58
  if (body !== void 0) {
62
- const detail = typeof body.detail === "string" ? body.detail : record(body.detail) !== void 0 || Array.isArray(body.detail) ? JSON.stringify(body.detail) : void 0;
63
- const message = text(body.message) ?? text(body.error) ?? detail;
59
+ const detail = typeof body.detail === "string" ? body.detail : asJsonObject(body.detail) !== void 0 || Array.isArray(body.detail) ? JSON.stringify(body.detail) : void 0;
60
+ const message = trimmedText(body.message) ?? trimmedText(body.error) ?? detail;
64
61
  if (message !== void 0 && message !== "") return message;
65
62
  }
66
63
  return `fal.ai \u8FD4\u56DE HTTP ${status}`;
67
64
  }
68
65
  async function request(ctx, input) {
69
- const response = await guardedFetch(buildUrl(input.base, input.path, input.query), {
66
+ const result = await http.request({
67
+ baseUrl: input.base,
68
+ path: input.path,
70
69
  method: input.method ?? (input.body === void 0 ? "GET" : "POST"),
70
+ query: Object.entries(input.query ?? {}),
71
71
  headers: {
72
72
  "authorization": `Key ${requireApiKey(ctx, SERVICE)}`,
73
73
  "content-type": "application/json",
74
74
  ...input.headers
75
75
  },
76
- body: input.body === void 0 ? void 0 : JSON.stringify(input.body)
76
+ ...input.body === void 0 ? {} : { json: input.body },
77
+ invalidJsonMessage: "fal.ai \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
78
+ mapError: ({ bodyKind, data, status }) => upstreamError(
79
+ status,
80
+ errorMessage(bodyKind === "json" ? data : null, status)
81
+ )
77
82
  });
78
- const body = await response.text();
79
- let payload = null;
80
- if (body !== "") {
81
- try {
82
- payload = JSON.parse(body);
83
- } catch {
84
- if (response.ok) {
85
- throw new TBError("unavailable", "fal.ai \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
86
- }
87
- }
88
- }
89
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
90
- return payload;
83
+ return result.data === void 0 ? null : result.data;
91
84
  }
92
85
  function requireRecord(value) {
93
- const result = record(value);
86
+ const result = asJsonObject(value);
94
87
  if (result === void 0) throw new TBError("unavailable", "fal.ai \u54CD\u5E94\u4E0D\u662F\u5BF9\u8C61", { retryable: true });
95
88
  return result;
96
89
  }
@@ -114,13 +107,13 @@ async function getModels(input, ctx) {
114
107
  const payload = await request(ctx, {
115
108
  base: PLATFORM_BASE,
116
109
  path: "/v1/models",
117
- query: compact({
118
- q: text(input.q),
110
+ query: compactDefined({
111
+ q: trimmedText(input.q),
119
112
  limit: input.limit,
120
- cursor: text(input.cursor),
113
+ cursor: trimmedText(input.cursor),
121
114
  expand: stringOrArray(input.expand),
122
- status: text(input.status),
123
- category: text(input.category),
115
+ status: trimmedText(input.status),
116
+ category: trimmedText(input.category),
124
117
  endpoint_id: stringOrArray(input.endpointId)
125
118
  })
126
119
  });
@@ -162,7 +155,7 @@ async function queueGetStatus(input, ctx) {
162
155
  base: QUEUE_BASE,
163
156
  path: queueRequestPath(input.modelId, input.requestId, "status"),
164
157
  // logs: 0 是显式值,要发;只有"没给"才不发。
165
- query: compact({ logs: input.logs })
158
+ query: compactDefined({ logs: input.logs })
166
159
  }));
167
160
  return {
168
161
  status: str(payload.status) ?? "",
@@ -193,7 +186,7 @@ async function queueGetStatusStream(input, ctx) {
193
186
  buildUrl(
194
187
  QUEUE_BASE,
195
188
  queueRequestPath(input.modelId, input.requestId, "status/stream"),
196
- compact({ logs: input.logs })
189
+ compactDefined({ logs: input.logs })
197
190
  ),
198
191
  {
199
192
  method: "GET",
@@ -236,7 +229,7 @@ async function getQueueRequestResult(input, ctx) {
236
229
  return {
237
230
  status: str(payload.status) ?? "",
238
231
  logs: queueLogs(payload.logs),
239
- response: record(payload.response) ?? {}
232
+ response: asJsonObject(payload.response) ?? {}
240
233
  };
241
234
  }
242
235
  async function cancelQueueRequest(input, ctx) {
@@ -1,15 +1,13 @@
1
1
  import {
2
2
  createGuardedFetch
3
- } from "./chunk-2O27H4Y2.js";
4
- import {
5
- createPlugin
6
- } from "./chunk-GKX72JMJ.js";
3
+ } from "./chunk-SWBNHIO4.js";
7
4
  import {
8
5
  TBError,
6
+ createPlugin,
9
7
  isTBError,
10
8
  normalizeUpstreamError
11
- } from "./chunk-YB2FLNWI.js";
12
- import "./chunk-MLKGABMK.js";
9
+ } from "./chunk-OKRZPQ3R.js";
10
+ import "./chunk-U67V476Y.js";
13
11
 
14
12
  // ../plugins/src/feishu/feishuMcp.ts
15
13
  import {
@@ -2,16 +2,15 @@ import {
2
2
  createProviderPlugin,
3
3
  requireCredential,
4
4
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
5
+ } from "./chunk-B4P6YZFS.js";
6
6
  import {
7
7
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
8
+ } from "./chunk-SWBNHIO4.js";
10
9
  import {
11
10
  TBError,
12
11
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
12
+ } from "./chunk-OKRZPQ3R.js";
13
+ import "./chunk-U67V476Y.js";
15
14
 
16
15
  // ../plugins/src/feishu_custom_bot/api.ts
17
16
  var SERVICE = "feishu_custom_bot";
@@ -1,34 +1,29 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined,
7
+ trimmedText
8
+ } from "./chunk-JXHMDBAY.js";
1
9
  import {
2
10
  createProviderPlugin,
3
11
  requireApiKey,
4
12
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
13
+ } from "./chunk-B4P6YZFS.js";
14
+ import "./chunk-SWBNHIO4.js";
10
15
  import {
11
16
  TBError,
12
17
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
18
+ } from "./chunk-OKRZPQ3R.js";
19
+ import "./chunk-U67V476Y.js";
15
20
 
16
21
  // ../plugins/src/figma/api.ts
17
22
  var SERVICE = "figma";
18
23
  var API_BASE = "https://api.figma.com";
19
- function text(value) {
20
- if (typeof value !== "string") return void 0;
21
- const trimmed = value.trim();
22
- return trimmed === "" ? void 0 : trimmed;
23
- }
24
- function record(value) {
25
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
26
- }
27
- function compact(input) {
28
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
29
- }
24
+ var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
30
25
  function requireInput(value, field) {
31
- const result = text(value);
26
+ const result = trimmedText(value);
32
27
  if (result === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u662F\u7A7A\u767D`);
33
28
  return result;
34
29
  }
@@ -43,7 +38,7 @@ function requireIds(value, field) {
43
38
  return joined;
44
39
  }
45
40
  function requireRecord(value, label) {
46
- const result = record(value);
41
+ const result = asJsonObject(value);
47
42
  if (result === void 0) throw new TBError("unavailable", `${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
48
43
  return result;
49
44
  }
@@ -52,55 +47,35 @@ function requireArray(value, label) {
52
47
  return value;
53
48
  }
54
49
  function errorMessage(payload, status) {
55
- if (typeof payload === "string") return text(payload) ?? `Figma \u8FD4\u56DE HTTP ${status}`;
56
- const body = record(payload);
57
- const error = record(body?.error);
58
- return text(body?.message) ?? text(body?.err) ?? text(body?.error) ?? text(body?.status) ?? text(error?.message) ?? text(error?.detail) ?? `Figma \u8FD4\u56DE HTTP ${status}`;
59
- }
60
- function buildUrl(path, query) {
61
- const url = new URL(path, API_BASE);
62
- for (const [key, value] of Object.entries(query ?? {})) {
63
- if (value === void 0) continue;
64
- url.searchParams.set(key, String(value));
65
- }
66
- return url.toString();
50
+ if (typeof payload === "string") return trimmedText(payload) ?? `Figma \u8FD4\u56DE HTTP ${status}`;
51
+ const body = asJsonObject(payload);
52
+ const error = asJsonObject(body?.error);
53
+ return trimmedText(body?.message) ?? trimmedText(body?.err) ?? trimmedText(body?.error) ?? trimmedText(body?.status) ?? trimmedText(error?.message) ?? trimmedText(error?.detail) ?? `Figma \u8FD4\u56DE HTTP ${status}`;
67
54
  }
68
55
  async function request(ctx, input) {
69
56
  const hasBody = input.body !== void 0;
70
- const headers = {
71
- "accept": "application/json",
72
- "x-figma-token": requireApiKey(ctx, SERVICE)
73
- };
74
- if (hasBody) headers["content-type"] = "application/json";
75
- let response;
76
- try {
77
- response = await guardedFetch(buildUrl(input.path, input.query), {
78
- method: input.method ?? "GET",
79
- headers,
80
- body: hasBody ? JSON.stringify(input.body) : void 0
81
- });
82
- } catch (error) {
83
- if (error instanceof TBError) throw error;
84
- throw new TBError("unavailable", "Figma \u8BF7\u6C42\u5931\u8D25", { retryable: true });
85
- }
86
- const body = await response.text().catch(() => "");
87
- let payload = null;
88
- if (body.trim() !== "") {
89
- try {
90
- payload = JSON.parse(body);
91
- } catch {
92
- payload = body;
93
- }
94
- }
95
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
96
- return payload;
57
+ const { data } = await http.request({
58
+ path: input.path,
59
+ method: input.method ?? "GET",
60
+ query: Object.entries(input.query ?? {}),
61
+ headers: {
62
+ "accept": "application/json",
63
+ "x-figma-token": requireApiKey(ctx, SERVICE)
64
+ },
65
+ ...hasBody ? { json: input.body } : {},
66
+ // Figma 的错误消息有时是纯文本;成功响应也保留旧实现的原文 payload 语义。
67
+ invalidJson: "text",
68
+ mapError: ({ data: payload, status }) => upstreamError(status, errorMessage(payload, status)),
69
+ mapTransportError: () => new TBError("unavailable", "Figma \u8BF7\u6C42\u5931\u8D25", { retryable: true })
70
+ });
71
+ return data ?? null;
97
72
  }
98
73
  function fileQuery(input) {
99
- return compact({
100
- version: text(input.version),
74
+ return compactDefined({
75
+ version: trimmedText(input.version),
101
76
  ids: joinIds(input.nodeIds),
102
77
  depth: input.depth,
103
- geometry: text(input.geometry),
78
+ geometry: trimmedText(input.geometry),
104
79
  plugin_data: joinIds(input.pluginData),
105
80
  branch_data: input.branchData
106
81
  });
@@ -111,7 +86,7 @@ async function libraryItems(ctx, path, itemField) {
111
86
  return {
112
87
  items: requireArray(meta[itemField], `Figma ${itemField} \u5217\u8868`),
113
88
  // 上游把游标放在 meta.cursor;没有就给空对象,免得消费者要区分"没有"与"没分页"。
114
- pagination: record(meta.cursor) ?? {},
89
+ pagination: asJsonObject(meta.cursor) ?? {},
115
90
  raw
116
91
  };
117
92
  }
@@ -167,11 +142,11 @@ async function renderImages(input, ctx) {
167
142
  const raw = requireRecord(
168
143
  await request(ctx, {
169
144
  path: `/v1/images/${encodeURIComponent(requireInput(input.fileKey, "fileKey"))}`,
170
- query: compact({
145
+ query: compactDefined({
171
146
  ids: requireIds(input.nodeIds, "nodeIds"),
172
- version: text(input.version),
147
+ version: trimmedText(input.version),
173
148
  scale: input.scale,
174
- format: text(input.format),
149
+ format: trimmedText(input.format),
175
150
  svg_include_id: input.svgIncludeId,
176
151
  svg_simplify_stroke: input.svgSimplifyStroke,
177
152
  use_absolute_bounds: input.useAbsoluteBounds
@@ -182,7 +157,7 @@ async function renderImages(input, ctx) {
182
157
  return {
183
158
  images: requireRecord(raw.images, "Figma \u6E32\u67D3\u7ED3\u679C\u8868"),
184
159
  // err 总是给出来:渲染是"部分成功"的接口,消费者要能一眼看到有没有出错。
185
- err: raw.err === null ? null : text(raw.err) ?? null,
160
+ err: raw.err === null ? null : trimmedText(raw.err) ?? null,
186
161
  raw
187
162
  };
188
163
  }
@@ -198,17 +173,17 @@ async function listFileVersions(input, ctx) {
198
173
  const raw = requireRecord(
199
174
  await request(ctx, {
200
175
  path: filePath(input.fileKey, "/versions"),
201
- query: compact({
176
+ query: compactDefined({
202
177
  page_size: input.pageSize,
203
- before: text(input.before),
204
- after: text(input.after)
178
+ before: trimmedText(input.before),
179
+ after: trimmedText(input.after)
205
180
  })
206
181
  }),
207
182
  "Figma \u7248\u672C\u5217\u8868\u54CD\u5E94"
208
183
  );
209
184
  return {
210
185
  versions: requireArray(raw.versions, "Figma \u7248\u672C\u5217\u8868"),
211
- pagination: record(raw.pagination) ?? {},
186
+ pagination: asJsonObject(raw.pagination) ?? {},
212
187
  raw
213
188
  };
214
189
  }
@@ -223,10 +198,10 @@ async function postComment(input, ctx) {
223
198
  const payload = await request(ctx, {
224
199
  method: "POST",
225
200
  path: filePath(input.fileKey, "/comments"),
226
- body: compact({
201
+ body: compactDefined({
227
202
  message: requireInput(input.message, "message"),
228
- client_meta: record(input.clientMeta),
229
- comment_id: text(input.commentId)
203
+ client_meta: asJsonObject(input.clientMeta),
204
+ comment_id: trimmedText(input.commentId)
230
205
  })
231
206
  });
232
207
  return { comment: requireRecord(payload, "Figma \u8BC4\u8BBA\u54CD\u5E94") };
@@ -239,13 +214,13 @@ async function listCommentReactions(input, ctx) {
239
214
  const raw = requireRecord(
240
215
  await request(ctx, {
241
216
  path: commentPath(input.fileKey, input.commentId, "/reactions"),
242
- query: compact({ cursor: text(input.cursor) })
217
+ query: compactDefined({ cursor: trimmedText(input.cursor) })
243
218
  }),
244
219
  "Figma \u8BC4\u8BBA\u8868\u60C5\u54CD\u5E94"
245
220
  );
246
221
  return {
247
222
  reactions: requireArray(raw.reactions, "Figma \u8BC4\u8BBA\u8868\u60C5\u5217\u8868"),
248
- pagination: record(raw.pagination) ?? {},
223
+ pagination: asJsonObject(raw.pagination) ?? {},
249
224
  raw
250
225
  };
251
226
  }
@@ -286,7 +261,7 @@ async function listProjectFiles(input, ctx) {
286
261
  const raw = requireRecord(
287
262
  await request(ctx, {
288
263
  path: `/v1/projects/${encodeURIComponent(requireInput(input.projectId, "projectId"))}/files`,
289
- query: compact({ branch_data: input.branchData })
264
+ query: compactDefined({ branch_data: input.branchData })
290
265
  }),
291
266
  "Figma \u9879\u76EE\u6587\u4EF6\u54CD\u5E94"
292
267
  );
@@ -317,7 +292,7 @@ async function getDevResources(input, ctx) {
317
292
  const raw = requireRecord(
318
293
  await request(ctx, {
319
294
  path: filePath(input.fileKey, "/dev_resources"),
320
- query: compact({ node_ids: joinIds(input.nodeIds) })
295
+ query: compactDefined({ node_ids: joinIds(input.nodeIds) })
321
296
  }),
322
297
  "Figma dev resource \u54CD\u5E94"
323
298
  );
@@ -347,10 +322,10 @@ async function updateDevResources(input, ctx) {
347
322
  method: "PUT",
348
323
  path: "/v1/dev_resources",
349
324
  body: {
350
- dev_resources: input.devResources.map((resource) => compact({
325
+ dev_resources: input.devResources.map((resource) => compactDefined({
351
326
  id: requireInput(resource.id, "id"),
352
- name: text(resource.name),
353
- url: text(resource.url)
327
+ name: trimmedText(resource.name),
328
+ url: trimmedText(resource.url)
354
329
  }))
355
330
  }
356
331
  });
@@ -1,38 +1,38 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined,
7
+ trimmedText
8
+ } from "./chunk-JXHMDBAY.js";
1
9
  import {
2
10
  createProviderPlugin,
3
11
  requireApiKey,
4
12
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
13
+ } from "./chunk-B4P6YZFS.js";
14
+ import "./chunk-SWBNHIO4.js";
10
15
  import {
11
16
  TBError,
12
17
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
18
+ } from "./chunk-OKRZPQ3R.js";
19
+ import "./chunk-U67V476Y.js";
15
20
 
16
21
  // ../plugins/src/firehydrant/api.ts
17
22
  var SERVICE = "firehydrant";
18
23
  var API_BASE = "https://api.firehydrant.io/v1";
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
- }
24
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
25
25
  function responseObject(value, what) {
26
- const object = record(value);
26
+ const object = asJsonObject(value);
27
27
  if (object === void 0) {
28
28
  throw new TBError("unavailable", `${what} \u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
29
29
  }
30
30
  return object;
31
31
  }
32
32
  function errorMessage(payload, status) {
33
- const object = record(payload);
33
+ const object = asJsonObject(payload);
34
34
  if (object !== void 0) {
35
- const direct = text(object.error) ?? text(object.message);
35
+ const direct = trimmedText(object.error) ?? trimmedText(object.message);
36
36
  if (direct !== void 0) return direct;
37
37
  const errors = object.errors;
38
38
  if (Array.isArray(errors) && errors.length > 0) return errors.map(String).join(", ");
@@ -40,33 +40,23 @@ function errorMessage(payload, status) {
40
40
  return `FireHydrant request failed with status ${status}`;
41
41
  }
42
42
  async function request(ctx, input) {
43
- const url = new URL(`${API_BASE}${input.path}`);
44
- for (const [key, value] of Object.entries(input.query ?? {})) {
45
- if (value !== void 0) url.searchParams.set(key, value);
46
- }
47
- const response = await guardedFetch(url.toString(), {
43
+ const { data } = await http.request({
44
+ path: input.path,
48
45
  method: input.method ?? "GET",
46
+ query: Object.entries(input.query ?? {}),
49
47
  headers: {
50
48
  "accept": "application/json",
51
49
  "authorization": `Bearer ${requireApiKey(ctx, SERVICE)}`,
52
50
  "content-type": "application/json"
53
51
  },
54
- ...input.body === void 0 ? {} : { body: JSON.stringify(input.body) }
52
+ ...input.body === void 0 ? {} : { json: input.body },
53
+ invalidJsonMessage: "FireHydrant \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON",
54
+ mapError: ({ bodyKind, data: payload, status }) => bodyKind === "invalid-json" ? new TBError("unavailable", "FireHydrant \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON", { retryable: true }) : upstreamError(status, errorMessage(payload, status))
55
55
  });
56
- const body = await response.text();
57
- let payload = {};
58
- if (body !== "") {
59
- try {
60
- payload = JSON.parse(body);
61
- } catch {
62
- throw new TBError("unavailable", "FireHydrant \u8FD4\u56DE\u4E86\u975E\u6CD5 JSON", { retryable: true });
63
- }
64
- }
65
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
66
- return payload;
56
+ return data ?? {};
67
57
  }
68
58
  function nullableText(value) {
69
- return text(value) ?? null;
59
+ return trimmedText(value) ?? null;
70
60
  }
71
61
  function nullableInteger(value) {
72
62
  return typeof value === "number" && Number.isInteger(value) ? value : null;
@@ -86,7 +76,7 @@ function normalizeEntityRef(input) {
86
76
  };
87
77
  }
88
78
  function nullableEntityRef(value) {
89
- const object = record(value);
79
+ const object = asJsonObject(value);
90
80
  return object === void 0 ? null : normalizeEntityRef(object);
91
81
  }
92
82
  function normalizeIncident(input) {
@@ -109,7 +99,7 @@ function normalizeIncident(input) {
109
99
  services: readArray(input.services).map((item) => normalizeEntityRef(responseObject(item, "FireHydrant incident service"))),
110
100
  environments: readArray(input.environments).map((item) => normalizeEntityRef(responseObject(item, "FireHydrant incident environment"))),
111
101
  tags: readArray(input.tag_list).map(String),
112
- labels: record(input.labels) ?? null,
102
+ labels: asJsonObject(input.labels) ?? null,
113
103
  raw: input
114
104
  };
115
105
  }
@@ -123,13 +113,13 @@ function normalizeCatalogEntry(input) {
123
113
  createdAt: nullableText(input.created_at),
124
114
  updatedAt: nullableText(input.updated_at),
125
115
  activeIncidents: readArray(input.active_incidents).map(String),
126
- labels: record(input.labels) ?? null,
116
+ labels: asJsonObject(input.labels) ?? null,
127
117
  owner: nullableEntityRef(input.owner),
128
118
  raw: input
129
119
  };
130
120
  }
131
121
  function normalizePagination(value) {
132
- const object = record(value);
122
+ const object = asJsonObject(value);
133
123
  if (object === void 0) return null;
134
124
  return {
135
125
  count: nullableInteger(object.count),
@@ -147,23 +137,20 @@ function listQuery(input) {
147
137
  return {
148
138
  page: input.page === void 0 ? void 0 : String(input.page),
149
139
  per_page: input.perPage === void 0 ? void 0 : String(input.perPage),
150
- query: text(input.query),
151
- name: text(input.name),
152
- status: text(incident.status),
153
- services: text(incident.services),
154
- environments: text(incident.environments),
155
- tags: text(incident.tags),
156
- tag_match_strategy: text(incident.tagMatchStrategy),
140
+ query: trimmedText(input.query),
141
+ name: trimmedText(input.name),
142
+ status: trimmedText(incident.status),
143
+ services: trimmedText(incident.services),
144
+ environments: trimmedText(incident.environments),
145
+ tags: trimmedText(incident.tags),
146
+ tag_match_strategy: trimmedText(incident.tagMatchStrategy),
157
147
  archived: incident.archived === void 0 ? void 0 : String(incident.archived),
158
- created_at_or_after: text(incident.createdAtOrAfter),
159
- created_at_or_before: text(incident.createdAtOrBefore),
160
- updated_after: text(incident.updatedAfter),
161
- updated_before: text(incident.updatedBefore)
148
+ created_at_or_after: trimmedText(incident.createdAtOrAfter),
149
+ created_at_or_before: trimmedText(incident.createdAtOrBefore),
150
+ updated_after: trimmedText(incident.updatedAfter),
151
+ updated_before: trimmedText(incident.updatedBefore)
162
152
  };
163
153
  }
164
- function compact(input) {
165
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
166
- }
167
154
  async function listCollection(ctx, outputKey, path, input, normalizeItem) {
168
155
  const raw = responseObject(
169
156
  await request(ctx, { path, query: listQuery(input) }),
@@ -189,7 +176,7 @@ function getIncident(input, ctx) {
189
176
  return getSingle(ctx, "incident", { path }, normalizeIncident);
190
177
  }
191
178
  function createIncident(input, ctx) {
192
- const body = compact({
179
+ const body = compactDefined({
193
180
  name: input.name,
194
181
  summary: input.summary,
195
182
  customer_impact_summary: input.customerImpactSummary,