The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(provider): remove openai_codex module and update routing logic
Steven Enamakel85353fd7ee4b
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rs b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rsindex 0bfb084da7..2d11190de6 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once.rs@@ -41,7 +41,7 @@ impl std::fmt::Debug for CompletionEndpoint {f.debug_struct("CompletionEndpoint").field("base_url",- &crate::inference::provider::factory::redact_endpoint(&self.base_url),+ &crate::inference::provider::factory::redact_endpoint_origin(&self.base_url),).field("api_key", &"<redacted>").field("headers", &self.headers.len())diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rs b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rsindex 054633c972..2dfacb265e 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/complete_once_tests.rs@@ -102,6 +102,63 @@ async fn forwards_schema_max_tokens_and_provider_options() {assert_eq!(response.text(), "{\"ok\":true}");}+#[tokio::test]+async fn preserves_configured_endpoint_path_on_the_wire() {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path("/private-path-segment/v1/chat/completions"))+ .respond_with(+ ResponseTemplate::new(200).set_body_json(completion_body("ok", "stop")),+ )+ .mount(&server)+ .await;+ let endpoint = CompletionEndpoint {+ base_url: format!("{}/private-path-segment/v1", server.uri()),+ api_key: "sk-test".to_string(),+ headers: Vec::new(),+ };+ let request = ModelRequest::new(vec![Message::user("hi")]).with_model("m".to_string());++ complete_once(&endpoint, request, None).await.unwrap();++ let requests = server.received_requests().await.unwrap();+ assert_eq!(requests.len(), 1);+ assert_eq!(requests[0].url.path(), "/private-path-segment/v1/chat/completions");+}++#[test]+fn completion_endpoint_debug_redacts_path_url_credentials_and_header_values() {+ let endpoint = CompletionEndpoint {+ base_url: "https://user:[email protected]/private-path-token/v1?api_key=query-token#fragment-token"+ .to_string(),+ api_key: "bearer-token".to_string(),+ headers: vec![("X-Api-Key".to_string(), "header-token".to_string())],+ };++ let debug = format!("{endpoint:?}");++ assert!(debug.contains("https://provider.example"), "{debug}");+ for secret in [+ "user",+ "password",+ "private-path-token",+ "query-token",+ "fragment-token",+ "bearer-token",+ "header-token",+ ] {+ assert!(!debug.contains(secret), "leaked {secret} in {debug}");+ }+ let invalid = CompletionEndpoint {+ base_url: "not a URL with private-token".to_string(),+ api_key: "k".to_string(),+ headers: Vec::new(),+ };+ let debug = format!("{invalid:?}");+ assert!(debug.contains("<endpoint>"), "{debug}");+ assert!(!debug.contains("private-token"), "{debug}");+}+#[tokio::test]async fn surfaces_length_finish_reason() {let server = MockServer::start().await;diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rsindex a9cd157157..1f65d1d5da 100644--- a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs@@ -423,38 +423,39 @@ pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools_forcrate::security::egress::EgressDescriptor::inference(&slug, &effective_model, true),);- let http = match config+ let ca_bundle = config.cloud_provider_ca_certs.get(&slug).filter(|pem| !pem.is_empty())- {- Some(pem) => {- let label = if anthropic_native {- "provider.anthropic"- } else {- "provider.compatible"- };- match crate::util::tls::client_with_ca_bundle(pem, label) {- Ok(http) => Some(http),- Err(error) => return Some(Err(anyhow::anyhow!(error))),- }- }- None => None,+ .map(String::as_str);+ let service_key = if anthropic_native {+ "provider.anthropic"+ } else {+ "provider.compatible"};- let auth_style = cloud_spec::registry_auth_style(entry.auth_style)- .expect("managed JWT entries returned above");- let chat = cloud_spec::build_cloud_model(cloud_spec::CloudBuild {- spec: cloud_spec::cloud_provider_spec(entry, &effective_model),- auth_style,- key: key.as_str(),+ let http_builder = ca_bundle.map(|_| {+ std::sync::Arc::new(move || {+ crate::config::apply_runtime_proxy_to_builder(+ crate::util::tls::tls_client_builder(),+ service_key,+ )+ }) as tinyinference_llm::providers::registry::ProviderHttpClientBuilder<'_>+ });+ let spec = cloud_spec::cloud_provider_spec(entry, &effective_model);+ let chat = cloud_spec::build_cloud_model(+ &spec,+ &key,+ entry.auth_style,temperature_override,- temperature_unsupported_models: config.temperature_unsupported_models.as_slice(),+ config.temperature_unsupported_models.as_slice(),native_tool_calling,- extra_headers: extra_headers.as_slice(),- extra_query_params: extra_query_params.as_slice(),- user_agent: user_agent.as_deref(),- codex: codex_route,- http,- });+ extra_headers.as_slice(),+ extra_query_params.as_slice(),+ user_agent.as_deref(),+ codex_route,+ None,+ http_builder,+ ca_bundle,+ );Some(chat.map(|chat| (chat, effective_model)))}diff --git a/crates/openhuman-core/src/inference/provider/factory/discovery.rs b/crates/openhuman-core/src/inference/provider/factory/discovery.rsindex 5ee8436fdf..2bd256a670 100644--- a/crates/openhuman-core/src/inference/provider/factory/discovery.rs+++ b/crates/openhuman-core/src/inference/provider/factory/discovery.rs@@ -79,21 +79,19 @@ pub(crate) fn model_limits_request_for(log::debug!("[model_limits] codex oauth routing has no window listing slug={slug}");return None;}- let auth_style = super::cloud_spec::registry_auth_style(resolution.entry.auth_style)?;- let (extra_headers, temperature_unsupported) = (Vec::new(), Vec::new());- super::cloud_spec::cloud_discovery_request(&super::cloud_spec::CloudBuild {- spec: super::cloud_spec::cloud_provider_spec(resolution.entry, &resolution.effective_model),- auth_style,- key: resolution.key.as_str(),- temperature_override: None,- temperature_unsupported_models: &temperature_unsupported,- native_tool_calling: true,- extra_headers: &extra_headers,- extra_query_params: &[],- user_agent: None,- codex: Some(&resolution.codex),- http: None,- })+ if resolution.entry.auth_style == AuthStyle::OpenhumanJwt {+ return None;+ }+ let spec = super::cloud_spec::cloud_provider_spec(resolution.entry, &resolution.effective_model);+ super::cloud_spec::cloud_discovery_request(+ &spec,+ &resolution.key,+ resolution.entry.auth_style,+ &[],+ &[],+ None,+ Some(&resolution.codex),+ )}/// The managed backend's catalogue listing request, from the registereddiff --git a/crates/openhuman-core/src/inference/provider/mod.rs b/crates/openhuman-core/src/inference/provider/mod.rsindex cd4751bb16..546468f36c 100644--- a/crates/openhuman-core/src/inference/provider/mod.rs+++ b/crates/openhuman-core/src/inference/provider/mod.rs@@ -9,7 +9,6 @@ pub mod factory;pub(crate) mod fallback_diagnostics;pub mod http_error;pub mod models;-pub(crate) mod openai_codex;pub use factory::{create_chat_model_from_string, create_chat_model_from_string_with_model_id,diff --git a/crates/openhuman-core/src/inference/provider/models/catalog_listing.rs b/crates/openhuman-core/src/inference/provider/models/catalog_listing.rsindex 2358575df9..a2ef9b5852 100644--- a/crates/openhuman-core/src/inference/provider/models/catalog_listing.rs+++ b/crates/openhuman-core/src/inference/provider/models/catalog_listing.rs@@ -3,7 +3,7 @@//! managed entries), builds an authenticated `/models` request for it, and//! parses the response.-use super::super::openai_codex::resolve_openai_codex_routing;+use super::super::factory::resolve_codex_routing;use super::local_runtime::synthesize_local_runtime_entry;use tinyinference_llm::catalog::{append_query_param, endpoint_hosts_models_listing, is_openrouter_provider, list_models,@@ -178,9 +178,8 @@ pub async fn list_configured_models_from_config(let bearer_is_oauth = entry.slug == "openai"&& crate::inference::provider::factory::openai_bearer_is_oauth(config);- let routing =- resolve_openai_codex_routing(config, &entry.slug, &entry.endpoint, &api_key, bearer_is_oauth)- .unwrap_or_else(|err| {+ let routing = resolve_codex_routing(config, &entry.slug, &entry.endpoint, &api_key, bearer_is_oauth)+ .unwrap_or_else(|err| {log::warn!("[providers][list_models] openai codex routing unavailable; continuing with configured endpoint: {err}");diff --git a/crates/openhuman-core/src/inference/provider/openai_codex.rs b/crates/openhuman-core/src/inference/provider/openai_codex.rsdeleted file mode 100644index 71def06181..0000000000--- a/crates/openhuman-core/src/inference/provider/openai_codex.rs+++ /dev/null@@ -1,45 +0,0 @@-use crate::config::Config;-use tinyinference_llm::providers::openai::codex::{- OpenAiCodexRouting, OPENAI_CODEX_BACKEND_BASE_URL,-};--pub(crate) fn resolve_openai_codex_routing(- config: &Config,- slug: &str,- endpoint: &str,- bearer_key: &str,- bearer_is_oauth: bool,-) -> Result<OpenAiCodexRouting, String> {- if slug != "openai" {- return Ok(OpenAiCodexRouting::standard(endpoint));- }-- let credentials =- match crate::security::credentials::openai_oauth::lookup_openai_oauth_credentials(config) {- Ok(credentials) => credentials,- Err(err) if !bearer_key.trim().is_empty() => {- log::warn!(- "[providers][openai-codex] oauth metadata unavailable; continuing with standard bearer key: {err}"- );- None- }- Err(err) => return Err(format!("[chat-factory] openai oauth lookup failed: {err}")),- };-- let using_oauth = bearer_is_oauth && credentials.is_some();- let account_id = credentials- .filter(|_| using_oauth)- .and_then(|credentials| credentials.account_id)- .map(|value| value.trim().to_string())- .filter(|value| !value.is_empty());-- Ok(if using_oauth {- OpenAiCodexRouting {- endpoint: OPENAI_CODEX_BACKEND_BASE_URL.to_string(),- using_oauth: true,- account_id,- }- } else {- OpenAiCodexRouting::standard(endpoint)- })-}diff --git a/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs b/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rsindex a4dc977389..4a86d59aca 100644--- a/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs+++ b/crates/openhuman-core/src/security/credentials/openai_oauth/flow_tests_lifecycle_tests.rs@@ -566,7 +566,7 @@ fn codex_routing_reaches_backend_for_oauth_only_openai_even_after_token_rotation// backend regardless of the bearer string passed in — here a deliberately// *different* token, standing in for a post-refresh rotation.use crate::inference::provider::factory::openai_bearer_is_oauth;- use crate::inference::provider::openai_codex::resolve_openai_codex_routing;+ use crate::inference::provider::factory::resolve_codex_routing;let tmp = tempdir().unwrap();let config = test_config(&tmp);@@ -593,7 +593,7 @@ fn codex_routing_reaches_backend_for_oauth_only_openai_even_after_token_rotation"OAuth is the only openai credential, so the bearer is OAuth");- let routing = resolve_openai_codex_routing(+ let routing = resolve_codex_routing(&config,"openai","https://api.openai.com/v1",@@ -618,7 +618,7 @@ fn codex_routing_reaches_backend_for_oauth_only_openai_even_after_token_rotation).unwrap();assert!(!openai_bearer_is_oauth(&config));- let routing = resolve_openai_codex_routing(+ let routing = resolve_codex_routing(&config,"openai","https://api.openai.com/v1",