everydaycats commited on
Commit
3ab7d84
Β·
verified Β·
1 Parent(s): 6a63e4f

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +32 -52
app.js CHANGED
@@ -11,85 +11,65 @@ const PORT = process.env.PORT || 7860;
11
 
12
  const app = express();
13
  app.use(cors());
14
- // Increased limit for large snapshot payloads
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_SCRIPT'; // '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);
 
28
 
29
- if(state && state.flatList) {
30
- console.log(` Hierarchy Size: ${state.flatList.length} items (Flat Format)`);
31
- const lll = JSON.stringify(state.flatList);
32
- console.log(` Flat list: ${lll.length}`);
33
-
34
- }
35
-
36
- // 1. **HANDLE SCRIPT SOURCE (Loop Step 2)**
37
  if (scriptContext) {
38
- console.log(" πŸ“˜ Received Script Source for:", scriptContext.targetName);
39
- console.log(" --- START SOURCE ---\n", scriptContext.scriptSource.substring(0, 100) + "...", "\n --- END SOURCE ---");
40
-
41
- return res.json({
42
- success: true,
43
- message: `Source for ${scriptContext.targetName} received. Loop stopped.`
44
- });
45
  }
46
 
47
- // 2. **HANDLE LOGS (Loop Step 2)**
48
  if (logContext) {
49
- console.log(" πŸ“ Received Console Logs:");
50
- console.log(" --- LOGS ---\n", logContext.logs);
51
- console.log(" --- END LOGS ---");
52
 
53
- return res.json({
54
- success: true,
55
- message: "Console logs received and analyzed. Loop stopped."
56
- });
 
57
  }
58
 
59
- // 3. **DEMO TRIGGERS (Loop Step 1)**
60
-
61
  if (DEMO_MODE === 'BUILD_PART') {
62
  const luaCode = `
63
  \`\`\`lua
64
  local p = Instance.new("Part")
65
- p.Name = "AI_Cube"
66
- p.Color = Color3.new(1,0,0)
67
- p.Position = Vector3.new(0, 5, 0)
68
- p.Anchored = true
69
  p.Parent = workspace
70
- print("Part created by AI")
71
  \`\`\`
72
  `;
73
  return res.send(luaCode);
74
  }
75
-
76
  else if (DEMO_MODE === 'FETCH_SCRIPT') {
77
- console.log(" πŸ‘‰ Sending Fetch Script Request");
78
- return res.json({
79
- action: "read_script",
80
- targetName: "BikeLogic" // Ensure a script named this exists to test
81
- });
82
  }
83
-
84
  else if (DEMO_MODE === 'FETCH_LOGS') {
85
- console.log(" πŸ‘‰ Sending Fetch Logs Request");
86
- return res.json({
87
- action: "read_logs"
88
- });
 
 
89
  }
90
 
91
- // Default
92
- return res.json({ success: true, message: "Snapshot received. Waiting for demo trigger..." });
93
 
94
  } catch (err) {
95
  console.error("Server Error:", err);
@@ -97,4 +77,4 @@ app.post("/api/ai-build", async (req, res) => {
97
  }
98
  });
99
 
100
- app.listen(PORT, () => console.log(`πŸš€ Server running on port ${PORT}. Demo Mode: ${DEMO_MODE}`));
 
11
 
12
  const app = express();
13
  app.use(cors());
 
14
  app.use(bodyParser.json({ limit: "50mb" }));
15
 
16
+ // Options: 'NONE', 'BUILD_PART', 'FETCH_SCRIPT', 'FETCH_LOGS', 'SCAN_HIERARCHY'
17
+ const DEMO_MODE = 'SCAN_HIERARCHY';
 
18
 
19
  app.post("/api/ai-build", async (req, res) => {
20
  try {
21
+ const { instruction, selection, scriptContext, logContext, hierarchyContext } = req.body;
 
22
 
23
+ console.log("------------------------------------------------");
24
+ console.log("πŸ“₯ INSTRUCTION:", instruction);
25
+ if(selection) console.log(" Selected:", selection.name, `(${selection.className})`);
26
 
27
+ // 1. Script Loop
 
 
 
 
 
 
 
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: `Source received.` });
 
 
 
 
32
  }
33
 
34
+ // 2. Log Loop
35
  if (logContext) {
36
+ console.log("πŸ“ LOGS RECEIVED:\n", logContext.logs);
37
+ return res.json({ success: true, message: "Logs analyzed." });
38
+ }
39
 
40
+ // 3. Hierarchy Loop (New)
41
+ if (hierarchyContext) {
42
+ console.log("🌳 HIERARCHY RECEIVED:");
43
+ console.log(hierarchyContext.tree);
44
+ return res.json({ success: true, message: "Hierarchy analyzed." });
45
  }
46
 
47
+ // 4. Demo Triggers (Initial Request)
 
48
  if (DEMO_MODE === 'BUILD_PART') {
49
  const luaCode = `
50
  \`\`\`lua
51
  local p = Instance.new("Part")
52
+ p.Name = "AI_Part"
53
+ p.Color = Color3.new(0,1,0)
54
+ p.Position = Vector3.new(0, 10, 0)
 
55
  p.Parent = workspace
 
56
  \`\`\`
57
  `;
58
  return res.send(luaCode);
59
  }
 
60
  else if (DEMO_MODE === 'FETCH_SCRIPT') {
61
+ return res.json({ action: "read_script", targetName: "BikeLogic" });
 
 
 
 
62
  }
 
63
  else if (DEMO_MODE === 'FETCH_LOGS') {
64
+ return res.json({ action: "read_logs" });
65
+ }
66
+ else if (DEMO_MODE === 'SCAN_HIERARCHY') {
67
+ // AI decides it needs to see the world before acting
68
+ console.log(" πŸ‘‰ Requesting Hierarchy Scan...");
69
+ return res.json({ action: "read_hierarchy" });
70
  }
71
 
72
+ return res.json({ success: true, message: "Thinking..." });
 
73
 
74
  } catch (err) {
75
  console.error("Server Error:", err);
 
77
  }
78
  });
79
 
80
+ app.listen(PORT, () => console.log(`πŸš€ Server running on port ${PORT}. Mode: ${DEMO_MODE}`));