agentbnb 4.0.0 → 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.
- package/README.md +2 -0
- package/dist/{card-IE5UV5QX.js → card-RSGDCHCV.js} +11 -4
- package/dist/chunk-3MJT4PZG.js +50 -0
- package/dist/{chunk-HEVXCYCY.js → chunk-4P3EMGL4.js} +61 -24
- package/dist/chunk-5AH3CMOX.js +62 -0
- package/dist/{chunk-QO67IGCW.js → chunk-5KFI5X7B.js} +1 -1
- package/dist/chunk-75OC6E4F.js +33 -0
- package/dist/{chunk-CUVIWPQO.js → chunk-7NA43XCG.js} +7 -6
- package/dist/{conduct-IQYAT6ZU.js → chunk-BH6WGYFB.js} +70 -33
- package/dist/{chunk-QVV2P3FN.js → chunk-DNWT5FZQ.js} +22 -2
- package/dist/chunk-FF226TIV.js +148 -0
- package/dist/{chunk-UJWYE7VL.js → chunk-GGYC5U2Z.js} +28 -111
- package/dist/chunk-HH24WMFN.js +373 -0
- package/dist/{websocket-client-5TIQDYQ4.js → chunk-JOY533UH.js} +38 -4
- package/dist/chunk-QITOPASZ.js +96 -0
- package/dist/{chunk-3Y36WQDV.js → chunk-QT7TEVNV.js} +14 -2
- package/dist/{chunk-UOGDK2S2.js → chunk-T7NS2J2B.js} +1 -1
- package/dist/{chunk-XA63SD4T.js → chunk-WGZ5AGOX.js} +37 -0
- package/dist/{chunk-RSX4SCPN.js → chunk-XND2DWTZ.js} +4 -3
- package/dist/cli/index.js +2924 -835
- package/dist/{client-IOTK6GOS.js → client-T5MTY3CS.js} +3 -3
- package/dist/conduct-GZQNFTRP.js +19 -0
- package/dist/conduct-N52JX7RT.js +52 -0
- package/dist/{conductor-mode-XU7ONJWC.js → conductor-mode-XUWGR4ZE.js} +16 -9
- package/dist/execute-PNGQOMYO.js +10 -0
- package/dist/index.d.ts +1148 -915
- package/dist/index.js +589 -127
- package/dist/{peers-G36URZYB.js → peers-K7FSHPN3.js} +2 -1
- package/dist/request-4GQSSM4B.js +196 -0
- package/dist/serve-skill-TPHZH6BS.js +104 -0
- package/dist/server-365V3GYD.js +295 -0
- package/dist/websocket-client-6IIDGXKB.js +7 -0
- package/package.json +3 -6
- package/skills/agentbnb/HEARTBEAT.rules.md +47 -0
- package/skills/agentbnb/SKILL.md +166 -0
- package/skills/agentbnb/auto-request.ts +14 -0
- package/skills/agentbnb/auto-share.ts +10 -0
- package/skills/agentbnb/bootstrap.test.ts +323 -0
- package/skills/agentbnb/bootstrap.ts +126 -0
- package/skills/agentbnb/credit-mgr.ts +11 -0
- package/skills/agentbnb/gateway.ts +12 -0
- package/skills/agentbnb/install.sh +210 -0
- package/dist/chunk-BEI5MTNZ.js +0 -91
- package/dist/execute-GDGBU6DJ.js +0 -10
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentBnBError
|
|
3
|
+
} from "./chunk-WGZ5AGOX.js";
|
|
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
|
+
// src/cli/remote-registry.ts
|
|
61
|
+
var RegistryTimeoutError = class extends AgentBnBError {
|
|
62
|
+
constructor(url) {
|
|
63
|
+
super(
|
|
64
|
+
`Registry at ${url} did not respond within 5s. Showing local results only.`,
|
|
65
|
+
"REGISTRY_TIMEOUT"
|
|
66
|
+
);
|
|
67
|
+
this.name = "RegistryTimeoutError";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var RegistryConnectionError = class extends AgentBnBError {
|
|
71
|
+
constructor(url) {
|
|
72
|
+
super(
|
|
73
|
+
`Cannot reach ${url}. Is the registry running? Showing local results only.`,
|
|
74
|
+
"REGISTRY_CONNECTION"
|
|
75
|
+
);
|
|
76
|
+
this.name = "RegistryConnectionError";
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var RegistryAuthError = class extends AgentBnBError {
|
|
80
|
+
constructor(url) {
|
|
81
|
+
super(
|
|
82
|
+
`Authentication failed for ${url}. Run \`agentbnb config set token <your-token>\`.`,
|
|
83
|
+
"REGISTRY_AUTH"
|
|
84
|
+
);
|
|
85
|
+
this.name = "RegistryAuthError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
async function fetchRemoteCards(registryUrl, params, timeoutMs = 5e3) {
|
|
89
|
+
let cardsUrl;
|
|
90
|
+
try {
|
|
91
|
+
cardsUrl = new URL("/cards", registryUrl);
|
|
92
|
+
} catch {
|
|
93
|
+
throw new AgentBnBError(`Invalid registry URL: ${registryUrl}`, "INVALID_REGISTRY_URL");
|
|
94
|
+
}
|
|
95
|
+
const searchParams = new URLSearchParams();
|
|
96
|
+
if (params.q !== void 0) searchParams.set("q", params.q);
|
|
97
|
+
if (params.level !== void 0) searchParams.set("level", String(params.level));
|
|
98
|
+
if (params.online !== void 0) searchParams.set("online", String(params.online));
|
|
99
|
+
if (params.tag !== void 0) searchParams.set("tag", params.tag);
|
|
100
|
+
searchParams.set("limit", "100");
|
|
101
|
+
cardsUrl.search = searchParams.toString();
|
|
102
|
+
const controller = new AbortController();
|
|
103
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await fetch(cardsUrl.toString(), { signal: controller.signal });
|
|
107
|
+
} catch (err) {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
110
|
+
if (isTimeout) {
|
|
111
|
+
throw new RegistryTimeoutError(registryUrl);
|
|
112
|
+
}
|
|
113
|
+
throw new RegistryConnectionError(registryUrl);
|
|
114
|
+
} finally {
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
}
|
|
117
|
+
if (response.status === 401 || response.status === 403) {
|
|
118
|
+
throw new RegistryAuthError(registryUrl);
|
|
119
|
+
}
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
throw new RegistryConnectionError(registryUrl);
|
|
122
|
+
}
|
|
123
|
+
const body = await response.json();
|
|
124
|
+
return body.items;
|
|
125
|
+
}
|
|
126
|
+
function mergeResults(localCards, remoteCards, hasQuery) {
|
|
127
|
+
const taggedLocal = localCards.map((c) => ({ ...c, source: "local" }));
|
|
128
|
+
const taggedRemote = remoteCards.map((c) => ({ ...c, source: "remote" }));
|
|
129
|
+
const localIds = new Set(localCards.map((c) => c.id));
|
|
130
|
+
const dedupedRemote = taggedRemote.filter((c) => !localIds.has(c.id));
|
|
131
|
+
if (!hasQuery) {
|
|
132
|
+
return [...taggedLocal, ...dedupedRemote];
|
|
133
|
+
}
|
|
134
|
+
const result = [];
|
|
135
|
+
const maxLen = Math.max(taggedLocal.length, dedupedRemote.length);
|
|
136
|
+
for (let i = 0; i < maxLen; i++) {
|
|
137
|
+
if (i < taggedLocal.length) result.push(taggedLocal[i]);
|
|
138
|
+
if (i < dedupedRemote.length) result.push(dedupedRemote[i]);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export {
|
|
144
|
+
searchCards,
|
|
145
|
+
filterCards,
|
|
146
|
+
fetchRemoteCards,
|
|
147
|
+
mergeResults
|
|
148
|
+
};
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchRemoteCards,
|
|
3
|
+
searchCards
|
|
4
|
+
} from "./chunk-FF226TIV.js";
|
|
1
5
|
import {
|
|
2
6
|
requestCapability
|
|
3
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XND2DWTZ.js";
|
|
4
8
|
import {
|
|
5
9
|
findPeer
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-5AH3CMOX.js";
|
|
7
11
|
import {
|
|
8
12
|
getBalance,
|
|
9
13
|
holdEscrow,
|
|
10
14
|
releaseEscrow,
|
|
11
15
|
settleEscrow
|
|
12
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-DNWT5FZQ.js";
|
|
13
17
|
import {
|
|
14
18
|
AgentBnBError
|
|
15
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-WGZ5AGOX.js";
|
|
16
20
|
|
|
17
21
|
// src/autonomy/tiers.ts
|
|
18
22
|
import { randomUUID } from "crypto";
|
|
@@ -95,61 +99,6 @@ var BudgetManager = class {
|
|
|
95
99
|
}
|
|
96
100
|
};
|
|
97
101
|
|
|
98
|
-
// src/registry/matcher.ts
|
|
99
|
-
function searchCards(db, query, filters = {}) {
|
|
100
|
-
const words = query.trim().split(/\s+/).map((w) => w.replace(/["*^{}():]/g, "")).filter((w) => w.length > 0);
|
|
101
|
-
if (words.length === 0) return [];
|
|
102
|
-
const ftsQuery = words.map((w) => `"${w}"`).join(" OR ");
|
|
103
|
-
const conditions = [];
|
|
104
|
-
const params = [ftsQuery];
|
|
105
|
-
if (filters.level !== void 0) {
|
|
106
|
-
conditions.push(`json_extract(cc.data, '$.level') = ?`);
|
|
107
|
-
params.push(filters.level);
|
|
108
|
-
}
|
|
109
|
-
if (filters.online !== void 0) {
|
|
110
|
-
conditions.push(`json_extract(cc.data, '$.availability.online') = ?`);
|
|
111
|
-
params.push(filters.online ? 1 : 0);
|
|
112
|
-
}
|
|
113
|
-
const whereClause = conditions.length > 0 ? `AND ${conditions.join(" AND ")}` : "";
|
|
114
|
-
const sql = `
|
|
115
|
-
SELECT cc.data
|
|
116
|
-
FROM capability_cards cc
|
|
117
|
-
JOIN cards_fts ON cc.rowid = cards_fts.rowid
|
|
118
|
-
WHERE cards_fts MATCH ?
|
|
119
|
-
${whereClause}
|
|
120
|
-
ORDER BY bm25(cards_fts)
|
|
121
|
-
LIMIT 50
|
|
122
|
-
`;
|
|
123
|
-
const stmt = db.prepare(sql);
|
|
124
|
-
const rows = stmt.all(...params);
|
|
125
|
-
const results = rows.map((row) => JSON.parse(row.data));
|
|
126
|
-
if (filters.apis_used && filters.apis_used.length > 0) {
|
|
127
|
-
const requiredApis = filters.apis_used;
|
|
128
|
-
return results.filter((card) => {
|
|
129
|
-
const cardApis = card.metadata?.apis_used ?? [];
|
|
130
|
-
return requiredApis.every((api) => cardApis.includes(api));
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return results;
|
|
134
|
-
}
|
|
135
|
-
function filterCards(db, filters) {
|
|
136
|
-
const conditions = [];
|
|
137
|
-
const params = [];
|
|
138
|
-
if (filters.level !== void 0) {
|
|
139
|
-
conditions.push(`json_extract(data, '$.level') = ?`);
|
|
140
|
-
params.push(filters.level);
|
|
141
|
-
}
|
|
142
|
-
if (filters.online !== void 0) {
|
|
143
|
-
conditions.push(`json_extract(data, '$.availability.online') = ?`);
|
|
144
|
-
params.push(filters.online ? 1 : 0);
|
|
145
|
-
}
|
|
146
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
147
|
-
const sql = `SELECT data FROM capability_cards ${whereClause}`;
|
|
148
|
-
const stmt = db.prepare(sql);
|
|
149
|
-
const rows = stmt.all(...params);
|
|
150
|
-
return rows.map((row) => JSON.parse(row.data));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
102
|
// src/autonomy/pending-requests.ts
|
|
154
103
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
155
104
|
function createPendingRequest(db, opts) {
|
|
@@ -228,6 +177,7 @@ var AutoRequestor = class {
|
|
|
228
177
|
creditDb;
|
|
229
178
|
autonomyConfig;
|
|
230
179
|
budgetManager;
|
|
180
|
+
registryUrl;
|
|
231
181
|
/**
|
|
232
182
|
* Creates a new AutoRequestor.
|
|
233
183
|
*
|
|
@@ -239,6 +189,7 @@ var AutoRequestor = class {
|
|
|
239
189
|
this.creditDb = opts.creditDb;
|
|
240
190
|
this.autonomyConfig = opts.autonomyConfig;
|
|
241
191
|
this.budgetManager = opts.budgetManager;
|
|
192
|
+
this.registryUrl = opts.registryUrl;
|
|
242
193
|
}
|
|
243
194
|
/**
|
|
244
195
|
* Executes an autonomous capability request.
|
|
@@ -259,7 +210,23 @@ var AutoRequestor = class {
|
|
|
259
210
|
* @returns The result of the auto-request attempt.
|
|
260
211
|
*/
|
|
261
212
|
async requestWithAutonomy(need) {
|
|
262
|
-
|
|
213
|
+
let cards = searchCards(this.registryDb, need.query, { online: true });
|
|
214
|
+
if (cards.length === 0 && this.registryUrl) {
|
|
215
|
+
try {
|
|
216
|
+
cards = await fetchRemoteCards(this.registryUrl, { q: need.query, online: true });
|
|
217
|
+
} catch {
|
|
218
|
+
insertAuditEvent(this.registryDb, {
|
|
219
|
+
type: "auto_request_failed",
|
|
220
|
+
card_id: "none",
|
|
221
|
+
skill_id: "none",
|
|
222
|
+
tier_invoked: 3,
|
|
223
|
+
credits: 0,
|
|
224
|
+
peer: "none",
|
|
225
|
+
reason: `Remote registry fallback failed for query "${need.query}"`
|
|
226
|
+
});
|
|
227
|
+
cards = [];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
263
230
|
const candidates = [];
|
|
264
231
|
for (const card of cards) {
|
|
265
232
|
const cardAsV2 = card;
|
|
@@ -380,64 +347,14 @@ var AutoRequestor = class {
|
|
|
380
347
|
}
|
|
381
348
|
};
|
|
382
349
|
|
|
383
|
-
// src/utils/interpolation.ts
|
|
384
|
-
function resolvePath(obj, path) {
|
|
385
|
-
const segments = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter((s) => s.length > 0);
|
|
386
|
-
let current = obj;
|
|
387
|
-
for (const segment of segments) {
|
|
388
|
-
if (current === null || current === void 0) {
|
|
389
|
-
return void 0;
|
|
390
|
-
}
|
|
391
|
-
if (typeof current !== "object") {
|
|
392
|
-
return void 0;
|
|
393
|
-
}
|
|
394
|
-
current = current[segment];
|
|
395
|
-
}
|
|
396
|
-
return current;
|
|
397
|
-
}
|
|
398
|
-
function interpolate(template, context) {
|
|
399
|
-
return template.replace(/\$\{([^}]+)\}/g, (_match, expression) => {
|
|
400
|
-
const resolved = resolvePath(context, expression.trim());
|
|
401
|
-
if (resolved === void 0 || resolved === null) {
|
|
402
|
-
return "";
|
|
403
|
-
}
|
|
404
|
-
if (typeof resolved === "object") {
|
|
405
|
-
return JSON.stringify(resolved);
|
|
406
|
-
}
|
|
407
|
-
return String(resolved);
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
function interpolateObject(obj, context) {
|
|
411
|
-
const result = {};
|
|
412
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
413
|
-
result[key] = interpolateValue(value, context);
|
|
414
|
-
}
|
|
415
|
-
return result;
|
|
416
|
-
}
|
|
417
|
-
function interpolateValue(value, context) {
|
|
418
|
-
if (typeof value === "string") {
|
|
419
|
-
return interpolate(value, context);
|
|
420
|
-
}
|
|
421
|
-
if (Array.isArray(value)) {
|
|
422
|
-
return value.map((item) => interpolateValue(item, context));
|
|
423
|
-
}
|
|
424
|
-
if (value !== null && typeof value === "object") {
|
|
425
|
-
return interpolateObject(value, context);
|
|
426
|
-
}
|
|
427
|
-
return value;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
350
|
export {
|
|
431
351
|
DEFAULT_AUTONOMY_CONFIG,
|
|
432
352
|
getAutonomyTier,
|
|
433
353
|
insertAuditEvent,
|
|
434
354
|
DEFAULT_BUDGET_CONFIG,
|
|
435
355
|
BudgetManager,
|
|
436
|
-
searchCards,
|
|
437
|
-
filterCards,
|
|
438
356
|
listPendingRequests,
|
|
439
357
|
resolvePendingRequest,
|
|
440
358
|
scorePeers,
|
|
441
|
-
AutoRequestor
|
|
442
|
-
interpolateObject
|
|
359
|
+
AutoRequestor
|
|
443
360
|
};
|