@myun/gimi-chat 0.3.3 → 0.3.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.
@@ -50,7 +50,6 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
50
50
  createRoomId = _useApi.createRoomId,
51
51
  getAgentDetail = _useApi.getAgentDetail,
52
52
  deleteConversationById = _useApi.deleteConversationById,
53
- getAiCorrection = _useApi.getAiCorrection,
54
53
  checkRetry = _useApi.checkRetry;
55
54
  var _ref = props.chatInputConfig || {},
56
55
  onFirstSendSuccess = _ref.onFirstSendSuccess,
@@ -148,6 +147,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
148
147
  var historyListRef = useRef(historyList || []);
149
148
  var baseUrlRef = useRef(baseUrl || '');
150
149
  var tokenRef = useRef(token || '');
150
+ var initAttachmentsRef = useRef(initAttachments || []);
151
151
  // 重置key ref
152
152
  var resetKeyRef = useRef(resetKey || '');
153
153
  // 中断key ref
@@ -167,6 +167,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
167
167
  historyListRef.current = historyList;
168
168
  baseUrlRef.current = baseUrl;
169
169
  tokenRef.current = token;
170
+ initAttachmentsRef.current = initAttachments || [];
170
171
 
171
172
  // 错误处理ref(将在startChat和streamChat定义后初始化useChatError)
172
173
  var errRef = React.useRef({
@@ -194,61 +195,22 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
194
195
  }
195
196
  }));
196
197
  }, [dispatch]);
197
- var startAICorrection = React.useCallback( /*#__PURE__*/function () {
198
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(answerId, questionId) {
199
- var res, _res$result, _res$result2, message, aiChat;
200
- return _regeneratorRuntime().wrap(function _callee$(_context) {
201
- while (1) switch (_context.prev = _context.next) {
202
- case 0:
203
- _context.next = 2;
204
- return getAiCorrection({
205
- answerId: answerId,
206
- questionId: questionId
207
- });
208
- case 2:
209
- res = _context.sent;
210
- if (res.status === 0) {
211
- message = createUserChat((_res$result = res.result) === null || _res$result === void 0 ? void 0 : _res$result.title, '');
212
- aiChat = createAiChat({});
213
- dispatch(setMessageList({
214
- messageList: [message, aiChat]
215
- }));
216
- dispatch(setAgentDetail({
217
- agentDetail: {
218
- botId: (_res$result2 = res.result) === null || _res$result2 === void 0 ? void 0 : _res$result2.botId
219
- }
220
- }));
221
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
222
- streamAICorrectionChat();
223
- } else {
224
- Toast.error(res.message || '获取AI批改信息失败');
225
- }
226
- case 4:
227
- case "end":
228
- return _context.stop();
229
- }
230
- }, _callee);
231
- }));
232
- return function (_x, _x2) {
233
- return _ref2.apply(this, arguments);
234
- };
235
- }(), [getAiCorrection]);
236
- var deleteConversation = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
198
+ var deleteConversation = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
237
199
  var res;
238
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
239
- while (1) switch (_context2.prev = _context2.next) {
200
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
201
+ while (1) switch (_context.prev = _context.next) {
240
202
  case 0:
241
203
  if (conversationIdRef.current) {
242
- _context2.next = 3;
204
+ _context.next = 3;
243
205
  break;
244
206
  }
245
207
  Toast.error('会话ID不存在');
246
- return _context2.abrupt("return");
208
+ return _context.abrupt("return");
247
209
  case 3:
248
- _context2.next = 5;
210
+ _context.next = 5;
249
211
  return deleteConversationById(conversationIdRef.current);
250
212
  case 5:
251
- res = _context2.sent;
213
+ res = _context.sent;
252
214
  if (res.status === 0) {
253
215
  Toast.success('删除会话成功');
254
216
  // 清空Redux状态
@@ -261,100 +223,95 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
261
223
  }
262
224
  case 7:
263
225
  case "end":
264
- return _context2.stop();
226
+ return _context.stop();
265
227
  }
266
- }, _callee2);
228
+ }, _callee);
267
229
  })), [dispatch]);
268
230
 
269
231
  // 打断ai输出
270
- var handleInterrupt = /*#__PURE__*/function () {
271
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
272
- var uid, messageList, _item, newMessageList, _newMessageList;
273
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
274
- while (1) switch (_context3.prev = _context3.next) {
275
- case 0:
276
- uid = 'msg_' + Date.now();
277
- if (navigator.onLine) {
278
- _context3.next = 4;
279
- break;
280
- }
281
- Toast.error('无法连接到网络');
282
- return _context3.abrupt("return");
283
- case 4:
284
- if (streamEsAbortRef.current) {
285
- _context3.next = 7;
286
- break;
287
- }
288
- Toast.error('没有可取消的请求');
289
- return _context3.abrupt("return");
290
- case 7:
291
- streamEsAbortRef.current.abort();
292
- streamEsAbortRef.current = null;
293
- messageList = messageListRef.current;
294
- if (step.current === 1) {
295
- _item = {
296
- role: 1,
297
- type: 1,
298
- content: '',
299
- id: uid,
300
- messageId: uid,
301
- videoResourceList: [],
302
- relatedCourseRecommendation: [],
303
- loading: false,
304
- reasoningLoading: false,
305
- msgLoading: false,
306
- reasoningStatus: 3,
307
- expand: false,
308
- // 是否展开
309
- reasoningContent: '',
310
- // 推理内容
311
- stop: 1
312
- };
313
- if (messageList[messageList.length - 1].vipLevel === 1) {
314
- newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), _item), {}, {
315
- reasoningStatus: messageList[messageList.length - 1].content ? 2 : 3
316
- })]);
317
- dispatch(setMessageList({
318
- messageList: newMessageList
319
- }));
320
- }
321
- } else {
322
- _newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
323
- loading: false,
324
- reasoningLoading: false,
325
- stop: 1,
326
- reasoningStatus: messageList[messageList.length - 1].content ? 2 : 3,
327
- msgLoading: false,
328
- relatedResourceList: [],
329
- mcp: null
232
+ var handleInterrupt = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
233
+ var uid, messageList, _item, newMessageList, _newMessageList;
234
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
235
+ while (1) switch (_context2.prev = _context2.next) {
236
+ case 0:
237
+ uid = 'msg_' + Date.now();
238
+ if (navigator.onLine) {
239
+ _context2.next = 4;
240
+ break;
241
+ }
242
+ Toast.error('无法连接到网络');
243
+ return _context2.abrupt("return");
244
+ case 4:
245
+ if (streamEsAbortRef.current) {
246
+ _context2.next = 7;
247
+ break;
248
+ }
249
+ Toast.error('没有可取消的请求');
250
+ return _context2.abrupt("return");
251
+ case 7:
252
+ streamEsAbortRef.current.abort();
253
+ streamEsAbortRef.current = null;
254
+ messageList = messageListRef.current;
255
+ if (step.current === 1) {
256
+ _item = {
257
+ role: 1,
258
+ type: 1,
259
+ content: '',
260
+ id: uid,
261
+ messageId: uid,
262
+ videoResourceList: [],
263
+ relatedCourseRecommendation: [],
264
+ loading: false,
265
+ reasoningLoading: false,
266
+ msgLoading: false,
267
+ reasoningStatus: 3,
268
+ expand: false,
269
+ // 是否展开
270
+ reasoningContent: '',
271
+ // 推理内容
272
+ stop: 1
273
+ };
274
+ if (messageList[messageList.length - 1].vipLevel === 1) {
275
+ newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), _item), {}, {
276
+ reasoningStatus: messageList[messageList.length - 1].content ? 2 : 3
330
277
  })]);
