agentbnb 4.0.1 → 4.0.2

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 (39) hide show
  1. package/README.md +2 -0
  2. package/dist/{card-4XH4AOTE.js → card-RSGDCHCV.js} +1 -1
  3. package/dist/{chunk-MQKYGY5I.js → chunk-4P3EMGL4.js} +3 -3
  4. package/dist/{chunk-DVAS2443.js → chunk-5KFI5X7B.js} +1 -1
  5. package/dist/{chunk-Q7HRI666.js → chunk-7NA43XCG.js} +4 -4
  6. package/dist/{chunk-3UKAVIMC.js → chunk-BH6WGYFB.js} +4 -4
  7. package/dist/{chunk-XQHN6ITI.js → chunk-DNWT5FZQ.js} +22 -2
  8. package/dist/{chunk-QJEOCKVF.js → chunk-FF226TIV.js} +1 -1
  9. package/dist/{chunk-6K5WUVF3.js → chunk-GGYC5U2Z.js} +4 -4
  10. package/dist/{chunk-ODBGCCEH.js → chunk-HH24WMFN.js} +18 -3
  11. package/dist/{chunk-M3G5NR2Z.js → chunk-QITOPASZ.js} +8 -2
  12. package/dist/{chunk-TLU7ALCZ.js → chunk-T7NS2J2B.js} +1 -1
  13. package/dist/{chunk-FNKBHBYK.js → chunk-WGZ5AGOX.js} +37 -3
  14. package/dist/{chunk-KJG2UJV5.js → chunk-XND2DWTZ.js} +3 -2
  15. package/dist/cli/index.d.ts +1 -0
  16. package/dist/cli/index.js +403 -134
  17. package/dist/{client-BTPIFY7E.js → client-T5MTY3CS.js} +3 -3
  18. package/dist/conduct-GZQNFTRP.js +19 -0
  19. package/dist/{conduct-CW62HBPT.js → conduct-N52JX7RT.js} +9 -9
  20. package/dist/{conductor-mode-3JS4VWCR.js → conductor-mode-XUWGR4ZE.js} +7 -7
  21. package/dist/execute-PNGQOMYO.js +10 -0
  22. package/dist/index.d.ts +146 -2
  23. package/dist/index.js +131 -65
  24. package/dist/{request-CNZ3XIVX.js → request-4GQSSM4B.js} +8 -8
  25. package/dist/{serve-skill-SUOGUM7N.js → serve-skill-TPHZH6BS.js} +5 -5
  26. package/dist/{server-2LWHL24P.js → server-365V3GYD.js} +10 -10
  27. package/package.json +3 -6
  28. package/skills/agentbnb/HEARTBEAT.rules.md +47 -0
  29. package/skills/agentbnb/SKILL.md +166 -0
  30. package/skills/agentbnb/auto-request.ts +14 -0
  31. package/skills/agentbnb/auto-share.ts +10 -0
  32. package/skills/agentbnb/bootstrap.test.ts +323 -0
  33. package/skills/agentbnb/bootstrap.ts +126 -0
  34. package/skills/agentbnb/credit-mgr.ts +11 -0
  35. package/skills/agentbnb/gateway.ts +12 -0
  36. package/skills/agentbnb/install.sh +210 -0
  37. package/dist/conduct-FXLVGKD5.js +0 -19
  38. package/dist/execute-EXOITLHN.js +0 -10
  39. package/dist/types-FGBUZ3QV.js +0 -18
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  requestCapability,
3
3
  requestViaRelay
4
- } from "./chunk-KJG2UJV5.js";
5
- import "./chunk-DVAS2443.js";
6
- import "./chunk-FNKBHBYK.js";
4
+ } from "./chunk-XND2DWTZ.js";
5
+ import "./chunk-5KFI5X7B.js";
6
+ import "./chunk-WGZ5AGOX.js";
7
7
  export {
8
8
  requestCapability,
9
9
  requestViaRelay
@@ -0,0 +1,19 @@
1
+ import {
2
+ conductAction
3
+ } from "./chunk-BH6WGYFB.js";
4
+ import "./chunk-4P3EMGL4.js";
5
+ import "./chunk-3MJT4PZG.js";
6
+ import "./chunk-GGYC5U2Z.js";
7
+ import "./chunk-FF226TIV.js";
8
+ import "./chunk-XND2DWTZ.js";
9
+ import "./chunk-5AH3CMOX.js";
10
+ import "./chunk-75OC6E4F.js";
11
+ import "./chunk-T7NS2J2B.js";
12
+ import "./chunk-DNWT5FZQ.js";
13
+ import "./chunk-5KFI5X7B.js";
14
+ import "./chunk-WGZ5AGOX.js";
15
+ import "./chunk-JOY533UH.js";
16
+ import "./chunk-QT7TEVNV.js";
17
+ export {
18
+ conductAction
19
+ };
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  conductAction
3
- } from "./chunk-3UKAVIMC.js";
4
- import "./chunk-MQKYGY5I.js";
3
+ } from "./chunk-BH6WGYFB.js";
4
+ import "./chunk-4P3EMGL4.js";
5
5
  import "./chunk-3MJT4PZG.js";
