agental 0.7.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +364 -19
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -46,7 +46,7 @@ import { parseArgs } from "node:util";
|
|
|
46
46
|
|
|
47
47
|
// ../src/cli-build.ts
|
|
48
48
|
var PUBLISHED = true;
|
|
49
|
-
var CLI_VERSION = true ? "0.
|
|
49
|
+
var CLI_VERSION = true ? "0.10.0" : "dev";
|
|
50
50
|
var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
|
|
51
51
|
var PACKAGE_NAME = "agental";
|
|
52
52
|
var USER_AGENT = `agental-cli/${CLI_VERSION}`;
|
|
@@ -763,10 +763,10 @@ async function whoIs(base, key2) {
|
|
|
763
763
|
throw error;
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
|
-
async function pushRequest(base,
|
|
766
|
+
async function pushRequest(base, ask8) {
|
|
767
767
|
let made;
|
|
768
768
|
try {
|
|
769
|
-
made = await call(base, "POST", "/v1/cli-sign-ins",
|
|
769
|
+
made = await call(base, "POST", "/v1/cli-sign-ins", ask8);
|
|
770
770
|
} catch (error) {
|
|
771
771
|
if (error instanceof Refused && (error.status === 401 || error.status === 404)) {
|
|
772
772
|
throw new Error(`${base} does not sign the command in through the browser. Make a key in its console, under API keys, and run agental login --key.`);
|
|
@@ -2077,7 +2077,16 @@ var WEBHOOK_EVENTS = [...LIFECYCLE_EVENTS, "prompt.created"];
|
|
|
2077
2077
|
var EMAIL_EVENTS = ["email.received", "email.delivered", "email.bounced"];
|
|
2078
2078
|
var MEMBER_EVENTS = ["member.invited", "member.joined", "member.removed", "member.role_changed", "key.revoked"];
|
|
2079
2079
|
var TEMPLATE_EVENTS = ["template.created", "template.updated", "template.secrets_changed", "template.labels_changed", "template.deleted"];
|
|
2080
|
-
var
|
|
2080
|
+
var HEADROOM_EVENTS = [
|
|
2081
|
+
"headroom.burst_started",
|
|
2082
|
+
"headroom.burst_ended",
|
|
2083
|
+
"headroom.refused",
|
|
2084
|
+
"headroom.running_count_reached",
|
|
2085
|
+
"headroom.budget_threshold",
|
|
2086
|
+
"headroom.budget_reached"
|
|
2087
|
+
];
|
|
2088
|
+
var WEBHOOK_KINDS = [...WEBHOOK_EVENTS, ...EMAIL_EVENTS, ...MEMBER_EVENTS, ...TEMPLATE_EVENTS, ...HEADROOM_EVENTS];
|
|
2089
|
+
var WEBHOOK_GROUPS = [...new Set(WEBHOOK_KINDS.map((kind) => kind.slice(0, kind.indexOf("."))))];
|
|
2081
2090
|
var WEBHOOK_RETRY_AFTER_MS = [6e4, 5 * 6e4, 15 * 6e4, 60 * 6e4, 3 * 36e5, 6 * 36e5, 12 * 36e5];
|
|
2082
2091
|
|
|
2083
2092
|
// ../src/cli-webhooks.ts
|
|
@@ -2176,14 +2185,16 @@ function eventsFrom(options, needed) {
|
|
|
2176
2185
|
}
|
|
2177
2186
|
if (options.events === void 0) {
|
|
2178
2187
|
if (needed) {
|
|
2179
|
-
throw new Error(`Say what to send: --events with kinds such as sandbox.stopped,sandbox.error, or --all. The kinds are ${WEBHOOK_KINDS.join(", ")}.`);
|
|
2188
|
+
throw new Error(`Say what to send: --events with kinds such as sandbox.stopped,sandbox.error, or --all. The kinds are ${WEBHOOK_KINDS.join(", ")}; a group of them is ${WEBHOOK_GROUPS.map((group) => `${group}.*`).join(", ")}, quoted for the shell.`);
|
|
2180
2189
|
}
|
|
2181
2190
|
return void 0;
|
|
2182
2191
|
}
|
|
2183
2192
|
const kinds = options.events.split(",").map((kind) => kind.trim()).filter(Boolean);
|
|
2184
|
-
const unknown = kinds.filter((kind) => !WEBHOOK_KINDS.includes(kind));
|
|
2193
|
+
const unknown = kinds.filter((kind) => !WEBHOOK_KINDS.includes(kind) && !(kind.endsWith(".*") && WEBHOOK_GROUPS.includes(kind.slice(0, -2))));
|
|
2185
2194
|
if (kinds.length === 0 || unknown.length > 0) {
|
|
2186
|
-
throw new Error(
|
|
2195
|
+
throw new Error(
|
|
2196
|
+
`${unknown.length > 0 ? `No event is called ${unknown.join(", ")}. ` : "--events names no kind. "}The kinds are ${WEBHOOK_KINDS.join(", ")}; a group of them is ${WEBHOOK_GROUPS.map((group) => `${group}.*`).join(", ")}; or --all for every event.`
|
|
2197
|
+
);
|
|
2187
2198
|
}
|
|
2188
2199
|
return kinds;
|
|
2189
2200
|
}
|
|
@@ -2321,6 +2332,200 @@ function needId(id, what) {
|
|
|
2321
2332
|
return id;
|
|
2322
2333
|
}
|
|
2323
2334
|
|
|
2335
|
+
// ../src/cli-claude.ts
|
|
2336
|
+
var USAGE5 = "claude takes connect, show, update or disconnect. agental help shows each.";
|
|
2337
|
+
var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
|
|
2338
|
+
var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
|
|
2339
|
+
async function ask7(client, method, pathname, body) {
|
|
2340
|
+
const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
|
|
2341
|
+
let answered = null;
|
|
2342
|
+
if (response.status !== 204) {
|
|
2343
|
+
try {
|
|
2344
|
+
answered = await response.json();
|
|
2345
|
+
} catch {
|
|
2346
|
+
answered = null;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
if (!response.ok) {
|
|
2350
|
+
client.fail(response.status, answered);
|
|
2351
|
+
}
|
|
2352
|
+
return answered;
|
|
2353
|
+
}
|
|
2354
|
+
function connectionOf(body) {
|
|
2355
|
+
const connection = body?.connection ?? body;
|
|
2356
|
+
if (!connection || typeof connection !== "object" || typeof connection.id !== "string") {
|
|
2357
|
+
throw new Error("The answer was not a Claude connection.");
|
|
2358
|
+
}
|
|
2359
|
+
return connection;
|
|
2360
|
+
}
|
|
2361
|
+
function describe4(connection) {
|
|
2362
|
+
return [
|
|
2363
|
+
`id: ${connection.id}`,
|
|
2364
|
+
`environment: ${connection.environmentId}`,
|
|
2365
|
+
`template: ${connection.templateId ?? "the account's default"}`,
|
|
2366
|
+
`keeps a sleeping session's sandbox for ${connection.keepDays} day${connection.keepDays === 1 ? "" : "s"}`,
|
|
2367
|
+
`webhook: ${connection.webhookUrl}`,
|
|
2368
|
+
` ${connection.hasWebhookSecret ? "its signing secret is kept" : "no signing secret: sessions are found by a pass every minute, so a first turn waits up to a minute"}`,
|
|
2369
|
+
""
|
|
2370
|
+
].join("\n");
|
|
2371
|
+
}
|
|
2372
|
+
function keepDaysOf(options) {
|
|
2373
|
+
const given = options["keep-days"];
|
|
2374
|
+
if (given === void 0) {
|
|
2375
|
+
return void 0;
|
|
2376
|
+
}
|
|
2377
|
+
const days = Number(given);
|
|
2378
|
+
if (!Number.isInteger(days) || days < 1) {
|
|
2379
|
+
throw new Error("--keep-days takes a whole number of days, as --keep-days 7");
|
|
2380
|
+
}
|
|
2381
|
+
return days;
|
|
2382
|
+
}
|
|
2383
|
+
async function templateOf(client, options) {
|
|
2384
|
+
if (options.template === void 0) {
|
|
2385
|
+
return void 0;
|
|
2386
|
+
}
|
|
2387
|
+
return options.template === "default" ? null : await client.templateId(options.template);
|
|
2388
|
+
}
|
|
2389
|
+
async function secretFrom(variable, what, required) {
|
|
2390
|
+
const fromEnvironment = process.env[variable]?.trim();
|
|
2391
|
+
if (fromEnvironment) {
|
|
2392
|
+
return fromEnvironment;
|
|
2393
|
+
}
|
|
2394
|
+
if (!process.stdin.isTTY) {
|
|
2395
|
+
if (!required) {
|
|
2396
|
+
return void 0;
|
|
2397
|
+
}
|
|
2398
|
+
const chunks = [];
|
|
2399
|
+
for await (const chunk of process.stdin) {
|
|
2400
|
+
chunks.push(Buffer.from(chunk));
|
|
2401
|
+
}
|
|
2402
|
+
const piped = Buffer.concat(chunks).toString("utf8").trim();
|
|
2403
|
+
if (!piped) {
|
|
2404
|
+
throw new Error(`Give the ${what} in ${variable}, or pipe it in. It is never taken on the command line.`);
|
|
2405
|
+
}
|
|
2406
|
+
return piped;
|
|
2407
|
+
}
|
|
2408
|
+
const typed = await hidden(`${what} (not shown${required ? "" : "; Enter for none"}): `);
|
|
2409
|
+
if (!typed && required) {
|
|
2410
|
+
throw new Error(`The ${what} is needed.`);
|
|
2411
|
+
}
|
|
2412
|
+
return typed || void 0;
|
|
2413
|
+
}
|
|
2414
|
+
async function hidden(question) {
|
|
2415
|
+
const { createInterface: createInterface2 } = await import("node:readline");
|
|
2416
|
+
return await new Promise((resolve) => {
|
|
2417
|
+
const lines = createInterface2({ input: process.stdin, output: process.stderr, terminal: true });
|
|
2418
|
+
const muted = lines;
|
|
2419
|
+
process.stderr.write(question);
|
|
2420
|
+
muted._writeToOutput = () => void 0;
|
|
2421
|
+
lines.question("", (answer) => {
|
|
2422
|
+
lines.close();
|
|
2423
|
+
process.stderr.write("\n");
|
|
2424
|
+
resolve(answer.trim());
|
|
2425
|
+
});
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
async function listClaude(client, asJson) {
|
|
2429
|
+
const body = await ask7(client, "GET", "/v1/claude/connections");
|
|
2430
|
+
if (asJson) {
|
|
2431
|
+
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
2432
|
+
`);
|
|
2433
|
+
return;
|
|
2434
|
+
}
|
|
2435
|
+
const connections = (Array.isArray(body?.data) ? body.data : []).map(connectionOf);
|
|
2436
|
+
if (connections.length === 0) {
|
|
2437
|
+
process.stdout.write("No Claude environments are connected. agental claude connect <environment-id> connects one.\n");
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
const pad3 = (value, width) => value.padEnd(width, " ");
|
|
2441
|
+
process.stdout.write(`${[pad3("ID", 22), pad3("ENVIRONMENT", 30), pad3("TEMPLATE", 22), pad3("KEEPS", 8), "WEBHOOK"].join(" ")}
|
|
2442
|
+
`);
|
|
2443
|
+
for (const one of connections) {
|
|
2444
|
+
process.stdout.write(`${[pad3(one.id, 22), pad3(one.environmentId, 30), pad3(one.templateId ?? "default", 22), pad3(`${one.keepDays}d`, 8), one.hasWebhookSecret ? "signed" : "none"].join(" ")}
|
|
2445
|
+
`);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
async function claude(client, positionals, options) {
|
|
2449
|
+
const [what, target, ...rest] = positionals;
|
|
2450
|
+
if (rest.length > 0) {
|
|
2451
|
+
throw new Error(USAGE5);
|
|
2452
|
+
}
|
|
2453
|
+
switch (what) {
|
|
2454
|
+
case "connect": {
|
|
2455
|
+
if (target === void 0) {
|
|
2456
|
+
throw new Error("claude connect needs the environment's id from the Claude Console, as agental claude connect env_01...");
|
|
2457
|
+
}
|
|
2458
|
+
const templateId = await templateOf(client, options);
|
|
2459
|
+
const keepDays = keepDaysOf(options);
|
|
2460
|
+
const environmentKey = await secretFrom(KEY_VARIABLE, "environment key", true);
|
|
2461
|
+
const webhookSecret = await secretFrom(SECRET_VARIABLE, "webhook signing secret", false);
|
|
2462
|
+
const made = connectionOf(
|
|
2463
|
+
await ask7(client, "POST", "/v1/claude/connections", {
|
|
2464
|
+
environmentId: target,
|
|
2465
|
+
environmentKey,
|
|
2466
|
+
...webhookSecret !== void 0 ? { webhookSecret } : {},
|
|
2467
|
+
...templateId !== void 0 ? { templateId } : {},
|
|
2468
|
+
...keepDays !== void 0 ? { keepDays } : {}
|
|
2469
|
+
})
|
|
2470
|
+
);
|
|
2471
|
+
if (options.json) {
|
|
2472
|
+
process.stdout.write(`${JSON.stringify(made, null, 2)}
|
|
2473
|
+
`);
|
|
2474
|
+
return;
|
|
2475
|
+
}
|
|
2476
|
+
process.stdout.write(describe4(made));
|
|
2477
|
+
process.stderr.write(
|
|
2478
|
+
made.hasWebhookSecret ? `In the Claude Console, set ${made.webhookUrl} as a webhook for session.status_run_started.
|
|
2479
|
+
` : `For a turn to start at once, add ${made.webhookUrl} as a webhook for session.status_run_started in the Claude Console, then: ${SECRET_VARIABLE}=whsec_... agental claude update ${made.id} --webhook-secret
|
|
2480
|
+
`
|
|
2481
|
+
);
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2484
|
+
case "show": {
|
|
2485
|
+
const found = connectionOf(await ask7(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
|
|
2486
|
+
process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
|
|
2487
|
+
` : describe4(found));
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
case "update": {
|
|
2491
|
+
const id = needId2(target, "update");
|
|
2492
|
+
if (options["webhook-secret"] && options["no-webhook-secret"]) {
|
|
2493
|
+
throw new Error("--webhook-secret and --no-webhook-secret say two things: give one.");
|
|
2494
|
+
}
|
|
2495
|
+
const templateId = await templateOf(client, options);
|
|
2496
|
+
const keepDays = keepDaysOf(options);
|
|
2497
|
+
const environmentKey = options["new-key"] ? await secretFrom(KEY_VARIABLE, "new environment key", true) : void 0;
|
|
2498
|
+
const webhookSecret = options["webhook-secret"] ? await secretFrom(SECRET_VARIABLE, "new webhook signing secret", true) : options["no-webhook-secret"] ? null : void 0;
|
|
2499
|
+
const patch = {
|
|
2500
|
+
...environmentKey !== void 0 ? { environmentKey } : {},
|
|
2501
|
+
...webhookSecret !== void 0 ? { webhookSecret } : {},
|
|
2502
|
+
...templateId !== void 0 ? { templateId } : {},
|
|
2503
|
+
...keepDays !== void 0 ? { keepDays } : {}
|
|
2504
|
+
};
|
|
2505
|
+
if (Object.keys(patch).length === 0) {
|
|
2506
|
+
throw new Error("claude update changes --template, --keep-days, --new-key, --webhook-secret or --no-webhook-secret, and was given none of them.");
|
|
2507
|
+
}
|
|
2508
|
+
const updated = connectionOf(await ask7(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
|
|
2509
|
+
process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
|
|
2510
|
+
` : describe4(updated));
|
|
2511
|
+
return;
|
|
2512
|
+
}
|
|
2513
|
+
case "disconnect": {
|
|
2514
|
+
await ask7(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
|
|
2515
|
+
process.stdout.write("Disconnected: its key and signing secret are forgotten, and no more of its work is claimed. Its sessions' sandboxes are left as they are.\n");
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
default:
|
|
2519
|
+
throw new Error(USAGE5);
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
function needId2(id, what) {
|
|
2523
|
+
if (id === void 0) {
|
|
2524
|
+
throw new Error(`claude ${what} needs the connection's id, as agental claude lists them.`);
|
|
2525
|
+
}
|
|
2526
|
+
return id;
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2324
2529
|
// ../src/cli-shell.ts
|
|
2325
2530
|
import { createHash as createHash2, randomBytes as randomBytes4 } from "node:crypto";
|
|
2326
2531
|
var TERMINAL_PROTOCOL = "agental.terminal.v1";
|
|
@@ -2822,6 +3027,11 @@ async function main() {
|
|
|
2822
3027
|
all: { type: "boolean", default: false },
|
|
2823
3028
|
description: { type: "string" },
|
|
2824
3029
|
url: { type: "string" },
|
|
3030
|
+
// agental claude: a connection's days, and which of its secrets to read anew.
|
|
3031
|
+
"keep-days": { type: "string" },
|
|
3032
|
+
"new-key": { type: "boolean", default: false },
|
|
3033
|
+
"webhook-secret": { type: "boolean", default: false },
|
|
3034
|
+
"no-webhook-secret": { type: "boolean", default: false },
|
|
2825
3035
|
preset: { type: "string" },
|
|
2826
3036
|
actions: { type: "string" },
|
|
2827
3037
|
sandbox: { type: "string", multiple: true },
|
|
@@ -2985,6 +3195,15 @@ async function main() {
|
|
|
2985
3195
|
case "webhook":
|
|
2986
3196
|
await webhook({ request, fail }, positionals.slice(1), values);
|
|
2987
3197
|
return;
|
|
3198
|
+
case "claude": {
|
|
3199
|
+
const client = { request, fail, templateId: async (word) => (await templateNamed(word)).id };
|
|
3200
|
+
if (positionals.length === 1) {
|
|
3201
|
+
await listClaude(client, values.json);
|
|
3202
|
+
} else {
|
|
3203
|
+
await claude(client, positionals.slice(1), { ...values, template: once(values.template, "--template") });
|
|
3204
|
+
}
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
2988
3207
|
case "keys":
|
|
2989
3208
|
await listKeys({ request, fail }, values.json);
|
|
2990
3209
|
return;
|
|
@@ -3001,7 +3220,7 @@ async function main() {
|
|
|
3001
3220
|
await key({ request, fail }, positionals.slice(1), values);
|
|
3002
3221
|
return;
|
|
3003
3222
|
case "billing":
|
|
3004
|
-
await billing(positionals.slice(1), values.json);
|
|
3223
|
+
await billing(positionals.slice(1), values.json, values.limit);
|
|
3005
3224
|
return;
|
|
3006
3225
|
case "headroom":
|
|
3007
3226
|
await headroom(positionals.slice(1), { json: values.json, from: values.from, to: values.to, step: values.step });
|
|
@@ -4301,10 +4520,10 @@ async function secrets(positionals, values) {
|
|
|
4301
4520
|
case void 0: {
|
|
4302
4521
|
const listed = await call2(`${base}/variables`, { method: "GET" });
|
|
4303
4522
|
const names = listed.names;
|
|
4304
|
-
const
|
|
4523
|
+
const hidden2 = listed.hidden ?? [];
|
|
4305
4524
|
const paths = (await call2(`${base}/files`, { method: "GET" })).paths;
|
|
4306
4525
|
if (values.json) {
|
|
4307
|
-
process.stdout.write(`${JSON.stringify({ variables: names, hidden, files: paths }, null, 2)}
|
|
4526
|
+
process.stdout.write(`${JSON.stringify({ variables: names, hidden: hidden2, files: paths }, null, 2)}
|
|
4308
4527
|
`);
|
|
4309
4528
|
return;
|
|
4310
4529
|
}
|
|
@@ -4313,7 +4532,7 @@ async function secrets(positionals, values) {
|
|
|
4313
4532
|
return;
|
|
4314
4533
|
}
|
|
4315
4534
|
process.stdout.write(
|
|
4316
|
-
[...names.map((name) => `variable ${name}${
|
|
4535
|
+
[...names.map((name) => `variable ${name}${hidden2.includes(name) ? " kept out of the sandbox" : ""}
|
|
4317
4536
|
`), ...paths.map((path4) => `file ${path4}
|
|
4318
4537
|
`)].join("")
|
|
4319
4538
|
);
|
|
@@ -4680,18 +4899,25 @@ async function telemetry(positionals, given, asJson) {
|
|
|
4680
4899
|
throw new Error(usage);
|
|
4681
4900
|
}
|
|
4682
4901
|
}
|
|
4683
|
-
async function billing(positionals, asJson) {
|
|
4902
|
+
async function billing(positionals, asJson, limit) {
|
|
4684
4903
|
const [what, amount, ...rest] = positionals;
|
|
4685
|
-
const usage = "billing takes nothing, prices, card, top-up <dollars>, or auto-reload <dollars | off>";
|
|
4904
|
+
const usage = "billing takes nothing, prices, invoices, card, top-up <dollars>, or auto-reload <dollars | off>";
|
|
4686
4905
|
if (rest.length > 0 || what !== "top-up" && what !== "auto-reload" && amount !== void 0) {
|
|
4687
4906
|
throw new Error(usage);
|
|
4688
4907
|
}
|
|
4908
|
+
if (limit !== void 0 && what !== "invoices") {
|
|
4909
|
+
throw new Error("--limit is taken by billing invoices alone.");
|
|
4910
|
+
}
|
|
4689
4911
|
const print4 = (body, text) => process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
|
|
4690
4912
|
` : text());
|
|
4691
4913
|
switch (what) {
|
|
4692
4914
|
case void 0: {
|
|
4693
|
-
const body = await asked("/v1/billing", { method: "GET" });
|
|
4694
|
-
print4(body, () => describeBilling(body));
|
|
4915
|
+
const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), asJson ? null : cardOnFile()]);
|
|
4916
|
+
print4(body, () => describeBilling(body, card));
|
|
4917
|
+
return;
|
|
4918
|
+
}
|
|
4919
|
+
case "invoices": {
|
|
4920
|
+
await invoices(asJson, limit);
|
|
4695
4921
|
return;
|
|
4696
4922
|
}
|
|
4697
4923
|
case "prices": {
|
|
@@ -4755,14 +4981,17 @@ function wholeMoney(micros) {
|
|
|
4755
4981
|
function dayOf(iso) {
|
|
4756
4982
|
return iso ? new Date(iso).toLocaleDateString("en-GB", { day: "numeric", month: "long", timeZone: "UTC" }) : "";
|
|
4757
4983
|
}
|
|
4758
|
-
function describeBilling(body) {
|
|
4984
|
+
function describeBilling(body, card = null) {
|
|
4759
4985
|
const lines = [];
|
|
4760
4986
|
const free = body.free ?? null;
|
|
4761
4987
|
if (free && body.plan) {
|
|
4762
4988
|
lines.push(["Plan", "free: nothing a month. What runs is paid from your credits, at list price."]);
|
|
4763
4989
|
if (!free.cardSaved) {
|
|
4764
4990
|
lines.push(["Card", "none saved. Save one, charged nothing, to run sandboxes and be given the free plan's credit: agental billing card."]);
|
|
4765
|
-
} else if (
|
|
4991
|
+
} else if (card) {
|
|
4992
|
+
lines.push(["Card", describeCard(card)]);
|
|
4993
|
+
}
|
|
4994
|
+
if (free.cardSaved && !free.paid) {
|
|
4766
4995
|
lines.push(["At once", `${free.unpaidUnits} small sandboxes until you buy a top-up, then ${(body.plan.runningUnits ?? 20).toLocaleString("en-US")}. A tiny counts half.`]);
|
|
4767
4996
|
}
|
|
4768
4997
|
lines.push(["Used", `${money(body.usedMicros)} this month at list price${usedParts(body)}`]);
|
|
@@ -4787,6 +5016,9 @@ function describeBilling(body) {
|
|
|
4787
5016
|
const charged = body.usedMicros - (body.discount?.micros ?? 0) + (body.carriedMicros ?? 0);
|
|
4788
5017
|
lines.push(["Included", `${money(body.includedMicros)}, ${money(Math.max(0, body.includedMicros - charged))} left. It does not carry over.`]);
|
|
4789
5018
|
lines.push(["Top-ups left", `${money(body.topUpMicros)}, used after the plan's credits. They do not expire.`]);
|
|
5019
|
+
if (card) {
|
|
5020
|
+
lines.push(["Card", describeCard(card)]);
|
|
5021
|
+
}
|
|
4790
5022
|
if (body.autoReload) {
|
|
4791
5023
|
lines.push(["Auto-reload", describeAutoReload(body.autoReload)]);
|
|
4792
5024
|
} else if (body.canAutoReload) {
|
|
@@ -4813,6 +5045,97 @@ function describeBilling(body) {
|
|
|
4813
5045
|
return lines.map(([label, value]) => `${label.padEnd(14)}${value}
|
|
4814
5046
|
`).join("");
|
|
4815
5047
|
}
|
|
5048
|
+
async function cardOnFile() {
|
|
5049
|
+
try {
|
|
5050
|
+
const response = await request("/v1/billing/card", { method: "GET" });
|
|
5051
|
+
if (!response.ok) {
|
|
5052
|
+
return null;
|
|
5053
|
+
}
|
|
5054
|
+
const body = await readBody(response);
|
|
5055
|
+
return body?.card ?? null;
|
|
5056
|
+
} catch {
|
|
5057
|
+
return null;
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
var CARD_BRANDS = {
|
|
5061
|
+
amex: "American Express",
|
|
5062
|
+
diners: "Diners Club",
|
|
5063
|
+
discover: "Discover",
|
|
5064
|
+
eftpos_au: "eftpos",
|
|
5065
|
+
jcb: "JCB",
|
|
5066
|
+
link: "Link",
|
|
5067
|
+
mastercard: "Mastercard",
|
|
5068
|
+
unionpay: "UnionPay",
|
|
5069
|
+
visa: "Visa"
|
|
5070
|
+
};
|
|
5071
|
+
var WALLETS = { apple_pay: "Apple Pay", google_pay: "Google Pay", link: "Link", samsung_pay: "Samsung Pay" };
|
|
5072
|
+
function describeCard(card) {
|
|
5073
|
+
const brand = (card.brand ? CARD_BRANDS[card.brand] : void 0) ?? (card.brand ? card.brand.charAt(0).toUpperCase() + card.brand.slice(1) : "Card");
|
|
5074
|
+
const ending = card.last4 ? ` ending ${card.last4}` : "";
|
|
5075
|
+
const expires = card.expMonth !== null && card.expYear !== null ? `, expires ${String(card.expMonth).padStart(2, "0")}/${String(card.expYear % 100).padStart(2, "0")}` : "";
|
|
5076
|
+
const wallet = card.wallet ? `, through ${WALLETS[card.wallet] ?? card.wallet}` : "";
|
|
5077
|
+
return `${brand}${ending}${expires}${wallet}. It is changed in the console, under Billing.`;
|
|
5078
|
+
}
|
|
5079
|
+
async function invoices(asJson, limit) {
|
|
5080
|
+
if (limit !== void 0 && (!/^\d+$/.test(limit) || Number(limit) < 1 || Number(limit) > 100)) {
|
|
5081
|
+
throw new Error("billing invoices --limit takes how many of the newest invoices to list, a whole number from 1 to 100.");
|
|
5082
|
+
}
|
|
5083
|
+
const wanted = limit === void 0 ? Infinity : Number(limit);
|
|
5084
|
+
const listed = [];
|
|
5085
|
+
let after = null;
|
|
5086
|
+
do {
|
|
5087
|
+
const query = new URLSearchParams({ limit: String(Math.min(100, wanted - listed.length)) });
|
|
5088
|
+
if (after !== null) {
|
|
5089
|
+
query.set("startingAfter", after);
|
|
5090
|
+
}
|
|
5091
|
+
const body = await asked(`/v1/billing/invoices?${query}`, { method: "GET" });
|
|
5092
|
+
listed.push(...body.invoices);
|
|
5093
|
+
after = body.next === after ? null : body.next;
|
|
5094
|
+
} while (after !== null && listed.length < wanted);
|
|
5095
|
+
listed.splice(wanted);
|
|
5096
|
+
if (after !== null) {
|
|
5097
|
+
process.stderr.write("There are older invoices. Drop --limit to list them all.\n");
|
|
5098
|
+
}
|
|
5099
|
+
if (asJson) {
|
|
5100
|
+
process.stdout.write(`${JSON.stringify(listed, null, 2)}
|
|
5101
|
+
`);
|
|
5102
|
+
return;
|
|
5103
|
+
}
|
|
5104
|
+
if (listed.length === 0) {
|
|
5105
|
+
process.stdout.write("No invoices yet. A plan's month, a top-up or an auto-reload makes one once it is charged.\n");
|
|
5106
|
+
return;
|
|
5107
|
+
}
|
|
5108
|
+
const rows = listed.map((invoice) => [
|
|
5109
|
+
shortDayOf(invoice.createdAt),
|
|
5110
|
+
invoice.number ?? "-",
|
|
5111
|
+
INVOICE_STATES[invoice.status] ?? invoice.status,
|
|
5112
|
+
amountOf(invoice.totalMicros, invoice.currency),
|
|
5113
|
+
invoice.description ?? ""
|
|
5114
|
+
]);
|
|
5115
|
+
const widths = [0, 1, 2, 3].map((column) => Math.max(...rows.map((row) => row[column]?.length ?? 0)));
|
|
5116
|
+
for (const row of rows) {
|
|
5117
|
+
const [day, number, state2, total, what] = row;
|
|
5118
|
+
process.stdout.write(`${day.padEnd(widths[0] ?? 0)} ${number.padEnd(widths[1] ?? 0)} ${state2.padEnd(widths[2] ?? 0)} ${total.padStart(widths[3] ?? 0)} ${what}`.trimEnd() + "\n");
|
|
5119
|
+
}
|
|
5120
|
+
for (const invoice of listed.filter((each) => each.status === "open" && each.pageUrl)) {
|
|
5121
|
+
process.stdout.write(`${invoice.number ?? invoice.id} is not paid yet. Pay it at:
|
|
5122
|
+
${invoice.pageUrl}
|
|
5123
|
+
`);
|
|
5124
|
+
}
|
|
5125
|
+
if (listed.some((each) => each.pdfUrl)) {
|
|
5126
|
+
process.stdout.write("--json gives each one's page and PDF.\n");
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
var INVOICE_STATES = { open: "not paid", paid: "paid", void: "void", uncollectible: "written off" };
|
|
5130
|
+
function amountOf(micros, currency) {
|
|
5131
|
+
if (currency.toLowerCase() === "usd") {
|
|
5132
|
+
return money(micros);
|
|
5133
|
+
}
|
|
5134
|
+
return `${(micros / 1e6).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${currency.toUpperCase()}`;
|
|
5135
|
+
}
|
|
5136
|
+
function shortDayOf(iso) {
|
|
5137
|
+
return new Date(iso).toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" });
|
|
5138
|
+
}
|
|
4816
5139
|
function usedParts(body) {
|
|
4817
5140
|
const parts = [
|
|
4818
5141
|
...(body.mailMicros ?? 0) > 0 ? [`${money(body.mailMicros ?? 0)} by email`] : [],
|
|
@@ -5234,6 +5557,11 @@ Usage
|
|
|
5234
5557
|
agental webhook update <webhook-id> [--url <url>] [--events <kind>[,<kind>...] | --all] [--description <text>] [--json]
|
|
5235
5558
|
agental webhook rotate <webhook-id> [--json]
|
|
5236
5559
|
agental webhook delete <webhook-id>
|
|
5560
|
+
agental claude [--json]
|
|
5561
|
+
agental claude connect <environment-id> [--template <template>|default] [--keep-days <n>] [--json]
|
|
5562
|
+
agental claude show <connection-id> [--json]
|
|
5563
|
+
agental claude update <connection-id> [--template <template>|default] [--keep-days <n>] [--new-key] [--webhook-secret | --no-webhook-secret] [--json]
|
|
5564
|
+
agental claude disconnect <connection-id>
|
|
5237
5565
|
agental org [list] [--json]
|
|
5238
5566
|
agental org use <organization>
|
|
5239
5567
|
agental org create <name> [--json]
|
|
@@ -5248,6 +5576,7 @@ Usage
|
|
|
5248
5576
|
agental key allow-from <key> (<address-or-range>... | --anywhere) [--json]
|
|
5249
5577
|
agental key delete <key>
|
|
5250
5578
|
agental billing [prices | card | top-up <dollars> | auto-reload <dollars | off>] [--json]
|
|
5579
|
+
agental billing invoices [--limit <n>] [--json]
|
|
5251
5580
|
agental headroom [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
|
|
5252
5581
|
agental headroom budget <dollars> | budget default [--json]
|
|
5253
5582
|
agental egress [budget <dollars> | budget default] [--json]
|
|
@@ -5382,6 +5711,10 @@ webhooks lists the addresses your account's events are posted to, with what each
|
|
|
5382
5711
|
how its last post went. webhook add makes one: it posts to <url>, which has to be on the public
|
|
5383
5712
|
internet, the kinds --events names, such as sandbox.stopped,sandbox.error, or every kind with
|
|
5384
5713
|
--all, those added later included. The kinds are ${WEBHOOK_KINDS.join(", ")}.
|
|
5714
|
+
A group by its name and .*, as headroom.* or sandbox.*, is every kind of the group, and any
|
|
5715
|
+
added to it later; quote it, as --events 'headroom.*,sandbox.error', so the shell leaves it be.
|
|
5716
|
+
headroom.* are the organization's, about no sandbox: a burst begun and ended, starts refused,
|
|
5717
|
+
the running count met, and the burst budget at 80% and reached.
|
|
5385
5718
|
It prints the webhook's signing secret, the one time it is given: each post carries
|
|
5386
5719
|
X-Agental-Signature, the HMAC-SHA256 of its body under that secret. show says what one is sent,
|
|
5387
5720
|
how its last post went, and each event it did not take at the first try, with the answer to
|
|
@@ -5390,6 +5723,15 @@ every try. A post that is not answered with a 2xx is made again after 1, 5 and 1
|
|
|
5390
5723
|
its kinds or its description, and keeps what it is not given. rotate gives it a new secret,
|
|
5391
5724
|
and the old one stops working at once. delete removes it, the events still owed to it, and its
|
|
5392
5725
|
tries.
|
|
5726
|
+
claude lists the Claude Managed Agents environments connected to this account: each session of a
|
|
5727
|
+
connected self-hosted environment runs its tool calls in a sandbox of your own, made on the
|
|
5728
|
+
connection's template, stopped between turns and deleted once it has slept --keep-days (7). claude
|
|
5729
|
+
connect takes the environment's id from the Claude Console; its key is read from
|
|
5730
|
+
ANTHROPIC_ENVIRONMENT_KEY, from what is piped in, or asked for without being shown, never from the
|
|
5731
|
+
command line, and the webhook's signing secret likewise from ANTHROPIC_WEBHOOK_SIGNING_KEY. It
|
|
5732
|
+
prints the address to give the Claude Console as the webhook for session.status_run_started. update
|
|
5733
|
+
--new-key and --webhook-secret read a new one the same way; --no-webhook-secret forgets it.
|
|
5734
|
+
disconnect forgets the key and claims no more of its work.
|
|
5393
5735
|
org lists the organizations you are in, your own and your teams, and marks the one this command
|
|
5394
5736
|
acts in. A key acts in the organization it was made in, for good, so org use signs in again in
|
|
5395
5737
|
the browser for a key made in the one given, by its id or name, and deletes the key the command
|
|
@@ -5423,8 +5765,11 @@ from its next request, and the sandboxes it made stay. Limit a key used inside a
|
|
|
5423
5765
|
server it is on, which changes when it moves. On a network with IPv6 the API sees your IPv6
|
|
5424
5766
|
address, so a key limited to IPv4 addresses alone is refused there.
|
|
5425
5767
|
billing says where your account stands: its plan, what it has used this month at list price,
|
|
5426
|
-
what is left of the month's credits,
|
|
5427
|
-
after it and do not expire
|
|
5768
|
+
what is left of the month's credits, what is left of the top-ups, which are used
|
|
5769
|
+
after it and do not expire, and the card it pays with. invoices lists the account's invoices,
|
|
5770
|
+
newest first, each with its day, number, state, total and what it was for, and where to pay
|
|
5771
|
+
one that is not paid yet; --limit lists that many of the newest, and --json gives each one's
|
|
5772
|
+
page and PDF to the account's owner. The free plan costs nothing a month and pays for what runs from
|
|
5428
5773
|
credits alone; it makes tiny and small sandboxes. prices lists the plans with the sizes each
|
|
5429
5774
|
makes, the top-ups with their bonus and the hourly price of each size. card prints the address
|
|
5430
5775
|
of a page to save a card for the free plan: nothing is charged, and once it is saved the account
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agental",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The agental command: Linux sandboxes for your agents, from the terminal. npx agental@latest signs you in and installs the agent skills.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "VERTIXER LTD",
|