@tool-bridge/server 0.21.1 → 0.22.1

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 (178) hide show
  1. package/dist/admin.js +170 -0
  2. package/dist/airtable-ML2GIGCH.js +790 -0
  3. package/dist/{alt_text_generator_ai-W7O34SNG.js → alt_text_generator_ai-FGYQAF2A.js} +12 -11
  4. package/dist/{amap-VOX4T2AW.js → amap-G7V65NGK.js} +221 -220
  5. package/dist/anthropic-6ZK24TBB.js +203 -0
  6. package/dist/apify-VDGYHP6W.js +248 -0
  7. package/dist/brave_search-TAATLZOS.js +302 -0
  8. package/dist/chunk-2IAI3XQM.js +302 -0
  9. package/dist/chunk-7ISGFRC6.js +161 -0
  10. package/dist/{chunk-E6JCVKW6.js → chunk-BNMLA2RC.js} +3 -3
  11. package/dist/chunk-HA4BGL6C.js +8429 -0
  12. package/dist/{chunk-KMTT3I6D.js → chunk-RMAWSG7E.js} +19172 -25717
  13. package/dist/{chunk-XYBU3WZH.js → chunk-RTW5VRTK.js} +3 -3
  14. package/dist/chunk-U7PTOA3U.js +7320 -0
  15. package/dist/chunk-UY6ANCOY.js +378 -0
  16. package/dist/{chunk-ATK45BXV.js → chunk-X7ZUTKHR.js} +4 -2
  17. package/dist/circleci-BQ2UWXL2.js +389 -0
  18. package/dist/clerk-2JYWQNOI.js +1019 -0
  19. package/dist/cohere-6MI7AQM4.js +185 -0
  20. package/dist/{confluence-B3EWPZVE.js → confluence-6Y6GDETF.js} +105 -104
  21. package/dist/{convertapi-EUWSQYPF.js → convertapi-HBZCSWOX.js} +32 -31
  22. package/dist/{currencyapi-KVTIK3GL.js → currencyapi-337U5TGI.js} +71 -71
  23. package/dist/deepseek-OSPASO7O.js +210 -0
  24. package/dist/docker_hub-3ATQOY5L.js +933 -0
  25. package/dist/dropbox-LSA4GM2Y.js +1305 -0
  26. package/dist/dub-VZPJSPI6.js +680 -0
  27. package/dist/e2b-6SDYQZL2.js +278 -0
  28. package/dist/exa-B6EUYDVP.js +332 -0
  29. package/dist/{fal_ai-23E7JPNT.js → fal_ai-K4Q27IME.js} +81 -80
  30. package/dist/{feishu-7QRIDUV6.js → feishu-4TKXG4SU.js} +528 -572
  31. package/dist/{feishu_custom_bot-TJ4K7QNJ.js → feishu_custom_bot-7CTEAKRB.js} +57 -53
  32. package/dist/figma-OUKSZLD5.js +777 -0
  33. package/dist/firehydrant-7MOYL7QH.js +563 -0
  34. package/dist/{fixer-BWON27UO.js → fixer-H2BV2NO4.js} +34 -33
  35. package/dist/fly-PXKY6PNH.js +469 -0
  36. package/dist/{front-QCGXYEDJ.js → front-UZYIV5DW.js} +104 -104
  37. package/dist/geocodio-NSYO7TFP.js +213 -0
  38. package/dist/ghost-QBKKQQMF.js +338 -0
  39. package/dist/github-ENLSJ4CL.js +5421 -0
  40. package/dist/gmail-KQSDEB47.js +1887 -0
  41. package/dist/googlecalendar-5YCX4SZF.js +2524 -0
  42. package/dist/{googledocs-BUHL4J2H.js → googledocs-SSWIVFKA.js} +341 -340
  43. package/dist/{grafana-GLU2DWF2.js → grafana-TF2LXDQA.js} +221 -220
  44. package/dist/graphhopper-CURBVHYK.js +325 -0
  45. package/dist/index.d.ts +1132 -332
  46. package/dist/index.js +31 -14
  47. package/dist/{ip2proxy-EZ64Y4ZH.js → ip2proxy-YNVMTZEM.js} +28 -27
  48. package/dist/ipgeolocation_io-NAU7VJ4J.js +315 -0
  49. package/dist/ipqualityscore-OT63L4TI.js +279 -0
  50. package/dist/{jina_ai-EFBHTBXL.js → jina_ai-6WBMBGWM.js} +23 -23
  51. package/dist/{jira-HQSHAA5K.js → jira-DVDVTHNO.js} +118 -117
  52. package/dist/langsmith-IM5N4YAU.js +593 -0
  53. package/dist/lemlist-277SHUQF.js +289 -0
  54. package/dist/{linear-K7RYFYAD.js → linear-AEPH7B5V.js} +327 -326
  55. package/dist/logsnag-VEWRAGBG.js +150 -0
  56. package/dist/main.js +57 -280
  57. package/dist/{mattermost-S2BRCWLQ.js → mattermost-Q3A2BIZA.js} +59 -58
  58. package/dist/mem0-AXS7GZGI.js +544 -0
  59. package/dist/memos-7TXG4ZTU.js +744 -0
  60. package/dist/{metabase-MMSEPCOF.js → metabase-NSVACWQM.js} +90 -89
  61. package/dist/mistral_ai-YZ52RGD4.js +1196 -0
  62. package/dist/{mother_duck-H7PCQNZ2.js → mother_duck-XLLL6FVL.js} +94 -93
  63. package/dist/ngrok-4O4W3WZW.js +356 -0
  64. package/dist/{notes-PFMKRO33.js → notes-YTB3TJOO.js} +11 -9
  65. package/dist/notion-4W4O7J7V.js +940 -0
  66. package/dist/open_exchange_rates-23QJXVO5.js +215 -0
  67. package/dist/openai-ZS7GLSLH.js +800 -0
  68. package/dist/opengraph_io-PMVH7OYI.js +362 -0
  69. package/dist/openrouter-ONRGFNB6.js +441 -0
  70. package/dist/outline-UCUYZZ7J.js +599 -0
  71. package/dist/paddle-35HTKTUL.js +454 -0
  72. package/dist/perplexity-NVOBYN24.js +220 -0
  73. package/dist/pinecone-55CJY73C.js +571 -0
  74. package/dist/{pipedrive-Y2O7QGFF.js → pipedrive-WMCAKS72.js} +99 -98
  75. package/dist/polar-SM4ZM53B.js +395 -0
  76. package/dist/posthog-NWCXVXNJ.js +3464 -0
  77. package/dist/postmark-QJV5PHUQ.js +427 -0
  78. package/dist/{prerender-MENYM2TY.js → prerender-2W7UT4SC.js} +31 -30
  79. package/dist/{pubmed-GOXUVVH5.js → pubmed-VVV7XYLU.js} +239 -238
  80. package/dist/{railway-V2SID4WV.js → railway-KGI57S3O.js} +118 -117
  81. package/dist/readwise-AGHTQB42.js +470 -0
  82. package/dist/render-O4HBROCK.js +461 -0
  83. package/dist/{replicate-756MXPYX.js → replicate-KWBOMX7D.js} +81 -80
  84. package/dist/{resend-ZKH3BTBI.js → resend-DRH6Y6I4.js} +20 -16
  85. package/dist/rootly-XGCUDW6X.js +336 -0
  86. package/dist/{scrapfly-NSRHFDIQ.js → scrapfly-OIQ3OY6L.js} +62 -61
  87. package/dist/{scrapingbee-OQHLAVEY.js → scrapingbee-OCZO4FHX.js} +56 -56
  88. package/dist/{screenshot_fyi-DVWG3AXC.js → screenshot_fyi-CUNGFZOC.js} +16 -16
  89. package/dist/semantic_scholar-3UJRLKES.js +611 -0
  90. package/dist/{sentry-546MNDJG.js → sentry-5BWVZFJV.js} +208 -207
  91. package/dist/{shodan-C3OON3Z3.js → shodan-HI37CTEW.js} +62 -61
  92. package/dist/shopify-LJ2EV2HH.js +610 -0
  93. package/dist/stripe-3LHMV55K.js +585 -0
  94. package/dist/{supabase-U2SL4D63.js → supabase-H2KPX3Q2.js} +245 -244
  95. package/dist/tavily-FBEWGH3Z.js +326 -0
  96. package/dist/telegram-MYYO3JND.js +1767 -0
  97. package/dist/{telnyx-CXQ4EZUX.js → telnyx-H4ALEGAX.js} +57 -56
  98. package/dist/todoist-OBWICA5Q.js +664 -0
  99. package/dist/trello-GUFUJRWO.js +1080 -0
  100. package/dist/turso-NIAK4UMS.js +416 -0
  101. package/dist/{twilio-4PDBJKWX.js → twilio-K6SLK2CX.js} +70 -69
  102. package/dist/umami-42RS2EPS.js +389 -0
  103. package/dist/unsplash-V7TOTETT.js +351 -0
  104. package/dist/{upstash_redis-G4LQBYHA.js → upstash_redis-AWQMB6Y3.js} +51 -50
  105. package/dist/uptimerobot-AZC2DHOT.js +483 -0
  106. package/dist/v2ex-4TVRNMLS.js +667 -0
  107. package/dist/vercel-DPHTJ3XR.js +1076 -0
  108. package/dist/{wolfram_alpha_api-3G4PUJWB.js → wolfram_alpha_api-XAG7IXBW.js} +36 -35
  109. package/dist/wordpress-KMPKVGUX.js +812 -0
  110. package/dist/workos-PKB2YR7S.js +664 -0
  111. package/dist/zhihu-Y4H4XYPB.js +254 -0
  112. package/package.json +18 -9
  113. package/dist/airtable-LLZDFN7M.js +0 -789
  114. package/dist/anthropic-G23NN3X5.js +0 -202
  115. package/dist/apify-Y3SS734K.js +0 -247
  116. package/dist/brave_search-ZC7OAPSZ.js +0 -301
  117. package/dist/chunk-R6P4XAE5.js +0 -248
  118. package/dist/chunk-U7B6DS2O.js +0 -977
  119. package/dist/chunk-UZM2RXZH.js +0 -23436
  120. package/dist/circleci-3BAX5FCG.js +0 -388
  121. package/dist/clerk-6LEM6TNU.js +0 -1019
  122. package/dist/cloudflare_dns-KINYTJUD.js +0 -588
  123. package/dist/cohere-XCJ5AJ6B.js +0 -185
  124. package/dist/deepseek-PC5YGNC5.js +0 -209
  125. package/dist/docker_hub-C3MA5FU6.js +0 -932
  126. package/dist/dropbox-XBV7Z2IR.js +0 -1304
  127. package/dist/dub-LDOFG3HC.js +0 -679
  128. package/dist/e2b-JMCPSVBW.js +0 -277
  129. package/dist/exa-RAK7O7RD.js +0 -331
  130. package/dist/figma-E6IX5DTH.js +0 -773
  131. package/dist/firehydrant-ZBLPQREE.js +0 -562
  132. package/dist/fly-ZH3HFCZJ.js +0 -468
  133. package/dist/geocodio-YGNI7DA4.js +0 -212
  134. package/dist/ghost-EVSGKH2Q.js +0 -337
  135. package/dist/github-MA2BGRCJ.js +0 -5420
  136. package/dist/gmail-E5E6AADE.js +0 -1886
  137. package/dist/googlecalendar-BTLFPXTD.js +0 -2523
  138. package/dist/graphhopper-WSMB3TCD.js +0 -324
  139. package/dist/ipgeolocation_io-AA7HAS22.js +0 -315
  140. package/dist/ipqualityscore-BHJXVTJT.js +0 -277
  141. package/dist/langsmith-5W6SCT6F.js +0 -592
  142. package/dist/lemlist-HJWH6UMK.js +0 -288
  143. package/dist/logsnag-4KFOHL37.js +0 -150
  144. package/dist/mem0-CAW43CIC.js +0 -543
  145. package/dist/memos-TWEGPKFM.js +0 -740
  146. package/dist/mistral_ai-64BGZQHP.js +0 -1195
  147. package/dist/ngrok-GQCUGZKJ.js +0 -356
  148. package/dist/notion-DQWZWP4N.js +0 -936
  149. package/dist/open_exchange_rates-QMMD735E.js +0 -214
  150. package/dist/openai-W6PX32NZ.js +0 -799
  151. package/dist/opengraph_io-HNDBXYNW.js +0 -361
  152. package/dist/openrouter-JJYMEAUL.js +0 -437
  153. package/dist/outline-MCBNQZYY.js +0 -595
  154. package/dist/paddle-D2SKLUDN.js +0 -453
  155. package/dist/perplexity-XIFMKUAE.js +0 -219
  156. package/dist/pinecone-HUFTALV2.js +0 -570
  157. package/dist/polar-TYTOMOSR.js +0 -394
  158. package/dist/posthog-43JAR3VW.js +0 -3463
  159. package/dist/postmark-KL2QJYSG.js +0 -426
  160. package/dist/readwise-CI4GIMMJ.js +0 -469
  161. package/dist/render-SUBJ6YRZ.js +0 -460
  162. package/dist/rootly-CD2LJHPI.js +0 -336
  163. package/dist/semantic_scholar-T4A252KW.js +0 -610
  164. package/dist/shopify-Y2HN2MCQ.js +0 -609
  165. package/dist/stripe-VE3CD3AY.js +0 -584
  166. package/dist/tavily-KCZHK6HE.js +0 -326
  167. package/dist/telegram-3URFBCMY.js +0 -1766
  168. package/dist/todoist-HNPWNYTD.js +0 -663
  169. package/dist/trello-3W2MIXRP.js +0 -1079
  170. package/dist/turso-2EQF7C2Z.js +0 -415
  171. package/dist/umami-5REN7TGP.js +0 -388
  172. package/dist/unsplash-EIXL424F.js +0 -350
  173. package/dist/uptimerobot-KNJ3EYLY.js +0 -482
  174. package/dist/v2ex-RHJ234PZ.js +0 -666
  175. package/dist/vercel-AS6NCIC7.js +0 -1075
  176. package/dist/wordpress-KNDAAUV7.js +0 -811
  177. package/dist/workos-R6UITSJ7.js +0 -663
  178. package/dist/zhihu-AGK4HILK.js +0 -253
