agentbnb 4.0.1 → 4.0.4

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 (47) hide show
  1. package/README.md +33 -2
  2. package/dist/{card-4XH4AOTE.js → card-RNEWSAQ6.js} +1 -1
  3. package/dist/card-RSGDCHCV.js +88 -0
  4. package/dist/{chunk-MQKYGY5I.js → chunk-4P3EMGL4.js} +3 -3
  5. package/dist/{chunk-DVAS2443.js → chunk-5KFI5X7B.js} +1 -1
  6. package/dist/{chunk-Q7HRI666.js → chunk-5QGXARLJ.js} +8 -6
  7. package/dist/{chunk-3UKAVIMC.js → chunk-BH6WGYFB.js} +4 -4
  8. package/dist/{chunk-XQHN6ITI.js → chunk-DNWT5FZQ.js} +22 -2
  9. package/dist/chunk-EVBX22YU.js +68 -0
  10. package/dist/{chunk-QJEOCKVF.js → chunk-FF226TIV.js} +1 -1
  11. package/dist/{chunk-6K5WUVF3.js → chunk-GGYC5U2Z.js} +4 -4
  12. package/dist/{chunk-ODBGCCEH.js → chunk-HH24WMFN.js} +18 -3
  13. package/dist/chunk-JXEOE7HX.js +295 -0
  14. package/dist/{chunk-M3G5NR2Z.js → chunk-QITOPASZ.js} +8 -2
  15. package/dist/{chunk-TLU7ALCZ.js → chunk-T7NS2J2B.js} +1 -1
  16. package/dist/chunk-UB2NPFC7.js +165 -0
  17. package/dist/{chunk-FNKBHBYK.js → chunk-WGZ5AGOX.js} +37 -3
  18. package/dist/{chunk-KJG2UJV5.js → chunk-XND2DWTZ.js} +3 -2
  19. package/dist/cli/index.d.ts +1 -0
  20. package/dist/cli/index.js +406 -135
  21. package/dist/{client-BTPIFY7E.js → client-T5MTY3CS.js} +3 -3
  22. package/dist/conduct-GZQNFTRP.js +19 -0
  23. package/dist/{conduct-CW62HBPT.js → conduct-N52JX7RT.js} +9 -9
  24. package/dist/conductor-mode-ESGFZ6T5.js +739 -0
  25. package/dist/{conductor-mode-3JS4VWCR.js → conductor-mode-XUWGR4ZE.js} +7 -7
  26. package/dist/execute-QH6F54D7.js +10 -0
  27. package/dist/index.d.ts +151 -2
  28. package/dist/index.js +135 -67
  29. package/dist/peers-E4MKNNDN.js +12 -0
  30. package/dist/{request-CNZ3XIVX.js → request-4GQSSM4B.js} +8 -8
  31. package/dist/{serve-skill-SUOGUM7N.js → serve-skill-Q6NHX2RA.js} +5 -5
  32. package/dist/{server-2LWHL24P.js → server-B5E566CI.js} +10 -10
  33. package/dist/skills/agentbnb/bootstrap.js +2001 -0
  34. package/openclaw.plugin.json +54 -0
  35. package/package.json +9 -6
  36. package/skills/agentbnb/HEARTBEAT.rules.md +47 -0
  37. package/skills/agentbnb/SKILL.md +166 -0
  38. package/skills/agentbnb/auto-request.ts +14 -0
  39. package/skills/agentbnb/auto-share.ts +10 -0
  40. package/skills/agentbnb/bootstrap.test.ts +323 -0
  41. package/skills/agentbnb/bootstrap.ts +126 -0
  42. package/skills/agentbnb/credit-mgr.ts +11 -0
  43. package/skills/agentbnb/gateway.ts +12 -0
  44. package/skills/agentbnb/install.sh +210 -0
  45. package/dist/conduct-FXLVGKD5.js +0 -19
  46. package/dist/execute-EXOITLHN.js +0 -10
  47. package/dist/types-FGBUZ3QV.js +0 -18
