@ibiz-template/vue3-components 0.7.41-alpha.166 → 0.7.41-alpha.168

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;
148
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("");
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,7 @@ class AIChatUtil {
451
460
  editorParams
452
461
  );
453
462
  };
463
+ chatOptions.openEmbedView = this.openEmbedView.bind(this);
454
464
  chatOptions.fetchKnowledgeBaseList = (args2 = {}) => {
455
465
  return this.getKnowledgeBaseList(context, params, editorParams, args2);
456
466
  };
@@ -484,6 +494,7 @@ class AIChatUtil {
484
494
  }
485
495
  const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
486
496
  chatOptions.fileSystemOptions = fileSystemOptions;
497
+ chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
487
498
  chatOptions.history = async (ctx, param, other) => {
488
499
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
489
500
  const historyRequestData = {};
@@ -1081,8 +1092,11 @@ class AIChatUtil {
1081
1092
  locale: ibiz.i18n.getLang(),
1082
1093
  enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
1083
1094
  projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
1095
+ knowledgeBaseView: params.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
1084
1096
  selectAIProjectId: params.srfselectaiprojectid
1085
1097
  };
1098
+ if (params.hasOwnProperty("srfaiknowledgebaseview"))
1099
+ delete params.srfaiknowledgebaseview;
1086
1100
  if (params.hasOwnProperty("srfselectaiprojectid"))
1087
1101
  delete params.srfselectaiprojectid;
1088
1102
  if (params.hasOwnProperty("srfenableaiprojectselect"))
@@ -1225,6 +1239,7 @@ class AIChatUtil {
1225
1239
  } else {
1226
1240
  chatOptions.enableWorkSpace = ibiz.config.common.aiEnableWorkSpace;
1227
1241
  }
1242
+ chatOptions.openEmbedView = this.openEmbedView.bind(this);
1228
1243
  chatOptions.fetchAgentList = (args2 = {}) => {
1229
1244
  const { query, agentid } = args2;
1230
1245
  return this.getAIAgentList(context, {
@@ -1265,6 +1280,7 @@ class AIChatUtil {
1265
1280
  }
1266
1281
  const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
1267
1282
  chatOptions.fileSystemOptions = fileSystemOptions;
1283
+ chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
1268
1284
  chatOptions.history = async (ctx, param, other) => {
1269
1285
  const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
1270
1286
  const historyRequestData = {};
@@ -2202,6 +2218,77 @@ class AIChatUtil {
2202
2218
  };
2203
2219
  return fileSystemOptions;
2204
2220
  }
2221
+ /**
2222
+ * @description 打开嵌入视图
2223
+ * @private
2224
+ * @param {IContext} context 上下文
2225
+ * @param {IParams} params 视图参数
2226
+ * @param {string} viewId 视图标识
2227
+ * @param {HTMLElement} container 视图挂载容器
2228
+ * @param {IData[]} [selectedData] 选中数据
2229
+ * @param {(result: IModalData) => void} [callback] 回调
2230
+ * @returns {*} {Promise<void>}
2231
+ * @memberof AIChatUtil
2232
+ */
2233
+ async openEmbedView(context, params, viewId, container, selectedData, callback) {
2234
+ const unmount = (result = { ok: false }) => {
2235
+ callback == null ? void 0 : callback(result);
2236
+ render(null, container);
2237
+ };
2238
+ const modal = new Modal({
2239
+ mode: ViewMode.EMBED,
2240
+ viewUsage: 2,
2241
+ dismiss: (result) => unmount(result)
2242
+ });
2243
+ const modelData = await ibiz.hub.getAppView(viewId);
2244
+ const vNode = createVNode(IBizViewShell, {
2245
+ modal,
2246
+ modelData,
2247
+ context,
2248
+ params: { ...params, checkstrictly: true },
2249
+ state: { selectedData }
2250
+ });
2251
+ vNode.appContext = this.App._context;
2252
+ render(vNode, container);
2253
+ return {
2254
+ width: modelData.width,
2255
+ height: modelData.height,
2256
+ unmount
2257
+ };
2258
+ }
2259
+ /**
2260
+ * @description 获取异步行为配置
2261
+ * @returns {*} {Promise<IData>}
2262
+ * @memberof AIChatUtil
2263
+ */
2264
+ async getAIAsyncActionOptions() {
2265
+ const asyncActionOptions = {};
2266
+ asyncActionOptions.getLastAsyncAction = async (asyncActionID) => {
2267
+ const result = await ibiz.hub.notice.asyncAction.service.get(asyncActionID);
2268
+ if (result.ok && result.data) {
2269
+ return result.data;
2270
+ }
2271
+ return null;
2272
+ };
2273
+ asyncActionOptions.registerCallBack = (asyncActionID, callback) => {
2274
+ let callbacks = this.asyncActionCallBackMap.get(asyncActionID);
2275
+ if (!callbacks) {
2276
+ callbacks = /* @__PURE__ */ new Set();
2277
+ this.asyncActionCallBackMap.set(asyncActionID, callbacks);
2278
+ }
2279
+ callbacks.add(callback);
2280
+ return () => {
2281
+ callbacks.delete(callback);
2282
+ if (!callbacks.size) {
2283
+ this.asyncActionCallBackMap.delete(asyncActionID);
2284
+ }
2285
+ };
2286
+ };
2287
+ asyncActionOptions.onPreview = async (asyncAction, _event) => {
2288
+ return openAsyncActionModal(asyncAction);
2289
+ };
2290
+ return asyncActionOptions;
2291
+ }
2205
2292
  }
2206
2293
 
2207
2294
  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;