web-agent-bridge 2.6.0 → 2.7.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/package.json +79 -79
- package/sdk/package.json +22 -14
- package/server/config/plans.js +367 -0
- package/server/middleware/featureGate.js +88 -0
- package/server/migrations/005_marketplace_metering.sql +126 -0
- package/server/routes/runtime.js +313 -3
- package/server/services/hosted-runtime.js +205 -0
- package/server/services/marketplace.js +270 -0
- package/server/services/metering.js +182 -0
package/package.json
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "web-agent-bridge",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Open-source middleware that bridges AI agents and websites — providing a standardized command interface for intelligent automation",
|
|
5
|
-
"main": "server/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"web-agent-bridge": "./bin/cli.js",
|
|
8
|
-
"wab": "./bin/cli.js",
|
|
9
|
-
"wab-agent": "./bin/cli.js"
|
|
10
|
-
},
|
|
11
|
-
"scripts": {
|
|
12
|
-
"start": "node server/index.js",
|
|
13
|
-
"dev": "node server/index.js",
|
|
14
|
-
"test": "jest --forceExit --detectOpenHandles",
|
|
15
|
-
"build:script": "node scripts/build.js",
|
|
16
|
-
"prepublishOnly": "npm test"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"ai",
|
|
20
|
-
"agent",
|
|
21
|
-
"bridge",
|
|
22
|
-
"automation",
|
|
23
|
-
"web",
|
|
24
|
-
"middleware",
|
|
25
|
-
"ai-agent",
|
|
26
|
-
"browser-automation",
|
|
27
|
-
"webdriver-bidi"
|
|
28
|
-
],
|
|
29
|
-
"repository": {
|
|
30
|
-
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/abokenan444/web-agent-bridge.git"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/abokenan444/web-agent-bridge#readme",
|
|
34
|
-
"bugs": {
|
|
35
|
-
"url": "https://github.com/abokenan444/web-agent-bridge/issues"
|
|
36
|
-
},
|
|
37
|
-
"files": [
|
|
38
|
-
"bin/",
|
|
39
|
-
"server/",
|
|
40
|
-
"public/*.html",
|
|
41
|
-
"public/*.txt",
|
|
42
|
-
"public/*.xml",
|
|
43
|
-
"public/*.json",
|
|
44
|
-
"public/css/",
|
|
45
|
-
"public/js/",
|
|
46
|
-
"public/script/",
|
|
47
|
-
"public/assets/",
|
|
48
|
-
"public/.well-known/",
|
|
49
|
-
"script/",
|
|
50
|
-
"sdk/",
|
|
51
|
-
"templates/",
|
|
52
|
-
"examples/",
|
|
53
|
-
"README.md",
|
|
54
|
-
"README.ar.md",
|
|
55
|
-
"LICENSE"
|
|
56
|
-
],
|
|
57
|
-
"engines": {
|
|
58
|
-
"node": ">=18.0.0"
|
|
59
|
-
},
|
|
60
|
-
"license": "MIT",
|
|
61
|
-
"dependencies": {
|
|
62
|
-
"bcryptjs": "^3.0.3",
|
|
63
|
-
"better-sqlite3": "^11.6.0",
|
|
64
|
-
"cors": "^2.8.5",
|
|
65
|
-
"dotenv": "^16.4.5",
|
|
66
|
-
"express": "^4.21.0",
|
|
67
|
-
"express-rate-limit": "^7.4.1",
|
|
68
|
-
"helmet": "^8.0.0",
|
|
69
|
-
"jsonwebtoken": "^9.0.2",
|
|
70
|
-
"nodemailer": "^8.0.3",
|
|
71
|
-
"stripe": "^20.4.1",
|
|
72
|
-
"uuid": "^10.0.0",
|
|
73
|
-
"ws": "^8.20.0"
|
|
74
|
-
},
|
|
75
|
-
"devDependencies": {
|
|
76
|
-
"jest": "^30.3.0",
|
|
77
|
-
"supertest": "^7.2.2"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "web-agent-bridge",
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "Open-source middleware that bridges AI agents and websites — providing a standardized command interface for intelligent automation",
|
|
5
|
+
"main": "server/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"web-agent-bridge": "./bin/cli.js",
|
|
8
|
+
"wab": "./bin/cli.js",
|
|
9
|
+
"wab-agent": "./bin/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "node server/index.js",
|
|
13
|
+
"dev": "node server/index.js",
|
|
14
|
+
"test": "jest --forceExit --detectOpenHandles",
|
|
15
|
+
"build:script": "node scripts/build.js",
|
|
16
|
+
"prepublishOnly": "npm test"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"ai",
|
|
20
|
+
"agent",
|
|
21
|
+
"bridge",
|
|
22
|
+
"automation",
|
|
23
|
+
"web",
|
|
24
|
+
"middleware",
|
|
25
|
+
"ai-agent",
|
|
26
|
+
"browser-automation",
|
|
27
|
+
"webdriver-bidi"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/abokenan444/web-agent-bridge.git"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/abokenan444/web-agent-bridge#readme",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/abokenan444/web-agent-bridge/issues"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"bin/",
|
|
39
|
+
"server/",
|
|
40
|
+
"public/*.html",
|
|
41
|
+
"public/*.txt",
|
|
42
|
+
"public/*.xml",
|
|
43
|
+
"public/*.json",
|
|
44
|
+
"public/css/",
|
|
45
|
+
"public/js/",
|
|
46
|
+
"public/script/",
|
|
47
|
+
"public/assets/",
|
|
48
|
+
"public/.well-known/",
|
|
49
|
+
"script/",
|
|
50
|
+
"sdk/",
|
|
51
|
+
"templates/",
|
|
52
|
+
"examples/",
|
|
53
|
+
"README.md",
|
|
54
|
+
"README.ar.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
],
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18.0.0"
|
|
59
|
+
},
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"bcryptjs": "^3.0.3",
|
|
63
|
+
"better-sqlite3": "^11.6.0",
|
|
64
|
+
"cors": "^2.8.5",
|
|
65
|
+
"dotenv": "^16.4.5",
|
|
66
|
+
"express": "^4.21.0",
|
|
67
|
+
"express-rate-limit": "^7.4.1",
|
|
68
|
+
"helmet": "^8.0.0",
|
|
69
|
+
"jsonwebtoken": "^9.0.2",
|
|
70
|
+
"nodemailer": "^8.0.3",
|
|
71
|
+
"stripe": "^20.4.1",
|
|
72
|
+
"uuid": "^10.0.0",
|
|
73
|
+
"ws": "^8.20.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"jest": "^30.3.0",
|
|
77
|
+
"supertest": "^7.2.2"
|
|
78
|
+
}
|
|
79
|
+
}
|
package/sdk/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "web-agent-bridge-sdk",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"keywords": [
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "web-agent-bridge-sdk",
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"wab",
|
|
9
|
+
"ai-agent",
|
|
10
|
+
"sdk",
|
|
11
|
+
"web-automation",
|
|
12
|
+
"bridge"
|
|
13
|
+
],
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"puppeteer": ">=20.0.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependenciesMeta": {
|
|
18
|
+
"puppeteer": {
|
|
19
|
+
"optional": true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WAB Business Model Configuration
|
|
5
|
+
*
|
|
6
|
+
* Defines what is OPEN (free core for adoption) and what is CLOSED (paid for revenue).
|
|
7
|
+
*
|
|
8
|
+
* Principle: "Open what creates network effects. Close what creates operational value."
|
|
9
|
+
*
|
|
10
|
+
* OPEN (Core — free forever):
|
|
11
|
+
* - WAP Protocol (schema, discovery, permissions)
|
|
12
|
+
* - SDK + Client Runtime (JS, integrations)
|
|
13
|
+
* - Browser Execution Layer (basic)
|
|
14
|
+
* - Adapters (MCP, REST, Browser)
|
|
15
|
+
* - Registry (read-only — search commands, sites, templates)
|
|
16
|
+
* - Basic agent registration & authentication
|
|
17
|
+
*
|
|
18
|
+
* CLOSED (Paid — revenue layer):
|
|
19
|
+
* - Workspace / Control Plane (dashboard, monitoring, agent management)
|
|
20
|
+
* - Advanced Orchestration (scheduling, retries, pipelines, distributed exec)
|
|
21
|
+
* - Observability (tracing, analytics, performance insights)
|
|
22
|
+
* - Enterprise Security (signing, audit logs, compliance, IP allowlists)
|
|
23
|
+
* - Hosted Runtime (cloud execution, auto-scaling)
|
|
24
|
+
* - Marketplace commissions (10-20%)
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// ─── Plans ──────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
const PLANS = {
|
|
30
|
+
free: {
|
|
31
|
+
id: 'free',
|
|
32
|
+
name: 'Free',
|
|
33
|
+
price: 0,
|
|
34
|
+
interval: 'month',
|
|
35
|
+
description: 'Core WAP protocol + SDK for developers & site integration',
|
|
36
|
+
limits: {
|
|
37
|
+
agents: 3,
|
|
38
|
+
tasksPerDay: 50,
|
|
39
|
+
executionsPerDay: 100,
|
|
40
|
+
sessions: 5,
|
|
41
|
+
maxConcurrency: 2,
|
|
42
|
+
replayRecordings: 10,
|
|
43
|
+
computeMinutesPerDay: 10,
|
|
44
|
+
storageMB: 50,
|
|
45
|
+
webhooks: 1,
|
|
46
|
+
customAgents: 1,
|
|
47
|
+
apiCallsPerMinute: 20,
|
|
48
|
+
},
|
|
49
|
+
features: {
|
|
50
|
+
// OPEN — always available
|
|
51
|
+
protocol: true,
|
|
52
|
+
sdk: true,
|
|
53
|
+
browserExecution: true,
|
|
54
|
+
adapters: true, // MCP, REST, Browser adapters
|
|
55
|
+
registryRead: true, // Browse commands, sites, templates
|
|
56
|
+
agentRegistration: true,
|
|
57
|
+
basicAuth: true,
|
|
58
|
+
discovery: true, // /.well-known/agent-tools.json
|
|
59
|
+
capabilityNegotiation: true,
|
|
60
|
+
semanticActions: true, // Basic semantic actions
|
|
61
|
+
communityTemplates: true,
|
|
62
|
+
|
|
63
|
+
// CLOSED — not available on free
|
|
64
|
+
workspace: false,
|
|
65
|
+
advancedOrchestration: false,
|
|
66
|
+
observability: false,
|
|
67
|
+
enterpriseSecurity: false,
|
|
68
|
+
hostedRuntime: false,
|
|
69
|
+
marketplace: false,
|
|
70
|
+
failureAnalysis: false,
|
|
71
|
+
replayEngine: false,
|
|
72
|
+
certification: false,
|
|
73
|
+
llmInference: false,
|
|
74
|
+
prioritySupport: false,
|
|
75
|
+
customDomain: false,
|
|
76
|
+
sla: false,
|
|
77
|
+
auditLog: false,
|
|
78
|
+
advancedAnalytics: false,
|
|
79
|
+
dataExtraction: false,
|
|
80
|
+
trafficIntelligence: false,
|
|
81
|
+
exploitShield: false,
|
|
82
|
+
visionAnalysis: false,
|
|
83
|
+
swarmExecution: false,
|
|
84
|
+
agentMemory: false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
starter: {
|
|
89
|
+
id: 'starter',
|
|
90
|
+
name: 'Starter',
|
|
91
|
+
price: 29,
|
|
92
|
+
interval: 'month',
|
|
93
|
+
stripePrice: process.env.STRIPE_PRICE_STARTER,
|
|
94
|
+
description: 'For developers building production agents',
|
|
95
|
+
limits: {
|
|
96
|
+
agents: 10,
|
|
97
|
+
tasksPerDay: 500,
|
|
98
|
+
executionsPerDay: 1000,
|
|
99
|
+
sessions: 25,
|
|
100
|
+
maxConcurrency: 5,
|
|
101
|
+
replayRecordings: 100,
|
|
102
|
+
computeMinutesPerDay: 60,
|
|
103
|
+
storageMB: 500,
|
|
104
|
+
webhooks: 5,
|
|
105
|
+
customAgents: 5,
|
|
106
|
+
apiCallsPerMinute: 60,
|
|
107
|
+
},
|
|
108
|
+
features: {
|
|
109
|
+
// OPEN
|
|
110
|
+
protocol: true,
|
|
111
|
+
sdk: true,
|
|
112
|
+
browserExecution: true,
|
|
113
|
+
adapters: true,
|
|
114
|
+
registryRead: true,
|
|
115
|
+
agentRegistration: true,
|
|
116
|
+
basicAuth: true,
|
|
117
|
+
discovery: true,
|
|
118
|
+
capabilityNegotiation: true,
|
|
119
|
+
semanticActions: true,
|
|
120
|
+
communityTemplates: true,
|
|
121
|
+
|
|
122
|
+
// PAID — now available
|
|
123
|
+
workspace: true,
|
|
124
|
+
advancedOrchestration: true,
|
|
125
|
+
observability: true, // Basic observability (metrics, logs)
|
|
126
|
+
failureAnalysis: true,
|
|
127
|
+
replayEngine: true,
|
|
128
|
+
llmInference: true,
|
|
129
|
+
advancedAnalytics: true,
|
|
130
|
+
dataExtraction: true,
|
|
131
|
+
agentMemory: true,
|
|
132
|
+
|
|
133
|
+
// Still closed
|
|
134
|
+
enterpriseSecurity: false,
|
|
135
|
+
hostedRuntime: false,
|
|
136
|
+
marketplace: false,
|
|
137
|
+
certification: false,
|
|
138
|
+
prioritySupport: false,
|
|
139
|
+
customDomain: false,
|
|
140
|
+
sla: false,
|
|
141
|
+
auditLog: false,
|
|
142
|
+
trafficIntelligence: false,
|
|
143
|
+
exploitShield: false,
|
|
144
|
+
visionAnalysis: false,
|
|
145
|
+
swarmExecution: false,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
pro: {
|
|
150
|
+
id: 'pro',
|
|
151
|
+
name: 'Pro',
|
|
152
|
+
price: 99,
|
|
153
|
+
interval: 'month',
|
|
154
|
+
stripePrice: process.env.STRIPE_PRICE_PRO,
|
|
155
|
+
description: 'For teams & companies running agents at scale',
|
|
156
|
+
limits: {
|
|
157
|
+
agents: 50,
|
|
158
|
+
tasksPerDay: 5000,
|
|
159
|
+
executionsPerDay: 10000,
|
|
160
|
+
sessions: 100,
|
|
161
|
+
maxConcurrency: 20,
|
|
162
|
+
replayRecordings: 1000,
|
|
163
|
+
computeMinutesPerDay: 300,
|
|
164
|
+
storageMB: 5000,
|
|
165
|
+
webhooks: 25,
|
|
166
|
+
customAgents: 25,
|
|
167
|
+
apiCallsPerMinute: 200,
|
|
168
|
+
},
|
|
169
|
+
features: {
|
|
170
|
+
// All OPEN
|
|
171
|
+
protocol: true, sdk: true, browserExecution: true, adapters: true,
|
|
172
|
+
registryRead: true, agentRegistration: true, basicAuth: true,
|
|
173
|
+
discovery: true, capabilityNegotiation: true, semanticActions: true,
|
|
174
|
+
communityTemplates: true,
|
|
175
|
+
|
|
176
|
+
// All Starter features
|
|
177
|
+
workspace: true, advancedOrchestration: true, observability: true,
|
|
178
|
+
failureAnalysis: true, replayEngine: true, llmInference: true,
|
|
179
|
+
advancedAnalytics: true, dataExtraction: true, agentMemory: true,
|
|
180
|
+
|
|
181
|
+
// New in Pro
|
|
182
|
+
hostedRuntime: true,
|
|
183
|
+
marketplace: true, // Publish & sell on marketplace
|
|
184
|
+
certification: true,
|
|
185
|
+
trafficIntelligence: true,
|
|
186
|
+
exploitShield: true,
|
|
187
|
+
visionAnalysis: true,
|
|
188
|
+
swarmExecution: true,
|
|
189
|
+
auditLog: true,
|
|
190
|
+
customDomain: true,
|
|
191
|
+
|
|
192
|
+
// Enterprise only
|
|
193
|
+
enterpriseSecurity: false,
|
|
194
|
+
prioritySupport: false,
|
|
195
|
+
sla: false,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
enterprise: {
|
|
200
|
+
id: 'enterprise',
|
|
201
|
+
name: 'Enterprise',
|
|
202
|
+
price: null, // Custom pricing
|
|
203
|
+
interval: 'month',
|
|
204
|
+
stripePrice: process.env.STRIPE_PRICE_ENTERPRISE,
|
|
205
|
+
description: 'For organizations needing security, compliance & dedicated support',
|
|
206
|
+
limits: {
|
|
207
|
+
agents: -1, // Unlimited
|
|
208
|
+
tasksPerDay: -1,
|
|
209
|
+
executionsPerDay: -1,
|
|
210
|
+
sessions: -1,
|
|
211
|
+
maxConcurrency: 100,
|
|
212
|
+
replayRecordings: -1,
|
|
213
|
+
computeMinutesPerDay: -1,
|
|
214
|
+
storageMB: -1,
|
|
215
|
+
webhooks: -1,
|
|
216
|
+
customAgents: -1,
|
|
217
|
+
apiCallsPerMinute: 1000,
|
|
218
|
+
},
|
|
219
|
+
features: {
|
|
220
|
+
// Everything
|
|
221
|
+
protocol: true, sdk: true, browserExecution: true, adapters: true,
|
|
222
|
+
registryRead: true, agentRegistration: true, basicAuth: true,
|
|
223
|
+
discovery: true, capabilityNegotiation: true, semanticActions: true,
|
|
224
|
+
communityTemplates: true,
|
|
225
|
+
workspace: true, advancedOrchestration: true, observability: true,
|
|
226
|
+
failureAnalysis: true, replayEngine: true, llmInference: true,
|
|
227
|
+
advancedAnalytics: true, dataExtraction: true, agentMemory: true,
|
|
228
|
+
hostedRuntime: true, marketplace: true, certification: true,
|
|
229
|
+
trafficIntelligence: true, exploitShield: true, visionAnalysis: true,
|
|
230
|
+
swarmExecution: true, auditLog: true, customDomain: true,
|
|
231
|
+
|
|
232
|
+
// Enterprise exclusive
|
|
233
|
+
enterpriseSecurity: true,
|
|
234
|
+
prioritySupport: true,
|
|
235
|
+
sla: true,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// ─── Usage-Based Pricing (Pay-as-you-go overages) ───────────────────
|
|
241
|
+
|
|
242
|
+
const USAGE_PRICING = {
|
|
243
|
+
execution: { unit: 'execution', price: 0.001, description: '$0.001 per execution beyond plan limit' },
|
|
244
|
+
computeMinute: { unit: 'minute', price: 0.01, description: '$0.01 per compute minute beyond plan limit' },
|
|
245
|
+
storage: { unit: 'MB', price: 0.05, description: '$0.05 per MB/month beyond plan limit' },
|
|
246
|
+
llmToken: { unit: '1K tokens', price: 0.002, description: '$0.002 per 1K tokens (pass-through + margin)' },
|
|
247
|
+
agent: { unit: 'agent', price: 2.00, description: '$2/month per additional agent beyond plan limit' },
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// ─── Marketplace Commissions ────────────────────────────────────────
|
|
251
|
+
|
|
252
|
+
const MARKETPLACE = {
|
|
253
|
+
commission: 0.15, // 15% platform fee
|
|
254
|
+
minPrice: 0.99,
|
|
255
|
+
maxPrice: 999.99,
|
|
256
|
+
payoutThreshold: 25.00, // Minimum balance for payout
|
|
257
|
+
categories: [
|
|
258
|
+
'automation', 'scraping', 'commerce', 'analytics',
|
|
259
|
+
'security', 'integration', 'ai-agent', 'template',
|
|
260
|
+
'adapter', 'plugin',
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// ─── Feature Gate Mapping ───────────────────────────────────────────
|
|
265
|
+
// Maps API path patterns to required features
|
|
266
|
+
|
|
267
|
+
const FEATURE_GATES = {
|
|
268
|
+
// Advanced orchestration
|
|
269
|
+
'/tasks': { feature: 'advancedOrchestration', methods: ['POST'] },
|
|
270
|
+
'/tasks/*/pause': { feature: 'advancedOrchestration', methods: ['POST'] },
|
|
271
|
+
'/tasks/*/resume': { feature: 'advancedOrchestration', methods: ['POST'] },
|
|
272
|
+
'/execute/pipeline': { feature: 'advancedOrchestration', methods: ['POST'] },
|
|
273
|
+
|
|
274
|
+
// Observability (write/analysis — reads are free for basic health)
|
|
275
|
+
'/observability/metrics': { feature: 'observability', methods: ['GET'] },
|
|
276
|
+
'/observability/traces': { feature: 'observability', methods: ['GET'] },
|
|
277
|
+
'/observability/logs': { feature: 'observability', methods: ['GET'] },
|
|
278
|
+
|
|
279
|
+
// Replay engine
|
|
280
|
+
'/replay': { feature: 'replayEngine', methods: ['GET', 'POST'] },
|
|
281
|
+
|
|
282
|
+
// Failure analysis
|
|
283
|
+
'/failures': { feature: 'failureAnalysis', methods: ['GET', 'POST'] },
|
|
284
|
+
|
|
285
|
+
// Sessions (beyond free limit)
|
|
286
|
+
'/sessions': { feature: 'workspace', methods: ['POST'] },
|
|
287
|
+
|
|
288
|
+
// Certification
|
|
289
|
+
'/certification/verify': { feature: 'certification', methods: ['POST'] },
|
|
290
|
+
|
|
291
|
+
// LLM
|
|
292
|
+
'/llm/complete': { feature: 'llmInference', methods: ['POST'] },
|
|
293
|
+
'/llm/embed': { feature: 'llmInference', methods: ['POST'] },
|
|
294
|
+
|
|
295
|
+
// Control plane
|
|
296
|
+
'/deployments': { feature: 'workspace', methods: ['POST'] },
|
|
297
|
+
'/policies': { feature: 'workspace', methods: ['POST'] },
|
|
298
|
+
|
|
299
|
+
// Signing (enterprise)
|
|
300
|
+
'/sign': { feature: 'enterpriseSecurity', methods: ['POST'] },
|
|
301
|
+
'/verify': { feature: 'enterpriseSecurity', methods: ['POST'] },
|
|
302
|
+
|
|
303
|
+
// Swarm
|
|
304
|
+
'/premium/v2/swarm': { feature: 'swarmExecution', methods: ['POST'] },
|
|
305
|
+
|
|
306
|
+
// Vision
|
|
307
|
+
'/premium/v2/vision': { feature: 'visionAnalysis', methods: ['POST'] },
|
|
308
|
+
|
|
309
|
+
// Marketplace
|
|
310
|
+
'/marketplace/publish': { feature: 'marketplace', methods: ['POST'] },
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// ─── Helpers ────────────────────────────────────────────────────────
|
|
314
|
+
|
|
315
|
+
function getPlan(tier) {
|
|
316
|
+
return PLANS[tier] || PLANS.free;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function getLimit(tier, limitName) {
|
|
320
|
+
const plan = getPlan(tier);
|
|
321
|
+
return plan.limits[limitName] ?? 0;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function hasFeature(tier, featureName) {
|
|
325
|
+
const plan = getPlan(tier);
|
|
326
|
+
return plan.features[featureName] === true;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function isUnlimited(tier, limitName) {
|
|
330
|
+
return getLimit(tier, limitName) === -1;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function listPlans(includeEnterprise = true) {
|
|
334
|
+
const plans = Object.values(PLANS);
|
|
335
|
+
return includeEnterprise ? plans : plans.filter(p => p.id !== 'enterprise');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function getUpgradePath(currentTier) {
|
|
339
|
+
const order = ['free', 'starter', 'pro', 'enterprise'];
|
|
340
|
+
const idx = order.indexOf(currentTier);
|
|
341
|
+
if (idx === -1 || idx >= order.length - 1) return null;
|
|
342
|
+
return PLANS[order[idx + 1]];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function checkFeatureGate(path, method) {
|
|
346
|
+
for (const [pattern, gate] of Object.entries(FEATURE_GATES)) {
|
|
347
|
+
const regex = new RegExp('^' + pattern.replace(/\*/g, '[^/]+') + '(/|$)');
|
|
348
|
+
if (regex.test(path) && gate.methods.includes(method)) {
|
|
349
|
+
return gate.feature;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return null; // No gate — free access
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
module.exports = {
|
|
356
|
+
PLANS,
|
|
357
|
+
USAGE_PRICING,
|
|
358
|
+
MARKETPLACE,
|
|
359
|
+
FEATURE_GATES,
|
|
360
|
+
getPlan,
|
|
361
|
+
getLimit,
|
|
362
|
+
hasFeature,
|
|
363
|
+
isUnlimited,
|
|
364
|
+
listPlans,
|
|
365
|
+
getUpgradePath,
|
|
366
|
+
checkFeatureGate,
|
|
367
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Feature Gate Middleware for Agent OS
|
|
5
|
+
*
|
|
6
|
+
* Enforces plan-based access control on /api/os/* endpoints.
|
|
7
|
+
* Checks tier features and usage limits before allowing access.
|
|
8
|
+
*
|
|
9
|
+
* OPEN endpoints (always free): protocol, registry read, discovery, adapters read,
|
|
10
|
+
* agent registration, basic health, SDK downloads
|
|
11
|
+
*
|
|
12
|
+
* GATED endpoints: orchestration, observability details, replay, failure analysis,
|
|
13
|
+
* sessions beyond limit, LLM inference, certification, signing, hosted runtime,
|
|
14
|
+
* marketplace publish, swarm, vision
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { checkFeatureGate, hasFeature, getPlan } = require('../config/plans');
|
|
18
|
+
const metering = require('../services/metering');
|
|
19
|
+
const { metrics } = require('../observability');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Feature Gate Middleware
|
|
23
|
+
* Checks if the requesting agent/user has the required feature in their plan.
|
|
24
|
+
*
|
|
25
|
+
* Requires req.agentTier to be set (by auth middleware or license verification).
|
|
26
|
+
* Falls back to 'free' if not set.
|
|
27
|
+
*/
|
|
28
|
+
function featureGate(req, res, next) {
|
|
29
|
+
const tier = req.agentTier || req.session?.tier || 'free';
|
|
30
|
+
const requiredFeature = checkFeatureGate(req.path, req.method);
|
|
31
|
+
|
|
32
|
+
// No gate on this endpoint — free access
|
|
33
|
+
if (!requiredFeature) return next();
|
|
34
|
+
|
|
35
|
+
// Check feature
|
|
36
|
+
if (!hasFeature(tier, requiredFeature)) {
|
|
37
|
+
metrics.increment('feature_gate.denied', 1, { feature: requiredFeature, tier });
|
|
38
|
+
const plan = getPlan(tier);
|
|
39
|
+
return res.status(403).json({
|
|
40
|
+
error: 'Feature not available on your plan',
|
|
41
|
+
feature: requiredFeature,
|
|
42
|
+
currentPlan: tier,
|
|
43
|
+
upgrade: `This feature requires a higher plan. Visit /api/os/plans for available plans.`,
|
|
44
|
+
upgradeUrl: '/api/os/plans',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
metrics.increment('feature_gate.allowed', 1, { feature: requiredFeature, tier });
|
|
49
|
+
next();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Usage Limit Middleware
|
|
54
|
+
* Enforces per-metric limits (executions/day, tasks/day, etc.) based on plan.
|
|
55
|
+
*/
|
|
56
|
+
function usageLimit(metric) {
|
|
57
|
+
return function (req, res, next) {
|
|
58
|
+
const tier = req.agentTier || req.session?.tier || 'free';
|
|
59
|
+
const entityId = req.agentId || req.session?.agentId || req.ip;
|
|
60
|
+
|
|
61
|
+
const result = metering.record(entityId, metric, tier);
|
|
62
|
+
|
|
63
|
+
if (!result.allowed) {
|
|
64
|
+
metrics.increment('usage_limit.exceeded', 1, { metric, tier });
|
|
65
|
+
return res.status(429).json({
|
|
66
|
+
error: 'Usage limit exceeded',
|
|
67
|
+
metric,
|
|
68
|
+
current: result.current,
|
|
69
|
+
limit: result.limit,
|
|
70
|
+
overage: result.overageAmount,
|
|
71
|
+
overageCost: result.overageCost,
|
|
72
|
+
upgrade: 'Upgrade your plan for higher limits or enable pay-as-you-go overages.',
|
|
73
|
+
upgradeUrl: '/api/os/plans',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Attach usage info to response headers
|
|
78
|
+
if (result.limit > 0) {
|
|
79
|
+
res.set('X-WAB-Usage-Current', String(result.current));
|
|
80
|
+
res.set('X-WAB-Usage-Limit', String(result.limit));
|
|
81
|
+
res.set('X-WAB-Usage-Remaining', String(Math.max(0, result.limit - result.current)));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
next();
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { featureGate, usageLimit };
|