331
278
  dispatch(setMessageList({
332
- messageList: _newMessageList
279
+ messageList: newMessageList
333
280
  }));
334
281
  }
335
- stopStreamOut({
336
- messageId: "".concat(messageList[messageList.length - 1].chatId)
337
- });
338
- setIgnoreOnMessage(true);
339
- removeLastEventId("".concat(messageList[messageList.length - 1].chatId));
340
- if (valueRef.current) {
341
- setStatus(1);
342
- } else {
343
- setStatus(0);
344
- }
345
- setMsgLoading(false);
346
- step.current = 0; // 重置步骤状态
347
- onSendEnd === null || onSendEnd === void 0 || onSendEnd(messageList[messageList.length - 1]);
348
- case 18:
349
- case "end":
350
- return _context3.stop();
351
- }
352
- }, _callee3);
353
- }));
354
- return function handleInterrupt() {
355
- return _ref4.apply(this, arguments);
356
- };
357
- }();
282
+ } else {
283
+ _newMessageList = [].concat(_toConsumableArray(messageList.slice(0, -1)), [_objectSpread(_objectSpread({}, messageList[messageList.length - 1]), {}, {
284
+ loading: false,
285
+ reasoningLoading: false,
286
+ stop: 1,
287
+ reasoningStatus: messageList[messageList.length - 1].content ? 2 : 3,
288
+ msgLoading: false,
289
+ relatedResourceList: [],
290
+ mcp: null
291
+ })]);
292
+ dispatch(setMessageList({
293
+ messageList: _newMessageList
294
+ }));
295
+ }
296
+ stopStreamOut({
297
+ messageId: "".concat(messageList[messageList.length - 1].chatId)
298
+ });
299
+ setIgnoreOnMessage(true);
300
+ removeLastEventId("".concat(messageList[messageList.length - 1].chatId));
301
+ if (valueRef.current) {
302
+ setStatus(1);
303
+ } else {
304
+ setStatus(0);
305
+ }
306
+ setMsgLoading(false);
307
+ step.current = 0; // 重置步骤状态
308
+ onSendEnd === null || onSendEnd === void 0 || onSendEnd(messageList[messageList.length - 1]);
309
+ case 18:
310
+ case "end":
311
+ return _context2.stop();
312
+ }
313
+ }, _callee2);
314
+ })), [dispatch, onSendEnd]);
358
315
  var handleMCPToolsStreamRs = React.useCallback(function (dataObj) {
359
316
  setStatus(2);
360
317
  var messageList = messageListRef.current;
@@ -372,75 +329,20 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
372
329
  }));
373
330
  }, [dispatch]);
374
331
 
375
- // 发起会话 - 使用新的hook简化逻辑
376
- var fetchAICorrectionChatStream = React.useCallback( /*#__PURE__*/function () {
377
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
378
- var fullResponse, reasoningResponse;
379
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
380
- while (1) switch (_context4.prev = _context4.next) {
381
- case 0:
382
- setIgnoreOnMessage(false);
383
- fullResponse = '';
384
- reasoningResponse = '';
385
- _context4.next = 5;
386
- return fetchChatStreamHook('', {}, {
387
- onSseOpen: function onSseOpen(response) {
388
- _onSseOpen(response);
389
- },
390
- onDataReceived: function onDataReceived(response, type) {
391
- setMsgLoading(false);
392
- if (type === 'content') {
393
- fullResponse = response;
394
- moduleInfoRef.current = null;
395
- } else if (type === 'reasoningContent') {
396
- reasoningResponse = response;
397
- vipLevelRef.current = 1;
398
- }
399
- _onDataReceived(response, type);
400
- },
401
- onComplete: function onComplete(response, type) {
402
- if (type === 'end' || type === 'COMPLETED') {
403
- if (platform === 'correction') {
404
- fullResponse = "<correction>".concat(fullResponse, "</correction>");
405
- }
406
- _onComplete(fullResponse, type, reasoningResponse);
407
- } else {
408
- moduleInfoRef.current = response;
409
- _onComplete(response, type);
410
- }
411
- },
412
- onErrorComplete: function onErrorComplete() {
413
- _onErrorComplete();
414
- },
415
- onMCPToolsStream: function onMCPToolsStream(dataObj) {
416
- handleMCPToolsStreamRs(dataObj);
417
- }
418
- }, 'POST', '/mbot/web/bot/chat/workflow');
419
- case 5:
420
- case "end":
421
- return _context4.stop();
422
- }
423
- }, _callee4);
424
- }));
425
- return function (_x3, _x4, _x5, _x6) {
426
- return _ref5.apply(this, arguments);
427
- };
428
- }(), [fetchChatStreamHook, setIgnoreOnMessage, dispatch, removeLastEventId, handleMCPToolsStreamRs]);
429
-
430
332
  // 发起会话 - 使用新的hook简化逻辑
