|
40 | 40 | export let onTaskClick = (e) => {}; |
41 | 41 | export let onAddMessages = (e) => {}; |
42 | 42 |
|
43 | | - // Memoize sourceIds to avoid creating a new array reference on every render, |
44 | | - // which would cause the entire Markdown/MarkdownTokens tree to re-render |
45 | | - $: computedSourceIds = (sources ?? []).reduce((acc, source) => { |
46 | | - let ids = []; |
47 | | - source.document.forEach((document, index) => { |
48 | | - if (model?.info?.meta?.capabilities?.citations == false) { |
49 | | - ids.push('N/A'); |
50 | | - return ids; |
51 | | - } |
52 | | -
|
53 | | - const metadata = source.metadata?.[index]; |
54 | | - const id = metadata?.source ?? 'N/A'; |
55 | | -
|
56 | | - if (metadata?.name) { |
57 | | - ids.push(metadata.name); |
58 | | - return ids; |
59 | | - } |
60 | | -
|
61 | | - if (id.startsWith('http://') || id.startsWith('https://')) { |
62 | | - ids.push(id); |
63 | | - } else { |
64 | | - ids.push(source?.source?.name ?? id); |
65 | | - } |
66 | | -
|
67 | | - return ids; |
68 | | - }); |
69 | | -
|
70 | | - acc = [...acc, ...ids]; |
71 | | -
|
72 | | - // remove duplicates |
73 | | - return acc.filter((item, index) => acc.indexOf(item) === index); |
74 | | - }, []); |
75 | | -
|
76 | 43 | let contentContainerElement; |
77 | 44 | let floatingButtonsElement; |
78 | 45 |
|
|
176 | 143 | {done} |
177 | 144 | {editCodeBlock} |
178 | 145 | {topPadding} |
179 | | - sourceIds={computedSourceIds} |
| 146 | + sourceIds={(sources ?? []).reduce((acc, source) => { |
| 147 | + let ids = []; |
| 148 | + source.document.forEach((document, index) => { |
| 149 | + if (model?.info?.meta?.capabilities?.citations == false) { |
| 150 | + ids.push('N/A'); |
| 151 | + return ids; |
| 152 | + } |
| 153 | +
|
| 154 | + const metadata = source.metadata?.[index]; |
| 155 | + const id = metadata?.source ?? 'N/A'; |
| 156 | +
|
| 157 | + if (metadata?.name) { |
| 158 | + ids.push(metadata.name); |
| 159 | + return ids; |
| 160 | + } |
| 161 | +
|
| 162 | + if (id.startsWith('http://') || id.startsWith('https://')) { |
| 163 | + ids.push(id); |
| 164 | + } else { |
| 165 | + ids.push(source?.source?.name ?? id); |
| 166 | + } |
| 167 | +
|
| 168 | + return ids; |
| 169 | + }); |
| 170 | +
|
| 171 | + acc = [...acc, ...ids]; |
| 172 | +
|
| 173 | + // remove duplicates |
| 174 | + return acc.filter((item, index) => acc.indexOf(item) === index); |
| 175 | + }, [])} |
180 | 176 | {onSourceClick} |
181 | 177 | {onTaskClick} |
182 | 178 | {onSave} |
|
0 commit comments