()
| 4596 | anchor: source?.anchor || "", |
| 4597 | url: source?.url || metadata.url || metadata.abs_url || metadata.pdf_url || "", |
| 4598 | metadata |
| 4599 | }; |
| 4600 | } |
| 4601 | |
| 4602 | function normalizeCitations(data) { |
| 4603 | const raw = Array.isArray(data?.citations) && data.citations.length ? data.citations : data?.sources; |
| 4604 | const items = Array.isArray(raw) ? raw : DEMO_MODE ? demoSources : []; |
| 4605 | return items.map((source, index) => normalizeCitationSource(source, index)); |
| 4606 | } |
| 4607 | |
| 4608 | function renderAnswerWithCitations(text, citations = []) { |
| 4609 | const refs = new Map(citations.map((citation) => [String(citation.index), citation])); |
| 4610 | const escaped = escapeHtml(text || ""); |
| 4611 | if (!escaped) return `<p>${escapeHtml(ui().chat.generating)}</p>`; |
| 4612 | const linked = escaped.replace(/\[(\d{1,3})\]/g, (match, index) => { |
no test coverage detected