|
1 | 1 | import { useEffect } from "react"; |
2 | 2 | import type { ChatInputAPI } from "@/components/ChatInput"; |
3 | 3 | import { matchesKeybind, KEYBINDS, isEditableElement } from "@/utils/ui/keybinds"; |
4 | | -import { getLastThinkingByModelKey } from "@/constants/storage"; |
| 4 | +import { getLastThinkingByModelKey, getModelKey } from "@/constants/storage"; |
5 | 5 | import { updatePersistedState, readPersistedState } from "@/hooks/usePersistedState"; |
6 | 6 | import type { ThinkingLevel, ThinkingLevelOn } from "@/types/thinking"; |
7 | 7 | import { DEFAULT_THINKING_LEVEL } from "@/types/thinking"; |
8 | 8 | import { getThinkingPolicyForModel } from "@/utils/thinking/policy"; |
| 9 | +import { defaultModel } from "@/utils/ai/models"; |
9 | 10 |
|
10 | 11 | interface UseAIViewKeybindsParams { |
11 | 12 | workspaceId: string; |
@@ -64,17 +65,18 @@ export function useAIViewKeybinds({ |
64 | 65 | if (matchesKeybind(e, KEYBINDS.TOGGLE_THINKING)) { |
65 | 66 | e.preventDefault(); |
66 | 67 |
|
67 | | - // Skip if no model set (workspace has no messages yet) |
68 | | - if (!currentModel) { |
69 | | - return; |
70 | | - } |
| 68 | + // Get selected model from localStorage (what user sees in UI) |
| 69 | + // Fall back to message history model, then to default model |
| 70 | + // This matches the same logic as useSendMessageOptions |
| 71 | + const selectedModel = readPersistedState<string | null>(getModelKey(workspaceId), null); |
| 72 | + const modelToUse = selectedModel ?? currentModel ?? defaultModel; |
71 | 73 |
|
72 | 74 | // Storage key for remembering this model's last-used active thinking level |
73 | | - const lastThinkingKey = getLastThinkingByModelKey(currentModel); |
| 75 | + const lastThinkingKey = getLastThinkingByModelKey(modelToUse); |
74 | 76 |
|
75 | 77 | // Special-case: if model has single-option policy (e.g., gpt-5-pro only supports HIGH), |
76 | 78 | // the toggle is a no-op to avoid confusing state transitions. |
77 | | - const allowed = getThinkingPolicyForModel(currentModel); |
| 79 | + const allowed = getThinkingPolicyForModel(modelToUse); |
78 | 80 | if (allowed.length === 1) { |
79 | 81 | return; // No toggle for single-option policies |
80 | 82 | } |
|
0 commit comments