(sourcePrefs = {})
| 5151 | renderChatSources(citations); |
| 5152 | } else { |
| 5153 | try { |
| 5154 | data = await streamWikiAsk(payload, answerTarget, message); |
| 5155 | } catch (streamError) { |
| 5156 | console.warn("Streaming Wiki ask failed, falling back to JSON.", streamError); |
| 5157 | showFeedbackToast("warning", ui().chat.streamInterruptedTitle, ui().chat.streamInterruptedDetail); |
| 5158 | data = await api("/api/wiki/ask", { method: "POST", timeoutMs: API_TIMEOUT_LONG_MS, body: JSON.stringify(payload) }); |
| 5159 | const citations = normalizeCitations(data); |
| 5160 | const currentMeta = message.querySelector(".answer-meta"); |
| 5161 | if (currentMeta) currentMeta.outerHTML = renderAnswerMeta(data, citations); |
| 5162 | await streamAnswerText(answerTarget, data.text || "", citations); |
| 5163 | renderChatSources(citations); |
| 5164 | } |
| 5165 | const citations = normalizeCitations(data); |
| 5166 | } |
| 5167 | if (data?.session_id) { |
| 5168 | state.chatSessionId = data.session_id; |
| 5169 | } |
| 5170 | try { |
| 5171 | await loadChatSessions(); |
| 5172 | } catch (historyError) { |
| 5173 | console.warn("Chat history refresh failed.", historyError); |
| 5174 | const detail = isUnknownApiRoute(historyError, "/api/chat/sessions") |
| 5175 | ? ui().chat.historyRestartDetail |
| 5176 | : ui().chat.historyReloadDetail; |
| 5177 | showFeedbackToast("warning", ui().chat.historyRefreshFailedTitle, detail); |
| 5178 | } |
| 5179 | $("chatThread").scrollTop = $("chatThread").scrollHeight; |
| 5180 | } catch (error) { |
| 5181 | answerTarget.classList.remove("loading"); |
| 5182 | answerTarget.innerHTML = `<p>${escapeHtml(ui().chat.generationFailed(error.message || String(error)))}</p>`; |
| 5183 | throw error; |
| 5184 | } finally { |
| 5185 | button.disabled = false; |
| 5186 | button.textContent = previousText; |
| 5187 | } |
| 5188 | } |
| 5189 | |
| 5190 | function envMap(data) { |
| 5191 | const entries = data.editable_env || data.env || {}; |
| 5192 | if (Array.isArray(entries)) { |
| 5193 | return Object.fromEntries(entries.filter((item) => item?.key).map((item) => [item.key, item])); |
| 5194 | } |
| 5195 | return Object.fromEntries(Object.entries(entries).map(([key, value]) => [ |
| 5196 | key, |
| 5197 | typeof value === "object" && value !== null ? value : { key, value, is_secret: false, present: true } |
| 5198 | ])); |
| 5199 | } |
| 5200 |
no test coverage detected