这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions libs/ui/app/agents/[agentId]/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
Expand All @@ -30,6 +43,8 @@ export default function Chat({
profile: Profile
}) {
const api = new Api(profile.api_key)
const [functionCalls, setFunctionCalls] = React.useState<any[]>()

const [isLoading, setIsLoading] = React.useState<boolean>(false)
const [selectedView, setSelectedView] = React.useState<"chat" | "trace">(
"chat"
Expand Down Expand Up @@ -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 = ""

Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -188,6 +217,23 @@ export default function Chat({
>
{timer.toFixed(1)}s
</p>

<div className="absolute right-0 z-50 flex items-center space-x-2 px-6 py-4">
{functionCalls && functionCalls.length > 0 && (
<Popover>
<PopoverTrigger>
<Badge variant="secondary" className="space-x-1">
<TbBolt className="text-lg text-green-400" />
<span className="font-mono">{functionCalls?.length}</span>
</Badge>
</PopoverTrigger>
<PopoverContent side="bottom">
<FunctionCalls functionCalls={functionCalls} />
</PopoverContent>
</Popover>
)}
</div>

{/*<div className="self-end">
<Select
value={selectedView}
Expand Down
7 changes: 6 additions & 1 deletion libs/ui/components/upload-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const UploadButton: FC<UploadButtonProps> = ({
onChange={handleFileChange}
accept={accept}
/>
<Button onClick={triggerFileInput} size="sm" variant="secondary">
<Button
type="button"
onClick={triggerFileInput}
size="sm"
variant="secondary"
>
{isLoading ? <Spinner /> : label}
</Button>
</>
Expand Down