agentgui 1.0.435 → 1.0.436
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/lib/ws-handlers-session.js +73 -2
- package/package.json +1 -1
- package/server.js +40 -2
|
@@ -60,14 +60,80 @@ function checkAgentAuth(agent) {
|
|
|
60
60
|
return s;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
async function acpFetch(port,
|
|
63
|
+
async function acpFetch(port, pth, body = null) {
|
|
64
64
|
const opts = { headers: { 'Content-Type': 'application/json' }, signal: AbortSignal.timeout(3000) };
|
|
65
65
|
if (body !== null) { opts.method = 'POST'; opts.body = JSON.stringify(body); }
|
|
66
|
-
const res = await fetch(`http://localhost:${port}${
|
|
66
|
+
const res = await fetch(`http://localhost:${port}${pth}`, opts);
|
|
67
67
|
if (!res.ok) return null;
|
|
68
68
|
return res.json();
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
function getApiKey(name) {
|
|
72
|
+
const envMap = {
|
|
73
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
74
|
+
google: 'GOOGLE_GENAI_API_KEY',
|
|
75
|
+
openai: 'OPENAI_API_KEY'
|
|
76
|
+
};
|
|
77
|
+
if (process.env[envMap[name]]) return process.env[envMap[name]];
|
|
78
|
+
const configPaths = {
|
|
79
|
+
anthropic: [
|
|
80
|
+
path.join(os.homedir(), '.claude.json'),
|
|
81
|
+
path.join(os.homedir(), '.anthropic.json')
|
|
82
|
+
],
|
|
83
|
+
google: [
|
|
84
|
+
path.join(os.homedir(), '.gemini.json'),
|
|
85
|
+
path.join(os.homedir(), '.config', 'gemini', 'credentials.json')
|
|
86
|
+
],
|
|
87
|
+
openai: [
|
|
88
|
+
path.join(os.homedir(), '.openai.json')
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
for (const p of (configPaths[name] || [])) {
|
|
92
|
+
const data = readJson(p);
|
|
93
|
+
if (data) {
|
|
94
|
+
const key = data.api_key || data.apiKey || data.github_token;
|
|
95
|
+
if (key) return key;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function fetchModelsFromAPI(agentId) {
|
|
102
|
+
if (agentId === 'claude-code') {
|
|
103
|
+
const apiKey = getApiKey('anthropic');
|
|
104
|
+
if (!apiKey) return null;
|
|
105
|
+
try {
|
|
106
|
+
const res = await fetch('https://api.anthropic.com/v1/models', {
|
|
107
|
+
headers: { 'x-api-key': apiKey, 'anthropic-version': '2023-06-01' },
|
|
108
|
+
signal: AbortSignal.timeout(8000)
|
|
109
|
+
});
|
|
110
|
+
if (!res.ok) return null;
|
|
111
|
+
const data = await res.json();
|
|
112
|
+
const items = (data.data || []).filter(m => m.id && m.id.startsWith('claude-'));
|
|
113
|
+
if (items.length === 0) return null;
|
|
114
|
+
return items.map(m => ({ id: m.id, label: m.display_name || m.id.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) }));
|
|
115
|
+
} catch { return null; }
|
|
116
|
+
}
|
|
117
|
+
if (agentId === 'gemini') {
|
|
118
|
+
const apiKey = getApiKey('google');
|
|
119
|
+
if (!apiKey) return null;
|
|
120
|
+
try {
|
|
121
|
+
const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`, {
|
|
122
|
+
signal: AbortSignal.timeout(8000)
|
|
123
|
+
});
|
|
124
|
+
if (!res.ok) return null;
|
|
125
|
+
const data = await res.json();
|
|
126
|
+
const items = (data.models || []).filter(m => m.name && m.name.includes('gemini'));
|
|
127
|
+
if (items.length === 0) return null;
|
|
128
|
+
return items.map(m => {
|
|
129
|
+
const id = m.name.replace(/^models\//, '');
|
|
130
|
+
return { id, label: id.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) };
|
|
131
|
+
});
|
|
132
|
+
} catch { return null; }
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
71
137
|
export function register(router, deps) {
|
|
72
138
|
const { db, discoveredAgents, modelCache,
|
|
73
139
|
getAgentDescriptor, activeScripts, broadcastSync, startGeminiOAuth,
|
|
@@ -184,6 +250,11 @@ export function register(router, deps) {
|
|
|
184
250
|
}
|
|
185
251
|
} catch (_) {}
|
|
186
252
|
}
|
|
253
|
+
const apiModels = await fetchModelsFromAPI(p.id);
|
|
254
|
+
if (apiModels && apiModels.length > 0) {
|
|
255
|
+
modelCache.set(p.id, { models: apiModels, ts: Date.now() });
|
|
256
|
+
return { models: apiModels };
|
|
257
|
+
}
|
|
187
258
|
return { models: [] };
|
|
188
259
|
});
|
|
189
260
|
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -442,8 +442,46 @@ function modelIdToLabel(id) {
|
|
|
442
442
|
return base.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
443
443
|
}
|
|
444
444
|
|
|
445
|
-
async function getModelsForAgent() {
|
|
446
|
-
|
|
445
|
+
async function getModelsForAgent(agentId) {
|
|
446
|
+
const cached = modelCache.get(agentId);
|
|
447
|
+
if (cached && Date.now() - cached.timestamp < 3600000) return cached.models;
|
|
448
|
+
let models = null;
|
|
449
|
+
if (agentId === 'claude-code') {
|
|
450
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
451
|
+
if (apiKey) {
|
|
452
|
+
try {
|
|
453
|
+
const res = await fetch('https://api.anthropic.com/v1/models', {
|
|
454
|
+
headers: { 'x-api-key': apiKey, 'anthropic-version': '2023-06-01' },
|
|
455
|
+
signal: AbortSignal.timeout(8000)
|
|
456
|
+
});
|
|
457
|
+
if (res.ok) {
|
|
458
|
+
const data = await res.json();
|
|
459
|
+
const items = (data.data || []).filter(m => m.id && m.id.startsWith('claude-'));
|
|
460
|
+
if (items.length > 0) models = items.map(m => ({ id: m.id, label: m.display_name || modelIdToLabel(m.id) }));
|
|
461
|
+
}
|
|
462
|
+
} catch (_) {}
|
|
463
|
+
}
|
|
464
|
+
} else if (agentId === 'gemini') {
|
|
465
|
+
const apiKey = process.env.GOOGLE_GENAI_API_KEY;
|
|
466
|
+
if (apiKey) {
|
|
467
|
+
try {
|
|
468
|
+
const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`, {
|
|
469
|
+
signal: AbortSignal.timeout(8000)
|
|
470
|
+
});
|
|
471
|
+
if (res.ok) {
|
|
472
|
+
const data = await res.json();
|
|
473
|
+
const items = (data.models || []).filter(m => m.name && m.name.includes('gemini'));
|
|
474
|
+
if (items.length > 0) models = items.map(m => {
|
|
475
|
+
const id = m.name.replace(/^models\//, '');
|
|
476
|
+
return { id, label: id.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) };
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
} catch (_) {}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const result = models || [];
|
|
483
|
+
modelCache.set(agentId, { models: result, timestamp: Date.now() });
|
|
484
|
+
return result;
|
|
447
485
|
}
|
|
448
486
|
|
|
449
487
|
const GEMINI_SCOPES = [
|