agental 0.9.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 +118 -10
- 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}`;
|
|
@@ -3220,7 +3220,7 @@ async function main() {
|
|
|
3220
3220
|
await key({ request, fail }, positionals.slice(1), values);
|
|
3221
3221
|
return;
|
|
3222
3222
|
case "billing":
|
|
3223
|
-
await billing(positionals.slice(1), values.json);
|
|
3223
|
+
await billing(positionals.slice(1), values.json, values.limit);
|
|
3224
3224
|
return;
|
|
3225
3225
|
case "headroom":
|
|
3226
3226
|
await headroom(positionals.slice(1), { json: values.json, from: values.from, to: values.to, step: values.step });
|
|
@@ -4899,18 +4899,25 @@ async function telemetry(positionals, given, asJson) {
|
|
|
4899
4899
|
throw new Error(usage);
|
|
4900
4900
|
}
|
|
4901
4901
|
}
|
|
4902
|
-
async function billing(positionals, asJson) {
|
|
4902
|
+
async function billing(positionals, asJson, limit) {
|
|
4903
4903
|
const [what, amount, ...rest] = positionals;
|
|
4904
|
-
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>";
|
|
4905
4905
|
if (rest.length > 0 || what !== "top-up" && what !== "auto-reload" && amount !== void 0) {
|
|
4906
4906
|
throw new Error(usage);
|
|
4907
4907
|
}
|
|
4908
|
+
if (limit !== void 0 && what !== "invoices") {
|
|
4909
|
+
throw new Error("--limit is taken by billing invoices alone.");
|
|
4910
|
+
}
|
|
4908
4911
|
const print4 = (body, text) => process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
|
|
4909
4912
|
` : text());
|
|
4910
4913
|
switch (what) {
|
|
4911
4914
|
case void 0: {
|
|
4912
|
-
const body = await asked("/v1/billing", { method: "GET" });
|
|
4913
|
-
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);
|
|
4914
4921
|
return;
|
|
4915
4922
|
}
|
|
4916
4923
|
case "prices": {
|
|
@@ -4974,14 +4981,17 @@ function wholeMoney(micros) {
|
|
|
4974
4981
|
function dayOf(iso) {
|
|
4975
4982
|
return iso ? new Date(iso).toLocaleDateString("en-GB", { day: "numeric", month: "long", timeZone: "UTC" }) : "";
|
|
4976
4983
|
}
|
|
4977
|
-
function describeBilling(body) {
|
|
4984
|
+
function describeBilling(body, card = null) {
|
|
4978
4985
|
const lines = [];
|
|
4979
4986
|
const free = body.free ?? null;
|
|
4980
4987
|
if (free && body.plan) {
|
|
4981
4988
|
lines.push(["Plan", "free: nothing a month. What runs is paid from your credits, at list price."]);
|
|
4982
4989
|
if (!free.cardSaved) {
|
|
4983
4990
|
lines.push(["Card", "none saved. Save one, charged nothing, to run sandboxes and be given the free plan's credit: agental billing card."]);
|
|
4984
|
-
} else if (
|
|
4991
|
+
} else if (card) {
|
|
4992
|
+
lines.push(["Card", describeCard(card)]);
|
|
4993
|
+
}
|
|
4994
|
+
if (free.cardSaved && !free.paid) {
|
|
4985
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.`]);
|
|
4986
4996
|
}
|
|
4987
4997
|
lines.push(["Used", `${money(body.usedMicros)} this month at list price${usedParts(body)}`]);
|
|
@@ -5006,6 +5016,9 @@ function describeBilling(body) {
|
|
|
5006
5016
|
const charged = body.usedMicros - (body.discount?.micros ?? 0) + (body.carriedMicros ?? 0);
|
|
5007
5017
|
lines.push(["Included", `${money(body.includedMicros)}, ${money(Math.max(0, body.includedMicros - charged))} left. It does not carry over.`]);
|
|
5008
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
|
+
}
|
|
5009
5022
|
if (body.autoReload) {
|
|
5010
5023
|
lines.push(["Auto-reload", describeAutoReload(body.autoReload)]);
|
|
5011
5024
|
} else if (body.canAutoReload) {
|
|
@@ -5032,6 +5045,97 @@ function describeBilling(body) {
|
|
|
5032
5045
|
return lines.map(([label, value]) => `${label.padEnd(14)}${value}
|
|
5033
5046
|
`).join("");
|
|
5034
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
|
+
}
|
|
5035
5139
|
function usedParts(body) {
|
|
5036
5140
|
const parts = [
|
|
5037
5141
|
...(body.mailMicros ?? 0) > 0 ? [`${money(body.mailMicros ?? 0)} by email`] : [],
|
|
@@ -5472,6 +5576,7 @@ Usage
|
|
|
5472
5576
|
agental key allow-from <key> (<address-or-range>... | --anywhere) [--json]
|
|
5473
5577
|
agental key delete <key>
|
|
5474
5578
|
agental billing [prices | card | top-up <dollars> | auto-reload <dollars | off>] [--json]
|
|
5579
|
+
agental billing invoices [--limit <n>] [--json]
|
|
5475
5580
|
agental headroom [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
|
|
5476
5581
|
agental headroom budget <dollars> | budget default [--json]
|
|
5477
5582
|
agental egress [budget <dollars> | budget default] [--json]
|
|
@@ -5660,8 +5765,11 @@ from its next request, and the sandboxes it made stay. Limit a key used inside a
|
|
|
5660
5765
|
server it is on, which changes when it moves. On a network with IPv6 the API sees your IPv6
|
|
5661
5766
|
address, so a key limited to IPv4 addresses alone is refused there.
|
|
5662
5767
|
billing says where your account stands: its plan, what it has used this month at list price,
|
|
5663
|
-
what is left of the month's credits,
|
|
5664
|
-
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
|
|
5665
5773
|
credits alone; it makes tiny and small sandboxes. prices lists the plans with the sizes each
|
|
5666
5774
|
makes, the top-ups with their bonus and the hourly price of each size. card prints the address
|
|
5667
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",
|