@caypo/canton-cli 0.1.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.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * caypo traffic — Show validator traffic balance.
3
+ */
4
+
5
+ import { Command } from "commander";
6
+ import ora from "ora";
7
+ import chalk from "chalk";
8
+ import { banner, keyValue, accent, warn } from "../helpers/format.js";
9
+ import { loadAgent } from "../helpers/load-agent.js";
10
+
11
+ export const trafficCommand = new Command("traffic")
12
+ .description("Show validator traffic balance")
13
+ .action(async () => {
14
+ banner();
15
+
16
+ const spinner = ora("Checking traffic balance...").start();
17
+ try {
18
+ const agent = await loadAgent();
19
+ const balance = await agent.traffic.trafficBalance();
20
+ const sufficient = balance.remaining > 1000;
21
+ spinner.stop();
22
+
23
+ console.log(chalk.gray(" Validator Traffic\n"));
24
+ keyValue("Total purchased", accent(String(balance.totalPurchased)));
25
+ keyValue("Consumed", String(balance.consumed));
26
+ keyValue("Remaining", sufficient ? accent(String(balance.remaining)) : warn(String(balance.remaining)));
27
+ keyValue("Status", sufficient ? "Sufficient" : warn("Low — consider purchasing more"));
28
+ console.log("");
29
+ } catch (err) {
30
+ spinner.fail(`Failed: ${(err as Error).message}`);
31
+ process.exit(1);
32
+ }
33
+ });
34
+
35
+ trafficCommand
36
+ .command("purchase")
37
+ .argument("<cc-amount>", "Canton Coin amount to burn for traffic")
38
+ .description("Purchase additional traffic by burning CC")
39
+ .action(async (ccAmount: string) => {
40
+ const spinner = ora(`Purchasing traffic with ${ccAmount} CC...`).start();
41
+ try {
42
+ const agent = await loadAgent();
43
+ await agent.traffic.purchaseTraffic(ccAmount);
44
+ spinner.succeed("Traffic purchased");
45
+ } catch (err) {
46
+ spinner.fail(`Purchase failed: ${(err as Error).message}`);
47
+ process.exit(1);
48
+ }
49
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * CLI formatting helpers.
3
+ */
4
+
5
+ import chalk from "chalk";
6
+
7
+ export const label = (text: string) => chalk.gray(text);
8
+ export const value = (text: string) => chalk.white.bold(text);
9
+ export const success = (text: string) => chalk.green(text);
10
+ export const warn = (text: string) => chalk.yellow(text);
11
+ export const fail = (text: string) => chalk.red(text);
12
+ export const accent = (text: string) => chalk.cyan(text);
13
+ export const dim = (text: string) => chalk.dim(text);
14
+
15
+ export function banner(): void {
16
+ console.log(chalk.cyan.bold("\n CAYPO") + chalk.gray(" — A bank account for AI agents on Canton Network\n"));
17
+ }
18
+
19
+ export function keyValue(key: string, val: string): void {
20
+ console.log(` ${label(key + ":")} ${value(val)}`);
21
+ }
22
+
23
+ export function errorMessage(msg: string): void {
24
+ console.log(`\n ${fail("✗")} ${msg}\n`);
25
+ }
26
+
27
+ export function successMessage(msg: string): void {
28
+ console.log(`\n ${success("✓")} ${msg}\n`);
29
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Load CantonAgent from config for CLI commands.
3
+ */
4
+
5
+ import { CantonAgent, loadConfig } from "@caypo/canton-sdk";
6
+ import { errorMessage } from "./format.js";
7
+
8
+ export async function loadAgent(): Promise<CantonAgent> {
9
+ try {
10
+ const config = await loadConfig();
11
+
12
+ if (!config.partyId) {
13
+ errorMessage("No wallet configured. Run 'caypo init' first.");
14
+ process.exit(1);
15
+ }
16
+
17
+ return CantonAgent.create({
18
+ ledgerUrl: config.ledgerUrl,
19
+ partyId: config.partyId,
20
+ userId: config.userId,
21
+ network: config.network,
22
+ token: process.env.CANTON_JWT ?? "",
23
+ });
24
+ } catch (err) {
25
+ errorMessage(`Failed to load agent: ${(err as Error).message}`);
26
+ process.exit(1);
27
+ }
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @caypo/canton-cli — CLI for Canton Network agent.
3
+ * Binary: caypo (aliases: canton-agent, ca)
4
+ */
5
+
6
+ import { Command } from "commander";
7
+ import { CANTON_SDK_VERSION } from "@caypo/canton-sdk";
8
+
9
+ import { initCommand } from "./commands/init.js";
10
+ import { balanceCommand } from "./commands/balance.js";
11
+ import { sendCommand } from "./commands/send.js";
12
+ import { payCommand } from "./commands/pay.js";
13
+ import { addressCommand } from "./commands/address.js";
14
+ import { safeguardsCommand } from "./commands/safeguards.js";
15
+ import { trafficCommand } from "./commands/traffic.js";
16
+ import { mcpCommand } from "./commands/mcp.js";
17
+
18
+ export const CANTON_CLI_VERSION = "0.1.0";
19
+
20
+ const program = new Command();
21
+
22
+ program
23
+ .name("caypo")
24
+ .description("CAYPO — A bank account for AI agents on Canton Network")
25
+ .version(CANTON_CLI_VERSION, "-v, --version")
26
+ .addCommand(initCommand)
27
+ .addCommand(balanceCommand)
28
+ .addCommand(sendCommand)
29
+ .addCommand(payCommand)
30
+ .addCommand(addressCommand)
31
+ .addCommand(safeguardsCommand)
32
+ .addCommand(trafficCommand)
33
+ .addCommand(mcpCommand);
34
+
35
+ program.parse(process.argv);
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src"]
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts"],
5
+ format: ["esm"],
6
+ dts: false,
7
+ clean: true,
8
+ sourcemap: true,
9
+ banner: {
10
+ js: "#!/usr/bin/env node",
11
+ },
12
+ });
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ passWithNoTests: true,
7
+ },
8
+ });