Skip to content

Commit af8b1cd

Browse files
committed
refactor: Chat components and data structures
Refactors chat-related components for better organization and maintainability. - Moves `ChatConversationsList` to `ChatSidebar` as `ChatSidebarConversationItem`. - Updates data structures to use `Message` type from `database.d.ts` instead of `conversation.d.ts`. - Standardizes props naming in `ChatForm` (`onsend` -> `onSend`, `onstop` -> `onStop`). - Improves markdown rendering and code block enhancements in `MarkdownContent`. - Updates database store import.
1 parent 5e72f25 commit af8b1cd

21 files changed

+137
-216
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
declare global {
2+
namespace App {
3+
// interface Error {}
4+
// interface Locals {}
5+
// interface PageData {}
6+
// interface Platform {}
7+
}
8+
}
9+
110
export * from './types/chat';
2-
export * from './types/conversation';
311
export * from './types/database';
412
export * from './types/settings';

tools/server/webui/src/lib/components/MarkdownContent.svelte

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts">
22
import { remark } from 'remark';
3-
import remarkGfm from 'remark-gfm';
43
import remarkBreaks from 'remark-breaks';
5-
import remarkRehype from 'remark-rehype';
4+
import remarkGfm from 'remark-gfm';
65
import rehypeHighlight from 'rehype-highlight';
6+
import remarkRehype from 'remark-rehype';
77
import rehypeStringify from 'rehype-stringify';
88
import 'highlight.js/styles/github-dark.css';
99
@@ -26,20 +26,6 @@
2626
.use(rehypeStringify); // Convert to HTML string
2727
});
2828
29-
async function processMarkdown(text: string): Promise<string> {
30-
try {
31-
const result = await processor().process(text);
32-
const html = String(result);
33-
34-
return enhanceCodeBlocks(html);
35-
} catch (error) {
36-
console.error('Markdown processing error:', error);
37-
38-
// Fallback to plain text with line breaks
39-
return text.replace(/\n/g, '<br>');
40-
}
41-
}
42-
4329
function enhanceCodeBlocks(html: string): string {
4430
const tempDiv = document.createElement('div');
4531
tempDiv.innerHTML = html;
@@ -100,6 +86,20 @@
10086
return tempDiv.innerHTML;
10187
}
10288
89+
async function processMarkdown(text: string): Promise<string> {
90+
try {
91+
const result = await processor().process(text);
92+
const html = String(result);
93+
94+
return enhanceCodeBlocks(html);
95+
} catch (error) {
96+
console.error('Markdown processing error:', error);
97+
98+
// Fallback to plain text with line breaks
99+
return text.replace(/\n/g, '<br>');
100+
}
101+
}
102+
103103
function setupCopyButtons() {
104104
if (!containerRef) return;
105105

tools/server/webui/src/lib/components/ServerInfo.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { Server, Eye, Mic } from '@lucide/svelte';
44
import { serverStore } from '$lib/stores/server.svelte';
55
6-
// Reactive server information
76
const props = $derived(serverStore.serverProps);
87
const model = $derived(serverStore.modelName);
98
const modalities = $derived(serverStore.supportedModalities);
@@ -19,14 +18,12 @@
1918
</Badge>
2019
{/if}
2120

22-
<!-- Context Length -->
2321
{#if props.n_ctx}
2422
<Badge variant="secondary" class="text-xs">
2523
ctx: {props.n_ctx.toLocaleString()}
2624
</Badge>
2725
{/if}
2826

29-
<!-- Supported Modalities -->
3027
{#if modalities.length > 0}
3128
{#each modalities as modality}
3229
<Badge variant="secondary" class="text-xs">

tools/server/webui/src/lib/components/ServerStatus.svelte

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
let { class: className = '', variant = 'header', showActions = false }: Props = $props();
1414
15-
// Real server status from store
1615
const serverData = $derived(serverProps());
1716
const loading = $derived(serverLoading());
1817
const error = $derived(serverError());
@@ -34,13 +33,11 @@
3433
</script>
3534

3635
<div class="flex items-center space-x-2 {className}">
37-
<!-- Status Indicator -->
3836
<div class="flex items-center space-x-2">
3937
<div class="h-2 w-2 rounded-full {getStatusColor()}"></div>
4038
<span class="text-muted-foreground text-sm">{getStatusText()}</span>
4139
</div>
4240

43-
<!-- Server Info -->
4441
{#if serverData && !error}
4542
<Badge variant="outline" class="text-xs">
4643
<Server class="mr-1 h-3 w-3" />
@@ -53,7 +50,6 @@
5350
{/if}
5451
{/if}
5552

56-
<!-- Error Action (if needed) -->
5753
{#if showActions && error}
5854
<Button variant="outline" size="sm" class="text-destructive">
5955
<AlertTriangle class="mr-2 h-4 w-4" />

tools/server/webui/src/lib/components/chat/ChatConversations/ChatConversationsList.svelte

Lines changed: 0 additions & 48 deletions
This file was deleted.

tools/server/webui/src/lib/components/chat/ChatForm.svelte

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
class?: string;
88
disabled?: boolean;
99
isLoading?: boolean;
10-
onsend?: (message: string) => void;
11-
onstop?: () => void;
10+
onSend?: (message: string) => void;
11+
onStop?: () => void;
1212
showHelperText?: boolean;
1313
}
1414
1515
let {
1616
class: className,
1717
disabled = false,
1818
isLoading = false,
19-
onsend,
20-
onstop,
19+
onSend,
20+
onStop,
2121
showHelperText = true
2222
}: Props = $props();
2323
@@ -28,7 +28,7 @@
2828
event.preventDefault();
2929
if (!message.trim() || disabled || isLoading) return;
3030
31-
onsend?.(message.trim());
31+
onSend?.(message.trim());
3232
message = '';
3333
3434
if (textareaElement) {
@@ -42,7 +42,7 @@
4242
4343
if (!message.trim() || disabled || isLoading) return;
4444
45-
onsend?.(message.trim());
45+
onSend?.(message.trim());
4646
message = '';
4747
4848
if (textareaElement) {
@@ -52,19 +52,17 @@
5252
}
5353
5454
function handleStop() {
55-
onstop?.();
55+
onStop?.();
5656
}
5757
</script>
5858

5959
<form
6060
onsubmit={handleSubmit}
6161
class="bg-background dark:bg-muted border-radius-bottom-none mx-auto max-w-4xl overflow-hidden rounded-3xl {className}"
6262
>
63-
<!-- Input Container -->
6463
<div
6564
class="bg-muted/30 border-border/40 focus-within:border-primary/40 flex-column relative min-h-[48px] items-center rounded-3xl border px-5 py-3 shadow-sm transition-all focus-within:shadow-md"
6665
>
67-
<!-- Text Input -->
6866
<div class="flex-1">
6967
<textarea
7068
bind:this={textareaElement}
@@ -77,9 +75,7 @@
7775
></textarea>
7876
</div>
7977

80-
<!-- Actions Bar -->
8178
<div class="flex items-center justify-between gap-1">
82-
<!-- Left Actions -->
8379
<Button
8480
type="button"
8581
variant="ghost"
@@ -121,7 +117,6 @@
121117
</div>
122118
</form>
123119

124-
<!-- Helper Text -->
125120
{#if showHelperText}
126121
<div class="mt-4 flex items-center justify-center">
127122
<p class="text-muted-foreground text-xs">

0 commit comments

Comments
 (0)