@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,43 +1,37 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined,
7
+ integerValue,
8
+ trimmedText
9
+ } from "./chunk-JXHMDBAY.js";
1
10
  import {
2
11
  createProviderPlugin,
3
12
  requireApiKey,
4
13
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
14
+ } from "./chunk-YASUMV2K.js";
6
15
  import {
7
- assertPublicHttpUrl,
8
- guardedFetch
9
- } from "./chunk-2O27H4Y2.js";
10
- import "./chunk-GKX72JMJ.js";
16
+ assertPublicHttpUrl
17
+ } from "./chunk-U5UHT7CX.js";
11
18
  import {
12
19
  TBError,
13
20
  external_exports
14
- } from "./chunk-YB2FLNWI.js";
15
- import "./chunk-MLKGABMK.js";
21
+ } from "./chunk-RVWZN3CI.js";
22
+ import "./chunk-U67V476Y.js";
16
23
 
17
24
  // ../plugins/src/outline/api.ts
18
25
  var SERVICE = "outline";
19
26
  var CLOUD_API_BASE = "https://app.getoutline.com/api";
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
- }
27
+ var http = createProviderHttpClient({ service: SERVICE });
28
28
  function nullableText(value) {
29
- return value === null ? null : text(value);
29
+ return value === null ? null : trimmedText(value);
30
30
  }
31
31
  function nullableBoolean(value) {
32
32
  if (value === null) return null;
33
33
  return typeof value === "boolean" ? value : void 0;
34
34
  }
35
- function integer(value) {
36
- return typeof value === "number" && Number.isInteger(value) ? value : void 0;
37
- }
38
- function compact(input) {
39
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
40
- }
41
35
  function responseError(message) {
42
36
  return new TBError("unavailable", message, { retryable: true });
43
37
  }
