agentbnb 8.2.0 → 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 (40) hide show
  1. package/dist/{chunk-TBJ3FZKZ.js → chunk-4IPJJRTP.js} +1 -1
  2. package/dist/chunk-CKOOVZOI.js +158 -0
  3. package/dist/chunk-CQFBNTGT.js +145 -0
  4. package/dist/{chunk-P4LOYSLA.js → chunk-DYQOFGGI.js} +331 -416
  5. package/dist/{chunk-ALX4WS3A.js → chunk-EG6RS4JC.js} +70 -46
  6. package/dist/{chunk-CUONY5TO.js → chunk-EJKW57ZV.js} +19 -1
  7. package/dist/{chunk-5AAFG2V2.js → chunk-LKLKYXLV.js} +239 -24
  8. package/dist/{chunk-7EF3HYVZ.js → chunk-MCED4GDW.js} +499 -86
  9. package/dist/{chunk-YHY7OG6S.js → chunk-MWOXW7JQ.js} +7 -7
  10. package/dist/{chunk-E2OKP5CY.js → chunk-QCGIG7WW.js} +182 -86
  11. package/dist/{chunk-5GME4KJZ.js → chunk-QHZGOG3O.js} +148 -46
  12. package/dist/{chunk-D6RKW2XG.js → chunk-RYISHSHB.js} +302 -4
  13. package/dist/{chunk-O2OYBAVR.js → chunk-S3V6R3EN.js} +75 -39
  14. package/dist/{chunk-X32NE6V4.js → chunk-WNXXLCV5.js} +1 -1
  15. package/dist/{chunk-C537SFHV.js → chunk-XBGVQMQJ.js} +72 -48
  16. package/dist/{chunk-FTZTEHYG.js → chunk-Z2GEFFDO.js} +135 -8
  17. package/dist/cli/index.js +42 -67
  18. package/dist/{client-HKV3QWZ3.js → client-XOLP5IUZ.js} +4 -2
  19. package/dist/{conduct-W6XF6DJW.js → conduct-AZFLNUX3.js} +10 -11
  20. package/dist/{conduct-YB64OHI6.js → conduct-VPUYTNEA.js} +10 -11
  21. package/dist/{conductor-mode-AKREGDIU.js → conductor-mode-PLTB6MS3.js} +7 -8
  22. package/dist/{conductor-mode-TFCVCQHU.js → conductor-mode-WKB42PYM.js} +6 -3
  23. package/dist/{execute-EPE6MZLT.js → execute-NNDCXTN4.js} +3 -2
  24. package/dist/{execute-AYQWORVH.js → execute-RIRHTIBU.js} +6 -5
  25. package/dist/index.d.ts +8 -8
  26. package/dist/index.js +637 -693
  27. package/dist/{publish-capability-AH2HDW54.js → publish-capability-QDR2QIZ2.js} +2 -2
  28. package/dist/{request-HCCXSKAY.js → request-NX7GSPIG.js} +31 -36
  29. package/dist/{serve-skill-SZAQT5T5.js → serve-skill-E6EJQYAK.js} +10 -9
  30. package/dist/{server-LMY2A3GT.js → server-VBCT32FC.js} +12 -18
  31. package/dist/{service-coordinator-WGH6B2VT.js → service-coordinator-KMSA6BST.js} +137 -69
  32. package/dist/skills/agentbnb/bootstrap.js +561 -247
  33. package/package.json +13 -17
  34. package/skills/agentbnb/bootstrap.test.ts +8 -6
  35. package/skills/agentbnb/bootstrap.ts +21 -13
  36. package/skills/agentbnb/install.sh +0 -0
  37. package/dist/chunk-64AK4FJM.js +0 -84
  38. package/dist/chunk-KF3TZHA5.js +0 -91
  39. package/dist/chunk-LJM7FHPM.js +0 -138
  40. package/dist/chunk-OH7BP5NP.js +0 -96
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  insertCard
3
- } from "./chunk-O2OYBAVR.js";
3
+ } from "./chunk-S3V6R3EN.js";
4
4
  import {
5
5
  CapabilityCardSchema
6
6
  } from "./chunk-WVY2W7AA.js";
