mirror of
https://github.com/openai/codex.git
synced 2026-10-18 17:18:52 +00:00
## What changed Add `codex-cloud-client`, a reusable Rust client for `ThreadService.Resume` and live `ThreadService.Attach` over HTTP/2. Callers supply the native gRPC origin, bearer token, account ID, and `HttpClientFactory`. - Reuse shared proxy, custom CA, and network policy handling for HTTPS. Reject redirects and allow plaintext HTTP only on direct loopback with unrestricted, unmanaged policy. - Preserve notification and server-request protobuf payloads as opaque bytes and expose native gRPC status details while redacting credentials, payloads, and error details from diagnostics. - Bound resume and attach setup to 150 seconds without retrying requests or imposing an idle deadline on live streams. Attach ends on its first error and provides no history or automatic reconnect. - Select Rustls in `HttpClientBuilder::http2_prior_knowledge()` so HTTPS advertises `h2` through ALPN. Include a standalone attach example and documentation of admission semantics and stream behavior. ## Testing Add HTTP/2 fixture tests for protobuf framing, authentication metadata, status trailers, event preservation, malformed responses, stream cancellation, redirect rejection, and diagnostic redaction. Add checks for unsafe origins, network policy restrictions, and TLS `h2` advertisement. GitOrigin-RevId: 55db70438bb5e59272c6995c67a46ced5fa28ff4
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
//! Standalone consumer; prints event kinds without logging payloads.
|
|
use codex_cloud_client::Client;
|
|
use codex_cloud_client::Credentials;
|
|
use codex_cloud_client::ResumeRequest;
|
|
use codex_http_client::HttpClientFactory;
|
|
use codex_http_client::OutboundProxyPolicy;
|
|
use futures::StreamExt;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let mut args = std::env::args().skip(1);
|
|
let endpoint = args
|
|
.next()
|
|
.ok_or_else(|| anyhow::anyhow!("expected native gRPC origin"))?;
|
|
let thread_id = args
|
|
.next()
|
|
.ok_or_else(|| anyhow::anyhow!("expected existing thread ID"))?;
|
|
let credentials = Credentials::new(
|
|
&std::env::var("CODEX_CLOUD_ACCESS_TOKEN")?,
|
|
&std::env::var("CODEX_CLOUD_ACCOUNT_ID")?,
|
|
)?;
|
|
let client = Client::new(
|
|
&HttpClientFactory::new(OutboundProxyPolicy::RespectSystemProxy),
|
|
&endpoint,
|
|
credentials,
|
|
)?;
|
|
client
|
|
.resume(&ResumeRequest {
|
|
thread_id: thread_id.clone(),
|
|
wait: false,
|
|
shared_access: false,
|
|
})
|
|
.await?;
|
|
let mut events = client.attach(&thread_id).await?;
|
|
while let Some(event) = events.next().await {
|
|
println!("{:?}", event?);
|
|
}
|
|
Ok(())
|
|
}
|