Repository navigation
Expand file tree
/
Copy pathbot.ts
More file actions
58 lines (48 loc) · 1.83 KB
/
Copy pathbot.ts
File metadata and controls
58 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Chat } from "chat";
import { SlackAdapter } from "@chat-adapter/slack";
import { createWhatsAppAdapter, WhatsAppAdapter } from "@chat-adapter/whatsapp";
import { createGitHubAdapter } from "@chat-adapter/github";
import { agentLogger, createAgentState } from "@/lib/agents/createAgentState";
import type { CodingAgentThreadState } from "./types";
import { validateCodingAgentEnv } from "./validateEnv";
import { isWhatsAppConfigured } from "./whatsApp/isWhatsAppConfigured";
type CodingAgentAdapters = {
slack: SlackAdapter;
github: ReturnType<typeof createGitHubAdapter>;
whatsapp?: WhatsAppAdapter;
};
/**
* Creates a new Chat bot instance configured with Slack, GitHub, and optionally WhatsApp adapters.
*
* @returns The configured Chat bot instance
*/
export function createCodingAgentBot() {
validateCodingAgentEnv();
const state = createAgentState("coding-agent");
const slack = new SlackAdapter({
botToken: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
logger: agentLogger,
});
const github = createGitHubAdapter({
token: process.env.GITHUB_TOKEN!,
webhookSecret: process.env.GITHUB_WEBHOOK_SECRET!,
userName: process.env.GITHUB_BOT_USERNAME ?? "recoup-coding-agent",
logger: agentLogger,
});
const adapters: CodingAgentAdapters = { slack, github };
if (isWhatsAppConfigured()) {
adapters.whatsapp = createWhatsAppAdapter({ logger: agentLogger });
}
return new Chat<CodingAgentAdapters, CodingAgentThreadState>({
userName: "Recoup Agent",
adapters,
state,
});
}
export type CodingAgentBot = ReturnType<typeof createCodingAgentBot>;
/**
* Singleton bot instance. Registers as the Chat SDK singleton
* so ThreadImpl can resolve adapters lazily from thread IDs.
*/
export const codingAgentBot = createCodingAgentBot().registerSingleton();