web-agent-bridge 1.0.0 → 1.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.
Files changed (52) hide show
  1. package/README.ar.md +1 -1
  2. package/README.md +336 -36
  3. package/docs/DEPLOY.md +118 -0
  4. package/docs/SPEC.md +1540 -0
  5. package/examples/mcp-agent.js +85 -0
  6. package/examples/vision-agent.js +12 -0
  7. package/package.json +14 -3
  8. package/public/admin/dashboard.html +848 -0
  9. package/public/admin/login.html +84 -0
  10. package/public/cookies.html +208 -0
  11. package/public/css/premium.css +317 -0
  12. package/public/dashboard.html +138 -0
  13. package/public/docs.html +5 -2
  14. package/public/index.html +54 -28
  15. package/public/js/auth-nav.js +31 -0
  16. package/public/js/auth-redirect.js +12 -0
  17. package/public/js/cookie-consent.js +56 -0
  18. package/public/js/ws-client.js +74 -0
  19. package/public/login.html +4 -2
  20. package/public/premium-dashboard.html +2075 -0
  21. package/public/premium.html +791 -0
  22. package/public/privacy.html +295 -0
  23. package/public/register.html +11 -2
  24. package/public/terms.html +254 -0
  25. package/script/ai-agent-bridge.js +253 -22
  26. package/sdk/index.js +36 -0
  27. package/server/config/secrets.js +92 -0
  28. package/server/index.js +100 -26
  29. package/server/middleware/adminAuth.js +30 -0
  30. package/server/middleware/auth.js +4 -7
  31. package/server/middleware/rateLimits.js +24 -0
  32. package/server/migrations/001_add_analytics_indexes.sql +7 -0
  33. package/server/migrations/002_premium_features.sql +418 -0
  34. package/server/models/db.js +360 -4
  35. package/server/routes/admin.js +247 -0
  36. package/server/routes/api.js +26 -9
  37. package/server/routes/billing.js +45 -0
  38. package/server/routes/discovery.js +324 -0
  39. package/server/routes/license.js +200 -11
  40. package/server/routes/noscript.js +543 -0
  41. package/server/routes/premium.js +724 -0
  42. package/server/services/email.js +204 -0
  43. package/server/services/fairness.js +420 -0
  44. package/server/services/premium.js +1680 -0
  45. package/server/services/stripe.js +192 -0
  46. package/server/utils/cache.js +125 -0
  47. package/server/utils/migrate.js +81 -0
  48. package/server/utils/secureFields.js +50 -0
  49. package/server/ws.js +33 -13
  50. package/wab-mcp-adapter/README.md +136 -0
  51. package/wab-mcp-adapter/index.js +528 -0
  52. package/wab-mcp-adapter/package.json +17 -0
package/README.ar.md CHANGED
@@ -276,7 +276,7 @@ docker compose up -d
276
276
 
277
277
  # أو البناء يدوياً
278
278
  docker build -t web-agent-bridge .
