@conto_finance/create-conto-agent 0.3.1 → 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.
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  clearGlobalConfig,
3
+ ensureEnvLocalGitignored,
3
4
  isSensitiveConfigKey,
4
5
  loadConfig,
5
6
  loadGlobalConfig,
@@ -10,9 +11,10 @@ import {
10
11
  saveGlobalConfig,
11
12
  writeContoConfig,
12
13
  writeEnvLocal
13
- } from "./chunk-WMVGNUSL.js";
14
+ } from "./chunk-2U2MPMMD.js";
14
15
  export {
15
16
  clearGlobalConfig,
17
+ ensureEnvLocalGitignored,
16
18
  isSensitiveConfigKey,
17
19
  loadConfig,
18
20
  loadGlobalConfig,
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  runInit
3
- } from "./chunk-QN5FG53Q.js";
3
+ } from "./chunk-5OT7YKV4.js";
4
4
  import {
5
+ isJsonMode,
6
+ printJson,
5
7
  setJsonMode
6
8
  } from "./chunk-K4LBO234.js";
7
- import "./chunk-WMVGNUSL.js";
9
+ import "./chunk-2U2MPMMD.js";
8
10
 
9
11
  // src/index.ts
10
12
  var CLI_COMMANDS = /* @__PURE__ */ new Set([
@@ -14,6 +16,7 @@ var CLI_COMMANDS = /* @__PURE__ */ new Set([
14
16
  "pay",
15
17
  "transactions",
16
18
  "wallets",
19
+ "webhooks",
17
20
  "fund",
18
21
  "policies",
19
22
  "limits",
@@ -31,7 +34,8 @@ var CLI_COMMANDS = /* @__PURE__ */ new Set([
31
34
  "-V"
32
35
  ]);
33
36
  var args = process.argv.slice(2);
34
- if (args.length > 0 && CLI_COMMANDS.has(args[0])) {
37
+ var delegatedCommand = args[0] && CLI_COMMANDS.has(args[0]) || args[0] === "--json" && args[1] !== void 0 && CLI_COMMANDS.has(args[1]);
38
+ if (delegatedCommand) {
35
39
  await import("./cli.js");
36
40
  } else {
37
41
  const options = {};
@@ -57,13 +61,17 @@ if (args.length > 0 && CLI_COMMANDS.has(args[0])) {
57
61
  options.json = true;
58
62
  } else if (arg === "--no-install") {
59
63
  options.noInstall = true;
64
+ } else if (arg === "--confirm-mainnet") {
65
+ options.confirmMainnet = true;
60
66
  }
61
67
  }
62
68
  if (options.json) {
63
69
  setJsonMode(true);
64
70
  }
65
- if (options.noBrowser && !options.sandbox && !options.apiKey) {
66
- console.error("--no-browser requires either --sandbox or --api-key <org-api-key>.");
71
+ if (options.noBrowser && !options.sandbox && !options.apiKey && !process.env.CONTO_ORG_API_KEY) {
72
+ const error = "--no-browser requires --sandbox, --api-key <org-api-key>, or CONTO_ORG_API_KEY.";
73
+ if (isJsonMode()) printJson({ ok: false, error });
74
+ else console.error(error);
67
75
  process.exit(1);
68
76
  }
69
77
  runInit({
@@ -74,9 +82,12 @@ if (args.length > 0 && CLI_COMMANDS.has(args[0])) {
74
82
  baseUrl: options.baseUrl,
75
83
  install: options.noInstall ? false : void 0,
76
84
  sandbox: options.sandbox === true,
77
- apiKey: options.apiKey
85
+ apiKey: options.apiKey,
86
+ confirmMainnet: options.confirmMainnet === true
78
87
  }).catch((err) => {
79
- console.error("Fatal error:", err.message || err);
88
+ const error = err instanceof Error ? err.message : String(err);
89
+ if (isJsonMode()) printJson({ ok: false, error });
90
+ else console.error("Fatal error:", error);
80
91
  process.exit(1);
81
92
  });
82
93
  }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Pure helpers that turn prompt input into policy rule values the server
3
+ * evaluates correctly. Kept free of prompts and I/O so tests can call them.
4
+ */
5
+ type ValidationResult = {
6
+ ok: true;
7
+ value: string;
8
+ } | {
9
+ ok: false;
10
+ error: string;
11
+ };
12
+ /**
13
+ * TRUST_SCORE rules compare against counterparty trust scores stored on a
14
+ * 0.0 to 1.0 scale. A value such as 50 would never pass, so reject it with a
15
+ * message instead of converting it silently.
16
+ */
17
+ declare function parseTrustScoreInput(input: string): ValidationResult;
18
+ declare const VELOCITY_PERIODS: readonly ["HOUR", "DAY", "WEEK", "MONTH"];
19
+ type VelocityPeriod = (typeof VELOCITY_PERIODS)[number];
20
+ /**
21
+ * VELOCITY_LIMIT rules with a bare number are read by the server as an hourly
22
+ * dollar cap. A transaction-count limit must be sent as
23
+ * {"maxCount": n, "period": "HOUR" | "DAY" | "WEEK" | "MONTH"}.
24
+ */
25
+ declare function buildVelocityCountValue(input: string, period: string): ValidationResult;
26
+ interface PaymentRequestBody {
27
+ amount: number;
28
+ recipientAddress: string;
29
+ purpose?: string;
30
+ category?: string;
31
+ walletId?: string;
32
+ }
33
+ type PaymentValidation = {
34
+ ok: true;
35
+ body: PaymentRequestBody;
36
+ } | {
37
+ ok: false;
38
+ errors: string[];
39
+ };
40
+ /**
41
+ * Mirrors the request schema of POST /api/sdk/payments/request so a dry run
42
+ * catches the same input errors without contacting the server.
43
+ */
44
+ declare function validatePaymentRequest(input: {
45
+ address: string;
46
+ amount: string;
47
+ purpose?: string;
48
+ category?: string;
49
+ walletId?: string;
50
+ }): PaymentValidation;
51
+
52
+ export { type PaymentRequestBody, type PaymentValidation, VELOCITY_PERIODS, type ValidationResult, type VelocityPeriod, buildVelocityCountValue, parseTrustScoreInput, validatePaymentRequest };
@@ -0,0 +1,12 @@
1
+ import {
2
+ VELOCITY_PERIODS,
3
+ buildVelocityCountValue,
4
+ parseTrustScoreInput,
5
+ validatePaymentRequest
6
+ } from "../chunk-TJJY5NFH.js";
7
+ export {
8
+ VELOCITY_PERIODS,
9
+ buildVelocityCountValue,
10
+ parseTrustScoreInput,
11
+ validatePaymentRequest
12
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@conto_finance/create-conto-agent",
3
- "version": "0.3.1",
4
- "description": "CLI quickstart for Conto — Agentic Payments Control Center",
3
+ "version": "0.4.2",
4
+ "description": "Set up an AI agent with Conto spending controls",
5
5
  "bin": {
6
6
  "create-conto-agent": "bin/create-conto-agent.js",
7
7
  "conto": "bin/conto.js"
@@ -10,13 +10,21 @@
10
10
  "type": "module",
11
11
  "files": [
12
12
  "dist",
13
- "bin"
13
+ "bin",
14
+ "README.md",
15
+ "CHANGELOG.md"
14
16
  ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
15
20
  "scripts": {
16
- "build": "tsup src/index.ts src/cli.ts --format esm --dts --clean",
17
- "dev": "tsup src/index.ts src/cli.ts --format esm --dts --watch",
21
+ "build": "tsup src/index.ts src/cli.ts src/lib/rule-values.ts --format esm --dts --clean",
22
+ "dev": "tsup src/index.ts src/cli.ts src/lib/rule-values.ts --format esm --dts --watch",
18
23
  "lint": "tsc --noEmit",
19
- "test": "npm run build && node --test test/*.test.mjs"
24
+ "test": "npm run lint && npm run test:contract",
25
+ "test:contract": "npm run build && node --test test/*.test.mjs",
26
+ "verify:release": "node scripts/verify-release.mjs",
27
+ "prepublishOnly": "npm run verify:release && npm test"
20
28
  },
21
29
  "engines": {
22
30
  "node": ">=20.19.0"
@@ -35,12 +43,12 @@
35
43
  "license": "MIT",
36
44
  "repository": {
37
45
  "type": "git",
38
- "url": "https://github.com/kwattana/conto.git",
46
+ "url": "https://github.com/conto-finance/conto.git",
39
47
  "directory": "packages/cli"
40
48
  },
41
- "homepage": "https://conto.finance",
49
+ "homepage": "https://conto.finance/docs/cli/quickstart",
42
50
  "bugs": {
43
- "url": "https://github.com/kwattana/conto/issues"
51
+ "email": "support@conto.finance"
44
52
  },
45
53
  "dependencies": {
46
54
  "@clack/prompts": "^0.9.1",
@@ -1,127 +0,0 @@
1
- // src/lib/config.ts
2
- import fs from "fs";
3
- import path from "path";
4
- import os from "os";
5
- var CONTO_DIR = path.join(os.homedir(), ".conto");
6
- var CONFIG_FILE = path.join(CONTO_DIR, "config.json");
7
- var PRIVATE_DIR_MODE = 448;
8
- var PRIVATE_FILE_MODE = 384;
9
- var DEFAULT_VISIBLE_SECRET_CHARS = 10;
10
- var SENSITIVE_CONFIG_KEY_PATTERN = /(^|\.)(apiKey|orgApiKey)$/i;
11
- function ensureContoDir() {
12
- if (!fs.existsSync(CONTO_DIR)) {
13
- fs.mkdirSync(CONTO_DIR, { recursive: true, mode: PRIVATE_DIR_MODE });
14
- }
15
- fs.chmodSync(CONTO_DIR, PRIVATE_DIR_MODE);
16
- }
17
- function writePrivateFile(filePath, content) {
18
- fs.writeFileSync(filePath, content, { mode: PRIVATE_FILE_MODE });
19
- fs.chmodSync(filePath, PRIVATE_FILE_MODE);
20
- }
21
- function loadGlobalConfig() {
22
- try {
23
- if (fs.existsSync(CONFIG_FILE)) {
24
- const raw = fs.readFileSync(CONFIG_FILE, "utf-8");
25
- return JSON.parse(raw);
26
- }
27
- } catch {
28
- }
29
- return {};
30
- }
31
- function saveGlobalConfig(config) {
32
- ensureContoDir();
33
- writePrivateFile(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n");
34
- }
35
- function loadProjectEnv(dir) {
36
- const envPath = path.join(dir || process.cwd(), ".env.local");
37
- if (fs.existsSync(envPath)) {
38
- const content = fs.readFileSync(envPath, "utf-8");
39
- const result = {};
40
- for (const line of content.split("\n")) {
41
- const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
42
- if (match) result[match[1]] = match[2];
43
- }
44
- return result;
45
- }
46
- return {};
47
- }
48
- function loadProjectConfig(dir) {
49
- const configPath = path.join(dir || process.cwd(), "conto.config.json");
50
- try {
51
- if (fs.existsSync(configPath)) {
52
- const raw = fs.readFileSync(configPath, "utf-8");
53
- return JSON.parse(raw);
54
- }
55
- } catch {
56
- }
57
- return {};
58
- }
59
- function loadConfig() {
60
- const global = loadGlobalConfig();
61
- const project = loadProjectConfig();
62
- const env = loadProjectEnv();
63
- return {
64
- apiKey: env.CONTO_API_KEY || global.server?.apiKey,
65
- baseUrl: env.CONTO_BASE_URL || global.server?.baseUrl || "https://conto.finance",
66
- agentId: env.CONTO_AGENT_ID || global.agent?.id,
67
- chainId: env.CONTO_CHAIN_ID || global.network?.chainId,
68
- chainName: env.CONTO_CHAIN_NAME || global.network?.chain,
69
- currency: env.CONTO_CURRENCY || global.network?.currency,
70
- explorerUrl: env.CONTO_EXPLORER_URL || global.network?.explorerUrl,
71
- walletId: env.CONTO_WALLET_ID || global.wallet?.id,
72
- walletAddress: env.CONTO_WALLET_ADDRESS || global.wallet?.address,
73
- orgApiKey: global.server?.orgApiKey,
74
- // Sandbox metadata is project-scoped and ephemeral. Do not let a prior
75
- // sandbox stored in ~/.conto/config.json bleed into unrelated agents.
76
- sandboxExecution: env.CONTO_SANDBOX_EXECUTION || project.sandbox?.execution,
77
- sandboxExpiresAt: env.CONTO_SANDBOX_EXPIRES_AT || project.sandbox?.expiresAt,
78
- testnet: global.network?.testnet || project.network?.testnet || env.CONTO_CHAIN_ID === "42431"
79
- };
80
- }
81
- function writeEnvLocal(dir, entries) {
82
- const lines = entries.map(
83
- (entry) => typeof entry === "string" ? entry : `${entry[0]}=${entry[1]}`
84
- );
85
- const content = lines.join("\n") + "\n";
86
- writePrivateFile(path.join(dir, ".env.local"), content);
87
- }
88
- function writeContoConfig(dir, config) {
89
- fs.writeFileSync(path.join(dir, "conto.config.json"), JSON.stringify(config, null, 2) + "\n");
90
- }
91
- function clearGlobalConfig() {
92
- if (fs.existsSync(CONFIG_FILE)) {
93
- fs.unlinkSync(CONFIG_FILE);
94
- }
95
- }
96
- function isSensitiveConfigKey(key) {
97
- return SENSITIVE_CONFIG_KEY_PATTERN.test(key);
98
- }
99
- function maskSecret(value, visibleChars = DEFAULT_VISIBLE_SECRET_CHARS) {
100
- if (!value) return "";
101
- const prefixLength = Math.max(1, Math.min(visibleChars, value.length));
102
- return `${value.slice(0, prefixLength)}...`;
103
- }
104
- function missingSdkKeyMessage(config) {
105
- if (config.orgApiKey) {
106
- return [
107
- "Logged in with an organization key, but no agent SDK key is configured.",
108
- 'Run "npx create-conto-agent --api-key <org-api-key>" to create an agent,',
109
- "or set CONTO_API_KEY to an existing conto_agent_ key."
110
- ].join(" ");
111
- }
112
- return 'Not configured. Run "npx create-conto-agent" first, or set CONTO_API_KEY.';
113
- }
114
-
115
- export {
116
- loadGlobalConfig,
117
- saveGlobalConfig,
118
- loadProjectEnv,
119
- loadProjectConfig,
120
- loadConfig,
121
- writeEnvLocal,
122
- writeContoConfig,
123
- clearGlobalConfig,
124
- isSensitiveConfigKey,
125
- maskSecret,
126
- missingSdkKeyMessage
127
- };