Spaces:
Build error
Build error
File size: 1,349 Bytes
1b66f8d 5da61b4 77c7055 5da61b4 1b66f8d 3aa8136 1b66f8d 77c7055 1b66f8d 0714764 837d314 3aa8136 1b66f8d b7f9ccb 1b66f8d 3aa8136 5da61b4 3aa8136 1b66f8d 0714764 1b66f8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<script lang="ts">
import type { Message } from "$lib/types/Message";
import { snapScrollToBottom } from "$lib/actions/snapScrollToBottom";
import ScrollToBottomBtn from "$lib/components/ScrollToBottomBtn.svelte";
import { tick } from "svelte";
import ChatIntroduction from "./ChatIntroduction.svelte";
import ChatMessage from "./ChatMessage.svelte";
export let messages: Message[];
export let loading: boolean;
export let pending: boolean;
let chatContainer: HTMLElement;
async function scrollToBottom() {
await tick();
chatContainer.scrollTop = chatContainer.scrollHeight;
}
// If last message is from user, scroll to bottom
$: if (messages.at(-1)?.from === "user") {
scrollToBottom();
}
</script>
<div
class="overflow-y-auto h-full scrollbar-custom mr-1"
use:snapScrollToBottom={messages}
bind:this={chatContainer}
>
<div class="max-w-3xl xl:max-w-4xl mx-auto px-5 pt-6 flex flex-col gap-5 sm:gap-8 h-full">
{#each messages as message, i}
<ChatMessage loading={loading && i === messages.length - 1} {message} />
{:else}
<ChatIntroduction on:message />
{/each}
{#if pending}
<ChatMessage message={{ from: "assistant", content: "" }} />
{/if}
<div class="h-32 flex-none" />
</div>
<ScrollToBottomBtn
class="max-md:hidden bottom-36 right-4 lg:right-10"
scrollNode={chatContainer}
/>
</div>
|