@@ -96,6 +96,8 @@
|
||||
let controlPane;
|
||||
let controlPaneComponent;
|
||||
|
||||
let messageInput;
|
||||
|
||||
let autoScroll = true;
|
||||
let processing = '';
|
||||
let messagesContainerElement: HTMLDivElement;
|
||||
@@ -140,24 +142,39 @@
|
||||
let params = {};
|
||||
|
||||
$: if (chatIdProp) {
|
||||
(async () => {
|
||||
loading = true;
|
||||
navigateHandler();
|
||||
}
|
||||
|
||||
prompt = '';
|
||||
files = [];
|
||||
selectedToolIds = [];
|
||||
selectedFilterIds = [];
|
||||
webSearchEnabled = false;
|
||||
imageGenerationEnabled = false;
|
||||
const navigateHandler = async () => {
|
||||
loading = true;
|
||||
|
||||
if (sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
|
||||
prompt = '';
|
||||
messageInput?.setText('');
|
||||
|
||||
files = [];
|
||||
selectedToolIds = [];
|
||||
selectedFilterIds = [];
|
||||
webSearchEnabled = false;
|
||||
imageGenerationEnabled = false;
|
||||
|
||||
const storageChatInput = sessionStorage.getItem(
|
||||
`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`
|
||||
);
|
||||
|
||||
if (chatIdProp && (await loadChat())) {
|
||||
await tick();
|
||||
loading = false;
|
||||
window.setTimeout(() => scrollToBottom(), 0);
|
||||
|
||||
await tick();
|
||||
|
||||
if (storageChatInput) {
|
||||
try {
|
||||
const input = JSON.parse(
|
||||
sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)
|
||||
);
|
||||
const input = JSON.parse(storageChatInput);
|
||||
|
||||
console.log(input);
|
||||
if (!$temporaryChatEnabled) {
|
||||
prompt = input.prompt;
|
||||
messageInput?.setText(input.prompt);
|
||||
files = input.files;
|
||||
selectedToolIds = input.selectedToolIds;
|
||||
selectedFilterIds = input.selectedFilterIds;
|
||||
@@ -168,17 +185,12 @@
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
if (chatIdProp && (await loadChat())) {
|
||||
await tick();
|
||||
loading = false;
|
||||
window.setTimeout(() => scrollToBottom(), 0);
|
||||
const chatInput = document.getElementById('chat-input');
|
||||
chatInput?.focus();
|
||||
} else {
|
||||
await goto('/');
|
||||
}
|
||||
})();
|
||||
}
|
||||
const chatInput = document.getElementById('chat-input');
|
||||
chatInput?.focus();
|
||||
} else {
|
||||
await goto('/');
|
||||
}
|
||||
};
|
||||
|
||||
$: if (selectedModels && chatIdProp !== '') {
|
||||
saveSessionSelectedModels();
|
||||
@@ -405,7 +417,7 @@
|
||||
const inputElement = document.getElementById('chat-input');
|
||||
|
||||
if (inputElement) {
|
||||
prompt = event.data.text;
|
||||
messageInput?.setText(event.data.text);
|
||||
inputElement.focus();
|
||||
}
|
||||
}
|
||||
@@ -443,8 +455,19 @@
|
||||
}
|
||||
});
|
||||
|
||||
if (sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)) {
|
||||
const storageChatInput = sessionStorage.getItem(
|
||||
`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`
|
||||
);
|
||||
|
||||
if (!chatIdProp) {
|
||||
loading = false;
|
||||
await tick();
|
||||
}
|
||||
|
||||
if (storageChatInput) {
|
||||
prompt = '';
|
||||
messageInput?.setText('');
|
||||
|
||||
files = [];
|
||||
selectedToolIds = [];
|
||||
selectedFilterIds = [];
|
||||
@@ -453,12 +476,11 @@
|
||||
codeInterpreterEnabled = false;
|
||||
|
||||
try {
|
||||
const input = JSON.parse(
|
||||
sessionStorage.getItem(`chat-input${chatIdProp ? `-${chatIdProp}` : ''}`)
|
||||
);
|
||||
const input = JSON.parse(storageChatInput);
|
||||
console.log(input);
|
||||
|
||||
if (!$temporaryChatEnabled) {
|
||||
prompt = input.prompt;
|
||||
messageInput?.setText(input.prompt);
|
||||
files = input.files;
|
||||
selectedToolIds = input.selectedToolIds;
|
||||
selectedFilterIds = input.selectedFilterIds;
|
||||
@@ -469,11 +491,6 @@
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
if (!chatIdProp) {
|
||||
loading = false;
|
||||
await tick();
|
||||
}
|
||||
|
||||
showControls.subscribe(async (value) => {
|
||||
if (controlPane && !$mobile) {
|
||||
try {
|
||||
@@ -833,12 +850,13 @@
|
||||
}
|
||||
|
||||
if ($page.url.searchParams.get('q')) {
|
||||
prompt = $page.url.searchParams.get('q') ?? '';
|
||||
const q = $page.url.searchParams.get('q') ?? '';
|
||||
messageInput?.setText(q);
|
||||
|
||||
if (prompt) {
|
||||
if (q) {
|
||||
if (($page.url.searchParams.get('submit') ?? 'true') === 'true') {
|
||||
await tick();
|
||||
submitPrompt(prompt);
|
||||
submitPrompt(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1071,7 +1089,7 @@
|
||||
};
|
||||
|
||||
const createMessagePair = async (userPrompt) => {
|
||||
prompt = '';
|
||||
messageInput?.setText('');
|
||||
if (selectedModels.length === 0) {
|
||||
toast.error($i18n.t('Model not selected'));
|
||||
} else {
|
||||
@@ -1392,7 +1410,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
prompt = '';
|
||||
messageInput?.setText('');
|
||||
|
||||
// Reset chat input textarea
|
||||
if (!($settings?.richTextInput ?? true)) {
|
||||
@@ -1413,7 +1431,7 @@
|
||||
);
|
||||
|
||||
files = [];
|
||||
prompt = '';
|
||||
messageInput?.setText('');
|
||||
|
||||
// Create user message
|
||||
let userMessageId = uuidv4();
|
||||
@@ -2104,6 +2122,7 @@
|
||||
|
||||
<div class=" pb-2">
|
||||
<MessageInput
|
||||
bind:this={messageInput}
|
||||
{history}
|
||||
{taskIds}
|
||||
{selectedModels}
|
||||
@@ -2166,6 +2185,7 @@
|
||||
<Placeholder
|
||||
{history}
|
||||
{selectedModels}
|
||||
bind:messageInput
|
||||
bind:files
|
||||
bind:prompt
|
||||
bind:autoScroll
|
||||
|
||||
Reference in New Issue
Block a user