fix: message input issue

This commit is contained in:
Timothy J. Baek 2024-10-21 03:17:30 -07:00
parent d105be9ca2
commit f99facf383
4 changed files with 90 additions and 76 deletions

View File

@ -790,48 +790,55 @@
//////////////////////////
const submitPrompt = async (userPrompt, { _raw = false } = {}) => {
let _responses = [];
console.log('submitPrompt', $chatId);
const messages = createMessagesList(history.currentId);
console.log('submitPrompt', userPrompt, $chatId);
const messages = createMessagesList(history.currentId);
selectedModels = selectedModels.map((modelId) =>
$models.map((m) => m.id).includes(modelId) ? modelId : ''
);
if (userPrompt === '') {
toast.error($i18n.t('Please enter a prompt'));
return;
}
if (selectedModels.includes('')) {
toast.error($i18n.t('Model not selected'));
} else if (messages.length != 0 && messages.at(-1).done != true) {
return;
}
if (messages.length != 0 && messages.at(-1).done != true) {
// Response not done
console.log('wait');
} else if (messages.length != 0 && messages.at(-1).error) {
return;
}
if (messages.length != 0 && messages.at(-1).error) {
// Error in response
toast.error(
$i18n.t(
`Oops! There was an error in the previous response. Please try again or contact admin.`
)
);
} else if (
toast.error($i18n.t(`Oops! There was an error in the previous response.`));
return;
}
if (
files.length > 0 &&
files.filter((file) => file.type !== 'image' && file.status === 'uploading').length > 0
) {
// Upload not done
toast.error(
$i18n.t(
`Oops! Hold tight! Your files are still in the processing oven. We're cooking them up to perfection. Please be patient and we'll let you know once they're ready.`
)
$i18n.t(`Oops! There are files still uploading. Please wait for the upload to complete.`)
);
} else if (
return;
}
if (
($config?.file?.max_count ?? null) !== null &&
files.length + chatFiles.length > $config?.file?.max_count
) {
console.log(chatFiles.length, files.length);
toast.error(
$i18n.t(`You can only chat with a maximum of {{maxCount}} file(s) at a time.`, {
maxCount: $config?.file?.max_count
})
);
} else {
return;
}
let _responses = [];
prompt = '';
await tick();
// Reset chat input textarea
const chatInputContainer = document.getElementById('chat-input-container');
@ -882,7 +889,6 @@
chatInput?.focus();
_responses = await sendPrompt(userPrompt, userMessageId, { newChat: true });
}
return _responses;
};

View File

@ -517,6 +517,7 @@
<RichTextInput
bind:this={chatInputElement}
id="chat-input"
trim={true}
placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
bind:value={prompt}
shiftEnter={!$mobile ||

View File

@ -31,8 +31,10 @@
}
}}
>
<div class=" w-fit font-medium transition flex items-center justify-between gap-2">
<div>
<div
class=" w-fit font-medium flex items-center justify-between gap-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition"
>
<div class=" ">
{title}
</div>
@ -56,9 +58,7 @@
}
}}
>
<div
class="flex items-center gap-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition"
>
<div>
<slot />
</div>
</div>

View File

@ -30,6 +30,7 @@
export let id = '';
export let value = '';
export let placeholder = 'Type here...';
export let trim = false;
let element: HTMLElement; // Element where ProseMirror will attach
let state;
@ -128,8 +129,12 @@
// Utility function to convert ProseMirror content back to markdown text
function serializeEditorContent(doc) {
const markdown = customMarkdownSerializer.serialize(doc);
if (trim) {
return unescapeMarkdown(markdown).trim();
} else {
return unescapeMarkdown(markdown);
}
}
// ---- Input Rules ----
// Input rule for heading (e.g., # Headings)
@ -381,6 +386,8 @@
value = serializeEditorContent(newState.doc); // Convert ProseMirror content to markdown text
eventDispatch('input', { value });
console.log('Editor content:', value);
},
handleDOMEvents: {
focus: (view, event) => {