@tool-bridge/server 0.16.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-23JBIM6X.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-ADWBTCIH.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-CYQCYW2Z.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-5P62HDNR.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-54RZUAGW.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-AHJ6FTD5.js} +52 -77
  7. package/dist/{chunk-VK3V2WTY.js → chunk-B4P6YZFS.js} +4 -6
  8. package/dist/{chunk-BB6ZLMTU.js → chunk-CLEZ6YQ6.js} +2600 -481
  9. package/dist/chunk-JXHMDBAY.js +45 -0
  10. package/dist/chunk-LMLX3DJF.js +50 -0
  11. package/dist/{chunk-YB2FLNWI.js → chunk-OKRZPQ3R.js} +2558 -1926
  12. package/dist/chunk-SWBNHIO4.js +977 -0
  13. package/dist/chunk-U67V476Y.js +35 -0
  14. package/dist/chunk-VLOIDU5U.js +283 -0
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-UM3NSQJ3.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-FE5LQ2CZ.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-KEZABKUT.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-4IPJADXP.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-56QEKNQI.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-3QRM5K5T.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-L6G4OND5.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-LGC6HBFG.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-XDMK3BIU.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-4QARMFZU.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-C6JSJKOT.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-6A6TVACJ.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-SIWWW6AA.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-3IJXOKSP.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-L4KDA4DC.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-SDM75H4P.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-6DD436DN.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-SYSGYB3R.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-FZG7ASTF.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-HMRCZBUC.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-FAFSD7I3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-4D3TWENM.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-OSO2FOZS.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-OR4I4RHE.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-5AOPJ63E.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-SOJIJUWH.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-QSKN5TLN.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-R3AIZM7M.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-4CR3QOAX.js} +32 -46
  44. package/dist/index.d.ts +108 -56
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-OBCG6X6J.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-NHH3DTQW.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-7POMCBEC.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-YXVKROV4.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-LADO3VJU.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-XZ6UAQFU.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-P74GLNE7.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-CXJ7D37A.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-EVVHWFLK.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-WG2MRGBD.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-HQWUKG6U.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-SQMJIFOE.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-E27G2DZI.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-MIL63NIT.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-AIZVCBNR.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-XS4DVIQS.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-JEOUSL2Y.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-U4EZVDW2.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-AZSQEYEJ.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-HW3SYMTQ.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-QX74MAEL.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-OXSKYL6N.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-CCQAPDSW.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-6KQPSSCK.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-2TXO7IQE.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-YOO7NULI.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-Q6RIFIFP.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-KUMGCES3.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-VXQHBSMB.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-YLIPF52S.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-CRY7UJN5.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-3Z4T5AM7.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-BP37IGFL.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-HTKICF4K.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-WIVTUXJH.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-JJYPA43D.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-TKHZVG7A.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-FRSZLG5U.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-M5WXGQWE.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-PMXNLLBK.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-HFW4TAOH.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-KXVH2VZQ.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-WWOT2LRX.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-FY635H35.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-HQLBVSA5.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-GJN2GOHB.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BBNZGQU6.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-DPENIBOG.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-L4NONG6H.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-H67MAEZS.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-G2BSP4DX.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-7WMVFDG2.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-ZUAESFC2.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-EYFYIX3B.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-AXAUDUVF.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-UCQAWPLR.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-ZPZ4ASU6.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-4QVKKUD5.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-VGEFJTYC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-JME4TSCN.js} +124 -150
  107. package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
  108. package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-TRGU2MDG.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-WRUKLCZR.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-ZDW4EHS4.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-4VI67CWU.js} +35 -57
  112. package/package.json +3 -3
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. package/dist/chunk-MLKGABMK.js +0 -9
@@ -1,52 +1,43 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.js";
4
+ import {
5
+ asJsonObject,
6
+ booleanValue,
7
+ compactDefined,
8
+ integerValue,
9
+ trimmedText
10
+ } from "./chunk-JXHMDBAY.js";
1
11
  import {
2
12
  createProviderPlugin,
3
13
  requireApiKey,
4
14
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
15
+ } from "./chunk-B4P6YZFS.js";
16
+ import "./chunk-SWBNHIO4.js";
10
17
  import {
11
18
  TBError,
12
19
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
20
+ } from "./chunk-OKRZPQ3R.js";
21
+ import "./chunk-U67V476Y.js";
15
22
 
