@agentbus/agentbus-client 0.19.0 → 0.20.0

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.
@@ -0,0 +1,10 @@
1
+ export type AgentIdAction = {
2
+ type: "message" | "runner_ack" | "implementation" | "qa_verdict" | "agy_go" | "merge" | "push" | "release" | "identity_admin";
3
+ [key: string]: string;
4
+ };
5
+ export declare function validateAgentIdValue(value: unknown, path?: string): void;
6
+ export declare function validateAgentIdAction(value: unknown): AgentIdAction;
7
+ /** RFC 8785 bytes loaded through a preserved ESM dynamic-import boundary. */
8
+ export declare function canonicalizeAgentId(value: unknown): Promise<Buffer>;
9
+ export declare function agentIdCanonicalSha256(value: unknown): Promise<string>;
10
+ export declare function verifyAgentIdSignature(unsigned: unknown, signatureBase64Url: string, publicKeyBase64Url: string): Promise<boolean>;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAgentIdValue = validateAgentIdValue;
4
+ exports.validateAgentIdAction = validateAgentIdAction;
5
+ exports.canonicalizeAgentId = canonicalizeAgentId;
6
+ exports.agentIdCanonicalSha256 = agentIdCanonicalSha256;
7
+ exports.verifyAgentIdSignature = verifyAgentIdSignature;
8
+ const crypto_1 = require("crypto");
9
+ const importEsm = new Function("specifier", "return import(specifier)");
10
+ function validateAgentIdValue(value, path = "$") {
11
+ if (value === null || typeof value === "boolean")
12
+ return;
13
+ if (typeof value === "string") {
14
+ if (value.normalize("NFC") !== value) {
15
+ throw new Error(`non_nfc_string: ${path}`);
16
+ }
17
+ for (let i = 0; i < value.length; i += 1) {
18
+ const unit = value.charCodeAt(i);
19
+ if (unit >= 0xd800 && unit <= 0xdbff) {
20
+ const next = value.charCodeAt(i + 1);
21
+ if (!(next >= 0xdc00 && next <= 0xdfff)) {
22
+ throw new Error(`invalid_unicode_scalar: ${path}`);
23
+ }
24
+ i += 1;
25
+ }
26
+ else if (unit >= 0xdc00 && unit <= 0xdfff) {
27
+ throw new Error(`invalid_unicode_scalar: ${path}`);
28
+ }
29
+ }
30
+ return;
31
+ }
32
+ if (typeof value === "number") {
33
+ if (!Number.isFinite(value))
34
+ throw new Error(`non_finite_number: ${path}`);
35
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
36
+ throw new Error(`unsafe_integer: ${path}`);
37
+ }
38
+ return;
39
+ }
40
+ if (Array.isArray(value)) {
41
+ value.forEach((child, index) => validateAgentIdValue(child, `${path}[${index}]`));
42
+ return;
43
+ }
44
+ if (typeof value === "object") {
45
+ for (const [key, child] of Object.entries(value)) {
46
+ validateAgentIdValue(key, `${path}.<key>`);
47
+ validateAgentIdValue(child, `${path}.${key}`);
48
+ }
49
+ return;
50
+ }
51
+ throw new Error(`unsupported_json_type: ${path}`);
52
+ }
53
+ function validateAgentIdAction(value) {
54
+ validateAgentIdValue(value, "$.action");
55
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
56
+ throw new Error("invalid_typed_action");
57
+ }
58
+ const action = value;
59
+ const types = new Set([
60
+ "message",
61
+ "runner_ack",
62
+ "implementation",
63
+ "qa_verdict",
64
+ "agy_go",
65
+ "merge",
66
+ "push",
67
+ "release",
68
+ "identity_admin",
69
+ ]);
70
+ if (typeof action.type !== "string" || !types.has(action.type)) {
71
+ throw new Error(`unknown_action_type: ${String(action.type)}`);
72
+ }
73
+ const allowedFields = {
74
+ message: new Set(["type"]),
75
+ runner_ack: new Set(["type", "source_event_id", "status"]),
76
+ implementation: new Set(["type", "phase", "task"]),
77
+ qa_verdict: new Set(["type", "result", "mission_id", "candidate"]),
78
+ agy_go: new Set(["type", "phase", "scope"]),
79
+ merge: new Set(["type", "target", "candidate"]),
80
+ push: new Set(["type", "target", "candidate"]),
81
+ release: new Set(["type", "version", "candidate"]),
82
+ identity_admin: new Set(["type", "operation", "subject"]),
83
+ };
84
+ const extras = Object.keys(action).filter((field) => !allowedFields[action.type].has(field));
85
+ if (extras.length > 0) {
86
+ throw new Error(`unexpected_action_fields: ${extras.sort().join(",")}`);
87
+ }
88
+ if (action.type === "qa_verdict" &&
89
+ action.result !== "green" &&
90
+ action.result !== "red") {
91
+ throw new Error("invalid_qa_verdict_result");
92
+ }
93
+ if (action.type === "agy_go" && typeof action.phase !== "string") {
94
+ throw new Error("agy_go_phase_required");
95
+ }
96
+ if (action.type === "identity_admin" &&
97
+ !new Set(["delegate", "enroll", "mode", "revoke", "rotate"]).has(action.operation)) {
98
+ throw new Error("invalid_identity_admin_operation");
99
+ }
100
+ for (const [field, fieldValue] of Object.entries(action)) {
101
+ if (field === "source_event_id" &&
102
+ (typeof fieldValue !== "string" || !/^\d+$/.test(fieldValue))) {
103
+ throw new Error("invalid_runner_ack_source_event_id");
104
+ }
105
+ if (field !== "source_event_id" && typeof fieldValue !== "string") {
106
+ throw new Error(`invalid_action_field: ${field}`);
107
+ }
108
+ }
109
+ return action;
110
+ }
111
+ /** RFC 8785 bytes loaded through a preserved ESM dynamic-import boundary. */
112
+ async function canonicalizeAgentId(value) {
113
+ validateAgentIdValue(value);
114
+ const module = await importEsm("canonicalize");
115
+ const canonicalize = module.default;
116
+ if (typeof canonicalize !== "function") {
117
+ throw new Error("canonicalize_module_invalid");
118
+ }
119
+ const result = canonicalize(value);
120
+ if (typeof result !== "string")
121
+ throw new Error("canonicalize_failed");
122
+ return Buffer.from(result, "utf8");
123
+ }
124
+ async function agentIdCanonicalSha256(value) {
125
+ return (0, crypto_1.createHash)("sha256")
126
+ .update(await canonicalizeAgentId(value))
127
+ .digest("hex");
128
+ }
129
+ async function verifyAgentIdSignature(unsigned, signatureBase64Url, publicKeyBase64Url) {
130
+ const rawPublic = Buffer.from(publicKeyBase64Url, "base64url");
131
+ if (rawPublic.length !== 32)
132
+ throw new Error("invalid_ed25519_public_key");
133
+ // RFC 8410 SubjectPublicKeyInfo prefix for a raw 32-byte Ed25519 key.
134
+ const spki = Buffer.concat([
135
+ Buffer.from("302a300506032b6570032100", "hex"),
136
+ rawPublic,
137
+ ]);
138
+ const key = (0, crypto_1.createPublicKey)({ key: spki, format: "der", type: "spki" });
139
+ return (0, crypto_1.verify)(null, await canonicalizeAgentId(unsigned), key, Buffer.from(signatureBase64Url, "base64url"));
140
+ }
package/dist/index.d.ts CHANGED
@@ -3,9 +3,11 @@ import type { AgentBusOptions, BusEvent } from "./types";
3
3
  export { getDatabasePath } from "./locator";