279
- docker run -p 3000:3000 -e JWT_SECRET=your-secret web-agent-bridge
279
+ docker run -p 3000:3000 -e JWT_SECRET=your-secret -e JWT_SECRET_ADMIN=your-admin-secret web-agent-bridge
280
280
  ```
281
281
 
282
282
  ---
package/README.md CHANGED
@@ -1,38 +1,117 @@
1
1
  # Web Agent Bridge (WAB)
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/web-agent-bridge)](https://www.npmjs.com/package/web-agent-bridge)
3
4
  [![CI](https://github.com/abokenan444/web-agent-bridge/actions/workflows/ci.yml/badge.svg)](https://github.com/abokenan444/web-agent-bridge/actions/workflows/ci.yml)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org/)
6
7
  [![Docker](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/)
7
8
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
9
+ [![Socket](https://img.shields.io/badge/Socket-Verified-brightgreen.svg)](https://socket.dev/npm/package/web-agent-bridge)
8
10
 
9
- **Open-source middleware that bridges AI agents and websites providing a standardized command interface for intelligent automation.**
11
+ > **robots.txt told bots what NOT to do. WAB tells AI agents what they CAN do.**
10
12
 
11
- **English** | **[العربية](README.ar.md)**
13
+ **English** | **[العربية](README.ar.md)** | **[Protocol Spec](docs/SPEC.md)** | **[Socket Report](https://socket.dev/npm/package/web-agent-bridge)**
12
14
 
13
- WAB gives website owners a script they embed in their pages that exposes a `window.AICommands` interface. AI agents read this interface to discover available actions, execute commands, and interact with sites accurately without parsing raw DOM.
15
+ WAB is an **open protocol + runtime** for AI agents to interact with websites the **OpenAPI for human-facing pages**. It provides a standardized discovery format (`agent-bridge.json`), a command protocol, and a fairness layer that ensures small businesses get equal visibility alongside large platforms.
16
+
17
+ WAB transforms websites from opaque HTML into **agent-readable endpoints** with declared capabilities, permissions, and actions. AI agents discover what a site offers, authenticate, and execute commands through a uniform protocol — no DOM scraping, no guesswork, no bias toward big brands.
18
+
19
+ ### Architecture: Protocol + Runtime + Ecosystem
20
+
21
+ ```
22
+ ┌──────────────────────────────────────────────────────────┐
23
+ │ WAB Protocol (Spec) │
24
+ │ agent-bridge.json · Commands · Lifecycle · Fairness │
25
+ ├────────────┬───────────────────┬─────────────────────────┤
26
+ │ JS Runtime │ HTTP Transport │ MCP Adapter │
27
+ │ AICommands │ REST + WebSocket │ WAB → MCP Tools │
28
+ ├────────────┴───────────────────┴─────────────────────────┤
29
+ │ Discovery Registry + Fairness Engine │
30
+ └──────────────────────────────────────────────────────────┘
31
+ ```
32
+
33
+ ### Three Paths to WAB
34
+
35
+ | Path | For | How |
36
+ |---|---|---|
37
+ | **🏢 Website Owner** | Control how AI interacts with your site | Embed the script, publish `agent-bridge.json` |
38
+ | **🤖 Agent Developer** | Build reliable agents that work on any WAB-enabled site | Use `window.AICommands`, the Agent SDK, or the MCP Adapter |
39
+ | **🔧 Self-Hosting** | Run the full WAB platform for your organization | Clone, deploy, manage licenses & analytics |
40
+ | **🔌 MCP Integration** | Connect WAB to Claude, GPT, or any MCP-compatible agent | Use `wab-mcp-adapter` |
41
+ | **WordPress** | Sites powered by WP | Use the **[Web Agent Bridge WordPress plugin](web-agent-bridge-wordpress/README.md)** |
42
+
43
+ ---
44
+
45
+ ## What's New in v1.1.0
46
+
47
+ - **WAB Protocol Specification v1.0** — Formal protocol spec (`docs/SPEC.md`) with discovery format, command protocol, lifecycle, and fairness layer
48
+ - **Discovery Protocol** — Sites publish `agent-bridge.json` or `/.well-known/wab.json` for agent discovery
49
+ - **MCP Adapter** — `wab-mcp-adapter` converts WAB actions into MCP tools for Claude/GPT integration
50
+ - **Fairness Engine** — Neutrality layer ensures equal visibility for small businesses and independent sites
51
+ - **Discovery Registry** — Public searchable directory of WAB-enabled sites with fairness-weighted results
52
+ - **9 Protocol Commands** — `wab.discover`, `wab.getContext`, `wab.getActions`, `wab.executeAction`, `wab.readContent`, `wab.getPageInfo`, `wab.authenticate`, `wab.subscribe`, `wab.ping`
14
53
 
15
54
  ---
16
55
 
17
56
  ## Features
18
57
 
58
+ ### Protocol Layer
59
+ - **WAB Specification v1.0** — Formal protocol spec defining discovery, commands, lifecycle, and fairness ([docs/SPEC.md](docs/SPEC.md))
60
+ - **Discovery Protocol** — Sites declare capabilities via `agent-bridge.json` or `/.well-known/wab.json`
61
+ - **Command Protocol** — 9 standard methods with request/response format (transport-agnostic)
62
+ - **Lifecycle Protocol** — Discover → Authenticate → Plan → Execute → Confirm
63
+ - **MCP Compatibility** — Full adapter for Model Context Protocol (Claude, GPT, LangChain)
64
+
65
+ ### Fairness & Neutrality
66
+ - **Fairness Engine** — Neutrality scoring ensures small businesses get equal agent visibility
67
+ - **Discovery Registry** — Public directory of WAB-enabled sites with anti-bias ranking
68
+ - **Commission Transparency** — Sites declare commission rates; agents can favor direct providers
69
+ - **Independent Business Priority** — Self-declared independent sites get fairness scoring boost
70
+
71
+ ### Runtime
19
72
  - **Auto-Discovery** — Automatically detects buttons, forms, and navigation on the page
20
73
  - **Permission System** — Granular control over what AI agents can do (click, fill forms, API access, etc.)
21
74
  - **Standardized Interface** — Unified `window.AICommands` object any agent can consume
22
- - **Rate Limiting** — Built-in abuse protection with configurable limits
75
+ - **Self-Healing Selectors** — Resilient element resolution with 7-strategy fuzzy matching for SPAs
76
+ - **Security Sandbox** — Origin validation, session tokens, command signing, audit logging, auto-lockdown
77
+ - **Stealth Mode** — Human-like interaction patterns (requires explicit consent)
78
+ - **NoJS Fallback** — CSS tracking, pixel tracking, and SSR bridge for JavaScript-disabled environments
79
+
80
+ ### Infrastructure
81
+ - **Secure License Exchange** — Embed uses `siteId` + token exchange; keys stay in the dashboard
82
+ - **Rate Limiting** — Multi-dimensional abuse protection (IP + license key + site)
23
83
  - **Analytics Dashboard** — Track how AI agents interact with your site
24
- - **Real-Time Analytics** — WebSocket-based live event streaming for Enterprise users
84
+ - **Real-Time Analytics** — WebSocket-based live event streaming with auto-reconnection
25
85
  - **WebDriver BiDi Compatible** — Standard protocol support via `window.__wab_bidi`
26
86
  - **CDN Versioning** — Serve scripts via versioned URLs (`/v1/ai-agent-bridge.js`, `/latest/ai-agent-bridge.js`)
27
87
  - **Docker Ready** — One-command deployment with Docker Compose
28
- - **Custom Actions** — Register your own actions with custom handlers
29
- - **Subscription Tiers** — Free core + paid premium features (API access, analytics, automated login)
30
- - **Event System** — Subscribe to bridge events for monitoring
31
- - **Security Sandbox** — Origin validation, session tokens, command signing, audit logging, auto-lockdown
32
- - **Self-Healing Selectors** — Resilient element resolution with fuzzy matching for dynamic SPAs
33
- - **Stealth Mode** — Human-like interaction patterns (mouse events, typing delays, natural scrolling)
34
88
  - **Multi-Database** — SQLite (default), PostgreSQL, MySQL via pluggable adapters
35
89
  - **Agent SDK** — Built-in SDK for building AI agents with Puppeteer/Playwright
90
+ - **Admin Dashboard** — User management, tier grants, system analytics
91
+ - **Stripe Integration** — Payment processing with customer portal
92
+
93
+ ---
94
+
95
+ ## Premium Services (webagentbridge.com)
96
+
97
+ The open-source core is free forever. For teams and businesses that need more, **[webagentbridge.com](https://webagentbridge.com/premium)** offers paid add-ons and higher-tier plans:
98
+
99
+ | # | Service | Plans |
100
+ |---|---------|-------|
101
+ | 1 | **Agent Traffic Intelligence** — Deep analytics: agent type, platform, country, behavioral classification, anomaly alerts | Starter+ |
102
+ | 2 | **Advanced Exploit Shield** — Behavioral fingerprint blocking, unauthorized command detection, periodic security reports | Pro+ |
103
+ | 3 | **Pre-built Smart Actions Library** — Ready-made action packs for WooCommerce, Shopify, WordPress, Salesforce with auto-updates | Starter+ |
104
+ | 4 | **Custom AI Agents as a Service** — Visual agent builder, task scheduling, cloud-based execution | Pro+ |
105
+ | 5 | **CRM & Cloud Integrations** — Salesforce, HubSpot, Zoho; export to BigQuery/Snowflake/Datadog; custom webhooks | Pro+ |
106
+ | 6 | **Multi-Tenant Permission Management** — Sub-users, per-user quotas, central control panel for agencies | Enterprise |
107
+ | 7 | **AI-Powered Priority Support** — Smart chatbot, live video sessions, SLA from 15 min (Enterprise) to same-day (Starter) | Starter+ |
108
+ | 8 | **Custom Bridge Script** — Plugin-based custom actions, performance optimization, automatic zero-day patches | Pro+ |
109
+ | 9 | **Stealth Mode Pro** — Customizable human-like behavior profiles, anti-detection bypass, monthly fingerprint updates | Pro+ |
110
+ | 10 | **Private CDN** — Global edge network, custom domain (`bridge.yoursite.com`), geo performance stats | Pro+ |
111
+ | 11 | **Extended Audit Logs & Compliance** — 7-year retention, HIPAA/GDPR/SOC2 settings, signed PDF/CSV exports | Enterprise |
112
+ | 12 | **Virtual Sandbox Environment** — Isolated test environment, simulated agent traffic, before/after benchmarks | Enterprise |
113
+
114
+ Plans: **Free** (open source) → **Starter $9/mo** → **Pro $29/mo** → **Enterprise (custom)**. Visit [webagentbridge.com/premium](https://webagentbridge.com/premium) for details.
36
115
 
37
116
  ---
38
117
 
@@ -62,9 +141,11 @@ Visit `http://localhost:3000/register` and create an account, then add your site
62
141
  ### 3. Add the Script to Your Website
