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 CHANGED
@@ -1,158 +1,236 @@
1
- # Valta SDK
1
+ # valta-sdk
2
2
 
3
- Official TypeScript SDK for [Valta](https://valta.co) - Programmable AI Agent Spending Controls.
4
-
5
- ## Installation
3
+ Official JavaScript/TypeScript SDK for [Valta](https://valta.co) AI agent financial infrastructure.
6
4
 
5
+ Give your AI agents their own wallets, spending policies, kill switches, and audit logs.
7
6
  ```bash
8
7
  npm install valta-sdk
9
8
  ```
10
9
 
11
- ## Quick Start
10
+ ---
12
11
 
12
+ ## Quick Start
13
13
  ```typescript
14
- import { Valta } from "valta-sdk";
14
+ import Valta from 'valta-sdk';
15
15
 
16
- const valta = new Valta({
17
- apiKey: "sk_valta_...", // Your API key from valta.co/dashboard/api-keys
16
+ const valta = new Valta('vk_live_your_api_key');
17
+
18
+ // Create an agent
19
+ const agent = await valta.agents.create({
20
+ name: 'My Trading Agent',
21
+ type: 'trading',
18
22
  });
19
23
 
20
- // Request agent spending permission
21
- const result = await valta.requestSpend({
22
- agentId: "research-agent",
23
- amount: 20,
24
- category: "api_calls",
25
- description: "Purchase dataset access",
24
+ // Assign a spend policy
25
+ await valta.policies.create({
26
+ agentId: agent.id,
27
+ name: 'Daily limit',
28
+ maxSpendPerDay: 500,
29
+ currency: 'USDC',
26
30
  });
27
31
 
28
- if (result.approved) {
29
- console.log("Approved! TX:", result.tx_id);
30
- } else if (result.requires_approval) {
31
- console.log("Pending human approval:", result.request_id);
32
- } else {
33
- console.log("Denied:", result.reason);
34
- }
35
- ```
32
+ // Check wallet balance
33
+ const wallet = await valta.wallets.get(agent.id);
34
+ console.log(wallet.balance); // { usdc: '245.00' }
36
35
 
37
- ## Features
36
+ // Freeze agent instantly
37
+ await valta.agents.freeze(agent.id);
38
38
 
39
- - **Spending Controls** - Request permission before agents spend money
40
- - **Spending Policies** - Set per-transaction, daily, and monthly limits
41
- - **Human Approval Mode** - Require manual approval above thresholds
42
- - **Kill Switch** - Instantly freeze agent spending
43
- - **Agent Tools** - Configure and execute agent tools
44
- - **Agent Chains** - Create agent-to-agent workflows
45
- - **Balance Queries** - Check wallet balance programmatically
39
+ // Pull immutable audit log
40
+ const logs = await valta.audit.list({ agentId: agent.id });
41
+ ```
46
42
 
47
- ## API Reference
43
+ ---
48
44
 
49
- ### Initialize
45
+ ## Get an API Key
50
46
 
51
- ```typescript
52
- const valta = new Valta({
53
- apiKey: "sk_valta_...",
54
- baseUrl: "https://valta.co", // optional, defaults to production
55
- });
47
+ **Option 1 — Dashboard:**
48
+ 1. Go to [valta.co/dashboard](https://valta.co/dashboard)
49
+ 2. Navigate to API Keys
50
+ 3. Click Generate Key
51
+
52
+ **Option 2 — CLI (no dashboard needed):**
53
+ ```bash
54
+ npx valta-sdk login
56
55
  ```
57
56
 
58
- ### Spending
57
+ ---
59
58
 
60
- ```typescript
61
- // Request a spend action
62
- const result = await valta.requestSpend({
63
- agentId: "my-agent",
64
- amount: 10,
65
- category: "api_calls",
66
- description: "Call external API",
67
- });
59
+ ## CLI
60
+
61
+ The SDK ships with a terminal CLI. Use Valta entirely without a browser.
62
+ ```bash
63
+ # Authenticate
64
+ valta login
65
+
66
+ # List your agents
67
+ valta agents list
68
68
 
69
- // Check balance
70
- const { balance, currency } = await valta.getBalance();
69
+ # Freeze an agent
70
+ valta agents freeze ag_abc123
71
+
72
+ # Log out
73
+ valta logout
71
74
  ```
72
75
 
73
- ### Policies
76
+ ---
74
77
 
78
+ ## Agents
75
79
  ```typescript
76
- // Create a spending policy
77
- const policy = await valta.createPolicy({
78
- agentId: "research-agent",
79
- name: "Research Budget",
80
- dailyLimit: 100,
81
- monthlyLimit: 1000,
82
- maxPerTransaction: 50,
83
- requireApprovalAbove: 25,
84
- allowedCategories: ["api_calls", "datasets"],
80
+ // List all agents
81
+ const { agents } = await valta.agents.list();
82
+
83
+ // Get one agent
84
+ const agent = await valta.agents.get('ag_abc123');
85
+
86
+ // Create an agent
87
+ const agent = await valta.agents.create({
88
+ name: 'Portfolio Watcher',
89
+ type: 'analytics',
85
90
  });
86
91
 
87
- // List all policies
88
- const policies = await valta.listPolicies();
92
+ // Freeze an agent (stops all spending)
93
+ await valta.agents.freeze('ag_abc123');
94
+
95
+ // Unfreeze
96
+ await valta.agents.unfreeze('ag_abc123');
97
+
98
+ // Delete
99
+ await valta.agents.delete('ag_abc123');
89
100
  ```
90
101
 
91
- ### Approvals
102
+ ---
92
103
 
104
+ ## Wallets
93
105
  ```typescript
94
- // Get pending approvals
95
- const pending = await valta.getPendingApprovals();
96
-
97
- // Approve or reject
98
- await valta.approveRequest(requestId);
99
- await valta.rejectRequest(requestId, "Too expensive");
106
+ // Get wallet balance
107
+ const wallet = await valta.wallets.get('ag_abc123');
108
+ // { usdc: '500.00', usdcPending: '0.00' }
109
+
110
+ // Transfer funds between agents
111
+ await valta.wallets.transfer('ag_abc123', {
112
+ toAgentId: 'ag_def456',
113
+ amount: '100.00',
114
+ currency: 'USDC',
115
+ note: 'Fund allocation',
116
+ });
100
117
  ```
101
118
 
102
- ### Kill Switch
119
+ ---
103
120
 
121
+ ## Policies
104
122
  ```typescript
105
- // Freeze an agent immediately
106
- await valta.freezeAgent("rogue-agent", "Suspicious activity detected");
123
+ // Create a spend policy
124
+ await valta.policies.create({
125
+ agentId: 'ag_abc123',
126
+ name: 'Conservative limit',
127
+ maxSpendPerDay: 200,
128
+ maxSpendPerTransaction: 50,
129
+ currency: 'USDC',
130
+ });
107
131
 
108
- // Unfreeze when resolved
109
- await valta.unfreezeAgent("rogue-agent");
132
+ // List policies for an agent
133
+ const policies = await valta.policies.list('ag_abc123');
134
+
135
+ // Update a policy
136
+ await valta.policies.update('pol_xyz', {
137
+ maxSpendPerDay: 500,
138
+ });
110
139
  ```
111
140
 
112
- ### Agent Tools
141
+ ---
113
142
 
143
+ ## Audit Logs
114
144
  ```typescript
115
- // Get tools configured for an agent
116
- const tools = await valta.getAgentTools("my-agent");
117
-
118
- // Toggle a tool on/off
119
- await valta.toggleTool(toolId, false);
145
+ // Get full audit trail for an agent
146
+ const { logs } = await valta.audit.list({
147
+ agentId: 'ag_abc123',
148
+ limit: 50,
149
+ });
120
150
 
121
- // Execute a tool
122
- const result = await valta.executeTool("my-agent", toolId, { query: "data" });
151
+ // Each log entry is immutable and hash-chained
152
+ console.log(logs[0]);
153
+ // {
154
+ // id: 'log_001',
155
+ // action: 'transfer',
156
+ // amount: '100.00',
157
+ // hash: '0xabc...',
158
+ // previousHash: '0xdef...',
159
+ // createdAt: '2026-03-21T...'
160
+ // }
123
161
  ```
124
162
 
125
- ### Agent Chains
163
+ ---
126
164
 
165
+ ## API Keys
127
166
  ```typescript
128
- // Create an agent chain (agent-to-agent workflow)
129
- const chain = await valta.createChain({
130
- name: "Research Pipeline",
131
- steps: [
132
- { order: 1, agent_id: "research", agent_name: "Research Agent", action: "gather_data", input_from: "user" },
133
- { order: 2, agent_id: "analysis", agent_name: "Analysis Agent", action: "analyze", input_from: "previous" },
134
- { order: 3, agent_id: "report", agent_name: "Report Agent", action: "generate_report", input_from: "previous" },
135
- ],
136
- });
167
+ // List your API keys
168
+ const keys = await valta.keys.list();
169
+
170
+ // Create a new key
171
+ const { key } = await valta.keys.create('production');
172
+ console.log(key); // shown once save it now
137
173
 
138
- // Execute a chain
139
- await valta.executeChain(chain.chain_id);
174
+ // Revoke a key
175
+ await valta.keys.revoke('key_abc123');
140
176
  ```
141
177
 
178
+ ---
179
+
142
180
  ## Error Handling
143
181
 
182
+ The SDK throws typed errors so you always know what went wrong.
144
183
  ```typescript
145
- import { ValtaError } from "valta-sdk";
184
+ import Valta, { AuthError, TierError, RateLimitError } from 'valta-sdk';
146
185
 
147
186
  try {
148
- await valta.requestSpend({ agentId: "agent", amount: 1000 });
149
- } catch (error) {
150
- if (error instanceof ValtaError) {
151
- console.error(`Valta error (${error.status}):`, error.message);
187
+ await valta.agents.create({ name: 'Agent', type: 'trading' });
188
+ } catch (err) {
189
+ if (err instanceof TierError) {
190
+ console.log(`Upgrade required: ${err.requiredTier}`);
191
+ console.log(`Upgrade at: ${err.upgradeUrl}`);
192
+ } else if (err instanceof AuthError) {
193
+ console.log('Invalid API key');
194
+ } else if (err instanceof RateLimitError) {
195
+ console.log('Slow down — rate limit hit');
152
196
  }
153
197
  }
154
198
  ```
155
199
 
200
+ | Error | Status | When |
201
+ |---|---|---|
202
+ | `AuthError` | 401 | Invalid or missing API key |
203
+ | `TierError` | 403 | Feature requires a higher tier |
204
+ | `RateLimitError` | 429 | Too many requests |
205
+ | `NotFoundError` | 404 | Agent/resource not found |
206
+ | `ValtaError` | 5xx | Server error |
207
+
208
+ ---
209
+
210
+ ## Tier Limits
211
+
212
+ | Feature | Free | Builder | Startup | Enterprise |
213
+ |---|---|---|---|---|
214
+ | Agent wallets | 1 | 10 | Unlimited | Unlimited |
215
+ | Policies | 1 | Unlimited | Unlimited | Unlimited |
216
+ | API calls/day | 100 | 1,000 | Unlimited | Unlimited |
217
+ | Audit export | ✗ | ✗ | ✓ | ✓ |
218
+ | Team members | 1 | 1 | 5 | Unlimited |
219
+
220
+ ---
221
+
222
+ ## TypeScript
223
+
224
+ The SDK is written in TypeScript. All types are included — no `@types` package needed.
225
+ ```typescript
226
+ import Valta, { Agent, Policy, WalletBalance } from 'valta-sdk';
227
+
228
+ const agent: Agent = await valta.agents.get('ag_abc123');
229
+ const wallet: WalletBalance = await valta.wallets.get(agent.id);
230
+ ```
231
+
232
+ ---
233
+
156
234
  ## License
157
235
 
158
- MIT
236
+ MIT — built by [Valta](https://valta.co)
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
- import { readFileSync, writeFileSync, existsSync } from "fs";
4
- import { join } from "path";
5
- import { homedir } from "os";
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
6
8
 
7
- const CONFIG_FILE = join(homedir(), ".valta", "config.json");
8
- const VERSION = "2.0.0";
9
+ const cliPath = join(__dirname, '..', 'dist', 'cli', 'index.mjs');
9
10
 
10
- function loadConfig() {
11
- if (!existsSync(CONFIG_FILE)) return {};
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
+ });