agentbnb 8.2.1 → 8.2.2
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-7Q2XUXSA.js → chunk-4IPJJRTP.js} +1 -1
- package/dist/{chunk-EZVOG7QS.js → chunk-CKOOVZOI.js} +15 -18
- package/dist/chunk-CQFBNTGT.js +145 -0
- package/dist/{chunk-WKWJWKX7.js → chunk-DYQOFGGI.js} +155 -445
- package/dist/{chunk-NP55V7RQ.js → chunk-EG6RS4JC.js} +70 -46
- package/dist/{chunk-KBQNTUTN.js → chunk-LKLKYXLV.js} +1 -1
- package/dist/{chunk-STJLWMXH.js → chunk-MCED4GDW.js} +467 -98
- package/dist/{chunk-GWMMYVLL.js → chunk-MWOXW7JQ.js} +7 -7
- package/dist/{chunk-GJETGML6.js → chunk-QCGIG7WW.js} +4 -6
- package/dist/{chunk-UYCD3JBZ.js → chunk-QHZGOG3O.js} +148 -46
- package/dist/{chunk-JLNHMNES.js → chunk-RYISHSHB.js} +286 -1
- package/dist/{chunk-SRBVKO2V.js → chunk-S3V6R3EN.js} +66 -39
- package/dist/{chunk-RBXTWWUH.js → chunk-WNXXLCV5.js} +1 -1
- package/dist/{chunk-LOUEJI6X.js → chunk-XBGVQMQJ.js} +71 -47
- package/dist/{chunk-DEWY7OQK.js → chunk-Z2GEFFDO.js} +1 -1
- package/dist/cli/index.js +25 -28
- package/dist/{client-66TFS7RS.js → client-XOLP5IUZ.js} +1 -1
- package/dist/{conduct-A6COHLHY.js → conduct-AZFLNUX3.js} +9 -10
- package/dist/{conduct-IUVAXUAV.js → conduct-VPUYTNEA.js} +9 -10
- package/dist/{conductor-mode-L2MB44BW.js → conductor-mode-PLTB6MS3.js} +6 -7
- package/dist/{conductor-mode-D5TFQW5L.js → conductor-mode-WKB42PYM.js} +6 -3
- package/dist/{execute-WOS457HW.js → execute-NNDCXTN4.js} +3 -2
- package/dist/{execute-5AWLARB5.js → execute-RIRHTIBU.js} +5 -4
- package/dist/index.d.ts +5069 -0
- package/dist/index.js +208 -610
- package/dist/{publish-capability-JJCBBMSX.js → publish-capability-QDR2QIZ2.js} +2 -2
- package/dist/{request-6YQLA7K3.js → request-NX7GSPIG.js} +30 -40
- package/dist/{serve-skill-X7TZSILV.js → serve-skill-E6EJQYAK.js} +9 -8
- package/dist/{server-5TSP4DBX.js → server-VBCT32FC.js} +10 -14
- package/dist/{service-coordinator-WTUSMPY6.js → service-coordinator-KMSA6BST.js} +77 -32
- package/dist/skills/agentbnb/bootstrap.js +113 -69
- package/package.json +1 -1
- package/dist/chunk-BZOJ7HBT.js +0 -170
- package/dist/chunk-KF3TZHA5.js +0 -91
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RelayClient,
|
|
3
|
+
RelayMessageSchema
|
|
4
|
+
} from "../../chunk-3LWBH7P3.js";
|
|
1
5
|
import {
|
|
2
6
|
AutoRequestor,
|
|
3
7
|
BudgetController,
|
|
@@ -5,23 +9,19 @@ import {
|
|
|
5
9
|
DEFAULT_AUTONOMY_CONFIG,
|
|
6
10
|
DEFAULT_BUDGET_CONFIG,
|
|
7
11
|
ORCHESTRATION_FEE,
|
|
8
|
-
buildReputationMap,
|
|
9
|
-
computeReputation,
|
|
10
12
|
decompose,
|
|
11
|
-
fetchRemoteCards,
|
|
12
|
-
filterCards,
|
|
13
13
|
getAutonomyTier,
|
|
14
14
|
insertAuditEvent,
|
|
15
15
|
interpolateObject,
|
|
16
16
|
listPendingRequests,
|
|
17
17
|
matchSubTasks,
|
|
18
|
-
mergeResults,
|
|
19
18
|
orchestrate,
|
|
19
|
+
resolvePendingRequest
|
|
20
|
+
} from "../../chunk-DYQOFGGI.js";
|
|
21
|
+
import {
|
|
20
22
|
requestCapability,
|
|
21
|
-
requestViaRelay
|
|
22
|
-
|
|
23
|
-
searchCards
|
|
24
|
-
} from "../../chunk-WKWJWKX7.js";
|
|
23
|
+
requestViaRelay
|
|
24
|
+
} from "../../chunk-CKOOVZOI.js";
|
|
25
25
|
import {
|
|
26
26
|
loadPeers
|
|
27
27
|
} from "../../chunk-HLUEOLSZ.js";
|
|
@@ -30,10 +30,13 @@ import {
|
|
|
30
30
|
executeCapabilityRequest,
|
|
31
31
|
releaseRequesterEscrow,
|
|
32
32
|
settleRequesterEscrow
|
|
33
|
-
} from "../../chunk-
|
|
33
|
+
} from "../../chunk-EG6RS4JC.js";
|
|
34
34
|
import {
|
|
35
35
|
bootstrapAgent,
|
|
36
|
-
|
|
36
|
+
buildReputationMap,
|
|
37
|
+
computeReputation,
|
|
38
|
+
fetchRemoteCards,
|
|
39
|
+
filterCards,
|
|
37
40
|
getActivityFeed,
|
|
38
41
|
getBalance,
|
|
39
42
|
getCard,
|
|
@@ -51,21 +54,26 @@ import {
|
|
|
51
54
|
insertFeedback,
|
|
52
55
|
insertRequestLog,
|
|
53
56
|
listCards,
|
|
54
|
-
loadKeyPair,
|
|
55
57
|
lookupAgent,
|
|
58
|
+
mergeResults,
|
|
56
59
|
migrateOwner,
|
|
57
60
|
openCreditDb,
|
|
58
61
|
openDatabase,
|
|
59
62
|
releaseEscrow,
|
|
60
|
-
|
|
63
|
+
searchCards,
|
|
61
64
|
settleEscrow,
|
|
62
|
-
signEscrowReceipt,
|
|
63
65
|
updateCard,
|
|
64
66
|
updateSkillAvailability,
|
|
65
|
-
updateSkillIdleRate
|
|
66
|
-
|
|
67
|
-
} from "../../chunk-STJLWMXH.js";
|
|
67
|
+
updateSkillIdleRate
|
|
68
|
+
} from "../../chunk-MCED4GDW.js";
|
|
68
69
|
import "../../chunk-NWIQJ2CL.js";
|
|
70
|
+
import {
|
|
71
|
+
generateKeyPair,
|
|
72
|
+
loadKeyPair,
|
|
73
|
+
saveKeyPair,
|
|
74
|
+
signEscrowReceipt,
|
|
75
|
+
verifyEscrowReceipt
|
|
76
|
+
} from "../../chunk-EJKW57ZV.js";
|
|
69
77
|
import {
|
|
70
78
|
getConfigDir,
|
|
71
79
|
loadConfig
|
|
@@ -74,17 +82,13 @@ import {
|
|
|
74
82
|
AgentBnBError,
|
|
75
83
|
AnyCardSchema
|
|
76
84
|
} from "../../chunk-WVY2W7AA.js";
|
|
77
|
-
import {
|
|
78
|
-
RelayClient,
|
|
79
|
-
RelayMessageSchema
|
|
80
|
-
} from "../../chunk-3LWBH7P3.js";
|
|
81
85
|
|
|
82
86
|
// skills/agentbnb/bootstrap.ts
|
|
83
87
|
import { join as join7, basename as basename2, dirname as dirname3 } from "path";
|
|
84
88
|
import { homedir as homedir4 } from "os";
|
|
85
89
|
import { exec } from "child_process";
|
|
86
90
|
import { promisify as promisify2 } from "util";
|
|
87
|
-
import { randomUUID as
|
|
91
|
+
import { randomUUID as randomUUID11 } from "crypto";
|
|
88
92
|
|
|
89
93
|
// src/runtime/process-guard.ts
|
|
90
94
|
import { dirname, join } from "path";
|
|
@@ -1272,7 +1276,7 @@ var AgentRuntime = class {
|
|
|
1272
1276
|
}
|
|
1273
1277
|
const modes = /* @__PURE__ */ new Map();
|
|
1274
1278
|
if (this.conductorEnabled) {
|
|
1275
|
-
const { ConductorMode } = await import("../../conductor-mode-
|
|
1279
|
+
const { ConductorMode } = await import("../../conductor-mode-WKB42PYM.js");
|
|
1276
1280
|
const { registerConductorCard, CONDUCTOR_OWNER } = await import("../../card-EX2EYGCZ.js");
|
|
1277
1281
|
const { loadPeers: loadPeers2 } = await import("../../peers-CJ7T4RJO.js");
|
|
1278
1282
|
registerConductorCard(this.registryDb);
|
|
@@ -1585,6 +1589,7 @@ import swaggerUi from "@fastify/swagger-ui";
|
|
|
1585
1589
|
import fastifyStatic from "@fastify/static";
|
|
1586
1590
|
import fastifyWebsocket from "@fastify/websocket";
|
|
1587
1591
|
import { join as join3, dirname as dirname2 } from "path";
|
|
1592
|
+
import { randomUUID as randomUUID7 } from "crypto";
|
|
1588
1593
|
import { fileURLToPath } from "url";
|
|
1589
1594
|
import { existsSync as existsSync4 } from "fs";
|
|
1590
1595
|
import { z as z7 } from "zod";
|
|
@@ -5533,15 +5538,60 @@ function createRegistryServer(opts) {
|
|
|
5533
5538
|
});
|
|
5534
5539
|
}
|
|
5535
5540
|
const { requests, strategy, total_budget } = parseResult.data;
|
|
5536
|
-
const
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5541
|
+
const host = request.headers.host ?? request.hostname;
|
|
5542
|
+
const relayRegistryUrl = `${request.protocol}://${host}`;
|
|
5543
|
+
const relayRequesterOwner = `${owner}:batch:${Date.now()}`;
|
|
5544
|
+
let relayClient;
|
|
5545
|
+
try {
|
|
5546
|
+
const batchResult = await executeCapabilityBatch({
|
|
5547
|
+
requests,
|
|
5548
|
+
strategy,
|
|
5549
|
+
total_budget,
|
|
5550
|
+
registryDb: db,
|
|
5551
|
+
creditDb: opts.creditDb,
|
|
5552
|
+
owner,
|
|
5553
|
+
registryUrl: relayRegistryUrl,
|
|
5554
|
+
dispatchRequest: async ({ target, params, requester }) => {
|
|
5555
|
+
if (!target.via_relay) {
|
|
5556
|
+
return { card_id: target.cardId, skill_id: target.skillId };
|
|
5557
|
+
}
|
|
5558
|
+
if (!relayClient) {
|
|
5559
|
+
const { RelayClient: RelayClient2 } = await import("../../websocket-client-4Z5P54RU.js");
|
|
5560
|
+
relayClient = new RelayClient2({
|
|
5561
|
+
registryUrl: relayRegistryUrl,
|
|
5562
|
+
owner: relayRequesterOwner,
|
|
5563
|
+
token: "batch-token",
|
|
5564
|
+
card: {
|
|
5565
|
+
spec_version: "1.0",
|
|
5566
|
+
id: randomUUID7(),
|
|
5567
|
+
owner: relayRequesterOwner,
|
|
5568
|
+
name: relayRequesterOwner,
|
|
5569
|
+
description: "Batch requester",
|
|
5570
|
+
level: 1,
|
|
5571
|
+
inputs: [],
|
|
5572
|
+
outputs: [],
|
|
5573
|
+
pricing: { credits_per_call: 1 },
|
|
5574
|
+
availability: { online: false }
|
|
5575
|
+
},
|
|
5576
|
+
onRequest: async () => ({ error: { code: -32601, message: "Batch requester does not serve capabilities" } }),
|
|
5577
|
+
silent: true
|
|
5578
|
+
});
|
|
5579
|
+
await relayClient.connect();
|
|
5580
|
+
}
|
|
5581
|
+
const { requestViaRelay: requestViaRelay2 } = await import("../../client-XOLP5IUZ.js");
|
|
5582
|
+
return requestViaRelay2(relayClient, {
|
|
5583
|
+
targetOwner: target.owner,
|
|
5584
|
+
cardId: target.cardId,
|
|
5585
|
+
skillId: target.skillId,
|
|
5586
|
+
params: { ...params, requester },
|
|
5587
|
+
requester
|
|
5588
|
+
});
|
|
5589
|
+
}
|
|
5590
|
+
});
|
|
5591
|
+
return reply.send(batchResult);
|
|
5592
|
+
} finally {
|
|
5593
|
+
relayClient?.disconnect();
|
|
5594
|
+
}
|
|
5545
5595
|
});
|
|
5546
5596
|
if (opts.ownerApiKey && opts.ownerName) {
|
|
5547
5597
|
const ownerApiKey = opts.ownerApiKey;
|
|
@@ -6123,7 +6173,7 @@ function extractErrorMessage(err) {
|
|
|
6123
6173
|
import { spawn as spawn2 } from "child_process";
|
|
6124
6174
|
import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
|
|
6125
6175
|
import { join as join5 } from "path";
|
|
6126
|
-
import { randomUUID as
|
|
6176
|
+
import { randomUUID as randomUUID8 } from "crypto";
|
|
6127
6177
|
var ServiceCoordinator = class {
|
|
6128
6178
|
config;
|
|
6129
6179
|
guard;
|
|
@@ -6326,10 +6376,10 @@ var ServiceCoordinator = class {
|
|
|
6326
6376
|
}
|
|
6327
6377
|
if (opts.registryUrl && opts.relay) {
|
|
6328
6378
|
const { RelayClient: RelayClient2 } = await import("../../websocket-client-4Z5P54RU.js");
|
|
6329
|
-
const { executeCapabilityRequest: executeCapabilityRequest2 } = await import("../../execute-
|
|
6379
|
+
const { executeCapabilityRequest: executeCapabilityRequest2 } = await import("../../execute-NNDCXTN4.js");
|
|
6330
6380
|
const cards = listCards(this.runtime.registryDb, this.config.owner);
|
|
6331
6381
|
const card = cards[0] ?? {
|
|
6332
|
-
id:
|
|
6382
|
+
id: randomUUID8(),
|
|
6333
6383
|
owner: this.config.owner,
|
|
6334
6384
|
name: this.config.owner,
|
|
6335
6385
|
description: "Agent registered via CLI",
|
|
@@ -6635,11 +6685,11 @@ function sleep2(ms) {
|
|
|
6635
6685
|
}
|
|
6636
6686
|
|
|
6637
6687
|
// src/app/agentbnb-service.ts
|
|
6638
|
-
import { randomUUID as
|
|
6688
|
+
import { randomUUID as randomUUID10 } from "crypto";
|
|
6639
6689
|
|
|
6640
6690
|
// src/credit/escrow-receipt.ts
|
|
6641
6691
|
import { z as z8 } from "zod";
|
|
6642
|
-
import { randomUUID as
|
|
6692
|
+
import { randomUUID as randomUUID9 } from "crypto";
|
|
6643
6693
|
var EscrowReceiptSchema = z8.object({
|
|
6644
6694
|
requester_owner: z8.string().min(1),
|
|
6645
6695
|
requester_agent_id: z8.string().optional(),
|
|
@@ -6661,7 +6711,7 @@ function createSignedEscrowReceipt(db, privateKey, publicKey, opts) {
|
|
|
6661
6711
|
card_id: opts.cardId,
|
|
6662
6712
|
...opts.skillId ? { skill_id: opts.skillId } : {},
|
|
6663
6713
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6664
|
-
nonce:
|
|
6714
|
+
nonce: randomUUID9()
|
|
6665
6715
|
};
|
|
6666
6716
|
const signature = signEscrowReceipt(receiptData, privateKey);
|
|
6667
6717
|
const receipt = {
|
|
@@ -6903,13 +6953,13 @@ var AgentBnBService = class {
|
|
|
6903
6953
|
if (!this.config.registry) {
|
|
6904
6954
|
throw new AgentBnBError("Registry is required for relay fallback.", "RELAY_NOT_AVAILABLE");
|
|
6905
6955
|
}
|
|
6906
|
-
const requesterId = `${this.config.owner}:req:${
|
|
6956
|
+
const requesterId = `${this.config.owner}:req:${randomUUID10()}`;
|
|
6907
6957
|
const tempRelay = new RelayClient({
|
|
6908
6958
|
registryUrl: this.config.registry,
|
|
6909
6959
|
owner: requesterId,
|
|
6910
6960
|
token: this.config.token,
|
|
6911
6961
|
card: {
|
|
6912
|
-
id:
|
|
6962
|
+
id: randomUUID10(),
|
|
6913
6963
|
owner: requesterId,
|
|
6914
6964
|
name: requesterId,
|
|
6915
6965
|
description: "Requester",
|
|
@@ -7129,12 +7179,23 @@ async function handleRequest(args, ctx) {
|
|
|
7129
7179
|
} finally {
|
|
7130
7180
|
db.close();
|
|
7131
7181
|
}
|
|
7182
|
+
let identityAuth;
|
|
7183
|
+
try {
|
|
7184
|
+
const keys = loadKeyPair(ctx.configDir);
|
|
7185
|
+
identityAuth = {
|
|
7186
|
+
agentId: ctx.identity.agent_id,
|
|
7187
|
+
publicKey: ctx.identity.public_key,
|
|
7188
|
+
privateKey: keys.privateKey
|
|
7189
|
+
};
|
|
7190
|
+
} catch {
|
|
7191
|
+
}
|
|
7132
7192
|
if (localCard && localCard.owner === ctx.config.owner) {
|
|
7133
7193
|
const result = await requestCapability({
|
|
7134
7194
|
gatewayUrl: ctx.config.gateway_url,
|
|
7135
7195
|
token: ctx.config.token,
|
|
7136
7196
|
cardId,
|
|
7137
|
-
params: { ...args.params ?? {}, ...args.skill_id ? { skill_id: args.skill_id } : {}, requester: ctx.config.owner }
|
|
7197
|
+
params: { ...args.params ?? {}, ...args.skill_id ? { skill_id: args.skill_id } : {}, requester: ctx.config.owner },
|
|
7198
|
+
identity: identityAuth
|
|
7138
7199
|
});
|
|
7139
7200
|
return {
|
|
7140
7201
|
content: [{ type: "text", text: JSON.stringify({ success: true, result }, null, 2) }]
|
|
@@ -7164,33 +7225,16 @@ async function handleRequest(args, ctx) {
|
|
|
7164
7225
|
const targetOwner = remoteCard["owner"] ?? remoteCard["agent_name"];
|
|
7165
7226
|
const gatewayUrl = remoteCard["gateway_url"];
|
|
7166
7227
|
if (gatewayUrl) {
|
|
7167
|
-
const
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7228
|
+
const result = await requestCapability({
|
|
7229
|
+
gatewayUrl,
|
|
7230
|
+
token: "",
|
|
7231
|
+
cardId,
|
|
7232
|
+
params: { ...args.params ?? {}, ...args.skill_id ? { skill_id: args.skill_id } : {}, requester: ctx.config.owner },
|
|
7233
|
+
identity: identityAuth
|
|
7172
7234
|
});
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
gatewayUrl,
|
|
7177
|
-
token: "",
|
|
7178
|
-
cardId,
|
|
7179
|
-
params: { ...args.params ?? {}, ...args.skill_id ? { skill_id: args.skill_id } : {}, requester: ctx.config.owner },
|
|
7180
|
-
identity: {
|
|
7181
|
-
agentId: ctx.identity.agent_id,
|
|
7182
|
-
publicKey: ctx.identity.public_key,
|
|
7183
|
-
privateKey: keys.privateKey
|
|
7184
|
-
}
|
|
7185
|
-
});
|
|
7186
|
-
await ledger.settle(escrowId, targetOwner ?? "unknown");
|
|
7187
|
-
return {
|
|
7188
|
-
content: [{ type: "text", text: JSON.stringify({ success: true, result, credits_spent: maxCost }, null, 2) }]
|
|
7189
|
-
};
|
|
7190
|
-
} catch (err) {
|
|
7191
|
-
await ledger.release(escrowId);
|
|
7192
|
-
throw err;
|
|
7193
|
-
}
|
|
7235
|
+
return {
|
|
7236
|
+
content: [{ type: "text", text: JSON.stringify({ success: true, result }, null, 2) }]
|
|
7237
|
+
};
|
|
7194
7238
|
}
|
|
7195
7239
|
if (targetOwner) {
|
|
7196
7240
|
const relay = new RelayClient({
|
|
@@ -7714,7 +7758,7 @@ function registerDecomposerCard(configDir, owner) {
|
|
|
7714
7758
|
"SELECT id FROM capability_cards WHERE owner = ? AND json_extract(data, '$.capability_type') = ?"
|
|
7715
7759
|
).get(owner, "task_decomposition");
|
|
7716
7760
|
if (existing) return;
|
|
7717
|
-
const cardId =
|
|
7761
|
+
const cardId = randomUUID11();
|
|
7718
7762
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
7719
7763
|
const card = {
|
|
7720
7764
|
spec_version: "2.0",
|
|
@@ -7781,7 +7825,7 @@ function deriveAgentName(configDir) {
|
|
|
7781
7825
|
if (parent && parent !== "." && parent !== ".agentbnb" && parent !== homedir4().split("/").pop()) {
|
|
7782
7826
|
return parent;
|
|
7783
7827
|
}
|
|
7784
|
-
return `agent-${
|
|
7828
|
+
return `agent-${randomUUID11().slice(0, 8)}`;
|
|
7785
7829
|
}
|
|
7786
7830
|
var defaultDeps = { resolveSelfCli, runCommand };
|
|
7787
7831
|
async function autoOnboard(configDir, deps = defaultDeps) {
|
package/package.json
CHANGED
package/dist/chunk-BZOJ7HBT.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getFeedbackForProvider
|
|
3
|
-
} from "./chunk-SRBVKO2V.js";
|
|
4
|
-
|
|
5
|
-
// src/feedback/reputation.ts
|
|
6
|
-
var QUALITY_SCORES = {
|
|
7
|
-
excellent: 1,
|
|
8
|
-
good: 0.8,
|
|
9
|
-
acceptable: 0.6,
|
|
10
|
-
poor: 0.3,
|
|
11
|
-
failed: 0
|
|
12
|
-
};
|
|
13
|
-
var COST_VALUE_SCORES = {
|
|
14
|
-
great: 1,
|
|
15
|
-
fair: 0.6,
|
|
16
|
-
overpriced: 0.2
|
|
17
|
-
};
|
|
18
|
-
var DECAY_DAYS = 30;
|
|
19
|
-
var WEIGHTS = {
|
|
20
|
-
rating: 0.4,
|
|
21
|
-
quality: 0.3,
|
|
22
|
-
would_reuse: 0.2,
|
|
23
|
-
cost_value: 0.1
|
|
24
|
-
};
|
|
25
|
-
function computeReputation(feedbacks) {
|
|
26
|
-
if (feedbacks.length === 0) return 0.5;
|
|
27
|
-
const now = Date.now();
|
|
28
|
-
let weightedSum = 0;
|
|
29
|
-
let totalWeight = 0;
|
|
30
|
-
for (const fb of feedbacks) {
|
|
31
|
-
const feedbackDate = new Date(fb.timestamp).getTime();
|
|
32
|
-
const ageDays = Math.max(0, (now - feedbackDate) / (1e3 * 60 * 60 * 24));
|
|
33
|
-
const recencyWeight = Math.exp(-ageDays / DECAY_DAYS);
|
|
34
|
-
const ratingScore = (fb.rating - 1) / 4;
|
|
35
|
-
const qualityScore = QUALITY_SCORES[fb.result_quality];
|
|
36
|
-
const reuseScore = fb.would_reuse ? 1 : 0;
|
|
37
|
-
const costScore = COST_VALUE_SCORES[fb.cost_value_ratio];
|
|
38
|
-
const componentScore = WEIGHTS.rating * ratingScore + WEIGHTS.quality * qualityScore + WEIGHTS.would_reuse * reuseScore + WEIGHTS.cost_value * costScore;
|
|
39
|
-
weightedSum += recencyWeight * componentScore;
|
|
40
|
-
totalWeight += recencyWeight;
|
|
41
|
-
}
|
|
42
|
-
if (totalWeight === 0) return 0.5;
|
|
43
|
-
const raw = weightedSum / totalWeight;
|
|
44
|
-
return Math.max(0, Math.min(1, raw));
|
|
45
|
-
}
|
|
46
|
-
function getReputationScore(db, agentId) {
|
|
47
|
-
const feedbacks = getFeedbackForProvider(db, agentId);
|
|
48
|
-
return computeReputation(feedbacks);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/registry/matcher.ts
|
|
52
|
-
var CACHE_MAX_ENTRIES = 100;
|
|
53
|
-
var CACHE_TTL_MS = 3e4;
|
|
54
|
-
var dbCaches = /* @__PURE__ */ new WeakMap();
|
|
55
|
-
function getDbCache(db) {
|
|
56
|
-
let cache = dbCaches.get(db);
|
|
57
|
-
if (!cache) {
|
|
58
|
-
cache = /* @__PURE__ */ new Map();
|
|
59
|
-
dbCaches.set(db, cache);
|
|
60
|
-
}
|
|
61
|
-
return cache;
|
|
62
|
-
}
|
|
63
|
-
function cacheKey(query, filters) {
|
|
64
|
-
return `${query}|${filters.level ?? ""}|${filters.online ?? ""}|${(filters.apis_used ?? []).join(",")}|${filters.min_reputation ?? ""}`;
|
|
65
|
-
}
|
|
66
|
-
function evictCache(cache) {
|
|
67
|
-
const now = Date.now();
|
|
68
|
-
for (const [key, entry] of cache) {
|
|
69
|
-
if (entry.expiresAt <= now) cache.delete(key);
|
|
70
|
-
}
|
|
71
|
-
while (cache.size > CACHE_MAX_ENTRIES) {
|
|
72
|
-
const firstKey = cache.keys().next().value;
|
|
73
|
-
cache.delete(firstKey);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function searchCards(db, query, filters = {}) {
|
|
77
|
-
const cache = getDbCache(db);
|
|
78
|
-
const key = cacheKey(query, filters);
|
|
79
|
-
const cached = cache.get(key);
|
|
80
|
-
if (cached && cached.expiresAt > Date.now()) {
|
|
81
|
-
return cached.results;
|
|
82
|
-
}
|
|
83
|
-
const words = query.trim().split(/\s+/).map((w) => w.replace(/["*^{}():]/g, "")).filter((w) => w.length > 0);
|
|
84
|
-
if (words.length === 0) return [];
|
|
85
|
-
const ftsQuery = words.map((w) => `"${w}"`).join(" OR ");
|
|
86
|
-
const conditions = [];
|
|
87
|
-
const params = [ftsQuery];
|
|
88
|
-
if (filters.level !== void 0) {
|
|
89
|
-
conditions.push(`json_extract(cc.data, '$.level') = ?`);
|
|
90
|
-
params.push(filters.level);
|
|
91
|
-
}
|
|
92
|
-
if (filters.online !== void 0) {
|
|
93
|
-
conditions.push(`json_extract(cc.data, '$.availability.online') = ?`);
|
|
94
|
-
params.push(filters.online ? 1 : 0);
|
|
95
|
-
}
|
|
96
|
-
const whereClause = conditions.length > 0 ? `AND ${conditions.join(" AND ")}` : "";
|
|
97
|
-
const sql = `
|
|
98
|
-
SELECT cc.data
|
|
99
|
-
FROM capability_cards cc
|
|
100
|
-
JOIN cards_fts ON cc.rowid = cards_fts.rowid
|
|
101
|
-
WHERE cards_fts MATCH ?
|
|
102
|
-
${whereClause}
|
|
103
|
-
ORDER BY bm25(cards_fts)
|
|
104
|
-
LIMIT 50
|
|
105
|
-
`;
|
|
106
|
-
const stmt = db.prepare(sql);
|
|
107
|
-
const rows = stmt.all(...params);
|
|
108
|
-
const results = rows.map((row) => JSON.parse(row.data));
|
|
109
|
-
let filtered = results;
|
|
110
|
-
if (filters.apis_used && filters.apis_used.length > 0) {
|
|
111
|
-
const requiredApis = filters.apis_used;
|
|
112
|
-
filtered = filtered.filter((card) => {
|
|
113
|
-
const cardApis = card.metadata?.apis_used ?? [];
|
|
114
|
-
return requiredApis.every((api) => cardApis.includes(api));
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (filters.min_reputation !== void 0 && filters.min_reputation > 0) {
|
|
118
|
-
filtered = applyReputationFilter(db, filtered, filters.min_reputation);
|
|
119
|
-
}
|
|
120
|
-
evictCache(cache);
|
|
121
|
-
cache.set(key, { results: filtered, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
122
|
-
return filtered;
|
|
123
|
-
}
|
|
124
|
-
function filterCards(db, filters) {
|
|
125
|
-
const conditions = [];
|
|
126
|
-
const params = [];
|
|
127
|
-
if (filters.level !== void 0) {
|
|
128
|
-
conditions.push(`json_extract(data, '$.level') = ?`);
|
|
129
|
-
params.push(filters.level);
|
|
130
|
-
}
|
|
131
|
-
if (filters.online !== void 0) {
|
|
132
|
-
conditions.push(`json_extract(data, '$.availability.online') = ?`);
|
|
133
|
-
params.push(filters.online ? 1 : 0);
|
|
134
|
-
}
|
|
135
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
136
|
-
const sql = `SELECT data FROM capability_cards ${whereClause}`;
|
|
137
|
-
const stmt = db.prepare(sql);
|
|
138
|
-
const rows = stmt.all(...params);
|
|
139
|
-
let cards = rows.map((row) => JSON.parse(row.data));
|
|
140
|
-
if (filters.min_reputation !== void 0 && filters.min_reputation > 0) {
|
|
141
|
-
cards = applyReputationFilter(db, cards, filters.min_reputation);
|
|
142
|
-
}
|
|
143
|
-
return cards;
|
|
144
|
-
}
|
|
145
|
-
function applyReputationFilter(db, cards, minReputation) {
|
|
146
|
-
const owners = [...new Set(cards.map((c) => c.owner))];
|
|
147
|
-
const reputationMap = /* @__PURE__ */ new Map();
|
|
148
|
-
for (const owner of owners) {
|
|
149
|
-
reputationMap.set(owner, getReputationScore(db, owner));
|
|
150
|
-
}
|
|
151
|
-
return cards.filter((card) => {
|
|
152
|
-
const score = reputationMap.get(card.owner) ?? 0.5;
|
|
153
|
-
return score >= minReputation;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
function buildReputationMap(db, owners) {
|
|
157
|
-
const unique = [...new Set(owners)];
|
|
158
|
-
const map = /* @__PURE__ */ new Map();
|
|
159
|
-
for (const owner of unique) {
|
|
160
|
-
map.set(owner, getReputationScore(db, owner));
|
|
161
|
-
}
|
|
162
|
-
return map;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export {
|
|
166
|
-
computeReputation,
|
|
167
|
-
searchCards,
|
|
168
|
-
filterCards,
|
|
169
|
-
buildReputationMap
|
|
170
|
-
};
|
package/dist/chunk-KF3TZHA5.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AgentBnBError
|
|
3
|
-
} from "./chunk-WVY2W7AA.js";
|
|
4
|
-
|
|
5
|
-
// src/cli/remote-registry.ts
|
|
6
|
-
var RegistryTimeoutError = class extends AgentBnBError {
|
|
7
|
-
constructor(url) {
|
|
8
|
-
super(
|
|
9
|
-
`Registry at ${url} did not respond within 5s. Showing local results only.`,
|
|
10
|
-
"REGISTRY_TIMEOUT"
|
|
11
|
-
);
|
|
12
|
-
this.name = "RegistryTimeoutError";
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var RegistryConnectionError = class extends AgentBnBError {
|
|
16
|
-
constructor(url) {
|
|
17
|
-
super(
|
|
18
|
-
`Cannot reach ${url}. Is the registry running? Showing local results only.`,
|
|
19
|
-
"REGISTRY_CONNECTION"
|
|
20
|
-
);
|
|
21
|
-
this.name = "RegistryConnectionError";
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var RegistryAuthError = class extends AgentBnBError {
|
|
25
|
-
constructor(url) {
|
|
26
|
-
super(
|
|
27
|
-
`Authentication failed for ${url}. Run \`agentbnb config set token <your-token>\`.`,
|
|
28
|
-
"REGISTRY_AUTH"
|
|
29
|
-
);
|
|
30
|
-
this.name = "RegistryAuthError";
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
async function fetchRemoteCards(registryUrl, params, timeoutMs = 5e3) {
|
|
34
|
-
let cardsUrl;
|
|
35
|
-
try {
|
|
36
|
-
cardsUrl = new URL("/cards", registryUrl);
|
|
37
|
-
} catch {
|
|
38
|
-
throw new AgentBnBError(`Invalid registry URL: ${registryUrl}`, "INVALID_REGISTRY_URL");
|
|
39
|
-
}
|
|
40
|
-
const searchParams = new URLSearchParams();
|
|
41
|
-
if (params.q !== void 0) searchParams.set("q", params.q);
|
|
42
|
-
if (params.level !== void 0) searchParams.set("level", String(params.level));
|
|
43
|
-
if (params.online !== void 0) searchParams.set("online", String(params.online));
|
|
44
|
-
if (params.tag !== void 0) searchParams.set("tag", params.tag);
|
|
45
|
-
searchParams.set("limit", "100");
|
|
46
|
-
cardsUrl.search = searchParams.toString();
|
|
47
|
-
const controller = new AbortController();
|
|
48
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
49
|
-
let response;
|
|
50
|
-
try {
|
|
51
|
-
response = await fetch(cardsUrl.toString(), { signal: controller.signal });
|
|
52
|
-
} catch (err) {
|
|
53
|
-
clearTimeout(timer);
|
|
54
|
-
const isTimeout = err instanceof Error && err.name === "AbortError";
|
|
55
|
-
if (isTimeout) {
|
|
56
|
-
throw new RegistryTimeoutError(registryUrl);
|
|
57
|
-
}
|
|
58
|
-
throw new RegistryConnectionError(registryUrl);
|
|
59
|
-
} finally {
|
|
60
|
-
clearTimeout(timer);
|
|
61
|
-
}
|
|
62
|
-
if (response.status === 401 || response.status === 403) {
|
|
63
|
-
throw new RegistryAuthError(registryUrl);
|
|
64
|
-
}
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
throw new RegistryConnectionError(registryUrl);
|
|
67
|
-
}
|
|
68
|
-
const body = await response.json();
|
|
69
|
-
return body.items;
|
|
70
|
-
}
|
|
71
|
-
function mergeResults(localCards, remoteCards, hasQuery) {
|
|
72
|
-
const taggedLocal = localCards.map((c) => ({ ...c, source: "local" }));
|
|
73
|
-
const taggedRemote = remoteCards.map((c) => ({ ...c, source: "remote" }));
|
|
74
|
-
const localIds = new Set(localCards.map((c) => c.id));
|
|
75
|
-
const dedupedRemote = taggedRemote.filter((c) => !localIds.has(c.id));
|
|
76
|
-
if (!hasQuery) {
|
|
77
|
-
return [...taggedLocal, ...dedupedRemote];
|
|
78
|
-
}
|
|
79
|
-
const result = [];
|
|
80
|
-
const maxLen = Math.max(taggedLocal.length, dedupedRemote.length);
|
|
81
|
-
for (let i = 0; i < maxLen; i++) {
|
|
82
|
-
if (i < taggedLocal.length) result.push(taggedLocal[i]);
|
|
83
|
-
if (i < dedupedRemote.length) result.push(dedupedRemote[i]);
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export {
|
|
89
|
-
fetchRemoteCards,
|
|
90
|
-
mergeResults
|
|
91
|
-
};
|