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:
@@ -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[] {
|
||||
|
||||
Reference in New Issue
Block a user