@@ -3,18 +3,18 @@ import {
3
3
  decompose,
4
4
  matchSubTasks,
5
5
  orchestrate
6
- } from "./chunk-MQKYGY5I.js";
6
+ } from "./chunk-4P3EMGL4.js";
7
7
  import "./chunk-3MJT4PZG.js";
8
8
  import {
9
9
  BudgetManager
10
- } from "./chunk-6K5WUVF3.js";
11
- import "./chunk-QJEOCKVF.js";
12
- import "./chunk-KJG2UJV5.js";
10
+ } from "./chunk-GGYC5U2Z.js";
11
+ import "./chunk-FF226TIV.js";
12
+ import "./chunk-XND2DWTZ.js";
13
13
  import "./chunk-5AH3CMOX.js";
14
14
  import "./chunk-75OC6E4F.js";
15
- import "./chunk-XQHN6ITI.js";
16
- import "./chunk-DVAS2443.js";
17
- import "./chunk-FNKBHBYK.js";
15
+ import "./chunk-DNWT5FZQ.js";
16
+ import "./chunk-5KFI5X7B.js";
17
+ import "./chunk-WGZ5AGOX.js";
18
18
 
19
19
  // src/conductor/conductor-mode.ts
20
20
  var ConductorMode = class {
@@ -0,0 +1,10 @@
1
+ import {
2
+ executeCapabilityRequest
3
+ } from "./chunk-5QGXARLJ.js";
4
+ import "./chunk-T7NS2J2B.js";
5
+ import "./chunk-DNWT5FZQ.js";
6
+ import "./chunk-5KFI5X7B.js";
7
+ import "./chunk-WGZ5AGOX.js";
8
+ export {
9
+ executeCapabilityRequest
10
+ };
package/dist/index.d.ts CHANGED
@@ -220,6 +220,8 @@ declare const CapabilityCardV2Schema: z.ZodObject<{
220
220
  owner: z.ZodString;
221
221
  /** Agent display name — was 'name' in v1.0. */
222
222
  agent_name: z.ZodString;
223
+ /** Short one-liner shown in Hub v2 Identity Header. */
224
+ short_description: z.ZodOptional<z.ZodString>;
223
225
  /** At least one skill is required. */
224
226
  skills: z.ZodArray<z.ZodObject<{
225
227
  /** Stable skill identifier, e.g. 'tts-elevenlabs'. Used for gateway routing and idle tracking. */
@@ -443,6 +445,97 @@ declare const CapabilityCardV2Schema: z.ZodObject<{
443
445
  runtime: string;
444
446
  region?: string | undefined;
445
447
  }>>;
448
+ /** Suitability metadata for Hub v2 profile and future routing warnings. */
449
+ suitability: z.ZodOptional<z.ZodObject<{
450
+ /** Use cases this agent/skill is optimised for. */
451
+ ideal_for: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
452
+ /** Scenarios this agent/skill cannot reliably handle. */
453
+ not_suitable_for: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
454
+ /** Domains explicitly excluded (used for routing exclusions in later phases). */
455
+ excluded_domains: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
456
+ /** Conditions that increase failure risk, shown as warnings in the Hub. */
457
+ risk_conditions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
458
+ /** Recommended alternative when this agent is unsuitable. */
459
+ fallback_recommendation: z.ZodOptional<z.ZodString>;
460
+ }, "strip", z.ZodTypeAny, {
461
+ ideal_for?: string[] | undefined;
462
+ not_suitable_for?: string[] | undefined;
463
+ excluded_domains?: string[] | undefined;
464
+ risk_conditions?: string[] | undefined;
465
+ fallback_recommendation?: string | undefined;
466
+ }, {
467
+ ideal_for?: string[] | undefined;
468
+ not_suitable_for?: string[] | undefined;
469
+ excluded_domains?: string[] | undefined;
470
+ risk_conditions?: string[] | undefined;
471
+ fallback_recommendation?: string | undefined;
472
+ }>>;
473
+ /** Learning signals — self-declared limitations, improvements, critiques. */
474
+ learning: z.ZodOptional<z.ZodObject<{
475
+ /** Known limitations that may affect reliability (self-declared). */
476
+ known_limitations: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
477
+ /** Common failure patterns observed by the provider. */
478
+ common_failure_patterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
479
+ /** Version-tagged improvements the provider has shipped. */
480
+ recent_improvements: z.ZodOptional<z.ZodArray<z.ZodObject<{
481
+ version: z.ZodString;
482
+ summary: z.ZodString;
483
+ timestamp: z.ZodString;
484
+ }, "strip", z.ZodTypeAny, {
485
+ version: string;
486
+ summary: string;
487
+ timestamp: string;
488
+ }, {
489
+ version: string;
490
+ summary: string;
491
+ timestamp: string;
492
+ }>, "many">>;
493
+ /** Structured critiques from external sources (phase 2+). */
494
+ critiques: z.ZodOptional<z.ZodArray<z.ZodObject<{
495
+ type: z.ZodLiteral<"structured">;
496
+ summary: z.ZodString;
497
+ source_tier: z.ZodString;
498
+ timestamp: z.ZodString;
499
+ }, "strip", z.ZodTypeAny, {
500
+ type: "structured";
501
+ summary: string;
502
+ timestamp: string;
503
+ source_tier: string;
504
+ }, {
505
+ type: "structured";
506
+ summary: string;
507
+ timestamp: string;
508
+ source_tier: string;
509
+ }>, "many">>;
510
+ }, "strip", z.ZodTypeAny, {
511
+ known_limitations?: string[] | undefined;
512
+ common_failure_patterns?: string[] | undefined;
513
+ recent_improvements?: {
514
+ version: string;
515
+ summary: string;
516
+ timestamp: string;
517
+ }[] | undefined;
518
+ critiques?: {
519
+ type: "structured";
520
+ summary: string;
521
+ timestamp: string;
522
+ source_tier: string;
523
+ }[] | undefined;
524
+ }, {
525
+ known_limitations?: string[] | undefined;
526
+ common_failure_patterns?: string[] | undefined;
527
+ recent_improvements?: {
528
+ version: string;
529
+ summary: string;
530
+ timestamp: string;
531
+ }[] | undefined;
532
+ critiques?: {
533
+ type: "structured";
534
+ summary: string;
535
+ timestamp: string;
536
+ source_tier: string;
537
+ }[] | undefined;
538
+ }>>;
446
539
  /**
447
540
  * Private per-card metadata. Stripped from all API and CLI responses —
448
541
  * never transmitted beyond the local store.
@@ -509,10 +602,33 @@ declare const CapabilityCardV2Schema: z.ZodObject<{
509
602
  gateway_url?: string | undefined;
510
603
  created_at?: string | undefined;
511
604
  updated_at?: string | undefined;
605
+ short_description?: string | undefined;
512
606
  environment?: {
513
607
  runtime: string;
514
608
  region?: string | undefined;
515
609
  } | undefined;
610
+ suitability?: {
611
+ ideal_for?: string[] | undefined;
612
+ not_suitable_for?: string[] | undefined;
613
+ excluded_domains?: string[] | undefined;
614
+ risk_conditions?: string[] | undefined;
615
+ fallback_recommendation?: string | undefined;
616
+ } | undefined;
617
+ learning?: {
618
+ known_limitations?: string[] | undefined;
619
+ common_failure_patterns?: string[] | undefined;
620
+ recent_improvements?: {
621
+ version: string;
622
+ summary: string;
623
+ timestamp: string;
624
+ }[] | undefined;
625
+ critiques?: {
626
+ type: "structured";
627
+ summary: string;
628
+ timestamp: string;
629
+ source_tier: string;
630
+ }[] | undefined;
631
+ } | undefined;
516
632
  }, {
517
633
  spec_version: "2.0";
518
634
  id: string;
@@ -570,10 +686,33 @@ declare const CapabilityCardV2Schema: z.ZodObject<{
570
686
  gateway_url?: string | undefined;
571
687
  created_at?: string | undefined;
572
688
  updated_at?: string | undefined;
689
+ short_description?: string | undefined;
573
690
  environment?: {
574
691
  runtime: string;
575
692
  region?: string | undefined;
576
693
  } | undefined;
694
+ suitability?: {
695
+ ideal_for?: string[] | undefined;
696
+ not_suitable_for?: string[] | undefined;
697
+ excluded_domains?: string[] | undefined;
698
+ risk_conditions?: string[] | undefined;
699
+ fallback_recommendation?: string | undefined;
700
+ } | undefined;
701
+ learning?: {
702
+ known_limitations?: string[] | undefined;
703
+ common_failure_patterns?: string[] | undefined;
704
+ recent_improvements?: {
705
+ version: string;
706
+ summary: string;
707
+ timestamp: string;
708
+ }[] | undefined;
709
+ critiques?: {
710
+ type: "structured";
711
+ summary: string;
712
+ timestamp: string;
713
+ source_tier: string;
714
+ }[] | undefined;
715
+ } | undefined;
577
716
  }>;
578
717
  type CapabilityCardV2 = z.infer<typeof CapabilityCardV2Schema>;
579
718
  /**
@@ -2859,7 +2998,10 @@ type ErrorMessage = z.infer<typeof ErrorMessageSchema>;
2859
2998
  type RelayMessage = z.infer<typeof RelayMessageSchema>;
2860
2999
  /** Pending relay request tracking */
2861
3000
  interface PendingRelayRequest {
3001
+ /** Connection key used to route the response back (may be a synthetic ID) */
2862
3002
  originOwner: string;
3003
+ /** Actual agent owner for credit operations (defaults to originOwner) */
3004
+ creditOwner?: string;
2863
3005
  timeout: ReturnType<typeof setTimeout>;
2864
3006
  /** Escrow ID for the credit hold, if credits were reserved for this request */
2865
3007
  escrowId?: string;
@@ -3157,21 +3299,21 @@ declare const EscrowReceiptSchema: z.ZodObject<{
3157
3299
  nonce: z.ZodString;
3158
3300
  signature: z.ZodString;
3159
3301
  }, "strip", z.ZodTypeAny, {
3302
+ timestamp: string;
3160
3303
  signature: string;
3161
3304
  requester_owner: string;
3162
3305
  requester_public_key: string;
3163
3306
  amount: number;
3164
3307
  card_id: string;
3165
- timestamp: string;
3166
3308
  nonce: string;
3167
3309
  skill_id?: string | undefined;
3168
3310
  }, {
3311
+ timestamp: string;
3169
3312
  signature: string;
3170
3313
  requester_owner: string;
3171
3314
  requester_public_key: string;
3172
3315
  amount: number;
3173
3316
  card_id: string;
3174
- timestamp: string;
3175
3317
  nonce: string;
3176
3318
  skill_id?: string | undefined;
3177
3319
  }>;
@@ -3709,6 +3851,11 @@ interface ExecuteRequestOptions {
3709
3851
  timeoutMs?: number;
3710
3852
  /** Optional progress callback forwarded to SkillExecutor during execution. */
3711
3853
  onProgress?: ProgressCallback;
3854
+ /**
3855
+ * When true, skip local credit check and escrow management.
3856
+ * Used for relay-routed requests where the Hub relay has already held credits.
3857
+ */
3858
+ relayAuthorized?: boolean;
3712
3859
  }
3713
3860
  /**
3714
3861
  * Result of a capability execution.
@@ -3749,6 +3896,8 @@ interface RelayRequestOptions {
3749
3896
  escrowReceipt?: EscrowReceipt;
3750
3897
  /** Timeout in milliseconds. Default 30000. */
3751
3898
  timeoutMs?: number;
3899
+ /** Actual requester owner for credit tracking (defaults to relay client's owner). */
3900
+ requester?: string;
3752
3901
  }
3753
3902
  /**
3754
3903
  * Sends a capability request to another agent via the WebSocket relay.
package/dist/index.js CHANGED
@@ -83,12 +83,45 @@ var SkillSchema = z.object({
83
83
  */
84
84
  _internal: z.record(z.unknown()).optional()
85
85
  });
86
+ var SuitabilitySchema = z.object({
87
+ /** Use cases this agent/skill is optimised for. */
88
+ ideal_for: z.array(z.string()).optional(),
89
+ /** Scenarios this agent/skill cannot reliably handle. */
90
+ not_suitable_for: z.array(z.string()).optional(),
91
+ /** Domains explicitly excluded (used for routing exclusions in later phases). */
92
+ excluded_domains: z.array(z.string()).optional(),
93
+ /** Conditions that increase failure risk, shown as warnings in the Hub. */
94
+ risk_conditions: z.array(z.string()).optional(),
95
+ /** Recommended alternative when this agent is unsuitable. */
96
+ fallback_recommendation: z.string().optional()
97
+ });
98
+ var LearningSchema = z.object({
99
+ /** Known limitations that may affect reliability (self-declared). */
100
+ known_limitations: z.array(z.string()).optional(),
101
+ /** Common failure patterns observed by the provider. */
102
+ common_failure_patterns: z.array(z.string()).optional(),
103
+ /** Version-tagged improvements the provider has shipped. */
104
+ recent_improvements: z.array(z.object({
105
+ version: z.string(),
106
+ summary: z.string(),
107
+ timestamp: z.string()
108
+ })).optional(),
109
+ /** Structured critiques from external sources (phase 2+). */
110
+ critiques: z.array(z.object({
111
+ type: z.literal("structured"),
112
+ summary: z.string(),
113
+ source_tier: z.string(),
114
+ timestamp: z.string()
115
+ })).optional()
116
+ });
86
117
  var CapabilityCardV2Schema = z.object({
87
118
  spec_version: z.literal("2.0"),
88
119
  id: z.string().uuid(),
89
120
  owner: z.string().min(1),
90
121
  /** Agent display name — was 'name' in v1.0. */
91
122
  agent_name: z.string().min(1).max(100),
123
+ /** Short one-liner shown in Hub v2 Identity Header. */
124
+ short_description: z.string().max(200).optional(),
92
125
  /** At least one skill is required. */
93
126
  skills: z.array(SkillSchema).min(1),
94
127
  availability: z.object({
@@ -100,6 +133,10 @@ var CapabilityCardV2Schema = z.object({
100
133
  runtime: z.string(),
101
134
  region: z.string().optional()
102
135
  }).optional(),
136
+ /** Suitability metadata for Hub v2 profile and future routing warnings. */
137
+ suitability: SuitabilitySchema.optional(),
138
+ /** Learning signals — self-declared limitations, improvements, critiques. */
139
+ learning: LearningSchema.optional(),
103
140
  /**
104
141
  * Private per-card metadata. Stripped from all API and CLI responses —
105
142
  * never transmitted beyond the local store.
@@ -760,7 +797,8 @@ async function executeCapabilityRequest(opts) {
760
797
  skillExecutor,
761
798
  handlerUrl,
762
799
  timeoutMs = 3e5,
763
- onProgress
800
+ onProgress,
801
+ relayAuthorized = false
764
802
  } = opts;
765
803
  const card = getCard(registryDb, cardId);
766
804
  if (!card) {
@@ -785,7 +823,8 @@ async function executeCapabilityRequest(opts) {
785
823
  }
786
824
  let escrowId = null;
787
825
  let isRemoteEscrow = false;
788
- if (receipt) {
826
+ if (relayAuthorized) {
827
+ } else if (receipt) {
789
828
  const { signature, ...receiptData2 } = receipt;
790
829
  const publicKeyBuf = Buffer.from(receipt.requester_public_key, "hex");
791
830
  const valid = verifyEscrowReceipt(receiptData2, signature, publicKeyBuf);
@@ -1968,6 +2007,7 @@ async function requestViaRelay(relay, opts) {
1968
2007
  cardId: opts.cardId,
1969
2008
  skillId: opts.skillId,
1970
2009
  params: opts.params ?? {},
2010
+ requester: opts.requester,
1971
2011
  escrowReceipt: opts.escrowReceipt,
1972
2012
  timeoutMs: opts.timeoutMs
1973
2013
  });
@@ -2760,7 +2800,13 @@ function verifyAgentCertificate(cert) {
2760
2800
  }
2761
2801
  function ensureIdentity(configDir, owner) {
2762
2802
  const existing = loadIdentity(configDir);
2763
- if (existing) return existing;
2803
+ if (existing) {
2804
+ if (existing.owner !== owner) {
2805
+ existing.owner = owner;
2806
+ saveIdentity(configDir, existing);
2807
+ }
2808
+ return existing;
2809
+ }
2764
2810
  return createIdentity(configDir, owner);
2765
2811
  }
2766
2812
 
@@ -3216,14 +3262,27 @@ function lookupCardPrice(registryDb, cardId, skillId) {
3216
3262
  } catch {
3217
3263
  return null;
3218
3264
  }
3219
- if (skillId && Array.isArray(card.skills)) {
3265
+ if (Array.isArray(card.skills) && card.skills.length > 0) {
3220
3266
  const skills = card.skills;
3221
- const skill = skills.find((s) => s.id === skillId);
3222
- if (skill) {
3223
- const skillPricing = skill.pricing;
3224
- if (skillPricing && typeof skillPricing.credits_per_call === "number") {
3225
- return skillPricing.credits_per_call;
3267
+ if (skillId) {
3268
+ const skill = skills.find((s) => s.id === skillId);
3269
+ if (skill) {
3270
+ const skillPricing = skill.pricing;
3271
+ if (skillPricing && typeof skillPricing.credits_per_call === "number") {
3272
+ return skillPricing.credits_per_call;
3273
+ }
3226
3274
  }
3275
+ } else {
3276
+ let minPrice = null;
3277
+ for (const s of skills) {
3278
+ const sp = s.pricing;
3279
+ if (sp && typeof sp.credits_per_call === "number" && sp.credits_per_call > 0) {
3280
+ if (minPrice === null || sp.credits_per_call < minPrice) {
3281
+ minPrice = sp.credits_per_call;
3282
+ }
3283
+ }
3284
+ }
3285
+ if (minPrice !== null) return minPrice;
3227
3286
  }
3228
3287
  }
3229
3288
  const pricing = card.pricing;
@@ -3401,7 +3460,13 @@ function registerWebSocketRelay(server, db, creditDb) {
3401
3460
  }
3402
3461
  }
3403
3462
  connections.set(owner, ws);
3404
- const cardId = upsertCard(card, owner);
3463
+ let cardId;
3464
+ try {
3465
+ cardId = upsertCard(card, owner);
3466
+ } catch (err) {
3467
+ console.error(`[relay] card validation failed for ${owner}:`, err instanceof Error ? err.message : err);
3468
+ cardId = card.id ?? owner;
3469
+ }
3405
3470
  const cardName = card.name ?? card.agent_name ?? owner;
3406
3471
  logAgentJoined(owner, cardName, cardId);
3407
3472
  if (msg.cards && msg.cards.length > 0) {
@@ -3441,12 +3506,13 @@ function registerWebSocketRelay(server, db, creditDb) {
3441
3506
  });
3442
3507
  return;
3443
3508
  }
3509
+ const creditOwner = msg.requester ?? fromOwner;
3444
3510
  let escrowId;
3445
3511
  if (creditDb) {
3446
3512
  try {
3447
3513
  const price = lookupCardPrice(db, msg.card_id, msg.skill_id);
3448
3514
  if (price !== null && price > 0) {
3449
- escrowId = holdForRelay(creditDb, fromOwner, price, msg.card_id);
3515
+ escrowId = holdForRelay(creditDb, creditOwner, price, msg.card_id);
3450
3516
  }
3451
3517
  } catch (err) {
3452
3518
  if (err instanceof AgentBnBError && err.code === "INSUFFICIENT_CREDITS") {
@@ -3476,7 +3542,7 @@ function registerWebSocketRelay(server, db, creditDb) {
3476
3542
  error: { code: -32603, message: "Relay request timeout" }
3477
3543
  });
3478
3544
  }, RELAY_TIMEOUT_MS);
3479
- pendingRequests.set(msg.id, { originOwner: fromOwner, timeout, escrowId, targetOwner: msg.target_owner });
3545
+ pendingRequests.set(msg.id, { originOwner: fromOwner, creditOwner, timeout, escrowId, targetOwner: msg.target_owner });
3480
3546
  sendMessage(targetWs, {
3481
3547
  type: "incoming_request",
3482
3548
  id: msg.id,
@@ -3564,7 +3630,7 @@ function registerWebSocketRelay(server, db, creditDb) {
3564
3630
  conductorFee = calculateConductorFee(totalCredits);
3565
3631
  if (conductorFee > 0) {
3566
3632
  try {
3567
- const feeEscrowId = holdForRelay(creditDb, pending.originOwner, conductorFee, msg.id);
3633
+ const feeEscrowId = holdForRelay(creditDb, pending.creditOwner ?? pending.originOwner, conductorFee, msg.id);
3568
3634
  settleForRelay(creditDb, feeEscrowId, pending.targetOwner);
3569
3635
  } catch (e) {
3570
3636
  console.error("[relay] conductor fee settlement failed (non-fatal):", e);
@@ -3620,60 +3686,62 @@ function registerWebSocketRelay(server, db, creditDb) {
3620
3686
  }
3621
3687
  }
3622
3688
  }
3623
- server.get("/ws", { websocket: true }, (rawSocket, _request) => {
3624
- const socket = rawSocket;
3625
- let registeredOwner;
3626
- socket.on("message", (raw) => {
3627
- void (async () => {
3628
- let data;
3629
- try {
3630
- data = JSON.parse(typeof raw === "string" ? raw : raw.toString("utf-8"));
3631
- } catch {
3632
- sendMessage(socket, { type: "error", code: "invalid_json", message: "Invalid JSON" });
3633
- return;
3634
- }
3635
- const parsed = RelayMessageSchema.safeParse(data);
3636
- if (!parsed.success) {
3637
- sendMessage(socket, {
3638
- type: "error",
3639
- code: "invalid_message",
3640
- message: `Invalid message: ${parsed.error.issues[0]?.message ?? "unknown error"}`
3641
- });
3642
- return;
3643
- }
3644
- const msg = parsed.data;
3645
- switch (msg.type) {
3646
- case "register":
3647
- registeredOwner = msg.owner;
3648
- handleRegister(socket, msg);
3649
- break;
3650
- case "relay_request":
3651
- if (!registeredOwner) {
3652
- sendMessage(socket, {
3653
- type: "error",
3654
- code: "not_registered",
3655
- message: "Must send register message before relay requests"
3656
- });
3657
- return;
3658
- }
3659
- await handleRelayRequest(socket, msg, registeredOwner);
3660
- break;
3661
- case "relay_response":
3662
- handleRelayResponse(msg);
3663
- break;
3664
- case "relay_progress":
3665
- handleRelayProgress(msg);
3666
- break;
3667
- default:
3668
- break;
3669
- }
3670
- })();
3671
- });
3672
- socket.on("close", () => {
3673
- handleDisconnect(registeredOwner);
3674
- });
3675
- socket.on("error", () => {
3676
- handleDisconnect(registeredOwner);
3689
+ void server.register(async (app) => {
3690
+ app.get("/ws", { websocket: true }, (rawSocket, _request) => {
3691
+ const socket = rawSocket;
3692
+ let registeredOwner;
3693
+ socket.on("message", (raw) => {
3694
+ void (async () => {
3695
+ let data;
3696
+ try {
3697
+ data = JSON.parse(typeof raw === "string" ? raw : raw.toString("utf-8"));
3698
+ } catch {
3699
+ sendMessage(socket, { type: "error", code: "invalid_json", message: "Invalid JSON" });
3700
+ return;
3701
+ }
3702
+ const parsed = RelayMessageSchema.safeParse(data);
3703
+ if (!parsed.success) {
3704
+ sendMessage(socket, {
3705
+ type: "error",
3706
+ code: "invalid_message",
3707
+ message: `Invalid message: ${parsed.error.issues[0]?.message ?? "unknown error"}`
3708
+ });
3709
+ return;
3710
+ }
3711
+ const msg = parsed.data;
3712
+ switch (msg.type) {
3713
+ case "register":
3714
+ registeredOwner = msg.owner;
3715
+ handleRegister(socket, msg);
3716
+ break;
3717
+ case "relay_request":
3718
+ if (!registeredOwner) {
3719
+ sendMessage(socket, {
3720
+ type: "error",
3721
+ code: "not_registered",
3722
+ message: "Must send register message before relay requests"
3723
+ });
3724
+ return;
3725
+ }
3726
+ await handleRelayRequest(socket, msg, registeredOwner);
3727
+ break;
3728
+ case "relay_response":
3729
+ handleRelayResponse(msg);
3730
+ break;
3731
+ case "relay_progress":
3732
+ handleRelayProgress(msg);
3733
+ break;
3734
+ default:
3735
+ break;
3736
+ }
3737
+ })();
3738
+ });
3739
+ socket.on("close", () => {
3740
+ handleDisconnect(registeredOwner);
3741
+ });
3742
+ socket.on("error", () => {
3743
+ handleDisconnect(registeredOwner);
3744
+ });
3677
3745
  });
3678
3746
  });
3679
3747
  return {
@@ -0,0 +1,12 @@
1
+ import {
2
+ findPeer,
3
+ loadPeers,
4
+ removePeer,
5
+ savePeer
6
+ } from "./chunk-EVBX22YU.js";
7
+ export {
8
+ findPeer,
9
+ loadPeers,
10
+ removePeer,
11
+ savePeer
12
+ };
@@ -1,28 +1,28 @@
1
1
  import {
2
2
  createLedger
3
- } from "./chunk-ODBGCCEH.js";
3
+ } from "./chunk-HH24WMFN.js";
4
4
  import {
5
5
  AutoRequestor,
6
6
  BudgetManager,
7
7
  DEFAULT_AUTONOMY_CONFIG,
8
8
  DEFAULT_BUDGET_CONFIG
9
- } from "./chunk-6K5WUVF3.js";
10
- import "./chunk-QJEOCKVF.js";
9
+ } from "./chunk-GGYC5U2Z.js";
10
+ import "./chunk-FF226TIV.js";
11
11
  import {
12
12
  requestCapability
13
- } from "./chunk-KJG2UJV5.js";
13
+ } from "./chunk-XND2DWTZ.js";
14
14
  import "./chunk-5AH3CMOX.js";
15
15
  import "./chunk-75OC6E4F.js";
16
16
  import {
17
17
  openDatabase
18
- } from "./chunk-TLU7ALCZ.js";
18
+ } from "./chunk-T7NS2J2B.js";
19
19
  import {
20
20
  openCreditDb
21
- } from "./chunk-XQHN6ITI.js";
21
+ } from "./chunk-DNWT5FZQ.js";
22
22
  import {
23
23
  loadKeyPair
24
- } from "./chunk-DVAS2443.js";
25
- import "./chunk-FNKBHBYK.js";
24
+ } from "./chunk-5KFI5X7B.js";
25
+ import "./chunk-WGZ5AGOX.js";
26
26
  import {
27
27
  RelayClient
28
28
  } from "./chunk-JOY533UH.js";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  executeCapabilityRequest
3
- } from "./chunk-Q7HRI666.js";
3
+ } from "./chunk-5QGXARLJ.js";
4
4
  import {
5
5
  listCards,
6
6
  openDatabase
7
- } from "./chunk-TLU7ALCZ.js";
7
+ } from "./chunk-T7NS2J2B.js";
8
8
  import {
9
9
  openCreditDb
10
- } from "./chunk-XQHN6ITI.js";
11
- import "./chunk-DVAS2443.js";
12
- import "./chunk-FNKBHBYK.js";
10
+ } from "./chunk-DNWT5FZQ.js";
11
+ import "./chunk-5KFI5X7B.js";
12
+ import "./chunk-WGZ5AGOX.js";
13
13
  import {
14
14
  RelayClient
15
15
  } from "./chunk-JOY533UH.js";