(sessionId)
| 4416 | } |
| 4417 | |
| 4418 | async function loadChatSession(sessionId) { |
| 4419 | const normalizedSessionId = String(sessionId || "").trim(); |
| 4420 | if (!normalizedSessionId) { |
| 4421 | startNewChat({ silent: true }); |
| 4422 | return; |
| 4423 | } |
| 4424 | const token = ++state.chatLoadToken; |
| 4425 | let data; |
| 4426 | try { |
| 4427 | data = await api(`/api/chat/session?user_id=${encodeURIComponent(currentUser())}&session_id=${encodeURIComponent(normalizedSessionId)}`); |
| 4428 | } catch (error) { |
| 4429 | if (isUnknownApiRoute(error, "/api/chat/session")) { |
| 4430 | renderChatHistoryUnavailable(); |
| 4431 | return; |
| 4432 | } |
| 4433 | throw error; |
| 4434 | } |
| 4435 | if (token !== state.chatLoadToken) return; |
| 4436 | if (!data.session) throw new Error(ui().chat.missingSession); |
| 4437 | state.chatSessionId = data.session.session_id || normalizedSessionId; |
| 4438 | renderChatMessages(data.messages || []); |
| 4439 | renderChatHistory({ sessions: state.chatHistory, groups: state.chatHistoryGroups }); |
| 4440 | } |
| 4441 | |
| 4442 | async function clearChatHistory() { |
| 4443 | const count = state.chatHistory.length; |
no test coverage detected