431
333
  var fetchChatStream = React.useCallback( /*#__PURE__*/function () {
432
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id, reSumeInfo, _onSseOpen2, _onDataReceived2, _onComplete2, _onErrorComplete2) {
334
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(id, reSumeInfo, _onSseOpen, _onDataReceived, _onComplete, _onErrorComplete) {
433
335
  var fullResponse, reasoningResponse;
434
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
435
- while (1) switch (_context5.prev = _context5.next) {
336
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
337
+ while (1) switch (_context3.prev = _context3.next) {
436
338
  case 0:
437
339
  setIgnoreOnMessage(false);
438
340
  fullResponse = Object.keys(reSumeInfo).length > 0 ? reSumeInfo.content : '';
439
341
  reasoningResponse = Object.keys(reSumeInfo).length > 0 ? reSumeInfo.reasoningContent : '';
440
- _context5.next = 5;
342
+ _context3.next = 5;
441
343
  return fetchChatStreamHook(id, reSumeInfo, {
442
344
  onSseOpen: function onSseOpen(response) {
443
- _onSseOpen2(response);
345
+ _onSseOpen(response);
444
346
  // if (historyListRef.current.findIndex((item: any) => item.id === conversationIdRef.current) !== 0) {
445
347
  // dispatch(getChatHistoryList({ pageIndex: 1, pageSize: 50, loadMore: false }));
446
348
  // }
@@ -454,19 +356,19 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
454
356
  reasoningResponse = response;
455
357
  vipLevelRef.current = 1;
456
358
  }
457
- _onDataReceived2(response, type);
359
+ _onDataReceived(response, type);
458
360
  },
459
361
  onComplete: function onComplete(response, type) {
460
362
  if (type === 'end' || type === 'COMPLETED') {
461
363
  removeLastEventId(id);
462
- _onComplete2(fullResponse, type, reasoningResponse);
364
+ _onComplete(fullResponse, type, reasoningResponse);
463
365
  } else {
464
366
  moduleInfoRef.current = response;
465
- _onComplete2(response, type);
367
+ _onComplete(response, type);
466
368
  }
467
369
  },
468
370
  onErrorComplete: function onErrorComplete() {
469
- _onErrorComplete2();
371
+ _onErrorComplete();
470
372
  },
471
373
  onMCPToolsStream: function onMCPToolsStream(dataObj) {
472
374
  handleMCPToolsStreamRs(dataObj);
@@ -474,111 +376,28 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
474
376
  });
475
377
  case 5:
476
378
  case "end":
477
- return _context5.stop();
379
+ return _context3.stop();
478
380
  }
479
- }, _callee5);
381
+ }, _callee3);
480
382
  }));
481
- return function (_x7, _x8, _x9, _x10, _x11, _x12) {
482
- return _ref6.apply(this, arguments);
383
+ return function (_x, _x2, _x3, _x4, _x5, _x6) {
384
+ return _ref4.apply(this, arguments);
483
385
  };
484
- }(), [fetchChatStreamHook, setIgnoreOnMessage, dispatch, removeLastEventId, handleMCPToolsStreamRs]);
485
-
486
- // AI批改流式输出开始
487
- var streamAICorrectionChat = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
488
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
489
- while (1) switch (_context7.prev = _context7.next) {
490
- case 0:
491
- step.current = 2;
492
- _context7.next = 3;
493
- return fetchAICorrectionChatStream(function () {
494
- setStatus(1);
495
- var currentMessageList = messageListRef.current;
496
- var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
497
- loading: false,
498
- reasoningLoading: false,
499
- stop: 0
500
- })]);
501
- dispatch(setMessageList({
502
- messageList: newMessageList
503
- }));
504
- }, function (response, type) {
505
- // if (isSystemAuto) return;
506
- setStatus(2);
507
- var currentMessageList = messageListRef.current;
508
- var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, type, response || ''), "loading", true), "msgLoading", false), "vipLevel", vipLevelRef.current), "reasoningLoading", type === 'content' ? false : true), "reasoningStatus", type === 'content' ? 2 : 1), "moduleInfo", null), "moduleType", 'end'), "mcp", null))]);
509
- dispatch(setMessageList({
510
- messageList: newMessageList
511
- }));
512
- }, /*#__PURE__*/function () {
513
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(Response, type, reasoningResponse) {
514
- var currentMessageList, newMessageList;
515
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
516
- while (1) switch (_context6.prev = _context6.next) {
517
- case 0:
518
- // if (isSystemAuto) return;
519
- setIgnoreOnMessage(true);
520
- currentMessageList = messageListRef.current;
521
- newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
522
- moduleType: type
523
- }, type === 'end' ? 'content' : 'moduleInfo', Response), "reasoningResponse", type === 'end' ? reasoningResponse : ''), "loading", false), "reasoningLoading", false), "mcp", null))]);
524
- dispatch(setMessageList({
525
- messageList: newMessageList
526
- }));
527
- if (type === 'ask' || type === 'skill') {
528
- scrollBottomForce();
529
- }
530
- setStatus(1);
531
- setMsgLoading(false);
532
- case 7:
533
- case "end":
534
- return _context6.stop();
535
- }
536
- }, _callee6);
537
- }));
538
- return function (_x13, _x14, _x15) {
539
- return _ref8.apply(this, arguments);
540
- };
541
- }(), function () {
542
- setIgnoreOnMessage(true);
543
- var currentMessageList = messageListRef.current;
544
- var newMessageList = [].concat(_toConsumableArray(currentMessageList.slice(0, -1)), [_objectSpread(_objectSpread({}, currentMessageList[currentMessageList.length - 1]), {}, {
545
- loading: false,
546
- reasoningLoading: false,
547
- stop: 0,
548
- reasoningStatus: 3,
549
- msgLoading: false,
550
- mcp: null
551
- })]);
552
- dispatch(setMessageList({
553
- messageList: newMessageList
554
- }));
555
- if (valueRef.current) {
556
- setStatus(1);
557
- } else {
558
- setStatus(0);
559
- }
560
- setMsgLoading(false);
561
- });
562
- case 3:
563
- case "end":
564
- return _context7.stop();
565
- }
566
- }, _callee7);
567
- })), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList]);
386
+ }(), [fetchChatStreamHook, setIgnoreOnMessage, removeLastEventId, handleMCPToolsStreamRs]);
568
387
 
569
388
  // 流式输出开始
