mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
codex: address PR review feedback (#28582)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use codex_core::config::Config;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::default_client::chatgpt_cloudflare_cookie_header;
|
||||
use codex_login::default_client::create_client;
|
||||
use codex_utils_plugins::plugin_service_routing::plugin_service_preview_enabled;
|
||||
use codex_utils_plugins::plugin_service_routing::plugin_service_routing_cookie;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::de::DeserializeOwned;
|
||||
@@ -9,18 +12,54 @@ use std::time::Duration;
|
||||
const OAI_PRODUCT_SKU_HEADER: &str = "OAI-Product-Sku";
|
||||
const CODEX_PRODUCT_SKU: &str = "codex";
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ChatgptRequestRouting {
|
||||
Default,
|
||||
PluginService,
|
||||
}
|
||||
|
||||
/// Make a GET request to the ChatGPT backend API.
|
||||
pub(crate) async fn chatgpt_get_request<T: DeserializeOwned>(
|
||||
config: &Config,
|
||||
path: String,
|
||||
) -> anyhow::Result<T> {
|
||||
chatgpt_get_request_with_timeout(config, path, /*timeout*/ None).await
|
||||
chatgpt_get_request_with_timeout_inner(
|
||||
config,
|
||||
path,
|
||||
/*timeout*/ None,
|
||||
ChatgptRequestRouting::Default,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn chatgpt_get_request_with_timeout<T: DeserializeOwned>(
|
||||
config: &Config,
|
||||
path: String,
|
||||
timeout: Option<Duration>,
|
||||
) -> anyhow::Result<T> {
|
||||
chatgpt_get_request_with_timeout_inner(config, path, timeout, ChatgptRequestRouting::Default)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn chatgpt_get_plugin_service_request_with_timeout<T: DeserializeOwned>(
|
||||
config: &Config,
|
||||
path: String,
|
||||
timeout: Option<Duration>,
|
||||
) -> anyhow::Result<T> {
|
||||
chatgpt_get_request_with_timeout_inner(
|
||||
config,
|
||||
path,
|
||||
timeout,
|
||||
ChatgptRequestRouting::PluginService,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn chatgpt_get_request_with_timeout_inner<T: DeserializeOwned>(
|
||||
config: &Config,
|
||||
path: String,
|
||||
timeout: Option<Duration>,
|
||||
routing: ChatgptRequestRouting,
|
||||
) -> anyhow::Result<T> {
|
||||
let chatgpt_base_url = &config.chatgpt_base_url;
|
||||
let auth_manager =
|
||||
@@ -52,6 +91,16 @@ pub(crate) async fn chatgpt_get_request_with_timeout<T: DeserializeOwned>(
|
||||
.header(OAI_PRODUCT_SKU_HEADER, CODEX_PRODUCT_SKU)
|
||||
.header("Content-Type", "application/json");
|
||||
|
||||
if matches!(routing, ChatgptRequestRouting::PluginService) && plugin_service_preview_enabled() {
|
||||
let cloudflare_cookie = chatgpt_cloudflare_cookie_header(&url);
|
||||
let existing_cookie_headers = cloudflare_cookie.as_deref().into_iter().collect::<Vec<_>>();
|
||||
if let Some(routing_cookie) =
|
||||
plugin_service_routing_cookie(&existing_cookie_headers, /*preview_enabled*/ true)
|
||||
{
|
||||
request = request.header("Cookie", routing_cookie);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(timeout) = timeout {
|
||||
request = request.timeout(timeout);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::chatgpt_client::chatgpt_get_request_with_timeout;
|
||||
use crate::chatgpt_client::chatgpt_get_plugin_service_request_with_timeout;
|
||||
|
||||
use codex_app_server_protocol::AppInfo;
|
||||
use codex_connectors::ConnectorDirectoryCacheContext;
|
||||
@@ -21,6 +21,7 @@ pub use codex_core::connectors::with_app_enabled_state;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_plugin::AppConnectorId;
|
||||
use codex_utils_plugins::plugin_service_routing::plugin_service_preview_enabled;
|
||||
|
||||
const DIRECTORY_CONNECTORS_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
|
||||
@@ -101,7 +102,7 @@ pub async fn list_all_connectors_with_options(
|
||||
auth.is_workspace_account(),
|
||||
force_refetch,
|
||||
|path| async move {
|
||||
chatgpt_get_request_with_timeout::<DirectoryListResponse>(
|
||||
chatgpt_get_plugin_service_request_with_timeout::<DirectoryListResponse>(
|
||||
config,
|
||||
path,
|
||||
Some(DIRECTORY_CONNECTORS_TIMEOUT),
|
||||
@@ -127,7 +128,8 @@ fn connector_directory_cache_context(
|
||||
auth.get_account_id(),
|
||||
auth.get_chatgpt_user_id(),
|
||||
auth.is_workspace_account(),
|
||||
),
|
||||
)
|
||||
.plugin_service_preview(plugin_service_preview_enabled()),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user