Skip to content

Commit 4cc58c5

Browse files
committed
fix: migrate and persist missing modeApiConfigs for per-mode API profiles
- Backfill `modeApiConfigs` on initialize if absent, seeding with the current profile - Ensure `setModeConfig()` always mutates and persists the real modeApiConfigs map - Addresses regression introduced in PR #1997
1 parent b51abf7 commit 4cc58c5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/core/config/ProviderSettingsManager.ts

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

7878
let isDirty = false
7979

80+
// Migrate existing installs to have per-mode API config map
81+
if (!providerProfiles.modeApiConfigs) {
82+
// Use the currently selected config for all modes initially
83+
const currentName = providerProfiles.currentApiConfigName
84+
const seedId =
85+
providerProfiles.apiConfigs[currentName]?.id ??
86+
Object.values(providerProfiles.apiConfigs)[0]?.id ??
87+
this.defaultConfigId
88+
providerProfiles.modeApiConfigs = Object.fromEntries(modes.map((m) => [m.slug, seedId]))
89+
isDirty = true
90+
}
91+
8092
// Ensure all configs have IDs.
8193
for (const [_name, apiConfig] of Object.entries(providerProfiles.apiConfigs)) {
8294
if (!apiConfig.id) {
@@ -307,8 +319,12 @@ export class ProviderSettingsManager {
307319
try {
308320
return await this.lock(async () => {
309321
const providerProfiles = await this.load()
310-
const { modeApiConfigs = {} } = providerProfiles
311-
modeApiConfigs[mode] = configId
322+
// Ensure the per-mode config map exists
323+
if (!providerProfiles.modeApiConfigs) {
324+
providerProfiles.modeApiConfigs = {}
325+
}
326+
// Assign the chosen config ID to this mode
327+
providerProfiles.modeApiConfigs[mode] = configId
312328
await this.store(providerProfiles)
313329
})
314330
} catch (error) {

0 commit comments

Comments
 (0)