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