@ai-group/chat-sdk 3.7.4 → 3.7.5

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,5 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import React from 'react';
2
+ import React from "react";
3
3
  import Messages from "./Messages";
4
4
  import Sender from "./Sender";
5
5
 
@@ -28,20 +28,23 @@ var Chatbot = function Chatbot(_ref) {
28
28
  return /*#__PURE__*/_jsxs("div", {
29
29
  className: className,
30
30
  style: _objectSpread({
31
- display: 'flex',
32
- flexDirection: 'column',
33
- height: '100%',
34
- width: '100%'
31
+ display: "flex",
32
+ flexDirection: "column",
33
+ height: "100%",
34
+ minHeight: 0,
35
+ overflow: "hidden",
36
+ width: "100%"
35
37
  }, style),
36
38
  children: [/*#__PURE__*/_jsx("div", {
37
39
  style: {
38
40
  flex: 1,
39
- overflow: 'hidden'
41
+ minHeight: 0,
42
+ overflow: "hidden"
40
43
  },
41
44
  children: /*#__PURE__*/_jsx(Messages, _objectSpread({}, messagesProps))
42
45
  }), /*#__PURE__*/_jsx(Sender, _objectSpread({}, senderProps))]
43
46
  });
44
47
  };
45
- Chatbot.displayName = 'XAdkProvider.Chatbot';
48
+ Chatbot.displayName = "XAdkProvider.Chatbot";
46
49
  export default Chatbot;
47
50
  //# sourceMappingURL=Chatbot.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","Messages","Sender","jsx","_jsx","jsxs","_jsxs","Chatbot","_ref","messagesProps","senderProps","style","className","_objectSpread","display","flexDirection","height","width","children","flex","overflow","displayName"],"sources":["../../../../../src/components/XAdkProvider/compound/Chatbot.tsx"],"sourcesContent":["import React from 'react';\nimport Messages, { XAdkMessagesProps } from './Messages';\nimport Sender, { XAdkSenderCompoundProps } from './Sender';\n\n/**\n * XAdkProvider.Chatbot - 完整的聊天界面组件\n *\n * 组合了 Messages + Sender,提供开箱即用的完整聊天界面\n *\n * @example\n * ```tsx\n * <XAdkProvider url=\"...\" token=\"...\">\n * <XAdkProvider.Chatbot\n * messagesProps={{ showFnCallDetail: true }}\n * senderProps={{ allowUpload: true }}\n * />\n * </XAdkProvider>\n * ```\n */\nexport interface XAdkChatbotCompoundProps {\n /** Messages 组件的属性 */\n messagesProps?: XAdkMessagesProps;\n /** Sender 组件的属性 */\n senderProps?: XAdkSenderCompoundProps;\n /** 容器样式 */\n style?: React.CSSProperties;\n /** 容器类名 */\n className?: string;\n}\n\nconst Chatbot: React.FC<XAdkChatbotCompoundProps> = ({\n messagesProps,\n senderProps,\n style,\n className,\n}) => {\n return (\n <div\n className={className}\n style={{\n display: 'flex',\n flexDirection: 'column',\n height: '100%',\n width: '100%',\n ...style,\n }}\n >\n {/* 消息列表区域 */}\n <div style={{ flex: 1, overflow: 'hidden' }}>\n <Messages {...messagesProps} />\n </div>\n\n {/* 输入框区域 */}\n <Sender {...senderProps} />\n </div>\n );\n};\n\nChatbot.displayName = 'XAdkProvider.Chatbot';\n\nexport default Chatbot;\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,QAAQ;AACf,OAAOC,MAAM;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAdA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AA0BA,IAAMC,OAA2C,GAAG,SAA9CA,OAA2CA,CAAAC,IAAA,EAK3C;EAAA,IAJJC,aAAa,GAAAD,IAAA,CAAbC,aAAa;IACbC,WAAW,GAAAF,IAAA,CAAXE,WAAW;IACXC,KAAK,GAAAH,IAAA,CAALG,KAAK;IACLC,SAAS,GAAAJ,IAAA,CAATI,SAAS;EAET,oBACEN,KAAA;IACEM,SAAS,EAAEA,SAAU;IACrBD,KAAK,EAAAE,aAAA;MACHC,OAAO,EAAE,MAAM;MACfC,aAAa,EAAE,QAAQ;MACvBC,MAAM,EAAE,MAAM;MACdC,KAAK,EAAE;IAAM,GACVN,KAAK,CACR;IAAAO,QAAA,gBAGFd,IAAA;MAAKO,KAAK,EAAE;QAAEQ,IAAI,EAAE,CAAC;QAAEC,QAAQ,EAAE;MAAS,CAAE;MAAAF,QAAA,eAC1Cd,IAAA,CAACH,QAAQ,EAAAY,aAAA,KAAKJ,aAAa,CAAG;IAAC,CAC5B,CAAC,eAGNL,IAAA,CAACF,MAAM,EAAAW,aAAA,KAAKH,WAAW,CAAG,CAAC;EAAA,CACxB,CAAC;AAEV,CAAC;AAEDH,OAAO,CAACc,WAAW,GAAG,sBAAsB;AAE5C,eAAed,OAAO"}
