@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
@@ -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-B4P6YZFS.js";
4
+ import {
5
+ createGuardedFetch
6
+ } from "./chunk-SWBNHIO4.js";
7
+ import {
8
+ TBError
9
+ } from "./chunk-OKRZPQ3R.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,29 +1,26 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.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-B4P6YZFS.js";
13
+ import "./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/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",
@@ -1,85 +1,64 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.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-B4P6YZFS.js";
13
+ import "./chunk-SWBNHIO4.js";
10
14
  import {
11
15
  external_exports
12
- } from "./chunk-YB2FLNWI.js";
13
- import "./chunk-MLKGABMK.js";
16
+ } from "./chunk-OKRZPQ3R.js";
17
+ import "./chunk-U67V476Y.js";
14
18
 
15
19
  // ../plugins/src/clerk/api.ts
16
20
  var SERVICE = "clerk";
17
- var API_BASE = "https://api.clerk.com/v1";
18
- function text(value) {
19
- if (typeof value !== "string") return void 0;
20
- const trimmed = value.trim();
21
- return trimmed === "" ? void 0 : trimmed;
22
- }
23
- function record(value) {
24
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
25
- }
21
+ var http = createProviderHttpClient({ baseUrl: "https://api.clerk.com/v1/", service: SERVICE });
26
22
  function errorMessage(payload) {
27
- if (typeof payload === "string") return text(payload)?.slice(0, 200);
28
- const body = record(payload);
23
+ if (typeof payload === "string") return trimmedText(payload)?.slice(0, 200);
24
+ const body = asJsonObject(payload);
29
25
  if (body === void 0) return void 0;
30
26
  if (Array.isArray(body.errors)) {
31
- const first = record(body.errors[0]);
32
- return text(first?.long_message) ?? text(first?.message) ?? text(first?.code);
33
- }
34
- return text(body.message) ?? text(body.error);
35
- }
36
- async function readPayload(response) {
37
- const body = await response.text().catch(() => "");
38
- if (body.trim() === "") return {};
39
- try {
40
- return JSON.parse(body);
41
- } catch {
42
- return body;
27
+ const first = asJsonObject(body.errors[0]);
28
+ return trimmedText(first?.long_message) ?? trimmedText(first?.message) ?? trimmedText(first?.code);
43
29
  }
30
+ return trimmedText(body.message) ?? trimmedText(body.error);
44
31
  }
