@conto_finance/create-conto-agent 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-ICDSTI2Z.js +1209 -0
- package/dist/{chunk-6TRDZ4JG.js → chunk-K4LBO234.js} +1 -1
- package/dist/{chunk-NK52PCTE.js → chunk-OS5PZNRM.js} +14 -5
- package/dist/cli.js +336 -62
- package/dist/{config-CFVDT6M4.js → config-EKAEJVZR.js} +1 -1
- package/dist/index.js +75 -26
- package/dist/{output-VT23PY74.js → output-IN47X4NU.js} +1 -1
- package/package.json +9 -5
- package/dist/chunk-AWKUQSTP.js +0 -777
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CLI_PACKAGE_VERSION,
|
|
2
3
|
browserAuth,
|
|
3
4
|
createApiClient,
|
|
4
5
|
fetchChains,
|
|
5
6
|
getChain,
|
|
6
7
|
runInit
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ICDSTI2Z.js";
|
|
8
9
|
import {
|
|
9
10
|
isJsonMode,
|
|
10
11
|
printAmount,
|
|
@@ -18,12 +19,12 @@ import {
|
|
|
18
19
|
printTable,
|
|
19
20
|
setJsonMode,
|
|
20
21
|
truncateAddress
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-K4LBO234.js";
|
|
22
23
|
import {
|
|
23
24
|
loadConfig,
|
|
24
25
|
loadGlobalConfig,
|
|
25
26
|
saveGlobalConfig
|
|
26
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-OS5PZNRM.js";
|
|
27
28
|
|
|
28
29
|
// src/cli.ts
|
|
29
30
|
import { Command } from "commander";
|
|
@@ -49,6 +50,7 @@ async function statusCommand() {
|
|
|
49
50
|
printKeyValue("Name", info.agent.name);
|
|
50
51
|
printKeyValue("Type", info.agent.agentType);
|
|
51
52
|
printKeyValue("Status", info.agent.status);
|
|
53
|
+
printKeyValue("Server", config.baseUrl);
|
|
52
54
|
printKeyValue("Wallets", String(info.walletCount));
|
|
53
55
|
if (walletsData.wallets.length > 0) {
|
|
54
56
|
printHeader("Wallets");
|
|
@@ -86,6 +88,153 @@ function progressBar(pct, width = 20) {
|
|
|
86
88
|
return `${color}[${"\u2588".repeat(filled)}${"\u2591".repeat(empty)}]\x1B[0m`;
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
// src/commands/doctor.ts
|
|
92
|
+
import chalk from "chalk";
|
|
93
|
+
function mark(status) {
|
|
94
|
+
if (status === "ok") return chalk.green("\u2713");
|
|
95
|
+
if (status === "warn") return chalk.yellow("\u26A0");
|
|
96
|
+
return chalk.red("\u2717");
|
|
97
|
+
}
|
|
98
|
+
async function doctorCommand() {
|
|
99
|
+
const config = loadConfig();
|
|
100
|
+
const checks = [];
|
|
101
|
+
checks.push({
|
|
102
|
+
name: "Base URL",
|
|
103
|
+
status: "ok",
|
|
104
|
+
detail: config.baseUrl
|
|
105
|
+
});
|
|
106
|
+
if (!config.apiKey) {
|
|
107
|
+
checks.push({
|
|
108
|
+
name: "SDK key",
|
|
109
|
+
status: "fail",
|
|
110
|
+
detail: 'No CONTO_API_KEY found. Run "npx create-conto-agent" or "conto login".'
|
|
111
|
+
});
|
|
112
|
+
report(checks, null);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
checks.push({
|
|
116
|
+
name: "SDK key",
|
|
117
|
+
status: "ok",
|
|
118
|
+
detail: `${config.apiKey.slice(0, 16)}... (from ${process.env.CONTO_API_KEY ? "environment" : ".env.local or ~/.conto/config.json"})`
|
|
119
|
+
});
|
|
120
|
+
const api = createApiClient({ baseUrl: config.baseUrl, apiKey: config.apiKey });
|
|
121
|
+
let setup;
|
|
122
|
+
try {
|
|
123
|
+
setup = await api.getSetup();
|
|
124
|
+
} catch (err) {
|
|
125
|
+
const message = err instanceof Error ? err.message : "Request failed";
|
|
126
|
+
checks.push({
|
|
127
|
+
name: "Authentication",
|
|
128
|
+
status: "fail",
|
|
129
|
+
detail: `${config.baseUrl}/api/sdk/setup: ${message}`
|
|
130
|
+
});
|
|
131
|
+
report(checks, null);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
checks.push({
|
|
135
|
+
name: "Authentication",
|
|
136
|
+
status: "ok",
|
|
137
|
+
detail: `Authenticated as agent "${setup.agent.name}"`
|
|
138
|
+
});
|
|
139
|
+
checks.push({
|
|
140
|
+
name: "Agent status",
|
|
141
|
+
status: setup.agent.status === "ACTIVE" ? "ok" : "fail",
|
|
142
|
+
detail: setup.agent.status === "ACTIVE" ? "ACTIVE" : `${setup.agent.status}. Activate the agent in the dashboard.`
|
|
143
|
+
});
|
|
144
|
+
const scopes = setup.scopes || [];
|
|
145
|
+
const canRequest = scopes.includes("payments:request");
|
|
146
|
+
const canExecute = scopes.includes("payments:execute");
|
|
147
|
+
checks.push({
|
|
148
|
+
name: "Scope payments:request",
|
|
149
|
+
status: canRequest ? "ok" : "fail",
|
|
150
|
+
detail: canRequest ? "Granted" : "Missing. This key cannot request payments."
|
|
151
|
+
});
|
|
152
|
+
checks.push({
|
|
153
|
+
name: "Scope payments:execute",
|
|
154
|
+
status: canExecute ? "ok" : "warn",
|
|
155
|
+
detail: canExecute ? "Granted" : 'Missing. "conto pay" can request but not execute. Create a new standard SDK key.'
|
|
156
|
+
});
|
|
157
|
+
const wallets = setup.wallets || [];
|
|
158
|
+
if (wallets.length === 0) {
|
|
159
|
+
checks.push({
|
|
160
|
+
name: "Wallet",
|
|
161
|
+
status: "fail",
|
|
162
|
+
detail: 'No wallet linked to this agent. Run "npx create-conto-agent" or link one in the dashboard.'
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
for (const w of wallets) {
|
|
166
|
+
const chainLabel = `${w.chainName} (${w.chainId})${w.isTestnet ? " testnet" : ""}`;
|
|
167
|
+
checks.push({
|
|
168
|
+
name: `Wallet ${shortAddress(w.address)}`,
|
|
169
|
+
status: w.status === "ACTIVE" ? "ok" : "warn",
|
|
170
|
+
detail: `${chainLabel}, ${w.custodyType} custody, status ${w.status}`
|
|
171
|
+
});
|
|
172
|
+
const executionMode = w.executionMode || (w.isExecutable ? "managed" : "manual");
|
|
173
|
+
checks.push({
|
|
174
|
+
name: " Execution",
|
|
175
|
+
status: executionMode === "managed" ? "ok" : "warn",
|
|
176
|
+
detail: executionMode === "managed" ? "Managed by custody provider (real transfers)" : executionMode === "manual" ? "Manual: agent signs its own transactions, then confirms via API" : "Simulated: no custody provider linked. Transfers are mocked in dev and blocked in production."
|
|
177
|
+
});
|
|
178
|
+
checks.push({
|
|
179
|
+
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)" : ""}.`
|
|
182
|
+
});
|
|
183
|
+
if (w.limits?.daily != null) {
|
|
184
|
+
checks.push({
|
|
185
|
+
name: " Daily limit",
|
|
186
|
+
status: "ok",
|
|
187
|
+
detail: `${printAmount(w.spent?.today ?? 0, "USD")} spent of ${printAmount(w.limits.daily, "USD")}`
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const caps = setup.capabilities;
|
|
192
|
+
if (caps) {
|
|
193
|
+
checks.push({
|
|
194
|
+
name: "Payment readiness",
|
|
195
|
+
status: caps.canAutoExecute ? "ok" : caps.canRequestPayments ? "warn" : "fail",
|
|
196
|
+
detail: caps.canAutoExecute ? "Key and wallet can request and execute payments" : caps.canRequestPayments ? "Requests work; execution is limited (see checks above)" : "This key cannot request payments"
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
report(checks, setup);
|
|
200
|
+
const failed = checks.some((c) => c.status === "fail");
|
|
201
|
+
if (failed) process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
function shortAddress(address) {
|
|
204
|
+
if (!address || address.length <= 14) return address;
|
|
205
|
+
return `${address.slice(0, 8)}...${address.slice(-6)}`;
|
|
206
|
+
}
|
|
207
|
+
function report(checks, setup) {
|
|
208
|
+
if (isJsonMode()) {
|
|
209
|
+
printJson({
|
|
210
|
+
ok: !checks.some((c) => c.status === "fail"),
|
|
211
|
+
checks: checks.map((c) => ({ name: c.name.trim(), status: c.status, detail: c.detail })),
|
|
212
|
+
setup
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
printHeader("Conto Doctor");
|
|
217
|
+
for (const c of checks) {
|
|
218
|
+
console.log(` ${mark(c.status)} ${chalk.bold(c.name)}`);
|
|
219
|
+
console.log(` ${chalk.dim(c.detail)}`);
|
|
220
|
+
}
|
|
221
|
+
console.log("");
|
|
222
|
+
const fails = checks.filter((c) => c.status === "fail").length;
|
|
223
|
+
const warns = checks.filter((c) => c.status === "warn").length;
|
|
224
|
+
if (fails === 0 && warns === 0) {
|
|
225
|
+
console.log(chalk.green(" All checks passed."));
|
|
226
|
+
} else if (fails === 0) {
|
|
227
|
+
console.log(
|
|
228
|
+
chalk.yellow(
|
|
229
|
+
` ${warns} warning${warns === 1 ? "" : "s"}. Payments may still work; read the notes above.`
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
} else {
|
|
233
|
+
console.log(chalk.red(` ${fails} check${fails === 1 ? "" : "s"} failed.`));
|
|
234
|
+
}
|
|
235
|
+
console.log("");
|
|
236
|
+
}
|
|
237
|
+
|
|
89
238
|
// src/commands/balance.ts
|
|
90
239
|
async function balanceCommand() {
|
|
91
240
|
const config = loadConfig();
|
|
@@ -130,7 +279,7 @@ async function balanceCommand() {
|
|
|
130
279
|
}
|
|
131
280
|
|
|
132
281
|
// src/commands/pay.ts
|
|
133
|
-
import
|
|
282
|
+
import chalk2 from "chalk";
|
|
134
283
|
async function payCommand(address, amountStr, options) {
|
|
135
284
|
const config = loadConfig();
|
|
136
285
|
if (!config.apiKey) {
|
|
@@ -173,11 +322,11 @@ async function payCommand(address, amountStr, options) {
|
|
|
173
322
|
printError("Payment denied by policy");
|
|
174
323
|
if (request.violations) {
|
|
175
324
|
for (const v of request.violations) {
|
|
176
|
-
console.log(
|
|
325
|
+
console.log(chalk2.red(` ${v.message}`));
|
|
177
326
|
}
|
|
178
327
|
}
|
|
179
328
|
if (request.reasons.length > 0) {
|
|
180
|
-
console.log(
|
|
329
|
+
console.log(chalk2.dim(`
|
|
181
330
|
Reasons: ${request.reasons.join(", ")}`));
|
|
182
331
|
}
|
|
183
332
|
process.exit(1);
|
|
@@ -189,7 +338,20 @@ async function payCommand(address, amountStr, options) {
|
|
|
189
338
|
}
|
|
190
339
|
printPending("Payment requires manual approval");
|
|
191
340
|
printKeyValue("Request ID", request.requestId);
|
|
192
|
-
console.log(
|
|
341
|
+
console.log(chalk2.dim(" Approve in the Conto dashboard to execute."));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (request.status !== "APPROVED") {
|
|
345
|
+
if (isJsonMode()) {
|
|
346
|
+
printJson(request);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
printPending(`Payment is ${request.status}`);
|
|
350
|
+
printKeyValue("Request ID", request.requestId);
|
|
351
|
+
if (request.reasons.length > 0) {
|
|
352
|
+
console.log(chalk2.dim(` Reasons: ${request.reasons.join(", ")}`));
|
|
353
|
+
}
|
|
354
|
+
console.log(chalk2.dim(" Check the Conto dashboard for next steps."));
|
|
193
355
|
return;
|
|
194
356
|
}
|
|
195
357
|
if (options.dryRun) {
|
|
@@ -211,7 +373,11 @@ async function payCommand(address, amountStr, options) {
|
|
|
211
373
|
printJson(result);
|
|
212
374
|
return;
|
|
213
375
|
}
|
|
214
|
-
|
|
376
|
+
if (result.simulated) {
|
|
377
|
+
printSuccess("Payment recorded (simulated: no onchain transfer)");
|
|
378
|
+
} else {
|
|
379
|
+
printSuccess("Payment sent!");
|
|
380
|
+
}
|
|
215
381
|
printKeyValue("TX Hash", result.txHash);
|
|
216
382
|
printKeyValue("Amount", printAmount(result.amount, result.currency));
|
|
217
383
|
printKeyValue("Recipient", result.recipient);
|
|
@@ -219,11 +385,25 @@ async function payCommand(address, amountStr, options) {
|
|
|
219
385
|
printKeyValue("Explorer", result.explorerUrl);
|
|
220
386
|
console.log("");
|
|
221
387
|
} catch (err) {
|
|
388
|
+
const code = err.code;
|
|
222
389
|
const message = err instanceof Error ? err.message : "Payment failed";
|
|
223
390
|
if (isJsonMode()) {
|
|
224
|
-
printJson({ error: message });
|
|
225
|
-
|
|
226
|
-
|
|
391
|
+
printJson({ error: message, code });
|
|
392
|
+
process.exit(1);
|
|
393
|
+
}
|
|
394
|
+
printError(message);
|
|
395
|
+
if (code === "INSUFFICIENT_SCOPE") {
|
|
396
|
+
console.log(
|
|
397
|
+
chalk2.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
|
|
398
|
+
);
|
|
399
|
+
console.log(chalk2.dim(" or create a new standard SDK key (includes payments:execute)."));
|
|
400
|
+
} else if (code === "SIMULATED_EXECUTION_BLOCKED" || code === "CUSTODY_NOT_CONFIGURED") {
|
|
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.'));
|
|
227
407
|
}
|
|
228
408
|
process.exit(1);
|
|
229
409
|
}
|
|
@@ -304,7 +484,7 @@ async function transactionsCommand(id, options) {
|
|
|
304
484
|
}
|
|
305
485
|
|
|
306
486
|
// src/commands/wallets.ts
|
|
307
|
-
import
|
|
487
|
+
import chalk3 from "chalk";
|
|
308
488
|
async function walletsCommand(subcommand) {
|
|
309
489
|
const config = loadConfig();
|
|
310
490
|
if (!config.apiKey) {
|
|
@@ -368,20 +548,20 @@ async function walletsCommand(subcommand) {
|
|
|
368
548
|
console.log("");
|
|
369
549
|
if (chainEntry?.faucetAvailable && config.testnet) {
|
|
370
550
|
console.log(
|
|
371
|
-
|
|
551
|
+
chalk3.cyan(
|
|
372
552
|
' This is a testnet wallet. Use "conto fund --faucet" to get free test tokens.'
|
|
373
553
|
)
|
|
374
554
|
);
|
|
375
555
|
console.log("");
|
|
376
556
|
} else {
|
|
377
|
-
console.log(` To fund your agent wallet, send ${
|
|
557
|
+
console.log(` To fund your agent wallet, send ${chalk3.bold(w.currency || "USD")} to:
|
|
378
558
|
`);
|
|
379
|
-
console.log(
|
|
559
|
+
console.log(chalk3.bold(` ${w.address}`));
|
|
380
560
|
console.log("");
|
|
381
561
|
const instructions = getFundingInstructions(w.currency || "USD", chainEntry);
|
|
382
562
|
console.log(` How to get ${w.currency || "USD"}:`);
|
|
383
563
|
for (const instruction of instructions) {
|
|
384
|
-
console.log(` ${
|
|
564
|
+
console.log(` ${chalk3.dim("\u2022")} ${instruction}`);
|
|
385
565
|
}
|
|
386
566
|
console.log("");
|
|
387
567
|
if (chainEntry) {
|
|
@@ -401,6 +581,13 @@ async function walletsCommand(subcommand) {
|
|
|
401
581
|
}
|
|
402
582
|
}
|
|
403
583
|
function getFundingInstructions(currency, chain) {
|
|
584
|
+
if (currency === "USDC.e" && chain?.chainId === "4217") {
|
|
585
|
+
return [
|
|
586
|
+
"Bridge USDC into Tempo to receive USDC.e",
|
|
587
|
+
"Transfer USDC.e from another Tempo wallet",
|
|
588
|
+
"Swap supported Tempo assets into USDC.e"
|
|
589
|
+
];
|
|
590
|
+
}
|
|
404
591
|
if (currency === "pathUSD") {
|
|
405
592
|
return [
|
|
406
593
|
"Swap USDC \u2192 pathUSD on Tempo DEX",
|
|
@@ -426,7 +613,7 @@ function getFundingInstructions(currency, chain) {
|
|
|
426
613
|
}
|
|
427
614
|
|
|
428
615
|
// src/commands/policies.ts
|
|
429
|
-
import
|
|
616
|
+
import chalk4 from "chalk";
|
|
430
617
|
import * as p from "@clack/prompts";
|
|
431
618
|
var POLICY_TYPES = [
|
|
432
619
|
{
|
|
@@ -699,11 +886,11 @@ async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
|
699
886
|
process.exit(1);
|
|
700
887
|
}
|
|
701
888
|
return await removeRule(api, idOrAmount, extra);
|
|
889
|
+
case "help":
|
|
890
|
+
return printPolicyHelp();
|
|
702
891
|
default:
|
|
703
892
|
printError(`Unknown subcommand: ${subcommand}`);
|
|
704
|
-
printInfo(
|
|
705
|
-
"Available: list, all, create, update <id>, delete <id>, assign <id>, unassign <id>, add-rule <id>, remove-rule <policyId> <ruleId>"
|
|
706
|
-
);
|
|
893
|
+
printInfo('Run "conto policies help" for usage guide');
|
|
707
894
|
process.exit(1);
|
|
708
895
|
}
|
|
709
896
|
} catch (err) {
|
|
@@ -728,21 +915,21 @@ async function listAgentPolicies(api) {
|
|
|
728
915
|
}
|
|
729
916
|
printHeader("Agent Policies");
|
|
730
917
|
for (const policy of policies) {
|
|
731
|
-
const scope = policy.assignedVia === "agent" ?
|
|
918
|
+
const scope = policy.assignedVia === "agent" ? chalk4.cyan("[agent]") : chalk4.dim("[org-wide]");
|
|
732
919
|
console.log(
|
|
733
920
|
`
|
|
734
|
-
${
|
|
921
|
+
${chalk4.bold(policy.name)} ${scope} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
|
|
735
922
|
);
|
|
736
|
-
console.log(` ${
|
|
923
|
+
console.log(` ${chalk4.dim("ID:")} ${policy.id}`);
|
|
737
924
|
console.log(
|
|
738
|
-
` ${
|
|
925
|
+
` ${chalk4.dim("Active:")} ${policy.isActive ? chalk4.green("Yes") : chalk4.red("No")}`
|
|
739
926
|
);
|
|
740
927
|
if (policy.rules.length > 0) {
|
|
741
|
-
console.log(` ${
|
|
928
|
+
console.log(` ${chalk4.dim("Rules:")}`);
|
|
742
929
|
for (const rule of policy.rules) {
|
|
743
930
|
const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
|
|
744
931
|
console.log(
|
|
745
|
-
` ${
|
|
932
|
+
` ${chalk4.dim("\u2022")} ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
|
|
746
933
|
);
|
|
747
934
|
}
|
|
748
935
|
}
|
|
@@ -764,18 +951,18 @@ async function listAllPolicies(api) {
|
|
|
764
951
|
const agentCount = policy._count?.agentPolicies ?? "?";
|
|
765
952
|
console.log(
|
|
766
953
|
`
|
|
767
|
-
${
|
|
954
|
+
${chalk4.bold(policy.name)} ${chalk4.dim(`(${policy.policyType}, priority: ${policy.priority}, ${agentCount} agents)`)}`
|
|
768
955
|
);
|
|
769
|
-
console.log(` ${
|
|
956
|
+
console.log(` ${chalk4.dim("ID:")} ${policy.id}`);
|
|
770
957
|
console.log(
|
|
771
|
-
` ${
|
|
958
|
+
` ${chalk4.dim("Active:")} ${policy.isActive ? chalk4.green("Yes") : chalk4.red("No")}`
|
|
772
959
|
);
|
|
773
960
|
if (policy.rules.length > 0) {
|
|
774
|
-
console.log(` ${
|
|
961
|
+
console.log(` ${chalk4.dim("Rules:")}`);
|
|
775
962
|
for (const rule of policy.rules) {
|
|
776
963
|
const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
|
|
777
964
|
console.log(
|
|
778
|
-
` ${
|
|
965
|
+
` ${chalk4.dim("\u2022")} [${rule.id.slice(-6)}] ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
|
|
779
966
|
);
|
|
780
967
|
}
|
|
781
968
|
}
|
|
@@ -956,6 +1143,66 @@ async function promptForRule(policyType) {
|
|
|
956
1143
|
action
|
|
957
1144
|
};
|
|
958
1145
|
}
|
|
1146
|
+
function printPolicyHelp() {
|
|
1147
|
+
console.log(chalk4.bold("\n Conto Policy Management\n"));
|
|
1148
|
+
console.log(chalk4.bold(" Commands:"));
|
|
1149
|
+
console.log(" conto policies List agent policies");
|
|
1150
|
+
console.log(" conto policies all List all org policies");
|
|
1151
|
+
console.log(" conto policies create Create a new policy");
|
|
1152
|
+
console.log(" conto policies update <id> Update name/priority/status");
|
|
1153
|
+
console.log(" conto policies delete <id> Delete a policy");
|
|
1154
|
+
console.log(" conto policies assign <id> Assign to current agent");
|
|
1155
|
+
console.log(" conto policies unassign <id> Remove from agent");
|
|
1156
|
+
console.log(" conto policies add-rule <id> Add a rule");
|
|
1157
|
+
console.log(" conto policies remove-rule <id> <rid> Remove a rule");
|
|
1158
|
+
console.log(" conto policies help This help page");
|
|
1159
|
+
console.log(chalk4.bold("\n Policy Types:"));
|
|
1160
|
+
for (const pt of POLICY_TYPES) {
|
|
1161
|
+
console.log(` ${chalk4.cyan(pt.value.padEnd(22))} ${chalk4.dim(pt.hint)}`);
|
|
1162
|
+
}
|
|
1163
|
+
console.log(chalk4.bold("\n Common Rule Types:"));
|
|
1164
|
+
const commonRules = [
|
|
1165
|
+
["MAX_AMOUNT", "Max per-transaction amount (e.g. 500)"],
|
|
1166
|
+
["DAILY_LIMIT", "Max total spend per day (e.g. 1000)"],
|
|
1167
|
+
["WEEKLY_LIMIT", "Max total spend per week"],
|
|
1168
|
+
["MONTHLY_LIMIT", "Max total spend per month"],
|
|
1169
|
+
["REQUIRE_APPROVAL_ABOVE", "Human approval above $ amount"],
|
|
1170
|
+
["ALLOWED_COUNTERPARTIES", "JSON array of allowed addresses"],
|
|
1171
|
+
["BLOCKED_COUNTERPARTIES", "JSON array of blocked addresses"],
|
|
1172
|
+
["GEOGRAPHIC_RESTRICTION", "JSON array of blocked country codes"],
|
|
1173
|
+
["VELOCITY_LIMIT", "Max transactions per time window"],
|
|
1174
|
+
["DATE_RANGE", 'JSON: {"start":"2025-01-01","end":"2025-12-31"}']
|
|
1175
|
+
];
|
|
1176
|
+
for (const [rule, desc] of commonRules) {
|
|
1177
|
+
console.log(` ${chalk4.cyan(rule.padEnd(28))} ${chalk4.dim(desc)}`);
|
|
1178
|
+
}
|
|
1179
|
+
console.log(chalk4.bold("\n Value Examples:"));
|
|
1180
|
+
console.log(" Spend limits: 500");
|
|
1181
|
+
console.log(' Address lists: ["0xabc...","0xdef..."]');
|
|
1182
|
+
console.log(' Country codes: ["CU","IR","KP","SY","RU"]');
|
|
1183
|
+
console.log(" Trust score: 50 (0-100)");
|
|
1184
|
+
console.log(' Date range: {"start":"2025-01-01","end":"2025-12-31"}');
|
|
1185
|
+
console.log(' Categories: ["API_PROVIDER","CLOUD","SAAS"]');
|
|
1186
|
+
console.log(chalk4.bold("\n Operators:"));
|
|
1187
|
+
console.log(" LTE (<= at most) GTE (>= at least) EQUALS NOT_EQUALS");
|
|
1188
|
+
console.log(" IN_LIST NOT_IN_LIST BETWEEN DENY");
|
|
1189
|
+
console.log(chalk4.bold("\n Actions:"));
|
|
1190
|
+
console.log(` ${chalk4.green("ALLOW")} Payment proceeds if rule passes`);
|
|
1191
|
+
console.log(` ${chalk4.red("DENY")} Payment is blocked`);
|
|
1192
|
+
console.log(` ${chalk4.yellow("REQUIRE_APPROVAL")} Payment needs human approval`);
|
|
1193
|
+
console.log(chalk4.bold("\n Examples:"));
|
|
1194
|
+
console.log(chalk4.dim(" # Create a $500/day spend limit"));
|
|
1195
|
+
console.log(" conto policies create");
|
|
1196
|
+
console.log(chalk4.dim(" # Add a weekly limit rule to an existing policy"));
|
|
1197
|
+
console.log(" conto policies add-rule cmn4abc123");
|
|
1198
|
+
console.log(chalk4.dim(" # Deactivate a policy without deleting"));
|
|
1199
|
+
console.log(" conto policies update cmn4abc123");
|
|
1200
|
+
console.log(chalk4.dim(" # View all policies as JSON"));
|
|
1201
|
+
console.log(" conto policies all --json");
|
|
1202
|
+
console.log(`
|
|
1203
|
+
${chalk4.dim("Full docs: https://conto.finance/docs/cli/policies")}
|
|
1204
|
+
`);
|
|
1205
|
+
}
|
|
959
1206
|
function formatRuleValue(ruleType, value) {
|
|
960
1207
|
if (ruleType.includes("LIMIT") || ruleType.includes("AMOUNT") || ruleType.includes("CAP")) {
|
|
961
1208
|
const num = Number(value);
|
|
@@ -970,7 +1217,7 @@ function formatRuleValue(ruleType, value) {
|
|
|
970
1217
|
}
|
|
971
1218
|
|
|
972
1219
|
// src/commands/limits.ts
|
|
973
|
-
import
|
|
1220
|
+
import chalk5 from "chalk";
|
|
974
1221
|
async function limitsCommand() {
|
|
975
1222
|
const config = loadConfig();
|
|
976
1223
|
if (!config.apiKey) {
|
|
@@ -994,21 +1241,21 @@ async function limitsCommand() {
|
|
|
994
1241
|
printHeader("Spending Limits");
|
|
995
1242
|
for (const l of limits) {
|
|
996
1243
|
console.log(`
|
|
997
|
-
${
|
|
1244
|
+
${chalk5.bold(l.walletName)}`);
|
|
998
1245
|
const dailyPct = l.daily.limit > 0 ? Math.round(l.daily.spent / l.daily.limit * 100) : 0;
|
|
999
1246
|
console.log(
|
|
1000
|
-
` ${
|
|
1247
|
+
` ${chalk5.dim("Daily:")} ${bar(dailyPct)} ${printAmount(l.daily.spent, "USD")} / ${printAmount(l.daily.limit, "USD")} ${chalk5.dim(`(${printAmount(l.daily.remaining, "USD")} remaining)`)}`
|
|
1001
1248
|
);
|
|
1002
1249
|
if (l.weekly) {
|
|
1003
1250
|
const weeklyPct = l.weekly.limit > 0 ? Math.round(l.weekly.spent / l.weekly.limit * 100) : 0;
|
|
1004
1251
|
console.log(
|
|
1005
|
-
` ${
|
|
1252
|
+
` ${chalk5.dim("Weekly:")} ${bar(weeklyPct)} ${printAmount(l.weekly.spent, "USD")} / ${printAmount(l.weekly.limit, "USD")} ${chalk5.dim(`(${printAmount(l.weekly.remaining, "USD")} remaining)`)}`
|
|
1006
1253
|
);
|
|
1007
1254
|
}
|
|
1008
1255
|
if (l.monthly) {
|
|
1009
1256
|
const monthlyPct = l.monthly.limit > 0 ? Math.round(l.monthly.spent / l.monthly.limit * 100) : 0;
|
|
1010
1257
|
console.log(
|
|
1011
|
-
` ${
|
|
1258
|
+
` ${chalk5.dim("Monthly:")} ${bar(monthlyPct)} ${printAmount(l.monthly.spent, "USD")} / ${printAmount(l.monthly.limit, "USD")} ${chalk5.dim(`(${printAmount(l.monthly.remaining, "USD")} remaining)`)}`
|
|
1012
1259
|
);
|
|
1013
1260
|
}
|
|
1014
1261
|
printKeyValue(" Per-TX max", printAmount(l.perTransaction, "USD"));
|
|
@@ -1032,7 +1279,7 @@ function bar(pct, width = 15) {
|
|
|
1032
1279
|
}
|
|
1033
1280
|
|
|
1034
1281
|
// src/commands/alerts.ts
|
|
1035
|
-
import
|
|
1282
|
+
import chalk6 from "chalk";
|
|
1036
1283
|
async function alertsCommand(options = {}) {
|
|
1037
1284
|
const config = loadConfig();
|
|
1038
1285
|
if (!config.apiKey) {
|
|
@@ -1080,20 +1327,20 @@ async function alertsCommand(options = {}) {
|
|
|
1080
1327
|
function severityColor(severity) {
|
|
1081
1328
|
switch (severity.toUpperCase()) {
|
|
1082
1329
|
case "CRITICAL":
|
|
1083
|
-
return
|
|
1330
|
+
return chalk6.red.bold(severity);
|
|
1084
1331
|
case "HIGH":
|
|
1085
|
-
return
|
|
1332
|
+
return chalk6.red(severity);
|
|
1086
1333
|
case "MEDIUM":
|
|
1087
|
-
return
|
|
1334
|
+
return chalk6.yellow(severity);
|
|
1088
1335
|
case "LOW":
|
|
1089
|
-
return
|
|
1336
|
+
return chalk6.dim(severity);
|
|
1090
1337
|
default:
|
|
1091
1338
|
return severity;
|
|
1092
1339
|
}
|
|
1093
1340
|
}
|
|
1094
1341
|
|
|
1095
1342
|
// src/commands/config.ts
|
|
1096
|
-
import
|
|
1343
|
+
import chalk7 from "chalk";
|
|
1097
1344
|
async function configCommand(key, value) {
|
|
1098
1345
|
if (key && value) {
|
|
1099
1346
|
const global = loadGlobalConfig();
|
|
@@ -1118,20 +1365,20 @@ async function configCommand(key, value) {
|
|
|
1118
1365
|
printHeader("Configuration");
|
|
1119
1366
|
printKeyValue(
|
|
1120
1367
|
"API Key",
|
|
1121
|
-
config.apiKey ? `${config.apiKey.slice(0, 10)}...` :
|
|
1368
|
+
config.apiKey ? `${config.apiKey.slice(0, 10)}...` : chalk7.dim("not set")
|
|
1122
1369
|
);
|
|
1123
1370
|
printKeyValue("Base URL", config.baseUrl);
|
|
1124
|
-
printKeyValue("Agent ID", config.agentId ||
|
|
1125
|
-
printKeyValue("Chain", config.chainName ||
|
|
1126
|
-
printKeyValue("Chain ID", config.chainId ||
|
|
1127
|
-
printKeyValue("Currency", config.currency ||
|
|
1128
|
-
printKeyValue("Explorer", config.explorerUrl ||
|
|
1129
|
-
printKeyValue("Wallet ID", config.walletId ||
|
|
1130
|
-
printKeyValue("Wallet Address", config.walletAddress ||
|
|
1371
|
+
printKeyValue("Agent ID", config.agentId || chalk7.dim("not set"));
|
|
1372
|
+
printKeyValue("Chain", config.chainName || chalk7.dim("not set"));
|
|
1373
|
+
printKeyValue("Chain ID", config.chainId || chalk7.dim("not set"));
|
|
1374
|
+
printKeyValue("Currency", config.currency || chalk7.dim("not set"));
|
|
1375
|
+
printKeyValue("Explorer", config.explorerUrl || chalk7.dim("not set"));
|
|
1376
|
+
printKeyValue("Wallet ID", config.walletId || chalk7.dim("not set"));
|
|
1377
|
+
printKeyValue("Wallet Address", config.walletAddress || chalk7.dim("not set"));
|
|
1131
1378
|
printKeyValue("Testnet", config.testnet ? "Yes" : "No");
|
|
1132
1379
|
console.log("");
|
|
1133
|
-
console.log(
|
|
1134
|
-
console.log(
|
|
1380
|
+
console.log(chalk7.dim(" Config sources: ~/.conto/config.json + .env.local"));
|
|
1381
|
+
console.log(chalk7.dim(" Update with: conto config <key> <value>"));
|
|
1135
1382
|
console.log("");
|
|
1136
1383
|
}
|
|
1137
1384
|
|
|
@@ -1165,10 +1412,13 @@ async function mcpCommand() {
|
|
|
1165
1412
|
printError('Not configured. Run "npx create-conto-agent" or "conto login" first.');
|
|
1166
1413
|
process.exit(1);
|
|
1167
1414
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1415
|
+
console.error(`Starting Conto MCP server (${config.baseUrl})...`);
|
|
1416
|
+
console.error(`Using SDK key ${config.apiKey.slice(0, 16)}...`);
|
|
1417
|
+
console.error("Press Ctrl+C to stop.\n");
|
|
1418
|
+
const isWindows = process.platform === "win32";
|
|
1419
|
+
const child = spawn(isWindows ? "npx.cmd" : "npx", ["--yes", "@conto_finance/mcp-server"], {
|
|
1171
1420
|
stdio: "inherit",
|
|
1421
|
+
shell: isWindows,
|
|
1172
1422
|
env: {
|
|
1173
1423
|
...process.env,
|
|
1174
1424
|
CONTO_API_KEY: config.apiKey,
|
|
@@ -1176,8 +1426,8 @@ async function mcpCommand() {
|
|
|
1176
1426
|
}
|
|
1177
1427
|
});
|
|
1178
1428
|
child.on("error", (err) => {
|
|
1179
|
-
|
|
1180
|
-
|
|
1429
|
+
console.error(`Failed to start MCP server: ${err.message}`);
|
|
1430
|
+
console.error("Install it with: npm install -g @conto_finance/mcp-server");
|
|
1181
1431
|
process.exit(1);
|
|
1182
1432
|
});
|
|
1183
1433
|
child.on("exit", (code) => {
|
|
@@ -1187,22 +1437,32 @@ async function mcpCommand() {
|
|
|
1187
1437
|
|
|
1188
1438
|
// src/cli.ts
|
|
1189
1439
|
var program = new Command();
|
|
1190
|
-
program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version(
|
|
1440
|
+
program.name("conto").description("Conto CLI \u2014 Agentic Payments Control Center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (thisCommand) => {
|
|
1191
1441
|
const opts = thisCommand.opts();
|
|
1192
1442
|
if (opts.json) {
|
|
1193
1443
|
setJsonMode(true);
|
|
1194
1444
|
}
|
|
1195
1445
|
});
|
|
1196
|
-
program.command("init").description("Run the
|
|
1446
|
+
program.command("init").description("Run the setup wizard (interactive, or headless with --sandbox/--api-key)").option(
|
|
1447
|
+
"--chain <chain>",
|
|
1448
|
+
"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("--api-key <key>", "Existing organization API key (skips browser authentication)").option("--no-install", "Skip installing the conto CLI into the project").action(async (opts, command) => {
|
|
1450
|
+
if (command.parent?.opts()?.json) {
|
|
1451
|
+
setJsonMode(true);
|
|
1452
|
+
}
|
|
1197
1453
|
await runInit({
|
|
1198
1454
|
chain: opts.chain,
|
|
1199
1455
|
name: opts.name,
|
|
1200
1456
|
type: opts.type,
|
|
1201
1457
|
limit: opts.limit ? Number(opts.limit) : void 0,
|
|
1202
|
-
baseUrl: opts.baseUrl
|
|
1458
|
+
baseUrl: opts.baseUrl,
|
|
1459
|
+
install: opts.install,
|
|
1460
|
+
sandbox: opts.sandbox === true,
|
|
1461
|
+
apiKey: opts.apiKey
|
|
1203
1462
|
});
|
|
1204
1463
|
});
|
|
1205
1464
|
program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
|
|
1465
|
+
program.command("doctor").description("Diagnose setup: auth, key scopes, wallet, chain, balance, base URL").action(doctorCommand);
|
|
1206
1466
|
program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
|
|
1207
1467
|
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Policy check without executing").option("--wallet <walletId>", "Specific wallet to use").action(payCommand);
|
|
1208
1468
|
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);
|
|
@@ -1218,10 +1478,24 @@ program.command("alerts").description("List alerts").option("--unread", "Show on
|
|
|
1218
1478
|
program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
|
|
1219
1479
|
program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
|
|
1220
1480
|
program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1221
|
-
const { clearGlobalConfig } = await import("./config-
|
|
1481
|
+
const { clearGlobalConfig } = await import("./config-EKAEJVZR.js");
|
|
1222
1482
|
clearGlobalConfig();
|
|
1223
|
-
const { printSuccess: printSuccess3 } = await import("./output-
|
|
1483
|
+
const { printSuccess: printSuccess3 } = await import("./output-IN47X4NU.js");
|
|
1224
1484
|
printSuccess3("Logged out. Credentials cleared.");
|
|
1225
1485
|
});
|
|
1226
1486
|
program.command("mcp").description("Start MCP server for AI agent integration").action(mcpCommand);
|
|
1487
|
+
program.command("docs [topic]").description("Open Conto documentation (cli, policies, sdk, api)").action(async (topic) => {
|
|
1488
|
+
const open = (await import("open")).default;
|
|
1489
|
+
const urls = {
|
|
1490
|
+
cli: "https://conto.finance/docs/cli/quickstart",
|
|
1491
|
+
policies: "https://conto.finance/docs/cli/policies",
|
|
1492
|
+
commands: "https://conto.finance/docs/cli/commands",
|
|
1493
|
+
sdk: "https://conto.finance/docs/sdk/installation",
|
|
1494
|
+
api: "https://conto.finance/docs/api"
|
|
1495
|
+
};
|
|
1496
|
+
const url = urls[topic || "cli"] || urls.cli;
|
|
1497
|
+
const { printInfo: printInfo3 } = await import("./output-IN47X4NU.js");
|
|
1498
|
+
printInfo3(`Opening ${url}`);
|
|
1499
|
+
open(url);
|
|
1500
|
+
});
|
|
1227
1501
|
program.parse();
|