@ibiz-template/vue3-components 0.7.41-alpha.166 → 0.7.41-alpha.167
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-CCoBeNIV.js → index-DXoEi5m-.js} +28 -28
- package/dist/{index.es-D1vng-7i.js → index.es-nZgG-TGm.js} +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/{wang-editor-B0ZpE6o-.js → wang-editor-CK60NH54.js} +1 -1
- package/dist/{xlsx-util-Djaaq9Po.js → xlsx-util-5Xgq-UOe.js} +1 -1
- package/es/panel-component/user-message/async-action/async-action/async-action.provider.mjs +44 -41
- package/es/util/ai-chat-util/ai-chat-util.mjs +152 -47
- package/es/web-app/main.mjs +1 -1
- package/lib/panel-component/user-message/async-action/async-action/async-action.provider.cjs +44 -40
- package/lib/util/ai-chat-util/ai-chat-util.cjs +150 -45
- package/lib/web-app/main.cjs +1 -1
- package/package.json +5 -5
- package/src/panel-component/user-message/async-action/async-action/async-action.provider.ts +58 -42
- package/src/util/ai-chat-util/ai-chat-util.ts +212 -53
- package/src/web-app/main.ts +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/* eslint-disable no-prototype-builtins */
|
|
5
5
|
/* eslint-disable no-unused-vars */
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
-
import { h } from 'vue';
|
|
7
|
+
import { App, createVNode, h, render } from 'vue';
|
|
8
8
|
import { AxiosProgressEvent } from 'axios';
|
|
9
9
|
import { createUUID } from 'qx-util';
|
|
10
10
|
import {
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
IAppDEUIActionGroupDetail,
|
|
14
14
|
} from '@ibiz/model-core';
|
|
15
15
|
import {
|
|
16
|
+
Modal,
|
|
16
17
|
IModal,
|
|
18
|
+
ViewMode,
|
|
17
19
|
IModalData,
|
|
18
20
|
UtilService,
|
|
19
21
|
UIActionUtil,
|
|
@@ -36,9 +38,12 @@ import {
|
|
|
36
38
|
IBizContext,
|
|
37
39
|
IChatMessage,
|
|
38
40
|
IPortalAsyncAction,
|
|
41
|
+
IPortalMessage,
|
|
39
42
|
} from '@ibiz-template/core';
|
|
43
|
+
import { IBizViewShell } from '@ibiz-template/vue3-util';
|
|
40
44
|
import { isNotNil } from 'ramda';
|
|
41
45
|
import { AIFeedback } from './ai-feedback/ai-feedback';
|
|
46
|
+
import { openAsyncActionModal } from '../../panel-component/user-message/async-action/async-action/async-action.provider';
|
|
42
47
|
|
|
43
48
|
export class AIChatUtil implements IApiAIChatUtil {
|
|
44
49
|
private TOPIC_CHAT_PREFIX: string = 'topic';
|
|
@@ -56,11 +61,30 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
56
61
|
private NONE_ERROR_MESSAGE: string =
|
|
57
62
|
'Expected content-type to be text/event-stream, Actual: null';
|
|
58
63
|
|
|
59
|
-
//
|
|
60
|
-
private
|
|
64
|
+
// 各 asyncActionID 对应的回调集合(同一 ID 可能被多处注册不同回调),回调入参为最新异步作业对象
|
|
65
|
+
private asyncActionCallBackMap: Map<
|
|
66
|
+
string,
|
|
67
|
+
Set<(action: IPortalAsyncAction) => void>
|
|
68
|
+
> = new Map();
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Creates an instance of AIChatUtil.
|
|
72
|
+
* @param {App} App vue App
|
|
73
|
+
* @memberof AIChatUtil
|
|
74
|
+
*/
|
|
75
|
+
constructor(private App: App) {
|
|
76
|
+
// 全局监听器仅注册一次,按 asyncacitonid 分发到对应回调集合
|
|
77
|
+
ibiz.mc.command.asyncAction.on((msg: IPortalMessage) => {
|
|
78
|
+
if (!msg.data || msg.subtype !== 'ASYNCACTION') return;
|
|
79
|
+
const action = msg.data as IPortalAsyncAction;
|
|
80
|
+
// 异步交谈补全操作拦截,不做分发(与全局异步作业监听的处理保持一致)
|
|
81
|
+
if (action.actiontype === 'ASYNCCHATCOMPLETION') return;
|
|
82
|
+
const callbacks = this.asyncActionCallBackMap.get(action.asyncacitonid);
|
|
83
|
+
if (callbacks) {
|
|
84
|
+
callbacks.forEach(cb => cb(action));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
64
88
|
|
|
65
89
|
/**
|
|
66
90
|
* @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
|
|
@@ -146,7 +170,7 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
146
170
|
}
|
|
147
171
|
|
|
148
172
|
/**
|
|
149
|
-
* @description 网络中断(network error)后按 asyncacitonid
|
|
173
|
+
* @description 网络中断(network error)后按 asyncacitonid 自动续传一次;成功返回 true,失败返回 false 交回调用方走既有错误处理
|
|
150
174
|
* @param {any} aiChat 单实例聊天总控
|
|
151
175
|
* @param {IContext} ctx 上下文
|
|
152
176
|
* @param {IParams} param 视图参数
|
|
@@ -173,55 +197,43 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
173
197
|
): Promise<boolean> {
|
|
174
198
|
// 续传前先释放旧 SSE 连接,避免旧连接未关闭影响新连接建立
|
|
175
199
|
state.abortController?.abort();
|
|
176
|
-
//
|
|
177
|
-
//
|
|
200
|
+
// 新建 AbortController 并存回 state:用户点停止时,abortQuestion abort 的即是该实例,
|
|
201
|
+
// 请求携带已中止信号会立即抛 AbortError 结束续传
|
|
178
202
|
state.abortController = new AbortController();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
// 其余(网络仍断等)继续下一轮退避重试
|
|
203
|
+
try {
|
|
204
|
+
const resumeRequestData: IData = {
|
|
205
|
+
asyncacitonid: resumeInfo.asyncacitonid,
|
|
206
|
+
};
|
|
207
|
+
if (resumeInfo.sessionid) {
|
|
208
|
+
resumeRequestData.sessionid = resumeInfo.sessionid;
|
|
209
|
+
}
|
|
210
|
+
if (resumeInfo.srfaiagent) {
|
|
211
|
+
resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
|
|
212
|
+
}
|
|
213
|
+
if (resumeInfo.srfproject) {
|
|
214
|
+
resumeRequestData.srfproject = resumeInfo.srfproject;
|
|
215
|
+
}
|
|
216
|
+
await deService.aiResumeSse(
|
|
217
|
+
onMsg,
|
|
218
|
+
state.abortController,
|
|
219
|
+
ctx,
|
|
220
|
+
{ srfactag: param.srfactag },
|
|
221
|
+
{ ...resumeRequestData },
|
|
222
|
+
);
|
|
223
|
+
return true;
|
|
224
|
+
} catch (resumeError) {
|
|
225
|
+
// 用户已点停止,不再续传
|
|
226
|
+
if ((resumeError as Error)?.name === 'AbortError') {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
// 续传失败(网络仍断、后端异步动作已完成等),中止续传连接后交回调用方走既有错误处理
|
|
230
|
+
state.abortController?.abort();
|
|
231
|
+
// 后端异步动作已完成,无可恢复内容,清空异步消息任务
|
|
232
|
+
if ((resumeError as Error)?.message === this.NONE_ERROR_MESSAGE) {
|
|
233
|
+
aiChat.setActiveAsyncacitonId('');
|
|
222
234
|
}
|
|
235
|
+
return false;
|
|
223
236
|
}
|
|
224
|
-
return false;
|
|
225
237
|
}
|
|
226
238
|
|
|
227
239
|
/**
|
|
@@ -498,6 +510,9 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
498
510
|
projectSelectPlaceholder:
|
|
499
511
|
editorParams.srfprojectselectplaceholder ||
|
|
500
512
|
ibiz.config.common.aiProjectSelectPlaceholder,
|
|
513
|
+
knowledgeBaseView:
|
|
514
|
+
editorParams.srfaiknowledgebaseview ||
|
|
515
|
+
ibiz.config.common.aiKnowledgeBaseView,
|
|
501
516
|
selectAIProjectId: editorParams.srfselectaiprojectid,
|
|
502
517
|
};
|
|
503
518
|
// 编辑器参数srfaiappendcurdata,是否传入对象参数,用于历史查询传参
|
|
@@ -659,6 +674,24 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
659
674
|
editorParams,
|
|
660
675
|
);
|
|
661
676
|
};
|
|
677
|
+
// 打开视图
|
|
678
|
+
chatOptions.openEmbedView = async (
|
|
679
|
+
ctx: IContext,
|
|
680
|
+
param: IParams,
|
|
681
|
+
viewId: string,
|
|
682
|
+
container: HTMLElement,
|
|
683
|
+
selectedData: IData[],
|
|
684
|
+
callback?: (result: IModalData) => void,
|
|
685
|
+
) => {
|
|
686
|
+
await this.openEmbedView(
|
|
687
|
+
ctx,
|
|
688
|
+
param,
|
|
689
|
+
viewId,
|
|
690
|
+
container,
|
|
691
|
+
selectedData,
|
|
692
|
+
callback,
|
|
693
|
+
);
|
|
694
|
+
};
|
|
662
695
|
// 知识库
|
|
663
696
|
chatOptions.fetchKnowledgeBaseList = (args: IParams = {}) => {
|
|
664
697
|
return this.getKnowledgeBaseList(context, params, editorParams, args);
|
|
@@ -705,6 +738,9 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
705
738
|
await this.getAIFileSystemOptions(filePreviewMode);
|
|
706
739
|
chatOptions.fileSystemOptions = fileSystemOptions;
|
|
707
740
|
|
|
741
|
+
// 异步任务参数
|
|
742
|
+
chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
|
|
743
|
+
|
|
708
744
|
// 请求历史
|
|
709
745
|
chatOptions.history = async (
|
|
710
746
|
ctx: IContext,
|
|
@@ -1451,8 +1487,12 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1451
1487
|
projectSelectPlaceholder:
|
|
1452
1488
|
params.srfprojectselectplaceholder ||
|
|
1453
1489
|
ibiz.config.common.aiProjectSelectPlaceholder,
|
|
1490
|
+
knowledgeBaseView:
|
|
1491
|
+
params.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
|
|
1454
1492
|
selectAIProjectId: params.srfselectaiprojectid,
|
|
1455
1493
|
};
|
|
1494
|
+
if (params.hasOwnProperty('srfaiknowledgebaseview'))
|
|
1495
|
+
delete params.srfaiknowledgebaseview;
|
|
1456
1496
|
if (params.hasOwnProperty('srfselectaiprojectid'))
|
|
1457
1497
|
delete params.srfselectaiprojectid;
|
|
1458
1498
|
if (params.hasOwnProperty('srfenableaiprojectselect'))
|
|
@@ -1631,7 +1671,24 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1631
1671
|
} else {
|
|
1632
1672
|
chatOptions.enableWorkSpace = ibiz.config.common.aiEnableWorkSpace;
|
|
1633
1673
|
}
|
|
1634
|
-
|
|
1674
|
+
// 打开视图
|
|
1675
|
+
chatOptions.openEmbedView = async (
|
|
1676
|
+
ctx: IContext,
|
|
1677
|
+
param: IParams,
|
|
1678
|
+
viewId: string,
|
|
1679
|
+
container: HTMLElement,
|
|
1680
|
+
selectedData: IData[],
|
|
1681
|
+
callback?: (result: IModalData) => void,
|
|
1682
|
+
) => {
|
|
1683
|
+
await this.openEmbedView(
|
|
1684
|
+
ctx,
|
|
1685
|
+
param,
|
|
1686
|
+
viewId,
|
|
1687
|
+
container,
|
|
1688
|
+
selectedData,
|
|
1689
|
+
callback,
|
|
1690
|
+
);
|
|
1691
|
+
};
|
|
1635
1692
|
// 智能体选项(由内部获取,优化打开速度)
|
|
1636
1693
|
chatOptions.fetchAgentList = (args: IParams = {}) => {
|
|
1637
1694
|
const { query, agentid } = args;
|
|
@@ -1685,6 +1742,9 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1685
1742
|
await this.getAIFileSystemOptions(filePreviewMode);
|
|
1686
1743
|
chatOptions.fileSystemOptions = fileSystemOptions;
|
|
1687
1744
|
|
|
1745
|
+
// 异步任务参数
|
|
1746
|
+
chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
|
|
1747
|
+
|
|
1688
1748
|
// 查询历史
|
|
1689
1749
|
chatOptions.history = async (
|
|
1690
1750
|
ctx: IContext,
|
|
@@ -2901,4 +2961,103 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
2901
2961
|
};
|
|
2902
2962
|
return fileSystemOptions;
|
|
2903
2963
|
}
|
|
2964
|
+
|
|
2965
|
+
/**
|
|
2966
|
+
* @description 打开嵌入视图
|
|
2967
|
+
* @private
|
|
2968
|
+
* @param {IContext} context 上下文
|
|
2969
|
+
* @param {IParams} params 视图参数
|
|
2970
|
+
* @param {string} viewId 视图标识
|
|
2971
|
+
* @param {HTMLElement} container 视图挂载容器
|
|
2972
|
+
* @param {IData[]} [selectedData] 选中数据
|
|
2973
|
+
* @param {(result: IModalData) => void} [callback] 回调
|
|
2974
|
+
* @returns {*} {Promise<void>}
|
|
2975
|
+
* @memberof AIChatUtil
|
|
2976
|
+
*/
|
|
2977
|
+
private async openEmbedView(
|
|
2978
|
+
context: IContext,
|
|
2979
|
+
params: IParams,
|
|
2980
|
+
viewId: string,
|
|
2981
|
+
container: HTMLElement,
|
|
2982
|
+
selectedData: IData[],
|
|
2983
|
+
callback?: (result: IModalData) => void,
|
|
2984
|
+
): Promise<void> {
|
|
2985
|
+
// 1. 先安全卸载之前的视图
|
|
2986
|
+
render(null, container);
|
|
2987
|
+
// 2. 绘制视图
|
|
2988
|
+
const modal = new Modal({
|
|
2989
|
+
mode: ViewMode.EMBED,
|
|
2990
|
+
viewUsage: 2,
|
|
2991
|
+
dismiss: (result: IModalData) => {
|
|
2992
|
+
callback?.(result);
|
|
2993
|
+
// 视图关闭时卸载
|
|
2994
|
+
render(null, container);
|
|
2995
|
+
},
|
|
2996
|
+
});
|
|
2997
|
+
const modelData = await ibiz.hub.getAppView(viewId);
|
|
2998
|
+
const vNode = createVNode(IBizViewShell, {
|
|
2999
|
+
modal,
|
|
3000
|
+
modelData,
|
|
3001
|
+
context,
|
|
3002
|
+
params: { ...params, checkstrictly: true },
|
|
3003
|
+
style: {
|
|
3004
|
+
height: `${modelData.height || 400}px`,
|
|
3005
|
+
},
|
|
3006
|
+
state: {
|
|
3007
|
+
selectedData,
|
|
3008
|
+
},
|
|
3009
|
+
});
|
|
3010
|
+
// 3. 设置应用上下文
|
|
3011
|
+
vNode.appContext = this.App._context;
|
|
3012
|
+
// 4. 挂载视图
|
|
3013
|
+
render(vNode, container);
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
/**
|
|
3017
|
+
* @description 获取异步行为配置
|
|
3018
|
+
* @returns {*} {Promise<IData>}
|
|
3019
|
+
* @memberof AIChatUtil
|
|
3020
|
+
*/
|
|
3021
|
+
async getAIAsyncActionOptions(): Promise<IData> {
|
|
3022
|
+
const asyncActionOptions: IData = {};
|
|
3023
|
+
// 获取最后一次执行异步行为对象
|
|
3024
|
+
asyncActionOptions.getLastAsyncAction = async (
|
|
3025
|
+
asyncActionID: string,
|
|
3026
|
+
): Promise<IPortalAsyncAction | null> => {
|
|
3027
|
+
const result =
|
|
3028
|
+
await ibiz.hub.notice.asyncAction.service.get(asyncActionID);
|
|
3029
|
+
if (result.ok && result.data) {
|
|
3030
|
+
return result.data;
|
|
3031
|
+
}
|
|
3032
|
+
return null;
|
|
3033
|
+
};
|
|
3034
|
+
// 注册回调,返回销毁函数
|
|
3035
|
+
asyncActionOptions.registerCallBack = (
|
|
3036
|
+
asyncActionID: string,
|
|
3037
|
+
callback: (action: IPortalAsyncAction) => void,
|
|
3038
|
+
) => {
|
|
3039
|
+
let callbacks = this.asyncActionCallBackMap.get(asyncActionID);
|
|
3040
|
+
if (!callbacks) {
|
|
3041
|
+
callbacks = new Set();
|
|
3042
|
+
this.asyncActionCallBackMap.set(asyncActionID, callbacks);
|
|
3043
|
+
}
|
|
3044
|
+
// 同一回调重复注册时幂等跳过
|
|
3045
|
+
callbacks.add(callback);
|
|
3046
|
+
// 返回取消订阅函数,供外部在不再需要时清理
|
|
3047
|
+
return () => {
|
|
3048
|
+
callbacks!.delete(callback);
|
|
3049
|
+
if (!callbacks!.size) {
|
|
3050
|
+
this.asyncActionCallBackMap.delete(asyncActionID);
|
|
3051
|
+
}
|
|
3052
|
+
};
|
|
3053
|
+
};
|
|
3054
|
+
// 预览异步行为
|
|
3055
|
+
asyncActionOptions.onPreview = async (
|
|
3056
|
+
asyncAction: IPortalAsyncAction,
|
|
3057
|
+
_event: MouseEvent,
|
|
3058
|
+
): Promise<boolean> => {
|
|
3059
|
+
return openAsyncActionModal(asyncAction);
|
|
3060
|
+
};
|
|
3061
|
+
return asyncActionOptions;
|
|
3062
|
+
}
|
|
2904
3063
|
}
|
package/src/web-app/main.ts
CHANGED
|
@@ -133,7 +133,7 @@ export async function runApp(
|
|
|
133
133
|
ibiz.overlay = new OverlayController();
|
|
134
134
|
ibiz.inLineAIUtil = new InLineAIUtil();
|
|
135
135
|
ibiz.screenShotUtil = new ScreenShotUtil();
|
|
136
|
-
ibiz.aiChatUtil = new AIChatUtil();
|
|
136
|
+
ibiz.aiChatUtil = new AIChatUtil(app);
|
|
137
137
|
ibiz.util.text.format = (value, code): string => {
|
|
138
138
|
return app.config.globalProperties.$textFormat(value, code);
|
|
139
139
|
};
|