agentgui 1.0.308 → 1.0.309
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 +49 -46
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -319,30 +319,11 @@ const modelCache = new Map();
|
|
|
319
319
|
|
|
320
320
|
const AGENT_MODEL_COMMANDS = {
|
|
321
321
|
'claude-code': 'claude models',
|
|
322
|
+
'gemini': 'gemini models',
|
|
322
323
|
'opencode': 'opencode models',
|
|
323
324
|
'kilo': 'kilo models',
|
|
324
325
|
};
|
|
325
326
|
|
|
326
|
-
const AGENT_DEFAULT_MODELS = {
|
|
327
|
-
'gemini': [
|
|
328
|
-
{ id: '', label: 'Default' },
|
|
329
|
-
{ id: 'gemini-2.5-pro', label: 'Gemini 2.5 Pro' },
|
|
330
|
-
{ id: 'gemini-2.5-flash', label: 'Gemini 2.5 Flash' },
|
|
331
|
-
{ id: 'gemini-2.0-flash', label: 'Gemini 2.0 Flash' }
|
|
332
|
-
],
|
|
333
|
-
'goose': [
|
|
334
|
-
{ id: '', label: 'Default' },
|
|
335
|
-
{ id: 'claude-sonnet-4-5', label: 'Sonnet 4.5' },
|
|
336
|
-
{ id: 'claude-opus-4-5', label: 'Opus 4.5' }
|
|
337
|
-
],
|
|
338
|
-
'codex': [
|
|
339
|
-
{ id: '', label: 'Default' },
|
|
340
|
-
{ id: 'o4-mini', label: 'o4-mini' },
|
|
341
|
-
{ id: 'o3', label: 'o3' },
|
|
342
|
-
{ id: 'o3-mini', label: 'o3-mini' }
|
|
343
|
-
]
|
|
344
|
-
};
|
|
345
|
-
|
|
346
327
|
async function fetchClaudeModelsFromAPI() {
|
|
347
328
|
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
348
329
|
if (!apiKey) return null;
|
|
@@ -377,31 +358,59 @@ async function fetchClaudeModelsFromAPI() {
|
|
|
377
358
|
} catch { return null; }
|
|
378
359
|
}
|
|
379
360
|
|
|
361
|
+
async function fetchGeminiModelsFromAPI() {
|
|
362
|
+
const apiKey = process.env.GOOGLE_GENAI_API_KEY;
|
|
363
|
+
if (!apiKey) return null;
|
|
364
|
+
try {
|
|
365
|
+
const https = await import('https');
|
|
366
|
+
return new Promise((resolve) => {
|
|
367
|
+
const req = https.default.request({
|
|
368
|
+
hostname: 'generativelanguage.googleapis.com',
|
|
369
|
+
path: '/v1beta/models?key=' + apiKey,
|
|
370
|
+
method: 'GET',
|
|
371
|
+
timeout: 8000
|
|
372
|
+
}, (res) => {
|
|
373
|
+
let body = '';
|
|
374
|
+
res.on('data', d => body += d);
|
|
375
|
+
res.on('end', () => {
|
|
376
|
+
try {
|
|
377
|
+
const data = JSON.parse(body);
|
|
378
|
+
const items = (data.models || []).filter(m => m.name && m.name.includes('gemini'));
|
|
379
|
+
if (items.length === 0) return resolve(null);
|
|
380
|
+
const models = [{ id: '', label: 'Default' }];
|
|
381
|
+
for (const m of items) {
|
|
382
|
+
const modelId = m.name.replace(/^models\//, '');
|
|
383
|
+
const label = modelId.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
384
|
+
models.push({ id: modelId, label });
|
|
385
|
+
}
|
|
386
|
+
resolve(models);
|
|
387
|
+
} catch { resolve(null); }
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
req.on('error', () => resolve(null));
|
|
391
|
+
req.on('timeout', () => { req.destroy(); resolve(null); });
|
|
392
|
+
req.end();
|
|
393
|
+
});
|
|
394
|
+
} catch { return null; }
|
|
395
|
+
}
|
|
396
|
+
|
|
380
397
|
async function getModelsForAgent(agentId) {
|
|
381
398
|
const cached = modelCache.get(agentId);
|
|
382
399
|
if (cached && Date.now() - cached.timestamp < 3600000) {
|
|
383
400
|
return cached.models;
|
|
384
401
|
}
|
|
385
402
|
|
|
403
|
+
let models = null;
|
|
404
|
+
|
|
386
405
|
if (agentId === 'claude-code') {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (lines.length > 0) {
|
|
396
|
-
const models = [{ id: '', label: 'Default' }];
|
|
397
|
-
for (const line of lines) {
|
|
398
|
-
models.push({ id: line, label: line });
|
|
399
|
-
}
|
|
400
|
-
modelCache.set(agentId, { models, timestamp: Date.now() });
|
|
401
|
-
return models;
|
|
402
|
-
}
|
|
403
|
-
} catch (_) {}
|
|
404
|
-
return [{ id: '', label: 'Default' }];
|
|
406
|
+
models = await fetchClaudeModelsFromAPI();
|
|
407
|
+
} else if (agentId === 'gemini') {
|
|
408
|
+
models = await fetchGeminiModelsFromAPI();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (models) {
|
|
412
|
+
modelCache.set(agentId, { models, timestamp: Date.now() });
|
|
413
|
+
return models;
|
|
405
414
|
}
|
|
406
415
|
|
|
407
416
|
if (AGENT_MODEL_COMMANDS[agentId]) {
|
|
@@ -409,7 +418,7 @@ async function getModelsForAgent(agentId) {
|
|
|
409
418
|
const result = execSync(AGENT_MODEL_COMMANDS[agentId], { encoding: 'utf-8', timeout: 15000 });
|
|
410
419
|
const lines = result.split('\n').map(l => l.trim()).filter(Boolean);
|
|
411
420
|
if (lines.length > 0) {
|
|
412
|
-
|
|
421
|
+
models = [{ id: '', label: 'Default' }];
|
|
413
422
|
for (const line of lines) {
|
|
414
423
|
models.push({ id: line, label: line });
|
|
415
424
|
}
|
|
@@ -419,12 +428,6 @@ async function getModelsForAgent(agentId) {
|
|
|
419
428
|
} catch (_) {}
|
|
420
429
|
}
|
|
421
430
|
|
|
422
|
-
if (AGENT_DEFAULT_MODELS[agentId]) {
|
|
423
|
-
const models = AGENT_DEFAULT_MODELS[agentId];
|
|
424
|
-
modelCache.set(agentId, { models, timestamp: Date.now() });
|
|
425
|
-
return models;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
431
|
const { getRegisteredAgents } = await import('./lib/claude-runner.js');
|
|
429
432
|
const agents = getRegisteredAgents();
|
|
430
433
|
const agent = agents.find(a => a.id === agentId);
|
|
@@ -435,7 +438,7 @@ async function getModelsForAgent(agentId) {
|
|
|
435
438
|
const result = execSync(modelCmd, { encoding: 'utf-8', timeout: 15000 });
|
|
436
439
|
const lines = result.split('\n').map(l => l.trim()).filter(Boolean);
|
|
437
440
|
if (lines.length > 0) {
|
|
438
|
-
|
|
441
|
+
models = [{ id: '', label: 'Default' }];
|
|
439
442
|
for (const line of lines) {
|
|
440
443
|
models.push({ id: line, label: line });
|
|
441
444
|
}
|