Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
50 changes: 49 additions & 1 deletion src/commands/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,89 @@ 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) =>
n == null ? "unlimited" : formatBytes(n);
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`,
]
: []),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
43 changes: 41 additions & 2 deletions tests/commands/usage-keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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<string, string> = {}) {
Expand Down Expand Up @@ -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("");
});

Expand All @@ -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);
Expand Down
Loading