@fatagnus/convex-feedback 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 (78) hide show
  1. package/LICENSE +177 -0
  2. package/README.md +382 -0
  3. package/dist/convex/agents/bugReportAgent.d.ts +30 -0
  4. package/dist/convex/agents/bugReportAgent.d.ts.map +1 -0
  5. package/dist/convex/agents/bugReportAgent.js +243 -0
  6. package/dist/convex/agents/bugReportAgent.js.map +1 -0
  7. package/dist/convex/agents/feedbackAgent.d.ts +29 -0
  8. package/dist/convex/agents/feedbackAgent.d.ts.map +1 -0
  9. package/dist/convex/agents/feedbackAgent.js +232 -0
  10. package/dist/convex/agents/feedbackAgent.js.map +1 -0
  11. package/dist/convex/bugReports.d.ts +49 -0
  12. package/dist/convex/bugReports.d.ts.map +1 -0
  13. package/dist/convex/bugReports.js +321 -0
  14. package/dist/convex/bugReports.js.map +1 -0
  15. package/dist/convex/convex.config.d.ts +3 -0
  16. package/dist/convex/convex.config.d.ts.map +1 -0
  17. package/dist/convex/convex.config.js +6 -0
  18. package/dist/convex/convex.config.js.map +1 -0
  19. package/dist/convex/emails/bugReportEmails.d.ts +16 -0
  20. package/dist/convex/emails/bugReportEmails.d.ts.map +1 -0
  21. package/dist/convex/emails/bugReportEmails.js +403 -0
  22. package/dist/convex/emails/bugReportEmails.js.map +1 -0
  23. package/dist/convex/emails/feedbackEmails.d.ts +16 -0
  24. package/dist/convex/emails/feedbackEmails.d.ts.map +1 -0
  25. package/dist/convex/emails/feedbackEmails.js +389 -0
  26. package/dist/convex/emails/feedbackEmails.js.map +1 -0
  27. package/dist/convex/feedback.d.ts +49 -0
  28. package/dist/convex/feedback.d.ts.map +1 -0
  29. package/dist/convex/feedback.js +327 -0
  30. package/dist/convex/feedback.js.map +1 -0
  31. package/dist/convex/index.d.ts +10 -0
  32. package/dist/convex/index.d.ts.map +1 -0
  33. package/dist/convex/index.js +12 -0
  34. package/dist/convex/index.js.map +1 -0
  35. package/dist/convex/schema.d.ts +200 -0
  36. package/dist/convex/schema.d.ts.map +1 -0
  37. package/dist/convex/schema.js +150 -0
  38. package/dist/convex/schema.js.map +1 -0
  39. package/dist/convex/supportTeams.d.ts +29 -0
  40. package/dist/convex/supportTeams.d.ts.map +1 -0
  41. package/dist/convex/supportTeams.js +159 -0
  42. package/dist/convex/supportTeams.js.map +1 -0
  43. package/dist/index.d.ts +70 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +63 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/react/BugReportButton.d.ts +70 -0
  48. package/dist/react/BugReportButton.d.ts.map +1 -0
  49. package/dist/react/BugReportButton.js +371 -0
  50. package/dist/react/BugReportButton.js.map +1 -0
  51. package/dist/react/BugReportContext.d.ts +59 -0
  52. package/dist/react/BugReportContext.d.ts.map +1 -0
  53. package/dist/react/BugReportContext.js +107 -0
  54. package/dist/react/BugReportContext.js.map +1 -0
  55. package/dist/react/index.d.ts +36 -0
  56. package/dist/react/index.d.ts.map +1 -0
  57. package/dist/react/index.js +36 -0
  58. package/dist/react/index.js.map +1 -0
  59. package/dist/types.d.ts +89 -0
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +5 -0
  62. package/dist/types.js.map +1 -0
  63. package/package.json +101 -0
  64. package/src/convex/agents/bugReportAgent.ts +277 -0
  65. package/src/convex/agents/feedbackAgent.ts +264 -0
  66. package/src/convex/bugReports.ts +350 -0
  67. package/src/convex/convex.config.ts +7 -0
  68. package/src/convex/emails/bugReportEmails.ts +479 -0
  69. package/src/convex/emails/feedbackEmails.ts +465 -0
  70. package/src/convex/feedback.ts +356 -0
  71. package/src/convex/index.ts +28 -0
  72. package/src/convex/schema.ts +207 -0
  73. package/src/convex/supportTeams.ts +179 -0
  74. package/src/index.ts +77 -0
  75. package/src/react/BugReportButton.tsx +755 -0
  76. package/src/react/BugReportContext.tsx +146 -0
  77. package/src/react/index.ts +46 -0
  78. package/src/types.ts +93 -0
