AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(builder): Importing/exporting Agents and Templates (#7466)
Reinier van der Leer8264d7bf5ae4
diff --git a/rnd/autogpt_builder/package.json b/rnd/autogpt_builder/package.jsonindex ed4627ad1d..193237724c 100644--- a/rnd/autogpt_builder/package.json+++ b/rnd/autogpt_builder/package.json@@ -9,11 +9,15 @@"lint": "next lint"},"dependencies": {+ "@hookform/resolvers": "^3.9.0","@radix-ui/react-avatar": "^1.1.0",+ "@radix-ui/react-dialog": "^1.1.1","@radix-ui/react-dropdown-menu": "^2.1.1","@radix-ui/react-icons": "^1.3.0",+ "@radix-ui/react-label": "^2.1.0","@radix-ui/react-popover": "^1.1.1","@radix-ui/react-slot": "^1.1.0",+ "@radix-ui/react-switch": "^1.1.0","@radix-ui/react-tooltip": "^1.1.2","class-variance-authority": "^0.7.0","clsx": "^2.1.1",@@ -26,12 +30,14 @@"react": "^18","react-day-picker": "^8.10.1","react-dom": "^18",+ "react-hook-form": "^7.52.1","react-markdown": "^9.0.1","react-modal": "^3.16.1","reactflow": "^11.11.4","recharts": "^2.12.7","tailwind-merge": "^2.3.0",- "tailwindcss-animate": "^1.0.7"+ "tailwindcss-animate": "^1.0.7",+ "zod": "^3.23.8"},"devDependencies": {"@types/node": "^20",diff --git a/rnd/autogpt_builder/src/app/build/page.tsx b/rnd/autogpt_builder/src/app/build/page.tsxindex 895cb07323..3c667a2007 100644--- a/rnd/autogpt_builder/src/app/build/page.tsx+++ b/rnd/autogpt_builder/src/app/build/page.tsx@@ -4,6 +4,8 @@ import { useSearchParams } from "next/navigation";import FlowEditor from '@/components/Flow';export default function Home() {+ const query = useSearchParams();+return (<div className="flex flex-col items-center px-12"><div className="z-10 w-full items-center justify-between font-mono text-sm lg:flex">@@ -35,7 +37,8 @@ export default function Home() {<div className="w-full flex justify-center mt-10"><FlowEditorclassName="flow-container w-full min-h-[75vh] border border-gray-300 dark:border-gray-700 rounded-lg"- flowID={useSearchParams().get("flowID") ?? undefined}+ flowID={query.get("flowID") ?? query.get("templateID") ?? undefined}+ template={!!query.get("templateID")}/></div></div>diff --git a/rnd/autogpt_builder/src/app/monitor/page.tsx b/rnd/autogpt_builder/src/app/monitor/page.tsxindex f1bdf00e55..7666e5c6d4 100644--- a/rnd/autogpt_builder/src/app/monitor/page.tsx+++ b/rnd/autogpt_builder/src/app/monitor/page.tsx@@ -16,21 +16,24 @@ import {import {DropdownMenu,DropdownMenuContent,+ DropdownMenuItem,DropdownMenuLabel,DropdownMenuRadioGroup,DropdownMenuRadioItem,DropdownMenuSeparator,DropdownMenuTrigger,} from "@/components/ui/dropdown-menu"-import { ClockIcon, Pencil2Icon } from '@radix-ui/react-icons';-import AutoGPTServerAPI, { Graph, NodeExecutionResult } from '@/lib/autogpt_server_api';-import { cn, hashString } from '@/lib/utils';+import { ChevronDownIcon, ClockIcon, EnterIcon, ExitIcon, Pencil2Icon } from '@radix-ui/react-icons';+import AutoGPTServerAPI, { Graph, GraphMeta, NodeExecutionResult } from '@/lib/autogpt_server_api';+import { cn, exportAsJSONFile, hashString } from '@/lib/utils';import { Badge } from "@/components/ui/badge";import { Button, buttonVariants } from "@/components/ui/button";import { Calendar } from "@/components/ui/calendar";import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { Dialog, DialogContent, DialogHeader, DialogTrigger } from '@/components/ui/dialog';import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";+import { AgentImportForm } from '@/components/agent-import-form';const Monitor = () => {const [flows, setFlows] = useState<Graph[]>([]);@@ -205,11 +208,65 @@ const AgentFlowList = (onSelectFlow: (f: Graph) => void,className?: string,}-) => (- <Card className={className}>- <CardHeader>+) => {+ const [templates, setTemplates] = useState<GraphMeta[]>([]);+ const api = new AutoGPTServerAPI();+ useEffect(() => {+ api.listTemplates().then(templates => setTemplates(templates))+ }, []);++ return <Card className={className}>+ <CardHeader className="flex-row justify-between items-center space-x-3 space-y-0"><CardTitle>Agents</CardTitle>++ <div className="flex items-center">{/* Split "Create" button */}+ <Button variant="outline" className="rounded-r-none" asChild>+ <Link href="/build">Create</Link>+ </Button>+ <Dialog>{/* https://ui.shadcn.com/docs/components/dialog#notes */}+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="outline" className={"rounded-l-none border-l-0 px-2"}>+ <ChevronDownIcon />+ </Button>+ </DropdownMenuTrigger>++ <DropdownMenuContent>+ <DialogTrigger asChild>+ <DropdownMenuItem>+ <EnterIcon className="mr-2" /> Import from file+ </DropdownMenuItem>+ </DialogTrigger>+ {templates.length > 0 && <>{/* List of templates */}+ <DropdownMenuSeparator />+ <DropdownMenuLabel>Use a template</DropdownMenuLabel>+ {templates.map(template => (+ <DropdownMenuItem+ key={template.id}+ onClick={() => {+ api.createGraph(template.id, template.version)+ .then(newGraph => {+ window.location.href = `/build?flowID=${newGraph.id}`;+ });+ }}+ >+ {template.name}+ </DropdownMenuItem>+ ))}+ </>}+ </DropdownMenuContent>+ </DropdownMenu>++ <DialogContent>+ <DialogHeader className="text-lg">+ Import an Agent (template) from a file+ </DialogHeader>+ <AgentImportForm />+ </DialogContent>+ </Dialog>+ </div></CardHeader>+<CardContent><Table><TableHeader>@@ -264,7 +321,7 @@ const AgentFlowList = (</Table></CardContent></Card>-);+};const FlowStatusBadge = ({ status }: { status: "active" | "disabled" | "failing" }) => (<Badge@@ -390,6 +447,14 @@ const FlowInfo: React.FC<{<Link className={buttonVariants({ variant: "outline" })} href={`/build?flowID=${flow.id}`}><Pencil2Icon className="mr-2" /> Edit</Link>+ <Button+ variant="outline"+ className="px-2.5"+ title="Export to a JSON-file"+ onClick={() => exportAsJSONFile(flow, `${flow.name}_v${flow.version}.json`)}+ >+ <ExitIcon />+ </Button></div></CardHeader><CardContent>diff --git a/rnd/autogpt_builder/src/components/Flow.tsx b/rnd/autogpt_builder/src/components/Flow.tsxindex 7532525039..190076b84e 100644--- a/rnd/autogpt_builder/src/components/Flow.tsx+++ b/rnd/autogpt_builder/src/components/Flow.tsx@@ -68,10 +68,11 @@ const Sidebar: React.FC<{ isOpen: boolean, availableNodes: Block[], addNode: (id);};-const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({- flowID,- className,-}) => {+const FlowEditor: React.FC<{+ flowID?: string;+ template?: boolean;+ className?: string;+}> = ({ flowID, template, className }) => {const [nodes, setNodes] = useState<Node<CustomNodeData>[]>([]);const [edges, setEdges] = useState<Edge[]>([]);const [nodeId, setNodeId] = useState<number>(1);@@ -111,9 +112,9 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({useEffect(() => {if (!flowID || availableNodes.length == 0) return;- api.getGraph(flowID)+ (template ? api.getTemplate(flowID) : api.getGraph(flowID)).then(graph => loadGraph(graph));- }, [flowID, availableNodes]);+ }, [flowID, template, availableNodes]);const nodeTypes: NodeTypes = useMemo(() => ({ custom: CustomNode }), []);@@ -292,7 +293,7 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({return inputData;};- const saveAgent = async () => {+ async function saveAgent (asTemplate: boolean = false) {setNodes((nds) =>nds.map((node) => ({...node,@@ -359,8 +360,12 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({}const newSavedAgent = savedAgent- ? await api.updateGraph(savedAgent.id, payload)- : await api.createGraph(payload);+ ? await (savedAgent.is_template+ ? api.updateTemplate(savedAgent.id, payload)+ : api.updateGraph(savedAgent.id, payload))+ : await (asTemplate+ ? api.createTemplate(payload)+ : api.createGraph(payload));console.debug('Response from the API:', newSavedAgent);setSavedAgent(newSavedAgent);@@ -467,8 +472,15 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({onChange={(e) => setAgentDescription(e.target.value)}/><div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}> {/* Added gap for spacing */}- <Button onClick={saveAgent}>Save Agent</Button>- <Button onClick={runAgent}>Save & Run Agent</Button>+ <Button onClick={() => saveAgent(savedAgent?.is_template)}>+ Save {savedAgent?.is_template ? "Template" : "Agent"}+ </Button>+ {!savedAgent?.is_template &&+ <Button onClick={runAgent}>Save & Run Agent</Button>+ }+ {!savedAgent &&+ <Button onClick={() => saveAgent(true)}>Save as Template</Button>+ }</div></div></ReactFlow>diff --git a/rnd/autogpt_builder/src/components/agent-import-form.tsx b/rnd/autogpt_builder/src/components/agent-import-form.tsxnew file mode 100644index 0000000000..5d4ba1b863--- /dev/null+++ b/rnd/autogpt_builder/src/components/agent-import-form.tsx@@ -0,0 +1,180 @@+import { z } from "zod"+import { useForm } from "react-hook-form"+import { zodResolver } from "@hookform/resolvers/zod"+import React, { useState } from "react"+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/components/ui/form"+import { Input } from "@/components/ui/input"+import { Button } from "@/components/ui/button"+import { Switch } from "@/components/ui/switch"+import { Textarea } from "@/components/ui/textarea"+import AutoGPTServerAPI, { Graph, GraphCreatable } from "@/lib/autogpt_server_api"+import { cn } from "@/lib/utils"+import { EnterIcon } from "@radix-ui/react-icons"+++const formSchema = z.object({+ agentFile: z.instanceof(File),+ agentName: z.string().min(1, "Agent name is required"),+ agentDescription: z.string(),+ importAsTemplate: z.boolean(),+})++export const AgentImportForm: React.FC<React.FormHTMLAttributes<HTMLFormElement>> = (+ { className, ...props }+) => {+ const [agentObject, setAgentObject] = useState<GraphCreatable | null>(null)+ const api = new AutoGPTServerAPI()++ const form = useForm<z.infer<typeof formSchema>>({+ resolver: zodResolver(formSchema),+ defaultValues: {+ agentName: "",+ agentDescription: "",+ importAsTemplate: false,+ },+ })++ function onSubmit(values: z.infer<typeof formSchema>) {+ if (!agentObject) {+ form.setError("root", { message: "No Agent object to save" })+ return+ }+ const payload: GraphCreatable = {+ ...agentObject,+ name: values.agentName,+ description: values.agentDescription,+ is_active: !values.importAsTemplate,+ is_template: values.importAsTemplate,+ };++ (values.importAsTemplate ? api.createTemplate(payload) : api.createGraph(payload))+ .then((response) => {+ const qID = values.importAsTemplate ? "templateID" : "flowID";+ window.location.href = `/build?${qID}=${response.id}`;+ })+ .catch(error => {+ const entity_type = values.importAsTemplate ? 'template' : 'agent';+ form.setError("root", { message: `Could not create ${entity_type}: ${error}` });+ })+ }++ return (+ <Form {...form}>+ <form+ onSubmit={form.handleSubmit(onSubmit)}+ className={cn("space-y-4", className)}+ {...props}+ >+ <FormField+ control={form.control}+ name="agentFile"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Agent file</FormLabel>+ <FormControl className="cursor-pointer">+ <Input+ type="file"+ accept="application/json"+ onChange={(e) => {+ const file = e.target.files?.[0];+ if (file) {+ field.onChange(file)+ const reader = new FileReader();+ // Attach parser to file reader+ reader.onload = (event) => {+ try {+ const obj = JSON.parse(+ event.target?.result as string+ );+ if (+ !["name", "description", "nodes", "links"]+ .every(key => !!obj[key])+ ) {+ throw new Error(+ "Invalid agent object in file: "+ + JSON.stringify(obj, null, 2)+ );+ }+ const agent = obj as Graph;+ setAgentObject(agent);+ form.setValue("agentName", agent.name);+ form.setValue("agentDescription", agent.description);+ form.setValue("importAsTemplate", agent.is_template);+ } catch (error) {+ console.error("Error loading agent file:", error);+ }+ };+ // Load file+ reader.readAsText(file);+ }+ }}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="agentName"+ disabled={!agentObject}+ render={({ field }) => (+ <FormItem>+ <FormLabel>Agent name</FormLabel>+ <FormControl>+ <Input {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="agentDescription"+ disabled={!agentObject}+ render={({ field }) => (+ <FormItem>+ <FormLabel>Agent description</FormLabel>+ <FormControl>+ <Textarea {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="importAsTemplate"+ disabled={!agentObject}+ render={({ field }) => (+ <FormItem>+ <FormLabel>Import as</FormLabel>+ <FormControl>+ <div className="flex space-x-2 items-center">+ <span className={field.value ? "text-gray-400 dark:text-gray-600" : ""}>Agent</span>+ <Switch+ disabled={field.disabled}+ checked={field.value}+ onCheckedChange={field.onChange}+ />+ <span className={field.value ? "" : "text-gray-400 dark:text-gray-600"}>Template</span>+ </div>+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <Button type="submit" className="w-full" disabled={!agentObject}>+ <EnterIcon className="mr-2" /> Import & Edit+ </Button>+ </form>+ </Form>+ )+}diff --git a/rnd/autogpt_builder/src/components/ui/dialog.tsx b/rnd/autogpt_builder/src/components/ui/dialog.tsxnew file mode 100644index 0000000000..eca43bfe16--- /dev/null+++ b/rnd/autogpt_builder/src/components/ui/dialog.tsx@@ -0,0 +1,122 @@+"use client"++import * as React from "react"+import * as DialogPrimitive from "@radix-ui/react-dialog"+import { Cross2Icon } from "@radix-ui/react-icons"++import { cn } from "@/lib/utils"++const Dialog = DialogPrimitive.Root++const DialogTrigger = DialogPrimitive.Trigger++const DialogPortal = DialogPrimitive.Portal++const DialogClose = DialogPrimitive.Close++const DialogOverlay = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Overlay>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>+>(({ className, ...props }, ref) => (+ <DialogPrimitive.Overlay+ ref={ref}+ className={cn(+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",+ className+ )}+ {...props}+ />+))+DialogOverlay.displayName = DialogPrimitive.Overlay.displayName++const DialogContent = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>+>(({ className, children, ...props }, ref) => (+ <DialogPortal>+ <DialogOverlay />+ <DialogPrimitive.Content+ ref={ref}+ className={cn(+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-neutral-800 dark:bg-neutral-950",+ className+ )}+ {...props}+ >+ {children}+ <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-neutral-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-neutral-100 data-[state=open]:text-neutral-500 dark:ring-offset-neutral-950 dark:focus:ring-neutral-300 dark:data-[state=open]:bg-neutral-800 dark:data-[state=open]:text-neutral-400">+ <Cross2Icon className="h-4 w-4" />+ <span className="sr-only">Close</span>+ </DialogPrimitive.Close>+ </DialogPrimitive.Content>+ </DialogPortal>+))+DialogContent.displayName = DialogPrimitive.Content.displayName++const DialogHeader = ({+ className,+ ...props+}: React.HTMLAttributes<HTMLDivElement>) => (+ <div+ className={cn(+ "flex flex-col space-y-1.5 text-center sm:text-left",+ className+ )}+ {...props}+ />+)+DialogHeader.displayName = "DialogHeader"++const DialogFooter = ({+ className,+ ...props+}: React.HTMLAttributes<HTMLDivElement>) => (+ <div+ className={cn(+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",+ className+ )}+ {...props}+ />+)+DialogFooter.displayName = "DialogFooter"++const DialogTitle = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Title>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>+>(({ className, ...props }, ref) => (+ <DialogPrimitive.Title+ ref={ref}+ className={cn(+ "text-lg font-semibold leading-none tracking-tight",+ className+ )}+ {...props}+ />+))+DialogTitle.displayName = DialogPrimitive.Title.displayName++const DialogDescription = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Description>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>+>(({ className, ...props }, ref) => (+ <DialogPrimitive.Description+ ref={ref}+ className={cn("text-sm text-neutral-500 dark:text-neutral-400", className)}+ {...props}+ />+))+DialogDescription.displayName = DialogPrimitive.Description.displayName++export {+ Dialog,+ DialogPortal,+ DialogOverlay,+ DialogTrigger,+ DialogClose,+ DialogContent,+ DialogHeader,+ DialogFooter,+ DialogTitle,+ DialogDescription,+}diff --git a/rnd/autogpt_builder/src/components/ui/dropdown-menu.tsx b/rnd/autogpt_builder/src/components/ui/dropdown-menu.tsxindex 9972335523..4681fc0ff9 100644--- a/rnd/autogpt_builder/src/components/ui/dropdown-menu.tsx+++ b/rnd/autogpt_builder/src/components/ui/dropdown-menu.tsx@@ -88,7 +88,7 @@ const DropdownMenuItem = React.forwardRef<<DropdownMenuPrimitive.Itemref={ref}className={cn(- "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-neutral-100 focus:text-neutral-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",+ "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-neutral-100 focus:text-neutral-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",inset && "pl-8",className)}@@ -104,7 +104,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<<DropdownMenuPrimitive.CheckboxItemref={ref}className={cn(- "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-neutral-100 focus:text-neutral-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",+ "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-neutral-100 focus:text-neutral-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",className)}checked={checked}diff --git a/rnd/autogpt_builder/src/components/ui/form.tsx b/rnd/autogpt_builder/src/components/ui/form.tsxnew file mode 100644index 0000000000..cef40bd96d--- /dev/null+++ b/rnd/autogpt_builder/src/components/ui/form.tsx@@ -0,0 +1,178 @@+"use client"++import * as React from "react"+import * as LabelPrimitive from "@radix-ui/react-label"+import { Slot } from "@radix-ui/react-slot"+import {+ Controller,+ ControllerProps,+ FieldPath,+ FieldValues,+ FormProvider,+ useFormContext,+} from "react-hook-form"++import { cn } from "@/lib/utils"+import { Label } from "@/components/ui/label"++const Form = FormProvider++type FormFieldContextValue<+ TFieldValues extends FieldValues = FieldValues,+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>+> = {+ name: TName+}++const FormFieldContext = React.createContext<FormFieldContextValue>(+ {} as FormFieldContextValue+)++const FormField = <+ TFieldValues extends FieldValues = FieldValues,+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>+>({+ ...props+}: ControllerProps<TFieldValues, TName>) => {+ return (+ <FormFieldContext.Provider value={{ name: props.name }}>+ <Controller {...props} />+ </FormFieldContext.Provider>+ )+}++const useFormField = () => {+ const fieldContext = React.useContext(FormFieldContext)+ const itemContext = React.useContext(FormItemContext)+ const { getFieldState, formState } = useFormContext()++ const fieldState = getFieldState(fieldContext.name, formState)++ if (!fieldContext) {+ throw new Error("useFormField should be used within <FormField>")+ }++ const { id } = itemContext++ return {+ id,+ name: fieldContext.name,+ formItemId: `${id}-form-item`,+ formDescriptionId: `${id}-form-item-description`,+ formMessageId: `${id}-form-item-message`,+ ...fieldState,+ }+}++type FormItemContextValue = {+ id: string+}++const FormItemContext = React.createContext<FormItemContextValue>(+ {} as FormItemContextValue+)++const FormItem = React.forwardRef<+ HTMLDivElement,+ React.HTMLAttributes<HTMLDivElement>+>(({ className, ...props }, ref) => {+ const id = React.useId()++ return (+ <FormItemContext.Provider value={{ id }}>+ <div ref={ref} className={cn("space-y-2", className)} {...props} />+ </FormItemContext.Provider>+ )+})+FormItem.displayName = "FormItem"++const FormLabel = React.forwardRef<+ React.ElementRef<typeof LabelPrimitive.Root>,+ React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>+>(({ className, ...props }, ref) => {+ const { error, formItemId } = useFormField()++ return (+ <Label+ ref={ref}+ className={cn(error && "text-red-500 dark:text-red-900", className)}+ htmlFor={formItemId}+ {...props}+ />+ )+})+FormLabel.displayName = "FormLabel"++const FormControl = React.forwardRef<+ React.ElementRef<typeof Slot>,+ React.ComponentPropsWithoutRef<typeof Slot>+>(({ ...props }, ref) => {+ const { error, formItemId, formDescriptionId, formMessageId } = useFormField()++ return (+ <Slot+ ref={ref}+ id={formItemId}+ aria-describedby={+ !error+ ? `${formDescriptionId}`+ : `${formDescriptionId} ${formMessageId}`+ }+ aria-invalid={!!error}+ {...props}+ />+ )+})+FormControl.displayName = "FormControl"++const FormDescription = React.forwardRef<+ HTMLParagraphElement,+ React.HTMLAttributes<HTMLParagraphElement>+>(({ className, ...props }, ref) => {+ const { formDescriptionId } = useFormField()++ return (+ <p+ ref={ref}+ id={formDescriptionId}+ className={cn("text-[0.8rem] text-neutral-500 dark:text-neutral-400", className)}+ {...props}+ />+ )+})+FormDescription.displayName = "FormDescription"++const FormMessage = React.forwardRef<+ HTMLParagraphElement,+ React.HTMLAttributes<HTMLParagraphElement>+>(({ className, children, ...props }, ref) => {+ const { error, formMessageId } = useFormField()+ const body = error ? String(error?.message) : children++ if (!body) {+ return null+ }++ return (+ <p+ ref={ref}+ id={formMessageId}+ className={cn("text-[0.8rem] font-medium text-red-500 dark:text-red-900", className)}+ {...props}+ >+ {body}+ </p>+ )+})+FormMessage.displayName = "FormMessage"++export {+ useFormField,+ Form,+ FormItem,+ FormLabel,+ FormControl,+ FormDescription,+ FormMessage,+ FormField,+}diff --git a/rnd/autogpt_builder/src/components/ui/input.tsx b/rnd/autogpt_builder/src/components/ui/input.tsxindex c8a3fc063e..2bdc268ca8 100644--- a/rnd/autogpt_builder/src/components/ui/input.tsx+++ b/rnd/autogpt_builder/src/components/ui/input.tsx@@ -12,6 +12,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(type={type}className={cn("flex h-9 w-full rounded-md border border-gray-200 bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-800 dark:placeholder:text-gray-400 dark:focus-visible:ring-gray-300",+ type == "file" ? "pt-1.5 pb-0.5" : "", // fix alignmentclassName)}ref={ref}diff --git a/rnd/autogpt_builder/src/components/ui/label.tsx b/rnd/autogpt_builder/src/components/ui/label.tsxnew file mode 100644index 0000000000..534182176b--- /dev/null+++ b/rnd/autogpt_builder/src/components/ui/label.tsx@@ -0,0 +1,26 @@+"use client"++import * as React from "react"+import * as LabelPrimitive from "@radix-ui/react-label"+import { cva, type VariantProps } from "class-variance-authority"++import { cn } from "@/lib/utils"++const labelVariants = cva(+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+)++const Label = React.forwardRef<+ React.ElementRef<typeof LabelPrimitive.Root>,+ React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &+ VariantProps<typeof labelVariants>+>(({ className, ...props }, ref) => (+ <LabelPrimitive.Root+ ref={ref}+ className={cn(labelVariants(), className)}+ {...props}+ />+))+Label.displayName = LabelPrimitive.Root.displayName++export { Label }diff --git a/rnd/autogpt_builder/src/components/ui/switch.tsx b/rnd/autogpt_builder/src/components/ui/switch.tsxnew file mode 100644index 0000000000..9f9cc0ce31--- /dev/null+++ b/rnd/autogpt_builder/src/components/ui/switch.tsx@@ -0,0 +1,29 @@+"use client"++import * as React from "react"+import * as SwitchPrimitives from "@radix-ui/react-switch"++import { cn } from "@/lib/utils"++const Switch = React.forwardRef<+ React.ElementRef<typeof SwitchPrimitives.Root>,+ React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>+>(({ className, ...props }, ref) => (+ <SwitchPrimitives.Root+ className={cn(+ "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-neutral-900 data-[state=unchecked]:bg-neutral-200 dark:focus-visible:ring-neutral-300 dark:focus-visible:ring-offset-neutral-950 dark:data-[state=checked]:bg-neutral-50 dark:data-[state=unchecked]:bg-neutral-800",+ className+ )}+ {...props}+ ref={ref}+ >+ <SwitchPrimitives.Thumb+ className={cn(+ "pointer-events-none block h-4 w-4 rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0 dark:bg-neutral-950"+ )}+ />+ </SwitchPrimitives.Root>+))+Switch.displayName = SwitchPrimitives.Root.displayName++export { Switch }diff --git a/rnd/autogpt_builder/src/lib/autogpt_server_api.ts b/rnd/autogpt_builder/src/lib/autogpt_server_api.tsindex 7f50e03584..509dc20850 100644--- a/rnd/autogpt_builder/src/lib/autogpt_server_api.ts+++ b/rnd/autogpt_builder/src/lib/autogpt_server_api.ts@@ -22,15 +22,28 @@ export default class AutoGPTServerAPI {return this._get("/graphs")}+ async listTemplates(): Promise<GraphMeta[]> {+ return this._get("/templates")+ }+async getGraph(id: string, version?: number): Promise<Graph> {const query = version !== undefined ? `?version=${version}` : "";return this._get(`/graphs/${id}` + query);}+ async getTemplate(id: string, version?: number): Promise<Graph> {+ const query = version !== undefined ? `?version=${version}` : "";+ return this._get(`/templates/${id}` + query);+ }+async getGraphAllVersions(id: string): Promise<Graph[]> {return this._get(`/graphs/${id}/versions`);}+ async getTemplateAllVersions(id: string): Promise<Graph[]> {+ return this._get(`/templates/${id}/versions`);+ }+async createGraph(graphCreateBody: GraphCreatable): Promise<Graph>;async createGraph(fromTemplateID: string, templateVersion: number): Promise<Graph>;async createGraph(@@ -53,10 +66,19 @@ export default class AutoGPTServerAPI {return this._request("POST", "/graphs", requestBody);}+ async createTemplate(templateCreateBody: GraphCreatable): Promise<Graph> {+ const requestBody: GraphCreateRequestBody = { graph: templateCreateBody };+ return this._request("POST", "/templates", requestBody);+ }+async updateGraph(id: string, graph: GraphUpdateable): Promise<Graph> {return await this._request("PUT", `/graphs/${id}`, graph);}+ async updateTemplate(id: string, template: GraphUpdateable): Promise<Graph> {+ return await this._request("PUT", `/templates/${id}`, template);+ }+async setGraphActiveVersion(id: string, version: number): Promise<Graph> {return this._request("PUT", `/graphs/${id}/versions/active`, { active_graph_version: version }diff --git a/rnd/autogpt_builder/src/lib/utils.ts b/rnd/autogpt_builder/src/lib/utils.tsindex 97ff7fcb23..3566a93135 100644--- a/rnd/autogpt_builder/src/lib/utils.ts+++ b/rnd/autogpt_builder/src/lib/utils.ts@@ -37,7 +37,7 @@ export function beautifyString(name: string): string {.replace(/([A-Z])([A-Z][a-z])/g, '$1 $2') // Add space between acronyms and next word.replace(/_/g, ' ') // Replace underscores with spaces.replace(/\b\w/g, char => char.toUpperCase()); // Capitalize the first letter of each word-+return applyExceptions(result);};@@ -60,3 +60,21 @@ const applyExceptions = (str: string): string => {});return str;};++export function exportAsJSONFile(obj: object, filename: string): void {+ // Create downloadable blob+ const jsonString = JSON.stringify(obj, null, 2);+ const blob = new Blob([jsonString], { type: 'application/json' });+ const url = URL.createObjectURL(blob);++ // Trigger the browser to download the blob to a file+ const link = document.createElement('a');+ link.href = url;+ link.download = filename;+ document.body.appendChild(link);+ link.click();+ document.body.removeChild(link);++ // Clean up+ URL.revokeObjectURL(url);+}diff --git a/rnd/autogpt_builder/yarn.lock b/rnd/autogpt_builder/yarn.lockindex e81d5fc4a8..fc24fc21fb 100644--- a/rnd/autogpt_builder/yarn.lock+++ b/rnd/autogpt_builder/yarn.lock@@ -73,6 +73,11 @@resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.4.tgz#1d459cee5031893a08a0e064c406ad2130cced7c"integrity sha512-dWO2pw8hhi+WrXq1YJy2yCuWoL20PddgGaqTgVe4cOS9Q6qklXCiA1tJEqX6BEwRNSCP84/afac9hd4MS+zEUA==+"@hookform/resolvers@^3.9.0":+ version "3.9.0"+ resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-3.9.0.tgz#cf540ac21c6c0cd24a40cf53d8e6d64391fb753d"+ integrity sha512-bU0Gr4EepJ/EQsH/IwEzYLsT/PEj5C0ynLQ4m+GSHS+xKH4TfSelhluTgOaoc4kA5s7eCsQbM4wvZLzELmWzUg==+"@humanwhocodes/config-array@^0.11.14":version "0.11.14"resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b"@@ -261,6 +266,26 @@resolved "https://registry.yarnpkg.com/@radix-ui/react-context/-/react-context-1.1.0.tgz#6df8d983546cfd1999c8512f3a8ad85a6e7fcee8"integrity sha512-OKrckBy+sMEgYM/sMmqmErVn0kZqrHPJze+Ql3DzYsDDp0hl0L62nx/2122/Bvps1qz645jlcu2tD9lrRSdf8A==+"@radix-ui/react-dialog@^1.1.1":+ version "1.1.1"+ resolved "https://registry.yarnpkg.com/@radix-ui/react-dialog/-/react-dialog-1.1.1.tgz#4906507f7b4ad31e22d7dad69d9330c87c431d44"+ integrity sha512-zysS+iU4YP3STKNS6USvFVqI4qqx8EpiwmT5TuCApVEBca+eRCbONi4EgzfNSuVnOXvC5UPHHMjs8RXO6DH9Bg==+ dependencies:+ "@radix-ui/primitive" "1.1.0"+ "@radix-ui/react-compose-refs" "1.1.0"+ "@radix-ui/react-context" "1.1.0"+ "@radix-ui/react-dismissable-layer" "1.1.0"+ "@radix-ui/react-focus-guards" "1.1.0"+ "@radix-ui/react-focus-scope" "1.1.0"+ "@radix-ui/react-id" "1.1.0"+ "@radix-ui/react-portal" "1.1.1"+ "@radix-ui/react-presence" "1.1.0"+ "@radix-ui/react-primitive" "2.0.0"+ "@radix-ui/react-slot" "1.1.0"+ "@radix-ui/react-use-controllable-state" "1.1.0"+ aria-hidden "^1.1.1"+ react-remove-scroll "2.5.7"+"@radix-ui/[email protected]":version "1.1.0"resolved "https://registry.yarnpkg.com/@radix-ui/react-direction/-/react-direction-1.1.0.tgz#a7d39855f4d077adc2a1922f9c353c5977a09cdc"@@ -316,6 +341,13 @@dependencies:"@radix-ui/react-use-layout-effect" "1.1.0"+"@radix-ui/react-label@^2.1.0":+ version "2.1.0"+ resolved "https://registry.yarnpkg.com/@radix-ui/react-label/-/react-label-2.1.0.tgz#3aa2418d70bb242be37c51ff5e51a2adcbc372e3"+ integrity sha512-peLblDlFw/ngk3UWq0VnYaOLy6agTZZ+MUO/WhVfm14vJGML+xH4FAl2XQGLqdefjNb7ApRg6Yn7U42ZhmYXdw==+ dependencies:+ "@radix-ui/react-primitive" "2.0.0"+"@radix-ui/[email protected]":version "2.1.1"resolved "https://registry.yarnpkg.com/@radix-ui/react-menu/-/react-menu-2.1.1.tgz#bd623ace0e1ae1ac78023a505fec0541d59fb346"@@ -422,6 +454,19 @@dependencies:"@radix-ui/react-compose-refs" "1.1.0"+"@radix-ui/react-switch@^1.1.0":+ version "1.1.0"+ resolved "https://registry.yarnpkg.com/@radix-ui/react-switch/-/react-switch-1.1.0.tgz#fcf8e778500f1d60d4b2bec2fc3fad77a7c118e3"+ integrity sha512-OBzy5WAj641k0AOSpKQtreDMe+isX0MQJ1IVyF03ucdF3DunOnROVrjWs8zsXUxC3zfZ6JL9HFVCUlMghz9dJw==+ dependencies:+ "@radix-ui/primitive" "1.1.0"+ "@radix-ui/react-compose-refs" "1.1.0"+ "@radix-ui/react-context" "1.1.0"+ "@radix-ui/react-primitive" "2.0.0"+ "@radix-ui/react-use-controllable-state" "1.1.0"+ "@radix-ui/react-use-previous" "1.1.0"+ "@radix-ui/react-use-size" "1.1.0"+"@radix-ui/react-tooltip@^1.1.2":version "1.1.2"resolved "https://registry.yarnpkg.com/@radix-ui/react-tooltip/-/react-tooltip-1.1.2.tgz#c42db2ffd7dcc6ff3d65407c8cb70490288f518d"@@ -464,6 +509,11 @@resolved "https://registry.yarnpkg.com/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.0.tgz#3c2c8ce04827b26a39e442ff4888d9212268bd27"integrity sha512-+FPE0rOdziWSrH9athwI1R0HDVbWlEhd+FR+aSDk4uWGmSJ9Z54sdZVDQPZAinJhJXwfT+qnj969mCsT2gfm5w==+"@radix-ui/[email protected]":+ version "1.1.0"+ resolved "https://registry.yarnpkg.com/@radix-ui/react-use-previous/-/react-use-previous-1.1.0.tgz#d4dd37b05520f1d996a384eb469320c2ada8377c"+ integrity sha512-Z/e78qg2YFnnXcW88A4JmTtm4ADckLno6F7OXotmkQfeuCVaKuYzqAATPhVzl3delXE7CxIV8shofPn3jPc5Og==+"@radix-ui/[email protected]":version "1.1.0"resolved "https://registry.yarnpkg.com/@radix-ui/react-use-rect/-/react-use-rect-1.1.0.tgz#13b25b913bd3e3987cc9b073a1a164bb1cf47b88"@@ -3471,6 +3521,11 @@ react-dom@^18:loose-envify "^1.1.0"scheduler "^0.23.2"+react-hook-form@^7.52.1:+ version "7.52.1"+ resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.52.1.tgz#ec2c96437b977f8b89ae2d541a70736c66284852"+ integrity sha512-uNKIhaoICJ5KQALYZ4TOaOLElyM+xipord+Ha3crEFhTntdLvWZqVY49Wqd/0GiVCA/f9NjemLeiNPjG7Hpurg==+react-is@^16.10.2, react-is@^16.13.1:version "16.13.1"resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"@@ -4392,6 +4447,11 @@ yocto-queue@^0.1.0:resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==+zod@^3.23.8:+ version "3.23.8"+ resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d"+ integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==+zustand@^4.4.1:version "4.5.4"resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.5.4.tgz#63abdd81edfb190bc61e0bbae045cc4d52158a05"diff --git a/rnd/autogpt_server/autogpt_server/data/graph.py b/rnd/autogpt_server/autogpt_server/data/graph.pyindex 929c3170b9..09ae4e981d 100644--- a/rnd/autogpt_server/autogpt_server/data/graph.py+++ b/rnd/autogpt_server/autogpt_server/data/graph.py@@ -264,7 +264,9 @@ async def create_graph(graph: Graph) -> Graph:])- if created_graph := await get_graph(graph.id, graph.version):+ if created_graph := await get_graph(+ graph.id, graph.version, template=graph.is_template+ ):return created_graph- raise ValueError(f"Failed to create graph {graph.id}:{graph.version}.")+ raise ValueError(f"Created graph {graph.id} v{graph.version} is not in DB")