您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

context.tsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. export type EmbeddedChatbotContextValue = {
  17. appInfoError?: any
  18. appInfoLoading?: boolean
  19. appMeta?: AppMeta
  20. appData?: AppData
  21. appParams?: ChatConfig
  22. appChatListDataLoading?: boolean
  23. currentConversationId: string
  24. currentConversationItem?: ConversationItem
  25. appPrevChatList: ChatItem[]
  26. pinnedConversationList: AppConversationData['data']
  27. conversationList: AppConversationData['data']
  28. newConversationInputs: Record<string, any>
  29. newConversationInputsRef: RefObject<Record<string, any>>
  30. handleNewConversationInputsChange: (v: Record<string, any>) => void
  31. inputsForms: any[]
  32. handleNewConversation: () => void
  33. handleStartChat: (callback?: any) => void
  34. handleChangeConversation: (conversationId: string) => void
  35. handleNewConversationCompleted: (newConversationId: string) => void
  36. chatShouldReloadKey: string
  37. isMobile: boolean
  38. isInstalledApp: boolean
  39. appId?: string
  40. handleFeedback: (messageId: string, feedback: Feedback) => void
  41. currentChatInstanceRef: RefObject<{ handleStop: () => void }>
  42. themeBuilder?: ThemeBuilder
  43. clearChatList?: boolean
  44. setClearChatList: (state: boolean) => void
  45. isResponding?: boolean
  46. setIsResponding: (state: boolean) => void,
  47. currentConversationInputs: Record<string, any> | null,
  48. setCurrentConversationInputs: (v: Record<string, any>) => void,
  49. }
  50. export const EmbeddedChatbotContext = createContext<EmbeddedChatbotContextValue>({
  51. currentConversationId: '',
  52. appPrevChatList: [],
  53. pinnedConversationList: [],
  54. conversationList: [],
  55. newConversationInputs: {},
  56. newConversationInputsRef: { current: {} },
  57. handleNewConversationInputsChange: () => {},
  58. inputsForms: [],
  59. handleNewConversation: () => {},
  60. handleStartChat: () => {},
  61. handleChangeConversation: () => {},
  62. handleNewConversationCompleted: () => {},
  63. chatShouldReloadKey: '',
  64. isMobile: false,
  65. isInstalledApp: false,
  66. handleFeedback: () => {},
  67. currentChatInstanceRef: { current: { handleStop: () => {} } },
  68. clearChatList: false,
  69. setClearChatList: () => {},
  70. isResponding: false,
  71. setIsResponding: () => {},
  72. currentConversationInputs: {},
  73. setCurrentConversationInputs: () => {},
  74. })
  75. export const useEmbeddedChatbotContext = () => useContext(EmbeddedChatbotContext)