@nordsym/apiclaw 2.2.0 → 2.2.1

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 (176) hide show
  1. package/README.md +15 -2
  2. package/dist/bin-http.js +0 -0
  3. package/dist/bin.bundled.js +79288 -0
  4. package/dist/gateway-client.d.ts.map +1 -1
  5. package/dist/gateway-client.js +24 -2
  6. package/dist/gateway-client.js.map +1 -1
  7. package/dist/index.bundled.js +61263 -0
  8. package/dist/index.js +2 -2
  9. package/dist/index.js.map +1 -1
  10. package/package.json +7 -2
  11. package/.claude/settings.local.json +0 -13
  12. package/.env.prod +0 -1
  13. package/apiclaw-README.md +0 -494
  14. package/convex/_generated/api.d.ts +0 -145
  15. package/convex/_generated/api.js +0 -23
  16. package/convex/_generated/dataModel.d.ts +0 -60
  17. package/convex/_generated/server.d.ts +0 -143
  18. package/convex/_generated/server.js +0 -93
  19. package/convex/_listWorkspaces.ts +0 -13
  20. package/convex/adminActivate.ts +0 -53
  21. package/convex/adminStats.ts +0 -306
  22. package/convex/agents.ts +0 -939
  23. package/convex/analytics.ts +0 -187
  24. package/convex/apiKeys.ts +0 -220
  25. package/convex/backfillAnalytics.ts +0 -272
  26. package/convex/backfillSearchLogs.ts +0 -35
  27. package/convex/billing.ts +0 -834
  28. package/convex/capabilities.ts +0 -157
  29. package/convex/chains.ts +0 -1318
  30. package/convex/credits.ts +0 -211
  31. package/convex/crons.ts +0 -65
  32. package/convex/debugFilestackLogs.ts +0 -16
  33. package/convex/debugGetToken.ts +0 -18
  34. package/convex/directCall.ts +0 -713
  35. package/convex/earnProgress.ts +0 -753
  36. package/convex/email.ts +0 -329
  37. package/convex/feedback.ts +0 -265
  38. package/convex/funnel.ts +0 -431
  39. package/convex/guards.ts +0 -174
  40. package/convex/http.ts +0 -3756
  41. package/convex/inbound.ts +0 -32
  42. package/convex/logs.ts +0 -701
  43. package/convex/migrateFilestack.ts +0 -81
  44. package/convex/migratePartnersProd.ts +0 -174
  45. package/convex/migratePratham.ts +0 -126
  46. package/convex/migrateProviderWorkspaces.ts +0 -175
  47. package/convex/mou.ts +0 -91
  48. package/convex/nurture.ts +0 -355
  49. package/convex/providerKeys.ts +0 -289
  50. package/convex/providers.ts +0 -1135
  51. package/convex/purchases.ts +0 -183
  52. package/convex/ratelimit.ts +0 -104
  53. package/convex/schema.ts +0 -926
  54. package/convex/searchLogs.ts +0 -265
  55. package/convex/seedAPILayerAPIs.ts +0 -191
  56. package/convex/seedDirectCallConfigs.ts +0 -336
  57. package/convex/seedPratham.ts +0 -149
  58. package/convex/spendAlerts.ts +0 -442
  59. package/convex/stripeActions.ts +0 -607
  60. package/convex/teams.ts +0 -243
  61. package/convex/telemetry.ts +0 -81
  62. package/convex/tsconfig.json +0 -25
  63. package/convex/updateAPIStatus.ts +0 -44
  64. package/convex/usage.ts +0 -260
  65. package/convex/usageReports.ts +0 -357
  66. package/convex/waitlist.ts +0 -55
  67. package/convex/webhooks.ts +0 -494
  68. package/convex/workspaceSettings.ts +0 -143
  69. package/convex/workspaces.ts +0 -1331
  70. package/convex.json +0 -3
  71. package/direct-test.mjs +0 -51
  72. package/email-templates/filestack-provider-outreach.html +0 -162
  73. package/email-templates/partnership-template.html +0 -116
  74. package/email-templates/pratham-draft-preview.txt +0 -57
  75. package/email-templates/pratham-partnership-draft.html +0 -141
  76. package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
  77. package/reports/pipeline/PIPELINE-REPORT.json +0 -153
  78. package/reports/pipeline/acquire_apisguru.json +0 -17
  79. package/reports/pipeline/capabilities.json +0 -38
  80. package/reports/pipeline/discover_azure_recursive.json +0 -1551
  81. package/reports/pipeline/discover_github.json +0 -25
  82. package/reports/pipeline/discover_github_repos.json +0 -49
  83. package/reports/pipeline/discover_swaggerhub.json +0 -24
  84. package/reports/pipeline/discover_well_known.json +0 -23
  85. package/reports/pipeline/fetch_specs.json +0 -19
  86. package/reports/pipeline/generate_providers.json +0 -14
  87. package/reports/pipeline/match_registry.json +0 -11
  88. package/reports/pipeline/parse_specs.json +0 -17
  89. package/reports/pipeline/promote_candidates.json +0 -34
  90. package/reports/pipeline/validate.json +0 -30
  91. package/reports/pipeline/validate_smoke_details.json +0 -3835
  92. package/reports/session-report-2026-04-05.html +0 -433
  93. package/seed-apis-direct.mjs +0 -106
  94. package/src/access-control.ts +0 -174
  95. package/src/adapters/base.ts +0 -364
  96. package/src/adapters/claude-desktop.ts +0 -41
  97. package/src/adapters/cline.ts +0 -88
  98. package/src/adapters/continue.ts +0 -91
  99. package/src/adapters/cursor.ts +0 -43
  100. package/src/adapters/custom.ts +0 -188
  101. package/src/adapters/detect.ts +0 -202
  102. package/src/adapters/index.ts +0 -47
  103. package/src/adapters/windsurf.ts +0 -44
  104. package/src/bin-http.ts +0 -45
  105. package/src/bin.ts +0 -34
  106. package/src/capability-router.ts +0 -331
  107. package/src/chainExecutor.ts +0 -730
  108. package/src/chainResolver.test.ts +0 -246
  109. package/src/chainResolver.ts +0 -658
  110. package/src/cli/commands/demo.ts +0 -109
  111. package/src/cli/commands/doctor.ts +0 -435
  112. package/src/cli/commands/index.ts +0 -9
  113. package/src/cli/commands/login.ts +0 -203
  114. package/src/cli/commands/mcp-install.ts +0 -373
  115. package/src/cli/commands/restore.ts +0 -333
  116. package/src/cli/commands/setup.ts +0 -297
  117. package/src/cli/commands/uninstall.ts +0 -240
  118. package/src/cli/index.ts +0 -148
  119. package/src/cli.ts +0 -370
  120. package/src/confirmation.ts +0 -296
  121. package/src/credentials.ts +0 -455
  122. package/src/credits.ts +0 -329
  123. package/src/crypto.ts +0 -75
  124. package/src/discovery.ts +0 -568
  125. package/src/enterprise/env.ts +0 -156
  126. package/src/enterprise/index.ts +0 -7
  127. package/src/enterprise/script-generator.ts +0 -481
  128. package/src/execute-dynamic.ts +0 -617
  129. package/src/execute.ts +0 -2386
  130. package/src/funnel-client.ts +0 -168
  131. package/src/funnel.test.ts +0 -187
  132. package/src/gateway-client.ts +0 -192
  133. package/src/hivr-whitelist.ts +0 -110
  134. package/src/http-api.ts +0 -286
  135. package/src/http-server-minimal.ts +0 -154
  136. package/src/index.ts +0 -2702
  137. package/src/intelligent-gateway.ts +0 -339
  138. package/src/mcp-analytics.ts +0 -156
  139. package/src/metered.ts +0 -149
  140. package/src/open-apis-generated.ts +0 -157
  141. package/src/open-apis.ts +0 -558
  142. package/src/postinstall.ts +0 -40
  143. package/src/product-whitelist.ts +0 -246
  144. package/src/proxy.ts +0 -36
  145. package/src/registration-guard.ts +0 -117
  146. package/src/session.ts +0 -129
  147. package/src/stripe.ts +0 -497
  148. package/src/telemetry.ts +0 -71
  149. package/src/test.ts +0 -135
  150. package/src/types/convex-api.d.ts +0 -20
  151. package/src/types/convex-api.ts +0 -21
  152. package/src/types.ts +0 -109
  153. package/src/ui/colors.ts +0 -219
  154. package/src/ui/errors.ts +0 -394
  155. package/src/ui/index.ts +0 -17
  156. package/src/ui/prompts.ts +0 -390
  157. package/src/ui/spinner.ts +0 -325
  158. package/src/utils/backup.ts +0 -224
  159. package/src/utils/config.ts +0 -318
  160. package/src/utils/os.ts +0 -124
  161. package/src/utils/paths.ts +0 -203
  162. package/src/webhook.ts +0 -107
  163. package/test-10-working.cjs +0 -97
  164. package/test-14-final.cjs +0 -96
  165. package/test-actual-handlers.ts +0 -92
  166. package/test-apilayer-all-14.ts +0 -249
  167. package/test-apilayer-fixed.ts +0 -248
  168. package/test-direct-endpoints.ts +0 -174
  169. package/test-exact-endpoints.ts +0 -144
  170. package/test-final.ts +0 -83
  171. package/test-full-routing.ts +0 -100
  172. package/test-handlers-correct.ts +0 -217
  173. package/test-numverify-key.ts +0 -41
  174. package/test-via-handlers.ts +0 -92
  175. package/test-worldnews.mjs +0 -26
  176. package/tsconfig.json +0 -20
