@conto_finance/create-conto-agent 0.8.0 → 0.9.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 +47 -0
- package/README.md +16 -6
- package/dist/{chunk-HGEZBNZB.js → chunk-6PK4I5VO.js} +149 -33
- package/dist/chunk-D6JPJHU4.js +45 -0
- package/dist/{chunk-RQ4PUBL7.js → chunk-F72EK2TO.js} +12 -0
- package/dist/{chunk-2M2WVAJI.js → chunk-PUHGIKBB.js} +19 -1
- package/dist/cli.js +240 -80
- package/dist/{config-MACPIPYV.js → config-2C6Q4NEJ.js} +3 -1
- package/dist/index.js +6 -34
- package/dist/lib/cli-commands.d.ts +11 -0
- package/dist/lib/cli-commands.js +8 -0
- package/dist/lib/rule-values.d.ts +9 -1
- package/dist/lib/rule-values.js +5 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
- `conto login` and the `conto init` sign-in now collect the organization key from Conto instead
|
|
6
|
+
of waiting for the browser to send it to the CLI. Current Chrome can hold that send behind a
|
|
7
|
+
local network permission, so the page spun on "Connecting to CLI..." and the login timed out.
|
|
8
|
+
The CLI prints a code, and the browser shows the same one next to Connect CLI. Older Conto
|
|
9
|
+
servers still send the key from the browser, and the CLI accepts it as before.
|
|
10
|
+
- `conto alerts` works again. Without `--json` it failed as soon as an alert existed, and `--unread`
|
|
11
|
+
and `--active` always failed with "Invalid status filter". The table now shows each alert's ID,
|
|
12
|
+
date, severity, status, and title, and `--unread` and `--active` list open alerts.
|
|
13
|
+
- `conto config` no longer changes `server.baseUrl`, because the saved keys would go to the new
|
|
14
|
+
server. It tells you to run `conto login --base-url <url>`, which signs in to that server and
|
|
15
|
+
removes the agent key saved for the old one.
|
|
16
|
+
- Setup with `--api-key` or `CONTO_ORG_API_KEY` uses that organization key for the run and no longer
|
|
17
|
+
saves it in `~/.conto/config.json`, where other projects of the same organization on the machine
|
|
18
|
+
would use it. In a terminal, setup asks first, and the default is No. The output says when the key
|
|
19
|
+
was not saved, and the `--json` result has `credentials.orgApiKeySaved`. A key from the browser
|
|
20
|
+
sign-in or `conto login` is saved as before, and setup keeps one already saved for the same server.
|
|
21
|
+
- `--json` runs never prompt, even in a terminal. Setup uses the headless defaults for flags you
|
|
22
|
+
leave out and needs `--api-key`, `CONTO_ORG_API_KEY`, or `--sandbox`. `conto policies create`,
|
|
23
|
+
`update`, `delete`, and `add-rule` prompt for input, so under `--json` they now stop with an error.
|
|
24
|
+
- `conto agents unfreeze` no longer asks Conto to keep the agent's wallets frozen unless you pass
|
|
25
|
+
`--wallets`. With neither flag, Conto unfreezes the wallets the agent's freeze froze, leaving any
|
|
26
|
+
wallet a person froze or another frozen agent still holds. `--wallets` also does it for a freeze
|
|
27
|
+
recorded before Conto kept that list, and the new `--keep-wallets` leaves every wallet frozen.
|
|
28
|
+
|
|
29
|
+
## 0.9.0
|
|
30
|
+
|
|
31
|
+
- `conto pay --json` now exits 1 when a policy denies the payment, as it already did without
|
|
32
|
+
`--json`. Earlier versions exited 0, so a script that checks the exit code could read a denied
|
|
33
|
+
payment as sent. The JSON output is the same.
|
|
34
|
+
- Inside a project the CLI set up, commands that need the organization key, such as `conto teams`,
|
|
35
|
+
`conto policies all`, and `conto spending export`, now use the key that setup or `conto login`
|
|
36
|
+
saved in `~/.conto/config.json` when the project's `.env.local` has no `CONTO_ORG_API_KEY`.
|
|
37
|
+
First the CLI checks with Conto that this key and the project's agent key belong to the same
|
|
38
|
+
organization, and it uses the key only with the server it was saved for. If the organizations
|
|
39
|
+
differ or the check can't finish, the command stops and says what to do. A `CONTO_ORG_API_KEY`
|
|
40
|
+
in the environment or in `.env.local` is used as before.
|
|
41
|
+
- `npx @conto_finance/create-conto-agent teams`, `budgets`, `tasks`, `purchases`, and `spending` now
|
|
42
|
+
run those commands. Earlier versions started the setup wizard instead.
|
|
43
|
+
- `conto webhooks test` now sends `X-Conto-Signature-V2`, `X-Conto-Delivery-Id`, and `deliveryId`
|
|
44
|
+
in the body, like a real delivery, so a handler that checks the v2 signature accepts it. The
|
|
45
|
+
event's `data.settlementMode` is `test`.
|
|
46
|
+
- When you add a rule that blocks what it matches, such as `BLOCKED_COUNTERPARTIES` or
|
|
47
|
+
`BLACKOUT_PERIOD`, the action picker starts on Deny and no longer offers Allow, which Conto now
|
|
48
|
+
refuses for these rules.
|
|
49
|
+
|
|
3
50
|
## 0.8.0
|
|
4
51
|
|
|
5
52
|
- With the key from `conto login`, `conto teams` changes now go to owner review instead of failing.
|
package/README.md
CHANGED
|
@@ -24,7 +24,9 @@ See [configure controls](https://conto.finance/docs/quickstart/agent-sandbox#con
|
|
|
24
24
|
|
|
25
25
|
Run the wizard without `--sandbox` to sign in and provision a managed wallet. Choose Tempo
|
|
26
26
|
Testnet for free faucet tokens and actual onchain test transfers. For headless organization
|
|
27
|
-
setup, set `CONTO_ORG_API_KEY` or pass `--api-key`.
|
|
27
|
+
setup, set `CONTO_ORG_API_KEY` or pass `--api-key`. Setup uses that key for the run and does not
|
|
28
|
+
save it in `~/.conto/config.json` unless you agree when it asks in a terminal. A `--json` run never
|
|
29
|
+
prompts.
|
|
28
30
|
|
|
29
31
|
A mainnet setup asks you to confirm the network (pass `--confirm-mainnet` when headless) and
|
|
30
32
|
creates the agent in the `PROD` environment, because only `PROD` agents can pay from mainnet
|
|
@@ -34,6 +36,12 @@ Inside a CLI-created project, `npx conto <command>` is a shorter form of the sam
|
|
|
34
36
|
one, bare `npx conto` fetches an unrelated npm package, so use the full package name.
|
|
35
37
|
`--help`, `--version`, and `--json` work without an interactive terminal.
|
|
36
38
|
|
|
39
|
+
Commands that need the organization key, such as `conto teams` and `conto policies all`, use
|
|
40
|
+
`CONTO_ORG_API_KEY` from the environment or `.env.local`. When a project has none, they use the key
|
|
41
|
+
that setup or `conto login` saved in `~/.conto/config.json`, but only with the server it was saved
|
|
42
|
+
for and only after Conto confirms it belongs to the same organization as the project's agent key.
|
|
43
|
+
Otherwise the command stops and says why. A key in the environment replaces both keys in the files.
|
|
44
|
+
|
|
37
45
|
Test a local webhook handler with the same development secret configured in that handler:
|
|
38
46
|
|
|
39
47
|
```bash
|
|
@@ -41,16 +49,18 @@ export CONTO_WEBHOOK_SECRET="your-local-development-secret"
|
|
|
41
49
|
npx @conto_finance/create-conto-agent webhooks test http://localhost:8080/webhooks/conto --json
|
|
42
50
|
```
|
|
43
51
|
|
|
44
|
-
This sends one synthetic
|
|
52
|
+
This sends one synthetic event to a loopback address, signed like a real delivery with both
|
|
53
|
+
`X-Conto-Signature` and `X-Conto-Signature-V2` and an `X-Conto-Delivery-Id`. It creates no payment
|
|
54
|
+
and requires no API key.
|
|
45
55
|
|
|
46
56
|
`npx @conto_finance/create-conto-agent pay <address> <amount> --dry-run` validates the payment
|
|
47
57
|
locally and prints the request it would send. It contacts nothing and does not evaluate policy. Use
|
|
48
58
|
`npx @conto_finance/create-conto-agent limits` to see current limits.
|
|
49
59
|
|
|
50
|
-
Every `pay` run prints an idempotency key and, before sending, the request ID.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
`--idempotency-key <key>`.
|
|
60
|
+
Every `pay` run prints an idempotency key and, before sending, the request ID. A policy denial exits
|
|
61
|
+
1, with or without `--json`. Exit code 6 means the outcome is unknown and the payment may have gone
|
|
62
|
+
through. Do not run the same command again, because that starts a new payment. Run
|
|
63
|
+
`pay status <requestId>`, or, with no request ID yet, retry with `--idempotency-key <key>`.
|
|
54
64
|
|
|
55
65
|
Setup keeps the other lines in an existing `.env.local` and replaces only its `CONTO_*` keys. It asks
|
|
56
66
|
before replacing an existing `conto.config.json` or `example.mjs`. A headless run keeps them unless
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureContoDirGitignored,
|
|
3
3
|
ensureEnvLocalGitignored,
|
|
4
|
+
loadGlobalConfig,
|
|
4
5
|
loadProjectEnv,
|
|
5
6
|
saveGlobalConfig,
|
|
6
7
|
writeEnvLocal,
|
|
7
8
|
writeSandboxSetupEnv
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-F72EK2TO.js";
|
|
9
10
|
import {
|
|
10
11
|
isJsonMode,
|
|
11
12
|
printBanner,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
// package.json
|
|
22
23
|
var package_default = {
|
|
23
24
|
name: "@conto_finance/create-conto-agent",
|
|
24
|
-
version: "0.
|
|
25
|
+
version: "0.9.1",
|
|
25
26
|
description: "Set up an AI agent with Conto spending controls",
|
|
26
27
|
bin: {
|
|
27
28
|
"create-conto-agent": "bin/create-conto-agent.js",
|
|
@@ -39,8 +40,8 @@ var package_default = {
|
|
|
39
40
|
access: "public"
|
|
40
41
|
},
|
|
41
42
|
scripts: {
|
|
42
|
-
build: "tsup src/index.ts src/cli.ts src/lib/rule-values.ts --format esm --dts --clean",
|
|
43
|
-
dev: "tsup src/index.ts src/cli.ts src/lib/rule-values.ts --format esm --dts --watch",
|
|
43
|
+
build: "tsup src/index.ts src/cli.ts src/lib/rule-values.ts src/lib/cli-commands.ts --format esm --dts --clean",
|
|
44
|
+
dev: "tsup src/index.ts src/cli.ts src/lib/rule-values.ts src/lib/cli-commands.ts --format esm --dts --watch",
|
|
44
45
|
lint: "tsc --noEmit",
|
|
45
46
|
test: "npm run lint && npm run test:contract",
|
|
46
47
|
"test:contract": "npm run build && node --test test/*.test.mjs",
|
|
@@ -364,7 +365,7 @@ function chainHint(chain) {
|
|
|
364
365
|
|
|
365
366
|
// src/lib/auth.ts
|
|
366
367
|
import http from "http";
|
|
367
|
-
import { randomBytes } from "crypto";
|
|
368
|
+
import { createHash, randomBytes } from "crypto";
|
|
368
369
|
import open from "open";
|
|
369
370
|
var CALLBACK_BODY_LIMIT_BYTES = 16 * 1024;
|
|
370
371
|
async function readRequestBody(req) {
|
|
@@ -404,16 +405,93 @@ async function parseCallbackPayload(req) {
|
|
|
404
405
|
returnedState: params.get("state")
|
|
405
406
|
};
|
|
406
407
|
}
|
|
407
|
-
|
|
408
|
-
|
|
408
|
+
var PICKUP_POLL_MS = 2e3;
|
|
409
|
+
var PAIRING_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ";
|
|
410
|
+
var PICKUP_FINAL_CODES = /* @__PURE__ */ new Set([
|
|
411
|
+
"CLI_AUTH_REFUSED",
|
|
412
|
+
"EXPIRED",
|
|
413
|
+
"ALREADY_PICKED_UP",
|
|
414
|
+
"INVALID_PICKUP_CODE"
|
|
415
|
+
]);
|
|
416
|
+
function pairingCode(pickupHash) {
|
|
417
|
+
const digest = createHash("sha256").update(`conto-cli-pairing:${pickupHash}`).digest();
|
|
418
|
+
let code = "";
|
|
419
|
+
for (let i = 0; i < 8; i += 1) code += PAIRING_ALPHABET[digest[i] % PAIRING_ALPHABET.length];
|
|
420
|
+
return `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
421
|
+
}
|
|
422
|
+
async function pollPickup(baseUrl, code, state) {
|
|
423
|
+
let response;
|
|
424
|
+
try {
|
|
425
|
+
response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/cli-auth/pickup`, {
|
|
426
|
+
method: "POST",
|
|
427
|
+
headers: { "Content-Type": "application/json" },
|
|
428
|
+
body: JSON.stringify({ code, state }),
|
|
429
|
+
redirect: "error"
|
|
430
|
+
});
|
|
431
|
+
} catch {
|
|
432
|
+
return { done: false };
|
|
433
|
+
}
|
|
434
|
+
const body = await response.json().catch(() => null);
|
|
435
|
+
if (response.status === 200 && body?.status === "DELIVERED" && typeof body.token === "string") {
|
|
436
|
+
if (body.state !== state) return { done: true, error: "Invalid authentication state" };
|
|
437
|
+
return {
|
|
438
|
+
done: true,
|
|
439
|
+
result: {
|
|
440
|
+
orgApiKey: body.token,
|
|
441
|
+
organizationName: typeof body.organizationName === "string" ? body.organizationName : "",
|
|
442
|
+
expiresAt: typeof body.expiresAt === "string" ? body.expiresAt : ""
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
if (typeof body?.code === "string" && PICKUP_FINAL_CODES.has(body.code)) {
|
|
447
|
+
return {
|
|
448
|
+
done: true,
|
|
449
|
+
error: typeof body.error === "string" ? body.error : "Authentication failed"
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
const retry = response.status === 202 || response.status === 429 || response.status >= 500;
|
|
453
|
+
return { done: false, stop: !retry };
|
|
454
|
+
}
|
|
455
|
+
async function browserAuth(baseUrl, onAuthUrl, onPairingCode) {
|
|
456
|
+
return new Promise((rawResolve, rawReject) => {
|
|
409
457
|
const state = randomBytes(16).toString("hex");
|
|
458
|
+
const pickupCode = `conto_clipickup_${randomBytes(32).toString("hex")}`;
|
|
459
|
+
const pickupHash = createHash("sha256").update(pickupCode).digest("hex");
|
|
460
|
+
let settled = false;
|
|
461
|
+
let pollTimer;
|
|
462
|
+
const finish = () => {
|
|
463
|
+
settled = true;
|
|
464
|
+
clearTimeout(timeout);
|
|
465
|
+
clearTimeout(pollTimer);
|
|
466
|
+
server.close();
|
|
467
|
+
};
|
|
468
|
+
const resolve = (result) => {
|
|
469
|
+
if (settled) return;
|
|
470
|
+
finish();
|
|
471
|
+
rawResolve(result);
|
|
472
|
+
};
|
|
473
|
+
const reject = (error) => {
|
|
474
|
+
if (settled) return;
|
|
475
|
+
finish();
|
|
476
|
+
rawReject(error);
|
|
477
|
+
};
|
|
410
478
|
const timeout = setTimeout(
|
|
411
479
|
() => {
|
|
412
|
-
server.close();
|
|
413
480
|
reject(new Error("Authentication timed out. Please try again."));
|
|
414
481
|
},
|
|
415
482
|
5 * 60 * 1e3
|
|
416
483
|
);
|
|
484
|
+
const poll = async () => {
|
|
485
|
+
if (settled) return;
|
|
486
|
+
const outcome = await pollPickup(baseUrl, pickupCode, state);
|
|
487
|
+
if (settled) return;
|
|
488
|
+
if (outcome.done) {
|
|
489
|
+
if ("result" in outcome) resolve(outcome.result);
|
|
490
|
+
else reject(new Error(`Authentication failed: ${outcome.error}`));
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (!outcome.stop) pollTimer = setTimeout(() => void poll(), PICKUP_POLL_MS);
|
|
494
|
+
};
|
|
417
495
|
const server = http.createServer((req, res) => {
|
|
418
496
|
void (async () => {
|
|
419
497
|
const url = new URL(req.url || "/", "http://127.0.0.1");
|
|
@@ -436,44 +514,37 @@ async function browserAuth(baseUrl, onAuthUrl) {
|
|
|
436
514
|
if (error) {
|
|
437
515
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
438
516
|
res.end(getErrorHtml(error));
|
|
439
|
-
clearTimeout(timeout);
|
|
440
|
-
server.close();
|
|
441
517
|
reject(new Error(`Authentication failed: ${error}`));
|
|
442
518
|
return;
|
|
443
519
|
}
|
|
444
520
|
if (!orgApiKey) {
|
|
445
521
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
446
522
|
res.end(getErrorHtml("No token received"));
|
|
447
|
-
clearTimeout(timeout);
|
|
448
|
-
server.close();
|
|
449
523
|
reject(new Error("No authentication token received"));
|
|
450
524
|
return;
|
|
451
525
|
}
|
|
452
526
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
453
527
|
res.end(getSuccessHtml());
|
|
454
|
-
clearTimeout(timeout);
|
|
455
|
-
server.close();
|
|
456
528
|
resolve({ orgApiKey, organizationName, expiresAt });
|
|
457
529
|
})().catch((error) => {
|
|
458
530
|
res.writeHead(500, { "Content-Type": "text/html" });
|
|
459
531
|
res.end(getErrorHtml("Authentication callback failed"));
|
|
460
|
-
clearTimeout(timeout);
|
|
461
|
-
server.close();
|
|
462
532
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
463
533
|
});
|
|
464
534
|
});
|
|
465
535
|
server.listen(0, "127.0.0.1", () => {
|
|
466
536
|
const address = server.address();
|
|
467
537
|
if (!address || typeof address === "string") {
|
|
468
|
-
clearTimeout(timeout);
|
|
469
538
|
reject(new Error("Failed to start local auth server"));
|
|
470
539
|
return;
|
|
471
540
|
}
|
|
472
541
|
const callbackUrl = `http://127.0.0.1:${address.port}/callback`;
|
|
473
|
-
const authUrl = `${baseUrl}/cli-auth?callback=${encodeURIComponent(callbackUrl)}&state=${encodeURIComponent(state)}`;
|
|
542
|
+
const authUrl = `${baseUrl}/cli-auth?pickup=${pickupHash}&callback=${encodeURIComponent(callbackUrl)}&state=${encodeURIComponent(state)}`;
|
|
474
543
|
onAuthUrl?.(authUrl);
|
|
544
|
+
onPairingCode?.(pairingCode(pickupHash));
|
|
475
545
|
open(authUrl).catch(() => {
|
|
476
546
|
});
|
|
547
|
+
pollTimer = setTimeout(() => void poll(), PICKUP_POLL_MS);
|
|
477
548
|
});
|
|
478
549
|
});
|
|
479
550
|
}
|
|
@@ -707,10 +778,13 @@ var ApiClient = class {
|
|
|
707
778
|
this.apiKey = options.apiKey;
|
|
708
779
|
this.orgApiKey = options.orgApiKey;
|
|
709
780
|
}
|
|
781
|
+
async orgToken() {
|
|
782
|
+
return typeof this.orgApiKey === "function" ? this.orgApiKey() : this.orgApiKey;
|
|
783
|
+
}
|
|
710
784
|
async request(method, path3, options) {
|
|
711
785
|
const url = `${this.baseUrl}${path3}`;
|
|
712
786
|
const authType = options?.auth || "sdk";
|
|
713
|
-
const token = authType === "org" ? this.
|
|
787
|
+
const token = authType === "org" ? await this.orgToken() : this.apiKey;
|
|
714
788
|
const headers = {
|
|
715
789
|
...options?.headers,
|
|
716
790
|
...options?.body instanceof FormData ? {} : { "Content-Type": "application/json" },
|
|
@@ -802,7 +876,7 @@ var ApiClient = class {
|
|
|
802
876
|
return response.data;
|
|
803
877
|
}
|
|
804
878
|
async spendingDownload(path3, owner = false) {
|
|
805
|
-
const token = owner ? this.
|
|
879
|
+
const token = owner ? await this.orgToken() : this.apiKey;
|
|
806
880
|
const response = await fetch(
|
|
807
881
|
`${this.baseUrl}/api/${owner ? "spending" : path3.startsWith("purchases") ? "sdk/spending" : "sdk"}/${path3}`,
|
|
808
882
|
{
|
|
@@ -1267,7 +1341,7 @@ function reviewAccessFor(baseUrl, orgApiKey) {
|
|
|
1267
1341
|
// src/lib/project-state.ts
|
|
1268
1342
|
import fs from "fs";
|
|
1269
1343
|
import path from "path";
|
|
1270
|
-
import { createHash, randomBytes as randomBytes2 } from "crypto";
|
|
1344
|
+
import { createHash as createHash2, randomBytes as randomBytes2 } from "crypto";
|
|
1271
1345
|
var PROJECT_STATE_DIR = ".conto";
|
|
1272
1346
|
var PRIVATE_DIR_MODE = 448;
|
|
1273
1347
|
var PRIVATE_FILE_MODE = 384;
|
|
@@ -1326,11 +1400,11 @@ function removeProjectStateFile(cwd, fileName) {
|
|
|
1326
1400
|
}
|
|
1327
1401
|
}
|
|
1328
1402
|
function fingerprintSecret(secret) {
|
|
1329
|
-
return `sha256:${
|
|
1403
|
+
return `sha256:${createHash2("sha256").update(secret).digest("hex").slice(0, 16)}`;
|
|
1330
1404
|
}
|
|
1331
1405
|
|
|
1332
1406
|
// src/lib/init-checkpoint.ts
|
|
1333
|
-
import { createHash as
|
|
1407
|
+
import { createHash as createHash3, randomBytes as randomBytes3 } from "crypto";
|
|
1334
1408
|
var INIT_CHECKPOINT_NAME = "init-checkpoint.json";
|
|
1335
1409
|
var INIT_CHECKPOINT_FILE = projectStateFile(INIT_CHECKPOINT_NAME);
|
|
1336
1410
|
var STEP_ORDER = ["wallet", "faucet", "agent", "walletLink", "policy", "sdkKey"];
|
|
@@ -1351,7 +1425,7 @@ function canonicalJson(value) {
|
|
|
1351
1425
|
return JSON.stringify(value);
|
|
1352
1426
|
}
|
|
1353
1427
|
function configurationHash(request) {
|
|
1354
|
-
return `sha256:${
|
|
1428
|
+
return `sha256:${createHash3("sha256").update(canonicalJson(request)).digest("hex")}`;
|
|
1355
1429
|
}
|
|
1356
1430
|
function newOperationId() {
|
|
1357
1431
|
return randomBytes3(8).toString("hex");
|
|
@@ -2397,7 +2471,9 @@ function resumeCommand(baseUrl, options) {
|
|
|
2397
2471
|
...isJsonMode() ? ["--json"] : []
|
|
2398
2472
|
].join(" ");
|
|
2399
2473
|
}
|
|
2400
|
-
|
|
2474
|
+
function resumeCredentialHint() {
|
|
2475
|
+
return isJsonMode() ? "Resume with the same organization: pass --api-key or set CONTO_ORG_API_KEY, or run it in a terminal without --json to sign in with the browser." : "Resume with the same organization: pass --api-key or set CONTO_ORG_API_KEY, or run it in a terminal to sign in with the browser.";
|
|
2476
|
+
}
|
|
2401
2477
|
function refuse(message, details) {
|
|
2402
2478
|
failInit(message, { status: "refused", ...details }, INIT_EXIT_CODES.refused);
|
|
2403
2479
|
}
|
|
@@ -2439,6 +2515,22 @@ function storedSdkKeyFor(cwd, baseUrl, agentId) {
|
|
|
2439
2515
|
return void 0;
|
|
2440
2516
|
}
|
|
2441
2517
|
}
|
|
2518
|
+
var ORG_KEY_NOT_SAVED = 'The organization key was used for this setup only. It was not saved in ~/.conto/config.json. For commands that need it, set CONTO_ORG_API_KEY or run "conto login".';
|
|
2519
|
+
function isSameServer(a, b) {
|
|
2520
|
+
try {
|
|
2521
|
+
return normalizeBaseUrl(a) === normalizeBaseUrl(b);
|
|
2522
|
+
} catch {
|
|
2523
|
+
return false;
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
function orgKeySavedFor(baseUrl) {
|
|
2527
|
+
const server = loadGlobalConfig().server;
|
|
2528
|
+
if (!server?.orgApiKey || !isSameServer(server.baseUrl || DEFAULT_BASE_URL, baseUrl)) return {};
|
|
2529
|
+
return { orgApiKey: server.orgApiKey, orgApiKeyExpiresAt: server.orgApiKeyExpiresAt };
|
|
2530
|
+
}
|
|
2531
|
+
function isSavedOrgApiKey(orgApiKey, baseUrl) {
|
|
2532
|
+
return orgKeySavedFor(baseUrl).orgApiKey === orgApiKey;
|
|
2533
|
+
}
|
|
2442
2534
|
function organizationBindingProblem(checkpoint, credential) {
|
|
2443
2535
|
const organization = checkpoint.binding.organization;
|
|
2444
2536
|
if (organization.anchor) return null;
|
|
@@ -2451,7 +2543,7 @@ function organizationBindingProblem(checkpoint, credential) {
|
|
|
2451
2543
|
}
|
|
2452
2544
|
async function runOrganizationInit(options) {
|
|
2453
2545
|
const cwd = process.cwd();
|
|
2454
|
-
const interactive2 = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
2546
|
+
const interactive2 = Boolean(process.stdin.isTTY && process.stdout.isTTY) && !isJsonMode();
|
|
2455
2547
|
const providedOrgApiKey = options.apiKey || process.env.CONTO_ORG_API_KEY;
|
|
2456
2548
|
if (options.resume && options.restart) {
|
|
2457
2549
|
refuse("Use --resume or --restart, not both.", { code: "INVALID_OPTIONS" });
|
|
@@ -2496,9 +2588,9 @@ async function runOrganizationInit(options) {
|
|
|
2496
2588
|
if (!interactive2 && !providedOrgApiKey) {
|
|
2497
2589
|
failInit(
|
|
2498
2590
|
[
|
|
2499
|
-
resumeFrom ? "Resuming setup without an interactive terminal needs an organization API key." : "create-conto-agent needs an interactive terminal for the setup wizard.",
|
|
2591
|
+
isJsonMode() ? "A --json run does not prompt or open a browser, so it needs an organization API key." : resumeFrom ? "Resuming setup without an interactive terminal needs an organization API key." : "create-conto-agent needs an interactive terminal for the setup wizard.",
|
|
2500
2592
|
"Headless options: --sandbox, or --api-key <org-api-key>.",
|
|
2501
|
-
"Add --json for machine-readable output."
|
|
2593
|
+
...isJsonMode() ? [] : ["Add --json for machine-readable output."]
|
|
2502
2594
|
].join(" "),
|
|
2503
2595
|
{ headlessOptions: ["--sandbox", "--api-key <org-api-key>"] }
|
|
2504
2596
|
);
|
|
@@ -2623,13 +2715,30 @@ async function runOrganizationInit(options) {
|
|
|
2623
2715
|
let orgApiKey;
|
|
2624
2716
|
let orgApiKeyExpiresAt;
|
|
2625
2717
|
let organizationName;
|
|
2718
|
+
let saveOrgApiKey = true;
|
|
2626
2719
|
if (providedOrgApiKey) {
|
|
2627
2720
|
orgApiKey = providedOrgApiKey;
|
|
2628
2721
|
printSuccess("Using provided organization API key");
|
|
2722
|
+
saveOrgApiKey = isSavedOrgApiKey(providedOrgApiKey, baseUrl);
|
|
2723
|
+
if (!saveOrgApiKey && interactive2) {
|
|
2724
|
+
const save = await p.confirm({
|
|
2725
|
+
message: "Save this organization key in ~/.conto/config.json? Other projects of this organization on this machine can then use it.",
|
|
2726
|
+
initialValue: false
|
|
2727
|
+
});
|
|
2728
|
+
if (p.isCancel(save)) {
|
|
2729
|
+
p.cancel("Setup cancelled.");
|
|
2730
|
+
process.exit(0);
|
|
2731
|
+
}
|
|
2732
|
+
saveOrgApiKey = save === true;
|
|
2733
|
+
}
|
|
2629
2734
|
} else {
|
|
2630
2735
|
s.start("Opening browser to authenticate...");
|
|
2631
2736
|
try {
|
|
2632
|
-
const authResult = await browserAuth(
|
|
2737
|
+
const authResult = await browserAuth(
|
|
2738
|
+
baseUrl,
|
|
2739
|
+
void 0,
|
|
2740
|
+
(code) => s.message(`Waiting for the browser. Connect only if it shows ${code}`)
|
|
2741
|
+
);
|
|
2633
2742
|
orgApiKey = authResult.orgApiKey;
|
|
2634
2743
|
orgApiKeyExpiresAt = authResult.expiresAt || void 0;
|
|
2635
2744
|
organizationName = authResult.organizationName || void 0;
|
|
@@ -2760,6 +2869,8 @@ async function runOrganizationInit(options) {
|
|
|
2760
2869
|
},
|
|
2761
2870
|
options
|
|
2762
2871
|
);
|
|
2872
|
+
const previousOrgKey = orgKeySavedFor(baseUrl);
|
|
2873
|
+
const savedOrgKey = !providedOrgApiKey ? { orgApiKey, orgApiKeyExpiresAt } : saveOrgApiKey && previousOrgKey.orgApiKey !== orgApiKey ? { orgApiKey } : previousOrgKey;
|
|
2763
2874
|
saveGlobalConfig({
|
|
2764
2875
|
agent: { id: agent.id, name: agent.name, type: agentType },
|
|
2765
2876
|
network: {
|
|
@@ -2775,7 +2886,7 @@ async function runOrganizationInit(options) {
|
|
|
2775
2886
|
address: wallet.address,
|
|
2776
2887
|
custodyMode: wallet.custodyMode ?? "MANAGED"
|
|
2777
2888
|
},
|
|
2778
|
-
server: { baseUrl, apiKey: sdkKey.key,
|
|
2889
|
+
server: { baseUrl, apiKey: sdkKey.key, ...savedOrgKey }
|
|
2779
2890
|
});
|
|
2780
2891
|
removeCheckpoint(cwd);
|
|
2781
2892
|
let cliResolves = false;
|
|
@@ -2819,7 +2930,8 @@ async function runOrganizationInit(options) {
|
|
|
2819
2930
|
},
|
|
2820
2931
|
credentials: {
|
|
2821
2932
|
storedIn: ".env.local",
|
|
2822
|
-
sdkKeyEnv: "CONTO_API_KEY"
|
|
2933
|
+
sdkKeyEnv: "CONTO_API_KEY",
|
|
2934
|
+
orgApiKeySaved: saveOrgApiKey
|
|
2823
2935
|
},
|
|
2824
2936
|
files: PROJECT_FILES.filter((file) => !keptFiles.includes(file)),
|
|
2825
2937
|
...keptFiles.length > 0 ? { keptFiles } : {},
|
|
@@ -2840,6 +2952,10 @@ async function runOrganizationInit(options) {
|
|
|
2840
2952
|
}
|
|
2841
2953
|
console.log("");
|
|
2842
2954
|
printKeptFiles(keptFiles);
|
|
2955
|
+
if (!saveOrgApiKey) {
|
|
2956
|
+
printInfo(ORG_KEY_NOT_SAVED);
|
|
2957
|
+
console.log("");
|
|
2958
|
+
}
|
|
2843
2959
|
console.log(
|
|
2844
2960
|
` ${chalk2.dim("Wallet:")} ${wallet.address} (${chain.name}${chain.testnet ? " testnet" : ""}, ${wallet.custodyMode ?? "MANAGED"} custody)`
|
|
2845
2961
|
);
|
|
@@ -2908,7 +3024,7 @@ function reportStoppedSetup(input) {
|
|
|
2908
3024
|
checkpoint: INIT_CHECKPOINT_FILE,
|
|
2909
3025
|
resume: resumable ? {
|
|
2910
3026
|
command,
|
|
2911
|
-
credential:
|
|
3027
|
+
credential: resumeCredentialHint(),
|
|
2912
3028
|
...stop.reconciliation?.notBefore ? { notBefore: stop.reconciliation.notBefore } : {}
|
|
2913
3029
|
} : null,
|
|
2914
3030
|
...stop.retryAfterSeconds !== void 0 ? { retryAfterSeconds: stop.retryAfterSeconds } : {},
|
|
@@ -2963,7 +3079,7 @@ function reportStoppedSetup(input) {
|
|
|
2963
3079
|
console.log("");
|
|
2964
3080
|
if (resumable) {
|
|
2965
3081
|
printInfo(`Resume: ${command}`);
|
|
2966
|
-
printInfo(
|
|
3082
|
+
printInfo(resumeCredentialHint());
|
|
2967
3083
|
} else {
|
|
2968
3084
|
printInfo(`The unfinished setup is kept in ${INIT_CHECKPOINT_FILE}. Nothing was changed.`);
|
|
2969
3085
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/lib/cli-commands.ts
|
|
2
|
+
var CLI_COMMANDS = /* @__PURE__ */ new Set([
|
|
3
|
+
"status",
|
|
4
|
+
"doctor",
|
|
5
|
+
"balance",
|
|
6
|
+
"pay",
|
|
7
|
+
"transactions",
|
|
8
|
+
"wallets",
|
|
9
|
+
"webhooks",
|
|
10
|
+
"agents",
|
|
11
|
+
"teams",
|
|
12
|
+
"counterparties",
|
|
13
|
+
"channels",
|
|
14
|
+
"changes",
|
|
15
|
+
"test-report",
|
|
16
|
+
"fund",
|
|
17
|
+
"policies",
|
|
18
|
+
"limits",
|
|
19
|
+
"alerts",
|
|
20
|
+
"config",
|
|
21
|
+
"login",
|
|
22
|
+
"logout",
|
|
23
|
+
"mcp",
|
|
24
|
+
"docs",
|
|
25
|
+
"init",
|
|
26
|
+
"sandbox",
|
|
27
|
+
"spending",
|
|
28
|
+
"budgets",
|
|
29
|
+
"tasks",
|
|
30
|
+
"purchases",
|
|
31
|
+
"help",
|
|
32
|
+
"--help",
|
|
33
|
+
"-h",
|
|
34
|
+
"--version",
|
|
35
|
+
"-V"
|
|
36
|
+
]);
|
|
37
|
+
function delegatesToCli(args) {
|
|
38
|
+
if (args[0] !== void 0 && CLI_COMMANDS.has(args[0])) return true;
|
|
39
|
+
return args[0] === "--json" && args[1] !== void 0 && CLI_COMMANDS.has(args[1]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
CLI_COMMANDS,
|
|
44
|
+
delegatesToCli
|
|
45
|
+
};
|
|
@@ -87,7 +87,9 @@ function loadConfig() {
|
|
|
87
87
|
const baseUrl = withoutUrlCredentials(
|
|
88
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
89
|
);
|
|
90
|
+
const credentialSource = hasProcessCredential ? "process" : hasProjectCredential ? "project" : hasGlobalCredential ? "global" : "none";
|
|
90
91
|
return {
|
|
92
|
+
credentialSource,
|
|
91
93
|
// Secrets never come from conto.config.json: it is written world-readable
|
|
92
94
|
// (0644) and is not gitignored. Read the API key only from the environment,
|
|
93
95
|
// the gitignored .env.local, or the private global store (~/.conto, 0600).
|
|
@@ -112,6 +114,15 @@ function loadConfig() {
|
|
|
112
114
|
testnet: explicitTestnet === "true" ? true : explicitTestnet === "false" ? false : matchingNetwork?.testnet ?? chainId === "42431"
|
|
113
115
|
};
|
|
114
116
|
}
|
|
117
|
+
function savedOrgKeyFor(config) {
|
|
118
|
+
if (config.credentialSource !== "project" || config.orgApiKey || !config.apiKey) return void 0;
|
|
119
|
+
const server = loadGlobalConfig().server;
|
|
120
|
+
if (!server?.orgApiKey) return void 0;
|
|
121
|
+
return {
|
|
122
|
+
orgApiKey: server.orgApiKey,
|
|
123
|
+
baseUrl: withoutUrlCredentials(server.baseUrl || DEFAULT_BASE_URL)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
115
126
|
function linesOutsideContoBlock(content) {
|
|
116
127
|
const lines = content.split("\n");
|
|
117
128
|
const kept = [];
|
|
@@ -204,6 +215,7 @@ export {
|
|
|
204
215
|
loadProjectEnv,
|
|
205
216
|
loadProjectConfig,
|
|
206
217
|
loadConfig,
|
|
218
|
+
savedOrgKeyFor,
|
|
207
219
|
writeEnvLocal,
|
|
208
220
|
ensureEnvLocalGitignored,
|
|
209
221
|
SANDBOX_SETUP_ENV_FILE,
|
|
@@ -86,6 +86,22 @@ function validatePaymentRequest(input) {
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
+
var BLOCKLIST_RULE_TYPES = [
|
|
90
|
+
"BLOCKED_COUNTERPARTIES",
|
|
91
|
+
"BLOCKED_CATEGORIES",
|
|
92
|
+
"X402_BLOCKED_SERVICES",
|
|
93
|
+
"MPP_BLOCKED_SERVICES",
|
|
94
|
+
"MPP_BLOCK_SESSION_INTENT",
|
|
95
|
+
"CARD_BLOCKED_MCCS",
|
|
96
|
+
"CARD_BLOCKED_MERCHANTS",
|
|
97
|
+
"CARD_BLOCKED_MERCHANT_DOMAINS",
|
|
98
|
+
"BLACKOUT_PERIOD",
|
|
99
|
+
"MAINTENANCE_WINDOW",
|
|
100
|
+
"BLOCKED_TIME_WINDOW"
|
|
101
|
+
];
|
|
102
|
+
function isBlocklistRuleType(ruleType) {
|
|
103
|
+
return BLOCKLIST_RULE_TYPES.includes(ruleType);
|
|
104
|
+
}
|
|
89
105
|
|
|
90
106
|
export {
|
|
91
107
|
parseTrustScoreInput,
|
|
@@ -94,5 +110,7 @@ export {
|
|
|
94
110
|
BUDGET_PERIODS,
|
|
95
111
|
buildBudgetCapValue,
|
|
96
112
|
dateRangePlaceholder,
|
|
97
|
-
validatePaymentRequest
|
|
113
|
+
validatePaymentRequest,
|
|
114
|
+
BLOCKLIST_RULE_TYPES,
|
|
115
|
+
isBlocklistRuleType
|
|
98
116
|
};
|