Merge pull request #1591 from ksylvan/0707-anthropic-can-now-use-only-oauth

Improved Anthropic Plugin Configuration Logic
This commit is contained in:
Kayvan Sylvan
2025-07-07 03:22:27 -07:00
committed by GitHub
2 changed files with 36 additions and 6 deletions

View File

@@ -243,7 +243,7 @@ func (o *PluginRegistry) SetupVendor(vendorName string) (err error) {
func (o *PluginRegistry) ConfigureVendors() {
o.VendorManager.Clear()
for _, vendor := range o.VendorsAll.Vendors {
if vendorErr := vendor.Configure(); vendorErr == nil {
if vendorErr := vendor.Configure(); vendorErr == nil && vendor.IsConfigured() {
o.VendorManager.AddVendors(vendor)
}
}

View File

@@ -19,6 +19,8 @@ const webSearchToolName = "web_search"
const webSearchToolType = "web_search_20250305"
const sourcesHeader = "## Sources"
const vendorTokenIdentifier = "claude"
func NewClient() (ret *Client) {
vendorName := "Anthropic"
ret = &Client{}
@@ -32,11 +34,7 @@ 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
ret.defaultRequiredUserMessage = "Hi"
@@ -52,6 +50,38 @@ func NewClient() (ret *Client) {
return
}
// IsConfigured returns true if either the API key or OAuth is configured
func (an *Client) IsConfigured() bool {
// Check if API key is configured
if an.ApiKey.Value != "" {
return true
}
// Check if OAuth is enabled and has a valid token
if plugins.ParseBoolElseFalse(an.UseOAuth.Value) {
storage, err := common.NewOAuthStorage()
if err != nil {
return false
}
// If no valid token exists, automatically run OAuth flow
if !storage.HasValidToken(vendorTokenIdentifier, 5) {
fmt.Println("OAuth enabled but no valid token found. Starting authentication...")
_, err := RunOAuthFlow()
if err != nil {
fmt.Printf("OAuth authentication failed: %v\n", err)
return false
}
// After successful OAuth flow, check again
return storage.HasValidToken("claude", 5)
}
return true
}
return false
}
type Client struct {
*plugins.PluginBase
ApiBaseURL *plugins.SetupQuestion