Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
-
// server.js
|
| 2 |
import express from "express";
|
| 3 |
import bodyParser from "body-parser";
|
| 4 |
import cors from "cors";
|
| 5 |
-
import fs from "fs";
|
| 6 |
import path from "path";
|
| 7 |
import { fileURLToPath } from "url";
|
| 8 |
|
|
@@ -12,14 +11,16 @@ const PORT = process.env.PORT || 7860;
|
|
| 12 |
|
| 13 |
const app = express();
|
| 14 |
app.use(cors());
|
|
|
|
| 15 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 16 |
|
| 17 |
// === DEMO CONTROLLER ===
|
| 18 |
// Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT'
|
| 19 |
-
const DEMO_MODE = 'FETCH_SCRIPT';
|
| 20 |
|
| 21 |
app.post("/api/ai-build", async (req, res) => {
|
| 22 |
try {
|
|
|
|
| 23 |
const { instruction, state, scriptContext } = req.body;
|
| 24 |
|
| 25 |
console.log("📥 Received Request");
|
|
@@ -27,7 +28,6 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 27 |
|
| 28 |
if(state && state.flatList) {
|
| 29 |
console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
|
| 30 |
-
//console.log(`Flatlist : ${JSON.stringify(state.flatList).length}`);
|
| 31 |
}
|
| 32 |
|
| 33 |
// 1. **FIXED LOOP LOGIC:** IF WE RECEIVED SCRIPT SOURCE (Step 2 of the loop)
|
|
@@ -36,27 +36,21 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 36 |
console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
|
| 37 |
|
| 38 |
// **STOP THE LOOP:** Send back a simple JSON message instead of executable code.
|
| 39 |
-
// In a real application, the AI would generate the final Lua code here.
|
| 40 |
return res.json({
|
| 41 |
success: true,
|
| 42 |
message: `Source for ${scriptContext.targetName} received and analyzed. Loop stopped in demo mode.`
|
| 43 |
});
|
| 44 |
|
| 45 |
-
//
|
| 46 |
/*
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
print("Final Code Executed!")
|
| 51 |
-
\`\`\`
|
| 52 |
-
`;
|
| 53 |
-
return res.send(finalCode);
|
| 54 |
*/
|
| 55 |
}
|
| 56 |
|
| 57 |
// 2. DEMO RESPONSES (Step 1 of the loop/initial request)
|
| 58 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 59 |
-
// ... (BUILD_PART logic remains the same)
|
| 60 |
const luaCode = `
|
| 61 |
\`\`\`lua
|
| 62 |
-- AI Generated Demo: Part Builder
|
|
|
|
| 1 |
+
// server.js
|
| 2 |
import express from "express";
|
| 3 |
import bodyParser from "body-parser";
|
| 4 |
import cors from "cors";
|
|
|
|
| 5 |
import path from "path";
|
| 6 |
import { fileURLToPath } from "url";
|
| 7 |
|
|
|
|
| 11 |
|
| 12 |
const app = express();
|
| 13 |
app.use(cors());
|
| 14 |
+
// Increased limit for large snapshot payloads
|
| 15 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 16 |
|
| 17 |
// === DEMO CONTROLLER ===
|
| 18 |
// Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT'
|
| 19 |
+
const DEMO_MODE = 'FETCH_SCRIPT';
|
| 20 |
|
| 21 |
app.post("/api/ai-build", async (req, res) => {
|
| 22 |
try {
|
| 23 |
+
// We expect 'scriptContext' if this is a follow-up request from the plugin
|
| 24 |
const { instruction, state, scriptContext } = req.body;
|
| 25 |
|
| 26 |
console.log("📥 Received Request");
|
|
|
|
| 28 |
|
| 29 |
if(state && state.flatList) {
|
| 30 |
console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
// 1. **FIXED LOOP LOGIC:** IF WE RECEIVED SCRIPT SOURCE (Step 2 of the loop)
|
|
|
|
| 36 |
console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
|
| 37 |
|
| 38 |
// **STOP THE LOOP:** Send back a simple JSON message instead of executable code.
|
|
|
|
| 39 |
return res.json({
|
| 40 |
success: true,
|
| 41 |
message: `Source for ${scriptContext.targetName} received and analyzed. Loop stopped in demo mode.`
|
| 42 |
});
|
| 43 |
|
| 44 |
+
// In a real scenario, you would perform AI analysis here and send back new code:
|
| 45 |
/*
|
| 46 |
+
return res.json({
|
| 47 |
+
code: `print("I have updated ${scriptContext.targetName}")`
|
| 48 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
*/
|
| 50 |
}
|
| 51 |
|
| 52 |
// 2. DEMO RESPONSES (Step 1 of the loop/initial request)
|
| 53 |
if (DEMO_MODE === 'BUILD_PART') {
|
|
|
|
| 54 |
const luaCode = `
|
| 55 |
\`\`\`lua
|
| 56 |
-- AI Generated Demo: Part Builder
|