agentgui 1.0.509 → 1.0.511

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.
@@ -6,10 +6,10 @@ import path from 'path';
6
6
 
7
7
  const isWindows = os.platform() === 'win32';
8
8
  const TOOLS = [
9
- { id: 'gm-oc', name: 'OpenCode', pkg: 'gm-oc' },
10
- { id: 'gm-gc', name: 'Gemini CLI', pkg: 'gm-gc' },
11
- { id: 'gm-kilo', name: 'Kilo', pkg: 'gm-kilo' },
12
- { id: 'gm-cc', name: 'Claude Code', pkg: 'gm-cc' },
9
+ { id: 'gm-oc', name: 'OpenCode', pkg: 'opencode-ai' },
10
+ { id: 'gm-gc', name: 'Gemini CLI', pkg: '@google/gemini-cli' },
11
+ { id: 'gm-kilo', name: 'Kilo', pkg: '@kilocode/cli' },
12
+ { id: 'gm-cc', name: 'Claude Code', pkg: '@anthropic-ai/claude-code' },
13
13
  ];
14
14
 
15
15
  const statusCache = new Map();
@@ -26,12 +26,58 @@ const getNodeModulesPath = () => {
26
26
  const getInstalledVersion = (pkg) => {
27
27
  try {
28
28
  const homeDir = os.homedir();
29
- const pluginPath = path.join(homeDir, '.claude', 'plugins', pkg);
30
- const pluginJsonPath = path.join(pluginPath, 'plugin.json');
31
- if (fs.existsSync(pluginJsonPath)) {
32
- const pluginJson = JSON.parse(fs.readFileSync(pluginJsonPath, 'utf-8'));
33
- if (pluginJson.version) {
34
- return pluginJson.version;
29
+
30
+ // Check Claude Code plugins
31
+ const claudePath = path.join(homeDir, '.claude', 'plugins', pkg, 'plugin.json');
32
+ if (fs.existsSync(claudePath)) {
33
+ try {
34
+ const pluginJson = JSON.parse(fs.readFileSync(claudePath, 'utf-8'));
35
+ if (pluginJson.version) return pluginJson.version;
36
+ } catch (e) {
37
+ console.warn(`[tool-manager] Failed to parse ${claudePath}:`, e.message);
38
+ }
39
+ }
40
+
41
+ // Check OpenCode agents
42
+ const opencodePath = path.join(homeDir, '.config', 'opencode', 'agents', pkg, 'plugin.json');
43
+ if (fs.existsSync(opencodePath)) {
44
+ try {
45
+ const pluginJson = JSON.parse(fs.readFileSync(opencodePath, 'utf-8'));
46
+ if (pluginJson.version) return pluginJson.version;
47
+ } catch (e) {
48
+ console.warn(`[tool-manager] Failed to parse ${opencodePath}:`, e.message);
49
+ }
50
+ }
51
+
52
+ // Check Gemini CLI agents (stored as 'gm' directory)
53
+ const geminiPath = path.join(homeDir, '.gemini', 'extensions', 'gm', 'plugin.json');
54
+ if (fs.existsSync(geminiPath)) {
55
+ try {
56
+ const pluginJson = JSON.parse(fs.readFileSync(geminiPath, 'utf-8'));
57
+ if (pluginJson.version) return pluginJson.version;
58
+ } catch (e) {
59
+ console.warn(`[tool-manager] Failed to parse ${geminiPath}:`, e.message);
60
+ }
61
+ }
62
+ // Try gemini-extension.json as fallback
63
+ const geminiExtPath = path.join(homeDir, '.gemini', 'extensions', 'gm', 'gemini-extension.json');
64
+ if (fs.existsSync(geminiExtPath)) {
65
+ try {
66
+ const extJson = JSON.parse(fs.readFileSync(geminiExtPath, 'utf-8'));
67
+ if (extJson.version) return extJson.version;
68
+ } catch (e) {
69
+ console.warn(`[tool-manager] Failed to parse ${geminiExtPath}:`, e.message);
70
+ }
71
+ }
72
+
73
+ // Check Kilo agents
74
+ const kiloPath = path.join(homeDir, '.config', 'kilo', 'agents', pkg, 'plugin.json');
75
+ if (fs.existsSync(kiloPath)) {
76
+ try {
77
+ const pluginJson = JSON.parse(fs.readFileSync(kiloPath, 'utf-8'));
78
+ if (pluginJson.version) return pluginJson.version;
79
+ } catch (e) {
80
+ console.warn(`[tool-manager] Failed to parse ${kiloPath}:`, e.message);
35
81
  }
36
82
  }
37
83
  } catch (_) {}
@@ -119,75 +165,69 @@ const getPublishedVersion = async (pkg) => {
119
165
 
120
166
  const checkToolInstalled = (pkg) => {
121
167
  try {
168
+ const homeDir = os.homedir();
169
+
170
+ // Check Claude Code plugins
171
+ if (fs.existsSync(path.join(homeDir, '.claude', 'plugins', pkg))) {
172
+ return true;
173
+ }
174
+
175
+ // Check OpenCode agents
176
+ if (fs.existsSync(path.join(homeDir, '.config', 'opencode', 'agents', pkg))) {
177
+ return true;
178
+ }
179
+
180
+ // Check Gemini CLI agents (always stored as 'gm' directory)
181
+ if (fs.existsSync(path.join(homeDir, '.gemini', 'extensions', 'gm'))) {
182
+ return true;
183
+ }
184
+
185
+ // Check Kilo agents
186
+ if (fs.existsSync(path.join(homeDir, '.config', 'kilo', 'agents', pkg))) {
187
+ return true;
188
+ }
189
+
190
+ // Check node_modules as fallback
122
191
  const nodeModulesPath = getNodeModulesPath();
123
- const nodeModulesPackagePath = path.join(nodeModulesPath, pkg);
124
- if (fs.existsSync(nodeModulesPackagePath)) {
192
+ if (fs.existsSync(path.join(nodeModulesPath, pkg))) {
125
193
  return true;
126
194
  }
127
- const homeDir = os.homedir();
128
- const pluginPath = path.join(homeDir, '.claude', 'plugins', pkg);
129
- return fs.existsSync(pluginPath);
130
- } catch (_) {
131
- return false;
195
+ } catch (_) {}
196
+ return false;
197
+ };
198
+
199
+ const compareVersions = (v1, v2) => {
200
+ if (!v1 || !v2) return false;
201
+ const parts1 = v1.split('.').map(Number);
202
+ const parts2 = v2.split('.').map(Number);
203
+ for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
204
+ const p1 = parts1[i] || 0;
205
+ const p2 = parts2[i] || 0;
206
+ if (p1 < p2) return true;
207
+ if (p1 > p2) return false;
132
208
  }
209
+ return false;
133
210
  };
134
211
 
135
212
  const checkToolViaBunx = async (pkg) => {
136
213
  try {
137
- const cmd = isWindows ? 'bunx.cmd' : 'bunx';
138
- const checkResult = await new Promise((resolve) => {
139
- const proc = spawn(cmd, [pkg, '--version'], {
140
- stdio: ['pipe', 'pipe', 'pipe'],
141
- timeout: 10000,
142
- shell: isWindows
143
- });
144
- let stdout = '', stderr = '';
145
- proc.stdout.on('data', (d) => { stdout += d.toString(); });
146
- proc.stderr.on('data', (d) => { stderr += d.toString(); });
147
- const timer = setTimeout(() => {
148
- try { proc.kill('SIGKILL'); } catch (_) {}
149
- const installed = checkToolInstalled(pkg);
150
- const installedVersion = getInstalledVersion(pkg);
151
- resolve({ installed, isUpToDate: installed, upgradeNeeded: false, output: 'timeout', installedVersion });
152
- }, 10000);
153
- proc.on('close', (code) => {
154
- clearTimeout(timer);
155
- const output = stdout + stderr;
156
- const installed = code === 0 || checkToolInstalled(pkg);
157
- const upgradeNeeded = output.includes('Upgrading') || output.includes('upgrade');
158
- const isUpToDate = installed && !upgradeNeeded;
159
- const installedVersion = getInstalledVersion(pkg);
160
- resolve({ installed, isUpToDate, upgradeNeeded, output, installedVersion });
161
- });
162
- proc.on('error', () => {
163
- clearTimeout(timer);
164
- const installed = checkToolInstalled(pkg);
165
- const installedVersion = getInstalledVersion(pkg);
166
- resolve({ installed, isUpToDate: false, upgradeNeeded: false, output: '', installedVersion });
167
- });
168
- });
214
+ const installed = checkToolInstalled(pkg);
215
+ const installedVersion = getInstalledVersion(pkg);
216
+ const publishedVersion = await getPublishedVersion(pkg);
169
217
 
170
- let finalInstalledVersion = checkResult.installedVersion;
171
- if (!finalInstalledVersion && checkResult.installed) {
172
- finalInstalledVersion = await getCliToolVersion(pkg);
173
- }
218
+ // Determine if update is needed by comparing versions
219
+ // Do NOT run bunx --version as it triggers installation/upgrade
220
+ const needsUpdate = installed && publishedVersion && compareVersions(installedVersion, publishedVersion);
221
+ const isUpToDate = installed && !needsUpdate;
174
222
 
175
- const publishedVersion = await getPublishedVersion(pkg);
176
- const compareVersions = (v1, v2) => {
177
- if (!v1 || !v2) return false;
178
- const parts1 = v1.split('.').map(Number);
179
- const parts2 = v2.split('.').map(Number);
180
- for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
181
- const p1 = parts1[i] || 0;
182
- const p2 = parts2[i] || 0;
183
- if (p1 < p2) return true;
184
- if (p1 > p2) return false;
185
- }
186
- return false;
223
+ return {
224
+ installed,
225
+ isUpToDate,
226
+ upgradeNeeded: needsUpdate,
227
+ output: 'version-check',
228
+ installedVersion,
229
+ publishedVersion
187
230
  };
188
-
189
- const needsUpdate = checkResult.installed && publishedVersion && compareVersions(finalInstalledVersion, publishedVersion);
190
- return { ...checkResult, installedVersion: finalInstalledVersion, publishedVersion, upgradeNeeded: needsUpdate };
191
231
  } catch (_) {
192
232
  const installedVersion = getInstalledVersion(pkg);
193
233
  return { installed: checkToolInstalled(pkg), isUpToDate: false, upgradeNeeded: false, output: '', installedVersion, publishedVersion: null };
@@ -308,7 +348,7 @@ const spawnBunxProc = (pkg, onProgress) => new Promise((resolve) => {
308
348
  code === 0 && !output.includes('error')
309
349
  ];
310
350
  if (successPatterns.some(p => p)) {
311
- resolve({ success: true, error: null });
351
+ resolve({ success: true, error: null, pkg });
312
352
  } else {
313
353
  resolve({ success: false, error: output.substring(0, 1000) || 'Failed' });
314
354
  }
@@ -331,8 +371,24 @@ export async function install(toolId, onProgress) {
331
371
  installLocks.set(toolId, true);
332
372
  try {
333
373
  const result = await spawnBunxProc(tool.pkg, onProgress);
334
- statusCache.delete(toolId);
335
- versionCache.delete(`published-${tool.pkg}`);
374
+ if (result.success) {
375
+ // Give the filesystem a moment to settle after bunx install
376
+ await new Promise(r => setTimeout(r, 500));
377
+
378
+ // Aggressively clear all version caches to force fresh detection
379
+ statusCache.delete(toolId);
380
+ versionCache.clear();
381
+
382
+ const version = getInstalledVersion(tool.pkg);
383
+ if (!version) {
384
+ console.warn(`[tool-manager] Install succeeded but version detection failed for ${toolId}. Attempting CLI check...`);
385
+ const cliVersion = await getCliToolVersion(tool.pkg);
386
+ const freshStatus = await checkToolStatusAsync(toolId);
387
+ return { success: true, error: null, version: cliVersion || 'unknown', ...freshStatus };
388
+ }
389
+ const freshStatus = await checkToolStatusAsync(toolId);
390
+ return { success: true, error: null, version, ...freshStatus };
391
+ }
336
392
  return result;
337
393
  } finally {
338
394
  installLocks.delete(toolId);
@@ -349,8 +405,24 @@ export async function update(toolId, onProgress) {
349
405
  installLocks.set(toolId, true);
350
406
  try {
351
407
  const result = await spawnBunxProc(tool.pkg, onProgress);
352
- statusCache.delete(toolId);
353
- versionCache.delete(`published-${tool.pkg}`);
408
+ if (result.success) {
409
+ // Give the filesystem a moment to settle after bunx update
410
+ await new Promise(r => setTimeout(r, 500));
411
+
412
+ // Aggressively clear all version caches to force fresh detection
413
+ statusCache.delete(toolId);
414
+ versionCache.clear();
415
+
416
+ const version = getInstalledVersion(tool.pkg);
417
+ if (!version) {
418
+ console.warn(`[tool-manager] Update succeeded but version detection failed for ${toolId}. Attempting CLI check...`);
419
+ const cliVersion = await getCliToolVersion(tool.pkg);
420
+ const freshStatus = await checkToolStatusAsync(toolId);
421
+ return { success: true, error: null, version: cliVersion || 'unknown', ...freshStatus };
422
+ }
423
+ const freshStatus = await checkToolStatusAsync(toolId);
424
+ return { success: true, error: null, version, ...freshStatus };
425
+ }
354
426
  return result;
355
427
  } finally {
356
428
  installLocks.delete(toolId);
@@ -1,8 +1,8 @@
1
1
  import zlib from 'zlib';
2
2
 
3
3
  const MESSAGE_PRIORITY = {
4
- high: ['streaming_error', 'streaming_complete', 'rate_limit_hit', 'streaming_cancelled', 'run_cancelled'],
5
- normal: ['streaming_progress', 'streaming_start', 'message_created', 'queue_status'],
4
+ high: ['streaming_error', 'streaming_complete', 'rate_limit_hit', 'streaming_cancelled', 'run_cancelled', 'tool_install_complete', 'tool_update_complete', 'tool_install_failed', 'tool_update_failed'],
5
+ normal: ['streaming_progress', 'streaming_start', 'message_created', 'queue_status', 'tool_install_progress', 'tool_update_progress'],
6
6
  low: ['model_download_progress', 'stt_progress', 'tts_setup_progress', 'voice_list', 'tts_audio']
7
7
  };
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.509",
3
+ "version": "1.0.511",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -1861,17 +1861,22 @@ const server = http.createServer(async (req, res) => {
1861
1861
  if (wsOptimizer && wsOptimizer.broadcast) {
1862
1862
  wsOptimizer.broadcast({ type: 'tool_install_progress', toolId, data: msg });
1863
1863
  }
1864
- }).then((result) => {
1864
+ }).then(async (result) => {
1865
1865
  clearTimeout(installTimeout);
1866
1866
  if (installCompleted) return;
1867
1867
  installCompleted = true;
1868
1868
  if (result.success) {
1869
- queries.updateToolStatus(toolId, { status: 'installed', version: result.version, installed_at: Date.now() });
1869
+ const version = result.version || null;
1870
+ console.log(`[TOOLS-API] Install succeeded for ${toolId}, version: ${version}`);
1871
+ queries.updateToolStatus(toolId, { status: 'installed', version, installed_at: Date.now() });
1872
+ const freshStatus = await toolManager.checkToolStatusAsync(toolId);
1873
+ console.log(`[TOOLS-API] Fresh status after install for ${toolId}:`, JSON.stringify(freshStatus));
1870
1874
  if (wsOptimizer && wsOptimizer.broadcast) {
1871
- wsOptimizer.broadcast({ type: 'tool_install_complete', toolId, data: result });
1875
+ wsOptimizer.broadcast({ type: 'tool_install_complete', toolId, data: { success: true, ...freshStatus } });
1872
1876
  }
1873
1877
  queries.addToolInstallHistory(toolId, 'install', 'success', null);
1874
1878
  } else {
1879
+ console.error(`[TOOLS-API] Install failed for ${toolId}:`, result.error);
1875
1880
  queries.updateToolStatus(toolId, { status: 'failed', error_message: result.error });
1876
1881
  if (wsOptimizer && wsOptimizer.broadcast) {
1877
1882
  wsOptimizer.broadcast({ type: 'tool_install_failed', toolId, data: result });
@@ -1883,6 +1888,7 @@ const server = http.createServer(async (req, res) => {
1883
1888
  if (installCompleted) return;
1884
1889
  installCompleted = true;
1885
1890
  const error = err?.message || 'Unknown error';
1891
+ console.error(`[TOOLS-API] Install error for ${toolId}:`, error);
1886
1892
  queries.updateToolStatus(toolId, { status: 'failed', error_message: error });
1887
1893
  if (wsOptimizer && wsOptimizer.broadcast) {
1888
1894
  wsOptimizer.broadcast({ type: 'tool_install_failed', toolId, data: { success: false, error } });
@@ -1900,7 +1906,7 @@ const server = http.createServer(async (req, res) => {
1900
1906
  sendJSON(req, res, 404, { error: 'Tool not found' });
1901
1907
  return;
1902
1908
  }
1903
- const current = toolManager.checkToolStatus(toolId);
1909
+ const current = await toolManager.checkToolStatusAsync(toolId);
1904
1910
  if (!current || !current.installed) {
1905
1911
  sendJSON(req, res, 400, { error: 'Tool not installed' });
1906
1912
  return;
@@ -1924,17 +1930,22 @@ const server = http.createServer(async (req, res) => {
1924
1930
  if (wsOptimizer && wsOptimizer.broadcast) {
1925
1931
  wsOptimizer.broadcast({ type: 'tool_update_progress', toolId, data: msg });
1926
1932
  }
1927
- }).then((result) => {
1933
+ }).then(async (result) => {
1928
1934
  clearTimeout(updateTimeout);
1929
1935
  if (updateCompleted) return;
1930
1936
  updateCompleted = true;
1931
1937
  if (result.success) {
1932
- queries.updateToolStatus(toolId, { status: 'installed', version: result.version, installed_at: Date.now() });
1938
+ const version = result.version || null;
1939
+ console.log(`[TOOLS-API] Update succeeded for ${toolId}, version: ${version}`);
1940
+ queries.updateToolStatus(toolId, { status: 'installed', version, installed_at: Date.now() });
1941
+ const freshStatus = await toolManager.checkToolStatusAsync(toolId);
1942
+ console.log(`[TOOLS-API] Fresh status after update for ${toolId}:`, JSON.stringify(freshStatus));
1933
1943
  if (wsOptimizer && wsOptimizer.broadcast) {
1934
- wsOptimizer.broadcast({ type: 'tool_update_complete', toolId, data: result });
1944
+ wsOptimizer.broadcast({ type: 'tool_update_complete', toolId, data: { success: true, ...freshStatus } });
1935
1945
  }
1936
1946
  queries.addToolInstallHistory(toolId, 'update', 'success', null);
1937
1947
  } else {
1948
+ console.error(`[TOOLS-API] Update failed for ${toolId}:`, result.error);
1938
1949
  queries.updateToolStatus(toolId, { status: 'failed', error_message: result.error });
1939
1950
  if (wsOptimizer && wsOptimizer.broadcast) {
1940
1951
  wsOptimizer.broadcast({ type: 'tool_update_failed', toolId, data: result });
@@ -1946,6 +1957,7 @@ const server = http.createServer(async (req, res) => {
1946
1957
  if (updateCompleted) return;
1947
1958
  updateCompleted = true;
1948
1959
  const error = err?.message || 'Unknown error';
1960
+ console.error(`[TOOLS-API] Update error for ${toolId}:`, error);
1949
1961
  queries.updateToolStatus(toolId, { status: 'failed', error_message: error });
1950
1962
  if (wsOptimizer && wsOptimizer.broadcast) {
1951
1963
  wsOptimizer.broadcast({ type: 'tool_update_failed', toolId, data: { success: false, error } });
@@ -1965,6 +1977,81 @@ const server = http.createServer(async (req, res) => {
1965
1977
  return;
1966
1978
  }
1967
1979
 
1980
+
1981
+ // Handle POST /api/tools/{toolId}/install - individual tool install
1982
+ const installMatch = pathOnly.match(/^\/api\/tools\/([^\/]+)\/install$/);
1983
+ if (installMatch && req.method === 'POST') {
1984
+ const toolId = installMatch[1];
1985
+ sendJSON(req, res, 200, { installing: true, toolId });
1986
+ setImmediate(async () => {
1987
+ try {
1988
+ const result = await toolManager.install(toolId, (msg) => {
1989
+ if (wsOptimizer && wsOptimizer.broadcast) {
1990
+ wsOptimizer.broadcast({ type: 'tool_install_progress', toolId, data: msg });
1991
+ }
1992
+ });
1993
+ if (result.success) {
1994
+ queries.updateToolStatus(toolId, { status: 'installed', installed_at: Date.now() });
1995
+ queries.addToolInstallHistory(toolId, 'install', 'success', null);
1996
+ const freshStatus = await toolManager.checkToolStatusAsync(toolId);
1997
+ if (wsOptimizer && wsOptimizer.broadcast) {
1998
+ wsOptimizer.broadcast({ type: 'tool_install_complete', toolId, data: { ...result, ...freshStatus } });
1999
+ }
2000
+ } else {
2001
+ queries.updateToolStatus(toolId, { status: 'failed', error_message: result.error });
2002
+ queries.addToolInstallHistory(toolId, 'install', 'failed', result.error);
2003
+ if (wsOptimizer && wsOptimizer.broadcast) {
2004
+ wsOptimizer.broadcast({ type: 'tool_install_failed', toolId, data: result });
2005
+ }
2006
+ }
2007
+ } catch (err) {
2008
+ queries.updateToolStatus(toolId, { status: 'failed', error_message: err.message });
2009
+ queries.addToolInstallHistory(toolId, 'install', 'failed', err.message);
2010
+ if (wsOptimizer && wsOptimizer.broadcast) {
2011
+ wsOptimizer.broadcast({ type: 'tool_install_failed', toolId, data: { success: false, error: err.message } });
2012
+ }
2013
+ }
2014
+ });
2015
+ return;
2016
+ }
2017
+
2018
+ // Handle POST /api/tools/{toolId}/update - individual tool update
2019
+ const updateMatch = pathOnly.match(/^\/api\/tools\/([^\/]+)\/update$/);
2020
+ if (updateMatch && req.method === 'POST') {
2021
+ const toolId = updateMatch[1];
2022
+ sendJSON(req, res, 200, { updating: true, toolId });
2023
+ setImmediate(async () => {
2024
+ try {
2025
+ const result = await toolManager.update(toolId, (msg) => {
2026
+ if (wsOptimizer && wsOptimizer.broadcast) {
2027
+ wsOptimizer.broadcast({ type: 'tool_update_progress', toolId, data: msg });
2028
+ }
2029
+ });
2030
+ if (result.success) {
2031
+ queries.updateToolStatus(toolId, { status: 'installed', installed_at: Date.now() });
2032
+ queries.addToolInstallHistory(toolId, 'update', 'success', null);
2033
+ const freshStatus = await toolManager.checkToolStatusAsync(toolId);
2034
+ if (wsOptimizer && wsOptimizer.broadcast) {
2035
+ wsOptimizer.broadcast({ type: 'tool_update_complete', toolId, data: { ...result, ...freshStatus } });
2036
+ }
2037
+ } else {
2038
+ queries.updateToolStatus(toolId, { status: 'failed', error_message: result.error });
2039
+ queries.addToolInstallHistory(toolId, 'update', 'failed', result.error);
2040
+ if (wsOptimizer && wsOptimizer.broadcast) {
2041
+ wsOptimizer.broadcast({ type: 'tool_update_failed', toolId, data: result });
2042
+ }
2043
+ }
2044
+ } catch (err) {
2045
+ queries.updateToolStatus(toolId, { status: 'failed', error_message: err.message });
2046
+ queries.addToolInstallHistory(toolId, 'update', 'failed', err.message);
2047
+ if (wsOptimizer && wsOptimizer.broadcast) {
2048
+ wsOptimizer.broadcast({ type: 'tool_update_failed', toolId, data: { success: false, error: err.message } });
2049
+ }
2050
+ }
2051
+ });
2052
+ return;
2053
+ }
2054
+
1968
2055
  if (pathOnly === '/api/tools/update' && req.method === 'POST') {
1969
2056
  sendJSON(req, res, 200, { updating: true, toolCount: 4 });
1970
2057
  if (wsOptimizer && wsOptimizer.broadcast) {
@@ -4085,7 +4172,10 @@ const BROADCAST_TYPES = new Set([
4085
4172
  'rate_limit_hit', 'rate_limit_clear',
4086
4173
  'script_started', 'script_stopped', 'script_output',
4087
4174
  'model_download_progress', 'stt_progress', 'tts_setup_progress', 'voice_list',
4088
- 'streaming_start', 'streaming_progress', 'streaming_complete', 'streaming_error'
4175
+ 'streaming_start', 'streaming_progress', 'streaming_complete', 'streaming_error',
4176
+ 'tool_install_started', 'tool_install_progress', 'tool_install_complete', 'tool_install_failed',
4177
+ 'tool_update_progress', 'tool_update_complete', 'tool_update_failed',
4178
+ 'tools_update_started', 'tools_update_complete', 'tools_refresh_complete'
4089
4179
  ]);
4090
4180
 
4091
4181
  const wsOptimizer = new WSOptimizer();
@@ -175,6 +175,7 @@
175
175
  tool.hasUpdate = (data.data?.upgradeNeeded && data.data?.installed) ?? false;
176
176
  tool.progress = 100;
177
177
  operationInProgress.delete(data.toolId);
178
+ render();
178
179
  setTimeout(fetchTools, 1000);
179
180
  }
180
181
  } else if (data.type === 'tool_install_failed' || data.type === 'tool_update_failed') {
@@ -0,0 +1,101 @@
1
+ import http from 'http';
2
+
3
+ const BASE_URL = 'http://localhost:3000/gm';
4
+
5
+ async function httpGet(path) {
6
+ return new Promise((resolve, reject) => {
7
+ const url = new URL(path, BASE_URL);
8
+ http.get(url, (res) => {
9
+ let data = '';
10
+ res.on('data', chunk => data += chunk);
11
+ res.on('end', () => {
12
+ try {
13
+ resolve({ status: res.statusCode, data: JSON.parse(data) });
14
+ } catch {
15
+ resolve({ status: res.statusCode, data });
16
+ }
17
+ });
18
+ }).on('error', reject);
19
+ });
20
+ }
21
+
22
+ async function httpPost(path, body) {
23
+ return new Promise((resolve, reject) => {
24
+ const url = new URL(path, BASE_URL);
25
+ const bodyStr = JSON.stringify(body);
26
+ const options = {
27
+ method: 'POST',
28
+ headers: { 'Content-Type': 'application/json', 'Content-Length': bodyStr.length }
29
+ };
30
+ const req = http.request(url, options, (res) => {
31
+ let data = '';
32
+ res.on('data', chunk => data += chunk);
33
+ res.on('end', () => {
34
+ try {
35
+ resolve({ status: res.statusCode, data: JSON.parse(data) });
36
+ } catch {
37
+ resolve({ status: res.statusCode, data });
38
+ }
39
+ });
40
+ }).on('error', reject);
41
+ req.write(bodyStr);
42
+ req.end();
43
+ });
44
+ }
45
+
46
+ async function runTests() {
47
+ console.log('=== HTTP API TESTS ===\n');
48
+
49
+ try {
50
+ console.log('TEST 1: GET /api/tools');
51
+ const tools = await httpGet('/api/tools');
52
+ console.log('Status:', tools.status);
53
+ console.log('Tools:', tools.data?.tools?.length || 0);
54
+ if (tools.data?.tools) {
55
+ tools.data.tools.forEach(t => {
56
+ console.log(` ${t.id}: status=${t.status}, installed=${t.installed}, hasUpdate=${t.hasUpdate}`);
57
+ console.log(` versions: installed=${t.installedVersion}, published=${t.publishedVersion}`);
58
+ });
59
+ }
60
+ console.log('');
61
+
62
+ if (tools.data?.tools?.length > 0) {
63
+ const firstTool = tools.data.tools[0];
64
+
65
+ console.log(`TEST 2: GET /api/tools/${firstTool.id}/status`);
66
+ const status = await httpGet(`/api/tools/${firstTool.id}/status`);
67
+ console.log('Status code:', status.status);
68
+ console.log('Status data:', JSON.stringify(status.data, null, 2));
69
+ console.log('');
70
+
71
+ if (firstTool.installed && firstTool.hasUpdate) {
72
+ console.log(`TEST 3: POST /api/tools/${firstTool.id}/update (DRY RUN - not actually posting)`);
73
+ console.log(`Would update: ${firstTool.id}`);
74
+ console.log(`Current version: ${firstTool.installedVersion}`);
75
+ console.log(`Available version: ${firstTool.publishedVersion}`);
76
+ console.log('');
77
+
78
+ console.log('FLOW WOULD BE:');
79
+ console.log(' 1. Frontend sends POST /api/tools/{id}/update');
80
+ console.log(' 2. Backend sets status to "updating" in DB');
81
+ console.log(' 3. Backend sends immediate 200 response');
82
+ console.log(' 4. Backend spawns bunx process async');
83
+ console.log(' 5. Backend broadcasts WebSocket "tool_update_progress" events');
84
+ console.log(' 6. When bunx completes:');
85
+ console.log(' - Clears caches');
86
+ console.log(' - Calls checkToolStatusAsync() for fresh status');
87
+ console.log(' - Broadcasts "tool_update_complete" with new status');
88
+ console.log(' - Updates DB with new version');
89
+ console.log(' 7. Frontend receives event and updates UI');
90
+ }
91
+ }
92
+
93
+ console.log('\n=== TESTS COMPLETED ===');
94
+ process.exit(0);
95
+ } catch (err) {
96
+ console.error('ERROR:', err.message);
97
+ process.exit(1);
98
+ }
99
+ }
100
+
101
+ runTests();