{#if showComparison && ComparisonModal} {/if} oauthRedirectHandler({ id, serverId: id.split(':').at(-1), authType: 'mcp' }, chatInputDraft)} /> { await tick(); }} on:close={() => { inputMenuCloseOnOutsideClick = true; }} /> { console.log(content); chatInputElement?.setContent(content?.json ?? null); }} onClose={async () => { await tick(); focus(); }} /> {#if loaded} {#if typingUsers.length > 0} {typingUsers.map((user) => user.name).join(', ')} {typingUsers.length === 1 ? $i18n.t('is typing...') : $i18n.t('are typing...')} {/if} {#if autoScroll === false && history?.currentId} { autoScroll = true; scrollToBottom(); }} > {/if} { if (inputFiles && inputFiles.length > 0) { const _inputFiles = Array.from(inputFiles); inputFilesHandler(_inputFiles); } else { toast.error($i18n.t(`File not found.`)); } filesInputElement.value = ''; }} /> { recording = false; await tick(); focus({ preventScroll: true }); }} onConfirm={async (data) => { const { text, filename } = data; recording = false; await tick(); await insertTextAtCursor(`${text}`); await tick(); focus({ preventScroll: true }); if ($settings?.speechAutoSend ?? false) { dispatch('submit', prompt); } }} /> { dispatch('submit', prompt); }} > createMessagePair(prompt)} /> {#if askUser?.show} {#key askUser.id} {@const activeAskUser = askUser} { activeAskUser.onConfirm(e.detail); }} on:cancel={() => { activeAskUser.onCancel(); }} /> {/key} {/if} {#if isActive && chatTasks.length > 0} {/if} {#if messageQueue.length > 0} {#each messageQueue as queuedMessage (queuedMessage.id)} {/each} {/if} {#if showStatusPanel} {$i18n.t('Status')} { showStatusPanel = false; }} > {$i18n.t('Close')} {$i18n.t('Context usage')} {contextValue} {#if contextHasThreshold} {/if} {#if messageQueue.length} {$i18n.t('Queued messages')} {messageQueue.length} {/if} {#if chatTasks.length} {$i18n.t('Tasks')} {chatTasks.length} {/if} {$i18n.t('Chat ID')} {#if chatId} {copiedStatusChatId ? $i18n.t('Copied') : chatId} {:else} none {/if} {/if} {#if atSelectedModel !== undefined} model.id === atSelectedModel.id).id}&lang=${$i18n.language}`} /> {atSelectedModelName} { atSelectedModel = undefined; }} > {/if} {#if files.length > 0} {#each files as file, fileIdx} {#if file.type === 'image' || isRasterImageContentType(file?.content_type)} {@const fileUrl = file.url.startsWith('data') || file.url.startsWith('http') ? file.url : `${WEBUI_API_BASE_URL}/files/${file.url}${file?.content_type ? '/content' : ''}`} {#if selectedModelIds.length !== visionCapableModels.length} !visionCapableModels.includes(id)) .join(', ') })} > {/if} { files.splice(fileIdx, 1); files = files; }} > {:else} { // Remove from UI state files.splice(fileIdx, 1); files = files; }} on:click={() => { console.log(file); }} /> {/if} {/each} {/if} {#if prompt.split('\n').length > 2} { showInputModal = true; }} > {/if} {#if suggestions} {#key $settings?.richTextInput ?? true} {#key $settings?.showFormattingToolbar ?? false} { prompt = content.md; inputContent = content; command = getCommand(); }} json={true} richText={$settings?.richTextInput ?? true} messageInput={true} followUpSuggestion={!generating && history?.messages?.[history?.currentId]?.role === 'assistant' && history?.messages?.[history?.currentId]?.done ? (history.messages[history.currentId].followUps?.[0] ?? '') : ''} 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)) { return null; } const res = await generateAutoCompletion( localStorage.token, selectedModelIds.at(0), text, history?.currentId ? createMessagesList(history, history.currentId) : null, 'general' ).catch((error) => { console.log(error); return null; }); 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 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 .getElementById(messagesContainerId) ?.getElementsByClassName('user-message') ?? []) ]?.at(-1); if (userMessageElement) { userMessageElement.scrollIntoView({ block: 'center' }); const editButton = [ ...userMessageElement.getElementsByClassName( 'edit-user-message-button' ) ]?.at(-1); editButton?.click(); } } 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.shiftKey : (e.key === 'Enter' || e.keyCode === 13) && !e.shiftKey; if (enterPressed) { e.preventDefault(); if (prompt !== '' || files.length > 0) { dispatch('submit', prompt); } } } } if ( $settings?.keyboardShortcuts !== false && matchKeybinding(e) === Shortcut.CLEAR_INPUT_SELECTIONS ) { console.log('Escape'); atSelectedModel = undefined; selectedToolIds = []; selectedFilterIds = []; webSearchEnabled = false; imageGenerationEnabled = false; codeInterpreterEnabled = false; } }} on:paste={async (e) => { e = e.detail.event; console.log(e); const clipboardData = e.clipboardData || window.clipboardData; if (clipboardData && clipboardData.items) { for (const item of clipboardData.items) { 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, { context: 'full' }); } } } else { const file = item.getAsFile(); if (file) { await inputFilesHandler([file]); e.preventDefault(); } } } } }} /> {/key} {/key} {/if} { filesInputElement.click(); }} uploadGoogleDriveHandler={async () => { try { const fileData = await createPicker(); if (fileData) { const file = new File([fileData.blob], fileData.name, { type: fileData.blob.type }); await uploadFileHandler(file); } else { console.log('No file was selected from Google Drive'); } } catch (error) { console.error('Google Drive Error:', error); toast.error( $i18n.t('Error accessing Google Drive: {{error}}', { error: error.message }) ); } }} uploadOneDriveHandler={async (authorityType) => { try { const fileData = await pickAndDownloadFile(authorityType); if (fileData) { const file = new File([fileData.blob], fileData.name, { type: fileData.blob.type || 'application/octet-stream' }); await uploadFileHandler(file); } else { console.log('No file was selected from OneDrive'); } } catch (error) { console.error('OneDrive Error:', error); } }} {onUpload} onClose={async () => { await tick(); if (!$mobile) { const chatInput = document.getElementById(inputId); chatInput?.focus(); } }} > {#if showTerminalSelector && terminalControlsInMenu} {#if inputMenuTab === ''} {/if} {/if} {#if showWebSearchButton || showImageGenerationButton || showCodeInterpreterButton || showToolsButton || showSkillsButton || (toggleFilters && toggleFilters.length > 0)} oauthRedirectHandler(tool, chatInputDraft)} {onWebSearchToggle} onShowValves={(e) => { const { type, id } = e; selectedValvesType = type; selectedValvesItemId = id; showValvesModal = true; inputMenuCloseOnOutsideClick = false; }} /> {/if} {#if hasChatVariables} { dispatch('chatVariables'); }} > {/if} {#if selectedModelIds.length === 1 && $models.find((m) => m.id === selectedModelIds[0])?.has_user_valves && ($_user?.role === 'admin' || ($_user?.permissions?.chat?.valves ?? true))} { selectedValvesType = 'function'; selectedValvesItemId = selectedModelIds[0]?.split('.')[0]; showValvesModal = true; }} > {/if} {#if showInputSelections && (selectedToolIds ?? []).length > 0 && $visibleControls['chat.selected_tools']} { showTools = !showTools; }} > {(selectedToolIds ?? []).length} {/if} {#if showInputSelections && (selectedSkillIds ?? []).length > 0 && $visibleControls['chat.selected_skills']} { showSkills = !showSkills; }} > {(selectedSkillIds ?? []).length} {/if} {#each selectedFilterIds as filterId (filterId)} {@const filter = toggleFilters.find((f) => f.id === filterId)} {#if showInputSelections && filter && $visibleControls['chat.selected_filters']} { if ( filter?.has_user_valves && ($_user?.role === 'admin' || ($_user?.permissions?.chat?.valves ?? true)) ) { selectedValvesType = 'function'; selectedValvesItemId = filterId; showValvesModal = true; } else { selectedFilterIds = selectedFilterIds.filter( (id) => id !== filterId ); } }} type="button" class="group p-[0.375rem] flex gap-1.5 items-center text-sm rounded-full transition-colors duration-300 focus:outline-hidden max-w-full overflow-hidden {selectedFilterIds.includes( filterId ) ? 'text-sky-500 dark:text-sky-300 bg-sky-50 hover:bg-sky-100 dark:bg-sky-400/10 dark:hover:bg-sky-600/10 border border-sky-200/40 dark:border-sky-500/20' : 'bg-transparent text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 '} capitalize" > {#if filter?.icon} {:else} {/if} { e.stopPropagation(); e.preventDefault(); selectedFilterIds = selectedFilterIds.filter( (id) => id !== filterId ); }} > {/if} {/each} {#if showInputSelections && webSearchEnabled && showWebSearchButton && $visibleControls['chat.selected_web_search']} (webSearchEnabled = !webSearchEnabled)} type="button" class="group p-[0.375rem] flex gap-1.5 items-center text-sm rounded-full transition-colors duration-300 focus:outline-hidden max-w-full overflow-hidden {webSearchEnabled || ($settings?.webSearch ?? false) === 'always' ? ' text-sky-500 dark:text-sky-300 bg-sky-50 hover:bg-sky-100 dark:bg-sky-400/10 dark:hover:bg-sky-600/10 border border-sky-200/40 dark:border-sky-500/20' : 'bg-transparent text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 '}" > {/if} {#if showInputSelections && imageGenerationEnabled && showImageGenerationButton && $visibleControls['chat.selected_image_generation']} (imageGenerationEnabled = !imageGenerationEnabled)} type="button" class="group p-[0.375rem] flex gap-1.5 items-center text-sm rounded-full transition-colors duration-300 focus:outline-hidden max-w-full overflow-hidden {imageGenerationEnabled ? ' text-sky-500 dark:text-sky-300 bg-sky-50 hover:bg-sky-100 dark:bg-sky-400/10 dark:hover:bg-sky-700/10 border border-sky-200/40 dark:border-sky-500/20' : 'bg-transparent text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 '}" > {/if} {#if showInputSelections && codeInterpreterEnabled && showCodeInterpreterButton && $visibleControls['chat.selected_code_interpreter']} (codeInterpreterEnabled = !codeInterpreterEnabled)} type="button" class=" group p-[0.375rem] flex gap-1.5 items-center text-sm transition-colors duration-300 max-w-full overflow-hidden {codeInterpreterEnabled ? ' text-sky-500 dark:text-sky-300 bg-sky-50 hover:bg-sky-100 dark:bg-sky-400/10 dark:hover:bg-sky-700/10 border border-sky-200/40 dark:border-sky-500/20' : 'bg-transparent text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 '} {($settings?.highContrastMode ?? false) ? 'm-1' : 'focus:outline-hidden rounded-full'}" > {/if} {#if showTerminalSelector} {/if} {#each pendingOAuthTools as pendingTool (pendingTool.id)} { oauthRedirectHandler(pendingTool, chatInputDraft); }} type="button" class="flex h-[1.875rem] min-w-0 max-w-full translate-y-[0.0625rem] items-center self-center gap-1 bg-transparent px-1 text-[0.8125rem] leading-none text-gray-600 transition-colors duration-150 hover:text-gray-900 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-400 dark:text-gray-300 dark:hover:text-gray-100 dark:focus-visible:outline-gray-500" > {pendingTool.name} {/each} {#if isActive && (history.messages[history.currentId]?.user_id ?? $_user?.id) === $_user?.id && prompt === '' && files.length === 0} { stopResponse(); }} > {:else} {#if !history?.currentId || history.messages[history.currentId]?.done == true} {#if $_user?.role === 'admin' || ($_user?.permissions?.chat?.stt ?? true)} { try { let stream = await navigator.mediaDevices .getUserMedia({ audio: true }) .catch(function (err) { toast.error( $i18n.t( `Permission denied when accessing microphone: {{error}}`, { error: err } ) ); return null; }); if (stream) { recording = true; const tracks = stream.getTracks(); tracks.forEach((track) => track.stop()); } stream = null; } catch { toast.error($i18n.t('Permission denied when accessing microphone')); } }} aria-label={$i18n.t('Voice Input')} > {/if} {/if} {#if callEnabled && !embedded && prompt === '' && files.length === 0 && showCallButton} { if (callActive) { showCallOverlay.set(true); showTabs.set('voice'); return; } if (selectedModels.length > 1) { toast.error($i18n.t('Select only one model to call')); return; } if ($config?.audio?.realtime?.enabled) { showCallOverlay.set(true); showTabs.set(true); return; } // check if user has access to getUserMedia try { let stream = await navigator.mediaDevices.getUserMedia({ audio: true }); // If the user grants the permission, proceed to show the call overlay if (stream) { const tracks = stream.getTracks(); tracks.forEach((track) => track.stop()); } stream = null; if ($settings.audio?.tts?.engine === 'browser-kokoro') { // If the user has not initialized the TTS worker, initialize it if (!$TTSWorker) { await TTSWorker.set( new KokoroWorker({ dtype: $settings.audio?.tts?.engineConfig?.dtype ?? 'fp32' }) ); await $TTSWorker.init(); } } showCallOverlay.set(true); showTabs.set(true); } catch (err) { // If the user denies the permission or an error occurs, show an error message toast.error( $i18n.t('Permission denied when accessing media devices') ); } }} aria-label={callActive ? $i18n.t('Return to call') : $i18n.t('Voice mode')} > {:else} {/if} {/if} {#if $config?.license_metadata?.input_footer} {@html DOMPurify.sanitize(marked($config?.license_metadata?.input_footer))} {:else} {/if} {/if}