@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.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
  7. package/dist/chunk-JXHMDBAY.js +45 -0
  8. package/dist/chunk-LMLX3DJF.js +50 -0
  9. package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
  10. package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
  11. package/dist/chunk-U5UHT7CX.js +977 -0
  12. package/dist/chunk-U67V476Y.js +35 -0
  13. package/dist/chunk-WW2IMPQK.js +283 -0
  14. package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
  44. package/dist/index.d.ts +57 -50
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.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-BNXOJMB6.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
  112. package/package.json +5 -5
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. package/dist/chunk-MLKGABMK.js +0 -9
@@ -0,0 +1,35 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+
31
+ export {
32
+ __commonJS,
33
+ __export,
34
+ __toESM
35
+ };
@@ -0,0 +1,283 @@
1
+ import {
2
+ upstreamError
3
+ } from "./chunk-YASUMV2K.js";
4
+ import {
5
+ createGuardedFetch
6
+ } from "./chunk-U5UHT7CX.js";
7
+ import {
8
+ TBError
9
+ } from "./chunk-RVWZN3CI.js";
10
+
11
+ // ../plugins/src/_runtime/providerHttp.ts
12
+ function credentialLike(name) {
13
+ return /(?:^|-|_)(?:api[-_]?key|access[-_]?key|key|token|secret|auth(?:entication|orization)?|credentials?|pass(?:word)?|passwd|cookie|signature)(?:$|-|_)/i.test(name);
14
+ }
15
+ function addSecret(secrets, value) {
16
+ if (value === "") return;
17
+ secrets.add(value);
18
+ try {
19
+ const encoded = encodeURIComponent(value);
20
+ if (encoded !== value) secrets.add(encoded);
21
+ } catch {
22
+ }
23
+ const json = JSON.stringify(value);
24
+ const escaped = json.slice(1, -1);
25
+ if (escaped !== value) secrets.add(escaped);
26
+ }
27
+ function appendQuery(url, query, secrets) {
28
+ for (const [name, raw] of query ?? []) {
29
+ if (raw === void 0 || raw === null) continue;
30
+ const values = Array.isArray(raw) ? raw : [raw];
31
+ for (const value of values) {
32
+ const encoded = String(value);
33
+ url.searchParams.append(name, encoded);
34
+ if (credentialLike(name)) addSecret(secrets, encoded);
35
+ }
36
+ }
37
+ }
38
+ function collectUrlSecrets(url, secrets) {
39
+ for (const [name, value] of url.searchParams) {
40
+ if (credentialLike(name)) addSecret(secrets, value);
41
+ }
42
+ }
43
+ function collectHeaderSecrets(headers, sensitiveHeaders, secrets) {
44
+ for (const [name, value] of headers) {
45
+ if (!credentialLike(name) && !sensitiveHeaders.has(name.toLowerCase())) continue;
46
+ addSecret(secrets, value);
47
+ const authorization = /^([A-Za-z][A-Za-z0-9._~-]*)\s+(.+)$/.exec(value);
48
+ if (authorization === null) continue;
49
+ const scheme = authorization[1] ?? "";
50
+ const payload = authorization[2] ?? "";
51
+ addSecret(secrets, payload);
52
+ if (scheme.toLowerCase() !== "basic") continue;
53
+ try {
54
+ const binary = atob(payload);
55
+ addSecret(secrets, binary);
56
+ const separator = binary.indexOf(":");
57
+ if (separator >= 0) {
58
+ addSecret(secrets, binary.slice(0, separator));
59
+ addSecret(secrets, binary.slice(separator + 1));
60
+ }
61
+ const utf8 = new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
62
+ addSecret(secrets, utf8);
63
+ const utf8Separator = utf8.indexOf(":");
64
+ if (utf8Separator >= 0) {
65
+ addSecret(secrets, utf8.slice(0, utf8Separator));
66
+ addSecret(secrets, utf8.slice(utf8Separator + 1));
67
+ }
68
+ } catch {
69
+ }
70
+ }
71
+ }
72
+ function collectJsonSecrets(value, secrets) {
73
+ const seen = /* @__PURE__ */ new Set();
74
+ const pending = [
75
+ { sensitive: false, value }
76
+ ];
77
+ while (pending.length > 0) {
78
+ const current = pending.pop();
79
+ if (current.value === null || current.value === void 0) continue;
80
+ if (typeof current.value !== "object") {
81
+ if (current.sensitive) addSecret(secrets, String(current.value));
82
+ continue;
83
+ }
84
+ if (seen.has(current.value)) continue;
85
+ seen.add(current.value);
86
+ if (Array.isArray(current.value)) {
87
+ for (const item of current.value) pending.push({ sensitive: current.sensitive, value: item });
88
+ continue;
89
+ }
90
+ for (const [name, item] of Object.entries(current.value)) {
91
+ pending.push({ sensitive: current.sensitive || credentialLike(name), value: item });
92
+ }
93
+ }
94
+ }
95
+ function acceptedStatuses(values, service) {
96
+ const result = /* @__PURE__ */ new Set();
97
+ for (const value of values ?? []) {
98
+ if (!Number.isFinite(value) || !Number.isInteger(value) || value < 100 || value > 599) {
99
+ throw new TBError("invalid_argument", `${service} acceptStatuses must contain HTTP status integers from 100 to 599`);
100
+ }
101
+ result.add(value);
102
+ }
103
+ return result;
104
+ }
105
+ var MAX_TIMEOUT_MS = 2147483647;
106
+ function requestTimeout(timeoutMs, service) {
107
+ if (timeoutMs === void 0) {
108
+ return { cancel: () => {
109
+ }, race: (operation) => operation, signal: void 0 };
110
+ }
111
+ if (!Number.isFinite(timeoutMs) || !Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMEOUT_MS) {
112
+ throw new TBError(
113
+ "invalid_argument",
114
+ `${service} timeoutMs must be an integer from 1 to ${MAX_TIMEOUT_MS}`
115
+ );
116
+ }
117
+ let signal;
118
+ try {
119
+ signal = AbortSignal.timeout(timeoutMs);
120
+ } catch {
121
+ throw new TBError("invalid_argument", `${service} timeoutMs is outside the supported range`);
122
+ }
123
+ let onAbort;
124
+ const expired = new Promise((_resolve, reject) => {
125
+ onAbort = () => reject(signal.reason ?? new DOMException("The operation timed out", "TimeoutError"));
126
+ if (signal.aborted) onAbort();
127
+ else signal.addEventListener("abort", onAbort, { once: true });
128
+ });
129
+ return {
130
+ cancel: () => signal.removeEventListener("abort", onAbort),
131
+ race: (operation) => Promise.race([operation, expired]),
132
+ signal
133
+ };
134
+ }
135
+ function redact(message, secrets) {
136
+ let safe = message.replace(/https?:\/\/[^\s)\]}>'"]+/gi, "[redacted-url]");
137
+ for (const secret of secrets) {
138
+ if (secret !== "") safe = safe.replaceAll(secret, "[redacted]");
139
+ }
140
+ return safe.slice(0, 500);
141
+ }
142
+ function redactError(error, secrets) {
143
+ const message = redact(error.message, secrets);
144
+ if (message === error.message) return error;
145
+ return new TBError(error.code, message, {
146
+ httpStatus: error.httpStatus,
147
+ retryable: error.retryable
148
+ });
149
+ }
150
+ async function readResponse(response, responseType, invalidJson, service, invalidJsonMessage) {
151
+ if (responseType === "empty" || response.status === 204 || response.status === 205) {
152
+ return { bodyKind: "empty", data: void 0, rawText: void 0 };
153
+ }
154
+ let raw;
155
+ try {
156
+ raw = await response.text();
157
+ } catch {
158
+ if (!response.ok) return { bodyKind: "empty", data: void 0, rawText: void 0 };
159
+ throw upstreamError(502, `${service} returned an unreadable response`);
160
+ }
161
+ if (raw === "") return { bodyKind: "empty", data: void 0, rawText: void 0 };
162
+ if (responseType === "json" && raw.trim() === "") return { bodyKind: "empty", data: void 0, rawText: raw };
163
+ if (responseType === "text") return { bodyKind: "text", data: raw, rawText: raw };
164
+ if (responseType === "auto" && !response.headers.get("content-type")?.toLowerCase().includes("json")) {
165
+ return { bodyKind: "text", data: raw, rawText: raw };
166
+ }
167
+ try {
168
+ return { bodyKind: "json", data: JSON.parse(raw), rawText: raw };
169
+ } catch {
170
+ if (!response.ok || invalidJson === "text") return { bodyKind: "invalid-json", data: raw, rawText: raw };
171
+ throw upstreamError(502, invalidJsonMessage ?? `${service} returned an invalid JSON response`);
172
+ }
173
+ }
174
+ function createProviderHttpClient(options) {
175
+ let fixedBaseUrl;
176
+ if (options.baseUrl !== void 0) {
177
+ try {
178
+ fixedBaseUrl = new URL(options.baseUrl);
179
+ } catch {
180
+ throw new TBError("invalid_argument", `${options.service} baseUrl must be a valid absolute URL`);
181
+ }
182
+ }
183
+ const guardedFetch = createGuardedFetch({
184
+ crossOriginRedirect: options.crossOriginRedirect ?? "error",
185
+ fetch: options.transport,
186
+ maxRedirects: options.maxRedirects,
187
+ sensitiveHeaders: options.sensitiveHeaders
188
+ });
189
+ const sensitiveHeaders = new Set(
190
+ (options.sensitiveHeaders ?? []).map((name) => name.toLowerCase())
191
+ );
192
+ return {
193
+ async request(request) {
194
+ const hasJson = Object.hasOwn(request, "json");
195
+ const hasBody = Object.hasOwn(request, "body");
196
+ if (hasJson && hasBody) {
197
+ throw new TBError("invalid_argument", `${options.service} request cannot contain both json and body`);
198
+ }
199
+ const accepted = acceptedStatuses(request.acceptStatuses, options.service);
200
+ let baseUrl = fixedBaseUrl;
201
+ if (request.baseUrl !== void 0) {
202
+ try {
203
+ baseUrl = new URL(request.baseUrl);
204
+ } catch {
205
+ throw new TBError("invalid_argument", `${options.service} baseUrl must be a valid absolute URL`);
206
+ }
207
+ }
208
+ if (baseUrl === void 0) {
209
+ throw new TBError("invalid_argument", `${options.service} request requires a baseUrl`);
210
+ }
211
+ const url = new URL(request.path.replace(/^\/+/, ""), baseUrl);
212
+ if (url.origin !== baseUrl.origin) {
213
+ throw new TBError("invalid_argument", `${options.service} request path must stay on the configured origin`);
214
+ }
215
+ const secrets = new Set(request.sensitiveValues ?? []);
216
+ for (const secret of [...secrets]) addSecret(secrets, secret);
217
+ collectUrlSecrets(url, secrets);
218
+ appendQuery(url, request.query, secrets);
219
+ const headers = new Headers(request.headers);
220
+ collectHeaderSecrets(headers, sensitiveHeaders, secrets);
221
+ if (hasJson) collectJsonSecrets(request.json, secrets);
222
+ if (hasJson && !headers.has("content-type")) headers.set("content-type", "application/json");
223
+ const timeout = requestTimeout(request.timeoutMs, options.service);
224
+ const signal = timeout.signal;
225
+ const completed = await (async () => {
226
+ try {
227
+ return await timeout.race((async () => {
228
+ const response2 = await guardedFetch(url, {
229
+ method: request.method ?? "GET",
230
+ headers,
231
+ body: hasJson ? JSON.stringify(request.json) : request.body,
232
+ ...signal === void 0 ? {} : { signal }
233
+ });
234
+ const parsed2 = await readResponse(
235
+ response2,
236
+ request.responseType ?? "json",
237
+ request.invalidJson ?? "error",
238
+ options.service,
239
+ request.invalidJsonMessage
240
+ );
241
+ return { parsed: parsed2, response: response2 };
242
+ })());
243
+ } catch (error) {
244
+ if (error instanceof TBError && signal?.aborted !== true) throw error;
245
+ const kind = signal?.aborted === true ? "timeout" : "network";
246
+ const rawMessage = error instanceof Error ? error.message : void 0;
247
+ const context = {
248
+ kind,
249
+ message: rawMessage === void 0 ? void 0 : redact(rawMessage, secrets)
250
+ };
251
+ const mapped = request.mapTransportError?.(context) ?? upstreamError(kind === "timeout" ? 504 : 502, `${options.service} request failed`);
252
+ throw redactError(mapped, secrets);
253
+ } finally {
254
+ timeout.cancel();
255
+ }
256
+ })();
257
+ const { parsed, response } = completed;
258
+ if (!response.ok && !accepted.has(response.status)) {
259
+ const mapped = request.mapError?.({
260
+ bodyKind: parsed.bodyKind,
261
+ data: parsed.data,
262
+ headers: response.headers,
263
+ rawText: parsed.rawText,
264
+ status: response.status,
265
+ statusText: response.statusText
266
+ }) ?? upstreamError(response.status, `${options.service} request failed with ${response.status}`);
267
+ throw redactError(mapped, secrets);
268
+ }
269
+ return {
270
+ bodyKind: parsed.bodyKind,
271
+ data: parsed.data,
272
+ headers: response.headers,
273
+ rawText: parsed.rawText,
274
+ status: response.status,
275
+ statusText: response.statusText
276
+ };
277
+ }
278
+ };
279
+ }
280
+
281
+ export {
282
+ createProviderHttpClient
283
+ };
@@ -1,9 +1,7 @@
1
1
  import {
2
+ TBError,
2
3
  createPlugin
3
- } from "./chunk-GKX72JMJ.js";
4
- import {
5
- TBError
6
- } from "./chunk-YB2FLNWI.js";
4
+ } from "./chunk-RVWZN3CI.js";
7
5
 
