@agentbean/daemon 0.1.23 → 0.1.25
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/dist/index.js +37 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,6 +8,10 @@ import { pickAdapter } from './adapters/factory.js';
|
|
|
8
8
|
import { logger } from './log.js';
|
|
9
9
|
import { scanRuntimes, scanAgentOSAgents, scanLocalAgents, getDeviceId } from './scanner.js';
|
|
10
10
|
import { loadAuth, saveAuth } from './auth-store.js';
|
|
11
|
+
export function discoveredAgentId(name, deviceId) {
|
|
12
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
13
|
+
return deviceId ? `scan-${deviceId}-${slug}` : slug;
|
|
14
|
+
}
|
|
11
15
|
async function discoverAgents(deviceId) {
|
|
12
16
|
const [_runtimes, agentos, local] = await Promise.all([
|
|
13
17
|
scanRuntimes(),
|
|
@@ -21,7 +25,7 @@ async function discoverAgents(deviceId) {
|
|
|
21
25
|
continue;
|
|
22
26
|
seen.add(s.command);
|
|
23
27
|
results.push({
|
|
24
|
-
id: s.name
|
|
28
|
+
id: discoveredAgentId(s.name, deviceId),
|
|
25
29
|
name: s.name,
|
|
26
30
|
role: s.category === 'executor-hosted' ? 'executor-agent' : 'gateway-agent',
|
|
27
31
|
category: s.category,
|
|
@@ -29,6 +33,7 @@ async function discoverAgents(deviceId) {
|
|
|
29
33
|
kind: s.adapterKind,
|
|
30
34
|
command: s.command,
|
|
31
35
|
args: s.args,
|
|
36
|
+
cwd: s.cwd,
|
|
32
37
|
},
|
|
33
38
|
visibility: 'public',
|
|
34
39
|
});
|
|
@@ -141,6 +146,7 @@ Options:
|
|
|
141
146
|
}
|
|
142
147
|
let serverUrl = values['server-url'] ?? process.env.AGENT_BEAN_SERVER_URL;
|
|
143
148
|
let token = values['token'] ?? process.env.AGENT_BEAN_AGENT_TOKEN;
|
|
149
|
+
let savedAuth = null;
|
|
144
150
|
let networkId = values['network-id'] ?? 'default';
|
|
145
151
|
if (values.invite) {
|
|
146
152
|
if (!serverUrl) {
|
|
@@ -153,11 +159,10 @@ Options:
|
|
|
153
159
|
networkId = auth.networkId ?? networkId;
|
|
154
160
|
}
|
|
155
161
|
else if (!token) {
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
serverUrl = serverUrl ??
|
|
159
|
-
token =
|
|
160
|
-
networkId = saved.networkId ?? networkId;
|
|
162
|
+
savedAuth = loadAuth();
|
|
163
|
+
if (savedAuth) {
|
|
164
|
+
serverUrl = serverUrl ?? savedAuth.serverUrl;
|
|
165
|
+
token = savedAuth.token;
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
168
|
if (!serverUrl || !token) {
|
|
@@ -165,6 +170,18 @@ Options:
|
|
|
165
170
|
console.error('Usage: agentbean-daemon --server-url <url> --token <token>');
|
|
166
171
|
process.exit(1);
|
|
167
172
|
}
|
|
173
|
+
const tokenNetworkId = networkIdFromToken(token);
|
|
174
|
+
if (values['network-id'] && tokenNetworkId && values['network-id'] !== tokenNetworkId) {
|
|
175
|
+
console.error('Error: --network-id does not match the provided token.');
|
|
176
|
+
console.error('Use the team ID embedded in the token, or omit --network-id and let the daemon detect it.');
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
networkId = resolveCliNetworkId({
|
|
180
|
+
explicitNetworkId: values['network-id'],
|
|
181
|
+
token,
|
|
182
|
+
savedNetworkId: savedAuth?.networkId,
|
|
183
|
+
fallbackNetworkId: networkId,
|
|
184
|
+
});
|
|
168
185
|
const deviceId = values['device-id'] ?? await getDeviceId();
|
|
169
186
|
logger.info({ serverUrl, deviceId, networkId }, 'CLI mode: auto-discovering agents');
|
|
170
187
|
const agents = await discoverAgents(deviceId);
|
|
@@ -187,6 +204,20 @@ function normalizeAgentUrl(serverUrl) {
|
|
|
187
204
|
const base = normalizeBaseUrl(serverUrl);
|
|
188
205
|
return `${base}/agent`;
|
|
189
206
|
}
|
|
207
|
+
export function networkIdFromToken(token) {
|
|
208
|
+
const parts = String(token ?? '').split(':');
|
|
209
|
+
if (parts.length !== 3)
|
|
210
|
+
return undefined;
|
|
211
|
+
const networkId = parts[1]?.trim();
|
|
212
|
+
return networkId || undefined;
|
|
213
|
+
}
|
|
214
|
+
export function resolveCliNetworkId(input) {
|
|
215
|
+
return input.explicitNetworkId
|
|
216
|
+
?? networkIdFromToken(input.token)
|
|
217
|
+
?? input.savedNetworkId
|
|
218
|
+
?? input.fallbackNetworkId
|
|
219
|
+
?? 'default';
|
|
220
|
+
}
|
|
190
221
|
export const INVITE_CONNECTION_TIMEOUT_MS = 20_000;
|
|
191
222
|
export function createInviteSocketOptions() {
|
|
192
223
|
return {
|