refac
This commit is contained in:
1 parent
4fd790f7dd
commit
7746e9f4b8
8 files changed
+94
-103
No files matched your search
@@ -53,7 +53,8 @@
|
|||||||
getPromptVariables,
|
getPromptVariables,
|
||||||
processDetails,
|
processDetails,
|
||||||
removeAllDetails,
|
removeAllDetails,
|
||||||
getCodeBlockContents
|
getCodeBlockContents,
|
||||||
|
isYoutubeUrl
|
||||||
} from '$lib/utils';
|
} from '$lib/utils';
|
||||||
import { AudioQueue } from '$lib/utils/audio';
|
import { AudioQueue } from '$lib/utils/audio';
|
||||||
|
|
||||||
@@ -773,69 +774,61 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadWeb = async (url) => {
|
const uploadWeb = async (urls) => {
|
||||||
console.log(url);
|
if (!Array.isArray(urls)) {
|
||||||
|
urls = [urls];
|
||||||
const fileItem = {
|
|
||||||
type: 'text',
|
|
||||||
name: url,
|
|
||||||
collection_name: '',
|
|
||||||
status: 'uploading',
|
|
||||||
url: url,
|
|
||||||
error: ''
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
files = [...files, fileItem];
|
|
||||||
const res = await processWeb(localStorage.token, '', url);
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
fileItem.status = 'uploaded';
|
|
||||||
fileItem.collection_name = res.collection_name;
|
|
||||||
fileItem.file = {
|
|
||||||
...res.file,
|
|
||||||
...fileItem.file
|
|
||||||
};
|
|
||||||
|
|
||||||
files = files;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// Remove the failed doc from the files array
|
|
||||||
files = files.filter((f) => f.name !== url);
|
|
||||||
toast.error(JSON.stringify(e));
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const uploadYoutubeTranscription = async (url) => {
|
// deduplicate URLs
|
||||||
console.log(url);
|
urls = [...new Set(urls)];
|
||||||
|
|
||||||
const fileItem = {
|
// Create file items first
|
||||||
|
const fileItems = urls.map((url) => ({
|
||||||
type: 'text',
|
type: 'text',
|
||||||
name: url,
|
name: url,
|
||||||
collection_name: '',
|
collection_name: '',
|
||||||
status: 'uploading',
|
status: 'uploading',
|
||||||
context: 'full',
|
context: 'full',
|
||||||
url: url,
|
url,
|
||||||
error: ''
|
error: ''
|
||||||
};
|
}));
|
||||||
|
|
||||||
try {
|
// Display all items at once
|
||||||
files = [...files, fileItem];
|
files = [...files, ...fileItems];
|
||||||
const res = await processYoutubeVideo(localStorage.token, url);
|
|
||||||
|
|
||||||
if (res) {
|
// Process sequentially (NOT parallel)
|
||||||
fileItem.status = 'uploaded';
|
for (const fileItem of fileItems) {
|
||||||
fileItem.collection_name = res.collection_name;
|
try {
|
||||||
fileItem.file = {
|
const res = isYoutubeUrl(fileItem.url)
|
||||||
...res.file,
|
? await processYoutubeVideo(localStorage.token, fileItem.url)
|
||||||
...fileItem.file
|
: await processWeb(localStorage.token, '', fileItem.url);
|
||||||
};
|
|
||||||
files = files;
|
if (res) {
|
||||||
|
fileItem.status = 'uploaded';
|
||||||
|
fileItem.collection_name = res.collection_name;
|
||||||
|
fileItem.file = {
|
||||||
|
...res.file,
|
||||||
|
...fileItem.file
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
fileItem.status = 'error';
|
||||||
|
fileItem.error = String(e);
|
||||||
|
toast.error(`${e}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
// Remove the failed doc from the files array
|
// Force UI reactivity after each file finishes
|
||||||
files = files.filter((f) => f.name !== url);
|
files = [...files];
|
||||||
toast.error(`${e}`);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onUpload = async (event) => {
|
||||||
|
const { type, data } = event;
|
||||||
|
|
||||||
|
if (type === 'google-drive') {
|
||||||
|
await uploadGoogleDriveFile(data);
|
||||||
|
} else if (type === 'web') {
|
||||||
|
await uploadWeb(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1010,9 +1003,7 @@
|
|||||||
params = {};
|
params = {};
|
||||||
|
|
||||||
if ($page.url.searchParams.get('youtube')) {
|
if ($page.url.searchParams.get('youtube')) {
|
||||||
uploadYoutubeTranscription(
|
await uploadWeb(`https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}`);
|
||||||
`https://www.youtube.com/watch?v=${$page.url.searchParams.get('youtube')}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($page.url.searchParams.get('load-url')) {
|
if ($page.url.searchParams.get('load-url')) {
|
||||||
@@ -2532,22 +2523,12 @@
|
|||||||
{generating}
|
{generating}
|
||||||
{stopResponse}
|
{stopResponse}
|
||||||
{createMessagePair}
|
{createMessagePair}
|
||||||
|
{onUpload}
|
||||||
onChange={(data) => {
|
onChange={(data) => {
|
||||||
if (!$temporaryChatEnabled) {
|
if (!$temporaryChatEnabled) {
|
||||||
saveDraft(data, $chatId);
|
saveDraft(data, $chatId);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:upload={async (e) => {
|
|
||||||
const { type, data } = e.detail;
|
|
||||||
|
|
||||||
if (type === 'web') {
|
|
||||||
await uploadWeb(data);
|
|
||||||
} else if (type === 'youtube') {
|
|
||||||
await uploadYoutubeTranscription(data);
|
|
||||||
} else if (type === 'google-drive') {
|
|
||||||
await uploadGoogleDriveFile(data);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:submit={async (e) => {
|
on:submit={async (e) => {
|
||||||
clearDraft();
|
clearDraft();
|
||||||
if (e.detail || files.length > 0) {
|
if (e.detail || files.length > 0) {
|
||||||
@@ -2584,20 +2565,12 @@
|
|||||||
{stopResponse}
|
{stopResponse}
|
||||||
{createMessagePair}
|
{createMessagePair}
|
||||||
{onSelect}
|
{onSelect}
|
||||||
|
{onUpload}
|
||||||
onChange={(data) => {
|
onChange={(data) => {
|
||||||
if (!$temporaryChatEnabled) {
|
if (!$temporaryChatEnabled) {
|
||||||
saveDraft(data);
|
saveDraft(data);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:upload={async (e) => {
|
|
||||||
const { type, data } = e.detail;
|
|
||||||
|
|
||||||
if (type === 'web') {
|
|
||||||
await uploadWeb(data);
|
|
||||||
} else if (type === 'youtube') {
|
|
||||||
await uploadYoutubeTranscription(data);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:submit={async (e) => {
|
on:submit={async (e) => {
|
||||||
clearDraft();
|
clearDraft();
|
||||||
if (e.detail || files.length > 0) {
|
if (e.detail || files.length > 0) {
|
||||||
|
|||||||
@@ -94,6 +94,7 @@
|
|||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
export let onChange: Function = () => {};
|
export let onChange: Function = () => {};
|
||||||
|
|
||||||
export let createMessagePair: Function;
|
export let createMessagePair: Function;
|
||||||
export let stopResponse: Function;
|
export let stopResponse: Function;
|
||||||
|
|
||||||
@@ -848,7 +849,7 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
dispatch('upload', e);
|
onUpload(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -883,7 +884,7 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
dispatch('upload', e);
|
onUpload(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -918,7 +919,7 @@
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
dispatch('upload', e);
|
onUpload(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1487,9 +1488,7 @@
|
|||||||
console.error('OneDrive Error:', error);
|
console.error('OneDrive Error:', error);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onUpload={async (e) => {
|
{onUpload}
|
||||||
dispatch('upload', e);
|
|
||||||
}}
|
|
||||||
onClose={async () => {
|
onClose={async () => {
|
||||||
await tick();
|
await tick();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import Modal from '$lib/components/common/Modal.svelte';
|
import Modal from '$lib/components/common/Modal.svelte';
|
||||||
import XMark from '$lib/components/icons/XMark.svelte';
|
import XMark from '$lib/components/icons/XMark.svelte';
|
||||||
import { isValidHttpUrl, isYoutubeUrl } from '$lib/utils';
|
import { isValidHttpUrl } from '$lib/utils';
|
||||||
|
|
||||||
export let show = false;
|
export let show = false;
|
||||||
export let onSubmit: (e) => void;
|
export let onSubmit: (e) => void;
|
||||||
@@ -15,17 +15,20 @@
|
|||||||
let url = '';
|
let url = '';
|
||||||
|
|
||||||
const submitHandler = () => {
|
const submitHandler = () => {
|
||||||
if (isValidHttpUrl(url)) {
|
const urls = url
|
||||||
onSubmit({
|
.split('\n')
|
||||||
type: isYoutubeUrl(url) ? 'youtube' : 'web',
|
.map((u) => u.trim())
|
||||||
data: url
|
.filter((u) => u !== '')
|
||||||
});
|
.filter((u) => isValidHttpUrl(u));
|
||||||
|
|
||||||
show = false;
|
if (urls.length === 0) {
|
||||||
url = '';
|
|
||||||
} else {
|
|
||||||
toast.error($i18n.t('Please enter a valid URL.'));
|
toast.error($i18n.t('Please enter a valid URL.'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSubmit({ type: 'web', data: urls });
|
||||||
|
show = false;
|
||||||
|
url = '';
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -57,15 +60,16 @@
|
|||||||
<label
|
<label
|
||||||
for="webpage-url"
|
for="webpage-url"
|
||||||
class={`text-xs ${($settings?.highContrastMode ?? false) ? 'text-gray-800 dark:text-gray-100' : 'text-gray-500'}`}
|
class={`text-xs ${($settings?.highContrastMode ?? false) ? 'text-gray-800 dark:text-gray-100' : 'text-gray-500'}`}
|
||||||
>{$i18n.t('Webpage URL')}</label
|
>{$i18n.t('Webpage URLs')}</label
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input
|
<textarea
|
||||||
id="webpage-url"
|
id="webpage-url"
|
||||||
class={`w-full flex-1 text-sm bg-transparent ${($settings?.highContrastMode ?? false) ? 'placeholder:text-gray-700 dark:placeholder:text-gray-100' : 'outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700'}`}
|
class={`w-full flex-1 text-sm bg-transparent ${($settings?.highContrastMode ?? false) ? 'placeholder:text-gray-700 dark:placeholder:text-gray-100' : 'outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700'}`}
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={url}
|
bind:value={url}
|
||||||
|
rows="3"
|
||||||
placeholder={'https://example.com'}
|
placeholder={'https://example.com'}
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
required
|
required
|
||||||
|
|||||||
@@ -110,13 +110,6 @@
|
|||||||
type: 'file',
|
type: 'file',
|
||||||
data: data
|
data: data
|
||||||
});
|
});
|
||||||
} else if (type === 'youtube') {
|
|
||||||
insertTextHandler('');
|
|
||||||
|
|
||||||
onUpload({
|
|
||||||
type: 'youtube',
|
|
||||||
data: data
|
|
||||||
});
|
|
||||||
} else if (type === 'web') {
|
} else if (type === 'web') {
|
||||||
insertTextHandler('');
|
insertTextHandler('');
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,7 @@
|
|||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (isValidHttpUrl(query)) {
|
if (isValidHttpUrl(query)) {
|
||||||
onSelect({
|
onSelect({
|
||||||
type: 'youtube',
|
type: 'web',
|
||||||
data: query
|
data: query
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
export let codeInterpreterEnabled = false;
|
export let codeInterpreterEnabled = false;
|
||||||
export let webSearchEnabled = false;
|
export let webSearchEnabled = false;
|
||||||
|
|
||||||
|
export let onUpload: Function = (e) => {};
|
||||||
export let onSelect = (e) => {};
|
export let onSelect = (e) => {};
|
||||||
export let onChange = (e) => {};
|
export let onChange = (e) => {};
|
||||||
|
|
||||||
@@ -216,9 +217,7 @@
|
|||||||
{createMessagePair}
|
{createMessagePair}
|
||||||
placeholder={$i18n.t('How can I help you today?')}
|
placeholder={$i18n.t('How can I help you today?')}
|
||||||
{onChange}
|
{onChange}
|
||||||
on:upload={(e) => {
|
{onUpload}
|
||||||
dispatch('upload', e.detail);
|
|
||||||
}}
|
|
||||||
on:submit={(e) => {
|
on:submit={(e) => {
|
||||||
dispatch('submit', e.detail);
|
dispatch('submit', e.detail);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -51,13 +51,16 @@
|
|||||||
import FilesOverlay from '$lib/components/chat/MessageInput/FilesOverlay.svelte';
|
import FilesOverlay from '$lib/components/chat/MessageInput/FilesOverlay.svelte';
|
||||||
import DropdownOptions from '$lib/components/common/DropdownOptions.svelte';
|
import DropdownOptions from '$lib/components/common/DropdownOptions.svelte';
|
||||||
import Pagination from '$lib/components/common/Pagination.svelte';
|
import Pagination from '$lib/components/common/Pagination.svelte';
|
||||||
|
import AttachWebpageModal from '$lib/components/chat/MessageInput/AttachWebpageModal.svelte';
|
||||||
|
|
||||||
let largeScreen = true;
|
let largeScreen = true;
|
||||||
|
|
||||||
let pane;
|
let pane;
|
||||||
let showSidepanel = true;
|
let showSidepanel = true;
|
||||||
|
|
||||||
|
let showAddWebpageModal = false;
|
||||||
let showAddTextContentModal = false;
|
let showAddTextContentModal = false;
|
||||||
|
|
||||||
let showSyncConfirmModal = false;
|
let showSyncConfirmModal = false;
|
||||||
let showAccessControlModal = false;
|
let showAccessControlModal = false;
|
||||||
|
|
||||||
@@ -696,6 +699,13 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<AttachWebpageModal
|
||||||
|
bind:show={showAddWebpageModal}
|
||||||
|
onSubmit={async (data) => {
|
||||||
|
console.log(data);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<AddTextContentModal
|
<AddTextContentModal
|
||||||
bind:show={showAddTextContentModal}
|
bind:show={showAddTextContentModal}
|
||||||
on:submit={(e) => {
|
on:submit={(e) => {
|
||||||
@@ -829,6 +839,8 @@
|
|||||||
onUpload={(data) => {
|
onUpload={(data) => {
|
||||||
if (data.type === 'directory') {
|
if (data.type === 'directory') {
|
||||||
uploadDirectoryHandler();
|
uploadDirectoryHandler();
|
||||||
|
} else if (data.type === 'web') {
|
||||||
|
showAddWebpageModal = true;
|
||||||
} else if (data.type === 'text') {
|
} else if (data.type === 'text') {
|
||||||
showAddTextContentModal = true;
|
showAddTextContentModal = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import BarsArrowUp from '$lib/components/icons/BarsArrowUp.svelte';
|
import BarsArrowUp from '$lib/components/icons/BarsArrowUp.svelte';
|
||||||
import FolderOpen from '$lib/components/icons/FolderOpen.svelte';
|
import FolderOpen from '$lib/components/icons/FolderOpen.svelte';
|
||||||
import ArrowPath from '$lib/components/icons/ArrowPath.svelte';
|
import ArrowPath from '$lib/components/icons/ArrowPath.svelte';
|
||||||
|
import GlobeAlt from '$lib/components/icons/GlobeAlt.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
@@ -96,6 +97,16 @@
|
|||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
|
||||||
|
on:click={() => {
|
||||||
|
onUpload({ type: 'web' });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<GlobeAlt strokeWidth="2" />
|
||||||
|
<div class="flex items-center">{$i18n.t('Add webpage')}</div>
|
||||||
|
</DropdownMenu.Item>
|
||||||
|
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
|
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
|
|||||||
Reference in new issue
Block a user