agentbnb 9.1.1 → 9.2.1

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 (54) hide show
  1. package/README.md +22 -0
  2. package/dist/{card-UF465O7O.js → card-L3ZPPBVI.js} +3 -3
  3. package/dist/{chunk-LENX5NUW.js → chunk-2KSRFDKF.js} +56 -3
  4. package/dist/{chunk-TCA63C42.js → chunk-563ZZUOA.js} +61 -27
  5. package/dist/chunk-5FXLZ5FX.js +16 -0
  6. package/dist/{chunk-ELFGYC22.js → chunk-7YJOBVWN.js} +3 -0
  7. package/dist/{chunk-5CC6O6SO.js → chunk-AA25Z6FW.js} +1 -1
  8. package/dist/{chunk-WARYO57F.js → chunk-COOBXNXU.js} +6 -6
  9. package/dist/{chunk-I4E5ERDN.js → chunk-CPSV5WR2.js} +1 -1
  10. package/dist/{process-guard-6324CZDC.js → chunk-DG4FQ4MD.js} +1 -1
  11. package/dist/{chunk-MPS4RE7T.js → chunk-DT2IEL5U.js} +11 -0
  12. package/dist/chunk-EMVVFP2L.js +54 -0
  13. package/dist/{chunk-O44N3KR7.js → chunk-FVLHEI3Y.js} +5 -5
  14. package/dist/chunk-GIK2AZQH.js +23 -0
  15. package/dist/{chunk-W6LOCBWQ.js → chunk-IWAK4WHK.js} +1 -1
  16. package/dist/{chunk-Y7CO3VLF.js → chunk-NISX3N7K.js} +16 -7
  17. package/dist/{chunk-2HH2F3DM.js → chunk-NLGLGR2K.js} +55 -2
  18. package/dist/{chunk-AW4VSROG.js → chunk-OFIRWD6B.js} +1 -1
  19. package/dist/{chunk-AMABG5SI.js → chunk-OI46BKQF.js} +12 -12
  20. package/dist/{chunk-F2CIPAN2.js → chunk-OTAZIF65.js} +2 -2
  21. package/dist/{chunk-ZYOMPJGG.js → chunk-OXU4QJSZ.js} +3 -3
  22. package/dist/{chunk-RVOZHVM7.js → chunk-PFAEZI32.js} +10 -10
  23. package/dist/{chunk-D7NH6YLM.js → chunk-UJXDBOKV.js} +12 -1
  24. package/dist/{chunk-G4TF4LB4.js → chunk-VDYHCI5F.js} +22 -1
  25. package/dist/{chunk-QG2LLVXP.js → chunk-WA23XRTN.js} +1 -1
  26. package/dist/cli/index.js +797 -107
  27. package/dist/{client-XOSXFC7Q.js → client-KL67WZVJ.js} +2 -2
  28. package/dist/{conduct-UT6ZYSJD.js → conduct-65BGO2EU.js} +16 -14
  29. package/dist/{conduct-MALC6HEK.js → conduct-AALDEKTH.js} +16 -14
  30. package/dist/{conductor-mode-3WLLERB4.js → conductor-mode-6S6ADNLW.js} +18 -18
  31. package/dist/{conductor-mode-UJKMO2GW.js → conductor-mode-HJHU4XLT.js} +4 -4
  32. package/dist/{credits-action-KOUJNR36.js → credits-action-CLLPNRDT.js} +17 -8
  33. package/dist/{did-action-UHUYMA4Y.js → did-action-ERXWCVEJ.js} +3 -3
  34. package/dist/{execute-UFMGTXET.js → execute-R5STYWLD.js} +13 -13
  35. package/dist/{execute-3RADNI74.js → execute-YMPHTJPN.js} +3 -3
  36. package/dist/{openclaw-setup-HEWZZOY7.js → openclaw-setup-HUOBTGN4.js} +17 -15
  37. package/dist/{openclaw-skills-5XLQFRWT.js → openclaw-skills-74372B6I.js} +2 -2
  38. package/dist/process-guard-IUMZ2GSD.js +8 -0
  39. package/dist/{publish-capability-LM4RSQXX.js → publish-capability-OYXXXYAU.js} +4 -4
  40. package/dist/remote-registry-5TM7DMCO.js +16 -0
  41. package/dist/{request-LID2N42Y.js → request-NEA66RCW.js} +66 -24
  42. package/dist/{serve-skill-CDNSHTEE.js → serve-skill-VKNRBVWE.js} +19 -18
  43. package/dist/{server-QIAO3YSK.js → server-LNT4YQZ7.js} +24 -20
  44. package/dist/{service-coordinator-FB44QL7L.js → service-coordinator-RE2KPWO4.js} +312 -54
  45. package/dist/{session-action-GYITLYOE.js → session-action-UBWJTQVQ.js} +19 -4
  46. package/dist/signing-AQTKYJDB.js +16 -0
  47. package/dist/skills/agentbnb/bootstrap.js +430 -43
  48. package/dist/{store-C4DLIXYM.js → store-GJJFFEQZ.js} +3 -3
  49. package/dist/{vc-action-BWGNQ77Y.js → vc-action-72TQVMY2.js} +15 -5
  50. package/package.json +12 -18
  51. package/skills/agentbnb/install.sh +0 -0
  52. package/dist/{chunk-YNBZLXYS.js → chunk-65GNX2KC.js} +0 -0
  53. package/dist/{chunk-7VZ4M4CT.js → chunk-QE42IJC4.js} +6 -6
  54. package/dist/{daemon-ETXXE4IS.js → daemon-OM2K3U7J.js} +1 -1
