forked from sourcewizard-ai/react-ai-agent-chat-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-chat.tsx
More file actions
50 lines (45 loc) · 1.52 KB
/
agent-chat.tsx
File metadata and controls
50 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use client';
import { AgentChatConfig } from './config';
import { AgentChatProvider, useChatState } from './chat-config-provider';
import { ChatMessage } from './chat-message';
import { ChatInput } from './chat-input';
import { DebugPanel } from './debug-panel';
import { ChatLayout, ChatMessagesContainer } from './chat-layout';
export const AgentChat = ({ config, conversationId }: { config: AgentChatConfig; conversationId: string }) => {
return (
<AgentChatProvider config={config} conversationId={conversationId}>
<ChatLayout>
<ChatMessagesContainer>
<ChatMessages />
{config.showDebugPanel && <DebugPanel />}
</ChatMessagesContainer>
<ChatInput />
</ChatLayout>
</AgentChatProvider>
);
};
const ChatMessages = () => {
const { isLoadingHistory, allMessages } = useChatState();
if (isLoadingHistory) {
return (
<div className="flex items-center justify-center py-8 text-gray-500">
<div className="flex items-center space-x-2">
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-gray-400"></div>
<span className="text-sm">Loading conversation history...</span>
</div>
</div>
);
}
return (
<>
{allMessages.map((message: any, messageIndex: number) => (
<ChatMessage
key={message.id || messageIndex}
message={message}
messageIndex={messageIndex}
isLastMessage={messageIndex === allMessages.length - 1}
/>
))}
</>
);
};