-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathfindSymbolDefinitionsToolComponent.tsx
More file actions
61 lines (56 loc) · 2.54 KB
/
findSymbolDefinitionsToolComponent.tsx
File metadata and controls
61 lines (56 loc) · 2.54 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
'use client';
import { FindSymbolDefinitionsToolUIPart } from "@/features/chat/tools";
import { useMemo, useState } from "react";
import { FileListItem, ToolHeader, TreeList } from "./shared";
import { CodeSnippet } from "@/app/components/codeSnippet";
import { Separator } from "@/components/ui/separator";
import { BookOpenIcon } from "lucide-react";
export const FindSymbolDefinitionsToolComponent = ({ part }: { part: FindSymbolDefinitionsToolUIPart }) => {
const [isExpanded, setIsExpanded] = useState(false);
const label = useMemo(() => {
switch (part.state) {
case 'input-streaming':
return 'Resolving definition...';
case 'input-available':
return <span>Resolving definition for <CodeSnippet>{part.input.symbol}</CodeSnippet></span>;
case 'output-error':
return '"Find symbol definitions" tool call failed';
case 'output-available':
return <span>Resolved definition for <CodeSnippet>{part.input.symbol}</CodeSnippet></span>;
}
}, [part]);
return (
<div className="my-4">
<ToolHeader
isLoading={part.state !== 'output-available' && part.state !== 'output-error'}
isError={part.state === 'output-error'}
isExpanded={isExpanded}
label={label}
Icon={BookOpenIcon}
onExpand={setIsExpanded}
input={part.state !== 'input-streaming' ? JSON.stringify(part.input) : undefined}
output={part.state === 'output-available' ? part.output.output : undefined}
/>
{part.state === 'output-available' && isExpanded && (
<>
{part.output.metadata.files.length === 0 ? (
<span className="text-sm text-muted-foreground ml-[25px]">No matches found</span>
) : (
<TreeList>
{part.output.metadata.files.map((file) => {
return (
<FileListItem
key={file.fileName}
path={file.fileName}
repoName={file.repo}
/>
)
})}
</TreeList>
)}
<Separator className='ml-[7px] my-2' />
</>
)}
</div>
)
}