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
13 changes: 4 additions & 9 deletions apps/desktop-tauri/src-tauri/src/commands/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ pub struct CostSnapshotBridge {
pub formatted_balance: Option<String>,
#[serde(default)]
pub daily: Vec<CostDailyPointBridge>,
#[serde(default)]
pub always_visible: bool,
}

fn default_currency() -> String {
Expand Down Expand Up @@ -335,12 +333,10 @@ impl ProviderUsageSnapshot {
.unwrap_or_else(|| metadata.session_label.to_string()),
),
secondary: secondary_snap,
secondary_label: usage.secondary.as_ref().map(|_| {
usage
.secondary_label
.clone()
.unwrap_or_else(|| metadata.weekly_label.to_string())
}),
secondary_label: usage
.secondary
.as_ref()
.map(|_| metadata.weekly_label.to_string()),
model_specific: usage
.model_specific
.as_ref()
Expand Down Expand Up @@ -389,7 +385,6 @@ impl ProviderUsageSnapshot {
amount: point.amount,
})
.collect(),
always_visible: c.always_visible,
}),
plan_name: usage.login_method.clone(),
account_email: usage.account_email.clone(),
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop-tauri/src-tauri/src/commands/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const LOCAL_USAGE_TTL: Duration = Duration::from_secs(30);
#[serde(rename_all = "camelCase")]
pub struct DailyCostPoint {
pub date: String,
pub value: Option<f64>,
pub value: f64,
}

