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
37 changes: 37 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ pub struct ProviderInventoryItemSnapshot {
pub next_expires_at: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProviderDisplayProgressSnapshot {
pub used: f64,
pub total: f64,
}

/// Display-only provider detail row. It never participates in quota math or
/// core persistence and contains values validated by the provider carrier.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProviderDisplayDetailSnapshot {
pub id: String,
pub title: String,
pub value: String,
pub secondary_value: Option<String>,
pub progress: Option<ProviderDisplayProgressSnapshot>,
}

/// A frontend-friendly snapshot of one provider's usage data.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -213,6 +232,8 @@ pub struct ProviderUsageSnapshot {
pub extra_rate_windows: Vec<NamedRateWindowSnapshot>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub inventory: Vec<ProviderInventoryItemSnapshot>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub display_details: Vec<ProviderDisplayDetailSnapshot>,
#[serde(default)]
pub cost: Option<CostSnapshotBridge>,
#[serde(default)]
Expand Down Expand Up @@ -407,6 +428,21 @@ impl ProviderUsageSnapshot {
next_expires_at: item.next_expires_at.map(|date| date.to_rfc3339()),
})
.collect(),
display_details: result
.display_details()
.map(|detail| ProviderDisplayDetailSnapshot {
id: detail.id().to_string(),
title: detail.title().to_string(),
value: detail.value().to_string(),
secondary_value: detail.secondary_value().map(ToOwned::to_owned),
progress: detail
.progress()
.map(|progress| ProviderDisplayProgressSnapshot {
used: progress.used(),
total: progress.total(),
}),
})
.collect(),
cost: result.cost.as_ref().map(|c| CostSnapshotBridge {
used: c.used,
limit: c.limit,
Expand Down Expand Up @@ -485,6 +521,7 @@ impl ProviderUsageSnapshot {
tertiary_label: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: None,
plan_name: None,
account_email: None,
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/provider_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct ProviderDetail {
pub tertiary: Option<RateWindowSnapshot>,
pub extra_rate_windows: Vec<NamedRateWindowSnapshot>,
pub inventory: Vec<ProviderInventoryItemSnapshot>,
pub display_details: Vec<ProviderDisplayDetailSnapshot>,

// Cost / pace.
pub cost: Option<CostSnapshotBridge>,
Expand Down Expand Up @@ -93,6 +94,7 @@ pub(crate) fn build_provider_detail(provider_id: &str) -> Result<ProviderDetail,
tertiary: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: None,
pace: None,
last_error: None,
Expand Down Expand Up @@ -157,6 +159,7 @@ pub fn get_provider_detail(
detail.tertiary = snapshot.tertiary.clone();
detail.extra_rate_windows = snapshot.extra_rate_windows.clone();
detail.inventory = snapshot.inventory.clone();
detail.display_details = snapshot.display_details.clone();
detail.cost = snapshot.cost.clone();
detail.pace = snapshot.pace.clone();
}
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/commands/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ mod reset_backfill_tests {
tertiary_label: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: None,
plan_name: None,
account_email: None,
Expand Down
29 changes: 26 additions & 3 deletions apps/desktop-tauri/src-tauri/src/commands/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::state::AppState;
use crate::surface::SurfaceMode;
use crate::surface_target::SurfaceTarget;
use codexbar::core::{
FetchContext, ProviderAccountData, ProviderError, ProviderFetchResult, ProviderId,
ProviderInventoryItem, SourceMode, TokenAccount, instantiate_provider,
FetchContext, ProviderAccountData, ProviderDisplayDetail, ProviderError, ProviderFetchResult,
ProviderId, ProviderInventoryItem, SourceMode, TokenAccount, instantiate_provider,
};
use codexbar::host::session::launch_block_reason;
use codexbar::settings::{ApiKeys, Language, ManualCookies, Settings};
Expand Down Expand Up @@ -993,7 +993,12 @@ fn provider_inventory_maps_to_the_bridge_without_token_ids() {
title: "Limit Reset Credits".to_string(),
available_count: 2,
next_expires_at: Some(expiry),
});
})
.with_display_detail(
ProviderDisplayDetail::new("credits", "Used this cycle", "12")
.with_secondary_value("Monthly refill: 100")
.with_progress(12.0, 100.0),
);
let metadata = instantiate_provider(ProviderId::Grok).metadata().clone();
let snapshot =
ProviderUsageSnapshot::from_fetch_result(ProviderId::Grok, &metadata, &result, None);
Expand All @@ -1004,6 +1009,12 @@ fn provider_inventory_maps_to_the_bridge_without_token_ids() {
snapshot.inventory[0].next_expires_at.as_deref(),
Some("2030-03-17T17:46:40+00:00")
);
assert_eq!(snapshot.display_details.len(), 1);
assert_eq!(snapshot.display_details[0].value, "12");
assert_eq!(
snapshot.display_details[0].secondary_value.as_deref(),
Some("Monthly refill: 100")
);
let serialized = serde_json::to_string(&snapshot).unwrap();
assert!(serialized.contains("reset-credits"));
assert!(!serialized.contains("coupon-token-secret"));
Expand Down Expand Up @@ -1086,6 +1097,7 @@ fn provider_cache_upsert_replaces_existing_provider() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "CLI".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1113,6 +1125,7 @@ fn provider_cache_prunes_disabled_providers() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "CLI".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1147,6 +1160,7 @@ fn hiding_codex_spark_rows_preserves_other_extra_usage() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "CLI".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1181,6 +1195,7 @@ fn claude_transient_auth_failure_preserves_first_last_good_snapshot() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1217,6 +1232,7 @@ fn codex_transient_transport_failure_helper_uses_typed_policy() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1252,6 +1268,7 @@ fn claude_repeated_auth_failure_surfaces_error() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1294,6 +1311,7 @@ fn claude_cloudflare_challenge_retains_prior_usage_while_surfaceing_guidance() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1347,6 +1365,7 @@ fn claude_cloudflare_challenge_keeps_prior_usage_when_guidance_surfaces() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "Web".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1397,6 +1416,7 @@ fn claude_cli_parse_failure_keeps_last_good_every_time() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "CLI".to_string(),
has_successful_claude_cli_quota: true,
pace_authoritative: true,
Expand Down Expand Up @@ -1443,6 +1463,7 @@ fn claude_hard_credentials_missing_does_not_preserve_stale() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1614,6 +1635,7 @@ fn japanese_provider_snapshot_localizes_weekly_label() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down Expand Up @@ -1647,6 +1669,7 @@ fn japanese_provider_snapshot_localizes_pace_reserve_description() {
cost: None,
wayfinder_usage: None,
inventory: Vec::new(),
display_details: Vec::new(),
source_label: "OAuth".to_string(),
has_successful_claude_cli_quota: false,
pace_authoritative: true,
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop-tauri/src-tauri/src/powertoys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ mod tests {
tertiary_label: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: None,
plan_name: Some("Team".to_string()),
account_email: Some("dev@example.com".to_string()),
Expand Down Expand Up @@ -245,6 +246,7 @@ mod tests {
tertiary_label: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: None,
plan_name: None,
account_email: None,
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/tray_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ mod tests {
tertiary_label: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: cost.map(|(used, limit)| crate::commands::CostSnapshotBridge {
used,
limit: Some(limit),
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/usage_metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ mod tests {
tertiary_label: None,
extra_rate_windows: Vec::new(),
inventory: Vec::new(),
display_details: Vec::new(),
cost: None,
plan_name: None,
account_email: None,
Expand Down
37 changes: 37 additions & 0 deletions apps/desktop-tauri/src/components/MenuCardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from "react";
import type {
CostSummaryDisplayStyle,
DailyCostPoint,
ProviderDisplayDetail,
PaceSnapshot,
ProviderInventoryItem,
ProviderChartData,
Expand Down Expand Up @@ -415,6 +416,7 @@ function MetricRow({
export interface MenuCardPresence {
hasMetrics: boolean;
hasInventory: boolean;
hasDisplayDetails: boolean;
hasCost: boolean;
hasPace: boolean;
hasCharts: boolean;
Expand Down Expand Up @@ -459,6 +461,7 @@ export function describeCard(
const wayfinderUsage = isWayfinder ? provider.wayfinderUsage : null;
const hasMetrics = visibleMetrics.length > 0;
const hasInventory = !provider.error && (provider.inventory?.length ?? 0) > 0;
const hasDisplayDetails = !provider.error && (provider.displayDetails?.length ?? 0) > 0;
const hasCost =
!!provider.cost &&
(costSummaryDisplayStyle !== "hidden" || provider.cost.alwaysVisible === true);
Expand All @@ -470,6 +473,7 @@ export function describeCard(
!provider.error &&
(hasMetrics ||
hasInventory ||
hasDisplayDetails ||
hasCost ||
hasPace ||
hasCharts ||
Expand All @@ -478,6 +482,7 @@ export function describeCard(
return {
hasMetrics,
hasInventory,
hasDisplayDetails,
hasCost,
hasPace,
hasCharts,
Expand Down Expand Up @@ -516,6 +521,7 @@ export default function MenuCardDetails({
const {
hasMetrics,
hasInventory,
hasDisplayDetails,
hasCost,
hasPace,
hasCharts,
Expand Down Expand Up @@ -563,6 +569,14 @@ export default function MenuCardDetails({
</section>
)}

{!provider.error && hasDisplayDetails && (
<section className="menu-card__group menu-card__provider-details">
{provider.displayDetails?.map((detail, index) => (
<DisplayDetailRow key={`${detail.id}-${index}`} detail={detail} />
))}
</section>
)}

{wayfinderUsage && <WayfinderUsageBlock usage={wayfinderUsage} />}

{hasMetrics && hasCost && <div className="menu-card__divider" />}
Expand Down Expand Up @@ -761,3 +775,26 @@ function InventoryItemRow({
</div>
);
}

function DisplayDetailRow({ detail }: { detail: ProviderDisplayDetail }) {
const progress = detail.progress;
const progressPercent = progress && Number.isFinite(progress.used) && Number.isFinite(progress.total) && progress.total > 0
? Math.max(0, Math.min(100, (progress.used / progress.total) * 100))
: null;

return (
<div className="menu-card__provider-detail">
<div className="menu-card__cost-line">
<span>{detail.title}: {detail.value}</span>
{detail.secondaryValue && (
<span className="menu-card__cost-line--muted">{detail.secondaryValue}</span>
)}
</div>
{progressPercent != null && (
<div className="menu-metric__bar" aria-label={`${detail.title} progress`}>
<div className="menu-metric__bar-fill" style={{ width: `${progressPercent}%` }} />
</div>
)}
</div>
);
}
Loading