valta-sdk 2.1.7 → 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 +92 -294
- 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 -533
- 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.cjs
DELETED
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// src/cli/commands/login.ts
|
|
4
|
-
var import_readline = require("readline");
|
|
5
|
-
|
|
6
|
-
// src/cli/config.ts
|
|
7
|
-
var import_os = require("os");
|
|
8
|
-
var import_path = require("path");
|
|
9
|
-
var import_fs = require("fs");
|
|
10
|
-
var CONFIG_DIR = (0, import_path.join)((0, import_os.homedir)(), ".valta");
|
|
11
|
-
var CONFIG_FILE = (0, import_path.join)(CONFIG_DIR, "config.json");
|
|
12
|
-
function saveConfig(config) {
|
|
13
|
-
if (!(0, import_fs.existsSync)(CONFIG_DIR)) (0, import_fs.mkdirSync)(CONFIG_DIR, { recursive: true });
|
|
14
|
-
(0, import_fs.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
15
|
-
}
|
|
16
|
-
function loadConfig() {
|
|
17
|
-
if (!(0, import_fs.existsSync)(CONFIG_FILE)) return null;
|
|
18
|
-
try {
|
|
19
|
-
return JSON.parse((0, import_fs.readFileSync)(CONFIG_FILE, "utf-8"));
|
|
20
|
-
} catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function clearConfig() {
|
|
25
|
-
if ((0, import_fs.existsSync)(CONFIG_FILE)) (0, import_fs.writeFileSync)(CONFIG_FILE, "{}");
|
|
26
|
-
}
|
|
27
|
-
function getApiKey() {
|
|
28
|
-
return loadConfig()?.apiKey ?? null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// src/cli/commands/login.ts
|
|
32
|
-
var BASE_URL = "https://valta.co/api/v1";
|
|
33
|
-
function prompt(question, hidden = false) {
|
|
34
|
-
const rl = (0, import_readline.createInterface)({ input: process.stdin, output: process.stdout });
|
|
35
|
-
return new Promise((resolve) => {
|
|
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
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async function loginCommand() {
|
|
73
|
-
console.log("\n Valta Login\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");
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/errors/index.ts
|
|
115
|
-
var ValtaError = class extends Error {
|
|
116
|
-
constructor(message, code, status) {
|
|
117
|
-
super(message);
|
|
118
|
-
this.name = "ValtaError";
|
|
119
|
-
this.code = code;
|
|
120
|
-
this.status = status;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var AuthError = class extends ValtaError {
|
|
124
|
-
constructor(message = "Invalid or missing API key") {
|
|
125
|
-
super(message, "UNAUTHORIZED", 401);
|
|
126
|
-
this.name = "AuthError";
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
var TierError = class extends ValtaError {
|
|
130
|
-
constructor(message, requiredTier) {
|
|
131
|
-
super(message, "TIER_LIMIT", 403);
|
|
132
|
-
this.name = "TierError";
|
|
133
|
-
this.requiredTier = requiredTier;
|
|
134
|
-
this.upgradeUrl = "https://valta.co/upgrade";
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var RateLimitError = class extends ValtaError {
|
|
138
|
-
constructor(message = "Rate limit exceeded. Slow down your requests.") {
|
|
139
|
-
super(message, "RATE_LIMIT", 429);
|
|
140
|
-
this.name = "RateLimitError";
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var NotFoundError = class extends ValtaError {
|
|
144
|
-
constructor(resource) {
|
|
145
|
-
super(`${resource} not found`, "NOT_FOUND", 404);
|
|
146
|
-
this.name = "NotFoundError";
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// src/http/requester.ts
|
|
151
|
-
var DEFAULT_BASE_URL = "https://valta.co/api/v1";
|
|
152
|
-
var Requester = class {
|
|
153
|
-
constructor(apiKey, baseUrl) {
|
|
154
|
-
if (!apiKey || typeof apiKey !== "string") {
|
|
155
|
-
throw new AuthError("An API key is required. Get one at https://valta.co/dashboard/api-keys");
|
|
156
|
-
}
|
|
157
|
-
this.apiKey = apiKey;
|
|
158
|
-
this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;
|
|
159
|
-
}
|
|
160
|
-
async request(path, options = {}) {
|
|
161
|
-
const { method = "GET", body } = options;
|
|
162
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
163
|
-
method,
|
|
164
|
-
headers: {
|
|
165
|
-
"x-api-key": this.apiKey,
|
|
166
|
-
"Content-Type": "application/json",
|
|
167
|
-
"X-Valta-SDK": "0.2.0"
|
|
168
|
-
},
|
|
169
|
-
body: body ? JSON.stringify(body) : void 0
|
|
170
|
-
});
|
|
171
|
-
if (!res.ok) {
|
|
172
|
-
let errorData = {};
|
|
173
|
-
try {
|
|
174
|
-
errorData = await res.json();
|
|
175
|
-
} catch {
|
|
176
|
-
}
|
|
177
|
-
const message = errorData.message ?? "An unknown error occurred";
|
|
178
|
-
switch (res.status) {
|
|
179
|
-
case 401:
|
|
180
|
-
throw new AuthError(message);
|
|
181
|
-
case 403:
|
|
182
|
-
throw new TierError(message, errorData.requiredTier ?? "builder");
|
|
183
|
-
case 404:
|
|
184
|
-
throw new NotFoundError(path);
|
|
185
|
-
case 429:
|
|
186
|
-
throw new RateLimitError(message);
|
|
187
|
-
default:
|
|
188
|
-
throw new ValtaError(message, "SERVER_ERROR", res.status);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return res.json();
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// src/resources/agents.ts
|
|
196
|
-
var AgentsResource = class {
|
|
197
|
-
constructor(requester) {
|
|
198
|
-
this.requester = requester;
|
|
199
|
-
}
|
|
200
|
-
// Get all agents
|
|
201
|
-
async list(params = {}) {
|
|
202
|
-
const query = new URLSearchParams();
|
|
203
|
-
if (params.limit) query.set("limit", String(params.limit));
|
|
204
|
-
if (params.offset) query.set("offset", String(params.offset));
|
|
205
|
-
if (params.status) query.set("status", params.status);
|
|
206
|
-
const qs = query.toString();
|
|
207
|
-
return this.requester.request(
|
|
208
|
-
`/agents${qs ? `?${qs}` : ""}`
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
// Get one agent by ID
|
|
212
|
-
async get(agentId) {
|
|
213
|
-
return this.requester.request(`/agents/${agentId}`);
|
|
214
|
-
}
|
|
215
|
-
// Create a new agent
|
|
216
|
-
async create(params) {
|
|
217
|
-
return this.requester.request("/agents", {
|
|
218
|
-
method: "POST",
|
|
219
|
-
body: params
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
// Update an agent
|
|
223
|
-
async update(agentId, params) {
|
|
224
|
-
return this.requester.request(`/agents/${agentId}`, {
|
|
225
|
-
method: "PATCH",
|
|
226
|
-
body: params
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
// Freeze an agent (stops it from spending)
|
|
230
|
-
async freeze(agentId) {
|
|
231
|
-
return this.requester.request(`/agents/${agentId}/freeze`, {
|
|
232
|
-
method: "POST"
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
// Unfreeze an agent
|
|
236
|
-
async unfreeze(agentId) {
|
|
237
|
-
return this.requester.request(`/agents/${agentId}/unfreeze`, {
|
|
238
|
-
method: "POST"
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
// Delete an agent
|
|
242
|
-
async delete(agentId) {
|
|
243
|
-
return this.requester.request(
|
|
244
|
-
`/agents/${agentId}`,
|
|
245
|
-
{ method: "DELETE" }
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
// src/resources/wallets.ts
|
|
251
|
-
var WalletsResource = class {
|
|
252
|
-
constructor(requester) {
|
|
253
|
-
this.requester = requester;
|
|
254
|
-
}
|
|
255
|
-
// Get wallet balance for an agent
|
|
256
|
-
async get(agentId) {
|
|
257
|
-
return this.requester.request(
|
|
258
|
-
`/agents/${agentId}/wallet`
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
// Transfer funds from one agent wallet to another
|
|
262
|
-
async transfer(agentId, params) {
|
|
263
|
-
return this.requester.request(
|
|
264
|
-
`/agents/${agentId}/wallet/transfer`,
|
|
265
|
-
{ method: "POST", body: params }
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
// src/resources/policies.ts
|
|
271
|
-
var PoliciesResource = class {
|
|
272
|
-
constructor(requester) {
|
|
273
|
-
this.requester = requester;
|
|
274
|
-
}
|
|
275
|
-
async list(agentId) {
|
|
276
|
-
const qs = agentId ? `?agentId=${agentId}` : "";
|
|
277
|
-
return this.requester.request(`/policies${qs}`);
|
|
278
|
-
}
|
|
279
|
-
async create(params) {
|
|
280
|
-
return this.requester.request("/policies", {
|
|
281
|
-
method: "POST",
|
|
282
|
-
body: params
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
async update(policyId, params) {
|
|
286
|
-
return this.requester.request(`/policies/${policyId}`, {
|
|
287
|
-
method: "PATCH",
|
|
288
|
-
body: params
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
async delete(policyId) {
|
|
292
|
-
return this.requester.request(`/policies/${policyId}`, {
|
|
293
|
-
method: "DELETE"
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
// src/resources/audit.ts
|
|
299
|
-
var AuditResource = class {
|
|
300
|
-
constructor(requester) {
|
|
301
|
-
this.requester = requester;
|
|
302
|
-
}
|
|
303
|
-
async list(params = {}) {
|
|
304
|
-
const query = new URLSearchParams();
|
|
305
|
-
if (params.agentId) query.set("agentId", params.agentId);
|
|
306
|
-
if (params.limit) query.set("limit", String(params.limit));
|
|
307
|
-
if (params.offset) query.set("offset", String(params.offset));
|
|
308
|
-
if (params.from) query.set("from", params.from);
|
|
309
|
-
if (params.to) query.set("to", params.to);
|
|
310
|
-
const qs = query.toString();
|
|
311
|
-
return this.requester.request(`/audit${qs ? `?${qs}` : ""}`);
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
// src/resources/keys.ts
|
|
316
|
-
var KeysResource = class {
|
|
317
|
-
constructor(requester) {
|
|
318
|
-
this.requester = requester;
|
|
319
|
-
}
|
|
320
|
-
async list() {
|
|
321
|
-
return this.requester.request("/keys");
|
|
322
|
-
}
|
|
323
|
-
async create(name) {
|
|
324
|
-
return this.requester.request("/keys", {
|
|
325
|
-
method: "POST",
|
|
326
|
-
body: { name }
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
async revoke(keyId) {
|
|
330
|
-
return this.requester.request(`/keys/${keyId}`, {
|
|
331
|
-
method: "DELETE"
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
// src/client.ts
|
|
337
|
-
var ValtaClient = class {
|
|
338
|
-
constructor(config) {
|
|
339
|
-
const apiKey = typeof config === "string" ? config : config.apiKey;
|
|
340
|
-
const baseUrl = typeof config === "object" ? config.baseUrl : void 0;
|
|
341
|
-
const requester = new Requester(apiKey, baseUrl);
|
|
342
|
-
this.agents = new AgentsResource(requester);
|
|
343
|
-
this.wallets = new WalletsResource(requester);
|
|
344
|
-
this.policies = new PoliciesResource(requester);
|
|
345
|
-
this.audit = new AuditResource(requester);
|
|
346
|
-
this.keys = new KeysResource(requester);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
// src/cli/commands/agents.ts
|
|
351
|
-
function getClient() {
|
|
352
|
-
const apiKey = getApiKey();
|
|
353
|
-
if (!apiKey) {
|
|
354
|
-
console.error("\n \u2716 Not logged in. Run: valta login\n");
|
|
355
|
-
process.exit(1);
|
|
356
|
-
}
|
|
357
|
-
return new ValtaClient(apiKey);
|
|
358
|
-
}
|
|
359
|
-
async function agentsListCommand() {
|
|
360
|
-
const client = getClient();
|
|
361
|
-
try {
|
|
362
|
-
const result = await client.agents.list();
|
|
363
|
-
const agents = result.agents;
|
|
364
|
-
if (!agents.length) {
|
|
365
|
-
console.log("\n No agents found. Create one at https://valta.co/dashboard\n");
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
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");
|
|
370
|
-
for (const agent of agents) {
|
|
371
|
-
const id = (agent.id || "").padEnd(24);
|
|
372
|
-
const name = (agent.name || "").padEnd(23);
|
|
373
|
-
const status = agent.status || "";
|
|
374
|
-
console.log(` ${id} ${name} ${status}`);
|
|
375
|
-
}
|
|
376
|
-
console.log();
|
|
377
|
-
} catch (err) {
|
|
378
|
-
console.error(`
|
|
379
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
380
|
-
`);
|
|
381
|
-
process.exit(1);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
async function agentsFreezeCommand(agentId) {
|
|
385
|
-
const client = getClient();
|
|
386
|
-
try {
|
|
387
|
-
await client.agents.freeze(agentId);
|
|
388
|
-
console.log(`
|
|
389
|
-
\u2714 Agent ${agentId} frozen.
|
|
390
|
-
`);
|
|
391
|
-
} catch (err) {
|
|
392
|
-
console.error(`
|
|
393
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
394
|
-
`);
|
|
395
|
-
process.exit(1);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
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
|
-
|
|
465
|
-
// src/cli/index.ts
|
|
466
|
-
var [, , command, sub, ...args] = process.argv;
|
|
467
|
-
async function main() {
|
|
468
|
-
switch (command) {
|
|
469
|
-
case "login":
|
|
470
|
-
await loginCommand();
|
|
471
|
-
break;
|
|
472
|
-
case "logout":
|
|
473
|
-
clearConfig();
|
|
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
|
-
}
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
case "agents":
|
|
488
|
-
if (!sub || sub === "list") {
|
|
489
|
-
await agentsListCommand();
|
|
490
|
-
} else if (sub === "freeze" && args[0]) {
|
|
491
|
-
await agentsFreezeCommand(args[0]);
|
|
492
|
-
} else {
|
|
493
|
-
console.log("\n Usage:");
|
|
494
|
-
console.log(" valta agents list");
|
|
495
|
-
console.log(" valta agents freeze [id]\n");
|
|
496
|
-
}
|
|
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;
|
|
512
|
-
default:
|
|
513
|
-
console.log(`
|
|
514
|
-
Valta CLI
|
|
515
|
-
|
|
516
|
-
Commands:
|
|
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
|
|
527
|
-
`);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
main().catch((err) => {
|
|
531
|
-
console.error("\n \u2716 Unexpected error:", err.message, "\n");
|
|
532
|
-
process.exit(1);
|
|
533
|
-
});
|
package/dist/cli/index.d.cts
DELETED
package/dist/cli/index.d.mts
DELETED
package/dist/cli/index.d.ts
DELETED
package/dist/cli/index.mjs
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ValtaClient
|
|
3
|
-
} from "../chunk-HGO47A3L.mjs";
|
|
4
|
-
|
|
5
|
-
// src/cli/commands/login.ts
|
|
6
|
-
import { createInterface } from "readline";
|
|
7
|
-
|
|
8
|
-
// src/cli/config.ts
|
|
9
|
-
import { homedir } from "os";
|
|
10
|
-
import { join } from "path";
|
|
11
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
12
|
-
var CONFIG_DIR = join(homedir(), ".valta");
|
|
13
|
-
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
14
|
-
function saveConfig(config) {
|
|
15
|
-
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
16
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
17
|
-
}
|
|
18
|
-
function loadConfig() {
|
|
19
|
-
if (!existsSync(CONFIG_FILE)) return null;
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
|
|
22
|
-
} catch {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function clearConfig() {
|
|
27
|
-
if (existsSync(CONFIG_FILE)) writeFileSync(CONFIG_FILE, "{}");
|
|
28
|
-
}
|
|
29
|
-
function getApiKey() {
|
|
30
|
-
return loadConfig()?.apiKey ?? null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/cli/commands/login.ts
|
|
34
|
-
function prompt(question) {
|
|
35
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
36
|
-
return new Promise((resolve) => {
|
|
37
|
-
rl.question(question, (answer) => {
|
|
38
|
-
rl.close();
|
|
39
|
-
resolve(answer.trim());
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async function loginCommand() {
|
|
44
|
-
console.log("\n Valta Login\n");
|
|
45
|
-
const apiKey = await prompt(" API Key: ");
|
|
46
|
-
if (!apiKey || !apiKey.startsWith("vk_")) {
|
|
47
|
-
console.error("\n \u2716 Invalid API key. Keys start with vk_\n");
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
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
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/cli/commands/agents.ts
|
|
56
|
-
function getClient() {
|
|
57
|
-
const apiKey = getApiKey();
|
|
58
|
-
if (!apiKey) {
|
|
59
|
-
console.error("\n \u2716 Not logged in. Run: valta login\n");
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
return new ValtaClient(apiKey);
|
|
63
|
-
}
|
|
64
|
-
async function agentsListCommand() {
|
|
65
|
-
const client = getClient();
|
|
66
|
-
try {
|
|
67
|
-
const result = await client.agents.list();
|
|
68
|
-
const agents = result.agents;
|
|
69
|
-
if (agents.length === 0) {
|
|
70
|
-
console.log("\n No agents found. Create one at https://valta.co/dashboard\n");
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
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");
|
|
75
|
-
for (const agent of agents) {
|
|
76
|
-
const id = agent.id.padEnd(16);
|
|
77
|
-
const name = agent.name.padEnd(23);
|
|
78
|
-
const status = agent.status;
|
|
79
|
-
console.log(` ${id} ${name} ${status}`);
|
|
80
|
-
}
|
|
81
|
-
console.log();
|
|
82
|
-
} catch (err) {
|
|
83
|
-
console.error(`
|
|
84
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
85
|
-
`);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async function agentsFreezeCommand(agentId) {
|
|
90
|
-
const client = getClient();
|
|
91
|
-
try {
|
|
92
|
-
await client.agents.freeze(agentId);
|
|
93
|
-
console.log(`
|
|
94
|
-
\u2714 Agent ${agentId} frozen.
|
|
95
|
-
`);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
console.error(`
|
|
98
|
-
\u2716 ${err instanceof Error ? err.message : "Unknown error"}
|
|
99
|
-
`);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/cli/index.ts
|
|
105
|
-
var [, , command, sub, ...args] = process.argv;
|
|
106
|
-
async function main() {
|
|
107
|
-
switch (command) {
|
|
108
|
-
case "login":
|
|
109
|
-
await loginCommand();
|
|
110
|
-
break;
|
|
111
|
-
case "logout":
|
|
112
|
-
clearConfig();
|
|
113
|
-
console.log("\n \u2714 Logged out. Config cleared.\n");
|
|
114
|
-
break;
|
|
115
|
-
case "agents":
|
|
116
|
-
if (sub === "list" || !sub) {
|
|
117
|
-
await agentsListCommand();
|
|
118
|
-
} else if (sub === "freeze" && args[0]) {
|
|
119
|
-
await agentsFreezeCommand(args[0]);
|
|
120
|
-
} else {
|
|
121
|
-
console.log("\n Usage:");
|
|
122
|
-
console.log(" valta agents list");
|
|
123
|
-
console.log(" valta agents freeze [id]\n");
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
console.log(`
|
|
128
|
-
Valta CLI
|
|
129
|
-
|
|
130
|
-
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
|
|
135
|
-
`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
main().catch((err) => {
|
|
139
|
-
console.error("\n \u2716 Unexpected error:", err.message, "\n");
|
|
140
|
-
process.exit(1);
|
|
141
|
-
});
|