{#if getChatVariablesForm(selectedModelIds, chatVariables, $models).conflicts.length > 0} {$i18n.t('Chat Variables')} { showChatVariablesModal = false; }} > {$i18n.t('Selected models define incompatible Chat Variables.')} {#each getChatVariablesForm(selectedModelIds, chatVariables, $models).conflicts as conflict} {conflict.key} {conflict.modelIds.join(', ')} {/each} {:else} {/if} { if (pendingWebSearchPrompt === null) { webSearchEnabled = false; } pendingWebSearchPrompt = null; }} /> { confirmDeleteChat(); }} > {$i18n.t('This will delete')} {$chatTitle}. { if (eventConfirmationInput) { eventCallback(e.detail); } else if (e.detail) { eventCallback(e.detail); } else { eventCallback(true); } }} on:cancel={() => { eventCallback(false); }} /> {#if !loading} {#if !embedded && $selectedFolder && $selectedFolder?.meta?.background_image_url} {:else if !embedded && ($settings?.backgroundImageUrl ?? $config?.license_metadata?.background_image_url ?? null)} {/if} {#if embedded} 0} {loading} onNewChat={onNewEmbeddedChat} onSelectChat={onSelectEmbeddedChat} onDeleteChat={onDeleteEmbeddedChat} /> onCloseEmbedded?.()} aria-label={$i18n.t('Close')} > {:else} { try { if (!history?.currentId || !Object.keys(history.messages).length) { toast.error($i18n.t('No conversation to save')); return; } const messages = createMessagesList(history, history.currentId); const title = messages.find((m) => m.role === 'user')?.content ?? $i18n.t('New Chat'); const savedChat = await createNewChat( localStorage.token, { id: uuidv4(), title: title.length > 50 ? `${title.slice(0, 50)}...` : title, models: selectedModels, params: params, history: history, messages: messages, timestamp: Date.now() }, null, chatVariables ); if (savedChat) { temporaryChatEnabled.set(false); chatId.set(savedChat.id); await refreshChatList(localStorage.token); await goto(`/c/${savedChat.id}`); toast.success($i18n.t('Conversation saved successfully')); } } catch (error) { console.error('Failed to save temporary chat:', error); toast.error($i18n.t('Failed to save conversation')); } }} /> {/if} {#if ($settings?.landingPageMode === 'chat' && !$selectedFolder) || createMessagesList(history, history.currentId).length > 0} { autoScroll = messagesContainerElement.scrollHeight - messagesContainerElement.scrollTop <= messagesContainerElement.clientHeight + 5; isNearTop = messagesContainerElement.scrollTop <= 100; }} > { messageInput?.setText(text); }} bind:selectedModels {atSelectedModel} className={embedded ? 'h-full flex pt-4' : 'h-full flex pt-18'} {sendMessage} {showMessage} {submitMessage} {continueResponse} {regenerateResponse} {mergeResponses} {chatActionHandler} {addMessages} allowDelete={!(generating || taskIds?.length)} forkHandler={generating || taskIds?.length ? null : handleForkChat} topPadding={!embedded} bottomPadding={files.length > 0} {onSelect} {onInsertToNote} /> {#if readOnly} {$i18n.t('Read only')} {:else} { const queue = $chatRequestQueues[$chatId] ?? []; const item = queue.find((m) => m.id === id); if (item) { // Remove from queue chatRequestQueues.update((q) => ({ ...q, [$chatId]: queue.filter((m) => m.id !== id) })); await stopResponse(false); await tick(); await submitPrompt(item.prompt, item.files); } }} onQueueEdit={(id) => { const queue = $chatRequestQueues[$chatId] ?? []; const item = queue.find((m) => m.id === id); if (item) { // Remove from queue chatRequestQueues.update((q) => ({ ...q, [$chatId]: queue.filter((m) => m.id !== id) })); // Set files and restore prompt to input files = item.files; messageInput?.setText(item.prompt); } }} onQueueDelete={(id) => { const queue = $chatRequestQueues[$chatId] ?? []; chatRequestQueues.update((q) => ({ ...q, [$chatId]: queue.filter((m) => m.id !== id) })); }} onChange={(data) => { if (!$temporaryChatEnabled) { saveDraft(data, $chatId); } }} onWebSearchToggle={handleWebSearchToggle} on:chatVariables={() => { showChatVariablesModal = true; }} on:submit={async (e) => { clearDraft($chatId); if (e.detail || files.length > 0) { await tick(); submitHandler(withSelectedText(e.detail)); } }} /> {/if} {:else if embedded} {#if suggestedPrompts.length > 0} {$i18n.t('Suggested prompts')} {#each suggestedPrompts as suggestion} { await tick(); await submitHandler(withSelectedText(suggestion)); }} > {suggestion} {/each} {/if} { showChatVariablesModal = true; }} on:submit={async (e) => { clearDraft($chatId); if (e.detail || files.length > 0) { await tick(); submitHandler(withSelectedText(e.detail)); } }} /> {:else} { showChatVariablesModal = true; }} onChange={(data) => { if (!$temporaryChatEnabled) { saveDraft(data); } }} on:submit={async (e) => { clearDraft(); if (e.detail || files.length > 0) { await tick(); submitHandler(withSelectedText(e.detail)); } }} /> {/if} {#if !embedded} { const model = $models.find((m) => m.id === e); if (model) { return [...a, model]; } return a; }, [])} submitPrompt={submitHandler} {stopResponse} {showMessage} {eventTarget} {codeInterpreterEnabled} containerId={chatContainerId} /> {/if} {:else if loading} {/if}