Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/core/config/ProviderSettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ export class ProviderSettingsManager {

let isDirty = false

// Migrate existing installs to have per-mode API config map
if (!providerProfiles.modeApiConfigs) {
// Use the currently selected config for all modes initially
const currentName = providerProfiles.currentApiConfigName
const seedId =
providerProfiles.apiConfigs[currentName]?.id ??
Object.values(providerProfiles.apiConfigs)[0]?.id ??
this.defaultConfigId
providerProfiles.modeApiConfigs = Object.fromEntries(modes.map((m) => [m.slug, seedId]))
isDirty = true
}

// Ensure all configs have IDs.
for (const [_name, apiConfig] of Object.entries(providerProfiles.apiConfigs)) {
if (!apiConfig.id) {
Expand Down Expand Up @@ -307,8 +319,12 @@ export class ProviderSettingsManager {
try {
return await this.lock(async () => {
const providerProfiles = await this.load()
const { modeApiConfigs = {} } = providerProfiles
modeApiConfigs[mode] = configId
// Ensure the per-mode config map exists
if (!providerProfiles.modeApiConfigs) {
providerProfiles.modeApiConfigs = {}
}
// Assign the chosen config ID to this mode
providerProfiles.modeApiConfigs[mode] = configId
await this.store(providerProfiles)
})
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe("ProviderSettingsManager", () => {
fuzzyMatchThreshold: 1.0,
},
},
modeApiConfigs: {},
migrations: {
rateLimitSecondsMigrated: true,
diffSettingsMigrated: true,
Expand Down