Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -15,13 +15,13 @@ 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 = '
|
| 20 |
|
| 21 |
app.post("/api/ai-build", async (req, res) => {
|
| 22 |
try {
|
| 23 |
-
//
|
| 24 |
-
const { instruction, state, scriptContext } = req.body;
|
| 25 |
|
| 26 |
console.log("π₯ Received Request");
|
| 27 |
console.log(" Instruction:", instruction);
|
|
@@ -30,54 +30,63 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 30 |
console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
|
| 31 |
}
|
| 32 |
|
| 33 |
-
// 1. **
|
| 34 |
if (scriptContext) {
|
| 35 |
console.log(" π Received Script Source for:", scriptContext.targetName);
|
| 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
|
| 42 |
});
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return res.json({
|
| 47 |
-
|
|
|
|
| 48 |
});
|
| 49 |
-
*/
|
| 50 |
}
|
| 51 |
|
| 52 |
-
//
|
|
|
|
| 53 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 54 |
const luaCode = `
|
| 55 |
\`\`\`lua
|
| 56 |
-
-- AI Generated Demo: Part Builder
|
| 57 |
local p = Instance.new("Part")
|
| 58 |
-
p.Name = "
|
| 59 |
-
p.Color = Color3.
|
| 60 |
-
p.
|
| 61 |
-
p.Position = Vector3.new(0, 10, 0)
|
| 62 |
p.Anchored = true
|
| 63 |
p.Parent = workspace
|
| 64 |
-
print("
|
| 65 |
\`\`\`
|
| 66 |
`;
|
| 67 |
return res.send(luaCode);
|
| 68 |
}
|
| 69 |
|
| 70 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 71 |
-
console.log(" π Sending Fetch Request
|
| 72 |
-
// This tells the plugin to find a script named "BikeLogic" and send it back
|
| 73 |
return res.json({
|
| 74 |
action: "read_script",
|
| 75 |
-
targetName: "BikeLogic"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
});
|
| 77 |
}
|
| 78 |
|
| 79 |
// Default
|
| 80 |
-
return res.json({ success: true,
|
| 81 |
|
| 82 |
} catch (err) {
|
| 83 |
console.error("Server Error:", err);
|
|
|
|
| 15 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 16 |
|
| 17 |
// === DEMO CONTROLLER ===
|
| 18 |
+
// Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT', 'FETCH_LOGS'
|
| 19 |
+
const DEMO_MODE = 'FETCH_LOGS';
|
| 20 |
|
| 21 |
app.post("/api/ai-build", async (req, res) => {
|
| 22 |
try {
|
| 23 |
+
// Destructure specifically to look for follow-up contexts
|
| 24 |
+
const { instruction, state, scriptContext, logContext } = req.body;
|
| 25 |
|
| 26 |
console.log("π₯ Received Request");
|
| 27 |
console.log(" Instruction:", instruction);
|
|
|
|
| 30 |
console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
|
| 31 |
}
|
| 32 |
|
| 33 |
+
// 1. **HANDLE SCRIPT SOURCE (Loop Step 2)**
|
| 34 |
if (scriptContext) {
|
| 35 |
console.log(" π Received Script Source for:", scriptContext.targetName);
|
| 36 |
console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
|
| 37 |
|
|
|
|
| 38 |
return res.json({
|
| 39 |
success: true,
|
| 40 |
+
message: `Source for ${scriptContext.targetName} received. Loop stopped.`
|
| 41 |
});
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// 2. **HANDLE LOGS (Loop Step 2)**
|
| 45 |
+
if (logContext) {
|
| 46 |
+
console.log(" π Received Console Logs:");
|
| 47 |
+
console.log(" --- LOGS ---\n", logContext.logs);
|
| 48 |
+
console.log(" --- END LOGS ---");
|
| 49 |
+
|
| 50 |
return res.json({
|
| 51 |
+
success: true,
|
| 52 |
+
message: "Console logs received and analyzed. Loop stopped."
|
| 53 |
});
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
+
// 3. **DEMO TRIGGERS (Loop Step 1)**
|
| 57 |
+
|
| 58 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 59 |
const luaCode = `
|
| 60 |
\`\`\`lua
|
|
|
|
| 61 |
local p = Instance.new("Part")
|
| 62 |
+
p.Name = "AI_Cube"
|
| 63 |
+
p.Color = Color3.new(1,0,0)
|
| 64 |
+
p.Position = Vector3.new(0, 5, 0)
|
|
|
|
| 65 |
p.Anchored = true
|
| 66 |
p.Parent = workspace
|
| 67 |
+
print("Part created by AI")
|
| 68 |
\`\`\`
|
| 69 |
`;
|
| 70 |
return res.send(luaCode);
|
| 71 |
}
|
| 72 |
|
| 73 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 74 |
+
console.log(" π Sending Fetch Script Request");
|
|
|
|
| 75 |
return res.json({
|
| 76 |
action: "read_script",
|
| 77 |
+
targetName: "BikeLogic" // Ensure a script named this exists to test
|
| 78 |
+
});
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
else if (DEMO_MODE === 'FETCH_LOGS') {
|
| 82 |
+
console.log(" π Sending Fetch Logs Request");
|
| 83 |
+
return res.json({
|
| 84 |
+
action: "read_logs"
|
| 85 |
});
|
| 86 |
}
|
| 87 |
|
| 88 |
// Default
|
| 89 |
+
return res.json({ success: true, message: "Snapshot received. Waiting for demo trigger..." });
|
| 90 |
|
| 91 |
} catch (err) {
|
| 92 |
console.error("Server Error:", err);
|