@nordsym/apiclaw 1.5.9 → 1.5.10

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.
Files changed (72) hide show
  1. package/CHANGELOG-WHITELIST-V2.md +269 -0
  2. package/HIVR-INTEGRATION.md +281 -0
  3. package/HIVR-WHITELIST-STATUS.md +205 -0
  4. package/HIVR-WHITELIST.md +148 -0
  5. package/WHITELIST-ARCHITECTURE.md +379 -0
  6. package/api/discover.ts +71 -0
  7. package/api/health.ts +20 -0
  8. package/convex/http.d.ts.map +1 -1
  9. package/convex/http.js +8 -0
  10. package/convex/http.js.map +1 -1
  11. package/convex/http.ts +8 -0
  12. package/dist/access-control.d.ts +45 -0
  13. package/dist/access-control.d.ts.map +1 -0
  14. package/dist/access-control.js +142 -0
  15. package/dist/access-control.js.map +1 -0
  16. package/dist/analytics.d.ts +4 -0
  17. package/dist/analytics.d.ts.map +1 -1
  18. package/dist/analytics.js +1 -0
  19. package/dist/analytics.js.map +1 -1
  20. package/dist/credentials.d.ts.map +1 -1
  21. package/dist/credentials.js +20 -0
  22. package/dist/credentials.js.map +1 -1
  23. package/dist/execute.d.ts.map +1 -1
  24. package/dist/execute.js +245 -0
  25. package/dist/execute.js.map +1 -1
  26. package/dist/hivr-whitelist.d.ts +18 -0
  27. package/dist/hivr-whitelist.d.ts.map +1 -0
  28. package/dist/hivr-whitelist.js +95 -0
  29. package/dist/hivr-whitelist.js.map +1 -0
  30. package/dist/http-api.d.ts.map +1 -1
  31. package/dist/http-api.js +17 -33
  32. package/dist/http-api.js.map +1 -1
  33. package/dist/http-server-minimal.d.ts +7 -0
  34. package/dist/http-server-minimal.d.ts.map +1 -0
  35. package/dist/http-server-minimal.js +126 -0
  36. package/dist/http-server-minimal.js.map +1 -0
  37. package/dist/product-whitelist.d.ts +37 -0
  38. package/dist/product-whitelist.d.ts.map +1 -0
  39. package/dist/product-whitelist.js +203 -0
  40. package/dist/product-whitelist.js.map +1 -0
  41. package/dist/proxy.d.ts.map +1 -1
  42. package/dist/proxy.js +1 -1
  43. package/dist/proxy.js.map +1 -1
  44. package/landing/next-env.d.ts +1 -0
  45. package/landing/pages/api/discover.ts +43 -0
  46. package/landing/pages/api/health.ts +20 -0
  47. package/landing/src/app/auth/verify/page.tsx +6 -0
  48. package/landing/src/app/dashboard/verify/page.tsx +6 -0
  49. package/landing/src/app/join/page.tsx +6 -0
  50. package/landing/src/app/mou/[partnerId]/page.tsx +6 -0
  51. package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +6 -0
  52. package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +5 -0
  53. package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +5 -0
  54. package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +5 -0
  55. package/landing/src/app/providers/dashboard/[apiId]/page.tsx +5 -0
  56. package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +5 -0
  57. package/landing/src/app/providers/dashboard/layout.tsx +6 -6
  58. package/landing/src/app/providers/dashboard/verify/page.tsx +6 -0
  59. package/landing/src/app/upgrade/page.tsx +6 -0
  60. package/landing/src/app/workspace/page.tsx +6 -0
  61. package/landing/src/lib/stats.json +1 -1
  62. package/package.json +4 -2
  63. package/scripts/test-whitelist-v2.sh +128 -0
  64. package/src/access-control.ts +174 -0
  65. package/src/analytics.ts +5 -0
  66. package/src/credentials.ts +20 -0
  67. package/src/execute.ts +247 -0
  68. package/src/hivr-whitelist.ts +110 -0
  69. package/src/http-api.ts +18 -34
  70. package/src/http-server-minimal.ts +154 -0
  71. package/src/product-whitelist.ts +246 -0
  72. package/src/proxy.ts +1 -1
@@ -0,0 +1,246 @@
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
+ }
package/src/proxy.ts CHANGED
@@ -33,4 +33,4 @@ export async function callProxy(provider: string, params: any): Promise<any> {
33
33
  return response.json();
34
34
  }
35
35
 
36
- export const PROXY_PROVIDERS = ["openrouter", "brave_search", "resend", "elevenlabs", "46elks", "twilio", "replicate", "firecrawl", "e2b", "groq", "deepgram", "serper", "mistral", "cohere", "together", "stability", "assemblyai", "github"];
36
+ export const PROXY_PROVIDERS = ["openrouter", "brave_search", "resend", "elevenlabs", "46elks", "twilio", "replicate", "firecrawl", "e2b", "groq", "deepgram", "serper", "mistral", "cohere", "together", "stability", "assemblyai", "github", "apilayer"];