everydaycats commited on
Commit
3456cb8
Β·
verified Β·
1 Parent(s): c0715a4

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +32 -23
app.js CHANGED
@@ -15,13 +15,13 @@ app.use(cors());
15
  app.use(bodyParser.json({ limit: "50mb" }));
16
 
17
  // === DEMO CONTROLLER ===
18
- // Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT'
19
- const DEMO_MODE = 'FETCH_SCRIPT';
20
 
21
  app.post("/api/ai-build", async (req, res) => {
22
  try {
23
- // We expect 'scriptContext' if this is a follow-up request from the plugin
24
- const { instruction, state, scriptContext } = req.body;
25
 
26
  console.log("πŸ“₯ Received Request");
27
  console.log(" Instruction:", instruction);
@@ -30,54 +30,63 @@ app.post("/api/ai-build", async (req, res) => {
30
  console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
31
  }
32
 
33
- // 1. **FIXED LOOP LOGIC:** IF WE RECEIVED SCRIPT SOURCE (Step 2 of the loop)
34
  if (scriptContext) {
35
  console.log(" πŸ“˜ Received Script Source for:", scriptContext.targetName);
36
  console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
37
 
38
- // **STOP THE LOOP:** Send back a simple JSON message instead of executable code.
39
  return res.json({
40
  success: true,
41
- message: `Source for ${scriptContext.targetName} received and analyzed. Loop stopped in demo mode.`
42
  });
43
-
44
- // In a real scenario, you would perform AI analysis here and send back new code:
45
- /*
 
 
 
 
 
46
  return res.json({
47
- code: `print("I have updated ${scriptContext.targetName}")`
 
48
  });
49
- */
50
  }
51
 
52
- // 2. DEMO RESPONSES (Step 1 of the loop/initial request)
 
53
  if (DEMO_MODE === 'BUILD_PART') {
54
  const luaCode = `
55
  \`\`\`lua
56
- -- AI Generated Demo: Part Builder
57
  local p = Instance.new("Part")
58
- p.Name = "AI_Generated_Cube"
59
- p.Color = Color3.fromRGB(0, 255, 100)
60
- p.Size = Vector3.new(4, 4, 4)
61
- p.Position = Vector3.new(0, 10, 0)
62
  p.Anchored = true
63
  p.Parent = workspace
64
- print("Hello from the Server! I made a part.")
65
  \`\`\`
66
  `;
67
  return res.send(luaCode);
68
  }
69
 
70
  else if (DEMO_MODE === 'FETCH_SCRIPT') {
71
- console.log(" πŸ‘‰ Sending Fetch Request Demo (Step 1)");
72
- // This tells the plugin to find a script named "BikeLogic" and send it back
73
  return res.json({
74
  action: "read_script",
75
- targetName: "BikeLogic"
 
 
 
 
 
 
 
76
  });
77
  }
78
 
79
  // Default
80
- return res.json({ success: true, assetId: "req_" + Date.now(), message: "Snapshot received. AI is thinking..." });
81
 
82
  } catch (err) {
83
  console.error("Server Error:", err);
 
15
  app.use(bodyParser.json({ limit: "50mb" }));
16
 
17
  // === DEMO CONTROLLER ===
18
+ // Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT', 'FETCH_LOGS'
19
+ const DEMO_MODE = 'FETCH_LOGS';
20
 
21
  app.post("/api/ai-build", async (req, res) => {
22
  try {
23
+ // Destructure specifically to look for follow-up contexts
24
+ const { instruction, state, scriptContext, logContext } = req.body;
25
 
26
  console.log("πŸ“₯ Received Request");
27
  console.log(" Instruction:", instruction);
 
30
  console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
31
  }
32
 
33
+ // 1. **HANDLE SCRIPT SOURCE (Loop Step 2)**
34
  if (scriptContext) {
35
  console.log(" πŸ“˜ Received Script Source for:", scriptContext.targetName);
36
  console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
37
 
 
38
  return res.json({
39
  success: true,
40
+ message: `Source for ${scriptContext.targetName} received. Loop stopped.`
41
  });
42
+ }
43
+
44
+ // 2. **HANDLE LOGS (Loop Step 2)**
45
+ if (logContext) {
46
+ console.log(" πŸ“ Received Console Logs:");
47
+ console.log(" --- LOGS ---\n", logContext.logs);
48
+ console.log(" --- END LOGS ---");
49
+
50
  return res.json({
51
+ success: true,
52
+ message: "Console logs received and analyzed. Loop stopped."
53
  });
 
54
  }
55
 
56
+ // 3. **DEMO TRIGGERS (Loop Step 1)**
57
+
58
  if (DEMO_MODE === 'BUILD_PART') {
59
  const luaCode = `
60
  \`\`\`lua
 
61
  local p = Instance.new("Part")
62
+ p.Name = "AI_Cube"
63
+ p.Color = Color3.new(1,0,0)
64
+ p.Position = Vector3.new(0, 5, 0)
 
65
  p.Anchored = true
66
  p.Parent = workspace
67
+ print("Part created by AI")
68
  \`\`\`
69
  `;
70
  return res.send(luaCode);
71
  }
72
 
73
  else if (DEMO_MODE === 'FETCH_SCRIPT') {
74
+ console.log(" πŸ‘‰ Sending Fetch Script Request");
 
75
  return res.json({
76
  action: "read_script",
77
+ targetName: "BikeLogic" // Ensure a script named this exists to test
78
+ });
79
+ }
80
+
81
+ else if (DEMO_MODE === 'FETCH_LOGS') {
82
+ console.log(" πŸ‘‰ Sending Fetch Logs Request");
83
+ return res.json({
84
+ action: "read_logs"
85
  });
86
  }
87
 
88
  // Default
89
+ return res.json({ success: true, message: "Snapshot received. Waiting for demo trigger..." });
90
 
91
  } catch (err) {
92
  console.error("Server Error:", err);