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

refactor: Use Ant Design X instead #530

Merged
merged 29 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2b52d21
chore: init of x
zombieJ Nov 26, 2024
c82f04f
chore: useXChat
zombieJ Nov 27, 2024
ec6bb69
chore: use Sender
zombieJ Nov 27, 2024
85bbf1f
Merge branch 'main' of https://github.com/petercat-ai/petercat into x
ch-liuzhide Dec 6, 2024
9af4267
Merge branch 'main' of https://github.com/petercat-ai/petercat into x
ch-liuzhide Dec 10, 2024
d87f8f5
update antd-x
ch-liuzhide Dec 18, 2024
0297bce
Merge branch 'main' of https://github.com/petercat-ai/petercat into x
ch-liuzhide Dec 18, 2024
f5d0344
add template render and thoughtchain for antdx
ch-liuzhide Dec 18, 2024
134db89
Merge branch 'main' of https://github.com/petercat-ai/petercat into x
ch-liuzhide Dec 18, 2024
b9a7c87
refactor(assistant): 添加初始化loading
ch-liuzhide Dec 19, 2024
5ff9ec3
fix(assistant): udate botinfo when assistantMeta changed
ch-liuzhide Dec 19, 2024
4a7617c
fix(assistant): fix disbaled ui
ch-liuzhide Dec 19, 2024
78f3fa4
add bottom
ch-liuzhide Dec 19, 2024
5a6550f
Merge branch 'main' of https://github.com/petercat-ai/petercat into x
ch-liuzhide Dec 19, 2024
2741d52
fix useEffect dependecy error
ch-liuzhide Dec 19, 2024
3b4d57a
upgrade @petercatai/assistant version
ch-liuzhide Dec 19, 2024
5a3e2a1
update bubble min height & fix textarea text color
ch-liuzhide Dec 19, 2024
82d7d93
Refresh the message list after the abort is completed render
ch-liuzhide Dec 19, 2024
2295bc6
fix: style pollution of the Bubble component. (#606)
YumoImer Dec 23, 2024
08a370d
resolve conversation
ch-liuzhide Dec 23, 2024
81d6bec
Merge branch 'x' of https://github.com/petercat-ai/petercat into f_x
ch-liuzhide Dec 23, 2024
ae5d843
fix name pertercat
ch-liuzhide Dec 23, 2024
abb6d9b
Merge branch 'main' of https://github.com/petercat-ai/petercat into f_x
ch-liuzhide Dec 23, 2024
7d84cee
upgrade @petercatai/assistant to 2.0.4
ch-liuzhide Dec 23, 2024
29e1443
Load the avatar by using a background image.
ch-liuzhide Dec 23, 2024
f616019
upgrade @petercatai/assistant to 2.0.5
ch-liuzhide Dec 23, 2024
0039541
fix: Fix the bug where the bot_id of the editing assistant is not upd…
ch-liuzhide Dec 24, 2024
e01132f
update yarn.lock
ch-liuzhide Dec 24, 2024
c00c955
remove @ant-design/pro-chat in pacakge.json
ch-liuzhide Dec 24, 2024
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 assistant/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $ yarn run doctor
```


## How to integrate PertercatLUI by UMD way?
## How to integrate PeterCatLUI by UMD way?

Step 1, externalize the following dependencies for your project **if you already used them in your project**:

Expand Down
50 changes: 25 additions & 25 deletions assistant/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@petercatai/assistant",
"version": "1.0.22",
"version": "2.0.7",
"description": "PeterCat Assistant Application",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"style": "dist/esm/style.css",
"browser": "dist/umd/assistant.min.js",
"repository": "https://github.com/petercat-ai/petercat.git",
"license": "MIT",
"sideEffects": [
"**/*.css"
],
"exports": {
".": {
"import": "./dist/esm/index.js"
Expand All @@ -14,25 +15,24 @@
"import": "./dist/esm/style.css"
}
},
"module": "dist/esm/index.js",
"browser": "dist/umd/assistant.min.js",
"types": "dist/esm/index.d.ts",
"style": "dist/esm/style.css",
"scripts": {
"start": "npm run dev",
"dev": "dumi dev",
"build:css": "tailwindcss -i tailwind.css -o ./src/style.css",
"build": "npm run build:css && cp ./src/style.css ./.dumi/tmp/style.css && father build",
"build:css": "tailwindcss -i tailwind.css -o ./src/style.css",
"build:watch": "father dev",
"dev": "dumi dev",
"docs:build": "dumi build",
"prepare": "dumi setup",
"doctor": "father doctor",
"lint": "npm run lint:es && npm run lint:css",
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
"prepublishOnly": "father doctor && npm run build"
"prepare": "dumi setup",
"prepublishOnly": "father doctor && npm run build",
"start": "npm run dev"
},
"authors": [],
"license": "MIT",
"sideEffects": [
"**/*.css"
],
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand All @@ -55,17 +55,10 @@
"prettier --parser=typescript --write"
]
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"react": ">=16.9.0 <19.0.0",
"react-dom": ">=16.9.0 <19.0.0"
},
"dependencies": {
"@ant-design/icons": "^5.3.5",
"@ant-design/pro-chat": "^1.9.0",
"@ant-design/pro-editor": "^1.1.1",
"@ant-design/x": "^1.0.0",
"@babel/runtime": "^7.18.0",
"antd": "^5.15.3",
"antd-style": "^3.6.1",
Expand All @@ -81,7 +74,7 @@
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@types/lodash": "^4.14.202",
"@types/lodash": "^4.17.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@umijs/lint": "^4.0.0",
Expand All @@ -97,5 +90,12 @@
"react-dom": "^18.0.0",
"stylelint": "^14.9.1"
},
"repository": "https://github.com/petercat-ai/petercat.git"
"peerDependencies": {
"react": ">=16.9.0 <19.0.0",
"react-dom": ">=16.9.0 <19.0.0"
},
"publishConfig": {
"access": "public"
},
"authors": []
}
3 changes: 1 addition & 2 deletions assistant/src/Assistant/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default () => {
apiUrl='/api/chat/stream_builder'
token='0553365a-edb1-435c-b69c-4c645290b86e'
clearMessage={true}
apiUr
/>
</div>
);
Expand All @@ -53,4 +52,4 @@ export default () => {
| `disabled` | `boolean` | `false` | 是否禁用聊天输入区域,禁用后用户无法输入消息。 |
| `disabledPlaceholder` | `string` | `undefined` | 当聊天输入区域被禁用时显示的占位符文本。 |
| `getToolsResult` | `(response: any) => void` | `undefined` | 用于接收工具处理结果的回调函数。 |

| `bottom` | `number` | `120` | 聊天助手距离底部的距离,单位为像素。 |
11 changes: 9 additions & 2 deletions assistant/src/Assistant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ export interface AssistantProps extends ChatProps {
showBubble: boolean;
isVisible: boolean;
onClose?: () => void;
bottom?: number;
}

const Assistant = (props: AssistantProps) => {
const { showBubble = true, isVisible, onClose, drawerWidth = 500 } = props;
const {
showBubble = true,
isVisible,
onClose,
drawerWidth = 500,
bottom = 120,
} = props;
const [chatVisible, setChatVisible] = useState(isVisible);
const [position, setPosition] = useState({ bottom: 120 });
const [position, setPosition] = useState({ bottom: bottom });

const toggleDrawer = () => {
setChatVisible(!chatVisible);
Expand Down
3 changes: 2 additions & 1 deletion assistant/src/Chat/components/InputAreaRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const InputAreaRender = (props: {
return (
<Form
form={form}
className="relative px-[12px] py-[10px] m-[12px] rounded-[10px] lui-input-area bg-[#f1f1f1]"
className="relative px-[12px] py-[10px] rounded-[10px] lui-input-area bg-[#f1f1f1]"
style={{ opacity: disabled ? 0.6 : 1 }}
>
{disabled && disabledPlaceholder && (
Expand All @@ -181,6 +181,7 @@ const InputAreaRender = (props: {
border: 'none',
resize: 'none',
backgroundColor: '#F1F1F1',
color: 'rgba(0, 0, 0, 0.88)',
}}
onKeyDown={handleKeyDown}
/>
Expand Down
3 changes: 2 additions & 1 deletion assistant/src/Chat/components/LoadingStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ const LoadingAnimationStart = require('../../assets/bubble-start.json');
interface LoadingStartProps {
loop?: boolean;
onComplete?: () => void;
className?: string;
}

const LoadingStart: React.FC<LoadingStartProps> = (props) => {
const { onComplete, loop = true } = props;

return (
<div className="loading">
<div className={`loading ${props.className || ''}`}>
<Lottie
animationData={LoadingAnimationStart}
loop={loop}
Expand Down
18 changes: 18 additions & 0 deletions assistant/src/Chat/components/MarkdownRender.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable react/no-danger */
import { Markdown } from '@ant-design/pro-editor';
import React from 'react';

interface IProps {
className?: string;
content: string;
}

const MarkdownRender = (props: IProps) => (
<Markdown
className="ant-pro-chat-list-item-message-content"
style={{ overflowX: 'hidden', overflowY: 'auto' }}
>
{props.content}
</Markdown>
);
export default MarkdownRender;
26 changes: 26 additions & 0 deletions assistant/src/Chat/components/MySpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';
import { Spin } from 'antd';
import React from 'react';

export interface ISpinnerProps {
loading?: boolean;
spinner?: React.ReactNode;
children?: React.ReactNode;
}

const MySpinner = (props: ISpinnerProps) => {
const { loading } = props;
if (loading) {
return (
<div className="relative w-full h-full">
<div className="absolute top-0 left-0 w-full h-full pointer-events-none flex justify-center items-center bg-white bg-opacity-75">
{props.spinner ?? <Spin />}
</div>
{props.children}
</div>
);
}
return props.children;
};

export default MySpinner;
43 changes: 36 additions & 7 deletions assistant/src/Chat/index.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
.chat_item_container{
.chat_item_container {
position: relative;
width: 100%;
max-width: 100vw;
padding: 16px;
content-visibility: auto;
contain-intrinsic-size: 100px;
}
width: 100%;
max-width: 100vw;
padding: 16px;
content-visibility: auto;
contain-intrinsic-size: 100px;
}
.petercat-avatar {
flex: 0 0 40px;
}
.petercat-avatar .ant-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
}
.petercat-header {
font-size: 12px !important;
line-height: 1 !important;
color: rgba(0, 0, 0, 0.45) !important;
}

.petercat-content-start {
padding: 8px 16px 8px 16px !important;
border-radius: 16px !important;
background: rgba(241, 241, 241, 1) !important;
}

.petercat-content-end {
padding: 8px 16px 8px 16px !important;
border-radius: 16px !important;
background: rgba(250, 228, 203, 1) !important;
}

.petercat-lui .ant-bubble-content {
min-height: 0 !important;
}
51 changes: 30 additions & 21 deletions assistant/src/Chat/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ atomId: Chat

# Chat

Chat 是一个基于 @ant-design/pro-chat 和 @ant-design/pro-editor 构建的聊天组件,提供了丰富的功能和配置选项。它支持与一个基于API的聊天服务进行交互,并且可以渲染多种消息类型。
Chat 是一个基于 @ant-design/x 和 @ant-design/pro-editor 构建的聊天组件,提供了丰富的功能和配置选项。它支持与一个基于 @ant-design/x 的聊天服务进行交互,并且可以渲染多种消息类型。

## 安装

Expand All @@ -16,6 +16,7 @@ npm install @petercatai/assistant

## 使用示例


```jsx
import React, { useEffect, useState } from 'react';
import { Chat } from '@petercatai/assistant';
Expand All @@ -26,16 +27,25 @@ export default () => {
useEffect(() => {
console.log('res', res);
}, [res]);

const meta = {
avatar: `https://mdn.alipayobjects.com/huamei_j8gzmo/afts/img/A*YAP3SI7MMHQAAAAAAAAAAAAADrPSAQ/original`,
title: 'PeterCat',
}
return (
<div style={{ height: '100vh' }}>
<Chat
disabled={false}
disabledPlaceholder="`机器人尚未配置任何内容 请在完成配置后进行对话测试`"
starters={['介绍下xxx这个项目', '查看xxx的贡献指南', '我该怎样快速上手']}
apiUrl="/api/chat/stream_builder"
helloMessage={"hello"}
disabledPlaceholder="`机器人尚未配置任何内容 ,请在完成配置后进行对话测试`"
starters={[
'介绍下xxx这个项目',
'查看xxx的贡献指南',
'我该怎样快速上手',
]}
apiUrl="/api/chat/stream_qa"
hideLogo="true"
getToolsResult={setRes}
assistantMeta={meta}
/>
</div>
);
Expand All @@ -44,19 +54,18 @@ export default () => {

## API


| 属性名 | 类型 | 默认值 | 描述 |
| -------------------- | -------------------------------- | ------------------------- | ------------------------------------------------------------------------------------- |
| `apiDomain` | `string` | `'http://api.petercat.ai'` | API域名地址,组件将通过此域名与后端服务进行通信。 |
| `apiUrl` | `string` | `undefined` | 指定聊天API的URL路径,如果未指定,将使用默认路径。 |
| `drawerWidth` | `number` | `500` | 控制聊天窗口的宽度。 |
| `assistantMeta` | `MetaData` | `{}` | 设置聊天助手的元数据信息,包括头像、标题和背景颜色。 |
| `helloMessage` | `string` | `undefined` | 设定聊天窗口打开时的欢迎消息。 |
| `starters` | `string[]` | `[]` | 聊天启动器消息的数组,用户可以选择这些消息来快速开始对话。 |
| `prompt` | `string` | `undefined` | 指定聊天的提示内容,用于指导对话的进行。 |
| `token` | `string` | `undefined` | 用于验证聊天服务的令牌。 |
| `style` | `React.CSSProperties` | `{}` | 自定义聊天组件的内联样式。 |
| `hideLogo` | `boolean` | `false` | 是否隐藏聊天窗口顶部的Logo。 |
| `disabled` | `boolean` | `false` | 是否禁用聊天输入区域,禁用后用户无法输入消息。 |
| `disabledPlaceholder`| `string` | `undefined` | 当聊天输入区域被禁用时显示的占位符文本。 |
| `getToolsResult` | `(response: any) => void` | `undefined` | 用于接收工具处理结果的回调函数。 |
| 属性名 | 类型 | 默认值 | 描述 |
| --- | --- | --- | --- |
ch-liuzhide marked this conversation as resolved.
Show resolved Hide resolved
| `apiDomain` | `string` | `'http://api.petercat.ai'` | API 域名地址,组件将通过此域名与后端服务进行通信。 |
| `apiUrl` | `string` | `undefined` | 指定聊天 API 的 URL 路径,如果未指定,将使用默认路径。 |
| `drawerWidth` | `number` | `500` | 控制聊天窗口的宽度。 |
| `assistantMeta` | `MetaData` | `{}` | 设置聊天助手的元数据信息,包括头像、标题和背景颜色。 |
| `helloMessage` | `string` | `undefined` | 设定聊天窗口打开时的欢迎消息。 |
| `starters` | `string[]` | `[]` | 聊天启动器消息的数组,用户可以选择这些消息来快速开始对话。 |
| `prompt` | `string` | `undefined` | 指定聊天的提示内容,用于指导对话的进行。 |
| `token` | `string` | `undefined` | 用于验证聊天服务的令牌。 |
| `style` | `React.CSSProperties` | `{}` | 自定义聊天组件的内联样式。 |
| `hideLogo` | `boolean` | `false` | 是否隐藏聊天窗口顶部的 Logo。 |
| `disabled` | `boolean` | `false` | 是否禁用聊天输入区域,禁用后用户无法输入消息。 |
| `disabledPlaceholder` | `string` | `undefined` | 当聊天输入区域被禁用时显示的占位符文本。 |
| `getToolsResult` | `(response: any) => void` | `undefined` | 用于接收工具处理结果的回调函数。 |
Loading
Loading