Refactor checkExistKey to use centralized SECRET_KEYS array

This commit is contained in:
sam hoang 2025-02-27 15:47:24 +07:00
parent 381b07849a
commit 167229fa73

View file

@ -1,23 +1,20 @@
import { ApiConfiguration } from "../shared/api"
import { SECRET_KEYS } from "./globalState"
export function checkExistKey(config: ApiConfiguration | undefined) {
return config
? [
config.apiKey,
config.glamaApiKey,
config.openRouterApiKey,
config.awsRegion,
config.vertexProjectId,
config.openAiApiKey,
config.ollamaModelId,
config.lmStudioModelId,
config.geminiApiKey,
config.openAiNativeApiKey,
config.deepSeekApiKey,
config.mistralApiKey,
config.vsCodeLmModelSelector,
config.requestyApiKey,
config.unboundApiKey,
].some((key) => key !== undefined)
: false
if (!config) return false
// Check all secret keys from the centralized SECRET_KEYS array
const hasSecretKey = SECRET_KEYS.some((key) => config[key as keyof ApiConfiguration] !== undefined)
// Check additional non-secret configuration properties
const hasOtherConfig = [
config.awsRegion,
config.vertexProjectId,
config.ollamaModelId,
config.lmStudioModelId,
config.vsCodeLmModelSelector,
].some((value) => value !== undefined)
return hasSecretKey || hasOtherConfig
}