@letterstory/cli 0.122.0 → 0.123.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/lib/cli.mjs +3 -2
- package/lib/commands/admin.mjs +29 -2
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
} from "./commands.mjs";
|
|
62
62
|
|
|
63
63
|
// Keep in sync with cli/package.json.
|
|
64
|
-
export const VERSION = "0.
|
|
64
|
+
export const VERSION = "0.123.0";
|
|
65
65
|
|
|
66
66
|
// Flags that never take a value. Listing them explicitly means `deploy get --json <id>`
|
|
67
67
|
// can't accidentally swallow the id as --json's value. Every `type: "bool"` flag (and its
|
|
@@ -851,7 +851,8 @@ Admin (STAFF key — --staff-key / LETTERSTORY_STAFF_API_KEY; acts before an org
|
|
|
851
851
|
| add --vendor V --amount N --from D [--to D] --area A --category C [--basis billed|estimated] …
|
|
852
852
|
| import <file.csv> [--vendor Concentrate] [--area A] [--ledger-key K] [--dry-run]
|
|
853
853
|
| import <file.csv> [--vendor Concentrate] [--area A] [--keep-ledger-key] [--dry-run]
|
|
854
|
-
| usage <events.json> per-call costs as kernels/lettertrace push them
|
|
854
|
+
| usage <events.json> per-call costs as kernels/lettertrace/models push them
|
|
855
|
+
| usage list --source models --from D --to D one source's calls back, newest first
|
|
855
856
|
| remove <entry-id> | services | service <slug> [--owner …] [--monthly N|none] [--renewal D] [--units N|none]
|
|
856
857
|
Where Letter's money goes (spending.letter.dev):
|
|
857
858
|
totals, run rate, area/vendor/provider/model/
|
package/lib/commands/admin.mjs
CHANGED
|
@@ -4043,7 +4043,34 @@ async function cmdAdminSpend(ctx) {
|
|
|
4043
4043
|
return 0;
|
|
4044
4044
|
}
|
|
4045
4045
|
case "usage": {
|
|
4046
|
-
|
|
4046
|
+
if (positionals[1] === "list") {
|
|
4047
|
+
// One source's calls back, newest first (GET /api/superadmin/spend/usage).
|
|
4048
|
+
const source = flagStr(flags.source);
|
|
4049
|
+
const from = flagStr(flags.from);
|
|
4050
|
+
const to = flagStr(flags.to);
|
|
4051
|
+
if (!source || !from || !to)
|
|
4052
|
+
throw new CliError(
|
|
4053
|
+
"Usage: admin spend usage list --source models --from YYYY-MM-DD --to YYYY-MM-DD [--limit N]"
|
|
4054
|
+
);
|
|
4055
|
+
const params = new URLSearchParams(
|
|
4056
|
+
compact({ source, from, to, limit: flagNum(flags.limit)?.toString() })
|
|
4057
|
+
);
|
|
4058
|
+
const result = await staffRequest(ctx, "GET", `${SPEND}/usage?${params}`);
|
|
4059
|
+
printResult(
|
|
4060
|
+
io,
|
|
4061
|
+
flags,
|
|
4062
|
+
result,
|
|
4063
|
+
(r) =>
|
|
4064
|
+
(r.events ?? [])
|
|
4065
|
+
.map(
|
|
4066
|
+
(e) =>
|
|
4067
|
+
`${e.occurred_at} ${e.model.padEnd(16)} ${e.operation.padEnd(10)} ${(e.outcome ?? "").padEnd(8)} ${String(e.latency_ms ?? "").padStart(7)}ms ${usd(e.cost_usd).padStart(9)} ${e.key_label}`
|
|
4068
|
+
)
|
|
4069
|
+
.join("\n") + (r.next ? "\n… more (narrow --from/--to or raise --limit)" : "")
|
|
4070
|
+
);
|
|
4071
|
+
return 0;
|
|
4072
|
+
}
|
|
4073
|
+
// Per-call model costs, as kernels / lettertrace / models push them (POST /api/superadmin/spend/usage):
|
|
4047
4074
|
// a JSON file holding { events: [...] } or a bare array. Idempotent on each event_id.
|
|
4048
4075
|
const path = positionals[1];
|
|
4049
4076
|
if (!path) throw new CliError("Usage: admin spend usage <events.json> ({ events: [...] } or an array)");
|
|
@@ -4193,7 +4220,7 @@ async function cmdAdminSpend(ctx) {
|
|
|
4193
4220
|
}
|
|
4194
4221
|
default:
|
|
4195
4222
|
throw new CliError(
|
|
4196
|
-
"Usage: admin spend summary [--range day|week|month|year | --from D --to D] [--grain day|week|month] | reconcile [--from D --to D] | pnl [--range …] | reference add … | stripe-sync --from D --to D | entries [--from D] [--to D] [--vendor V] [--area A] [--source S] | add --vendor V --amount N --from D … | import <file.csv> … | usage <events.json> | remove <entry-id> | services | service <slug> --owner … --monthly …"
|
|
4223
|
+
"Usage: admin spend summary [--range day|week|month|year | --from D --to D] [--grain day|week|month] | reconcile [--from D --to D] | pnl [--range …] | reference add … | stripe-sync --from D --to D | entries [--from D] [--to D] [--vendor V] [--area A] [--source S] | add --vendor V --amount N --from D … | import <file.csv> … | usage <events.json> | usage list --source S --from D --to D | remove <entry-id> | services | service <slug> --owner … --monthly …"
|
|
4197
4224
|
);
|
|
4198
4225
|
}
|
|
4199
4226
|
}
|