1
+ {"version":3,"names":["React","Messages","Sender","jsx","_jsx","jsxs","_jsxs","Chatbot","_ref","messagesProps","senderProps","style","className","_objectSpread","display","flexDirection","height","minHeight","overflow","width","children","flex","displayName"],"sources":["../../../../../src/components/XAdkProvider/compound/Chatbot.tsx"],"sourcesContent":["import React from \"react\";\nimport Messages, { XAdkMessagesProps } from \"./Messages\";\nimport Sender, { XAdkSenderCompoundProps } from \"./Sender\";\n\n/**\n * XAdkProvider.Chatbot - 完整的聊天界面组件\n *\n * 组合了 Messages + Sender,提供开箱即用的完整聊天界面\n *\n * @example\n * ```tsx\n * <XAdkProvider url=\"...\" token=\"...\">\n * <XAdkProvider.Chatbot\n * messagesProps={{ showFnCallDetail: true }}\n * senderProps={{ allowUpload: true }}\n * />\n * </XAdkProvider>\n * ```\n */\nexport interface XAdkChatbotCompoundProps {\n /** Messages 组件的属性 */\n messagesProps?: XAdkMessagesProps;\n /** Sender 组件的属性 */\n senderProps?: XAdkSenderCompoundProps;\n /** 容器样式 */\n style?: React.CSSProperties;\n /** 容器类名 */\n className?: string;\n}\n\nconst Chatbot: React.FC<XAdkChatbotCompoundProps> = ({\n messagesProps,\n senderProps,\n style,\n className,\n}) => {\n return (\n <div\n className={className}\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n height: \"100%\",\n minHeight: 0,\n overflow: \"hidden\",\n width: \"100%\",\n ...style,\n }}\n >\n {/* 消息列表区域 */}\n <div style={{ flex: 1, minHeight: 0, overflow: \"hidden\" }}>\n <Messages {...messagesProps} />\n </div>\n\n {/* 输入框区域 */}\n <Sender {...senderProps} />\n </div>\n );\n};\n\nChatbot.displayName = \"XAdkProvider.Chatbot\";\n\nexport default Chatbot;\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,QAAQ;AACf,OAAOC,MAAM;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAdA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AA0BA,IAAMC,OAA2C,GAAG,SAA9CA,OAA2CA,CAAAC,IAAA,EAK3C;EAAA,IAJJC,aAAa,GAAAD,IAAA,CAAbC,aAAa;IACbC,WAAW,GAAAF,IAAA,CAAXE,WAAW;IACXC,KAAK,GAAAH,IAAA,CAALG,KAAK;IACLC,SAAS,GAAAJ,IAAA,CAATI,SAAS;EAET,oBACEN,KAAA;IACEM,SAAS,EAAEA,SAAU;IACrBD,KAAK,EAAAE,aAAA;MACHC,OAAO,EAAE,MAAM;MACfC,aAAa,EAAE,QAAQ;MACvBC,MAAM,EAAE,MAAM;MACdC,SAAS,EAAE,CAAC;MACZC,QAAQ,EAAE,QAAQ;MAClBC,KAAK,EAAE;IAAM,GACVR,KAAK,CACR;IAAAS,QAAA,gBAGFhB,IAAA;MAAKO,KAAK,EAAE;QAAEU,IAAI,EAAE,CAAC;QAAEJ,SAAS,EAAE,CAAC;QAAEC,QAAQ,EAAE;MAAS,CAAE;MAAAE,QAAA,eACxDhB,IAAA,CAACH,QAAQ,EAAAY,aAAA,KAAKJ,aAAa,CAAG;IAAC,CAC5B,CAAC,eAGNL,IAAA,CAACF,MAAM,EAAAW,aAAA,KAAKH,WAAW,CAAG,CAAC;EAAA,CACxB,CAAC;AAEV,CAAC;AAEDH,OAAO,CAACe,WAAW,GAAG,sBAAsB;AAE5C,eAAef,OAAO"}
@@ -1158,7 +1158,7 @@ function useADKChat(_ref2) {
1158
1158
  while (1) switch (_context4.prev = _context4.next) {
1159
1159
  case 0:
1160
1160
  if (!sessionId) {
1161
- _context4.next = 35;
1161
+ _context4.next = 39;
1162
1162
  break;
1163
1163
  }
1164
1164
  if (!(sessionId === currentSessionId)) {
@@ -1199,9 +1199,12 @@ function useADKChat(_ref2) {
1199
1199
  // 2. 尝试从后台恢复目标会话
1200
1200
  bg = backgroundRef.current.get(sessionId);
1201
1201
  if (!bg) {
1202
- _context4.next = 19;
1202
+ _context4.next = 21;
1203
1203
  break;
1204
1204
  }
1205
+ // 缓存会话属于历史上下文,不能沿用当前新会话的开场白和建议问题。
1206
+ setPrologue("");
1207
+ setSuggestedQuestions([]);
1205
1208
  setMessages(bg.messages);
1206
1209
  messagesRef.current = bg.messages;
1207
1210
  textMsgRef.current = bg.textMsgRef;
@@ -1214,20 +1217,23 @@ function useADKChat(_ref2) {
1214
1217
  setInitialized(true);
1215
1218
  backgroundRef.current.delete(sessionId);
1216
1219
  return _context4.abrupt("return");
1217
- case 19:
1220
+ case 21:
1218
1221
  // 3. 后台没有目标 session,走 API 加载(原有逻辑)
1219
1222
  setInitialized(false);
1220
1223
  setCurrentSessionId(sessionId);
1224
+ // 在详情返回前先退出 onboarding,避免多个 Provider/Tab 并发初始化时短暂回显开场白。
1225
+ setPrologue("");
1226
+ setSuggestedQuestions([]);
1221
1227
  sessionDetailLoadingRef.current = true;
1222
- _context4.prev = 22;
1223
- _context4.next = 25;
1228
+ _context4.prev = 26;
1229
+ _context4.next = 29;
1224
1230
  return fetchSessionDetail({
1225
1231
  url: url,
1226
1232
  appNo: appNo,
1227
1233
  sessionId: sessionId,
1228
1234
  token: tokenRef.current
1229
1235
  });
1230
- case 25:
1236
+ case 29:
1231
1237
  _yield$fetchSessionDe = _context4.sent;
1232
1238
  data = _yield$fetchSessionDe.data;
1233
1239
  result = _yield$fetchSessionDe.result;
@@ -1246,21 +1252,21 @@ function useADKChat(_ref2) {
1246
1252
  setSuggestedQuestions((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn4 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn4 === void 0 ? void 0 : _appInfo$onboardingIn4.suggested_questions) || []);
1247
1253
  }
1248
1254
  }
1249
- case 29:
1250
- _context4.prev = 29;
1255
+ case 33:
1256
+ _context4.prev = 33;
1251
1257
  sessionDetailLoadingRef.current = false;
1252
1258
  setInitialized(true);
1253
- return _context4.finish(29);
1254
- case 33:
1255
- _context4.next = 36;
1259
+ return _context4.finish(33);
1260
+ case 37:
1261
+ _context4.next = 40;
1256
1262
  break;
1257
- case 35:
1263
+ case 39:
1258
1264
  setCurrentSessionId(v4());
1259
- case 36:
1265
+ case 40:
1260
1266
  case "end":
1261
1267
  return _context4.stop();
1262
1268
  }
1263
- }, _callee4, null, [[22,, 29, 33]]);
1269
+ }, _callee4, null, [[26,, 33, 37]]);
1264
1270
  }));
