diff --git a/src/ProChat/container/index.tsx b/src/ProChat/container/index.tsx index 54ced77a..24008d50 100644 --- a/src/ProChat/container/index.tsx +++ b/src/ProChat/container/index.tsx @@ -29,6 +29,7 @@ export const ProChat = memo( assistantMeta, showTitle, request, + onResetMessage, style, className, ...props @@ -42,6 +43,7 @@ export const ProChat = memo( userMeta={userMeta} assistantMeta={assistantMeta} request={request} + onResetMessage={onResetMessage} {...props} devtoolOptions={__PRO_CHAT_STORE_DEVTOOLS__} > diff --git a/src/ProChat/demos/meta.tsx b/src/ProChat/demos/meta.tsx index 2f55d838..1744dd63 100644 --- a/src/ProChat/demos/meta.tsx +++ b/src/ProChat/demos/meta.tsx @@ -9,7 +9,10 @@ export default () => {
diff --git a/src/ProChat/mocks/threebody.ts b/src/ProChat/mocks/threebody.ts index b7883bd4..2c8b8c61 100644 --- a/src/ProChat/mocks/threebody.ts +++ b/src/ProChat/mocks/threebody.ts @@ -8,7 +8,7 @@ export const chats = { updateAt: 1697862243540, }, Sb5pAzLL: { - content: '闭嘴', + content: '保持静默,不要回答,不要回答。', createAt: 1697862247302, id: 'Sb5pAzLL', parentId: 'ZGxiX2p4', diff --git a/src/ProChat/store/action.ts b/src/ProChat/store/action.ts index dbba42aa..ee1937dc 100644 --- a/src/ProChat/store/action.ts +++ b/src/ProChat/store/action.ts @@ -83,8 +83,11 @@ export const chatAction: StateCreator ({ - clearMessage: () => { - const { dispatchMessage } = get(); + clearMessage: async () => { + const { dispatchMessage, onResetMessage } = get(); + + // 重置消息,清空聊天记录,等待 onResetMessage 完成后再清空 + if (onResetMessage) await onResetMessage(); dispatchMessage({ type: 'resetMessages' }); diff --git a/src/ProChat/store/initialState.ts b/src/ProChat/store/initialState.ts index 5cce7f20..253658e1 100644 --- a/src/ProChat/store/initialState.ts +++ b/src/ProChat/store/initialState.ts @@ -23,6 +23,12 @@ export interface ChatPropsState { */ helloMessage?: string; request?: string | ChatRequest; + + /** + * 重置消息 + * @returns + */ + onResetMessage?: () => Promise; // /** // * 控制是否流式输出 // * @default true diff --git a/src/components/Avatar/index.tsx b/src/components/Avatar/index.tsx index 56d46c39..ad74c0b3 100644 --- a/src/components/Avatar/index.tsx +++ b/src/components/Avatar/index.tsx @@ -46,6 +46,7 @@ const Avatar = memo( const isImage = Boolean( avatar && ['/', 'http', 'data:'].some((index) => avatar.startsWith(index)), ); + const isBase64 = Boolean(avatar?.startsWith('data')); const emoji = useMemo(() => avatar && !isImage && getEmoji(avatar), [avatar]); const { styles, cx } = useStyles({ background, isEmoji: Boolean(emoji), size }); @@ -60,7 +61,11 @@ const Avatar = memo( }; return isImage ? ( - + } + {...avatarProps} + {...props} + /> ) : ( {emoji ? : text?.toUpperCase().slice(0, 2)}