@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
@@ -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聊天对象
@@ -32,6 +159,81 @@ class AIChatUtil {
32
159
  const chatInstance = module.chat || module.default.chat;
33
160
  return chatInstance;
34
161
  }
162
+ /**
163
+ * @description 获取AI聊天工具(防止全屏模式下消息弹框、确认弹框、通知弹框被隐藏,添加appendTo参数)
164
+ * @returns {*} {IData}
165
+ * @memberof AIChatUtil
166
+ */
167
+ getAIChatUtils() {
168
+ return {
169
+ message: {
170
+ info: (msg, duration, closable, options) => ibiz.message.info(msg, duration, closable, {
171
+ appendTo: document.fullscreenElement,
172
+ ...options
173
+ }),
174
+ success: (msg, duration, closable, options) => ibiz.message.success(msg, duration, closable, {
175
+ appendTo: document.fullscreenElement,
176
+ ...options
177
+ }),
178
+ warning: (msg, duration, closable, options) => ibiz.message.warning(msg, duration, closable, {
179
+ appendTo: document.fullscreenElement,
180
+ ...options
181
+ }),
182
+ error: (msg, duration, closable, options) => ibiz.message.error(msg, duration, closable, {
183
+ appendTo: document.fullscreenElement,
184
+ ...options
185
+ })
186
+ },
187
+ confirm: {
188
+ info: (args) => ibiz.confirm.info({
189
+ options: {
190
+ appendTo: document.fullscreenElement
191
+ },
192
+ ...args
193
+ }),
194
+ success: (args) => ibiz.confirm.success({
195
+ options: {
196
+ appendTo: document.fullscreenElement
197
+ },
198
+ ...args
199
+ }),
200
+ warning: (args) => ibiz.confirm.warning({
201
+ options: {
202
+ appendTo: document.fullscreenElement
203
+ },
204
+ ...args
205
+ }),
206
+ error: (args) => ibiz.confirm.error({
207
+ options: {
208
+ appendTo: document.fullscreenElement
209
+ },
210
+ ...args
211
+ })
212
+ },
213
+ notification: {
214
+ default: (args) => ibiz.notification.default({
215
+ appendTo: document.fullscreenElement || "",
216
+ ...args
217
+ }),
218
+ info: (args) => ibiz.notification.info({
219
+ appendTo: document.fullscreenElement || "",
220
+ ...args
221
+ }),
222
+ success: (args) => ibiz.notification.success({
223
+ appendTo: document.fullscreenElement || "",
224
+ ...args
225
+ }),
226
+ warning: (args) => ibiz.notification.warning({
227
+ appendTo: document.fullscreenElement || "",
228
+ ...args
229
+ }),
230
+ error: (args) => ibiz.notification.error({
231
+ appendTo: document.fullscreenElement || "",
232
+ ...args
233
+ })
234
+ }
235
+ };
236
+ }
35
237
  /**
36
238
  * 获取编辑器扩展AI聊天参数
37
239
  * @param editorParams
@@ -113,7 +315,10 @@ class AIChatUtil {
113
315
  topicOptions.beforeDelete = async (title, description) => {
114
316
  const result = await ibiz.confirm.warning({
115
317
  title,
116
- desc: description
318
+ desc: description,
319
+ options: {
320
+ appendTo: document.fullscreenElement
321
+ }
117
322
  });
118
323
  return result;
119
324
  };
@@ -129,7 +334,8 @@ class AIChatUtil {
129
334
  const chatOptions = {
130
335
  locale: ibiz.i18n.getLang(),
131
336
  enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
132
- projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
337
+ projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
338
+ selectAIProjectId: editorParams.srfselectaiprojectid
133
339
  };
134
340
  if (editorParams.srfaiappendcurdata) {
135
341
  chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
@@ -340,37 +546,37 @@ class AIChatUtil {
340
546
  return true;
341
547
  };
342
548
  chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
343
- let updateFlag = true;
344
549
  const state = getChatState(aiChat);
345
550
  state.id = qxUtil.createUUID();
346
551
  state.abortController = new AbortController();
347
552
  const { id, abortController } = state;
348
553
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
554
+ const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
349
555
  try {
350
- const questionRequestData = {
556
+ const requestData = {
351
557
  messages: arr,
352
558
  sessionid: sessionid2
353
559
  };
354
560
  if (srfaiagent)
355
- questionRequestData.srfaiagent = srfaiagent;
561
+ requestData.srfaiagent = srfaiagent;
356
562
  if (srfmode)
357
- questionRequestData.mode = srfmode;
563
+ requestData.mode = srfmode;
358
564
  if (srfscope)
359
- questionRequestData.srfscope = srfscope;
565
+ requestData.srfscope = srfscope;
360
566
  if (srfproject)
361
- questionRequestData.srfproject = srfproject;
567
+ requestData.srfproject = srfproject;
362
568
  if (srfknowledgebases)
363
- questionRequestData.knowledgebases = srfknowledgebases;
569
+ requestData.knowledgebases = srfknowledgebases;
364
570
  if (srfaiagentconfig) {
365
- Object.assign(questionRequestData, srfaiagentconfig);
571
+ Object.assign(requestData, srfaiagentconfig);
366
572
  }
367
573
  if (mcpservers) {
368
- Object.assign(questionRequestData, {
574
+ Object.assign(requestData, {
369
575
  mcpservers
370
576
  });
371
577
  }
372
578
  if (sessionmeta) {
373
- Object.assign(questionRequestData, {
579
+ Object.assign(requestData, {
374
580
  srfuimeta: JSON.stringify(sessionmeta)
375
581
  });
376
582
  }
@@ -382,68 +588,33 @@ class AIChatUtil {
382
588
  Object.assign(extParams, { ...appendcurdata });
383
589
  }
384
590
  if (extParams && Object.keys(extParams).length > 0) {
385
- Object.assign(questionRequestData, { srfextparams: extParams });
591
+ Object.assign(requestData, { srfextparams: extParams });
386
592
  }
387
593
  aiChat.addWaitingMessage(id);
388
594
  await deService.aiChatSse(
389
- (msg) => {
390
- if (msg.actionstate === 20 && msg.actionresult) {
391
- aiChat.removeWaitingMessage(id);
392
- if (msg.asextparam && localMsgID && updateFlag) {
393
- aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
394
- updateFlag = false;
395
- }
396
- if (!aiChat.getActiveAsyncacitonId()) {
397
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
398
- }
399
- aiChat.addMessage({
400
- messageid: id,
401
- state: msg.actionstate,
402
- type: "DEFAULT",
403
- role: "ASSISTANT",
404
- content: msg.actionresult,
405
- status: "pending"
406
- });
407
- } else if (msg.actionstate === 30 && msg.actionresult) {
408
- const result = JSON.parse(msg.actionresult);
409
- if (result.usage) {
410
- aiChat.updateMsgUsage(id, result.usage);
411
- }
412
- if (result.files) {
413
- aiChat.updateMsgOutputFiles(id, result.files);
414
- }
415
- const choices = result.choices;
416
- if (choices && choices.length > 0) {
417
- aiChat.replaceMessage({
418
- messageid: id,
419
- state: msg.actionstate,
420
- type: "DEFAULT",
421
- role: "ASSISTANT",
422
- content: choices[0].content || "",
423
- realmessageid: choices[0].messageid,
424
- status: "sent"
425
- });
426
- }
427
- aiChat.setActiveAsyncacitonId("");
428
- } else if (msg.actionstate === 40) {
429
- aiChat.replaceMessage({
430
- messageid: id,
431
- state: msg.actionstate,
432
- type: "ERROR",
433
- role: "ASSISTANT",
434
- errorText: msg.actionresult,
435
- status: "failed"
436
- });
437
- aiChat.setActiveAsyncacitonId("");
438
- }
439
- },
595
+ onMsg,
440
596
  abortController,
441
597
  ctx,
442
598
  { srfactag: param.srfactag },
443
- { ...questionRequestData }
599
+ { ...requestData }
444
600
  );
445
601
  } catch (error) {
446
- 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) {
447
618
  aiChat.replaceMessage({
448
619
  messageid: id,
449
620
  state: 40,
@@ -457,7 +628,8 @@ class AIChatUtil {
457
628
  aiChat.replaceMessage(
458
629
  {
459
630
  ...lastMessage,
460
- state: 40
631
+ state: 40,
632
+ errorText: ibiz.i18n.t("app.aiError")
461
633
  },
462
634
  false
463
635
  );
@@ -510,77 +682,33 @@ class AIChatUtil {
510
682
  state.abortController = new AbortController();
511
683
  const { id, abortController } = state;
512
684
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
513
- const resumeRequestData = { asyncacitonid: other.asyncacitonid };
685
+ const requestData = { asyncacitonid: other.asyncacitonid };
514
686
  if (other.sessionid) {
515
- Object.assign(resumeRequestData, {
687
+ Object.assign(requestData, {
516
688
  sessionid: other.sessionid
517
689
  });
518
690
  }
519
691
  if (other.srfaiagent) {
520
- Object.assign(resumeRequestData, {
692
+ Object.assign(requestData, {
521
693
  srfaiagent: other.srfaiagent
522
694
  });
523
695
  }
524
696
  if (other.srfproject)
525
- Object.assign(resumeRequestData, {
697
+ Object.assign(requestData, {
526
698
  srfproject: other.srfproject
527
699
  });
700
+ const onMsg = this.createChatSseHandler(aiChat, id, "");
528
701
  try {
529
702
  await deService.aiResumeSse(
530
- (msg) => {
531
- if (msg.actionstate === 20 && msg.actionresult) {
532
- aiChat.isLoading.value = true;
533
- if (!aiChat.getActiveAsyncacitonId()) {
534
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
535
- }
536
- aiChat.addMessage({
537
- messageid: id,
538
- state: msg.actionstate,
539
- type: "DEFAULT",
540
- role: "ASSISTANT",
541
- content: msg.actionresult,
542
- status: "pending"
543
- });
544
- } else if (msg.actionstate === 30 && msg.actionresult) {
545
- const result = JSON.parse(msg.actionresult);
546
- if (result.usage) {
547
- aiChat.updateMsgUsage(id, result.usage);
548
- }
549
- if (result.files) {
550
- aiChat.updateMsgOutputFiles(id, result.files);
551
- }
552
- const choices = result.choices;
553
- if (choices && choices.length > 0) {
554
- aiChat.replaceMessage({
555
- messageid: id,
556
- state: msg.actionstate,
557
- type: "DEFAULT",
558
- role: "ASSISTANT",
559
- content: choices[0].content || "",
560
- realmessageid: choices[0].messageid,
561
- status: "sent"
562
- });
563
- }
564
- aiChat.setActiveAsyncacitonId("");
565
- } else if (msg.actionstate === 40) {
566
- aiChat.replaceMessage({
567
- messageid: id,
568
- state: msg.actionstate,
569
- type: "ERROR",
570
- role: "ASSISTANT",
571
- errorText: msg.actionresult,
572
- status: "failed"
573
- });
574
- aiChat.setActiveAsyncacitonId("");
575
- }
576
- },
703
+ onMsg,
577
704
  abortController,
578
705
  ctx,
579
706
  { srfactag: param.srfactag },
580
- { ...resumeRequestData }
707
+ { ...requestData }
581
708
  );
582
709
  } catch (error) {
583
- 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) {
584
712
  if (error && error.message !== this.PRE_ERROR_MESSAGE) {
585
713
  aiChat.replaceMessage({
586
714
  messageid: id,
@@ -595,7 +723,8 @@ class AIChatUtil {
595
723
  aiChat.replaceMessage(
596
724
  {
597
725
  ...lastMessage,
598
- state: 40
726
+ state: 40,
727
+ errorText: ibiz.i18n.t("app.aiError")
599
728
  },
600
729
  false
601
730
  );
@@ -830,11 +959,7 @@ class AIChatUtil {
830
959
  );
831
960
  }
832
961
  };
833
- chatOptions.utils = {
834
- message: ibiz.message,
835
- notification: ibiz.notification,
836
- confirm: ibiz.confirm
837
- };
962
+ chatOptions.utils = this.getAIChatUtils();
838
963
  return { containerOptions, topicOptions, chatOptions };
839
964
  }
840
965
  /**
@@ -938,7 +1063,10 @@ class AIChatUtil {
938
1063
  topicOptions.beforeDelete = async (title, description) => {
939
1064
  const result = await ibiz.confirm.warning({
940
1065
  title,
941
- desc: description
1066
+ desc: description,
1067
+ options: {
1068
+ appendTo: document.fullscreenElement
1069
+ }
942
1070
  });
943
1071
  return result;
944
1072
  };
@@ -954,8 +1082,11 @@ class AIChatUtil {
954
1082
  const chatOptions = {
955
1083
  locale: ibiz.i18n.getLang(),
956
1084
  enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
957
- projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
1085
+ projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
1086
+ selectAIProjectId: params.srfselectaiprojectid
958
1087
  };
1088
+ if (params.hasOwnProperty("srfselectaiprojectid"))
1089
+ delete params.srfselectaiprojectid;
959
1090
  if (params.hasOwnProperty("srfenableaiprojectselect"))
960
1091
  delete params.srfenableaiprojectselect;
961
1092
  if (params.hasOwnProperty("srfprojectselectplaceholder"))
@@ -1196,35 +1327,35 @@ class AIChatUtil {
1196
1327
  return true;
1197
1328
  };
1198
1329
  chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
1199
- let updateFlag = true;
1200
1330
  const state = getChatState(aiChat);
1201
1331
  state.id = qxUtil.createUUID();
1202
1332
  state.abortController = new AbortController();
1203
1333
  const { id, abortController } = state;
1204
1334
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1335
+ const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
1205
1336
  try {
1206
- const questionRequestData = {
1337
+ const requestData = {
1207
1338
  messages: arr,
1208
1339
  sessionid
1209
1340
  };
1210
1341
  if (srfaiagent)
1211
- questionRequestData.srfaiagent = srfaiagent;
1342
+ requestData.srfaiagent = srfaiagent;
1212
1343
  if (srfmode)
1213
- questionRequestData.mode = srfmode;
1344
+ requestData.mode = srfmode;
1214
1345
  if (srfscope)
1215
- questionRequestData.srfscope = srfscope;
1346
+ requestData.srfscope = srfscope;
1216
1347
  if (srfproject)
1217
- questionRequestData.srfproject = srfproject;
1348
+ requestData.srfproject = srfproject;
1218
1349
  if (srfknowledgebases)
1219
- questionRequestData.knowledgebases = srfknowledgebases;
1350
+ requestData.knowledgebases = srfknowledgebases;
1220
1351
  if (srfaiagentconfig) {
1221
- Object.assign(questionRequestData, srfaiagentconfig);
1352
+ Object.assign(requestData, srfaiagentconfig);
1222
1353
  }
1223
1354
  if (mcpservers) {
1224
- Object.assign(questionRequestData, { mcpservers });
1355
+ Object.assign(requestData, { mcpservers });
1225
1356
  }
1226
1357
  if (sessionmeta) {
1227
- Object.assign(questionRequestData, {
1358
+ Object.assign(requestData, {
1228
1359
  srfuimeta: JSON.stringify(sessionmeta)
1229
1360
  });
1230
1361
  }
@@ -1236,68 +1367,33 @@ class AIChatUtil {
1236
1367
  Object.assign(extParams, { ...appendcurdata });
1237
1368
  }
1238
1369
  if (extParams && Object.keys(extParams).length > 0) {
1239
- Object.assign(questionRequestData, { srfextparams: extParams });
1370
+ Object.assign(requestData, { srfextparams: extParams });
1240
1371
  }
1241
1372
  aiChat.addWaitingMessage(id);
1242
1373
  await deService.aiChatSse(
1243
- (msg) => {
1244
- if (msg.actionstate === 20 && msg.actionresult) {
1245
- aiChat.removeWaitingMessage(id);
1246
- if (msg.asextparam && localMsgID && updateFlag) {
1247
- aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
1248
- updateFlag = false;
1249
- }
1250
- if (!aiChat.getActiveAsyncacitonId()) {
1251
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
1252
- }
1253
- aiChat.addMessage({
1254
- messageid: id,
1255
- state: msg.actionstate,
1256
- type: "DEFAULT",
1257
- role: "ASSISTANT",
1258
- content: msg.actionresult,
1259
- status: "pending"
1260
- });
1261
- } else if (msg.actionstate === 30 && msg.actionresult) {
1262
- const result = JSON.parse(msg.actionresult);
1263
- if (result.usage) {
1264
- aiChat.updateMsgUsage(id, result.usage);
1265
- }
1266
- if (result.files) {
1267
- aiChat.updateMsgOutputFiles(id, result.files);
1268
- }
1269
- const choices = result.choices;
1270
- if (choices && choices.length > 0) {
1271
- aiChat.replaceMessage({
1272
- messageid: id,
1273
- state: msg.actionstate,
1274
- type: "DEFAULT",
1275
- role: "ASSISTANT",
1276
- content: choices[0].content || "",
1277
- realmessageid: choices[0].messageid,
1278
- status: "sent"
1279
- });
1280
- }
1281
- aiChat.setActiveAsyncacitonId("");
1282
- } else if (msg.actionstate === 40) {
1283
- aiChat.replaceMessage({
1284
- messageid: id,
1285
- state: msg.actionstate,
1286
- type: "ERROR",
1287
- role: "ASSISTANT",
1288
- errorText: msg.actionresult,
1289
- status: "failed"
1290
- });
1291
- aiChat.setActiveAsyncacitonId("");
1292
- }
1293
- },
1374
+ onMsg,
1294
1375
  abortController,
1295
1376
  ctx,
1296
1377
  { srfactag: param.srfactag },
1297
- { ...questionRequestData }
1378
+ { ...requestData }
1298
1379
  );
1299
1380
  } catch (error) {
1300
- 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) {
1301
1397
  aiChat.replaceMessage({
1302
1398
  messageid: id,
1303
1399
  state: 40,
@@ -1311,7 +1407,8 @@ class AIChatUtil {
1311
1407
  aiChat.replaceMessage(
1312
1408
  {
1313
1409
  ...lastMessage,
1314
- state: 40
1410
+ state: 40,
1411
+ errorText: ibiz.i18n.t("app.aiError")
1315
1412
  },
1316
1413
  false
1317
1414
  );
@@ -1364,77 +1461,33 @@ class AIChatUtil {
1364
1461
  state.abortController = new AbortController();
1365
1462
  const { id, abortController } = state;
1366
1463
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1367
- const resumeRequestData = { asyncacitonid: other.asyncacitonid };
1464
+ const requestData = { asyncacitonid: other.asyncacitonid };
1368
1465
  if (other.sessionid) {
1369
- Object.assign(resumeRequestData, {
1466
+ Object.assign(requestData, {
1370
1467
  sessionid: other.sessionid
1371
1468
  });
1372
1469
  }
1373
1470
  if (other.srfaiagent) {
1374
- Object.assign(resumeRequestData, {
1471
+ Object.assign(requestData, {
1375
1472
  srfaiagent: other.srfaiagent
1376
1473
  });
1377
1474
  }
1378
1475
  if (other.srfproject)
1379
- Object.assign(resumeRequestData, {
1476
+ Object.assign(requestData, {
1380
1477
  srfproject: other.srfproject
1381
1478
  });
1479
+ const onMsg = this.createChatSseHandler(aiChat, id, "");
1382
1480
  try {
1383
1481
  await deService.aiResumeSse(
1384
- (msg) => {
1385
- if (msg.actionstate === 20 && msg.actionresult) {
1386
- aiChat.isLoading.value = true;
1387
- if (!aiChat.getActiveAsyncacitonId()) {
1388
- aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
1389
- }
1390
- aiChat.addMessage({
1391
- messageid: id,
1392
- state: msg.actionstate,
1393
- type: "DEFAULT",
1394
- role: "ASSISTANT",
1395
- content: msg.actionresult,
1396
- status: "pending"
1397
- });
1398
- } else if (msg.actionstate === 30 && msg.actionresult) {
1399
- const result = JSON.parse(msg.actionresult);
1400
- if (result.usage) {
1401
- aiChat.updateMsgUsage(id, result.usage);
1402
- }
1403
- if (result.files) {
1404
- aiChat.updateMsgOutputFiles(id, result.files);
1405
- }
1406
- const choices = result.choices;
1407
- if (choices && choices.length > 0) {
1408
- aiChat.replaceMessage({
1409
- messageid: id,
1410
- state: msg.actionstate,
1411
- type: "DEFAULT",
1412
- role: "ASSISTANT",
1413
- content: choices[0].content || "",
1414
- realmessageid: choices[0].messageid,
1415
- status: "sent"
1416
- });
1417
- }
1418
- aiChat.setActiveAsyncacitonId("");
1419
- } else if (msg.actionstate === 40) {
1420
- aiChat.replaceMessage({
1421
- messageid: id,
1422
- state: msg.actionstate,
1423
- type: "ERROR",
1424
- role: "ASSISTANT",
1425
- errorText: msg.actionresult,
1426
- status: "failed"
1427
- });
1428
- aiChat.setActiveAsyncacitonId("");
1429
- }
1430
- },
1482
+ onMsg,
1431
1483
  abortController,
1432
1484
  ctx,
1433
1485
  { srfactag: param.srfactag },
1434
- { ...resumeRequestData }
1486
+ { ...requestData }
1435
1487
  );
1436
1488
  } catch (error) {
1437
- 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) {
1438
1491
  if (error && error.message !== this.PRE_ERROR_MESSAGE) {
1439
1492
  aiChat.replaceMessage({
1440
1493
  messageid: id,
@@ -1449,7 +1502,8 @@ class AIChatUtil {
1449
1502
  aiChat.replaceMessage(
1450
1503
  {
1451
1504
  ...lastMessage,
1452
- state: 40
1505
+ state: 40,
1506
+ errorText: ibiz.i18n.t("app.aiError")
1453
1507
  },
1454
1508
  false
1455
1509
  );
@@ -1686,11 +1740,7 @@ class AIChatUtil {
1686
1740
  );
1687
1741
  }
1688
1742
  };
1689
- chatOptions.utils = {
1690
- message: ibiz.message,
1691
- notification: ibiz.notification,
1692
- confirm: ibiz.confirm
1693
- };
1743
+ chatOptions.utils = this.getAIChatUtils();
1694
1744
  return { containerOptions, topicOptions, chatOptions };
1695
1745
  }
1696
1746
  /**
@@ -2108,6 +2158,15 @@ class AIChatUtil {
2108
2158
  );
2109
2159
  return response.data;
2110
2160
  };
2161
+ fileSystemOptions.unZipFile = async (ctx, param, other) => {
2162
+ const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, param.appDataEntityId);
2163
+ const response = await deService.aiChatProject(
2164
+ ctx,
2165
+ { srfactag: param.srfactag },
2166
+ { action: "UNZIP", ...other }
2167
+ );
2168
+ return response.data;
2169
+ };
2111
2170
  fileSystemOptions.readFile = async (ctx, param, other) => {
2112
2171
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, param.appDataEntityId);
2113
2172
  const response = await deService.aiChatProject(