@conto_finance/create-conto-agent 0.5.0 → 0.5.1

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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.1
4
+
5
+ - `conto pay` no longer invites a second payment after a failed call. Every run sends an idempotency
6
+ key and prints it, and prints the request ID before sending. A timeout, dropped connection,
7
+ non-JSON response, or server error now exits 6 with "outcome unknown" and the command to check the
8
+ payment. Retrying with `--idempotency-key <key>` returns the same request. Payment calls also
9
+ refuse redirects, so the SDK key never follows one.
10
+ - `conto pay status <requestId>` now works for a payment that needed no approval. It reports the
11
+ stored status and sends nothing. Earlier versions failed with "This payment does not need approval."
12
+ - `init` keeps other lines and comments in an existing `.env.local` and replaces only its `CONTO_*`
13
+ keys. It asks before replacing an existing `conto.config.json` or `example.mjs`. A headless run
14
+ keeps them and lists them under `keptFiles`, and `--overwrite` replaces them.
15
+ - `conto limits` shows no limit as `unlimited` instead of $0, and `--json` emits `null` for it.
16
+ Weekly and monthly are always present in `--json` now.
17
+ - `conto login` to a different server removes the agent key and the agent, wallet, and network
18
+ details saved for the old one, so that key is never sent to the new server. It also prints the
19
+ login link in case the browser does not open.
20
+ - Empty table cells and missing values print `-` instead of an em dash, and chain labels read
21
+ "Testnet: free pathUSD, no real funds" instead of using a dash.
22
+ - `conto channels add --type webhook --json` no longer prints a signing secret taken from
23
+ `CONTO_WEBHOOK_SECRET`. Earlier versions printed it to stdout, so rotate it if that output was
24
+ logged. A generated secret is still shown once.
25
+ - Credentials in a base URL, such as `https://user:password@host`, are dropped when the config loads,
26
+ so `conto config`, `conto status`, and error messages no longer print them.
27
+
3
28
  ## 0.5.0
4
29
 
5
30
  - `conto pay` handles payments that need approval. It prints the review link, opens it in a
package/README.md CHANGED
@@ -47,6 +47,15 @@ This sends one synthetic signed event to a loopback address. It creates no payme
47
47
  locally and prints the request it would send. It contacts nothing and does not evaluate policy. Use
48
48
  `npx @conto_finance/create-conto-agent limits` to see current limits.
49
49
 
50
+ Every `pay` run prints an idempotency key and, before sending, the request ID. Exit code 6 means the
51
+ outcome is unknown and the payment may have gone through. Do not run the same command again, because
52
+ that starts a new payment. Run `pay status <requestId>`, or, with no request ID yet, retry with
53
+ `--idempotency-key <key>`.
54
+
55
+ Setup keeps the other lines in an existing `.env.local` and replaces only its `CONTO_*` keys. It asks
56
+ before replacing an existing `conto.config.json` or `example.mjs`. A headless run keeps them unless
57
+ you pass `--overwrite`.
58
+
50
59
  ## Hand a sandbox to its owner
51
60
 
