a tool to help your Letta AI agents navigate bluesky
at main 1.9 kB view raw
1import type { Notification } from "./types.ts"; 2import { agentContext } from "./agentContext.ts"; 3import { messageAgent } from "./messageAgent.ts"; 4 5import { likePrompt } from "../prompts/likePrompt.ts"; 6import { mentionPrompt } from "../prompts/mentionPrompt.ts"; 7import { newFollowerPrompt } from "../prompts/newFollowerPrompt.ts"; 8import { quotePrompt } from "../prompts/quotePrompt.ts"; 9import { replyPrompt } from "../prompts/replyPrompt.ts"; 10import { repostPrompt } from "../prompts/repostPrompt.ts"; 11 12const notificationHandlers: any = { 13 like: { 14 promptFn: likePrompt, 15 counter: "likeCount", 16 }, 17 repost: { 18 promptFn: repostPrompt, 19 counter: "repostCount", 20 }, 21 follow: { 22 promptFn: newFollowerPrompt, 23 counter: "followCount", 24 }, 25 mention: { 26 promptFn: mentionPrompt, 27 counter: "mentionCount", 28 }, 29 reply: { 30 promptFn: replyPrompt, 31 counter: "replyCount", 32 }, 33 quote: { 34 promptFn: quotePrompt, 35 counter: "quoteCount", 36 }, 37} as const; 38 39export const processNotification = async (notification: Notification) => { 40 const agentName = agentContext.agentBskyName; 41 const kind = notification.reason; 42 const author = `@${notification.author.handle}`; 43 const handler = notificationHandlers[kind]; 44 45 if (!handler) { 46 console.log( 47 `🔹 kind "${kind}" does not have a system prompt associated with it, moving on…`, 48 ); 49 console.log("notification response: ", notification); 50 return; 51 } 52 53 try { 54 const prompt = await handler.promptFn(notification); 55 await messageAgent(prompt); 56 console.log( 57 `🔹 sent ${kind} notification from ${author} to ${agentName}. moving on…`, 58 ); 59 } catch (error) { 60 console.log( 61 `🔹 Error processing ${kind} notification from ${author}: `, 62 error, 63 ); 64 } finally { 65 (agentContext as any)[handler.counter]++; 66 agentContext.notifCount++; 67 } 68};