agentbnb 3.1.4 → 3.1.6

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/cli/index.js CHANGED
@@ -1646,13 +1646,19 @@ function createGatewayServer(opts) {
1646
1646
  } = opts;
1647
1647
  const fastify = Fastify({ logger: !silent });
1648
1648
  const tokenSet = new Set(tokens);
1649
- fastify.addHook("onRequest", async (request, reply) => {
1649
+ fastify.addHook("onRequest", async (request) => {
1650
1650
  if (request.method === "GET" && request.url === "/health") return;
1651
1651
  const auth = request.headers.authorization;
1652
1652
  if (auth && auth.startsWith("Bearer ")) {
1653
1653
  const token = auth.slice("Bearer ".length).trim();
1654
- if (tokenSet.has(token)) return;
1654
+ if (tokenSet.has(token)) {
1655
+ request._authenticated = true;
1656
+ }
1655
1657
  }
1658
+ });
1659
+ fastify.addHook("preHandler", async (request, reply) => {
1660
+ if (request._authenticated) return;
1661
+ if (request.method === "GET" && request.url === "/health") return;
1656
1662
  const agentId = request.headers["x-agent-id"];
1657
1663
  const publicKeyHex = request.headers["x-agent-public-key"];
1658
1664
  const signature = request.headers["x-agent-signature"];
@@ -1660,8 +1666,10 @@ function createGatewayServer(opts) {
1660
1666
  try {
1661
1667
  const publicKeyBuf = Buffer.from(publicKeyHex, "hex");
1662
1668
  const body = request.body;
1663
- const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
1664
- if (valid) return;
1669
+ if (body && typeof body === "object") {
1670
+ const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
1671
+ if (valid) return;
1672
+ }
1665
1673
  } catch {
1666
1674
  }
1667
1675
  }
@@ -2941,15 +2949,17 @@ program.command("init").description("Initialize AgentBnB config and create agent
2941
2949
  const port = parseInt(opts.port, 10);
2942
2950
  const ip = opts.host ?? getLanIp();
2943
2951
  const existingConfig = loadConfig();
2944
- const api_key = existingConfig?.api_key ?? randomBytes(32).toString("hex");
2945
2952
  const config = {
2953
+ ...existingConfig,
2954
+ // Preserve all existing keys (registry, autonomy, budget, etc.)
2946
2955
  owner,
2947
2956
  gateway_url: `http://${ip}:${port}`,
2948
2957
  gateway_port: port,
2949
2958
  db_path: dbPath,
2950
2959
  credit_db_path: creditDbPath,
2951
- token,
2952
- api_key
2960
+ token: existingConfig?.token ?? token,
2961
+ // Preserve existing token
2962
+ api_key: existingConfig?.api_key ?? randomBytes(32).toString("hex")
2953
2963
  };
2954
2964
  saveConfig(config);
2955
2965
  let keypairStatus = "existing";
@@ -3456,7 +3466,7 @@ program.command("request [card-id]").description("Request a capability from anot
3456
3466
  let gatewayUrl;
3457
3467
  let token;
3458
3468
  let isRemoteRequest = false;
3459
- let identityAuth;
3469
+ const identityAuth = loadIdentityAuth(config.owner);
3460
3470
  if (opts.peer) {
3461
3471
  const peer = findPeer(opts.peer);
3462
3472
  if (!peer) {
@@ -3466,7 +3476,6 @@ program.command("request [card-id]").description("Request a capability from anot
3466
3476
  gatewayUrl = peer.url;
3467
3477
  token = peer.token;
3468
3478
  isRemoteRequest = true;
3469
- identityAuth = loadIdentityAuth(config.owner);
3470
3479
  } else {
3471
3480
  const db = openDatabase(config.db_path);
3472
3481
  let localCard;
@@ -3505,7 +3514,6 @@ program.command("request [card-id]").description("Request a capability from anot
3505
3514
  gatewayUrl = remoteCard.gateway_url;
3506
3515
  token = "";
3507
3516
  isRemoteRequest = true;
3508
- identityAuth = loadIdentityAuth(config.owner);
3509
3517
  if (!opts.json) {
3510
3518
  const displayName = remoteCard.name ?? remoteCard.agent_name ?? cardId;
3511
3519
  console.log(`Found remote card: ${displayName} @ ${gatewayUrl}`);
package/dist/index.js CHANGED
@@ -943,13 +943,19 @@ function createGatewayServer(opts) {
943
943
  } = opts;
944
944
  const fastify = Fastify({ logger: !silent });
945
945
  const tokenSet = new Set(tokens);
946
- fastify.addHook("onRequest", async (request, reply) => {
946
+ fastify.addHook("onRequest", async (request) => {
947
947
  if (request.method === "GET" && request.url === "/health") return;
948
948
  const auth = request.headers.authorization;
949
949
  if (auth && auth.startsWith("Bearer ")) {
950
950
  const token = auth.slice("Bearer ".length).trim();
951
- if (tokenSet.has(token)) return;
951
+ if (tokenSet.has(token)) {
952
+ request._authenticated = true;
953
+ }
952
954
  }
955
+ });
956
+ fastify.addHook("preHandler", async (request, reply) => {
957
+ if (request._authenticated) return;
958
+ if (request.method === "GET" && request.url === "/health") return;
953
959
  const agentId = request.headers["x-agent-id"];
954
960
  const publicKeyHex = request.headers["x-agent-public-key"];
955
961
  const signature = request.headers["x-agent-signature"];
@@ -957,8 +963,10 @@ function createGatewayServer(opts) {
957
963
  try {
958
964
  const publicKeyBuf = Buffer.from(publicKeyHex, "hex");
959
965
  const body = request.body;
960
- const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
961
- if (valid) return;
966
+ if (body && typeof body === "object") {
967
+ const valid = verifyEscrowReceipt(body, signature, publicKeyBuf);
968
+ if (valid) return;
969
+ }
962
970
  } catch {
963
971
  }
964
972
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentbnb",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "P2P Agent Capability Sharing Protocol — Airbnb for AI agent pipelines",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",