@nodaro/cli 1.17.0 → 1.18.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/index.js CHANGED
@@ -29,7 +29,7 @@ var require_package = __commonJS({
29
29
  "package.json"(exports$1, module) {
30
30
  module.exports = {
31
31
  name: "@nodaro/cli",
32
- version: "1.17.0",
32
+ version: "1.18.0",
33
33
  description: "Command-line interface for Nodaro \u2014 list and run workflows, inspect jobs and executions, manage projects from the terminal.",
34
34
  type: "module",
35
35
  license: "Apache-2.0",
@@ -70,11 +70,11 @@ var require_package = __commonJS({
70
70
  "@inquirer/confirm": "^6.0.12",
71
71
  "@inquirer/input": "^5.0.12",
72
72
  "@inquirer/select": "^5.1.4",
73
- "@nodaro/sdk": "^1.25.0",
74
- "@nodaro/shared": "^2.17.0",
73
+ "@nodaro/sdk": "^1.26.0",
74
+ "@nodaro/shared": "^2.20.0",
75
75
  commander: "^12.1.0",
76
76
  picocolors: "^1.1.1",
77
- "@nodaro/prompts": "^1.12.0"
77
+ "@nodaro/prompts": "^1.15.0"
78
78
  },
79
79
  devDependencies: {
80
80
  tsup: "^8.5.0",
@@ -398,7 +398,7 @@ function saveWorkspace(profileName, workspaceId) {
398
398
  }
399
399
 
400
400
  // src/client.ts
401
- var CLI_VERSION = "1.17.0" ;
401
+ var CLI_VERSION = "1.18.0" ;
402
402
  function buildClient(profileName) {
403
403
  const { name, profile } = getProfile(profileName);
404
404
  if (!profile) {
@@ -4325,6 +4325,67 @@ function orgCommand() {
4325
4325
  handleError(err);
4326
4326
  }
4327
4327
  });
4328
+ cmd.command("usage <orgId>").description("credits by workspace, member, model or day for a date range").option("--from <YYYY-MM-DD>", "inclusive start date").option("--to <YYYY-MM-DD>", "inclusive end date").option("--tz <iana>", "IANA time zone (default: your local zone)").option("--group-by <dim>", "workspace | member | model | day | none", "day").option("--workspace <id>", "narrow to one workspace").option("--user <id>", "narrow to one member").option("--limit <n>", "rows page size (with --group-by none)", (v) => Number(v)).option("--cursor <cursor>", "continue a rows page").option("--csv", "write the report as CSV to stdout").option("--profile <name>").option("--json").action(
4329
+ async (orgId, opts) => {
4330
+ try {
4331
+ const client = buildClient(opts.profile);
4332
+ const tz = opts.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
4333
+ const common = { from: opts.from, to: opts.to, tz, workspaceId: opts.workspace, userId: opts.user };
4334
+ if (opts.csv) {
4335
+ process.stdout.write(
4336
+ await client.organizations.usageCsv(orgId, {
4337
+ ...common,
4338
+ groupBy: opts.groupBy
4339
+ })
4340
+ );
4341
+ return;
4342
+ }
4343
+ if (opts.groupBy === "none") {
4344
+ const page = await client.organizations.usageRows(orgId, { ...common, limit: opts.limit, cursor: opts.cursor });
4345
+ if (opts.json) {
4346
+ emit(page, opts);
4347
+ return;
4348
+ }
4349
+ table(
4350
+ page.data.map((e) => ({
4351
+ at: e.createdAt,
4352
+ member: e.member?.displayName ?? e.member?.email ?? e.member?.userId ?? "",
4353
+ model: e.model,
4354
+ status: e.status,
4355
+ credits: e.credits
4356
+ })),
4357
+ ["at", "member", "model", "status", "credits"]
4358
+ );
4359
+ if (page.nextCursor) dim(`more: --cursor ${page.nextCursor}`);
4360
+ return;
4361
+ }
4362
+ const { data: report } = await client.organizations.usage(orgId, {
4363
+ ...common,
4364
+ groupBy: opts.groupBy
4365
+ });
4366
+ if (opts.json) {
4367
+ emit(report, opts);
4368
+ return;
4369
+ }
4370
+ table(
4371
+ report.rows.map((r) => ({
4372
+ group: r.workspace ? r.workspace.name ?? r.workspace.slug ?? r.workspace.id : r.member ? r.member.displayName ?? r.member.email ?? r.member.userId : r.model ?? r.day ?? r.key,
4373
+ runs: r.runCount,
4374
+ credits: r.credits,
4375
+ settled: r.settledCredits,
4376
+ in_flight: r.inFlightCredits
4377
+ })),
4378
+ ["group", "runs", "credits", "settled", "in_flight"]
4379
+ );
4380
+ dim(
4381
+ `total: ${report.totals.credits} credits (${report.totals.settledCredits} settled, ${report.totals.inFlightCredits} in flight, ${report.totals.platformAbsorbedCredits} platform-absorbed overrun, ${report.totals.appMarkupAbsorbedCredits} app-markup absorbed)`
4382
+ );
4383
+ if (report.truncated) warn("report truncated at 5000 groups \u2014 narrow the window");
4384
+ } catch (err) {
4385
+ handleError(err);
4386
+ }
4387
+ }
4388
+ );
4328
4389
  return cmd;
4329
4390
  }
4330
4391
  function workspaceCommand() {
@@ -4453,6 +4514,72 @@ function workspaceCommand() {
4453
4514
  handleError(err);
4454
4515
  }
4455
4516
  });
4517
+ cmd.command("usage [id]").description("credits by member, model or day for a workspace (yours if id omitted)").option("--from <YYYY-MM-DD>", "inclusive start date").option("--to <YYYY-MM-DD>", "inclusive end date").option("--tz <iana>", "IANA time zone (default: your local zone)").option("--group-by <dim>", "member | model | day | none", "day").option("--user <id>", "narrow to one member (admins only)").option("--limit <n>", "rows page size (with --group-by none)", (v) => Number(v)).option("--cursor <cursor>", "continue a rows page").option("--csv", "write the report as CSV to stdout").option("--profile <name>").option("--json").action(
4518
+ async (id, opts) => {
4519
+ try {
4520
+ const workspaceId = id ?? resolveWorkspace(getProfile(opts.profile).profile).workspaceId;
4521
+ if (!workspaceId) {
4522
+ handleError(new Error("no workspace selected; pass an id or run nodaro workspace use <id>"));
4523
+ return;
4524
+ }
4525
+ const client = buildClient(opts.profile);
4526
+ const tz = opts.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
4527
+ const common = { from: opts.from, to: opts.to, tz, userId: opts.user };
4528
+ if (opts.csv) {
4529
+ process.stdout.write(
4530
+ await client.workspaces.usageCsv(workspaceId, {
4531
+ ...common,
4532
+ groupBy: opts.groupBy
4533
+ })
4534
+ );
4535
+ return;
4536
+ }
4537
+ if (opts.groupBy === "none") {
4538
+ const page = await client.workspaces.usageRows(workspaceId, { ...common, limit: opts.limit, cursor: opts.cursor });
4539
+ if (opts.json) {
4540
+ emit(page, opts);
4541
+ return;
4542
+ }
4543
+ table(
4544
+ page.data.map((e) => ({
4545
+ at: e.createdAt,
4546
+ member: e.member?.displayName ?? e.member?.email ?? e.member?.userId ?? "",
4547
+ model: e.model,
4548
+ status: e.status,
4549
+ credits: e.credits
4550
+ })),
4551
+ ["at", "member", "model", "status", "credits"]
4552
+ );
4553
+ if (page.nextCursor) dim(`more: --cursor ${page.nextCursor}`);
4554
+ return;
4555
+ }
4556
+ const { data: report } = await client.workspaces.usage(workspaceId, {
4557
+ ...common,
4558
+ groupBy: opts.groupBy
4559
+ });
4560
+ if (opts.json) {
4561
+ emit(report, opts);
4562
+ return;
4563
+ }
4564
+ table(
4565
+ report.rows.map((r) => ({
4566
+ group: r.member ? r.member.displayName ?? r.member.email ?? r.member.userId : r.model ?? r.day ?? r.key,
4567
+ runs: r.runCount,
4568
+ credits: r.credits,
4569
+ settled: r.settledCredits,
4570
+ in_flight: r.inFlightCredits
4571
+ })),
4572
+ ["group", "runs", "credits", "settled", "in_flight"]
4573
+ );
4574
+ dim(
4575
+ `total: ${report.totals.credits} credits (${report.totals.settledCredits} settled, ${report.totals.inFlightCredits} in flight, ${report.totals.platformAbsorbedCredits} platform-absorbed overrun, ${report.totals.appMarkupAbsorbedCredits} app-markup absorbed)`
4576
+ );
4577
+ if (report.truncated) warn("report truncated at 5000 groups \u2014 narrow the window");
4578
+ } catch (err) {
4579
+ handleError(err);
4580
+ }
4581
+ }
4582
+ );
4456
4583
  return cmd;
4457
4584
  }
4458
4585
  var SOURCE_LABELS = {