File size: 1,060 Bytes
e586655 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | "use client";
import React, { createContext, useContext } from "react";
import { useSessions, Session, Message } from "@/lib/SessionManager";
interface SessionContextType {
sessions: Session[];
currentSessionId: string | null;
createNewSession: () => void;
switchSession: (sessionId: string) => void;
updateSessionMessages: (sessionId: string, messages: Message[]) => void;
deleteSession: (sessionId: string) => void;
renameSession: (sessionId: string, newName: string) => void;
}
const SessionContext = createContext<SessionContextType | undefined>(undefined);
export const SessionProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const sessionManager = useSessions();
return (
<SessionContext.Provider value={sessionManager}>
{children}
</SessionContext.Provider>
);
};
export const useSessionContext = () => {
const context = useContext(SessionContext);
if (context === undefined) {
throw new Error("useSessionContext must be used within a SessionProvider");
}
return context;
};
|