mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Forward thread originators from standalone extensions (#33677)
## Why Standalone web search and image requests need to preserve the trusted, thread-scoped originator used for billing attribution. ## What changed - Seed extension data with the resolved thread originator and recognize `codex_work_cca` and `chatgpt_cca` service names as originators. - Forward non-default originators from the web search and image generation extensions with the shared originator-header helper. ## Testing - Cover originator resolution, header validation, and forwarding for web search, image generation, and image editing. GitOrigin-RevId: 165dace8e4d24e4bd92f234bff5ec77a21a7ff6e
This commit is contained in:
1 parent
71448a29e7
commit
78ba047bda
16 files changed
+248
-44
No files matched your search
@@ -18,6 +18,7 @@ use codex_extension_api::parse_tool_input_schema_without_compaction;
|
||||
use codex_extension_items::ExtensionItem;
|
||||
use codex_extension_items::web_search::WebSearchAction;
|
||||
use codex_extension_items::web_search::WebSearchItem;
|
||||
use codex_login::default_client::add_originator_header;
|
||||
use codex_login::default_client::build_reqwest_client;
|
||||
use codex_model_provider::SharedModelProvider;
|
||||
use codex_protocol::models::WebSearchAction as CoreWebSearchAction;
|
||||
@@ -44,6 +45,7 @@ pub(crate) struct WebSearchTool {
|
||||
pub(crate) session_id: String,
|
||||
pub(crate) provider: SharedModelProvider,
|
||||
pub(crate) settings: SearchSettings,
|
||||
pub(crate) originator: Option<String>,
|
||||
}
|
||||
|
||||
impl ToolExecutor<ToolCall> for WebSearchTool {
|
||||
@@ -115,12 +117,10 @@ impl WebSearchTool {
|
||||
u64::try_from(call.truncation_policy.token_budget()).unwrap_or(u64::MAX),
|
||||
),
|
||||
};
|
||||
let mut extra_headers = HeaderMap::new();
|
||||
if let Some(turn_metadata) = call.codex_turn_metadata.as_deref()
|
||||
&& let Ok(header_value) = HeaderValue::from_str(turn_metadata)
|
||||
{
|
||||
extra_headers.insert(X_CODEX_TURN_METADATA_HEADER, header_value);
|
||||
}
|
||||
let extra_headers = search_request_headers(
|
||||
self.originator.as_deref(),
|
||||
call.codex_turn_metadata.as_deref(),
|
||||
);
|
||||
call.turn_item_emitter
|
||||
.emit_started(extension_turn_item(
|
||||
WebSearchItem {
|
||||
@@ -174,6 +174,20 @@ impl WebSearchTool {
|
||||
}
|
||||
}
|
||||
|
||||
fn search_request_headers(originator: Option<&str>, turn_metadata: Option<&str>) -> HeaderMap {
|
||||
let mut headers = HeaderMap::new();
|
||||
if let Some(turn_metadata) = turn_metadata
|
||||
&& let Ok(header_value) = HeaderValue::from_str(turn_metadata)
|
||||
{
|
||||
headers.insert(X_CODEX_TURN_METADATA_HEADER, header_value);
|
||||
}
|
||||
|
||||
if let Some(originator) = originator {
|
||||
add_originator_header(&mut headers, originator);
|
||||
}
|
||||
headers
|
||||
}
|
||||
|
||||
fn parse_commands(call: &ToolCall) -> Result<SearchCommands, FunctionCallError> {
|
||||
let arguments = call.function_arguments()?;
|
||||
if arguments.trim().is_empty() {
|
||||
@@ -245,6 +259,25 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::command_action;
|
||||
use super::search_request_headers;
|
||||
use codex_core::X_CODEX_TURN_METADATA_HEADER;
|
||||
|
||||
#[test]
|
||||
fn search_request_headers_forward_thread_originator_and_turn_metadata() {
|
||||
let headers = search_request_headers(Some("chatgpt_cca"), Some("turn-metadata"));
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("originator")
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some("chatgpt_cca")
|
||||
);
|
||||
assert_eq!(
|
||||
headers
|
||||
.get(X_CODEX_TURN_METADATA_HEADER)
|
||||
.and_then(|value| value.to_str().ok()),
|
||||
Some("turn-metadata")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_action_reports_queries_and_navigation_detail() {
|
||||
|
||||
Reference in new issue
Block a user