mirror of
https://github.com/openai/codex.git
synced 2026-11-28 07:32:19 +00:00
Show actionable rate-limit banners in the TUI (#41742)
## What changed - Carry optional backend-owned banner and account identity data through `account/rateLimits/read`, filtering banners that do not match the authenticated account and user. - Render supported rate-limit notices above the composer with actions for usage, credits, resets, owner notifications, and plan management while preserving the existing fallback UI for absent or unsupported banners. - Refresh usage after limit errors, reject stale responses, and keep queued input paused until recovery completes. When instructed by the banner, switch to the first available fallback model without changing unrelated thread settings. ## Testing - Add protocol, banner parsing and rendering, CTA, identity filtering, refresh ordering, fallback-model, account-change, and queued-input recovery coverage. GitOrigin-RevId: e03d75a82e425deb87f4b120a71cf2286c0ef6cc
This commit is contained in:
1 parent
94cbbddafc
commit
79b04f1ab5
69 files changed
+3454
-69
No files matched your search
@@ -13,6 +13,8 @@
|
||||
//!
|
||||
//! Some UI is time-based rather than input-based, such as the transient "press again to quit"
|
||||
//! hint. The pane schedules redraws so those hints can expire even when the UI is otherwise idle.
|
||||
//! Inline banners sit above the composer. Number shortcuts apply only to an empty, idle composer;
|
||||
//! drafts, paste bursts, and active dialogs keep their normal input routing.
|
||||
use std::collections::VecDeque;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -55,6 +57,7 @@ use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
mod action_required_title;
|
||||
mod actionable_banner;
|
||||
mod app_link_view;
|
||||
mod apply_patch_header;
|
||||
mod approval_overlay;
|
||||
@@ -67,6 +70,8 @@ mod status_surface_preview;
|
||||
mod title_setup;
|
||||
pub(crate) use action_required_title::ACTION_REQUIRED_PREVIEW_PREFIX;
|
||||
pub(crate) use action_required_title::build_action_required_title_text;
|
||||
pub(crate) use actionable_banner::ActionableBanner;
|
||||
pub(crate) use actionable_banner::BannerDismissal;
|
||||
pub(crate) use app_link_view::AppLinkElicitationTarget;
|
||||
pub(crate) use app_link_view::AppLinkSuggestionType;
|
||||
pub(crate) use app_link_view::AppLinkView;
|
||||
@@ -243,6 +248,7 @@ pub(crate) struct BottomPane {
|
||||
|
||||
/// Inline status indicator shown above the composer while a task is running.
|
||||
status: Option<StatusIndicatorWidget>,
|
||||
inline_banner: Option<actionable_banner::InlineBanner>,
|
||||
/// Unified exec session summary source.
|
||||
///
|
||||
/// When a status row exists, this summary is mirrored inline in that row;
|
||||
@@ -313,6 +319,7 @@ impl BottomPane {
|
||||
disable_paste_burst,
|
||||
is_task_running: false,
|
||||
status: None,
|
||||
inline_banner: None,
|
||||
unified_exec_footer: UnifiedExecFooter::new(),
|
||||
pending_input_preview: PendingInputPreview::new(),
|
||||
pending_thread_approvals: PendingThreadApprovals::new(),
|
||||
@@ -691,6 +698,9 @@ impl BottomPane {
|
||||
self.request_redraw();
|
||||
InputResult::None
|
||||
} else {
|
||||
if self.handle_inline_banner_key(key_event) {
|
||||
return InputResult::None;
|
||||
}
|
||||
// If a task is running and a status line is visible, allow the
|
||||
// configured action to interrupt even while the composer has focus.
|
||||
// When a popup is active, prefer dismissing it over interrupting the task.
|
||||
@@ -1461,7 +1471,10 @@ impl BottomPane {
|
||||
/// overlays or popups and not running a task. This is the safe context to
|
||||
/// use Esc-Esc for backtracking from the main view.
|
||||
pub(crate) fn is_normal_backtrack_mode(&self) -> bool {
|
||||
!self.is_task_running && self.view_stack.is_empty() && !self.composer.popup_active()
|
||||
!self.is_task_running
|
||||
&& self.view_stack.is_empty()
|
||||
&& !self.composer.popup_active()
|
||||
&& !self.inline_banner_accepts_dismissal()
|
||||
}
|
||||
|
||||
/// Return true when no popups or modal views are active, regardless of task state.
|
||||
@@ -1815,10 +1828,22 @@ impl BottomPane {
|
||||
&'_ self,
|
||||
composer_right_reserve: u16,
|
||||
) -> RenderableItem<'_> {
|
||||
if (self.is_task_running || !self.view_stack.is_empty())
|
||||
&& let Some(banner) = &self.inline_banner
|
||||
{
|
||||
banner.visible.set(false);
|
||||
}
|
||||
if let Some(view) = self.active_view() {
|
||||
RenderableItem::Borrowed(view)
|
||||
} else {
|
||||
let mut flex = FlexRenderable::new();
|
||||
if let Some(banner) = self
|
||||
.inline_banner
|
||||
.as_ref()
|
||||
.filter(|_| !self.is_task_running)
|
||||
{
|
||||
flex.push(/*flex*/ 0, RenderableItem::Borrowed(banner));
|
||||
}
|
||||
if let Some(status) = &self.status {
|
||||
flex.push(/*flex*/ 0, RenderableItem::Borrowed(status));
|
||||
}
|
||||
@@ -1952,6 +1977,9 @@ impl Renderable for BottomPane {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[path = "actionable_banner_tests.rs"]
|
||||
mod actionable_banner_tests;
|
||||
|
||||
use super::*;
|
||||
use crate::app::app_server_requests::ResolvedAppServerRequest;
|
||||
use crate::app_command::AppCommand as Op;
|
||||
@@ -2030,6 +2058,93 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_banner_snapshot() {
|
||||
let (tx, _rx) = unbounded_channel();
|
||||
let mut pane = test_pane(AppEventSender::new(tx));
|
||||
pane.set_inline_banner(Some(ActionableBanner {
|
||||
title: "Choose how to continue working".to_string(),
|
||||
description: "A long description wraps to fit the available terminal width.\n"
|
||||
.repeat(/*n*/ 8),
|
||||
actions: vec![
|
||||
SelectionItem {
|
||||
name: "Open usage settings".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
SelectionItem {
|
||||
name: "Notify owner".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
}));
|
||||
let width = 44;
|
||||
let area = Rect::new(
|
||||
/*x*/ 0,
|
||||
/*y*/ 0,
|
||||
width,
|
||||
pane.desired_height(width),
|
||||
);
|
||||
assert_snapshot!(
|
||||
"inline_banner_wrapped_and_truncated",
|
||||
render_snapshot(&pane, area)
|
||||
);
|
||||
assert!(!pane.is_normal_backtrack_mode());
|
||||
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
|
||||
assert!(pane.is_normal_backtrack_mode());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backend_banner_snapshots_and_numbered_actions() {
|
||||
for (kind, action, label) in [
|
||||
("personal_limit", "view_usage", "View usage"),
|
||||
("workspace_member_credits", "notify_owner", "Notify owner"),
|
||||
] {
|
||||
let banner = crate::backend_banners::BackendBanner::parse(&serde_json::json!({
|
||||
"banner_type": kind,
|
||||
"presentation": "dismissible",
|
||||
"title": "Usage limit\u{7} reached",
|
||||
"description": "Your included usage is depleted.\nChoose an action to continue.",
|
||||
"ctas": [
|
||||
{"action": "unsupported", "label": "Hidden action"},
|
||||
{"action": "view_usage", "label": "Open usage settings"},
|
||||
{"action": action, "label": label},
|
||||
{"action": "view_usage", "label": "Extra action"}
|
||||
]
|
||||
}))
|
||||
.expect("valid optional banner");
|
||||
let (tx, mut rx) = unbounded_channel();
|
||||
let mut pane = test_pane(AppEventSender::new(tx));
|
||||
pane.set_inline_banner(Some(banner.actionable_banner()));
|
||||
let width = 44;
|
||||
let area = Rect::new(
|
||||
/*x*/ 0,
|
||||
/*y*/ 0,
|
||||
width,
|
||||
pane.desired_height(width),
|
||||
);
|
||||
assert_snapshot!(
|
||||
format!("backend_banner_{kind}"),
|
||||
render_snapshot(&pane, area)
|
||||
);
|
||||
pane.handle_key_event(KeyEvent::new(KeyCode::Char('2'), KeyModifiers::NONE));
|
||||
let selected = match rx.try_recv().expect("numbered CTA dispatch") {
|
||||
AppEvent::OpenUrlInBrowser { url } => url,
|
||||
AppEvent::SendAddCreditsNudgeEmail { credit_type } => format!("{credit_type:?}"),
|
||||
other => panic!("unexpected banner action: {other:?}"),
|
||||
};
|
||||
assert_eq!(
|
||||
selected,
|
||||
if action == "view_usage" {
|
||||
"https://chatgpt.com/codex/settings/usage"
|
||||
} else {
|
||||
"Credits"
|
||||
}
|
||||
);
|
||||
assert!(pane.inline_banner.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct DismissibleView {
|
||||
id: Option<&'static str>,
|
||||
|
||||
Reference in new issue
Block a user