1265
1271
  return function setCurrentSession(_x2) {
1266
1272
  return _ref7.apply(this, arguments);
@@ -1281,6 +1287,7 @@ function useADKChat(_ref2) {
1281
1287
  sessionId,
1282
1288
  _appInfo$onboardingIn5,
1283
1289
  _appInfo$onboardingIn6,
1290
+ canRestoreOnboarding,
1284
1291
  _args5 = arguments;
1285
1292
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1286
1293
  while (1) switch (_context5.prev = _context5.next) {
@@ -1323,8 +1330,11 @@ function useADKChat(_ref2) {
1323
1330
  if (showFirstSession) {
1324
1331
  setCurrentSession(sessionId);
1325
1332
  } else {
1326
- fetchDetail && setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn5 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn5 === void 0 ? void 0 : _appInfo$onboardingIn5.prologue) || "");
1327
- fetchDetail && setSuggestedQuestions((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn6 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn6 === void 0 ? void 0 : _appInfo$onboardingIn6.suggested_questions) || []);
1333
+ // 仅真正处于空白新会话时恢复 onboarding。历史详情或已有消息优先,
1334
+ // 防止较晚返回的会话列表请求把开场白写回有内容的会话。
1335
+ canRestoreOnboarding = fetchDetail && !sessionDetailLoadingRef.current && messagesRef.current.length === 0;
1336
+ canRestoreOnboarding && setPrologue((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn5 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn5 === void 0 ? void 0 : _appInfo$onboardingIn5.prologue) || "");
1337
+ canRestoreOnboarding && setSuggestedQuestions((appInfo === null || appInfo === void 0 || (_appInfo$onboardingIn6 = appInfo.onboardingInfo) === null || _appInfo$onboardingIn6 === void 0 ? void 0 : _appInfo$onboardingIn6.suggested_questions) || []);
1328
1338
  }
1329
1339
  // 成功回调
1330
1340
  if (!initialized) {