@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.
@@ -12,6 +12,48 @@ var __publicField = (obj, key, value) => {
12
12
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
13
  return value;
14
14
  };
15
+ async function openAsyncActionModal(asyncAction) {
16
+ if (isNil(asyncAction.actiontype) || asyncAction.actiontype === "asyncaction") {
17
+ ibiz.overlay.modal(
18
+ (modal) => {
19
+ return h(AsyncActionResult, {
20
+ asyncAction,
21
+ modal
22
+ });
23
+ },
24
+ {},
25
+ { width: "80%", height: "80%" }
26
+ );
27
+ return true;
28
+ }
29
+ if (asyncAction.actiontype === "DEEXPORTDATA") {
30
+ ibiz.overlay.modal(
31
+ (modal) => {
32
+ return h(AsyncDataExport, {
33
+ asyncAction,
34
+ modal
35
+ });
36
+ },
37
+ {},
38
+ { width: "80%", height: "80%" }
39
+ );
40
+ return true;
41
+ }
42
+ if (isObject(asyncAction.actionresult)) {
43
+ ibiz.overlay.modal(
44
+ (modal) => {
45
+ return h(AsyncActionPreview, {
46
+ asyncAction,
47
+ modal
48
+ });
49
+ },
50
+ {},
51
+ { width: "80%", height: "80%" }
52
+ );
53
+ return true;
54
+ }
55
+ return false;
56
+ }
15
57
  class AsyncActionProvider {
16
58
  constructor() {
17
59
  __publicField(this, "component", AsyncAction);
@@ -23,47 +65,8 @@ class AsyncActionProvider {
23
65
  });
24
66
  }
25
67
  async onClick(asyncAction, _event) {
26
- if (isNil(asyncAction.actiontype)) {
27
- ibiz.overlay.modal(
28
- (modal) => {
29
- return h(AsyncActionResult, {
30
- asyncAction,
31
- modal
32
- });
33
- },
34
- {},
35
- { width: "80%", height: "80%" }
36
- );
37
- return true;
38
- }
39
- if (asyncAction.actiontype === "DEEXPORTDATA") {
40
- ibiz.overlay.modal(
41
- (modal) => {
42
- return h(AsyncDataExport, {
43
- asyncAction,
44
- modal
45
- });
46
- },
47
- {},
48
- { width: "80%", height: "80%" }
49
- );
50
- return true;
51
- }
52
- if (isObject(asyncAction.actionresult)) {
53
- ibiz.overlay.modal(
54
- (modal) => {
55
- return h(AsyncActionPreview, {
56
- asyncAction,
57
- modal
58
- });
59
- },
60
- {},
61
- { width: "80%", height: "80%" }
62
- );
63
- return true;
64
- }
65
- return false;
68
+ return openAsyncActionModal(asyncAction);
66
69
  }
67
70
  }
68
71
 
69
- export { AsyncActionProvider };
72
+ export { AsyncActionProvider, openAsyncActionModal };
@@ -1,9 +1,11 @@
1
- import { h } from 'vue';
1
+ import { h, render, createVNode } from 'vue';
2
2
  import { createUUID } from 'qx-util';
3
- import { ConfigService, UIActionUtil, SysUIActionTag, parseViewProtocol, OpenAppViewCommand, UtilService, AIUtilService } from '@ibiz-template/runtime';
3
+ import { ConfigService, UIActionUtil, SysUIActionTag, parseViewProtocol, OpenAppViewCommand, UtilService, AIUtilService, Modal, ViewMode } from '@ibiz-template/runtime';
4
4
  import { StringUtil, IBizContext } from '@ibiz-template/core';
5
+ import { IBizViewShell } from '@ibiz-template/vue3-util';
5
6
  import { isNotNil } from 'ramda';
6
7
  import { AIFeedback } from './ai-feedback/ai-feedback.mjs';
8
+ import { openAsyncActionModal } from '../../panel-component/user-message/async-action/async-action/async-action.provider.mjs';
7
9
 
8
10
  "use strict";
9
11
  var __defProp = Object.defineProperty;
@@ -13,7 +15,13 @@ var __publicField = (obj, key, value) => {
13
15
  return value;
14
16
  };
