mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-27 00:00:49 +00:00
feat: add openai gpt parity routes
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -39,6 +39,12 @@ pub struct CodexRequestContext<'a> {
|
||||
pub account_id: Option<&'a str>,
|
||||
pub request_id: &'a str,
|
||||
pub turn_state: Option<&'a str>,
|
||||
pub turn_metadata: Option<&'a str>,
|
||||
pub beta_features: Option<&'a str>,
|
||||
pub include_timing_metrics: Option<&'a str>,
|
||||
pub version: Option<&'a str>,
|
||||
pub codex_window_id: Option<&'a str>,
|
||||
pub parent_thread_id: Option<&'a str>,
|
||||
pub cookie_header: Option<&'a str>,
|
||||
}
|
||||
|
||||
@@ -158,10 +164,36 @@ impl CodexBackendClient {
|
||||
if let Some(cookie_header) = context.cookie_header {
|
||||
headers.insert(COOKIE, HeaderValue::from_str(cookie_header)?);
|
||||
}
|
||||
insert_optional_header(&mut headers, "x-codex-turn-metadata", context.turn_metadata)?;
|
||||
insert_optional_header(&mut headers, "x-codex-beta-features", context.beta_features)?;
|
||||
insert_optional_header(
|
||||
&mut headers,
|
||||
"x-responsesapi-include-timing-metrics",
|
||||
context.include_timing_metrics,
|
||||
)?;
|
||||
insert_optional_header(&mut headers, "version", context.version)?;
|
||||
insert_optional_header(&mut headers, "x-codex-window-id", context.codex_window_id)?;
|
||||
insert_optional_header(
|
||||
&mut headers,
|
||||
"x-codex-parent-thread-id",
|
||||
context.parent_thread_id,
|
||||
)?;
|
||||
Ok(headers)
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_optional_header(
|
||||
headers: &mut HeaderMap,
|
||||
name: &'static str,
|
||||
value: Option<&str>,
|
||||
) -> CodexClientResult<()> {
|
||||
let Some(value) = value else {
|
||||
return Ok(());
|
||||
};
|
||||
headers.insert(HeaderName::from_static(name), HeaderValue::from_str(value)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn build_reqwest_client(force_http11: bool) -> Result<Client, reqwest::Error> {
|
||||
// Codex Desktop 指纹依赖 reqwest/rustls 组合,升级前必须重新验证 TLS 行为。
|
||||
let builder = Client::builder()
|
||||
|
||||
+61
-3
@@ -13,11 +13,69 @@ pub struct CodexResponsesRequest {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tools: Option<Vec<Value>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tool_choice: Option<Value>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parallel_tool_calls: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub text: Option<Value>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub service_tier: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub previous_response_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "is_false")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub prompt_cache_key: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub include: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub client_metadata: Option<Value>,
|
||||
#[serde(skip)]
|
||||
pub use_websocket: bool,
|
||||
#[serde(skip)]
|
||||
pub turn_state: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub turn_metadata: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub beta_features: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub version: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub include_timing_metrics: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub codex_window_id: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub parent_thread_id: Option<String>,
|
||||
}
|
||||
|
||||
fn is_false(value: &bool) -> bool {
|
||||
!*value
|
||||
impl CodexResponsesRequest {
|
||||
pub fn new_http_sse(
|
||||
model: impl Into<String>,
|
||||
instructions: impl Into<String>,
|
||||
input: Vec<Value>,
|
||||
) -> Self {
|
||||
Self {
|
||||
model: model.into(),
|
||||
instructions: instructions.into(),
|
||||
input,
|
||||
stream: true,
|
||||
store: false,
|
||||
reasoning: None,
|
||||
tools: None,
|
||||
tool_choice: None,
|
||||
parallel_tool_calls: None,
|
||||
text: None,
|
||||
service_tier: None,
|
||||
previous_response_id: None,
|
||||
prompt_cache_key: None,
|
||||
include: None,
|
||||
client_metadata: None,
|
||||
use_websocket: false,
|
||||
turn_state: None,
|
||||
turn_metadata: None,
|
||||
beta_features: None,
|
||||
version: None,
|
||||
include_timing_metrics: None,
|
||||
codex_window_id: None,
|
||||
parent_thread_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user