agentbnb 5.1.10 → 6.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-RSGDCHCV.js → card-REW7BSWW.js} +1 -1
- package/dist/{chunk-EPIWHNB2.js → chunk-2TLZ6G2B.js} +446 -373
- package/dist/{chunk-WGZ5AGOX.js → chunk-3CIMVISQ.js} +24 -1
- package/dist/{chunk-NH2FIERR.js → chunk-574W3HHE.js} +1 -1
- package/dist/{chunk-B5FTAGFN.js → chunk-7XHDSWRD.js} +75 -75
- package/dist/{chunk-NLAWT4DT.js → chunk-7YLFLC5C.js} +6 -6
- package/dist/chunk-BP3L2TET.js +148 -0
- package/dist/{chunk-EGUOAHCW.js → chunk-C2T4BMRW.js} +12 -12
- package/dist/{chunk-5KFI5X7B.js → chunk-F53QQIM2.js} +1 -1
- package/dist/chunk-JR6TJDIF.js +425 -0
- package/dist/{chunk-DFBX3BBD.js → chunk-KA2VIEGM.js} +211 -16
- package/dist/chunk-NQTE577Q.js +159 -0
- package/dist/{chunk-WTXRY7R2.js → chunk-NYV3NE5Z.js} +157 -9
- package/dist/{chunk-UKT6H7YT.js → chunk-OZXCRLP3.js} +1 -1
- package/dist/{chunk-QITOPASZ.js → chunk-PSQHUZ7X.js} +1 -1
- package/dist/{chunk-EANI2N2V.js → chunk-RVYQSC6L.js} +2 -99
- package/dist/{chunk-MLS6IGGG.js → chunk-TQDV254A.js} +1 -1
- package/dist/{chunk-QQFBFV4V.js → chunk-TR6UZDNX.js} +57 -18
- package/dist/{chunk-ZX5623ER.js → chunk-VMH2YS2I.js} +1 -1
- package/dist/{chunk-XND2DWTZ.js → chunk-VPQ44XKE.js} +2 -2
- package/dist/{chunk-CSATDXZC.js → chunk-Y7T6IMM3.js} +1 -1
- package/dist/{chunk-FLY3WIQR.js → chunk-YRRVFTDR.js} +3 -3
- package/dist/cli/index.js +261 -125
- package/dist/{client-T5MTY3CS.js → client-HRYRJKSA.js} +3 -3
- package/dist/{conduct-WU3VEXB6.js → conduct-LF6FYPLD.js} +11 -11
- package/dist/conduct-QAFZIEY6.js +21 -0
- package/dist/{conductor-mode-ZMTFZGJP.js → conductor-mode-NUDQLZFM.js} +309 -13
- package/dist/conductor-mode-YQ6QSPPT.js +275 -0
- package/dist/{execute-4D4ITQCL.js → execute-ITHIYYOX.js} +4 -3
- package/dist/execute-PNJFABVJ.js +14 -0
- package/dist/index.d.ts +555 -0
- package/dist/index.js +592 -83
- package/dist/{process-guard-CC7CNRQJ.js → process-guard-QCCBGILS.js} +1 -1
- package/dist/publish-capability-TS6CNR5G.js +12 -0
- package/dist/{request-VOXBFUOG.js → request-P6QCTCCG.js} +14 -14
- package/dist/{serve-skill-IH7UAJNR.js → serve-skill-EZOL7UYN.js} +10 -9
- package/dist/{server-JVQW2TID.js → server-3G6ZTASA.js} +16 -16
- package/dist/{service-coordinator-EYRDTHL5.js → service-coordinator-CRSE4GWC.js} +174 -242
- package/dist/skill-config-4W5W5O6T.js +22 -0
- package/dist/skills/agentbnb/bootstrap.js +227 -67
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/skills/agentbnb/SKILL.md +50 -1
- package/skills/agentbnb/bootstrap.ts +126 -8
- package/skills/agentbnb/install.sh +49 -9
- package/dist/chunk-CRFCWD6V.js +0 -366
- package/dist/conduct-6LKIJJKQ.js +0 -21
- package/dist/conductor-mode-Q4IIDY5E.js +0 -123
- package/dist/execute-T7Y6RKSW.js +0 -13
|
@@ -3,16 +3,150 @@ import {
|
|
|
3
3
|
} from "./chunk-3MJT4PZG.js";
|
|
4
4
|
import {
|
|
5
5
|
scorePeers
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-C2T4BMRW.js";
|
|
7
7
|
import {
|
|
8
8
|
fetchRemoteCards
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VMH2YS2I.js";
|
|
10
10
|
import {
|
|
11
11
|
searchCards
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-574W3HHE.js";
|
|
13
13
|
import {
|
|
14
14
|
requestCapability
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-VPQ44XKE.js";
|
|
16
|
+
|
|
17
|
+
// src/conductor/decomposition-validator.ts
|
|
18
|
+
function validateAndNormalizeSubtasks(raw, context) {
|
|
19
|
+
try {
|
|
20
|
+
return _validate(raw, context);
|
|
21
|
+
} catch {
|
|
22
|
+
return { valid: [], errors: ["internal validation error"] };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _validate(raw, context) {
|
|
26
|
+
if (!Array.isArray(raw)) {
|
|
27
|
+
return { valid: [], errors: ["decomposition output must be an array"] };
|
|
28
|
+
}
|
|
29
|
+
if (raw.length === 0) {
|
|
30
|
+
return { valid: [], errors: [] };
|
|
31
|
+
}
|
|
32
|
+
const errors = [];
|
|
33
|
+
const validItems = [];
|
|
34
|
+
const validIds = [];
|
|
35
|
+
for (let i = 0; i < raw.length; i++) {
|
|
36
|
+
const item = raw[i];
|
|
37
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
38
|
+
errors.push(`subtask[${i}]: must be an object`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const obj = item;
|
|
42
|
+
let itemValid = true;
|
|
43
|
+
const id = obj["id"];
|
|
44
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
45
|
+
errors.push(`subtask[${i}]: id must be a non-empty string`);
|
|
46
|
+
itemValid = false;
|
|
47
|
+
}
|
|
48
|
+
const description = obj["description"];
|
|
49
|
+
if (typeof description !== "string" || description.length === 0) {
|
|
50
|
+
errors.push(`subtask[${i}]: description must be a non-empty string`);
|
|
51
|
+
itemValid = false;
|
|
52
|
+
}
|
|
53
|
+
const required_capability = obj["required_capability"];
|
|
54
|
+
if (typeof required_capability !== "string" || required_capability.length === 0) {
|
|
55
|
+
errors.push(`subtask[${i}]: required_capability must be a non-empty string`);
|
|
56
|
+
itemValid = false;
|
|
57
|
+
}
|
|
58
|
+
const estimated_credits = obj["estimated_credits"];
|
|
59
|
+
if (estimated_credits !== void 0) {
|
|
60
|
+
if (typeof estimated_credits !== "number" || estimated_credits <= 0) {
|
|
61
|
+
errors.push(`subtask[${i}]: estimated_credits must be a positive number`);
|
|
62
|
+
itemValid = false;
|
|
63
|
+
} else if (estimated_credits > context.max_credits) {
|
|
64
|
+
errors.push(
|
|
65
|
+
`subtask[${i}]: estimated_credits ${estimated_credits} exceeds max_credits ${context.max_credits}`
|
|
66
|
+
);
|
|
67
|
+
itemValid = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (itemValid) {
|
|
71
|
+
validItems.push(obj);
|
|
72
|
+
validIds.push(id);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const idSet = /* @__PURE__ */ new Set();
|
|
76
|
+
for (const id of validIds) {
|
|
77
|
+
if (idSet.has(id)) {
|
|
78
|
+
errors.push(`duplicate subtask id: ${id}`);
|
|
79
|
+
} else {
|
|
80
|
+
idSet.add(id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (let i = 0; i < validItems.length; i++) {
|
|
84
|
+
const item = validItems[i];
|
|
85
|
+
const depends_on = item["depends_on"];
|
|
86
|
+
if (!Array.isArray(depends_on)) continue;
|
|
87
|
+
for (const dep of depends_on) {
|
|
88
|
+
if (typeof dep === "string" && !idSet.has(dep)) {
|
|
89
|
+
errors.push(`subtask[${i}]: depends_on references unknown id '${dep}'`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (errors.length === 0 && validItems.length > 0) {
|
|
94
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
95
|
+
const adjList = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const id of validIds) {
|
|
97
|
+
inDegree.set(id, 0);
|
|
98
|
+
adjList.set(id, []);
|
|
99
|
+
}
|
|
100
|
+
for (const item of validItems) {
|
|
101
|
+
const depends_on = item["depends_on"];
|
|
102
|
+
if (!Array.isArray(depends_on)) continue;
|
|
103
|
+
for (const dep of depends_on) {
|
|
104
|
+
if (typeof dep !== "string" || !idSet.has(dep)) continue;
|
|
105
|
+
adjList.get(dep)?.push(item["id"]);
|
|
106
|
+
inDegree.set(item["id"], (inDegree.get(item["id"]) ?? 0) + 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const queue = [];
|
|
110
|
+
for (const [id, deg] of inDegree) {
|
|
111
|
+
if (deg === 0) queue.push(id);
|
|
112
|
+
}
|
|
113
|
+
let processed = 0;
|
|
114
|
+
while (queue.length > 0) {
|
|
115
|
+
const current = queue.shift();
|
|
116
|
+
processed++;
|
|
117
|
+
for (const neighbor of adjList.get(current) ?? []) {
|
|
118
|
+
const newDeg = (inDegree.get(neighbor) ?? 0) - 1;
|
|
119
|
+
inDegree.set(neighbor, newDeg);
|
|
120
|
+
if (newDeg === 0) queue.push(neighbor);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (processed < validItems.length) {
|
|
124
|
+
for (const [id, deg] of inDegree) {
|
|
125
|
+
if (deg > 0) {
|
|
126
|
+
errors.push(`circular dependency detected involving subtask id: ${id}`);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (errors.length > 0) {
|
|
133
|
+
return { valid: [], errors };
|
|
134
|
+
}
|
|
135
|
+
const normalized = validItems.map((item) => {
|
|
136
|
+
const depends_on = Array.isArray(item["depends_on"]) ? item["depends_on"].filter((x) => typeof x === "string") : [];
|
|
137
|
+
const params = typeof item["params"] === "object" && item["params"] !== null && !Array.isArray(item["params"]) ? item["params"] : {};
|
|
138
|
+
const estimated_credits = typeof item["estimated_credits"] === "number" ? item["estimated_credits"] : 0;
|
|
139
|
+
return {
|
|
140
|
+
id: item["id"],
|
|
141
|
+
description: item["description"],
|
|
142
|
+
required_capability: item["required_capability"],
|
|
143
|
+
params,
|
|
144
|
+
depends_on,
|
|
145
|
+
estimated_credits
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
return { valid: normalized, errors: [] };
|
|
149
|
+
}
|
|
16
150
|
|
|
17
151
|
// src/conductor/task-decomposer.ts
|
|
18
152
|
import { randomUUID } from "crypto";
|
|
@@ -279,6 +413,12 @@ function computeWaves(subtasks) {
|
|
|
279
413
|
async function orchestrate(opts) {
|
|
280
414
|
const { subtasks, matches, gatewayToken, resolveAgentUrl, timeoutMs = 3e5, maxBudget, relayClient, requesterOwner } = opts;
|
|
281
415
|
const startTime = Date.now();
|
|
416
|
+
const teamMemberMap = /* @__PURE__ */ new Map();
|
|
417
|
+
if (opts.team) {
|
|
418
|
+
for (const member of opts.team.matched) {
|
|
419
|
+
teamMemberMap.set(member.subtask.id, member);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
282
422
|
if (subtasks.length === 0) {
|
|
283
423
|
return {
|
|
284
424
|
success: true,
|
|
@@ -290,6 +430,7 @@ async function orchestrate(opts) {
|
|
|
290
430
|
const results = /* @__PURE__ */ new Map();
|
|
291
431
|
const errors = [];
|
|
292
432
|
let totalCredits = 0;
|
|
433
|
+
const traceContext = /* @__PURE__ */ new Map();
|
|
293
434
|
const waves = computeWaves(subtasks);
|
|
294
435
|
const subtaskMap = new Map(subtasks.map((s) => [s.id, s]));
|
|
295
436
|
for (const wave of waves) {
|
|
@@ -326,7 +467,11 @@ async function orchestrate(opts) {
|
|
|
326
467
|
subtask.params,
|
|
327
468
|
interpContext
|
|
328
469
|
);
|
|
329
|
-
const
|
|
470
|
+
const teamMember = teamMemberMap.get(taskId);
|
|
471
|
+
const teamId = opts.team?.team_id ?? null;
|
|
472
|
+
const taskCapabilityType = teamMember?.capability_type ?? null;
|
|
473
|
+
const agentOwner = teamMember?.agent ?? m.selected_agent;
|
|
474
|
+
const primary = resolveAgentUrl(agentOwner);
|
|
330
475
|
try {
|
|
331
476
|
let res;
|
|
332
477
|
if (primary.url.startsWith("relay://") && relayClient) {
|
|
@@ -347,7 +492,7 @@ async function orchestrate(opts) {
|
|
|
347
492
|
timeoutMs
|
|
348
493
|
});
|
|
349
494
|
}
|
|
350
|
-
return { taskId, result: res, credits: m.credits };
|
|
495
|
+
return { taskId, result: res, credits: m.credits, team_id: teamId, capability_type: taskCapabilityType };
|
|
351
496
|
} catch (primaryErr) {
|
|
352
497
|
if (m.alternatives.length > 0) {
|
|
353
498
|
const alt = m.alternatives[0];
|
|
@@ -372,7 +517,7 @@ async function orchestrate(opts) {
|
|
|
372
517
|
timeoutMs
|
|
373
518
|
});
|
|
374
519
|
}
|
|
375
|
-
return { taskId, result: altRes, credits: alt.credits };
|
|
520
|
+
return { taskId, result: altRes, credits: alt.credits, team_id: teamId, capability_type: taskCapabilityType };
|
|
376
521
|
} catch (altErr) {
|
|
377
522
|
throw new Error(
|
|
378
523
|
`Task ${taskId}: primary (${m.selected_agent}) failed: ${primaryErr instanceof Error ? primaryErr.message : String(primaryErr)}; alternative (${alt.agent}) failed: ${altErr instanceof Error ? altErr.message : String(altErr)}`
|
|
@@ -387,9 +532,10 @@ async function orchestrate(opts) {
|
|
|
387
532
|
);
|
|
388
533
|
for (const settlement of waveResults) {
|
|
389
534
|
if (settlement.status === "fulfilled") {
|
|
390
|
-
const { taskId, result, credits } = settlement.value;
|
|
535
|
+
const { taskId, result, credits, team_id, capability_type } = settlement.value;
|
|
391
536
|
results.set(taskId, result);
|
|
392
537
|
totalCredits += credits;
|
|
538
|
+
traceContext.set(taskId, { team_id: team_id ?? null, capability_type: capability_type ?? null });
|
|
393
539
|
} else {
|
|
394
540
|
errors.push(settlement.reason instanceof Error ? settlement.reason.message : String(settlement.reason));
|
|
395
541
|
}
|
|
@@ -400,11 +546,13 @@ async function orchestrate(opts) {
|
|
|
400
546
|
results,
|
|
401
547
|
total_credits: totalCredits,
|
|
402
548
|
latency_ms: Date.now() - startTime,
|
|
403
|
-
errors: errors.length > 0 ? errors : void 0
|
|
549
|
+
errors: errors.length > 0 ? errors : void 0,
|
|
550
|
+
trace: traceContext.size > 0 ? traceContext : void 0
|
|
404
551
|
};
|
|
405
552
|
}
|
|
406
553
|
|
|
407
554
|
export {
|
|
555
|
+
validateAndNormalizeSubtasks,
|
|
408
556
|
decompose,
|
|
409
557
|
matchSubTasks,
|
|
410
558
|
ORCHESTRATION_FEE,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBnBError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3CIMVISQ.js";
|
|
4
4
|
|
|
5
5
|
// src/credit/escrow.ts
|
|
6
6
|
import { randomUUID } from "crypto";
|
|
@@ -198,99 +198,6 @@ function migrateOwner(db, oldOwner, newOwner) {
|
|
|
198
198
|
})();
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
// src/feedback/store.ts
|
|
202
|
-
import { randomUUID as randomUUID3 } from "crypto";
|
|
203
|
-
function initFeedbackTable(db) {
|
|
204
|
-
db.exec(`
|
|
205
|
-
CREATE TABLE IF NOT EXISTS feedback (
|
|
206
|
-
id TEXT PRIMARY KEY,
|
|
207
|
-
transaction_id TEXT NOT NULL,
|
|
208
|
-
provider_agent TEXT NOT NULL,
|
|
209
|
-
skill_id TEXT NOT NULL,
|
|
210
|
-
requester_agent TEXT NOT NULL,
|
|
211
|
-
rating INTEGER NOT NULL,
|
|
212
|
-
latency_ms INTEGER NOT NULL,
|
|
213
|
-
result_quality TEXT NOT NULL,
|
|
214
|
-
quality_details TEXT,
|
|
215
|
-
would_reuse INTEGER NOT NULL,
|
|
216
|
-
cost_value_ratio TEXT NOT NULL,
|
|
217
|
-
timestamp TEXT NOT NULL,
|
|
218
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
CREATE INDEX IF NOT EXISTS feedback_provider_idx ON feedback(provider_agent);
|
|
222
|
-
CREATE INDEX IF NOT EXISTS feedback_skill_idx ON feedback(skill_id);
|
|
223
|
-
`);
|
|
224
|
-
}
|
|
225
|
-
function insertFeedback(db, feedback) {
|
|
226
|
-
const id = randomUUID3();
|
|
227
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
228
|
-
db.prepare(`
|
|
229
|
-
INSERT INTO feedback (
|
|
230
|
-
id, transaction_id, provider_agent, skill_id, requester_agent,
|
|
231
|
-
rating, latency_ms, result_quality, quality_details,
|
|
232
|
-
would_reuse, cost_value_ratio, timestamp, created_at
|
|
233
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
234
|
-
`).run(
|
|
235
|
-
id,
|
|
236
|
-
feedback.transaction_id,
|
|
237
|
-
feedback.provider_agent,
|
|
238
|
-
feedback.skill_id,
|
|
239
|
-
feedback.requester_agent,
|
|
240
|
-
feedback.rating,
|
|
241
|
-
feedback.latency_ms,
|
|
242
|
-
feedback.result_quality,
|
|
243
|
-
feedback.quality_details ?? null,
|
|
244
|
-
feedback.would_reuse ? 1 : 0,
|
|
245
|
-
feedback.cost_value_ratio,
|
|
246
|
-
feedback.timestamp,
|
|
247
|
-
now
|
|
248
|
-
);
|
|
249
|
-
return id;
|
|
250
|
-
}
|
|
251
|
-
function getFeedbackForSkill(db, skillId, limit = 20) {
|
|
252
|
-
const rows = db.prepare(`
|
|
253
|
-
SELECT * FROM feedback
|
|
254
|
-
WHERE skill_id = ?
|
|
255
|
-
ORDER BY timestamp DESC
|
|
256
|
-
LIMIT ?
|
|
257
|
-
`).all(skillId, limit);
|
|
258
|
-
return rows.map(rowToFeedback);
|
|
259
|
-
}
|
|
260
|
-
function getFeedbackForProvider(db, providerAgent, sinceDays) {
|
|
261
|
-
let rows;
|
|
262
|
-
if (sinceDays !== void 0) {
|
|
263
|
-
rows = db.prepare(`
|
|
264
|
-
SELECT * FROM feedback
|
|
265
|
-
WHERE provider_agent = ?
|
|
266
|
-
AND timestamp >= datetime('now', ? || ' days')
|
|
267
|
-
ORDER BY timestamp DESC
|
|
268
|
-
`).all(providerAgent, `-${sinceDays}`);
|
|
269
|
-
} else {
|
|
270
|
-
rows = db.prepare(`
|
|
271
|
-
SELECT * FROM feedback
|
|
272
|
-
WHERE provider_agent = ?
|
|
273
|
-
ORDER BY timestamp DESC
|
|
274
|
-
`).all(providerAgent);
|
|
275
|
-
}
|
|
276
|
-
return rows.map(rowToFeedback);
|
|
277
|
-
}
|
|
278
|
-
function rowToFeedback(row) {
|
|
279
|
-
return {
|
|
280
|
-
transaction_id: row["transaction_id"],
|
|
281
|
-
provider_agent: row["provider_agent"],
|
|
282
|
-
skill_id: row["skill_id"],
|
|
283
|
-
requester_agent: row["requester_agent"],
|
|
284
|
-
rating: row["rating"],
|
|
285
|
-
latency_ms: row["latency_ms"],
|
|
286
|
-
result_quality: row["result_quality"],
|
|
287
|
-
quality_details: row["quality_details"] ?? void 0,
|
|
288
|
-
would_reuse: row["would_reuse"] === 1,
|
|
289
|
-
cost_value_ratio: row["cost_value_ratio"],
|
|
290
|
-
timestamp: row["timestamp"]
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
201
|
export {
|
|
295
202
|
holdEscrow,
|
|
296
203
|
settleEscrow,
|
|
@@ -301,9 +208,5 @@ export {
|
|
|
301
208
|
getBalance,
|
|
302
209
|
getTransactions,
|
|
303
210
|
recordEarning,
|
|
304
|
-
migrateOwner
|
|
305
|
-
initFeedbackTable,
|
|
306
|
-
insertFeedback,
|
|
307
|
-
getFeedbackForSkill,
|
|
308
|
-
getFeedbackForProvider
|
|
211
|
+
migrateOwner
|
|
309
212
|
};
|
|
@@ -1,26 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
2
|
settleProviderEarning
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
getCard,
|
|
6
|
-
insertRequestLog,
|
|
7
|
-
updateReputation
|
|
8
|
-
} from "./chunk-DFBX3BBD.js";
|
|
3
|
+
} from "./chunk-OZXCRLP3.js";
|
|
9
4
|
import {
|
|
10
5
|
getBalance,
|
|
11
6
|
holdEscrow,
|
|
12
7
|
releaseEscrow,
|
|
13
8
|
settleEscrow
|
|
14
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-RVYQSC6L.js";
|
|
15
10
|
import {
|
|
16
11
|
verifyEscrowReceipt
|
|
17
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-F53QQIM2.js";
|
|
13
|
+
import {
|
|
14
|
+
loadConfig
|
|
15
|
+
} from "./chunk-75OC6E4F.js";
|
|
16
|
+
import {
|
|
17
|
+
getCard,
|
|
18
|
+
insertRequestLog,
|
|
19
|
+
updateReputation
|
|
20
|
+
} from "./chunk-KA2VIEGM.js";
|
|
18
21
|
import {
|
|
19
22
|
AgentBnBError
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-3CIMVISQ.js";
|
|
21
24
|
|
|
22
25
|
// src/gateway/execute.ts
|
|
23
26
|
import { randomUUID } from "crypto";
|
|
27
|
+
async function notifyTelegramSkillExecuted(opts) {
|
|
28
|
+
const cfg = loadConfig();
|
|
29
|
+
if (!cfg?.telegram_notifications) return;
|
|
30
|
+
const token = cfg.telegram_bot_token ?? process.env["TELEGRAM_BOT_TOKEN"];
|
|
31
|
+
const chatId = cfg.telegram_chat_id ?? process.env["TELEGRAM_CHAT_ID"];
|
|
32
|
+
if (!token || !chatId) return;
|
|
33
|
+
const balance = getBalance(opts.creditDb, opts.owner);
|
|
34
|
+
const skillLabel = opts.skillId ? `${opts.skillName} (${opts.skillId})` : opts.skillName;
|
|
35
|
+
const text = [
|
|
36
|
+
"[AgentBnB] Skill executed",
|
|
37
|
+
`Skill: ${skillLabel}`,
|
|
38
|
+
`Requester: ${opts.requester}`,
|
|
39
|
+
`Earned: +${opts.creditsEarned} credits`,
|
|
40
|
+
`Balance: ${balance} credits`,
|
|
41
|
+
`Latency: ${opts.latencyMs}ms`
|
|
42
|
+
].join("\n");
|
|
43
|
+
await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: { "Content-Type": "application/json" },
|
|
46
|
+
body: JSON.stringify({ chat_id: chatId, text })
|
|
47
|
+
});
|
|
48
|
+
}
|
|
24
49
|
async function executeCapabilityRequest(opts) {
|
|
25
50
|
const {
|
|
26
51
|
registryDb,
|
|
@@ -52,7 +77,8 @@ async function executeCapabilityRequest(opts) {
|
|
|
52
77
|
status: "failure",
|
|
53
78
|
latency_ms: 0,
|
|
54
79
|
credits_charged: 0,
|
|
55
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
80
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
81
|
+
failure_reason: "auth_error"
|
|
56
82
|
});
|
|
57
83
|
} catch {
|
|
58
84
|
}
|
|
@@ -107,7 +133,7 @@ async function executeCapabilityRequest(opts) {
|
|
|
107
133
|
}
|
|
108
134
|
const startMs = Date.now();
|
|
109
135
|
const receiptData = isRemoteEscrow ? { receipt_released: true } : void 0;
|
|
110
|
-
const handleFailure = (status, latencyMs, message) => {
|
|
136
|
+
const handleFailure = (status, latencyMs, message, failureReason = "bad_execution") => {
|
|
111
137
|
if (!isRemoteEscrow && escrowId) releaseEscrow(creditDb, escrowId);
|
|
112
138
|
updateReputation(registryDb, cardId, false, latencyMs);
|
|
113
139
|
try {
|
|
@@ -120,7 +146,8 @@ async function executeCapabilityRequest(opts) {
|
|
|
120
146
|
status,
|
|
121
147
|
latency_ms: latencyMs,
|
|
122
148
|
credits_charged: 0,
|
|
123
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
149
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
150
|
+
failure_reason: failureReason
|
|
124
151
|
});
|
|
125
152
|
} catch {
|
|
126
153
|
}
|
|
@@ -150,6 +177,16 @@ async function executeCapabilityRequest(opts) {
|
|
|
150
177
|
});
|
|
151
178
|
} catch {
|
|
152
179
|
}
|
|
180
|
+
notifyTelegramSkillExecuted({
|
|
181
|
+
creditDb,
|
|
182
|
+
owner: card.owner,
|
|
183
|
+
skillName: cardName,
|
|
184
|
+
skillId: resolvedSkillId ?? null,
|
|
185
|
+
requester,
|
|
186
|
+
creditsEarned: creditsNeeded,
|
|
187
|
+
latencyMs
|
|
188
|
+
}).catch(() => {
|
|
189
|
+
});
|
|
153
190
|
const successResult = isRemoteEscrow ? {
|
|
154
191
|
...typeof result === "object" && result !== null ? result : { data: result },
|
|
155
192
|
receipt_settled: true,
|
|
@@ -167,23 +204,24 @@ async function executeCapabilityRequest(opts) {
|
|
|
167
204
|
return handleFailure(
|
|
168
205
|
"failure",
|
|
169
206
|
Date.now() - startMs,
|
|
170
|
-
"No skill_id specified and no skills registered on this provider."
|
|
207
|
+
"No skill_id specified and no skills registered on this provider.",
|
|
208
|
+
"not_found"
|
|
171
209
|
);
|
|
172
210
|
}
|
|
173
211
|
}
|
|
174
212
|
try {
|
|
175
213
|
const execResult = await skillExecutor.execute(targetSkillId, params, onProgress);
|
|
176
214
|
if (!execResult.success) {
|
|
177
|
-
return handleFailure("failure", execResult.latency_ms, execResult.error ?? "Execution failed");
|
|
215
|
+
return handleFailure("failure", execResult.latency_ms, execResult.error ?? "Execution failed", "bad_execution");
|
|
178
216
|
}
|
|
179
217
|
return handleSuccess(execResult.result, execResult.latency_ms);
|
|
180
218
|
} catch (err) {
|
|
181
219
|
const message = err instanceof Error ? err.message : "Execution error";
|
|
182
|
-
return handleFailure("failure", Date.now() - startMs, message);
|
|
220
|
+
return handleFailure("failure", Date.now() - startMs, message, "bad_execution");
|
|
183
221
|
}
|
|
184
222
|
}
|
|
185
223
|
if (!handlerUrl) {
|
|
186
|
-
return handleFailure("failure", Date.now() - startMs, "No skill executor or handler URL configured");
|
|
224
|
+
return handleFailure("failure", Date.now() - startMs, "No skill executor or handler URL configured", "bad_execution");
|
|
187
225
|
}
|
|
188
226
|
const controller = new AbortController();
|
|
189
227
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -196,7 +234,7 @@ async function executeCapabilityRequest(opts) {
|
|
|
196
234
|
});
|
|
197
235
|
clearTimeout(timer);
|
|
198
236
|
if (!response.ok) {
|
|
199
|
-
return handleFailure("failure", Date.now() - startMs, `Handler returned ${response.status}
|
|
237
|
+
return handleFailure("failure", Date.now() - startMs, `Handler returned ${response.status}`, "bad_execution");
|
|
200
238
|
}
|
|
201
239
|
const result = await response.json();
|
|
202
240
|
return handleSuccess(result, Date.now() - startMs);
|
|
@@ -206,7 +244,8 @@ async function executeCapabilityRequest(opts) {
|
|
|
206
244
|
return handleFailure(
|
|
207
245
|
isTimeout ? "timeout" : "failure",
|
|
208
246
|
Date.now() - startMs,
|
|
209
|
-
isTimeout ? "Execution timeout" : "Handler error"
|
|
247
|
+
isTimeout ? "Execution timeout" : "Handler error",
|
|
248
|
+
isTimeout ? "timeout" : "bad_execution"
|
|
210
249
|
);
|
|
211
250
|
}
|
|
212
251
|
}
|
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
openCreditDb,
|
|
8
8
|
releaseEscrow,
|
|
9
9
|
settleEscrow
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-RVYQSC6L.js";
|
|
11
11
|
import {
|
|
12
12
|
signEscrowReceipt,
|
|
13
13
|
verifyEscrowReceipt
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-F53QQIM2.js";
|
|
15
15
|
import {
|
|
16
16
|
AgentBnBError
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-3CIMVISQ.js";
|
|
18
18
|
|
|
19
19
|
// src/credit/local-credit-ledger.ts
|
|
20
20
|
var LocalCreditLedger = class {
|