@@ -15,6 +15,23 @@ import (
1515
1616var AzureResourceNameRegex = regexp .MustCompile (`^[a-z0-9]([a-z0-9-]*[a-z0-9])?$` )
1717
18+ const (
19+ OpenAIResponsesEndpoint = "https://api.openai.com/v1/responses"
20+ OpenAIChatEndpoint = "https://api.openai.com/v1/chat/completions"
21+ OpenRouterChatEndpoint = "https://openrouter.ai/api/v1/chat/completions"
22+ AzureLegacyEndpointTemplate = "https://%s.openai.azure.com/openai/deployments/%s/chat/completions?api-version=%s"
23+ AzureResponsesEndpointTemplate = "https://%s.openai.azure.com/openai/v1/responses"
24+ AzureChatEndpointTemplate = "https://%s.openai.azure.com/openai/v1/chat/completions"
25+ GoogleGeminiEndpointTemplate = "https://generativelanguage.googleapis.com/v1beta/models/%s:streamGenerateContent"
26+
27+ AzureLegacyDefaultAPIVersion = "2025-04-01-preview"
28+
29+ OpenAIAPITokenSecretName = "OPENAI_KEY"
30+ OpenRouterAPITokenSecretName = "OPENROUTER_KEY"
31+ AzureOpenAIAPITokenSecretName = "AZURE_OPENAI_KEY"
32+ GoogleAIAPITokenSecretName = "GOOGLE_AI_KEY"
33+ )
34+
1835func resolveAIMode (requestedMode string , premium bool ) (string , * wconfig.AIModeConfigType , error ) {
1936 mode := requestedMode
2037 if mode == "" {
@@ -52,14 +69,21 @@ func applyProviderDefaults(config *wconfig.AIModeConfigType) {
5269 }
5370 }
5471 if config .Provider == uctypes .AIProvider_OpenAI {
55- if config .Endpoint == "" {
56- config .Endpoint = uctypes .DefaultOpenAIEndpoint
57- }
5872 if config .APIType == "" {
5973 config .APIType = getOpenAIAPIType (config .Model )
6074 }
75+ if config .Endpoint == "" {
76+ switch config .APIType {
77+ case uctypes .APIType_OpenAIResponses :
78+ config .Endpoint = OpenAIResponsesEndpoint
79+ case uctypes .APIType_OpenAIChat :
80+ config .Endpoint = OpenAIChatEndpoint
81+ default :
82+ config .Endpoint = OpenAIChatEndpoint
83+ }
84+ }
6185 if config .APITokenSecretName == "" {
62- config .APITokenSecretName = "OPENAI_KEY"
86+ config .APITokenSecretName = OpenAIAPITokenSecretName
6387 }
6488 if len (config .Capabilities ) == 0 {
6589 if isO1Model (config .Model ) {
@@ -70,29 +94,29 @@ func applyProviderDefaults(config *wconfig.AIModeConfigType) {
7094 }
7195 }
7296 if config .Provider == uctypes .AIProvider_OpenRouter {
73- if config .Endpoint == "" {
74- config .Endpoint = uctypes .DefaultOpenRouterEndpoint
75- }
7697 if config .APIType == "" {
7798 config .APIType = uctypes .APIType_OpenAIChat
7899 }
100+ if config .Endpoint == "" {
101+ config .Endpoint = OpenRouterChatEndpoint
102+ }
79103 if config .APITokenSecretName == "" {
80- config .APITokenSecretName = "OPENROUTER_KEY"
104+ config .APITokenSecretName = OpenRouterAPITokenSecretName
81105 }
82106 }
83107 if config .Provider == uctypes .AIProvider_AzureLegacy {
84108 if config .AzureAPIVersion == "" {
85- config .AzureAPIVersion = "2025-04-01-preview"
109+ config .AzureAPIVersion = AzureLegacyDefaultAPIVersion
86110 }
87111 if config .Endpoint == "" && isValidAzureResourceName (config .AzureResourceName ) && config .AzureDeployment != "" {
88- config .Endpoint = fmt .Sprintf ("https://%s.openai.azure.com/openai/deployments/%s/chat/completions?api-version=%s" ,
112+ config .Endpoint = fmt .Sprintf (AzureLegacyEndpointTemplate ,
89113 config .AzureResourceName , config .AzureDeployment , config .AzureAPIVersion )
90114 }
91115 if config .APIType == "" {
92116 config .APIType = uctypes .APIType_OpenAIChat
93117 }
94118 if config .APITokenSecretName == "" {
95- config .APITokenSecretName = "AZURE_OPENAI_KEY"
119+ config .APITokenSecretName = AzureOpenAIAPITokenSecretName
96120 }
97121 }
98122 if config .Provider == uctypes .AIProvider_Azure {
@@ -103,27 +127,26 @@ func applyProviderDefaults(config *wconfig.AIModeConfigType) {
103127 config .APIType = getAzureAPIType (config .Model )
104128 }
105129 if config .Endpoint == "" && isValidAzureResourceName (config .AzureResourceName ) && isAzureAPIType (config .APIType ) {
106- base := fmt .Sprintf ("https://%s.openai.azure.com/openai/v1" , config .AzureResourceName )
107130 switch config .APIType {
108131 case uctypes .APIType_OpenAIResponses :
109- config .Endpoint = base + "/responses"
132+ config .Endpoint = fmt . Sprintf ( AzureResponsesEndpointTemplate , config . AzureResourceName )
110133 case uctypes .APIType_OpenAIChat :
111- config .Endpoint = base + "/chat/completions"
134+ config .Endpoint = fmt . Sprintf ( AzureChatEndpointTemplate , config . AzureResourceName )
112135 }
113136 }
114137 if config .APITokenSecretName == "" {
115- config .APITokenSecretName = "AZURE_OPENAI_KEY"
138+ config .APITokenSecretName = AzureOpenAIAPITokenSecretName
116139 }
117140 }
118141 if config .Provider == uctypes .AIProvider_Google {
119142 if config .APIType == "" {
120143 config .APIType = uctypes .APIType_GoogleGemini
121144 }
122145 if config .Endpoint == "" && config .Model != "" {
123- config .Endpoint = fmt .Sprintf ("https://generativelanguage.googleapis.com/v1beta/models/%s:streamGenerateContent" , config .Model )
146+ config .Endpoint = fmt .Sprintf (GoogleGeminiEndpointTemplate , config .Model )
124147 }
125148 if config .APITokenSecretName == "" {
126- config .APITokenSecretName = "GOOGLE_AI_KEY"
149+ config .APITokenSecretName = GoogleAIAPITokenSecretName
127150 }
128151 if len (config .Capabilities ) == 0 {
129152 config .Capabilities = []string {uctypes .AICapabilityTools , uctypes .AICapabilityImages , uctypes .AICapabilityPdfs }
0 commit comments