8
6
  // ../plugins/src/_runtime/plugin.ts
9
7
  function requireApiKey(ctx, service) {
@@ -83,8 +81,8 @@ function upstreamError(status, message) {
83
81
  }
84
82
 
85
83
  export {
84
+ upstreamError,
86
85
  requireApiKey,
87
86
  requireCredential,
88
- createProviderPlugin,
89
- upstreamError
87
+ createProviderPlugin
90
88
  };
@@ -1,29 +1,26 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject,
6
+ trimmedText
7
+ } from "./chunk-JXHMDBAY.js";
1
8
  import {
2
9
  createProviderPlugin,
3
10
  requireApiKey,
4
11
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
12
+ } from "./chunk-YASUMV2K.js";
13
+ import "./chunk-U5UHT7CX.js";
10
14
  import {
11
15
  TBError,
12
16
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
17
+ } from "./chunk-RVWZN3CI.js";
18
+ import "./chunk-U67V476Y.js";
15
19
 
16
20
  // ../plugins/src/circleci/api.ts
17
21
  var SERVICE = "circleci";
18
22
  var API_BASE = "https://circleci.com/api/v2";
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
- }
23
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
27
24
  function trimSlashes(value) {
28
25
  let start = 0;
29
26
  let end = value.length;
@@ -59,42 +56,26 @@ function errorMessage(payload, status) {
59
56
  const trimmed = payload.trim();
60
57
  if (trimmed !== "") return trimmed;
61
58
  }
62
- const body = record(payload);
63
- return text(body?.message) ?? text(body?.error) ?? `CircleCI \u8FD4\u56DE HTTP ${status}`;
64
- }
65
- function buildUrl(path, query) {
66
- const url = new URL(`${API_BASE}${path}`);
67
- for (const [key, value] of Object.entries(query ?? {})) {
68
- if (value === void 0 || value === "") continue;
69
- url.searchParams.set(key, value);
70
- }
71
- return url.toString();
59
+ const body = asJsonObject(payload);
60
+ return trimmedText(body?.message) ?? trimmedText(body?.error) ?? `CircleCI \u8FD4\u56DE HTTP ${status}`;
72
61
  }
