@ibiz-template/vue3-components 0.7.41-alpha.165 → 0.7.41-alpha.166

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.
Files changed (28) hide show
  1. package/dist/{index-li-EqXGB.js → index-CCoBeNIV.js} +6 -6
  2. package/dist/{index.es-CA0rGKdK.js → index.es-D1vng-7i.js} +1 -1
  3. package/dist/index.min.css +1 -1
  4. package/dist/index.system.min.js +1 -1
  5. package/dist/{wang-editor-BPGsMZgX.js → wang-editor-B0ZpE6o-.js} +1 -1
  6. package/dist/{xlsx-util-Bv9fDQB8.js → xlsx-util-Djaaq9Po.js} +1 -1
  7. package/es/editor/index.mjs +8 -0
  8. package/es/editor/work-space/embed-work-space/embed-work-space.css +1 -0
  9. package/es/editor/work-space/embed-work-space/embed-work-space.mjs +75 -0
  10. package/es/editor/work-space/embed-work-space.controller.mjs +62 -0
  11. package/es/editor/work-space/embed-work-space.provider.mjs +22 -0
  12. package/es/editor/work-space/index.mjs +5 -0
  13. package/es/util/ai-chat-util/ai-chat-util.mjs +217 -240
  14. package/lib/editor/index.cjs +8 -0
  15. package/lib/editor/work-space/embed-work-space/embed-work-space.cjs +77 -0
  16. package/lib/editor/work-space/embed-work-space/embed-work-space.css +1 -0
  17. package/lib/editor/work-space/embed-work-space.controller.cjs +64 -0
  18. package/lib/editor/work-space/embed-work-space.provider.cjs +24 -0
  19. package/lib/editor/work-space/index.cjs +11 -0
  20. package/lib/util/ai-chat-util/ai-chat-util.cjs +217 -240
  21. package/package.json +5 -5
  22. package/src/editor/index.ts +7 -1
  23. package/src/editor/work-space/embed-work-space/embed-work-space.scss +8 -0
  24. package/src/editor/work-space/embed-work-space/embed-work-space.tsx +78 -0
  25. package/src/editor/work-space/embed-work-space.controller.ts +70 -0
  26. package/src/editor/work-space/embed-work-space.provider.ts +28 -0
  27. package/src/editor/work-space/index.ts +3 -0
  28. package/src/util/ai-chat-util/ai-chat-util.ts +256 -276
