diff --git a/app/frontend/components/Chat.tsx b/app/frontend/components/Chat.tsx index 2558573e..c13dde5d 100644 --- a/app/frontend/components/Chat.tsx +++ b/app/frontend/components/Chat.tsx @@ -4,6 +4,7 @@ import { CopilotKit, useCoAgent, useCoAgentStateRender, + useCopilotAction, } from "@copilotkit/react-core"; import { CopilotChat } from "@copilotkit/react-ui"; import "@copilotkit/react-ui/styles.css"; @@ -34,6 +35,299 @@ interface ChatSessionState { qa_history: QAResponse[]; } +function SpinnerIcon() { + return ( + + + + ); +} + +function CheckIcon() { + return ( + + + + ); +} + +function SearchIcon() { + return ( + + + + + ); +} + +function MessageIcon() { + return ( + + + + ); +} + +function FileIcon() { + return ( + + + + + ); +} + +function ToolCallIndicator({ + toolName, + status, + args, +}: { + toolName: string; + status: string; + args: Record; +}) { + const isComplete = status === "complete"; + + const getToolIcon = () => { + switch (toolName) { + case "search": + return ; + case "ask": + return ; + case "get_document": + return ; + default: + return ; + } + }; + + const getToolLabel = () => { + switch (toolName) { + case "search": + return "Search"; + case "ask": + return "Ask"; + case "get_document": + return "Document"; + default: + return toolName; + } + }; + + const getDescription = () => { + switch (toolName) { + case "search": { + const query = args.query as string; + const docName = args.document_name as string | undefined; + return ( + <> + {query} + {docName && ( + + {" "} + in {docName} + + )} + > + ); + } + case "ask": { + const question = args.question as string; + const docName = args.document_name as string | undefined; + return ( + <> + {question} + {docName && ( + + {" "} + from {docName} + + )} + > + ); + } + case "get_document": + return {args.query as string}; + default: + return Processing...; + } + }; + + return ( + + + + {isComplete ? : } + + + + + {getToolIcon()} + {getToolLabel()} + + + {isComplete ? "Done" : "Working..."} + + + {getDescription()} + + + ); +} + function ChatContent() { useCoAgent({ name: "chat_agent", @@ -54,6 +348,51 @@ function ChatContent() { }, }); + useCopilotAction({ + name: "search", + available: "disabled", + parameters: [ + { name: "query", type: "string" }, + { name: "document_name", type: "string" }, + ], + render: ({ status, args }) => ( + } + /> + ), + }); + + useCopilotAction({ + name: "ask", + available: "disabled", + parameters: [ + { name: "question", type: "string" }, + { name: "document_name", type: "string" }, + ], + render: ({ status, args }) => ( + } + /> + ), + }); + + useCopilotAction({ + name: "get_document", + available: "disabled", + parameters: [{ name: "query", type: "string" }], + render: ({ status, args }) => ( + } + /> + ), + }); + return ( <>