@nordsym/apiclaw 1.3.4 → 1.3.6
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/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +303 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/docs/PRD-workspace-fixes.md +178 -0
- package/landing/src/app/dashboard/page.tsx +9 -679
- package/landing/src/app/dashboard/verify/page.tsx +1 -1
- package/landing/src/app/login/page.tsx +1 -1
- 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/workspace/layout.tsx +30 -0
- package/landing/src/app/workspace/page.tsx +1637 -0
- package/landing/src/lib/stats.json +1 -1
- package/package.json +1 -1
- package/src/cli.ts +370 -0
- package/src/index.ts +10 -0
package/package.json
CHANGED
package/src/cli.ts
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
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
|
+
|
|
87
|
+
// Use HTTP endpoint for magic link
|
|
88
|
+
const response = await fetch(`${CONVEX_URL.replace('.cloud', '.site')}/workspace/magic-link`, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: { 'Content-Type': 'application/json' },
|
|
91
|
+
body: JSON.stringify({ email, fingerprint }),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const result = await response.json() as { success?: boolean; token?: string; error?: string };
|
|
95
|
+
|
|
96
|
+
if (result?.success && result?.token) {
|
|
97
|
+
success(`Magic link sent to ${email}`);
|
|
98
|
+
log(`\n📧 Check your email and click the link to authenticate.`);
|
|
99
|
+
|
|
100
|
+
// Start polling for verification
|
|
101
|
+
log(`\n⏳ Waiting for you to click the link...`);
|
|
102
|
+
log(` (Press Ctrl+C to cancel)\n`);
|
|
103
|
+
|
|
104
|
+
await pollForVerification(result.token, fingerprint);
|
|
105
|
+
} else {
|
|
106
|
+
error(`Failed: ${result?.error || 'Unknown error'}`);
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
error(`Failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function pollForVerification(token: string, fingerprint: string): Promise<void> {
|
|
114
|
+
const maxAttempts = 60; // 5 minutes
|
|
115
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
116
|
+
await new Promise(r => setTimeout(r, 5000)); // Poll every 5 seconds
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const response = await fetch(`${CONVEX_URL.replace('.cloud', '.site')}/workspace/poll?token=${token}`);
|
|
120
|
+
const result = await response.json() as {
|
|
121
|
+
verified?: boolean;
|
|
122
|
+
sessionToken?: string;
|
|
123
|
+
workspaceId?: string;
|
|
124
|
+
email?: string;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (result?.verified && result?.sessionToken) {
|
|
128
|
+
// Save the real session
|
|
129
|
+
writeSession(
|
|
130
|
+
result.sessionToken,
|
|
131
|
+
result.workspaceId || '',
|
|
132
|
+
result.email || ''
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
success(`Authenticated as ${result.email}!`);
|
|
136
|
+
|
|
137
|
+
// Reload workspace context
|
|
138
|
+
await validateSession();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
} catch {
|
|
142
|
+
// Continue polling
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Show progress dot
|
|
146
|
+
process.stdout.write('.');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
log('\n');
|
|
150
|
+
error('Verification timed out. Please try again.');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function showStatus(): Promise<void> {
|
|
154
|
+
const valid = await validateSession();
|
|
155
|
+
|
|
156
|
+
log(`\n${colors.bright}APIClaw Status${colors.reset}`);
|
|
157
|
+
log(`${'─'.repeat(40)}`);
|
|
158
|
+
|
|
159
|
+
if (valid && workspaceContext) {
|
|
160
|
+
success(`Authenticated as ${workspaceContext.email}`);
|
|
161
|
+
log(` Tier: ${workspaceContext.tier}`);
|
|
162
|
+
log(` Remaining calls: ${workspaceContext.usageRemaining}`);
|
|
163
|
+
} else {
|
|
164
|
+
error(`Not authenticated`);
|
|
165
|
+
log(` Run: ${colors.cyan}register <email>${colors.reset}`);
|
|
166
|
+
}
|
|
167
|
+
log('');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function discover(query: string): Promise<void> {
|
|
171
|
+
info(`Searching for: "${query}"`);
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const results = discoverAPIs(query, { maxResults: 5 });
|
|
175
|
+
|
|
176
|
+
if (!results || results.length === 0) {
|
|
177
|
+
log(`No APIs found for "${query}"`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
log(`\n${colors.bright}Found ${results.length} APIs:${colors.reset}\n`);
|
|
182
|
+
|
|
183
|
+
// Get connected providers for Direct Call detection
|
|
184
|
+
const connected = getConnectedProviders().map(p => p.provider.toLowerCase());
|
|
185
|
+
|
|
186
|
+
for (const result of results) {
|
|
187
|
+
const api = result.provider;
|
|
188
|
+
const isDirectCall = connected.includes(api.id?.toLowerCase() || api.name.toLowerCase().replace(/\s+/g, '_'));
|
|
189
|
+
const directCallBadge = isDirectCall ? `${colors.green}[Direct Call]${colors.reset}` : '';
|
|
190
|
+
log(`${colors.cyan}${api.name}${colors.reset} ${directCallBadge}`);
|
|
191
|
+
log(` ${api.description}`);
|
|
192
|
+
log(` Category: ${api.category}`);
|
|
193
|
+
log(` Pricing: ${api.pricing?.model || 'See docs'}`);
|
|
194
|
+
log('');
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
error(`Search failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function listConnected(): Promise<void> {
|
|
202
|
+
try {
|
|
203
|
+
const providers = getConnectedProviders();
|
|
204
|
+
|
|
205
|
+
log(`\n${colors.bright}Direct Call Providers (no API key needed):${colors.reset}\n`);
|
|
206
|
+
|
|
207
|
+
for (const p of providers) {
|
|
208
|
+
log(`${colors.cyan}${p.provider}${colors.reset}`);
|
|
209
|
+
log(` Actions: ${p.actions?.join(', ') || 'See docs'}`);
|
|
210
|
+
log('');
|
|
211
|
+
}
|
|
212
|
+
} catch (err) {
|
|
213
|
+
error(`Failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function callApi(provider: string, action: string, params: Record<string, any>): Promise<void> {
|
|
218
|
+
if (!workspaceContext) {
|
|
219
|
+
error('Not authenticated. Run: register <email>');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
info(`Calling ${provider}.${action}...`);
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
const result = await executeAPICall(
|
|
227
|
+
provider,
|
|
228
|
+
action,
|
|
229
|
+
params,
|
|
230
|
+
workspaceContext.workspaceId
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
log(`\n${colors.bright}Result:${colors.reset}\n`);
|
|
234
|
+
log(JSON.stringify(result, null, 2));
|
|
235
|
+
log('');
|
|
236
|
+
} catch (err) {
|
|
237
|
+
error(`Call failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function showHelp(): void {
|
|
242
|
+
log(`
|
|
243
|
+
${colors.bright}🦞 APIClaw CLI${colors.reset}
|
|
244
|
+
|
|
245
|
+
${colors.cyan}Commands:${colors.reset}
|
|
246
|
+
register <email> Send magic link to authenticate
|
|
247
|
+
status Check authentication status
|
|
248
|
+
discover <query> Search for APIs by capability
|
|
249
|
+
list Show Direct Call providers
|
|
250
|
+
call <provider> <action> <json-params>
|
|
251
|
+
Call an API (e.g., call brave_search search {"q":"test"})
|
|
252
|
+
help Show this help
|
|
253
|
+
exit Quit
|
|
254
|
+
|
|
255
|
+
${colors.cyan}Examples:${colors.reset}
|
|
256
|
+
discover send SMS
|
|
257
|
+
discover image generation
|
|
258
|
+
list
|
|
259
|
+
call brave_search search {"q":"hello world"}
|
|
260
|
+
`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function parseCallCommand(args: string): { provider: string; action: string; params: Record<string, any> } | null {
|
|
264
|
+
// Format: provider action {json}
|
|
265
|
+
const match = args.match(/^(\S+)\s+(\S+)\s+(.+)$/);
|
|
266
|
+
if (!match) return null;
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
const params = JSON.parse(match[3]);
|
|
270
|
+
return { provider: match[1], action: match[2], params };
|
|
271
|
+
} catch {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export async function startCLI(): Promise<void> {
|
|
277
|
+
log(`
|
|
278
|
+
${colors.bright}🦞 APIClaw CLI v1.1.5${colors.reset}
|
|
279
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
280
|
+
|
|
281
|
+
Type ${colors.cyan}help${colors.reset} for commands, ${colors.cyan}exit${colors.reset} to quit.
|
|
282
|
+
`);
|
|
283
|
+
|
|
284
|
+
// Check session on startup
|
|
285
|
+
const valid = await validateSession();
|
|
286
|
+
if (valid && workspaceContext) {
|
|
287
|
+
success(`Authenticated as ${workspaceContext.email}`);
|
|
288
|
+
} else {
|
|
289
|
+
info(`Not authenticated. Run: ${colors.cyan}register <email>${colors.reset}`);
|
|
290
|
+
}
|
|
291
|
+
log('');
|
|
292
|
+
|
|
293
|
+
const rl = readline.createInterface({
|
|
294
|
+
input: process.stdin,
|
|
295
|
+
output: process.stdout,
|
|
296
|
+
prompt: `${colors.red}apiclaw${colors.reset}> `,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
rl.prompt();
|
|
300
|
+
|
|
301
|
+
rl.on('line', async (line) => {
|
|
302
|
+
const input = line.trim();
|
|
303
|
+
const [cmd, ...args] = input.split(/\s+/);
|
|
304
|
+
const argsStr = args.join(' ');
|
|
305
|
+
|
|
306
|
+
switch (cmd.toLowerCase()) {
|
|
307
|
+
case '':
|
|
308
|
+
break;
|
|
309
|
+
|
|
310
|
+
case 'help':
|
|
311
|
+
case '?':
|
|
312
|
+
showHelp();
|
|
313
|
+
break;
|
|
314
|
+
|
|
315
|
+
case 'exit':
|
|
316
|
+
case 'quit':
|
|
317
|
+
case 'q':
|
|
318
|
+
log('Bye! 🦞');
|
|
319
|
+
process.exit(0);
|
|
320
|
+
break;
|
|
321
|
+
|
|
322
|
+
case 'register':
|
|
323
|
+
if (!argsStr) {
|
|
324
|
+
error('Usage: register <email>');
|
|
325
|
+
} else {
|
|
326
|
+
await registerOwner(argsStr);
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
|
|
330
|
+
case 'status':
|
|
331
|
+
await showStatus();
|
|
332
|
+
break;
|
|
333
|
+
|
|
334
|
+
case 'discover':
|
|
335
|
+
case 'search':
|
|
336
|
+
if (!argsStr) {
|
|
337
|
+
error('Usage: discover <query>');
|
|
338
|
+
} else {
|
|
339
|
+
await discover(argsStr);
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
|
|
343
|
+
case 'list':
|
|
344
|
+
case 'connected':
|
|
345
|
+
await listConnected();
|
|
346
|
+
break;
|
|
347
|
+
|
|
348
|
+
case 'call':
|
|
349
|
+
const parsed = parseCallCommand(argsStr);
|
|
350
|
+
if (!parsed) {
|
|
351
|
+
error('Usage: call <provider> <action> {"param":"value"}');
|
|
352
|
+
log('Example: call brave_search search {"q":"hello"}');
|
|
353
|
+
} else {
|
|
354
|
+
await callApi(parsed.provider, parsed.action, parsed.params);
|
|
355
|
+
}
|
|
356
|
+
break;
|
|
357
|
+
|
|
358
|
+
default:
|
|
359
|
+
error(`Unknown command: ${cmd}`);
|
|
360
|
+
log(`Type ${colors.cyan}help${colors.reset} for available commands.`);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
rl.prompt();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
rl.on('close', () => {
|
|
367
|
+
log('\nBye! 🦞');
|
|
368
|
+
process.exit(0);
|
|
369
|
+
});
|
|
370
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1233,6 +1233,13 @@ Docs: https://apiclaw.nordsym.com
|
|
|
1233
1233
|
|
|
1234
1234
|
// Start server
|
|
1235
1235
|
async function main() {
|
|
1236
|
+
// Check for CLI mode
|
|
1237
|
+
if (process.argv.includes('--cli') || process.argv.includes('-c')) {
|
|
1238
|
+
const { startCLI } = await import('./cli.js');
|
|
1239
|
+
await startCLI();
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1236
1243
|
const transport = new StdioServerTransport();
|
|
1237
1244
|
await server.connect(transport);
|
|
1238
1245
|
trackStartup();
|
|
@@ -1258,6 +1265,9 @@ Quick Start:
|
|
|
1258
1265
|
Direct Call (no API key needed):
|
|
1259
1266
|
list_connected()
|
|
1260
1267
|
|
|
1268
|
+
Interactive CLI mode:
|
|
1269
|
+
npx @nordsym/apiclaw --cli
|
|
1270
|
+
|
|
1261
1271
|
Docs: https://apiclaw.nordsym.com
|
|
1262
1272
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
1263
1273
|
`);
|