@@ -149,7 +149,8 @@ export function SessionConfigModel(props: { onClose: () => void }) {
149149 text = { Locale . Chat . Config . Reset }
150150 onClick = { async ( ) => {
151151 if ( await showConfirm ( Locale . Memory . ResetConfirm ) ) {
152- chatStore . updateCurrentSession (
152+ chatStore . updateTargetSession (
153+ session ,
153154 ( session ) => ( session . memoryPrompt = "" ) ,
154155 ) ;
155156 }
@@ -174,7 +175,10 @@ export function SessionConfigModel(props: { onClose: () => void }) {
174175 updateMask = { ( updater ) => {
175176 const mask = { ...session . mask } ;
176177 updater ( mask ) ;
177- chatStore . updateCurrentSession ( ( session ) => ( session . mask = mask ) ) ;
178+ chatStore . updateTargetSession (
179+ session ,
180+ ( session ) => ( session . mask = mask ) ,
181+ ) ;
178182 } }
179183 shouldSyncFromGlobal
180184 extraListItems = {
@@ -346,12 +350,14 @@ export function PromptHints(props: {
346350
347351function ClearContextDivider ( ) {
348352 const chatStore = useChatStore ( ) ;
353+ const session = chatStore . currentSession ( ) ;
349354
350355 return (
351356 < div
352357 className = { styles [ "clear-context" ] }
353358 onClick = { ( ) =>
354- chatStore . updateCurrentSession (
359+ chatStore . updateTargetSession (
360+ session ,
355361 ( session ) => ( session . clearContextIndex = undefined ) ,
356362 )
357363 }
@@ -461,6 +467,7 @@ export function ChatActions(props: {
461467 const navigate = useNavigate ( ) ;
462468 const chatStore = useChatStore ( ) ;
463469 const pluginStore = usePluginStore ( ) ;
470+ const session = chatStore . currentSession ( ) ;
464471
465472 // switch themes
466473 const theme = config . theme ;
@@ -477,10 +484,9 @@ export function ChatActions(props: {
477484 const stopAll = ( ) => ChatControllerPool . stopAll ( ) ;
478485
479486 // switch model
480- const currentModel = chatStore . currentSession ( ) . mask . modelConfig . model ;
487+ const currentModel = session . mask . modelConfig . model ;
481488 const currentProviderName =
482- chatStore . currentSession ( ) . mask . modelConfig ?. providerName ||
483- ServiceProvider . OpenAI ;
489+ session . mask . modelConfig ?. providerName || ServiceProvider . OpenAI ;
484490 const allModels = useAllModels ( ) ;
485491 const models = useMemo ( ( ) => {
486492 const filteredModels = allModels . filter ( ( m ) => m . available ) ;
@@ -514,12 +520,9 @@ export function ChatActions(props: {
514520 const dalle3Sizes : DalleSize [ ] = [ "1024x1024" , "1792x1024" , "1024x1792" ] ;
515521 const dalle3Qualitys : DalleQuality [ ] = [ "standard" , "hd" ] ;
516522 const dalle3Styles : DalleStyle [ ] = [ "vivid" , "natural" ] ;
517- const currentSize =
518- chatStore . currentSession ( ) . mask . modelConfig ?. size ?? "1024x1024" ;
519- const currentQuality =
520- chatStore . currentSession ( ) . mask . modelConfig ?. quality ?? "standard" ;
521- const currentStyle =
522- chatStore . currentSession ( ) . mask . modelConfig ?. style ?? "vivid" ;
523+ const currentSize = session . mask . modelConfig ?. size ?? "1024x1024" ;
524+ const currentQuality = session . mask . modelConfig ?. quality ?? "standard" ;
525+ const currentStyle = session . mask . modelConfig ?. style ?? "vivid" ;
523526
524527 const isMobileScreen = useMobileScreen ( ) ;
525528
@@ -537,7 +540,7 @@ export function ChatActions(props: {
537540 if ( isUnavailableModel && models . length > 0 ) {
538541 // show next model to default model if exist
539542 let nextModel = models . find ( ( model ) => model . isDefault ) || models [ 0 ] ;
540- chatStore . updateCurrentSession ( ( session ) => {
543+ chatStore . updateTargetSession ( session , ( session ) => {
541544 session . mask . modelConfig . model = nextModel . name ;
542545 session . mask . modelConfig . providerName = nextModel ?. provider
543546 ?. providerName as ServiceProvider ;
@@ -548,7 +551,7 @@ export function ChatActions(props: {
548551 : nextModel . name ,
549552 ) ;
550553 }
551- } , [ chatStore , currentModel , models ] ) ;
554+ } , [ chatStore , currentModel , models , session ] ) ;
552555
553556 return (
554557 < div className = { styles [ "chat-input-actions" ] } >
@@ -615,7 +618,7 @@ export function ChatActions(props: {
615618 text = { Locale . Chat . InputActions . Clear }
616619 icon = { < BreakIcon /> }
617620 onClick = { ( ) => {
618- chatStore . updateCurrentSession ( ( session ) => {
621+ chatStore . updateTargetSession ( session , ( session ) => {
619622 if ( session . clearContextIndex === session . messages . length ) {
620623 session . clearContextIndex = undefined ;
621624 } else {
@@ -647,7 +650,7 @@ export function ChatActions(props: {
647650 onSelection = { ( s ) => {
648651 if ( s . length === 0 ) return ;
649652 const [ model , providerName ] = getModelProvider ( s [ 0 ] ) ;
650- chatStore . updateCurrentSession ( ( session ) => {
653+ chatStore . updateTargetSession ( session , ( session ) => {
651654 session . mask . modelConfig . model = model as ModelType ;
652655 session . mask . modelConfig . providerName =
653656 providerName as ServiceProvider ;
@@ -685,7 +688,7 @@ export function ChatActions(props: {
685688 onSelection = { ( s ) => {
686689 if ( s . length === 0 ) return ;
687690 const size = s [ 0 ] ;
688- chatStore . updateCurrentSession ( ( session ) => {
691+ chatStore . updateTargetSession ( session , ( session ) => {
689692 session . mask . modelConfig . size = size ;
690693 } ) ;
691694 showToast ( size ) ;
@@ -712,7 +715,7 @@ export function ChatActions(props: {
712715 onSelection = { ( q ) => {
713716 if ( q . length === 0 ) return ;
714717 const quality = q [ 0 ] ;
715- chatStore . updateCurrentSession ( ( session ) => {
718+ chatStore . updateTargetSession ( session , ( session ) => {
716719 session . mask . modelConfig . quality = quality ;
717720 } ) ;
718721 showToast ( quality ) ;
@@ -739,7 +742,7 @@ export function ChatActions(props: {
739742 onSelection = { ( s ) => {
740743 if ( s . length === 0 ) return ;
741744 const style = s [ 0 ] ;
742- chatStore . updateCurrentSession ( ( session ) => {
745+ chatStore . updateTargetSession ( session , ( session ) => {
743746 session . mask . modelConfig . style = style ;
744747 } ) ;
745748 showToast ( style ) ;
@@ -770,7 +773,7 @@ export function ChatActions(props: {
770773 } ) ) }
771774 onClose = { ( ) => setShowPluginSelector ( false ) }
772775 onSelection = { ( s ) => {
773- chatStore . updateCurrentSession ( ( session ) => {
776+ chatStore . updateTargetSession ( session , ( session ) => {
774777 session . mask . plugin = s as string [ ] ;
775778 } ) ;
776779 } }
@@ -813,7 +816,8 @@ export function EditMessageModal(props: { onClose: () => void }) {
813816 icon = { < ConfirmIcon /> }
814817 key = "ok"
815818 onClick = { ( ) => {
816- chatStore . updateCurrentSession (
819+ chatStore . updateTargetSession (
820+ session ,
817821 ( session ) => ( session . messages = messages ) ,
818822 ) ;
819823 props . onClose ( ) ;
@@ -830,7 +834,8 @@ export function EditMessageModal(props: { onClose: () => void }) {
830834 type = "text"
831835 value = { session . topic }
832836 onInput = { ( e ) =>
833- chatStore . updateCurrentSession (
837+ chatStore . updateTargetSession (
838+ session ,
834839 ( session ) => ( session . topic = e . currentTarget . value ) ,
835840 )
836841 }
@@ -991,7 +996,8 @@ function _Chat() {
991996 prev : ( ) => chatStore . nextSession ( - 1 ) ,
992997 next : ( ) => chatStore . nextSession ( 1 ) ,
993998 clear : ( ) =>
994- chatStore . updateCurrentSession (
999+ chatStore . updateTargetSession (
1000+ session ,
9951001 ( session ) => ( session . clearContextIndex = session . messages . length ) ,
9961002 ) ,
9971003 fork : ( ) => chatStore . forkSession ( ) ,
@@ -1062,7 +1068,7 @@ function _Chat() {
10621068 } ;
10631069
10641070 useEffect ( ( ) => {
1065- chatStore . updateCurrentSession ( ( session ) => {
1071+ chatStore . updateTargetSession ( session , ( session ) => {
10661072 const stopTiming = Date . now ( ) - REQUEST_TIMEOUT_MS ;
10671073 session . messages . forEach ( ( m ) => {
10681074 // check if should stop all stale messages
@@ -1088,7 +1094,7 @@ function _Chat() {
10881094 }
10891095 } ) ;
10901096 // eslint-disable-next-line react-hooks/exhaustive-deps
1091- } , [ ] ) ;
1097+ } , [ session ] ) ;
10921098
10931099 // check if should send message
10941100 const onInputKeyDown = ( e : React . KeyboardEvent < HTMLTextAreaElement > ) => {
@@ -1119,7 +1125,8 @@ function _Chat() {
11191125 } ;
11201126
11211127 const deleteMessage = ( msgId ?: string ) => {
1122- chatStore . updateCurrentSession (
1128+ chatStore . updateTargetSession (
1129+ session ,
11231130 ( session ) =>
11241131 ( session . messages = session . messages . filter ( ( m ) => m . id !== msgId ) ) ,
11251132 ) ;
@@ -1186,7 +1193,7 @@ function _Chat() {
11861193 } ;
11871194
11881195 const onPinMessage = ( message : ChatMessage ) => {
1189- chatStore . updateCurrentSession ( ( session ) =>
1196+ chatStore . updateTargetSession ( session , ( session ) =>
11901197 session . mask . context . push ( message ) ,
11911198 ) ;
11921199
@@ -1712,14 +1719,17 @@ function _Chat() {
17121719 } ) ;
17131720 }
17141721 }
1715- chatStore . updateCurrentSession ( ( session ) => {
1716- const m = session . mask . context
1717- . concat ( session . messages )
1718- . find ( ( m ) => m . id === message . id ) ;
1719- if ( m ) {
1720- m . content = newContent ;
1721- }
1722- } ) ;
1722+ chatStore . updateTargetSession (
1723+ session ,
1724+ ( session ) => {
1725+ const m = session . mask . context
1726+ . concat ( session . messages )
1727+ . find ( ( m ) => m . id === message . id ) ;
1728+ if ( m ) {
1729+ m . content = newContent ;
1730+ }
1731+ } ,
1732+ ) ;
17231733 } }
17241734 > </ IconButton >
17251735 </ div >
0 commit comments