2025-07-07 15:26:12 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { onMount, getContext } from 'svelte';
|
|
|
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
2025-07-07 15:47:32 +00:00
|
|
|
import Skeleton from '$lib/components/chat/Messages/Skeleton.svelte';
|
2025-07-07 15:56:31 +00:00
|
|
|
import Markdown from '$lib/components/chat/Messages/Markdown.svelte';
|
|
|
|
|
import Pencil from '$lib/components/icons/Pencil.svelte';
|
|
|
|
|
import Textarea from '$lib/components/common/Textarea.svelte';
|
2025-07-07 17:22:07 +00:00
|
|
|
import DocumentArrowUp from '$lib/components/icons/DocumentArrowUp.svelte';
|
|
|
|
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
2025-07-07 15:47:32 +00:00
|
|
|
|
2025-07-07 15:26:12 +00:00
|
|
|
export let message;
|
|
|
|
|
export let idx;
|
|
|
|
|
|
|
|
|
|
export let onDelete;
|
2025-07-07 15:56:31 +00:00
|
|
|
export let onEdit;
|
2025-07-07 17:22:07 +00:00
|
|
|
export let onInsert;
|
2025-07-07 15:26:12 +00:00
|
|
|
|
|
|
|
|
let textAreaElement: HTMLTextAreaElement;
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="flex flex-col gap-1 group">
|
2025-07-07 15:56:31 +00:00
|
|
|
<div class="flex items-center justify-between pt-1">
|
2025-07-07 15:42:08 +00:00
|
|
|
<div class="py-1 text-sm font-semibold uppercase min-w-[6rem] text-left rounded-lg transition">
|
2025-07-07 15:26:12 +00:00
|
|
|
{$i18n.t(message.role)}
|
|
|
|
|
</div>
|
2025-07-07 15:42:08 +00:00
|
|
|
|
2025-07-07 15:56:31 +00:00
|
|
|
<div class="flex items-center gap-2">
|
2025-07-07 17:22:07 +00:00
|
|
|
<Tooltip placement="top" content={$i18n.t('Insert')}>
|
|
|
|
|
<button
|
|
|
|
|
class=" text-transparent group-hover:text-gray-500 dark:hover:text-gray-300 transition"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
onInsert();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DocumentArrowUp className="size-3.5" strokeWidth="2" />
|
|
|
|
|
</button>
|
|
|
|
|
</Tooltip>
|
2025-07-07 15:56:31 +00:00
|
|
|
|
2025-07-07 17:22:07 +00:00
|
|
|
<Tooltip placement="top" content={$i18n.t('Edit')}>
|
|
|
|
|
<button
|
|
|
|
|
class=" text-transparent group-hover:text-gray-500 dark:hover:text-gray-300 transition"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
onEdit();
|
|
|
|
|
}}
|
2025-07-07 15:42:08 +00:00
|
|
|
>
|
2025-07-07 17:22:07 +00:00
|
|
|
<Pencil className="size-3.5" strokeWidth="2" />
|
|
|
|
|
</button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
|
|
<Tooltip placement="top" content={$i18n.t('Delete')}>
|
|
|
|
|
<button
|
|
|
|
|
class=" text-transparent group-hover:text-gray-500 dark:hover:text-gray-300 transition"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
onDelete();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
fill="none"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
class="size-4"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
stroke-linejoin="round"
|
|
|
|
|
d="M15 12H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</Tooltip>
|
2025-07-07 15:42:08 +00:00
|
|
|
</div>
|
2025-07-07 15:26:12 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="flex-1">
|
|
|
|
|
<!-- $i18n.t('a user') -->
|
|
|
|
|
<!-- $i18n.t('an assistant') -->
|
|
|
|
|
|
2025-07-07 15:47:32 +00:00
|
|
|
{#if !(message?.done ?? true) && message?.content === ''}
|
2025-07-07 15:56:31 +00:00
|
|
|
<div class="">
|
2025-07-07 15:47:32 +00:00
|
|
|
<Skeleton size="sm" />
|
|
|
|
|
</div>
|
2025-07-07 15:56:31 +00:00
|
|
|
{:else if message?.edit === true}
|
|
|
|
|
<Textarea
|
2025-07-07 20:07:50 +00:00
|
|
|
className="w-full bg-transparent outline-hidden text-sm resize-none overflow-hidden"
|
2025-07-07 15:47:32 +00:00
|
|
|
placeholder={$i18n.t(`Enter {{role}} message here`, {
|
|
|
|
|
role: message.role === 'user' ? $i18n.t('a user') : $i18n.t('an assistant')
|
|
|
|
|
})}
|
|
|
|
|
bind:value={message.content}
|
2025-07-07 17:22:07 +00:00
|
|
|
onBlur={() => {
|
|
|
|
|
message.edit = false;
|
|
|
|
|
}}
|
2025-07-07 15:47:32 +00:00
|
|
|
/>
|
2025-07-07 15:56:31 +00:00
|
|
|
{:else}
|
|
|
|
|
<div class=" markdown-prose-sm">
|
|
|
|
|
<Markdown id={`note-message-${idx}`} content={message.content} />
|
|
|
|
|
</div>
|
2025-07-07 15:47:32 +00:00
|
|
|
{/if}
|
2025-07-07 15:26:12 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|