diff --git a/extensions/qqbot/src/engine/session/session-store.ts b/extensions/qqbot/src/engine/session/session-store.ts index 7d374cec79f..d4cb4e48345 100644 --- a/extensions/qqbot/src/engine/session/session-store.ts +++ b/extensions/qqbot/src/engine/session/session-store.ts @@ -62,16 +62,6 @@ function getCandidateSessionPaths(accountId: string): string[] { return primaryPath === legacyPath ? [primaryPath] : [primaryPath, legacyPath]; } -function isSessionFileName(file: string): boolean { - return file.startsWith("session-") && file.endsWith(".json"); -} - -function readSessionStateFile(file: string): { filePath: string; state: SessionState } { - const filePath = path.join(getSessionDir(), file); - const data = fs.readFileSync(filePath, "utf-8"); - return { filePath, state: JSON.parse(data) as SessionState }; -} - /** Load a saved session, rejecting expired or mismatched appId entries. */ export function loadSession(accountId: string, expectedAppId?: string): SessionState | null { try { @@ -212,65 +202,3 @@ export function clearSession(accountId: string): void { ); } } - -/** Load all saved sessions from disk. */ -export function getAllSessions(): SessionState[] { - const sessions = new Map(); - try { - const sessionDir = getSessionDir(); - if (!fs.existsSync(sessionDir)) { - return []; - } - const files = fs.readdirSync(sessionDir); - - for (const file of files) { - if (isSessionFileName(file)) { - try { - const { state } = readSessionStateFile(file); - if (typeof state.accountId !== "string" || !state.accountId) { - continue; - } - const existing = sessions.get(state.accountId); - if (!existing || (state.savedAt ?? 0) >= (existing.savedAt ?? 0)) { - sessions.set(state.accountId, state); - } - } catch {} - } - } - } catch {} - return [...sessions.values()]; -} - -/** Remove expired session files from disk. */ -export function cleanupExpiredSessions(): number { - let cleaned = 0; - try { - const sessionDir = getSessionDir(); - if (!fs.existsSync(sessionDir)) { - return 0; - } - const now = Date.now(); - const files = fs.readdirSync(sessionDir); - - for (const file of files) { - if (isSessionFileName(file)) { - const filePath = path.join(sessionDir, file); - try { - const { state } = readSessionStateFile(file); - - if (now - state.savedAt > SESSION_EXPIRE_TIME) { - fs.unlinkSync(filePath); - cleaned++; - debugLog(`[session-store] Cleaned expired session: ${file}`); - } - } catch { - try { - fs.unlinkSync(filePath); - cleaned++; - } catch {} - } - } - } - } catch {} - return cleaned; -} diff --git a/extensions/qqbot/src/engine/utils/platform-storage-laziness.test.ts b/extensions/qqbot/src/engine/utils/platform-storage-laziness.test.ts index 9c15c0bcc09..3969a830561 100644 --- a/extensions/qqbot/src/engine/utils/platform-storage-laziness.test.ts +++ b/extensions/qqbot/src/engine/utils/platform-storage-laziness.test.ts @@ -38,14 +38,12 @@ describe("qqbot storage laziness", () => { const qqbotRoot = path.join(homeDir, ".openclaw", "qqbot"); - const sessionStore = await import("../session/session-store.js"); + await import("../session/session-store.js"); await import("../session/known-users.js"); await import("../ref/store.js"); const { loadCredentialBackup } = await import("../config/credential-backup.js"); expect(loadCredentialBackup("default")).toBeNull(); - expect(sessionStore.getAllSessions()).toEqual([]); - expect(sessionStore.cleanupExpiredSessions()).toBe(0); expect(fs.existsSync(qqbotRoot)).toBe(false); });