agentgui 1.0.832 → 1.0.834
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 +4 -0
- package/lib/claude-runner-acp.js +155 -0
- package/lib/claude-runner-agents.js +104 -0
- package/lib/claude-runner-direct.js +116 -0
- package/lib/claude-runner-run.js +49 -0
- package/lib/claude-runner.js +55 -1266
- package/lib/db-queries-chunks.js +195 -0
- package/lib/db-queries-chunks2.js +82 -0
- package/lib/db-queries-cleanup.js +85 -0
- package/lib/db-queries-del.js +142 -0
- package/lib/db-queries-events.js +68 -0
- package/lib/db-queries-import.js +133 -0
- package/lib/db-queries-messages.js +102 -0
- package/lib/db-queries-sessions.js +112 -0
- package/lib/db-queries-streams.js +100 -0
- package/lib/db-queries-tools.js +127 -0
- package/lib/db-queries-voice.js +85 -0
- package/lib/db-queries.js +92 -1412
- package/lib/plugins/agents-plugin.js +0 -3
- package/lib/speech-manager.js +1 -7
- package/lib/ws-handlers-session.js +3 -117
- package/lib/ws-handlers-session2.js +106 -0
- package/package.json +1 -1
- package/server.js +1 -1
package/lib/speech-manager.js
CHANGED
|
@@ -2,7 +2,6 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
|
-
|
|
6
5
|
let speechModule = null;
|
|
7
6
|
let _broadcastSync = null;
|
|
8
7
|
let _syncClients = null;
|
|
@@ -13,18 +12,15 @@ export function initSpeechManager({ broadcastSync, syncClients, queries }) {
|
|
|
13
12
|
_syncClients = syncClients;
|
|
14
13
|
_queries = queries;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
export async function ensurePocketTtsSetup(onProgress) {
|
|
18
16
|
const r = createRequire(import.meta.url);
|
|
19
17
|
const serverTTS = r('webtalk/server-tts');
|
|
20
18
|
return serverTTS.ensureInstalled(onProgress);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
export async function getSpeech() {
|
|
24
21
|
if (!speechModule) speechModule = await import('./speech.js');
|
|
25
22
|
return speechModule;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
const ttsTextAccumulators = new Map();
|
|
29
25
|
|
|
30
26
|
export const voiceCacheManager = {
|
|
@@ -58,7 +54,6 @@ export const voiceCacheManager = {
|
|
|
58
54
|
}
|
|
59
55
|
}
|
|
60
56
|
};
|
|
61
|
-
|
|
62
57
|
export const modelDownloadState = {
|
|
63
58
|
downloading: false,
|
|
64
59
|
progress: null,
|
|
@@ -68,7 +63,6 @@ export const modelDownloadState = {
|
|
|
68
63
|
downloadMetrics: new Map(),
|
|
69
64
|
waiters: []
|
|
70
65
|
};
|
|
71
|
-
|
|
72
66
|
export function broadcastModelProgress(progress) {
|
|
73
67
|
modelDownloadState.progress = progress;
|
|
74
68
|
const broadcastData = {
|
|
@@ -203,4 +197,4 @@ function pushTTSAudio(cacheKey, wav, conversationId, sessionId, voiceId) {
|
|
|
203
197
|
sessionId,
|
|
204
198
|
timestamp: Date.now()
|
|
205
199
|
});
|
|
206
|
-
}
|
|
200
|
+
}
|
|
@@ -1,79 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { execSync, spawn } from 'child_process';
|
|
5
|
-
import { ensureRunning, touch, queryModels } from './acp-sdk-manager.js';
|
|
6
|
-
|
|
7
|
-
function spawnScript(cmd, args, convId, scriptName, agentId, deps) {
|
|
8
|
-
const { activeScripts, broadcastSync, modelCache } = deps;
|
|
9
|
-
if (activeScripts.has(convId)) throw { code: 409, message: 'Process already running' };
|
|
10
|
-
const child = spawn(cmd, args, {
|
|
11
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
12
|
-
env: { ...process.env, FORCE_COLOR: '1' },
|
|
13
|
-
shell: os.platform() === 'win32'
|
|
14
|
-
});
|
|
15
|
-
activeScripts.set(convId, { process: child, script: scriptName, startTime: Date.now() });
|
|
16
|
-
broadcastSync({ type: 'script_started', conversationId: convId, script: scriptName, agentId, timestamp: Date.now() });
|
|
17
|
-
const relay = (stream) => (chunk) => {
|
|
18
|
-
broadcastSync({ type: 'script_output', conversationId: convId, data: chunk.toString(), stream, timestamp: Date.now() });
|
|
19
|
-
};
|
|
20
|
-
child.stdout.on('data', relay('stdout'));
|
|
21
|
-
child.stderr.on('data', relay('stderr'));
|
|
22
|
-
child.on('error', (err) => {
|
|
23
|
-
activeScripts.delete(convId);
|
|
24
|
-
broadcastSync({ type: 'script_stopped', conversationId: convId, code: 1, error: err.message, timestamp: Date.now() });
|
|
25
|
-
});
|
|
26
|
-
child.on('close', (code) => {
|
|
27
|
-
activeScripts.delete(convId);
|
|
28
|
-
if (modelCache && agentId) modelCache.delete(agentId);
|
|
29
|
-
broadcastSync({ type: 'script_stopped', conversationId: convId, code: code || 0, timestamp: Date.now() });
|
|
30
|
-
});
|
|
31
|
-
return child.pid;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function readJson(filePath) {
|
|
35
|
-
try { return fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : null; } catch { return null; }
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function checkAgentAuth(agent) {
|
|
39
|
-
const s = { id: agent.id, name: agent.name, authenticated: false, detail: '' };
|
|
40
|
-
try {
|
|
41
|
-
if (agent.id === 'claude-code') {
|
|
42
|
-
const creds = readJson(path.join(os.homedir(), '.claude', '.credentials.json'));
|
|
43
|
-
if (creds?.claudeAiOauth?.expiresAt > Date.now()) {
|
|
44
|
-
s.authenticated = true;
|
|
45
|
-
s.detail = creds.claudeAiOauth.subscriptionType || 'authenticated';
|
|
46
|
-
} else { s.detail = creds ? 'expired' : 'no credentials'; }
|
|
47
|
-
} else if (agent.id === 'gemini') {
|
|
48
|
-
const oauth = readJson(path.join(os.homedir(), '.gemini', 'oauth_creds.json'));
|
|
49
|
-
const accts = readJson(path.join(os.homedir(), '.gemini', 'google_accounts.json'));
|
|
50
|
-
const hasOAuth = !!(oauth?.refresh_token || oauth?.access_token);
|
|
51
|
-
if (accts?.active) { s.authenticated = true; s.detail = accts.active; }
|
|
52
|
-
else if (hasOAuth) { s.authenticated = true; s.detail = 'oauth'; }
|
|
53
|
-
else { s.detail = accts ? 'logged out' : 'no credentials'; }
|
|
54
|
-
} else if (agent.id === 'opencode') {
|
|
55
|
-
const out = execSync('opencode auth list 2>&1', { encoding: 'utf-8', timeout: 5000 });
|
|
56
|
-
const m = out.match(/(\d+)\s+credentials?/);
|
|
57
|
-
if (m && parseInt(m[1], 10) > 0) { s.authenticated = true; s.detail = m[1] + ' credential(s)'; }
|
|
58
|
-
else { s.detail = 'no credentials'; }
|
|
59
|
-
} else { s.detail = 'unknown'; }
|
|
60
|
-
} catch { s.detail = 'check failed'; }
|
|
61
|
-
return s;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function acpFetch(port, pth, body = null) {
|
|
65
|
-
const opts = { headers: { 'Content-Type': 'application/json' }, signal: AbortSignal.timeout(3000) };
|
|
66
|
-
if (body !== null) { opts.method = 'POST'; opts.body = JSON.stringify(body); }
|
|
67
|
-
const res = await fetch(`http://localhost:${port}${pth}`, opts);
|
|
68
|
-
if (!res.ok) return null;
|
|
69
|
-
return res.json();
|
|
70
|
-
}
|
|
71
|
-
|
|
1
|
+
import { queryModels } from './acp-sdk-manager.js';
|
|
72
2
|
|
|
73
3
|
export function register(router, deps) {
|
|
74
|
-
const { db, discoveredAgents, modelCache,
|
|
75
|
-
getAgentDescriptor, activeScripts, broadcastSync, startGeminiOAuth,
|
|
76
|
-
geminiOAuthState } = deps;
|
|
4
|
+
const { db, discoveredAgents, modelCache, getAgentDescriptor } = deps;
|
|
77
5
|
console.log('[ws-handlers-session] register() called with discoveredAgents.length:', discoveredAgents.length);
|
|
78
6
|
|
|
79
7
|
router.handle('sess.get', (p) => {
|
|
@@ -129,8 +57,6 @@ export function register(router, deps) {
|
|
|
129
57
|
}))
|
|
130
58
|
};
|
|
131
59
|
});
|
|
132
|
-
// Note: agent.subagents is handled by ws-handlers-util.js which is registered after this file
|
|
133
|
-
// Keeping this note to avoid duplicate handler registration
|
|
134
60
|
|
|
135
61
|
router.handle('agent.get', (p) => {
|
|
136
62
|
const a = discoveredAgents.find(x => x.id === p.id);
|
|
@@ -165,44 +91,4 @@ export function register(router, deps) {
|
|
|
165
91
|
});
|
|
166
92
|
|
|
167
93
|
router.handle('agent.search', (p) => db.searchAgents(discoveredAgents, p.query || p));
|
|
168
|
-
|
|
169
|
-
router.handle('agent.auth', async (p) => {
|
|
170
|
-
const agentId = p.id;
|
|
171
|
-
if (!discoveredAgents.find(a => a.id === agentId)) throw { code: 404, message: 'Agent not found' };
|
|
172
|
-
if (agentId === 'gemini') {
|
|
173
|
-
const result = await startGeminiOAuth();
|
|
174
|
-
const cid = '__agent_auth__';
|
|
175
|
-
broadcastSync({ type: 'script_started', conversationId: cid, script: 'auth-gemini', agentId: 'gemini', timestamp: Date.now() });
|
|
176
|
-
broadcastSync({ type: 'script_output', conversationId: cid, data: `\x1b[36mOpening Google OAuth...\x1b[0m\r\n\r\nVisit:\r\n${result.authUrl}\r\n`, stream: 'stdout', timestamp: Date.now() });
|
|
177
|
-
const pollId = setInterval(() => {
|
|
178
|
-
const st = geminiOAuthState();
|
|
179
|
-
if (st.status === 'success') {
|
|
180
|
-
clearInterval(pollId);
|
|
181
|
-
broadcastSync({ type: 'script_output', conversationId: cid, data: `\r\n\x1b[32mAuth OK${st.email ? ' (' + st.email + ')' : ''}\x1b[0m\r\n`, stream: 'stdout', timestamp: Date.now() });
|
|
182
|
-
broadcastSync({ type: 'script_stopped', conversationId: cid, code: 0, timestamp: Date.now() });
|
|
183
|
-
} else if (st.status === 'error') {
|
|
184
|
-
clearInterval(pollId);
|
|
185
|
-
broadcastSync({ type: 'script_output', conversationId: cid, data: `\r\n\x1b[31mAuth failed: ${st.error}\x1b[0m\r\n`, stream: 'stderr', timestamp: Date.now() });
|
|
186
|
-
broadcastSync({ type: 'script_stopped', conversationId: cid, code: 1, error: st.error, timestamp: Date.now() });
|
|
187
|
-
}
|
|
188
|
-
}, 1000);
|
|
189
|
-
setTimeout(() => clearInterval(pollId), 5 * 60 * 1000);
|
|
190
|
-
return { ok: true, agentId, authUrl: result.authUrl, mode: result.mode };
|
|
191
|
-
}
|
|
192
|
-
const cmds = { 'claude-code': { cmd: 'claude', args: ['setup-token'] }, 'opencode': { cmd: 'opencode', args: ['auth', 'login'] } };
|
|
193
|
-
const c = cmds[agentId];
|
|
194
|
-
if (!c) throw { code: 400, message: 'No auth command for this agent' };
|
|
195
|
-
const pid = spawnScript(c.cmd, c.args, '__agent_auth__', 'auth-' + agentId, agentId, { activeScripts, broadcastSync });
|
|
196
|
-
return { ok: true, agentId, pid };
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
router.handle('agent.authstat', () => ({ agents: discoveredAgents.map(checkAgentAuth) }));
|
|
200
|
-
|
|
201
|
-
router.handle('agent.update', (p) => {
|
|
202
|
-
const cmds = { 'claude-code': { cmd: 'claude', args: ['update', '--yes'] } };
|
|
203
|
-
const c = cmds[p.id];
|
|
204
|
-
if (!c) throw { code: 400, message: 'No update command for this agent' };
|
|
205
|
-
const pid = spawnScript(c.cmd, c.args, '__agent_update__', 'update-' + p.id, p.id, { activeScripts, broadcastSync, modelCache });
|
|
206
|
-
return { ok: true, agentId: p.id, pid };
|
|
207
|
-
});
|
|
208
|
-
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { execSync, spawn } from 'child_process';
|
|
5
|
+
|
|
6
|
+
function spawnScript(cmd, args, convId, scriptName, agentId, deps) {
|
|
7
|
+
const { activeScripts, broadcastSync, modelCache } = deps;
|
|
8
|
+
if (activeScripts.has(convId)) throw { code: 409, message: 'Process already running' };
|
|
9
|
+
const child = spawn(cmd, args, {
|
|
10
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
11
|
+
env: { ...process.env, FORCE_COLOR: '1' },
|
|
12
|
+
shell: os.platform() === 'win32'
|
|
13
|
+
});
|
|
14
|
+
activeScripts.set(convId, { process: child, script: scriptName, startTime: Date.now() });
|
|
15
|
+
broadcastSync({ type: 'script_started', conversationId: convId, script: scriptName, agentId, timestamp: Date.now() });
|
|
16
|
+
const relay = (stream) => (chunk) => {
|
|
17
|
+
broadcastSync({ type: 'script_output', conversationId: convId, data: chunk.toString(), stream, timestamp: Date.now() });
|
|
18
|
+
};
|
|
19
|
+
child.stdout.on('data', relay('stdout'));
|
|
20
|
+
child.stderr.on('data', relay('stderr'));
|
|
21
|
+
child.on('error', (err) => {
|
|
22
|
+
activeScripts.delete(convId);
|
|
23
|
+
broadcastSync({ type: 'script_stopped', conversationId: convId, code: 1, error: err.message, timestamp: Date.now() });
|
|
24
|
+
});
|
|
25
|
+
child.on('close', (code) => {
|
|
26
|
+
activeScripts.delete(convId);
|
|
27
|
+
if (modelCache && agentId) modelCache.delete(agentId);
|
|
28
|
+
broadcastSync({ type: 'script_stopped', conversationId: convId, code: code || 0, timestamp: Date.now() });
|
|
29
|
+
});
|
|
30
|
+
return child.pid;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readJson(filePath) {
|
|
34
|
+
try { return fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : null; } catch { return null; }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function checkAgentAuth(agent) {
|
|
38
|
+
const s = { id: agent.id, name: agent.name, authenticated: false, detail: '' };
|
|
39
|
+
try {
|
|
40
|
+
if (agent.id === 'claude-code') {
|
|
41
|
+
const creds = readJson(path.join(os.homedir(), '.claude', '.credentials.json'));
|
|
42
|
+
if (creds?.claudeAiOauth?.expiresAt > Date.now()) {
|
|
43
|
+
s.authenticated = true;
|
|
44
|
+
s.detail = creds.claudeAiOauth.subscriptionType || 'authenticated';
|
|
45
|
+
} else { s.detail = creds ? 'expired' : 'no credentials'; }
|
|
46
|
+
} else if (agent.id === 'gemini') {
|
|
47
|
+
const oauth = readJson(path.join(os.homedir(), '.gemini', 'oauth_creds.json'));
|
|
48
|
+
const accts = readJson(path.join(os.homedir(), '.gemini', 'google_accounts.json'));
|
|
49
|
+
const hasOAuth = !!(oauth?.refresh_token || oauth?.access_token);
|
|
50
|
+
if (accts?.active) { s.authenticated = true; s.detail = accts.active; }
|
|
51
|
+
else if (hasOAuth) { s.authenticated = true; s.detail = 'oauth'; }
|
|
52
|
+
else { s.detail = accts ? 'logged out' : 'no credentials'; }
|
|
53
|
+
} else if (agent.id === 'opencode') {
|
|
54
|
+
const out = execSync('opencode auth list 2>&1', { encoding: 'utf-8', timeout: 5000 });
|
|
55
|
+
const m = out.match(/(\d+)\s+credentials?/);
|
|
56
|
+
if (m && parseInt(m[1], 10) > 0) { s.authenticated = true; s.detail = m[1] + ' credential(s)'; }
|
|
57
|
+
else { s.detail = 'no credentials'; }
|
|
58
|
+
} else { s.detail = 'unknown'; }
|
|
59
|
+
} catch { s.detail = 'check failed'; }
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function register(router, deps) {
|
|
64
|
+
const { discoveredAgents, modelCache, activeScripts, broadcastSync,
|
|
65
|
+
startGeminiOAuth, geminiOAuthState } = deps;
|
|
66
|
+
|
|
67
|
+
router.handle('agent.auth', async (p) => {
|
|
68
|
+
const agentId = p.id;
|
|
69
|
+
if (!discoveredAgents.find(a => a.id === agentId)) throw { code: 404, message: 'Agent not found' };
|
|
70
|
+
if (agentId === 'gemini') {
|
|
71
|
+
const result = await startGeminiOAuth();
|
|
72
|
+
const cid = '__agent_auth__';
|
|
73
|
+
broadcastSync({ type: 'script_started', conversationId: cid, script: 'auth-gemini', agentId: 'gemini', timestamp: Date.now() });
|
|
74
|
+
broadcastSync({ type: 'script_output', conversationId: cid, data: `\x1b[36mOpening Google OAuth...\x1b[0m\r\n\r\nVisit:\r\n${result.authUrl}\r\n`, stream: 'stdout', timestamp: Date.now() });
|
|
75
|
+
const pollId = setInterval(() => {
|
|
76
|
+
const st = geminiOAuthState();
|
|
77
|
+
if (st.status === 'success') {
|
|
78
|
+
clearInterval(pollId);
|
|
79
|
+
broadcastSync({ type: 'script_output', conversationId: cid, data: `\r\n\x1b[32mAuth OK${st.email ? ' (' + st.email + ')' : ''}\x1b[0m\r\n`, stream: 'stdout', timestamp: Date.now() });
|
|
80
|
+
broadcastSync({ type: 'script_stopped', conversationId: cid, code: 0, timestamp: Date.now() });
|
|
81
|
+
} else if (st.status === 'error') {
|
|
82
|
+
clearInterval(pollId);
|
|
83
|
+
broadcastSync({ type: 'script_output', conversationId: cid, data: `\r\n\x1b[31mAuth failed: ${st.error}\x1b[0m\r\n`, stream: 'stderr', timestamp: Date.now() });
|
|
84
|
+
broadcastSync({ type: 'script_stopped', conversationId: cid, code: 1, error: st.error, timestamp: Date.now() });
|
|
85
|
+
}
|
|
86
|
+
}, 1000);
|
|
87
|
+
setTimeout(() => clearInterval(pollId), 5 * 60 * 1000);
|
|
88
|
+
return { ok: true, agentId, authUrl: result.authUrl, mode: result.mode };
|
|
89
|
+
}
|
|
90
|
+
const cmds = { 'claude-code': { cmd: 'claude', args: ['setup-token'] }, 'opencode': { cmd: 'opencode', args: ['auth', 'login'] } };
|
|
91
|
+
const c = cmds[agentId];
|
|
92
|
+
if (!c) throw { code: 400, message: 'No auth command for this agent' };
|
|
93
|
+
const pid = spawnScript(c.cmd, c.args, '__agent_auth__', 'auth-' + agentId, agentId, { activeScripts, broadcastSync });
|
|
94
|
+
return { ok: true, agentId, pid };
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
router.handle('agent.authstat', () => ({ agents: discoveredAgents.map(checkAgentAuth) }));
|
|
98
|
+
|
|
99
|
+
router.handle('agent.update', (p) => {
|
|
100
|
+
const cmds = { 'claude-code': { cmd: 'claude', args: ['update', '--yes'] } };
|
|
101
|
+
const c = cmds[p.id];
|
|
102
|
+
if (!c) throw { code: 400, message: 'No update command for this agent' };
|
|
103
|
+
const pid = spawnScript(c.cmd, c.args, '__agent_update__', 'update-' + p.id, p.id, { activeScripts, broadcastSync, modelCache });
|
|
104
|
+
return { ok: true, agentId: p.id, pid };
|
|
105
|
+
});
|
|
106
|
+
}
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -14,7 +14,7 @@ import express from 'express';
|
|
|
14
14
|
import Busboy from 'busboy';
|
|
15
15
|
import fsbrowse from 'fsbrowse';
|
|
16
16
|
import { queries } from './database.js';
|
|
17
|
-
import { runClaudeWithStreaming } from './lib/claude-runner.js';
|
|
17
|
+
import { runClaudeWithStreaming } from './lib/claude-runner-run.js';
|
|
18
18
|
import { initializeDescriptors, getAgentDescriptor } from './lib/agent-descriptors.js';
|
|
19
19
|
import { discoverExternalACPServers, initializeAgentDiscovery } from './lib/agent-discovery.js';
|
|
20
20
|
import { startGeminiOAuth, exchangeGeminiOAuthCode, handleGeminiOAuthCallback, getGeminiOAuthStatus, getGeminiOAuthState } from './lib/oauth-gemini.js';
|