@@ -0,0 +1,158 @@
1
+ import {
2
+ signEscrowReceipt
3
+ } from "./chunk-EJKW57ZV.js";
4
+ import {
5
+ AgentBnBError
6
+ } from "./chunk-WVY2W7AA.js";
7
+
8
+ // src/gateway/client.ts
9
+ import { randomUUID } from "crypto";
10
+ import { Agent } from "undici";
11
+ var gatewayAgent = new Agent({
12
+ keepAliveTimeout: 3e4,
13
+ keepAliveMaxTimeout: 6e4,
14
+ connections: 10,
15
+ pipelining: 1
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
+ }
30
+ async function requestCapability(opts) {
31
+ const { gatewayUrl, token, cardId, params = {}, timeoutMs = 3e5, escrowReceipt, identity } = opts;
32
+ const id = randomUUID();
33
+ const payload = {
34
+ jsonrpc: "2.0",
35
+ id,
36
+ method: "capability.execute",
37
+ params: {
38
+ card_id: cardId,
39
+ ...params,
40
+ ...escrowReceipt ? { escrow_receipt: escrowReceipt } : {}
41
+ }
42
+ };
43
+ const headers = buildGatewayAuthHeaders(payload, token, identity);
44
+ const controller = new AbortController();
45
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
46
+ let response;
47
+ try {
48
+ response = await fetch(`${gatewayUrl}/rpc`, {
49
+ method: "POST",
50
+ headers,
51
+ body: JSON.stringify(payload),
52
+ signal: controller.signal,
53
+ // undici dispatcher for connection pooling (Node.js 20+)
54
+ dispatcher: gatewayAgent
55
+ });
56
+ } catch (err) {
57
+ clearTimeout(timer);
58
+ const isTimeout = err instanceof Error && err.name === "AbortError";
59
+ throw new AgentBnBError(
60
+ isTimeout ? "Request timed out" : `Network error: ${String(err)}`,
61
+ isTimeout ? "TIMEOUT" : "NETWORK_ERROR"
62
+ );
63
+ } finally {
64
+ clearTimeout(timer);
65
+ }
66
+ const body = await response.json();
67
+ if (body.error) {
68
+ throw new AgentBnBError(body.error.message, `RPC_ERROR_${body.error.code}`);
69
+ }
70
+ return body.result;
71
+ }
72
+ async function requestCapabilityBatch(gatewayUrl, token, items, opts = {}) {
73
+ if (items.length === 0) return /* @__PURE__ */ new Map();
74
+ if (items.length === 1) {
75
+ const item = items[0];
76
+ const result = await requestCapability({
77
+ gatewayUrl,
78
+ token,
79
+ cardId: item.cardId,
80
+ params: item.params,
81
+ escrowReceipt: item.escrowReceipt,
82
+ timeoutMs: opts.timeoutMs,
83
+ identity: opts.identity
84
+ });
85
+ return /* @__PURE__ */ new Map([[item.id, result]]);
86
+ }
87
+ const { timeoutMs = 3e5, identity } = opts;
88
+ const batchPayload = items.map((item) => ({
89
+ jsonrpc: "2.0",
90
+ id: item.id,
91
+ method: "capability.execute",
92
+ params: {
93
+ card_id: item.cardId,
94
+ ...item.params,
95
+ ...item.escrowReceipt ? { escrow_receipt: item.escrowReceipt } : {}
96
+ }
97
+ }));
98
+ const headers = buildGatewayAuthHeaders(batchPayload, token, identity);
99
+ const controller = new AbortController();
100
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
101
+ let response;
102
+ try {
103
+ response = await fetch(`${gatewayUrl}/rpc`, {
104
+ method: "POST",
105
+ headers,
106
+ body: JSON.stringify(batchPayload),
107
+ signal: controller.signal,
108
+ dispatcher: gatewayAgent
109
+ });
110
+ } catch (err) {
111
+ clearTimeout(timer);
112
+ const isTimeout = err instanceof Error && err.name === "AbortError";
113
+ throw new AgentBnBError(
114
+ isTimeout ? "Batch request timed out" : `Network error: ${String(err)}`,
115
+ isTimeout ? "TIMEOUT" : "NETWORK_ERROR"
116
+ );
117
+ } finally {
118
+ clearTimeout(timer);
119
+ }
120
+ const body = await response.json();
121
+ const results = /* @__PURE__ */ new Map();
122
+ for (const resp of body) {
123
+ if (resp.error) {
124
+ results.set(resp.id, new AgentBnBError(resp.error.message, `RPC_ERROR_${resp.error.code}`));
125
+ } else {
126
+ results.set(resp.id, resp.result);
127
+ }
128
+ }
129
+ return results;
130
+ }
131
+ async function requestViaRelay(relay, opts) {
132
+ try {
133
+ return await relay.request({
134
+ targetOwner: opts.targetOwner,
135
+ cardId: opts.cardId,
136
+ skillId: opts.skillId,
137
+ params: opts.params ?? {},
138
+ requester: opts.requester,
139
+ escrowReceipt: opts.escrowReceipt,
140
+ timeoutMs: opts.timeoutMs
141
+ });
142
+ } catch (err) {
143
+ const message = err instanceof Error ? err.message : String(err);
144
+ if (message.includes("timeout")) {
145
+ throw new AgentBnBError(message, "TIMEOUT");
146
+ }
147
+ if (message.includes("offline")) {
148
+ throw new AgentBnBError(message, "AGENT_OFFLINE");
149
+ }
150
+ throw new AgentBnBError(message, "RELAY_ERROR");
151
+ }
152
+ }
153
+
154
+ export {
155
+ requestCapability,
156
+ requestCapabilityBatch,
157
+ requestViaRelay
158
+ };
@@ -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
+ };