63
142
 
64
143
  ```html
144
+ <!-- Recommended: copy the snippet from your dashboard (uses siteId only) -->
65
145
  <script>
66
146
  window.AIBridgeConfig = {
67
- licenseKey: "WAB-XXXXX-XXXXX-XXXXX-XXXXX",
147
+ siteId: "your-site-uuid-from-dashboard",
148
+ configEndpoint: "https://yourserver.com/api/license/token",
68
149
  agentPermissions: {
69
150
  readContent: true,
70
151
  click: true,
@@ -73,9 +154,11 @@ window.AIBridgeConfig = {
73
154
  }
74
155
  };
75
156
  </script>
76
- <script src="http://localhost:3000/script/ai-agent-bridge.js"></script>
157
+ <script src="https://yourserver.com/script/ai-agent-bridge.js"></script>
77
158
  ```
78
159
 
160
+ The server matches **Origin** to your registered site domain, then returns a short-lived **session token**. Analytics (`/api/license/track`) require that session — not the long-lived license key. Keep the license key in the dashboard only.
161
+
79
162
  ### 4. AI Agents Can Now Interact
80
163
 
81
164
  ```javascript
@@ -88,29 +171,173 @@ const info = bridge.getPageInfo(); // get page metadata
88
171
 
89
172
  ---
90
173
 
174
+ ## Discovery Protocol (`agent-bridge.json`)
175
+
176
+ Any website can declare its WAB capabilities by serving a discovery document at `/agent-bridge.json` or `/.well-known/wab.json`. AI agents fetch this file to understand what a site offers before interacting.
177
+
178
+ ```json
179
+ {
180
+ "wab_version": "1.0",
181
+ "provider": {
182
+ "name": "Local Bookshop",
183
+ "domain": "localbookshop.com",
184
+ "category": "e-commerce",
185
+ "description": "Independent bookshop"
186
+ },
187
+ "capabilities": {
188
+ "commands": ["readContent", "click", "fillForms"],
189
+ "permissions": { "readContent": true, "click": true, "fillForms": true },
190
+ "tier": "starter",
191
+ "transport": ["js_global", "http"]
192
+ },
193
+ "agent_access": {
194
+ "bridge_script": "/script/ai-agent-bridge.js",
195
+ "api_base": "/api/license",
196
+ "selectors": { "search": "#search-input", "cart": ".add-to-cart" }
197
+ },
198
+ "fairness": {
199
+ "is_independent": true,
200
+ "commission_rate": 0,
201
+ "direct_benefit": "Owner is the producer",
202
+ "neutrality_score": 85
203
+ },
204
+ "security": {
205
+ "session_required": true,
206
+ "origin_validation": true,
207
+ "rate_limit": 60,
208
+ "sandbox": true
209
+ }
210
+ }
211
+ ```
212
+
213
+ WAB servers auto-generate this document from each site's configuration. No manual file creation needed — register your site and the discovery endpoint is live.
214
+
215
+ ### Discovery API Endpoints
216
+
217
+ | Endpoint | Method | Description |
218
+ |---|---|---|
219
+ | `/.well-known/wab.json` | GET | Discovery document (domain-matched) |
220
+ | `/agent-bridge.json` | GET | Alternative discovery location |
221
+ | `/api/discovery/:siteId` | GET | Discovery document for a specific site |
222
+ | `/api/discovery/registry` | GET | Public directory of WAB-enabled sites |
223
+ | `/api/discovery/search` | GET | Fairness-weighted site search |
224
+ | `/api/discovery/register` | POST | Register site in directory (authenticated) |
225
+
226
+ ---
227
+
228
+ ## MCP Adapter (Model Context Protocol)
229
+
230
+ The `wab-mcp-adapter` converts WAB capabilities into MCP tools, so Claude, GPT, LangChain, or any MCP-compatible agent can interact with WAB-enabled sites.
231
+
232
+ ```javascript
233
+ const { WABMCPAdapter } = require('web-agent-bridge/wab-mcp-adapter');
234
+
235
+ const adapter = new WABMCPAdapter({
236
+ siteUrl: 'https://example.com',
237
+ transport: 'http'
238
+ });
239
+
240
+ // Discover site capabilities
241
+ const discovery = await adapter.discover();
242
+
243
+ // Get all available MCP tools
244
+ const tools = await adapter.getTools();
245
+ // → [{ name: 'wab_discover', ... }, { name: 'wab_click_signup', ... }, ...]
246
+
247
+ // Execute a tool (just like any MCP tool call)
248
+ const result = await adapter.executeTool('wab_execute_action', {
249
+ name: 'signup',
250
+ data: { email: 'user@test.com' }
251
+ });
252
+ ```
253
+
254
+ ### Built-in MCP Tools
255
+
256
+ | Tool | Description |
257
+ |---|---|
258
+ | `wab_discover` | Discover site capabilities and fairness data |
259
+ | `wab_get_actions` | List all available actions |
260
+ | `wab_execute_action` | Execute any action by name |
261
+ | `wab_read_content` | Read page content by CSS selector |
262
+ | `wab_get_page_info` | Get page metadata and bridge status |
263
+ | `wab_fairness_search` | Search WAB registry with fairness-weighted results |
264
+ | `wab_authenticate` | Authenticate with a WAB site |
265
+
266
+ See [`wab-mcp-adapter/README.md`](wab-mcp-adapter/README.md) for the full API reference.
267
+
268
+ ---
269
+
270
+ ## Fairness Engine
271
+
272
+ WAB includes a **Neutrality Layer** — a fairness engine that prevents AI agents from systematically favoring large platforms over small businesses.
273
+
274
+ ### How It Works
275
+
276
+ 1. **Neutrality Scoring** — Each site gets a score (0-100) based on config quality, trust signatures, and commission transparency — not brand recognition
277
+ 2. **Anti-Bias Ranking** — Search results are fairness-weighted: independent businesses get +15%, transparent commission sites get +10%
278
+ 3. **Position Rotation** — Top results are shuffled to prevent position lock-in
279
+ 4. **Monopoly Prevention** — No single provider can dominate more than 30% of top results
280
+
281
+ ### Register Your Site
282
+
283
+ ```bash
284
+ # Register in the WAB discovery directory
285
+ curl -X POST https://yourserver.com/api/discovery/register \
286
+ -H "Authorization: Bearer YOUR_JWT" \
287
+ -H "Content-Type: application/json" \
288
+ -d '{
289
+ "siteId": "your-site-uuid",
290
+ "category": "e-commerce",
291
+ "is_independent": true,
292
+ "commission_rate": 0,
293
+ "direct_benefit": "Products from local artisans",
294
+ "tags": ["handmade", "local", "organic"]
295
+ }'
296
+ ```
297
+
298
+ ---
299
+
91
300
  ## Project Structure
92
301
 
93
302
  ```
