@myun/gimi-chat 0.6.7 → 0.6.9

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.
@@ -14,6 +14,10 @@ function getFaviconByUrl(url) {
14
14
  try {
15
15
  // 解析URL,获取域名部分
16
16
  var parsedUrl = new URL(url);
17
+ // 单独处理政府网站图标
18
+ if (parsedUrl.host.indexOf('gov.cn') !== -1) {
19
+ return GHIcon;
20
+ }
17
21
  // 拼接标准favicon路径
18
22
  var faviconUrl = "".concat(parsedUrl.protocol, "//").concat(parsedUrl.host, "/favicon.ico");
19
23
  return faviconUrl;
@@ -29,14 +33,6 @@ var IconComponent = function IconComponent(_ref) {
29
33
  var handleImageError = function handleImageError(e) {
30
34
  e.target.src = DEFAULT_ICON_URL;
31
35
  };
32
- // 单独处理政府网站图标
33
- if (iconUrl === 'https://www.gov.cn/favicon.ico') {
34
- return /*#__PURE__*/React.createElement("img", {
35
- className: styles.icon,
36
- src: GHIcon,
37
- alt: item.sitename
38
- });
39
- }
40
36
  return /*#__PURE__*/React.createElement("img", {
41
37
  className: styles.icon,
42
38
  src: iconUrl || DEFAULT_ICON_URL,
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import type { VirtuosoHandle, VirtuosoProps } from 'react-virtuoso';
3
+ import { IChatMessageItem } from '../interfaces/chatMessage';
4
+ export declare function useChatVirtuosoStickyEngine(messages: IChatMessageItem[], setMessages: React.Dispatch<React.SetStateAction<IChatMessageItem[]>>): {
5
+ virtuosoRef: import("react").RefObject<VirtuosoHandle>;
6
+ virtuosoProps: Partial<VirtuosoProps<IChatMessageItem, unknown>>;
7
+ prependMessages: (older: IChatMessageItem[]) => void;
8
+ startStreaming: () => void;
9
+ finishStreaming: () => void;
10
+ updateStreaming: (updater: (prev: IChatMessageItem[]) => IChatMessageItem[]) => void;
11
+ forceScrollToBottom: (smooth?: boolean) => void;
12
+ };
@@ -0,0 +1,121 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { useCallback, useMemo, useRef, useState } from 'react';
12
+ export function useChatVirtuosoStickyEngine(messages, setMessages) {
13
+ var virtuosoRef = useRef(null);
14
+
15
+ /**
16
+ * ==============================
17
+ * Anchor Index(解决 prepend)
18
+ * ==============================
19
+ */
20
+ var _useState = useState(100000),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ firstItemIndex = _useState2[0],
23
+ setFirstItemIndex = _useState2[1];
24
+
25
+ /**
26
+ * ==============================
27
+ * 🥇 Viewport Sticky Engine
28
+ * ==============================
29
+ */
30
+
31
+ var viewportStickyRef = useRef(true);
32
+ var atBottomStateChange = useCallback(function (isBottom) {
33
+ viewportStickyRef.current = isBottom;
34
+ }, []);
35
+
36
+ /**
37
+ * ==============================
38
+ * 🥈 Output Growth Engine
39
+ * ==============================
40
+ */
41
+
42
+ var outputGrowingRef = useRef(false);
43
+ var startStreaming = useCallback(function () {
44
+ outputGrowingRef.current = true;
45
+ }, []);
46
+ var finishStreaming = useCallback(function () {
47
+ outputGrowingRef.current = false;
48
+ }, []);
49
+
50
+ /**
51
+ * ⭐ 真正的 Sticky Bottom 决策器
52
+ */
53
+ var followOutput = useCallback(function () {
54
+ return viewportStickyRef.current && outputGrowingRef.current;
55
+ }, []);
56
+
57
+ /**
58
+ * ==============================
59
+ * prepend 历史(零跳动)
60
+ * ==============================
61
+ */
62
+ var prependMessages = useCallback(function (older) {
63
+ if (!older.length) return;
64
+ setMessages(function (prev) {
65
+ return [].concat(_toConsumableArray(older), _toConsumableArray(prev));
66
+ });
67
+ setFirstItemIndex(function (prev) {
68
+ return prev - older.length;
69
+ });
70
+ }, [setMessages]);
71
+
72
+ /**
73
+ * ==============================
74
+ * ⭐ Streaming Append(零 scroll 指令)
75
+ * ==============================
76
+ */
77
+ var updateStreaming = useCallback(function (updater) {
78
+ setMessages(function (prev) {
79
+ return updater(prev);
80
+ });
81
+ }, [setMessages]);
82
+
83
+ /**
84
+ * 强制滚到底
85
+ */
86
+ var forceScrollToBottom = useCallback(function () {
87
+ var _virtuosoRef$current;
88
+ var smooth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
89
+ (_virtuosoRef$current = virtuosoRef.current) === null || _virtuosoRef$current === void 0 || _virtuosoRef$current.scrollToIndex({
90
+ index: messages.length - 1,
91
+ align: 'end',
92
+ behavior: smooth ? 'smooth' : 'auto'
93
+ });
94
+ viewportStickyRef.current = true;
95
+ }, [messages.length]);
96
+
97
+ /**
98
+ * Virtuoso Props
99
+ */
100
+ var virtuosoProps = useMemo(function () {
101
+ return {
102
+ data: messages,
103
+ firstItemIndex: firstItemIndex,
104
+ atBottomStateChange: atBottomStateChange,
105
+ followOutput: followOutput,
106
+ increaseViewportBy: {
107
+ top: 600,
108
+ bottom: 1200
109
+ } // ⭐ 双层引擎必须大 buffer
110
+ };
111
+ }, [messages, firstItemIndex, atBottomStateChange, followOutput]);
112
+ return {
113
+ virtuosoRef: virtuosoRef,
114
+ virtuosoProps: virtuosoProps,
115
+ prependMessages: prependMessages,
116
+ startStreaming: startStreaming,
117
+ finishStreaming: finishStreaming,
118
+ updateStreaming: updateStreaming,
119
+ forceScrollToBottom: forceScrollToBottom
120
+ };
121
+ }
@@ -1211,6 +1211,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1211
1211
  } else if (chatItem.mcp && !chatItem.content && !chatItem.reasoningContent) {
1212
1212
  // mcp工具调用中,但没有end输出时,不能被终止
1213
1213
  setDisableSend(true);
1214
+ } else {
1215
+ setDisableSend(false);
1214
1216
  }
1215
1217
  } else {
1216
1218
  setDisableSend(false);