Spaces:
Paused
Paused
Update stateManager.js
Browse files- stateManager.js +24 -5
stateManager.js
CHANGED
|
@@ -96,25 +96,44 @@ export const StateManager = {
|
|
| 96 |
statusBuffers.delete(projectId);
|
| 97 |
},
|
| 98 |
|
|
|
|
| 99 |
queueCommand: async (projectId, input) => {
|
| 100 |
let project = activeProjects.get(projectId);
|
| 101 |
if (!project) project = await StateManager.getProject(projectId);
|
| 102 |
if (!project) return;
|
|
|
|
| 103 |
let command = null;
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
else if (typeof input === 'string') {
|
| 106 |
-
const
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
if (codeMatch) command = { type: "EXECUTE", payload: codeMatch[1].trim() };
|
| 110 |
else if (readScriptMatch) command = { type: "READ_SCRIPT", payload: readScriptMatch[1].trim() };
|
| 111 |
else if (readHierarchyMatch) command = { type: "READ_HIERARCHY", payload: readHierarchyMatch[1].trim() };
|
|
|
|
| 112 |
}
|
|
|
|
| 113 |
if (command) {
|
| 114 |
if (!project.commandQueue) project.commandQueue = [];
|
| 115 |
project.commandQueue.push(command);
|
|
|
|
| 116 |
}
|
| 117 |
},
|
|
|
|
| 118 |
popCommand: async (projectId) => {
|
| 119 |
const project = activeProjects.get(projectId);
|
| 120 |
if (!project || !project.commandQueue || project.commandQueue.length === 0) return null;
|
|
@@ -132,7 +151,7 @@ export const StateManager = {
|
|
| 132 |
delete mergedInfo.commandQueue;
|
| 133 |
await supabase.from('projects').update({
|
| 134 |
info: mergedInfo,
|
| 135 |
-
updated_at: new Date().toISOString()
|
| 136 |
}).eq('id', projectId);
|
| 137 |
}
|
| 138 |
},
|
|
|
|
| 96 |
statusBuffers.delete(projectId);
|
| 97 |
},
|
| 98 |
|
| 99 |
+
// --- RESTORED FULL REGEX LOGIC ---
|
| 100 |
queueCommand: async (projectId, input) => {
|
| 101 |
let project = activeProjects.get(projectId);
|
| 102 |
if (!project) project = await StateManager.getProject(projectId);
|
| 103 |
if (!project) return;
|
| 104 |
+
|
| 105 |
let command = null;
|
| 106 |
+
|
| 107 |
+
if (typeof input === 'object' && input.type && input.payload) {
|
| 108 |
+
command = input;
|
| 109 |
+
}
|
| 110 |
else if (typeof input === 'string') {
|
| 111 |
+
const rawResponse = input;
|
| 112 |
+
|
| 113 |
+
// Loop Prevention
|
| 114 |
+
if (rawResponse.includes("[ASK_PM:")) return;
|
| 115 |
+
if (rawResponse.includes("[ROUTE_TO_PM:")) return;
|
| 116 |
+
if (rawResponse.includes("[GENERATE_IMAGE:") && !rawResponse.includes("```")) return;
|
| 117 |
+
|
| 118 |
+
// REGEX Parsing (RESTORED)
|
| 119 |
+
const codeMatch = rawResponse.match(/```(?:lua|luau)?([\s\S]*?)```/i);
|
| 120 |
+
const readScriptMatch = rawResponse.match(/\[READ_SCRIPT:\s*(.*?)\]/);
|
| 121 |
+
const readHierarchyMatch = rawResponse.match(/\[READ_HIERARCHY:\s*(.*?)\]/);
|
| 122 |
+
const readLogsMatch = rawResponse.includes("[READ_LOGS]");
|
| 123 |
+
|
| 124 |
if (codeMatch) command = { type: "EXECUTE", payload: codeMatch[1].trim() };
|
| 125 |
else if (readScriptMatch) command = { type: "READ_SCRIPT", payload: readScriptMatch[1].trim() };
|
| 126 |
else if (readHierarchyMatch) command = { type: "READ_HIERARCHY", payload: readHierarchyMatch[1].trim() };
|
| 127 |
+
else if (readLogsMatch) command = { type: "READ_LOGS", payload: null };
|
| 128 |
}
|
| 129 |
+
|
| 130 |
if (command) {
|
| 131 |
if (!project.commandQueue) project.commandQueue = [];
|
| 132 |
project.commandQueue.push(command);
|
| 133 |
+
console.log(`[Memory] Queued command: ${command.type}`);
|
| 134 |
}
|
| 135 |
},
|
| 136 |
+
|
| 137 |
popCommand: async (projectId) => {
|
| 138 |
const project = activeProjects.get(projectId);
|
| 139 |
if (!project || !project.commandQueue || project.commandQueue.length === 0) return null;
|
|
|
|
| 151 |
delete mergedInfo.commandQueue;
|
| 152 |
await supabase.from('projects').update({
|
| 153 |
info: mergedInfo,
|
| 154 |
+
updated_at: new Date().toISOString() // RESTORED TIMESTAMP
|
| 155 |
}).eq('id', projectId);
|
| 156 |
}
|
| 157 |
},
|