Files
codex/codex-rs/app-server-client/src/cloud_backend/auth.rs
T
Benjamin Carlsson b016cd1847 Enable automatic titles for Cloud conversations (#61600)
## Why

Cloud conversations previously skipped TUI title generation, leaving them without automatically saved names.

## What changed

- Generate structured titles using the selected Cloud account and its backend routing, without agent tools or a temporary conversation.
- Read and save names outside the conversation command queue without replacing the active attachment. Preserve an existing name if it no longer matches the expected value.
- Fall back to the first-message title when generation is unavailable, and allow up to three seconds for pending saves during shutdown.
- Report a retryable error when a manual rename encounters an automatic save in progress, keeping the UI responsive.

## Testing

Add coverage for selected-account title generation, saved-name reads without attachment, first-message fallback persistence, and manual rename retries after automatic saves.

GitOrigin-RevId: 48030cc0b75e790a2004af018f54e5751665b760
2026-11-15 03:17:50 +00:00

72 lines
2.6 KiB
Rust

//! Opens the internal Cloud preview with the selected ChatGPT credentials and local transport policy.
use super::CloudTitleClient;
use super::start_worker;
use crate::AppServerClient;
use crate::legacy_core::config::Config;
use codex_app_server_protocol as protocol;
use codex_cloud_client as cloud;
use codex_login::token_data::parse_jwt_expiration;
use codex_protocol::account::PlanType;
use color_eyre::eyre::Result;
use color_eyre::eyre::bail;
use color_eyre::eyre::eyre;
const ORIGIN: &str = "https://codex-cloud-backend.chatgpt.com";
pub async fn connect(config: &Config) -> Result<AppServerClient> {
// The preview borrows Local's policy without owning credential updates.
let factory = config.http_client_factory();
let policy = factory.network_policy().clone().for_current_account();
let factory = factory.with_network_policy(policy);
let storage = config.auth_config();
let auth = storage
.load_auth(/*enable_codex_api_key_env*/ false)
.await?
.ok_or_else(|| eyre!("Sign in with ChatGPT and reopen Codex to use Cloud."))?;
if !auth.is_chatgpt_auth() || auth.is_fedramp_account() {
bail!("This account is not supported by the cloud conversation preview.");
}
let account_id = auth
.get_account_id()
.ok_or_else(|| eyre!("Cloud requires a selected account."))?;
let token = auth.get_token()?;
if let Ok(Some(expires)) = parse_jwt_expiration(&token)
&& std::time::SystemTime::from(expires) <= std::time::SystemTime::now()
{
bail!("Your ChatGPT credential expired. Reopen Codex to reconnect.");
}
let origin = ORIGIN.parse()?;
let permit = factory.network_policy().acquire(&origin)?;
let credentials = cloud::Credentials::new(&token, &account_id)?;
let client = cloud::Client::new(&factory, ORIGIN, credentials)?;
let title_client = CloudTitleClient::new(
factory,
&auth,
account_id.clone(),
config.chatgpt_backend_url(),
)
.ok();
Ok(start_worker(
client,
super::idle::Login {
storage,
mode: auth.api_auth_mode(),
token,
account: account_id,
permit,
},
protocol::GetAccountResponse {
user_id: auth.get_chatgpt_user_id(),
account: Some(protocol::Account::Chatgpt {
email: auth.get_account_email(),
plan_type: auth.account_plan_type().unwrap_or(PlanType::Unknown),
workspace_name: None,
}),
requires_openai_auth: true,
workspace_routing: None,
},
title_client,
))
}