@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,41 +1,36 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined,
7
+ trimmedText
8
+ } from "./chunk-JXHMDBAY.js";
1
9
  import {
2
10
  createProviderPlugin,
3
11
  requireApiKey,
4
12
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
13
+ } from "./chunk-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/pinecone/api.ts
17
22
  var SERVICE = "pinecone";
18
23
  var CONTROL_API_BASE = "https://api.pinecone.io";
19
24
  var API_VERSION = "2026-04";
20
- function record(value) {
21
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
22
- }
23
- function text(value) {
24
- if (typeof value !== "string") return void 0;
25
- const trimmed = value.trim();
26
- return trimmed === "" ? void 0 : trimmed;
27
- }
25
+ var http = createProviderHttpClient({ service: SERVICE });
28
26
  function requireText(value, field) {
29
- const result = text(value);
27
+ const result = trimmedText(value);
30
28
  if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
31
29
  return result;
32
30
  }
33
- function compact(input) {
34
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
35
- }
36
31
  function compactDeep(value) {
37
32
  if (Array.isArray(value)) return value.map((item) => compactDeep(item));
38
- const fields = record(value);
33
+ const fields = asJsonObject(value);
39
34
  if (fields === void 0) return value;
40
35
  return Object.fromEntries(
41
36
  Object.entries(fields).filter(([, child]) => child !== void 0).map(([key, child]) => [key, compactDeep(child)])
@@ -53,22 +48,9 @@ function requireIndexHost(value) {
53
48
  if (parsed.username !== "" || parsed.password !== "") {
54
49
  throw new TBError("invalid_argument", "indexHost must not include credentials");
55
50
  }
56
- parsed.pathname = parsed.pathname.replace(/\/+$/, "");
57
51
  parsed.search = "";
58
52
  parsed.hash = "";
59
- return parsed.toString().replace(/\/+$/, "");
60
- }
61
- function buildUrl(baseUrl, path, query) {
62
- const url = new URL(path, `${baseUrl.replace(/\/+$/, "")}/`);
63
- for (const [key, value] of Object.entries(query ?? {})) {
64
- if (value === void 0) continue;
65
- if (Array.isArray(value)) {
66
- for (const item of value) url.searchParams.append(key, item);
67
- continue;
68
- }
69
- url.searchParams.set(key, value);
70
- }
71
- return url.toString();
53
+ return parsed.origin;
72
54
  }
73
55
  function headers(apiKey, hasBody) {
74
56
  return {
@@ -80,41 +62,33 @@ function headers(apiKey, hasBody) {
80
62
  }
81
63
  function errorMessage(payload, status) {
82
64
  if (typeof payload === "string") {
83
- const message2 = text(payload);
65
+ const message2 = trimmedText(payload);
84
66
  if (message2 !== void 0) return message2;
85
67
  }
86
- const fields = record(payload);
87
- const message = text(fields?.message) ?? text(record(fields?.error)?.message);
68
+ const fields = asJsonObject(payload);
69
+ const message = trimmedText(fields?.message) ?? trimmedText(asJsonObject(fields?.error)?.message);
88
70
  return message ?? `Pinecone request failed with status ${status}`;
89
71
  }
90
72
  async function request(ctx, input) {
91
73
  const apiKey = requireApiKey(ctx, SERVICE);
92
- let response;
93
- try {
94
- response = await guardedFetch(buildUrl(input.baseUrl ?? CONTROL_API_BASE, input.path, input.query), {
95
- method: input.method,
96
- headers: headers(apiKey, input.body !== void 0),
97
- body: input.body === void 0 ? void 0 : JSON.stringify(compactDeep(input.body))
98
- });
99
- } catch (error) {
100
- if (error instanceof TBError) throw error;
101
- const message = error instanceof Error ? `Pinecone request failed: ${error.message}` : "Pinecone request failed";
102
- throw upstreamError(502, message);
103
- }
104
- const raw = await response.text().catch(() => "");
105
- let payload = {};
106
- if (raw.trim() !== "") {
107
- try {
108
- payload = JSON.parse(raw);
109
- } catch {
110
- throw upstreamError(502, "Pinecone returned invalid JSON");
111
- }
112
- }
113
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
114
- return payload;
74
+ const result = await http.request({
75
+ baseUrl: `${(input.baseUrl ?? CONTROL_API_BASE).replace(/\/+$/, "")}/`,
76
+ path: input.path,
77
+ method: input.method,
78
+ query: Object.entries(input.query ?? {}),
79
+ headers: headers(apiKey, input.body !== void 0),
80
+ ...input.body === void 0 ? {} : { json: compactDeep(input.body) },
81
+ invalidJsonMessage: "Pinecone returned invalid JSON",
82
+ mapError: ({ bodyKind, data, status }) => bodyKind === "invalid-json" ? upstreamError(502, "Pinecone returned invalid JSON") : upstreamError(status, errorMessage(data, status)),
83
+ mapTransportError: ({ message }) => upstreamError(
84
+ 502,
85
+ message === void 0 ? "Pinecone request failed" : `Pinecone request failed: ${message}`
86
+ )
87
+ });
88
+ return result.data === void 0 ? {} : result.data;
115
89
  }
116
90
  function requireObject(payload, label) {
117
- const fields = record(payload);
91
+ const fields = asJsonObject(payload);
118
92
  if (fields === void 0) throw upstreamError(502, `${label} must be a JSON object`);
119
93
  return fields;
120
94
  }
@@ -143,13 +117,13 @@ async function createIndex(input, ctx) {
143
117
  method: "POST",
144
118
  path: "/indexes",
145
119
  // camelCase 入参 → snake_case 请求体,且 spec 恒存在(只支持 serverless)。
146
- body: compact({
120
+ body: compactDefined({
147
121
  name: requireText(input.name, "name"),
148
122
  dimension: typeof input.dimension === "number" ? input.dimension : void 0,
149
- metric: text(input.metric),
150
- vector_type: text(input.vectorType),
151
- deletion_protection: text(input.deletionProtection),
152
- tags: record(input.tags),
123
+ metric: trimmedText(input.metric),
124
+ vector_type: trimmedText(input.vectorType),
125
+ deletion_protection: trimmedText(input.deletionProtection),
126
+ tags: asJsonObject(input.tags),
153
127
  spec: {
154
128
  serverless: {
155
129
  cloud: requireText(input.cloud, "cloud"),
@@ -164,11 +138,11 @@ async function configureIndex(input, ctx) {
164
138
  const payload = await request(ctx, {
165
139
  method: "PATCH",
166
140
  path: `/indexes/${encodeURIComponent(requireText(input.name, "name"))}`,
167
- body: compact({
168
- deletion_protection: text(input.deletionProtection),
169
- tags: record(input.tags),
141
+ body: compactDefined({
142
+ deletion_protection: trimmedText(input.deletionProtection),
143
+ tags: asJsonObject(input.tags),
170
144
  // 没给 readCapacity 就整个不发 spec:发一个空 spec 会被 Pinecone 当成"改成空配置"。
171
- spec: input.readCapacity ? { serverless: { read_capacity: record(input.readCapacity) } } : void 0
145
+ spec: input.readCapacity ? { serverless: { read_capacity: asJsonObject(input.readCapacity) } } : void 0
172
146
  })
173
147
  });
174
148
  return { index: requireObject(payload, "Pinecone configure index response") };
@@ -184,7 +158,7 @@ async function getIndexStats(input, ctx) {
184
158
  const payload = await dataRequest(ctx, input.indexHost, {
185
159
  method: "POST",
186
160
  path: "/describe_index_stats",
187
- body: { filter: record(input.filter) }
161
+ body: { filter: asJsonObject(input.filter) }
188
162
  });
189
163
  return { stats: requireObject(payload, "Pinecone index stats response") };
190
164
  }
@@ -193,7 +167,7 @@ async function upsertVectors(input, ctx) {
193
167
  await dataRequest(ctx, input.indexHost, {
194
168
  method: "POST",
195
169
  path: "/vectors/upsert",
196
- body: { vectors: input.vectors, namespace: text(input.namespace) }
170
+ body: { vectors: input.vectors, namespace: trimmedText(input.namespace) }
197
171
  }),
198
172
  "Pinecone upsert response"
199
173
  );
@@ -214,10 +188,10 @@ async function queryVectors(input, ctx) {
214
188
  body: {
215
189
  vector: input.values,
216
190
  sparseVector: input.sparseValues,
217
- id: text(input.id),
191
+ id: trimmedText(input.id),
218
192
  topK: input.topK,
219
- namespace: text(input.namespace),
220
- filter: record(input.filter),
193
+ namespace: trimmedText(input.namespace),
194
+ filter: asJsonObject(input.filter),
221
195
  includeValues: input.includeValues,
222
196
  includeMetadata: input.includeMetadata
223
197
  }
@@ -227,8 +201,8 @@ async function queryVectors(input, ctx) {
227
201
  return {
228
202
  matches: objectArray(payload.matches),
229
203
  // null 与"字段缺席"是两回事:前者是上游明确说"这次没有 namespace"。
230
- namespace: text(payload.namespace) ?? null,
231
- usage: record(payload.usage) ?? null,
204
+ namespace: trimmedText(payload.namespace) ?? null,
205
+ usage: asJsonObject(payload.usage) ?? null,
232
206
  raw: payload
233
207
  };
234
208
  }
@@ -239,16 +213,16 @@ async function fetchVectors(input, ctx) {
239
213
  path: "/vectors/fetch",
240
214
  // fetch 是 GET:ids 展开成重复的同名 query 参数,不进请求体。
241
215
  query: {
242
- namespace: text(input.namespace),
216
+ namespace: trimmedText(input.namespace),
243
217
  ids: Array.isArray(input.ids) ? input.ids.map((id) => String(id)) : []
244
218
  }
245
219
  }),
246
220
  "Pinecone fetch response"
247
221
  );
248
222
  return {
249
- vectors: record(payload.vectors) ?? {},
250
- namespace: text(payload.namespace) ?? null,
251
- usage: record(payload.usage) ?? null,
223
+ vectors: asJsonObject(payload.vectors) ?? {},
224
+ namespace: trimmedText(payload.namespace) ?? null,
225
+ usage: asJsonObject(payload.usage) ?? null,
252
226
  raw: payload
253
227
  };
254
228
  }
@@ -258,10 +232,10 @@ async function listVectorIds(input, ctx) {
258
232
  method: "GET",
259
233
  path: "/vectors/list",
260
234
  query: {
261
- namespace: text(input.namespace),
262
- prefix: text(input.prefix),
235
+ namespace: trimmedText(input.namespace),
236
+ prefix: trimmedText(input.prefix),
263
237
  limit: input.limit === void 0 ? void 0 : String(input.limit),
264
- paginationToken: text(input.paginationToken)
238
+ paginationToken: trimmedText(input.paginationToken)
265
239
  }
266
240
  }),
267
241
  "Pinecone list vectors response"
@@ -269,7 +243,7 @@ async function listVectorIds(input, ctx) {
269
243
  return {
270
244
  vectors: objectArray(payload.vectors),
271
245
  // 翻页靠它:上游没有下一页时给 null,把它压成 undefined 会让调用方分不清"到底了"。
272
- pagination: record(payload.pagination) ?? null,
246
+ pagination: asJsonObject(payload.pagination) ?? null,
273
247
  raw: payload
274
248
  };
275
249
  }
@@ -282,8 +256,8 @@ async function deleteVectors(input, ctx) {
282
256
  path: "/vectors/delete",
283
257
  body: {
284
258
  ids: input.ids,
285
- namespace: text(input.namespace),
286
- filter: record(input.filter),
259
+ namespace: trimmedText(input.namespace),
260
+ filter: asJsonObject(input.filter),
287
261
  deleteAll: input.deleteAll
288
262
  }
289
263
  });
@@ -298,12 +272,12 @@ async function updateVector(input, ctx) {
298
272
  method: "POST",
299
273
  path: "/vectors/update",
300
274
  body: {
301
- id: text(input.id),
275
+ id: trimmedText(input.id),
302
276
  values: input.values,
303
277
  sparseValues: input.sparseValues,
304
- setMetadata: record(input.setMetadata),
305
- namespace: text(input.namespace),
306
- filter: record(input.filter),
278
+ setMetadata: asJsonObject(input.setMetadata),
279
+ namespace: trimmedText(input.namespace),
280
+ filter: asJsonObject(input.filter),
307
281
  dryRun: input.dryRun
308
282
  }
309
283
  }),
@@ -1,17 +1,21 @@
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/pipedrive/schema.ts
17
21
  var listPersonsInput = external_exports.looseObject({}).describe("Input for listing Pipedrive persons.");
@@ -256,6 +260,7 @@ var pipedriveActions = {
256
260
  // ../plugins/src/pipedrive/api.ts
257
261
  var SERVICE = "pipedrive";
258
262
  var API_BASE = "https://api.pipedrive.com";
263
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
259
264
  var OPERATIONS = {
260
265
  list_persons: { method: "GET", path: "/api/v2/persons", listKey: "persons" },
261
266
  get_person: { method: "GET", path: "/api/v2/persons/{id}", idField: "personId", itemKey: "person" },
@@ -300,16 +305,8 @@ var OPERATIONS = {
300
305
  list_stages: { method: "GET", path: "/api/v2/stages", listKey: "stages" },
301
306
  get_stage: { method: "GET", path: "/api/v2/stages/{id}", idField: "stageId", itemKey: "stage" }
302
307
  };
303
- function asRecord(value) {
304
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
305
- }
306
- function optionalText(value) {
307
- if (typeof value !== "string") return void 0;
308
- const trimmed = value.trim();
309
- return trimmed === "" ? void 0 : trimmed;
310
- }
311
308
  function requiredText(value, field) {
312
- const text = optionalText(value);
309
+ const text = trimmedText(value);
313
310
  if (text === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
314
311
  return text;
315
312
  }
@@ -344,55 +341,36 @@ function buildBody(operation, input) {
344
341
  }
345
342
  return body;
346
343
  }
347
- async function readPayload(response) {
348
- const text = await response.text().catch(() => "");
349
- if (text.trim() === "") return null;
350
- try {
351
- return JSON.parse(text);
352
- } catch {
353
- return text;
354
- }
355
- }
356
344
  function errorMessage(payload) {
357
- if (typeof payload === "string") return optionalText(payload);
358
- const record = asRecord(payload);
345
+ if (typeof payload === "string") return trimmedText(payload);
346
+ const record = asJsonObject(payload);
359
347
  if (record === void 0) return void 0;
360
- return optionalText(record.error) ?? optionalText(record.error_info) ?? optionalText(record.message) ?? optionalText(record.statusText);
348
+ return trimmedText(record.error) ?? trimmedText(record.error_info) ?? trimmedText(record.message) ?? trimmedText(record.statusText);
361
349
  }
362
350
  async function request(ctx, operation, input) {
363
351
  const apiKey = requireApiKey(ctx, SERVICE);
364
- const url = new URL(buildPath(operation, input), API_BASE);
365
- if (operation.method === "GET") {
366
- for (const [key, value] of Object.entries(buildQuery(operation, input))) {
367
- if (value !== void 0) url.searchParams.set(key, value);
368
- }
369
- }
370
352
  const hasBody = operation.method === "POST" || operation.method === "PATCH";
371
353
  const headers = {
372
354
  "accept": "application/json",
373
355
  "x-api-token": apiKey
374
356
  };
375
- if (hasBody) headers["content-type"] = "application/json";
376
- let response;
377
- let payload;
378
- try {
379
- response = await guardedFetch(url.toString(), {
380
- method: operation.method,
381
- headers,
382
- ...hasBody ? { body: JSON.stringify(buildBody(operation, input)) } : {}
383
- });
384
- payload = await readPayload(response);
385
- } catch (error) {
386
- if (error instanceof TBError) throw error;
387
- throw upstreamError(502, error instanceof Error ? `pipedrive \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "pipedrive \u8BF7\u6C42\u5931\u8D25");
388
- }
389
- if (!response.ok) {
390
- throw upstreamError(
391
- response.status,
392
- errorMessage(payload) ?? (response.statusText || `pipedrive \u8FD4\u56DE HTTP ${response.status}`)
393
- );
394
- }
395
- const record = payload === null ? {} : asRecord(payload);
357
+ const response = await http.request({
358
+ method: operation.method,
359
+ path: buildPath(operation, input),
360
+ headers,
361
+ ...operation.method === "GET" ? { query: Object.entries(buildQuery(operation, input)) } : {},
362
+ ...hasBody ? { json: buildBody(operation, input) } : {},
363
+ invalidJson: "text",
364
+ mapError: ({ data, status, statusText }) => upstreamError(
365
+ status,
366
+ errorMessage(data) ?? (statusText || `pipedrive \u8FD4\u56DE HTTP ${status}`)
367
+ ),
368
+ mapTransportError: ({ message }) => upstreamError(
369
+ 502,
370
+ message === void 0 ? "pipedrive \u8BF7\u6C42\u5931\u8D25" : `pipedrive \u8BF7\u6C42\u5931\u8D25: ${message}`
371
+ )
372
+ });
373
+ const record = response.bodyKind === "empty" ? {} : asJsonObject(response.data);
396
374
  if (record === void 0) throw upstreamError(502, "pipedrive \u8FD4\u56DE\u7684\u54CD\u5E94\u4E0D\u662F JSON \u5BF9\u8C61");
397
375
  if (record.success === false) {
398
376
  throw upstreamError(502, errorMessage(record) ?? "pipedrive \u62A5\u544A\u4E86\u4E00\u6B21\u5931\u8D25\u7684\u54CD\u5E94");
@@ -400,13 +378,13 @@ async function request(ctx, operation, input) {
400
378
  return record;
401
379
  }
402
380
  function responseRecord(value, field) {
403
- const record = asRecord(value);
381
+ const record = asJsonObject(value);
404
382
  if (record === void 0) throw upstreamError(502, `pipedrive \u54CD\u5E94\u7684 ${field} \u4E0D\u662F\u5BF9\u8C61`);
405
383
  return record;
406
384
  }
407
385
  function nextCursor(envelope) {
408
- const pagination = asRecord(asRecord(envelope.additional_data)?.pagination);
409
- return optionalText(pagination?.next_cursor) ?? null;
386
+ const pagination = asJsonObject(asJsonObject(envelope.additional_data)?.pagination);
387
+ return trimmedText(pagination?.next_cursor) ?? null;
410
388
  }
411
389
  function shapeOutput(envelope, operation) {
412
390
  const data = envelope.data;
@@ -420,7 +398,7 @@ function shapeOutput(envelope, operation) {
420
398
  const searchData = responseRecord(data, "data");
421
399
  return { items: Array.isArray(searchData.items) ? searchData.items : [], nextCursor: nextCursor(envelope) };
422
400
  }
423
- const deleted = asRecord(data);
401
+ const deleted = asJsonObject(data);
424
402
  const id = deleted?.id;
425
403
  return {
426
404
  // id 通常是整数;不是整数时如实透出原值,而不是伪造成 null —— 调用方要能看见上游给了什么。
@@ -1,111 +1,101 @@
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/polar/api.ts
17
21
  var SERVICE = "polar";
18
22
  var API_BASE = "https://api.polar.sh/v1";
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 requireRecord(value, label) {
28
- const result = record(value);
25
+ const result = asJsonObject(value);
29
26
  if (result === void 0) throw new TBError("unavailable", `Polar \u7684${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
30
27
  return result;
31
28
  }
32
29
  function requireId(value, field) {
33
- const id = text(value);
30
+ const id = trimmedText(value);
34
31
  if (id === void 0) throw new TBError("invalid_argument", `${field} \u662F\u5FC5\u586B\u7684`);
35
32
  return encodeURIComponent(id);
36
33
  }
37
- function appendQueryValue(url, key, value) {
34
+ function appendQueryValue(query, key, value) {
38
35
  if (value === void 0 || value === null) return;
39
36
  if (Array.isArray(value)) {
40
- for (const child of value) appendQueryValue(url, key, child);
37
+ for (const child of value) appendQueryValue(query, key, child);
41
38
  return;
42
39
  }
43
40
  if (typeof value === "boolean") {
44
- url.searchParams.append(key, value ? "true" : "false");
41
+ query.push([key, value ? "true" : "false"]);
45
42
  return;
46
43
  }
47
44
  if (typeof value === "number") {
48
- url.searchParams.append(key, String(value));
45
+ query.push([key, String(value)]);
49
46
  return;
50
47
  }
51
- const stringValue = text(value);
52
- if (stringValue !== void 0) url.searchParams.append(key, stringValue);
48
+ const stringValue = trimmedText(value);
49
+ if (stringValue !== void 0) query.push([key, stringValue]);
53
50
  }
54
- function listUrl(path, input) {
55
- const url = new URL(`${API_BASE}${path}`);
51
+ function listQuery(input) {
52
+ const query = [];
56
53
  for (const [key, value] of Object.entries(input)) {
57
54
  if (key === "metadata") {
58
- const metadata = record(value);
55
+ const metadata = asJsonObject(value);
59
56
  if (metadata !== void 0) {
60
- for (const [name, child] of Object.entries(metadata)) appendQueryValue(url, `metadata[${name}]`, child);
57
+ for (const [name, child] of Object.entries(metadata)) appendQueryValue(query, `metadata[${name}]`, child);
61
58
  }
62
59
  continue;
63
60
  }
64
- appendQueryValue(url, key, value);
61
+ appendQueryValue(query, key, value);
65
62
  }
66
- return url.toString();
63
+ return query;
67
64
  }
68
65
  function errorDetail(payload) {
69
- const body = record(payload);
66
+ const body = asJsonObject(payload);
70
67
  if (body === void 0) return void 0;
71
68
  const detail = body.detail;
72
- const detailText = text(detail);
69
+ const detailText = trimmedText(detail);
73
70
  if (detailText !== void 0) return detailText;
74
71
  if (Array.isArray(detail)) {
75
- const message = text(record(detail[0])?.msg);
72
+ const message = trimmedText(asJsonObject(detail[0])?.msg);
76
73
  if (message !== void 0) return message;
77
74
  }
78
- return text(body.message) ?? text(body.error) ?? text(body.title);
75
+ return trimmedText(body.message) ?? trimmedText(body.error) ?? trimmedText(body.title);
79
76
  }
80
- async function request(ctx, url) {
81
- const response = await guardedFetch(url, {
77
+ async function request(ctx, path, query) {
78
+ const { data } = await http.request({
79
+ path,
82
80
  method: "GET",
81
+ query,
83
82
  headers: {
84
83
  accept: "application/json",
85
84
  authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
86
- }
85
+ },
86
+ invalidJsonMessage: "Polar \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
87
+ mapError: ({ data: payload, status }) => upstreamError(
88
+ status,
89
+ errorDetail(payload) ?? `Polar \u8FD4\u56DE HTTP ${status}`
90
+ )
87
91
  });
88
- const body = await response.text();
89
- let payload = null;
90
- if (body.trim() !== "") {
91
- try {
92
- payload = JSON.parse(body);
93
- } catch {
94
- if (response.ok) {
95
- throw new TBError("unavailable", "Polar \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
96
- }
97
- }
98
- }
99
- if (!response.ok) {
100
- throw upstreamError(response.status, errorDetail(payload) ?? `Polar \u8FD4\u56DE HTTP ${response.status}`);
101
- }
102
- return payload;
92
+ return data ?? null;
103
93
  }
104
94
  async function listResources(path, input, ctx) {
105
- return requireRecord(await request(ctx, listUrl(path, input)), "\u5217\u8868\u54CD\u5E94");
95
+ return requireRecord(await request(ctx, path, listQuery(input)), "\u5217\u8868\u54CD\u5E94");
106
96
  }
107
97
  async function getResource(path, ctx) {
108
- return { payload: requireRecord(await request(ctx, `${API_BASE}${path}`), "\u8D44\u6E90\u54CD\u5E94") };
98
+ return { payload: requireRecord(await request(ctx, path), "\u8D44\u6E90\u54CD\u5E94") };
109
99
  }
110
100
  function listOrganizations(input, ctx) {
111
101
  return listResources("/organizations/", input, ctx);