agentbnb 3.1.3 → 3.1.5

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +22 -26
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -2905,6 +2905,22 @@ async function confirm(question) {
2905
2905
  rl.close();
2906
2906
  }
2907
2907
  }
2908
+ function loadIdentityAuth(owner) {
2909
+ const configDir = getConfigDir();
2910
+ let keys;
2911
+ try {
2912
+ keys = loadKeyPair(configDir);
2913
+ } catch {
2914
+ keys = generateKeyPair();
2915
+ saveKeyPair(configDir, keys);
2916
+ }
2917
+ const identity = ensureIdentity(configDir, owner);
2918
+ return {
2919
+ agentId: identity.agent_id,
2920
+ publicKey: identity.public_key,
2921
+ privateKey: keys.privateKey
2922
+ };
2923
+ }
2908
2924
  function getLanIp() {
2909
2925
  const nets = networkInterfaces();
2910
2926
  for (const ifaces of Object.values(nets)) {
@@ -2925,15 +2941,17 @@ program.command("init").description("Initialize AgentBnB config and create agent
2925
2941
  const port = parseInt(opts.port, 10);
2926
2942
  const ip = opts.host ?? getLanIp();
2927
2943
  const existingConfig = loadConfig();
2928
- const api_key = existingConfig?.api_key ?? randomBytes(32).toString("hex");
2929
2944
  const config = {
2945
+ ...existingConfig,
2946
+ // Preserve all existing keys (registry, autonomy, budget, etc.)
2930
2947
  owner,
2931
2948
  gateway_url: `http://${ip}:${port}`,
2932
2949
  gateway_port: port,
2933
2950
  db_path: dbPath,
2934
2951
  credit_db_path: creditDbPath,
2935
- token,
2936
- api_key
2952
+ token: existingConfig?.token ?? token,
2953
+ // Preserve existing token
2954
+ api_key: existingConfig?.api_key ?? randomBytes(32).toString("hex")
2937
2955
  };
2938
2956
  saveConfig(config);
2939
2957
  let keypairStatus = "existing";
@@ -3440,7 +3458,7 @@ program.command("request [card-id]").description("Request a capability from anot
3440
3458
  let gatewayUrl;
3441
3459
  let token;
3442
3460
  let isRemoteRequest = false;
3443
- let identityAuth;
3461
+ const identityAuth = loadIdentityAuth(config.owner);
3444
3462
  if (opts.peer) {
3445
3463
  const peer = findPeer(opts.peer);
3446
3464
  if (!peer) {
@@ -3450,16 +3468,6 @@ program.command("request [card-id]").description("Request a capability from anot
3450
3468
  gatewayUrl = peer.url;
3451
3469
  token = peer.token;
3452
3470
  isRemoteRequest = true;
3453
- const configDir = getConfigDir();
3454
- const agentIdentity = loadIdentity(configDir);
3455
- if (agentIdentity) {
3456
- const keys = loadKeyPair(configDir);
3457
- identityAuth = {
3458
- agentId: agentIdentity.agent_id,
3459
- publicKey: agentIdentity.public_key,
3460
- privateKey: keys.privateKey
3461
- };
3462
- }
3463
3471
  } else {
3464
3472
  const db = openDatabase(config.db_path);
3465
3473
  let localCard;
@@ -3498,18 +3506,6 @@ program.command("request [card-id]").description("Request a capability from anot
3498
3506
  gatewayUrl = remoteCard.gateway_url;
3499
3507
  token = "";
3500
3508
  isRemoteRequest = true;
3501
- const configDir = getConfigDir();
3502
- const agentIdentity = loadIdentity(configDir);
3503
- if (!agentIdentity) {
3504
- console.error("Error: no agent identity found. Run `agentbnb init` first.");
3505
- process.exit(1);
3506
- }
3507
- const keys = loadKeyPair(configDir);
3508
- identityAuth = {
3509
- agentId: agentIdentity.agent_id,
3510
- publicKey: agentIdentity.public_key,
3511
- privateKey: keys.privateKey
3512
- };
3513
3509
  if (!opts.json) {
3514
3510
  const displayName = remoteCard.name ?? remoteCard.agent_name ?? cardId;
3515
3511
  console.log(`Found remote card: ${displayName} @ ${gatewayUrl}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentbnb",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "P2P Agent Capability Sharing Protocol — Airbnb for AI agent pipelines",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",