Skip to content
Open
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
21 changes: 13 additions & 8 deletions apps/mobile/src/features/threads/ComposerUsageLimits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export function ComposerUsageLimits({
account.resetCreditInput ??
(account.instanceId ? { instanceId: account.instanceId } : undefined);
const driverLabel = providerClients.get(account.driver)?.label ?? account.driver;
const statusSuffix =
account.status === "held"
? " · Held"
: account.status === "signed-out"
? " · Sign in"
: "";
const instanceLabel = account.instanceId
? account.displayName?.trim() ||
(String(account.instanceId) !== String(account.driver)
? account.instanceId
: driverLabel)
: account.label;
return (
<AccountLimits
key={account.id}
Expand All @@ -45,14 +57,7 @@ export function ComposerUsageLimits({
driver={account.driver}
accentColor={account.accentColor}
label={driverLabel}
instanceLabel={
account.instanceId
? account.displayName?.trim() ||
(String(account.instanceId) !== String(account.driver)
? account.instanceId
: driverLabel)
: account.label
}
instanceLabel={`${instanceLabel}${statusSuffix}`}
detail={account.plan}
limits={account.limits}
now={now}
Expand Down
22 changes: 16 additions & 6 deletions apps/mobile/src/features/usage/UsageLimitsPooled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ import { ProviderIcon } from "../../components/ProviderIcon";
import { SettingsScreen } from "../settings/components/SettingsScreen";
import { environmentPresentations } from "../../state/presentation";
import { ResetCredits } from "./UsageLimitsSection";
import { pooledSegmentCaption } from "./pooledSegmentCaption";
import { usageProviderKind, useProviderColors } from "./usageProviders";

const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace" } as const;

function accountName(account: LimitAccount) {
if (account.displayName) return account.displayName;
if (!account.email) return providerClients.get(account.driver)?.label ?? account.driver;
return emailInitials(account.email) || "Account";
const name = account.displayName
? account.displayName
: account.email
? emailInitials(account.email) || "Account"
: (providerClients.get(account.driver)?.label ?? account.driver);
if (account.status === "held") return `${name} · Held`;
if (account.status === "signed-out") return `${name} · Sign in`;
return name;
}

function emailInitials(email: string) {
Expand Down Expand Up @@ -235,6 +241,7 @@ function PoolWindowCard({
/>
);
const { account, window } = member;
const segmentCaption = pooledSegmentCaption(account, accountName(account), inlineName);
const timeLeft = paceRemainingPercent(window, now);
const credits = account.limits.resetCredits?.availableCount ?? 0;
const resetsIn = formatResetsIn(window, now)?.replace("resets in ", "");
Expand Down Expand Up @@ -264,14 +271,14 @@ function PoolWindowCard({
>
<View className="min-w-0 shrink flex-row items-center gap-1.5">
{account.email ? <AccountChip email={account.email} /> : null}
{account.email && !(account.displayName && inlineName) ? null : (
{segmentCaption ? (
<Text
numberOfLines={1}
className="min-w-0 shrink text-xs font-t3-medium text-foreground"
>
{accountName(account)}
{segmentCaption}
</Text>
)}
) : null}
<Text className="text-sm font-t3-bold tabular-nums text-foreground">
{remainingPercent(window)}%
</Text>
Expand Down Expand Up @@ -590,6 +597,9 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
{account.plan}
</Text>
) : null}
{account.statusDetail ? (
<Text className="text-sm text-foreground-muted">{account.statusDetail}</Text>
) : null}
</View>
<View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
<Text className="text-sm font-t3-medium text-foreground">{window.label}</Text>
Expand Down
32 changes: 32 additions & 0 deletions apps/mobile/src/features/usage/pooledSegmentCaption.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, expect, it } from "@effect/vitest";

import { pooledSegmentCaption } from "./pooledSegmentCaption";

describe("pooledSegmentCaption", () => {
const held = {
email: "a@example.com",
displayName: null,
status: "held" as const,
};

it("keeps Held on a wide bar when the emailed name is hidden", () => {
expect(pooledSegmentCaption(held, "AE · Held", false)).toBe("Held");
expect(pooledSegmentCaption({ ...held, status: "signed-out" }, "AE · Sign in", false)).toBe(
"Sign in",
);
});

it("leaves an unnamed emailed seat as the chip", () => {
expect(pooledSegmentCaption({ ...held, status: null }, "AE", false)).toBeNull();
});

it("shows the full name once the segment is wide enough", () => {
expect(
pooledSegmentCaption(
{ ...held, displayName: "A Person · SuperGrok" },
"A Person · SuperGrok · Held",
true,
),
).toBe("A Person · SuperGrok · Held");
});
});
16 changes: 16 additions & 0 deletions apps/mobile/src/features/usage/pooledSegmentCaption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** What a wide pooled segment may print beside its chip. */
export function pooledSegmentCaption(
account: {
readonly email: string | undefined;
readonly displayName: string | null;
readonly status: "held" | "signed-out" | null;
},
fullName: string,
showFullName: boolean,
): string | null {
const showName = !account.email || (!!account.displayName && showFullName);
if (showName) return fullName;
if (account.status === "held") return "Held";
if (account.status === "signed-out") return "Sign in";
return null;
}
164 changes: 164 additions & 0 deletions apps/server/src/usage/magpieQuotas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ describe("magpieQuotasToAccounts", () => {
"magpie-go:oc-billed",
"magpie-go:oc-other",
"claude:second@example.com",
"grok:jeffrey.smith@closura.ai",
"grok:kameron.smith@closura.ai",
]);
const team = accounts[2]!;
const billed = accounts[3]!;
Expand Down Expand Up @@ -173,6 +175,129 @@ describe("magpieQuotasToAccounts", () => {
"weekly",
"monthly",
]);
// Both seats share the product name "Grok" and neither has an alias.
expect(grok.map((account) => account.displayName)).toEqual(["Jeffrey Smith", "Kameron Smith"]);
});

it("prefers an alias, splits a shared product name, and keeps held and lapsed seats", () => {
const labeled = magpieQuotasToAccounts(
[
{
provider: "claude",
name: "Claude Code",
plan: "max",
user: "a@example.com",
alias: "Kameron · Claude work",
windows: [{ name: "5 hours", used: 0 }],
},
{
provider: "claude",
name: "Claude Code",
plan: "max",
user: "bee.person@example.com",
alias: null,
windows: [{ name: "5 hours", used: 10 }],
},
{
provider: "grok",
name: "Grok (SuperGrok)",
user: "jeffrey.smith@example.com",
alias: null,
windows: [{ name: "7 days", used: 65 }],
},
{
provider: "grok",
name: "Grok (SuperGrok)",
user: "kameron.smith@example.com",
windows: [{ name: "7 days", used: 7 }],
},
{
provider: "codex",
name: "Codex",
plan: "pro",
user: "a@example.com",
held: true,
until: "2026-12-02T00:00:00Z",
windows: [{ name: "7 days", used: 100 }],
},
{
provider: "claude",
user: "old@example.com",
lapsed: "Claude Code is no longer signed in",
windows: [{ name: "7 days", used: 100 }],
},
],
checkedAt,
);
expect(labeled.find((account) => account.email === "a@example.com")?.displayName).toBe(
"Kameron · Claude work",
);
// The second Claude seat shares the product name and has no alias.
expect(labeled.find((account) => account.email === "bee.person@example.com")?.displayName).toBe(
"Bee Person",
);
expect(
labeled.filter((account) => account.driver === "grok").map((account) => account.displayName),
).toEqual(["Jeffrey Smith · SuperGrok", "Kameron Smith · SuperGrok"]);
const held = labeled.find((account) => account.driver === "codex");
expect(held?.status).toBe("held");
expect(held?.statusDetail).toBe("Held until 2026-12-02.");
const lapsed = labeled.find((account) => account.email === "old@example.com");
expect(lapsed?.status).toBe("signed-out");
expect(lapsed?.statusDetail).toBe("Claude Code is no longer signed in.");
expect(lapsed?.usageLimits.windows).toHaveLength(1);
});

it("leaves one emailed seat unnamed, including a duplicate row, and keeps a colliding alias", () => {
const lone = magpieQuotasToAccounts(
[
{
provider: "grok",
name: "Grok (SuperGrok)",
user: "only@example.com",
alias: null,
held: null,
lapsed: null,
windows: [{ name: "7 days", used: 10 }],
},
{
provider: "grok",
name: "Grok (SuperGrok)",
user: "only@example.com",
windows: [{ name: "7 days", used: 12 }],
},
{
provider: "claude",
name: "Claude Code",
user: "a@example.com",
alias: "Bee Person",
windows: [{ name: "5 hours", used: 1 }],
},
{
provider: "claude",
name: "Claude Code",
user: "bee.person@example.com",
alias: null,
windows: [{ name: "5 hours", used: 2 }],
},
{
provider: "claude",
name: "Claude Code",
user: "c@example.com",
windows: [{ name: "5 hours", used: 3 }],
},
],
checkedAt,
);
const grok = lone.filter((account) => account.driver === "grok");
expect(grok.map((account) => account.email)).toEqual(["only@example.com"]);
expect(grok[0]?.displayName).toBeUndefined();
expect(lone.find((account) => account.email === "a@example.com")?.displayName).toBe(
"Bee Person",
);
expect(lone.find((account) => account.email === "bee.person@example.com")?.displayName).toBe(
"Bee Person · example",
);
});
});

Expand Down Expand Up @@ -327,6 +452,45 @@ describe("makeMagpieApi", () => {
}),
);

it.effect("accepts null alias, held, and lapsed on a quota row", () =>
Effect.gen(function* () {
const http = HttpClient.make((request) =>
Effect.sync(() =>
HttpClientResponse.fromWeb(
request,
Response.json({
object: "list",
data: [
{
provider: "grok",
name: "Grok (SuperGrok)",
user: "only@example.com",
alias: null,
held: null,
until: null,
lapsed: null,
windows: [{ name: "7 days", used: 4, resetsAt: null }],
},
],
}),
),
),
);
const result = yield* makeMagpieApi.pipe(
Effect.flatMap((api) =>
api.readAccounts({ url: "http://127.0.0.1:3425", managementKey: "" }),
),
Effect.result,
Effect.provideService(HttpClient.HttpClient, http),
);
expect(result._tag).toBe("Success");
if (result._tag !== "Success") return;
expect(result.success.map((account) => account.id)).toEqual(["grok:only@example.com"]);
expect(result.success[0]?.displayName).toBeUndefined();
expect(result.success[0]?.status).toBeUndefined();
}),
);

it.effect("sends a configured gateway key and explains a refusal", () =>
Effect.gen(function* () {
const { result, seen } = yield* run("gateway-key", 401);
Expand Down
Loading
Loading