1
+ import { Icon } from '@lobehub/ui' ;
1
2
import { Dropdown } from 'antd' ;
2
3
import { createStyles } from 'antd-style' ;
3
4
import isEqual from 'fast-deep-equal' ;
5
+ import { LucideArrowRight } from 'lucide-react' ;
6
+ import { useRouter } from 'next/navigation' ;
4
7
import { PropsWithChildren , memo , useMemo } from 'react' ;
8
+ import { useTranslation } from 'react-i18next' ;
9
+ import { Flexbox } from 'react-layout-kit' ;
5
10
6
11
import { ModelItemRender , ProviderItemRender } from '@/components/ModelSelect' ;
7
12
import { useGlobalStore } from '@/store/global' ;
8
13
import { modelConfigSelectors } from '@/store/global/selectors' ;
9
14
import { useSessionStore } from '@/store/session' ;
10
15
import { agentSelectors } from '@/store/session/selectors' ;
11
16
import { ModelProviderCard } from '@/types/llm' ;
17
+ import { withBasePath } from '@/utils/basePath' ;
12
18
13
19
const useStyles = createStyles ( ( { css, prefixCls } ) => ( {
14
20
menu : css `
@@ -32,30 +38,51 @@ const useStyles = createStyles(({ css, prefixCls }) => ({
32
38
} ) ) ;
33
39
34
40
const ModelSwitchPanel = memo < PropsWithChildren > ( ( { children } ) => {
35
- const { styles } = useStyles ( ) ;
41
+ const { t } = useTranslation ( 'components' ) ;
42
+ const { styles, theme } = useStyles ( ) ;
36
43
const model = useSessionStore ( agentSelectors . currentAgentModel ) ;
37
44
const updateAgentConfig = useSessionStore ( ( s ) => s . updateAgentConfig ) ;
38
45
39
- const select = useGlobalStore ( modelConfigSelectors . modelSelectList , isEqual ) ;
40
- const enabledList = select . filter ( ( s ) => s . enabled ) ;
46
+ const router = useRouter ( ) ;
47
+ const enabledList = useGlobalStore ( modelConfigSelectors . enabledModelProviderList , isEqual ) ;
41
48
42
49
const items = useMemo ( ( ) => {
43
- const getModelItems = ( provider : ModelProviderCard ) =>
44
- provider . chatModels
45
- . filter ( ( c ) => ! c . hidden )
46
- . map ( ( model ) => ( {
47
- key : model . id ,
48
- label : < ModelItemRender { ...model } /> ,
49
- onClick : ( ) => {
50
- updateAgentConfig ( { model : model . id , provider : provider . id } ) ;
50
+ const getModelItems = ( provider : ModelProviderCard ) => {
51
+ const items = provider . chatModels . map ( ( model ) => ( {
52
+ key : model . id ,
53
+ label : < ModelItemRender { ...model } /> ,
54
+ onClick : ( ) => {
55
+ updateAgentConfig ( { model : model . id , provider : provider . id } ) ;
56
+ } ,
57
+ } ) ) ;
58
+
59
+ // if there is empty items, add a placeholder guide
60
+ if ( items . length === 0 )
61
+ return [
62
+ {
63
+ key : 'empty' ,
64
+ label : (
65
+ < Flexbox gap = { 8 } horizontal style = { { color : theme . colorTextTertiary } } >
66
+ { t ( 'ModelSwitchPanel.emptyModel' ) }
67
+ < Icon icon = { LucideArrowRight } />
68
+ </ Flexbox >
69
+ ) ,
70
+ onClick : ( ) => {
71
+ router . push ( withBasePath ( '/settings/llm' ) ) ;
72
+ } ,
51
73
} ,
52
- } ) ) ;
74
+ ] ;
75
+
76
+ return items ;
77
+ } ;
53
78
79
+ // If there is only one provider, just remove the group, show model directly
54
80
if ( enabledList . length === 1 ) {
55
81
const provider = enabledList [ 0 ] ;
56
82
return getModelItems ( provider ) ;
57
83
}
58
84
85
+ // otherwise show with provider group
59
86
return enabledList . map ( ( provider ) => ( {
60
87
children : getModelItems ( provider ) ,
61
88
key : provider . id ,
0 commit comments