feat: integrate model router, session persistence, and hook engine

- NativeAgent now loads/saves messages to SessionStore
- Daemon creates ModelRouter with fallback chain support
- Telegram bot handles confirmation callbacks from HookEngine
- Session data stored in ~/.local/share/flynn/sessions.db

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
William Valentin
2026-02-05 00:05:42 -08:00
parent 26bd6ce65d
commit 6e6c263e14
3 changed files with 143 additions and 12 deletions
+27 -2
View File
@@ -1,35 +1,60 @@
import type { ModelClient, Message } from '../../models/types.js';
import type { SessionStore } from '../../session/index.js';
export interface NativeAgentConfig {
modelClient: ModelClient;
systemPrompt: string;
sessionStore?: SessionStore;
sessionId?: string;
}
export class NativeAgent {
private modelClient: ModelClient;
private systemPrompt: string;
private sessionStore?: SessionStore;
private sessionId: string;
private history: Message[] = [];
constructor(config: NativeAgentConfig) {
this.modelClient = config.modelClient;
this.systemPrompt = config.systemPrompt;
this.sessionStore = config.sessionStore;
this.sessionId = config.sessionId ?? 'default';
// Load existing history from store
if (this.sessionStore) {
this.history = this.sessionStore.getMessages(this.sessionId);
}
}
async process(userMessage: string): Promise<string> {
this.history.push({ role: 'user', content: userMessage });
const userMsg: Message = { role: 'user', content: userMessage };
this.history.push(userMsg);
if (this.sessionStore) {
this.sessionStore.addMessage(this.sessionId, userMsg);
}
const response = await this.modelClient.chat({
messages: [...this.history],
system: this.systemPrompt,
});
this.history.push({ role: 'assistant', content: response.content });
const assistantMsg: Message = { role: 'assistant', content: response.content };
this.history.push(assistantMsg);
if (this.sessionStore) {
this.sessionStore.addMessage(this.sessionId, assistantMsg);
}
return response.content;
}
reset(): void {
this.history = [];
if (this.sessionStore) {
this.sessionStore.clearSession(this.sessionId);
}
}
getHistory(): Message[] {