+
+ {#if suggestions}
+ {#key $settings?.richTextInput ?? true}
+ {#key $settings?.showFormattingToolbar ?? false}
+ {
+ prompt = e.md;
+ command = getCommand();
}}
- on:click={() => {
- console.log(file);
+ json={true}
+ richText={$settings?.richTextInput ?? true}
+ messageInput={true}
+ showFormattingToolbar={$settings?.showFormattingToolbar ?? false}
+ floatingMenuPlacement={'top-start'}
+ insertPromptAsRichText={$settings?.insertPromptAsRichText ?? false}
+ shiftEnter={!($settings?.ctrlEnterToSend ?? false) &&
+ !$mobile &&
+ !(
+ 'ontouchstart' in window ||
+ navigator.maxTouchPoints > 0 ||
+ navigator.msMaxTouchPoints > 0
+ )}
+ placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
+ largeTextAsFile={($settings?.largeTextAsFile ?? false) && !shiftKey}
+ autocomplete={$config?.features?.enable_autocomplete_generation &&
+ ($settings?.promptAutocomplete ?? false)}
+ generateAutoCompletion={async (text) => {
+ if (selectedModelIds.length === 0 || !selectedModelIds.at(0)) {
+ toast.error($i18n.t('Please select a model first.'));
+ }
+
+ const res = await generateAutoCompletion(
+ localStorage.token,
+ selectedModelIds.at(0),
+ text,
+ history?.currentId
+ ? createMessagesList(history, history.currentId)
+ : null
+ ).catch((error) => {
+ console.log(error);
+
+ return null;
+ });
+
+ console.log(res);
+ return res;
}}
- />
- {/if}
- {/each}
-
- {/if}
+ {suggestions}
+ oncompositionstart={() => (isComposing = true)}
+ oncompositionend={(e) => {
+ compositionEndedAt = e.timeStamp;
+ isComposing = false;
+ }}
+ on:keydown={async (e) => {
+ e = e.detail.event;
-
-
- {#if suggestions}
- {#key $settings?.richTextInput ?? true}
- {#key $settings?.showFormattingToolbar ?? false}
- {
- prompt = e.md;
- command = getCommand();
- }}
- json={true}
- richText={$settings?.richTextInput ?? true}
- messageInput={true}
- showFormattingToolbar={$settings?.showFormattingToolbar ?? false}
- floatingMenuPlacement={'top-start'}
- insertPromptAsRichText={$settings?.insertPromptAsRichText ?? false}
- shiftEnter={!($settings?.ctrlEnterToSend ?? false) &&
- !$mobile &&
- !(
- 'ontouchstart' in window ||
- navigator.maxTouchPoints > 0 ||
- navigator.msMaxTouchPoints > 0
- )}
- placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
- largeTextAsFile={($settings?.largeTextAsFile ?? false) && !shiftKey}
- autocomplete={$config?.features?.enable_autocomplete_generation &&
- ($settings?.promptAutocomplete ?? false)}
- generateAutoCompletion={async (text) => {
- if (selectedModelIds.length === 0 || !selectedModelIds.at(0)) {
- toast.error($i18n.t('Please select a model first.'));
- }
+ const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
+ const suggestionsContainerElement =
+ document.getElementById('suggestions-container');
- const res = await generateAutoCompletion(
- localStorage.token,
- selectedModelIds.at(0),
- text,
- history?.currentId
- ? createMessagesList(history, history.currentId)
- : null
- ).catch((error) => {
- console.log(error);
+ if (e.key === 'Escape') {
+ stopResponse();
+ }
- return null;
- });
+ if (prompt === '' && e.key == 'ArrowUp') {
+ e.preventDefault();
- console.log(res);
- return res;
- }}
- {suggestions}
- oncompositionstart={() => (isComposing = true)}
- oncompositionend={(e) => {
- compositionEndedAt = e.timeStamp;
- isComposing = false;
- }}
- on:keydown={async (e) => {
- e = e.detail.event;
+ const userMessageElement = [
+ ...document.getElementsByClassName('user-message')
+ ]?.at(-1);
- const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
- const suggestionsContainerElement =
- document.getElementById('suggestions-container');
-
- if (e.key === 'Escape') {
- stopResponse();
- }
-
- if (prompt === '' && e.key == 'ArrowUp') {
- e.preventDefault();
-
- const userMessageElement = [
- ...document.getElementsByClassName('user-message')
+ if (userMessageElement) {
+ userMessageElement.scrollIntoView({ block: 'center' });
+ const editButton = [
+ ...document.getElementsByClassName('edit-user-message-button')
]?.at(-1);
- if (userMessageElement) {
- userMessageElement.scrollIntoView({ block: 'center' });
- const editButton = [
- ...document.getElementsByClassName('edit-user-message-button')
- ]?.at(-1);
-
- editButton?.click();
- }
+ editButton?.click();
}
+ }
- if (!suggestionsContainerElement) {
- if (
- !$mobile ||
- !(
- 'ontouchstart' in window ||
- navigator.maxTouchPoints > 0 ||
- navigator.msMaxTouchPoints > 0
- )
- ) {
- if (inOrNearComposition(e)) {
- return;
- }
+ if (!suggestionsContainerElement) {
+ if (
+ !$mobile ||
+ !(
+ 'ontouchstart' in window ||
+ navigator.maxTouchPoints > 0 ||
+ navigator.msMaxTouchPoints > 0
+ )
+ ) {
+ if (inOrNearComposition(e)) {
+ return;
+ }
- // Uses keyCode '13' for Enter key for chinese/japanese keyboards.
- //
- // Depending on the user's settings, it will send the message
- // either when Enter is pressed or when Ctrl+Enter is pressed.
- const enterPressed =
- ($settings?.ctrlEnterToSend ?? false)
- ? (e.key === 'Enter' || e.keyCode === 13) && isCtrlPressed
- : (e.key === 'Enter' || e.keyCode === 13) && !e.shiftKey;
+ // Uses keyCode '13' for Enter key for chinese/japanese keyboards.
+ //
+ // Depending on the user's settings, it will send the message
+ // either when Enter is pressed or when Ctrl+Enter is pressed.
+ const enterPressed =
+ ($settings?.ctrlEnterToSend ?? false)
+ ? (e.key === 'Enter' || e.keyCode === 13) && isCtrlPressed
+ : (e.key === 'Enter' || e.keyCode === 13) && !e.shiftKey;
- if (enterPressed) {
- e.preventDefault();
- if (prompt !== '' || files.length > 0) {
- dispatch('submit', prompt);
- }
+ if (enterPressed) {
+ e.preventDefault();
+ if (prompt !== '' || files.length > 0) {
+ dispatch('submit', prompt);
}
}
}
+ }
- if (e.key === 'Escape') {
- console.log('Escape');
- atSelectedModel = undefined;
- selectedToolIds = [];
- selectedFilterIds = [];
+ if (e.key === 'Escape') {
+ console.log('Escape');
+ atSelectedModel = undefined;
+ selectedToolIds = [];
+ selectedFilterIds = [];
- webSearchEnabled = false;
- imageGenerationEnabled = false;
- codeInterpreterEnabled = false;
- }
- }}
- on:paste={async (e) => {
- e = e.detail.event;
- console.log(e);
+ webSearchEnabled = false;
+ imageGenerationEnabled = false;
+ codeInterpreterEnabled = false;
+ }
+ }}
+ on:paste={async (e) => {
+ e = e.detail.event;
+ console.log(e);
- const clipboardData = e.clipboardData || window.clipboardData;
+ const clipboardData = e.clipboardData || window.clipboardData;
- if (clipboardData && clipboardData.items) {
- for (const item of clipboardData.items) {
- if (item.type.indexOf('image') !== -1) {
- const blob = item.getAsFile();
- const reader = new FileReader();
+ if (clipboardData && clipboardData.items) {
+ for (const item of clipboardData.items) {
+ if (item.type.indexOf('image') !== -1) {
+ const blob = item.getAsFile();
+ const reader = new FileReader();
- reader.onload = function (e) {
- files = [
- ...files,
- {
- type: 'image',
- url: `${e.target.result}`
- }
- ];
- };
-
- reader.readAsDataURL(blob);
- } else if (item?.kind === 'file') {
- const file = item.getAsFile();
- if (file) {
- const _files = [file];
- await inputFilesHandler(_files);
- e.preventDefault();
- }
- } else if (item.type === 'text/plain') {
- if (($settings?.largeTextAsFile ?? false) && !shiftKey) {
- const text = clipboardData.getData('text/plain');
-
- if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
- e.preventDefault();
- const blob = new Blob([text], { type: 'text/plain' });
- const file = new File(
- [blob],
- `Pasted_Text_${Date.now()}.txt`,
- {
- type: 'text/plain'
- }
- );
-
- await uploadFileHandler(file, true);
+ reader.onload = function (e) {
+ files = [
+ ...files,
+ {
+ type: 'image',
+ url: `${e.target.result}`
}
+ ];
+ };
+
+ reader.readAsDataURL(blob);
+ } else if (item?.kind === 'file') {
+ const file = item.getAsFile();
+ if (file) {
+ const _files = [file];
+ await inputFilesHandler(_files);
+ e.preventDefault();
+ }
+ } else if (item.type === 'text/plain') {
+ if (($settings?.largeTextAsFile ?? false) && !shiftKey) {
+ const text = clipboardData.getData('text/plain');
+
+ if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
+ e.preventDefault();
+ const blob = new Blob([text], { type: 'text/plain' });
+ const file = new File(
+ [blob],
+ `Pasted_Text_${Date.now()}.txt`,
+ {
+ type: 'text/plain'
+ }
+ );
+
+ await uploadFileHandler(file, true);
}
}
}
}
- }}
- />
- {/key}
+ }
+ }}
+ />
{/key}
- {/if}
-
+ {/key}
+ {/if}
+
- {@html DOMPurify.sanitize(marked($config?.license_metadata?.input_footer))}
+
+ {#if (!history?.currentId || history.messages[history.currentId]?.done == true) && ($_user?.role === 'admin' || ($_user?.permissions?.chat?.stt ?? true))}
+
+
+
+
+ {/if}
+
+ {#if (taskIds && taskIds.length > 0) || (history.currentId && history.messages[history.currentId]?.done != true) || generating}
+
+
+
+
+
+ {:else if prompt === '' && files.length === 0 && ($_user?.role === 'admin' || ($_user?.permissions?.chat?.call ?? true))}
+
+
+
+
+
+
+ {:else}
+
+ {/if}
- {:else}
-
- {/if}
-
- {/if}
+