Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: optimize pushChat function #244

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ProChat/hooks/useProChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface ProChatInstance
* 往数据流中推送消息
* @returns void
*/
pushChat: (chats: { id?: string; content: string; role: string }) => void;
pushChat: (chats: { id?: string; content: string; role: string; [key: string]: any }) => void;
/**
* 获取当前聊天消息列表
* @returns ChatMessage[]
Expand Down
6 changes: 4 additions & 2 deletions src/ProChat/store/reducers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ export const messagesReducer = (
case 'addMessage': {
return produce(state, (draftState) => {
const mid = payload.id || nanoid();
// drop type from payload, otherwise the content display in a wrong way
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { type: _, ...rest } = payload;

draftState.push({
content: payload.message,
createAt: Date.now(),
id: mid,
parentId: payload.parentId,
role: payload.role,
updateAt: Date.now(),
...rest,
});
});
}
Expand Down
Loading