feat: wire daemon, agent, and telegram bot together

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
William Valentin
2026-02-02 21:02:50 -08:00
parent d0fe4c5b35
commit b6b85f07d0
2 changed files with 49 additions and 3 deletions
+41 -1
View File
@@ -1,14 +1,41 @@
import { Bot } from 'grammy';
import { Lifecycle } from './lifecycle.js';
import type { Config } from '../config/index.js';
import { AnthropicClient } from '../models/index.js';
import { NativeAgent } from '../backends/index.js';
import { createTelegramBot } from '../frontends/telegram/index.js';
export interface DaemonContext {
config: Config;
lifecycle: Lifecycle;
bot: Bot;
agent: NativeAgent;
}
const SYSTEM_PROMPT = `You are Flynn, a helpful personal AI assistant. You are direct, concise, and helpful. You can help with a variety of tasks including answering questions, providing information, and having conversations.
Keep responses focused and avoid unnecessary verbosity. Use markdown formatting when it improves readability.`;
export async function startDaemon(config: Config): Promise<DaemonContext> {
const lifecycle = new Lifecycle();
// Initialize model client
const modelClient = new AnthropicClient({
model: config.models.default.model,
});
// Initialize native agent
const agent = new NativeAgent({
modelClient,
systemPrompt: SYSTEM_PROMPT,
});
// Initialize Telegram bot
const bot = createTelegramBot({
telegram: config.telegram,
agent,
});
// Register signal handlers
const signalHandler = () => {
lifecycle.shutdown().then(() => process.exit(0));
@@ -22,9 +49,22 @@ export async function startDaemon(config: Config): Promise<DaemonContext> {
process.off('SIGTERM', signalHandler);
});
// Start bot
lifecycle.onShutdown(async () => {
await bot.stop();
console.log('Telegram bot stopped');
});
// Use long polling (no webhook, no internet exposure)
bot.start({
onStart: (botInfo) => {
console.log(`Telegram bot started: @${botInfo.username}`);
},
});
console.log('Flynn daemon started');
return { config, lifecycle };
return { config, lifecycle, bot, agent };
}
export { Lifecycle } from './lifecycle.js';