@conto_finance/create-conto-agent 0.3.0 → 0.4.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/CHANGELOG.md +29 -0
- package/README.md +47 -0
- package/dist/chunk-2U2MPMMD.js +155 -0
- package/dist/{chunk-ICDSTI2Z.js → chunk-5OT7YKV4.js} +295 -172
- package/dist/chunk-TJJY5NFH.js +76 -0
- package/dist/cli.js +405 -113
- package/dist/{config-EKAEJVZR.js → config-LEPHM5HT.js} +11 -1
- package/dist/index.js +18 -7
- package/dist/lib/rule-values.d.ts +52 -0
- package/dist/lib/rule-values.js +12 -0
- package/package.json +19 -11
- package/dist/chunk-OS5PZNRM.js +0 -87
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,13 @@ import {
|
|
|
5
5
|
fetchChains,
|
|
6
6
|
getChain,
|
|
7
7
|
runInit
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-5OT7YKV4.js";
|
|
9
|
+
import {
|
|
10
|
+
VELOCITY_PERIODS,
|
|
11
|
+
buildVelocityCountValue,
|
|
12
|
+
parseTrustScoreInput,
|
|
13
|
+
validatePaymentRequest
|
|
14
|
+
} from "./chunk-TJJY5NFH.js";
|
|
9
15
|
import {
|
|
10
16
|
isJsonMode,
|
|
11
17
|
printAmount,
|
|
@@ -17,14 +23,18 @@ import {
|
|
|
17
23
|
printPending,
|
|
18
24
|
printSuccess,
|
|
19
25
|
printTable,
|
|
26
|
+
printWarning,
|
|
20
27
|
setJsonMode,
|
|
21
28
|
truncateAddress
|
|
22
29
|
} from "./chunk-K4LBO234.js";
|
|
23
30
|
import {
|
|
31
|
+
isSensitiveConfigKey,
|
|
24
32
|
loadConfig,
|
|
25
33
|
loadGlobalConfig,
|
|
34
|
+
maskSecret,
|
|
35
|
+
missingSdkKeyMessage,
|
|
26
36
|
saveGlobalConfig
|
|
27
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-2U2MPMMD.js";
|
|
28
38
|
|
|
29
39
|
// src/cli.ts
|
|
30
40
|
import { Command } from "commander";
|
|
@@ -33,7 +43,7 @@ import { Command } from "commander";
|
|
|
33
43
|
async function statusCommand() {
|
|
34
44
|
const config = loadConfig();
|
|
35
45
|
if (!config.apiKey) {
|
|
36
|
-
printError(
|
|
46
|
+
printError(missingSdkKeyMessage(config));
|
|
37
47
|
process.exit(1);
|
|
38
48
|
}
|
|
39
49
|
const api = createApiClient({
|
|
@@ -98,6 +108,7 @@ function mark(status) {
|
|
|
98
108
|
async function doctorCommand() {
|
|
99
109
|
const config = loadConfig();
|
|
100
110
|
const checks = [];
|
|
111
|
+
const isSandbox = config.sandboxMode === "test";
|
|
101
112
|
checks.push({
|
|
102
113
|
name: "Base URL",
|
|
103
114
|
status: "ok",
|
|
@@ -107,7 +118,7 @@ async function doctorCommand() {
|
|
|
107
118
|
checks.push({
|
|
108
119
|
name: "SDK key",
|
|
109
120
|
status: "fail",
|
|
110
|
-
detail:
|
|
121
|
+
detail: missingSdkKeyMessage(config)
|
|
111
122
|
});
|
|
112
123
|
report(checks, null);
|
|
113
124
|
process.exit(1);
|
|
@@ -115,7 +126,7 @@ async function doctorCommand() {
|
|
|
115
126
|
checks.push({
|
|
116
127
|
name: "SDK key",
|
|
117
128
|
status: "ok",
|
|
118
|
-
detail: `${config.apiKey
|
|
129
|
+
detail: `${maskSecret(config.apiKey)} (from ${process.env.CONTO_API_KEY ? "environment" : ".env.local or ~/.conto/config.json"})`
|
|
119
130
|
});
|
|
120
131
|
const api = createApiClient({ baseUrl: config.baseUrl, apiKey: config.apiKey });
|
|
121
132
|
let setup;
|
|
@@ -138,8 +149,8 @@ async function doctorCommand() {
|
|
|
138
149
|
});
|
|
139
150
|
checks.push({
|
|
140
151
|
name: "Agent status",
|
|
141
|
-
status: setup.agent.status === "
|
|
142
|
-
detail: setup.agent.status === "
|
|
152
|
+
status: setup.agent.status === "active" ? "ok" : "fail",
|
|
153
|
+
detail: setup.agent.status === "active" ? "Active" : `${setup.agent.status}. Activate the agent in the dashboard.`
|
|
143
154
|
});
|
|
144
155
|
const scopes = setup.scopes || [];
|
|
145
156
|
const canRequest = scopes.includes("payments:request");
|
|
@@ -159,26 +170,26 @@ async function doctorCommand() {
|
|
|
159
170
|
checks.push({
|
|
160
171
|
name: "Wallet",
|
|
161
172
|
status: "fail",
|
|
162
|
-
detail: 'No wallet linked to this agent. Run "npx create-conto-agent" or link one in the dashboard.'
|
|
173
|
+
detail: 'No wallet linked to this agent. Run "npx @conto_finance/create-conto-agent" or link one in the dashboard.'
|
|
163
174
|
});
|
|
164
175
|
}
|
|
165
176
|
for (const w of wallets) {
|
|
166
177
|
const chainLabel = `${w.chainName} (${w.chainId})${w.isTestnet ? " testnet" : ""}`;
|
|
167
178
|
checks.push({
|
|
168
179
|
name: `Wallet ${shortAddress(w.address)}`,
|
|
169
|
-
status: w.status === "
|
|
170
|
-
detail: `${chainLabel}, ${w.
|
|
180
|
+
status: w.status === "active" ? "ok" : "warn",
|
|
181
|
+
detail: `${chainLabel}, ${w.custodyMode} custody, status ${w.status}`
|
|
171
182
|
});
|
|
172
|
-
const
|
|
183
|
+
const paymentMode = isSandbox ? "test" : w.custodyMode === "MANAGED" ? "managed" : "external";
|
|
173
184
|
checks.push({
|
|
174
185
|
name: " Execution",
|
|
175
|
-
status:
|
|
176
|
-
detail:
|
|
186
|
+
status: paymentMode === "managed" || paymentMode === "test" ? "ok" : "warn",
|
|
187
|
+
detail: paymentMode === "managed" ? "Managed by Conto (real transfers)" : paymentMode === "test" ? `Sandbox test mode${config.sandboxExpiresAt ? ` until ${config.sandboxExpiresAt}` : ""}; no onchain transfer required` : "External: the agent signs transactions and confirms them through the API"
|
|
177
188
|
});
|
|
178
189
|
checks.push({
|
|
179
190
|
name: " Balance",
|
|
180
|
-
status: w.balance > 0 ? "ok" : "warn",
|
|
181
|
-
detail: w.balance > 0 ? `${printAmount(w.balance, w.currency)}` : `0 ${w.currency}. Fund this wallet before paying${w.isTestnet ? " (testnet faucet available via init)" : ""}.`
|
|
191
|
+
status: w.balance > 0 || isSandbox ? "ok" : "warn",
|
|
192
|
+
detail: isSandbox ? "Simulated sandbox: no onchain funding required" : w.balance > 0 ? `${printAmount(w.balance, w.currency)}` : `0 ${w.currency}. Fund this wallet before paying${w.isTestnet ? " (testnet faucet available via init)" : ""}.`
|
|
182
193
|
});
|
|
183
194
|
if (w.limits?.daily != null) {
|
|
184
195
|
checks.push({
|
|
@@ -188,14 +199,15 @@ async function doctorCommand() {
|
|
|
188
199
|
});
|
|
189
200
|
}
|
|
190
201
|
}
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
202
|
+
const hasManagedWallet = wallets.some(
|
|
203
|
+
(wallet) => wallet.status === "active" && wallet.custodyMode === "MANAGED" && wallet.balance > 0
|
|
204
|
+
);
|
|
205
|
+
const readyForManagedExecution = setup.agent.status === "active" && canRequest && canExecute && (hasManagedWallet || isSandbox && wallets.some((wallet) => wallet.status === "active"));
|
|
206
|
+
checks.push({
|
|
207
|
+
name: "Payment readiness",
|
|
208
|
+
status: readyForManagedExecution ? "ok" : canRequest ? "warn" : "fail",
|
|
209
|
+
detail: readyForManagedExecution ? isSandbox ? "Sandbox can request and record test payments" : "Key and managed wallet can request and execute payments" : canRequest ? "Requests work; execution is limited (see checks above)" : "This key cannot request payments"
|
|
210
|
+
});
|
|
199
211
|
report(checks, setup);
|
|
200
212
|
const failed = checks.some((c) => c.status === "fail");
|
|
201
213
|
if (failed) process.exit(1);
|
|
@@ -239,7 +251,9 @@ function report(checks, setup) {
|
|
|
239
251
|
async function balanceCommand() {
|
|
240
252
|
const config = loadConfig();
|
|
241
253
|
if (!config.apiKey) {
|
|
242
|
-
printError(
|
|
254
|
+
printError(
|
|
255
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
256
|
+
);
|
|
243
257
|
process.exit(1);
|
|
244
258
|
}
|
|
245
259
|
const api = createApiClient({
|
|
@@ -280,24 +294,83 @@ async function balanceCommand() {
|
|
|
280
294
|
|
|
281
295
|
// src/commands/pay.ts
|
|
282
296
|
import chalk2 from "chalk";
|
|
297
|
+
var DRY_RUN_NOTICE = "Dry run: nothing was sent to Conto and no policy evaluation was performed.";
|
|
283
298
|
async function payCommand(address, amountStr, options) {
|
|
284
299
|
const config = loadConfig();
|
|
300
|
+
const validation = validatePaymentRequest({
|
|
301
|
+
address,
|
|
302
|
+
amount: amountStr,
|
|
303
|
+
purpose: options.purpose,
|
|
304
|
+
category: options.category,
|
|
305
|
+
walletId: options.wallet
|
|
306
|
+
});
|
|
307
|
+
if (options.dryRun) {
|
|
308
|
+
const baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/+$/, "");
|
|
309
|
+
const url = `${baseUrl}/api/sdk/payments/request`;
|
|
310
|
+
if (!validation.ok) {
|
|
311
|
+
if (isJsonMode()) {
|
|
312
|
+
printJson({
|
|
313
|
+
dryRun: true,
|
|
314
|
+
valid: false,
|
|
315
|
+
policyEvaluated: false,
|
|
316
|
+
errors: validation.errors
|
|
317
|
+
});
|
|
318
|
+
} else {
|
|
319
|
+
for (const error of validation.errors) printError(error);
|
|
320
|
+
console.log(chalk2.dim(`
|
|
321
|
+
${DRY_RUN_NOTICE}`));
|
|
322
|
+
}
|
|
323
|
+
process.exit(1);
|
|
324
|
+
}
|
|
325
|
+
if (isJsonMode()) {
|
|
326
|
+
printJson({
|
|
327
|
+
dryRun: true,
|
|
328
|
+
valid: true,
|
|
329
|
+
policyEvaluated: false,
|
|
330
|
+
apiKeyConfigured: Boolean(config.apiKey),
|
|
331
|
+
request: { method: "POST", url, body: validation.body },
|
|
332
|
+
note: DRY_RUN_NOTICE
|
|
333
|
+
});
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
printHeader("Payment Request (dry run)");
|
|
337
|
+
printKeyValue("To", address);
|
|
338
|
+
printKeyValue("Amount", printAmount(validation.body.amount, config.currency || "USD"));
|
|
339
|
+
if (options.purpose) printKeyValue("Purpose", options.purpose);
|
|
340
|
+
if (options.category) printKeyValue("Category", options.category);
|
|
341
|
+
if (options.wallet) printKeyValue("Wallet", options.wallet);
|
|
342
|
+
console.log("");
|
|
343
|
+
printSuccess("Input is valid");
|
|
344
|
+
console.log(chalk2.dim(` Would send: POST ${url}`));
|
|
345
|
+
console.log(chalk2.dim(` ${JSON.stringify(validation.body)}`));
|
|
346
|
+
if (!config.apiKey) {
|
|
347
|
+
printWarning('No API key configured. Run "conto login" before sending payments.');
|
|
348
|
+
}
|
|
349
|
+
console.log("");
|
|
350
|
+
printWarning(DRY_RUN_NOTICE);
|
|
351
|
+
console.log(chalk2.dim(' Run "conto limits" to see current spend limits.'));
|
|
352
|
+
console.log(chalk2.dim(" Run without --dry-run to submit the payment for policy evaluation."));
|
|
353
|
+
console.log("");
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
285
356
|
if (!config.apiKey) {
|
|
286
|
-
printError(
|
|
357
|
+
printError(
|
|
358
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
359
|
+
);
|
|
287
360
|
process.exit(1);
|
|
288
361
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
printError("Amount must be a positive number.");
|
|
362
|
+
if (!validation.ok) {
|
|
363
|
+
for (const error of validation.errors) printError(error);
|
|
292
364
|
process.exit(1);
|
|
293
365
|
}
|
|
366
|
+
const amount = validation.body.amount;
|
|
294
367
|
const api = createApiClient({
|
|
295
368
|
baseUrl: config.baseUrl,
|
|
296
369
|
apiKey: config.apiKey
|
|
297
370
|
});
|
|
298
371
|
try {
|
|
299
372
|
if (!isJsonMode()) {
|
|
300
|
-
printHeader(
|
|
373
|
+
printHeader("Payment Request");
|
|
301
374
|
printKeyValue("To", address);
|
|
302
375
|
printKeyValue("Amount", printAmount(amount, config.currency || "USD"));
|
|
303
376
|
if (options.purpose) printKeyValue("Purpose", options.purpose);
|
|
@@ -310,10 +383,6 @@ async function payCommand(address, amountStr, options) {
|
|
|
310
383
|
category: options.category,
|
|
311
384
|
walletId: options.wallet
|
|
312
385
|
});
|
|
313
|
-
if (isJsonMode() && options.dryRun) {
|
|
314
|
-
printJson(request);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
386
|
if (request.status === "DENIED") {
|
|
318
387
|
if (isJsonMode()) {
|
|
319
388
|
printJson(request);
|
|
@@ -354,35 +423,24 @@ async function payCommand(address, amountStr, options) {
|
|
|
354
423
|
console.log(chalk2.dim(" Check the Conto dashboard for next steps."));
|
|
355
424
|
return;
|
|
356
425
|
}
|
|
357
|
-
if (options.dryRun) {
|
|
358
|
-
if (isJsonMode()) {
|
|
359
|
-
printJson(request);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
printSuccess("Payment would be APPROVED");
|
|
363
|
-
printKeyValue("Wallet", request.wallet?.address || "\u2014");
|
|
364
|
-
printKeyValue(
|
|
365
|
-
"Balance",
|
|
366
|
-
printAmount(request.wallet?.availableBalance || 0, config.currency || "USD")
|
|
367
|
-
);
|
|
368
|
-
printKeyValue("Request ID", request.requestId);
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
426
|
const result = await api.executePayment(request.requestId);
|
|
372
427
|
if (isJsonMode()) {
|
|
373
428
|
printJson(result);
|
|
374
429
|
return;
|
|
375
430
|
}
|
|
376
|
-
if (
|
|
377
|
-
printSuccess("Payment recorded
|
|
431
|
+
if (config.sandboxMode === "test") {
|
|
432
|
+
printSuccess("Payment recorded in sandbox test mode");
|
|
378
433
|
} else {
|
|
379
434
|
printSuccess("Payment sent!");
|
|
380
435
|
}
|
|
381
|
-
printKeyValue("TX Hash", result.txHash);
|
|
436
|
+
if (result.receipt?.txHash) printKeyValue("TX Hash", result.receipt?.txHash);
|
|
382
437
|
printKeyValue("Amount", printAmount(result.amount, result.currency));
|
|
383
438
|
printKeyValue("Recipient", result.recipient);
|
|
384
439
|
printKeyValue("Status", result.status);
|
|
385
|
-
printKeyValue("
|
|
440
|
+
printKeyValue("Request ID", request.requestId);
|
|
441
|
+
if (result.receipt?.settlementMode)
|
|
442
|
+
printKeyValue("Settlement mode", result.receipt.settlementMode);
|
|
443
|
+
if (result.receipt?.explorerUrl) printKeyValue("Explorer", result.receipt?.explorerUrl);
|
|
386
444
|
console.log("");
|
|
387
445
|
} catch (err) {
|
|
388
446
|
const code = err.code;
|
|
@@ -397,13 +455,8 @@ async function payCommand(address, amountStr, options) {
|
|
|
397
455
|
chalk2.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
|
|
398
456
|
);
|
|
399
457
|
console.log(chalk2.dim(" or create a new standard SDK key (includes payments:execute)."));
|
|
400
|
-
} else if (code === "
|
|
401
|
-
console.log(
|
|
402
|
-
chalk2.dim(
|
|
403
|
-
" The wallet has no custody provider linked, so it cannot execute real transfers."
|
|
404
|
-
)
|
|
405
|
-
);
|
|
406
|
-
console.log(chalk2.dim(' Run "conto doctor" for wallet details.'));
|
|
458
|
+
} else if (code === "EXECUTION_UNAVAILABLE") {
|
|
459
|
+
console.log(chalk2.dim(" Try again later or contact Conto support if the issue continues."));
|
|
407
460
|
}
|
|
408
461
|
process.exit(1);
|
|
409
462
|
}
|
|
@@ -413,7 +466,7 @@ async function payCommand(address, amountStr, options) {
|
|
|
413
466
|
async function transactionsCommand(id, options) {
|
|
414
467
|
const config = loadConfig();
|
|
415
468
|
if (!config.apiKey) {
|
|
416
|
-
printError(
|
|
469
|
+
printError(missingSdkKeyMessage(config));
|
|
417
470
|
process.exit(1);
|
|
418
471
|
}
|
|
419
472
|
const api = createApiClient({
|
|
@@ -429,29 +482,42 @@ async function transactionsCommand(id, options) {
|
|
|
429
482
|
}
|
|
430
483
|
printHeader("Transaction Details");
|
|
431
484
|
printKeyValue("ID", tx.id);
|
|
432
|
-
printKeyValue("TX Hash", tx.txHash);
|
|
485
|
+
printKeyValue("TX Hash", tx.txHash || void 0);
|
|
433
486
|
printKeyValue("Status", tx.status);
|
|
434
|
-
printKeyValue("
|
|
435
|
-
printKeyValue("
|
|
436
|
-
|
|
487
|
+
printKeyValue("Type", tx.kind.replaceAll("_", " "));
|
|
488
|
+
printKeyValue("Authorization", tx.authorizationDecision.replaceAll("_", " "));
|
|
489
|
+
printKeyValue("Amount", printAmount(Number(tx.amount), tx.currency));
|
|
490
|
+
printKeyValue("Recipient", tx.recipientAgent?.name || tx.merchantName || tx.toAddress);
|
|
491
|
+
printKeyValue("Recipient Address", tx.toAddress);
|
|
437
492
|
if (tx.purpose) printKeyValue("Purpose", tx.purpose);
|
|
438
|
-
if (tx.
|
|
439
|
-
|
|
440
|
-
|
|
493
|
+
if (tx.merchantCategory) printKeyValue("Category", tx.merchantCategory);
|
|
494
|
+
if (tx.sourceWallet) {
|
|
495
|
+
printKeyValue("Source Wallet", `${tx.sourceWallet.name} (${tx.sourceWallet.id})`);
|
|
496
|
+
}
|
|
497
|
+
printKeyValue("Network", `${tx.chain.type.toUpperCase()} ${tx.chain.id}`);
|
|
498
|
+
if (tx.chain.blockNumber !== null) {
|
|
499
|
+
printKeyValue("Block", String(tx.chain.blockNumber));
|
|
500
|
+
}
|
|
501
|
+
if (tx.chain.explorerUrl) printKeyValue("Explorer", tx.chain.explorerUrl);
|
|
502
|
+
printKeyValue("Created", new Date(tx.initiatedAt).toLocaleString());
|
|
441
503
|
if (tx.confirmedAt) printKeyValue("Confirmed", new Date(tx.confirmedAt).toLocaleString());
|
|
504
|
+
if (tx.failedAt) printKeyValue("Failed", new Date(tx.failedAt).toLocaleString());
|
|
442
505
|
if (tx.alerts && tx.alerts.length > 0) {
|
|
443
506
|
printHeader("Alerts");
|
|
444
507
|
for (const a of tx.alerts) {
|
|
445
|
-
console.log(` [${a.
|
|
508
|
+
console.log(` [${a.severity.label}] ${a.title} \u2014 ${a.status.label}`);
|
|
509
|
+
console.log(` ${a.message}`);
|
|
510
|
+
if (a.reviewUrl) console.log(` Review: ${a.reviewUrl}`);
|
|
446
511
|
}
|
|
447
512
|
}
|
|
448
513
|
} else {
|
|
449
|
-
const { transactions,
|
|
514
|
+
const { transactions, pagination } = await api.getTransactions({
|
|
450
515
|
limit: options?.limit ? Number(options.limit) : 10,
|
|
451
516
|
status: options?.status
|
|
452
517
|
});
|
|
518
|
+
const total = pagination?.total ?? transactions.length;
|
|
453
519
|
if (isJsonMode()) {
|
|
454
|
-
printJson({ transactions,
|
|
520
|
+
printJson({ transactions, pagination });
|
|
455
521
|
return;
|
|
456
522
|
}
|
|
457
523
|
if (transactions.length === 0) {
|
|
@@ -462,9 +528,9 @@ async function transactionsCommand(id, options) {
|
|
|
462
528
|
printTable(
|
|
463
529
|
["Date", "Amount", "Recipient", "Purpose", "Status", "TX Hash"],
|
|
464
530
|
transactions.map((tx) => [
|
|
465
|
-
new Date(tx.
|
|
466
|
-
printAmount(tx.amount, tx.currency),
|
|
467
|
-
tx.
|
|
531
|
+
new Date(tx.initiatedAt).toLocaleDateString(),
|
|
532
|
+
printAmount(Number(tx.amount), tx.currency),
|
|
533
|
+
tx.recipientAgent?.name || tx.merchantName || truncateAddress(tx.toAddress),
|
|
468
534
|
tx.purpose || "\u2014",
|
|
469
535
|
tx.status,
|
|
470
536
|
tx.txHash ? truncateAddress(tx.txHash, 8) : "\u2014"
|
|
@@ -485,15 +551,16 @@ async function transactionsCommand(id, options) {
|
|
|
485
551
|
|
|
486
552
|
// src/commands/wallets.ts
|
|
487
553
|
import chalk3 from "chalk";
|
|
488
|
-
async function walletsCommand(subcommand) {
|
|
554
|
+
async function walletsCommand(subcommand, options = {}) {
|
|
489
555
|
const config = loadConfig();
|
|
490
556
|
if (!config.apiKey) {
|
|
491
|
-
printError(
|
|
557
|
+
printError(missingSdkKeyMessage(config));
|
|
492
558
|
process.exit(1);
|
|
493
559
|
}
|
|
494
560
|
const api = createApiClient({
|
|
495
561
|
baseUrl: config.baseUrl,
|
|
496
|
-
apiKey: config.apiKey
|
|
562
|
+
apiKey: config.apiKey,
|
|
563
|
+
orgApiKey: config.orgApiKey
|
|
497
564
|
});
|
|
498
565
|
try {
|
|
499
566
|
await fetchChains(config.baseUrl);
|
|
@@ -525,6 +592,54 @@ async function walletsCommand(subcommand) {
|
|
|
525
592
|
printError("No wallets to fund.");
|
|
526
593
|
return;
|
|
527
594
|
}
|
|
595
|
+
if (options.faucet) {
|
|
596
|
+
if (!config.orgApiKey) {
|
|
597
|
+
printError(
|
|
598
|
+
'Faucet funding requires an organization key. Run "conto login" or create the project with "npx @conto_finance/create-conto-agent".'
|
|
599
|
+
);
|
|
600
|
+
process.exit(1);
|
|
601
|
+
}
|
|
602
|
+
const results = [];
|
|
603
|
+
for (const w of wallets) {
|
|
604
|
+
const chainEntry = getChain(w.chainId);
|
|
605
|
+
if (!chainEntry?.faucetAvailable) {
|
|
606
|
+
results.push({
|
|
607
|
+
walletId: w.id,
|
|
608
|
+
address: w.address,
|
|
609
|
+
ok: false,
|
|
610
|
+
error: `No faucet available for chain ${w.chainId}`
|
|
611
|
+
});
|
|
612
|
+
if (!isJsonMode()) {
|
|
613
|
+
printError(`No faucet available for ${w.name} on chain ${w.chainId}.`);
|
|
614
|
+
}
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
try {
|
|
618
|
+
const faucetResult = await api.fundWallet(w.id);
|
|
619
|
+
results.push({ walletId: w.id, address: w.address, ok: true, ...faucetResult });
|
|
620
|
+
if (!isJsonMode()) {
|
|
621
|
+
printSuccess(
|
|
622
|
+
faucetResult.message || `Testnet funds requested for ${truncateAddress(w.address)}`
|
|
623
|
+
);
|
|
624
|
+
if (typeof faucetResult.updatedBalance === "number") {
|
|
625
|
+
printInfo(
|
|
626
|
+
`Updated balance: ${printAmount(faucetResult.updatedBalance, w.currency || "USD")}`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
} catch (err) {
|
|
631
|
+
const message = err instanceof Error ? err.message : "Faucet request failed";
|
|
632
|
+
results.push({ walletId: w.id, address: w.address, ok: false, error: message });
|
|
633
|
+
if (!isJsonMode()) {
|
|
634
|
+
printError(message);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (isJsonMode()) {
|
|
639
|
+
printJson({ results });
|
|
640
|
+
}
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
528
643
|
for (const w of wallets) {
|
|
529
644
|
const chainEntry = getChain(w.chainId);
|
|
530
645
|
if (isJsonMode()) {
|
|
@@ -706,7 +821,7 @@ var RULE_TYPES = {
|
|
|
706
821
|
label: "Counterparty Status",
|
|
707
822
|
hint: "Check trust status (TRUSTED, BLOCKED, etc.)"
|
|
708
823
|
},
|
|
709
|
-
{ value: "TRUST_SCORE", label: "Trust Score", hint: "Minimum trust score required (0-
|
|
824
|
+
{ value: "TRUST_SCORE", label: "Trust Score", hint: "Minimum trust score required (0.0-1.0)" }
|
|
710
825
|
],
|
|
711
826
|
CATEGORY: [
|
|
712
827
|
{
|
|
@@ -802,7 +917,7 @@ var RULE_TYPES = {
|
|
|
802
917
|
{
|
|
803
918
|
value: "MAINTENANCE_WINDOW",
|
|
804
919
|
label: "Maintenance Window",
|
|
805
|
-
hint: "Scheduled downtime
|
|
920
|
+
hint: "Scheduled downtime, no payments"
|
|
806
921
|
},
|
|
807
922
|
{ value: "BLOCKED_TIME_WINDOW", label: "Blocked Time Window", hint: "Recurring blocked hours" }
|
|
808
923
|
]
|
|
@@ -834,7 +949,9 @@ var ACTIONS = [
|
|
|
834
949
|
async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
835
950
|
const config = loadConfig();
|
|
836
951
|
if (!config.apiKey) {
|
|
837
|
-
printError(
|
|
952
|
+
printError(
|
|
953
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
954
|
+
);
|
|
838
955
|
process.exit(1);
|
|
839
956
|
}
|
|
840
957
|
const api = createApiClient({
|
|
@@ -915,7 +1032,7 @@ async function listAgentPolicies(api) {
|
|
|
915
1032
|
}
|
|
916
1033
|
printHeader("Agent Policies");
|
|
917
1034
|
for (const policy of policies) {
|
|
918
|
-
const scope = policy.
|
|
1035
|
+
const scope = policy.scope === "organization" ? chalk4.dim("[organization]") : chalk4.cyan(`[${policy.appliesVia.join("+")}]`);
|
|
919
1036
|
console.log(
|
|
920
1037
|
`
|
|
921
1038
|
${chalk4.bold(policy.name)} ${scope} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
|
|
@@ -949,9 +1066,10 @@ async function listAllPolicies(api) {
|
|
|
949
1066
|
printHeader(`All Organization Policies (${policies.length})`);
|
|
950
1067
|
for (const policy of policies) {
|
|
951
1068
|
const agentCount = policy._count?.agentPolicies ?? "?";
|
|
1069
|
+
const scope = policy.scope === "organization" ? "organization-wide" : `${agentCount} agents`;
|
|
952
1070
|
console.log(
|
|
953
1071
|
`
|
|
954
|
-
${chalk4.bold(policy.name)} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority}, ${
|
|
1072
|
+
${chalk4.bold(policy.name)} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority}, ${scope})`)}`
|
|
955
1073
|
);
|
|
956
1074
|
console.log(` ${chalk4.dim("ID:")} ${policy.id}`);
|
|
957
1075
|
console.log(
|
|
@@ -980,8 +1098,24 @@ async function createPolicy(api, agentId) {
|
|
|
980
1098
|
options: POLICY_TYPES
|
|
981
1099
|
});
|
|
982
1100
|
if (p.isCancel(policyType)) process.exit(0);
|
|
1101
|
+
const scope = await p.select({
|
|
1102
|
+
message: "Where should this policy apply?",
|
|
1103
|
+
options: [
|
|
1104
|
+
{
|
|
1105
|
+
value: "organization",
|
|
1106
|
+
label: "Entire organization",
|
|
1107
|
+
hint: "Mandatory baseline for every payment"
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
value: "assigned",
|
|
1111
|
+
label: "Only assigned targets",
|
|
1112
|
+
hint: "Assign to agents, wallets, or cards after creation"
|
|
1113
|
+
}
|
|
1114
|
+
]
|
|
1115
|
+
});
|
|
1116
|
+
if (p.isCancel(scope)) process.exit(0);
|
|
983
1117
|
const priority = await p.text({
|
|
984
|
-
message: "Priority (
|
|
1118
|
+
message: "Priority (higher = evaluated first)",
|
|
985
1119
|
initialValue: "50"
|
|
986
1120
|
});
|
|
987
1121
|
if (p.isCancel(priority)) process.exit(0);
|
|
@@ -992,13 +1126,14 @@ async function createPolicy(api, agentId) {
|
|
|
992
1126
|
const rule = await promptForRule(policyType);
|
|
993
1127
|
if (rule) rules.push(rule);
|
|
994
1128
|
}
|
|
995
|
-
const assignToAgent = agentId ? await p.confirm({ message: "Assign to current agent?" }) : false;
|
|
1129
|
+
const assignToAgent = agentId && scope === "assigned" ? await p.confirm({ message: "Assign to current agent?" }) : false;
|
|
996
1130
|
if (p.isCancel(assignToAgent)) process.exit(0);
|
|
997
1131
|
const result = await api.createPolicy({
|
|
998
1132
|
name,
|
|
999
1133
|
policyType,
|
|
1000
1134
|
priority: Number(priority),
|
|
1001
1135
|
isActive: true,
|
|
1136
|
+
scope,
|
|
1002
1137
|
rules,
|
|
1003
1138
|
agentIds: assignToAgent && agentId ? [agentId] : void 0
|
|
1004
1139
|
});
|
|
@@ -1029,10 +1164,20 @@ async function updatePolicy(api, policyId) {
|
|
|
1029
1164
|
]
|
|
1030
1165
|
});
|
|
1031
1166
|
if (p.isCancel(isActive)) process.exit(0);
|
|
1167
|
+
const scope = await p.select({
|
|
1168
|
+
message: "Scope?",
|
|
1169
|
+
options: [
|
|
1170
|
+
{ value: "skip", label: "No change" },
|
|
1171
|
+
{ value: "organization", label: "Entire organization" },
|
|
1172
|
+
{ value: "assigned", label: "Only assigned targets" }
|
|
1173
|
+
]
|
|
1174
|
+
});
|
|
1175
|
+
if (p.isCancel(scope)) process.exit(0);
|
|
1032
1176
|
const params = {};
|
|
1033
1177
|
if (name) params.name = name;
|
|
1034
1178
|
if (priority) params.priority = Number(priority);
|
|
1035
1179
|
if (isActive !== "skip") params.isActive = isActive === "true";
|
|
1180
|
+
if (scope !== "skip") params.scope = scope;
|
|
1036
1181
|
if (Object.keys(params).length === 0) {
|
|
1037
1182
|
printInfo("No changes to make.");
|
|
1038
1183
|
return;
|
|
@@ -1108,6 +1253,35 @@ async function promptForRule(policyType) {
|
|
|
1108
1253
|
});
|
|
1109
1254
|
if (p.isCancel(operator)) return null;
|
|
1110
1255
|
const ruleStr = ruleType.toString();
|
|
1256
|
+
if (ruleStr === "VELOCITY_LIMIT") {
|
|
1257
|
+
const period = await p.select({
|
|
1258
|
+
message: "Time window",
|
|
1259
|
+
options: VELOCITY_PERIODS.map((value2) => ({ value: value2, label: `Per ${value2.toLowerCase()}` }))
|
|
1260
|
+
});
|
|
1261
|
+
if (p.isCancel(period)) return null;
|
|
1262
|
+
const count = await p.text({
|
|
1263
|
+
message: "Max transactions in that window",
|
|
1264
|
+
placeholder: "5",
|
|
1265
|
+
validate: (v) => {
|
|
1266
|
+
const result = buildVelocityCountValue(v, period);
|
|
1267
|
+
return result.ok ? void 0 : result.error;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
if (p.isCancel(count)) return null;
|
|
1271
|
+
const built = buildVelocityCountValue(count, period);
|
|
1272
|
+
if (!built.ok) return null;
|
|
1273
|
+
const action2 = await p.select({
|
|
1274
|
+
message: "Action when rule triggers",
|
|
1275
|
+
options: ACTIONS
|
|
1276
|
+
});
|
|
1277
|
+
if (p.isCancel(action2)) return null;
|
|
1278
|
+
return {
|
|
1279
|
+
ruleType: ruleStr,
|
|
1280
|
+
operator,
|
|
1281
|
+
value: built.value,
|
|
1282
|
+
action: action2
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1111
1285
|
let placeholder = "500";
|
|
1112
1286
|
let valueHint = "Enter a number for limits, or JSON for lists";
|
|
1113
1287
|
if (ruleStr.includes("LIMIT") || ruleStr.includes("AMOUNT") || ruleStr.includes("CAP") || ruleStr === "REQUIRE_APPROVAL_ABOVE") {
|
|
@@ -1117,8 +1291,8 @@ async function promptForRule(policyType) {
|
|
|
1117
1291
|
placeholder = '["0xabc...","0xdef..."]';
|
|
1118
1292
|
valueHint = "JSON array of addresses or category names";
|
|
1119
1293
|
} else if (ruleStr === "TRUST_SCORE") {
|
|
1120
|
-
placeholder = "
|
|
1121
|
-
valueHint = "Trust score 0-
|
|
1294
|
+
placeholder = "0.7";
|
|
1295
|
+
valueHint = "Trust score 0.0-1.0";
|
|
1122
1296
|
} else if (ruleStr === "COUNTRY" || ruleStr === "GEOGRAPHIC_RESTRICTION") {
|
|
1123
1297
|
placeholder = '["US","GB","DE"]';
|
|
1124
1298
|
valueHint = "JSON array of country codes";
|
|
@@ -1127,10 +1301,20 @@ async function promptForRule(policyType) {
|
|
|
1127
1301
|
valueHint = "JSON with start and end dates (ISO format)";
|
|
1128
1302
|
}
|
|
1129
1303
|
const value = await p.text({
|
|
1130
|
-
message: `Value
|
|
1131
|
-
placeholder
|
|
1304
|
+
message: `Value: ${valueHint}`,
|
|
1305
|
+
placeholder,
|
|
1306
|
+
validate: ruleStr === "TRUST_SCORE" ? (v) => {
|
|
1307
|
+
const result = parseTrustScoreInput(v);
|
|
1308
|
+
return result.ok ? void 0 : result.error;
|
|
1309
|
+
} : void 0
|
|
1132
1310
|
});
|
|
1133
1311
|
if (p.isCancel(value)) return null;
|
|
1312
|
+
let ruleValue = value;
|
|
1313
|
+
if (ruleStr === "TRUST_SCORE") {
|
|
1314
|
+
const parsed = parseTrustScoreInput(ruleValue);
|
|
1315
|
+
if (!parsed.ok) return null;
|
|
1316
|
+
ruleValue = parsed.value;
|
|
1317
|
+
}
|
|
1134
1318
|
const action = await p.select({
|
|
1135
1319
|
message: "Action when rule triggers",
|
|
1136
1320
|
options: ACTIONS
|
|
@@ -1139,7 +1323,7 @@ async function promptForRule(policyType) {
|
|
|
1139
1323
|
return {
|
|
1140
1324
|
ruleType,
|
|
1141
1325
|
operator,
|
|
1142
|
-
value,
|
|
1326
|
+
value: ruleValue,
|
|
1143
1327
|
action
|
|
1144
1328
|
};
|
|
1145
1329
|
}
|
|
@@ -1180,7 +1364,8 @@ function printPolicyHelp() {
|
|
|
1180
1364
|
console.log(" Spend limits: 500");
|
|
1181
1365
|
console.log(' Address lists: ["0xabc...","0xdef..."]');
|
|
1182
1366
|
console.log(' Country codes: ["CU","IR","KP","SY","RU"]');
|
|
1183
|
-
console.log(" Trust score:
|
|
1367
|
+
console.log(" Trust score: 0.7 (0.0-1.0)");
|
|
1368
|
+
console.log(' Velocity: {"maxCount":5,"period":"HOUR"}');
|
|
1184
1369
|
console.log(' Date range: {"start":"2025-01-01","end":"2025-12-31"}');
|
|
1185
1370
|
console.log(' Categories: ["API_PROVIDER","CLOUD","SAAS"]');
|
|
1186
1371
|
console.log(chalk4.bold("\n Operators:"));
|
|
@@ -1221,7 +1406,9 @@ import chalk5 from "chalk";
|
|
|
1221
1406
|
async function limitsCommand() {
|
|
1222
1407
|
const config = loadConfig();
|
|
1223
1408
|
if (!config.apiKey) {
|
|
1224
|
-
printError(
|
|
1409
|
+
printError(
|
|
1410
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
1411
|
+
);
|
|
1225
1412
|
process.exit(1);
|
|
1226
1413
|
}
|
|
1227
1414
|
const api = createApiClient({
|
|
@@ -1283,7 +1470,7 @@ import chalk6 from "chalk";
|
|
|
1283
1470
|
async function alertsCommand(options = {}) {
|
|
1284
1471
|
const config = loadConfig();
|
|
1285
1472
|
if (!config.apiKey) {
|
|
1286
|
-
printError(
|
|
1473
|
+
printError(missingSdkKeyMessage(config));
|
|
1287
1474
|
process.exit(1);
|
|
1288
1475
|
}
|
|
1289
1476
|
const api = createApiClient({
|
|
@@ -1291,15 +1478,16 @@ async function alertsCommand(options = {}) {
|
|
|
1291
1478
|
apiKey: config.apiKey
|
|
1292
1479
|
});
|
|
1293
1480
|
try {
|
|
1481
|
+
const activeOnly = options.active || options.unread;
|
|
1294
1482
|
const { alerts } = await api.getAlerts({
|
|
1295
|
-
status:
|
|
1483
|
+
status: activeOnly ? "ACTIVE" : void 0
|
|
1296
1484
|
});
|
|
1297
1485
|
if (isJsonMode()) {
|
|
1298
1486
|
printJson(alerts);
|
|
1299
1487
|
return;
|
|
1300
1488
|
}
|
|
1301
1489
|
if (alerts.length === 0) {
|
|
1302
|
-
console.log("\n No alerts." + (
|
|
1490
|
+
console.log("\n No alerts." + (activeOnly ? " (showing active only)" : ""));
|
|
1303
1491
|
return;
|
|
1304
1492
|
}
|
|
1305
1493
|
printHeader(`Alerts (${alerts.length})`);
|
|
@@ -1308,7 +1496,7 @@ async function alertsCommand(options = {}) {
|
|
|
1308
1496
|
alerts.map((a) => [
|
|
1309
1497
|
new Date(a.createdAt).toLocaleDateString(),
|
|
1310
1498
|
severityColor(a.severity),
|
|
1311
|
-
a.
|
|
1499
|
+
a.alertType,
|
|
1312
1500
|
a.message.length > 50 ? a.message.slice(0, 50) + "..." : a.message,
|
|
1313
1501
|
a.status
|
|
1314
1502
|
])
|
|
@@ -1341,10 +1529,23 @@ function severityColor(severity) {
|
|
|
1341
1529
|
|
|
1342
1530
|
// src/commands/config.ts
|
|
1343
1531
|
import chalk7 from "chalk";
|
|
1532
|
+
var FORBIDDEN_CONFIG_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
1533
|
+
function isSafeConfigPath(parts) {
|
|
1534
|
+
return parts.length > 0 && parts.every(
|
|
1535
|
+
(part) => part.length > 0 && !FORBIDDEN_CONFIG_PATH_SEGMENTS.has(part.toLowerCase())
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1344
1538
|
async function configCommand(key, value) {
|
|
1345
1539
|
if (key && value) {
|
|
1346
1540
|
const global = loadGlobalConfig();
|
|
1347
1541
|
const parts = key.split(".");
|
|
1542
|
+
if (!isSafeConfigPath(parts)) {
|
|
1543
|
+
const error = "Invalid configuration key path.";
|
|
1544
|
+
if (isJsonMode()) printJson({ ok: false, error });
|
|
1545
|
+
else printError(error);
|
|
1546
|
+
process.exitCode = 1;
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1348
1549
|
let target = global;
|
|
1349
1550
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
1350
1551
|
if (!target[parts[i]] || typeof target[parts[i]] !== "object") {
|
|
@@ -1354,18 +1555,24 @@ async function configCommand(key, value) {
|
|
|
1354
1555
|
}
|
|
1355
1556
|
target[parts[parts.length - 1]] = value;
|
|
1356
1557
|
saveGlobalConfig(global);
|
|
1357
|
-
|
|
1558
|
+
const displayValue = isSensitiveConfigKey(key) ? maskSecret(value) : value;
|
|
1559
|
+
printSuccess(`Set ${key} = ${displayValue}`);
|
|
1358
1560
|
return;
|
|
1359
1561
|
}
|
|
1360
1562
|
const config = loadConfig();
|
|
1361
1563
|
if (isJsonMode()) {
|
|
1362
|
-
printJson(
|
|
1564
|
+
printJson({
|
|
1565
|
+
...config,
|
|
1566
|
+
apiKey: config.apiKey ? maskSecret(config.apiKey) : void 0,
|
|
1567
|
+
orgApiKey: config.orgApiKey ? maskSecret(config.orgApiKey) : void 0
|
|
1568
|
+
});
|
|
1363
1569
|
return;
|
|
1364
1570
|
}
|
|
1365
1571
|
printHeader("Configuration");
|
|
1572
|
+
printKeyValue("API Key", config.apiKey ? maskSecret(config.apiKey) : chalk7.dim("not set"));
|
|
1366
1573
|
printKeyValue(
|
|
1367
|
-
"
|
|
1368
|
-
config.
|
|
1574
|
+
"Organization credential expires",
|
|
1575
|
+
config.orgApiKeyExpiresAt || chalk7.dim("not recorded")
|
|
1369
1576
|
);
|
|
1370
1577
|
printKeyValue("Base URL", config.baseUrl);
|
|
1371
1578
|
printKeyValue("Agent ID", config.agentId || chalk7.dim("not set"));
|
|
@@ -1388,15 +1595,19 @@ async function loginCommand(options = {}) {
|
|
|
1388
1595
|
const baseUrl = options.baseUrl || existingConfig.server?.baseUrl || "https://conto.finance";
|
|
1389
1596
|
printInfo("Opening browser to authenticate...");
|
|
1390
1597
|
try {
|
|
1391
|
-
const { orgApiKey, organizationName } = await browserAuth(baseUrl);
|
|
1598
|
+
const { orgApiKey, organizationName, expiresAt } = await browserAuth(baseUrl);
|
|
1392
1599
|
const config = loadGlobalConfig();
|
|
1393
1600
|
if (!config.server) {
|
|
1394
1601
|
config.server = { baseUrl };
|
|
1395
1602
|
}
|
|
1396
1603
|
config.server.orgApiKey = orgApiKey;
|
|
1604
|
+
config.server.orgApiKeyExpiresAt = expiresAt;
|
|
1397
1605
|
config.server.baseUrl = baseUrl;
|
|
1398
1606
|
saveGlobalConfig(config);
|
|
1399
1607
|
printSuccess(`Authenticated with organization: ${organizationName}`);
|
|
1608
|
+
if (expiresAt) {
|
|
1609
|
+
printInfo(`Organization credential expires: ${expiresAt}`);
|
|
1610
|
+
}
|
|
1400
1611
|
printInfo("Credentials saved to ~/.conto/config.json");
|
|
1401
1612
|
} catch (err) {
|
|
1402
1613
|
printError(err instanceof Error ? err.message : "Authentication failed");
|
|
@@ -1409,11 +1620,13 @@ import { spawn } from "child_process";
|
|
|
1409
1620
|
async function mcpCommand() {
|
|
1410
1621
|
const config = loadConfig();
|
|
1411
1622
|
if (!config.apiKey) {
|
|
1412
|
-
printError(
|
|
1623
|
+
printError(
|
|
1624
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
1625
|
+
);
|
|
1413
1626
|
process.exit(1);
|
|
1414
1627
|
}
|
|
1415
1628
|
console.error(`Starting Conto MCP server (${config.baseUrl})...`);
|
|
1416
|
-
console.error(`Using SDK key ${config.apiKey
|
|
1629
|
+
console.error(`Using SDK key ${maskSecret(config.apiKey)}.`);
|
|
1417
1630
|
console.error("Press Ctrl+C to stop.\n");
|
|
1418
1631
|
const isWindows = process.platform === "win32";
|
|
1419
1632
|
const child = spawn(isWindows ? "npx.cmd" : "npx", ["--yes", "@conto_finance/mcp-server"], {
|
|
@@ -1435,10 +1648,81 @@ async function mcpCommand() {
|
|
|
1435
1648
|
});
|
|
1436
1649
|
}
|
|
1437
1650
|
|
|
1651
|
+
// src/commands/webhooks.ts
|
|
1652
|
+
import { createHmac, randomUUID } from "crypto";
|
|
1653
|
+
async function testWebhook(url) {
|
|
1654
|
+
const started = Date.now();
|
|
1655
|
+
try {
|
|
1656
|
+
const target = new URL(url);
|
|
1657
|
+
if (!["http:", "https:"].includes(target.protocol) || !["localhost", "127.0.0.1", "[::1]"].includes(target.hostname) || target.username || target.password) {
|
|
1658
|
+
throw new Error("Use a localhost, 127.0.0.1, or [::1] development URL.");
|
|
1659
|
+
}
|
|
1660
|
+
const secret = process.env.CONTO_WEBHOOK_SECRET;
|
|
1661
|
+
if (!secret)
|
|
1662
|
+
throw new Error(
|
|
1663
|
+
"Set CONTO_WEBHOOK_SECRET to the signing secret configured in your local handler."
|
|
1664
|
+
);
|
|
1665
|
+
const event = "payment.confirmed";
|
|
1666
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1667
|
+
const paymentId = `test_${randomUUID()}`;
|
|
1668
|
+
const body = JSON.stringify({
|
|
1669
|
+
event,
|
|
1670
|
+
timestamp,
|
|
1671
|
+
data: {
|
|
1672
|
+
paymentId,
|
|
1673
|
+
transactionId: `test_${randomUUID()}`,
|
|
1674
|
+
agentId: "test_agent",
|
|
1675
|
+
transactionHash: `0x${"0".repeat(64)}`,
|
|
1676
|
+
amount: 0.01,
|
|
1677
|
+
currency: "pathUSD",
|
|
1678
|
+
status: "CONFIRMED",
|
|
1679
|
+
test: true
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
const response = await fetch(target, {
|
|
1683
|
+
method: "POST",
|
|
1684
|
+
redirect: "error",
|
|
1685
|
+
signal: AbortSignal.timeout(1e4),
|
|
1686
|
+
headers: {
|
|
1687
|
+
"Content-Type": "application/json",
|
|
1688
|
+
"X-Conto-Event": event,
|
|
1689
|
+
"X-Conto-Timestamp": timestamp,
|
|
1690
|
+
"X-Conto-Delivery-Attempt": "1",
|
|
1691
|
+
"X-Conto-Signature": createHmac("sha256", secret).update(body).digest("hex")
|
|
1692
|
+
},
|
|
1693
|
+
body
|
|
1694
|
+
});
|
|
1695
|
+
await response.body?.cancel();
|
|
1696
|
+
const result = {
|
|
1697
|
+
ok: response.ok,
|
|
1698
|
+
status: response.status,
|
|
1699
|
+
elapsedMs: Date.now() - started,
|
|
1700
|
+
event,
|
|
1701
|
+
paymentId,
|
|
1702
|
+
test: true
|
|
1703
|
+
};
|
|
1704
|
+
if (isJsonMode()) printJson(result);
|
|
1705
|
+
else if (response.ok)
|
|
1706
|
+
printSuccess(
|
|
1707
|
+
`Local webhook accepted (HTTP ${response.status}, ${result.elapsedMs} ms). Event: ${paymentId}`
|
|
1708
|
+
);
|
|
1709
|
+
else
|
|
1710
|
+
printError(
|
|
1711
|
+
`Local handler returned HTTP ${response.status}. Check signature verification and server logs.`
|
|
1712
|
+
);
|
|
1713
|
+
if (!response.ok) process.exitCode = 1;
|
|
1714
|
+
} catch (error) {
|
|
1715
|
+
const message = error instanceof Error && (error.message.startsWith("Use a localhost") || error.message.startsWith("Set CONTO_WEBHOOK_SECRET")) ? error.message : "Local delivery failed. Check the URL and handler; redirects are not followed.";
|
|
1716
|
+
if (isJsonMode()) printJson({ ok: false, error: message });
|
|
1717
|
+
else printError(message);
|
|
1718
|
+
process.exitCode = 1;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1438
1722
|
// src/cli.ts
|
|
1439
1723
|
var program = new Command();
|
|
1440
|
-
program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (
|
|
1441
|
-
const opts =
|
|
1724
|
+
program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (_thisCommand, actionCommand) => {
|
|
1725
|
+
const opts = actionCommand.optsWithGlobals();
|
|
1442
1726
|
if (opts.json) {
|
|
1443
1727
|
setJsonMode(true);
|
|
1444
1728
|
}
|
|
@@ -1446,8 +1730,14 @@ program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Cen
|
|
|
1446
1730
|
program.command("init").description("Run the setup wizard (interactive, or headless with --sandbox/--api-key)").option(
|
|
1447
1731
|
"--chain <chain>",
|
|
1448
1732
|
"Chain ID from /api/chains (for example 42431, 4217, 8453, solana-mainnet)"
|
|
1449
|
-
).option("--name <name>", "Agent name").option("--type <type>", "Agent type").option("--limit <limit>", "Daily spending limit in USD").option("--base-url <url>", "Conto instance URL").option("--sandbox", "Create an anonymous test-mode sandbox (headless, no account needed)").option(
|
|
1450
|
-
|
|
1733
|
+
).option("--name <name>", "Agent name").option("--type <type>", "Agent type").option("--limit <limit>", "Daily spending limit in USD").option("--base-url <url>", "Conto instance URL").option("--sandbox", "Create an anonymous test-mode sandbox (headless, no account needed)").option(
|
|
1734
|
+
"--api-key <key>",
|
|
1735
|
+
"Existing organization API key (or set CONTO_ORG_API_KEY; skips browser authentication)"
|
|
1736
|
+
).option(
|
|
1737
|
+
"--confirm-mainnet",
|
|
1738
|
+
"Confirm that the selected network can move real funds (required for headless mainnet setup)"
|
|
1739
|
+
).option("--no-install", "Skip installing the conto CLI into the project").action(async (opts, command) => {
|
|
1740
|
+
if (command.optsWithGlobals().json) {
|
|
1451
1741
|
setJsonMode(true);
|
|
1452
1742
|
}
|
|
1453
1743
|
await runInit({
|
|
@@ -1458,30 +1748,32 @@ program.command("init").description("Run the setup wizard (interactive, or headl
|
|
|
1458
1748
|
baseUrl: opts.baseUrl,
|
|
1459
1749
|
install: opts.install,
|
|
1460
1750
|
sandbox: opts.sandbox === true,
|
|
1461
|
-
apiKey: opts.apiKey
|
|
1751
|
+
apiKey: opts.apiKey,
|
|
1752
|
+
confirmMainnet: opts.confirmMainnet === true
|
|
1462
1753
|
});
|
|
1463
1754
|
});
|
|
1755
|
+
program.command("webhooks").description("Test local webhook handlers").command("test <url>").description("Send one signed synthetic payment event to a localhost handler").action(testWebhook);
|
|
1464
1756
|
program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
|
|
1465
1757
|
program.command("doctor").description("Diagnose setup: auth, key scopes, wallet, chain, balance, base URL").action(doctorCommand);
|
|
1466
1758
|
program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
|
|
1467
|
-
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "
|
|
1759
|
+
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Validate input and show the request without sending it (no policy check)").option("--wallet <walletId>", "Specific wallet to use").action(payCommand);
|
|
1468
1760
|
program.command("transactions [id]").description("List recent transactions or view details").option("--limit <n>", "Number of transactions", "10").option("--status <status>", "Filter by status").action(transactionsCommand);
|
|
1469
1761
|
program.command("wallets").description("List wallets with balances").action(() => walletsCommand("list"));
|
|
1470
|
-
program.command("fund").description("Show wallet funding instructions").action(() => walletsCommand("fund"));
|
|
1762
|
+
program.command("fund").description("Show wallet funding instructions").option("--faucet", "Request testnet funds from the configured faucet").action((opts) => walletsCommand("fund", { faucet: opts.faucet === true }));
|
|
1471
1763
|
program.command("policies [subcommand] [id] [extra]").description(
|
|
1472
1764
|
"Manage spending policies (list, all, create, update, delete, assign, unassign, add-rule, remove-rule)"
|
|
1473
1765
|
).action(
|
|
1474
1766
|
(subcommand, id, extra) => policiesCommand(subcommand || "list", id, extra)
|
|
1475
1767
|
);
|
|
1476
1768
|
program.command("limits").description("Show spending limits and remaining budget").action(limitsCommand);
|
|
1477
|
-
program.command("alerts").description("List alerts").option("--
|
|
1769
|
+
program.command("alerts").description("List alerts").option("--active", "Show only active alerts").option("--unread", "Alias for --active").action(alertsCommand);
|
|
1478
1770
|
program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
|
|
1479
1771
|
program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
|
|
1480
1772
|
program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1481
|
-
const { clearGlobalConfig } = await import("./config-
|
|
1773
|
+
const { clearGlobalConfig } = await import("./config-LEPHM5HT.js");
|
|
1482
1774
|
clearGlobalConfig();
|
|
1483
|
-
const { printSuccess:
|
|
1484
|
-
|
|
1775
|
+
const { printSuccess: printSuccess2 } = await import("./output-IN47X4NU.js");
|
|
1776
|
+
printSuccess2("Logged out. Credentials cleared.");
|
|
1485
1777
|
});
|
|
1486
1778
|
program.command("mcp").description("Start MCP server for AI agent integration").action(mcpCommand);
|
|
1487
1779
|
program.command("docs [topic]").description("Open Conto documentation (cli, policies, sdk, api)").action(async (topic) => {
|
|
@@ -1494,8 +1786,8 @@ program.command("docs [topic]").description("Open Conto documentation (cli, poli
|
|
|
1494
1786
|
api: "https://conto.finance/docs/api"
|
|
1495
1787
|
};
|
|
1496
1788
|
const url = urls[topic || "cli"] || urls.cli;
|
|
1497
|
-
const { printInfo:
|
|
1498
|
-
|
|
1789
|
+
const { printInfo: printInfo2 } = await import("./output-IN47X4NU.js");
|
|
1790
|
+
printInfo2(`Opening ${url}`);
|
|
1499
1791
|
open(url);
|
|
1500
1792
|
});
|
|
1501
1793
|
program.parse();
|