UNPKG

@nomyx/assistant

Version:

A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)

41 lines (32 loc) 960 B
import { HistoryEntry, ILogger } from "./types/common"; export class RequestHistory { private history: HistoryEntry[] = []; private maxLength: number; constructor(maxLength: number = 5, private logger?: ILogger) { this.maxLength = maxLength; } addEntry(request: string, response: string): void { const entry: HistoryEntry = { request, response, timestamp: Date.now(), }; this.history.unshift(entry); if (this.history.length > this.maxLength) { this.history.pop(); } this.logger?.debug(`Added new entry to request history. Current history length: ${this.history.length}`); } getHistory(): HistoryEntry[] { return [...this.history]; } clear(): void { this.history = []; this.logger?.info('Request history cleared'); } getFormattedHistory(): string { return this.history.map(entry => `User: ${entry.request}\nAI: ${entry.response}\n` ).join('\n'); } }