1
0

interface.ts 5.5 KB

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