@lobehub/ui 1.58.0 → 1.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/ChatItem/index.d.ts +5 -4
- package/es/ChatItem/index.js +11 -6
- package/es/ChatList/Item.d.ts +50 -0
- package/es/ChatList/Item.js +78 -0
- package/es/ChatList/index.d.ts +6 -39
- package/es/ChatList/index.js +17 -75
- package/es/EditableMessageList/index.d.ts +3 -3
- package/es/EditableMessageList/index.js +1 -1
- package/es/{Chat/store → EditableMessageList}/messageReducer.d.ts +5 -4
- package/es/{Chat/store → EditableMessageList}/messageReducer.js +0 -15
- package/es/Icon/index.js +1 -1
- package/es/List/ListItem/index.js +42 -41
- package/es/List/ListItem/style.d.ts +1 -1
- package/es/List/ListItem/style.js +8 -13
- package/es/index.d.ts +2 -2
- package/es/types/chatMessage.d.ts +4 -4
- package/es/types/llm.d.ts +13 -33
- package/es/types/llm.js +1 -10
- package/package.json +1 -1
- package/es/Chat/const.d.ts +0 -1
- package/es/Chat/const.js +0 -1
- package/es/Chat/index.d.ts +0 -2
- package/es/Chat/index.js +0 -2
- package/es/Chat/store/index.d.ts +0 -19
- package/es/Chat/store/index.js +0 -15
- package/es/Chat/store/initialState.d.ts +0 -28
- package/es/Chat/store/initialState.js +0 -9
- package/es/Chat/store/store.d.ts +0 -34
- package/es/Chat/store/store.js +0 -240
- package/es/Chat/types.d.ts +0 -77
- package/es/Chat/types.js +0 -1
- package/es/Chat/utils/fetch.d.ts +0 -11
- package/es/Chat/utils/fetch.js +0 -100
package/es/ChatItem/index.d.ts
CHANGED
|
@@ -3,14 +3,11 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { type EditableMessageProps } from "../EditableMessage";
|
|
4
4
|
import { MetaData } from "../types/meta";
|
|
5
5
|
export interface ChatItemProps {
|
|
6
|
+
ErrorMessage?: ReactNode;
|
|
6
7
|
/**
|
|
7
8
|
* @description Actions to be displayed in the chat item
|
|
8
9
|
*/
|
|
9
10
|
actions?: ReactNode;
|
|
10
|
-
/**
|
|
11
|
-
* @description Props for Alert component
|
|
12
|
-
*/
|
|
13
|
-
alert?: AlertProps;
|
|
14
11
|
/**
|
|
15
12
|
* @description Metadata for the avatar
|
|
16
13
|
*/
|
|
@@ -27,6 +24,10 @@ export interface ChatItemProps {
|
|
|
27
24
|
* @description Whether the chat item is in editing mode
|
|
28
25
|
*/
|
|
29
26
|
editing?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description Props for Error render
|
|
29
|
+
*/
|
|
30
|
+
error?: AlertProps;
|
|
30
31
|
/**
|
|
31
32
|
* @description Whether the chat item is in loading state
|
|
32
33
|
*/
|
package/es/ChatItem/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["actions", "className", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "
|
|
3
|
+
var _excluded = ["actions", "className", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "renderMessage", "text", "ErrorMessage"];
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
import { Alert } from 'antd';
|
|
@@ -27,7 +27,7 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
27
27
|
_ref$type = _ref.type,
|
|
28
28
|
type = _ref$type === void 0 ? 'block' : _ref$type,
|
|
29
29
|
avatar = _ref.avatar,
|
|
30
|
-
|
|
30
|
+
error = _ref.error,
|
|
31
31
|
showTitle = _ref.showTitle,
|
|
32
32
|
time = _ref.time,
|
|
33
33
|
editing = _ref.editing,
|
|
@@ -36,6 +36,7 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
36
36
|
messageExtra = _ref.messageExtra,
|
|
37
37
|
renderMessage = _ref.renderMessage,
|
|
38
38
|
text = _ref.text,
|
|
39
|
+
ErrorMessage = _ref.ErrorMessage,
|
|
39
40
|
properties = _objectWithoutProperties(_ref, _excluded);
|
|
40
41
|
var _useStyles = useStyles({
|
|
41
42
|
avatarSize: AVATAR_SIZE,
|
|
@@ -90,10 +91,14 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
90
91
|
})]
|
|
91
92
|
}), /*#__PURE__*/_jsxs("div", {
|
|
92
93
|
className: styles.messageContent,
|
|
93
|
-
children: [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
children: [error ? /*#__PURE__*/_jsxs(Flexbox, {
|
|
95
|
+
gap: 8,
|
|
96
|
+
children: [/*#__PURE__*/_jsx(Alert, _objectSpread({
|
|
97
|
+
className: styles.alert,
|
|
98
|
+
showIcon: true,
|
|
99
|
+
type: 'error'
|
|
100
|
+
}, error)), ErrorMessage]
|
|
101
|
+
}) : /*#__PURE__*/_jsxs(Flexbox, {
|
|
97
102
|
className: cx(styles.message, editing && styles.editingContainer),
|
|
98
103
|
children: [messageContent, messageExtra && !editing ? /*#__PURE__*/_jsx("div", {
|
|
99
104
|
className: styles.messageExtra,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { type ChatItemProps } from "../ChatItem";
|
|
3
|
+
import { ChatMessage, ChatMessageError } from "../types/chatMessage";
|
|
4
|
+
import { type ActionsBarProps } from './ActionsBar';
|
|
5
|
+
export type OnMessageChange = (id: string, content: string) => void;
|
|
6
|
+
export type MessageExtra = (props: ChatMessage) => ReactNode;
|
|
7
|
+
export type OnActionClick = (actionKey: string, messageId: string) => void;
|
|
8
|
+
export type RenderMessage = (content: ReactNode, message: ChatMessage) => ReactNode;
|
|
9
|
+
export type RenderErrorMessage = (error: ChatMessageError, message: ChatMessage) => ReactNode;
|
|
10
|
+
export interface ListItemProps {
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @description 点击操作按钮的回调函数
|
|
14
|
+
*/
|
|
15
|
+
onActionClick?: OnActionClick;
|
|
16
|
+
/**
|
|
17
|
+
* @description 消息变化的回调函数
|
|
18
|
+
*/
|
|
19
|
+
onMessageChange?: OnMessageChange;
|
|
20
|
+
/**
|
|
21
|
+
* @description 渲染错误消息的函数
|
|
22
|
+
*/
|
|
23
|
+
renderErrorMessage?: RenderErrorMessage;
|
|
24
|
+
/**
|
|
25
|
+
* @description 渲染消息的函数
|
|
26
|
+
*/
|
|
27
|
+
renderMessage?: RenderMessage;
|
|
28
|
+
/**
|
|
29
|
+
* @description 渲染消息额外内容的函数
|
|
30
|
+
*/
|
|
31
|
+
renderMessageExtra?: MessageExtra;
|
|
32
|
+
/**
|
|
33
|
+
* @description 是否显示聊天项的名称
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
showTitle?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* @description 文本内容
|
|
39
|
+
*/
|
|
40
|
+
text?: ChatItemProps['text'] & ActionsBarProps['text'] & {
|
|
41
|
+
copySuccess?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* @description 聊天列表的类型
|
|
45
|
+
* @default 'chat'
|
|
46
|
+
*/
|
|
47
|
+
type?: 'docs' | 'chat';
|
|
48
|
+
}
|
|
49
|
+
declare const Item: import("react").NamedExoticComponent<ChatMessage & ListItemProps>;
|
|
50
|
+
export default Item;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["renderMessageExtra", "showTitle", "onActionClick", "onMessageChange", "type", "text", "renderMessage", "renderErrorMessage", "loading"];
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
import { App } from 'antd';
|
|
8
|
+
import copy from 'copy-to-clipboard';
|
|
9
|
+
import { memo, useCallback, useState } from 'react';
|
|
10
|
+
import ChatItem from "../ChatItem";
|
|
11
|
+
import ActionsBar from "./ActionsBar";
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
var Item = /*#__PURE__*/memo(function (_ref) {
|
|
14
|
+
var _item$error;
|
|
15
|
+
var MessageExtra = _ref.renderMessageExtra,
|
|
16
|
+
showTitle = _ref.showTitle,
|
|
17
|
+
_onActionClick = _ref.onActionClick,
|
|
18
|
+
onMessageChange = _ref.onMessageChange,
|
|
19
|
+
type = _ref.type,
|
|
20
|
+
text = _ref.text,
|
|
21
|
+
renderMessage = _ref.renderMessage,
|
|
22
|
+
renderErrorMessage = _ref.renderErrorMessage,
|
|
23
|
+
loading = _ref.loading,
|
|
24
|
+
item = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
+
var renderMessageExtra = MessageExtra ? /*#__PURE__*/_jsx(MessageExtra, _objectSpread({}, item)) : undefined;
|
|
26
|
+
var _useState = useState(false),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
editing = _useState2[0],
|
|
29
|
+
setEditing = _useState2[1];
|
|
30
|
+
var _App$useApp = App.useApp(),
|
|
31
|
+
message = _App$useApp.message;
|
|
32
|
+
var innerRenderMessage = useCallback(function (content) {
|
|
33
|
+
return renderMessage === null || renderMessage === void 0 ? void 0 : renderMessage(content, item);
|
|
34
|
+
}, [renderMessage]);
|
|
35
|
+
return /*#__PURE__*/_jsx(ChatItem, {
|
|
36
|
+
ErrorMessage: item.error ? renderErrorMessage === null || renderErrorMessage === void 0 ? void 0 : renderErrorMessage(item.error, item) : undefined,
|
|
37
|
+
actions: /*#__PURE__*/_jsx(ActionsBar, {
|
|
38
|
+
onActionClick: function onActionClick(actionKey) {
|
|
39
|
+
switch (actionKey) {
|
|
40
|
+
case 'copy':
|
|
41
|
+
{
|
|
42
|
+
copy(item.content);
|
|
43
|
+
message.success((text === null || text === void 0 ? void 0 : text.copySuccess) || 'Copy Success');
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case 'edit':
|
|
47
|
+
{
|
|
48
|
+
setEditing(true);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_onActionClick === null || _onActionClick === void 0 ? void 0 : _onActionClick(actionKey, item.id);
|
|
53
|
+
},
|
|
54
|
+
primary: item.role === 'user',
|
|
55
|
+
text: text
|
|
56
|
+
}),
|
|
57
|
+
avatar: item.meta,
|
|
58
|
+
editing: editing,
|
|
59
|
+
error: item.error ? {
|
|
60
|
+
message: (_item$error = item.error) === null || _item$error === void 0 ? void 0 : _item$error.message
|
|
61
|
+
} : undefined,
|
|
62
|
+
loading: loading,
|
|
63
|
+
message: item.content,
|
|
64
|
+
messageExtra: renderMessageExtra,
|
|
65
|
+
onChange: function onChange(value) {
|
|
66
|
+
onMessageChange === null || onMessageChange === void 0 ? void 0 : onMessageChange(item.id, value);
|
|
67
|
+
},
|
|
68
|
+
onEditingChange: setEditing,
|
|
69
|
+
placement: type === 'chat' ? item.role === 'user' ? 'right' : 'left' : 'left',
|
|
70
|
+
primary: item.role === 'user',
|
|
71
|
+
renderMessage: renderMessage ? innerRenderMessage : undefined,
|
|
72
|
+
showTitle: showTitle,
|
|
73
|
+
text: text,
|
|
74
|
+
time: item.updateAt || item.createAt,
|
|
75
|
+
type: type === 'chat' ? 'block' : 'pure'
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
export default Item;
|
package/es/ChatList/index.d.ts
CHANGED
|
@@ -1,46 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { type ActionsBarProps } from './ActionsBar';
|
|
6
|
-
export type MessageExtra = (props: ChatMessage) => ReactNode;
|
|
7
|
-
export type RenderMessage = (content: ReactNode, message: ChatMessage) => ReactNode;
|
|
8
|
-
export interface ItemProps extends ChatMessage {
|
|
9
|
-
MessageExtra?: MessageExtra;
|
|
10
|
-
onActionClick?: (actionKey: string, messageId: string) => void;
|
|
11
|
-
onMessageChange?: (id: string, content: string) => void;
|
|
12
|
-
renderMessage?: RenderMessage;
|
|
13
|
-
showTitle?: boolean;
|
|
14
|
-
text?: ChatItemProps['text'] & ActionsBarProps['text'] & {
|
|
15
|
-
copySuccess?: string;
|
|
16
|
-
};
|
|
17
|
-
type: 'docs' | 'chat';
|
|
18
|
-
}
|
|
19
|
-
export interface ChatListProps extends DivProps {
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ChatMessage, DivProps } from "../types";
|
|
3
|
+
import { ListItemProps } from './Item';
|
|
4
|
+
export interface ChatListProps extends DivProps, ListItemProps {
|
|
20
5
|
/**
|
|
21
6
|
* @description Data of chat messages to be displayed
|
|
22
7
|
*/
|
|
23
8
|
data: ChatMessage[];
|
|
24
|
-
|
|
25
|
-
* @description Callback function triggered when an action is clicked
|
|
26
|
-
* @param {string} actionKey - The key of the action
|
|
27
|
-
* @param {string} messageId - The id of the message
|
|
28
|
-
*/
|
|
29
|
-
onActionClick?: (actionKey: string, messageId: string) => void;
|
|
30
|
-
onMessageChange?: (id: string, content: string) => void;
|
|
31
|
-
renderMessage?: RenderMessage;
|
|
32
|
-
renderMessageExtra?: MessageExtra;
|
|
33
|
-
/**
|
|
34
|
-
* @description Whether to show name of the chat item
|
|
35
|
-
* @default false
|
|
36
|
-
*/
|
|
37
|
-
showTitle?: ChatItemProps['showTitle'];
|
|
38
|
-
text?: ItemProps['text'];
|
|
39
|
-
/**
|
|
40
|
-
* @description Type of chat list
|
|
41
|
-
* @default 'chat'
|
|
42
|
-
*/
|
|
43
|
-
type?: 'docs' | 'chat';
|
|
9
|
+
loadingId?: string;
|
|
44
10
|
}
|
|
11
|
+
export type { OnActionClick, OnMessageChange, RenderErrorMessage, RenderMessage } from './Item';
|
|
45
12
|
declare const ChatList: import("react").NamedExoticComponent<ChatListProps>;
|
|
46
13
|
export default ChatList;
|
package/es/ChatList/index.js
CHANGED
|
@@ -1,86 +1,26 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["
|
|
5
|
-
_excluded2 = ["onActionClick", "renderMessageExtra", "className", "data", "type", "text", "showTitle", "onMessageChange", "renderMessage"];
|
|
3
|
+
var _excluded = ["onActionClick", "renderMessageExtra", "className", "data", "type", "text", "showTitle", "onMessageChange", "renderMessage", "renderErrorMessage", "loadingId"];
|
|
6
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import { memo, useCallback, useState } from 'react';
|
|
11
|
-
import ChatItem from "../ChatItem";
|
|
12
|
-
import ActionsBar from "./ActionsBar";
|
|
6
|
+
import { memo } from 'react';
|
|
7
|
+
import Item from "./Item";
|
|
13
8
|
import { useStyles } from "./style";
|
|
14
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
-
var
|
|
16
|
-
var
|
|
10
|
+
var ChatList = /*#__PURE__*/memo(function (_ref) {
|
|
11
|
+
var onActionClick = _ref.onActionClick,
|
|
12
|
+
MessageExtra = _ref.renderMessageExtra,
|
|
13
|
+
className = _ref.className,
|
|
14
|
+
data = _ref.data,
|
|
15
|
+
_ref$type = _ref.type,
|
|
16
|
+
type = _ref$type === void 0 ? 'chat' : _ref$type,
|
|
17
|
+
text = _ref.text,
|
|
17
18
|
showTitle = _ref.showTitle,
|
|
18
|
-
_onActionClick = _ref.onActionClick,
|
|
19
19
|
onMessageChange = _ref.onMessageChange,
|
|
20
|
-
type = _ref.type,
|
|
21
|
-
text = _ref.text,
|
|
22
20
|
renderMessage = _ref.renderMessage,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
-
editing = _useState2[0],
|
|
28
|
-
setEditing = _useState2[1];
|
|
29
|
-
var _App$useApp = App.useApp(),
|
|
30
|
-
message = _App$useApp.message;
|
|
31
|
-
var innerRenderMessage = useCallback(function (content) {
|
|
32
|
-
return renderMessage === null || renderMessage === void 0 ? void 0 : renderMessage(content, item);
|
|
33
|
-
}, [renderMessage]);
|
|
34
|
-
return /*#__PURE__*/_jsx(ChatItem, {
|
|
35
|
-
actions: /*#__PURE__*/_jsx(ActionsBar, {
|
|
36
|
-
onActionClick: function onActionClick(actionKey) {
|
|
37
|
-
switch (actionKey) {
|
|
38
|
-
case 'copy':
|
|
39
|
-
{
|
|
40
|
-
copy(item.content);
|
|
41
|
-
message.success((text === null || text === void 0 ? void 0 : text.copySuccess) || 'Copy Success');
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case 'edit':
|
|
45
|
-
{
|
|
46
|
-
setEditing(true);
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
_onActionClick === null || _onActionClick === void 0 ? void 0 : _onActionClick(actionKey, item.id);
|
|
51
|
-
},
|
|
52
|
-
primary: item.role === 'user',
|
|
53
|
-
text: text
|
|
54
|
-
}),
|
|
55
|
-
avatar: item.meta,
|
|
56
|
-
editing: editing,
|
|
57
|
-
message: item.content,
|
|
58
|
-
messageExtra: renderMessageExtra,
|
|
59
|
-
onChange: function onChange(value) {
|
|
60
|
-
onMessageChange === null || onMessageChange === void 0 ? void 0 : onMessageChange(item.id, value);
|
|
61
|
-
},
|
|
62
|
-
onEditingChange: setEditing,
|
|
63
|
-
placement: type === 'chat' ? item.role === 'user' ? 'right' : 'left' : 'left',
|
|
64
|
-
primary: item.role === 'user',
|
|
65
|
-
renderMessage: renderMessage ? innerRenderMessage : undefined,
|
|
66
|
-
showTitle: showTitle,
|
|
67
|
-
text: text,
|
|
68
|
-
time: item.updateAt || item.createAt,
|
|
69
|
-
type: type === 'chat' ? 'block' : 'pure'
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
var ChatList = /*#__PURE__*/memo(function (_ref2) {
|
|
73
|
-
var onActionClick = _ref2.onActionClick,
|
|
74
|
-
MessageExtra = _ref2.renderMessageExtra,
|
|
75
|
-
className = _ref2.className,
|
|
76
|
-
data = _ref2.data,
|
|
77
|
-
_ref2$type = _ref2.type,
|
|
78
|
-
type = _ref2$type === void 0 ? 'chat' : _ref2$type,
|
|
79
|
-
text = _ref2.text,
|
|
80
|
-
showTitle = _ref2.showTitle,
|
|
81
|
-
onMessageChange = _ref2.onMessageChange,
|
|
82
|
-
renderMessage = _ref2.renderMessage,
|
|
83
|
-
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
21
|
+
renderErrorMessage = _ref.renderErrorMessage,
|
|
22
|
+
loadingId = _ref.loadingId,
|
|
23
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
84
24
|
var _useStyles = useStyles(),
|
|
85
25
|
cx = _useStyles.cx,
|
|
86
26
|
styles = _useStyles.styles;
|
|
@@ -89,10 +29,12 @@ var ChatList = /*#__PURE__*/memo(function (_ref2) {
|
|
|
89
29
|
}, props), {}, {
|
|
90
30
|
children: data.map(function (item) {
|
|
91
31
|
return /*#__PURE__*/_jsx(Item, _objectSpread({
|
|
92
|
-
|
|
32
|
+
loading: loadingId === item.id,
|
|
93
33
|
onActionClick: onActionClick,
|
|
94
34
|
onMessageChange: onMessageChange,
|
|
35
|
+
renderErrorMessage: renderErrorMessage,
|
|
95
36
|
renderMessage: renderMessage,
|
|
37
|
+
renderMessageExtra: MessageExtra,
|
|
96
38
|
showTitle: showTitle,
|
|
97
39
|
text: text,
|
|
98
40
|
type: type
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { LLMMessage } from "../types/llm";
|
|
3
3
|
export interface EditableMessageListProps {
|
|
4
4
|
/**
|
|
5
5
|
* @description The data sources to be rendered
|
|
6
6
|
*/
|
|
7
|
-
dataSources:
|
|
7
|
+
dataSources: LLMMessage[];
|
|
8
8
|
/**
|
|
9
9
|
* @description Whether the component is disabled or not
|
|
10
10
|
* @default false
|
|
@@ -14,7 +14,7 @@ export interface EditableMessageListProps {
|
|
|
14
14
|
* @description Callback function triggered when the data sources are changed
|
|
15
15
|
* @param chatMessages - the updated data sources
|
|
16
16
|
*/
|
|
17
|
-
onChange?: (chatMessages:
|
|
17
|
+
onChange?: (chatMessages: LLMMessage[]) => void;
|
|
18
18
|
}
|
|
19
19
|
export declare const EditableMessageList: import("react").NamedExoticComponent<EditableMessageListProps>;
|
|
20
20
|
export default EditableMessageList;
|
|
@@ -5,9 +5,9 @@ import { Plus, Trash } from 'lucide-react';
|
|
|
5
5
|
import { memo, useEffect, useReducer } from 'react';
|
|
6
6
|
import { Flexbox } from 'react-layout-kit';
|
|
7
7
|
import ActionIcon from "../ActionIcon";
|
|
8
|
-
import { messagesReducer } from "../Chat";
|
|
9
8
|
import Icon from "../Icon";
|
|
10
9
|
import { ControlInput } from "../components/ControlInput";
|
|
10
|
+
import { messagesReducer } from "./messageReducer";
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
export var EditableMessageList = /*#__PURE__*/memo(function (_ref) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatMessageError, MessageRoleType } from "../types";
|
|
2
|
+
import { LLMMessage } from "../types/llm";
|
|
2
3
|
export type MessageDispatch = {
|
|
3
|
-
message:
|
|
4
|
+
message: LLMMessage;
|
|
4
5
|
type: 'addMessage';
|
|
5
6
|
} | {
|
|
6
7
|
index: number;
|
|
7
|
-
message:
|
|
8
|
+
message: LLMMessage;
|
|
8
9
|
type: 'insertMessage';
|
|
9
10
|
} | {
|
|
10
11
|
index: number;
|
|
@@ -34,4 +35,4 @@ export type MessageDispatch = {
|
|
|
34
35
|
index: number;
|
|
35
36
|
type: 'setErrorMessage';
|
|
36
37
|
};
|
|
37
|
-
export declare const messagesReducer: (state:
|
|
38
|
+
export declare const messagesReducer: (state: LLMMessage[], payload: MessageDispatch) => LLMMessage[];
|
|
@@ -66,21 +66,6 @@ export var messagesReducer = function messagesReducer(state, payload) {
|
|
|
66
66
|
draftState[index].error = error;
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
case 'updateMessageChoice':
|
|
70
|
-
{
|
|
71
|
-
return produce(state, function (draftState) {
|
|
72
|
-
var index = payload.index,
|
|
73
|
-
message = payload.message;
|
|
74
|
-
var botMessage = draftState[index];
|
|
75
|
-
var previousMessage = botMessage.content;
|
|
76
|
-
botMessage.content = message;
|
|
77
|
-
if (botMessage.choices) {
|
|
78
|
-
botMessage.choices.push(previousMessage);
|
|
79
|
-
} else {
|
|
80
|
-
botMessage.choices = [previousMessage];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
69
|
default:
|
|
85
70
|
{
|
|
86
71
|
throw new Error('暂未实现的 type,请检查 reducer');
|
package/es/Icon/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var Icon = /*#__PURE__*/memo(function (_ref) {
|
|
|
68
68
|
}, props), {}, {
|
|
69
69
|
children: /*#__PURE__*/_jsx(SvgIcon, {
|
|
70
70
|
color: color,
|
|
71
|
-
fill: fill,
|
|
71
|
+
fill: fill !== null && fill !== void 0 ? fill : 'transparent',
|
|
72
72
|
focusable: false,
|
|
73
73
|
height: fontSize,
|
|
74
74
|
size: fontSize,
|
|
@@ -33,14 +33,8 @@ var ListItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, refere
|
|
|
33
33
|
var _useStyles = useStyles(),
|
|
34
34
|
styles = _useStyles.styles,
|
|
35
35
|
cx = _useStyles.cx;
|
|
36
|
-
return /*#__PURE__*/
|
|
37
|
-
align: 'flex-start',
|
|
36
|
+
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
38
37
|
className: cx(styles.container, active && styles.active, className),
|
|
39
|
-
distribution: 'space-between',
|
|
40
|
-
gap: 8,
|
|
41
|
-
horizontal: true,
|
|
42
|
-
paddingBlock: 12,
|
|
43
|
-
paddingInline: 16,
|
|
44
38
|
ref: reference,
|
|
45
39
|
style: style
|
|
46
40
|
}, props), {}, {
|
|
@@ -50,41 +44,48 @@ var ListItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, refere
|
|
|
50
44
|
onMouseLeave: function onMouseLeave() {
|
|
51
45
|
onHoverChange === null || onHoverChange === void 0 ? void 0 : onHoverChange(false);
|
|
52
46
|
},
|
|
53
|
-
children:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
className: styles.content,
|
|
59
|
-
children: [/*#__PURE__*/_jsx(Flexbox, {
|
|
60
|
-
distribution: 'space-between',
|
|
61
|
-
horizontal: true,
|
|
62
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
63
|
-
className: styles.title,
|
|
64
|
-
children: title
|
|
65
|
-
})
|
|
66
|
-
}), description && /*#__PURE__*/_jsx("div", {
|
|
67
|
-
className: styles.desc,
|
|
68
|
-
children: description
|
|
69
|
-
}), /*#__PURE__*/_jsx("div", {
|
|
70
|
-
className: styles.textOverlay
|
|
71
|
-
})]
|
|
72
|
-
}), loading ? /*#__PURE__*/_jsx(LoadingOutlined, {
|
|
73
|
-
spin: true
|
|
74
|
-
}) : showAction ? /*#__PURE__*/_jsx(Flexbox, {
|
|
75
|
-
gap: 4,
|
|
47
|
+
children: /*#__PURE__*/_jsxs(Flexbox, {
|
|
48
|
+
align: 'flex-start',
|
|
49
|
+
className: styles.inner,
|
|
50
|
+
distribution: 'space-between',
|
|
51
|
+
gap: 8,
|
|
76
52
|
horizontal: true,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
53
|
+
paddingBlock: 12,
|
|
54
|
+
paddingInline: 16,
|
|
55
|
+
children: [avatar !== null && avatar !== void 0 ? avatar : /*#__PURE__*/_jsx(MessageOutlined, {
|
|
56
|
+
style: {
|
|
57
|
+
marginTop: 4
|
|
58
|
+
}
|
|
59
|
+
}), /*#__PURE__*/_jsxs(Flexbox, {
|
|
60
|
+
className: styles.content,
|
|
61
|
+
children: [/*#__PURE__*/_jsx(Flexbox, {
|
|
62
|
+
distribution: 'space-between',
|
|
63
|
+
horizontal: true,
|
|
64
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
65
|
+
className: styles.title,
|
|
66
|
+
children: title
|
|
67
|
+
})
|
|
68
|
+
}), description && /*#__PURE__*/_jsx("div", {
|
|
69
|
+
className: styles.desc,
|
|
70
|
+
children: description
|
|
71
|
+
})]
|
|
72
|
+
}), loading ? /*#__PURE__*/_jsx(LoadingOutlined, {
|
|
73
|
+
spin: true
|
|
74
|
+
}) : showAction ? /*#__PURE__*/_jsx(Flexbox, {
|
|
75
|
+
gap: 4,
|
|
76
|
+
horizontal: true,
|
|
77
|
+
onClick: function onClick(e) {
|
|
78
|
+
e.stopPropagation();
|
|
79
|
+
},
|
|
80
|
+
style: {
|
|
81
|
+
display: showAction ? undefined : 'none'
|
|
82
|
+
},
|
|
83
|
+
children: renderActions
|
|
84
|
+
}) : date && /*#__PURE__*/_jsx("div", {
|
|
85
|
+
className: cx(styles.time, classNames.time),
|
|
86
|
+
children: getChatItemTime(date)
|
|
87
|
+
}), children]
|
|
88
|
+
})
|
|
88
89
|
}));
|
|
89
90
|
}));
|
|
90
91
|
export default ListItem;
|
|
@@ -3,7 +3,7 @@ export declare const useStyles: (props?: unknown) => import("antd-style").Return
|
|
|
3
3
|
container: import("antd-style").SerializedStyles;
|
|
4
4
|
content: import("antd-style").SerializedStyles;
|
|
5
5
|
desc: import("antd-style").SerializedStyles;
|
|
6
|
-
|
|
6
|
+
inner: import("antd-style").SerializedStyles;
|
|
7
7
|
time: import("antd-style").SerializedStyles;
|
|
8
8
|
title: import("antd-style").SerializedStyles;
|
|
9
9
|
}>;
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
|
-
import { convertAlphaToSolid } from "../../utils/colorUtils";
|
|
5
4
|
export var useStyles = createStyles(function (_ref) {
|
|
6
5
|
var css = _ref.css,
|
|
7
|
-
cx = _ref.cx,
|
|
8
6
|
token = _ref.token;
|
|
9
|
-
var textOverlay = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --overlay-background: ", ";\n\n position: absolute;\n z-index: 10;\n top: 0;\n right: 0;\n\n width: 32px;\n height: 44px;\n\n background: linear-gradient(to right, transparent, var(--overlay-background));\n "])), token.colorBgContainer);
|
|
10
|
-
var overlayColor = convertAlphaToSolid(token.colorFillContent, token.colorBgContainer);
|
|
11
|
-
var hoverOverlay = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n .", " {\n --overlay-background: ", ";\n }\n "])), cx(textOverlay), overlayColor);
|
|
12
7
|
return {
|
|
13
|
-
active: css(
|
|
14
|
-
container: css(
|
|
15
|
-
content: css(
|
|
16
|
-
desc: css(
|
|
17
|
-
|
|
18
|
-
time: css(
|
|
19
|
-
title: css(
|
|
8
|
+
active: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: ", ";\n background-color: ", ";\n\n &:hover {\n background-color: ", ";\n }\n "])), token.colorText, token.colorFillTertiary, token.colorFill),
|
|
9
|
+
container: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: pointer;\n color: ", ";\n transition: background-color 200ms ", ";\n\n &:active {\n background-color: ", " !important;\n }\n\n &:hover {\n background-color: ", ";\n }\n "])), token.colorTextTertiary, token.motionEaseOut, token.colorFill, token.colorFillSecondary),
|
|
10
|
+
content: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n flex: 1;\n "]))),
|
|
11
|
+
desc: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n overflow: hidden;\n\n width: 100%;\n margin-top: 2px;\n\n font-size: 12px;\n color: ", ";\n text-overflow: ellipsis;\n white-space: nowrap;\n "])), token.colorTextDescription),
|
|
12
|
+
inner: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n transition: scale 400ms ", ";\n\n &:active {\n scale: 0.95;\n }\n "])), token.motionEaseOut),
|
|
13
|
+
time: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n font-size: 12px;\n color: ", ";\n "])), token.colorTextPlaceholder),
|
|
14
|
+
title: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n overflow: hidden;\n\n width: 100%;\n\n font-size: 16px;\n color: ", ";\n text-overflow: ellipsis;\n white-space: nowrap;\n "])), token.colorText)
|
|
20
15
|
};
|
|
21
16
|
});
|
package/es/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export { default as ActionIcon, type ActionIconProps, type ActionIconSize } from
|
|
|
2
2
|
export { default as ActionIconGroup, type ActionIconGroupProps } from './ActionIconGroup';
|
|
3
3
|
export { default as Avatar, type AvatarProps } from './Avatar';
|
|
4
4
|
export { default as Burger, type BurgerProps } from './Burger';
|
|
5
|
-
export type { ChatMessage, MessageRoleType } from './Chat';
|
|
6
5
|
export { default as ChatHeader, type ChatHeaderProps } from './ChatHeader';
|
|
7
6
|
export { default as ChatInputArea, type ChatInputAreaProps } from './ChatInputArea';
|
|
8
7
|
export { default as ChatItem, type ChatItemProps } from './ChatItem';
|
|
9
|
-
export {
|
|
8
|
+
export type { ChatListProps, OnActionClick, OnMessageChange, RenderErrorMessage, RenderMessage, } from './ChatList';
|
|
9
|
+
export { default as ChatList } from './ChatList';
|
|
10
10
|
export { default as CodeEditor, type CodeEditorProps } from './CodeEditor';
|
|
11
11
|
export { default as ColorScales, type ColorScalesProps } from './ColorScales';
|
|
12
12
|
export { default as ContextMenu, type ContextMenuProps } from './ContextMenu';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LLMRoleType } from './llm';
|
|
2
1
|
import { BaseDataModel } from './meta';
|
|
2
|
+
export type MessageRoleType = 'user' | 'system' | 'assistant' | 'function';
|
|
3
3
|
/**
|
|
4
4
|
* 聊天消息错误对象
|
|
5
5
|
*/
|
|
@@ -8,8 +8,7 @@ export interface ChatMessageError {
|
|
|
8
8
|
* 错误信息
|
|
9
9
|
*/
|
|
10
10
|
message: string;
|
|
11
|
-
|
|
12
|
-
type: 'general' | 'llm';
|
|
11
|
+
type?: string;
|
|
13
12
|
}
|
|
14
13
|
export interface ChatMessage extends BaseDataModel {
|
|
15
14
|
/**
|
|
@@ -17,6 +16,7 @@ export interface ChatMessage extends BaseDataModel {
|
|
|
17
16
|
* @description 消息内容
|
|
18
17
|
*/
|
|
19
18
|
content: string;
|
|
19
|
+
error?: ChatMessageError;
|
|
20
20
|
extra?: {
|
|
21
21
|
translate?: {
|
|
22
22
|
target: string;
|
|
@@ -29,5 +29,5 @@ export interface ChatMessage extends BaseDataModel {
|
|
|
29
29
|
* 角色
|
|
30
30
|
* @description 消息发送者的角色
|
|
31
31
|
*/
|
|
32
|
-
role:
|
|
32
|
+
role: MessageRoleType;
|
|
33
33
|
}
|