interface.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 { Message } from '@douyinfe/semi-foundation/chat/foundation';
  6. import type { TooltipProps } from '../tooltip';
  7. export { Message };
  8. export interface CommonChatsProps {
  9. align?: 'leftRight' | 'leftAlign';
  10. mode?: 'bubble' | 'noBubble' | 'userBubble';
  11. chats?: Message[];
  12. roleConfig?: RoleConfig;
  13. onMessageDelete?: (message?: Message) => void;
  14. onChatsChange?: (chats?: Message[]) => void;
  15. onMessageBadFeedback?: (message?: Message) => void;
  16. onMessageGoodFeedback?: (message?: Message) => void;
  17. onMessageReset?: (message?: Message) => void;
  18. onMessageCopy?: (message?: Message) => void;
  19. chatBoxRenderConfig?: ChatBoxRenderConfig;
  20. customMarkDownComponents?: MDXProps['components']
  21. }
  22. export interface ChatProps extends CommonChatsProps {
  23. style?: React.CSSProperties;
  24. className?: string;
  25. hints?: string[];
  26. renderHintBox?: (props: {content: string; index: number;onHintClick: () => void}) => React.ReactNode;
  27. onHintClick?: (hint: string) => void;
  28. onChatsChange?: (chats?: Message[]) => void;
  29. onStopGenerator?: (e?: MouseEvent) => void;
  30. customMarkDownComponents?: MDXProps['components'];
  31. onClear?: () => void;
  32. onInputChange?: (props: { value?: string; attachment?: FileItem[] }) => void;
  33. onMessageSend?: (content: string, attachment: FileItem[]) => void;
  34. inputBoxStyle?: React.CSSProperties;
  35. inputBoxCls?: string;
  36. renderInputArea?: (props?: RenderInputAreaProps) => ReactNode;
  37. placeholder?: string;
  38. topSlot?: ReactNode | ReactNode[];
  39. bottomSlot?: ReactNode | ReactNode[];
  40. showStopGenerate?: boolean;
  41. hintStyle?: React.CSSProperties;
  42. hintCls?: string;
  43. uploadProps?: UploadProps;
  44. uploadTipProps?: TooltipProps;
  45. showClearContext?: boolean;
  46. sendHotKey?: 'enter' | 'shift+enter'
  47. }
  48. export interface RenderInputAreaProps {
  49. defaultNode?: ReactNode;
  50. onSend?: (content?: string, attachment?: FileItem[]) => void;
  51. onClear?: (e?: any) => void
  52. }
  53. export interface ChatBoxRenderConfig {
  54. renderChatBoxTitle?: (props: {role?: Metadata; defaultTitle?: ReactNode}) => ReactNode;
  55. renderChatBoxAvatar?: (props: { role?: Metadata; defaultAvatar?: ReactNode}) => ReactNode;
  56. renderChatBoxContent?: (props: {message?: Message; role?: Metadata; defaultContent?: ReactNode | ReactNode[]; className?: string}) => ReactNode;
  57. renderChatBoxAction?: (props: {message?: Message; defaultActions?: ReactNode | ReactNode[]; className: string}) => ReactNode;
  58. renderFullChatBox?: (props: {message?: Message; role?: Metadata; defaultNodes?: FullChatBoxNodes; className: string}) => ReactNode
  59. }
  60. export interface FullChatBoxNodes {
  61. avatar?: ReactNode;
  62. title?: ReactNode;
  63. content?: ReactNode;
  64. action?: ReactNode
  65. }
  66. export interface RoleConfig {
  67. user?: Metadata;
  68. assistant?: Metadata;
  69. system?: Metadata;
  70. [x: string]: Metadata
  71. }
  72. export interface Metadata {
  73. name?: string;
  74. avatar?: string;
  75. color?: string;
  76. [x: string]: any
  77. }
  78. export interface ChatState {
  79. chats?: Message[];
  80. isLoading?: boolean;
  81. backBottomVisible?: boolean;
  82. scrollVisible?: boolean;
  83. wheelScroll?: boolean;
  84. cacheHints?: string[];
  85. uploadAreaVisible?: boolean
  86. }
  87. export interface ChatBoxProps extends Omit<CommonChatsProps, "chats"> {
  88. toast?: any;
  89. style?: React.CSSProperties;
  90. className?: string;
  91. previousMessage?: Message;
  92. message?: Message;
  93. lastChat?: boolean;
  94. customMarkDownComponents?: MDXProps['components']
  95. }
  96. export interface InputBoxProps {
  97. showClearContext?: boolean;
  98. sendHotKey?: 'enter' | 'shift+enter';
  99. placeholder: string;
  100. className?: string;
  101. style?: React.CSSProperties;
  102. disableSend?: boolean;
  103. uploadRef?: React.RefObject<Upload>;
  104. uploadTipProps?: TooltipProps;
  105. uploadProps?: UploadProps;
  106. manualUpload?: (file: File[]) => void;
  107. renderInputArea?: (props: RenderInputAreaProps) => React.ReactNode;
  108. onSend?: (content: string, attachment: FileItem[]) => void;
  109. onClearContext?: (e: any) => void;
  110. onInputChange?: (props: {inputValue: string; attachment: FileItem[]}) => void
  111. }
  112. export interface InputBoxState {
  113. content: string;
  114. attachment: FileItem[]
  115. }