interface.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import React, { ReactNode } from 'react';
  2. import { MDXProps } from 'mdx/types';
  3. import { Upload } from '../index';
  4. import type { FileItem, UploadProps } from '../upload';
  5. import { EnableUploadProps, Message } from '@douyinfe/semi-foundation/chat/foundation';
  6. import type { TooltipProps } from '../tooltip';
  7. import { MarkdownRenderProps as OriginMarkdownRenderProps } from '../markdownRender';
  8. export type MarkdownRenderProps = Partial<OriginMarkdownRenderProps>;
  9. export { Message };
  10. export interface CommonChatsProps {
  11. align?: 'leftRight' | 'leftAlign';
  12. mode?: 'bubble' | 'noBubble' | 'userBubble';
  13. chats?: Message[];
  14. roleConfig?: RoleConfig;
  15. onMessageDelete?: (message?: Message) => void;
  16. onChatsChange?: (chats?: Message[]) => void;
  17. onMessageBadFeedback?: (message?: Message) => void;
  18. onMessageGoodFeedback?: (message?: Message) => void;
  19. onMessageReset?: (message?: Message) => void;
  20. onMessageCopy?: (message?: Message) => void;
  21. chatBoxRenderConfig?: ChatBoxRenderConfig;
  22. customMarkDownComponents?: MDXProps['components'];
  23. renderDivider?: (message?: Message) => ReactNode;
  24. markdownRenderProps?: MarkdownRenderProps
  25. }
  26. export interface ChatProps extends CommonChatsProps {
  27. style?: React.CSSProperties;
  28. className?: string;
  29. canSend?: boolean;
  30. hints?: string[];
  31. renderHintBox?: (props: {content: string; index: number;onHintClick: () => void}) => React.ReactNode;
  32. onHintClick?: (hint: string) => void;
  33. onChatsChange?: (chats?: Message[]) => void;
  34. onStopGenerator?: (e?: MouseEvent) => void;
  35. customMarkDownComponents?: MDXProps['components'];
  36. onClear?: () => void;
  37. onInputChange?: (props: { value?: string; attachment?: FileItem[] }) => void;
  38. onMessageSend?: (content: string, attachment: FileItem[]) => void;
  39. inputBoxStyle?: React.CSSProperties;
  40. inputBoxCls?: string;
  41. renderInputArea?: (props?: RenderInputAreaProps) => ReactNode;
  42. placeholder?: string;
  43. topSlot?: ReactNode | ReactNode[];
  44. bottomSlot?: ReactNode | ReactNode[];
  45. showStopGenerate?: boolean;
  46. hintStyle?: React.CSSProperties;
  47. hintCls?: string;
  48. uploadProps?: UploadProps;
  49. uploadTipProps?: TooltipProps;
  50. showClearContext?: boolean;
  51. sendHotKey?: 'enter' | 'shift+enter';
  52. enableUpload?: boolean | EnableUploadProps
  53. }
  54. export interface RenderInputAreaProps {
  55. defaultNode?: ReactNode;
  56. onSend?: (content?: string, attachment?: FileItem[]) => void;
  57. onClear?: (e?: any) => void;
  58. detailProps?: {
  59. clearContextNode?: ReactNode;
  60. uploadNode?: ReactNode;
  61. inputNode?: ReactNode;
  62. sendNode?: ReactNode;
  63. onClick?: (e?: MouseEvent) => void
  64. }
  65. }
  66. export interface RenderTitleProps {
  67. message?: Message;
  68. role?: Metadata;
  69. defaultTitle?: ReactNode
  70. }
  71. export interface RenderAvatarProps {
  72. message?: Message;
  73. role?: Metadata;
  74. defaultAvatar?: ReactNode
  75. }
  76. export interface RenderContentProps {
  77. message?: Message;
  78. role?: Metadata;
  79. defaultContent?: ReactNode | ReactNode[];
  80. className?: string
  81. }
  82. export interface DefaultActionNodeObj {
  83. copyNode: ReactNode;
  84. likeNode: ReactNode;
  85. dislikeNode: ReactNode;
  86. resetNode: ReactNode;
  87. deleteNode: ReactNode
  88. }
  89. export interface RenderActionProps {
  90. message?: Message;
  91. defaultActions?: ReactNode | ReactNode[];
  92. className: string;
  93. defaultActionsObj?: DefaultActionNodeObj
  94. }
  95. export interface RenderFullChatBoxProps {
  96. message?: Message;
  97. role?: Metadata;
  98. defaultNodes?: FullChatBoxNodes;
  99. className: string
  100. }
  101. export interface ChatBoxRenderConfig {
  102. renderChatBoxTitle?: (props: RenderTitleProps) => ReactNode;
  103. renderChatBoxAvatar?: (props: RenderAvatarProps) => ReactNode;
  104. renderChatBoxContent?: (props: RenderContentProps) => ReactNode;
  105. renderChatBoxAction?: (props: RenderActionProps) => ReactNode;
  106. renderFullChatBox?: (props: RenderFullChatBoxProps) => ReactNode
  107. }
  108. export interface FullChatBoxNodes {
  109. avatar?: ReactNode;
  110. title?: ReactNode;
  111. content?: ReactNode;
  112. action?: ReactNode
  113. }
  114. export interface RoleConfig {
  115. user?: Metadata;
  116. assistant?: Metadata;
  117. system?: Metadata;
  118. [x: string]: Metadata
  119. }
  120. export interface Metadata {
  121. name?: string;
  122. avatar?: string;
  123. color?: string;
  124. [x: string]: any
  125. }
  126. export interface ChatState {
  127. chats?: Message[];
  128. isLoading?: boolean;
  129. backBottomVisible?: boolean;
  130. scrollVisible?: boolean;
  131. wheelScroll?: boolean;
  132. cacheHints?: string[];
  133. uploadAreaVisible?: boolean
  134. }
  135. export interface ChatBoxProps extends Omit<CommonChatsProps, "chats"> {
  136. toast?: any;
  137. style?: React.CSSProperties;
  138. className?: string;
  139. previousMessage?: Message;
  140. message?: Message;
  141. lastChat?: boolean;
  142. customMarkDownComponents?: MDXProps['components']
  143. }
  144. export interface InputBoxProps {
  145. canSend?: boolean;
  146. showClearContext?: boolean;
  147. sendHotKey?: 'enter' | 'shift+enter';
  148. placeholder: string;
  149. className?: string;
  150. style?: React.CSSProperties;
  151. disableSend?: boolean;
  152. uploadRef?: React.RefObject<Upload>;
  153. uploadTipProps?: TooltipProps;
  154. uploadProps?: UploadProps;
  155. manualUpload?: (file: File[]) => void;
  156. renderInputArea?: (props: RenderInputAreaProps) => React.ReactNode;
  157. onSend?: (content: string, attachment: FileItem[]) => void;
  158. onClearContext?: (e: any) => void;
  159. onInputChange?: (props: {inputValue: string; attachment: FileItem[]}) => void;
  160. clickUpload?: boolean;
  161. pasteUpload?: boolean
  162. }
  163. export interface InputBoxState {
  164. content: string;
  165. attachment: FileItem[]
  166. }