Skip to content

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(frontend/builder): Prevent unnecessary saves before run (#10670)

Reinier van der Leer35bd7f7f7a22
diff --git a/autogpt_platform/frontend/src/components/CustomNode.tsx b/autogpt_platform/frontend/src/components/CustomNode.tsx
index 3606898294..ac6bba0bb4 100644
--- a/autogpt_platform/frontend/src/components/CustomNode.tsx
+++ b/autogpt_platform/frontend/src/components/CustomNode.tsx
@@ -187,7 +187,19 @@ export const CustomNode = React.memo(
useEffect(() => {
isInitialSetup.current = false;
- setHardcodedValues(fillDefaults(data.hardcodedValues, data.inputSchema));
+ if (data.uiType === BlockUIType.AGENT) {
+ setHardcodedValues({
+ ...data.hardcodedValues,
+ inputs: fillDefaults(
+ data.hardcodedValues.inputs ?? {},
+ data.inputSchema,
+ ),
+ });
+ } else {
+ setHardcodedValues(
+ fillDefaults(data.hardcodedValues, data.inputSchema),
+ );
+ }
}, []);
const setErrors = useCallback(
diff --git a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx
index 7b9222f493..5b1990f716 100644
--- a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx
+++ b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx
@@ -930,15 +930,27 @@ export default function useAgentGraph(
}
function graphsEquivalent(saved: Graph, current: GraphCreatable): boolean {
+ const sortNodes = (nodes: NodeCreatable[]) =>
+ nodes.toSorted((a, b) => a.id.localeCompare(b.id));
+
+ const sortLinks = (links: LinkCreatable[]) =>
+ links.toSorted(
+ (a, b) =>
+ 8 * a.source_id.localeCompare(b.source_id) +
+ 4 * a.sink_id.localeCompare(b.sink_id) +
+ 2 * a.source_name.localeCompare(b.source_name) +
+ a.sink_name.localeCompare(b.sink_name),
+ );
+
const _saved = {
name: saved.name,
description: saved.description,
- nodes: saved.nodes.map((v) => ({
+ nodes: sortNodes(saved.nodes).map((v) => ({
block_id: v.block_id,
input_default: v.input_default,
metadata: v.metadata,
})),
- links: saved.links.map((v) => ({
+ links: sortLinks(saved.links).map((v) => ({
sink_name: v.sink_name,
source_name: v.source_name,
})),
@@ -946,8 +958,10 @@ function graphsEquivalent(saved: Graph, current: GraphCreatable): boolean {
const _current = {
name: current.name,
description: current.description,
- nodes: current.nodes.map(({ id: _, ...rest }) => rest),
- links: current.links.map(({ source_id: _, sink_id: __, ...rest }) => rest),
+ nodes: sortNodes(current.nodes).map(({ id: _, ...rest }) => rest),
+ links: sortLinks(current.links).map(
+ ({ source_id: _, sink_id: __, ...rest }) => rest,
+ ),
};
return deepEquals(_saved, _current);
}
diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts
index 6e51d818ec..15c2894421 100644
--- a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts
+++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts
@@ -323,8 +323,9 @@ export type CredentialsInputSchema = {
/* Mirror of backend/data/graph.py:Graph */
export type Graph = GraphMeta & {
- nodes: Array<Node>;
- links: Array<Link>;
+ nodes: Node[];
+ links: Link[];
+ sub_graphs: Omit<Graph, "sub_graphs">[]; // Flattened sub-graphs
};
export type GraphUpdateable = Omit<
@@ -334,6 +335,7 @@ export type GraphUpdateable = Omit<
| "is_active"
| "nodes"
| "links"
+ | "sub_graphs"
| "input_schema"
| "output_schema"
| "credentials_input_schema"
@@ -341,13 +343,16 @@ export type GraphUpdateable = Omit<
> & {
version?: number;
is_active?: boolean;
- nodes: Array<NodeCreatable>;
- links: Array<LinkCreatable>;
+ nodes: NodeCreatable[];
+ links: LinkCreatable[];
input_schema?: GraphIOSchema;
output_schema?: GraphIOSchema;
};
-export type GraphCreatable = Omit<GraphUpdateable, "id"> & { id?: string };
+export type GraphCreatable = _GraphCreatableInner & {
+ sub_graphs?: _GraphCreatableInner[]; // Flattened sub-graphs
+};
+type _GraphCreatableInner = Omit<GraphUpdateable, "id"> & { id?: string };
/* Mirror of backend/data/execution.py:NodeExecutionResult */
export type NodeExecutionResult = {