45
32
  async function request(ctx, path, input) {
46
- const apiKey = requireApiKey(ctx, SERVICE);
47
- const url = new URL(`${API_BASE}${path}`);
48
- for (const [key, value] of input.query ?? []) {
49
- if (value === void 0 || value === null || value === "") continue;
50
- if (Array.isArray(value)) {
51
- for (const item of value) url.searchParams.append(key, String(item));
52
- continue;
53
- }
54
- url.searchParams.set(key, String(value));
55
- }
56
- const headers = {
57
- accept: "application/json",
58
- authorization: `Bearer ${apiKey}`
59
- };
60
- if (input.body !== void 0) headers["content-type"] = "application/json";
61
- let response;
62
- try {
63
- response = await guardedFetch(url.toString(), {
64
- method: input.method,
65
- headers,
66
- ...input.body === void 0 ? {} : { body: JSON.stringify(input.body) }
67
- });
68
- } catch (error) {
69
- throw upstreamError(502, error instanceof Error ? `clerk \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "clerk \u8BF7\u6C42\u5931\u8D25");
70
- }
71
- const payload = await readPayload(response);
72
- if (!response.ok) {
73
- throw upstreamError(response.status, errorMessage(payload) ?? (response.statusText || `clerk \u8FD4\u56DE HTTP ${response.status}`));
74
- }
75
- return payload;
33
+ const { data } = await http.request({
34
+ path,
35
+ method: input.method,
36
+ query: input.query,
37
+ headers: {
38
+ accept: "application/json",
39
+ authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
40
+ },
41
+ ...input.body === void 0 ? {} : { json: input.body },
42
+ invalidJson: "text",
43
+ mapError: ({ data: payload, status }) => upstreamError(
44
+ status,
45
+ errorMessage(payload) ?? `clerk \u8FD4\u56DE HTTP ${status}`
46
+ ),
47
+ mapTransportError: ({ message }) => upstreamError(
48
+ 502,
49
+ message === void 0 ? "clerk \u8BF7\u6C42\u5931\u8D25" : `clerk \u8BF7\u6C42\u5931\u8D25: ${message}`
50
+ )
51
+ });
52
+ return data ?? {};
76
53
  }
77
54
  function normalizeListUsers(payload) {
78
55
  if (Array.isArray(payload)) return { users: payload, total_count: payload.length };
79
- const body = record(payload);
56
+ const body = asJsonObject(payload);
80
57
  if (body !== void 0 && Array.isArray(body.data)) {
81
- const total = body.total_count;
82
- return { users: body.data, total_count: typeof total === "number" ? total : body.data.length };
58
+ return {
59
+ users: body.data,
60
+ total_count: typeof body.total_count === "number" ? body.total_count : body.data.length
61
+ };
83
62
  }
84
63
  throw upstreamError(502, "clerk list_users \u8FD4\u56DE\u4E86\u975E\u9884\u671F\u5F62\u72B6");
85
64
  }
@@ -94,10 +73,10 @@ function userFilterQuery(input) {
94
73
  ];
95
74
  }
96
75
  async function runUserStateAction(action, userId, ctx) {
97
- return { user: await request(ctx, `/users/${encodeURIComponent(userId)}/${action}`, { method: "POST" }) };
76
+ return { user: await request(ctx, `users/${encodeURIComponent(userId)}/${action}`, { method: "POST" }) };
98
77
  }
99
78
  async function listUsers(input, ctx) {
100
- const payload = await request(ctx, "/users", {
79
+ return normalizeListUsers(await request(ctx, "users", {
101
80
  method: "GET",
102
81
  query: [
103
82
  ...userFilterQuery(input),
@@ -105,41 +84,42 @@ async function listUsers(input, ctx) {
105
84
  ["limit", input.limit],
106
85
  ["offset", input.offset]
107
86
  ]
108
- });
109
- return normalizeListUsers(payload);
87
+ }));
110
88
  }
111
- async function countUsers(input, ctx) {
112
- return request(ctx, "/users/count", { method: "GET", query: userFilterQuery(input) });
89
+ function countUsers(input, ctx) {
90
+ return request(ctx, "users/count", { method: "GET", query: userFilterQuery(input) });
113
91
  }
114
92
  async function getUser(input, ctx) {
115
- return { user: await request(ctx, `/users/${encodeURIComponent(input.user_id)}`, { method: "GET" }) };
93
+ return { user: await request(ctx, `users/${encodeURIComponent(input.user_id)}`, { method: "GET" }) };
116
94
  }
117
95
  async function createUser(input, ctx) {
118
- return { user: await request(ctx, "/users", { method: "POST", body: input }) };
96
+ return { user: await request(ctx, "users", { method: "POST", body: input }) };
119
97
  }
120
98
  async function updateUser(input, ctx) {
121
99
  const { user_id, ...body } = input;
122
- return { user: await request(ctx, `/users/${encodeURIComponent(user_id)}`, { method: "PATCH", body }) };
100
+ return { user: await request(ctx, `users/${encodeURIComponent(user_id)}`, { method: "PATCH", body }) };
123
101
  }
124
102
  async function updateUserMetadata(input, ctx) {
125
103
  const { user_id, ...body } = input;
126
- const path = `/users/${encodeURIComponent(user_id)}/metadata`;
127
- return { user: await request(ctx, path, { method: "PATCH", body }) };
104
+ return {
105
+ user: await request(ctx, `users/${encodeURIComponent(user_id)}/metadata`, { method: "PATCH", body })
106
+ };
128
107
  }
129
108
  async function deleteUser(input, ctx) {
130
- const path = `/users/${encodeURIComponent(input.user_id)}`;
131
- return { deleted_object: await request(ctx, path, { method: "DELETE" }) };
109
+ return {
110
+ deleted_object: await request(ctx, `users/${encodeURIComponent(input.user_id)}`, { method: "DELETE" })
111
+ };
132
112
  }
133
- async function banUser(input, ctx) {
113
+ function banUser(input, ctx) {
134
114
  return runUserStateAction("ban", input.user_id, ctx);
135
115
  }
136
- async function unbanUser(input, ctx) {
116
+ function unbanUser(input, ctx) {
137
117
  return runUserStateAction("unban", input.user_id, ctx);
138
118
  }
139
- async function lockUser(input, ctx) {
119
+ function lockUser(input, ctx) {
140
120
  return runUserStateAction("lock", input.user_id, ctx);
141
121
  }
142
- async function unlockUser(input, ctx) {
122
+ function unlockUser(input, ctx) {
143
123
  return runUserStateAction("unlock", input.user_id, ctx);
144
124
  }
145
125