web-agent-bridge 1.1.2 → 2.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/LICENSE +21 -21
- package/README.ar.md +446 -446
- package/README.md +780 -844
- package/bin/cli.js +80 -80
- package/bin/wab.js +80 -80
- package/examples/bidi-agent.js +119 -119
- package/examples/mcp-agent.js +94 -94
- package/examples/next-app-router/README.md +44 -0
- package/examples/puppeteer-agent.js +108 -108
- package/examples/saas-dashboard/README.md +55 -0
- package/examples/shopify-hydrogen/README.md +74 -0
- package/examples/vision-agent.js +171 -171
- package/examples/wordpress-elementor/README.md +77 -0
- package/package.json +69 -78
- package/public/.well-known/ai-assets.json +59 -0
- package/public/admin/login.html +84 -84
- package/public/ai.html +196 -0
- package/public/cookies.html +208 -208
- package/public/css/premium.css +317 -0
- package/public/css/styles.css +1235 -1235
- package/public/dashboard.html +704 -704
- package/public/demo.html +259 -0
- package/public/docs.html +585 -585
- package/public/feed.xml +89 -0
- package/public/index.html +495 -332
- package/public/js/auth-nav.js +31 -31
- package/public/js/auth-redirect.js +12 -12
- package/public/js/cookie-consent.js +56 -56
- package/public/js/wab-demo-page.js +721 -0
- package/public/js/ws-client.js +74 -74
- package/public/llms-full.txt +309 -0
- package/public/llms.txt +85 -0
- package/public/login.html +83 -83
- package/public/openapi.json +580 -0
- package/public/premium-dashboard.html +2487 -0
- package/public/premium.html +791 -0
- package/public/privacy.html +295 -295
- package/public/register.html +103 -103
- package/public/robots.txt +87 -0
- package/public/script/wab-consent.d.ts +36 -0
- package/public/script/wab-consent.js +104 -0
- package/public/script/wab-schema.js +131 -0
- package/public/script/wab.d.ts +108 -0
- package/public/script/wab.min.js +234 -0
- package/public/sitemap.xml +93 -0
- package/public/terms.html +254 -254
- package/public/video/tutorial.mp4 +0 -0
- package/script/ai-agent-bridge.js +1558 -1513
- package/sdk/README.md +55 -55
- package/sdk/index.d.ts +118 -0
- package/sdk/index.js +257 -203
- package/sdk/package.json +14 -14
- package/sdk/schema-discovery.js +83 -0
- package/server/config/secrets.js +94 -92
- package/server/index.js +0 -9
- package/server/middleware/adminAuth.js +30 -30
- package/server/middleware/auth.js +41 -41
- package/server/middleware/rateLimits.js +24 -24
- package/server/migrations/001_add_analytics_indexes.sql +7 -7
- package/server/migrations/002_premium_features.sql +418 -0
- package/server/models/adapters/index.js +33 -33
- package/server/models/adapters/mysql.js +183 -183
- package/server/models/adapters/postgresql.js +172 -172
- package/server/models/adapters/sqlite.js +7 -7
- package/server/models/db.js +561 -561
- package/server/routes/admin-premium.js +671 -0
- package/server/routes/admin.js +247 -247
- package/server/routes/api.js +131 -138
- package/server/routes/auth.js +51 -51
- package/server/routes/billing.js +45 -45
- package/server/routes/discovery.js +406 -329
- package/server/routes/license.js +240 -240
- package/server/routes/noscript.js +543 -543
- package/server/routes/premium-v2.js +686 -0
- package/server/routes/premium.js +724 -0
- package/server/routes/wab-api.js +476 -476
- package/server/services/agent-memory.js +625 -0
- package/server/services/email.js +204 -204
- package/server/services/fairness.js +420 -420
- package/server/services/plugins.js +747 -0
- package/server/services/premium.js +1883 -0
- package/server/services/self-healing.js +843 -0
- package/server/services/stripe.js +192 -192
- package/server/services/swarm.js +788 -0
- package/server/services/vision.js +871 -0
- package/server/utils/cache.js +125 -125
- package/server/utils/migrate.js +81 -81
- package/server/utils/secureFields.js +50 -50
- package/server/ws.js +101 -101
- package/docs/DEPLOY.md +0 -118
- package/docs/SPEC.md +0 -1540
- package/wab-mcp-adapter/README.md +0 -136
- package/wab-mcp-adapter/index.js +0 -555
- package/wab-mcp-adapter/package.json +0 -17
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const { URL } = require('url');
|
|
5
|
+
const { db } = require('../models/db');
|
|
6
|
+
|
|
7
|
+
// ─── Schema ──────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
db.exec(`
|
|
10
|
+
CREATE TABLE IF NOT EXISTS swarm_configs (
|
|
11
|
+
id TEXT PRIMARY KEY,
|
|
12
|
+
site_id TEXT UNIQUE,
|
|
13
|
+
name TEXT,
|
|
14
|
+
strategy TEXT DEFAULT 'parallel',
|
|
15
|
+
max_agents INTEGER DEFAULT 3,
|
|
16
|
+
timeout_ms INTEGER DEFAULT 30000,
|
|
17
|
+
merge_strategy TEXT DEFAULT 'best_score',
|
|
18
|
+
enabled INTEGER DEFAULT 1,
|
|
19
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
20
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
CREATE TABLE IF NOT EXISTS swarm_tasks (
|
|
24
|
+
id TEXT PRIMARY KEY,
|
|
25
|
+
site_id TEXT,
|
|
26
|
+
config_id TEXT,
|
|
27
|
+
task_type TEXT,
|
|
28
|
+
objective TEXT,
|
|
29
|
+
parameters TEXT DEFAULT '{}',
|
|
30
|
+
status TEXT DEFAULT 'pending',
|
|
31
|
+
created_by TEXT,
|
|
32
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
33
|
+
started_at TEXT,
|
|
34
|
+
completed_at TEXT
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
CREATE TABLE IF NOT EXISTS swarm_agents (
|
|
38
|
+
id TEXT PRIMARY KEY,
|
|
39
|
+
task_id TEXT,
|
|
40
|
+
agent_role TEXT,
|
|
41
|
+
agent_type TEXT,
|
|
42
|
+
target TEXT,
|
|
43
|
+
status TEXT DEFAULT 'idle',
|
|
44
|
+
result TEXT DEFAULT '{}',
|
|
45
|
+
score REAL,
|
|
46
|
+
error TEXT,
|
|
47
|
+
started_at TEXT,
|
|
48
|
+
completed_at TEXT
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
CREATE TABLE IF NOT EXISTS swarm_results (
|
|
52
|
+
id TEXT PRIMARY KEY,
|
|
53
|
+
task_id TEXT,
|
|
54
|
+
merged_result TEXT DEFAULT '{}',
|
|
55
|
+
fairness_applied INTEGER DEFAULT 0,
|
|
56
|
+
total_sources INTEGER DEFAULT 0,
|
|
57
|
+
best_source TEXT,
|
|
58
|
+
comparison TEXT DEFAULT '{}',
|
|
59
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_configs_site ON swarm_configs(site_id);
|
|
63
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_tasks_site ON swarm_tasks(site_id);
|
|
64
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_tasks_status ON swarm_tasks(status);
|
|
65
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_tasks_config ON swarm_tasks(config_id);
|
|
66
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_agents_task ON swarm_agents(task_id);
|
|
67
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_agents_status ON swarm_agents(status);
|
|
68
|
+
CREATE INDEX IF NOT EXISTS idx_swarm_results_task ON swarm_results(task_id);
|
|
69
|
+
`);
|
|
70
|
+
|
|
71
|
+
// ─── Prepared Statements ─────────────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
const stmts = {
|
|
74
|
+
upsertConfig: db.prepare(`
|
|
75
|
+
INSERT INTO swarm_configs (id, site_id, name, strategy, max_agents, timeout_ms, merge_strategy, enabled)
|
|
76
|
+
VALUES (@id, @site_id, @name, @strategy, @max_agents, @timeout_ms, @merge_strategy, @enabled)
|
|
77
|
+
ON CONFLICT(site_id) DO UPDATE SET
|
|
78
|
+
name = excluded.name,
|
|
79
|
+
strategy = excluded.strategy,
|
|
80
|
+
max_agents = excluded.max_agents,
|
|
81
|
+
timeout_ms = excluded.timeout_ms,
|
|
82
|
+
merge_strategy = excluded.merge_strategy,
|
|
83
|
+
enabled = excluded.enabled,
|
|
84
|
+
updated_at = datetime('now')
|
|
85
|
+
`),
|
|
86
|
+
getConfig: db.prepare('SELECT * FROM swarm_configs WHERE site_id = ?'),
|
|
87
|
+
getConfigById: db.prepare('SELECT * FROM swarm_configs WHERE id = ?'),
|
|
88
|
+
insertTask: db.prepare(`
|
|
89
|
+
INSERT INTO swarm_tasks (id, site_id, config_id, task_type, objective, parameters, status, created_by)
|
|
90
|
+
VALUES (@id, @site_id, @config_id, @task_type, @objective, @parameters, @status, @created_by)
|
|
91
|
+
`),
|
|
92
|
+
getTask: db.prepare('SELECT * FROM swarm_tasks WHERE id = ?'),
|
|
93
|
+
updateTaskStatus: db.prepare('UPDATE swarm_tasks SET status = ?, started_at = COALESCE(started_at, ?), completed_at = ? WHERE id = ?'),
|
|
94
|
+
insertAgent: db.prepare(`
|
|
95
|
+
INSERT INTO swarm_agents (id, task_id, agent_role, agent_type, target, status)
|
|
96
|
+
VALUES (@id, @task_id, @agent_role, @agent_type, @target, @status)
|
|
97
|
+
`),
|
|
98
|
+
getAgentsByTask: db.prepare('SELECT * FROM swarm_agents WHERE task_id = ? ORDER BY started_at ASC'),
|
|
99
|
+
updateAgent: db.prepare(`
|
|
100
|
+
UPDATE swarm_agents SET status = ?, result = ?, score = ?, error = ?, started_at = COALESCE(started_at, ?), completed_at = ?
|
|
101
|
+
WHERE id = ?
|
|
102
|
+
`),
|
|
103
|
+
insertResult: db.prepare(`
|
|
104
|
+
INSERT INTO swarm_results (id, task_id, merged_result, fairness_applied, total_sources, best_source, comparison)
|
|
105
|
+
VALUES (@id, @task_id, @merged_result, @fairness_applied, @total_sources, @best_source, @comparison)
|
|
106
|
+
`),
|
|
107
|
+
getResult: db.prepare('SELECT * FROM swarm_results WHERE task_id = ?'),
|
|
108
|
+
cancelPendingAgents: db.prepare("UPDATE swarm_agents SET status = 'cancelled' WHERE task_id = ? AND status IN ('idle', 'running')"),
|
|
109
|
+
taskHistory: db.prepare('SELECT * FROM swarm_tasks WHERE site_id = ? ORDER BY created_at DESC LIMIT ?'),
|
|
110
|
+
taskHistoryByType: db.prepare('SELECT * FROM swarm_tasks WHERE site_id = ? AND task_type = ? ORDER BY created_at DESC LIMIT ?'),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// ─── 1. configureSwarm ───────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
function configureSwarm(siteId, { name, strategy, maxAgents, timeoutMs, mergeStrategy } = {}) {
|
|
116
|
+
const existing = stmts.getConfig.get(siteId);
|
|
117
|
+
const id = existing ? existing.id : crypto.randomUUID();
|
|
118
|
+
|
|
119
|
+
const params = {
|
|
120
|
+
id,
|
|
121
|
+
site_id: siteId,
|
|
122
|
+
name: name ?? (existing ? existing.name : siteId),
|
|
123
|
+
strategy: strategy ?? (existing ? existing.strategy : 'parallel'),
|
|
124
|
+
max_agents: maxAgents ?? (existing ? existing.max_agents : 3),
|
|
125
|
+
timeout_ms: timeoutMs ?? (existing ? existing.timeout_ms : 30000),
|
|
126
|
+
merge_strategy: mergeStrategy ?? (existing ? existing.merge_strategy : 'best_score'),
|
|
127
|
+
enabled: 1,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
stmts.upsertConfig.run(params);
|
|
131
|
+
return stmts.getConfig.get(siteId);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ─── 2. getSwarmConfig ───────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
function getSwarmConfig(siteId) {
|
|
137
|
+
return stmts.getConfig.get(siteId) || null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ─── 3. createTask ───────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
function createTask(siteId, { taskType, objective, parameters, createdBy } = {}) {
|
|
143
|
+
const config = stmts.getConfig.get(siteId);
|
|
144
|
+
const id = crypto.randomUUID();
|
|
145
|
+
|
|
146
|
+
stmts.insertTask.run({
|
|
147
|
+
id,
|
|
148
|
+
site_id: siteId,
|
|
149
|
+
config_id: config ? config.id : null,
|
|
150
|
+
task_type: taskType || 'general',
|
|
151
|
+
objective: objective || '',
|
|
152
|
+
parameters: JSON.stringify(parameters || {}),
|
|
153
|
+
status: 'pending',
|
|
154
|
+
created_by: createdBy || null,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return stmts.getTask.get(id);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ─── 4. assignAgents ─────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
function assignAgents(taskId, agentDefinitions) {
|
|
163
|
+
const task = stmts.getTask.get(taskId);
|
|
164
|
+
if (!task) throw new Error(`Task ${taskId} not found`);
|
|
165
|
+
|
|
166
|
+
const config = task.config_id ? stmts.getConfigById.get(task.config_id) : null;
|
|
167
|
+
const maxAgents = config ? config.max_agents : 10;
|
|
168
|
+
const defs = agentDefinitions.slice(0, maxAgents);
|
|
169
|
+
|
|
170
|
+
const agents = [];
|
|
171
|
+
const insertMany = db.transaction((items) => {
|
|
172
|
+
for (const def of items) {
|
|
173
|
+
const agentId = crypto.randomUUID();
|
|
174
|
+
stmts.insertAgent.run({
|
|
175
|
+
id: agentId,
|
|
176
|
+
task_id: taskId,
|
|
177
|
+
agent_role: def.role || 'worker',
|
|
178
|
+
agent_type: def.type || 'fetch',
|
|
179
|
+
target: def.target || '',
|
|
180
|
+
status: 'idle',
|
|
181
|
+
});
|
|
182
|
+
agents.push({ id: agentId, task_id: taskId, agent_role: def.role, agent_type: def.type, target: def.target, status: 'idle' });
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
insertMany(defs);
|
|
187
|
+
return agents;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ─── 5. runSwarmTask ─────────────────────────────────────────────────
|
|
191
|
+
|
|
192
|
+
async function runSwarmTask(taskId) {
|
|
193
|
+
const task = stmts.getTask.get(taskId);
|
|
194
|
+
if (!task) throw new Error(`Task ${taskId} not found`);
|
|
195
|
+
if (task.status === 'cancelled') throw new Error(`Task ${taskId} is cancelled`);
|
|
196
|
+
|
|
197
|
+
const config = task.config_id ? stmts.getConfigById.get(task.config_id) : null;
|
|
198
|
+
const strategy = config ? config.strategy : 'parallel';
|
|
199
|
+
const mergeStrategy = config ? config.merge_strategy : 'best_score';
|
|
200
|
+
const timeoutMs = config ? config.timeout_ms : 30000;
|
|
201
|
+
|
|
202
|
+
const now = new Date().toISOString();
|
|
203
|
+
stmts.updateTaskStatus.run('running', now, null, taskId);
|
|
204
|
+
|
|
205
|
+
let agents = stmts.getAgentsByTask.all(taskId);
|
|
206
|
+
if (agents.length === 0) throw new Error(`No agents assigned to task ${taskId}`);
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
switch (strategy) {
|
|
210
|
+
case 'sequential':
|
|
211
|
+
await runSequential(agents, timeoutMs);
|
|
212
|
+
break;
|
|
213
|
+
case 'competitive':
|
|
214
|
+
await runCompetitive(agents, timeoutMs);
|
|
215
|
+
break;
|
|
216
|
+
case 'collaborative':
|
|
217
|
+
await runCollaborative(agents, timeoutMs);
|
|
218
|
+
break;
|
|
219
|
+
case 'parallel':
|
|
220
|
+
default:
|
|
221
|
+
await runParallel(agents, timeoutMs);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
agents = stmts.getAgentsByTask.all(taskId);
|
|
226
|
+
const completedAgents = agents.filter(a => a.status === 'completed');
|
|
227
|
+
|
|
228
|
+
const rawResults = completedAgents.map(a => {
|
|
229
|
+
let parsed = {};
|
|
230
|
+
try { parsed = JSON.parse(a.result || '{}'); } catch (_) {}
|
|
231
|
+
return { ...parsed, _agentId: a.id, _role: a.agent_role, _score: a.score, _source: a.target };
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const fairResults = applyFairnessToResults(rawResults);
|
|
235
|
+
const merged = mergeResults(fairResults, mergeStrategy);
|
|
236
|
+
|
|
237
|
+
const bestAgent = completedAgents.reduce((best, cur) =>
|
|
238
|
+
(cur.score || 0) > (best.score || 0) ? cur : best, completedAgents[0]);
|
|
239
|
+
|
|
240
|
+
const comparison = completedAgents.map(a => ({
|
|
241
|
+
agentId: a.id,
|
|
242
|
+
role: a.agent_role,
|
|
243
|
+
target: a.target,
|
|
244
|
+
score: a.score,
|
|
245
|
+
status: a.status,
|
|
246
|
+
}));
|
|
247
|
+
|
|
248
|
+
const resultId = crypto.randomUUID();
|
|
249
|
+
stmts.insertResult.run({
|
|
250
|
+
id: resultId,
|
|
251
|
+
task_id: taskId,
|
|
252
|
+
merged_result: JSON.stringify(merged),
|
|
253
|
+
fairness_applied: 1,
|
|
254
|
+
total_sources: completedAgents.length,
|
|
255
|
+
best_source: bestAgent ? bestAgent.target : null,
|
|
256
|
+
comparison: JSON.stringify(comparison),
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const doneAt = new Date().toISOString();
|
|
260
|
+
stmts.updateTaskStatus.run('completed', now, doneAt, taskId);
|
|
261
|
+
|
|
262
|
+
return { taskId, status: 'completed', result: merged, sources: completedAgents.length, bestSource: bestAgent ? bestAgent.target : null };
|
|
263
|
+
} catch (err) {
|
|
264
|
+
const failAt = new Date().toISOString();
|
|
265
|
+
stmts.updateTaskStatus.run('failed', now, failAt, taskId);
|
|
266
|
+
throw err;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ─── Strategy Runners ────────────────────────────────────────────────
|
|
271
|
+
|
|
272
|
+
async function runParallel(agents, timeoutMs) {
|
|
273
|
+
const promises = agents.map(agent => runSingleAgent(agent, timeoutMs));
|
|
274
|
+
await Promise.allSettled(promises);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async function runSequential(agents, timeoutMs) {
|
|
278
|
+
let previousResult = null;
|
|
279
|
+
for (const agent of agents) {
|
|
280
|
+
previousResult = await runSingleAgent(agent, timeoutMs, previousResult);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function runCompetitive(agents, timeoutMs) {
|
|
285
|
+
const promises = agents.map(agent => runSingleAgent(agent, timeoutMs));
|
|
286
|
+
await Promise.allSettled(promises);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function runCollaborative(agents, timeoutMs) {
|
|
290
|
+
const promises = agents.map(agent => runSingleAgent(agent, timeoutMs));
|
|
291
|
+
await Promise.allSettled(promises);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function runSingleAgent(agent, timeoutMs, previousResult) {
|
|
295
|
+
const startedAt = new Date().toISOString();
|
|
296
|
+
stmts.updateAgent.run('running', agent.result || '{}', null, null, startedAt, null, agent.id);
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
const agentInput = { ...agent, timeoutMs, previousResult };
|
|
300
|
+
const result = await executeAgent(agentInput);
|
|
301
|
+
const completedAt = new Date().toISOString();
|
|
302
|
+
stmts.updateAgent.run('completed', JSON.stringify(result), result.relevance || 0, null, startedAt, completedAt, agent.id);
|
|
303
|
+
return result;
|
|
304
|
+
} catch (err) {
|
|
305
|
+
const completedAt = new Date().toISOString();
|
|
306
|
+
stmts.updateAgent.run('failed', '{}', 0, err.message, startedAt, completedAt, agent.id);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ─── 6. executeAgent ─────────────────────────────────────────────────
|
|
312
|
+
|
|
313
|
+
function executeAgent(agent) {
|
|
314
|
+
const timeout = agent.timeoutMs || 30000;
|
|
315
|
+
const targetUrl = agent.target;
|
|
316
|
+
|
|
317
|
+
if (!targetUrl) {
|
|
318
|
+
return Promise.resolve({ title: '', description: '', prices: [], relevance: 0, source: '' });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
let parsed;
|
|
323
|
+
try {
|
|
324
|
+
parsed = new URL(targetUrl);
|
|
325
|
+
} catch (_) {
|
|
326
|
+
return resolve({ title: '', description: '', prices: [], relevance: 0, source: targetUrl, error: 'Invalid URL' });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const transport = parsed.protocol === 'https:' ? https : http;
|
|
330
|
+
const timer = setTimeout(() => {
|
|
331
|
+
req.destroy();
|
|
332
|
+
resolve({ title: '', description: '', prices: [], relevance: 0, source: targetUrl, error: 'Timeout' });
|
|
333
|
+
}, timeout);
|
|
334
|
+
|
|
335
|
+
const req = transport.get(targetUrl, { headers: { 'User-Agent': 'WAB-Swarm-Agent/1.0' } }, (res) => {
|
|
336
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
337
|
+
clearTimeout(timer);
|
|
338
|
+
const redirectAgent = { ...agent, target: res.headers.location };
|
|
339
|
+
resolve(executeAgent(redirectAgent));
|
|
340
|
+
res.resume();
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let body = '';
|
|
345
|
+
const maxBytes = 2 * 1024 * 1024;
|
|
346
|
+
let received = 0;
|
|
347
|
+
|
|
348
|
+
res.on('data', (chunk) => {
|
|
349
|
+
received += chunk.length;
|
|
350
|
+
if (received <= maxBytes) body += chunk;
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
res.on('end', () => {
|
|
354
|
+
clearTimeout(timer);
|
|
355
|
+
|
|
356
|
+
const title = extractFirst(body, /<title[^>]*>([\s\S]*?)<\/title>/i) || '';
|
|
357
|
+
const metaDesc = extractFirst(body, /<meta\s+name=["']description["']\s+content=["']([\s\S]*?)["']/i)
|
|
358
|
+
|| extractFirst(body, /<meta\s+content=["']([\s\S]*?)["']\s+name=["']description["']/i)
|
|
359
|
+
|| '';
|
|
360
|
+
const h1 = extractFirst(body, /<h1[^>]*>([\s\S]*?)<\/h1>/i) || '';
|
|
361
|
+
const priceMatches = body.match(/(?:\$|USD\s?)(\d{1,7}(?:[.,]\d{2})?)/g) || [];
|
|
362
|
+
const prices = [...new Set(priceMatches.slice(0, 20))];
|
|
363
|
+
|
|
364
|
+
const objective = agent.previousResult?.objective || '';
|
|
365
|
+
const relevance = computeRelevanceScore(title, metaDesc, h1, prices, objective, targetUrl);
|
|
366
|
+
|
|
367
|
+
resolve({
|
|
368
|
+
title: cleanHtml(title).slice(0, 500),
|
|
369
|
+
description: cleanHtml(metaDesc).slice(0, 1000),
|
|
370
|
+
h1: cleanHtml(h1).slice(0, 500),
|
|
371
|
+
prices,
|
|
372
|
+
relevance,
|
|
373
|
+
source: targetUrl,
|
|
374
|
+
statusCode: res.statusCode,
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
res.on('error', (err) => {
|
|
379
|
+
clearTimeout(timer);
|
|
380
|
+
resolve({ title: '', description: '', prices: [], relevance: 0, source: targetUrl, error: err.message });
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
req.on('error', (err) => {
|
|
385
|
+
clearTimeout(timer);
|
|
386
|
+
resolve({ title: '', description: '', prices: [], relevance: 0, source: targetUrl, error: err.message });
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function extractFirst(html, regex) {
|
|
392
|
+
const m = html.match(regex);
|
|
393
|
+
return m ? m[1].trim() : null;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function cleanHtml(text) {
|
|
397
|
+
return text.replace(/<[^>]+>/g, '').replace(/&/g, '&').replace(/</g, '<')
|
|
398
|
+
.replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'")
|
|
399
|
+
.replace(/ /g, ' ').replace(/\s+/g, ' ').trim();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function computeRelevanceScore(title, description, h1, prices, objective, source) {
|
|
403
|
+
let score = 0;
|
|
404
|
+
|
|
405
|
+
if (title) score += 15;
|
|
406
|
+
if (description) score += 15;
|
|
407
|
+
if (h1) score += 10;
|
|
408
|
+
if (prices.length > 0) score += 10;
|
|
409
|
+
|
|
410
|
+
if (objective) {
|
|
411
|
+
const terms = objective.toLowerCase().split(/\s+/).filter(Boolean);
|
|
412
|
+
const corpus = `${title} ${description} ${h1}`.toLowerCase();
|
|
413
|
+
let hits = 0;
|
|
414
|
+
for (const t of terms) {
|
|
415
|
+
if (corpus.includes(t)) hits++;
|
|
416
|
+
}
|
|
417
|
+
const termRatio = terms.length > 0 ? hits / terms.length : 0;
|
|
418
|
+
score += Math.round(termRatio * 40);
|
|
419
|
+
} else {
|
|
420
|
+
score += 20;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (source) {
|
|
424
|
+
try {
|
|
425
|
+
const u = new URL(source);
|
|
426
|
+
if (u.protocol === 'https:') score += 5;
|
|
427
|
+
if (u.pathname !== '/' && u.pathname.length > 1) score += 5;
|
|
428
|
+
} catch (_) {}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return Math.min(Math.max(Math.round(score * 100) / 100, 0), 100);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// ─── 7. mergeResults ─────────────────────────────────────────────────
|
|
435
|
+
|
|
436
|
+
function mergeResults(agents, strategy) {
|
|
437
|
+
if (!agents || agents.length === 0) return { merged: true, data: [], strategy };
|
|
438
|
+
|
|
439
|
+
switch (strategy) {
|
|
440
|
+
case 'best_score': return mergeBestScore(agents);
|
|
441
|
+
case 'weighted_average': return mergeWeightedAverage(agents);
|
|
442
|
+
case 'union': return mergeUnion(agents);
|
|
443
|
+
case 'consensus': return mergeConsensus(agents);
|
|
444
|
+
default: return mergeBestScore(agents);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function mergeBestScore(agents) {
|
|
449
|
+
const sorted = [...agents].sort((a, b) => (b._score || b.relevance || 0) - (a._score || a.relevance || 0));
|
|
450
|
+
const best = sorted[0];
|
|
451
|
+
return {
|
|
452
|
+
merged: true,
|
|
453
|
+
strategy: 'best_score',
|
|
454
|
+
title: best.title || '',
|
|
455
|
+
description: best.description || '',
|
|
456
|
+
h1: best.h1 || '',
|
|
457
|
+
prices: best.prices || [],
|
|
458
|
+
relevance: best._score || best.relevance || 0,
|
|
459
|
+
source: best._source || best.source || '',
|
|
460
|
+
allSources: sorted.map(a => ({ source: a._source || a.source, score: a._score || a.relevance || 0 })),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function mergeWeightedAverage(agents) {
|
|
465
|
+
const totalWeight = agents.reduce((s, a) => s + (a._score || a.relevance || 0), 0);
|
|
466
|
+
if (totalWeight === 0) return mergeBestScore(agents);
|
|
467
|
+
|
|
468
|
+
const allPrices = [];
|
|
469
|
+
let weightedRelevance = 0;
|
|
470
|
+
let bestTitle = '';
|
|
471
|
+
let bestDesc = '';
|
|
472
|
+
let bestH1 = '';
|
|
473
|
+
let highestWeight = -1;
|
|
474
|
+
|
|
475
|
+
for (const a of agents) {
|
|
476
|
+
const w = a._score || a.relevance || 0;
|
|
477
|
+
weightedRelevance += w * w;
|
|
478
|
+
if (a.prices) allPrices.push(...a.prices);
|
|
479
|
+
if (w > highestWeight) {
|
|
480
|
+
highestWeight = w;
|
|
481
|
+
bestTitle = a.title || bestTitle;
|
|
482
|
+
bestDesc = a.description || bestDesc;
|
|
483
|
+
bestH1 = a.h1 || bestH1;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return {
|
|
488
|
+
merged: true,
|
|
489
|
+
strategy: 'weighted_average',
|
|
490
|
+
title: bestTitle,
|
|
491
|
+
description: bestDesc,
|
|
492
|
+
h1: bestH1,
|
|
493
|
+
prices: [...new Set(allPrices)],
|
|
494
|
+
relevance: Math.round((weightedRelevance / totalWeight) * 100) / 100,
|
|
495
|
+
sourceCount: agents.length,
|
|
496
|
+
allSources: agents.map(a => ({ source: a._source || a.source, score: a._score || a.relevance || 0 })),
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function mergeUnion(agents) {
|
|
501
|
+
const allPrices = [];
|
|
502
|
+
const allTitles = [];
|
|
503
|
+
const allDescriptions = [];
|
|
504
|
+
let maxRelevance = 0;
|
|
505
|
+
|
|
506
|
+
for (const a of agents) {
|
|
507
|
+
if (a.title) allTitles.push(a.title);
|
|
508
|
+
if (a.description) allDescriptions.push(a.description);
|
|
509
|
+
if (a.prices) allPrices.push(...a.prices);
|
|
510
|
+
maxRelevance = Math.max(maxRelevance, a._score || a.relevance || 0);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
merged: true,
|
|
515
|
+
strategy: 'union',
|
|
516
|
+
titles: [...new Set(allTitles)],
|
|
517
|
+
descriptions: [...new Set(allDescriptions)],
|
|
518
|
+
prices: [...new Set(allPrices)],
|
|
519
|
+
relevance: maxRelevance,
|
|
520
|
+
sourceCount: agents.length,
|
|
521
|
+
allSources: agents.map(a => ({ source: a._source || a.source, score: a._score || a.relevance || 0 })),
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function mergeConsensus(agents) {
|
|
526
|
+
const titleFreq = {};
|
|
527
|
+
const priceFreq = {};
|
|
528
|
+
let bestDesc = '';
|
|
529
|
+
let bestDescScore = -1;
|
|
530
|
+
|
|
531
|
+
for (const a of agents) {
|
|
532
|
+
const t = (a.title || '').toLowerCase().trim();
|
|
533
|
+
if (t) titleFreq[t] = (titleFreq[t] || 0) + 1;
|
|
534
|
+
if (a.prices) {
|
|
535
|
+
for (const p of a.prices) priceFreq[p] = (priceFreq[p] || 0) + 1;
|
|
536
|
+
}
|
|
537
|
+
const s = a._score || a.relevance || 0;
|
|
538
|
+
if (s > bestDescScore && a.description) {
|
|
539
|
+
bestDescScore = s;
|
|
540
|
+
bestDesc = a.description;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const threshold = Math.max(Math.ceil(agents.length / 2), 1);
|
|
545
|
+
|
|
546
|
+
const consensusTitles = Object.entries(titleFreq).filter(([, c]) => c >= threshold).map(([t]) => t);
|
|
547
|
+
const consensusPrices = Object.entries(priceFreq).filter(([, c]) => c >= threshold).map(([p]) => p);
|
|
548
|
+
|
|
549
|
+
const avgRelevance = agents.reduce((s, a) => s + (a._score || a.relevance || 0), 0) / agents.length;
|
|
550
|
+
|
|
551
|
+
return {
|
|
552
|
+
merged: true,
|
|
553
|
+
strategy: 'consensus',
|
|
554
|
+
titles: consensusTitles,
|
|
555
|
+
description: bestDesc,
|
|
556
|
+
prices: consensusPrices,
|
|
557
|
+
relevance: Math.round(avgRelevance * 100) / 100,
|
|
558
|
+
agreement: {
|
|
559
|
+
titleAgreement: consensusTitles.length > 0,
|
|
560
|
+
priceAgreement: consensusPrices.length > 0,
|
|
561
|
+
threshold,
|
|
562
|
+
totalAgents: agents.length,
|
|
563
|
+
},
|
|
564
|
+
allSources: agents.map(a => ({ source: a._source || a.source, score: a._score || a.relevance || 0 })),
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ─── 8. applyFairnessToResults ───────────────────────────────────────
|
|
569
|
+
|
|
570
|
+
function applyFairnessToResults(results) {
|
|
571
|
+
if (!results || results.length === 0) return results;
|
|
572
|
+
|
|
573
|
+
const domainCounts = {};
|
|
574
|
+
for (const r of results) {
|
|
575
|
+
const domain = extractDomain(r._source || r.source || '');
|
|
576
|
+
domainCounts[domain] = (domainCounts[domain] || 0) + 1;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const totalResults = results.length;
|
|
580
|
+
|
|
581
|
+
return results.map(r => {
|
|
582
|
+
const domain = extractDomain(r._source || r.source || '');
|
|
583
|
+
const score = r._score || r.relevance || 0;
|
|
584
|
+
let adjusted = score;
|
|
585
|
+
|
|
586
|
+
const isIndie = isIndependentSite(domain);
|
|
587
|
+
if (isIndie) adjusted += score * 0.12;
|
|
588
|
+
|
|
589
|
+
const domainShare = (domainCounts[domain] || 1) / totalResults;
|
|
590
|
+
if (domainShare > 0.4) {
|
|
591
|
+
adjusted -= score * 0.10;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const isSmall = isSmallSite(domain);
|
|
595
|
+
if (isSmall) adjusted += score * 0.08;
|
|
596
|
+
|
|
597
|
+
adjusted = Math.min(Math.max(Math.round(adjusted * 100) / 100, 0), 100);
|
|
598
|
+
|
|
599
|
+
return { ...r, _score: adjusted, _fairnessApplied: true, _originalScore: score };
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function extractDomain(url) {
|
|
604
|
+
try { return new URL(url).hostname; } catch (_) { return url; }
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const MAJOR_DOMAINS = [
|
|
608
|
+
'amazon.com', 'google.com', 'facebook.com', 'apple.com', 'microsoft.com',
|
|
609
|
+
'walmart.com', 'ebay.com', 'target.com', 'bestbuy.com', 'alibaba.com',
|
|
610
|
+
'aliexpress.com', 'rakuten.com', 'shopify.com', 'etsy.com',
|
|
611
|
+
];
|
|
612
|
+
|
|
613
|
+
function isIndependentSite(domain) {
|
|
614
|
+
const lower = domain.toLowerCase().replace(/^www\./, '');
|
|
615
|
+
return !MAJOR_DOMAINS.some(d => lower === d || lower.endsWith('.' + d));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function isSmallSite(domain) {
|
|
619
|
+
const lower = domain.toLowerCase().replace(/^www\./, '');
|
|
620
|
+
const parts = lower.split('.');
|
|
621
|
+
if (parts.length > 3) return false;
|
|
622
|
+
return !MAJOR_DOMAINS.some(d => lower === d || lower.endsWith('.' + d));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// ─── 9. getTaskStatus / getTaskResult ────────────────────────────────
|
|
626
|
+
|
|
627
|
+
function getTaskStatus(taskId) {
|
|
628
|
+
const task = stmts.getTask.get(taskId);
|
|
629
|
+
if (!task) return null;
|
|
630
|
+
|
|
631
|
+
const agents = stmts.getAgentsByTask.all(taskId);
|
|
632
|
+
const agentSummary = agents.map(a => ({
|
|
633
|
+
id: a.id,
|
|
634
|
+
role: a.agent_role,
|
|
635
|
+
type: a.agent_type,
|
|
636
|
+
target: a.target,
|
|
637
|
+
status: a.status,
|
|
638
|
+
score: a.score,
|
|
639
|
+
error: a.error,
|
|
640
|
+
}));
|
|
641
|
+
|
|
642
|
+
return {
|
|
643
|
+
id: task.id,
|
|
644
|
+
siteId: task.site_id,
|
|
645
|
+
taskType: task.task_type,
|
|
646
|
+
objective: task.objective,
|
|
647
|
+
status: task.status,
|
|
648
|
+
createdAt: task.created_at,
|
|
649
|
+
startedAt: task.started_at,
|
|
650
|
+
completedAt: task.completed_at,
|
|
651
|
+
agents: agentSummary,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function getTaskResult(taskId) {
|
|
656
|
+
const task = stmts.getTask.get(taskId);
|
|
657
|
+
if (!task) return null;
|
|
658
|
+
|
|
659
|
+
const resultRow = stmts.getResult.get(taskId);
|
|
660
|
+
if (!resultRow) return { taskId, status: task.status, result: null };
|
|
661
|
+
|
|
662
|
+
let mergedResult = {};
|
|
663
|
+
let comparison = {};
|
|
664
|
+
try { mergedResult = JSON.parse(resultRow.merged_result || '{}'); } catch (_) {}
|
|
665
|
+
try { comparison = JSON.parse(resultRow.comparison || '{}'); } catch (_) {}
|
|
666
|
+
|
|
667
|
+
return {
|
|
668
|
+
taskId,
|
|
669
|
+
status: task.status,
|
|
670
|
+
result: mergedResult,
|
|
671
|
+
fairnessApplied: !!resultRow.fairness_applied,
|
|
672
|
+
totalSources: resultRow.total_sources,
|
|
673
|
+
bestSource: resultRow.best_source,
|
|
674
|
+
comparison,
|
|
675
|
+
createdAt: resultRow.created_at,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// ─── 10. cancelTask ──────────────────────────────────────────────────
|
|
680
|
+
|
|
681
|
+
function cancelTask(taskId) {
|
|
682
|
+
const task = stmts.getTask.get(taskId);
|
|
683
|
+
if (!task) return null;
|
|
684
|
+
if (task.status === 'completed' || task.status === 'cancelled') {
|
|
685
|
+
return { id: task.id, status: task.status, changed: false };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
const now = new Date().toISOString();
|
|
689
|
+
stmts.updateTaskStatus.run('cancelled', task.started_at || now, now, taskId);
|
|
690
|
+
stmts.cancelPendingAgents.run(taskId);
|
|
691
|
+
|
|
692
|
+
return { id: task.id, status: 'cancelled', changed: true };
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// ─── 11. getSwarmHistory ─────────────────────────────────────────────
|
|
696
|
+
|
|
697
|
+
function getSwarmHistory(siteId, { limit = 50, taskType } = {}) {
|
|
698
|
+
let tasks;
|
|
699
|
+
if (taskType) {
|
|
700
|
+
tasks = stmts.taskHistoryByType.all(siteId, taskType, limit);
|
|
701
|
+
} else {
|
|
702
|
+
tasks = stmts.taskHistory.all(siteId, limit);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return tasks.map(t => {
|
|
706
|
+
let params = {};
|
|
707
|
+
try { params = JSON.parse(t.parameters || '{}'); } catch (_) {}
|
|
708
|
+
const agents = stmts.getAgentsByTask.all(t.id);
|
|
709
|
+
return {
|
|
710
|
+
id: t.id,
|
|
711
|
+
taskType: t.task_type,
|
|
712
|
+
objective: t.objective,
|
|
713
|
+
parameters: params,
|
|
714
|
+
status: t.status,
|
|
715
|
+
agentCount: agents.length,
|
|
716
|
+
createdBy: t.created_by,
|
|
717
|
+
createdAt: t.created_at,
|
|
718
|
+
startedAt: t.started_at,
|
|
719
|
+
completedAt: t.completed_at,
|
|
720
|
+
};
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// ─── 12. getSwarmStats ───────────────────────────────────────────────
|
|
725
|
+
|
|
726
|
+
function getSwarmStats(siteId) {
|
|
727
|
+
const totalTasks = db.prepare('SELECT COUNT(*) as c FROM swarm_tasks WHERE site_id = ?').get(siteId).c;
|
|
728
|
+
const completedTasks = db.prepare("SELECT COUNT(*) as c FROM swarm_tasks WHERE site_id = ? AND status = 'completed'").get(siteId).c;
|
|
729
|
+
const failedTasks = db.prepare("SELECT COUNT(*) as c FROM swarm_tasks WHERE site_id = ? AND status = 'failed'").get(siteId).c;
|
|
730
|
+
const cancelledTasks = db.prepare("SELECT COUNT(*) as c FROM swarm_tasks WHERE site_id = ? AND status = 'cancelled'").get(siteId).c;
|
|
731
|
+
const runningTasks = db.prepare("SELECT COUNT(*) as c FROM swarm_tasks WHERE site_id = ? AND status = 'running'").get(siteId).c;
|
|
732
|
+
|
|
733
|
+
const avgAgentsRow = db.prepare(`
|
|
734
|
+
SELECT AVG(agent_count) as avg_agents FROM (
|
|
735
|
+
SELECT COUNT(*) as agent_count FROM swarm_agents a
|
|
736
|
+
JOIN swarm_tasks t ON a.task_id = t.id
|
|
737
|
+
WHERE t.site_id = ? GROUP BY a.task_id
|
|
738
|
+
)
|
|
739
|
+
`).get(siteId);
|
|
740
|
+
const avgAgents = avgAgentsRow ? Math.round((avgAgentsRow.avg_agents || 0) * 100) / 100 : 0;
|
|
741
|
+
|
|
742
|
+
const successRate = totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 10000) / 100 : 0;
|
|
743
|
+
|
|
744
|
+
const latencyRow = db.prepare(`
|
|
745
|
+
SELECT AVG(
|
|
746
|
+
CAST((julianday(completed_at) - julianday(started_at)) * 86400000 AS INTEGER)
|
|
747
|
+
) as avg_latency
|
|
748
|
+
FROM swarm_tasks
|
|
749
|
+
WHERE site_id = ? AND status = 'completed' AND started_at IS NOT NULL AND completed_at IS NOT NULL
|
|
750
|
+
`).get(siteId);
|
|
751
|
+
const avgLatencyMs = latencyRow ? Math.round(latencyRow.avg_latency || 0) : 0;
|
|
752
|
+
|
|
753
|
+
const taskTypeBreakdown = db.prepare(`
|
|
754
|
+
SELECT task_type, COUNT(*) as count,
|
|
755
|
+
SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed
|
|
756
|
+
FROM swarm_tasks WHERE site_id = ? GROUP BY task_type
|
|
757
|
+
`).all(siteId);
|
|
758
|
+
|
|
759
|
+
return {
|
|
760
|
+
totalTasks,
|
|
761
|
+
completedTasks,
|
|
762
|
+
failedTasks,
|
|
763
|
+
cancelledTasks,
|
|
764
|
+
runningTasks,
|
|
765
|
+
avgAgents,
|
|
766
|
+
successRate,
|
|
767
|
+
avgLatencyMs,
|
|
768
|
+
taskTypeBreakdown,
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// ─── Exports ─────────────────────────────────────────────────────────
|
|
773
|
+
|
|
774
|
+
module.exports = {
|
|
775
|
+
configureSwarm,
|
|
776
|
+
getSwarmConfig,
|
|
777
|
+
createTask,
|
|
778
|
+
assignAgents,
|
|
779
|
+
runSwarmTask,
|
|
780
|
+
executeAgent,
|
|
781
|
+
mergeResults,
|
|
782
|
+
applyFairnessToResults,
|
|
783
|
+
getTaskStatus,
|
|
784
|
+
getTaskResult,
|
|
785
|
+
cancelTask,
|
|
786
|
+
getSwarmHistory,
|
|
787
|
+
getSwarmStats,
|
|
788
|
+
};
|