(options)
| 963 | } |
| 964 | |
| 965 | function migrateUserConfig(options) { |
| 966 | const migrated = { ...options } |
| 967 | let dirty = false |
| 968 | |
| 969 | if (migrated.customChatGptWebApiUrl === 'https://chat.openai.com') { |
| 970 | migrated.customChatGptWebApiUrl = 'https://chatgpt.com' |
| 971 | dirty = true |
| 972 | } |
| 973 | |
| 974 | const canonicalModelName = canonicalizeModelKey(migrated.modelName) |
| 975 | if (canonicalModelName !== migrated.modelName) { |
| 976 | migrated.modelName = canonicalModelName |
| 977 | dirty = true |
| 978 | } |
| 979 | |
| 980 | const canonicalActiveApiModes = canonicalizeModelKeyArray(migrated.activeApiModes) |
| 981 | if (canonicalActiveApiModes !== migrated.activeApiModes) { |
| 982 | migrated.activeApiModes = canonicalActiveApiModes |
| 983 | dirty = true |
| 984 | } |
| 985 | |
| 986 | const hasProviderSecretsRecord = isPlainObject(migrated.providerSecrets) |
| 987 | const providerSecrets = hasProviderSecretsRecord ? { ...migrated.providerSecrets } : {} |
| 988 | if (!hasProviderSecretsRecord) { |
| 989 | dirty = true |
| 990 | } |
| 991 | for (const [legacyKey, providerId] of Object.entries(LEGACY_SECRET_KEY_TO_PROVIDER_ID)) { |
| 992 | const legacyKeyValue = normalizeText(migrated[legacyKey]) |
| 993 | const hasProviderSecret = Object.hasOwn(providerSecrets, providerId) |
| 994 | if (legacyKeyValue && !hasProviderSecret) { |
| 995 | providerSecrets[providerId] = legacyKeyValue |
| 996 | dirty = true |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | const builtinProviderIds = new Set( |
| 1001 | Object.values(API_MODE_GROUP_TO_PROVIDER_ID) |
| 1002 | .map((providerId) => normalizeText(providerId)) |
| 1003 | .filter((providerId) => providerId), |
| 1004 | ) |
| 1005 | const providerIdSet = new Set(builtinProviderIds) |
| 1006 | const providerIdRenameLookup = new Map() |
| 1007 | const providerIdRenames = [] |
| 1008 | const rawCustomOpenAIProviders = Array.isArray(migrated.customOpenAIProviders) |
| 1009 | ? migrated.customOpenAIProviders |
| 1010 | : [] |
| 1011 | const legacyCustomProviderIds = new Set( |
| 1012 | rawCustomOpenAIProviders |
| 1013 | .map((provider) => normalizeProviderId(provider?.id)) |
| 1014 | .filter((providerId) => providerId), |
| 1015 | ) |
| 1016 | const normalizedProviderResults = rawCustomOpenAIProviders |
| 1017 | .map((provider, index) => normalizeCustomProviderForStorage(provider, index, providerIdSet)) |
| 1018 | .filter((result) => result && result.provider) |
| 1019 | const unchangedProviderIds = new Set( |
| 1020 | normalizedProviderResults |
| 1021 | .filter( |
| 1022 | ({ originalId, provider }) => originalId && originalId === normalizeProviderId(provider.id), |
no test coverage detected