everydaycats commited on
Commit
553d916
·
verified ·
1 Parent(s): 4286e24

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +26 -9
app.js CHANGED
@@ -12,11 +12,12 @@ const PORT = process.env.PORT || 7860;
12
 
13
  const app = express();
14
  app.use(cors());
 
15
  app.use(bodyParser.json({ limit: "50mb" }));
16
 
17
  // === DEMO CONTROLLER ===
18
  // CHANGE THIS TO TEST DIFFERENT INTERACTIONS
19
- // Options: 'NONE' (Just save), 'BUILD_PART' (Send Lua Code), 'FETCH_SCRIPT' (Ask for Source)
20
  const DEMO_MODE = 'BUILD_PART';
21
 
22
  app.post("/api/ai-build", async (req, res) => {
@@ -33,18 +34,34 @@ app.post("/api/ai-build", async (req, res) => {
33
 
34
  // 2. IF WE RECEIVED SCRIPT SOURCE (From a previous fetch request)
35
  if (scriptContext) {
36
- console.log(" 📘 Received Script Source for:", scriptContext.name);
37
- console.log(" --- START SOURCE ---\n", scriptContext.source.substring(0, 100) + "...", "\n --- END SOURCE ---");
38
  // In a real app, you would now feed this to the AI to edit.
39
- return res.json({ success: true, message: "Source received, analyzing..." });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
 
42
  // 3. DEMO RESPONSES
43
  if (DEMO_MODE === 'BUILD_PART') {
44
  console.log(" 👉 Sending Code Demo");
 
45
  const luaCode = `
46
- ```lua
47
- -- AI Generated Demo
48
  local p = Instance.new("Part")
49
  p.Name = "AI_Generated_Cube"
50
  p.Color = Color3.fromRGB(0, 255, 100)
@@ -53,7 +70,7 @@ app.post("/api/ai-build", async (req, res) => {
53
  p.Anchored = true
54
  p.Parent = workspace
55
  print("Hello from the Server! I made a part.")
56
- ```
57
  `;
58
  return res.send(luaCode); // Sending raw markdown/text
59
  }
@@ -68,11 +85,11 @@ app.post("/api/ai-build", async (req, res) => {
68
  }
69
 
70
  // Default: Just acknowledge
71
- return res.json({ success: true, assetId: "req_" + Date.now() });
72
 
73
  } catch (err) {
74
  console.error("Server Error:", err);
75
- res.status(500).send("Server Error");
76
  }
77
  });
78
 
 
12
 
13
  const app = express();
14
  app.use(cors());
15
+ // Increased limit to 50mb to handle large complex workspaces
16
  app.use(bodyParser.json({ limit: "50mb" }));
17
 
18
  // === DEMO CONTROLLER ===
19
  // CHANGE THIS TO TEST DIFFERENT INTERACTIONS
20
+ // Options: 'NONE' (Just acknowledge), 'BUILD_PART' (Send Lua Code), 'FETCH_SCRIPT' (Ask for Source)
21
  const DEMO_MODE = 'BUILD_PART';
22
 
23
  app.post("/api/ai-build", async (req, res) => {
 
34
 
35
  // 2. IF WE RECEIVED SCRIPT SOURCE (From a previous fetch request)
36
  if (scriptContext) {
37
+ console.log(" 📘 Received Script Source for:", scriptContext.targetName);
38
+ console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
39
  // In a real app, you would now feed this to the AI to edit.
40
+ // For demo purposes, we can acknowledge and then send code back:
41
+
42
+ const returnCode = `
43
+ \`\`\`lua
44
+ -- AI analyzed script ${scriptContext.targetName}. Sending back a confirmation part.
45
+ local p = Instance.new("Part")
46
+ p.Name = "AI_SCRIPT_ACKNOWLEDGED"
47
+ p.Color = Color3.fromRGB(255, 255, 0)
48
+ p.Size = Vector3.new(2, 2, 2)
49
+ p.Position = Vector3.new(5, 5, 0)
50
+ p.Anchored = true
51
+ p.Parent = workspace
52
+ print("Script analysis complete. Confirmation part created.")
53
+ \`\`\`
54
+ `;
55
+ return res.send(returnCode);
56
  }
57
 
58
  // 3. DEMO RESPONSES
59
  if (DEMO_MODE === 'BUILD_PART') {
60
  console.log(" 👉 Sending Code Demo");
61
+ // FIX: Using template literals (backticks `) for multi-line string
62
  const luaCode = `
63
+ \`\`\`lua
64
+ -- AI Generated Demo: Part Builder
65
  local p = Instance.new("Part")
66
  p.Name = "AI_Generated_Cube"
67
  p.Color = Color3.fromRGB(0, 255, 100)
 
70
  p.Anchored = true
71
  p.Parent = workspace
72
  print("Hello from the Server! I made a part.")
73
+ \`\`\`
74
  `;
75
  return res.send(luaCode); // Sending raw markdown/text
76
  }
 
85
  }
86
 
87
  // Default: Just acknowledge
88
+ return res.json({ success: true, assetId: "req_" + Date.now(), message: "Snapshot received. AI is thinking..." });
89
 
90
  } catch (err) {
91
  console.error("Server Error:", err);
92
+ res.status(500).send("Server Error: " + err.message);
93
  }
94
  });
95