forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-rendering.tsx
More file actions
68 lines (61 loc) · 2.31 KB
/
Copy pathtool-rendering.tsx
File metadata and controls
68 lines (61 loc) · 2.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use client";
import { useEffect, useRef } from "react";
interface ToolReasoningProps {
name: string;
args?: object | unknown;
status: string;
}
const statusIndicator = {
executing: (
<span className="inline-block h-3 w-3 rounded-full border-2 border-gray-400 border-t-transparent animate-spin" />
),
inProgress: (
<span className="inline-block h-3 w-3 rounded-full border-2 border-gray-400 border-t-transparent animate-spin" />
),
complete: <span className="text-green-500 text-xs">✓</span>,
};
function formatValue(value: unknown): string {
if (Array.isArray(value)) return `[${value.length} items]`;
if (typeof value === "object" && value !== null)
return `{${Object.keys(value).length} keys}`;
if (typeof value === "string") return `"${value}"`;
return String(value);
}
export function ToolReasoning({ name, args, status }: ToolReasoningProps) {
const entries = args ? Object.entries(args) : [];
const detailsRef = useRef<HTMLDetailsElement>(null);
const toolStatus = status as "complete" | "inProgress" | "executing";
// Auto-open while executing, auto-close when complete
useEffect(() => {
if (!detailsRef.current) return;
detailsRef.current.open = status === "executing";
}, [status]);
return (
<div className="my-2 text-sm">
{entries.length > 0 ? (
<details ref={detailsRef} open>
<summary className="flex items-center gap-2 text-gray-600 dark:text-gray-400 cursor-pointer list-none">
{statusIndicator[toolStatus]}
<span className="font-medium">{name}</span>
<span className="text-[10px]">▼</span>
</summary>
<div className="pl-5 mt-1 space-y-1 text-xs text-gray-500 dark:text-zinc-400">
{entries.map(([key, value]) => (
<div key={key} className="flex gap-2 min-w-0">
<span className="font-medium shrink-0">{key}:</span>
<span className="text-gray-600 dark:text-gray-400 truncate">
{formatValue(value)}
</span>
</div>
))}
</div>
</details>
) : (
<div className="flex items-center gap-2 text-gray-600 dark:text-gray-400">
{statusIndicator[toolStatus]}
<span className="font-medium">{name}</span>
</div>
)}
</div>
);
}