@apa-network/agent-sdk 0.2.0-beta.12 → 0.2.0-beta.13
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.
|
@@ -3,9 +3,13 @@ export function buildCredentialFromRegisterResult(result, apiBase, fallbackName)
|
|
|
3
3
|
if (!obj) {
|
|
4
4
|
return null;
|
|
5
5
|
}
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const agent = (obj.agent && typeof obj.agent === "object" ? obj.agent : null);
|
|
7
|
+
if (!agent) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const agentID = typeof agent.agent_id === "string" ? agent.agent_id : "";
|
|
11
|
+
const apiKey = typeof agent.api_key === "string" ? agent.api_key : "";
|
|
12
|
+
const agentName = typeof agent.name === "string" && agent.name.trim() ? agent.name : fallbackName;
|
|
9
13
|
if (!agentID || !apiKey || !agentName) {
|
|
10
14
|
return null;
|
|
11
15
|
}
|
|
@@ -3,9 +3,11 @@ import assert from "node:assert/strict";
|
|
|
3
3
|
import { buildCredentialFromRegisterResult } from "./register.js";
|
|
4
4
|
test("buildCredentialFromRegisterResult returns credential when response has required fields", () => {
|
|
5
5
|
const out = buildCredentialFromRegisterResult({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
agent: {
|
|
7
|
+
agent_id: "agent_123",
|
|
8
|
+
api_key: "apa_123",
|
|
9
|
+
name: "BotX"
|
|
10
|
+
}
|
|
9
11
|
}, "http://localhost:8080/api", "FallbackBot");
|
|
10
12
|
assert.ok(out);
|
|
11
13
|
assert.equal(out?.agent_id, "agent_123");
|
|
@@ -14,13 +16,17 @@ test("buildCredentialFromRegisterResult returns credential when response has req
|
|
|
14
16
|
});
|
|
15
17
|
test("buildCredentialFromRegisterResult falls back to CLI name and rejects incomplete payload", () => {
|
|
16
18
|
const fallback = buildCredentialFromRegisterResult({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
agent: {
|
|
20
|
+
agent_id: "agent_abc",
|
|
21
|
+
api_key: "apa_abc"
|
|
22
|
+
}
|
|
19
23
|
}, "http://localhost:8080/api", "FallbackBot");
|
|
20
24
|
assert.ok(fallback);
|
|
21
25
|
assert.equal(fallback?.agent_name, "FallbackBot");
|
|
22
26
|
const bad = buildCredentialFromRegisterResult({
|
|
23
|
-
|
|
27
|
+
agent: {
|
|
28
|
+
api_key: "apa_missing_agent"
|
|
29
|
+
}
|
|
24
30
|
}, "http://localhost:8080/api", "FallbackBot");
|
|
25
31
|
assert.equal(bad, null);
|
|
26
32
|
});
|