File size: 3,720 Bytes
c0715a4
b06a41a
 
 
ab9b3de
 
b06a41a
ab9b3de
 
4286e24
9903c38
ab9b3de
 
eace673
072db80
f918ae6
9b3839b
 
f918ae6
9b3839b
 
 
45ae1d9
eace673
b06a41a
3ab7d84
4286e24
3ab7d84
 
4286e24
9b3839b
4286e24
f918ae6
 
3ab7d84
f918ae6
3456cb8
 
9b3839b
3ab7d84
f918ae6
 
0900d48
 
4286e24
ab9b3de
9b3839b
 
 
 
 
 
 
 
 
 
 
 
 
 
4286e24
f918ae6
0900d48
 
 
 
f918ae6
4286e24
 
9b3839b
f918ae6
 
 
 
ab9b3de
f918ae6
 
0900d48
 
f918ae6
0900d48
 
f918ae6
 
9b3839b
 
 
 
 
f918ae6
9903c38
3ab7d84
9903c38
 
4286e24
553d916
2d34f28
ab9b3de
b06a41a
3ab7d84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// server.js
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PORT = process.env.PORT || 7860;

const app = express();
app.use(cors());
app.use(bodyParser.json({ limit: "50mb" }));

// === TEST MODES ===
// 'BUILD_PART'          -> Makes a part
// 'FETCH_SCRIPT'        -> Finds a script by name anywhere
// 'SCAN_SERVER_STORAGE' -> Scans "ServerStorage" explicitly
// 'SCAN_SELECTION'      -> Scans whatever you clicked on in Roblox
// 'FETCH_LOGS'          -> Fetches the recent Output logs
const DEMO_MODE = 'FETCH_LOGS'; 

app.post("/api/ai-build", async (req, res) => {
  try {
    const { instruction, selection, scriptContext, logContext, hierarchyContext } = req.body;
    
    console.log("------------------------------------------------");
    console.log("πŸ“₯ INSTRUCTION:", instruction);
    
    // 1. Script Found Response
    if (scriptContext) {
        console.log(`πŸ“˜ SCRIPT FOUND [${scriptContext.targetName}]:`);
        console.log(`   Parent: ${scriptContext.parentName}`);
        console.log(scriptContext.scriptSource.substring(0, 150) + "...\n");
        return res.json({ success: true, message: `Read ${scriptContext.targetName} successfully.` });
    }

    // 2. Hierarchy Scanned Response
    if (hierarchyContext) {
        console.log(`🌳 SCANNED HIERARCHY [${hierarchyContext.rootName}]:`);
        const treePreview = hierarchyContext.tree.split('\n').slice(0, 20).join('\n');
        console.log(treePreview);
        return res.json({ success: true, message: `Scanned ${hierarchyContext.rootName}.` });
    }

    // 3. Logs Received Response (RESTORED)
    if (logContext) {
        console.log("πŸ“ LOGS RECEIVED:");
        console.log("------------------------------------------------");
        // Print last 500 chars to avoid flooding terminal
        const logPreview = logContext.logs.length > 500 
            ? "..." + logContext.logs.substring(logContext.logs.length - 500) 
            : logContext.logs;
        console.log(logPreview);
        console.log("------------------------------------------------");
        return res.json({ success: true, message: "Logs received and analyzed." });
    }

    // 4. Demo Triggers
    if (DEMO_MODE === 'BUILD_PART') {
        return res.send(`\`\`\`lua
        local p = Instance.new("Part", workspace)
        p.Position = Vector3.new(0,20,0)
        p.Anchored = true
        print("Created Part")
        \`\`\``);
    } 
    else if (DEMO_MODE === 'FETCH_SCRIPT') {
        console.log("   πŸ‘‰ Asking to find 'BikeLogic'...");
        return res.json({ 
            action: "read_script", 
            targetName: "BikeLogic" 
        });
    }
    else if (DEMO_MODE === 'SCAN_SERVER_STORAGE') {
        console.log("   πŸ‘‰ Asking to scan ServerStorage...");
        return res.json({ 
            action: "read_hierarchy",
            targetName: "ServerStorage" 
        });
    }
    else if (DEMO_MODE === 'SCAN_SELECTION') {
        console.log("   πŸ‘‰ Asking to scan selection...");
        return res.json({ action: "read_hierarchy" });
    }
    else if (DEMO_MODE === 'FETCH_LOGS') {
        console.log("   πŸ‘‰ Asking to fetch Console Logs...");
        return res.json({ action: "read_logs" });
    }

    return res.json({ success: true, message: "Thinking..." });

  } catch (err) {
    console.error("Server Error:", err);
    res.status(500).send("Server Error: " + err.message);
  }
});

app.listen(PORT, () => console.log(`πŸš€ Server running on port ${PORT}. Mode: ${DEMO_MODE}`));