Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -14,11 +14,12 @@ app.use(cors());
|
|
| 14 |
app.use(bodyParser.json({ limit: "50mb" }));
|
| 15 |
|
| 16 |
// === TEST MODES ===
|
| 17 |
-
// 'BUILD_PART'
|
| 18 |
-
// 'FETCH_SCRIPT'
|
| 19 |
// 'SCAN_SERVER_STORAGE' -> Scans "ServerStorage" explicitly
|
| 20 |
-
// 'SCAN_SELECTION'
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
app.post("/api/ai-build", async (req, res) => {
|
| 24 |
try {
|
|
@@ -27,7 +28,7 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 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}`);
|
|
@@ -35,7 +36,7 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 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');
|
|
@@ -43,7 +44,20 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 43 |
return res.json({ success: true, message: `Scanned ${hierarchyContext.rootName}.` });
|
| 44 |
}
|
| 45 |
|
| 46 |
-
// 3.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 48 |
return res.send(`\`\`\`lua
|
| 49 |
local p = Instance.new("Part", workspace)
|
|
@@ -53,15 +67,13 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 53 |
\`\`\``);
|
| 54 |
}
|
| 55 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 56 |
-
|
| 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",
|
|
@@ -69,9 +81,12 @@ app.post("/api/ai-build", async (req, res) => {
|
|
| 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"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
|
| 77 |
return res.json({ success: true, message: "Thinking..." });
|
|
|
|
| 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 |
+
// 'FETCH_LOGS' -> Fetches the recent Output logs
|
| 22 |
+
const DEMO_MODE = 'FETCH_LOGS';
|
| 23 |
|
| 24 |
app.post("/api/ai-build", async (req, res) => {
|
| 25 |
try {
|
|
|
|
| 28 |
console.log("------------------------------------------------");
|
| 29 |
console.log("π₯ INSTRUCTION:", instruction);
|
| 30 |
|
| 31 |
+
// 1. Script Found Response
|
| 32 |
if (scriptContext) {
|
| 33 |
console.log(`π SCRIPT FOUND [${scriptContext.targetName}]:`);
|
| 34 |
console.log(` Parent: ${scriptContext.parentName}`);
|
|
|
|
| 36 |
return res.json({ success: true, message: `Read ${scriptContext.targetName} successfully.` });
|
| 37 |
}
|
| 38 |
|
| 39 |
+
// 2. Hierarchy Scanned Response
|
| 40 |
if (hierarchyContext) {
|
| 41 |
console.log(`π³ SCANNED HIERARCHY [${hierarchyContext.rootName}]:`);
|
| 42 |
const treePreview = hierarchyContext.tree.split('\n').slice(0, 20).join('\n');
|
|
|
|
| 44 |
return res.json({ success: true, message: `Scanned ${hierarchyContext.rootName}.` });
|
| 45 |
}
|
| 46 |
|
| 47 |
+
// 3. Logs Received Response (RESTORED)
|
| 48 |
+
if (logContext) {
|
| 49 |
+
console.log("π LOGS RECEIVED:");
|
| 50 |
+
console.log("------------------------------------------------");
|
| 51 |
+
// Print last 500 chars to avoid flooding terminal
|
| 52 |
+
const logPreview = logContext.logs.length > 500
|
| 53 |
+
? "..." + logContext.logs.substring(logContext.logs.length - 500)
|
| 54 |
+
: logContext.logs;
|
| 55 |
+
console.log(logPreview);
|
| 56 |
+
console.log("------------------------------------------------");
|
| 57 |
+
return res.json({ success: true, message: "Logs received and analyzed." });
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// 4. Demo Triggers
|
| 61 |
if (DEMO_MODE === 'BUILD_PART') {
|
| 62 |
return res.send(`\`\`\`lua
|
| 63 |
local p = Instance.new("Part", workspace)
|
|
|
|
| 67 |
\`\`\``);
|
| 68 |
}
|
| 69 |
else if (DEMO_MODE === 'FETCH_SCRIPT') {
|
| 70 |
+
console.log(" π Asking to find 'BikeLogic'...");
|
|
|
|
| 71 |
return res.json({
|
| 72 |
action: "read_script",
|
| 73 |
targetName: "BikeLogic"
|
| 74 |
});
|
| 75 |
}
|
| 76 |
else if (DEMO_MODE === 'SCAN_SERVER_STORAGE') {
|
|
|
|
| 77 |
console.log(" π Asking to scan ServerStorage...");
|
| 78 |
return res.json({
|
| 79 |
action: "read_hierarchy",
|
|
|
|
| 81 |
});
|
| 82 |
}
|
| 83 |
else if (DEMO_MODE === 'SCAN_SELECTION') {
|
|
|
|
| 84 |
console.log(" π Asking to scan selection...");
|
| 85 |
+
return res.json({ action: "read_hierarchy" });
|
| 86 |
+
}
|
| 87 |
+
else if (DEMO_MODE === 'FETCH_LOGS') {
|
| 88 |
+
console.log(" π Asking to fetch Console Logs...");
|
| 89 |
+
return res.json({ action: "read_logs" });
|
| 90 |
}
|
| 91 |
|
| 92 |
return res.json({ success: true, message: "Thinking..." });
|