char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: ESLint config updates (#27700)f1357e499

char/aliceai-t5-moe
2.6 KiB98 linesraw
1<script lang="ts">
2	import { browser } from '$app/environment';
3	import { goto } from '$app/navigation';
4	import { page } from '$app/state';
5	import { SearchInput, SidebarNavigationSearchResults } from '$lib/components/app';
6	import { ROUTES } from '$lib/constants';
7	import { RouterService } from '$lib/services/router.service';
8	import { chatStore, conversationsStore, deviceStore } from '$lib/stores';
9
10	let searchQuery = $state('');
11	let searchInputRef = $state<HTMLInputElement | null>(null);
12
13	let currentChatId = $derived(page.params.id);
14
15	let filteredConversations = $derived.by(() => {
16		const query = searchQuery.trim().toLowerCase();
17
18		if (query.length === 0) return [];
19
20		return conversationsStore.conversations.filter((c) => c.name.toLowerCase().includes(query));
21	});
22
23	// Search page is intended for mobile; on desktop the sidebar already exposes
24	// in-place search, so bounce back to a new-chat tab without a history entry.
25	$effect(() => {
26		if (browser && !deviceStore.isMobile) {
27			goto(ROUTES.START, { replaceState: true });
28		}
29	});
30
31	async function selectConversation(id: string) {
32		await goto(RouterService.chat(id));
33	}
34
35	async function handleEditConversation(id: string) {
36		const conversation = conversationsStore.conversations.find((c) => c.id === id);
37
38		if (!conversation) return;
39
40		const newName = window.prompt('Rename conversation', conversation.name);
41
42		if (newName && newName.trim()) {
43			await conversationsStore.updateConversationName(id, newName.trim());
44		}
45	}
46
47	async function handleDeleteConversation(id: string) {
48		const conversation = conversationsStore.conversations.find((c) => c.id === id);
49
50		if (!conversation) return;
51
52		const confirmed = window.confirm(
53			`Delete "${conversation.name}"? This action cannot be undone.`
54		);
55
56		if (!confirmed) return;
57
58		await conversationsStore.deleteConversation(id, { deleteWithForks: false });
59	}
60
61	function handleStopGeneration(id: string) {
62		chatStore.stopGenerationForChat(id);
63	}
64
65	function handleBack() {
66		if (history.length > 1) {
67			history.back();
68		} else {
69			conversationsStore.openNewChat();
70		}
71	}
72</script>
73
74<svelte:head>
75	<title>Search · llama.cpp</title>
76</svelte:head>
77
78<div class="fixed top-0 z-10 left-0 right-0 p-2">
79	<SearchInput
80		bind:ref={searchInputRef}
81		bind:value={searchQuery}
82		autofocus
83		onClose={handleBack}
84		placeholder="Search conversations..."
85	/>
86</div>
87
88<div class="p-2 pt-16">
89	<SidebarNavigationSearchResults
90		{currentChatId}
91		{filteredConversations}
92		onDelete={handleDeleteConversation}
93		onEdit={handleEditConversation}
94		onSelect={selectConversation}
95		onStop={handleStopGeneration}
96		{searchQuery}
97	/>
98</div>