mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Add a gated Cloud backend to the TUI (#59828)
## What changed - Register an additional Cloud connection on supported macOS and Linux launches when `TuiMultiBackend` is enabled, using the selected ChatGPT account and local network policy. - Preserve backend settings and identify Cloud in connection controls and status. - Let Cloud supply the model when a thread opens, skip local skills requests and stale results, and allow resume without a local working-directory override. - Preserve Git metadata in Cloud thread snapshots and continue history hydration past empty filtered pages within the scan budget. - Report Cloud connection failures and require reopening Codex to reconnect. ## Testing Add regression coverage for Cloud model bootstrap, skipped skills requests, resume directory handling, history pagination through filtered pages, and Git metadata preservation. GitOrigin-RevId: 6717f0f5ad7708c5e9b5796d94711dd1eecc49bb
This commit is contained in:
committed by
copyberry
parent
a037e65ead
commit
7b8d67e456
@@ -0,0 +1,53 @@
|
||||
//! Opens the internal Cloud preview with the selected ChatGPT credentials and local transport policy.
|
||||
|
||||
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 auth = config
|
||||
.auth_config()
|
||||
.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.");
|
||||
}
|
||||
factory.network_policy().acquire(&ORIGIN.parse()?)?;
|
||||
let credentials = cloud::Credentials::new(&token, &account_id)?;
|
||||
let client = cloud::Client::new(&factory, ORIGIN, credentials)?;
|
||||
Ok(start_worker(
|
||||
client,
|
||||
protocol::GetAccountResponse {
|
||||
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,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Adapts native Cloud requests and the currently open conversation’s reply stream.
|
||||
//! A replacement becomes active only after its native attachment opens successfully.
|
||||
|
||||
mod auth;
|
||||
mod events;
|
||||
mod requests;
|
||||
|
||||
@@ -19,6 +20,8 @@ use futures::stream::BoxStream;
|
||||
use serde_json::Value;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
pub use auth::connect;
|
||||
|
||||
type ReplyStream = BoxStream<'static, Result<cloud::Event, cloud::Error>>;
|
||||
|
||||
/// Rejected locally before an admission request can be sent.
|
||||
@@ -144,7 +147,7 @@ impl Replies {
|
||||
}
|
||||
|
||||
/// Opens an app-server client backed by the authenticated native Cloud client.
|
||||
pub fn connect(client: cloud::Client, account: protocol::GetAccountResponse) -> AppServerClient {
|
||||
fn start_worker(client: cloud::Client, account: protocol::GetAccountResponse) -> AppServerClient {
|
||||
let (app_client, commands, output) = CloudClient::channel(/*capacity*/ 32);
|
||||
let mut requests = requests::Requests {
|
||||
client,
|
||||
|
||||
Reference in New Issue
Block a user