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
package/sdk/README.md CHANGED
@@ -1,55 +1,55 @@
1
- # WAB Agent SDK
2
-
3
- SDK for building AI agents that interact with [Web Agent Bridge](https://github.com/abokenan444/web-agent-bridge).
4
-
5
- ## Quick Start
6
-
7
- ```javascript
8
- const puppeteer = require('puppeteer');
9
- const { WABAgent } = require('web-agent-bridge/sdk');
10
-
11
- const browser = await puppeteer.launch();
12
- const page = await browser.newPage();
13
-
14
- const agent = new WABAgent(page);
15
- await agent.navigateAndWait('https://example.com');
16
-
17
- // Discover available actions
18
- const actions = await agent.getActions();
19
- console.log(actions);
20
-
21
- // Execute an action
22
- const result = await agent.execute('signup', { email: 'user@example.com' });
23
-
24
- // Read page content
25
- const content = await agent.readContent('h1');
26
-
27
- await browser.close();
28
- ```
29
-
30
- ## BiDi Mode
31
-
32
- ```javascript
33
- const agent = new WABAgent(page, { useBiDi: true });
34
- await agent.waitForBridge();
35
-
36
- const context = await agent.getBiDiContext();
37
- const actions = await agent.getActions();
38
- await agent.execute('click-login');
39
- ```
40
-
41
- ## API
42
-
43
- | Method | Description |
44
- |---|---|
45
- | `waitForBridge()` | Wait for WAB to load on the page |
46
- | `hasBridge()` | Check if WAB is available |
47
- | `getActions(category?)` | List available actions |
48
- | `getAction(name)` | Get a specific action |
49
- | `execute(name, params?)` | Execute an action |
50
- | `readContent(selector)` | Read element text content |
51
- | `getPageInfo()` | Get page metadata |
52
- | `authenticate(apiKey, meta?)` | Authenticate the agent |
53
- | `navigateAndWait(url)` | Navigate and wait for bridge |
54
- | `executeSteps(steps)` | Execute multiple actions in sequence |
55
- | `getBiDiContext()` | Get BiDi context (BiDi mode only) |
1
+ # WAB Agent SDK
2
+
3
+ SDK for building AI agents that interact with [Web Agent Bridge](https://github.com/abokenan444/web-agent-bridge).
4
+
5
+ ## Quick Start
6
+
7
+ ```javascript
8
+ const puppeteer = require('puppeteer');
9
+ const { WABAgent } = require('web-agent-bridge/sdk');
10
+
11
+ const browser = await puppeteer.launch();
12
+ const page = await browser.newPage();
13
+
14
+ const agent = new WABAgent(page);
15
+ await agent.navigateAndWait('https://example.com');
16
+
17
+ // Discover available actions
18
+ const actions = await agent.getActions();
19
+ console.log(actions);
20
+
21
+ // Execute an action
22
+ const result = await agent.execute('signup', { email: 'user@example.com' });
23
+
24
+ // Read page content
25
+ const content = await agent.readContent('h1');
26
+
27
+ await browser.close();
28
+ ```
29
+
30
+ ## BiDi Mode
31
+
32
+ ```javascript
33
+ const agent = new WABAgent(page, { useBiDi: true });
34
+ await agent.waitForBridge();
35
+
36
+ const context = await agent.getBiDiContext();
37
+ const actions = await agent.getActions();
38
+ await agent.execute('click-login');
39
+ ```
40
+
41
+ ## API
42
+
43
+ | Method | Description |
44
+ |---|---|
45
+ | `waitForBridge()` | Wait for WAB to load on the page |
46
+ | `hasBridge()` | Check if WAB is available |
47
+ | `getActions(category?)` | List available actions |
48
+ | `getAction(name)` | Get a specific action |
49
+ | `execute(name, params?)` | Execute an action |
50
+ | `readContent(selector)` | Read element text content |
51
+ | `getPageInfo()` | Get page metadata |
52
+ | `authenticate(apiKey, meta?)` | Authenticate the agent |
53
+ | `navigateAndWait(url)` | Navigate and wait for bridge |
54
+ | `executeSteps(steps)` | Execute multiple actions in sequence |
55
+ | `getBiDiContext()` | Get BiDi context (BiDi mode only) |
package/sdk/index.js CHANGED
@@ -1,203 +1,203 @@
1
- /**
2
- * WAB Agent SDK
3
- *
4
- * Helpers for building AI agents that interact with Web Agent Bridge.
5
- * Works with Puppeteer, Playwright, or any browser automation tool.
6
- *
7
- * Usage:
8
- * const { WABAgent } = require('./sdk');
9
- * const agent = new WABAgent(page);
10
- * await agent.waitForBridge();
11
- * const actions = await agent.getActions();
12
- * await agent.execute('signup', { email: 'test@example.com' });
13
- */
14
-
15
- class WABAgent {
16
- /**
17
- * @param {object} page — A Puppeteer or Playwright page object
18
- * @param {object} [options]
19
- * @param {number} [options.timeout=10000] — Default timeout in ms
20
- * @param {boolean} [options.useBiDi=false] — Use BiDi interface instead of AICommands
21
- */
22
- constructor(page, options = {}) {
23
- this.page = page;
24
- this.timeout = options.timeout || 10000;
25
- this.useBiDi = options.useBiDi || false;
26
- this._biDiId = 0;
27
- }
28
-
29
- /**
30
- * Wait for the WAB bridge to be ready on the page.
31
- * @returns {Promise<boolean>}
32
- */
33
- async waitForBridge() {
34
- const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
35
- await this.page.waitForFunction(
36
- (name) => typeof window[name] !== 'undefined',
37
- { timeout: this.timeout },
38
- iface
39
- );
40
- return true;
41
- }
42
-
43
- /**
44
- * Check if the bridge is loaded on the current page.
45
- * @returns {Promise<boolean>}
46
- */
47
- async hasBridge() {
48
- const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
49
- return this.page.evaluate((name) => typeof window[name] !== 'undefined', iface);
50
- }
51
-
52
- /**
53
- * Get all available actions.
54
- * @param {string} [category] — Optional category filter
55
- * @returns {Promise<Array>}
56
- */
57
- async getActions(category) {
58
- if (this.useBiDi) {
59
- const result = await this._bidiSend('wab.getActions', category ? { category } : {});
60
- return result.result || [];
61
- }
62
- return this.page.evaluate((cat) => window.AICommands.getActions(cat), category);
63
- }
64
-
65
- /**
66
- * Get a single action by name.
67
- * @param {string} name
68
- * @returns {Promise<object|null>}
69
- */
70
- async getAction(name) {
71
- return this.page.evaluate((n) => window.AICommands.getAction(n), name);
72
- }
73
-
74
- /**
75
- * Execute an action by name.
76
- * @param {string} name — Action name
77
- * @param {object} [params] — Action parameters
78
- * @returns {Promise<object>}
79
- */
80
- async execute(name, params) {
81
- if (this.useBiDi) {
82
- const result = await this._bidiSend('wab.executeAction', { name, data: params || {} });
83
- return result.result || result;
84
- }
85
- return this.page.evaluate(
86
- (n, p) => window.AICommands.execute(n, p),
87
- name, params
88
- );
89
- }
90
-
91
- /**
92
- * Read text content of an element.
93
- * @param {string} selector — CSS selector
94
- * @returns {Promise<object>}
95
- */
96
- async readContent(selector) {
97
- if (this.useBiDi) {
98
- const result = await this._bidiSend('wab.readContent', { selector });
99
- return result.result || result;
100
- }
101
- return this.page.evaluate((sel) => window.AICommands.readContent(sel), selector);
102
- }
103
-
104
- /**
105
- * Get page info and bridge metadata.
106
- * @returns {Promise<object>}
107
- */
108
- async getPageInfo() {
109
- if (this.useBiDi) {
110
- const result = await this._bidiSend('wab.getPageInfo');
111
- return result.result || result;
112
- }
113
- return this.page.evaluate(() => window.AICommands.getPageInfo());
114
- }
115
-
116
- /**
117
- * Authenticate an agent with the bridge.
118
- * @param {string} apiKey
119
- * @param {object} [meta] — Agent metadata
120
- * @returns {Promise<object>}
121
- */
122
- async authenticate(apiKey, meta) {
123
- return this.page.evaluate(
124
- (key, m) => window.AICommands.authenticate(key, m),
125
- apiKey, meta
126
- );
127
- }
128
-
129
- /**
130
- * Navigate to a URL and wait for the bridge.
131
- * @param {string} url
132
- * @returns {Promise<void>}
133
- */
134
- async navigateAndWait(url) {
135
- await this.page.goto(url, { waitUntil: 'networkidle2' });
136
- await this.waitForBridge();
137
- }
138
-
139
- /**
140
- * Execute multiple actions in sequence.
141
- * @param {Array<{name: string, params?: object}>} steps
142
- * @returns {Promise<Array>}
143
- */
144
- async executeSteps(steps) {
145
- const results = [];
146
- for (const step of steps) {
147
- results.push(await this.execute(step.name, step.params));
148
- }
149
- return results;
150
- }
151
-
152
- /**
153
- * Get the WAB discovery document for the current page.
154
- * @returns {Promise<object>}
155
- */
156
- async discover() {
157
- if (this.useBiDi) {
158
- const result = await this._bidiSend('wab.discover');
159
- return result.result || result;
160
- }
161
- return this.page.evaluate(() => window.AICommands.discover());
162
- }
163
-
164
- /**
165
- * Ping the bridge for a health check.
166
- * @returns {Promise<object>}
167
- */
168
- async ping() {
169
- if (this.useBiDi) {
170
- const result = await this._bidiSend('wab.ping');
171
- return result.result || result;
172
- }
173
- return this.page.evaluate(() => window.AICommands.ping());
174
- }
175
-
176
- /**
177
- * Get BiDi context (only available when useBiDi is true).
178
- * @returns {Promise<object>}
179
- */
180
- async getBiDiContext() {
181
- return this.page.evaluate(() => window.__wab_bidi.getContext());
182
- }
183
-
184
- /**
185
- * Get the WAB protocol interface data.
186
- * @returns {Promise<object>}
187
- */
188
- async getProtocolInfo() {
189
- return this.page.evaluate(() => window.__wab_protocol ? {
190
- version: window.__wab_protocol.version,
191
- protocol: window.__wab_protocol.protocol,
192
- discovery: window.__wab_protocol.discover()
193
- } : null);
194
- }
195
-
196
- /** @private */
197
- async _bidiSend(method, params = {}) {
198
- const cmd = { id: ++this._biDiId, method, params };
199
- return this.page.evaluate((c) => window.__wab_bidi.send(c), cmd);
200
- }
201
- }
202
-
203
- module.exports = { WABAgent };
1
+ /**
2
+ * WAB Agent SDK
3
+ *
4
+ * Helpers for building AI agents that interact with Web Agent Bridge.
5
+ * Works with Puppeteer, Playwright, or any browser automation tool.
6
+ *
7
+ * Usage:
8
+ * const { WABAgent } = require('./sdk');
9
+ * const agent = new WABAgent(page);
10
+ * await agent.waitForBridge();
11
+ * const actions = await agent.getActions();
12
+ * await agent.execute('signup', { email: 'test@example.com' });
13
+ */
14
+
15
+ class WABAgent {
16
+ /**
17
+ * @param {object} page — A Puppeteer or Playwright page object
18
+ * @param {object} [options]
19
+ * @param {number} [options.timeout=10000] — Default timeout in ms
20
+ * @param {boolean} [options.useBiDi=false] — Use BiDi interface instead of AICommands
21
+ */
22
+ constructor(page, options = {}) {
23
+ this.page = page;
24
+ this.timeout = options.timeout || 10000;
25
+ this.useBiDi = options.useBiDi || false;
26
+ this._biDiId = 0;
27
+ }
28
+
29
+ /**
30
+ * Wait for the WAB bridge to be ready on the page.
31
+ * @returns {Promise<boolean>}
32
+ */
33
+ async waitForBridge() {
34
+ const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
35
+ await this.page.waitForFunction(
36
+ (name) => typeof window[name] !== 'undefined',
37
+ { timeout: this.timeout },
38
+ iface
39
+ );
40
+ return true;
41
+ }
42
+
43
+ /**
44
+ * Check if the bridge is loaded on the current page.
45
+ * @returns {Promise<boolean>}
46
+ */
47
+ async hasBridge() {
48
+ const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
49
+ return this.page.evaluate((name) => typeof window[name] !== 'undefined', iface);
50
+ }
51
+
52
+ /**
53
+ * Get all available actions.
54
+ * @param {string} [category] — Optional category filter
55
+ * @returns {Promise<Array>}
56
+ */
57
+ async getActions(category) {
58
+ if (this.useBiDi) {
59
+ const result = await this._bidiSend('wab.getActions', category ? { category } : {});
60
+ return result.result || [];
61
+ }
62
+ return this.page.evaluate((cat) => window.AICommands.getActions(cat), category);
63
+ }
64
+
65
+ /**
66
+ * Get a single action by name.
67
+ * @param {string} name
68
+ * @returns {Promise<object|null>}
69
+ */
70
+ async getAction(name) {
71
+ return this.page.evaluate((n) => window.AICommands.getAction(n), name);
72
+ }
73
+
74
+ /**
75
+ * Execute an action by name.
76
+ * @param {string} name — Action name
77
+ * @param {object} [params] — Action parameters
78
+ * @returns {Promise<object>}
79
+ */
80
+ async execute(name, params) {
81
+ if (this.useBiDi) {
82
+ const result = await this._bidiSend('wab.executeAction', { name, data: params || {} });
83
+ return result.result || result;
84
+ }
85
+ return this.page.evaluate(
86
+ (n, p) => window.AICommands.execute(n, p),
87
+ name, params
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Read text content of an element.
93
+ * @param {string} selector — CSS selector
94
+ * @returns {Promise<object>}
95
+ */
96
+ async readContent(selector) {
97
+ if (this.useBiDi) {
98
+ const result = await this._bidiSend('wab.readContent', { selector });
99
+ return result.result || result;
100
+ }
101
+ return this.page.evaluate((sel) => window.AICommands.readContent(sel), selector);
102
+ }
103
+
104
+ /**
105
+ * Get page info and bridge metadata.
106
+ * @returns {Promise<object>}
107
+ */
108
+ async getPageInfo() {
109
+ if (this.useBiDi) {
110
+ const result = await this._bidiSend('wab.getPageInfo');
111
+ return result.result || result;
112
+ }
113
+ return this.page.evaluate(() => window.AICommands.getPageInfo());
114
+ }
115
+
116
+ /**
117
+ * Authenticate an agent with the bridge.
118
+ * @param {string} apiKey
119
+ * @param {object} [meta] — Agent metadata
120
+ * @returns {Promise<object>}
121
+ */
122
+ async authenticate(apiKey, meta) {
123
+ return this.page.evaluate(
124
+ (key, m) => window.AICommands.authenticate(key, m),
125
+ apiKey, meta
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Navigate to a URL and wait for the bridge.
131
+ * @param {string} url
132
+ * @returns {Promise<void>}
133
+ */
134
+ async navigateAndWait(url) {
135
+ await this.page.goto(url, { waitUntil: 'networkidle2' });
136
+ await this.waitForBridge();
137
+ }
138
+
139
+ /**
140
+ * Execute multiple actions in sequence.
141
+ * @param {Array<{name: string, params?: object}>} steps
142
+ * @returns {Promise<Array>}
143
+ */
144
+ async executeSteps(steps) {
145
+ const results = [];
146
+ for (const step of steps) {
147
+ results.push(await this.execute(step.name, step.params));
148
+ }
149
+ return results;
150
+ }
151
+
152
+ /**
153
+ * Get the WAB discovery document for the current page.
154
+ * @returns {Promise<object>}
155
+ */
156
+ async discover() {
157
+ if (this.useBiDi) {
158
+ const result = await this._bidiSend('wab.discover');
159
+ return result.result || result;
160
+ }
161
+ return this.page.evaluate(() => window.AICommands.discover());
162
+ }
163
+
164
+ /**
165
+ * Ping the bridge for a health check.
166
+ * @returns {Promise<object>}
167
+ */
168
+ async ping() {
169
+ if (this.useBiDi) {
170
+ const result = await this._bidiSend('wab.ping');
171
+ return result.result || result;
172
+ }
173
+ return this.page.evaluate(() => window.AICommands.ping());
174
+ }
175
+
176
+ /**
177
+ * Get BiDi context (only available when useBiDi is true).
178
+ * @returns {Promise<object>}
179
+ */
180
+ async getBiDiContext() {
181
+ return this.page.evaluate(() => window.__wab_bidi.getContext());
182
+ }
183
+
184
+ /**
185
+ * Get the WAB protocol interface data.
186
+ * @returns {Promise<object>}
187
+ */
188
+ async getProtocolInfo() {
189
+ return this.page.evaluate(() => window.__wab_protocol ? {
190
+ version: window.__wab_protocol.version,
191
+ protocol: window.__wab_protocol.protocol,
192
+ discovery: window.__wab_protocol.discover()
193
+ } : null);
194
+ }
195
+
196
+ /** @private */
197
+ async _bidiSend(method, params = {}) {
198
+ const cmd = { id: ++this._biDiId, method, params };
199
+ return this.page.evaluate((c) => window.__wab_bidi.send(c), cmd);
200
+ }
201
+ }
202
+
203
+ module.exports = { WABAgent };
package/sdk/package.json CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "name": "@anthropic-wab/agent-sdk",
3
- "version": "1.0.0",
4
- "description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
5
- "main": "index.js",
6
- "license": "MIT",
7
- "keywords": ["wab", "ai-agent", "sdk", "web-automation", "bridge"],
8
- "peerDependencies": {
9
- "puppeteer": ">=20.0.0"
10
- },
11
- "peerDependenciesMeta": {
12
- "puppeteer": { "optional": true }
13
- }
14
- }
1
+ {
2
+ "name": "@anthropic-wab/agent-sdk",
3
+ "version": "1.0.0",
4
+ "description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
5
+ "main": "index.js",
6
+ "license": "MIT",
7
+ "keywords": ["wab", "ai-agent", "sdk", "web-automation", "bridge"],
8
+ "peerDependencies": {
9
+ "puppeteer": ">=20.0.0"
10
+ },
11
+ "peerDependenciesMeta": {
12
+ "puppeteer": { "optional": true }
13
+ }
14
+ }