16
23
  // ../plugins/src/cloudflare_dns/api.ts
17
24
  var SERVICE = "cloudflare_dns";
18
25
  var API_BASE = "https://api.cloudflare.com/client/v4";
26
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
19
27
  var DEFAULT_ACCOUNTS_PAGE = 1;
20
28
  var DEFAULT_ACCOUNTS_PER_PAGE = 50;
21
- function text(value) {
22
- if (typeof value !== "string") return void 0;
23
- const trimmed = value.trim();
24
- return trimmed === "" ? void 0 : trimmed;
25
- }
26
29
  function rawText(value) {
27
30
  return typeof value === "string" ? value : void 0;
28
31
  }
29
- function record(value) {
30
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
31
- }
32
- function integer(value) {
33
- return typeof value === "number" && Number.isInteger(value) ? value : void 0;
34
- }
35
- function boolean(value) {
36
- return typeof value === "boolean" ? value : void 0;
37
- }
38
32
  function nullableText(value) {
39
- return value === null ? null : text(value);
33
+ return value === null ? null : trimmedText(value);
40
34
  }
41
35
  function textArray(value) {
42
36
  if (!Array.isArray(value)) return void 0;
43
37
  return value.filter((item) => typeof item === "string");
44
38
  }
45
- function compact(input) {
46
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
47
- }
48
39
  function requireRecord(value, label) {
49
- const result = record(value);
40
+ const result = asJsonObject(value);
50
41
  if (result === void 0) throw new TBError("unavailable", `${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
51
42
  return result;
52
43
  }
@@ -55,24 +46,16 @@ function requireArray(value, label) {
55
46
  return value;
56
47
  }
57
48
  function requireText(source, field, label) {
58
- const value = text(source[field]);
49
+ const value = trimmedText(source[field]);
59
50
  if (value === void 0) {
60
51
  throw new TBError("unavailable", `${label}\u7F3A\u5C11 ${field}`, { retryable: true });
61
52
  }
62
53
  return value;
63
54
  }
64
- function buildUrl(path, query) {
65
- const url = new URL(`${API_BASE}${path}`);
66
- for (const [key, value] of Object.entries(query ?? {})) {
67
- if (value === void 0 || value === "") continue;
68
- url.searchParams.set(key, String(value));
69
- }
70
- return url.toString();
71
- }
72
55
  function errorMessage(envelope, status) {
73
56
  for (const source of [envelope.errors, envelope.messages]) {
74
57
  for (const entry of Array.isArray(source) ? source : []) {
75
- const message = text(record(entry)?.message);
58
+ const message = trimmedText(asJsonObject(entry)?.message);
76
59
  if (message !== void 0) return message;
77
60
  }
78
61
  }
@@ -80,115 +63,109 @@ function errorMessage(envelope, status) {
80
63
  }
81
64
  async function request(ctx, input) {
82
65
  const hasBody = input.body !== void 0;
83
- const headers = {
84
- accept: "application/json",
85
- authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
86
- };
87
- if (hasBody) headers["content-type"] = "application/json";
88
- const response = await guardedFetch(buildUrl(input.path, input.query), {
66
+ const result = await http.request({
67
+ path: input.path,
89
68
  method: input.method ?? "GET",
90
- headers,
91
- body: hasBody ? JSON.stringify(input.body) : void 0
92
- });
93
- const body = await response.text().catch(() => "");
94
- let envelope;
95
- if (body !== "") {
96
- try {
97
- envelope = requireRecord(JSON.parse(body), "Cloudflare \u54CD\u5E94");
98
- } catch (error) {
99
- if (error instanceof TBError) throw error;
100
- if (response.ok) {
101
- throw new TBError("unavailable", "Cloudflare \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
69
+ // 上游 `queryParams`:undefined / null / 空串一律不发。
70
+ query: Object.entries(input.query ?? {}).filter(([, value]) => value !== void 0 && value !== ""),
71
+ headers: { accept: "application/json", authorization: `Bearer ${requireApiKey(ctx, SERVICE)}` },
72
+ ...hasBody ? { json: input.body } : {},
73
+ invalidJsonMessage: "Cloudflare \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
74
+ mapError: ({ bodyKind, data, status }) => {
75
+ if (bodyKind === "json" && asJsonObject(data) === void 0) {
76
+ return new TBError("unavailable", "Cloudflare \u54CD\u5E94\u4E0D\u662F\u5BF9\u8C61", { retryable: true });
102
77
  }
78
+ const envelope2 = bodyKind === "json" ? data : {};
79
+ return upstreamError(status, errorMessage(envelope2, status));
103
80
  }
81
+ });
82
+ const envelope = result.data === void 0 ? {} : requireRecord(result.data, "Cloudflare \u54CD\u5E94");
83
+ if (envelope.success === false) {
84
+ throw upstreamError(result.status, errorMessage(envelope, result.status));
104
85
  }
105
- const result = envelope ?? {};
106
- if (!response.ok || result.success === false) {
107
- throw upstreamError(response.status, errorMessage(result, response.status));
108
- }
109
- return result;
86
+ return envelope;
110
87
  }
111
88
  function normalizeAccount(value) {
112
89
  const account = requireRecord(value, "Cloudflare \u8D26\u6237");
113
- return compact({
90
+ return compactDefined({
114
91
  id: requireText(account, "id", "Cloudflare \u8D26\u6237"),
115
- name: text(account.name),
116
- type: text(account.type)
92
+ name: trimmedText(account.name),
93
+ type: trimmedText(account.type)
117
94
  });
118
95
  }
119
96
  function normalizeZoneAccount(value) {
120
- const account = record(value);
97
+ const account = asJsonObject(value);
121
98
  if (account === void 0) return void 0;
122
- return compact({
123
- id: text(account.id),
124
- name: text(account.name),
125
- type: text(account.type)
99
+ return compactDefined({
100
+ id: trimmedText(account.id),
101
+ name: trimmedText(account.name),
102
+ type: trimmedText(account.type)
126
103
  });
127
104
  }
128
105
  function normalizeZone(value) {
129
106
  const zone = requireRecord(value, "Cloudflare zone");
130
- return compact({
107
+ return compactDefined({
131
108
  id: requireText(zone, "id", "Cloudflare zone"),
132
109
  name: requireText(zone, "name", "Cloudflare zone"),
133
- status: text(zone.status),
134
- type: text(zone.type),
135
- paused: boolean(zone.paused),
136
- createdOn: text(zone.created_on),
137
- modifiedOn: text(zone.modified_on),
110
+ status: trimmedText(zone.status),
111
+ type: trimmedText(zone.type),
112
+ paused: booleanValue(zone.paused),
113
+ createdOn: trimmedText(zone.created_on),
114
+ modifiedOn: trimmedText(zone.modified_on),
138
115
  nameServers: textArray(zone.name_servers),
139
116
  originalNameServers: textArray(zone.original_name_servers),
140
117
  account: normalizeZoneAccount(zone.account),
141
- meta: record(zone.meta)
118
+ meta: asJsonObject(zone.meta)
142
119
  });
143
120
  }
144
121
  function normalizeDnsRecord(value) {
145
122
  const dns = requireRecord(value, "Cloudflare DNS \u8BB0\u5F55");
146
- return compact({
123
+ return compactDefined({
147
124
  id: requireText(dns, "id", "Cloudflare DNS \u8BB0\u5F55"),
148
- zoneId: text(dns.zone_id),
149
- zoneName: text(dns.zone_name),
125
+ zoneId: trimmedText(dns.zone_id),
126
+ zoneName: trimmedText(dns.zone_name),
150
127
  type: requireText(dns, "type", "Cloudflare DNS \u8BB0\u5F55"),
151
128
  name: requireText(dns, "name", "Cloudflare DNS \u8BB0\u5F55"),
152
129
  content: nullableText(dns.content),
153
- ttl: integer(dns.ttl),
154
- proxied: boolean(dns.proxied),
155
- proxiable: boolean(dns.proxiable),
156
- priority: integer(dns.priority),
130
+ ttl: integerValue(dns.ttl),
131
+ proxied: booleanValue(dns.proxied),
132
+ proxiable: booleanValue(dns.proxiable),
133
+ priority: integerValue(dns.priority),
157
134
  comment: nullableText(dns.comment),
158
135
  tags: textArray(dns.tags),
159
- createdOn: text(dns.created_on),
160
- modifiedOn: text(dns.modified_on),
161
- commentModifiedOn: text(dns.comment_modified_on),
162
- tagsModifiedOn: text(dns.tags_modified_on),
163
- data: record(dns.data),
164
- meta: record(dns.meta),
165
- settings: record(dns.settings)
136
+ createdOn: trimmedText(dns.created_on),
137
+ modifiedOn: trimmedText(dns.modified_on),
138
+ commentModifiedOn: trimmedText(dns.comment_modified_on),
139
+ tagsModifiedOn: trimmedText(dns.tags_modified_on),
140
+ data: asJsonObject(dns.data),
141
+ meta: asJsonObject(dns.meta),
142
+ settings: asJsonObject(dns.settings)
166
143
  });
167
144
  }
168
145
  function normalizeResultInfo(value) {
169
- const info = record(value);
146
+ const info = asJsonObject(value);
170
147
  if (info === void 0) return void 0;
171
- return compact({
172
- page: integer(info.page),
173
- perPage: integer(info.per_page),
174
- count: integer(info.count),
175
- totalCount: integer(info.total_count),
176
- totalPages: integer(info.total_pages)
148
+ return compactDefined({
149
+ page: integerValue(info.page),
150
+ perPage: integerValue(info.per_page),
151
+ count: integerValue(info.count),
152
+ totalCount: integerValue(info.total_count),
153
+ totalPages: integerValue(info.total_pages)
177
154
  });
178
155
  }
179
156
  function mutationBody(input) {
180
- return compact({
181
- type: text(input.type),
182
- name: text(input.name),
157
+ return compactDefined({
158
+ type: trimmedText(input.type),
159
+ name: trimmedText(input.name),
183
160
  // content / comment 原样发:清空一个字段靠的就是发空串,trim 掉就没法表达"清空"。
184
161
  content: rawText(input.content),
185
- data: record(input.data),
186
- ttl: integer(input.ttl),
187
- proxied: boolean(input.proxied),
188
- priority: integer(input.priority),
162
+ data: asJsonObject(input.data),
163
+ ttl: integerValue(input.ttl),
164
+ proxied: booleanValue(input.proxied),
165
+ priority: integerValue(input.priority),
189
166
  comment: rawText(input.comment),
190
167
  tags: input.tags,
191
- settings: record(input.settings)
168
+ settings: asJsonObject(input.settings)
192
169
  });
193
170
  }
194
171
  async function listAccounts(input, ctx) {
@@ -200,7 +177,7 @@ async function listAccounts(input, ctx) {
200
177
  per_page: input.perPage ?? DEFAULT_ACCOUNTS_PER_PAGE
201
178
  }
202
179
  });
203
- return compact({
180
+ return compactDefined({
204
181
  accounts: requireArray(envelope.result, "Cloudflare \u8D26\u6237\u5217\u8868").map((item) => normalizeAccount(item)),
205
182
  resultInfo: normalizeResultInfo(envelope.result_info)
206
183
  });
@@ -211,16 +188,16 @@ async function listZones(input, ctx) {
211
188
  query: {
212
189
  "page": input.page,
213
190
  "per_page": input.perPage,
214
- "name": text(input.name),
215
- "status": text(input.status),
191
+ "name": trimmedText(input.name),
192
+ "status": trimmedText(input.status),
216
193
  // 上游的过滤键就叫 `account.id`,带点,不是笔误。
217
- "account.id": text(input.accountId),
194
+ "account.id": trimmedText(input.accountId),
218
195
  "match": input.match,
219
- "order": text(input.order),
196
+ "order": trimmedText(input.order),
220
197
  "direction": input.direction
221
198
  }
222
199
  });
223
- return compact({
200
+ return compactDefined({
224
201
  zones: requireArray(envelope.result, "Cloudflare zone \u5217\u8868").map((item) => normalizeZone(item)),
225
202
  resultInfo: normalizeResultInfo(envelope.result_info)
226
203
  });
@@ -236,15 +213,15 @@ async function listDnsRecords(input, ctx) {
236
213
  page: input.page,
237
214
  per_page: input.perPage,
238
215
  type: input.type,
239
- name: text(input.name),
240
- content: text(input.content),
216
+ name: trimmedText(input.name),
217
+ content: trimmedText(input.content),
241
218
  proxied: input.proxied,
242
219
  match: input.match,
243
- order: text(input.order),
220
+ order: trimmedText(input.order),
244
221
  direction: input.direction
245
222
  }
246
223
  });
247
- return compact({
224
+ return compactDefined({
248
225
  records: requireArray(envelope.result, "Cloudflare DNS \u8BB0\u5F55\u5217\u8868").map((item) => normalizeDnsRecord(item)),
249
226
  resultInfo: normalizeResultInfo(envelope.result_info)
250
227
  });
@@ -1,72 +1,56 @@
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/cohere/api.ts
16
20
  var SERVICE = "cohere";
17
- var API_BASE = "https://api.cohere.com";
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
- }
26
- function errorMessage(body, status) {
27
- const fallback = text(body) ?? `cohere request failed with ${status}`;
28
- let payload;
29
- try {
30
- payload = JSON.parse(body);
31
- } catch {
32
- return fallback;
33
- }
34
- const root = record(payload);
35
- return text(record(root?.error)?.message) ?? text(root?.message) ?? fallback;
36
- }
37
- function cohereError(status, body) {
38
- return upstreamError(status === 498 ? 401 : status, errorMessage(body, status));
21
+ var http = createProviderHttpClient({ baseUrl: "https://api.cohere.com/", service: SERVICE });
22
+ function errorMessage(payload, status) {
23
+ const fallback = trimmedText(payload) ?? `cohere request failed with ${status}`;
24
+ const root = asJsonObject(payload);
25
+ return trimmedText(asJsonObject(root?.error)?.message) ?? trimmedText(root?.message) ?? fallback;
39
26
  }
40
27
  async function post(ctx, path, body) {
41
- const response = await guardedFetch(`${API_BASE}${path}`, {
28
+ const { data } = await http.request({
29
+ path,
42
30
  method: "POST",
43
31
  headers: {
44
- "accept": "application/json",
45
- "authorization": `Bearer ${requireApiKey(ctx, SERVICE)}`,
46
- "content-type": "application/json"
32
+ accept: "application/json",
33
+ authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
47
34
  },
48
- body: JSON.stringify(body)
35
+ json: body,
36
+ invalidJsonMessage: "cohere returned an invalid JSON response",
37
+ mapError: ({ data: payload, status }) => upstreamError(
38
+ status === 498 ? 401 : status,
39
+ errorMessage(payload, status)
40
+ )
49
41
  });
50
- const raw = await response.text().catch(() => "");
51
- if (!response.ok) throw cohereError(response.status, raw);
52
- let payload;
53
- try {
54
- payload = JSON.parse(raw);
55
- } catch {
56
- throw upstreamError(502, "cohere returned an invalid JSON response");
57
- }
58
- const result = record(payload);
42
+ const result = asJsonObject(data);
59
43
  if (result === void 0) throw upstreamError(502, "cohere returned an invalid JSON response");
60
44
  return result;
61
45
  }
62
- async function chat(input, ctx) {
63
- return post(ctx, "/v2/chat", input);
46
+ function chat(input, ctx) {
47
+ return post(ctx, "v2/chat", input);
64
48
  }
65
- async function embedTexts(input, ctx) {
66
- return post(ctx, "/v2/embed", input);
49
+ function embedTexts(input, ctx) {
50
+ return post(ctx, "v2/embed", input);
67
51
  }
68
- async function rerankDocuments(input, ctx) {
69
- return post(ctx, "/v2/rerank", input);
52
+ function rerankDocuments(input, ctx) {
53
+ return post(ctx, "v2/rerank", input);
70
54
  }
71
55
 
72
56
  // ../plugins/src/cohere/schema.ts