4
4
  export { DatabaseWatcher } from "./watcher";
5
5
  export { createStdioMcpClient } from "./stdio";
6
+ export { agentIdCanonicalSha256, canonicalizeAgentId, validateAgentIdValue, validateAgentIdAction, verifyAgentIdSignature, } from "./identity";
6
7
  export { platformKey, optionalPackageName, resolveGoWorkerPath, } from "./goBin";
7
8
  export type { AgentBusOptions, BusEvent, McpToolClient, } from "./types";
8
9
  export type { StdioMcpOptions } from "./stdio";
10
+ export type { AgentIdAction } from "./identity";
9
11
  /**
10
12
  * Idiomatic Node client: EventEmitter + publish/poll over AgentBus MCP tools,
11
13
  * with fs.watch-triggered polls and a slow timer fallback.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentBus = exports.resolveGoWorkerPath = exports.optionalPackageName = exports.platformKey = exports.createStdioMcpClient = exports.DatabaseWatcher = exports.getDatabasePath = void 0;
3
+ exports.AgentBus = exports.resolveGoWorkerPath = exports.optionalPackageName = exports.platformKey = exports.verifyAgentIdSignature = exports.validateAgentIdAction = exports.validateAgentIdValue = exports.canonicalizeAgentId = exports.agentIdCanonicalSha256 = exports.createStdioMcpClient = exports.DatabaseWatcher = exports.getDatabasePath = void 0;
4
4
  exports.unwrapToolResult = unwrapToolResult;
5
5
  exports.parsePollPage = parsePollPage;
6
6
  exports.normalizePollResult = normalizePollResult;
@@ -14,6 +14,12 @@ var watcher_2 = require("./watcher");
14
14
  Object.defineProperty(exports, "DatabaseWatcher", { enumerable: true, get: function () { return watcher_2.DatabaseWatcher; } });
15
15
  var stdio_2 = require("./stdio");
16
16
  Object.defineProperty(exports, "createStdioMcpClient", { enumerable: true, get: function () { return stdio_2.createStdioMcpClient; } });
17
+ var identity_1 = require("./identity");
18
+ Object.defineProperty(exports, "agentIdCanonicalSha256", { enumerable: true, get: function () { return identity_1.agentIdCanonicalSha256; } });
19
+ Object.defineProperty(exports, "canonicalizeAgentId", { enumerable: true, get: function () { return identity_1.canonicalizeAgentId; } });
20
+ Object.defineProperty(exports, "validateAgentIdValue", { enumerable: true, get: function () { return identity_1.validateAgentIdValue; } });
21
+ Object.defineProperty(exports, "validateAgentIdAction", { enumerable: true, get: function () { return identity_1.validateAgentIdAction; } });
22
+ Object.defineProperty(exports, "verifyAgentIdSignature", { enumerable: true, get: function () { return identity_1.verifyAgentIdSignature; } });
17
23
  var goBin_1 = require("./goBin");
18
24
  Object.defineProperty(exports, "platformKey", { enumerable: true, get: function () { return goBin_1.platformKey; } });
19
25
  Object.defineProperty(exports, "optionalPackageName", { enumerable: true, get: function () { return goBin_1.optionalPackageName; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbus/agentbus-client",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "TypeScript/Node EventEmitter client for AgentBus (MCP + fs.watch poll)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,15 +9,16 @@
9
9
  "README.md"
10
10
  ],
11
11
  "optionalDependencies": {
12
- "@agentbus/go-worker-linux-x64": "0.19.0",
13
- "@agentbus/go-worker-linux-arm64": "0.19.0",
14
- "@agentbus/go-worker-darwin-x64": "0.19.0",
15
- "@agentbus/go-worker-darwin-arm64": "0.19.0",
16
- "@agentbus/go-worker-win32-x64": "0.19.0"
12
+ "@agentbus/go-worker-linux-x64": "0.20.0",
13
+ "@agentbus/go-worker-linux-arm64": "0.20.0",
14
+ "@agentbus/go-worker-darwin-x64": "0.20.0",
15
+ "@agentbus/go-worker-darwin-arm64": "0.20.0",
16
+ "@agentbus/go-worker-win32-x64": "0.20.0"
17
17
  },
18
18
  "scripts": {
19
19
  "build": "tsc",
20
20
  "prepublishOnly": "npm run build",
21
+ "pretest": "npm run build",
21
22
  "test": "vitest run",
22
23
  "test:watch": "vitest"
23
24
  },
@@ -45,7 +46,8 @@
45
46
  "provenance": true
46
47
  },
47
48
  "dependencies": {
48
- "@modelcontextprotocol/sdk": "^1.12.1"
49
+ "@modelcontextprotocol/sdk": "^1.12.1",
50
+ "canonicalize": "4.0.0"
49
51
  },
50
52
  "devDependencies": {
51
53
  "@types/node": "^22.15.0",