@tool-bridge/server 0.16.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-23JBIM6X.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-ADWBTCIH.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-CYQCYW2Z.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-5P62HDNR.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-54RZUAGW.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-AHJ6FTD5.js} +52 -77
  7. package/dist/{chunk-VK3V2WTY.js → chunk-B4P6YZFS.js} +4 -6
  8. package/dist/{chunk-BB6ZLMTU.js → chunk-CLEZ6YQ6.js} +2600 -481
  9. package/dist/chunk-JXHMDBAY.js +45 -0
  10. package/dist/chunk-LMLX3DJF.js +50 -0
  11. package/dist/{chunk-YB2FLNWI.js → chunk-OKRZPQ3R.js} +2558 -1926
  12. package/dist/chunk-SWBNHIO4.js +977 -0
  13. package/dist/chunk-U67V476Y.js +35 -0
  14. package/dist/chunk-VLOIDU5U.js +283 -0
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-UM3NSQJ3.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-FE5LQ2CZ.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-KEZABKUT.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-4IPJADXP.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-56QEKNQI.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-3QRM5K5T.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-L6G4OND5.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-LGC6HBFG.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-XDMK3BIU.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-4QARMFZU.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-C6JSJKOT.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-6A6TVACJ.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-SIWWW6AA.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-3IJXOKSP.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-L4KDA4DC.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-SDM75H4P.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-6DD436DN.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-SYSGYB3R.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-FZG7ASTF.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-HMRCZBUC.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-FAFSD7I3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-4D3TWENM.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-OSO2FOZS.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-OR4I4RHE.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-5AOPJ63E.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-SOJIJUWH.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-QSKN5TLN.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-R3AIZM7M.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-4CR3QOAX.js} +32 -46
  44. package/dist/index.d.ts +108 -56
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-OBCG6X6J.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-NHH3DTQW.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-7POMCBEC.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-YXVKROV4.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-LADO3VJU.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-XZ6UAQFU.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-P74GLNE7.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-CXJ7D37A.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-EVVHWFLK.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-WG2MRGBD.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-HQWUKG6U.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-SQMJIFOE.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-E27G2DZI.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-MIL63NIT.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-AIZVCBNR.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-XS4DVIQS.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-JEOUSL2Y.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-U4EZVDW2.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-AZSQEYEJ.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-HW3SYMTQ.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-QX74MAEL.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-OXSKYL6N.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-CCQAPDSW.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-6KQPSSCK.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-2TXO7IQE.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-YOO7NULI.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-Q6RIFIFP.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-KUMGCES3.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-VXQHBSMB.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-YLIPF52S.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-CRY7UJN5.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-3Z4T5AM7.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-BP37IGFL.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-HTKICF4K.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-WIVTUXJH.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-JJYPA43D.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-TKHZVG7A.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-FRSZLG5U.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-M5WXGQWE.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-PMXNLLBK.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-HFW4TAOH.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-KXVH2VZQ.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-WWOT2LRX.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-FY635H35.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-HQLBVSA5.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-GJN2GOHB.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BBNZGQU6.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-DPENIBOG.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-L4NONG6H.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-H67MAEZS.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-G2BSP4DX.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-7WMVFDG2.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-ZUAESFC2.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-EYFYIX3B.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-AXAUDUVF.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-UCQAWPLR.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-ZPZ4ASU6.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-4QVKKUD5.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-VGEFJTYC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-JME4TSCN.js} +124 -150
  107. package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
  108. package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-TRGU2MDG.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-WRUKLCZR.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-ZDW4EHS4.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-4VI67CWU.js} +35 -57
  112. package/package.json +3 -3
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. package/dist/chunk-MLKGABMK.js +0 -9
@@ -1,118 +1,99 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.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-B4P6YZFS.js";
14
+ import "./chunk-SWBNHIO4.js";
10
15
  import {
11
16
  TBError,
12
17
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
18
+ } from "./chunk-OKRZPQ3R.js";
19
+ import "./chunk-U67V476Y.js";
15
20
 
