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.
- package/LICENSE +21 -21
- package/README.ar.md +446 -446
- package/README.md +844 -844
- package/bin/cli.js +80 -80
- package/bin/wab.js +80 -80
- package/docs/DEPLOY.md +118 -118
- package/docs/SPEC.md +1540 -1540
- package/examples/bidi-agent.js +119 -119
- package/examples/mcp-agent.js +94 -94
- package/examples/puppeteer-agent.js +108 -108
- package/examples/vision-agent.js +171 -171
- package/package.json +78 -78
- package/public/admin/dashboard.html +848 -848
- package/public/admin/login.html +84 -84
- package/public/cookies.html +208 -208
- package/public/css/styles.css +1235 -1235
- package/public/dashboard.html +704 -704
- package/public/docs.html +585 -585
- package/public/index.html +332 -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/ws-client.js +74 -74
- package/public/login.html +83 -83
- package/public/privacy.html +295 -295
- package/public/register.html +103 -103
- package/public/terms.html +254 -254
- package/script/ai-agent-bridge.js +1513 -1513
- package/sdk/README.md +55 -55
- package/sdk/index.js +203 -203
- package/sdk/package.json +14 -14
- package/server/config/secrets.js +92 -92
- package/server/index.js +181 -181
- 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/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.js +247 -247
- package/server/routes/api.js +138 -138
- package/server/routes/auth.js +51 -51
- package/server/routes/billing.js +45 -45
- package/server/routes/discovery.js +329 -329
- package/server/routes/license.js +240 -240
- package/server/routes/noscript.js +543 -543
- package/server/routes/wab-api.js +476 -476
- package/server/services/email.js +204 -204
- package/server/services/fairness.js +420 -420
- package/server/services/stripe.js +192 -192
- 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/wab-mcp-adapter/README.md +136 -136
- package/wab-mcp-adapter/index.js +555 -555
- package/wab-mcp-adapter/package.json +17 -17
- package/public/css/premium.css +0 -317
- package/public/premium-dashboard.html +0 -2075
- package/public/premium.html +0 -791
- package/server/migrations/002_premium_features.sql +0 -418
- package/server/routes/premium.js +0 -724
- package/server/services/premium.js +0 -1680
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
|
+
});
|
package/examples/mcp-agent.js
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: Using WAB sites via the MCP adapter
|
|
3
|
-
*
|
|
4
|
-
* The WAB-MCP adapter exposes every WAB site action as an MCP tool,
|
|
5
|
-
* so any MCP-compatible AI agent (Claude, GPT, etc.) can interact
|
|
6
|
-
* with WAB-enabled websites through a uniform tool interface.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* node examples/mcp-agent.js <site-url>
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const { WABMCPAdapter } = require('../wab-mcp-adapter');
|
|
13
|
-
|
|
14
|
-
const TARGET = process.argv[2] || 'http://localhost:3000';
|
|
15
|
-
|
|
16
|
-
async function main() {
|
|
17
|
-
console.log('\n WAB ā MCP Adapter Demo');
|
|
18
|
-
console.log(` Target: ${TARGET}\n`);
|
|
19
|
-
|
|
20
|
-
const adapter = new WABMCPAdapter({
|
|
21
|
-
siteUrl: TARGET,
|
|
22
|
-
transport: 'http'
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Step 1: Discover site capabilities
|
|
26
|
-
console.log('1. Discovering WAB capabilities...');
|
|
27
|
-
const discovery = await adapter.discover();
|
|
28
|
-
if (discovery) {
|
|
29
|
-
console.log(` Provider: ${discovery.provider?.name || 'unknown'}`);
|
|
30
|
-
console.log(` Domain: ${discovery.provider?.domain || 'unknown'}`);
|
|
31
|
-
console.log(` Tier: ${discovery.capabilities?.tier || 'free'}`);
|
|
32
|
-
console.log(` Features: ${(discovery.capabilities?.features || []).join(', ')}`);
|
|
33
|
-
if (discovery.fairness) {
|
|
34
|
-
console.log(` Fairness: score=${discovery.fairness.neutrality_score}, independent=${discovery.fairness.is_independent}`);
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
console.log(' No discovery document found (site may not have WAB configured)');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Step 2: List MCP tools
|
|
41
|
-
console.log('\n2. Available MCP tools:');
|
|
42
|
-
const tools = await adapter.getTools();
|
|
43
|
-
tools.forEach(tool => {
|
|
44
|
-
const params = tool.input_schema?.properties
|
|
45
|
-
? Object.keys(tool.input_schema.properties).join(', ')
|
|
46
|
-
: 'none';
|
|
47
|
-
console.log(` - ${tool.name}: ${tool.description} (params: ${params})`);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Step 3: Execute built-in tools
|
|
51
|
-
console.log('\n3. Executing wab_get_page_info...');
|
|
52
|
-
try {
|
|
53
|
-
const infoResult = await adapter.executeTool('wab_get_page_info', {});
|
|
54
|
-
const info = infoResult.content;
|
|
55
|
-
if (infoResult.is_error) {
|
|
56
|
-
console.log(` Error: ${info.error}`);
|
|
57
|
-
} else {
|
|
58
|
-
console.log(` Title: ${info.title || 'N/A'}`);
|
|
59
|
-
console.log(` Version: ${info.bridgeVersion || 'N/A'}`);
|
|
60
|
-
console.log(` Domain: ${info.domain || 'N/A'}`);
|
|
61
|
-
}
|
|
62
|
-
} catch (err) {
|
|
63
|
-
console.log(` Error: ${err.message}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Step 4: Search the fairness registry
|
|
67
|
-
console.log('\n4. Fairness-weighted search (demo):');
|
|
68
|
-
try {
|
|
69
|
-
const searchResult = await adapter.executeTool('wab_fairness_search', {
|
|
70
|
-
query: 'e-commerce',
|
|
71
|
-
limit: 5
|
|
72
|
-
});
|
|
73
|
-
const search = searchResult.content;
|
|
74
|
-
if (searchResult.is_error) {
|
|
75
|
-
console.log(` Error: ${search.error}`);
|
|
76
|
-
} else if (search.results?.length) {
|
|
77
|
-
search.results.forEach(r => {
|
|
78
|
-
console.log(` - ${r.name} (${r.domain}) ā score: ${r.final_score}`);
|
|
79
|
-
});
|
|
80
|
-
} else {
|
|
81
|
-
console.log(' No sites registered in directory yet.');
|
|
82
|
-
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
console.log(` Registry not available: ${err.message}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
console.log('\nDone. In a real MCP integration, these tools would be');
|
|
88
|
-
console.log('exposed to Claude/GPT via the MCP tool-use protocol.\n');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
main().catch(err => {
|
|
92
|
-
console.error('Error:', err.message);
|
|
93
|
-
process.exit(1);
|
|
94
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Example: Using WAB sites via the MCP adapter
|
|
3
|
+
*
|
|
4
|
+
* The WAB-MCP adapter exposes every WAB site action as an MCP tool,
|
|
5
|
+
* so any MCP-compatible AI agent (Claude, GPT, etc.) can interact
|
|
6
|
+
* with WAB-enabled websites through a uniform tool interface.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* node examples/mcp-agent.js <site-url>
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { WABMCPAdapter } = require('../wab-mcp-adapter');
|
|
13
|
+
|
|
14
|
+
const TARGET = process.argv[2] || 'http://localhost:3000';
|
|
15
|
+
|
|
16
|
+
async function main() {
|
|
17
|
+
console.log('\n WAB ā MCP Adapter Demo');
|
|
18
|
+
console.log(` Target: ${TARGET}\n`);
|
|
19
|
+
|
|
20
|
+
const adapter = new WABMCPAdapter({
|
|
21
|
+
siteUrl: TARGET,
|
|
22
|
+
transport: 'http'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Step 1: Discover site capabilities
|
|
26
|
+
console.log('1. Discovering WAB capabilities...');
|
|
27
|
+
const discovery = await adapter.discover();
|
|
28
|
+
if (discovery) {
|
|
29
|
+
console.log(` Provider: ${discovery.provider?.name || 'unknown'}`);
|
|
30
|
+
console.log(` Domain: ${discovery.provider?.domain || 'unknown'}`);
|
|
31
|
+
console.log(` Tier: ${discovery.capabilities?.tier || 'free'}`);
|
|
32
|
+
console.log(` Features: ${(discovery.capabilities?.features || []).join(', ')}`);
|
|
33
|
+
if (discovery.fairness) {
|
|
34
|
+
console.log(` Fairness: score=${discovery.fairness.neutrality_score}, independent=${discovery.fairness.is_independent}`);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
console.log(' No discovery document found (site may not have WAB configured)');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Step 2: List MCP tools
|
|
41
|
+
console.log('\n2. Available MCP tools:');
|
|
42
|
+
const tools = await adapter.getTools();
|
|
43
|
+
tools.forEach(tool => {
|
|
44
|
+
const params = tool.input_schema?.properties
|
|
45
|
+
? Object.keys(tool.input_schema.properties).join(', ')
|
|
46
|
+
: 'none';
|
|
47
|
+
console.log(` - ${tool.name}: ${tool.description} (params: ${params})`);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Step 3: Execute built-in tools
|
|
51
|
+
console.log('\n3. Executing wab_get_page_info...');
|
|
52
|
+
try {
|
|
53
|
+
const infoResult = await adapter.executeTool('wab_get_page_info', {});
|
|
54
|
+
const info = infoResult.content;
|
|
55
|
+
if (infoResult.is_error) {
|
|
56
|
+
console.log(` Error: ${info.error}`);
|
|
57
|
+
} else {
|
|
58
|
+
console.log(` Title: ${info.title || 'N/A'}`);
|
|
59
|
+
console.log(` Version: ${info.bridgeVersion || 'N/A'}`);
|
|
60
|
+
console.log(` Domain: ${info.domain || 'N/A'}`);
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.log(` Error: ${err.message}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Step 4: Search the fairness registry
|
|
67
|
+
console.log('\n4. Fairness-weighted search (demo):');
|
|
68
|
+
try {
|
|
69
|
+
const searchResult = await adapter.executeTool('wab_fairness_search', {
|
|
70
|
+
query: 'e-commerce',
|
|
71
|
+
limit: 5
|
|
72
|
+
});
|
|
73
|
+
const search = searchResult.content;
|
|
74
|
+
if (searchResult.is_error) {
|
|
75
|
+
console.log(` Error: ${search.error}`);
|
|
76
|
+
} else if (search.results?.length) {
|
|
77
|
+
search.results.forEach(r => {
|
|
78
|
+
console.log(` - ${r.name} (${r.domain}) ā score: ${r.final_score}`);
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
console.log(' No sites registered in directory yet.');
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
console.log(` Registry not available: ${err.message}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log('\nDone. In a real MCP integration, these tools would be');
|
|
88
|
+
console.log('exposed to Claude/GPT via the MCP tool-use protocol.\n');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
main().catch(err => {
|
|
92
|
+
console.error('Error:', err.message);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: Basic AI Agent using Puppeteer + WAB
|
|
3
|
-
*
|
|
4
|
-
* This agent connects to a website that has the Web Agent Bridge script installed,
|
|
5
|
-
* discovers available actions, and executes them.
|
|
6
|
-
*
|
|
7
|
-
* Prerequisites:
|
|
8
|
-
* npm install puppeteer
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* node examples/puppeteer-agent.js <url>
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const puppeteer = require('puppeteer');
|
|
15
|
-
|
|
16
|
-
const TARGET_URL = process.argv[2] || 'http://localhost:3000';
|
|
17
|
-
|
|
18
|
-
async function main() {
|
|
19
|
-
console.log(`\nš¤ WAB Puppeteer Agent`);
|
|
20
|
-
console.log(` Target: ${TARGET_URL}\n`);
|
|
21
|
-
|
|
22
|
-
const browser = await puppeteer.launch({ headless: true });
|
|
23
|
-
const page = await browser.newPage();
|
|
24
|
-
|
|
25
|
-
// Navigate to the target site
|
|
26
|
-
await page.goto(TARGET_URL, { waitUntil: 'networkidle2' });
|
|
27
|
-
console.log(`ā Page loaded: ${await page.title()}`);
|
|
28
|
-
|
|
29
|
-
// Wait for WAB bridge to be ready
|
|
30
|
-
const hasBridge = await page.evaluate(() => {
|
|
31
|
-
return new Promise((resolve) => {
|
|
32
|
-
if (window.AICommands && window.AICommands._ready) {
|
|
33
|
-
resolve(true);
|
|
34
|
-
} else {
|
|
35
|
-
// Wait up to 5 seconds for bridge
|
|
36
|
-
const timeout = setTimeout(() => resolve(false), 5000);
|
|
37
|
-
document.addEventListener('wab:ready', () => {
|
|
38
|
-
clearTimeout(timeout);
|
|
39
|
-
resolve(true);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (!hasBridge) {
|
|
46
|
-
console.log('ā Web Agent Bridge not found on this page.');
|
|
47
|
-
await browser.close();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log('ā Web Agent Bridge detected\n');
|
|
52
|
-
|
|
53
|
-
// Step 1: Get page info
|
|
54
|
-
const pageInfo = await page.evaluate(() => window.AICommands.getPageInfo());
|
|
55
|
-
console.log('š Page Info:');
|
|
56
|
-
console.log(` Title: ${pageInfo.title}`);
|
|
57
|
-
console.log(` URL: ${pageInfo.url}`);
|
|
58
|
-
console.log(` Bridge Version: ${pageInfo.bridgeVersion}`);
|
|
59
|
-
console.log(` Tier: ${pageInfo.tier}`);
|
|
60
|
-
console.log(` Actions Available: ${pageInfo.actionsCount}`);
|
|
61
|
-
console.log(` Rate Limit Remaining: ${pageInfo.rateLimitRemaining}\n`);
|
|
62
|
-
|
|
63
|
-
// Step 2: Discover all available actions
|
|
64
|
-
const actions = await page.evaluate(() => window.AICommands.getActions());
|
|
65
|
-
console.log(`š Discovered ${actions.length} actions:`);
|
|
66
|
-
actions.forEach((action) => {
|
|
67
|
-
console.log(` ⢠${action.name} (${action.trigger}) ā ${action.description}`);
|
|
68
|
-
if (action.fields) {
|
|
69
|
-
action.fields.forEach((f) => {
|
|
70
|
-
console.log(` āā ${f.name}: ${f.type}${f.required ? ' (required)' : ''}`);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Step 3: Read content from the page
|
|
76
|
-
const content = await page.evaluate(() => {
|
|
77
|
-
return window.AICommands.readContent('h1') || window.AICommands.readContent('title');
|
|
78
|
-
});
|
|
79
|
-
if (content && content.success) {
|
|
80
|
-
console.log(`\nš Page heading: "${content.text}"`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Step 4: Execute a click action (first available)
|
|
84
|
-
const clickAction = actions.find((a) => a.trigger === 'click');
|
|
85
|
-
if (clickAction) {
|
|
86
|
-
console.log(`\nā¶ Executing action: "${clickAction.name}"`);
|
|
87
|
-
const result = await page.evaluate(
|
|
88
|
-
(name) => window.AICommands.execute(name),
|
|
89
|
-
clickAction.name
|
|
90
|
-
);
|
|
91
|
-
console.log(` Result: ${result.success ? 'ā Success' : 'ā ' + result.error}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Step 5: List permissions
|
|
95
|
-
const permissions = pageInfo.permissions;
|
|
96
|
-
console.log('\nš Permissions:');
|
|
97
|
-
Object.entries(permissions).forEach(([key, value]) => {
|
|
98
|
-
console.log(` ${value ? 'ā' : 'ā'} ${key}`);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
console.log('\nā Agent session complete.');
|
|
102
|
-
await browser.close();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
main().catch((err) => {
|
|
106
|
-
console.error('Agent error:', err.message);
|
|
107
|
-
process.exit(1);
|
|
108
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Example: Basic AI Agent using Puppeteer + WAB
|
|
3
|
+
*
|
|
4
|
+
* This agent connects to a website that has the Web Agent Bridge script installed,
|
|
5
|
+
* discovers available actions, and executes them.
|
|
6
|
+
*
|
|
7
|
+
* Prerequisites:
|
|
8
|
+
* npm install puppeteer
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node examples/puppeteer-agent.js <url>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const puppeteer = require('puppeteer');
|
|
15
|
+
|
|
16
|
+
const TARGET_URL = process.argv[2] || 'http://localhost:3000';
|
|
17
|
+
|
|
18
|
+
async function main() {
|
|
19
|
+
console.log(`\nš¤ WAB Puppeteer Agent`);
|
|
20
|
+
console.log(` Target: ${TARGET_URL}\n`);
|
|
21
|
+
|
|
22
|
+
const browser = await puppeteer.launch({ headless: true });
|
|
23
|
+
const page = await browser.newPage();
|
|
24
|
+
|
|
25
|
+
// Navigate to the target site
|
|
26
|
+
await page.goto(TARGET_URL, { waitUntil: 'networkidle2' });
|
|
27
|
+
console.log(`ā Page loaded: ${await page.title()}`);
|
|
28
|
+
|
|
29
|
+
// Wait for WAB bridge to be ready
|
|
30
|
+
const hasBridge = await page.evaluate(() => {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
if (window.AICommands && window.AICommands._ready) {
|
|
33
|
+
resolve(true);
|
|
34
|
+
} else {
|
|
35
|
+
// Wait up to 5 seconds for bridge
|
|
36
|
+
const timeout = setTimeout(() => resolve(false), 5000);
|
|
37
|
+
document.addEventListener('wab:ready', () => {
|
|
38
|
+
clearTimeout(timeout);
|
|
39
|
+
resolve(true);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!hasBridge) {
|
|
46
|
+
console.log('ā Web Agent Bridge not found on this page.');
|
|
47
|
+
await browser.close();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log('ā Web Agent Bridge detected\n');
|
|
52
|
+
|
|
53
|
+
// Step 1: Get page info
|
|
54
|
+
const pageInfo = await page.evaluate(() => window.AICommands.getPageInfo());
|
|
55
|
+
console.log('š Page Info:');
|
|
56
|
+
console.log(` Title: ${pageInfo.title}`);
|
|
57
|
+
console.log(` URL: ${pageInfo.url}`);
|
|
58
|
+
console.log(` Bridge Version: ${pageInfo.bridgeVersion}`);
|
|
59
|
+
console.log(` Tier: ${pageInfo.tier}`);
|
|
60
|
+
console.log(` Actions Available: ${pageInfo.actionsCount}`);
|
|
61
|
+
console.log(` Rate Limit Remaining: ${pageInfo.rateLimitRemaining}\n`);
|
|
62
|
+
|
|
63
|
+
// Step 2: Discover all available actions
|
|
64
|
+
const actions = await page.evaluate(() => window.AICommands.getActions());
|
|
65
|
+
console.log(`š Discovered ${actions.length} actions:`);
|
|
66
|
+
actions.forEach((action) => {
|
|
67
|
+
console.log(` ⢠${action.name} (${action.trigger}) ā ${action.description}`);
|
|
68
|
+
if (action.fields) {
|
|
69
|
+
action.fields.forEach((f) => {
|
|
70
|
+
console.log(` āā ${f.name}: ${f.type}${f.required ? ' (required)' : ''}`);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Step 3: Read content from the page
|
|
76
|
+
const content = await page.evaluate(() => {
|
|
77
|
+
return window.AICommands.readContent('h1') || window.AICommands.readContent('title');
|
|
78
|
+
});
|
|
79
|
+
if (content && content.success) {
|
|
80
|
+
console.log(`\nš Page heading: "${content.text}"`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Step 4: Execute a click action (first available)
|
|
84
|
+
const clickAction = actions.find((a) => a.trigger === 'click');
|
|
85
|
+
if (clickAction) {
|
|
86
|
+
console.log(`\nā¶ Executing action: "${clickAction.name}"`);
|
|
87
|
+
const result = await page.evaluate(
|
|
88
|
+
(name) => window.AICommands.execute(name),
|
|
89
|
+
clickAction.name
|
|
90
|
+
);
|
|
91
|
+
console.log(` Result: ${result.success ? 'ā Success' : 'ā ' + result.error}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Step 5: List permissions
|
|
95
|
+
const permissions = pageInfo.permissions;
|
|
96
|
+
console.log('\nš Permissions:');
|
|
97
|
+
Object.entries(permissions).forEach(([key, value]) => {
|
|
98
|
+
console.log(` ${value ? 'ā' : 'ā'} ${key}`);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log('\nā Agent session complete.');
|
|
102
|
+
await browser.close();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
main().catch((err) => {
|
|
106
|
+
console.error('Agent error:', err.message);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
});
|