@@ -1,31 +1,31 @@
1
1
  import {
2
2
  executeCapabilityRequest
3
- } from "./chunk-RVOZHVM7.js";
4
- import "./chunk-ZYOMPJGG.js";
5
- import "./chunk-LENX5NUW.js";
6
- import "./chunk-5CC6O6SO.js";
7
- import "./chunk-O44N3KR7.js";
8
- import "./chunk-ELFGYC22.js";
9
- import "./chunk-I4E5ERDN.js";
3
+ } from "./chunk-PFAEZI32.js";
4
+ import "./chunk-OXU4QJSZ.js";
5
+ import "./chunk-2KSRFDKF.js";
6
+ import "./chunk-AA25Z6FW.js";
7
+ import "./chunk-FVLHEI3Y.js";
8
+ import "./chunk-CPSV5WR2.js";
10
9
  import {
11
10
  openCreditDb
12
- } from "./chunk-D7NH6YLM.js";
11
+ } from "./chunk-UJXDBOKV.js";
13
12
  import {
14
13
  listCards,
15
14
  openDatabase
16
- } from "./chunk-7VZ4M4CT.js";
15
+ } from "./chunk-QE42IJC4.js";
16
+ import "./chunk-4XTYT4JW.js";
17
+ import "./chunk-GZUTU6IZ.js";
17
18
  import {
18
19
  RelayClient
19
20
  } from "./chunk-UPNREF4L.js";
20
21
  import "./chunk-Q5OFZ2JR.js";
21
22
  import "./chunk-QXRNW4OJ.js";
22
- import "./chunk-YNBZLXYS.js";
23
+ import "./chunk-65GNX2KC.js";
23
24
  import "./chunk-YDGXKH2T.js";
24
25
  import "./chunk-J4RFJVXI.js";
25
- import "./chunk-UVCNMRPS.js";
26
26
  import "./chunk-3XPBFF6H.js";
27
- import "./chunk-4XTYT4JW.js";
28
- import "./chunk-GZUTU6IZ.js";
27
+ import "./chunk-7YJOBVWN.js";
28
+ import "./chunk-UVCNMRPS.js";
29
29
  import "./chunk-3RG5ZIWI.js";
30
30
 
31
31
  // src/mcp/tools/serve-skill.ts
@@ -67,11 +67,12 @@ async function handleServeSkill(args, ctx) {
67
67
  const result = await executeCapabilityRequest({
68
68
  registryDb,
69
69
  creditDb,
70
- cardId: req.params?.card_id ?? card.id,
71
- skillId: req.params?.skill_id,
72
- params: req.params?.params ?? {},
73
- requester: req.params?.requester ?? "unknown",
74
- handlerUrl
70
+ cardId: req.card_id ?? card.id,
71
+ skillId: req.skill_id,
72
+ params: req.params,
73
+ requester: req.requester ?? req.from_owner ?? "unknown",
74
+ handlerUrl,
75
+ relayAuthorized: true
75
76
  });
76
77
  if (result.success) {
77
78
  return { result: result.result };
@@ -1,39 +1,42 @@
1
+ import {
2
+ createSessionState
3
+ } from "./chunk-EMVVFP2L.js";
1
4
  import {
2
5
  createLedger
3
- } from "./chunk-LENX5NUW.js";
6
+ } from "./chunk-2KSRFDKF.js";
4
7
  import {
5
8
  ensureIdentity
6
- } from "./chunk-5CC6O6SO.js";
7
- import {
8
- fetchRemoteCards,
9
- mergeResults
10
- } from "./chunk-ELFGYC22.js";
9
+ } from "./chunk-AA25Z6FW.js";
11
10
  import {
12
11
  searchCards
13
- } from "./chunk-I4E5ERDN.js";
12
+ } from "./chunk-CPSV5WR2.js";
14
13
  import {
15
14
  getBalance,
16
15
  openCreditDb
17
- } from "./chunk-D7NH6YLM.js";
16
+ } from "./chunk-UJXDBOKV.js";
18
17
  import {
19
18
  insertCard,
20
19
  openDatabase
21
- } from "./chunk-7VZ4M4CT.js";
20
+ } from "./chunk-QE42IJC4.js";
21
+ import "./chunk-4XTYT4JW.js";
22
+ import "./chunk-GZUTU6IZ.js";
22
23
  import "./chunk-QXRNW4OJ.js";
