Repository navigation
refactor(agent): share model endpoint resolution #7942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //! Endpoint resolution shared by agent startup and desktop security suggestions. | ||
| use super::Provider; | ||
|
|
||
| pub fn provider_base_url( | ||
| provider: &Provider, | ||
| lookup: impl Fn(&str) -> Option<String>, | ||
| ) -> Result<String, String> { | ||
| let (key, default) = match provider { | ||
| Provider::Anthropic => ("ANTHROPIC_BASE_URL", Some("https://api.anthropic.com")), | ||
| Provider::OpenAi => ("OPENAI_COMPAT_BASE_URL", Some("https://api.openai.com/v1")), | ||
| Provider::OpenRouter => ("OPENROUTER_BASE_URL", Some("https://openrouter.ai/api/v1")), | ||
| Provider::Databricks | Provider::DatabricksV2 => ("DATABRICKS_HOST", None), | ||
| }; | ||
| lookup(key) | ||
| .or_else(|| default.map(str::to_owned)) | ||
| .ok_or_else(|| format!("config: {key} required")) | ||
| } | ||
|
|
||
| /// Resolve without fetching credentials, signing in, or making network requests. | ||
| pub fn configured_endpoint(lookup: impl Fn(&str) -> Option<String>) -> Option<String> { | ||
|
Comment on lines
+19
to
+20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 I think this one needs a sentence or two of contract. My guess is that's why the bot keeps flagging it, though I agree full Rustdoc on Related: for an allowlist use case, |
||
| let provider = super::resolve_provider( | ||
| lookup("BUZZ_AGENT_PROVIDER").as_deref(), | ||
| Some("configured"), | ||
| Some("configured"), | ||
| Some("configured"), | ||
| ) | ||
|
Comment on lines
+21
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 The |
||
| .ok()?; | ||
| provider_base_url(&provider, lookup).ok() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| #[test] | ||
| fn endpoints_follow_selected_provider_and_overrides() { | ||
| for (provider, expected) in [ | ||
| ("anthropic", "https://api.anthropic.com"), | ||
| ("openai-compat", "https://api.openai.com/v1"), | ||
| ("openrouter", "https://openrouter.ai/api/v1"), | ||
| ] { | ||
| assert_eq!( | ||
| configured_endpoint(|key| (key == "BUZZ_AGENT_PROVIDER").then(|| provider.into())) | ||
| .as_deref(), | ||
| Some(expected) | ||
| ); | ||
| } | ||
| assert_eq!( | ||
| configured_endpoint(|key| match key { | ||
| "BUZZ_AGENT_PROVIDER" => Some("databricks_v2".into()), | ||
| "DATABRICKS_HOST" => Some("https://workspace.example.com".into()), | ||
| _ => None, | ||
| }) | ||
| .as_deref(), | ||
| Some("https://workspace.example.com") | ||
| ); | ||
| assert!(configured_endpoint(|_| None).is_none()); | ||
| assert_eq!( | ||
| provider_base_url(&Provider::OpenAi, |_| Some( | ||
| "http://localhost:1234/v1".into() | ||
| )) | ||
| .unwrap(), | ||
| "http://localhost:1234/v1" | ||
| ); | ||
|
Comment on lines
+57
to
+63
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 This lookup returns the custom URL for any key, so if OpenAI's override key accidentally became |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provider_base_urlis newly exposed through the publicconfig::endpointmodule but has no Rustdoc describing its lookup contract, provider defaults, or the required Databricks host. Add a doc comment, or restrict its visibility if it is not intended for external launchers, to satisfy the repository requirement that every new public API be documented.AGENTS.md reference: AGENTS.md:L193-L196
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems overkill for a lookup?