15
17
  class AIChatUtil {
16
- constructor() {
18
+ /**
19
+ * Creates an instance of AIChatUtil.
20
+ * @param {App} App vue App
21
+ * @memberof AIChatUtil
22
+ */
23
+ constructor(App2) {
24
+ this.App = App2;
17
25
  __publicField(this, "TOPIC_CHAT_PREFIX", "topic");
18
26
  __publicField(this, "INLINE_CHAT_SUFFIX", "inline");
19
27
  __publicField(this, "TEMP_CHAT_SUFFIX", "temp");
@@ -21,10 +29,19 @@ class AIChatUtil {
21
29
  __publicField(this, "PRE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: application/json;charset=UTF-8");
22
30
  // 无流内容回来
23
31
  __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);
32
+ // 各 asyncActionID 对应的回调集合(同一 ID 可能被多处注册不同回调),回调入参为最新异步作业对象
33
+ __publicField(this, "asyncActionCallBackMap", /* @__PURE__ */ new Map());
34
+ ibiz.mc.command.asyncAction.on((msg) => {
35
+ if (!msg.data || msg.subtype !== "ASYNCACTION")
36
+ return;
37
+ const action = msg.data;
38
+ if (action.actiontype === "ASYNCCHATCOMPLETION")
39
+ return;
40
+ const callbacks = this.asyncActionCallBackMap.get(action.asyncacitonid);
41
+ if (callbacks) {
42
+ callbacks.forEach((cb) => cb(action));
43
+ }
44
+ });
28
45
  }
29
46
  /**
30
47
  * @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
@@ -93,7 +110,7 @@ class AIChatUtil {
93
110
  };
94
111
  }
95
112
  /**
96
- * @description 网络中断(network error)后按 asyncacitonid 自动续传,指数退避重试;成功返回 true,不可恢复/重试耗尽返回 false 交回调用方走既有错误处理
113
+ * @description 网络中断(network error)后按 asyncacitonid 自动续传一次;成功返回 true,失败返回 false 交回调用方走既有错误处理
97
114
  * @param {any} aiChat 单实例聊天总控
98
115
  * @param {IContext} ctx 上下文
99
116
  * @param {IParams} param 视图参数
@@ -105,49 +122,40 @@ class AIChatUtil {
105
122
  * @memberof AIChatUtil
106
123
  */
107
124
  async autoResumeChat(aiChat, ctx, param, deService, state, resumeInfo, onMsg) {
108
- var _a;
125
+ var _a, _b;
109
126
  (_a = state.abortController) == null ? void 0 : _a.abort();
110
127
  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
- }
128
+ try {
129
+ const resumeRequestData = {
130
+ asyncacitonid: resumeInfo.asyncacitonid
131
+ };
132
+ if (resumeInfo.sessionid) {
133
+ resumeRequestData.sessionid = resumeInfo.sessionid;
134
+ }
135
+ if (resumeInfo.srfaiagent) {
136
+ resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
137
+ }
138
+ if (resumeInfo.srfproject) {
139
+ resumeRequestData.srfproject = resumeInfo.srfproject;
140
+ }
141
+ await deService.aiResumeSse(
142
+ onMsg,
143
+ state.abortController,
144
+ ctx,
145
+ { srfactag: param.srfactag },
146
+ { ...resumeRequestData }
147
+ );
148
+ return true;
149
+ } catch (resumeError) {
150
+ if ((resumeError == null ? void 0 : resumeError.name) === "AbortError") {
151
+ return false;
152
+ }
153
+ (_b = state.abortController) == null ? void 0 : _b.abort();
154
+ if ((resumeError == null ? void 0 : resumeError.message) === this.NONE_ERROR_MESSAGE) {
155
+ aiChat.setActiveAsyncacitonId("");
148
156
  }
157
+ return false;
149
158
  }
150
- return false;
151
159
  }
152
160
  /**
153
161
  * 获取AI聊天对象
@@ -333,6 +341,7 @@ class AIChatUtil {
333
341
  locale: ibiz.i18n.getLang(),
334
342
  enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
335
343
  projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
344
+ knowledgeBaseView: editorParams.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
336
345
  selectAIProjectId: editorParams.srfselectaiprojectid
337
346
  };
338
347
  if (editorParams.srfaiappendcurdata) {
@@ -451,6 +460,16 @@ class AIChatUtil {
451
460
  editorParams
452
461
  );
453
462
  };
463
+ chatOptions.openEmbedView = async (ctx, param, viewId, container, selectedData, callback) => {
464
+ await this.openEmbedView(
465
+ ctx,
466
+ param,
467
+ viewId,
468
+ container,
469
+ selectedData,
470
+ callback
471
+ );
472
+ };
454
473
  chatOptions.fetchKnowledgeBaseList = (args2 = {}) => {
455
474
  return this.getKnowledgeBaseList(context, params, editorParams, args2);
456
475
  };
@@ -484,6 +503,7 @@ class AIChatUtil {
484
503
  }
485
504
  const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
486
505
  chatOptions.fileSystemOptions = fileSystemOptions;
506
+ chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
487
507
  chatOptions.history = async (ctx, param, other) => {
488
508
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
489
509
  const historyRequestData = {};
@@ -1081,8 +1101,11 @@ class AIChatUtil {
1081
1101
  locale: ibiz.i18n.getLang(),
1082
1102
  enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
1083
1103
  projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
1104
+ knowledgeBaseView: params.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
1084
1105
  selectAIProjectId: params.srfselectaiprojectid
1085
1106
  };
1107
+ if (params.hasOwnProperty("srfaiknowledgebaseview"))
1108
+ delete params.srfaiknowledgebaseview;
1086
1109
  if (params.hasOwnProperty("srfselectaiprojectid"))
1087
1110
  delete params.srfselectaiprojectid;
1088
1111
  if (params.hasOwnProperty("srfenableaiprojectselect"))
@@ -1225,6 +1248,16 @@ class AIChatUtil {
1225
1248
  } else {
1226
1249
  chatOptions.enableWorkSpace = ibiz.config.common.aiEnableWorkSpace;
1227
1250
  }
1251
+ chatOptions.openEmbedView = async (ctx, param, viewId, container, selectedData, callback) => {
1252
+ await this.openEmbedView(
1253
+ ctx,
1254
+ param,
1255
+ viewId,
1256
+ container,
1257
+ selectedData,
1258
+ callback
1259
+ );
1260
+ };
1228
1261
  chatOptions.fetchAgentList = (args2 = {}) => {
1229
1262
  const { query, agentid } = args2;
1230
1263
  return this.getAIAgentList(context, {
@@ -1265,6 +1298,7 @@ class AIChatUtil {
1265
1298
  }
1266
1299
  const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
1267
1300
  chatOptions.fileSystemOptions = fileSystemOptions;
1301
+ chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
1268
1302
  chatOptions.history = async (ctx, param, other) => {
1269
1303
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1270
1304
  const historyRequestData = {};
@@ -2202,6 +2236,77 @@ class AIChatUtil {
2202
2236
  };
2203
2237
  return fileSystemOptions;
2204
2238
  }
2239
+ /**
2240
+ * @description 打开嵌入视图
2241
+ * @private
2242
+ * @param {IContext} context 上下文
2243
+ * @param {IParams} params 视图参数
2244
+ * @param {string} viewId 视图标识
2245
+ * @param {HTMLElement} container 视图挂载容器
2246
+ * @param {IData[]} [selectedData] 选中数据
2247
+ * @param {(result: IModalData) => void} [callback] 回调
2248
+ * @returns {*} {Promise<void>}
2249
+ * @memberof AIChatUtil
2250
+ */
2251
+ async openEmbedView(context, params, viewId, container, selectedData, callback) {
2252
+ render(null, container);
2253
+ const modal = new Modal({
2254
+ mode: ViewMode.EMBED,
2255
+ viewUsage: 2,
2256
+ dismiss: (result) => {
2257
+ callback == null ? void 0 : callback(result);
2258
+ render(null, container);
2259
+ }
2260
+ });
2261
+ const modelData = await ibiz.hub.getAppView(viewId);
2262
+ const vNode = createVNode(IBizViewShell, {
2263
+ modal,
2264
+ modelData,
2265
+ context,
2266
+ params: { ...params, checkstrictly: true },
2267
+ style: {
2268
+ height: "".concat(modelData.height || 400, "px")
2269
+ },
2270
+ state: {
2271
+ selectedData
2272
+ }
2273
+ });
2274
+ vNode.appContext = this.App._context;
2275
+ render(vNode, container);
2276
+ }
2277
+ /**
2278
+ * @description 获取异步行为配置
2279
+ * @returns {*} {Promise<IData>}
2280
+ * @memberof AIChatUtil
2281
+ */
2282
+ async getAIAsyncActionOptions() {
2283
+ const asyncActionOptions = {};
2284
+ asyncActionOptions.getLastAsyncAction = async (asyncActionID) => {
2285
+ const result = await ibiz.hub.notice.asyncAction.service.get(asyncActionID);
2286
+ if (result.ok && result.data) {
2287
+ return result.data;
2288
+ }
2289
+ return null;
2290
+ };
2291
+ asyncActionOptions.registerCallBack = (asyncActionID, callback) => {
2292
+ let callbacks = this.asyncActionCallBackMap.get(asyncActionID);
2293
+ if (!callbacks) {
2294
+ callbacks = /* @__PURE__ */ new Set();
2295
+ this.asyncActionCallBackMap.set(asyncActionID, callbacks);
2296
+ }
2297
+ callbacks.add(callback);
2298
+ return () => {
2299
+ callbacks.delete(callback);
2300
+ if (!callbacks.size) {
2301
+ this.asyncActionCallBackMap.delete(asyncActionID);
2302
+ }
2303
+ };
2304
+ };
2305
+ asyncActionOptions.onPreview = async (asyncAction, _event) => {
2306
+ return openAsyncActionModal(asyncAction);
2307
+ };
2308
+ return asyncActionOptions;
2309
+ }
2205
2310
  }
