@@ -19,6 +19,8 @@ const webSearchToolName = "web_search"
19
19
const webSearchToolType = "web_search_20250305"
20
20
const sourcesHeader = "## Sources"
21
21
22
+ const vendorTokenIdentifier = "claude"
23
+
22
24
func NewClient () (ret * Client ) {
23
25
vendorName := "Anthropic"
24
26
ret = & Client {}
@@ -32,11 +34,7 @@ func NewClient() (ret *Client) {
32
34
ret .ApiBaseURL = ret .AddSetupQuestion ("API Base URL" , false )
33
35
ret .ApiBaseURL .Value = defaultBaseUrl
34
36
ret .UseOAuth = ret .AddSetupQuestionBool ("Use OAuth login" , false )
35
- if plugins .ParseBoolElseFalse (ret .UseOAuth .Value ) {
36
- ret .ApiKey = ret .PluginBase .AddSetupQuestion ("API key" , false )
37
- } else {
38
- ret .ApiKey = ret .PluginBase .AddSetupQuestion ("API key" , true )
39
- }
37
+ ret .ApiKey = ret .PluginBase .AddSetupQuestion ("API key" , false )
40
38
41
39
ret .maxTokens = 4096
42
40
ret .defaultRequiredUserMessage = "Hi"
@@ -52,6 +50,38 @@ func NewClient() (ret *Client) {
52
50
return
53
51
}
54
52
53
+ // IsConfigured returns true if either the API key or OAuth is configured
54
+ func (an * Client ) IsConfigured () bool {
55
+ // Check if API key is configured
56
+ if an .ApiKey .Value != "" {
57
+ return true
58
+ }
59
+
60
+ // Check if OAuth is enabled and has a valid token
61
+ if plugins .ParseBoolElseFalse (an .UseOAuth .Value ) {
62
+ storage , err := common .NewOAuthStorage ()
63
+ if err != nil {
64
+ return false
65
+ }
66
+
67
+ // If no valid token exists, automatically run OAuth flow
68
+ if ! storage .HasValidToken (vendorTokenIdentifier , 5 ) {
69
+ fmt .Println ("OAuth enabled but no valid token found. Starting authentication..." )
70
+ _ , err := RunOAuthFlow ()
71
+ if err != nil {
72
+ fmt .Printf ("OAuth authentication failed: %v\n " , err )
73
+ return false
74
+ }
75
+ // After successful OAuth flow, check again
76
+ return storage .HasValidToken ("claude" , 5 )
77
+ }
78
+
79
+ return true
80
+ }
81
+
82
+ return false
83
+ }
84
+
55
85
type Client struct {
56
86
* plugins.PluginBase
57
87
ApiBaseURL * plugins.SetupQuestion
0 commit comments