()
| 397 | } |
| 398 | |
| 399 | async function persistSessionCache() { |
| 400 | if (!serverCacheAddr || !S.sessionId) return; |
| 401 | const todoSnapshot = getTodoSnapshot(); |
| 402 | const snapshotRoot = $msgs.cloneNode(true); |
| 403 | snapshotRoot.querySelectorAll('[data-optimistic], .working-indicator').forEach(el => el.remove()); |
| 404 | const record = { |
| 405 | cacheKey: buildCacheKey(serverCacheAddr, S.sessionId), |
| 406 | serverAddr, |
| 407 | sessionId: S.sessionId, |
| 408 | html: snapshotRoot.innerHTML, |
| 409 | seenUuids: Array.from(S.seenUuids), |
| 410 | todoTasks: todoSnapshot.tasks, |
| 411 | todoPanelOpen: todoSnapshot.panelOpen, |
| 412 | cwd: S.cwd, |
| 413 | model: S.model, |
| 414 | lastSeq: S.lastSeq, |
| 415 | updatedAt: Date.now(), |
| 416 | }; |
| 417 | record.sizeBytes = estimateCacheBytes(record); |
| 418 | |
| 419 | try { |
| 420 | if (record.sizeBytes > CHAT_CACHE_MAX_SESSION_BYTES) { |
| 421 | await chatCacheDelete(record.cacheKey).catch(() => {}); |
| 422 | return; |
| 423 | } |
| 424 | await chatCacheWrite(record); |
| 425 | await pruneChatCache(); |
| 426 | } catch (err) { |
| 427 | console.warn('[chat-cache]', err); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | export function scheduleSessionCacheSave() { |
| 432 | if (!serverCacheAddr || !S.sessionId) return; |
no test coverage detected