@bubblelab/bubble-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/LICENSE.txt +202 -0
  2. package/dist/bubble-bundle.d.ts +2021 -0
  3. package/dist/bubble-factory.d.ts +161 -0
  4. package/dist/bubble-factory.d.ts.map +1 -0
  5. package/dist/bubble-factory.js +426 -0
  6. package/dist/bubble-factory.js.map +1 -0
  7. package/dist/bubble-flow/bubble-flow-class.d.ts +19 -0
  8. package/dist/bubble-flow/bubble-flow-class.d.ts.map +1 -0
  9. package/dist/bubble-flow/bubble-flow-class.js +23 -0
  10. package/dist/bubble-flow/bubble-flow-class.js.map +1 -0
  11. package/dist/bubble-flow/sample/data-analyst-flow.d.ts +15 -0
  12. package/dist/bubble-flow/sample/data-analyst-flow.d.ts.map +1 -0
  13. package/dist/bubble-flow/sample/data-analyst-flow.js +63 -0
  14. package/dist/bubble-flow/sample/data-analyst-flow.js.map +1 -0
  15. package/dist/bubble-flow/sample/error-ts.d.ts +23 -0
  16. package/dist/bubble-flow/sample/error-ts.d.ts.map +1 -0
  17. package/dist/bubble-flow/sample/error-ts.js +31 -0
  18. package/dist/bubble-flow/sample/error-ts.js.map +1 -0
  19. package/dist/bubble-flow/sample/sanitytest.d.ts +10 -0
  20. package/dist/bubble-flow/sample/sanitytest.d.ts.map +1 -0
  21. package/dist/bubble-flow/sample/sanitytest.js +13 -0
  22. package/dist/bubble-flow/sample/sanitytest.js.map +1 -0
  23. package/dist/bubble-flow/sample/simple-webhook-2.d.ts +19 -0
  24. package/dist/bubble-flow/sample/simple-webhook-2.d.ts.map +1 -0
  25. package/dist/bubble-flow/sample/simple-webhook-2.js +23 -0
  26. package/dist/bubble-flow/sample/simple-webhook-2.js.map +1 -0
  27. package/dist/bubble-flow/sample/simple-webhook.d.ts +10 -0
  28. package/dist/bubble-flow/sample/simple-webhook.d.ts.map +1 -0
  29. package/dist/bubble-flow/sample/simple-webhook.js +18 -0
  30. package/dist/bubble-flow/sample/simple-webhook.js.map +1 -0
  31. package/dist/bubble-flow/sample/simplified-data-analysis.flow.d.ts +29 -0
  32. package/dist/bubble-flow/sample/simplified-data-analysis.flow.d.ts.map +1 -0
  33. package/dist/bubble-flow/sample/simplified-data-analysis.flow.js +150 -0
  34. package/dist/bubble-flow/sample/simplified-data-analysis.flow.js.map +1 -0
  35. package/dist/bubble-flow/sample/slack-v0.1.d.ts +10 -0
  36. package/dist/bubble-flow/sample/slack-v0.1.d.ts.map +1 -0
  37. package/dist/bubble-flow/sample/slack-v0.1.js +59 -0
  38. package/dist/bubble-flow/sample/slack-v0.1.js.map +1 -0
  39. package/dist/bubble-flow/sample/slackagenttest.d.ts +10 -0
  40. package/dist/bubble-flow/sample/slackagenttest.d.ts.map +1 -0
  41. package/dist/bubble-flow/sample/slackagenttest.js +59 -0
  42. package/dist/bubble-flow/sample/slackagenttest.js.map +1 -0
  43. package/dist/bubble-trigger/index.d.ts +2 -0
  44. package/dist/bubble-trigger/index.d.ts.map +1 -0
  45. package/dist/bubble-trigger/index.js +2 -0
  46. package/dist/bubble-trigger/index.js.map +1 -0
  47. package/dist/bubble-trigger/types.d.ts +87 -0
  48. package/dist/bubble-trigger/types.d.ts.map +1 -0
  49. package/dist/bubble-trigger/types.js +14 -0
  50. package/dist/bubble-trigger/types.js.map +1 -0
  51. package/dist/bubbles/service-bubble/ai-agent.d.ts +428 -0
  52. package/dist/bubbles/service-bubble/ai-agent.d.ts.map +1 -0
  53. package/dist/bubbles/service-bubble/ai-agent.js +881 -0
  54. package/dist/bubbles/service-bubble/ai-agent.js.map +1 -0
  55. package/dist/bubbles/service-bubble/gmail.d.ts +3073 -0
  56. package/dist/bubbles/service-bubble/gmail.d.ts.map +1 -0
  57. package/dist/bubbles/service-bubble/gmail.js +908 -0
  58. package/dist/bubbles/service-bubble/gmail.js.map +1 -0
  59. package/dist/bubbles/service-bubble/google-calendar.d.ts +3377 -0
  60. package/dist/bubbles/service-bubble/google-calendar.d.ts.map +1 -0
  61. package/dist/bubbles/service-bubble/google-calendar.js +527 -0
  62. package/dist/bubbles/service-bubble/google-calendar.js.map +1 -0
  63. package/dist/bubbles/service-bubble/google-drive.d.ts +1152 -0
  64. package/dist/bubbles/service-bubble/google-drive.d.ts.map +1 -0
  65. package/dist/bubbles/service-bubble/google-drive.js +943 -0
  66. package/dist/bubbles/service-bubble/google-drive.js.map +1 -0
  67. package/dist/bubbles/service-bubble/google-sheets.d.ts +1811 -0
  68. package/dist/bubbles/service-bubble/google-sheets.d.ts.map +1 -0
  69. package/dist/bubbles/service-bubble/google-sheets.js +904 -0
  70. package/dist/bubbles/service-bubble/google-sheets.js.map +1 -0
  71. package/dist/bubbles/service-bubble/hello-world.d.ts +74 -0
  72. package/dist/bubbles/service-bubble/hello-world.d.ts.map +1 -0
  73. package/dist/bubbles/service-bubble/hello-world.js +67 -0
  74. package/dist/bubbles/service-bubble/hello-world.js.map +1 -0
  75. package/dist/bubbles/service-bubble/http.d.ts +134 -0
  76. package/dist/bubbles/service-bubble/http.d.ts.map +1 -0
  77. package/dist/bubbles/service-bubble/http.js +184 -0
  78. package/dist/bubbles/service-bubble/http.js.map +1 -0
  79. package/dist/bubbles/service-bubble/postgresql.d.ts +180 -0
  80. package/dist/bubbles/service-bubble/postgresql.d.ts.map +1 -0
  81. package/dist/bubbles/service-bubble/postgresql.js +448 -0
  82. package/dist/bubbles/service-bubble/postgresql.js.map +1 -0
  83. package/dist/bubbles/service-bubble/resend.d.ts +301 -0
  84. package/dist/bubbles/service-bubble/resend.d.ts.map +1 -0
  85. package/dist/bubbles/service-bubble/resend.js +253 -0
  86. package/dist/bubbles/service-bubble/resend.js.map +1 -0
  87. package/dist/bubbles/service-bubble/slack.d.ts +5869 -0
  88. package/dist/bubbles/service-bubble/slack.d.ts.map +1 -0
  89. package/dist/bubbles/service-bubble/slack.js +1536 -0
  90. package/dist/bubbles/service-bubble/slack.js.map +1 -0
  91. package/dist/bubbles/service-bubble/storage.d.ts +571 -0
  92. package/dist/bubbles/service-bubble/storage.d.ts.map +1 -0
  93. package/dist/bubbles/service-bubble/storage.js +504 -0
  94. package/dist/bubbles/service-bubble/storage.js.map +1 -0
  95. package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.d.ts +308 -0
  96. package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.d.ts.map +1 -0
  97. package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.js +285 -0
  98. package/dist/bubbles/tool-bubble/bubbleflow-validation-tool.js.map +1 -0
  99. package/dist/bubbles/tool-bubble/chart-js-tool.d.ts +416 -0
  100. package/dist/bubbles/tool-bubble/chart-js-tool.d.ts.map +1 -0
  101. package/dist/bubbles/tool-bubble/chart-js-tool.js +570 -0
  102. package/dist/bubbles/tool-bubble/chart-js-tool.js.map +1 -0
  103. package/dist/bubbles/tool-bubble/get-bubble-details-tool.d.ts +99 -0
  104. package/dist/bubbles/tool-bubble/get-bubble-details-tool.d.ts.map +1 -0
  105. package/dist/bubbles/tool-bubble/get-bubble-details-tool.js +645 -0
  106. package/dist/bubbles/tool-bubble/get-bubble-details-tool.js.map +1 -0
  107. package/dist/bubbles/tool-bubble/list-bubbles-tool.d.ts +112 -0
  108. package/dist/bubbles/tool-bubble/list-bubbles-tool.d.ts.map +1 -0
  109. package/dist/bubbles/tool-bubble/list-bubbles-tool.js +82 -0
  110. package/dist/bubbles/tool-bubble/list-bubbles-tool.js.map +1 -0
  111. package/dist/bubbles/tool-bubble/reddit-scrape-tool.d.ts +413 -0
  112. package/dist/bubbles/tool-bubble/reddit-scrape-tool.d.ts.map +1 -0
  113. package/dist/bubbles/tool-bubble/reddit-scrape-tool.js +327 -0
  114. package/dist/bubbles/tool-bubble/reddit-scrape-tool.js.map +1 -0
  115. package/dist/bubbles/tool-bubble/research-agent-tool.d.ts +122 -0
  116. package/dist/bubbles/tool-bubble/research-agent-tool.d.ts.map +1 -0
  117. package/dist/bubbles/tool-bubble/research-agent-tool.js +343 -0
  118. package/dist/bubbles/tool-bubble/research-agent-tool.js.map +1 -0
  119. package/dist/bubbles/tool-bubble/sql-query-tool.d.ts +131 -0
  120. package/dist/bubbles/tool-bubble/sql-query-tool.d.ts.map +1 -0
  121. package/dist/bubbles/tool-bubble/sql-query-tool.js +147 -0
  122. package/dist/bubbles/tool-bubble/sql-query-tool.js.map +1 -0
  123. package/dist/bubbles/tool-bubble/tool-template.d.ts +257 -0
  124. package/dist/bubbles/tool-bubble/tool-template.d.ts.map +1 -0
  125. package/dist/bubbles/tool-bubble/tool-template.js +238 -0
  126. package/dist/bubbles/tool-bubble/tool-template.js.map +1 -0
  127. package/dist/bubbles/tool-bubble/virtual-file-editor-example.d.ts +8 -0
  128. package/dist/bubbles/tool-bubble/virtual-file-editor-example.d.ts.map +1 -0
  129. package/dist/bubbles/tool-bubble/virtual-file-editor-example.js +65 -0
  130. package/dist/bubbles/tool-bubble/virtual-file-editor-example.js.map +1 -0
  131. package/dist/bubbles/tool-bubble/virtual-file-editor.tool.d.ts +125 -0
  132. package/dist/bubbles/tool-bubble/virtual-file-editor.tool.d.ts.map +1 -0
  133. package/dist/bubbles/tool-bubble/virtual-file-editor.tool.js +169 -0
  134. package/dist/bubbles/tool-bubble/virtual-file-editor.tool.js.map +1 -0
  135. package/dist/bubbles/tool-bubble/web-crawl-tool.d.ts +218 -0
  136. package/dist/bubbles/tool-bubble/web-crawl-tool.d.ts.map +1 -0
  137. package/dist/bubbles/tool-bubble/web-crawl-tool.js +255 -0
  138. package/dist/bubbles/tool-bubble/web-crawl-tool.js.map +1 -0
  139. package/dist/bubbles/tool-bubble/web-extract-tool.d.ts +134 -0
  140. package/dist/bubbles/tool-bubble/web-extract-tool.d.ts.map +1 -0
  141. package/dist/bubbles/tool-bubble/web-extract-tool.js +175 -0
  142. package/dist/bubbles/tool-bubble/web-extract-tool.js.map +1 -0
  143. package/dist/bubbles/tool-bubble/web-scrape-tool.d.ts +228 -0
  144. package/dist/bubbles/tool-bubble/web-scrape-tool.d.ts.map +1 -0
  145. package/dist/bubbles/tool-bubble/web-scrape-tool.js +214 -0
  146. package/dist/bubbles/tool-bubble/web-scrape-tool.js.map +1 -0
  147. package/dist/bubbles/tool-bubble/web-search-tool.d.ts +134 -0
  148. package/dist/bubbles/tool-bubble/web-search-tool.d.ts.map +1 -0
  149. package/dist/bubbles/tool-bubble/web-search-tool.js +155 -0
  150. package/dist/bubbles/tool-bubble/web-search-tool.js.map +1 -0
  151. package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.d.ts +114 -0
  152. package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.d.ts.map +1 -0
  153. package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.js +777 -0
  154. package/dist/bubbles/workflow-bubble/bubbleflow-generator.workflow.js.map +1 -0
  155. package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.d.ts +97 -0
  156. package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.d.ts.map +1 -0
  157. package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.js +327 -0
  158. package/dist/bubbles/workflow-bubble/bubblscript-generateor.workflow.js.map +1 -0
  159. package/dist/bubbles/workflow-bubble/database-analyzer.workflow.d.ts +303 -0
  160. package/dist/bubbles/workflow-bubble/database-analyzer.workflow.d.ts.map +1 -0
  161. package/dist/bubbles/workflow-bubble/database-analyzer.workflow.js +297 -0
  162. package/dist/bubbles/workflow-bubble/database-analyzer.workflow.js.map +1 -0
  163. package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.d.ts +157 -0
  164. package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.d.ts.map +1 -0
  165. package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.js +310 -0
  166. package/dist/bubbles/workflow-bubble/file-editor-agent.workflow.js.map +1 -0
  167. package/dist/bubbles/workflow-bubble/generate-document.workflow.d.ts +543 -0
  168. package/dist/bubbles/workflow-bubble/generate-document.workflow.d.ts.map +1 -0
  169. package/dist/bubbles/workflow-bubble/generate-document.workflow.js +628 -0
  170. package/dist/bubbles/workflow-bubble/generate-document.workflow.js.map +1 -0
  171. package/dist/bubbles/workflow-bubble/parse-document.workflow.d.ts +679 -0
  172. package/dist/bubbles/workflow-bubble/parse-document.workflow.d.ts.map +1 -0
  173. package/dist/bubbles/workflow-bubble/parse-document.workflow.js +604 -0
  174. package/dist/bubbles/workflow-bubble/parse-document.workflow.js.map +1 -0
  175. package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.d.ts +1011 -0
  176. package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.d.ts.map +1 -0
  177. package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.js +841 -0
  178. package/dist/bubbles/workflow-bubble/pdf-form-operations.workflow.js.map +1 -0
  179. package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.d.ts +883 -0
  180. package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.d.ts.map +1 -0
  181. package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.js +781 -0
  182. package/dist/bubbles/workflow-bubble/pdf-ocr.workflow.js.map +1 -0
  183. package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.d.ts +300 -0
  184. package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.d.ts.map +1 -0
  185. package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.js +508 -0
  186. package/dist/bubbles/workflow-bubble/slack-data-assistant.workflow.js.map +1 -0
  187. package/dist/bubbles/workflow-bubble/slack-formatter-agent.d.ts +731 -0
  188. package/dist/bubbles/workflow-bubble/slack-formatter-agent.d.ts.map +1 -0
  189. package/dist/bubbles/workflow-bubble/slack-formatter-agent.js +690 -0
  190. package/dist/bubbles/workflow-bubble/slack-formatter-agent.js.map +1 -0
  191. package/dist/bubbles/workflow-bubble/slack-notifier.workflow.d.ts +401 -0
  192. package/dist/bubbles/workflow-bubble/slack-notifier.workflow.d.ts.map +1 -0
  193. package/dist/bubbles/workflow-bubble/slack-notifier.workflow.js +382 -0
  194. package/dist/bubbles/workflow-bubble/slack-notifier.workflow.js.map +1 -0
  195. package/dist/bubbles/workflow-bubble/workflow-template.d.ts +144 -0
  196. package/dist/bubbles/workflow-bubble/workflow-template.d.ts.map +1 -0
  197. package/dist/bubbles/workflow-bubble/workflow-template.js +124 -0
  198. package/dist/bubbles/workflow-bubble/workflow-template.js.map +1 -0
  199. package/dist/index.d.ts +46 -0
  200. package/dist/index.d.ts.map +1 -0
  201. package/dist/index.js +53 -0
  202. package/dist/index.js.map +1 -0
  203. package/dist/logging/BubbleLogger.d.ts +146 -0
  204. package/dist/logging/BubbleLogger.d.ts.map +1 -0
  205. package/dist/logging/BubbleLogger.js +472 -0
  206. package/dist/logging/BubbleLogger.js.map +1 -0
  207. package/dist/logging/StreamingBubbleLogger.d.ts +85 -0
  208. package/dist/logging/StreamingBubbleLogger.d.ts.map +1 -0
  209. package/dist/logging/StreamingBubbleLogger.js +340 -0
  210. package/dist/logging/StreamingBubbleLogger.js.map +1 -0
  211. package/dist/types/ai-models.d.ts +4 -0
  212. package/dist/types/ai-models.d.ts.map +1 -0
  213. package/dist/types/ai-models.js +14 -0
  214. package/dist/types/ai-models.js.map +1 -0
  215. package/dist/types/available-tools.d.ts +4 -0
  216. package/dist/types/available-tools.d.ts.map +1 -0
  217. package/dist/types/available-tools.js +19 -0
  218. package/dist/types/available-tools.js.map +1 -0
  219. package/dist/types/base-bubble-class.d.ts +47 -0
  220. package/dist/types/base-bubble-class.d.ts.map +1 -0
  221. package/dist/types/base-bubble-class.js +212 -0
  222. package/dist/types/base-bubble-class.js.map +1 -0
  223. package/dist/types/bubble-errors.d.ts +44 -0
  224. package/dist/types/bubble-errors.d.ts.map +1 -0
  225. package/dist/types/bubble-errors.js +51 -0
  226. package/dist/types/bubble-errors.js.map +1 -0
  227. package/dist/types/bubble.d.ts +73 -0
  228. package/dist/types/bubble.d.ts.map +1 -0
  229. package/dist/types/bubble.js +2 -0
  230. package/dist/types/bubble.js.map +1 -0
  231. package/dist/types/credentials.d.ts +6 -0
  232. package/dist/types/credentials.d.ts.map +1 -0
  233. package/dist/types/credentials.js +6 -0
  234. package/dist/types/credentials.js.map +1 -0
  235. package/dist/types/service-bubble-class.d.ts +31 -0
  236. package/dist/types/service-bubble-class.d.ts.map +1 -0
  237. package/dist/types/service-bubble-class.js +36 -0
  238. package/dist/types/service-bubble-class.js.map +1 -0
  239. package/dist/types/streaming-events.d.ts +18 -0
  240. package/dist/types/streaming-events.d.ts.map +1 -0
  241. package/dist/types/streaming-events.js +5 -0
  242. package/dist/types/streaming-events.js.map +1 -0
  243. package/dist/types/tool-bubble-class.d.ts +19 -0
  244. package/dist/types/tool-bubble-class.d.ts.map +1 -0
  245. package/dist/types/tool-bubble-class.js +48 -0
  246. package/dist/types/tool-bubble-class.js.map +1 -0
  247. package/dist/types/workflow-bubble-class.d.ts +25 -0
  248. package/dist/types/workflow-bubble-class.d.ts.map +1 -0
  249. package/dist/types/workflow-bubble-class.js +30 -0
  250. package/dist/types/workflow-bubble-class.js.map +1 -0
  251. package/dist/utils/bubbleflow-parser.d.ts +32 -0
  252. package/dist/utils/bubbleflow-parser.d.ts.map +1 -0
  253. package/dist/utils/bubbleflow-parser.js +332 -0
  254. package/dist/utils/bubbleflow-parser.js.map +1 -0
  255. package/dist/utils/bubbleflow-validation.d.ts +9 -0
  256. package/dist/utils/bubbleflow-validation.d.ts.map +1 -0
  257. package/dist/utils/bubbleflow-validation.js +116 -0
  258. package/dist/utils/bubbleflow-validation.js.map +1 -0
  259. package/dist/utils/json-parsing.d.ts +20 -0
  260. package/dist/utils/json-parsing.d.ts.map +1 -0
  261. package/dist/utils/json-parsing.js +394 -0
  262. package/dist/utils/json-parsing.js.map +1 -0
  263. package/dist/utils/mock-data-generator.d.ts +43 -0
  264. package/dist/utils/mock-data-generator.d.ts.map +1 -0
  265. package/dist/utils/mock-data-generator.js +312 -0
  266. package/dist/utils/mock-data-generator.js.map +1 -0
  267. package/dist/utils/param-helper.d.ts +2 -0
  268. package/dist/utils/param-helper.d.ts.map +1 -0
  269. package/dist/utils/param-helper.js +5 -0
  270. package/dist/utils/param-helper.js.map +1 -0
  271. package/dist/utils/source-bubble-parser.d.ts +31 -0
  272. package/dist/utils/source-bubble-parser.d.ts.map +1 -0
  273. package/dist/utils/source-bubble-parser.js +231 -0
  274. package/dist/utils/source-bubble-parser.js.map +1 -0
  275. package/package.json +63 -0
