refac: WIP
This commit is contained in:
1 parent
5978e7c9a6
commit
b1521cacad
7 files changed
+65
-49
No files matched your search
@@ -226,7 +226,7 @@ __builtins__.input = input`);
|
||||
}
|
||||
};
|
||||
|
||||
$: if (token.raw) {
|
||||
$: if (token) {
|
||||
if (lang === 'mermaid' && (token?.raw ?? '').slice(-4).includes('```')) {
|
||||
(async () => {
|
||||
await drawMermaidDiagram();
|
||||
@@ -245,6 +245,7 @@ __builtins__.input = input`);
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
console.log('codeblock', lang, code);
|
||||
if (document.documentElement.classList.contains('dark')) {
|
||||
mermaid.initialize({
|
||||
startOnLoad: true,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</script>
|
||||
|
||||
<!-- {JSON.stringify(tokens)} -->
|
||||
{#each tokens as token, tokenIdx}
|
||||
{#each tokens as token, tokenIdx (tokenIdx)}
|
||||
{#if token.type === 'hr'}
|
||||
<hr />
|
||||
{:else if token.type === 'heading'}
|
||||
|
||||
@@ -12,10 +12,8 @@
|
||||
import UserMessage from './UserMessage.svelte';
|
||||
import { updateChatById } from '$lib/apis/chats';
|
||||
|
||||
// h here refers to the height of the message graph
|
||||
export let h;
|
||||
|
||||
export let chatId;
|
||||
export let idx = 0;
|
||||
|
||||
export let history;
|
||||
export let messageId;
|
||||
@@ -40,12 +38,23 @@
|
||||
|
||||
export let readOnly = false;
|
||||
|
||||
let message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
$: if (history.messages) {
|
||||
if (JSON.stringify(message) !== JSON.stringify(history.messages[messageId])) {
|
||||
message = JSON.parse(JSON.stringify(history.messages[messageId]));
|
||||
}
|
||||
}
|
||||
|
||||
const copyToClipboardWithToast = async (text) => {
|
||||
const res = await copyToClipboard(text);
|
||||
if (res) {
|
||||
toast.success($i18n.t('Copying to clipboard was successful!'));
|
||||
}
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
console.log('message', idx);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -53,13 +62,12 @@
|
||||
? 'max-w-full'
|
||||
: 'max-w-5xl'} mx-auto rounded-lg group"
|
||||
>
|
||||
{#if history.messages[messageId]}
|
||||
{@const message = history.messages[messageId]}
|
||||
{#if message}
|
||||
{#if message.role === 'user'}
|
||||
<UserMessage
|
||||
{user}
|
||||
{message}
|
||||
isFirstMessage={h === 0}
|
||||
isFirstMessage={idx === 0}
|
||||
siblings={message.parentId !== null
|
||||
? (history.messages[message.parentId]?.childrenIds ?? [])
|
||||
: (Object.values(history.messages)
|
||||
@@ -152,24 +160,3 @@
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if history.messages[messageId]?.parentId !== null}
|
||||
<svelte:self
|
||||
h={h + 1}
|
||||
{chatId}
|
||||
{history}
|
||||
messageId={history.messages[messageId]?.parentId}
|
||||
{user}
|
||||
{scrollToBottom}
|
||||
{chatActionHandler}
|
||||
{showPreviousMessage}
|
||||
{showNextMessage}
|
||||
{editMessage}
|
||||
{deleteMessage}
|
||||
{rateMessage}
|
||||
{regenerateResponse}
|
||||
{continueResponse}
|
||||
{mergeResponses}
|
||||
{readOnly}
|
||||
></svelte:self>
|
||||
{/if}
|
||||
@@ -316,6 +316,8 @@
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
console.log('ResponseMessage mounted');
|
||||
|
||||
await tick();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import dayjs from 'dayjs';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { tick, createEventDispatcher, getContext } from 'svelte';
|
||||
import { tick, createEventDispatcher, getContext, onMount } from 'svelte';
|
||||
|
||||
import { models, settings } from '$lib/stores';
|
||||
import { user as _user } from '$lib/stores';
|
||||
@@ -37,6 +37,10 @@
|
||||
let editedContent = '';
|
||||
let messageEditTextAreaElement: HTMLTextAreaElement;
|
||||
|
||||
$: if (message) {
|
||||
console.log('message', message);
|
||||
}
|
||||
|
||||
const copyToClipboard = async (text) => {
|
||||
const res = await _copyToClipboard(text);
|
||||
if (res) {
|
||||
@@ -71,6 +75,10 @@
|
||||
const deleteMessageHandler = async () => {
|
||||
dispatch('delete', message.id);
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
console.log('UserMessage mounted');
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class=" flex w-full user-message" dir={$settings.chatDirection} id="message-{message.id}">
|
||||
|
||||
Reference in new issue
Block a user