refac
This commit is contained in:
@@ -1531,8 +1531,6 @@
|
||||
error: e.message || 'Unknown error'
|
||||
})
|
||||
);
|
||||
} finally {
|
||||
await processNextInQueue($chatId);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1583,6 +1581,22 @@
|
||||
toast.error(`${e}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onUpdate = async ({ file }: { file?: any } = {}) => {
|
||||
if (file?.itemId) {
|
||||
chatRequestQueues.update((q) => ({
|
||||
...q,
|
||||
[$chatId]: (q[$chatId] ?? []).map((message) =>
|
||||
(message.files ?? []).some((item) => item.itemId === file.itemId)
|
||||
? {
|
||||
...message,
|
||||
files: message.files.map((item) => (item.itemId === file.itemId ? file : item))
|
||||
}
|
||||
: message
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
await processNextInQueue($chatId);
|
||||
};
|
||||
@@ -1594,8 +1608,6 @@
|
||||
await uploadGoogleDriveFile(data);
|
||||
} else if (type === 'web') {
|
||||
await uploadWeb(data);
|
||||
} else if (type === 'file') {
|
||||
await processNextInQueue($chatId);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3339,6 +3351,15 @@
|
||||
// while the request was in flight (prevents overwriting $chatId
|
||||
// and causing spurious toast notifications / state duplication).
|
||||
if (res.chat_id && $chatId !== res.chat_id && $chatId === _chatId) {
|
||||
chatRequestQueues.update((q) => {
|
||||
if (!q[_chatId]?.length) return q;
|
||||
|
||||
const { [_chatId]: pendingQueue, ...rest } = q;
|
||||
return {
|
||||
...rest,
|
||||
[res.chat_id]: [...pendingQueue, ...(rest[res.chat_id] ?? [])]
|
||||
};
|
||||
});
|
||||
await chatId.set(res.chat_id);
|
||||
if (!$temporaryChatEnabled && !embedded) {
|
||||
window.history.replaceState(history.state, '', `/c/${res.chat_id}`);
|
||||
@@ -4089,6 +4110,7 @@
|
||||
{stopResponse}
|
||||
{createMessagePair}
|
||||
{onUpload}
|
||||
{onUpdate}
|
||||
messageQueue={$chatRequestQueues[$chatId] ?? []}
|
||||
{chatTasks}
|
||||
onQueueSendNow={sendQueuedMessageNow}
|
||||
@@ -4176,6 +4198,7 @@
|
||||
{stopResponse}
|
||||
{createMessagePair}
|
||||
{onUpload}
|
||||
{onUpdate}
|
||||
messageQueue={$chatRequestQueues[$chatId] ?? []}
|
||||
{chatTasks}
|
||||
onQueueSendNow={sendQueuedMessageNow}
|
||||
@@ -4219,6 +4242,7 @@
|
||||
{createMessagePair}
|
||||
{onSelect}
|
||||
{onUpload}
|
||||
{onUpdate}
|
||||
messageQueue={$chatRequestQueues[$chatId] ?? []}
|
||||
onQueueSendNow={sendQueuedMessageNow}
|
||||
onQueueEdit={editQueuedMessage}
|
||||
|
||||
@@ -168,6 +168,7 @@
|
||||
export let onQueueSendNow: (id: string) => void = () => {};
|
||||
export let onQueueEdit: (id: string) => void = () => {};
|
||||
export let onQueueDelete: (id: string) => void = () => {};
|
||||
export let onUpdate: (data?: { file?: any }) => void = () => {};
|
||||
|
||||
export let chatTasks = [];
|
||||
|
||||
@@ -890,7 +891,7 @@
|
||||
toast.error(`${e}`);
|
||||
files = files.filter((item) => item?.itemId !== tempItemId);
|
||||
} finally {
|
||||
onUpload({ type: 'file' });
|
||||
onUpdate({ file: fileItem });
|
||||
}
|
||||
} else {
|
||||
// If temporary chat is enabled, we just add the file to the list without uploading it.
|
||||
@@ -907,7 +908,7 @@
|
||||
fileItem.error = $i18n.t('Failed to extract content from the file.');
|
||||
toast.error($i18n.t('Failed to extract content from the file.'));
|
||||
files = files.filter((item) => item?.itemId !== tempItemId);
|
||||
onUpload({ type: 'file' });
|
||||
onUpdate({ file: fileItem });
|
||||
return null;
|
||||
} else {
|
||||
console.log('Extracted content from file:', {
|
||||
@@ -922,7 +923,7 @@
|
||||
fileItem.id = uuidv4(); // Temporary ID for the file
|
||||
|
||||
files = files;
|
||||
onUpload({ type: 'file' });
|
||||
onUpdate({ file: fileItem });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
export let webSearchEnabled = false;
|
||||
|
||||
export let onUpload: Function = (e) => {};
|
||||
export let onUpdate: (data?: { file?: any }) => void = () => {};
|
||||
export let onSelect = (e) => {};
|
||||
export let onChange = (e) => {};
|
||||
export let onWebSearchToggle: Function = () => {};
|
||||
@@ -243,6 +244,7 @@
|
||||
placeholder={$i18n.t('How can I help you today?')}
|
||||
{onChange}
|
||||
{onUpload}
|
||||
{onUpdate}
|
||||
{messageQueue}
|
||||
{onQueueSendNow}
|
||||
{onQueueEdit}
|
||||
|
||||
Reference in New Issue
Block a user