start chatHistory
This commit is contained in:
parent
a60cc7e941
commit
76da6aed0e
8 changed files with 89 additions and 38 deletions
|
@ -1,23 +1,25 @@
|
|||
/* type ChatMessage = {
|
||||
|
||||
type Message = {
|
||||
role: string;
|
||||
content:string
|
||||
}
|
||||
|
||||
type Chat = {
|
||||
name: string;
|
||||
messages: any;
|
||||
messages: Message[];
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
let chatHistory: ChatMessage[] = [];
|
||||
export let chatHistory: Chat[] = [];
|
||||
|
||||
function addMessageToHistory(name: string, message: any): void {
|
||||
const newMessage: ChatMessage = {
|
||||
name: name,
|
||||
messages: message,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
chatHistory.push(newMessage);
|
||||
console.log(`Added message from ${name}: ${message}`);
|
||||
chatHistory.sort((a,b) => b.timestamp - a.timestamp)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
function removeMessageFromHistory(timestamp: number): void {
|
||||
export function removeMessageFromHistory(timestamp: number): void {
|
||||
const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
|
||||
if (index > -1) {
|
||||
chatHistory.splice(index, 1);
|
||||
|
@ -26,4 +28,3 @@ function removeMessageFromHistory(timestamp: number): void {
|
|||
console.log(`Message not found with timestamp: ${timestamp}`);
|
||||
}
|
||||
}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue