valta-sdk 2.1.4 → 2.1.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.
@@ -29,25 +29,86 @@ function getApiKey() {
29
29
  }
30
30
 
31
31
  // src/cli/commands/login.ts
32
- function prompt(question) {
32
+ var BASE_URL = "https://valta.co/api/v1";
33
+ function prompt(question, hidden = false) {
33
34
  const rl = (0, import_readline.createInterface)({ input: process.stdin, output: process.stdout });
34
35
  return new Promise((resolve) => {
35
- rl.question(question, (answer) => {
36
- rl.close();
37
- resolve(answer.trim());
38
- });
36
+ if (hidden) {
37
+ process.stdout.write(question);
38
+ process.stdin.setRawMode?.(true);
39
+ let input = "";
40
+ process.stdin.resume();
41
+ process.stdin.setEncoding("utf8");
42
+ process.stdin.on("data", function handler(char) {
43
+ if (char === "\n" || char === "\r" || char === "") {
44
+ process.stdin.setRawMode?.(false);
45
+ process.stdin.pause();
46
+ process.stdin.removeListener("data", handler);
47
+ process.stdout.write("\n");
48
+ rl.close();
49
+ resolve(input);
50
+ } else if (char === "") {
51
+ process.exit();
52
+ } else if (char === "\x7F") {
53
+ if (input.length > 0) {
54
+ input = input.slice(0, -1);
55
+ process.stdout.clearLine?.(0);
56
+ process.stdout.cursorTo?.(0);
57
+ process.stdout.write(question + "\u2022".repeat(input.length));
58
+ }
59
+ } else {
60
+ input += char;
61
+ process.stdout.write("\u2022");
62
+ }
63
+ });
64
+ } else {
65
+ rl.question(question, (answer) => {
66
+ rl.close();
67
+ resolve(answer.trim());
68
+ });
69
+ }
39
70
  });
40
71
  }
41
72
  async function loginCommand() {
42
73
  console.log("\n Valta Login\n");
43
- const apiKey = await prompt(" API Key: ");
44
- if (!apiKey || !apiKey.startsWith("sk_valta_")) {
45
- console.error("\n \u2716 Invalid API key. Keys start with sk_valta_\n");
74
+ const email = await prompt(" Email: ");
75
+ const password = await prompt(" Password: ", true);
76
+ if (!email || !password) {
77
+ console.error("\n \u2716 Email and password are required.\n");
78
+ process.exit(1);
79
+ }
80
+ try {
81
+ const res = await fetch(`${BASE_URL}/auth/login`, {
82
+ method: "POST",
83
+ headers: { "Content-Type": "application/json" },
84
+ body: JSON.stringify({ email, password })
85
+ });
86
+ const data = await res.json();
87
+ if (!res.ok || !data.success) {
88
+ console.error(`
89
+ \u2716 ${data.error || "Login failed"}
90
+ `);
91
+ process.exit(1);
92
+ }
93
+ const tier = data.tier || "free";
94
+ if (data.hasExistingKey) {
95
+ saveConfig({ apiKey: "", email: data.email, tier });
96
+ console.log(`
97
+ \u2714 Authenticated as ${data.email} (${tier} tier)`);
98
+ console.log(` You already have an API key (${data.apiKeyPrefix}...)`);
99
+ console.log(" Run: valta keys create [name] to generate a new key\n");
100
+ } else {
101
+ saveConfig({ apiKey: data.apiKey, email: data.email, tier });
102
+ console.log(`
103
+ \u2714 Authenticated as ${data.email} (${tier} tier)`);
104
+ console.log(`
105
+ API Key: ${data.apiKey}`);
106
+ console.log(" (Saved to ~/.valta/config.json \u2014 shown once)\n");
107
+ }
108
+ } catch {
109
+ console.error("\n \u2716 Could not connect to Valta. Check your internet connection.\n");
46
110
  process.exit(1);
47
111
  }
48
- saveConfig({ apiKey });
49
- console.log("\n \u2714 API key saved to ~/.valta/config.json");
50
- console.log(" You can now use the Valta SDK.\n");
51
112
  }
52
113
 
53
114
  // src/errors/index.ts
@@ -300,16 +361,16 @@ async function agentsListCommand() {
300
361
  try {
301
362
  const result = await client.agents.list();
302
363
  const agents = result.agents;
303
- if (agents.length === 0) {
364
+ if (!agents.length) {
304
365
  console.log("\n No agents found. Create one at https://valta.co/dashboard\n");
305
366
  return;
306
367
  }
307
- console.log("\n ID NAME STATUS");
308
- console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
368
+ console.log("\n ID NAME STATUS");
369
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
309
370
  for (const agent of agents) {
310
- const id = agent.id.padEnd(16);
311
- const name = agent.name.padEnd(23);
312
- const status = agent.status;
371
+ const id = (agent.id || "").padEnd(24);
372
+ const name = (agent.name || "").padEnd(23);
373
+ const status = agent.status || "";
313
374
  console.log(` ${id} ${name} ${status}`);
314
375
  }
315
376
  console.log();
@@ -335,6 +396,72 @@ async function agentsFreezeCommand(agentId) {
335
396
  }
336
397
  }
337
398
 
399
+ // src/cli/commands/keys.ts
400
+ function getClient2() {
401
+ const apiKey = getApiKey();
402
+ if (!apiKey) {
403
+ console.error("\n \u2716 Not logged in. Run: valta login\n");
404
+ process.exit(1);
405
+ }
406
+ return new ValtaClient(apiKey);
407
+ }
408
+ async function keysListCommand() {
409
+ const client = getClient2();
410
+ try {
411
+ const keys = await client.keys.list();
412
+ if (!keys.length) {
413
+ console.log("\n No API keys found.\n");
414
+ return;
415
+ }
416
+ console.log("\n PREFIX NAME CREATED");
417
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
418
+ for (const key of keys) {
419
+ const prefix = (key.prefix || "").padEnd(15);
420
+ const name = (key.name || "").padEnd(23);
421
+ const created = key.createdAt ? new Date(key.createdAt).toLocaleDateString() : "";
422
+ console.log(` ${prefix} ${name} ${created}`);
423
+ }
424
+ console.log();
425
+ } catch (err) {
426
+ console.error(`
427
+ \u2716 ${err instanceof Error ? err.message : "Unknown error"}
428
+ `);
429
+ process.exit(1);
430
+ }
431
+ }
432
+ async function keysCreateCommand(name) {
433
+ const client = getClient2();
434
+ try {
435
+ const result = await client.keys.create(name || "CLI Key");
436
+ console.log(`
437
+ \u2714 API key created`);
438
+ console.log(`
439
+ Key: ${result.key}`);
440
+ console.log(` Name: ${result.name}`);
441
+ console.log(` Tier: ${result.tier}`);
442
+ console.log("\n (Shown once \u2014 copy it now and save it securely)\n");
443
+ } catch (err) {
444
+ console.error(`
445
+ \u2716 ${err instanceof Error ? err.message : "Unknown error"}
446
+ `);
447
+ process.exit(1);
448
+ }
449
+ }
450
+ async function keysRevokeCommand(keyId) {
451
+ const client = getClient2();
452
+ try {
453
+ await client.keys.revoke(keyId);
454
+ console.log(`
455
+ \u2714 Key ${keyId} revoked.
456
+ `);
457
+ } catch (err) {
458
+ console.error(`
459
+ \u2716 ${err instanceof Error ? err.message : "Unknown error"}
460
+ `);
461
+ process.exit(1);
462
+ }
463
+ }
464
+
338
465
  // src/cli/index.ts
339
466
  var [, , command, sub, ...args] = process.argv;
340
467
  async function main() {
@@ -344,10 +471,21 @@ async function main() {
344
471
  break;
345
472
  case "logout":
346
473
  clearConfig();
347
- console.log("\n \u2714 Logged out. Config cleared.\n");
474
+ console.log("\n \u2714 Logged out.\n");
475
+ break;
476
+ case "whoami": {
477
+ const config = loadConfig();
478
+ if (!config?.email) {
479
+ console.log("\n Not logged in. Run: valta login\n");
480
+ } else {
481
+ console.log(`
482
+ ${config.email} (${config.tier || "free"} tier)
483
+ `);
484
+ }
348
485
  break;
486
+ }
349
487
  case "agents":
350
- if (sub === "list" || !sub) {
488
+ if (!sub || sub === "list") {
351
489
  await agentsListCommand();
352
490
  } else if (sub === "freeze" && args[0]) {
353
491
  await agentsFreezeCommand(args[0]);
@@ -357,15 +495,35 @@ async function main() {
357
495
  console.log(" valta agents freeze [id]\n");
358
496
  }
359
497
  break;
498
+ case "keys":
499
+ if (!sub || sub === "list") {
500
+ await keysListCommand();
501
+ } else if (sub === "create") {
502
+ await keysCreateCommand(args[0] || "");
503
+ } else if (sub === "revoke" && args[0]) {
504
+ await keysRevokeCommand(args[0]);
505
+ } else {
506
+ console.log("\n Usage:");
507
+ console.log(" valta keys list");
508
+ console.log(" valta keys create [name]");
509
+ console.log(" valta keys revoke [id]\n");
510
+ }
511
+ break;
360
512
  default:
361
513
  console.log(`
362
514
  Valta CLI
363
515
 
364
516
  Commands:
365
- valta login Save your API key
366
- valta logout Clear credentials
367
- valta agents list List all agents
368
- valta agents freeze [id] Freeze an agent
517
+ valta login Authenticate with email + password
518
+ valta logout Clear credentials
519
+ valta whoami Show current user
520
+
521
+ valta agents list List all agents
522
+ valta agents freeze [id] Freeze an agent
523
+
524
+ valta keys list List API keys
525
+ valta keys create [name] Generate a new API key
526
+ valta keys revoke [id] Revoke a key
369
527
  `);
370
528
  }
371
529
  }
package/dist/cli/index.js CHANGED
@@ -31,25 +31,86 @@ function getApiKey() {
31
31
  }
32
32
 
33
33
  // src/cli/commands/login.ts
34
- function prompt(question) {
34
+ var BASE_URL = "https://valta.co/api/v1";
35
+ function prompt(question, hidden = false) {
35
36
  const rl = createInterface({ input: process.stdin, output: process.stdout });
36
37
  return new Promise((resolve) => {
37
- rl.question(question, (answer) => {
38
- rl.close();
39
- resolve(answer.trim());
40
- });
38
+ if (hidden) {
39
+ process.stdout.write(question);
40
+ process.stdin.setRawMode?.(true);
41
+ let input = "";
42
+ process.stdin.resume();
43
+ process.stdin.setEncoding("utf8");
44
+ process.stdin.on("data", function handler(char) {
45
+ if (char === "\n" || char === "\r" || char === "") {
46
+ process.stdin.setRawMode?.(false);
47
+ process.stdin.pause();
48
+ process.stdin.removeListener("data", handler);
49
+ process.stdout.write("\n");
50
+ rl.close();
51
+ resolve(input);
52
+ } else if (char === "") {
53
+ process.exit();
54
+ } else if (char === "\x7F") {
55
+ if (input.length > 0) {
56
+ input = input.slice(0, -1);
57
+ process.stdout.clearLine?.(0);
58
+ process.stdout.cursorTo?.(0);
59
+ process.stdout.write(question + "\u2022".repeat(input.length));
60
+ }
61
+ } else {
62
+ input += char;
63
+ process.stdout.write("\u2022");
64
+ }
65
+ });
66
+ } else {
67
+ rl.question(question, (answer) => {
68
+ rl.close();
69
+ resolve(answer.trim());
70
+ });
71
+ }
41
72
  });
42
73
  }
43
74
  async function loginCommand() {
44
75
  console.log("\n Valta Login\n");
45
- const apiKey = await prompt(" API Key: ");
46
- if (!apiKey || !apiKey.startsWith("sk_valta_")) {
47
- console.error("\n \u2716 Invalid API key. Keys start with sk_valta_\n");
76
+ const email = await prompt(" Email: ");
77
+ const password = await prompt(" Password: ", true);
78
+ if (!email || !password) {
79
+ console.error("\n \u2716 Email and password are required.\n");
80
+ process.exit(1);
81
+ }
82
+ try {
83
+ const res = await fetch(`${BASE_URL}/auth/login`, {
84
+ method: "POST",
85
+ headers: { "Content-Type": "application/json" },
86
+ body: JSON.stringify({ email, password })
87
+ });
88
+ const data = await res.json();
89
+ if (!res.ok || !data.success) {
90
+ console.error(`
91
+ \u2716 ${data.error || "Login failed"}
92
+ `);
93
+ process.exit(1);
94
+ }
95
+ const tier = data.tier || "free";
96
+ if (data.hasExistingKey) {
97
+ saveConfig({ apiKey: "", email: data.email, tier });
98
+ console.log(`
99
+ \u2714 Authenticated as ${data.email} (${tier} tier)`);
100
+ console.log(` You already have an API key (${data.apiKeyPrefix}...)`);
101
+ console.log(" Run: valta keys create [name] to generate a new key\n");
102
+ } else {
103
+ saveConfig({ apiKey: data.apiKey, email: data.email, tier });
104
+ console.log(`
105
+ \u2714 Authenticated as ${data.email} (${tier} tier)`);
106
+ console.log(`
107
+ API Key: ${data.apiKey}`);
108
+ console.log(" (Saved to ~/.valta/config.json \u2014 shown once)\n");
109
+ }
110
+ } catch {
111
+ console.error("\n \u2716 Could not connect to Valta. Check your internet connection.\n");
48
112
  process.exit(1);
49
113
  }
50
- saveConfig({ apiKey });
51
- console.log("\n \u2714 API key saved to ~/.valta/config.json");
52
- console.log(" You can now use the Valta SDK.\n");
53
114
  }
54
115
 
55
116
  // src/cli/commands/agents.ts
@@ -66,16 +127,16 @@ async function agentsListCommand() {
66
127
  try {
67
128
  const result = await client.agents.list();
68
129
  const agents = result.agents;
69
- if (agents.length === 0) {
130
+ if (!agents.length) {
70
131
  console.log("\n No agents found. Create one at https://valta.co/dashboard\n");
71
132
  return;
72
133
  }
73
- console.log("\n ID NAME STATUS");
74
- console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
134
+ console.log("\n ID NAME STATUS");
135
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
75
136
  for (const agent of agents) {
76
- const id = agent.id.padEnd(16);
77
- const name = agent.name.padEnd(23);
78
- const status = agent.status;
137
+ const id = (agent.id || "").padEnd(24);
138
+ const name = (agent.name || "").padEnd(23);
139
+ const status = agent.status || "";
79
140
  console.log(` ${id} ${name} ${status}`);
80
141
  }
81
142
  console.log();
@@ -101,6 +162,72 @@ async function agentsFreezeCommand(agentId) {
101
162
  }
102
163
  }
103
164
 
165
+ // src/cli/commands/keys.ts
166
+ function getClient2() {
167
+ const apiKey = getApiKey();
168
+ if (!apiKey) {
169
+ console.error("\n \u2716 Not logged in. Run: valta login\n");
170
+ process.exit(1);
171
+ }
172
+ return new ValtaClient(apiKey);
173
+ }
174
+ async function keysListCommand() {
175
+ const client = getClient2();
176
+ try {
177
+ const keys = await client.keys.list();
178
+ if (!keys.length) {
179
+ console.log("\n No API keys found.\n");
180
+ return;
181
+ }
182
+ console.log("\n PREFIX NAME CREATED");
183
+ console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
184
+ for (const key of keys) {
185
+ const prefix = (key.prefix || "").padEnd(15);
186
+ const name = (key.name || "").padEnd(23);
187
+ const created = key.createdAt ? new Date(key.createdAt).toLocaleDateString() : "";
188
+ console.log(` ${prefix} ${name} ${created}`);
189
+ }
190
+ console.log();
191
+ } catch (err) {
192
+ console.error(`
193
+ \u2716 ${err instanceof Error ? err.message : "Unknown error"}
194
+ `);
195
+ process.exit(1);
196
+ }
197
+ }
198
+ async function keysCreateCommand(name) {
199
+ const client = getClient2();
200
+ try {
201
+ const result = await client.keys.create(name || "CLI Key");
202
+ console.log(`
203
+ \u2714 API key created`);
204
+ console.log(`
205
+ Key: ${result.key}`);
206
+ console.log(` Name: ${result.name}`);
207
+ console.log(` Tier: ${result.tier}`);
208
+ console.log("\n (Shown once \u2014 copy it now and save it securely)\n");
209
+ } catch (err) {
210
+ console.error(`
211
+ \u2716 ${err instanceof Error ? err.message : "Unknown error"}
212
+ `);
213
+ process.exit(1);
214
+ }
215
+ }
216
+ async function keysRevokeCommand(keyId) {
217
+ const client = getClient2();
218
+ try {
219
+ await client.keys.revoke(keyId);
220
+ console.log(`
221
+ \u2714 Key ${keyId} revoked.
222
+ `);
223
+ } catch (err) {
224
+ console.error(`
225
+ \u2716 ${err instanceof Error ? err.message : "Unknown error"}
226
+ `);
227
+ process.exit(1);
228
+ }
229
+ }
230
+
104
231
  // src/cli/index.ts
105
232
  var [, , command, sub, ...args] = process.argv;
106
233
  async function main() {
@@ -110,10 +237,21 @@ async function main() {
110
237
  break;
111
238
  case "logout":
112
239
  clearConfig();
113
- console.log("\n \u2714 Logged out. Config cleared.\n");
240
+ console.log("\n \u2714 Logged out.\n");
241
+ break;
242
+ case "whoami": {
243
+ const config = loadConfig();
244
+ if (!config?.email) {
245
+ console.log("\n Not logged in. Run: valta login\n");
246
+ } else {
247
+ console.log(`
248
+ ${config.email} (${config.tier || "free"} tier)
249
+ `);
250
+ }
114
251
  break;
252
+ }
115
253
  case "agents":
116
- if (sub === "list" || !sub) {
254
+ if (!sub || sub === "list") {
117
255
  await agentsListCommand();
118
256
  } else if (sub === "freeze" && args[0]) {
119
257
  await agentsFreezeCommand(args[0]);
@@ -123,15 +261,35 @@ async function main() {
123
261
  console.log(" valta agents freeze [id]\n");
124
262
  }
125
263
  break;
264
+ case "keys":
265
+ if (!sub || sub === "list") {
266
+ await keysListCommand();
267
+ } else if (sub === "create") {
268
+ await keysCreateCommand(args[0] || "");
269
+ } else if (sub === "revoke" && args[0]) {
270
+ await keysRevokeCommand(args[0]);
271
+ } else {
272
+ console.log("\n Usage:");
273
+ console.log(" valta keys list");
274
+ console.log(" valta keys create [name]");
275
+ console.log(" valta keys revoke [id]\n");
276
+ }
277
+ break;
126
278
  default:
127
279
  console.log(`
128
280
  Valta CLI
129
281
 
130
282
  Commands:
131
- valta login Save your API key
132
- valta logout Clear credentials
133
- valta agents list List all agents
134
- valta agents freeze [id] Freeze an agent
283
+ valta login Authenticate with email + password
284
+ valta logout Clear credentials
285
+ valta whoami Show current user
286
+
287
+ valta agents list List all agents
288
+ valta agents freeze [id] Freeze an agent
289
+
290
+ valta keys list List API keys
291
+ valta keys create [name] Generate a new API key
292
+ valta keys revoke [id] Revoke a key
135
293
  `);
136
294
  }
137
295
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valta-sdk",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "Official SDK for Valta — AI agent financial infrastructure",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",