]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/blob
dad8d954cbb2c7e7baa7fb4cf2ab10e98ba0387b
[pkg/ggml/sources/llama.cpp] /
1 <script lang="ts">
2 import {
3 Trash2,
4 Pencil,
5 MoreHorizontal,
6 Download,
7 Loader2,
8 Square,
9 GitBranch
10 } from '@lucide/svelte';
11 import { DropdownMenuActions } from '$lib/components/app';
12 import * as Tooltip from '$lib/components/ui/tooltip';
13 import { FORK_TREE_DEPTH_PADDING } from '$lib/constants';
14 import { RouterService } from '$lib/services/router.service';
15 import { getAllLoadingChats } from '$lib/stores/chat.svelte';
16 import { conversationsStore } from '$lib/stores/conversations.svelte';
17 import { TruncatedText } from '$lib/components/app';
18 import { onMount } from 'svelte';
19
20 interface Props {
21 isActive?: boolean;
22 depth?: number;
23 conversation: DatabaseConversation;
24 onDelete?: (id: string) => void;
25 onEdit?: (id: string) => void;
26 onSelect?: (id: string) => void;
27 onStop?: (id: string) => void;
28 }
29
30 let {
31 conversation,
32 onDelete,
33 onEdit,
34 onSelect,
35 onStop,
36 isActive = false,
37 depth = 0
38 }: Props = $props();
39
40 let renderActionsDropdown = $state(false);
41 let dropdownOpen = $state(false);
42
43 let isLoading = $derived(getAllLoadingChats().includes(conversation.id));
44
45 function handleEdit(event: Event) {
46 event.stopPropagation();
47 onEdit?.(conversation.id);
48 }
49
50 function handleDelete(event: Event) {
51 event.stopPropagation();
52 onDelete?.(conversation.id);
53 }
54
55 function handleStop(event: Event) {
56 event.stopPropagation();
57 onStop?.(conversation.id);
58 }
59
60 function handleGlobalEditEvent(event: Event) {
61 const customEvent = event as CustomEvent<{ conversationId: string }>;
62
63 if (customEvent.detail.conversationId === conversation.id && isActive) {
64 handleEdit(event);
65 }
66 }
67
68 function handleMouseLeave() {
69 if (!dropdownOpen) {
70 renderActionsDropdown = false;
71 }
72 }
73
74 function handleMouseOver() {
75 renderActionsDropdown = true;
76 }
77
78 function handleSelect() {
79 onSelect?.(conversation.id);
80 }
81
82 $effect(() => {
83 if (!dropdownOpen) {
84 renderActionsDropdown = false;
85 }
86 });
87
88 onMount(() => {
89 document.addEventListener('edit-active-conversation', handleGlobalEditEvent as EventListener);
90
91 return () => {
92 document.removeEventListener(
93 'edit-active-conversation',
94 handleGlobalEditEvent as EventListener
95 );
96 };
97 });
98 </script>
99
100 <!-- svelte-ignore a11y_mouse_events_have_key_events -->
101 <button
102 class="group flex min-h-9 w-full cursor-pointer items-center justify-between space-x-3 rounded-lg py-1.5 text-left transition-colors hover:bg-foreground/10 {isActive
103 ? 'bg-foreground/5 text-accent-foreground'
104 : ''} px-3"
105 onclick={handleSelect}
106 onmouseover={handleMouseOver}
107 onmouseleave={handleMouseLeave}
108 >
109 <div
110 class="flex min-w-0 flex-1 items-center gap-2"
111 style:padding-left="{depth * FORK_TREE_DEPTH_PADDING}px"
112 >
113 {#if depth > 0}
114 <Tooltip.Root>
115 <Tooltip.Trigger>
116 <a
117 href={RouterService.chat(conversation.forkedFromConversationId)}
118 class="flex shrink-0 items-center text-muted-foreground transition-colors hover:text-foreground"
119 >
120 <GitBranch class="h-3.5 w-3.5" />
121 </a>
122 </Tooltip.Trigger>
123
124 <Tooltip.Content>
125 <p>See parent conversation</p>
126 </Tooltip.Content>
127 </Tooltip.Root>
128 {/if}
129
130 {#if isLoading}
131 <Tooltip.Root>
132 <Tooltip.Trigger>
133 <div
134 class="stop-button flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"
135 onclick={handleStop}
136 onkeydown={(e) => e.key === 'Enter' && handleStop(e)}
137 role="button"
138 tabindex="0"
139 aria-label="Stop generation"
140 >
141 <Loader2 class="loading-icon h-3.5 w-3.5 animate-spin" />
142
143 <Square class="stop-icon hidden h-3 w-3 fill-current text-destructive" />
144 </div>
145 </Tooltip.Trigger>
146
147 <Tooltip.Content>
148 <p>Stop generation</p>
149 </Tooltip.Content>
150 </Tooltip.Root>
151 {/if}
152
153 <TruncatedText text={conversation.name} class="text-sm font-medium" showTooltip={false} />
154 </div>
155
156 {#if renderActionsDropdown}
157 <div class="actions flex items-center">
158 <DropdownMenuActions
159 triggerIcon={MoreHorizontal}
160 triggerTooltip="More actions"
161 bind:open={dropdownOpen}
162 actions={[
163 {
164 icon: Pencil,
165 label: 'Edit',
166 onclick: handleEdit,
167 shortcut: ['shift', 'cmd', 'e']
168 },
169 {
170 icon: Download,
171 label: 'Export',
172 onclick: (e: Event) => {
173 e.stopPropagation();
174 conversationsStore.downloadConversation(conversation.id);
175 },
176 shortcut: ['shift', 'cmd', 's']
177 },
178 {
179 icon: Trash2,
180 label: 'Delete',
181 onclick: handleDelete,
182 variant: 'destructive',
183 shortcut: ['shift', 'cmd', 'd'],
184 separator: true
185 }
186 ]}
187 />
188 </div>
189 {/if}
190 </button>
191
192 <style>
193 button {
194 :global([data-slot='dropdown-menu-trigger']:not([data-state='open'])) {
195 opacity: 0;
196 }
197
198 &:is(:hover) :global([data-slot='dropdown-menu-trigger']) {
199 opacity: 1;
200 }
201 @media (max-width: 768px) {
202 :global([data-slot='dropdown-menu-trigger']) {
203 opacity: 1 !important;
204 }
205 }
206
207 .stop-button {
208 :global(.stop-icon) {
209 display: none;
210 }
211
212 :global(.loading-icon) {
213 display: block;
214 }
215 }
216
217 &:is(:hover) .stop-button {
218 :global(.stop-icon) {
219 display: block;
220 }
221
222 :global(.loading-icon) {
223 display: none;
224 }
225 }
226 }
227 </style>