fix(chat): persist default thinking variant selection (#492)
Treat selecting Default as an explicit variant clear across send-time persistence, stream metadata sync, and historical session analysis so stale non-default variants are not reapplied.
This commit is contained in:
@@ -1149,9 +1149,7 @@ export const useEventStream = () => {
|
|||||||
const variant = typeof (messageExt as { variant?: unknown }).variant === 'string'
|
const variant = typeof (messageExt as { variant?: unknown }).variant === 'string'
|
||||||
? (messageExt as { variant: string }).variant
|
? (messageExt as { variant: string }).variant
|
||||||
: undefined;
|
: undefined;
|
||||||
if (variant) {
|
context.saveAgentModelVariantForSession(sessionId, agentCandidate, providerID, modelID, variant);
|
||||||
context.saveAgentModelVariantForSession(sessionId, agentCandidate, providerID, modelID, variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentSessionIdRef.current === sessionId) {
|
if (currentSessionIdRef.current === sessionId) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -304,6 +304,10 @@ export const useContextStore = create<ContextStore>()(
|
|||||||
? infoAny.model.modelID
|
? infoAny.model.modelID
|
||||||
: (typeof infoAny.modelID === 'string' && infoAny.modelID.trim().length > 0 ? infoAny.modelID : undefined);
|
: (typeof infoAny.modelID === 'string' && infoAny.modelID.trim().length > 0 ? infoAny.modelID : undefined);
|
||||||
|
|
||||||
|
const userVariant = typeof infoAny.variant === 'string' && infoAny.variant.trim().length > 0
|
||||||
|
? infoAny.variant
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (agentName && userProvider && userModel && agents.find((a) => a.name === agentName)) {
|
if (agentName && userProvider && userModel && agents.find((a) => a.name === agentName)) {
|
||||||
const choice = {
|
const choice = {
|
||||||
providerId: userProvider,
|
providerId: userProvider,
|
||||||
@@ -314,15 +318,11 @@ export const useContextStore = create<ContextStore>()(
|
|||||||
if (!existing || choice.timestamp > existing.timestamp) {
|
if (!existing || choice.timestamp > existing.timestamp) {
|
||||||
agentLastChoices.set(agentName, choice);
|
agentLastChoices.set(agentName, choice);
|
||||||
}
|
}
|
||||||
if (typeof infoAny.variant === 'string' && infoAny.variant.trim().length > 0) {
|
saveAgentModelVariantForSession(sessionId, agentName, userProvider, userModel, userVariant);
|
||||||
saveAgentModelVariantForSession(sessionId, agentName, userProvider, userModel, infoAny.variant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User message: variant is top-level, model is nested in model.providerID/modelID
|
// User message: variant is top-level, model is nested in model.providerID/modelID
|
||||||
pendingVariant = typeof infoAny.variant === 'string' && infoAny.variant.trim().length > 0
|
pendingVariant = userVariant;
|
||||||
? infoAny.variant
|
|
||||||
: undefined;
|
|
||||||
pendingUserModel = infoAny.model?.providerID && infoAny.model?.modelID
|
pendingUserModel = infoAny.model?.providerID && infoAny.model?.modelID
|
||||||
? { providerID: infoAny.model.providerID, modelID: infoAny.model.modelID }
|
? { providerID: infoAny.model.providerID, modelID: infoAny.model.modelID }
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -335,7 +335,7 @@ export const useContextStore = create<ContextStore>()(
|
|||||||
|
|
||||||
if (agentName && agents.find((a) => a.name === agentName)) {
|
if (agentName && agents.find((a) => a.name === agentName)) {
|
||||||
// Apply pending variant from user message if model matches
|
// Apply pending variant from user message if model matches
|
||||||
if (pendingVariant && pendingUserModel &&
|
if (pendingUserModel &&
|
||||||
pendingUserModel.providerID === infoAny.providerID &&
|
pendingUserModel.providerID === infoAny.providerID &&
|
||||||
pendingUserModel.modelID === infoAny.modelID) {
|
pendingUserModel.modelID === infoAny.modelID) {
|
||||||
saveAgentModelVariantForSession(sessionId, agentName, infoAny.providerID, infoAny.modelID, pendingVariant);
|
saveAgentModelVariantForSession(sessionId, agentName, infoAny.providerID, infoAny.modelID, pendingVariant);
|
||||||
|
|||||||
@@ -397,14 +397,12 @@ export const useSessionStore = create<SessionStore>()(
|
|||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variant !== undefined) {
|
try {
|
||||||
try {
|
useContextStore
|
||||||
useContextStore
|
.getState()
|
||||||
.getState()
|
.saveAgentModelVariantForSession(created.id, effectiveDraftAgent, draftProviderId, draftModelId, variant);
|
||||||
.saveAgentModelVariantForSession(created.id, effectiveDraftAgent, draftProviderId, draftModelId, variant);
|
} catch {
|
||||||
} catch {
|
// ignored
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,14 +459,12 @@ export const useSessionStore = create<SessionStore>()(
|
|||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
if (variant !== undefined) {
|
try {
|
||||||
try {
|
useContextStore
|
||||||
useContextStore
|
.getState()
|
||||||
.getState()
|
.saveAgentModelVariantForSession(currentSessionId, effectiveAgent, providerID, modelID, variant);
|
||||||
.saveAgentModelVariantForSession(currentSessionId, effectiveAgent, providerID, modelID, variant);
|
} catch {
|
||||||
} catch {
|
// ignored
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user