@lobehub/ui 1.21.0 → 1.21.1

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.
@@ -1,15 +1,16 @@
1
1
  /// <reference types="react" />
2
2
  import { type AlertProps } from 'antd';
3
3
  import type { DivProps } from "../types";
4
+ import { MetaData } from "../types/meta";
4
5
  export interface ChatItemProps extends DivProps {
5
6
  /**
6
- * @description Weather to show alert and alert config
7
+ * @description Whether to show alert and alert config
7
8
  */
8
9
  alert?: AlertProps;
9
10
  /**
10
- * @description URL of the avatar image
11
+ * @description Avatar config
11
12
  */
12
- avatar?: string;
13
+ avatar: MetaData;
13
14
  /**
14
15
  * @description Whether to add spacing between chat items
15
16
  * @default true
@@ -24,10 +25,6 @@ export interface ChatItemProps extends DivProps {
24
25
  * @description The message to be displayed
25
26
  */
26
27
  message?: string;
27
- /**
28
- * @description The name of the chat item
29
- */
30
- name?: string;
31
28
  /**
32
29
  * @description The placement of the chat item
33
30
  * @default 'left'
@@ -38,6 +35,15 @@ export interface ChatItemProps extends DivProps {
38
35
  * @default false
39
36
  */
40
37
  primary?: boolean;
38
+ /**
39
+ * @description Whether to show name of the chat item
40
+ * @default false
41
+ */
42
+ showTitle?: boolean;
43
+ /**
44
+ * @description Time of chat message
45
+ */
46
+ time?: number;
41
47
  /**
42
48
  * @description The type of chat item
43
49
  * @default 'block'
@@ -1,19 +1,20 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["className", "name", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "alert"];
3
+ var _excluded = ["className", "title", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "alert", "showTitle", "time"];
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';
7
7
  import { Loader2 } from 'lucide-react';
8
8
  import { memo } from 'react';
9
9
  import { Avatar, Icon, Markdown } from "./..";
10
+ import { formatTime } from "../utils/formatTime";
10
11
  import { useStyles } from "./style";
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
13
14
  var AVATAR_SIZE = 40;
14
15
  var ChatItem = /*#__PURE__*/memo(function (_ref) {
15
16
  var className = _ref.className,
16
- name = _ref.name,
17
+ title = _ref.title,
17
18
  primary = _ref.primary,
18
19
  _ref$borderSpacing = _ref.borderSpacing,
19
20
  borderSpacing = _ref$borderSpacing === void 0 ? true : _ref$borderSpacing,
@@ -25,13 +26,16 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
25
26
  type = _ref$type === void 0 ? 'block' : _ref$type,
26
27
  avatar = _ref.avatar,
27
28
  alert = _ref.alert,
29
+ showTitle = _ref.showTitle,
30
+ time = _ref.time,
28
31
  props = _objectWithoutProperties(_ref, _excluded);
29
32
  var _useStyles = useStyles({
30
33
  placement: placement,
31
34
  type: type,
32
- name: name,
35
+ title: title,
33
36
  primary: primary,
34
- avatarSize: AVATAR_SIZE
37
+ avatarSize: AVATAR_SIZE,
38
+ showTitle: showTitle
35
39
  }),
36
40
  cx = _useStyles.cx,
37
41
  styles = _useStyles.styles;
@@ -41,8 +45,10 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
41
45
  children: [/*#__PURE__*/_jsxs("div", {
42
46
  className: styles.avatarContainer,
43
47
  children: [/*#__PURE__*/_jsx(Avatar, {
44
- avatar: avatar,
45
- size: AVATAR_SIZE
48
+ avatar: avatar.avatar,
49
+ background: avatar.backgroundColor,
50
+ size: AVATAR_SIZE,
51
+ title: avatar.title
46
52
  }), loading && /*#__PURE__*/_jsx("div", {
47
53
  className: styles.loading,
48
54
  children: /*#__PURE__*/_jsx(Icon, {
@@ -56,9 +62,12 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
56
62
  })]
57
63
  }), /*#__PURE__*/_jsxs("div", {
58
64
  className: styles.messageContainer,
59
- children: [name && /*#__PURE__*/_jsx("div", {
60
- className: styles.name,
61
- children: name
65
+ children: [/*#__PURE__*/_jsxs("div", {
66
+ className: cx(styles.name, 'chat-item-name'),
67
+ children: [showTitle ? avatar.title || 'untitled' : null, time && /*#__PURE__*/_jsx("span", {
68
+ className: cx(type === 'pure' && !showTitle && styles.time, 'chat-item-time'),
69
+ children: formatTime(time)
70
+ })]
62
71
  }), alert ? /*#__PURE__*/_jsx(Alert, _objectSpread({
63
72
  showIcon: true
64
73
  }, alert)) : /*#__PURE__*/_jsx("div", {
@@ -1,8 +1,9 @@
1
1
  export declare const useStyles: (props?: {
2
2
  avatarSize: number;
3
- name?: string | undefined;
4
3
  placement?: "left" | "right" | undefined;
5
4
  primary?: boolean | undefined;
5
+ showTitle?: boolean | undefined;
6
+ title?: string | undefined;
6
7
  type?: "block" | "pure" | undefined;
7
8
  } | undefined) => import("antd-style").ReturnStyles<{
8
9
  container: string;
@@ -10,5 +11,6 @@ export declare const useStyles: (props?: {
10
11
  avatarContainer: import("antd-style").SerializedStyles;
11
12
  messageContainer: import("antd-style").SerializedStyles;
12
13
  name: import("antd-style").SerializedStyles;
14
+ time: string;
13
15
  message: string;
14
16
  }>;
@@ -1,25 +1,28 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
3
3
  import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref, _ref2) {
5
5
  var cx = _ref.cx,
6
6
  css = _ref.css,
7
- token = _ref.token;
7
+ token = _ref.token,
8
+ stylish = _ref.stylish;
8
9
  var placement = _ref2.placement,
9
10
  type = _ref2.type,
10
- name = _ref2.name,
11
+ title = _ref2.title,
11
12
  primary = _ref2.primary,
12
- avatarSize = _ref2.avatarSize;
13
+ avatarSize = _ref2.avatarSize,
14
+ showTitle = _ref2.showTitle;
13
15
  var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: 8px 12px;\n background-color: ", ";\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:active {\n background-color: ", ";\n }\n "])), primary ? token.colorFillSecondary : token.colorFillTertiary, token.borderRadiusLG, token.motionEaseOut, primary ? token.colorFill : token.colorFillSecondary);
14
- var pureStylish = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-top: ", ";\n "])), name ? 0 : '6px');
16
+ var pureStylish = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-top: ", ";\n "])), title ? 0 : '6px');
15
17
  var pureContainerStylish = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:hover {\n background-color: ", ";\n }\n\n &:active {\n background-color: ", ";\n }\n "])), token.borderRadiusLG, token.motionEaseOut, token.colorFillTertiary, token.colorFillSecondary);
16
18
  var typeStylish = type === 'block' ? blockStylish : pureStylish;
17
19
  return {
18
- container: cx(type === 'pure' && pureContainerStylish, css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: ", ";\n gap: 12px;\n align-items: flex-start;\n justify-content: revert;\n\n width: 100%;\n padding: 12px;\n "])), placement === 'left' ? 'row' : 'row-reverse')),
20
+ container: cx(type === 'pure' && pureContainerStylish, css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: ", ";\n gap: 12px;\n align-items: flex-start;\n justify-content: revert;\n\n width: 100%;\n padding: 12px;\n\n .chat-item-time {\n display: none;\n }\n\n &:hover {\n .chat-item-time {\n display: inline-block;\n }\n }\n "])), placement === 'left' ? 'row' : 'row-reverse')),
19
21
  loading: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n right: ", ";\n bottom: 0;\n left: ", ";\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 16px;\n height: 16px;\n\n color: ", ";\n\n background: ", ";\n border-radius: 50%;\n "])), placement === 'left' ? '-4px' : 'unset', placement === 'right' ? '-4px' : 'unset', token.colorBgLayout, token.colorPrimary),
20
22
  avatarContainer: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n position: relative;\n flex: none;\n width: ", "px;\n height: ", "px;\n "])), avatarSize, avatarSize),
21
23
  messageContainer: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n\n .ant-alert-with-description {\n padding-block: 12px;\n padding-inline: 12px;\n }\n "]))),
22
- name: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n margin-bottom: 6px;\n\n font-size: 12px;\n line-height: 1;\n color: ", ";\n text-align: ", ";\n "])), token.colorTextDescription, placement === 'left' ? 'left' : 'right'),
23
- message: cx(typeStylish, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: relative;\n "]))))
24
+ name: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n position: ", ";\n top: ", ";\n right: ", ";\n left: ", ";\n\n display: flex;\n flex-direction: ", ";\n gap: 4px;\n\n margin-bottom: 6px;\n\n font-size: 12px;\n line-height: 1;\n color: ", ";\n text-align: ", ";\n "])), showTitle ? 'relative' : 'absolute', showTitle ? 'unset' : '-16px', placement === 'right' ? '0' : 'unset', placement === 'left' ? '0' : 'unset', placement === 'left' ? 'row' : 'row-reverse', token.colorTextDescription, placement === 'left' ? 'left' : 'right'),
25
+ time: cx(stylish.blur, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: 4px 6px;\n\n line-height: 1;\n\n background: ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadius)),
26
+ message: cx(typeStylish, css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n position: relative;\n "]))))
24
27
  };
25
28
  });
@@ -1,11 +1,17 @@
1
1
  /// <reference types="react" />
2
- import { ChatMessage } from "../Chat";
2
+ import { ChatItemProps } from "../index";
3
3
  import type { DivProps } from "../types";
4
+ import { ChatMessage } from "../types/chatMessage";
4
5
  export interface ChatListProps extends DivProps {
5
6
  /**
6
7
  * @description Data of chat messages to be displayed
7
8
  */
8
9
  data: ChatMessage[];
10
+ /**
11
+ * @description Whether to show name of the chat item
12
+ * @default false
13
+ */
14
+ showTitle?: ChatItemProps['showTitle'];
9
15
  /**
10
16
  * @description Type of chat list
11
17
  * @default 'chat'
@@ -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 = ["className", "data", "type"];
3
+ var _excluded = ["className", "data", "type", "showTitle"];
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 { memo } from 'react';
@@ -12,6 +12,7 @@ var ChatList = /*#__PURE__*/memo(function (_ref) {
12
12
  data = _ref.data,
13
13
  _ref$type = _ref.type,
14
14
  type = _ref$type === void 0 ? 'chat' : _ref$type,
15
+ showTitle = _ref.showTitle,
15
16
  props = _objectWithoutProperties(_ref, _excluded);
16
17
  var _useStyles = useStyles(),
17
18
  cx = _useStyles.cx,
@@ -19,14 +20,17 @@ var ChatList = /*#__PURE__*/memo(function (_ref) {
19
20
  return /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
20
21
  className: cx(styles.container, className)
21
22
  }, props), {}, {
22
- children: data.map(function (item, index) {
23
+ children: data.map(function (item) {
23
24
  return /*#__PURE__*/_jsx(ChatItem, {
25
+ avatar: item.meta,
24
26
  borderSpacing: type === 'chat',
25
27
  message: item.content,
26
28
  placement: type === 'chat' ? item.role === 'user' ? 'right' : 'left' : 'left',
27
29
  primary: item.role === 'user',
30
+ showTitle: showTitle,
31
+ time: item.updateAt || item.createAt,
28
32
  type: type === 'chat' ? 'block' : 'pure'
29
- }, index);
33
+ }, item.id);
30
34
  })
31
35
  }));
32
36
  });
@@ -0,0 +1,33 @@
1
+ import { LLMRoleType } from './llm';
2
+ import { BaseDataModel } from './meta';
3
+ /**
4
+ * 聊天消息错误对象
5
+ */
6
+ export interface ChatMessageError {
7
+ /**
8
+ * 错误信息
9
+ */
10
+ message: string;
11
+ status: number;
12
+ type: 'general' | 'llm';
13
+ }
14
+ export interface ChatMessage extends BaseDataModel {
15
+ /**
16
+ * @title 内容
17
+ * @description 消息内容
18
+ */
19
+ content: string;
20
+ extra?: {
21
+ translate: {
22
+ target: string;
23
+ to: string;
24
+ };
25
+ } & Record<string, any>;
26
+ parentId?: string;
27
+ quotaId?: string;
28
+ /**
29
+ * 角色
30
+ * @description 消息发送者的角色
31
+ */
32
+ role: LLMRoleType;
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * LLM 模型
3
+ */
4
+ export declare enum LanguageModel {
5
+ /**
6
+ * GPT 3.5 Turbo
7
+ */
8
+ GPT3_5 = "gpt-3.5-turbo",
9
+ /**
10
+ * GPT 4
11
+ */
12
+ GPT4 = "gpt-4"
13
+ }
14
+ export interface LLMParams {
15
+ /**
16
+ * 控制生成文本中的惩罚系数,用于减少重复性
17
+ */
18
+ frequency_penalty?: number;
19
+ /**
20
+ * 生成文本的最大长度
21
+ */
22
+ max_tokens?: number;
23
+ /**
24
+ * 控制生成文本中的惩罚系数,用于减少主题的变化
25
+ */
26
+ presence_penalty?: number;
27
+ /**
28
+ * 生成文本的随机度量,用于控制文本的创造性和多样性
29
+ * @default 0.8
30
+ */
31
+ temperature: number;
32
+ /**
33
+ * 控制生成文本中最高概率的单个 token
34
+ */
35
+ top_p?: number;
36
+ }
37
+ export declare type LLMRoleType = 'user' | 'system' | 'assistant';
38
+ export interface LLMMessage {
39
+ content: string;
40
+ role: LLMRoleType;
41
+ }
42
+ export declare type LLMExample = LLMMessage[];
@@ -0,0 +1,10 @@
1
+ /**
2
+ * LLM 模型
3
+ */
4
+ export var LanguageModel;
5
+
6
+ // 语言模型的设置参数
7
+ (function (LanguageModel) {
8
+ LanguageModel["GPT3_5"] = "gpt-3.5-turbo";
9
+ LanguageModel["GPT4"] = "gpt-4";
10
+ })(LanguageModel || (LanguageModel = {}));
@@ -0,0 +1,25 @@
1
+ export interface MetaData {
2
+ /**
3
+ * 角色头像
4
+ * @description 可选参数,如果不传则使用默认头像
5
+ */
6
+ avatar?: string;
7
+ /**
8
+ * 背景色
9
+ * @description 可选参数,如果不传则使用默认背景色
10
+ */
11
+ backgroundColor?: string;
12
+ description?: string;
13
+ tag?: string[];
14
+ /**
15
+ * 名称
16
+ * @description 可选参数,如果不传则使用默认名称
17
+ */
18
+ title?: string;
19
+ }
20
+ export interface BaseDataModel {
21
+ createAt?: number;
22
+ id: string;
23
+ meta: MetaData;
24
+ updateAt?: number;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const formatTime: (time: number) => string;
@@ -0,0 +1,12 @@
1
+ import dayjs from 'dayjs';
2
+ export var formatTime = function formatTime(time) {
3
+ var now = dayjs();
4
+ var target = dayjs(time);
5
+ if (target.isSame(now, 'day')) {
6
+ return target.format('HH:mm');
7
+ } else if (target.isSame(now, 'year')) {
8
+ return target.format('MM-DD HH:mm');
9
+ } else {
10
+ return target.format('YYYY-MM-DD HH:mm');
11
+ }
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "description": "Lobe UI is an open-source UI component library for building chatbot web apps",
5
5
  "keywords": [
6
6
  "lobehub",