Preserve provider changes before sending
This commit is contained in:
+28
-15
@@ -63,6 +63,10 @@ import {
|
||||
type WorkspaceItem,
|
||||
} from "@/lib/api";
|
||||
import { useSessionAuth } from "@/hooks/use-session-auth";
|
||||
import {
|
||||
getChatModelSelection,
|
||||
getChatModelSelectionSyncKey,
|
||||
} from "@/lib/chat-model-selection";
|
||||
import {
|
||||
resolveSidebarSelectionAfterRefresh,
|
||||
type SidebarSelection,
|
||||
@@ -545,14 +549,6 @@ function normalizeEnabledTools(value: unknown, availableTools: ChatToolInfo[]) {
|
||||
);
|
||||
}
|
||||
|
||||
function getChatModelSelection(chat: Pick<ChatSummary, "lastUsedProvider" | "lastUsedModel"> | Pick<ChatDetail, "lastUsedProvider" | "lastUsedModel"> | null) {
|
||||
if (!chat?.lastUsedProvider || !chat.lastUsedModel?.trim()) return null;
|
||||
return {
|
||||
provider: chat.lastUsedProvider,
|
||||
model: chat.lastUsedModel.trim(),
|
||||
};
|
||||
}
|
||||
|
||||
type ToolLogMetadata = {
|
||||
kind: "tool_call";
|
||||
toolCallId?: string;
|
||||
@@ -1562,15 +1558,32 @@ export default function App() {
|
||||
return searches.find((search) => search.id === selectedItem.id) ?? null;
|
||||
}, [searches, selectedItem]);
|
||||
|
||||
useEffect(() => {
|
||||
if (draftKind || selectedItem?.kind !== "chat") return;
|
||||
const selectedChatModelSelection = useMemo(() => {
|
||||
if (draftKind || selectedItem?.kind !== "chat") return null;
|
||||
const detailSelection = selectedChat?.id === selectedItem.id ? getChatModelSelection(selectedChat) : null;
|
||||
const summarySelection = getChatModelSelection(selectedChatSummary);
|
||||
const nextSelection = detailSelection ?? summarySelection;
|
||||
if (!nextSelection) return;
|
||||
setProvider(nextSelection.provider);
|
||||
setModel(nextSelection.model);
|
||||
}, [draftKind, selectedChat, selectedChatSummary, selectedItem]);
|
||||
return detailSelection ?? summarySelection;
|
||||
}, [
|
||||
draftKind,
|
||||
selectedChat?.id,
|
||||
selectedChat?.lastUsedModel,
|
||||
selectedChat?.lastUsedProvider,
|
||||
selectedChatSummary?.id,
|
||||
selectedChatSummary?.lastUsedModel,
|
||||
selectedChatSummary?.lastUsedProvider,
|
||||
selectedItem?.id,
|
||||
selectedItem?.kind,
|
||||
]);
|
||||
const selectedChatModelSelectionSyncKey = getChatModelSelectionSyncKey(
|
||||
selectedItem?.kind === "chat" ? selectedItem.id : null,
|
||||
selectedChatModelSelection
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedChatModelSelection) return;
|
||||
setProvider(selectedChatModelSelection.provider);
|
||||
setModel(selectedChatModelSelection.model);
|
||||
}, [selectedChatModelSelectionSyncKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (draftKind === "chat") return;
|
||||
|
||||
Reference in New Issue
Block a user