mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
## What changed Allow callers to attach eligible Apps tool results as `tool_result` on selected executed tool calls in Responses HTTP and WebSocket requests. Keep text content and optional object-valued `structuredContent`, with a 1 MiB per-result limit and a 15 MiB budget for the enriched message. Attach results after request observers receive the original JSON. Keep result IDs local and suppress WebSocket payload tracing for enriched frames. Preserve the enriched HTTP body on retries to the original endpoint and retry with the original JSON on HTTP 307 and 308 redirects. Codex's default request construction supplies no result bodies. ## Testing Add coverage for result eligibility and size limits, HTTP retry and redirect behavior, and TLS fallback without forwarding the enriched body to a redirect destination. GitOrigin-RevId: c3f2f86f31349e40fcb699d48637c3cbbbe38837
79 lines
2.7 KiB
Rust
79 lines
2.7 KiB
Rust
//! Request drafts shared by fixed clients and route-aware pools.
|
|
//!
|
|
//! Replay header operations in order so reqwest owns URL authentication and header precedence.
|
|
//! Header operations are the sole header state until build; the draft's request holds no headers.
|
|
//! Redirects and TLS retries use the resulting request without repeating this construction.
|
|
|
|
use http::HeaderMap;
|
|
use http::HeaderName;
|
|
use http::HeaderValue;
|
|
use http::Method;
|
|
use reqwest::IntoUrl;
|
|
|
|
use crate::client::TransportClient;
|
|
|
|
/// Request inputs awaiting construction through reqwest with a selected HTTP client.
|
|
///
|
|
/// Route-aware pools select a client for the destination before calling [`Self::build`]; fixed
|
|
/// transports use their existing client. Building applies URL authentication and the queued header
|
|
/// operations once, then redirects and TLS retries reuse the resulting request.
|
|
pub(crate) struct RequestDraft {
|
|
pub(crate) request: reqwest::Request,
|
|
pub(crate) headers: Vec<HeaderUpdate>,
|
|
pub(crate) private_body: bool,
|
|
}
|
|
|
|
/// Streaming preserves the exact length but prevents reqwest from replaying the body on redirects.
|
|
pub(crate) fn prevent_body_redirects(request: &mut reqwest::Request) {
|
|
let body = request.body_mut();
|
|
*body = body.take().map(reqwest::Body::wrap);
|
|
}
|
|
|
|
pub(crate) enum HeaderUpdate {
|
|
Replace(HeaderMap),
|
|
Append(HeaderName, HeaderValue),
|
|
}
|
|
|
|
impl From<reqwest::Request> for RequestDraft {
|
|
fn from(mut request: reqwest::Request) -> Self {
|
|
let headers = vec![HeaderUpdate::Replace(std::mem::take(request.headers_mut()))];
|
|
Self {
|
|
request,
|
|
headers,
|
|
private_body: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl RequestDraft {
|
|
pub(crate) fn new<U: IntoUrl>(method: Method, url: U) -> Result<Self, reqwest::Error> {
|
|
url.into_url()
|
|
.map(|url| Self::from(reqwest::Request::new(method, url)))
|
|
}
|
|
|
|
pub(crate) fn extend_headers(&mut self, headers: HeaderMap) {
|
|
self.headers.push(HeaderUpdate::Replace(headers));
|
|
}
|
|
|
|
pub(crate) fn build(
|
|
self,
|
|
client: &TransportClient,
|
|
) -> Result<reqwest::Request, reqwest::Error> {
|
|
let mut request = self.request;
|
|
let mut builder = client
|
|
.inner
|
|
.request(request.method().clone(), request.url().clone());
|
|
for update in self.headers {
|
|
builder = match update {
|
|
HeaderUpdate::Replace(headers) => builder.headers(headers),
|
|
HeaderUpdate::Append(name, value) => builder.header(name, value),
|
|
};
|
|
}
|
|
let mut built = builder.build()?;
|
|
*built.body_mut() = request.body_mut().take();
|
|
*built.timeout_mut() = request.timeout().copied();
|
|
*built.version_mut() = request.version();
|
|
Ok(built)
|
|
}
|
|
}
|