agentbnb 2.2.0 → 3.0.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/card-P5C36VBD.js +81 -0
- package/dist/chunk-BEI5MTNZ.js +91 -0
- package/dist/chunk-EZB4RUIG.js +372 -0
- package/dist/chunk-PJSYSVKN.js +491 -0
- package/dist/chunk-TQMI73LL.js +125 -0
- package/dist/chunk-V7M6GIJZ.js +666 -0
- package/dist/cli/index.js +495 -1353
- package/dist/conduct-JZJS2ZHA.js +115 -0
- package/dist/conductor-mode-DJ3RIJ5T.js +111 -0
- package/dist/index.d.ts +2174 -120
- package/dist/index.js +1721 -27
- package/dist/peers-G36URZYB.js +12 -0
- package/package.json +2 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openDatabase
|
|
3
|
+
} from "./chunk-PJSYSVKN.js";
|
|
4
|
+
import {
|
|
5
|
+
BudgetController,
|
|
6
|
+
ORCHESTRATION_FEE,
|
|
7
|
+
decompose,
|
|
8
|
+
matchSubTasks,
|
|
9
|
+
orchestrate
|
|
10
|
+
} from "./chunk-EZB4RUIG.js";
|
|
11
|
+
import {
|
|
12
|
+
BudgetManager,
|
|
13
|
+
openCreditDb
|
|
14
|
+
} from "./chunk-V7M6GIJZ.js";
|
|
15
|
+
import {
|
|
16
|
+
loadConfig,
|
|
17
|
+
loadPeers
|
|
18
|
+
} from "./chunk-BEI5MTNZ.js";
|
|
19
|
+
import "./chunk-TQMI73LL.js";
|
|
20
|
+
|
|
21
|
+
// src/cli/conduct.ts
|
|
22
|
+
async function conductAction(task, opts) {
|
|
23
|
+
const config = loadConfig();
|
|
24
|
+
if (!config) {
|
|
25
|
+
return { success: false, error: "Not initialized. Run `agentbnb init` first." };
|
|
26
|
+
}
|
|
27
|
+
const maxBudget = parseInt(opts.maxBudget ?? "100", 10);
|
|
28
|
+
const subtasks = decompose(task);
|
|
29
|
+
if (subtasks.length === 0) {
|
|
30
|
+
return { success: false, error: "No matching template for this task" };
|
|
31
|
+
}
|
|
32
|
+
const db = openDatabase(config.db_path);
|
|
33
|
+
let matchResults;
|
|
34
|
+
try {
|
|
35
|
+
matchResults = matchSubTasks({
|
|
36
|
+
db,
|
|
37
|
+
subtasks,
|
|
38
|
+
conductorOwner: config.owner
|
|
39
|
+
});
|
|
40
|
+
} finally {
|
|
41
|
+
db.close();
|
|
42
|
+
}
|
|
43
|
+
const creditDb = openCreditDb(config.credit_db_path);
|
|
44
|
+
let budget;
|
|
45
|
+
try {
|
|
46
|
+
const budgetManager = new BudgetManager(creditDb, config.owner);
|
|
47
|
+
const budgetController = new BudgetController(budgetManager, maxBudget);
|
|
48
|
+
budget = budgetController.calculateBudget(matchResults);
|
|
49
|
+
} finally {
|
|
50
|
+
creditDb.close();
|
|
51
|
+
}
|
|
52
|
+
const plan = subtasks.map((st, i) => {
|
|
53
|
+
const match = matchResults.find((m) => m.subtask_id === st.id);
|
|
54
|
+
return {
|
|
55
|
+
step: i + 1,
|
|
56
|
+
description: st.description,
|
|
57
|
+
capability: st.required_capability,
|
|
58
|
+
agent: match?.selected_agent || "(unmatched)",
|
|
59
|
+
credits: match?.credits ?? st.estimated_credits,
|
|
60
|
+
depends_on: st.depends_on
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
const planOutput = {
|
|
64
|
+
steps: plan,
|
|
65
|
+
orchestration_fee: ORCHESTRATION_FEE,
|
|
66
|
+
estimated_total: budget.estimated_total,
|
|
67
|
+
max_budget: maxBudget
|
|
68
|
+
};
|
|
69
|
+
if (opts.planOnly) {
|
|
70
|
+
return { success: true, plan: planOutput };
|
|
71
|
+
}
|
|
72
|
+
const peers = loadPeers();
|
|
73
|
+
const resolveAgentUrl = (owner) => {
|
|
74
|
+
const peer = peers.find((p) => p.name.toLowerCase() === owner.toLowerCase());
|
|
75
|
+
if (!peer) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Unknown peer "${owner}". Add with: agentbnb peers add ${owner} <url> <token>`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const execDb = openDatabase(config.db_path);
|
|
81
|
+
try {
|
|
82
|
+
const stmt = execDb.prepare("SELECT id FROM capability_cards WHERE owner = ? LIMIT 1");
|
|
83
|
+
const row = stmt.get(owner);
|
|
84
|
+
return { url: peer.url, cardId: row?.id ?? owner };
|
|
85
|
+
} finally {
|
|
86
|
+
execDb.close();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const matchMap = new Map(
|
|
90
|
+
matchResults.map((m) => [m.subtask_id, m])
|
|
91
|
+
);
|
|
92
|
+
const orchResult = await orchestrate({
|
|
93
|
+
subtasks,
|
|
94
|
+
matches: matchMap,
|
|
95
|
+
gatewayToken: config.token ?? "",
|
|
96
|
+
resolveAgentUrl,
|
|
97
|
+
timeoutMs: 3e4,
|
|
98
|
+
maxBudget
|
|
99
|
+
});
|
|
100
|
+
const resultObj = {};
|
|
101
|
+
for (const [key, value] of orchResult.results) {
|
|
102
|
+
resultObj[key] = value;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
success: orchResult.success,
|
|
106
|
+
plan: planOutput,
|
|
107
|
+
execution: resultObj,
|
|
108
|
+
total_credits: orchResult.total_credits,
|
|
109
|
+
latency_ms: orchResult.latency_ms,
|
|
110
|
+
errors: orchResult.errors
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
conductAction
|
|
115
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BudgetController,
|
|
3
|
+
decompose,
|
|
4
|
+
matchSubTasks,
|
|
5
|
+
orchestrate
|
|
6
|
+
} from "./chunk-EZB4RUIG.js";
|
|
7
|
+
import {
|
|
8
|
+
BudgetManager
|
|
9
|
+
} from "./chunk-V7M6GIJZ.js";
|
|
10
|
+
import "./chunk-BEI5MTNZ.js";
|
|
11
|
+
import "./chunk-TQMI73LL.js";
|
|
12
|
+
|
|
13
|
+
// src/conductor/conductor-mode.ts
|
|
14
|
+
var ConductorMode = class {
|
|
15
|
+
db;
|
|
16
|
+
creditDb;
|
|
17
|
+
conductorOwner;
|
|
18
|
+
gatewayToken;
|
|
19
|
+
resolveAgentUrl;
|
|
20
|
+
maxBudget;
|
|
21
|
+
constructor(opts) {
|
|
22
|
+
this.db = opts.db;
|
|
23
|
+
this.creditDb = opts.creditDb;
|
|
24
|
+
this.conductorOwner = opts.conductorOwner;
|
|
25
|
+
this.gatewayToken = opts.gatewayToken;
|
|
26
|
+
this.resolveAgentUrl = opts.resolveAgentUrl;
|
|
27
|
+
this.maxBudget = opts.maxBudget ?? 100;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Execute a conductor skill with the given config and params.
|
|
31
|
+
*
|
|
32
|
+
* @param config - SkillConfig with type 'conductor' and conductor_skill field.
|
|
33
|
+
* @param params - Must include `task` string.
|
|
34
|
+
* @returns Execution result without latency_ms (added by SkillExecutor).
|
|
35
|
+
*/
|
|
36
|
+
async execute(config, params) {
|
|
37
|
+
const conductorSkill = config.conductor_skill;
|
|
38
|
+
if (conductorSkill !== "orchestrate" && conductorSkill !== "plan") {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: `Unknown conductor skill: "${conductorSkill}"`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const task = params.task;
|
|
45
|
+
if (typeof task !== "string" || task.length === 0) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: 'Missing or empty "task" parameter'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const subtasks = decompose(task);
|
|
52
|
+
if (subtasks.length === 0) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
error: "No template matches task"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const matchResults = matchSubTasks({
|
|
59
|
+
db: this.db,
|
|
60
|
+
subtasks,
|
|
61
|
+
conductorOwner: this.conductorOwner
|
|
62
|
+
});
|
|
63
|
+
const budgetManager = new BudgetManager(this.creditDb, this.conductorOwner);
|
|
64
|
+
const budgetController = new BudgetController(budgetManager, this.maxBudget);
|
|
65
|
+
const executionBudget = budgetController.calculateBudget(matchResults);
|
|
66
|
+
if (!budgetController.canExecute(executionBudget)) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: `Budget exceeded: estimated ${executionBudget.estimated_total} cr, max ${this.maxBudget} cr`
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (conductorSkill === "plan") {
|
|
73
|
+
return {
|
|
74
|
+
success: true,
|
|
75
|
+
result: {
|
|
76
|
+
subtasks,
|
|
77
|
+
matches: matchResults,
|
|
78
|
+
budget: executionBudget
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const matchMap = new Map(
|
|
83
|
+
matchResults.map((m) => [m.subtask_id, m])
|
|
84
|
+
);
|
|
85
|
+
const orchResult = await orchestrate({
|
|
86
|
+
subtasks,
|
|
87
|
+
matches: matchMap,
|
|
88
|
+
gatewayToken: this.gatewayToken,
|
|
89
|
+
resolveAgentUrl: this.resolveAgentUrl,
|
|
90
|
+
maxBudget: this.maxBudget
|
|
91
|
+
});
|
|
92
|
+
const resultObj = {};
|
|
93
|
+
for (const [key, value] of orchResult.results) {
|
|
94
|
+
resultObj[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
success: orchResult.success,
|
|
98
|
+
result: {
|
|
99
|
+
plan: subtasks,
|
|
100
|
+
execution: resultObj,
|
|
101
|
+
total_credits: orchResult.total_credits,
|
|
102
|
+
latency_ms: orchResult.latency_ms,
|
|
103
|
+
errors: orchResult.errors
|
|
104
|
+
},
|
|
105
|
+
error: orchResult.success ? void 0 : orchResult.errors?.join("; ")
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
export {
|
|
110
|
+
ConductorMode
|
|
111
|
+
};
|