6
- import "./chunk-6K5WUVF3.js";
7
- import "./chunk-QJEOCKVF.js";
8
- import "./chunk-KJG2UJV5.js";
6
+ import "./chunk-GGYC5U2Z.js";
7
+ import "./chunk-FF226TIV.js";
8
+ import "./chunk-XND2DWTZ.js";
9
9
  import "./chunk-5AH3CMOX.js";
10
10
  import "./chunk-75OC6E4F.js";
11
- import "./chunk-TLU7ALCZ.js";
12
- import "./chunk-XQHN6ITI.js";
13
- import "./chunk-DVAS2443.js";
14
- import "./chunk-FNKBHBYK.js";
11
+ import "./chunk-T7NS2J2B.js";
12
+ import "./chunk-DNWT5FZQ.js";
13
+ import "./chunk-5KFI5X7B.js";
14
+ import "./chunk-WGZ5AGOX.js";
15
15
  import "./chunk-JOY533UH.js";
16
16
  import "./chunk-QT7TEVNV.js";
17
17
 
@@ -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-7NA43XCG.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
  }>;
@@ -3749,6 +3891,8 @@ interface RelayRequestOptions {
3749
3891
  escrowReceipt?: EscrowReceipt;
3750
3892
  /** Timeout in milliseconds. Default 30000. */
3751
3893
  timeoutMs?: number;
3894
+ /** Actual requester owner for credit tracking (defaults to relay client's owner). */
3895
+ requester?: string;
3752
3896
  }