@@ -0,0 +1,908 @@
1
+ import { z } from 'zod';
2
+ import { ServiceBubble } from '../../types/service-bubble-class.js';
3
+ import { CredentialType } from '@bubblelab/shared-schemas';
4
+ // Define email header schema
5
+ const EmailHeaderSchema = z
6
+ .object({
7
+ name: z.string().describe('Header name (e.g., "Subject", "From", "To")'),
8
+ value: z.string().describe('Header value'),
9
+ })
10
+ .describe('Email header key-value pair');
11
+ // Define email message schema
12
+ const GmailMessageSchema = z
13
+ .object({
14
+ id: z.string().describe('Unique message identifier'),
15
+ threadId: z.string().describe('Thread identifier this message belongs to'),
16
+ labelIds: z
17
+ .array(z.string())
18
+ .optional()
19
+ .describe('List of label IDs applied to this message'),
20
+ snippet: z
21
+ .string()
22
+ .optional()
23
+ .describe('Short snippet of the message text'),
24
+ historyId: z
25
+ .string()
26
+ .optional()
27
+ .describe('History record ID that last modified this message'),
28
+ internalDate: z
29
+ .string()
30
+ .optional()
31
+ .describe('Internal message creation timestamp (epoch ms)'),
32
+ sizeEstimate: z.number().optional().describe('Estimated size in bytes'),
33
+ raw: z
34
+ .string()
35
+ .optional()
36
+ .describe('Entire email message in RFC 2822 format (base64url encoded)'),
37
+ payload: z
38
+ .object({
39
+ mimeType: z
40
+ .string()
41
+ .optional()
42
+ .describe('MIME type of the email content'),
43
+ headers: z
44
+ .array(EmailHeaderSchema)
45
+ .optional()
46
+ .describe('Email headers (Subject, From, To, etc.)'),
47
+ body: z
48
+ .object({
49
+ data: z
50
+ .string()
51
+ .optional()
52
+ .describe('Email body content (base64url encoded)'),
53
+ size: z
54
+ .number()
55
+ .optional()
56
+ .describe('Size of the body content in bytes'),
57
+ attachmentId: z
58
+ .string()
59
+ .optional()
60
+ .describe('ID of the attachment if this body part is an attachment'),
61
+ })
62
+ .optional()
63
+ .describe('Email body content and metadata'),
64
+ parts: z
65
+ .array(z.any())
66
+ .optional()
67
+ .describe('Array of message parts for multipart emails'),
68
+ })
69
+ .optional()
70
+ .describe('Parsed email structure'),
71
+ })
72
+ .describe('Gmail message object');
73
+ // Define draft schema
74
+ const GmailDraftSchema = z
75
+ .object({
76
+ id: z.string().describe('Unique draft identifier'),
77
+ message: GmailMessageSchema.describe('Draft message content'),
78
+ })
79
+ .describe('Gmail draft object');
80
+ // Define thread schema
81
+ const GmailThreadSchema = z
82
+ .object({
83
+ id: z.string().describe('Unique thread identifier'),
84
+ historyId: z.string().optional().describe('Last history record ID'),
85
+ messages: z
86
+ .array(GmailMessageSchema)
87
+ .optional()
88
+ .describe('Messages in this thread'),
89
+ snippet: z.string().optional().describe('Thread snippet'),
90
+ })
91
+ .describe('Gmail thread object');
92
+ // Define the parameters schema for Gmail operations
93
+ const GmailParamsSchema = z.discriminatedUnion('operation', [
94
+ // Send email operation
95
+ z.object({
96
+ operation: z.literal('send_email').describe('Send an email message'),
97
+ to: z
98
+ .array(z.string().email())
99
+ .min(1, 'At least one recipient is required')
100
+ .describe('List of recipient email addresses'),
101
+ cc: z
102
+ .array(z.string().email())
103
+ .optional()
104
+ .describe('List of CC recipient email addresses'),
105
+ bcc: z
106
+ .array(z.string().email())
107
+ .optional()
108
+ .describe('List of BCC recipient email addresses'),
109
+ subject: z
110
+ .string()
111
+ .min(1, 'Subject is required')
112
+ .describe('Email subject line'),
113
+ body_text: z.string().optional().describe('Plain text email body'),
114
+ body_html: z.string().optional().describe('HTML email body'),
115
+ reply_to: z.string().email().optional().describe('Reply-to email address'),
116
+ thread_id: z
117
+ .string()
118
+ .optional()
119
+ .describe('Thread ID to reply to (for threaded conversations)'),
120
+ credentials: z
121
+ .record(z.nativeEnum(CredentialType), z.string())
122
+ .optional()
123
+ .describe('Object mapping credential types to values (injected at runtime)'),
124
+ }),
125
+ // List emails operation
126
+ z.object({
127
+ operation: z
128
+ .literal('list_emails')
129
+ .describe('List emails in the user mailbox'),
130
+ query: z
131
+ .string()
132
+ .optional()
133
+ .describe('Gmail search query (e.g., "from:user@example.com is:unread")'),
134
+ label_ids: z
135
+ .array(z.string())
136
+ .optional()
137
+ .describe('Filter by specific label IDs'),
138
+ include_spam_trash: z
139
+ .boolean()
140
+ .optional()
141
+ .default(false)
142
+ .describe('Include messages from SPAM and TRASH'),
143
+ max_results: z
144
+ .number()
145
+ .min(1)
146
+ .max(500)
147
+ .optional()
148
+ .default(100)
149
+ .describe('Maximum number of messages to return'),
150
+ page_token: z
151
+ .string()
152
+ .optional()
153
+ .describe('Token for pagination to get next page'),
154
+ credentials: z
155
+ .record(z.nativeEnum(CredentialType), z.string())
156
+ .optional()
157
+ .describe('Object mapping credential types to values (injected at runtime)'),
158
+ }),
159
+ // Get email operation
160
+ z.object({
161
+ operation: z.literal('get_email').describe('Get a specific email message'),
162
+ message_id: z
163
+ .string()
164
+ .min(1, 'Message ID is required')
165
+ .describe('Gmail message ID to retrieve'),
166
+ format: z
167
+ .enum(['minimal', 'full', 'raw', 'metadata'])
168
+ .optional()
169
+ .default('full')
170
+ .describe('Format to return the message in'),
171
+ metadata_headers: z
172
+ .array(z.string())
173
+ .optional()
174
+ .describe('List of headers to include when format is metadata'),
175
+ credentials: z
176
+ .record(z.nativeEnum(CredentialType), z.string())
177
+ .optional()
178
+ .describe('Object mapping credential types to values (injected at runtime)'),
179
+ }),
180
+ // Search emails operation
181
+ z.object({
182
+ operation: z.literal('search_emails').describe('Search emails with query'),
183
+ query: z
184
+ .string()
185
+ .min(1, 'Search query is required')
186
+ .describe('Gmail search query string'),
187
+ max_results: z
188
+ .number()
189
+ .min(1)
190
+ .max(500)
191
+ .optional()
192
+ .default(50)
193
+ .describe('Maximum number of results to return'),
194
+ include_spam_trash: z
195
+ .boolean()
196
+ .optional()
197
+ .default(false)
198
+ .describe('Include messages from SPAM and TRASH'),
199
+ credentials: z
200
+ .record(z.nativeEnum(CredentialType), z.string())
201
+ .optional()
202
+ .describe('Object mapping credential types to values (injected at runtime)'),
203
+ }),
204
+ // Mark as read operation
205
+ z.object({
206
+ operation: z
207
+ .literal('mark_as_read')
208
+ .describe('Mark one or more messages as read'),
209
+ message_ids: z
210
+ .array(z.string())
211
+ .min(1, 'At least one message ID is required')
212
+ .describe('List of message IDs to mark as read'),
213
+ credentials: z
214
+ .record(z.nativeEnum(CredentialType), z.string())
215
+ .optional()
216
+ .describe('Object mapping credential types to values (injected at runtime)'),
217
+ }),
218
+ // Mark as unread operation
219
+ z.object({
220
+ operation: z
221
+ .literal('mark_as_unread')
222
+ .describe('Mark one or more messages as unread'),
223
+ message_ids: z
224
+ .array(z.string())
225
+ .min(1, 'At least one message ID is required')
226
+ .describe('List of message IDs to mark as unread'),
227
+ credentials: z
228
+ .record(z.nativeEnum(CredentialType), z.string())
229
+ .optional()
230
+ .describe('Object mapping credential types to values (injected at runtime)'),
231
+ }),
232
+ // Create draft operation
233
+ z.object({
234
+ operation: z.literal('create_draft').describe('Create a draft email'),
235
+ to: z
236
+ .array(z.string().email())
237
+ .min(1, 'At least one recipient is required')
238
+ .describe('List of recipient email addresses'),
239
+ cc: z
240
+ .array(z.string().email())
241
+ .optional()
242
+ .describe('List of CC recipient email addresses'),
243
+ bcc: z
244
+ .array(z.string().email())
245
+ .optional()
246
+ .describe('List of BCC recipient email addresses'),
247
+ subject: z
248
+ .string()
249
+ .min(1, 'Subject is required')
250
+ .describe('Email subject line'),
251
+ body_text: z.string().optional().describe('Plain text email body'),
252
+ body_html: z.string().optional().describe('HTML email body'),
253
+ reply_to: z.string().email().optional().describe('Reply-to email address'),
254
+ thread_id: z
255
+ .string()
256
+ .optional()
257
+ .describe('Thread ID to reply to (for threaded conversations)'),
258
+ credentials: z
259
+ .record(z.nativeEnum(CredentialType), z.string())
260
+ .optional()
261
+ .describe('Object mapping credential types to values (injected at runtime)'),
262
+ }),
263
+ // Send draft operation
264
+ z.object({
265
+ operation: z.literal('send_draft').describe('Send a draft email'),
266
+ draft_id: z
267
+ .string()
268
+ .min(1, 'Draft ID is required')
269
+ .describe('Gmail draft ID to send'),
270
+ credentials: z
271
+ .record(z.nativeEnum(CredentialType), z.string())
272
+ .optional()
273
+ .describe('Object mapping credential types to values (injected at runtime)'),
274
+ }),
275
+ // List drafts operation
276
+ z.object({
277
+ operation: z.literal('list_drafts').describe('List draft emails'),
278
+ query: z.string().optional().describe('Search query to filter drafts'),
279
+ max_results: z
280
+ .number()
281
+ .min(1)
282
+ .max(500)
283
+ .optional()
284
+ .default(100)
285
+ .describe('Maximum number of drafts to return'),
286
+ page_token: z
287
+ .string()
288
+ .optional()
289
+ .describe('Token for pagination to get next page'),
290
+ include_spam_trash: z
291
+ .boolean()
292
+ .optional()
293
+ .default(false)
294
+ .describe('Include drafts from SPAM and TRASH'),
295
+ credentials: z
296
+ .record(z.nativeEnum(CredentialType), z.string())
297
+ .optional()
298
+ .describe('Object mapping credential types to values (injected at runtime)'),
299
+ }),
300
+ // Delete email operation
301
+ z.object({
302
+ operation: z
303
+ .literal('delete_email')
304
+ .describe('Delete an email message permanently'),
305
+ message_id: z
306
+ .string()
307
+ .min(1, 'Message ID is required')
308
+ .describe('Gmail message ID to delete'),
309
+ credentials: z
310
+ .record(z.nativeEnum(CredentialType), z.string())
311
+ .optional()
312
+ .describe('Object mapping credential types to values (injected at runtime)'),
313
+ }),
314
+ // Trash email operation
315
+ z.object({
316
+ operation: z
317
+ .literal('trash_email')
318
+ .describe('Move an email message to trash'),
319
+ message_id: z
320
+ .string()
321
+ .min(1, 'Message ID is required')
322
+ .describe('Gmail message ID to move to trash'),
323
+ credentials: z
324
+ .record(z.nativeEnum(CredentialType), z.string())
325
+ .optional()
326
+ .describe('Object mapping credential types to values (injected at runtime)'),
327
+ }),
328
+ // List threads operation
329
+ z.object({
330
+ operation: z.literal('list_threads').describe('List email threads'),
331
+ query: z
332
+ .string()
333
+ .optional()
334
+ .describe('Gmail search query to filter threads'),
335
+ label_ids: z
336
+ .array(z.string())
337
+ .optional()
338
+ .describe('Filter by specific label IDs'),
339
+ include_spam_trash: z
340
+ .boolean()
341
+ .optional()
342
+ .default(false)
343
+ .describe('Include threads from SPAM and TRASH'),
344
+ max_results: z
345
+ .number()
346
+ .min(1)
347
+ .max(500)
348
+ .optional()
349
+ .default(100)
350
+ .describe('Maximum number of threads to return'),
351
+ page_token: z
352
+ .string()
353
+ .optional()
354
+ .describe('Token for pagination to get next page'),
355
+ credentials: z
356
+ .record(z.nativeEnum(CredentialType), z.string())
357
+ .optional()
358
+ .describe('Object mapping credential types to values (injected at runtime)'),
359
+ }),
360
+ ]);
361
+ // Define result schemas for different operations
362
+ const GmailResultSchema = z.discriminatedUnion('operation', [
363
+ z.object({
364
+ operation: z.literal('send_email').describe('Send an email message'),
365
+ success: z.boolean().describe('Whether the email was sent successfully'),
366
+ message_id: z.string().optional().describe('Sent message ID'),
367
+ thread_id: z.string().optional().describe('Thread ID'),
368
+ error: z.string().describe('Error message if operation failed'),
369
+ }),
370
+ z.object({
371
+ operation: z
372
+ .literal('list_emails')
373
+ .describe('List emails in the user mailbox'),
374
+ success: z
375
+ .boolean()
376
+ .describe('Whether the email list was retrieved successfully'),
377
+ messages: z
378
+ .array(GmailMessageSchema)
379
+ .optional()
380
+ .describe('List of email messages'),
381
+ next_page_token: z
382
+ .string()
383
+ .optional()
384
+ .describe('Token for fetching next page'),
385
+ result_size_estimate: z
386
+ .number()
387
+ .optional()
388
+ .describe('Estimated total number of results'),
389
+ error: z.string().describe('Error message if operation failed'),
390
+ }),
391
+ z.object({
392
+ operation: z.literal('get_email').describe('Get a specific email message'),
393
+ success: z
394
+ .boolean()
395
+ .describe('Whether the email was retrieved successfully'),
396
+ message: GmailMessageSchema.optional().describe('Email message details'),
397
+ error: z.string().describe('Error message if operation failed'),
398
+ }),
399
+ z.object({
400
+ operation: z.literal('search_emails').describe('Search emails with query'),
401
+ success: z
402
+ .boolean()
403
+ .describe('Whether the email search was completed successfully'),
404
+ messages: z
405
+ .array(GmailMessageSchema)
406
+ .optional()
407
+ .describe('List of matching email messages'),
408
+ result_size_estimate: z
409
+ .number()
410
+ .optional()
411
+ .describe('Estimated total number of results'),
412
+ error: z.string().describe('Error message if operation failed'),
413
+ }),
414
+ z.object({
415
+ operation: z
416
+ .literal('mark_as_read')
417
+ .describe('Mark one or more messages as read'),
418
+ success: z
419
+ .boolean()
420
+ .describe('Whether the messages were marked as read successfully'),
421
+ modified_messages: z
422
+ .array(z.string())
423
+ .optional()
424
+ .describe('IDs of messages that were modified'),
425
+ error: z.string().describe('Error message if operation failed'),
426
+ }),
427
+ z.object({
428
+ operation: z
429
+ .literal('mark_as_unread')
430
+ .describe('Mark one or more messages as unread'),
431
+ success: z
432
+ .boolean()
433
+ .describe('Whether the messages were marked as unread successfully'),
434
+ modified_messages: z
435
+ .array(z.string())
436
+ .optional()
437
+ .describe('IDs of messages that were modified'),
438
+ error: z.string().describe('Error message if operation failed'),
439
+ }),
440
+ z.object({
441
+ operation: z.literal('create_draft').describe('Create a draft email'),
442
+ success: z.boolean().describe('Whether the draft was created successfully'),
443
+ draft: GmailDraftSchema.optional().describe('Created draft'),
444
+ error: z.string().describe('Error message if operation failed'),
445
+ }),
446
+ z.object({
447
+ operation: z.literal('send_draft').describe('Send a draft email'),
448
+ success: z.boolean().describe('Whether the draft was sent successfully'),
449
+ message_id: z.string().optional().describe('Sent message ID'),
450
+ thread_id: z.string().optional().describe('Thread ID'),
451
+ error: z.string().describe('Error message if operation failed'),
452
+ }),
453
+ z.object({
454
+ operation: z.literal('list_drafts').describe('List draft emails'),
455
+ success: z
456
+ .boolean()
457
+ .describe('Whether the draft list was retrieved successfully'),
458
+ drafts: z.array(GmailDraftSchema).optional().describe('List of drafts'),
459
+ next_page_token: z
460
+ .string()
461
+ .optional()
462
+ .describe('Token for fetching next page'),
463
+ result_size_estimate: z
464
+ .number()
465
+ .optional()
466
+ .describe('Estimated total number of results'),
467
+ error: z.string().describe('Error message if operation failed'),
468
+ }),
469
+ z.object({
470
+ operation: z
471
+ .literal('delete_email')
472
+ .describe('Delete an email message permanently'),
473
+ success: z.boolean().describe('Whether the email was deleted successfully'),
474
+ deleted_message_id: z
475
+ .string()
476
+ .optional()
477
+ .describe('ID of the deleted message'),
478
+ error: z.string().describe('Error message if operation failed'),
479
+ }),
480
+ z.object({
481
+ operation: z
482
+ .literal('trash_email')
483
+ .describe('Move an email message to trash'),
484
+ success: z
485
+ .boolean()
486
+ .describe('Whether the email was moved to trash successfully'),
487
+ trashed_message_id: z
488
+ .string()
489
+ .optional()
490
+ .describe('ID of the trashed message'),
491
+ error: z.string().describe('Error message if operation failed'),
492
+ }),
493
+ z.object({
494
+ operation: z.literal('list_threads').describe('List email threads'),
495
+ success: z
496
+ .boolean()
497
+ .describe('Whether the thread list was retrieved successfully'),
498
+ threads: z
499
+ .array(GmailThreadSchema)
500
+ .optional()
501
+ .describe('List of email threads'),
502
+ next_page_token: z
503
+ .string()
504
+ .optional()
505
+ .describe('Token for fetching next page'),
506
+ result_size_estimate: z
507
+ .number()
508
+ .optional()
509
+ .describe('Estimated total number of results'),
510
+ error: z.string().describe('Error message if operation failed'),
511
+ }),
512
+ ]);
513
+ export class GmailBubble extends ServiceBubble {
514
+ static type = 'service';
515
+ static service = 'gmail';
516
+ static authType = 'oauth';
517
+ static bubbleName = 'gmail';
518
+ static schema = GmailParamsSchema;
519
+ static resultSchema = GmailResultSchema;
520
+ static shortDescription = 'Gmail integration for email management';
521
+ static longDescription = `
522
+ Gmail service integration for comprehensive email management and automation.
523
+ Use cases:
524
+ - Send and receive emails with rich formatting
525
+ - Search and filter emails with advanced queries
526
+ - Manage drafts and email threads
527
+ - Mark messages as read/unread
528
+ - Organize emails with labels and folders
529
+ - Handle email attachments and metadata
530
+ `;
531
+ static alias = 'gmail';
532
+ constructor(params = {
533
+ operation: 'list_emails',
534
+ max_results: 10,
535
+ }, context) {
536
+ super(params, context);
537
+ }
538
+ async testCredential() {
539
+ const credential = this.chooseCredential();
540
+ if (!credential) {
541
+ throw new Error('Gmail credentials are required');
542
+ }
543
+ try {
544
+ // Test the credentials by making a simple API call
545
+ const response = await fetch('https://www.googleapis.com/gmail/v1/users/me/profile', {
546
+ headers: {
547
+ Authorization: `Bearer ${credential}`,
548
+ 'Content-Type': 'application/json',
549
+ },
550
+ });
551
+ return response.ok;
552
+ }
553
+ catch {
554
+ return false;
555
+ }
556
+ }
557
+ async makeGmailApiRequest(endpoint, method = 'GET', body, headers = {}) {
558
+ const url = endpoint.startsWith('https://')
559
+ ? endpoint
560
+ : `https://www.googleapis.com/gmail/v1/users/me${endpoint}`;
561
+ const requestHeaders = {
562
+ Authorization: `Bearer ${this.chooseCredential()}`,
563
+ 'Content-Type': 'application/json',
564
+ ...headers,
565
+ };
566
+ const requestInit = {
567
+ method,
568
+ headers: requestHeaders,
569
+ };
570
+ if (body && method !== 'GET') {
571
+ requestInit.body = JSON.stringify(body);
572
+ }
573
+ const response = await fetch(url, requestInit);
574
+ if (!response.ok) {
575
+ const errorText = await response.text();
576
+ throw new Error(`Gmail API error: ${response.status} ${response.statusText} - ${errorText}`);
577
+ }
578
+ // Handle empty responses
579
+ const contentType = response.headers.get('content-type');
580
+ if (contentType && contentType.includes('application/json')) {
581
+ return await response.json();
582
+ }
583
+ else {
584
+ return await response.text();
585
+ }
586
+ }
587
+ async performAction(context) {
588
+ void context;
589
+ const { operation } = this.params;
590
+ try {
591
+ const result = await (async () => {
592
+ switch (operation) {
593
+ case 'send_email':
594
+ return await this.sendEmail(this.params);
595
+ case 'list_emails':
596
+ return await this.listEmails(this.params);
597
+ case 'get_email':
598
+ return await this.getEmail(this.params);
599
+ case 'search_emails':
600
+ return await this.searchEmails(this.params);
601
+ case 'mark_as_read':
602
+ return await this.markAsRead(this.params);
603
+ case 'mark_as_unread':
604
+ return await this.markAsUnread(this.params);
605
+ case 'create_draft':
606
+ return await this.createDraft(this.params);
607
+ case 'send_draft':
608
+ return await this.sendDraft(this.params);
609
+ case 'list_drafts':
610
+ return await this.listDrafts(this.params);
611
+ case 'delete_email':
612
+ return await this.deleteEmail(this.params);
613
+ case 'trash_email':
614
+ return await this.trashEmail(this.params);
615
+ case 'list_threads':
616
+ return await this.listThreads(this.params);
617
+ default:
618
+ throw new Error(`Unsupported operation: ${operation}`);
619
+ }
620
+ })();
621
+ return result;
622
+ }
623
+ catch (error) {
624
+ return {
625
+ operation,
626
+ success: false,
627
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
628
+ };
629
+ }
630
+ }
631
+ createEmailMessage(params) {
632
+ const { to, cc, bcc, subject, body_text, body_html, reply_to, thread_id } = params;
633
+ let emailContent = '';
634
+ emailContent += `To: ${to.join(', ')}\r\n`;
635
+ if (cc && cc.length > 0) {
636
+ emailContent += `Cc: ${cc.join(', ')}\r\n`;
637
+ }
638
+ if (bcc && bcc.length > 0) {
639
+ emailContent += `Bcc: ${bcc.join(', ')}\r\n`;
640
+ }
641
+ emailContent += `Subject: ${subject}\r\n`;
642
+ if (reply_to) {
643
+ emailContent += `Reply-To: ${reply_to}\r\n`;
644
+ }
645
+ if (thread_id) {
646
+ emailContent += `In-Reply-To: ${thread_id}\r\n`;
647
+ emailContent += `References: ${thread_id}\r\n`;
648
+ }
649
+ // Handle multipart content
650
+ if (body_text && body_html) {
651
+ const boundary = '----=_Part_0_123456789.123456789';
652
+ emailContent += `Content-Type: multipart/alternative; boundary="${boundary}"\r\n`;
653
+ emailContent += `\r\n`;
654
+ emailContent += `--${boundary}\r\n`;
655
+ emailContent += `Content-Type: text/plain; charset=UTF-8\r\n`;
656
+ emailContent += `\r\n`;
657
+ emailContent += `${body_text}\r\n`;
658
+ emailContent += `--${boundary}\r\n`;
659
+ emailContent += `Content-Type: text/html; charset=UTF-8\r\n`;
660
+ emailContent += `\r\n`;
661
+ emailContent += `${body_html}\r\n`;
662
+ emailContent += `--${boundary}--\r\n`;
663
+ }
664
+ else if (body_html) {
665
+ emailContent += `Content-Type: text/html; charset=UTF-8\r\n`;
666
+ emailContent += `\r\n`;
667
+ emailContent += `${body_html}\r\n`;
668
+ }
669
+ else if (body_text) {
670
+ emailContent += `Content-Type: text/plain; charset=UTF-8\r\n`;
671
+ emailContent += `\r\n`;
672
+ emailContent += `${body_text}\r\n`;
673
+ }
674
+ // Convert to base64url encoding
675
+ return Buffer.from(emailContent)
676
+ .toString('base64')
677
+ .replace(/\+/g, '-')
678
+ .replace(/\//g, '_')
679
+ .replace(/=+$/, '');
680
+ }
681
+ async sendEmail(params) {
682
+ const { to, cc, bcc, subject, body_text, body_html, reply_to, thread_id } = params;
683
+ // Validate that at least one body type is provided
684
+ if (!body_text && !body_html) {
685
+ throw new Error('Either body_text or body_html must be provided');
686
+ }
687
+ const raw = this.createEmailMessage({
688
+ to,
689
+ cc,
690
+ bcc,
691
+ subject,
692
+ body_text,
693
+ body_html,
694
+ reply_to,
695
+ thread_id,
696
+ });
697
+ const messageData = { raw };
698
+ if (thread_id) {
699
+ messageData.threadId = thread_id;
700
+ }
701
+ const response = await this.makeGmailApiRequest('/messages/send', 'POST', messageData);
702
+ return {
703
+ operation: 'send_email',
704
+ success: true,
705
+ message_id: response.id,
706
+ thread_id: response.threadId,
707
+ error: '',
708
+ };
709
+ }
710
+ async listEmails(params) {
711
+ const { query, label_ids, include_spam_trash, max_results, page_token } = params;
712
+ const queryParams = new URLSearchParams({
713
+ maxResults: max_results.toString(),
714
+ });
715
+ if (query)
716
+ queryParams.set('q', query);
717
+ if (label_ids && label_ids.length > 0) {
718
+ label_ids.forEach((labelId) => queryParams.append('labelIds', labelId));
719
+ }
720
+ if (include_spam_trash)
721
+ queryParams.set('includeSpamTrash', 'true');
722
+ if (page_token)
723
+ queryParams.set('pageToken', page_token);
724
+ const response = await this.makeGmailApiRequest(`/messages?${queryParams.toString()}`);
725
+ return {
726
+ operation: 'list_emails',
727
+ success: true,
728
+ messages: response.messages || [],
729
+ next_page_token: response.nextPageToken,
730
+ result_size_estimate: response.resultSizeEstimate,
731
+ error: '',
732
+ };
733
+ }
734
+ async getEmail(params) {
735
+ const { message_id, format, metadata_headers } = params;
736
+ const queryParams = new URLSearchParams({
737
+ format: format,
738
+ });
739
+ if (metadata_headers && metadata_headers.length > 0) {
740
+ metadata_headers.forEach((header) => queryParams.append('metadataHeaders', header));
741
+ }
742
+ const response = await this.makeGmailApiRequest(`/messages/${message_id}?${queryParams.toString()}`);
743
+ return {
744
+ operation: 'get_email',
745
+ success: true,
746
+ message: response,
747
+ error: '',
748
+ };
749
+ }
750
+ async searchEmails(params) {
751
+ const { query, max_results, include_spam_trash } = params;
752
+ const queryParams = new URLSearchParams({
753
+ q: query,
754
+ maxResults: max_results.toString(),
755
+ });
756
+ if (include_spam_trash)
757
+ queryParams.set('includeSpamTrash', 'true');
758
+ const response = await this.makeGmailApiRequest(`/messages?${queryParams.toString()}`);
759
+ return {
760
+ operation: 'search_emails',
761
+ success: true,
762
+ messages: response.messages || [],
763
+ result_size_estimate: response.resultSizeEstimate,
764
+ error: '',
765
+ };
766
+ }
767
+ async markAsRead(params) {
768
+ const { message_ids } = params;
769
+ await this.makeGmailApiRequest('/messages/batchModify', 'POST', {
770
+ ids: message_ids,
771
+ removeLabelIds: ['UNREAD'],
772
+ });
773
+ return {
774
+ operation: 'mark_as_read',
775
+ success: true,
776
+ modified_messages: message_ids,
777
+ error: '',
778
+ };
779
+ }
780
+ async markAsUnread(params) {
781
+ const { message_ids } = params;
782
+ await this.makeGmailApiRequest('/messages/batchModify', 'POST', {
783
+ ids: message_ids,
784
+ addLabelIds: ['UNREAD'],
785
+ });
786
+ return {
787
+ operation: 'mark_as_unread',
788
+ success: true,
789
+ modified_messages: message_ids,
790
+ error: '',
791
+ };
792
+ }
793
+ async createDraft(params) {
794
+ const { to, cc, bcc, subject, body_text, body_html, reply_to, thread_id } = params;
795
+ // Validate that at least one body type is provided
796
+ if (!body_text && !body_html) {
797
+ throw new Error('Either body_text or body_html must be provided');
798
+ }
799
+ const raw = this.createEmailMessage({
800
+ to,
801
+ cc,
802
+ bcc,
803
+ subject,
804
+ body_text,
805
+ body_html,
806
+ reply_to,
807
+ thread_id,
808
+ });
809
+ const draftData = {
810
+ message: { raw },
811
+ };
812
+ if (thread_id) {
813
+ draftData.message.threadId = thread_id;
814
+ }
815
+ const response = await this.makeGmailApiRequest('/drafts', 'POST', draftData);
816
+ return {
817
+ operation: 'create_draft',
818
+ success: true,
819
+ draft: response,
820
+ error: '',
821
+ };
822
+ }
823
+ async sendDraft(params) {
824
+ const { draft_id } = params;
825
+ const response = await this.makeGmailApiRequest(`/drafts/${draft_id}/send`, 'POST', {});
826
+ return {
827
+ operation: 'send_draft',
828
+ success: true,
829
+ message_id: response.id,
830
+ thread_id: response.threadId,
831
+ error: '',
832
+ };
833
+ }
834
+ async listDrafts(params) {
835
+ const { query, max_results, page_token, include_spam_trash } = params;
836
+ const queryParams = new URLSearchParams({
837
+ maxResults: max_results.toString(),
838
+ });
839
+ if (query)
840
+ queryParams.set('q', query);
841
+ if (include_spam_trash)
842
+ queryParams.set('includeSpamTrash', 'true');
843
+ if (page_token)
844
+ queryParams.set('pageToken', page_token);
845
+ const response = await this.makeGmailApiRequest(`/drafts?${queryParams.toString()}`);
846
+ return {
847
+ operation: 'list_drafts',
848
+ success: true,
849
+ drafts: response.drafts || [],
850
+ next_page_token: response.nextPageToken,
851
+ result_size_estimate: response.resultSizeEstimate,
852
+ error: '',
853
+ };
854
+ }
855
+ async deleteEmail(params) {
856
+ const { message_id } = params;
857
+ await this.makeGmailApiRequest(`/messages/${message_id}`, 'DELETE');
858
+ return {
859
+ operation: 'delete_email',
860
+ success: true,
861
+ deleted_message_id: message_id,
862
+ error: '',
863
+ };
864
+ }
865
+ async trashEmail(params) {
866
+ const { message_id } = params;
867
+ await this.makeGmailApiRequest(`/messages/${message_id}/trash`, 'POST');
868
+ return {
869
+ operation: 'trash_email',
870
+ success: true,
871
+ trashed_message_id: message_id,
872
+ error: '',
873
+ };
874
+ }
875
+ async listThreads(params) {
876
+ const { query, label_ids, include_spam_trash, max_results, page_token } = params;
877
+ const queryParams = new URLSearchParams({
878
+ maxResults: max_results.toString(),
879
+ });
880
+ if (query)
881
+ queryParams.set('q', query);
882
+ if (label_ids && label_ids.length > 0) {
883
+ label_ids.forEach((labelId) => queryParams.append('labelIds', labelId));
884
+ }
885
+ if (include_spam_trash)
886
+ queryParams.set('includeSpamTrash', 'true');
887
+ if (page_token)
888
+ queryParams.set('pageToken', page_token);
889
+ const response = await this.makeGmailApiRequest(`/threads?${queryParams.toString()}`);
890
+ return {
891
+ operation: 'list_threads',
892
+ success: true,
893
+ threads: response.threads || [],
894
+ next_page_token: response.nextPageToken,
895
+ result_size_estimate: response.resultSizeEstimate,
896
+ error: '',
897
+ };
898
+ }
899
+ chooseCredential() {
900
+ const { credentials } = this.params;
901
+ if (!credentials || typeof credentials !== 'object') {
902
+ throw new Error('No Gmail credentials provided');
903
+ }
904
+ // Gmail bubble uses GMAIL_CRED credentials
905
+ return credentials[CredentialType.GMAIL_CRED];
906
+ }
907
+ }
908
+ //# sourceMappingURL=gmail.js.map