web-agent-bridge 1.1.1 → 1.1.2

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 (66) hide show
  1. package/LICENSE +21 -21
  2. package/README.ar.md +446 -446
  3. package/README.md +844 -844
  4. package/bin/cli.js +80 -80
  5. package/bin/wab.js +80 -80
  6. package/docs/DEPLOY.md +118 -118
  7. package/docs/SPEC.md +1540 -1540
  8. package/examples/bidi-agent.js +119 -119
  9. package/examples/mcp-agent.js +94 -94
  10. package/examples/puppeteer-agent.js +108 -108
  11. package/examples/vision-agent.js +171 -171
  12. package/package.json +78 -78
  13. package/public/admin/dashboard.html +848 -848
  14. package/public/admin/login.html +84 -84
  15. package/public/cookies.html +208 -208
  16. package/public/css/styles.css +1235 -1235
  17. package/public/dashboard.html +704 -704
  18. package/public/docs.html +585 -585
  19. package/public/index.html +332 -332
  20. package/public/js/auth-nav.js +31 -31
  21. package/public/js/auth-redirect.js +12 -12
  22. package/public/js/cookie-consent.js +56 -56
  23. package/public/js/ws-client.js +74 -74
  24. package/public/login.html +83 -83
  25. package/public/privacy.html +295 -295
  26. package/public/register.html +103 -103
  27. package/public/terms.html +254 -254
  28. package/script/ai-agent-bridge.js +1513 -1513
  29. package/sdk/README.md +55 -55
  30. package/sdk/index.js +203 -203
  31. package/sdk/package.json +14 -14
  32. package/server/config/secrets.js +92 -92
  33. package/server/index.js +181 -181
  34. package/server/middleware/adminAuth.js +30 -30
  35. package/server/middleware/auth.js +41 -41
  36. package/server/middleware/rateLimits.js +24 -24
  37. package/server/migrations/001_add_analytics_indexes.sql +7 -7
  38. package/server/models/adapters/index.js +33 -33
  39. package/server/models/adapters/mysql.js +183 -183
  40. package/server/models/adapters/postgresql.js +172 -172
  41. package/server/models/adapters/sqlite.js +7 -7
  42. package/server/models/db.js +561 -561
  43. package/server/routes/admin.js +247 -247
  44. package/server/routes/api.js +138 -138
  45. package/server/routes/auth.js +51 -51
  46. package/server/routes/billing.js +45 -45
  47. package/server/routes/discovery.js +329 -329
  48. package/server/routes/license.js +240 -240
  49. package/server/routes/noscript.js +543 -543
  50. package/server/routes/wab-api.js +476 -476
  51. package/server/services/email.js +204 -204
  52. package/server/services/fairness.js +420 -420
  53. package/server/services/stripe.js +192 -192
  54. package/server/utils/cache.js +125 -125
  55. package/server/utils/migrate.js +81 -81
  56. package/server/utils/secureFields.js +50 -50
  57. package/server/ws.js +101 -101
  58. package/wab-mcp-adapter/README.md +136 -136
  59. package/wab-mcp-adapter/index.js +555 -555
  60. package/wab-mcp-adapter/package.json +17 -17
  61. package/public/css/premium.css +0 -317
  62. package/public/premium-dashboard.html +0 -2075
  63. package/public/premium.html +0 -791
  64. package/server/migrations/002_premium_features.sql +0 -418
  65. package/server/routes/premium.js +0 -724
  66. package/server/services/premium.js +0 -1680
