Preserve imported persona model on provider select

This commit is contained in:
klopez4212
2026-06-21 12:19:43 +01:00
parent 1f406efcde
commit b25d074a55
3 changed files with 35 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ import {
getImportErrorLabel,
IMPORT_ERROR_VISIBILITY_MS,
} from "./personaDialogImportState";
import { shouldClearModelForRuntimeChange } from "./personaRuntimeModel";
type PersonaDialogProps = {
open: boolean;
@@ -543,8 +544,16 @@ export function PersonaDialog({
<Select
disabled={isPending || runtimesLoading}
onValueChange={(nextRuntime) => {
const previousRuntime = runtime;
setRuntime(nextRuntime);
setModel("");
if (
shouldClearModelForRuntimeChange(
previousRuntime,
nextRuntime,
)
) {
setModel("");
}
}}
value={runtime}
>

View File

@@ -0,0 +1,16 @@
import assert from "node:assert/strict";
import test from "node:test";
import { shouldClearModelForRuntimeChange } from "./personaRuntimeModel.ts";
test("shouldClearModelForRuntimeChange preserves model for first runtime selection", () => {
assert.equal(shouldClearModelForRuntimeChange("", "goose"), false);
});
test("shouldClearModelForRuntimeChange clears model when switching runtimes", () => {
assert.equal(shouldClearModelForRuntimeChange("goose", "claude"), true);
});
test("shouldClearModelForRuntimeChange keeps model for unchanged runtime", () => {
assert.equal(shouldClearModelForRuntimeChange("goose", "goose"), false);
});

View File

@@ -0,0 +1,9 @@
export function shouldClearModelForRuntimeChange(
previousRuntime: string,
nextRuntime: string,
): boolean {
const previous = previousRuntime.trim();
const next = nextRuntime.trim();
return previous.length > 0 && next.length > 0 && previous !== next;
}