mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Remove redundant methods
This commit is contained in:
3 files changed
+2
-45
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -47,10 +47,6 @@ export class SessionManager {
|
||||
private aiSettings: { providers: Record<string, { baseURL: string; apiKey?: string }> };
|
||||
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<string, { baseURL: string; apiKey?: string }> },
|
||||
@@ -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<void> {
|
||||
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)
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user