agentbnb 8.0.1 → 8.2.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.
- package/dist/{conductor-mode-2GSLHVN6.js → chunk-P4LOYSLA.js} +624 -260
- package/dist/cli/index.js +15 -5
- package/dist/conductor-mode-TFCVCQHU.js +266 -0
- package/dist/{server-MHMAYXWZ.js → server-LMY2A3GT.js} +2 -4
- package/dist/skills/agentbnb/bootstrap.js +717 -13
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/skills/agentbnb/bootstrap.test.ts +34 -0
- package/skills/agentbnb/bootstrap.ts +28 -0
- package/skills/agentbnb/openclaw-tools.test.ts +328 -0
- package/skills/agentbnb/openclaw-tools.ts +297 -0
- package/dist/chunk-B2VJTKO5.js +0 -393
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AutoRequestor,
|
|
3
|
+
BudgetController,
|
|
4
|
+
BudgetManager,
|
|
2
5
|
DEFAULT_AUTONOMY_CONFIG,
|
|
6
|
+
DEFAULT_BUDGET_CONFIG,
|
|
7
|
+
ORCHESTRATION_FEE,
|
|
3
8
|
buildReputationMap,
|
|
4
9
|
computeReputation,
|
|
10
|
+
decompose,
|
|
5
11
|
fetchRemoteCards,
|
|
6
12
|
filterCards,
|
|
7
13
|
getAutonomyTier,
|
|
8
14
|
insertAuditEvent,
|
|
9
15
|
interpolateObject,
|
|
10
16
|
listPendingRequests,
|
|
17
|
+
matchSubTasks,
|
|
18
|
+
mergeResults,
|
|
19
|
+
orchestrate,
|
|
11
20
|
requestCapability,
|
|
12
21
|
requestViaRelay,
|
|
13
22
|
resolvePendingRequest,
|
|
14
23
|
searchCards
|
|
15
|
-
} from "../../chunk-
|
|
24
|
+
} from "../../chunk-P4LOYSLA.js";
|
|
25
|
+
import {
|
|
26
|
+
loadPeers
|
|
27
|
+
} from "../../chunk-HLUEOLSZ.js";
|
|
16
28
|
import {
|
|
17
29
|
executeCapabilityBatch,
|
|
18
30
|
executeCapabilityRequest,
|
|
@@ -67,8 +79,8 @@ import {
|
|
|
67
79
|
} from "../../chunk-3LWBH7P3.js";
|
|
68
80
|
|
|
69
81
|
// skills/agentbnb/bootstrap.ts
|
|
70
|
-
import { join as
|
|
71
|
-
import { homedir as
|
|
82
|
+
import { join as join6, basename, dirname as dirname4 } from "path";
|
|
83
|
+
import { homedir as homedir3 } from "os";
|
|
72
84
|
import { spawnSync, exec } from "child_process";
|
|
73
85
|
import { promisify as promisify2 } from "util";
|
|
74
86
|
import { randomUUID as randomUUID10 } from "crypto";
|
|
@@ -1259,12 +1271,12 @@ var AgentRuntime = class {
|
|
|
1259
1271
|
}
|
|
1260
1272
|
const modes = /* @__PURE__ */ new Map();
|
|
1261
1273
|
if (this.conductorEnabled) {
|
|
1262
|
-
const { ConductorMode } = await import("../../conductor-mode-
|
|
1274
|
+
const { ConductorMode } = await import("../../conductor-mode-TFCVCQHU.js");
|
|
1263
1275
|
const { registerConductorCard, CONDUCTOR_OWNER } = await import("../../card-EX2EYGCZ.js");
|
|
1264
|
-
const { loadPeers } = await import("../../peers-CJ7T4RJO.js");
|
|
1276
|
+
const { loadPeers: loadPeers2 } = await import("../../peers-CJ7T4RJO.js");
|
|
1265
1277
|
registerConductorCard(this.registryDb);
|
|
1266
1278
|
const resolveAgentUrl = (owner) => {
|
|
1267
|
-
const peers =
|
|
1279
|
+
const peers = loadPeers2();
|
|
1268
1280
|
const peer = peers.find((p) => p.name.toLowerCase() === owner.toLowerCase());
|
|
1269
1281
|
if (!peer) {
|
|
1270
1282
|
throw new Error(
|
|
@@ -6735,24 +6747,705 @@ function isNetworkError(err) {
|
|
|
6735
6747
|
return msg.includes("NETWORK_ERROR") || msg.includes("ECONNREFUSED") || msg.includes("fetch failed") || msg.includes("Network error");
|
|
6736
6748
|
}
|
|
6737
6749
|
|
|
6750
|
+
// skills/agentbnb/openclaw-tools.ts
|
|
6751
|
+
import { readFileSync as readFileSync5, existsSync as existsSync6 } from "fs";
|
|
6752
|
+
import { join as join5 } from "path";
|
|
6753
|
+
import { homedir as homedir2 } from "os";
|
|
6754
|
+
|
|
6755
|
+
// src/mcp/tools/discover.ts
|
|
6756
|
+
import { z as z9 } from "zod";
|
|
6757
|
+
var discoverInputSchema = {
|
|
6758
|
+
query: z9.string().describe("Natural language search query"),
|
|
6759
|
+
level: z9.number().optional().describe("Filter by capability level (1=Atomic, 2=Pipeline, 3=Environment)"),
|
|
6760
|
+
online_only: z9.boolean().optional().describe("Only show online agents")
|
|
6761
|
+
};
|
|
6762
|
+
async function handleDiscover(args, ctx) {
|
|
6763
|
+
try {
|
|
6764
|
+
const db = openDatabase(ctx.config.db_path);
|
|
6765
|
+
let localCards;
|
|
6766
|
+
try {
|
|
6767
|
+
localCards = searchCards(db, args.query, {
|
|
6768
|
+
level: args.level,
|
|
6769
|
+
online: args.online_only
|
|
6770
|
+
});
|
|
6771
|
+
} finally {
|
|
6772
|
+
db.close();
|
|
6773
|
+
}
|
|
6774
|
+
let remoteCards = [];
|
|
6775
|
+
if (ctx.config.registry) {
|
|
6776
|
+
try {
|
|
6777
|
+
remoteCards = await fetchRemoteCards(ctx.config.registry, {
|
|
6778
|
+
q: args.query,
|
|
6779
|
+
level: args.level,
|
|
6780
|
+
online: args.online_only
|
|
6781
|
+
});
|
|
6782
|
+
} catch {
|
|
6783
|
+
}
|
|
6784
|
+
}
|
|
6785
|
+
const merged = mergeResults(localCards, remoteCards, true);
|
|
6786
|
+
const results = merged.map((card) => {
|
|
6787
|
+
const raw = card;
|
|
6788
|
+
const skills = Array.isArray(raw["skills"]) ? raw["skills"].map((s) => ({
|
|
6789
|
+
id: s.id,
|
|
6790
|
+
name: s.name,
|
|
6791
|
+
description: s.description,
|
|
6792
|
+
credits_per_call: s.pricing.credits_per_call
|
|
6793
|
+
})) : void 0;
|
|
6794
|
+
return {
|
|
6795
|
+
id: card.id,
|
|
6796
|
+
name: card.name,
|
|
6797
|
+
owner: card.owner,
|
|
6798
|
+
description: card.description,
|
|
6799
|
+
level: card.level,
|
|
6800
|
+
skills,
|
|
6801
|
+
pricing: card.pricing,
|
|
6802
|
+
source: card.source,
|
|
6803
|
+
online: card.availability?.online ?? false
|
|
6804
|
+
};
|
|
6805
|
+
});
|
|
6806
|
+
return {
|
|
6807
|
+
content: [{ type: "text", text: JSON.stringify({ results, count: results.length }, null, 2) }]
|
|
6808
|
+
};
|
|
6809
|
+
} catch (err) {
|
|
6810
|
+
const message = err instanceof Error ? err.message : "Unknown error during discover";
|
|
6811
|
+
return {
|
|
6812
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: message }) }]
|
|
6813
|
+
};
|
|
6814
|
+
}
|
|
6815
|
+
}
|
|
6816
|
+
|
|
6817
|
+
// src/mcp/tools/request.ts
|
|
6818
|
+
import { z as z10 } from "zod";
|
|
6819
|
+
var requestInputSchema = {
|
|
6820
|
+
query: z10.string().optional().describe("Search query to find a matching capability (auto-request mode)"),
|
|
6821
|
+
card_id: z10.string().optional().describe("Direct card ID to request (skips search)"),
|
|
6822
|
+
skill_id: z10.string().optional().describe("Specific skill within a v2.0 card"),
|
|
6823
|
+
params: z10.record(z10.unknown()).optional().describe("Input parameters for the capability"),
|
|
6824
|
+
max_cost: z10.number().optional().default(50).describe("Maximum credits to spend")
|
|
6825
|
+
};
|
|
6826
|
+
async function handleRequest(args, ctx) {
|
|
6827
|
+
try {
|
|
6828
|
+
const maxCost = args.max_cost ?? 50;
|
|
6829
|
+
if (args.query) {
|
|
6830
|
+
const registryDb = openDatabase(ctx.config.db_path);
|
|
6831
|
+
const creditDb = openCreditDb(ctx.config.credit_db_path);
|
|
6832
|
+
registryDb.pragma("busy_timeout = 5000");
|
|
6833
|
+
creditDb.pragma("busy_timeout = 5000");
|
|
6834
|
+
try {
|
|
6835
|
+
const budgetManager = new BudgetManager(
|
|
6836
|
+
creditDb,
|
|
6837
|
+
ctx.config.owner,
|
|
6838
|
+
ctx.config.budget ?? DEFAULT_BUDGET_CONFIG
|
|
6839
|
+
);
|
|
6840
|
+
const requestor = new AutoRequestor({
|
|
6841
|
+
owner: ctx.config.owner,
|
|
6842
|
+
registryDb,
|
|
6843
|
+
creditDb,
|
|
6844
|
+
autonomyConfig: ctx.config.autonomy ?? DEFAULT_AUTONOMY_CONFIG,
|
|
6845
|
+
budgetManager,
|
|
6846
|
+
registryUrl: ctx.config.registry
|
|
6847
|
+
});
|
|
6848
|
+
const result = await requestor.requestWithAutonomy({
|
|
6849
|
+
query: args.query,
|
|
6850
|
+
maxCostCredits: maxCost,
|
|
6851
|
+
params: args.params
|
|
6852
|
+
});
|
|
6853
|
+
return {
|
|
6854
|
+
content: [{ type: "text", text: JSON.stringify({ success: true, ...result }, null, 2) }]
|
|
6855
|
+
};
|
|
6856
|
+
} finally {
|
|
6857
|
+
registryDb.close();
|
|
6858
|
+
creditDb.close();
|
|
6859
|
+
}
|
|
6860
|
+
}
|
|
6861
|
+
if (args.card_id) {
|
|
6862
|
+
const cardId = args.card_id;
|
|
6863
|
+
const db = openDatabase(ctx.config.db_path);
|
|
6864
|
+
let localCard;
|
|
6865
|
+
try {
|
|
6866
|
+
const row = db.prepare("SELECT data FROM capability_cards WHERE id = ?").get(cardId);
|
|
6867
|
+
if (row) {
|
|
6868
|
+
localCard = JSON.parse(row.data);
|
|
6869
|
+
}
|
|
6870
|
+
} finally {
|
|
6871
|
+
db.close();
|
|
6872
|
+
}
|
|
6873
|
+
if (localCard && localCard.owner === ctx.config.owner) {
|
|
6874
|
+
const result = await requestCapability({
|
|
6875
|
+
gatewayUrl: ctx.config.gateway_url,
|
|
6876
|
+
token: ctx.config.token,
|
|
6877
|
+
cardId,
|
|
6878
|
+
params: { ...args.params ?? {}, ...args.skill_id ? { skill_id: args.skill_id } : {}, requester: ctx.config.owner }
|
|
6879
|
+
});
|
|
6880
|
+
return {
|
|
6881
|
+
content: [{ type: "text", text: JSON.stringify({ success: true, result }, null, 2) }]
|
|
6882
|
+
};
|
|
6883
|
+
}
|
|
6884
|
+
if (!ctx.config.registry) {
|
|
6885
|
+
return {
|
|
6886
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Card not found locally and no remote registry configured" }) }]
|
|
6887
|
+
};
|
|
6888
|
+
}
|
|
6889
|
+
const cardUrl = `${ctx.config.registry.replace(/\/$/, "")}/cards/${cardId}`;
|
|
6890
|
+
let remoteCard;
|
|
6891
|
+
try {
|
|
6892
|
+
const resp = await fetch(cardUrl);
|
|
6893
|
+
if (!resp.ok) {
|
|
6894
|
+
return {
|
|
6895
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: `Card ${cardId} not found on remote registry (${resp.status})` }) }]
|
|
6896
|
+
};
|
|
6897
|
+
}
|
|
6898
|
+
remoteCard = await resp.json();
|
|
6899
|
+
} catch (err) {
|
|
6900
|
+
const msg = err instanceof Error ? err.message : "Registry unreachable";
|
|
6901
|
+
return {
|
|
6902
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: `Cannot reach registry: ${msg}` }) }]
|
|
6903
|
+
};
|
|
6904
|
+
}
|
|
6905
|
+
const targetOwner = remoteCard["owner"] ?? remoteCard["agent_name"];
|
|
6906
|
+
const gatewayUrl = remoteCard["gateway_url"];
|
|
6907
|
+
if (gatewayUrl) {
|
|
6908
|
+
const keys = loadKeyPair(ctx.configDir);
|
|
6909
|
+
const ledger = createLedger({
|
|
6910
|
+
registryUrl: ctx.config.registry,
|
|
6911
|
+
ownerPublicKey: ctx.identity.public_key,
|
|
6912
|
+
privateKey: keys.privateKey
|
|
6913
|
+
});
|
|
6914
|
+
const { escrowId } = await ledger.hold(ctx.config.owner, maxCost, cardId);
|
|
6915
|
+
try {
|
|
6916
|
+
const result = await requestCapability({
|
|
6917
|
+
gatewayUrl,
|
|
6918
|
+
token: "",
|
|
6919
|
+
cardId,
|
|
6920
|
+
params: { ...args.params ?? {}, ...args.skill_id ? { skill_id: args.skill_id } : {}, requester: ctx.config.owner }
|
|
6921
|
+
});
|
|
6922
|
+
await ledger.settle(escrowId, targetOwner ?? "unknown");
|
|
6923
|
+
return {
|
|
6924
|
+
content: [{ type: "text", text: JSON.stringify({ success: true, result, credits_spent: maxCost }, null, 2) }]
|
|
6925
|
+
};
|
|
6926
|
+
} catch (err) {
|
|
6927
|
+
await ledger.release(escrowId);
|
|
6928
|
+
throw err;
|
|
6929
|
+
}
|
|
6930
|
+
}
|
|
6931
|
+
if (targetOwner) {
|
|
6932
|
+
const relay = new RelayClient({
|
|
6933
|
+
registryUrl: ctx.config.registry,
|
|
6934
|
+
owner: ctx.config.owner,
|
|
6935
|
+
token: ctx.config.token ?? "",
|
|
6936
|
+
card: { id: ctx.config.owner, owner: ctx.config.owner, name: "mcp-requester" },
|
|
6937
|
+
onRequest: async () => ({ error: { code: -32601, message: "MCP client does not accept requests" } }),
|
|
6938
|
+
silent: true
|
|
6939
|
+
});
|
|
6940
|
+
try {
|
|
6941
|
+
await relay.connect();
|
|
6942
|
+
const result = await relay.request({
|
|
6943
|
+
targetOwner,
|
|
6944
|
+
cardId,
|
|
6945
|
+
skillId: args.skill_id,
|
|
6946
|
+
params: args.params ?? {},
|
|
6947
|
+
requester: ctx.config.owner,
|
|
6948
|
+
timeoutMs: 3e5
|
|
6949
|
+
});
|
|
6950
|
+
return {
|
|
6951
|
+
content: [{ type: "text", text: JSON.stringify({ success: true, result }, null, 2) }]
|
|
6952
|
+
};
|
|
6953
|
+
} finally {
|
|
6954
|
+
relay.disconnect();
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
return {
|
|
6958
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Remote card has no gateway_url and no owner for relay routing" }) }]
|
|
6959
|
+
};
|
|
6960
|
+
}
|
|
6961
|
+
return {
|
|
6962
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Provide either query or card_id" }) }]
|
|
6963
|
+
};
|
|
6964
|
+
} catch (err) {
|
|
6965
|
+
const message = err instanceof Error ? err.message : "Unknown error during request";
|
|
6966
|
+
return {
|
|
6967
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: message }) }]
|
|
6968
|
+
};
|
|
6969
|
+
}
|
|
6970
|
+
}
|
|
6971
|
+
|
|
6972
|
+
// src/mcp/tools/conduct.ts
|
|
6973
|
+
import { z as z11 } from "zod";
|
|
6974
|
+
|
|
6975
|
+
// src/cli/conduct.ts
|
|
6976
|
+
async function conductAction(task, opts) {
|
|
6977
|
+
const config = loadConfig();
|
|
6978
|
+
if (!config) {
|
|
6979
|
+
return { success: false, error: "Not initialized. Run `agentbnb init` first." };
|
|
6980
|
+
}
|
|
6981
|
+
const maxBudget = parseInt(opts.maxBudget ?? "100", 10);
|
|
6982
|
+
const subtasks = decompose(task);
|
|
6983
|
+
if (subtasks.length === 0) {
|
|
6984
|
+
return { success: false, error: "No matching template for this task" };
|
|
6985
|
+
}
|
|
6986
|
+
const db = openDatabase(config.db_path);
|
|
6987
|
+
let matchResults;
|
|
6988
|
+
try {
|
|
6989
|
+
matchResults = await matchSubTasks({
|
|
6990
|
+
db,
|
|
6991
|
+
subtasks,
|
|
6992
|
+
conductorOwner: config.owner,
|
|
6993
|
+
registryUrl: config.registry
|
|
6994
|
+
});
|
|
6995
|
+
} finally {
|
|
6996
|
+
db.close();
|
|
6997
|
+
}
|
|
6998
|
+
const creditDb = openCreditDb(config.credit_db_path);
|
|
6999
|
+
let budget;
|
|
7000
|
+
try {
|
|
7001
|
+
const budgetManager = new BudgetManager(creditDb, config.owner);
|
|
7002
|
+
const budgetController = new BudgetController(budgetManager, maxBudget);
|
|
7003
|
+
budget = budgetController.calculateBudget(matchResults);
|
|
7004
|
+
} finally {
|
|
7005
|
+
creditDb.close();
|
|
7006
|
+
}
|
|
7007
|
+
const plan = subtasks.map((st, i) => {
|
|
7008
|
+
const match = matchResults.find((m) => m.subtask_id === st.id);
|
|
7009
|
+
return {
|
|
7010
|
+
step: i + 1,
|
|
7011
|
+
description: st.description,
|
|
7012
|
+
capability: st.required_capability,
|
|
7013
|
+
agent: match?.selected_agent || "(unmatched)",
|
|
7014
|
+
credits: match?.credits ?? st.estimated_credits,
|
|
7015
|
+
depends_on: st.depends_on
|
|
7016
|
+
};
|
|
7017
|
+
});
|
|
7018
|
+
const planOutput = {
|
|
7019
|
+
steps: plan,
|
|
7020
|
+
orchestration_fee: ORCHESTRATION_FEE,
|
|
7021
|
+
estimated_total: budget.estimated_total,
|
|
7022
|
+
max_budget: maxBudget
|
|
7023
|
+
};
|
|
7024
|
+
if (opts.planOnly) {
|
|
7025
|
+
return { success: true, plan: planOutput };
|
|
7026
|
+
}
|
|
7027
|
+
const peers = loadPeers();
|
|
7028
|
+
const matchMap = new Map(
|
|
7029
|
+
matchResults.map((m) => [m.subtask_id, m])
|
|
7030
|
+
);
|
|
7031
|
+
const resolveAgentUrl = (owner) => {
|
|
7032
|
+
const peer = peers.find((p) => p.name.toLowerCase() === owner.toLowerCase());
|
|
7033
|
+
if (peer) {
|
|
7034
|
+
const execDb = openDatabase(config.db_path);
|
|
7035
|
+
try {
|
|
7036
|
+
const stmt = execDb.prepare("SELECT id FROM capability_cards WHERE owner = ? LIMIT 1");
|
|
7037
|
+
const row = stmt.get(owner);
|
|
7038
|
+
return { url: peer.url, cardId: row?.id ?? owner };
|
|
7039
|
+
} finally {
|
|
7040
|
+
execDb.close();
|
|
7041
|
+
}
|
|
7042
|
+
}
|
|
7043
|
+
if (config.registry) {
|
|
7044
|
+
let cardId = owner;
|
|
7045
|
+
for (const m of matchMap.values()) {
|
|
7046
|
+
if (m.selected_agent === owner && m.selected_card_id) {
|
|
7047
|
+
cardId = m.selected_card_id;
|
|
7048
|
+
break;
|
|
7049
|
+
}
|
|
7050
|
+
}
|
|
7051
|
+
return { url: `relay://${owner}`, cardId };
|
|
7052
|
+
}
|
|
7053
|
+
throw new Error(
|
|
7054
|
+
`Unknown peer "${owner}". Add with: agentbnb connect ${owner} <url> <token>`
|
|
7055
|
+
);
|
|
7056
|
+
};
|
|
7057
|
+
let relay;
|
|
7058
|
+
if (config.registry) {
|
|
7059
|
+
relay = new RelayClient({
|
|
7060
|
+
registryUrl: config.registry,
|
|
7061
|
+
owner: config.owner,
|
|
7062
|
+
token: config.token ?? "",
|
|
7063
|
+
card: { id: config.owner, owner: config.owner, name: "conductor" },
|
|
7064
|
+
onRequest: async () => ({ error: { code: -32601, message: "Conductor does not accept requests" } }),
|
|
7065
|
+
silent: true
|
|
7066
|
+
});
|
|
7067
|
+
try {
|
|
7068
|
+
await relay.connect();
|
|
7069
|
+
} catch {
|
|
7070
|
+
relay = void 0;
|
|
7071
|
+
}
|
|
7072
|
+
}
|
|
7073
|
+
let orchResult;
|
|
7074
|
+
try {
|
|
7075
|
+
orchResult = await orchestrate({
|
|
7076
|
+
subtasks,
|
|
7077
|
+
matches: matchMap,
|
|
7078
|
+
gatewayToken: config.token ?? "",
|
|
7079
|
+
resolveAgentUrl,
|
|
7080
|
+
timeoutMs: 3e5,
|
|
7081
|
+
maxBudget,
|
|
7082
|
+
relayClient: relay,
|
|
7083
|
+
requesterOwner: config.owner
|
|
7084
|
+
});
|
|
7085
|
+
} finally {
|
|
7086
|
+
relay?.disconnect();
|
|
7087
|
+
}
|
|
7088
|
+
const resultObj = {};
|
|
7089
|
+
for (const [key, value] of orchResult.results) {
|
|
7090
|
+
resultObj[key] = value;
|
|
7091
|
+
}
|
|
7092
|
+
return {
|
|
7093
|
+
success: orchResult.success,
|
|
7094
|
+
plan: planOutput,
|
|
7095
|
+
execution: resultObj,
|
|
7096
|
+
total_credits: orchResult.total_credits,
|
|
7097
|
+
latency_ms: orchResult.latency_ms,
|
|
7098
|
+
errors: orchResult.errors
|
|
7099
|
+
};
|
|
7100
|
+
}
|
|
7101
|
+
|
|
7102
|
+
// src/mcp/tools/conduct.ts
|
|
7103
|
+
var conductInputSchema = {
|
|
7104
|
+
task: z11.string().describe("Natural language task description"),
|
|
7105
|
+
plan_only: z11.boolean().optional().default(false).describe("If true, return execution plan without executing"),
|
|
7106
|
+
max_budget: z11.number().optional().default(100).describe("Maximum credits to spend")
|
|
7107
|
+
};
|
|
7108
|
+
async function handleConduct(args, _ctx) {
|
|
7109
|
+
try {
|
|
7110
|
+
const result = await conductAction(args.task, {
|
|
7111
|
+
planOnly: args.plan_only ?? false,
|
|
7112
|
+
maxBudget: String(args.max_budget ?? 100)
|
|
7113
|
+
});
|
|
7114
|
+
return {
|
|
7115
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
7116
|
+
};
|
|
7117
|
+
} catch (err) {
|
|
7118
|
+
const message = err instanceof Error ? err.message : "Unknown error during conduct";
|
|
7119
|
+
return {
|
|
7120
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: message }) }]
|
|
7121
|
+
};
|
|
7122
|
+
}
|
|
7123
|
+
}
|
|
7124
|
+
|
|
7125
|
+
// src/mcp/tools/status.ts
|
|
7126
|
+
import { z as z12 } from "zod";
|
|
7127
|
+
var statusInputSchema = {
|
|
7128
|
+
_unused: z12.string().optional().describe("No parameters needed")
|
|
7129
|
+
};
|
|
7130
|
+
async function handleStatus(ctx) {
|
|
7131
|
+
try {
|
|
7132
|
+
let balance = 0;
|
|
7133
|
+
if (ctx.config.registry) {
|
|
7134
|
+
try {
|
|
7135
|
+
const keys = loadKeyPair(ctx.configDir);
|
|
7136
|
+
const ledger = createLedger({
|
|
7137
|
+
registryUrl: ctx.config.registry,
|
|
7138
|
+
ownerPublicKey: ctx.identity.public_key,
|
|
7139
|
+
privateKey: keys.privateKey
|
|
7140
|
+
});
|
|
7141
|
+
balance = await ledger.getBalance(ctx.identity.owner);
|
|
7142
|
+
} catch {
|
|
7143
|
+
const creditDb = openCreditDb(ctx.config.credit_db_path);
|
|
7144
|
+
try {
|
|
7145
|
+
balance = getBalance(creditDb, ctx.identity.owner);
|
|
7146
|
+
} finally {
|
|
7147
|
+
creditDb.close();
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
} else {
|
|
7151
|
+
const creditDb = openCreditDb(ctx.config.credit_db_path);
|
|
7152
|
+
try {
|
|
7153
|
+
balance = getBalance(creditDb, ctx.identity.owner);
|
|
7154
|
+
} finally {
|
|
7155
|
+
creditDb.close();
|
|
7156
|
+
}
|
|
7157
|
+
}
|
|
7158
|
+
const result = {
|
|
7159
|
+
agent_id: ctx.identity.agent_id,
|
|
7160
|
+
owner: ctx.identity.owner,
|
|
7161
|
+
public_key: ctx.identity.public_key,
|
|
7162
|
+
balance,
|
|
7163
|
+
registry_url: ctx.config.registry ?? null,
|
|
7164
|
+
config_dir: ctx.configDir
|
|
7165
|
+
};
|
|
7166
|
+
return {
|
|
7167
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
7168
|
+
};
|
|
7169
|
+
} catch (err) {
|
|
7170
|
+
const message = err instanceof Error ? err.message : "Unknown error during status check";
|
|
7171
|
+
return {
|
|
7172
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: message }) }]
|
|
7173
|
+
};
|
|
7174
|
+
}
|
|
7175
|
+
}
|
|
7176
|
+
|
|
7177
|
+
// src/mcp/tools/publish.ts
|
|
7178
|
+
import { z as z13 } from "zod";
|
|
7179
|
+
var publishInputSchema = {
|
|
7180
|
+
card_json: z13.string().describe("JSON string of the capability card to publish")
|
|
7181
|
+
};
|
|
7182
|
+
async function handlePublish(args, ctx) {
|
|
7183
|
+
try {
|
|
7184
|
+
let parsed;
|
|
7185
|
+
try {
|
|
7186
|
+
parsed = JSON.parse(args.card_json);
|
|
7187
|
+
} catch {
|
|
7188
|
+
return {
|
|
7189
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Invalid JSON in card_json" }) }]
|
|
7190
|
+
};
|
|
7191
|
+
}
|
|
7192
|
+
const validated = AnyCardSchema.safeParse(parsed);
|
|
7193
|
+
if (!validated.success) {
|
|
7194
|
+
return {
|
|
7195
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Card validation failed", details: validated.error.issues }) }]
|
|
7196
|
+
};
|
|
7197
|
+
}
|
|
7198
|
+
const card = validated.data;
|
|
7199
|
+
const rawCard = card;
|
|
7200
|
+
if (Array.isArray(rawCard["skills"])) {
|
|
7201
|
+
const skills = rawCard["skills"];
|
|
7202
|
+
for (const skill of skills) {
|
|
7203
|
+
if (skill.pricing.credits_per_call < 1) {
|
|
7204
|
+
return {
|
|
7205
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Minimum price is 1 credit per call for each skill" }) }]
|
|
7206
|
+
};
|
|
7207
|
+
}
|
|
7208
|
+
}
|
|
7209
|
+
} else {
|
|
7210
|
+
const pricing = rawCard["pricing"];
|
|
7211
|
+
if (pricing && pricing.credits_per_call < 1) {
|
|
7212
|
+
return {
|
|
7213
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: "Minimum price is 1 credit per call" }) }]
|
|
7214
|
+
};
|
|
7215
|
+
}
|
|
7216
|
+
}
|
|
7217
|
+
const db = openDatabase(ctx.config.db_path);
|
|
7218
|
+
try {
|
|
7219
|
+
insertCard(db, card);
|
|
7220
|
+
} finally {
|
|
7221
|
+
db.close();
|
|
7222
|
+
}
|
|
7223
|
+
let remotePublished = false;
|
|
7224
|
+
if (ctx.config.registry) {
|
|
7225
|
+
try {
|
|
7226
|
+
const publishUrl = new URL("/cards", ctx.config.registry);
|
|
7227
|
+
const body = {
|
|
7228
|
+
...card,
|
|
7229
|
+
gateway_url: ctx.config.gateway_url
|
|
7230
|
+
};
|
|
7231
|
+
const res = await fetch(publishUrl.toString(), {
|
|
7232
|
+
method: "POST",
|
|
7233
|
+
headers: { "Content-Type": "application/json" },
|
|
7234
|
+
body: JSON.stringify(body)
|
|
7235
|
+
});
|
|
7236
|
+
remotePublished = res.ok;
|
|
7237
|
+
} catch {
|
|
7238
|
+
}
|
|
7239
|
+
}
|
|
7240
|
+
return {
|
|
7241
|
+
content: [{ type: "text", text: JSON.stringify({
|
|
7242
|
+
success: true,
|
|
7243
|
+
card_id: card.id,
|
|
7244
|
+
card_name: rawCard["name"] ?? rawCard["agent_name"] ?? card.id,
|
|
7245
|
+
remote_published: remotePublished
|
|
7246
|
+
}, null, 2) }]
|
|
7247
|
+
};
|
|
7248
|
+
} catch (err) {
|
|
7249
|
+
const message = err instanceof Error ? err.message : "Unknown error during publish";
|
|
7250
|
+
return {
|
|
7251
|
+
content: [{ type: "text", text: JSON.stringify({ success: false, error: message }) }]
|
|
7252
|
+
};
|
|
7253
|
+
}
|
|
7254
|
+
}
|
|
7255
|
+
|
|
7256
|
+
// skills/agentbnb/openclaw-tools.ts
|
|
7257
|
+
var contextCache = /* @__PURE__ */ new Map();
|
|
7258
|
+
function resolveConfigDir(toolCtx) {
|
|
7259
|
+
if (toolCtx.agentDir) {
|
|
7260
|
+
return toolCtx.agentDir.endsWith(".agentbnb") ? toolCtx.agentDir : join5(toolCtx.agentDir, ".agentbnb");
|
|
7261
|
+
}
|
|
7262
|
+
if (toolCtx.workspaceDir) {
|
|
7263
|
+
return join5(toolCtx.workspaceDir, ".agentbnb");
|
|
7264
|
+
}
|
|
7265
|
+
return join5(homedir2(), ".agentbnb");
|
|
7266
|
+
}
|
|
7267
|
+
function buildMcpContext(toolCtx) {
|
|
7268
|
+
const configDir = resolveConfigDir(toolCtx);
|
|
7269
|
+
const cached = contextCache.get(configDir);
|
|
7270
|
+
if (cached) return cached;
|
|
7271
|
+
const configPath = join5(configDir, "config.json");
|
|
7272
|
+
if (!existsSync6(configPath)) {
|
|
7273
|
+
throw new Error(
|
|
7274
|
+
`AgentBnB not initialized at ${configDir}. Run \`agentbnb init\` or activate the plugin first.`
|
|
7275
|
+
);
|
|
7276
|
+
}
|
|
7277
|
+
const config = JSON.parse(readFileSync5(configPath, "utf-8"));
|
|
7278
|
+
const identity = ensureIdentity(configDir, config.owner);
|
|
7279
|
+
const ctx = { configDir, config, identity };
|
|
7280
|
+
contextCache.set(configDir, ctx);
|
|
7281
|
+
return ctx;
|
|
7282
|
+
}
|
|
7283
|
+
function toAgentToolResult(mcpResult) {
|
|
7284
|
+
const text = mcpResult.content[0]?.text ?? "{}";
|
|
7285
|
+
let details;
|
|
7286
|
+
try {
|
|
7287
|
+
details = JSON.parse(text);
|
|
7288
|
+
} catch {
|
|
7289
|
+
details = void 0;
|
|
7290
|
+
}
|
|
7291
|
+
return { content: text, details };
|
|
7292
|
+
}
|
|
7293
|
+
function createDiscoverTool(toolCtx) {
|
|
7294
|
+
return {
|
|
7295
|
+
name: "agentbnb-discover",
|
|
7296
|
+
label: "AgentBnB Discover",
|
|
7297
|
+
description: "Search for agent capabilities on the AgentBnB network. Returns matching capability cards from both local and remote registries.",
|
|
7298
|
+
parameters: {
|
|
7299
|
+
type: "object",
|
|
7300
|
+
properties: {
|
|
7301
|
+
query: { type: "string", description: "Natural language search query" },
|
|
7302
|
+
level: {
|
|
7303
|
+
type: "number",
|
|
7304
|
+
description: "Filter by capability level (1=Atomic, 2=Pipeline, 3=Environment)"
|
|
7305
|
+
},
|
|
7306
|
+
online_only: { type: "boolean", description: "Only show online agents" }
|
|
7307
|
+
},
|
|
7308
|
+
required: ["query"]
|
|
7309
|
+
},
|
|
7310
|
+
async execute(_toolCallId, params) {
|
|
7311
|
+
const ctx = buildMcpContext(toolCtx);
|
|
7312
|
+
const result = await handleDiscover(
|
|
7313
|
+
params,
|
|
7314
|
+
ctx
|
|
7315
|
+
);
|
|
7316
|
+
return toAgentToolResult(result);
|
|
7317
|
+
}
|
|
7318
|
+
};
|
|
7319
|
+
}
|
|
7320
|
+
function createRequestTool(toolCtx) {
|
|
7321
|
+
return {
|
|
7322
|
+
name: "agentbnb-request",
|
|
7323
|
+
label: "AgentBnB Request",
|
|
7324
|
+
description: "Request execution of a skill from another agent on the AgentBnB network. Handles credit escrow automatically.",
|
|
7325
|
+
parameters: {
|
|
7326
|
+
type: "object",
|
|
7327
|
+
properties: {
|
|
7328
|
+
query: {
|
|
7329
|
+
type: "string",
|
|
7330
|
+
description: "Search query to find a matching capability (auto-request mode)"
|
|
7331
|
+
},
|
|
7332
|
+
card_id: { type: "string", description: "Direct card ID to request (skips search)" },
|
|
7333
|
+
skill_id: { type: "string", description: "Specific skill within a v2.0 card" },
|
|
7334
|
+
params: { type: "object", description: "Input parameters for the capability" },
|
|
7335
|
+
max_cost: {
|
|
7336
|
+
type: "number",
|
|
7337
|
+
description: "Maximum credits to spend (default: 50)"
|
|
7338
|
+
}
|
|
7339
|
+
},
|
|
7340
|
+
required: []
|
|
7341
|
+
},
|
|
7342
|
+
async execute(_toolCallId, params) {
|
|
7343
|
+
const ctx = buildMcpContext(toolCtx);
|
|
7344
|
+
const result = await handleRequest(
|
|
7345
|
+
params,
|
|
7346
|
+
ctx
|
|
7347
|
+
);
|
|
7348
|
+
return toAgentToolResult(result);
|
|
7349
|
+
}
|
|
7350
|
+
};
|
|
7351
|
+
}
|
|
7352
|
+
function createConductTool(toolCtx) {
|
|
7353
|
+
return {
|
|
7354
|
+
name: "agentbnb-conduct",
|
|
7355
|
+
label: "AgentBnB Conduct",
|
|
7356
|
+
description: "Orchestrate a complex task across multiple agents on the AgentBnB network. Decomposes the task, matches sub-tasks to agents, and executes the pipeline.",
|
|
7357
|
+
parameters: {
|
|
7358
|
+
type: "object",
|
|
7359
|
+
properties: {
|
|
7360
|
+
task: { type: "string", description: "Natural language task description" },
|
|
7361
|
+
plan_only: {
|
|
7362
|
+
type: "boolean",
|
|
7363
|
+
description: "If true, return execution plan without executing"
|
|
7364
|
+
},
|
|
7365
|
+
max_budget: {
|
|
7366
|
+
type: "number",
|
|
7367
|
+
description: "Maximum credits to spend (default: 100)"
|
|
7368
|
+
}
|
|
7369
|
+
},
|
|
7370
|
+
required: ["task"]
|
|
7371
|
+
},
|
|
7372
|
+
async execute(_toolCallId, params) {
|
|
7373
|
+
const ctx = buildMcpContext(toolCtx);
|
|
7374
|
+
const result = await handleConduct(
|
|
7375
|
+
params,
|
|
7376
|
+
ctx
|
|
7377
|
+
);
|
|
7378
|
+
return toAgentToolResult(result);
|
|
7379
|
+
}
|
|
7380
|
+
};
|
|
7381
|
+
}
|
|
7382
|
+
function createStatusTool(toolCtx) {
|
|
7383
|
+
return {
|
|
7384
|
+
name: "agentbnb-status",
|
|
7385
|
+
label: "AgentBnB Status",
|
|
7386
|
+
description: "Check your AgentBnB agent status: identity, credit balance, and configuration.",
|
|
7387
|
+
parameters: {
|
|
7388
|
+
type: "object",
|
|
7389
|
+
properties: {},
|
|
7390
|
+
required: []
|
|
7391
|
+
},
|
|
7392
|
+
async execute(_toolCallId, _params) {
|
|
7393
|
+
const ctx = buildMcpContext(toolCtx);
|
|
7394
|
+
const result = await handleStatus(ctx);
|
|
7395
|
+
return toAgentToolResult(result);
|
|
7396
|
+
}
|
|
7397
|
+
};
|
|
7398
|
+
}
|
|
7399
|
+
function createPublishTool(toolCtx) {
|
|
7400
|
+
return {
|
|
7401
|
+
name: "agentbnb-publish",
|
|
7402
|
+
label: "AgentBnB Publish",
|
|
7403
|
+
description: "Publish a capability card to the AgentBnB network. Stores locally and optionally syncs to remote registry.",
|
|
7404
|
+
parameters: {
|
|
7405
|
+
type: "object",
|
|
7406
|
+
properties: {
|
|
7407
|
+
card_json: {
|
|
7408
|
+
type: "string",
|
|
7409
|
+
description: "JSON string of the capability card to publish"
|
|
7410
|
+
}
|
|
7411
|
+
},
|
|
7412
|
+
required: ["card_json"]
|
|
7413
|
+
},
|
|
7414
|
+
async execute(_toolCallId, params) {
|
|
7415
|
+
const ctx = buildMcpContext(toolCtx);
|
|
7416
|
+
const result = await handlePublish(params, ctx);
|
|
7417
|
+
return toAgentToolResult(result);
|
|
7418
|
+
}
|
|
7419
|
+
};
|
|
7420
|
+
}
|
|
7421
|
+
function createAllTools(toolCtx) {
|
|
7422
|
+
return [
|
|
7423
|
+
createDiscoverTool(toolCtx),
|
|
7424
|
+
createRequestTool(toolCtx),
|
|
7425
|
+
createConductTool(toolCtx),
|
|
7426
|
+
createStatusTool(toolCtx),
|
|
7427
|
+
createPublishTool(toolCtx)
|
|
7428
|
+
];
|
|
7429
|
+
}
|
|
7430
|
+
|
|
6738
7431
|
// skills/agentbnb/bootstrap.ts
|
|
6739
7432
|
var execAsync = promisify2(exec);
|
|
6740
7433
|
function resolveWorkspaceDir() {
|
|
6741
7434
|
if (process.env["AGENTBNB_DIR"]) {
|
|
6742
7435
|
return process.env["AGENTBNB_DIR"];
|
|
6743
7436
|
}
|
|
6744
|
-
const openclawAgentsDir =
|
|
7437
|
+
const openclawAgentsDir = join6(homedir3(), ".openclaw", "agents");
|
|
6745
7438
|
const cwd = process.cwd();
|
|
6746
7439
|
if (cwd.startsWith(openclawAgentsDir + "/")) {
|
|
6747
7440
|
const relative = cwd.slice(openclawAgentsDir.length + 1);
|
|
6748
7441
|
const agentName = relative.split("/")[0];
|
|
6749
|
-
return
|
|
7442
|
+
return join6(openclawAgentsDir, agentName, ".agentbnb");
|
|
6750
7443
|
}
|
|
6751
|
-
return
|
|
7444
|
+
return join6(homedir3(), ".agentbnb");
|
|
6752
7445
|
}
|
|
6753
7446
|
function registerDecomposerCard(configDir, owner) {
|
|
6754
7447
|
try {
|
|
6755
|
-
const db = openDatabase(
|
|
7448
|
+
const db = openDatabase(join6(configDir, "registry.db"));
|
|
6756
7449
|
const existing = db.prepare(
|
|
6757
7450
|
"SELECT id FROM capability_cards WHERE owner = ? AND json_extract(data, '$.capability_type') = ?"
|
|
6758
7451
|
).get(owner, "task_decomposition");
|
|
@@ -6821,7 +7514,7 @@ async function runCommand(cmd, env) {
|
|
|
6821
7514
|
}
|
|
6822
7515
|
function deriveAgentName(configDir) {
|
|
6823
7516
|
const parent = basename(dirname4(configDir));
|
|
6824
|
-
if (parent && parent !== "." && parent !== ".agentbnb" && parent !==
|
|
7517
|
+
if (parent && parent !== "." && parent !== ".agentbnb" && parent !== homedir3().split("/").pop()) {
|
|
6825
7518
|
return parent;
|
|
6826
7519
|
}
|
|
6827
7520
|
return `agent-${randomUUID10().slice(0, 8)}`;
|
|
@@ -6868,7 +7561,7 @@ async function activate(config = {}, _onboardDeps) {
|
|
|
6868
7561
|
`
|
|
6869
7562
|
);
|
|
6870
7563
|
} else if (config.workspaceDir) {
|
|
6871
|
-
const derived =
|
|
7564
|
+
const derived = join6(config.workspaceDir, ".agentbnb");
|
|
6872
7565
|
process.env["AGENTBNB_DIR"] = derived;
|
|
6873
7566
|
process.stderr.write(
|
|
6874
7567
|
`[agentbnb] AGENTBNB_DIR derived from config.workspaceDir: ${derived}
|
|
@@ -6897,7 +7590,7 @@ async function activate(config = {}, _onboardDeps) {
|
|
|
6897
7590
|
`[agentbnb] activate: owner=${agentConfig.owner} config=${configDir}/config.json
|
|
6898
7591
|
`
|
|
6899
7592
|
);
|
|
6900
|
-
const guard = new ProcessGuard(
|
|
7593
|
+
const guard = new ProcessGuard(join6(configDir, ".pid"));
|
|
6901
7594
|
const coordinator = new ServiceCoordinator(agentConfig, guard);
|
|
6902
7595
|
const service = new AgentBnBService(coordinator, agentConfig);
|
|
6903
7596
|
const opts = {
|
|
@@ -6935,9 +7628,20 @@ async function deactivate(ctx) {
|
|
|
6935
7628
|
}
|
|
6936
7629
|
}
|
|
6937
7630
|
}
|
|
7631
|
+
var bootstrap_default = {
|
|
7632
|
+
id: "agentbnb",
|
|
7633
|
+
name: "AgentBnB",
|
|
7634
|
+
description: "Where AI agents hire AI agents \u2014 discover, request, and orchestrate agent capabilities.",
|
|
7635
|
+
register(api) {
|
|
7636
|
+
api.registerTool(
|
|
7637
|
+
(toolCtx) => createAllTools(toolCtx)
|
|
7638
|
+
);
|
|
7639
|
+
}
|
|
7640
|
+
};
|
|
6938
7641
|
export {
|
|
6939
7642
|
activate,
|
|
6940
7643
|
deactivate,
|
|
7644
|
+
bootstrap_default as default,
|
|
6941
7645
|
findCli,
|
|
6942
7646
|
runCommand
|
|
6943
7647
|
};
|