16
21
  // ../plugins/src/mem0/api.ts
17
22
  var SERVICE = "mem0";
18
23
  var API_BASE = "https://api.mem0.ai";
19
- function text(value) {
20
- if (typeof value !== "string") return void 0;
21
- const trimmed = value.trim();
22
- return trimmed === "" ? void 0 : trimmed;
23
- }
24
- function record(value) {
25
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
26
- }
27
- function compact(input) {
28
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
29
- }
24
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
30
25
  function requireText(value, field) {
31
- const result = text(value);
26
+ const result = trimmedText(value);
32
27
  if (result === void 0) throw new TBError("invalid_argument", `${field} \u662F\u5FC5\u586B\u7684`);
33
28
  return result;
34
29
  }
35
- function errorMessage(body, status) {
36
- if (body === "") return `Mem0 \u8FD4\u56DE HTTP ${status}`;
37
- let payload;
38
- try {
39
- payload = record(JSON.parse(body));
40
- } catch {
41
- return body;
42
- }
43
- if (payload === void 0) return body;
30
+ function errorMessage(value, status) {
31
+ if (typeof value === "string") return value === "" ? `Mem0 \u8FD4\u56DE HTTP ${status}` : value;
32
+ const payload = asJsonObject(value);
33
+ if (payload === void 0) return `Mem0 \u8FD4\u56DE HTTP ${status}`;
44
34
  const detail = payload.detail;
45
35
  if (typeof detail === "string" && detail !== "") return detail;
46
36
  if (Array.isArray(detail)) {
47
- const parts = detail.map((item) => typeof record(item)?.msg === "string" ? record(item)?.msg : void 0).filter((item) => item !== void 0 && item !== "");
37
+ const parts = detail.map((item) => typeof asJsonObject(item)?.msg === "string" ? asJsonObject(item)?.msg : void 0).filter((item) => item !== void 0 && item !== "");
48
38
  if (parts.length > 0) return parts.join("; ");
49
39
  }
50
40
  if (typeof payload.message === "string" && payload.message !== "") return payload.message;
51
41
  if (typeof payload.error === "string" && payload.error !== "") return payload.error;
52
- return body;
53
- }
54
- function buildUrl(path, query) {
55
- const url = new URL(`${API_BASE}${path}`);
56
- for (const [key, value] of Object.entries(query ?? {})) {
57
- if (value === void 0) continue;
58
- url.searchParams.set(key, String(value));
59
- }
60
- return url.toString();
42
+ return `Mem0 \u8FD4\u56DE HTTP ${status}`;
61
43
  }
62
- function rawRequest(ctx, input) {
63
- const headers = {
64
- // Token 而非 Bearer —— Mem0 用的是 DRF 的 TokenAuthentication。
65
- authorization: `Token ${requireApiKey(ctx, SERVICE)}`,
66
- accept: "application/json"
67
- };
68
- if (input.body !== void 0) headers["content-type"] = "application/json";
69
- return guardedFetch(buildUrl(input.path, input.query), {
44
+ function execute(ctx, input) {
45
+ return http.request({
46
+ path: input.path,
70
47
  method: input.method ?? "GET",
71
- headers,
72
- body: input.body === void 0 ? void 0 : JSON.stringify(input.body)
48
+ query: Object.entries(input.query ?? {}),
49
+ headers: {
50
+ accept: "application/json",
51
+ // Token 而非 Bearer —— Mem0 用的是 DRF 的 TokenAuthentication。
52
+ authorization: `Token ${requireApiKey(ctx, SERVICE)}`
53
+ },
54
+ ...input.body === void 0 ? {} : { json: input.body },
55
+ invalidJson: "text",
56
+ mapError: ({ data, status }) => upstreamError(status, errorMessage(data, status))
73
57
  });
74
58
  }
75
59
  async function request(ctx, input) {
76
- const response = await rawRequest(ctx, input);
77
- const body = await response.text();
78
- if (!response.ok) throw upstreamError(response.status, errorMessage(body, response.status));
79
- if (response.status === 204 || body === "") return {};
80
- try {
81
- return JSON.parse(body);
82
- } catch {
83
- return { raw: body };
60
+ const result = await execute(ctx, input);
61
+ if (result.bodyKind === "empty") return {};
62
+ if (result.bodyKind === "invalid-json" || result.bodyKind === "text") {
63
+ return { raw: result.data };
84
64
  }
65
+ return result.data;
85
66
  }
86
67
  function addMemories(input, ctx) {
87
- const memory = text(input.memory);
68
+ const memory = trimmedText(input.memory);
88
69
  if (memory === void 0 && !Array.isArray(input.messages)) {
89
70
  throw new TBError("invalid_argument", "\u5FC5\u987B\u63D0\u4F9B memory \u6216 messages");
90
71
  }
91
72
  return request(ctx, {
92
73
  method: "POST",
93
74
  path: "/v1/memories/",
94
- body: compact({
75
+ body: compactDefined({
95
76
  memory,
96
77
  messages: input.messages,
97
- user_id: text(input.user_id),
98
- agent_id: text(input.agent_id),
99
- app_id: text(input.app_id),
100
- run_id: text(input.run_id),
101
- org_id: text(input.org_id),
102
- project_id: text(input.project_id),
103
- metadata: record(input.metadata),
104
- custom_categories: record(input.custom_categories),
78
+ user_id: trimmedText(input.user_id),
79
+ agent_id: trimmedText(input.agent_id),
80
+ app_id: trimmedText(input.app_id),
81
+ run_id: trimmedText(input.run_id),
82
+ org_id: trimmedText(input.org_id),
83
+ project_id: trimmedText(input.project_id),
84
+ metadata: asJsonObject(input.metadata),
85
+ custom_categories: asJsonObject(input.custom_categories),
105
86
  enable_graph: input.enable_graph,
106
87
  infer: input.infer,
107
88
  async_mode: input.async_mode,
108
- output_format: text(input.output_format),
109
- version: text(input.version),
110
- custom_instructions: text(input.custom_instructions),
89
+ output_format: trimmedText(input.output_format),
90
+ version: trimmedText(input.version),
91
+ custom_instructions: trimmedText(input.custom_instructions),
111
92
  immutable: input.immutable,
112
93
  timestamp: input.timestamp,
113
- expiration_date: text(input.expiration_date),
114
- includes: text(input.includes),
115
- excludes: text(input.excludes)
94
+ expiration_date: trimmedText(input.expiration_date),
95
+ includes: trimmedText(input.includes),
96
+ excludes: trimmedText(input.excludes)
116
97
  })
117
98
  });
118
99
  }
@@ -120,12 +101,12 @@ function getMemories(input, ctx) {
120
101
  return request(ctx, {
121
102
  method: "POST",
122
103
  path: "/v2/memories/",
123
- body: compact({
124
- filters: record(input.filters),
104
+ body: compactDefined({
105
+ filters: asJsonObject(input.filters),
125
106
  page: input.page,
126
107
  page_size: input.page_size,
127
- org_id: text(input.org_id),
128
- project_id: text(input.project_id)
108
+ org_id: trimmedText(input.org_id),
109
+ project_id: trimmedText(input.project_id)
129
110
  })
130
111
  });
131
112
  }
@@ -133,17 +114,17 @@ function searchMemories(input, ctx) {
133
114
  return request(ctx, {
134
115
  method: "POST",
135
116
  path: "/v2/memories/search/",
136
- body: compact({
117
+ body: compactDefined({
137
118
  query: requireText(input.query, "query"),
138
- filters: record(input.filters),
119
+ filters: asJsonObject(input.filters),
139
120
  top_k: input.top_k,
140
121
  rerank: input.rerank,
141
122
  threshold: input.threshold,
142
123
  fields: input.fields,
143
124
  keyword_search: input.keyword_search,
144
125
  filter_memories: input.filter_memories,
145
- org_id: text(input.org_id),
146
- project_id: text(input.project_id)
126
+ org_id: trimmedText(input.org_id),
127
+ project_id: trimmedText(input.project_id)
147
128
  })
148
129
  });
149
130
  }
@@ -153,35 +134,28 @@ function getMemory(input, ctx) {
153
134
  }
154
135
  function updateMemory(input, ctx) {
155
136
  const memoryId = requireText(input.memory_id, "memory_id");
156
- const value = text(input.text);
157
- const metadata = record(input.metadata);
137
+ const value = trimmedText(input.text);
138
+ const metadata = asJsonObject(input.metadata);
158
139
  if (value === void 0 && metadata === void 0) {
159
140
  throw new TBError("invalid_argument", "\u5FC5\u987B\u63D0\u4F9B text \u6216 metadata");
160
141
  }
161
142
  return request(ctx, {
162
143
  method: "PUT",
163
144
  path: `/v1/memories/${encodeURIComponent(memoryId)}/`,
164
- body: compact({ text: value, metadata })
145
+ body: compactDefined({ text: value, metadata })
165
146
  });
166
147
  }
167
148
  async function deleteMemory(input, ctx) {
168
149
  const memoryId = requireText(input.memory_id, "memory_id");
169
- const response = await rawRequest(ctx, {
150
+ const result = await execute(ctx, {
170
151
  method: "DELETE",
171
152
  path: `/v1/memories/${encodeURIComponent(memoryId)}/`
172
153
  });
173
- const body = await response.text();
174
- if (!response.ok) throw upstreamError(response.status, errorMessage(body, response.status));
175
- let payload;
176
- try {
177
- payload = body === "" ? void 0 : record(JSON.parse(body));
178
- } catch {
179
- payload = void 0;
180
- }
154
+ const payload = result.bodyKind === "json" ? asJsonObject(result.data) : void 0;
181
155
  return {
182
156
  memory_id: memoryId,
183
157
  deleted: true,
184
- message: text(payload?.message) ?? "Memory deleted successfully!"
158
+ message: trimmedText(payload?.message) ?? "Memory deleted successfully!"
185
159
  };
186
160
  }
187
161
  function getMemoryHistory(input, ctx) {
@@ -192,9 +166,9 @@ function getEvents(input, ctx) {
192
166
  return request(ctx, {
193
167
  path: "/v1/events/",
194
168
  query: {
195
- event_type: text(input.event_type),
196
- start_date: text(input.start_date),
197
- end_date: text(input.end_date),
169
+ event_type: trimmedText(input.event_type),
170
+ start_date: trimmedText(input.start_date),
171
+ end_date: trimmedText(input.end_date),
198
172
  page: input.page,
199
173
  page_size: input.page_size
200
174
  }
@@ -205,8 +179,8 @@ function getEvent(input, ctx) {
205
179
  return request(ctx, { path: `/v1/event/${encodeURIComponent(eventId)}/` });
206
180
  }
207
181
  function getUsers(input, ctx) {
208
- const orgId = text(input.org_id);
209
- const projectId = text(input.project_id);
182
+ const orgId = trimmedText(input.org_id);
183
+ const projectId = trimmedText(input.project_id);
210
184
  if (orgId === void 0 !== (projectId === void 0)) {
211
185
  throw new TBError("invalid_argument", "org_id \u4E0E project_id \u5FC5\u987B\u540C\u65F6\u63D0\u4F9B\u6216\u540C\u65F6\u7701\u7565");
212
186
  }
@@ -1,24 +1,35 @@
1
+ import {
2
+ bytesToBase64,
3
+ readBoundedResponseBytes
4
+ } from "./chunk-LMLX3DJF.js";
5
+ import {
6
+ createProviderHttpClient
7
+ } from "./chunk-VLOIDU5U.js";
8
+ import {
9
+ asJsonObject,
10
+ compactDefined,
11
+ trimmedText
12
+ } from "./chunk-JXHMDBAY.js";
1
13
  import {
2
14
  createProviderPlugin,
3
15
  requireApiKey,
4
16
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
17
+ } from "./chunk-B4P6YZFS.js";
6
18
  import {
7
19
  assertPublicHttpUrl,
8
20
  guardedFetch
9
- } from "./chunk-2O27H4Y2.js";
10
- import "./chunk-GKX72JMJ.js";
21
+ } from "./chunk-SWBNHIO4.js";
11
22
  import {
12
23
  TBError,
13
24
  external_exports
14
- } from "./chunk-YB2FLNWI.js";
15
- import "./chunk-MLKGABMK.js";
25
+ } from "./chunk-OKRZPQ3R.js";
26
+ import "./chunk-U67V476Y.js";
16
27
 
17
28
  // ../plugins/src/memos/api.ts
18
29
  var SERVICE = "memos";
19
30
  var API_SUFFIX = "/api/v1";
20
31
  var ATTACHMENT_MAX_BYTES = 20 * 1024 * 1024;
21
- var BASE64_CHUNK = 8192;
32
+ var http = createProviderHttpClient({ service: SERVICE });
22
33
  var UPDATE_MASKS = [
23
34
  ["content", "content"],
24
35
  ["visibility", "visibility"],
@@ -27,29 +38,16 @@ var UPDATE_MASKS = [
27
38
  ["createTime", "create_time"],
28
39
  ["location", "location"]
29
40
  ];
30
- function record(value) {
31
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
32
- }
33
- function text(value) {
34
- if (typeof value !== "string") return void 0;
35
- const trimmed = value.trim();
36
- return trimmed === "" ? void 0 : trimmed;
37
- }
38
41
  function requireText(value, field) {
39
- const result = text(value);
42
+ const result = trimmedText(value);
40
43
  if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
41
44
  return result;
42
45
  }
43
- function compact(input) {
44
- return Object.fromEntries(
45
- Object.entries(input).filter(([, value]) => value !== void 0)
46
- );
47
- }
48
46
  function responseError(message) {
49
47
  return new TBError("unavailable", message, { retryable: true });
50
48
  }
51
49
  function requireResponseObject(value, operation) {
52
- const object = record(value);
50
+ const object = asJsonObject(value);
53
51
  if (object === void 0) throw responseError(`Memos ${operation} response did not include an object`);
54
52
  return object;
55
53
  }
@@ -63,7 +61,7 @@ function configError(message) {
63
61
  function resolveBaseUrl(ctx) {
64
62
  const configured = ctx.config?.baseUrl;
65
63
  if (configured !== void 0 && typeof configured !== "string") throw configError("\u5FC5\u987B\u662F\u5B57\u7B26\u4E32");
66
- const candidate = text(configured);
64
+ const candidate = trimmedText(configured);
67
65
  if (candidate === void 0) {
68
66
  throw configError(
69
67
  "\u662F\u5FC5\u914D\u9879:\u7ED9\u6302\u8F7D\u8282\u70B9\u914D providerConfig.baseUrl \u6307\u5411\u4F60\u7684 Memos \u5B9E\u4F8B(\u5982 https://memos.example.com)\u3002Memos \u53EA\u6709\u81EA\u5EFA\u5B9E\u4F8B,\u6CA1\u6709\u516C\u5171\u7F3A\u7701\u5730\u5740"
@@ -96,86 +94,34 @@ function resourcePath(name, collection) {
96
94
  }
97
95
  return `/${collection}/${encodeURIComponent(id)}`;
98
96
  }
99
- function readPayload(response, body) {
100
- if (body.trim() === "") return null;
101
- try {
102
- return JSON.parse(body);
103
- } catch {
104
- if (response.ok) throw responseError("Memos returned invalid JSON");
105
- return body;
106
- }
107
- }
108
97
  function errorMessage(payload) {
109
- const direct = text(payload);
98
+ const direct = trimmedText(payload);
110
99
  if (direct !== void 0) return direct;
111
- return text(record(payload)?.message) ?? "Memos request failed";
100
+ return trimmedText(asJsonObject(payload)?.message) ?? "Memos request failed";
112
101
  }
113
102
  async function request(target, input) {
114
- const url = new URL(`${target.baseUrl}${input.path}`);
115
- for (const [key, value] of Object.entries(input.query ?? {})) {
116
- if (value !== void 0) url.searchParams.set(key, String(value));
117
- }
118
- let response;
119
- let payload;
120
- try {
121
- response = await guardedFetch(url.toString(), {
122
- method: input.method ?? "GET",
123
- headers: {
124
- accept: "application/json",
125
- authorization: `Bearer ${target.apiKey}`,
126
- ...input.body === void 0 ? {} : { "content-type": "application/json" }
127
- },
128
- body: input.body === void 0 ? void 0 : JSON.stringify(input.body)
129
- });
130
- payload = readPayload(response, await response.text());
131
- } catch (error) {
132
- if (error instanceof TBError) throw error;
133
- const detail = error instanceof Error ? error.message : "unknown network error";
134
- throw upstreamError(502, `Memos ${input.path} request failed: ${detail}`);
135
- }
136
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload));
137
- return payload;
103
+ const result = await http.request({
104
+ baseUrl: `${target.baseUrl}/`,
105
+ path: input.path,
106
+ method: input.method ?? "GET",
107
+ query: Object.entries(input.query ?? {}),
108
+ headers: { accept: "application/json", authorization: `Bearer ${target.apiKey}` },
109
+ ...input.body === void 0 ? {} : { json: input.body },
110
+ invalidJsonMessage: "Memos returned invalid JSON",
111
+ mapError: ({ data, status }) => upstreamError(status, errorMessage(data)),
112
+ mapTransportError: ({ message }) => upstreamError(
113
+ 502,
114
+ `Memos ${input.path} request failed: ${message ?? "unknown network error"}`
115
+ )
116
+ });
117
+ return result.data === void 0 ? null : result.data;
138
118
  }
139
119
  async function readBoundedBytes(response) {
140
120
  const tooLarge = () => new TBError(
141
121
  "invalid_argument",
142
122
  `fileUrl \u6307\u5411\u7684\u6587\u4EF6\u8D85\u8FC7 ${ATTACHMENT_MAX_BYTES} \u5B57\u8282\u7684\u4E0A\u9650`
143
123
  );
144
- const declared = Number(response.headers.get("content-length"));
145
- if (Number.isFinite(declared) && declared > ATTACHMENT_MAX_BYTES) throw tooLarge();
146
- const body = response.body;
147
- if (body === null) {
148
- const bytes2 = new Uint8Array(await response.arrayBuffer());
149
- if (bytes2.byteLength > ATTACHMENT_MAX_BYTES) throw tooLarge();
150
- return bytes2;
151
- }
152
- const reader = body.getReader();
153
- const chunks = [];
154
- let total = 0;
155
- for (; ; ) {
156
- const { done, value } = await reader.read();
157
- if (done) break;
158
- total += value.byteLength;
159
- if (total > ATTACHMENT_MAX_BYTES) {
160
- await reader.cancel();
161
- throw tooLarge();
162
- }
163
- chunks.push(value);
164
- }
165
- const bytes = new Uint8Array(total);
166
- let offset = 0;
167
- for (const chunk of chunks) {
168
- bytes.set(chunk, offset);
169
- offset += chunk.byteLength;
170
- }
171
- return bytes;
172
- }
173
- function base64(bytes) {
174
- let binary = "";
175
- for (let offset = 0; offset < bytes.length; offset += BASE64_CHUNK) {
176
- binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_CHUNK));
177
- }
178
- return btoa(binary);
124
+ return readBoundedResponseBytes(response, { maxBytes: ATTACHMENT_MAX_BYTES, tooLarge });
179
125
  }
180
126
  async function downloadAttachment(fileUrl, declaredType) {
181
127
  let response;
@@ -188,7 +134,7 @@ async function downloadAttachment(fileUrl, declaredType) {
188
134
  }
189
135
  if (!response.ok) throw upstreamError(502, `failed to fetch fileUrl: ${response.status}`);
190
136
  const bytes = await readBoundedBytes(response);
191
- const responseType = text(response.headers.get("content-type")?.split(";", 1)[0]);
137
+ const responseType = trimmedText(response.headers.get("content-type")?.split(";", 1)[0]);
192
138
  return { bytes, mimeType: declaredType ?? responseType ?? "application/octet-stream" };
193
139
  }
194
140
  async function createMemo(input, ctx) {
@@ -196,11 +142,11 @@ async function createMemo(input, ctx) {
196
142
  method: "POST",
197
143
  path: "/memos",
198
144
  // memoId 是**query** 参数而不是 body 字段(Memos 的 AIP 风格:资源 id 走 query)。
199
- query: compact({ memoId: text(input.memoId) }),
200
- body: compact({
145
+ query: compactDefined({ memoId: trimmedText(input.memoId) }),
146
+ body: compactDefined({
201
147
  content: input.content,
202
- visibility: text(input.visibility),
203
- createTime: text(input.createTime),
148
+ visibility: trimmedText(input.visibility),
149
+ createTime: trimmedText(input.createTime),
204
150
  pinned: input.pinned,
205
151
  location: input.location
206
152
  })
@@ -210,19 +156,19 @@ async function createMemo(input, ctx) {
210
156
  async function listMemos(input, ctx) {
211
157
  const payload = requireResponseObject(await request(resolveTarget(ctx), {
212
158
  path: "/memos",
213
- query: compact({
159
+ query: compactDefined({
214
160
  pageSize: input.pageSize,
215
- pageToken: text(input.pageToken),
216
- state: text(input.state),
217
- orderBy: text(input.orderBy),
218
- filter: text(input.filter),
161
+ pageToken: trimmedText(input.pageToken),
162
+ state: trimmedText(input.state),
163
+ orderBy: trimmedText(input.orderBy),
164
+ filter: trimmedText(input.filter),
219
165
  showDeleted: input.showDeleted
220
166
  })
221
167
  }), "list memos");
222
168
  return {
223
169
  // 一页都没有时 Memos 干脆不给 `memos` 键,补成空数组;非数组则是上游坏了。
224
170
  memos: requireResponseObjects(payload.memos ?? [], "list memos"),
225
- nextPageToken: text(payload.nextPageToken) ?? null
171
+ nextPageToken: trimmedText(payload.nextPageToken) ?? null
226
172
  };
227
173
  }
228
174
  async function getMemo(input, ctx) {
@@ -240,7 +186,7 @@ async function updateMemo(input, ctx) {
240
186
  method: "PATCH",
241
187
  path: resourcePath(name, "memos"),
242
188
  query: { updateMask: updateMask.join(",") },
243
- body: compact({
189
+ body: compactDefined({
244
190
  name,
245
191
  content: input.content,
246
192
  visibility: input.visibility,
@@ -257,22 +203,22 @@ async function deleteMemo(input, ctx) {
257
203
  await request(resolveTarget(ctx), {
258
204
  method: "DELETE",
259
205
  path: resourcePath(name, "memos"),
260
- query: compact({ force: input.force })
206
+ query: compactDefined({ force: input.force })
261
207
  });
262
208
  return { deleted: true, name };
263
209
  }
264
210
  async function uploadAttachment(input, ctx) {
265
211
  const target = resolveTarget(ctx);
266
- const source = await downloadAttachment(requireText(input.fileUrl, "fileUrl"), text(input.type));
212
+ const source = await downloadAttachment(requireText(input.fileUrl, "fileUrl"), trimmedText(input.type));
267
213
  const payload = await request(target, {
268
214
  method: "POST",
269
215
  path: "/attachments",
270
- query: compact({ attachmentId: text(input.attachmentId) }),
271
- body: compact({
216
+ query: compactDefined({ attachmentId: trimmedText(input.attachmentId) }),
217
+ body: compactDefined({
272
218
  filename: requireText(input.filename, "filename"),
273
- content: base64(source.bytes),
219
+ content: bytesToBase64(source.bytes),
274
220
  type: source.mimeType,
275
- memo: text(input.memo)
221
+ memo: trimmedText(input.memo)
276
222
  })
277
223
  });
278
224
  return { attachment: requireResponseObject(payload, "upload attachment") };
@@ -280,16 +226,16 @@ async function uploadAttachment(input, ctx) {
280
226
  async function listAttachments(input, ctx) {
281
227
  const payload = requireResponseObject(await request(resolveTarget(ctx), {
282
228
  path: "/attachments",
283
- query: compact({
229
+ query: compactDefined({
284
230
  pageSize: input.pageSize,
285
- pageToken: text(input.pageToken),
286
- filter: text(input.filter),
287
- orderBy: text(input.orderBy)
231
+ pageToken: trimmedText(input.pageToken),
232
+ filter: trimmedText(input.filter),
233
+ orderBy: trimmedText(input.orderBy)
288
234
  })
289
235
  }), "list attachments");
290
236
  return {
291
237
  attachments: requireResponseObjects(payload.attachments ?? [], "list attachments"),
292
- nextPageToken: text(payload.nextPageToken) ?? null
238
+ nextPageToken: trimmedText(payload.nextPageToken) ?? null
293
239
  };
294
240
  }
295
241
  async function getAttachment(input, ctx) {
@@ -306,11 +252,11 @@ async function listMemoAttachments(input, ctx) {
306
252
  const name = requireText(input.name, "name");
307
253
  const payload = requireResponseObject(await request(resolveTarget(ctx), {
308
254
  path: `${resourcePath(name, "memos")}/attachments`,
309
- query: compact({ pageSize: input.pageSize, pageToken: text(input.pageToken) })
255
+ query: compactDefined({ pageSize: input.pageSize, pageToken: trimmedText(input.pageToken) })
310
256
  }), "list memo attachments");
311
257
  return {
312
258
  attachments: requireResponseObjects(payload.attachments ?? [], "list memo attachments"),
313
- nextPageToken: text(payload.nextPageToken) ?? null
259
+ nextPageToken: trimmedText(payload.nextPageToken) ?? null
314
260
  };
315
261
  }
316
262
  async function setMemoAttachments(input, ctx) {
@@ -331,23 +277,23 @@ async function getCurrentUser(_input, ctx) {
331
277
  async function listUsers(input, ctx) {
332
278
  const payload = requireResponseObject(await request(resolveTarget(ctx), {
333
279
  path: "/users",
334
- query: compact({
280
+ query: compactDefined({
335
281
  pageSize: input.pageSize,
336
- pageToken: text(input.pageToken),
337
- filter: text(input.filter),
282
+ pageToken: trimmedText(input.pageToken),
283
+ filter: trimmedText(input.filter),
338
284
  showDeleted: input.showDeleted
339
285
  })
340
286
  }), "list users");
341
287
  return {
342
288
  users: requireResponseObjects(payload.users ?? [], "list users"),
343
- nextPageToken: text(payload.nextPageToken) ?? null
289
+ nextPageToken: trimmedText(payload.nextPageToken) ?? null
344
290
  };
345
291
  }
346
292
  async function getUser(input, ctx) {
347
293
  const path = resourcePath(requireText(input.name, "name"), "users");
348
294
  const payload = await request(resolveTarget(ctx), {
349
295
  path,
350
- query: compact({ readMask: text(input.readMask) })
296
+ query: compactDefined({ readMask: trimmedText(input.readMask) })
351
297
  });
352
298
  return { user: requireResponseObject(payload, "get user") };
353
299
  }