1use std::collections::HashSet;
4use std::time::Duration;
5
6use chrono::Utc;
7use reqwest::Client;
8
9use crate::cache::DEFAULT_TTL;
10use crate::config::{Config, CustomProviderConfig};
11use crate::error::{AppError, Result};
12use crate::theme::Theme;
13use crate::vendor::{VendorId, VendorOutcome};
14
15#[derive(Debug, Clone)]
21pub enum TabState {
22 Loading,
23 Ready(Box<ReadyTab>),
24 Error {
25 message: String,
26 plan: Option<String>,
30 },
31}
32
33#[derive(Debug, Clone)]
34pub struct ReadyTab {
35 pub snapshot: crate::usage::VendorSnapshot,
36 pub stale: bool,
37 pub last_error: Option<(u16, String)>,
38 pub fetched_at: Option<chrono::DateTime<chrono::Utc>>,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq, Hash)]
49pub enum TabSource {
50 Builtin(VendorId),
51 Custom {
52 id: String,
53 name: String,
54 short_name: String,
55 },
56}
57
58impl TabState {
59 pub fn error(message: impl AsRef<str>) -> Self {
60 Self::error_with_plan(message, None)
61 }
62
63 pub fn error_with_plan(message: impl AsRef<str>, plan: Option<String>) -> Self {
64 let plan = plan.and_then(|plan| {
65 let cleaned = crate::display::sanitize_untrusted_field(plan.trim());
66 if cleaned.is_empty() || cleaned.eq_ignore_ascii_case("unknown") {
67 None
68 } else {
69 Some(cleaned)
70 }
71 });
72 Self::Error {
73 message: message.as_ref().to_string(),
74 plan,
75 }
76 }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Hash)]
86pub struct TabId {
87 pub source: TabSource,
88 pub account: Option<String>,
89 pub desktop: bool,
90}
91
92impl TabId {
93 pub fn vendor(vendor: VendorId) -> Self {
95 Self {
96 source: TabSource::Builtin(vendor),
97 account: None,
98 desktop: false,
99 }
100 }
101
102 pub fn account(label: impl Into<String>) -> Self {
104 Self::account_for(VendorId::Anthropic, label)
105 }
106
107 pub fn account_for(vendor: VendorId, label: impl Into<String>) -> Self {
109 Self {
110 source: TabSource::Builtin(vendor),
111 account: Some(label.into()),
112 desktop: false,
113 }
114 }
115
116 pub fn desktop_account(label: impl Into<String>) -> Self {
119 Self {
120 source: TabSource::Builtin(VendorId::Anthropic),
121 account: Some(label.into()),
122 desktop: true,
123 }
124 }
125
126 pub fn custom(spec: &CustomProviderConfig) -> Self {
128 Self {
129 source: TabSource::Custom {
130 id: spec.id.clone(),
131 name: spec.name.clone(),
132 short_name: spec.short_name.clone(),
133 },
134 account: None,
135 desktop: false,
136 }
137 }
138
139 pub fn vendor_id(&self) -> Option<VendorId> {
142 match &self.source {
143 TabSource::Builtin(vendor) => Some(*vendor),
144 TabSource::Custom { .. } => None,
145 }
146 }
147}
148
149pub fn tabs_from_config(config: &Config) -> Vec<TabId> {
158 build_tabs(config, &[])
159}
160
161pub fn tabs_with_desktop(config: &Config) -> Vec<TabId> {
165 build_tabs(config, &desktop_profile_labels(config))
166}
167
168fn build_tabs(config: &Config, desktop_labels: &[String]) -> Vec<TabId> {
181 let desktop_set: HashSet<&str> = desktop_labels.iter().map(String::as_str).collect();
182 let mut tabs = Vec::new();
183 for vendor in config.enabled_vendors() {
184 if vendor == VendorId::Anthropic {
185 let accounts: Vec<_> = config
186 .anthropic
187 .all_accounts()
188 .into_iter()
189 .filter(|a| !desktop_set.contains(a.label.as_str()))
190 .collect();
191 if config.anthropic.show_default_account
195 || (accounts.is_empty() && desktop_labels.is_empty())
196 {
197 tabs.push(TabId::vendor(vendor));
198 }
199 for acct in accounts {
200 tabs.push(TabId::account(acct.label));
201 }
202 for label in desktop_labels {
203 tabs.push(TabId::desktop_account(label.clone()));
204 }
205 } else if vendor == VendorId::Openrouter {
206 if config.openrouter.show_default_account || config.openrouter.accounts.is_empty() {
207 tabs.push(TabId::vendor(vendor));
208 }
209 for account in &config.openrouter.accounts {
210 tabs.push(TabId::account_for(vendor, account.label.clone()));
211 }
212 } else if vendor == VendorId::Openai {
213 tabs.push(TabId::vendor(vendor));
214 for account in &config.openai.accounts {
215 tabs.push(TabId::account_for(vendor, account.label.clone()));
216 }
217 } else {
218 tabs.push(TabId::vendor(vendor));
219 }
220 }
221 for spec in config.enabled_custom() {
223 tabs.push(TabId::custom(spec));
224 }
225 tabs
226}
227
228#[cfg(target_os = "macos")]
232fn desktop_profile_labels(config: &Config) -> Vec<String> {
233 let Ok(paths) = crate::claude_desktop::Paths::resolve(&config.anthropic) else {
234 return Vec::new();
235 };
236 if !paths.available() {
237 return Vec::new();
238 }
239 crate::claude_desktop::load_profiles(&paths.profiles_dir)
240 .into_iter()
241 .filter(|p| p.has_credentials)
242 .map(|p| p.label)
243 .collect()
244}
245
246#[cfg(not(target_os = "macos"))]
247fn desktop_profile_labels(_config: &Config) -> Vec<String> {
248 Vec::new()
249}
250
251#[derive(Debug)]
252pub struct App {
253 pub tabs_meta: Vec<TabId>,
254 pub active: usize,
255 pub tabs: Vec<TabState>,
256 refreshing_tabs: HashSet<TabId>,
259 pub tab_generation: u64,
263 pub overview: bool,
266 pub overview_vendors: Option<Vec<VendorId>>,
268 pub theme: Theme,
269 pub quit: bool,
270 pub settings: Option<crate::tui::settings::SettingsState>,
272 pub context_enabled: bool,
275 pub context_generation: u64,
278 pub context: Option<crate::tui::context::ContextState>,
280 pub vendor_box: crate::config::VendorBoxStyle,
282}
283
284impl App {
285 pub fn new(tabs_meta: Vec<TabId>) -> Self {
286 Self::with_theme(tabs_meta, Theme::default().merged_with_omarchy())
289 }
290
291 pub fn with_theme(tabs_meta: Vec<TabId>, theme: Theme) -> Self {
297 let n = tabs_meta.len();
298 Self {
299 tabs_meta,
300 active: 0,
301 tabs: vec![TabState::Loading; n],
302 refreshing_tabs: HashSet::new(),
303 tab_generation: 0,
304 overview: false,
305 overview_vendors: None,
306 theme,
307 quit: false,
308 settings: None,
309 context_enabled: false,
310 context_generation: 0,
311 context: None,
312 vendor_box: crate::config::VendorBoxStyle::Sidebar,
313 }
314 }
315
316 pub fn new_with_primary(tabs_meta: Vec<TabId>, primary: Option<VendorId>) -> Self {
320 let mut app = Self::new(tabs_meta);
321 if primary.is_some() {
324 app.select_primary(primary);
325 } else {
326 app.overview = true;
327 }
328 app
329 }
330
331 pub fn active_tab_id(&self) -> Option<&TabId> {
332 self.tabs_meta.get(self.active)
333 }
334
335 pub fn active_vendor(&self) -> Option<VendorId> {
336 self.tabs_meta.get(self.active).and_then(TabId::vendor_id)
337 }
338
339 pub fn set_tabs(&mut self, tabs_meta: Vec<TabId>) {
346 let selected = self.active_tab_id().cloned();
347 let fallback = self.active.min(tabs_meta.len().saturating_sub(1));
348 self.tab_generation = self.tab_generation.wrapping_add(1);
349 self.active = selected
350 .as_ref()
351 .and_then(|tab| tabs_meta.iter().position(|candidate| candidate == tab))
352 .unwrap_or(fallback);
353 self.tabs = vec![TabState::Loading; tabs_meta.len()];
354 self.tabs_meta = tabs_meta;
355 self.refreshing_tabs.clear();
356 }
357
358 pub fn begin_refresh(&mut self, tab: &TabId) -> bool {
362 let Some(index) = self.tabs_meta.iter().position(|current| current == tab) else {
363 return false;
364 };
365 if !self.refreshing_tabs.insert(tab.clone()) {
366 return false;
367 }
368 if !matches!(self.tabs[index], TabState::Ready(_)) {
369 self.tabs[index] = TabState::Loading;
370 }
371 true
372 }
373
374 pub fn is_refreshing(&self, tab: &TabId) -> bool {
375 self.refreshing_tabs.contains(tab)
376 }
377
378 pub fn tab_is_refreshing(&self, index: usize) -> bool {
379 self.tabs_meta
380 .get(index)
381 .is_some_and(|tab| self.is_refreshing(tab))
382 }
383
384 pub fn apply_refresh(&mut self, generation: u64, tab: &TabId, state: TabState) -> bool {
389 if generation != self.tab_generation {
390 return false;
391 }
392 let Some(index) = self.tabs_meta.iter().position(|current| current == tab) else {
393 return false;
394 };
395 let was_refreshing = self.refreshing_tabs.remove(tab);
396 if was_refreshing
400 && let TabState::Ready(ready) = &mut self.tabs[index]
401 && let TabState::Error { message, .. } = state
402 {
403 ready.stale = true;
404 ready.last_error = Some((0, message));
405 } else {
406 self.tabs[index] = state;
407 }
408 true
409 }
410
411 pub fn select_primary(&mut self, primary: Option<VendorId>) {
414 if let Some(p) = primary
415 && let Some(idx) = self.tabs_meta.iter().position(|t| t.vendor_id() == Some(p))
416 {
417 self.active = idx;
418 self.overview = false;
419 }
420 }
421
422 pub fn next_tab(&mut self) {
425 if self.overview {
426 if !self.tabs_meta.is_empty() {
427 self.overview = false;
428 self.active = 0;
429 }
430 } else if self.active + 1 < self.tabs_meta.len() {
431 self.active += 1;
432 } else {
433 self.overview = true;
434 }
435 }
436
437 pub fn prev_tab(&mut self) {
438 if self.overview {
439 if !self.tabs_meta.is_empty() {
440 self.overview = false;
441 self.active = self.tabs_meta.len() - 1;
442 }
443 } else if self.active > 0 {
444 self.active -= 1;
445 } else {
446 self.overview = true;
447 }
448 }
449
450 pub fn overview_tabs(&self) -> Vec<usize> {
455 match &self.overview_vendors {
456 None => (0..self.tabs_meta.len()).collect(),
457 Some(wanted) => wanted
458 .iter()
459 .flat_map(|v| {
460 self.tabs_meta
461 .iter()
462 .enumerate()
463 .filter(move |(_, t)| t.vendor_id() == Some(*v))
464 .map(|(i, _)| i)
465 })
466 .collect(),
467 }
468 }
469}
470
471pub async fn refresh_one(client: &Client, config: &Config, tab: &TabId) -> TabState {
473 match build_outcome(client, config, tab).await {
474 Ok(outcome) => {
475 let now = Utc::now();
480 let fetched_at = outcome
481 .cache_age
482 .map(|age| now - chrono::Duration::from_std(age).unwrap_or_default());
483 TabState::Ready(Box::new(ReadyTab {
484 snapshot: outcome.snapshot,
485 stale: outcome.stale,
486 last_error: outcome.last_error.map(|(code, message)| {
487 (code, crate::display::sanitize_untrusted_field(&message))
488 }),
489 fetched_at,
490 }))
491 }
492 Err(e) => TabState::error_with_plan(
493 crate::display::sanitize_untrusted_field(&e.user_message()),
494 e.plan().map(str::to_string),
495 ),
496 }
497}
498
499async fn build_outcome(client: &Client, config: &Config, tab: &TabId) -> Result<VendorOutcome> {
500 let vendor = match &tab.source {
501 TabSource::Builtin(vendor) => *vendor,
502 TabSource::Custom { id, .. } => {
503 let spec = config.custom_by_id(id).ok_or_else(|| {
506 AppError::Other(format!("custom provider {id} is not configured"))
507 })?;
508 let api_key = spec.resolve_api_key()?;
509 let cache = crate::cache::Cache::for_vendor_account("custom", id)?;
510 let outcome =
511 crate::custom::fetch_snapshot(client, spec, &api_key, &cache, spec.cache_ttl())
512 .await?;
513 return Ok(outcome.into());
514 }
515 };
516 match vendor {
517 VendorId::Anthropic => {
518 let (creds_target, cache) = match tab.account.as_deref() {
524 Some(label) if tab.desktop => {
525 crate::anthropic::desktop_creds::account_target(config, label)?
526 }
527 Some(label) => config.anthropic.account_target(label)?,
528 None => {
529 let target = match config.anthropic.credentials_path.clone() {
530 Some(p) => crate::anthropic::creds::CredsTarget::Explicit(p),
531 None => crate::anthropic::creds::CredsTarget::Default(
532 crate::anthropic::creds::default_path().unwrap_or_default(),
533 ),
534 };
535 (target, crate::cache::Cache::for_vendor("anthropic")?)
536 }
537 };
538 let endpoints = crate::anthropic::fetch::Endpoints::default();
539 let outcome = crate::anthropic::fetch_snapshot(
540 client,
541 &creds_target,
542 &cache,
543 &endpoints,
544 DEFAULT_TTL,
545 )
546 .await?;
547 Ok(outcome.map(crate::usage::VendorSnapshot::Anthropic))
548 }
549 VendorId::AnthropicApi => {
550 let key = crate::config::resolve_api_key(
551 "Anthropic_API",
552 &config.anthropic_api.api_key_env,
553 config.anthropic_api.api_key.as_deref(),
554 )?;
555 let cache = crate::cache::Cache::for_vendor("anthropic_api")?;
556 let endpoints = crate::anthropic_api::fetch::Endpoints::default();
557 let outcome = crate::anthropic_api::fetch_snapshot(
558 client,
559 &key,
560 &cache,
561 &endpoints,
562 DEFAULT_TTL,
563 config.anthropic_api.monthly_limit,
564 )
565 .await?;
566 Ok(outcome.into())
567 }
568 VendorId::Openrouter => {
569 let api_key = config.openrouter.resolve_api_key(tab.account.as_deref())?;
570 let cache = match tab.account.as_deref() {
571 Some(label) => crate::cache::Cache::for_vendor_account("openrouter", label)?,
572 None => crate::cache::Cache::for_vendor("openrouter")?,
573 };
574 let endpoints = crate::openrouter::fetch::Endpoints::default();
575 let outcome = crate::openrouter::fetch_snapshot(
576 client,
577 &api_key,
578 &cache,
579 &endpoints,
580 DEFAULT_TTL,
581 )
582 .await?;
583 Ok(outcome.into())
584 }
585 VendorId::Zai => {
586 let api_key = crate::config::resolve_api_key(
587 "Zai",
588 &config.zai.api_key_env,
589 config.zai.api_key.as_deref(),
590 )?;
591 let cache = crate::cache::Cache::for_vendor("zai")?;
592 let endpoints = crate::zai::fetch::Endpoints::default();
593 let outcome = crate::zai::fetch_snapshot(
594 client,
595 &api_key,
596 &cache,
597 &endpoints,
598 DEFAULT_TTL,
599 config.zai.plan_tier.as_deref(),
600 )
601 .await?;
602 Ok(outcome.into())
603 }
604 VendorId::Openai => {
605 let label = tab.account.as_deref();
606 let cache = match label {
607 Some(label) => crate::cache::Cache::for_vendor_account("openai", label)?,
608 None => crate::cache::Cache::for_vendor("openai")?,
609 };
610 let creds_path = config.openai.resolve_auth_path(label)?;
611 let endpoints = crate::openai::fetch::Endpoints::default();
612 let outcome =
613 crate::openai::fetch_snapshot(client, &creds_path, &cache, &endpoints, DEFAULT_TTL)
614 .await?;
615 Ok(outcome.into())
616 }
617 VendorId::Copilot => {
618 let token = config.copilot.resolve_token()?;
619 let cache = crate::cache::Cache::for_vendor("copilot")?;
620 let endpoints = crate::copilot::fetch::Endpoints::default();
621 let outcome =
622 crate::copilot::fetch_snapshot(client, &token, &cache, &endpoints, DEFAULT_TTL)
623 .await?;
624 Ok(outcome.into())
625 }
626 VendorId::Deepseek => {
627 let api_key = crate::config::resolve_api_key(
628 "DeepSeek",
629 &config.deepseek.api_key_env,
630 config.deepseek.api_key.as_deref(),
631 )?;
632 let cache = crate::cache::Cache::for_vendor("deepseek")?;
633 let endpoints = crate::deepseek::fetch::Endpoints::default();
634 let outcome =
635 crate::deepseek::fetch_snapshot(client, &api_key, &cache, &endpoints, DEFAULT_TTL)
636 .await?;
637 Ok(outcome.into())
638 }
639 VendorId::Kimi => {
640 let (auth, endpoints) = crate::kimi::resolve_auth(&config.kimi)?;
641 let cache = crate::cache::Cache::for_vendor("kimi")?;
642 let outcome = crate::kimi::fetch::fetch_snapshot_with_auth(
643 client,
644 &auth,
645 &cache,
646 &endpoints,
647 DEFAULT_TTL,
648 )
649 .await?;
650 Ok(outcome.into())
651 }
652 VendorId::Kilo => {
653 let api_key = crate::config::resolve_api_key(
654 "Kilo",
655 &config.kilo.api_key_env,
656 config.kilo.api_key.as_deref(),
657 )?;
658 let cache = crate::cache::Cache::for_vendor("kilo")?;
659 let endpoints = crate::kilo::fetch::Endpoints::default();
660 let outcome = crate::kilo::fetch_snapshot(
661 client,
662 &api_key,
663 &cache,
664 &endpoints,
665 DEFAULT_TTL,
666 config.kilo.organization_id.as_deref(),
667 )
668 .await?;
669 Ok(outcome.into())
670 }
671 VendorId::Novita => {
672 let api_key = crate::config::resolve_api_key(
673 "Novita",
674 &config.novita.api_key_env,
675 config.novita.api_key.as_deref(),
676 )?;
677 let cache = crate::cache::Cache::for_vendor("novita")?;
678 let endpoints = crate::novita::fetch::Endpoints::default();
679 let outcome =
680 crate::novita::fetch_snapshot(client, &api_key, &cache, &endpoints, DEFAULT_TTL)
681 .await?;
682 Ok(outcome.into())
683 }
684 VendorId::Moonshot => {
685 let api_key = crate::config::resolve_api_key(
686 "Moonshot",
687 &config.moonshot.api_key_env,
688 config.moonshot.api_key.as_deref(),
689 )?;
690 let cache = crate::cache::Cache::for_vendor("moonshot")?;
691 let (endpoints, currency) =
692 crate::moonshot::fetch::Endpoints::for_region(&config.moonshot.region);
693 let outcome = crate::moonshot::fetch_snapshot(
694 client,
695 &api_key,
696 &cache,
697 &endpoints,
698 DEFAULT_TTL,
699 currency,
700 )
701 .await?;
702 Ok(outcome.into())
703 }
704 VendorId::Grok => {
705 let key = crate::config::resolve_api_key(
706 "Grok",
707 &config.grok.api_key_env,
708 config.grok.api_key.as_deref(),
709 )?;
710 let cache = crate::cache::Cache::for_vendor("grok")?;
711 let endpoints = crate::grok::fetch::Endpoints::default();
712 let outcome = crate::grok::fetch_snapshot(
713 client,
714 &key,
715 &cache,
716 &endpoints,
717 DEFAULT_TTL,
718 config.grok.team_id.as_deref(),
719 )
720 .await?;
721 Ok(outcome.into())
722 }
723 VendorId::Supergrok => {
724 let cache = crate::cache::Cache::for_vendor("supergrok")?;
725 let scope_paths = crate::supergrok::scope::ScopePaths::with_overrides(
726 config.supergrok.auth_path.as_deref(),
727 config.supergrok.config_path.as_deref(),
728 )?;
729 let outcome = crate::supergrok::fetch_snapshot(
730 &config.supergrok.grok_binary,
731 &scope_paths,
732 &cache,
733 DEFAULT_TTL,
734 )
735 .await?;
736 Ok(outcome.into())
737 }
738 VendorId::Antigravity => {
739 let cache = crate::cache::Cache::for_vendor("antigravity")?;
742 let oauth = crate::antigravity::cloud::OauthClient::from_config(
743 config.antigravity.oauth_client_id.as_deref(),
744 config.antigravity.oauth_client_secret.as_deref(),
745 );
746 let outcome =
747 crate::antigravity::fetch_snapshot(client, &cache, DEFAULT_TTL, oauth.as_ref())
748 .await?;
749 Ok(outcome.into())
750 }
751 VendorId::Minimax => {
752 let api_key = crate::config::resolve_api_key(
753 "MiniMax",
754 &config.minimax.api_key_env,
755 config.minimax.api_key.as_deref(),
756 )?;
757 let cache = crate::cache::Cache::for_vendor("minimax")?;
758 let endpoints = crate::minimax::fetch::Endpoints::for_region(&config.minimax.region);
759 let outcome =
760 crate::minimax::fetch_snapshot(client, &api_key, &cache, &endpoints, DEFAULT_TTL)
761 .await?;
762 Ok(outcome.into())
763 }
764 VendorId::Cursor => {
765 let cache = crate::cache::Cache::for_vendor("cursor")?;
766 let db_path = config
767 .cursor
768 .db_path
769 .clone()
770 .map(Ok)
771 .unwrap_or_else(crate::cursor::db::default_db_path)?;
772 let agent_auth_path = config
773 .cursor
774 .agent_auth_path
775 .clone()
776 .map(Ok)
777 .unwrap_or_else(crate::cursor::db::default_agent_auth_path)?;
778 let endpoints = crate::cursor::fetch::Endpoints::default();
779 let outcome = crate::cursor::fetch_snapshot(
780 client,
781 &db_path,
782 &agent_auth_path,
783 &cache,
784 &endpoints,
785 DEFAULT_TTL,
786 )
787 .await?;
788 Ok(outcome.into())
789 }
790 VendorId::Kiro => {
791 let cache = crate::cache::Cache::for_vendor("kiro")?;
792 let db_path = config
793 .kiro
794 .db_path
795 .clone()
796 .map(Ok)
797 .unwrap_or_else(crate::kiro::db::default_db_path)?;
798 let outcome =
799 crate::kiro::fetch_snapshot(client, &db_path, &cache, DEFAULT_TTL).await?;
800 Ok(outcome.into())
801 }
802 VendorId::NousResearch => {
803 let store = crate::nous::credentials::CredentialStore::default();
804 let endpoints = crate::nous::fetch::Endpoints::default();
805 let account = crate::nous::fetch::fetch_account_with_refresh(
806 client,
807 &store,
808 &endpoints,
809 Utc::now(),
810 )
811 .await?;
812 Ok(crate::outcome::Outcome::fresh(
814 crate::usage::VendorSnapshot::NousResearch(account),
815 ))
816 }
817 VendorId::OpenCodeGo => {
818 let api_key = crate::config::resolve_api_key(
819 "OpenCode Go",
820 &config.opencode_go.api_key_env,
821 config.opencode_go.api_key.as_deref(),
822 )?;
823 let cache = crate::cache::Cache::for_vendor("opencode-go")?;
824 let endpoints = crate::opencode_go::fetch::Endpoints::default();
825 let outcome = crate::opencode_go::fetch::fetch_snapshot(
826 client,
827 &api_key,
828 &cache,
829 &endpoints,
830 DEFAULT_TTL,
831 )
832 .await?;
833 Ok(outcome.into())
834 }
835 VendorId::CommandCode => {
836 let credential =
837 crate::commandcode::creds::resolve(config.commandcode.auth_paths.as_deref())?;
838 let cache = crate::cache::Cache::for_vendor("commandcode")?;
839 let endpoints = crate::commandcode::fetch::Endpoints::default();
840 let outcome = crate::commandcode::fetch::fetch_snapshot(
841 client,
842 &credential.token,
843 &cache,
844 &endpoints,
845 DEFAULT_TTL,
846 )
847 .await?;
848 Ok(outcome.into())
849 }
850 VendorId::Ollama => {
851 let api_key = crate::config::resolve_api_key(
852 "Ollama",
853 &config.ollama.api_key_env,
854 config.ollama.api_key.as_deref(),
855 )?;
856 let cache = crate::cache::Cache::for_vendor("ollama")?;
857 let endpoints = crate::ollama::fetch::Endpoints::default();
858 let outcome = crate::ollama::fetch_snapshot(
859 client,
860 &api_key,
861 &config.ollama.plan,
862 &cache,
863 &endpoints,
864 DEFAULT_TTL,
865 )
866 .await?;
867 Ok(outcome.into())
868 }
869 }
870}
871
872pub const REFRESH_INTERVAL: Duration = Duration::from_secs(60);
875
876pub const ANTHROPIC_REFRESH_STAGGER: Duration = Duration::from_millis(800);
883
884pub fn refresh_stagger(tabs: &[TabId], step: Duration) -> Vec<Duration> {
890 let mut anthropic_seen: u32 = 0;
891 tabs.iter()
892 .map(|tab| {
893 if tab.vendor_id() == Some(VendorId::Anthropic) {
894 let delay = step * anthropic_seen;
895 anthropic_seen += 1;
896 delay
897 } else {
898 Duration::ZERO
899 }
900 })
901 .collect()
902}
903
904#[cfg(test)]
905mod tests {
906 use super::*;
907 use chrono::TimeZone;
908
909 #[test]
913 fn refresh_stagger_spaces_out_anthropic_tabs_only() {
914 let step = Duration::from_millis(800);
915 let tabs = vec![
916 TabId::vendor(VendorId::Anthropic), TabId::account("work"),
918 TabId::account("personal"),
919 TabId::vendor(VendorId::Openai),
920 TabId::vendor(VendorId::Zai),
921 ];
922 let delays = refresh_stagger(&tabs, step);
923 assert_eq!(
924 delays,
925 vec![
926 Duration::ZERO, step, step * 2, Duration::ZERO, Duration::ZERO, ]
932 );
933 }
934
935 #[test]
936 fn refresh_stagger_is_a_noop_without_anthropic_accounts() {
937 let tabs = vec![
939 TabId::vendor(VendorId::Anthropic),
940 TabId::vendor(VendorId::Openrouter),
941 ];
942 assert!(
943 refresh_stagger(&tabs, Duration::from_millis(800))
944 .iter()
945 .all(|d| d.is_zero())
946 );
947 }
948
949 #[test]
950 fn select_primary_moves_to_enabled_vendor() {
951 let mut app = App::with_theme(
952 vec![
953 TabId::vendor(VendorId::Anthropic),
954 TabId::vendor(VendorId::Openrouter),
955 ],
956 Theme::default(),
957 );
958 app.select_primary(Some(VendorId::Openrouter));
959 assert_eq!(app.active_vendor(), Some(VendorId::Openrouter));
960 }
961
962 #[test]
963 fn select_primary_ignores_disabled_vendor() {
964 let mut app = App::with_theme(vec![TabId::vendor(VendorId::Anthropic)], Theme::default());
965 app.select_primary(Some(VendorId::Openai));
966 assert_eq!(app.active_vendor(), Some(VendorId::Anthropic));
967 }
968
969 #[test]
970 fn nav_ring_wraps_through_the_overview_at_both_ends() {
971 let mut app = App::with_theme(
972 vec![
973 TabId::vendor(VendorId::Anthropic),
974 TabId::vendor(VendorId::Openai),
975 ],
976 Theme::default(),
977 );
978 app.overview = true;
979
980 app.next_tab(); assert!(!app.overview);
982 assert_eq!(app.active, 0);
983 app.next_tab();
984 assert_eq!(app.active, 1);
985 app.next_tab(); assert!(app.overview);
987
988 app.prev_tab(); assert!(!app.overview);
990 assert_eq!(app.active, 1);
991 app.prev_tab();
992 assert_eq!(app.active, 0);
993 app.prev_tab(); assert!(app.overview);
995 }
996
997 #[test]
998 fn overview_tabs_defaults_to_all_and_honors_the_config_filter() {
999 let mut app = App::with_theme(
1000 vec![
1001 TabId::vendor(VendorId::Anthropic),
1002 TabId::vendor(VendorId::Openai),
1003 TabId::vendor(VendorId::Zai),
1004 ],
1005 Theme::default(),
1006 );
1007 assert_eq!(app.overview_tabs(), vec![0, 1, 2]);
1008
1009 app.overview_vendors = Some(vec![VendorId::Zai, VendorId::Anthropic]);
1011 assert_eq!(app.overview_tabs(), vec![2, 0]);
1012
1013 app.overview_vendors = Some(vec![VendorId::Grok, VendorId::Openai]);
1015 assert_eq!(app.overview_tabs(), vec![1]);
1016 }
1017
1018 fn config_with_accounts(labels: &[&str]) -> Config {
1019 let mut config = Config::default();
1020 config.openai.enabled = false;
1023 config.zai.enabled = false;
1024 config.openrouter.enabled = false;
1025 config.anthropic.accounts = labels
1026 .iter()
1027 .map(|l| crate::config::AnthropicAccount {
1028 label: (*l).to_string(),
1029 credentials_path: format!("/creds/{l}.json").into(),
1030 })
1031 .collect();
1032 config
1033 }
1034
1035 #[test]
1036 fn show_default_account_false_hides_the_unnamed_claude_tab() {
1037 let mut config = config_with_accounts(&["work", "personal"]);
1040 config.anthropic.show_default_account = false;
1041 assert_eq!(
1042 tabs_from_config(&config),
1043 vec![TabId::account("work"), TabId::account("personal")]
1044 );
1045
1046 let mut empty = Config::default();
1049 empty.openai.enabled = false;
1050 empty.zai.enabled = false;
1051 empty.openrouter.enabled = false;
1052 empty.anthropic.show_default_account = false;
1053 assert_eq!(
1054 tabs_from_config(&empty),
1055 vec![TabId::vendor(VendorId::Anthropic)]
1056 );
1057 }
1058
1059 #[test]
1060 fn tabs_expand_anthropic_accounts_after_default() {
1061 let tabs = tabs_from_config(&config_with_accounts(&["work", "personal"]));
1063 assert_eq!(
1064 tabs,
1065 vec![
1066 TabId::vendor(VendorId::Anthropic),
1067 TabId::account("work"),
1068 TabId::account("personal"),
1069 ]
1070 );
1071 }
1072
1073 #[test]
1074 fn tabs_without_accounts_are_just_enabled_vendors() {
1075 let config = Config::default();
1077 let tabs = tabs_from_config(&config);
1078 let vendors: Vec<VendorId> = tabs.iter().filter_map(TabId::vendor_id).collect();
1079 assert_eq!(vendors, config.enabled_vendors());
1080 assert!(tabs.iter().all(|t| t.account.is_none()));
1081 }
1082
1083 #[test]
1084 fn tabs_expand_openrouter_accounts_without_changing_other_vendors() {
1085 let mut config = Config::default();
1086 config.anthropic.enabled = false;
1087 config.openai.enabled = false;
1088 config.zai.enabled = false;
1089 config.openrouter.accounts = vec![
1090 crate::config::OpenRouterAccount {
1091 label: "work".into(),
1092 api_key_env: Some("OPENROUTER_WORK_API_KEY".into()),
1093 api_key: None,
1094 },
1095 crate::config::OpenRouterAccount {
1096 label: "personal".into(),
1097 api_key_env: None,
1098 api_key: Some("personal-key".into()),
1099 },
1100 ];
1101 assert_eq!(
1102 tabs_from_config(&config),
1103 vec![
1104 TabId::vendor(VendorId::Openrouter),
1105 TabId::account_for(VendorId::Openrouter, "work"),
1106 TabId::account_for(VendorId::Openrouter, "personal"),
1107 ]
1108 );
1109 }
1110
1111 #[test]
1112 fn openai_named_accounts_get_their_own_tabs_after_the_default() {
1113 let mut config = Config::default();
1114 config.anthropic.enabled = false;
1115 config.zai.enabled = false;
1116 config.openrouter.enabled = false;
1117 config.openai.accounts.push(crate::config::OpenAiAccount {
1118 label: "work".into(),
1119 codex_auth_path: "/tmp/codex-work/auth.json".into(),
1120 });
1121 assert_eq!(
1122 tabs_from_config(&config),
1123 vec![
1124 TabId::vendor(VendorId::Openai),
1125 TabId::account_for(VendorId::Openai, "work"),
1126 ]
1127 );
1128 }
1129
1130 #[test]
1131 fn openrouter_can_hide_default_only_when_named_accounts_exist() {
1132 let mut config = Config::default();
1133 config.anthropic.enabled = false;
1134 config.openai.enabled = false;
1135 config.zai.enabled = false;
1136 config.openrouter.show_default_account = false;
1137 assert_eq!(
1138 tabs_from_config(&config),
1139 vec![TabId::vendor(VendorId::Openrouter)]
1140 );
1141
1142 config
1143 .openrouter
1144 .accounts
1145 .push(crate::config::OpenRouterAccount {
1146 label: "work".into(),
1147 api_key_env: Some("OPENROUTER_WORK_API_KEY".into()),
1148 api_key: None,
1149 });
1150 assert_eq!(
1151 tabs_from_config(&config),
1152 vec![TabId::account_for(VendorId::Openrouter, "work")]
1153 );
1154 }
1155
1156 #[test]
1157 fn tabs_include_accounts_auto_discovered_from_accounts_dir() {
1158 let td = tempfile::tempdir().unwrap();
1161 for label in ["work", "personal"] {
1162 let dir = td.path().join(label);
1163 std::fs::create_dir_all(&dir).unwrap();
1164 std::fs::write(dir.join(".credentials.json"), "{}").unwrap();
1165 }
1166 let mut config = Config::default();
1167 config.openai.enabled = false;
1168 config.zai.enabled = false;
1169 config.openrouter.enabled = false;
1170 config.anthropic.accounts_dir = Some(td.path().to_path_buf());
1171
1172 let tabs = tabs_from_config(&config);
1173 assert_eq!(
1174 tabs,
1175 vec![
1176 TabId::vendor(VendorId::Anthropic),
1177 TabId::account("personal"), TabId::account("work"),
1179 ]
1180 );
1181 }
1182
1183 #[test]
1184 fn desktop_labels_become_account_tabs_after_cli_accounts() {
1185 let config = config_with_accounts(&["work"]);
1187 let tabs = build_tabs(&config, &["gmail".into(), "hotmail".into()]);
1188 assert_eq!(
1189 tabs,
1190 vec![
1191 TabId::vendor(VendorId::Anthropic),
1192 TabId::account("work"),
1193 TabId::desktop_account("gmail"),
1194 TabId::desktop_account("hotmail"),
1195 ]
1196 );
1197 }
1198
1199 #[test]
1200 fn a_desktop_profile_wins_a_label_collision_with_a_cli_account() {
1201 let config = config_with_accounts(&["gmail", "work"]);
1206 let tabs = build_tabs(&config, &["gmail".into(), "hotmail".into()]);
1207 assert_eq!(
1208 tabs,
1209 vec![
1210 TabId::vendor(VendorId::Anthropic),
1211 TabId::account("work"),
1212 TabId::desktop_account("gmail"),
1213 TabId::desktop_account("hotmail"),
1214 ]
1215 );
1216 }
1217
1218 #[test]
1219 fn desktop_accounts_suppress_the_default_tab_like_named_ones() {
1220 let mut config = config_with_accounts(&[]);
1223 config.cursor.enabled = false;
1224 config.anthropic.show_default_account = false;
1225
1226 assert_eq!(
1229 build_tabs(&config, &[]),
1230 vec![TabId::vendor(VendorId::Anthropic)]
1231 );
1232 assert_eq!(
1234 build_tabs(&config, &["gmail".into()]),
1235 vec![TabId::desktop_account("gmail")]
1236 );
1237 }
1238
1239 #[test]
1240 fn set_tabs_resets_states_and_clamps_selection() {
1241 let mut app = App::with_theme(
1245 tabs_from_config(&config_with_accounts(&["work", "personal"])),
1246 Theme::default(),
1247 );
1248 app.active = 2; app.tabs[0] = TabState::error("old");
1250 let old_tab = app.tabs_meta[0].clone();
1251 assert!(app.begin_refresh(&old_tab));
1252
1253 app.set_tabs(tabs_from_config(&config_with_accounts(&[])));
1254 assert_eq!(app.tabs_meta, vec![TabId::vendor(VendorId::Anthropic)]);
1255 assert_eq!(app.active, 0, "selection clamped after shrink");
1256 assert!(matches!(app.tabs[0], TabState::Loading));
1257 assert!(!app.is_refreshing(&old_tab));
1258 }
1259
1260 #[test]
1261 fn set_tabs_preserves_selected_identity_when_entries_are_inserted() {
1262 let mut app = App::with_theme(
1263 vec![
1264 TabId::vendor(VendorId::Anthropic),
1265 TabId::vendor(VendorId::Openai),
1266 ],
1267 Theme::default(),
1268 );
1269 app.active = 1;
1270
1271 app.set_tabs(vec![
1272 TabId::vendor(VendorId::Anthropic),
1273 TabId::account("work"),
1274 TabId::vendor(VendorId::Openai),
1275 ]);
1276
1277 assert_eq!(app.active, 2);
1278 assert_eq!(app.active_tab_id(), Some(&TabId::vendor(VendorId::Openai)));
1279 }
1280
1281 #[test]
1282 fn refresh_from_old_generation_is_discarded() {
1283 let mut app = App::with_theme(vec![TabId::vendor(VendorId::Anthropic)], Theme::default());
1284 let old_generation = app.tab_generation;
1285 app.set_tabs(vec![TabId::vendor(VendorId::Openai)]);
1286
1287 assert!(!app.apply_refresh(
1288 old_generation,
1289 &TabId::vendor(VendorId::Anthropic),
1290 TabState::error("old result"),
1291 ));
1292 assert!(matches!(app.tabs[0], TabState::Loading));
1293 }
1294
1295 #[test]
1296 fn refresh_identity_mismatch_is_discarded() {
1297 let mut app = App::with_theme(vec![TabId::vendor(VendorId::Anthropic)], Theme::default());
1298 let generation = app.tab_generation;
1299
1300 assert!(!app.apply_refresh(
1301 generation,
1302 &TabId::vendor(VendorId::Openai),
1303 TabState::error("wrong tab"),
1304 ));
1305 assert!(matches!(app.tabs[0], TabState::Loading));
1306 }
1307
1308 #[test]
1309 fn refresh_identity_lands_at_new_index_after_same_generation_reorder() {
1310 let anthropic = TabId::vendor(VendorId::Anthropic);
1311 let openai = TabId::vendor(VendorId::Openai);
1312 let mut app = App::with_theme(vec![anthropic.clone(), openai.clone()], Theme::default());
1313 let generation = app.tab_generation;
1314 assert!(app.begin_refresh(&anthropic));
1315
1316 app.tabs_meta.swap(0, 1);
1319 app.tabs.swap(0, 1);
1320 assert!(app.apply_refresh(generation, &anthropic, TabState::error("ready")));
1321 assert!(matches!(app.tabs[0], TabState::Loading));
1322 assert!(matches!(&app.tabs[1], TabState::Error { message, .. } if message == "ready"));
1323 assert!(!app.is_refreshing(&anthropic));
1324 }
1325
1326 fn ready_at(fetched_at: chrono::DateTime<Utc>) -> TabState {
1327 TabState::Ready(Box::new(ReadyTab {
1328 snapshot: crate::usage::VendorSnapshot::Openrouter(crate::usage::OpenRouterSnapshot {
1329 label: "test".into(),
1330 total_credits: 0.0,
1331 total_usage: 0.0,
1332 usage_daily: 0.0,
1333 usage_weekly: 0.0,
1334 usage_monthly: 0.0,
1335 is_free_tier: false,
1336 limit: None,
1337 limit_remaining: None,
1338 }),
1339 stale: false,
1340 last_error: None,
1341 fetched_at: Some(fetched_at),
1342 }))
1343 }
1344
1345 #[test]
1346 fn refresh_keeps_ready_snapshot_visible_and_suppresses_duplicates() {
1347 let tab = TabId::vendor(VendorId::Openrouter);
1348 let fetched_at = Utc.with_ymd_and_hms(2026, 5, 23, 12, 0, 0).unwrap();
1349 let mut app = App::with_theme(vec![tab.clone()], Theme::default());
1350 app.tabs[0] = ready_at(fetched_at);
1351
1352 assert!(app.begin_refresh(&tab));
1353 assert!(
1354 !app.begin_refresh(&tab),
1355 "duplicate request must be suppressed"
1356 );
1357 assert!(app.is_refreshing(&tab));
1358 match &app.tabs[0] {
1359 TabState::Ready(ready) => assert_eq!(ready.fetched_at, Some(fetched_at)),
1360 other => panic!("ready snapshot disappeared during refresh: {other:?}"),
1361 }
1362 }
1363
1364 #[test]
1365 fn first_refresh_still_uses_loading_until_data_arrives() {
1366 let tab = TabId::vendor(VendorId::Openrouter);
1367 let mut app = App::with_theme(vec![tab.clone()], Theme::default());
1368
1369 assert!(app.begin_refresh(&tab));
1370 assert!(app.is_refreshing(&tab));
1371 assert!(matches!(app.tabs[0], TabState::Loading));
1372
1373 assert!(app.apply_refresh(app.tab_generation, &tab, TabState::error("not signed in"),));
1374 assert!(!app.is_refreshing(&tab));
1375 assert!(
1376 matches!(&app.tabs[0], TabState::Error { message, .. } if message == "not signed in")
1377 );
1378 }
1379
1380 #[test]
1381 fn successful_revalidation_replaces_snapshot_and_clears_indicator() {
1382 let tab = TabId::vendor(VendorId::Openrouter);
1383 let old_at = Utc.with_ymd_and_hms(2026, 5, 23, 12, 0, 0).unwrap();
1384 let new_at = Utc.with_ymd_and_hms(2026, 5, 23, 12, 1, 0).unwrap();
1385 let mut app = App::with_theme(vec![tab.clone()], Theme::default());
1386 app.tabs[0] = ready_at(old_at);
1387
1388 assert!(app.begin_refresh(&tab));
1389 assert!(app.apply_refresh(app.tab_generation, &tab, ready_at(new_at)));
1390 assert!(!app.is_refreshing(&tab));
1391 match &app.tabs[0] {
1392 TabState::Ready(ready) => assert_eq!(ready.fetched_at, Some(new_at)),
1393 other => panic!("expected replacement snapshot, got {other:?}"),
1394 }
1395 }
1396
1397 #[test]
1398 fn failed_revalidation_preserves_snapshot_with_visible_warning() {
1399 let tab = TabId::vendor(VendorId::Openrouter);
1400 let fetched_at = Utc.with_ymd_and_hms(2026, 5, 23, 12, 0, 0).unwrap();
1401 let mut app = App::with_theme(vec![tab.clone()], Theme::default());
1402 app.tabs[0] = ready_at(fetched_at);
1403
1404 assert!(app.begin_refresh(&tab));
1405 assert!(app.apply_refresh(app.tab_generation, &tab, TabState::error("refresh failed"),));
1406 assert!(!app.is_refreshing(&tab));
1407 match &app.tabs[0] {
1408 TabState::Ready(ready) => {
1409 assert_eq!(ready.fetched_at, Some(fetched_at));
1410 assert!(ready.stale);
1411 assert_eq!(ready.last_error, Some((0, "refresh failed".into())));
1412 }
1413 other => panic!("last successful snapshot was lost: {other:?}"),
1414 }
1415 let sections = crate::tui::panels::sections_for(&app.tabs[0], Utc::now(), 5);
1416 assert!(sections.iter().any(|section| matches!(
1417 section,
1418 crate::tui::panels::Section::Text { label, value }
1419 if label == "Warning" && value == "refresh failed"
1420 )));
1421 }
1422
1423 #[test]
1424 fn old_generation_result_does_not_clear_current_refresh() {
1425 let tab = TabId::vendor(VendorId::Openrouter);
1426 let mut app = App::with_theme(vec![tab.clone()], Theme::default());
1427 let old_generation = app.tab_generation;
1428 app.set_tabs(vec![tab.clone()]);
1429 assert!(app.begin_refresh(&tab));
1430
1431 assert!(!app.apply_refresh(old_generation, &tab, TabState::error("old result"),));
1432 assert!(app.is_refreshing(&tab));
1433 assert!(matches!(app.tabs[0], TabState::Loading));
1434 }
1435
1436 #[test]
1437 fn apply_refresh_stamps_fetched_at_on_only_the_matching_tab() {
1438 let anthropic = TabId::vendor(VendorId::Anthropic);
1444 let openai = TabId::vendor(VendorId::Openai);
1445 let mut app = App::with_theme(vec![anthropic.clone(), openai], Theme::default());
1446 let generation = app.tab_generation;
1447 let fetched_at = Utc.with_ymd_and_hms(2026, 5, 23, 12, 0, 0).unwrap();
1448
1449 assert!(app.apply_refresh(generation, &anthropic, ready_at(fetched_at)));
1450 match &app.tabs[0] {
1451 TabState::Ready(ready) => assert_eq!(ready.fetched_at, Some(fetched_at)),
1452 other => panic!("expected Anthropic tab Ready, got {other:?}"),
1453 }
1454 assert!(matches!(app.tabs[1], TabState::Loading));
1455 }
1456
1457 #[test]
1458 fn select_primary_lands_on_default_account_tab() {
1459 let app = {
1462 let tabs = tabs_from_config(&config_with_accounts(&["work"]));
1463 let mut a = App::with_theme(tabs, Theme::default());
1464 a.select_primary(Some(VendorId::Anthropic));
1465 a
1466 };
1467 assert_eq!(app.active, 0);
1468 assert_eq!(
1469 app.active_tab_id(),
1470 Some(&TabId::vendor(VendorId::Anthropic))
1471 );
1472 }
1473
1474 fn custom_spec(id: &str, enabled: bool) -> CustomProviderConfig {
1475 CustomProviderConfig {
1476 id: id.into(),
1477 name: "My Tool".into(),
1478 short_name: "myt".into(),
1479 enabled,
1480 ..Default::default()
1481 }
1482 }
1483
1484 #[test]
1485 fn custom_providers_get_tabs_after_every_builtin() {
1486 let config = Config {
1487 custom: vec![custom_spec("mytool", true), custom_spec("other", true)],
1488 ..Default::default()
1489 };
1490 let tabs = tabs_from_config(&config);
1491 let builtin_count = config.enabled_vendors().len();
1492 assert_eq!(tabs.len(), builtin_count + 2);
1493 assert!(
1494 tabs[..builtin_count]
1495 .iter()
1496 .all(|t| matches!(t.source, TabSource::Builtin(_)))
1497 );
1498 assert_eq!(tabs[builtin_count], TabId::custom(&config.custom[0]));
1499 assert_eq!(tabs[builtin_count + 1], TabId::custom(&config.custom[1]));
1500 assert_eq!(
1501 tabs[builtin_count].source,
1502 TabSource::Custom {
1503 id: "mytool".into(),
1504 name: "My Tool".into(),
1505 short_name: "myt".into(),
1506 }
1507 );
1508 assert!(tabs[builtin_count].account.is_none());
1509 assert!(!tabs[builtin_count].desktop);
1510 assert_eq!(tabs[builtin_count].vendor_id(), None);
1511 }
1512
1513 #[test]
1514 fn disabled_custom_provider_has_no_tab() {
1515 let config = Config {
1516 custom: vec![custom_spec("mytool", false)],
1517 ..Default::default()
1518 };
1519 let tabs = tabs_from_config(&config);
1520 assert!(
1521 tabs.iter()
1522 .all(|t| matches!(t.source, TabSource::Builtin(_)))
1523 );
1524 assert_eq!(tabs.len(), config.enabled_vendors().len());
1525 }
1526
1527 #[test]
1528 fn custom_tabs_are_listed_by_the_default_overview_but_not_by_a_vendor_filter() {
1529 let spec = custom_spec("mytool", true);
1530 let mut app = App::with_theme(
1531 vec![
1532 TabId::vendor(VendorId::Anthropic),
1533 TabId::custom(&spec),
1534 TabId::vendor(VendorId::Openai),
1535 ],
1536 Theme::default(),
1537 );
1538 assert_eq!(app.overview_tabs(), vec![0, 1, 2]);
1539
1540 app.overview_vendors = Some(vec![VendorId::Openai, VendorId::Anthropic]);
1542 assert_eq!(app.overview_tabs(), vec![2, 0]);
1543 }
1544
1545 #[test]
1546 fn a_custom_active_tab_has_no_vendor_and_never_staggers() {
1547 let spec = custom_spec("mytool", true);
1548 let tabs = vec![
1549 TabId::vendor(VendorId::Anthropic),
1550 TabId::custom(&spec),
1551 TabId::account("work"),
1552 ];
1553 let mut app = App::with_theme(tabs.clone(), Theme::default());
1554 app.active = 1;
1555 assert_eq!(app.active_vendor(), None);
1556 assert_eq!(app.active_tab_id(), Some(&TabId::custom(&spec)));
1557
1558 app.select_primary(Some(VendorId::Anthropic));
1560 assert_eq!(app.active, 0);
1561
1562 let step = Duration::from_millis(800);
1563 assert_eq!(
1564 refresh_stagger(&tabs, step),
1565 vec![Duration::ZERO, Duration::ZERO, step]
1566 );
1567 }
1568}