@ibiz-template/vue3-components 0.7.41-alpha.165 → 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-li-EqXGB.js → index-DXoEi5m-.js} +28 -28
- package/dist/{index.es-CA0rGKdK.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-BPGsMZgX.js → wang-editor-CK60NH54.js} +1 -1
- package/dist/{xlsx-util-Bv9fDQB8.js → xlsx-util-5Xgq-UOe.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/panel-component/user-message/async-action/async-action/async-action.provider.mjs +44 -41
- package/es/util/ai-chat-util/ai-chat-util.mjs +326 -244
- package/es/web-app/main.mjs +1 -1
- 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/panel-component/user-message/async-action/async-action/async-action.provider.cjs +44 -40
- package/lib/util/ai-chat-util/ai-chat-util.cjs +324 -242
- package/lib/web-app/main.cjs +1 -1
- 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/panel-component/user-message/async-action/async-action/async-action.provider.ts +58 -42
- package/src/util/ai-chat-util/ai-chat-util.ts +418 -279
- package/src/web-app/main.ts +1 -1
|
@@ -4,8 +4,10 @@ var vue = require('vue');
|
|
|
4
4
|
var qxUtil = require('qx-util');
|
|
5
5
|
var runtime = require('@ibiz-template/runtime');
|
|
6
6
|
var core = require('@ibiz-template/core');
|
|
7
|
+
var vue3Util = require('@ibiz-template/vue3-util');
|
|
7
8
|
var ramda = require('ramda');
|
|
8
9
|
var aiFeedback = require('./ai-feedback/ai-feedback.cjs');
|
|
10
|
+
var asyncAction_provider = require('../../panel-component/user-message/async-action/async-action/async-action.provider.cjs');
|
|
9
11
|
|
|
10
12
|
"use strict";
|
|
11
13
|
var __defProp = Object.defineProperty;
|
|
@@ -15,7 +17,13 @@ var __publicField = (obj, key, value) => {
|
|
|
15
17
|
return value;
|
|
16
18
|
};
|
|
17
19
|
class AIChatUtil {
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of AIChatUtil.
|
|
22
|
+
* @param {App} App vue App
|
|
23
|
+
* @memberof AIChatUtil
|
|
24
|
+
*/
|
|
25
|
+
constructor(App2) {
|
|
26
|
+
this.App = App2;
|
|
19
27
|
__publicField(this, "TOPIC_CHAT_PREFIX", "topic");
|
|
20
28
|
__publicField(this, "INLINE_CHAT_SUFFIX", "inline");
|
|
21
29
|
__publicField(this, "TEMP_CHAT_SUFFIX", "temp");
|
|
@@ -23,6 +31,133 @@ class AIChatUtil {
|
|
|
23
31
|
__publicField(this, "PRE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: application/json;charset=UTF-8");
|
|
24
32
|
// 无流内容回来
|
|
25
33
|
__publicField(this, "NONE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: null");
|
|
34
|
+
// 各 asyncActionID 对应的回调集合(同一 ID 可能被多处注册不同回调),回调入参为最新异步作业对象
|
|
35
|
+
__publicField(this, "asyncActionCallBackMap", /* @__PURE__ */ new Map());
|
|
36
|
+
ibiz.mc.command.asyncAction.on((msg) => {
|
|
37
|
+
if (!msg.data || msg.subtype !== "ASYNCACTION")
|
|
38
|
+
return;
|
|
39
|
+
const action = msg.data;
|
|
40
|
+
if (action.actiontype === "ASYNCCHATCOMPLETION")
|
|
41
|
+
return;
|
|
42
|
+
const callbacks = this.asyncActionCallBackMap.get(action.asyncacitonid);
|
|
43
|
+
if (callbacks) {
|
|
44
|
+
callbacks.forEach((cb) => cb(action));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
|
|
50
|
+
* @param {any} aiChat 单实例聊天总控
|
|
51
|
+
* @param {string} id 本次问答的流式消息 id
|
|
52
|
+
* @param {string} localMsgID 本地用户消息 id(用于回填真实消息 id;为空串时为恢复会话场景,状态 20 走 isLoading 加载分支)
|
|
53
|
+
* @return {*} {(msg: IPortalAsyncAction) => void}
|
|
54
|
+
* @memberof AIChatUtil
|
|
55
|
+
*/
|
|
56
|
+
createChatSseHandler(aiChat, id, localMsgID) {
|
|
57
|
+
let updateFlag = true;
|
|
58
|
+
return (msg) => {
|
|
59
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
60
|
+
if (localMsgID) {
|
|
61
|
+
aiChat.removeWaitingMessage(id);
|
|
62
|
+
if (msg.asextparam && updateFlag) {
|
|
63
|
+
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
64
|
+
updateFlag = false;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
aiChat.isLoading.value = true;
|
|
68
|
+
}
|
|
69
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
70
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
71
|
+
}
|
|
72
|
+
aiChat.addMessage({
|
|
73
|
+
messageid: id,
|
|
74
|
+
state: msg.actionstate,
|
|
75
|
+
type: "DEFAULT",
|
|
76
|
+
role: "ASSISTANT",
|
|
77
|
+
content: msg.actionresult,
|
|
78
|
+
status: "pending"
|
|
79
|
+
});
|
|
80
|
+
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
81
|
+
const result = JSON.parse(msg.actionresult);
|
|
82
|
+
if (result.usage) {
|
|
83
|
+
aiChat.updateMsgUsage(id, result.usage);
|
|
84
|
+
}
|
|
85
|
+
if (result.files) {
|
|
86
|
+
aiChat.updateMsgOutputFiles(id, result.files);
|
|
87
|
+
}
|
|
88
|
+
const choices = result.choices;
|
|
89
|
+
if (choices && choices.length > 0) {
|
|
90
|
+
aiChat.replaceMessage({
|
|
91
|
+
messageid: id,
|
|
92
|
+
state: msg.actionstate,
|
|
93
|
+
type: "DEFAULT",
|
|
94
|
+
role: "ASSISTANT",
|
|
95
|
+
content: choices[0].content || "",
|
|
96
|
+
realmessageid: choices[0].messageid,
|
|
97
|
+
status: "sent"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
aiChat.setActiveAsyncacitonId("");
|
|
101
|
+
} else if (msg.actionstate === 40) {
|
|
102
|
+
aiChat.replaceMessage({
|
|
103
|
+
messageid: id,
|
|
104
|
+
state: msg.actionstate,
|
|
105
|
+
type: "ERROR",
|
|
106
|
+
role: "ASSISTANT",
|
|
107
|
+
errorText: msg.actionresult,
|
|
108
|
+
status: "failed"
|
|
109
|
+
});
|
|
110
|
+
aiChat.setActiveAsyncacitonId("");
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @description 网络中断(network error)后按 asyncacitonid 自动续传一次;成功返回 true,失败返回 false 交回调用方走既有错误处理
|
|
116
|
+
* @param {any} aiChat 单实例聊天总控
|
|
117
|
+
* @param {IContext} ctx 上下文
|
|
118
|
+
* @param {IParams} param 视图参数
|
|
119
|
+
* @param {*} deService 实体服务
|
|
120
|
+
* @param {{ id: string; abortController: AbortController }} state 聊天实例提问状态(WeakMap 持有的同一对象引用)
|
|
121
|
+
* @param {{ asyncacitonid: string; sessionid?: string; srfaiagent?: string; srfproject?: string }} resumeInfo 续传参数
|
|
122
|
+
* @param {(msg: IPortalAsyncAction) => void} onMsg SSE 流式消息处理回调
|
|
123
|
+
* @return {*} {Promise<boolean>} 是否续传成功
|
|
124
|
+
* @memberof AIChatUtil
|
|
125
|
+
*/
|
|
126
|
+
async autoResumeChat(aiChat, ctx, param, deService, state, resumeInfo, onMsg) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
(_a = state.abortController) == null ? void 0 : _a.abort();
|
|
129
|
+
state.abortController = new AbortController();
|
|
130
|
+
try {
|
|
131
|
+
const resumeRequestData = {
|
|
132
|
+
asyncacitonid: resumeInfo.asyncacitonid
|
|
133
|
+
};
|
|
134
|
+
if (resumeInfo.sessionid) {
|
|
135
|
+
resumeRequestData.sessionid = resumeInfo.sessionid;
|
|
136
|
+
}
|
|
137
|
+
if (resumeInfo.srfaiagent) {
|
|
138
|
+
resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
|
|
139
|
+
}
|
|
140
|
+
if (resumeInfo.srfproject) {
|
|
141
|
+
resumeRequestData.srfproject = resumeInfo.srfproject;
|
|
142
|
+
}
|
|
143
|
+
await deService.aiResumeSse(
|
|
144
|
+
onMsg,
|
|
145
|
+
state.abortController,
|
|
146
|
+
ctx,
|
|
147
|
+
{ srfactag: param.srfactag },
|
|
148
|
+
{ ...resumeRequestData }
|
|
149
|
+
);
|
|
150
|
+
return true;
|
|
151
|
+
} catch (resumeError) {
|
|
152
|
+
if ((resumeError == null ? void 0 : resumeError.name) === "AbortError") {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
(_b = state.abortController) == null ? void 0 : _b.abort();
|
|
156
|
+
if ((resumeError == null ? void 0 : resumeError.message) === this.NONE_ERROR_MESSAGE) {
|
|
157
|
+
aiChat.setActiveAsyncacitonId("");
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
26
161
|
}
|
|
27
162
|
/**
|
|
28
163
|
* 获取AI聊天对象
|
|
@@ -207,7 +342,9 @@ class AIChatUtil {
|
|
|
207
342
|
const chatOptions = {
|
|
208
343
|
locale: ibiz.i18n.getLang(),
|
|
209
344
|
enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
|
|
210
|
-
projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
|
|
345
|
+
projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
|
|
346
|
+
knowledgeBaseView: editorParams.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
|
|
347
|
+
selectAIProjectId: editorParams.srfselectaiprojectid
|
|
211
348
|
};
|
|
212
349
|
if (editorParams.srfaiappendcurdata) {
|
|
213
350
|
chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
|
|
@@ -325,6 +462,16 @@ class AIChatUtil {
|
|
|
325
462
|
editorParams
|
|
326
463
|
);
|
|
327
464
|
};
|
|
465
|
+
chatOptions.openEmbedView = async (ctx, param, viewId, container, selectedData, callback) => {
|
|
466
|
+
await this.openEmbedView(
|
|
467
|
+
ctx,
|
|
468
|
+
param,
|
|
469
|
+
viewId,
|
|
470
|
+
container,
|
|
471
|
+
selectedData,
|
|
472
|
+
callback
|
|
473
|
+
);
|
|
474
|
+
};
|
|
328
475
|
chatOptions.fetchKnowledgeBaseList = (args2 = {}) => {
|
|
329
476
|
return this.getKnowledgeBaseList(context, params, editorParams, args2);
|
|
330
477
|
};
|
|
@@ -358,6 +505,7 @@ class AIChatUtil {
|
|
|
358
505
|
}
|
|
359
506
|
const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
|
|
360
507
|
chatOptions.fileSystemOptions = fileSystemOptions;
|
|
508
|
+
chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
|
|
361
509
|
chatOptions.history = async (ctx, param, other) => {
|
|
362
510
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
363
511
|
const historyRequestData = {};
|
|
@@ -418,37 +566,37 @@ class AIChatUtil {
|
|
|
418
566
|
return true;
|
|
419
567
|
};
|
|
420
568
|
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
|
|
421
|
-
let updateFlag = true;
|
|
422
569
|
const state = getChatState(aiChat);
|
|
423
570
|
state.id = qxUtil.createUUID();
|
|
424
571
|
state.abortController = new AbortController();
|
|
425
572
|
const { id, abortController } = state;
|
|
426
573
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
574
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
427
575
|
try {
|
|
428
|
-
const
|
|
576
|
+
const requestData = {
|
|
429
577
|
messages: arr,
|
|
430
578
|
sessionid: sessionid2
|
|
431
579
|
};
|
|
432
580
|
if (srfaiagent)
|
|
433
|
-
|
|
581
|
+
requestData.srfaiagent = srfaiagent;
|
|
434
582
|
if (srfmode)
|
|
435
|
-
|
|
583
|
+
requestData.mode = srfmode;
|
|
436
584
|
if (srfscope)
|
|
437
|
-
|
|
585
|
+
requestData.srfscope = srfscope;
|
|
438
586
|
if (srfproject)
|
|
439
|
-
|
|
587
|
+
requestData.srfproject = srfproject;
|
|
440
588
|
if (srfknowledgebases)
|
|
441
|
-
|
|
589
|
+
requestData.knowledgebases = srfknowledgebases;
|
|
442
590
|
if (srfaiagentconfig) {
|
|
443
|
-
Object.assign(
|
|
591
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
444
592
|
}
|
|
445
593
|
if (mcpservers) {
|
|
446
|
-
Object.assign(
|
|
594
|
+
Object.assign(requestData, {
|
|
447
595
|
mcpservers
|
|
448
596
|
});
|
|
449
597
|
}
|
|
450
598
|
if (sessionmeta) {
|
|
451
|
-
Object.assign(
|
|
599
|
+
Object.assign(requestData, {
|
|
452
600
|
srfuimeta: JSON.stringify(sessionmeta)
|
|
453
601
|
});
|
|
454
602
|
}
|
|
@@ -460,68 +608,33 @@ class AIChatUtil {
|
|
|
460
608
|
Object.assign(extParams, { ...appendcurdata });
|
|
461
609
|
}
|
|
462
610
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
463
|
-
Object.assign(
|
|
611
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
464
612
|
}
|
|
465
613
|
aiChat.addWaitingMessage(id);
|
|
466
614
|
await deService.aiChatSse(
|
|
467
|
-
|
|
468
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
469
|
-
aiChat.removeWaitingMessage(id);
|
|
470
|
-
if (msg.asextparam && localMsgID && updateFlag) {
|
|
471
|
-
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
472
|
-
updateFlag = false;
|
|
473
|
-
}
|
|
474
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
475
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
476
|
-
}
|
|
477
|
-
aiChat.addMessage({
|
|
478
|
-
messageid: id,
|
|
479
|
-
state: msg.actionstate,
|
|
480
|
-
type: "DEFAULT",
|
|
481
|
-
role: "ASSISTANT",
|
|
482
|
-
content: msg.actionresult,
|
|
483
|
-
status: "pending"
|
|
484
|
-
});
|
|
485
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
486
|
-
const result = JSON.parse(msg.actionresult);
|
|
487
|
-
if (result.usage) {
|
|
488
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
489
|
-
}
|
|
490
|
-
if (result.files) {
|
|
491
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
492
|
-
}
|
|
493
|
-
const choices = result.choices;
|
|
494
|
-
if (choices && choices.length > 0) {
|
|
495
|
-
aiChat.replaceMessage({
|
|
496
|
-
messageid: id,
|
|
497
|
-
state: msg.actionstate,
|
|
498
|
-
type: "DEFAULT",
|
|
499
|
-
role: "ASSISTANT",
|
|
500
|
-
content: choices[0].content || "",
|
|
501
|
-
realmessageid: choices[0].messageid,
|
|
502
|
-
status: "sent"
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
aiChat.setActiveAsyncacitonId("");
|
|
506
|
-
} else if (msg.actionstate === 40) {
|
|
507
|
-
aiChat.replaceMessage({
|
|
508
|
-
messageid: id,
|
|
509
|
-
state: msg.actionstate,
|
|
510
|
-
type: "ERROR",
|
|
511
|
-
role: "ASSISTANT",
|
|
512
|
-
errorText: msg.actionresult,
|
|
513
|
-
status: "failed"
|
|
514
|
-
});
|
|
515
|
-
aiChat.setActiveAsyncacitonId("");
|
|
516
|
-
}
|
|
517
|
-
},
|
|
615
|
+
onMsg,
|
|
518
616
|
abortController,
|
|
519
617
|
ctx,
|
|
520
618
|
{ srfactag: param.srfactag },
|
|
521
|
-
{ ...
|
|
619
|
+
{ ...requestData }
|
|
522
620
|
);
|
|
523
621
|
} catch (error) {
|
|
524
|
-
|
|
622
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
623
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
624
|
+
if (errMsg === "network error" && asyncacitonid) {
|
|
625
|
+
const resumed = await this.autoResumeChat(
|
|
626
|
+
aiChat,
|
|
627
|
+
ctx,
|
|
628
|
+
param,
|
|
629
|
+
deService,
|
|
630
|
+
state,
|
|
631
|
+
{ asyncacitonid, sessionid: sessionid2, srfaiagent, srfproject },
|
|
632
|
+
onMsg
|
|
633
|
+
);
|
|
634
|
+
if (resumed)
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
525
638
|
aiChat.replaceMessage({
|
|
526
639
|
messageid: id,
|
|
527
640
|
state: 40,
|
|
@@ -535,7 +648,8 @@ class AIChatUtil {
|
|
|
535
648
|
aiChat.replaceMessage(
|
|
536
649
|
{
|
|
537
650
|
...lastMessage,
|
|
538
|
-
state: 40
|
|
651
|
+
state: 40,
|
|
652
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
539
653
|
},
|
|
540
654
|
false
|
|
541
655
|
);
|
|
@@ -588,77 +702,33 @@ class AIChatUtil {
|
|
|
588
702
|
state.abortController = new AbortController();
|
|
589
703
|
const { id, abortController } = state;
|
|
590
704
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
591
|
-
const
|
|
705
|
+
const requestData = { asyncacitonid: other.asyncacitonid };
|
|
592
706
|
if (other.sessionid) {
|
|
593
|
-
Object.assign(
|
|
707
|
+
Object.assign(requestData, {
|
|
594
708
|
sessionid: other.sessionid
|
|
595
709
|
});
|
|
596
710
|
}
|
|
597
711
|
if (other.srfaiagent) {
|
|
598
|
-
Object.assign(
|
|
712
|
+
Object.assign(requestData, {
|
|
599
713
|
srfaiagent: other.srfaiagent
|
|
600
714
|
});
|
|
601
715
|
}
|
|
602
716
|
if (other.srfproject)
|
|
603
|
-
Object.assign(
|
|
717
|
+
Object.assign(requestData, {
|
|
604
718
|
srfproject: other.srfproject
|
|
605
719
|
});
|
|
720
|
+
const onMsg = this.createChatSseHandler(aiChat, id, "");
|
|
606
721
|
try {
|
|
607
722
|
await deService.aiResumeSse(
|
|
608
|
-
|
|
609
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
610
|
-
aiChat.isLoading.value = true;
|
|
611
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
612
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
613
|
-
}
|
|
614
|
-
aiChat.addMessage({
|
|
615
|
-
messageid: id,
|
|
616
|
-
state: msg.actionstate,
|
|
617
|
-
type: "DEFAULT",
|
|
618
|
-
role: "ASSISTANT",
|
|
619
|
-
content: msg.actionresult,
|
|
620
|
-
status: "pending"
|
|
621
|
-
});
|
|
622
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
623
|
-
const result = JSON.parse(msg.actionresult);
|
|
624
|
-
if (result.usage) {
|
|
625
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
626
|
-
}
|
|
627
|
-
if (result.files) {
|
|
628
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
629
|
-
}
|
|
630
|
-
const choices = result.choices;
|
|
631
|
-
if (choices && choices.length > 0) {
|
|
632
|
-
aiChat.replaceMessage({
|
|
633
|
-
messageid: id,
|
|
634
|
-
state: msg.actionstate,
|
|
635
|
-
type: "DEFAULT",
|
|
636
|
-
role: "ASSISTANT",
|
|
637
|
-
content: choices[0].content || "",
|
|
638
|
-
realmessageid: choices[0].messageid,
|
|
639
|
-
status: "sent"
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
aiChat.setActiveAsyncacitonId("");
|
|
643
|
-
} else if (msg.actionstate === 40) {
|
|
644
|
-
aiChat.replaceMessage({
|
|
645
|
-
messageid: id,
|
|
646
|
-
state: msg.actionstate,
|
|
647
|
-
type: "ERROR",
|
|
648
|
-
role: "ASSISTANT",
|
|
649
|
-
errorText: msg.actionresult,
|
|
650
|
-
status: "failed"
|
|
651
|
-
});
|
|
652
|
-
aiChat.setActiveAsyncacitonId("");
|
|
653
|
-
}
|
|
654
|
-
},
|
|
723
|
+
onMsg,
|
|
655
724
|
abortController,
|
|
656
725
|
ctx,
|
|
657
726
|
{ srfactag: param.srfactag },
|
|
658
|
-
{ ...
|
|
727
|
+
{ ...requestData }
|
|
659
728
|
);
|
|
660
729
|
} catch (error) {
|
|
661
|
-
|
|
730
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
731
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
662
732
|
if (error && error.message !== this.PRE_ERROR_MESSAGE) {
|
|
663
733
|
aiChat.replaceMessage({
|
|
664
734
|
messageid: id,
|
|
@@ -673,7 +743,8 @@ class AIChatUtil {
|
|
|
673
743
|
aiChat.replaceMessage(
|
|
674
744
|
{
|
|
675
745
|
...lastMessage,
|
|
676
|
-
state: 40
|
|
746
|
+
state: 40,
|
|
747
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
677
748
|
},
|
|
678
749
|
false
|
|
679
750
|
);
|
|
@@ -1031,8 +1102,14 @@ class AIChatUtil {
|
|
|
1031
1102
|
const chatOptions = {
|
|
1032
1103
|
locale: ibiz.i18n.getLang(),
|
|
1033
1104
|
enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
|
|
1034
|
-
projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
|
|
1035
|
-
|
|
1105
|
+
projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
|
|
1106
|
+
knowledgeBaseView: params.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
|
|
1107
|
+
selectAIProjectId: params.srfselectaiprojectid
|
|
1108
|
+
};
|
|
1109
|
+
if (params.hasOwnProperty("srfaiknowledgebaseview"))
|
|
1110
|
+
delete params.srfaiknowledgebaseview;
|
|
1111
|
+
if (params.hasOwnProperty("srfselectaiprojectid"))
|
|
1112
|
+
delete params.srfselectaiprojectid;
|
|
1036
1113
|
if (params.hasOwnProperty("srfenableaiprojectselect"))
|
|
1037
1114
|
delete params.srfenableaiprojectselect;
|
|
1038
1115
|
if (params.hasOwnProperty("srfprojectselectplaceholder"))
|
|
@@ -1173,6 +1250,16 @@ class AIChatUtil {
|
|
|
1173
1250
|
} else {
|
|
1174
1251
|
chatOptions.enableWorkSpace = ibiz.config.common.aiEnableWorkSpace;
|
|
1175
1252
|
}
|
|
1253
|
+
chatOptions.openEmbedView = async (ctx, param, viewId, container, selectedData, callback) => {
|
|
1254
|
+
await this.openEmbedView(
|
|
1255
|
+
ctx,
|
|
1256
|
+
param,
|
|
1257
|
+
viewId,
|
|
1258
|
+
container,
|
|
1259
|
+
selectedData,
|
|
1260
|
+
callback
|
|
1261
|
+
);
|
|
1262
|
+
};
|
|
1176
1263
|
chatOptions.fetchAgentList = (args2 = {}) => {
|
|
1177
1264
|
const { query, agentid } = args2;
|
|
1178
1265
|
return this.getAIAgentList(context, {
|
|
@@ -1213,6 +1300,7 @@ class AIChatUtil {
|
|
|
1213
1300
|
}
|
|
1214
1301
|
const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
|
|
1215
1302
|
chatOptions.fileSystemOptions = fileSystemOptions;
|
|
1303
|
+
chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
|
|
1216
1304
|
chatOptions.history = async (ctx, param, other) => {
|
|
1217
1305
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1218
1306
|
const historyRequestData = {};
|
|
@@ -1273,35 +1361,35 @@ class AIChatUtil {
|
|
|
1273
1361
|
return true;
|
|
1274
1362
|
};
|
|
1275
1363
|
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
|
|
1276
|
-
let updateFlag = true;
|
|
1277
1364
|
const state = getChatState(aiChat);
|
|
1278
1365
|
state.id = qxUtil.createUUID();
|
|
1279
1366
|
state.abortController = new AbortController();
|
|
1280
1367
|
const { id, abortController } = state;
|
|
1281
1368
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1369
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
1282
1370
|
try {
|
|
1283
|
-
const
|
|
1371
|
+
const requestData = {
|
|
1284
1372
|
messages: arr,
|
|
1285
1373
|
sessionid
|
|
1286
1374
|
};
|
|
1287
1375
|
if (srfaiagent)
|
|
1288
|
-
|
|
1376
|
+
requestData.srfaiagent = srfaiagent;
|
|
1289
1377
|
if (srfmode)
|
|
1290
|
-
|
|
1378
|
+
requestData.mode = srfmode;
|
|
1291
1379
|
if (srfscope)
|
|
1292
|
-
|
|
1380
|
+
requestData.srfscope = srfscope;
|
|
1293
1381
|
if (srfproject)
|
|
1294
|
-
|
|
1382
|
+
requestData.srfproject = srfproject;
|
|
1295
1383
|
if (srfknowledgebases)
|
|
1296
|
-
|
|
1384
|
+
requestData.knowledgebases = srfknowledgebases;
|
|
1297
1385
|
if (srfaiagentconfig) {
|
|
1298
|
-
Object.assign(
|
|
1386
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
1299
1387
|
}
|
|
1300
1388
|
if (mcpservers) {
|
|
1301
|
-
Object.assign(
|
|
1389
|
+
Object.assign(requestData, { mcpservers });
|
|
1302
1390
|
}
|
|
1303
1391
|
if (sessionmeta) {
|
|
1304
|
-
Object.assign(
|
|
1392
|
+
Object.assign(requestData, {
|
|
1305
1393
|
srfuimeta: JSON.stringify(sessionmeta)
|
|
1306
1394
|
});
|
|
1307
1395
|
}
|
|
@@ -1313,68 +1401,33 @@ class AIChatUtil {
|
|
|
1313
1401
|
Object.assign(extParams, { ...appendcurdata });
|
|
1314
1402
|
}
|
|
1315
1403
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
1316
|
-
Object.assign(
|
|
1404
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
1317
1405
|
}
|
|
1318
1406
|
aiChat.addWaitingMessage(id);
|
|
1319
1407
|
await deService.aiChatSse(
|
|
1320
|
-
|
|
1321
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1322
|
-
aiChat.removeWaitingMessage(id);
|
|
1323
|
-
if (msg.asextparam && localMsgID && updateFlag) {
|
|
1324
|
-
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
1325
|
-
updateFlag = false;
|
|
1326
|
-
}
|
|
1327
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1328
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1329
|
-
}
|
|
1330
|
-
aiChat.addMessage({
|
|
1331
|
-
messageid: id,
|
|
1332
|
-
state: msg.actionstate,
|
|
1333
|
-
type: "DEFAULT",
|
|
1334
|
-
role: "ASSISTANT",
|
|
1335
|
-
content: msg.actionresult,
|
|
1336
|
-
status: "pending"
|
|
1337
|
-
});
|
|
1338
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1339
|
-
const result = JSON.parse(msg.actionresult);
|
|
1340
|
-
if (result.usage) {
|
|
1341
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
1342
|
-
}
|
|
1343
|
-
if (result.files) {
|
|
1344
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
1345
|
-
}
|
|
1346
|
-
const choices = result.choices;
|
|
1347
|
-
if (choices && choices.length > 0) {
|
|
1348
|
-
aiChat.replaceMessage({
|
|
1349
|
-
messageid: id,
|
|
1350
|
-
state: msg.actionstate,
|
|
1351
|
-
type: "DEFAULT",
|
|
1352
|
-
role: "ASSISTANT",
|
|
1353
|
-
content: choices[0].content || "",
|
|
1354
|
-
realmessageid: choices[0].messageid,
|
|
1355
|
-
status: "sent"
|
|
1356
|
-
});
|
|
1357
|
-
}
|
|
1358
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1359
|
-
} else if (msg.actionstate === 40) {
|
|
1360
|
-
aiChat.replaceMessage({
|
|
1361
|
-
messageid: id,
|
|
1362
|
-
state: msg.actionstate,
|
|
1363
|
-
type: "ERROR",
|
|
1364
|
-
role: "ASSISTANT",
|
|
1365
|
-
errorText: msg.actionresult,
|
|
1366
|
-
status: "failed"
|
|
1367
|
-
});
|
|
1368
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1369
|
-
}
|
|
1370
|
-
},
|
|
1408
|
+
onMsg,
|
|
1371
1409
|
abortController,
|
|
1372
1410
|
ctx,
|
|
1373
1411
|
{ srfactag: param.srfactag },
|
|
1374
|
-
{ ...
|
|
1412
|
+
{ ...requestData }
|
|
1375
1413
|
);
|
|
1376
1414
|
} catch (error) {
|
|
1377
|
-
|
|
1415
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
1416
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
1417
|
+
if (errMsg === "network error" && asyncacitonid) {
|
|
1418
|
+
const resumed = await this.autoResumeChat(
|
|
1419
|
+
aiChat,
|
|
1420
|
+
ctx,
|
|
1421
|
+
param,
|
|
1422
|
+
deService,
|
|
1423
|
+
state,
|
|
1424
|
+
{ asyncacitonid, sessionid, srfaiagent, srfproject },
|
|
1425
|
+
onMsg
|
|
1426
|
+
);
|
|
1427
|
+
if (resumed)
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
1378
1431
|
aiChat.replaceMessage({
|
|
1379
1432
|
messageid: id,
|
|
1380
1433
|
state: 40,
|
|
@@ -1388,7 +1441,8 @@ class AIChatUtil {
|
|
|
1388
1441
|
aiChat.replaceMessage(
|
|
1389
1442
|
{
|
|
1390
1443
|
...lastMessage,
|
|
1391
|
-
state: 40
|
|
1444
|
+
state: 40,
|
|
1445
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
1392
1446
|
},
|
|
1393
1447
|
false
|
|
1394
1448
|
);
|
|
@@ -1441,77 +1495,33 @@ class AIChatUtil {
|
|
|
1441
1495
|
state.abortController = new AbortController();
|
|
1442
1496
|
const { id, abortController } = state;
|
|
1443
1497
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1444
|
-
const
|
|
1498
|
+
const requestData = { asyncacitonid: other.asyncacitonid };
|
|
1445
1499
|
if (other.sessionid) {
|
|
1446
|
-
Object.assign(
|
|
1500
|
+
Object.assign(requestData, {
|
|
1447
1501
|
sessionid: other.sessionid
|
|
1448
1502
|
});
|
|
1449
1503
|
}
|
|
1450
1504
|
if (other.srfaiagent) {
|
|
1451
|
-
Object.assign(
|
|
1505
|
+
Object.assign(requestData, {
|
|
1452
1506
|
srfaiagent: other.srfaiagent
|
|
1453
1507
|
});
|
|
1454
1508
|
}
|
|
1455
1509
|
if (other.srfproject)
|
|
1456
|
-
Object.assign(
|
|
1510
|
+
Object.assign(requestData, {
|
|
1457
1511
|
srfproject: other.srfproject
|
|
1458
1512
|
});
|
|
1513
|
+
const onMsg = this.createChatSseHandler(aiChat, id, "");
|
|
1459
1514
|
try {
|
|
1460
1515
|
await deService.aiResumeSse(
|
|
1461
|
-
|
|
1462
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1463
|
-
aiChat.isLoading.value = true;
|
|
1464
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1465
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1466
|
-
}
|
|
1467
|
-
aiChat.addMessage({
|
|
1468
|
-
messageid: id,
|
|
1469
|
-
state: msg.actionstate,
|
|
1470
|
-
type: "DEFAULT",
|
|
1471
|
-
role: "ASSISTANT",
|
|
1472
|
-
content: msg.actionresult,
|
|
1473
|
-
status: "pending"
|
|
1474
|
-
});
|
|
1475
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1476
|
-
const result = JSON.parse(msg.actionresult);
|
|
1477
|
-
if (result.usage) {
|
|
1478
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
1479
|
-
}
|
|
1480
|
-
if (result.files) {
|
|
1481
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
1482
|
-
}
|
|
1483
|
-
const choices = result.choices;
|
|
1484
|
-
if (choices && choices.length > 0) {
|
|
1485
|
-
aiChat.replaceMessage({
|
|
1486
|
-
messageid: id,
|
|
1487
|
-
state: msg.actionstate,
|
|
1488
|
-
type: "DEFAULT",
|
|
1489
|
-
role: "ASSISTANT",
|
|
1490
|
-
content: choices[0].content || "",
|
|
1491
|
-
realmessageid: choices[0].messageid,
|
|
1492
|
-
status: "sent"
|
|
1493
|
-
});
|
|
1494
|
-
}
|
|
1495
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1496
|
-
} else if (msg.actionstate === 40) {
|
|
1497
|
-
aiChat.replaceMessage({
|
|
1498
|
-
messageid: id,
|
|
1499
|
-
state: msg.actionstate,
|
|
1500
|
-
type: "ERROR",
|
|
1501
|
-
role: "ASSISTANT",
|
|
1502
|
-
errorText: msg.actionresult,
|
|
1503
|
-
status: "failed"
|
|
1504
|
-
});
|
|
1505
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1506
|
-
}
|
|
1507
|
-
},
|
|
1516
|
+
onMsg,
|
|
1508
1517
|
abortController,
|
|
1509
1518
|
ctx,
|
|
1510
1519
|
{ srfactag: param.srfactag },
|
|
1511
|
-
{ ...
|
|
1520
|
+
{ ...requestData }
|
|
1512
1521
|
);
|
|
1513
1522
|
} catch (error) {
|
|
1514
|
-
|
|
1523
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
1524
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
1515
1525
|
if (error && error.message !== this.PRE_ERROR_MESSAGE) {
|
|
1516
1526
|
aiChat.replaceMessage({
|
|
1517
1527
|
messageid: id,
|
|
@@ -1526,7 +1536,8 @@ class AIChatUtil {
|
|
|
1526
1536
|
aiChat.replaceMessage(
|
|
1527
1537
|
{
|
|
1528
1538
|
...lastMessage,
|
|
1529
|
-
state: 40
|
|
1539
|
+
state: 40,
|
|
1540
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
1530
1541
|
},
|
|
1531
1542
|
false
|
|
1532
1543
|
);
|
|
@@ -2227,6 +2238,77 @@ class AIChatUtil {
|
|
|
2227
2238
|
};
|
|
2228
2239
|
return fileSystemOptions;
|
|
2229
2240
|
}
|
|
2241
|
+
/**
|
|
2242
|
+
* @description 打开嵌入视图
|
|
2243
|
+
* @private
|
|
2244
|
+
* @param {IContext} context 上下文
|
|
2245
|
+
* @param {IParams} params 视图参数
|
|
2246
|
+
* @param {string} viewId 视图标识
|
|
2247
|
+
* @param {HTMLElement} container 视图挂载容器
|
|
2248
|
+
* @param {IData[]} [selectedData] 选中数据
|
|
2249
|
+
* @param {(result: IModalData) => void} [callback] 回调
|
|
2250
|
+
* @returns {*} {Promise<void>}
|
|
2251
|
+
* @memberof AIChatUtil
|
|
2252
|
+
*/
|
|
2253
|
+
async openEmbedView(context, params, viewId, container, selectedData, callback) {
|
|
2254
|
+
vue.render(null, container);
|
|
2255
|
+
const modal = new runtime.Modal({
|
|
2256
|
+
mode: runtime.ViewMode.EMBED,
|
|
2257
|
+
viewUsage: 2,
|
|
2258
|
+
dismiss: (result) => {
|
|
2259
|
+
callback == null ? void 0 : callback(result);
|
|
2260
|
+
vue.render(null, container);
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
const modelData = await ibiz.hub.getAppView(viewId);
|
|
2264
|
+
const vNode = vue.createVNode(vue3Util.IBizViewShell, {
|
|
2265
|
+
modal,
|
|
2266
|
+
modelData,
|
|
2267
|
+
context,
|
|
2268
|
+
params: { ...params, checkstrictly: true },
|
|
2269
|
+
style: {
|
|
2270
|
+
height: "".concat(modelData.height || 400, "px")
|
|
2271
|
+
},
|
|
2272
|
+
state: {
|
|
2273
|
+
selectedData
|
|
2274
|
+
}
|
|
2275
|
+
});
|
|
2276
|
+
vNode.appContext = this.App._context;
|
|
2277
|
+
vue.render(vNode, container);
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* @description 获取异步行为配置
|
|
2281
|
+
* @returns {*} {Promise<IData>}
|
|
2282
|
+
* @memberof AIChatUtil
|
|
2283
|
+
*/
|
|
2284
|
+
async getAIAsyncActionOptions() {
|
|
2285
|
+
const asyncActionOptions = {};
|
|
2286
|
+
asyncActionOptions.getLastAsyncAction = async (asyncActionID) => {
|
|
2287
|
+
const result = await ibiz.hub.notice.asyncAction.service.get(asyncActionID);
|
|
2288
|
+
if (result.ok && result.data) {
|
|
2289
|
+
return result.data;
|
|
2290
|
+
}
|
|
2291
|
+
return null;
|
|
2292
|
+
};
|
|
2293
|
+
asyncActionOptions.registerCallBack = (asyncActionID, callback) => {
|
|
2294
|
+
let callbacks = this.asyncActionCallBackMap.get(asyncActionID);
|
|
2295
|
+
if (!callbacks) {
|
|
2296
|
+
callbacks = /* @__PURE__ */ new Set();
|
|
2297
|
+
this.asyncActionCallBackMap.set(asyncActionID, callbacks);
|
|
2298
|
+
}
|
|
2299
|
+
callbacks.add(callback);
|
|
2300
|
+
return () => {
|
|
2301
|
+
callbacks.delete(callback);
|
|
2302
|
+
if (!callbacks.size) {
|
|
2303
|
+
this.asyncActionCallBackMap.delete(asyncActionID);
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
};
|
|
2307
|
+
asyncActionOptions.onPreview = async (asyncAction, _event) => {
|
|
2308
|
+
return asyncAction_provider.openAsyncActionModal(asyncAction);
|
|
2309
|
+
};
|
|
2310
|
+
return asyncActionOptions;
|
|
2311
|
+
}
|
|
2230
2312
|
}
|
|
2231
2313
|
|
|
2232
2314
|
exports.AIChatUtil = AIChatUtil;
|