570
389
  var streamChat = React.useCallback( /*#__PURE__*/function () {
571
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(lastId, again) {
390
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lastId, again) {
572
391
  var reSumeInfo,
573
392
  agentInfo,
574
- _args9 = arguments;
575
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
576
- while (1) switch (_context9.prev = _context9.next) {
393
+ _args5 = arguments;
394
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
395
+ while (1) switch (_context5.prev = _context5.next) {
577
396
  case 0:
578
- reSumeInfo = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
579
- agentInfo = _args9.length > 3 ? _args9[3] : undefined;
397
+ reSumeInfo = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {};
398
+ agentInfo = _args5.length > 3 ? _args5[3] : undefined;
580
399
  step.current = 2;
581
- _context9.next = 5;
400
+ _context5.next = 5;
582
401
  return fetchChatStream(lastId, reSumeInfo, function () {
583
402
  if (!again) {
584
403
  errRef.current = {
@@ -610,10 +429,10 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
610
429
  messageList: newMessageList
611
430
  }));
612
431
  }, /*#__PURE__*/function () {
613
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(Response, type, reasoningResponse) {
432
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(Response, type, reasoningResponse) {
614
433
  var currentMessageList, newMessageList, agentDetail;
615
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
616
- while (1) switch (_context8.prev = _context8.next) {
434
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
435
+ while (1) switch (_context4.prev = _context4.next) {
617
436
  case 0:
618
437
  // if (isSystemAuto) return;
619
438
  setIgnoreOnMessage(true);
@@ -632,10 +451,10 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
632
451
  // 获取最新的agent详情,防止redux异步更新
633
452
  agentDetail = agentInfo || agentObjRef.current;
634
453
  if (!((agentDetail === null || agentDetail === void 0 ? void 0 : agentDetail.isEnableRelated) === 1 && (type === 'end' || type === 'COMPLETED'))) {
635
- _context8.next = 10;
454
+ _context4.next = 10;
636
455
  break;
637
456
  }
638
- _context8.next = 10;
457
+ _context4.next = 10;
639
458
  return getRecommendList(newMessageList, lastId, statusRef.current);
640
459
  case 10:
641
460
  if (valueRef.current) {
@@ -647,12 +466,12 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
647
466
  onSendEnd === null || onSendEnd === void 0 || onSendEnd(newMessageList[newMessageList.length - 1]);
648
467
  case 13:
649
468
  case "end":
650
- return _context8.stop();
469
+ return _context4.stop();
651
470
  }
652
- }, _callee8);
471
+ }, _callee4);
653
472
  }));
654
- return function (_x18, _x19, _x20) {
655
- return _ref10.apply(this, arguments);
473
+ return function (_x9, _x10, _x11) {
474
+ return _ref6.apply(this, arguments);
656
475
  };
657
476
  }(), function () {
658
477
  setIgnoreOnMessage(true);
@@ -678,26 +497,26 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
678
497
  });
679
498
  case 5:
680
499
  case "end":
681
- return _context9.stop();
500
+ return _context5.stop();
682
501
  }
683
- }, _callee9);
502
+ }, _callee5);
684
503
  }));
685
- return function (_x16, _x17) {
686
- return _ref9.apply(this, arguments);
504
+ return function (_x7, _x8) {
505
+ return _ref5.apply(this, arguments);
687
506
  };
688
- }(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList]);
689
- var regenerate = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
507
+ }(), [fetchChatStream, dispatch, setIgnoreOnMessage, scrollBottomForce, getRecommendList, onSendEnd]);
508
+ var regenerate = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
690
509
  var res, retryId, newMessageList;
691
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
692
- while (1) switch (_context10.prev = _context10.next) {
510
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
511
+ while (1) switch (_context6.prev = _context6.next) {
693
512
  case 0:
694
- _context10.prev = 0;
695
- _context10.next = 3;
513
+ _context6.prev = 0;
514
+ _context6.next = 3;
696
515
  return checkRetry({
697
516
  conversationId: conversationIdRef.current
698
517
  });
699
518
  case 3:
700
- res = _context10.sent;
519
+ res = _context6.sent;
701
520
  if (res.status === 0 && res.result) {
702
521
  retryId = res.result;
703
522
  newMessageList = [].concat(_toConsumableArray(messageListRef.current.slice(0, -1)), [_objectSpread(_objectSpread({}, messageListRef.current[messageListRef.current.length - 1]), {}, {
@@ -718,25 +537,25 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
718
537
  } else {
719
538
  Toast.error(res.message || '当前消息不可进行重试');
720
539
  }
721
- _context10.next = 10;
540
+ _context6.next = 10;
722
541
  break;
723
542
  case 7:
724
- _context10.prev = 7;
725
- _context10.t0 = _context10["catch"](0);
543
+ _context6.prev = 7;
544
+ _context6.t0 = _context6["catch"](0);
726
545
  Toast.error('重试失败');
727
546
  case 10:
728
547
  case "end":
729
- return _context10.stop();
548
+ return _context6.stop();
730
549
  }
731
- }, _callee10, null, [[0, 7]]);
550
+ }, _callee6, null, [[0, 7]]);
732
551
  })), [streamChat]);
733
552
 
734
553
  // 单独的断点续传
735
554
  var checkUnfinishedMessage = React.useCallback( /*#__PURE__*/function () {
736
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(chatList) {
555
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(chatList) {
737
556
  var lastMessage, newMessageList, _agentObjRef$current, lastUserRequestMessage;
738
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
739
- while (1) switch (_context11.prev = _context11.next) {
557
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
558
+ while (1) switch (_context7.prev = _context7.next) {
740
559
  case 0:
741
560
  lastMessage = chatList[chatList.length - 1]; // 检查最后一条消息是否为未完成的AI消息
742
561
  if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 0 && lastMessage.chatId) {
@@ -754,7 +573,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
754
573
  }, agentObjRef.current); // 调用续传接口
755
574
  }
756
575
  if (!((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.type) === 1 && lastMessage.isCompleteOut === 1)) {
757
- _context11.next = 8;
576
+ _context7.next = 8;
758
577
  break;
759
578
  }
760
579
  removeLastEventId("".concat(lastMessage.chatId));
@@ -763,19 +582,19 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
763
582
  return item.role === 0;
764
583
  }).slice(-1)[0];
765
584
  if (!(((_agentObjRef$current = agentObjRef.current) === null || _agentObjRef$current === void 0 ? void 0 : _agentObjRef$current.isEnableRelated) === 1 && !(lastUserRequestMessage !== null && lastUserRequestMessage !== void 0 && lastUserRequestMessage.relatedResourceList) && ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'end' || (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.moduleType) === 'COMPLETED') && lastMessage.stop === 0)) {
766
- _context11.next = 8;
585
+ _context7.next = 8;
767
586
  break;
768
587
  }
769
- _context11.next = 8;
588
+ _context7.next = 8;
770
589
  return rewriteRecommendListFormHistory(chatList, "".concat(lastUserRequestMessage.chatId));
771
590
  case 8:
772
591
  case "end":
773
- return _context11.stop();
592
+ return _context7.stop();
774
593
  }
775
- }, _callee11);
594
+ }, _callee7);
776
595
  }));
777
- return function (_x21) {
778
- return _ref12.apply(this, arguments);
596
+ return function (_x12) {
597
+ return _ref8.apply(this, arguments);
779
598
  };
780
599
  }(), [dispatch, streamChat, removeLastEventId, rewriteRecommendListFormHistory]);
781
600
  var _useChatHistory = useChatHistory(checkUnfinishedMessage, scrollBottomForce, containerRef),
@@ -792,76 +611,9 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
792
611
  }
793
612
  }, [messageList, isMoreLoading, throttledScrollToBottom, scrollBottomForce]);
794
613
 