94
303
  web-agent-bridge/
304
+ ├── docs/
305
+ │ └── SPEC.md # WAB Protocol Specification v1.0
95
306
  ├── server/ # Express.js backend
96
307
  │ ├── index.js # Server entry point
97
308
  │ ├── routes/
98
309
  │ │ ├── auth.js # Authentication (register/login)
99
310
  │ │ ├── api.js # Sites, config, analytics API
100
- │ │ └── license.js # License verification & tracking
311
+ │ │ ├── license.js # License verification & token exchange
312
+ │ │ ├── discovery.js # Discovery protocol endpoints
313
+ │ │ ├── noscript.js # NoJS fallback (pixel, CSS, SSR)
314
+ │ │ ├── admin.js # Admin dashboard API
315
+ │ │ └── billing.js # Stripe billing integration
316
+ │ ├── services/
317
+ │ │ └── fairness.js # Fairness engine & neutrality layer
101
318
  │ ├── middleware/
102
319
  │ │ └── auth.js # JWT authentication middleware
103
- └── models/
104
- └── db.js # SQLite database & operations
320
+ ├── models/
321
+ └── db.js # SQLite database & operations
322
+ │ ├── migrations/ # Numbered SQL migrations
323
+ │ └── utils/
324
+ │ ├── cache.js # In-memory cache + analytics queue
325
+ │ └── migrate.js # Migration runner
326
+ ├── wab-mcp-adapter/ # MCP adapter for WAB → Claude/GPT
327
+ │ ├── index.js # WABMCPAdapter class
328
+ │ ├── package.json
329
+ │ └── README.md
105
330
  ├── public/ # Frontend
