@nordsym/apiclaw 1.5.17 → 1.5.19
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/convex/http.js.map +1 -1
- package/convex/http.ts +516 -0
- package/dist/analytics.d.ts +0 -4
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +0 -1
- package/dist/analytics.js.map +1 -1
- package/dist/bin.js +1 -1
- package/dist/cli/commands/mcp-install.d.ts.map +1 -1
- package/dist/cli/commands/mcp-install.js +8 -87
- package/dist/cli/commands/mcp-install.js.map +1 -1
- package/dist/cli/index.js +0 -7
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +38 -43
- package/dist/credentials.js.map +1 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +82 -191
- package/dist/discovery.js.map +1 -1
- package/dist/http-api.d.ts.map +1 -1
- package/dist/http-api.js +33 -17
- package/dist/http-api.js.map +1 -1
- package/dist/proxy.js +1 -1
- package/dist/proxy.js.map +1 -1
- package/landing/next-env.d.ts +0 -1
- package/landing/src/app/api/auth/magic-link/route.ts +1 -1
- package/landing/src/app/auth/verify/page.tsx +0 -6
- package/landing/src/app/dashboard/verify/page.tsx +0 -6
- package/landing/src/app/join/page.tsx +0 -6
- package/landing/src/app/layout.tsx +2 -2
- package/landing/src/app/login/page.tsx +1 -1
- package/landing/src/app/mou/[partnerId]/page.tsx +0 -6
- package/landing/src/app/page.tsx +18 -39
- package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +0 -6
- package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +0 -5
- package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +0 -5
- package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +1 -6
- package/landing/src/app/providers/dashboard/[apiId]/page.tsx +0 -5
- package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +0 -5
- package/landing/src/app/providers/dashboard/layout.tsx +6 -6
- package/landing/src/app/providers/dashboard/login/page.tsx +1 -1
- package/landing/src/app/providers/dashboard/page.tsx +1 -1
- package/landing/src/app/providers/dashboard/verify/page.tsx +0 -6
- package/landing/src/app/providers/layout.tsx +1 -1
- package/landing/src/app/upgrade/page.tsx +0 -6
- package/landing/src/app/workspace/page.tsx +0 -6
- package/landing/src/components/HeroTabs.tsx +2 -2
- package/landing/src/components/{Workspace.tsx → ProviderDashboard.tsx} +2 -2
- package/landing/src/components/VideoDemo.tsx +10 -21
- package/landing/src/lib/mock-data.ts +1 -1
- package/landing/src/lib/stats.json +1 -1
- package/package.json +3 -8
- package/src/analytics.ts +0 -5
- package/src/bin.ts +1 -1
- package/src/cli/commands/mcp-install.ts +8 -90
- package/src/cli/index.ts +0 -8
- package/src/credentials.ts +39 -44
- package/src/discovery.ts +82 -191
- package/src/http-api.ts +34 -18
- package/src/proxy.ts +1 -1
- package/APILAYER_STATUS_2026-03-24.md +0 -38
- package/CHANGELOG-WHITELIST-V2.md +0 -269
- package/HIVR-WHITELIST-STATUS.md +0 -205
- package/HIVR-WHITELIST.md +0 -148
- package/TERMINOLOGY-AUDIT.md +0 -99
- package/TERMINOLOGY-FIXED.md +0 -74
- package/VIDEO-DEMO-GUIDE.md +0 -82
- package/WHITELIST-ARCHITECTURE.md +0 -379
- package/api/discover.ts +0 -71
- package/api/health.ts +0 -20
- package/convex/adminActivate.d.ts +0 -3
- package/convex/adminActivate.js +0 -47
- package/convex/adminStats.d.ts +0 -3
- package/convex/adminStats.js +0 -42
- package/convex/agents.d.ts +0 -54
- package/convex/agents.js +0 -499
- package/convex/analytics.d.ts +0 -5
- package/convex/analytics.js +0 -166
- package/convex/billing.d.ts +0 -88
- package/convex/billing.js +0 -655
- package/convex/capabilities.d.ts +0 -9
- package/convex/capabilities.js +0 -145
- package/convex/chains.d.ts +0 -67
- package/convex/chains.js +0 -1042
- package/convex/credits.d.ts +0 -25
- package/convex/credits.js +0 -186
- package/convex/crons.d.ts +0 -3
- package/convex/crons.js +0 -17
- package/convex/directCall.d.ts +0 -72
- package/convex/directCall.js +0 -627
- package/convex/earnProgress.d.ts +0 -58
- package/convex/earnProgress.js +0 -649
- package/convex/email.d.ts +0 -14
- package/convex/email.js +0 -300
- package/convex/feedback.d.ts +0 -7
- package/convex/feedback.js +0 -227
- package/convex/http.d.ts +0 -3
- package/convex/http.js +0 -910
- package/convex/logs.d.ts +0 -38
- package/convex/logs.js +0 -487
- package/convex/mou.d.ts +0 -6
- package/convex/mou.js +0 -82
- package/convex/providerKeys.d.ts +0 -31
- package/convex/providerKeys.js +0 -257
- package/convex/providers.d.ts +0 -29
- package/convex/providers.js +0 -756
- package/convex/purchases.d.ts +0 -7
- package/convex/purchases.js +0 -157
- package/convex/ratelimit.d.ts +0 -4
- package/convex/ratelimit.js +0 -91
- package/convex/searchLogs.d.ts +0 -4
- package/convex/searchLogs.js +0 -129
- package/convex/spendAlerts.d.ts +0 -36
- package/convex/spendAlerts.js +0 -380
- package/convex/stripeActions.d.ts +0 -19
- package/convex/stripeActions.js +0 -411
- package/convex/teams.d.ts +0 -21
- package/convex/teams.js +0 -215
- package/convex/telemetry.d.ts +0 -4
- package/convex/telemetry.js +0 -74
- package/convex/usage.d.ts +0 -27
- package/convex/usage.js +0 -229
- package/convex/waitlist.d.ts +0 -4
- package/convex/waitlist.js +0 -49
- package/convex/webhooks.d.ts +0 -12
- package/convex/webhooks.js +0 -410
- package/convex/workspaces.d.ts +0 -29
- package/convex/workspaces.js +0 -880
- package/direct-test.mjs +0 -51
- package/dist/access-control.d.ts +0 -45
- package/dist/access-control.d.ts.map +0 -1
- package/dist/access-control.js +0 -142
- package/dist/access-control.js.map +0 -1
- package/dist/chain-types.d.ts +0 -187
- package/dist/chain-types.d.ts.map +0 -1
- package/dist/chain-types.js +0 -33
- package/dist/chain-types.js.map +0 -1
- package/dist/convex/adminActivate.js +0 -46
- package/dist/convex/adminStats.js +0 -41
- package/dist/convex/agents.js +0 -498
- package/dist/convex/analytics.js +0 -165
- package/dist/convex/billing.js +0 -654
- package/dist/convex/capabilities.js +0 -144
- package/dist/convex/chains.js +0 -1041
- package/dist/convex/credits.js +0 -185
- package/dist/convex/crons.js +0 -16
- package/dist/convex/directCall.js +0 -626
- package/dist/convex/earnProgress.js +0 -648
- package/dist/convex/email.js +0 -299
- package/dist/convex/feedback.js +0 -226
- package/dist/convex/http.js +0 -909
- package/dist/convex/logs.js +0 -486
- package/dist/convex/mou.js +0 -81
- package/dist/convex/providerKeys.js +0 -256
- package/dist/convex/providers.js +0 -755
- package/dist/convex/purchases.js +0 -156
- package/dist/convex/ratelimit.js +0 -90
- package/dist/convex/schema.js +0 -709
- package/dist/convex/searchLogs.js +0 -128
- package/dist/convex/spendAlerts.js +0 -379
- package/dist/convex/stripeActions.js +0 -410
- package/dist/convex/teams.js +0 -214
- package/dist/convex/telemetry.js +0 -73
- package/dist/convex/usage.js +0 -228
- package/dist/convex/waitlist.js +0 -48
- package/dist/convex/webhooks.js +0 -409
- package/dist/convex/workspaces.js +0 -879
- package/dist/hivr-whitelist.d.ts +0 -18
- package/dist/hivr-whitelist.d.ts.map +0 -1
- package/dist/hivr-whitelist.js +0 -95
- package/dist/hivr-whitelist.js.map +0 -1
- package/dist/http-server-minimal.d.ts +0 -7
- package/dist/http-server-minimal.d.ts.map +0 -1
- package/dist/http-server-minimal.js +0 -126
- package/dist/http-server-minimal.js.map +0 -1
- package/dist/product-whitelist.d.ts +0 -37
- package/dist/product-whitelist.d.ts.map +0 -1
- package/dist/product-whitelist.js +0 -203
- package/dist/product-whitelist.js.map +0 -1
- package/dist/src/analytics.js +0 -129
- package/dist/src/bin.js +0 -17
- package/dist/src/capability-router.js +0 -240
- package/dist/src/chainExecutor.js +0 -451
- package/dist/src/chainResolver.js +0 -518
- package/dist/src/cli/commands/doctor.js +0 -324
- package/dist/src/cli/commands/mcp-install.js +0 -255
- package/dist/src/cli/commands/restore.js +0 -259
- package/dist/src/cli/commands/setup.js +0 -205
- package/dist/src/cli/commands/uninstall.js +0 -188
- package/dist/src/cli/index.js +0 -111
- package/dist/src/cli.js +0 -302
- package/dist/src/confirmation.js +0 -240
- package/dist/src/credentials.js +0 -357
- package/dist/src/credits.js +0 -260
- package/dist/src/crypto.js +0 -66
- package/dist/src/discovery.js +0 -504
- package/dist/src/enterprise/env.js +0 -123
- package/dist/src/enterprise/script-generator.js +0 -460
- package/dist/src/execute-dynamic.js +0 -473
- package/dist/src/execute.js +0 -1727
- package/dist/src/index.js +0 -2062
- package/dist/src/metered.js +0 -80
- package/dist/src/open-apis.js +0 -276
- package/dist/src/proxy.js +0 -28
- package/dist/src/session.js +0 -86
- package/dist/src/stripe.js +0 -407
- package/dist/src/telemetry.js +0 -49
- package/dist/src/types.js +0 -2
- package/dist/src/utils/backup.js +0 -181
- package/dist/src/utils/config.js +0 -220
- package/dist/src/utils/os.js +0 -105
- package/dist/src/utils/paths.js +0 -159
- package/landing/pages/api/discover.ts +0 -43
- package/landing/pages/api/health.ts +0 -20
- package/scripts/test-whitelist-v2.sh +0 -128
- package/src/access-control.ts +0 -174
- package/src/hivr-whitelist.ts +0 -110
- package/src/http-server-minimal.ts +0 -154
- package/src/product-whitelist.ts +0 -246
- package/test-actual-handlers.ts +0 -92
- package/test-apilayer-all-14.ts +0 -249
- package/test-apilayer-fixed.ts +0 -248
- package/test-direct-endpoints.ts +0 -174
- package/test-exact-endpoints.ts +0 -144
- package/test-final.ts +0 -83
- package/test-full-routing.ts +0 -100
- package/test-handlers-correct.ts +0 -217
- package/test-numverify-key.ts +0 -41
- package/test-via-handlers.ts +0 -92
- package/test-worldnews.mjs +0 -26
package/src/access-control.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Access Control System
|
|
3
|
-
* Controls which products/agents can access which providers
|
|
4
|
-
*
|
|
5
|
-
* Rules format:
|
|
6
|
-
* - Wildcard: "hivr:*" = all Hivr agents
|
|
7
|
-
* - Specific: "hivr:bytebee" = only ByteBee
|
|
8
|
-
* - Product-level: "nordsym:*" = all NordSym agents
|
|
9
|
-
*
|
|
10
|
-
* Provider wildcards:
|
|
11
|
-
* - "*" = all providers
|
|
12
|
-
* - "brave_*" = all Brave providers
|
|
13
|
-
* - Specific: ["brave_search", "groq"]
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
interface AccessRule {
|
|
17
|
-
agentPattern: string;
|
|
18
|
-
allowedProviders: string[];
|
|
19
|
-
description?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Default access rules
|
|
23
|
-
// These can be moved to Convex table for dynamic updates
|
|
24
|
-
const DEFAULT_RULES: AccessRule[] = [
|
|
25
|
-
{
|
|
26
|
-
agentPattern: 'hivr:*',
|
|
27
|
-
allowedProviders: ['*'], // Hivr gets everything
|
|
28
|
-
description: 'All Hivr bees get full access',
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
agentPattern: 'nordsym:*',
|
|
32
|
-
allowedProviders: ['brave_search', 'groq', 'replicate'],
|
|
33
|
-
description: 'NordSym team gets selected providers',
|
|
34
|
-
},
|
|
35
|
-
// Add more rules as needed
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
// Cache for compiled rules
|
|
39
|
-
let compiledRules: {
|
|
40
|
-
pattern: RegExp;
|
|
41
|
-
providers: string[];
|
|
42
|
-
}[] | null = null;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Compile agentPattern to RegExp
|
|
46
|
-
*/
|
|
47
|
-
function compilePattern(pattern: string): RegExp {
|
|
48
|
-
// Convert wildcard pattern to regex
|
|
49
|
-
// "hivr:*" → /^hivr:.+$/
|
|
50
|
-
// "hivr:byte*" → /^hivr:byte.+$/
|
|
51
|
-
const escaped = pattern
|
|
52
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape regex chars
|
|
53
|
-
.replace(/\*/g, '.+'); // Replace * with .+
|
|
54
|
-
|
|
55
|
-
return new RegExp(`^${escaped}$`, 'i');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Compile all rules (cache for performance)
|
|
60
|
-
*/
|
|
61
|
-
function compileRules(): void {
|
|
62
|
-
compiledRules = DEFAULT_RULES.map(rule => ({
|
|
63
|
-
pattern: compilePattern(rule.agentPattern),
|
|
64
|
-
providers: rule.allowedProviders,
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Check if provider matches pattern
|
|
70
|
-
*/
|
|
71
|
-
function matchesProvider(provider: string, pattern: string): boolean {
|
|
72
|
-
if (pattern === '*') return true;
|
|
73
|
-
if (pattern.endsWith('*')) {
|
|
74
|
-
const prefix = pattern.slice(0, -1);
|
|
75
|
-
return provider.startsWith(prefix);
|
|
76
|
-
}
|
|
77
|
-
return provider === pattern;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Check if agentId is allowed to access provider
|
|
82
|
-
*/
|
|
83
|
-
export function canAccessProvider(agentId: string, provider: string): boolean {
|
|
84
|
-
if (!compiledRules) {
|
|
85
|
-
compileRules();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const normalized = agentId.toLowerCase().trim();
|
|
89
|
-
const normalizedProvider = provider.toLowerCase().trim();
|
|
90
|
-
|
|
91
|
-
// Find matching rule
|
|
92
|
-
for (const rule of compiledRules!) {
|
|
93
|
-
if (rule.pattern.test(normalized)) {
|
|
94
|
-
// Check if provider is allowed
|
|
95
|
-
for (const providerPattern of rule.providers) {
|
|
96
|
-
if (matchesProvider(normalizedProvider, providerPattern)) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// Rule matched but provider not in allowlist
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// No rule matched = deny by default
|
|
106
|
-
console.warn(`[Access Control] No rule for ${normalized}`);
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get allowed providers for agentId
|
|
112
|
-
*/
|
|
113
|
-
export function getAllowedProviders(agentId: string): string[] {
|
|
114
|
-
if (!compiledRules) {
|
|
115
|
-
compileRules();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const normalized = agentId.toLowerCase().trim();
|
|
119
|
-
|
|
120
|
-
// Find matching rule
|
|
121
|
-
for (const rule of compiledRules!) {
|
|
122
|
-
if (rule.pattern.test(normalized)) {
|
|
123
|
-
return rule.providers;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Add new access rule (runtime)
|
|
132
|
-
*/
|
|
133
|
-
export function addAccessRule(rule: AccessRule): void {
|
|
134
|
-
DEFAULT_RULES.push(rule);
|
|
135
|
-
compiledRules = null; // Force recompile
|
|
136
|
-
console.log(`[Access Control] Added rule for ${rule.agentPattern}`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Get all access rules (for debugging/admin)
|
|
141
|
-
*/
|
|
142
|
-
export function getAccessRules(): AccessRule[] {
|
|
143
|
-
return [...DEFAULT_RULES];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Check if agentId + provider combination is allowed
|
|
148
|
-
* Combines whitelist check + access control
|
|
149
|
-
*/
|
|
150
|
-
export async function isAllowed(
|
|
151
|
-
agentId: string | undefined,
|
|
152
|
-
provider: string
|
|
153
|
-
): Promise<{ allowed: boolean; reason?: string }> {
|
|
154
|
-
if (!agentId) {
|
|
155
|
-
return { allowed: false, reason: 'No agentId provided' };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// First check: Is agent whitelisted?
|
|
159
|
-
const { isAuthorized } = await import('./product-whitelist.js');
|
|
160
|
-
const whitelisted = await isAuthorized(agentId);
|
|
161
|
-
|
|
162
|
-
if (!whitelisted) {
|
|
163
|
-
return { allowed: false, reason: 'Agent not whitelisted' };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Second check: Does agent have access to this provider?
|
|
167
|
-
const hasAccess = canAccessProvider(agentId, provider);
|
|
168
|
-
|
|
169
|
-
if (!hasAccess) {
|
|
170
|
-
return { allowed: false, reason: 'Provider not in access list' };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return { allowed: true };
|
|
174
|
-
}
|
package/src/hivr-whitelist.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hivr Bees Auto-Whitelist
|
|
3
|
-
* Dynamically fetches active agents from Hivr's Convex deployment
|
|
4
|
-
* Falls back to static whitelist if Convex is unreachable
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Hivr PROD Convex deployment
|
|
8
|
-
const HIVR_CONVEX_URL = "https://sensible-quail-275.convex.cloud";
|
|
9
|
-
|
|
10
|
-
// Fallback static whitelist (in case Convex is down)
|
|
11
|
-
const STATIC_WHITELIST = [
|
|
12
|
-
'bytebee',
|
|
13
|
-
'analyzerbee',
|
|
14
|
-
'buildbee',
|
|
15
|
-
'buzzwriter',
|
|
16
|
-
'hivemind',
|
|
17
|
-
'hivesage',
|
|
18
|
-
'symbot',
|
|
19
|
-
'hivrqueen',
|
|
20
|
-
'marketmaven',
|
|
21
|
-
'reconbee',
|
|
22
|
-
'sprintbee',
|
|
23
|
-
'quillbee',
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
// Cache whitelist for 5 minutes
|
|
27
|
-
let cachedWhitelist: string[] | null = null;
|
|
28
|
-
let cacheExpiry: number = 0;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Fetch all active agents from Hivr Convex
|
|
32
|
-
*/
|
|
33
|
-
async function fetchHivrAgents(): Promise<string[]> {
|
|
34
|
-
try {
|
|
35
|
-
// Call Convex HTTP API directly
|
|
36
|
-
const response = await fetch(`${HIVR_CONVEX_URL}/api/query`, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: {
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
},
|
|
41
|
-
body: JSON.stringify({
|
|
42
|
-
path: 'agents:list',
|
|
43
|
-
args: {},
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (!response.ok) {
|
|
48
|
-
console.warn('[Hivr Whitelist] Convex HTTP API error, using static whitelist');
|
|
49
|
-
return STATIC_WHITELIST;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const agents = await response.json() as any[];
|
|
53
|
-
|
|
54
|
-
if (!agents || !Array.isArray(agents)) {
|
|
55
|
-
console.warn('[Hivr Whitelist] Invalid response from Hivr Convex, using static whitelist');
|
|
56
|
-
return STATIC_WHITELIST;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Extract handles (Hivr uses 'handle', not 'agentId')
|
|
60
|
-
const handles = agents
|
|
61
|
-
.map((a: any) => a.handle?.toLowerCase().trim())
|
|
62
|
-
.filter((h: string | undefined) => h && h.length > 0);
|
|
63
|
-
|
|
64
|
-
console.log(`[Hivr Whitelist] Fetched ${handles.length} agents from Hivr`);
|
|
65
|
-
return handles;
|
|
66
|
-
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error('[Hivr Whitelist] Failed to fetch from Hivr Convex:', error);
|
|
69
|
-
return STATIC_WHITELIST;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get current whitelist (cached or fresh)
|
|
75
|
-
*/
|
|
76
|
-
export async function getWhitelist(): Promise<string[]> {
|
|
77
|
-
const now = Date.now();
|
|
78
|
-
|
|
79
|
-
// Return cached if still valid
|
|
80
|
-
if (cachedWhitelist && now < cacheExpiry) {
|
|
81
|
-
return cachedWhitelist;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Fetch fresh whitelist
|
|
85
|
-
cachedWhitelist = await fetchHivrAgents();
|
|
86
|
-
cacheExpiry = now + (5 * 60 * 1000); // 5 minutes
|
|
87
|
-
|
|
88
|
-
return cachedWhitelist;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Check if agent is authorized
|
|
93
|
-
*/
|
|
94
|
-
export async function isAuthorized(agentId: string | undefined): Promise<boolean> {
|
|
95
|
-
if (!agentId) return false;
|
|
96
|
-
|
|
97
|
-
const whitelist = await getWhitelist();
|
|
98
|
-
const normalized = agentId.toLowerCase().trim();
|
|
99
|
-
|
|
100
|
-
return whitelist.includes(normalized);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Force refresh whitelist (call after adding new bee)
|
|
105
|
-
*/
|
|
106
|
-
export function invalidateCache(): void {
|
|
107
|
-
cachedWhitelist = null;
|
|
108
|
-
cacheExpiry = 0;
|
|
109
|
-
console.log('[Hivr Whitelist] Cache invalidated');
|
|
110
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Minimal HTTP API Server for APIClaw
|
|
4
|
-
* Bypasses chain executor imports
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createServer } from 'http';
|
|
8
|
-
import { URL } from 'url';
|
|
9
|
-
|
|
10
|
-
const PORT = parseInt(process.env.PORT || '3001');
|
|
11
|
-
|
|
12
|
-
// Import whitelist directly
|
|
13
|
-
import { isAuthorized, getProduct } from './product-whitelist.js';
|
|
14
|
-
|
|
15
|
-
interface APIRequest {
|
|
16
|
-
provider: string;
|
|
17
|
-
action: string;
|
|
18
|
-
params: Record<string, any>;
|
|
19
|
-
agentId: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function sendJSON(res: any, status: number, data: any): void {
|
|
23
|
-
res.writeHead(status, {
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
'Access-Control-Allow-Origin': '*',
|
|
26
|
-
});
|
|
27
|
-
res.end(JSON.stringify(data));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function parseBody<T>(req: any): Promise<T> {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
let body = '';
|
|
33
|
-
req.on('data', (chunk: any) => body += chunk.toString());
|
|
34
|
-
req.on('end', () => {
|
|
35
|
-
try {
|
|
36
|
-
resolve(JSON.parse(body));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(new Error('Invalid JSON'));
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const server = createServer(async (req, res) => {
|
|
45
|
-
const url = new URL(req.url || '/', `http://${req.headers.host}`);
|
|
46
|
-
|
|
47
|
-
console.log(`[APIClaw] ${req.method} ${url.pathname}`);
|
|
48
|
-
|
|
49
|
-
// CORS
|
|
50
|
-
if (req.method === 'OPTIONS') {
|
|
51
|
-
res.writeHead(204, {
|
|
52
|
-
'Access-Control-Allow-Origin': '*',
|
|
53
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
54
|
-
'Access-Control-Allow-Headers': 'Content-Type',
|
|
55
|
-
});
|
|
56
|
-
res.end();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Health check
|
|
61
|
-
if (url.pathname === '/health') {
|
|
62
|
-
sendJSON(res, 200, {
|
|
63
|
-
status: 'ok',
|
|
64
|
-
service: 'apiclaw-http-api',
|
|
65
|
-
version: '2.0.0',
|
|
66
|
-
whitelist: 'multi-product',
|
|
67
|
-
});
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Discovery endpoint
|
|
72
|
-
if (url.pathname === '/api/discover' && req.method === 'GET') {
|
|
73
|
-
const query = url.searchParams.get('query');
|
|
74
|
-
const agentId = url.searchParams.get('agentId');
|
|
75
|
-
|
|
76
|
-
if (!query) {
|
|
77
|
-
sendJSON(res, 400, { error: 'Missing query parameter' });
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const authorized = await isAuthorized(agentId || undefined);
|
|
82
|
-
|
|
83
|
-
if (!authorized) {
|
|
84
|
-
sendJSON(res, 403, {
|
|
85
|
-
error: 'Unauthorized',
|
|
86
|
-
message: 'This endpoint is restricted. Contact admin@nordsym.com',
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const product = agentId ? getProduct(agentId) : null;
|
|
92
|
-
|
|
93
|
-
sendJSON(res, 200, {
|
|
94
|
-
success: true,
|
|
95
|
-
query,
|
|
96
|
-
agentId,
|
|
97
|
-
product,
|
|
98
|
-
message: 'Whitelist v2.0 active - discovery endpoint placeholder',
|
|
99
|
-
});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Call API endpoint
|
|
104
|
-
if (url.pathname === '/api/call_api' && req.method === 'POST') {
|
|
105
|
-
try {
|
|
106
|
-
const body = await parseBody<APIRequest>(req);
|
|
107
|
-
const { provider, action, params, agentId } = body;
|
|
108
|
-
|
|
109
|
-
if (!provider || !action || !agentId) {
|
|
110
|
-
sendJSON(res, 400, {
|
|
111
|
-
error: 'Missing required fields',
|
|
112
|
-
required: ['provider', 'action', 'agentId', 'params'],
|
|
113
|
-
});
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const authorized = await isAuthorized(agentId);
|
|
118
|
-
|
|
119
|
-
if (!authorized) {
|
|
120
|
-
sendJSON(res, 403, {
|
|
121
|
-
error: 'Unauthorized',
|
|
122
|
-
message: 'Agent not whitelisted',
|
|
123
|
-
});
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const product = getProduct(agentId);
|
|
128
|
-
|
|
129
|
-
sendJSON(res, 200, {
|
|
130
|
-
success: true,
|
|
131
|
-
agentId,
|
|
132
|
-
provider,
|
|
133
|
-
action,
|
|
134
|
-
product,
|
|
135
|
-
message: 'Whitelist v2.0 active - execution placeholder',
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
} catch (e: any) {
|
|
139
|
-
sendJSON(res, 400, { error: e.message });
|
|
140
|
-
}
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// 404
|
|
145
|
-
sendJSON(res, 404, { error: 'Not found' });
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
server.listen(PORT, () => {
|
|
149
|
-
console.log(`\n🦞 APIClaw HTTP API (Whitelist v2.0)`);
|
|
150
|
-
console.log(` Running on http://localhost:${PORT}`);
|
|
151
|
-
console.log(` GET /health`);
|
|
152
|
-
console.log(` GET /api/discover?query=...&agentId=...`);
|
|
153
|
-
console.log(` POST /api/call_api\n`);
|
|
154
|
-
});
|
package/src/product-whitelist.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multi-Product Whitelist System
|
|
3
|
-
* Supports multiple products (Hivr, NordSym, partners) with namespaced agentIds
|
|
4
|
-
*
|
|
5
|
-
* Format: product:agentId
|
|
6
|
-
* Examples: hivr:bytebee, nordsym:mollebot, partner_x:agent1
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
interface ProductSource {
|
|
10
|
-
name: string;
|
|
11
|
-
convexUrl: string;
|
|
12
|
-
queryPath: string;
|
|
13
|
-
agentIdField: string;
|
|
14
|
-
authToken?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Product sources configuration
|
|
18
|
-
const PRODUCT_SOURCES: ProductSource[] = [
|
|
19
|
-
{
|
|
20
|
-
name: 'hivr',
|
|
21
|
-
convexUrl: 'https://sensible-quail-275.convex.cloud',
|
|
22
|
-
queryPath: 'agents:list',
|
|
23
|
-
agentIdField: 'handle', // ✅ Fixed: Hivr agents use 'handle', not 'agentId'
|
|
24
|
-
},
|
|
25
|
-
// Add more products here as needed
|
|
26
|
-
// {
|
|
27
|
-
// name: 'nordsym',
|
|
28
|
-
// convexUrl: 'https://nordsym-deployment.convex.cloud',
|
|
29
|
-
// queryPath: 'team:listAgents',
|
|
30
|
-
// agentIdField: 'memberId',
|
|
31
|
-
// },
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
// Fallback static whitelist (emergency only)
|
|
35
|
-
const STATIC_WHITELIST = [
|
|
36
|
-
'hivr:bytebee',
|
|
37
|
-
'hivr:analyzerbee',
|
|
38
|
-
'hivr:buildbee',
|
|
39
|
-
'hivr:buzzwriter',
|
|
40
|
-
'hivr:hivemind',
|
|
41
|
-
'hivr:hivesage',
|
|
42
|
-
'hivr:symbot',
|
|
43
|
-
'hivr:hivrqueen',
|
|
44
|
-
'hivr:marketmaven',
|
|
45
|
-
'hivr:reconbee',
|
|
46
|
-
'hivr:sprintbee',
|
|
47
|
-
'hivr:quillbee',
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
// Cache per product (5 minutes TTL)
|
|
51
|
-
interface ProductCache {
|
|
52
|
-
agents: string[];
|
|
53
|
-
expiresAt: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const cache = new Map<string, ProductCache>();
|
|
57
|
-
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Fetch agents from a single product source
|
|
61
|
-
*/
|
|
62
|
-
async function fetchFromProduct(source: ProductSource): Promise<string[]> {
|
|
63
|
-
try {
|
|
64
|
-
const headers: Record<string, string> = {
|
|
65
|
-
'Content-Type': 'application/json',
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
if (source.authToken) {
|
|
69
|
-
headers['Authorization'] = `Bearer ${source.authToken}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const response = await fetch(`${source.convexUrl}/api/query`, {
|
|
73
|
-
method: 'POST',
|
|
74
|
-
headers,
|
|
75
|
-
body: JSON.stringify({
|
|
76
|
-
path: source.queryPath,
|
|
77
|
-
args: {},
|
|
78
|
-
}),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
console.warn(`[Whitelist] ${source.name}: HTTP ${response.status}`);
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const result = await response.json() as any;
|
|
87
|
-
|
|
88
|
-
// Convex HTTP API returns { status: "success", value: [...] }
|
|
89
|
-
const data = result.value || result;
|
|
90
|
-
|
|
91
|
-
if (!Array.isArray(data)) {
|
|
92
|
-
console.warn(`[Whitelist] ${source.name}: Invalid response format`, typeof data);
|
|
93
|
-
return [];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Extract agentIds and add namespace
|
|
97
|
-
const agents = data
|
|
98
|
-
.map((item: any) => {
|
|
99
|
-
const agentId = item[source.agentIdField];
|
|
100
|
-
if (!agentId) return null;
|
|
101
|
-
return `${source.name}:${String(agentId).toLowerCase().trim()}`;
|
|
102
|
-
})
|
|
103
|
-
.filter((id): id is string => id !== null && id.length > 0);
|
|
104
|
-
|
|
105
|
-
console.log(`[Whitelist] ${source.name}: Fetched ${agents.length} agents`);
|
|
106
|
-
return agents;
|
|
107
|
-
|
|
108
|
-
} catch (error) {
|
|
109
|
-
console.error(`[Whitelist] ${source.name}: Fetch failed`, error);
|
|
110
|
-
return [];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Fetch and merge agents from all product sources
|
|
116
|
-
*/
|
|
117
|
-
async function fetchAllProducts(): Promise<string[]> {
|
|
118
|
-
const results = await Promise.allSettled(
|
|
119
|
-
PRODUCT_SOURCES.map(source => fetchFromProduct(source))
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const allAgents: string[] = [];
|
|
123
|
-
|
|
124
|
-
for (const result of results) {
|
|
125
|
-
if (result.status === 'fulfilled') {
|
|
126
|
-
allAgents.push(...result.value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// If no products returned data, use static fallback
|
|
131
|
-
if (allAgents.length === 0) {
|
|
132
|
-
console.warn('[Whitelist] All sources failed, using static fallback');
|
|
133
|
-
return STATIC_WHITELIST;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return allAgents;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Get current whitelist (cached or fresh)
|
|
141
|
-
*/
|
|
142
|
-
export async function getWhitelist(): Promise<string[]> {
|
|
143
|
-
const now = Date.now();
|
|
144
|
-
|
|
145
|
-
// Check if any cache entry is still valid
|
|
146
|
-
const validCaches: string[] = [];
|
|
147
|
-
for (const [product, cached] of cache.entries()) {
|
|
148
|
-
if (now < cached.expiresAt) {
|
|
149
|
-
validCaches.push(...cached.agents);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// If all caches valid, return merged
|
|
154
|
-
if (validCaches.length > 0 && cache.size === PRODUCT_SOURCES.length) {
|
|
155
|
-
return validCaches;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Fetch fresh data
|
|
159
|
-
const agents = await fetchAllProducts();
|
|
160
|
-
|
|
161
|
-
// Update cache per product
|
|
162
|
-
const agentsByProduct = new Map<string, string[]>();
|
|
163
|
-
for (const agent of agents) {
|
|
164
|
-
const [product] = agent.split(':');
|
|
165
|
-
if (!agentsByProduct.has(product)) {
|
|
166
|
-
agentsByProduct.set(product, []);
|
|
167
|
-
}
|
|
168
|
-
agentsByProduct.get(product)!.push(agent);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
for (const [product, productAgents] of agentsByProduct.entries()) {
|
|
172
|
-
cache.set(product, {
|
|
173
|
-
agents: productAgents,
|
|
174
|
-
expiresAt: now + CACHE_TTL,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return agents;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Check if agentId is authorized
|
|
183
|
-
* Supports both namespaced (product:agent) and legacy (agent) formats
|
|
184
|
-
*/
|
|
185
|
-
export async function isAuthorized(agentId: string | undefined): Promise<boolean> {
|
|
186
|
-
if (!agentId) return false;
|
|
187
|
-
|
|
188
|
-
const normalized = agentId.toLowerCase().trim();
|
|
189
|
-
const whitelist = await getWhitelist();
|
|
190
|
-
|
|
191
|
-
// Check exact match (namespaced)
|
|
192
|
-
if (whitelist.includes(normalized)) {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Legacy support: check if agentId matches any product's agent (without namespace)
|
|
197
|
-
// e.g., "bytebee" matches "hivr:bytebee"
|
|
198
|
-
if (!normalized.includes(':')) {
|
|
199
|
-
const legacyMatch = whitelist.some(entry => {
|
|
200
|
-
const [, agent] = entry.split(':');
|
|
201
|
-
return agent === normalized;
|
|
202
|
-
});
|
|
203
|
-
if (legacyMatch) {
|
|
204
|
-
console.log(`[Whitelist] Legacy match for ${normalized}`);
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Extract product name from agentId
|
|
214
|
-
*/
|
|
215
|
-
export function getProduct(agentId: string): string | null {
|
|
216
|
-
const [product] = agentId.split(':');
|
|
217
|
-
return product || null;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Force refresh whitelist (call after adding new agent)
|
|
222
|
-
*/
|
|
223
|
-
export function invalidateCache(product?: string): void {
|
|
224
|
-
if (product) {
|
|
225
|
-
cache.delete(product);
|
|
226
|
-
console.log(`[Whitelist] Cache invalidated for ${product}`);
|
|
227
|
-
} else {
|
|
228
|
-
cache.clear();
|
|
229
|
-
console.log('[Whitelist] All caches invalidated');
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Add new product source dynamically
|
|
235
|
-
*/
|
|
236
|
-
export function addProductSource(source: ProductSource): void {
|
|
237
|
-
const existing = PRODUCT_SOURCES.find(s => s.name === source.name);
|
|
238
|
-
if (existing) {
|
|
239
|
-
console.warn(`[Whitelist] Product ${source.name} already exists, updating`);
|
|
240
|
-
Object.assign(existing, source);
|
|
241
|
-
} else {
|
|
242
|
-
PRODUCT_SOURCES.push(source);
|
|
243
|
-
console.log(`[Whitelist] Added product source: ${source.name}`);
|
|
244
|
-
}
|
|
245
|
-
invalidateCache(source.name);
|
|
246
|
-
}
|