Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -13,8 +13,8 @@ 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 = '
|
| 18 |
|
| 19 |
app.post("/api/ai-build", async (req, res) => {
|
| 20 |
try {
|
|
@@ -22,52 +22,56 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 22 |
|
| 23 |
console.log("------------------------------------------------");
|
| 24 |
console.log("π₯ INSTRUCTION:", instruction);
|
| 25 |
-
if(selection) console.log(" Selected:", selection.name
|
| 26 |
|
| 27 |
-
// 1. Script
|
| 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: `
|
| 32 |
}
|
| 33 |
|
| 34 |
-
// 2. Log
|
| 35 |
if (logContext) {
|
| 36 |
-
console.log("π LOGS
|
| 37 |
return res.json({ success: true, message: "Logs analyzed." });
|
| 38 |
}
|
| 39 |
|
| 40 |
-
// 3. Hierarchy
|
| 41 |
if (hierarchyContext) {
|
| 42 |
-
console.log(
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
-
// 4. Demo Triggers
|
| 48 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 49 |
-
const luaCode =
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
p.
|
| 53 |
-
|
| 54 |
-
|
| 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 |
-
//
|
| 68 |
-
console.log(" π Requesting Hierarchy Scan...");
|
| 69 |
return res.json({ action: "read_hierarchy" });
|
| 70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
return res.json({ success: true, message: "Thinking..." });
|
| 73 |
|
|
|
|
| 13 |
app.use(cors());
|
| 14 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 15 |
|
| 16 |
+
// Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT', 'FETCH_LOGS', 'SCAN_HIERARCHY', 'SCAN_SERVER_SERVICE'
|
| 17 |
+
const DEMO_MODE = 'SCAN_SERVER_SERVICE';
|
| 18 |
|
| 19 |
app.post("/api/ai-build", async (req, res) => {
|
| 20 |
try {
|
|
|
|
| 22 |
|
| 23 |
console.log("------------------------------------------------");
|
| 24 |
console.log("π₯ INSTRUCTION:", instruction);
|
| 25 |
+
if(selection) console.log(" Selected:", selection.name);
|
| 26 |
|
| 27 |
+
// 1. Script Response
|
| 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: `Read ${scriptContext.targetName}.` });
|
| 32 |
}
|
| 33 |
|
| 34 |
+
// 2. Log Response
|
| 35 |
if (logContext) {
|
| 36 |
+
console.log("π LOGS:", logContext.logs.substring(0, 200) + "...");
|
| 37 |
return res.json({ success: true, message: "Logs analyzed." });
|
| 38 |
}
|
| 39 |
|
| 40 |
+
// 3. Hierarchy Response
|
| 41 |
if (hierarchyContext) {
|
| 42 |
+
console.log(`π³ HIERARCHY [${hierarchyContext.rootName}]:`);
|
| 43 |
+
// Limit log output so terminal doesn't flood
|
| 44 |
+
const treePreview = hierarchyContext.tree.split('\n').slice(0, 20).join('\n');
|
| 45 |
+
console.log(treePreview);
|
| 46 |
+
console.log("... (and more)");
|
| 47 |
+
return res.json({ success: true, message: `Scanned ${hierarchyContext.rootName}.` });
|
| 48 |
}
|
| 49 |
|
| 50 |
+
// 4. Demo Triggers
|
| 51 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 52 |
+
const luaCode = `\`\`\`lua
|
| 53 |
+
local p = Instance.new("Part", workspace)
|
| 54 |
+
p.Position = Vector3.new(0,20,0)
|
| 55 |
+
p.Anchored = true
|
| 56 |
+
print("Created Part")
|
| 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 === 'SCAN_HIERARCHY') {
|
| 64 |
+
// Scans whatever is selected (default behavior)
|
|
|
|
| 65 |
return res.json({ action: "read_hierarchy" });
|
| 66 |
}
|
| 67 |
+
else if (DEMO_MODE === 'SCAN_SERVER_SERVICE') {
|
| 68 |
+
// NEW: Specifically asks to scan ServerScriptService
|
| 69 |
+
console.log(" π Asking to scan ServerScriptService...");
|
| 70 |
+
return res.json({
|
| 71 |
+
action: "read_hierarchy",
|
| 72 |
+
targetName: "ServerScriptService"
|
| 73 |
+
});
|
| 74 |
+
}
|
| 75 |
|
| 76 |
return res.json({ success: true, message: "Thinking..." });
|
| 77 |
|