@@ -0,0 +1,1887 @@
1
+ import {
2
+ createAuthedClient
3
+ } from "./chunk-RTW5VRTK.js";
4
+ import "./chunk-BNMLA2RC.js";
5
+ import {
6
+ asJsonObject
7
+ } from "./chunk-JXHMDBAY.js";
8
+ import {
9
+ createProviderPlugin,
10
+ upstreamError
11
+ } from "./chunk-X7ZUTKHR.js";
12
+ import "./chunk-7ISGFRC6.js";
13
+ import "./chunk-UY6ANCOY.js";
14
+ import {
15
+ TBError
16
+ } from "./chunk-HA4BGL6C.js";
17
+ import "./chunk-U67V476Y.js";
18
+
19
+ // ../plugins/src/gmail/api/shared.ts
20
+ var SERVICE = "gmail";
21
+ var API_BASE = "https://gmail.googleapis.com/gmail/v1";
22
+ var USER_ID = "me";
23
+ var RATE_LIMIT_REASONS = /* @__PURE__ */ new Set([
24
+ "dailyLimitExceeded",
25
+ "quotaExceeded",
26
+ "rateLimitExceeded",
27
+ "userRateLimitExceeded"
28
+ ]);
29
+ function trimmedString(value) {
30
+ return String(value ?? "").trim();
31
+ }
32
+ function toStringArray(value) {
33
+ if (!Array.isArray(value)) return [];
34
+ return value.map((item) => String(item).trim()).filter(Boolean);
35
+ }
36
+ function normalizeFormat(value, fallback) {
37
+ return trimmedString(value) || fallback;
38
+ }
39
+ var record = asJsonObject;
40
+ function requireRecord(value, label) {
41
+ const result = record(value);
42
+ if (result === void 0) throw new TBError("unavailable", `Gmail \u7684 ${label} \u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
43
+ return result;
44
+ }
45
+ function optionalString(value) {
46
+ return typeof value === "string" ? value : void 0;
47
+ }
48
+ function recordArray(value, label) {
49
+ if (value === void 0 || value === null) return [];
50
+ if (!Array.isArray(value)) {
51
+ throw new TBError("unavailable", `Gmail \u7684 ${label} \u4E0D\u662F\u6570\u7EC4`, { retryable: true });
52
+ }
53
+ return value.map((item) => requireRecord(item, `${label} \u7684\u5143\u7D20`));
54
+ }
55
+ function nullableRecord(value, label) {
56
+ if (value === null) return {};
57
+ return requireRecord(value, label);
58
+ }
59
+ function asObject(value) {
60
+ return record(value) ?? {};
61
+ }
62
+ function labelMutationPayload(input) {
63
+ return {
64
+ addLabelIds: toStringArray(input.addLabelIds),
65
+ removeLabelIds: toStringArray(input.removeLabelIds)
66
+ };
67
+ }
68
+ function bodyFromInput(input, drop = []) {
69
+ return Object.fromEntries(
70
+ Object.entries(input).filter(([key, value]) => key !== "userId" && !drop.includes(key) && value !== void 0)
71
+ );
72
+ }
73
+ async function hydrateInBatches(items, hydrate, batchSize = 10) {
74
+ const hydrated = [];
75
+ for (let index = 0; index < items.length; index += batchSize) {
76
+ const batch = items.slice(index, index + batchSize);
77
+ hydrated.push(...await Promise.all(batch.map((item) => hydrate(item))));
78
+ }
79
+ return hydrated;
80
+ }
81
+ function buildPath(path) {
82
+ const segments = path.map((segment) => encodeURIComponent(segment)).join("/");
83
+ return `users/${encodeURIComponent(USER_ID)}${segments === "" ? "" : `/${segments}`}`;
84
+ }
85
+ function errorMessage(payload) {
86
+ const error = record(payload)?.error;
87
+ if (typeof error === "string") return trimmedString(error) || void 0;
88
+ return trimmedString(record(error)?.message) || void 0;
89
+ }
90
+ function errorReasons(payload) {
91
+ const errors = record(record(payload)?.error)?.errors;
92
+ if (!Array.isArray(errors)) return [];
93
+ return errors.map((item) => trimmedString(record(item)?.reason)).filter(Boolean);
94
+ }
95
+ function gmailError(status, payload) {
96
+ const message = errorMessage(payload) ?? `Gmail \u8FD4\u56DE HTTP ${status}`;
97
+ if (status === 403 && errorReasons(payload).some((reason) => RATE_LIMIT_REASONS.has(reason))) {
98
+ return upstreamError(429, message);
99
+ }
100
+ return upstreamError(status, message);
101
+ }
102
+ var http = createAuthedClient({
103
+ baseUrl: `${API_BASE}/`,
104
+ service: SERVICE,
105
+ auth: { kind: "bearer" },
106
+ mapError: ({ bodyKind, data, status }) => gmailError(
107
+ status,
108
+ bodyKind === "json" ? data : null
109
+ )
110
+ });
111
+ async function send(ctx, input) {
112
+ const hasBody = input.body !== void 0;
113
+ const response = await http.request(ctx, {
114
+ method: input.method ?? "GET",
115
+ path: buildPath(input.path),
116
+ query: Object.entries(input.query ?? {}),
117
+ ...hasBody ? { json: input.body } : {},
118
+ invalidJson: "text"
119
+ });
120
+ if (response.bodyKind === "invalid-json") {
121
+ throw new TBError("unavailable", "Gmail \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
122
+ }
123
+ return { payload: response.bodyKind === "empty" ? null : response.data };
124
+ }
125
+ async function requestJson(ctx, input) {
126
+ return (await send(ctx, input)).payload;
127
+ }
128
+ async function requestEmpty(ctx, input) {
129
+ await send(ctx, input);
130
+ }
131
+ async function requestRecord(ctx, input, label) {
132
+ return requireRecord(await requestJson(ctx, input), label);
133
+ }
134
+
135
+ // ../plugins/src/gmail/api/message.ts
136
+ function encodeBase64(value) {
137
+ const bytes = new TextEncoder().encode(value);
138
+ let binary = "";
139
+ for (const byte of bytes) binary += String.fromCharCode(byte);
140
+ return btoa(binary);
141
+ }
142
+ function encodeBase64Url(value) {
143
+ return encodeBase64(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
144
+ }
145
+ function decodeBase64Url(value) {
146
+ const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
147
+ const padded = normalized.padEnd(normalized.length + (4 - normalized.length % 4) % 4, "=");
148
+ let binary;
149
+ try {
150
+ binary = atob(padded);
151
+ } catch {
152
+ return "";
153
+ }
154
+ const bytes = new Uint8Array(binary.length);
155
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
156
+ return new TextDecoder().decode(bytes);
157
+ }
158
+ function joinAddresses(addresses) {
159
+ return addresses.filter(Boolean).join(", ");
160
+ }
161
+ function headerLine(name, value) {
162
+ return value ? `${name}: ${value}` : "";
163
+ }
164
+ function encodeSubject(subject) {
165
+ return [...subject].every((char) => char.charCodeAt(0) <= 127) ? subject : `=?UTF-8?B?${encodeBase64(subject)}?=`;
166
+ }
167
+ function normalizeReplySubject(subject) {
168
+ if (!subject) return "Re:";
169
+ return /^re:/i.test(subject) ? subject : `Re: ${subject}`;
170
+ }
171
+ function toMessageTimestamp(internalDate, fallbackDate) {
172
+ if (internalDate) {
173
+ const parsed = Number(internalDate);
174
+ if (Number.isFinite(parsed)) {
175
+ const date = new Date(parsed);
176
+ if (!Number.isNaN(date.getTime())) return date.toISOString();
177
+ }
178
+ }
179
+ if (fallbackDate) {
180
+ const parsed = new Date(fallbackDate);
181
+ if (!Number.isNaN(parsed.getTime())) return parsed.toISOString();
182
+ }
183
+ return "";
184
+ }
185
+ function collectAttachments(payload) {
186
+ if (!payload) return [];
187
+ const attachments = [];
188
+ if (payload.filename) {
189
+ attachments.push({
190
+ attachmentId: payload.body?.attachmentId ?? null,
191
+ filename: payload.filename,
192
+ mimeType: payload.mimeType ?? "application/octet-stream",
193
+ size: payload.body?.size ?? 0
194
+ });
195
+ }
196
+ for (const part of payload.parts ?? []) attachments.push(...collectAttachments(part));
197
+ return attachments;
198
+ }
199
+ function parseAddressList(value) {
200
+ const addresses = [];
201
+ let current = "";
202
+ let inQuotes = false;
203
+ let angleDepth = 0;
204
+ let escaped = false;
205
+ for (const char of value) {
206
+ if (escaped) {
207
+ current += char;
208
+ escaped = false;
209
+ continue;
210
+ }
211
+ if (char === "\\") {
212
+ current += char;
213
+ if (inQuotes) escaped = true;
214
+ continue;
215
+ }
216
+ if (char === '"') {
217
+ inQuotes = !inQuotes;
218
+ current += char;
219
+ continue;
220
+ }
221
+ if (!inQuotes) {
222
+ if (char === "<") {
223
+ angleDepth += 1;
224
+ } else if (char === ">" && angleDepth > 0) {
225
+ angleDepth -= 1;
226
+ } else if (char === "," && angleDepth === 0) {
227
+ const address2 = current.trim();
228
+ if (address2) addresses.push(address2);
229
+ current = "";
230
+ continue;
231
+ }
232
+ }
233
+ current += char;
234
+ }
235
+ const address = current.trim();
236
+ if (address) addresses.push(address);
237
+ return addresses;
238
+ }
239
+ function firstAddress(value) {
240
+ return parseAddressList(value)[0] ?? "";
241
+ }
242
+ function readHeader(headers, name) {
243
+ return headers.find((header) => header.name.toLowerCase() === name.toLowerCase())?.value ?? "";
244
+ }
245
+ function extractBodyContent(payload) {
246
+ if (!payload) return { body: "", isHtml: false };
247
+ if (payload.mimeType === "text/plain" && payload.body?.data) {
248
+ return { body: decodeBase64Url(payload.body.data), isHtml: false };
249
+ }
250
+ if (payload.mimeType === "text/html" && payload.body?.data) {
251
+ return { body: decodeBase64Url(payload.body.data), isHtml: true };
252
+ }
253
+ for (const part of payload.parts ?? []) {
254
+ const content = extractBodyContent(part);
255
+ if (content.body) return content;
256
+ }
257
+ if (payload.body?.data && (!payload.mimeType || payload.mimeType.startsWith("text/"))) {
258
+ return { body: decodeBase64Url(payload.body.data), isHtml: payload.mimeType === "text/html" };
259
+ }
260
+ return { body: "", isHtml: false };
261
+ }
262
+ function normalizeThreadId(value) {
263
+ return String(value ?? "").replace(/^thread-f:/i, "").replace(/^msg-f:/i, "").trim();
264
+ }
265
+ function normalizeMessageId(value) {
266
+ return String(value ?? "").trim();
267
+ }
268
+ function summarizeGmailMessage(resource) {
269
+ const headers = resource.payload?.headers ?? [];
270
+ return {
271
+ messageId: resource.id,
272
+ threadId: resource.threadId,
273
+ labelIds: resource.labelIds ?? [],
274
+ subject: readHeader(headers, "Subject"),
275
+ sender: readHeader(headers, "From"),
276
+ to: readHeader(headers, "To"),
277
+ messageTimestamp: toMessageTimestamp(resource.internalDate, readHeader(headers, "Date"))
278
+ };
279
+ }
280
+ function normalizeGmailMessage(resource) {
281
+ const payload = resource.payload ?? null;
282
+ const summary = summarizeGmailMessage(resource);
283
+ const messageText = extractBodyContent(payload).body;
284
+ return {
285
+ ...summary,
286
+ preview: {
287
+ subject: summary.subject,
288
+ // Gmail 自己的 snippet 优先(它已经做过 HTML 剥离);没有才从正文截 200 字。
289
+ body: resource.snippet ?? messageText.slice(0, 200)
290
+ },
291
+ payload,
292
+ messageText,
293
+ attachmentList: collectAttachments(payload),
294
+ ...resource.raw ? { raw: resource.raw } : {}
295
+ };
296
+ }
297
+ function resolveReplyHeaders(resource) {
298
+ const headers = resource.payload?.headers ?? [];
299
+ return {
300
+ subject: normalizeReplySubject(readHeader(headers, "Subject")),
301
+ to: firstAddress(readHeader(headers, "Reply-To")) || firstAddress(readHeader(headers, "From")),
302
+ references: readHeader(headers, "References") || readHeader(headers, "Message-ID") || resource.id,
303
+ inReplyTo: readHeader(headers, "Message-ID") || resource.id
304
+ };
305
+ }
306
+ function encodeMimeMessage(input) {
307
+ const headers = [
308
+ headerLine("From", joinAddresses(input.from ? [input.from] : [])),
309
+ headerLine("To", joinAddresses(input.to)),
310
+ headerLine("Cc", joinAddresses(input.cc ?? [])),
311
+ headerLine("Bcc", joinAddresses(input.bcc ?? [])),
312
+ headerLine("Subject", encodeSubject(input.subject ?? "")),
313
+ headerLine("In-Reply-To", input.inReplyTo),
314
+ headerLine("References", input.references),
315
+ "MIME-Version: 1.0",
316
+ `Content-Type: ${input.isHtml ? "text/html" : "text/plain"}; charset=UTF-8`,
317
+ "Content-Transfer-Encoding: base64"
318
+ ].filter(Boolean);
319
+ return encodeBase64Url(`${headers.join("\r\n")}\r
320
+ \r
321
+ ${encodeBase64(input.body ?? "")}`);
322
+ }
323
+ function optionalAddressList(value) {
324
+ if (Array.isArray(value)) return value.map((item) => String(item).trim()).filter(Boolean);
325
+ const stringValue = String(value ?? "").trim();
326
+ return stringValue ? [stringValue] : [];
327
+ }
328
+ function buildRecipients(input) {
329
+ return {
330
+ to: [
331
+ ...optionalAddressList(input.to),
332
+ ...optionalAddressList(input.recipientEmail),
333
+ ...optionalAddressList(input.extraRecipients)
334
+ ],
335
+ cc: optionalAddressList(input.cc),
336
+ bcc: optionalAddressList(input.bcc)
337
+ };
338
+ }
339
+
340
+ // ../plugins/src/gmail/api/mailbox.ts
341
+ var SETTINGS_AUTO_FORWARDING = "autoForwarding";
342
+ var SETTINGS_IMAP = "imap";
343
+ var SETTINGS_LANGUAGE = "language";
344
+ var SETTINGS_POP = "pop";
345
+ var SETTINGS_VACATION = "vacation";
346
+ function getSettings(resource, ctx) {
347
+ return requestRecord(ctx, { path: ["settings", resource] }, `settings/${resource} \u54CD\u5E94`);
348
+ }
349
+ function updateSettings(resource, input, ctx) {
350
+ return requestRecord(ctx, {
351
+ method: "PUT",
352
+ path: ["settings", resource],
353
+ body: bodyFromInput(input)
354
+ }, `settings/${resource} \u54CD\u5E94`);
355
+ }
356
+ async function getProfile(_input, ctx) {
357
+ return requestRecord(ctx, { path: ["profile"] }, "profile \u54CD\u5E94");
358
+ }
359
+ async function listHistory(input, ctx) {
360
+ const startHistoryId = normalizeMessageId(input.startHistoryId);
361
+ const historyTypes = toStringArray(input.historyTypes);
362
+ const payload = requireRecord(await requestJson(ctx, {
363
+ path: ["history"],
364
+ query: {
365
+ startHistoryId,
366
+ pageToken: input.pageToken,
367
+ maxResults: input.maxResults,
368
+ labelId: input.labelId,
369
+ historyTypes: historyTypes.length > 0 ? historyTypes : void 0
370
+ }
371
+ }), "history \u54CD\u5E94");
372
+ return {
373
+ history: recordArray(payload.history, "history"),
374
+ // 没有变更时 Gmail 不回 historyId;把入参那个原样报回去,调用方下一轮才有可用的水位。
375
+ historyId: optionalString(payload.historyId) ?? startHistoryId,
376
+ nextPageToken: optionalString(payload.nextPageToken) ?? null
377
+ };
378
+ }
379
+ async function listFilters(_input, ctx) {
380
+ const payload = nullableRecord(
381
+ await requestJson(ctx, { path: ["settings", "filters"] }),
382
+ "filters \u54CD\u5E94"
383
+ );
384
+ return { filters: recordArray(payload.filter, "filters") };
385
+ }
386
+ async function getFilter(input, ctx) {
387
+ return requestRecord(
388
+ ctx,
389
+ { path: ["settings", "filters", normalizeMessageId(input.filterId)] },
390
+ "filter \u54CD\u5E94"
391
+ );
392
+ }
393
+ async function createFilter(input, ctx) {
394
+ return requestRecord(ctx, {
395
+ method: "POST",
396
+ path: ["settings", "filters"],
397
+ // 只发 criteria 与 action 两个键:filters.create 不认别的字段(userId 尤其会被拒)。
398
+ body: { criteria: asObject(input.criteria), action: asObject(input.action) }
399
+ }, "filter \u54CD\u5E94");
400
+ }
401
+ async function deleteFilter(input, ctx) {
402
+ await requestEmpty(ctx, {
403
+ method: "DELETE",
404
+ path: ["settings", "filters", normalizeMessageId(input.filterId)]
405
+ });
406
+ return { success: true };
407
+ }
408
+ async function listForwardingAddresses(_input, ctx) {
409
+ const payload = nullableRecord(
410
+ await requestJson(ctx, { path: ["settings", "forwardingAddresses"] }),
411
+ "forwardingAddresses \u54CD\u5E94"
412
+ );
413
+ return { forwardingAddresses: recordArray(payload.forwardingAddresses, "forwardingAddresses") };
414
+ }
415
+ function getLanguageSettings(_input, ctx) {
416
+ return getSettings(SETTINGS_LANGUAGE, ctx);
417
+ }
418
+ function updateLanguageSettings(input, ctx) {
419
+ return updateSettings(SETTINGS_LANGUAGE, input, ctx);
420
+ }
421
+ function getVacationSettings(_input, ctx) {
422
+ return getSettings(SETTINGS_VACATION, ctx);
423
+ }
424
+ function updateVacationSettings(input, ctx) {
425
+ return updateSettings(SETTINGS_VACATION, input, ctx);
426
+ }
427
+ function getAutoForwarding(_input, ctx) {
428
+ return getSettings(SETTINGS_AUTO_FORWARDING, ctx);
429
+ }
430
+ function settingsGetImap(_input, ctx) {
431
+ return getSettings(SETTINGS_IMAP, ctx);
432
+ }
433
+ function updateImapSettings(input, ctx) {
434
+ return updateSettings(SETTINGS_IMAP, input, ctx);
435
+ }
436
+ function settingsGetPop(_input, ctx) {
437
+ return getSettings(SETTINGS_POP, ctx);
438
+ }
439
+ function updatePopSettings(input, ctx) {
440
+ return updateSettings(SETTINGS_POP, input, ctx);
441
+ }
442
+ async function stopWatch(_input, ctx) {
443
+ await requestEmpty(ctx, { method: "POST", path: ["stop"] });
444
+ return { success: true };
445
+ }
446
+
447
+ // ../plugins/src/gmail/api/resources.ts
448
+ function shapeError(label, detail) {
449
+ return new TBError("unavailable", `Gmail \u7684 ${label} ${detail}`, { retryable: true });
450
+ }
451
+ function asMessageResource(payload, label) {
452
+ const value = requireRecord(payload, label);
453
+ if (typeof value.id !== "string" || typeof value.threadId !== "string") {
454
+ throw shapeError(label, "\u7F3A id \u6216 threadId");
455
+ }
456
+ return value;
457
+ }
458
+ function asThreadResource(payload, label) {
459
+ const value = requireRecord(payload, label);
460
+ if (typeof value.id !== "string") throw shapeError(label, "\u7F3A id");
461
+ return value;
462
+ }
463
+ function asDraftResource(payload, label) {
464
+ const value = requireRecord(payload, label);
465
+ if (typeof value.id !== "string") throw shapeError(label, "\u7F3A id");
466
+ asMessageResource(value.message, `${label} \u7684 message`);
467
+ return value;
468
+ }
469
+ async function getMessageResource(ctx, messageId, format) {
470
+ return asMessageResource(
471
+ await requestJson(ctx, { path: ["messages", messageId], query: { format } }),
472
+ "message \u54CD\u5E94"
473
+ );
474
+ }
475
+ async function getThreadResource(ctx, threadId, format) {
476
+ return asThreadResource(
477
+ await requestJson(ctx, { path: ["threads", threadId], query: { format } }),
478
+ "thread \u54CD\u5E94"
479
+ );
480
+ }
481
+ async function getDraftResource(ctx, draftId, format) {
482
+ return asDraftResource(
483
+ await requestJson(ctx, { path: ["drafts", draftId], query: { format } }),
484
+ "draft \u54CD\u5E94"
485
+ );
486
+ }
487
+
488
+ // ../plugins/src/gmail/api/messages.ts
489
+ var DEFAULT_FETCH_EMAILS_MAX_RESULTS = 20;
490
+ function threadSummary(thread) {
491
+ return {
492
+ threadId: thread.id,
493
+ snippet: thread.snippet ?? "",
494
+ historyId: thread.historyId ?? null,
495
+ messages: (thread.messages ?? []).map((message) => normalizeGmailMessage(message))
496
+ };
497
+ }
498
+ async function listThreads(input, ctx) {
499
+ const query = trimmedString(input.query);
500
+ const payload = requireRecord(await requestJson(ctx, {
501
+ path: ["threads"],
502
+ query: {
503
+ q: query === "" ? void 0 : query,
504
+ pageToken: input.pageToken,
505
+ maxResults: input.maxResults
506
+ }
507
+ }), "threads \u54CD\u5E94");
508
+ const threads = recordArray(payload.threads, "threads");
509
+ const nextPageToken = optionalString(payload.nextPageToken) ?? null;
510
+ if (input.verbose === true) {
511
+ const hydrated = await hydrateInBatches(threads, (thread) => getThreadResource(ctx, String(thread.id), "full"));
512
+ return {
513
+ threads: hydrated.map((thread) => threadSummary(thread)),
514
+ nextPageToken,
515
+ resultSizeEstimate: payload.resultSizeEstimate ?? hydrated.length
516
+ };
517
+ }
518
+ return {
519
+ threads: threads.map((thread) => ({
520
+ threadId: String(thread.id),
521
+ snippet: optionalString(thread.snippet) ?? "",
522
+ historyId: optionalString(thread.historyId) ?? null
523
+ })),
524
+ nextPageToken,
525
+ resultSizeEstimate: payload.resultSizeEstimate ?? threads.length
526
+ };
527
+ }
528
+ async function searchThreads(input, ctx) {
529
+ const output = await listThreads(input, ctx);
530
+ return {
531
+ threads: output.threads.map((thread) => ({
532
+ threadId: thread.threadId,
533
+ snippet: thread.snippet
534
+ }))
535
+ };
536
+ }
537
+ async function listThreadsAction(input, ctx) {
538
+ return { ...await listThreads(input, ctx) };
539
+ }
540
+ async function fetchEmails(input, ctx) {
541
+ const query = trimmedString(input.query);
542
+ const labelIds = toStringArray(input.labelIds);
543
+ const payload = requireRecord(await requestJson(ctx, {
544
+ path: ["messages"],
545
+ query: {
546
+ q: query === "" ? void 0 : query,
547
+ labelIds: labelIds.length > 0 ? labelIds : void 0,
548
+ pageToken: input.pageToken,
549
+ // 上游还做了一次 1..500 的范围校验;那层现在由 schema 的 `z.int().min(1).max(500)` 承担,
550
+ // 越界在进 handler 前就已经是 invalid_argument 了。
551
+ maxResults: input.maxResults ?? DEFAULT_FETCH_EMAILS_MAX_RESULTS,
552
+ includeSpamTrash: input.includeSpamTrash
553
+ }
554
+ }), "messages \u54CD\u5E94");
555
+ const messages = recordArray(payload.messages, "messages");
556
+ const nextPageToken = optionalString(payload.nextPageToken) ?? null;
557
+ const detail = trimmedString(input.detail) || "summary";
558
+ if (detail === "ids") {
559
+ return {
560
+ messages: messages.map((message) => ({
561
+ messageId: String(message.id),
562
+ threadId: String(message.threadId)
563
+ })),
564
+ nextPageToken,
565
+ resultSizeEstimate: payload.resultSizeEstimate ?? messages.length
566
+ };
567
+ }
568
+ const includeFullMessage = detail === "full";
569
+ const hydrated = await hydrateInBatches(messages, (message) => getMessageResource(ctx, String(message.id), includeFullMessage ? "full" : "metadata"));
570
+ return {
571
+ messages: hydrated.map((message) => includeFullMessage ? normalizeGmailMessage(message) : summarizeGmailMessage(message)),
572
+ nextPageToken,
573
+ resultSizeEstimate: payload.resultSizeEstimate ?? hydrated.length
574
+ };
575
+ }
576
+ async function getMessage(input, ctx) {
577
+ const message = await getMessageResource(ctx, normalizeMessageId(input.messageId), "full");
578
+ const output = normalizeGmailMessage(message);
579
+ return {
580
+ messageId: output.messageId,
581
+ threadId: output.threadId,
582
+ subject: output.subject,
583
+ from: output.sender,
584
+ to: output.to,
585
+ // date 取的是原始 `Date` 头,而不是 normalize 出来的 ISO 时间戳 —— 两者是不同的东西。
586
+ date: readHeader(message.payload?.headers ?? [], "Date"),
587
+ body: output.messageText
588
+ };
589
+ }
590
+ async function fetchMessageByMessageId(input, ctx) {
591
+ const message = await getMessageResource(
592
+ ctx,
593
+ normalizeMessageId(input.messageId),
594
+ normalizeFormat(input.format, "full")
595
+ );
596
+ return { ...normalizeGmailMessage(message) };
597
+ }
598
+ async function fetchMessageByThreadId(input, ctx) {
599
+ const thread = await getThreadResource(ctx, normalizeThreadId(input.threadId), "full");
600
+ return {
601
+ threadId: thread.id,
602
+ historyId: thread.historyId ?? null,
603
+ messages: (thread.messages ?? []).map((message) => normalizeGmailMessage(message))
604
+ };
605
+ }
606
+ async function addLabelToEmail(input, ctx) {
607
+ const message = asMessageResource(await requestJson(ctx, {
608
+ method: "POST",
609
+ path: ["messages", normalizeMessageId(input.messageId), "modify"],
610
+ body: labelMutationPayload(input)
611
+ }), "message \u54CD\u5E94");
612
+ return { ...normalizeGmailMessage(message) };
613
+ }
614
+ async function batchModifyMessages(input, ctx) {
615
+ await requestEmpty(ctx, {
616
+ method: "POST",
617
+ path: ["messages", "batchModify"],
618
+ body: { ids: toStringArray(input.messageIds), ...labelMutationPayload(input) }
619
+ });
620
+ return { success: true };
621
+ }
622
+ async function messageAction(messageId, action, ctx) {
623
+ const message = asMessageResource(await requestJson(ctx, {
624
+ method: "POST",
625
+ path: ["messages", normalizeMessageId(messageId), action]
626
+ }), "message \u54CD\u5E94");
627
+ return { ...normalizeGmailMessage(message) };
628
+ }
629
+ async function threadAction(threadId, action, ctx, body) {
630
+ const thread = asThreadResource(await requestJson(ctx, {
631
+ method: "POST",
632
+ path: ["threads", normalizeThreadId(threadId), action],
633
+ body
634
+ }), "thread \u54CD\u5E94");
635
+ return {
636
+ threadId: thread.id,
637
+ historyId: thread.historyId ?? null,
638
+ messages: (thread.messages ?? []).map((message) => normalizeGmailMessage(message))
639
+ };
640
+ }
641
+ function moveToTrash(input, ctx) {
642
+ return messageAction(input.messageId, "trash", ctx);
643
+ }
644
+ function untrashMessage(input, ctx) {
645
+ return messageAction(input.messageId, "untrash", ctx);
646
+ }
647
+ function modifyThreadLabels(input, ctx) {
648
+ return threadAction(input.threadId, "modify", ctx, labelMutationPayload(input));
649
+ }
650
+ function moveThreadToTrash(input, ctx) {
651
+ return threadAction(input.threadId, "trash", ctx);
652
+ }
653
+ function untrashThread(input, ctx) {
654
+ return threadAction(input.threadId, "untrash", ctx);
655
+ }
656
+
657
+ // ../plugins/src/gmail/api/drafts.ts
658
+ function asSentMessage(payload) {
659
+ const value = requireRecord(payload, "send \u54CD\u5E94");
660
+ if (typeof value.id !== "string") {
661
+ throw new TBError("unavailable", "Gmail \u7684 send \u54CD\u5E94\u7F3A id", { retryable: true });
662
+ }
663
+ return { id: value.id, threadId: optionalString(value.threadId) };
664
+ }
665
+ function asDraftMutation(payload) {
666
+ const draft = requireRecord(payload, "draft \u54CD\u5E94");
667
+ const message = record(draft.message);
668
+ if (typeof draft.id !== "string") {
669
+ throw new TBError("unavailable", "Gmail \u7684 draft \u54CD\u5E94\u7F3A id", { retryable: true });
670
+ }
671
+ return {
672
+ draftId: draft.id,
673
+ messageId: optionalString(message?.id) ?? "",
674
+ threadId: optionalString(message?.threadId) ?? ""
675
+ };
676
+ }
677
+ async function sendThreadMessage(ctx, threadId, raw) {
678
+ return asSentMessage(await requestJson(ctx, {
679
+ method: "POST",
680
+ path: ["messages", "send"],
681
+ body: { threadId, raw }
682
+ }));
683
+ }
684
+ async function createDraftResource(input, ctx) {
685
+ const recipients = buildRecipients(input);
686
+ return asDraftMutation(await requestJson(ctx, {
687
+ method: "POST",
688
+ path: ["drafts"],
689
+ body: {
690
+ message: {
691
+ raw: encodeMimeMessage({
692
+ to: recipients.to,
693
+ cc: recipients.cc,
694
+ bcc: recipients.bcc,
695
+ subject: trimmedString(input.subject),
696
+ body: trimmedString(input.body) || trimmedString(input.messageBody),
697
+ isHtml: input.isHtml === true,
698
+ from: trimmedString(input.fromEmail)
699
+ }),
700
+ threadId: trimmedString(input.threadId) ? normalizeThreadId(input.threadId) : void 0
701
+ }
702
+ }
703
+ }));
704
+ }
705
+ async function sendEmail(input, ctx) {
706
+ const recipients = buildRecipients(input);
707
+ const sent = asSentMessage(await requestJson(ctx, {
708
+ method: "POST",
709
+ path: ["messages", "send"],
710
+ body: {
711
+ raw: encodeMimeMessage({
712
+ to: recipients.to,
713
+ cc: recipients.cc,
714
+ bcc: recipients.bcc,
715
+ subject: trimmedString(input.subject),
716
+ body: trimmedString(input.body) || trimmedString(input.messageBody),
717
+ isHtml: input.isHtml === true,
718
+ from: trimmedString(input.fromEmail)
719
+ })
720
+ }
721
+ }));
722
+ return { messageId: sent.id };
723
+ }
724
+ async function replyEmail(input, ctx) {
725
+ const message = await getMessageResource(ctx, normalizeMessageId(input.messageId), "full");
726
+ const replyHeaders = resolveReplyHeaders(message);
727
+ const threadId = normalizeThreadId(message.threadId || input.threadId);
728
+ const sent = await sendThreadMessage(ctx, threadId, encodeMimeMessage({
729
+ to: [replyHeaders.to],
730
+ subject: replyHeaders.subject,
731
+ body: trimmedString(input.body),
732
+ inReplyTo: replyHeaders.inReplyTo,
733
+ references: replyHeaders.references
734
+ }));
735
+ return { messageId: sent.id };
736
+ }
737
+ async function replyToThread(input, ctx) {
738
+ const thread = await getThreadResource(ctx, normalizeThreadId(input.threadId), "full");
739
+ const target = thread.messages?.at(-1);
740
+ if (target === void 0) {
741
+ throw new TBError("invalid_argument", "thread \u91CC\u6CA1\u6709\u4EFB\u4F55\u6D88\u606F,\u65E0\u6CD5\u56DE\u590D");
742
+ }
743
+ const recipients = buildRecipients(input);
744
+ const replyHeaders = resolveReplyHeaders(target);
745
+ const sent = await sendThreadMessage(ctx, thread.id, encodeMimeMessage({
746
+ to: recipients.to.length > 0 ? recipients.to : [replyHeaders.to],
747
+ cc: recipients.cc,
748
+ bcc: recipients.bcc,
749
+ subject: replyHeaders.subject,
750
+ body: trimmedString(input.messageBody) || trimmedString(input.body),
751
+ isHtml: input.isHtml === true,
752
+ inReplyTo: replyHeaders.inReplyTo,
753
+ references: replyHeaders.references
754
+ }));
755
+ return { messageId: sent.id, threadId: sent.threadId ?? thread.id };
756
+ }
757
+ async function createDraft(input, ctx) {
758
+ const { draftId } = await createDraftResource(input, ctx);
759
+ return { draftId };
760
+ }
761
+ async function createEmailDraft(input, ctx) {
762
+ return { ...await createDraftResource(input, ctx) };
763
+ }
764
+ async function listDrafts(input, ctx) {
765
+ const payload = requireRecord(await requestJson(ctx, {
766
+ path: ["drafts"],
767
+ query: { pageToken: input.pageToken, maxResults: input.maxResults }
768
+ }), "drafts \u54CD\u5E94");
769
+ const drafts = recordArray(payload.drafts, "drafts");
770
+ const nextPageToken = optionalString(payload.nextPageToken) ?? null;
771
+ if (input.verbose === true) {
772
+ const hydrated = await hydrateInBatches(drafts, (draft) => getDraftResource(ctx, String(draft.id), "full"));
773
+ return {
774
+ drafts: hydrated.map((draft) => ({ id: draft.id, message: normalizeGmailMessage(draft.message) })),
775
+ nextPageToken
776
+ };
777
+ }
778
+ return {
779
+ drafts: drafts.map((draft) => ({
780
+ id: String(draft.id),
781
+ // 非 verbose 时列表接口只回 id 对,其余字段一律缺席 —— 用空串而不是 null 占位,
782
+ // 与出参声明(message 的字段都是 string)对齐。
783
+ message: {
784
+ messageId: optionalString(record(draft.message)?.id) ?? "",
785
+ threadId: optionalString(record(draft.message)?.threadId) ?? ""
786
+ }
787
+ })),
788
+ nextPageToken
789
+ };
790
+ }
791
+ async function getDraft(input, ctx) {
792
+ const draft = await getDraftResource(
793
+ ctx,
794
+ normalizeMessageId(input.draftId),
795
+ normalizeFormat(input.format, "full")
796
+ );
797
+ return { id: draft.id, message: normalizeGmailMessage(draft.message) };
798
+ }
799
+ async function updateDraft(input, ctx) {
800
+ const draftId = normalizeMessageId(input.draftId);
801
+ const existing = await getDraftResource(ctx, draftId, "full");
802
+ const headers = existing.message.payload?.headers ?? [];
803
+ const next = buildRecipients(input);
804
+ const recipients = buildRecipients({
805
+ to: next.to.length > 0 ? next.to : parseAddressList(readHeader(headers, "To")),
806
+ cc: next.cc.length > 0 ? next.cc : parseAddressList(readHeader(headers, "Cc")),
807
+ bcc: next.bcc.length > 0 ? next.bcc : parseAddressList(readHeader(headers, "Bcc"))
808
+ });
809
+ const existingBody = extractBodyContent(existing.message.payload ?? null);
810
+ const body = Object.hasOwn(input, "body") ? trimmedString(input.body) : Object.hasOwn(input, "messageBody") ? trimmedString(input.messageBody) : existingBody.body;
811
+ const threadId = trimmedString(input.threadId) || existing.message.threadId;
812
+ const mutation = asDraftMutation(await requestJson(ctx, {
813
+ method: "PUT",
814
+ path: ["drafts", draftId],
815
+ body: {
816
+ id: draftId,
817
+ message: {
818
+ raw: encodeMimeMessage({
819
+ to: recipients.to,
820
+ cc: recipients.cc,
821
+ bcc: recipients.bcc,
822
+ subject: trimmedString(input.subject) || readHeader(headers, "Subject"),
823
+ body,
824
+ // 没显式给 isHtml 就沿用原草稿的正文类型,免得一次改标题把 HTML 信降成纯文本。
825
+ isHtml: typeof input.isHtml === "boolean" ? input.isHtml : existingBody.isHtml,
826
+ from: trimmedString(input.fromEmail) || firstAddress(readHeader(headers, "From"))
827
+ }),
828
+ threadId: threadId ? normalizeThreadId(threadId) : void 0
829
+ }
830
+ }
831
+ }));
832
+ return { ...mutation };
833
+ }
834
+ async function sendDraft(input, ctx) {
835
+ const sent = asSentMessage(await requestJson(ctx, {
836
+ method: "POST",
837
+ path: ["drafts", "send"],
838
+ body: { id: normalizeMessageId(input.draftId) }
839
+ }));
840
+ return { messageId: sent.id, threadId: sent.threadId ?? null };
841
+ }
842
+ async function deleteDraft(input, ctx) {
843
+ await requestEmpty(ctx, { method: "DELETE", path: ["drafts", normalizeMessageId(input.draftId)] });
844
+ return { success: true };
845
+ }
846
+
847
+ // ../plugins/src/gmail/api/labels.ts
848
+ async function listLabels(_input, ctx) {
849
+ const payload = await requestRecord(ctx, { path: ["labels"] }, "labels \u54CD\u5E94");
850
+ return { labels: recordArray(payload.labels, "labels") };
851
+ }
852
+ async function getLabel(input, ctx) {
853
+ return requestRecord(ctx, { path: ["labels", normalizeMessageId(input.labelId)] }, "label \u54CD\u5E94");
854
+ }
855
+ async function createLabel(input, ctx) {
856
+ return requestRecord(ctx, {
857
+ method: "POST",
858
+ path: ["labels"],
859
+ body: bodyFromInput(input, ["labelId"])
860
+ }, "label \u54CD\u5E94");
861
+ }
862
+ async function patchLabel(input, ctx) {
863
+ return requestRecord(ctx, {
864
+ method: "PATCH",
865
+ path: ["labels", normalizeMessageId(input.labelId)],
866
+ body: bodyFromInput(input, ["labelId"])
867
+ }, "label \u54CD\u5E94");
868
+ }
869
+ async function updateLabel(input, ctx) {
870
+ return requestRecord(ctx, {
871
+ method: "PUT",
872
+ path: ["labels", normalizeMessageId(input.labelId)],
873
+ body: bodyFromInput(input, ["labelId"])
874
+ }, "label \u54CD\u5E94");
875
+ }
876
+ async function deleteLabel(input, ctx) {
877
+ await requestEmpty(ctx, { method: "DELETE", path: ["labels", normalizeMessageId(input.labelId)] });
878
+ return { success: true };
879
+ }
880
+
881
+ // ../plugins/src/gmail/schema.ts
882
+ import { z } from "zod/v4";
883
+ var searchThreadsInput = z.strictObject({
884
+ query: z.string().describe("Gmail search query."),
885
+ maxResults: z.int().min(1).max(500).describe("Maximum number of results to return.").optional()
886
+ }).describe("The input payload for this action.");
887
+ var searchThreadsOutput = z.strictObject({
888
+ threads: z.array(z.looseObject({
889
+ threadId: z.string().min(1).describe("Gmail thread ID."),
890
+ historyId: z.string().describe("Mailbox history checkpoint ID.").nullable().optional(),
891
+ snippet: z.string().describe("Thread snippet.").optional(),
892
+ messages: z.array(z.looseObject({
893
+ messageId: z.string().min(1).describe("Gmail message ID."),
894
+ threadId: z.string().min(1).describe("Gmail thread ID."),
895
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
896
+ subject: z.string().describe("Message subject."),
897
+ sender: z.string().describe("Message sender."),
898
+ to: z.string().describe("Message recipients."),
899
+ messageTimestamp: z.string().describe("Message timestamp."),
900
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
901
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
902
+ messageText: z.string().describe("Extracted message body text.").optional(),
903
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
904
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
905
+ }).describe("Normalized Gmail message.")).describe("Messages in the thread.").optional()
906
+ }).describe("Gmail thread.")).describe("Matching thread summaries.")
907
+ }).describe("Thread search result.");
908
+ var listThreadsInput = z.strictObject({
909
+ query: z.string().describe("Gmail search query.").optional(),
910
+ verbose: z.boolean().describe("Hydrate each thread.").optional(),
911
+ maxResults: z.int().min(1).max(500).describe("Maximum number of results to return.").optional(),
912
+ pageToken: z.string().describe("Opaque pagination token returned by Gmail.").optional()
913
+ }).describe("The input payload for this action.");
914
+ var listThreadsOutput = z.strictObject({
915
+ threads: z.array(z.looseObject({
916
+ threadId: z.string().min(1).describe("Gmail thread ID."),
917
+ historyId: z.string().describe("Mailbox history checkpoint ID.").nullable().optional(),
918
+ snippet: z.string().describe("Thread snippet.").optional(),
919
+ messages: z.array(z.looseObject({
920
+ messageId: z.string().min(1).describe("Gmail message ID."),
921
+ threadId: z.string().min(1).describe("Gmail thread ID."),
922
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
923
+ subject: z.string().describe("Message subject."),
924
+ sender: z.string().describe("Message sender."),
925
+ to: z.string().describe("Message recipients."),
926
+ messageTimestamp: z.string().describe("Message timestamp."),
927
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
928
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
929
+ messageText: z.string().describe("Extracted message body text.").optional(),
930
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
931
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
932
+ }).describe("Normalized Gmail message.")).describe("Messages in the thread.").optional()
933
+ }).describe("Gmail thread.")).describe("Returned threads."),
934
+ nextPageToken: z.string().describe("Opaque pagination token returned by Gmail.").nullable().optional(),
935
+ resultSizeEstimate: z.int().describe("Approximate result count.").optional()
936
+ }).describe("Thread list result.");
937
+ var fetchEmailsInput = z.strictObject({
938
+ query: z.string().describe("Gmail search query.").optional(),
939
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
940
+ includeSpamTrash: z.boolean().describe("Whether to include Spam and Trash.").optional(),
941
+ detail: z.enum(["ids", "summary", "full"]).default("summary").describe("Message detail level.").optional(),
942
+ maxResults: z.int().min(1).max(500).describe("Maximum number of results to return.").optional(),
943
+ pageToken: z.string().describe("Opaque pagination token returned by Gmail.").optional()
944
+ }).describe("The input payload for this action.");
945
+ var fetchEmailsOutput = z.strictObject({
946
+ messages: z.array(z.union([z.looseObject({
947
+ messageId: z.string().min(1).describe("Gmail message ID."),
948
+ threadId: z.string().min(1).describe("Gmail thread ID."),
949
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
950
+ subject: z.string().describe("Message subject."),
951
+ sender: z.string().describe("Message sender."),
952
+ to: z.string().describe("Message recipients."),
953
+ messageTimestamp: z.string().describe("Message timestamp.")
954
+ }).describe("Normalized Gmail message summary."), z.looseObject({
955
+ messageId: z.string().min(1).describe("Gmail message ID."),
956
+ threadId: z.string().min(1).describe("Gmail thread ID."),
957
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
958
+ subject: z.string().describe("Message subject."),
959
+ sender: z.string().describe("Message sender."),
960
+ to: z.string().describe("Message recipients."),
961
+ messageTimestamp: z.string().describe("Message timestamp."),
962
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
963
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
964
+ messageText: z.string().describe("Extracted message body text.").optional(),
965
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
966
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
967
+ }).describe("Normalized Gmail message."), z.looseObject({}).describe("Gmail API object.")])).describe("Returned messages."),
968
+ nextPageToken: z.string().describe("Opaque pagination token returned by Gmail.").nullable().optional(),
969
+ resultSizeEstimate: z.int().describe("Approximate result count.").optional()
970
+ }).describe("Message list result.");
971
+ var getMessageInput = z.strictObject({
972
+ messageId: z.string().min(1).describe("Gmail message ID.")
973
+ }).describe("The input payload for this action.");
974
+ var getMessageOutput = z.strictObject({
975
+ messageId: z.string().min(1).describe("Gmail message ID."),
976
+ threadId: z.string().min(1).describe("Gmail thread ID."),
977
+ subject: z.string().optional(),
978
+ from: z.string().optional(),
979
+ to: z.string().optional(),
980
+ date: z.string().optional(),
981
+ body: z.string().optional()
982
+ }).describe("Simplified Gmail message.");
983
+ var fetchMessageByMessageIdInput = z.strictObject({
984
+ messageId: z.string().min(1).describe("Gmail message ID."),
985
+ format: z.enum(["minimal", "full", "raw", "metadata"]).describe("Gmail response format to request.").optional()
986
+ }).describe("The input payload for this action.");
987
+ var fetchMessageByMessageIdOutput = z.looseObject({
988
+ messageId: z.string().min(1).describe("Gmail message ID."),
989
+ threadId: z.string().min(1).describe("Gmail thread ID."),
990
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
991
+ subject: z.string().describe("Message subject."),
992
+ sender: z.string().describe("Message sender."),
993
+ to: z.string().describe("Message recipients."),
994
+ messageTimestamp: z.string().describe("Message timestamp."),
995
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
996
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
997
+ messageText: z.string().describe("Extracted message body text.").optional(),
998
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
999
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1000
+ }).describe("Normalized Gmail message.");
1001
+ var fetchMessageByThreadIdInput = z.strictObject({
1002
+ threadId: z.string().min(1).describe("Gmail thread ID.")
1003
+ }).describe("The input payload for this action.");
1004
+ var fetchMessageByThreadIdOutput = z.looseObject({
1005
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1006
+ historyId: z.string().describe("Mailbox history checkpoint ID.").nullable().optional(),
1007
+ snippet: z.string().describe("Thread snippet.").optional(),
1008
+ messages: z.array(z.looseObject({
1009
+ messageId: z.string().min(1).describe("Gmail message ID."),
1010
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1011
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1012
+ subject: z.string().describe("Message subject."),
1013
+ sender: z.string().describe("Message sender."),
1014
+ to: z.string().describe("Message recipients."),
1015
+ messageTimestamp: z.string().describe("Message timestamp."),
1016
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1017
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1018
+ messageText: z.string().describe("Extracted message body text.").optional(),
1019
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1020
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1021
+ }).describe("Normalized Gmail message.")).describe("Messages in the thread.").optional()
1022
+ }).describe("Gmail thread.");
1023
+ var getProfileInput = z.strictObject({
1024
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1025
+ }).describe("The input payload for this action.");
1026
+ var getProfileOutput = z.strictObject({
1027
+ emailAddress: z.string(),
1028
+ messagesTotal: z.int(),
1029
+ threadsTotal: z.int(),
1030
+ historyId: z.string()
1031
+ }).describe("Gmail profile.");
1032
+ var sendEmailInput = z.strictObject({
1033
+ recipientEmail: z.string().describe("Primary recipient email address.").optional(),
1034
+ to: z.string().describe("Primary recipient email address.").optional(),
1035
+ extraRecipients: z.array(z.string()).describe("Additional To recipients.").optional(),
1036
+ cc: z.union([z.string(), z.array(z.string())]).describe("Cc recipients.").optional(),
1037
+ bcc: z.union([z.string(), z.array(z.string())]).describe("Bcc recipients.").optional(),
1038
+ subject: z.string().describe("Email subject line.").optional(),
1039
+ body: z.string().describe("Email body content.").optional(),
1040
+ messageBody: z.string().describe("Reply or draft body content.").optional(),
1041
+ isHtml: z.boolean().describe("Whether the body is HTML.").optional(),
1042
+ fromEmail: z.string().describe("Verified Gmail send-as alias.").optional()
1043
+ }).describe("The input payload for this action.");
1044
+ var sendEmailOutput = z.strictObject({
1045
+ messageId: z.string().min(1).describe("Gmail message ID.")
1046
+ }).describe("Sent message result.");
1047
+ var replyEmailInput = z.strictObject({
1048
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1049
+ messageId: z.string().min(1).describe("Gmail message ID."),
1050
+ body: z.string().describe("Reply body.")
1051
+ }).describe("The input payload for this action.");
1052
+ var replyEmailOutput = z.strictObject({
1053
+ messageId: z.string().min(1).describe("Gmail message ID.")
1054
+ }).describe("Reply result.");
1055
+ var replyToThreadInput = z.strictObject({
1056
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1057
+ recipientEmail: z.string().describe("Primary recipient email address.").optional(),
1058
+ to: z.string().describe("Primary recipient email address.").optional(),
1059
+ extraRecipients: z.array(z.string()).describe("Additional To recipients.").optional(),
1060
+ cc: z.union([z.string(), z.array(z.string())]).describe("Cc recipients.").optional(),
1061
+ bcc: z.union([z.string(), z.array(z.string())]).describe("Bcc recipients.").optional(),
1062
+ subject: z.string().describe("Email subject line.").optional(),
1063
+ body: z.string().describe("Email body content.").optional(),
1064
+ messageBody: z.string().describe("Reply or draft body content.").optional(),
1065
+ isHtml: z.boolean().describe("Whether the body is HTML.").optional(),
1066
+ fromEmail: z.string().describe("Verified Gmail send-as alias.").optional()
1067
+ }).describe("The input payload for this action.");
1068
+ var replyToThreadOutput = z.strictObject({
1069
+ messageId: z.string().min(1).describe("Gmail message ID."),
1070
+ threadId: z.string().min(1).describe("Gmail thread ID.").optional()
1071
+ }).describe("Thread reply result.");
1072
+ var createDraftInput = z.strictObject({
1073
+ to: z.string(),
1074
+ subject: z.string(),
1075
+ body: z.string(),
1076
+ cc: z.union([z.string(), z.array(z.string())]).optional()
1077
+ }).describe("The input payload for this action.");
1078
+ var createDraftOutput = z.strictObject({
1079
+ draftId: z.string().min(1).describe("Gmail draft ID.")
1080
+ }).describe("Created draft result.");
1081
+ var createEmailDraftInput = z.strictObject({
1082
+ recipientEmail: z.string().describe("Primary recipient email address.").optional(),
1083
+ to: z.string().describe("Primary recipient email address.").optional(),
1084
+ extraRecipients: z.array(z.string()).describe("Additional To recipients.").optional(),
1085
+ cc: z.union([z.string(), z.array(z.string())]).describe("Cc recipients.").optional(),
1086
+ bcc: z.union([z.string(), z.array(z.string())]).describe("Bcc recipients.").optional(),
1087
+ subject: z.string().describe("Email subject line.").optional(),
1088
+ body: z.string().describe("Email body content.").optional(),
1089
+ messageBody: z.string().describe("Reply or draft body content.").optional(),
1090
+ isHtml: z.boolean().describe("Whether the body is HTML.").optional(),
1091
+ fromEmail: z.string().describe("Verified Gmail send-as alias.").optional(),
1092
+ threadId: z.string().min(1).describe("Gmail thread ID.").optional()
1093
+ }).describe("The input payload for this action.");
1094
+ var createEmailDraftOutput = z.strictObject({
1095
+ draftId: z.string().min(1).describe("Gmail draft ID."),
1096
+ messageId: z.string().min(1).describe("Gmail message ID.").optional(),
1097
+ threadId: z.string().min(1).describe("Gmail thread ID.").optional()
1098
+ }).describe("Created draft.");
1099
+ var listDraftsInput = z.strictObject({
1100
+ verbose: z.boolean().describe("Hydrate each draft.").optional(),
1101
+ maxResults: z.int().min(1).max(500).describe("Maximum number of results to return.").optional(),
1102
+ pageToken: z.string().describe("Opaque pagination token returned by Gmail.").optional()
1103
+ }).describe("The input payload for this action.");
1104
+ var listDraftsOutput = z.strictObject({
1105
+ drafts: z.array(z.looseObject({
1106
+ id: z.string().min(1).describe("Gmail draft ID."),
1107
+ message: z.looseObject({
1108
+ messageId: z.string().min(1).describe("Gmail message ID."),
1109
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1110
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1111
+ subject: z.string().describe("Message subject."),
1112
+ sender: z.string().describe("Message sender."),
1113
+ to: z.string().describe("Message recipients."),
1114
+ messageTimestamp: z.string().describe("Message timestamp."),
1115
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1116
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1117
+ messageText: z.string().describe("Extracted message body text.").optional(),
1118
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1119
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1120
+ }).describe("Normalized Gmail message.")
1121
+ }).describe("Gmail draft.")),
1122
+ nextPageToken: z.string().describe("Opaque pagination token returned by Gmail.").nullable().optional()
1123
+ }).describe("Draft list result.");
1124
+ var getDraftInput = z.strictObject({
1125
+ draftId: z.string().min(1).describe("Gmail draft ID."),
1126
+ format: z.enum(["minimal", "full", "raw", "metadata"]).describe("Gmail response format to request.").optional()
1127
+ }).describe("The input payload for this action.");
1128
+ var getDraftOutput = z.looseObject({
1129
+ id: z.string().min(1).describe("Gmail draft ID."),
1130
+ message: z.looseObject({
1131
+ messageId: z.string().min(1).describe("Gmail message ID."),
1132
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1133
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1134
+ subject: z.string().describe("Message subject."),
1135
+ sender: z.string().describe("Message sender."),
1136
+ to: z.string().describe("Message recipients."),
1137
+ messageTimestamp: z.string().describe("Message timestamp."),
1138
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1139
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1140
+ messageText: z.string().describe("Extracted message body text.").optional(),
1141
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1142
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1143
+ }).describe("Normalized Gmail message.")
1144
+ }).describe("Gmail draft.");
1145
+ var updateDraftInput = z.strictObject({
1146
+ draftId: z.string().min(1).describe("Gmail draft ID."),
1147
+ recipientEmail: z.string().describe("Primary recipient email address.").optional(),
1148
+ to: z.string().describe("Primary recipient email address.").optional(),
1149
+ extraRecipients: z.array(z.string()).describe("Additional To recipients.").optional(),
1150
+ cc: z.union([z.string(), z.array(z.string())]).describe("Cc recipients.").optional(),
1151
+ bcc: z.union([z.string(), z.array(z.string())]).describe("Bcc recipients.").optional(),
1152
+ subject: z.string().describe("Email subject line.").optional(),
1153
+ body: z.string().describe("Email body content.").optional(),
1154
+ messageBody: z.string().describe("Reply or draft body content.").optional(),
1155
+ isHtml: z.boolean().describe("Whether the body is HTML.").optional(),
1156
+ fromEmail: z.string().describe("Verified Gmail send-as alias.").optional(),
1157
+ threadId: z.string().min(1).describe("Gmail thread ID.").optional()
1158
+ }).describe("The input payload for this action.");
1159
+ var updateDraftOutput = z.strictObject({
1160
+ draftId: z.string().min(1).describe("Gmail draft ID."),
1161
+ messageId: z.string().min(1).describe("Gmail message ID.").optional(),
1162
+ threadId: z.string().min(1).describe("Gmail thread ID.").optional()
1163
+ }).describe("Updated draft.");
1164
+ var sendDraftInput = z.strictObject({
1165
+ draftId: z.string().min(1).describe("Gmail draft ID.")
1166
+ }).describe("The input payload for this action.");
1167
+ var sendDraftOutput = z.strictObject({
1168
+ messageId: z.string().min(1).describe("Gmail message ID."),
1169
+ threadId: z.string().min(1).describe("Gmail thread ID.").nullable().optional()
1170
+ }).describe("Sent draft result.");
1171
+ var deleteDraftInput = z.strictObject({
1172
+ draftId: z.string().min(1).describe("Gmail draft ID."),
1173
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1174
+ }).describe("The input payload for this action.");
1175
+ var deleteDraftOutput = z.strictObject({
1176
+ success: z.boolean().describe("Whether the operation completed successfully.")
1177
+ }).describe("Operation result.");
1178
+ var listLabelsInput = z.strictObject({
1179
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1180
+ }).describe("The input payload for this action.");
1181
+ var listLabelsOutput = z.strictObject({
1182
+ labels: z.array(z.looseObject({
1183
+ id: z.string().min(1).describe("Gmail label ID."),
1184
+ name: z.string().describe("Label display name."),
1185
+ type: z.string().describe("Label type."),
1186
+ messageListVisibility: z.enum(["show", "hide"]).describe("Whether messages with this label appear in the message list.").optional(),
1187
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).describe("Whether the label appears in the label list.").optional(),
1188
+ color: z.strictObject({
1189
+ textColor: z.string().describe("Hex text color.").optional(),
1190
+ backgroundColor: z.string().describe("Hex background color.").optional()
1191
+ }).describe("Gmail label color.").optional()
1192
+ }).describe("Gmail label."))
1193
+ }).describe("Label list.");
1194
+ var getLabelInput = z.strictObject({
1195
+ labelId: z.string().min(1).describe("Gmail label ID."),
1196
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1197
+ }).describe("The input payload for this action.");
1198
+ var getLabelOutput = z.looseObject({
1199
+ id: z.string().min(1).describe("Gmail label ID."),
1200
+ name: z.string().describe("Label display name."),
1201
+ type: z.string().describe("Label type."),
1202
+ messageListVisibility: z.enum(["show", "hide"]).describe("Whether messages with this label appear in the message list.").optional(),
1203
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).describe("Whether the label appears in the label list.").optional(),
1204
+ color: z.strictObject({
1205
+ textColor: z.string().describe("Hex text color.").optional(),
1206
+ backgroundColor: z.string().describe("Hex background color.").optional()
1207
+ }).describe("Gmail label color.").optional()
1208
+ }).describe("Gmail label.");
1209
+ var createLabelInput = z.strictObject({
1210
+ name: z.string().min(1).describe("Display name for the new label."),
1211
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).optional(),
1212
+ messageListVisibility: z.enum(["show", "hide"]).optional(),
1213
+ color: z.strictObject({
1214
+ textColor: z.string().describe("Hex text color.").optional(),
1215
+ backgroundColor: z.string().describe("Hex background color.").optional()
1216
+ }).describe("Gmail label color.").optional(),
1217
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1218
+ }).describe("The input payload for this action.");
1219
+ var createLabelOutput = z.looseObject({
1220
+ id: z.string().min(1).describe("Gmail label ID."),
1221
+ name: z.string().describe("Label display name."),
1222
+ type: z.string().describe("Label type."),
1223
+ messageListVisibility: z.enum(["show", "hide"]).describe("Whether messages with this label appear in the message list.").optional(),
1224
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).describe("Whether the label appears in the label list.").optional(),
1225
+ color: z.strictObject({
1226
+ textColor: z.string().describe("Hex text color.").optional(),
1227
+ backgroundColor: z.string().describe("Hex background color.").optional()
1228
+ }).describe("Gmail label color.").optional()
1229
+ }).describe("Gmail label.");
1230
+ var patchLabelInput = z.strictObject({
1231
+ labelId: z.string().min(1).describe("Gmail label ID."),
1232
+ name: z.string().describe("Updated display name for the label.").optional(),
1233
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).optional(),
1234
+ messageListVisibility: z.enum(["show", "hide"]).optional(),
1235
+ color: z.strictObject({
1236
+ textColor: z.string().describe("Hex text color.").optional(),
1237
+ backgroundColor: z.string().describe("Hex background color.").optional()
1238
+ }).describe("Gmail label color.").optional(),
1239
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1240
+ }).describe("The input payload for this action.");
1241
+ var patchLabelOutput = z.looseObject({
1242
+ id: z.string().min(1).describe("Gmail label ID."),
1243
+ name: z.string().describe("Label display name."),
1244
+ type: z.string().describe("Label type."),
1245
+ messageListVisibility: z.enum(["show", "hide"]).describe("Whether messages with this label appear in the message list.").optional(),
1246
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).describe("Whether the label appears in the label list.").optional(),
1247
+ color: z.strictObject({
1248
+ textColor: z.string().describe("Hex text color.").optional(),
1249
+ backgroundColor: z.string().describe("Hex background color.").optional()
1250
+ }).describe("Gmail label color.").optional()
1251
+ }).describe("Gmail label.");
1252
+ var updateLabelInput = z.strictObject({
1253
+ labelId: z.string().min(1).describe("Gmail label ID."),
1254
+ name: z.string().describe("Updated display name for the label.").optional(),
1255
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).optional(),
1256
+ messageListVisibility: z.enum(["show", "hide"]).optional(),
1257
+ color: z.strictObject({
1258
+ textColor: z.string().describe("Hex text color.").optional(),
1259
+ backgroundColor: z.string().describe("Hex background color.").optional()
1260
+ }).describe("Gmail label color.").optional(),
1261
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1262
+ }).describe("The input payload for this action.");
1263
+ var updateLabelOutput = z.looseObject({
1264
+ id: z.string().min(1).describe("Gmail label ID."),
1265
+ name: z.string().describe("Label display name."),
1266
+ type: z.string().describe("Label type."),
1267
+ messageListVisibility: z.enum(["show", "hide"]).describe("Whether messages with this label appear in the message list.").optional(),
1268
+ labelListVisibility: z.enum(["labelShow", "labelShowIfUnread", "labelHide"]).describe("Whether the label appears in the label list.").optional(),
1269
+ color: z.strictObject({
1270
+ textColor: z.string().describe("Hex text color.").optional(),
1271
+ backgroundColor: z.string().describe("Hex background color.").optional()
1272
+ }).describe("Gmail label color.").optional()
1273
+ }).describe("Gmail label.");
1274
+ var deleteLabelInput = z.strictObject({
1275
+ labelId: z.string().min(1).describe("Gmail label ID."),
1276
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1277
+ }).describe("The input payload for this action.");
1278
+ var deleteLabelOutput = z.strictObject({
1279
+ success: z.boolean().describe("Whether the operation completed successfully.")
1280
+ }).describe("Operation result.");
1281
+ var addLabelToEmailInput = z.strictObject({
1282
+ messageId: z.string().min(1).describe("Gmail message ID."),
1283
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1284
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1285
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1286
+ }).describe("The input payload for this action.");
1287
+ var addLabelToEmailOutput = z.looseObject({
1288
+ messageId: z.string().min(1).describe("Gmail message ID."),
1289
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1290
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1291
+ subject: z.string().describe("Message subject."),
1292
+ sender: z.string().describe("Message sender."),
1293
+ to: z.string().describe("Message recipients."),
1294
+ messageTimestamp: z.string().describe("Message timestamp."),
1295
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1296
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1297
+ messageText: z.string().describe("Extracted message body text.").optional(),
1298
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1299
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1300
+ }).describe("Normalized Gmail message.");
1301
+ var batchModifyMessagesInput = z.strictObject({
1302
+ messageIds: z.array(z.string().min(1).describe("Gmail message ID.")).describe("Message IDs to modify."),
1303
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1304
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1305
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1306
+ }).describe("The input payload for this action.");
1307
+ var batchModifyMessagesOutput = z.strictObject({
1308
+ success: z.boolean().describe("Whether the operation completed successfully.")
1309
+ }).describe("Operation result.");
1310
+ var moveToTrashInput = z.strictObject({
1311
+ messageId: z.string().min(1).describe("Gmail message ID."),
1312
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1313
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1314
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1315
+ }).describe("The input payload for this action.");
1316
+ var moveToTrashOutput = z.looseObject({
1317
+ messageId: z.string().min(1).describe("Gmail message ID."),
1318
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1319
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1320
+ subject: z.string().describe("Message subject."),
1321
+ sender: z.string().describe("Message sender."),
1322
+ to: z.string().describe("Message recipients."),
1323
+ messageTimestamp: z.string().describe("Message timestamp."),
1324
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1325
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1326
+ messageText: z.string().describe("Extracted message body text.").optional(),
1327
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1328
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1329
+ }).describe("Normalized Gmail message.");
1330
+ var untrashMessageInput = z.strictObject({
1331
+ messageId: z.string().min(1).describe("Gmail message ID."),
1332
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1333
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1334
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1335
+ }).describe("The input payload for this action.");
1336
+ var untrashMessageOutput = z.looseObject({
1337
+ messageId: z.string().min(1).describe("Gmail message ID."),
1338
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1339
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1340
+ subject: z.string().describe("Message subject."),
1341
+ sender: z.string().describe("Message sender."),
1342
+ to: z.string().describe("Message recipients."),
1343
+ messageTimestamp: z.string().describe("Message timestamp."),
1344
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1345
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1346
+ messageText: z.string().describe("Extracted message body text.").optional(),
1347
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1348
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1349
+ }).describe("Normalized Gmail message.");
1350
+ var modifyThreadLabelsInput = z.strictObject({
1351
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1352
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1353
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1354
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1355
+ }).describe("The input payload for this action.");
1356
+ var modifyThreadLabelsOutput = z.looseObject({
1357
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1358
+ historyId: z.string().describe("Mailbox history checkpoint ID.").nullable().optional(),
1359
+ snippet: z.string().describe("Thread snippet.").optional(),
1360
+ messages: z.array(z.looseObject({
1361
+ messageId: z.string().min(1).describe("Gmail message ID."),
1362
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1363
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1364
+ subject: z.string().describe("Message subject."),
1365
+ sender: z.string().describe("Message sender."),
1366
+ to: z.string().describe("Message recipients."),
1367
+ messageTimestamp: z.string().describe("Message timestamp."),
1368
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1369
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1370
+ messageText: z.string().describe("Extracted message body text.").optional(),
1371
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1372
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1373
+ }).describe("Normalized Gmail message.")).describe("Messages in the thread.").optional()
1374
+ }).describe("Gmail thread.");
1375
+ var moveThreadToTrashInput = z.strictObject({
1376
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1377
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1378
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1379
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1380
+ }).describe("The input payload for this action.");
1381
+ var moveThreadToTrashOutput = z.looseObject({
1382
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1383
+ historyId: z.string().describe("Mailbox history checkpoint ID.").nullable().optional(),
1384
+ snippet: z.string().describe("Thread snippet.").optional(),
1385
+ messages: z.array(z.looseObject({
1386
+ messageId: z.string().min(1).describe("Gmail message ID."),
1387
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1388
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1389
+ subject: z.string().describe("Message subject."),
1390
+ sender: z.string().describe("Message sender."),
1391
+ to: z.string().describe("Message recipients."),
1392
+ messageTimestamp: z.string().describe("Message timestamp."),
1393
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1394
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1395
+ messageText: z.string().describe("Extracted message body text.").optional(),
1396
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1397
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1398
+ }).describe("Normalized Gmail message.")).describe("Messages in the thread.").optional()
1399
+ }).describe("Gmail thread.");
1400
+ var untrashThreadInput = z.strictObject({
1401
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1402
+ addLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1403
+ removeLabelIds: z.array(z.string().min(1)).describe("Gmail label IDs.").optional(),
1404
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1405
+ }).describe("The input payload for this action.");
1406
+ var untrashThreadOutput = z.looseObject({
1407
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1408
+ historyId: z.string().describe("Mailbox history checkpoint ID.").nullable().optional(),
1409
+ snippet: z.string().describe("Thread snippet.").optional(),
1410
+ messages: z.array(z.looseObject({
1411
+ messageId: z.string().min(1).describe("Gmail message ID."),
1412
+ threadId: z.string().min(1).describe("Gmail thread ID."),
1413
+ labelIds: z.array(z.string().min(1)).describe("Gmail label IDs."),
1414
+ subject: z.string().describe("Message subject."),
1415
+ sender: z.string().describe("Message sender."),
1416
+ to: z.string().describe("Message recipients."),
1417
+ messageTimestamp: z.string().describe("Message timestamp."),
1418
+ preview: z.looseObject({}).describe("Gmail API object.").optional(),
1419
+ payload: z.looseObject({}).describe("Gmail API object.").nullable().optional(),
1420
+ messageText: z.string().describe("Extracted message body text.").optional(),
1421
+ attachmentList: z.array(z.looseObject({}).describe("Gmail API object.")).describe("Message attachments.").optional(),
1422
+ raw: z.string().describe("Raw RFC 2822 message when requested.").optional()
1423
+ }).describe("Normalized Gmail message.")).describe("Messages in the thread.").optional()
1424
+ }).describe("Gmail thread.");
1425
+ var listHistoryInput = z.strictObject({
1426
+ startHistoryId: z.string().min(1).describe("History checkpoint."),
1427
+ pageToken: z.string().describe("Opaque pagination token returned by Gmail.").optional(),
1428
+ maxResults: z.int().min(1).max(500).describe("Maximum number of results to return.").optional(),
1429
+ labelId: z.string().min(1).describe("Gmail label ID.").optional(),
1430
+ historyTypes: z.array(z.string()).describe("History event types to include.").optional(),
1431
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1432
+ }).describe("The input payload for this action.");
1433
+ var listHistoryOutput = z.strictObject({
1434
+ history: z.array(z.looseObject({}).describe("Gmail API object.")),
1435
+ historyId: z.string(),
1436
+ nextPageToken: z.string().describe("Opaque pagination token returned by Gmail.").nullable().optional()
1437
+ }).describe("Mailbox history result.");
1438
+ var listFiltersInput = z.strictObject({
1439
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1440
+ }).describe("The input payload for this action.");
1441
+ var listFiltersOutput = z.strictObject({
1442
+ filters: z.array(z.looseObject({
1443
+ id: z.string().min(1).describe("Gmail filter ID."),
1444
+ criteria: z.looseObject({}).describe("Gmail API object.").optional(),
1445
+ action: z.looseObject({}).describe("Gmail API object.").optional()
1446
+ }).describe("Gmail filter."))
1447
+ }).describe("Filter list.");
1448
+ var getFilterInput = z.strictObject({
1449
+ filterId: z.string().min(1).describe("Gmail filter ID."),
1450
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1451
+ }).describe("The input payload for this action.");
1452
+ var getFilterOutput = z.looseObject({
1453
+ id: z.string().min(1).describe("Gmail filter ID."),
1454
+ criteria: z.looseObject({}).describe("Gmail API object.").optional(),
1455
+ action: z.looseObject({}).describe("Gmail API object.").optional()
1456
+ }).describe("Gmail filter.");
1457
+ var createFilterInput = z.strictObject({
1458
+ criteria: z.looseObject({}).describe("Gmail API object."),
1459
+ action: z.looseObject({}).describe("Gmail API object."),
1460
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1461
+ }).describe("The input payload for this action.");
1462
+ var createFilterOutput = z.looseObject({
1463
+ id: z.string().min(1).describe("Gmail filter ID."),
1464
+ criteria: z.looseObject({}).describe("Gmail API object.").optional(),
1465
+ action: z.looseObject({}).describe("Gmail API object.").optional()
1466
+ }).describe("Gmail filter.");
1467
+ var deleteFilterInput = z.strictObject({
1468
+ filterId: z.string().min(1).describe("Gmail filter ID."),
1469
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1470
+ }).describe("The input payload for this action.");
1471
+ var deleteFilterOutput = z.strictObject({
1472
+ success: z.boolean().describe("Whether the operation completed successfully.")
1473
+ }).describe("Operation result.");
1474
+ var getLanguageSettingsInput = z.strictObject({
1475
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1476
+ }).describe("The input payload for this action.");
1477
+ var getLanguageSettingsOutput = z.looseObject({}).describe("Gmail API object.");
1478
+ var updateLanguageSettingsInput = z.strictObject({
1479
+ displayLanguage: z.string().min(1).describe("Language code."),
1480
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1481
+ }).describe("The input payload for this action.");
1482
+ var updateLanguageSettingsOutput = z.looseObject({}).describe("Gmail API object.");
1483
+ var getVacationSettingsInput = z.strictObject({
1484
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1485
+ }).describe("The input payload for this action.");
1486
+ var getVacationSettingsOutput = z.looseObject({}).describe("Gmail API object.");
1487
+ var updateVacationSettingsInput = z.strictObject({
1488
+ enableAutoReply: z.boolean().optional(),
1489
+ responseSubject: z.string().optional(),
1490
+ responseBodyPlainText: z.string().optional(),
1491
+ responseBodyHtml: z.string().optional(),
1492
+ restrictToContacts: z.boolean().optional(),
1493
+ restrictToDomain: z.boolean().optional(),
1494
+ startTime: z.string().optional(),
1495
+ endTime: z.string().optional(),
1496
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1497
+ }).describe("The input payload for this action.");
1498
+ var updateVacationSettingsOutput = z.looseObject({}).describe("Gmail API object.");
1499
+ var getAutoForwardingInput = z.strictObject({
1500
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1501
+ }).describe("The input payload for this action.");
1502
+ var getAutoForwardingOutput = z.looseObject({}).describe("Gmail API object.");
1503
+ var listForwardingAddressesInput = z.strictObject({
1504
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1505
+ }).describe("The input payload for this action.");
1506
+ var listForwardingAddressesOutput = z.looseObject({}).describe("Gmail API object.");
1507
+ var settingsGetImapInput = z.strictObject({
1508
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1509
+ }).describe("The input payload for this action.");
1510
+ var settingsGetImapOutput = z.looseObject({}).describe("Gmail API object.");
1511
+ var settingsGetPopInput = z.strictObject({
1512
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1513
+ }).describe("The input payload for this action.");
1514
+ var settingsGetPopOutput = z.looseObject({}).describe("Gmail API object.");
1515
+ var stopWatchInput = z.strictObject({
1516
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1517
+ }).describe("The input payload for this action.");
1518
+ var stopWatchOutput = z.strictObject({
1519
+ success: z.boolean().describe("Whether the operation completed successfully.")
1520
+ }).describe("Operation result.");
1521
+ var updateImapSettingsInput = z.strictObject({
1522
+ enabled: z.boolean().optional(),
1523
+ autoExpunge: z.boolean().optional(),
1524
+ expungeBehavior: z.string().optional(),
1525
+ maxFolderSize: z.int().optional(),
1526
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1527
+ }).describe("The input payload for this action.");
1528
+ var updateImapSettingsOutput = z.looseObject({}).describe("Gmail API object.");
1529
+ var updatePopSettingsInput = z.strictObject({
1530
+ accessWindow: z.string().optional(),
1531
+ disposition: z.string().optional(),
1532
+ userId: z.string().describe("Gmail user ID. Omit to use the connected mailbox.").optional()
1533
+ }).describe("The input payload for this action.");
1534
+ var updatePopSettingsOutput = z.looseObject({}).describe("Gmail API object.");
1535
+ var gmailActions = {
1536
+ search_threads: {
1537
+ description: "Search Gmail threads by query and return lightweight thread summaries. Spam and trash stay excluded unless explicitly targeted in the query.",
1538
+ effect: "read",
1539
+ inputSchema: searchThreadsInput,
1540
+ outputSchema: z.toJSONSchema(searchThreadsOutput, { io: "output", unrepresentable: "any" })
1541
+ },
1542
+ list_threads: {
1543
+ description: "List Gmail threads with optional query filtering and pagination.",
1544
+ effect: "read",
1545
+ inputSchema: listThreadsInput,
1546
+ outputSchema: z.toJSONSchema(listThreadsOutput, { io: "output", unrepresentable: "any" })
1547
+ },
1548
+ fetch_emails: {
1549
+ description: "List Gmail messages with optional query, label, and pagination filters. Use detail to choose IDs, summaries, or full messages.",
1550
+ effect: "read",
1551
+ inputSchema: fetchEmailsInput,
1552
+ outputSchema: z.toJSONSchema(fetchEmailsOutput, { io: "output", unrepresentable: "any" })
1553
+ },
1554
+ get_message: {
1555
+ description: "Get a Gmail message by message ID with a simplified normalized output.",
1556
+ effect: "read",
1557
+ inputSchema: getMessageInput,
1558
+ outputSchema: z.toJSONSchema(getMessageOutput, { io: "output", unrepresentable: "any" })
1559
+ },
1560
+ fetch_message_by_message_id: {
1561
+ description: "Fetch a Gmail message by message ID with a controllable response format.",
1562
+ effect: "read",
1563
+ inputSchema: fetchMessageByMessageIdInput,
1564
+ outputSchema: z.toJSONSchema(fetchMessageByMessageIdOutput, { io: "output", unrepresentable: "any" })
1565
+ },
1566
+ fetch_message_by_thread_id: {
1567
+ description: "Fetch all messages in a Gmail thread.",
1568
+ effect: "read",
1569
+ inputSchema: fetchMessageByThreadIdInput,
1570
+ outputSchema: z.toJSONSchema(fetchMessageByThreadIdOutput, { io: "output", unrepresentable: "any" })
1571
+ },
1572
+ get_profile: {
1573
+ description: "Get the connected Gmail profile, including mailbox totals and the current historyId.",
1574
+ effect: "read",
1575
+ inputSchema: getProfileInput,
1576
+ outputSchema: z.toJSONSchema(getProfileOutput, { io: "output", unrepresentable: "any" })
1577
+ },
1578
+ send_email: {
1579
+ description: "Send an email from the connected Gmail account.",
1580
+ effect: "write",
1581
+ inputSchema: sendEmailInput,
1582
+ outputSchema: z.toJSONSchema(sendEmailOutput, { io: "output", unrepresentable: "any" })
1583
+ },
1584
+ reply_email: {
1585
+ description: "Reply to an existing Gmail thread using the original message's reply headers.",
1586
+ effect: "write",
1587
+ inputSchema: replyEmailInput,
1588
+ outputSchema: z.toJSONSchema(replyEmailOutput, { io: "output", unrepresentable: "any" })
1589
+ },
1590
+ reply_to_thread: {
1591
+ description: "Reply to an existing Gmail thread while preserving Gmail threading.",
1592
+ effect: "write",
1593
+ inputSchema: replyToThreadInput,
1594
+ outputSchema: z.toJSONSchema(replyToThreadOutput, { io: "output", unrepresentable: "any" })
1595
+ },
1596
+ create_draft: {
1597
+ description: "Create a Gmail draft with a simplified input and output shape.",
1598
+ effect: "write",
1599
+ inputSchema: createDraftInput,
1600
+ outputSchema: z.toJSONSchema(createDraftOutput, { io: "output", unrepresentable: "any" })
1601
+ },
1602
+ create_email_draft: {
1603
+ description: "Create a Gmail draft with recipients, subject, body, and optional threading.",
1604
+ effect: "write",
1605
+ inputSchema: createEmailDraftInput,
1606
+ outputSchema: z.toJSONSchema(createEmailDraftOutput, { io: "output", unrepresentable: "any" })
1607
+ },
1608
+ list_drafts: {
1609
+ description: "List Gmail drafts with pagination.",
1610
+ effect: "read",
1611
+ inputSchema: listDraftsInput,
1612
+ outputSchema: z.toJSONSchema(listDraftsOutput, { io: "output", unrepresentable: "any" })
1613
+ },
1614
+ get_draft: {
1615
+ description: "Get a Gmail draft by draft ID.",
1616
+ effect: "read",
1617
+ inputSchema: getDraftInput,
1618
+ outputSchema: z.toJSONSchema(getDraftOutput, { io: "output", unrepresentable: "any" })
1619
+ },
1620
+ update_draft: {
1621
+ description: "Update an existing Gmail draft in place.",
1622
+ effect: "write",
1623
+ inputSchema: updateDraftInput,
1624
+ outputSchema: z.toJSONSchema(updateDraftOutput, { io: "output", unrepresentable: "any" })
1625
+ },
1626
+ send_draft: {
1627
+ description: "Send an existing Gmail draft as-is.",
1628
+ effect: "write",
1629
+ inputSchema: sendDraftInput,
1630
+ outputSchema: z.toJSONSchema(sendDraftOutput, { io: "output", unrepresentable: "any" })
1631
+ },
1632
+ delete_draft: {
1633
+ description: "Permanently delete a Gmail draft by draft ID.",
1634
+ effect: "destructive",
1635
+ inputSchema: deleteDraftInput,
1636
+ outputSchema: z.toJSONSchema(deleteDraftOutput, { io: "output", unrepresentable: "any" })
1637
+ },
1638
+ list_labels: {
1639
+ description: "List all system and user-created Gmail labels.",
1640
+ effect: "read",
1641
+ inputSchema: listLabelsInput,
1642
+ outputSchema: z.toJSONSchema(listLabelsOutput, { io: "output", unrepresentable: "any" })
1643
+ },
1644
+ get_label: {
1645
+ description: "Get details for a Gmail label.",
1646
+ effect: "read",
1647
+ inputSchema: getLabelInput,
1648
+ outputSchema: z.toJSONSchema(getLabelOutput, { io: "output", unrepresentable: "any" })
1649
+ },
1650
+ create_label: {
1651
+ description: "Create a new Gmail label and return its internal label ID.",
1652
+ effect: "write",
1653
+ inputSchema: createLabelInput,
1654
+ outputSchema: z.toJSONSchema(createLabelOutput, { io: "output", unrepresentable: "any" })
1655
+ },
1656
+ patch_label: {
1657
+ description: "Patch a user-created Gmail label.",
1658
+ effect: "write",
1659
+ inputSchema: patchLabelInput,
1660
+ outputSchema: z.toJSONSchema(patchLabelOutput, { io: "output", unrepresentable: "any" })
1661
+ },
1662
+ update_label: {
1663
+ description: "Update an existing Gmail label.",
1664
+ effect: "write",
1665
+ inputSchema: updateLabelInput,
1666
+ outputSchema: z.toJSONSchema(updateLabelOutput, { io: "output", unrepresentable: "any" })
1667
+ },
1668
+ delete_label: {
1669
+ description: "Permanently delete a user-created Gmail label.",
1670
+ effect: "destructive",
1671
+ inputSchema: deleteLabelInput,
1672
+ outputSchema: z.toJSONSchema(deleteLabelOutput, { io: "output", unrepresentable: "any" })
1673
+ },
1674
+ add_label_to_email: {
1675
+ description: "Add and/or remove labels on a single Gmail message.",
1676
+ effect: "write",
1677
+ inputSchema: addLabelToEmailInput,
1678
+ outputSchema: z.toJSONSchema(addLabelToEmailOutput, { io: "output", unrepresentable: "any" })
1679
+ },
1680
+ batch_modify_messages: {
1681
+ description: "Add and/or remove labels on up to 1,000 Gmail messages.",
1682
+ effect: "write",
1683
+ inputSchema: batchModifyMessagesInput,
1684
+ outputSchema: z.toJSONSchema(batchModifyMessagesOutput, { io: "output", unrepresentable: "any" })
1685
+ },
1686
+ move_to_trash: {
1687
+ description: "Move a Gmail message to trash.",
1688
+ effect: "write",
1689
+ inputSchema: moveToTrashInput,
1690
+ outputSchema: z.toJSONSchema(moveToTrashOutput, { io: "output", unrepresentable: "any" })
1691
+ },
1692
+ untrash_message: {
1693
+ description: "Restore a previously trashed Gmail message.",
1694
+ effect: "write",
1695
+ inputSchema: untrashMessageInput,
1696
+ outputSchema: z.toJSONSchema(untrashMessageOutput, { io: "output", unrepresentable: "any" })
1697
+ },
1698
+ modify_thread_labels: {
1699
+ description: "Add and/or remove labels on every message in a Gmail thread.",
1700
+ effect: "write",
1701
+ inputSchema: modifyThreadLabelsInput,
1702
+ outputSchema: z.toJSONSchema(modifyThreadLabelsOutput, { io: "output", unrepresentable: "any" })
1703
+ },
1704
+ move_thread_to_trash: {
1705
+ description: "Move an entire Gmail thread to trash.",
1706
+ effect: "write",
1707
+ inputSchema: moveThreadToTrashInput,
1708
+ outputSchema: z.toJSONSchema(moveThreadToTrashOutput, { io: "output", unrepresentable: "any" })
1709
+ },
1710
+ untrash_thread: {
1711
+ description: "Restore a previously trashed Gmail thread.",
1712
+ effect: "write",
1713
+ inputSchema: untrashThreadInput,
1714
+ outputSchema: z.toJSONSchema(untrashThreadOutput, { io: "output", unrepresentable: "any" })
1715
+ },
1716
+ list_history: {
1717
+ description: "List Gmail mailbox change history after a known startHistoryId.",
1718
+ effect: "read",
1719
+ inputSchema: listHistoryInput,
1720
+ outputSchema: z.toJSONSchema(listHistoryOutput, { io: "output", unrepresentable: "any" })
1721
+ },
1722
+ list_filters: {
1723
+ description: "List Gmail filters for the mailbox.",
1724
+ effect: "read",
1725
+ inputSchema: listFiltersInput,
1726
+ outputSchema: z.toJSONSchema(listFiltersOutput, { io: "output", unrepresentable: "any" })
1727
+ },
1728
+ get_filter: {
1729
+ description: "Get a Gmail filter by filter ID.",
1730
+ effect: "read",
1731
+ inputSchema: getFilterInput,
1732
+ outputSchema: z.toJSONSchema(getFilterOutput, { io: "output", unrepresentable: "any" })
1733
+ },
1734
+ create_filter: {
1735
+ description: "Create a Gmail filter with matching criteria and resulting actions.",
1736
+ effect: "write",
1737
+ inputSchema: createFilterInput,
1738
+ outputSchema: z.toJSONSchema(createFilterOutput, { io: "output", unrepresentable: "any" })
1739
+ },
1740
+ delete_filter: {
1741
+ description: "Permanently delete a Gmail filter by filter ID.",
1742
+ effect: "destructive",
1743
+ inputSchema: deleteFilterInput,
1744
+ outputSchema: z.toJSONSchema(deleteFilterOutput, { io: "output", unrepresentable: "any" })
1745
+ },
1746
+ get_language_settings: {
1747
+ description: "Get the Gmail display language settings.",
1748
+ effect: "read",
1749
+ inputSchema: getLanguageSettingsInput,
1750
+ outputSchema: z.toJSONSchema(getLanguageSettingsOutput, { io: "output", unrepresentable: "any" })
1751
+ },
1752
+ update_language_settings: {
1753
+ description: "Update the Gmail display language settings.",
1754
+ effect: "write",
1755
+ inputSchema: updateLanguageSettingsInput,
1756
+ outputSchema: z.toJSONSchema(updateLanguageSettingsOutput, { io: "output", unrepresentable: "any" })
1757
+ },
1758
+ get_vacation_settings: {
1759
+ description: "Get the Gmail vacation responder settings.",
1760
+ effect: "read",
1761
+ inputSchema: getVacationSettingsInput,
1762
+ outputSchema: z.toJSONSchema(getVacationSettingsOutput, { io: "output", unrepresentable: "any" })
1763
+ },
1764
+ update_vacation_settings: {
1765
+ description: "Update the Gmail vacation responder settings.",
1766
+ effect: "write",
1767
+ inputSchema: updateVacationSettingsInput,
1768
+ outputSchema: z.toJSONSchema(updateVacationSettingsOutput, { io: "output", unrepresentable: "any" })
1769
+ },
1770
+ get_auto_forwarding: {
1771
+ description: "Get the current Gmail auto-forwarding configuration.",
1772
+ effect: "read",
1773
+ inputSchema: getAutoForwardingInput,
1774
+ outputSchema: z.toJSONSchema(getAutoForwardingOutput, { io: "output", unrepresentable: "any" })
1775
+ },
1776
+ list_forwarding_addresses: {
1777
+ description: "List registered forwarding addresses.",
1778
+ effect: "read",
1779
+ inputSchema: listForwardingAddressesInput,
1780
+ outputSchema: z.toJSONSchema(listForwardingAddressesOutput, { io: "output", unrepresentable: "any" })
1781
+ },
1782
+ settings_get_imap: {
1783
+ description: "Get the Gmail IMAP settings.",
1784
+ effect: "write",
1785
+ inputSchema: settingsGetImapInput,
1786
+ outputSchema: z.toJSONSchema(settingsGetImapOutput, { io: "output", unrepresentable: "any" })
1787
+ },
1788
+ settings_get_pop: {
1789
+ description: "Get the Gmail POP settings.",
1790
+ effect: "write",
1791
+ inputSchema: settingsGetPopInput,
1792
+ outputSchema: z.toJSONSchema(settingsGetPopOutput, { io: "output", unrepresentable: "any" })
1793
+ },
1794
+ stop_watch: {
1795
+ description: "Stop Gmail push watch notifications for the mailbox.",
1796
+ effect: "write",
1797
+ inputSchema: stopWatchInput,
1798
+ outputSchema: z.toJSONSchema(stopWatchOutput, { io: "output", unrepresentable: "any" })
1799
+ },
1800
+ update_imap_settings: {
1801
+ description: "Update the Gmail IMAP settings.",
1802
+ effect: "write",
1803
+ inputSchema: updateImapSettingsInput,
1804
+ outputSchema: z.toJSONSchema(updateImapSettingsOutput, { io: "output", unrepresentable: "any" })
1805
+ },
1806
+ update_pop_settings: {
1807
+ description: "Update the Gmail POP settings.",
1808
+ effect: "write",
1809
+ inputSchema: updatePopSettingsInput,
1810
+ outputSchema: z.toJSONSchema(updatePopSettingsOutput, { io: "output", unrepresentable: "any" })
1811
+ }
1812
+ };
1813
+
1814
+ // ../plugins/src/gmail/index.ts
1815
+ function createGmailPlugin() {
1816
+ return createProviderPlugin({
1817
+ description: "Gmail",
1818
+ actions: gmailActions,
1819
+ oauth: {
1820
+ authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
1821
+ tokenUrl: "https://oauth2.googleapis.com/token",
1822
+ scopes: [
1823
+ "https://www.googleapis.com/auth/gmail.readonly",
1824
+ "https://www.googleapis.com/auth/gmail.modify",
1825
+ "https://www.googleapis.com/auth/gmail.compose",
1826
+ "https://www.googleapis.com/auth/gmail.send",
1827
+ "https://www.googleapis.com/auth/gmail.labels",
1828
+ "https://www.googleapis.com/auth/gmail.settings.basic"
1829
+ ],
1830
+ clientAuth: "client_secret_post",
1831
+ authorizationParams: { access_type: "offline", prompt: "consent" }
1832
+ },
1833
+ handlers: {
1834
+ search_threads: searchThreads,
1835
+ list_threads: listThreadsAction,
1836
+ fetch_emails: fetchEmails,
1837
+ get_message: getMessage,
1838
+ fetch_message_by_message_id: fetchMessageByMessageId,
1839
+ fetch_message_by_thread_id: fetchMessageByThreadId,
1840
+ get_profile: getProfile,
1841
+ send_email: sendEmail,
1842
+ reply_email: replyEmail,
1843
+ reply_to_thread: replyToThread,
1844
+ create_draft: createDraft,
1845
+ create_email_draft: createEmailDraft,
1846
+ list_drafts: listDrafts,
1847
+ get_draft: getDraft,
1848
+ update_draft: updateDraft,
1849
+ send_draft: sendDraft,
1850
+ delete_draft: deleteDraft,
1851
+ list_labels: listLabels,
1852
+ get_label: getLabel,
1853
+ create_label: createLabel,
1854
+ patch_label: patchLabel,
1855
+ update_label: updateLabel,
1856
+ delete_label: deleteLabel,
1857
+ add_label_to_email: addLabelToEmail,
1858
+ batch_modify_messages: batchModifyMessages,
1859
+ move_to_trash: moveToTrash,
1860
+ untrash_message: untrashMessage,
1861
+ modify_thread_labels: modifyThreadLabels,
1862
+ move_thread_to_trash: moveThreadToTrash,
1863
+ untrash_thread: untrashThread,
1864
+ list_history: listHistory,
1865
+ list_filters: listFilters,
1866
+ get_filter: getFilter,
1867
+ create_filter: createFilter,
1868
+ delete_filter: deleteFilter,
1869
+ get_language_settings: getLanguageSettings,
1870
+ update_language_settings: updateLanguageSettings,
1871
+ get_vacation_settings: getVacationSettings,
1872
+ update_vacation_settings: updateVacationSettings,
1873
+ get_auto_forwarding: getAutoForwarding,
1874
+ list_forwarding_addresses: listForwardingAddresses,
1875
+ settings_get_imap: settingsGetImap,
1876
+ update_imap_settings: updateImapSettings,
1877
+ settings_get_pop: settingsGetPop,
1878
+ update_pop_settings: updatePopSettings,
1879
+ stop_watch: stopWatch
1880
+ }
1881
+ });
1882
+ }
1883
+ var gmail_default = createGmailPlugin();
1884
+ export {
1885
+ createGmailPlugin,
1886
+ gmail_default as default
1887
+ };