@myun/gimi-chat 0.9.79 → 0.9.80

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.
@@ -639,7 +639,7 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
639
639
  }, UploadFileTool, !props.hiddenDeepThink && (deepThinkDisabled ? /*#__PURE__*/React.createElement(Tooltip, {
640
640
  content: t('chatInput.deepThinkNotSupported')
641
641
  }, /*#__PURE__*/React.createElement("div", {
642
- className: classNames(styles.deepthink, _defineProperty(_defineProperty({}, styles.active, deepThinkActive), styles.disabled, deepThinkDisabled)),
642
+ className: classNames(styles.deepthink, _defineProperty({}, styles.disabled, deepThinkDisabled)),
643
643
  onClick: toggleDeepThink
644
644
  }, /*#__PURE__*/React.createElement(IconFontCom, {
645
645
  type: "icon-moxing",
@@ -17,6 +17,20 @@ import ChatContext from "../components/templates/chatContext";
17
17
 
18
18
  /** 深度思考配置(服务端按 agentId 维度返回) */
19
19
 
20
+ /**
21
+ * 是否展示「选中」态。
22
+ * 必须同时满足:该智能体支持深度思考(thinking === 1)且开关已开启(thinkingEnable === 1)。
23
+ * 只看 thinkingEnable 会在「不支持但历史开启过」时出现选中底色 + 禁用态并存的矛盾样式。
24
+ */
25
+ var isDeepThinkOn = function isDeepThinkOn(config) {
26
+ return (config === null || config === void 0 ? void 0 : config.thinking) === 1 && (config === null || config === void 0 ? void 0 : config.thinkingEnable) === 1;
27
+ };
28
+
29
+ /** 是否置灰禁用:该智能体不支持深度思考 */
30
+ var isDeepThinkDisabled = function isDeepThinkDisabled(config) {
31
+ return (config === null || config === void 0 ? void 0 : config.thinking) !== 1;
32
+ };
33
+
20
34
  /**
21
35
  * 深度思考配置缓存,key 为 agentId。
22
36
  *
@@ -78,12 +92,13 @@ var useDeepThinkConfig = function useDeepThinkConfig(_ref) {
78
92
  _useState2 = _slicedToArray(_useState, 2),
79
93
  deepThinkDisabled = _useState2[0],
80
94
  setDeepThinkDisabled = _useState2[1];
81
- // true: 已开启(高亮)
95
+ // true: 已选中(thinking === 1 且 thinkingEnable === 1,按钮显示高亮底色)
82
96
  var _useState3 = useState(false),
83
97
  _useState4 = _slicedToArray(_useState3, 2),
84
98
  deepThinkActive = _useState4[0],
85
99
  setDeepThinkActive = _useState4[1];
86
100
  useEffect(function () {
101
+ var _thinkingCache$get;
87
102
  var id = Number(agentId);
88
103
  var api = apiServiceRef.current;
89
104
  if (hidden || !agentId || !(api !== null && api !== void 0 && api.getThinkingEffective)) {
@@ -91,11 +106,16 @@ var useDeepThinkConfig = function useDeepThinkConfig(_ref) {
91
106
  setDeepThinkActive(false);
92
107
  return;
93
108
  }
109
+
110
+ // 先用缓存里的已知结果同步一次:切换 agentId 时不会残留上一个智能体的选中态
111
+ var cached = (_thinkingCache$get = thinkingCache.get(id)) === null || _thinkingCache$get === void 0 ? void 0 : _thinkingCache$get.result;
112
+ setDeepThinkDisabled(isDeepThinkDisabled(cached));
113
+ setDeepThinkActive(isDeepThinkOn(cached));
94
114
  var alive = true;
95
115
  loadThinkingConfig(api, id).then(function (result) {
96
116
  if (!alive) return;
97
- setDeepThinkDisabled(result.thinking !== 1);
98
- setDeepThinkActive(result.thinkingEnable === 1);
117
+ setDeepThinkDisabled(isDeepThinkDisabled(result));
118
+ setDeepThinkActive(isDeepThinkOn(result));
99
119
  }).catch(function (e) {
100
120
  if (!alive) return;
101
121
  console.error('[deepThink] getThinkingEffective error:', e);
@@ -109,13 +129,17 @@ var useDeepThinkConfig = function useDeepThinkConfig(_ref) {
109
129
 
110
130
  // 点击切换深度思考开关
111
131
  var toggleDeepThink = useCallback(function () {
132
+ var _thinkingCache$get2;
112
133
  if (deepThinkDisabled) return; // 置灰禁用时不可点击
113
134
  var id = Number(agentId);
114
135
  var api = apiServiceRef.current;
115
136
  if (!agentId || !(api !== null && api !== void 0 && api.saveThinkingEnable)) return;
116
137
  var nextActive = !deepThinkActive;
117
138
  var thinkingEnable = nextActive ? 1 : 0;
118
- setDeepThinkActive(nextActive); // 乐观更新
139
+ // 乐观更新同样遵守「thinking === 1 才可能选中」,避免配置未知时误亮底色
140
+ setDeepThinkActive(isDeepThinkOn(_objectSpread(_objectSpread({}, (_thinkingCache$get2 = thinkingCache.get(id)) === null || _thinkingCache$get2 === void 0 ? void 0 : _thinkingCache$get2.result), {}, {
141
+ thinkingEnable: thinkingEnable
142
+ })));
119
143
  api.saveThinkingEnable({
120
144
  agentId: id,
121
145
  thinkingEnable: thinkingEnable