@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,46 +1,40 @@
1
+ import {
2
+ bytesToBase64
3
+ } from "./chunk-LMLX3DJF.js";
4
+ import {
5
+ createProviderHttpClient
6
+ } from "./chunk-WW2IMPQK.js";
7
+ import {
8
+ asJsonObject,
9
+ booleanValue,
10
+ compactDefined,
11
+ finiteNumber,
12
+ trimmedText
13
+ } from "./chunk-JXHMDBAY.js";
1
14
  import {
2
15
  createProviderPlugin,
3
16
  requireApiKey,
4
17
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
18
+ } from "./chunk-YASUMV2K.js";
6
19
  import {
7
20
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
21
+ } from "./chunk-U5UHT7CX.js";
10
22
  import {
11
23
  TBError,
12
24
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
25
+ } from "./chunk-RVWZN3CI.js";
26
+ import "./chunk-U67V476Y.js";
15
27
 
16
28
  // ../plugins/src/dropbox/api.ts
17
29
  var SERVICE = "dropbox";
18
30
  var API_BASE = "https://api.dropboxapi.com/2";
19
31
  var CONTENT_BASE = "https://content.dropboxapi.com/2";
32
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
20
33
  var MAX_SIMPLE_UPLOAD_BYTES = 150 * 1024 * 1024;
21
34
  var DEFAULT_MIME_TYPE = "application/octet-stream";
22
- function text(value) {
23
- if (typeof value !== "string") return void 0;
24
- const trimmed = value.trim();
25
- return trimmed === "" ? void 0 : trimmed;
26
- }
27
- function bool(value) {
28
- return typeof value === "boolean" ? value : void 0;
29
- }
30
- function num(value) {
31
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
32
- }
33
- function record(value) {
34
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
35
- }
36
- function compact(input) {
37
- return Object.fromEntries(
38
- Object.entries(input).filter(([, value]) => value !== void 0)
39
- );
40
- }
41
35
  function objectArray(value) {
42
36
  if (!Array.isArray(value)) return [];
43
- return value.map((item) => record(item)).filter((item) => item !== void 0);
37
+ return value.map((item) => asJsonObject(item)).filter((item) => item !== void 0);
44
38
  }
