@ibiz-template/vue3-components 0.7.41-alpha.164 → 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 (34) hide show
  1. package/dist/{index-DWRQ9IG6.js → index-CCoBeNIV.js} +6 -6
  2. package/dist/{index.es-BJBzhTrX.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-DtLGL_ju.js → wang-editor-B0ZpE6o-.js} +1 -1
  6. package/dist/{xlsx-util-k3HzMMjk.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 +311 -252
  14. package/es/util/message-util/message-util.mjs +12 -8
  15. package/es/util/notification-util/notification-util.mjs +1 -0
  16. package/lib/editor/index.cjs +8 -0
  17. package/lib/editor/work-space/embed-work-space/embed-work-space.cjs +77 -0
  18. package/lib/editor/work-space/embed-work-space/embed-work-space.css +1 -0
  19. package/lib/editor/work-space/embed-work-space.controller.cjs +64 -0
  20. package/lib/editor/work-space/embed-work-space.provider.cjs +24 -0
  21. package/lib/editor/work-space/index.cjs +11 -0
  22. package/lib/util/ai-chat-util/ai-chat-util.cjs +311 -252
  23. package/lib/util/message-util/message-util.cjs +12 -8
  24. package/lib/util/notification-util/notification-util.cjs +1 -0
  25. package/package.json +5 -5
  26. package/src/editor/index.ts +7 -1
  27. package/src/editor/work-space/embed-work-space/embed-work-space.scss +8 -0
  28. package/src/editor/work-space/embed-work-space/embed-work-space.tsx +78 -0
  29. package/src/editor/work-space/embed-work-space.controller.ts +70 -0
  30. package/src/editor/work-space/embed-work-space.provider.ts +28 -0
  31. package/src/editor/work-space/index.ts +3 -0
  32. package/src/util/ai-chat-util/ai-chat-util.ts +391 -287
  33. package/src/util/message-util/message-util.ts +8 -0
  34. package/src/util/notification-util/notification-util.ts +1 -0
@@ -21,6 +21,133 @@ class AIChatUtil {
21
21
  __publicField(this, "PRE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: application/json;charset=UTF-8");
22
22
  // 无流内容回来
23
23
  __publicField(this, "NONE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: null");
24
+ // 网络中断自动续传的最大重试次数
25
+ __publicField(this, "AUTO_RESUME_MAX_RETRY", 3);
26
+ // 网络中断自动续传的退避基数(毫秒),按 1s/2s/4s 指数退避
27
+ __publicField(this, "AUTO_RESUME_BACKOFF_BASE", 1e3);
28
+ }
29
+ /**
30
+ * @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
31
+ * @param {any} aiChat 单实例聊天总控
32
+ * @param {string} id 本次问答的流式消息 id
33
+ * @param {string} localMsgID 本地用户消息 id(用于回填真实消息 id;为空串时为恢复会话场景,状态 20 走 isLoading 加载分支)
34
+ * @return {*} {(msg: IPortalAsyncAction) => void}
35
+ * @memberof AIChatUtil
36
+ */
37
+ createChatSseHandler(aiChat, id, localMsgID) {
38
+ let updateFlag = true;
39
+ return (msg) => {
40
+ if (msg.actionstate === 20 && msg.actionresult) {
41
+ if (localMsgID) {
42
+ aiChat.removeWaitingMessage(id);
43
+ if (msg.asextparam && updateFlag) {
44
+ aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
45
+ updateFlag = false;
46
+ }
47
+ } else {
48
+ aiChat.isLoading.value = true;
49
+ }
50
+ if (!aiChat.getActiveAsyncacitonId()) {
51
+ aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
52
+ }
53
+ aiChat.addMessage({
54
+ messageid: id,
55
+ state: msg.actionstate,
56
+ type: "DEFAULT",
57
+ role: "ASSISTANT",
58
+ content: msg.actionresult,
59
+ status: "pending"
60
+ });
61
+ } else if (msg.actionstate === 30 && msg.actionresult) {
62
+ const result = JSON.parse(msg.actionresult);
63
+ if (result.usage) {
64
+ aiChat.updateMsgUsage(id, result.usage);
65
+ }
66
+ if (result.files) {
67
+ aiChat.updateMsgOutputFiles(id, result.files);
68
+ }
69
+ const choices = result.choices;
70
+ if (choices && choices.length > 0) {
71
+ aiChat.replaceMessage({
72
+ messageid: id,
73
+ state: msg.actionstate,
74
+ type: "DEFAULT",
75
+ role: "ASSISTANT",
76
+ content: choices[0].content || "",
77
+ realmessageid: choices[0].messageid,
78
+ status: "sent"
79
+ });
80
+ }
81
+ aiChat.setActiveAsyncacitonId("");
82
+ } else if (msg.actionstate === 40) {
83
+ aiChat.replaceMessage({
84
+ messageid: id,
85
+ state: msg.actionstate,
86
+ type: "ERROR",
87
+ role: "ASSISTANT",
88
+ errorText: msg.actionresult,
89
+ status: "failed"
90
+ });
91
+ aiChat.setActiveAsyncacitonId("");
92
+ }
93
+ };
94
+ }
95
+ /**
96
+ * @description 网络中断(network error)后按 asyncacitonid 自动续传,指数退避重试;成功返回 true,不可恢复/重试耗尽返回 false 交回调用方走既有错误处理
97
+ * @param {any} aiChat 单实例聊天总控
98
+ * @param {IContext} ctx 上下文
99
+ * @param {IParams} param 视图参数
100
+ * @param {*} deService 实体服务
101
+ * @param {{ id: string; abortController: AbortController }} state 聊天实例提问状态(WeakMap 持有的同一对象引用)
102
+ * @param {{ asyncacitonid: string; sessionid?: string; srfaiagent?: string; srfproject?: string }} resumeInfo 续传参数
103
+ * @param {(msg: IPortalAsyncAction) => void} onMsg SSE 流式消息处理回调
104
+ * @return {*} {Promise<boolean>} 是否续传成功
105
+ * @memberof AIChatUtil
106
+ */
107
+ async autoResumeChat(aiChat, ctx, param, deService, state, resumeInfo, onMsg) {
108
+ var _a;
109
+ (_a = state.abortController) == null ? void 0 : _a.abort();
110
+ state.abortController = new AbortController();
111
+ for (let attempt = 1; attempt <= this.AUTO_RESUME_MAX_RETRY; attempt++) {
112
+ try {
113
+ await new Promise((resolve) => {
114
+ setTimeout(
115
+ resolve,
116
+ this.AUTO_RESUME_BACKOFF_BASE * 2 ** (attempt - 1)
117
+ );
118
+ });
119
+ const resumeRequestData = {
120
+ asyncacitonid: resumeInfo.asyncacitonid
121
+ };
122
+ if (resumeInfo.sessionid) {
123
+ resumeRequestData.sessionid = resumeInfo.sessionid;
124
+ }
125
+ if (resumeInfo.srfaiagent) {
126
+ resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
127
+ }
128
+ if (resumeInfo.srfproject) {
129
+ resumeRequestData.srfproject = resumeInfo.srfproject;
130
+ }
131
+ await deService.aiResumeSse(
132
+ onMsg,
133
+ state.abortController,
134
+ ctx,
135
+ { srfactag: param.srfactag },
136
+ { ...resumeRequestData }
137
+ );
138
+ return true;
139
+ } catch (resumeError) {
140
+ const resumeMsg = (resumeError == null ? void 0 : resumeError.message) || "";
141
+ if ((resumeError == null ? void 0 : resumeError.name) === "AbortError") {
142
+ return false;
143
+ }
144
+ if (resumeMsg === this.NONE_ERROR_MESSAGE) {
145
+ aiChat.setActiveAsyncacitonId("");
146
+ return false;
147
+ }
148
+ }
149
+ }
150
+ return false;
24
151
  }
25
152
  /**
26
153
  * 获取AI聊天对象
@@ -30,6 +157,81 @@ class AIChatUtil {
30
157
  const chatInstance = module.chat || module.default.chat;
31
158
  return chatInstance;
32
159
  }
160
+ /**
161
+ * @description 获取AI聊天工具(防止全屏模式下消息弹框、确认弹框、通知弹框被隐藏,添加appendTo参数)
162
+ * @returns {*} {IData}
163
+ * @memberof AIChatUtil
164
+ */
165
+ getAIChatUtils() {
166
+ return {
167
+ message: {
168
+ info: (msg, duration, closable, options) => ibiz.message.info(msg, duration, closable, {
169
+ appendTo: document.fullscreenElement,
170
+ ...options
171
+ }),
172
+ success: (msg, duration, closable, options) => ibiz.message.success(msg, duration, closable, {
173
+ appendTo: document.fullscreenElement,
174
+ ...options
175
+ }),
176
+ warning: (msg, duration, closable, options) => ibiz.message.warning(msg, duration, closable, {
177
+ appendTo: document.fullscreenElement,
178
+ ...options
179
+ }),
180
+ error: (msg, duration, closable, options) => ibiz.message.error(msg, duration, closable, {
181
+ appendTo: document.fullscreenElement,
182
+ ...options
183
+ })
184
+ },
185
+ confirm: {
186
+ info: (args) => ibiz.confirm.info({
187
+ options: {
188
+ appendTo: document.fullscreenElement
189
+ },
190
+ ...args
191
+ }),
192
+ success: (args) => ibiz.confirm.success({
193
+ options: {
194
+ appendTo: document.fullscreenElement
195
+ },
196
+ ...args
197
+ }),
198
+ warning: (args) => ibiz.confirm.warning({
199
+ options: {
200
+ appendTo: document.fullscreenElement
201
+ },
202
+ ...args
203
+ }),
204
+ error: (args) => ibiz.confirm.error({
205
+ options: {
206
+ appendTo: document.fullscreenElement
207
+ },
208
+ ...args
209
+ })
210
+ },
211
+ notification: {
212
+ default: (args) => ibiz.notification.default({
213
+ appendTo: document.fullscreenElement || "",
214
+ ...args
215
+ }),
216
+ info: (args) => ibiz.notification.info({
217
+ appendTo: document.fullscreenElement || "",
218
+ ...args
219
+ }),
220
+ success: (args) => ibiz.notification.success({
221
+ appendTo: document.fullscreenElement || "",
222
+ ...args
223
+ }),
224
+ warning: (args) => ibiz.notification.warning({
225
+ appendTo: document.fullscreenElement || "",
226
+ ...args
227
+ }),
228
+ error: (args) => ibiz.notification.error({
229
+ appendTo: document.fullscreenElement || "",
230
+ ...args
231
+ })
232
+ }
233
+ };
234
+ }
33
235
  /**
34
236
  * 获取编辑器扩展AI聊天参数
35
237
  * @param editorParams
@@ -111,7 +313,10 @@ class AIChatUtil {
111
313
  topicOptions.beforeDelete = async (title, description) => {
112
314
  const result = await ibiz.confirm.warning({
113
315
  title,
114
- desc: description
316
+ desc: description,
317
+ options: {
318
+ appendTo: document.fullscreenElement
319
+ }
115
320
  });
116
321
  return result;
117
322
  };
@@ -127,7 +332,8 @@ class AIChatUtil {
127
332
  const chatOptions = {
128
333
  locale: ibiz.i18n.getLang(),
129
334
  enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
130
- projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
335
+ projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
336
+ selectAIProjectId: editorParams.srfselectaiprojectid
131
337
  };
132
338
  if (editorParams.srfaiappendcurdata) {
133
339
  chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
@@ -338,37 +544,37 @@ class AIChatUtil {
338
544
  return true;
339
545
  };
340
546
  chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
341
- let updateFlag = true;
342
547
  const state = getChatState(aiChat);
343
548
  state.id = createUUID();
344
549
  state.abortController = new AbortController();
345
550
  const { id, abortController } = state;
346
551
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
552
+ const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
347
553
  try {
348
- const questionRequestData = {
554
+ const requestData = {
349
555
  messages: arr,
350
556
  sessionid: sessionid2
351
557
  };
352
558
  if (srfaiagent)
353
- questionRequestData.srfaiagent = srfaiagent;
559
+ requestData.srfaiagent = srfaiagent;
354
560
  if (srfmode)
355
- questionRequestData.mode = srfmode;
561
+ requestData.mode = srfmode;
356
562
  if (srfscope)
357
- questionRequestData.srfscope = srfscope;
563
+ requestData.srfscope = srfscope;
358
564
  if (srfproject)
359
- questionRequestData.srfproject = srfproject;
565
+ requestData.srfproject = srfproject;
360
566
  if (srfknowledgebases)
361
- questionRequestData.knowledgebases = srfknowledgebases;
567
+ requestData.knowledgebases = srfknowledgebases;
362
568
  if (srfaiagentconfig) {
363
- Object.assign(questionRequestData, srfaiagentconfig);
569
+ Object.assign(requestData, srfaiagentconfig);
364
570
  }
365
571
  if (mcpservers) {
366
- Object.assign(questionRequestData, {
572
+ Object.assign(requestData, {
367
573
  mcpservers
368
574
  });
369
575
  }
370
576
  if (sessionmeta) {
371
- Object.assign(questionRequestData, {
577
+ Object.assign(requestData, {
372
578
  srfuimeta: JSON.stringify(sessionmeta)
373
579
  });
374
580
  }
@@ -380,68 +586,33 @@ class AIChatUtil {
380
586
  Object.assign(extParams, { ...appendcurdata });
381
587
  }
382
588
  if (extParams && Object.keys(extParams).length > 0) {
383
- Object.assign(questionRequestData, { srfextparams: extParams });
589
+ Object.assign(requestData, { srfextparams: extParams });
384
590
  }
385
591
  aiChat.addWaitingMessage(id);
386
592
  await deService.aiChatSse(
387
- (msg) => {
388
- if (msg.actionstate === 20 && msg.actionresult) {
389
- aiChat.removeWaitingMessage(id);
390
- if (msg.asextparam && localMsgID && updateFlag) {
391
- aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
392
- updateFlag = false;
393
- }
394
- if (!aiChat.getActiveAsyncacitonId()) {
395
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
396
- }
397
- aiChat.addMessage({
398
- messageid: id,
399
- state: msg.actionstate,
400
- type: "DEFAULT",
401
- role: "ASSISTANT",
402
- content: msg.actionresult,
403
- status: "pending"
404
- });
405
- } else if (msg.actionstate === 30 && msg.actionresult) {
406
- const result = JSON.parse(msg.actionresult);
407
- if (result.usage) {
408
- aiChat.updateMsgUsage(id, result.usage);
409
- }
410
- if (result.files) {
411
- aiChat.updateMsgOutputFiles(id, result.files);
412
- }
413
- const choices = result.choices;
414
- if (choices && choices.length > 0) {
415
- aiChat.replaceMessage({
416
- messageid: id,
417
- state: msg.actionstate,
418
- type: "DEFAULT",
419
- role: "ASSISTANT",
420
- content: choices[0].content || "",
421
- realmessageid: choices[0].messageid,
422
- status: "sent"
423
- });
424
- }
425
- aiChat.setActiveAsyncacitonId("");
426
- } else if (msg.actionstate === 40) {
427
- aiChat.replaceMessage({
428
- messageid: id,
429
- state: msg.actionstate,
430
- type: "ERROR",
431
- role: "ASSISTANT",
432
- errorText: msg.actionresult,
433
- status: "failed"
434
- });
435
- aiChat.setActiveAsyncacitonId("");
436
- }
437
- },
593
+ onMsg,
438
594
  abortController,
439
595
  ctx,
440
596
  { srfactag: param.srfactag },
441
- { ...questionRequestData }
597
+ { ...requestData }
442
598
  );
443
599
  } catch (error) {
444
- if (error && error.message !== this.PRE_ERROR_MESSAGE) {
600
+ const errMsg = (error == null ? void 0 : error.message) || "";
601
+ const asyncacitonid = aiChat.getActiveAsyncacitonId();
602
+ if (errMsg === "network error" && asyncacitonid) {
603
+ const resumed = await this.autoResumeChat(
604
+ aiChat,
605
+ ctx,
606
+ param,
607
+ deService,
608
+ state,
609
+ { asyncacitonid, sessionid: sessionid2, srfaiagent, srfproject },
610
+ onMsg
611
+ );
612
+ if (resumed)
613
+ return true;
614
+ }
615
+ if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
445
616
  aiChat.replaceMessage({
446
617
  messageid: id,
447
618
  state: 40,
@@ -455,7 +626,8 @@ class AIChatUtil {
455
626
  aiChat.replaceMessage(
456
627
  {
457
628
  ...lastMessage,
458
- state: 40
629
+ state: 40,
630
+ errorText: ibiz.i18n.t("app.aiError")
459
631
  },
460
632
  false
461
633
  );
@@ -508,77 +680,33 @@ class AIChatUtil {
508
680
  state.abortController = new AbortController();
509
681
  const { id, abortController } = state;
510
682
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
511
- const resumeRequestData = { asyncacitonid: other.asyncacitonid };
683
+ const requestData = { asyncacitonid: other.asyncacitonid };
512
684
  if (other.sessionid) {
513
- Object.assign(resumeRequestData, {
685
+ Object.assign(requestData, {
514
686
  sessionid: other.sessionid
515
687
  });
516
688
  }
517
689
  if (other.srfaiagent) {
518
- Object.assign(resumeRequestData, {
690
+ Object.assign(requestData, {
519
691
  srfaiagent: other.srfaiagent
520
692
  });
521
693
  }
522
694
  if (other.srfproject)
523
- Object.assign(resumeRequestData, {
695
+ Object.assign(requestData, {
524
696
  srfproject: other.srfproject
525
697
  });
698
+ const onMsg = this.createChatSseHandler(aiChat, id, "");
526
699
  try {
527
700
  await deService.aiResumeSse(
528
- (msg) => {
529
- if (msg.actionstate === 20 && msg.actionresult) {
530
- aiChat.isLoading.value = true;
531
- if (!aiChat.getActiveAsyncacitonId()) {
532
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
533
- }
534
- aiChat.addMessage({
535
- messageid: id,
536
- state: msg.actionstate,
537
- type: "DEFAULT",
538
- role: "ASSISTANT",
539
- content: msg.actionresult,
540
- status: "pending"
541
- });
542
- } else if (msg.actionstate === 30 && msg.actionresult) {
543
- const result = JSON.parse(msg.actionresult);
544
- if (result.usage) {
545
- aiChat.updateMsgUsage(id, result.usage);
546
- }
547
- if (result.files) {
548
- aiChat.updateMsgOutputFiles(id, result.files);
549
- }
550
- const choices = result.choices;
551
- if (choices && choices.length > 0) {
552
- aiChat.replaceMessage({
553
- messageid: id,
554
- state: msg.actionstate,
555
- type: "DEFAULT",
556
- role: "ASSISTANT",
557
- content: choices[0].content || "",
558
- realmessageid: choices[0].messageid,
559
- status: "sent"
560
- });
561
- }
562
- aiChat.setActiveAsyncacitonId("");
563
- } else if (msg.actionstate === 40) {
564
- aiChat.replaceMessage({
565
- messageid: id,
566
- state: msg.actionstate,
567
- type: "ERROR",
568
- role: "ASSISTANT",
569
- errorText: msg.actionresult,
570
- status: "failed"
571
- });
572
- aiChat.setActiveAsyncacitonId("");
573
- }
574
- },
701
+ onMsg,
575
702
  abortController,
576
703
  ctx,
577
704
  { srfactag: param.srfactag },
578
- { ...resumeRequestData }
705
+ { ...requestData }
579
706
  );
580
707
  } catch (error) {
581
- if (error && error.message !== this.NONE_ERROR_MESSAGE) {
708
+ const errMsg = (error == null ? void 0 : error.message) || "";
709
+ if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
582
710
  if (error && error.message !== this.PRE_ERROR_MESSAGE) {
583
711
  aiChat.replaceMessage({
584
712
  messageid: id,
@@ -593,7 +721,8 @@ class AIChatUtil {
593
721
  aiChat.replaceMessage(
594
722
  {
595
723
  ...lastMessage,
596
- state: 40
724
+ state: 40,
725
+ errorText: ibiz.i18n.t("app.aiError")
597
726
  },
598
727
  false
599
728
  );
@@ -828,11 +957,7 @@ class AIChatUtil {
828
957
  );
829
958
  }
830
959
  };
831
- chatOptions.utils = {
832
- message: ibiz.message,
833
- notification: ibiz.notification,
834
- confirm: ibiz.confirm
835
- };
960
+ chatOptions.utils = this.getAIChatUtils();
836
961
  return { containerOptions, topicOptions, chatOptions };
837
962
  }
838
963
  /**
@@ -936,7 +1061,10 @@ class AIChatUtil {
936
1061
  topicOptions.beforeDelete = async (title, description) => {
937
1062
  const result = await ibiz.confirm.warning({
938
1063
  title,
939
- desc: description
1064
+ desc: description,
1065
+ options: {
1066
+ appendTo: document.fullscreenElement
1067
+ }
940
1068
  });
941
1069
  return result;
942
1070
  };
@@ -952,8 +1080,11 @@ class AIChatUtil {
952
1080
  const chatOptions = {
953
1081
  locale: ibiz.i18n.getLang(),
954
1082
  enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
955
- projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
1083
+ projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
1084
+ selectAIProjectId: params.srfselectaiprojectid
956
1085
  };
1086
+ if (params.hasOwnProperty("srfselectaiprojectid"))
1087
+ delete params.srfselectaiprojectid;
957
1088
  if (params.hasOwnProperty("srfenableaiprojectselect"))
958
1089
  delete params.srfenableaiprojectselect;
959
1090
  if (params.hasOwnProperty("srfprojectselectplaceholder"))
@@ -1194,35 +1325,35 @@ class AIChatUtil {
1194
1325
  return true;
1195
1326
  };
1196
1327
  chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
1197
- let updateFlag = true;
1198
1328
  const state = getChatState(aiChat);
1199
1329
  state.id = createUUID();
1200
1330
  state.abortController = new AbortController();
1201
1331
  const { id, abortController } = state;
1202
1332
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1333
+ const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
1203
1334
  try {
1204
- const questionRequestData = {
1335
+ const requestData = {
1205
1336
  messages: arr,
1206
1337
  sessionid
1207
1338
  };
1208
1339
  if (srfaiagent)
1209
- questionRequestData.srfaiagent = srfaiagent;
1340
+ requestData.srfaiagent = srfaiagent;
1210
1341
  if (srfmode)
1211
- questionRequestData.mode = srfmode;
1342
+ requestData.mode = srfmode;
1212
1343
  if (srfscope)
1213
- questionRequestData.srfscope = srfscope;
1344
+ requestData.srfscope = srfscope;
1214
1345
  if (srfproject)
1215
- questionRequestData.srfproject = srfproject;
1346
+ requestData.srfproject = srfproject;
1216
1347
  if (srfknowledgebases)
1217
- questionRequestData.knowledgebases = srfknowledgebases;
1348
+ requestData.knowledgebases = srfknowledgebases;
1218
1349
  if (srfaiagentconfig) {
1219
- Object.assign(questionRequestData, srfaiagentconfig);
1350
+ Object.assign(requestData, srfaiagentconfig);
1220
1351
  }
1221
1352
  if (mcpservers) {
1222
- Object.assign(questionRequestData, { mcpservers });
1353
+ Object.assign(requestData, { mcpservers });
1223
1354
  }
1224
1355
  if (sessionmeta) {
1225
- Object.assign(questionRequestData, {
1356
+ Object.assign(requestData, {
1226
1357
  srfuimeta: JSON.stringify(sessionmeta)
1227
1358
  });
1228
1359
  }
@@ -1234,68 +1365,33 @@ class AIChatUtil {
1234
1365
  Object.assign(extParams, { ...appendcurdata });
1235
1366
  }
1236
1367
  if (extParams && Object.keys(extParams).length > 0) {
1237
- Object.assign(questionRequestData, { srfextparams: extParams });
1368
+ Object.assign(requestData, { srfextparams: extParams });
1238
1369
  }
1239
1370
  aiChat.addWaitingMessage(id);
1240
1371
  await deService.aiChatSse(
1241
- (msg) => {
1242
- if (msg.actionstate === 20 && msg.actionresult) {
1243
- aiChat.removeWaitingMessage(id);
1244
- if (msg.asextparam && localMsgID && updateFlag) {
1245
- aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
1246
- updateFlag = false;
1247
- }
1248
- if (!aiChat.getActiveAsyncacitonId()) {
1249
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
1250
- }
1251
- aiChat.addMessage({
1252
- messageid: id,
1253
- state: msg.actionstate,
1254
- type: "DEFAULT",
1255
- role: "ASSISTANT",
1256
- content: msg.actionresult,
1257
- status: "pending"
1258
- });
1259
- } else if (msg.actionstate === 30 && msg.actionresult) {
1260
- const result = JSON.parse(msg.actionresult);
1261
- if (result.usage) {
1262
- aiChat.updateMsgUsage(id, result.usage);
1263
- }
1264
- if (result.files) {
1265
- aiChat.updateMsgOutputFiles(id, result.files);
1266
- }
1267
- const choices = result.choices;
1268
- if (choices && choices.length > 0) {
1269
- aiChat.replaceMessage({
1270
- messageid: id,
1271
- state: msg.actionstate,
1272
- type: "DEFAULT",
1273
- role: "ASSISTANT",
1274
- content: choices[0].content || "",
1275
- realmessageid: choices[0].messageid,
1276
- status: "sent"
1277
- });
1278
- }
1279
- aiChat.setActiveAsyncacitonId("");
1280
- } else if (msg.actionstate === 40) {
1281
- aiChat.replaceMessage({
1282
- messageid: id,
1283
- state: msg.actionstate,
1284
- type: "ERROR",
1285
- role: "ASSISTANT",
1286
- errorText: msg.actionresult,
1287
- status: "failed"
1288
- });
1289
- aiChat.setActiveAsyncacitonId("");
1290
- }
1291
- },
1372
+ onMsg,
1292
1373
  abortController,
1293
1374
  ctx,
1294
1375
  { srfactag: param.srfactag },
1295
- { ...questionRequestData }
1376
+ { ...requestData }
1296
1377
  );
1297
1378
  } catch (error) {
1298
- if (error && error.message !== this.PRE_ERROR_MESSAGE) {
1379
+ const errMsg = (error == null ? void 0 : error.message) || "";
1380
+ const asyncacitonid = aiChat.getActiveAsyncacitonId();
1381
+ if (errMsg === "network error" && asyncacitonid) {
1382
+ const resumed = await this.autoResumeChat(
1383
+ aiChat,
1384
+ ctx,
1385
+ param,
1386
+ deService,
1387
+ state,
1388
+ { asyncacitonid, sessionid, srfaiagent, srfproject },
1389
+ onMsg
1390
+ );
1391
+ if (resumed)
1392
+ return true;
1393
+ }
1394
+ if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
1299
1395
  aiChat.replaceMessage({
1300
1396
  messageid: id,
1301
1397
  state: 40,
@@ -1309,7 +1405,8 @@ class AIChatUtil {
1309
1405
  aiChat.replaceMessage(
1310
1406
  {
1311
1407
  ...lastMessage,
1312
- state: 40
1408
+ state: 40,
1409
+ errorText: ibiz.i18n.t("app.aiError")
1313
1410
  },
1314
1411
  false
1315
1412
  );
@@ -1362,77 +1459,33 @@ class AIChatUtil {
1362
1459
  state.abortController = new AbortController();
1363
1460
  const { id, abortController } = state;
1364
1461
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1365
- const resumeRequestData = { asyncacitonid: other.asyncacitonid };
1462
+ const requestData = { asyncacitonid: other.asyncacitonid };
1366
1463
  if (other.sessionid) {
1367
- Object.assign(resumeRequestData, {
1464
+ Object.assign(requestData, {
1368
1465
  sessionid: other.sessionid
1369
1466
  });
1370
1467
  }
1371
1468
  if (other.srfaiagent) {
1372
- Object.assign(resumeRequestData, {
1469
+ Object.assign(requestData, {
1373
1470
  srfaiagent: other.srfaiagent
1374
1471
  });
1375
1472
  }
1376
1473
  if (other.srfproject)
1377
- Object.assign(resumeRequestData, {
1474
+ Object.assign(requestData, {
1378
1475
  srfproject: other.srfproject
1379
1476
  });
1477
+ const onMsg = this.createChatSseHandler(aiChat, id, "");
1380
1478
  try {
1381
1479
  await deService.aiResumeSse(
1382
- (msg) => {
1383
- if (msg.actionstate === 20 && msg.actionresult) {
1384
- aiChat.isLoading.value = true;
1385
- if (!aiChat.getActiveAsyncacitonId()) {
1386
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
1387
- }
1388
- aiChat.addMessage({
1389
- messageid: id,
1390
- state: msg.actionstate,
1391
- type: "DEFAULT",
1392
- role: "ASSISTANT",
1393
- content: msg.actionresult,
1394
- status: "pending"
1395
- });
1396
- } else if (msg.actionstate === 30 && msg.actionresult) {
1397
- const result = JSON.parse(msg.actionresult);
1398
- if (result.usage) {
1399
- aiChat.updateMsgUsage(id, result.usage);
1400
- }
1401
- if (result.files) {
1402
- aiChat.updateMsgOutputFiles(id, result.files);
1403
- }
1404
- const choices = result.choices;
1405
- if (choices && choices.length > 0) {
1406
- aiChat.replaceMessage({
1407
- messageid: id,
1408
- state: msg.actionstate,
1409
- type: "DEFAULT",
1410
- role: "ASSISTANT",
1411
- content: choices[0].content || "",
1412
- realmessageid: choices[0].messageid,
1413
- status: "sent"
1414
- });
1415
- }
1416
- aiChat.setActiveAsyncacitonId("");
1417
- } else if (msg.actionstate === 40) {
1418
- aiChat.replaceMessage({
1419
- messageid: id,
1420
- state: msg.actionstate,
1421
- type: "ERROR",
1422
- role: "ASSISTANT",
1423
- errorText: msg.actionresult,
1424
- status: "failed"
1425
- });
1426
- aiChat.setActiveAsyncacitonId("");
1427
- }
1428
- },
1480
+ onMsg,
1429
1481
  abortController,
1430
1482
  ctx,
1431
1483
  { srfactag: param.srfactag },
1432
- { ...resumeRequestData }
1484
+ { ...requestData }
1433
1485
  );
1434
1486
  } catch (error) {
1435
- if (error && error.message !== this.NONE_ERROR_MESSAGE) {
1487
+ const errMsg = (error == null ? void 0 : error.message) || "";
1488
+ if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
1436
1489
  if (error && error.message !== this.PRE_ERROR_MESSAGE) {
1437
1490
  aiChat.replaceMessage({
1438
1491
  messageid: id,
@@ -1447,7 +1500,8 @@ class AIChatUtil {
1447
1500
  aiChat.replaceMessage(
1448
1501
  {
1449
1502
  ...lastMessage,
1450
- state: 40
1503
+ state: 40,
1504
+ errorText: ibiz.i18n.t("app.aiError")
1451
1505
  },
1452
1506
  false
1453
1507
  );
@@ -1684,11 +1738,7 @@ class AIChatUtil {
1684
1738
  );
1685
1739
  }
1686
1740
  };
1687
- chatOptions.utils = {
1688
- message: ibiz.message,
1689
- notification: ibiz.notification,
1690
- confirm: ibiz.confirm
1691
- };
1741
+ chatOptions.utils = this.getAIChatUtils();
1692
1742
  return { containerOptions, topicOptions, chatOptions };
1693
1743
  }
1694
1744
  /**
@@ -2106,6 +2156,15 @@ class AIChatUtil {
2106
2156
  );
2107
2157
  return response.data;
2108
2158
  };
2159
+ fileSystemOptions.unZipFile = async (ctx, param, other) => {
2160
+ const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, param.appDataEntityId);
2161
+ const response = await deService.aiChatProject(
2162
+ ctx,
2163
+ { srfactag: param.srfactag },
2164
+ { action: "UNZIP", ...other }
2165
+ );
2166
+ return response.data;
2167
+ };
2109
2168
  fileSystemOptions.readFile = async (ctx, param, other) => {
2110
2169
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, param.appDataEntityId);
2111
2170
  const response = await deService.aiChatProject(