@agentbridge1/cli 0.0.3 → 0.0.4
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/build-info.json +4 -4
- package/dist/commands/connect.js +56 -23
- package/package.json +1 -1
package/dist/build-info.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"builtAt": "2026-06-
|
|
3
|
-
"gitHead": "
|
|
4
|
-
"sourceLatestMtime": "2026-06-
|
|
5
|
-
"sourceLatestFile": "src/commands/
|
|
2
|
+
"builtAt": "2026-06-02T04:55:04.008Z",
|
|
3
|
+
"gitHead": "86fed7f",
|
|
4
|
+
"sourceLatestMtime": "2026-06-02T04:51:46.614Z",
|
|
5
|
+
"sourceLatestFile": "src/commands/connect.ts"
|
|
6
6
|
}
|
package/dist/commands/connect.js
CHANGED
|
@@ -10,35 +10,68 @@ function resolveBaseUrl(override) {
|
|
|
10
10
|
config_1.DEFAULT_API_BASE_URL);
|
|
11
11
|
}
|
|
12
12
|
async function verifyCredentials(projectId, apiKey, apiBaseUrl) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
13
|
+
const summaryUrl = `${apiBaseUrl}/v1/dev/projects/${projectId}/summary`;
|
|
14
|
+
const packetUrl = `${apiBaseUrl}/v1/dev/projects/${projectId}/packet`;
|
|
15
|
+
const headers = {
|
|
16
|
+
Authorization: `Bearer ${apiKey}`,
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
};
|
|
19
|
+
async function get(url) {
|
|
20
|
+
try {
|
|
21
|
+
return await fetch(url, { method: "GET", headers });
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
25
|
+
throw new errors_1.SafeCliError(`Could not reach AgentBridge server at ${apiBaseUrl}.\nNetwork error: ${msg}\n\nCheck your AGENTBRIDGE_BASE_URL or internet connection.`);
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
async function readBody(res) {
|
|
29
|
+
try {
|
|
30
|
+
return await res.text();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
function isRouteMissing(body) {
|
|
37
|
+
return body.toLowerCase().includes("route not found");
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
async function throwAuthOrNotFound(res) {
|
|
40
|
+
if (res.status === 401 || res.status === 403) {
|
|
41
|
+
throw new errors_1.SafeCliError(`API key rejected (HTTP ${res.status}).\n\nGet a valid key at https://agentbridge.dev/dashboard and set AGENTBRIDGE_API_KEY.`);
|
|
42
|
+
}
|
|
43
|
+
if (res.status === 404) {
|
|
44
|
+
throw new errors_1.SafeCliError(`Project not found or key has no access on ${apiBaseUrl}.\nCheck project ID, API key, and backend URL.`);
|
|
45
|
+
}
|
|
46
|
+
const text = await readBody(res);
|
|
47
|
+
throw new http_1.CliHttpError(`GET ${summaryUrl} failed (${res.status}): ${text || "<empty>"}`, res.status, text);
|
|
48
|
+
}
|
|
49
|
+
let res;
|
|
50
|
+
res = await get(summaryUrl);
|
|
51
|
+
if (res.ok) {
|
|
52
|
+
const body = (await res.json());
|
|
53
|
+
return {
|
|
54
|
+
projectName: body.project_name ?? body.projectName ?? projectId,
|
|
55
|
+
agentCount: typeof body.agent_count === "number"
|
|
56
|
+
? body.agent_count
|
|
57
|
+
: Array.isArray(body.agents)
|
|
58
|
+
? body.agents.length
|
|
59
|
+
: 0,
|
|
60
|
+
};
|
|
33
61
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
const summaryBody = await readBody(res);
|
|
63
|
+
if (!(res.status === 404 && isRouteMissing(summaryBody))) {
|
|
64
|
+
await throwAuthOrNotFound(res);
|
|
37
65
|
}
|
|
38
|
-
|
|
66
|
+
// Backward compatibility for servers that haven't shipped /summary yet.
|
|
67
|
+
const packetRes = await get(packetUrl);
|
|
68
|
+
if (!packetRes.ok) {
|
|
69
|
+
await throwAuthOrNotFound(packetRes);
|
|
70
|
+
}
|
|
71
|
+
const packetBody = (await packetRes.json());
|
|
39
72
|
return {
|
|
40
|
-
projectName:
|
|
41
|
-
agentCount:
|
|
73
|
+
projectName: packetBody.project_name ?? projectId,
|
|
74
|
+
agentCount: 0,
|
|
42
75
|
};
|
|
43
76
|
}
|
|
44
77
|
async function listAgents(projectId, apiKey, apiBaseUrl) {
|