Fix explorer back and session usage selection

This commit is contained in:
iris committed 2026-09-09 13:01:27 -04:00
1 parent 8c88a7e991
commit 14dd520719
10 files changed
+222 -57

No files matched your search

+28 -5
View File
@@ -60,6 +60,9 @@ pub struct UsageWindow {
pub label: String,
/// 0-100.
pub percent: f64,
/// Length of the cycle when the provider reports one.
#[serde(skip_serializing_if = "Option::is_none")]
pub duration_minutes: Option<u64>,
/// ISO-8601, as the API sends it; absent for windows that never reset.
#[serde(skip_serializing_if = "Option::is_none")]
pub resets_at: Option<String>,
@@ -361,11 +364,18 @@ fn parse_codex_windows(limits: &Value) -> Vec<UsageWindow> {
None => "Secondary window".to_string(),
};
Some(UsageWindow {
// Common semantic names: the phone's compact bar asks for
// `session`, and auto-resume treats all windows alike.
kind: if primary { "session" } else { "weekly_all" }.to_string(),
// Keep the common semantic names where the duration establishes them. `primary`
// is only the protocol's position and can itself be a weekly window.
kind: match minutes {
Some(300) => "session",
Some(10_080) => "weekly_all",
_ if primary => "primary",
_ => "secondary",
}
.to_string(),
label,
percent: window.get("usedPercent")?.as_f64()?,
duration_minutes: minutes,
resets_at: window
.get("resetsAt")
.and_then(Value::as_i64)
@@ -374,7 +384,8 @@ fn parse_codex_windows(limits: &Value) -> Vec<UsageWindow> {
at.format(&time::format_description::well_known::Rfc3339)
.ok()
}),
active: primary,
// Unlike Claude's response, Codex does not say which window is binding.
active: false,
})
})
.collect()
@@ -528,6 +539,11 @@ fn parse_windows(body: &Value) -> Vec<UsageWindow> {
kind: kind.to_string(),
label,
percent,
duration_minutes: match kind {
"session" => Some(300),
"weekly_all" | "weekly_scoped" => Some(10_080),
_ => None,
},
resets_at: limit
.get("resets_at")
.and_then(Value::as_str)
@@ -662,6 +678,7 @@ fn fixture_windows(percent: f64, reset: Option<&str>) -> Vec<UsageWindow> {
kind: "session".to_string(),
label: "5-hour window".to_string(),
percent,
duration_minutes: Some(300),
resets_at: resets_at.clone(),
active: true,
},
@@ -669,6 +686,7 @@ fn fixture_windows(percent: f64, reset: Option<&str>) -> Vec<UsageWindow> {
kind: "weekly_all".to_string(),
label: "Weekly (all models)".to_string(),
percent: percent / 2.0,
duration_minutes: Some(10_080),
resets_at: resets_at.as_ref().map(|_| reset_in(FIXTURE_MINUTES * 40)),
active: false,
},
@@ -676,6 +694,7 @@ fn fixture_windows(percent: f64, reset: Option<&str>) -> Vec<UsageWindow> {
kind: "weekly_scoped".to_string(),
label: "Weekly (Echo)".to_string(),
percent: percent / 4.0,
duration_minutes: Some(10_080),
resets_at: resets_at.as_ref().map(|_| reset_in(FIXTURE_MINUTES * 40)),
active: false,
},
@@ -1107,9 +1126,11 @@ mod tests {
assert_eq!(windows.len(), 2);
assert_eq!(windows[0].label, "5-hour window");
assert_eq!(windows[0].percent, 10.0);
assert!(windows[0].active);
assert_eq!(windows[0].duration_minutes, Some(300));
assert!(!windows[0].active);
assert_eq!(windows[1].kind, "weekly_all");
assert_eq!(windows[1].label, "Weekly");
assert_eq!(windows[1].duration_minutes, Some(10_080));
assert!(
windows[1]
.resets_at
@@ -1141,6 +1162,8 @@ mod tests {
assert_eq!(snapshot.limit_id.as_deref(), Some("base_model_inference"));
assert_eq!(snapshot.limit_name.as_deref(), Some("gpt-reserve"));
assert_eq!(snapshot.windows.len(), 1);
assert_eq!(snapshot.windows[0].kind, "weekly_all");
assert_eq!(snapshot.windows[0].label, "Weekly");
assert_eq!(snapshot.windows[0].duration_minutes, Some(10_080));
}
}