Skip to content

Commit cc85602

Browse files
committed
Use constants instead of hard-coded strings in buildApiHandler; fix
vercel copy/pasta Signed-off-by: Geoff Wilson <[email protected]>
1 parent 4736894 commit cc85602

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

packages/types/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const API_KEYS = {
2424
IO_INTELLIGENCE: 'IOINTELLIGENCE_API_KEY',
2525
MOONSHOOT: 'MOONSHOT_API_KEY',
2626
SAMBA_NOVA: 'SAMBANOVA_API_KEY',
27-
VERCEL_NOVA: 'VERCEL_API_KEY',
27+
VERCEL: 'VERCEL_API_KEY',
2828
ZAI: 'ZAI_API_KEY',
2929
} as const
3030

src/api/index.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Anthropic } from "@anthropic-ai/sdk"
22

33
import type { ProviderSettings, ModelInfo } from "@roo-code/types"
4+
import { API_KEYS } from "@roo-code/types"
45

56
import { ApiStream } from "./transform/stream"
67

@@ -107,19 +108,19 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
107108
switch (apiProvider) {
108109
case "anthropic":
109110
if (options.anthropicConfigUseEnvVars) {
110-
options.apiKey = getEnvVar("ANTHROPIC_API_KEY", options.apiKey)
111+
options.apiKey = getEnvVar(API_KEYS.ANTHROPIC, options.apiKey)
111112
}
112113
return new AnthropicHandler(options)
113114
case "claude-code":
114115
return new ClaudeCodeHandler(options)
115116
case "glama":
116117
if (options.glamaConfigUseEnvVars) {
117-
options.glamaApiKey = getEnvVar("GLAMA_API_KEY", options.glamaApiKey)
118+
options.glamaApiKey = getEnvVar(API_KEYS.GLAMA, options.glamaApiKey)
118119
}
119120
return new GlamaHandler(options)
120121
case "openrouter":
121122
if (options.openRouterConfigUseEnvVars) {
122-
options.openRouterApiKey = getEnvVar("OPENROUTER_API_KEY", options.openRouterApiKey)
123+
options.openRouterApiKey = getEnvVar(API_KEYS.OPEN_ROUTER, options.openRouterApiKey)
123124
}
124125
return new OpenRouterHandler(options)
125126
case "bedrock":
@@ -130,7 +131,7 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
130131
: new VertexHandler(options)
131132
case "openai":
132133
if (options.openAiConfigUseEnvVars) {
133-
options.openAiApiKey = getEnvVar("OPENAI_API_KEY", options.openAiApiKey)
134+
options.openAiApiKey = getEnvVar(API_KEYS.OPENAI, options.openAiApiKey)
134135
}
135136
return new OpenAiHandler(options)
136137
case "ollama":
@@ -139,46 +140,46 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
139140
return new LmStudioHandler(options)
140141
case "gemini":
141142
if (options.geminiConfigUseEnvVars) {
142-
options.geminiApiKey = getEnvVar("GEMINI_API_KEY", options.geminiApiKey)
143+
options.geminiApiKey = getEnvVar(API_KEYS.GEMINI, options.geminiApiKey)
143144
}
144145
return new GeminiHandler(options)
145146
case "openai-native":
146147
if (options.openAiNativeConfigUseEnvVars) {
147-
options.openAiNativeApiKey = getEnvVar("OPENAI_API_KEY", options.openAiNativeApiKey)
148+
options.openAiNativeApiKey = getEnvVar(API_KEYS.OPENAI, options.openAiNativeApiKey)
148149
}
149150
return new OpenAiNativeHandler(options)
150151
case "deepseek":
151152
if (options.deepSeekConfigUseEnvVars) {
152-
options.deepSeekApiKey = getEnvVar("DEEPSEEK_API_KEY", options.deepSeekApiKey)
153+
options.deepSeekApiKey = getEnvVar(API_KEYS.DEEP_SEEK, options.deepSeekApiKey)
153154
}
154155
return new DeepSeekHandler(options)
155156
case "doubao":
156157
if (options.doubaoConfigUseEnvVars) {
157-
options.doubaoApiKey = getEnvVar("DOUBAO_API_KEY", options.doubaoApiKey)
158+
options.doubaoApiKey = getEnvVar(API_KEYS.DOUBAO, options.doubaoApiKey)
158159
}
159160
return new DoubaoHandler(options)
160161
case "qwen-code":
161162
return new QwenCodeHandler(options)
162163
case "moonshot":
163164
if (options.moonshotConfigUseEnvVars) {
164-
options.moonshotApiKey = getEnvVar("MOONSHOT_API_KEY", options.moonshotApiKey)
165+
options.moonshotApiKey = getEnvVar(API_KEYS.MOONSHOOT, options.moonshotApiKey)
165166
}
166167
return new MoonshotHandler(options)
167168
case "vscode-lm":
168169
return new VsCodeLmHandler(options)
169170
case "mistral":
170171
if (options.mistralConfigUseEnvVars) {
171-
options.mistralApiKey = getEnvVar("MISTRAL_API_KEY", options.mistralApiKey)
172+
options.mistralApiKey = getEnvVar(API_KEYS.MISTRAL, options.mistralApiKey)
172173
}
173174
return new MistralHandler(options)
174175
case "unbound":
175176
if (options.unboundConfigUseEnvVars) {
176-
options.unboundApiKey = getEnvVar("UNBOUND_API_KEY", options.unboundApiKey)
177+
options.unboundApiKey = getEnvVar(API_KEYS.UNBOUND, options.unboundApiKey)
177178
}
178179
return new UnboundHandler(options)
179180
case "requesty":
180181
if (options.requestyConfigUseEnvVars) {
181-
options.requestyApiKey = getEnvVar("REQUESTY_API_KEY", options.requestyApiKey)
182+
options.requestyApiKey = getEnvVar(API_KEYS.REQUESTY, options.requestyApiKey)
182183
}
183184
return new RequestyHandler(options)
184185
case "human-relay":
@@ -187,57 +188,57 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
187188
return new FakeAIHandler(options)
188189
case "xai":
189190
if (options.xaiConfigUseEnvVars) {
190-
options.xaiApiKey = getEnvVar("XAI_API_KEY", options.xaiApiKey)
191+
options.xaiApiKey = getEnvVar(API_KEYS.XAI, options.xaiApiKey)
191192
}
192193
return new XAIHandler(options)
193194
case "groq":
194195
if (options.groqConfigUseEnvVars) {
195-
options.groqApiKey = getEnvVar("GROQ_API_KEY", options.groqApiKey)
196+
options.groqApiKey = getEnvVar(API_KEYS.GROQ, options.groqApiKey)
196197
}
197198
return new GroqHandler(options)
198199
case "deepinfra":
199200
if (options.deepInfraConfigUseEnvVars) {
200-
options.deepInfraApiKey = getEnvVar("DEEPINFRA_API_KEY", options.deepInfraApiKey)
201+
options.deepInfraApiKey = getEnvVar(API_KEYS.DEEP_INFRA, options.deepInfraApiKey)
201202
}
202203
return new DeepInfraHandler(options)
203204
case "huggingface":
204205
if (options.huggingFaceConfigUseEnvVars) {
205-
options.huggingFaceApiKey = getEnvVar("HUGGINGFACE_API_KEY", options.huggingFaceApiKey)
206+
options.huggingFaceApiKey = getEnvVar(API_KEYS.HUGGING_FACE, options.huggingFaceApiKey)
206207
}
207208
return new HuggingFaceHandler(options)
208209
case "chutes":
209210
if (options.chutesConfigUseEnvVars) {
210-
options.chutesApiKey = getEnvVar("CHUTES_API_KEY", options.chutesApiKey)
211+
options.chutesApiKey = getEnvVar(API_KEYS.CHUTES, options.chutesApiKey)
211212
}
212213
return new ChutesHandler(options)
213214
case "litellm":
214215
if (options.litellmConfigUseEnvVars) {
215-
options.litellmApiKey = getEnvVar("LITELLM_API_KEY", options.litellmApiKey)
216+
options.litellmApiKey = getEnvVar(API_KEYS.LITELLM, options.litellmApiKey)
216217
}
217218
return new LiteLLMHandler(options)
218219
case "cerebras":
219220
if (options.cerebrasConfigUseEnvVars) {
220-
options.cerebrasApiKey = getEnvVar("CEREBRAS_API_KEY", options.cerebrasApiKey)
221+
options.cerebrasApiKey = getEnvVar(API_KEYS.CEREBRAS, options.cerebrasApiKey)
221222
}
222223
return new CerebrasHandler(options)
223224
case "sambanova":
224225
if (options.sambaNovaConfigUseEnvVars) {
225-
options.sambaNovaApiKey = getEnvVar("SAMBANOVA_API_KEY", options.sambaNovaApiKey)
226+
options.sambaNovaApiKey = getEnvVar(API_KEYS.SAMBA_NOVA, options.sambaNovaApiKey)
226227
}
227228
return new SambaNovaHandler(options)
228229
case "zai":
229230
if (options.zaiConfigUseEnvVars) {
230-
options.zaiApiKey = getEnvVar("ZAI_API_KEY", options.zaiApiKey)
231+
options.zaiApiKey = getEnvVar(API_KEYS.ZAI, options.zaiApiKey)
231232
}
232233
return new ZAiHandler(options)
233234
case "fireworks":
234235
if (options.fireworksConfigUseEnvVars) {
235-
options.fireworksApiKey = getEnvVar("FIREWORKS_API_KEY", options.fireworksApiKey)
236+
options.fireworksApiKey = getEnvVar(API_KEYS.FIREWORKS, options.fireworksApiKey)
236237
}
237238
return new FireworksHandler(options)
238239
case "io-intelligence":
239240
if (options.ioIntelligenceConfigUseEnvVars) {
240-
options.ioIntelligenceApiKey = getEnvVar("IOINTELLIGENCE_API_KEY", options.ioIntelligenceApiKey)
241+
options.ioIntelligenceApiKey = getEnvVar(API_KEYS.IO_INTELLIGENCE, options.ioIntelligenceApiKey)
241242
}
242243
return new IOIntelligenceHandler(options)
243244
case "roo":
@@ -246,12 +247,12 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
246247
return new RooHandler(options)
247248
case "featherless":
248249
if (options.featherlessConfigUseEnvVars) {
249-
options.featherlessApiKey = getEnvVar("FEATHERLESS_API_KEY", options.featherlessApiKey)
250+
options.featherlessApiKey = getEnvVar(API_KEYS.FEATHERLESS, options.featherlessApiKey)
250251
}
251252
return new FeatherlessHandler(options)
252253
case "vercel-ai-gateway":
253254
if (options.vercelConfigUseEnvVars) {
254-
options.vercelAiGatewayApiKey = getEnvVar("VERCEL_API_KEY", options.vercelAiGatewayApiKey)
255+
options.vercelAiGatewayApiKey = getEnvVar(API_KEYS.VERCEL, options.vercelAiGatewayApiKey)
255256
}
256257
return new VercelAiGatewayHandler(options)
257258
default:

webview-ui/src/components/settings/providers/VercelAiGateway.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const VercelAiGateway = ({
2929
<>
3030
<ApiKey
3131
apiKey={apiConfiguration?.vercelAiGatewayApiKey || ""}
32-
apiKeyEnvVar={API_KEYS.VERCEL_NOVA}
32+
apiKeyEnvVar={API_KEYS.VERCEL}
3333
configUseEnvVars={!!apiConfiguration?.vercelConfigUseEnvVars}
3434
setApiKey={(value: string) => setApiConfigurationField("vercelAiGatewayApiKey", value)}
3535
setConfigUseEnvVars={(value: boolean) => setApiConfigurationField("vercelConfigUseEnvVars", value)}

0 commit comments

Comments
 (0)