Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(inference): update cloud provider factory to use ProviderRegistry

Steven Enamakel33d0ec966665
diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
index 1f65d1d5da..d3da10f22d 100644
--- a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs
@@ -9,7 +9,9 @@ use crate::inference::provider::factory::access_gates::verify_backend_session_ac
use crate::inference::provider::factory::access_gates::verify_session_active;
use crate::inference::provider::fallback_diagnostics;
use tinyinference_llm::providers::anthropic::endpoint_is_anthropic_messages;
-use tinyinference_llm::providers::registry::resolve_slug_model;
+use tinyinference_llm::providers::registry::{
+ resolve_slug_model, ProviderBuildOptions, ProviderRegistry,
+};
/// Look up a `cloud_providers` entry by slug and build the provider.
/// The shared resolution for a `<slug>:<model>` cloud provider — the cloud
@@ -442,20 +444,29 @@ pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools_for
}) 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,
- config.temperature_unsupported_models.as_slice(),
- native_tool_calling,
- extra_headers.as_slice(),
- extra_query_params.as_slice(),
- user_agent.as_deref(),
- codex_route,
- None,
- http_builder,
- ca_bundle,
+ log::debug!(
+ "[providers][cloud-spec] build slug={} kind={} auth={:?}",
+ spec.provider,
+ spec.kind.as_str(),
+ entry.auth_style
);
+ let chat = ProviderRegistry::new(cloud_spec::CloudCredentialResolver(&key))
+ .build_with(
+ &spec,
+ ProviderBuildOptions {
+ auth_style: Some(entry.auth_style.into()),
+ temperature_override,
+ temperature_unsupported_models: config.temperature_unsupported_models.as_slice(),
+ native_tool_calling: Some(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_builder,
+ ca_bundle,
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .map_err(|error| anyhow::anyhow!("[chat-factory] {error}"));
Some(chat.map(|chat| (chat, effective_model)))
}
diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
index 85ebba3c7e..dab212ccc5 100644
--- a/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_spec_tests.rs
@@ -1,4 +1,5 @@
use super::*;
+use tinyinference_llm::providers::registry::{ProviderBuildOptions, ProviderRegistry};
fn entry(slug: &str, endpoint: &str, auth_style: AuthStyle) -> CloudProviderCreds {
CloudProviderCreds {
@@ -12,22 +13,17 @@ fn entry(slug: &str, endpoint: &str, auth_style: AuthStyle) -> CloudProviderCred
}
fn build(entry: &CloudProviderCreds, model: &str, key: &str) {
- build_cloud_model(
- &cloud_provider_spec(entry, model),
- key,
- entry.auth_style,
- None,
- &[],
- true,
- &[],
- &[],
- None,
- None,
- None,
- None,
- None,
- )
- .unwrap_or_else(|error| panic!("{} failed to build: {error}", entry.slug));
+ let spec = cloud_provider_spec(entry, model);
+ ProviderRegistry::new(CloudCredentialResolver(key))
+ .build_with(
+ &spec,
+ ProviderBuildOptions {
+ auth_style: Some(entry.auth_style.into()),
+ native_tool_calling: Some(true),
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .unwrap_or_else(|error| panic!("{} failed to build: {error}", entry.slug));
}
#[test]
@@ -80,16 +76,16 @@ fn discovery_request_carries_bearer_auth_and_pins_openrouter_sorting() {
AuthStyle::Bearer,
);
let spec = cloud_provider_spec(&creds, "m");
- let request = cloud_discovery_request(
- &spec,
- "sk-or",
- AuthStyle::Bearer,
- &[],
- &[],
- None,
- None,
- )
- .expect("openrouter has a listing");
+ let request = ProviderRegistry::new(CloudCredentialResolver("sk-or"))
+ .discovery_request(
+ &spec,
+ &ProviderBuildOptions {
+ auth_style: Some(AuthStyle::Bearer.into()),
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .unwrap()
+ .expect("openrouter has a listing");
assert_eq!(request.endpoint, "https://openrouter.ai/api/v1");
assert!(request
.headers
@@ -105,16 +101,16 @@ fn discovery_request_uses_x_api_key_for_anthropic() {
AuthStyle::Anthropic,
);
let spec = cloud_provider_spec(&claude, "claude");
- let request = cloud_discovery_request(
- &spec,
- "sk-ant",
- AuthStyle::Anthropic,
- &[],
- &[],
- None,
- None,
- )
- .expect("listing");
+ let request = ProviderRegistry::new(CloudCredentialResolver("sk-ant"))
+ .discovery_request(
+ &spec,
+ &ProviderBuildOptions {
+ auth_style: Some(AuthStyle::Anthropic.into()),
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .unwrap()
+ .expect("listing");
assert!(request.headers.iter().any(|(name, _)| name == "x-api-key"));
}
@@ -128,16 +124,19 @@ fn discovery_request_builds_codex_oauth_listing_request() {
};
let query = [("client_version".to_string(), "0.130.0".to_string())];
let spec = cloud_provider_spec(&openai, "gpt");
- let request = cloud_discovery_request(
- &spec,
- "tok",
- AuthStyle::Bearer,
- &[],
- &query,
- Some("codex_cli_rs/0.0.0 (OpenHuman 0.64.18)"),
- Some(&oauth),
- )
- .expect("Codex OAuth has a listing");
+ let request = ProviderRegistry::new(CloudCredentialResolver("tok"))
+ .discovery_request(
+ &spec,
+ &ProviderBuildOptions {
+ auth_style: Some(AuthStyle::Bearer.into()),
+ extra_query_params: &query,
+ user_agent: Some("codex_cli_rs/0.0.0 (OpenHuman 0.64.18)"),
+ codex: Some(&oauth),
+ ..ProviderBuildOptions::default()
+ },
+ )
+ .unwrap()
+ .expect("Codex OAuth has a listing");
assert_eq!(request.endpoint, "https://chatgpt.com/backend-api/codex");
assert_eq!(
request.effective_listing_url(),