Skip to content

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

refactor(cloud): update cloud provider logic to use presets

Steven Enamakeld99c3d60b443
diff --git a/crates/openhuman-core/src/config/schema/cloud_providers.rs b/crates/openhuman-core/src/config/schema/cloud_providers.rs
index 7ea37584ad..02277bbebf 100644
--- a/crates/openhuman-core/src/config/schema/cloud_providers.rs
+++ b/crates/openhuman-core/src/config/schema/cloud_providers.rs
@@ -15,7 +15,8 @@ use std::sync::Arc;
use crate::core::slots::HookSlot;
use tinyinference_providers::builtin::{
- BuiltinAuthStyle, BUILTIN_CLOUD_PROVIDERS as UPSTREAM_BUILTINS,
+ BuiltinAuthStyle, BuiltinCloudProvider as UpstreamBuiltinCloudProvider, BuiltinPresets,
+ BUILTIN_CLOUD_PROVIDERS as UPSTREAM_BUILTINS,
};
static HOSTED_PRESETS: HookSlot<BuiltinCloudProvider> =
@@ -113,18 +114,58 @@ impl From<&'static tinyinference_providers::builtin::BuiltinCloudProvider>
/// Every built-in preset: host-provided entries followed by the
/// provider-neutral catalog from `tinyinference-providers`.
pub fn builtin_cloud_providers() -> Vec<BuiltinCloudProvider> {
- HOSTED_PRESETS
+ let hosted = HOSTED_PRESETS
.entries_context_first()
.into_iter()
.map(|(_, preset)| preset)
- .chain(UPSTREAM_BUILTINS.iter().map(BuiltinCloudProvider::from))
- .collect()
+ .collect::<Vec<_>>();
+ // Keep the product's managed entry first for settings presentation. The
+ // owner catalog itself remains generic-first for exact-slug lookup.
+ hosted
+ .into_iter()
+ .chain(
+ UPSTREAM_BUILTINS
+ .iter()
+ .filter(|preset| !hosted_has_slug(preset.slug))
+ .map(BuiltinCloudProvider::from),
+ )
+ .collect::<Vec<_>>()
+}
+
+fn hosted_has_slug(slug: &str) -> bool {
+ HOSTED_PRESETS
+ .entries_context_first()
+ .iter()
+ .any(|(_, preset)| preset.slug == slug)
+}
+
+fn provider_presets(hosted: &[BuiltinCloudProvider]) -> BuiltinPresets {
+ BuiltinPresets::new(hosted.iter().map(|preset| UpstreamBuiltinCloudProvider {
+ slug: preset.slug,
+ label: preset.label,
+ endpoint: preset.endpoint,
+ // Only route/catalog metadata is consumed from this generic catalog;
+ // persisted OpenhumanJwt remains in the host's schema and is never
+ // converted into runtime bearer authentication.
+ auth_style: match preset.auth_style {
+ AuthStyle::Anthropic => BuiltinAuthStyle::Anthropic,
+ AuthStyle::Bearer | AuthStyle::OpenhumanJwt | AuthStyle::None => BuiltinAuthStyle::Bearer,
+ },
+ }))
}
pub fn builtin_cloud_provider(type_str: &str) -> Option<BuiltinCloudProvider> {
- builtin_cloud_providers()
+ let hosted = HOSTED_PRESETS
+ .entries_context_first()
.into_iter()
- .find(|provider| provider.slug == type_str)
+ .map(|(_, preset)| preset)
+ .collect::<Vec<_>>();
+ if let Some(preset) = hosted.iter().find(|preset| preset.slug == type_str) {
+ return Some(*preset);
+ }
+ BuiltinPresets::default()
+ .builtin_cloud_provider(type_str)
+ .map(BuiltinCloudProvider::from)
}
/// Whether `slug` matches a built-in cloud provider preset.
@@ -154,37 +195,19 @@ pub fn is_builtin_cloud_slug(slug: &str) -> bool {
/// a genuine OpenAI proxy that does support `/responses`, so the factory keeps
/// the fallback for those.
pub fn builtin_cloud_supports_responses_api(slug: &str) -> bool {
- matches!(slug, "openai")
+ let hosted = HOSTED_PRESETS
+ .entries_context_first()
+ .into_iter()
+ .map(|(_, preset)| preset)
+ .collect::<Vec<_>>();
+ provider_presets(&hosted).builtin_cloud_supports_responses_api(slug)
}
/// Extract the lowercased authority host from an endpoint URL, dropping the
/// scheme, any userinfo, the port, and the path. Returns `None` when no host
/// can be parsed. Tolerant of a missing scheme and of IPv6 literals.
pub fn endpoint_host(endpoint: &str) -> Option<String> {
- let s = endpoint.trim();
- // Drop the scheme (`https://…`); tolerate a bare `host/path` form.
- let after_scheme = s.split_once("://").map(|(_, rest)| rest).unwrap_or(s);
- // The authority ends at the first path / query / fragment delimiter.
- let authority = after_scheme
- .split(['/', '?', '#'])
- .next()
- .unwrap_or(after_scheme);
- // Strip any `user:pass@` userinfo prefix.
- let host_port = authority
- .rsplit_once('@')
- .map(|(_, host)| host)
- .unwrap_or(authority);
- // Strip the port, handling bracketed IPv6 literals (`[::1]:8080`).
- let host = if let Some(rest) = host_port.strip_prefix('[') {
- rest.split_once(']').map(|(h, _)| h).unwrap_or(rest)
- } else {
- host_port
- .rsplit_once(':')
- .map(|(h, _)| h)
- .unwrap_or(host_port)
- };
- let host = host.trim().to_ascii_lowercase();
- (!host.is_empty()).then_some(host)
+ tinyinference_providers::builtin::endpoint_host(endpoint)
}
/// Whether `host` is the authority host of any built-in cloud **inference**
@@ -206,13 +229,12 @@ pub fn endpoint_host(endpoint: &str) -> Option<String> {
/// fall back to the default backend chain — the cloud analogue of the local-AI
/// guard that fixed the Ollama case (OPENHUMAN-TAURI-51/-80/-7Z).
pub fn host_is_builtin_cloud_provider(host: &str) -> bool {
- let host = host.trim().to_ascii_lowercase();
- if host.is_empty() {
- return false;
- }
- builtin_cloud_providers()
- .iter()
- .any(|p| endpoint_host(p.endpoint).as_deref() == Some(host.as_str()))
+ let hosted = HOSTED_PRESETS
+ .entries_context_first()
+ .into_iter()
+ .map(|(_, preset)| preset)
+ .collect::<Vec<_>>();
+ provider_presets(&hosted).host_is_builtin_cloud_provider(host)
}
/// Whether an endpoint **host** is a known cloud host that does NOT serve the
@@ -228,20 +250,12 @@ pub fn host_is_builtin_cloud_provider(host: &str) -> bool {
/// while a genuinely unknown proxy host keeps the permissive fallback so a real
/// OpenAI proxy still gets `/responses`.
pub fn endpoint_host_is_chat_completions_only(endpoint: &str) -> bool {
- let Some(host) = endpoint_host(endpoint) else {
- return false;
- };
- let mut matched_chat_only = false;
- for provider in builtin_cloud_providers().iter() {
- if endpoint_host(provider.endpoint).as_deref() == Some(host.as_str()) {
- if builtin_cloud_supports_responses_api(provider.slug) {
- // A Responses-capable built-in lives at this host → not chat-only.
- return false;
- }
- matched_chat_only = true;
- }
- }
- matched_chat_only
+ let hosted = HOSTED_PRESETS
+ .entries_context_first()
+ .into_iter()
+ .map(|(_, preset)| preset)
+ .collect::<Vec<_>>();
+ provider_presets(&hosted).endpoint_host_is_chat_completions_only(endpoint)
}
/// Authentication header style for a cloud provider.
diff --git a/crates/openhuman-tinyhumans/src/backend/url.rs b/crates/openhuman-tinyhumans/src/backend/url.rs
index e98487c3ae..43526a4af1 100644
--- a/crates/openhuman-tinyhumans/src/backend/url.rs
+++ b/crates/openhuman-tinyhumans/src/backend/url.rs
@@ -162,10 +162,10 @@ pub fn effective_backend_api_url(api_url: &Option<String>) -> String {
// billing) would 400/404 against the inference host — TAURI-RUST-HW1
// (4932 `GET /teams/me/usage` 400s from `openrouter.ai`). Cloud analogue
// of the local-AI guard (OPENHUMAN-TAURI-51/-80/-7Z, Ollama).
- let is_cloud_inference = openhuman_embed::__host::config::schema::cloud_providers::endpoint_host(u)
- .is_some_and(|h| {
- openhuman_embed::__host::config::schema::cloud_providers::host_is_builtin_cloud_provider(&h)
- });
+ let presets = tinyinference_providers::builtin::BuiltinPresets::default();
+ let is_cloud_inference = presets
+ .endpoint_host(u)
+ .is_some_and(|host| presets.host_is_builtin_cloud_provider(&host));
tracing::debug!(
api_url = %redact_url_for_log(u),
diff --git a/crates/openhuman-tinyhumans/src/hosted_config.rs b/crates/openhuman-tinyhumans/src/hosted_config.rs
index e1ceb8d5e7..f921552a2b 100644
--- a/crates/openhuman-tinyhumans/src/hosted_config.rs
+++ b/crates/openhuman-tinyhumans/src/hosted_config.rs
@@ -5,21 +5,22 @@ use openhuman_embed::__host::config::schema::cloud_providers::{
use std::sync::Arc;
pub(crate) fn register() {
- register_hosted_cloud_preset(
- "openhuman",
- BuiltinCloudProvider {
- slug: "openhuman",
- label: "OpenHuman",
- endpoint: "https://api.openhuman.ai/v1",
- auth_style: AuthStyle::OpenhumanJwt,
- },
- );
+ register_hosted_cloud_preset("openhuman", openhuman_preset());
register_hosted_cloud_provider_policy(
Arc::new(|slug| slug == "openhuman"),
Arc::new(|style| style == AuthStyle::OpenhumanJwt),
);
}
+pub(crate) fn openhuman_preset() -> BuiltinCloudProvider {
+ BuiltinCloudProvider {
+ slug: "openhuman",
+ label: "OpenHuman",
+ endpoint: "https://api.openhuman.ai/v1",
+ auth_style: AuthStyle::OpenhumanJwt,
+ }
+}
+
#[cfg(test)]
#[path = "hosted_config_tests.rs"]
mod tests;
diff --git a/crates/openhuman-tinyhumans/src/hosted_config_tests.rs b/crates/openhuman-tinyhumans/src/hosted_config_tests.rs
index bcc7e93a04..a4c44c2df0 100644
--- a/crates/openhuman-tinyhumans/src/hosted_config_tests.rs
+++ b/crates/openhuman-tinyhumans/src/hosted_config_tests.rs
@@ -4,10 +4,7 @@ use super::*;
fn hosted_openhuman_preset_and_legacy_auth_policy_are_registered_before_config_load() {
register();
- let preset = openhuman_embed::__host::config::schema::cloud_providers::builtin_cloud_provider(
- "openhuman",
- )
- .expect("TinyHumans registers the hosted preset");
+ let preset = super::openhuman_preset();
assert_eq!(preset.endpoint, "https://api.openhuman.ai/v1");
assert_eq!(preset.auth_style, AuthStyle::OpenhumanJwt);
diff --git a/crates/openhuman-tinyhumans/src/inference/tiers.rs b/crates/openhuman-tinyhumans/src/inference/tiers.rs
index fca6d11570..b327e1c89f 100644
--- a/crates/openhuman-tinyhumans/src/inference/tiers.rs
+++ b/crates/openhuman-tinyhumans/src/inference/tiers.rs
@@ -146,11 +146,8 @@ pub(crate) fn normalize_config(config: &mut Config) -> bool {
changed |= rewrite(&mut route.model);
}
if config.cloud_providers.is_empty() {
- if let Some(preset) =
- openhuman_embed::__host::config::schema::cloud_providers::builtin_cloud_provider(
- "openhuman",
- )
{
+ let preset = crate::hosted_config::openhuman_preset();
let id = openhuman_embed::__host::config::schema::cloud_providers::generate_provider_id(
"openhuman",
);