Skip to content

Commit 2d11ee3

Browse files
committed
fix: persistently storing new Gemini migrations
1 parent fa7cd5d commit 2d11ee3

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,38 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
219219
})
220220
}, [])
221221

222+
const handleLegacyGeminiModelMapping = useCallback(
223+
<K extends keyof ProviderSettings>(
224+
field: K,
225+
previousValue: ProviderSettings[K],
226+
value: ProviderSettings[K],
227+
provider: string | undefined,
228+
updatedApiConfiguration: ProviderSettings,
229+
): boolean => {
230+
if (field !== "apiModelId" || typeof previousValue !== "string" || typeof value !== "string") {
231+
return false
232+
}
233+
234+
let isLegacyMapping = false
235+
if (provider === "gemini") {
236+
isLegacyMapping = mapLegacyGeminiModel(previousValue) === value
237+
} else if (provider === "vertex") {
238+
isLegacyMapping = mapLegacyVertexModel(previousValue) === value
239+
}
240+
241+
if (isLegacyMapping && currentApiConfigName) {
242+
vscode.postMessage({
243+
type: "upsertApiConfiguration",
244+
text: currentApiConfigName,
245+
apiConfiguration: updatedApiConfiguration,
246+
})
247+
}
248+
249+
return isLegacyMapping
250+
},
251+
[currentApiConfigName],
252+
)
253+
222254
const setApiConfigurationField = useCallback(
223255
<K extends keyof ProviderSettings>(field: K, value: ProviderSettings[K]) => {
224256
setCachedState((prevState) => {
@@ -232,23 +264,24 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
232264
// This prevents the dirty state when the component initializes and auto-syncs the model ID
233265
const isInitialSync = previousValue === undefined && value !== undefined
234266

235-
let isLegacyGeminiMapping = false
236-
if (field === "apiModelId" && typeof previousValue === "string" && typeof value === "string") {
237-
const provider = prevState.apiConfiguration?.apiProvider
238-
if (provider === "gemini") {
239-
isLegacyGeminiMapping = mapLegacyGeminiModel(previousValue) === value
240-
} else if (provider === "vertex") {
241-
isLegacyGeminiMapping = mapLegacyVertexModel(previousValue) === value
242-
}
243-
}
267+
const updatedApiConfiguration = { ...prevState.apiConfiguration, [field]: value }
268+
269+
const isLegacyMapping = handleLegacyGeminiModelMapping(
270+
field,
271+
previousValue,
272+
value,
273+
prevState.apiConfiguration?.apiProvider,
274+
updatedApiConfiguration,
275+
)
244276

245-
if (!isInitialSync && !isLegacyGeminiMapping) {
277+
if (!isInitialSync && !isLegacyMapping) {
246278
setChangeDetected(true)
247279
}
248-
return { ...prevState, apiConfiguration: { ...prevState.apiConfiguration, [field]: value } }
280+
281+
return { ...prevState, apiConfiguration: updatedApiConfiguration }
249282
})
250283
},
251-
[],
284+
[handleLegacyGeminiModelMapping],
252285
)
253286

254287
const setExperimentEnabled: SetExperimentEnabled = useCallback((id: ExperimentId, enabled: boolean) => {

0 commit comments

Comments
 (0)