106
331
  │ ├── index.html # Landing page
107
332
  │ ├── dashboard.html # Management dashboard
108
333
  │ ├── docs.html # Documentation
109
- │ ├── login.html # Sign in
110
- │ ├── register.html # Sign up
334
+ │ ├── admin/ # Admin panel
335
+ │ ├── js/ # Client-side utilities
111
336
  │ └── css/styles.css # Design system
112
337
  ├── script/
113
338
  │ └── ai-agent-bridge.js # The bridge script (embed in websites)
339
+ ├── examples/ # Agent examples (Puppeteer, BiDi, MCP, Vision)
340
+ ├── sdk/ # Agent SDK for Puppeteer/Playwright
114
341
  ├── .env # Environment variables
115
342
  └── package.json
116
343
  ```
@@ -141,8 +368,20 @@ web-agent-bridge/
141
368
  ### License (Public)
142
369
  | Endpoint | Method | Description |
143
370
  |---|---|---|
144
- | `/api/license/verify` | POST | Verify license key for domain |
145
- | `/api/license/track` | POST | Record analytics event |
371
+ | `/api/license/verify` | POST | Verify license key for domain (cached) |
372
+ | `/api/license/token` | POST | Exchange `siteId` (Origin must match domain) or `licenseKey` for session token |
373
+ | `/api/license/session` | POST | Validate session token (domain-locked) |
374
+ | `/api/license/track` | POST | Record analytics (`sessionToken` + Origin; legacy `licenseKey` only if `ALLOW_LEGACY_LICENSE_TRACK`) |
375
+
376
+ ### Discovery Protocol (Public)
377
+ | Endpoint | Method | Description |
378
+ |---|---|---|
379
+ | `/.well-known/wab.json` | GET | Discovery document for the requesting domain |
380
+ | `/agent-bridge.json` | GET | Alternative discovery location |
381
+ | `/api/discovery/:siteId` | GET | Discovery document for a specific site |
382
+ | `/api/discovery/registry` | GET | Public directory of WAB-enabled sites |
383
+ | `/api/discovery/search?q=&category=` | GET | Fairness-weighted site search |
384
+ | `/api/discovery/register` | POST | Register site in directory (authenticated) |
146
385
 
147
386
  ---
148
387
 
@@ -152,18 +391,22 @@ Once loaded, `window.AICommands` exposes:
152
391
 
153
392
  | Method | Description |
154
393
  |---|---|
394
+ | `discover()` | Get full discovery document with protocol info and fairness data |
395
+ | `ping()` | Health check — returns version, protocol, ready state |
155
396
  | `getActions(category?)` | List available actions |
156
397
  | `getAction(name)` | Get a specific action |
157
398
  | `execute(name, params?)` | Execute an action |
158
399
  | `readContent(selector)` | Read element content |
159
400
  | `getPageInfo()` | Get page and bridge metadata |
401
+ | `subscribe(event, callback)` | Subscribe to events with subscription ID |
402
+ | `unsubscribe(subscriptionId)` | Unsubscribe from events |
160
403
  | `waitForElement(selector, timeout?)` | Wait for DOM element |
161
404
  | `waitForNavigation(timeout?)` | Wait for URL change |
162
405
  | `registerAction(def)` | Register a custom action |
163
406
  | `authenticate(key, meta?)` | Authenticate an agent |
164
407
  | `refresh()` | Re-scan the page |
165
408
  | `onReady(callback)` | Callback when bridge is ready |
166
- | `events.on(event, cb)` | Subscribe to events |
409
+ | `events.on(event, cb)` | Subscribe to raw events |
167
410
 
168
411
  ---
169
412
 
@@ -171,7 +414,13 @@ Once loaded, `window.AICommands` exposes:
171
414
 
172
415
  ```javascript
