valta-sdk 2.0.1 → 2.1.0
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/bin/valta.js +9 -154
- package/dist/chunk-HGO47A3L.mjs +244 -0
- package/dist/chunk-LPBJPXJO.js +244 -0
- package/dist/cli/index.cjs +375 -0
- package/dist/cli/index.d.cts +2 -0
- package/dist/cli/index.d.mts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +141 -0
- package/dist/cli/index.mjs +141 -0
- package/dist/index.cjs +276 -0
- package/dist/index.d.cts +197 -0
- package/dist/index.d.mts +161 -131
- package/dist/index.d.ts +161 -131
- package/dist/index.js +15 -353
- package/dist/index.mjs +12 -314
- package/package.json +34 -49
package/bin/valta.js
CHANGED
|
@@ -1,159 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { homedir } from "os";
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
6
8
|
|
|
7
|
-
const
|
|
8
|
-
const VERSION = "2.0.0";
|
|
9
|
+
const cliPath = join(__dirname, '..', 'dist', 'cli', 'index.mjs');
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
try { return JSON.parse(readFileSync(CONFIG_FILE, "utf8")); } catch { return {}; }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function saveConfig(data) {
|
|
16
|
-
const dir = join(homedir(), ".valta");
|
|
17
|
-
if (!existsSync(dir)) {
|
|
18
|
-
const { mkdirSync } = await import("fs");
|
|
19
|
-
mkdirSync(dir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(data, null, 2));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const args = process.argv.slice(2);
|
|
25
|
-
const command = args[0];
|
|
26
|
-
|
|
27
|
-
const help = `
|
|
28
|
-
Valta CLI v${VERSION}
|
|
29
|
-
|
|
30
|
-
COMMANDS
|
|
31
|
-
valta init Initialize a new Valta project
|
|
32
|
-
valta login Save your API key
|
|
33
|
-
valta create-agent Generate an agent starter file
|
|
34
|
-
valta run Run a quick agent query
|
|
35
|
-
valta --version Show CLI version
|
|
36
|
-
valta help Show this help
|
|
37
|
-
|
|
38
|
-
EXAMPLES
|
|
39
|
-
valta login
|
|
40
|
-
valta create-agent trading
|
|
41
|
-
valta run "What is BTC doing today?" --agent trading_signal
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
async function main() {
|
|
45
|
-
switch (command) {
|
|
46
|
-
case "init": {
|
|
47
|
-
const template = `// Valta project starter
|
|
48
|
-
// https://valta.co/docs
|
|
49
|
-
|
|
50
|
-
import { ValtaClient } from "valta-sdk";
|
|
51
|
-
|
|
52
|
-
const valta = new ValtaClient({
|
|
53
|
-
apiKey: process.env.VALTA_API_KEY,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// List available agents
|
|
57
|
-
const agents = await valta.listAgents();
|
|
58
|
-
console.log("Available agents:", agents.map(a => a.name));
|
|
59
|
-
|
|
60
|
-
// Chat with the Trading Signal agent
|
|
61
|
-
const agent = valta.createAgent("trading_signal");
|
|
62
|
-
const response = await agent.chat("What is BTC doing today?");
|
|
63
|
-
console.log(response.message);
|
|
64
|
-
`;
|
|
65
|
-
writeFileSync("valta-starter.js", template);
|
|
66
|
-
console.log("✓ Created valta-starter.js");
|
|
67
|
-
console.log(" Run: node valta-starter.js");
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
case "login": {
|
|
72
|
-
const { createInterface } = await import("readline");
|
|
73
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
74
|
-
rl.question("Enter your Valta API key (from /dashboard/api-keys): ", (key) => {
|
|
75
|
-
rl.close();
|
|
76
|
-
const trimmed = key.trim();
|
|
77
|
-
if (!trimmed) { console.error("✗ No API key provided"); process.exit(1); }
|
|
78
|
-
const cfg = loadConfig();
|
|
79
|
-
cfg.apiKey = trimmed;
|
|
80
|
-
try { saveConfig(cfg); } catch {
|
|
81
|
-
const { mkdirSync } = require("fs");
|
|
82
|
-
mkdirSync(join(homedir(), ".valta"), { recursive: true });
|
|
83
|
-
saveConfig(cfg);
|
|
84
|
-
}
|
|
85
|
-
console.log(`✓ API key saved to ${CONFIG_FILE}`);
|
|
86
|
-
console.log(" You can now import it as: VALTA_API_KEY from your environment.");
|
|
87
|
-
});
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
case "create-agent": {
|
|
92
|
-
const type = args[1] || "general";
|
|
93
|
-
const fileName = `${type}Agent.js`;
|
|
94
|
-
const agentTemplate = `// ${type.charAt(0).toUpperCase() + type.slice(1)} Agent — Valta SDK
|
|
95
|
-
import { ValtaClient } from "valta-sdk";
|
|
96
|
-
|
|
97
|
-
const valta = new ValtaClient({ apiKey: process.env.VALTA_API_KEY });
|
|
98
|
-
const agent = valta.createAgent("${type}_agent");
|
|
99
|
-
|
|
100
|
-
const response = await agent.chat("Your question here");
|
|
101
|
-
console.log(response.message);
|
|
102
|
-
`;
|
|
103
|
-
writeFileSync(fileName, agentTemplate);
|
|
104
|
-
console.log(`✓ Created ${fileName}`);
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
case "run": {
|
|
109
|
-
const message = args[1];
|
|
110
|
-
const agentFlag = args.indexOf("--agent");
|
|
111
|
-
const agentId = agentFlag !== -1 ? args[agentFlag + 1] : "financial_advisor";
|
|
112
|
-
|
|
113
|
-
if (!message) {
|
|
114
|
-
console.error("Usage: valta run \"your question\" --agent <agent_id>");
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const cfg = loadConfig();
|
|
119
|
-
const apiKey = cfg.apiKey || process.env.VALTA_API_KEY;
|
|
120
|
-
if (!apiKey) {
|
|
121
|
-
console.error("✗ No API key. Run: valta login");
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
console.log(`Running ${agentId}...`);
|
|
126
|
-
const res = await fetch(`https://valta.co/api/bot/${encodeURIComponent(agentId)}/chat`, {
|
|
127
|
-
method: "POST",
|
|
128
|
-
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiKey}` },
|
|
129
|
-
body: JSON.stringify({ message }),
|
|
130
|
-
});
|
|
131
|
-
const data = await res.json();
|
|
132
|
-
if (!res.ok) { console.error("✗", data.error || "Request failed"); process.exit(1); }
|
|
133
|
-
console.log("\n" + (data.message || data.response || JSON.stringify(data)));
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
case "--version":
|
|
138
|
-
case "-v":
|
|
139
|
-
console.log(`valta-sdk v${VERSION}`);
|
|
140
|
-
break;
|
|
141
|
-
|
|
142
|
-
case "help":
|
|
143
|
-
case "--help":
|
|
144
|
-
case "-h":
|
|
145
|
-
case undefined:
|
|
146
|
-
console.log(help);
|
|
147
|
-
break;
|
|
148
|
-
|
|
149
|
-
default:
|
|
150
|
-
console.error(`Unknown command: ${command}`);
|
|
151
|
-
console.log(help);
|
|
152
|
-
process.exit(1);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
main().catch((err) => {
|
|
157
|
-
console.error("✗", err.message);
|
|
11
|
+
import(pathToFileURL(cliPath).href).catch((err) => {
|
|
12
|
+
console.error('Valta CLI failed to start:', err.message);
|
|
158
13
|
process.exit(1);
|
|
159
|
-
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// src/errors/index.ts
|
|
2
|
+
var ValtaError = class extends Error {
|
|
3
|
+
constructor(message, code, status) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "ValtaError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.status = status;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var AuthError = class extends ValtaError {
|
|
11
|
+
constructor(message = "Invalid or missing API key") {
|
|
12
|
+
super(message, "UNAUTHORIZED", 401);
|
|
13
|
+
this.name = "AuthError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var TierError = class extends ValtaError {
|
|
17
|
+
constructor(message, requiredTier) {
|
|
18
|
+
super(message, "TIER_LIMIT", 403);
|
|
19
|
+
this.name = "TierError";
|
|
20
|
+
this.requiredTier = requiredTier;
|
|
21
|
+
this.upgradeUrl = "https://valta.co/upgrade";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var RateLimitError = class extends ValtaError {
|
|
25
|
+
constructor(message = "Rate limit exceeded. Slow down your requests.") {
|
|
26
|
+
super(message, "RATE_LIMIT", 429);
|
|
27
|
+
this.name = "RateLimitError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var NotFoundError = class extends ValtaError {
|
|
31
|
+
constructor(resource) {
|
|
32
|
+
super(`${resource} not found`, "NOT_FOUND", 404);
|
|
33
|
+
this.name = "NotFoundError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/http/requester.ts
|
|
38
|
+
var DEFAULT_BASE_URL = "https://valta.co/api/v1";
|
|
39
|
+
var Requester = class {
|
|
40
|
+
constructor(apiKey, baseUrl) {
|
|
41
|
+
if (!apiKey || typeof apiKey !== "string") {
|
|
42
|
+
throw new AuthError("An API key is required. Get one at https://valta.co/dashboard/api-keys");
|
|
43
|
+
}
|
|
44
|
+
this.apiKey = apiKey;
|
|
45
|
+
this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;
|
|
46
|
+
}
|
|
47
|
+
async request(path, options = {}) {
|
|
48
|
+
const { method = "GET", body } = options;
|
|
49
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
50
|
+
method,
|
|
51
|
+
headers: {
|
|
52
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"X-Valta-SDK": "0.2.0"
|
|
55
|
+
},
|
|
56
|
+
body: body ? JSON.stringify(body) : void 0
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
let errorData = {};
|
|
60
|
+
try {
|
|
61
|
+
errorData = await res.json();
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
const message = errorData.message ?? "An unknown error occurred";
|
|
65
|
+
switch (res.status) {
|
|
66
|
+
case 401:
|
|
67
|
+
throw new AuthError(message);
|
|
68
|
+
case 403:
|
|
69
|
+
throw new TierError(message, errorData.requiredTier ?? "builder");
|
|
70
|
+
case 404:
|
|
71
|
+
throw new NotFoundError(path);
|
|
72
|
+
case 429:
|
|
73
|
+
throw new RateLimitError(message);
|
|
74
|
+
default:
|
|
75
|
+
throw new ValtaError(message, "SERVER_ERROR", res.status);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return res.json();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/resources/agents.ts
|
|
83
|
+
var AgentsResource = class {
|
|
84
|
+
constructor(requester) {
|
|
85
|
+
this.requester = requester;
|
|
86
|
+
}
|
|
87
|
+
// Get all agents
|
|
88
|
+
async list(params = {}) {
|
|
89
|
+
const query = new URLSearchParams();
|
|
90
|
+
if (params.limit) query.set("limit", String(params.limit));
|
|
91
|
+
if (params.offset) query.set("offset", String(params.offset));
|
|
92
|
+
if (params.status) query.set("status", params.status);
|
|
93
|
+
const qs = query.toString();
|
|
94
|
+
return this.requester.request(
|
|
95
|
+
`/agents${qs ? `?${qs}` : ""}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
// Get one agent by ID
|
|
99
|
+
async get(agentId) {
|
|
100
|
+
return this.requester.request(`/agents/${agentId}`);
|
|
101
|
+
}
|
|
102
|
+
// Create a new agent
|
|
103
|
+
async create(params) {
|
|
104
|
+
return this.requester.request("/agents", {
|
|
105
|
+
method: "POST",
|
|
106
|
+
body: params
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Update an agent
|
|
110
|
+
async update(agentId, params) {
|
|
111
|
+
return this.requester.request(`/agents/${agentId}`, {
|
|
112
|
+
method: "PATCH",
|
|
113
|
+
body: params
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// Freeze an agent (stops it from spending)
|
|
117
|
+
async freeze(agentId) {
|
|
118
|
+
return this.requester.request(`/agents/${agentId}/freeze`, {
|
|
119
|
+
method: "POST"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Unfreeze an agent
|
|
123
|
+
async unfreeze(agentId) {
|
|
124
|
+
return this.requester.request(`/agents/${agentId}/unfreeze`, {
|
|
125
|
+
method: "POST"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Delete an agent
|
|
129
|
+
async delete(agentId) {
|
|
130
|
+
return this.requester.request(
|
|
131
|
+
`/agents/${agentId}`,
|
|
132
|
+
{ method: "DELETE" }
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/resources/wallets.ts
|
|
138
|
+
var WalletsResource = class {
|
|
139
|
+
constructor(requester) {
|
|
140
|
+
this.requester = requester;
|
|
141
|
+
}
|
|
142
|
+
// Get wallet balance for an agent
|
|
143
|
+
async get(agentId) {
|
|
144
|
+
return this.requester.request(
|
|
145
|
+
`/agents/${agentId}/wallet`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
// Transfer funds from one agent wallet to another
|
|
149
|
+
async transfer(agentId, params) {
|
|
150
|
+
return this.requester.request(
|
|
151
|
+
`/agents/${agentId}/wallet/transfer`,
|
|
152
|
+
{ method: "POST", body: params }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/resources/policies.ts
|
|
158
|
+
var PoliciesResource = class {
|
|
159
|
+
constructor(requester) {
|
|
160
|
+
this.requester = requester;
|
|
161
|
+
}
|
|
162
|
+
async list(agentId) {
|
|
163
|
+
const qs = agentId ? `?agentId=${agentId}` : "";
|
|
164
|
+
return this.requester.request(`/policies${qs}`);
|
|
165
|
+
}
|
|
166
|
+
async create(params) {
|
|
167
|
+
return this.requester.request("/policies", {
|
|
168
|
+
method: "POST",
|
|
169
|
+
body: params
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async update(policyId, params) {
|
|
173
|
+
return this.requester.request(`/policies/${policyId}`, {
|
|
174
|
+
method: "PATCH",
|
|
175
|
+
body: params
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async delete(policyId) {
|
|
179
|
+
return this.requester.request(`/policies/${policyId}`, {
|
|
180
|
+
method: "DELETE"
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/resources/audit.ts
|
|
186
|
+
var AuditResource = class {
|
|
187
|
+
constructor(requester) {
|
|
188
|
+
this.requester = requester;
|
|
189
|
+
}
|
|
190
|
+
async list(params = {}) {
|
|
191
|
+
const query = new URLSearchParams();
|
|
192
|
+
if (params.agentId) query.set("agentId", params.agentId);
|
|
193
|
+
if (params.limit) query.set("limit", String(params.limit));
|
|
194
|
+
if (params.offset) query.set("offset", String(params.offset));
|
|
195
|
+
if (params.from) query.set("from", params.from);
|
|
196
|
+
if (params.to) query.set("to", params.to);
|
|
197
|
+
const qs = query.toString();
|
|
198
|
+
return this.requester.request(`/audit${qs ? `?${qs}` : ""}`);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/resources/keys.ts
|
|
203
|
+
var KeysResource = class {
|
|
204
|
+
constructor(requester) {
|
|
205
|
+
this.requester = requester;
|
|
206
|
+
}
|
|
207
|
+
async list() {
|
|
208
|
+
return this.requester.request("/keys");
|
|
209
|
+
}
|
|
210
|
+
async create(name) {
|
|
211
|
+
return this.requester.request("/keys", {
|
|
212
|
+
method: "POST",
|
|
213
|
+
body: { name }
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async revoke(keyId) {
|
|
217
|
+
return this.requester.request(`/keys/${keyId}`, {
|
|
218
|
+
method: "DELETE"
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/client.ts
|
|
224
|
+
var ValtaClient = class {
|
|
225
|
+
constructor(config) {
|
|
226
|
+
const apiKey = typeof config === "string" ? config : config.apiKey;
|
|
227
|
+
const baseUrl = typeof config === "object" ? config.baseUrl : void 0;
|
|
228
|
+
const requester = new Requester(apiKey, baseUrl);
|
|
229
|
+
this.agents = new AgentsResource(requester);
|
|
230
|
+
this.wallets = new WalletsResource(requester);
|
|
231
|
+
this.policies = new PoliciesResource(requester);
|
|
232
|
+
this.audit = new AuditResource(requester);
|
|
233
|
+
this.keys = new KeysResource(requester);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
ValtaError,
|
|
239
|
+
AuthError,
|
|
240
|
+
TierError,
|
|
241
|
+
RateLimitError,
|
|
242
|
+
NotFoundError,
|
|
243
|
+
ValtaClient
|
|
244
|
+
};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// src/errors/index.ts
|
|
2
|
+
var ValtaError = class extends Error {
|
|
3
|
+
constructor(message, code, status) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "ValtaError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.status = status;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var AuthError = class extends ValtaError {
|
|
11
|
+
constructor(message = "Invalid or missing API key") {
|
|
12
|
+
super(message, "UNAUTHORIZED", 401);
|
|
13
|
+
this.name = "AuthError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var TierError = class extends ValtaError {
|
|
17
|
+
constructor(message, requiredTier) {
|
|
18
|
+
super(message, "TIER_LIMIT", 403);
|
|
19
|
+
this.name = "TierError";
|
|
20
|
+
this.requiredTier = requiredTier;
|
|
21
|
+
this.upgradeUrl = "https://valta.co/upgrade";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var RateLimitError = class extends ValtaError {
|
|
25
|
+
constructor(message = "Rate limit exceeded. Slow down your requests.") {
|
|
26
|
+
super(message, "RATE_LIMIT", 429);
|
|
27
|
+
this.name = "RateLimitError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var NotFoundError = class extends ValtaError {
|
|
31
|
+
constructor(resource) {
|
|
32
|
+
super(`${resource} not found`, "NOT_FOUND", 404);
|
|
33
|
+
this.name = "NotFoundError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/http/requester.ts
|
|
38
|
+
var DEFAULT_BASE_URL = "https://valta.co/api/v1";
|
|
39
|
+
var Requester = class {
|
|
40
|
+
constructor(apiKey, baseUrl) {
|
|
41
|
+
if (!apiKey || typeof apiKey !== "string") {
|
|
42
|
+
throw new AuthError("An API key is required. Get one at https://valta.co/dashboard/api-keys");
|
|
43
|
+
}
|
|
44
|
+
this.apiKey = apiKey;
|
|
45
|
+
this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;
|
|
46
|
+
}
|
|
47
|
+
async request(path, options = {}) {
|
|
48
|
+
const { method = "GET", body } = options;
|
|
49
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
50
|
+
method,
|
|
51
|
+
headers: {
|
|
52
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"X-Valta-SDK": "0.2.0"
|
|
55
|
+
},
|
|
56
|
+
body: body ? JSON.stringify(body) : void 0
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
let errorData = {};
|
|
60
|
+
try {
|
|
61
|
+
errorData = await res.json();
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
const message = errorData.message ?? "An unknown error occurred";
|
|
65
|
+
switch (res.status) {
|
|
66
|
+
case 401:
|
|
67
|
+
throw new AuthError(message);
|
|
68
|
+
case 403:
|
|
69
|
+
throw new TierError(message, errorData.requiredTier ?? "builder");
|
|
70
|
+
case 404:
|
|
71
|
+
throw new NotFoundError(path);
|
|
72
|
+
case 429:
|
|
73
|
+
throw new RateLimitError(message);
|
|
74
|
+
default:
|
|
75
|
+
throw new ValtaError(message, "SERVER_ERROR", res.status);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return res.json();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/resources/agents.ts
|
|
83
|
+
var AgentsResource = class {
|
|
84
|
+
constructor(requester) {
|
|
85
|
+
this.requester = requester;
|
|
86
|
+
}
|
|
87
|
+
// Get all agents
|
|
88
|
+
async list(params = {}) {
|
|
89
|
+
const query = new URLSearchParams();
|
|
90
|
+
if (params.limit) query.set("limit", String(params.limit));
|
|
91
|
+
if (params.offset) query.set("offset", String(params.offset));
|
|
92
|
+
if (params.status) query.set("status", params.status);
|
|
93
|
+
const qs = query.toString();
|
|
94
|
+
return this.requester.request(
|
|
95
|
+
`/agents${qs ? `?${qs}` : ""}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
// Get one agent by ID
|
|
99
|
+
async get(agentId) {
|
|
100
|
+
return this.requester.request(`/agents/${agentId}`);
|
|
101
|
+
}
|
|
102
|
+
// Create a new agent
|
|
103
|
+
async create(params) {
|
|
104
|
+
return this.requester.request("/agents", {
|
|
105
|
+
method: "POST",
|
|
106
|
+
body: params
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Update an agent
|
|
110
|
+
async update(agentId, params) {
|
|
111
|
+
return this.requester.request(`/agents/${agentId}`, {
|
|
112
|
+
method: "PATCH",
|
|
113
|
+
body: params
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// Freeze an agent (stops it from spending)
|
|
117
|
+
async freeze(agentId) {
|
|
118
|
+
return this.requester.request(`/agents/${agentId}/freeze`, {
|
|
119
|
+
method: "POST"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Unfreeze an agent
|
|
123
|
+
async unfreeze(agentId) {
|
|
124
|
+
return this.requester.request(`/agents/${agentId}/unfreeze`, {
|
|
125
|
+
method: "POST"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Delete an agent
|
|
129
|
+
async delete(agentId) {
|
|
130
|
+
return this.requester.request(
|
|
131
|
+
`/agents/${agentId}`,
|
|
132
|
+
{ method: "DELETE" }
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/resources/wallets.ts
|
|
138
|
+
var WalletsResource = class {
|
|
139
|
+
constructor(requester) {
|
|
140
|
+
this.requester = requester;
|
|
141
|
+
}
|
|
142
|
+
// Get wallet balance for an agent
|
|
143
|
+
async get(agentId) {
|
|
144
|
+
return this.requester.request(
|
|
145
|
+
`/agents/${agentId}/wallet`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
// Transfer funds from one agent wallet to another
|
|
149
|
+
async transfer(agentId, params) {
|
|
150
|
+
return this.requester.request(
|
|
151
|
+
`/agents/${agentId}/wallet/transfer`,
|
|
152
|
+
{ method: "POST", body: params }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/resources/policies.ts
|
|
158
|
+
var PoliciesResource = class {
|
|
159
|
+
constructor(requester) {
|
|
160
|
+
this.requester = requester;
|
|
161
|
+
}
|
|
162
|
+
async list(agentId) {
|
|
163
|
+
const qs = agentId ? `?agentId=${agentId}` : "";
|
|
164
|
+
return this.requester.request(`/policies${qs}`);
|
|
165
|
+
}
|
|
166
|
+
async create(params) {
|
|
167
|
+
return this.requester.request("/policies", {
|
|
168
|
+
method: "POST",
|
|
169
|
+
body: params
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async update(policyId, params) {
|
|
173
|
+
return this.requester.request(`/policies/${policyId}`, {
|
|
174
|
+
method: "PATCH",
|
|
175
|
+
body: params
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async delete(policyId) {
|
|
179
|
+
return this.requester.request(`/policies/${policyId}`, {
|
|
180
|
+
method: "DELETE"
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/resources/audit.ts
|
|
186
|
+
var AuditResource = class {
|
|
187
|
+
constructor(requester) {
|
|
188
|
+
this.requester = requester;
|
|
189
|
+
}
|
|
190
|
+
async list(params = {}) {
|
|
191
|
+
const query = new URLSearchParams();
|
|
192
|
+
if (params.agentId) query.set("agentId", params.agentId);
|
|
193
|
+
if (params.limit) query.set("limit", String(params.limit));
|
|
194
|
+
if (params.offset) query.set("offset", String(params.offset));
|
|
195
|
+
if (params.from) query.set("from", params.from);
|
|
196
|
+
if (params.to) query.set("to", params.to);
|
|
197
|
+
const qs = query.toString();
|
|
198
|
+
return this.requester.request(`/audit${qs ? `?${qs}` : ""}`);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// src/resources/keys.ts
|
|
203
|
+
var KeysResource = class {
|
|
204
|
+
constructor(requester) {
|
|
205
|
+
this.requester = requester;
|
|
206
|
+
}
|
|
207
|
+
async list() {
|
|
208
|
+
return this.requester.request("/keys");
|
|
209
|
+
}
|
|
210
|
+
async create(name) {
|
|
211
|
+
return this.requester.request("/keys", {
|
|
212
|
+
method: "POST",
|
|
213
|
+
body: { name }
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async revoke(keyId) {
|
|
217
|
+
return this.requester.request(`/keys/${keyId}`, {
|
|
218
|
+
method: "DELETE"
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/client.ts
|
|
224
|
+
var ValtaClient = class {
|
|
225
|
+
constructor(config) {
|
|
226
|
+
const apiKey = typeof config === "string" ? config : config.apiKey;
|
|
227
|
+
const baseUrl = typeof config === "object" ? config.baseUrl : void 0;
|
|
228
|
+
const requester = new Requester(apiKey, baseUrl);
|
|
229
|
+
this.agents = new AgentsResource(requester);
|
|
230
|
+
this.wallets = new WalletsResource(requester);
|
|
231
|
+
this.policies = new PoliciesResource(requester);
|
|
232
|
+
this.audit = new AuditResource(requester);
|
|
233
|
+
this.keys = new KeysResource(requester);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
ValtaError,
|
|
239
|
+
AuthError,
|
|
240
|
+
TierError,
|
|
241
|
+
RateLimitError,
|
|
242
|
+
NotFoundError,
|
|
243
|
+
ValtaClient
|
|
244
|
+
};
|