agentbnb 8.2.3 → 8.3.0

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 (62) hide show
  1. package/dist/{card-EX2EYGCZ.js → card-BN643ZOY.js} +6 -2
  2. package/dist/card-T2XJZA5A.js +92 -0
  3. package/dist/{chunk-3LWBH7P3.js → chunk-4NFJ3VYZ.js} +20 -1
  4. package/dist/chunk-5AIYALBX.js +857 -0
  5. package/dist/chunk-6QMDJVMS.js +238 -0
  6. package/dist/{chunk-LKLKYXLV.js → chunk-74LZDEDT.js} +6 -4
  7. package/dist/{chunk-GKVTD4EZ.js → chunk-77KGEDH4.js} +1 -1
  8. package/dist/{chunk-QCGIG7WW.js → chunk-7IQE34QK.js} +14 -7
  9. package/dist/{chunk-QHZGOG3O.js → chunk-D242QZCR.js} +168 -41
  10. package/dist/chunk-EE3V3DXK.js +60 -0
  11. package/dist/{chunk-RYISHSHB.js → chunk-F3KIEVJ2.js} +207 -265
  12. package/dist/{chunk-XBGVQMQJ.js → chunk-FELGHDCA.js} +16 -39
  13. package/dist/{chunk-EJKW57ZV.js → chunk-GIEJVKZZ.js} +1 -1
  14. package/dist/{chunk-WVY2W7AA.js → chunk-I7KWA7OB.js} +20 -0
  15. package/dist/{chunk-4IPJJRTP.js → chunk-IGQNP3ZO.js} +5 -2
  16. package/dist/chunk-NQANA6WH.js +797 -0
  17. package/dist/{chunk-Z4MCGKTL.js → chunk-NX27AFPA.js} +15 -2
  18. package/dist/{chunk-Z2GEFFDO.js → chunk-O4Q7BRG6.js} +2 -2
  19. package/dist/{chunk-SSK653A6.js → chunk-PQIP7EXY.js} +6 -0
  20. package/dist/{chunk-EG6RS4JC.js → chunk-QFPXZITP.js} +20 -65
  21. package/dist/chunk-R4F4XII4.js +264 -0
  22. package/dist/{chunk-DYQOFGGI.js → chunk-RVBW2QXU.js} +178 -49
  23. package/dist/{chunk-CQFBNTGT.js → chunk-S7DZHKCG.js} +25 -12
  24. package/dist/chunk-U6LP4KWN.js +238 -0
  25. package/dist/{chunk-MWOXW7JQ.js → chunk-VJ7XBEY6.js} +24 -16
  26. package/dist/chunk-WTHMHNKC.js +129 -0
  27. package/dist/{chunk-OCSU2S6W.js → chunk-WX3GZVFG.js} +2 -1
  28. package/dist/{chunk-CKOOVZOI.js → chunk-YKMBFQC2.js} +37 -5
  29. package/dist/{chunk-S3V6R3EN.js → chunk-ZU2TP7CN.js} +70 -27
  30. package/dist/cli/index.js +203 -237
  31. package/dist/client-OKJJ3UP2.js +19 -0
  32. package/dist/client-UQBGCIPA.js +20 -0
  33. package/dist/conduct-4JDMWBQD.js +22 -0
  34. package/dist/{conduct-AZFLNUX3.js → conduct-VYYBCPHA.js} +14 -13
  35. package/dist/{conductor-mode-WKB42PYM.js → conductor-mode-OPGQJFLA.js} +12 -8
  36. package/dist/{conductor-mode-PLTB6MS3.js → conductor-mode-SBDCRIX6.js} +16 -11
  37. package/dist/execute-FZLQGIXB.js +14 -0
  38. package/dist/execute-TEZPQ5WP.js +15 -0
  39. package/dist/index.d.ts +172 -11
  40. package/dist/index.js +1529 -433
  41. package/dist/{process-guard-GH5LRNWO.js → process-guard-TNSUNHSR.js} +1 -1
  42. package/dist/{publish-capability-QDR2QIZ2.js → publish-capability-HVYILTPR.js} +4 -3
  43. package/dist/{reliability-metrics-QG7WC5QK.js → reliability-metrics-G7LPUYJD.js} +3 -1
  44. package/dist/reliability-metrics-RRUKJ4ME.js +20 -0
  45. package/dist/{request-OERS5BE7.js → request-KJNKR27T.js} +76 -71
  46. package/dist/{serve-skill-E6EJQYAK.js → serve-skill-GC6NIQ5T.js} +10 -11
  47. package/dist/{server-46VEG2W7.js → server-YV3XPTX5.js} +11 -10
  48. package/dist/{service-coordinator-KMSA6BST.js → service-coordinator-RY5AKUZS.js} +420 -171
  49. package/dist/{skill-config-FETXPNVP.js → skill-config-5O2VR546.js} +1 -1
  50. package/dist/skills/agentbnb/bootstrap.js +528 -253
  51. package/dist/websocket-client-3U27WJUU.js +7 -0
  52. package/dist/{websocket-client-4Z5P54RU.js → websocket-client-SNDF3B6N.js} +1 -1
  53. package/package.json +1 -1
  54. package/dist/chunk-MCED4GDW.js +0 -1572
  55. package/dist/chunk-NWIQJ2CL.js +0 -108
  56. package/dist/chunk-TUCEDQGM.js +0 -44
  57. package/dist/chunk-WNXXLCV5.js +0 -32
  58. package/dist/client-XOLP5IUZ.js +0 -12
  59. package/dist/conduct-VPUYTNEA.js +0 -21
  60. package/dist/execute-NNDCXTN4.js +0 -13
  61. package/dist/execute-RIRHTIBU.js +0 -16
  62. package/dist/websocket-client-QOVARTRN.js +0 -7
