Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -36,6 +36,21 @@ app.post('/internal/notify', (req, res) => {
|
|
| 36 |
res.json({ success: false });
|
| 37 |
});
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
// Verify JWT against DB Secret
|
| 40 |
async function verifyThrustToken(token) {
|
| 41 |
const decoded = jwt.decode(token);
|
|
@@ -195,12 +210,12 @@ wss.on('connection', (ws, req, userId) => {
|
|
| 195 |
ws.send(JSON.stringify({ type: 'response', text: result.text, should_reload: result.should_reload, usage: result.usage }));
|
| 196 |
}
|
| 197 |
|
| 198 |
-
// 2. BACKGROUND
|
| 199 |
if (data.type === 'context_sync') {
|
| 200 |
const payloadData = data.data;
|
| 201 |
const currentTime = new Date().toLocaleString(); // Anchor time for the AI
|
| 202 |
|
| 203 |
-
const formattedPrompt = `[WORKSPACE UPDATE - CURRENT TIME: ${currentTime}]\n\nActivity Log (
|
| 204 |
|
| 205 |
await fetch(`${CORE_URL}/process`, {
|
| 206 |
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
|
|
| 36 |
res.json({ success: false });
|
| 37 |
});
|
| 38 |
|
| 39 |
+
// NEW: Internal MCP Query Webhook (Routes AI requests down to the local daemon)
|
| 40 |
+
app.post('/internal/mcp_query', (req, res) => {
|
| 41 |
+
const { user_id, lead_id, payload } = req.body;
|
| 42 |
+
if (clients.has(user_id)) {
|
| 43 |
+
clients.get(user_id).forEach(ws => {
|
| 44 |
+
if (ws.readyState === WebSocket.OPEN) {
|
| 45 |
+
// Forward the exact payload to the daemon
|
| 46 |
+
ws.send(JSON.stringify({ type: 'mcp_query', payload }));
|
| 47 |
+
}
|
| 48 |
+
});
|
| 49 |
+
return res.json({ success: true });
|
| 50 |
+
}
|
| 51 |
+
res.json({ success: false, message: "User daemon not connected" });
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
// Verify JWT against DB Secret
|
| 55 |
async function verifyThrustToken(token) {
|
| 56 |
const decoded = jwt.decode(token);
|
|
|
|
| 210 |
ws.send(JSON.stringify({ type: 'response', text: result.text, should_reload: result.should_reload, usage: result.usage }));
|
| 211 |
}
|
| 212 |
|
| 213 |
+
// 2. BACKGROUND CONTEXT SYNC (SMART DEBOUNCED)
|
| 214 |
if (data.type === 'context_sync') {
|
| 215 |
const payloadData = data.data;
|
| 216 |
const currentTime = new Date().toLocaleString(); // Anchor time for the AI
|
| 217 |
|
| 218 |
+
const formattedPrompt = `[WORKSPACE UPDATE - CURRENT TIME: ${currentTime}]\n\nActivity Log (Recent Activity):\n${payloadData.buffer}\n\nGit Diffs (Modified Files):\n${payloadData.diffs}\n\nNew Untracked Files:\n${payloadData.new_files}`;
|
| 219 |
|
| 220 |
await fetch(`${CORE_URL}/process`, {
|
| 221 |
method: 'POST', headers: { 'Content-Type': 'application/json' },
|