(data = {})
| 4296 | } |
| 4297 | |
| 4298 | function renderChatHistory(data = {}) { |
| 4299 | const sessions = Array.isArray(data.sessions) ? data.sessions : state.chatHistory; |
| 4300 | let groups = Array.isArray(data.groups) ? data.groups : state.chatHistoryGroups; |
| 4301 | if ((!groups || !groups.length) && sessions.length) { |
| 4302 | const grouped = {}; |
| 4303 | sessions.forEach((session) => { |
| 4304 | const date = String(session.updated_at || session.created_at || todayDateValue()).slice(0, 10); |
| 4305 | if (!grouped[date]) grouped[date] = []; |
| 4306 | grouped[date].push(session); |
| 4307 | }); |
| 4308 | groups = Object.keys(grouped).map((date) => ({ date, sessions: grouped[date] })); |
| 4309 | } |
| 4310 | state.chatHistory = sessions; |
| 4311 | state.chatHistoryGroups = groups || []; |
| 4312 | |
| 4313 | const hint = $("chatHistoryHint"); |
| 4314 | if (hint) hint.textContent = sessions.length ? ui().chat.conversations(sessions.length) : ui().chat.historyHint; |
| 4315 | |
| 4316 | const target = $("chatHistoryList"); |
| 4317 | target.className = sessions.length ? "chat-history-list" : "chat-history-list empty"; |
| 4318 | if (!sessions.length) { |
| 4319 | target.innerHTML = ui().chat.historyEmptyDetail; |
| 4320 | return; |
| 4321 | } |
| 4322 | target.innerHTML = state.chatHistoryGroups.map((group) => ` |
| 4323 | <div class="chat-history-date"> |
| 4324 | <div class="chat-history-date-title">${escapeHtml(formatChatDateLabel(group.date))}</div> |
| 4325 | ${(group.sessions || []).map((session) => ` |
| 4326 | <button |
| 4327 | class="chat-session-button${session.session_id === state.chatSessionId ? " active" : ""}" |
| 4328 | type="button" |
| 4329 | data-chat-session-id="${escapeHtml(session.session_id)}" |
| 4330 | title="${escapeHtml(session.title || ui().chat.newChatTitle)}" |
| 4331 | > |
| 4332 | <strong>${escapeHtml(session.title || ui().chat.newChatTitle)}</strong> |
| 4333 | <span>${escapeHtml(formatChatTime(session.updated_at))}${session.message_count ? ` · ${escapeHtml(ui().chat.messageCount(session.message_count))}` : ""}</span> |
| 4334 | </button> |
| 4335 | `).join("")} |
| 4336 | </div> |
| 4337 | `).join(""); |
| 4338 | } |
| 4339 | |
| 4340 | function renderChatMessages(messages = []) { |
| 4341 | state.chatMessages = messages; |
no test coverage detected