@@ -49,7 +43,7 @@ function resolveApiBase(ctx) {
49
43
  if (configured !== void 0 && typeof configured !== "string") {
50
44
  throw configError("\u5FC5\u987B\u662F\u5B57\u7B26\u4E32");
51
45
  }
52
- const candidate = text(configured) ?? CLOUD_API_BASE;
46
+ const candidate = trimmedText(configured) ?? CLOUD_API_BASE;
53
47
  let url;
54
48
  try {
55
49
  url = assertPublicHttpUrl(candidate);
@@ -67,50 +61,41 @@ function resolveApiBase(ctx) {
67
61
  return normalized.endsWith("/api") ? normalized : `${normalized}/api`;
68
62
  }
69
63
  function errorMessage(status, payload) {
70
- const body = record(payload);
71
- return text(body?.message) ?? text(body?.error) ?? text(body?.status) ?? `outline request failed with status ${status}`;
64
+ const body = asJsonObject(payload);
65
+ return trimmedText(body?.message) ?? trimmedText(body?.error) ?? trimmedText(body?.status) ?? `outline request failed with status ${status}`;
66
+ }
67
+ function errorPayload(data, bodyKind) {
68
+ return bodyKind === "invalid-json" && typeof data === "string" ? { message: data.trim() } : data;
72
69
  }
73
70
  async function request(ctx, path, body = {}) {
74
71
  const apiKey = requireApiKey(ctx, SERVICE);
75
- const apiBase = resolveApiBase(ctx);
76
- let response;
77
- try {
78
- response = await guardedFetch(`${apiBase}/${path}`, {
79
- method: "POST",
80
- headers: {
81
- "accept": "application/json",
82
- "authorization": `Bearer ${apiKey}`,
83
- "content-type": "application/json"
84
- },
85
- body: JSON.stringify(body)
86
- });
87
- } catch (error) {
88
- if (error instanceof TBError) throw error;
89
- const message = error instanceof Error ? error.message : "unknown network error";
90
- throw upstreamError(502, `outline ${path} failed before receiving response: ${message}`);
91
- }
92
- const raw = await response.text().catch(() => "");
93
- let payload = null;
94
- if (raw.trim() !== "") {
95
- try {
96
- payload = JSON.parse(raw);
97
- } catch {
98
- if (response.ok) throw responseError("outline \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
99
- payload = { message: raw.trim() };
100
- }
101
- }
102
- if (!response.ok) throw upstreamError(response.status, errorMessage(response.status, payload));
103
- return payload;
72
+ const result = await http.request({
73
+ baseUrl: `${resolveApiBase(ctx)}/`,
74
+ path,
75
+ method: "POST",
76
+ headers: { accept: "application/json", authorization: `Bearer ${apiKey}` },
77
+ json: body,
78
+ invalidJsonMessage: "outline \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
79
+ mapError: ({ bodyKind, data, status }) => upstreamError(
80
+ status,
81
+ errorMessage(status, errorPayload(data, bodyKind))
82
+ ),
83
+ mapTransportError: ({ message }) => upstreamError(
84
+ 502,
85
+ `outline ${path} failed before receiving response: ${message ?? "unknown network error"}`
86
+ )
87
+ });
88
+ return result.data === void 0 ? null : result.data;
104
89
  }
105
90
  function readData(payload) {
106
- const body = record(payload);
91
+ const body = asJsonObject(payload);
107
92
  if (body === void 0 || !("data" in body)) {
108
93
  throw responseError("outline \u54CD\u5E94\u91CC\u6CA1\u6709 data");
109
94
  }
110
95
  return body.data;
111
96
  }
112
97
  function requireObject(value, label) {
113
- const result = record(value);
98
+ const result = asJsonObject(value);
114
99
  if (result === void 0) throw responseError(`outline ${label} \u4E0D\u662F\u5BF9\u8C61`);
115
100
  return result;
116
101
  }
@@ -119,30 +104,30 @@ function requireObjectArray(value, label) {
119
104
  return value.map((item, index) => requireObject(item, `${label}[${index}]`));
120
105
  }
121
106
  function requireText(value, label) {
122
- const result = text(value);
107
+ const result = trimmedText(value);
123
108
  if (result === void 0) throw responseError(`outline \u54CD\u5E94\u91CC\u6CA1\u6709 ${label}`);
124
109
  return result;
125
110
  }
126
111
  function requireInputText(value, field) {
127
- const result = text(value);
112
+ const result = trimmedText(value);
128
113
  if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
129
114
  return result;
130
115
  }
131
116
  function statusFilter(value) {
132
117
  if (!Array.isArray(value)) return void 0;
133
- const items = value.map((item) => text(item)).filter((item) => item !== void 0);
118
+ const items = value.map((item) => trimmedText(item)).filter((item) => item !== void 0);
134
119
  return items.length > 0 ? items : void 0;
135
120
  }
136
121
  function normalizeSort(value) {
137
- const sort = record(value);
122
+ const sort = asJsonObject(value);
138
123
  if (sort === void 0) return void 0;
139
- const field = text(sort.field);
140
- const direction = text(sort.direction);
124
+ const field = trimmedText(sort.field);
125
+ const direction = trimmedText(sort.direction);
141
126
  if (field === void 0 || direction === void 0) return void 0;
142
127
  return { field, direction };
143
128
  }
144
129
  function normalizeCollection(input) {
145
- return compact({
130
+ return compactDefined({
146
131
  id: requireText(input.id, "collection.id"),
147
132
  urlId: nullableText(input.urlId),
148
133
  name: requireText(input.name, "collection.name"),
@@ -162,12 +147,12 @@ function normalizeCollection(input) {
162
147
  });
163
148
  }
164
149
  function normalizeUser(value) {
165
- const user = record(value);
150
+ const user = asJsonObject(value);
166
151
  if (user === void 0) return void 0;
167
- const id = text(user.id);
168
- const name = text(user.name);
152
+ const id = trimmedText(user.id);
153
+ const name = trimmedText(user.name);
169
154
  if (id === void 0 && name === void 0) return void 0;
170
- return compact({
155
+ return compactDefined({
171
156
  id,
172
157
  name,
173
158
  avatarUrl: nullableText(user.avatarUrl),
@@ -180,14 +165,14 @@ function normalizeUser(value) {
180
165
  }
181
166
  function normalizeDataAttributes(value) {
182
167
  if (!Array.isArray(value)) return void 0;
183
- return value.map((item) => record(item)).filter((item) => item !== void 0).map((item) => compact({
168
+ return value.map((item) => asJsonObject(item)).filter((item) => item !== void 0).map((item) => compactDefined({
184
169
  dataAttributeId: requireText(item.dataAttributeId, "document.dataAttributes[].dataAttributeId"),
185
170
  value: item.value,
186
171
  updatedAt: nullableText(item.updatedAt)
187
172
  }));
188
173
  }
189
174
  function normalizeDocument(input) {
190
- return compact({
175
+ return compactDefined({
191
176
  id: requireText(input.id, "document.id"),
192
177
  collectionId: nullableText(input.collectionId),
193
178
  parentDocumentId: nullableText(input.parentDocumentId),
@@ -198,7 +183,7 @@ function normalizeDocument(input) {
198
183
  urlId: nullableText(input.urlId),
199
184
  pinned: nullableBoolean(input.pinned),
200
185
  templateId: nullableText(input.templateId),
201
- revision: integer(input.revision),
186
+ revision: integerValue(input.revision),
202
187
  createdAt: nullableText(input.createdAt),
203
188
  createdBy: normalizeUser(input.createdBy),
204
189
  updatedAt: nullableText(input.updatedAt),
@@ -211,10 +196,10 @@ function normalizeDocument(input) {
211
196
  });
212
197
  }
213
198
  function normalizePagination(payload) {
214
- const pagination = record(record(payload)?.pagination);
199
+ const pagination = asJsonObject(asJsonObject(payload)?.pagination);
215
200
  return {
216
- offset: integer(pagination?.offset) ?? 0,
217
- limit: integer(pagination?.limit) ?? 0
201
+ offset: integerValue(pagination?.offset) ?? 0,
202
+ limit: integerValue(pagination?.limit) ?? 0
218
203
  };
219
204
  }
220
205
  function normalizeNavigationNode(input, label) {
@@ -222,17 +207,17 @@ function normalizeNavigationNode(input, label) {
222
207
  id: requireText(input.id, `${label}.id`),
223
208
  title: requireText(input.title, `${label}.title`),
224
209
  url: requireText(input.url, `${label}.url`),
225
- children: Array.isArray(input.children) ? input.children.map((child) => record(child)).filter((child) => child !== void 0).map((child) => normalizeNavigationNode(child, `${label}.children[]`)) : []
210
+ children: Array.isArray(input.children) ? input.children.map((child) => asJsonObject(child)).filter((child) => child !== void 0).map((child) => normalizeNavigationNode(child, `${label}.children[]`)) : []
226
211
  };
227
212
  }
228
213
  async function listCollections(input, ctx) {
229
- const payload = await request(ctx, "collections.list", compact({
230
- query: text(input.query),
214
+ const payload = await request(ctx, "collections.list", compactDefined({
215
+ query: trimmedText(input.query),
231
216
  statusFilter: statusFilter(input.statusFilter),
232
- sort: text(input.sort),
233
- direction: text(input.direction),
234
- offset: integer(input.offset),
235
- limit: integer(input.limit)
217
+ sort: trimmedText(input.sort),
218
+ direction: trimmedText(input.direction),
219
+ offset: integerValue(input.offset),
220
+ limit: integerValue(input.limit)
236
221
  }));
237
222
  return {
238
223
  collections: requireObjectArray(readData(payload), "collections.list.data").map(normalizeCollection),
@@ -250,15 +235,15 @@ async function listCollectionDocuments(input, ctx) {
250
235
  };
251
236
  }
252
237
  async function listDocuments(input, ctx) {
253
- const payload = await request(ctx, "documents.list", compact({
254
- offset: integer(input.offset),
255
- limit: integer(input.limit),
256
- sort: text(input.sort),
257
- direction: text(input.direction),
258
- collectionId: text(input.collectionId),
259
- userId: text(input.userId),
260
- backlinkDocumentId: text(input.backlinkDocumentId),
261
- parentDocumentId: text(input.parentDocumentId),
238
+ const payload = await request(ctx, "documents.list", compactDefined({
239
+ offset: integerValue(input.offset),
240
+ limit: integerValue(input.limit),
241
+ sort: trimmedText(input.sort),
242
+ direction: trimmedText(input.direction),
243
+ collectionId: trimmedText(input.collectionId),
244
+ userId: trimmedText(input.userId),
245
+ backlinkDocumentId: trimmedText(input.backlinkDocumentId),
246
+ parentDocumentId: trimmedText(input.parentDocumentId),
262
247
  statusFilter: statusFilter(input.statusFilter)
263
248
  }));
264
249
  return {
@@ -267,20 +252,20 @@ async function listDocuments(input, ctx) {
267
252
  };
268
253
  }
269
254
  async function searchDocuments(input, ctx) {
270
- const payload = await request(ctx, "documents.search", compact({
255
+ const payload = await request(ctx, "documents.search", compactDefined({
271
256
  query: requireInputText(input.query, "query"),
272
- offset: integer(input.offset),
273
- limit: integer(input.limit),
274
- userId: text(input.userId),
275
- collectionId: text(input.collectionId),
276
- documentId: text(input.documentId),
257
+ offset: integerValue(input.offset),
258
+ limit: integerValue(input.limit),
259
+ userId: trimmedText(input.userId),
260
+ collectionId: trimmedText(input.collectionId),
261
+ documentId: trimmedText(input.documentId),
277
262
  statusFilter: statusFilter(input.statusFilter),
278
- dateFilter: text(input.dateFilter),
279
- shareId: text(input.shareId),
280
- snippetMinWords: integer(input.snippetMinWords),
281
- snippetMaxWords: integer(input.snippetMaxWords),
282
- sort: text(input.sort),
283
- direction: text(input.direction)
263
+ dateFilter: trimmedText(input.dateFilter),
264
+ shareId: trimmedText(input.shareId),
265
+ snippetMinWords: integerValue(input.snippetMinWords),
266
+ snippetMaxWords: integerValue(input.snippetMaxWords),
267
+ sort: trimmedText(input.sort),
268
+ direction: trimmedText(input.direction)
284
269
  }));
285
270
  return {
286
271
  documents: requireObjectArray(readData(payload), "documents.search.data").map(normalizeDocument),
@@ -288,12 +273,12 @@ async function searchDocuments(input, ctx) {
288
273
  };
289
274
  }
290
275
  async function getDocument(input, ctx) {
291
- const id = text(input.id);
292
- const shareId = text(input.shareId);
276
+ const id = trimmedText(input.id);
277
+ const shareId = trimmedText(input.shareId);
293
278
  if (id === void 0 && shareId === void 0) {
294
279
  throw new TBError("invalid_argument", "Provide at least one of id or shareId.");
295
280
  }
296
- const payload = await request(ctx, "documents.info", compact({ id, shareId }));
281
+ const payload = await request(ctx, "documents.info", compactDefined({ id, shareId }));
297
282
  return { document: normalizeDocument(requireObject(readData(payload), "documents.info.data")) };
298
283
  }
299
284
 
@@ -1,87 +1,72 @@
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/paddle/api.ts
17
21
  var SERVICE = "paddle";
18
22
  var API_BASE = "https://api.paddle.com";
19
- function toRecord(value) {
20
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
21
- }
22
- function text(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 pathSegment(value, field) {
28
25
  if (value === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
29
26
  return encodeURIComponent(value);
30
27
  }
31
28
  function setOptional(params, key, value) {
32
- const stringValue = typeof value === "boolean" || typeof value === "number" ? String(value) : text(value);
29
+ const stringValue = typeof value === "boolean" || typeof value === "number" ? String(value) : trimmedText(value);
33
30
  if (stringValue !== void 0) params.set(key, stringValue);
34
31
  }
35
32
  function setJoined(params, key, value) {
36
33
  if (value === void 0 || value.length === 0) return;
37
34
  params.set(key, value.map(String).join(","));
38
35
  }
39
- async function readPayload(response) {
40
- const body = await response.text().catch(() => "");
41
- if (body.trim() === "") return null;
42
- try {
43
- return JSON.parse(body);
44
- } catch {
45
- if (response.ok) throw upstreamError(502, "Paddle returned malformed JSON");
46
- return body;
47
- }
48
- }
49
- function errorMessage(payload, response) {
50
- const data = toRecord(payload);
36
+ function errorMessage(payload, context) {
37
+ const data = asJsonObject(payload);
51
38
  if (data === void 0) {
52
- return typeof payload === "string" && payload !== "" ? payload : response.statusText || `Paddle \u8FD4\u56DE HTTP ${response.status}`;
39
+ return typeof payload === "string" && payload !== "" ? payload : context.statusText || `Paddle \u8FD4\u56DE HTTP ${context.status}`;
53
40
  }
54
- const error = toRecord(data.error);
55
- const message = text(error?.detail) ?? text(error?.message) ?? text(data.message) ?? text(data.error);
56
- return message ?? (response.statusText || `Paddle \u8FD4\u56DE HTTP ${response.status}`);
41
+ const error = asJsonObject(data.error);
42
+ const message = trimmedText(error?.detail) ?? trimmedText(error?.message) ?? trimmedText(data.message) ?? trimmedText(data.error);
43
+ return message ?? (context.statusText || `Paddle \u8FD4\u56DE HTTP ${context.status}`);
57
44
  }
58
45
  async function request(ctx, input) {
59
- const url = new URL(input.path, API_BASE);
60
- for (const [key, value] of input.searchParams ?? []) url.searchParams.set(key, value);
61
- const headers = {
62
- accept: "application/json",
63
- authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
64
- };
65
- if (input.body !== void 0) headers["content-type"] = "application/json";
66
- if (input.skipCount === true) headers["skip-count"] = "true";
67
- const response = await guardedFetch(url.toString(), {
46
+ const result = await http.request({
47
+ path: input.path,
68
48
  method: input.method,
69
- headers,
70
- ...input.body === void 0 ? {} : { body: JSON.stringify(input.body) }
49
+ query: [...input.searchParams ?? []],
50
+ headers: {
51
+ accept: "application/json",
52
+ authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`,
53
+ ...input.skipCount === true ? { "skip-count": "true" } : {}
54
+ },
55
+ ...input.body === void 0 ? {} : { json: input.body },
56
+ invalidJsonMessage: "Paddle returned malformed JSON",
57
+ mapError: (context) => upstreamError(context.status, errorMessage(context.data, context))
71
58
  });
72
- const payload = await readPayload(response);
73
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response));
74
- return payload;
59
+ return result.data === void 0 ? null : result.data;
75
60
  }
76
61
  function readMeta(payload) {
77
- return toRecord(toRecord(payload)?.meta) ?? {};
62
+ return asJsonObject(asJsonObject(payload)?.meta) ?? {};
78
63
  }
79
64
  function listResult(payload) {
80
- const data = toRecord(payload)?.data;
65
+ const data = asJsonObject(payload)?.data;
81
66
  return { data: Array.isArray(data) ? data : [], meta: readMeta(payload) };
82
67
  }
83
68
  function entityResult(key, payload) {
84
- return { [key]: toRecord(toRecord(payload)?.data) ?? null, meta: readMeta(payload) };
69
+ return { [key]: asJsonObject(asJsonObject(payload)?.data) ?? null, meta: readMeta(payload) };
85
70
  }
86
71
  function paginationParams(input) {
87
72
  const params = new URLSearchParams();
@@ -1,70 +1,53 @@
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/perplexity/api.ts
17
21
  var SERVICE = "perplexity";
18
22
  var API_BASE = "https://api.perplexity.ai";
23
+ var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
19
24
  var EMBEDDING_MIN_DIMENSIONS = 128;
20
25
  var EMBEDDING_MAX_DIMENSIONS = { "pplx-embed-v1-0.6b": 1024 };
21
26
  var EMBEDDING_MAX_DIMENSIONS_FALLBACK = 2560;
22
- function record(value) {
23
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
24
- }
25
- function text(value) {
26
- if (typeof value !== "string") return void 0;
27
- const trimmed = value.trim();
28
- return trimmed === "" ? void 0 : trimmed;
29
- }
30
- function errorMessage(status, body, payload) {
31
- const top = record(payload);
32
- const nested = record(top?.error);
33
- return text(nested?.message) ?? text(nested?.detail) ?? text(top?.message) ?? text(top?.detail) ?? text(body) ?? `perplexity request failed with ${status}`;
27
+ function errorMessage(status, payload, bodyKind) {
28
+ const top = asJsonObject(payload);
29
+ const nested = asJsonObject(top?.error);
30
+ return trimmedText(nested?.message) ?? trimmedText(nested?.detail) ?? trimmedText(top?.message) ?? trimmedText(top?.detail) ?? (bodyKind === "invalid-json" || bodyKind === "text" ? trimmedText(payload) : void 0) ?? `perplexity request failed with ${status}`;
34
31
  }
35
32
  async function request(ctx, method, path, body) {
36
33
  const apiKey = requireApiKey(ctx, SERVICE);
37
- const headers = {
38
- accept: "application/json",
39
- authorization: `Bearer ${apiKey}`
40
- };
41
- if (method === "POST") headers["content-type"] = "application/json";
42
- let response;
43
- try {
44
- response = await guardedFetch(`${API_BASE}${path}`, {
45
- method,
46
- headers,
47
- // 上游先过一道 `compactObject`;JSON.stringify 本来就丢 undefined 值,故不再重复一遍。
48
- body: method === "POST" ? JSON.stringify(body ?? {}) : void 0
49
- });
50
- } catch (error) {
51
- if (error instanceof TBError) throw error;
52
- const message = error instanceof Error ? error.message : "unknown network error";
53
- throw upstreamError(502, `perplexity ${method} ${path} failed before receiving response: ${message}`);
54
- }
55
- const raw = await response.text();
56
- let payload = null;
57
- if (raw !== "") {
58
- try {
59
- payload = JSON.parse(raw);
60
- } catch {
61
- if (response.ok) {
62
- throw new TBError("unavailable", "Perplexity \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
63
- }
64
- }
65
- }
66
- if (!response.ok) throw upstreamError(response.status, errorMessage(response.status, raw, payload));
67
- return payload;
34
+ const { data } = await http.request({
35
+ path,
36
+ method,
37
+ headers: { accept: "application/json", authorization: `Bearer ${apiKey}` },
38
+ // 上游先过一道 `compactObject`;JSON.stringify 本来就丢 undefined 值,故不再重复一遍。
39
+ ...method === "POST" ? { json: body ?? {} } : {},
40
+ invalidJsonMessage: "Perplexity \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
41
+ mapError: ({ bodyKind, data: payload, status }) => upstreamError(
42
+ status,
43
+ errorMessage(status, payload, bodyKind)
44
+ ),
45
+ mapTransportError: ({ message }) => upstreamError(
46
+ 502,
47
+ `perplexity ${method} ${path} failed before receiving response: ${message ?? "unknown network error"}`
48
+ )
49
+ });
50
+ return data ?? null;
68
51
  }
69
52
  function assertStreamingDisabled(input) {
70
53
  if (input.stream === true) {