Initial files

This commit is contained in:
Bentlybro
2024-06-19 11:34:51 +01:00
committed by Aarushi
parent 26bcb26bb7
commit ce3117e6e1
14 changed files with 656 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
node_modules/
public/

View File

@@ -0,0 +1,13 @@
# AutoGPT-Builder
for this we have used the [ReactFlow](https://github.com/xyflow/xyflow)
# Getting Started with AutoGPT-Builder
To use make sure you have NPM installed and do
```
npm install reactflow
```
then
```
npm start
```

View File

@@ -0,0 +1,38 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@@ -0,0 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -0,0 +1,12 @@
import React from 'react';
import Flow from './Flow';
const App: React.FC = () => {
return (
<div className="App">
<Flow />
</div>
);
};
export default App;

View File

@@ -0,0 +1,69 @@
import React from 'react';
import { Handle, Position, NodeProps } from 'reactflow';
import 'reactflow/dist/style.css';
type Schema = {
properties: { [key: string]: any };
};
const CustomNode: React.FC<NodeProps> = ({ data }) => {
const generateHandles = (schema: Schema, type: 'source' | 'target') => {
if (!schema?.properties) return null;
const keys = Object.keys(schema.properties);
return keys.map((key, index) => (
<div key={key} style={{ display: 'flex', alignItems: 'center', position: 'relative', marginBottom: '5px' }}>
{type === 'target' && (
<>
<Handle
type={type}
position={Position.Left}
id={`${type}-${key}`}
style={{ background: '#555', borderRadius: '50%' }}
/>
<span style={{ color: '#e0e0e0', marginLeft: '10px' }}>{key}</span>
</>
)}
{type === 'source' && (
<>
<span style={{ color: '#e0e0e0', marginRight: '10px' }}>{key}</span>
<Handle
type={type}
position={Position.Right}
id={`${type}-${key}`}
style={{ background: '#555', borderRadius: '50%' }}
/>
</>
)}
</div>
));
};
return (
<div style={{ padding: '20px', border: '2px solid #fff', borderRadius: '20px', background: '#333', color: '#e0e0e0', width: '250px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '10px' }}>
<div style={{ fontSize: '18px', fontWeight: 'bold' }}>
{data?.title.replace(/\d+/g, '')}
</div>
<button
style={{ background: 'transparent', border: 'none', cursor: 'pointer', color: '#e0e0e0' }}
onClick={(event: React.MouseEvent) => {
event.stopPropagation();
data.openPropertiesSidebar(data);
}}
>
&#9776;
</button>
</div>
<div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', gap: '20px' }}>
<div>
{data.inputSchema && generateHandles(data.inputSchema, 'target')}
</div>
<div>
{data.outputSchema && generateHandles(data.outputSchema, 'source')}
</div>
</div>
</div>
);
};
export default CustomNode;

View File

@@ -0,0 +1,318 @@
import React, { useState, useCallback, useEffect } from 'react';
import ReactFlow, {
addEdge,
applyNodeChanges,
applyEdgeChanges,
Node,
Edge,
OnNodesChange,
OnEdgesChange,
OnConnect,
NodeTypes,
} from 'reactflow';
import 'reactflow/dist/style.css';
import Modal from 'react-modal';
import CustomNode from './CustomNode';
import './index.css';
const initialNodes: Node[] = [
{ id: '1', type: 'custom', data: { label: 'Start Node', title: 'Start Node', description: 'Start Node' }, position: { x: 250, y: 5 } },
];
const initialEdges: Edge[] = [];
const nodeTypes: NodeTypes = {
custom: CustomNode,
};
interface AvailableNode {
id: string;
name: string;
inputSchema?: { properties: { [key: string]: any } };
outputSchema?: { properties: { [key: string]: any } };
}
const Flow: React.FC = () => {
const [nodes, setNodes] = useState<Node[]>(initialNodes);
const [edges, setEdges] = useState<Edge[]>(initialEdges);
const [nodeId, setNodeId] = useState<number>(2);
const [modalIsOpen, setModalIsOpen] = useState<boolean>(false);
const [selectedNode, setSelectedNode] = useState<Node | null>(null);
const [title, setTitle] = useState<string>('');
const [description, setDescription] = useState<string>('');
const [variableName, setVariableName] = useState<string>('');
const [variableValue, setVariableValue] = useState<string>('');
const [printVariable, setPrintVariable] = useState<string>('');
const [isSidebarOpen, setIsSidebarOpen] = useState<boolean>(false);
const [isPropertiesSidebarOpen, setIsPropertiesSidebarOpen] = useState<boolean>(false);
const [propertiesNode, setPropertiesNode] = useState<Node | null>(null);
const [searchQuery, setSearchQuery] = useState<string>('');
const [availableNodes, setAvailableNodes] = useState<AvailableNode[]>([]);
useEffect(() => {
fetch('http://192.168.0.215:8000/blocks')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
setAvailableNodes(data);
})
.catch(error => console.error('Error fetching nodes:', error));
}, []);
const onNodesChange: OnNodesChange = useCallback(
(changes) => setNodes((nds) => applyNodeChanges(changes, nds)),
[]
);
const onEdgesChange: OnEdgesChange = useCallback(
(changes) => setEdges((eds) => applyEdgeChanges(changes, eds)),
[]
);
const onConnect: OnConnect = useCallback(
(connection) => setEdges((eds) => addEdge(connection, eds)),
[]
);
const addNode = (type: string, label: string) => {
const nodeSchema = availableNodes.find(node => node.name === label);
const newNode: Node = {
id: nodeId.toString(),
type: 'custom',
data: {
label: label,
title: `${type} ${nodeId}`,
description: `${type} Description ${nodeId}`,
inputSchema: nodeSchema?.inputSchema,
outputSchema: nodeSchema?.outputSchema,
variableName: '',
variableValue: '',
printVariable: '',
setVariableName,
setVariableValue,
setPrintVariable,
openPropertiesSidebar: (node: Node) => openPropertiesSidebar(node),
},
position: { x: Math.random() * 400, y: Math.random() * 400 },
};
setNodes((nds) => [...nds, newNode]);
setNodeId((id) => id + 1);
};
const closeModal = () => {
setModalIsOpen(false);
setSelectedNode(null);
};
const saveNodeData = () => {
if (selectedNode) {
setNodes((nds) =>
nds.map((node) =>
node.id === selectedNode.id
? { ...node, data: { ...node.data, title, description, label: title, variableName, variableValue, printVariable } }
: node
)
);
closeModal();
}
};
const toggleSidebar = () => {
setIsSidebarOpen(!isSidebarOpen);
};
const openPropertiesSidebar = (node: Node) => {
console.log(node);
setPropertiesNode(node);
setIsPropertiesSidebarOpen(true);
};
const closePropertiesSidebar = () => {
setIsPropertiesSidebarOpen(false);
setPropertiesNode(null);
};
const getNodeConnections = (nodeId: string) => {
const inputs = edges.filter(edge => edge.target === nodeId).length;
const outputs = edges.filter(edge => edge.source === nodeId).length;
return { inputs, outputs };
};
const filteredNodes = availableNodes.filter(node => node.name.toLowerCase().includes(searchQuery.toLowerCase()));
return (
<div style={{ height: '100vh', position: 'relative', backgroundColor: '#121212' }}>
<div style={{ position: 'absolute', top: '20px', left: isSidebarOpen ? '400px' : '20px', zIndex: 10, transition: 'left 0.3s ease' }}>
<button
onClick={toggleSidebar}
style={{
padding: '10px 20px',
fontSize: '16px',
backgroundColor: '#007bff',
color: '#fff',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
}}
>
Nodes
</button>
</div>
<div style={{ height: '100%', width: '100%' }}>
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
fitView
/>
</div>
{selectedNode && (
<Modal isOpen={modalIsOpen} onRequestClose={closeModal} contentLabel="Node Info" className="modal" overlayClassName="overlay">
<h2>Edit Node</h2>
<form
onSubmit={(e) => {
e.preventDefault();
saveNodeData();
}}
>
<div>
<label>
Title:
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</label>
</div>
<div>
<label>
Description:
<textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
required
/>
</label>
</div>
{selectedNode.data.title.includes('Variable') && (
<>
<div>
<label>
Variable Name:
<input
type="text"
value={variableName}
onChange={(e) => setVariableName(e.target.value)}
required
/>
</label>
</div>
<div>
<label>
Variable Value:
<input
type="text"
value={variableValue}
onChange={(e) => setVariableValue(e.target.value)}
required
/>
</label>
</div>
</>
)}
{selectedNode.data.title.includes('Print') && (
<>
<div>
<label>
Variable to Print:
<input
type="text"
value={printVariable}
onChange={(e) => setPrintVariable(e.target.value)}
required
/>
</label>
</div>
</>
)}
<button type="submit">Save</button>
<button type="button" onClick={closeModal}>
Cancel
</button>
</form>
</Modal>
)}
<div className={`sidebar ${isSidebarOpen ? 'open' : ''}`}>
<h3 style={{ margin: '0 0 10px 0' }}>Nodes</h3>
<input
type="text"
placeholder="Search nodes..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
style={{
padding: '10px',
fontSize: '16px',
backgroundColor: '#333',
color: '#e0e0e0',
border: '1px solid #555',
borderRadius: '4px',
marginBottom: '10px',
width: 'calc(100% - 22px)',
boxSizing: 'border-box',
}}
/>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px' }}>
{filteredNodes.map(node => (
<button
key={node.id}
onClick={() => addNode(node.name, node.name)}
style={sidebarButtonStyle}
>
{`Add ${node.name}`}
</button>
))}
</div>
</div>
{propertiesNode && (
<div className={`properties-sidebar ${isPropertiesSidebarOpen ? 'open' : ''}`}>
<h3>Node Properties</h3>
<p><strong>Name:</strong> {propertiesNode?.data?.label}</p>
<p><strong>Title:</strong> {propertiesNode?.data?.title}</p>
<p><strong>Description:</strong> {propertiesNode?.data?.description}</p>
<p><strong>Inputs:</strong> {getNodeConnections(propertiesNode.id).inputs}</p>
<p><strong>Outputs:</strong> {getNodeConnections(propertiesNode.id).outputs}</p>
{propertiesNode.data?.variableName !== undefined && (
<p><strong>Variable Name:</strong> {propertiesNode.data.variableName}</p>
)}
{propertiesNode.data?.variableValue !== undefined && (
<p><strong>Variable Value:</strong> {propertiesNode.data.variableValue}</p>
)}
{propertiesNode.data?.printVariable !== undefined && (
<p><strong>Variable to Print:</strong> {propertiesNode.data.printVariable}</p>
)}
<button onClick={closePropertiesSidebar}>Close</button>
</div>
)}
</div>
);
};
const sidebarButtonStyle = {
padding: '10px 20px',
fontSize: '16px',
backgroundColor: '#007bff',
color: '#fff',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
};
export default Flow;

View File

@@ -0,0 +1,128 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-osx-smoothing: grayscale;
background-color: #121212;
color: #e0e0e0;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
button {
background-color: #333;
color: #e0e0e0;
padding: 10px;
border: none;
border-radius: 4px;
}
button:hover {
background-color: #555;
}
input, textarea {
background-color: #333;
color: #e0e0e0;
border: 1px solid #555;
padding: 8px;
border-radius: 4px;
width: calc(100% - 18px);
box-sizing: border-box;
margin-top: 5px;
}
input::placeholder, textarea::placeholder {
color: #aaa;
}
.modal {
position: absolute;
top: 50%;
left: 50%;
right: auto;
bottom: auto;
margin-right: -50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border: 1px solid #ccc;
border-radius: 4px;
}
.overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.75);
}
.modal h2 {
margin-top: 0;
}
.modal button {
margin-right: 10px;
}
.modal form {
display: flex;
flex-direction: column;
}
.modal form div {
margin-bottom: 15px;
}
.sidebar {
position: fixed;
top: 0;
left: -600px;
width: 350px;
height: 100%;
background-color: #333;
color: #fff;
padding: 20px;
transition: left 0.3s ease;
z-index: 1000;
overflow-y: auto;
}
.sidebar.open {
left: 0;
}
.sidebar h3 {
margin: 0 0 20px;
}
.properties-sidebar {
position: fixed;
top: 0;
right: -600px;
width: 300px;
height: 100%;
background-color: #333;
color: #fff;
padding: 20px;
transition: right 0.3s ease;
z-index: 1000;
overflow-y: auto;
}
.properties-sidebar.open {
right: 0;
}
.properties-sidebar h3 {
margin: 0 0 20px;
}

View File

@@ -0,0 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -0,0 +1 @@
/// <reference types="react-scripts" />

View File

@@ -0,0 +1,15 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;

View File

@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}