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.
Updating api calls in AutoGPT builder (#7275)
Bentlyd5ab83aa34cd
diff --git a/rnd/autogpt_builder/src/components/CustomNode.tsx b/rnd/autogpt_builder/src/components/CustomNode.tsxindex f401efbf54..74cf1c2303 100644--- a/rnd/autogpt_builder/src/components/CustomNode.tsx+++ b/rnd/autogpt_builder/src/components/CustomNode.tsx@@ -166,6 +166,7 @@ const CustomNode: FC<NodeProps> = ({ data, id }) => {}};+return (<div className="custom-node"><div className="node-header">diff --git a/rnd/autogpt_builder/src/components/Flow.tsx b/rnd/autogpt_builder/src/components/Flow.tsxindex 8a0191b3b1..aebd99c7f2 100644--- a/rnd/autogpt_builder/src/components/Flow.tsx+++ b/rnd/autogpt_builder/src/components/Flow.tsx@@ -119,12 +119,12 @@ const Flow: React.FC = () => {nds.map((node) => {if (node.id === connection.source) {const connections = node.data.connections || [];- connections.push(`${node.data.title} ${connection.sourceHandle} -> ${connection.targetHandle}`);+ connections.push(`${node.data.title} ${connection.sourceHandle} -> ${connection.target}`);return { ...node, data: { ...node.data, connections } };}if (node.id === connection.target) {const connections = node.data.connections || [];- connections.push(`${connection.sourceHandle} -> ${node.data.title} ${connection.targetHandle}`);+ connections.push(`${connection.source} -> ${node.data.title} ${connection.targetHandle}`);return { ...node, data: { ...node.data, connections } };}return node;@@ -214,18 +214,17 @@ const Flow: React.FC = () => {let inputData: { [key: string]: any } = {};const inputProperties = nodeSchema.inputSchema.properties;- const requiredProperties = nodeSchema.inputSchema.required || [];-- // Initialize inputData with default values for all required properties- requiredProperties.forEach(prop => {- inputData[prop] = node.data.hardcodedValues[prop] || '';- });Object.keys(inputProperties).forEach(prop => {- const inputEdge = allEdges.find(edge => edge.target === node.id && edge.targetHandle === prop);- if (inputEdge) {- const sourceNode = allNodes.find(n => n.id === inputEdge.source);- inputData[prop] = sourceNode?.data.output_data || sourceNode?.data.hardcodedValues[prop] || '';+ const inputEdges = allEdges.filter(edge => edge.target === node.id && edge.targetHandle === prop);+ if (inputEdges.length > 0) {+ const sourceNode = allNodes.find(n => n.id === inputEdges[0].source);+ if (sourceNode && sourceNode.data.output_data) {+ // Map the output of the source node to the input of the target node+ const sourceOutput = sourceNode.data.output_data;+ const outputKey = Object.keys(sourceOutput)[0]; // Assume first output key+ inputData[prop] = sourceOutput[outputKey];+ }} else if (node.data.hardcodedValues && node.data.hardcodedValues[prop]) {inputData[prop] = node.data.hardcodedValues[prop];}@@ -255,25 +254,31 @@ const Flow: React.FC = () => {const runAgent = async () => {try {- const formattedNodes = nodes.map(node => ({- id: node.id,- block_id: node.data.block_id,- input_default: prepareNodeInputData(node, nodes, edges),- input_nodes: edges.filter(edge => edge.target === node.id).reduce((acc, edge) => {- if (edge.targetHandle) {- acc[edge.targetHandle] = edge.source;- }- return acc;- }, {} as { [key: string]: string }),- output_nodes: edges.filter(edge => edge.source === node.id).reduce((acc, edge) => {- if (edge.sourceHandle) {- acc[edge.sourceHandle] = edge.target;- }- return acc;- }, {} as { [key: string]: string }),- metadata: node.data.metadata,- connections: node.data.connections // Ensure connections are preserved- }));+ const formattedNodes = nodes.map(node => {+ const inputDefault = prepareNodeInputData(node, nodes, edges);+ const inputNodes = edges+ .filter(edge => edge.target === node.id)+ .map(edge => ({+ name: edge.targetHandle || '',+ node_id: edge.source,+ }));++ const outputNodes = edges+ .filter(edge => edge.source === node.id)+ .map(edge => ({+ name: edge.sourceHandle || '',+ node_id: edge.target,+ }));++ return {+ id: node.id,+ block_id: node.data.block_id,+ input_default: inputNodes.length === 0 ? inputDefault : {},+ input_nodes: inputNodes,+ output_nodes: outputNodes,+ metadata: node.data.metadata+ };+ });const payload = {id: '',@@ -282,7 +287,7 @@ const Flow: React.FC = () => {nodes: formattedNodes,};- const createResponse = await fetch(`${apiUrl}/agents`, {+ const createResponse = await fetch(`${apiUrl}/graphs`, {method: 'POST',headers: {'Content-Type': 'application/json',@@ -300,13 +305,6 @@ const Flow: React.FC = () => {const responseNodes = createData.nodes.map((node: any) => {const block = availableNodes.find(n => n.id === node.block_id);- const connections = edges.filter(edge => edge.source === node.id || edge.target === node.id).map(edge => ({- id: edge.id,- source: edge.source,- sourceHandle: edge.sourceHandle,- target: edge.target,- targetHandle: edge.targetHandle- }));return {id: node.id,type: 'custom',@@ -317,7 +315,7 @@ const Flow: React.FC = () => {description: `${block?.description || ''}`,inputSchema: block?.inputSchema,outputSchema: block?.outputSchema,- connections: connections.map(c => `${c.source}-${c.sourceHandle} -> ${c.target}-${c.targetHandle}`),+ connections: node.input_nodes.map((input: any) => `${input.node_id}-${input.name} -> ${node.id}`),variableName: '',variableValue: '',printVariable: '',@@ -339,12 +337,12 @@ const Flow: React.FC = () => {});const newEdges = createData.nodes.flatMap((node: any) => {- return Object.entries(node.output_nodes).map(([sourceHandle, targetNodeId]) => ({- id: `${node.id}-${sourceHandle}-${targetNodeId}`,+ return node.output_nodes.map((outputNode: { name: string; node_id: string }) => ({+ id: `${node.id}-${outputNode.name}-${outputNode.node_id}`,source: node.id,- sourceHandle: sourceHandle,- target: targetNodeId,- targetHandle: Object.keys(node.input_nodes).find(key => node.input_nodes[key] === targetNodeId) || '',+ sourceHandle: outputNode.name,+ target: outputNode.node_id,+ targetHandle: node.input_nodes.find((inputNode: { name: string; node_id: string }) => inputNode.node_id === outputNode.node_id)?.name || '',}));});@@ -367,7 +365,7 @@ const Flow: React.FC = () => {return acc;}, {} as { [key: string]: any });- const executeResponse = await fetch(`${apiUrl}/agents/${agentId}/execute`, {+ const executeResponse = await fetch(`${apiUrl}/graphs/${agentId}/execute`, {method: 'POST',headers: {'Content-Type': 'application/json',@@ -380,8 +378,7 @@ const Flow: React.FC = () => {}const executeData = await executeResponse.json();- const runId = executeData.run_id;-+ const runId = executeData.id; // Correctly capturing runId from executeDataconst startPolling = () => {const endTime = Date.now() + 60000;@@ -392,7 +389,7 @@ const Flow: React.FC = () => {}try {- const response = await fetch(`${apiUrl}/agents/${agentId}/executions/${runId}`);+ const response = await fetch(`${apiUrl}/graphs/${agentId}/executions/${runId}`);if (!response.ok) {throw new Error(`HTTP error! Status: ${response.status}`);}