mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
feat(codex): align Search and execution protocol
This commit is contained in:
@@ -101,6 +101,29 @@ pub(crate) fn client_session_affinity_from_request(
|
||||
client_session_scope_from_request(headers, body_json)?.scheduler_affinity()
|
||||
}
|
||||
|
||||
pub(crate) fn client_session_affinity_from_api_request(
|
||||
api_format: &str,
|
||||
headers: &http::HeaderMap,
|
||||
body_json: Option<&Value>,
|
||||
) -> Option<ClientSessionAffinity> {
|
||||
client_session_scope_from_api_request(api_format, headers, body_json)?.scheduler_affinity()
|
||||
}
|
||||
|
||||
fn client_session_scope_from_api_request(
|
||||
api_format: &str,
|
||||
headers: &http::HeaderMap,
|
||||
body_json: Option<&Value>,
|
||||
) -> Option<ClientSessionScope> {
|
||||
if api_format.trim().eq_ignore_ascii_case("openai:search") {
|
||||
let request = ClientSessionRequest { headers, body_json };
|
||||
return explicit_aether_session_scope(&request, CodexSessionScopeAdapter.family())
|
||||
.or_else(|| codex_search_session_scope(&request))
|
||||
.or_else(|| client_session_scope_from_request(headers, body_json));
|
||||
}
|
||||
|
||||
client_session_scope_from_request(headers, body_json)
|
||||
}
|
||||
|
||||
pub(crate) fn client_session_scope_from_request(
|
||||
headers: &http::HeaderMap,
|
||||
body_json: Option<&Value>,
|
||||
@@ -113,6 +136,22 @@ pub(crate) fn client_session_scope_from_request(
|
||||
.or_else(|| extract_scope_from_other_specific_adapters(&request, client_family.as_str()))
|
||||
}
|
||||
|
||||
fn codex_search_session_scope(request: &ClientSessionRequest<'_>) -> Option<ClientSessionScope> {
|
||||
let session_id = request
|
||||
.body_json?
|
||||
.get("id")?
|
||||
.as_str()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())?;
|
||||
Some(ClientSessionScope::new(
|
||||
CodexSessionScopeAdapter.family(),
|
||||
session_id,
|
||||
None,
|
||||
header_value_str(request.headers, "chatgpt-account-id"),
|
||||
ClientSessionSignalSource::Body,
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn client_session_affinity_from_parts(
|
||||
parts: &http::request::Parts,
|
||||
body_json: Option<&Value>,
|
||||
@@ -789,6 +828,7 @@ fn has_header_with_prefix(headers: &http::HeaderMap, prefix: &str) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
client_session_affinity_from_api_request,
|
||||
client_session_affinity_from_report_context_value, client_session_affinity_from_request,
|
||||
client_session_affinity_report_context_value, client_session_scope_from_request,
|
||||
ClientSessionSignalSource, AETHER_AGENT_ID_HEADER, AETHER_SESSION_ID_HEADER,
|
||||
@@ -1125,4 +1165,28 @@ mod tests {
|
||||
|
||||
assert!(client_session_affinity_from_request(&headers, Some(&body)).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_search_uses_request_id_as_session_affinity() {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("chatgpt-account-id", HeaderValue::from_static("account-1"));
|
||||
let body = json!({"id": "codex-session-1", "model": "gpt-5.6"});
|
||||
|
||||
let affinity =
|
||||
client_session_affinity_from_api_request("openai:search", &headers, Some(&body))
|
||||
.expect("search affinity should build");
|
||||
|
||||
assert_eq!(affinity.client_family.as_deref(), Some("codex"));
|
||||
assert_eq!(
|
||||
affinity.session_key.as_deref(),
|
||||
Some("account=account-1;session=codex-session-1")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn top_level_request_id_is_not_a_generic_session_signal() {
|
||||
let body = json!({"id": "request-id", "model": "gpt-5.6"});
|
||||
|
||||
assert!(client_session_affinity_from_request(&HeaderMap::new(), Some(&body)).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user