forked from React-Group/interstellar_ai
		
	
		
			
				
	
	
		
			30 lines
		
	
	
	
		
			777 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			777 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
 | 
						|
type Message = {
 | 
						|
    role: string;
 | 
						|
    content:string
 | 
						|
}
 | 
						|
 | 
						|
type Chat = {
 | 
						|
    name: string;
 | 
						|
    messages: Message[];
 | 
						|
    timestamp: number;
 | 
						|
};
 | 
						|
 | 
						|
export let chatHistory: Chat[] = [];
 | 
						|
 | 
						|
export function addMessageToHistory(index: number, chat: Chat): void {
 | 
						|
    if (index >= 0 && index < chatHistory.length) {
 | 
						|
        chatHistory[index] = chat;
 | 
						|
        chatHistory.sort((a, b) => b.timestamp - a.timestamp)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
export function removeMessageFromHistory(timestamp: number): void {
 | 
						|
    const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
 | 
						|
    if (index > -1) {
 | 
						|
        chatHistory.splice(index, 1);
 | 
						|
        console.log(`Removed message with timestamp: ${timestamp}`);
 | 
						|
    } else {
 | 
						|
        console.log(`Message not found with timestamp: ${timestamp}`);
 | 
						|
    }
 | 
						|
}
 |