23
24
  import {
24
25
  loadKeyPair
25
- } from "./chunk-YNBZLXYS.js";
26
+ } from "./chunk-65GNX2KC.js";
26
27
  import "./chunk-YDGXKH2T.js";
27
28
  import "./chunk-J4RFJVXI.js";
28
- import {
29
- AnyCardSchema
30
- } from "./chunk-UVCNMRPS.js";
31
29
  import {
32
30
  getConfigDir,
33
31
  loadConfig
34
32
  } from "./chunk-3XPBFF6H.js";
35
- import "./chunk-4XTYT4JW.js";
36
- import "./chunk-GZUTU6IZ.js";
33
+ import {
34
+ fetchRemoteCards,
35
+ mergeResults
36
+ } from "./chunk-7YJOBVWN.js";
37
+ import {
38
+ AnyCardSchema
39
+ } from "./chunk-UVCNMRPS.js";
37
40
  import "./chunk-3RG5ZIWI.js";
38
41
 
39
42
  // src/mcp/server.ts
@@ -262,7 +265,7 @@ function registerPublishTool(server, ctx) {
262
265
  }
263
266
 
264
267
  // src/mcp/server.ts
265
- var VERSION = true ? "9.1.1" : "0.0.0-dev";
268
+ var VERSION = true ? "9.2.1" : "0.0.0-dev";
266
269
  async function startMcpServer() {
267
270
  const config = loadConfig();
268
271
  if (!config) {
@@ -278,14 +281,15 @@ async function startMcpServer() {
278
281
  const ctx = {
279
282
  configDir,
280
283
  config,
281
- identity
284
+ identity,
285
+ consumerSession: createSessionState()
282
286
  };
283
287
  registerDiscoverTool(server, ctx);
284
288
  registerStatusTool(server, ctx);
285
289
  registerPublishTool(server, ctx);
286
- const { registerRequestTool } = await import("./request-LID2N42Y.js");
287
- const { registerConductTool } = await import("./conduct-UT6ZYSJD.js");
288
- const { registerServeSkillTool } = await import("./serve-skill-CDNSHTEE.js");
290
+ const { registerRequestTool } = await import("./request-NEA66RCW.js");
291
+ const { registerConductTool } = await import("./conduct-65BGO2EU.js");
292
+ const { registerServeSkillTool } = await import("./serve-skill-VKNRBVWE.js");
289
293
  registerRequestTool(server, ctx);
290
294
  registerConductTool(server, ctx);
291
295
  registerServeSkillTool(server, ctx);
@@ -1,10 +1,11 @@
1
+ import {
2
+ executeCapabilityBatch,
3
+ executeCapabilityRequest,
4
+ notifyProviderEvent
5
+ } from "./chunk-PFAEZI32.js";
1
6
  import {
2
7
  StructuredFeedbackSchema
3
8
  } from "./chunk-AUBHR7HH.js";
4
- import {
5
- ApiSkillConfigSchema,
6
- parseSkillsFile
7
- } from "./chunk-WX3GZVFG.js";
8
9
  import {
9
10
  decodeUCAN,
10
11
  verifyUCAN
@@ -12,15 +13,13 @@ import {
12
13
  import {
13
14
  interpolateObject
14
15
  } from "./chunk-3MJT4PZG.js";
15
- import {
16
- executeCapabilityBatch,
17
- executeCapabilityRequest,
18
- notifyProviderEvent
19
- } from "./chunk-RVOZHVM7.js";
20
16
  import {
21
17
  announceGateway,
22
18
  stopAnnouncement
23
19
  } from "./chunk-TA73FIZU.js";
20
+ import {
21
+ syncCreditsFromRegistry
22
+ } from "./chunk-OXU4QJSZ.js";
24
23
  import {
25
24
  resolveSelfCli
26
25
  } from "./chunk-7S4ZLFVI.js";
@@ -28,39 +27,49 @@ import {
28
27
  KNOWN_API_KEYS,
29
28
  buildDraftCard,
30
29
  detectApiKeys,
31
- getPricingStats
32
- } from "./chunk-G4TF4LB4.js";
30
+ getPricingStats,
31
+ probeRegistry
32
+ } from "./chunk-VDYHCI5F.js";
33
+ import {
34
+ TimeoutError,
35
+ withTimeout
36
+ } from "./chunk-GIK2AZQH.js";
37
+ import {
38
+ shouldSkipNetwork
39
+ } from "./chunk-5FXLZ5FX.js";
40
+ import {
41
+ createLedger,
42
+ identityAuthPlugin,
43
+ tryVerifyIdentity
44
+ } from "./chunk-2KSRFDKF.js";
45
+ import {
46
+ deriveAgentId
47
+ } from "./chunk-AA25Z6FW.js";
48
+ import {
49
+ ApiSkillConfigSchema,
50
+ parseSkillsFile
51
+ } from "./chunk-WX3GZVFG.js";
33
52
  import {
34
53
  listPendingRequests,
35
54
  resolvePendingRequest
36
55
  } from "./chunk-5PV5YCSN.js";
56
+ import "./chunk-FVLHEI3Y.js";
37
57
  import {
38
58
  DEFAULT_AUTONOMY_CONFIG,
39
59
  getAutonomyTier,
40
60
  insertAuditEvent
41
61
  } from "./chunk-G5WKW3ED.js";
42
- import {
43
- syncCreditsFromRegistry
44
- } from "./chunk-ZYOMPJGG.js";
45
- import {
46
- createLedger,
47
- identityAuthPlugin
48
- } from "./chunk-LENX5NUW.js";
49
- import {
50
- deriveAgentId
51
- } from "./chunk-5CC6O6SO.js";
52
- import "./chunk-O44N3KR7.js";
53
- import "./chunk-ELFGYC22.js";
54
62
  import {
55
63
  buildReputationMap,
56
64
  computeReputation,
57
65
  filterCards,
58
66
  searchCards
59
- } from "./chunk-I4E5ERDN.js";
67
+ } from "./chunk-CPSV5WR2.js";
60
68
  import {
61
69
  NETWORK_FEE_RATE,
62
70
  bootstrapAgent,
63
71
  getBalance,
72
+ getEscrowStatus,
64
73
  getTransactions,
65
74
  holdEscrow,
66
75
  markEscrowAbandoned,
@@ -70,7 +79,7 @@ import {
70
79
  openCreditDb,
71
80
  releaseEscrow,
72
81
  settleEscrow
73
- } from "./chunk-D7NH6YLM.js";
82
+ } from "./chunk-UJXDBOKV.js";
74
83
  import {
75
84
  attachCanonicalAgentId,
76
85
  getCard,
@@ -87,7 +96,16 @@ import {
87
96
  updateCard,
88
97
  updateSkillAvailability,
89
98
  updateSkillIdleRate
90
- } from "./chunk-7VZ4M4CT.js";
99
+ } from "./chunk-QE42IJC4.js";
100
+ import {
101
+ getActivityFeed,
102
+ getRequestLog,
103
+ getSkillRequestCount,
104
+ insertRequestLog
105
+ } from "./chunk-4XTYT4JW.js";
106
+ import {
107
+ emitProviderEvent
108
+ } from "./chunk-GZUTU6IZ.js";
91
109
  import {
92
110
  RelayMessageSchema,
93
111
  SESSION_MESSAGE_TYPES,
@@ -102,25 +120,17 @@ import {
102
120
  import {
103
121
  generateKeyPair,
104
122
  verifyEscrowReceipt
105
- } from "./chunk-YNBZLXYS.js";
123
+ } from "./chunk-65GNX2KC.js";
106
124
  import "./chunk-YDGXKH2T.js";
107
125
  import "./chunk-J4RFJVXI.js";
108
- import {
109
- AgentBnBError,
110
- AnyCardSchema
111
- } from "./chunk-UVCNMRPS.js";
112
126
  import {
113
127
  getConfigDir
114
128
  } from "./chunk-3XPBFF6H.js";
129
+ import "./chunk-7YJOBVWN.js";
115
130
  import {
116
- getActivityFeed,
117
- getRequestLog,
118
- getSkillRequestCount,
119
- insertRequestLog
120
- } from "./chunk-4XTYT4JW.js";
121
- import {
122
- emitProviderEvent
123
- } from "./chunk-GZUTU6IZ.js";
131
+ AgentBnBError,
132
+ AnyCardSchema
133
+ } from "./chunk-UVCNMRPS.js";
124
134
  import "./chunk-3RG5ZIWI.js";
125
135
 
126
136
  // src/runtime/agent-runtime.ts
@@ -1179,8 +1189,8 @@ var AgentRuntime = class {
1179
1189
  }
1180
1190
  const modes = /* @__PURE__ */ new Map();
1181
1191
  if (this.conductorEnabled) {
1182
- const { ConductorMode } = await import("./conductor-mode-3WLLERB4.js");
1183
- const { registerConductorCard, CONDUCTOR_OWNER } = await import("./card-UF465O7O.js");
1192
+ const { ConductorMode } = await import("./conductor-mode-6S6ADNLW.js");
1193
+ const { registerConductorCard, CONDUCTOR_OWNER } = await import("./card-L3ZPPBVI.js");
1184
1194
  const { loadPeers } = await import("./peers-7BMU2775.js");
1185
1195
  registerConductorCard(this.registryDb);
1186
1196
  const resolveAgentUrl = (owner) => {
@@ -3265,6 +3275,75 @@ function initiateGithubAuth() {
3265
3275
  };
3266
3276
  }
3267
3277
 
3278
+ // src/registry/hub-identities.ts
3279
+ import { randomBytes as randomBytes2, createHash } from "crypto";
3280
+ var HUB_IDENTITIES_SCHEMA = `
3281
+ CREATE TABLE IF NOT EXISTS hub_identities (
3282
+ email TEXT PRIMARY KEY,
3283
+ agent_id TEXT NOT NULL UNIQUE,
3284
+ public_key TEXT NOT NULL,
3285
+ encrypted_private_key TEXT NOT NULL,
3286
+ kdf_salt TEXT NOT NULL,
3287
+ display_name TEXT NOT NULL,
3288
+ created_at TEXT NOT NULL
3289
+ );
3290
+
3291
+ CREATE INDEX IF NOT EXISTS idx_hub_identities_agent_id
3292
+ ON hub_identities(agent_id);
3293
+ `;
3294
+ var CHALLENGES_SCHEMA = `
3295
+ CREATE TABLE IF NOT EXISTS hub_challenges (
3296
+ challenge TEXT PRIMARY KEY,
3297
+ expires_at TEXT NOT NULL,
3298
+ consumed_at TEXT
3299
+ );
3300
+ `;
3301
+ function ensureHubIdentitiesTables(db) {
3302
+ db.exec(HUB_IDENTITIES_SCHEMA);
3303
+ db.exec(CHALLENGES_SCHEMA);
3304
+ }
3305
+ function deriveAgentId2(publicKeyHex) {
3306
+ const hash = createHash("sha256").update(publicKeyHex, "hex").digest("hex");
3307
+ return `agent-${hash.slice(0, 16)}`;
3308
+ }
3309
+ var CHALLENGE_TTL_MS = 10 * 60 * 1e3;
3310
+ function createChallenge(db) {
3311
+ const challenge = randomBytes2(32).toString("hex");
3312
+ const expires_at = new Date(Date.now() + CHALLENGE_TTL_MS).toISOString();
3313
+ db.prepare("INSERT INTO hub_challenges (challenge, expires_at) VALUES (?, ?)").run(challenge, expires_at);
3314
+ return { challenge, expires_at };
3315
+ }
3316
+ function consumeChallenge(db, challenge) {
3317
+ const row = db.prepare("SELECT expires_at, consumed_at FROM hub_challenges WHERE challenge = ?").get(challenge);
3318
+ if (!row) return false;
3319
+ if (row.consumed_at) return false;
3320
+ if (new Date(row.expires_at).getTime() < Date.now()) return false;
3321
+ const consumed_at = (/* @__PURE__ */ new Date()).toISOString();
3322
+ db.prepare("UPDATE hub_challenges SET consumed_at = ? WHERE challenge = ?").run(consumed_at, challenge);
3323
+ return true;
3324
+ }
3325
+ function pruneChallenges(db) {
3326
+ const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1e3).toISOString();
3327
+ db.prepare("DELETE FROM hub_challenges WHERE expires_at < ? OR consumed_at IS NOT NULL").run(cutoff);
3328
+ }
3329
+ function registerHubIdentity(db, input) {
3330
+ const agent_id = deriveAgentId2(input.public_key);
3331
+ const created_at = (/* @__PURE__ */ new Date()).toISOString();
3332
+ db.prepare(`
3333
+ INSERT INTO hub_identities (email, agent_id, public_key, encrypted_private_key, kdf_salt, display_name, created_at)
3334
+ VALUES (?, ?, ?, ?, ?, ?, ?)
3335
+ `).run(input.email, agent_id, input.public_key, input.encrypted_private_key, input.kdf_salt, input.display_name, created_at);
3336
+ return { ...input, agent_id, created_at };
3337
+ }
3338
+ function getHubIdentityByEmail(db, email) {
3339
+ const row = db.prepare("SELECT * FROM hub_identities WHERE email = ?").get(email);
3340
+ return row ?? null;
3341
+ }
3342
+ function getHubIdentityByAgentId(db, agent_id) {
3343
+ const row = db.prepare("SELECT * FROM hub_identities WHERE agent_id = ?").get(agent_id);
3344
+ return row ?? null;
3345
+ }
3346
+
3268
3347
  // src/registry/free-tier.ts
3269
3348
  function initFreeTierTable(db) {
3270
3349
  db.exec(`
@@ -3362,6 +3441,39 @@ async function creditRoutesPlugin(fastify, options) {
3362
3441
  const transactions = getTransactions(creditDb, owner, { limit, after: since });
3363
3442
  return reply.send({ owner, transactions, limit });
3364
3443
  });
3444
+ fastify.get("/api/credits/escrow/:id", {
3445
+ schema: {
3446
+ tags: ["credits"],
3447
+ summary: "Get escrow status by ID (public, no auth required)",
3448
+ params: {
3449
+ type: "object",
3450
+ properties: { id: { type: "string" } },
3451
+ required: ["id"]
3452
+ },
3453
+ response: {
3454
+ 200: {
3455
+ type: "object",
3456
+ properties: {
3457
+ id: { type: "string" },
3458
+ owner: { type: "string" },
3459
+ amount: { type: "number" },
3460
+ card_id: { type: "string" },
3461
+ status: { type: "string" },
3462
+ created_at: { type: "string" },
3463
+ settled_at: { type: ["string", "null"] }
3464
+ }
3465
+ },
3466
+ 404: { type: "object", properties: { error: { type: "string" } } }
3467
+ }
3468
+ }
3469
+ }, async (request, reply) => {
3470
+ const { id } = request.params;
3471
+ const escrow = getEscrowStatus(creditDb, id);
3472
+ if (!escrow) {
3473
+ return reply.code(404).send({ error: "Escrow record not found" });
3474
+ }
3475
+ return reply.send(escrow);
3476
+ });
3365
3477
  await fastify.register(async (scope) => {
3366
3478
  identityAuthPlugin(scope, { agentDb: creditDb });
3367
3479
  scope.post("/api/credits/hold", {
@@ -5273,6 +5385,121 @@ function createRegistryServer(opts) {
5273
5385
  throw err;
5274
5386
  }
5275
5387
  });
5388
+ ensureHubIdentitiesTables(db);
5389
+ try {
5390
+ pruneChallenges(db);
5391
+ } catch {
5392
+ }
5393
+ api.get("/api/agents/challenge", {
5394
+ schema: {
5395
+ tags: ["hub-auth"],
5396
+ summary: "Get a registration challenge",
5397
+ response: {
5398
+ 200: {
5399
+ type: "object",
5400
+ properties: {
5401
+ challenge: { type: "string" },
5402
+ expires_at: { type: "string" }
5403
+ }
5404
+ }
5405
+ }
5406
+ }
5407
+ }, async (_request, reply) => {
5408
+ const { challenge, expires_at } = createChallenge(db);
5409
+ return reply.send({ challenge, expires_at });
5410
+ });
5411
+ api.post("/api/agents/register", {
5412
+ schema: {
5413
+ tags: ["hub-auth"],
5414
+ summary: "Register a new Hub-managed agent identity",
5415
+ body: {
5416
+ type: "object",
5417
+ required: ["email", "public_key", "encrypted_private_key", "kdf_salt", "display_name", "challenge", "signature"],
5418
+ properties: {
5419
+ email: { type: "string", format: "email" },
5420
+ public_key: { type: "string" },
5421
+ encrypted_private_key: { type: "string" },
5422
+ kdf_salt: { type: "string" },
5423
+ display_name: { type: "string" },
5424
+ challenge: { type: "string" },
5425
+ signature: { type: "string" }
5426
+ }
5427
+ },
5428
+ response: {
5429
+ 201: { type: "object", additionalProperties: true },
5430
+ 400: { type: "object", properties: { error: { type: "string" } } },
5431
+ 409: { type: "object", properties: { error: { type: "string" } } }
5432
+ }
5433
+ }
5434
+ }, async (request, reply) => {
5435
+ const body = request.body;
5436
+ if (!consumeChallenge(db, body.challenge)) {
5437
+ return reply.code(400).send({ error: "Invalid or expired challenge" });
5438
+ }
5439
+ if (!/^[0-9a-fA-F]+$/.test(body.public_key) || body.public_key.length % 2 !== 0) {
5440
+ return reply.code(400).send({ error: "Invalid public_key format" });
5441
+ }
5442
+ try {
5443
+ const { verifyEscrowReceipt: verifyEscrowReceipt2 } = await import("./signing-AQTKYJDB.js");
5444
+ const publicKeyBuffer = Buffer.from(body.public_key, "hex");
5445
+ const valid = verifyEscrowReceipt2({ challenge: body.challenge }, body.signature, publicKeyBuffer);
5446
+ if (!valid) {
5447
+ return reply.code(400).send({ error: "Invalid signature" });
5448
+ }
5449
+ } catch (err) {
5450
+ const msg = err instanceof Error ? err.message : String(err);
5451
+ return reply.code(400).send({ error: `Signature verification failed: ${msg}` });
5452
+ }
5453
+ const existing = getHubIdentityByEmail(db, body.email.toLowerCase());
5454
+ if (existing) {
5455
+ return reply.code(409).send({ error: "Email already registered" });
5456
+ }
5457
+ const agent_id = deriveAgentId2(body.public_key);
5458
+ const existingByAgentId = getHubIdentityByAgentId(db, agent_id);
5459
+ if (existingByAgentId) {
5460
+ return reply.code(409).send({ error: "Agent already registered" });
5461
+ }
5462
+ const identity = registerHubIdentity(db, {
5463
+ email: body.email.toLowerCase(),
5464
+ public_key: body.public_key,
5465
+ encrypted_private_key: body.encrypted_private_key,
5466
+ kdf_salt: body.kdf_salt,
5467
+ display_name: body.display_name
5468
+ });
5469
+ return reply.code(201).send({
5470
+ agent_id: identity.agent_id,
5471
+ did: `did:agentbnb:${identity.agent_id}`,
5472
+ created_at: identity.created_at
5473
+ });
5474
+ });
5475
+ api.post("/api/agents/login", {
5476
+ schema: {
5477
+ tags: ["hub-auth"],
5478
+ summary: "Fetch encrypted identity blob for login",
5479
+ body: {
5480
+ type: "object",
5481
+ required: ["email"],
5482
+ properties: { email: { type: "string", format: "email" } }
5483
+ },
5484
+ response: {
5485
+ 200: { type: "object", additionalProperties: true },
5486
+ 404: { type: "object", properties: { error: { type: "string" } } }
5487
+ }
5488
+ }
5489
+ }, async (request, reply) => {
5490
+ const body = request.body;
5491
+ const identity = getHubIdentityByEmail(db, body.email.toLowerCase());
5492
+ if (!identity) {
5493
+ return reply.code(404).send({ error: "Identity not found" });
5494
+ }
5495
+ return reply.send({
5496
+ agent_id: identity.agent_id,
5497
+ public_key: identity.public_key,
5498
+ encrypted_private_key: identity.encrypted_private_key,
5499
+ kdf_salt: identity.kdf_salt,
5500
+ display_name: identity.display_name
5501
+ });
5502
+ });
5276
5503
  api.post("/api/identity/link", {
5277
5504
  schema: {
5278
5505
  tags: ["identity"],
@@ -5572,7 +5799,7 @@ function createRegistryServer(opts) {
5572
5799
  });
5573
5800
  await relayClient.connect();
5574
5801
  }
5575
- const { requestViaRelay } = await import("./client-XOSXFC7Q.js");
5802
+ const { requestViaRelay } = await import("./client-KL67WZVJ.js");
5576
5803
  return requestViaRelay(relayClient, {
5577
5804
  targetOwner: target.owner,
5578
5805
  cardId: target.cardId,
@@ -5591,12 +5818,24 @@ function createRegistryServer(opts) {
5591
5818
  const ownerApiKey = opts.ownerApiKey;
5592
5819
  const ownerName = opts.ownerName;
5593
5820
  void api.register(async (ownerRoutes) => {
5594
- ownerRoutes.addHook("onRequest", async (request, reply) => {
5821
+ ownerRoutes.addHook("preHandler", async (request, reply) => {
5595
5822
  const auth = request.headers.authorization;
5596
5823
  const token = auth?.startsWith("Bearer ") ? auth.slice(7).trim() : null;
5597
- if (!token || token !== ownerApiKey) {
5598
- return reply.status(401).send({ error: "Unauthorized" });
5824
+ if (token === ownerApiKey) {
5825
+ request.agentId = ownerName;
5826
+ return;
5827
+ }
5828
+ const didResult = await tryVerifyIdentity(request, {});
5829
+ if (didResult.valid) {
5830
+ const hubIdentity = getHubIdentityByAgentId(db, didResult.agentId);
5831
+ if (!hubIdentity) {
5832
+ return reply.status(401).send({ error: "Agent not registered on this Hub" });
5833
+ }
5834
+ request.agentId = didResult.agentId;
5835
+ request.agentPublicKey = didResult.publicKey;
5836
+ return;
5599
5837
  }
5838
+ return reply.status(401).send({ error: "Unauthorized" });
5600
5839
  });
5601
5840
  ownerRoutes.get("/me", {
5602
5841
  schema: {
@@ -5607,13 +5846,14 @@ function createRegistryServer(opts) {
5607
5846
  200: { type: "object", properties: { owner: { type: "string" }, balance: { type: "number" } } }
5608
5847
  }
5609
5848
  }
5610
- }, async (_request, reply) => {
5849
+ }, async (request, reply) => {
5850
+ const identity = request.agentId ?? ownerName;
5611
5851
  let balance = 0;
5612
5852
  if (opts.creditDb) {
5613
5853
  const ledger = createLedger({ db: opts.creditDb });
5614
- balance = await ledger.getBalance(ownerName);
5854
+ balance = await ledger.getBalance(identity);
5615
5855
  }
5616
- return reply.send({ owner: ownerName, balance });
5856
+ return reply.send({ owner: identity, balance });
5617
5857
  });
5618
5858
  ownerRoutes.get("/requests", {
5619
5859
  schema: {
@@ -6064,6 +6304,7 @@ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
6064
6304
  import { join as join2 } from "path";
6065
6305
  import { randomUUID as randomUUID8 } from "crypto";
6066
6306
  import { Cron as Cron2 } from "croner";
6307
+ var STARTUP_SYNC_BUDGET_MS = 3e3;
6067
6308
  function buildFallbackRelayCard(owner) {
6068
6309
  return {
6069
6310
  id: randomUUID8(),
@@ -6235,7 +6476,7 @@ var ServiceCoordinator = class {
6235
6476
  console.log("Conductor mode enabled \u2014 orchestrate/plan skills available via gateway");
6236
6477
  }
6237
6478
  if (opts.conductorEnabled && this.config.conductor?.public) {
6238
- const { buildConductorCard } = await import("./card-UF465O7O.js");
6479
+ const { buildConductorCard } = await import("./card-L3ZPPBVI.js");
6239
6480
  const conductorCard = attachCanonicalAgentId(
6240
6481
  this.runtime.registryDb,
6241
6482
  buildConductorCard(this.config.owner)
@@ -6267,11 +6508,28 @@ var ServiceCoordinator = class {
6267
6508
  this.runtime.registerJob(idleJob);
6268
6509
  console.log("IdleMonitor started (60s poll interval, 70% idle threshold)");
6269
6510
  if (this.config.registry) {
6270
- const startupSync = await syncCreditsFromRegistry(this.config, this.runtime.creditDb);
6271
- if (startupSync.synced) {
6272
- console.log(`[agentbnb] credits synced: ${startupSync.remoteBalance} (was ${startupSync.localWas})`);
6511
+ if (shouldSkipNetwork()) {
6512
+ console.warn("[agentbnb] credit sync skipped: test/offline mode");
6273
6513
  } else {
6274
- console.warn(`[agentbnb] credit sync skipped: ${startupSync.error}`);
6514
+ const reachable = await probeRegistry(this.config.registry);
6515
+ if (!reachable) {
6516
+ console.warn("[agentbnb] credit sync skipped: registry unreachable (will retry every 5m)");
6517
+ } else {
6518
+ try {
6519
+ const startupSync = await withTimeout(
6520
+ syncCreditsFromRegistry(this.config, this.runtime.creditDb),
6521
+ STARTUP_SYNC_BUDGET_MS
6522
+ );
6523
+ if (startupSync.synced) {
6524
+ console.log(`[agentbnb] credits synced: ${startupSync.remoteBalance} (was ${startupSync.localWas})`);
6525
+ } else {
6526
+ console.warn(`[agentbnb] credit sync skipped: ${startupSync.error}`);
6527
+ }
6528
+ } catch (err) {
6529
+ const reason = err instanceof TimeoutError ? `timeout after ${STARTUP_SYNC_BUDGET_MS}ms` : err.message;
6530
+ console.warn(`[agentbnb] credit sync skipped: ${reason} (will retry every 5m)`);
6531
+ }
6532
+ }
6275
6533
  }
6276
6534
  this.creditSyncJob = new Cron2("*/5 * * * *", async () => {
6277
6535
  const result = await syncCreditsFromRegistry(this.config, this.runtime.creditDb);
@@ -6312,7 +6570,7 @@ var ServiceCoordinator = class {
6312
6570
  }
6313
6571
  if (opts.registryUrl && opts.relay) {
6314
6572
  const { RelayClient } = await import("./websocket-client-FCPZOE4S.js");
6315
- const { executeCapabilityRequest: executeCapabilityRequest2 } = await import("./execute-UFMGTXET.js");
6573
+ const { executeCapabilityRequest: executeCapabilityRequest2 } = await import("./execute-R5STYWLD.js");
6316
6574
  const localCards = listCards(this.runtime.registryDb, this.config.owner);
6317
6575
  const { primaryCard, additionalCards } = buildRelayRegistrationCards(this.config.owner, localCards);
6318
6576
  if (this.config.conductor?.public) {