@@ -1,136 +1,136 @@
1
- # WAB-MCP Adapter
2
-
3
- **MCP adapter for Web Agent Bridge** — exposes every capability of a WAB-enabled website as a set of [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) tools so that any MCP-compatible AI agent (Claude, GPT, Gemini, open-source LLMs, etc.) can discover, read, and interact with the site through a single, standardised interface.
4
-
5
- ## Quick Start
6
-
7
- ```js
8
- const { WABMCPAdapter } = require('wab-mcp-adapter');
9
-
10
- const adapter = new WABMCPAdapter({
11
- siteUrl: 'https://example.com',
12
- transport: 'http', // 'http' | 'websocket' | 'direct'
13
- apiKey: 'sk-optional', // optional API key
14
- });
15
-
16
- // 1. Discover site capabilities
17
- const doc = await adapter.discover();
18
-
19
- // 2. Get MCP tool definitions for the AI agent
20
- const tools = await adapter.getTools();
21
-
22
- // 3. Execute a tool call
23
- const result = await adapter.executeTool('wab_execute_action', {
24
- name: 'signup',
25
- params: { email: 'user@example.com' },
26
- });
27
-
28
- // 4. Clean up
29
- adapter.close();
30
- ```
31
-
32
- ## API Reference
33
-
34
- ### `new WABMCPAdapter(options)`
35
-
36
- | Option | Type | Default | Description |
37
- |---|---|---|---|
38
- | `siteUrl` | `string` | — | Target WAB site URL (required for `http` transport) |
39
- | `siteId` | `string` | `null` | WAB site identifier |
40
- | `apiKey` | `string` | `null` | API key for authenticated requests |
41
- | `transport` | `string` | `'http'` | Transport type: `http`, `websocket`, or `direct` |
42
- | `registryUrl` | `string` | `https://webagentbridge.com` | WAB fairness registry URL |
43
- | `page` | `object` | — | Puppeteer/Playwright page (required for `direct`) |
44
- | `wsUrl` | `string` | auto | WebSocket URL (required for `websocket` if no `siteUrl`) |
45
- | `timeout` | `number` | `15000` | Request timeout in milliseconds |
46
-
47
- ### Methods
48
-
49
- | Method | Returns | Description |
50
- |---|---|---|
51
- | `discover(url?)` | `Promise<object>` | Fetch the WAB discovery document |
52
- | `getTools()` | `Promise<object[]>` | Return MCP tool definitions (built-in + site-specific) |
53
- | `executeTool(name, input)` | `Promise<object>` | Execute an MCP tool call |
54
- | `close()` | `void` | Release transport resources |
55
-
56
- ## Built-in Tools
57
-
58
- These tools are always available, regardless of which site actions are discovered:
59
-
60
- | Tool | Description |
61
- |---|---|
62
- | `wab_discover` | Fetch the WAB discovery document from a site |
63
- | `wab_get_actions` | List available actions, optionally filtered by category |
64
- | `wab_execute_action` | Execute any WAB action by name and params |
65
- | `wab_read_content` | Read page element text by CSS selector |
66
- | `wab_get_page_info` | Return page metadata and bridge configuration |
67
- | `wab_fairness_search` | Search the WAB registry with fairness-weighted results |
68
- | `wab_authenticate` | Authenticate with the site using an API key |
69
-
70
- Site-specific actions are exposed as additional tools named `wab_<action_name>` and are generated automatically from the discovery document.
71
-
72
- ## Transport Options
73
-
74
- | Transport | When to use | Requirements |
75
- |---|---|---|
76
- | **http** | Server-to-server or CLI tools calling a WAB site over REST | `siteUrl` |
77
- | **websocket** | Real-time bidirectional communication with low latency | `wsUrl` or `siteUrl` |
78
- | **direct** | In-browser automation with Puppeteer/Playwright | `page` object |
79
-
80
- ## Fairness Protocol
81
-
82
- The WAB discovery registry uses a **fairness-weighted ranking** algorithm that prevents large, high-traffic sites from monopolising search results. When you call `wab_fairness_search`, the registry applies:
83
-
84
- - **Inverse-popularity weighting** — smaller sites receive a ranking boost.
85
- - **Recency bonus** — newly registered or recently updated sites surface sooner.
86
- - **Category balancing** — results are distributed across categories to avoid domination by a single vertical.
87
-
88
- This ensures a level playing field so every WAB-enabled site has equitable visibility to AI agents.
89
-
90
- ## Integration with Claude / MCP
91
-
92
- Pass the tools returned by `getTools()` as the `tools` parameter when calling the Anthropic Messages API and route any `tool_use` blocks back through `executeTool`:
93
-
94
- ```js
95
- const Anthropic = require('@anthropic-ai/sdk');
96
- const { WABMCPAdapter } = require('wab-mcp-adapter');
97
-
98
- const client = new Anthropic();
99
- const adapter = new WABMCPAdapter({ siteUrl: 'https://shop.example.com' });
100
- const tools = await adapter.getTools();
101
-
102
- let messages = [{ role: 'user', content: 'Find the signup form and register me.' }];
103
-
104
- while (true) {
105
- const res = await client.messages.create({
106
- model: 'claude-sonnet-4-20250514',
107
- max_tokens: 1024,
108
- tools,
109
- messages,
110
- });
111
-
112
- if (res.stop_reason === 'end_turn') break;
113
-
114
- const toolBlocks = res.content.filter((b) => b.type === 'tool_use');
115
- if (!toolBlocks.length) break;
116
-
117
- messages.push({ role: 'assistant', content: res.content });
118
-
119
- const toolResults = [];
120
- for (const block of toolBlocks) {
121
- const result = await adapter.executeTool(block.name, block.input);
122
- toolResults.push({
123
- type: 'tool_result',
124
- tool_use_id: block.id,
125
- content: JSON.stringify(result.content),
126
- });
127
- }
128
- messages.push({ role: 'user', content: toolResults });
129
- }
130
-
131
- adapter.close();
132
- ```
133
-
134
- ## License
135
-
136
- MIT — see [LICENSE](../LICENSE).
1
+ # WAB-MCP Adapter
2
+
3
+ **MCP adapter for Web Agent Bridge** — exposes every capability of a WAB-enabled website as a set of [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) tools so that any MCP-compatible AI agent (Claude, GPT, Gemini, open-source LLMs, etc.) can discover, read, and interact with the site through a single, standardised interface.
4
+
5
+ ## Quick Start
6
+
7
+ ```js
8
+ const { WABMCPAdapter } = require('wab-mcp-adapter');
9
+
10
+ const adapter = new WABMCPAdapter({
11
+ siteUrl: 'https://example.com',
12
+ transport: 'http', // 'http' | 'websocket' | 'direct'
13
+ apiKey: 'sk-optional', // optional API key
14
+ });
15
+
16
+ // 1. Discover site capabilities
17
+ const doc = await adapter.discover();
18
+
19
+ // 2. Get MCP tool definitions for the AI agent
20
+ const tools = await adapter.getTools();
21
+
22
+ // 3. Execute a tool call
23
+ const result = await adapter.executeTool('wab_execute_action', {
24
+ name: 'signup',
25
+ params: { email: 'user@example.com' },
26
+ });
27
+
28
+ // 4. Clean up
29
+ adapter.close();
30
+ ```
31
+
32
+ ## API Reference
33
+
34
+ ### `new WABMCPAdapter(options)`
35
+
36
+ | Option | Type | Default | Description |
37
+ |---|---|---|---|
38
+ | `siteUrl` | `string` | — | Target WAB site URL (required for `http` transport) |
39
+ | `siteId` | `string` | `null` | WAB site identifier |
40
+ | `apiKey` | `string` | `null` | API key for authenticated requests |
41
+ | `transport` | `string` | `'http'` | Transport type: `http`, `websocket`, or `direct` |
42
+ | `registryUrl` | `string` | `https://webagentbridge.com` | WAB fairness registry URL |
43
+ | `page` | `object` | — | Puppeteer/Playwright page (required for `direct`) |
44
+ | `wsUrl` | `string` | auto | WebSocket URL (required for `websocket` if no `siteUrl`) |
45
+ | `timeout` | `number` | `15000` | Request timeout in milliseconds |
46
+
47
+ ### Methods
48
+
49
+ | Method | Returns | Description |
50
+ |---|---|---|
51
+ | `discover(url?)` | `Promise<object>` | Fetch the WAB discovery document |
52
+ | `getTools()` | `Promise<object[]>` | Return MCP tool definitions (built-in + site-specific) |
53
+ | `executeTool(name, input)` | `Promise<object>` | Execute an MCP tool call |
54
+ | `close()` | `void` | Release transport resources |
55
+
56
+ ## Built-in Tools
57
+
58
+ These tools are always available, regardless of which site actions are discovered:
59
+
60
+ | Tool | Description |
61
+ |---|---|
62
+ | `wab_discover` | Fetch the WAB discovery document from a site |
63
+ | `wab_get_actions` | List available actions, optionally filtered by category |
64
+ | `wab_execute_action` | Execute any WAB action by name and params |
65
+ | `wab_read_content` | Read page element text by CSS selector |
66
+ | `wab_get_page_info` | Return page metadata and bridge configuration |
67
+ | `wab_fairness_search` | Search the WAB registry with fairness-weighted results |
68
+ | `wab_authenticate` | Authenticate with the site using an API key |
69
+
70
+ Site-specific actions are exposed as additional tools named `wab_<action_name>` and are generated automatically from the discovery document.
71
+
72
+ ## Transport Options
73
+
74
+ | Transport | When to use | Requirements |
75
+ |---|---|---|
76
+ | **http** | Server-to-server or CLI tools calling a WAB site over REST | `siteUrl` |
77
+ | **websocket** | Real-time bidirectional communication with low latency | `wsUrl` or `siteUrl` |
78
+ | **direct** | In-browser automation with Puppeteer/Playwright | `page` object |
79
+
80
+ ## Fairness Protocol
81
+
82
+ The WAB discovery registry uses a **fairness-weighted ranking** algorithm that prevents large, high-traffic sites from monopolising search results. When you call `wab_fairness_search`, the registry applies:
83
+
84
+ - **Inverse-popularity weighting** — smaller sites receive a ranking boost.
85
+ - **Recency bonus** — newly registered or recently updated sites surface sooner.
86
+ - **Category balancing** — results are distributed across categories to avoid domination by a single vertical.
87
+
88
+ This ensures a level playing field so every WAB-enabled site has equitable visibility to AI agents.
89
+
90
+ ## Integration with Claude / MCP
91
+
92
+ Pass the tools returned by `getTools()` as the `tools` parameter when calling the Anthropic Messages API and route any `tool_use` blocks back through `executeTool`:
93
+
94
+ ```js
95
+ const Anthropic = require('@anthropic-ai/sdk');
96
+ const { WABMCPAdapter } = require('wab-mcp-adapter');
97
+
98
+ const client = new Anthropic();
99
+ const adapter = new WABMCPAdapter({ siteUrl: 'https://shop.example.com' });
100
+ const tools = await adapter.getTools();
101
+
102
+ let messages = [{ role: 'user', content: 'Find the signup form and register me.' }];
103
+
104
+ while (true) {
105
+ const res = await client.messages.create({
106
+ model: 'claude-sonnet-4-20250514',
107
+ max_tokens: 1024,
108
+ tools,
109
+ messages,
110
+ });
111
+
112
+ if (res.stop_reason === 'end_turn') break;
113
+
114
+ const toolBlocks = res.content.filter((b) => b.type === 'tool_use');
115
+ if (!toolBlocks.length) break;
116
+
117
+ messages.push({ role: 'assistant', content: res.content });
118
+
119
+ const toolResults = [];
120
+ for (const block of toolBlocks) {
121
+ const result = await adapter.executeTool(block.name, block.input);
122
+ toolResults.push({
123
+ type: 'tool_result',
124
+ tool_use_id: block.id,
125
+ content: JSON.stringify(result.content),
126
+ });
127
+ }
128
+ messages.push({ role: 'user', content: toolResults });
129
+ }
130
+
131
+ adapter.close();
132
+ ```
133
+
134
+ ## License
135
+
136
+ MIT — see [LICENSE](../LICENSE).