web-agent-bridge 2.9.0 → 3.2.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 +51 -0
- package/README.ar.md +79 -0
- package/README.md +104 -4
- package/package.json +2 -1
- package/public/.well-known/ai-plugin.json +28 -0
- package/public/agent-workspace.html +3 -1
- package/public/ai.html +5 -3
- package/public/api.html +412 -0
- package/public/browser.html +4 -2
- package/public/cookies.html +4 -2
- package/public/dashboard.html +5 -3
- package/public/demo.html +1770 -1
- package/public/docs.html +6 -4
- package/public/growth.html +463 -0
- package/public/index.html +982 -738
- package/public/llms-full.txt +52 -1
- package/public/llms.txt +39 -0
- package/public/login.html +6 -4
- package/public/premium-dashboard.html +7 -5
- package/public/premium.html +6 -4
- package/public/privacy.html +4 -2
- package/public/register.html +6 -4
- package/public/score.html +263 -0
- package/public/terms.html +4 -2
- package/sdk/index.js +7 -1
- package/sdk/package.json +12 -1
- package/server/index.js +427 -375
- package/server/middleware/rateLimits.js +3 -3
- package/server/migrations/006_growth_suite.sql +138 -0
- package/server/routes/agent-workspace.js +162 -0
- package/server/routes/demo-showcase.js +332 -0
- package/server/routes/discovery.js +18 -7
- package/server/routes/gateway.js +157 -0
- package/server/routes/growth.js +962 -0
- package/server/routes/runtime.js +204 -0
- package/server/routes/universal.js +9 -1
- package/server/routes/wab-api.js +16 -6
- package/server/runtime/container-worker.js +111 -0
- package/server/runtime/container.js +448 -0
- package/server/runtime/distributed-worker.js +362 -0
- package/server/runtime/index.js +21 -1
- package/server/runtime/queue.js +599 -0
- package/server/runtime/replay.js +431 -29
- package/server/runtime/scheduler.js +194 -55
- package/server/services/api-key-engine.js +261 -0
- package/server/services/lfd.js +22 -3
- package/server/services/modules/affiliate-intelligence.js +93 -0
- package/server/services/modules/agent-firewall.js +90 -0
- package/server/services/modules/bounty.js +89 -0
- package/server/services/modules/collective-bargaining.js +92 -0
- package/server/services/modules/dark-pattern.js +66 -0
- package/server/services/modules/gov-intelligence.js +45 -0
- package/server/services/modules/neural.js +55 -0
- package/server/services/modules/notary.js +49 -0
- package/server/services/modules/price-time-machine.js +86 -0
- package/server/services/modules/protocol.js +104 -0
- package/server/services/premium.js +1 -1
- package/server/services/price-intelligence.js +2 -1
- package/server/services/vision.js +2 -2
package/server/routes/runtime.js
CHANGED
|
@@ -1940,4 +1940,208 @@ router.get('/cluster/events', (req, res) => {
|
|
|
1940
1940
|
res.json({ events });
|
|
1941
1941
|
});
|
|
1942
1942
|
|
|
1943
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1944
|
+
// CONTAINER ISOLATION
|
|
1945
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1946
|
+
|
|
1947
|
+
let containerRunner;
|
|
1948
|
+
try { containerRunner = require('../runtime/container').containerRunner; } catch {}
|
|
1949
|
+
|
|
1950
|
+
/**
|
|
1951
|
+
* Run a task in an isolated container
|
|
1952
|
+
*/
|
|
1953
|
+
router.post('/containers/run', async (req, res) => {
|
|
1954
|
+
if (!containerRunner) return res.status(501).json({ error: 'Container isolation not available' });
|
|
1955
|
+
try {
|
|
1956
|
+
const result = await containerRunner.runInProcess(
|
|
1957
|
+
req.body.taskId || `ctr_task_${Date.now()}`,
|
|
1958
|
+
req.body.code || '',
|
|
1959
|
+
{
|
|
1960
|
+
params: req.body.params || {},
|
|
1961
|
+
timeout: req.body.timeout || 60000,
|
|
1962
|
+
maxMemory: req.body.maxMemory || 256 * 1024 * 1024,
|
|
1963
|
+
allowNetwork: req.body.allowNetwork !== false,
|
|
1964
|
+
}
|
|
1965
|
+
);
|
|
1966
|
+
res.json(result);
|
|
1967
|
+
} catch (err) {
|
|
1968
|
+
res.status(500).json({ error: err.message });
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
|
|
1972
|
+
/**
|
|
1973
|
+
* List active containers
|
|
1974
|
+
*/
|
|
1975
|
+
router.get('/containers', (req, res) => {
|
|
1976
|
+
if (!containerRunner) return res.json({ containers: [] });
|
|
1977
|
+
res.json({ containers: containerRunner.listContainers() });
|
|
1978
|
+
});
|
|
1979
|
+
|
|
1980
|
+
/**
|
|
1981
|
+
* Get container details
|
|
1982
|
+
*/
|
|
1983
|
+
router.get('/containers/:containerId', (req, res) => {
|
|
1984
|
+
if (!containerRunner) return res.status(404).json({ error: 'Not found' });
|
|
1985
|
+
const c = containerRunner.getContainer(req.params.containerId);
|
|
1986
|
+
if (!c) return res.status(404).json({ error: 'Container not found' });
|
|
1987
|
+
res.json(c);
|
|
1988
|
+
});
|
|
1989
|
+
|
|
1990
|
+
/**
|
|
1991
|
+
* Kill a container
|
|
1992
|
+
*/
|
|
1993
|
+
router.post('/containers/:containerId/kill', (req, res) => {
|
|
1994
|
+
if (!containerRunner) return res.status(404).json({ error: 'Not found' });
|
|
1995
|
+
const ok = containerRunner.kill(req.params.containerId);
|
|
1996
|
+
res.json({ success: ok });
|
|
1997
|
+
});
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* Container stats
|
|
2001
|
+
*/
|
|
2002
|
+
router.get('/containers/stats/summary', (req, res) => {
|
|
2003
|
+
if (!containerRunner) return res.json({ active: 0 });
|
|
2004
|
+
res.json(containerRunner.getStats());
|
|
2005
|
+
});
|
|
2006
|
+
|
|
2007
|
+
/**
|
|
2008
|
+
* Check Docker availability
|
|
2009
|
+
*/
|
|
2010
|
+
router.get('/containers/docker/status', (req, res) => {
|
|
2011
|
+
if (!containerRunner) return res.json({ available: false });
|
|
2012
|
+
res.json({ available: containerRunner.isDockerAvailable() });
|
|
2013
|
+
});
|
|
2014
|
+
|
|
2015
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2016
|
+
// EXTERNAL QUEUE MANAGEMENT
|
|
2017
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2018
|
+
|
|
2019
|
+
let queueModule;
|
|
2020
|
+
try { queueModule = require('../runtime/queue'); } catch {}
|
|
2021
|
+
|
|
2022
|
+
/**
|
|
2023
|
+
* Queue stats
|
|
2024
|
+
*/
|
|
2025
|
+
router.get('/queue/stats', (req, res) => {
|
|
2026
|
+
if (!queueModule) return res.json({ backend: 'memory' });
|
|
2027
|
+
const q = queueModule.createQueue('scheduler');
|
|
2028
|
+
res.json(q.getStats());
|
|
2029
|
+
});
|
|
2030
|
+
|
|
2031
|
+
/**
|
|
2032
|
+
* Purge completed items from queue
|
|
2033
|
+
*/
|
|
2034
|
+
router.post('/queue/purge', (req, res) => {
|
|
2035
|
+
if (!queueModule) return res.json({ purged: 0 });
|
|
2036
|
+
const q = queueModule.createQueue('scheduler');
|
|
2037
|
+
const purged = q.purgeCompleted(parseInt(req.body.maxAge) || 3600_000);
|
|
2038
|
+
res.json({ purged });
|
|
2039
|
+
});
|
|
2040
|
+
|
|
2041
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2042
|
+
// ENHANCED REPLAY
|
|
2043
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2044
|
+
|
|
2045
|
+
/**
|
|
2046
|
+
* Export a recording (full data for download)
|
|
2047
|
+
*/
|
|
2048
|
+
router.get('/replay/recordings/:taskId/export', (req, res) => {
|
|
2049
|
+
const data = replayEngine.exportRecording(req.params.taskId);
|
|
2050
|
+
if (!data) return res.status(404).json({ error: 'Recording not found' });
|
|
2051
|
+
res.json(data);
|
|
2052
|
+
});
|
|
2053
|
+
|
|
2054
|
+
/**
|
|
2055
|
+
* Import a recording
|
|
2056
|
+
*/
|
|
2057
|
+
router.post('/replay/recordings/import', (req, res) => {
|
|
2058
|
+
try {
|
|
2059
|
+
const id = replayEngine.importRecording(req.body);
|
|
2060
|
+
res.json({ success: true, recordingId: id });
|
|
2061
|
+
} catch (err) {
|
|
2062
|
+
res.status(400).json({ error: err.message });
|
|
2063
|
+
}
|
|
2064
|
+
});
|
|
2065
|
+
|
|
2066
|
+
/**
|
|
2067
|
+
* Delete a recording
|
|
2068
|
+
*/
|
|
2069
|
+
router.delete('/replay/recordings/:taskId', (req, res) => {
|
|
2070
|
+
replayEngine.deleteRecording(req.params.taskId);
|
|
2071
|
+
res.json({ success: true });
|
|
2072
|
+
});
|
|
2073
|
+
|
|
2074
|
+
/**
|
|
2075
|
+
* Replay from a specific checkpoint
|
|
2076
|
+
*/
|
|
2077
|
+
router.post('/replay/:taskId/from-checkpoint', async (req, res) => {
|
|
2078
|
+
try {
|
|
2079
|
+
const result = await replayEngine.replay(req.params.taskId, {
|
|
2080
|
+
verify: req.body.verify !== false,
|
|
2081
|
+
continueOnMismatch: !!req.body.continueOnMismatch,
|
|
2082
|
+
fromCheckpoint: req.body.checkpoint,
|
|
2083
|
+
});
|
|
2084
|
+
res.json(result);
|
|
2085
|
+
} catch (err) {
|
|
2086
|
+
res.status(400).json({ error: err.message });
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
|
|
2090
|
+
/**
|
|
2091
|
+
* Purge old recordings
|
|
2092
|
+
*/
|
|
2093
|
+
router.post('/replay/purge', (req, res) => {
|
|
2094
|
+
const maxAge = parseInt(req.body.maxAge) || 7 * 24 * 3600_000;
|
|
2095
|
+
replayEngine.purgeOld(maxAge);
|
|
2096
|
+
res.json({ success: true });
|
|
2097
|
+
});
|
|
2098
|
+
|
|
2099
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2100
|
+
// WORKER PULL ENDPOINT (for distributed workers)
|
|
2101
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
2102
|
+
|
|
2103
|
+
/**
|
|
2104
|
+
* Workers pull tasks from here
|
|
2105
|
+
*/
|
|
2106
|
+
router.post('/cluster/nodes/:nodeId/pull', (req, res) => {
|
|
2107
|
+
const limit = parseInt(req.body.limit) || 5;
|
|
2108
|
+
// Fetch pending tasks from the cluster task distributor
|
|
2109
|
+
const tasks = [];
|
|
2110
|
+
try {
|
|
2111
|
+
const pending = distributor.getPendingTasks ? distributor.getPendingTasks(req.params.nodeId, limit) : [];
|
|
2112
|
+
tasks.push(...pending);
|
|
2113
|
+
} catch {}
|
|
2114
|
+
res.json({ tasks });
|
|
2115
|
+
});
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Worker reports task started
|
|
2119
|
+
*/
|
|
2120
|
+
router.post('/cluster/tasks/:taskId/started', (req, res) => {
|
|
2121
|
+
bus.emit('cluster.task.started', { taskId: req.params.taskId, nodeId: req.body.nodeId });
|
|
2122
|
+
res.json({ ok: true });
|
|
2123
|
+
});
|
|
2124
|
+
|
|
2125
|
+
/**
|
|
2126
|
+
* Worker reports task completed
|
|
2127
|
+
*/
|
|
2128
|
+
router.post('/cluster/tasks/:taskId/completed', (req, res) => {
|
|
2129
|
+
bus.emit('cluster.task.completed', {
|
|
2130
|
+
taskId: req.params.taskId,
|
|
2131
|
+
result: req.body.result,
|
|
2132
|
+
});
|
|
2133
|
+
res.json({ ok: true });
|
|
2134
|
+
});
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* Worker reports task failed
|
|
2138
|
+
*/
|
|
2139
|
+
router.post('/cluster/tasks/:taskId/failed', (req, res) => {
|
|
2140
|
+
bus.emit('cluster.task.failed', {
|
|
2141
|
+
taskId: req.params.taskId,
|
|
2142
|
+
error: req.body.error,
|
|
2143
|
+
});
|
|
2144
|
+
res.json({ ok: true });
|
|
2145
|
+
});
|
|
2146
|
+
|
|
1943
2147
|
module.exports = router;
|
|
@@ -11,7 +11,15 @@ const express = require('express');
|
|
|
11
11
|
const router = express.Router();
|
|
12
12
|
const scraper = require('../services/universal-scraper');
|
|
13
13
|
const priceIntel = require('../services/price-intelligence');
|
|
14
|
-
|
|
14
|
+
let fairness;
|
|
15
|
+
try { fairness = require('../services/fairness-engine'); } catch {
|
|
16
|
+
fairness = {
|
|
17
|
+
calculateFairnessScore: () => ({ score: 0, label: 'unrated' }),
|
|
18
|
+
rankWithFairness: (_items) => _items,
|
|
19
|
+
detectDarkPatterns: () => [],
|
|
20
|
+
getTopFairSites: () => []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
|
|
16
24
|
// ─── POST /api/universal/extract ─────────────────────────────────────
|
|
17
25
|
// Extract prices/products from a URL (server-side fetch)
|
package/server/routes/wab-api.js
CHANGED
|
@@ -14,12 +14,22 @@ const { findSiteById, findSiteByLicense, recordAnalytic, db } = require('../mode
|
|
|
14
14
|
const { broadcastAnalytic } = require('../ws');
|
|
15
15
|
const { wabAuthenticateLimiter, wabActionLimiter, searchLimiter } = require('../middleware/rateLimits');
|
|
16
16
|
const { auditLog } = require('../services/security');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
|
|
18
|
+
// Fairness module is proprietary — provide stubs when not available
|
|
19
|
+
let calculateNeutralityScore, fairnessWeightedSearch, getDirectoryListings, generateFairnessReport;
|
|
20
|
+
try {
|
|
21
|
+
({
|
|
22
|
+
calculateNeutralityScore,
|
|
23
|
+
fairnessWeightedSearch,
|
|
24
|
+
getDirectoryListings,
|
|
25
|
+
generateFairnessReport
|
|
26
|
+
} = require('../services/fairness'));
|
|
27
|
+
} catch {
|
|
28
|
+
calculateNeutralityScore = () => ({ score: 0, label: 'unrated' });
|
|
29
|
+
fairnessWeightedSearch = (_q, candidates) => candidates;
|
|
30
|
+
getDirectoryListings = () => [];
|
|
31
|
+
generateFairnessReport = () => ({ status: 'unavailable' });
|
|
32
|
+
}
|
|
23
33
|
|
|
24
34
|
const WAB_VERSION = '1.2.0';
|
|
25
35
|
const PROTOCOL_VERSION = '1.0';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WAB Container Worker — Runs inside a forked child process
|
|
5
|
+
*
|
|
6
|
+
* This script is the entry point for process-isolated task execution.
|
|
7
|
+
* It reads the task definition from a JSON file, executes it,
|
|
8
|
+
* and sends results back via IPC.
|
|
9
|
+
*
|
|
10
|
+
* Security:
|
|
11
|
+
* - Runs in a separate process with memory limits (--max-old-space-size)
|
|
12
|
+
* - Limited filesystem access (only its tmp directory)
|
|
13
|
+
* - Can disable network via environment
|
|
14
|
+
* - Timeout enforced by parent
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const taskFile = process.argv[2];
|
|
21
|
+
if (!taskFile) {
|
|
22
|
+
process.stderr.write('No task file specified\n');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let taskData;
|
|
27
|
+
try {
|
|
28
|
+
taskData = JSON.parse(fs.readFileSync(taskFile, 'utf8'));
|
|
29
|
+
} catch (err) {
|
|
30
|
+
process.stderr.write(`Failed to read task file: ${err.message}\n`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ─── Sandbox Utilities (available to task code) ──────────────────────
|
|
35
|
+
|
|
36
|
+
const sandbox = {
|
|
37
|
+
taskId: taskData.taskId,
|
|
38
|
+
containerId: taskData.containerId,
|
|
39
|
+
params: taskData.params || {},
|
|
40
|
+
|
|
41
|
+
// Send progress updates
|
|
42
|
+
progress(pct) {
|
|
43
|
+
if (process.send) process.send({ type: 'progress', progress: pct });
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// Send log messages
|
|
47
|
+
log(message) {
|
|
48
|
+
if (process.send) process.send({ type: 'log', message: String(message).slice(0, 1000) });
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// Read a param
|
|
52
|
+
param(key, defaultValue) {
|
|
53
|
+
return taskData.params[key] !== undefined ? taskData.params[key] : defaultValue;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
// Filesystem is restricted to tmpDir
|
|
57
|
+
tmpDir: path.dirname(taskFile),
|
|
58
|
+
|
|
59
|
+
readFile(name) {
|
|
60
|
+
const p = path.join(sandbox.tmpDir, path.basename(name));
|
|
61
|
+
return fs.readFileSync(p, 'utf8');
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
writeFile(name, content) {
|
|
65
|
+
const p = path.join(sandbox.tmpDir, path.basename(name));
|
|
66
|
+
fs.writeFileSync(p, content);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// ─── Execute Task ────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
async function execute() {
|
|
73
|
+
try {
|
|
74
|
+
let result;
|
|
75
|
+
|
|
76
|
+
if (taskData.code) {
|
|
77
|
+
// Execute provided code string in a restricted scope
|
|
78
|
+
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
|
79
|
+
const fn = new AsyncFunction('sandbox', 'params', taskData.code);
|
|
80
|
+
result = await fn(sandbox, taskData.params);
|
|
81
|
+
} else if (taskData.module) {
|
|
82
|
+
// Execute a module (for trusted internal tasks)
|
|
83
|
+
const mod = require(taskData.module);
|
|
84
|
+
if (typeof mod.execute === 'function') {
|
|
85
|
+
result = await mod.execute(taskData.params, sandbox);
|
|
86
|
+
} else {
|
|
87
|
+
result = { error: 'Module has no execute() function' };
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
result = { echo: taskData.params, message: 'No code or module specified' };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Send result back via IPC
|
|
94
|
+
if (process.send) {
|
|
95
|
+
process.send({ type: 'result', data: result });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Give IPC time to flush
|
|
99
|
+
setTimeout(() => process.exit(0), 100);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
process.stderr.write(`Task error: ${err.message}\n${err.stack}\n`);
|
|
102
|
+
|
|
103
|
+
if (process.send) {
|
|
104
|
+
process.send({ type: 'result', data: null });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setTimeout(() => process.exit(1), 100);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
execute();
|