(text, citations = [])
| 4208 | } |
| 4209 | |
| 4210 | function renderAnswerWithCitations(text, citations = []) { |
| 4211 | const refs = new Map(citations.map((citation) => [String(citation.index), citation])); |
| 4212 | const escaped = escapeHtml(text || ""); |
| 4213 | if (!escaped) return `<p>${escapeHtml(ui().chat.generating)}</p>`; |
| 4214 | const linked = escaped.replace(/\[(\d{1,3})\]/g, (match, index) => { |
| 4215 | if (!refs.has(String(index))) return match; |
| 4216 | const citation = refs.get(String(index)); |
| 4217 | return `<button type="button" class="citation-ref" data-citation-index="${index}" title="${escapeHtml(citation.title)}">[${index}]</button>`; |
| 4218 | }).replace(/\*\*([^*\n]+?)\*\*/g, "<strong>$1</strong>"); |
| 4219 | return linked |
| 4220 | .split(/\n{2,}/) |
| 4221 | .map((block) => `<p>${block.replace(/\n/g, "<br>")}</p>`) |
| 4222 | .join(""); |
| 4223 | } |
| 4224 | |
| 4225 | function routingLabel(reason) { |
| 4226 | return ui().chat.routing[reason] || reason || ""; |
no test coverage detected