Skip to content

Commit

Permalink
feat: add section for optional user tools in agent edit form
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Hopper-Lowe <[email protected]>
  • Loading branch information
ryanhopperlowe committed Nov 1, 2024
1 parent 60da0eb commit ad2e62e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 273 deletions.
51 changes: 0 additions & 51 deletions ui/admin/app/components/Typography.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { VariantProps, cva } from "class-variance-authority";
import React, { ReactNode } from "react";

import { cn } from "~/lib/utils";
Expand Down Expand Up @@ -183,53 +182,3 @@ export function TypographyMuted({
</p>
);
}

const typographyVariants = cva(`scroll-m-20`, {
variants: {
variant: {
h1: `text-4xl font-extrabold tracking-tight lg:text-5xl`,
h2: `text-3xl font-semibold tracking-tight first:mt-0`,
h3: `text-2xl font-semibold tracking-tight`,
h4: `text-xl font-semibold tracking-tight`,
p: `leading-7`,
blockquote: `mt-6 border-l-2 pl-6 italic`,
inlineCode: `relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold`,
lead: `text-xl text-muted-foreground`,
large: `text-lg font-semibold`,
small: `text-sm font-medium leading-none`,
muted: `text-sm text-muted-foreground`,
},
},
defaultVariants: {
variant: `p`,
},
});

const componentMap: Record<
Required<VariantProps<typeof typographyVariants>>["variant"],
TypographyElement
> = {
h1: `h1`,
h2: `h2`,
h3: `h3`,
h4: `h4`,
p: `p`,
blockquote: `blockquote`,
inlineCode: `code`,
lead: `p`,
large: `div`,
small: `small`,
muted: `p`,
};

export function Typography({
variant,
className,
...props
}: TypographyProps<TypographyElement> &
VariantProps<typeof typographyVariants>) {
return React.createElement(variantConfig, {
className: cn(variantConfig, className),
...props,
});
}
75 changes: 4 additions & 71 deletions ui/admin/app/components/agent/ToolEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { TrashIcon } from "lucide-react";
import { useEffect } from "react";
import { useForm } from "react-hook-form";
import useSWR from "swr";
import { z } from "zod";

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

import { TruncatedText } from "../TruncatedText";
import { ToolIcon } from "../tools/ToolIcon";
import { LoadingSpinner } from "../ui/LoadingSpinner";
import { Button } from "../ui/button";
import { Form, FormField, FormItem, FormMessage } from "../ui/form";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "../ui/select";
import { TruncatedText } from "~/components/TruncatedText";
import { ToolIcon } from "~/components/tools/ToolIcon";
import { LoadingSpinner } from "~/components/ui/LoadingSpinner";
import { Button } from "~/components/ui/button";

export function ToolEntry({
tool,
Expand Down Expand Up @@ -68,58 +56,3 @@ export function ToolEntry({
</div>
);
}

const schema = z.object({
variant: z.enum(["fixed", "default", "canAdd"]),
});

type ToolEntryForm = z.infer<typeof schema>;

function ToolEntryForm({
onChange,
}: {
onChange: (data: ToolEntryForm) => void;
}) {
const form = useForm<ToolEntryForm>({
resolver: zodResolver(schema),
defaultValues: {
variant: "default",
},
});

useEffect(() => {
return form.watch((values) => {
const { success, data } = schema.safeParse(values);

if (!success) return;

onChange(data);
}).unsubscribe;
}, [form, onChange]);

return (
<Form {...form}>
<FormField
control={form.control}
name="variant"
render={({ field: { ref: _, ...field } }) => (
<FormItem>
<Select {...field} onValueChange={field.onChange}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>

<SelectContent>
<SelectItem value="fixed">Fixed</SelectItem>
<SelectItem value="default">Default</SelectItem>
<SelectItem value="canAdd">Can Add</SelectItem>
</SelectContent>
</Select>

<FormMessage />
</FormItem>
)}
/>
</Form>
);
}
Loading

0 comments on commit ad2e62e

Please sign in to comment.