agentbnb 4.0.4 → 5.1.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 (45) hide show
  1. package/dist/chunk-AUBHR7HH.js +25 -0
  2. package/dist/chunk-B5FTAGFN.js +393 -0
  3. package/dist/{chunk-GGYC5U2Z.js → chunk-BTTL24TZ.js} +29 -91
  4. package/dist/chunk-C6KPAFCC.js +387 -0
  5. package/dist/{chunk-JXEOE7HX.js → chunk-CRFCWD6V.js} +163 -92
  6. package/dist/chunk-CSATDXZC.js +89 -0
  7. package/dist/{chunk-T7NS2J2B.js → chunk-DFBX3BBD.js} +84 -1
  8. package/dist/{chunk-DNWT5FZQ.js → chunk-EANI2N2V.js} +98 -1
  9. package/dist/{chunk-HH24WMFN.js → chunk-FLY3WIQR.js} +1 -1
  10. package/dist/{chunk-EVBX22YU.js → chunk-HLUEOLSZ.js} +11 -17
  11. package/dist/chunk-IVOYM3WG.js +25 -0
  12. package/dist/chunk-LCAIAAG2.js +916 -0
  13. package/dist/chunk-MLS6IGGG.js +294 -0
  14. package/dist/{chunk-4P3EMGL4.js → chunk-MNO4COST.js} +5 -3
  15. package/dist/chunk-NH2FIERR.js +138 -0
  16. package/dist/chunk-UKT6H7YT.js +29 -0
  17. package/dist/{chunk-BH6WGYFB.js → chunk-VE3E4AMH.js} +8 -8
  18. package/dist/{chunk-5QGXARLJ.js → chunk-W5BZMKMF.js} +159 -27
  19. package/dist/{chunk-FF226TIV.js → chunk-ZX5623ER.js} +0 -57
  20. package/dist/cli/index.js +362 -4633
  21. package/dist/{conduct-N52JX7RT.js → conduct-KM6ZNJGE.js} +10 -8
  22. package/dist/{conduct-GZQNFTRP.js → conduct-WGTMQND5.js} +10 -8
  23. package/dist/{conductor-mode-XUWGR4ZE.js → conductor-mode-OL2FNOYY.js} +6 -4
  24. package/dist/{conductor-mode-ESGFZ6T5.js → conductor-mode-VRO7TYW2.js} +20 -167
  25. package/dist/execute-CPFSOOO3.js +13 -0
  26. package/dist/execute-IP2QHALV.js +10 -0
  27. package/dist/index.d.ts +14 -8
  28. package/dist/index.js +186 -35
  29. package/dist/{peers-E4MKNNDN.js → peers-CJ7T4RJO.js} +2 -1
  30. package/dist/process-guard-CC7CNRQJ.js +176 -0
  31. package/dist/{request-4GQSSM4B.js → request-YOWPXVLQ.js} +13 -10
  32. package/dist/schema-7BSSLZ4S.js +8 -0
  33. package/dist/{serve-skill-Q6NHX2RA.js → serve-skill-JHFNR7BW.js} +8 -7
  34. package/dist/{server-B5E566CI.js → server-HKJJWFRG.js} +10 -8
  35. package/dist/service-coordinator-5R4LQW6L.js +4917 -0
  36. package/dist/skills/agentbnb/bootstrap.js +5028 -848
  37. package/dist/websocket-client-WRN3HO73.js +6 -0
  38. package/package.json +4 -1
  39. package/skills/agentbnb/SKILL.md +87 -70
  40. package/skills/agentbnb/bootstrap.test.ts +142 -242
  41. package/skills/agentbnb/bootstrap.ts +88 -95
  42. package/skills/agentbnb/install.sh +97 -27
  43. package/dist/card-RNEWSAQ6.js +0 -88
  44. package/dist/chunk-UB2NPFC7.js +0 -165
  45. package/dist/execute-QH6F54D7.js +0 -10
@@ -1,16 +1,17 @@
1
+ import {
2
+ settleProviderEarning
3
+ } from "./chunk-UKT6H7YT.js";
1
4
  import {
2
5
  getCard,
3
6
  insertRequestLog,
4
7
  updateReputation
5
- } from "./chunk-T7NS2J2B.js";
8
+ } from "./chunk-DFBX3BBD.js";
6
9
  import {
7
- confirmEscrowDebit,
8
10
  getBalance,
9
11
  holdEscrow,
10
- recordEarning,
11
12
  releaseEscrow,
12
13
  settleEscrow
13
- } from "./chunk-DNWT5FZQ.js";
14
+ } from "./chunk-EANI2N2V.js";
14
15
  import {
15
16
  verifyEscrowReceipt
16
17
  } from "./chunk-5KFI5X7B.js";
