fix: allow model override before chat session exists
- Add pendingModelOverride state to useNotebookChat hook - Store model selection when no session exists yet - Apply pending model override when session is auto-created on first message - Simplify ChatColumn by using new setModelOverride function
This commit is contained in:
parent
e11f0a4db8
commit
a1d0a3a666
2 changed files with 26 additions and 7 deletions
|
|
@ -95,12 +95,8 @@ export function ChatColumn({ notebookId, contextSelections }: ChatColumnProps) {
|
||||||
isStreaming={chat.isSending}
|
isStreaming={chat.isSending}
|
||||||
contextIndicators={null}
|
contextIndicators={null}
|
||||||
onSendMessage={(message, modelOverride) => chat.sendMessage(message, modelOverride)}
|
onSendMessage={(message, modelOverride) => chat.sendMessage(message, modelOverride)}
|
||||||
modelOverride={chat.currentSession?.model_override ?? undefined}
|
modelOverride={chat.currentSession?.model_override ?? chat.pendingModelOverride ?? undefined}
|
||||||
onModelChange={(model) => {
|
onModelChange={(model) => chat.setModelOverride(model ?? null)}
|
||||||
if (chat.currentSessionId) {
|
|
||||||
chat.updateSession(chat.currentSessionId, { model_override: model ?? null })
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
sessions={chat.sessions}
|
sessions={chat.sessions}
|
||||||
currentSessionId={chat.currentSessionId}
|
currentSessionId={chat.currentSessionId}
|
||||||
onCreateSession={(title) => chat.createSession(title)}
|
onCreateSession={(title) => chat.createSession(title)}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ export function useNotebookChat({ notebookId, sources, notes, contextSelections
|
||||||
const [isSending, setIsSending] = useState(false)
|
const [isSending, setIsSending] = useState(false)
|
||||||
const [tokenCount, setTokenCount] = useState<number>(0)
|
const [tokenCount, setTokenCount] = useState<number>(0)
|
||||||
const [charCount, setCharCount] = useState<number>(0)
|
const [charCount, setCharCount] = useState<number>(0)
|
||||||
|
// Pending model override for when user changes model before a session exists
|
||||||
|
const [pendingModelOverride, setPendingModelOverride] = useState<string | null>(null)
|
||||||
|
|
||||||
// Fetch sessions for this notebook
|
// Fetch sessions for this notebook
|
||||||
const {
|
const {
|
||||||
|
|
@ -176,10 +178,14 @@ export function useNotebookChat({ notebookId, sources, notes, contextSelections
|
||||||
: message
|
: message
|
||||||
const newSession = await chatApi.createSession({
|
const newSession = await chatApi.createSession({
|
||||||
notebook_id: notebookId,
|
notebook_id: notebookId,
|
||||||
title: defaultTitle
|
title: defaultTitle,
|
||||||
|
// Include pending model override when creating session
|
||||||
|
model_override: pendingModelOverride ?? undefined
|
||||||
})
|
})
|
||||||
sessionId = newSession.id
|
sessionId = newSession.id
|
||||||
setCurrentSessionId(sessionId)
|
setCurrentSessionId(sessionId)
|
||||||
|
// Clear pending model override now that it's applied to the session
|
||||||
|
setPendingModelOverride(null)
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: QUERY_KEYS.notebookChatSessions(notebookId)
|
queryKey: QUERY_KEYS.notebookChatSessions(notebookId)
|
||||||
})
|
})
|
||||||
|
|
@ -226,6 +232,7 @@ export function useNotebookChat({ notebookId, sources, notes, contextSelections
|
||||||
notebookId,
|
notebookId,
|
||||||
currentSessionId,
|
currentSessionId,
|
||||||
currentSession,
|
currentSession,
|
||||||
|
pendingModelOverride,
|
||||||
buildContext,
|
buildContext,
|
||||||
refetchCurrentSession,
|
refetchCurrentSession,
|
||||||
queryClient
|
queryClient
|
||||||
|
|
@ -257,6 +264,20 @@ export function useNotebookChat({ notebookId, sources, notes, contextSelections
|
||||||
return deleteSessionMutation.mutate(sessionId)
|
return deleteSessionMutation.mutate(sessionId)
|
||||||
}, [deleteSessionMutation])
|
}, [deleteSessionMutation])
|
||||||
|
|
||||||
|
// Set model override - handles both existing sessions and pending state
|
||||||
|
const setModelOverride = useCallback((model: string | null) => {
|
||||||
|
if (currentSessionId) {
|
||||||
|
// Session exists - update it directly
|
||||||
|
updateSessionMutation.mutate({
|
||||||
|
sessionId: currentSessionId,
|
||||||
|
data: { model_override: model }
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// No session yet - store as pending
|
||||||
|
setPendingModelOverride(model)
|
||||||
|
}
|
||||||
|
}, [currentSessionId, updateSessionMutation])
|
||||||
|
|
||||||
// Update token/char counts when context selections change
|
// Update token/char counts when context selections change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateContextCounts = async () => {
|
const updateContextCounts = async () => {
|
||||||
|
|
@ -279,6 +300,7 @@ export function useNotebookChat({ notebookId, sources, notes, contextSelections
|
||||||
loadingSessions,
|
loadingSessions,
|
||||||
tokenCount,
|
tokenCount,
|
||||||
charCount,
|
charCount,
|
||||||
|
pendingModelOverride,
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
createSession,
|
createSession,
|
||||||
|
|
@ -286,6 +308,7 @@ export function useNotebookChat({ notebookId, sources, notes, contextSelections
|
||||||
deleteSession,
|
deleteSession,
|
||||||
switchSession,
|
switchSession,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
|
setModelOverride,
|
||||||
refetchSessions
|
refetchSessions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue