(options = {})
| 4393 | } |
| 4394 | |
| 4395 | async function loadChatSessions(options = {}) { |
| 4396 | let data; |
| 4397 | try { |
| 4398 | data = await api(`/api/chat/sessions?user_id=${encodeURIComponent(currentUser())}&days=90&limit=120`); |
| 4399 | } catch (error) { |
| 4400 | if (isUnknownApiRoute(error, "/api/chat/sessions")) { |
| 4401 | renderChatHistoryUnavailable(); |
| 4402 | return; |
| 4403 | } |
| 4404 | throw error; |
| 4405 | } |
| 4406 | state.chatHistoryLoaded = true; |
| 4407 | renderChatHistory(data); |
| 4408 | if (options.openLatest && !state.chatSessionId) { |
| 4409 | const latest = state.chatHistory[0]; |
| 4410 | if (latest?.session_id) { |
| 4411 | await loadChatSession(latest.session_id); |
| 4412 | } else { |
| 4413 | resetChatThread(); |
| 4414 | } |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | async function loadChatSession(sessionId) { |
| 4419 | const normalizedSessionId = String(sessionId || "").trim(); |
no test coverage detected