Spaces:
Running
Running
Commit ·
3589760
1
Parent(s): 5f43c64
commit initial 09-12-2025 001
Browse files- package-lock.json +0 -0
- package.json +3 -0
- src/App.js +58 -16
- src/agent/assistant.js +12 -0
- src/agent/projectGenerator.js +22 -0
- src/agent/runner.js +7 -0
- src/apiClient.js +7 -0
package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
CHANGED
|
@@ -3,12 +3,15 @@
|
|
| 3 |
"version": "0.1.0",
|
| 4 |
"private": true,
|
| 5 |
"dependencies": {
|
|
|
|
| 6 |
"@testing-library/dom": "^10.4.0",
|
| 7 |
"@testing-library/jest-dom": "^6.6.3",
|
| 8 |
"@testing-library/react": "^16.3.0",
|
| 9 |
"@testing-library/user-event": "^13.5.0",
|
|
|
|
| 10 |
"react": "^19.1.0",
|
| 11 |
"react-dom": "^19.1.0",
|
|
|
|
| 12 |
"react-scripts": "5.0.1",
|
| 13 |
"web-vitals": "^2.1.4"
|
| 14 |
},
|
|
|
|
| 3 |
"version": "0.1.0",
|
| 4 |
"private": true,
|
| 5 |
"dependencies": {
|
| 6 |
+
"@monaco-editor/react": "^4.7.0",
|
| 7 |
"@testing-library/dom": "^10.4.0",
|
| 8 |
"@testing-library/jest-dom": "^6.6.3",
|
| 9 |
"@testing-library/react": "^16.3.0",
|
| 10 |
"@testing-library/user-event": "^13.5.0",
|
| 11 |
+
"axios": "^1.13.2",
|
| 12 |
"react": "^19.1.0",
|
| 13 |
"react-dom": "^19.1.0",
|
| 14 |
+
"react-hot-toast": "^2.6.0",
|
| 15 |
"react-scripts": "5.0.1",
|
| 16 |
"web-vitals": "^2.1.4"
|
| 17 |
},
|
src/App.js
CHANGED
|
@@ -1,23 +1,65 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
|
|
|
|
|
|
| 3 |
|
| 4 |
function App() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
return (
|
| 6 |
-
<div
|
| 7 |
-
<
|
| 8 |
-
<
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
>
|
| 18 |
-
|
| 19 |
-
</
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
</div>
|
| 22 |
);
|
| 23 |
}
|
|
|
|
| 1 |
+
import { useState } from "react";
|
| 2 |
+
import Editor from "@monaco-editor/react";
|
| 3 |
+
import { askAgent } from "./agent/assistant";
|
| 4 |
+
import { runCode } from "./agent/runner";
|
| 5 |
|
| 6 |
function App() {
|
| 7 |
+
const [code, setCode] = useState("# Python\nprint('Hello from IDE')");
|
| 8 |
+
const [output, setOutput] = useState("");
|
| 9 |
+
const [prompt, setPrompt] = useState("");
|
| 10 |
+
|
| 11 |
+
const handleRun = async () => {
|
| 12 |
+
const res = await runCode(code);
|
| 13 |
+
setOutput(res.output);
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
const handleAsk = async () => {
|
| 17 |
+
const reply = await askAgent(
|
| 18 |
+
`Improve or fix this code and return only the updated code.\n\n${prompt}`,
|
| 19 |
+
[{ role: "user", content: code }]
|
| 20 |
+
);
|
| 21 |
+
setCode(reply);
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
return (
|
| 25 |
+
<div style={{ display: "flex", height: "100vh", background: "#111" }}>
|
| 26 |
+
<div style={{ flex: 3 }}>
|
| 27 |
+
<Editor
|
| 28 |
+
height="100vh"
|
| 29 |
+
theme="vs-dark"
|
| 30 |
+
defaultLanguage="python"
|
| 31 |
+
value={code}
|
| 32 |
+
onChange={setCode}
|
| 33 |
+
options={{ minimap: { enabled: true }, fontSize: 14 }}
|
| 34 |
+
/>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<div style={{ flex: 1, padding: 16, color: "#fff" }}>
|
| 38 |
+
<h3>💻 Output</h3>
|
| 39 |
+
<pre
|
| 40 |
+
style={{
|
| 41 |
+
background: "#000",
|
| 42 |
+
padding: 8,
|
| 43 |
+
height: "40vh",
|
| 44 |
+
overflow: "auto",
|
| 45 |
+
borderRadius: 4,
|
| 46 |
+
}}
|
| 47 |
>
|
| 48 |
+
{output}
|
| 49 |
+
</pre>
|
| 50 |
+
<button onClick={handleRun}>▶ Run</button>
|
| 51 |
+
|
| 52 |
+
<h3 style={{ marginTop: 24 }}>🤖 Agent Prompt</h3>
|
| 53 |
+
<textarea
|
| 54 |
+
style={{ width: "100%", height: "20vh" }}
|
| 55 |
+
value={prompt}
|
| 56 |
+
onChange={(e) => setPrompt(e.target.value)}
|
| 57 |
+
placeholder="Explain, optimize, or add a feature..."
|
| 58 |
+
/>
|
| 59 |
+
<button onClick={handleAsk} style={{ marginTop: 8 }}>
|
| 60 |
+
Ask Agent
|
| 61 |
+
</button>
|
| 62 |
+
</div>
|
| 63 |
</div>
|
| 64 |
);
|
| 65 |
}
|
src/agent/assistant.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// src/agent/assistant.js
|
| 2 |
+
import { api } from "../apiClient";
|
| 3 |
+
|
| 4 |
+
export async function askAgent(message, history = []) {
|
| 5 |
+
const res = await api.post(
|
| 6 |
+
"/chat-stream",
|
| 7 |
+
{ message, history },
|
| 8 |
+
{ responseType: "text" } // backend returns text/plain
|
| 9 |
+
);
|
| 10 |
+
|
| 11 |
+
return res.data; // whole reply text
|
| 12 |
+
}
|
src/agent/projectGenerator.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// src/agent/projectGenerator.js
|
| 2 |
+
import { api } from "../apiClient";
|
| 3 |
+
|
| 4 |
+
export async function generateProject(file, frontend, backend, database) {
|
| 5 |
+
const formData = new FormData();
|
| 6 |
+
formData.append("file", file);
|
| 7 |
+
formData.append("frontend", frontend);
|
| 8 |
+
formData.append("backend", backend);
|
| 9 |
+
formData.append("database", database);
|
| 10 |
+
|
| 11 |
+
const res = await api.post("/chat-stream-doc", formData, {
|
| 12 |
+
responseType: "blob", // you’re getting ZIP back
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
// trigger download
|
| 16 |
+
const url = window.URL.createObjectURL(new Blob([res.data]));
|
| 17 |
+
const a = document.createElement("a");
|
| 18 |
+
a.href = url;
|
| 19 |
+
a.download = "generated_project.zip";
|
| 20 |
+
a.click();
|
| 21 |
+
window.URL.revokeObjectURL(url);
|
| 22 |
+
}
|
src/agent/runner.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// src/agent/runner.js
|
| 2 |
+
import { api } from "../apiClient";
|
| 3 |
+
|
| 4 |
+
export async function runCode(code, filename = "main.py") {
|
| 5 |
+
const res = await api.post("/execute", { code, filename });
|
| 6 |
+
return res.data; // { output, error }
|
| 7 |
+
}
|
src/apiClient.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
|
| 3 |
+
const API_BASE = process.env.REACT_APP_API_BASE; // 👈 CRA uses REACT_APP_
|
| 4 |
+
|
| 5 |
+
export const api = axios.create({
|
| 6 |
+
baseURL: API_BASE,
|
| 7 |
+
});
|