Skip to content

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

feat(config): add resolved endpoints schema

Steven Enamakel7bba4ded552c
diff --git a/crates/openhuman-core/src/config/schema/resolved_endpoints.rs b/crates/openhuman-core/src/config/schema/resolved_endpoints.rs
index 6cb7956ee3..b61b136768 100644
--- a/crates/openhuman-core/src/config/schema/resolved_endpoints.rs
+++ b/crates/openhuman-core/src/config/schema/resolved_endpoints.rs
@@ -27,6 +27,19 @@ pub struct ResolvedEndpoints {
pub socket_url: Option<String>,
/// Where tracing/observability events are pushed.
pub tracing_ingest_url: Option<String>,
+ /// Where OTLP trace exports are pushed (the OTLP/HTTP traces endpoint of
+ /// the same tracing backend), when the host exposes one.
+ pub tracing_otlp_url: Option<String>,
+ /// The deployment bucket the host places its control plane in
+ /// (`"production"`, `"staging"`, `"development"` or `"external"`). The core
+ /// classifies loopback hosts itself and treats anything unrecognised as
+ /// `"external"`, which does not push traces.
+ pub deployment_environment: Option<String>,
+ /// Host patterns the installed host treats as its own managed backend:
+ /// an exact host (`api.example.com`) or a `.suffix` that matches any
+ /// subdomain (`.example.com`). Empty with no host registered, so nothing
+ /// is recognised as a managed endpoint.
+ pub managed_hosts: Vec<String>,
/// Headers stamped on every request to the control plane, `(name, value)`.
pub attribution_headers: Vec<(String, String)>,
/// The product identity the host reports (the `x-sdk-name` value).
@@ -63,6 +76,13 @@ impl ResolvedEndpoints {
})
}
+ /// Whether `url` (or a bare host) names one of the resolved managed hosts.
+ /// Matching is on the host component only, case-insensitively, so a path
+ /// or query that happens to contain a managed host name never matches.
+ pub fn is_managed_host(&self, url: &str) -> bool {
+ host_matches_any(url, &self.managed_hosts)
+ }
+
/// The attribution headers as a `reqwest` header map; invalid pairs are
/// skipped.
pub fn attribution_header_map(&self) -> reqwest::header::HeaderMap {
@@ -78,3 +98,38 @@ impl ResolvedEndpoints {
map
}
}
+
+/// Lower-cased host of `url` (scheme, userinfo, port and path stripped).
+fn host_of(url: &str) -> String {
+ let lower = url.trim().to_ascii_lowercase();
+ let without_scheme = lower.split("://").nth(1).unwrap_or(&lower);
+ let authority = without_scheme.split('/').next().unwrap_or("");
+ let host = authority.split('@').next_back().unwrap_or(authority);
+ host.split(':').next().unwrap_or(host).to_string()
+}
+
+/// Whether the host of `url` equals a pattern or falls under a `.suffix`
+/// pattern. Empty patterns never match.
+pub fn host_matches_any(url: &str, patterns: &[String]) -> bool {
+ if patterns.is_empty() {
+ return false;
+ }
+ let host = host_of(url);
+ if host.is_empty() {
+ return false;
+ }
+ patterns.iter().any(|pattern| {
+ let pattern = pattern.trim().to_ascii_lowercase();
+ if pattern.is_empty() {
+ false
+ } else if pattern.starts_with('.') {
+ host.ends_with(&pattern)
+ } else {
+ host == pattern
+ }
+ })
+}
+
+#[cfg(test)]
+#[path = "resolved_endpoints_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs b/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs
new file mode 100644
index 0000000000..09eb8f9345
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/resolved_endpoints_tests.rs
@@ -0,0 +1,35 @@
+use super::*;
+
+fn endpoints() -> ResolvedEndpoints {
+ ResolvedEndpoints {
+ managed_hosts: vec![
+ "api.example.test".into(),
+ ".example.test".into(),
+ "bare-name".into(),
+ ],
+ ..Default::default()
+ }
+}
+
+#[test]
+fn nothing_is_managed_without_registered_hosts() {
+ assert!(!ResolvedEndpoints::default().is_managed_host("https://api.example.test/x"));
+}
+
+#[test]
+fn exact_and_suffix_patterns_match_the_host_only() {
+ let e = endpoints();
+ assert!(e.is_managed_host("https://api.example.test/openai/v1"));
+ assert!(e.is_managed_host("HTTPS://[email protected]:8443/x"));
+ assert!(e.is_managed_host("bare-name"));
+ assert!(e.is_managed_host("http://bare-name:7788"));
+}
+
+#[test]
+fn lookalikes_and_path_mentions_do_not_match() {
+ let e = endpoints();
+ assert!(!e.is_managed_host("https://evilexample.test"));
+ assert!(!e.is_managed_host("https://example.test.evil.invalid"));
+ assert!(!e.is_managed_host("https://other.invalid/api.example.test"));
+ assert!(!e.is_managed_host(""));
+}
diff --git a/crates/openhuman-core/src/core/session_expiry_tests.rs b/crates/openhuman-core/src/core/session_expiry_tests.rs
index 8f4a2afaaa..bddb2cde58 100644
--- a/crates/openhuman-core/src/core/session_expiry_tests.rs
+++ b/crates/openhuman-core/src/core/session_expiry_tests.rs
@@ -18,17 +18,11 @@ fn is_session_expired_error_matches_backend_path_401() {
#[test]
fn is_session_expired_error_matches_flattened_backend_unauthorized() {
// #3297: after #2781 the backend 401 is a typed `BackendApiError::Unauthorized`
- // that team/billing ops flatten via `the hosted layer's flatten step`. The dispatcher
+ // that team/billing ops flatten in the hosted layer. The dispatcher
// classifier MUST recognise that flattened string as session expiry, so the
- // 401 is suppressed from Sentry (TAURI-RUST-8WY on `/teams/me/usage`,
- // TAURI-RUST-8WZ on `/payments/stripe/currentPlan`) AND triggers the
- // `SessionExpired` publish. End-to-end: build the typed error → flatten → classify.
- let flat = crate::the hosted layer's flatten step(anyhow::Error::new(
- crate::backend::BackendApiError::Unauthorized {
- method: "GET".to_string(),
- path: "/teams/me/usage".to_string(),
- },
- ));
+ // 401 is suppressed from Sentry (TAURI-RUST-8WY, TAURI-RUST-8WZ) AND triggers the
+ // `SessionExpired` publish. End-to-end: classify the flattened sentinel.
+ let flat = "SESSION_EXPIRED: backend rejected session token on GET /some/route".to_string();
assert!(
is_session_expired_error(&flat),
"flattened backend Unauthorized must classify as session expiry: {flat}"