2 import { Edit, Copy, RefreshCw, Trash2, ArrowRight, GitBranch } from '@lucide/svelte';
5 ChatMessageActionIconsBranchingControls,
7 } from '$lib/components/app';
8 import { Switch } from '$lib/components/ui/switch';
9 import { Checkbox } from '$lib/components/ui/checkbox';
10 import Input from '$lib/components/ui/input/input.svelte';
11 import Label from '$lib/components/ui/label/label.svelte';
12 import { MessageRole } from '$lib/enums';
13 import { activeConversation } from '$lib/stores/conversations.svelte';
16 role: MessageRole.USER | MessageRole.ASSISTANT;
17 justify: 'start' | 'end';
18 actionsPosition: 'left' | 'right';
19 siblingInfo?: ChatMessageSiblingInfo | null;
20 showDeleteDialog: boolean;
24 assistantMessages: number;
25 messageTypes: string[];
29 onRegenerate?: () => void;
30 onContinue?: () => void;
31 onForkConversation?: (options: { name: string; includeAttachments: boolean }) => void;
33 onConfirmDelete: () => void;
34 onNavigateToSibling?: (siblingId: string) => void;
35 onShowDeleteDialogChange: (show: boolean) => void;
36 showRawOutputSwitch?: boolean;
37 rawOutputEnabled?: boolean;
38 onRawOutputToggle?: (enabled: boolean) => void;
52 onShowDeleteDialogChange,
57 showRawOutputSwitch = false,
58 rawOutputEnabled = false,
62 let showForkDialog = $state(false);
63 let forkName = $state('');
64 let forkIncludeAttachments = $state(true);
66 function handleConfirmDelete() {
68 onShowDeleteDialogChange(false);
71 function handleOpenForkDialog() {
72 const conv = activeConversation();
74 forkName = `Fork of ${conv?.name ?? 'Conversation'}`;
75 forkIncludeAttachments = true;
76 showForkDialog = true;
79 function handleConfirmFork() {
80 onForkConversation?.({ name: forkName.trim(), includeAttachments: forkIncludeAttachments });
81 showForkDialog = false;
85 <div class="relative {justify === 'start' ? 'mt-2' : ''} flex h-6 items-center justify-between">
87 class="{actionsPosition === 'left'
89 : 'right-0'} flex items-center gap-2 opacity-100 transition-opacity"
91 {#if siblingInfo && siblingInfo.totalSiblings > 1}
92 <ChatMessageActionIconsBranchingControls {siblingInfo} {onNavigateToSibling} />
96 class="pointer-events-auto inset-0 flex items-center gap-1 opacity-100 transition-all duration-150"
98 <ActionIcon icon={Copy} tooltip="Copy" onclick={onCopy} />
101 <ActionIcon icon={Edit} tooltip="Edit" onclick={onEdit} />
104 {#if role === MessageRole.ASSISTANT && onRegenerate}
105 <ActionIcon icon={RefreshCw} tooltip="Regenerate" onclick={() => onRegenerate()} />
108 {#if role === MessageRole.ASSISTANT && onContinue}
109 <ActionIcon icon={ArrowRight} tooltip="Continue" onclick={onContinue} />
112 {#if onForkConversation}
113 <ActionIcon icon={GitBranch} tooltip="Fork conversation" onclick={handleOpenForkDialog} />
116 <ActionIcon icon={Trash2} tooltip="Delete" onclick={onDelete} />
120 {#if showRawOutputSwitch}
121 <div class="flex items-center gap-2">
122 <span class="text-xs text-muted-foreground">Show raw output</span>
124 checked={rawOutputEnabled}
125 onCheckedChange={(checked) => onRawOutputToggle?.(checked)}
132 bind:open={showDeleteDialog}
133 title="Delete Message"
134 description={deletionInfo && deletionInfo.totalCount > 1
135 ? `This will delete ${deletionInfo.totalCount} messages including: ${deletionInfo.userMessages} user message${deletionInfo.userMessages > 1 ? 's' : ''} and ${deletionInfo.assistantMessages} assistant response${deletionInfo.assistantMessages > 1 ? 's' : ''}. All messages in this branch and their responses will be permanently removed. This action cannot be undone.`
136 : 'Are you sure you want to delete this message? This action cannot be undone.'}
137 confirmText={deletionInfo && deletionInfo.totalCount > 1
138 ? `Delete ${deletionInfo.totalCount} Messages`
141 variant="destructive"
143 onConfirm={handleConfirmDelete}
144 onCancel={() => onShowDeleteDialogChange(false)}
148 bind:open={showForkDialog}
149 title="Fork Conversation"
150 description="Create a new conversation branching from this message."
154 onConfirm={handleConfirmFork}
155 onCancel={() => (showForkDialog = false)}
157 <div class="flex flex-col gap-4 py-2">
158 <div class="flex flex-col gap-2">
159 <Label for="fork-name">Title</Label>
163 class="text-foreground"
164 placeholder="Enter fork name"
166 bind:value={forkName}
170 <div class="flex items-center gap-2">
172 id="fork-attachments"
173 checked={forkIncludeAttachments}
174 onCheckedChange={(checked) => {
175 forkIncludeAttachments = checked === true;
179 <Label for="fork-attachments" class="cursor-pointer text-sm font-normal">
180 Include all attachments
184 </DialogConfirmation>