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
|
@@ -1,329 +1,406 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WAB Discovery Protocol — Auto-generated discovery documents and
|
|
3
|
-
* public registry of WAB-enabled sites with fairness scoring.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const express = require('express');
|
|
7
|
-
const router = express.Router();
|
|
8
|
-
const { findSiteById, db } = require('../models/db');
|
|
9
|
-
const { authenticateToken } = require('../middleware/auth');
|
|
10
|
-
const {
|
|
11
|
-
calculateNeutralityScore,
|
|
12
|
-
fairnessWeightedSearch,
|
|
13
|
-
registerInDirectory,
|
|
14
|
-
getDirectoryListings,
|
|
15
|
-
generateFairnessReport
|
|
16
|
-
} = require('../services/fairness');
|
|
17
|
-
|
|
18
|
-
const WAB_VERSION = '1.
|
|
19
|
-
|
|
20
|
-
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
function findSiteByDomain(domain) {
|
|
23
|
-
if (!domain) return null;
|
|
24
|
-
const normalized = domain.toLowerCase().replace(/^www\./, '');
|
|
25
|
-
return db.prepare(
|
|
26
|
-
|
|
27
|
-
).get(normalized);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getRequestDomain(req) {
|
|
31
|
-
const origin = req.get('origin');
|
|
32
|
-
if (origin) {
|
|
33
|
-
try { return new URL(origin).hostname; } catch (_) {}
|
|
34
|
-
}
|
|
35
|
-
const host = req.get('host');
|
|
36
|
-
if (host) return host.split(':')[0];
|
|
37
|
-
return req.hostname;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function parseSiteConfig(site) {
|
|
41
|
-
try { return JSON.parse(site.config || '{}'); } catch (_) { return {}; }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function buildDiscoveryDocument(site) {
|
|
45
|
-
const config = parseSiteConfig(site);
|
|
46
|
-
const perms = config.agentPermissions || {};
|
|
47
|
-
const restrictions = config.restrictions || {};
|
|
48
|
-
const features = config.features || {};
|
|
49
|
-
|
|
50
|
-
const enabledActions = Object.entries(perms)
|
|
51
|
-
.filter(([, v]) => v)
|
|
52
|
-
.map(([k]) => k);
|
|
53
|
-
|
|
54
|
-
const featureList = ['auto_discovery', 'noscript_fallback'];
|
|
55
|
-
if (features.advancedAnalytics) featureList.push('advanced_analytics');
|
|
56
|
-
if (features.realTimeUpdates) featureList.push('real_time_updates');
|
|
57
|
-
if (perms.apiAccess) featureList.push('api_access');
|
|
58
|
-
|
|
59
|
-
const dirEntry = db.prepare('SELECT * FROM wab_directory WHERE site_id = ?').get(site.id);
|
|
60
|
-
const neutralityScore = calculateNeutralityScore(site);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
wab_version: WAB_VERSION,
|
|
64
|
-
generated_at: new Date().toISOString(),
|
|
65
|
-
provider: {
|
|
66
|
-
name: site.name,
|
|
67
|
-
domain: site.domain,
|
|
68
|
-
category: (dirEntry && dirEntry.category) || config.category || 'general',
|
|
69
|
-
description: site.description || ''
|
|
70
|
-
},
|
|
71
|
-
capabilities: {
|
|
72
|
-
commands: enabledActions,
|
|
73
|
-
permissions: perms,
|
|
74
|
-
tier: site.tier,
|
|
75
|
-
transport: ['js_global', 'http', 'websocket'],
|
|
76
|
-
features: featureList
|
|
77
|
-
},
|
|
78
|
-
agent_access: {
|
|
79
|
-
bridge_script: '/script/ai-agent-bridge.js',
|
|
80
|
-
api_base: '/api/wab',
|
|
81
|
-
websocket: '/ws/analytics',
|
|
82
|
-
noscript: `/api/noscript/bridge/${site.id}`,
|
|
83
|
-
discovery: `/api/discovery/${site.id}`
|
|
84
|
-
},
|
|
85
|
-
fairness: {
|
|
86
|
-
is_independent: dirEntry ? !!dirEntry.is_independent : false,
|
|
87
|
-
commission_rate: dirEntry ? dirEntry.commission_rate : 0,
|
|
88
|
-
direct_benefit: dirEntry ? (dirEntry.direct_benefit || '') : '',
|
|
89
|
-
neutrality_score: neutralityScore
|
|
90
|
-
},
|
|
91
|
-
security: {
|
|
92
|
-
session_required: true,
|
|
93
|
-
origin_validation: true,
|
|
94
|
-
rate_limit: (restrictions.rateLimit && restrictions.rateLimit.maxCallsPerMinute) || 60,
|
|
95
|
-
sandbox: true
|
|
96
|
-
},
|
|
97
|
-
endpoints: {
|
|
98
|
-
authenticate: '/api/wab/authenticate',
|
|
99
|
-
discover: `/api/wab/discover?siteId=${site.id}`,
|
|
100
|
-
actions: `/api/wab/actions?siteId=${site.id}`,
|
|
101
|
-
execute: '/api/wab/actions/{actionName}',
|
|
102
|
-
read: '/api/wab/read',
|
|
103
|
-
page_info: `/api/wab/page-info?siteId=${site.id}`,
|
|
104
|
-
search: '/api/wab/search',
|
|
105
|
-
ping: '/api/wab/ping',
|
|
106
|
-
token_exchange: '/api/license/token',
|
|
107
|
-
bridge_page: `/api/noscript/bridge/${site.id}`
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ═════════════════════════════════════════════════════════════════════
|
|
113
|
-
// 1. GET /.well-known/wab.json — Standard discovery location
|
|
114
|
-
// ═════════════════════════════════════════════════════════════════════
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
1
|
+
/**
|
|
2
|
+
* WAB Discovery Protocol — Auto-generated discovery documents and
|
|
3
|
+
* public registry of WAB-enabled sites with fairness scoring.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const express = require('express');
|
|
7
|
+
const router = express.Router();
|
|
8
|
+
const { findSiteById, db } = require('../models/db');
|
|
9
|
+
const { authenticateToken } = require('../middleware/auth');
|
|
10
|
+
const {
|
|
11
|
+
calculateNeutralityScore,
|
|
12
|
+
fairnessWeightedSearch,
|
|
13
|
+
registerInDirectory,
|
|
14
|
+
getDirectoryListings,
|
|
15
|
+
generateFairnessReport
|
|
16
|
+
} = require('../services/fairness');
|
|
17
|
+
|
|
18
|
+
const WAB_VERSION = '1.2.0';
|
|
19
|
+
|
|
20
|
+
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
function findSiteByDomain(domain) {
|
|
23
|
+
if (!domain) return null;
|
|
24
|
+
const normalized = domain.toLowerCase().replace(/^www\./, '');
|
|
25
|
+
return db.prepare(
|
|
26
|
+
"SELECT * FROM sites WHERE LOWER(REPLACE(domain, 'www.', '')) = ? AND active = 1 LIMIT 1"
|
|
27
|
+
).get(normalized);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getRequestDomain(req) {
|
|
31
|
+
const origin = req.get('origin');
|
|
32
|
+
if (origin) {
|
|
33
|
+
try { return new URL(origin).hostname; } catch (_) {}
|
|
34
|
+
}
|
|
35
|
+
const host = req.get('host');
|
|
36
|
+
if (host) return host.split(':')[0];
|
|
37
|
+
return req.hostname;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseSiteConfig(site) {
|
|
41
|
+
try { return JSON.parse(site.config || '{}'); } catch (_) { return {}; }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function buildDiscoveryDocument(site) {
|
|
45
|
+
const config = parseSiteConfig(site);
|
|
46
|
+
const perms = config.agentPermissions || {};
|
|
47
|
+
const restrictions = config.restrictions || {};
|
|
48
|
+
const features = config.features || {};
|
|
49
|
+
|
|
50
|
+
const enabledActions = Object.entries(perms)
|
|
51
|
+
.filter(([, v]) => v)
|
|
52
|
+
.map(([k]) => k);
|
|
53
|
+
|
|
54
|
+
const featureList = ['auto_discovery', 'noscript_fallback'];
|
|
55
|
+
if (features.advancedAnalytics) featureList.push('advanced_analytics');
|
|
56
|
+
if (features.realTimeUpdates) featureList.push('real_time_updates');
|
|
57
|
+
if (perms.apiAccess) featureList.push('api_access');
|
|
58
|
+
|
|
59
|
+
const dirEntry = db.prepare('SELECT * FROM wab_directory WHERE site_id = ?').get(site.id);
|
|
60
|
+
const neutralityScore = calculateNeutralityScore(site);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
wab_version: WAB_VERSION,
|
|
64
|
+
generated_at: new Date().toISOString(),
|
|
65
|
+
provider: {
|
|
66
|
+
name: site.name,
|
|
67
|
+
domain: site.domain,
|
|
68
|
+
category: (dirEntry && dirEntry.category) || config.category || 'general',
|
|
69
|
+
description: site.description || ''
|
|
70
|
+
},
|
|
71
|
+
capabilities: {
|
|
72
|
+
commands: enabledActions,
|
|
73
|
+
permissions: perms,
|
|
74
|
+
tier: site.tier,
|
|
75
|
+
transport: ['js_global', 'http', 'websocket'],
|
|
76
|
+
features: featureList
|
|
77
|
+
},
|
|
78
|
+
agent_access: {
|
|
79
|
+
bridge_script: '/script/ai-agent-bridge.js',
|
|
80
|
+
api_base: '/api/wab',
|
|
81
|
+
websocket: '/ws/analytics',
|
|
82
|
+
noscript: `/api/noscript/bridge/${site.id}`,
|
|
83
|
+
discovery: `/api/discovery/${site.id}`
|
|
84
|
+
},
|
|
85
|
+
fairness: {
|
|
86
|
+
is_independent: dirEntry ? !!dirEntry.is_independent : false,
|
|
87
|
+
commission_rate: dirEntry ? dirEntry.commission_rate : 0,
|
|
88
|
+
direct_benefit: dirEntry ? (dirEntry.direct_benefit || '') : '',
|
|
89
|
+
neutrality_score: neutralityScore
|
|
90
|
+
},
|
|
91
|
+
security: {
|
|
92
|
+
session_required: true,
|
|
93
|
+
origin_validation: true,
|
|
94
|
+
rate_limit: (restrictions.rateLimit && restrictions.rateLimit.maxCallsPerMinute) || 60,
|
|
95
|
+
sandbox: true
|
|
96
|
+
},
|
|
97
|
+
endpoints: {
|
|
98
|
+
authenticate: '/api/wab/authenticate',
|
|
99
|
+
discover: `/api/wab/discover?siteId=${site.id}`,
|
|
100
|
+
actions: `/api/wab/actions?siteId=${site.id}`,
|
|
101
|
+
execute: '/api/wab/actions/{actionName}',
|
|
102
|
+
read: '/api/wab/read',
|
|
103
|
+
page_info: `/api/wab/page-info?siteId=${site.id}`,
|
|
104
|
+
search: '/api/wab/search',
|
|
105
|
+
ping: '/api/wab/ping',
|
|
106
|
+
token_exchange: '/api/license/token',
|
|
107
|
+
bridge_page: `/api/noscript/bridge/${site.id}`
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
113
|
+
// 1. GET /.well-known/wab.json — Standard discovery location
|
|
114
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
115
|
+
|
|
116
|
+
function buildSelfDiscovery() {
|
|
117
|
+
return {
|
|
118
|
+
wab_version: WAB_VERSION,
|
|
119
|
+
protocol: '1.0',
|
|
120
|
+
generated_at: new Date().toISOString(),
|
|
121
|
+
provider: {
|
|
122
|
+
name: 'Web Agent Bridge',
|
|
123
|
+
domain: 'webagentbridge.com',
|
|
124
|
+
category: 'developer-tools',
|
|
125
|
+
description: 'Open protocol and runtime for AI agent ↔ website interaction. The OpenAPI for human-facing web pages.'
|
|
126
|
+
},
|
|
127
|
+
capabilities: {
|
|
128
|
+
commands: ['read', 'navigate', 'search', 'discover'],
|
|
129
|
+
permissions: { readContent: true, navigate: true, apiAccess: true },
|
|
130
|
+
tier: 'platform',
|
|
131
|
+
transport: ['http', 'javascript', 'websocket'],
|
|
132
|
+
features: [
|
|
133
|
+
'discovery_protocol', 'fairness_engine', 'mcp_adapter',
|
|
134
|
+
'noscript_fallback', 'agent_sdk', 'wordpress_plugin',
|
|
135
|
+
'openapi_spec', 'llms_txt', 'atom_feed'
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
agent_access: {
|
|
139
|
+
bridge_script: '/script/ai-agent-bridge.js',
|
|
140
|
+
api_base: '/api/wab',
|
|
141
|
+
websocket: '/ws/analytics',
|
|
142
|
+
discovery: '/agent-bridge.json',
|
|
143
|
+
llms_txt: '/llms.txt',
|
|
144
|
+
llms_full_txt: '/llms-full.txt',
|
|
145
|
+
openapi: '/openapi.json',
|
|
146
|
+
ai_assets: '/.well-known/ai-assets.json',
|
|
147
|
+
atom_feed: '/feed.xml',
|
|
148
|
+
sitemap: '/sitemap.xml'
|
|
149
|
+
},
|
|
150
|
+
fairness: {
|
|
151
|
+
is_independent: true,
|
|
152
|
+
commission_rate: 0,
|
|
153
|
+
direct_benefit: 'Open-source protocol maintainer',
|
|
154
|
+
neutrality_score: 100
|
|
155
|
+
},
|
|
156
|
+
security: {
|
|
157
|
+
session_required: false,
|
|
158
|
+
origin_validation: true,
|
|
159
|
+
rate_limit: 60,
|
|
160
|
+
sandbox: true
|
|
161
|
+
},
|
|
162
|
+
endpoints: {
|
|
163
|
+
discover: '/api/wab/discover',
|
|
164
|
+
actions: '/api/wab/actions',
|
|
165
|
+
execute: '/api/wab/execute',
|
|
166
|
+
ping: '/api/wab/ping',
|
|
167
|
+
search: '/api/wab/search',
|
|
168
|
+
registry: '/api/discovery/registry',
|
|
169
|
+
plans: '/api/plans',
|
|
170
|
+
page_info: '/api/wab/page-info'
|
|
171
|
+
},
|
|
172
|
+
ecosystem: {
|
|
173
|
+
npm: 'https://www.npmjs.com/package/web-agent-bridge',
|
|
174
|
+
github: 'https://github.com/abokenan444/web-agent-bridge',
|
|
175
|
+
security: 'https://socket.dev/npm/package/web-agent-bridge',
|
|
176
|
+
mcp_adapter: 'https://www.npmjs.com/package/wab-mcp-adapter',
|
|
177
|
+
wordpress: 'https://github.com/abokenan444/web-agent-bridge/tree/master/web-agent-bridge-wordpress',
|
|
178
|
+
specification: 'https://github.com/abokenan444/web-agent-bridge/blob/master/docs/SPEC.md'
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
router.get('/.well-known/wab.json', (req, res) => {
|
|
184
|
+
try {
|
|
185
|
+
const domain = getRequestDomain(req);
|
|
186
|
+
const site = findSiteByDomain(domain);
|
|
187
|
+
|
|
188
|
+
if (!site) {
|
|
189
|
+
if (domain === 'webagentbridge.com' || domain === 'www.webagentbridge.com' || domain === 'localhost') {
|
|
190
|
+
res.set('Cache-Control', 'public, max-age=300');
|
|
191
|
+
res.set('X-WAB-Version', WAB_VERSION);
|
|
192
|
+
return res.json(buildSelfDiscovery());
|
|
193
|
+
}
|
|
194
|
+
return res.status(404).json({
|
|
195
|
+
error: 'No WAB-enabled site found for this domain',
|
|
196
|
+
domain,
|
|
197
|
+
hint: 'Register your site at /dashboard to enable WAB discovery'
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const doc = buildDiscoveryDocument(site);
|
|
202
|
+
res.set('Cache-Control', 'public, max-age=300');
|
|
203
|
+
res.set('X-WAB-Version', WAB_VERSION);
|
|
204
|
+
res.json(doc);
|
|
205
|
+
} catch (err) {
|
|
206
|
+
res.status(500).json({ error: 'Failed to generate discovery document' });
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
211
|
+
// 2. GET /agent-bridge.json — Alternative discovery location
|
|
212
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
213
|
+
|
|
214
|
+
router.get('/agent-bridge.json', (req, res) => {
|
|
215
|
+
try {
|
|
216
|
+
const domain = getRequestDomain(req);
|
|
217
|
+
const site = findSiteByDomain(domain);
|
|
218
|
+
|
|
219
|
+
if (!site) {
|
|
220
|
+
if (domain === 'webagentbridge.com' || domain === 'www.webagentbridge.com' || domain === 'localhost') {
|
|
221
|
+
res.set('Cache-Control', 'public, max-age=300');
|
|
222
|
+
res.set('X-WAB-Version', WAB_VERSION);
|
|
223
|
+
return res.json(buildSelfDiscovery());
|
|
224
|
+
}
|
|
225
|
+
return res.status(404).json({
|
|
226
|
+
error: 'No WAB-enabled site found for this domain',
|
|
227
|
+
domain,
|
|
228
|
+
hint: 'Register your site at /dashboard to enable WAB discovery'
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const doc = buildDiscoveryDocument(site);
|
|
233
|
+
res.set('Cache-Control', 'public, max-age=300');
|
|
234
|
+
res.set('X-WAB-Version', WAB_VERSION);
|
|
235
|
+
res.json(doc);
|
|
236
|
+
} catch (err) {
|
|
237
|
+
res.status(500).json({ error: 'Failed to generate discovery document' });
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
242
|
+
// 3. GET /api/discovery/registry — Public registry with fairness scoring
|
|
243
|
+
// (defined BEFORE :siteId to avoid route shadowing)
|
|
244
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
245
|
+
|
|
246
|
+
router.get('/api/discovery/registry', (req, res) => {
|
|
247
|
+
try {
|
|
248
|
+
const category = req.query.category || 'all';
|
|
249
|
+
const limit = Math.min(parseInt(req.query.limit) || 50, 200);
|
|
250
|
+
const offset = parseInt(req.query.offset) || 0;
|
|
251
|
+
|
|
252
|
+
const listings = getDirectoryListings(category, { limit, offset });
|
|
253
|
+
|
|
254
|
+
const registry = listings.map(entry => ({
|
|
255
|
+
siteId: entry.id,
|
|
256
|
+
name: entry.name,
|
|
257
|
+
domain: entry.domain,
|
|
258
|
+
description: entry.description || '',
|
|
259
|
+
category: entry.category || 'general',
|
|
260
|
+
tier: entry.tier,
|
|
261
|
+
neutrality_score: entry.neutrality_score || 0,
|
|
262
|
+
is_independent: !!entry.is_independent,
|
|
263
|
+
tags: safeParseTags(entry.tags),
|
|
264
|
+
discovery_url: `/api/discovery/${entry.id}`
|
|
265
|
+
}));
|
|
266
|
+
|
|
267
|
+
res.json({
|
|
268
|
+
wab_version: WAB_VERSION,
|
|
269
|
+
total: registry.length,
|
|
270
|
+
category,
|
|
271
|
+
listings: registry
|
|
272
|
+
});
|
|
273
|
+
} catch (err) {
|
|
274
|
+
res.status(500).json({ error: 'Failed to fetch registry' });
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
279
|
+
// 4. POST /api/discovery/register — Register site in WAB directory
|
|
280
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
281
|
+
|
|
282
|
+
router.post('/api/discovery/register', authenticateToken, (req, res) => {
|
|
283
|
+
try {
|
|
284
|
+
const { siteId, category, tags, is_independent, commission_rate, direct_benefit, trust_signature } = req.body;
|
|
285
|
+
|
|
286
|
+
if (!siteId) {
|
|
287
|
+
return res.status(400).json({ error: 'siteId is required' });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const site = findSiteById.get(siteId);
|
|
291
|
+
if (!site) {
|
|
292
|
+
return res.status(404).json({ error: 'Site not found' });
|
|
293
|
+
}
|
|
294
|
+
if (site.user_id !== req.user.id) {
|
|
295
|
+
return res.status(403).json({ error: 'You do not own this site' });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const result = registerInDirectory(siteId, {
|
|
299
|
+
category,
|
|
300
|
+
tags,
|
|
301
|
+
is_independent,
|
|
302
|
+
commission_rate,
|
|
303
|
+
direct_benefit,
|
|
304
|
+
trust_signature
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
if (!result.success) {
|
|
308
|
+
return res.status(400).json({ error: result.error });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const report = generateFairnessReport(siteId);
|
|
312
|
+
|
|
313
|
+
res.status(201).json({
|
|
314
|
+
success: true,
|
|
315
|
+
registration: result,
|
|
316
|
+
fairness_report: report
|
|
317
|
+
});
|
|
318
|
+
} catch (err) {
|
|
319
|
+
res.status(500).json({ error: 'Failed to register site' });
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
324
|
+
// 5. GET /api/discovery/search — Search WAB sites (fairness-weighted)
|
|
325
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
326
|
+
|
|
327
|
+
router.get('/api/discovery/search', (req, res) => {
|
|
328
|
+
try {
|
|
329
|
+
const query = req.query.q || '';
|
|
330
|
+
const category = req.query.category || null;
|
|
331
|
+
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
|
|
332
|
+
|
|
333
|
+
let sql = `
|
|
334
|
+
SELECT s.*, d.category, d.tags, d.is_independent, d.commission_rate,
|
|
335
|
+
d.direct_benefit, d.neutrality_score, d.trust_signature
|
|
336
|
+
FROM wab_directory d
|
|
337
|
+
JOIN sites s ON d.site_id = s.id AND s.active = 1
|
|
338
|
+
WHERE d.listed = 1
|
|
339
|
+
`;
|
|
340
|
+
const params = [];
|
|
341
|
+
|
|
342
|
+
if (category) {
|
|
343
|
+
sql += ' AND d.category = ?';
|
|
344
|
+
params.push(category);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
sql += ' ORDER BY d.neutrality_score DESC LIMIT ?';
|
|
348
|
+
params.push(limit * 3);
|
|
349
|
+
|
|
350
|
+
const candidates = db.prepare(sql).all(...params);
|
|
351
|
+
const results = fairnessWeightedSearch(query, candidates).slice(0, limit);
|
|
352
|
+
|
|
353
|
+
res.json({
|
|
354
|
+
wab_version: WAB_VERSION,
|
|
355
|
+
query,
|
|
356
|
+
total: results.length,
|
|
357
|
+
results: results.map(r => ({
|
|
358
|
+
siteId: r.id,
|
|
359
|
+
name: r.name,
|
|
360
|
+
domain: r.domain,
|
|
361
|
+
description: r.description || '',
|
|
362
|
+
category: r.category || 'general',
|
|
363
|
+
tier: r.tier,
|
|
364
|
+
neutrality_score: r._neutralityScore,
|
|
365
|
+
is_independent: r._isIndependent,
|
|
366
|
+
relevance_score: r._relevance,
|
|
367
|
+
fairness_boost: r._fairnessBoost,
|
|
368
|
+
final_score: r._finalScore,
|
|
369
|
+
tags: safeParseTags(r.tags),
|
|
370
|
+
discovery_url: `/api/discovery/${r.id}`
|
|
371
|
+
}))
|
|
372
|
+
});
|
|
373
|
+
} catch (err) {
|
|
374
|
+
res.status(500).json({ error: 'Search failed' });
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
379
|
+
// 6. GET /api/discovery/:siteId — Discovery doc for a specific site
|
|
380
|
+
// (defined AFTER named routes to prevent shadowing)
|
|
381
|
+
// ═════════════════════════════════════════════════════════════════════
|
|
382
|
+
|
|
383
|
+
router.get('/api/discovery/:siteId', (req, res) => {
|
|
384
|
+
try {
|
|
385
|
+
const site = findSiteById.get(req.params.siteId);
|
|
386
|
+
if (!site || !site.active) {
|
|
387
|
+
return res.status(404).json({ error: 'Site not found' });
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const doc = buildDiscoveryDocument(site);
|
|
391
|
+
res.set('Cache-Control', 'public, max-age=300');
|
|
392
|
+
res.set('X-WAB-Version', WAB_VERSION);
|
|
393
|
+
res.json(doc);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
res.status(500).json({ error: 'Failed to generate discovery document' });
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// ─── Utility ─────────────────────────────────────────────────────────
|
|
400
|
+
|
|
401
|
+
function safeParseTags(tags) {
|
|
402
|
+
if (Array.isArray(tags)) return tags;
|
|
403
|
+
try { return JSON.parse(tags || '[]'); } catch (_) { return []; }
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
module.exports = router;
|