@@ -20,26 +21,6 @@ import {
20
21
 
21
22
  // src/gateway/execute.ts
22
23
  import { randomUUID } from "crypto";
23
-
24
- // src/credit/settlement.ts
25
- function settleProviderEarning(providerDb, providerOwner, receipt) {
26
- recordEarning(
27
- providerDb,
28
- providerOwner,
29
- receipt.amount,
30
- receipt.card_id,
31
- receipt.nonce
32
- );
33
- return { settled: true };
34
- }
35
- function settleRequesterEscrow(requesterDb, escrowId) {
36
- confirmEscrowDebit(requesterDb, escrowId);
37
- }
38
- function releaseRequesterEscrow(requesterDb, escrowId) {
39
- releaseEscrow(requesterDb, escrowId);
40
- }
41
-
42
- // src/gateway/execute.ts
43
24
  async function executeCapabilityRequest(opts) {
44
25
  const {
45
26
  registryDb,
@@ -199,9 +180,160 @@ async function executeCapabilityRequest(opts) {
199
180
  );
200
181
  }
201
182
  }
183
+ async function executeCapabilityBatch(options) {
184
+ const { requests, strategy, total_budget, registryDb, creditDb, owner } = options;
185
+ if (requests.length === 0) {
186
+ return { results: [], total_credits_spent: 0, total_credits_refunded: 0, success: true };
187
+ }
188
+ const sumMaxCredits = requests.reduce((acc, r) => acc + r.max_credits, 0);
189
+ if (sumMaxCredits > total_budget) {
190
+ return {
191
+ results: requests.map((_, i) => ({
192
+ request_index: i,
193
+ status: "skipped",
194
+ credits_spent: 0,
195
+ credits_refunded: 0,
196
+ error: `Total requested credits (${sumMaxCredits}) exceeds total_budget (${total_budget})`
197
+ })),
198
+ total_credits_spent: 0,
199
+ total_credits_refunded: 0,
200
+ success: false
201
+ };
202
+ }
203
+ const executeItem = async (item, index) => {
204
+ const card = getCard(registryDb, item.skill_id);
205
+ if (!card) {
206
+ return {
207
+ request_index: index,
208
+ status: "failed",
209
+ credits_spent: 0,
210
+ credits_refunded: 0,
211
+ error: `Card/skill not found: ${item.skill_id}`
212
+ };
213
+ }
214
+ const rawCard = card;
215
+ let creditsNeeded;
216
+ let resolvedSkillId;
217
+ if (Array.isArray(rawCard["skills"])) {
218
+ const v2card = card;
219
+ const skill = v2card.skills[0];
220
+ if (!skill) {
221
+ return {
222
+ request_index: index,
223
+ status: "failed",
224
+ credits_spent: 0,
225
+ credits_refunded: 0,
226
+ error: `No skills defined on card: ${item.skill_id}`
227
+ };
228
+ }
229
+ creditsNeeded = skill.pricing.credits_per_call;
230
+ resolvedSkillId = skill.id;
231
+ } else {
232
+ creditsNeeded = card.pricing.credits_per_call;
233
+ }
234
+ if (creditsNeeded > item.max_credits) {
235
+ return {
236
+ request_index: index,
237
+ status: "failed",
238
+ credits_spent: 0,
239
+ credits_refunded: 0,
240
+ error: `Skill costs ${creditsNeeded} credits but max_credits is ${item.max_credits}`
241
+ };
242
+ }
243
+ let escrowId;
244
+ try {
245
+ const balance = getBalance(creditDb, owner);
246
+ if (balance < creditsNeeded) {
247
+ return {
248
+ request_index: index,
249
+ status: "failed",
250
+ credits_spent: 0,
251
+ credits_refunded: 0,
252
+ error: "Insufficient credits"
253
+ };
254
+ }
255
+ escrowId = holdEscrow(creditDb, owner, creditsNeeded, card.id);
256
+ } catch (err) {
257
+ const msg = err instanceof AgentBnBError ? err.message : "Failed to hold escrow";
258
+ return {
259
+ request_index: index,
260
+ status: "failed",
261
+ credits_spent: 0,
262
+ credits_refunded: 0,
263
+ error: msg
264
+ };
265
+ }
266
+ const startMs = Date.now();
267
+ const latencyMs = Date.now() - startMs;
268
+ settleEscrow(creditDb, escrowId, card.owner);
269
+ updateReputation(registryDb, card.id, true, latencyMs);
270
+ try {
271
+ insertRequestLog(registryDb, {
272
+ id: randomUUID(),
273
+ card_id: card.id,
274
+ card_name: card.name,
275
+ skill_id: resolvedSkillId,
276
+ requester: owner,
277
+ status: "success",
278
+ latency_ms: latencyMs,
279
+ credits_charged: creditsNeeded,
280
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
281
+ });
282
+ } catch {
283
+ }
284
+ return {
285
+ request_index: index,
286
+ status: "success",
287
+ result: { card_id: card.id, skill_id: resolvedSkillId },
288
+ credits_spent: creditsNeeded,
289
+ credits_refunded: 0
290
+ };
291
+ };
292
+ let results;
293
+ if (strategy === "sequential") {
294
+ results = [];
295
+ let stopped = false;
296
+ for (let i = 0; i < requests.length; i++) {
297
+ if (stopped) {
298
+ results.push({
299
+ request_index: i,
300
+ status: "skipped",
301
+ credits_spent: 0,
302
+ credits_refunded: 0,
303
+ error: "Skipped due to earlier failure"
304
+ });
305
+ continue;
306
+ }
307
+ const result = await executeItem(requests[i], i);
308
+ results.push(result);
309
+ if (result.status === "failed") {
310
+ stopped = true;
311
+ }
312
+ }
313
+ } else {
314
+ const settled = await Promise.allSettled(
315
+ requests.map((item, i) => executeItem(item, i))
316
+ );
317
+ results = settled.map((outcome, i) => {
318
+ if (outcome.status === "fulfilled") {
319
+ return outcome.value;
320
+ }
321
+ return {
322
+ request_index: i,
323
+ status: "failed",
324
+ credits_spent: 0,
325
+ credits_refunded: 0,
326
+ error: outcome.reason instanceof Error ? outcome.reason.message : "Unknown error"
327
+ };
328
+ });
329
+ }
330
+ const total_credits_spent = results.reduce((acc, r) => acc + r.credits_spent, 0);
331
+ const total_credits_refunded = results.reduce((acc, r) => acc + r.credits_refunded, 0);
332
+ const success = results.every((r) => r.status === "success");
333
+ return { results, total_credits_spent, total_credits_refunded, success };
334
+ }
202
335
 
203
336
  export {
204
- settleRequesterEscrow,
205
- releaseRequesterEscrow,
206
- executeCapabilityRequest
337
+ executeCapabilityRequest,
338
+ executeCapabilityBatch
207
339
  };
@@ -2,61 +2,6 @@ import {
2
2
  AgentBnBError
3
3
  } from "./chunk-WGZ5AGOX.js";
4
4
 
5
- // src/registry/matcher.ts
6
- function searchCards(db, query, filters = {}) {
7
- const words = query.trim().split(/\s+/).map((w) => w.replace(/["*^{}():]/g, "")).filter((w) => w.length > 0);
8
- if (words.length === 0) return [];
9
- const ftsQuery = words.map((w) => `"${w}"`).join(" OR ");
10
- const conditions = [];
11
- const params = [ftsQuery];
12
- if (filters.level !== void 0) {
13
- conditions.push(`json_extract(cc.data, '$.level') = ?`);
14
- params.push(filters.level);
15
- }
16
- if (filters.online !== void 0) {
17
- conditions.push(`json_extract(cc.data, '$.availability.online') = ?`);
18
- params.push(filters.online ? 1 : 0);
19
- }
20
- const whereClause = conditions.length > 0 ? `AND ${conditions.join(" AND ")}` : "";
21
- const sql = `
22
- SELECT cc.data
23
- FROM capability_cards cc
24
- JOIN cards_fts ON cc.rowid = cards_fts.rowid
25
- WHERE cards_fts MATCH ?
26
- ${whereClause}
27
- ORDER BY bm25(cards_fts)
28
- LIMIT 50
29
- `;
30
- const stmt = db.prepare(sql);
31
- const rows = stmt.all(...params);
32
- const results = rows.map((row) => JSON.parse(row.data));
33
- if (filters.apis_used && filters.apis_used.length > 0) {
34
- const requiredApis = filters.apis_used;
35
- return results.filter((card) => {
36
- const cardApis = card.metadata?.apis_used ?? [];
37
- return requiredApis.every((api) => cardApis.includes(api));
38
- });
39
- }
40
- return results;
41
- }
42
- function filterCards(db, filters) {
43
- const conditions = [];
44
- const params = [];
45
- if (filters.level !== void 0) {
46
- conditions.push(`json_extract(data, '$.level') = ?`);
47
- params.push(filters.level);
48
- }
49
- if (filters.online !== void 0) {
50
- conditions.push(`json_extract(data, '$.availability.online') = ?`);
51
- params.push(filters.online ? 1 : 0);
52
- }
53
- const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
54
- const sql = `SELECT data FROM capability_cards ${whereClause}`;
55
- const stmt = db.prepare(sql);
56
- const rows = stmt.all(...params);
57
- return rows.map((row) => JSON.parse(row.data));
58
- }
59
-
60
5
  // src/cli/remote-registry.ts
61
6
  var RegistryTimeoutError = class extends AgentBnBError {
62
7
  constructor(url) {
@@ -141,8 +86,6 @@ function mergeResults(localCards, remoteCards, hasQuery) {
141
86
  }
142
87
 
143
88
  export {
144
- searchCards,
145
- filterCards,
146
89
  fetchRemoteCards,
147
90
  mergeResults
148
91
  };