1}
+ showAccountName={showAccountName}
/>
) : pool.kind === "monthly" && member.account.limits.zeroSpendCap ? (
{
]);
});
+ it("keeps the emergency route name and still names the other Grok seat", () => {
+ const grok = ProviderDriverKind.make("grok");
+ const weeklyGrok = { ...window, id: "subscription", kind: "weekly" as const, usedPercent: 7 };
+ const emergency = provider({
+ driver: grok,
+ instanceId: ProviderInstanceId.make("grok-direct"),
+ displayName: "Grok · Emergency (direct)",
+ auth: { status: "authenticated", email: "a@example.com" },
+ usageLimits: { checkedAt, windows: [weeklyGrok] },
+ });
+ const hubAccount = (
+ email: string,
+ displayName: string,
+ usedPercent: number,
+ status?: "held" | "signed-out",
+ ) => ({
+ id: `grok:${email}`,
+ driver: grok,
+ email,
+ displayName,
+ ...(status
+ ? { status, statusDetail: status === "held" ? "Held." : "Sign-in required." }
+ : {}),
+ usageLimits: { checkedAt, windows: [{ ...weeklyGrok, usedPercent }] },
+ });
+ const input = new Map([
+ [
+ EnvironmentId.make("env-a"),
+ {
+ ...laptop,
+ serverConfig: {
+ providers: [emergency],
+ usageLimitSources: [
+ {
+ ...source,
+ kind: "magpie" as const,
+ label: "Magpie",
+ accounts: [
+ hubAccount("a@example.com", "A Person · SuperGrok", 7, "held"),
+ hubAccount("b@example.com", "B Person · SuperGrok", 65),
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ ]);
+ expect(
+ collectLimitAccounts(input).map(({ displayName, email, status }) => ({
+ displayName,
+ email,
+ status,
+ })),
+ ).toEqual([
+ { displayName: "Grok · Emergency (direct)", email: "a@example.com", status: "held" },
+ { displayName: "B Person · SuperGrok", email: "b@example.com", status: null },
+ ]);
+ });
+
+ it("keeps a chosen instance name and a hub alias whichever row arrives first", () => {
+ const grok = ProviderDriverKind.make("grok");
+ const weeklyGrok = { ...window, id: "subscription", kind: "weekly" as const, usedPercent: 7 };
+ const instance = (id: string, displayName: string) =>
+ provider({
+ driver: grok,
+ instanceId: ProviderInstanceId.make(id),
+ displayName,
+ auth: { status: "authenticated", email: "a@example.com" },
+ usageLimits: { checkedAt, windows: [weeklyGrok] },
+ });
+ const hub = (id: string, displayName?: string) => ({
+ id,
+ driver: grok,
+ email: "a@example.com",
+ ...(displayName ? { displayName } : {}),
+ usageLimits: { checkedAt, windows: [weeklyGrok] },
+ });
+ const names = (providers: ReturnType[], accounts: ReturnType[]) =>
+ collectLimitAccounts(
+ new Map([
+ [
+ EnvironmentId.make("env-a"),
+ {
+ ...laptop,
+ serverConfig: {
+ providers,
+ usageLimitSources: [{ ...source, accounts }],
+ },
+ },
+ ],
+ ]),
+ ).map((account) => account.displayName);
+
+ const generic = instance("grok", "Grok");
+ const emergency = instance("grok-direct", "Grok · Emergency (direct)");
+ const unnamed = hub("plain");
+ const aliased = hub("named", "A Person · SuperGrok");
+ for (const providers of [
+ [generic, emergency],
+ [emergency, generic],
+ ]) {
+ expect(names(providers, [unnamed, aliased])).toEqual(["Grok · Emergency (direct)"]);
+ expect(names(providers, [aliased, unnamed])).toEqual(["Grok · Emergency (direct)"]);
+ }
+ expect(names([], [unnamed, aliased])).toEqual(["A Person · SuperGrok"]);
+ expect(names([], [aliased, unnamed])).toEqual(["A Person · SuperGrok"]);
+ });
+
it("pools Codex windows by kind, whichever slot reported them", () => {
const codexAccount = (id: string, slots: readonly string[]) => ({
id,
@@ -1119,6 +1227,8 @@ describe("pools", () => {
displayName: "Go",
email: undefined,
plan: undefined,
+ status: null,
+ statusDetail: null,
accentColor: undefined,
environments: [],
sourceLabel: null,
@@ -1170,6 +1280,8 @@ describe("pooled account columns", () => {
displayName: key,
email: undefined,
plan: undefined,
+ status: null,
+ statusDetail: null,
accentColor: undefined,
environments: [],
sourceLabel: "Hub",
@@ -1497,6 +1609,81 @@ describe("/usage-limits", () => {
expect(report?.accounts[0]?.limits.resetCredits?.availableCount).toBe(3);
});
+ it("copies a merged hub alias and held or signed-out state onto the composer row", () => {
+ const grok = ProviderDriverKind.make("grok");
+ const native = provider({
+ driver: grok,
+ instanceId: ProviderInstanceId.make("grok"),
+ displayName: "Grok",
+ auth: { status: "authenticated", email: "a@example.com" },
+ usageLimits: limits,
+ });
+ const emergency = provider({
+ ...native,
+ instanceId: ProviderInstanceId.make("grok-direct"),
+ displayName: "Grok · Emergency (direct)",
+ });
+ const hub = [
+ {
+ ...sources[0]!,
+ accounts: [
+ {
+ id: "grok:a@example.com",
+ driver: grok,
+ email: "a@example.com",
+ displayName: "A Person · SuperGrok",
+ status: "held" as const,
+ statusDetail: "Held.",
+ usageLimits: limits,
+ },
+ {
+ id: "grok:a-signed-out",
+ driver: grok,
+ email: "a@example.com",
+ displayName: null,
+ status: "signed-out" as const,
+ statusDetail: "Sign-in required.",
+ usageLimits: limits,
+ },
+ ],
+ },
+ ];
+ const generic = collectProviderUsageLimits(native.instanceId, [native], hub, now);
+ expect(generic?.accounts).toHaveLength(1);
+ expect(generic?.accounts[0]).toMatchObject({
+ displayName: "A Person · SuperGrok",
+ status: "signed-out",
+ statusDetail: "Sign-in required.",
+ });
+ const named = collectProviderUsageLimits(emergency.instanceId, [emergency], hub, now);
+ expect(named?.accounts[0]).toMatchObject({
+ displayName: "Grok · Emergency (direct)",
+ status: "signed-out",
+ statusDetail: "Sign-in required.",
+ });
+ const fresherGeneric = provider({
+ ...native,
+ usageLimits: { ...limits, checkedAt: "2026-09-03T11:30:00.000Z" },
+ });
+ const olderEmergency = provider({
+ ...emergency,
+ usageLimits: { ...limits, checkedAt: "2026-09-03T10:00:00.000Z" },
+ });
+ for (const providers of [
+ [fresherGeneric, olderEmergency],
+ [olderEmergency, fresherGeneric],
+ ]) {
+ expect(
+ collectProviderUsageLimits(fresherGeneric.instanceId, providers, hub, now)?.accounts[0],
+ ).toMatchObject({
+ displayName: "Grok · Emergency (direct)",
+ status: "signed-out",
+ statusDetail: "Sign-in required.",
+ limits: { checkedAt: "2026-09-03T11:30:00.000Z" },
+ });
+ }
+ });
+
it("labels hub rows by account id without .json", () => {
const hub = [
{
diff --git a/packages/shared/src/usageLimits.ts b/packages/shared/src/usageLimits.ts
index 7c1d84e498db2..bb5651dd4f9a4 100644
--- a/packages/shared/src/usageLimits.ts
+++ b/packages/shared/src/usageLimits.ts
@@ -14,6 +14,7 @@ import {
type ServerProviderResetCredits,
type ServerProviderUsageLimits,
type ServerProviderUsageWindow,
+ type UsageLimitSourceAccount,
type UsageLimitSourceSnapshot,
type UsageLimitSourceSnapshots,
} from "@t3tools/contracts";
@@ -332,6 +333,8 @@ export interface LimitAccount {
readonly displayName: string | null;
readonly email: string | undefined;
readonly plan: string | undefined;
+ readonly status: UsageLimitSourceAccount["status"] | null;
+ readonly statusDetail: string | null;
readonly accentColor: string | undefined;
readonly environments: ReadonlyArray<{
readonly environmentId: EnvironmentId;
@@ -391,18 +394,39 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
];
const winner = fresher ? next : previous;
const creditSource = creditSources.get(key);
- // A hub e-mail names the account better than the driver's default instance name.
- const hubEmail = [previous, next].some(
- (account) => account.environments.length === 0 && account.email,
- );
- const displayName = previous.displayName ?? next.displayName;
+ const sides = [previous, next];
+ const generic = (name: string | null | undefined) =>
+ !!name && name.toLowerCase() === PROVIDER_DISPLAY_NAMES[previous.driver]?.toLowerCase();
+ // Either row may arrive first. A renamed instance names that route; a
+ // generic "Grok" does not hide a later "Grok · Emergency (direct)". A hub
+ // alias replaces only that generic name, and a null hub name does not hide
+ // a later alias.
+ const chosen = sides.find(
+ (account) =>
+ account.environments.length > 0 && account.displayName && !generic(account.displayName),
+ )?.displayName;
+ const hubNames = sides
+ .filter((account) => account.environments.length === 0)
+ .map((account) => account.displayName?.trim() || null);
+ const hubName = hubNames.find((name) => name) ?? null;
+ const anyHub = hubNames.length > 0;
+ const nativeName =
+ sides.find((account) => account.environments.length > 0)?.displayName ?? null;
+ const displayName = chosen
+ ? chosen
+ : anyHub
+ ? (hubName ?? (generic(nativeName) ? null : nativeName))
+ : nativeName;
+ const statusAccount =
+ sides.find((account) => account.status === "signed-out") ??
+ sides.find((account) => account.status);
+ const status = statusAccount?.status ?? null;
+ const statusDetail = statusAccount?.statusDetail ?? null;
accounts.set(key, {
...previous,
- displayName:
- hubEmail &&
- displayName?.toLowerCase() === PROVIDER_DISPLAY_NAMES[previous.driver]?.toLowerCase()
- ? null
- : displayName,
+ displayName,
+ status,
+ statusDetail,
plan: planSources.get(key)?.plan ?? previous.plan ?? next.plan,
accentColor: previous.accentColor ?? next.accentColor,
environments,
@@ -436,6 +460,8 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
displayName: provider.displayName?.trim() || null,
email: provider.auth.email,
plan: provider.auth.label,
+ status: null,
+ statusDetail: null,
accentColor: provider.accentColor,
environments: [{ environmentId, label }],
sourceLabel: null,
@@ -459,9 +485,12 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
merge(resolved ?? key, {
key,
driver: account.driver,
- displayName: account.email ? null : hubAccountName(account),
+ displayName:
+ account.displayName?.trim() || (account.email ? null : hubAccountName(account)),
email: account.email,
plan: account.plan,
+ status: account.status ?? null,
+ statusDetail: account.statusDetail ?? null,
accentColor: undefined,
environments: [],
sourceLabel,
@@ -533,8 +562,12 @@ export function collectLimitNotices(presentations: LimitPresentations): readonly
}
/** A hub account by its email, else its id without the `provider:` prefix sources add. */
-function sourceAccountName(account: { readonly id: string; readonly email?: string | undefined }) {
- return account.email ?? account.id.replace(/^[\w-]+:/, "");
+function sourceAccountName(account: {
+ readonly id: string;
+ readonly email?: string | undefined;
+ readonly displayName?: string | undefined;
+}) {
+ return account.displayName?.trim() || account.email || account.id.replace(/^[\w-]+:/, "");
}
/** "Payment Required" from a vendor: a lapsed or unpaid subscription, which needs a person. */
@@ -1153,7 +1186,7 @@ export function collectProviderUsageLimits(
type NativeSnapshot = { provider: ServerProvider; limits: ServerProviderUsageLimits };
const nativeByAccount = new Map<
string,
- { usage: NativeSnapshot; credits: NativeSnapshot | null }
+ { usage: NativeSnapshot; credits: NativeSnapshot | null; chosenName: string | null }
>();
for (const provider of providersWithLimits(providers)) {
if (provider.driver !== selected.driver || !provider.usageLimits) continue;
@@ -1174,9 +1207,16 @@ export function collectProviderUsageLimits(
Date.parse(snapshot.limits.checkedAt) > Date.parse(previousCredit.limits.checkedAt))
? snapshot
: (previousCredit ?? null);
+ const trimmedName = provider.displayName?.trim() || null;
+ const chosenName =
+ trimmedName &&
+ trimmedName.toLowerCase() !== PROVIDER_DISPLAY_NAMES[provider.driver]?.toLowerCase()
+ ? trimmedName
+ : null;
nativeByAccount.set(key, {
usage: providerWins ? snapshot : previous.usage,
credits,
+ chosenName: previous?.chosenName ?? chosenName,
});
}
const native = [...nativeByAccount.values()];
@@ -1191,6 +1231,7 @@ export function collectProviderUsageLimits(
for (const {
usage: { provider, limits },
credits,
+ chosenName,
} of native) {
const key = resolveKey(nativeReport(provider));
const hubCredits = sources
@@ -1215,6 +1256,23 @@ export function collectProviderUsageLimits(
const shownCredits = showHubCredits
? hubCredits.account.usageLimits.resetCredits
: credits?.limits.resetCredits;
+ const relatedHubs = sources
+ .flatMap((source) => source.accounts.map((account) => ({ source, account })))
+ .filter(
+ ({ account }) =>
+ key !== null && resolveKey(account) === key && account.driver === provider.driver,
+ );
+ const statusAccount =
+ relatedHubs.find(({ account }) => account.status === "signed-out")?.account ??
+ relatedHubs.find(({ account }) => account.status)?.account;
+ const nativeLabel = chosenName ?? (provider.displayName?.trim() || null);
+ const hubLabel =
+ relatedHubs.map(({ account }) => account.displayName?.trim() || null).find((name) => name) ??
+ null;
+ const generic =
+ !!nativeLabel &&
+ nativeLabel.toLowerCase() === PROVIDER_DISPLAY_NAMES[provider.driver]?.toLowerCase();
+ const displayName = nativeLabel && !generic ? nativeLabel : (hubLabel ?? nativeLabel);
accounts.push({
id: provider.instanceId,
driver: provider.driver,
@@ -1229,7 +1287,9 @@ export function collectProviderUsageLimits(
creditId: hubCreditId,
}
: { instanceId: credits?.provider.instanceId ?? provider.instanceId },
- ...(provider.displayName ? { displayName: provider.displayName } : {}),
+ ...(displayName ? { displayName } : {}),
+ ...(statusAccount?.status ? { status: statusAccount.status } : {}),
+ ...(statusAccount?.statusDetail ? { statusDetail: statusAccount.statusDetail } : {}),
...(provider.accentColor ? { accentColor: provider.accentColor } : {}),
...(provider.auth.email ? { email: provider.auth.email } : {}),
limits: shownCredits ? { ...limits, resetCredits: shownCredits } : limits,
@@ -1240,10 +1300,11 @@ export function collectProviderUsageLimits(
for (const account of matching) {
const key = resolveKey(account);
if (key && nativeAccountKeys.has(key)) continue;
+ const hubName = account.displayName?.trim();
accounts.push({
id: `${source.id}:${account.id}`,
driver: account.driver,
- label: `${source.label} · ${hubAccountName(account)}`,
+ label: hubName || `${source.label} · ${hubAccountName(account)}`,
sourceLabel: "CLI Proxy",
...(account.usageLimits.resetCredits?.nextCreditId
? {
@@ -1255,6 +1316,9 @@ export function collectProviderUsageLimits(
}
: {}),
...(account.plan ? { plan: account.plan } : {}),
+ ...(hubName ? { displayName: hubName } : {}),
+ ...(account.status ? { status: account.status } : {}),
+ ...(account.statusDetail ? { statusDetail: account.statusDetail } : {}),
...(account.email ? { email: account.email } : {}),
limits: account.usageLimits,
});