@@ -1,331 +0,0 @@
1
- /**
2
- * APIClaw Capability Router
3
- * Routes capability requests to the best available provider
4
- */
5
-
6
- import { executeAPICall } from './execute.js';
7
- import { logAPICall } from './mcp-analytics.js';
8
-
9
- // Convex HTTP API for capability queries
10
- const CONVEX_URL = process.env.NEXT_PUBLIC_CONVEX_URL || 'https://brilliant-puffin-712.eu-west-1.convex.cloud';
11
-
12
- interface ProviderMapping {
13
- providerId: string;
14
- capabilityId: string;
15
- priority: number;
16
- regions: string[];
17
- pricePerUnit: number;
18
- currency: string;
19
- avgLatencyMs: number;
20
- paramMapping: Record<string, string>;
21
- enabled: boolean;
22
- healthStatus: string;
23
- }
24
-
25
- interface CapabilityPreferences {
26
- region?: string;
27
- maxPrice?: number;
28
- preferredProvider?: string;
29
- fallback?: boolean;
30
- }
31
-
32
- interface CapabilityResult {
33
- success: boolean;
34
- capability: string;
35
- action: string;
36
- providerUsed?: string;
37
- fallbackAttempted: boolean;
38
- fallbackReason?: string;
39
- data?: unknown;
40
- error?: string;
41
- cost?: number;
42
- currency?: string;
43
- latencyMs?: number;
44
- }
45
-
46
- /**
47
- * Query Convex for providers that support a capability
48
- */
49
- async function getProvidersForCapability(
50
- capabilityId: string,
51
- region?: string
52
- ): Promise<ProviderMapping[]> {
53
- try {
54
- const res = await fetch(`${CONVEX_URL}/api/query`, {
55
- method: 'POST',
56
- headers: { 'Content-Type': 'application/json' },
57
- body: JSON.stringify({
58
- path: 'capabilities:getProviders',
59
- args: { capabilityId, region },
60
- }),
61
- });
62
-
63
- if (!res.ok) return [];
64
-
65
- const data = await res.json() as { value?: ProviderMapping[] } | ProviderMapping[];
66
- if (Array.isArray(data)) return data;
67
- return (data.value || []) as ProviderMapping[];
68
- } catch (e) {
69
- console.error('Failed to fetch capability providers:', e);
70
- return [];
71
- }
72
- }
73
-
74
- /**
75
- * Map capability params to provider-specific params
76
- */
77
- function mapParams(
78
- params: Record<string, unknown>,
79
- mapping: Record<string, string>
80
- ): Record<string, unknown> {
81
- const result: Record<string, unknown> = {};
82
-
83
- for (const [capParam, value] of Object.entries(params)) {
84
- const providerParam = mapping[capParam] || capParam;
85
- result[providerParam] = value;
86
- }
87
-
88
- return result;
89
- }
90
-
91
- /**
92
- * Log capability usage to Convex
93
- */
94
- async function logCapabilityUsage(params: {
95
- capabilityId: string;
96
- providerId: string;
97
- userId: string;
98
- action: string;
99
- success: boolean;
100
- fallbackUsed: boolean;
101
- fallbackReason?: string;
102
- latencyMs: number;
103
- cost: number;
104
- currency: string;
105
- }): Promise<void> {
106
- try {
107
- await fetch(`${CONVEX_URL}/api/mutation`, {
108
- method: 'POST',
109
- headers: { 'Content-Type': 'application/json' },
110
- body: JSON.stringify({
111
- path: 'capabilities:logUsage',
112
- args: params,
113
- }),
114
- });
115
- } catch (e) {
116
- console.error('Failed to log capability usage:', e);
117
- }
118
- }
119
-
120
- /**
121
- * Execute a capability request with automatic provider selection and fallback
122
- */
123
- export async function executeCapability(
124
- capabilityId: string,
125
- action: string,
126
- params: Record<string, unknown>,
127
- userId: string,
128
- preferences: CapabilityPreferences = {}
129
- ): Promise<CapabilityResult> {
130
- const startTime = Date.now();
131
- const enableFallback = preferences.fallback !== false; // Default true
132
-
133
- // Get providers for this capability
134
- const providers = await getProvidersForCapability(capabilityId, preferences.region);
135
-
136
- if (providers.length === 0) {
137
- return {
138
- success: false,
139
- capability: capabilityId,
140
- action,
141
- fallbackAttempted: false,
142
- error: `No providers available for capability: ${capabilityId}`,
143
- };
144
- }
145
-
146
- // Filter by max price if specified
147
- let filteredProviders = providers;
148
- if (preferences.maxPrice !== undefined) {
149
- filteredProviders = providers.filter(p => p.pricePerUnit <= preferences.maxPrice!);
150
- }
151
-
152
- // Prefer specific provider if requested
153
- if (preferences.preferredProvider) {
154
- const preferred = filteredProviders.find(p => p.providerId === preferences.preferredProvider);
155
- if (preferred) {
156
- filteredProviders = [preferred, ...filteredProviders.filter(p => p.providerId !== preferences.preferredProvider)];
157
- }
158
- }
159
-
160
- if (filteredProviders.length === 0) {
161
- return {
162
- success: false,
163
- capability: capabilityId,
164
- action,
165
- fallbackAttempted: false,
166
- error: 'No providers match your preferences (region/price)',
167
- };
168
- }
169
-
170
- // Try providers in order
171
- let fallbackAttempted = false;
172
- let lastError = '';
173
-
174
- for (let i = 0; i < filteredProviders.length; i++) {
175
- const provider = filteredProviders[i];
176
- const isFirstAttempt = i === 0;
177
-
178
- if (!isFirstAttempt) {
179
- fallbackAttempted = true;
180
- }
181
-
182
- try {
183
- // Map params to provider-specific format
184
- const mappedParams = mapParams(params, provider.paramMapping || {});
185
-
186
- // Execute via existing executeAPICall
187
- const result = await executeAPICall(
188
- provider.providerId,
189
- action,
190
- mappedParams,
191
- userId
192
- );
193
-
194
- const latencyMs = Date.now() - startTime;
195
-
196
- if (result.success) {
197
- // Log successful usage
198
- logCapabilityUsage({
199
- capabilityId,
200
- providerId: provider.providerId,
201
- userId,
202
- action,
203
- success: true,
204
- fallbackUsed: fallbackAttempted,
205
- fallbackReason: fallbackAttempted ? lastError : undefined,
206
- latencyMs,
207
- cost: provider.pricePerUnit,
208
- currency: provider.currency,
209
- });
210
-
211
- // Also log to file-based analytics
212
- logAPICall({
213
- timestamp: new Date().toISOString(),
214
- provider: provider.providerId,
215
- action,
216
- type: 'direct',
217
- userId,
218
- success: true,
219
- latencyMs,
220
- });
221
-
222
- return {
223
- success: true,
224
- capability: capabilityId,
225
- action,
226
- providerUsed: provider.providerId,
227
- fallbackAttempted,
228
- fallbackReason: fallbackAttempted ? lastError : undefined,
229
- data: result.data,
230
- cost: provider.pricePerUnit,
231
- currency: provider.currency,
232
- latencyMs,
233
- };
234
- }
235
-
236
- // Provider returned error, try next
237
- lastError = result.error || 'Unknown error';
238
-
239
- if (!enableFallback) {
240
- break;
241
- }
242
-
243
- } catch (e: any) {
244
- lastError = e.message || 'Provider execution failed';
245
-
246
- if (!enableFallback) {
247
- break;
248
- }
249
- }
250
- }
251
-
252
- // All providers failed
253
- const latencyMs = Date.now() - startTime;
254
-
255
- logCapabilityUsage({
256
- capabilityId,
257
- providerId: filteredProviders[0].providerId,
258
- userId,
259
- action,
260
- success: false,
261
- fallbackUsed: fallbackAttempted,
262
- fallbackReason: lastError,
263
- latencyMs,
264
- cost: 0,
265
- currency: 'SEK',
266
- });
267
-
268
- return {
269
- success: false,
270
- capability: capabilityId,
271
- action,
272
- fallbackAttempted,
273
- error: `All providers failed. Last error: ${lastError}`,
274
- latencyMs,
275
- };
276
- }
277
-
278
- /**
279
- * List available capabilities
280
- */
281
- export async function listCapabilities(): Promise<{ id: string; name: string; category: string }[]> {
282
- try {
283
- const res = await fetch(`${CONVEX_URL}/api/query`, {
284
- method: 'POST',
285
- headers: { 'Content-Type': 'application/json' },
286
- body: JSON.stringify({
287
- path: 'capabilities:list',
288
- args: {},
289
- }),
290
- });
291
-
292
- if (!res.ok) return [];
293
-
294
- const data = await res.json() as { value?: any[] } | any[];
295
- const capabilities = Array.isArray(data) ? data : (data.value || []);
296
-
297
- return capabilities.map(c => ({
298
- id: c.id,
299
- name: c.name,
300
- category: c.category,
301
- }));
302
- } catch (e) {
303
- return [];
304
- }
305
- }
306
-
307
- /**
308
- * Check if a capability exists
309
- */
310
- export async function hasCapability(capabilityId: string): Promise<boolean> {
311
- try {
312
- const res = await fetch(`${CONVEX_URL}/api/query`, {
313
- method: 'POST',
314
- headers: { 'Content-Type': 'application/json' },
315
- body: JSON.stringify({
316
- path: 'capabilities:getById',
317
- args: { id: capabilityId },
318
- }),
319
- });
320
-
321
- if (!res.ok) return false;
322
-
323
- const data = await res.json() as { value?: unknown } | unknown;
324
- if (data && typeof data === 'object' && 'value' in data) {
325
- return !!data.value;
326
- }
327
- return !!data;
328
- } catch (e) {
329
- return false;
330
- }
331
- }