Skip to content

Commit e23d39d

Browse files
committed
feat: Allows sending messages with attachments only
Updates the chat form to enable sending messages even if the text input is empty, as long as there are uploaded files attached. Also adds tooltips to the microphone and attachment buttons to indicate if the current model does not support audio or vision, respectively. Hides the card from the user's message if the message content is empty.
1 parent 7919123 commit e23d39d

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
<ChatFormActionButtons
160160
{disabled}
161161
{isLoading}
162-
canSend={message.trim().length > 0}
162+
canSend={message.trim().length > 0 || uploadedFiles.length > 0}
163163
onFileUpload={handleFileUpload}
164164
onStop={handleStop}
165165
/>

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

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
22
import { Button } from '$lib/components/ui/button';
33
import { Square, Paperclip, Mic, ArrowUp } from '@lucide/svelte';
4+
import { supportsAudio, supportsVision } from '$lib/stores/server.svelte';
5+
import * as Tooltip from '$lib/components/ui/tooltip';
46
57
interface Props {
68
disabled?: boolean;
@@ -9,6 +11,7 @@
911
onFileUpload?: () => void;
1012
onStop?: () => void;
1113
onMicClick?: () => void;
14+
isRecording?: boolean;
1215
class?: string;
1316
}
1417
@@ -19,20 +22,34 @@
1922
onFileUpload,
2023
onStop,
2124
onMicClick,
25+
isRecording = false,
2226
class: className = ''
2327
}: Props = $props();
2428
</script>
2529

2630
<div class="flex items-center justify-between gap-1 {className}">
27-
<Button
28-
type="button"
29-
class="text-muted-foreground bg-transparent hover:bg-foreground/10 hover:text-foreground h-8 w-8 rounded-full p-0"
30-
disabled={disabled || isLoading}
31-
onclick={onFileUpload}
32-
>
33-
<span class="sr-only">Attach files</span>
34-
<Paperclip class="h-4 w-4" />
35-
</Button>
31+
<div class="flex items-center gap-1">
32+
<Tooltip.Root>
33+
<Tooltip.Trigger>
34+
<Button
35+
type="button"
36+
class="text-muted-foreground bg-transparent hover:bg-foreground/10 hover:text-foreground h-8 w-8 rounded-full p-0 {!supportsVision()
37+
? 'opacity-50 cursor-not-allowed'
38+
: ''}"
39+
disabled={disabled || isLoading || !supportsVision()}
40+
onclick={onFileUpload}
41+
>
42+
<span class="sr-only">Attach files</span>
43+
<Paperclip class="h-4 w-4" />
44+
</Button>
45+
</Tooltip.Trigger>
46+
{#if !supportsVision()}
47+
<Tooltip.Content>
48+
<p>Current model does not support vision</p>
49+
</Tooltip.Content>
50+
{/if}
51+
</Tooltip.Root>
52+
</div>
3653

3754
<div class="flex gap-2">
3855
{#if isLoading}
@@ -45,15 +62,29 @@
4562
<Square class="h-8 w-8 fill-destructive stroke-destructive" />
4663
</Button>
4764
{:else}
48-
<Button
49-
type="button"
50-
class="text-muted-foreground bg-transparent hover:bg-foreground/10 hover:text-foreground h-8 w-8 rounded-full p-0"
51-
disabled={disabled || isLoading}
52-
onclick={onMicClick}
53-
>
54-
<span class="sr-only">Start recording</span>
55-
<Mic class="h-8 w-8" />
56-
</Button>
65+
<Tooltip.Root>
66+
<Tooltip.Trigger>
67+
<Button
68+
type="button"
69+
class="h-8 w-8 rounded-full p-0 {isRecording
70+
? 'bg-red-500 hover:bg-red-600 text-white animate-pulse'
71+
: 'text-muted-foreground bg-transparent hover:bg-foreground/10 hover:text-foreground'} {!supportsAudio()
72+
? 'opacity-50 cursor-not-allowed'
73+
: ''}"
74+
disabled={disabled || isLoading || !supportsAudio()}
75+
onclick={onMicClick}
76+
>
77+
<span class="sr-only">{isRecording ? 'Stop recording' : 'Start recording'}</span>
78+
<Mic class="h-4 w-4" />
79+
</Button>
80+
</Tooltip.Trigger>
81+
82+
{#if !supportsAudio()}
83+
<Tooltip.Content>
84+
<p>Current model does not support audio</p>
85+
</Tooltip.Content>
86+
{/if}
87+
</Tooltip.Root>
5788

5889
<Button
5990
type="submit"

tools/server/webui/src/lib/components/app/chat/ChatMessages/ChatMessage.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@
143143
</div>
144144
{/if}
145145

146-
<Card class="bg-primary text-primary-foreground max-w-[80%] rounded-2xl px-2.5 py-1.5">
147-
<div class="text-md whitespace-pre-wrap">
148-
{message.content}
149-
</div>
150-
</Card>
146+
{#if message.content.trim()}
147+
<Card class="bg-primary text-primary-foreground max-w-[80%] rounded-2xl px-2.5 py-1.5">
148+
<div class="text-md whitespace-pre-wrap">
149+
{message.content}
150+
</div>
151+
</Card>
152+
{/if}
151153

152154
<div class="relative flex h-6 items-center">
153155
{@render messageActions({ role: 'user' })}

0 commit comments

Comments
 (0)