@@ -0,0 +1,479 @@
1
+ /**
2
+ * Bug Report Email Notifications
3
+ *
4
+ * Sends email notifications using Resend when bug reports are analyzed.
5
+ * - Reporter receives a thank-you email with summary
6
+ * - Team members receive full analysis report
7
+ */
8
+
9
+ import { v } from "convex/values";
10
+ import { internalAction, internalQuery } from "../_generated/server";
11
+ import { internal } from "../_generated/api";
12
+ import { Resend } from "resend";
13
+ import type { BugSeverity } from "../schema";
14
+
15
+ // Severity labels and colors
16
+ const severityConfig: Record<string, { label: string; color: string }> = {
17
+ low: { label: "Low", color: "#22c55e" },
18
+ medium: { label: "Medium", color: "#f59e0b" },
19
+ high: { label: "High", color: "#ea580c" },
20
+ critical: { label: "Critical", color: "#ef4444" },
21
+ };
22
+
23
+ // Effort labels
24
+ const effortLabels: Record<string, string> = {
25
+ low: "Low (< 1 week)",
26
+ medium: "Medium (1-4 weeks)",
27
+ high: "High (> 4 weeks)",
28
+ };
29
+
30
+ // ============================================================================
31
+ // Internal Queries
32
+ // ============================================================================
33
+
34
+ /**
35
+ * Get full bug report data for email
36
+ */
37
+ export const getBugReportForEmail = internalQuery({
38
+ args: {
39
+ reportId: v.id("bugReports"),
40
+ },
41
+ returns: v.union(
42
+ v.object({
43
+ _id: v.id("bugReports"),
44
+ title: v.string(),
45
+ description: v.string(),
46
+ severity: v.string(),
47
+ status: v.string(),
48
+ reporterName: v.string(),
49
+ reporterEmail: v.string(),
50
+ url: v.string(),
51
+ consoleErrors: v.optional(v.string()),
52
+ createdAt: v.number(),
53
+ }),
54
+ v.null()
55
+ ),
56
+ handler: async (ctx, args) => {
57
+ const report = await ctx.db.get(args.reportId);
58
+ if (!report) {
59
+ return null;
60
+ }
61
+ return {
62
+ _id: report._id,
63
+ title: report.title,
64
+ description: report.description,
65
+ severity: report.severity,
66
+ status: report.status,
67
+ reporterName: report.reporterName,
68
+ reporterEmail: report.reporterEmail,
69
+ url: report.url,
70
+ consoleErrors: report.consoleErrors,
71
+ createdAt: report.createdAt,
72
+ };
73
+ },
74
+ });
75
+
76
+ // ============================================================================
77
+ // Email Templates
78
+ // ============================================================================
79
+
80
+ function generateReporterEmailHtml(report: {
81
+ title: string;
82
+ summary: string;
83
+ reporterName: string;
84
+ }): string {
85
+ return `
86
+ <!DOCTYPE html>
87
+ <html>
88
+ <head>
89
+ <meta charset="utf-8">
90
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
91
+ <title>Thank You for Your Bug Report</title>
92
+ </head>
93
+ <body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
94
+ <div style="background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); padding: 30px; border-radius: 10px 10px 0 0;">
95
+ <h1 style="color: white; margin: 0; font-size: 24px;">Thank You for Your Bug Report!</h1>
96
+ </div>
97
+
98
+ <div style="background: #f8f9fa; padding: 30px; border: 1px solid #e9ecef; border-top: none; border-radius: 0 0 10px 10px;">
99
+ <p style="margin-top: 0;">Hi ${report.reporterName},</p>
100
+
101
+ <p>Thank you for reporting this issue. We've received your bug report and our team is already investigating.</p>
102
+
103
+ <div style="background: white; padding: 20px; border-radius: 8px; border-left: 4px solid #ef4444; margin: 20px 0;">
104
+ <h3 style="margin: 0 0 10px 0; color: #ef4444;">${report.title}</h3>
105
+ <p style="margin: 0; color: #666;">${report.summary}</p>
106
+ </div>
107
+
108
+ <p>We take all bug reports seriously and will work to resolve this issue as quickly as possible. You may receive updates as we make progress.</p>
109
+
110
+ <p style="margin-bottom: 0;">Best regards,<br><strong>The Support Team</strong></p>
111
+ </div>
112
+
113
+ <div style="text-align: center; padding: 20px; color: #999; font-size: 12px;">
114
+ <p>This is an automated message. Please do not reply directly to this email.</p>
115
+ </div>
116
+ </body>
117
+ </html>
118
+ `;
119
+ }
120
+
121
+ function generateTeamEmailHtml(
122
+ report: {
123
+ title: string;
124
+ description: string;
125
+ severity: string;
126
+ reporterName: string;
127
+ reporterEmail: string;
128
+ url: string;
129
+ consoleErrors?: string;
130
+ createdAt: number;
131
+ },
132
+ analysis: {
133
+ summary: string;
134
+ rootCauseAnalysis: string;
135
+ reproductionSteps: string[];
136
+ suggestedFix: string;
137
+ estimatedEffort: string;
138
+ }
139
+ ): string {
140
+ const severityInfo = severityConfig[report.severity] || severityConfig.medium;
141
+ const effortLabel = effortLabels[analysis.estimatedEffort] || analysis.estimatedEffort;
142
+ const submittedDate = new Date(report.createdAt).toLocaleString();
143
+
144
+ const reproductionStepsHtml = analysis.reproductionSteps
145
+ .map((step) => `<li style="margin-bottom: 8px;">${step}</li>`)
146
+ .join("");
147
+
148
+ let consoleErrorsHtml = "";
149
+ if (report.consoleErrors) {
150
+ try {
151
+ const errors = JSON.parse(report.consoleErrors);
152
+ if (Array.isArray(errors) && errors.length > 0) {
153
+ const errorItems = errors
154
+ .slice(0, 10)
155
+ .map(
156
+ (err: { message?: string } | string) =>
157
+ `<li style="margin-bottom: 4px; font-family: monospace; font-size: 12px; word-break: break-all;">${typeof err === 'string' ? err : err.message || JSON.stringify(err)}</li>`
158
+ )
159
+ .join("");
160
+ consoleErrorsHtml = `
161
+ <div style="background: #fef2f2; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
162
+ <h3 style="margin: 0 0 10px 0; color: #991b1b; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px;">🔴 Console Errors</h3>
163
+ <ul style="margin: 0; padding-left: 20px; color: #333;">
164
+ ${errorItems}
165
+ </ul>
166
+ </div>`;
167
+ }
168
+ } catch {
169
+ // Invalid JSON, skip console errors section
170
+ }
171
+ }
172
+
173
+ return `
174
+ <!DOCTYPE html>
175
+ <html>
176
+ <head>
177
+ <meta charset="utf-8">
178
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
179
+ <title>New Bug Report Analysis</title>
180
+ </head>
181
+ <body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; color: #333; max-width: 700px; margin: 0 auto; padding: 20px; background: #f5f5f5;">
182
+ <div style="background: white; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); overflow: hidden;">
183
+ <!-- Header -->
184
+ <div style="background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); padding: 25px 30px;">
185
+ <h1 style="color: white; margin: 0; font-size: 22px;">New Bug Report Received</h1>
186
+ <p style="color: rgba(255,255,255,0.9); margin: 10px 0 0 0; font-size: 14px;">AI-Analyzed Bug Report</p>
187
+ </div>
188
+
189
+ <!-- Content -->
190
+ <div style="padding: 30px;">
191
+ <!-- Title & Severity Badge -->
192
+ <div style="margin-bottom: 25px;">
193
+ <h2 style="margin: 0 0 10px 0; color: #1a1a2e;">${report.title}</h2>
194
+ <span style="display: inline-block; background: ${severityInfo.color}; color: white; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;">
195
+ ${severityInfo.label} Severity
196
+ </span>
197
+ <span style="display: inline-block; background: #e0e7ff; color: #4338ca; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-left: 8px;">
198
+ ${effortLabel}
199
+ </span>
200
+ </div>
201
+
202
+ <!-- AI Summary -->
203
+ <div style="background: #f0f4ff; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
204
+ <h3 style="margin: 0 0 10px 0; color: #4338ca; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px;">📋 AI Summary</h3>
205
+ <p style="margin: 0; color: #333;">${analysis.summary}</p>
206
+ </div>
207
+
208
+ <!-- Root Cause Analysis -->
209
+ <div style="background: #fff7ed; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
210
+ <h3 style="margin: 0 0 10px 0; color: #c2410c; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px;">🔍 Root Cause Analysis</h3>
211
+ <p style="margin: 0; color: #333;">${analysis.rootCauseAnalysis}</p>
212
+ </div>
213
+
214
+ <!-- Reproduction Steps -->
215
+ <div style="background: #fefce8; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
216
+ <h3 style="margin: 0 0 15px 0; color: #854d0e; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px;">🔄 Reproduction Steps</h3>
217
+ <ol style="margin: 0; padding-left: 20px; color: #333;">
218
+ ${reproductionStepsHtml}
219
+ </ol>
220
+ </div>
221
+
222
+ <!-- Suggested Fix -->
223
+ <div style="background: #f0fdf4; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
224
+ <h3 style="margin: 0 0 10px 0; color: #166534; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px;">💡 Suggested Fix</h3>
225
+ <p style="margin: 0; color: #333;">${analysis.suggestedFix}</p>
226
+ </div>
227
+
228
+ ${consoleErrorsHtml}
229
+
230
+ <!-- Original Bug Description -->
231
+ <div style="border: 1px solid #e5e7eb; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
232
+ <h3 style="margin: 0 0 10px 0; color: #6b7280; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px;">📝 Original Bug Description</h3>
233
+ <p style="margin: 0; color: #333; white-space: pre-wrap;">${report.description}</p>
234
+ </div>
235
+
236
+ <!-- Reporter Info -->
237
+ <div style="background: #f9fafb; padding: 15px 20px; border-radius: 8px; font-size: 14px;">
238
+ <table style="width: 100%; border-collapse: collapse;">
239
+ <tr>
240
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Reporter:</strong></td>
241
+ <td style="padding: 5px 0;">${report.reporterName}</td>
242
+ </tr>
243
+ <tr>
244
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Email:</strong></td>
245
+ <td style="padding: 5px 0;"><a href="mailto:${report.reporterEmail}" style="color: #4338ca;">${report.reporterEmail}</a></td>
246
+ </tr>
247
+ <tr>
248
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Submitted:</strong></td>
249
+ <td style="padding: 5px 0;">${submittedDate}</td>
250
+ </tr>
251
+ <tr>
252
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Page URL:</strong></td>
253
+ <td style="padding: 5px 0;"><a href="${report.url}" style="color: #4338ca; word-break: break-all;">${report.url}</a></td>
254
+ </tr>
255
+ </table>
256
+ </div>
257
+ </div>
258
+ </div>
259
+
260
+ <div style="text-align: center; padding: 20px; color: #999; font-size: 12px;">
261
+ <p>This analysis was generated by AI. Please review and verify before taking action.</p>
262
+ </div>
263
+ </body>
264
+ </html>
265
+ `;
266
+ }
267
+
268
+ function generateSimpleTeamEmailHtml(report: {
269
+ title: string;
270
+ description: string;
271
+ severity: string;
272
+ reporterName: string;
273
+ reporterEmail: string;
274
+ url: string;
275
+ createdAt: number;
276
+ }): string {
277
+ const severityInfo = severityConfig[report.severity] || severityConfig.medium;
278
+ const submittedDate = new Date(report.createdAt).toLocaleString();
279
+
280
+ return `
281
+ <!DOCTYPE html>
282
+ <html>
283
+ <head>
284
+ <meta charset="utf-8">
285
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
286
+ <title>New Bug Report</title>
287
+ </head>
288
+ <body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; color: #333; max-width: 700px; margin: 0 auto; padding: 20px; background: #f5f5f5;">
289
+ <div style="background: white; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); overflow: hidden;">
290
+ <div style="background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); padding: 25px 30px;">
291
+ <h1 style="color: white; margin: 0; font-size: 22px;">New Bug Report Received</h1>
292
+ </div>
293
+
294
+ <div style="padding: 30px;">
295
+ <div style="margin-bottom: 25px;">
296
+ <h2 style="margin: 0 0 10px 0; color: #1a1a2e;">${report.title}</h2>
297
+ <span style="display: inline-block; background: ${severityInfo.color}; color: white; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;">
298
+ ${severityInfo.label} Severity
299
+ </span>
300
+ </div>
301
+
302
+ <div style="border: 1px solid #e5e7eb; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
303
+ <h3 style="margin: 0 0 10px 0; color: #6b7280; font-size: 14px;">Description</h3>
304
+ <p style="margin: 0; color: #333; white-space: pre-wrap;">${report.description}</p>
305
+ </div>
306
+
307
+ <div style="background: #f9fafb; padding: 15px 20px; border-radius: 8px; font-size: 14px;">
308
+ <table style="width: 100%; border-collapse: collapse;">
309
+ <tr>
310
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Reporter:</strong></td>
311
+ <td style="padding: 5px 0;">${report.reporterName} (${report.reporterEmail})</td>
312
+ </tr>
313
+ <tr>
314
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Submitted:</strong></td>
315
+ <td style="padding: 5px 0;">${submittedDate}</td>
316
+ </tr>
317
+ <tr>
318
+ <td style="padding: 5px 0; color: #6b7280;"><strong>Page URL:</strong></td>
319
+ <td style="padding: 5px 0;"><a href="${report.url}" style="color: #4338ca;">${report.url}</a></td>
320
+ </tr>
321
+ </table>
322
+ </div>
323
+ </div>
324
+ </div>
325
+ </body>
326
+ </html>
327
+ `;
328
+ }
329
+
330
+ // ============================================================================
331
+ // Email Sending Action
332
+ // ============================================================================
333
+
334
+ /**
335
+ * Send bug report notifications to reporter and team.
336
+ */
337
+ export const sendBugReportNotifications = internalAction({
338
+ args: {
339
+ reportId: v.id("bugReports"),
340
+ analysis: v.union(
341
+ v.object({
342
+ summary: v.string(),
343
+ rootCauseAnalysis: v.string(),
344
+ reproductionSteps: v.array(v.string()),
345
+ suggestedFix: v.string(),
346
+ estimatedEffort: v.string(),
347
+ }),
348
+ v.null()
349
+ ),
350
+ },
351
+ returns: v.object({
352
+ success: v.boolean(),
353
+ reporterEmailSent: v.boolean(),
354
+ teamEmailsSent: v.number(),
355
+ error: v.optional(v.string()),
356
+ }),
357
+ handler: async (
358
+ ctx,
359
+ args
360
+ ): Promise<{
361
+ success: boolean;
362
+ reporterEmailSent: boolean;
363
+ teamEmailsSent: number;
364
+ error?: string;
365
+ }> => {
366
+ // Check for Resend API key
367
+ const resendApiKey = process.env.RESEND_API_KEY;
368
+ if (!resendApiKey) {
369
+ console.warn("RESEND_API_KEY not configured. Skipping email notifications.");
370
+ return {
371
+ success: false,
372
+ reporterEmailSent: false,
373
+ teamEmailsSent: 0,
374
+ error: "RESEND_API_KEY not configured",
375
+ };
376
+ }
377
+
378
+ const resend = new Resend(resendApiKey);
379
+ const fromEmail = process.env.RESEND_FROM_EMAIL || "bugs@resend.dev";
380
+
381
+ // Get bug report data
382
+ const report = await ctx.runQuery(
383
+ internal.emails.bugReportEmails.getBugReportForEmail,
384
+ {
385
+ reportId: args.reportId,
386
+ }
387
+ );
388
+
389
+ if (!report) {
390
+ return {
391
+ success: false,
392
+ reporterEmailSent: false,
393
+ teamEmailsSent: 0,
394
+ error: "Bug report not found",
395
+ };
396
+ }
397
+
398
+ let reporterEmailSent = false;
399
+ let teamEmailsSent = 0;
400
+
401
+ // Send email to reporter
402
+ try {
403
+ const summary = args.analysis?.summary || "We are investigating your report.";
404
+ const reporterHtml = generateReporterEmailHtml({
405
+ title: report.title,
406
+ summary,
407
+ reporterName: report.reporterName,
408
+ });
409
+
410
+ await resend.emails.send({
411
+ from: fromEmail,
412
+ to: [report.reporterEmail],
413
+ subject: `Thank you for your bug report: ${report.title}`,
414
+ html: reporterHtml,
415
+ });
416
+
417
+ reporterEmailSent = true;
418
+ console.log(`Reporter email sent to ${report.reporterEmail}`);
419
+ } catch (error) {
420
+ console.error("Failed to send reporter email:", error);
421
+ }
422
+
423
+ // Get teams that handle this bug report severity
424
+ const teams = await ctx.runQuery(internal.supportTeams.getTeamsForBugReportSeverity, {
425
+ severity: report.severity as BugSeverity,
426
+ });
427
+
428
+ // Generate team email HTML
429
+ const teamHtml = args.analysis
430
+ ? generateTeamEmailHtml(
431
+ {
432
+ title: report.title,
433
+ description: report.description,
434
+ severity: report.severity,
435
+ reporterName: report.reporterName,
436
+ reporterEmail: report.reporterEmail,
437
+ url: report.url,
438
+ consoleErrors: report.consoleErrors,
439
+ createdAt: report.createdAt,
440
+ },
441
+ args.analysis
442
+ )
443
+ : generateSimpleTeamEmailHtml({
444
+ title: report.title,
445
+ description: report.description,
446
+ severity: report.severity,
447
+ reporterName: report.reporterName,
448
+ reporterEmail: report.reporterEmail,
449
+ url: report.url,
450
+ createdAt: report.createdAt,
451
+ });
452
+
453
+ // Send email to all team members from all matching teams
454
+ for (const team of teams) {
455
+ if (team.isActive && team.memberEmails.length > 0) {
456
+ for (const email of team.memberEmails) {
457
+ try {
458
+ await resend.emails.send({
459
+ from: fromEmail,
460
+ to: [email],
461
+ subject: `[Bug Report - ${severityConfig[report.severity]?.label || report.severity}] ${report.title}${args.analysis ? " - AI Analysis" : ""}`,
462
+ html: teamHtml,
463
+ });
464
+ teamEmailsSent++;
465
+ console.log(`Team email sent to ${email}`);
466
+ } catch (error) {
467
+ console.error(`Failed to send team email to ${email}:`, error);
468
+ }
469
+ }
470
+ }
471
+ }
472
+
473
+ return {
474
+ success: true,
475
+ reporterEmailSent,
476
+ teamEmailsSent,
477
+ };
478
+ },
479
+ });