-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a pretty substantial overhaul of the agent edit UX. The main changes are: - A new "Advanced" tab that allows you to edit the prompt - The name and description now look like contentEditable fields (they're not, but they act like them) - The edit agent page has moved the "go back" button to the header - New "Knowledge" suggestion for preview chats - Updated "restart chat" button to be "new thread" along with a companion button to select past threads - Accordion options now have color, descriptions, and larger text. - New Agents now have a name of "New Agent" instead of the fun random names they used to have. Signed-off-by: tylerslaton <[email protected]>
- Loading branch information
1 parent
5e4d6d5
commit 6fef2d2
Showing
13 changed files
with
426 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import { useEffect } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { z } from "zod"; | ||
|
||
import { Agent } from "~/lib/model/agents"; | ||
|
||
import { ControlledTextarea } from "~/components/form/controlledInputs"; | ||
import { Form } from "~/components/ui/form"; | ||
|
||
const formSchema = z.object({ | ||
prompt: z.string().optional(), | ||
}); | ||
|
||
export type AdvancedFormValues = z.infer<typeof formSchema>; | ||
|
||
type AdvancedFormProps = { | ||
agent: Agent; | ||
onSubmit?: (values: AdvancedFormValues) => void; | ||
onChange?: (values: AdvancedFormValues) => void; | ||
}; | ||
|
||
export function AdvancedForm({ agent, onSubmit, onChange }: AdvancedFormProps) { | ||
const form = useForm<AdvancedFormValues>({ | ||
resolver: zodResolver(formSchema), | ||
mode: "onChange", | ||
defaultValues: { | ||
prompt: agent.prompt || "", | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
if (agent) form.reset({ prompt: agent.prompt || "" }); | ||
}, [agent, form]); | ||
|
||
useEffect(() => { | ||
return form.watch((values) => { | ||
if (!onChange) return; | ||
|
||
const { data, success } = formSchema.safeParse(values); | ||
|
||
if (!success) return; | ||
|
||
onChange(data); | ||
}).unsubscribe; | ||
}, [onChange, form]); | ||
|
||
const handleSubmit = form.handleSubmit((values: AdvancedFormValues) => | ||
onSubmit?.({ ...values }) | ||
); | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={handleSubmit} className="space-y-8"> | ||
<ControlledTextarea | ||
control={form.control} | ||
name="prompt" | ||
label="Additional Instructions" | ||
description="Give the agent additional instructions on how it should behave." | ||
placeholder="Talk like a pirate." | ||
/> | ||
</form> | ||
</Form> | ||
); | ||
} |
Oops, something went wrong.