agentbnb 8.0.1 → 8.2.1
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/{chunk-TBJ3FZKZ.js → chunk-7Q2XUXSA.js} +1 -1
- package/dist/{chunk-LJM7FHPM.js → chunk-BZOJ7HBT.js} +33 -1
- package/dist/{chunk-FTZTEHYG.js → chunk-DEWY7OQK.js} +135 -8
- package/dist/{chunk-CUONY5TO.js → chunk-EJKW57ZV.js} +19 -1
- package/dist/chunk-EZVOG7QS.js +161 -0
- package/dist/{chunk-E2OKP5CY.js → chunk-GJETGML6.js} +181 -83
- package/dist/{chunk-YHY7OG6S.js → chunk-GWMMYVLL.js} +4 -4
- package/dist/{chunk-D6RKW2XG.js → chunk-JLNHMNES.js} +16 -3
- package/dist/{chunk-5AAFG2V2.js → chunk-KBQNTUTN.js} +239 -24
- package/dist/{chunk-C537SFHV.js → chunk-LOUEJI6X.js} +4 -4
- package/dist/{chunk-ALX4WS3A.js → chunk-NP55V7RQ.js} +1 -1
- package/dist/{chunk-X32NE6V4.js → chunk-RBXTWWUH.js} +1 -1
- package/dist/{chunk-O2OYBAVR.js → chunk-SRBVKO2V.js} +9 -0
- package/dist/{chunk-7EF3HYVZ.js → chunk-STJLWMXH.js} +48 -4
- package/dist/{chunk-5GME4KJZ.js → chunk-UYCD3JBZ.js} +3 -3
- package/dist/chunk-WKWJWKX7.js +1460 -0
- package/dist/cli/index.js +36 -48
- package/dist/{client-HKV3QWZ3.js → client-66TFS7RS.js} +4 -2
- package/dist/{conduct-W6XF6DJW.js → conduct-A6COHLHY.js} +8 -8
- package/dist/{conduct-YB64OHI6.js → conduct-IUVAXUAV.js} +8 -8
- package/dist/conductor-mode-D5TFQW5L.js +266 -0
- package/dist/{conductor-mode-AKREGDIU.js → conductor-mode-L2MB44BW.js} +7 -7
- package/dist/{execute-AYQWORVH.js → execute-5AWLARB5.js} +5 -5
- package/dist/{execute-EPE6MZLT.js → execute-WOS457HW.js} +2 -2
- package/dist/index.js +438 -92
- package/dist/{publish-capability-AH2HDW54.js → publish-capability-JJCBBMSX.js} +2 -2
- package/dist/{request-HCCXSKAY.js → request-6YQLA7K3.js} +13 -8
- package/dist/{serve-skill-SZAQT5T5.js → serve-skill-X7TZSILV.js} +5 -5
- package/dist/{server-MHMAYXWZ.js → server-5TSP4DBX.js} +11 -15
- package/dist/{service-coordinator-WGH6B2VT.js → service-coordinator-WTUSMPY6.js} +69 -46
- package/dist/skills/agentbnb/bootstrap.js +1158 -184
- package/openclaw.plugin.json +1 -1
- package/package.json +13 -17
- package/skills/agentbnb/bootstrap.test.ts +42 -6
- package/skills/agentbnb/bootstrap.ts +49 -13
- package/skills/agentbnb/install.sh +0 -0
- package/skills/agentbnb/openclaw-tools.test.ts +328 -0
- package/skills/agentbnb/openclaw-tools.ts +297 -0
- package/dist/chunk-64AK4FJM.js +0 -84
- package/dist/chunk-B2VJTKO5.js +0 -393
- package/dist/chunk-OH7BP5NP.js +0 -96
- package/dist/conductor-mode-2GSLHVN6.js +0 -891
- package/dist/index.d.ts +0 -5069
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw tool factory — bridges AgentBnB MCP tool handlers into
|
|
3
|
+
* OpenClaw's native plugin tool system.
|
|
4
|
+
*
|
|
5
|
+
* Each tool delegates to the existing `handle*()` functions from src/mcp/tools/.
|
|
6
|
+
* Context is lazily constructed and per-agent cached to avoid process.env mutation.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { ensureIdentity } from '../../src/identity/identity.js';
|
|
13
|
+
import type { AgentBnBConfig } from '../../src/cli/config.js';
|
|
14
|
+
import type { McpServerContext } from '../../src/mcp/server.js';
|
|
15
|
+
import { handleDiscover } from '../../src/mcp/tools/discover.js';
|
|
16
|
+
import { handleRequest } from '../../src/mcp/tools/request.js';
|
|
17
|
+
import { handleConduct } from '../../src/mcp/tools/conduct.js';
|
|
18
|
+
import { handleStatus } from '../../src/mcp/tools/status.js';
|
|
19
|
+
import { handlePublish } from '../../src/mcp/tools/publish.js';
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Types
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/** Subset of OpenClaw's plugin tool context passed to tool factories. */
|
|
26
|
+
export interface OpenClawToolContext {
|
|
27
|
+
workspaceDir?: string;
|
|
28
|
+
agentDir?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** OpenClaw-compatible tool result. */
|
|
32
|
+
export interface AgentToolResult {
|
|
33
|
+
content: string;
|
|
34
|
+
details?: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** OpenClaw-compatible tool shape. */
|
|
38
|
+
export interface AgentTool {
|
|
39
|
+
name: string;
|
|
40
|
+
label: string;
|
|
41
|
+
description: string;
|
|
42
|
+
parameters: Record<string, unknown>;
|
|
43
|
+
execute: (toolCallId: string, params: Record<string, unknown>) => Promise<AgentToolResult>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Context cache — per-agent isolation keyed by configDir
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
const contextCache = new Map<string, McpServerContext>();
|
|
51
|
+
|
|
52
|
+
/** Clears the per-agent context cache. Useful for tests and daemon restarts. */
|
|
53
|
+
export function resetContextCache(): void {
|
|
54
|
+
contextCache.clear();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Resolves the configDir from OpenClaw tool context.
|
|
59
|
+
*
|
|
60
|
+
* Priority:
|
|
61
|
+
* 1. agentDir (if ends with .agentbnb, use directly; else append .agentbnb)
|
|
62
|
+
* 2. workspaceDir + /.agentbnb
|
|
63
|
+
* 3. Fallback: ~/.agentbnb
|
|
64
|
+
*/
|
|
65
|
+
export function resolveConfigDir(toolCtx: OpenClawToolContext): string {
|
|
66
|
+
if (toolCtx.agentDir) {
|
|
67
|
+
return toolCtx.agentDir.endsWith('.agentbnb')
|
|
68
|
+
? toolCtx.agentDir
|
|
69
|
+
: join(toolCtx.agentDir, '.agentbnb');
|
|
70
|
+
}
|
|
71
|
+
if (toolCtx.workspaceDir) {
|
|
72
|
+
return join(toolCtx.workspaceDir, '.agentbnb');
|
|
73
|
+
}
|
|
74
|
+
return join(homedir(), '.agentbnb');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Constructs an McpServerContext from OpenClaw tool context.
|
|
79
|
+
* Per-agent cached — same configDir reuses the same context.
|
|
80
|
+
*
|
|
81
|
+
* Reads config directly from configDir/config.json instead of mutating
|
|
82
|
+
* process.env.AGENTBNB_DIR, which avoids race conditions in the shared
|
|
83
|
+
* OpenClaw daemon process.
|
|
84
|
+
*/
|
|
85
|
+
export function buildMcpContext(toolCtx: OpenClawToolContext): McpServerContext {
|
|
86
|
+
const configDir = resolveConfigDir(toolCtx);
|
|
87
|
+
|
|
88
|
+
const cached = contextCache.get(configDir);
|
|
89
|
+
if (cached) return cached;
|
|
90
|
+
|
|
91
|
+
const configPath = join(configDir, 'config.json');
|
|
92
|
+
if (!existsSync(configPath)) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`AgentBnB not initialized at ${configDir}. Run \`agentbnb init\` or activate the plugin first.`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const config = JSON.parse(readFileSync(configPath, 'utf-8')) as AgentBnBConfig;
|
|
99
|
+
const identity = ensureIdentity(configDir, config.owner);
|
|
100
|
+
|
|
101
|
+
const ctx: McpServerContext = { configDir, config, identity };
|
|
102
|
+
contextCache.set(configDir, ctx);
|
|
103
|
+
return ctx;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Result conversion
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Converts MCP result format to OpenClaw AgentToolResult.
|
|
112
|
+
* MCP returns `{ content: [{type:'text', text: '<json>'}] }`.
|
|
113
|
+
* OpenClaw expects `{ content: string, details?: unknown }`.
|
|
114
|
+
*/
|
|
115
|
+
export function toAgentToolResult(
|
|
116
|
+
mcpResult: { content: Array<{ type: string; text: string }> },
|
|
117
|
+
): AgentToolResult {
|
|
118
|
+
const text = mcpResult.content[0]?.text ?? '{}';
|
|
119
|
+
let details: unknown;
|
|
120
|
+
try {
|
|
121
|
+
details = JSON.parse(text);
|
|
122
|
+
} catch {
|
|
123
|
+
details = undefined;
|
|
124
|
+
}
|
|
125
|
+
return { content: text, details };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Tool creators
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
/** Creates the agentbnb-discover tool. */
|
|
133
|
+
export function createDiscoverTool(toolCtx: OpenClawToolContext): AgentTool {
|
|
134
|
+
return {
|
|
135
|
+
name: 'agentbnb-discover',
|
|
136
|
+
label: 'AgentBnB Discover',
|
|
137
|
+
description:
|
|
138
|
+
'Search for agent capabilities on the AgentBnB network. Returns matching capability cards from both local and remote registries.',
|
|
139
|
+
parameters: {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {
|
|
142
|
+
query: { type: 'string', description: 'Natural language search query' },
|
|
143
|
+
level: {
|
|
144
|
+
type: 'number',
|
|
145
|
+
description: 'Filter by capability level (1=Atomic, 2=Pipeline, 3=Environment)',
|
|
146
|
+
},
|
|
147
|
+
online_only: { type: 'boolean', description: 'Only show online agents' },
|
|
148
|
+
},
|
|
149
|
+
required: ['query'],
|
|
150
|
+
},
|
|
151
|
+
async execute(_toolCallId, params) {
|
|
152
|
+
const ctx = buildMcpContext(toolCtx);
|
|
153
|
+
const result = await handleDiscover(
|
|
154
|
+
params as { query: string; level?: number; online_only?: boolean },
|
|
155
|
+
ctx,
|
|
156
|
+
);
|
|
157
|
+
return toAgentToolResult(result);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Creates the agentbnb-request tool. */
|
|
163
|
+
export function createRequestTool(toolCtx: OpenClawToolContext): AgentTool {
|
|
164
|
+
return {
|
|
165
|
+
name: 'agentbnb-request',
|
|
166
|
+
label: 'AgentBnB Request',
|
|
167
|
+
description:
|
|
168
|
+
'Request execution of a skill from another agent on the AgentBnB network. Handles credit escrow automatically.',
|
|
169
|
+
parameters: {
|
|
170
|
+
type: 'object',
|
|
171
|
+
properties: {
|
|
172
|
+
query: {
|
|
173
|
+
type: 'string',
|
|
174
|
+
description: 'Search query to find a matching capability (auto-request mode)',
|
|
175
|
+
},
|
|
176
|
+
card_id: { type: 'string', description: 'Direct card ID to request (skips search)' },
|
|
177
|
+
skill_id: { type: 'string', description: 'Specific skill within a v2.0 card' },
|
|
178
|
+
params: { type: 'object', description: 'Input parameters for the capability' },
|
|
179
|
+
max_cost: {
|
|
180
|
+
type: 'number',
|
|
181
|
+
description: 'Maximum credits to spend (default: 50)',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
required: [],
|
|
185
|
+
},
|
|
186
|
+
async execute(_toolCallId, params) {
|
|
187
|
+
const ctx = buildMcpContext(toolCtx);
|
|
188
|
+
const result = await handleRequest(
|
|
189
|
+
params as {
|
|
190
|
+
query?: string;
|
|
191
|
+
card_id?: string;
|
|
192
|
+
skill_id?: string;
|
|
193
|
+
params?: Record<string, unknown>;
|
|
194
|
+
max_cost?: number;
|
|
195
|
+
},
|
|
196
|
+
ctx,
|
|
197
|
+
);
|
|
198
|
+
return toAgentToolResult(result);
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Creates the agentbnb-conduct tool. */
|
|
204
|
+
export function createConductTool(toolCtx: OpenClawToolContext): AgentTool {
|
|
205
|
+
return {
|
|
206
|
+
name: 'agentbnb-conduct',
|
|
207
|
+
label: 'AgentBnB Conduct',
|
|
208
|
+
description:
|
|
209
|
+
'Orchestrate a complex task across multiple agents on the AgentBnB network. Decomposes the task, matches sub-tasks to agents, and executes the pipeline.',
|
|
210
|
+
parameters: {
|
|
211
|
+
type: 'object',
|
|
212
|
+
properties: {
|
|
213
|
+
task: { type: 'string', description: 'Natural language task description' },
|
|
214
|
+
plan_only: {
|
|
215
|
+
type: 'boolean',
|
|
216
|
+
description: 'If true, return execution plan without executing',
|
|
217
|
+
},
|
|
218
|
+
max_budget: {
|
|
219
|
+
type: 'number',
|
|
220
|
+
description: 'Maximum credits to spend (default: 100)',
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
required: ['task'],
|
|
224
|
+
},
|
|
225
|
+
async execute(_toolCallId, params) {
|
|
226
|
+
const ctx = buildMcpContext(toolCtx);
|
|
227
|
+
const result = await handleConduct(
|
|
228
|
+
params as { task: string; plan_only?: boolean; max_budget?: number },
|
|
229
|
+
ctx,
|
|
230
|
+
);
|
|
231
|
+
return toAgentToolResult(result);
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Creates the agentbnb-status tool. */
|
|
237
|
+
export function createStatusTool(toolCtx: OpenClawToolContext): AgentTool {
|
|
238
|
+
return {
|
|
239
|
+
name: 'agentbnb-status',
|
|
240
|
+
label: 'AgentBnB Status',
|
|
241
|
+
description:
|
|
242
|
+
'Check your AgentBnB agent status: identity, credit balance, and configuration.',
|
|
243
|
+
parameters: {
|
|
244
|
+
type: 'object',
|
|
245
|
+
properties: {},
|
|
246
|
+
required: [],
|
|
247
|
+
},
|
|
248
|
+
async execute(_toolCallId, _params) {
|
|
249
|
+
const ctx = buildMcpContext(toolCtx);
|
|
250
|
+
const result = await handleStatus(ctx);
|
|
251
|
+
return toAgentToolResult(result);
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Creates the agentbnb-publish tool. */
|
|
257
|
+
export function createPublishTool(toolCtx: OpenClawToolContext): AgentTool {
|
|
258
|
+
return {
|
|
259
|
+
name: 'agentbnb-publish',
|
|
260
|
+
label: 'AgentBnB Publish',
|
|
261
|
+
description:
|
|
262
|
+
'Publish a capability card to the AgentBnB network. Stores locally and optionally syncs to remote registry.',
|
|
263
|
+
parameters: {
|
|
264
|
+
type: 'object',
|
|
265
|
+
properties: {
|
|
266
|
+
card_json: {
|
|
267
|
+
type: 'string',
|
|
268
|
+
description: 'JSON string of the capability card to publish',
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
required: ['card_json'],
|
|
272
|
+
},
|
|
273
|
+
async execute(_toolCallId, params) {
|
|
274
|
+
const ctx = buildMcpContext(toolCtx);
|
|
275
|
+
const result = await handlePublish(params as { card_json: string }, ctx);
|
|
276
|
+
return toAgentToolResult(result);
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// Factory
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Creates all 5 AgentBnB tools for an OpenClaw bot.
|
|
287
|
+
* Called by the plugin's `register()` method via `api.registerTool()`.
|
|
288
|
+
*/
|
|
289
|
+
export function createAllTools(toolCtx: OpenClawToolContext): AgentTool[] {
|
|
290
|
+
return [
|
|
291
|
+
createDiscoverTool(toolCtx),
|
|
292
|
+
createRequestTool(toolCtx),
|
|
293
|
+
createConductTool(toolCtx),
|
|
294
|
+
createStatusTool(toolCtx),
|
|
295
|
+
createPublishTool(toolCtx),
|
|
296
|
+
];
|
|
297
|
+
}
|
package/dist/chunk-64AK4FJM.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
signEscrowReceipt
|
|
3
|
-
} from "./chunk-CUONY5TO.js";
|
|
4
|
-
import {
|
|
5
|
-
AgentBnBError
|
|
6
|
-
} from "./chunk-WVY2W7AA.js";
|
|
7
|
-
|
|
8
|
-
// src/gateway/client.ts
|
|
9
|
-
import { randomUUID } from "crypto";
|
|
10
|
-
async function requestCapability(opts) {
|
|
11
|
-
const { gatewayUrl, token, cardId, params = {}, timeoutMs = 3e5, escrowReceipt, identity } = opts;
|
|
12
|
-
const id = randomUUID();
|
|
13
|
-
const payload = {
|
|
14
|
-
jsonrpc: "2.0",
|
|
15
|
-
id,
|
|
16
|
-
method: "capability.execute",
|
|
17
|
-
params: {
|
|
18
|
-
card_id: cardId,
|
|
19
|
-
...params,
|
|
20
|
-
...escrowReceipt ? { escrow_receipt: escrowReceipt } : {}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const headers = { "Content-Type": "application/json" };
|
|
24
|
-
if (identity) {
|
|
25
|
-
const signature = signEscrowReceipt(payload, identity.privateKey);
|
|
26
|
-
headers["X-Agent-Id"] = identity.agentId;
|
|
27
|
-
headers["X-Agent-Public-Key"] = identity.publicKey;
|
|
28
|
-
headers["X-Agent-Signature"] = signature;
|
|
29
|
-
} else if (token) {
|
|
30
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
31
|
-
}
|
|
32
|
-
const controller = new AbortController();
|
|
33
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
34
|
-
let response;
|
|
35
|
-
try {
|
|
36
|
-
response = await fetch(`${gatewayUrl}/rpc`, {
|
|
37
|
-
method: "POST",
|
|
38
|
-
headers,
|
|
39
|
-
body: JSON.stringify(payload),
|
|
40
|
-
signal: controller.signal
|
|
41
|
-
});
|
|
42
|
-
} catch (err) {
|
|
43
|
-
clearTimeout(timer);
|
|
44
|
-
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
45
|
-
throw new AgentBnBError(
|
|
46
|
-
isTimeout ? "Request timed out" : `Network error: ${String(err)}`,
|
|
47
|
-
isTimeout ? "TIMEOUT" : "NETWORK_ERROR"
|
|
48
|
-
);
|
|
49
|
-
} finally {
|
|
50
|
-
clearTimeout(timer);
|
|
51
|
-
}
|
|
52
|
-
const body = await response.json();
|
|
53
|
-
if (body.error) {
|
|
54
|
-
throw new AgentBnBError(body.error.message, `RPC_ERROR_${body.error.code}`);
|
|
55
|
-
}
|
|
56
|
-
return body.result;
|
|
57
|
-
}
|
|
58
|
-
async function requestViaRelay(relay, opts) {
|
|
59
|
-
try {
|
|
60
|
-
return await relay.request({
|
|
61
|
-
targetOwner: opts.targetOwner,
|
|
62
|
-
cardId: opts.cardId,
|
|
63
|
-
skillId: opts.skillId,
|
|
64
|
-
params: opts.params ?? {},
|
|
65
|
-
requester: opts.requester,
|
|
66
|
-
escrowReceipt: opts.escrowReceipt,
|
|
67
|
-
timeoutMs: opts.timeoutMs
|
|
68
|
-
});
|
|
69
|
-
} catch (err) {
|
|
70
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
71
|
-
if (message.includes("timeout")) {
|
|
72
|
-
throw new AgentBnBError(message, "TIMEOUT");
|
|
73
|
-
}
|
|
74
|
-
if (message.includes("offline")) {
|
|
75
|
-
throw new AgentBnBError(message, "AGENT_OFFLINE");
|
|
76
|
-
}
|
|
77
|
-
throw new AgentBnBError(message, "RELAY_ERROR");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export {
|
|
82
|
-
requestCapability,
|
|
83
|
-
requestViaRelay
|
|
84
|
-
};
|