context.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use client'
  2. import type { RefObject } from 'react'
  3. import { createContext, useContext } from 'use-context-selector'
  4. import type {
  5. Callback,
  6. ChatConfig,
  7. ChatItem,
  8. Feedback,
  9. } from '../types'
  10. import type { ThemeBuilder } from '../embedded-chatbot/theme/theme-context'
  11. import type {
  12. AppConversationData,
  13. AppData,
  14. AppMeta,
  15. ConversationItem,
  16. } from '@/models/share'
  17. export type ChatWithHistoryContextValue = {
  18. appInfoError?: any
  19. appInfoLoading?: boolean
  20. appMeta?: AppMeta
  21. appData?: AppData
  22. appParams?: ChatConfig
  23. appChatListDataLoading?: boolean
  24. currentConversationId: string
  25. currentConversationItem?: ConversationItem
  26. appPrevChatList: ChatItem[]
  27. pinnedConversationList: AppConversationData['data']
  28. conversationList: AppConversationData['data']
  29. showConfigPanelBeforeChat: boolean
  30. newConversationInputs: Record<string, any>
  31. handleNewConversationInputsChange: (v: Record<string, any>) => void
  32. inputsForms: any[]
  33. handleNewConversation: () => void
  34. handleStartChat: () => void
  35. handleChangeConversation: (conversationId: string) => void
  36. handlePinConversation: (conversationId: string) => void
  37. handleUnpinConversation: (conversationId: string) => void
  38. handleDeleteConversation: (conversationId: string, callback: Callback) => void
  39. conversationRenaming: boolean
  40. handleRenameConversation: (conversationId: string, newName: string, callback: Callback) => void
  41. handleNewConversationCompleted: (newConversationId: string) => void
  42. chatShouldReloadKey: string
  43. isMobile: boolean
  44. isInstalledApp: boolean
  45. appId?: string
  46. handleFeedback: (messageId: string, feedback: Feedback) => void
  47. currentChatInstanceRef: RefObject<{ handleStop: () => void }>
  48. themeBuilder?: ThemeBuilder
  49. }
  50. export const ChatWithHistoryContext = createContext<ChatWithHistoryContextValue>({
  51. currentConversationId: '',
  52. appPrevChatList: [],
  53. pinnedConversationList: [],
  54. conversationList: [],
  55. showConfigPanelBeforeChat: false,
  56. newConversationInputs: {},
  57. handleNewConversationInputsChange: () => {},
  58. inputsForms: [],
  59. handleNewConversation: () => {},
  60. handleStartChat: () => {},
  61. handleChangeConversation: () => {},
  62. handlePinConversation: () => {},
  63. handleUnpinConversation: () => {},
  64. handleDeleteConversation: () => {},
  65. conversationRenaming: false,
  66. handleRenameConversation: () => {},
  67. handleNewConversationCompleted: () => {},
  68. chatShouldReloadKey: '',
  69. isMobile: false,
  70. isInstalledApp: false,
  71. handleFeedback: () => {},
  72. currentChatInstanceRef: { current: { handleStop: () => {} } },
  73. })
  74. export const useChatWithHistoryContext = () => useContext(ChatWithHistoryContext)