@@ -23,6 +23,133 @@ class AIChatUtil {
23
23
  __publicField(this, "PRE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: application/json;charset=UTF-8");
24
24
  // 无流内容回来
25
25
  __publicField(this, "NONE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: null");
26
+ // 网络中断自动续传的最大重试次数
27
+ __publicField(this, "AUTO_RESUME_MAX_RETRY", 3);
28
+ // 网络中断自动续传的退避基数(毫秒),按 1s/2s/4s 指数退避
29
+ __publicField(this, "AUTO_RESUME_BACKOFF_BASE", 1e3);
30
+ }
31
+ /**
32
+ * @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
33
+ * @param {any} aiChat 单实例聊天总控
34
+ * @param {string} id 本次问答的流式消息 id
35
+ * @param {string} localMsgID 本地用户消息 id(用于回填真实消息 id;为空串时为恢复会话场景,状态 20 走 isLoading 加载分支)
36
+ * @return {*} {(msg: IPortalAsyncAction) => void}
37
+ * @memberof AIChatUtil
38
+ */
39
+ createChatSseHandler(aiChat, id, localMsgID) {
40
+ let updateFlag = true;
41
+ return (msg) => {
42
+ if (msg.actionstate === 20 && msg.actionresult) {
43
+ if (localMsgID) {
44
+ aiChat.removeWaitingMessage(id);
45
+ if (msg.asextparam && updateFlag) {
46
+ aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
47
+ updateFlag = false;
48
+ }
49
+ } else {
50
+ aiChat.isLoading.value = true;
51
+ }
52
+ if (!aiChat.getActiveAsyncacitonId()) {
53
+ aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
54
+ }
55
+ aiChat.addMessage({
56
+ messageid: id,
57
+ state: msg.actionstate,
58
+ type: "DEFAULT",
59
+ role: "ASSISTANT",
60
+ content: msg.actionresult,
61
+ status: "pending"
62
+ });
63
+ } else if (msg.actionstate === 30 && msg.actionresult) {
64
+ const result = JSON.parse(msg.actionresult);
65
+ if (result.usage) {
66
+ aiChat.updateMsgUsage(id, result.usage);
67
+ }
68
+ if (result.files) {
69
+ aiChat.updateMsgOutputFiles(id, result.files);
70
+ }
71
+ const choices = result.choices;
72
+ if (choices && choices.length > 0) {
73
+ aiChat.replaceMessage({
74
+ messageid: id,
75
+ state: msg.actionstate,
76
+ type: "DEFAULT",
77
+ role: "ASSISTANT",
78
+ content: choices[0].content || "",
79
+ realmessageid: choices[0].messageid,
80
+ status: "sent"
81
+ });
82
+ }
83
+ aiChat.setActiveAsyncacitonId("");
84
+ } else if (msg.actionstate === 40) {
85
+ aiChat.replaceMessage({
86
+ messageid: id,
87
+ state: msg.actionstate,
88
+ type: "ERROR",
89
+ role: "ASSISTANT",
90
+ errorText: msg.actionresult,
91
+ status: "failed"
92
+ });
93
+ aiChat.setActiveAsyncacitonId("");
94
+ }
95
+ };
96
+ }
97
+ /**
98
+ * @description 网络中断(network error)后按 asyncacitonid 自动续传,指数退避重试;成功返回 true,不可恢复/重试耗尽返回 false 交回调用方走既有错误处理
99
+ * @param {any} aiChat 单实例聊天总控
100
+ * @param {IContext} ctx 上下文
101
+ * @param {IParams} param 视图参数
102
+ * @param {*} deService 实体服务
103
+ * @param {{ id: string; abortController: AbortController }} state 聊天实例提问状态(WeakMap 持有的同一对象引用)
104
+ * @param {{ asyncacitonid: string; sessionid?: string; srfaiagent?: string; srfproject?: string }} resumeInfo 续传参数
105
+ * @param {(msg: IPortalAsyncAction) => void} onMsg SSE 流式消息处理回调
106
+ * @return {*} {Promise<boolean>} 是否续传成功
107
+ * @memberof AIChatUtil
108
+ */
109
+ async autoResumeChat(aiChat, ctx, param, deService, state, resumeInfo, onMsg) {
110
+ var _a;
111
+ (_a = state.abortController) == null ? void 0 : _a.abort();
112
+ state.abortController = new AbortController();
113
+ for (let attempt = 1; attempt <= this.AUTO_RESUME_MAX_RETRY; attempt++) {
114
+ try {
115
+ await new Promise((resolve) => {
116
+ setTimeout(
117
+ resolve,
118
+ this.AUTO_RESUME_BACKOFF_BASE * 2 ** (attempt - 1)
119
+ );
120
+ });
121
+ const resumeRequestData = {
122
+ asyncacitonid: resumeInfo.asyncacitonid
123
+ };
124
+ if (resumeInfo.sessionid) {
125
+ resumeRequestData.sessionid = resumeInfo.sessionid;
126
+ }
127
+ if (resumeInfo.srfaiagent) {
128
+ resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
129
+ }
130
+ if (resumeInfo.srfproject) {
131
+ resumeRequestData.srfproject = resumeInfo.srfproject;
132
+ }
133
+ await deService.aiResumeSse(
134
+ onMsg,
135
+ state.abortController,
136
+ ctx,
137
+ { srfactag: param.srfactag },
138
+ { ...resumeRequestData }
139
+ );
140
+ return true;
141
+ } catch (resumeError) {
142
+ const resumeMsg = (resumeError == null ? void 0 : resumeError.message) || "";
143
+ if ((resumeError == null ? void 0 : resumeError.name) === "AbortError") {
144
+ return false;
145
+ }
146
+ if (resumeMsg === this.NONE_ERROR_MESSAGE) {
147
+ aiChat.setActiveAsyncacitonId("");
148
+ return false;
149
+ }
150
+ }
151
+ }
152
+ return false;
26
153
  }
