Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add icon and friendly name for tools #304

Merged
merged 1 commit into from
Oct 25, 2024
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
47 changes: 47 additions & 0 deletions ui/admin/app/components/agent/ToolEntry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { TrashIcon } from "lucide-react";
import useSWR from "swr";

import { ToolReferenceService } from "~/lib/service/api/toolreferenceService";

import { ToolIcon } from "../tools/ToolIcon";
import { LoadingSpinner } from "../ui/LoadingSpinner";
import { Button } from "../ui/button";

export function ToolEntry({
tool,
onDelete,
}: {
tool: string;
onDelete: () => void;
}) {
const { data: toolReference, isLoading } = useSWR(
ToolReferenceService.getToolReferenceById.key(tool),
({ toolReferenceId }) =>
ToolReferenceService.getToolReferenceById(toolReferenceId)
);

return (
<div className="flex items-center space-x-2 justify-between mt-1">
<div className="border text-sm px-3 shadow-sm rounded-md p-2 w-full flex items-center gap-2">
{isLoading ? (
<LoadingSpinner className="w-4 h-4" />
) : (
<ToolIcon
className="w-4 h-4"
name={toolReference?.name || tool}
icon={toolReference?.metadata?.icon}
/>
)}
{toolReference?.name || tool}
</div>
<Button
type="button"
variant="secondary"
size="icon"
onClick={() => onDelete()}
>
<TrashIcon className="w-4 h-4" />
</Button>
</div>
);
}
38 changes: 15 additions & 23 deletions ui/admin/app/components/agent/ToolForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { PlusIcon, TrashIcon } from "lucide-react";
import { PlusIcon } from "lucide-react";
import { useCallback, useEffect } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand All @@ -23,6 +23,8 @@ import {
PopoverTrigger,
} from "~/components/ui/popover";

import { ToolEntry } from "./ToolEntry";

const formSchema = z.object({
tools: z.array(z.string()),
});
Expand Down Expand Up @@ -83,28 +85,18 @@ export function ToolForm({

<div className="mt-2 w-full">
{field.value?.map((tool, index) => (
<div
key={index}
className="flex items-center space-x-2 justify-between mt-1"
>
<div className="border text-sm px-3 shadow-sm rounded-md p-2 w-full">
{tool}
</div>
<Button
type="button"
variant="destructive"
size="icon"
onClick={() => {
const newTools =
field.value?.filter(
(_, i) => i !== index
);
field.onChange(newTools);
}}
>
<TrashIcon className="w-4 h-4" />
</Button>
</div>
<ToolEntry
key={tool}
tool={tool}
onDelete={() => {
const newTools =
field.value?.filter(
(_, i) => i !== index
);

field.onChange(newTools);
}}
/>
))}
</div>
<div className="flex justify-end w-full my-4">
Expand Down