web-agent-bridge 1.2.0 โ 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 -933
- 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
package/bin/cli.js
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Web Agent Bridge CLI
|
|
5
|
-
* Usage: npx web-agent-bridge [command]
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
|
|
11
|
-
const args = process.argv.slice(2);
|
|
12
|
-
const command = args[0] || 'start';
|
|
13
|
-
|
|
14
|
-
function printHelp() {
|
|
15
|
-
console.log(`
|
|
16
|
-
Web Agent Bridge CLI
|
|
17
|
-
|
|
18
|
-
Usage:
|
|
19
|
-
npx web-agent-bridge <command> [options]
|
|
20
|
-
|
|
21
|
-
Commands:
|
|
22
|
-
start Start the WAB server (default)
|
|
23
|
-
init Create .env file from template
|
|
24
|
-
help Show this help message
|
|
25
|
-
|
|
26
|
-
Options:
|
|
27
|
-
--port, -p Set server port (default: 3000)
|
|
28
|
-
|
|
29
|
-
Examples:
|
|
30
|
-
npx web-agent-bridge start
|
|
31
|
-
npx web-agent-bridge start --port 4000
|
|
32
|
-
npx web-agent-bridge init
|
|
33
|
-
`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
switch (command) {
|
|
37
|
-
case 'start': {
|
|
38
|
-
const portIdx = args.indexOf('--port') !== -1 ? args.indexOf('--port') : args.indexOf('-p');
|
|
39
|
-
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
40
|
-
process.env.PORT = args[portIdx + 1];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
44
|
-
if (fs.existsSync(envPath)) {
|
|
45
|
-
require('dotenv').config({ path: envPath });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
require('../server/index.js');
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
case 'init': {
|
|
53
|
-
const envExample = path.join(__dirname, '..', '.env.example');
|
|
54
|
-
const envTarget = path.join(process.cwd(), '.env');
|
|
55
|
-
|
|
56
|
-
if (fs.existsSync(envTarget)) {
|
|
57
|
-
console.log(' .env file already exists. Skipping.');
|
|
58
|
-
} else if (fs.existsSync(envExample)) {
|
|
59
|
-
fs.copyFileSync(envExample, envTarget);
|
|
60
|
-
console.log(' Created .env file from template.');
|
|
61
|
-
console.log(' Edit .env to set your JWT_SECRET before starting.');
|
|
62
|
-
} else {
|
|
63
|
-
const defaultEnv = 'PORT=3000\nJWT_SECRET=change-this-to-a-strong-random-secret-in-production\nNODE_ENV=development\n';
|
|
64
|
-
fs.writeFileSync(envTarget, defaultEnv);
|
|
65
|
-
console.log(' Created default .env file.');
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
case 'help':
|
|
71
|
-
case '--help':
|
|
72
|
-
case '-h':
|
|
73
|
-
printHelp();
|
|
74
|
-
break;
|
|
75
|
-
|
|
76
|
-
default:
|
|
77
|
-
console.error(` Unknown command: ${command}`);
|
|
78
|
-
printHelp();
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web Agent Bridge CLI
|
|
5
|
+
* Usage: npx web-agent-bridge [command]
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
const command = args[0] || 'start';
|
|
13
|
+
|
|
14
|
+
function printHelp() {
|
|
15
|
+
console.log(`
|
|
16
|
+
Web Agent Bridge CLI
|
|
17
|
+
|
|
18
|
+
Usage:
|
|
19
|
+
npx web-agent-bridge <command> [options]
|
|
20
|
+
|
|
21
|
+
Commands:
|
|
22
|
+
start Start the WAB server (default)
|
|
23
|
+
init Create .env file from template
|
|
24
|
+
help Show this help message
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--port, -p Set server port (default: 3000)
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
npx web-agent-bridge start
|
|
31
|
+
npx web-agent-bridge start --port 4000
|
|
32
|
+
npx web-agent-bridge init
|
|
33
|
+
`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
switch (command) {
|
|
37
|
+
case 'start': {
|
|
38
|
+
const portIdx = args.indexOf('--port') !== -1 ? args.indexOf('--port') : args.indexOf('-p');
|
|
39
|
+
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
40
|
+
process.env.PORT = args[portIdx + 1];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
44
|
+
if (fs.existsSync(envPath)) {
|
|
45
|
+
require('dotenv').config({ path: envPath });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
require('../server/index.js');
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
case 'init': {
|
|
53
|
+
const envExample = path.join(__dirname, '..', '.env.example');
|
|
54
|
+
const envTarget = path.join(process.cwd(), '.env');
|
|
55
|
+
|
|
56
|
+
if (fs.existsSync(envTarget)) {
|
|
57
|
+
console.log(' .env file already exists. Skipping.');
|
|
58
|
+
} else if (fs.existsSync(envExample)) {
|
|
59
|
+
fs.copyFileSync(envExample, envTarget);
|
|
60
|
+
console.log(' Created .env file from template.');
|
|
61
|
+
console.log(' Edit .env to set your JWT_SECRET before starting.');
|
|
62
|
+
} else {
|
|
63
|
+
const defaultEnv = 'PORT=3000\nJWT_SECRET=change-this-to-a-strong-random-secret-in-production\nNODE_ENV=development\n';
|
|
64
|
+
fs.writeFileSync(envTarget, defaultEnv);
|
|
65
|
+
console.log(' Created default .env file.');
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case 'help':
|
|
71
|
+
case '--help':
|
|
72
|
+
case '-h':
|
|
73
|
+
printHelp();
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
console.error(` Unknown command: ${command}`);
|
|
78
|
+
printHelp();
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
package/bin/wab.js
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Web Agent Bridge CLI
|
|
5
|
-
* Usage: npx web-agent-bridge [command]
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
|
|
11
|
-
const args = process.argv.slice(2);
|
|
12
|
-
const command = args[0] || 'start';
|
|
13
|
-
|
|
14
|
-
function printHelp() {
|
|
15
|
-
console.log(`
|
|
16
|
-
Web Agent Bridge CLI
|
|
17
|
-
|
|
18
|
-
Usage:
|
|
19
|
-
npx web-agent-bridge <command> [options]
|
|
20
|
-
|
|
21
|
-
Commands:
|
|
22
|
-
start Start the WAB server (default)
|
|
23
|
-
init Create .env file from template
|
|
24
|
-
help Show this help message
|
|
25
|
-
|
|
26
|
-
Options:
|
|
27
|
-
--port, -p Set server port (default: 3000)
|
|
28
|
-
|
|
29
|
-
Examples:
|
|
30
|
-
npx web-agent-bridge start
|
|
31
|
-
npx web-agent-bridge start --port 4000
|
|
32
|
-
npx web-agent-bridge init
|
|
33
|
-
`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
switch (command) {
|
|
37
|
-
case 'start': {
|
|
38
|
-
const portIdx = args.indexOf('--port') !== -1 ? args.indexOf('--port') : args.indexOf('-p');
|
|
39
|
-
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
40
|
-
process.env.PORT = args[portIdx + 1];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
44
|
-
if (fs.existsSync(envPath)) {
|
|
45
|
-
require('dotenv').config({ path: envPath });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
require('../server/index.js');
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
case 'init': {
|
|
53
|
-
const envExample = path.join(__dirname, '..', '.env.example');
|
|
54
|
-
const envTarget = path.join(process.cwd(), '.env');
|
|
55
|
-
|
|
56
|
-
if (fs.existsSync(envTarget)) {
|
|
57
|
-
console.log(' .env file already exists. Skipping.');
|
|
58
|
-
} else if (fs.existsSync(envExample)) {
|
|
59
|
-
fs.copyFileSync(envExample, envTarget);
|
|
60
|
-
console.log(' Created .env file from template.');
|
|
61
|
-
console.log(' Edit .env to set your JWT_SECRET before starting.');
|
|
62
|
-
} else {
|
|
63
|
-
const defaultEnv = 'PORT=3000\nJWT_SECRET=change-this-to-a-strong-random-secret-in-production\nNODE_ENV=development\n';
|
|
64
|
-
fs.writeFileSync(envTarget, defaultEnv);
|
|
65
|
-
console.log(' Created default .env file.');
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
case 'help':
|
|
71
|
-
case '--help':
|
|
72
|
-
case '-h':
|
|
73
|
-
printHelp();
|
|
74
|
-
break;
|
|
75
|
-
|
|
76
|
-
default:
|
|
77
|
-
console.error(` Unknown command: ${command}`);
|
|
78
|
-
printHelp();
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web Agent Bridge CLI
|
|
5
|
+
* Usage: npx web-agent-bridge [command]
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
const command = args[0] || 'start';
|
|
13
|
+
|
|
14
|
+
function printHelp() {
|
|
15
|
+
console.log(`
|
|
16
|
+
Web Agent Bridge CLI
|
|
17
|
+
|
|
18
|
+
Usage:
|
|
19
|
+
npx web-agent-bridge <command> [options]
|
|
20
|
+
|
|
21
|
+
Commands:
|
|
22
|
+
start Start the WAB server (default)
|
|
23
|
+
init Create .env file from template
|
|
24
|
+
help Show this help message
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--port, -p Set server port (default: 3000)
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
npx web-agent-bridge start
|
|
31
|
+
npx web-agent-bridge start --port 4000
|
|
32
|
+
npx web-agent-bridge init
|
|
33
|
+
`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
switch (command) {
|
|
37
|
+
case 'start': {
|
|
38
|
+
const portIdx = args.indexOf('--port') !== -1 ? args.indexOf('--port') : args.indexOf('-p');
|
|
39
|
+
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
40
|
+
process.env.PORT = args[portIdx + 1];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
44
|
+
if (fs.existsSync(envPath)) {
|
|
45
|
+
require('dotenv').config({ path: envPath });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
require('../server/index.js');
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
case 'init': {
|
|
53
|
+
const envExample = path.join(__dirname, '..', '.env.example');
|
|
54
|
+
const envTarget = path.join(process.cwd(), '.env');
|
|
55
|
+
|
|
56
|
+
if (fs.existsSync(envTarget)) {
|
|
57
|
+
console.log(' .env file already exists. Skipping.');
|
|
58
|
+
} else if (fs.existsSync(envExample)) {
|
|
59
|
+
fs.copyFileSync(envExample, envTarget);
|
|
60
|
+
console.log(' Created .env file from template.');
|
|
61
|
+
console.log(' Edit .env to set your JWT_SECRET before starting.');
|
|
62
|
+
} else {
|
|
63
|
+
const defaultEnv = 'PORT=3000\nJWT_SECRET=change-this-to-a-strong-random-secret-in-production\nNODE_ENV=development\n';
|
|
64
|
+
fs.writeFileSync(envTarget, defaultEnv);
|
|
65
|
+
console.log(' Created default .env file.');
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case 'help':
|
|
71
|
+
case '--help':
|
|
72
|
+
case '-h':
|
|
73
|
+
printHelp();
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
console.error(` Unknown command: ${command}`);
|
|
78
|
+
printHelp();
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
package/examples/bidi-agent.js
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: AI Agent using WebDriver BiDi Protocol via WAB
|
|
3
|
-
*
|
|
4
|
-
* This agent connects to a website using the __wab_bidi interface,
|
|
5
|
-
* which follows WebDriver BiDi conventions for standardized communication.
|
|
6
|
-
*
|
|
7
|
-
* Prerequisites:
|
|
8
|
-
* npm install puppeteer
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* node examples/bidi-agent.js <url>
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const puppeteer = require('puppeteer');
|
|
15
|
-
|
|
16
|
-
const TARGET_URL = process.argv[2] || 'http://localhost:3000';
|
|
17
|
-
|
|
18
|
-
let commandId = 0;
|
|
19
|
-
|
|
20
|
-
function bidiCommand(method, params = {}) {
|
|
21
|
-
return { id: ++commandId, method, params };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function main() {
|
|
25
|
-
console.log(`\n๐ WAB BiDi Agent`);
|
|
26
|
-
console.log(` Target: ${TARGET_URL}\n`);
|
|
27
|
-
|
|
28
|
-
const browser = await puppeteer.launch({ headless: true });
|
|
29
|
-
const page = await browser.newPage();
|
|
30
|
-
|
|
31
|
-
await page.goto(TARGET_URL, { waitUntil: 'networkidle2' });
|
|
32
|
-
console.log(`โ Page loaded: ${await page.title()}`);
|
|
33
|
-
|
|
34
|
-
// Check for BiDi interface
|
|
35
|
-
const hasBiDi = await page.evaluate(() => {
|
|
36
|
-
return typeof window.__wab_bidi !== 'undefined' && typeof window.__wab_bidi.send === 'function';
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
if (!hasBiDi) {
|
|
40
|
-
console.log('โ WAB BiDi interface not found on this page.');
|
|
41
|
-
await browser.close();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
console.log('โ WAB BiDi interface detected\n');
|
|
46
|
-
|
|
47
|
-
// Step 1: Get BiDi context
|
|
48
|
-
const context = await page.evaluate(() => window.__wab_bidi.getContext());
|
|
49
|
-
console.log('๐ BiDi Context:');
|
|
50
|
-
console.log(` URL: ${context.context.url}`);
|
|
51
|
-
console.log(` Title: ${context.context.title}`);
|
|
52
|
-
console.log(` Version: ${context.version}`);
|
|
53
|
-
console.log(` Tier: ${context.capabilities.tier}`);
|
|
54
|
-
console.log(` Capabilities: ${context.capabilities.actions.length} actions\n`);
|
|
55
|
-
|
|
56
|
-
// Step 2: Get actions via BiDi command
|
|
57
|
-
const actionsResult = await page.evaluate((cmd) => {
|
|
58
|
-
return window.__wab_bidi.send(cmd);
|
|
59
|
-
}, bidiCommand('wab.getActions'));
|
|
60
|
-
|
|
61
|
-
console.log(`๐ Actions (via BiDi):`);
|
|
62
|
-
if (actionsResult.result) {
|
|
63
|
-
actionsResult.result.forEach((action) => {
|
|
64
|
-
console.log(` โข ${action.name} [${action.trigger}] โ ${action.description}`);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Step 3: Get page info via BiDi
|
|
69
|
-
const infoResult = await page.evaluate((cmd) => {
|
|
70
|
-
return window.__wab_bidi.send(cmd);
|
|
71
|
-
}, bidiCommand('wab.getPageInfo'));
|
|
72
|
-
|
|
73
|
-
console.log('\n๐ Page Info (via BiDi):');
|
|
74
|
-
if (infoResult.result) {
|
|
75
|
-
console.log(` Title: ${infoResult.result.title}`);
|
|
76
|
-
console.log(` Domain: ${infoResult.result.domain}`);
|
|
77
|
-
console.log(` Bridge: v${infoResult.result.bridgeVersion}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Step 4: Read content via BiDi command
|
|
81
|
-
const readResult = await page.evaluate((cmd) => {
|
|
82
|
-
return window.__wab_bidi.send(cmd);
|
|
83
|
-
}, bidiCommand('wab.readContent', { selector: 'h1' }));
|
|
84
|
-
|
|
85
|
-
if (readResult.result && readResult.result.success) {
|
|
86
|
-
console.log(`\n๐ Content: "${readResult.result.text}"`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Step 5: Execute an action via BiDi
|
|
90
|
-
const actions = actionsResult.result || [];
|
|
91
|
-
const firstAction = actions.find((a) => a.trigger === 'click');
|
|
92
|
-
if (firstAction) {
|
|
93
|
-
console.log(`\nโถ Executing via BiDi: "${firstAction.name}"`);
|
|
94
|
-
const execResult = await page.evaluate((cmd) => {
|
|
95
|
-
return window.__wab_bidi.send(cmd);
|
|
96
|
-
}, bidiCommand('wab.executeAction', { name: firstAction.name }));
|
|
97
|
-
|
|
98
|
-
const r = execResult.result;
|
|
99
|
-
console.log(` Result: ${r && r.success ? 'โ Success' : 'โ ' + (r?.error || 'Unknown error')}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Step 6: Test error handling
|
|
103
|
-
console.log('\n๐งช Testing error handling:');
|
|
104
|
-
const errorResult = await page.evaluate((cmd) => {
|
|
105
|
-
return window.__wab_bidi.send(cmd);
|
|
106
|
-
}, bidiCommand('wab.unknownMethod'));
|
|
107
|
-
|
|
108
|
-
if (errorResult.error) {
|
|
109
|
-
console.log(` โ Unknown command handled: ${errorResult.error.code} โ ${errorResult.error.message}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
console.log('\nโ BiDi agent session complete.');
|
|
113
|
-
await browser.close();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
main().catch((err) => {
|
|
117
|
-
console.error('Agent error:', err.message);
|
|
118
|
-
process.exit(1);
|
|
119
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Example: AI Agent using WebDriver BiDi Protocol via WAB
|
|
3
|
+
*
|
|
4
|
+
* This agent connects to a website using the __wab_bidi interface,
|
|
5
|
+
* which follows WebDriver BiDi conventions for standardized communication.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* npm install puppeteer
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node examples/bidi-agent.js <url>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const puppeteer = require('puppeteer');
|
|
15
|
+
|
|
16
|
+
const TARGET_URL = process.argv[2] || 'http://localhost:3000';
|
|
17
|
+
|
|
18
|
+
let commandId = 0;
|
|
19
|
+
|
|
20
|
+
function bidiCommand(method, params = {}) {
|
|
21
|
+
return { id: ++commandId, method, params };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
console.log(`\n๐ WAB BiDi Agent`);
|
|
26
|
+
console.log(` Target: ${TARGET_URL}\n`);
|
|
27
|
+
|
|
28
|
+
const browser = await puppeteer.launch({ headless: true });
|
|
29
|
+
const page = await browser.newPage();
|
|
30
|
+
|
|
31
|
+
await page.goto(TARGET_URL, { waitUntil: 'networkidle2' });
|
|
32
|
+
console.log(`โ Page loaded: ${await page.title()}`);
|
|
33
|
+
|
|
34
|
+
// Check for BiDi interface
|
|
35
|
+
const hasBiDi = await page.evaluate(() => {
|
|
36
|
+
return typeof window.__wab_bidi !== 'undefined' && typeof window.__wab_bidi.send === 'function';
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (!hasBiDi) {
|
|
40
|
+
console.log('โ WAB BiDi interface not found on this page.');
|
|
41
|
+
await browser.close();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log('โ WAB BiDi interface detected\n');
|
|
46
|
+
|
|
47
|
+
// Step 1: Get BiDi context
|
|
48
|
+
const context = await page.evaluate(() => window.__wab_bidi.getContext());
|
|
49
|
+
console.log('๐ BiDi Context:');
|
|
50
|
+
console.log(` URL: ${context.context.url}`);
|
|
51
|
+
console.log(` Title: ${context.context.title}`);
|
|
52
|
+
console.log(` Version: ${context.version}`);
|
|
53
|
+
console.log(` Tier: ${context.capabilities.tier}`);
|
|
54
|
+
console.log(` Capabilities: ${context.capabilities.actions.length} actions\n`);
|
|
55
|
+
|
|
56
|
+
// Step 2: Get actions via BiDi command
|
|
57
|
+
const actionsResult = await page.evaluate((cmd) => {
|
|
58
|
+
return window.__wab_bidi.send(cmd);
|
|
59
|
+
}, bidiCommand('wab.getActions'));
|
|
60
|
+
|
|
61
|
+
console.log(`๐ Actions (via BiDi):`);
|
|
62
|
+
if (actionsResult.result) {
|
|
63
|
+
actionsResult.result.forEach((action) => {
|
|
64
|
+
console.log(` โข ${action.name} [${action.trigger}] โ ${action.description}`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Step 3: Get page info via BiDi
|
|
69
|
+
const infoResult = await page.evaluate((cmd) => {
|
|
70
|
+
return window.__wab_bidi.send(cmd);
|
|
71
|
+
}, bidiCommand('wab.getPageInfo'));
|
|
72
|
+
|
|
73
|
+
console.log('\n๐ Page Info (via BiDi):');
|
|
74
|
+
if (infoResult.result) {
|
|
75
|
+
console.log(` Title: ${infoResult.result.title}`);
|
|
76
|
+
console.log(` Domain: ${infoResult.result.domain}`);
|
|
77
|
+
console.log(` Bridge: v${infoResult.result.bridgeVersion}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Step 4: Read content via BiDi command
|
|
81
|
+
const readResult = await page.evaluate((cmd) => {
|
|
82
|
+
return window.__wab_bidi.send(cmd);
|
|
83
|
+
}, bidiCommand('wab.readContent', { selector: 'h1' }));
|
|
84
|
+
|
|
85
|
+
if (readResult.result && readResult.result.success) {
|
|
86
|
+
console.log(`\n๐ Content: "${readResult.result.text}"`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Step 5: Execute an action via BiDi
|
|
90
|
+
const actions = actionsResult.result || [];
|
|
91
|
+
const firstAction = actions.find((a) => a.trigger === 'click');
|
|
92
|
+
if (firstAction) {
|
|
93
|
+
console.log(`\nโถ Executing via BiDi: "${firstAction.name}"`);
|
|
94
|
+
const execResult = await page.evaluate((cmd) => {
|
|
95
|
+
return window.__wab_bidi.send(cmd);
|
|
96
|
+
}, bidiCommand('wab.executeAction', { name: firstAction.name }));
|
|
97
|
+
|
|
98
|
+
const r = execResult.result;
|
|
99
|
+
console.log(` Result: ${r && r.success ? 'โ Success' : 'โ ' + (r?.error || 'Unknown error')}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Step 6: Test error handling
|
|
103
|
+
console.log('\n๐งช Testing error handling:');
|
|
104
|
+
const errorResult = await page.evaluate((cmd) => {
|
|
105
|
+
return window.__wab_bidi.send(cmd);
|
|
106
|
+
}, bidiCommand('wab.unknownMethod'));
|
|
107
|
+
|
|
108
|
+
if (errorResult.error) {
|
|
109
|
+
console.log(` โ Unknown command handled: ${errorResult.error.code} โ ${errorResult.error.message}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log('\nโ BiDi agent session complete.');
|
|
113
|
+
await browser.close();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
main().catch((err) => {
|
|
117
|
+
console.error('Agent error:', err.message);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|