@@ -3,43 +3,48 @@ import localForage from 'localforage'
33import { v4 as uuidv4 } from 'uuid'
44import { useMessageStore } from '@/renderer/store/message'
55
6+ type ConversationID = string
7+
68export type MessageEntry = {
79 role : string
810 content : any
911 reasoning_content ?: string
1012 [ key : string ] : any
1113}
1214
13- interface ConversationEntry {
14- id : string
15+ type ConversationEntry = {
16+ id : ConversationID
1517 messages : MessageEntry [ ]
1618}
1719
1820export const useHistoryStore = defineStore ( 'historyStore' , {
1921 state : ( ) => ( {
22+ selected : undefined as ConversationID [ ] | undefined ,
2023 conversation : [ ] as ConversationEntry [ ]
2124 } ) ,
2225 persist : {
26+ include : [ 'conversation' ] ,
2327 storage : localForage
2428 } ,
25- getters : {
26- getDate : ( ) => {
29+ getters : { } ,
30+ actions : {
31+ getDate ( ) {
2732 const date = new Date ( ) . toLocaleString ( 'zh' , { timeZoneName : 'short' , hour12 : false } )
2833 return `${ date } ${ uuidv4 ( ) } `
29- }
30- } ,
31- actions : {
34+ } ,
3235 resetState ( ) {
3336 this . $reset ( )
3437 } ,
3538 deleteById ( index ) {
3639 this . conversation . splice ( index , 1 )
3740 } ,
3841 init ( conversation ) {
42+ const newId = this . getDate ( )
3943 this . conversation . unshift ( {
40- id : this . getDate ,
44+ id : newId ,
4145 messages : conversation
4246 } )
47+ this . selected = [ newId ]
4348 } ,
4449 replace ( id ) {
4550 this . deleteById ( id )
@@ -48,9 +53,7 @@ export const useHistoryStore = defineStore('historyStore', {
4853 } ,
4954 select ( id ) {
5055 const messageStore = useMessageStore ( )
51- // settingStore.configHistory = false
5256 messageStore . conversation = this . conversation [ id ] . messages
53- // this.replace(id)
5457 } ,
5558 getColor ( id ) {
5659 const targetElement = this . conversation [ id ] ?. messages . find (
0 commit comments