795
- // 获取对话标题
796
- var getHeaderValue = /*#__PURE__*/function () {
797
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(conversationId) {
798
- var res, _res$result3;
799
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
800
- while (1) switch (_context12.prev = _context12.next) {
801
- case 0:
802
- if (conversationId) {
803
- _context12.next = 2;
804
- break;
805
- }
806
- return _context12.abrupt("return");
807
- case 2:
808
- _context12.prev = 2;
809
- _context12.next = 5;
810
- return getMessageTitle("".concat(conversationId));
811
- case 5:
812
- res = _context12.sent;
813
- if ((res === null || res === void 0 ? void 0 : res.status) === 0) {
814
- setHeaderValue(res === null || res === void 0 || (_res$result3 = res.result) === null || _res$result3 === void 0 ? void 0 : _res$result3.title);
815
- }
816
- _context12.next = 12;
817
- break;
818
- case 9:
819
- _context12.prev = 9;
820
- _context12.t0 = _context12["catch"](2);
821
- Toast.error('网络异常');
822
- case 12:
823
- case "end":
824
- return _context12.stop();
825
- }
826
- }, _callee12, null, [[2, 9]]);
827
- }));
828
- return function getHeaderValue(_x22) {
829
- return _ref13.apply(this, arguments);
830
- };
831
- }();
832
- React.useEffect(function () {
833
- if (conversationId && conversationIdRef.current !== conversationId) {
834
- conversationIdRef.current = conversationId;
835
- // 如果有初始化发送值,不自动加载历史消息,而是直接发送初始化发送值
836
- if (autoLoadConversation && !initSendValue) {
837
- getHeaderValue(conversationId);
838
- getContentMessageList();
839
- }
840
- if (initSendValue) {
841
- getHeaderValue(conversationId);
842
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
843
- handleSend(initSendValue);
844
- }
845
- }
846
- }, [conversationId, autoLoadConversation, initSendValue]);
847
- React.useEffect(function () {
848
- var idAtEffectTime = conversationId;
849
- return function () {
850
- if (idAtEffectTime !== null && idAtEffectTime !== undefined && idAtEffectTime !== -1) {
851
- if (controllerRef.current) {
852
- controllerRef.current.abort();
853
- }
854
- if (streamEsAbortRef.current) {
855
- streamEsAbortRef.current.abort();
856
- }
857
- }
858
- clearQuotesFromRedux();
859
- };
860
- }, [conversationId]);
861
-
862
614
  // 开始会话