45
39
  function stringArray(value) {
46
40
  if (!Array.isArray(value)) return void 0;
@@ -51,28 +45,20 @@ function contractError(label) {
51
45
  return new TBError("unavailable", `Dropbox \u54CD\u5E94\u7F3A\u5C11 ${label}`, { retryable: true });
52
46
  }
53
47
  function requiredText(value, label) {
54
- const result = text(value);
48
+ const result = trimmedText(value);
55
49
  if (result === void 0) throw contractError(label);
56
50
  return result;
57
51
  }
58
52
  function requiredRecord(value, label) {
59
- const result = record(value);
53
+ const result = asJsonObject(value);
60
54
  if (result === void 0) throw contractError(label);
61
55
  return result;
62
56
  }
63
57
  function required(value, field) {
64
- const result = text(value);
58
+ const result = trimmedText(value);
65
59
  if (result === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
66
60
  return result;
67
61
  }
68
- function bytesToBase64(bytes) {
69
- let binary = "";
70
- const chunk = 32768;
71
- for (let index = 0; index < bytes.length; index += chunk) {
72
- binary += String.fromCharCode(...bytes.subarray(index, index + chunk));
73
- }
74
- return btoa(binary);
75
- }
76
62
  function base64ToBytes(value) {
77
63
  let binary;
78
64
  try {
@@ -106,37 +92,44 @@ async function readError(response, fallback) {
106
92
  }
107
93
  let payload;
108
94
  try {
109
- payload = record(JSON.parse(await response.text()));
95
+ payload = asJsonObject(JSON.parse(await response.text()));
110
96
  } catch {
111
97
  payload = void 0;
112
98
  }
113
- const summary = text(payload?.error_summary);
114
- const tag = text(record(payload?.error)?.[".tag"]);
99
+ const summary = trimmedText(payload?.error_summary);
100
+ const tag = trimmedText(asJsonObject(payload?.error)?.[".tag"]);
115
101
  const message = summary === void 0 ? tag ?? fallback : trimSummary(summary);
116
102
  return dropboxError(response.status, summary ?? tag, message);
117
103
  }
118
104
  function authHeader(ctx) {
119
105
  return `Bearer ${requireApiKey(ctx, SERVICE)}`;
120
106
  }
107
+ function rpcError(context, fallback) {
108
+ if (!context.headers.get("content-type")?.includes("application/json")) {
109
+ const raw = context.rawText?.trim();
110
+ return dropboxError(context.status, void 0, raw === void 0 || raw === "" ? fallback : raw);
111
+ }
112
+ const payload = asJsonObject(context.data);
113
+ const summary = trimmedText(payload?.error_summary);
114
+ const tag = trimmedText(asJsonObject(payload?.error)?.[".tag"]);
115
+ const message = summary === void 0 ? tag ?? fallback : trimSummary(summary);
116
+ return dropboxError(context.status, summary ?? tag, message);
117
+ }
121
118
  async function rpc(ctx, route, options = {}) {
122
119
  const hasBody = options.body !== void 0;
123
- const response = await guardedFetch(`${API_BASE}/${route}`, {
120
+ const result = await http.request({
121
+ path: route,
124
122
  method: "POST",
125
- headers: hasBody ? { "authorization": authHeader(ctx), "content-type": "application/json" } : { authorization: authHeader(ctx) },
126
- body: hasBody ? JSON.stringify(options.body) : void 0
123
+ headers: { authorization: authHeader(ctx) },
124
+ ...hasBody ? { json: options.body } : {},
125
+ invalidJsonMessage: "Dropbox \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
126
+ mapError: (context) => rpcError(context, `Dropbox ${route} \u8C03\u7528\u5931\u8D25`)
127
127
  });
128
- if (!response.ok) throw await readError(response, `Dropbox ${route} \u8C03\u7528\u5931\u8D25`);
129
- const raw = await response.text();
130
- if (raw.trim() === "") {
128
+ if (result.bodyKind === "empty") {
131
129
  if (options.allowEmptyResponse === true) return {};
132
130
  throw new TBError("unavailable", `Dropbox ${route} \u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94`, { retryable: true });
133
131
  }
134
- let parsed;
135
- try {
136
- parsed = JSON.parse(raw);
137
- } catch {
138
- throw new TBError("unavailable", "Dropbox \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
139
- }
132
+ const parsed = result.data;
140
133
  if (parsed === null) return {};
141
134
  return requiredRecord(parsed, `${route} \u54CD\u5E94`);
142
135
  }
@@ -166,9 +159,9 @@ async function downloadContent(ctx, route, arg, fallbackMessage) {
166
159
  };
167
160
  }
168
161
  function metadataTag(item) {
169
- const explicit = text(item[".tag"]);
162
+ const explicit = trimmedText(item[".tag"]);
170
163
  if (explicit !== void 0) return explicit;
171
- if (bool(item.is_downloadable) !== void 0 || text(item.rev) !== void 0 || text(item.content_hash) !== void 0 || num(item.size) !== void 0) {
164
+ if (booleanValue(item.is_downloadable) !== void 0 || trimmedText(item.rev) !== void 0 || trimmedText(item.content_hash) !== void 0 || finiteNumber(item.size) !== void 0) {
172
165
  return "file";
173
166
  }
174
167
  return "unknown";
@@ -178,52 +171,52 @@ function mapMetadata(value) {
178
171
  return {
179
172
  tag: metadataTag(item),
180
173
  // 名字缺失时给空串而不是 null:出参契约里 name 是必填 string。
181
- name: text(item.name) ?? "",
182
- id: text(item.id) ?? null,
183
- pathDisplay: text(item.path_display) ?? null,
184
- pathLower: text(item.path_lower) ?? null,
185
- clientModified: text(item.client_modified) ?? null,
186
- serverModified: text(item.server_modified) ?? null,
187
- rev: text(item.rev) ?? null,
188
- sizeBytes: num(item.size) ?? null,
189
- isDownloadable: bool(item.is_downloadable) ?? null,
190
- contentHash: text(item.content_hash) ?? null,
191
- url: text(item.url) ?? null,
192
- expiresAt: text(item.expires) ?? null,
193
- sharingInfo: record(item.sharing_info) ?? null,
194
- linkPermissions: record(item.link_permissions) ?? null
174
+ name: trimmedText(item.name) ?? "",
175
+ id: trimmedText(item.id) ?? null,
176
+ pathDisplay: trimmedText(item.path_display) ?? null,
177
+ pathLower: trimmedText(item.path_lower) ?? null,
178
+ clientModified: trimmedText(item.client_modified) ?? null,
179
+ serverModified: trimmedText(item.server_modified) ?? null,
180
+ rev: trimmedText(item.rev) ?? null,
181
+ sizeBytes: finiteNumber(item.size) ?? null,
182
+ isDownloadable: booleanValue(item.is_downloadable) ?? null,
183
+ contentHash: trimmedText(item.content_hash) ?? null,
184
+ url: trimmedText(item.url) ?? null,
185
+ expiresAt: trimmedText(item.expires) ?? null,
186
+ sharingInfo: asJsonObject(item.sharing_info) ?? null,
187
+ linkPermissions: asJsonObject(item.link_permissions) ?? null
195
188
  };
196
189
  }
197
190
  function listFolderResult(payload) {
198
191
  return {
199
192
  entries: objectArray(payload.entries).map((entry) => mapMetadata(entry)),
200
193
  cursor: requiredText(payload.cursor, "cursor"),
201
- hasMore: bool(payload.has_more) ?? false
194
+ hasMore: booleanValue(payload.has_more) ?? false
202
195
  };
203
196
  }
204
197
  function searchResult(payload) {
205
198
  return {
206
199
  matches: objectArray(payload.matches).map((match) => {
207
- const metadata = record(match.metadata) ?? {};
200
+ const metadata = asJsonObject(match.metadata) ?? {};
208
201
  return {
209
- matchType: text(record(match.match_type)?.[".tag"]) ?? "unknown",
202
+ matchType: trimmedText(asJsonObject(match.match_type)?.[".tag"]) ?? "unknown",
210
203
  // search_v2 的 match.metadata 自己还套一层 metadata;两种形状都接。
211
- metadata: mapMetadata(record(metadata.metadata) ?? metadata),
204
+ metadata: mapMetadata(asJsonObject(metadata.metadata) ?? metadata),
212
205
  highlightSpans: objectArray(match.highlight_spans)
213
206
  };
214
207
  }),
215
- cursor: text(payload.cursor) ?? null,
216
- hasMore: bool(payload.has_more) ?? false
208
+ cursor: trimmedText(payload.cursor) ?? null,
209
+ hasMore: booleanValue(payload.has_more) ?? false
217
210
  };
218
211
  }
219
212
  function saveUrlResult(payload) {
220
- const tag = text(payload[".tag"]) ?? "unknown";
221
- const metadata = record(payload.complete) ?? record(payload.metadata) ?? (tag === "complete" ? payload : void 0);
213
+ const tag = trimmedText(payload[".tag"]) ?? "unknown";
214
+ const metadata = asJsonObject(payload.complete) ?? asJsonObject(payload.metadata) ?? (tag === "complete" ? payload : void 0);
222
215
  return {
223
216
  tag,
224
- asyncJobId: text(payload.async_job_id) ?? null,
217
+ asyncJobId: trimmedText(payload.async_job_id) ?? null,
225
218
  metadata: metadata === void 0 ? null : mapMetadata(metadata),
226
- failure: record(payload.failed) ?? record(payload.failure) ?? null
219
+ failure: asJsonObject(payload.failed) ?? asJsonObject(payload.failure) ?? null
227
220
  };
228
221
  }
229
222
  function downloadResult(downloaded, fileName, action) {
@@ -235,38 +228,38 @@ function downloadResult(downloaded, fileName, action) {
235
228
  if (typeof fileId !== "string" || fileId === "") throw contractError("\u4E0B\u8F7D\u5143\u6570\u636E\u91CC\u7684\u6587\u4EF6 id");
236
229
  return {
237
230
  fileId,
238
- name: text(fileName) ?? metadata.name,
239
- mimeType: text(downloaded.contentType) ?? DEFAULT_MIME_TYPE,
231
+ name: trimmedText(fileName) ?? metadata.name,
232
+ mimeType: trimmedText(downloaded.contentType) ?? DEFAULT_MIME_TYPE,
240
233
  sizeBytes: metadata.sizeBytes,
241
234
  contentBase64: bytesToBase64(downloaded.bytes)
242
235
  };
243
236
  }
244
237
  async function getCurrentAccount(_input, ctx) {
245
238
  const payload = await rpc(ctx, "users/get_current_account");
246
- const name = record(payload.name) ?? {};
247
- const team = record(payload.team) ?? {};
248
- const accountType = record(payload.account_type) ?? {};
239
+ const name = asJsonObject(payload.name) ?? {};
240
+ const team = asJsonObject(payload.team) ?? {};
241
+ const accountType = asJsonObject(payload.account_type) ?? {};
249
242
  return {
250
243
  accountId: requiredText(payload.account_id, "account_id"),
251
244
  displayName: requiredText(name.display_name, "name.display_name"),
252
- abbreviatedName: text(name.abbreviated_name) ?? null,
253
- givenName: text(name.given_name) ?? null,
254
- surname: text(name.surname) ?? null,
255
- email: text(payload.email) ?? null,
256
- emailVerified: bool(payload.email_verified) ?? null,
257
- disabled: bool(payload.disabled) ?? false,
258
- locale: text(payload.locale) ?? null,
259
- country: text(payload.country) ?? null,
260
- accountType: text(accountType[".tag"]) ?? null,
261
- teamId: text(team.id) ?? null,
262
- teamName: text(team.name) ?? null
245
+ abbreviatedName: trimmedText(name.abbreviated_name) ?? null,
246
+ givenName: trimmedText(name.given_name) ?? null,
247
+ surname: trimmedText(name.surname) ?? null,
248
+ email: trimmedText(payload.email) ?? null,
249
+ emailVerified: booleanValue(payload.email_verified) ?? null,
250
+ disabled: booleanValue(payload.disabled) ?? false,
251
+ locale: trimmedText(payload.locale) ?? null,
252
+ country: trimmedText(payload.country) ?? null,
253
+ accountType: trimmedText(accountType[".tag"]) ?? null,
254
+ teamId: trimmedText(team.id) ?? null,
255
+ teamName: trimmedText(team.name) ?? null
263
256
  };
264
257
  }
265
258
  async function listFolder(input, ctx) {
266
259
  const payload = await rpc(ctx, "files/list_folder", {
267
- body: compact({
260
+ body: compactDefined({
268
261
  // 根目录在 Dropbox 里是空串,不是 '/' —— 省略 path 等同列根。
269
- path: text(input.path) ?? "",
262
+ path: trimmedText(input.path) ?? "",
270
263
  recursive: input.recursive,
271
264
  include_deleted: input.includeDeleted,
272
265
  include_mounted_folders: input.includeMountedFolders,
@@ -281,7 +274,7 @@ async function listFolderContinue(input, ctx) {
281
274
  }
282
275
  async function getMetadata(input, ctx) {
283
276
  const payload = await rpc(ctx, "files/get_metadata", {
284
- body: compact({
277
+ body: compactDefined({
285
278
  path: required(input.path, "path"),
286
279
  include_deleted: input.includeDeleted,
287
280
  include_has_explicit_shared_members: input.includeHasExplicitSharedMembers
@@ -301,7 +294,7 @@ async function downloadFile(input, ctx) {
301
294
  function writeMode(mode, updateRev) {
302
295
  if (mode === "overwrite") return "overwrite";
303
296
  if (mode === "update") {
304
- const rev = text(updateRev);
297
+ const rev = trimmedText(updateRev);
305
298
  if (rev === void 0) throw new TBError("invalid_argument", "mode \u4E3A 'update' \u65F6\u5FC5\u987B\u7ED9 updateRev");
306
299
  return { ".tag": "update", "update": rev };
307
300
  }
@@ -309,14 +302,14 @@ function writeMode(mode, updateRev) {
309
302
  }
310
303
  function uploadSource(input) {
311
304
  const inlineText = input.text;
312
- const contentBase64 = text(input.contentBase64);
305
+ const contentBase64 = trimmedText(input.contentBase64);
313
306
  const sources = Number(inlineText !== void 0) + Number(contentBase64 !== void 0);
314
307
  if (sources !== 1) {
315
308
  throw new TBError("invalid_argument", "text \u4E0E contentBase64 \u5FC5\u987B\u6070\u597D\u7ED9\u4E00\u4E2A");
316
309
  }
317
310
  return {
318
311
  bytes: inlineText === void 0 ? base64ToBytes(contentBase64 ?? "") : new TextEncoder().encode(inlineText),
319
- mimeType: text(input.mimeType) ?? DEFAULT_MIME_TYPE
312
+ mimeType: trimmedText(input.mimeType) ?? DEFAULT_MIME_TYPE
320
313
  };
321
314
  }
322
315
  async function uploadFile(input, ctx) {
@@ -327,14 +320,14 @@ async function uploadFile(input, ctx) {
327
320
  "upload_file \u5355\u8BF7\u6C42\u6700\u591A 150 MiB(\u66F4\u5927\u7684\u6587\u4EF6\u9700\u8981 upload_session,\u672C provider \u5C1A\u672A\u652F\u6301)"
328
321
  );
329
322
  }
330
- const arg = compact({
323
+ const arg = compactDefined({
331
324
  path: required(input.path, "path"),
332
325
  mode: writeMode(input.mode, input.updateRev),
333
326
  autorename: input.autorename,
334
- client_modified: text(input.clientModified),
327
+ client_modified: trimmedText(input.clientModified),
335
328
  mute: input.mute,
336
329
  strict_conflict: input.strictConflict,
337
- content_hash: text(input.contentHash)
330
+ content_hash: trimmedText(input.contentHash)
338
331
  });
339
332
  const response = await guardedFetch(`${CONTENT_BASE}/files/upload`, {
340
333
  method: "POST",
@@ -357,7 +350,7 @@ async function uploadFile(input, ctx) {
357
350
  }
358
351
  async function createFolder(input, ctx) {
359
352
  const payload = await rpc(ctx, "files/create_folder_v2", {
360
- body: compact({
353
+ body: compactDefined({
361
354
  path: required(input.path, "path"),
362
355
  autorename: input.autorename
363
356
  })
@@ -366,7 +359,7 @@ async function createFolder(input, ctx) {
366
359
  }
367
360
  async function relocate(input, ctx, route) {
368
361
  const payload = await rpc(ctx, `files/${route}`, {
369
- body: compact({
362
+ body: compactDefined({
370
363
  from_path: required(input.fromPath, "fromPath"),
371
364
  to_path: required(input.toPath, "toPath"),
372
365
  autorename: input.autorename,
@@ -383,25 +376,25 @@ function copy(input, ctx) {
383
376
  }
384
377
  async function deletePath(input, ctx) {
385
378
  const payload = await rpc(ctx, "files/delete_v2", {
386
- body: compact({
379
+ body: compactDefined({
387
380
  path: required(input.path, "path"),
388
- parent_rev: text(input.parentRev)
381
+ parent_rev: trimmedText(input.parentRev)
389
382
  })
390
383
  });
391
384
  return { metadata: mapMetadata(payload.metadata) };
392
385
  }
393
386
  async function searchFiles(input, ctx) {
394
- const options = compact({
395
- path: text(input.path),
387
+ const options = compactDefined({
388
+ path: trimmedText(input.path),
396
389
  max_results: input.maxResults,
397
- file_status: text(input.fileStatus),
390
+ file_status: trimmedText(input.fileStatus),
398
391
  filename_only: input.filenameOnly,
399
392
  file_categories: stringArray(input.fileCategories),
400
393
  file_extensions: stringArray(input.fileExtensions),
401
- order_by: text(input.orderBy)
394
+ order_by: trimmedText(input.orderBy)
402
395
  });
403
396
  const payload = await rpc(ctx, "files/search_v2", {
404
- body: compact({
397
+ body: compactDefined({
405
398
  query: required(input.query, "query"),
406
399
  // 一个都没给就整个 options 不发(空对象会被 Dropbox 当成显式的全默认)。
407
400
  options: Object.keys(options).length > 0 ? options : void 0,
@@ -440,18 +433,18 @@ async function saveUrlCheckJobStatus(input, ctx) {
440
433
  }
441
434
  async function listRevisions(input, ctx) {
442
435
  const payload = await rpc(ctx, "files/list_revisions", {
443
- body: compact({
436
+ body: compactDefined({
444
437
  path: required(input.path, "path"),
445
- mode: text(input.mode),
446
- before_rev: text(input.beforeRev),
438
+ mode: trimmedText(input.mode),
439
+ before_rev: trimmedText(input.beforeRev),
447
440
  limit: input.limit
448
441
  })
449
442
  });
450
443
  return {
451
444
  entries: objectArray(payload.entries).map((entry) => mapMetadata(entry)),
452
- isDeleted: bool(payload.is_deleted) ?? false,
453
- serverDeleted: text(payload.server_deleted) ?? null,
454
- hasMore: bool(payload.has_more) ?? false
445
+ isDeleted: booleanValue(payload.is_deleted) ?? false,
446
+ serverDeleted: trimmedText(payload.server_deleted) ?? null,
447
+ hasMore: booleanValue(payload.has_more) ?? false
455
448
  };
456
449
  }
457
450
  async function restore(input, ctx) {
@@ -471,23 +464,23 @@ async function getTags(input, ctx) {
471
464
  pathsToTags: objectArray(payload.paths_to_tags).map((entry) => ({
472
465
  path: requiredText(entry.path, "paths_to_tags[].path"),
473
466
  tags: objectArray(entry.tags).map((tag) => ({
474
- tag: text(tag[".tag"]) ?? "unknown",
475
- tagText: text(tag.tag_text) ?? null
467
+ tag: trimmedText(tag[".tag"]) ?? "unknown",
468
+ tagText: trimmedText(tag.tag_text) ?? null
476
469
  }))
477
470
  }))
478
471
  };
479
472
  }
480
473
  async function createSharedLink(input, ctx) {
481
- const settings = compact({
482
- requested_visibility: text(input.requestedVisibility),
483
- audience: text(input.audience),
484
- access: text(input.access),
474
+ const settings = compactDefined({
475
+ requested_visibility: trimmedText(input.requestedVisibility),
476
+ audience: trimmedText(input.audience),
477
+ access: trimmedText(input.access),
485
478
  allow_download: input.allowDownload,
486
- password: text(input.password),
487
- expires: text(input.expiresAt)
479
+ password: trimmedText(input.password),
480
+ expires: trimmedText(input.expiresAt)
488
481
  });
489
482
  const payload = await rpc(ctx, "sharing/create_shared_link_with_settings", {
490
- body: compact({
483
+ body: compactDefined({
491
484
  path: required(input.path, "path"),
492
485
  settings: Object.keys(settings).length > 0 ? settings : void 0
493
486
  })
@@ -496,23 +489,23 @@ async function createSharedLink(input, ctx) {
496
489
  }
497
490
  async function listSharedLinks(input, ctx) {
498
491
  const payload = await rpc(ctx, "sharing/list_shared_links", {
499
- body: compact({
500
- path: text(input.path),
501
- cursor: text(input.cursor),
492
+ body: compactDefined({
493
+ path: trimmedText(input.path),
494
+ cursor: trimmedText(input.cursor),
502
495
  direct_only: input.directOnly
503
496
  })
504
497
  });
505
498
  return {
506
499
  links: objectArray(payload.links).map((link) => mapMetadata(link)),
507
- cursor: text(payload.cursor) ?? null,
508
- hasMore: bool(payload.has_more) ?? false
500
+ cursor: trimmedText(payload.cursor) ?? null,
501
+ hasMore: booleanValue(payload.has_more) ?? false
509
502
  };
510
503
  }
511
504
  async function getSharedLinkMetadata(input, ctx) {
512
505
  const payload = await rpc(ctx, "sharing/get_shared_link_metadata", {
513
- body: compact({
506
+ body: compactDefined({
514
507
  url: required(input.url, "url"),
515
- path: text(input.path)
508
+ path: trimmedText(input.path)
516
509
  })
517
510
  });
518
511
  return { link: mapMetadata(payload) };
@@ -521,23 +514,23 @@ async function getSharedLinkFile(input, ctx) {
521
514
  const downloaded = await downloadContent(
522
515
  ctx,
523
516
  "/sharing/get_shared_link_file",
524
- compact({ url: required(input.url, "url"), path: text(input.path) }),
517
+ compactDefined({ url: required(input.url, "url"), path: trimmedText(input.path) }),
525
518
  "Dropbox \u5171\u4EAB\u94FE\u63A5\u4E0B\u8F7D\u5931\u8D25"
526
519
  );
527
520
  return downloadResult(downloaded, input.fileName, "get_shared_link_file");
528
521
  }
529
522
  async function modifySharedLink(input, ctx) {
530
- const settings = compact({
531
- requested_visibility: text(input.requestedVisibility),
532
- audience: text(input.audience),
533
- access: text(input.access),
523
+ const settings = compactDefined({
524
+ requested_visibility: trimmedText(input.requestedVisibility),
525
+ audience: trimmedText(input.audience),
526
+ access: trimmedText(input.access),
534
527
  allow_download: input.allowDownload,
535
- link_password: text(input.password),
536
- expires: text(input.expiresAt)
528
+ link_password: trimmedText(input.password),
529
+ expires: trimmedText(input.expiresAt)
537
530
  });
538
531
  const payload = await rpc(ctx, "sharing/modify_shared_link_settings", {
539
532
  // 与 create 不同:这里的 settings 即便是空对象也照发(上游如此)。
540
- body: compact({
533
+ body: compactDefined({
541
534
  url: required(input.url, "url"),
542
535
  settings,
543
536
  remove_expiration: input.removeExpiration