mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-20 17:02:18 +00:00
fix: support Claude OAuth token for model listing (#109)
This commit is contained in:
parent
a7b3881099
commit
a5a6492165
3 changed files with 188 additions and 1 deletions
|
|
@ -55,6 +55,32 @@ static USER_MESSAGE_COUNTER: AtomicU64 = AtomicU64::new(1);
|
|||
const ANTHROPIC_MODELS_URL: &str = "https://api.anthropic.com/v1/models?beta=true";
|
||||
const ANTHROPIC_VERSION: &str = "2023-06-01";
|
||||
|
||||
fn claude_oauth_fallback_models() -> AgentModelsResponse {
|
||||
AgentModelsResponse {
|
||||
models: vec![
|
||||
AgentModelInfo {
|
||||
id: "default".to_string(),
|
||||
name: Some("Default (recommended)".to_string()),
|
||||
variants: None,
|
||||
default_variant: None,
|
||||
},
|
||||
AgentModelInfo {
|
||||
id: "opus".to_string(),
|
||||
name: Some("Opus".to_string()),
|
||||
variants: None,
|
||||
default_variant: None,
|
||||
},
|
||||
AgentModelInfo {
|
||||
id: "haiku".to_string(),
|
||||
name: Some("Haiku".to_string()),
|
||||
variants: None,
|
||||
default_variant: None,
|
||||
},
|
||||
],
|
||||
default_model: Some("default".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum BrandingMode {
|
||||
#[default]
|
||||
|
|
@ -3318,6 +3344,13 @@ impl SessionManager {
|
|||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
if matches!(cred.auth_type, AuthType::Oauth) {
|
||||
tracing::warn!(
|
||||
status = %status,
|
||||
"Anthropic model list rejected OAuth credentials; using Claude OAuth fallback models"
|
||||
);
|
||||
return Ok(claude_oauth_fallback_models());
|
||||
}
|
||||
return Err(SandboxError::StreamError {
|
||||
message: format!("Anthropic models request failed {status}: {body}"),
|
||||
});
|
||||
|
|
@ -3372,6 +3405,13 @@ impl SessionManager {
|
|||
default_model = models.first().map(|model| model.id.clone());
|
||||
}
|
||||
|
||||
if models.is_empty() && matches!(cred.auth_type, AuthType::Oauth) {
|
||||
tracing::warn!(
|
||||
"Anthropic model list was empty for OAuth credentials; using Claude OAuth fallback models"
|
||||
);
|
||||
return Ok(claude_oauth_fallback_models());
|
||||
}
|
||||
|
||||
Ok(AgentModelsResponse {
|
||||
models,
|
||||
default_model,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue