()
| 70 | } |
| 71 | |
| 72 | export function getNotificationService(): NotificationService { |
| 73 | if (!notificationService) { |
| 74 | notificationService = new NotificationService(); |
| 75 | |
| 76 | // 监听 task:updated,当任务进入 IN_REVIEW 时发送通知 |
| 77 | getEventBus().on('task:updated', ({ taskId, status }) => { |
| 78 | if (status !== 'IN_REVIEW') return; |
| 79 | prisma.task.findUnique({ |
| 80 | where: { id: taskId }, |
| 81 | select: { title: true, projectId: true }, |
| 82 | }) |
| 83 | .then((task) => { |
| 84 | notificationService!.notify({ |
| 85 | type: 'task_in_review', |
| 86 | title: 'Agent Tower', // 模板里会覆盖 |
| 87 | body: '', // 模板里会覆盖 |
| 88 | metadata: { |
| 89 | taskId, |
| 90 | taskTitle: task?.title ?? taskId, |
| 91 | projectId: task?.projectId ?? '', |
| 92 | }, |
| 93 | }); |
| 94 | }) |
| 95 | .catch((err) => { |
| 96 | console.error('[NotificationService] Failed to fetch task for notification:', err); |
| 97 | }); |
| 98 | }); |
| 99 | } |
| 100 | return notificationService; |
| 101 | } |
no test coverage detected