agentgui 1.0.435 → 1.0.437
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 +26 -60
- package/package.json +1 -1
- package/server.js +32 -22
|
@@ -60,14 +60,15 @@ 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
|
+
|
|
71
72
|
export function register(router, deps) {
|
|
72
73
|
const { db, discoveredAgents, modelCache,
|
|
73
74
|
getAgentDescriptor, activeScripts, broadcastSync, startGeminiOAuth,
|
|
@@ -128,64 +129,29 @@ export function register(router, deps) {
|
|
|
128
129
|
return d;
|
|
129
130
|
});
|
|
130
131
|
|
|
131
|
-
router.handle('agent.models', async (p) => {
|
|
132
|
-
const cached = modelCache.get(p.id);
|
|
133
|
-
if (cached && (Date.now() - cached.ts) < 300000) return { models: cached.models };
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const id = m.id || m;
|
|
155
|
-
if (id) allModels.set(id, m.name || m.label || id);
|
|
156
|
-
}
|
|
157
|
-
try {
|
|
158
|
-
const desc = await acpFetch(port, `/agents/${agentId}/descriptor`);
|
|
159
|
-
const enumVals = desc?.specs?.config?.properties?.model?.enum || desc?.specs?.input?.properties?.model?.enum || [];
|
|
160
|
-
for (const v of enumVals) allModels.set(v, v);
|
|
161
|
-
} catch (_) {}
|
|
162
|
-
}
|
|
163
|
-
if (allModels.size > 0) {
|
|
164
|
-
const models = Array.from(allModels.entries()).map(([id, label]) => ({ id, label }));
|
|
165
|
-
modelCache.set(p.id, { models, ts: Date.now() });
|
|
166
|
-
return { models };
|
|
167
|
-
}
|
|
168
|
-
} catch (_) {}
|
|
169
|
-
}
|
|
170
|
-
const acpAgents = discoveredAgents.filter(x => x.protocol === 'acp' && x.acpPort);
|
|
171
|
-
for (const acpAgent of acpAgents) {
|
|
172
|
-
const port = acpAgent.acpPort;
|
|
173
|
-
try {
|
|
174
|
-
const desc = await acpFetch(port, `/agents/${p.id}/descriptor`);
|
|
175
|
-
if (desc) {
|
|
176
|
-
const enumVals = desc?.specs?.config?.properties?.model?.enum || desc?.specs?.input?.properties?.model?.enum || [];
|
|
177
|
-
if (enumVals.length > 0) {
|
|
178
|
-
const models = enumVals.map(v => ({ id: v, label: v }));
|
|
179
|
-
modelCache.set(p.id, { models, ts: Date.now() });
|
|
180
|
-
return { models };
|
|
181
|
-
}
|
|
182
|
-
const name = desc?.metadata?.ref?.name;
|
|
183
|
-
if (name) { const models = [{ id: p.id, label: name }]; modelCache.set(p.id, { models, ts: Date.now() }); return { models }; }
|
|
184
|
-
}
|
|
185
|
-
} catch (_) {}
|
|
186
|
-
}
|
|
187
|
-
return { models: [] };
|
|
188
|
-
});
|
|
132
|
+
router.handle('agent.models', async (p) => {
|
|
133
|
+
const cached = modelCache.get(p.id);
|
|
134
|
+
if (cached && (Date.now() - cached.ts) < 300000) return { models: cached.models };
|
|
135
|
+
let models = [];
|
|
136
|
+
if (p.id === 'claude-code') {
|
|
137
|
+
models = [
|
|
138
|
+
{ id: 'claude-haiku', label: 'Haiku' },
|
|
139
|
+
{ id: 'claude-sonnet', label: 'Sonnet' },
|
|
140
|
+
{ id: 'claude-opus', label: 'Opus' }
|
|
141
|
+
];
|
|
142
|
+
} else {
|
|
143
|
+
const agent = discoveredAgents.find(x => x.id === p.id);
|
|
144
|
+
if (agent?.protocol === 'acp' && agent.acpPort) {
|
|
145
|
+
try {
|
|
146
|
+
const data = await acpFetch(agent.acpPort, '/models');
|
|
147
|
+
const list = data?.data || data?.models || (Array.isArray(data) ? data : []);
|
|
148
|
+
models = list.map(m => ({ id: m.id || m.model_id, label: m.name || m.display_name || m.id || m.model_id })).filter(m => m.id);
|
|
149
|
+
} catch (_) {}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (models.length > 0) modelCache.set(p.id, { models, ts: Date.now() });
|
|
153
|
+
return { models };
|
|
154
|
+
});
|
|
189
155
|
|
|
190
156
|
router.handle('agent.search', (p) => db.searchAgents(discoveredAgents, p.query || p));
|
|
191
157
|
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -411,22 +411,13 @@ function discoverAgents() {
|
|
|
411
411
|
|
|
412
412
|
// Function to discover agents from external ACP servers
|
|
413
413
|
async function discoverExternalACPServers() {
|
|
414
|
-
// Default ACP servers to query (excluding local server to prevent recursion)
|
|
415
|
-
const acpServers = [
|
|
416
|
-
'http://localhost:8080', // Common default ACP port
|
|
417
|
-
];
|
|
418
|
-
|
|
419
414
|
const externalAgents = [];
|
|
420
|
-
for (const
|
|
415
|
+
for (const agent of discoveredAgents.filter(a => a.protocol === 'acp' && a.acpPort)) {
|
|
421
416
|
try {
|
|
422
|
-
|
|
423
|
-
const agents = await queryACPServerAgents(serverUrl);
|
|
417
|
+
const agents = await queryACPServerAgents(`http://localhost:${agent.acpPort}`);
|
|
424
418
|
externalAgents.push(...agents);
|
|
425
|
-
} catch (
|
|
426
|
-
console.error(`Failed to query ${serverUrl}:`, error.message);
|
|
427
|
-
}
|
|
419
|
+
} catch (_) {}
|
|
428
420
|
}
|
|
429
|
-
|
|
430
421
|
return externalAgents;
|
|
431
422
|
}
|
|
432
423
|
|
|
@@ -435,15 +426,34 @@ initializeDescriptors(discoveredAgents);
|
|
|
435
426
|
|
|
436
427
|
const modelCache = new Map();
|
|
437
428
|
|
|
438
|
-
function
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
429
|
+
async function getModelsForAgent(agentId) {
|
|
430
|
+
const cached = modelCache.get(agentId);
|
|
431
|
+
if (cached && Date.now() - cached.timestamp < 300000) return cached.models;
|
|
432
|
+
let models = [];
|
|
433
|
+
if (agentId === 'claude-code') {
|
|
434
|
+
models = [
|
|
435
|
+
{ id: 'claude-haiku', label: 'Haiku' },
|
|
436
|
+
{ id: 'claude-sonnet', label: 'Sonnet' },
|
|
437
|
+
{ id: 'claude-opus', label: 'Opus' }
|
|
438
|
+
];
|
|
439
|
+
} else {
|
|
440
|
+
const agent = discoveredAgents.find(a => a.id === agentId);
|
|
441
|
+
if (agent?.protocol === 'acp' && agent.acpPort) {
|
|
442
|
+
try {
|
|
443
|
+
const res = await fetch(`http://localhost:${agent.acpPort}/models`, {
|
|
444
|
+
headers: { 'Content-Type': 'application/json' },
|
|
445
|
+
signal: AbortSignal.timeout(3000)
|
|
446
|
+
});
|
|
447
|
+
if (res.ok) {
|
|
448
|
+
const data = await res.json();
|
|
449
|
+
const list = data?.data || data?.models || (Array.isArray(data) ? data : []);
|
|
450
|
+
models = list.map(m => ({ id: m.id || m.model_id, label: m.name || m.display_name || m.id || m.model_id })).filter(m => m.id);
|
|
451
|
+
}
|
|
452
|
+
} catch (_) {}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
modelCache.set(agentId, { models, timestamp: Date.now() });
|
|
456
|
+
return models;
|
|
447
457
|
}
|
|
448
458
|
|
|
449
459
|
const GEMINI_SCOPES = [
|
|
@@ -3813,7 +3823,7 @@ registerConvHandlers(wsRouter, {
|
|
|
3813
3823
|
});
|
|
3814
3824
|
|
|
3815
3825
|
registerSessionHandlers(wsRouter, {
|
|
3816
|
-
db: queries, discoveredAgents,
|
|
3826
|
+
db: queries, discoveredAgents, modelCache,
|
|
3817
3827
|
getAgentDescriptor, activeScripts, broadcastSync,
|
|
3818
3828
|
startGeminiOAuth, geminiOAuthState: () => geminiOAuthState
|
|
3819
3829
|
});
|