agentgui 1.0.347 → 1.0.349
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 +62 -2
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -62,6 +62,35 @@ function broadcastModelProgress(progress) {
|
|
|
62
62
|
broadcastSync(broadcastData);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
async function validateAndCleanupModels(modelsDir) {
|
|
66
|
+
try {
|
|
67
|
+
const manifestPath = path.join(modelsDir, '.manifests.json');
|
|
68
|
+
if (fs.existsSync(manifestPath)) {
|
|
69
|
+
try {
|
|
70
|
+
const content = fs.readFileSync(manifestPath, 'utf8');
|
|
71
|
+
JSON.parse(content);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error('[MODELS] Manifest corrupted, removing:', e.message);
|
|
74
|
+
fs.unlinkSync(manifestPath);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const files = fs.readdirSync(modelsDir);
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
if (file.endsWith('.tmp')) {
|
|
81
|
+
try {
|
|
82
|
+
fs.unlinkSync(path.join(modelsDir, file));
|
|
83
|
+
console.log('[MODELS] Cleaned up temp file:', file);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.warn('[MODELS] Failed to clean:', file);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.warn('[MODELS] Cleanup check failed:', e.message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
65
94
|
async function ensureModelsDownloaded() {
|
|
66
95
|
if (modelDownloadState.downloading) {
|
|
67
96
|
while (modelDownloadState.downloading) {
|
|
@@ -83,6 +112,8 @@ async function ensureModelsDownloaded() {
|
|
|
83
112
|
? (fs.existsSync(path.join(process.env.PORTABLE_EXE_DIR, 'models', 'onnx-community')) ? path.join(process.env.PORTABLE_EXE_DIR, 'models') : gmguiModels)
|
|
84
113
|
: gmguiModels;
|
|
85
114
|
|
|
115
|
+
await validateAndCleanupModels(modelsBase);
|
|
116
|
+
|
|
86
117
|
const config = createConfig({
|
|
87
118
|
modelsDir: modelsBase,
|
|
88
119
|
ttsModelsDir: path.join(modelsBase, 'tts'),
|
|
@@ -323,16 +354,31 @@ function extractModelsFromClaudeCLI() {
|
|
|
323
354
|
let m;
|
|
324
355
|
while ((m = re.exec(src)) !== null) ids.add(m[1]);
|
|
325
356
|
if (ids.size === 0) return null;
|
|
357
|
+
|
|
326
358
|
const models = [{ id: '', label: 'Default' }];
|
|
327
359
|
const sorted = [...ids].sort((a, b) => {
|
|
328
360
|
const va = a.replace(/claude-/, '').replace(/-\d{8}$/, '');
|
|
329
361
|
const vb = b.replace(/claude-/, '').replace(/-\d{8}$/, '');
|
|
330
362
|
return vb.localeCompare(va);
|
|
331
363
|
});
|
|
364
|
+
|
|
365
|
+
const latest = { haiku: null, sonnet: null, opus: null };
|
|
366
|
+
for (const id of sorted) {
|
|
367
|
+
if (id.startsWith('claude-3-')) continue;
|
|
368
|
+
if (id.includes('haiku') && !latest.haiku) latest.haiku = id;
|
|
369
|
+
if (id.includes('sonnet') && !latest.sonnet) latest.sonnet = id;
|
|
370
|
+
if (id.includes('opus') && !latest.opus) latest.opus = id;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (latest.opus) models.push({ id: latest.opus, label: 'Opus (Latest)' });
|
|
374
|
+
if (latest.sonnet) models.push({ id: latest.sonnet, label: 'Sonnet (Latest)' });
|
|
375
|
+
if (latest.haiku) models.push({ id: latest.haiku, label: 'Haiku (Latest)' });
|
|
376
|
+
|
|
332
377
|
for (const id of sorted) {
|
|
333
378
|
if (id.startsWith('claude-3-')) continue;
|
|
334
379
|
models.push({ id, label: modelIdToLabel(id) });
|
|
335
380
|
}
|
|
381
|
+
|
|
336
382
|
return models;
|
|
337
383
|
} catch { return null; }
|
|
338
384
|
}
|
|
@@ -2434,8 +2480,22 @@ const server = http.createServer(async (req, res) => {
|
|
|
2434
2480
|
sendJSON(req, res, 200, { text: finalText });
|
|
2435
2481
|
} catch (err) {
|
|
2436
2482
|
debugLog('[STT] Error: ' + err.message);
|
|
2437
|
-
|
|
2438
|
-
if (
|
|
2483
|
+
let errorMsg = err.message || 'STT failed';
|
|
2484
|
+
if (errorMsg.includes('VERS_1.21') || errorMsg.includes('onnxruntime')) {
|
|
2485
|
+
errorMsg = 'STT model load failed: onnxruntime version mismatch. Try: npm install or npm ci';
|
|
2486
|
+
} else if (errorMsg.includes('not valid JSON') || errorMsg.includes('Unexpected token')) {
|
|
2487
|
+
errorMsg = 'STT model load failed: corrupted cache. Clearing... try again.';
|
|
2488
|
+
const modelsDir = path.join(os.homedir(), '.gmgui', 'models');
|
|
2489
|
+
try {
|
|
2490
|
+
const manifestPath = path.join(modelsDir, '.manifests.json');
|
|
2491
|
+
if (fs.existsSync(manifestPath)) fs.unlinkSync(manifestPath);
|
|
2492
|
+
console.log('[STT] Cleared corrupted manifest');
|
|
2493
|
+
} catch (e) {
|
|
2494
|
+
console.warn('[STT] Failed to clear manifest:', e.message);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
broadcastSync({ type: 'stt_progress', status: 'failed', percentComplete: 0, error: errorMsg });
|
|
2498
|
+
if (!res.headersSent) sendJSON(req, res, 500, { error: errorMsg });
|
|
2439
2499
|
}
|
|
2440
2500
|
return;
|
|
2441
2501
|
}
|