Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -13,8 +13,12 @@ const app = express();
|
|
| 13 |
app.use(cors());
|
| 14 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 15 |
|
| 16 |
-
//
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
app.post("/api/ai-build", async (req, res) => {
|
| 20 |
try {
|
|
@@ -22,58 +26,53 @@ 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: `Read ${scriptContext.targetName}.` });
|
| 32 |
}
|
| 33 |
|
| 34 |
-
// 2.
|
| 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 |
-
|
| 44 |
-
const treePreview = hierarchyContext.tree;//.split('\n').slice(0, 200).join('\n');
|
| 45 |
console.log(treePreview);
|
| 46 |
-
//console.log("... (and more)");
|
| 47 |
return res.json({ success: true, message: `Scanned ${hierarchyContext.rootName}.` });
|
| 48 |
}
|
| 49 |
|
| 50 |
-
//
|
| 51 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 52 |
-
|
| 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 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
});
|
| 68 |
}
|
| 69 |
-
else if (DEMO_MODE === '
|
| 70 |
-
//
|
| 71 |
-
console.log(" π Asking to scan
|
| 72 |
return res.json({
|
| 73 |
action: "read_hierarchy",
|
| 74 |
-
targetName: "
|
| 75 |
});
|
| 76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
return res.json({ success: true, message: "Thinking..." });
|
| 79 |
|
|
|
|
| 13 |
app.use(cors());
|
| 14 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 15 |
|
| 16 |
+
// === TEST MODES ===
|
| 17 |
+
// 'BUILD_PART' -> Makes a part
|
| 18 |
+
// 'FETCH_SCRIPT' -> Finds a script by name anywhere
|
| 19 |
+
// 'SCAN_SERVER_STORAGE' -> Scans "ServerStorage" explicitly
|
| 20 |
+
// 'SCAN_SELECTION' -> Scans whatever you clicked on in Roblox
|
| 21 |
+
const DEMO_MODE = 'SCAN_SERVER_STORAGE';
|
| 22 |
|
| 23 |
app.post("/api/ai-build", async (req, res) => {
|
| 24 |
try {
|
|
|
|
| 26 |
|
| 27 |
console.log("------------------------------------------------");
|
| 28 |
console.log("π₯ INSTRUCTION:", instruction);
|
|
|
|
| 29 |
|
| 30 |
+
// 1. Script Found
|
| 31 |
if (scriptContext) {
|
| 32 |
+
console.log(`π SCRIPT FOUND [${scriptContext.targetName}]:`);
|
| 33 |
+
console.log(` Parent: ${scriptContext.parentName}`);
|
| 34 |
console.log(scriptContext.scriptSource.substring(0, 150) + "...\n");
|
| 35 |
+
return res.json({ success: true, message: `Read ${scriptContext.targetName} successfully.` });
|
| 36 |
}
|
| 37 |
|
| 38 |
+
// 2. Hierarchy Scanned
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
if (hierarchyContext) {
|
| 40 |
+
console.log(`π³ SCANNED HIERARCHY [${hierarchyContext.rootName}]:`);
|
| 41 |
+
const treePreview = hierarchyContext.tree.split('\n').slice(0, 20).join('\n');
|
|
|
|
| 42 |
console.log(treePreview);
|
|
|
|
| 43 |
return res.json({ success: true, message: `Scanned ${hierarchyContext.rootName}.` });
|
| 44 |
}
|
| 45 |
|
| 46 |
+
// 3. Demo Triggers
|
| 47 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 48 |
+
return res.send(`\`\`\`lua
|
| 49 |
local p = Instance.new("Part", workspace)
|
| 50 |
p.Position = Vector3.new(0,20,0)
|
| 51 |
p.Anchored = true
|
| 52 |
print("Created Part")
|
| 53 |
+
\`\`\``);
|
|
|
|
| 54 |
}
|
| 55 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 56 |
+
// AI asks to find "MyServerScript" (put this script in ServerScriptService to test)
|
| 57 |
+
console.log(" π Asking to find 'MyServerScript'...");
|
| 58 |
+
return res.json({
|
| 59 |
+
action: "read_script",
|
| 60 |
+
targetName: "BikeLogic"
|
| 61 |
+
});
|
|
|
|
| 62 |
}
|
| 63 |
+
else if (DEMO_MODE === 'SCAN_SERVER_STORAGE') {
|
| 64 |
+
// AI explicitly asks to see what's in ServerStorage
|
| 65 |
+
console.log(" π Asking to scan ServerStorage...");
|
| 66 |
return res.json({
|
| 67 |
action: "read_hierarchy",
|
| 68 |
+
targetName: "ServerStorage"
|
| 69 |
});
|
| 70 |
}
|
| 71 |
+
else if (DEMO_MODE === 'SCAN_SELECTION') {
|
| 72 |
+
// AI asks to scan whatever you have selected
|
| 73 |
+
console.log(" π Asking to scan selection...");
|
| 74 |
+
return res.json({ action: "read_hierarchy", targetName: "Workspace" });
|
| 75 |
+
}
|
| 76 |
|
| 77 |
return res.json({ success: true, message: "Thinking..." });
|
| 78 |
|