diff --git a/src/hooks/useAIChat.ts b/src/hooks/useAIChat.ts index ff3cc410..e96a64bb 100644 --- a/src/hooks/useAIChat.ts +++ b/src/hooks/useAIChat.ts @@ -47,7 +47,7 @@ export function useAIChat({ useEffect(() => { const initSession = async () => { // Check if there's already an active session for this project - const existingSession = sessionManager.getProjectSession(projectId); + const existingSession = sessionManager.getSession(projectId); if (existingSession) { // Initialize individual state variables from existing session diff --git a/src/hooks/useProjectSessionStatus.ts b/src/hooks/useProjectSessionStatus.ts index 0593d4e4..1fdb61b2 100644 --- a/src/hooks/useProjectSessionStatus.ts +++ b/src/hooks/useProjectSessionStatus.ts @@ -11,7 +11,7 @@ export function useProjectSessionStatus(projectId: string) { useEffect(() => { const updateStatus = () => { - const projectSession = sessionManager.getProjectSession(projectId); + const projectSession = sessionManager.getSession(projectId); setHasActiveSessions(!!projectSession); setHasRunningSessions(!!projectSession?.isLoading); diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index d4fd2685..f8df1f2f 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -47,10 +47,6 @@ export class SessionManager { private aiSettings: { providers: Record }; private getProviderModels?: () => Array<{ id: string; provider: string; contextLength?: number; pricing?: { prompt: import('decimal.js').Decimal; completion: import('decimal.js').Decimal } }>; - // Performance constants - private readonly MAX_SESSIONS = 50; - private readonly MAX_SESSION_AGE = 7 * 24 * 60 * 60 * 1000; // 7 days - constructor( fs: JSRuntimeFS, aiSettings: { providers: Record }, @@ -118,13 +114,6 @@ export class SessionManager { return Array.from(this.sessions.values()); } - /** - * Get session for a specific project - */ - getProjectSession(projectId: string): SessionState | undefined { - return this.sessions.get(projectId); - } - /** * Delete a session */ @@ -137,13 +126,6 @@ export class SessionManager { this.emit('sessionDeleted', projectId); } - /** - * Delete session for a project - */ - async deleteProjectSession(projectId: string): Promise { - await this.deleteSession(projectId); - } - /** * Add a message to a session */ @@ -155,8 +137,6 @@ export class SessionManager { session.lastActivity = new Date(); await this.saveSessionHistory(projectId); - this.cleanupOldSessions(); - this.emit('messageAdded', projectId, message); } @@ -310,7 +290,6 @@ export class SessionManager { // Save and emit all updates together await this.saveSessionHistory(projectId); - this.cleanupOldSessions(); this.emit('messageAdded', projectId, assistantMessage); conversationMessages.push(assistantMessage); @@ -395,28 +374,6 @@ export class SessionManager { this.emit('loadingChanged', projectId, false); } - /** - * Clean up old sessions to prevent memory bloat - */ - private cleanupOldSessions(): void { - const now = Date.now(); - - // Delete old sessions - for (const [projectId, session] of this.sessions) { - if (now - session.lastActivity.getTime() > this.MAX_SESSION_AGE) { - this.deleteSession(projectId); - } - } - - // Delete oldest sessions if we have too many - if (this.sessions.size > this.MAX_SESSIONS) { - Array.from(this.sessions.entries()) - .sort(([, a], [, b]) => a.lastActivity.getTime() - b.lastActivity.getTime()) - .slice(0, this.sessions.size - this.MAX_SESSIONS) - .forEach(([projectId]) => this.deleteSession(projectId)); - } - } - /** * Start a new session (clear messages but keep configuration) */