fix: prefer config var to env var (#2495)
This commit is contained in:
@@ -208,11 +208,7 @@ impl ModelClient {
|
|||||||
req_builder = req_builder.header("chatgpt-account-id", account_id);
|
req_builder = req_builder.header("chatgpt-account-id", account_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let originator = self
|
let originator = &self.config.responses_originator_header;
|
||||||
.config
|
|
||||||
.internal_originator
|
|
||||||
.as_deref()
|
|
||||||
.unwrap_or("codex_cli_rs");
|
|
||||||
req_builder = req_builder.header("originator", originator);
|
req_builder = req_builder.header("originator", originator);
|
||||||
req_builder = req_builder.header("User-Agent", get_codex_user_agent(Some(originator)));
|
req_builder = req_builder.header("User-Agent", get_codex_user_agent(Some(originator)));
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use crate::model_provider_info::built_in_model_providers;
|
|||||||
use crate::openai_model_info::get_model_info;
|
use crate::openai_model_info::get_model_info;
|
||||||
use crate::protocol::AskForApproval;
|
use crate::protocol::AskForApproval;
|
||||||
use crate::protocol::SandboxPolicy;
|
use crate::protocol::SandboxPolicy;
|
||||||
use crate::spawn::CODEX_ORIGINATOR_ENV_VAR;
|
|
||||||
use codex_login::AuthMode;
|
use codex_login::AuthMode;
|
||||||
use codex_protocol::config_types::ReasoningEffort;
|
use codex_protocol::config_types::ReasoningEffort;
|
||||||
use codex_protocol::config_types::ReasoningSummary;
|
use codex_protocol::config_types::ReasoningSummary;
|
||||||
@@ -36,6 +35,8 @@ pub(crate) const PROJECT_DOC_MAX_BYTES: usize = 32 * 1024; // 32 KiB
|
|||||||
|
|
||||||
const CONFIG_TOML_FILE: &str = "config.toml";
|
const CONFIG_TOML_FILE: &str = "config.toml";
|
||||||
|
|
||||||
|
const DEFAULT_RESPONSES_ORIGINATOR_HEADER: &str = "codex_cli_rs";
|
||||||
|
|
||||||
/// Application configuration loaded from disk and merged with overrides.
|
/// Application configuration loaded from disk and merged with overrides.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@@ -164,7 +165,7 @@ pub struct Config {
|
|||||||
pub include_apply_patch_tool: bool,
|
pub include_apply_patch_tool: bool,
|
||||||
|
|
||||||
/// The value for the `originator` header included with Responses API requests.
|
/// The value for the `originator` header included with Responses API requests.
|
||||||
pub internal_originator: Option<String>,
|
pub responses_originator_header: String,
|
||||||
|
|
||||||
/// If set to `true`, the API key will be signed with the `originator` header.
|
/// If set to `true`, the API key will be signed with the `originator` header.
|
||||||
pub preferred_auth_method: AuthMode,
|
pub preferred_auth_method: AuthMode,
|
||||||
@@ -411,7 +412,7 @@ pub struct ConfigToml {
|
|||||||
pub experimental_instructions_file: Option<PathBuf>,
|
pub experimental_instructions_file: Option<PathBuf>,
|
||||||
|
|
||||||
/// The value for the `originator` header included with Responses API requests.
|
/// The value for the `originator` header included with Responses API requests.
|
||||||
pub internal_originator: Option<String>,
|
pub responses_originator_header_internal_override: Option<String>,
|
||||||
|
|
||||||
pub projects: Option<HashMap<String, ProjectConfig>>,
|
pub projects: Option<HashMap<String, ProjectConfig>>,
|
||||||
|
|
||||||
@@ -626,9 +627,9 @@ impl Config {
|
|||||||
let include_apply_patch_tool_val =
|
let include_apply_patch_tool_val =
|
||||||
include_apply_patch_tool.unwrap_or(model_family.uses_apply_patch_tool);
|
include_apply_patch_tool.unwrap_or(model_family.uses_apply_patch_tool);
|
||||||
|
|
||||||
let originator = std::env::var(CODEX_ORIGINATOR_ENV_VAR)
|
let responses_originator_header: String = cfg
|
||||||
.ok()
|
.responses_originator_header_internal_override
|
||||||
.or(cfg.internal_originator);
|
.unwrap_or(DEFAULT_RESPONSES_ORIGINATOR_HEADER.to_owned());
|
||||||
|
|
||||||
let config = Self {
|
let config = Self {
|
||||||
model,
|
model,
|
||||||
@@ -683,7 +684,7 @@ impl Config {
|
|||||||
experimental_resume,
|
experimental_resume,
|
||||||
include_plan_tool: include_plan_tool.unwrap_or(false),
|
include_plan_tool: include_plan_tool.unwrap_or(false),
|
||||||
include_apply_patch_tool: include_apply_patch_tool_val,
|
include_apply_patch_tool: include_apply_patch_tool_val,
|
||||||
internal_originator: originator,
|
responses_originator_header,
|
||||||
preferred_auth_method: cfg.preferred_auth_method.unwrap_or(AuthMode::ChatGPT),
|
preferred_auth_method: cfg.preferred_auth_method.unwrap_or(AuthMode::ChatGPT),
|
||||||
};
|
};
|
||||||
Ok(config)
|
Ok(config)
|
||||||
@@ -1048,7 +1049,7 @@ disable_response_storage = true
|
|||||||
base_instructions: None,
|
base_instructions: None,
|
||||||
include_plan_tool: false,
|
include_plan_tool: false,
|
||||||
include_apply_patch_tool: false,
|
include_apply_patch_tool: false,
|
||||||
internal_originator: None,
|
responses_originator_header: "codex_cli_rs".to_string(),
|
||||||
preferred_auth_method: AuthMode::ChatGPT,
|
preferred_auth_method: AuthMode::ChatGPT,
|
||||||
},
|
},
|
||||||
o3_profile_config
|
o3_profile_config
|
||||||
@@ -1101,7 +1102,7 @@ disable_response_storage = true
|
|||||||
base_instructions: None,
|
base_instructions: None,
|
||||||
include_plan_tool: false,
|
include_plan_tool: false,
|
||||||
include_apply_patch_tool: false,
|
include_apply_patch_tool: false,
|
||||||
internal_originator: None,
|
responses_originator_header: "codex_cli_rs".to_string(),
|
||||||
preferred_auth_method: AuthMode::ChatGPT,
|
preferred_auth_method: AuthMode::ChatGPT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1169,7 +1170,7 @@ disable_response_storage = true
|
|||||||
base_instructions: None,
|
base_instructions: None,
|
||||||
include_plan_tool: false,
|
include_plan_tool: false,
|
||||||
include_apply_patch_tool: false,
|
include_apply_patch_tool: false,
|
||||||
internal_originator: None,
|
responses_originator_header: "codex_cli_rs".to_string(),
|
||||||
preferred_auth_method: AuthMode::ChatGPT,
|
preferred_auth_method: AuthMode::ChatGPT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ pub const CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR: &str = "CODEX_SANDBOX_NETWORK_
|
|||||||
/// accommodate sandboxing configuration and other sandboxing mechanisms.
|
/// accommodate sandboxing configuration and other sandboxing mechanisms.
|
||||||
pub const CODEX_SANDBOX_ENV_VAR: &str = "CODEX_SANDBOX";
|
pub const CODEX_SANDBOX_ENV_VAR: &str = "CODEX_SANDBOX";
|
||||||
|
|
||||||
/// Set this to change the originator sent with all network requests.
|
|
||||||
pub const CODEX_ORIGINATOR_ENV_VAR: &str = "CODEX_ORIGINATOR";
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum StdioPolicy {
|
pub enum StdioPolicy {
|
||||||
RedirectForShellTool,
|
RedirectForShellTool,
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ async fn originator_config_override_is_used() {
|
|||||||
let codex_home = TempDir::new().unwrap();
|
let codex_home = TempDir::new().unwrap();
|
||||||
let mut config = load_default_config_for_test(&codex_home);
|
let mut config = load_default_config_for_test(&codex_home);
|
||||||
config.model_provider = model_provider;
|
config.model_provider = model_provider;
|
||||||
config.internal_originator = Some("my_override".to_string());
|
config.responses_originator_header = "my_override".to_owned();
|
||||||
|
|
||||||
let conversation_manager = ConversationManager::default();
|
let conversation_manager = ConversationManager::default();
|
||||||
let codex = conversation_manager
|
let codex = conversation_manager
|
||||||
|
|||||||
Reference in New Issue
Block a user