863
615
  var startChat = React.useCallback( /*#__PURE__*/function () {
864
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(messageList) {
616
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(messageList) {
865
617
  var _reverse$find;
866
618
  var isSystemAuto,
867
619
  conversationId,
@@ -878,13 +630,13 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
878
630
  responseMsg,
879
631
  result,
880
632
  aiChat,
881
- _args13 = arguments;
882
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
883
- while (1) switch (_context13.prev = _context13.next) {
633
+ _args8 = arguments;
634
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
635
+ while (1) switch (_context8.prev = _context8.next) {
884
636
  case 0:
885
- isSystemAuto = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
886
- conversationId = _args13.length > 2 ? _args13[2] : undefined;
887
- isAskFileSend = _args13.length > 3 ? _args13[3] : undefined;
637
+ isSystemAuto = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : false;
638
+ conversationId = _args8.length > 2 ? _args8[2] : undefined;
639
+ isAskFileSend = _args8.length > 3 ? _args8[3] : undefined;
888
640
  // 如果是ask卡片的file上传,发送content为''
889
641
  val = isAskFileSend ? '' : (_reverse$find = _toConsumableArray(messageList).reverse().find(function (item) {
890
642
  return item.role === 0;
@@ -899,7 +651,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
899
651
  signal = controllerRef.current.signal;
900
652
  step.current = 1;
901
653
  currentBussinessParams = _objectSpread({}, bussinessParamsRef.current || {});
902
- _context13.prev = 10;
654
+ _context8.prev = 10;
903
655
  params = _objectSpread({
904
656
  content: val,
905
657
  conversationId: conversationId || conversationIdRef.current,
@@ -929,7 +681,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
929
681
  if (isSystemAuto) {
930
682
  params.isSystemAuto = 1;
931
683
  }
932
- _context13.next = 20;
684
+ _context8.next = 20;
933
685
  return fetch("https://".concat(baseUrlRef.current, "/mbot/web/agent-message"), {
934
686
  method: 'POST',
935
687
  headers: {
@@ -940,15 +692,15 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
940
692
  body: JSON.stringify(params)
941
693
  });
942
694
  case 20:
943
- _response = _context13.sent;
695
+ _response = _context8.sent;
944
696
  if (!_response.ok) {
945
- _context13.next = 29;
697
+ _context8.next = 29;
946
698
  break;
947
699
  }
948
- _context13.next = 24;
700
+ _context8.next = 24;
949
701
  return _response.json();
950
702
  case 24:
951
- responseMsg = _context13.sent;
703
+ responseMsg = _context8.sent;
952
704
  // 执行使用方定义的回调函数
953
705
  if (!onFirstSendSuccessCalledRef.current) {
954
706
  onFirstSendSuccess === null || onFirstSendSuccess === void 0 || onFirstSendSuccess();
@@ -980,12 +732,12 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
980
732
  }
981
733
  }
982
734
  case 29:
983
- _context13.next = 34;
735
+ _context8.next = 34;
984
736
  break;
985
737
  case 31:
986
- _context13.prev = 31;
987
- _context13.t0 = _context13["catch"](10);
988
- if (_context13.t0.name === 'AbortError') {
738
+ _context8.prev = 31;
739
+ _context8.t0 = _context8["catch"](10);
740
+ if (_context8.t0.name === 'AbortError') {
989
741
  setMsgLoading(false);
990
742
  if (valueRef.current) {
991
743
  setStatus(1);
@@ -1003,67 +755,243 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1003
755
  }
1004
756
  case 34:
1005
757
  case "end":
1006
- return _context13.stop();
758
+ return _context8.stop();
1007
759
  }
1008
- }, _callee13, null, [[10, 31]]);
760
+ }, _callee8, null, [[10, 31]]);
1009
761
  }));
1010
- return function (_x23) {
1011
- return _ref14.apply(this, arguments);
762
+ return function (_x13) {
763
+ return _ref9.apply(this, arguments);
1012
764
  };
1013
765
  }(), [dispatch]);
766
+ var fillInputModel = React.useCallback(function (value, messageList) {
767
+ if ((messageList === null || messageList === void 0 ? void 0 : messageList.length) > 0 && value && messageList[messageList.length - 1].moduleType === 'ask') {
768
+ var targetChatItem = _toConsumableArray(messageList).reverse().find(function (item) {
769
+ return item.role === 1;
770
+ });
771
+ if (!targetChatItem || !targetChatItem.moduleInfo) return;
772
+ var moduleInfo = targetChatItem.moduleInfo;
773
+ var _inputModel = _defineProperty({}, "".concat(moduleInfo.id, ".input"), value || '');
774
+ inputModelRef.current = _inputModel;
775
+ }
776
+ }, []);
777
+ var handleSend = React.useCallback( /*#__PURE__*/function () {
778
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(val) {
779
+ var _chatInputConfig$onBe;
780
+ var agent,
781
+ isSystemAuto,
782
+ conversationId,
783
+ value,
784
+ fileValidationMsg,
785
+ cleanVal,
786
+ userChat,
787
+ prevChatList,
788
+ _prevChatList,
789
+ lastItem,
790
+ newChatList,
791
+ _args9 = arguments;
792
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
793
+ while (1) switch (_context9.prev = _context9.next) {
794
+ case 0:
795
+ agent = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : agentObjRef.current;
796
+ isSystemAuto = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : false;
797
+ conversationId = _args9.length > 3 ? _args9[3] : undefined;
798
+ value = val.trim();
799
+ console.log('initAttachments', initAttachments);
800
+ if (!(!value && !isSystemAuto)) {
801
+ _context9.next = 7;
802
+ break;
803
+ }
804
+ return _context9.abrupt("return");
805
+ case 7:
806
+ if (navigator.onLine) {
807
+ _context9.next = 10;
808
+ break;
809
+ }
810
+ Toast.error('无法连接到网络');
811
+ return _context9.abrupt("return");
812
+ case 10:
813
+ if (!(status === 2 || isMsgRecievingRef.current)) {
814
+ _context9.next = 13;
815
+ break;
816
+ }
817
+ Toast.error('AI正在输出中,请稍后');
818
+ return _context9.abrupt("return");
819
+ case 13:
820
+ chatInputConfig === null || chatInputConfig === void 0 || (_chatInputConfig$onBe = chatInputConfig.onBeforeSend) === null || _chatInputConfig$onBe === void 0 || _chatInputConfig$onBe.call(chatInputConfig, value);
821
+
822
+ // 设置inputModel
823
+ fillInputModel(value, messageListRef.current);
824
+ fileValidationMsg = fileValidation(fileListRef.current);
825
+ if (!fileValidationMsg) {
826
+ _context9.next = 19;
827
+ break;
828
+ }
829
+ Toast.error(fileValidationMsg);
830
+ return _context9.abrupt("return");
831
+ case 19:
832
+ if (isPlaying) {
833
+ // 点击发送按钮时,先停止播放
834
+ stopTTSByText === null || stopTTSByText === void 0 || stopTTSByText();
835
+ }
836
+ valueRef.current = '';
837
+ cleanVal = filterPropmptFromUserInput(agent.defaultPrompt, val);
838
+ userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current), initAttachmentsRef.current);
839
+ vipLevelRef.current = null;
840
+
841
+ // 根据isSystemAuto决定是否添加用户消息到列表
842
+ prevChatList = messageListRef.current.slice();
843
+ if (!isSystemAuto) {
844
+ setMsgLoading(true);
845
+ if (((_prevChatList = prevChatList) === null || _prevChatList === void 0 ? void 0 : _prevChatList.length) > 1) {
846
+ lastItem = prevChatList[prevChatList.length - 1];
847
+ if (lastItem.moduleType === 'ask') {
848
+ prevChatList = [].concat(_toConsumableArray(prevChatList.slice(0, -1)), [_objectSpread(_objectSpread({}, prevChatList[prevChatList.length - 1]), {}, {
849
+ disableUploadFile: true
850
+ })]);
851
+ }
852
+ }
853
+ newChatList = [].concat(_toConsumableArray(prevChatList), [userChat]);
854
+ dispatch(setMessageList({
855
+ messageList: newChatList
856
+ }));
857
+ startChat(newChatList, isSystemAuto, conversationId);
858
+ } else {
859
+ setMsgLoading(true);
860
+ // 系统自动上传,直接开始会话,不更新列表
861
+ startChat([].concat(_toConsumableArray(prevChatList), [userChat]), isSystemAuto, conversationId);
862
+ }
863
+ case 26:
864
+ case "end":
865
+ return _context9.stop();
866
+ }
867
+ }, _callee9);
868
+ }));
869
+ return function (_x14) {
870
+ return _ref10.apply(this, arguments);
871
+ };
872
+ }(), [dispatch, startChat, chatInputConfig, createUserChat, fillInputModel, isPlaying, status, stopTTSByText]);
873
+
874
+ // 获取对话标题
875
+ var getHeaderValue = React.useCallback( /*#__PURE__*/function () {
876
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(conversationId) {
877
+ var res, _res$result;
878
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
879
+ while (1) switch (_context10.prev = _context10.next) {
880
+ case 0:
881
+ if (conversationId) {
882
+ _context10.next = 2;
883
+ break;
884
+ }
885
+ return _context10.abrupt("return");
886
+ case 2:
887
+ _context10.prev = 2;
888
+ _context10.next = 5;
889
+ return getMessageTitle("".concat(conversationId));
890
+ case 5:
891
+ res = _context10.sent;
892
+ if ((res === null || res === void 0 ? void 0 : res.status) === 0) {
893
+ setHeaderValue(res === null || res === void 0 || (_res$result = res.result) === null || _res$result === void 0 ? void 0 : _res$result.title);
894
+ }
895
+ _context10.next = 12;
896
+ break;
897
+ case 9:
898
+ _context10.prev = 9;
899
+ _context10.t0 = _context10["catch"](2);
900
+ Toast.error('网络异常');
901
+ case 12:
902
+ case "end":
903
+ return _context10.stop();
904
+ }
905
+ }, _callee10, null, [[2, 9]]);
906
+ }));
907
+ return function (_x15) {
908
+ return _ref11.apply(this, arguments);
909
+ };
910
+ }(), []);
911
+ React.useEffect(function () {
912
+ if (conversationId && conversationIdRef.current !== conversationId) {
913
+ conversationIdRef.current = conversationId;
914
+ // 清空当前会话的消息列表
915
+ messageListRef.current = [];
916
+ // 如果有初始化发送值,不自动加载历史消息,而是直接发送初始化发送值
917
+ if (autoLoadConversation && !initSendValue) {
918
+ getHeaderValue(conversationId);
919
+ getContentMessageList();
920
+ }
921
+ if (initSendValue) {
922
+ getHeaderValue(conversationId);
923
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
924
+ handleSend(initSendValue);
925
+ }
926
+ }
927
+ }, [conversationId, autoLoadConversation, initSendValue, handleSend, getContentMessageList, getHeaderValue]);
928
+ React.useEffect(function () {
929
+ var idAtEffectTime = conversationId;
930
+ return function () {
931
+ if (idAtEffectTime !== null && idAtEffectTime !== undefined) {
932
+ if (controllerRef.current) {
933
+ controllerRef.current.abort();
934
+ }
935
+ if (streamEsAbortRef.current) {
936
+ streamEsAbortRef.current.abort();
937
+ }
938
+ }
939
+ clearQuotesFromRedux();
940
+ };
941
+ }, [conversationId, dispatch, clearQuotesFromRedux, streamEsAbortRef]);
1014
942
  var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
1015
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(agentId) {
943
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(agentId) {
1016
944
  var res;
1017
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1018
- while (1) switch (_context14.prev = _context14.next) {
945
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
946
+ while (1) switch (_context11.prev = _context11.next) {
1019
947
  case 0:
1020
- _context14.prev = 0;
1021
- _context14.next = 3;
948
+ _context11.prev = 0;
949
+ _context11.next = 3;
1022
950
  return getAgentDetail(agentId);
1023
951
  case 3:
1024
- res = _context14.sent;
952
+ res = _context11.sent;
1025
953
  if (!(res.status === 0)) {
1026
- _context14.next = 9;
954
+ _context11.next = 9;
1027
955
  break;
1028
956
  }
1029
957
  dispatch(setAgentDetail({
1030
958
  agentDetail: res.result
1031
959
  }));
1032
- return _context14.abrupt("return", res.result);
960
+ return _context11.abrupt("return", res.result);
1033
961
  case 9:
1034
962
  Toast.error(res.message);
1035
- return _context14.abrupt("return", null);
963
+ return _context11.abrupt("return", null);
1036
964
  case 11:
1037
- _context14.next = 17;
965
+ _context11.next = 17;
1038
966
  break;
1039
967
  case 13:
1040
- _context14.prev = 13;
1041
- _context14.t0 = _context14["catch"](0);
1042
- console.log('error', _context14.t0);
1043
- return _context14.abrupt("return", null);
968
+ _context11.prev = 13;
969
+ _context11.t0 = _context11["catch"](0);
970
+ console.log('error', _context11.t0);
971
+ return _context11.abrupt("return", null);
1044
972
  case 17:
1045
973
  case "end":
1046
- return _context14.stop();
974
+ return _context11.stop();
1047
975
  }
1048
- }, _callee14, null, [[0, 13]]);
976
+ }, _callee11, null, [[0, 13]]);
1049
977
  }));
1050
- return function (_x24) {
1051
- return _ref15.apply(this, arguments);
978
+ return function (_x16) {
979
+ return _ref12.apply(this, arguments);
1052
980
  };
1053
981
  }(), []);
1054
982
  var startConversationAndChat = React.useCallback( /*#__PURE__*/function () {
1055
- var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(value) {
983
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(value) {
1056
984
  var _agentObjRef$current3;
1057
985
  var currentBussinessParams, params, res;
1058
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1059
- while (1) switch (_context15.prev = _context15.next) {
986
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
987
+ while (1) switch (_context12.prev = _context12.next) {
1060
988
  case 0:
1061
989
  if ((_agentObjRef$current3 = agentObjRef.current) !== null && _agentObjRef$current3 !== void 0 && _agentObjRef$current3.agentId) {
1062
- _context15.next = 3;
990
+ _context12.next = 3;
1063
991
  break;
1064
992
  }
1065
993
  Toast.error('请先关联智能体');
1066
- return _context15.abrupt("return");
994
+ return _context12.abrupt("return");
1067
995
  case 3:
1068
996
  currentBussinessParams = _objectSpread({}, bussinessParamsRef.current || {});
1069
997
  params = _objectSpread({
@@ -1075,12 +1003,12 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1075
1003
  dispatch(setAutoLoadConversation({
1076
1004
  autoLoadConversation: false
1077
1005
  }));
1078
- _context15.prev = 6;
1006
+ _context12.prev = 6;
1079
1007
  setMsgLoading(true);
1080
- _context15.next = 10;
1008
+ _context12.next = 10;
1081
1009
  return createRoomId(params);
1082
1010
  case 10:
1083
- res = _context15.sent;
1011
+ res = _context12.sent;
1084
1012
  if (res.status === 0) {
1085
1013
  dispatch(setConversationId({
1086
1014
  conversationId: res.result
@@ -1097,29 +1025,29 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1097
1025
  } else {
1098
1026
  Toast.error(res.message);
1099
1027
  }
1100
- _context15.next = 19;
1028
+ _context12.next = 19;
1101
1029
  break;
1102
1030
  case 14:
1103
- _context15.prev = 14;
1104
- _context15.t0 = _context15["catch"](6);
1031
+ _context12.prev = 14;
1032
+ _context12.t0 = _context12["catch"](6);
1105
1033
  Toast.error('创建会话失败');
1106
- console.log('error', _context15.t0);
1034
+ console.log('error', _context12.t0);
1107
1035
  setMsgLoading(false);
1108
1036
  case 19:
1109
1037
  case "end":
1110
- return _context15.stop();
1038
+ return _context12.stop();
1111
1039
  }
1112
- }, _callee15, null, [[6, 14]]);
1040
+ }, _callee12, null, [[6, 14]]);
1113
1041
  }));
1114
- return function (_x25) {
1115
- return _ref16.apply(this, arguments);
1042
+ return function (_x17) {
1043
+ return _ref13.apply(this, arguments);
1116
1044
  };
1117
- }(), []);
1045
+ }(), [handleSend, platform, dispatch, createRoomId, onConversationCreated, getHeaderValue]);
1118
1046
  React.useEffect(function () {
1119
1047
  if (agentId && baseUrl) {
1120
1048
  fetchAgentDetail(agentId);
1121
1049
  }
1122
- }, [agentId, reloadAgentKey, baseUrl]);
1050
+ }, [agentId, reloadAgentKey, baseUrl, fetchAgentDetail]);
1123
1051
  React.useEffect(function () {
1124
1052
  if (resetKey && resetKey !== resetKeyRef.current) {
1125
1053
  var _controllerRef$curren, _streamEsAbortRef$cur;
@@ -1134,113 +1062,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1134
1062
  }));
1135
1063
  setHeaderValue('');
1136
1064
  }
1137
- }, [resetKey]);
1138
- var fillInputModel = React.useCallback(function (value, messageList) {
1139
- if ((messageList === null || messageList === void 0 ? void 0 : messageList.length) > 0 && value && messageList[messageList.length - 1].moduleType === 'ask') {
1140
- var targetChatItem = _toConsumableArray(messageList).reverse().find(function (item) {
1141
- return item.role === 1;
1142
- });
1143
- if (!targetChatItem || !targetChatItem.moduleInfo) return;
1144
- var moduleInfo = targetChatItem.moduleInfo;
1145
- var _inputModel = _defineProperty({}, "".concat(moduleInfo.id, ".input"), value || '');
1146
- inputModelRef.current = _inputModel;
1147
- }
1148
- }, []);
1149
- var handleSend = React.useCallback( /*#__PURE__*/function () {
1150
- var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(val) {
1151
- var _chatInputConfig$onBe;
1152
- var agent,
1153
- isSystemAuto,
1154
- conversationId,
1155
- value,
1156
- fileValidationMsg,
1157
- cleanVal,
1158
- userChat,
1159
- prevChatList,
1160
- _prevChatList,
1161
- lastItem,
1162
- newChatList,
1163
- _args16 = arguments;
1164
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1165
- while (1) switch (_context16.prev = _context16.next) {
1166
- case 0:
1167
- agent = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : agentObjRef.current;
1168
- isSystemAuto = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : false;
1169
- conversationId = _args16.length > 3 ? _args16[3] : undefined;
1170
- value = val.trim();
1171
- if (!(!value && !isSystemAuto)) {
1172
- _context16.next = 6;
1173
- break;
1174
- }
1175
- return _context16.abrupt("return");
1176
- case 6:
1177
- if (navigator.onLine) {
1178
- _context16.next = 9;
1179
- break;
1180
- }
1181
- Toast.error('无法连接到网络');
1182
- return _context16.abrupt("return");
1183
- case 9:
1184
- if (!(status === 2 || isMsgRecievingRef.current)) {
1185
- _context16.next = 12;
1186
- break;
1187
- }
1188
- Toast.error('AI正在输出中,请稍后');
1189
- return _context16.abrupt("return");
1190
- case 12:
1191
- chatInputConfig === null || chatInputConfig === void 0 || (_chatInputConfig$onBe = chatInputConfig.onBeforeSend) === null || _chatInputConfig$onBe === void 0 || _chatInputConfig$onBe.call(chatInputConfig, value);
1192
-
1193
- // 设置inputModel
1194
- fillInputModel(value, messageListRef.current);
1195
- fileValidationMsg = fileValidation(fileListRef.current);
1196
- if (!fileValidationMsg) {
1197
- _context16.next = 18;
1198
- break;
1199
- }
1200
- Toast.error(fileValidationMsg);
1201
- return _context16.abrupt("return");
1202
- case 18:
1203
- if (isPlaying) {
1204
- // 点击发送按钮时,先停止播放
1205
- stopTTSByText === null || stopTTSByText === void 0 || stopTTSByText();
1206
- }
1207
- valueRef.current = '';
1208
- cleanVal = filterPropmptFromUserInput(agent.defaultPrompt, val);
1209
- userChat = createUserChat(cleanVal, "".concat(conversationIdRef.current), initAttachments);
1210
- vipLevelRef.current = null;
1211
-
1212
- // 根据isSystemAuto决定是否添加用户消息到列表
1213
- prevChatList = messageListRef.current.slice();
1214
- if (!isSystemAuto) {
1215
- setMsgLoading(true);
1216
- if (((_prevChatList = prevChatList) === null || _prevChatList === void 0 ? void 0 : _prevChatList.length) > 1) {
1217
- lastItem = prevChatList[prevChatList.length - 1];
1218
- if (lastItem.moduleType === 'ask') {
1219
- prevChatList = [].concat(_toConsumableArray(prevChatList.slice(0, -1)), [_objectSpread(_objectSpread({}, prevChatList[prevChatList.length - 1]), {}, {
1220
- disableUploadFile: true
1221
- })]);
1222
- }
1223
- }
1224
- newChatList = [].concat(_toConsumableArray(prevChatList), [userChat]);
1225
- dispatch(setMessageList({
1226
- messageList: newChatList
1227
- }));
1228
- startChat(newChatList, isSystemAuto, conversationId);
1229
- } else {
1230
- setMsgLoading(true);
1231
- // 系统自动上传,直接开始会话,不更新列表
1232
- startChat([].concat(_toConsumableArray(prevChatList), [userChat]), isSystemAuto, conversationId);
1233
- }
1234
- case 25:
1235
- case "end":
1236
- return _context16.stop();
1237
- }
1238
- }, _callee16);
1239
- }));
1240
- return function (_x26) {
1241
- return _ref17.apply(this, arguments);
1242
- };
1243
- }(), [dispatch, startChat, chatInputConfig === null || chatInputConfig === void 0 ? void 0 : chatInputConfig.onBeforeSend]);
1065
+ }, [resetKey, dispatch, streamEsAbortRef]);
1244
1066
  var handleSendFile = React.useCallback(function (messageList) {
1245
1067
  if (!navigator.onLine) {
1246
1068
  Toast.error('无法连接到网络');
@@ -1253,7 +1075,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1253
1075
  valueRef.current = '';
1254
1076
  setMsgLoading(true);
1255
1077
  startChat(messageList, false, undefined, true);
1256
- }, [dispatch, startChat, status, msgLoading]);
1078
+ }, [startChat, status, msgLoading]);
1257
1079
  React.useEffect(function () {
1258
1080
  var _fileListRef$current;
1259
1081
  var hasValidFile = ((_fileListRef$current = fileListRef.current) === null || _fileListRef$current === void 0 ? void 0 : _fileListRef$current.length) > 0;
@@ -1295,7 +1117,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1295
1117
  }));
1296
1118
  }
1297
1119
  }
1298
- }, [fileList, dispatch]);
1120
+ }, [fileList, dispatch, handleSendFile, createUserChat]);
1299
1121
  var onSucessExcel = React.useCallback(function (value) {
1300
1122
  // setDisableSend(true);
1301
1123
  setMsgLoading(false);
@@ -1385,7 +1207,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1385
1207
  };
1386
1208
  inputModelRef.current = _inputModel;
1387
1209
  handleSend('重试');
1388
- }, []);
1210
+ }, [handleSend, dispatch]);
1389
1211
  React.useEffect(function () {
1390
1212
  if (interruptKey && interruptKey !== interruptKeyRef.current) {
1391
1213
  interruptKeyRef.current = interruptKey || '';
@@ -1404,7 +1226,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1404
1226
  onSendEnd === null || onSendEnd === void 0 || onSendEnd(messageList[messageList.length - 1]);
1405
1227
  }
1406
1228
  }
1407
- }, [interruptKey, onSendEnd, handleInterrupt]);
1229
+ }, [interruptKey, onSendEnd, handleInterrupt, messageList, dispatch, streamEsAbortRef]);
1408
1230
  return {
1409
1231
  headerValue: headerValue,
1410
1232
  getHeaderValue: getHeaderValue,
@@ -1424,8 +1246,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1424
1246
  isMoreLoading: isMoreLoading,
1425
1247
  startConversationAndChat: startConversationAndChat,
1426
1248
  deleteConversation: deleteConversation,
1427
- regenerate: regenerate,
1428
- startAICorrection: startAICorrection
1249
+ regenerate: regenerate
1429
1250
  };
1430
1251
  };
1431
1252
  export default useCommonChatAPI;