web-agent-bridge 1.1.2 → 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 -844
- 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/public/register.html
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Create Account — Web Agent Bridge</title>
|
|
7
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
8
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
9
|
-
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
10
|
-
<link rel="stylesheet" href="/css/styles.css">
|
|
11
|
-
<script src="/js/auth-redirect.js"></script>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<div class="auth-page">
|
|
15
|
-
<div class="auth-card fade-in">
|
|
16
|
-
<div style="text-align:center; margin-bottom:32px;">
|
|
17
|
-
<a href="/" class="navbar-brand" style="justify-content:center;">
|
|
18
|
-
<div class="brand-icon">⚡</div>
|
|
19
|
-
<span>WAB</span>
|
|
20
|
-
</a>
|
|
21
|
-
</div>
|
|
22
|
-
<h1 style="text-align:center;">Create account</h1>
|
|
23
|
-
<p class="subtitle" style="text-align:center;">Get started with Web Agent Bridge</p>
|
|
24
|
-
|
|
25
|
-
<div class="alert alert-error" id="errorAlert"></div>
|
|
26
|
-
<div class="alert alert-success" id="successAlert"></div>
|
|
27
|
-
|
|
28
|
-
<form id="registerForm">
|
|
29
|
-
<div class="form-group">
|
|
30
|
-
<label for="name">Full Name</label>
|
|
31
|
-
<input type="text" id="name" class="form-input" placeholder="John Doe" required>
|
|
32
|
-
</div>
|
|
33
|
-
<div class="form-group">
|
|
34
|
-
<label for="email">Email</label>
|
|
35
|
-
<input type="email" id="email" class="form-input" placeholder="you@example.com" required>
|
|
36
|
-
</div>
|
|
37
|
-
<div class="form-group">
|
|
38
|
-
<label for="company">Company <span style="color:var(--text-muted);">(optional)</span></label>
|
|
39
|
-
<input type="text" id="company" class="form-input" placeholder="Your company">
|
|
40
|
-
</div>
|
|
41
|
-
<div class="form-group">
|
|
42
|
-
<label for="password">Password</label>
|
|
43
|
-
<input type="password" id="password" class="form-input" placeholder="Min 8 characters" required minlength="8">
|
|
44
|
-
</div>
|
|
45
|
-
<div class="form-group" style="display: flex; align-items: flex-start; gap: 8px;">
|
|
46
|
-
<input type="checkbox" id="termsConsent" required style="margin-top: 4px; accent-color: var(--accent-blue);">
|
|
47
|
-
<label for="termsConsent" style="font-size: 0.85rem; color: var(--text-muted); line-height: 1.5;">
|
|
48
|
-
I agree to the <a href="/terms" style="color: var(--accent-blue);">Terms of Service</a> and
|
|
49
|
-
<a href="/privacy" style="color: var(--accent-blue);">Privacy Policy</a>
|
|
50
|
-
</label>
|
|
51
|
-
</div>
|
|
52
|
-
<button type="submit" class="btn btn-primary btn-lg">Create Account</button>
|
|
53
|
-
</form>
|
|
54
|
-
|
|
55
|
-
<div class="auth-footer">
|
|
56
|
-
Already have an account? <a href="/login">Sign in</a>
|
|
57
|
-
</div>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
|
|
61
|
-
<script>
|
|
62
|
-
if (localStorage.getItem('wab_token')) {
|
|
63
|
-
window.location.replace(typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
document.getElementById('registerForm').addEventListener('submit', async (e) => {
|
|
67
|
-
e.preventDefault();
|
|
68
|
-
const errorEl = document.getElementById('errorAlert');
|
|
69
|
-
const successEl = document.getElementById('successAlert');
|
|
70
|
-
errorEl.style.display = 'none';
|
|
71
|
-
successEl.style.display = 'none';
|
|
72
|
-
|
|
73
|
-
const name = document.getElementById('name').value;
|
|
74
|
-
const email = document.getElementById('email').value;
|
|
75
|
-
const company = document.getElementById('company').value;
|
|
76
|
-
const password = document.getElementById('password').value;
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const res = await fetch('/api/auth/register', {
|
|
80
|
-
method: 'POST',
|
|
81
|
-
headers: { 'Content-Type': 'application/json' },
|
|
82
|
-
body: JSON.stringify({ name, email, company, password })
|
|
83
|
-
});
|
|
84
|
-
const data = await res.json();
|
|
85
|
-
|
|
86
|
-
if (!res.ok) {
|
|
87
|
-
errorEl.textContent = data.error || 'Registration failed';
|
|
88
|
-
errorEl.style.display = 'block';
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
localStorage.setItem('wab_token', data.token);
|
|
93
|
-
localStorage.setItem('wab_user', JSON.stringify(data.user));
|
|
94
|
-
window.location.href = typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard';
|
|
95
|
-
} catch (err) {
|
|
96
|
-
errorEl.textContent = 'Connection error. Please try again.';
|
|
97
|
-
errorEl.style.display = 'block';
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
</script>
|
|
101
|
-
<script src="/js/cookie-consent.js"></script>
|
|
102
|
-
</body>
|
|
103
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Create Account — Web Agent Bridge</title>
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
9
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
10
|
+
<link rel="stylesheet" href="/css/styles.css">
|
|
11
|
+
<script src="/js/auth-redirect.js"></script>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div class="auth-page">
|
|
15
|
+
<div class="auth-card fade-in">
|
|
16
|
+
<div style="text-align:center; margin-bottom:32px;">
|
|
17
|
+
<a href="/" class="navbar-brand" style="justify-content:center;">
|
|
18
|
+
<div class="brand-icon">⚡</div>
|
|
19
|
+
<span>WAB</span>
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
<h1 style="text-align:center;">Create account</h1>
|
|
23
|
+
<p class="subtitle" style="text-align:center;">Get started with Web Agent Bridge</p>
|
|
24
|
+
|
|
25
|
+
<div class="alert alert-error" id="errorAlert"></div>
|
|
26
|
+
<div class="alert alert-success" id="successAlert"></div>
|
|
27
|
+
|
|
28
|
+
<form id="registerForm">
|
|
29
|
+
<div class="form-group">
|
|
30
|
+
<label for="name">Full Name</label>
|
|
31
|
+
<input type="text" id="name" class="form-input" placeholder="John Doe" required>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="form-group">
|
|
34
|
+
<label for="email">Email</label>
|
|
35
|
+
<input type="email" id="email" class="form-input" placeholder="you@example.com" required>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="form-group">
|
|
38
|
+
<label for="company">Company <span style="color:var(--text-muted);">(optional)</span></label>
|
|
39
|
+
<input type="text" id="company" class="form-input" placeholder="Your company">
|
|
40
|
+
</div>
|
|
41
|
+
<div class="form-group">
|
|
42
|
+
<label for="password">Password</label>
|
|
43
|
+
<input type="password" id="password" class="form-input" placeholder="Min 8 characters" required minlength="8">
|
|
44
|
+
</div>
|
|
45
|
+
<div class="form-group" style="display: flex; align-items: flex-start; gap: 8px;">
|
|
46
|
+
<input type="checkbox" id="termsConsent" required style="margin-top: 4px; accent-color: var(--accent-blue);">
|
|
47
|
+
<label for="termsConsent" style="font-size: 0.85rem; color: var(--text-muted); line-height: 1.5;">
|
|
48
|
+
I agree to the <a href="/terms" style="color: var(--accent-blue);">Terms of Service</a> and
|
|
49
|
+
<a href="/privacy" style="color: var(--accent-blue);">Privacy Policy</a>
|
|
50
|
+
</label>
|
|
51
|
+
</div>
|
|
52
|
+
<button type="submit" class="btn btn-primary btn-lg">Create Account</button>
|
|
53
|
+
</form>
|
|
54
|
+
|
|
55
|
+
<div class="auth-footer">
|
|
56
|
+
Already have an account? <a href="/login">Sign in</a>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<script>
|
|
62
|
+
if (localStorage.getItem('wab_token')) {
|
|
63
|
+
window.location.replace(typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
document.getElementById('registerForm').addEventListener('submit', async (e) => {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
const errorEl = document.getElementById('errorAlert');
|
|
69
|
+
const successEl = document.getElementById('successAlert');
|
|
70
|
+
errorEl.style.display = 'none';
|
|
71
|
+
successEl.style.display = 'none';
|
|
72
|
+
|
|
73
|
+
const name = document.getElementById('name').value;
|
|
74
|
+
const email = document.getElementById('email').value;
|
|
75
|
+
const company = document.getElementById('company').value;
|
|
76
|
+
const password = document.getElementById('password').value;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const res = await fetch('/api/auth/register', {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'Content-Type': 'application/json' },
|
|
82
|
+
body: JSON.stringify({ name, email, company, password })
|
|
83
|
+
});
|
|
84
|
+
const data = await res.json();
|
|
85
|
+
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
errorEl.textContent = data.error || 'Registration failed';
|
|
88
|
+
errorEl.style.display = 'block';
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
localStorage.setItem('wab_token', data.token);
|
|
93
|
+
localStorage.setItem('wab_user', JSON.stringify(data.user));
|
|
94
|
+
window.location.href = typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard';
|
|
95
|
+
} catch (err) {
|
|
96
|
+
errorEl.textContent = 'Connection error. Please try again.';
|
|
97
|
+
errorEl.style.display = 'block';
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
</script>
|
|
101
|
+
<script src="/js/cookie-consent.js"></script>
|
|
102
|
+
</body>
|
|
103
|
+
</html>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Web Agent Bridge — robots.txt
|
|
2
|
+
# https://webagentbridge.com
|
|
3
|
+
|
|
4
|
+
User-agent: *
|
|
5
|
+
Allow: /
|
|
6
|
+
Allow: /docs
|
|
7
|
+
Allow: /premium
|
|
8
|
+
Allow: /privacy
|
|
9
|
+
Allow: /terms
|
|
10
|
+
Allow: /cookies
|
|
11
|
+
Allow: /llms.txt
|
|
12
|
+
Allow: /llms-full.txt
|
|
13
|
+
Allow: /sitemap.xml
|
|
14
|
+
Allow: /agent-bridge.json
|
|
15
|
+
Allow: /.well-known/wab.json
|
|
16
|
+
Allow: /.well-known/ai-assets.json
|
|
17
|
+
Allow: /api/wab/discover
|
|
18
|
+
Allow: /api/wab/ping
|
|
19
|
+
Allow: /api/discovery/registry
|
|
20
|
+
Allow: /api/plans
|
|
21
|
+
Disallow: /api/admin/
|
|
22
|
+
Disallow: /api/auth/
|
|
23
|
+
Disallow: /api/billing/
|
|
24
|
+
Disallow: /admin/
|
|
25
|
+
Disallow: /dashboard
|
|
26
|
+
Disallow: /premium-dashboard
|
|
27
|
+
|
|
28
|
+
# AI Crawlers — Welcome! We have structured data for you.
|
|
29
|
+
User-agent: GPTBot
|
|
30
|
+
Allow: /
|
|
31
|
+
Allow: /llms.txt
|
|
32
|
+
Allow: /llms-full.txt
|
|
33
|
+
Allow: /agent-bridge.json
|
|
34
|
+
Allow: /sitemap.xml
|
|
35
|
+
Crawl-delay: 2
|
|
36
|
+
|
|
37
|
+
User-agent: ChatGPT-User
|
|
38
|
+
Allow: /
|
|
39
|
+
Allow: /llms.txt
|
|
40
|
+
Allow: /llms-full.txt
|
|
41
|
+
Crawl-delay: 2
|
|
42
|
+
|
|
43
|
+
User-agent: Claude-Web
|
|
44
|
+
Allow: /
|
|
45
|
+
Allow: /llms.txt
|
|
46
|
+
Allow: /llms-full.txt
|
|
47
|
+
Crawl-delay: 2
|
|
48
|
+
|
|
49
|
+
User-agent: Anthropic-AI
|
|
50
|
+
Allow: /
|
|
51
|
+
Allow: /llms.txt
|
|
52
|
+
Allow: /llms-full.txt
|
|
53
|
+
Crawl-delay: 2
|
|
54
|
+
|
|
55
|
+
User-agent: Google-Extended
|
|
56
|
+
Allow: /
|
|
57
|
+
Crawl-delay: 2
|
|
58
|
+
|
|
59
|
+
User-agent: Bingbot
|
|
60
|
+
Allow: /
|
|
61
|
+
Crawl-delay: 1
|
|
62
|
+
|
|
63
|
+
User-agent: PerplexityBot
|
|
64
|
+
Allow: /
|
|
65
|
+
Allow: /llms.txt
|
|
66
|
+
Allow: /llms-full.txt
|
|
67
|
+
Crawl-delay: 2
|
|
68
|
+
|
|
69
|
+
User-agent: YouBot
|
|
70
|
+
Allow: /
|
|
71
|
+
Allow: /llms.txt
|
|
72
|
+
Allow: /llms-full.txt
|
|
73
|
+
Crawl-delay: 2
|
|
74
|
+
|
|
75
|
+
User-agent: CCBot
|
|
76
|
+
Allow: /
|
|
77
|
+
Crawl-delay: 5
|
|
78
|
+
|
|
79
|
+
# Sitemap
|
|
80
|
+
Sitemap: https://webagentbridge.com/sitemap.xml
|
|
81
|
+
|
|
82
|
+
# AI-readable resources
|
|
83
|
+
# llms.txt: https://webagentbridge.com/llms.txt
|
|
84
|
+
# llms-full.txt: https://webagentbridge.com/llms-full.txt
|
|
85
|
+
# Discovery: https://webagentbridge.com/agent-bridge.json
|
|
86
|
+
# AI Assets: https://webagentbridge.com/.well-known/ai-assets.json
|
|
87
|
+
# OpenAPI: https://webagentbridge.com/openapi.json
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAB Consent — GDPR/CCPA consent banner for AI agent actions.
|
|
3
|
+
* Loaded after wab.min.js: <script src="/script/wab-consent.js"></script>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface WABConsentBannerOptions {
|
|
7
|
+
/** URL to the privacy policy page. */
|
|
8
|
+
policyUrl?: string;
|
|
9
|
+
/** Custom banner message. */
|
|
10
|
+
message?: string;
|
|
11
|
+
/** Called when user clicks Allow. */
|
|
12
|
+
onAccept?: () => void;
|
|
13
|
+
/** Called when user clicks Decline. */
|
|
14
|
+
onDecline?: () => void;
|
|
15
|
+
/** If true (default), skip banner if consent already granted. */
|
|
16
|
+
skipIfGranted?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface WABConsentAPI {
|
|
20
|
+
/** Show the consent banner (skips if already granted unless skipIfGranted is false). */
|
|
21
|
+
showBanner(options?: WABConsentBannerOptions): void;
|
|
22
|
+
/** Returns true if the user has granted consent. */
|
|
23
|
+
hasConsent(): boolean;
|
|
24
|
+
/** Clear stored consent (resets to un-decided). */
|
|
25
|
+
clear(): void;
|
|
26
|
+
/** localStorage key used for persisting consent. */
|
|
27
|
+
STORAGE_KEY: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare global {
|
|
31
|
+
interface Window {
|
|
32
|
+
WABConsent: WABConsentAPI;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAB Consent — optional GDPR/CCPA-style prompt before agents run actions.
|
|
3
|
+
* Load after wab.min.js: <script src="/script/wab-consent.js"></script>
|
|
4
|
+
*
|
|
5
|
+
* WABConsent.showBanner({
|
|
6
|
+
* policyUrl: '/privacy',
|
|
7
|
+
* onAccept: () => WAB.init({ ... }),
|
|
8
|
+
* onDecline: () => { ... }
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* Before execute, check WABConsent.hasConsent() or gate your own flows.
|
|
12
|
+
*/
|
|
13
|
+
(function (global) {
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
var STORAGE_KEY = 'wab_agent_consent_v1';
|
|
17
|
+
|
|
18
|
+
function hasConsent() {
|
|
19
|
+
try {
|
|
20
|
+
return global.localStorage.getItem(STORAGE_KEY) === 'granted';
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function setConsent(value) {
|
|
27
|
+
try {
|
|
28
|
+
if (value === null) global.localStorage.removeItem(STORAGE_KEY);
|
|
29
|
+
else global.localStorage.setItem(STORAGE_KEY, value);
|
|
30
|
+
} catch (e) {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function injectStyles() {
|
|
34
|
+
if (global.document.getElementById('wab-consent-styles')) return;
|
|
35
|
+
var s = global.document.createElement('style');
|
|
36
|
+
s.id = 'wab-consent-styles';
|
|
37
|
+
s.textContent =
|
|
38
|
+
'#wab-consent-bar{position:fixed;left:16px;right:16px;bottom:16px;max-width:520px;margin:0 auto;' +
|
|
39
|
+
'background:#0f172a;color:#e2e8f0;padding:16px 18px;border-radius:12px;border:1px solid #334155;' +
|
|
40
|
+
'box-shadow:0 12px 40px rgba(0,0,0,0.35);z-index:99999;font-family:system-ui,sans-serif;font-size:14px;line-height:1.45}' +
|
|
41
|
+
'#wab-consent-bar p{margin:0 0 12px}' +
|
|
42
|
+
'#wab-consent-bar .wab-c-actions{display:flex;flex-wrap:wrap;gap:10px;align-items:center}' +
|
|
43
|
+
'#wab-consent-bar button{padding:8px 16px;border-radius:8px;border:none;font-weight:600;cursor:pointer;font-size:13px}' +
|
|
44
|
+
'#wab-consent-bar .wab-c-accept{background:#3b82f6;color:#fff}' +
|
|
45
|
+
'#wab-consent-bar .wab-c-decline{background:#1e293b;color:#94a3b8;border:1px solid #334155}' +
|
|
46
|
+
'#wab-consent-bar a{color:#93c5fd}';
|
|
47
|
+
global.document.head.appendChild(s);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function showBanner(options) {
|
|
51
|
+
options = options || {};
|
|
52
|
+
if (hasConsent() && options.skipIfGranted !== false) {
|
|
53
|
+
if (typeof options.onAccept === 'function') options.onAccept();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
injectStyles();
|
|
57
|
+
var existing = global.document.getElementById('wab-consent-bar');
|
|
58
|
+
if (existing) existing.remove();
|
|
59
|
+
|
|
60
|
+
var bar = global.document.createElement('div');
|
|
61
|
+
bar.id = 'wab-consent-bar';
|
|
62
|
+
bar.setAttribute('role', 'dialog');
|
|
63
|
+
bar.setAttribute('aria-label', 'AI agent consent');
|
|
64
|
+
|
|
65
|
+
var policy = options.policyUrl
|
|
66
|
+
? '<a href="' + options.policyUrl + '" target="_blank" rel="noopener">Privacy policy</a>'
|
|
67
|
+
: '';
|
|
68
|
+
|
|
69
|
+
bar.innerHTML =
|
|
70
|
+
'<p><strong>AI assistance on this site</strong><br>' +
|
|
71
|
+
(options.message ||
|
|
72
|
+
'This site can expose actions to AI agents (forms, cart, navigation). Allow this site to register agent-ready actions in your browser?') +
|
|
73
|
+
(policy ? ' ' + policy + '.' : '') +
|
|
74
|
+
'</p>' +
|
|
75
|
+
'<div class="wab-c-actions">' +
|
|
76
|
+
'<button type="button" class="wab-c-accept" id="wab-c-accept">Allow</button>' +
|
|
77
|
+
'<button type="button" class="wab-c-decline" id="wab-c-decline">Decline</button>' +
|
|
78
|
+
'</div>';
|
|
79
|
+
|
|
80
|
+
global.document.body.appendChild(bar);
|
|
81
|
+
|
|
82
|
+
bar.querySelector('#wab-c-accept').addEventListener('click', function () {
|
|
83
|
+
setConsent('granted');
|
|
84
|
+
bar.remove();
|
|
85
|
+
if (typeof options.onAccept === 'function') options.onAccept();
|
|
86
|
+
});
|
|
87
|
+
bar.querySelector('#wab-c-decline').addEventListener('click', function () {
|
|
88
|
+
setConsent('denied');
|
|
89
|
+
bar.remove();
|
|
90
|
+
if (typeof options.onDecline === 'function') options.onDecline();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function clear() {
|
|
95
|
+
setConsent(null);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
global.WABConsent = {
|
|
99
|
+
showBanner: showBanner,
|
|
100
|
+
hasConsent: hasConsent,
|
|
101
|
+
clear: clear,
|
|
102
|
+
STORAGE_KEY: STORAGE_KEY
|
|
103
|
+
};
|
|
104
|
+
})(typeof window !== 'undefined' ? window : globalThis);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAB Schema hints — scan JSON-LD (schema.org Product, Offer) to suggest WAB actions.
|
|
3
|
+
* <script src="/script/wab-schema.js"></script>
|
|
4
|
+
*
|
|
5
|
+
* var products = WABSchema.scanJsonLd();
|
|
6
|
+
* var suggested = WABSchema.suggestActions(products);
|
|
7
|
+
* WAB.init(WABSchema.mergeWithManual({ buy: { ... } }, suggested));
|
|
8
|
+
*/
|
|
9
|
+
(function (global) {
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
function normalizeNode(node) {
|
|
13
|
+
if (!node || typeof node !== 'object') return null;
|
|
14
|
+
var types = node['@type'];
|
|
15
|
+
if (typeof types === 'string') types = [types];
|
|
16
|
+
if (!Array.isArray(types)) types = [];
|
|
17
|
+
return { raw: node, types: types };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function flattenGraph(data) {
|
|
21
|
+
if (Array.isArray(data)) return data;
|
|
22
|
+
if (data && Array.isArray(data['@graph'])) return data['@graph'];
|
|
23
|
+
return [data];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns {Array<{ type: string, name?: string, sku?: string, offers?: unknown, source: string }>}
|
|
28
|
+
*/
|
|
29
|
+
function scanJsonLd() {
|
|
30
|
+
var out = [];
|
|
31
|
+
var scripts = global.document.querySelectorAll('script[type="application/ld+json"]');
|
|
32
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
33
|
+
var text = scripts[i].textContent;
|
|
34
|
+
if (!text || !text.trim()) continue;
|
|
35
|
+
try {
|
|
36
|
+
var data = JSON.parse(text);
|
|
37
|
+
var items = flattenGraph(data);
|
|
38
|
+
for (var j = 0; j < items.length; j++) {
|
|
39
|
+
var n = normalizeNode(items[j]);
|
|
40
|
+
if (!n) continue;
|
|
41
|
+
var isProduct = n.types.indexOf('Product') !== -1;
|
|
42
|
+
if (!isProduct) continue;
|
|
43
|
+
out.push({
|
|
44
|
+
type: 'Product',
|
|
45
|
+
name: n.raw.name,
|
|
46
|
+
sku: n.raw.sku,
|
|
47
|
+
offers: n.raw.offers,
|
|
48
|
+
source: 'schema.org'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {}
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {ReturnType<typeof scanJsonLd>} products
|
|
58
|
+
*/
|
|
59
|
+
function suggestActions(products) {
|
|
60
|
+
var actions = [];
|
|
61
|
+
if (products && products.length) {
|
|
62
|
+
actions.push({
|
|
63
|
+
name: 'getProductFromSchema',
|
|
64
|
+
description: 'Return structured product data detected from schema.org JSON-LD on this page',
|
|
65
|
+
source: 'schema.org',
|
|
66
|
+
auto: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
var hasOffer = products && products.some(function (p) { return p.offers; });
|
|
70
|
+
if (hasOffer) {
|
|
71
|
+
actions.push({
|
|
72
|
+
name: 'getOfferPrice',
|
|
73
|
+
description: 'Read price/availability from schema.org Offer if present',
|
|
74
|
+
source: 'schema.org',
|
|
75
|
+
auto: true
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return actions;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Merge manual WAB.init actions with schema-derived runners (read-only helpers).
|
|
83
|
+
* @param {Record<string, object>} manual — same shape as WAB.init({ actions })
|
|
84
|
+
* @param {ReturnType<typeof suggestActions>} suggestions
|
|
85
|
+
*/
|
|
86
|
+
function mergeWithManual(manual, suggestions) {
|
|
87
|
+
manual = manual || {};
|
|
88
|
+
var products = scanJsonLd();
|
|
89
|
+
var extra = {};
|
|
90
|
+
if (suggestions && suggestions.some(function (s) { return s.name === 'getProductFromSchema'; })) {
|
|
91
|
+
extra.getProductFromSchema = {
|
|
92
|
+
description: 'List products from schema.org JSON-LD embedded in the page',
|
|
93
|
+
run: function () {
|
|
94
|
+
return { products: products, count: products.length };
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (suggestions && suggestions.some(function (s) { return s.name === 'getOfferPrice'; })) {
|
|
99
|
+
extra.getOfferPrice = {
|
|
100
|
+
description: 'Extract offer price strings from detected Product nodes',
|
|
101
|
+
run: function () {
|
|
102
|
+
var prices = [];
|
|
103
|
+
products.forEach(function (p) {
|
|
104
|
+
var o = p.offers;
|
|
105
|
+
if (!o) return;
|
|
106
|
+
var list = Array.isArray(o) ? o : [o];
|
|
107
|
+
list.forEach(function (off) {
|
|
108
|
+
if (off && typeof off === 'object') {
|
|
109
|
+
prices.push({
|
|
110
|
+
product: p.name,
|
|
111
|
+
price: off.price,
|
|
112
|
+
priceCurrency: off.priceCurrency,
|
|
113
|
+
availability: off.availability
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
return { offers: prices };
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
var merged = Object.assign({}, extra, manual);
|
|
123
|
+
return { actions: merged };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
global.WABSchema = {
|
|
127
|
+
scanJsonLd: scanJsonLd,
|
|
128
|
+
suggestActions: suggestActions,
|
|
129
|
+
mergeWithManual: mergeWithManual
|
|
130
|
+
};
|
|
131
|
+
})(typeof window !== 'undefined' ? window : globalThis);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the WAB browser client (wab.min.js).
|
|
3
|
+
* Reference in tsconfig: "types": ["./node_modules/web-agent-bridge/public/script/wab.d.ts"]
|
|
4
|
+
* Or copy this file next to your app and /// <reference path="wab.d.ts" />
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface WABActionParamSpec {
|
|
8
|
+
name: string;
|
|
9
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'any' | string;
|
|
10
|
+
description?: string;
|
|
11
|
+
defaultValue?: unknown;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type WABActionParams = Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
export interface WABActionConfig<TParams extends WABActionParams = WABActionParams, TResult = unknown> {
|
|
18
|
+
description?: string;
|
|
19
|
+
params?: WABActionParamSpec[];
|
|
20
|
+
run: (params: TParams) => TResult | Promise<TResult>;
|
|
21
|
+
handler?: (params: TParams) => TResult | Promise<TResult>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type WABActionsMap = Record<
|
|
25
|
+
string,
|
|
26
|
+
WABActionConfig | ((params: WABActionParams) => unknown | Promise<unknown>)
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
export interface WABInitConfig {
|
|
30
|
+
name?: string;
|
|
31
|
+
actions?: WABActionsMap;
|
|
32
|
+
/** When set, discover() and execute() can proxy to this origin */
|
|
33
|
+
serverUrl?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface WABDiscoveryAction {
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
params?: WABActionParamSpec[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface WABDiscoverResult {
|
|
43
|
+
wab_version: string;
|
|
44
|
+
protocol?: string;
|
|
45
|
+
name: string;
|
|
46
|
+
actions: WABDiscoveryAction[];
|
|
47
|
+
transport?: string[];
|
|
48
|
+
timestamp?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface WABExecuteResult {
|
|
53
|
+
success: boolean;
|
|
54
|
+
error?: string;
|
|
55
|
+
action?: string;
|
|
56
|
+
status?: number;
|
|
57
|
+
data?: unknown;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type WABEventName = 'ready' | 'refresh' | 'execute' | 'action:before' | 'action:after' | string;
|
|
62
|
+
|
|
63
|
+
export interface WABInstance {
|
|
64
|
+
name: string;
|
|
65
|
+
serverUrl: string;
|
|
66
|
+
discover(): Promise<WABDiscoverResult>;
|
|
67
|
+
execute(actionName: string, params?: WABActionParams): Promise<WABExecuteResult>;
|
|
68
|
+
getActions(): string[];
|
|
69
|
+
getAuditLog(): unknown[];
|
|
70
|
+
on(event: WABEventName, fn: (data?: unknown) => void): WABInstance;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface WABStatic {
|
|
74
|
+
version: string;
|
|
75
|
+
init(config?: WABInitConfig): WABInstance;
|
|
76
|
+
connect(serverUrl: string): WABInstance;
|
|
77
|
+
discover(): Promise<WABDiscoverResult>;
|
|
78
|
+
execute(actionName: string, params?: WABActionParams): Promise<WABExecuteResult>;
|
|
79
|
+
_instance: WABInstance | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare global {
|
|
83
|
+
interface Window {
|
|
84
|
+
WAB: WABStatic;
|
|
85
|
+
__wab_protocol?: {
|
|
86
|
+
version: string;
|
|
87
|
+
protocol: string;
|
|
88
|
+
name: string;
|
|
89
|
+
actions: WABDiscoveryAction[];
|
|
90
|
+
transport: string[];
|
|
91
|
+
ready: boolean;
|
|
92
|
+
discover(): Promise<WABDiscoverResult>;
|
|
93
|
+
execute(name: string, params?: WABActionParams): Promise<WABExecuteResult>;
|
|
94
|
+
};
|
|
95
|
+
WABConsent?: {
|
|
96
|
+
showBanner: (options: Record<string, unknown>) => void;
|
|
97
|
+
hasConsent: () => boolean;
|
|
98
|
+
clear: () => void;
|
|
99
|
+
};
|
|
100
|
+
WABSchema?: {
|
|
101
|
+
scanJsonLd: () => unknown[];
|
|
102
|
+
suggestActions: (products: unknown[]) => unknown[];
|
|
103
|
+
mergeWithManual: (manual: WABActionsMap, suggestions: unknown[]) => WABInitConfig;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export {};
|