From f13a56685b8f8992234645bf44747cdba492da23 Mon Sep 17 00:00:00 2001 From: Kayvan Sylvan Date: Sat, 5 Jul 2025 14:46:43 -0700 Subject: [PATCH] feat: add OAuth login support for Anthropic API configuration --- plugins/ai/anthropic/anthropic.go | 5 +++ restapi/configuration.go | 72 +++++++++++++++---------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/plugins/ai/anthropic/anthropic.go b/plugins/ai/anthropic/anthropic.go index 9dd48223..3695d6f5 100644 --- a/plugins/ai/anthropic/anthropic.go +++ b/plugins/ai/anthropic/anthropic.go @@ -45,6 +45,11 @@ func NewClient() (ret *Client) { ret.ApiBaseURL = ret.AddSetupQuestion("API Base URL", false) ret.ApiBaseURL.Value = defaultBaseUrl ret.UseOAuth = ret.AddSetupQuestionBool("Use OAuth login", false) + if plugins.ParseBoolElseFalse(ret.UseOAuth.Value) { + ret.ApiKey = ret.PluginBase.AddSetupQuestion("API key", false) + } else { + ret.ApiKey = ret.PluginBase.AddSetupQuestion("API key", true) + } ret.ApiKey = ret.PluginBase.AddSetupQuestion("API key", false) ret.maxTokens = 4096 diff --git a/restapi/configuration.go b/restapi/configuration.go index f2a7b958..da33cd06 100755 --- a/restapi/configuration.go +++ b/restapi/configuration.go @@ -57,18 +57,18 @@ func (h *ConfigHandler) GetConfig(c *gin.Context) { } config := map[string]string{ - "openai": os.Getenv("OPENAI_API_KEY"), - "anthropic": os.Getenv("ANTHROPIC_API_KEY"), - "anthropic_auth_token": os.Getenv("ANTHROPIC_AUTH_TOKEN"), - "groq": os.Getenv("GROQ_API_KEY"), - "mistral": os.Getenv("MISTRAL_API_KEY"), - "gemini": os.Getenv("GEMINI_API_KEY"), - "ollama": os.Getenv("OLLAMA_URL"), - "openrouter": os.Getenv("OPENROUTER_API_KEY"), - "silicon": os.Getenv("SILICON_API_KEY"), - "deepseek": os.Getenv("DEEPSEEK_API_KEY"), - "grokai": os.Getenv("GROKAI_API_KEY"), - "lmstudio": os.Getenv("LM_STUDIO_API_BASE_URL"), + "openai": os.Getenv("OPENAI_API_KEY"), + "anthropic": os.Getenv("ANTHROPIC_API_KEY"), + "anthropic_use_oauth_login": os.Getenv("ANTHROPIC_USE_OAUTH_LOGIN"), + "groq": os.Getenv("GROQ_API_KEY"), + "mistral": os.Getenv("MISTRAL_API_KEY"), + "gemini": os.Getenv("GEMINI_API_KEY"), + "ollama": os.Getenv("OLLAMA_URL"), + "openrouter": os.Getenv("OPENROUTER_API_KEY"), + "silicon": os.Getenv("SILICON_API_KEY"), + "deepseek": os.Getenv("DEEPSEEK_API_KEY"), + "grokai": os.Getenv("GROKAI_API_KEY"), + "lmstudio": os.Getenv("LM_STUDIO_API_BASE_URL"), } c.JSON(http.StatusOK, config) @@ -81,18 +81,18 @@ func (h *ConfigHandler) UpdateConfig(c *gin.Context) { } var config struct { - OpenAIApiKey string `json:"openai_api_key"` - AnthropicApiKey string `json:"anthropic_api_key"` - AnthropicAuthToken string `json:"anthropic_auth_token"` - GroqApiKey string `json:"groq_api_key"` - MistralApiKey string `json:"mistral_api_key"` - GeminiApiKey string `json:"gemini_api_key"` - OllamaURL string `json:"ollama_url"` - OpenRouterApiKey string `json:"openrouter_api_key"` - SiliconApiKey string `json:"silicon_api_key"` - DeepSeekApiKey string `json:"deepseek_api_key"` - GrokaiApiKey string `json:"grokai_api_key"` - LMStudioURL string `json:"lm_studio_base_url"` + OpenAIApiKey string `json:"openai_api_key"` + AnthropicApiKey string `json:"anthropic_api_key"` + AnthropicUseAuthToken string `json:"anthropic_use_auth_token"` + GroqApiKey string `json:"groq_api_key"` + MistralApiKey string `json:"mistral_api_key"` + GeminiApiKey string `json:"gemini_api_key"` + OllamaURL string `json:"ollama_url"` + OpenRouterApiKey string `json:"openrouter_api_key"` + SiliconApiKey string `json:"silicon_api_key"` + DeepSeekApiKey string `json:"deepseek_api_key"` + GrokaiApiKey string `json:"grokai_api_key"` + LMStudioURL string `json:"lm_studio_base_url"` } if err := c.ShouldBindJSON(&config); err != nil { @@ -101,18 +101,18 @@ func (h *ConfigHandler) UpdateConfig(c *gin.Context) { } envVars := map[string]string{ - "OPENAI_API_KEY": config.OpenAIApiKey, - "ANTHROPIC_API_KEY": config.AnthropicApiKey, - "ANTHROPIC_AUTH_TOKEN": config.AnthropicAuthToken, - "GROQ_API_KEY": config.GroqApiKey, - "MISTRAL_API_KEY": config.MistralApiKey, - "GEMINI_API_KEY": config.GeminiApiKey, - "OLLAMA_URL": config.OllamaURL, - "OPENROUTER_API_KEY": config.OpenRouterApiKey, - "SILICON_API_KEY": config.SiliconApiKey, - "DEEPSEEK_API_KEY": config.DeepSeekApiKey, - "GROKAI_API_KEY": config.GrokaiApiKey, - "LM_STUDIO_API_BASE_URL": config.LMStudioURL, + "OPENAI_API_KEY": config.OpenAIApiKey, + "ANTHROPIC_API_KEY": config.AnthropicApiKey, + "ANTHROPIC_USE_OAUTH_LOGIN": config.AnthropicUseAuthToken, + "GROQ_API_KEY": config.GroqApiKey, + "MISTRAL_API_KEY": config.MistralApiKey, + "GEMINI_API_KEY": config.GeminiApiKey, + "OLLAMA_URL": config.OllamaURL, + "OPENROUTER_API_KEY": config.OpenRouterApiKey, + "SILICON_API_KEY": config.SiliconApiKey, + "DEEPSEEK_API_KEY": config.DeepSeekApiKey, + "GROKAI_API_KEY": config.GrokaiApiKey, + "LM_STUDIO_API_BASE_URL": config.LMStudioURL, } var envContent strings.Builder