Skip to content

Commit 01fec4c

Browse files
authored
fix: migrate and persist modeApiConfigs for per-mode API profiles (#3071)
1 parent bf38b83 commit 01fec4c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/core/config/ProviderSettingsManager.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ export class ProviderSettingsManager {
7979

8080
let isDirty = false
8181

82+
// Migrate existing installs to have per-mode API config map
83+
if (!providerProfiles.modeApiConfigs) {
84+
// Use the currently selected config for all modes initially
85+
const currentName = providerProfiles.currentApiConfigName
86+
const seedId =
87+
providerProfiles.apiConfigs[currentName]?.id ??
88+
Object.values(providerProfiles.apiConfigs)[0]?.id ??
89+
this.defaultConfigId
90+
providerProfiles.modeApiConfigs = Object.fromEntries(modes.map((m) => [m.slug, seedId]))
91+
isDirty = true
92+
}
93+
8294
// Ensure all configs have IDs.
8395
for (const [_name, apiConfig] of Object.entries(providerProfiles.apiConfigs)) {
8496
if (!apiConfig.id) {
@@ -340,8 +352,12 @@ export class ProviderSettingsManager {
340352
try {
341353
return await this.lock(async () => {
342354
const providerProfiles = await this.load()
343-
const { modeApiConfigs = {} } = providerProfiles
344-
modeApiConfigs[mode] = configId
355+
// Ensure the per-mode config map exists
356+
if (!providerProfiles.modeApiConfigs) {
357+
providerProfiles.modeApiConfigs = {}
358+
}
359+
// Assign the chosen config ID to this mode
360+
providerProfiles.modeApiConfigs[mode] = configId
345361
await this.store(providerProfiles)
346362
})
347363
} catch (error) {

src/core/config/__tests__/ProviderSettingsManager.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("ProviderSettingsManager", () => {
5353
fuzzyMatchThreshold: 1.0,
5454
},
5555
},
56+
modeApiConfigs: {},
5657
migrations: {
5758
rateLimitSecondsMigrated: true,
5859
diffSettingsMigrated: true,

0 commit comments

Comments
 (0)