@ibiz-template/vue3-components 0.7.41-alpha.42 → 0.7.41-alpha.44
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/ibiz-markdown-editor-CUzKkFER.js +1 -0
- package/dist/{index-CaWTEUU1.js → index-DgqTP4Vw.js} +1 -1
- package/dist/{index-CD2XM6M6.js → index-Dr0VM8iS.js} +1 -1
- package/dist/index-DtEaU3-5.js +11 -0
- package/dist/index.min.css +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/wang-editor-CRWSwyXY.js +1 -0
- package/dist/{xlsx-util-B1eGfH7d.js → xlsx-util-CMJON8Uq.js} +1 -1
- package/es/control/grid/grid-column/grid-field-column/attachment-column/attachment-column.mjs +2 -1
- package/es/control/grid/grid-column/grid-field-column/attachment-column/file-util.mjs +22 -11
- package/es/control/toolbar/export-excel/export-excel.mjs +19 -4
- package/es/editor/carousel/ibiz-carousel/ibiz-carousel.mjs +5 -2
- package/es/editor/code/monaco-editor/monaco-editor.mjs +8 -194
- package/es/editor/html/wang-editor/module/ai-module.mjs +1 -1
- package/es/editor/html/wang-editor/wang-editor.mjs +35 -207
- package/es/editor/markdown/ibiz-markdown-editor/custom-menu.mjs +11 -222
- package/es/editor/markdown/ibiz-markdown-editor/ibiz-markdown-editor.css +1 -1
- package/es/editor/markdown/ibiz-markdown-editor/ibiz-markdown-editor.mjs +23 -12
- package/es/editor/text-box/input/input.mjs +11 -197
- package/es/editor/text-box/signature/signature.mjs +28 -15
- package/es/editor/upload/upload-editor.controller.mjs +12 -1
- package/es/editor/upload/use/use-iview-upload.mjs +28 -13
- package/es/locale/en/index.mjs +29 -2
- package/es/locale/zh-CN/index.mjs +29 -2
- package/es/panel-component/coop-pos/coop-pos.controller.mjs +11 -1
- package/es/panel-component/panel-app-title/panel-app-title.controller.mjs +3 -1
- package/es/panel-component/panel-app-title/panel-app-title.mjs +22 -43
- package/es/util/ai-chat-util/ai-chat-util.mjs +672 -7
- package/es/util/ai-chat-util/ai-feedback/ai-feedback.css +1 -0
- package/es/util/ai-chat-util/ai-feedback/ai-feedback.mjs +130 -0
- package/es/util/app-util/app-util.mjs +26 -247
- package/es/util/inline-ai-util/inline-ai-textarea/common/ai-think/ai-think.css +1 -0
- package/es/util/inline-ai-util/inline-ai-textarea/common/ai-think/ai-think.mjs +56 -0
- package/es/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call/ai-tool-call.css +1 -0
- package/es/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call/ai-tool-call.mjs +52 -0
- package/es/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call-item/ai-tool-call-item.css +1 -0
- package/es/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call-item/ai-tool-call-item.mjs +143 -0
- package/es/util/inline-ai-util/inline-ai-textarea/common/index.mjs +4 -0
- package/es/util/inline-ai-util/inline-ai-textarea/icon.mjs +52 -1
- package/es/util/inline-ai-util/inline-ai-textarea/inline-ai-textarea.css +1 -1
- package/es/util/inline-ai-util/inline-ai-textarea/inline-ai-textarea.hook.mjs +34 -4
- package/es/util/inline-ai-util/inline-ai-textarea/inline-ai-textarea.mjs +32 -25
- package/es/util/inline-ai-util/inline-ai-textarea/interface.mjs +1 -0
- package/lib/control/grid/grid-column/grid-field-column/attachment-column/attachment-column.cjs +2 -1
- package/lib/control/grid/grid-column/grid-field-column/attachment-column/file-util.cjs +22 -11
- package/lib/control/toolbar/export-excel/export-excel.cjs +18 -3
- package/lib/editor/carousel/ibiz-carousel/ibiz-carousel.cjs +5 -2
- package/lib/editor/code/monaco-editor/monaco-editor.cjs +8 -194
- package/lib/editor/html/wang-editor/module/ai-module.cjs +1 -1
- package/lib/editor/html/wang-editor/wang-editor.cjs +34 -206
- package/lib/editor/markdown/ibiz-markdown-editor/custom-menu.cjs +11 -222
- package/lib/editor/markdown/ibiz-markdown-editor/ibiz-markdown-editor.cjs +23 -12
- package/lib/editor/markdown/ibiz-markdown-editor/ibiz-markdown-editor.css +1 -1
- package/lib/editor/text-box/input/input.cjs +10 -196
- package/lib/editor/text-box/signature/signature.cjs +28 -15
- package/lib/editor/upload/upload-editor.controller.cjs +12 -1
- package/lib/editor/upload/use/use-iview-upload.cjs +28 -13
- package/lib/locale/en/index.cjs +29 -2
- package/lib/locale/zh-CN/index.cjs +29 -2
- package/lib/panel-component/coop-pos/coop-pos.controller.cjs +11 -1
- package/lib/panel-component/panel-app-title/panel-app-title.cjs +21 -42
- package/lib/panel-component/panel-app-title/panel-app-title.controller.cjs +3 -1
- package/lib/util/ai-chat-util/ai-chat-util.cjs +670 -5
- package/lib/util/ai-chat-util/ai-feedback/ai-feedback.cjs +132 -0
- package/lib/util/ai-chat-util/ai-feedback/ai-feedback.css +1 -0
- package/lib/util/app-util/app-util.cjs +25 -246
- package/lib/util/inline-ai-util/inline-ai-textarea/common/ai-think/ai-think.cjs +58 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/common/ai-think/ai-think.css +1 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call/ai-tool-call.cjs +54 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call/ai-tool-call.css +1 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call-item/ai-tool-call-item.cjs +145 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/common/ai-tool-call-item/ai-tool-call-item.css +1 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/common/index.cjs +9 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/icon.cjs +54 -0
- package/lib/util/inline-ai-util/inline-ai-textarea/inline-ai-textarea.cjs +31 -24
- package/lib/util/inline-ai-util/inline-ai-textarea/inline-ai-textarea.css +1 -1
- package/lib/util/inline-ai-util/inline-ai-textarea/inline-ai-textarea.hook.cjs +34 -4
- package/lib/util/inline-ai-util/inline-ai-textarea/interface.cjs +3 -0
- package/package.json +7 -7
- package/dist/ibiz-markdown-editor-pEdb_gS_.js +0 -1
- package/dist/index-BObZTN7-.js +0 -11
- package/dist/wang-editor-Ck-JCWqK.js +0 -1
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { h } from 'vue';
|
|
2
|
+
import { createUUID } from 'qx-util';
|
|
3
|
+
import { UIActionUtil, SysUIActionTag, ConfigService, UtilService, AIUtilService } from '@ibiz-template/runtime';
|
|
4
|
+
import { StringUtil, IBizContext } from '@ibiz-template/core';
|
|
5
|
+
import { AIFeedback } from './ai-feedback/ai-feedback.mjs';
|
|
3
6
|
|
|
4
7
|
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField = (obj, key, value) => {
|
|
11
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
5
14
|
class AIChatUtil {
|
|
15
|
+
constructor() {
|
|
16
|
+
__publicField(this, "TOPIC_CHAT_PREFIX", "topic");
|
|
17
|
+
__publicField(this, "INLINE_CHAT_SUFFIX", "inline");
|
|
18
|
+
__publicField(this, "TEMP_CHAT_SUFFIX", "temp");
|
|
19
|
+
__publicField(this, "UNKOWN_CHAT_SUFFIX", "unknow");
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* 获取AI聊天对象
|
|
8
23
|
*/
|
|
@@ -18,7 +33,7 @@ class AIChatUtil {
|
|
|
18
33
|
* @param params
|
|
19
34
|
* @param data
|
|
20
35
|
*/
|
|
21
|
-
getEditorExAIChatParams(editorParams, context, params, data) {
|
|
36
|
+
async getEditorExAIChatParams(editorParams, context, params, data, deACMode, args) {
|
|
22
37
|
const containerOptions = {};
|
|
23
38
|
if (editorParams.enableaiminimize) {
|
|
24
39
|
containerOptions.enableAIMinimize = editorParams.enableaiminimize === "true";
|
|
@@ -39,6 +54,7 @@ class AIChatUtil {
|
|
|
39
54
|
ibiz.log.error(error);
|
|
40
55
|
}
|
|
41
56
|
}
|
|
57
|
+
const topicOptions = {};
|
|
42
58
|
const chatOptions = {};
|
|
43
59
|
if (editorParams.srfaiappendcurdata) {
|
|
44
60
|
chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
|
|
@@ -55,15 +71,252 @@ class AIChatUtil {
|
|
|
55
71
|
if (editorParams.srfmode) {
|
|
56
72
|
chatOptions.srfMode = editorParams.srfmode;
|
|
57
73
|
}
|
|
58
|
-
|
|
74
|
+
if (editorParams.srfaiagent) {
|
|
75
|
+
chatOptions.activeAIAgentID = editorParams.srfaiagent;
|
|
76
|
+
}
|
|
77
|
+
const aiAgentlist = await this.getAIAgentList(
|
|
78
|
+
context,
|
|
79
|
+
params,
|
|
80
|
+
editorParams
|
|
81
|
+
);
|
|
82
|
+
chatOptions.aiAgentlist = aiAgentlist;
|
|
83
|
+
if (deACMode) {
|
|
84
|
+
const {
|
|
85
|
+
contentToolbarItems,
|
|
86
|
+
footerToolbarItems,
|
|
87
|
+
questionToolbarItems,
|
|
88
|
+
otherToolbarItems
|
|
89
|
+
} = this.calcAiToolbarItemsByAc(deACMode);
|
|
90
|
+
chatOptions.contentToolbarItems = contentToolbarItems;
|
|
91
|
+
chatOptions.footerToolbarItems = footerToolbarItems;
|
|
92
|
+
chatOptions.questionToolbarItems = questionToolbarItems;
|
|
93
|
+
chatOptions.otherToolbarItems = otherToolbarItems;
|
|
94
|
+
}
|
|
95
|
+
const sessionid = this.getChatSessionId("TEMP");
|
|
96
|
+
chatOptions.sessionid = sessionid;
|
|
97
|
+
let id = "";
|
|
98
|
+
let abortController;
|
|
99
|
+
const { chatInstance, view, ctrl } = args;
|
|
100
|
+
chatOptions.history = async (ctx, param, other) => {
|
|
101
|
+
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
102
|
+
const historyRequestData = {};
|
|
103
|
+
if (other.appendCurData) {
|
|
104
|
+
Object.assign(historyRequestData, {
|
|
105
|
+
...other.appendCurData
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (other.sessionid) {
|
|
109
|
+
Object.assign(historyRequestData, {
|
|
110
|
+
sessionid: other.sessionid
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (other.srfaiagent) {
|
|
114
|
+
Object.assign(historyRequestData, {
|
|
115
|
+
srfaiagent: other.srfaiagent
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (other.srfmode) {
|
|
119
|
+
Object.assign(historyRequestData, {
|
|
120
|
+
mode: other.srfmode
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const result = await deService.aiChatHistory(
|
|
124
|
+
ctx,
|
|
125
|
+
param,
|
|
126
|
+
historyRequestData
|
|
127
|
+
);
|
|
128
|
+
if (result.data && Array.isArray(result.data)) {
|
|
129
|
+
let preMsg;
|
|
130
|
+
result.data.forEach((item) => {
|
|
131
|
+
if (item.role === "TOOL") {
|
|
132
|
+
if (preMsg && item.content) {
|
|
133
|
+
chatInstance.aiChat.updateRecommendPrompt(
|
|
134
|
+
preMsg,
|
|
135
|
+
item.content
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
const msg = {
|
|
140
|
+
messageid: createUUID(),
|
|
141
|
+
state: 30,
|
|
142
|
+
type: "DEFAULT",
|
|
143
|
+
role: item.role,
|
|
144
|
+
content: item.content,
|
|
145
|
+
completed: true
|
|
146
|
+
};
|
|
147
|
+
preMsg = msg;
|
|
148
|
+
chatInstance.aiChat.addMessage(msg);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
};
|
|
154
|
+
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode) => {
|
|
155
|
+
id = createUUID();
|
|
156
|
+
abortController = new AbortController();
|
|
157
|
+
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
158
|
+
try {
|
|
159
|
+
const questionRequestData = {
|
|
160
|
+
messages: arr,
|
|
161
|
+
sessionid: sessionid2
|
|
162
|
+
};
|
|
163
|
+
if (srfaiagent) {
|
|
164
|
+
questionRequestData.srfaiagent = srfaiagent;
|
|
165
|
+
}
|
|
166
|
+
if (srfmode) {
|
|
167
|
+
questionRequestData.mode = srfmode;
|
|
168
|
+
}
|
|
169
|
+
await deService.aiChatSse(
|
|
170
|
+
(msg) => {
|
|
171
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
172
|
+
aiChat.addMessage({
|
|
173
|
+
messageid: id,
|
|
174
|
+
state: msg.actionstate,
|
|
175
|
+
type: "DEFAULT",
|
|
176
|
+
role: "ASSISTANT",
|
|
177
|
+
content: msg.actionresult
|
|
178
|
+
});
|
|
179
|
+
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
180
|
+
const result = JSON.parse(msg.actionresult);
|
|
181
|
+
const choices = result.choices;
|
|
182
|
+
if (choices && choices.length > 0) {
|
|
183
|
+
aiChat.replaceMessage({
|
|
184
|
+
messageid: id,
|
|
185
|
+
state: msg.actionstate,
|
|
186
|
+
type: "DEFAULT",
|
|
187
|
+
role: "ASSISTANT",
|
|
188
|
+
content: choices[0].content || "",
|
|
189
|
+
realmessageid: choices[0].messageid
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
} else if (msg.actionstate === 40) {
|
|
193
|
+
aiChat.replaceMessage({
|
|
194
|
+
messageid: id,
|
|
195
|
+
state: msg.actionstate,
|
|
196
|
+
type: "ERROR",
|
|
197
|
+
role: "ASSISTANT",
|
|
198
|
+
content: msg.actionresult
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
abortController,
|
|
203
|
+
ctx,
|
|
204
|
+
param,
|
|
205
|
+
{ ...questionRequestData }
|
|
206
|
+
);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
aiChat.replaceMessage({
|
|
209
|
+
messageid: id,
|
|
210
|
+
state: 40,
|
|
211
|
+
type: "ERROR",
|
|
212
|
+
role: "ASSISTANT",
|
|
213
|
+
content: error.message || ibiz.i18n.t("app.aiError")
|
|
214
|
+
});
|
|
215
|
+
abortController == null ? void 0 : abortController.abort();
|
|
216
|
+
} finally {
|
|
217
|
+
aiChat.completeMessage(id, true);
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
chatOptions.abortQuestion = async (aiChat) => {
|
|
222
|
+
abortController == null ? void 0 : abortController.abort();
|
|
223
|
+
await aiChat.stopMessage({
|
|
224
|
+
messageid: id,
|
|
225
|
+
state: 30,
|
|
226
|
+
type: "DEFAULT",
|
|
227
|
+
role: "ASSISTANT",
|
|
228
|
+
content: ""
|
|
229
|
+
});
|
|
230
|
+
await aiChat.completeMessage(id, true);
|
|
231
|
+
};
|
|
232
|
+
chatOptions.recommendPrompt = async (ctx, param, other) => {
|
|
233
|
+
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
234
|
+
const tempParams = { ...param };
|
|
235
|
+
if (other.srfaiagent) {
|
|
236
|
+
tempParams.srfaiagent = other.srfaiagent;
|
|
237
|
+
}
|
|
238
|
+
const result = await deService.aiChatRecommendPrompt(
|
|
239
|
+
ctx,
|
|
240
|
+
tempParams,
|
|
241
|
+
other.message
|
|
242
|
+
);
|
|
243
|
+
if (result.ok && result.data) {
|
|
244
|
+
const choices = result.data.choices;
|
|
245
|
+
if (choices && choices.length > 0) {
|
|
246
|
+
return choices[0];
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
};
|
|
252
|
+
chatOptions.uploader = {
|
|
253
|
+
onUpload: async (file, reportProgress, options) => {
|
|
254
|
+
const fileMeata = ibiz.util.file.calcFileUpDownUrl(
|
|
255
|
+
(options == null ? void 0 : options.context) || context,
|
|
256
|
+
(options == null ? void 0 : options.params) || params,
|
|
257
|
+
{},
|
|
258
|
+
{ enableNoAccess: true }
|
|
259
|
+
);
|
|
260
|
+
const fielUploadHeaders = ibiz.util.file.getUploadHeaders();
|
|
261
|
+
const formData = new FormData();
|
|
262
|
+
formData.append("file", file);
|
|
263
|
+
const res = await ibiz.net.axios({
|
|
264
|
+
url: fileMeata.uploadUrl,
|
|
265
|
+
method: "post",
|
|
266
|
+
headers: fielUploadHeaders,
|
|
267
|
+
data: formData,
|
|
268
|
+
onUploadProgress: (progressEvent) => {
|
|
269
|
+
const percent = progressEvent.loaded / progressEvent.total * 100;
|
|
270
|
+
reportProgress(percent);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return res.data;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
chatOptions.extendToolbarClick = async (event, source, context2, params2, data2) => {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
const result = await UIActionUtil.exec(
|
|
279
|
+
source.id,
|
|
280
|
+
{
|
|
281
|
+
view,
|
|
282
|
+
ctrl,
|
|
283
|
+
context: IBizContext.create(context2),
|
|
284
|
+
params: params2,
|
|
285
|
+
data: [data2],
|
|
286
|
+
event
|
|
287
|
+
},
|
|
288
|
+
source.appId
|
|
289
|
+
);
|
|
290
|
+
if (result.closeView) {
|
|
291
|
+
view.closeView({ ok: true });
|
|
292
|
+
} else if (result.refresh) {
|
|
293
|
+
switch (result.refreshMode) {
|
|
294
|
+
case 1:
|
|
295
|
+
view.callUIAction(SysUIActionTag.REFRESH);
|
|
296
|
+
break;
|
|
297
|
+
case 2:
|
|
298
|
+
(_a = view.parentView) == null ? void 0 : _a.callUIAction(SysUIActionTag.REFRESH);
|
|
299
|
+
break;
|
|
300
|
+
case 3:
|
|
301
|
+
(_b = view.getTopView()) == null ? void 0 : _b.callUIAction(SysUIActionTag.REFRESH);
|
|
302
|
+
break;
|
|
303
|
+
default:
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
};
|
|
308
|
+
return { containerOptions, topicOptions, chatOptions };
|
|
59
309
|
}
|
|
60
310
|
/**
|
|
61
311
|
* 获取界面行为扩展AI聊天参数
|
|
62
312
|
* @param context
|
|
63
313
|
* @param params
|
|
64
314
|
* @param data
|
|
315
|
+
* @param deACMode
|
|
316
|
+
* @param args
|
|
317
|
+
* @returns
|
|
65
318
|
*/
|
|
66
|
-
getUIActionExAIChatParams(context, params, data) {
|
|
319
|
+
async getUIActionExAIChatParams(context, params, data, deACMode, args) {
|
|
67
320
|
const containerOptions = {};
|
|
68
321
|
if (params.hasOwnProperty("enableaiminimize")) {
|
|
69
322
|
containerOptions.enableAIMinimize = params.enableaiminimize === "true";
|
|
@@ -87,6 +340,34 @@ class AIChatUtil {
|
|
|
87
340
|
ibiz.log.error(error);
|
|
88
341
|
}
|
|
89
342
|
}
|
|
343
|
+
const topicOptions = {};
|
|
344
|
+
if (params.hasOwnProperty("topiccaptionmode")) {
|
|
345
|
+
topicOptions.captionMode = params.topiccaptionmode;
|
|
346
|
+
delete params.topiccaptionmode;
|
|
347
|
+
} else {
|
|
348
|
+
topicOptions.captionMode = ibiz.config.common.aiChatTopicCaptionMode;
|
|
349
|
+
}
|
|
350
|
+
topicOptions.beforeDelete = async (...args2) => {
|
|
351
|
+
const isBatchRemove = args2[4];
|
|
352
|
+
const result = await ibiz.confirm.warning({
|
|
353
|
+
title: ibiz.i18n.t(
|
|
354
|
+
"util.appUtil.".concat(isBatchRemove ? "clearTopic" : "aiTitle")
|
|
355
|
+
),
|
|
356
|
+
desc: ibiz.i18n.t(
|
|
357
|
+
"util.appUtil.".concat(isBatchRemove ? "clearTopicDesc" : "aiDesc")
|
|
358
|
+
)
|
|
359
|
+
});
|
|
360
|
+
return result;
|
|
361
|
+
};
|
|
362
|
+
topicOptions.action = async (action, context2, params2, data2, event) => {
|
|
363
|
+
if (action === "LINK") {
|
|
364
|
+
await ibiz.openView.push(data2.url);
|
|
365
|
+
}
|
|
366
|
+
return true;
|
|
367
|
+
};
|
|
368
|
+
topicOptions.configService = (appid, storageType, subType) => {
|
|
369
|
+
return new ConfigService(appid, storageType, subType);
|
|
370
|
+
};
|
|
90
371
|
const chatOptions = {};
|
|
91
372
|
if (context.srfaiappendcurdata === "true") {
|
|
92
373
|
chatOptions.appendCurData = data;
|
|
@@ -120,7 +401,236 @@ class AIChatUtil {
|
|
|
120
401
|
chatOptions.srfMode = params.srfmode;
|
|
121
402
|
delete params.srfmode;
|
|
122
403
|
}
|
|
123
|
-
|
|
404
|
+
if (params.hasOwnProperty("srfaiagent")) {
|
|
405
|
+
chatOptions.activeAIAgentID = params.srfaiagent;
|
|
406
|
+
delete params.srfaiagent;
|
|
407
|
+
}
|
|
408
|
+
const aiAgentlist = await this.getAIAgentList(context, params);
|
|
409
|
+
chatOptions.aiAgentlist = aiAgentlist;
|
|
410
|
+
if (deACMode) {
|
|
411
|
+
const {
|
|
412
|
+
contentToolbarItems,
|
|
413
|
+
footerToolbarItems,
|
|
414
|
+
questionToolbarItems,
|
|
415
|
+
otherToolbarItems
|
|
416
|
+
} = this.calcAiToolbarItemsByAc(deACMode);
|
|
417
|
+
chatOptions.contentToolbarItems = contentToolbarItems;
|
|
418
|
+
chatOptions.footerToolbarItems = footerToolbarItems;
|
|
419
|
+
chatOptions.questionToolbarItems = questionToolbarItems;
|
|
420
|
+
chatOptions.otherToolbarItems = otherToolbarItems;
|
|
421
|
+
}
|
|
422
|
+
let id = "";
|
|
423
|
+
let abortController;
|
|
424
|
+
const { chatInstance, view, ctrl } = args;
|
|
425
|
+
chatOptions.history = async (ctx, param, other) => {
|
|
426
|
+
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
427
|
+
const historyRequestData = {};
|
|
428
|
+
if (other.appendCurData) {
|
|
429
|
+
Object.assign(historyRequestData, {
|
|
430
|
+
...other.appendCurData
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
if (other.sessionid) {
|
|
434
|
+
Object.assign(historyRequestData, {
|
|
435
|
+
sessionid: other.sessionid
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
if (other.srfaiagent) {
|
|
439
|
+
Object.assign(historyRequestData, {
|
|
440
|
+
srfaiagent: other.srfaiagent
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
if (other.srfmode) {
|
|
444
|
+
Object.assign(historyRequestData, {
|
|
445
|
+
mode: other.srfmode
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
const result = await deService.aiChatHistory(
|
|
449
|
+
ctx,
|
|
450
|
+
param,
|
|
451
|
+
historyRequestData
|
|
452
|
+
);
|
|
453
|
+
if (result.data && Array.isArray(result.data)) {
|
|
454
|
+
let preMsg;
|
|
455
|
+
result.data.forEach((item) => {
|
|
456
|
+
if (item.role === "TOOL") {
|
|
457
|
+
if (preMsg && item.content) {
|
|
458
|
+
chatInstance.aiChat.updateRecommendPrompt(
|
|
459
|
+
preMsg,
|
|
460
|
+
item.content
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
const msg = {
|
|
465
|
+
messageid: createUUID(),
|
|
466
|
+
state: 30,
|
|
467
|
+
type: "DEFAULT",
|
|
468
|
+
role: item.role,
|
|
469
|
+
content: item.content,
|
|
470
|
+
completed: true
|
|
471
|
+
};
|
|
472
|
+
preMsg = msg;
|
|
473
|
+
chatInstance.aiChat.addMessage(msg);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return true;
|
|
478
|
+
};
|
|
479
|
+
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode) => {
|
|
480
|
+
id = createUUID();
|
|
481
|
+
abortController = new AbortController();
|
|
482
|
+
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
483
|
+
try {
|
|
484
|
+
const questionRequestData = {
|
|
485
|
+
messages: arr,
|
|
486
|
+
sessionid
|
|
487
|
+
};
|
|
488
|
+
if (srfaiagent) {
|
|
489
|
+
questionRequestData.srfaiagent = srfaiagent;
|
|
490
|
+
}
|
|
491
|
+
if (srfmode) {
|
|
492
|
+
questionRequestData.mode = srfmode;
|
|
493
|
+
}
|
|
494
|
+
await deService.aiChatSse(
|
|
495
|
+
(msg) => {
|
|
496
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
497
|
+
aiChat.addMessage({
|
|
498
|
+
messageid: id,
|
|
499
|
+
state: msg.actionstate,
|
|
500
|
+
type: "DEFAULT",
|
|
501
|
+
role: "ASSISTANT",
|
|
502
|
+
content: msg.actionresult
|
|
503
|
+
});
|
|
504
|
+
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
505
|
+
const result = JSON.parse(msg.actionresult);
|
|
506
|
+
const choices = result.choices;
|
|
507
|
+
if (choices && choices.length > 0) {
|
|
508
|
+
aiChat.replaceMessage({
|
|
509
|
+
messageid: id,
|
|
510
|
+
state: msg.actionstate,
|
|
511
|
+
type: "DEFAULT",
|
|
512
|
+
role: "ASSISTANT",
|
|
513
|
+
content: choices[0].content || "",
|
|
514
|
+
realmessageid: choices[0].messageid
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
} else if (msg.actionstate === 40) {
|
|
518
|
+
aiChat.replaceMessage({
|
|
519
|
+
messageid: id,
|
|
520
|
+
state: msg.actionstate,
|
|
521
|
+
type: "ERROR",
|
|
522
|
+
role: "ASSISTANT",
|
|
523
|
+
content: msg.actionresult
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
abortController,
|
|
528
|
+
ctx,
|
|
529
|
+
param,
|
|
530
|
+
{ ...questionRequestData }
|
|
531
|
+
);
|
|
532
|
+
} catch (error) {
|
|
533
|
+
aiChat.replaceMessage({
|
|
534
|
+
messageid: id,
|
|
535
|
+
state: 40,
|
|
536
|
+
type: "ERROR",
|
|
537
|
+
role: "ASSISTANT",
|
|
538
|
+
content: error.message || ibiz.i18n.t("app.aiError")
|
|
539
|
+
});
|
|
540
|
+
abortController == null ? void 0 : abortController.abort();
|
|
541
|
+
} finally {
|
|
542
|
+
aiChat.completeMessage(id, true);
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
chatOptions.abortQuestion = async (aiChat) => {
|
|
547
|
+
abortController == null ? void 0 : abortController.abort();
|
|
548
|
+
await aiChat.stopMessage({
|
|
549
|
+
messageid: id,
|
|
550
|
+
state: 30,
|
|
551
|
+
type: "DEFAULT",
|
|
552
|
+
role: "ASSISTANT",
|
|
553
|
+
content: ""
|
|
554
|
+
});
|
|
555
|
+
await aiChat.completeMessage(id, true);
|
|
556
|
+
};
|
|
557
|
+
chatOptions.recommendPrompt = async (ctx, param, other) => {
|
|
558
|
+
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
559
|
+
const tempParams = { ...param };
|
|
560
|
+
if (other.srfaiagent) {
|
|
561
|
+
tempParams.srfaiagent = other.srfaiagent;
|
|
562
|
+
}
|
|
563
|
+
const result = await deService.aiChatRecommendPrompt(
|
|
564
|
+
ctx,
|
|
565
|
+
tempParams,
|
|
566
|
+
other.message
|
|
567
|
+
);
|
|
568
|
+
if (result.ok && result.data) {
|
|
569
|
+
const choices = result.data.choices;
|
|
570
|
+
if (choices && choices.length > 0) {
|
|
571
|
+
return choices[0];
|
|
572
|
+
}
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
return null;
|
|
576
|
+
};
|
|
577
|
+
chatOptions.uploader = {
|
|
578
|
+
onUpload: async (file, reportProgress, options) => {
|
|
579
|
+
const { uploadUrl } = ibiz.util.file.calcFileUpDownUrl(
|
|
580
|
+
(options == null ? void 0 : options.context) || context,
|
|
581
|
+
(options == null ? void 0 : options.params) || params,
|
|
582
|
+
{},
|
|
583
|
+
{ enableNoAccess: true }
|
|
584
|
+
);
|
|
585
|
+
const headers = ibiz.util.file.getUploadHeaders();
|
|
586
|
+
const formData = new FormData();
|
|
587
|
+
formData.append("file", file);
|
|
588
|
+
const res = await ibiz.net.axios({
|
|
589
|
+
url: uploadUrl,
|
|
590
|
+
method: "post",
|
|
591
|
+
headers,
|
|
592
|
+
data: formData,
|
|
593
|
+
onUploadProgress: (progressEvent) => {
|
|
594
|
+
const percent = progressEvent.loaded / progressEvent.total * 100;
|
|
595
|
+
reportProgress(percent);
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
return res.data;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
chatOptions.extendToolbarClick = async (event, source, context2, params2, data2) => {
|
|
602
|
+
var _a, _b;
|
|
603
|
+
const result = await UIActionUtil.exec(
|
|
604
|
+
source.id,
|
|
605
|
+
{
|
|
606
|
+
view,
|
|
607
|
+
ctrl,
|
|
608
|
+
context: IBizContext.create(context2),
|
|
609
|
+
params: params2,
|
|
610
|
+
data: [data2],
|
|
611
|
+
event
|
|
612
|
+
},
|
|
613
|
+
source.appId
|
|
614
|
+
);
|
|
615
|
+
if (result.closeView) {
|
|
616
|
+
view.closeView({ ok: true });
|
|
617
|
+
} else if (result.refresh) {
|
|
618
|
+
switch (result.refreshMode) {
|
|
619
|
+
case 1:
|
|
620
|
+
view.callUIAction(SysUIActionTag.REFRESH);
|
|
621
|
+
break;
|
|
622
|
+
case 2:
|
|
623
|
+
(_a = view.parentView) == null ? void 0 : _a.callUIAction(SysUIActionTag.REFRESH);
|
|
624
|
+
break;
|
|
625
|
+
case 3:
|
|
626
|
+
(_b = view.getTopView()) == null ? void 0 : _b.callUIAction(SysUIActionTag.REFRESH);
|
|
627
|
+
break;
|
|
628
|
+
default:
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return result;
|
|
632
|
+
};
|
|
633
|
+
return { containerOptions, topicOptions, chatOptions };
|
|
124
634
|
}
|
|
125
635
|
/**
|
|
126
636
|
* 计算界面行为扩展AI聊天工具栏项
|
|
@@ -198,7 +708,7 @@ class AIChatUtil {
|
|
|
198
708
|
return emptyList;
|
|
199
709
|
}
|
|
200
710
|
const utilService = new UtilService(aiAgentUtil);
|
|
201
|
-
const resultParams = { ...params };
|
|
711
|
+
const resultParams = { ...params, page: 0, size: 1e3 };
|
|
202
712
|
if (editorParams && editorParams.srfaiagentscope) {
|
|
203
713
|
Object.assign(resultParams, {
|
|
204
714
|
srfaiagentscope: editorParams.srfaiagentscope
|
|
@@ -210,6 +720,161 @@ class AIChatUtil {
|
|
|
210
720
|
}
|
|
211
721
|
return data;
|
|
212
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* 获取会话标识(TOPIC:适用于多话题场景;INLINE:适用于ai行内会话场景;TEMP:适用于传统ai编辑器会话场景)
|
|
725
|
+
* @param sessionID
|
|
726
|
+
*/
|
|
727
|
+
getChatSessionId(type, sessionID) {
|
|
728
|
+
let tempSessionID = "";
|
|
729
|
+
switch (type) {
|
|
730
|
+
case "TOPIC":
|
|
731
|
+
tempSessionID += this.TOPIC_CHAT_PREFIX;
|
|
732
|
+
break;
|
|
733
|
+
case "INLINE":
|
|
734
|
+
tempSessionID += this.INLINE_CHAT_SUFFIX;
|
|
735
|
+
break;
|
|
736
|
+
case "TEMP":
|
|
737
|
+
tempSessionID += this.TEMP_CHAT_SUFFIX;
|
|
738
|
+
break;
|
|
739
|
+
default:
|
|
740
|
+
tempSessionID += this.UNKOWN_CHAT_SUFFIX;
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
tempSessionID += "@".concat(sessionID || createUUID(), "@").concat((/* @__PURE__ */ new Date()).getTime());
|
|
744
|
+
return tempSessionID;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* 获取AI会话应用功能
|
|
748
|
+
* @returns
|
|
749
|
+
*/
|
|
750
|
+
async getAIResourceUtil() {
|
|
751
|
+
const app = ibiz.hub.getApp(ibiz.env.appId);
|
|
752
|
+
const aiSessionUtil = app.getAppUtil("DYNAMICAISESSION", "CUSTOM");
|
|
753
|
+
return aiSessionUtil;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* 获取AI资源参数
|
|
757
|
+
* @returns
|
|
758
|
+
*/
|
|
759
|
+
async getAIResourceOptions(context, params) {
|
|
760
|
+
const resourceOptions = {};
|
|
761
|
+
if (ibiz.config.common.aiResourceMode) {
|
|
762
|
+
resourceOptions.resourceMode = ibiz.config.common.aiResourceMode;
|
|
763
|
+
return resourceOptions;
|
|
764
|
+
}
|
|
765
|
+
const aiSessionUtil = await this.getAIResourceUtil();
|
|
766
|
+
resourceOptions.resourceMode = aiSessionUtil ? "REMOTE" : "LOCAL";
|
|
767
|
+
if (!aiSessionUtil) {
|
|
768
|
+
return resourceOptions;
|
|
769
|
+
}
|
|
770
|
+
const utilService = new AIUtilService(aiSessionUtil);
|
|
771
|
+
resourceOptions.getSessionList = async (args = {}) => {
|
|
772
|
+
const tempParams = { ...params, page: 0, size: 1e3, ...args };
|
|
773
|
+
const result = await utilService.getSessionList(context, tempParams);
|
|
774
|
+
return result;
|
|
775
|
+
};
|
|
776
|
+
resourceOptions.updateSession = async (realID, data) => {
|
|
777
|
+
const result = await utilService.updateSession(
|
|
778
|
+
context,
|
|
779
|
+
params,
|
|
780
|
+
realID,
|
|
781
|
+
data
|
|
782
|
+
);
|
|
783
|
+
return result;
|
|
784
|
+
};
|
|
785
|
+
resourceOptions.deleteSession = async (realID) => {
|
|
786
|
+
const result = await utilService.deleteSession(context, params, realID);
|
|
787
|
+
return result;
|
|
788
|
+
};
|
|
789
|
+
resourceOptions.getMessages = async (args = {}) => {
|
|
790
|
+
const tempParams = { ...params, page: 0, size: 1e3, ...args };
|
|
791
|
+
const result = await utilService.getMessageList(context, tempParams);
|
|
792
|
+
return result;
|
|
793
|
+
};
|
|
794
|
+
resourceOptions.deleteMessage = async (messageID) => {
|
|
795
|
+
const result = await utilService.deleteMessage(
|
|
796
|
+
context,
|
|
797
|
+
params,
|
|
798
|
+
messageID
|
|
799
|
+
);
|
|
800
|
+
return result;
|
|
801
|
+
};
|
|
802
|
+
resourceOptions.likeMessage = async (messageID) => {
|
|
803
|
+
const result = await utilService.likeMessage(context, params, messageID);
|
|
804
|
+
return result;
|
|
805
|
+
};
|
|
806
|
+
resourceOptions.dislikeMessage = async (messageID, feedbackContent) => {
|
|
807
|
+
var _a, _b;
|
|
808
|
+
const overlay = ibiz.overlay.createModal(
|
|
809
|
+
(modal) => {
|
|
810
|
+
return h(AIFeedback, {
|
|
811
|
+
modal,
|
|
812
|
+
content: feedbackContent
|
|
813
|
+
});
|
|
814
|
+
},
|
|
815
|
+
void 0,
|
|
816
|
+
{ width: "520px", height: "auto", showClose: true }
|
|
817
|
+
);
|
|
818
|
+
overlay.present();
|
|
819
|
+
const result = await overlay.onWillDismiss();
|
|
820
|
+
if (!result.ok)
|
|
821
|
+
return false;
|
|
822
|
+
const content = (_b = (_a = result.data) == null ? void 0 : _a[0]) == null ? void 0 : _b.feedbackContent;
|
|
823
|
+
const _result = await utilService.dislikeMessage(
|
|
824
|
+
context,
|
|
825
|
+
params,
|
|
826
|
+
messageID,
|
|
827
|
+
content
|
|
828
|
+
);
|
|
829
|
+
return _result;
|
|
830
|
+
};
|
|
831
|
+
resourceOptions.cancelFeedback = async (messageID) => {
|
|
832
|
+
const result = await utilService.cancelFeedback(
|
|
833
|
+
context,
|
|
834
|
+
params,
|
|
835
|
+
messageID
|
|
836
|
+
);
|
|
837
|
+
return result;
|
|
838
|
+
};
|
|
839
|
+
resourceOptions.clearAllSession = async (excludeSessionID) => {
|
|
840
|
+
const result = await utilService.clearAllSession(
|
|
841
|
+
context,
|
|
842
|
+
params,
|
|
843
|
+
excludeSessionID
|
|
844
|
+
);
|
|
845
|
+
return result;
|
|
846
|
+
};
|
|
847
|
+
resourceOptions.clearAllMessageBySessionId = async (realID) => {
|
|
848
|
+
const result = await utilService.clearAllMessageBySessionId(
|
|
849
|
+
context,
|
|
850
|
+
params,
|
|
851
|
+
realID
|
|
852
|
+
);
|
|
853
|
+
return result;
|
|
854
|
+
};
|
|
855
|
+
return resourceOptions;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* 获取AI聊天模式
|
|
859
|
+
* @param type 场景类型:UIACTION:界面行为;EDITOR:编辑器
|
|
860
|
+
* @param context
|
|
861
|
+
* @param params
|
|
862
|
+
* @param editorParams
|
|
863
|
+
*/
|
|
864
|
+
getAIChatMode(type, context, params, editorParams) {
|
|
865
|
+
switch (type) {
|
|
866
|
+
case "UIACTION":
|
|
867
|
+
if (params.srfenabletempmode && params.srfenabletempmode === "true") {
|
|
868
|
+
delete params.srfenabletempmode;
|
|
869
|
+
return "DEFAULT";
|
|
870
|
+
}
|
|
871
|
+
return "TOPIC";
|
|
872
|
+
case "EDITOR":
|
|
873
|
+
return "DEFAULT";
|
|
874
|
+
default:
|
|
875
|
+
return "DEFAULT";
|
|
876
|
+
}
|
|
877
|
+
}
|
|
213
878
|
}
|
|
214
879
|
|
|
215
880
|
export { AIChatUtil };
|