173
416
  window.AIBridgeConfig = {
174
- licenseKey: "WAB-XXXXX-XXXXX-XXXXX-XXXXX",
417
+ // Recommended — copy siteId from dashboard snippet (no license key in HTML)
418
+ siteId: "uuid-from-dashboard",
419
+ configEndpoint: "/api/license/token",
420
+
421
+ // Legacy: token exchange via license key (avoid embedding in public pages)
422
+ // licenseKey: "WAB-...",
423
+
175
424
  agentPermissions: {
176
425
  readContent: true, // Read page text
177
426
  click: true, // Click elements
@@ -213,12 +462,19 @@ window.AIBridgeConfig = {
213
462
 
214
463
  ## Tech Stack
215
464
 
465
+ - **Protocol**: WAB Specification v1.0 with RFC 2119 conformance levels
216
466
  - **Backend**: Node.js + Express + WebSocket (ws)
217
- - **Database**: SQLite (via better-sqlite3)
218
- - **Auth**: JWT + bcrypt
467
+ - **Database**: SQLite (via better-sqlite3) with migration runner
468
+ - **Auth**: JWT + bcrypt + session tokens (domain-locked)
469
+ - **MCP**: WAB-to-MCP adapter for Claude, GPT, LangChain integration
470
+ - **Fairness**: Neutrality engine with anti-bias ranking and monopoly prevention
471
+ - **Discovery**: Auto-generated `agent-bridge.json` + public registry
472
+ - **Caching**: In-memory TTL cache + batched analytics queue
473
+ - **Payments**: Stripe integration with billing portal
219
474
  - **Frontend**: Vanilla HTML/CSS/JS (no framework dependencies)
220
- - **Security**: Helmet, CORS, CSP, rate limiting
475
+ - **Security**: Helmet, CORS, CSP, multi-layer rate limiting, sandbox
221
476
  - **Containers**: Docker + Docker Compose
477
+ - **CI/CD**: GitHub Actions (test + auto-publish to npm)
222
478
  - **Testing**: Jest + Supertest
223
479
 
224
480
  ---
@@ -239,16 +495,28 @@ const result = await window.__wab_bidi.send({
239
495
  });
240
496
 
241
497
  // Supported methods:
242
- // wab.getContext, wab.getActions, wab.executeAction, wab.readContent, wab.getPageInfo
498
+ // wab.discover, wab.getContext, wab.getActions, wab.executeAction,
499
+ // wab.readContent, wab.getPageInfo, wab.authenticate, wab.subscribe, wab.ping
243
500
  ```
244
501
 
245
502
  ---
246
503
 
247
504
  ## Real-Time Analytics (WebSocket)
248
505
 
249
- Connect to `ws://localhost:3000/ws/analytics` for live analytics:
506
+ Connect to `ws://localhost:3000/ws/analytics` for live analytics. Use the built-in `WABWebSocket` client for automatic reconnection with exponential backoff:
507
+
508
+ ```javascript
509
+ // Recommended: use the auto-reconnecting client
510
+ import { WABWebSocket } from './js/ws-client.js';
511
+
512
+ const ws = new WABWebSocket('jwt-token', 'site-id');
513
+ ws.on('analytic', (data) => console.log(data));
514
+ ws.on('reconnecting', ({ attempt, delay }) => console.log(`Reconnecting #${attempt}...`));
515
+ ws.connect();
516
+ ```
250
517
 
251
518
  ```javascript
519
+ // Or connect manually
252
520
  const ws = new WebSocket('ws://localhost:3000/ws/analytics');
253
521
  ws.onopen = () => ws.send(JSON.stringify({ type: 'auth', token: 'jwt-token', siteId: 'site-id' }));
254
522
  ws.onmessage = (e) => console.log(JSON.parse(e.data));
@@ -321,7 +589,7 @@ docker compose up -d
321
589
 
322
590
  # Or build manually
323
591
  docker build -t web-agent-bridge .
324
- docker run -p 3000:3000 -e JWT_SECRET=your-secret web-agent-bridge
592
+ docker run -p 3000:3000 -e JWT_SECRET=your-secret -e JWT_SECRET_ADMIN=your-admin-secret web-agent-bridge
325
593
  ```
326
594
 
327
595
  ---
@@ -364,11 +632,13 @@ Ready-to-run agent examples in the [`examples/`](examples/) directory:
364
632
  |---|---|
365
633
  | `puppeteer-agent.js` | Basic agent using Puppeteer + `window.AICommands` |
366
634
  | `bidi-agent.js` | Agent using WebDriver BiDi protocol via `window.__wab_bidi` |
367
- | `vision-agent.js` | Vision/NLP agentresolves natural language intents to actions |
635
+ | `mcp-agent.js` | MCP adapter demo WAB actions as MCP tools for Claude/GPT |
636
+ | `vision-agent.js` | Vision/NLP agent — resolves natural language intents to actions using a local keyword-based resolver (no external API) |
368
637
 
369
638
  ```bash
370
639
  node examples/puppeteer-agent.js http://localhost:3000
371
640
  node examples/bidi-agent.js http://localhost:3000
641
+ node examples/mcp-agent.js http://localhost:3000
372
642
  node examples/vision-agent.js http://localhost:3000
373
643
  ```
374
644
 
@@ -409,6 +679,23 @@ See [`server/models/adapters/`](server/models/adapters/) for adapter implementat
409
679
 
410
680
  WAB implements defense-in-depth to protect the bridge from misuse:
411
681
 
682
+ ### Secure License Exchange
683
+
684
+ 1. **Dashboard snippet (recommended):** `siteId` + `configEndpoint`. The browser sends `POST /api/license/token` with `{ siteId }`; the server checks **Origin** against the site’s registered domain and issues a session token.
685
+ 2. **Legacy:** `licenseKey` + `configEndpoint` (or deprecated `_licenseKey`) still works for token exchange but should not be embedded in public HTML.
686
+ 3. **Session** is domain-locked (1h TTL); **analytics** use `sessionToken` on `POST /api/license/track` (not the license key).
687
+ 4. **WebSocket** `/ws/analytics`: user JWT must **own** the `siteId`; admin JWT may observe any site.
688
+
689
+ ```
690
+ Client Server
691
+ │── POST /api/license/token ──→│ { siteId } + Origin header
692
+ │ │ domain match → sessionToken
693
+ │←── { sessionToken, tier } ──│
694
+ │── POST /api/license/track ─→│ { sessionToken, actionName } + Origin
695
+ ```
696
+
697
+ **Production:** set `JWT_SECRET`, `JWT_SECRET_ADMIN`, `STRIPE_WEBHOOK_SECRET`, `ALLOWED_ORIGINS`, and create the first admin via `BOOTSTRAP_ADMIN_*` or `node scripts/create-admin.js`.
698
+
412
699
  ### Security Sandbox
413
700
 
414
701
  Every bridge instance runs inside a `SecuritySandbox` that provides:
@@ -487,14 +774,19 @@ Add `data-wab-id` attributes to critical elements for maximum stability:
487
774
 
488
775
  ## Stealth Mode
489
776
 
490
- For sites with anti-bot protection, WAB can simulate human-like interaction patterns:
777
+ For sites with anti-bot protection, WAB can simulate human-like interaction patterns. **Stealth mode requires explicit consent** to ensure ethical use.
491
778
 
492
779
  ```javascript
493
780
  window.AIBridgeConfig = {
494
- stealth: { enabled: true }
781
+ stealth: {
782
+ enabled: true,
783
+ consent: true // Required — confirms site owner authorizes human-like patterns
784
+ }
495
785
  };
496
786
  ```
497
787
 
788
+ > **⚠️ Ethical Use Policy:** Stealth mode is designed for accessibility and testing on your own websites. Using it to bypass security controls on sites you do not own may violate terms of service and applicable laws.
789
+
498
790
  When enabled, all interactions use:
499
791
 
500
792
  | Feature | Description |
@@ -505,8 +797,8 @@ When enabled, all interactions use:
505
797
  | **Random delays** | 50-400ms natural pauses between actions |
506
798
 
507
799
  ```javascript
508
- // Enable/disable at runtime
509
- bridge.stealth.enable();
800
+ // Enable/disable at runtime (consent required)
801
+ bridge.stealth.enable(true); // true = consent granted
510
802
  bridge.stealth.disable();
511
803
  ```
512
804
 
@@ -529,14 +821,22 @@ npx web-agent-bridge init
529
821
 
530
822
  ## Environment Variables
531
823
 
824
+ See `.env.example`. Important:
825
+
532
826
  ```
533
827
  PORT=3000
534
- JWT_SECRET=your-secret-here
535
828
  NODE_ENV=development
536
- DB_ADAPTER=sqlite # sqlite | postgresql | mysql
537
- DATABASE_URL= # Required for postgresql/mysql
829
+ JWT_SECRET=long-random-user-signing-secret
830
+ JWT_SECRET_ADMIN=long-random-admin-signing-secret # required in production
831
+ ALLOWED_ORIGINS=http://localhost:3000,https://your-app.com
832
+ STRIPE_WEBHOOK_SECRET=whsec_... # Stripe webhook verify
833
+ CREDENTIALS_ENCRYPTION_KEY=... # optional SMTP password encryption
834
+ DB_ADAPTER=sqlite
835
+ DATABASE_URL=
538
836
  ```
539
837
 
838
+ First admin: set `BOOTSTRAP_ADMIN_EMAIL` / `BOOTSTRAP_ADMIN_PASSWORD` when the `admins` table is empty, or run `node scripts/create-admin.js <email> <password>`.
839
+
540
840
  ---
541
841
 
542
842
  ## License