agentbnb 8.2.1 → 8.2.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 (34) hide show
  1. package/dist/{chunk-7Q2XUXSA.js → chunk-4IPJJRTP.js} +1 -1
  2. package/dist/{chunk-EZVOG7QS.js → chunk-CKOOVZOI.js} +15 -18
  3. package/dist/chunk-CQFBNTGT.js +145 -0
  4. package/dist/{chunk-WKWJWKX7.js → chunk-DYQOFGGI.js} +155 -445
  5. package/dist/{chunk-NP55V7RQ.js → chunk-EG6RS4JC.js} +70 -46
  6. package/dist/{chunk-KBQNTUTN.js → chunk-LKLKYXLV.js} +1 -1
  7. package/dist/{chunk-STJLWMXH.js → chunk-MCED4GDW.js} +467 -98
  8. package/dist/{chunk-GWMMYVLL.js → chunk-MWOXW7JQ.js} +7 -7
  9. package/dist/{chunk-GJETGML6.js → chunk-QCGIG7WW.js} +4 -6
  10. package/dist/{chunk-UYCD3JBZ.js → chunk-QHZGOG3O.js} +148 -46
  11. package/dist/{chunk-JLNHMNES.js → chunk-RYISHSHB.js} +286 -1
  12. package/dist/{chunk-SRBVKO2V.js → chunk-S3V6R3EN.js} +66 -39
  13. package/dist/{chunk-RBXTWWUH.js → chunk-WNXXLCV5.js} +1 -1
  14. package/dist/{chunk-LOUEJI6X.js → chunk-XBGVQMQJ.js} +71 -47
  15. package/dist/{chunk-DEWY7OQK.js → chunk-Z2GEFFDO.js} +1 -1
  16. package/dist/cli/index.js +25 -28
  17. package/dist/{client-66TFS7RS.js → client-XOLP5IUZ.js} +1 -1
  18. package/dist/{conduct-A6COHLHY.js → conduct-AZFLNUX3.js} +9 -10
  19. package/dist/{conduct-IUVAXUAV.js → conduct-VPUYTNEA.js} +9 -10
  20. package/dist/{conductor-mode-L2MB44BW.js → conductor-mode-PLTB6MS3.js} +6 -7
  21. package/dist/{conductor-mode-D5TFQW5L.js → conductor-mode-WKB42PYM.js} +6 -3
  22. package/dist/{execute-WOS457HW.js → execute-NNDCXTN4.js} +3 -2
  23. package/dist/{execute-5AWLARB5.js → execute-RIRHTIBU.js} +5 -4
  24. package/dist/index.d.ts +5069 -0
  25. package/dist/index.js +208 -610
  26. package/dist/{publish-capability-JJCBBMSX.js → publish-capability-QDR2QIZ2.js} +2 -2
  27. package/dist/{request-6YQLA7K3.js → request-NX7GSPIG.js} +30 -40
  28. package/dist/{serve-skill-X7TZSILV.js → serve-skill-E6EJQYAK.js} +9 -8
  29. package/dist/{server-5TSP4DBX.js → server-VBCT32FC.js} +10 -14
  30. package/dist/{service-coordinator-WTUSMPY6.js → service-coordinator-KMSA6BST.js} +77 -32
  31. package/dist/skills/agentbnb/bootstrap.js +113 -69
  32. package/package.json +1 -1
  33. package/dist/chunk-BZOJ7HBT.js +0 -170
  34. package/dist/chunk-KF3TZHA5.js +0 -91
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  insertCard
3
- } from "./chunk-SRBVKO2V.js";
3
+ } from "./chunk-S3V6R3EN.js";
4
4
  import {
5
5
  CapabilityCardSchema
6
6
  } from "./chunk-WVY2W7AA.js";
@@ -14,6 +14,19 @@ var gatewayAgent = new Agent({
14
14
  connections: 10,
15
15
  pipelining: 1
16
16
  });
