valta-sdk 2.0.1 → 2.1.1
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 +176 -98
- 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/dist/index.js
CHANGED
|
@@ -1,355 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
AgentHandle: () => AgentHandle,
|
|
24
|
-
AnalyticsTool: () => AnalyticsTool,
|
|
25
|
-
PortfolioAgent: () => PortfolioAgent,
|
|
26
|
-
TradingAgent: () => TradingAgent,
|
|
27
|
-
ValtaAuthError: () => ValtaAuthError,
|
|
28
|
-
ValtaClient: () => ValtaClient,
|
|
29
|
-
ValtaError: () => ValtaError,
|
|
30
|
-
ValtaRateLimitError: () => ValtaRateLimitError,
|
|
31
|
-
ValtaUpgradeError: () => ValtaUpgradeError,
|
|
32
|
-
WalletTool: () => WalletTool,
|
|
33
|
-
default: () => ValtaClient
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
|
|
37
|
-
// src/core/config.ts
|
|
38
|
-
var DEFAULT_BASE_URL = "https://valta.co";
|
|
39
|
-
function validateConfig(config) {
|
|
40
|
-
if (!config.apiKey || typeof config.apiKey !== "string") {
|
|
41
|
-
throw new Error("ValtaClient: apiKey is required. Get yours at https://valta.co/dashboard/api-keys");
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
apiKey: config.apiKey.trim(),
|
|
45
|
-
baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, ""),
|
|
46
|
-
timeout: config.timeout || 3e4
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/utils/errors.ts
|
|
51
|
-
var ValtaError = class extends Error {
|
|
52
|
-
constructor(message, status = 500, code) {
|
|
53
|
-
super(message);
|
|
54
|
-
this.name = "ValtaError";
|
|
55
|
-
this.status = status;
|
|
56
|
-
this.code = code;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
var ValtaAuthError = class extends ValtaError {
|
|
60
|
-
constructor(message = "Invalid or missing API key") {
|
|
61
|
-
super(message, 401, "AUTH_ERROR");
|
|
62
|
-
this.name = "ValtaAuthError";
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var ValtaRateLimitError = class extends ValtaError {
|
|
66
|
-
constructor(message = "Rate limit exceeded", retryAfter) {
|
|
67
|
-
super(message, 429, "RATE_LIMIT");
|
|
68
|
-
this.name = "ValtaRateLimitError";
|
|
69
|
-
this.retryAfter = retryAfter;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var ValtaUpgradeError = class extends ValtaError {
|
|
73
|
-
constructor(message = "Upgrade your plan to access this feature") {
|
|
74
|
-
super(message, 403, "UPGRADE_REQUIRED");
|
|
75
|
-
this.name = "ValtaUpgradeError";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// src/utils/http.ts
|
|
80
|
-
async function request(apiKey, baseUrl, method, path, body) {
|
|
81
|
-
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
82
|
-
const res = await fetch(url, {
|
|
83
|
-
method,
|
|
84
|
-
headers: {
|
|
85
|
-
"Content-Type": "application/json",
|
|
86
|
-
"Authorization": `Bearer ${apiKey}`,
|
|
87
|
-
"X-Valta-SDK": "1.0.0"
|
|
88
|
-
},
|
|
89
|
-
body: body ? JSON.stringify(body) : void 0
|
|
90
|
-
});
|
|
91
|
-
if (!res.ok) {
|
|
92
|
-
let parsed;
|
|
93
|
-
try {
|
|
94
|
-
parsed = await res.json();
|
|
95
|
-
} catch {
|
|
96
|
-
parsed = {};
|
|
97
|
-
}
|
|
98
|
-
const message = parsed?.error || parsed?.message || `HTTP ${res.status}`;
|
|
99
|
-
const code = parsed?.code;
|
|
100
|
-
if (res.status === 401) throw new ValtaAuthError(message);
|
|
101
|
-
if (res.status === 403) throw new ValtaUpgradeError(message);
|
|
102
|
-
if (res.status === 429) {
|
|
103
|
-
const retryAfter = Number(res.headers.get("retry-after")) || void 0;
|
|
104
|
-
throw new ValtaRateLimitError(message, retryAfter);
|
|
105
|
-
}
|
|
106
|
-
throw new ValtaError(message, res.status, code);
|
|
107
|
-
}
|
|
108
|
-
return res.json();
|
|
109
|
-
}
|
|
110
|
-
async function get(apiKey, baseUrl, path) {
|
|
111
|
-
return request(apiKey, baseUrl, "GET", path);
|
|
112
|
-
}
|
|
113
|
-
async function post(apiKey, baseUrl, path, body) {
|
|
114
|
-
return request(apiKey, baseUrl, "POST", path, body);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// src/tools/wallet.ts
|
|
118
|
-
var WalletTool = class {
|
|
119
|
-
constructor(apiKey, baseUrl) {
|
|
120
|
-
this.apiKey = apiKey;
|
|
121
|
-
this.baseUrl = baseUrl;
|
|
122
|
-
}
|
|
123
|
-
async getBalance() {
|
|
124
|
-
const res = await get(
|
|
125
|
-
this.apiKey,
|
|
126
|
-
this.baseUrl,
|
|
127
|
-
"/api/user/wallet/balance"
|
|
128
|
-
);
|
|
129
|
-
return { balance: res.balance || 0, currency: res.currency || "USDC" };
|
|
130
|
-
}
|
|
131
|
-
async getTransactions(limit = 20) {
|
|
132
|
-
const res = await get(
|
|
133
|
-
this.apiKey,
|
|
134
|
-
this.baseUrl,
|
|
135
|
-
`/api/user/transactions?limit=${limit}`
|
|
136
|
-
);
|
|
137
|
-
return res.transactions || res.data || [];
|
|
138
|
-
}
|
|
139
|
-
async getAddress() {
|
|
140
|
-
const res = await get(
|
|
141
|
-
this.apiKey,
|
|
142
|
-
this.baseUrl,
|
|
143
|
-
"/api/user/wallet"
|
|
144
|
-
);
|
|
145
|
-
return res.address || res.walletAddress || "";
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// src/tools/analytics.ts
|
|
150
|
-
var AnalyticsTool = class {
|
|
151
|
-
constructor(apiKey, baseUrl) {
|
|
152
|
-
this.apiKey = apiKey;
|
|
153
|
-
this.baseUrl = baseUrl;
|
|
154
|
-
}
|
|
155
|
-
async getSummary() {
|
|
156
|
-
const res = await get(
|
|
157
|
-
this.apiKey,
|
|
158
|
-
this.baseUrl,
|
|
159
|
-
"/api/user/analytics"
|
|
160
|
-
);
|
|
161
|
-
return res.summary || { totalSpend: 0, topAgents: [], spendByDay: [] };
|
|
162
|
-
}
|
|
163
|
-
async getAuditTrail(limit = 50) {
|
|
164
|
-
const res = await get(
|
|
165
|
-
this.apiKey,
|
|
166
|
-
this.baseUrl,
|
|
167
|
-
`/api/user/audit-trail?limit=${limit}`
|
|
168
|
-
);
|
|
169
|
-
return res.events || [];
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// src/agents/tradingAgent.ts
|
|
174
|
-
var TRADING_AGENT_ID = "trading_signal";
|
|
175
|
-
var TradingAgent = class {
|
|
176
|
-
constructor(apiKey, baseUrl) {
|
|
177
|
-
this.apiKey = apiKey;
|
|
178
|
-
this.baseUrl = baseUrl;
|
|
179
|
-
}
|
|
180
|
-
async analyze(question) {
|
|
181
|
-
const res = await post(
|
|
182
|
-
this.apiKey,
|
|
183
|
-
this.baseUrl,
|
|
184
|
-
`/api/bot/${TRADING_AGENT_ID}/chat`,
|
|
185
|
-
{ message: question }
|
|
186
|
-
);
|
|
187
|
-
return { message: res.message || "", agentId: TRADING_AGENT_ID, tokens: res.tokens, provider: res.provider };
|
|
188
|
-
}
|
|
189
|
-
async getMarketBrief() {
|
|
190
|
-
const res = await this.analyze(
|
|
191
|
-
"Give me a brief market analysis for BTC, ETH, and SOL. Include price action, key levels, and sentiment."
|
|
192
|
-
);
|
|
193
|
-
return res.message;
|
|
194
|
-
}
|
|
195
|
-
async getSignals(assets) {
|
|
196
|
-
const assetList = assets.join(", ").toUpperCase();
|
|
197
|
-
const res = await this.analyze(
|
|
198
|
-
`Provide buy/sell/hold signals for: ${assetList}. Include entry price, target, and stop-loss.`
|
|
199
|
-
);
|
|
200
|
-
return res.message;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// src/agents/portfolioAgent.ts
|
|
205
|
-
var PORTFOLIO_AGENT_ID = "portfolio_analyzer";
|
|
206
|
-
var PortfolioAgent = class {
|
|
207
|
-
constructor(apiKey, baseUrl) {
|
|
208
|
-
this.apiKey = apiKey;
|
|
209
|
-
this.baseUrl = baseUrl;
|
|
210
|
-
}
|
|
211
|
-
async analyze(question) {
|
|
212
|
-
const res = await post(
|
|
213
|
-
this.apiKey,
|
|
214
|
-
this.baseUrl,
|
|
215
|
-
`/api/bot/${PORTFOLIO_AGENT_ID}/chat`,
|
|
216
|
-
{ message: question }
|
|
217
|
-
);
|
|
218
|
-
return { message: res.message || "", agentId: PORTFOLIO_AGENT_ID, tokens: res.tokens, provider: res.provider };
|
|
219
|
-
}
|
|
220
|
-
async getReport() {
|
|
221
|
-
const res = await this.analyze(
|
|
222
|
-
"Generate a full portfolio health report. Include current allocation, risk score, and rebalancing suggestions."
|
|
223
|
-
);
|
|
224
|
-
return res.message;
|
|
225
|
-
}
|
|
226
|
-
async getRebalancingSuggestions(targetAllocation) {
|
|
227
|
-
const allocStr = Object.entries(targetAllocation).map(([asset, pct]) => `${asset}: ${pct}%`).join(", ");
|
|
228
|
-
const res = await this.analyze(
|
|
229
|
-
`Suggest how to rebalance my portfolio to reach this target allocation: ${allocStr}`
|
|
230
|
-
);
|
|
231
|
-
return res.message;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// src/core/client.ts
|
|
236
|
-
var ValtaClient = class {
|
|
237
|
-
constructor(config) {
|
|
238
|
-
this.plugins = [];
|
|
239
|
-
const validated = validateConfig(config);
|
|
240
|
-
this.apiKey = validated.apiKey;
|
|
241
|
-
this.baseUrl = validated.baseUrl;
|
|
242
|
-
this.wallet = new WalletTool(this.apiKey, this.baseUrl);
|
|
243
|
-
this.analytics = new AnalyticsTool(this.apiKey, this.baseUrl);
|
|
244
|
-
this.trading = new TradingAgent(this.apiKey, this.baseUrl);
|
|
245
|
-
this.portfolio = new PortfolioAgent(this.apiKey, this.baseUrl);
|
|
246
|
-
}
|
|
247
|
-
// ── Plugin system (express-style middleware) ────────────────
|
|
248
|
-
use(plugin) {
|
|
249
|
-
plugin(this);
|
|
250
|
-
this.plugins.push(plugin);
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
// ── Agents ──────────────────────────────────────────────────
|
|
254
|
-
async listAgents() {
|
|
255
|
-
const res = await get(
|
|
256
|
-
this.apiKey,
|
|
257
|
-
this.baseUrl,
|
|
258
|
-
"/api/agents"
|
|
259
|
-
);
|
|
260
|
-
return res.agents || res.capabilities || [];
|
|
261
|
-
}
|
|
262
|
-
createAgent(agentId) {
|
|
263
|
-
return new AgentHandle(this.apiKey, this.baseUrl, agentId);
|
|
264
|
-
}
|
|
265
|
-
// ── Automations ─────────────────────────────────────────────
|
|
266
|
-
async createAutomation(config) {
|
|
267
|
-
const res = await post(
|
|
268
|
-
this.apiKey,
|
|
269
|
-
this.baseUrl,
|
|
270
|
-
"/api/user/automations",
|
|
271
|
-
{
|
|
272
|
-
name: config.name,
|
|
273
|
-
triggerType: "schedule",
|
|
274
|
-
schedule: config.schedule,
|
|
275
|
-
agentId: config.agentId,
|
|
276
|
-
enabled: config.enabled ?? true,
|
|
277
|
-
payload: JSON.stringify({ task: config.task })
|
|
278
|
-
}
|
|
279
|
-
);
|
|
280
|
-
const list = await this.listAutomations();
|
|
281
|
-
return list.find((a) => a.automationId === res.automationId) || { automationId: res.automationId };
|
|
282
|
-
}
|
|
283
|
-
async listAutomations() {
|
|
284
|
-
const res = await get(
|
|
285
|
-
this.apiKey,
|
|
286
|
-
this.baseUrl,
|
|
287
|
-
"/api/user/automations"
|
|
288
|
-
);
|
|
289
|
-
return res.automations || [];
|
|
290
|
-
}
|
|
291
|
-
async runAutomation(automationId) {
|
|
292
|
-
const res = await post(
|
|
293
|
-
this.apiKey,
|
|
294
|
-
this.baseUrl,
|
|
295
|
-
`/api/user/automations/${encodeURIComponent(automationId)}/run`
|
|
296
|
-
);
|
|
297
|
-
return { response: res.result?.agentResponse || null };
|
|
298
|
-
}
|
|
299
|
-
// ── Multi-Agent Pipelines (Enterprise) ──────────────────────
|
|
300
|
-
async createPipeline(config) {
|
|
301
|
-
const res = await post(
|
|
302
|
-
this.apiKey,
|
|
303
|
-
this.baseUrl,
|
|
304
|
-
"/api/user/pipelines",
|
|
305
|
-
config
|
|
306
|
-
);
|
|
307
|
-
return res.pipelineId;
|
|
308
|
-
}
|
|
309
|
-
async runPipeline(pipelineId) {
|
|
310
|
-
const res = await post(
|
|
311
|
-
this.apiKey,
|
|
312
|
-
this.baseUrl,
|
|
313
|
-
`/api/user/pipelines/${encodeURIComponent(pipelineId)}/run`
|
|
314
|
-
);
|
|
315
|
-
return res.results || [];
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
var AgentHandle = class {
|
|
319
|
-
constructor(apiKey, baseUrl, agentId) {
|
|
320
|
-
this.apiKey = apiKey;
|
|
321
|
-
this.baseUrl = baseUrl;
|
|
322
|
-
this.agentId = agentId;
|
|
323
|
-
}
|
|
324
|
-
async chat(message, conversationId) {
|
|
325
|
-
const res = await post(
|
|
326
|
-
this.apiKey,
|
|
327
|
-
this.baseUrl,
|
|
328
|
-
`/api/bot/${encodeURIComponent(this.agentId)}/chat`,
|
|
329
|
-
{ message, conversationId }
|
|
330
|
-
);
|
|
331
|
-
return {
|
|
332
|
-
message: res.message || "",
|
|
333
|
-
agentId: this.agentId,
|
|
334
|
-
tokens: res.tokens,
|
|
335
|
-
provider: res.provider
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
run() {
|
|
339
|
-
console.log(`Agent ${this.agentId} is ready. Use .chat(message) to interact.`);
|
|
340
|
-
return this;
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
344
|
-
0 && (module.exports = {
|
|
345
|
-
AgentHandle,
|
|
346
|
-
AnalyticsTool,
|
|
347
|
-
PortfolioAgent,
|
|
348
|
-
TradingAgent,
|
|
349
|
-
ValtaAuthError,
|
|
1
|
+
import {
|
|
2
|
+
AuthError,
|
|
3
|
+
NotFoundError,
|
|
4
|
+
RateLimitError,
|
|
5
|
+
TierError,
|
|
6
|
+
ValtaClient,
|
|
7
|
+
ValtaError
|
|
8
|
+
} from "./chunk-LPBJPXJO.js";
|
|
9
|
+
export {
|
|
10
|
+
AuthError,
|
|
11
|
+
NotFoundError,
|
|
12
|
+
RateLimitError,
|
|
13
|
+
TierError,
|
|
350
14
|
ValtaClient,
|
|
351
15
|
ValtaError,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
WalletTool
|
|
355
|
-
});
|
|
16
|
+
ValtaClient as default
|
|
17
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,319 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, ""),
|
|
10
|
-
timeout: config.timeout || 3e4
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// src/utils/errors.ts
|
|
15
|
-
var ValtaError = class extends Error {
|
|
16
|
-
constructor(message, status = 500, code) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = "ValtaError";
|
|
19
|
-
this.status = status;
|
|
20
|
-
this.code = code;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var ValtaAuthError = class extends ValtaError {
|
|
24
|
-
constructor(message = "Invalid or missing API key") {
|
|
25
|
-
super(message, 401, "AUTH_ERROR");
|
|
26
|
-
this.name = "ValtaAuthError";
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var ValtaRateLimitError = class extends ValtaError {
|
|
30
|
-
constructor(message = "Rate limit exceeded", retryAfter) {
|
|
31
|
-
super(message, 429, "RATE_LIMIT");
|
|
32
|
-
this.name = "ValtaRateLimitError";
|
|
33
|
-
this.retryAfter = retryAfter;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var ValtaUpgradeError = class extends ValtaError {
|
|
37
|
-
constructor(message = "Upgrade your plan to access this feature") {
|
|
38
|
-
super(message, 403, "UPGRADE_REQUIRED");
|
|
39
|
-
this.name = "ValtaUpgradeError";
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/utils/http.ts
|
|
44
|
-
async function request(apiKey, baseUrl, method, path, body) {
|
|
45
|
-
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
46
|
-
const res = await fetch(url, {
|
|
47
|
-
method,
|
|
48
|
-
headers: {
|
|
49
|
-
"Content-Type": "application/json",
|
|
50
|
-
"Authorization": `Bearer ${apiKey}`,
|
|
51
|
-
"X-Valta-SDK": "1.0.0"
|
|
52
|
-
},
|
|
53
|
-
body: body ? JSON.stringify(body) : void 0
|
|
54
|
-
});
|
|
55
|
-
if (!res.ok) {
|
|
56
|
-
let parsed;
|
|
57
|
-
try {
|
|
58
|
-
parsed = await res.json();
|
|
59
|
-
} catch {
|
|
60
|
-
parsed = {};
|
|
61
|
-
}
|
|
62
|
-
const message = parsed?.error || parsed?.message || `HTTP ${res.status}`;
|
|
63
|
-
const code = parsed?.code;
|
|
64
|
-
if (res.status === 401) throw new ValtaAuthError(message);
|
|
65
|
-
if (res.status === 403) throw new ValtaUpgradeError(message);
|
|
66
|
-
if (res.status === 429) {
|
|
67
|
-
const retryAfter = Number(res.headers.get("retry-after")) || void 0;
|
|
68
|
-
throw new ValtaRateLimitError(message, retryAfter);
|
|
69
|
-
}
|
|
70
|
-
throw new ValtaError(message, res.status, code);
|
|
71
|
-
}
|
|
72
|
-
return res.json();
|
|
73
|
-
}
|
|
74
|
-
async function get(apiKey, baseUrl, path) {
|
|
75
|
-
return request(apiKey, baseUrl, "GET", path);
|
|
76
|
-
}
|
|
77
|
-
async function post(apiKey, baseUrl, path, body) {
|
|
78
|
-
return request(apiKey, baseUrl, "POST", path, body);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/tools/wallet.ts
|
|
82
|
-
var WalletTool = class {
|
|
83
|
-
constructor(apiKey, baseUrl) {
|
|
84
|
-
this.apiKey = apiKey;
|
|
85
|
-
this.baseUrl = baseUrl;
|
|
86
|
-
}
|
|
87
|
-
async getBalance() {
|
|
88
|
-
const res = await get(
|
|
89
|
-
this.apiKey,
|
|
90
|
-
this.baseUrl,
|
|
91
|
-
"/api/user/wallet/balance"
|
|
92
|
-
);
|
|
93
|
-
return { balance: res.balance || 0, currency: res.currency || "USDC" };
|
|
94
|
-
}
|
|
95
|
-
async getTransactions(limit = 20) {
|
|
96
|
-
const res = await get(
|
|
97
|
-
this.apiKey,
|
|
98
|
-
this.baseUrl,
|
|
99
|
-
`/api/user/transactions?limit=${limit}`
|
|
100
|
-
);
|
|
101
|
-
return res.transactions || res.data || [];
|
|
102
|
-
}
|
|
103
|
-
async getAddress() {
|
|
104
|
-
const res = await get(
|
|
105
|
-
this.apiKey,
|
|
106
|
-
this.baseUrl,
|
|
107
|
-
"/api/user/wallet"
|
|
108
|
-
);
|
|
109
|
-
return res.address || res.walletAddress || "";
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// src/tools/analytics.ts
|
|
114
|
-
var AnalyticsTool = class {
|
|
115
|
-
constructor(apiKey, baseUrl) {
|
|
116
|
-
this.apiKey = apiKey;
|
|
117
|
-
this.baseUrl = baseUrl;
|
|
118
|
-
}
|
|
119
|
-
async getSummary() {
|
|
120
|
-
const res = await get(
|
|
121
|
-
this.apiKey,
|
|
122
|
-
this.baseUrl,
|
|
123
|
-
"/api/user/analytics"
|
|
124
|
-
);
|
|
125
|
-
return res.summary || { totalSpend: 0, topAgents: [], spendByDay: [] };
|
|
126
|
-
}
|
|
127
|
-
async getAuditTrail(limit = 50) {
|
|
128
|
-
const res = await get(
|
|
129
|
-
this.apiKey,
|
|
130
|
-
this.baseUrl,
|
|
131
|
-
`/api/user/audit-trail?limit=${limit}`
|
|
132
|
-
);
|
|
133
|
-
return res.events || [];
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// src/agents/tradingAgent.ts
|
|
138
|
-
var TRADING_AGENT_ID = "trading_signal";
|
|
139
|
-
var TradingAgent = class {
|
|
140
|
-
constructor(apiKey, baseUrl) {
|
|
141
|
-
this.apiKey = apiKey;
|
|
142
|
-
this.baseUrl = baseUrl;
|
|
143
|
-
}
|
|
144
|
-
async analyze(question) {
|
|
145
|
-
const res = await post(
|
|
146
|
-
this.apiKey,
|
|
147
|
-
this.baseUrl,
|
|
148
|
-
`/api/bot/${TRADING_AGENT_ID}/chat`,
|
|
149
|
-
{ message: question }
|
|
150
|
-
);
|
|
151
|
-
return { message: res.message || "", agentId: TRADING_AGENT_ID, tokens: res.tokens, provider: res.provider };
|
|
152
|
-
}
|
|
153
|
-
async getMarketBrief() {
|
|
154
|
-
const res = await this.analyze(
|
|
155
|
-
"Give me a brief market analysis for BTC, ETH, and SOL. Include price action, key levels, and sentiment."
|
|
156
|
-
);
|
|
157
|
-
return res.message;
|
|
158
|
-
}
|
|
159
|
-
async getSignals(assets) {
|
|
160
|
-
const assetList = assets.join(", ").toUpperCase();
|
|
161
|
-
const res = await this.analyze(
|
|
162
|
-
`Provide buy/sell/hold signals for: ${assetList}. Include entry price, target, and stop-loss.`
|
|
163
|
-
);
|
|
164
|
-
return res.message;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// src/agents/portfolioAgent.ts
|
|
169
|
-
var PORTFOLIO_AGENT_ID = "portfolio_analyzer";
|
|
170
|
-
var PortfolioAgent = class {
|
|
171
|
-
constructor(apiKey, baseUrl) {
|
|
172
|
-
this.apiKey = apiKey;
|
|
173
|
-
this.baseUrl = baseUrl;
|
|
174
|
-
}
|
|
175
|
-
async analyze(question) {
|
|
176
|
-
const res = await post(
|
|
177
|
-
this.apiKey,
|
|
178
|
-
this.baseUrl,
|
|
179
|
-
`/api/bot/${PORTFOLIO_AGENT_ID}/chat`,
|
|
180
|
-
{ message: question }
|
|
181
|
-
);
|
|
182
|
-
return { message: res.message || "", agentId: PORTFOLIO_AGENT_ID, tokens: res.tokens, provider: res.provider };
|
|
183
|
-
}
|
|
184
|
-
async getReport() {
|
|
185
|
-
const res = await this.analyze(
|
|
186
|
-
"Generate a full portfolio health report. Include current allocation, risk score, and rebalancing suggestions."
|
|
187
|
-
);
|
|
188
|
-
return res.message;
|
|
189
|
-
}
|
|
190
|
-
async getRebalancingSuggestions(targetAllocation) {
|
|
191
|
-
const allocStr = Object.entries(targetAllocation).map(([asset, pct]) => `${asset}: ${pct}%`).join(", ");
|
|
192
|
-
const res = await this.analyze(
|
|
193
|
-
`Suggest how to rebalance my portfolio to reach this target allocation: ${allocStr}`
|
|
194
|
-
);
|
|
195
|
-
return res.message;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// src/core/client.ts
|
|
200
|
-
var ValtaClient = class {
|
|
201
|
-
constructor(config) {
|
|
202
|
-
this.plugins = [];
|
|
203
|
-
const validated = validateConfig(config);
|
|
204
|
-
this.apiKey = validated.apiKey;
|
|
205
|
-
this.baseUrl = validated.baseUrl;
|
|
206
|
-
this.wallet = new WalletTool(this.apiKey, this.baseUrl);
|
|
207
|
-
this.analytics = new AnalyticsTool(this.apiKey, this.baseUrl);
|
|
208
|
-
this.trading = new TradingAgent(this.apiKey, this.baseUrl);
|
|
209
|
-
this.portfolio = new PortfolioAgent(this.apiKey, this.baseUrl);
|
|
210
|
-
}
|
|
211
|
-
// ── Plugin system (express-style middleware) ────────────────
|
|
212
|
-
use(plugin) {
|
|
213
|
-
plugin(this);
|
|
214
|
-
this.plugins.push(plugin);
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
// ── Agents ──────────────────────────────────────────────────
|
|
218
|
-
async listAgents() {
|
|
219
|
-
const res = await get(
|
|
220
|
-
this.apiKey,
|
|
221
|
-
this.baseUrl,
|
|
222
|
-
"/api/agents"
|
|
223
|
-
);
|
|
224
|
-
return res.agents || res.capabilities || [];
|
|
225
|
-
}
|
|
226
|
-
createAgent(agentId) {
|
|
227
|
-
return new AgentHandle(this.apiKey, this.baseUrl, agentId);
|
|
228
|
-
}
|
|
229
|
-
// ── Automations ─────────────────────────────────────────────
|
|
230
|
-
async createAutomation(config) {
|
|
231
|
-
const res = await post(
|
|
232
|
-
this.apiKey,
|
|
233
|
-
this.baseUrl,
|
|
234
|
-
"/api/user/automations",
|
|
235
|
-
{
|
|
236
|
-
name: config.name,
|
|
237
|
-
triggerType: "schedule",
|
|
238
|
-
schedule: config.schedule,
|
|
239
|
-
agentId: config.agentId,
|
|
240
|
-
enabled: config.enabled ?? true,
|
|
241
|
-
payload: JSON.stringify({ task: config.task })
|
|
242
|
-
}
|
|
243
|
-
);
|
|
244
|
-
const list = await this.listAutomations();
|
|
245
|
-
return list.find((a) => a.automationId === res.automationId) || { automationId: res.automationId };
|
|
246
|
-
}
|
|
247
|
-
async listAutomations() {
|
|
248
|
-
const res = await get(
|
|
249
|
-
this.apiKey,
|
|
250
|
-
this.baseUrl,
|
|
251
|
-
"/api/user/automations"
|
|
252
|
-
);
|
|
253
|
-
return res.automations || [];
|
|
254
|
-
}
|
|
255
|
-
async runAutomation(automationId) {
|
|
256
|
-
const res = await post(
|
|
257
|
-
this.apiKey,
|
|
258
|
-
this.baseUrl,
|
|
259
|
-
`/api/user/automations/${encodeURIComponent(automationId)}/run`
|
|
260
|
-
);
|
|
261
|
-
return { response: res.result?.agentResponse || null };
|
|
262
|
-
}
|
|
263
|
-
// ── Multi-Agent Pipelines (Enterprise) ──────────────────────
|
|
264
|
-
async createPipeline(config) {
|
|
265
|
-
const res = await post(
|
|
266
|
-
this.apiKey,
|
|
267
|
-
this.baseUrl,
|
|
268
|
-
"/api/user/pipelines",
|
|
269
|
-
config
|
|
270
|
-
);
|
|
271
|
-
return res.pipelineId;
|
|
272
|
-
}
|
|
273
|
-
async runPipeline(pipelineId) {
|
|
274
|
-
const res = await post(
|
|
275
|
-
this.apiKey,
|
|
276
|
-
this.baseUrl,
|
|
277
|
-
`/api/user/pipelines/${encodeURIComponent(pipelineId)}/run`
|
|
278
|
-
);
|
|
279
|
-
return res.results || [];
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
var AgentHandle = class {
|
|
283
|
-
constructor(apiKey, baseUrl, agentId) {
|
|
284
|
-
this.apiKey = apiKey;
|
|
285
|
-
this.baseUrl = baseUrl;
|
|
286
|
-
this.agentId = agentId;
|
|
287
|
-
}
|
|
288
|
-
async chat(message, conversationId) {
|
|
289
|
-
const res = await post(
|
|
290
|
-
this.apiKey,
|
|
291
|
-
this.baseUrl,
|
|
292
|
-
`/api/bot/${encodeURIComponent(this.agentId)}/chat`,
|
|
293
|
-
{ message, conversationId }
|
|
294
|
-
);
|
|
295
|
-
return {
|
|
296
|
-
message: res.message || "",
|
|
297
|
-
agentId: this.agentId,
|
|
298
|
-
tokens: res.tokens,
|
|
299
|
-
provider: res.provider
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
run() {
|
|
303
|
-
console.log(`Agent ${this.agentId} is ready. Use .chat(message) to interact.`);
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
AuthError,
|
|
3
|
+
NotFoundError,
|
|
4
|
+
RateLimitError,
|
|
5
|
+
TierError,
|
|
6
|
+
ValtaClient,
|
|
7
|
+
ValtaError
|
|
8
|
+
} from "./chunk-HGO47A3L.mjs";
|
|
307
9
|
export {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
ValtaAuthError,
|
|
10
|
+
AuthError,
|
|
11
|
+
NotFoundError,
|
|
12
|
+
RateLimitError,
|
|
13
|
+
TierError,
|
|
313
14
|
ValtaClient,
|
|
314
15
|
ValtaError,
|
|
315
|
-
ValtaRateLimitError,
|
|
316
|
-
ValtaUpgradeError,
|
|
317
|
-
WalletTool,
|
|
318
16
|
ValtaClient as default
|
|
319
17
|
};
|