Skip to content

Commit f9cfe3b

Browse files
committed
fix: allow sample messages to be either string or array
1 parent 1a4a3c5 commit f9cfe3b

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

frontend/src/components/chat/chat-input.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import { Icons } from '@/components/icons';
55
import { Button } from '@/components/ui/button';
66
import { Textarea } from '@/components/ui/textarea';
77
import { cn } from '@/lib/utils';
8-
import { Chat } from '@/store/chats';
98
import { useChat, useChats } from '@/hooks/use-chats';
109
import { toast } from '@/hooks/use-toast';
11-
import { Badge } from '../ui/badge';
1210

1311
interface ChatInputProps {
1412
chatId: number;
15-
onSubmit: (message: string) => void;
16-
onAbort?: () => void;
13+
onSend: (message: string) => void;
1714
onReset?: () => void;
1815
loading?: boolean;
1916
disabled?: boolean;
@@ -23,8 +20,7 @@ interface ChatInputProps {
2320

2421
export const ChatInput = ({
2522
chatId,
26-
onSubmit,
27-
onAbort,
23+
onSend,
2824
onReset,
2925
loading,
3026
disabled,
@@ -49,15 +45,14 @@ export const ChatInput = ({
4945
const handleSubmit = useCallback(
5046
async (e: React.FormEvent) => {
5147
e.preventDefault();
52-
if (loading || disabled) return;
48+
setMessage('');
5349
if (chat?.status === 'wait_for_human_input') {
5450
await handleHumanInput(message);
5551
} else {
56-
onSubmit(message);
52+
onSend(message);
5753
}
58-
setMessage('');
5954
},
60-
[message, loading, disabled, onSubmit, handleHumanInput]
55+
[message, onSend, handleHumanInput]
6156
);
6257

6358
const handleKeyDown = useCallback(
@@ -175,34 +170,41 @@ export const ChatInput = ({
175170
<>
176171
<Button
177172
variant="outline"
178-
size="icon"
179-
className="h-7 w-7"
173+
size="sm"
174+
className="h-7"
180175
onClick={() => handleHumanInput('\n')}
181176
>
177+
enter
182178
<Icons.enter className="w-4 h-4" />
183179
</Button>
184180
<Button
185181
variant="outline"
186-
size="icon"
187-
className="h-7 w-7"
182+
size="sm"
183+
className="h-7"
188184
onClick={() => handleHumanInput('exit')}
189185
>
186+
exit
190187
<Icons.exit className="w-4 h-4" />
191188
</Button>
192189
</>
193190
)}
194191
<Button
195-
variant="default"
196192
size="icon"
197193
disabled={
198-
(!message.trim() && chat?.status !== 'wait_for_human_input') ||
199194
disabled ||
200-
isResetting
195+
isResetting ||
196+
chat?.status === 'running' ||
197+
(!message.trim() && chat?.status !== 'wait_for_human_input')
201198
}
202199
className="h-7 w-7"
203-
onClick={chat?.status !== 'ready' ? handleAbort : handleSubmit}
200+
onClick={
201+
chat?.status === 'running' ||
202+
chat?.status === 'wait_for_human_input'
203+
? handleAbort
204+
: handleSubmit
205+
}
204206
>
205-
{isUpdating ? (
207+
{chat?.status === 'running' ? (
206208
<Icons.stop className="w-4 h-4 text-red-500" />
207209
) : (
208210
<Icons.send className="w-4 h-4" />

frontend/src/components/chat/chat-pane.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export const ChatPane = ({ projectId, chatId }: ChatPaneProps) => {
2424
const { chat, chatSource, isLoading: isLoadingChat } = useChat(currentChatId);
2525
const { createChat, isCreating } = useChats();
2626
const { toast } = useToast();
27-
const [status, setStatus] = useState('ready');
2827
const [messages, setMessages] = useState<any[]>([]);
2928
const [isLoadingMessages, setIsLoadingMessages] = useState(false);
3029
const isFirstRender = useRef(true);
@@ -56,27 +55,11 @@ export const ChatPane = ({ projectId, chatId }: ChatPaneProps) => {
5655
}, [setMessages, chatId]);
5756

5857
// Fetch chat status
59-
const fetchChatStatus = useCallback(async () => {
60-
if (chatId === -1) return;
61-
const { data, error } = await supabase
62-
.from('chats')
63-
.select('status')
64-
.eq('id', chatId)
65-
.single();
66-
67-
if (error && error.code !== 'PGRST116') {
68-
console.error('Error fetching chat status:', error);
69-
} else if (data) {
70-
setStatus(data.status);
71-
}
72-
}, [setStatus, chatId]);
73-
7458
useEffect(() => {
7559
setCurrentChatId(chatId);
7660
if (chatId === -1) return;
7761

7862
fetchMessages();
79-
fetchChatStatus();
8063

8164
// Subscribe to chat_messages
8265
const messagesChannel: RealtimeChannel = supabase
@@ -181,11 +164,10 @@ export const ChatPane = ({ projectId, chatId }: ChatPaneProps) => {
181164
<div className="relative flex flex-col gap-1 w-full max-w-4xl mx-auto p-2 pt-0">
182165
<ChatInput
183166
chatId={chatId}
184-
onSubmit={handleSend}
167+
onSend={handleSend}
185168
onReset={handleReset}
186169
disabled={true}
187170
className="w-full"
188-
sampleMessages={['sample message']}
189171
/>
190172
</div>
191173
</div>
@@ -208,7 +190,10 @@ export const ChatPane = ({ projectId, chatId }: ChatPaneProps) => {
208190
const config = chatSource?.flow?.nodes?.find(
209191
(node: any) => node.type === 'initializer'
210192
);
211-
const sampleMessages = config?.data?.sample_messages?.split('\n') ?? [];
193+
let sampleMessages = config?.data?.sample_messages; // string or array
194+
if (sampleMessages && typeof sampleMessages === 'string') {
195+
sampleMessages = sampleMessages.split('\n');
196+
}
212197

213198
return (
214199
<div className="flex flex-col w-full h-full bg-muted">
@@ -236,10 +221,9 @@ export const ChatPane = ({ projectId, chatId }: ChatPaneProps) => {
236221
<div className="relative flex flex-col gap-1 w-full max-w-4xl mx-auto p-2 pt-0">
237222
<ChatInput
238223
chatId={chatId}
239-
onSubmit={handleSend}
224+
onSend={handleSend}
240225
onReset={handleReset}
241-
loading={status === 'running'}
242-
disabled={status === 'failed' || currentChatId === -1}
226+
disabled={currentChatId === -1}
243227
className="w-full"
244228
sampleMessages={sampleMessages}
245229
/>

0 commit comments

Comments
 (0)