@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
@@ -1,34 +1,27 @@
1
+ import {
2
+ asJsonObject,
3
+ integerValue,
4
+ trimmedText
5
+ } from "./chunk-JXHMDBAY.js";
1
6
  import {
2
7
  createProviderPlugin,
3
8
  requireCredential,
4
9
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
10
+ } from "./chunk-YASUMV2K.js";
6
11
  import {
7
12
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
13
+ } from "./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/twilio/api.ts
17
21
  var SERVICE = "twilio";
18
22
  var API_BASE = "https://api.twilio.com/2010-04-01";
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 integer(value) {
28
- return typeof value === "number" && Number.isInteger(value) ? value : void 0;
29
- }
30
23
  function requireText(value, field) {
31
- const result = text(value);
24
+ const result = trimmedText(value);
32
25
  if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
33
26
  return result;
34
27
  }
@@ -41,13 +34,13 @@ function basicAuthHeader(ctx) {
41
34
  return `Basic ${btoa(binary)}`;
42
35
  }
43
36
  function errorMessage(payload, raw, status) {
44
- const body = record(payload);
37
+ const body = asJsonObject(payload);
45
38
  if (body === void 0) {
46
39
  const trimmed = raw.trim();
47
40
  return trimmed === "" ? `Twilio request failed with ${status}` : trimmed;
48
41
  }
49
- const message = text(body.message) ?? text(body.detail) ?? `Twilio request failed with ${status}`;
50
- const code = text(body.code) ?? integer(body.code)?.toString();
42
+ const message = trimmedText(body.message) ?? trimmedText(body.detail) ?? `Twilio request failed with ${status}`;
43
+ const code = trimmedText(body.code) ?? integerValue(body.code)?.toString();
51
44
  return code === void 0 ? message : `${message} (${code})`;
52
45
  }
