| import { Chat } from '../types'; | |
| const STORAGE_KEY = 'turkish-ai-chats'; | |
| export const saveChats = (chats: Chat[]): void => { | |
| try { | |
| localStorage.setItem(STORAGE_KEY, JSON.stringify(chats)); | |
| } catch (error) { | |
| console.error('Error saving chats:', error); | |
| } | |
| }; | |
| export const loadChats = (): Chat[] => { | |
| try { | |
| const stored = localStorage.getItem(STORAGE_KEY); | |
| return stored ? JSON.parse(stored) : []; | |
| } catch (error) { | |
| console.error('Error loading chats:', error); | |
| return []; | |
| } | |
| }; | |
| export const createNewChat = (modelName: string): Chat => { | |
| return { | |
| id: Date.now().toString(), | |
| title: 'Yeni Sohbet', | |
| messages: [], | |
| createdAt: Date.now(), | |
| updatedAt: Date.now(), | |
| modelName | |
| }; | |
| }; | |
| export const updateChatTitle = (chat: Chat): string => { | |
| const firstUserMessage = chat.messages.find(m => m.role === 'user'); | |
| if (firstUserMessage) { | |
| const title = firstUserMessage.content.slice(0, 50); | |
| return title.length < firstUserMessage.content.length ? `${title}...` : title; | |
| } | |
| return 'Yeni Sohbet'; | |
| }; | |