agentgui 1.0.763 → 1.0.764
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +24 -26
- package/static/js/websocket-manager.js +3 -1
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -527,6 +527,10 @@ const server = http.createServer(async (req, res) => {
|
|
|
527
527
|
}
|
|
528
528
|
|
|
529
529
|
if (pathOnly === '/api/health' && req.method === 'GET') {
|
|
530
|
+
let dbStatus = { ok: true };
|
|
531
|
+
try { queries._db.prepare('SELECT 1').get(); } catch (e) { dbStatus = { ok: false, error: e.message }; }
|
|
532
|
+
const queueSizes = {};
|
|
533
|
+
for (const [k, v] of messageQueues) queueSizes[k] = v.length;
|
|
530
534
|
sendJSON(req, res, 200, {
|
|
531
535
|
status: 'ok',
|
|
532
536
|
version: PKG_VERSION,
|
|
@@ -535,7 +539,9 @@ const server = http.createServer(async (req, res) => {
|
|
|
535
539
|
activeExecutions: activeExecutions.size,
|
|
536
540
|
wsClients: wss.clients.size,
|
|
537
541
|
memory: process.memoryUsage(),
|
|
538
|
-
acp: getACPStatus()
|
|
542
|
+
acp: getACPStatus(),
|
|
543
|
+
db: dbStatus,
|
|
544
|
+
queueSizes
|
|
539
545
|
});
|
|
540
546
|
return;
|
|
541
547
|
}
|
|
@@ -1189,7 +1195,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
1189
1195
|
}
|
|
1190
1196
|
|
|
1191
1197
|
if (pathOnly === '/api/agents' && req.method === 'GET') {
|
|
1192
|
-
|
|
1198
|
+
debugLog(`[API /api/agents] Returning ${discoveredAgents.length} agents`);
|
|
1193
1199
|
sendJSON(req, res, 200, { agents: discoveredAgents });
|
|
1194
1200
|
return;
|
|
1195
1201
|
}
|
|
@@ -1199,21 +1205,6 @@ const server = http.createServer(async (req, res) => {
|
|
|
1199
1205
|
return;
|
|
1200
1206
|
}
|
|
1201
1207
|
|
|
1202
|
-
if (pathOnly === '/api/health' && req.method === 'GET') {
|
|
1203
|
-
let dbStatus = { ok: true };
|
|
1204
|
-
try { queries._db.prepare('SELECT 1').get(); } catch (e) { dbStatus = { ok: false, error: e.message }; }
|
|
1205
|
-
const queueSizes = {};
|
|
1206
|
-
for (const [k, v] of messageQueues) queueSizes[k] = v.length;
|
|
1207
|
-
sendJSON(req, res, 200, {
|
|
1208
|
-
uptime: process.uptime(),
|
|
1209
|
-
db: dbStatus,
|
|
1210
|
-
activeExecutionCount: activeExecutions.size,
|
|
1211
|
-
queueSizes,
|
|
1212
|
-
wsClientCount: syncClients.size,
|
|
1213
|
-
memory: process.memoryUsage()
|
|
1214
|
-
});
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
1208
|
|
|
1218
1209
|
if (pathOnly === '/api/debug' && req.method === 'GET') {
|
|
1219
1210
|
const execSnap = {};
|
|
@@ -2093,7 +2084,8 @@ function serveFile(filePath, res, req) {
|
|
|
2093
2084
|
fs.readFile(filePath, (err2, data) => {
|
|
2094
2085
|
if (err2) { res.writeHead(500); res.end('Server error'); return; }
|
|
2095
2086
|
let content = data.toString();
|
|
2096
|
-
const
|
|
2087
|
+
const wsToken = process.env.PASSWORD ? `window.__WS_TOKEN='${process.env.PASSWORD.replace(/'/g, "\\'")}';` : '';
|
|
2088
|
+
const baseTag = `<script>window.__BASE_URL='${BASE_URL}';window.__SERVER_VERSION='${PKG_VERSION}';${wsToken}</script>`;
|
|
2097
2089
|
content = content.replace('<head>', `<head>\n <base href="${BASE_URL}/">\n ` + baseTag);
|
|
2098
2090
|
content = content.replace(/(href|src)="vendor\//g, `$1="${BASE_URL}/vendor/`);
|
|
2099
2091
|
content = content.replace(/(src)="\/gm\/js\//g, `$1="${BASE_URL}/js/`);
|
|
@@ -2821,12 +2813,18 @@ const subscriptionIndex = new Map();
|
|
|
2821
2813
|
const pm2Subscribers = new Set();
|
|
2822
2814
|
|
|
2823
2815
|
wss.on('connection', (ws, req) => {
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2816
|
+
const _pwd = process.env.PASSWORD;
|
|
2817
|
+
if (_pwd) {
|
|
2818
|
+
const url = new URL(req.url, 'http://localhost');
|
|
2819
|
+
const token = url.searchParams.get('token');
|
|
2820
|
+
if (token !== _pwd) { ws.close(4001, 'Unauthorized'); return; }
|
|
2821
|
+
}
|
|
2822
|
+
const wsPath = req.url.split('?')[0];
|
|
2823
|
+
const wsRoute = wsPath.startsWith(BASE_URL) ? wsPath.slice(BASE_URL.length) : wsPath;
|
|
2824
|
+
if (wsRoute === '/hot-reload') {
|
|
2827
2825
|
hotReloadClients.push(ws);
|
|
2828
2826
|
ws.on('close', () => { const i = hotReloadClients.indexOf(ws); if (i > -1) hotReloadClients.splice(i, 1); });
|
|
2829
|
-
} else if (
|
|
2827
|
+
} else if (wsRoute === '/sync') {
|
|
2830
2828
|
syncClients.add(ws);
|
|
2831
2829
|
ws.isAlive = true;
|
|
2832
2830
|
ws.subscriptions = new Set();
|
|
@@ -2857,7 +2855,7 @@ wss.on('connection', (ws, req) => {
|
|
|
2857
2855
|
if (ws.pm2Subscribed) {
|
|
2858
2856
|
pm2Subscribers.delete(ws);
|
|
2859
2857
|
}
|
|
2860
|
-
|
|
2858
|
+
debugLog(`[WebSocket] Client ${ws.clientId} disconnected`);
|
|
2861
2859
|
});
|
|
2862
2860
|
}
|
|
2863
2861
|
});
|
|
@@ -2935,13 +2933,13 @@ registerMsgHandlers(wsRouter, {
|
|
|
2935
2933
|
|
|
2936
2934
|
registerQueueHandlers(wsRouter, { queries, messageQueues, broadcastSync });
|
|
2937
2935
|
|
|
2938
|
-
|
|
2936
|
+
debugLog('[INIT] registerSessionHandlers, agents: ' + discoveredAgents.length);
|
|
2939
2937
|
registerSessionHandlers(wsRouter, {
|
|
2940
2938
|
db: queries, discoveredAgents, modelCache,
|
|
2941
2939
|
getAgentDescriptor, activeScripts, broadcastSync,
|
|
2942
2940
|
startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState
|
|
2943
2941
|
});
|
|
2944
|
-
|
|
2942
|
+
debugLog('[INIT] registerSessionHandlers completed');
|
|
2945
2943
|
|
|
2946
2944
|
registerRunHandlers(wsRouter, {
|
|
2947
2945
|
queries, discoveredAgents, activeExecutions, activeProcessesByRunId,
|
|
@@ -3014,7 +3012,7 @@ wsRouter.onLegacy((data, ws) => {
|
|
|
3014
3012
|
if (data.conversationId && checkpointManager.hasPendingCheckpoint(data.conversationId)) {
|
|
3015
3013
|
const checkpoint = checkpointManager.getPendingCheckpoint(data.conversationId);
|
|
3016
3014
|
if (checkpoint) {
|
|
3017
|
-
|
|
3015
|
+
debugLog(`[checkpoint] Injecting ${checkpoint.events.length} events to client for ${data.conversationId}`);
|
|
3018
3016
|
|
|
3019
3017
|
const latestSession = queries.getLatestSession(data.conversationId);
|
|
3020
3018
|
if (latestSession) {
|
|
@@ -113,7 +113,9 @@ class WebSocketManager {
|
|
|
113
113
|
getWebSocketURL() {
|
|
114
114
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
115
115
|
const baseURL = window.__BASE_URL || '/gm';
|
|
116
|
-
|
|
116
|
+
let url = `${protocol}//${window.location.host}${baseURL}/sync`;
|
|
117
|
+
if (window.__WS_TOKEN) url += `?token=${encodeURIComponent(window.__WS_TOKEN)}`;
|
|
118
|
+
return url;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
async connect() {
|