53
46
  async function request(ctx, options) {
@@ -91,38 +84,38 @@ function accountPath(ctx, suffix) {
91
84
  return `/Accounts/${encodeURIComponent(accountSid)}${suffix}`;
92
85
  }
93
86
  function normalizeAccount(payload) {
94
- const account = record(payload) ?? {};
87
+ const account = asJsonObject(payload) ?? {};
95
88
  return {
96
- accountSid: text(account.sid) ?? "",
97
- friendlyName: text(account.friendly_name) ?? null,
98
- status: text(account.status) ?? null,
99
- type: text(account.type) ?? null
89
+ accountSid: trimmedText(account.sid) ?? "",
90
+ friendlyName: trimmedText(account.friendly_name) ?? null,
91
+ status: trimmedText(account.status) ?? null,
92
+ type: trimmedText(account.type) ?? null
100
93
  };
101
94
  }
102
95
  function normalizeUsageRecord(value) {
103
- const usage = record(value) ?? {};
96
+ const usage = asJsonObject(value) ?? {};
104
97
  return {
105
- accountSid: text(usage.account_sid) ?? null,
106
- category: text(usage.category) ?? null,
107
- count: text(usage.count) ?? null,
108
- countUnit: text(usage.count_unit) ?? null,
109
- usage: text(usage.usage) ?? null,
110
- usageUnit: text(usage.usage_unit) ?? null,
111
- price: text(usage.price) ?? null,
112
- priceUnit: text(usage.price_unit) ?? null,
113
- startDate: text(usage.start_date) ?? null,
114
- endDate: text(usage.end_date) ?? null
98
+ accountSid: trimmedText(usage.account_sid) ?? null,
99
+ category: trimmedText(usage.category) ?? null,
100
+ count: trimmedText(usage.count) ?? null,
101
+ countUnit: trimmedText(usage.count_unit) ?? null,
102
+ usage: trimmedText(usage.usage) ?? null,
103
+ usageUnit: trimmedText(usage.usage_unit) ?? null,
104
+ price: trimmedText(usage.price) ?? null,
105
+ priceUnit: trimmedText(usage.price_unit) ?? null,
106
+ startDate: trimmedText(usage.start_date) ?? null,
107
+ endDate: trimmedText(usage.end_date) ?? null
115
108
  };
116
109
  }
117
110
  function normalizeMessage(payload) {
118
- const message = record(payload) ?? {};
111
+ const message = asJsonObject(payload) ?? {};
119
112
  return {
120
- messageSid: text(message.sid) ?? "",
121
- accountSid: text(message.account_sid) ?? null,
122
- status: text(message.status) ?? null,
123
- to: text(message.to) ?? null,
124
- from: text(message.from) ?? null,
125
- body: text(message.body) ?? null
113
+ messageSid: trimmedText(message.sid) ?? "",
114
+ accountSid: trimmedText(message.account_sid) ?? null,
115
+ status: trimmedText(message.status) ?? null,
116
+ to: trimmedText(message.to) ?? null,
117
+ from: trimmedText(message.from) ?? null,
118
+ body: trimmedText(message.body) ?? null
126
119
  };
127
120
  }
128
121
  function list(value) {
@@ -132,35 +125,35 @@ async function getAccount(_input, ctx) {
132
125
  return normalizeAccount(await request(ctx, { path: accountPath(ctx, ".json") }));
133
126
  }
134
127
  async function listUsageRecords(input, ctx) {
135
- const payload = record(await request(ctx, {
128
+ const payload = asJsonObject(await request(ctx, {
136
129
  path: accountPath(ctx, "/Usage/Records.json"),
137
130
  query: {
138
- Category: text(input.category),
139
- StartDate: text(input.startDate),
140
- EndDate: text(input.endDate),
131
+ Category: trimmedText(input.category),
132
+ StartDate: trimmedText(input.startDate),
133
+ EndDate: trimmedText(input.endDate),
141
134
  PageSize: input.pageSize
142
135
  }
143
136
  })) ?? {};
144
137
  return {
145
138
  usageRecords: list(payload.usage_records).map((item) => normalizeUsageRecord(item)),
146
- page: integer(payload.page) ?? null,
147
- pageSize: integer(payload.page_size) ?? null,
148
- nextPageUri: text(payload.next_page_uri) ?? null
139
+ page: integerValue(payload.page) ?? null,
140
+ pageSize: integerValue(payload.page_size) ?? null,
141
+ nextPageUri: trimmedText(payload.next_page_uri) ?? null
149
142
  };
150
143
  }
151
144
  async function listMessages(input, ctx) {
152
- const payload = record(await request(ctx, {
145
+ const payload = asJsonObject(await request(ctx, {
153
146
  path: accountPath(ctx, "/Messages.json"),
154
147
  query: {
155
- To: text(input.to),
156
- From: text(input.from),
148
+ To: trimmedText(input.to),
149
+ From: trimmedText(input.from),
157
150
  PageSize: input.pageSize,
158
- PageToken: text(input.pageToken)
151
+ PageToken: trimmedText(input.pageToken)
159
152
  }
160
153
  })) ?? {};
161
154
  return {
162
155
  messages: list(payload.messages).map((item) => normalizeMessage(item)),
163
- nextPageUri: text(payload.next_page_uri) ?? null
156
+ nextPageUri: trimmedText(payload.next_page_uri) ?? null
164
157
  };
165
158
  }
166
159
  async function getMessage(input, ctx) {
@@ -1,81 +1,61 @@
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/umami/api.ts
17
21
  var SERVICE = "umami";
18
22
  var API_BASE = "https://api.umami.is";
19
- function asRecord(value) {
20
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
21
- }
22
- function optionalText(value) {
23
- if (typeof value !== "string") return void 0;
24
- const trimmed = value.trim();
25
- return trimmed === "" ? void 0 : trimmed;
26
- }
23
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
27
24
  function requiredText(value, field) {
28
- const text = optionalText(value);
25
+ const text = trimmedText(value);
29
26
  if (text === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
30
27
  return text;
31
28
  }
32
- async function readPayload(response) {
33
- const text = await response.text().catch(() => "");
34
- if (text.trim() === "") return null;
35
- try {
36
- return JSON.parse(text);
37
- } catch {
38
- return text;
39
- }
40
- }
41
29
  function errorMessage(payload) {
42
- if (typeof payload === "string") return optionalText(payload);
43
- const body = asRecord(payload);
30
+ if (typeof payload === "string") return trimmedText(payload);
31
+ const body = asJsonObject(payload);
44
32
  if (body === void 0) return void 0;
45
- return optionalText(body.error) ?? optionalText(asRecord(body.error)?.message) ?? optionalText(body.message);
33
+ return trimmedText(body.error) ?? trimmedText(asJsonObject(body.error)?.message) ?? trimmedText(body.message);
46
34
  }
47
35
  async function request(ctx, path, query = {}) {
48
36
  const apiKey = requireApiKey(ctx, SERVICE);
49
- const url = new URL(`${API_BASE}${path}`);
50
- for (const [key, value] of Object.entries(query)) {
51
- if (value !== void 0) url.searchParams.set(key, value);
52
- }
53
- let response;
54
- let payload;
55
- try {
56
- response = await guardedFetch(url.toString(), {
57
- method: "GET",
58
- headers: {
59
- accept: "application/json",
60
- authorization: `Bearer ${apiKey}`
61
- }
62
- });
63
- payload = await readPayload(response);
64
- } catch (error) {
65
- if (error instanceof TBError) throw error;
66
- throw upstreamError(502, error instanceof Error ? `umami \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "umami \u8BF7\u6C42\u5931\u8D25");
67
- }
68
- if (!response.ok) {
69
- throw upstreamError(
70
- response.status,
71
- errorMessage(payload) ?? (response.statusText || `umami \u8FD4\u56DE HTTP ${response.status}`)
72
- );
73
- }
74
- if (typeof payload === "string") throw upstreamError(502, "umami \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
75
- return payload;
37
+ const response = await http.request({
38
+ path,
39
+ query: Object.entries(query),
40
+ headers: {
41
+ accept: "application/json",
42
+ authorization: `Bearer ${apiKey}`
43
+ },
44
+ invalidJson: "text",
45
+ mapError: ({ data, status, statusText }) => upstreamError(
46
+ status,
47
+ errorMessage(data) ?? (statusText || `umami \u8FD4\u56DE HTTP ${status}`)
48
+ ),
49
+ mapTransportError: ({ message }) => upstreamError(
50
+ 502,
51
+ message === void 0 ? "umami \u8BF7\u6C42\u5931\u8D25" : `umami \u8BF7\u6C42\u5931\u8D25: ${message}`
52
+ )
53
+ });
54
+ if (response.bodyKind === "invalid-json") throw upstreamError(502, "umami \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
55
+ return response.bodyKind === "empty" ? null : response.data;
76
56
  }
77
57
  function responseRecord(value, field) {
78
- const object = asRecord(value);
58
+ const object = asJsonObject(value);
79
59
  if (object === void 0) throw upstreamError(502, `umami \u54CD\u5E94\u7684 ${field} \u4E0D\u662F\u5BF9\u8C61`);
80
60
  return object;
81
61
  }
@@ -97,16 +77,16 @@ function dateRangeQuery(input) {
97
77
  startAt: String(input.startAt),
98
78
  endAt: String(input.endAt),
99
79
  timezone: requiredText(input.timezone, "timezone"),
100
- url: optionalText(input.url),
101
- referrer: optionalText(input.referrer),
102
- title: optionalText(input.title),
103
- host: optionalText(input.host),
104
- os: optionalText(input.os),
105
- browser: optionalText(input.browser),
106
- device: optionalText(input.device),
107
- country: optionalText(input.country),
108
- region: optionalText(input.region),
109
- city: optionalText(input.city)
80
+ url: trimmedText(input.url),
81
+ referrer: trimmedText(input.referrer),
82
+ title: trimmedText(input.title),
83
+ host: trimmedText(input.host),
84
+ os: trimmedText(input.os),
85
+ browser: trimmedText(input.browser),
86
+ device: trimmedText(input.device),
87
+ country: trimmedText(input.country),
88
+ region: trimmedText(input.region),
89
+ city: trimmedText(input.city)
110
90
  };
111
91
  }
112
92
  function websitePath(websiteId, suffix = "") {
@@ -128,7 +108,7 @@ async function getCurrentUser(_input, ctx) {
128
108
  }
129
109
  async function listWebsites(input, ctx) {
130
110
  const payload = await request(ctx, "/api/websites", {
131
- query: optionalText(input.query),
111
+ query: trimmedText(input.query),
132
112
  page: input.page === void 0 ? void 0 : String(input.page),
133
113
  pageSize: input.pageSize === void 0 ? void 0 : String(input.pageSize)
134
114
  });
@@ -145,7 +125,7 @@ async function getWebsiteStats(input, ctx) {
145
125
  }
146
126
  async function getPageviews(input, ctx) {
147
127
  const path = websitePath(input.websiteId, "/pageviews");
148
- const query = { ...dateRangeQuery(input), unit: optionalText(input.unit) };
128
+ const query = { ...dateRangeQuery(input), unit: trimmedText(input.unit) };
149
129
  const pageviews = responseRecord(await request(ctx, path, query), "pageviews");
150
130
  return { pageviews, raw: pageviews };
151
131
  }
@@ -168,7 +148,7 @@ async function listEvents(input, ctx) {
168
148
  const path = websitePath(input.websiteId, "/events");
169
149
  const query = {
170
150
  ...dateRangeQuery(input),
171
- query: optionalText(input.query),
151
+ query: trimmedText(input.query),
172
152
  page: input.page === void 0 ? void 0 : String(input.page),
173
153
  pageSize: input.pageSize === void 0 ? void 0 : String(input.pageSize)
174
154
  };
@@ -1,34 +1,29 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject,
6
+ finiteNumber,
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-YASUMV2K.js";
14
+ import "./chunk-U5UHT7CX.js";
10
15
  import {
11
16
  TBError,
12
17
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
18
+ } from "./chunk-RVWZN3CI.js";
19
+ import "./chunk-U67V476Y.js";
15
20
 
16
21
  // ../plugins/src/unsplash/api.ts
17
22
  var SERVICE = "unsplash";
18
23
  var API_BASE = "https://api.unsplash.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 numeric(value) {
28
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
29
- }
24
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
30
25
  function requireRecord(value, label) {
31
- const result = record(value);
26
+ const result = asJsonObject(value);
32
27
  if (result === void 0) {
33
28
  throw new TBError("unavailable", `${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
34
29
  }
@@ -41,58 +36,46 @@ function objectArray(value) {
41
36
  return value.map((item) => requireRecord(item, "Unsplash \u6570\u7EC4\u5143\u7D20"));
42
37
  }
43
38
  function requireText(value, field) {
44
- const result = text(value);
39
+ const result = trimmedText(value);
45
40
  if (result === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u662F\u7A7A\u767D`);
46
41
  return result;
47
42
  }
48
43
  function csv(value) {
49
44
  if (value === void 0) return void 0;
50
- const items = value.map((item) => text(item)).filter((item) => item !== void 0);
45
+ const items = value.map((item) => trimmedText(item)).filter((item) => item !== void 0);
51
46
  return items.length > 0 ? items.join(",") : void 0;
52
47
  }
53
- function buildUrl(path, query) {
54
- const url = new URL(`${API_BASE}${path}`);
55
- for (const [key, value] of Object.entries(query)) {
56
- if (value !== void 0) url.searchParams.set(key, String(value));
57
- }
58
- return url.toString();
59
- }
60
48
  function errorMessage(payload) {
61
- const body = record(payload);
49
+ const body = asJsonObject(payload);
62
50
  if (body === void 0) return void 0;
63
51
  if (Array.isArray(body.errors)) {
64
52
  for (const item of body.errors) {
65
- const message = text(item);
53
+ const message = trimmedText(item);
66
54
  if (message !== void 0) return message;
67
55
  }
68
56
  }
69
- return text(body.error) ?? text(body.message);
57
+ return trimmedText(body.error) ?? trimmedText(body.message);
70
58
  }
71
59
  async function request(ctx, path, query = {}) {
72
- const response = await guardedFetch(buildUrl(path, query), {
73
- method: "GET",
60
+ const response = await http.request({
61
+ path,
62
+ query: Object.entries(query),
74
63
  headers: {
75
64
  "accept": "application/json",
76
65
  // Unsplash 自有的方案名,不是 Bearer。
77
66
  "authorization": `Client-ID ${requireApiKey(ctx, SERVICE)}`,
78
67
  "accept-version": "v1"
79
- }
68
+ },
69
+ invalidJson: "text",
70
+ mapError: ({ bodyKind, data, status }) => upstreamError(
71
+ status,
72
+ errorMessage(bodyKind === "json" ? data : null) ?? `Unsplash \u8FD4\u56DE HTTP ${status}`
73
+ )
80
74
  });
81
- const body = await response.text();
82
- let payload = null;
83
- if (body !== "") {
84
- try {
85
- payload = JSON.parse(body);
86
- } catch {
87
- if (response.ok) {
88
- throw new TBError("unavailable", "Unsplash \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
89
- }
90
- }
91
- }
92
- if (!response.ok) {
93
- throw upstreamError(response.status, errorMessage(payload) ?? `Unsplash \u8FD4\u56DE HTTP ${response.status}`);
75
+ if (response.bodyKind === "invalid-json") {
76
+ throw new TBError("unavailable", "Unsplash \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
94
77
  }
95
- return payload;
78
+ return response.bodyKind === "empty" ? null : response.data;
96
79
  }
97
80
  async function listPhotos(input, ctx) {
98
81
  const payload = await request(ctx, "/photos", {
@@ -116,8 +99,8 @@ async function searchPhotos(input, ctx) {
116
99
  });
117
100
  const result = requireRecord(payload, "Unsplash \u641C\u7D22\u54CD\u5E94");
118
101
  return {
119
- total: numeric(result.total) ?? 0,
120
- totalPages: numeric(result.total_pages) ?? 0,
102
+ total: finiteNumber(result.total) ?? 0,
103
+ totalPages: finiteNumber(result.total_pages) ?? 0,
121
104
  results: objectArray(result.results)
122
105
  };
123
106
  }
@@ -127,7 +110,7 @@ async function getPhoto(input, ctx) {
127
110
  return { photo: requireRecord(payload, "Unsplash \u7167\u7247\u54CD\u5E94") };
128
111
  }
129
112
  async function getRandomPhoto(input, ctx) {
130
- const query = text(input.query);
113
+ const query = trimmedText(input.query);
131
114
  const collections = csv(input.collections);
132
115
  const topics = csv(input.topics);
133
116
  if (query !== void 0 && (collections !== void 0 || topics !== void 0)) {
@@ -137,7 +120,7 @@ async function getRandomPhoto(input, ctx) {
137
120
  query,
138
121
  collections,
139
122
  topics,
140
- username: text(input.username),
123
+ username: trimmedText(input.username),
141
124
  orientation: input.orientation,
142
125
  content_filter: input.contentFilter,
143
126
  count: input.count
@@ -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
  requireCredential,
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/upstash_redis/api.ts
17
21
  var SERVICE = "upstash_redis";
18
22
  var HOSTNAME_SUFFIX = ".upstash.io";
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({ service: SERVICE });
27
24
  function responseError(message) {
28
25
  return new TBError("unavailable", message, { retryable: true });
29
26
  }
@@ -54,15 +51,15 @@ function restUrl(ctx) {
54
51
  return url;
55
52
  }
56
53
  function commandError(status, payload, fallbackBody) {
57
- const body = record(payload);
58
- const message = text(body?.error) ?? text(body?.message) ?? text(fallbackBody) ?? `Upstash Redis \u8FD4\u56DE HTTP ${status}`;
54
+ const body = asJsonObject(payload);
55
+ const message = trimmedText(body?.error) ?? trimmedText(body?.message) ?? trimmedText(fallbackBody) ?? `Upstash Redis \u8FD4\u56DE HTTP ${status}`;
59
56
  if (isQuotaMessage(message)) return upstreamError(429, message);
60
57
  return upstreamError(status, message);
61
58
  }
62
59
  function unwrap(payload) {
63
- const body = record(payload);
60
+ const body = asJsonObject(payload);
64
61
  if (body === void 0) throw responseError("Upstash Redis \u54CD\u5E94\u4E0D\u662F\u5BF9\u8C61");
65
- const error = text(body.error);
62
+ const error = trimmedText(body.error);
66
63
  if (error !== void 0) {
67
64
  if (isQuotaMessage(error)) throw upstreamError(429, error);
68
65
  throw new TBError("invalid_argument", error);
@@ -71,31 +68,22 @@ function unwrap(payload) {
71
68
  return body.result;
72
69
  }
73
70
  async function command(ctx, args) {
74
- const response = await guardedFetch(restUrl(ctx), {
71
+ const result = await http.request({
72
+ baseUrl: restUrl(ctx),
73
+ path: "/",
75
74
  method: "POST",
76
75
  headers: {
77
- "accept": "application/json",
78
- "authorization": `Bearer ${requireCredential(ctx, SERVICE, "restToken")}`,
79
- "content-type": "application/json"
76
+ accept: "application/json",
77
+ authorization: `Bearer ${requireCredential(ctx, SERVICE, "restToken")}`
80
78
  },
81
- body: JSON.stringify(args)
79
+ json: args,
80
+ invalidJsonMessage: "Upstash Redis \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
81
+ mapError: ({ data, rawText, status }) => commandError(status, data, rawText ?? "")
82
82
  });
83
- const body = await response.text();
84
- let payload;
85
- let parsed = false;
86
- if (body !== "") {
87
- try {
88
- payload = JSON.parse(body);
89
- parsed = true;
90
- } catch {
91
- if (response.ok) throw responseError("Upstash Redis \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
92
- }
93
- }
94
- if (!response.ok) throw commandError(response.status, parsed ? payload : void 0, body);
95
- return unwrap(payload);
83
+ return unwrap(result.data);
96
84
  }
97
85
  function redisKey(value) {
98
- const key = text(value);
86
+ const key = trimmedText(value);
99
87
  if (key === void 0) throw new TBError("invalid_argument", "key \u4E0D\u80FD\u662F\u7A7A\u767D");
100
88
  return key;
101
89
  }
@@ -158,8 +146,8 @@ async function ttl(input, ctx) {
158
146
  return { ttlSeconds: integer(result, "TTL") };
159
147
  }
160
148
  async function scan(input, ctx) {
161
- const args = ["SCAN", text(input.cursor) ?? "0"];
162
- const match = text(input.match);
149
+ const args = ["SCAN", trimmedText(input.cursor) ?? "0"];
150
+ const match = trimmedText(input.match);
163
151
  if (match !== void 0) args.push("MATCH", match);
164
152
  if (input.count !== void 0) args.push("COUNT", input.count);
165
153
  const page = scanPage(await command(ctx, args));
@@ -1,24 +1,23 @@
1
+ import {
2
+ asJsonObject
3
+ } from "./chunk-JXHMDBAY.js";
1
4
  import {
2
5
  createProviderPlugin,
3
6
  requireApiKey,
4
7
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
8
+ } from "./chunk-YASUMV2K.js";
6
9
  import {
7
10
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
11
+ } from "./chunk-U5UHT7CX.js";
10
12
  import {
11
13
  TBError,
12
14
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
15
+ } from "./chunk-RVWZN3CI.js";
16
+ import "./chunk-U67V476Y.js";
15
17
 
16
18
  // ../plugins/src/uptimerobot/api.ts
17
19
  var SERVICE = "uptimerobot";
18
20
  var API_BASE = "https://api.uptimerobot.com/v2/";
19
- function record(value) {
20
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
21
- }
22
21
  function text(value) {
23
22
  return typeof value === "string" && value !== "" ? value : void 0;
24
23
  }
@@ -31,7 +30,7 @@ function integer(value) {
31
30
  return void 0;
32
31
  }
33
32
  function toError(status, payload) {
34
- const error = record(record(payload)?.error);
33
+ const error = asJsonObject(asJsonObject(payload)?.error);
35
34
  const message = text(error?.message) ?? (!status || status === 200 ? "uptimerobot request failed" : `uptimerobot request failed with status ${status}`);
36
35
  const type = text(error?.type);
37
36
  const httpStatus = status >= 400 ? status : void 0;
@@ -75,13 +74,13 @@ async function request(ctx, endpoint, body) {
75
74
  }
76
75
  const payload = await readPayload(response);
77
76
  if (!response.ok) throw toError(response.status, payload);
78
- const parsed = record(payload);
77
+ const parsed = asJsonObject(payload);
79
78
  if (parsed === void 0) throw upstreamError(502, "uptimerobot returned an invalid response payload");
80
79
  if (parsed.stat !== "ok") throw toError(response.status, parsed);
81
80
  return parsed;
82
81
  }
83
82
  function requireObjectPayload(value, label) {
84
- const parsed = record(value);
83
+ const parsed = asJsonObject(value);
85
84
  if (parsed === void 0) throw upstreamError(502, `${label} must be an object`);
86
85
  return parsed;
87
86
  }
@@ -172,7 +171,7 @@ async function getMonitor(input, ctx) {
172
171
  setBoolean(form, "alert_contacts", input.alert_contacts);
173
172
  const payload = await request(ctx, "getMonitors", form);
174
173
  const monitors = requireArrayPayload(payload.monitors, "uptimerobot single monitor response");
175
- const monitor = record(monitors[0]);
174
+ const monitor = asJsonObject(monitors[0]);
176
175
  if (monitor === void 0) throw upstreamError(404, `monitor ${input.monitor_id} was not found`);
177
176
  return { monitor };
178
177
  }