/// A single (date, tokens) point for the Tokens chart mode (upstream 0.50.0
Expand Down Expand Up @@ -494,7 +494,7 @@ fn load_openai_dashboard_chart_data(
.iter()
.map(|d| DailyCostPoint {
date: d.day.clone(),
value: Some(d.total_credits_used),
value: d.total_credits_used,
})
.collect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ fn cookie_source_provider(provider_id: &str) -> Option<codexbar::core::ProviderI
"opencode" => ProviderId::OpenCode,
"factory" => ProviderId::Factory,
"alibaba" => ProviderId::Alibaba,
"alibabatokenplan" => ProviderId::AlibabaTokenPlan,
"kimi" | "kimik2" => ProviderId::Kimi,
"minimax" => ProviderId::MiniMax,
"augment" => ProviderId::Augment,
Expand Down Expand Up @@ -548,7 +547,7 @@ pub fn cookie_source_options_for(provider_id: &str, lang: Language) -> Vec<Cooki
None,
),
],
"alibaba" | "alibabatokenplan" => vec![
"alibaba" => vec![
cookie_option(
lang,
"auto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub async fn get_spend_contract(
history_days,
include_import,
settings.hide_native_codex_cost_when_open_codex_present && provider == "codex",
settings.hide_personal_info,
summary,
)
})
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop-tauri/src-tauri/src/commands/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,16 +1117,16 @@ fn chart_data_serde_roundtrip_preserves_fields() {
cost_history: vec![
DailyCostPoint {
date: "2025-01-01".into(),
value: Some(1.25),
value: 1.25,
},
DailyCostPoint {
date: "2025-01-02".into(),
value: Some(0.0),
value: 0.0,
},
],
credits_history: vec![DailyCostPoint {
date: "2025-01-01".into(),
value: Some(42.0),
value: 42.0,
}],
usage_breakdown: vec![DailyUsageBreakdown {
day: "2025-01-01".into(),
Expand Down Expand Up @@ -1169,7 +1169,7 @@ fn chart_data_serde_roundtrip_preserves_fields() {
assert_eq!(back.provider_id, "codex");
assert_eq!(back.cost_history.len(), 2);
assert_eq!(back.cost_history[0].date, "2025-01-01");
assert_eq!(back.credits_history[0].value, Some(42.0));
assert_eq!(back.credits_history[0].value, 42.0);
assert_eq!(back.usage_breakdown[0].services.len(), 2);
assert_eq!(back.usage_breakdown[0].total_credits_used, 13.5);
assert_eq!(back.tokens_history[0].tokens, 123_456);
Expand Down
84 changes: 24 additions & 60 deletions apps/desktop-tauri/src-tauri/src/commands/usage_spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ fn build_usage_spend_summary_cached(
selected_days: u32,
force_refresh: bool,
) -> Result<UsageSpendSummary, String> {
let settings = codexbar::settings::Settings::load();
let key = usage_spend_cache_key(cached, selected_days, &settings);
let key = usage_spend_cache_key(cached, selected_days);
let mut guard = usage_spend_summary_cache()
.lock()
.map_err(|error| error.to_string())?;
Expand All @@ -126,35 +125,16 @@ fn build_usage_spend_summary_cached(
}
// Hold the cache mutex while building: callers for the same app revision
// coalesce behind this single scan instead of starting parallel rescans.
let summary = build_usage_spend_summary(cached, selected_days, &settings);
let summary = build_usage_spend_summary(cached, selected_days);
*guard = Some(CachedUsageSpendSummary {
key,
summary: summary.clone(),
});
Ok(summary)
}

fn usage_spend_cache_key(
cached: &[ProviderUsageSnapshot],
selected_days: u32,
settings: &codexbar::settings::Settings,
) -> String {
usage_spend_cache_key_with_privacy(
cached,
selected_days,
settings.open_codex_usage_logs_enabled,
settings.hide_native_codex_cost_when_open_codex_present,
settings.hide_personal_info,
)
}

fn usage_spend_cache_key_with_privacy(
cached: &[ProviderUsageSnapshot],
selected_days: u32,
include_opencodex: bool,
hide_native: bool,
hide_personal_info: bool,
) -> String {
fn usage_spend_cache_key(cached: &[ProviderUsageSnapshot], selected_days: u32) -> String {
let settings = codexbar::settings::Settings::load();
let mut revisions: Vec<String> = cached
.iter()
.map(|snapshot| {
Expand Down Expand Up @@ -182,24 +162,35 @@ fn usage_spend_cache_key_with_privacy(
.collect();
revisions.sort();
format!(
"{}|{}|{}|{}|{}|{}",
"{}|{}|{}|{}|{}",
chrono::Local::now().date_naive(),
selected_days,
include_opencodex,
hide_native,
hide_personal_info,
settings.open_codex_usage_logs_enabled,
settings.hide_native_codex_cost_when_open_codex_present,
revisions.join(";")
)
}

fn build_usage_spend_summary(
cached: &[ProviderUsageSnapshot],
selected_days: u32,
settings: &codexbar::settings::Settings,
) -> UsageSpendSummary {
let settings = codexbar::settings::Settings::load();
let include_opencodex = settings.open_codex_usage_logs_enabled;
let hide_native = settings.hide_native_codex_cost_when_open_codex_present;

let codex_cache =
codexbar::core::JsonlScanner::load_cache(codexbar::core::ProviderId::Codex, None);
let codex_stale = !codex_cache.days.is_empty() && codex_cache.previous_report.is_some();
let codex_stale_updated_at = codex_stale
.then(|| {
codex_cache
.previous_report
.as_ref()
.and_then(|r| r.updated_at.clone())
})
.flatten();

// Upstream 0.55.0 #3105: independent provider baselines load in parallel.
// Keep each provider's 7d/30d scans serial so they can safely share that
// provider's incremental cache, while Codex and Claude run concurrently.
Expand All @@ -223,29 +214,18 @@ fn build_usage_spend_summary(
)
});

let codex_stale = !codex_30_summary.history_coverage_established;
let codex_stale_updated_at = codex_stale
.then(|| {
codexbar::core::JsonlScanner::load_cache_status(codexbar::core::ProviderId::Codex, None)
.previous_report
.and_then(|report| report.updated_at)
})
.flatten();

let codex_7_contract = build_local_spend_contract_from_summary(
"codex",
7,
include_opencodex,
hide_native,
settings.hide_personal_info,
codex_7_summary.clone(),
);
let codex_30_contract = build_local_spend_contract_from_summary(
"codex",
30,
include_opencodex,
hide_native,
settings.hide_personal_info,
codex_30_summary.clone(),
);

Expand Down Expand Up @@ -371,16 +351,13 @@ fn build_usage_spend_summary(
spend
}
"antigravity" => {
use codexbar::providers::antigravity::local_sessions::LocalHistoryCoverage;
let seven = codexbar::providers::antigravity::local_sessions::summarize(7);
let thirty = codexbar::providers::antigravity::local_sessions::summarize(30);
let mut spend = cached_spend(cached_snapshot);
spend.seven_day_tokens = matches!(seven.coverage, LocalHistoryCoverage::Complete)
.then_some(seven.total_tokens);
spend.thirty_day_tokens = matches!(thirty.coverage, LocalHistoryCoverage::Complete)
.then_some(thirty.total_tokens);
if matches!(thirty.coverage, LocalHistoryCoverage::Complete) {
spend.source = "local Antigravity history".to_string();
spend.seven_day_tokens = (seven.session_count > 0).then_some(seven.total_tokens);
spend.thirty_day_tokens = (thirty.session_count > 0).then_some(thirty.total_tokens);
if thirty.session_count > 0 {
spend.source = "local Antigravity sessions".to_string();
}
spend
}
Expand Down Expand Up @@ -435,7 +412,6 @@ fn build_usage_spend_summary(
history_days,
include_opencodex,
hide_native,
settings.hide_personal_info,
selected_summary,
);
UsageSpendSummary { rows, contract }
Expand Down Expand Up @@ -528,15 +504,3 @@ fn cached_spend(snapshot: Option<&ProviderUsageSnapshot>) -> SpendValues {
stale_updated_at: None,
}
}

#[cfg(test)]
mod cache_key_tests {
use super::*;

#[test]
fn privacy_mode_is_part_of_usage_spend_cache_identity() {
let public = usage_spend_cache_key_with_privacy(&[], 30, false, false, false);
let private = usage_spend_cache_key_with_privacy(&[], 30, false, false, true);
assert_ne!(public, private);
}
}
1 change: 0 additions & 1 deletion apps/desktop-tauri/src-tauri/src/tray_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ mod tests {
balance: None,
formatted_balance: None,
daily: Vec::new(),
always_visible: false,
}),
plan_name: None,
account_email: None,
Expand Down
28 changes: 0 additions & 28 deletions apps/desktop-tauri/src/components/MenuCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function renderCard(
showResetWhenExhausted?: boolean;
showPace?: boolean;
onLayoutChange?: () => void;
costSummaryDisplayStyle?: "compact" | "detailed" | "hidden";
} = {},
) {
return render(
Expand All @@ -99,7 +98,6 @@ function renderCard(
showAsUsed: opts.showAsUsed,
showResetWhenExhausted: opts.showResetWhenExhausted,
showPace: opts.showPace,
costSummaryDisplayStyle: opts.costSummaryDisplayStyle,
}}
onLayoutChange={opts.onLayoutChange}
/>
Expand All @@ -113,7 +111,6 @@ describe("MenuCard", () => {
tauriMocks.getLocaleStrings.mockResolvedValue(
buildBundle({
ActionCopyError: "Copy error",
ApiSpendTitle: "API spend",
DetailPaceRunsOutIn: "Runs out in",
PanelEstimatedFromLocalLogs: "Estimated from local logs",
PanelLeftSuffix: "left",
Expand Down Expand Up @@ -170,31 +167,6 @@ describe("MenuCard", () => {
eventMocks.listen.mockResolvedValue(() => {});
});

it("keeps Fireworks vendor API spend visible when local cost summaries are hidden", async () => {
const snapshot = provider(null, 0);
snapshot.providerId = "fireworks";
snapshot.displayName = "Fireworks";
snapshot.cost = {
used: 12.34,
limit: null,
remaining: null,
currencyCode: "USD",
currencySymbol: "$",
period: "30 days",
resetsAt: null,
formattedUsed: "$12.34",
formattedLimit: null,
balance: null,
formattedBalance: null,
daily: [],
alwaysVisible: true,
};

renderCard(snapshot, { costSummaryDisplayStyle: "hidden" });

expect(await screen.findByText("API spend")).toBeInTheDocument();
expect(document.querySelector(".menu-card__cost-line")).toHaveTextContent("$12.34");
});
it("does not mix stale local usage into an error card", async () => {
const { container } = renderCard(
provider("OAuth error: Claude OAuth credentials not found."),
Expand Down
Loading