a tool to help your Letta AI agents navigate bluesky
1import { bsky } from "./bsky.ts";
2
3const notificationTypes = (Deno.env.get("BSKY_NOTIFICATION_TYPES") ||
4 "mention,reply")
5 .split(",")
6 .map((type) => type.trim());
7
8const supportedTools = (Deno.env.get("BSKY_SUPPORTED_TOOLS") ||
9 "mention,reply")
10 .split(",")
11 .map((type) => type.trim());
12
13const agentName = Deno.env.get("LETTA_PROJECT_NAME")
14 ? Deno.env.get("LETTA_PROJECT_NAME")
15 : "Agent";
16
17const agentBskyDID = bsky?.did ? bsky.did : "";
18
19const delayNotifMin: number = Deno.env.get("DELAY_NOTIF_SECONDS_MIN")
20 ? Number(Deno.env.get("DELAY_NOTIF_SECONDS_MIN")) * 1000
21 : 20000;
22
23const delayNotifMax: number = Deno.env.get("DELAY_NOTIF_SECONDS_MAX")
24 ? Number(Deno.env.get("DELAY_NOTIF_SECONDS_MAX")) * 1000
25 : 300000;
26
27const delayNotifMultiplier = Deno.env.get("DELAY_NOTIF_MULTIPLIER_PERCENT")
28 ? (Number(Deno.env.get("DELAY_NOTIF_MULTIPLIER_PERCENT")) / 100) + 1
29 : 1.05;
30
31const reflectionEnabled =
32 Deno.env.get("REFLECTION_ENABLED")?.toLowerCase() === "true";
33
34const isProactive = Deno.env.get("IS_PROACTIVE")?.toLowerCase() === "true";
35
36const delayReflectMin: number = Deno.env.get("DELAY_REFLECT_MINUTES_MIN")
37 ? Number(Deno.env.get("DELAY_REFLECT_MINUTES_MIN"))
38 : 30;
39
40const delayReflectMax: number = Deno.env.get("DELAY_REFLECT_MINUTES_MAX")
41 ? Number(Deno.env.get("DELAY_REFLECT_MINUTES_MAX"))
42 : 720;
43
44const sleepTimeEnabled = Deno.env.get("SLEEP_TIME") && Deno.env.get("WAKE_TIME")
45 ? true
46 : false;
47
48const timeZone: string = Deno.env.get("TIME_ZONE") ?? "America/Los_Angeles";
49
50const wakeTime = Deno.env.get("WAKE_TIME")
51 ? Number(Deno.env.get("WAKE_TIME"))
52 : 7;
53const sleepTime = Deno.env.get("SLEEP_TIME")
54 ? Number(Deno.env.get("SLEEP_TIME"))
55 : 23;
56
57export const session = {
58 busy: false,
59 checkCount: 0,
60 reflectionCount: 0,
61 processingCount: 0,
62 likeCount: 0,
63 repostCount: 0,
64 followCount: 0,
65 mentionCount: 0,
66 replyCount: 0,
67 quoteCount: 0,
68 get totalNotifs() {
69 return (
70 this.likeCount +
71 this.repostCount +
72 this.followCount +
73 this.mentionCount +
74 this.replyCount +
75 this.quoteCount
76 );
77 },
78 agentName: agentName,
79 agentBskyDID: agentBskyDID,
80 notificationTypes: notificationTypes,
81 supportedTools: supportedTools,
82 minNotifDelaySeconds: delayNotifMin,
83 currentNotifDelaySeconds: delayNotifMin,
84 maxNotifDelaySeconds: delayNotifMax,
85 notifDelayMultiplier: delayNotifMultiplier,
86 reflectionEnabled: reflectionEnabled,
87 isProactive: isProactive,
88 minReflectDelayMinutes: delayReflectMin,
89 currentReflectDelayMinutes: delayReflectMin,
90 maxReflectDelayMinutes: delayReflectMax,
91 sleepTimeEnabled: sleepTimeEnabled,
92 timeZone: timeZone,
93 wakeTime: wakeTime,
94 sleepTime: sleepTime,
95};
96
97export const claimTaskThread = () => {
98 if (session.busy) return false;
99 session.busy = true;
100 return true;
101};
102
103export const releaseTaskThread = () => {
104 session.busy = false;
105};
106
107export const resetSessionCounts = () => {
108 session.likeCount = 0;
109 session.repostCount = 0;
110 session.followCount = 0;
111 session.mentionCount = 0;
112 session.replyCount = 0;
113 session.quoteCount = 0;
114 session.checkCount = 0;
115 session.processingCount = 0;
116};