11import { useAtom , useAtomValue , useSetAtom } from 'jotai'
22import { atomWithStorage } from 'jotai/utils'
3- import { uniqBy } from 'lodash-es'
3+ import { sample , uniqBy } from 'lodash-es'
44import { FC , Suspense , useCallback , useEffect , useMemo } from 'react'
55import { useTranslation } from 'react-i18next'
66import { cx } from '~/utils'
77import Button from '~app/components/Button'
88import ChatMessageInput from '~app/components/Chat/ChatMessageInput'
99import LayoutSwitch from '~app/components/Chat/LayoutSwitch'
10- import { Layout } from '~app/consts'
10+ import { CHATBOTS , Layout } from '~app/consts'
1111import { useChat } from '~app/hooks/use-chat'
1212import { usePremium } from '~app/hooks/use-premium'
1313import { trackEvent } from '~app/plausible'
1414import { showPremiumModalAtom } from '~app/state'
1515import { BotId } from '../bots'
1616import ConversationPanel from '../components/Chat/ConversationPanel'
1717
18+ const DEFAULT_BOTS : BotId [ ] = [ 'chatgpt' , 'claude' , 'bard' , 'bing' , 'llama' , 'pi' ]
19+
1820const layoutAtom = atomWithStorage < Layout > ( 'multiPanelLayout' , 2 , undefined , { unstable_getOnInit : true } )
19- const twoPanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:2' , [ 'chatgpt' , 'claude' ] )
20- const threePanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:3' , [ 'chatgpt' , 'claude' , 'bard' ] )
21- const fourPanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:4' , [ 'chatgpt' , 'claude' , 'bard' , 'bing' ] )
22- const sixPanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:6' , [
23- 'chatgpt' ,
24- 'claude' ,
25- 'bard' ,
26- 'bing' ,
27- 'pi' ,
28- 'llama' ,
29- ] )
21+ const twoPanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:2' , DEFAULT_BOTS . slice ( 0 , 2 ) )
22+ const threePanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:3' , DEFAULT_BOTS . slice ( 0 , 3 ) )
23+ const fourPanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:4' , DEFAULT_BOTS . slice ( 0 , 4 ) )
24+ const sixPanelBotsAtom = atomWithStorage < BotId [ ] > ( 'multiPanelBots:6' , DEFAULT_BOTS . slice ( 0 , 6 ) )
25+
26+ function replaceDeprecatedBots ( bots : BotId [ ] ) : BotId [ ] {
27+ return bots . map ( ( bot ) => {
28+ if ( CHATBOTS [ bot ] ) {
29+ return bot
30+ }
31+ return sample ( DEFAULT_BOTS ) !
32+ } )
33+ }
3034
3135const GeneralChatPanel : FC < {
3236 chats : ReturnType < typeof useChat > [ ]
@@ -131,15 +135,17 @@ const GeneralChatPanel: FC<{
131135}
132136
133137const TwoBotChatPanel = ( ) => {
134- const [ multiPanelBotIds , setBots ] = useAtom ( twoPanelBotsAtom )
138+ const [ bots , setBots ] = useAtom ( twoPanelBotsAtom )
139+ const multiPanelBotIds = useMemo ( ( ) => replaceDeprecatedBots ( bots ) , [ bots ] )
135140 const chat1 = useChat ( multiPanelBotIds [ 0 ] )
136141 const chat2 = useChat ( multiPanelBotIds [ 1 ] )
137142 const chats = useMemo ( ( ) => [ chat1 , chat2 ] , [ chat1 , chat2 ] )
138143 return < GeneralChatPanel chats = { chats } setBots = { setBots } />
139144}
140145
141146const ThreeBotChatPanel = ( ) => {
142- const [ multiPanelBotIds , setBots ] = useAtom ( threePanelBotsAtom )
147+ const [ bots , setBots ] = useAtom ( threePanelBotsAtom )
148+ const multiPanelBotIds = useMemo ( ( ) => replaceDeprecatedBots ( bots ) , [ bots ] )
143149 const chat1 = useChat ( multiPanelBotIds [ 0 ] )
144150 const chat2 = useChat ( multiPanelBotIds [ 1 ] )
145151 const chat3 = useChat ( multiPanelBotIds [ 2 ] )
@@ -148,7 +154,8 @@ const ThreeBotChatPanel = () => {
148154}
149155
150156const FourBotChatPanel = ( ) => {
151- const [ multiPanelBotIds , setBots ] = useAtom ( fourPanelBotsAtom )
157+ const [ bots , setBots ] = useAtom ( fourPanelBotsAtom )
158+ const multiPanelBotIds = useMemo ( ( ) => replaceDeprecatedBots ( bots ) , [ bots ] )
152159 const chat1 = useChat ( multiPanelBotIds [ 0 ] )
153160 const chat2 = useChat ( multiPanelBotIds [ 1 ] )
154161 const chat3 = useChat ( multiPanelBotIds [ 2 ] )
@@ -158,7 +165,8 @@ const FourBotChatPanel = () => {
158165}
159166
160167const SixBotChatPanel = ( ) => {
161- const [ multiPanelBotIds , setBots ] = useAtom ( sixPanelBotsAtom )
168+ const [ bots , setBots ] = useAtom ( sixPanelBotsAtom )
169+ const multiPanelBotIds = useMemo ( ( ) => replaceDeprecatedBots ( bots ) , [ bots ] )
162170 const chat1 = useChat ( multiPanelBotIds [ 0 ] )
163171 const chat2 = useChat ( multiPanelBotIds [ 1 ] )
164172 const chat3 = useChat ( multiPanelBotIds [ 2 ] )
0 commit comments