52
61
  ```bash
@@ -38,7 +38,7 @@ function printPending(text) {
38
38
  }
39
39
  function printKeyValue(key, value) {
40
40
  if (jsonMode) return;
41
- console.log(` ${chalk.dim(key + ":")} ${value ?? chalk.dim("\u2014")}`);
41
+ console.log(` ${chalk.dim(key + ":")} ${value ?? chalk.dim("-")}`);
42
42
  }
43
43
  function printTable(headers, rows, options) {
44
44
  if (jsonMode) return;
@@ -9,6 +9,8 @@ var PRIVATE_FILE_MODE = 384;
9
9
  var DEFAULT_VISIBLE_SECRET_CHARS = 10;
10
10
  var DEFAULT_BASE_URL = "https://conto.finance";
11
11
  var SENSITIVE_CONFIG_KEY_PATTERN = /(^|\.)(apiKey|orgApiKey)$/i;
12
+ var CONTO_ENV_ASSIGNMENT = /^\s*(?:export\s+)?CONTO_[A-Z0-9_]*\s*=/;
13
+ var CONTO_ENV_SECTION_COMMENT = /^# (?:Conto Agent Configuration.*|Generated by: npx @conto_finance\/create-conto-agent.*|SDK Authentication|Agent Identity|Network: .*|Wallet|Sandbox \(shown once, keep private\))$/;
12
14
  function ensureContoDir() {
13
15
  if (!fs.existsSync(CONTO_DIR)) {
14
16
  fs.mkdirSync(CONTO_DIR, { recursive: true, mode: PRIVATE_DIR_MODE });
@@ -57,10 +59,23 @@ function loadProjectConfig(dir) {
57
59
  }
58
60
  return {};
59
61
  }
62
+ function withoutUrlCredentials(baseUrl) {
63
+ try {
64
+ const parsed = new URL(baseUrl);
65
+ if (!parsed.username && !parsed.password) return baseUrl;
66
+ parsed.username = "";
67
+ parsed.password = "";
68
+ return parsed.toString().replace(/\/$/, "");
69
+ } catch {
70
+ return baseUrl;
71
+ }
72
+ }
60
73
  function loadConfig() {
61
74
  const global = loadGlobalConfig();
62
75
  const project = loadProjectConfig();
63
76
  const env = loadProjectEnv();
77
+ const agentId = process.env.CONTO_AGENT_ID || env.CONTO_AGENT_ID || project.agent?.id || global.agent?.id;
78
+ const projectSandbox = !project.agent?.id || project.agent.id === agentId ? project.sandbox : void 0;
64
79
  const chainId = process.env.CONTO_CHAIN_ID || env.CONTO_CHAIN_ID || project.network?.chainId || global.network?.chainId;
65
80
  const matchingNetwork = project.network?.chainId === chainId ? project.network : global.network?.chainId === chainId ? global.network : void 0;
66
81
  const explicitTestnet = process.env.CONTO_TESTNET || env.CONTO_TESTNET;
@@ -69,14 +84,16 @@ function loadConfig() {
69
84
  const hasGlobalCredential = !hasProcessCredential && !hasProjectCredential && Boolean(global.server?.apiKey || global.server?.orgApiKey);
70
85
  const apiKey = hasProcessCredential ? process.env.CONTO_API_KEY : hasProjectCredential ? env.CONTO_API_KEY : global.server?.apiKey;
71
86
  const orgApiKey = hasProcessCredential ? process.env.CONTO_ORG_API_KEY : hasProjectCredential ? env.CONTO_ORG_API_KEY : global.server?.orgApiKey;
72
- const baseUrl = process.env.CONTO_BASE_URL || (hasProcessCredential ? DEFAULT_BASE_URL : hasProjectCredential ? env.CONTO_BASE_URL || DEFAULT_BASE_URL : hasGlobalCredential ? global.server?.baseUrl || DEFAULT_BASE_URL : env.CONTO_BASE_URL || global.server?.baseUrl || DEFAULT_BASE_URL);
87
+ const baseUrl = withoutUrlCredentials(
88
+ process.env.CONTO_BASE_URL || (hasProcessCredential ? DEFAULT_BASE_URL : hasProjectCredential ? env.CONTO_BASE_URL || DEFAULT_BASE_URL : hasGlobalCredential ? global.server?.baseUrl || DEFAULT_BASE_URL : env.CONTO_BASE_URL || global.server?.baseUrl || DEFAULT_BASE_URL)
89
+ );
73
90
  return {
74
91
  // Secrets never come from conto.config.json: it is written world-readable
75
92
  // (0644) and is not gitignored. Read the API key only from the environment,
76
93
  // the gitignored .env.local, or the private global store (~/.conto, 0600).
77
94
  apiKey,
78
95
  baseUrl,
79
- agentId: process.env.CONTO_AGENT_ID || env.CONTO_AGENT_ID || project.agent?.id || global.agent?.id,
96
+ agentId,
80
97
  chainId,
81
98
  chainName: process.env.CONTO_CHAIN_NAME || env.CONTO_CHAIN_NAME || project.network?.chain || global.network?.chain,
82
99
  currency: process.env.CONTO_CURRENCY || env.CONTO_CURRENCY || project.network?.currency || global.network?.currency,
@@ -87,20 +104,39 @@ function loadConfig() {
87
104
  // world-readable conto.config.json. Env, .env.local, or the global store only.
88
105
  orgApiKey,
89
106
  orgApiKeyExpiresAt: (hasProcessCredential ? process.env.CONTO_ORG_API_KEY_EXPIRES_AT : hasProjectCredential ? env.CONTO_ORG_API_KEY_EXPIRES_AT : global.server?.orgApiKeyExpiresAt) || void 0,
90
- sandboxMode: process.env.CONTO_SANDBOX_MODE || env.CONTO_SANDBOX_MODE || project.sandbox?.mode,
107
+ sandboxMode: process.env.CONTO_SANDBOX_MODE || env.CONTO_SANDBOX_MODE || projectSandbox?.mode,
91
108
  // Sandbox metadata is project-scoped and ephemeral. Do not let a prior
92
109
  // sandbox stored in ~/.conto/config.json bleed into unrelated agents.
93
- sandboxExecution: process.env.CONTO_SANDBOX_EXECUTION || env.CONTO_SANDBOX_EXECUTION || project.sandbox?.execution,
94
- sandboxExpiresAt: process.env.CONTO_SANDBOX_EXPIRES_AT || env.CONTO_SANDBOX_EXPIRES_AT || project.sandbox?.expiresAt,
110
+ sandboxExecution: process.env.CONTO_SANDBOX_EXECUTION || env.CONTO_SANDBOX_EXECUTION || projectSandbox?.execution,
111
+ sandboxExpiresAt: process.env.CONTO_SANDBOX_EXPIRES_AT || env.CONTO_SANDBOX_EXPIRES_AT || projectSandbox?.expiresAt,
95
112
  testnet: explicitTestnet === "true" ? true : explicitTestnet === "false" ? false : matchingNetwork?.testnet ?? chainId === "42431"
96
113
  };
97
114
  }
115
+ function linesOutsideContoBlock(content) {
116
+ const lines = content.split("\n");
117
+ const kept = [];
118
+ let leadsIntoBlock = false;
119
+ for (let i = lines.length - 1; i >= 0; i--) {
120
+ const line = lines[i];
121
+ const isBlank = line.trim() === "";
122
+ if (CONTO_ENV_ASSIGNMENT.test(line) || leadsIntoBlock && (isBlank || CONTO_ENV_SECTION_COMMENT.test(line.trimEnd()))) {
123
+ leadsIntoBlock = true;
124
+ continue;
125
+ }
126
+ leadsIntoBlock = false;
127
+ kept.unshift(line);
128
+ }
129
+ while (kept.length > 0 && kept[kept.length - 1].trim() === "") kept.pop();
130
+ return kept;
131
+ }
98
132
  function writeEnvLocal(dir, entries) {
133
+ const envPath = path.join(dir, ".env.local");
134
+ const kept = fs.existsSync(envPath) ? linesOutsideContoBlock(fs.readFileSync(envPath, "utf8")) : [];
99
135
  const lines = entries.map(
100
136
  (entry) => typeof entry === "string" ? entry : `${entry[0]}=${entry[1]}`
101
137
  );
102
- const content = lines.join("\n") + "\n";
103
- writePrivateFile(path.join(dir, ".env.local"), content);
138
+ const content = [...kept, ...kept.length > 0 ? [""] : [], ...lines].join("\n") + "\n";
139
+ writePrivateFile(envPath, content);
104
140
  }
105
141
  function ensureEnvLocalGitignored(dir) {
106
142
  const gitignorePath = path.join(dir, ".gitignore");
@@ -138,9 +174,6 @@ function ensureContoDirGitignored(dir) {
138
174
  `
139
175
  );
140
176
  }
141
- function writeContoConfig(dir, config) {
142
- fs.writeFileSync(path.join(dir, "conto.config.json"), JSON.stringify(config, null, 2) + "\n");
143
- }
144
177
  function clearGlobalConfig() {
145
178
  if (fs.existsSync(CONFIG_FILE)) {
146
179
  fs.unlinkSync(CONFIG_FILE);
@@ -176,7 +209,6 @@ export {
176
209
  SANDBOX_SETUP_ENV_FILE,
177
210
  writeSandboxSetupEnv,
178
211
  ensureContoDirGitignored,
179
- writeContoConfig,
180
212
  clearGlobalConfig,
181
213
  isSensitiveConfigKey,
182
214
  maskSecret,