"use client"; import { createContext, useContext, useState } from "react"; import { ChatHistory } from "../types"; type ChatContextProps = { history: ChatHistory[]; setHistory: (history: ChatHistory[]) => void; addToHistory: (message: ChatHistory) => void; }; export const ChatContext = createContext( undefined ); export const ChatProvider = ({ children, }: { children: JSX.Element | JSX.Element[]; }): JSX.Element => { const [history, setHistory] = useState([]); const addToHistory = (message: ChatHistory) => { setHistory((prevHistory) => [...prevHistory, message]); }; return ( {children} ); }; export const useChatContext = (): ChatContextProps => { const context = useContext(ChatContext); if (context === undefined) { throw new Error("useChatContext must be used inside ChatProvider"); } return context; };