mirror of https://github.com/kortix-ai/suna.git
chore(ui): auto select default model based on subscription status
This commit is contained in:
parent
1d106426de
commit
5c73236330
|
@ -4,7 +4,8 @@ import { useSubscription } from '@/hooks/react-query/subscriptions/use-subscript
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
export const STORAGE_KEY_MODEL = 'suna-preferred-model';
|
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';
|
export type SubscriptionStatus = 'no_subscription' | 'active';
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ export const canAccessModel = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useModelSelection = () => {
|
export const useModelSelection = () => {
|
||||||
const [selectedModel, setSelectedModel] = useState(DEFAULT_MODEL_ID);
|
const [selectedModel, setSelectedModel] = useState(DEFAULT_FREE_MODEL_ID);
|
||||||
|
|
||||||
const { data: subscriptionData } = useSubscription();
|
const { data: subscriptionData } = useSubscription();
|
||||||
|
|
||||||
|
@ -51,15 +52,34 @@ export const useModelSelection = () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const savedModel = localStorage.getItem(STORAGE_KEY_MODEL);
|
const savedModel = localStorage.getItem(STORAGE_KEY_MODEL);
|
||||||
if (!savedModel) return;
|
|
||||||
|
|
||||||
const modelOption = MODEL_OPTIONS.find(option => option.id === savedModel);
|
if (subscriptionStatus === 'active') {
|
||||||
|
if (savedModel) {
|
||||||
if (modelOption && canAccessModel(subscriptionStatus, modelOption.requiresSubscription)) {
|
const modelOption = MODEL_OPTIONS.find(option => option.id === savedModel);
|
||||||
setSelectedModel(savedModel);
|
if (modelOption && canAccessModel(subscriptionStatus, modelOption.requiresSubscription)) {
|
||||||
} else {
|
setSelectedModel(savedModel);
|
||||||
localStorage.removeItem(STORAGE_KEY_MODEL);
|
return;
|
||||||
setSelectedModel(DEFAULT_MODEL_ID);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (error) {
|
||||||
console.warn('Failed to load preferences from localStorage:', error);
|
console.warn('Failed to load preferences from localStorage:', error);
|
||||||
|
|
Loading…
Reference in New Issue