diff --git a/libs/ui/app/agents/[agentId]/chat.tsx b/libs/ui/app/agents/[agentId]/chat.tsx index d7502657b..619563ad7 100644 --- a/libs/ui/app/agents/[agentId]/chat.tsx +++ b/libs/ui/app/agents/[agentId]/chat.tsx @@ -5,6 +5,7 @@ import { fetchEventSource } from "@microsoft/fetch-event-source" import dayjs from "dayjs" import relativeTime from "dayjs/plugin/relativeTime" import { RxChatBubble, RxCode } from "react-icons/rx" +import { TbBolt } from "react-icons/tb" import { useAsyncFn } from "react-use" import { v4 as uuidv4 } from "uuid" @@ -13,15 +14,27 @@ import { Profile } from "@/types/profile" import { Api } from "@/lib/api" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardHeader } from "@/components/ui/card" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" import { ScrollArea } from "@/components/ui/scroll-area" import { Toaster } from "@/components/ui/toaster" import { useToast } from "@/components/ui/use-toast" import Message from "@/components/message" +import FunctionCalls from "@/app/workflows/[id]/function-calls" import PromptForm from "./prompt-form" dayjs.extend(relativeTime) +const defaultFunctionCalls = [ + { + type: "start", + }, +] + export default function Chat({ agent, profile, @@ -30,6 +43,8 @@ export default function Chat({ profile: Profile }) { const api = new Api(profile.api_key) + const [functionCalls, setFunctionCalls] = React.useState() + const [isLoading, setIsLoading] = React.useState(false) const [selectedView, setSelectedView] = React.useState<"chat" | "trace">( "chat" @@ -61,6 +76,14 @@ export default function Chat({ } } + const resetState = () => { + setIsLoading(false) + setTimer(0) + if (timerRef.current) { + clearInterval(timerRef.current) + } + } + async function onSubmit(value: string) { let message = "" @@ -104,12 +127,18 @@ export default function Chat({ }), openWhenHidden: true, signal: abortControllerRef.current.signal, + + async onopen() { + setFunctionCalls(defaultFunctionCalls) + }, async onclose() { - setIsLoading(false) - setTimer(0) - if (timerRef.current) { - clearInterval(timerRef.current) - } + setFunctionCalls((previousFunctionCalls = []) => [ + ...previousFunctionCalls, + { + type: "end", + }, + ]) + resetState() }, async onmessage(event) { if (event.data !== "[END]" && event.event !== "function_call") { @@ -188,6 +217,23 @@ export default function Chat({ > {timer.toFixed(1)}s

+ +
+ {functionCalls && functionCalls.length > 0 && ( + + + + + {functionCalls?.length} + + + + + + + )} +
+ {/*