From 5c73236330419960b9a53a2c050c5f4bf137b577 Mon Sep 17 00:00:00 2001 From: Soumyadas15 Date: Wed, 7 May 2025 01:51:26 +0530 Subject: [PATCH] chore(ui): auto select default model based on subscription status --- .../thread/chat-input/_use-model-selection.ts | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/thread/chat-input/_use-model-selection.ts b/frontend/src/components/thread/chat-input/_use-model-selection.ts index d3a18a84..3625f55b 100644 --- a/frontend/src/components/thread/chat-input/_use-model-selection.ts +++ b/frontend/src/components/thread/chat-input/_use-model-selection.ts @@ -4,7 +4,8 @@ import { useSubscription } from '@/hooks/react-query/subscriptions/use-subscript import { useState, useEffect } from 'react'; export const STORAGE_KEY_MODEL = 'suna-preferred-model'; -export const DEFAULT_MODEL_ID = 'qwen3'; +export const DEFAULT_FREE_MODEL_ID = 'qwen3'; +export const DEFAULT_PREMIUM_MODEL_ID = 'sonnet-3.7'; export type SubscriptionStatus = 'no_subscription' | 'active'; @@ -38,7 +39,7 @@ export const canAccessModel = ( }; export const useModelSelection = () => { - const [selectedModel, setSelectedModel] = useState(DEFAULT_MODEL_ID); + const [selectedModel, setSelectedModel] = useState(DEFAULT_FREE_MODEL_ID); const { data: subscriptionData } = useSubscription(); @@ -51,15 +52,34 @@ export const useModelSelection = () => { try { const savedModel = localStorage.getItem(STORAGE_KEY_MODEL); - if (!savedModel) return; - const modelOption = MODEL_OPTIONS.find(option => option.id === savedModel); - - if (modelOption && canAccessModel(subscriptionStatus, modelOption.requiresSubscription)) { - setSelectedModel(savedModel); - } else { - localStorage.removeItem(STORAGE_KEY_MODEL); - setSelectedModel(DEFAULT_MODEL_ID); + if (subscriptionStatus === 'active') { + if (savedModel) { + const modelOption = MODEL_OPTIONS.find(option => option.id === savedModel); + if (modelOption && canAccessModel(subscriptionStatus, modelOption.requiresSubscription)) { + setSelectedModel(savedModel); + return; + } + } + + setSelectedModel(DEFAULT_PREMIUM_MODEL_ID); + try { + localStorage.setItem(STORAGE_KEY_MODEL, DEFAULT_PREMIUM_MODEL_ID); + } catch (error) { + console.warn('Failed to save model preference to localStorage:', error); + } + } + else if (savedModel) { + const modelOption = MODEL_OPTIONS.find(option => option.id === savedModel); + if (modelOption && canAccessModel(subscriptionStatus, modelOption.requiresSubscription)) { + setSelectedModel(savedModel); + } else { + localStorage.removeItem(STORAGE_KEY_MODEL); + setSelectedModel(DEFAULT_FREE_MODEL_ID); + } + } + else { + setSelectedModel(DEFAULT_FREE_MODEL_ID); } } catch (error) { console.warn('Failed to load preferences from localStorage:', error);