interstellar_ai/app/backend/ChatHistory.ts

28 lines
761 B
TypeScript
Raw Normal View History

2024-10-01 10:50:19 +02:00
type ChatMessage = {
name: string;
2024-10-02 14:01:16 +02:00
messages: any;
2024-10-01 10:50:19 +02:00
timestamp: number;
};
let chatHistory: ChatMessage[] = [];
2024-10-02 14:01:16 +02:00
function addMessageHistory(name: string, message: any): void {
2024-10-01 10:50:19 +02:00
const newMessage: ChatMessage = {
name: name,
2024-10-02 14:01:16 +02:00
messages: message,
2024-10-01 10:50:19 +02:00
timestamp: Date.now()
};
chatHistory.push(newMessage);
console.log(`Added message from ${name}: ${message}`);
}
2024-10-02 14:01:16 +02:00
function removeMessageHistory(timestamp: number): void {
2024-10-01 10:50:19 +02:00
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}`);
}
}