Updating api calls in AutoGPT builder (#7275)
* update api endpoints * get multi-node working + fix node output * updated multi-node running + re-add "wire" on rebuild * Fix node data mapping * removed getStatusValuepull/7293/head
parent
cbae8b5c14
commit
d5ab83aa34
|
@ -166,6 +166,7 @@ const CustomNode: FC<NodeProps> = ({ data, id }) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="custom-node">
|
<div className="custom-node">
|
||||||
<div className="node-header">
|
<div className="node-header">
|
||||||
|
|
|
@ -119,12 +119,12 @@ const Flow: React.FC = () => {
|
||||||
nds.map((node) => {
|
nds.map((node) => {
|
||||||
if (node.id === connection.source) {
|
if (node.id === connection.source) {
|
||||||
const connections = node.data.connections || [];
|
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 } };
|
return { ...node, data: { ...node.data, connections } };
|
||||||
}
|
}
|
||||||
if (node.id === connection.target) {
|
if (node.id === connection.target) {
|
||||||
const connections = node.data.connections || [];
|
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, data: { ...node.data, connections } };
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
@ -214,18 +214,17 @@ const Flow: React.FC = () => {
|
||||||
|
|
||||||
let inputData: { [key: string]: any } = {};
|
let inputData: { [key: string]: any } = {};
|
||||||
const inputProperties = nodeSchema.inputSchema.properties;
|
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 => {
|
Object.keys(inputProperties).forEach(prop => {
|
||||||
const inputEdge = allEdges.find(edge => edge.target === node.id && edge.targetHandle === prop);
|
const inputEdges = allEdges.filter(edge => edge.target === node.id && edge.targetHandle === prop);
|
||||||
if (inputEdge) {
|
if (inputEdges.length > 0) {
|
||||||
const sourceNode = allNodes.find(n => n.id === inputEdge.source);
|
const sourceNode = allNodes.find(n => n.id === inputEdges[0].source);
|
||||||
inputData[prop] = sourceNode?.data.output_data || sourceNode?.data.hardcodedValues[prop] || '';
|
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]) {
|
} else if (node.data.hardcodedValues && node.data.hardcodedValues[prop]) {
|
||||||
inputData[prop] = node.data.hardcodedValues[prop];
|
inputData[prop] = node.data.hardcodedValues[prop];
|
||||||
}
|
}
|
||||||
|
@ -255,25 +254,31 @@ const Flow: React.FC = () => {
|
||||||
|
|
||||||
const runAgent = async () => {
|
const runAgent = async () => {
|
||||||
try {
|
try {
|
||||||
const formattedNodes = nodes.map(node => ({
|
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,
|
id: node.id,
|
||||||
block_id: node.data.block_id,
|
block_id: node.data.block_id,
|
||||||
input_default: prepareNodeInputData(node, nodes, edges),
|
input_default: inputNodes.length === 0 ? inputDefault : {},
|
||||||
input_nodes: edges.filter(edge => edge.target === node.id).reduce((acc, edge) => {
|
input_nodes: inputNodes,
|
||||||
if (edge.targetHandle) {
|
output_nodes: outputNodes,
|
||||||
acc[edge.targetHandle] = edge.source;
|
metadata: node.data.metadata
|
||||||
}
|
};
|
||||||
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 payload = {
|
const payload = {
|
||||||
id: '',
|
id: '',
|
||||||
|
@ -282,7 +287,7 @@ const Flow: React.FC = () => {
|
||||||
nodes: formattedNodes,
|
nodes: formattedNodes,
|
||||||
};
|
};
|
||||||
|
|
||||||
const createResponse = await fetch(`${apiUrl}/agents`, {
|
const createResponse = await fetch(`${apiUrl}/graphs`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -300,13 +305,6 @@ const Flow: React.FC = () => {
|
||||||
|
|
||||||
const responseNodes = createData.nodes.map((node: any) => {
|
const responseNodes = createData.nodes.map((node: any) => {
|
||||||
const block = availableNodes.find(n => n.id === node.block_id);
|
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 {
|
return {
|
||||||
id: node.id,
|
id: node.id,
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
|
@ -317,7 +315,7 @@ const Flow: React.FC = () => {
|
||||||
description: `${block?.description || ''}`,
|
description: `${block?.description || ''}`,
|
||||||
inputSchema: block?.inputSchema,
|
inputSchema: block?.inputSchema,
|
||||||
outputSchema: block?.outputSchema,
|
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: '',
|
variableName: '',
|
||||||
variableValue: '',
|
variableValue: '',
|
||||||
printVariable: '',
|
printVariable: '',
|
||||||
|
@ -339,12 +337,12 @@ const Flow: React.FC = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const newEdges = createData.nodes.flatMap((node: any) => {
|
const newEdges = createData.nodes.flatMap((node: any) => {
|
||||||
return Object.entries(node.output_nodes).map(([sourceHandle, targetNodeId]) => ({
|
return node.output_nodes.map((outputNode: { name: string; node_id: string }) => ({
|
||||||
id: `${node.id}-${sourceHandle}-${targetNodeId}`,
|
id: `${node.id}-${outputNode.name}-${outputNode.node_id}`,
|
||||||
source: node.id,
|
source: node.id,
|
||||||
sourceHandle: sourceHandle,
|
sourceHandle: outputNode.name,
|
||||||
target: targetNodeId,
|
target: outputNode.node_id,
|
||||||
targetHandle: Object.keys(node.input_nodes).find(key => node.input_nodes[key] === targetNodeId) || '',
|
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;
|
return acc;
|
||||||
}, {} as { [key: string]: any });
|
}, {} as { [key: string]: any });
|
||||||
|
|
||||||
const executeResponse = await fetch(`${apiUrl}/agents/${agentId}/execute`, {
|
const executeResponse = await fetch(`${apiUrl}/graphs/${agentId}/execute`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -380,8 +378,7 @@ const Flow: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeData = await executeResponse.json();
|
const executeData = await executeResponse.json();
|
||||||
const runId = executeData.run_id;
|
const runId = executeData.id; // Correctly capturing runId from executeData
|
||||||
|
|
||||||
const startPolling = () => {
|
const startPolling = () => {
|
||||||
const endTime = Date.now() + 60000;
|
const endTime = Date.now() + 60000;
|
||||||
|
|
||||||
|
@ -392,7 +389,7 @@ const Flow: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${apiUrl}/agents/${agentId}/executions/${runId}`);
|
const response = await fetch(`${apiUrl}/graphs/${agentId}/executions/${runId}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue