You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context.tsx 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use client'
  2. import type { RefObject } from 'react'
  3. import { createContext, useContext } from 'use-context-selector'
  4. import type {
  5. ChatConfig,
  6. ChatItem,
  7. Feedback,
  8. } from '../types'
  9. import type { ThemeBuilder } from './theme/theme-context'
  10. import type {
  11. AppConversationData,
  12. AppData,
  13. AppMeta,
  14. ConversationItem,
  15. } from '@/models/share'
  16. import { noop } from 'lodash-es'
  17. export type EmbeddedChatbotContextValue = {
  18. userCanAccess?: boolean
  19. appInfoError?: any
  20. appInfoLoading?: boolean
  21. appMeta?: AppMeta
  22. appData?: AppData
  23. appParams?: ChatConfig
  24. appChatListDataLoading?: boolean
  25. currentConversationId: string
  26. currentConversationItem?: ConversationItem
  27. appPrevChatList: ChatItem[]
  28. pinnedConversationList: AppConversationData['data']
  29. conversationList: AppConversationData['data']
  30. newConversationInputs: Record<string, any>
  31. newConversationInputsRef: RefObject<Record<string, any>>
  32. handleNewConversationInputsChange: (v: Record<string, any>) => void
  33. inputsForms: any[]
  34. handleNewConversation: () => void
  35. handleStartChat: (callback?: any) => void
  36. handleChangeConversation: (conversationId: string) => void
  37. handleNewConversationCompleted: (newConversationId: string) => void
  38. chatShouldReloadKey: string
  39. isMobile: boolean
  40. isInstalledApp: boolean
  41. allowResetChat: boolean
  42. appId?: string
  43. handleFeedback: (messageId: string, feedback: Feedback) => void
  44. currentChatInstanceRef: RefObject<{ handleStop: () => void }>
  45. themeBuilder?: ThemeBuilder
  46. clearChatList?: boolean
  47. setClearChatList: (state: boolean) => void
  48. isResponding?: boolean
  49. setIsResponding: (state: boolean) => void,
  50. currentConversationInputs: Record<string, any> | null,
  51. setCurrentConversationInputs: (v: Record<string, any>) => void,
  52. allInputsHidden: boolean
  53. }
  54. export const EmbeddedChatbotContext = createContext<EmbeddedChatbotContextValue>({
  55. userCanAccess: false,
  56. currentConversationId: '',
  57. appPrevChatList: [],
  58. pinnedConversationList: [],
  59. conversationList: [],
  60. newConversationInputs: {},
  61. newConversationInputsRef: { current: {} },
  62. handleNewConversationInputsChange: noop,
  63. inputsForms: [],
  64. handleNewConversation: noop,
  65. handleStartChat: noop,
  66. handleChangeConversation: noop,
  67. handleNewConversationCompleted: noop,
  68. chatShouldReloadKey: '',
  69. isMobile: false,
  70. isInstalledApp: false,
  71. allowResetChat: true,
  72. handleFeedback: noop,
  73. currentChatInstanceRef: { current: { handleStop: noop } },
  74. clearChatList: false,
  75. setClearChatList: noop,
  76. isResponding: false,
  77. setIsResponding: noop,
  78. currentConversationInputs: {},
  79. setCurrentConversationInputs: noop,
  80. allInputsHidden: false,
  81. })
  82. export const useEmbeddedChatbotContext = () => useContext(EmbeddedChatbotContext)