@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.
- package/dist/{index-DWRQ9IG6.js → index-CCoBeNIV.js} +6 -6
- package/dist/{index.es-BJBzhTrX.js → index.es-D1vng-7i.js} +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/{wang-editor-DtLGL_ju.js → wang-editor-B0ZpE6o-.js} +1 -1
- package/dist/{xlsx-util-k3HzMMjk.js → xlsx-util-Djaaq9Po.js} +1 -1
- package/es/editor/index.mjs +8 -0
- package/es/editor/work-space/embed-work-space/embed-work-space.css +1 -0
- package/es/editor/work-space/embed-work-space/embed-work-space.mjs +75 -0
- package/es/editor/work-space/embed-work-space.controller.mjs +62 -0
- package/es/editor/work-space/embed-work-space.provider.mjs +22 -0
- package/es/editor/work-space/index.mjs +5 -0
- package/es/util/ai-chat-util/ai-chat-util.mjs +311 -252
- package/es/util/message-util/message-util.mjs +12 -8
- package/es/util/notification-util/notification-util.mjs +1 -0
- package/lib/editor/index.cjs +8 -0
- package/lib/editor/work-space/embed-work-space/embed-work-space.cjs +77 -0
- package/lib/editor/work-space/embed-work-space/embed-work-space.css +1 -0
- package/lib/editor/work-space/embed-work-space.controller.cjs +64 -0
- package/lib/editor/work-space/embed-work-space.provider.cjs +24 -0
- package/lib/editor/work-space/index.cjs +11 -0
- package/lib/util/ai-chat-util/ai-chat-util.cjs +311 -252
- package/lib/util/message-util/message-util.cjs +12 -8
- package/lib/util/notification-util/notification-util.cjs +1 -0
- package/package.json +5 -5
- package/src/editor/index.ts +7 -1
- package/src/editor/work-space/embed-work-space/embed-work-space.scss +8 -0
- package/src/editor/work-space/embed-work-space/embed-work-space.tsx +78 -0
- package/src/editor/work-space/embed-work-space.controller.ts +70 -0
- package/src/editor/work-space/embed-work-space.provider.ts +28 -0
- package/src/editor/work-space/index.ts +3 -0
- package/src/util/ai-chat-util/ai-chat-util.ts +391 -287
- package/src/util/message-util/message-util.ts +8 -0
- package/src/util/notification-util/notification-util.ts +1 -0
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
IControlController,
|
|
29
29
|
OpenAppViewCommand,
|
|
30
30
|
CodeListItem,
|
|
31
|
+
ConfirmParams,
|
|
32
|
+
NotificationParams,
|
|
31
33
|
} from '@ibiz-template/runtime';
|
|
32
34
|
import {
|
|
33
35
|
StringUtil,
|
|
@@ -54,6 +56,174 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
54
56
|
private NONE_ERROR_MESSAGE: string =
|
|
55
57
|
'Expected content-type to be text/event-stream, Actual: null';
|
|
56
58
|
|
|
59
|
+
// 网络中断自动续传的最大重试次数
|
|
60
|
+
private AUTO_RESUME_MAX_RETRY: number = 3;
|
|
61
|
+
|
|
62
|
+
// 网络中断自动续传的退避基数(毫秒),按 1s/2s/4s 指数退避
|
|
63
|
+
private AUTO_RESUME_BACKOFF_BASE: number = 1000;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
|
|
67
|
+
* @param {any} aiChat 单实例聊天总控
|
|
68
|
+
* @param {string} id 本次问答的流式消息 id
|
|
69
|
+
* @param {string} localMsgID 本地用户消息 id(用于回填真实消息 id;为空串时为恢复会话场景,状态 20 走 isLoading 加载分支)
|
|
70
|
+
* @return {*} {(msg: IPortalAsyncAction) => void}
|
|
71
|
+
* @memberof AIChatUtil
|
|
72
|
+
*/
|
|
73
|
+
private createChatSseHandler(
|
|
74
|
+
aiChat: any,
|
|
75
|
+
id: string,
|
|
76
|
+
localMsgID: string,
|
|
77
|
+
): (msg: IPortalAsyncAction) => void {
|
|
78
|
+
// 更新标记,主要用于更新用户消息真实消息ID(每条消息都会回asextparam,只需要设置一次即可)
|
|
79
|
+
let updateFlag = true;
|
|
80
|
+
return (msg: IPortalAsyncAction) => {
|
|
81
|
+
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
82
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
83
|
+
if (localMsgID) {
|
|
84
|
+
// 提问场景:移除等待回复消息
|
|
85
|
+
aiChat.removeWaitingMessage(id);
|
|
86
|
+
// 更新用户消息真实id
|
|
87
|
+
if (msg.asextparam && updateFlag) {
|
|
88
|
+
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
89
|
+
updateFlag = false;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
// 恢复会话场景:设置当前聊天在加载中
|
|
93
|
+
aiChat.isLoading.value = true;
|
|
94
|
+
}
|
|
95
|
+
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
96
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
97
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
98
|
+
}
|
|
99
|
+
aiChat.addMessage({
|
|
100
|
+
messageid: id,
|
|
101
|
+
state: msg.actionstate,
|
|
102
|
+
type: 'DEFAULT',
|
|
103
|
+
role: 'ASSISTANT',
|
|
104
|
+
content: msg.actionresult as string,
|
|
105
|
+
status: 'pending',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
109
|
+
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
110
|
+
const result = JSON.parse(msg.actionresult as string);
|
|
111
|
+
if (result.usage) {
|
|
112
|
+
aiChat.updateMsgUsage(id, result.usage);
|
|
113
|
+
}
|
|
114
|
+
if (result.files) {
|
|
115
|
+
aiChat.updateMsgOutputFiles(id, result.files);
|
|
116
|
+
}
|
|
117
|
+
const choices = result.choices;
|
|
118
|
+
if (choices && choices.length > 0) {
|
|
119
|
+
aiChat.replaceMessage({
|
|
120
|
+
messageid: id,
|
|
121
|
+
state: msg.actionstate,
|
|
122
|
+
type: 'DEFAULT',
|
|
123
|
+
role: 'ASSISTANT',
|
|
124
|
+
content: choices[0].content || '',
|
|
125
|
+
realmessageid: choices[0].messageid,
|
|
126
|
+
status: 'sent',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// 清空异步消息任务
|
|
130
|
+
aiChat.setActiveAsyncacitonId('');
|
|
131
|
+
}
|
|
132
|
+
// 40: 回答报错,展示错误信息
|
|
133
|
+
else if (msg.actionstate === 40) {
|
|
134
|
+
aiChat.replaceMessage({
|
|
135
|
+
messageid: id,
|
|
136
|
+
state: msg.actionstate,
|
|
137
|
+
type: 'ERROR',
|
|
138
|
+
role: 'ASSISTANT',
|
|
139
|
+
errorText: msg.actionresult as string,
|
|
140
|
+
status: 'failed',
|
|
141
|
+
});
|
|
142
|
+
// 清空异步消息任务
|
|
143
|
+
aiChat.setActiveAsyncacitonId('');
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @description 网络中断(network error)后按 asyncacitonid 自动续传,指数退避重试;成功返回 true,不可恢复/重试耗尽返回 false 交回调用方走既有错误处理
|
|
150
|
+
* @param {any} aiChat 单实例聊天总控
|
|
151
|
+
* @param {IContext} ctx 上下文
|
|
152
|
+
* @param {IParams} param 视图参数
|
|
153
|
+
* @param {*} deService 实体服务
|
|
154
|
+
* @param {{ id: string; abortController: AbortController }} state 聊天实例提问状态(WeakMap 持有的同一对象引用)
|
|
155
|
+
* @param {{ asyncacitonid: string; sessionid?: string; srfaiagent?: string; srfproject?: string }} resumeInfo 续传参数
|
|
156
|
+
* @param {(msg: IPortalAsyncAction) => void} onMsg SSE 流式消息处理回调
|
|
157
|
+
* @return {*} {Promise<boolean>} 是否续传成功
|
|
158
|
+
* @memberof AIChatUtil
|
|
159
|
+
*/
|
|
160
|
+
private async autoResumeChat(
|
|
161
|
+
aiChat: any,
|
|
162
|
+
ctx: IContext,
|
|
163
|
+
param: IParams,
|
|
164
|
+
deService: any,
|
|
165
|
+
state: { id: string; abortController: AbortController },
|
|
166
|
+
resumeInfo: {
|
|
167
|
+
asyncacitonid: string;
|
|
168
|
+
sessionid?: string;
|
|
169
|
+
srfaiagent?: string;
|
|
170
|
+
srfproject?: string;
|
|
171
|
+
},
|
|
172
|
+
onMsg: (msg: IPortalAsyncAction) => void,
|
|
173
|
+
): Promise<boolean> {
|
|
174
|
+
// 续传前先释放旧 SSE 连接,避免旧连接未关闭影响新连接建立
|
|
175
|
+
state.abortController?.abort();
|
|
176
|
+
// 全程复用同一个新 AbortController 并存回 state:退避等待期间用户点停止时,
|
|
177
|
+
// abortQuestion abort 的即是该实例,下一轮请求携带已中止信号会立即抛 AbortError 退出循环
|
|
178
|
+
state.abortController = new AbortController();
|
|
179
|
+
for (let attempt = 1; attempt <= this.AUTO_RESUME_MAX_RETRY; attempt++) {
|
|
180
|
+
try {
|
|
181
|
+
// 指数退避后重试
|
|
182
|
+
// eslint-disable-next-line no-await-in-loop
|
|
183
|
+
await new Promise<void>(resolve => {
|
|
184
|
+
setTimeout(
|
|
185
|
+
resolve,
|
|
186
|
+
this.AUTO_RESUME_BACKOFF_BASE * 2 ** (attempt - 1),
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
const resumeRequestData: IData = {
|
|
190
|
+
asyncacitonid: resumeInfo.asyncacitonid,
|
|
191
|
+
};
|
|
192
|
+
if (resumeInfo.sessionid) {
|
|
193
|
+
resumeRequestData.sessionid = resumeInfo.sessionid;
|
|
194
|
+
}
|
|
195
|
+
if (resumeInfo.srfaiagent) {
|
|
196
|
+
resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
|
|
197
|
+
}
|
|
198
|
+
if (resumeInfo.srfproject) {
|
|
199
|
+
resumeRequestData.srfproject = resumeInfo.srfproject;
|
|
200
|
+
}
|
|
201
|
+
// eslint-disable-next-line no-await-in-loop
|
|
202
|
+
await deService.aiResumeSse(
|
|
203
|
+
onMsg,
|
|
204
|
+
state.abortController,
|
|
205
|
+
ctx,
|
|
206
|
+
{ srfactag: param.srfactag },
|
|
207
|
+
{ ...resumeRequestData },
|
|
208
|
+
);
|
|
209
|
+
return true;
|
|
210
|
+
} catch (resumeError) {
|
|
211
|
+
const resumeMsg = (resumeError as Error)?.message || '';
|
|
212
|
+
// 用户已点停止,不再续传
|
|
213
|
+
if ((resumeError as Error)?.name === 'AbortError') {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
// 后端异步动作已完成,无可恢复内容
|
|
217
|
+
if (resumeMsg === this.NONE_ERROR_MESSAGE) {
|
|
218
|
+
aiChat.setActiveAsyncacitonId('');
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
// 其余(网络仍断等)继续下一轮退避重试
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
|
|
57
227
|
/**
|
|
58
228
|
* 获取AI聊天对象
|
|
59
229
|
*/
|
|
@@ -63,6 +233,115 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
63
233
|
return chatInstance;
|
|
64
234
|
}
|
|
65
235
|
|
|
236
|
+
/**
|
|
237
|
+
* @description 获取AI聊天工具(防止全屏模式下消息弹框、确认弹框、通知弹框被隐藏,添加appendTo参数)
|
|
238
|
+
* @returns {*} {IData}
|
|
239
|
+
* @memberof AIChatUtil
|
|
240
|
+
*/
|
|
241
|
+
getAIChatUtils(): IData {
|
|
242
|
+
return {
|
|
243
|
+
message: {
|
|
244
|
+
info: (
|
|
245
|
+
msg: string,
|
|
246
|
+
duration?: number | undefined,
|
|
247
|
+
closable?: boolean | undefined,
|
|
248
|
+
options?: object,
|
|
249
|
+
) =>
|
|
250
|
+
ibiz.message.info(msg, duration, closable, {
|
|
251
|
+
appendTo: document.fullscreenElement,
|
|
252
|
+
...options,
|
|
253
|
+
}),
|
|
254
|
+
success: (
|
|
255
|
+
msg: string,
|
|
256
|
+
duration?: number | undefined,
|
|
257
|
+
closable?: boolean | undefined,
|
|
258
|
+
options?: object,
|
|
259
|
+
) =>
|
|
260
|
+
ibiz.message.success(msg, duration, closable, {
|
|
261
|
+
appendTo: document.fullscreenElement,
|
|
262
|
+
...options,
|
|
263
|
+
}),
|
|
264
|
+
warning: (
|
|
265
|
+
msg: string,
|
|
266
|
+
duration?: number | undefined,
|
|
267
|
+
closable?: boolean | undefined,
|
|
268
|
+
options?: object,
|
|
269
|
+
) =>
|
|
270
|
+
ibiz.message.warning(msg, duration, closable, {
|
|
271
|
+
appendTo: document.fullscreenElement,
|
|
272
|
+
...options,
|
|
273
|
+
}),
|
|
274
|
+
error: (
|
|
275
|
+
msg: string,
|
|
276
|
+
duration?: number | undefined,
|
|
277
|
+
closable?: boolean | undefined,
|
|
278
|
+
options?: object,
|
|
279
|
+
) =>
|
|
280
|
+
ibiz.message.error(msg, duration, closable, {
|
|
281
|
+
appendTo: document.fullscreenElement,
|
|
282
|
+
...options,
|
|
283
|
+
}),
|
|
284
|
+
},
|
|
285
|
+
confirm: {
|
|
286
|
+
info: (args: ConfirmParams) =>
|
|
287
|
+
ibiz.confirm.info({
|
|
288
|
+
options: {
|
|
289
|
+
appendTo: document.fullscreenElement,
|
|
290
|
+
},
|
|
291
|
+
...args,
|
|
292
|
+
}),
|
|
293
|
+
success: (args: ConfirmParams) =>
|
|
294
|
+
ibiz.confirm.success({
|
|
295
|
+
options: {
|
|
296
|
+
appendTo: document.fullscreenElement,
|
|
297
|
+
},
|
|
298
|
+
...args,
|
|
299
|
+
}),
|
|
300
|
+
warning: (args: ConfirmParams) =>
|
|
301
|
+
ibiz.confirm.warning({
|
|
302
|
+
options: {
|
|
303
|
+
appendTo: document.fullscreenElement,
|
|
304
|
+
},
|
|
305
|
+
...args,
|
|
306
|
+
}),
|
|
307
|
+
error: (args: ConfirmParams) =>
|
|
308
|
+
ibiz.confirm.error({
|
|
309
|
+
options: {
|
|
310
|
+
appendTo: document.fullscreenElement,
|
|
311
|
+
},
|
|
312
|
+
...args,
|
|
313
|
+
}),
|
|
314
|
+
},
|
|
315
|
+
notification: {
|
|
316
|
+
default: (args: NotificationParams) =>
|
|
317
|
+
ibiz.notification.default({
|
|
318
|
+
appendTo: (document.fullscreenElement as HTMLElement) || '',
|
|
319
|
+
...args,
|
|
320
|
+
}),
|
|
321
|
+
info: (args: NotificationParams) =>
|
|
322
|
+
ibiz.notification.info({
|
|
323
|
+
appendTo: (document.fullscreenElement as HTMLElement) || '',
|
|
324
|
+
...args,
|
|
325
|
+
}),
|
|
326
|
+
success: (args: NotificationParams) =>
|
|
327
|
+
ibiz.notification.success({
|
|
328
|
+
appendTo: (document.fullscreenElement as HTMLElement) || '',
|
|
329
|
+
...args,
|
|
330
|
+
}),
|
|
331
|
+
warning: (args: NotificationParams) =>
|
|
332
|
+
ibiz.notification.warning({
|
|
333
|
+
appendTo: (document.fullscreenElement as HTMLElement) || '',
|
|
334
|
+
...args,
|
|
335
|
+
}),
|
|
336
|
+
error: (args: NotificationParams) =>
|
|
337
|
+
ibiz.notification.error({
|
|
338
|
+
appendTo: (document.fullscreenElement as HTMLElement) || '',
|
|
339
|
+
...args,
|
|
340
|
+
}),
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
66
345
|
/**
|
|
67
346
|
* 获取编辑器扩展AI聊天参数
|
|
68
347
|
* @param editorParams
|
|
@@ -184,6 +463,9 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
184
463
|
const result = await ibiz.confirm.warning({
|
|
185
464
|
title,
|
|
186
465
|
desc: description,
|
|
466
|
+
options: {
|
|
467
|
+
appendTo: document.fullscreenElement,
|
|
468
|
+
},
|
|
187
469
|
});
|
|
188
470
|
return result;
|
|
189
471
|
};
|
|
@@ -216,6 +498,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
216
498
|
projectSelectPlaceholder:
|
|
217
499
|
editorParams.srfprojectselectplaceholder ||
|
|
218
500
|
ibiz.config.common.aiProjectSelectPlaceholder,
|
|
501
|
+
selectAIProjectId: editorParams.srfselectaiprojectid,
|
|
219
502
|
};
|
|
220
503
|
// 编辑器参数srfaiappendcurdata,是否传入对象参数,用于历史查询传参
|
|
221
504
|
if (editorParams.srfaiappendcurdata) {
|
|
@@ -507,8 +790,6 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
507
790
|
srfproject: string | undefined,
|
|
508
791
|
localMsgID: string,
|
|
509
792
|
) => {
|
|
510
|
-
// 更新标记,主要用于更新用户消息真实消息ID(每条消息都会回asextparam,只需要设置一次即可)
|
|
511
|
-
let updateFlag = true;
|
|
512
793
|
const state = getChatState(aiChat);
|
|
513
794
|
state.id = createUUID();
|
|
514
795
|
state.abortController = new AbortController();
|
|
@@ -516,27 +797,28 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
516
797
|
const deService = await ibiz.hub
|
|
517
798
|
.getApp(ctx.srfappid)
|
|
518
799
|
.deService.getService(ctx, other.appDataEntityId);
|
|
800
|
+
// SSE 流式消息处理回调(question 与网络中断自动续传共用)
|
|
801
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
519
802
|
try {
|
|
520
|
-
const
|
|
803
|
+
const requestData: IData = {
|
|
521
804
|
messages: arr,
|
|
522
805
|
sessionid,
|
|
523
806
|
};
|
|
524
|
-
if (srfaiagent)
|
|
525
|
-
if (srfmode)
|
|
526
|
-
if (srfscope)
|
|
527
|
-
if (srfproject)
|
|
528
|
-
if (srfknowledgebases)
|
|
529
|
-
questionRequestData.knowledgebases = srfknowledgebases;
|
|
807
|
+
if (srfaiagent) requestData.srfaiagent = srfaiagent;
|
|
808
|
+
if (srfmode) requestData.mode = srfmode;
|
|
809
|
+
if (srfscope) requestData.srfscope = srfscope;
|
|
810
|
+
if (srfproject) requestData.srfproject = srfproject;
|
|
811
|
+
if (srfknowledgebases) requestData.knowledgebases = srfknowledgebases;
|
|
530
812
|
if (srfaiagentconfig) {
|
|
531
|
-
Object.assign(
|
|
813
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
532
814
|
}
|
|
533
815
|
if (mcpservers) {
|
|
534
|
-
Object.assign(
|
|
816
|
+
Object.assign(requestData, {
|
|
535
817
|
mcpservers,
|
|
536
818
|
});
|
|
537
819
|
}
|
|
538
820
|
if (sessionmeta) {
|
|
539
|
-
Object.assign(
|
|
821
|
+
Object.assign(requestData, {
|
|
540
822
|
srfuimeta: JSON.stringify(sessionmeta),
|
|
541
823
|
});
|
|
542
824
|
}
|
|
@@ -549,79 +831,34 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
549
831
|
Object.assign(extParams, { ...appendcurdata });
|
|
550
832
|
}
|
|
551
833
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
552
|
-
Object.assign(
|
|
834
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
553
835
|
}
|
|
554
836
|
// 新增等待回复消息(AI首条内容到达前显示loading气泡)
|
|
555
837
|
aiChat.addWaitingMessage(id);
|
|
556
838
|
await deService.aiChatSse(
|
|
557
|
-
|
|
558
|
-
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
559
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
560
|
-
// 移除等待回复消息
|
|
561
|
-
aiChat.removeWaitingMessage(id);
|
|
562
|
-
// 更新用户消息真实id
|
|
563
|
-
if (msg.asextparam && localMsgID && updateFlag) {
|
|
564
|
-
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
565
|
-
updateFlag = false;
|
|
566
|
-
}
|
|
567
|
-
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
568
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
569
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
570
|
-
}
|
|
571
|
-
aiChat.addMessage({
|
|
572
|
-
messageid: id,
|
|
573
|
-
state: msg.actionstate,
|
|
574
|
-
type: 'DEFAULT',
|
|
575
|
-
role: 'ASSISTANT',
|
|
576
|
-
content: msg.actionresult as string,
|
|
577
|
-
status: 'pending',
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
581
|
-
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
582
|
-
const result = JSON.parse(msg.actionresult as string);
|
|
583
|
-
if (result.usage) {
|
|
584
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
585
|
-
}
|
|
586
|
-
if (result.files) {
|
|
587
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
588
|
-
}
|
|
589
|
-
const choices = result.choices;
|
|
590
|
-
if (choices && choices.length > 0) {
|
|
591
|
-
aiChat.replaceMessage({
|
|
592
|
-
messageid: id,
|
|
593
|
-
state: msg.actionstate,
|
|
594
|
-
type: 'DEFAULT',
|
|
595
|
-
role: 'ASSISTANT',
|
|
596
|
-
content: choices[0].content || '',
|
|
597
|
-
realmessageid: choices[0].messageid,
|
|
598
|
-
status: 'sent',
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
// 清空异步消息任务
|
|
602
|
-
aiChat.setActiveAsyncacitonId('');
|
|
603
|
-
}
|
|
604
|
-
// 40: 回答报错,展示错误信息
|
|
605
|
-
else if (msg.actionstate === 40) {
|
|
606
|
-
aiChat.replaceMessage({
|
|
607
|
-
messageid: id,
|
|
608
|
-
state: msg.actionstate,
|
|
609
|
-
type: 'ERROR',
|
|
610
|
-
role: 'ASSISTANT',
|
|
611
|
-
errorText: msg.actionresult as string,
|
|
612
|
-
status: 'failed',
|
|
613
|
-
});
|
|
614
|
-
// 清空异步消息任务
|
|
615
|
-
aiChat.setActiveAsyncacitonId('');
|
|
616
|
-
}
|
|
617
|
-
},
|
|
839
|
+
onMsg,
|
|
618
840
|
abortController,
|
|
619
841
|
ctx,
|
|
620
842
|
{ srfactag: param.srfactag },
|
|
621
|
-
{ ...
|
|
843
|
+
{ ...requestData },
|
|
622
844
|
);
|
|
623
845
|
} catch (error) {
|
|
624
|
-
|
|
846
|
+
const errMsg = (error as Error)?.message || '';
|
|
847
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
848
|
+
// 仅网络中断且后端异步动作仍在运行(asyncid 未清)时自动续传
|
|
849
|
+
if (errMsg === 'network error' && asyncacitonid) {
|
|
850
|
+
const resumed = await this.autoResumeChat(
|
|
851
|
+
aiChat,
|
|
852
|
+
ctx,
|
|
853
|
+
param,
|
|
854
|
+
deService,
|
|
855
|
+
state,
|
|
856
|
+
{ asyncacitonid, sessionid, srfaiagent, srfproject },
|
|
857
|
+
onMsg,
|
|
858
|
+
);
|
|
859
|
+
if (resumed) return true;
|
|
860
|
+
}
|
|
861
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
625
862
|
aiChat.replaceMessage({
|
|
626
863
|
messageid: id,
|
|
627
864
|
state: 40,
|
|
@@ -636,6 +873,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
636
873
|
{
|
|
637
874
|
...lastMessage,
|
|
638
875
|
state: 40,
|
|
876
|
+
errorText: ibiz.i18n.t('app.aiError'),
|
|
639
877
|
},
|
|
640
878
|
false,
|
|
641
879
|
);
|
|
@@ -708,87 +946,35 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
708
946
|
const deService = await ibiz.hub
|
|
709
947
|
.getApp(ctx.srfappid)
|
|
710
948
|
.deService.getService(ctx, other.appDataEntityId);
|
|
711
|
-
const
|
|
949
|
+
const requestData: IData = { asyncacitonid: other.asyncacitonid };
|
|
712
950
|
if (other.sessionid) {
|
|
713
|
-
Object.assign(
|
|
951
|
+
Object.assign(requestData, {
|
|
714
952
|
sessionid: other.sessionid,
|
|
715
953
|
});
|
|
716
954
|
}
|
|
717
955
|
if (other.srfaiagent) {
|
|
718
|
-
Object.assign(
|
|
956
|
+
Object.assign(requestData, {
|
|
719
957
|
srfaiagent: other.srfaiagent,
|
|
720
958
|
});
|
|
721
959
|
}
|
|
722
960
|
if (other.srfproject)
|
|
723
|
-
Object.assign(
|
|
961
|
+
Object.assign(requestData, {
|
|
724
962
|
srfproject: other.srfproject,
|
|
725
963
|
});
|
|
964
|
+
// 恢复会话流式消息处理回调(与提问共用,localMsgID 传空串走 isLoading 分支)
|
|
965
|
+
const onMsg = this.createChatSseHandler(aiChat, id, '');
|
|
726
966
|
try {
|
|
727
967
|
await deService.aiResumeSse(
|
|
728
|
-
|
|
729
|
-
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
730
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
731
|
-
// 设置当前聊天在加载中
|
|
732
|
-
aiChat.isLoading.value = true;
|
|
733
|
-
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
734
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
735
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
736
|
-
}
|
|
737
|
-
aiChat.addMessage({
|
|
738
|
-
messageid: id,
|
|
739
|
-
state: msg.actionstate,
|
|
740
|
-
type: 'DEFAULT',
|
|
741
|
-
role: 'ASSISTANT',
|
|
742
|
-
content: msg.actionresult as string,
|
|
743
|
-
status: 'pending',
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
747
|
-
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
748
|
-
const result = JSON.parse(msg.actionresult as string);
|
|
749
|
-
if (result.usage) {
|
|
750
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
751
|
-
}
|
|
752
|
-
if (result.files) {
|
|
753
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
754
|
-
}
|
|
755
|
-
const choices = result.choices;
|
|
756
|
-
if (choices && choices.length > 0) {
|
|
757
|
-
aiChat.replaceMessage({
|
|
758
|
-
messageid: id,
|
|
759
|
-
state: msg.actionstate,
|
|
760
|
-
type: 'DEFAULT',
|
|
761
|
-
role: 'ASSISTANT',
|
|
762
|
-
content: choices[0].content || '',
|
|
763
|
-
realmessageid: choices[0].messageid,
|
|
764
|
-
status: 'sent',
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
// 清空异步消息任务
|
|
768
|
-
aiChat.setActiveAsyncacitonId('');
|
|
769
|
-
}
|
|
770
|
-
// 40: 回答报错,展示错误信息
|
|
771
|
-
else if (msg.actionstate === 40) {
|
|
772
|
-
aiChat.replaceMessage({
|
|
773
|
-
messageid: id,
|
|
774
|
-
state: msg.actionstate,
|
|
775
|
-
type: 'ERROR',
|
|
776
|
-
role: 'ASSISTANT',
|
|
777
|
-
errorText: msg.actionresult as string,
|
|
778
|
-
status: 'failed',
|
|
779
|
-
});
|
|
780
|
-
// 清空异步消息任务
|
|
781
|
-
aiChat.setActiveAsyncacitonId('');
|
|
782
|
-
}
|
|
783
|
-
},
|
|
968
|
+
onMsg,
|
|
784
969
|
abortController,
|
|
785
970
|
ctx,
|
|
786
971
|
{ srfactag: param.srfactag },
|
|
787
|
-
{ ...
|
|
972
|
+
{ ...requestData },
|
|
788
973
|
);
|
|
789
974
|
} catch (error) {
|
|
975
|
+
const errMsg = (error as Error)?.message || '';
|
|
790
976
|
// 等于NONE_ERROR_MESSAGE,代码该异步行为已经完成,不需要做处理
|
|
791
|
-
if (error &&
|
|
977
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
792
978
|
if (error && (error as Error).message !== this.PRE_ERROR_MESSAGE) {
|
|
793
979
|
aiChat.replaceMessage({
|
|
794
980
|
messageid: id,
|
|
@@ -805,6 +991,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
805
991
|
{
|
|
806
992
|
...lastMessage,
|
|
807
993
|
state: 40,
|
|
994
|
+
errorText: ibiz.i18n.t('app.aiError'),
|
|
808
995
|
},
|
|
809
996
|
false,
|
|
810
997
|
);
|
|
@@ -1086,11 +1273,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1086
1273
|
}
|
|
1087
1274
|
};
|
|
1088
1275
|
// 消息通知工具类
|
|
1089
|
-
chatOptions.utils =
|
|
1090
|
-
message: ibiz.message,
|
|
1091
|
-
notification: ibiz.notification,
|
|
1092
|
-
confirm: ibiz.confirm,
|
|
1093
|
-
};
|
|
1276
|
+
chatOptions.utils = this.getAIChatUtils();
|
|
1094
1277
|
return { containerOptions, topicOptions, chatOptions };
|
|
1095
1278
|
}
|
|
1096
1279
|
|
|
@@ -1233,6 +1416,9 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1233
1416
|
const result = await ibiz.confirm.warning({
|
|
1234
1417
|
title,
|
|
1235
1418
|
desc: description,
|
|
1419
|
+
options: {
|
|
1420
|
+
appendTo: document.fullscreenElement,
|
|
1421
|
+
},
|
|
1236
1422
|
});
|
|
1237
1423
|
return result;
|
|
1238
1424
|
};
|
|
@@ -1265,7 +1451,10 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1265
1451
|
projectSelectPlaceholder:
|
|
1266
1452
|
params.srfprojectselectplaceholder ||
|
|
1267
1453
|
ibiz.config.common.aiProjectSelectPlaceholder,
|
|
1454
|
+
selectAIProjectId: params.srfselectaiprojectid,
|
|
1268
1455
|
};
|
|
1456
|
+
if (params.hasOwnProperty('srfselectaiprojectid'))
|
|
1457
|
+
delete params.srfselectaiprojectid;
|
|
1269
1458
|
if (params.hasOwnProperty('srfenableaiprojectselect'))
|
|
1270
1459
|
delete params.srfenableaiprojectselect;
|
|
1271
1460
|
if (params.hasOwnProperty('srfprojectselectplaceholder'))
|
|
@@ -1581,8 +1770,6 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1581
1770
|
srfproject: string | undefined,
|
|
1582
1771
|
localMsgID: string,
|
|
1583
1772
|
) => {
|
|
1584
|
-
// 更新标记,主要用于更新用户消息真实消息ID(每条消息都会回asextparam,只需要设置一次即可)
|
|
1585
|
-
let updateFlag = true;
|
|
1586
1773
|
const state = getChatState(aiChat);
|
|
1587
1774
|
state.id = createUUID();
|
|
1588
1775
|
state.abortController = new AbortController();
|
|
@@ -1590,25 +1777,26 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1590
1777
|
const deService = await ibiz.hub
|
|
1591
1778
|
.getApp(ctx.srfappid)
|
|
1592
1779
|
.deService.getService(ctx, other.appDataEntityId);
|
|
1780
|
+
// SSE 流式消息处理回调(question 与网络中断自动续传共用)
|
|
1781
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
1593
1782
|
try {
|
|
1594
|
-
const
|
|
1783
|
+
const requestData: IData = {
|
|
1595
1784
|
messages: arr,
|
|
1596
1785
|
sessionid,
|
|
1597
1786
|
};
|
|
1598
|
-
if (srfaiagent)
|
|
1599
|
-
if (srfmode)
|
|
1600
|
-
if (srfscope)
|
|
1601
|
-
if (srfproject)
|
|
1602
|
-
if (srfknowledgebases)
|
|
1603
|
-
questionRequestData.knowledgebases = srfknowledgebases;
|
|
1787
|
+
if (srfaiagent) requestData.srfaiagent = srfaiagent;
|
|
1788
|
+
if (srfmode) requestData.mode = srfmode;
|
|
1789
|
+
if (srfscope) requestData.srfscope = srfscope;
|
|
1790
|
+
if (srfproject) requestData.srfproject = srfproject;
|
|
1791
|
+
if (srfknowledgebases) requestData.knowledgebases = srfknowledgebases;
|
|
1604
1792
|
if (srfaiagentconfig) {
|
|
1605
|
-
Object.assign(
|
|
1793
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
1606
1794
|
}
|
|
1607
1795
|
if (mcpservers) {
|
|
1608
|
-
Object.assign(
|
|
1796
|
+
Object.assign(requestData, { mcpservers });
|
|
1609
1797
|
}
|
|
1610
1798
|
if (sessionmeta) {
|
|
1611
|
-
Object.assign(
|
|
1799
|
+
Object.assign(requestData, {
|
|
1612
1800
|
srfuimeta: JSON.stringify(sessionmeta),
|
|
1613
1801
|
});
|
|
1614
1802
|
}
|
|
@@ -1621,79 +1809,34 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1621
1809
|
Object.assign(extParams, { ...appendcurdata });
|
|
1622
1810
|
}
|
|
1623
1811
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
1624
|
-
Object.assign(
|
|
1812
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
1625
1813
|
}
|
|
1626
1814
|
// 新增等待回复消息(AI首条内容到达前显示loading气泡)
|
|
1627
1815
|
aiChat.addWaitingMessage(id);
|
|
1628
1816
|
await deService.aiChatSse(
|
|
1629
|
-
|
|
1630
|
-
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
1631
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1632
|
-
// 移除等待回复消息
|
|
1633
|
-
aiChat.removeWaitingMessage(id);
|
|
1634
|
-
// 更新用户消息真实id
|
|
1635
|
-
if (msg.asextparam && localMsgID && updateFlag) {
|
|
1636
|
-
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
1637
|
-
updateFlag = false;
|
|
1638
|
-
}
|
|
1639
|
-
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
1640
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1641
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1642
|
-
}
|
|
1643
|
-
aiChat.addMessage({
|
|
1644
|
-
messageid: id,
|
|
1645
|
-
state: msg.actionstate,
|
|
1646
|
-
type: 'DEFAULT',
|
|
1647
|
-
role: 'ASSISTANT',
|
|
1648
|
-
content: msg.actionresult as string,
|
|
1649
|
-
status: 'pending',
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
1653
|
-
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1654
|
-
const result = JSON.parse(msg.actionresult as string);
|
|
1655
|
-
if (result.usage) {
|
|
1656
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
1657
|
-
}
|
|
1658
|
-
if (result.files) {
|
|
1659
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
1660
|
-
}
|
|
1661
|
-
const choices = result.choices;
|
|
1662
|
-
if (choices && choices.length > 0) {
|
|
1663
|
-
aiChat.replaceMessage({
|
|
1664
|
-
messageid: id,
|
|
1665
|
-
state: msg.actionstate,
|
|
1666
|
-
type: 'DEFAULT',
|
|
1667
|
-
role: 'ASSISTANT',
|
|
1668
|
-
content: choices[0].content || '',
|
|
1669
|
-
realmessageid: choices[0].messageid,
|
|
1670
|
-
status: 'sent',
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
|
-
// 清空异步消息任务
|
|
1674
|
-
aiChat.setActiveAsyncacitonId('');
|
|
1675
|
-
}
|
|
1676
|
-
// 40: 回答报错,展示错误信息
|
|
1677
|
-
else if (msg.actionstate === 40) {
|
|
1678
|
-
aiChat.replaceMessage({
|
|
1679
|
-
messageid: id,
|
|
1680
|
-
state: msg.actionstate,
|
|
1681
|
-
type: 'ERROR',
|
|
1682
|
-
role: 'ASSISTANT',
|
|
1683
|
-
errorText: msg.actionresult as string,
|
|
1684
|
-
status: 'failed',
|
|
1685
|
-
});
|
|
1686
|
-
// 清空异步消息任务
|
|
1687
|
-
aiChat.setActiveAsyncacitonId('');
|
|
1688
|
-
}
|
|
1689
|
-
},
|
|
1817
|
+
onMsg,
|
|
1690
1818
|
abortController,
|
|
1691
1819
|
ctx,
|
|
1692
1820
|
{ srfactag: param.srfactag },
|
|
1693
|
-
{ ...
|
|
1821
|
+
{ ...requestData },
|
|
1694
1822
|
);
|
|
1695
1823
|
} catch (error) {
|
|
1696
|
-
|
|
1824
|
+
const errMsg = (error as Error)?.message || '';
|
|
1825
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
1826
|
+
// 仅网络中断且后端异步动作仍在运行(asyncid 未清)时自动续传
|
|
1827
|
+
if (errMsg === 'network error' && asyncacitonid) {
|
|
1828
|
+
const resumed = await this.autoResumeChat(
|
|
1829
|
+
aiChat,
|
|
1830
|
+
ctx,
|
|
1831
|
+
param,
|
|
1832
|
+
deService,
|
|
1833
|
+
state,
|
|
1834
|
+
{ asyncacitonid, sessionid, srfaiagent, srfproject },
|
|
1835
|
+
onMsg,
|
|
1836
|
+
);
|
|
1837
|
+
if (resumed) return true;
|
|
1838
|
+
}
|
|
1839
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
1697
1840
|
aiChat.replaceMessage({
|
|
1698
1841
|
messageid: id,
|
|
1699
1842
|
state: 40,
|
|
@@ -1708,6 +1851,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1708
1851
|
{
|
|
1709
1852
|
...lastMessage,
|
|
1710
1853
|
state: 40,
|
|
1854
|
+
errorText: ibiz.i18n.t('app.aiError'),
|
|
1711
1855
|
},
|
|
1712
1856
|
false,
|
|
1713
1857
|
);
|
|
@@ -1780,87 +1924,35 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1780
1924
|
const deService = await ibiz.hub
|
|
1781
1925
|
.getApp(ctx.srfappid)
|
|
1782
1926
|
.deService.getService(ctx, other.appDataEntityId);
|
|
1783
|
-
const
|
|
1927
|
+
const requestData: IData = { asyncacitonid: other.asyncacitonid };
|
|
1784
1928
|
if (other.sessionid) {
|
|
1785
|
-
Object.assign(
|
|
1929
|
+
Object.assign(requestData, {
|
|
1786
1930
|
sessionid: other.sessionid,
|
|
1787
1931
|
});
|
|
1788
1932
|
}
|
|
1789
1933
|
if (other.srfaiagent) {
|
|
1790
|
-
Object.assign(
|
|
1934
|
+
Object.assign(requestData, {
|
|
1791
1935
|
srfaiagent: other.srfaiagent,
|
|
1792
1936
|
});
|
|
1793
1937
|
}
|
|
1794
1938
|
if (other.srfproject)
|
|
1795
|
-
Object.assign(
|
|
1939
|
+
Object.assign(requestData, {
|
|
1796
1940
|
srfproject: other.srfproject,
|
|
1797
1941
|
});
|
|
1942
|
+
// 恢复会话流式消息处理回调(与提问共用,localMsgID 传空串走 isLoading 分支)
|
|
1943
|
+
const onMsg = this.createChatSseHandler(aiChat, id, '');
|
|
1798
1944
|
try {
|
|
1799
1945
|
await deService.aiResumeSse(
|
|
1800
|
-
|
|
1801
|
-
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
1802
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1803
|
-
// 设置当前聊天在加载中
|
|
1804
|
-
aiChat.isLoading.value = true;
|
|
1805
|
-
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
1806
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1807
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1808
|
-
}
|
|
1809
|
-
aiChat.addMessage({
|
|
1810
|
-
messageid: id,
|
|
1811
|
-
state: msg.actionstate,
|
|
1812
|
-
type: 'DEFAULT',
|
|
1813
|
-
role: 'ASSISTANT',
|
|
1814
|
-
content: msg.actionresult as string,
|
|
1815
|
-
status: 'pending',
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
1819
|
-
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1820
|
-
const result = JSON.parse(msg.actionresult as string);
|
|
1821
|
-
if (result.usage) {
|
|
1822
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
1823
|
-
}
|
|
1824
|
-
if (result.files) {
|
|
1825
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
1826
|
-
}
|
|
1827
|
-
const choices = result.choices;
|
|
1828
|
-
if (choices && choices.length > 0) {
|
|
1829
|
-
aiChat.replaceMessage({
|
|
1830
|
-
messageid: id,
|
|
1831
|
-
state: msg.actionstate,
|
|
1832
|
-
type: 'DEFAULT',
|
|
1833
|
-
role: 'ASSISTANT',
|
|
1834
|
-
content: choices[0].content || '',
|
|
1835
|
-
realmessageid: choices[0].messageid,
|
|
1836
|
-
status: 'sent',
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
// 清空异步消息任务
|
|
1840
|
-
aiChat.setActiveAsyncacitonId('');
|
|
1841
|
-
}
|
|
1842
|
-
// 40: 回答报错,展示错误信息
|
|
1843
|
-
else if (msg.actionstate === 40) {
|
|
1844
|
-
aiChat.replaceMessage({
|
|
1845
|
-
messageid: id,
|
|
1846
|
-
state: msg.actionstate,
|
|
1847
|
-
type: 'ERROR',
|
|
1848
|
-
role: 'ASSISTANT',
|
|
1849
|
-
errorText: msg.actionresult as string,
|
|
1850
|
-
status: 'failed',
|
|
1851
|
-
});
|
|
1852
|
-
// 清空异步消息任务
|
|
1853
|
-
aiChat.setActiveAsyncacitonId('');
|
|
1854
|
-
}
|
|
1855
|
-
},
|
|
1946
|
+
onMsg,
|
|
1856
1947
|
abortController,
|
|
1857
1948
|
ctx,
|
|
1858
1949
|
{ srfactag: param.srfactag },
|
|
1859
|
-
{ ...
|
|
1950
|
+
{ ...requestData },
|
|
1860
1951
|
);
|
|
1861
1952
|
} catch (error) {
|
|
1953
|
+
const errMsg = (error as Error)?.message || '';
|
|
1862
1954
|
// 等于NONE_ERROR_MESSAGE,代码该异步行为已经完成,不需要做处理
|
|
1863
|
-
if (error &&
|
|
1955
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
1864
1956
|
if (error && (error as Error).message !== this.PRE_ERROR_MESSAGE) {
|
|
1865
1957
|
aiChat.replaceMessage({
|
|
1866
1958
|
messageid: id,
|
|
@@ -1877,6 +1969,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1877
1969
|
{
|
|
1878
1970
|
...lastMessage,
|
|
1879
1971
|
state: 40,
|
|
1972
|
+
errorText: ibiz.i18n.t('app.aiError'),
|
|
1880
1973
|
},
|
|
1881
1974
|
false,
|
|
1882
1975
|
);
|
|
@@ -2162,12 +2255,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
2162
2255
|
}
|
|
2163
2256
|
};
|
|
2164
2257
|
// 消息通知工具类
|
|
2165
|
-
chatOptions.utils =
|
|
2166
|
-
message: ibiz.message,
|
|
2167
|
-
notification: ibiz.notification,
|
|
2168
|
-
confirm: ibiz.confirm,
|
|
2169
|
-
};
|
|
2170
|
-
|
|
2258
|
+
chatOptions.utils = this.getAIChatUtils();
|
|
2171
2259
|
return { containerOptions, topicOptions, chatOptions };
|
|
2172
2260
|
}
|
|
2173
2261
|
|
|
@@ -2739,6 +2827,22 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
2739
2827
|
);
|
|
2740
2828
|
return response.data;
|
|
2741
2829
|
};
|
|
2830
|
+
// 解压文件
|
|
2831
|
+
fileSystemOptions.unZipFile = async (
|
|
2832
|
+
ctx: IContext,
|
|
2833
|
+
param: IParams,
|
|
2834
|
+
other: IParams,
|
|
2835
|
+
): Promise<IData> => {
|
|
2836
|
+
const deService = await ibiz.hub
|
|
2837
|
+
.getApp(ctx.srfappid)
|
|
2838
|
+
.deService.getService(ctx, param.appDataEntityId);
|
|
2839
|
+
const response = await deService.aiChatProject(
|
|
2840
|
+
ctx,
|
|
2841
|
+
{ srfactag: param.srfactag },
|
|
2842
|
+
{ action: 'UNZIP', ...other },
|
|
2843
|
+
);
|
|
2844
|
+
return response.data;
|
|
2845
|
+
};
|
|
2742
2846
|
// 读取文件内容
|
|
2743
2847
|
fileSystemOptions.readFile = async (
|
|
2744
2848
|
ctx: IContext,
|