refac
This commit is contained in:
@@ -42,6 +42,31 @@
|
|||||||
let contentContainerElement;
|
let contentContainerElement;
|
||||||
let floatingButtonsElement;
|
let floatingButtonsElement;
|
||||||
|
|
||||||
|
let sourceIds = [];
|
||||||
|
$: getSourceIds(sources);
|
||||||
|
|
||||||
|
const getSourceIds = (sources) => {
|
||||||
|
const result = [];
|
||||||
|
for (const source of sources ?? []) {
|
||||||
|
for (let index = 0; index < (source.document ?? []).length; index++) {
|
||||||
|
if (model?.info?.meta?.capabilities?.citations == false) {
|
||||||
|
result.push('N/A');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const metadata = source.metadata?.[index];
|
||||||
|
const id = metadata?.source ?? 'N/A';
|
||||||
|
if (metadata?.name) {
|
||||||
|
result.push(metadata.name);
|
||||||
|
} else if (id.startsWith('http://') || id.startsWith('https://')) {
|
||||||
|
result.push(id);
|
||||||
|
} else {
|
||||||
|
result.push(source?.source?.name ?? id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sourceIds = [...new Set(result)];
|
||||||
|
};
|
||||||
|
|
||||||
const updateButtonPosition = (event) => {
|
const updateButtonPosition = (event) => {
|
||||||
const buttonsContainerElement = document.getElementById(`floating-buttons-${id}`);
|
const buttonsContainerElement = document.getElementById(`floating-buttons-${id}`);
|
||||||
if (
|
if (
|
||||||
@@ -142,12 +167,54 @@
|
|||||||
{done}
|
{done}
|
||||||
{editCodeBlock}
|
{editCodeBlock}
|
||||||
{topPadding}
|
{topPadding}
|
||||||
sourceIds={(sources ?? []).reduce((acc, source) => {
|
{sourceIds}
|
||||||
let ids = [];
|
{onSourceClick}
|
||||||
source.document.forEach((document, index) => {
|
{onTaskClick}
|
||||||
if (model?.info?.meta?.capabilities?.citations == false) {
|
{onSave}
|
||||||
ids.push('N/A');
|
onUpdate={async (token) => {
|
||||||
return ids;
|
const { lang, text: code } = token;
|
||||||
|
|
||||||
|
if (
|
||||||
|
($settings?.detectArtifacts ?? true) &&
|
||||||
|
(['html', 'svg'].includes(lang) || (lang === 'xml' && code.includes('svg'))) &&
|
||||||
|
!$mobile &&
|
||||||
|
$chatId
|
||||||
|
) {
|
||||||
|
await tick();
|
||||||
|
showArtifacts.set(true);
|
||||||
|
showControls.set(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onPreview={async (value) => {
|
||||||
|
console.log('Preview', value);
|
||||||
|
await artifactCode.set(value);
|
||||||
|
await showControls.set(true);
|
||||||
|
await showArtifacts.set(true);
|
||||||
|
await showEmbeds.set(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if floatingButtons && model}
|
||||||
|
<FloatingButtons
|
||||||
|
bind:this={floatingButtonsElement}
|
||||||
|
{id}
|
||||||
|
{messageId}
|
||||||
|
actions={$settings?.floatingActionButtons ?? []}
|
||||||
|
model={(selectedModels ?? []).includes(model?.id)
|
||||||
|
? model?.id
|
||||||
|
: (selectedModels ?? []).length > 0
|
||||||
|
? selectedModels.at(0)
|
||||||
|
: model?.id}
|
||||||
|
messages={createMessagesList(history, messageId)}
|
||||||
|
onAdd={({ modelId, parentId, messages }) => {
|
||||||
|
console.log(modelId, parentId, messages);
|
||||||
|
onAddMessages({ modelId, parentId, messages });
|
||||||
|
closeFloatingButtons();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const metadata = source.metadata?.[index];
|
const metadata = source.metadata?.[index];
|
||||||
|
|||||||
Reference in New Issue
Block a user