73
62
  async function request(ctx, input) {
74
- const headers = {
75
- "circle-token": requireApiKey(ctx, SERVICE),
76
- "accept": "application/json"
77
- };
78
- if (input.body !== void 0) headers["content-type"] = "application/json";
79
- const response = await guardedFetch(buildUrl(input.path, input.query), {
63
+ const { data } = await http.request({
64
+ path: input.path,
80
65
  method: input.method ?? "GET",
81
- headers,
82
- body: input.body === void 0 ? void 0 : JSON.stringify(input.body)
66
+ query: Object.entries(input.query ?? {}).filter((entry) => {
67
+ const value = entry[1];
68
+ return value !== void 0 && value !== "";
69
+ }),
70
+ headers: {
71
+ "accept": "application/json",
72
+ "circle-token": requireApiKey(ctx, SERVICE)
73
+ },
74
+ ...input.body === void 0 ? {} : { json: input.body },
75
+ invalidJsonMessage: "CircleCI \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
76
+ mapError: ({ data: payload, status }) => upstreamError(status, errorMessage(payload, status))
83
77
  });
84
- const body = await response.text();
85
- let payload = {};
86
- if (body.trim() !== "") {
87
- try {
88
- payload = JSON.parse(body);
89
- } catch {
90
- if (response.ok) {
91
- throw new TBError("unavailable", "CircleCI \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
92
- }
93
- payload = body;
94
- }
95
- }
96
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
97
- return payload;
78
+ return data ?? {};
98
79
  }
99
80
  function getCurrentUser(_input, ctx) {
100
81
  return request(ctx, { path: "/me" });
@@ -106,7 +87,7 @@ function listPipelinesForProject(input, ctx) {
106
87
  return request(ctx, {
107
88
  path: `/project/${encodeURIComponent(projectSlug(input.projectSlug))}/pipeline`,
108
89
  // 入参是 camelCase 的 pageToken,上游 query 键却是连字符的 `page-token`。
109
- query: { "branch": text(input.branch), "page-token": text(input.pageToken) }
90
+ query: { "branch": trimmedText(input.branch), "page-token": trimmedText(input.pageToken) }
110
91
  });
111
92
  }
112
93
  function getPipeline(input, ctx) {
@@ -115,11 +96,11 @@ function getPipeline(input, ctx) {
115
96
  function listWorkflowsByPipeline(input, ctx) {
116
97
  return request(ctx, {
117
98
  path: `/pipeline/${encodeURIComponent(input.pipelineId.trim())}/workflow`,
118
- query: { "page-token": text(input.pageToken) }
99
+ query: { "page-token": trimmedText(input.pageToken) }
119
100
  });
120
101
  }
121
102
  function getWorkflowSummary(input, ctx) {
122
- if (typeof input.allBranches === "boolean" && text(input.branch) !== void 0) {
103
+ if (typeof input.allBranches === "boolean" && trimmedText(input.branch) !== void 0) {
123
104
  throw new TBError("invalid_argument", "allBranches \u4E0E branch \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528");
124
105
  }
125
106
  const slug = encodeURIComponent(projectSlug(input.projectSlug));
@@ -128,7 +109,7 @@ function getWorkflowSummary(input, ctx) {
128
109
  path: `/insights/${slug}/workflows/${workflow}/summary`,
129
110
  query: {
130
111
  "all-branches": typeof input.allBranches === "boolean" ? String(input.allBranches) : void 0,
131
- "branch": text(input.branch)
112
+ "branch": trimmedText(input.branch)
132
113
  }
133
114
  });
134
115
  }
@@ -146,19 +127,19 @@ function getJobArtifacts(input, ctx) {
146
127
  function listInsightsSummary(input, ctx) {
147
128
  return request(ctx, {
148
129
  path: `/insights/${encodeURIComponent(orgSlug(input.orgSlug))}/summary`,
149
- query: { "reporting-window": text(input.reportingWindow) }
130
+ query: { "reporting-window": trimmedText(input.reportingWindow) }
150
131
  });
151
132
  }
152
133
  function triggerPipeline(input, ctx) {
153
- const branch = text(input.branch);
154
- const tag = text(input.tag);
134
+ const branch = trimmedText(input.branch);
135
+ const tag = trimmedText(input.tag);
155
136
  if (branch !== void 0 && tag !== void 0) {
156
137
  throw new TBError("invalid_argument", "branch \u4E0E tag \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528");
157
138
  }
158
139
  const body = {};
159
140
  if (branch !== void 0) body.branch = branch;
160
141
  if (tag !== void 0) body.tag = tag;
161
- const parameters = record(input.parameters);
142
+ const parameters = asJsonObject(input.parameters);
162
143
  if (parameters !== void 0) body.parameters = parameters;
163
144
  return request(ctx, {
164
145
  method: "POST",