@conto_finance/create-conto-agent 0.4.7 → 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 +48 -0
- package/README.md +9 -0
- package/dist/{chunk-K4LBO234.js → chunk-DT5NOLBD.js} +1 -1
- package/dist/{chunk-XWUWB3FT.js → chunk-RQ4PUBL7.js} +43 -11
- package/dist/{chunk-HSJDGYZ5.js → chunk-YWVIBVYN.js} +976 -124
- package/dist/cli.js +1437 -421
- package/dist/{config-N7W4ZJJY.js → config-MACPIPYV.js} +1 -3
- package/dist/index.js +12 -4
- package/dist/{output-IN47X4NU.js → output-GD3QK4HS.js} +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ApiClient,
|
|
2
3
|
CLI_PACKAGE_VERSION,
|
|
3
4
|
HttpTransportError,
|
|
5
|
+
NOTHING_SENT_CODES,
|
|
6
|
+
REVIEW_EXIT_CODES_HELP,
|
|
4
7
|
apiUrl,
|
|
5
8
|
browserAuth,
|
|
9
|
+
createApiClient,
|
|
10
|
+
createOwnerClient,
|
|
11
|
+
directOrReview,
|
|
6
12
|
fetchChains,
|
|
7
13
|
fingerprintSecret,
|
|
14
|
+
followChange,
|
|
8
15
|
getChain,
|
|
16
|
+
isTightenOnlyRefusal,
|
|
9
17
|
normalizeBaseUrl,
|
|
10
18
|
parseSecureBaseUrl,
|
|
11
19
|
projectStateFile,
|
|
20
|
+
proposeForReview,
|
|
12
21
|
readProjectStateFile,
|
|
13
22
|
redactSecrets,
|
|
23
|
+
reportReview,
|
|
14
24
|
requestJson,
|
|
15
25
|
responseErrorCode,
|
|
16
26
|
responseErrorMessage,
|
|
17
27
|
retryAfterSeconds,
|
|
18
28
|
runInit,
|
|
19
29
|
writeProjectStateFile
|
|
20
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-YWVIBVYN.js";
|
|
21
31
|
import {
|
|
22
32
|
VELOCITY_PERIODS,
|
|
23
33
|
buildVelocityCountValue,
|
|
24
34
|
parseTrustScoreInput,
|
|
25
35
|
validatePaymentRequest
|
|
26
36
|
} from "./chunk-TJJY5NFH.js";
|
|
37
|
+
import {
|
|
38
|
+
SANDBOX_SETUP_ENV_FILE,
|
|
39
|
+
isSensitiveConfigKey,
|
|
40
|
+
loadConfig,
|
|
41
|
+
loadGlobalConfig,
|
|
42
|
+
loadProjectEnv,
|
|
43
|
+
maskSecret,
|
|
44
|
+
missingSdkKeyMessage,
|
|
45
|
+
saveGlobalConfig
|
|
46
|
+
} from "./chunk-RQ4PUBL7.js";
|
|
27
47
|
import {
|
|
28
48
|
isJsonMode,
|
|
29
49
|
printAmount,
|
|
@@ -38,255 +58,212 @@ import {
|
|
|
38
58
|
printWarning,
|
|
39
59
|
setJsonMode,
|
|
40
60
|
truncateAddress
|
|
41
|
-
} from "./chunk-
|
|
42
|
-
import {
|
|
43
|
-
SANDBOX_SETUP_ENV_FILE,
|
|
44
|
-
isSensitiveConfigKey,
|
|
45
|
-
loadConfig,
|
|
46
|
-
loadGlobalConfig,
|
|
47
|
-
loadProjectEnv,
|
|
48
|
-
maskSecret,
|
|
49
|
-
missingSdkKeyMessage,
|
|
50
|
-
saveGlobalConfig
|
|
51
|
-
} from "./chunk-XWUWB3FT.js";
|
|
52
|
-
|
|
53
|
-
// src/cli.ts
|
|
54
|
-
import { Command } from "commander";
|
|
61
|
+
} from "./chunk-DT5NOLBD.js";
|
|
55
62
|
|
|
56
|
-
// src/commands/
|
|
57
|
-
import
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var REQUEST_TIMEOUT_MS = 3e4;
|
|
61
|
-
function assertSecureBaseUrl(baseUrl) {
|
|
62
|
-
let parsed;
|
|
63
|
+
// src/commands/spending.ts
|
|
64
|
+
import { readFile, writeFile } from "fs/promises";
|
|
65
|
+
import { basename, extname } from "path";
|
|
66
|
+
async function run(work, owner = false) {
|
|
63
67
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (token) {
|
|
91
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
92
|
-
}
|
|
93
|
-
const controller = new AbortController();
|
|
94
|
-
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
95
|
-
try {
|
|
96
|
-
const response = await fetch(url, {
|
|
97
|
-
method,
|
|
98
|
-
headers,
|
|
99
|
-
body: options?.body ? JSON.stringify(options.body) : void 0,
|
|
100
|
-
signal: controller.signal
|
|
101
|
-
});
|
|
102
|
-
const contentType = response.headers.get("content-type") || "";
|
|
103
|
-
if (!contentType.includes("application/json")) {
|
|
104
|
-
const error = new Error(
|
|
105
|
-
response.status === 404 ? `API endpoint not found: ${path2}` : `API returned non-JSON response (${response.status})`
|
|
106
|
-
);
|
|
107
|
-
error.code = response.status === 404 ? "NOT_FOUND" : "INVALID_RESPONSE";
|
|
108
|
-
error.status = response.status;
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
const data = await response.json();
|
|
112
|
-
if (!response.ok) {
|
|
113
|
-
const error = new Error(data.error || `API request failed: ${response.status}`);
|
|
114
|
-
error.code = data.code || "API_ERROR";
|
|
115
|
-
error.status = response.status;
|
|
116
|
-
error.body = data;
|
|
117
|
-
throw error;
|
|
118
|
-
}
|
|
119
|
-
return data;
|
|
120
|
-
} catch (err) {
|
|
121
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
122
|
-
const error = new Error(
|
|
123
|
-
`Request timed out after ${REQUEST_TIMEOUT_MS / 1e3}s`
|
|
124
|
-
);
|
|
125
|
-
error.code = "TIMEOUT";
|
|
126
|
-
error.status = 0;
|
|
127
|
-
throw error;
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
if (!(owner ? config.orgApiKey : config.apiKey))
|
|
70
|
+
throw new Error(
|
|
71
|
+
owner ? "An organization key is required for owner actions." : "Run conto login first."
|
|
72
|
+
);
|
|
73
|
+
const result = await work(createApiClient(config));
|
|
74
|
+
if (isJsonMode()) printJson(result);
|
|
75
|
+
else {
|
|
76
|
+
const object = result;
|
|
77
|
+
for (const [key, value] of Object.entries(object)) {
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
for (const row of value) {
|
|
80
|
+
console.log("");
|
|
81
|
+
if (typeof row === "object" && row !== null)
|
|
82
|
+
for (const [field, item] of Object.entries(row))
|
|
83
|
+
printKeyValue(
|
|
84
|
+
field,
|
|
85
|
+
typeof item === "object" ? JSON.stringify(item) : String(item ?? "-")
|
|
86
|
+
);
|
|
87
|
+
else console.log(String(row));
|
|
88
|
+
}
|
|
89
|
+
else
|
|
90
|
+
printKeyValue(
|
|
91
|
+
key,
|
|
92
|
+
typeof value === "object" ? JSON.stringify(value) : String(value ?? "-")
|
|
93
|
+
);
|
|
128
94
|
}
|
|
129
|
-
throw err;
|
|
130
|
-
} finally {
|
|
131
|
-
clearTimeout(timeoutId);
|
|
132
95
|
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const e = error;
|
|
98
|
+
if (isJsonMode()) printJson({ error: e.message, code: e.code, ...e.details });
|
|
99
|
+
else printError(e.message);
|
|
100
|
+
process.exitCode = 1;
|
|
133
101
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
async updatePolicy(policyId, params) {
|
|
157
|
-
return this.request("PATCH", `/api/policies/${encodeURIComponent(policyId)}`, { body: params, auth: "org" });
|
|
158
|
-
}
|
|
159
|
-
async deletePolicy(policyId) {
|
|
160
|
-
return this.request("DELETE", `/api/policies/${encodeURIComponent(policyId)}`, { auth: "org" });
|
|
161
|
-
}
|
|
162
|
-
async addPolicyRule(policyId, rule) {
|
|
163
|
-
return this.request(
|
|
164
|
-
"POST",
|
|
165
|
-
`/api/policies/${encodeURIComponent(policyId)}/rules`,
|
|
166
|
-
{
|
|
167
|
-
body: rule,
|
|
168
|
-
auth: "org"
|
|
169
|
-
}
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
async deletePolicyRule(policyId, ruleId) {
|
|
173
|
-
return this.request(
|
|
174
|
-
"DELETE",
|
|
175
|
-
`/api/policies/${encodeURIComponent(policyId)}/rules/${encodeURIComponent(ruleId)}`,
|
|
176
|
-
{ auth: "org" }
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
async listOrgPolicies() {
|
|
180
|
-
return this.request("GET", "/api/policies", { auth: "org" });
|
|
181
|
-
}
|
|
182
|
-
async assignPolicyToAgent(agentId, policyId) {
|
|
183
|
-
return this.request("POST", `/api/agents/${encodeURIComponent(agentId)}/policies`, {
|
|
184
|
-
body: { policyId },
|
|
185
|
-
auth: "org"
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
async unassignPolicyFromAgent(agentId, policyId) {
|
|
189
|
-
return this.request(
|
|
190
|
-
"DELETE",
|
|
191
|
-
`/api/agents/${encodeURIComponent(agentId)}/policies?policyId=${encodeURIComponent(policyId)}`,
|
|
192
|
-
{
|
|
193
|
-
auth: "org"
|
|
194
|
-
}
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
async createSdkKey(agentId, params) {
|
|
198
|
-
return this.request("POST", `/api/agents/${encodeURIComponent(agentId)}/sdk-keys`, {
|
|
199
|
-
body: params,
|
|
200
|
-
auth: "org"
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
async fundWallet(walletId) {
|
|
204
|
-
return this.request("POST", `/api/wallets/${encodeURIComponent(walletId)}/faucet`, { auth: "org" });
|
|
205
|
-
}
|
|
206
|
-
// ── SDK Agent APIs (used by CLI commands) ──
|
|
207
|
-
async getSetup() {
|
|
208
|
-
return this.request("GET", "/api/sdk/setup");
|
|
209
|
-
}
|
|
210
|
-
async getAgentInfo() {
|
|
211
|
-
const data = await this.request("GET", "/api/sdk/agents/me");
|
|
212
|
-
return {
|
|
213
|
-
agent: {
|
|
214
|
-
id: data.id,
|
|
215
|
-
name: data.name,
|
|
216
|
-
agentType: data.agentType,
|
|
217
|
-
status: data.status,
|
|
218
|
-
createdAt: data.createdAt
|
|
219
|
-
},
|
|
220
|
-
organization: { name: data.organizationId },
|
|
221
|
-
walletCount: data.summary?.walletCount ?? 0,
|
|
222
|
-
summary: data.summary
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
async getWallets() {
|
|
226
|
-
return this.request("GET", "/api/sdk/wallets");
|
|
227
|
-
}
|
|
228
|
-
async getSpendingLimits() {
|
|
229
|
-
const data = await this.request("GET", "/api/sdk/spending-limits");
|
|
230
|
-
return {
|
|
231
|
-
limits: (data.wallets || []).map((w) => ({
|
|
232
|
-
walletId: w.walletId,
|
|
233
|
-
walletName: w.name,
|
|
234
|
-
daily: {
|
|
235
|
-
limit: w.limits?.daily ?? 0,
|
|
236
|
-
spent: w.spent?.today ?? 0,
|
|
237
|
-
remaining: w.remaining?.daily ?? 0
|
|
102
|
+
}
|
|
103
|
+
var id = encodeURIComponent;
|
|
104
|
+
function registerSpendingCommands(program2) {
|
|
105
|
+
const budgets = program2.command("budgets").description("Shared budget availability and owner controls");
|
|
106
|
+
budgets.command("list").option("--owner", "Use organization credentials").action((o) => run((api) => api.spending("GET", "budgets", void 0, o.owner), o.owner));
|
|
107
|
+
budgets.command("create <file>").description("Owner: create a budget from a JSON definition").action(
|
|
108
|
+
(file) => run(
|
|
109
|
+
async (api) => api.spending("POST", "budgets", JSON.parse(await readFile(file, "utf8")), true),
|
|
110
|
+
true
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
budgets.command("update <budgetId>").requiredOption("--expected-version <version>", "Current version").option("--amount <amount>", "Exact decimal ceiling").option("--expires <iso-date>", "Owner-approved extension of budget expiry").option("--pause", "Stop new purchases").option("--activate", "Resume within original expiry").action(
|
|
114
|
+
(budgetId, o) => run(async (api) => {
|
|
115
|
+
if (o.pause && o.activate) throw new Error("Choose either --pause or --activate.");
|
|
116
|
+
return api.spending(
|
|
117
|
+
"PATCH",
|
|
118
|
+
`budgets/${id(budgetId)}`,
|
|
119
|
+
{
|
|
120
|
+
version: Number(o.expectedVersion),
|
|
121
|
+
...o.amount ? { amount: o.amount } : {},
|
|
122
|
+
...o.expires ? { periodEnd: o.expires } : {},
|
|
123
|
+
...o.pause ? { isActive: false } : o.activate ? { isActive: true } : {}
|
|
238
124
|
},
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
} :
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
125
|
+
true
|
|
126
|
+
);
|
|
127
|
+
}, true)
|
|
128
|
+
);
|
|
129
|
+
const tasks = program2.command("tasks").description("Request and inspect bounded task authority");
|
|
130
|
+
tasks.command("list").option("--cursor <cursor>", "Next page cursor").option("--owner", "Use organization credentials").action(
|
|
131
|
+
(o) => run(
|
|
132
|
+
(api) => api.spending(
|
|
133
|
+
"GET",
|
|
134
|
+
`tasks${o.cursor ? `?cursor=${id(o.cursor)}` : ""}`,
|
|
135
|
+
void 0,
|
|
136
|
+
o.owner
|
|
137
|
+
),
|
|
138
|
+
o.owner
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
tasks.command("request").requiredOption("--purpose <purpose>", "Purpose").requiredOption("--amount <amount>", "Exact ceiling").requiredOption("--currency <currency>", "Exact currency").requiredOption("--expires <iso-date>", "Expiry").option("--merchants <ids...>", "Exact permitted merchant identifiers").option("--sources <ids...>", "Permitted wallet or card IDs").action(
|
|
142
|
+
(o) => run(
|
|
143
|
+
(api) => api.spending("POST", "tasks", {
|
|
144
|
+
purpose: o.purpose,
|
|
145
|
+
amount: o.amount,
|
|
146
|
+
currency: o.currency,
|
|
147
|
+
expiresAt: o.expires,
|
|
148
|
+
permittedMerchants: o.merchants || [],
|
|
149
|
+
permittedSourceIds: o.sources || []
|
|
150
|
+
})
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
tasks.command("decide <taskId> <decision>").description("Owner: APPROVE, REJECT, or CLOSE").option("--amount <amount>", "Approved ceiling").option("--agents <ids...>", "Approved participants, including requester").action(
|
|
154
|
+
(taskId, decision, o) => run(
|
|
155
|
+
(api) => api.spending(
|
|
156
|
+
"POST",
|
|
157
|
+
`tasks/${id(taskId)}/decide`,
|
|
158
|
+
{
|
|
159
|
+
decision: decision.toUpperCase(),
|
|
160
|
+
...o.amount ? { amount: o.amount } : {},
|
|
161
|
+
...o.agents ? { participantIds: o.agents } : {}
|
|
162
|
+
},
|
|
163
|
+
true
|
|
164
|
+
),
|
|
165
|
+
true
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
const purchases = program2.command("purchases").description("Inspect purchases, preview allowances, and attach evidence");
|
|
169
|
+
purchases.command("list").option("--cursor <cursor>", "Next page cursor").option("--owner", "Use organization credentials").action(
|
|
170
|
+
(o) => run(
|
|
171
|
+
(api) => api.spending(
|
|
172
|
+
"GET",
|
|
173
|
+
`purchases${o.cursor ? `?cursor=${id(o.cursor)}` : ""}`,
|
|
174
|
+
void 0,
|
|
175
|
+
o.owner
|
|
176
|
+
),
|
|
177
|
+
o.owner
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
purchases.command("show <purchaseId>").option("--owner", "Use organization credentials").action(
|
|
181
|
+
(purchaseId, o) => run((api) => api.spending("GET", `purchases/${id(purchaseId)}`, void 0, o.owner), o.owner)
|
|
182
|
+
);
|
|
183
|
+
purchases.command("preview").requiredOption("--amount <amount>", "Exact amount").requiredOption("--currency <currency>", "Exact currency").requiredOption("--wallet <walletId>", "Managed wallet").requiredOption("--merchant <merchant>", "Recipient identifier").option("--task <taskId>", "Approved task").option("--purchase-key <key>", "Stable purchase identity").action(
|
|
184
|
+
(o) => run(
|
|
185
|
+
(api) => api.spending("POST", "purchases/preview", {
|
|
186
|
+
amount: o.amount,
|
|
187
|
+
currency: o.currency,
|
|
188
|
+
sourceId: o.wallet,
|
|
189
|
+
merchant: o.merchant,
|
|
190
|
+
...o.task ? { taskRequestId: o.task } : {},
|
|
191
|
+
...o.purchaseKey ? { purchaseKey: o.purchaseKey } : {}
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
purchases.command("status <paymentRequestId>").description("Check an existing payment request, including pending approval").action((requestId) => run((api) => api.getPaymentStatus(requestId)));
|
|
196
|
+
purchases.command("export <file>").description("Export one row per purchase; refuses to overwrite an existing file").option("--owner", "Export all workspace purchases using organization credentials").action(
|
|
197
|
+
(file, o) => run(async (api) => {
|
|
198
|
+
const bytes = await api.spendingDownload("purchases/export", o.owner);
|
|
199
|
+
await writeFile(file, bytes, { flag: "wx" });
|
|
200
|
+
return { saved: file };
|
|
201
|
+
}, o.owner)
|
|
202
|
+
);
|
|
203
|
+
purchases.command("accounting <purchaseId> <file>").description("Owner: set department, project, and accountingCode from JSON").action(
|
|
204
|
+
(purchaseId, file) => run(
|
|
205
|
+
async (api) => api.spending(
|
|
206
|
+
"PATCH",
|
|
207
|
+
`purchases/${id(purchaseId)}`,
|
|
208
|
+
JSON.parse(await readFile(file, "utf8")),
|
|
209
|
+
true
|
|
210
|
+
),
|
|
211
|
+
true
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
purchases.command("review-evidence <purchaseId> <evidenceId> <file>").description("Owner: compare amount, currency, and merchant from a document").action(
|
|
215
|
+
(purchaseId, evidenceId, file) => run(
|
|
216
|
+
async (api) => api.spending(
|
|
217
|
+
"PATCH",
|
|
218
|
+
`purchases/${id(purchaseId)}/evidence/${id(evidenceId)}`,
|
|
219
|
+
JSON.parse(await readFile(file, "utf8")),
|
|
220
|
+
true
|
|
221
|
+
),
|
|
222
|
+
true
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
purchases.command("resume <paymentRequestId>").description(
|
|
226
|
+
"Execute the existing authorized managed-wallet request; never create a replacement"
|
|
227
|
+
).action((requestId) => run((api) => api.executePayment(requestId)));
|
|
228
|
+
purchases.command("attach <purchaseId> <file>").description("Attach a receipt or invoice (PDF, PNG, JPEG; 2 MiB)").action(
|
|
229
|
+
(purchaseId, file) => run(async (api) => {
|
|
230
|
+
const bytes = await readFile(file);
|
|
231
|
+
if (bytes.length > 2 * 1024 * 1024) throw new Error("Evidence exceeds 2 MiB.");
|
|
232
|
+
const mime = {
|
|
233
|
+
".pdf": "application/pdf",
|
|
234
|
+
".png": "image/png",
|
|
235
|
+
".jpg": "image/jpeg",
|
|
236
|
+
".jpeg": "image/jpeg"
|
|
237
|
+
};
|
|
238
|
+
const form = new FormData();
|
|
239
|
+
form.set(
|
|
240
|
+
"file",
|
|
241
|
+
new Blob([bytes], {
|
|
242
|
+
type: mime[extname(file).toLowerCase()] || "application/octet-stream"
|
|
243
|
+
}),
|
|
244
|
+
basename(file)
|
|
245
|
+
);
|
|
246
|
+
return api.spending("POST", `purchases/${id(purchaseId)}/evidence`, form);
|
|
247
|
+
})
|
|
248
|
+
);
|
|
249
|
+
purchases.command("reconcile <purchaseId> <file>").description("Owner: apply a verified outcome from a JSON file with a stable eventKey").action(
|
|
250
|
+
(purchaseId, file) => run(
|
|
251
|
+
async (api) => api.spending(
|
|
252
|
+
"POST",
|
|
253
|
+
`purchases/${id(purchaseId)}/reconcile`,
|
|
254
|
+
JSON.parse(await readFile(file, "utf8")),
|
|
255
|
+
true
|
|
256
|
+
),
|
|
257
|
+
true
|
|
258
|
+
)
|
|
259
|
+
);
|
|
287
260
|
}
|
|
288
261
|
|
|
262
|
+
// src/cli.ts
|
|
263
|
+
import { Command } from "commander";
|
|
264
|
+
|
|
289
265
|
// src/commands/test-report.ts
|
|
266
|
+
import fs from "fs";
|
|
290
267
|
async function testReportCommand(options) {
|
|
291
268
|
try {
|
|
292
269
|
const config = loadConfig();
|
|
@@ -968,9 +945,299 @@ async function balanceCommand() {
|
|
|
968
945
|
}
|
|
969
946
|
|
|
970
947
|
// src/commands/pay.ts
|
|
948
|
+
import { randomUUID } from "crypto";
|
|
949
|
+
import chalk3 from "chalk";
|
|
950
|
+
|
|
951
|
+
// src/lib/payment-review.ts
|
|
971
952
|
import chalk2 from "chalk";
|
|
953
|
+
var PAYMENT_EXIT_CODES_HELP = `
|
|
954
|
+
Payments that need approval:
|
|
955
|
+
the command prints a review link, opens it when it can, waits for the
|
|
956
|
+
decision, and sends the payment once it is approved.
|
|
957
|
+
|
|
958
|
+
conto pay status <requestId> Check any payment, and send it if an approver
|
|
959
|
+
approved it meanwhile
|
|
960
|
+
conto pay execute <requestId> Send a payment that is approved
|
|
961
|
+
|
|
962
|
+
When the outcome is unknown (exit 6), do not re-run the command, which would
|
|
963
|
+
start a new payment. Run conto pay status <requestId>. With no request ID yet,
|
|
964
|
+
re-run with the printed key: --idempotency-key <key> returns the same request.
|
|
965
|
+
|
|
966
|
+
Exit codes:
|
|
967
|
+
0 sent, or already handled
|
|
968
|
+
1 request failed
|
|
969
|
+
3 an approver rejected the payment
|
|
970
|
+
4 not sent yet: waiting for approval (--no-wait, or the wait timed out),
|
|
971
|
+
or approved and waiting for conto pay execute
|
|
972
|
+
5 the approval or the payment expired, or the approval was cancelled
|
|
973
|
+
6 outcome unknown: the payment may have gone through
|
|
974
|
+
`;
|
|
975
|
+
var PAY_EXIT_REJECTED = 3;
|
|
976
|
+
var PAY_EXIT_PENDING = 4;
|
|
977
|
+
var PAY_EXIT_EXPIRED = 5;
|
|
978
|
+
var PAY_EXIT_OUTCOME_UNKNOWN = 6;
|
|
979
|
+
var POLL_INTERVAL_MS = Number(process.env.CONTO_REVIEW_POLL_MS) || 3e3;
|
|
980
|
+
var DEFAULT_WAIT_SECONDS = 300;
|
|
981
|
+
var PaymentReviewClient = class extends ApiClient {
|
|
982
|
+
startReview(paymentRequestId) {
|
|
983
|
+
return this.request("POST", "/api/sdk/approval-reviews", {
|
|
984
|
+
body: { paymentRequestId, client: { name: "conto-cli", version: CLI_PACKAGE_VERSION } }
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
getReview(reviewSessionId) {
|
|
988
|
+
return this.request(
|
|
989
|
+
"GET",
|
|
990
|
+
`/api/sdk/approval-reviews/${encodeURIComponent(reviewSessionId)}`
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
function interactive() {
|
|
995
|
+
return Boolean(process.stdout.isTTY) && !isJsonMode();
|
|
996
|
+
}
|
|
997
|
+
function waitSeconds(wait) {
|
|
998
|
+
if (wait === false) return 0;
|
|
999
|
+
if (typeof wait === "string" && wait.trim() !== "") {
|
|
1000
|
+
const seconds = Number(wait);
|
|
1001
|
+
if (!Number.isFinite(seconds) || seconds < 0)
|
|
1002
|
+
throw new Error("--wait takes a number of seconds");
|
|
1003
|
+
return Math.min(Math.round(seconds), DEFAULT_WAIT_SECONDS);
|
|
1004
|
+
}
|
|
1005
|
+
if (wait === true) return DEFAULT_WAIT_SECONDS;
|
|
1006
|
+
return interactive() ? DEFAULT_WAIT_SECONDS : 0;
|
|
1007
|
+
}
|
|
1008
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1009
|
+
async function followPaymentReview(api, paymentRequestId, options = {}) {
|
|
1010
|
+
let review = await api.startReview(paymentRequestId);
|
|
1011
|
+
if (review.nextAction.type === "START_REVIEW_AGAIN") {
|
|
1012
|
+
review = await api.startReview(paymentRequestId);
|
|
1013
|
+
}
|
|
1014
|
+
if (review.state === "PENDING_REVIEW" && review.reviewUrl && !isJsonMode()) {
|
|
1015
|
+
printPending("This payment needs an approver to confirm it.");
|
|
1016
|
+
printKeyValue("Review", review.reviewUrl);
|
|
1017
|
+
if (options.open ?? interactive()) {
|
|
1018
|
+
try {
|
|
1019
|
+
const open = (await import("open")).default;
|
|
1020
|
+
await open(review.reviewUrl);
|
|
1021
|
+
} catch {
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
const deadline = Date.now() + waitSeconds(options.wait) * 1e3;
|
|
1026
|
+
while (review.nextAction.type === "WAIT_FOR_REVIEW" && Date.now() < deadline) {
|
|
1027
|
+
await sleep(POLL_INTERVAL_MS);
|
|
1028
|
+
review = await api.getReview(review.reviewSessionId);
|
|
1029
|
+
}
|
|
1030
|
+
return review;
|
|
1031
|
+
}
|
|
1032
|
+
function paymentReviewExitCode(review) {
|
|
1033
|
+
if (review.state === "REJECTED") return PAY_EXIT_REJECTED;
|
|
1034
|
+
if (review.state === "EXPIRED" || review.state === "CANCELLED") return PAY_EXIT_EXPIRED;
|
|
1035
|
+
if (review.nextAction.type === "WAIT_FOR_REVIEW" || review.state === "CHANGED") {
|
|
1036
|
+
return PAY_EXIT_PENDING;
|
|
1037
|
+
}
|
|
1038
|
+
return 0;
|
|
1039
|
+
}
|
|
1040
|
+
function printReviewOutcome(review, requestId) {
|
|
1041
|
+
if (review.nextAction.type === "WAIT_FOR_REVIEW") {
|
|
1042
|
+
printPending("Still waiting for approval. Nothing was sent.");
|
|
1043
|
+
console.log(chalk2.dim(` Check later with: conto pay status ${requestId}`));
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
console.log(chalk2.dim(` ${review.nextAction.message}`));
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// src/commands/pay.ts
|
|
1050
|
+
function printRecoveryId(label, value) {
|
|
1051
|
+
if (isJsonMode()) {
|
|
1052
|
+
console.error(`${label}: ${value}`);
|
|
1053
|
+
} else {
|
|
1054
|
+
printKeyValue(label, value);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
async function sendPayment(api, requestId, config, idempotencyKey) {
|
|
1058
|
+
const result = await api.executePayment(requestId);
|
|
1059
|
+
if (isJsonMode()) {
|
|
1060
|
+
printJson(idempotencyKey ? { ...result, idempotencyKey } : result);
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (config.sandboxMode === "test") {
|
|
1064
|
+
printSuccess("Payment recorded in sandbox test mode");
|
|
1065
|
+
} else {
|
|
1066
|
+
printSuccess("Payment sent!");
|
|
1067
|
+
}
|
|
1068
|
+
if (result.receipt?.txHash) printKeyValue("TX Hash", result.receipt?.txHash);
|
|
1069
|
+
printKeyValue("Amount", printAmount(result.amount, result.currency));
|
|
1070
|
+
printKeyValue("Recipient", result.recipient);
|
|
1071
|
+
printKeyValue("Status", result.status);
|
|
1072
|
+
printKeyValue("Request ID", requestId);
|
|
1073
|
+
if (result.receipt?.settlementMode)
|
|
1074
|
+
printKeyValue("Settlement mode", result.receipt.settlementMode);
|
|
1075
|
+
if (result.receipt?.explorerUrl) printKeyValue("Explorer", result.receipt?.explorerUrl);
|
|
1076
|
+
console.log("");
|
|
1077
|
+
}
|
|
1078
|
+
async function reviewAndSend(api, requestId, config, options, idempotencyKey) {
|
|
1079
|
+
const review = await followPaymentReview(api, requestId, options);
|
|
1080
|
+
if (review.nextAction.type === "EXECUTE_PAYMENT") {
|
|
1081
|
+
return sendPayment(api, requestId, config, idempotencyKey);
|
|
1082
|
+
}
|
|
1083
|
+
process.exitCode = paymentReviewExitCode(review);
|
|
1084
|
+
if (isJsonMode()) {
|
|
1085
|
+
printJson({ requestId, review, ...idempotencyKey ? { idempotencyKey } : {} });
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
printReviewOutcome(review, requestId);
|
|
1089
|
+
}
|
|
1090
|
+
function exitOutcomeUnknown(message, code, identity) {
|
|
1091
|
+
const { requestId, idempotencyKey } = identity;
|
|
1092
|
+
const nextAction = requestId ? `conto pay status ${requestId}` : `Re-run the same command with --idempotency-key ${idempotencyKey}`;
|
|
1093
|
+
if (isJsonMode()) {
|
|
1094
|
+
printJson({ error: message, code, outcome: "unknown", ...identity, nextAction });
|
|
1095
|
+
process.exit(PAY_EXIT_OUTCOME_UNKNOWN);
|
|
1096
|
+
}
|
|
1097
|
+
printError(message);
|
|
1098
|
+
printWarning(
|
|
1099
|
+
requestId ? "Outcome unknown: this payment may have gone through." : "Outcome unknown: Conto may have recorded this request."
|
|
1100
|
+
);
|
|
1101
|
+
console.log(chalk3.dim(" Do not re-run this command as it is. It would start a new payment."));
|
|
1102
|
+
if (requestId) {
|
|
1103
|
+
printKeyValue("Request ID", requestId);
|
|
1104
|
+
console.log(chalk3.dim(` Check it with: ${nextAction}`));
|
|
1105
|
+
} else {
|
|
1106
|
+
console.log(chalk3.dim(` ${nextAction}. That returns the same request.`));
|
|
1107
|
+
}
|
|
1108
|
+
process.exit(PAY_EXIT_OUTCOME_UNKNOWN);
|
|
1109
|
+
}
|
|
1110
|
+
function handlePayError(err, identity = {}) {
|
|
1111
|
+
const { code, outcomeUnknown } = err;
|
|
1112
|
+
const message = err instanceof Error ? err.message : "Payment failed";
|
|
1113
|
+
if (outcomeUnknown) exitOutcomeUnknown(message, code, identity);
|
|
1114
|
+
const { requestId } = identity;
|
|
1115
|
+
const nothingSent = code !== void 0 && NOTHING_SENT_CODES.has(code);
|
|
1116
|
+
const sendLater = requestId ? `conto pay execute ${requestId}` : void 0;
|
|
1117
|
+
if (isJsonMode()) {
|
|
1118
|
+
printJson({
|
|
1119
|
+
error: message,
|
|
1120
|
+
code,
|
|
1121
|
+
...identity,
|
|
1122
|
+
...nothingSent && sendLater ? { nextAction: sendLater } : {}
|
|
1123
|
+
});
|
|
1124
|
+
process.exit(1);
|
|
1125
|
+
}
|
|
1126
|
+
printError(message);
|
|
1127
|
+
if (code === "INSUFFICIENT_SCOPE") {
|
|
1128
|
+
console.log(
|
|
1129
|
+
chalk3.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
|
|
1130
|
+
);
|
|
1131
|
+
console.log(chalk3.dim(" or create a new standard SDK key (includes payments:execute)."));
|
|
1132
|
+
} else if (nothingSent) {
|
|
1133
|
+
console.log(
|
|
1134
|
+
chalk3.dim(" Nothing was sent. Try again later or contact Conto support if it continues.")
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1137
|
+
if (requestId) {
|
|
1138
|
+
printKeyValue("Request ID", requestId);
|
|
1139
|
+
console.log(
|
|
1140
|
+
chalk3.dim(
|
|
1141
|
+
nothingSent ? ` Send it later with: ${sendLater}` : ` Check it with: conto pay status ${requestId}`
|
|
1142
|
+
)
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
process.exit(1);
|
|
1146
|
+
}
|
|
1147
|
+
function storedPaymentExitCode(status) {
|
|
1148
|
+
switch (status) {
|
|
1149
|
+
case "completed":
|
|
1150
|
+
case "processing":
|
|
1151
|
+
return 0;
|
|
1152
|
+
case "failed":
|
|
1153
|
+
case "declined":
|
|
1154
|
+
return 1;
|
|
1155
|
+
case "expired":
|
|
1156
|
+
return PAY_EXIT_EXPIRED;
|
|
1157
|
+
case "reconciliation_required":
|
|
1158
|
+
return PAY_EXIT_OUTCOME_UNKNOWN;
|
|
1159
|
+
default:
|
|
1160
|
+
return PAY_EXIT_PENDING;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
async function reportStoredPayment(api, requestId) {
|
|
1164
|
+
const payment = await api.getPaymentStatus(requestId);
|
|
1165
|
+
process.exitCode = storedPaymentExitCode(payment.status);
|
|
1166
|
+
if (isJsonMode()) {
|
|
1167
|
+
printJson(payment);
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
switch (payment.status) {
|
|
1171
|
+
case "completed":
|
|
1172
|
+
printSuccess("Payment sent");
|
|
1173
|
+
break;
|
|
1174
|
+
case "processing":
|
|
1175
|
+
printPending("Payment is processing. Do not send it again.");
|
|
1176
|
+
break;
|
|
1177
|
+
case "approved":
|
|
1178
|
+
printPending("Approved and not sent yet.");
|
|
1179
|
+
console.log(chalk3.dim(` Send it with: conto pay execute ${requestId}`));
|
|
1180
|
+
break;
|
|
1181
|
+
case "reconciliation_required":
|
|
1182
|
+
printWarning("Conto is confirming whether this transfer went through. Do not send it again.");
|
|
1183
|
+
break;
|
|
1184
|
+
case "failed":
|
|
1185
|
+
printError("The payment failed.");
|
|
1186
|
+
break;
|
|
1187
|
+
case "declined":
|
|
1188
|
+
printError("The payment was declined.");
|
|
1189
|
+
break;
|
|
1190
|
+
case "expired":
|
|
1191
|
+
printError("The payment expired before it was sent.");
|
|
1192
|
+
break;
|
|
1193
|
+
default:
|
|
1194
|
+
printPending(`Payment is ${payment.status}.`);
|
|
1195
|
+
console.log(chalk3.dim(" Check the Conto dashboard for next steps."));
|
|
1196
|
+
}
|
|
1197
|
+
if (payment.transaction?.txHash) printKeyValue("TX Hash", payment.transaction.txHash);
|
|
1198
|
+
printKeyValue("Amount", printAmount(payment.amount, payment.currency));
|
|
1199
|
+
printKeyValue("Recipient", payment.recipient);
|
|
1200
|
+
printKeyValue("Status", payment.status);
|
|
1201
|
+
printKeyValue("Request ID", requestId);
|
|
1202
|
+
if (payment.transaction?.explorerUrl) printKeyValue("Explorer", payment.transaction.explorerUrl);
|
|
1203
|
+
if (payment.reasons?.length) {
|
|
1204
|
+
console.log(chalk3.dim(` Reasons: ${payment.reasons.join(", ")}`));
|
|
1205
|
+
}
|
|
1206
|
+
console.log("");
|
|
1207
|
+
}
|
|
1208
|
+
function isNoApprovalRequired(err) {
|
|
1209
|
+
const { code, details } = err;
|
|
1210
|
+
return code === "NO_APPROVAL_REQUIRED" || details?.code === "NO_APPROVAL_REQUIRED";
|
|
1211
|
+
}
|
|
1212
|
+
async function payStatus(api, requestId, config, options) {
|
|
1213
|
+
try {
|
|
1214
|
+
return await reviewAndSend(api, requestId, config, { wait: false, open: false, ...options });
|
|
1215
|
+
} catch (err) {
|
|
1216
|
+
if (!isNoApprovalRequired(err)) throw err;
|
|
1217
|
+
}
|
|
1218
|
+
return reportStoredPayment(api, requestId);
|
|
1219
|
+
}
|
|
1220
|
+
async function payFollowUpCommand(subcommand, requestId, options) {
|
|
1221
|
+
const config = loadConfig();
|
|
1222
|
+
if (!config.apiKey) {
|
|
1223
|
+
printError(
|
|
1224
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.'
|
|
1225
|
+
);
|
|
1226
|
+
process.exit(1);
|
|
1227
|
+
}
|
|
1228
|
+
const api = new PaymentReviewClient({ baseUrl: config.baseUrl, apiKey: config.apiKey });
|
|
1229
|
+
try {
|
|
1230
|
+
if (subcommand === "execute") return await sendPayment(api, requestId, config);
|
|
1231
|
+
return await payStatus(api, requestId, config, options);
|
|
1232
|
+
} catch (err) {
|
|
1233
|
+
handlePayError(err, { requestId });
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
972
1236
|
var DRY_RUN_NOTICE = "Dry run: nothing was sent to Conto and no policy evaluation was performed.";
|
|
973
1237
|
async function payCommand(address, amountStr, options) {
|
|
1238
|
+
if (address === "status" || address === "execute") {
|
|
1239
|
+
return payFollowUpCommand(address, amountStr, options);
|
|
1240
|
+
}
|
|
974
1241
|
const config = loadConfig();
|
|
975
1242
|
const validation = validatePaymentRequest({
|
|
976
1243
|
address,
|
|
@@ -979,6 +1246,15 @@ async function payCommand(address, amountStr, options) {
|
|
|
979
1246
|
category: options.category,
|
|
980
1247
|
walletId: options.wallet
|
|
981
1248
|
});
|
|
1249
|
+
const identity = {
|
|
1250
|
+
...options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {},
|
|
1251
|
+
...options.task || options.purchaseKey ? {
|
|
1252
|
+
context: {
|
|
1253
|
+
...options.task ? { taskRequestId: options.task } : {},
|
|
1254
|
+
...options.purchaseKey ? { purchaseKey: options.purchaseKey } : {}
|
|
1255
|
+
}
|
|
1256
|
+
} : {}
|
|
1257
|
+
};
|
|
982
1258
|
if (options.dryRun) {
|
|
983
1259
|
const baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/+$/, "");
|
|
984
1260
|
const url = `${baseUrl}/api/sdk/payments/request`;
|
|
@@ -992,7 +1268,7 @@ async function payCommand(address, amountStr, options) {
|
|
|
992
1268
|
});
|
|
993
1269
|
} else {
|
|
994
1270
|
for (const error of validation.errors) printError(error);
|
|
995
|
-
console.log(
|
|
1271
|
+
console.log(chalk3.dim(`
|
|
996
1272
|
${DRY_RUN_NOTICE}`));
|
|
997
1273
|
}
|
|
998
1274
|
process.exit(1);
|
|
@@ -1003,7 +1279,7 @@ async function payCommand(address, amountStr, options) {
|
|
|
1003
1279
|
valid: true,
|
|
1004
1280
|
policyEvaluated: false,
|
|
1005
1281
|
apiKeyConfigured: Boolean(config.apiKey),
|
|
1006
|
-
request: { method: "POST", url, body: validation.body },
|
|
1282
|
+
request: { method: "POST", url, body: { ...validation.body, ...identity } },
|
|
1007
1283
|
note: DRY_RUN_NOTICE
|
|
1008
1284
|
});
|
|
1009
1285
|
return;
|
|
@@ -1016,15 +1292,15 @@ async function payCommand(address, amountStr, options) {
|
|
|
1016
1292
|
if (options.wallet) printKeyValue("Wallet", options.wallet);
|
|
1017
1293
|
console.log("");
|
|
1018
1294
|
printSuccess("Input is valid");
|
|
1019
|
-
console.log(
|
|
1020
|
-
console.log(
|
|
1295
|
+
console.log(chalk3.dim(` Would send: POST ${url}`));
|
|
1296
|
+
console.log(chalk3.dim(` ${JSON.stringify({ ...validation.body, ...identity })}`));
|
|
1021
1297
|
if (!config.apiKey) {
|
|
1022
1298
|
printWarning('No API key configured. Run "conto login" before sending payments.');
|
|
1023
1299
|
}
|
|
1024
1300
|
console.log("");
|
|
1025
1301
|
printWarning(DRY_RUN_NOTICE);
|
|
1026
|
-
console.log(
|
|
1027
|
-
console.log(
|
|
1302
|
+
console.log(chalk3.dim(' Run "conto limits" to see current spend limits.'));
|
|
1303
|
+
console.log(chalk3.dim(" Run without --dry-run to submit the payment for policy evaluation."));
|
|
1028
1304
|
console.log("");
|
|
1029
1305
|
return;
|
|
1030
1306
|
}
|
|
@@ -1039,106 +1315,85 @@ async function payCommand(address, amountStr, options) {
|
|
|
1039
1315
|
process.exit(1);
|
|
1040
1316
|
}
|
|
1041
1317
|
const amount = validation.body.amount;
|
|
1042
|
-
const api =
|
|
1318
|
+
const api = new PaymentReviewClient({
|
|
1043
1319
|
baseUrl: config.baseUrl,
|
|
1044
1320
|
apiKey: config.apiKey
|
|
1045
1321
|
});
|
|
1322
|
+
const idempotencyKey = options.idempotencyKey ?? randomUUID();
|
|
1323
|
+
const payIdentity = { idempotencyKey };
|
|
1046
1324
|
try {
|
|
1047
1325
|
if (!isJsonMode()) {
|
|
1048
1326
|
printHeader("Payment Request");
|
|
1049
1327
|
printKeyValue("To", address);
|
|
1050
1328
|
printKeyValue("Amount", printAmount(amount, config.currency || "USD"));
|
|
1051
1329
|
if (options.purpose) printKeyValue("Purpose", options.purpose);
|
|
1052
|
-
console.log("");
|
|
1053
1330
|
}
|
|
1331
|
+
printRecoveryId("Idempotency key", idempotencyKey);
|
|
1332
|
+
if (!isJsonMode()) console.log("");
|
|
1054
1333
|
const request = await api.requestPayment({
|
|
1055
1334
|
amount,
|
|
1056
1335
|
recipientAddress: address,
|
|
1057
1336
|
purpose: options.purpose,
|
|
1058
1337
|
category: options.category,
|
|
1059
|
-
walletId: options.wallet
|
|
1338
|
+
walletId: options.wallet,
|
|
1339
|
+
...identity,
|
|
1340
|
+
idempotencyKey
|
|
1060
1341
|
});
|
|
1342
|
+
payIdentity.requestId = request.requestId;
|
|
1343
|
+
if (request.status === "COMPLETED" || request.status === "PROCESSING") {
|
|
1344
|
+
if (isJsonMode()) {
|
|
1345
|
+
printJson({ ...request, idempotencyKey });
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
printSuccess("This payment was already sent. No new payment was created.");
|
|
1349
|
+
printKeyValue("Status", request.status);
|
|
1350
|
+
printKeyValue("Request ID", request.requestId);
|
|
1351
|
+
console.log(chalk3.dim(` Check it with: conto pay status ${request.requestId}`));
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1061
1354
|
if (request.status === "DENIED") {
|
|
1062
1355
|
if (isJsonMode()) {
|
|
1063
|
-
printJson(request);
|
|
1356
|
+
printJson({ ...request, idempotencyKey });
|
|
1064
1357
|
return;
|
|
1065
1358
|
}
|
|
1066
1359
|
printError("Payment denied by policy");
|
|
1067
1360
|
if (request.violations) {
|
|
1068
1361
|
for (const v of request.violations) {
|
|
1069
|
-
console.log(
|
|
1362
|
+
console.log(chalk3.red(` ${v.message}`));
|
|
1070
1363
|
}
|
|
1071
1364
|
}
|
|
1072
1365
|
if (request.reasons.length > 0) {
|
|
1073
|
-
console.log(
|
|
1366
|
+
console.log(chalk3.dim(`
|
|
1074
1367
|
Reasons: ${request.reasons.join(", ")}`));
|
|
1075
1368
|
}
|
|
1076
1369
|
process.exit(1);
|
|
1077
1370
|
}
|
|
1078
1371
|
if (request.status === "REQUIRES_APPROVAL") {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
return;
|
|
1082
|
-
}
|
|
1083
|
-
printPending("Payment requires manual approval");
|
|
1084
|
-
printKeyValue("Request ID", request.requestId);
|
|
1085
|
-
console.log(chalk2.dim(" Approve in the Conto dashboard to execute."));
|
|
1086
|
-
return;
|
|
1372
|
+
printRecoveryId("Request ID", request.requestId);
|
|
1373
|
+
return await reviewAndSend(api, request.requestId, config, options, idempotencyKey);
|
|
1087
1374
|
}
|
|
1088
1375
|
if (request.status !== "APPROVED") {
|
|
1089
1376
|
if (isJsonMode()) {
|
|
1090
|
-
printJson(request);
|
|
1377
|
+
printJson({ ...request, idempotencyKey });
|
|
1091
1378
|
return;
|
|
1092
1379
|
}
|
|
1093
1380
|
printPending(`Payment is ${request.status}`);
|
|
1094
1381
|
printKeyValue("Request ID", request.requestId);
|
|
1095
1382
|
if (request.reasons.length > 0) {
|
|
1096
|
-
console.log(
|
|
1383
|
+
console.log(chalk3.dim(` Reasons: ${request.reasons.join(", ")}`));
|
|
1097
1384
|
}
|
|
1098
|
-
console.log(
|
|
1385
|
+
console.log(chalk3.dim(" Check the Conto dashboard for next steps."));
|
|
1099
1386
|
return;
|
|
1100
1387
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
printJson(result);
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
if (config.sandboxMode === "test") {
|
|
1107
|
-
printSuccess("Payment recorded in sandbox test mode");
|
|
1108
|
-
} else {
|
|
1109
|
-
printSuccess("Payment sent!");
|
|
1110
|
-
}
|
|
1111
|
-
if (result.receipt?.txHash) printKeyValue("TX Hash", result.receipt?.txHash);
|
|
1112
|
-
printKeyValue("Amount", printAmount(result.amount, result.currency));
|
|
1113
|
-
printKeyValue("Recipient", result.recipient);
|
|
1114
|
-
printKeyValue("Status", result.status);
|
|
1115
|
-
printKeyValue("Request ID", request.requestId);
|
|
1116
|
-
if (result.receipt?.settlementMode)
|
|
1117
|
-
printKeyValue("Settlement mode", result.receipt.settlementMode);
|
|
1118
|
-
if (result.receipt?.explorerUrl) printKeyValue("Explorer", result.receipt?.explorerUrl);
|
|
1119
|
-
console.log("");
|
|
1388
|
+
printRecoveryId("Request ID", request.requestId);
|
|
1389
|
+
await sendPayment(api, request.requestId, config, idempotencyKey);
|
|
1120
1390
|
} catch (err) {
|
|
1121
|
-
|
|
1122
|
-
const message = err instanceof Error ? err.message : "Payment failed";
|
|
1123
|
-
if (isJsonMode()) {
|
|
1124
|
-
printJson({ error: message, code });
|
|
1125
|
-
process.exit(1);
|
|
1126
|
-
}
|
|
1127
|
-
printError(message);
|
|
1128
|
-
if (code === "INSUFFICIENT_SCOPE") {
|
|
1129
|
-
console.log(
|
|
1130
|
-
chalk2.dim(' This SDK key cannot execute payments. Run "conto doctor" to see its scopes,')
|
|
1131
|
-
);
|
|
1132
|
-
console.log(chalk2.dim(" or create a new standard SDK key (includes payments:execute)."));
|
|
1133
|
-
} else if (code === "EXECUTION_UNAVAILABLE") {
|
|
1134
|
-
console.log(chalk2.dim(" Try again later or contact Conto support if the issue continues."));
|
|
1135
|
-
}
|
|
1136
|
-
process.exit(1);
|
|
1391
|
+
handlePayError(err, payIdentity);
|
|
1137
1392
|
}
|
|
1138
1393
|
}
|
|
1139
1394
|
|
|
1140
1395
|
// src/commands/transactions.ts
|
|
1141
|
-
async function transactionsCommand(
|
|
1396
|
+
async function transactionsCommand(id2, options) {
|
|
1142
1397
|
const config = loadConfig();
|
|
1143
1398
|
if (!config.apiKey) {
|
|
1144
1399
|
printError(missingSdkKeyMessage(config));
|
|
@@ -1149,8 +1404,8 @@ async function transactionsCommand(id, options) {
|
|
|
1149
1404
|
apiKey: config.apiKey
|
|
1150
1405
|
});
|
|
1151
1406
|
try {
|
|
1152
|
-
if (
|
|
1153
|
-
const tx = await api.getTransaction(
|
|
1407
|
+
if (id2) {
|
|
1408
|
+
const tx = await api.getTransaction(id2);
|
|
1154
1409
|
if (isJsonMode()) {
|
|
1155
1410
|
printJson(tx);
|
|
1156
1411
|
return;
|
|
@@ -1180,7 +1435,7 @@ async function transactionsCommand(id, options) {
|
|
|
1180
1435
|
if (tx.alerts && tx.alerts.length > 0) {
|
|
1181
1436
|
printHeader("Alerts");
|
|
1182
1437
|
for (const a of tx.alerts) {
|
|
1183
|
-
console.log(` [${a.severity.label}] ${a.title}
|
|
1438
|
+
console.log(` [${a.severity.label}] ${a.title}: ${a.status.label}`);
|
|
1184
1439
|
console.log(` ${a.message}`);
|
|
1185
1440
|
if (a.reviewUrl) console.log(` Review: ${a.reviewUrl}`);
|
|
1186
1441
|
}
|
|
@@ -1206,9 +1461,9 @@ async function transactionsCommand(id, options) {
|
|
|
1206
1461
|
new Date(tx.initiatedAt).toLocaleDateString(),
|
|
1207
1462
|
printAmount(Number(tx.amount), tx.currency),
|
|
1208
1463
|
tx.recipientAgent?.name || tx.merchantName || truncateAddress(tx.toAddress),
|
|
1209
|
-
tx.purpose || "
|
|
1464
|
+
tx.purpose || "-",
|
|
1210
1465
|
tx.status,
|
|
1211
|
-
tx.txHash ? truncateAddress(tx.txHash, 8) : "
|
|
1466
|
+
tx.txHash ? truncateAddress(tx.txHash, 8) : "-"
|
|
1212
1467
|
])
|
|
1213
1468
|
);
|
|
1214
1469
|
}
|
|
@@ -1225,7 +1480,7 @@ async function transactionsCommand(id, options) {
|
|
|
1225
1480
|
}
|
|
1226
1481
|
|
|
1227
1482
|
// src/commands/wallets.ts
|
|
1228
|
-
import
|
|
1483
|
+
import chalk4 from "chalk";
|
|
1229
1484
|
async function walletsCommand(subcommand, options = {}) {
|
|
1230
1485
|
const config = loadConfig();
|
|
1231
1486
|
if (!config.apiKey) {
|
|
@@ -1338,20 +1593,20 @@ async function walletsCommand(subcommand, options = {}) {
|
|
|
1338
1593
|
console.log("");
|
|
1339
1594
|
if (chainEntry?.faucetAvailable && config.testnet) {
|
|
1340
1595
|
console.log(
|
|
1341
|
-
|
|
1596
|
+
chalk4.cyan(
|
|
1342
1597
|
' This is a testnet wallet. Use "conto fund --faucet" to get free test tokens.'
|
|
1343
1598
|
)
|
|
1344
1599
|
);
|
|
1345
1600
|
console.log("");
|
|
1346
1601
|
} else {
|
|
1347
|
-
console.log(` To fund your agent wallet, send ${
|
|
1602
|
+
console.log(` To fund your agent wallet, send ${chalk4.bold(w.currency || "USD")} to:
|
|
1348
1603
|
`);
|
|
1349
|
-
console.log(
|
|
1604
|
+
console.log(chalk4.bold(` ${w.address}`));
|
|
1350
1605
|
console.log("");
|
|
1351
1606
|
const instructions = getFundingInstructions(w.currency || "USD", chainEntry);
|
|
1352
1607
|
console.log(` How to get ${w.currency || "USD"}:`);
|
|
1353
1608
|
for (const instruction of instructions) {
|
|
1354
|
-
console.log(` ${
|
|
1609
|
+
console.log(` ${chalk4.dim("\u2022")} ${instruction}`);
|
|
1355
1610
|
}
|
|
1356
1611
|
console.log("");
|
|
1357
1612
|
if (chainEntry) {
|
|
@@ -1403,7 +1658,7 @@ function getFundingInstructions(currency, chain) {
|
|
|
1403
1658
|
}
|
|
1404
1659
|
|
|
1405
1660
|
// src/commands/policies.ts
|
|
1406
|
-
import
|
|
1661
|
+
import chalk5 from "chalk";
|
|
1407
1662
|
import * as p from "@clack/prompts";
|
|
1408
1663
|
var POLICY_TYPES = [
|
|
1409
1664
|
{
|
|
@@ -1621,7 +1876,7 @@ var ACTIONS = [
|
|
|
1621
1876
|
hint: "Payment needs human approval if rule triggers"
|
|
1622
1877
|
}
|
|
1623
1878
|
];
|
|
1624
|
-
async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
1879
|
+
async function policiesCommand(subcommand = "list", idOrAmount, extra, reviewOptions = {}) {
|
|
1625
1880
|
const config = loadConfig();
|
|
1626
1881
|
if (!config.apiKey) {
|
|
1627
1882
|
printError(
|
|
@@ -1629,7 +1884,7 @@ async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
|
1629
1884
|
);
|
|
1630
1885
|
process.exit(1);
|
|
1631
1886
|
}
|
|
1632
|
-
const api =
|
|
1887
|
+
const api = createOwnerClient({
|
|
1633
1888
|
baseUrl: config.baseUrl,
|
|
1634
1889
|
apiKey: config.apiKey,
|
|
1635
1890
|
orgApiKey: config.orgApiKey
|
|
@@ -1647,13 +1902,13 @@ async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
|
1647
1902
|
printError("Usage: conto policies update <policy-id>");
|
|
1648
1903
|
process.exit(1);
|
|
1649
1904
|
}
|
|
1650
|
-
return await updatePolicy(api, idOrAmount);
|
|
1905
|
+
return await updatePolicy(api, idOrAmount, reviewOptions);
|
|
1651
1906
|
case "delete":
|
|
1652
1907
|
if (!idOrAmount) {
|
|
1653
1908
|
printError("Usage: conto policies delete <policy-id>");
|
|
1654
1909
|
process.exit(1);
|
|
1655
1910
|
}
|
|
1656
|
-
return await deletePolicy(api, idOrAmount);
|
|
1911
|
+
return await deletePolicy(api, idOrAmount, reviewOptions);
|
|
1657
1912
|
case "assign":
|
|
1658
1913
|
if (!idOrAmount) {
|
|
1659
1914
|
printError("Usage: conto policies assign <policy-id>");
|
|
@@ -1665,7 +1920,7 @@ async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
|
1665
1920
|
printError("Usage: conto policies unassign <policy-id>");
|
|
1666
1921
|
process.exit(1);
|
|
1667
1922
|
}
|
|
1668
|
-
return await unassignPolicy(api, config.agentId, idOrAmount);
|
|
1923
|
+
return await unassignPolicy(api, config.agentId, idOrAmount, reviewOptions);
|
|
1669
1924
|
case "add-rule":
|
|
1670
1925
|
if (!idOrAmount) {
|
|
1671
1926
|
printError("Usage: conto policies add-rule <policy-id>");
|
|
@@ -1677,7 +1932,25 @@ async function policiesCommand(subcommand = "list", idOrAmount, extra) {
|
|
|
1677
1932
|
printError("Usage: conto policies remove-rule <policy-id> <rule-id>");
|
|
1678
1933
|
process.exit(1);
|
|
1679
1934
|
}
|
|
1680
|
-
return await removeRule(api, idOrAmount, extra);
|
|
1935
|
+
return await removeRule(api, idOrAmount, extra, reviewOptions);
|
|
1936
|
+
case "versions":
|
|
1937
|
+
if (!idOrAmount) {
|
|
1938
|
+
printError("Usage: conto policies versions <policy-id>");
|
|
1939
|
+
process.exit(1);
|
|
1940
|
+
}
|
|
1941
|
+
return await listVersions(api, idOrAmount);
|
|
1942
|
+
case "rollback":
|
|
1943
|
+
if (!idOrAmount || !extra) {
|
|
1944
|
+
printError("Usage: conto policies rollback <policy-id> <version>");
|
|
1945
|
+
process.exit(1);
|
|
1946
|
+
}
|
|
1947
|
+
return await rollbackPolicy(api, idOrAmount, Number(extra), reviewOptions);
|
|
1948
|
+
case "simulate":
|
|
1949
|
+
if (!idOrAmount) {
|
|
1950
|
+
printError("Usage: conto policies simulate <policy-id>");
|
|
1951
|
+
process.exit(1);
|
|
1952
|
+
}
|
|
1953
|
+
return await simulatePolicy(api, idOrAmount);
|
|
1681
1954
|
case "help":
|
|
1682
1955
|
return printPolicyHelp();
|
|
1683
1956
|
default:
|
|
@@ -1707,21 +1980,21 @@ async function listAgentPolicies(api) {
|
|
|
1707
1980
|
}
|
|
1708
1981
|
printHeader("Agent Policies");
|
|
1709
1982
|
for (const policy of policies) {
|
|
1710
|
-
const scope = policy.scope === "organization" ?
|
|
1983
|
+
const scope = policy.scope === "organization" ? chalk5.dim("[organization]") : chalk5.cyan(`[${policy.appliesVia.join("+")}]`);
|
|
1711
1984
|
console.log(
|
|
1712
1985
|
`
|
|
1713
|
-
${
|
|
1986
|
+
${chalk5.bold(policy.name)} ${scope} ${chalk5.dim(`(${policy.policyType}, priority: ${policy.priority})`)}`
|
|
1714
1987
|
);
|
|
1715
|
-
console.log(` ${
|
|
1988
|
+
console.log(` ${chalk5.dim("ID:")} ${policy.id}`);
|
|
1716
1989
|
console.log(
|
|
1717
|
-
` ${
|
|
1990
|
+
` ${chalk5.dim("Active:")} ${policy.isActive ? chalk5.green("Yes") : chalk5.red("No")}`
|
|
1718
1991
|
);
|
|
1719
1992
|
if (policy.rules.length > 0) {
|
|
1720
|
-
console.log(` ${
|
|
1993
|
+
console.log(` ${chalk5.dim("Rules:")}`);
|
|
1721
1994
|
for (const rule of policy.rules) {
|
|
1722
1995
|
const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
|
|
1723
1996
|
console.log(
|
|
1724
|
-
` ${
|
|
1997
|
+
` ${chalk5.dim("\u2022")} ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
|
|
1725
1998
|
);
|
|
1726
1999
|
}
|
|
1727
2000
|
}
|
|
@@ -1744,18 +2017,18 @@ async function listAllPolicies(api) {
|
|
|
1744
2017
|
const scope = policy.scope === "organization" ? "organization-wide" : `${agentCount} agents`;
|
|
1745
2018
|
console.log(
|
|
1746
2019
|
`
|
|
1747
|
-
${
|
|
2020
|
+
${chalk5.bold(policy.name)} ${chalk5.dim(`(${policy.policyType}, priority: ${policy.priority}, ${scope})`)}`
|
|
1748
2021
|
);
|
|
1749
|
-
console.log(` ${
|
|
2022
|
+
console.log(` ${chalk5.dim("ID:")} ${policy.id}`);
|
|
1750
2023
|
console.log(
|
|
1751
|
-
` ${
|
|
2024
|
+
` ${chalk5.dim("Active:")} ${policy.isActive ? chalk5.green("Yes") : chalk5.red("No")}`
|
|
1752
2025
|
);
|
|
1753
2026
|
if (policy.rules.length > 0) {
|
|
1754
|
-
console.log(` ${
|
|
2027
|
+
console.log(` ${chalk5.dim("Rules:")}`);
|
|
1755
2028
|
for (const rule of policy.rules) {
|
|
1756
2029
|
const valueDisplay = formatRuleValue(rule.ruleType, rule.value);
|
|
1757
2030
|
console.log(
|
|
1758
|
-
` ${
|
|
2031
|
+
` ${chalk5.dim("\u2022")} [${rule.id.slice(-6)}] ${rule.ruleType} ${rule.operator} ${valueDisplay} \u2192 ${rule.action}`
|
|
1759
2032
|
);
|
|
1760
2033
|
}
|
|
1761
2034
|
}
|
|
@@ -1819,7 +2092,7 @@ async function createPolicy(api, agentId) {
|
|
|
1819
2092
|
if (assignToAgent) printSuccess("Assigned to current agent");
|
|
1820
2093
|
}
|
|
1821
2094
|
}
|
|
1822
|
-
async function updatePolicy(api, policyId) {
|
|
2095
|
+
async function updatePolicy(api, policyId, reviewOptions) {
|
|
1823
2096
|
const name = await p.text({
|
|
1824
2097
|
message: "New name (leave empty to skip)",
|
|
1825
2098
|
initialValue: ""
|
|
@@ -1857,22 +2130,63 @@ async function updatePolicy(api, policyId) {
|
|
|
1857
2130
|
printInfo("No changes to make.");
|
|
1858
2131
|
return;
|
|
1859
2132
|
}
|
|
1860
|
-
|
|
2133
|
+
let result;
|
|
2134
|
+
try {
|
|
2135
|
+
result = await api.updatePolicy(policyId, params);
|
|
2136
|
+
} catch (err) {
|
|
2137
|
+
if (!isTightenOnlyRefusal(err)) throw err;
|
|
2138
|
+
return proposePolicyUpdate(api, policyId, params, reviewOptions);
|
|
2139
|
+
}
|
|
1861
2140
|
if (isJsonMode()) {
|
|
1862
2141
|
printJson(result);
|
|
1863
2142
|
} else {
|
|
1864
2143
|
printSuccess(`Policy "${result.name}" updated`);
|
|
1865
2144
|
}
|
|
1866
2145
|
}
|
|
1867
|
-
async function
|
|
1868
|
-
|
|
2146
|
+
async function proposePolicyUpdate(api, policyId, params, reviewOptions) {
|
|
2147
|
+
if (params.scope !== void 0) {
|
|
2148
|
+
throw new Error("This key can't change a policy's scope. Change it in the dashboard.");
|
|
2149
|
+
}
|
|
2150
|
+
const proposals = [];
|
|
2151
|
+
if (params.name !== void 0 || params.priority !== void 0) {
|
|
2152
|
+
proposals.push({
|
|
2153
|
+
action: "update_policy",
|
|
2154
|
+
input: {
|
|
2155
|
+
policy_id: policyId,
|
|
2156
|
+
...params.name !== void 0 ? { name: params.name } : {},
|
|
2157
|
+
...params.priority !== void 0 ? { priority: params.priority } : {}
|
|
2158
|
+
},
|
|
2159
|
+
done: "Policy updated."
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
if (params.isActive !== void 0) {
|
|
2163
|
+
proposals.push({
|
|
2164
|
+
action: params.isActive ? "activate_policy" : "deactivate_policy",
|
|
2165
|
+
input: { policy_id: policyId },
|
|
2166
|
+
done: params.isActive ? "Policy turned on." : "Policy turned off."
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
for (const proposal of proposals) {
|
|
2170
|
+
const outcome = await proposeForReview(api, proposal.action, proposal.input, reviewOptions);
|
|
2171
|
+
reportReview(outcome, proposal.done);
|
|
2172
|
+
if (outcome.exitCode !== 0) return;
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
async function deletePolicy(api, policyId, reviewOptions) {
|
|
2176
|
+
const confirm3 = await p.confirm({
|
|
1869
2177
|
message: `Delete policy ${policyId}? This cannot be undone.`
|
|
1870
2178
|
});
|
|
1871
|
-
if (p.isCancel(
|
|
2179
|
+
if (p.isCancel(confirm3) || !confirm3) {
|
|
1872
2180
|
printInfo("Cancelled.");
|
|
1873
2181
|
return;
|
|
1874
2182
|
}
|
|
1875
|
-
await
|
|
2183
|
+
const result = await directOrReview(
|
|
2184
|
+
api,
|
|
2185
|
+
() => api.deletePolicy(policyId),
|
|
2186
|
+
async () => ({ action: "delete_policy", input: { policy_id: policyId } }),
|
|
2187
|
+
reviewOptions
|
|
2188
|
+
);
|
|
2189
|
+
if ("review" in result) return reportReview(result.review, `Policy ${policyId} deleted`);
|
|
1876
2190
|
printSuccess(`Policy ${policyId} deleted`);
|
|
1877
2191
|
}
|
|
1878
2192
|
async function assignPolicy(api, agentId, policyId) {
|
|
@@ -1883,8 +2197,19 @@ async function assignPolicy(api, agentId, policyId) {
|
|
|
1883
2197
|
printSuccess(`Policy ${policyId} assigned to agent`);
|
|
1884
2198
|
}
|
|
1885
2199
|
}
|
|
1886
|
-
async function unassignPolicy(api, agentId, policyId) {
|
|
1887
|
-
await
|
|
2200
|
+
async function unassignPolicy(api, agentId, policyId, reviewOptions) {
|
|
2201
|
+
const result = await directOrReview(
|
|
2202
|
+
api,
|
|
2203
|
+
() => api.unassignPolicyFromAgent(agentId, policyId),
|
|
2204
|
+
async () => ({
|
|
2205
|
+
action: "remove_policy_from_agent",
|
|
2206
|
+
input: { policy_id: policyId, agent_id: agentId }
|
|
2207
|
+
}),
|
|
2208
|
+
reviewOptions
|
|
2209
|
+
);
|
|
2210
|
+
if ("review" in result) {
|
|
2211
|
+
return reportReview(result.review, `Policy ${policyId} unassigned from agent`);
|
|
2212
|
+
}
|
|
1888
2213
|
if (isJsonMode()) {
|
|
1889
2214
|
printJson({ success: true, agentId, policyId });
|
|
1890
2215
|
} else {
|
|
@@ -1901,8 +2226,26 @@ async function addRule(api, policyId) {
|
|
|
1901
2226
|
printSuccess(`Rule "${rule.ruleType}" added to policy`);
|
|
1902
2227
|
}
|
|
1903
2228
|
}
|
|
1904
|
-
async function removeRule(api, policyId, ruleId) {
|
|
1905
|
-
await
|
|
2229
|
+
async function removeRule(api, policyId, ruleId, reviewOptions) {
|
|
2230
|
+
const result = await directOrReview(
|
|
2231
|
+
api,
|
|
2232
|
+
() => api.deletePolicyRule(policyId, ruleId),
|
|
2233
|
+
async () => {
|
|
2234
|
+
const { rules } = await api.listPolicyRules(policyId);
|
|
2235
|
+
if (!rules.some((rule) => rule.id === ruleId)) {
|
|
2236
|
+
throw new Error(`Rule ${ruleId} is not on policy ${policyId}.`);
|
|
2237
|
+
}
|
|
2238
|
+
return {
|
|
2239
|
+
action: "update_policy",
|
|
2240
|
+
input: {
|
|
2241
|
+
policy_id: policyId,
|
|
2242
|
+
rules: toToolRules(rules.filter((rule) => rule.id !== ruleId))
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
},
|
|
2246
|
+
reviewOptions
|
|
2247
|
+
);
|
|
2248
|
+
if ("review" in result) return reportReview(result.review, `Rule ${ruleId} removed from policy`);
|
|
1906
2249
|
if (isJsonMode()) {
|
|
1907
2250
|
printJson({ success: true, policyId, ruleId });
|
|
1908
2251
|
} else {
|
|
@@ -2003,8 +2346,8 @@ async function promptForRule(policyType) {
|
|
|
2003
2346
|
};
|
|
2004
2347
|
}
|
|
2005
2348
|
function printPolicyHelp() {
|
|
2006
|
-
console.log(
|
|
2007
|
-
console.log(
|
|
2349
|
+
console.log(chalk5.bold("\n Conto Policy Management\n"));
|
|
2350
|
+
console.log(chalk5.bold(" Commands:"));
|
|
2008
2351
|
console.log(" conto policies List agent policies");
|
|
2009
2352
|
console.log(" conto policies all List all org policies");
|
|
2010
2353
|
console.log(" conto policies create Create a new policy");
|
|
@@ -2015,11 +2358,11 @@ function printPolicyHelp() {
|
|
|
2015
2358
|
console.log(" conto policies add-rule <id> Add a rule");
|
|
2016
2359
|
console.log(" conto policies remove-rule <id> <rid> Remove a rule");
|
|
2017
2360
|
console.log(" conto policies help This help page");
|
|
2018
|
-
console.log(
|
|
2361
|
+
console.log(chalk5.bold("\n Policy Types:"));
|
|
2019
2362
|
for (const pt of POLICY_TYPES) {
|
|
2020
|
-
console.log(` ${
|
|
2363
|
+
console.log(` ${chalk5.cyan(pt.value.padEnd(22))} ${chalk5.dim(pt.hint)}`);
|
|
2021
2364
|
}
|
|
2022
|
-
console.log(
|
|
2365
|
+
console.log(chalk5.bold("\n Common Rule Types:"));
|
|
2023
2366
|
const commonRules = [
|
|
2024
2367
|
["MAX_AMOUNT", "Max per-transaction amount (e.g. 500)"],
|
|
2025
2368
|
["DAILY_LIMIT", "Max total spend per day (e.g. 1000)"],
|
|
@@ -2033,9 +2376,9 @@ function printPolicyHelp() {
|
|
|
2033
2376
|
["DATE_RANGE", 'JSON: {"start":"2025-01-01","end":"2025-12-31"}']
|
|
2034
2377
|
];
|
|
2035
2378
|
for (const [rule, desc] of commonRules) {
|
|
2036
|
-
console.log(` ${
|
|
2379
|
+
console.log(` ${chalk5.cyan(rule.padEnd(28))} ${chalk5.dim(desc)}`);
|
|
2037
2380
|
}
|
|
2038
|
-
console.log(
|
|
2381
|
+
console.log(chalk5.bold("\n Value Examples:"));
|
|
2039
2382
|
console.log(" Spend limits: 500");
|
|
2040
2383
|
console.log(' Address lists: ["0xabc...","0xdef..."]');
|
|
2041
2384
|
console.log(' Country codes: ["CU","IR","KP","SY","RU"]');
|
|
@@ -2043,24 +2386,24 @@ function printPolicyHelp() {
|
|
|
2043
2386
|
console.log(' Velocity: {"maxCount":5,"period":"HOUR"}');
|
|
2044
2387
|
console.log(' Date range: {"start":"2025-01-01","end":"2025-12-31"}');
|
|
2045
2388
|
console.log(' Categories: ["API_PROVIDER","CLOUD","SAAS"]');
|
|
2046
|
-
console.log(
|
|
2389
|
+
console.log(chalk5.bold("\n Operators:"));
|
|
2047
2390
|
console.log(" LTE (<= at most) GTE (>= at least) EQUALS NOT_EQUALS");
|
|
2048
2391
|
console.log(" IN_LIST NOT_IN_LIST BETWEEN DENY");
|
|
2049
|
-
console.log(
|
|
2050
|
-
console.log(` ${
|
|
2051
|
-
console.log(` ${
|
|
2052
|
-
console.log(` ${
|
|
2053
|
-
console.log(
|
|
2054
|
-
console.log(
|
|
2392
|
+
console.log(chalk5.bold("\n Actions:"));
|
|
2393
|
+
console.log(` ${chalk5.green("ALLOW")} Payment proceeds if rule passes`);
|
|
2394
|
+
console.log(` ${chalk5.red("DENY")} Payment is blocked`);
|
|
2395
|
+
console.log(` ${chalk5.yellow("REQUIRE_APPROVAL")} Payment needs human approval`);
|
|
2396
|
+
console.log(chalk5.bold("\n Examples:"));
|
|
2397
|
+
console.log(chalk5.dim(" # Create a $500/day spend limit"));
|
|
2055
2398
|
console.log(" conto policies create");
|
|
2056
|
-
console.log(
|
|
2399
|
+
console.log(chalk5.dim(" # Add a weekly limit rule to an existing policy"));
|
|
2057
2400
|
console.log(" conto policies add-rule cmn4abc123");
|
|
2058
|
-
console.log(
|
|
2401
|
+
console.log(chalk5.dim(" # Deactivate a policy without deleting"));
|
|
2059
2402
|
console.log(" conto policies update cmn4abc123");
|
|
2060
|
-
console.log(
|
|
2403
|
+
console.log(chalk5.dim(" # View all policies as JSON"));
|
|
2061
2404
|
console.log(" conto policies all --json");
|
|
2062
2405
|
console.log(`
|
|
2063
|
-
${
|
|
2406
|
+
${chalk5.dim("Full docs: https://conto.finance/docs/cli/policies")}
|
|
2064
2407
|
`);
|
|
2065
2408
|
}
|
|
2066
2409
|
function formatRuleValue(ruleType, value) {
|
|
@@ -2075,9 +2418,90 @@ function formatRuleValue(ruleType, value) {
|
|
|
2075
2418
|
}
|
|
2076
2419
|
return value;
|
|
2077
2420
|
}
|
|
2421
|
+
function toToolRules(rules) {
|
|
2422
|
+
return rules.map((rule) => ({
|
|
2423
|
+
rule_type: rule.ruleType,
|
|
2424
|
+
operator: rule.operator,
|
|
2425
|
+
value: rule.value,
|
|
2426
|
+
action: rule.action
|
|
2427
|
+
}));
|
|
2428
|
+
}
|
|
2429
|
+
async function listVersions(api, policyId) {
|
|
2430
|
+
const { versions } = await api.listPolicyVersions(policyId);
|
|
2431
|
+
if (isJsonMode()) return printJson(versions);
|
|
2432
|
+
if (versions.length === 0) return printInfo("This policy has no saved versions yet.");
|
|
2433
|
+
printHeader("Policy versions");
|
|
2434
|
+
for (const version of versions) {
|
|
2435
|
+
console.log(
|
|
2436
|
+
` ${chalk5.bold(`v${version.version}`)} ${version.changeType.toLowerCase()} ${chalk5.dim(
|
|
2437
|
+
new Date(version.createdAt).toLocaleString()
|
|
2438
|
+
)} ${version.rulesCount} rule${version.rulesCount === 1 ? "" : "s"}${version.note ? chalk5.dim(` ${version.note}`) : ""}`
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
console.log("");
|
|
2442
|
+
}
|
|
2443
|
+
async function rollbackPolicy(api, policyId, version, reviewOptions) {
|
|
2444
|
+
if (!Number.isInteger(version) || version < 1) {
|
|
2445
|
+
throw new Error(
|
|
2446
|
+
"Pass the version number to restore, for example: conto policies rollback <id> 3"
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
const result = await directOrReview(
|
|
2450
|
+
api,
|
|
2451
|
+
() => api.rollbackPolicyDirect(policyId, version),
|
|
2452
|
+
async () => {
|
|
2453
|
+
const { snapshot } = await api.getPolicyVersion(policyId, version);
|
|
2454
|
+
return {
|
|
2455
|
+
action: "update_policy",
|
|
2456
|
+
input: {
|
|
2457
|
+
policy_id: policyId,
|
|
2458
|
+
name: snapshot.name,
|
|
2459
|
+
description: snapshot.description,
|
|
2460
|
+
priority: snapshot.priority,
|
|
2461
|
+
rules: toToolRules(snapshot.rules)
|
|
2462
|
+
}
|
|
2463
|
+
};
|
|
2464
|
+
},
|
|
2465
|
+
reviewOptions
|
|
2466
|
+
);
|
|
2467
|
+
if ("review" in result) return reportReview(result.review, `Policy restored to v${version}`);
|
|
2468
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2469
|
+
printSuccess(`Policy restored to v${version}`);
|
|
2470
|
+
}
|
|
2471
|
+
async function simulatePolicy(api, policyId) {
|
|
2472
|
+
const policy = await api.getPolicy(policyId);
|
|
2473
|
+
const { summary, results } = await api.simulatePolicy({
|
|
2474
|
+
candidatePolicy: {
|
|
2475
|
+
name: policy.name,
|
|
2476
|
+
policyType: policy.policyType,
|
|
2477
|
+
rules: policy.rules.map((rule) => ({
|
|
2478
|
+
ruleType: rule.ruleType,
|
|
2479
|
+
operator: rule.operator,
|
|
2480
|
+
value: rule.value,
|
|
2481
|
+
action: rule.action
|
|
2482
|
+
}))
|
|
2483
|
+
}
|
|
2484
|
+
});
|
|
2485
|
+
if (isJsonMode()) return printJson({ summary, results });
|
|
2486
|
+
printHeader(`${policy.name} on your last ${summary.total} payments`);
|
|
2487
|
+
console.log(
|
|
2488
|
+
` ${summary.allow} allowed, ${summary.deny} blocked, ${summary.requireApproval} need approval`
|
|
2489
|
+
);
|
|
2490
|
+
console.log(
|
|
2491
|
+
chalk5.dim(` ${summary.newlyBlocked} newly blocked, ${summary.newlyAllowed} newly allowed`)
|
|
2492
|
+
);
|
|
2493
|
+
const changed = results.filter((row) => row.changed).slice(0, 10);
|
|
2494
|
+
for (const row of changed) {
|
|
2495
|
+
console.log(
|
|
2496
|
+
` ${row.amount} to ${row.recipient ?? "unknown"}: ${row.currentResult} -> ${row.wouldBe}${row.reasons[0] ? chalk5.dim(` ${row.reasons[0]}`) : ""}`
|
|
2497
|
+
);
|
|
2498
|
+
}
|
|
2499
|
+
console.log("");
|
|
2500
|
+
}
|
|
2078
2501
|
|
|
2079
2502
|
// src/commands/limits.ts
|
|
2080
|
-
import
|
|
2503
|
+
import chalk6 from "chalk";
|
|
2504
|
+
var UNLIMITED = "unlimited";
|
|
2081
2505
|
async function limitsCommand() {
|
|
2082
2506
|
const config = loadConfig();
|
|
2083
2507
|
if (!config.apiKey) {
|
|
@@ -2103,24 +2527,14 @@ async function limitsCommand() {
|
|
|
2103
2527
|
printHeader("Spending Limits");
|
|
2104
2528
|
for (const l of limits) {
|
|
2105
2529
|
console.log(`
|
|
2106
|
-
${
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2530
|
+
${chalk6.bold(l.walletName)}`);
|
|
2531
|
+
printWindow("Daily: ", l.daily);
|
|
2532
|
+
printWindow("Weekly: ", l.weekly);
|
|
2533
|
+
printWindow("Monthly: ", l.monthly);
|
|
2534
|
+
printKeyValue(
|
|
2535
|
+
" Per-TX max",
|
|
2536
|
+
l.perTransaction === null ? UNLIMITED : printAmount(l.perTransaction, "USD")
|
|
2110
2537
|
);
|
|
2111
|
-
if (l.weekly) {
|
|
2112
|
-
const weeklyPct = l.weekly.limit > 0 ? Math.round(l.weekly.spent / l.weekly.limit * 100) : 0;
|
|
2113
|
-
console.log(
|
|
2114
|
-
` ${chalk5.dim("Weekly:")} ${bar(weeklyPct)} ${printAmount(l.weekly.spent, "USD")} / ${printAmount(l.weekly.limit, "USD")} ${chalk5.dim(`(${printAmount(l.weekly.remaining, "USD")} remaining)`)}`
|
|
2115
|
-
);
|
|
2116
|
-
}
|
|
2117
|
-
if (l.monthly) {
|
|
2118
|
-
const monthlyPct = l.monthly.limit > 0 ? Math.round(l.monthly.spent / l.monthly.limit * 100) : 0;
|
|
2119
|
-
console.log(
|
|
2120
|
-
` ${chalk5.dim("Monthly:")} ${bar(monthlyPct)} ${printAmount(l.monthly.spent, "USD")} / ${printAmount(l.monthly.limit, "USD")} ${chalk5.dim(`(${printAmount(l.monthly.remaining, "USD")} remaining)`)}`
|
|
2121
|
-
);
|
|
2122
|
-
}
|
|
2123
|
-
printKeyValue(" Per-TX max", printAmount(l.perTransaction, "USD"));
|
|
2124
2538
|
}
|
|
2125
2539
|
console.log("");
|
|
2126
2540
|
} catch (err) {
|
|
@@ -2133,6 +2547,17 @@ async function limitsCommand() {
|
|
|
2133
2547
|
process.exit(1);
|
|
2134
2548
|
}
|
|
2135
2549
|
}
|
|
2550
|
+
function printWindow(label, window) {
|
|
2551
|
+
const spent = printAmount(window.spent, "USD");
|
|
2552
|
+
if (window.limit === null) {
|
|
2553
|
+
console.log(` ${chalk6.dim(label)} ${UNLIMITED} ${chalk6.dim(`(${spent} spent)`)}`);
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
const pct = window.limit > 0 ? Math.round(window.spent / window.limit * 100) : 0;
|
|
2557
|
+
console.log(
|
|
2558
|
+
` ${chalk6.dim(label)} ${bar(pct)} ${spent} / ${printAmount(window.limit, "USD")} ${chalk6.dim(`(${printAmount(window.remaining ?? 0, "USD")} remaining)`)}`
|
|
2559
|
+
);
|
|
2560
|
+
}
|
|
2136
2561
|
function bar(pct, width = 15) {
|
|
2137
2562
|
const filled = Math.round(pct / 100 * width);
|
|
2138
2563
|
const empty = width - filled;
|
|
@@ -2141,7 +2566,64 @@ function bar(pct, width = 15) {
|
|
|
2141
2566
|
}
|
|
2142
2567
|
|
|
2143
2568
|
// src/commands/alerts.ts
|
|
2144
|
-
import
|
|
2569
|
+
import chalk8 from "chalk";
|
|
2570
|
+
|
|
2571
|
+
// src/lib/owner-command.ts
|
|
2572
|
+
import chalk7 from "chalk";
|
|
2573
|
+
var LOGIN_HINT = 'This command needs your organization login. Run "conto login" (or set CONTO_ORG_API_KEY) and try again.';
|
|
2574
|
+
async function runOwnerCommand(needs, fn) {
|
|
2575
|
+
const config = loadConfig();
|
|
2576
|
+
if (needs === "org" && !config.orgApiKey) {
|
|
2577
|
+
fail(LOGIN_HINT, "ORG_KEY_REQUIRED");
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
if (needs === "sdk" && !config.apiKey) {
|
|
2581
|
+
fail(
|
|
2582
|
+
'Not configured. Run "npx @conto_finance/create-conto-agent" or "conto login" first.',
|
|
2583
|
+
"SDK_KEY_REQUIRED"
|
|
2584
|
+
);
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
const api = createOwnerClient({
|
|
2588
|
+
baseUrl: config.baseUrl,
|
|
2589
|
+
apiKey: config.apiKey,
|
|
2590
|
+
orgApiKey: config.orgApiKey
|
|
2591
|
+
});
|
|
2592
|
+
try {
|
|
2593
|
+
await fn({ api, config });
|
|
2594
|
+
} catch (err) {
|
|
2595
|
+
const error = err;
|
|
2596
|
+
if (error.status === 401) {
|
|
2597
|
+
fail(`${error.message}. ${LOGIN_HINT}`, error.code ?? "AUTH_FAILED");
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2600
|
+
fail(error.message || "Request failed", error.code, error.recovery);
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
function fail(message, code, recovery) {
|
|
2604
|
+
process.exitCode = 1;
|
|
2605
|
+
if (isJsonMode()) {
|
|
2606
|
+
printJson({
|
|
2607
|
+
ok: false,
|
|
2608
|
+
error: message,
|
|
2609
|
+
...code ? { code } : {},
|
|
2610
|
+
...recovery ? { recovery } : {}
|
|
2611
|
+
});
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
printError(message);
|
|
2615
|
+
if (recovery) console.log(chalk7.dim(` ${recovery}`));
|
|
2616
|
+
}
|
|
2617
|
+
function parseUsd(value, flag) {
|
|
2618
|
+
if (value === void 0) return void 0;
|
|
2619
|
+
const amount = Number(value);
|
|
2620
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
2621
|
+
throw new Error(`${flag} takes an amount in USD, for example 250`);
|
|
2622
|
+
}
|
|
2623
|
+
return amount;
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// src/commands/alerts.ts
|
|
2145
2627
|
async function alertsCommand(options = {}) {
|
|
2146
2628
|
const config = loadConfig();
|
|
2147
2629
|
if (!config.apiKey) {
|
|
@@ -2190,20 +2672,452 @@ async function alertsCommand(options = {}) {
|
|
|
2190
2672
|
function severityColor(severity) {
|
|
2191
2673
|
switch (severity.toUpperCase()) {
|
|
2192
2674
|
case "CRITICAL":
|
|
2193
|
-
return
|
|
2675
|
+
return chalk8.red.bold(severity);
|
|
2194
2676
|
case "HIGH":
|
|
2195
|
-
return
|
|
2677
|
+
return chalk8.red(severity);
|
|
2196
2678
|
case "MEDIUM":
|
|
2197
|
-
return
|
|
2679
|
+
return chalk8.yellow(severity);
|
|
2198
2680
|
case "LOW":
|
|
2199
|
-
return
|
|
2681
|
+
return chalk8.dim(severity);
|
|
2200
2682
|
default:
|
|
2201
2683
|
return severity;
|
|
2202
2684
|
}
|
|
2203
2685
|
}
|
|
2686
|
+
async function alertUpdateCommand(alertId, action) {
|
|
2687
|
+
await runOwnerCommand("sdk", async ({ api }) => {
|
|
2688
|
+
const result = await api.updateAlert(alertId, action);
|
|
2689
|
+
if (isJsonMode()) return printJson(result);
|
|
2690
|
+
printSuccess(action === "acknowledge" ? "Alert acknowledged." : "Alert resolved.");
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
// src/commands/agents.ts
|
|
2695
|
+
import * as p2 from "@clack/prompts";
|
|
2696
|
+
async function agentsListCommand() {
|
|
2697
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2698
|
+
const { agents } = await api.listAgents();
|
|
2699
|
+
if (isJsonMode()) return printJson(agents);
|
|
2700
|
+
if (agents.length === 0) return printInfo("No agents yet.");
|
|
2701
|
+
printHeader("Agents");
|
|
2702
|
+
printTable(
|
|
2703
|
+
["ID", "Name", "Status", "Wallets", "Payments"],
|
|
2704
|
+
agents.map((agent) => [
|
|
2705
|
+
agent.id,
|
|
2706
|
+
agent.name,
|
|
2707
|
+
agent.status,
|
|
2708
|
+
agent.linkedWalletCount ?? 0,
|
|
2709
|
+
agent.transactionCount ?? 0
|
|
2710
|
+
])
|
|
2711
|
+
);
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
async function agentsShowCommand(agentId) {
|
|
2715
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2716
|
+
const agent = await api.getAgent(agentId);
|
|
2717
|
+
if (isJsonMode()) return printJson(agent);
|
|
2718
|
+
printHeader(agent.name);
|
|
2719
|
+
printKeyValue("ID", agent.id);
|
|
2720
|
+
printKeyValue("Status", agent.status);
|
|
2721
|
+
if (agent.environment) printKeyValue("Environment", agent.environment);
|
|
2722
|
+
if (agent.owner?.name) printKeyValue("Owner", agent.owner.name);
|
|
2723
|
+
printKeyValue("Linked wallets", agent.linkedWalletCount ?? 0);
|
|
2724
|
+
printKeyValue("Payments", agent.transactionCount ?? 0);
|
|
2725
|
+
});
|
|
2726
|
+
}
|
|
2727
|
+
async function agentsPauseCommand(agentId) {
|
|
2728
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2729
|
+
const agent = await api.updateAgentStatus(agentId, "PAUSED");
|
|
2730
|
+
if (isJsonMode()) return printJson(agent);
|
|
2731
|
+
printSuccess(`Agent ${agent.name} is paused. Its key stops working for new payments.`);
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
async function agentsResumeCommand(agentId, options) {
|
|
2735
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2736
|
+
const result = await directOrReview(
|
|
2737
|
+
api,
|
|
2738
|
+
() => api.updateAgentStatus(agentId, "ACTIVE"),
|
|
2739
|
+
async () => ({ action: "activate_agent", input: { agent_id: agentId } }),
|
|
2740
|
+
options
|
|
2741
|
+
);
|
|
2742
|
+
if ("review" in result) return reportReview(result.review, "Agent resumed.");
|
|
2743
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2744
|
+
printSuccess(`Agent ${result.direct.name} is active again.`);
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
async function agentsFreezeCommand(agentId, options) {
|
|
2748
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2749
|
+
const result = await api.freezeAgent(agentId, {
|
|
2750
|
+
...options.reason ? { reason: options.reason } : {},
|
|
2751
|
+
freezeWallets: options.wallets === true
|
|
2752
|
+
});
|
|
2753
|
+
if (isJsonMode()) return printJson(result);
|
|
2754
|
+
printSuccess(
|
|
2755
|
+
options.wallets ? "Agent frozen, along with the wallets only it uses." : "Agent frozen. It cannot pay until the freeze is lifted."
|
|
2756
|
+
);
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
async function agentsUnfreezeCommand(agentId, options) {
|
|
2760
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2761
|
+
const result = await directOrReview(
|
|
2762
|
+
api,
|
|
2763
|
+
() => api.unfreezeAgent(agentId, {
|
|
2764
|
+
...options.reason ? { reason: options.reason } : {},
|
|
2765
|
+
unfreezeWallets: options.wallets === true
|
|
2766
|
+
}),
|
|
2767
|
+
async () => ({
|
|
2768
|
+
action: "activate_agent",
|
|
2769
|
+
input: {
|
|
2770
|
+
agent_id: agentId,
|
|
2771
|
+
restore_wallets: options.wallets === true,
|
|
2772
|
+
...options.reason ? { reason: options.reason } : {}
|
|
2773
|
+
}
|
|
2774
|
+
}),
|
|
2775
|
+
options
|
|
2776
|
+
);
|
|
2777
|
+
if ("review" in result) return reportReview(result.review, "Freeze lifted.");
|
|
2778
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2779
|
+
printSuccess("Freeze lifted. The agent can pay again within its limits.");
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
async function agentsDeleteCommand(agentId, options) {
|
|
2783
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2784
|
+
if (!options.yes) {
|
|
2785
|
+
if (!process.stdin.isTTY || isJsonMode()) {
|
|
2786
|
+
throw new Error("Deleting an agent cannot be undone. Pass --yes to confirm.");
|
|
2787
|
+
}
|
|
2788
|
+
const agent = await api.getAgent(agentId);
|
|
2789
|
+
const confirmed = await p2.confirm({
|
|
2790
|
+
message: `Delete agent ${agent.name}? Its keys stop working. This cannot be undone.`
|
|
2791
|
+
});
|
|
2792
|
+
if (p2.isCancel(confirmed) || !confirmed) return printInfo("Cancelled.");
|
|
2793
|
+
}
|
|
2794
|
+
const result = await directOrReview(
|
|
2795
|
+
api,
|
|
2796
|
+
() => api.deleteAgent(agentId),
|
|
2797
|
+
async () => ({ action: "delete_agent", input: { agent_id: agentId } }),
|
|
2798
|
+
options
|
|
2799
|
+
);
|
|
2800
|
+
if ("review" in result) return reportReview(result.review, "Agent deleted.");
|
|
2801
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2802
|
+
printSuccess("Agent deleted.");
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
async function agentsKeysListCommand(agentId) {
|
|
2806
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2807
|
+
const keys = await api.listSdkKeys(agentId);
|
|
2808
|
+
if (isJsonMode()) return printJson(keys);
|
|
2809
|
+
if (keys.length === 0) return printInfo("This agent has no SDK keys.");
|
|
2810
|
+
printHeader("SDK keys");
|
|
2811
|
+
printTable(
|
|
2812
|
+
["ID", "Name", "Prefix", "Type", "Status", "Last used"],
|
|
2813
|
+
keys.map((key) => [
|
|
2814
|
+
key.id,
|
|
2815
|
+
key.name,
|
|
2816
|
+
key.keyPrefix,
|
|
2817
|
+
key.keyType,
|
|
2818
|
+
key.revokedAt ? "revoked" : key.isActive ? "active" : "inactive",
|
|
2819
|
+
key.lastUsedAt ? new Date(key.lastUsedAt).toLocaleString() : "never"
|
|
2820
|
+
])
|
|
2821
|
+
);
|
|
2822
|
+
});
|
|
2823
|
+
}
|
|
2824
|
+
async function agentsKeysCreateCommand(agentId, options) {
|
|
2825
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2826
|
+
const name = options.name?.trim() || "CLI key";
|
|
2827
|
+
const result = await directOrReview(
|
|
2828
|
+
api,
|
|
2829
|
+
() => api.createSdkKeyDirect(agentId, name),
|
|
2830
|
+
async () => ({ action: "generate_sdk_key", input: { agent_id: agentId, key_name: name } }),
|
|
2831
|
+
options
|
|
2832
|
+
);
|
|
2833
|
+
if ("review" in result) return reportReview(result.review, `SDK key "${name}" created.`);
|
|
2834
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2835
|
+
printSuccess(`SDK key "${name}" created.`);
|
|
2836
|
+
printKeyValue("SDK key", result.direct.key);
|
|
2837
|
+
printWarning("This key is shown once. Store it now, for example as CONTO_API_KEY in .env.");
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2840
|
+
async function agentsKeysRevokeCommand(agentId, keyId) {
|
|
2841
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2842
|
+
const result = await api.revokeSdkKey(agentId, keyId);
|
|
2843
|
+
if (isJsonMode()) return printJson(result);
|
|
2844
|
+
printSuccess("SDK key revoked. It stops working right away.");
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
// src/commands/wallet-controls.ts
|
|
2849
|
+
var PERIODS = [
|
|
2850
|
+
["perTx", "per_tx", "PerTx"],
|
|
2851
|
+
["daily", "daily", "Daily"],
|
|
2852
|
+
["weekly", "weekly", "Weekly"],
|
|
2853
|
+
["monthly", "monthly", "Monthly"]
|
|
2854
|
+
];
|
|
2855
|
+
function readLimits(options) {
|
|
2856
|
+
const body = {};
|
|
2857
|
+
const input = {};
|
|
2858
|
+
for (const [flag, snake, camel] of PERIODS) {
|
|
2859
|
+
const amount = parseUsd(options[flag], `--${flag === "perTx" ? "per-tx" : flag}`);
|
|
2860
|
+
if (amount === void 0) continue;
|
|
2861
|
+
body[`spendLimit${camel}`] = amount;
|
|
2862
|
+
input[`spend_limit_${snake}`] = amount;
|
|
2863
|
+
}
|
|
2864
|
+
if (options.clearWeekly) {
|
|
2865
|
+
body.spendLimitWeekly = null;
|
|
2866
|
+
input.remove_weekly_limit = true;
|
|
2867
|
+
}
|
|
2868
|
+
if (options.clearMonthly) {
|
|
2869
|
+
body.spendLimitMonthly = null;
|
|
2870
|
+
input.remove_monthly_limit = true;
|
|
2871
|
+
}
|
|
2872
|
+
return { body, input };
|
|
2873
|
+
}
|
|
2874
|
+
async function walletFreezeCommand(walletId) {
|
|
2875
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2876
|
+
const wallet = await api.updateWallet(walletId, "FROZEN");
|
|
2877
|
+
if (isJsonMode()) return printJson(wallet);
|
|
2878
|
+
printSuccess("Wallet frozen. No agent can pay from it until it is unfrozen.");
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
async function walletUnfreezeCommand(walletId, options) {
|
|
2882
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2883
|
+
const result = await directOrReview(
|
|
2884
|
+
api,
|
|
2885
|
+
() => api.updateWallet(walletId, "ACTIVE"),
|
|
2886
|
+
async () => ({ action: "reactivate_wallet", input: { wallet_id: walletId } }),
|
|
2887
|
+
options
|
|
2888
|
+
);
|
|
2889
|
+
if ("review" in result) return reportReview(result.review, "Wallet unfrozen.");
|
|
2890
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2891
|
+
printSuccess("Wallet unfrozen. Linked agents can pay from it again.");
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
async function walletLinkCommand(agentId, walletId, options) {
|
|
2895
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2896
|
+
const { body, input } = readLimits(options);
|
|
2897
|
+
const delegation = options.delegation?.toUpperCase();
|
|
2898
|
+
const result = await directOrReview(
|
|
2899
|
+
api,
|
|
2900
|
+
() => api.linkWallet(agentId, {
|
|
2901
|
+
walletId,
|
|
2902
|
+
...body,
|
|
2903
|
+
...delegation ? { delegationType: delegation } : {}
|
|
2904
|
+
}),
|
|
2905
|
+
async () => ({
|
|
2906
|
+
action: "link_wallet_to_agent",
|
|
2907
|
+
input: {
|
|
2908
|
+
agent_id: agentId,
|
|
2909
|
+
wallet_id: walletId,
|
|
2910
|
+
...input,
|
|
2911
|
+
...delegation ? { delegation_type: delegation } : {}
|
|
2912
|
+
}
|
|
2913
|
+
}),
|
|
2914
|
+
options
|
|
2915
|
+
);
|
|
2916
|
+
if ("review" in result) return reportReview(result.review, "Wallet linked.");
|
|
2917
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2918
|
+
printSuccess("Wallet linked. The agent can spend from it within the limits set.");
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
async function walletUnlinkCommand(agentId, walletId) {
|
|
2922
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2923
|
+
const result = await api.unlinkWallet(agentId, walletId);
|
|
2924
|
+
if (isJsonMode()) return printJson(result);
|
|
2925
|
+
printSuccess("Wallet unlinked. The agent can no longer spend from it.");
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
async function walletLimitsCommand(agentId, walletId, options) {
|
|
2929
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2930
|
+
const { body, input } = readLimits(options);
|
|
2931
|
+
if (Object.keys(body).length === 0) {
|
|
2932
|
+
throw new Error(
|
|
2933
|
+
"Pass at least one limit: --per-tx, --daily, --weekly, --monthly, --clear-weekly, or --clear-monthly."
|
|
2934
|
+
);
|
|
2935
|
+
}
|
|
2936
|
+
const result = await directOrReview(
|
|
2937
|
+
api,
|
|
2938
|
+
() => api.updateWalletLink(agentId, walletId, body),
|
|
2939
|
+
async () => ({
|
|
2940
|
+
action: "update_agent_wallet_limits",
|
|
2941
|
+
input: { agent_id: agentId, wallet_id: walletId, ...input }
|
|
2942
|
+
}),
|
|
2943
|
+
options
|
|
2944
|
+
);
|
|
2945
|
+
if ("review" in result) return reportReview(result.review, "Limits updated.");
|
|
2946
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
2947
|
+
printSuccess("Limits updated.");
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
// src/commands/counterparties.ts
|
|
2952
|
+
async function counterpartiesListCommand() {
|
|
2953
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2954
|
+
const { counterparties } = await api.listCounterparties();
|
|
2955
|
+
if (isJsonMode()) return printJson(counterparties);
|
|
2956
|
+
if (counterparties.length === 0) return printInfo("No payees yet.");
|
|
2957
|
+
printHeader("Payees");
|
|
2958
|
+
printTable(
|
|
2959
|
+
["ID", "Name", "Address", "Status", "Trust"],
|
|
2960
|
+
counterparties.map((payee) => [
|
|
2961
|
+
payee.id,
|
|
2962
|
+
payee.name,
|
|
2963
|
+
payee.address ? truncateAddress(payee.address) : "",
|
|
2964
|
+
payee.lifecycleStatus,
|
|
2965
|
+
`${payee.trustLevel} (${payee.trustScore})`
|
|
2966
|
+
])
|
|
2967
|
+
);
|
|
2968
|
+
});
|
|
2969
|
+
}
|
|
2970
|
+
async function counterpartiesShowCommand(id2) {
|
|
2971
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2972
|
+
const payee = await api.getCounterparty(id2);
|
|
2973
|
+
if (isJsonMode()) return printJson(payee);
|
|
2974
|
+
printHeader(payee.name);
|
|
2975
|
+
printKeyValue("ID", payee.id);
|
|
2976
|
+
if (payee.address) printKeyValue("Address", payee.address);
|
|
2977
|
+
printKeyValue("Type", payee.type);
|
|
2978
|
+
printKeyValue("Status", payee.lifecycleStatus);
|
|
2979
|
+
printKeyValue("Trust", `${payee.trustLevel} (${payee.trustScore})`);
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2982
|
+
async function counterpartiesAddCommand(options) {
|
|
2983
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
2984
|
+
if (!options.name || !options.address) {
|
|
2985
|
+
throw new Error("Pass --name and --address.");
|
|
2986
|
+
}
|
|
2987
|
+
const payee = await api.createCounterparty({
|
|
2988
|
+
name: options.name,
|
|
2989
|
+
address: options.address,
|
|
2990
|
+
...options.type ? { type: options.type.toUpperCase() } : {},
|
|
2991
|
+
...options.category ? { category: options.category } : {}
|
|
2992
|
+
});
|
|
2993
|
+
if (isJsonMode()) return printJson(payee);
|
|
2994
|
+
printSuccess(`Payee ${payee.name} added. It stays pending until it is approved.`);
|
|
2995
|
+
printKeyValue("ID", payee.id);
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
async function counterpartiesBlockCommand(id2) {
|
|
2999
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3000
|
+
const payee = await api.updateCounterparty(id2, { lifecycleStatus: "BLOCKED" });
|
|
3001
|
+
if (isJsonMode()) return printJson(payee);
|
|
3002
|
+
printSuccess(`Payee ${payee.name} is blocked. Agents cannot pay it.`);
|
|
3003
|
+
});
|
|
3004
|
+
}
|
|
3005
|
+
async function counterpartiesApproveCommand(id2, options) {
|
|
3006
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3007
|
+
const result = await directOrReview(
|
|
3008
|
+
api,
|
|
3009
|
+
() => api.updateCounterparty(id2, { lifecycleStatus: "APPROVED" }),
|
|
3010
|
+
async () => ({
|
|
3011
|
+
action: "set_counterparty_status",
|
|
3012
|
+
input: {
|
|
3013
|
+
counterparty_id: id2,
|
|
3014
|
+
status: "APPROVED",
|
|
3015
|
+
...options.reason ? { reason: options.reason } : {}
|
|
3016
|
+
}
|
|
3017
|
+
}),
|
|
3018
|
+
options
|
|
3019
|
+
);
|
|
3020
|
+
if ("review" in result) return reportReview(result.review, "Payee approved.");
|
|
3021
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
3022
|
+
printSuccess(`Payee ${result.direct.name} is approved.`);
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
// src/commands/channels.ts
|
|
3027
|
+
import { randomBytes } from "crypto";
|
|
3028
|
+
async function channelsListCommand() {
|
|
3029
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3030
|
+
const { channels } = await api.listChannels();
|
|
3031
|
+
if (isJsonMode()) return printJson(channels);
|
|
3032
|
+
if (channels.length === 0) return printInfo("No event delivery channels yet.");
|
|
3033
|
+
printHeader("Event delivery channels");
|
|
3034
|
+
printTable(
|
|
3035
|
+
["ID", "Name", "Type", "Sends to", "Events", "Status"],
|
|
3036
|
+
channels.map((channel) => [
|
|
3037
|
+
channel.id,
|
|
3038
|
+
channel.name,
|
|
3039
|
+
channel.channelType,
|
|
3040
|
+
channel.destination ?? "",
|
|
3041
|
+
channel.eventTypes.join(", "),
|
|
3042
|
+
channel.needsAttention ? "needs attention" : channel.isActive ? "active" : "off"
|
|
3043
|
+
])
|
|
3044
|
+
);
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3047
|
+
async function channelsAddCommand(options) {
|
|
3048
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3049
|
+
const type = options.type?.toUpperCase();
|
|
3050
|
+
if (!options.name || !type) throw new Error("Pass --name and --type (email or webhook).");
|
|
3051
|
+
let config;
|
|
3052
|
+
let generatedSecret;
|
|
3053
|
+
if (type === "EMAIL") {
|
|
3054
|
+
const recipients = (options.recipients ?? "").split(",").map((email) => email.trim()).filter(Boolean);
|
|
3055
|
+
if (recipients.length === 0) throw new Error("Pass --recipients with one or more emails.");
|
|
3056
|
+
config = { recipients };
|
|
3057
|
+
} else if (type === "WEBHOOK") {
|
|
3058
|
+
if (!options.url) throw new Error("Pass --url with the https address to send events to.");
|
|
3059
|
+
if (!process.env.CONTO_WEBHOOK_SECRET) generatedSecret = randomBytes(32).toString("hex");
|
|
3060
|
+
config = { url: options.url, secret: process.env.CONTO_WEBHOOK_SECRET || generatedSecret };
|
|
3061
|
+
} else {
|
|
3062
|
+
throw new Error(
|
|
3063
|
+
"The CLI adds email and webhook channels. Add Slack, Telegram or WhatsApp in Settings > Event Delivery."
|
|
3064
|
+
);
|
|
3065
|
+
}
|
|
3066
|
+
const eventTypes = options.events?.split(",").map((event) => event.trim()).filter(Boolean);
|
|
3067
|
+
const created = await api.createChannel({
|
|
3068
|
+
channelType: type,
|
|
3069
|
+
name: options.name,
|
|
3070
|
+
config,
|
|
3071
|
+
...eventTypes?.length ? { eventTypes } : {}
|
|
3072
|
+
});
|
|
3073
|
+
if (isJsonMode()) {
|
|
3074
|
+
return printJson({
|
|
3075
|
+
...created,
|
|
3076
|
+
...generatedSecret ? { webhookSecret: generatedSecret } : {}
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
printSuccess(`Channel ${options.name} added.`);
|
|
3080
|
+
if (generatedSecret) {
|
|
3081
|
+
printKeyValue("Signing secret", generatedSecret);
|
|
3082
|
+
printWarning("Store this secret now to verify event signatures. It is not shown again.");
|
|
3083
|
+
}
|
|
3084
|
+
});
|
|
3085
|
+
}
|
|
3086
|
+
async function channelsTestCommand(id2) {
|
|
3087
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3088
|
+
const result = await api.testChannel(id2);
|
|
3089
|
+
if (isJsonMode()) return printJson(result);
|
|
3090
|
+
printSuccess("Test event sent.");
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
async function channelsRemoveCommand(id2, options) {
|
|
3094
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3095
|
+
const result = await directOrReview(
|
|
3096
|
+
api,
|
|
3097
|
+
() => api.deleteChannel(id2),
|
|
3098
|
+
async () => ({ action: "remove_notification_channel", input: { channel_id: id2 } }),
|
|
3099
|
+
options
|
|
3100
|
+
);
|
|
3101
|
+
if ("review" in result) return reportReview(result.review, "Channel removed.");
|
|
3102
|
+
if (isJsonMode()) return printJson(result.direct);
|
|
3103
|
+
printSuccess("Channel removed.");
|
|
3104
|
+
});
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
// src/commands/changes.ts
|
|
3108
|
+
async function changesStatusCommand(changeId, options) {
|
|
3109
|
+
await runOwnerCommand("org", async ({ api }) => {
|
|
3110
|
+
const change = await api.getOwnerAction(changeId);
|
|
3111
|
+
const outcome = await followChange(api, change, { open: false, wait: false, ...options });
|
|
3112
|
+
reportReview(
|
|
3113
|
+
outcome,
|
|
3114
|
+
change.change.action ? `${change.change.action}: done.` : "Change applied."
|
|
3115
|
+
);
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
2204
3118
|
|
|
2205
3119
|
// src/commands/config.ts
|
|
2206
|
-
import
|
|
3120
|
+
import chalk9 from "chalk";
|
|
2207
3121
|
var FORBIDDEN_CONFIG_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
2208
3122
|
function isSafeConfigPath(parts) {
|
|
2209
3123
|
return parts.length > 0 && parts.every(
|
|
@@ -2244,34 +3158,59 @@ async function configCommand(key, value) {
|
|
|
2244
3158
|
return;
|
|
2245
3159
|
}
|
|
2246
3160
|
printHeader("Configuration");
|
|
2247
|
-
printKeyValue("API Key", config.apiKey ? maskSecret(config.apiKey) :
|
|
3161
|
+
printKeyValue("API Key", config.apiKey ? maskSecret(config.apiKey) : chalk9.dim("not set"));
|
|
2248
3162
|
printKeyValue(
|
|
2249
3163
|
"Organization credential expires",
|
|
2250
|
-
config.orgApiKeyExpiresAt ||
|
|
3164
|
+
config.orgApiKeyExpiresAt || chalk9.dim("not recorded")
|
|
2251
3165
|
);
|
|
2252
3166
|
printKeyValue("Base URL", config.baseUrl);
|
|
2253
|
-
printKeyValue("Agent ID", config.agentId ||
|
|
2254
|
-
printKeyValue("Chain", config.chainName ||
|
|
2255
|
-
printKeyValue("Chain ID", config.chainId ||
|
|
2256
|
-
printKeyValue("Currency", config.currency ||
|
|
2257
|
-
printKeyValue("Explorer", config.explorerUrl ||
|
|
2258
|
-
printKeyValue("Wallet ID", config.walletId ||
|
|
2259
|
-
printKeyValue("Wallet Address", config.walletAddress ||
|
|
3167
|
+
printKeyValue("Agent ID", config.agentId || chalk9.dim("not set"));
|
|
3168
|
+
printKeyValue("Chain", config.chainName || chalk9.dim("not set"));
|
|
3169
|
+
printKeyValue("Chain ID", config.chainId || chalk9.dim("not set"));
|
|
3170
|
+
printKeyValue("Currency", config.currency || chalk9.dim("not set"));
|
|
3171
|
+
printKeyValue("Explorer", config.explorerUrl || chalk9.dim("not set"));
|
|
3172
|
+
printKeyValue("Wallet ID", config.walletId || chalk9.dim("not set"));
|
|
3173
|
+
printKeyValue("Wallet Address", config.walletAddress || chalk9.dim("not set"));
|
|
2260
3174
|
printKeyValue("Testnet", config.testnet ? "Yes" : "No");
|
|
2261
3175
|
console.log("");
|
|
2262
|
-
console.log(
|
|
2263
|
-
console.log(
|
|
3176
|
+
console.log(chalk9.dim(" Config sources: ~/.conto/config.json + .env.local"));
|
|
3177
|
+
console.log(chalk9.dim(" Update with: conto config <key> <value>"));
|
|
2264
3178
|
console.log("");
|
|
2265
3179
|
}
|
|
2266
3180
|
|
|
2267
3181
|
// src/commands/login.ts
|
|
3182
|
+
var DEFAULT_BASE_URL = "https://conto.finance";
|
|
3183
|
+
function isSameServer(a, b) {
|
|
3184
|
+
try {
|
|
3185
|
+
return normalizeBaseUrl(a) === normalizeBaseUrl(b);
|
|
3186
|
+
} catch {
|
|
3187
|
+
return false;
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
2268
3190
|
async function loginCommand(options = {}) {
|
|
2269
3191
|
const existingConfig = loadGlobalConfig();
|
|
2270
|
-
const baseUrl = options.baseUrl || existingConfig.server?.baseUrl ||
|
|
3192
|
+
const baseUrl = options.baseUrl || existingConfig.server?.baseUrl || DEFAULT_BASE_URL;
|
|
2271
3193
|
printInfo("Opening browser to authenticate...");
|
|
2272
3194
|
try {
|
|
2273
|
-
const { orgApiKey, organizationName, expiresAt } = await browserAuth(
|
|
3195
|
+
const { orgApiKey, organizationName, expiresAt } = await browserAuth(
|
|
3196
|
+
baseUrl,
|
|
3197
|
+
(authUrl) => printInfo(`If the browser does not open, visit: ${authUrl}`)
|
|
3198
|
+
);
|
|
2274
3199
|
const config = loadGlobalConfig();
|
|
3200
|
+
const previousBaseUrl = config.server?.baseUrl || DEFAULT_BASE_URL;
|
|
3201
|
+
if (!isSameServer(previousBaseUrl, baseUrl)) {
|
|
3202
|
+
const hadAgent = Boolean(config.server?.apiKey || config.agent);
|
|
3203
|
+
delete config.agent;
|
|
3204
|
+
delete config.wallet;
|
|
3205
|
+
delete config.network;
|
|
3206
|
+
delete config.sandbox;
|
|
3207
|
+
config.server = { baseUrl };
|
|
3208
|
+
if (hadAgent) {
|
|
3209
|
+
printInfo(
|
|
3210
|
+
`Removed the agent key saved for ${previousBaseUrl}. Run "conto init" to set up an agent on ${baseUrl}.`
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
2275
3214
|
if (!config.server) {
|
|
2276
3215
|
config.server = { baseUrl };
|
|
2277
3216
|
}
|
|
@@ -2324,7 +3263,7 @@ async function mcpCommand() {
|
|
|
2324
3263
|
}
|
|
2325
3264
|
|
|
2326
3265
|
// src/commands/webhooks.ts
|
|
2327
|
-
import { createHmac, randomUUID } from "crypto";
|
|
3266
|
+
import { createHmac, randomUUID as randomUUID2 } from "crypto";
|
|
2328
3267
|
async function testWebhook(url) {
|
|
2329
3268
|
const started = Date.now();
|
|
2330
3269
|
try {
|
|
@@ -2339,13 +3278,13 @@ async function testWebhook(url) {
|
|
|
2339
3278
|
);
|
|
2340
3279
|
const event = "payment.confirmed";
|
|
2341
3280
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
2342
|
-
const paymentId = `test_${
|
|
3281
|
+
const paymentId = `test_${randomUUID2()}`;
|
|
2343
3282
|
const body = JSON.stringify({
|
|
2344
3283
|
event,
|
|
2345
3284
|
timestamp,
|
|
2346
3285
|
data: {
|
|
2347
3286
|
paymentId,
|
|
2348
|
-
transactionId: `test_${
|
|
3287
|
+
transactionId: `test_${randomUUID2()}`,
|
|
2349
3288
|
agentId: "test_agent",
|
|
2350
3289
|
transactionHash: `0x${"0".repeat(64)}`,
|
|
2351
3290
|
amount: 0.01,
|
|
@@ -2397,15 +3336,15 @@ async function testWebhook(url) {
|
|
|
2397
3336
|
// src/commands/sandbox.ts
|
|
2398
3337
|
import fs2 from "fs";
|
|
2399
3338
|
import path from "path";
|
|
2400
|
-
import { setTimeout as
|
|
2401
|
-
import
|
|
3339
|
+
import { setTimeout as sleep2 } from "timers/promises";
|
|
3340
|
+
import chalk10 from "chalk";
|
|
2402
3341
|
|
|
2403
3342
|
// src/lib/sandbox-handoff-client.ts
|
|
2404
3343
|
var HANDOFF_PATH = "/api/agents/sandbox/handoff";
|
|
2405
3344
|
var DEFAULT_POLL_INTERVAL_SECONDS = 5;
|
|
2406
3345
|
var MIN_POLL_INTERVAL_SECONDS = 1;
|
|
2407
3346
|
var MAX_POLL_INTERVAL_SECONDS = 60;
|
|
2408
|
-
var
|
|
3347
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
2409
3348
|
var SANDBOX_ORG_KEY_PATTERN = /^conto_[a-f0-9]{64}$/;
|
|
2410
3349
|
var HANDOFF_TOKEN_PATTERN = /^conto_claim_[a-f0-9]{64}$/;
|
|
2411
3350
|
function isHandoffToken(value) {
|
|
@@ -2509,7 +3448,7 @@ async function initiateHandoff(input) {
|
|
|
2509
3448
|
url: apiUrl(input.baseUrl, HANDOFF_PATH),
|
|
2510
3449
|
method: "POST",
|
|
2511
3450
|
bearer: input.sandboxKey,
|
|
2512
|
-
timeoutMs:
|
|
3451
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
2513
3452
|
signal: input.signal
|
|
2514
3453
|
});
|
|
2515
3454
|
} catch (error) {
|
|
@@ -2560,7 +3499,7 @@ async function inspectHandoff(input) {
|
|
|
2560
3499
|
url: apiUrl(input.baseUrl, input.statusPath),
|
|
2561
3500
|
method: "GET",
|
|
2562
3501
|
bearer: input.token,
|
|
2563
|
-
timeoutMs:
|
|
3502
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
2564
3503
|
signal: input.signal
|
|
2565
3504
|
});
|
|
2566
3505
|
} catch (error) {
|
|
@@ -2644,8 +3583,8 @@ var SANDBOX_CLAIM_EXIT_CODES = {
|
|
|
2644
3583
|
rateLimited: 5,
|
|
2645
3584
|
interrupted: 130
|
|
2646
3585
|
};
|
|
2647
|
-
var
|
|
2648
|
-
var
|
|
3586
|
+
var DEFAULT_BASE_URL2 = "https://conto.finance";
|
|
3587
|
+
var DEFAULT_WAIT_SECONDS2 = 300;
|
|
2649
3588
|
var MAX_WAIT_SECONDS = 3600;
|
|
2650
3589
|
var MAX_CONSECUTIVE_POLL_ERRORS = 3;
|
|
2651
3590
|
var TEST_MODE_AFTER_CLAIM = {
|
|
@@ -2714,7 +3653,7 @@ function resolveSandboxCredential(command) {
|
|
|
2714
3653
|
})
|
|
2715
3654
|
};
|
|
2716
3655
|
}
|
|
2717
|
-
const baseUrl = fromProcess ? process.env.CONTO_BASE_URL ||
|
|
3656
|
+
const baseUrl = fromProcess ? process.env.CONTO_BASE_URL || DEFAULT_BASE_URL2 : process.env.CONTO_BASE_URL || env.CONTO_BASE_URL || DEFAULT_BASE_URL2;
|
|
2718
3657
|
try {
|
|
2719
3658
|
parseSecureBaseUrl(baseUrl);
|
|
2720
3659
|
} catch (error) {
|
|
@@ -2844,7 +3783,7 @@ function pendingFields(state, options) {
|
|
|
2844
3783
|
function printHandoff(state, reused, cli) {
|
|
2845
3784
|
console.log("");
|
|
2846
3785
|
console.log(
|
|
2847
|
-
` ${
|
|
3786
|
+
` ${chalk10.bold("Sandbox claim link")} ${chalk10.dim(`(expires ${state.expiresAt})`)}${reused ? chalk10.dim(" reused") : ""}`
|
|
2848
3787
|
);
|
|
2849
3788
|
console.log("");
|
|
2850
3789
|
console.log(` ${state.verificationUrl}`);
|
|
@@ -2859,7 +3798,7 @@ function printHandoff(state, reused, cli) {
|
|
|
2859
3798
|
printInfo(`Check the status: ${cli} sandbox claim-status`);
|
|
2860
3799
|
}
|
|
2861
3800
|
function parseWaitSeconds(timeout) {
|
|
2862
|
-
if (timeout === void 0) return { ok: true, seconds:
|
|
3801
|
+
if (timeout === void 0) return { ok: true, seconds: DEFAULT_WAIT_SECONDS2 };
|
|
2863
3802
|
if (!/^\d+$/.test(timeout)) {
|
|
2864
3803
|
return { ok: false, message: "--timeout takes a whole number of seconds." };
|
|
2865
3804
|
}
|
|
@@ -2883,7 +3822,7 @@ async function waitForClaim(credential, state, timeoutSeconds, stats) {
|
|
|
2883
3822
|
const remaining = deadline - Date.now();
|
|
2884
3823
|
if (remaining <= 0) return { kind: "timeout", lastRetryAfterSeconds };
|
|
2885
3824
|
try {
|
|
2886
|
-
await
|
|
3825
|
+
await sleep2(Math.min(delayMs, remaining), void 0, { signal: interrupt.signal });
|
|
2887
3826
|
} catch {
|
|
2888
3827
|
return { kind: "interrupted" };
|
|
2889
3828
|
}
|
|
@@ -2919,9 +3858,9 @@ async function waitForClaim(credential, state, timeoutSeconds, stats) {
|
|
|
2919
3858
|
process.removeListener("SIGINT", onSigint);
|
|
2920
3859
|
}
|
|
2921
3860
|
}
|
|
2922
|
-
async function withFailureReport(command,
|
|
3861
|
+
async function withFailureReport(command, run2) {
|
|
2923
3862
|
try {
|
|
2924
|
-
await
|
|
3863
|
+
await run2();
|
|
2925
3864
|
} catch (error) {
|
|
2926
3865
|
emit(
|
|
2927
3866
|
failureReport(command, SANDBOX_CLAIM_EXIT_CODES.failed, {
|
|
@@ -3349,6 +4288,12 @@ async function runSandboxClaimStatus() {
|
|
|
3349
4288
|
|
|
3350
4289
|
// src/cli.ts
|
|
3351
4290
|
var program = new Command();
|
|
4291
|
+
function withReview(command) {
|
|
4292
|
+
return command.option("--wait [seconds]", "Wait for the owner review (default when run in a terminal)").option("--no-wait", "Print the review link and return without waiting").option("--no-open", "Do not open the review page in a browser").addHelpText("after", REVIEW_EXIT_CODES_HELP);
|
|
4293
|
+
}
|
|
4294
|
+
function withLimits(command) {
|
|
4295
|
+
return command.option("--per-tx <usd>", "Per-payment limit in USD").option("--daily <usd>", "Daily limit in USD").option("--weekly <usd>", "Weekly limit in USD").option("--monthly <usd>", "Monthly limit in USD");
|
|
4296
|
+
}
|
|
3352
4297
|
var INIT_EXIT_CODES_HELP = `
|
|
3353
4298
|
Exit codes:
|
|
3354
4299
|
0 setup complete
|
|
@@ -3368,7 +4313,7 @@ Exit codes:
|
|
|
3368
4313
|
5 rate limited
|
|
3369
4314
|
130 interrupted while waiting, the link is still valid
|
|
3370
4315
|
`;
|
|
3371
|
-
program.name("conto").description("Conto CLI
|
|
4316
|
+
program.name("conto").description("Conto CLI: agentic payments control center").version(CLI_PACKAGE_VERSION).option("--json", "Output in JSON format").hook("preAction", (_thisCommand, actionCommand) => {
|
|
3372
4317
|
const opts = actionCommand.optsWithGlobals();
|
|
3373
4318
|
if (opts.json) {
|
|
3374
4319
|
setJsonMode(true);
|
|
@@ -3383,7 +4328,7 @@ program.command("init").description("Run the setup wizard (interactive, or headl
|
|
|
3383
4328
|
).option(
|
|
3384
4329
|
"--confirm-mainnet",
|
|
3385
4330
|
"Confirm that the selected network can move real funds (required for headless mainnet setup)"
|
|
3386
|
-
).option("--no-install", "Skip installing the conto CLI into the project").option("--resume", "Finish an unfinished organization setup recorded in .conto/").option("--restart", "Discard an unfinished setup record and start a new setup").addHelpText("after", INIT_EXIT_CODES_HELP).action(async (opts, command) => {
|
|
4331
|
+
).option("--no-install", "Skip installing the conto CLI into the project").option("--resume", "Finish an unfinished organization setup recorded in .conto/").option("--restart", "Discard an unfinished setup record and start a new setup").option("--overwrite", "Replace an existing conto.config.json and example.mjs without asking").addHelpText("after", INIT_EXIT_CODES_HELP).action(async (opts, command) => {
|
|
3387
4332
|
if (command.optsWithGlobals().json) {
|
|
3388
4333
|
setJsonMode(true);
|
|
3389
4334
|
}
|
|
@@ -3398,7 +4343,8 @@ program.command("init").description("Run the setup wizard (interactive, or headl
|
|
|
3398
4343
|
apiKey: opts.apiKey,
|
|
3399
4344
|
confirmMainnet: opts.confirmMainnet === true,
|
|
3400
4345
|
resume: opts.resume === true,
|
|
3401
|
-
restart: opts.restart === true
|
|
4346
|
+
restart: opts.restart === true,
|
|
4347
|
+
overwrite: opts.overwrite === true
|
|
3402
4348
|
});
|
|
3403
4349
|
});
|
|
3404
4350
|
var sandboxCommand = program.command("sandbox").description("Hand an anonymous sandbox to the person who will own it");
|
|
@@ -3408,24 +4354,93 @@ program.command("webhooks").description("Test local webhook handlers").command("
|
|
|
3408
4354
|
program.command("status").description("Agent info, wallet balances, spending summary").action(statusCommand);
|
|
3409
4355
|
program.command("doctor").description("Diagnose setup: auth, key scopes, wallet, chain, balance, base URL").action(doctorCommand);
|
|
3410
4356
|
program.command("balance").description("Wallet balances across all linked wallets").action(balanceCommand);
|
|
3411
|
-
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Validate input and show the request without sending it (no policy check)").option("--wallet <walletId>", "Specific wallet to use").
|
|
4357
|
+
program.command("pay <address> <amount>").description("Request + execute a payment").option("--purpose <purpose>", "Payment purpose").option("--category <category>", "Spend category").option("--dry-run", "Validate input and show the request without sending it (no policy check)").option("--wallet <walletId>", "Specific wallet to use").option("--task <taskId>", "Approved shared task authority").option("--purchase-key <key>", "Stable identity for the purchase").option(
|
|
4358
|
+
"--idempotency-key <key>",
|
|
4359
|
+
"Reuse the key a failed run printed, so the retry returns the same request"
|
|
4360
|
+
).option(
|
|
4361
|
+
"--wait [seconds]",
|
|
4362
|
+
"Wait for approval when it is needed (default when run in a terminal)"
|
|
4363
|
+
).option("--no-wait", "Print the approval link and return without waiting").option("--no-open", "Do not open the approval page in a browser").addHelpText("after", PAYMENT_EXIT_CODES_HELP).action(payCommand);
|
|
3412
4364
|
program.command("test-report").description("Save buyer-side payment, control, and review evidence without executing payments").requiredOption("--allowed <id>", "Completed allowed payment request ID").requiredOption("--denied <id>", "Policy-denied payment request ID").option("--review <id>", "Review exercise payment request ID").option("--review-outcome <outcome>", "Expected review outcome: approved, denied, or expired").requiredOption("--output <file>", "New owner-only JSON report file (never overwritten)").action(testReportCommand);
|
|
3413
4365
|
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);
|
|
3414
|
-
program.command("wallets").description("List wallets with balances").action(() => walletsCommand("list"));
|
|
4366
|
+
var walletsGroup = program.command("wallets").description("List wallets with balances, or change wallet controls").action(() => walletsCommand("list"));
|
|
4367
|
+
walletsGroup.command("list").description("List wallets with balances").action(() => walletsCommand("list"));
|
|
4368
|
+
walletsGroup.command("freeze <walletId>").description("Freeze a wallet so no agent can pay from it").action(walletFreezeCommand);
|
|
4369
|
+
withReview(
|
|
4370
|
+
walletsGroup.command("unfreeze <walletId>").description("Unfreeze a wallet (owner review)")
|
|
4371
|
+
).action(walletUnfreezeCommand);
|
|
4372
|
+
withReview(
|
|
4373
|
+
withLimits(
|
|
4374
|
+
walletsGroup.command("link <agentId> <walletId>").description("Let an agent spend from a wallet (owner review)").option("--delegation <type>", "limited, full, view_only, preapproved, or allowlist")
|
|
4375
|
+
)
|
|
4376
|
+
).action(walletLinkCommand);
|
|
4377
|
+
walletsGroup.command("unlink <agentId> <walletId>").description("Stop an agent spending from a wallet").action(walletUnlinkCommand);
|
|
4378
|
+
withReview(
|
|
4379
|
+
withLimits(
|
|
4380
|
+
walletsGroup.command("limits <agentId> <walletId>").description("Change an agent's limits on a wallet (raising one goes to owner review)").option("--clear-weekly", "Remove the weekly limit").option("--clear-monthly", "Remove the monthly limit")
|
|
4381
|
+
)
|
|
4382
|
+
).action(walletLimitsCommand);
|
|
4383
|
+
var agentsGroup = program.command("agents").description("Manage the organization's agents");
|
|
4384
|
+
agentsGroup.command("list").description("List agents").action(agentsListCommand);
|
|
4385
|
+
agentsGroup.command("show <agentId>").description("Show one agent").action(agentsShowCommand);
|
|
4386
|
+
agentsGroup.command("pause <agentId>").description("Pause an agent").action(agentsPauseCommand);
|
|
4387
|
+
withReview(
|
|
4388
|
+
agentsGroup.command("resume <agentId>").description("Resume a paused agent (owner review)")
|
|
4389
|
+
).action(agentsResumeCommand);
|
|
4390
|
+
agentsGroup.command("freeze <agentId>").description("Freeze an agent").option("--reason <text>", "Why, for the audit log").option("--wallets", "Also freeze wallets only this agent uses").action(agentsFreezeCommand);
|
|
4391
|
+
withReview(
|
|
4392
|
+
agentsGroup.command("unfreeze <agentId>").description("Lift a freeze (owner review)").option("--reason <text>", "Why, for the audit log").option("--wallets", "Also unfreeze the wallets frozen with it")
|
|
4393
|
+
).action(agentsUnfreezeCommand);
|
|
4394
|
+
withReview(
|
|
4395
|
+
agentsGroup.command("delete <agentId>").description("Delete an agent (owner review)").option("--yes", "Skip the confirmation prompt")
|
|
4396
|
+
).action(agentsDeleteCommand);
|
|
4397
|
+
var keysGroup = agentsGroup.command("keys").description("Manage an agent's SDK keys").argument("[agentId]", "Agent to list keys for").action((agentId) => {
|
|
4398
|
+
if (!agentId) {
|
|
4399
|
+
keysGroup.help();
|
|
4400
|
+
return;
|
|
4401
|
+
}
|
|
4402
|
+
return agentsKeysListCommand(agentId);
|
|
4403
|
+
});
|
|
4404
|
+
withReview(
|
|
4405
|
+
keysGroup.command("create <agentId>").description("Create an SDK key (owner review, shown once)").option("--name <name>", "Key label")
|
|
4406
|
+
).action(agentsKeysCreateCommand);
|
|
4407
|
+
keysGroup.command("revoke <agentId> <keyId>").description("Revoke an SDK key").action(agentsKeysRevokeCommand);
|
|
4408
|
+
var payeesGroup = program.command("counterparties").description("Manage the organization's payees");
|
|
4409
|
+
payeesGroup.command("list").description("List payees").action(counterpartiesListCommand);
|
|
4410
|
+
payeesGroup.command("show <id>").description("Show one payee").action(counterpartiesShowCommand);
|
|
4411
|
+
payeesGroup.command("add").description("Add a payee for review").option("--name <name>", "Payee name").option("--address <address>", "Wallet address").option("--type <type>", "vendor, service, agent, or other").option("--category <category>", "Spend category").action(counterpartiesAddCommand);
|
|
4412
|
+
payeesGroup.command("block <id>").description("Block a payee").action(counterpartiesBlockCommand);
|
|
4413
|
+
withReview(
|
|
4414
|
+
payeesGroup.command("approve <id>").description("Approve or unblock a payee (owner review)").option("--reason <text>", "Why, for the audit log")
|
|
4415
|
+
).action(counterpartiesApproveCommand);
|
|
4416
|
+
var channelsGroup = program.command("channels").description("Manage event delivery channels");
|
|
4417
|
+
channelsGroup.command("list").description("List channels").action(channelsListCommand);
|
|
4418
|
+
channelsGroup.command("add").description("Add an email or webhook channel").option("--name <name>", "Channel name").option("--type <type>", "email or webhook").option("--recipients <emails>", "Comma-separated emails (email)").option("--url <url>", "https address to send events to (webhook)").option("--events <types>", "Comma-separated event types (default: approval.requested)").action(channelsAddCommand);
|
|
4419
|
+
channelsGroup.command("test <id>").description("Send a test event").action(channelsTestCommand);
|
|
4420
|
+
withReview(
|
|
4421
|
+
channelsGroup.command("remove <id>").description("Remove a channel (owner review)")
|
|
4422
|
+
).action(channelsRemoveCommand);
|
|
4423
|
+
withReview(
|
|
4424
|
+
program.command("changes").description("Follow changes sent to owner review").command("status <changeId>").description("Show where a change stands, and collect it once approved")
|
|
4425
|
+
).action((changeId, opts) => changesStatusCommand(changeId, opts));
|
|
3415
4426
|
program.command("fund").description("Show wallet funding instructions").option("--faucet", "Request testnet funds from the configured faucet").action((opts) => walletsCommand("fund", { faucet: opts.faucet === true }));
|
|
3416
|
-
|
|
3417
|
-
"
|
|
4427
|
+
withReview(
|
|
4428
|
+
program.command("policies [subcommand] [id] [extra]").description(
|
|
4429
|
+
"Manage spending policies (list, all, create, update, delete, assign, unassign, add-rule, remove-rule, versions, rollback, simulate)"
|
|
4430
|
+
)
|
|
3418
4431
|
).action(
|
|
3419
|
-
(subcommand,
|
|
4432
|
+
(subcommand, id2, extra, opts) => policiesCommand(subcommand || "list", id2, extra, opts)
|
|
3420
4433
|
);
|
|
3421
4434
|
program.command("limits").description("Show spending limits and remaining budget").action(limitsCommand);
|
|
3422
|
-
program.command("alerts").description("List alerts").option("--active", "Show only active alerts").option("--unread", "Alias for --active").action(alertsCommand);
|
|
4435
|
+
var alertsGroup = program.command("alerts").description("List alerts, or acknowledge or resolve one").option("--active", "Show only active alerts").option("--unread", "Alias for --active").action(alertsCommand);
|
|
4436
|
+
alertsGroup.command("ack <alertId>").description("Acknowledge an alert").action((alertId) => alertUpdateCommand(alertId, "acknowledge"));
|
|
4437
|
+
alertsGroup.command("resolve <alertId>").description("Resolve an alert").action((alertId) => alertUpdateCommand(alertId, "resolve"));
|
|
3423
4438
|
program.command("config [key] [value]").description("Show or update configuration").action(configCommand);
|
|
3424
4439
|
program.command("login").description("Authenticate with Conto").option("--base-url <url>", "Conto instance URL").action(loginCommand);
|
|
3425
4440
|
program.command("logout").description("Clear stored credentials").action(async () => {
|
|
3426
|
-
const { clearGlobalConfig } = await import("./config-
|
|
4441
|
+
const { clearGlobalConfig } = await import("./config-MACPIPYV.js");
|
|
3427
4442
|
clearGlobalConfig();
|
|
3428
|
-
const { printSuccess: printSuccess2 } = await import("./output-
|
|
4443
|
+
const { printSuccess: printSuccess2 } = await import("./output-GD3QK4HS.js");
|
|
3429
4444
|
printSuccess2("Logged out. Credentials cleared.");
|
|
3430
4445
|
});
|
|
3431
4446
|
program.command("mcp").description("Start MCP server for AI agent integration").action(mcpCommand);
|
|
@@ -3439,8 +4454,9 @@ program.command("docs [topic]").description("Open Conto documentation (cli, poli
|
|
|
3439
4454
|
api: "https://conto.finance/docs/api"
|
|
3440
4455
|
};
|
|
3441
4456
|
const url = urls[topic || "cli"] || urls.cli;
|
|
3442
|
-
const { printInfo: printInfo2 } = await import("./output-
|
|
4457
|
+
const { printInfo: printInfo2 } = await import("./output-GD3QK4HS.js");
|
|
3443
4458
|
printInfo2(`Opening ${url}`);
|
|
3444
4459
|
open(url);
|
|
3445
4460
|
});
|
|
4461
|
+
registerSpendingCommands(program);
|
|
3446
4462
|
program.parse();
|