valta-sdk 2.1.8 → 2.2.2
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/README.md +79 -188
- package/bin/valta.js +12 -12
- package/dist/cli/index.js +90 -437
- package/dist/index.cjs +2 -276
- package/dist/index.d.ts +285 -131
- package/dist/index.js +2 -17
- package/package.json +56 -35
- package/dist/chunk-HGO47A3L.mjs +0 -244
- package/dist/chunk-LBY67QV7.js +0 -244
- package/dist/chunk-LPBJPXJO.js +0 -244
- package/dist/cli/index.cjs +0 -678
- package/dist/cli/index.d.cts +0 -2
- package/dist/cli/index.d.mts +0 -2
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.mjs +0 -141
- package/dist/index.d.cts +0 -197
- package/dist/index.d.mts +0 -197
- package/dist/index.mjs +0 -17
package/dist/cli/index.js
CHANGED
|
@@ -1,444 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
resolve(answer.trim());
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
async function loginCommand() {
|
|
75
|
-
console.log("\n Valta Login\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: data.apiKey, email: data.email, tier });
|
|
98
|
-
console.log(`
|
|
99
|
-
\u2714 Authenticated as ${data.email} (${tier} tier)`);
|
|
100
|
-
console.log(` API Key: ${data.apiKey}`);
|
|
101
|
-
console.log(" (Saved automatically \u2014 shown once)\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");
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/cli/commands/agents.ts
|
|
117
|
-
function getClient() {
|
|
118
|
-
const apiKey = getApiKey();
|
|
119
|
-
if (!apiKey) {
|
|
120
|
-
console.error("\n \u2716 Not logged in. Run: valta login\n");
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
return new ValtaClient(apiKey);
|
|
124
|
-
}
|
|
125
|
-
async function agentsListCommand() {
|
|
126
|
-
const client = getClient();
|
|
127
|
-
try {
|
|
128
|
-
const result = await client.agents.list();
|
|
129
|
-
const agents = result.agents;
|
|
130
|
-
if (!agents.length) {
|
|
131
|
-
console.log("\n No agents found. Create one at https://valta.co/dashboard\n");
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
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");
|
|
136
|
-
for (const agent of agents) {
|
|
137
|
-
const id = (agent.id || "").padEnd(24);
|
|
138
|
-
const name = (agent.name || "").padEnd(23);
|
|
139
|
-
const status = agent.status || "";
|
|
140
|
-
console.log(` ${id} ${name} ${status}`);
|
|
141
|
-
}
|
|
142
|
-
console.log();
|
|
143
|
-
} catch (err) {
|
|
144
|
-
console.error(`
|
|
145
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
146
|
-
`);
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async function agentsFreezeCommand(agentId) {
|
|
151
|
-
const client = getClient();
|
|
152
|
-
try {
|
|
153
|
-
await client.agents.freeze(agentId);
|
|
154
|
-
console.log(`
|
|
155
|
-
\u2714 Agent ${agentId} frozen.
|
|
156
|
-
`);
|
|
157
|
-
} catch (err) {
|
|
158
|
-
console.error(`
|
|
159
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
160
|
-
`);
|
|
161
|
-
process.exit(1);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async function agentsUnfreezeCommand(agentId) {
|
|
165
|
-
const client = getClient();
|
|
166
|
-
try {
|
|
167
|
-
await client.agents.unfreeze(agentId);
|
|
168
|
-
console.log(`
|
|
169
|
-
\u2714 Agent ${agentId} unfrozen.
|
|
170
|
-
`);
|
|
171
|
-
} catch (err) {
|
|
172
|
-
console.error(`
|
|
173
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
174
|
-
`);
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// src/cli/commands/keys.ts
|
|
180
|
-
function getClient2() {
|
|
181
|
-
const apiKey = getApiKey();
|
|
182
|
-
if (!apiKey) {
|
|
183
|
-
console.error("\n \u2716 Not logged in. Run: valta login\n");
|
|
184
|
-
process.exit(1);
|
|
185
|
-
}
|
|
186
|
-
return new ValtaClient(apiKey);
|
|
187
|
-
}
|
|
188
|
-
async function keysListCommand() {
|
|
189
|
-
const client = getClient2();
|
|
190
|
-
try {
|
|
191
|
-
const keys = await client.keys.list();
|
|
192
|
-
if (!keys.length) {
|
|
193
|
-
console.log("\n No API keys found.\n");
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
console.log("\n PREFIX NAME CREATED");
|
|
197
|
-
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");
|
|
198
|
-
for (const key of keys) {
|
|
199
|
-
const prefix = (key.prefix || "").padEnd(15);
|
|
200
|
-
const name = (key.name || "").padEnd(23);
|
|
201
|
-
const created = key.createdAt ? new Date(key.createdAt).toLocaleDateString() : "";
|
|
202
|
-
console.log(` ${prefix} ${name} ${created}`);
|
|
203
|
-
}
|
|
204
|
-
console.log();
|
|
205
|
-
} catch (err) {
|
|
206
|
-
console.error(`
|
|
207
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
208
|
-
`);
|
|
209
|
-
process.exit(1);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
async function keysCreateCommand(name) {
|
|
213
|
-
const client = getClient2();
|
|
214
|
-
try {
|
|
215
|
-
const result = await client.keys.create(name || "CLI Key");
|
|
216
|
-
console.log(`
|
|
217
|
-
\u2714 API key created`);
|
|
218
|
-
console.log(`
|
|
219
|
-
Key: ${result.key}`);
|
|
220
|
-
console.log(` Name: ${result.name}`);
|
|
221
|
-
console.log(` Tier: ${result.tier}`);
|
|
222
|
-
console.log("\n (Shown once \u2014 copy it now and save it securely)\n");
|
|
223
|
-
} catch (err) {
|
|
224
|
-
console.error(`
|
|
225
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
226
|
-
`);
|
|
227
|
-
process.exit(1);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async function keysRevokeCommand(keyId) {
|
|
231
|
-
const client = getClient2();
|
|
232
|
-
try {
|
|
233
|
-
await client.keys.revoke(keyId);
|
|
234
|
-
console.log(`
|
|
235
|
-
\u2714 Key ${keyId} revoked.
|
|
236
|
-
`);
|
|
237
|
-
} catch (err) {
|
|
238
|
-
console.error(`
|
|
239
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
240
|
-
`);
|
|
241
|
-
process.exit(1);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// src/cli/commands/wallet.ts
|
|
246
|
-
var BASE_URL2 = "https://valta.co/api/v1";
|
|
247
|
-
function getKey() {
|
|
248
|
-
const key = getApiKey();
|
|
249
|
-
if (!key) {
|
|
250
|
-
console.error("\n \u2716 Not logged in. Run: valta login\n");
|
|
251
|
-
process.exit(1);
|
|
252
|
-
}
|
|
253
|
-
return key;
|
|
254
|
-
}
|
|
255
|
-
async function walletCommand() {
|
|
256
|
-
const apiKey = getKey();
|
|
257
|
-
try {
|
|
258
|
-
const res = await fetch(`${BASE_URL2}/wallet`, {
|
|
259
|
-
headers: { "x-api-key": apiKey }
|
|
260
|
-
});
|
|
261
|
-
const data = await res.json();
|
|
262
|
-
if (!res.ok || !data.success) {
|
|
263
|
-
console.error(`
|
|
264
|
-
\u2716 ${data.error || "Failed to fetch wallet"}
|
|
265
|
-
`);
|
|
266
|
-
process.exit(1);
|
|
267
|
-
}
|
|
268
|
-
const m = data.mainWallet;
|
|
269
|
-
const a = data.agentWallet;
|
|
270
|
-
console.log("\n \u250C\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\u2510");
|
|
271
|
-
console.log(" \u2502 Your Wallets \u2502");
|
|
272
|
-
console.log(" \u251C\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\u2524");
|
|
273
|
-
console.log(` \u2502 Main Wallet \u2502`);
|
|
274
|
-
console.log(` \u2502 Balance: $${String(m.balance.toFixed(2)).padEnd(23)} \u2502`);
|
|
275
|
-
console.log(` \u2502 Locked: $${String(m.lockedBalance.toFixed(2)).padEnd(23)} \u2502`);
|
|
276
|
-
console.log(` \u2502 Currency: ${String(m.currency).padEnd(24)} \u2502`);
|
|
277
|
-
console.log(` \u2502 Mode: ${String(m.mode).padEnd(24)} \u2502`);
|
|
278
|
-
console.log(" \u251C\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\u2524");
|
|
279
|
-
console.log(` \u2502 Agent Wallet \u2502`);
|
|
280
|
-
console.log(` \u2502 Balance: $${String(Number(a.balance).toFixed(2)).padEnd(23)} \u2502`);
|
|
281
|
-
console.log(` \u2502 Used for per-message chat costs \u2502`);
|
|
282
|
-
console.log(" \u2514\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\u2518\n");
|
|
283
|
-
} catch {
|
|
284
|
-
console.error("\n \u2716 Could not connect to Valta.\n");
|
|
285
|
-
process.exit(1);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
async function walletAgentBalanceCommand(agentId) {
|
|
289
|
-
if (!agentId) {
|
|
290
|
-
console.error("\n \u2716 Agent ID required. Usage: valta wallet agent [agentId]\n");
|
|
291
|
-
process.exit(1);
|
|
292
|
-
}
|
|
293
|
-
const apiKey = getKey();
|
|
294
|
-
try {
|
|
295
|
-
const res = await fetch(`${BASE_URL2}/agents/${agentId}/wallet`, {
|
|
296
|
-
headers: { "x-api-key": apiKey }
|
|
297
|
-
});
|
|
298
|
-
const data = await res.json();
|
|
299
|
-
if (!res.ok || !data.success) {
|
|
300
|
-
console.error(`
|
|
301
|
-
\u2716 ${data.error || "Failed to fetch agent wallet"}
|
|
302
|
-
`);
|
|
303
|
-
process.exit(1);
|
|
304
|
-
}
|
|
305
|
-
const w = data.wallet;
|
|
306
|
-
console.log(`
|
|
307
|
-
Custom Agent Wallet \u2014 ${agentId}`);
|
|
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`);
|
|
309
|
-
console.log(` Balance: ${w.usdc} USDC`);
|
|
310
|
-
console.log(` Pending: ${w.usdcPending} USDC`);
|
|
311
|
-
console.log(` Status: ${w.status}
|
|
312
|
-
`);
|
|
313
|
-
} catch {
|
|
314
|
-
console.error("\n \u2716 Could not connect to Valta.\n");
|
|
315
|
-
process.exit(1);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// src/cli/commands/audit.ts
|
|
320
|
-
function getClient3() {
|
|
321
|
-
const apiKey = getApiKey();
|
|
322
|
-
if (!apiKey) {
|
|
323
|
-
console.error("\n \u2716 Not logged in. Run: valta login\n");
|
|
324
|
-
process.exit(1);
|
|
325
|
-
}
|
|
326
|
-
return new ValtaClient(apiKey);
|
|
327
|
-
}
|
|
328
|
-
async function auditCommand(agentId) {
|
|
329
|
-
const client = getClient3();
|
|
330
|
-
try {
|
|
331
|
-
const { logs } = await client.audit.list({ agentId, limit: 20 });
|
|
332
|
-
if (!logs.length) {
|
|
333
|
-
console.log("\n No audit logs found.\n");
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
console.log("\n TIME ACTION AGENT");
|
|
337
|
-
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");
|
|
338
|
-
for (const log of logs) {
|
|
339
|
-
const time = new Date(log.createdAt).toLocaleString().padEnd(24);
|
|
340
|
-
const action = (log.action || "").padEnd(19);
|
|
341
|
-
const agent = log.agentId || "";
|
|
342
|
-
console.log(` ${time} ${action} ${agent}`);
|
|
343
|
-
}
|
|
344
|
-
console.log();
|
|
345
|
-
} catch (err) {
|
|
346
|
-
console.error(`
|
|
347
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
348
|
-
`);
|
|
349
|
-
process.exit(1);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// src/cli/index.ts
|
|
354
|
-
var [, , command, sub, ...args] = process.argv;
|
|
355
|
-
async function main() {
|
|
356
|
-
switch (command) {
|
|
357
|
-
case "login":
|
|
358
|
-
await loginCommand();
|
|
359
|
-
break;
|
|
360
|
-
case "logout":
|
|
361
|
-
clearConfig();
|
|
362
|
-
console.log("\n \u2714 Logged out.\n");
|
|
363
|
-
break;
|
|
364
|
-
case "whoami": {
|
|
365
|
-
const config = loadConfig();
|
|
366
|
-
if (!config?.email) {
|
|
367
|
-
console.log("\n Not logged in. Run: valta login\n");
|
|
368
|
-
} else {
|
|
369
|
-
console.log(`
|
|
370
|
-
${config.email} (${config.tier || "free"} tier)
|
|
371
|
-
`);
|
|
372
|
-
}
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
case "agents":
|
|
376
|
-
if (!sub || sub === "list") {
|
|
377
|
-
await agentsListCommand();
|
|
378
|
-
} else if (sub === "freeze" && args[0]) {
|
|
379
|
-
await agentsFreezeCommand(args[0]);
|
|
380
|
-
} else if (sub === "unfreeze" && args[0]) {
|
|
381
|
-
await agentsUnfreezeCommand(args[0]);
|
|
382
|
-
} else {
|
|
383
|
-
console.log("\n Usage:");
|
|
384
|
-
console.log(" valta agents list");
|
|
385
|
-
console.log(" valta agents freeze [id]");
|
|
386
|
-
console.log(" valta agents unfreeze [id]\n");
|
|
387
|
-
}
|
|
388
|
-
break;
|
|
389
|
-
case "wallet":
|
|
390
|
-
if (!sub || sub === "balance") {
|
|
391
|
-
await walletCommand();
|
|
392
|
-
} else if (sub === "agent" && args[0]) {
|
|
393
|
-
await walletAgentBalanceCommand(args[0]);
|
|
394
|
-
} else {
|
|
395
|
-
console.log("\n Usage:");
|
|
396
|
-
console.log(" valta wallet Show main + agent wallet balances");
|
|
397
|
-
console.log(" valta wallet agent [agentId] Show custom agent wallet balance\n");
|
|
398
|
-
}
|
|
399
|
-
break;
|
|
400
|
-
case "keys":
|
|
401
|
-
if (!sub || sub === "list") {
|
|
402
|
-
await keysListCommand();
|
|
403
|
-
} else if (sub === "create") {
|
|
404
|
-
await keysCreateCommand(args[0] || "");
|
|
405
|
-
} else if (sub === "revoke" && args[0]) {
|
|
406
|
-
await keysRevokeCommand(args[0]);
|
|
407
|
-
} else {
|
|
408
|
-
console.log("\n Usage:");
|
|
409
|
-
console.log(" valta keys list");
|
|
410
|
-
console.log(" valta keys create [name]");
|
|
411
|
-
console.log(" valta keys revoke [id]\n");
|
|
412
|
-
}
|
|
413
|
-
break;
|
|
414
|
-
case "audit":
|
|
415
|
-
await auditCommand(sub);
|
|
416
|
-
break;
|
|
417
|
-
default:
|
|
418
|
-
console.log(`
|
|
1
|
+
import {homedir}from'os';import {join}from'path';import {existsSync,readFileSync,writeFileSync,mkdirSync}from'fs';import {createInterface}from'readline';var A=class{constructor(e){this.http=e;}async login(e,n){return this.http.post("/auth/login",{email:e,password:n},false)}async logout(){await this.http.post("/auth/logout");}async whoami(){return this.http.get("/auth/whoami")}async refreshToken(){return this.http.post("/auth/refresh-token")}};var R=class{constructor(e){this.http=e;}async create(e){return this.http.post("/agents",e)}async list(e){return this.http.get("/agents",e)}async get(e){return this.http.get(`/agents/${encodeURIComponent(e)}`)}async update(e,n){return this.http.patch(`/agents/${encodeURIComponent(e)}`,n)}async delete(e){return this.http.delete(`/agents/${encodeURIComponent(e)}`)}async freeze(e){return this.http.post(`/agents/${encodeURIComponent(e)}/freeze`)}async unfreeze(e){return this.http.post(`/agents/${encodeURIComponent(e)}/unfreeze`)}async run(e,n){return this.http.post(`/agents/${encodeURIComponent(e)}/run`,n)}async getRun(e,n){return this.http.get(`/agents/${encodeURIComponent(e)}/runs/${encodeURIComponent(n)}`)}async listRuns(e,n){return this.http.get(`/agents/${encodeURIComponent(e)}/runs`,n)}};var w=class{constructor(e){this.http=e;}async list(e){return this.http.get("/audit",e)}async get(e){return this.http.get(`/audit/${encodeURIComponent(e)}`)}async export(e){let n=[],s=1,r=true;for(;r;){let l=await this.list({...e,page:s,limit:100});n.push(...l.data),r=l.pagination.hasMore,s+=1;}return n}async verify(e){return this.http.get(`/audit/verify/${encodeURIComponent(e)}`)}};var C=class{constructor(e){this.http=e;}async create(e){return this.http.post("/keys",e)}async list(){return this.http.get("/keys")}async revoke(e){return this.http.delete(`/keys/${encodeURIComponent(e)}`)}};var d=class extends Error{constructor(e){super(e.message),this.name="ValtaError",this.code=e.code,this.status=e.status??null,this.details=e.details??null;}isRateLimit(){return this.code==="RATE_LIMIT_EXCEEDED"}isAuth(){return this.code==="UNAUTHORISED"||this.code==="FORBIDDEN"}requiresApproval(){return this.code==="APPROVAL_REQUIRED"}};var I=class{constructor(e){this.http=e;}async create(e){return this.http.post("/policies",e)}async get(e){try{return await this.http.get(`/policies/${encodeURIComponent(e)}`)}catch(n){if(n instanceof d&&n.code==="NOT_FOUND")return null;throw n}}async update(e,n){return this.http.patch(`/policies/${encodeURIComponent(e)}`,n)}async delete(e){return this.http.delete(`/policies/${encodeURIComponent(e)}`)}async list(){return this.http.get("/policies")}};var P=class{constructor(e){this.http=e;}async get(e){return this.http.get(`/wallets/${encodeURIComponent(e)}`)}async getBalance(e){return (await this.get(e)).balance}async getDepositAddress(e){return this.http.get(`/wallets/${encodeURIComponent(e)}/deposit-address`)}async listTransactions(e,n){return this.http.get(`/wallets/${encodeURIComponent(e)}/transactions`,n)}async transfer(e){return this.http.post("/wallets/transfer",e)}};var x="2.2.0",T=class{constructor(e){this.apiKey=e.apiKey,this.baseUrl=(e.baseUrl??"https://valta.co/api/v1").replace(/\/$/,""),this.timeout=e.timeout??3e4;}async request(e){let n=`${this.baseUrl}${e.path}`;if(e.query){let o=new URLSearchParams;for(let[E,p]of Object.entries(e.query))p!==void 0&&o.set(E,String(p));let f=o.toString();f&&(n+=`?${f}`);}let s=new AbortController,r=setTimeout(()=>s.abort(),this.timeout),l={"Content-Type":"application/json","User-Agent":`valta-sdk/${x}`,"X-Valta-SDK":x};e.authenticated!==false&&(l["x-api-key"]=this.apiKey);try{let o=await fetch(n,{method:e.method,headers:l,body:e.body===void 0?void 0:JSON.stringify(e.body),signal:s.signal});clearTimeout(r);let f=await o.text(),E=f?ee(f,o.status):null;if(!o.ok){let p=E??{};throw new d({message:p.message??p.error??`HTTP ${o.status}`,code:te(p.code,o.status),status:o.status,details:p})}return E}catch(o){throw clearTimeout(r),o instanceof d?o:o instanceof Error&&o.name==="AbortError"?new d({message:`Request timed out after ${this.timeout}ms`,code:"TIMEOUT"}):new d({message:o instanceof Error?o.message:"An unknown network error occurred",code:"NETWORK_ERROR"})}}get(e,n){return this.request({method:"GET",path:e,query:n})}post(e,n,s=true){return this.request({method:"POST",path:e,body:n,authenticated:s})}patch(e,n){return this.request({method:"PATCH",path:e,body:n})}delete(e){return this.request({method:"DELETE",path:e})}};function ee(t,e){try{return JSON.parse(t)}catch{throw new d({message:"Invalid JSON response from server",code:"SERVER_ERROR",status:e})}}function te(t,e){let n=String(t||"").toUpperCase();if(n==="UNAUTHORIZED"||n==="API_KEY_REQUIRED"||n==="INVALID_API_KEY")return "UNAUTHORISED";if(n==="RATE_LIMIT"||n==="API_KEY_RATE_LIMITED")return "RATE_LIMIT_EXCEEDED";if(n==="TIER_LIMIT")return "TIER_LIMIT_EXCEEDED";if(ne(n))return n;switch(e){case 400:return "INVALID_REQUEST";case 401:return "UNAUTHORISED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 429:return "RATE_LIMIT_EXCEEDED";default:return "SERVER_ERROR"}}function ne(t){return ["UNAUTHORISED","FORBIDDEN","NOT_FOUND","RATE_LIMIT_EXCEEDED","TIER_LIMIT_EXCEEDED","AGENT_FROZEN","POLICY_VIOLATION","INSUFFICIENT_BALANCE","APPROVAL_REQUIRED","INVALID_REQUEST","SERVER_ERROR","NETWORK_ERROR","TIMEOUT"].includes(t)}var c=class{constructor(e){let n=typeof e=="string"?{apiKey:e}:e;if(!n.apiKey)throw new Error("Valta API key is required. Get one at https://valta.co/dashboard/api-keys");this.http=new T(n),this.auth=new A(this.http),this.agents=new R(this.http),this.wallets=new P(this.http),this.policies=new I(this.http),this.audit=new w(this.http),this.keys=new C(this.http);}};var U=join(homedir(),".valta"),y=join(U,"config.json");function N(t){existsSync(U)||mkdirSync(U,{recursive:true}),writeFileSync(y,JSON.stringify(t,null,2));}function v(){if(!existsSync(y))return null;try{return JSON.parse(readFileSync(y,"utf-8"))}catch{return null}}function _(){existsSync(y)&&writeFileSync(y,"{}");}function g(){return v()?.apiKey??null}function u(){return v()}function re(){let t=g();t||(console.error(`
|
|
2
|
+
Not logged in. Run: valta login
|
|
3
|
+
`),process.exit(1));let e=u()?.baseUrl??process.env.VALTA_BASE_URL;return new c({apiKey:t,baseUrl:e})}async function S(t){let e=await re().audit.list({agentId:t,limit:20}),n=Array.isArray(e)?e:e?.data??[];if(!n.length){console.log(`
|
|
4
|
+
No audit entries found.
|
|
5
|
+
`);return}console.log(`
|
|
6
|
+
TIME ACTION STATUS AGENT`),console.log(" ------------------------------------------------------------------");for(let s of n){let r=new Date(s.createdAt).toLocaleString().padEnd(24);console.log(` ${r} ${s.action.padEnd(19)} ${s.status.padEnd(10)} ${s.agentId}`);}console.log();}function m(){let t=g();t||(console.error(`
|
|
7
|
+
Not logged in. Run: valta login
|
|
8
|
+
`),process.exit(1));let e=u()?.baseUrl??process.env.VALTA_BASE_URL;return new c({apiKey:t,baseUrl:e})}async function O(){let t=await m().agents.list({limit:20}),e=Array.isArray(t)?t:t?.data??[];if(!e.length){console.log(`
|
|
9
|
+
No agents found.
|
|
10
|
+
`);return}console.log(`
|
|
11
|
+
ID NAME STATUS BALANCE`),console.log(" -------------------------------------------------------------------");for(let n of e)console.log(` ${n.id.padEnd(24)} ${n.name.padEnd(23)} ${n.status.padEnd(11)} $${n.wallet.balance.toFixed(2)}`);console.log();}async function V(t){let e=t.join(" ").trim();e||(console.error(`
|
|
12
|
+
Usage: valta agents create "Agent Name"
|
|
13
|
+
`),process.exit(1));let n=await m().agents.create({name:e});console.log(`
|
|
14
|
+
Agent created: ${n.id}`),console.log(` Name: ${n.name}`),console.log(` Balance: $${n.wallet.balance.toFixed(2)}
|
|
15
|
+
`);}async function K(t){let e=await m().agents.get(t);console.log(`
|
|
16
|
+
${e.name}`),console.log(` ID: ${e.id}`),console.log(` Status: ${e.status}`),console.log(` Wallet: ${e.walletAddress}`),console.log(` Balance: $${e.wallet.balance.toFixed(2)}
|
|
17
|
+
`);}async function F(t,e){e.trim()||(console.error(`
|
|
18
|
+
Usage: valta agents run [agentId] "task"
|
|
19
|
+
`),process.exit(1));let n=await m().agents.run(t,{task:e});console.log(`
|
|
20
|
+
Run started: ${n.id}`),console.log(` Status: ${n.status}`),console.log(` Started: ${n.startedAt}
|
|
21
|
+
`);}async function B(t){let e=await m().agents.freeze(t);console.log(`
|
|
22
|
+
Agent ${e.agentId} frozen.
|
|
23
|
+
`);}async function M(t){let e=await m().agents.unfreeze(t);console.log(`
|
|
24
|
+
Agent ${e.agentId} active.
|
|
25
|
+
`);}async function j(t){await m().agents.delete(t),console.log(`
|
|
26
|
+
Agent ${t} deleted.
|
|
27
|
+
`);}function k(){let t=g();t||(console.error(`
|
|
28
|
+
Not logged in. Run: valta login
|
|
29
|
+
`),process.exit(1));let e=u()?.baseUrl??process.env.VALTA_BASE_URL;return new c({apiKey:t,baseUrl:e})}async function H(){let t=await k().keys.list();if(!t.length){console.log(`
|
|
30
|
+
No API keys found.
|
|
31
|
+
`);return}console.log(`
|
|
32
|
+
ID PREFIX NAME CREATED`),console.log(" --------------------------------------------------------------------------");for(let e of t){let n=e.createdAt?new Date(e.createdAt).toLocaleDateString():"";console.log(` ${e.id.padEnd(24)} ${e.keyPrefix.padEnd(15)} ${e.name.padEnd(23)} ${n}`);}console.log();}async function z(t){let e=await k().keys.create({name:t});console.log(`
|
|
33
|
+
API key created`),console.log(` Key: ${e.fullKey}`),console.log(` Name: ${e.name}`),console.log(` Prefix: ${e.keyPrefix}`),console.log(`
|
|
34
|
+
Save this key now. It will not be shown again.
|
|
35
|
+
`);}async function W(t){await k().keys.revoke(t),console.log(`
|
|
36
|
+
Key ${t} revoked.
|
|
37
|
+
`);}function q(t,e=false){let n=createInterface({input:process.stdin,output:process.stdout});return new Promise(s=>{if(!e){n.question(t,o=>{n.close(),s(o.trim());});return}process.stdout.write(t),process.stdin.setRawMode?.(true),process.stdin.resume(),process.stdin.setEncoding("utf8");let r="",l=o=>{o===`
|
|
38
|
+
`||o==="\r"||o===""?(process.stdin.setRawMode?.(false),process.stdin.pause(),process.stdin.removeListener("data",l),process.stdout.write(`
|
|
39
|
+
`),n.close(),s(r)):o===""?process.exit():o==="\x7F"?r=r.slice(0,-1):(r+=o,process.stdout.write("*"));};process.stdin.on("data",l);})}async function G(){console.log(`
|
|
40
|
+
Valta Login
|
|
41
|
+
`);let t=await q(" Email: "),e=await q(" Password: ",true);(!t||!e)&&(console.error(`
|
|
42
|
+
Email and password are required.
|
|
43
|
+
`),process.exit(1));let s=await new c({apiKey:"login",baseUrl:process.env.VALTA_BASE_URL}).auth.login(t,e),r=s?.user;if(!s?.token||!r?.email)throw new Error("Login response was missing token or user details. Check VALTA_BASE_URL and try again.");N({apiKey:s.token,email:r.email,tier:r.plan,baseUrl:process.env.VALTA_BASE_URL}),console.log(`
|
|
44
|
+
Authenticated as ${r.email} (${r.plan} plan)`),console.log(` API Key: ${s.token}`),console.log(` Saved to ~/.valta/config.json. The key is shown once.
|
|
45
|
+
`);}function h(){let t=g();t||(console.error(`
|
|
46
|
+
Not logged in. Run: valta login
|
|
47
|
+
`),process.exit(1));let e=u()?.baseUrl??process.env.VALTA_BASE_URL;return new c({apiKey:t,baseUrl:e})}async function X(t){t||(console.error(`
|
|
48
|
+
Usage: valta wallets get [agentId]
|
|
49
|
+
`),process.exit(1));let e=await h().wallets.get(t);console.log(`
|
|
50
|
+
Wallet: ${e.agentId}`),console.log(` Balance: $${e.balance.toFixed(2)} ${e.currency}`),console.log(` Daily spent: $${e.dailySpent.toFixed(2)}`),console.log(` Monthly spent: $${e.monthlySpent.toFixed(2)}`),console.log(` Daily limit: ${e.dailyLimit==null?"unlimited":`$${e.dailyLimit.toFixed(2)}`}`),console.log(` Monthly limit: ${e.monthlyLimit==null?"unlimited":`$${e.monthlyLimit.toFixed(2)}`}`),console.log(` Address: ${e.walletAddress}
|
|
51
|
+
`);}async function Q(t){let e=await h().wallets.getBalance(t);console.log(`
|
|
52
|
+
$${e.toFixed(2)} USDC
|
|
53
|
+
`);}async function J(t){let e=await h().wallets.getDepositAddress(t);console.log(`
|
|
54
|
+
Address: ${e.address}`),console.log(` Network: ${e.network}`),console.log(` Currency: ${e.currency}
|
|
55
|
+
`);}async function Y(t){let e=await h().wallets.listTransactions(t,{limit:20}),n=Array.isArray(e)?e:e?.data??[];if(!n.length){console.log(`
|
|
56
|
+
No transactions found.
|
|
57
|
+
`);return}console.log(`
|
|
58
|
+
ID TYPE AMOUNT STATUS`),console.log(" --------------------------------------------------------------");for(let s of n)console.log(` ${s.id.padEnd(24)} ${s.type.padEnd(16)} $${s.amount.toFixed(2).padEnd(10)} ${s.status}`);console.log();}async function Z(t){let[e,n,s,...r]=t,l=Number(s);(!e||!n||!Number.isFinite(l)||l<=0)&&(console.error(`
|
|
59
|
+
Usage: valta wallets transfer [fromAgentId] [toAgentId] [amount] [description]
|
|
60
|
+
`),process.exit(1));let o=await h().wallets.transfer({fromAgentId:e,toAgentId:n,amount:l,description:r.join(" ")||void 0});console.log(`
|
|
61
|
+
Transfer complete: ${o.transactionId}`),console.log(` From balance: $${o.fromBalance.toFixed(2)}`),console.log(` To balance: $${o.toBalance.toFixed(2)}
|
|
62
|
+
`);}var[,,le,i,...a]=process.argv;async function ce(){switch(le){case "login":await G();break;case "logout":_(),console.log(`
|
|
63
|
+
Logged out.
|
|
64
|
+
`);break;case "whoami":{let t=v();t?.email?console.log(`
|
|
65
|
+
${t.email} (${t.tier||"free"} plan)
|
|
66
|
+
`):console.log(`
|
|
67
|
+
Not logged in. Run: valta login
|
|
68
|
+
`);break}case "agents":!i||i==="list"?await O():i==="create"?await V(a):i==="get"&&a[0]?await K(a[0]):i==="run"&&a[0]?await F(a[0],a.slice(1).join(" ")):i==="freeze"&&a[0]?await B(a[0]):i==="unfreeze"&&a[0]?await M(a[0]):i==="delete"&&a[0]?await j(a[0]):$();break;case "wallets":case "wallet":!i||i==="get"?await X(a[0]):i==="balance"&&a[0]?await Q(a[0]):i==="deposit-address"&&a[0]?await J(a[0]):i==="transactions"&&a[0]?await Y(a[0]):i==="transfer"?await Z(a):$();break;case "keys":!i||i==="list"?await H():i==="create"?await z(a.join(" ")||"CLI Key"):i==="revoke"&&a[0]?await W(a[0]):$();break;case "audit":await S(i);break;default:$();}}function $(){console.log(`
|
|
419
69
|
Valta CLI
|
|
420
70
|
|
|
421
71
|
Commands:
|
|
422
|
-
valta login
|
|
423
|
-
valta logout
|
|
424
|
-
valta whoami
|
|
72
|
+
valta login Authenticate and create an API key
|
|
73
|
+
valta logout Clear local credentials
|
|
74
|
+
valta whoami Show the stored account
|
|
425
75
|
|
|
426
|
-
valta agents list
|
|
427
|
-
valta agents
|
|
428
|
-
valta agents
|
|
76
|
+
valta agents list List agents
|
|
77
|
+
valta agents create "Name" Create an agent
|
|
78
|
+
valta agents get [agentId] Get one agent
|
|
79
|
+
valta agents run [agentId] "task" Start an agent run
|
|
80
|
+
valta agents freeze [agentId] Freeze an agent
|
|
81
|
+
valta agents unfreeze [agentId] Unfreeze an agent
|
|
82
|
+
valta agents delete [agentId] Delete an agent
|
|
429
83
|
|
|
430
|
-
valta
|
|
431
|
-
valta
|
|
84
|
+
valta wallets get [agentId] Show wallet details
|
|
85
|
+
valta wallets balance [agentId] Show wallet balance
|
|
86
|
+
valta wallets deposit-address [id] Show deposit address
|
|
87
|
+
valta wallets transactions [id] List wallet transactions
|
|
88
|
+
valta wallets transfer [from] [to] [amount] [description]
|
|
432
89
|
|
|
433
|
-
valta keys list
|
|
434
|
-
valta keys create [name]
|
|
435
|
-
valta keys revoke [
|
|
90
|
+
valta keys list List API keys
|
|
91
|
+
valta keys create [name] Generate a new API key
|
|
92
|
+
valta keys revoke [keyId] Revoke an API key
|
|
436
93
|
|
|
437
|
-
valta audit [agentId]
|
|
438
|
-
`);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
main().catch((err) => {
|
|
442
|
-
console.error("\n \u2716 Unexpected error:", err.message, "\n");
|
|
443
|
-
process.exit(1);
|
|
444
|
-
});
|
|
94
|
+
valta audit [agentId] Show audit entries
|
|
95
|
+
`);}ce().catch(t=>{console.error(`
|
|
96
|
+
Unexpected error: ${t instanceof Error?t.message:"Unknown error"}
|
|
97
|
+
`),process.exit(1);});
|