{#if messages.length == 0} { let text = p; if (p.includes('{{CLIPBOARD}}')) { const clipboardText = await navigator.clipboard.readText().catch((err) => { toast.error($i18n.t('Failed to read clipboard contents')); return '{{CLIPBOARD}}'; }); text = p.replaceAll('{{CLIPBOARD}}', clipboardText); } prompt = text; await tick(); const chatInputElement = document.getElementById('chat-textarea'); if (chatInputElement) { prompt = p; chatInputElement.style.height = ''; chatInputElement.style.height = Math.min(chatInputElement.scrollHeight, 200) + 'px'; chatInputElement.focus(); const words = findWordIndices(prompt); if (words.length > 0) { const word = words.at(0); chatInputElement.setSelectionRange(word?.startIndex, word.endIndex + 1); } } await tick(); }} /> {:else}
{#key chatId} {#each messages as message, messageIdx}
{#if message.role === 'user'} deleteMessageHandler(message.id)} {user} {readOnly} {message} isFirstMessage={messageIdx === 0} siblings={message.parentId !== null ? (history.messages[message.parentId]?.childrenIds ?? []) : (Object.values(history.messages) .filter((message) => message.parentId === null) .map((message) => message.id) ?? [])} {confirmEditMessage} {showPreviousMessage} {showNextMessage} copyToClipboard={copyToClipboardWithToast} /> {:else if (history.messages[message.parentId]?.models?.length ?? 1) === 1} {#key message.id && history.currentId} { console.log('action', e); if (typeof e.detail === 'string') { await chatActionHandler(chatId, e.detail, message.model, message.id); } else { const { id, event } = e.detail; await chatActionHandler(chatId, id, message.model, message.id, event); } }} on:save={async (e) => { console.log('save', e); const message = e.detail; history.messages[message.id] = message; await updateChatById(localStorage.token, chatId, { messages: messages, history: history }); }} /> {/key} {:else} {#key message.parentId} { console.log('action', e); if (typeof e.detail === 'string') { await chatActionHandler(chatId, e.detail, message.model, message.id); } else { const { id, event } = e.detail; await chatActionHandler(chatId, id, message.model, message.id, event); } }} on:change={async () => { await updateChatById(localStorage.token, chatId, { messages: messages, history: history }); if (autoScroll) { const element = document.getElementById('messages-container'); autoScroll = element.scrollHeight - element.scrollTop <= element.clientHeight + 50; setTimeout(() => { scrollToBottom(); }, 100); } }} /> {/key} {/if}
{/each} {#if bottomPadding}
{/if} {/key}
{/if}