@agentbean/daemon 0.1.23 → 0.1.24
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 +31 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -141,6 +141,7 @@ Options:
|
|
|
141
141
|
}
|
|
142
142
|
let serverUrl = values['server-url'] ?? process.env.AGENT_BEAN_SERVER_URL;
|
|
143
143
|
let token = values['token'] ?? process.env.AGENT_BEAN_AGENT_TOKEN;
|
|
144
|
+
let savedAuth = null;
|
|
144
145
|
let networkId = values['network-id'] ?? 'default';
|
|
145
146
|
if (values.invite) {
|
|
146
147
|
if (!serverUrl) {
|
|
@@ -153,11 +154,10 @@ Options:
|
|
|
153
154
|
networkId = auth.networkId ?? networkId;
|
|
154
155
|
}
|
|
155
156
|
else if (!token) {
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
serverUrl = serverUrl ??
|
|
159
|
-
token =
|
|
160
|
-
networkId = saved.networkId ?? networkId;
|
|
157
|
+
savedAuth = loadAuth();
|
|
158
|
+
if (savedAuth) {
|
|
159
|
+
serverUrl = serverUrl ?? savedAuth.serverUrl;
|
|
160
|
+
token = savedAuth.token;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
if (!serverUrl || !token) {
|
|
@@ -165,6 +165,18 @@ Options:
|
|
|
165
165
|
console.error('Usage: agentbean-daemon --server-url <url> --token <token>');
|
|
166
166
|
process.exit(1);
|
|
167
167
|
}
|
|
168
|
+
const tokenNetworkId = networkIdFromToken(token);
|
|
169
|
+
if (values['network-id'] && tokenNetworkId && values['network-id'] !== tokenNetworkId) {
|
|
170
|
+
console.error('Error: --network-id does not match the provided token.');
|
|
171
|
+
console.error('Use the team ID embedded in the token, or omit --network-id and let the daemon detect it.');
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
networkId = resolveCliNetworkId({
|
|
175
|
+
explicitNetworkId: values['network-id'],
|
|
176
|
+
token,
|
|
177
|
+
savedNetworkId: savedAuth?.networkId,
|
|
178
|
+
fallbackNetworkId: networkId,
|
|
179
|
+
});
|
|
168
180
|
const deviceId = values['device-id'] ?? await getDeviceId();
|
|
169
181
|
logger.info({ serverUrl, deviceId, networkId }, 'CLI mode: auto-discovering agents');
|
|
170
182
|
const agents = await discoverAgents(deviceId);
|
|
@@ -187,6 +199,20 @@ function normalizeAgentUrl(serverUrl) {
|
|
|
187
199
|
const base = normalizeBaseUrl(serverUrl);
|
|
188
200
|
return `${base}/agent`;
|
|
189
201
|
}
|
|
202
|
+
export function networkIdFromToken(token) {
|
|
203
|
+
const parts = String(token ?? '').split(':');
|
|
204
|
+
if (parts.length !== 3)
|
|
205
|
+
return undefined;
|
|
206
|
+
const networkId = parts[1]?.trim();
|
|
207
|
+
return networkId || undefined;
|
|
208
|
+
}
|
|
209
|
+
export function resolveCliNetworkId(input) {
|
|
210
|
+
return input.explicitNetworkId
|
|
211
|
+
?? networkIdFromToken(input.token)
|
|
212
|
+
?? input.savedNetworkId
|
|
213
|
+
?? input.fallbackNetworkId
|
|
214
|
+
?? 'default';
|
|
215
|
+
}
|
|
190
216
|
export const INVITE_CONNECTION_TIMEOUT_MS = 20_000;
|
|
191
217
|
export function createInviteSocketOptions() {
|
|
192
218
|
return {
|