@nordsym/apiclaw 1.3.3 → 1.3.5
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/_generated/api.d.ts +6 -0
- package/convex/billing.ts +341 -0
- package/convex/email.ts +276 -0
- package/convex/http.ts +154 -0
- package/convex/schema.ts +43 -0
- package/convex/workspaces.ts +663 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +272 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +396 -4
- package/dist/index.js.map +1 -1
- package/dist/session.d.ts +29 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +87 -0
- package/dist/session.js.map +1 -0
- package/docs/PRD-agent-first-billing.md +525 -0
- package/docs/PRD-workspace-fixes.md +178 -0
- package/landing/package-lock.json +21 -3
- package/landing/package.json +2 -1
- package/landing/src/app/api/stripe/webhook/route.ts +178 -0
- package/landing/src/app/api/workspace-auth/magic-link/route.ts +84 -0
- package/landing/src/app/api/workspace-auth/session/route.ts +73 -0
- package/landing/src/app/api/workspace-auth/verify/route.ts +57 -0
- package/landing/src/app/auth/verify/page.tsx +292 -0
- package/landing/src/app/dashboard/layout.tsx +22 -0
- package/landing/src/app/dashboard/page.tsx +22 -0
- package/landing/src/app/dashboard/verify/page.tsx +108 -0
- package/landing/src/app/login/page.tsx +204 -0
- package/landing/src/app/page.tsx +23 -7
- package/landing/src/app/providers/dashboard/layout.tsx +5 -4
- package/landing/src/app/providers/dashboard/page.tsx +11 -641
- package/landing/src/app/upgrade/page.tsx +288 -0
- package/landing/src/app/workspace/layout.tsx +30 -0
- package/landing/src/app/workspace/page.tsx +1637 -0
- package/landing/src/lib/stats.json +14 -15
- package/landing/src/middleware.ts +50 -0
- package/landing/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/cli.ts +320 -0
- package/src/index.ts +444 -4
- package/src/session.ts +103 -0
package/package.json
CHANGED
package/src/cli.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* APIClaw Interactive CLI
|
|
4
|
+
* Run with: npx @nordsym/apiclaw --cli
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as readline from 'readline';
|
|
8
|
+
import { ConvexHttpClient } from 'convex/browser';
|
|
9
|
+
import { discoverAPIs, getAPIDetails, getCategories } from './discovery.js';
|
|
10
|
+
import { executeAPICall, getConnectedProviders } from './execute.js';
|
|
11
|
+
import { readSession, writeSession, clearSession, getMachineFingerprint } from './session.js';
|
|
12
|
+
|
|
13
|
+
const CONVEX_URL = process.env.CONVEX_URL || 'https://adventurous-avocet-799.convex.cloud';
|
|
14
|
+
const convex = new ConvexHttpClient(CONVEX_URL);
|
|
15
|
+
|
|
16
|
+
// Colors for terminal
|
|
17
|
+
const colors = {
|
|
18
|
+
reset: '\x1b[0m',
|
|
19
|
+
bright: '\x1b[1m',
|
|
20
|
+
red: '\x1b[31m',
|
|
21
|
+
green: '\x1b[32m',
|
|
22
|
+
yellow: '\x1b[33m',
|
|
23
|
+
blue: '\x1b[34m',
|
|
24
|
+
magenta: '\x1b[35m',
|
|
25
|
+
cyan: '\x1b[36m',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function log(msg: string) {
|
|
29
|
+
console.log(msg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function success(msg: string) {
|
|
33
|
+
console.log(`${colors.green}✓${colors.reset} ${msg}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function error(msg: string) {
|
|
37
|
+
console.log(`${colors.red}✗${colors.reset} ${msg}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function info(msg: string) {
|
|
41
|
+
console.log(`${colors.cyan}ℹ${colors.reset} ${msg}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface WorkspaceContext {
|
|
45
|
+
sessionToken: string;
|
|
46
|
+
workspaceId: string;
|
|
47
|
+
email: string;
|
|
48
|
+
tier: string;
|
|
49
|
+
usageRemaining: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let workspaceContext: WorkspaceContext | null = null;
|
|
53
|
+
|
|
54
|
+
async function validateSession(): Promise<boolean> {
|
|
55
|
+
const session = readSession();
|
|
56
|
+
if (!session) return false;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const result = await convex.query("workspaces:getWorkspaceStatus" as any, {
|
|
60
|
+
sessionToken: session.sessionToken,
|
|
61
|
+
}) as any;
|
|
62
|
+
|
|
63
|
+
if (!result?.authenticated || result?.status !== 'active') {
|
|
64
|
+
clearSession();
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
workspaceContext = {
|
|
69
|
+
sessionToken: session.sessionToken,
|
|
70
|
+
workspaceId: session.workspaceId,
|
|
71
|
+
email: result.email ?? '',
|
|
72
|
+
tier: result.tier ?? 'free',
|
|
73
|
+
usageRemaining: result.usageRemaining ?? 0,
|
|
74
|
+
};
|
|
75
|
+
return true;
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function registerOwner(email: string): Promise<void> {
|
|
82
|
+
info(`Sending magic link to ${email}...`);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const fingerprint = getMachineFingerprint();
|
|
86
|
+
const result = await convex.mutation("workspaces:requestMagicLink" as any, {
|
|
87
|
+
email,
|
|
88
|
+
fingerprint,
|
|
89
|
+
}) as any;
|
|
90
|
+
|
|
91
|
+
if (result?.sent) {
|
|
92
|
+
success(`Magic link sent to ${email}`);
|
|
93
|
+
log(`\n📧 Check your email and click the link to authenticate.`);
|
|
94
|
+
log(` Then run ${colors.cyan}status${colors.reset} to verify.\n`);
|
|
95
|
+
} else {
|
|
96
|
+
error(`Failed to send magic link: ${result?.error || 'Unknown error'}`);
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
error(`Failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function showStatus(): Promise<void> {
|
|
104
|
+
const valid = await validateSession();
|
|
105
|
+
|
|
106
|
+
log(`\n${colors.bright}APIClaw Status${colors.reset}`);
|
|
107
|
+
log(`${'─'.repeat(40)}`);
|
|
108
|
+
|
|
109
|
+
if (valid && workspaceContext) {
|
|
110
|
+
success(`Authenticated as ${workspaceContext.email}`);
|
|
111
|
+
log(` Tier: ${workspaceContext.tier}`);
|
|
112
|
+
log(` Remaining calls: ${workspaceContext.usageRemaining}`);
|
|
113
|
+
} else {
|
|
114
|
+
error(`Not authenticated`);
|
|
115
|
+
log(` Run: ${colors.cyan}register <email>${colors.reset}`);
|
|
116
|
+
}
|
|
117
|
+
log('');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function discover(query: string): Promise<void> {
|
|
121
|
+
info(`Searching for: "${query}"`);
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const results = discoverAPIs(query, { maxResults: 5 });
|
|
125
|
+
|
|
126
|
+
if (!results || results.length === 0) {
|
|
127
|
+
log(`No APIs found for "${query}"`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
log(`\n${colors.bright}Found ${results.length} APIs:${colors.reset}\n`);
|
|
132
|
+
|
|
133
|
+
// Get connected providers for Direct Call detection
|
|
134
|
+
const connected = getConnectedProviders().map(p => p.provider.toLowerCase());
|
|
135
|
+
|
|
136
|
+
for (const result of results) {
|
|
137
|
+
const api = result.provider;
|
|
138
|
+
const isDirectCall = connected.includes(api.id?.toLowerCase() || api.name.toLowerCase().replace(/\s+/g, '_'));
|
|
139
|
+
const directCallBadge = isDirectCall ? `${colors.green}[Direct Call]${colors.reset}` : '';
|
|
140
|
+
log(`${colors.cyan}${api.name}${colors.reset} ${directCallBadge}`);
|
|
141
|
+
log(` ${api.description}`);
|
|
142
|
+
log(` Category: ${api.category}`);
|
|
143
|
+
log(` Pricing: ${api.pricing?.model || 'See docs'}`);
|
|
144
|
+
log('');
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
error(`Search failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function listConnected(): Promise<void> {
|
|
152
|
+
try {
|
|
153
|
+
const providers = getConnectedProviders();
|
|
154
|
+
|
|
155
|
+
log(`\n${colors.bright}Direct Call Providers (no API key needed):${colors.reset}\n`);
|
|
156
|
+
|
|
157
|
+
for (const p of providers) {
|
|
158
|
+
log(`${colors.cyan}${p.provider}${colors.reset}`);
|
|
159
|
+
log(` Actions: ${p.actions?.join(', ') || 'See docs'}`);
|
|
160
|
+
log('');
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
error(`Failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function callApi(provider: string, action: string, params: Record<string, any>): Promise<void> {
|
|
168
|
+
if (!workspaceContext) {
|
|
169
|
+
error('Not authenticated. Run: register <email>');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
info(`Calling ${provider}.${action}...`);
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const result = await executeAPICall(
|
|
177
|
+
provider,
|
|
178
|
+
action,
|
|
179
|
+
params,
|
|
180
|
+
workspaceContext.workspaceId
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
log(`\n${colors.bright}Result:${colors.reset}\n`);
|
|
184
|
+
log(JSON.stringify(result, null, 2));
|
|
185
|
+
log('');
|
|
186
|
+
} catch (err) {
|
|
187
|
+
error(`Call failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function showHelp(): void {
|
|
192
|
+
log(`
|
|
193
|
+
${colors.bright}🦞 APIClaw CLI${colors.reset}
|
|
194
|
+
|
|
195
|
+
${colors.cyan}Commands:${colors.reset}
|
|
196
|
+
register <email> Send magic link to authenticate
|
|
197
|
+
status Check authentication status
|
|
198
|
+
discover <query> Search for APIs by capability
|
|
199
|
+
list Show Direct Call providers
|
|
200
|
+
call <provider> <action> <json-params>
|
|
201
|
+
Call an API (e.g., call brave_search search {"q":"test"})
|
|
202
|
+
help Show this help
|
|
203
|
+
exit Quit
|
|
204
|
+
|
|
205
|
+
${colors.cyan}Examples:${colors.reset}
|
|
206
|
+
discover send SMS
|
|
207
|
+
discover image generation
|
|
208
|
+
list
|
|
209
|
+
call brave_search search {"q":"hello world"}
|
|
210
|
+
`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function parseCallCommand(args: string): { provider: string; action: string; params: Record<string, any> } | null {
|
|
214
|
+
// Format: provider action {json}
|
|
215
|
+
const match = args.match(/^(\S+)\s+(\S+)\s+(.+)$/);
|
|
216
|
+
if (!match) return null;
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const params = JSON.parse(match[3]);
|
|
220
|
+
return { provider: match[1], action: match[2], params };
|
|
221
|
+
} catch {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function startCLI(): Promise<void> {
|
|
227
|
+
log(`
|
|
228
|
+
${colors.bright}🦞 APIClaw CLI v1.1.5${colors.reset}
|
|
229
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
230
|
+
|
|
231
|
+
Type ${colors.cyan}help${colors.reset} for commands, ${colors.cyan}exit${colors.reset} to quit.
|
|
232
|
+
`);
|
|
233
|
+
|
|
234
|
+
// Check session on startup
|
|
235
|
+
const valid = await validateSession();
|
|
236
|
+
if (valid && workspaceContext) {
|
|
237
|
+
success(`Authenticated as ${workspaceContext.email}`);
|
|
238
|
+
} else {
|
|
239
|
+
info(`Not authenticated. Run: ${colors.cyan}register <email>${colors.reset}`);
|
|
240
|
+
}
|
|
241
|
+
log('');
|
|
242
|
+
|
|
243
|
+
const rl = readline.createInterface({
|
|
244
|
+
input: process.stdin,
|
|
245
|
+
output: process.stdout,
|
|
246
|
+
prompt: `${colors.red}apiclaw${colors.reset}> `,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
rl.prompt();
|
|
250
|
+
|
|
251
|
+
rl.on('line', async (line) => {
|
|
252
|
+
const input = line.trim();
|
|
253
|
+
const [cmd, ...args] = input.split(/\s+/);
|
|
254
|
+
const argsStr = args.join(' ');
|
|
255
|
+
|
|
256
|
+
switch (cmd.toLowerCase()) {
|
|
257
|
+
case '':
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case 'help':
|
|
261
|
+
case '?':
|
|
262
|
+
showHelp();
|
|
263
|
+
break;
|
|
264
|
+
|
|
265
|
+
case 'exit':
|
|
266
|
+
case 'quit':
|
|
267
|
+
case 'q':
|
|
268
|
+
log('Bye! 🦞');
|
|
269
|
+
process.exit(0);
|
|
270
|
+
break;
|
|
271
|
+
|
|
272
|
+
case 'register':
|
|
273
|
+
if (!argsStr) {
|
|
274
|
+
error('Usage: register <email>');
|
|
275
|
+
} else {
|
|
276
|
+
await registerOwner(argsStr);
|
|
277
|
+
}
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
case 'status':
|
|
281
|
+
await showStatus();
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case 'discover':
|
|
285
|
+
case 'search':
|
|
286
|
+
if (!argsStr) {
|
|
287
|
+
error('Usage: discover <query>');
|
|
288
|
+
} else {
|
|
289
|
+
await discover(argsStr);
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
|
|
293
|
+
case 'list':
|
|
294
|
+
case 'connected':
|
|
295
|
+
await listConnected();
|
|
296
|
+
break;
|
|
297
|
+
|
|
298
|
+
case 'call':
|
|
299
|
+
const parsed = parseCallCommand(argsStr);
|
|
300
|
+
if (!parsed) {
|
|
301
|
+
error('Usage: call <provider> <action> {"param":"value"}');
|
|
302
|
+
log('Example: call brave_search search {"q":"hello"}');
|
|
303
|
+
} else {
|
|
304
|
+
await callApi(parsed.provider, parsed.action, parsed.params);
|
|
305
|
+
}
|
|
306
|
+
break;
|
|
307
|
+
|
|
308
|
+
default:
|
|
309
|
+
error(`Unknown command: ${cmd}`);
|
|
310
|
+
log(`Type ${colors.cyan}help${colors.reset} for available commands.`);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
rl.prompt();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
rl.on('close', () => {
|
|
317
|
+
log('\nBye! 🦞');
|
|
318
|
+
process.exit(0);
|
|
319
|
+
});
|
|
320
|
+
}
|