@@ -2,7 +2,10 @@ import {
2
2
  requestCapability,
3
3
  requestCapabilityBatch,
4
4
  requestViaRelay
5
- } from "./chunk-CKOOVZOI.js";
5
+ } from "./chunk-R4F4XII4.js";
6
+ import {
7
+ RelayClient
8
+ } from "./chunk-4NFJ3VYZ.js";
6
9
  import {
7
10
  findPeer
8
11
  } from "./chunk-HLUEOLSZ.js";
@@ -14,10 +17,13 @@ import {
14
17
  resolveTargetCapability,
15
18
  searchCards,
16
19
  settleEscrow
17
- } from "./chunk-MCED4GDW.js";
20
+ } from "./chunk-NQANA6WH.js";
21
+ import {
22
+ resolveCanonicalIdentity
23
+ } from "./chunk-EE3V3DXK.js";
18
24
  import {
19
25
  AgentBnBError
20
- } from "./chunk-WVY2W7AA.js";
26
+ } from "./chunk-I7KWA7OB.js";
21
27
 
22
28
  // src/conductor/decomposition-validator.ts
23
29
  function validateAndNormalizeSubtasks(raw, context) {
@@ -262,11 +268,67 @@ function decompose(task, _availableCapabilities) {
262
268
  return [];
263
269
  }
264
270
 
265
- // src/autonomy/auto-request.ts
266
- import { randomUUID as randomUUID4 } from "crypto";
271
+ // src/gateway/relay-dispatch.ts
272
+ import { randomUUID as randomUUID2 } from "crypto";
273
+ async function requestViaTemporaryRelay(opts) {
274
+ const {
275
+ registryUrl,
276
+ owner,
277
+ token,
278
+ targetOwner,
279
+ targetAgentId,
280
+ cardId,
281
+ skillId,
282
+ params,
283
+ timeoutMs = 3e5
284
+ } = opts;
285
+ const requesterId = `${owner}:req:${randomUUID2()}`;
286
+ const relay = new RelayClient({
287
+ registryUrl,
288
+ owner: requesterId,
289
+ token,
290
+ card: {
291
+ spec_version: "1.0",
292
+ id: randomUUID2(),
293
+ owner: requesterId,
294
+ name: requesterId,
295
+ description: "Temporary relay requester",
296
+ level: 1,
297
+ inputs: [],
298
+ outputs: [],
299
+ pricing: { credits_per_call: 0 },
300
+ availability: { online: false }
301
+ },
302
+ onRequest: async () => ({
303
+ error: { code: -32601, message: "Temporary relay requester does not serve capabilities" }
304
+ }),
305
+ silent: true
306
+ });
307
+ try {
308
+ await relay.connect();
309
+ } catch (err) {
310
+ relay.disconnect();
311
+ const message = err instanceof Error ? err.message : String(err);
312
+ throw new AgentBnBError(`Relay connection failed: ${message}`, "RELAY_UNAVAILABLE");
313
+ }
314
+ try {
315
+ return await requestViaRelay(relay, {
316
+ targetOwner,
317
+ targetAgentId,
318
+ cardId,
319
+ skillId,
320
+ params,
321
+ requester: owner,
322
+ // actual owner for credit tracking on relay server
323
+ timeoutMs
324
+ });
325
+ } finally {
326
+ relay.disconnect();
327
+ }
328
+ }
267
329
 
268
330
  // src/autonomy/tiers.ts
269
- import { randomUUID as randomUUID2 } from "crypto";
331
+ import { randomUUID as randomUUID3 } from "crypto";
270
332
  var DEFAULT_AUTONOMY_CONFIG = {
271
333
  tier1_max_credits: 0,
272
334
  tier2_max_credits: 0
@@ -287,7 +349,7 @@ function insertAuditEvent(db, event) {
287
349
  ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
288
350
  `);
289
351
  stmt.run(
290
- randomUUID2(),
352
+ randomUUID3(),
291
353
  cardId,
292
354
  "autonomy-audit",
293
355
  "self",
@@ -302,9 +364,9 @@ function insertAuditEvent(db, event) {
302
364
  }
303
365
 
304
366
  // src/autonomy/pending-requests.ts
305
- import { randomUUID as randomUUID3 } from "crypto";
367
+ import { randomUUID as randomUUID4 } from "crypto";
306
368
  function createPendingRequest(db, opts) {
307
- const id = randomUUID3();
369
+ const id = randomUUID4();
308
370
  const now = (/* @__PURE__ */ new Date()).toISOString();
309
371
  const paramsJson = opts.params !== void 0 ? JSON.stringify(opts.params) : null;
310
372
  db.prepare(`
@@ -353,8 +415,17 @@ function minMaxNormalize(values) {
353
415
  }
354
416
  return values.map((v) => (v - min) / (max - min));
355
417
  }
356
- function scorePeers(candidates, selfOwner) {
357
- const eligible = candidates.filter((c) => c.card.owner !== selfOwner);
418
+ function scorePeers(candidates, selfOwner, registryDb) {
419
+ const selfIdentity = registryDb ? resolveCanonicalIdentity(registryDb, selfOwner) : null;
420
+ const eligible = candidates.filter((c) => {
421
+ if (c.card.owner === selfOwner) return false;
422
+ if (!registryDb || !selfIdentity?.resolved) return true;
423
+ if (typeof c.card.agent_id === "string" && c.card.agent_id.length > 0) {
424
+ return c.card.agent_id !== selfIdentity.agent_id;
425
+ }
426
+ const peerIdentity = resolveCanonicalIdentity(registryDb, c.card.owner);
427
+ return !peerIdentity.resolved || peerIdentity.agent_id !== selfIdentity.agent_id;
428
+ });
358
429
  if (eligible.length === 0) return [];
359
430
  const successRates = eligible.map((c) => {
360
431
  if (c.skillMetadata?.success_rate !== void 0) {
@@ -423,6 +494,14 @@ var AutoRequestor = class {
423
494
  * @returns The result of the auto-request attempt.
424
495
  */
425
496
  async requestWithAutonomy(need) {
497
+ const selfIdentity = resolveCanonicalIdentity(this.registryDb, this.owner);
498
+ const isSelfTarget = (targetOwner, targetAgentId) => {
499
+ if (targetOwner === this.owner) return true;
500
+ if (!selfIdentity.resolved) return false;
501
+ if (targetAgentId && targetAgentId === selfIdentity.agent_id) return true;
502
+ const targetOwnerIdentity = resolveCanonicalIdentity(this.registryDb, targetOwner);
503
+ return targetOwnerIdentity.resolved && targetOwnerIdentity.agent_id === selfIdentity.agent_id;
504
+ };
426
505
  let cards = searchCards(this.registryDb, need.query, { online: true });
427
506
  if (cards.length === 0 && this.registryUrl) {
428
507
  try {
@@ -464,7 +543,7 @@ var AutoRequestor = class {
464
543
  }
465
544
  }
466
545
  }
467
- const scored = scorePeers(candidates, this.owner);
546
+ const scored = scorePeers(candidates, this.owner, this.registryDb);
468
547
  const resolverOptions = {
469
548
  registryDb: this.registryDb,
470
549
  registryUrl: this.registryUrl,
@@ -473,7 +552,7 @@ var AutoRequestor = class {
473
552
  let resolvedTarget = null;
474
553
  if (scored.length === 0) {
475
554
  resolvedTarget = await resolveTargetCapability(need.query, resolverOptions);
476
- if (!resolvedTarget || resolvedTarget.owner === this.owner || resolvedTarget.credits_per_call > need.maxCostCredits) {
555
+ if (!resolvedTarget || isSelfTarget(resolvedTarget.owner, resolvedTarget.agent_id) || resolvedTarget.credits_per_call > need.maxCostCredits) {
477
556
  this.logFailure("auto_request_failed", "system", "none", 3, 0, "none", "No eligible peer found");
478
557
  return { status: "no_peer", reason: "No eligible peer found" };
479
558
  }
@@ -481,7 +560,7 @@ var AutoRequestor = class {
481
560
  const top = scored[0];
482
561
  const targetKey = top.skillId ?? top.card.id;
483
562
  resolvedTarget = await resolveTargetCapability(targetKey, resolverOptions) ?? await resolveTargetCapability(need.query, resolverOptions);
484
- if (!resolvedTarget || resolvedTarget.owner === this.owner) {
563
+ if (!resolvedTarget || isSelfTarget(resolvedTarget.owner, resolvedTarget.agent_id)) {
485
564
  this.logFailure("auto_request_failed", top.card.id, top.skillId ?? "none", 3, top.cost, top.card.owner, "No eligible peer found");
486
565
  return { status: "no_peer", reason: "No eligible peer found" };
487
566
  }
@@ -532,9 +611,75 @@ var AutoRequestor = class {
532
611
  );
533
612
  return { status: "budget_blocked", reason: "Insufficient credits \u2014 reserve floor would be breached" };
534
613
  }
614
+ const requestParams = selectedSkillId ? { skill_id: selectedSkillId, ...need.params, requester: this.owner } : { ...need.params, requester: this.owner };
615
+ if (selectedViaRelay && selectedCost > 0) {
616
+ if (!this.registryUrl) {
617
+ this.logFailure(
618
+ "auto_request_failed",
619
+ selectedCardId,
620
+ selectedSkillId ?? "none",
621
+ tier,
622
+ selectedCost,
623
+ selectedPeer,
624
+ "Relay target found but registryUrl is not configured"
625
+ );
626
+ return { status: "no_peer", reason: "Relay target found but registryUrl is not configured" };
627
+ }
628
+ try {
629
+ const execResult = await requestViaTemporaryRelay({
630
+ registryUrl: this.registryUrl,
631
+ owner: this.owner,
632
+ token: "auto-request-token",
633
+ targetOwner: selectedPeer,
634
+ cardId: selectedCardId,
635
+ skillId: selectedSkillId,
636
+ params: requestParams
637
+ });
638
+ if (tier === 2) {
639
+ insertAuditEvent(this.registryDb, {
640
+ type: "auto_request_notify",
641
+ card_id: selectedCardId,
642
+ skill_id: selectedSkillId ?? selectedCardId,
643
+ tier_invoked: 2,
644
+ credits: selectedCost,
645
+ peer: selectedPeer
646
+ });
647
+ } else {
648
+ insertAuditEvent(this.registryDb, {
649
+ type: "auto_request",
650
+ card_id: selectedCardId,
651
+ skill_id: selectedSkillId ?? selectedCardId,
652
+ tier_invoked: 1,
653
+ credits: selectedCost,
654
+ peer: selectedPeer
655
+ });
656
+ }
657
+ return {
658
+ status: "success",
659
+ result: execResult,
660
+ peer: selectedPeer,
661
+ creditsSpent: selectedCost
662
+ };
663
+ } catch (err) {
664
+ const reason = err instanceof Error ? err.message : String(err);
665
+ this.logFailure(
666
+ "auto_request_failed",
667
+ selectedCardId,
668
+ selectedSkillId ?? "none",
669
+ tier,
670
+ selectedCost,
671
+ selectedPeer,
672
+ `Execution failed: ${reason}`
673
+ );
674
+ return {
675
+ status: "failed",
676
+ reason: `Execution failed: ${reason}`,
677
+ peer: selectedPeer
678
+ };
679
+ }
680
+ }
535
681
  const escrowId = holdEscrow(this.creditDb, this.owner, selectedCost, selectedCardId);
536
682
  try {
537
- const requestParams = selectedSkillId ? { skill_id: selectedSkillId, ...need.params, requester: this.owner } : { ...need.params, requester: this.owner };
538
683
  let execResult;
539
684
  if (selectedViaRelay) {
540
685
  if (!this.registryUrl) {
@@ -550,39 +695,15 @@ var AutoRequestor = class {
550
695
  releaseEscrow(this.creditDb, escrowId);
551
696
  return { status: "no_peer", reason: "Relay target found but registryUrl is not configured" };
552
697
  }
553
- const relayRequesterOwner = `${this.owner}:req:${randomUUID4()}`;
554
- const { RelayClient } = await import("./websocket-client-4Z5P54RU.js");
555
- const relayClient = new RelayClient({
698
+ execResult = await requestViaTemporaryRelay({
556
699
  registryUrl: this.registryUrl,
557
- owner: relayRequesterOwner,
700
+ owner: this.owner,
558
701
  token: "auto-request-token",
559
- card: {
560
- spec_version: "1.0",
561
- id: randomUUID4(),
562
- owner: relayRequesterOwner,
563
- name: relayRequesterOwner,
564
- description: "Auto-request requester",
565
- level: 1,
566
- inputs: [],
567
- outputs: [],
568
- pricing: { credits_per_call: 1 },
569
- availability: { online: false }
570
- },
571
- onRequest: async () => ({ error: { code: -32601, message: "Auto-request relay requester does not serve capabilities" } }),
572
- silent: true
702
+ targetOwner: selectedPeer,
703
+ cardId: selectedCardId,
704
+ skillId: selectedSkillId,
705
+ params: requestParams
573
706
  });
574
- try {
575
- await relayClient.connect();
576
- execResult = await requestViaRelay(relayClient, {
577
- targetOwner: selectedPeer,
578
- cardId: selectedCardId,
579
- skillId: selectedSkillId,
580
- params: requestParams,
581
- requester: this.owner
582
- });
583
- } finally {
584
- relayClient.disconnect();
585
- }
586
707
  } else {
587
708
  const peerConfig = findPeer(selectedPeer);
588
709
  if (!peerConfig) {
@@ -975,6 +1096,7 @@ async function executeSingleTask(pt, gatewayToken, timeoutMs, requesterOwner, re
975
1096
  async function orchestrate(opts) {
976
1097
  const { subtasks, matches, gatewayToken, resolveAgentUrl, timeoutMs = 3e5, maxBudget, relayClient, requesterOwner } = opts;
977
1098
  const startTime = Date.now();
1099
+ const hardDeadline = startTime + timeoutMs;
978
1100
  const teamMemberMap = /* @__PURE__ */ new Map();
979
1101
  if (opts.team) {
980
1102
  for (const member of opts.team.matched) {
@@ -996,6 +1118,12 @@ async function orchestrate(opts) {
996
1118
  const waves = computeWaves(subtasks);
997
1119
  const subtaskMap = new Map(subtasks.map((s) => [s.id, s]));
998
1120
  for (const wave of waves) {
1121
+ const remainingWaveMs = hardDeadline - Date.now();
1122
+ if (remainingWaveMs <= 0) {
1123
+ errors.push(`Orchestration timed out after ${timeoutMs}ms`);
1124
+ break;
1125
+ }
1126
+ const waveTimeoutMs = Math.max(1, Math.min(timeoutMs, remainingWaveMs));
999
1127
  if (maxBudget !== void 0 && totalCredits >= maxBudget) {
1000
1128
  errors.push(`Budget exceeded: spent ${totalCredits} cr, max ${maxBudget} cr`);
1001
1129
  break;
@@ -1069,7 +1197,7 @@ async function orchestrate(opts) {
1069
1197
  gatewayUrl,
1070
1198
  gatewayToken,
1071
1199
  items.map(({ _pt, ...item }) => item),
1072
- { timeoutMs }
1200
+ { timeoutMs: waveTimeoutMs }
1073
1201
  );
1074
1202
  return items.map((item) => {
1075
1203
  const res = batchResults.get(item.id);
@@ -1093,7 +1221,7 @@ async function orchestrate(opts) {
1093
1221
  } catch (batchErr) {
1094
1222
  return Promise.all(group.map(async (pt) => {
1095
1223
  try {
1096
- const res = await executeSingleTask(pt, gatewayToken, timeoutMs, requesterOwner, relayClient, resolveAgentUrl);
1224
+ const res = await executeSingleTask(pt, gatewayToken, waveTimeoutMs, requesterOwner, relayClient, resolveAgentUrl);
1097
1225
  return { status: "fulfilled", value: res };
1098
1226
  } catch (err) {
1099
1227
  return { status: "rejected", reason: err };
@@ -1107,7 +1235,7 @@ async function orchestrate(opts) {
1107
1235
  batchPromises.push(
1108
1236
  (async () => {
1109
1237
  try {
1110
- const res = await executeSingleTask(pt, gatewayToken, timeoutMs, requesterOwner, relayClient, resolveAgentUrl);
1238
+ const res = await executeSingleTask(pt, gatewayToken, waveTimeoutMs, requesterOwner, relayClient, resolveAgentUrl);
1111
1239
  return [{ status: "fulfilled", value: res }];
1112
1240
  } catch (err) {
1113
1241
  return [{ status: "rejected", reason: err }];
@@ -1120,7 +1248,7 @@ async function orchestrate(opts) {
1120
1248
  batchPromises.push(
1121
1249
  (async () => {
1122
1250
  try {
1123
- const res = await executeSingleTask(pt, gatewayToken, timeoutMs, requesterOwner, relayClient, resolveAgentUrl);
1251
+ const res = await executeSingleTask(pt, gatewayToken, waveTimeoutMs, requesterOwner, relayClient, resolveAgentUrl);
1124
1252
  return [{ status: "fulfilled", value: res }];
1125
1253
  } catch (err) {
1126
1254
  return [{ status: "rejected", reason: err }];
@@ -1155,6 +1283,7 @@ export {
1155
1283
  interpolateObject,
1156
1284
  validateAndNormalizeSubtasks,
1157
1285
  decompose,
1286
+ requestViaTemporaryRelay,
1158
1287
  DEFAULT_AUTONOMY_CONFIG,
1159
1288
  getAutonomyTier,
1160
1289
  insertAuditEvent,
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  fetchRemoteCards,
3
3
  searchCards
4
- } from "./chunk-RYISHSHB.js";
4
+ } from "./chunk-F3KIEVJ2.js";
5
5
  import {
6
6
  getCard
7
- } from "./chunk-S3V6R3EN.js";
7
+ } from "./chunk-5AIYALBX.js";
8
+ import {
9
+ resolveCanonicalIdentity
10
+ } from "./chunk-WTHMHNKC.js";
8
11
 
9
12
  // src/gateway/resolve-target-capability.ts
10
13
  function canQueryLocalDb(db) {
@@ -39,15 +42,25 @@ function pickSkill(card, queryOrId) {
39
42
  if ((scored[0]?.score ?? 0) > 0) return scored[0]?.skill;
40
43
  return skills[0];
41
44
  }
42
- function toResolved(card, queryOrId, source) {
45
+ function resolveCardAgentId(card, registryDb) {
46
+ if (typeof card.agent_id === "string" && card.agent_id.length > 0) {
47
+ return card.agent_id;
48
+ }
49
+ if (!canQueryLocalDb(registryDb)) return void 0;
50
+ const resolved = resolveCanonicalIdentity(registryDb, card.owner);
51
+ return resolved.resolved ? resolved.agent_id : void 0;
52
+ }
53
+ function toResolved(card, queryOrId, source, registryDb) {
43
54
  const skill = pickSkill(card, queryOrId);
44
55
  const gatewayUrl = getGatewayUrl(card);
45
56
  const viaRelay = source === "local" ? false : gatewayUrl.length === 0;
46
57
  const resolvedSource = viaRelay ? "relay" : source;
58
+ const agentId = resolveCardAgentId(card, registryDb);
47
59
  return {
48
60
  cardId: card.id,
49
61
  skillId: skill?.id,
50
62
  owner: card.owner,
63
+ ...agentId ? { agent_id: agentId } : {},
51
64
  gateway_url: gatewayUrl,
52
65
  via_relay: viaRelay,
53
66
  credits_per_call: skill?.pricing.credits_per_call ?? card.pricing.credits_per_call,
@@ -74,7 +87,7 @@ function findRemoteBySkillId(cards, skillId) {
74
87
  return null;
75
88
  }
76
89
  function looksLikeCardId(value) {
77
- return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
90
+ return value.startsWith("card-") || /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
78
91
  }
79
92
  async function resolveTargetCapability(queryOrId, options) {
80
93
  const { registryDb, registryUrl, onlineOnly = true } = options;
@@ -83,15 +96,15 @@ async function resolveTargetCapability(queryOrId, options) {
83
96
  if (canQueryLocalDb(registryDb)) {
84
97
  const byCardId = getCard(registryDb, needle);
85
98
  if (byCardId && (!onlineOnly || isOnline(byCardId))) {
86
- return toResolved(byCardId, needle, "local");
99
+ return toResolved(byCardId, needle, "local", registryDb);
87
100
  }
88
101
  const bySkillId = findLocalBySkillId(registryDb, needle, onlineOnly);
89
102
  if (bySkillId) {
90
- return toResolved(bySkillId, needle, "local");
103
+ return toResolved(bySkillId, needle, "local", registryDb);
91
104
  }
92
105
  const localMatches = searchCards(registryDb, needle, { online: onlineOnly ? true : void 0 });
93
106
  if (localMatches.length > 0) {
94
- return toResolved(localMatches[0], needle, "local");
107
+ return toResolved(localMatches[0], needle, "local", registryDb);
95
108
  }
96
109
  }
97
110
  if (!registryUrl) return null;
@@ -101,7 +114,7 @@ async function resolveTargetCapability(queryOrId, options) {
101
114
  if (cardResp.ok) {
102
115
  const remoteCard = await cardResp.json();
103
116
  if (!onlineOnly || isOnline(remoteCard)) {
104
- return toResolved(remoteCard, needle, "remote");
117
+ return toResolved(remoteCard, needle, "remote", registryDb);
105
118
  }
106
119
  }
107
120
  } catch {
@@ -114,8 +127,8 @@ async function resolveTargetCapability(queryOrId, options) {
114
127
  });
115
128
  if (remoteMatches.length > 0) {
116
129
  const exactSkill = findRemoteBySkillId(remoteMatches, needle);
117
- if (exactSkill) return toResolved(exactSkill, needle, "remote");
118
- return toResolved(remoteMatches[0], needle, "remote");
130
+ if (exactSkill) return toResolved(exactSkill, needle, "remote", registryDb);
131
+ return toResolved(remoteMatches[0], needle, "remote", registryDb);
119
132
  }
120
133
  } catch {
121
134
  }
@@ -124,7 +137,7 @@ async function resolveTargetCapability(queryOrId, options) {
124
137
  ...onlineOnly ? { online: true } : {}
125
138
  });
126
139
  const exactSkill = findRemoteBySkillId(onlineCards, needle);
127
- if (exactSkill) return toResolved(exactSkill, needle, "relay");
140
+ if (exactSkill) return toResolved(exactSkill, needle, "relay", registryDb);
128
141
  const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 0);
129
142
  const fuzzy = onlineCards.find((card) => {
130
143
  const text = [
@@ -134,7 +147,7 @@ async function resolveTargetCapability(queryOrId, options) {
134
147
  ].join(" ").toLowerCase();
135
148
  return tokens.some((token) => text.includes(token));
136
149
  });
137
- if (fuzzy) return toResolved(fuzzy, needle, "relay");
150
+ if (fuzzy) return toResolved(fuzzy, needle, "relay", registryDb);
138
151
  } catch {
139
152
  }
140
153
  return null;