MCPcopy Create free account
hub / github.com/AbhinavTheDev/coding-agent / ChatInterface

Function ChatInterface

ui/app/components/chatInterface.tsx:15–126  ·  view source on GitHub ↗
({
  isLoading,
  appendMessage,
  visibleMessages
}: {
  isLoading: boolean
  appendMessage: (message: TextMessage) => void
  visibleMessages: TextMessage[]
})

Source from the content-addressed store, hash-verified

13
14
15export default function ChatInterface({
16 isLoading,
17 appendMessage,
18 visibleMessages
19}: {
20 isLoading: boolean
21 appendMessage: (message: TextMessage) => void
22 visibleMessages: TextMessage[]
23}) {
24 const messagesEndRef = useRef<HTMLDivElement>(null)
25 const [inputValue, setInputValue] = useState("")
26
27 const scrollToBottom = () => {
28 messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
29 }
30
31
32
33 useEffect(() => {
34 const textarea = document.querySelector('textarea');
35 if (textarea) {
36 textarea.style.height = 'auto';
37 textarea.style.height = `${Math.min(textarea.scrollHeight, 120)}px`;
38 }
39 }, [inputValue]);
40
41 useEffect(() => {
42 scrollToBottom();
43 }, [visibleMessages]);
44
45 const handleSendMessage = () => {
46 if (inputValue.trim()) {
47 appendMessage(new TextMessage({
48 content: inputValue,
49 role: Role.User
50 }))
51 setInputValue("")
52 }
53 }
54
55
56
57 return (
58 <Card className="bg-[#cdcdd5] dark:bg-[#191A19] flex flex-col overflow-hidden">
59 <CardContent className="flex flex-col h-[calc(100vh-200px)] overflow-y-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-track]:rounded-full p-4 space-y-4">
60 {visibleMessages.map((message) => message.content && (
61 <div
62 key={message.id}
63 className={cn("flex items-start gap-2 group", {
64 "justify-end": (message.role === "user"),
65 })}
66 >
67 {(message.role === "assistant") && (
68 <Avatar className="w-8 h-8">
69 <AvatarImage src="/rdj.jpg" />
70 <AvatarFallback>AI</AvatarFallback>
71 </Avatar>
72 )}

Callers

nothing calls this directly

Calls 4

cnFunction · 0.90
scrollToBottomFunction · 0.85
formatMessageWithCodeFunction · 0.85
handleSendMessageFunction · 0.85

Tested by

no test coverage detected