(sessionId)
| 346 | |
| 347 | // ---- Session cache integration ---- |
| 348 | export async function restoreSessionCache(sessionId) { |
| 349 | debugLog('restore_session_cache_start', { sessionId }); |
| 350 | if (!serverCacheAddr || !sessionId) return false; |
| 351 | |
| 352 | let record; |
| 353 | try { |
| 354 | record = await chatCacheRead(buildCacheKey(serverCacheAddr, sessionId)); |
| 355 | } catch { |
| 356 | return false; |
| 357 | } |
| 358 | if (!record || !record.html) { |
| 359 | debugLog('restore_session_cache_miss', { sessionId }); |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | $msgs.innerHTML = record.html; |
| 364 | $msgs.querySelectorAll('[data-optimistic], .working-indicator').forEach(el => el.remove()); |
| 365 | S.seenUuids = new Set(Array.isArray(record.seenUuids) ? record.seenUuids : []); |
| 366 | S.lastSeq = Number.isInteger(record.lastSeq) ? record.lastSeq : 0; |
| 367 | S.cwd = record.cwd || S.cwd; |
| 368 | S.model = record.model || ''; |
| 369 | restoreTodoSnapshot({ |
| 370 | tasks: Array.isArray(record.todoTasks) ? record.todoTasks : [], |
| 371 | panelOpen: !!record.todoPanelOpen, |
| 372 | }); |
| 373 | rebuildRuntimeStateFromDom(); |
| 374 | removeWorkingIndicator(); |
| 375 | $input.disabled = false; |
| 376 | $('btn-send').disabled = false; |
| 377 | $('input-area').classList.remove('waiting'); |
| 378 | $input.placeholder = INPUT_PLACEHOLDER_DEFAULT; |
| 379 | updateHeaderInfo(); |
| 380 | updateSendBtn(); |
| 381 | updateScrollBtn(); |
| 382 | requestAnimationFrame(() => { $chat.scrollTop = $chat.scrollHeight; }); |
| 383 | debugLog('restore_session_cache_done', { |
| 384 | sessionId, |
| 385 | lastSeq: S.lastSeq, |
| 386 | waiting: S.waiting, |
| 387 | }); |
| 388 | return true; |
| 389 | } |
| 390 | |
| 391 | export async function flushSessionCacheSave() { |
| 392 | if (S.cacheSaveTimer) { |
no test coverage detected