2206
2311
 
2207
2312
  export { AIChatUtil };
@@ -89,7 +89,7 @@ async function runApp(plugins, opts) {
89
89
  ibiz.overlay = new OverlayController();
90
90
  ibiz.inLineAIUtil = new InLineAIUtil();
91
91
  ibiz.screenShotUtil = new ScreenShotUtil();
92
- ibiz.aiChatUtil = new AIChatUtil();
92
+ ibiz.aiChatUtil = new AIChatUtil(app);
93
93
  ibiz.util.text.format = (value, code) => {
94
94
  return app.config.globalProperties.$textFormat(value, code);
95
95
  };
@@ -14,6 +14,48 @@ var __publicField = (obj, key, value) => {
14
14
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
15
  return value;
16
16
  };
17
+ async function openAsyncActionModal(asyncAction) {
18
+ if (lodashEs.isNil(asyncAction.actiontype) || asyncAction.actiontype === "asyncaction") {
19
+ ibiz.overlay.modal(
20
+ (modal) => {
21
+ return vue.h(asyncActionResult.AsyncActionResult, {
22
+ asyncAction,
23
+ modal
24
+ });
25
+ },
26
+ {},
27
+ { width: "80%", height: "80%" }
28
+ );
29
+ return true;
30
+ }
31
+ if (asyncAction.actiontype === "DEEXPORTDATA") {
32
+ ibiz.overlay.modal(
33
+ (modal) => {
34
+ return vue.h(asyncDataExport.AsyncDataExport, {
35
+ asyncAction,
36
+ modal
37
+ });
38
+ },
39
+ {},
40
+ { width: "80%", height: "80%" }
41
+ );
42
+ return true;
43
+ }
44
+ if (lodashEs.isObject(asyncAction.actionresult)) {
45
+ ibiz.overlay.modal(
46
+ (modal) => {
47
+ return vue.h(asyncActionPreview.AsyncActionPreview, {
48
+ asyncAction,
49
+ modal
50
+ });
51
+ },
52
+ {},
53
+ { width: "80%", height: "80%" }
54
+ );
55
+ return true;
56
+ }
57
+ return false;
58
+ }
17
59
  class AsyncActionProvider {
18
60
  constructor() {
19
61
  __publicField(this, "component", asyncAction.AsyncAction);
@@ -25,47 +67,9 @@ class AsyncActionProvider {
25
67
  });
26
68
  }
27
69
  async onClick(asyncAction, _event) {
28
- if (lodashEs.isNil(asyncAction.actiontype)) {
29
- ibiz.overlay.modal(
30
- (modal) => {
31
- return vue.h(asyncActionResult.AsyncActionResult, {
32
- asyncAction,
33
- modal
34
- });
35
- },
36
- {},
37
- { width: "80%", height: "80%" }
38
- );
39
- return true;
40
- }
41
- if (asyncAction.actiontype === "DEEXPORTDATA") {
42
- ibiz.overlay.modal(
43
- (modal) => {
44
- return vue.h(asyncDataExport.AsyncDataExport, {
45
- asyncAction,
46
- modal
47
- });
48
- },
49
- {},
50
- { width: "80%", height: "80%" }
51
- );
52
- return true;
53
- }
54
- if (lodashEs.isObject(asyncAction.actionresult)) {
55
- ibiz.overlay.modal(
56
- (modal) => {
57
- return vue.h(asyncActionPreview.AsyncActionPreview, {
58
- asyncAction,
59
- modal
60
- });
61
- },
62
- {},
63
- { width: "80%", height: "80%" }
64
- );
65
- return true;
66
- }
67
- return false;
70
+ return openAsyncActionModal(asyncAction);
68
71
  }
69
72
  }
70
73
 
71
74
  exports.AsyncActionProvider = AsyncActionProvider;
75
+ exports.openAsyncActionModal = openAsyncActionModal;