11import { create } from "zustand" ;
2- import { persist , createJSONStorage } from "zustand/middleware" ;
32import { Conversation , ConversationSchema } from "../../pkg/gen/apiclient/chat/v2/chat_pb" ;
43import { fromJson } from "@bufbuild/protobuf" ;
54import { useConversationUiStore } from "./conversation-ui-store" ;
@@ -13,36 +12,15 @@ interface ConversationStore {
1312 setIsStreaming : ( isStreaming : boolean ) => void ;
1413}
1514
16- export const useConversationStore = create < ConversationStore > ( ) (
17- persist (
18- ( set , get ) => ( {
19- currentConversation : newConversation ( ) ,
20- setCurrentConversation : ( conversation : Conversation ) => set ( { currentConversation : conversation } ) ,
21- updateCurrentConversation : ( updater : ( conversation : Conversation ) => Conversation ) =>
22- set ( { currentConversation : updater ( get ( ) . currentConversation ) } ) ,
23- startFromScratch : ( ) => set ( { currentConversation : newConversation ( ) } ) ,
24- isStreaming : false ,
25- setIsStreaming : ( isStreaming : boolean ) => set ( { isStreaming } ) ,
26- } ) ,
27- {
28- name : "pd.conversation-storage" ,
29- storage : createJSONStorage ( ( ) => localStorage , {
30- replacer : ( _key , value ) => {
31- if ( typeof value === "bigint" ) {
32- return value . toString ( ) + "n" ;
33- }
34- return value ;
35- } ,
36- reviver : ( _key , value ) => {
37- if ( typeof value === "string" && / ^ - ? \d + n $ / . test ( value ) ) {
38- return BigInt ( value . slice ( 0 , - 1 ) ) ;
39- }
40- return value ;
41- } ,
42- } ) ,
43- } ,
44- ) ,
45- ) ;
15+ export const useConversationStore = create < ConversationStore > ( ( set , get ) => ( {
16+ currentConversation : newConversation ( ) ,
17+ setCurrentConversation : ( conversation : Conversation ) => set ( { currentConversation : conversation } ) ,
18+ updateCurrentConversation : ( updater : ( conversation : Conversation ) => Conversation ) =>
19+ set ( { currentConversation : updater ( get ( ) . currentConversation ) } ) ,
20+ startFromScratch : ( ) => set ( { currentConversation : newConversation ( ) } ) ,
21+ isStreaming : false ,
22+ setIsStreaming : ( isStreaming : boolean ) => set ( { isStreaming } ) ,
23+ } ) ) ;
4624
4725export function newConversation ( ) : Conversation {
4826 const modelSlug = useConversationUiStore . getState ( ) . lastUsedModelSlug ;
0 commit comments