GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: track provider usage and project weekly quota by Aditya190803 · Pull Request #1605 · pingdotgg/t3code

feat: track provider usage and project weekly quota #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aditya190803 wants to merge 12 commits into pingdotgg:main from Aditya190803:feat/weekly-usage

Uh oh!

There was an error while loading. Please reload this page.

Closed

feat: track provider usage and project weekly quota #1605

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
2c04af8
feat(contracts): add normalized provider usage and quota bucket schemas
Aditya190803 Apr 1, 2026
7c0eff8
feat(server): normalize provider rate-limit usage and stabilize usage…
Aditya190803 Apr 1, 2026
af9b91a
feat(web): render provider quota usage buckets in settings
Aditya190803 Apr 1, 2026
00875eb
feat: reduce probe timeouts and add refreshProviders to server API
Aditya190803 Apr 1, 2026
0065213
feat: enhance provider status checks and normalize usage labels
Aditya190803 Apr 2, 2026
a15ce97
Merge branch 'main' into feat/weekly-usage
Aditya190803 Apr 2, 2026
283e68d
feat: add test for deriving usedPercent from absolute remaining counts
Aditya190803 Apr 2, 2026
6db0956
Merge branch 'pingdotgg:main' into feat/weekly-usage
Aditya190803 Apr 2, 2026
c37fa7c
feat: add test for preference of remaining percentages over counts in…
Aditya190803 Apr 2, 2026
a2faf1e
Merge branch 'main' into feat/weekly-usage
Aditya190803 Apr 3, 2026
8308571
Merge branch 'pingdotgg:main' into feat/weekly-usage
Aditya190803 Apr 4, 2026
c44983f
Merge branch 'pingdotgg:main' into feat/weekly-usage
Aditya190803 Apr 4, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
feat(web): render provider quota usage buckets in settings
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@Aditya190803
Aditya190803 committed Apr 2, 2026
commit af9b91aeb2eea4e2b8a2ea8a58cbee05134e2f33

There are no files selected for viewing

57 changes: 57 additions & 0 deletions 57 apps/web/src/components/settings/SettingsPanels.tsx
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type ProviderKind,
type ServerProvider,
type ServerProviderModel,
type ServerProviderUsageBucket,
ThreadId,
} from "@t3tools/contracts";
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
Expand Down Expand Up @@ -45,6 +46,11 @@ import {
getCustomModelOptionsByProvider,
resolveAppModelSelectionState,
} from "../../modelSelection";
import {
formatUsageRemainingPercent,
formatUsageResetAt,
getProviderUsageBuckets,
} from "../../lib/accountQuota";
import { ensureNativeApi, readNativeApi } from "../../nativeApi";
import { useStore } from "../../store";
import { formatRelativeTime, formatRelativeTimeLabel } from "../../timestampFormat";
Expand All @@ -64,6 +70,51 @@ import {
useServerProviders,
} from "../../rpc/serverState";

function ProviderUsageRows({
buckets,
timestampFormat,
}: {
buckets: ReadonlyArray<ServerProviderUsageBucket>;
timestampFormat: "locale" | "12-hour" | "24-hour";
}) {
if (buckets.length === 0) {
return null;
}

return (
<div className="px-4 pb-4 sm:px-5">
<div className="space-y-3">
{buckets.map((bucket) => (
<div key={bucket.id} className="space-y-1.5">
<div className="flex items-center justify-between gap-3">
<span className="text-xs font-medium text-foreground">{bucket.label}</span>
<span className="text-[11px] text-muted-foreground">
{formatUsageRemainingPercent(bucket)}
</span>
</div>
<div
className="h-1.5 overflow-hidden rounded-full bg-muted"
role="progressbar"
aria-label={bucket.label}
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={bucket.usedPercent}
>
<div
className="h-full rounded-full bg-foreground/80 transition-[width]"
style={{ width: `${bucket.usedPercent}%` }}
/>
</div>
<div className="text-[11px] text-muted-foreground">
{formatUsageResetAt(bucket.resetsAt, timestampFormat)}
</div>
</div>
))}
</div>
</div>
);
}

