diff --git a/package-lock.json b/package-lock.json index 2fed47f..25b96fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pixelvault-cli", - "version": "0.23.1", + "version": "0.23.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pixelvault-cli", - "version": "0.23.1", + "version": "0.23.2", "license": "MIT", "dependencies": { "citty": "^0.1.6" diff --git a/package.json b/package.json index 03ad31a..ab80ac6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixelvault-cli", - "version": "0.23.1", + "version": "0.23.2", "description": "CLI for PixelVault — agent-first media hosting for images, PDFs, and video", "type": "module", "bin": { diff --git a/src/commands/usage.ts b/src/commands/usage.ts index e3c2214..08f4630 100644 --- a/src/commands/usage.ts +++ b/src/commands/usage.ts @@ -14,17 +14,38 @@ export interface UsageData { bandwidth_bytes_per_month: number | null; }; remaining: { storage_bytes: number | null; uploads: number | null }; + bandwidth?: { + status: "available" | "unavailable" | "unlimited"; + used: number | null; + remaining: number | null; + limit: number | null; + unit: "bytes"; + accounting_period: string; + resets_at: string; + measured_at: string | null; + freshness: "near_real_time" | "delayed" | "unavailable" | "not_applicable"; + }; /** AI image-generation credits (`pixelvault generate`) for the month. */ generation?: { credits_used: number; credits_limit: number; credits_remaining: number; }; + editing?: { + credits_used: number; + credits_limit: number; + credits_remaining: number; + }; video_optimization?: { seconds_used: number; seconds_limit: number; seconds_remaining: number; }; + video_enrichment?: { + seconds_used: number; + seconds_limit: number; + seconds_remaining: number; + }; } const bytes = (n: number | null | undefined) => @@ -32,23 +53,50 @@ const bytes = (n: number | null | undefined) => const count = (n: number | null | undefined) => n == null ? "unlimited" : String(n); +function renderBandwidth(d: UsageData): string { + const bandwidth = d.bandwidth; + if (!bandwidth) { + return `${bytes(d.limits.bandwidth_bytes_per_month)} limit per month (usage unavailable)`; + } + if (bandwidth.status === "unavailable") { + return `${bytes(bandwidth.limit)} limit for ${bandwidth.accounting_period} (used and remaining unknown; accounting unavailable)`; + } + if (bandwidth.status === "unlimited") { + return `${bandwidth.used == null ? "unknown" : formatBytes(bandwidth.used)} used / unlimited`; + } + const used = bandwidth.used == null ? "unknown" : formatBytes(bandwidth.used); + const limit = bandwidth.limit == null ? "unknown" : formatBytes(bandwidth.limit); + const left = bandwidth.remaining == null ? "unknown" : formatBytes(bandwidth.remaining); + return `${used} used / ${limit} limit / ${left} remaining (${bandwidth.freshness})`; +} + export function renderUsage(d: UsageData): string[] { return [ `Plan: ${d.plan}`, `Period: ${d.period} (resets ${d.resets_at})`, `Storage: ${formatBytes(d.usage.storage_bytes)} used / ${bytes(d.limits.storage_bytes)} limit / ${bytes(d.remaining.storage_bytes)} remaining`, `Uploads: ${d.usage.uploads} used / ${count(d.limits.uploads_per_month)} limit / ${count(d.remaining.uploads)} remaining`, - `Bandwidth: ${bytes(d.limits.bandwidth_bytes_per_month)} limit per month (usage not reported)`, + `Bandwidth: ${renderBandwidth(d)}`, ...(d.generation ? [ `AI images: ${d.generation.credits_used} credits used / ${d.generation.credits_limit} limit / ${d.generation.credits_remaining} remaining`, ] : []), + ...(d.editing + ? [ + `AI edits: ${d.editing.credits_used} credits used / ${d.editing.credits_limit} limit / ${d.editing.credits_remaining} remaining`, + ] + : []), ...(d.video_optimization ? [ `Social-ready video: ${d.video_optimization.seconds_used}s used / ${d.video_optimization.seconds_limit}s limit / ${d.video_optimization.seconds_remaining}s remaining`, ] : []), + ...(d.video_enrichment + ? [ + `Video enrichment: ${d.video_enrichment.seconds_used}s used / ${d.video_enrichment.seconds_limit}s limit / ${d.video_enrichment.seconds_remaining}s remaining`, + ] + : []), ]; } diff --git a/src/lib/client.ts b/src/lib/client.ts index 85129d8..e26845a 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -18,7 +18,7 @@ interface ApiError { // this channel (server reads X-PixelVault-Client at register/device-login — see // pixelvault docs/specs/lead-attribution.md). Keep the version in sync with // package.json on release (tests/lib/version.test.ts fails if they drift). -export const VERSION = "0.23.1"; +export const VERSION = "0.23.2"; const CLIENT_ID = `pixelvault-cli/${VERSION}`; /** CliError carrying the API's machine-readable error details. */ diff --git a/tests/commands/usage-keys.test.ts b/tests/commands/usage-keys.test.ts index 8d503ee..5f29e62 100644 --- a/tests/commands/usage-keys.test.ts +++ b/tests/commands/usage-keys.test.ts @@ -5,7 +5,7 @@ vi.mock("../../src/lib/config.js", () => ({ getApiUrl: () => "https://api.test.pixelvault.dev", })); -const { default: usage } = await import("../../src/commands/usage.js"); +const { default: usage, renderUsage } = await import("../../src/commands/usage.js"); const { default: keys } = await import("../../src/commands/keys.js"); const { formatBytes } = await import("../../src/lib/output.js"); @@ -23,6 +23,17 @@ const USAGE = { bandwidth_bytes_per_month: 10 * 1024 ** 3, }, remaining: { storage_bytes: 1024 ** 3 - 5 * 1024 * 1024, uploads: 488 }, + bandwidth: { + status: "unavailable" as const, + used: null, + remaining: null, + limit: 10 * 1024 ** 3, + unit: "bytes" as const, + accounting_period: "2026-10", + resets_at: "2026-11-01T00:00:00Z", + measured_at: null, + freshness: "unavailable" as const, + }, }; function mockFetch(status: number, body: unknown, headers: Record = {}) { @@ -75,7 +86,7 @@ describe("usage / keys commands", () => { expect(out).toContain("2026-10"); expect(out).toContain("5 MB used / 1 GB limit"); expect(out).toContain("12 used / 500 limit / 488 remaining"); - expect(out).toContain("10 GB limit per month"); + expect(out).toContain("10 GB limit for 2026-10 (used and remaining unknown; accounting unavailable)"); expect(err).toBe(""); }); @@ -96,6 +107,34 @@ describe("usage / keys commands", () => { expect(out).not.toContain("AI images"); }); + it("distinguishes zero, delayed accounting, and unlimited bandwidth", () => { + const available = renderUsage({ + ...USAGE, + bandwidth: { + ...USAGE.bandwidth, + status: "available", + used: 0, + remaining: 10 * 1024 ** 3, + measured_at: "2026-10-24T09:55:00Z", + freshness: "delayed", + }, + }); + expect(available).toContain("Bandwidth: 0 B used / 10 GB limit / 10 GB remaining (delayed)"); + + const unlimited = renderUsage({ + ...USAGE, + bandwidth: { + ...USAGE.bandwidth, + status: "unlimited", + used: 1024, + remaining: null, + limit: null, + freshness: "not_applicable", + }, + }); + expect(unlimited).toContain("Bandwidth: 1 KB used / unlimited"); + }); + it("--json prints the data object", async () => { mockFetch(200, { data: USAGE }); await usage.run!({ args: { json: true } } as any);