@conto_finance/create-conto-agent 0.3.1 → 0.4.3
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 +35 -0
- package/README.md +51 -0
- package/dist/chunk-2U2MPMMD.js +155 -0
- package/dist/{chunk-QN5FG53Q.js → chunk-CMPYURB7.js} +294 -183
- package/dist/chunk-TJJY5NFH.js +76 -0
- package/dist/cli.js +317 -86
- package/dist/{config-RZBPNEBZ.js → config-LEPHM5HT.js} +3 -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 +17 -9
- package/dist/chunk-WMVGNUSL.js +0 -127
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-CMPYURB7.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,6 +23,7 @@ import {
|
|
|
17
23
|
printPending,
|
|
18
24
|
printSuccess,
|
|
19
25
|
printTable,
|
|
26
|
+
printWarning,
|
|
20
27
|
setJsonMode,
|
|
21
28
|
truncateAddress
|
|
22
29
|
} from "./chunk-K4LBO234.js";
|
|
@@ -27,7 +34,7 @@ import {
|
|
|
27
34
|
maskSecret,
|
|
28
35
|
missingSdkKeyMessage,
|
|
29
36
|
saveGlobalConfig
|
|
30
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-2U2MPMMD.js";
|
|
31
38
|
|
|
32
39
|
// src/cli.ts
|
|
33
40
|
import { Command } from "commander";
|
|
@@ -101,7 +108,7 @@ function mark(status) {
|
|
|
101
108
|
async function doctorCommand() {
|
|
102
109
|
const config = loadConfig();
|
|
103
110
|
const checks = [];
|
|
104
|
-
const
|
|
111
|
+
const isSandbox = config.sandboxMode === "test";
|
|
105
112
|
checks.push({
|
|
106
113
|
name: "Base URL",
|
|
107
114
|
status: "ok",
|
|
@@ -142,8 +149,8 @@ async function doctorCommand() {
|
|
|
142
149
|
});
|
|
143
150
|
checks.push({
|
|
144
151
|
name: "Agent status",
|
|
145
|
-
status: setup.agent.status === "
|
|
146
|
-
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.`
|
|
147
154
|
});
|
|
148
155
|
const scopes = setup.scopes || [];
|
|
149
156
|
const canRequest = scopes.includes("payments:request");
|
|
@@ -163,26 +170,26 @@ async function doctorCommand() {
|
|
|
163
170
|
checks.push({
|
|
164
171
|
name: "Wallet",
|
|
165
172
|
status: "fail",
|
|
166
|
-
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.'
|
|
167
174
|
});
|
|
168
175
|
}
|
|
169
176
|
for (const w of wallets) {
|
|
170
177
|
const chainLabel = `${w.chainName} (${w.chainId})${w.isTestnet ? " testnet" : ""}`;
|
|
171
178
|
checks.push({
|
|
172
179
|
name: `Wallet ${shortAddress(w.address)}`,
|
|
173
|
-
status: w.status === "
|
|
174
|
-
detail: `${chainLabel}, ${w.
|
|
180
|
+
status: w.status === "active" ? "ok" : "warn",
|
|
181
|
+
detail: `${chainLabel}, ${w.custodyMode} custody, status ${w.status}`
|
|
175
182
|
});
|
|
176
|
-
const
|
|
183
|
+
const paymentMode = isSandbox ? "test" : w.custodyMode === "MANAGED" ? "managed" : "external";
|
|
177
184
|
checks.push({
|
|
178
185
|
name: " Execution",
|
|
179
|
-
status:
|
|
180
|
-
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"
|
|
181
188
|
});
|
|
182
189
|
checks.push({
|
|
183
190
|
name: " Balance",
|
|
184
|
-
status: w.balance > 0 ? "ok" : "warn",
|
|
185
|
-
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)" : ""}.`
|
|
186
193
|
});
|
|
187
194
|
if (w.limits?.daily != null) {
|
|
188
195
|
checks.push({
|
|
@@ -192,15 +199,15 @@ async function doctorCommand() {
|
|
|
192
199
|
});
|
|
193
200
|
}
|
|
194
201
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
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
|
+
});
|
|
204
211
|
report(checks, setup);
|
|
205
212
|
const failed = checks.some((c) => c.status === "fail");
|
|
206
213
|
if (failed) process.exit(1);
|
|
@@ -244,7 +251,9 @@ function report(checks, setup) {
|
|
|
244
251
|
async function balanceCommand() {
|
|
245
252
|
const config = loadConfig();
|
|
246
253
|
if (!config.apiKey) {
|
|
247
|
-
printError(
|
|
254
|
+
printError(
|
|
255
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
256
|
+
);
|
|
248
257
|
process.exit(1);
|
|
249
258
|
}
|
|
250
259
|
const api = createApiClient({
|
|
@@ -285,24 +294,83 @@ async function balanceCommand() {
|
|
|
285
294
|
|
|
286
295
|
// src/commands/pay.ts
|
|
287
296
|
import chalk2 from "chalk";
|
|
297
|
+
var DRY_RUN_NOTICE = "Dry run: nothing was sent to Conto and no policy evaluation was performed.";
|
|
288
298
|
async function payCommand(address, amountStr, options) {
|
|
289
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
|
+
}
|
|
290
356
|
if (!config.apiKey) {
|
|
291
|
-
printError(
|
|
357
|
+
printError(
|
|
358
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
359
|
+
);
|
|
292
360
|
process.exit(1);
|
|
293
361
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
printError("Amount must be a positive number.");
|
|
362
|
+
if (!validation.ok) {
|
|
363
|
+
for (const error of validation.errors) printError(error);
|
|
297
364
|
process.exit(1);
|
|
298
365
|
}
|
|
366
|
+
const amount = validation.body.amount;
|
|
299
367
|
const api = createApiClient({
|
|
300
368
|
baseUrl: config.baseUrl,
|
|
301
369
|
apiKey: config.apiKey
|
|
302
370
|
});
|
|
303
371
|
try {
|
|
304
372
|
if (!isJsonMode()) {
|
|
305
|
-
printHeader(
|
|
373
|
+
printHeader("Payment Request");
|
|
306
374
|
printKeyValue("To", address);
|
|
307
375
|
printKeyValue("Amount", printAmount(amount, config.currency || "USD"));
|
|
308
376
|
if (options.purpose) printKeyValue("Purpose", options.purpose);
|
|
@@ -315,10 +383,6 @@ async function payCommand(address, amountStr, options) {
|
|
|
315
383
|
category: options.category,
|
|
316
384
|
walletId: options.wallet
|
|
317
385
|
});
|
|
318
|
-
if (isJsonMode() && options.dryRun) {
|
|
319
|
-
printJson(request);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
386
|
if (request.status === "DENIED") {
|
|
323
387
|
if (isJsonMode()) {
|
|
324
388
|
printJson(request);
|
|
@@ -359,35 +423,24 @@ async function payCommand(address, amountStr, options) {
|
|
|
359
423
|
console.log(chalk2.dim(" Check the Conto dashboard for next steps."));
|
|
360
424
|
return;
|
|
361
425
|
}
|
|
362
|
-
if (options.dryRun) {
|
|
363
|
-
if (isJsonMode()) {
|
|
364
|
-
printJson(request);
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
printSuccess("Payment would be APPROVED");
|
|
368
|
-
printKeyValue("Wallet", request.wallet?.address || "\u2014");
|
|
369
|
-
printKeyValue(
|
|
370
|
-
"Balance",
|
|
371
|
-
printAmount(request.wallet?.availableBalance || 0, config.currency || "USD")
|
|
372
|
-
);
|
|
373
|
-
printKeyValue("Request ID", request.requestId);
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
426
|
const result = await api.executePayment(request.requestId);
|
|
377
427
|
if (isJsonMode()) {
|
|
378
428
|
printJson(result);
|
|
379
429
|
return;
|
|
380
430
|
}
|
|
381
|
-
if (
|
|
382
|
-
printSuccess("Payment recorded
|
|
431
|
+
if (config.sandboxMode === "test") {
|
|
432
|
+
printSuccess("Payment recorded in sandbox test mode");
|
|
383
433
|
} else {
|
|
384
434
|
printSuccess("Payment sent!");
|
|
385
435
|
}
|
|
386
|
-
printKeyValue("TX Hash", result.txHash);
|
|
436
|
+
if (result.receipt?.txHash) printKeyValue("TX Hash", result.receipt?.txHash);
|
|
387
437
|
printKeyValue("Amount", printAmount(result.amount, result.currency));
|
|
388
438
|
printKeyValue("Recipient", result.recipient);
|
|
389
439
|
printKeyValue("Status", result.status);
|
|
390
|
-
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);
|
|
391
444
|
console.log("");
|
|
392
445
|
} catch (err) {
|
|
393
446
|
const code = err.code;
|
|
@@ -402,13 +455,8 @@ async function payCommand(address, amountStr, options) {
|
|
|
402
455
|
chalk2.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
|
|
403
456
|
);
|
|
404
457
|
console.log(chalk2.dim(" or create a new standard SDK key (includes payments:execute)."));
|
|
405
|
-
} else if (code === "
|
|
406
|
-
console.log(
|
|
407
|
-
chalk2.dim(
|
|
408
|
-
" The wallet has no custody provider linked, so it cannot execute real transfers."
|
|
409
|
-
)
|
|
410
|
-
);
|
|
411
|
-
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."));
|
|
412
460
|
}
|
|
413
461
|
process.exit(1);
|
|
414
462
|
}
|
|
@@ -434,20 +482,32 @@ async function transactionsCommand(id, options) {
|
|
|
434
482
|
}
|
|
435
483
|
printHeader("Transaction Details");
|
|
436
484
|
printKeyValue("ID", tx.id);
|
|
437
|
-
printKeyValue("TX Hash", tx.txHash);
|
|
485
|
+
printKeyValue("TX Hash", tx.txHash || void 0);
|
|
438
486
|
printKeyValue("Status", tx.status);
|
|
487
|
+
printKeyValue("Type", tx.kind.replaceAll("_", " "));
|
|
488
|
+
printKeyValue("Authorization", tx.authorizationDecision.replaceAll("_", " "));
|
|
439
489
|
printKeyValue("Amount", printAmount(Number(tx.amount), tx.currency));
|
|
440
490
|
printKeyValue("Recipient", tx.recipientAgent?.name || tx.merchantName || tx.toAddress);
|
|
441
491
|
printKeyValue("Recipient Address", tx.toAddress);
|
|
442
492
|
if (tx.purpose) printKeyValue("Purpose", tx.purpose);
|
|
443
493
|
if (tx.merchantCategory) printKeyValue("Category", tx.merchantCategory);
|
|
444
|
-
|
|
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);
|
|
445
502
|
printKeyValue("Created", new Date(tx.initiatedAt).toLocaleString());
|
|
446
503
|
if (tx.confirmedAt) printKeyValue("Confirmed", new Date(tx.confirmedAt).toLocaleString());
|
|
504
|
+
if (tx.failedAt) printKeyValue("Failed", new Date(tx.failedAt).toLocaleString());
|
|
447
505
|
if (tx.alerts && tx.alerts.length > 0) {
|
|
448
506
|
printHeader("Alerts");
|
|
449
507
|
for (const a of tx.alerts) {
|
|
450
|
-
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}`);
|
|
451
511
|
}
|
|
452
512
|
}
|
|
453
513
|
} else {
|
|
@@ -535,7 +595,7 @@ async function walletsCommand(subcommand, options = {}) {
|
|
|
535
595
|
if (options.faucet) {
|
|
536
596
|
if (!config.orgApiKey) {
|
|
537
597
|
printError(
|
|
538
|
-
'Faucet funding requires an organization key. Run "conto login" or create the project with "npx create-conto-agent".'
|
|
598
|
+
'Faucet funding requires an organization key. Run "conto login" or create the project with "npx @conto_finance/create-conto-agent".'
|
|
539
599
|
);
|
|
540
600
|
process.exit(1);
|
|
541
601
|
}
|
|
@@ -761,7 +821,7 @@ var RULE_TYPES = {
|
|
|
761
821
|
label: "Counterparty Status",
|
|
762
822
|
hint: "Check trust status (TRUSTED, BLOCKED, etc.)"
|
|
763
823
|
},
|
|
764
|
-
{ 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)" }
|
|
765
825
|
],
|
|
766
826
|
CATEGORY: [
|
|
767
827
|
{
|
|
@@ -857,7 +917,7 @@ var RULE_TYPES = {
|
|
|
857
917
|
{
|
|
858
918
|
value: "MAINTENANCE_WINDOW",
|
|
859
919
|
label: "Maintenance Window",
|
|
860
|
-
hint: "Scheduled downtime
|
|
920
|
+
hint: "Scheduled downtime, no payments"
|
|
861
921
|
},
|
|
862
922
|
{ value: "BLOCKED_TIME_WINDOW", label: "Blocked Time Window", hint: "Recurring blocked hours" }
|
|
863
923
|
]
|
|
@@ -889,7 +949,9 @@ var ACTIONS = [
|
|
|
889
949
|
async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
890
950
|
const config = loadConfig();
|
|
891
951
|
if (!config.apiKey) {
|
|
892
|
-
printError(
|
|
952
|
+
printError(
|
|
953
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
954
|
+
);
|
|
893
955
|
process.exit(1);
|
|
894
956
|
}
|
|
895
957
|
const api = createApiClient({
|
|
@@ -970,7 +1032,7 @@ async function listAgentPolicies(api) {
|
|
|
970
1032
|
}
|
|
971
1033
|
printHeader("Agent Policies");
|
|
972
1034
|
for (const policy of policies) {
|
|
973
|
-
const scope = policy.
|
|
1035
|
+
const scope = policy.scope === "organization" ? chalk4.dim("[organization]") : chalk4.cyan(`[${policy.appliesVia.join("+")}]`);
|
|
974
1036
|
console.log(
|
|
975
1037
|
`
|
|
976
1038
|
${chalk4.bold(policy.name)} ${scope} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
|
|
@@ -1004,9 +1066,10 @@ async function listAllPolicies(api) {
|
|
|
1004
1066
|
printHeader(`All Organization Policies (${policies.length})`);
|
|
1005
1067
|
for (const policy of policies) {
|
|
1006
1068
|
const agentCount = policy._count?.agentPolicies ?? "?";
|
|
1069
|
+
const scope = policy.scope === "organization" ? "organization-wide" : `${agentCount} agents`;
|
|
1007
1070
|
console.log(
|
|
1008
1071
|
`
|
|
1009
|
-
${chalk4.bold(policy.name)} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority}, ${
|
|
1072
|
+
${chalk4.bold(policy.name)} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority}, ${scope})`)}`
|
|
1010
1073
|
);
|
|
1011
1074
|
console.log(` ${chalk4.dim("ID:")} ${policy.id}`);
|
|
1012
1075
|
console.log(
|
|
@@ -1035,8 +1098,24 @@ async function createPolicy(api, agentId) {
|
|
|
1035
1098
|
options: POLICY_TYPES
|
|
1036
1099
|
});
|
|
1037
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);
|
|
1038
1117
|
const priority = await p.text({
|
|
1039
|
-
message: "Priority (
|
|
1118
|
+
message: "Priority (higher = evaluated first)",
|
|
1040
1119
|
initialValue: "50"
|
|
1041
1120
|
});
|
|
1042
1121
|
if (p.isCancel(priority)) process.exit(0);
|
|
@@ -1047,13 +1126,14 @@ async function createPolicy(api, agentId) {
|
|
|
1047
1126
|
const rule = await promptForRule(policyType);
|
|
1048
1127
|
if (rule) rules.push(rule);
|
|
1049
1128
|
}
|
|
1050
|
-
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;
|
|
1051
1130
|
if (p.isCancel(assignToAgent)) process.exit(0);
|
|
1052
1131
|
const result = await api.createPolicy({
|
|
1053
1132
|
name,
|
|
1054
1133
|
policyType,
|
|
1055
1134
|
priority: Number(priority),
|
|
1056
1135
|
isActive: true,
|
|
1136
|
+
scope,
|
|
1057
1137
|
rules,
|
|
1058
1138
|
agentIds: assignToAgent && agentId ? [agentId] : void 0
|
|
1059
1139
|
});
|
|
@@ -1084,10 +1164,20 @@ async function updatePolicy(api, policyId) {
|
|
|
1084
1164
|
]
|
|
1085
1165
|
});
|
|
1086
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);
|
|
1087
1176
|
const params = {};
|
|
1088
1177
|
if (name) params.name = name;
|
|
1089
1178
|
if (priority) params.priority = Number(priority);
|
|
1090
1179
|
if (isActive !== "skip") params.isActive = isActive === "true";
|
|
1180
|
+
if (scope !== "skip") params.scope = scope;
|
|
1091
1181
|
if (Object.keys(params).length === 0) {
|
|
1092
1182
|
printInfo("No changes to make.");
|
|
1093
1183
|
return;
|
|
@@ -1163,6 +1253,35 @@ async function promptForRule(policyType) {
|
|
|
1163
1253
|
});
|
|
1164
1254
|
if (p.isCancel(operator)) return null;
|
|
1165
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
|
+
}
|
|
1166
1285
|
let placeholder = "500";
|
|
1167
1286
|
let valueHint = "Enter a number for limits, or JSON for lists";
|
|
1168
1287
|
if (ruleStr.includes("LIMIT") || ruleStr.includes("AMOUNT") || ruleStr.includes("CAP") || ruleStr === "REQUIRE_APPROVAL_ABOVE") {
|
|
@@ -1172,8 +1291,8 @@ async function promptForRule(policyType) {
|
|
|
1172
1291
|
placeholder = '["0xabc...","0xdef..."]';
|
|
1173
1292
|
valueHint = "JSON array of addresses or category names";
|
|
1174
1293
|
} else if (ruleStr === "TRUST_SCORE") {
|
|
1175
|
-
placeholder = "
|
|
1176
|
-
valueHint = "Trust score 0-
|
|
1294
|
+
placeholder = "0.7";
|
|
1295
|
+
valueHint = "Trust score 0.0-1.0";
|
|
1177
1296
|
} else if (ruleStr === "COUNTRY" || ruleStr === "GEOGRAPHIC_RESTRICTION") {
|
|
1178
1297
|
placeholder = '["US","GB","DE"]';
|
|
1179
1298
|
valueHint = "JSON array of country codes";
|
|
@@ -1182,10 +1301,20 @@ async function promptForRule(policyType) {
|
|
|
1182
1301
|
valueHint = "JSON with start and end dates (ISO format)";
|
|
1183
1302
|
}
|
|
1184
1303
|
const value = await p.text({
|
|
1185
|
-
message: `Value
|
|
1186
|
-
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
|
|
1187
1310
|
});
|
|
1188
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
|
+
}
|
|
1189
1318
|
const action = await p.select({
|
|
1190
1319
|
message: "Action when rule triggers",
|
|
1191
1320
|
options: ACTIONS
|
|
@@ -1194,7 +1323,7 @@ async function promptForRule(policyType) {
|
|
|
1194
1323
|
return {
|
|
1195
1324
|
ruleType,
|
|
1196
1325
|
operator,
|
|
1197
|
-
value,
|
|
1326
|
+
value: ruleValue,
|
|
1198
1327
|
action
|
|
1199
1328
|
};
|
|
1200
1329
|
}
|
|
@@ -1235,7 +1364,8 @@ function printPolicyHelp() {
|
|
|
1235
1364
|
console.log(" Spend limits: 500");
|
|
1236
1365
|
console.log(' Address lists: ["0xabc...","0xdef..."]');
|
|
1237
1366
|
console.log(' Country codes: ["CU","IR","KP","SY","RU"]');
|
|
1238
|
-
console.log(" Trust score:
|
|
1367
|
+
console.log(" Trust score: 0.7 (0.0-1.0)");
|
|
1368
|
+
console.log(' Velocity: {"maxCount":5,"period":"HOUR"}');
|
|
1239
1369
|
console.log(' Date range: {"start":"2025-01-01","end":"2025-12-31"}');
|
|
1240
1370
|
console.log(' Categories: ["API_PROVIDER","CLOUD","SAAS"]');
|
|
1241
1371
|
console.log(chalk4.bold("\n Operators:"));
|
|
@@ -1276,7 +1406,9 @@ import chalk5 from "chalk";
|
|
|
1276
1406
|
async function limitsCommand() {
|
|
1277
1407
|
const config = loadConfig();
|
|
1278
1408
|
if (!config.apiKey) {
|
|
1279
|
-
printError(
|
|
1409
|
+
printError(
|
|
1410
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
1411
|
+
);
|
|
1280
1412
|
process.exit(1);
|
|
1281
1413
|
}
|
|
1282
1414
|
const api = createApiClient({
|
|
@@ -1397,10 +1529,23 @@ function severityColor(severity) {
|
|
|
1397
1529
|
|
|
1398
1530
|
// src/commands/config.ts
|
|
1399
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
|
+
}
|
|
1400
1538
|
async function configCommand(key, value) {
|
|
1401
1539
|
if (key && value) {
|
|
1402
1540
|
const global = loadGlobalConfig();
|
|
1403
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
|
+
}
|
|
1404
1549
|
let target = global;
|
|
1405
1550
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
1406
1551
|
if (!target[parts[i]] || typeof target[parts[i]] !== "object") {
|
|
@@ -1424,9 +1569,10 @@ async function configCommand(key, value) {
|
|
|
1424
1569
|
return;
|
|
1425
1570
|
}
|
|
1426
1571
|
printHeader("Configuration");
|
|
1572
|
+
printKeyValue("API Key", config.apiKey ? maskSecret(config.apiKey) : chalk7.dim("not set"));
|
|
1427
1573
|
printKeyValue(
|
|
1428
|
-
"
|
|
1429
|
-
config.
|
|
1574
|
+
"Organization credential expires",
|
|
1575
|
+
config.orgApiKeyExpiresAt || chalk7.dim("not recorded")
|
|
1430
1576
|
);
|
|
1431
1577
|
printKeyValue("Base URL", config.baseUrl);
|
|
1432
1578
|
printKeyValue("Agent ID", config.agentId || chalk7.dim("not set"));
|
|
@@ -1449,15 +1595,19 @@ async function loginCommand(options = {}) {
|
|
|
1449
1595
|
const baseUrl = options.baseUrl || existingConfig.server?.baseUrl || "https://conto.finance";
|
|
1450
1596
|
printInfo("Opening browser to authenticate...");
|
|
1451
1597
|
try {
|
|
1452
|
-
const { orgApiKey, organizationName } = await browserAuth(baseUrl);
|
|
1598
|
+
const { orgApiKey, organizationName, expiresAt } = await browserAuth(baseUrl);
|
|
1453
1599
|
const config = loadGlobalConfig();
|
|
1454
1600
|
if (!config.server) {
|
|
1455
1601
|
config.server = { baseUrl };
|
|
1456
1602
|
}
|
|
1457
1603
|
config.server.orgApiKey = orgApiKey;
|
|
1604
|
+
config.server.orgApiKeyExpiresAt = expiresAt;
|
|
1458
1605
|
config.server.baseUrl = baseUrl;
|
|
1459
1606
|
saveGlobalConfig(config);
|
|
1460
1607
|
printSuccess(`Authenticated with organization: ${organizationName}`);
|
|
1608
|
+
if (expiresAt) {
|
|
1609
|
+
printInfo(`Organization credential expires: ${expiresAt}`);
|
|
1610
|
+
}
|
|
1461
1611
|
printInfo("Credentials saved to ~/.conto/config.json");
|
|
1462
1612
|
} catch (err) {
|
|
1463
1613
|
printError(err instanceof Error ? err.message : "Authentication failed");
|
|
@@ -1470,7 +1620,9 @@ import { spawn } from "child_process";
|
|
|
1470
1620
|
async function mcpCommand() {
|
|
1471
1621
|
const config = loadConfig();
|
|
1472
1622
|
if (!config.apiKey) {
|
|
1473
|
-
printError(
|
|
1623
|
+
printError(
|
|
1624
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
1625
|
+
);
|
|
1474
1626
|
process.exit(1);
|
|
1475
1627
|
}
|
|
1476
1628
|
console.error(`Starting Conto MCP server (${config.baseUrl})...`);
|
|
@@ -1496,10 +1648,81 @@ async function mcpCommand() {
|
|
|
1496
1648
|
});
|
|
1497
1649
|
}
|
|
1498
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
|
+
|
|
1499
1722
|
// src/cli.ts
|
|
1500
1723
|
var program = new Command();
|
|
1501
|
-
program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (
|
|
1502
|
-
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();
|
|
1503
1726
|
if (opts.json) {
|
|
1504
1727
|
setJsonMode(true);
|
|
1505
1728
|
}
|
|
@@ -1507,8 +1730,14 @@ program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Cen
|
|
|
1507
1730
|
program.command("init").description("Run the setup wizard (interactive, or headless with --sandbox/--api-key)").option(
|
|
1508
1731
|
"--chain <chain>",
|
|
1509
1732
|
"Chain ID from /api/chains (for example 42431, 4217, 8453, solana-mainnet)"
|
|
1510
|
-
).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(
|
|
1511
|
-
|
|
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) {
|
|
1512
1741
|
setJsonMode(true);
|
|
1513
1742
|
}
|
|
1514
1743
|
await runInit({
|
|
@@ -1519,13 +1748,15 @@ program.command("init").description("Run the setup wizard (interactive, or headl
|
|
|
1519
1748
|
baseUrl: opts.baseUrl,
|
|
1520
1749
|
install: opts.install,
|
|
1521
1750
|
sandbox: opts.sandbox === true,
|
|
1522
|
-
apiKey: opts.apiKey
|
|
1751
|
+
apiKey: opts.apiKey,
|
|
1752
|
+
confirmMainnet: opts.confirmMainnet === true
|
|
1523
1753
|
});
|
|
1524
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);
|
|
1525
1756
|
program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
|
|
1526
1757
|
program.command("doctor").description("Diagnose setup: auth, key scopes, wallet, chain, balance, base URL").action(doctorCommand);
|
|
1527
1758
|
program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
|
|
1528
|
-
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);
|
|
1529
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);
|
|
1530
1761
|
program.command("wallets").description("List wallets with balances").action(() => walletsCommand("list"));
|
|
1531
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 }));
|
|
@@ -1539,7 +1770,7 @@ program.command("alerts").description("List alerts").option("--active", "Show on
|
|
|
1539
1770
|
program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
|
|
1540
1771
|
program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
|
|
1541
1772
|
program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1542
|
-
const { clearGlobalConfig } = await import("./config-
|
|
1773
|
+
const { clearGlobalConfig } = await import("./config-LEPHM5HT.js");
|
|
1543
1774
|
clearGlobalConfig();
|
|
1544
1775
|
const { printSuccess: printSuccess2 } = await import("./output-IN47X4NU.js");
|
|
1545
1776
|
printSuccess2("Logged out. Credentials cleared.");
|