const THEME_OPTIONS = [
{
value: "system",
Expand Down Expand Up @@ -1063,6 +1114,7 @@ export function GeneralSettingsPanel() {
const customModelError = customModelErrorByProvider[providerCard.provider] ?? null;
const providerDisplayName =
PROVIDER_DISPLAY_NAMES[providerCard.provider] ?? providerCard.title;
const usageBuckets = getProviderUsageBuckets(providerCard.liveProvider);

return (
<div key={providerCard.provider} className="border-t border-border first:border-t-0">
Expand Down Expand Up @@ -1153,6 +1205,11 @@ export function GeneralSettingsPanel() {
</div>
</div>

<ProviderUsageRows
buckets={usageBuckets}
timestampFormat={settings.timestampFormat}
/>

<Collapsible
open={openProviderDetails[providerCard.provider]}
onOpenChange={(open) =>
Expand Down
77 changes: 77 additions & 0 deletions 77 apps/web/src/lib/accountQuota.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { describe, expect, it } from "vitest";
import type { ServerProvider } from "@t3tools/contracts";

import {
formatUsageRemainingPercent,
formatUsageResetAt,
getProviderUsageBuckets,
} from "./accountQuota";

function makeProvider(
input: Partial<ServerProvider> & Pick<ServerProvider, "provider">,
): ServerProvider {
return {
enabled: true,
installed: true,
version: "0.117.0",
status: "ready",
auth: { status: "authenticated" },
checkedAt: "2026-03-30T00:00:00.000Z",
models: [],
...input,
};
}

describe("accountQuota", () => {
it("returns provider usage buckets in normalized order", () => {
const buckets = getProviderUsageBuckets(
makeProvider({
provider: "codex",
usage: {
buckets: [
{
id: "fiveHour",
label: "5 hour usage limit",
remainingPercent: 67,
usedPercent: 33,
resetsAt: "2026-04-01T05:30:00.000Z",
},
{
id: "weekly",
label: "Weekly usage limit",
remainingPercent: 71,
usedPercent: 29,
resetsAt: "2026-04-06T05:12:45.000Z",
},
],
updatedAt: "2026-03-31T10:00:00.000Z",
},
}),
);

expect(buckets).toHaveLength(2);
expect(buckets[0]?.id).toBe("fiveHour");
expect(buckets[1]?.id).toBe("weekly");
});

it("formats compact remaining percentages", () => {
expect(
formatUsageRemainingPercent({
id: "weekly",
label: "Weekly usage limit",
remainingPercent: 58,
usedPercent: 42,
resetsAt: "2026-04-06T05:12:45.000Z",
}),
).toBe("58% remaining");
});

it("formats reset timestamps using the selected time format", () => {
expect(formatUsageResetAt("2026-04-06T17:05:00.000Z", "24-hour")).not.toMatch(/[AP]M/);
expect(formatUsageResetAt("2026-04-06T17:05:00.000Z", "12-hour")).toMatch(/[AP]M/);
});

it("returns an empty list when usage is unavailable", () => {
expect(getProviderUsageBuckets(makeProvider({ provider: "claudeAgent" }))).toEqual([]);
});
});
40 changes: 40 additions & 0 deletions 40 apps/web/src/lib/accountQuota.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type {
ServerProvider,
ServerProviderUsageBucket,
TimestampFormat,
} from "@t3tools/contracts";
import { getTimestampFormatOptions } from "../timestampFormat";

export function getProviderUsageBuckets(
provider: ServerProvider | null | undefined,
): ReadonlyArray<ServerProviderUsageBucket> {
return provider?.usage?.buckets ?? [];
}

export function formatUsageRemainingPercent(bucket: ServerProviderUsageBucket): string {
const rounded = Number.isInteger(bucket.remainingPercent)
? bucket.remainingPercent
: Number(bucket.remainingPercent.toFixed(1));
return `${rounded}% remaining`;
}

const usageResetFormatterCache = new Map<string, Intl.DateTimeFormat>();

function getUsageResetFormatter(timestampFormat: TimestampFormat): Intl.DateTimeFormat {
const cached = usageResetFormatterCache.get(timestampFormat);
if (cached) {
return cached;
}

const formatter = new Intl.DateTimeFormat(undefined, {
month: "short",
day: "numeric",
...getTimestampFormatOptions(timestampFormat, false),
});
usageResetFormatterCache.set(timestampFormat, formatter);
return formatter;
}

export function formatUsageResetAt(isoDate: string, timestampFormat: TimestampFormat): string {
return `Resets ${getUsageResetFormatter(timestampFormat).format(new Date(isoDate))}`;
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.