27
154
  /**
28
155
  * 获取AI聊天对象
@@ -207,7 +334,8 @@ class AIChatUtil {
207
334
  const chatOptions = {
208
335
  locale: ibiz.i18n.getLang(),
209
336
  enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
210
- projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
337
+ projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
338
+ selectAIProjectId: editorParams.srfselectaiprojectid
211
339
  };
212
340
  if (editorParams.srfaiappendcurdata) {
213
341
  chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
@@ -418,37 +546,37 @@ class AIChatUtil {
418
546
  return true;
419
547
  };
420
548
  chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
421
- let updateFlag = true;
422
549
  const state = getChatState(aiChat);
423
550
  state.id = qxUtil.createUUID();
424
551
  state.abortController = new AbortController();
425
552
  const { id, abortController } = state;
426
553
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
554
+ const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
427
555
  try {
428
- const questionRequestData = {
556
+ const requestData = {
429
557
  messages: arr,
430
558
  sessionid: sessionid2
431
559
  };
432
560
  if (srfaiagent)
433
- questionRequestData.srfaiagent = srfaiagent;
561
+ requestData.srfaiagent = srfaiagent;
434
562
  if (srfmode)
435
- questionRequestData.mode = srfmode;
563
+ requestData.mode = srfmode;
436
564
  if (srfscope)
437
- questionRequestData.srfscope = srfscope;
565
+ requestData.srfscope = srfscope;
438
566
  if (srfproject)
439
- questionRequestData.srfproject = srfproject;
567
+ requestData.srfproject = srfproject;
440
568
  if (srfknowledgebases)
441
- questionRequestData.knowledgebases = srfknowledgebases;
569
+ requestData.knowledgebases = srfknowledgebases;
442
570
  if (srfaiagentconfig) {
443
- Object.assign(questionRequestData, srfaiagentconfig);
571
+ Object.assign(requestData, srfaiagentconfig);
444
572
  }
445
573
  if (mcpservers) {
446
- Object.assign(questionRequestData, {
574
+ Object.assign(requestData, {
447
575
  mcpservers
448
576
  });
449
577
  }
450
578
  if (sessionmeta) {
451
- Object.assign(questionRequestData, {
579
+ Object.assign(requestData, {
452
580
  srfuimeta: JSON.stringify(sessionmeta)
453
581
  });
454
582
  }
@@ -460,68 +588,33 @@ class AIChatUtil {
460
588
  Object.assign(extParams, { ...appendcurdata });
461
589
  }
462
590
  if (extParams && Object.keys(extParams).length > 0) {
463
- Object.assign(questionRequestData, { srfextparams: extParams });
591
+ Object.assign(requestData, { srfextparams: extParams });
464
592
  }
465
593
  aiChat.addWaitingMessage(id);
466
594
  await deService.aiChatSse(
467
- (msg) => {
468
- if (msg.actionstate === 20 && msg.actionresult) {
469
- aiChat.removeWaitingMessage(id);
470
- if (msg.asextparam && localMsgID && updateFlag) {
471
- aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
472
- updateFlag = false;
473
- }
474
- if (!aiChat.getActiveAsyncacitonId()) {
475
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
476
- }
477
- aiChat.addMessage({
478
- messageid: id,
479
- state: msg.actionstate,
480
- type: "DEFAULT",
481
- role: "ASSISTANT",
482
- content: msg.actionresult,
483
- status: "pending"
484
- });
485
- } else if (msg.actionstate === 30 && msg.actionresult) {
486
- const result = JSON.parse(msg.actionresult);
487
- if (result.usage) {
488
- aiChat.updateMsgUsage(id, result.usage);
489
- }
490
- if (result.files) {
491
- aiChat.updateMsgOutputFiles(id, result.files);
492
- }
493
- const choices = result.choices;
494
- if (choices && choices.length > 0) {
495
- aiChat.replaceMessage({
496
- messageid: id,
497
- state: msg.actionstate,
498
- type: "DEFAULT",
499
- role: "ASSISTANT",
500
- content: choices[0].content || "",
501
- realmessageid: choices[0].messageid,
502
- status: "sent"
503
- });
504
- }
505
- aiChat.setActiveAsyncacitonId("");
506
- } else if (msg.actionstate === 40) {
507
- aiChat.replaceMessage({
508
- messageid: id,
509
- state: msg.actionstate,
510
- type: "ERROR",
511
- role: "ASSISTANT",
512
- errorText: msg.actionresult,
513
- status: "failed"
514
- });
515
- aiChat.setActiveAsyncacitonId("");
516
- }
517
- },
595
+ onMsg,
518
596
  abortController,
519
597
  ctx,
520
598
  { srfactag: param.srfactag },
521
- { ...questionRequestData }
599
+ { ...requestData }
522
600
  );
523
601
  } catch (error) {
524
- if (error && error.message !== this.PRE_ERROR_MESSAGE) {
602
+ const errMsg = (error == null ? void 0 : error.message) || "";
603
+ const asyncacitonid = aiChat.getActiveAsyncacitonId();
604
+ if (errMsg === "network error" && asyncacitonid) {
605
+ const resumed = await this.autoResumeChat(
606
+ aiChat,
607
+ ctx,
608
+ param,
609
+ deService,
610
+ state,
611
+ { asyncacitonid, sessionid: sessionid2, srfaiagent, srfproject },
612
+ onMsg
613
+ );
614
+ if (resumed)
615
+ return true;
616
+ }
617
+ if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
525
618
  aiChat.replaceMessage({
526
619
  messageid: id,
527
620
  state: 40,
@@ -535,7 +628,8 @@ class AIChatUtil {
535
628
  aiChat.replaceMessage(
536
629
  {
537
630
  ...lastMessage,
538
- state: 40
631
+ state: 40,
632
+ errorText: ibiz.i18n.t("app.aiError")
539
633
  },
540
634
  false
541
635
  );
@@ -588,77 +682,33 @@ class AIChatUtil {
588
682
  state.abortController = new AbortController();
589
683
  const { id, abortController } = state;
590
684
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
591
- const resumeRequestData = { asyncacitonid: other.asyncacitonid };
685
+ const requestData = { asyncacitonid: other.asyncacitonid };
592
686
  if (other.sessionid) {
593
- Object.assign(resumeRequestData, {
687
+ Object.assign(requestData, {
594
688
  sessionid: other.sessionid
595
689
  });
596
690
  }
597
691
  if (other.srfaiagent) {
598
- Object.assign(resumeRequestData, {
692
+ Object.assign(requestData, {
599
693
  srfaiagent: other.srfaiagent
600
694
  });
601
695
  }
602
696
  if (other.srfproject)
603
- Object.assign(resumeRequestData, {
697
+ Object.assign(requestData, {
604
698
  srfproject: other.srfproject
605
699
  });
700
+ const onMsg = this.createChatSseHandler(aiChat, id, "");
606
701
  try {
607
702
  await deService.aiResumeSse(
608
- (msg) => {
609
- if (msg.actionstate === 20 && msg.actionresult) {
610
- aiChat.isLoading.value = true;
611
- if (!aiChat.getActiveAsyncacitonId()) {
612
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
613
- }
614
- aiChat.addMessage({
615
- messageid: id,
616
- state: msg.actionstate,
617
- type: "DEFAULT",
618
- role: "ASSISTANT",
619
- content: msg.actionresult,
620
- status: "pending"
621
- });
622
- } else if (msg.actionstate === 30 && msg.actionresult) {
623
- const result = JSON.parse(msg.actionresult);
624
- if (result.usage) {
625
- aiChat.updateMsgUsage(id, result.usage);
626
- }
627
- if (result.files) {
628
- aiChat.updateMsgOutputFiles(id, result.files);
629
- }
630
- const choices = result.choices;
631
- if (choices && choices.length > 0) {
632
- aiChat.replaceMessage({
633
- messageid: id,
634
- state: msg.actionstate,
635
- type: "DEFAULT",
636
- role: "ASSISTANT",
637
- content: choices[0].content || "",
638
- realmessageid: choices[0].messageid,
639
- status: "sent"
640
- });
641
- }
642
- aiChat.setActiveAsyncacitonId("");
643
- } else if (msg.actionstate === 40) {
644
- aiChat.replaceMessage({
645
- messageid: id,
646
- state: msg.actionstate,
647
- type: "ERROR",
648
- role: "ASSISTANT",
649
- errorText: msg.actionresult,
650
- status: "failed"
651
- });
652
- aiChat.setActiveAsyncacitonId("");
653
- }
654
- },
703
+ onMsg,
655
704
  abortController,
656
705
  ctx,
657
706
  { srfactag: param.srfactag },
658
- { ...resumeRequestData }
707
+ { ...requestData }
659
708
  );
660
709
  } catch (error) {
661
- if (error && error.message !== this.NONE_ERROR_MESSAGE) {
710
+ const errMsg = (error == null ? void 0 : error.message) || "";
711
+ if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
662
712
  if (error && error.message !== this.PRE_ERROR_MESSAGE) {
663
713
  aiChat.replaceMessage({
664
714
  messageid: id,
@@ -673,7 +723,8 @@ class AIChatUtil {
673
723
  aiChat.replaceMessage(
674
724
  {
675
725
  ...lastMessage,
676
- state: 40
726
+ state: 40,
727
+ errorText: ibiz.i18n.t("app.aiError")
677
728
  },
678
729
  false
679
730
  );
@@ -1031,8 +1082,11 @@ class AIChatUtil {
1031
1082
  const chatOptions = {
1032
1083
  locale: ibiz.i18n.getLang(),
1033
1084
  enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
1034
- projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
1085
+ projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
1086
+ selectAIProjectId: params.srfselectaiprojectid
1035
1087
  };
1088
+ if (params.hasOwnProperty("srfselectaiprojectid"))
1089
+ delete params.srfselectaiprojectid;
1036
1090
  if (params.hasOwnProperty("srfenableaiprojectselect"))
1037
1091
  delete params.srfenableaiprojectselect;
1038
1092
  if (params.hasOwnProperty("srfprojectselectplaceholder"))
@@ -1273,35 +1327,35 @@ class AIChatUtil {
1273
1327
  return true;
1274
1328
  };
1275
1329
  chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
1276
- let updateFlag = true;
1277
1330
  const state = getChatState(aiChat);
1278
1331
  state.id = qxUtil.createUUID();
1279
1332
  state.abortController = new AbortController();
1280
1333
  const { id, abortController } = state;
1281
1334
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1335
+ const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
1282
1336
  try {
1283
- const questionRequestData = {
1337
+ const requestData = {
1284
1338
  messages: arr,
1285
1339
  sessionid
1286
1340
  };
1287
1341
  if (srfaiagent)
1288
- questionRequestData.srfaiagent = srfaiagent;
1342
+ requestData.srfaiagent = srfaiagent;
1289
1343
  if (srfmode)
1290
- questionRequestData.mode = srfmode;
1344
+ requestData.mode = srfmode;
1291
1345
  if (srfscope)
1292
- questionRequestData.srfscope = srfscope;
1346
+ requestData.srfscope = srfscope;
1293
1347
  if (srfproject)
1294
- questionRequestData.srfproject = srfproject;
1348
+ requestData.srfproject = srfproject;
1295
1349
  if (srfknowledgebases)
1296
- questionRequestData.knowledgebases = srfknowledgebases;
1350
+ requestData.knowledgebases = srfknowledgebases;
1297
1351
  if (srfaiagentconfig) {
1298
- Object.assign(questionRequestData, srfaiagentconfig);
1352
+ Object.assign(requestData, srfaiagentconfig);
1299
1353
  }
1300
1354
  if (mcpservers) {
1301
- Object.assign(questionRequestData, { mcpservers });
1355
+ Object.assign(requestData, { mcpservers });
1302
1356
  }
1303
1357
  if (sessionmeta) {
1304
- Object.assign(questionRequestData, {
1358
+ Object.assign(requestData, {
1305
1359
  srfuimeta: JSON.stringify(sessionmeta)
1306
1360
  });
1307
1361
  }
@@ -1313,68 +1367,33 @@ class AIChatUtil {
1313
1367
  Object.assign(extParams, { ...appendcurdata });
1314
1368
  }
1315
1369
  if (extParams && Object.keys(extParams).length > 0) {
1316
- Object.assign(questionRequestData, { srfextparams: extParams });
1370
+ Object.assign(requestData, { srfextparams: extParams });
1317
1371
  }
1318
1372
  aiChat.addWaitingMessage(id);
1319
1373
  await deService.aiChatSse(
1320
- (msg) => {
1321
- if (msg.actionstate === 20 && msg.actionresult) {
1322
- aiChat.removeWaitingMessage(id);
1323
- if (msg.asextparam && localMsgID && updateFlag) {
1324
- aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
1325
- updateFlag = false;
1326
- }
1327
- if (!aiChat.getActiveAsyncacitonId()) {
1328
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
1329
- }
1330
- aiChat.addMessage({
1331
- messageid: id,
1332
- state: msg.actionstate,
1333
- type: "DEFAULT",
1334
- role: "ASSISTANT",
1335
- content: msg.actionresult,
1336
- status: "pending"
1337
- });
1338
- } else if (msg.actionstate === 30 && msg.actionresult) {
1339
- const result = JSON.parse(msg.actionresult);
1340
- if (result.usage) {
1341
- aiChat.updateMsgUsage(id, result.usage);
1342
- }
1343
- if (result.files) {
1344
- aiChat.updateMsgOutputFiles(id, result.files);
1345
- }
1346
- const choices = result.choices;
1347
- if (choices && choices.length > 0) {
1348
- aiChat.replaceMessage({
1349
- messageid: id,
1350
- state: msg.actionstate,
1351
- type: "DEFAULT",
1352
- role: "ASSISTANT",
1353
- content: choices[0].content || "",
1354
- realmessageid: choices[0].messageid,
1355
- status: "sent"
1356
- });
1357
- }
1358
- aiChat.setActiveAsyncacitonId("");
1359
- } else if (msg.actionstate === 40) {
1360
- aiChat.replaceMessage({
1361
- messageid: id,
1362
- state: msg.actionstate,
1363
- type: "ERROR",
1364
- role: "ASSISTANT",
1365
- errorText: msg.actionresult,
1366
- status: "failed"
1367
- });
1368
- aiChat.setActiveAsyncacitonId("");
1369
- }
1370
- },
1374
+ onMsg,
1371
1375
  abortController,
1372
1376
  ctx,
1373
1377
  { srfactag: param.srfactag },
1374
- { ...questionRequestData }
1378
+ { ...requestData }
1375
1379
  );
1376
1380
  } catch (error) {
1377
- if (error && error.message !== this.PRE_ERROR_MESSAGE) {
1381
+ const errMsg = (error == null ? void 0 : error.message) || "";
1382
+ const asyncacitonid = aiChat.getActiveAsyncacitonId();
1383
+ if (errMsg === "network error" && asyncacitonid) {
1384
+ const resumed = await this.autoResumeChat(
1385
+ aiChat,
1386
+ ctx,
1387
+ param,
1388
+ deService,
1389
+ state,
1390
+ { asyncacitonid, sessionid, srfaiagent, srfproject },
1391
+ onMsg
1392
+ );
1393
+ if (resumed)
1394
+ return true;
1395
+ }
1396
+ if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
1378
1397
  aiChat.replaceMessage({
1379
1398
  messageid: id,
1380
1399
  state: 40,
@@ -1388,7 +1407,8 @@ class AIChatUtil {
1388
1407
  aiChat.replaceMessage(
1389
1408
  {
1390
1409
  ...lastMessage,
1391
- state: 40
1410
+ state: 40,
1411
+ errorText: ibiz.i18n.t("app.aiError")
1392
1412
  },
1393
1413
  false
1394
1414
  );
@@ -1441,77 +1461,33 @@ class AIChatUtil {
1441
1461
  state.abortController = new AbortController();
1442
1462
  const { id, abortController } = state;
1443
1463
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1444
- const resumeRequestData = { asyncacitonid: other.asyncacitonid };
1464
+ const requestData = { asyncacitonid: other.asyncacitonid };
1445
1465
  if (other.sessionid) {
1446
- Object.assign(resumeRequestData, {
1466
+ Object.assign(requestData, {
1447
1467
  sessionid: other.sessionid
1448
1468
  });
1449
1469
  }
1450
1470
  if (other.srfaiagent) {
1451
- Object.assign(resumeRequestData, {
1471
+ Object.assign(requestData, {
1452
1472
  srfaiagent: other.srfaiagent
1453
1473
  });
1454
1474
  }
1455
1475
  if (other.srfproject)
1456
- Object.assign(resumeRequestData, {
1476
+ Object.assign(requestData, {
1457
1477
  srfproject: other.srfproject
1458
1478
  });
1479
+ const onMsg = this.createChatSseHandler(aiChat, id, "");
1459
1480
  try {
1460
1481
  await deService.aiResumeSse(
1461
- (msg) => {
1462
- if (msg.actionstate === 20 && msg.actionresult) {
1463
- aiChat.isLoading.value = true;
1464
- if (!aiChat.getActiveAsyncacitonId()) {
1465
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
1466
- }
1467
- aiChat.addMessage({
1468
- messageid: id,
1469
- state: msg.actionstate,
1470
- type: "DEFAULT",
1471
- role: "ASSISTANT",
1472
- content: msg.actionresult,
1473
- status: "pending"
1474
- });
1475
- } else if (msg.actionstate === 30 && msg.actionresult) {
1476
- const result = JSON.parse(msg.actionresult);
1477
- if (result.usage) {
1478
- aiChat.updateMsgUsage(id, result.usage);
1479
- }
1480
- if (result.files) {
1481
- aiChat.updateMsgOutputFiles(id, result.files);
1482
- }
1483
- const choices = result.choices;
1484
- if (choices && choices.length > 0) {
1485
- aiChat.replaceMessage({
1486
- messageid: id,
1487
- state: msg.actionstate,
1488
- type: "DEFAULT",
1489
- role: "ASSISTANT",
1490
- content: choices[0].content || "",
1491
- realmessageid: choices[0].messageid,
1492
- status: "sent"
1493
- });
1494
- }
1495
- aiChat.setActiveAsyncacitonId("");
1496
- } else if (msg.actionstate === 40) {
1497
- aiChat.replaceMessage({
1498
- messageid: id,
1499
- state: msg.actionstate,
1500
- type: "ERROR",
1501
- role: "ASSISTANT",
1502
- errorText: msg.actionresult,
1503
- status: "failed"
1504
- });
1505
- aiChat.setActiveAsyncacitonId("");
1506
- }
1507
- },
1482
+ onMsg,
1508
1483
  abortController,
1509
1484
  ctx,
1510
1485
  { srfactag: param.srfactag },
1511
- { ...resumeRequestData }
1486
+ { ...requestData }
1512
1487
  );
1513
1488
  } catch (error) {
1514
- if (error && error.message !== this.NONE_ERROR_MESSAGE) {
1489
+ const errMsg = (error == null ? void 0 : error.message) || "";
1490
+ if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
1515
1491
  if (error && error.message !== this.PRE_ERROR_MESSAGE) {
1516
1492
  aiChat.replaceMessage({
1517
1493
  messageid: id,
@@ -1526,7 +1502,8 @@ class AIChatUtil {
1526
1502
  aiChat.replaceMessage(
1527
1503
  {
1528
1504
  ...lastMessage,
1529
- state: 40
1505
+ state: 40,
1506
+ errorText: ibiz.i18n.t("app.aiError")
1530
1507
  },
1531
1508
  false
1532
1509
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/vue3-components",
3
- "version": "0.7.41-alpha.165",
3
+ "version": "0.7.41-alpha.166",
4
4
  "description": "web端组件库(vue3)",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.mjs",
@@ -31,16 +31,16 @@
31
31
  "dependencies": {
32
32
  "@amap/amap-jsapi-loader": "^1.0.1",
33
33
  "@floating-ui/dom": "^1.5.3",
34
- "@ibiz-template-plugin/ai-chat": "^0.0.132",
34
+ "@ibiz-template-plugin/ai-chat": "^0.0.133",
35
35
  "@ibiz-template-plugin/gantt": "0.1.8-alpha.468",
36
36
  "@ibiz-template-plugin/bi-report": "0.0.32",
37
37
  "@ibiz-template-plugin/data-view": "0.0.8",
38
38
  "@ibiz-template/core": "0.7.41-alpha.152",
39
39
  "@ibiz-template/devtool": "0.0.18",
40
- "@ibiz-template/model-helper": "0.7.41-alpha.156",
41
- "@ibiz-template/runtime": "0.7.41-alpha.156",
40
+ "@ibiz-template/model-helper": "0.7.41-alpha.157",
41
+ "@ibiz-template/runtime": "0.7.41-alpha.157",
42
42
  "@ibiz-template/theme": "0.7.39",
43
- "@ibiz-template/vue3-util": "0.7.41-alpha.156",
43
+ "@ibiz-template/vue3-util": "0.7.41-alpha.157",
44
44
  "@ibiz-template/web-theme": "3.16.0",
45
45
  "@ibiz/model-core": "^0.1.89",
46
46
  "@imengyu/vue3-context-menu": "^1.3.5",