Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -11,85 +11,65 @@ const PORT = process.env.PORT || 7860;
|
|
| 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 |
-
//
|
| 18 |
-
|
| 19 |
-
const DEMO_MODE = 'FETCH_SCRIPT'; // 'FETCH_LOGS';
|
| 20 |
|
| 21 |
app.post("/api/ai-build", async (req, res) => {
|
| 22 |
try {
|
| 23 |
-
|
| 24 |
-
const { instruction, state, scriptContext, logContext } = req.body;
|
| 25 |
|
| 26 |
-
console.log("
|
| 27 |
-
console.log("
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
|
| 31 |
-
const lll = JSON.stringify(state.flatList);
|
| 32 |
-
console.log(` Flat list: ${lll.length}`);
|
| 33 |
-
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
// 1. **HANDLE SCRIPT SOURCE (Loop Step 2)**
|
| 37 |
if (scriptContext) {
|
| 38 |
-
console.log(
|
| 39 |
-
console.log(
|
| 40 |
-
|
| 41 |
-
return res.json({
|
| 42 |
-
success: true,
|
| 43 |
-
message: `Source for ${scriptContext.targetName} received. Loop stopped.`
|
| 44 |
-
});
|
| 45 |
}
|
| 46 |
|
| 47 |
-
// 2.
|
| 48 |
if (logContext) {
|
| 49 |
-
console.log("
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
-
//
|
| 60 |
-
|
| 61 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 62 |
const luaCode = `
|
| 63 |
\`\`\`lua
|
| 64 |
local p = Instance.new("Part")
|
| 65 |
-
p.Name = "
|
| 66 |
-
p.Color = Color3.new(1,0
|
| 67 |
-
p.Position = Vector3.new(0,
|
| 68 |
-
p.Anchored = true
|
| 69 |
p.Parent = workspace
|
| 70 |
-
print("Part created by AI")
|
| 71 |
\`\`\`
|
| 72 |
`;
|
| 73 |
return res.send(luaCode);
|
| 74 |
}
|
| 75 |
-
|
| 76 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 77 |
-
|
| 78 |
-
return res.json({
|
| 79 |
-
action: "read_script",
|
| 80 |
-
targetName: "BikeLogic" // Ensure a script named this exists to test
|
| 81 |
-
});
|
| 82 |
}
|
| 83 |
-
|
| 84 |
else if (DEMO_MODE === 'FETCH_LOGS') {
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
-
|
| 92 |
-
return res.json({ success: true, message: "Snapshot received. Waiting for demo trigger..." });
|
| 93 |
|
| 94 |
} catch (err) {
|
| 95 |
console.error("Server Error:", err);
|
|
@@ -97,4 +77,4 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 97 |
}
|
| 98 |
});
|
| 99 |
|
| 100 |
-
app.listen(PORT, () => console.log(`π Server running on port ${PORT}.
|
|
|
|
| 11 |
|
| 12 |
const app = express();
|
| 13 |
app.use(cors());
|
|
|
|
| 14 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 15 |
|
| 16 |
+
// Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT', 'FETCH_LOGS', 'SCAN_HIERARCHY'
|
| 17 |
+
const DEMO_MODE = 'SCAN_HIERARCHY';
|
|
|
|
| 18 |
|
| 19 |
app.post("/api/ai-build", async (req, res) => {
|
| 20 |
try {
|
| 21 |
+
const { instruction, selection, scriptContext, logContext, hierarchyContext } = req.body;
|
|
|
|
| 22 |
|
| 23 |
+
console.log("------------------------------------------------");
|
| 24 |
+
console.log("π₯ INSTRUCTION:", instruction);
|
| 25 |
+
if(selection) console.log(" Selected:", selection.name, `(${selection.className})`);
|
| 26 |
|
| 27 |
+
// 1. Script Loop
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if (scriptContext) {
|
| 29 |
+
console.log(`π SCRIPT [${scriptContext.targetName}]:`);
|
| 30 |
+
console.log(scriptContext.scriptSource.substring(0, 150) + "...\n");
|
| 31 |
+
return res.json({ success: true, message: `Source received.` });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
+
// 2. Log Loop
|
| 35 |
if (logContext) {
|
| 36 |
+
console.log("π LOGS RECEIVED:\n", logContext.logs);
|
| 37 |
+
return res.json({ success: true, message: "Logs analyzed." });
|
| 38 |
+
}
|
| 39 |
|
| 40 |
+
// 3. Hierarchy Loop (New)
|
| 41 |
+
if (hierarchyContext) {
|
| 42 |
+
console.log("π³ HIERARCHY RECEIVED:");
|
| 43 |
+
console.log(hierarchyContext.tree);
|
| 44 |
+
return res.json({ success: true, message: "Hierarchy analyzed." });
|
| 45 |
}
|
| 46 |
|
| 47 |
+
// 4. Demo Triggers (Initial Request)
|
|
|
|
| 48 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 49 |
const luaCode = `
|
| 50 |
\`\`\`lua
|
| 51 |
local p = Instance.new("Part")
|
| 52 |
+
p.Name = "AI_Part"
|
| 53 |
+
p.Color = Color3.new(0,1,0)
|
| 54 |
+
p.Position = Vector3.new(0, 10, 0)
|
|
|
|
| 55 |
p.Parent = workspace
|
|
|
|
| 56 |
\`\`\`
|
| 57 |
`;
|
| 58 |
return res.send(luaCode);
|
| 59 |
}
|
|
|
|
| 60 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 61 |
+
return res.json({ action: "read_script", targetName: "BikeLogic" });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
}
|
|
|
|
| 63 |
else if (DEMO_MODE === 'FETCH_LOGS') {
|
| 64 |
+
return res.json({ action: "read_logs" });
|
| 65 |
+
}
|
| 66 |
+
else if (DEMO_MODE === 'SCAN_HIERARCHY') {
|
| 67 |
+
// AI decides it needs to see the world before acting
|
| 68 |
+
console.log(" π Requesting Hierarchy Scan...");
|
| 69 |
+
return res.json({ action: "read_hierarchy" });
|
| 70 |
}
|
| 71 |
|
| 72 |
+
return res.json({ success: true, message: "Thinking..." });
|
|
|
|
| 73 |
|
| 74 |
} catch (err) {
|
| 75 |
console.error("Server Error:", err);
|
|
|
|
| 77 |
}
|
| 78 |
});
|
| 79 |
|
| 80 |
+
app.listen(PORT, () => console.log(`π Server running on port ${PORT}. Mode: ${DEMO_MODE}`));
|