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.
fix(builder/monitor): Fix `Graph` export (#7556)
Reinier van der Leerab0df04bfe19
diff --git a/rnd/autogpt_builder/src/app/monitor/page.tsx b/rnd/autogpt_builder/src/app/monitor/page.tsxindex 6452f064fc..7aebc6e831 100644--- a/rnd/autogpt_builder/src/app/monitor/page.tsx+++ b/rnd/autogpt_builder/src/app/monitor/page.tsx@@ -23,8 +23,13 @@ import {DropdownMenuSeparator,DropdownMenuTrigger,} from "@/components/ui/dropdown-menu"+import AutoGPTServerAPI, {+ Graph,+ GraphMeta,+ NodeExecutionResult,+ safeCopyGraph,+} from '@/lib/autogpt-server-api';import { ChevronDownIcon, ClockIcon, EnterIcon, ExitIcon, Pencil2Icon } from '@radix-ui/react-icons';-import AutoGPTServerAPI, { 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";@@ -400,8 +405,11 @@ const FlowInfo: React.FC<React.HTMLAttributes<HTMLDivElement> & {}> = ({ flow, flowRuns, flowVersion, ...props }) => {const api = new AutoGPTServerAPI();- const [flowVersions, setFlowVersions] = useState<GraphMeta[] | null>(null);+ const [flowVersions, setFlowVersions] = useState<Graph[] | null>(null);const [selectedVersion, setSelectedFlowVersion] = useState(flowVersion ?? "all");+ const selectedFlowVersion: Graph | undefined = flowVersions?.find(v => (+ v.version == (selectedVersion == "all" ? flow.version : selectedVersion)+ ));useEffect(() => {api.getGraphAllVersions(flow.id).then(result => setFlowVersions(result));@@ -449,7 +457,13 @@ const FlowInfo: React.FC<React.HTMLAttributes<HTMLDivElement> & {variant="outline"className="px-2.5"title="Export to a JSON-file"- onClick={() => exportAsJSONFile(flow, `${flow.name}_v${flow.version}.json`)}+ onClick={async () => exportAsJSONFile(+ safeCopyGraph(+ flowVersions!.find(v => v.version == selectedFlowVersion!.version)!,+ await api.getBlocks(),+ ),+ `${flow.name}_v${selectedFlowVersion!.version}.json`+ )}><ExitIcon /></Button>@@ -457,11 +471,7 @@ const FlowInfo: React.FC<React.HTMLAttributes<HTMLDivElement> & {</CardHeader><CardContent><FlowRunsStats- flows={[- selectedVersion != "all"- ? flowVersions?.find(v => v.version == selectedVersion)!- : flow- ]}+ flows={[selectedFlowVersion ?? flow]}flowRuns={flowRuns.filter(r =>r.graphID == flow.id&& (selectedVersion == "all" || r.graphVersion == selectedVersion)diff --git a/rnd/autogpt_builder/src/components/Flow.tsx b/rnd/autogpt_builder/src/components/Flow.tsxindex 7e379a2f91..d10f99f0ae 100644--- a/rnd/autogpt_builder/src/components/Flow.tsx+++ b/rnd/autogpt_builder/src/components/Flow.tsx@@ -15,8 +15,7 @@ import ReactFlow, {import 'reactflow/dist/style.css';import CustomNode from './CustomNode';import './flow.css';-import AutoGPTServerAPI, { Block, Graph } from '@/lib/autogpt_server_api';-import { ObjectSchema } from '@/lib/types';+import AutoGPTServerAPI, { Block, Graph, ObjectSchema } from '@/lib/autogpt-server-api';import { Button } from './ui/button';import { Input } from './ui/input';import { ChevronRight, ChevronLeft } from "lucide-react";diff --git a/rnd/autogpt_builder/src/components/agent-import-form.tsx b/rnd/autogpt_builder/src/components/agent-import-form.tsxindex 5d4ba1b863..8e5c60221d 100644--- a/rnd/autogpt_builder/src/components/agent-import-form.tsx+++ b/rnd/autogpt_builder/src/components/agent-import-form.tsx@@ -14,7 +14,7 @@ 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 AutoGPTServerAPI, { Graph, GraphCreatable } from "@/lib/autogpt-server-api"import { cn } from "@/lib/utils"import { EnterIcon } from "@radix-ui/react-icons"diff --git a/rnd/autogpt_builder/src/lib/autogpt_server_api.ts b/rnd/autogpt_builder/src/lib/autogpt-server-api/client.tssimilarity index 73%rename from rnd/autogpt_builder/src/lib/autogpt_server_api.tsrename to rnd/autogpt_builder/src/lib/autogpt-server-api/client.tsindex d57fbd9141..61b920a0cd 100644--- a/rnd/autogpt_builder/src/lib/autogpt_server_api.ts+++ b/rnd/autogpt_builder/src/lib/autogpt-server-api/client.ts@@ -1,5 +1,12 @@-import { XYPosition } from "reactflow";-import { ObjectSchema } from "./types";+import {+ Block,+ Graph,+ GraphCreatable,+ GraphUpdateable,+ GraphMeta,+ GraphExecuteResponse,+ NodeExecutionResult,+} from "./types"export default class AutoGPTServerAPI {private baseUrl: string;@@ -196,96 +203,12 @@ export default class AutoGPTServerAPI {}}-/* Mirror of autogpt_server/data/block.py:Block */-export type Block = {- id: string;- name: string;- description: string;- inputSchema: ObjectSchema;- outputSchema: ObjectSchema;-};--/* Mirror of autogpt_server/data/graph.py:Node */-export type Node = {- id: string;- block_id: string;- input_default: { [key: string]: any };- input_nodes: Array<{ name: string, node_id: string }>;- output_nodes: Array<{ name: string, node_id: string }>;- metadata: {- position: XYPosition;- [key: string]: any;- };-};--/* Mirror of autogpt_server/data/graph.py:Link */-export type Link = {- id: string;- source_id: string;- sink_id: string;- source_name: string;- sink_name: string;-}--export type LinkCreatable = Omit<Link, "id"> & {- id?: string;-}--/* Mirror of autogpt_server/data/graph.py:GraphMeta */-export type GraphMeta = {- id: string;- version: number;- is_active: boolean;- is_template: boolean;- name: string;- description: string;-}-/* Mirror of autogpt_server/data/graph.py:Graph */-export type Graph = GraphMeta & {- nodes: Array<Node>;- links: Array<Link>;-};+/* *** UTILITY TYPES *** */-export type GraphUpdateable = Omit<- Graph,- "version" | "is_active" | "is_template" | "links"-> & {- version?: number;- is_active?: boolean;- is_template?: boolean;- links: Array<LinkCreatable>;-}--export type GraphCreatable = Omit<GraphUpdateable, "id"> & { id?: string }--export type GraphCreateRequestBody = {+type GraphCreateRequestBody = {template_id: string;template_version: number;} | {graph: GraphCreatable;}--/* Derived from autogpt_server/executor/manager.py:ExecutionManager.add_execution */-export type GraphExecuteResponse = {- /* ID of the initiated run */- id: string;- /* List of node executions */- executions: Array<{ id: string, node_id: string }>;-};--/* Mirror of autogpt_server/data/execution.py:ExecutionResult */-export type NodeExecutionResult = {- graph_exec_id: string;- node_exec_id: string;- graph_id: string;- graph_version: number;- node_id: string;- status: 'INCOMPLETE' | 'QUEUED' | 'RUNNING' | 'COMPLETED' | 'FAILED';- input_data: { [key: string]: any };- output_data: { [key: string]: Array<any> };- add_time: Date;- queue_time?: Date;- start_time?: Date;- end_time?: Date;-};diff --git a/rnd/autogpt_builder/src/lib/autogpt-server-api/index.ts b/rnd/autogpt_builder/src/lib/autogpt-server-api/index.tsnew file mode 100644index 0000000000..234a72c750--- /dev/null+++ b/rnd/autogpt_builder/src/lib/autogpt-server-api/index.ts@@ -0,0 +1,5 @@+import AutoGPTServerAPI from "./client";++export default AutoGPTServerAPI;+export * from "./types";+export * from "./utils";diff --git a/rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts b/rnd/autogpt_builder/src/lib/autogpt-server-api/types.tsnew file mode 100644index 0000000000..64bbe17dd8--- /dev/null+++ b/rnd/autogpt_builder/src/lib/autogpt-server-api/types.ts@@ -0,0 +1,93 @@+/* Mirror of autogpt_server/data/block.py:Block */+export type Block = {+ id: string;+ name: string;+ description: string;+ inputSchema: ObjectSchema;+ outputSchema: ObjectSchema;+};++export type ObjectSchema = {+ type: string;+ properties: { [key: string]: any };+ additionalProperties?: { type: string };+ required?: string[];+};++/* Mirror of autogpt_server/data/graph.py:Node */+export type Node = {+ id: string;+ block_id: string;+ input_default: { [key: string]: any };+ input_nodes: Array<{ name: string, node_id: string }>;+ output_nodes: Array<{ name: string, node_id: string }>;+ metadata: {+ position: { x: number; y: number; };+ [key: string]: any;+ };+};++/* Mirror of autogpt_server/data/graph.py:Link */+export type Link = {+ id: string;+ source_id: string;+ sink_id: string;+ source_name: string;+ sink_name: string;+}++export type LinkCreatable = Omit<Link, "id"> & {+ id?: string;+}++/* Mirror of autogpt_server/data/graph.py:GraphMeta */+export type GraphMeta = {+ id: string;+ version: number;+ is_active: boolean;+ is_template: boolean;+ name: string;+ description: string;+}++/* Mirror of autogpt_server/data/graph.py:Graph */+export type Graph = GraphMeta & {+ nodes: Array<Node>;+ links: Array<Link>;+};++export type GraphUpdateable = Omit<+ Graph,+ "version" | "is_active" | "is_template" | "links"+> & {+ version?: number;+ is_active?: boolean;+ is_template?: boolean;+ links: Array<LinkCreatable>;+}++export type GraphCreatable = Omit<GraphUpdateable, "id"> & { id?: string }++/* Derived from autogpt_server/executor/manager.py:ExecutionManager.add_execution */+export type GraphExecuteResponse = {+ /** ID of the initiated run */+ id: string;+ /** List of node executions */+ executions: Array<{ id: string, node_id: string }>;+};++/* Mirror of autogpt_server/data/execution.py:ExecutionResult */+export type NodeExecutionResult = {+ graph_exec_id: string;+ node_exec_id: string;+ graph_id: string;+ graph_version: number;+ node_id: string;+ status: 'INCOMPLETE' | 'QUEUED' | 'RUNNING' | 'COMPLETED' | 'FAILED';+ input_data: { [key: string]: any };+ output_data: { [key: string]: Array<any> };+ add_time: Date;+ queue_time?: Date;+ start_time?: Date;+ end_time?: Date;+};diff --git a/rnd/autogpt_builder/src/lib/autogpt-server-api/utils.ts b/rnd/autogpt_builder/src/lib/autogpt-server-api/utils.tsnew file mode 100644index 0000000000..ea7306ebe5--- /dev/null+++ b/rnd/autogpt_builder/src/lib/autogpt-server-api/utils.ts@@ -0,0 +1,20 @@+import { Graph, Block, Node } from "./types";++/** Creates a copy of the graph with all secrets removed */+export function safeCopyGraph(graph: Graph, block_defs: Block[]): Graph {+ return {+ ...graph,+ nodes: graph.nodes.map(node => {+ const block = block_defs.find(b => b.id == node.block_id)!;+ return {+ ...node,+ input_default: Object.keys(node.input_default)+ .filter(k => !block.inputSchema.properties[k].secret)+ .reduce((obj: Node['input_default'], key) => {+ obj[key] = node.input_default[key];+ return obj;+ }, {}),+ }+ }),+ }+}diff --git a/rnd/autogpt_builder/src/lib/types.ts b/rnd/autogpt_builder/src/lib/types.tsindex 5bec6964c7..48f5857bbe 100644--- a/rnd/autogpt_builder/src/lib/types.ts+++ b/rnd/autogpt_builder/src/lib/types.ts@@ -1,10 +1,3 @@-export type ObjectSchema = {- type: string;- properties: { [key: string]: any };- additionalProperties?: { type: string };- required?: string[];-};-export type BlockSchema = {type: string;properties: { [key: string]: any };