123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 'use client'
- import type { ReactNode } from 'react'
- import { createContext, useContext } from 'use-context-selector'
- import type { ChatProps } from './index'
- export type ChatContextValue = Pick<ChatProps, 'config'
- | 'isResponding'
- | 'chatList'
- | 'showPromptLog'
- | 'questionIcon'
- | 'answerIcon'
- | 'allToolIcons'
- | 'onSend'
- | 'onAnnotationEdited'
- | 'onAnnotationAdded'
- | 'onAnnotationRemoved'
- | 'onFeedback'
- >
- const ChatContext = createContext<ChatContextValue>({
- chatList: [],
- })
- type ChatContextProviderProps = {
- children: ReactNode
- } & ChatContextValue
- export const ChatContextProvider = ({
- children,
- config,
- isResponding,
- chatList,
- showPromptLog,
- questionIcon,
- answerIcon,
- allToolIcons,
- onSend,
- onAnnotationEdited,
- onAnnotationAdded,
- onAnnotationRemoved,
- onFeedback,
- }: ChatContextProviderProps) => {
- return (
- <ChatContext.Provider value={{
- config,
- isResponding,
- chatList: chatList || [],
- showPromptLog,
- questionIcon,
- answerIcon,
- allToolIcons,
- onSend,
- onAnnotationEdited,
- onAnnotationAdded,
- onAnnotationRemoved,
- onFeedback,
- }}>
- {children}
- </ChatContext.Provider>
- )
- }
- export const useChatContext = () => useContext(ChatContext)
- export default ChatContext
|