3753
3897
  /**
3754
3898
  * 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.
@@ -1968,6 +2005,7 @@ async function requestViaRelay(relay, opts) {
1968
2005
  cardId: opts.cardId,
1969
2006
  skillId: opts.skillId,
1970
2007
  params: opts.params ?? {},
2008
+ requester: opts.requester,
1971
2009
  escrowReceipt: opts.escrowReceipt,
1972
2010
  timeoutMs: opts.timeoutMs
1973
2011
  });
@@ -2760,7 +2798,13 @@ function verifyAgentCertificate(cert) {
2760
2798
  }
2761
2799
  function ensureIdentity(configDir, owner) {
2762
2800
  const existing = loadIdentity(configDir);
2763
- if (existing) return existing;
2801
+ if (existing) {
2802
+ if (existing.owner !== owner) {
2803
+ existing.owner = owner;
2804
+ saveIdentity(configDir, existing);
2805
+ }
2806
+ return existing;
2807
+ }
2764
2808
  return createIdentity(configDir, owner);
2765
2809
  }
2766
2810
 
@@ -3216,14 +3260,27 @@ function lookupCardPrice(registryDb, cardId, skillId) {
3216
3260
  } catch {
3217
3261
  return null;
3218
3262
  }
3219
- if (skillId && Array.isArray(card.skills)) {
3263
+ if (Array.isArray(card.skills) && card.skills.length > 0) {
3220
3264
  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;
3265
+ if (skillId) {
3266
+ const skill = skills.find((s) => s.id === skillId);
3267
+ if (skill) {
3268
+ const skillPricing = skill.pricing;
3269
+ if (skillPricing && typeof skillPricing.credits_per_call === "number") {
3270
+ return skillPricing.credits_per_call;
3271
+ }
3226
3272
  }
3273
+ } else {
3274
+ let minPrice = null;
3275
+ for (const s of skills) {
3276
+ const sp = s.pricing;
3277
+ if (sp && typeof sp.credits_per_call === "number" && sp.credits_per_call > 0) {
3278
+ if (minPrice === null || sp.credits_per_call < minPrice) {
3279
+ minPrice = sp.credits_per_call;
3280
+ }
3281
+ }
3282
+ }
3283
+ if (minPrice !== null) return minPrice;
3227
3284
  }
3228
3285
  }
3229
3286
  const pricing = card.pricing;
@@ -3401,7 +3458,13 @@ function registerWebSocketRelay(server, db, creditDb) {
3401
3458
  }
3402
3459
  }
3403
3460
  connections.set(owner, ws);
3404
- const cardId = upsertCard(card, owner);
3461
+ let cardId;
3462
+ try {
3463
+ cardId = upsertCard(card, owner);
3464
+ } catch (err) {
3465
+ console.error(`[relay] card validation failed for ${owner}:`, err instanceof Error ? err.message : err);
3466
+ cardId = card.id ?? owner;
3467
+ }
3405
3468
  const cardName = card.name ?? card.agent_name ?? owner;
3406
3469
  logAgentJoined(owner, cardName, cardId);
3407
3470
  if (msg.cards && msg.cards.length > 0) {
@@ -3441,12 +3504,13 @@ function registerWebSocketRelay(server, db, creditDb) {
3441
3504
  });
3442
3505
  return;
3443
3506
  }
3507
+ const creditOwner = msg.requester ?? fromOwner;
3444
3508
  let escrowId;
3445
3509
  if (creditDb) {
3446
3510
  try {
3447
3511
  const price = lookupCardPrice(db, msg.card_id, msg.skill_id);
3448
3512
  if (price !== null && price > 0) {
3449
- escrowId = holdForRelay(creditDb, fromOwner, price, msg.card_id);
3513
+ escrowId = holdForRelay(creditDb, creditOwner, price, msg.card_id);
3450
3514
  }
3451
3515
  } catch (err) {
3452
3516
  if (err instanceof AgentBnBError && err.code === "INSUFFICIENT_CREDITS") {
@@ -3476,7 +3540,7 @@ function registerWebSocketRelay(server, db, creditDb) {
3476
3540
  error: { code: -32603, message: "Relay request timeout" }
3477
3541
  });
3478
3542
  }, RELAY_TIMEOUT_MS);
3479
- pendingRequests.set(msg.id, { originOwner: fromOwner, timeout, escrowId, targetOwner: msg.target_owner });
3543
+ pendingRequests.set(msg.id, { originOwner: fromOwner, creditOwner, timeout, escrowId, targetOwner: msg.target_owner });
3480
3544
  sendMessage(targetWs, {
3481
3545
  type: "incoming_request",
3482
3546
  id: msg.id,
@@ -3564,7 +3628,7 @@ function registerWebSocketRelay(server, db, creditDb) {
3564
3628
  conductorFee = calculateConductorFee(totalCredits);
3565
3629
  if (conductorFee > 0) {
3566
3630
  try {
3567
- const feeEscrowId = holdForRelay(creditDb, pending.originOwner, conductorFee, msg.id);
3631
+ const feeEscrowId = holdForRelay(creditDb, pending.creditOwner ?? pending.originOwner, conductorFee, msg.id);
3568
3632
  settleForRelay(creditDb, feeEscrowId, pending.targetOwner);
3569
3633
  } catch (e) {
3570
3634
  console.error("[relay] conductor fee settlement failed (non-fatal):", e);
@@ -3620,60 +3684,62 @@ function registerWebSocketRelay(server, db, creditDb) {
3620
3684
  }
3621
3685
  }
3622
3686
  }
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);
3687
+ void server.register(async (app) => {
3688
+ app.get("/ws", { websocket: true }, (rawSocket, _request) => {
3689
+ const socket = rawSocket;
3690
+ let registeredOwner;
3691
+ socket.on("message", (raw) => {
3692
+ void (async () => {
3693
+ let data;
3694
+ try {
3695
+ data = JSON.parse(typeof raw === "string" ? raw : raw.toString("utf-8"));
3696
+ } catch {
3697
+ sendMessage(socket, { type: "error", code: "invalid_json", message: "Invalid JSON" });
3698
+ return;
3699
+ }
3700
+ const parsed = RelayMessageSchema.safeParse(data);
3701
+ if (!parsed.success) {
3702
+ sendMessage(socket, {
3703
+ type: "error",
3704
+ code: "invalid_message",
3705
+ message: `Invalid message: ${parsed.error.issues[0]?.message ?? "unknown error"}`
3706
+ });
3707
+ return;
3708
+ }
3709
+ const msg = parsed.data;
3710
+ switch (msg.type) {
3711
+ case "register":
3712
+ registeredOwner = msg.owner;
3713
+ handleRegister(socket, msg);
3714
+ break;
3715
+ case "relay_request":
3716
+ if (!registeredOwner) {
3717
+ sendMessage(socket, {
3718
+ type: "error",
3719
+ code: "not_registered",
3720
+ message: "Must send register message before relay requests"
3721
+ });
3722
+ return;
3723
+ }
3724
+ await handleRelayRequest(socket, msg, registeredOwner);
3725
+ break;
3726
+ case "relay_response":
3727
+ handleRelayResponse(msg);
3728
+ break;
3729
+ case "relay_progress":
3730
+ handleRelayProgress(msg);
3731
+ break;
3732
+ default:
3733
+ break;
3734
+ }
3735
+ })();
3736
+ });
3737
+ socket.on("close", () => {
3738
+ handleDisconnect(registeredOwner);
3739
+ });
3740
+ socket.on("error", () => {
3741
+ handleDisconnect(registeredOwner);
3742
+ });
3677
3743
  });
3678
3744
  });
3679
3745
  return {
@@ -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-7NA43XCG.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";