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.

Revert "fix(frontend/builder): Sync frontend node IDs with backend after save" (#11142)

Nicholas Tindlea49c957467e8
diff --git a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx
index 2c9870d347..44bf913baa 100644
--- a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx
+++ b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx
@@ -629,7 +629,7 @@ export default function useAgentGraph(
recommended_schedule_cron: agentRecommendedScheduleCron || null,
nodes: xyNodes.map(
(node): NodeCreatable => ({
- id: node.data.backend_id ?? node.id,
+ id: node.id,
block_id: node.data.block_id,
input_default: prepareNodeInputData(node),
metadata: {
@@ -695,56 +695,38 @@ export default function useAgentGraph(
// Update the node IDs on the frontend
setSavedAgent(newSavedAgent);
-
- // Create a mapping from old frontend IDs to new backend IDs
- const oldToNewNodeIDMap = new Map<string, string>();
-
- setXYNodes((prev) =>
- newSavedAgent.nodes
+ setXYNodes((prev) => {
+ return newSavedAgent.nodes
.map((backendNode) => {
const key = `${backendNode.block_id}_${backendNode.metadata.position.x}_${backendNode.metadata.position.y}`;
- const oldFrontendNodeID = blockIDToNodeIDMap[key];
- const frontendNode = prev.find(
- (node) => node.id === oldFrontendNodeID,
- );
-
- if (frontendNode) {
- // Store the ID mapping for edge updates
- oldToNewNodeIDMap.set(oldFrontendNodeID, backendNode.id);
- }
+ const frontendNodeID = blockIDToNodeIDMap[key];
+ const frontendNode = prev.find((node) => node.id === frontendNodeID);
const { position, ...metadata } = backendNode.metadata;
return frontendNode
? ({
...frontendNode,
- id: backendNode.id, // Update the actual node ID to match backend
position,
data: {
...frontendNode.data,
hardcodedValues: removeEmptyStringsAndNulls(
frontendNode.data.hardcodedValues,
),
+ status: undefined,
backend_id: backendNode.id,
+ executionResults: [],
metadata,
- status: undefined,
- executionResults: undefined,
},
} satisfies CustomNode)
: _backendNodeToXYNode(backendNode, newSavedAgent); // fallback
})
- .filter((node) => node !== null),
- );
-
- // Reset bead count & update edge references to use the new node IDs
- setXYEdges((edges) =>
- edges.map((edge): CustomEdge => {
- const newSourceId = oldToNewNodeIDMap.get(edge.source) || edge.source;
- const newTargetId = oldToNewNodeIDMap.get(edge.target) || edge.target;
-
- return {
+ .filter((node) => node !== null);
+ });
+ // Reset bead count
+ setXYEdges((edges) => {
+ return edges.map(
+ (edge): CustomEdge => ({
...edge,
- source: newSourceId,
- target: newTargetId,
data: {
...edge.data,
edgeColor: edge.data?.edgeColor ?? "grey",
@@ -752,9 +734,9 @@ export default function useAgentGraph(
beadDown: 0,
beadData: new Map(),
},
- };
- }),
- );
+ }),
+ );
+ });
return newSavedAgent;
}, [
api,