Skip to content

Commit

Permalink
Merge pull request #19 from ONLY-yours/feat/update
Browse files Browse the repository at this point in the history
✨ feat: chatList hello dom support ReactNode
  • Loading branch information
ONLY-yours authored Dec 11, 2023
2 parents b723db1 + 62db9be commit bb2f3c8
Showing 13 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

# production
**/dist
**/docs-dist
/.vscode
/es
/lib
2 changes: 1 addition & 1 deletion src/ActionIconGroup/index.tsx
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ export interface ActionEvent {
keyPath: string[];
}

export interface ActionIconGroupProps extends DivProps {
export interface ActionIconGroupProps extends Omit<DivProps, 'content'> {
/**
* @description The direction of the icons
* @default "row"
5 changes: 3 additions & 2 deletions src/ChatList/ActionsBar.tsx
Original file line number Diff line number Diff line change
@@ -10,16 +10,17 @@ export interface ActionsBarProps extends ActionIconGroupProps {
edit?: string;
regenerate?: string;
};
content?: React.ReactNode | undefined;
}

const ActionsBar = memo<ActionsBarProps>(({ text, ...props }) => {
const ActionsBar = memo<ActionsBarProps>(({ text, ...rest }) => {
const { regenerate, edit, copy, divider, del } = useChatListActionsBar(text);
return (
<ActionIconGroup
dropdownMenu={[edit, copy, regenerate, divider, del]}
items={[regenerate, edit]}
type="ghost"
{...props}
{...rest}
/>
);
});
2 changes: 1 addition & 1 deletion src/ChatList/Item.tsx
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ const Item = memo<ChatListItemProps>((props) => {
const handleActionClick: ListItemProps['onActionsClick'] = (action, data) => {
switch (action.key) {
case 'copy': {
copy(data.content);
copy(data.content as string);
message.success(text?.copySuccess || 'Copy Success');
break;
}
1 change: 1 addition & 0 deletions src/ProChat/components/ChatList/Actions/index.ts
Original file line number Diff line number Diff line change
@@ -10,4 +10,5 @@ export const renderActions: ChatListProps['renderActions'] = {
function: FunctionActionsBar,
system: DefaultActionsBar,
user: UserActionsBar,
hello: () => undefined,
};
9 changes: 9 additions & 0 deletions src/ProChat/components/ChatList/Messages/Hello.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RenderMessage } from '@/ChatList';
import { memo } from 'react';
import { DefaultMessage } from './Default';

export const HelloMessage: RenderMessage = memo((props) => {
const { content } = props;
if (typeof content === 'string') return <DefaultMessage {...props} />;
return content;
});
2 changes: 2 additions & 0 deletions src/ProChat/components/ChatList/Messages/index.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@ import { ChatListProps } from '@/ChatList';

import { AssistantMessage } from './Assistant';
import { DefaultMessage } from './Default';
import { HelloMessage } from './Hello';

export const renderMessages: ChatListProps['renderMessages'] = {
hello: HelloMessage,
assistant: AssistantMessage,
default: DefaultMessage,
};
1 change: 1 addition & 0 deletions src/ProChat/demos/helloMessage.tsx
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ export default () => {
const theme = useTheme();
return (
<div style={{ background: theme.colorBgLayout }}>
<ProChat helloMessage={<div>{'这是一条自定义 ReactNode 消息'}</div>} />
<ProChat
helloMessage={
'这是一条自定义消息,支持 markdown 消息,例如:[ProChat](https://github.com/ant-design/pro-chat)'
2 changes: 1 addition & 1 deletion src/ProChat/index.md
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ useProChat hooks 必须在包裹 `ProChatProvider` 后方可使用。
| chats | 聊天记录 | ChatMessageMap | - |
| onChatsChange | 聊天记录变化回调函数, | (chats: ChatMessageMap) => void | chat |
| displayMode | 显示模式,默认是 chat | 'chat' \| 'docs' | - |
| helloMessage | 欢迎消息 | string | - |
| helloMessage | 欢迎消息 | string\| ReactNode | - |
| request | 请求消息 | string \| ChatRequest | - |
| onResetMessage | 重置消息回调函数 | `() => Promise<void>` | - |
| genMessageId | 生成消息 id 的函数,如果你的项目需要持久化时才需要使用 | `() => Promise<string>`` | nanoid |
3 changes: 2 additions & 1 deletion src/ProChat/store/initialState.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { ModelConfig } from '@/ProChat/types/config';
import { MetaData } from '@/ProChat/types/meta';
import { ChatMessage, ChatMessageMap } from '@/types/message';
import { TextAreaProps } from 'antd/es/input';
import { ReactNode } from 'react';
import { FlexBasicProps } from 'react-layout-kit/lib/FlexBasic';

export type ChatRequest = (messages: ChatMessage[], config: ModelConfig) => Promise<Response>;
@@ -23,7 +24,7 @@ export interface ChatPropsState<T extends Record<string, any> = Record<string, a
/**
* 帮助消息
*/
helloMessage?: string;
helloMessage?: ReactNode;
request?: string | ChatRequest;

/**
2 changes: 1 addition & 1 deletion src/ProChat/store/selectors/chat.ts
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ export const currentChatsWithGuideMessage = (s: ChatStore): ChatMessage[] => {
extra: {},
id: 'default',
meta: s.assistantMeta,
role: 'assistant',
role: 'hello',
updateAt: Date.now(),
} as ChatMessage;

2 changes: 1 addition & 1 deletion src/ProChat/types/chat.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ export interface OpenAIChatMessage {
* @title 内容
* @description 消息内容
*/
content: string;
content: React.ReactNode;

function_call?: OpenAIFunctionCall;
name?: string;
3 changes: 2 additions & 1 deletion src/types/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ModelRoleType } from '@/ProChat/types/config';
import { ReactNode } from 'react';

/**
* 聊天消息错误对象
@@ -14,7 +15,7 @@ export interface ChatMessage<T extends Record<string, any> = Record<string, any>
* @title 内容
* @description 消息内容
*/
content: string;
content: ReactNode;
error?: any;
model?: string;
name?: string;

0 comments on commit bb2f3c8

Please sign in to comment.