parent
e10c4ee4cd
commit
f94e81f48b
|
@ -34,34 +34,34 @@ type CustomNodeData = {
|
||||||
block_id: string;
|
block_id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Sidebar: React.FC<{isOpen: boolean, availableNodes: Block[], addNode: (id: string, name: string) => void}> =
|
const Sidebar: React.FC<{ isOpen: boolean, availableNodes: Block[], addNode: (id: string, name: string) => void }> =
|
||||||
({isOpen, availableNodes, addNode}) => {
|
({ isOpen, availableNodes, addNode }) => {
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
|
||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
|
|
||||||
const filteredNodes = availableNodes.filter(node =>
|
const filteredNodes = availableNodes.filter(node =>
|
||||||
node.name.toLowerCase().includes(searchQuery.toLowerCase())
|
node.name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`sidebar dark-theme ${isOpen ? 'open' : ''}`}>
|
<div className={`sidebar dark-theme ${isOpen ? 'open' : ''}`}>
|
||||||
<h3>Nodes</h3>
|
<h3>Nodes</h3>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search nodes..."
|
placeholder="Search nodes..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
/>
|
/>
|
||||||
{filteredNodes.map((node) => (
|
{filteredNodes.map((node) => (
|
||||||
<div key={node.id} className="sidebarNodeRowStyle dark-theme">
|
<div key={node.id} className="sidebarNodeRowStyle dark-theme">
|
||||||
<span>{node.name}</span>
|
<span>{node.name}</span>
|
||||||
<Button onClick={() => addNode(node.id, node.name)}>Add</Button>
|
<Button onClick={() => addNode(node.id, node.name)}>Add</Button>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({
|
const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({
|
||||||
flowID,
|
flowID,
|
||||||
|
@ -261,8 +261,7 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({
|
||||||
return inputData;
|
return inputData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveAgent = async () => {
|
||||||
const runAgent = async () => {
|
|
||||||
try {
|
try {
|
||||||
console.log("All nodes before formatting:", nodes);
|
console.log("All nodes before formatting:", nodes);
|
||||||
const blockIdToNodeIdMap = {};
|
const blockIdToNodeIdMap = {};
|
||||||
|
@ -326,6 +325,20 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({
|
||||||
|
|
||||||
setNodes(updatedNodes);
|
setNodes(updatedNodes);
|
||||||
|
|
||||||
|
return newAgentId;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error running agent:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const runAgent = async () => {
|
||||||
|
try {
|
||||||
|
const newAgentId = await saveAgent();
|
||||||
|
if (!newAgentId) {
|
||||||
|
console.error('Error saving agent');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const executeData = await api.executeFlow(newAgentId);
|
const executeData = await api.executeFlow(newAgentId);
|
||||||
const runId = executeData.id;
|
const runId = executeData.id;
|
||||||
|
|
||||||
|
@ -348,25 +361,25 @@ const FlowEditor: React.FC<{ flowID?: string; className?: string }> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const updateNodesWithExecutionData = (executionData: any[]) => {
|
const updateNodesWithExecutionData = (executionData: any[]) => {
|
||||||
setNodes((nds) =>
|
setNodes((nds) =>
|
||||||
nds.map((node) => {
|
nds.map((node) => {
|
||||||
const nodeExecution = executionData.find((exec) => exec.node_id === node.id);
|
const nodeExecution = executionData.find((exec) => exec.node_id === node.id);
|
||||||
if (nodeExecution) {
|
if (nodeExecution) {
|
||||||
return {
|
return {
|
||||||
...node,
|
...node,
|
||||||
data: {
|
data: {
|
||||||
...node.data,
|
...node.data,
|
||||||
status: nodeExecution.status,
|
status: nodeExecution.status,
|
||||||
output_data: nodeExecution.output_data,
|
output_data: nodeExecution.output_data,
|
||||||
isPropertiesOpen: true,
|
isPropertiesOpen: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleSidebar = () => setIsSidebarOpen(!isSidebarOpen);
|
const toggleSidebar = () => setIsSidebarOpen(!isSidebarOpen);
|
||||||
|
|
||||||
|
@ -406,7 +419,10 @@ const updateNodesWithExecutionData = (executionData: any[]) => {
|
||||||
value={agentDescription}
|
value={agentDescription}
|
||||||
onChange={(e) => setAgentDescription(e.target.value)}
|
onChange={(e) => setAgentDescription(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<Button onClick={runAgent}>Run Agent</Button>
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}> {/* Added gap for spacing */}
|
||||||
|
<Button onClick={saveAgent}>Save Agent</Button>
|
||||||
|
<Button onClick={runAgent}>Save & Run Agent</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue