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
11 changes: 10 additions & 1 deletion apps/desktop-tauri/src-tauri/src/commands/provider_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub struct ProviderDetail {
// Usage windows — reuse existing RateWindowSnapshot shape.
pub session: Option<RateWindowSnapshot>,
pub weekly: Option<RateWindowSnapshot>,
/// Provider-declared label for the session (primary) lane; None when the
/// provider uses the generic "Session" wording.
pub primary_label: Option<String>,
/// Provider-declared label for the weekly (secondary) lane; None when the
/// provider uses the generic "Weekly" wording.
pub secondary_label: Option<String>,
pub model_specific: Option<RateWindowSnapshot>,
pub tertiary: Option<RateWindowSnapshot>,
/// Locale key naming the tertiary lane when it carries a semantic label
Expand Down Expand Up @@ -97,6 +103,8 @@ pub(crate) fn build_provider_detail(
last_updated: None,
session: None,
weekly: None,
primary_label: None,
secondary_label: None,
model_specific: None,
tertiary: None,
tertiary_label_key: metadata.tertiary_label_key,
Expand Down Expand Up @@ -165,7 +173,8 @@ pub fn get_provider_detail(
super::usage_item_descriptors(Some(&snapshot), &settings, parsed_provider_id);
detail.session = Some(snapshot.primary.clone());
detail.weekly = snapshot.secondary.clone();
detail.model_specific = snapshot.model_specific.clone();
detail.primary_label = snapshot.primary_label.clone();
detail.secondary_label = snapshot.secondary_label.clone();
detail.tertiary = snapshot.tertiary.clone();
detail.extra_rate_windows = snapshot.extra_rate_windows.clone();
detail.inventory = snapshot.inventory.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,47 @@ describe("MenuBarMetricSection", () => {
providerMetrics: { copilot: "extraUsage" },
});
});

it("offers the provider-declared lane labels in the metric picker", () => {
const base = provider(false);
base.id = "litellm";
base.displayName = "LiteLLM";
base.weekly = rateWindow(30);
base.primaryLabel = "Personal budget";
base.secondaryLabel = "Team budget";

render(
<MenuBarMetricSection
provider={base}
providerMetrics={{}}
disabled={false}
t={(key) => key}
onChange={vi.fn()}
/>,
);

expect(screen.getByRole("option", { name: "Personal budget" })).toBeInTheDocument();
expect(screen.getByRole("option", { name: "Team budget" })).toBeInTheDocument();
expect(screen.queryByRole("option", { name: "ProviderSessionLabel" })).not.toBeInTheDocument();
expect(screen.queryByRole("option", { name: "ProviderWeeklyLabel" })).not.toBeInTheDocument();
});

it("keeps the generic metric labels when the provider declares none", () => {
const base = provider(false);
base.weekly = rateWindow(30);

render(
<MenuBarMetricSection
provider={base}
providerMetrics={{}}
disabled={false}
t={(key) => key}
onChange={vi.fn()}
/>,
);

expect(screen.getByRole("option", { name: "Automatic" })).toBeInTheDocument();
expect(screen.getByRole("option", { name: "ProviderSessionLabel" })).toBeInTheDocument();
expect(screen.getByRole("option", { name: "ProviderWeeklyLabel" })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ function metricOptions(
): MetricOption[] {
const options: MetricOption[] = [
{ value: "automatic", label: t("Automatic") },
{ value: "session", label: t("ProviderSessionLabel") },
{ value: "session", label: provider.primaryLabel || t("ProviderSessionLabel") },
];

if (provider.weekly) {
options.push({ value: "weekly", label: t("ProviderWeeklyLabel") });
options.push({ value: "weekly", label: provider.secondaryLabel || t("ProviderWeeklyLabel") });
}
if (provider.modelSpecific) {
options.push({ value: "model", label: t("DetailWindowModelSpecific") });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,36 @@ describe("UsageSection", () => {
expect(await screen.findByText(/Limit Reset Credits: 2 available/)).toBeInTheDocument();
expect(container.querySelector(".provider-usage-bar__track")).toBeNull();
});

it("shows provider-declared lane labels in settings bars", async () => {
const detail = provider();
detail.weekly = rateWindow(30);
detail.primaryLabel = "Personal budget";
detail.secondaryLabel = "Team budget";

render(
<LocaleProvider>
<UsageSection provider={detail} resetTimeRelative={true} t={(key) => key} />
</LocaleProvider>,
);

expect(await screen.findByText("Personal budget")).toBeInTheDocument();
expect(screen.getByText("Team budget")).toBeInTheDocument();
expect(screen.queryByText("ProviderSessionLabel")).not.toBeInTheDocument();
expect(screen.queryByText("ProviderWeeklyLabel")).not.toBeInTheDocument();
});

it("keeps the generic labels when the provider declares none", async () => {
const detail = provider();
detail.weekly = rateWindow(30);

render(
<LocaleProvider>
<UsageSection provider={detail} resetTimeRelative={true} t={(key) => key} />
</LocaleProvider>,
);

expect(await screen.findByText("ProviderSessionLabel")).toBeInTheDocument();
expect(screen.getByText("ProviderWeeklyLabel")).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export function UsageSection({ provider, resetTimeRelative, t }: Props) {
if (provider.session && isUsageItemVisible(provider.hiddenUsageItemIds, "primary")) {
bars.push({
key: "session",
label: t("ProviderSessionLabel"),
label: provider.primaryLabel || t("ProviderSessionLabel"),
rate: provider.session,
});
}
if (provider.weekly && isUsageItemVisible(provider.hiddenUsageItemIds, "secondary")) {
bars.push({
key: "weekly",
label: t("ProviderWeeklyLabel"),
label: provider.secondaryLabel || t("ProviderWeeklyLabel"),
rate: provider.weekly,
});
}
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop-tauri/src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ export interface ProviderDetail {
// Usage windows — mirror RateWindowSnapshot.
session: RateWindowSnapshot | null;
weekly: RateWindowSnapshot | null;
/** Provider-declared label for the session (primary) lane, e.g. "Personal budget". */
primaryLabel?: string | null;
/** Provider-declared label for the weekly (secondary) lane, e.g. "Team budget". */
secondaryLabel?: string | null;
modelSpecific: RateWindowSnapshot | null;
tertiary: RateWindowSnapshot | null;
/** Locale key for the tertiary metric lane when it carries a semantic label (upstream F5). */
Expand Down