agentgui 1.0.846 → 1.0.847
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/CHANGELOG.md +6 -5
- package/lib/broadcast.js +17 -0
- package/lib/http-handler.js +17 -13
- package/lib/routes-registry.js +62 -0
- package/package.json +1 -1
- package/server.js +7 -144
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
## [Unreleased] - refactor: extract
|
|
1
|
+
## [Unreleased] - refactor: extract routes registry + wire tool/debug routes
|
|
2
2
|
|
|
3
|
-
- Extract
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
3
|
+
- Extract all route and WS handler registrations from server.js L201-270 to lib/routes-registry.js (63L, createRegistry factory)
|
|
4
|
+
- Move BROADCAST_TYPES set to lib/broadcast.js as exported const; server.js imports it
|
|
5
|
+
- Refactor http-handler.js to accept routes object (routes.conv, routes.tools, routes.debug etc.) instead of individual named parameters; wire previously-unwired tool and debug routes
|
|
6
|
+
- Inline _mqDeps object into createMessageQueue call; compact process.on error handlers
|
|
7
|
+
- server.js reduced from 337L to 200L; all lib files ≤200L
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
## [Unreleased]
|
package/lib/broadcast.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
export const BROADCAST_TYPES = new Set([
|
|
2
|
+
'message_created', 'conversation_created', 'conversation_updated',
|
|
3
|
+
'conversations_updated', 'conversation_deleted', 'all_conversations_deleted', 'queue_status', 'queue_updated', 'queue_item_dequeued',
|
|
4
|
+
'rate_limit_hit', 'rate_limit_clear',
|
|
5
|
+
'script_started', 'script_stopped', 'script_output',
|
|
6
|
+
'model_download_progress', 'stt_progress', 'tts_setup_progress', 'voice_list',
|
|
7
|
+
'streaming_start', 'streaming_progress', 'streaming_complete', 'streaming_error',
|
|
8
|
+
'tool_install_started', 'tool_install_progress', 'tool_install_complete', 'tool_install_failed',
|
|
9
|
+
'tool_update_progress', 'tool_update_complete', 'tool_update_failed',
|
|
10
|
+
'tool_status_update', 'tool_update_available',
|
|
11
|
+
'tools_update_started', 'tools_update_complete', 'tools_refresh_complete',
|
|
12
|
+
'pm2_monit_update', 'pm2_monitoring_started', 'pm2_monitoring_stopped',
|
|
13
|
+
'pm2_list_response', 'pm2_start_response', 'pm2_stop_response',
|
|
14
|
+
'pm2_restart_response', 'pm2_delete_response', 'pm2_logs_response',
|
|
15
|
+
'pm2_flush_logs_response', 'pm2_ping_response', 'pm2_unavailable'
|
|
16
|
+
]);
|
|
17
|
+
|
|
1
18
|
export function createBroadcast({ syncClients, subscriptionIndex, wsOptimizer, broadcastTypes, getSeq }) {
|
|
2
19
|
return function broadcastSync(event) {
|
|
3
20
|
try {
|
package/lib/http-handler.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
5
|
|
|
6
|
-
export function createHttpHandler({ BASE_URL, expressApp, queries, sendJSON, serveFile, staticDir, messageQueues, wss, activeExecutions, getACPStatus, discoveredAgents, PKG_VERSION, RATE_LIMIT_MAX, rateLimitMap,
|
|
6
|
+
export function createHttpHandler({ BASE_URL, expressApp, queries, sendJSON, serveFile, staticDir, messageQueues, wss, activeExecutions, getACPStatus, discoveredAgents, PKG_VERSION, RATE_LIMIT_MAX, rateLimitMap, routes, handleGeminiOAuthCallback, handleCodexOAuthCallback, PORT }) {
|
|
7
7
|
return async function httpHandler(req, res) {
|
|
8
8
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
9
9
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
@@ -68,30 +68,34 @@ export function createHttpHandler({ BASE_URL, expressApp, queries, sendJSON, ser
|
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
const convHandler =
|
|
71
|
+
const convHandler = routes.conv._match(req.method, pathOnly);
|
|
72
72
|
if (convHandler) { await convHandler(req, res); return; }
|
|
73
|
-
const messagesHandler =
|
|
73
|
+
const messagesHandler = routes.messages._match(req.method, pathOnly);
|
|
74
74
|
if (messagesHandler) { await messagesHandler(req, res); return; }
|
|
75
|
-
const sessionsHandler =
|
|
75
|
+
const sessionsHandler = routes.sessions._match(req.method, pathOnly);
|
|
76
76
|
if (sessionsHandler) { await sessionsHandler(req, res); return; }
|
|
77
|
-
const scriptsHandler =
|
|
77
|
+
const scriptsHandler = routes.scripts._match(req.method, pathOnly);
|
|
78
78
|
if (scriptsHandler) { await scriptsHandler(req, res); return; }
|
|
79
|
-
const runsHandler =
|
|
79
|
+
const runsHandler = routes.runs._match(req.method, pathOnly);
|
|
80
80
|
if (runsHandler) { await runsHandler(req, res); return; }
|
|
81
|
-
const agentHandler =
|
|
81
|
+
const agentHandler = routes.agents._match(req.method, pathOnly);
|
|
82
82
|
if (agentHandler) { await agentHandler(req, res); return; }
|
|
83
|
-
const oauthHandler =
|
|
83
|
+
const oauthHandler = routes.oauth._match(req.method, pathOnly);
|
|
84
84
|
if (oauthHandler) { await oauthHandler(req, res); return; }
|
|
85
|
-
const agentActionsHandler =
|
|
85
|
+
const agentActionsHandler = routes.agentActions._match(req.method, pathOnly);
|
|
86
86
|
if (agentActionsHandler) { await agentActionsHandler(req, res); return; }
|
|
87
|
-
const authConfigHandler =
|
|
87
|
+
const authConfigHandler = routes.authConfig._match(req.method, pathOnly);
|
|
88
88
|
if (authConfigHandler) { await authConfigHandler(req, res); return; }
|
|
89
|
-
const speechHandler =
|
|
89
|
+
const speechHandler = routes.speech._match(req.method, pathOnly);
|
|
90
90
|
if (speechHandler) { await speechHandler(req, res, pathOnly); return; }
|
|
91
|
-
const utilHandler =
|
|
91
|
+
const utilHandler = routes.util._match(req.method, pathOnly);
|
|
92
92
|
if (utilHandler) { await utilHandler(req, res); return; }
|
|
93
|
-
const threadHandler =
|
|
93
|
+
const threadHandler = routes.threads._match(req.method, pathOnly);
|
|
94
94
|
if (threadHandler) { await threadHandler(req, res); return; }
|
|
95
|
+
const toolHandler = routes.tools._match(req.method, pathOnly);
|
|
96
|
+
if (toolHandler) { await toolHandler(req, res); return; }
|
|
97
|
+
const debugHandler = routes.debug._match(req.method, pathOnly);
|
|
98
|
+
if (debugHandler) { await debugHandler(req, res); return; }
|
|
95
99
|
if (routePath.startsWith('/api/image/')) {
|
|
96
100
|
const imagePath = routePath.slice('/api/image/'.length);
|
|
97
101
|
const decodedPath = decodeURIComponent(imagePath);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { register as registerSpeechRoutes } from './routes-speech.js';
|
|
2
|
+
import { register as registerOAuthRoutes } from './routes-oauth.js';
|
|
3
|
+
import { register as registerUtilRoutes } from './routes-util.js';
|
|
4
|
+
import { register as registerToolRoutes } from './routes-tools.js';
|
|
5
|
+
import { register as registerThreadRoutes } from './routes-threads.js';
|
|
6
|
+
import { register as registerDebugRoutes } from './routes-debug.js';
|
|
7
|
+
import { register as registerConvRoutes } from './routes-conversations.js';
|
|
8
|
+
import { register as registerAgentRoutes } from './routes-agents.js';
|
|
9
|
+
import { register as registerMessagesRoutes } from './routes-messages.js';
|
|
10
|
+
import { register as registerSessionsRoutes } from './routes-sessions.js';
|
|
11
|
+
import { register as registerRunsRoutes } from './routes-runs.js';
|
|
12
|
+
import { register as registerScriptsRoutes } from './routes-scripts.js';
|
|
13
|
+
import { register as registerAgentActionsRoutes } from './routes-agent-actions.js';
|
|
14
|
+
import { register as registerAuthConfigRoutes } from './routes-auth-config.js';
|
|
15
|
+
import { register as registerConvHandlers } from './ws-handlers-conv.js';
|
|
16
|
+
import { register as registerConvHandlers2 } from './ws-handlers-conv2.js';
|
|
17
|
+
import { register as registerSessionHandlers } from './ws-handlers-session.js';
|
|
18
|
+
import { register as registerSessionHandlers2 } from './ws-handlers-session2.js';
|
|
19
|
+
import { register as registerRunHandlers } from './ws-handlers-run.js';
|
|
20
|
+
import { register as registerUtilHandlers } from './ws-handlers-util.js';
|
|
21
|
+
import { register as registerOAuthHandlers } from './ws-handlers-oauth.js';
|
|
22
|
+
import { register as registerScriptHandlers } from './ws-handlers-scripts.js';
|
|
23
|
+
import { register as registerQueueHandlers } from './ws-handlers-queue.js';
|
|
24
|
+
import { register as registerMsgHandlers } from './ws-handlers-msg.js';
|
|
25
|
+
import { initSpeechManager, getSpeech, voiceCacheManager, modelDownloadState, ensureModelsDownloaded } from './speech-manager.js';
|
|
26
|
+
import { getAgentDescriptor } from './agent-descriptors.js';
|
|
27
|
+
import { startGeminiOAuth, exchangeGeminiOAuthCode, getGeminiOAuthState } from './oauth-gemini.js';
|
|
28
|
+
import { startCodexOAuth, exchangeCodexOAuthCode, getCodexOAuthState } from './oauth-codex.js';
|
|
29
|
+
import { getProviderConfigs, saveProviderConfig } from './provider-config.js';
|
|
30
|
+
|
|
31
|
+
export function createRegistry(wsRouter, deps) {
|
|
32
|
+
const { queries, sendJSON, parseBody, broadcastSync, debugLog, PORT, BASE_URL, rootDir, STARTUP_CWD, PKG_VERSION, processMessageWithStreaming, activeExecutions, activeProcessesByRunId, activeScripts, messageQueues, rateLimitState, cleanupExecution, discoveredAgents, getACPStatus, modelCache, getModelsForAgent, logError, toolManager, syncClients, wsOptimizer, errLogPath, getJsonlWatcher, routes } = deps;
|
|
33
|
+
|
|
34
|
+
initSpeechManager({ broadcastSync, syncClients, queries });
|
|
35
|
+
routes.speech = registerSpeechRoutes({ sendJSON, parseBody, broadcastSync, debugLog });
|
|
36
|
+
routes.oauth = registerOAuthRoutes({ sendJSON, parseBody, PORT, BASE_URL, rootDir });
|
|
37
|
+
routes.util = registerUtilRoutes({ sendJSON, parseBody, queries, STARTUP_CWD, PKG_VERSION });
|
|
38
|
+
routes.tools = registerToolRoutes({ sendJSON, parseBody, queries, broadcastSync, logError, toolManager });
|
|
39
|
+
routes.threads = registerThreadRoutes({ sendJSON, parseBody, queries });
|
|
40
|
+
routes.debug = registerDebugRoutes({ sendJSON, queries, activeExecutions, messageQueues, syncClients, wsOptimizer, _errLogPath: errLogPath });
|
|
41
|
+
routes.conv = registerConvRoutes({ sendJSON, parseBody, queries, activeExecutions, broadcastSync });
|
|
42
|
+
routes.agents = registerAgentRoutes({ sendJSON, parseBody, queries, discoveredAgents, getACPStatus, modelCache, getModelsForAgent, debugLog });
|
|
43
|
+
routes.messages = registerMessagesRoutes({ queries, sendJSON, parseBody, broadcastSync, processMessageWithStreaming, activeExecutions, messageQueues, debugLog, logError });
|
|
44
|
+
routes.sessions = registerSessionsRoutes({ queries, sendJSON, activeExecutions, rateLimitState, debugLog });
|
|
45
|
+
routes.runs = registerRunsRoutes({ sendJSON, parseBody, queries, broadcastSync, processMessageWithStreaming, activeExecutions, activeProcessesByRunId, discoveredAgents, STARTUP_CWD });
|
|
46
|
+
routes.scripts = registerScriptsRoutes({ sendJSON, parseBody, queries, broadcastSync, activeScripts, activeExecutions, processMessageWithStreaming, STARTUP_CWD });
|
|
47
|
+
routes.agentActions = registerAgentActionsRoutes({ sendJSON, queries, broadcastSync, discoveredAgents, activeScripts, startGeminiOAuth, startCodexOAuth, getGeminiOAuthState, getCodexOAuthState, modelCache, PORT, BASE_URL, rootDir });
|
|
48
|
+
routes.authConfig = registerAuthConfigRoutes({ sendJSON, parseBody, getProviderConfigs, saveProviderConfig });
|
|
49
|
+
|
|
50
|
+
registerConvHandlers(wsRouter, { queries, activeExecutions, rateLimitState, broadcastSync, processMessageWithStreaming, cleanupExecution, getJsonlWatcher });
|
|
51
|
+
registerConvHandlers2(wsRouter, { queries, activeExecutions, rateLimitState, broadcastSync, processMessageWithStreaming, cleanupExecution, getJsonlWatcher });
|
|
52
|
+
registerMsgHandlers(wsRouter, { queries, activeExecutions, messageQueues, broadcastSync, processMessageWithStreaming, logError });
|
|
53
|
+
registerQueueHandlers(wsRouter, { queries, messageQueues, broadcastSync });
|
|
54
|
+
debugLog('[INIT] registerSessionHandlers, agents: ' + discoveredAgents.length);
|
|
55
|
+
registerSessionHandlers(wsRouter, { db: queries, discoveredAgents, modelCache, getAgentDescriptor, activeScripts, broadcastSync, startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState });
|
|
56
|
+
registerSessionHandlers2(wsRouter, { discoveredAgents, modelCache, activeScripts, broadcastSync, startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState });
|
|
57
|
+
debugLog('[INIT] registerSessionHandlers completed');
|
|
58
|
+
registerRunHandlers(wsRouter, { queries, discoveredAgents, activeExecutions, activeProcessesByRunId, broadcastSync, processMessageWithStreaming, cleanupExecution });
|
|
59
|
+
registerUtilHandlers(wsRouter, { queries, wsOptimizer, modelDownloadState, ensureModelsDownloaded, broadcastSync, getSpeech, getProviderConfigs, saveProviderConfig, STARTUP_CWD, voiceCacheManager, toolManager, discoveredAgents });
|
|
60
|
+
registerScriptHandlers(wsRouter, { queries, broadcastSync, STARTUP_CWD, activeScripts });
|
|
61
|
+
registerOAuthHandlers(wsRouter, { startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), exchangeGeminiOAuthCode, geminiOAuthState: getGeminiOAuthState, startCodexOAuth: (req) => startCodexOAuth(req, { PORT, BASE_URL }), exchangeCodexOAuthCode, codexOAuthState: getCodexOAuthState });
|
|
62
|
+
}
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -11,20 +11,8 @@ import { initializeDescriptors, getAgentDescriptor } from './lib/agent-descripto
|
|
|
11
11
|
import { discoverExternalACPServers, initializeAgentDiscovery } from './lib/agent-discovery.js';
|
|
12
12
|
import { startGeminiOAuth, exchangeGeminiOAuthCode, handleGeminiOAuthCallback, getGeminiOAuthStatus, getGeminiOAuthState } from './lib/oauth-gemini.js';
|
|
13
13
|
import { initSpeechManager, getSpeech, voiceCacheManager, modelDownloadState, ensureModelsDownloaded, eagerTTS } from './lib/speech-manager.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { register as registerUtilRoutes } from './lib/routes-util.js';
|
|
17
|
-
import { register as registerToolRoutes } from './lib/routes-tools.js';
|
|
18
|
-
import { register as registerThreadRoutes } from './lib/routes-threads.js';
|
|
19
|
-
import { register as registerDebugRoutes } from './lib/routes-debug.js';
|
|
20
|
-
import { register as registerConvRoutes } from './lib/routes-conversations.js';
|
|
21
|
-
import { register as registerAgentRoutes } from './lib/routes-agents.js';
|
|
22
|
-
import { register as registerMessagesRoutes } from './lib/routes-messages.js';
|
|
23
|
-
import { register as registerSessionsRoutes } from './lib/routes-sessions.js';
|
|
24
|
-
import { register as registerRunsRoutes } from './lib/routes-runs.js';
|
|
25
|
-
import { register as registerScriptsRoutes } from './lib/routes-scripts.js';
|
|
26
|
-
import { register as registerAgentActionsRoutes } from './lib/routes-agent-actions.js';
|
|
27
|
-
import { register as registerAuthConfigRoutes } from './lib/routes-auth-config.js';
|
|
14
|
+
import { createRegistry } from './lib/routes-registry.js';
|
|
15
|
+
import { BROADCAST_TYPES } from './lib/broadcast.js';
|
|
28
16
|
import { startCodexOAuth, exchangeCodexOAuthCode, handleCodexOAuthCallback, getCodexOAuthStatus, getCodexOAuthState, CODEX_HOME, CODEX_AUTH_FILE } from './lib/oauth-codex.js';
|
|
29
17
|
import { WSOptimizer } from './lib/ws-optimizer.js';
|
|
30
18
|
import { WsRouter } from './lib/ws-protocol.js';
|
|
@@ -35,16 +23,6 @@ import { createHttpHandler } from './lib/http-handler.js';
|
|
|
35
23
|
import { createOnServerReady } from './lib/server-startup.js';
|
|
36
24
|
import { createAutoImport, createDbRecovery, createPluginLoader } from './lib/server-startup2.js';
|
|
37
25
|
const sendWs = (ws, obj) => { if (ws.readyState === 1) ws.send(wsEncode(obj)); };
|
|
38
|
-
import { register as registerConvHandlers } from './lib/ws-handlers-conv.js';
|
|
39
|
-
import { register as registerConvHandlers2 } from './lib/ws-handlers-conv2.js';
|
|
40
|
-
import { register as registerSessionHandlers } from './lib/ws-handlers-session.js';
|
|
41
|
-
import { register as registerSessionHandlers2 } from './lib/ws-handlers-session2.js';
|
|
42
|
-
import { register as registerRunHandlers } from './lib/ws-handlers-run.js';
|
|
43
|
-
import { register as registerUtilHandlers } from './lib/ws-handlers-util.js';
|
|
44
|
-
import { register as registerOAuthHandlers } from './lib/ws-handlers-oauth.js';
|
|
45
|
-
import { register as registerScriptHandlers } from './lib/ws-handlers-scripts.js';
|
|
46
|
-
import { register as registerQueueHandlers } from './lib/ws-handlers-queue.js';
|
|
47
|
-
import { register as registerMsgHandlers } from './lib/ws-handlers-msg.js';
|
|
48
26
|
import { startAll as startACPTools, stopAll as stopACPTools, getStatus as getACPStatus, getPort as getACPPort, ensureRunning, queryModels as queryACPModels, touch as touchACP } from './lib/acp-sdk-manager.js';
|
|
49
27
|
import * as execMachine from './lib/execution-machine.js';
|
|
50
28
|
import * as toolInstallMachine from './lib/tool-install-machine.js';
|
|
@@ -63,15 +41,9 @@ import { buildSystemPrompt, getProviderConfigs, saveProviderConfig } from './lib
|
|
|
63
41
|
import { logError, errLogPath, makeCleanupExecution, makeGetModelsForAgent } from './lib/server-utils.js';
|
|
64
42
|
|
|
65
43
|
|
|
66
|
-
process.on('uncaughtException', (err, origin) => {
|
|
67
|
-
console.error('[FATAL] Uncaught exception (contained):', err.message, '| origin:', origin);
|
|
68
|
-
console.error(err.stack);
|
|
69
|
-
});
|
|
44
|
+
process.on('uncaughtException', (err, origin) => { console.error('[FATAL] Uncaught exception:', err.message, '| origin:', origin); console.error(err.stack); });
|
|
70
45
|
|
|
71
|
-
process.on('unhandledRejection', (reason,
|
|
72
|
-
console.error('[FATAL] Unhandled rejection (contained):', reason instanceof Error ? reason.message : reason);
|
|
73
|
-
if (reason instanceof Error) console.error(reason.stack);
|
|
74
|
-
});
|
|
46
|
+
process.on('unhandledRejection', (reason) => { console.error('[FATAL] Unhandled rejection:', reason instanceof Error ? reason.message : reason); if (reason instanceof Error) console.error(reason.stack); });
|
|
75
47
|
|
|
76
48
|
process.on('SIGHUP', () => { console.log('[SIGNAL] SIGHUP received (ignored - uncrashable)'); });
|
|
77
49
|
process.on('beforeExit', (code) => { console.log('[PROCESS] beforeExit with code:', code); });
|
|
@@ -86,7 +58,6 @@ const activeProcessesByRunId = new Map();
|
|
|
86
58
|
const checkpointManager = new CheckpointManager(queries);
|
|
87
59
|
const STUCK_AGENT_THRESHOLD_MS = 1800000;
|
|
88
60
|
const NO_PID_GRACE_PERIOD_MS = 60000;
|
|
89
|
-
const DEFAULT_RATE_LIMIT_COOLDOWN_MS = 60000;
|
|
90
61
|
|
|
91
62
|
const debugLog = (msg) => {
|
|
92
63
|
const timestamp = new Date().toISOString();
|
|
@@ -127,47 +98,13 @@ const _assetDeps = { compressAndSend, acceptsEncoding, watch, BASE_URL, PKG_VERS
|
|
|
127
98
|
function serveFile(filePath, res, req) { return _serveFile(filePath, res, req, _assetDeps); }
|
|
128
99
|
|
|
129
100
|
const _routes = {};
|
|
130
|
-
const server = http.createServer(createHttpHandler({
|
|
131
|
-
BASE_URL, expressApp, queries, sendJSON, serveFile, staticDir, messageQueues,
|
|
132
|
-
get wss() { return wss; }, activeExecutions, getACPStatus, discoveredAgents,
|
|
133
|
-
PKG_VERSION, RATE_LIMIT_MAX, rateLimitMap: _rateLimitMap,
|
|
134
|
-
get convRoutes() { return _routes.conv; },
|
|
135
|
-
get messagesRoutes() { return _routes.messages; },
|
|
136
|
-
get sessionsRoutes() { return _routes.sessions; },
|
|
137
|
-
get scriptsRoutes() { return _routes.scripts; },
|
|
138
|
-
get runsRoutes() { return _routes.runs; },
|
|
139
|
-
get agentRoutes() { return _routes.agents; },
|
|
140
|
-
get oauthRoutes() { return _routes.oauth; },
|
|
141
|
-
get agentActionsRoutes() { return _routes.agentActions; },
|
|
142
|
-
get authConfigRoutes() { return _routes.authConfig; },
|
|
143
|
-
get speechRoutes() { return _routes.speech; },
|
|
144
|
-
get utilRoutes() { return _routes.util; },
|
|
145
|
-
get threadRoutes() { return _routes.threads; },
|
|
146
|
-
handleGeminiOAuthCallback, handleCodexOAuthCallback, PORT
|
|
147
|
-
}));
|
|
101
|
+
const server = http.createServer(createHttpHandler({ BASE_URL, expressApp, queries, sendJSON, serveFile, staticDir, messageQueues, get wss() { return wss; }, activeExecutions, getACPStatus, discoveredAgents, PKG_VERSION, RATE_LIMIT_MAX, rateLimitMap: _rateLimitMap, routes: _routes, handleGeminiOAuthCallback, handleCodexOAuthCallback, PORT }));
|
|
148
102
|
|
|
149
103
|
let broadcastSeq = 0;
|
|
150
104
|
const syncClients = new Set();
|
|
151
105
|
const subscriptionIndex = new Map();
|
|
152
106
|
const pm2Subscribers = new Set();
|
|
153
107
|
|
|
154
|
-
const BROADCAST_TYPES = new Set([
|
|
155
|
-
'message_created', 'conversation_created', 'conversation_updated',
|
|
156
|
-
'conversations_updated', 'conversation_deleted', 'all_conversations_deleted', 'queue_status', 'queue_updated', 'queue_item_dequeued',
|
|
157
|
-
'rate_limit_hit', 'rate_limit_clear',
|
|
158
|
-
'script_started', 'script_stopped', 'script_output',
|
|
159
|
-
'model_download_progress', 'stt_progress', 'tts_setup_progress', 'voice_list',
|
|
160
|
-
'streaming_start', 'streaming_progress', 'streaming_complete', 'streaming_error',
|
|
161
|
-
'tool_install_started', 'tool_install_progress', 'tool_install_complete', 'tool_install_failed',
|
|
162
|
-
'tool_update_progress', 'tool_update_complete', 'tool_update_failed',
|
|
163
|
-
'tool_status_update', 'tool_update_available',
|
|
164
|
-
'tools_update_started', 'tools_update_complete', 'tools_refresh_complete',
|
|
165
|
-
'pm2_monit_update', 'pm2_monitoring_started', 'pm2_monitoring_stopped',
|
|
166
|
-
'pm2_list_response', 'pm2_start_response', 'pm2_stop_response',
|
|
167
|
-
'pm2_restart_response', 'pm2_delete_response', 'pm2_logs_response',
|
|
168
|
-
'pm2_flush_logs_response', 'pm2_ping_response', 'pm2_unavailable'
|
|
169
|
-
]);
|
|
170
|
-
|
|
171
108
|
const wsOptimizer = new WSOptimizer();
|
|
172
109
|
|
|
173
110
|
const broadcastSync = createBroadcast({
|
|
@@ -179,13 +116,7 @@ const broadcastSync = createBroadcast({
|
|
|
179
116
|
});
|
|
180
117
|
|
|
181
118
|
const cleanupExecution = makeCleanupExecution({ execMachine, activeExecutions, queries, broadcastSync, debugLog });
|
|
182
|
-
|
|
183
|
-
const _mqDeps = {
|
|
184
|
-
queries, messageQueues, activeExecutions, rateLimitState, execMachine,
|
|
185
|
-
broadcastSync, cleanupExecution, debugLog,
|
|
186
|
-
getProcessMessageWithStreaming: () => processMessageWithStreaming
|
|
187
|
-
};
|
|
188
|
-
const { scheduleRetry, drainMessageQueue } = createMessageQueue(_mqDeps);
|
|
119
|
+
const { scheduleRetry, drainMessageQueue } = createMessageQueue({ queries, messageQueues, activeExecutions, rateLimitState, execMachine, broadcastSync, cleanupExecution, debugLog, getProcessMessageWithStreaming: () => processMessageWithStreaming });
|
|
189
120
|
|
|
190
121
|
const { processMessageWithStreaming } = createProcessMessage({
|
|
191
122
|
queries, activeExecutions, rateLimitState, execMachine,
|
|
@@ -197,76 +128,8 @@ const { processMessageWithStreaming } = createProcessMessage({
|
|
|
197
128
|
});
|
|
198
129
|
|
|
199
130
|
const wsRouter = new WsRouter();
|
|
131
|
+
createRegistry(wsRouter, { queries, sendJSON, parseBody, broadcastSync, debugLog, PORT, BASE_URL, rootDir, STARTUP_CWD, PKG_VERSION, processMessageWithStreaming, activeExecutions, activeProcessesByRunId, activeScripts, messageQueues, rateLimitState, cleanupExecution, discoveredAgents, getACPStatus, modelCache, getModelsForAgent, logError, toolManager, syncClients, wsOptimizer, errLogPath, getJsonlWatcher: () => getJsonlWatcher(), routes: _routes });
|
|
200
132
|
|
|
201
|
-
initSpeechManager({ broadcastSync, syncClients, queries });
|
|
202
|
-
_routes.speech = registerSpeechRoutes({ sendJSON, parseBody, broadcastSync, debugLog });
|
|
203
|
-
_routes.oauth = registerOAuthRoutes({ sendJSON, parseBody, PORT, BASE_URL, rootDir });
|
|
204
|
-
_routes.util = registerUtilRoutes({ sendJSON, parseBody, queries, STARTUP_CWD, PKG_VERSION });
|
|
205
|
-
const _toolRoutes = registerToolRoutes({ sendJSON, parseBody, queries, broadcastSync, logError, toolManager });
|
|
206
|
-
_routes.threads = registerThreadRoutes({ sendJSON, parseBody, queries });
|
|
207
|
-
const _debugRoutes = registerDebugRoutes({ sendJSON, queries, activeExecutions, messageQueues, syncClients, wsOptimizer, _errLogPath: errLogPath });
|
|
208
|
-
_routes.conv = registerConvRoutes({ sendJSON, parseBody, queries, activeExecutions, broadcastSync });
|
|
209
|
-
_routes.agents = registerAgentRoutes({ sendJSON, parseBody, queries, discoveredAgents, getACPStatus, modelCache, getModelsForAgent, debugLog });
|
|
210
|
-
_routes.messages = registerMessagesRoutes({ queries, sendJSON, parseBody, broadcastSync, processMessageWithStreaming, activeExecutions, messageQueues, debugLog, logError });
|
|
211
|
-
_routes.sessions = registerSessionsRoutes({ queries, sendJSON, activeExecutions, rateLimitState, debugLog });
|
|
212
|
-
_routes.runs = registerRunsRoutes({ sendJSON, parseBody, queries, broadcastSync, processMessageWithStreaming, activeExecutions, activeProcessesByRunId, discoveredAgents, STARTUP_CWD });
|
|
213
|
-
_routes.scripts = registerScriptsRoutes({ sendJSON, parseBody, queries, broadcastSync, activeScripts, activeExecutions, processMessageWithStreaming, STARTUP_CWD });
|
|
214
|
-
_routes.agentActions = registerAgentActionsRoutes({ sendJSON, queries, broadcastSync, discoveredAgents, activeScripts, startGeminiOAuth, startCodexOAuth, getGeminiOAuthState, getCodexOAuthState, modelCache, PORT, BASE_URL, rootDir });
|
|
215
|
-
_routes.authConfig = registerAuthConfigRoutes({ sendJSON, parseBody, getProviderConfigs, saveProviderConfig });
|
|
216
|
-
|
|
217
|
-
registerConvHandlers(wsRouter, {
|
|
218
|
-
queries, activeExecutions, rateLimitState,
|
|
219
|
-
broadcastSync, processMessageWithStreaming, cleanupExecution,
|
|
220
|
-
getJsonlWatcher
|
|
221
|
-
});
|
|
222
|
-
registerConvHandlers2(wsRouter, {
|
|
223
|
-
queries, activeExecutions, rateLimitState,
|
|
224
|
-
broadcastSync, processMessageWithStreaming, cleanupExecution,
|
|
225
|
-
getJsonlWatcher
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
registerMsgHandlers(wsRouter, {
|
|
229
|
-
queries, activeExecutions, messageQueues,
|
|
230
|
-
broadcastSync, processMessageWithStreaming, logError
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
registerQueueHandlers(wsRouter, { queries, messageQueues, broadcastSync });
|
|
234
|
-
|
|
235
|
-
debugLog('[INIT] registerSessionHandlers, agents: ' + discoveredAgents.length);
|
|
236
|
-
registerSessionHandlers(wsRouter, {
|
|
237
|
-
db: queries, discoveredAgents, modelCache,
|
|
238
|
-
getAgentDescriptor, activeScripts, broadcastSync,
|
|
239
|
-
startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState
|
|
240
|
-
});
|
|
241
|
-
registerSessionHandlers2(wsRouter, {
|
|
242
|
-
discoveredAgents, modelCache, activeScripts, broadcastSync,
|
|
243
|
-
startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState
|
|
244
|
-
});
|
|
245
|
-
debugLog('[INIT] registerSessionHandlers completed');
|
|
246
|
-
|
|
247
|
-
registerRunHandlers(wsRouter, {
|
|
248
|
-
queries, discoveredAgents, activeExecutions, activeProcessesByRunId,
|
|
249
|
-
broadcastSync, processMessageWithStreaming, cleanupExecution
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
registerUtilHandlers(wsRouter, {
|
|
253
|
-
queries, wsOptimizer, modelDownloadState, ensureModelsDownloaded,
|
|
254
|
-
broadcastSync, getSpeech, getProviderConfigs, saveProviderConfig,
|
|
255
|
-
STARTUP_CWD, voiceCacheManager, toolManager, discoveredAgents
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
registerScriptHandlers(wsRouter, {
|
|
259
|
-
queries, broadcastSync, STARTUP_CWD, activeScripts
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
registerOAuthHandlers(wsRouter, {
|
|
263
|
-
startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }),
|
|
264
|
-
exchangeGeminiOAuthCode,
|
|
265
|
-
geminiOAuthState: getGeminiOAuthState,
|
|
266
|
-
startCodexOAuth: (req) => startCodexOAuth(req, { PORT, BASE_URL }),
|
|
267
|
-
exchangeCodexOAuthCode,
|
|
268
|
-
codexOAuthState: getCodexOAuthState,
|
|
269
|
-
});
|
|
270
133
|
|
|
271
134
|
const { wss, hotReloadClients } = createWsSetup(server, {
|
|
272
135
|
BASE_URL, watch, staticDir, _assetCache, htmlState, sendWs, wsRouter, debugLog,
|