Download src/context/SessionContext.tsx from web-zero/ui: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/web-zero/ui/resolve/main/src/context/SessionContext.tsx
- Command line
-
hf download hf://spaces/web-zero/ui/src/context/SessionContext.tsx
-
curl -L -o SessionContext.tsx https://huggingface.co/spaces/web-zero/ui/resolve/main/src/context/SessionContext.tsx
1.06 kB
| "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; | |
| }; | |