@myun/gimi-chat 0.5.5 → 0.5.7

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.
@@ -8,4 +8,6 @@
8
8
  .aiLoading .text {
9
9
  margin-top: 4px;
10
10
  text-align: center;
11
+ font-size: 14px;
12
+ color: #1890ff;
11
13
  }
@@ -102,9 +102,12 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
102
102
  var _ref = apiService,
103
103
  createRoomId = _ref.createRoomId;
104
104
  React.useEffect(function () {
105
- var _props$defaultPrompt;
106
- if (!props.defaultPrompt) return;
107
- setHasContent(((_props$defaultPrompt = props.defaultPrompt) === null || _props$defaultPrompt === void 0 ? void 0 : _props$defaultPrompt.trim().length) > 0);
105
+ if (!props.defaultPrompt) {
106
+ setHasContent(false);
107
+ } else {
108
+ var _props$defaultPrompt;
109
+ setHasContent(((_props$defaultPrompt = props.defaultPrompt) === null || _props$defaultPrompt === void 0 ? void 0 : _props$defaultPrompt.trim().length) > 0);
110
+ }
108
111
  }, [props.defaultPrompt]);
109
112
  React.useImperativeHandle(ref, function () {
110
113
  return {
@@ -4,6 +4,7 @@
4
4
  top: 0;
5
5
  z-index: 10;
6
6
  height: 100%;
7
+ box-sizing: border-box;
7
8
  box-shadow: -1px 0 10px 0 rgb(233, 235, 242);
8
9
  width: 300px;
9
10
  display: flex;
@@ -54,6 +55,7 @@
54
55
  padding: 10px;
55
56
  border-left: 1px solid #EEEEEE;
56
57
  height: 100%;
58
+ box-sizing: border-box;
57
59
  box-shadow: -1px 0 10px 0 rgb(233, 235, 242);
58
60
  overflow: auto;
59
61
  z-index: 3;
@@ -1,4 +1,6 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
@@ -40,7 +42,13 @@ var MessageList = function MessageList(_ref) {
40
42
  onLikeCallback = _ref.onLikeCallback,
41
43
  onUnLikeCallback = _ref.onUnLikeCallback,
42
44
  onDownloadCallback = _ref.onDownloadCallback,
43
- reasoningTitle = _ref.reasoningTitle;
45
+ reasoningTitle = _ref.reasoningTitle,
46
+ _ref$hideUserMessage = _ref.hideUserMessage,
47
+ hideUserMessage = _ref$hideUserMessage === void 0 ? false : _ref$hideUserMessage,
48
+ _ref$messageLayout = _ref.messageLayout,
49
+ messageLayout = _ref$messageLayout === void 0 ? 'center' : _ref$messageLayout,
50
+ _ref$messageStyle = _ref.messageStyle,
51
+ messageStyle = _ref$messageStyle === void 0 ? {} : _ref$messageStyle;
44
52
  var _useGimiFileUpload = useGimiFileUpload(),
45
53
  handleSSEFileAnalyize = _useGimiFileUpload.handleSSEFileAnalyize,
46
54
  fileUpload = _useGimiFileUpload.fileUpload;
@@ -91,8 +99,19 @@ var MessageList = function MessageList(_ref) {
91
99
  var handleShowCourse = useCallback(function (v) {
92
100
  chatUI.showCourse(v.messageId ? v.messageId : v.chatId, v.videoResourceList);
93
101
  }, [chatUI]);
102
+ var buildStyle = function buildStyle() {
103
+ var style = {};
104
+ if (messageLayout === 'start') {
105
+ style.margin = 0;
106
+ } else if (messageLayout === 'end') {
107
+ style.margin = 0;
108
+ style.marginLeft = 'auto';
109
+ }
110
+ return _objectSpread(_objectSpread({}, style), messageStyle);
111
+ };
94
112
  return /*#__PURE__*/React.createElement("div", {
95
- className: classNames(styles.main)
113
+ className: classNames(styles.main),
114
+ style: buildStyle()
96
115
  }, /*#__PURE__*/React.createElement("div", {
97
116
  className: classNames(model === 'sidebar' ? styles.small_container : styles.container)
98
117
  }, chatList.length > 0 && /*#__PURE__*/React.createElement("div", {
@@ -110,7 +129,7 @@ var MessageList = function MessageList(_ref) {
110
129
  onMouseEnter: function onMouseEnter() {
111
130
  if (!v.loading) chatUI.setShowCopyId(v.id);
112
131
  }
113
- }, (v === null || v === void 0 ? void 0 : v.type) === 0 && /*#__PURE__*/React.createElement(React.Fragment, null, v.status !== 1 && /*#__PURE__*/React.createElement("div", {
132
+ }, (v === null || v === void 0 ? void 0 : v.type) === 0 && !hideUserMessage && /*#__PURE__*/React.createElement(React.Fragment, null, v.status !== 1 && /*#__PURE__*/React.createElement("div", {
114
133
  className: styles.qusetionOpera
115
134
  }, v.status === 0 && /*#__PURE__*/React.createElement(Spin, {
116
135
  size: "small"
@@ -22,6 +22,7 @@ import KnowledgeIconGroup from "../knowledge-trace/KnowledgeIconComponent";
22
22
  import { IconChevronUp, IconChevronDown } from '@douyinfe/semi-icons';
23
23
  import { useAppSelector, useAppDispatch } from "../../store/hooks";
24
24
  import { setMessageList } from "../../store/slices/gimiMenuSlice";
25
+ import ReasoningSearch from "../reasoning-search";
25
26
  var ReasoningContent = function ReasoningContent(_ref) {
26
27
  var reasoningTitle = _ref.reasoningTitle,
27
28
  item = _ref.item;
@@ -29,12 +30,53 @@ var ReasoningContent = function ReasoningContent(_ref) {
29
30
  var _useScroll = useScroll(containerRef),
30
31
  _useScroll2 = _slicedToArray(_useScroll, 1),
31
32
  throttledScrollToBottom = _useScroll2[0];
33
+ var _React$useState = React.useState({
34
+ isTop: true,
35
+ isBottom: true
36
+ }),
37
+ _React$useState2 = _slicedToArray(_React$useState, 2),
38
+ scrollState = _React$useState2[0],
39
+ setScrollState = _React$useState2[1];
32
40
  var messageList = useAppSelector(function (state) {
33
41
  return state.gimiMenu.messageList;
34
42
  });
35
43
  var messageListRef = useRef(messageList);
36
44
  messageListRef.current = messageList;
37
45
  var dispatch = useAppDispatch();
46
+ var handleScroll = useCallback(function () {
47
+ if (containerRef.current) {
48
+ var _containerRef$current = containerRef.current,
49
+ scrollTop = _containerRef$current.scrollTop,
50
+ scrollHeight = _containerRef$current.scrollHeight,
51
+ clientHeight = _containerRef$current.clientHeight;
52
+ var isTop = scrollTop <= 0;
53
+ var isBottom = scrollTop + clientHeight >= scrollHeight - 1; // 1px buffer for rounding
54
+ setScrollState({
55
+ isTop: isTop,
56
+ isBottom: isBottom
57
+ });
58
+ }
59
+ }, []);
60
+ useEffect(function () {
61
+ var container = containerRef.current;
62
+ if (container) {
63
+ container.addEventListener('scroll', handleScroll);
64
+ // Initial check
65
+ handleScroll();
66
+
67
+ // Re-check when content changes
68
+ var observer = new MutationObserver(handleScroll);
69
+ observer.observe(container, {
70
+ childList: true,
71
+ subtree: true,
72
+ characterData: true
73
+ });
74
+ return function () {
75
+ container.removeEventListener('scroll', handleScroll);
76
+ observer.disconnect();
77
+ };
78
+ }
79
+ }, [item.expand]);
38
80
  var updataChatList = React.useCallback(function (id, expand) {
39
81
  var _messageListRef$curre;
40
82
  var newMessageList = (_messageListRef$curre = messageListRef.current) === null || _messageListRef$curre === void 0 ? void 0 : _messageListRef$curre.map(function (item) {
@@ -79,7 +121,7 @@ var ReasoningContent = function ReasoningContent(_ref) {
79
121
  }, /*#__PURE__*/React.createElement("div", {
80
122
  className: styles.title
81
123
  }, reasoningTitle, renderStatusText()), item.expand ? /*#__PURE__*/React.createElement(IconChevronUp, null) : /*#__PURE__*/React.createElement(IconChevronDown, null)), item.expand ? /*#__PURE__*/React.createElement("div", {
82
- className: styles.deeping,
124
+ className: "".concat(styles.deeping, " ").concat(!scrollState.isTop ? styles.showTopMask : '', " ").concat(!scrollState.isBottom ? styles.showBottomMask : ''),
83
125
  ref: containerRef,
84
126
  style: item.reasoningStatus === 1 ? {
85
127
  maxHeight: 240
@@ -105,6 +147,9 @@ var ReasoningContent = function ReasoningContent(_ref) {
105
147
  customRender: [{
106
148
  type: 'knowledge',
107
149
  component: KnowledgeIconGroup
150
+ }, {
151
+ type: 'search',
152
+ component: ReasoningSearch
108
153
  }],
109
154
  showLoading: item.reasoningLoading
110
155
  }))), item.msgLoading && /*#__PURE__*/React.createElement("div", {
@@ -49,6 +49,18 @@
49
49
  margin-top: 8px;
50
50
  overflow-y: scroll;
51
51
  }
52
+ .container .deeping.showTopMask {
53
+ mask-image: linear-gradient(to bottom, transparent, black 32px);
54
+ -webkit-mask-image: linear-gradient(to bottom, transparent, black 32px);
55
+ }
56
+ .container .deeping.showBottomMask {
57
+ mask-image: linear-gradient(to top, transparent, black 32px);
58
+ -webkit-mask-image: linear-gradient(to top, transparent, black 32px);
59
+ }
60
+ .container .deeping.showTopMask.showBottomMask {
61
+ mask-image: linear-gradient(to bottom, transparent, black 32px, black calc(100% - 32px), transparent);
62
+ -webkit-mask-image: linear-gradient(to bottom, transparent, black 32px, black calc(100% - 32px), transparent);
63
+ }
52
64
  .container .deepThinkPack {
53
65
  width: 100%;
54
66
  position: relative;
@@ -1,4 +1,5 @@
1
+ import React from 'react';
1
2
  declare const ReasoningSearch: ({ value }: {
2
3
  value: any;
3
- }) => any;
4
+ }) => string | React.JSX.Element;
4
5
  export default ReasoningSearch;
@@ -1,16 +1,29 @@
1
1
  import styles from "./index.module.css";
2
2
  import React from 'react';
3
3
  import { IconSearchStroked, IconChevronRightStroked } from '@douyinfe/semi-icons';
4
+ import { useAppDispatch } from "../../store/hooks";
5
+ import { setShowSidebarReasoningSearch, setSidebarReasoningSearchList } from "../../store/slices/gimiMenuSlice";
4
6
  var ReasoningSearch = function ReasoningSearch(_ref) {
5
7
  var value = _ref.value;
8
+ var dispatch = useAppDispatch();
6
9
  var searchResult = {};
7
10
  try {
8
11
  searchResult = typeof value === 'string' ? JSON.parse(value) : value;
9
12
  } catch (error) {
10
13
  console.error(error);
11
- return searchResult;
14
+ return "".concat(searchResult);
12
15
  }
13
- var openSidebar = function openSidebar() {};
16
+ var openSidebar = function openSidebar() {
17
+ var list = (searchResult.results || []).map(function (item) {
18
+ return item['text_card'];
19
+ });
20
+ if (list.length > 0) {
21
+ dispatch(setShowSidebarReasoningSearch({
22
+ showSidebarReasoningSearch: true
23
+ }));
24
+ dispatch(setSidebarReasoningSearchList(list));
25
+ }
26
+ };
14
27
  return /*#__PURE__*/React.createElement("div", {
15
28
  className: styles.search_button,
16
29
  onClick: openSidebar
@@ -38,8 +38,9 @@
38
38
  display: flex;
39
39
  flex-direction: column;
40
40
  gap: 10px;
41
+ margin-top: 20px;
41
42
  width: 296px;
42
- height: 99px;
43
+ max-height: 99px;
43
44
  font-family: PingFang SC;
44
45
  font-weight: 400;
45
46
  font-style: Regular;
@@ -51,10 +52,22 @@
51
52
  .list .item .item_title {
52
53
  font-weight: 500;
53
54
  font-size: 14px;
55
+ font-style: Regular;
54
56
  color: rgb(46, 57, 76);
57
+ display: -webkit-box;
58
+ -webkit-box-orient: vertical;
59
+ -webkit-line-clamp: 2;
60
+ overflow: hidden;
61
+ text-overflow: ellipsis;
62
+ cursor: pointer;
55
63
  }
56
64
  .list .item .item_footer {
57
65
  display: flex;
58
66
  align-items: center;
59
67
  justify-content: space-between;
68
+ }
69
+ .list .item .item_footer .footer_left {
70
+ display: flex;
71
+ align-items: center;
72
+ gap: 5px;
60
73
  }
@@ -5,6 +5,23 @@ import { setShowSidebarReasoningSearch, setSidebarReasoningSearchList } from "..
5
5
  import ReactDOM from "react-dom";
6
6
  import styles from "./index.module.css";
7
7
  import { Badge } from '@douyinfe/semi-ui';
8
+ /**
9
+ * 根据URL获取网页favicon图标地址
10
+ * @param {string} url - 目标网页的URL(如https://www.baidu.com)
11
+ * @returns {string} favicon的完整URL
12
+ */
13
+ function getFaviconByUrl(url) {
14
+ try {
15
+ // 解析URL,获取域名部分
16
+ var parsedUrl = new URL(url);
17
+ // 拼接标准favicon路径
18
+ var faviconUrl = "".concat(parsedUrl.protocol, "//").concat(parsedUrl.host, "/favicon.ico");
19
+ return faviconUrl;
20
+ } catch (error) {
21
+ console.error('URL格式错误:', error);
22
+ return '';
23
+ }
24
+ }
8
25
  var ReasoningSearchSidebar = function ReasoningSearchSidebar(props) {
9
26
  var sidebarTargetElm = props.sidebarTargetElm,
10
27
  isOverFlow = props.isOverFlow,
@@ -27,27 +44,40 @@ var ReasoningSearchSidebar = function ReasoningSearchSidebar(props) {
27
44
  return /*#__PURE__*/React.createElement(GimiSideBar, {
28
45
  show: showSidebarReasoningSearch,
29
46
  isOverFlow: isOverFlow,
30
- title: "\u641C\u7D22\u6765\u6E90",
47
+ title: "\u641C\u7D22\u6765\u6E90 ".concat(sidebarReasoningSearchList.length),
31
48
  handleClose: handleClose,
32
49
  className: className,
33
50
  style: style
34
51
  }, /*#__PURE__*/React.createElement("div", {
35
52
  className: styles.list
36
53
  }, sidebarReasoningSearchList.map(function (item, index) {
54
+ var iconUrl = getFaviconByUrl(item.url);
37
55
  return /*#__PURE__*/React.createElement("div", {
38
56
  key: index,
39
57
  className: styles.item
40
58
  }, /*#__PURE__*/React.createElement("div", {
41
- className: styles.item_title
42
- }, item.title), /*#__PURE__*/React.createElement("div", {
43
- className: styles.item_description
59
+ className: styles.item_title,
60
+ onClick: function onClick() {
61
+ return window.open(item.url);
62
+ }
44
63
  }, item.title), /*#__PURE__*/React.createElement("div", {
45
64
  className: styles.item_footer
46
65
  }, /*#__PURE__*/React.createElement("div", {
47
66
  className: styles.footer_left
48
- }, item.sitename), /*#__PURE__*/React.createElement(Badge, {
49
- type: "tertiary"
50
- }, index + 1)));
67
+ }, iconUrl && /*#__PURE__*/React.createElement("img", {
68
+ style: {
69
+ width: '15px',
70
+ height: '15px'
71
+ },
72
+ src: iconUrl,
73
+ alt: item.sitename
74
+ }), item.sitename), /*#__PURE__*/React.createElement(Badge, {
75
+ style: {
76
+ background: 'rgba(233, 235, 242, 1)',
77
+ color: 'rgba(154, 167, 183, 1)'
78
+ },
79
+ count: index + 1
80
+ })));
51
81
  })));
52
82
  };
53
83
  if (isOverFlow) {
@@ -15,6 +15,7 @@ import { IconChevronDown } from '@douyinfe/semi-icons';
15
15
  import KonwledgeTrace from "../knowledge-trace";
16
16
  import FileCardSideBar from "../file-card/fileCardSidebar";
17
17
  import OfficeFilePreviewPanel from "../file-preview";
18
+ import ReasoningSearchSidebar from "../reasoning-search/sidebar";
18
19
  import AiLoading from "../ai-loading";
19
20
  var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
20
21
  var _props$showInput = props.showInput,
@@ -246,6 +247,8 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
246
247
  isOverFlow: model === 'fullscreen' ? false : true
247
248
  })), /*#__PURE__*/React.createElement(FileCardSideBar, _extends({}, props.sidebarConfig, {
248
249
  isOverFlow: model === 'fullscreen' ? false : true
249
- })), /*#__PURE__*/React.createElement(OfficeFilePreviewPanel, null));
250
+ })), /*#__PURE__*/React.createElement(OfficeFilePreviewPanel, null), /*#__PURE__*/React.createElement(ReasoningSearchSidebar, _extends({}, props.sidebarConfig, {
251
+ isOverFlow: model === 'fullscreen' ? false : true
252
+ })));
250
253
  });
251
254
  export default CommonChat;
@@ -1058,9 +1058,15 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1058
1058
  React.useEffect(function () {
1059
1059
  if (initSendValue && initSendValueRef.current !== initSendValue && agentObj !== null && agentObj !== void 0 && agentObj.agentId) {
1060
1060
  initSendValueRef.current = initSendValue;
1061
+ dispatch(setMessageList({
1062
+ messageList: []
1063
+ }));
1064
+ dispatch(setConversationId({
1065
+ conversationId: null
1066
+ }));
1061
1067
  startConversationAndChat(initSendValue);
1062
1068
  }
1063
- }, [initSendValue, startConversationAndChat, agentObj === null || agentObj === void 0 ? void 0 : agentObj.agentId]);
1069
+ }, [initSendValue, startConversationAndChat, agentObj === null || agentObj === void 0 ? void 0 : agentObj.agentId, dispatch]);
1064
1070
  React.useEffect(function () {
1065
1071
  if (resetKey && resetKey !== resetKeyRef.current) {
1066
1072
  var _controllerRef$curren, _streamEsAbortRef$cur;
@@ -158,6 +158,9 @@ export interface MessageConfig {
158
158
  enableRegenerate?: boolean;
159
159
  enableVoicePlay?: boolean;
160
160
  reasoningTitle?: string;
161
+ hideUserMessage?: boolean;
162
+ messageLayout?: 'start' | 'center' | 'end';
163
+ messageStyle?: React.CSSProperties;
161
164
  }
162
165
 
163
166
  export interface IChatMessageItem {