Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
107 lines
3.4 KiB
TypeScript
107 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { AlertTriangle, Gauge, KeyRound, RefreshCw } from "lucide-react";
|
|
import type { ApiKeyUsage } from "@/lib/types";
|
|
import { ApiError, getApiKeyUsage } from "@/lib/api";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/components/ui/card";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import { UsageList } from "@/components/usage/UsageCard";
|
|
import { useApiToken } from "@/lib/use-api-token";
|
|
import { friendlyErrorMessage } from "@/src/shared/errors/friendly";
|
|
|
|
type LoadState = "loading" | "ready" | "error";
|
|
|
|
/**
|
|
* The caller's per-key current-month usage + quotas, reusing the Epic-3 usage
|
|
* fetcher (GET /me/api-keys/usage) and presentational {@link UsageList}. Strictly
|
|
* caller-scoped and token-free; read-only.
|
|
*/
|
|
export function DeveloperUsageSection() {
|
|
const getApiToken = useApiToken();
|
|
const [status, setStatus] = React.useState<LoadState>("loading");
|
|
const [usage, setUsage] = React.useState<readonly ApiKeyUsage[]>([]);
|
|
const [errorMessage, setErrorMessage] = React.useState("");
|
|
|
|
const load = React.useCallback(async () => {
|
|
setStatus("loading");
|
|
setErrorMessage("");
|
|
try {
|
|
const token = await getApiToken();
|
|
const result = await getApiKeyUsage({ token });
|
|
setUsage(result);
|
|
setStatus("ready");
|
|
} catch (err) {
|
|
setErrorMessage(
|
|
friendlyErrorMessage(err, "Couldn't load your API-key usage."),
|
|
);
|
|
setStatus("error");
|
|
}
|
|
}, [getApiToken]);
|
|
|
|
React.useEffect(() => {
|
|
void load();
|
|
}, [load]);
|
|
|
|
return (
|
|
<Card>
|
|
<CardHeader>
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<div>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<Gauge className="size-5 text-primary" aria-hidden />
|
|
Usage & quota
|
|
</CardTitle>
|
|
<CardDescription>
|
|
Per-key rate limits, monthly quotas, and requests used this month.
|
|
</CardDescription>
|
|
</div>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => void load()}
|
|
disabled={status === "loading"}
|
|
>
|
|
<RefreshCw
|
|
className={status === "loading" ? "size-4 animate-spin" : "size-4"}
|
|
aria-hidden
|
|
/>
|
|
Refresh
|
|
</Button>
|
|
</div>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{status === "loading" ? (
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<Skeleton className="h-28 w-full rounded-lg" />
|
|
<Skeleton className="h-28 w-full rounded-lg" />
|
|
</div>
|
|
) : status === "error" ? (
|
|
<p
|
|
className="flex items-center gap-2 text-sm text-destructive"
|
|
role="alert"
|
|
>
|
|
<AlertTriangle className="size-4 shrink-0" aria-hidden />
|
|
{errorMessage}
|
|
</p>
|
|
) : usage.length === 0 ? (
|
|
<p className="flex flex-col items-center gap-2 rounded-md border border-dashed border-border p-8 text-center text-sm text-muted-foreground">
|
|
<KeyRound className="size-6 text-muted-foreground" aria-hidden />
|
|
No usage yet. Create an API key and make a request to see your
|
|
per-key usage here.
|
|
</p>
|
|
) : (
|
|
<UsageList usage={usage} />
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|