Skip to content

Commit 680feda

Browse files
7418claude
andcommitted
fix: guard against undefined currentModelOption in effort selector
When a model stored in localStorage doesn't exist in the current provider's model list (e.g. switching from Bailian's qwen3.5-plus to Kimi which doesn't have it), currentModelOption could be undefined, crashing with "Cannot read properties of undefined (reading 'supportsEffort')". - MessageInput.tsx: add optional chaining on currentModelMeta access - useProviderModels.ts: fall back to DEFAULT_MODEL_OPTIONS when provider's models array is empty Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 16326c4 commit 680feda

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/components/chat/MessageInput.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ export function MessageInput({
311311
[popover, slashCommands, cliToolsFetch, badge, cliBadge, inputValue, removeBadge, removeCliBadge]
312312
);
313313

314-
// Effort selector state
315-
const currentModelMeta = currentModelOption as typeof currentModelOption & { supportsEffort?: boolean; supportedEffortLevels?: string[] };
316-
const showEffortSelector = currentModelMeta.supportsEffort === true;
314+
// Effort selector state — guard against undefined when model not found in current provider's list
315+
const currentModelMeta = currentModelOption as (typeof currentModelOption & { supportsEffort?: boolean; supportedEffortLevels?: string[] }) | undefined;
316+
const showEffortSelector = currentModelMeta?.supportsEffort === true;
317317
const [localEffort, setLocalEffort] = useState<string>('high');
318318
const selectedEffort = effortProp ?? localEffort;
319319
const setSelectedEffort = useCallback((v: string) => {
@@ -432,7 +432,7 @@ export function MessageInput({
432432
<EffortSelectorDropdown
433433
selectedEffort={selectedEffort}
434434
onEffortChange={setSelectedEffort}
435-
supportedEffortLevels={currentModelMeta.supportedEffortLevels}
435+
supportedEffortLevels={currentModelMeta?.supportedEffortLevels}
436436
/>
437437
)}
438438

src/hooks/useProviderModels.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export function useProviderModels(
6060
// Derive flat model list for current provider
6161
const currentProviderIdValue = providerId || defaultProviderId || (providerGroups[0]?.provider_id ?? '');
6262
const currentGroup = providerGroups.find(g => g.provider_id === currentProviderIdValue) || providerGroups[0];
63-
const modelOptions = currentGroup?.models || DEFAULT_MODEL_OPTIONS;
63+
const modelOptions = (currentGroup?.models && currentGroup.models.length > 0)
64+
? currentGroup.models
65+
: DEFAULT_MODEL_OPTIONS;
6466

6567
const currentModelValue = modelName || 'sonnet';
6668
const currentModelOption = useMemo(

0 commit comments

Comments
 (0)