17
+ function buildGatewayAuthHeaders(payload, token, identity) {
18
+ const headers = { "Content-Type": "application/json" };
19
+ if (identity) {
20
+ const signature = signEscrowReceipt(payload, identity.privateKey);
21
+ headers["X-Agent-Id"] = identity.agentId;
22
+ headers["X-Agent-Public-Key"] = identity.publicKey;
23
+ headers["X-Agent-Signature"] = signature;
24
+ }
25
+ if (token) {
26
+ headers["Authorization"] = `Bearer ${token}`;
27
+ }
28
+ return headers;
29
+ }
17
30
  async function requestCapability(opts) {
18
31
  const { gatewayUrl, token, cardId, params = {}, timeoutMs = 3e5, escrowReceipt, identity } = opts;
19
32
  const id = randomUUID();
@@ -27,15 +40,7 @@ async function requestCapability(opts) {
27
40
  ...escrowReceipt ? { escrow_receipt: escrowReceipt } : {}
28
41
  }
29
42
  };
30
- const headers = { "Content-Type": "application/json" };
31
- if (identity) {
32
- const signature = signEscrowReceipt(payload, identity.privateKey);
33
- headers["X-Agent-Id"] = identity.agentId;
34
- headers["X-Agent-Public-Key"] = identity.publicKey;
35
- headers["X-Agent-Signature"] = signature;
36
- } else if (token) {
37
- headers["Authorization"] = `Bearer ${token}`;
38
- }
43
+ const headers = buildGatewayAuthHeaders(payload, token, identity);
39
44
  const controller = new AbortController();
40
45
  const timer = setTimeout(() => controller.abort(), timeoutMs);
41
46
  let response;
@@ -90,15 +95,7 @@ async function requestCapabilityBatch(gatewayUrl, token, items, opts = {}) {
90
95
  ...item.escrowReceipt ? { escrow_receipt: item.escrowReceipt } : {}
91
96
  }
92
97
  }));
93
- const headers = { "Content-Type": "application/json" };
94
- if (identity) {
95
- const signature = signEscrowReceipt(batchPayload, identity.privateKey);
96
- headers["X-Agent-Id"] = identity.agentId;
97
- headers["X-Agent-Public-Key"] = identity.publicKey;
98
- headers["X-Agent-Signature"] = signature;
99
- } else if (token) {
100
- headers["Authorization"] = `Bearer ${token}`;
101
- }
98
+ const headers = buildGatewayAuthHeaders(batchPayload, token, identity);
102
99
  const controller = new AbortController();
103
100
  const timer = setTimeout(() => controller.abort(), timeoutMs);
104
101
  let response;
