agentbnb 4.0.4 → 5.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.
- package/dist/chunk-AUBHR7HH.js +25 -0
- package/dist/chunk-B5FTAGFN.js +393 -0
- package/dist/{chunk-GGYC5U2Z.js → chunk-BTTL24TZ.js} +29 -91
- package/dist/chunk-C6KPAFCC.js +387 -0
- package/dist/{chunk-JXEOE7HX.js → chunk-CRFCWD6V.js} +163 -92
- package/dist/chunk-CSATDXZC.js +89 -0
- package/dist/{chunk-T7NS2J2B.js → chunk-DFBX3BBD.js} +84 -1
- package/dist/{chunk-DNWT5FZQ.js → chunk-EANI2N2V.js} +98 -1
- package/dist/{chunk-HH24WMFN.js → chunk-FLY3WIQR.js} +1 -1
- package/dist/{chunk-EVBX22YU.js → chunk-HLUEOLSZ.js} +11 -17
- package/dist/chunk-IVOYM3WG.js +25 -0
- package/dist/chunk-LCAIAAG2.js +916 -0
- package/dist/chunk-MLS6IGGG.js +294 -0
- package/dist/{chunk-4P3EMGL4.js → chunk-MNO4COST.js} +5 -3
- package/dist/chunk-NH2FIERR.js +138 -0
- package/dist/chunk-UKT6H7YT.js +29 -0
- package/dist/{chunk-BH6WGYFB.js → chunk-VE3E4AMH.js} +8 -8
- package/dist/{chunk-5QGXARLJ.js → chunk-W5BZMKMF.js} +159 -27
- package/dist/{chunk-FF226TIV.js → chunk-ZX5623ER.js} +0 -57
- package/dist/cli/index.js +362 -4633
- package/dist/{conduct-N52JX7RT.js → conduct-KM6ZNJGE.js} +10 -8
- package/dist/{conduct-GZQNFTRP.js → conduct-WGTMQND5.js} +10 -8
- package/dist/{conductor-mode-XUWGR4ZE.js → conductor-mode-OL2FNOYY.js} +6 -4
- package/dist/{conductor-mode-ESGFZ6T5.js → conductor-mode-VRO7TYW2.js} +20 -167
- package/dist/execute-CPFSOOO3.js +13 -0
- package/dist/execute-IP2QHALV.js +10 -0
- package/dist/index.d.ts +14 -8
- package/dist/index.js +186 -35
- package/dist/{peers-E4MKNNDN.js → peers-CJ7T4RJO.js} +2 -1
- package/dist/process-guard-CC7CNRQJ.js +176 -0
- package/dist/{request-4GQSSM4B.js → request-YOWPXVLQ.js} +13 -10
- package/dist/schema-7BSSLZ4S.js +8 -0
- package/dist/{serve-skill-Q6NHX2RA.js → serve-skill-JHFNR7BW.js} +8 -7
- package/dist/{server-B5E566CI.js → server-HKJJWFRG.js} +10 -8
- package/dist/service-coordinator-5R4LQW6L.js +4917 -0
- package/dist/skills/agentbnb/bootstrap.js +5028 -848
- package/dist/websocket-client-WRN3HO73.js +6 -0
- package/package.json +4 -1
- package/skills/agentbnb/SKILL.md +87 -70
- package/skills/agentbnb/bootstrap.test.ts +142 -242
- package/skills/agentbnb/bootstrap.ts +88 -95
- package/skills/agentbnb/install.sh +97 -27
- package/dist/card-RNEWSAQ6.js +0 -88
- package/dist/chunk-UB2NPFC7.js +0 -165
- package/dist/execute-QH6F54D7.js +0 -10
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import {
|
|
2
|
+
searchCards
|
|
3
|
+
} from "./chunk-NH2FIERR.js";
|
|
4
|
+
|
|
5
|
+
// src/cli/onboarding.ts
|
|
6
|
+
import { randomUUID } from "crypto";
|
|
7
|
+
import { createConnection } from "net";
|
|
8
|
+
var KNOWN_API_KEYS = [
|
|
9
|
+
"OPENAI_API_KEY",
|
|
10
|
+
"ANTHROPIC_API_KEY",
|
|
11
|
+
"ELEVENLABS_API_KEY",
|
|
12
|
+
"KLING_API_KEY",
|
|
13
|
+
"STABILITY_API_KEY",
|
|
14
|
+
"REPLICATE_API_TOKEN",
|
|
15
|
+
"GOOGLE_API_KEY",
|
|
16
|
+
"AZURE_OPENAI_API_KEY",
|
|
17
|
+
"COHERE_API_KEY",
|
|
18
|
+
"MISTRAL_API_KEY"
|
|
19
|
+
];
|
|
20
|
+
var API_TEMPLATES = {
|
|
21
|
+
OPENAI_API_KEY: {
|
|
22
|
+
name: "OpenAI Text Generation",
|
|
23
|
+
description: "Text completion and chat via OpenAI API",
|
|
24
|
+
level: 1,
|
|
25
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
26
|
+
outputs: [{ name: "completion", type: "text", required: true }],
|
|
27
|
+
pricing: { credits_per_call: 5 },
|
|
28
|
+
powered_by: [{ provider: "OpenAI", model: "GPT-4o" }],
|
|
29
|
+
metadata: { apis_used: ["openai"], tags: ["llm", "text", "generation"] }
|
|
30
|
+
},
|
|
31
|
+
ANTHROPIC_API_KEY: {
|
|
32
|
+
name: "Anthropic Claude",
|
|
33
|
+
description: "Text reasoning and analysis via Anthropic Claude API",
|
|
34
|
+
level: 1,
|
|
35
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
36
|
+
outputs: [{ name: "response", type: "text", required: true }],
|
|
37
|
+
pricing: { credits_per_call: 5 },
|
|
38
|
+
powered_by: [{ provider: "Anthropic", model: "Claude" }],
|
|
39
|
+
metadata: { apis_used: ["anthropic"], tags: ["llm", "text", "reasoning"] }
|
|
40
|
+
},
|
|
41
|
+
ELEVENLABS_API_KEY: {
|
|
42
|
+
name: "ElevenLabs Text-to-Speech",
|
|
43
|
+
description: "High-quality voice synthesis via ElevenLabs API",
|
|
44
|
+
level: 1,
|
|
45
|
+
inputs: [{ name: "text", type: "text", required: true }],
|
|
46
|
+
outputs: [{ name: "audio", type: "audio", required: true }],
|
|
47
|
+
pricing: { credits_per_call: 10 },
|
|
48
|
+
powered_by: [{ provider: "ElevenLabs" }],
|
|
49
|
+
metadata: { apis_used: ["elevenlabs"], tags: ["tts", "audio", "voice"] }
|
|
50
|
+
},
|
|
51
|
+
KLING_API_KEY: {
|
|
52
|
+
name: "Kling Video Generation",
|
|
53
|
+
description: "AI video generation via Kling API",
|
|
54
|
+
level: 1,
|
|
55
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
56
|
+
outputs: [{ name: "video", type: "video", required: true }],
|
|
57
|
+
pricing: { credits_per_call: 50 },
|
|
58
|
+
powered_by: [{ provider: "Kling", model: "v1.5" }],
|
|
59
|
+
metadata: { apis_used: ["kling"], tags: ["video", "generation", "ai"] }
|
|
60
|
+
},
|
|
61
|
+
STABILITY_API_KEY: {
|
|
62
|
+
name: "Stability AI Image Generation",
|
|
63
|
+
description: "Image generation via Stability AI (Stable Diffusion)",
|
|
64
|
+
level: 1,
|
|
65
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
66
|
+
outputs: [{ name: "image", type: "image", required: true }],
|
|
67
|
+
pricing: { credits_per_call: 8 },
|
|
68
|
+
powered_by: [{ provider: "Stability AI", model: "SDXL" }],
|
|
69
|
+
metadata: { apis_used: ["stability"], tags: ["image", "generation", "diffusion"] }
|
|
70
|
+
},
|
|
71
|
+
REPLICATE_API_TOKEN: {
|
|
72
|
+
name: "Replicate Model Runner",
|
|
73
|
+
description: "Run open-source models via Replicate API",
|
|
74
|
+
level: 1,
|
|
75
|
+
inputs: [{ name: "input", type: "json", required: true }],
|
|
76
|
+
outputs: [{ name: "output", type: "json", required: true }],
|
|
77
|
+
pricing: { credits_per_call: 10 },
|
|
78
|
+
powered_by: [{ provider: "Replicate" }],
|
|
79
|
+
metadata: { apis_used: ["replicate"], tags: ["ml", "inference"] }
|
|
80
|
+
},
|
|
81
|
+
GOOGLE_API_KEY: {
|
|
82
|
+
name: "Google AI (Gemini)",
|
|
83
|
+
description: "Multimodal AI via Google Gemini API",
|
|
84
|
+
level: 1,
|
|
85
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
86
|
+
outputs: [{ name: "response", type: "text", required: true }],
|
|
87
|
+
pricing: { credits_per_call: 5 },
|
|
88
|
+
powered_by: [{ provider: "Google", model: "Gemini" }],
|
|
89
|
+
metadata: { apis_used: ["google"], tags: ["llm", "multimodal", "text"] }
|
|
90
|
+
},
|
|
91
|
+
AZURE_OPENAI_API_KEY: {
|
|
92
|
+
name: "Azure OpenAI Service",
|
|
93
|
+
description: "OpenAI models hosted on Azure cloud",
|
|
94
|
+
level: 1,
|
|
95
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
96
|
+
outputs: [{ name: "completion", type: "text", required: true }],
|
|
97
|
+
pricing: { credits_per_call: 5 },
|
|
98
|
+
powered_by: [{ provider: "Azure OpenAI" }],
|
|
99
|
+
metadata: { apis_used: ["azure-openai"], tags: ["llm", "text", "azure"] }
|
|
100
|
+
},
|
|
101
|
+
COHERE_API_KEY: {
|
|
102
|
+
name: "Cohere Language AI",
|
|
103
|
+
description: "Text generation and embeddings via Cohere API",
|
|
104
|
+
level: 1,
|
|
105
|
+
inputs: [{ name: "text", type: "text", required: true }],
|
|
106
|
+
outputs: [{ name: "response", type: "text", required: true }],
|
|
107
|
+
pricing: { credits_per_call: 3 },
|
|
108
|
+
powered_by: [{ provider: "Cohere" }],
|
|
109
|
+
metadata: { apis_used: ["cohere"], tags: ["llm", "embeddings", "text"] }
|
|
110
|
+
},
|
|
111
|
+
MISTRAL_API_KEY: {
|
|
112
|
+
name: "Mistral AI",
|
|
113
|
+
description: "Text generation via Mistral AI API",
|
|
114
|
+
level: 1,
|
|
115
|
+
inputs: [{ name: "prompt", type: "text", required: true }],
|
|
116
|
+
outputs: [{ name: "response", type: "text", required: true }],
|
|
117
|
+
pricing: { credits_per_call: 4 },
|
|
118
|
+
powered_by: [{ provider: "Mistral" }],
|
|
119
|
+
metadata: { apis_used: ["mistral"], tags: ["llm", "text", "generation"] }
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function detectApiKeys(knownKeys) {
|
|
123
|
+
return knownKeys.filter((key) => key in process.env);
|
|
124
|
+
}
|
|
125
|
+
async function isPortOpen(port, host = "127.0.0.1", timeoutMs = 300) {
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
|
+
const socket = createConnection({ port, host });
|
|
128
|
+
const timer = setTimeout(() => {
|
|
129
|
+
socket.destroy();
|
|
130
|
+
resolve(false);
|
|
131
|
+
}, timeoutMs);
|
|
132
|
+
socket.on("connect", () => {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
socket.destroy();
|
|
135
|
+
resolve(true);
|
|
136
|
+
});
|
|
137
|
+
socket.on("error", () => {
|
|
138
|
+
clearTimeout(timer);
|
|
139
|
+
resolve(false);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async function detectOpenPorts(ports) {
|
|
144
|
+
const results = await Promise.all(
|
|
145
|
+
ports.map(async (port) => ({ port, open: await isPortOpen(port) }))
|
|
146
|
+
);
|
|
147
|
+
return results.filter((r) => r.open).map((r) => r.port);
|
|
148
|
+
}
|
|
149
|
+
function buildDraftCard(apiKey, owner) {
|
|
150
|
+
const template = API_TEMPLATES[apiKey];
|
|
151
|
+
if (!template) return null;
|
|
152
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
153
|
+
return {
|
|
154
|
+
spec_version: "1.0",
|
|
155
|
+
id: randomUUID(),
|
|
156
|
+
owner,
|
|
157
|
+
name: template.name,
|
|
158
|
+
description: template.description,
|
|
159
|
+
level: template.level,
|
|
160
|
+
inputs: template.inputs,
|
|
161
|
+
outputs: template.outputs,
|
|
162
|
+
pricing: template.pricing,
|
|
163
|
+
availability: { online: true },
|
|
164
|
+
powered_by: template.powered_by,
|
|
165
|
+
metadata: {
|
|
166
|
+
apis_used: template.metadata.apis_used,
|
|
167
|
+
tags: template.metadata.tags
|
|
168
|
+
},
|
|
169
|
+
created_at: now,
|
|
170
|
+
updated_at: now
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/registry/pricing.ts
|
|
175
|
+
function getPricingStats(db, query) {
|
|
176
|
+
const cards = searchCards(db, query);
|
|
177
|
+
const prices = [];
|
|
178
|
+
const queryLower = query.toLowerCase();
|
|
179
|
+
const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
|
|
180
|
+
for (const card of cards) {
|
|
181
|
+
const v2 = card;
|
|
182
|
+
if (v2.skills && v2.skills.length > 0) {
|
|
183
|
+
for (const skill of v2.skills) {
|
|
184
|
+
const nameMatch = skillMatchesQuery(skill, queryWords);
|
|
185
|
+
if (nameMatch) {
|
|
186
|
+
prices.push(skill.pricing.credits_per_call);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
prices.push(card.pricing.credits_per_call);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (prices.length === 0) {
|
|
194
|
+
return { min: 0, max: 0, median: 0, mean: 0, count: 0 };
|
|
195
|
+
}
|
|
196
|
+
prices.sort((a, b) => a - b);
|
|
197
|
+
const min = prices[0];
|
|
198
|
+
const max = prices[prices.length - 1];
|
|
199
|
+
const mean = prices.reduce((sum, p) => sum + p, 0) / prices.length;
|
|
200
|
+
const median = computeMedian(prices);
|
|
201
|
+
return { min, max, median, mean, count: prices.length };
|
|
202
|
+
}
|
|
203
|
+
function skillMatchesQuery(skill, queryWords) {
|
|
204
|
+
const text = `${skill.name} ${skill.description}`.toLowerCase();
|
|
205
|
+
return queryWords.some((word) => text.includes(word));
|
|
206
|
+
}
|
|
207
|
+
function computeMedian(sorted) {
|
|
208
|
+
const mid = Math.floor(sorted.length / 2);
|
|
209
|
+
if (sorted.length % 2 === 1) {
|
|
210
|
+
return sorted[mid];
|
|
211
|
+
}
|
|
212
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/discovery/mdns.ts
|
|
216
|
+
import { Bonjour } from "bonjour-service";
|
|
217
|
+
var bonjourInstance = null;
|
|
218
|
+
function getBonjour() {
|
|
219
|
+
if (bonjourInstance === null) {
|
|
220
|
+
bonjourInstance = new Bonjour();
|
|
221
|
+
}
|
|
222
|
+
return bonjourInstance;
|
|
223
|
+
}
|
|
224
|
+
function announceGateway(owner, port, metadata) {
|
|
225
|
+
const bonjour = getBonjour();
|
|
226
|
+
const txt = {
|
|
227
|
+
owner,
|
|
228
|
+
version: "1.0",
|
|
229
|
+
...metadata
|
|
230
|
+
};
|
|
231
|
+
bonjour.publish({
|
|
232
|
+
name: owner,
|
|
233
|
+
type: "agentbnb",
|
|
234
|
+
port,
|
|
235
|
+
txt
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function discoverLocalAgents(onFound, onDown) {
|
|
239
|
+
const bonjour = getBonjour();
|
|
240
|
+
const browser = bonjour.find({ type: "agentbnb" });
|
|
241
|
+
browser.on("up", (service) => {
|
|
242
|
+
const addresses = service.addresses ?? [];
|
|
243
|
+
const ipv4Addresses = addresses.filter((addr) => !addr.includes(":"));
|
|
244
|
+
const host = ipv4Addresses.length > 0 ? ipv4Addresses[0] : service.host;
|
|
245
|
+
const url = `http://${host}:${service.port}`;
|
|
246
|
+
const owner = service.txt?.owner ?? service.name;
|
|
247
|
+
onFound({
|
|
248
|
+
name: service.name,
|
|
249
|
+
url,
|
|
250
|
+
owner
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
if (onDown) {
|
|
254
|
+
browser.on("down", (service) => {
|
|
255
|
+
const addresses = service.addresses ?? [];
|
|
256
|
+
const ipv4Addresses = addresses.filter((addr) => !addr.includes(":"));
|
|
257
|
+
const host = ipv4Addresses.length > 0 ? ipv4Addresses[0] : service.host;
|
|
258
|
+
const url = `http://${host}:${service.port}`;
|
|
259
|
+
const owner = service.txt?.owner ?? service.name;
|
|
260
|
+
onDown({
|
|
261
|
+
name: service.name,
|
|
262
|
+
url,
|
|
263
|
+
owner
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
stop: () => browser.stop()
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async function stopAnnouncement() {
|
|
272
|
+
if (bonjourInstance === null) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const instance = bonjourInstance;
|
|
276
|
+
bonjourInstance = null;
|
|
277
|
+
await new Promise((resolve) => {
|
|
278
|
+
instance.unpublishAll(() => {
|
|
279
|
+
instance.destroy();
|
|
280
|
+
resolve();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export {
|
|
286
|
+
KNOWN_API_KEYS,
|
|
287
|
+
detectApiKeys,
|
|
288
|
+
detectOpenPorts,
|
|
289
|
+
buildDraftCard,
|
|
290
|
+
getPricingStats,
|
|
291
|
+
announceGateway,
|
|
292
|
+
discoverLocalAgents,
|
|
293
|
+
stopAnnouncement
|
|
294
|
+
};
|
|
@@ -3,11 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-3MJT4PZG.js";
|
|
4
4
|
import {
|
|
5
5
|
scorePeers
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BTTL24TZ.js";
|
|
7
|
+
import {
|
|
8
|
+
fetchRemoteCards
|
|
9
|
+
} from "./chunk-ZX5623ER.js";
|
|
7
10
|
import {
|
|
8
|
-
fetchRemoteCards,
|
|
9
11
|
searchCards
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-NH2FIERR.js";
|
|
11
13
|
import {
|
|
12
14
|
requestCapability
|
|
13
15
|
} from "./chunk-XND2DWTZ.js";
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getFeedbackForProvider
|
|
3
|
+
} from "./chunk-EANI2N2V.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
|
+
function searchCards(db, query, filters = {}) {
|
|
53
|
+
const words = query.trim().split(/\s+/).map((w) => w.replace(/["*^{}():]/g, "")).filter((w) => w.length > 0);
|
|
54
|
+
if (words.length === 0) return [];
|
|
55
|
+
const ftsQuery = words.map((w) => `"${w}"`).join(" OR ");
|
|
56
|
+
const conditions = [];
|
|
57
|
+
const params = [ftsQuery];
|
|
58
|
+
if (filters.level !== void 0) {
|
|
59
|
+
conditions.push(`json_extract(cc.data, '$.level') = ?`);
|
|
60
|
+
params.push(filters.level);
|
|
61
|
+
}
|
|
62
|
+
if (filters.online !== void 0) {
|
|
63
|
+
conditions.push(`json_extract(cc.data, '$.availability.online') = ?`);
|
|
64
|
+
params.push(filters.online ? 1 : 0);
|
|
65
|
+
}
|
|
66
|
+
const whereClause = conditions.length > 0 ? `AND ${conditions.join(" AND ")}` : "";
|
|
67
|
+
const sql = `
|
|
68
|
+
SELECT cc.data
|
|
69
|
+
FROM capability_cards cc
|
|
70
|
+
JOIN cards_fts ON cc.rowid = cards_fts.rowid
|
|
71
|
+
WHERE cards_fts MATCH ?
|
|
72
|
+
${whereClause}
|
|
73
|
+
ORDER BY bm25(cards_fts)
|
|
74
|
+
LIMIT 50
|
|
75
|
+
`;
|
|
76
|
+
const stmt = db.prepare(sql);
|
|
77
|
+
const rows = stmt.all(...params);
|
|
78
|
+
const results = rows.map((row) => JSON.parse(row.data));
|
|
79
|
+
let filtered = results;
|
|
80
|
+
if (filters.apis_used && filters.apis_used.length > 0) {
|
|
81
|
+
const requiredApis = filters.apis_used;
|
|
82
|
+
filtered = filtered.filter((card) => {
|
|
83
|
+
const cardApis = card.metadata?.apis_used ?? [];
|
|
84
|
+
return requiredApis.every((api) => cardApis.includes(api));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (filters.min_reputation !== void 0 && filters.min_reputation > 0) {
|
|
88
|
+
filtered = applyReputationFilter(db, filtered, filters.min_reputation);
|
|
89
|
+
}
|
|
90
|
+
return filtered;
|
|
91
|
+
}
|
|
92
|
+
function filterCards(db, filters) {
|
|
93
|
+
const conditions = [];
|
|
94
|
+
const params = [];
|
|
95
|
+
if (filters.level !== void 0) {
|
|
96
|
+
conditions.push(`json_extract(data, '$.level') = ?`);
|
|
97
|
+
params.push(filters.level);
|
|
98
|
+
}
|
|
99
|
+
if (filters.online !== void 0) {
|
|
100
|
+
conditions.push(`json_extract(data, '$.availability.online') = ?`);
|
|
101
|
+
params.push(filters.online ? 1 : 0);
|
|
102
|
+
}
|
|
103
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
104
|
+
const sql = `SELECT data FROM capability_cards ${whereClause}`;
|
|
105
|
+
const stmt = db.prepare(sql);
|
|
106
|
+
const rows = stmt.all(...params);
|
|
107
|
+
let cards = rows.map((row) => JSON.parse(row.data));
|
|
108
|
+
if (filters.min_reputation !== void 0 && filters.min_reputation > 0) {
|
|
109
|
+
cards = applyReputationFilter(db, cards, filters.min_reputation);
|
|
110
|
+
}
|
|
111
|
+
return cards;
|
|
112
|
+
}
|
|
113
|
+
function applyReputationFilter(db, cards, minReputation) {
|
|
114
|
+
const owners = [...new Set(cards.map((c) => c.owner))];
|
|
115
|
+
const reputationMap = /* @__PURE__ */ new Map();
|
|
116
|
+
for (const owner of owners) {
|
|
117
|
+
reputationMap.set(owner, getReputationScore(db, owner));
|
|
118
|
+
}
|
|
119
|
+
return cards.filter((card) => {
|
|
120
|
+
const score = reputationMap.get(card.owner) ?? 0.5;
|
|
121
|
+
return score >= minReputation;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function buildReputationMap(db, owners) {
|
|
125
|
+
const unique = [...new Set(owners)];
|
|
126
|
+
const map = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const owner of unique) {
|
|
128
|
+
map.set(owner, getReputationScore(db, owner));
|
|
129
|
+
}
|
|
130
|
+
return map;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export {
|
|
134
|
+
computeReputation,
|
|
135
|
+
searchCards,
|
|
136
|
+
filterCards,
|
|
137
|
+
buildReputationMap
|
|
138
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
confirmEscrowDebit,
|
|
3
|
+
recordEarning,
|
|
4
|
+
releaseEscrow
|
|
5
|
+
} from "./chunk-EANI2N2V.js";
|
|
6
|
+
|
|
7
|
+
// src/credit/settlement.ts
|
|
8
|
+
function settleProviderEarning(providerDb, providerOwner, receipt) {
|
|
9
|
+
recordEarning(
|
|
10
|
+
providerDb,
|
|
11
|
+
providerOwner,
|
|
12
|
+
receipt.amount,
|
|
13
|
+
receipt.card_id,
|
|
14
|
+
receipt.nonce
|
|
15
|
+
);
|
|
16
|
+
return { settled: true };
|
|
17
|
+
}
|
|
18
|
+
function settleRequesterEscrow(requesterDb, escrowId) {
|
|
19
|
+
confirmEscrowDebit(requesterDb, escrowId);
|
|
20
|
+
}
|
|
21
|
+
function releaseRequesterEscrow(requesterDb, escrowId) {
|
|
22
|
+
releaseEscrow(requesterDb, escrowId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
settleProviderEarning,
|
|
27
|
+
settleRequesterEscrow,
|
|
28
|
+
releaseRequesterEscrow
|
|
29
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RelayClient
|
|
3
|
+
} from "./chunk-JOY533UH.js";
|
|
1
4
|
import {
|
|
2
5
|
BudgetController,
|
|
3
6
|
ORCHESTRATION_FEE,
|
|
4
7
|
decompose,
|
|
5
8
|
matchSubTasks,
|
|
6
9
|
orchestrate
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-MNO4COST.js";
|
|
8
11
|
import {
|
|
9
12
|
BudgetManager
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-BTTL24TZ.js";
|
|
11
14
|
import {
|
|
12
15
|
loadPeers
|
|
13
16
|
} from "./chunk-5AH3CMOX.js";
|
|
@@ -16,13 +19,10 @@ import {
|
|
|
16
19
|
} from "./chunk-75OC6E4F.js";
|
|
17
20
|
import {
|
|
18
21
|
openDatabase
|
|
19
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-DFBX3BBD.js";
|
|
20
23
|
import {
|
|
21
24
|
openCreditDb
|
|
22
|
-
} from "./chunk-
|
|
23
|
-
import {
|
|
24
|
-
RelayClient
|
|
25
|
-
} from "./chunk-JOY533UH.js";
|
|
25
|
+
} from "./chunk-EANI2N2V.js";
|
|
26
26
|
|
|
27
27
|
// src/cli/conduct.ts
|
|
28
28
|
async function conductAction(task, opts) {
|
|
@@ -103,7 +103,7 @@ async function conductAction(task, opts) {
|
|
|
103
103
|
return { url: `relay://${owner}`, cardId };
|
|
104
104
|
}
|
|
105
105
|
throw new Error(
|
|
106
|
-
`Unknown peer "${owner}". Add with: agentbnb
|
|
106
|
+
`Unknown peer "${owner}". Add with: agentbnb connect ${owner} <url> <token>`
|
|
107
107
|
);
|
|
108
108
|
};
|
|
109
109
|
let relay;
|