interface.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. hints?: string[];
  30. renderHintBox?: (props: {content: string; index: number;onHintClick: () => void}) => React.ReactNode;
  31. onHintClick?: (hint: string) => void;
  32. onChatsChange?: (chats?: Message[]) => void;
  33. onStopGenerator?: (e?: MouseEvent) => void;
  34. customMarkDownComponents?: MDXProps['components'];
  35. onClear?: () => void;
  36. onInputChange?: (props: { value?: string; attachment?: FileItem[] }) => void;
  37. onMessageSend?: (content: string, attachment: FileItem[]) => void;
  38. /**
  39. * 是否允许输入框发送文字消息和文件
  40. * 默认true,受控属性
  41. */
  42. allowSend?: boolean;
  43. inputBoxStyle?: React.CSSProperties;
  44. inputBoxCls?: string;
  45. renderInputArea?: (props?: RenderInputAreaProps) => ReactNode;
  46. placeholder?: string;
  47. topSlot?: ReactNode | ReactNode[];
  48. bottomSlot?: ReactNode | ReactNode[];
  49. showStopGenerate?: boolean;
  50. hintStyle?: React.CSSProperties;
  51. hintCls?: string;
  52. uploadProps?: UploadProps;
  53. uploadTipProps?: TooltipProps;
  54. showClearContext?: boolean;
  55. sendHotKey?: 'enter' | 'shift+enter';
  56. enableUpload?: boolean | EnableUploadProps
  57. }
  58. export interface RenderInputAreaProps {
  59. defaultNode?: ReactNode;
  60. onSend?: (content?: string, attachment?: FileItem[]) => void;
  61. onClear?: (e?: any) => void;
  62. detailProps?: {
  63. clearContextNode?: ReactNode;
  64. uploadNode?: ReactNode;
  65. inputNode?: ReactNode;
  66. sendNode?: ReactNode;
  67. onClick?: (e?: MouseEvent) => void
  68. }
  69. }
  70. export interface RenderTitleProps {
  71. message?: Message;
  72. role?: Metadata;
  73. defaultTitle?: ReactNode
  74. }
  75. export interface RenderAvatarProps {
  76. message?: Message;
  77. role?: Metadata;
  78. defaultAvatar?: ReactNode
  79. }
  80. export interface RenderContentProps {
  81. message?: Message;
  82. role?: Metadata;
  83. defaultContent?: ReactNode | ReactNode[];
  84. className?: string
  85. }
  86. export interface DefaultActionNodeObj {
  87. copyNode: ReactNode;
  88. likeNode: ReactNode;
  89. dislikeNode: ReactNode;
  90. resetNode: ReactNode;
  91. deleteNode: ReactNode
  92. }
  93. export interface RenderActionProps {
  94. message?: Message;
  95. defaultActions?: ReactNode | ReactNode[];
  96. className: string;
  97. defaultActionsObj?: DefaultActionNodeObj
  98. }
  99. export interface RenderFullChatBoxProps {
  100. message?: Message;
  101. role?: Metadata;
  102. defaultNodes?: FullChatBoxNodes;
  103. className: string
  104. }
  105. export interface ChatBoxRenderConfig {
  106. renderChatBoxTitle?: (props: RenderTitleProps) => ReactNode;
  107. renderChatBoxAvatar?: (props: RenderAvatarProps) => ReactNode;
  108. renderChatBoxContent?: (props: RenderContentProps) => ReactNode;
  109. renderChatBoxAction?: (props: RenderActionProps) => ReactNode;
  110. renderFullChatBox?: (props: RenderFullChatBoxProps) => ReactNode
  111. }
  112. export interface FullChatBoxNodes {
  113. avatar?: ReactNode;
  114. title?: ReactNode;
  115. content?: ReactNode;
  116. action?: ReactNode
  117. }
  118. export interface RoleConfig {
  119. user?: Metadata;
  120. assistant?: Metadata;
  121. system?: Metadata;
  122. [x: string]: Metadata
  123. }
  124. export interface Metadata {
  125. name?: string;
  126. avatar?: string;
  127. color?: string;
  128. [x: string]: any
  129. }
  130. export interface ChatState {
  131. chats?: Message[];
  132. isLoading?: boolean;
  133. backBottomVisible?: boolean;
  134. scrollVisible?: boolean;
  135. wheelScroll?: boolean;
  136. cacheHints?: string[];
  137. uploadAreaVisible?: boolean
  138. }
  139. export interface ChatBoxProps extends Omit<CommonChatsProps, "chats"> {
  140. toast?: any;
  141. style?: React.CSSProperties;
  142. className?: string;
  143. previousMessage?: Message;
  144. message?: Message;
  145. lastChat?: boolean;
  146. customMarkDownComponents?: MDXProps['components']
  147. }
  148. export interface InputBoxProps {
  149. showClearContext?: boolean;
  150. sendHotKey?: 'enter' | 'shift+enter';
  151. placeholder: string;
  152. className?: string;
  153. style?: React.CSSProperties;
  154. disableSend?: boolean;
  155. uploadRef?: React.RefObject<Upload>;
  156. uploadTipProps?: TooltipProps;
  157. uploadProps?: UploadProps;
  158. manualUpload?: (file: File[]) => void;
  159. renderInputArea?: (props: RenderInputAreaProps) => React.ReactNode;
  160. onSend?: (content: string, attachment: FileItem[]) => void;
  161. onClearContext?: (e: any) => void;
  162. onInputChange?: (props: {inputValue: string; attachment: FileItem[]}) => void;
  163. clickUpload?: boolean;
  164. pasteUpload?: boolean;
  165. /**
  166. * 是否允许输入框发送文字消息和文件,默认true
  167. */
  168. allowSend?: boolean
  169. }
  170. export interface InputBoxState {
  171. content: string;
  172. attachment: FileItem[]
  173. }