Update app.js
Browse files
app.js
CHANGED
|
@@ -593,31 +593,41 @@ app.post('/project/ping', async (req, res) => {
|
|
| 593 |
});
|
| 594 |
*/
|
| 595 |
|
| 596 |
-
app.post('/
|
| 597 |
-
const {
|
| 598 |
-
if (!
|
| 599 |
-
|
| 600 |
-
const decoded = jwt.decode(token);
|
| 601 |
-
if (!decoded) return res.status(401).json({ error: 'Malformed token' });
|
| 602 |
-
|
| 603 |
-
const secret = await getSessionSecret(decoded.uid, decoded.projectId);
|
| 604 |
-
if (!secret) return res.status(404).json({ error: 'Session revoked' });
|
| 605 |
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
|
| 617 |
-
|
| 618 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
});
|
| 620 |
|
|
|
|
| 621 |
app.post('/human/override', validateRequest, async (req, res) => {
|
| 622 |
const { projectId, instruction, userId } = req.body;
|
| 623 |
try {
|
|
|
|
| 593 |
});
|
| 594 |
*/
|
| 595 |
|
| 596 |
+
app.post('/project/ping', async (req, res) => {
|
| 597 |
+
const { projectId, userId, isFrontend } = req.body;
|
| 598 |
+
if (!projectId || !userId) return res.status(400).json({ error: "Missing IDs" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
|
| 600 |
+
const project = await StateManager.getProject(projectId);
|
| 601 |
+
if (!project || project.userId !== userId) return res.json({ action: "IDLE" });
|
| 602 |
+
|
| 603 |
+
// 1. BASE RESPONSE (Visuals)
|
| 604 |
+
// Both Frontend and Plugin need this to show "Thinking..." or text generation
|
| 605 |
+
const response = {
|
| 606 |
+
action: "IDLE",
|
| 607 |
+
status: StateManager.getStatus(projectId),
|
| 608 |
+
snapshot: StateManager.getSnapshot(projectId)
|
| 609 |
+
};
|
| 610 |
+
|
| 611 |
+
// 2. EXECUTOR LOGIC (Plugin Only)
|
| 612 |
+
// Only pop commands if this is NOT the passive frontend viewer
|
| 613 |
+
if (!isFrontend) {
|
| 614 |
+
const command = await StateManager.popCommand(projectId);
|
| 615 |
|
| 616 |
+
// We don't need 'streamBuffers' anymore since we use 'snapshot' for visuals.
|
| 617 |
+
// But if you have legacy stream logic, we can leave it or remove it.
|
| 618 |
+
// For this hybrid model, snapshot is king.
|
| 619 |
+
|
| 620 |
+
if (command) {
|
| 621 |
+
response.action = command.type;
|
| 622 |
+
response.target = command.payload;
|
| 623 |
+
response.code = command.type === 'EXECUTE' ? command.payload : null;
|
| 624 |
+
}
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
res.json(response);
|
| 628 |
});
|
| 629 |
|
| 630 |
+
|
| 631 |
app.post('/human/override', validateRequest, async (req, res) => {
|
| 632 |
const { projectId, instruction, userId } = req.body;
|
| 633 |
try {
|