import type { Notification } from "./types.ts"; import { agentContext } from "./agentContext.ts"; import { messageAgent } from "./messageAgent.ts"; import { likePrompt } from "../prompts/likePrompt.ts"; import { mentionPrompt } from "../prompts/mentionPrompt.ts"; import { newFollowerPrompt } from "../prompts/newFollowerPrompt.ts"; import { quotePrompt } from "../prompts/quotePrompt.ts"; import { replyPrompt } from "../prompts/replyPrompt.ts"; import { repostPrompt } from "../prompts/repostPrompt.ts"; const notificationHandlers: any = { like: { promptFn: likePrompt, counter: "likeCount", }, repost: { promptFn: repostPrompt, counter: "repostCount", }, follow: { promptFn: newFollowerPrompt, counter: "followCount", }, mention: { promptFn: mentionPrompt, counter: "mentionCount", }, reply: { promptFn: replyPrompt, counter: "replyCount", }, quote: { promptFn: quotePrompt, counter: "quoteCount", }, } as const; export const processNotification = async (notification: Notification) => { const agentName = agentContext.agentBskyName; const kind = notification.reason; const author = `@${notification.author.handle}`; const handler = notificationHandlers[kind]; if (!handler) { console.log( `🔹 kind "${kind}" does not have a system prompt associated with it, moving on…`, ); console.log("notification response: ", notification); return; } try { const prompt = await handler.promptFn(notification); await messageAgent(prompt); console.log( `🔹 sent ${kind} notification from ${author} to ${agentName}. moving on…`, ); } catch (error) { console.log( `🔹 Error processing ${kind} notification from ${author}: `, error, ); } finally { (agentContext as any)[handler.counter]++; agentContext.notifCount++; } };