mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## Why Workspace headline request counters restart when the chat widget is replaced, allowing a response for the previous widget to match a new pending request. Archived headlines can also be selected for the status line. ## What changed - Use UUIDs for workspace headline requests and reject refresh events and responses that do not match the current widget's pending request. - Skip archived messages when selecting the first non-empty workspace headline. ## Testing Add a regression test verifying that a replacement widget rejects the previous widget's response while retaining its own pending request. Extend headline selection coverage to include an archived headline before the active one. GitOrigin-RevId: 44b98ab8c6cb70b7cf8e8b9341f27c99c1e1490a
355 lines
15 KiB
Rust
355 lines
15 KiB
Rust
//! Construction and initial wiring for `ChatWidget`.
|
|
|
|
use super::*;
|
|
|
|
impl ChatWidget {
|
|
pub(crate) fn new_with_app_event(common: ChatWidgetInit) -> Self {
|
|
let mut widget = Self::new_with_op_target(common, CodexOpTarget::AppEvent);
|
|
widget.bottom_pane.enable_agents_navigation();
|
|
widget
|
|
}
|
|
|
|
pub(super) fn new_with_op_target(
|
|
common: ChatWidgetInit,
|
|
codex_op_target: CodexOpTarget,
|
|
) -> Self {
|
|
let ChatWidgetInit {
|
|
config,
|
|
local_settings,
|
|
frame_requester,
|
|
app_event_tx,
|
|
workspace_command_runner,
|
|
initial_user_message,
|
|
enhanced_keys_supported,
|
|
has_chatgpt_account,
|
|
requires_openai_auth,
|
|
has_codex_backend_auth,
|
|
model_catalog,
|
|
feedback,
|
|
is_first_run,
|
|
status_account_display,
|
|
initial_plan_type,
|
|
model,
|
|
startup_tooltip_override,
|
|
status_line_invalid_items_warned,
|
|
terminal_title_invalid_items_warned,
|
|
session_telemetry,
|
|
} = common;
|
|
// Keep asynchronous widget callbacks scoped separately from the app and other widgets.
|
|
let app_event_tx = AppEventSender::new(app_event_tx.app_event_tx);
|
|
let model = model.filter(|m| !m.trim().is_empty());
|
|
let mut config = config;
|
|
config.model = model.clone();
|
|
let prevent_idle_sleep = config.features.enabled(Feature::PreventIdleSleep);
|
|
let placeholder = PLACEHOLDER.to_string();
|
|
let side_placeholder = SIDE_PLACEHOLDER.to_string();
|
|
|
|
let model_override = model.as_deref();
|
|
let model_for_header = model
|
|
.clone()
|
|
.unwrap_or_else(|| DEFAULT_MODEL_DISPLAY_NAME.to_string());
|
|
let active_collaboration_mask =
|
|
Self::initial_collaboration_mask(&config, model_catalog.as_ref(), model_override);
|
|
let header_model = active_collaboration_mask
|
|
.as_ref()
|
|
.and_then(|mask| mask.model.clone())
|
|
.unwrap_or_else(|| model_for_header.clone());
|
|
let fallback_default = Settings {
|
|
model: header_model.clone(),
|
|
reasoning_effort: None,
|
|
developer_instructions: None,
|
|
};
|
|
// Collaboration modes start in Default mode.
|
|
let current_collaboration_mode = CollaborationMode {
|
|
mode: ModeKind::Default,
|
|
settings: fallback_default,
|
|
};
|
|
|
|
let empty_state_animation = crate::empty_state_animation::EmptyStateAnimation::default();
|
|
let header = Self::placeholder_session_header_cell(&config);
|
|
let active_cell = Some(header);
|
|
|
|
let current_cwd = Some(config.cwd.to_path_buf());
|
|
let effective_service_tier = crate::service_tier_resolution::effective_service_tier(
|
|
&config,
|
|
&local_settings.notices,
|
|
&header_model,
|
|
&model_catalog.try_list_models().unwrap_or_default(),
|
|
);
|
|
let runtime_keymap = RuntimeKeymap::for_session(
|
|
&local_settings.tui.keymap,
|
|
local_settings.workspace_enabled(&config),
|
|
)
|
|
.ok();
|
|
let default_keymap = RuntimeKeymap::defaults();
|
|
let copy_last_response_binding = runtime_keymap
|
|
.as_ref()
|
|
.map(|keymap| keymap.app.copy.clone())
|
|
.unwrap_or_else(|| default_keymap.app.copy.clone());
|
|
let chat_keymap = runtime_keymap
|
|
.as_ref()
|
|
.map(|keymap| keymap.chat.clone())
|
|
.unwrap_or_else(|| default_keymap.chat.clone());
|
|
let pet_http_client = codex_http_client::RouteAwareClientPool::new(
|
|
config.http_client_factory(),
|
|
codex_http_client::ClientRouteClass::Other,
|
|
);
|
|
let configured_pet_load_generation = pets::start_configured_pet_load_if_needed(
|
|
&local_settings,
|
|
/*ambient_pet_missing*/ true,
|
|
frame_requester.clone(),
|
|
app_event_tx.clone(),
|
|
pet_http_client.clone(),
|
|
);
|
|
let config_panel_tui = local_settings.tui.clone();
|
|
let mut widget = Self {
|
|
empty_state_animation: std::cell::RefCell::new(empty_state_animation),
|
|
daybreak_enabled: false,
|
|
app_event_tx: app_event_tx.clone(),
|
|
frame_requester: frame_requester.clone(),
|
|
codex_op_target,
|
|
bottom_pane: BottomPane::new(BottomPaneParams {
|
|
frame_requester,
|
|
app_event_tx,
|
|
has_input_focus: true,
|
|
enhanced_keys_supported,
|
|
placeholder_text: placeholder.clone(),
|
|
disable_paste_burst: local_settings.tui.disable_paste_burst.unwrap_or(false),
|
|
animations_enabled: local_settings.tui.animations,
|
|
effects: local_settings.tui.effects,
|
|
skills: None,
|
|
}),
|
|
transcript: TranscriptState::new(active_cell),
|
|
raw_output_mode: local_settings.tui.raw_output_mode,
|
|
config,
|
|
local_settings,
|
|
config_panel_tui,
|
|
effective_service_tier,
|
|
skills_all: Vec::new(),
|
|
skills_initial_state: None,
|
|
current_collaboration_mode,
|
|
active_collaboration_mask,
|
|
has_chatgpt_account,
|
|
requires_openai_auth,
|
|
has_codex_backend_auth,
|
|
model_catalog,
|
|
model_popup_request_id: None,
|
|
cloud_picker_selection: None,
|
|
pending_cloud_turn_settings: None,
|
|
permission_popup_pending: false,
|
|
permission_popup_request_id: None,
|
|
permission_discovery: None,
|
|
inline_permission_profile_selection: None,
|
|
worktree_popup_request_id: None,
|
|
permission_profiles_menu_opened: false,
|
|
model_popup_model_ids: Vec::new(),
|
|
session_telemetry,
|
|
session_header: SessionHeader::new(header_model),
|
|
initial_user_message,
|
|
status_account_display,
|
|
remote_connection: None,
|
|
snapshot_local_images: false,
|
|
thread_settings_owner: crate::app_server_session::ThreadSettingsOwner::Client,
|
|
pending_image_submission: None,
|
|
local_worktree_operations: true,
|
|
windows_sandbox_local_server: false,
|
|
windows_sandbox_config: Default::default(),
|
|
windows_sandbox_host: crate::app::WindowsSandboxHost::Unknown,
|
|
#[cfg(any(target_os = "windows", test))]
|
|
windows_sandbox_elevated_setup_complete: false,
|
|
token_info: None,
|
|
token_usage_pending: false,
|
|
rate_limit_snapshots_by_limit_id: BTreeMap::new(),
|
|
refreshing_status_outputs: Vec::new(),
|
|
next_status_refresh_request_id: 0,
|
|
pending_rate_limit_reset_request_id: None,
|
|
pending_rate_limit_reset_idempotency_key: None,
|
|
rate_limit_reset_picker_request_id: None,
|
|
pending_rate_limit_reset_hint_request_id: None,
|
|
pending_usage_menu_rate_limit_request_id: None,
|
|
pending_rate_limit_reset_hint: None,
|
|
available_rate_limit_reset_credits: None,
|
|
next_rate_limit_reset_request_id: 0,
|
|
plan_type: initial_plan_type,
|
|
codex_rate_limit_reached_type: None,
|
|
codex_spend_control_reached: None,
|
|
rate_limit_warnings: RateLimitWarningState::default(),
|
|
clock_format: crate::clock_format::ClockFormat::system(),
|
|
usage_notice_state: usage_notice::UsageNoticeState::default(),
|
|
backend_banner_state: backend_banners::BackendBannerState::default(),
|
|
security_setup_request_id: uuid::Uuid::new_v4(),
|
|
security_setup_presented: false,
|
|
security_setup_identity: None,
|
|
security_setup_dismissed: false,
|
|
automatic_model_switch_state: backend_banners::AutomaticModelSwitchState::default(),
|
|
backend_banner_notice_model: None,
|
|
luna_reserve_notice_account_id: None,
|
|
warning_display_state: WarningDisplayState::default(),
|
|
composer_images: None,
|
|
rendered_selection: Default::default(),
|
|
rate_limit_switch_prompt: RateLimitSwitchPromptState::default(),
|
|
add_credits_nudge_email_in_flight: None,
|
|
adaptive_chunking: AdaptiveChunkingPolicy::default(),
|
|
stream_controller: None,
|
|
plan_stream_controller: None,
|
|
pending_stream_consolidations: 0,
|
|
pending_clipboard: None,
|
|
suppress_image_paste_until: Instant::now(),
|
|
copy_last_response_binding,
|
|
running_commands: HashMap::new(),
|
|
collab_agent_metadata: HashMap::new(),
|
|
pending_collab_spawn_requests: HashMap::new(),
|
|
suppressed_exec_calls: HashSet::new(),
|
|
last_unified_wait: None,
|
|
unified_exec_wait_streak: None,
|
|
turn_lifecycle: TurnLifecycleState::new(prevent_idle_sleep),
|
|
safety_recourse: None,
|
|
realtime_conversation: RealtimeConversationUiState::default(),
|
|
realtime_conversation_available_for_thread: false,
|
|
safety_buffering: SafetyBufferingState::default(),
|
|
task_complete_pending: false,
|
|
unified_exec_processes: Vec::new(),
|
|
pending_terminal_restore: None,
|
|
mcp_startup_status: None,
|
|
mcp_startup_last_diagnostics: HashMap::new(),
|
|
connectors: ConnectorsState::default(),
|
|
ide_context: IdeContextState::default(),
|
|
plugins_cache: PluginsCacheState::default(),
|
|
plugins_fetch_state: PluginListFetchState::default(),
|
|
plugin_remote_sections_loading: false,
|
|
plugin_remote_sections_loaded: false,
|
|
plugin_remote_section_errors: Vec::new(),
|
|
plugin_install_apps_needing_auth: Vec::new(),
|
|
plugin_install_auth_flow: None,
|
|
plugins_active_tab_id: None,
|
|
newly_installed_marketplace_tab_id: None,
|
|
interrupts: InterruptManager::new(),
|
|
reasoning_buffer: String::new(),
|
|
reasoning_header: None,
|
|
reasoning_summary_parts: Vec::new(),
|
|
status_state: StatusState::default(),
|
|
review: ReviewState::default(),
|
|
active_hook_cell: None,
|
|
pet_http_client,
|
|
ambient_pet: None,
|
|
configured_pet_load_generation,
|
|
pet_picker_preview_state: crate::pets::PetPickerPreviewState::default(),
|
|
pet_picker_preview_pet: None,
|
|
pet_picker_preview_request_id: 0,
|
|
pet_picker_preview_image_visible: std::cell::Cell::new(/*value*/ false),
|
|
pet_selection_load_request_id: 0,
|
|
#[cfg(test)]
|
|
pet_image_support_override: None,
|
|
thread_id: None,
|
|
thread_name: None,
|
|
thread_rename_block_message: None,
|
|
active_side_conversation: false,
|
|
blocks_direct_input: false,
|
|
external_writer_view: false,
|
|
read_only_history: false,
|
|
thread_settings_confirmed: false,
|
|
provider_error: None,
|
|
fork_in_progress: false,
|
|
misalignment_policy_violation: None,
|
|
normal_placeholder_text: placeholder,
|
|
side_placeholder_text: side_placeholder,
|
|
forked_from: None,
|
|
interrupted_turn_notice_mode: InterruptedTurnNoticeMode::Default,
|
|
input_queue: InputQueueState::default(),
|
|
thread_stream_disconnected: false,
|
|
safety_buffering_prompt: None,
|
|
safety_buffering_source: UserMessageSource::Prompt,
|
|
chat_keymap,
|
|
permission_shortcut_pending: false,
|
|
show_welcome_banner: is_first_run,
|
|
startup_tooltip_override,
|
|
suppress_session_configured_redraw: false,
|
|
suppress_initial_user_message_submit: false,
|
|
pending_notification: None,
|
|
quit_shortcut_expires_at: None,
|
|
new_backend_label: None,
|
|
quick_dial_menu: false,
|
|
quick_dial_menu_key_guard: None,
|
|
quit_shortcut_key: None,
|
|
turn_runtime_metrics: RuntimeMetricsSummary::default(),
|
|
last_rendered_width: std::cell::Cell::new(None),
|
|
feedback,
|
|
current_rollout_path: None,
|
|
current_cwd,
|
|
primary_environment_cwd: None,
|
|
workspace_command_runner,
|
|
instruction_source_paths: Vec::new(),
|
|
session_network_proxy: None,
|
|
status_line_invalid_items_warned,
|
|
terminal_title_invalid_items_warned,
|
|
last_terminal_title: None,
|
|
last_terminal_title_requires_action: false,
|
|
terminal_title_setup_original_items: None,
|
|
status_surface_overrides: StatusSurfaceOverrides::default(),
|
|
terminal_title_animation_origin: Instant::now(),
|
|
terminal_title_next_refresh: None,
|
|
status_line_project_root_name_cache: None,
|
|
status_line_branch: None,
|
|
status_line_branch_cwd: None,
|
|
status_line_branch_pending: false,
|
|
status_line_branch_lookup_complete: false,
|
|
status_line_git_summary: None,
|
|
status_line_git_summary_cwd: None,
|
|
status_line_git_summary_pending: false,
|
|
status_line_git_summary_lookup_complete: false,
|
|
status_line_workspace_headline: None,
|
|
status_line_workspace_headline_pending_request_id: None,
|
|
status_line_workspace_headline_last_requested_at: None,
|
|
status_line_workspace_messages_disabled: false,
|
|
thread_usage: thread_usage::ThreadUsageState::default(),
|
|
current_goal_status_indicator: None,
|
|
current_goal_status: None,
|
|
external_editor_state: ExternalEditorState::Closed,
|
|
last_rendered_user_message_display: None,
|
|
last_rendered_user_message_client_id: None,
|
|
last_non_retry_error: None,
|
|
#[cfg(test)]
|
|
test_codex_home: None,
|
|
};
|
|
|
|
widget.bottom_pane.set_mention_usage_home(
|
|
widget.local_settings.codex_home.as_path(),
|
|
widget.local_settings.history.persistence,
|
|
);
|
|
widget.prefetch_rate_limits();
|
|
if let Some(keymap) = runtime_keymap {
|
|
widget.bottom_pane.set_keymap_bindings(&keymap);
|
|
}
|
|
if widget.local_settings.tui.vim_mode_default {
|
|
widget.bottom_pane.enable_vim_in_insert_mode();
|
|
} else {
|
|
widget.bottom_pane.set_vim_enabled(/*enabled*/ false);
|
|
}
|
|
widget
|
|
.bottom_pane
|
|
.set_status_line_enabled(!widget.configured_status_line_items().is_empty());
|
|
widget
|
|
.bottom_pane
|
|
.set_collaboration_modes_enabled(/*enabled*/ true);
|
|
widget.sync_service_tier_commands();
|
|
widget.sync_worktrees_enabled();
|
|
widget.sync_plugins_command_enabled();
|
|
widget.sync_goal_command_enabled();
|
|
widget
|
|
.bottom_pane
|
|
.set_voice_command_enabled(/*enabled*/ false);
|
|
widget.sync_mentions_v2_enabled();
|
|
widget.update_collaboration_mode_indicator();
|
|
|
|
widget
|
|
.bottom_pane
|
|
.set_connectors_enabled(widget.connectors_enabled());
|
|
widget
|
|
.bottom_pane
|
|
.set_token_activity_command_enabled(widget.has_codex_backend_auth);
|
|
widget.refresh_status_surfaces();
|
|
|
|
widget
|
|
}
|
|
}
|