@@ -0,0 +1,145 @@
1
+ import {
2
+ fetchRemoteCards,
3
+ searchCards
4
+ } from "./chunk-RYISHSHB.js";
5
+ import {
6
+ getCard
7
+ } from "./chunk-S3V6R3EN.js";
8
+
9
+ // src/gateway/resolve-target-capability.ts
10
+ function canQueryLocalDb(db) {
11
+ return Boolean(db) && typeof db.prepare === "function";
12
+ }
13
+ function getGatewayUrl(card) {
14
+ if (typeof card.gateway_url === "string" && card.gateway_url.length > 0) {
15
+ return card.gateway_url;
16
+ }
17
+ const internal = card._internal;
18
+ const internalGateway = internal?.["gateway_url"];
19
+ return typeof internalGateway === "string" ? internalGateway : "";
20
+ }
21
+ function isOnline(card) {
22
+ return card.availability?.online !== false;
23
+ }
24
+ function scoreSkill(skill, query) {
25
+ const q = query.toLowerCase();
26
+ if (skill.id.toLowerCase() === q) return 100;
27
+ let score = 0;
28
+ if (skill.id.toLowerCase().includes(q)) score += 40;
29
+ if (skill.name.toLowerCase().includes(q)) score += 20;
30
+ if (skill.description.toLowerCase().includes(q)) score += 10;
31
+ return score;
32
+ }
33
+ function pickSkill(card, queryOrId) {
34
+ const skills = Array.isArray(card.skills) ? card.skills : [];
35
+ if (skills.length === 0) return void 0;
36
+ const exact = skills.find((s) => s.id === queryOrId);
37
+ if (exact) return exact;
38
+ const scored = skills.map((skill) => ({ skill, score: scoreSkill(skill, queryOrId) })).sort((a, b) => b.score - a.score);
39
+ if ((scored[0]?.score ?? 0) > 0) return scored[0]?.skill;
40
+ return skills[0];
41
+ }
42
+ function toResolved(card, queryOrId, source) {
43
+ const skill = pickSkill(card, queryOrId);
44
+ const gatewayUrl = getGatewayUrl(card);
45
+ const viaRelay = source === "local" ? false : gatewayUrl.length === 0;
46
+ const resolvedSource = viaRelay ? "relay" : source;
47
+ return {
48
+ cardId: card.id,
49
+ skillId: skill?.id,
50
+ owner: card.owner,
51
+ gateway_url: gatewayUrl,
52
+ via_relay: viaRelay,
53
+ credits_per_call: skill?.pricing.credits_per_call ?? card.pricing.credits_per_call,
54
+ source: resolvedSource
55
+ };
56
+ }
57
+ function findLocalBySkillId(db, skillId, onlineOnly) {
58
+ const rows = db.prepare("SELECT data FROM capability_cards").all();
59
+ for (const row of rows) {
60
+ const card = JSON.parse(row.data);
61
+ if (onlineOnly && !isOnline(card)) continue;
62
+ const skills = Array.isArray(card.skills) ? card.skills : [];
63
+ if (skills.some((s) => s.id === skillId)) {
64
+ return card;
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+ function findRemoteBySkillId(cards, skillId) {
70
+ for (const card of cards) {
71
+ const skills = Array.isArray(card.skills) ? card.skills : [];
72
+ if (skills.some((s) => s.id === skillId)) return card;
73
+ }
74
+ return null;
75
+ }
76
+ 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);
78
+ }
79
+ async function resolveTargetCapability(queryOrId, options) {
80
+ const { registryDb, registryUrl, onlineOnly = true } = options;
81
+ const needle = queryOrId.trim();
82
+ if (needle.length === 0) return null;
83
+ if (canQueryLocalDb(registryDb)) {
84
+ const byCardId = getCard(registryDb, needle);
85
+ if (byCardId && (!onlineOnly || isOnline(byCardId))) {
86
+ return toResolved(byCardId, needle, "local");
87
+ }
88
+ const bySkillId = findLocalBySkillId(registryDb, needle, onlineOnly);
89
+ if (bySkillId) {
90
+ return toResolved(bySkillId, needle, "local");
91
+ }
92
+ const localMatches = searchCards(registryDb, needle, { online: onlineOnly ? true : void 0 });
93
+ if (localMatches.length > 0) {
94
+ return toResolved(localMatches[0], needle, "local");
95
+ }
96
+ }
97
+ if (!registryUrl) return null;
98
+ if (looksLikeCardId(needle)) {
99
+ try {
100
+ const cardResp = await fetch(`${registryUrl.replace(/\/$/, "")}/cards/${encodeURIComponent(needle)}`);
101
+ if (cardResp.ok) {
102
+ const remoteCard = await cardResp.json();
103
+ if (!onlineOnly || isOnline(remoteCard)) {
104
+ return toResolved(remoteCard, needle, "remote");
105
+ }
106
+ }
107
+ } catch {
108
+ }
109
+ }
110
+ try {
111
+ const remoteMatches = await fetchRemoteCards(registryUrl, {
112
+ q: needle,
113
+ ...onlineOnly ? { online: true } : {}
114
+ });
115
+ if (remoteMatches.length > 0) {
116
+ const exactSkill = findRemoteBySkillId(remoteMatches, needle);
117
+ if (exactSkill) return toResolved(exactSkill, needle, "remote");
118
+ return toResolved(remoteMatches[0], needle, "remote");
119
+ }
120
+ } catch {
121
+ }
122
+ try {
123
+ const onlineCards = await fetchRemoteCards(registryUrl, {
124
+ ...onlineOnly ? { online: true } : {}
125
+ });
126
+ const exactSkill = findRemoteBySkillId(onlineCards, needle);
127
+ if (exactSkill) return toResolved(exactSkill, needle, "relay");
128
+ const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 0);
129
+ const fuzzy = onlineCards.find((card) => {
130
+ const text = [
131
+ card.name,
132
+ card.description,
133
+ ...Array.isArray(card.skills) ? card.skills.map((s) => `${s.id} ${s.name} ${s.description}`) : []
134
+ ].join(" ").toLowerCase();
135
+ return tokens.some((token) => text.includes(token));
136
+ });
137
+ if (fuzzy) return toResolved(fuzzy, needle, "relay");
138
+ } catch {
139
+ }
140
+ return null;
141
+ }
142
+
143
+ export {
144
+ resolveTargetCapability
145
+ };