fix(ui): preserve default in thinking cycle (#3153)
This commit is contained in:
@@ -885,6 +885,11 @@ interface DirectoryScopedConfig {
|
||||
selectionSource?: "auto" | "manual";
|
||||
}
|
||||
|
||||
type CurrentVariantSelection = {
|
||||
override: string | null | undefined;
|
||||
inherited: string | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lift the active directory's cached provider/agent snapshot into the top-level
|
||||
* fields the pickers read (`providers`, `agents`, selections), so a cold start
|
||||
@@ -1006,6 +1011,7 @@ interface ConfigStore {
|
||||
currentProviderId: string;
|
||||
currentModelId: string;
|
||||
currentVariant: string | undefined;
|
||||
currentVariantSelection: CurrentVariantSelection;
|
||||
currentAgentName: string | undefined;
|
||||
selectedProviderId: string;
|
||||
agentModelSelections: { [agentName: string]: { providerId: string; modelId: string } };
|
||||
@@ -1098,7 +1104,8 @@ interface ConfigStore {
|
||||
setProvider: (providerId: string) => void;
|
||||
setModel: (modelId: string) => void;
|
||||
setCurrentVariant: (variant: string | undefined) => void;
|
||||
cycleCurrentVariant: () => void;
|
||||
setCurrentVariantOverride: (override: string | null | undefined, inherited: string | undefined) => void;
|
||||
cycleCurrentVariant: () => string | undefined;
|
||||
getCurrentModelVariants: () => string[];
|
||||
setAgent: (agentName: string | undefined) => void;
|
||||
applyDefaultModelAgentSelection: (options?: { projectDefaultModel?: string; projectDefaultVariant?: string }) => void;
|
||||
@@ -1171,6 +1178,7 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
currentProviderId: "",
|
||||
currentModelId: "",
|
||||
currentVariant: undefined,
|
||||
currentVariantSelection: { override: undefined, inherited: undefined },
|
||||
currentAgentName: undefined,
|
||||
selectedProviderId: "",
|
||||
agentModelSelections: {},
|
||||
@@ -1437,6 +1445,7 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
currentProviderId: snapshot.currentProviderId,
|
||||
currentModelId: snapshot.currentModelId,
|
||||
currentVariant: snapshot.currentVariant,
|
||||
currentVariantSelection: { override: undefined, inherited: snapshot.currentVariant },
|
||||
currentAgentName: snapshot.currentAgentName,
|
||||
selectedProviderId: snapshot.selectedProviderId,
|
||||
agentModelSelections: snapshot.agentModelSelections,
|
||||
@@ -1453,6 +1462,7 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
agents: [],
|
||||
currentProviderId: "",
|
||||
currentModelId: "",
|
||||
currentVariantSelection: { override: undefined, inherited: undefined },
|
||||
currentAgentName: undefined,
|
||||
selectedProviderId: "",
|
||||
agentModelSelections: {},
|
||||
@@ -1847,13 +1857,22 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
},
|
||||
|
||||
setCurrentVariant: (variant: string | undefined) => {
|
||||
get().setCurrentVariantOverride(undefined, variant);
|
||||
},
|
||||
|
||||
setCurrentVariantOverride: (override, inherited) => {
|
||||
set((state) => {
|
||||
if (state.currentVariant === variant) {
|
||||
const currentVariant = override ?? inherited;
|
||||
if (
|
||||
state.currentVariant === currentVariant
|
||||
&& state.currentVariantSelection.override === override
|
||||
&& state.currentVariantSelection.inherited === inherited
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const directoryKey = state.activeDirectoryKey;
|
||||
const baseSnapshot: DirectoryScopedConfig = state.directoryScoped[directoryKey] ?? {
|
||||
const baseSnapshot = state.directoryScoped[directoryKey] ?? {
|
||||
providers: state.providers,
|
||||
agents: state.agents,
|
||||
currentProviderId: state.currentProviderId,
|
||||
@@ -1865,18 +1884,17 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
defaultProviders: state.defaultProviders,
|
||||
};
|
||||
|
||||
const nextSnapshot: DirectoryScopedConfig = {
|
||||
...baseSnapshot,
|
||||
currentVariant: variant,
|
||||
selectionSource: "manual",
|
||||
};
|
||||
|
||||
return {
|
||||
currentVariant: variant,
|
||||
currentVariant,
|
||||
currentVariantSelection: { override, inherited },
|
||||
selectionSource: "manual",
|
||||
directoryScoped: {
|
||||
...state.directoryScoped,
|
||||
[directoryKey]: nextSnapshot,
|
||||
[directoryKey]: {
|
||||
...baseSnapshot,
|
||||
currentVariant,
|
||||
selectionSource: "manual",
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -1894,22 +1912,26 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
cycleCurrentVariant: () => {
|
||||
const variantKeys = get().getCurrentModelVariants();
|
||||
if (variantKeys.length === 0) {
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const current = get().currentVariant;
|
||||
if (!current) {
|
||||
get().setCurrentVariant(variantKeys[0]);
|
||||
return;
|
||||
const state = get();
|
||||
const currentOverride = state.currentVariantSelection.override;
|
||||
const inheritedVariant = state.currentVariantSelection.inherited ?? state.currentVariant;
|
||||
const currentVariant = currentOverride === undefined
|
||||
? state.currentVariant
|
||||
: currentOverride;
|
||||
let nextOverride: string | null;
|
||||
|
||||
if (currentVariant === null || currentVariant === undefined) {
|
||||
nextOverride = variantKeys[0];
|
||||
} else {
|
||||
const index = variantKeys.indexOf(currentVariant);
|
||||
nextOverride = index >= 0 ? (variantKeys[index + 1] ?? null) : null;
|
||||
}
|
||||
|
||||
const index = variantKeys.indexOf(current);
|
||||
if (index === -1) {
|
||||
get().setCurrentVariant(variantKeys[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
get().setCurrentVariant(variantKeys[(index + 1) % variantKeys.length]);
|
||||
get().setCurrentVariantOverride(nextOverride, inheritedVariant);
|
||||
return nextOverride ?? undefined;
|
||||
},
|
||||
|
||||
setSelectedProvider: (providerId: string) => {
|
||||
@@ -2659,6 +2681,10 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
nextState.currentProviderId = resolvedProviderId;
|
||||
nextState.currentModelId = resolvedModelId;
|
||||
nextState.currentVariant = resolvedVariant;
|
||||
nextState.currentVariantSelection = {
|
||||
override: resolvedVariant,
|
||||
inherited: resolvedVariant,
|
||||
};
|
||||
}
|
||||
|
||||
return nextState;
|
||||
|
||||
Reference in New Issue
Block a user