@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
|
@@ -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
|
-
|
|
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,6 +29,133 @@ 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");
|
|
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
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
|
|
48
|
+
* @param {any} aiChat 单实例聊天总控
|
|
49
|
+
* @param {string} id 本次问答的流式消息 id
|
|
50
|
+
* @param {string} localMsgID 本地用户消息 id(用于回填真实消息 id;为空串时为恢复会话场景,状态 20 走 isLoading 加载分支)
|
|
51
|
+
* @return {*} {(msg: IPortalAsyncAction) => void}
|
|
52
|
+
* @memberof AIChatUtil
|
|
53
|
+
*/
|
|
54
|
+
createChatSseHandler(aiChat, id, localMsgID) {
|
|
55
|
+
let updateFlag = true;
|
|
56
|
+
return (msg) => {
|
|
57
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
58
|
+
if (localMsgID) {
|
|
59
|
+
aiChat.removeWaitingMessage(id);
|
|
60
|
+
if (msg.asextparam && updateFlag) {
|
|
61
|
+
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
62
|
+
updateFlag = false;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
aiChat.isLoading.value = true;
|
|
66
|
+
}
|
|
67
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
68
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
69
|
+
}
|
|
70
|
+
aiChat.addMessage({
|
|
71
|
+
messageid: id,
|
|
72
|
+
state: msg.actionstate,
|
|
73
|
+
type: "DEFAULT",
|
|
74
|
+
role: "ASSISTANT",
|
|
75
|
+
content: msg.actionresult,
|
|
76
|
+
status: "pending"
|
|
77
|
+
});
|
|
78
|
+
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
79
|
+
const result = JSON.parse(msg.actionresult);
|
|
80
|
+
if (result.usage) {
|
|
81
|
+
aiChat.updateMsgUsage(id, result.usage);
|
|
82
|
+
}
|
|
83
|
+
if (result.files) {
|
|
84
|
+
aiChat.updateMsgOutputFiles(id, result.files);
|
|
85
|
+
}
|
|
86
|
+
const choices = result.choices;
|
|
87
|
+
if (choices && choices.length > 0) {
|
|
88
|
+
aiChat.replaceMessage({
|
|
89
|
+
messageid: id,
|
|
90
|
+
state: msg.actionstate,
|
|
91
|
+
type: "DEFAULT",
|
|
92
|
+
role: "ASSISTANT",
|
|
93
|
+
content: choices[0].content || "",
|
|
94
|
+
realmessageid: choices[0].messageid,
|
|
95
|
+
status: "sent"
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
aiChat.setActiveAsyncacitonId("");
|
|
99
|
+
} else if (msg.actionstate === 40) {
|
|
100
|
+
aiChat.replaceMessage({
|
|
101
|
+
messageid: id,
|
|
102
|
+
state: msg.actionstate,
|
|
103
|
+
type: "ERROR",
|
|
104
|
+
role: "ASSISTANT",
|
|
105
|
+
errorText: msg.actionresult,
|
|
106
|
+
status: "failed"
|
|
107
|
+
});
|
|
108
|
+
aiChat.setActiveAsyncacitonId("");
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @description 网络中断(network error)后按 asyncacitonid 自动续传一次;成功返回 true,失败返回 false 交回调用方走既有错误处理
|
|
114
|
+
* @param {any} aiChat 单实例聊天总控
|
|
115
|
+
* @param {IContext} ctx 上下文
|
|
116
|
+
* @param {IParams} param 视图参数
|
|
117
|
+
* @param {*} deService 实体服务
|
|
118
|
+
* @param {{ id: string; abortController: AbortController }} state 聊天实例提问状态(WeakMap 持有的同一对象引用)
|
|
119
|
+
* @param {{ asyncacitonid: string; sessionid?: string; srfaiagent?: string; srfproject?: string }} resumeInfo 续传参数
|
|
120
|
+
* @param {(msg: IPortalAsyncAction) => void} onMsg SSE 流式消息处理回调
|
|
121
|
+
* @return {*} {Promise<boolean>} 是否续传成功
|
|
122
|
+
* @memberof AIChatUtil
|
|
123
|
+
*/
|
|
124
|
+
async autoResumeChat(aiChat, ctx, param, deService, state, resumeInfo, onMsg) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
(_a = state.abortController) == null ? void 0 : _a.abort();
|
|
127
|
+
state.abortController = new AbortController();
|
|
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("");
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
24
159
|
}
|
|
25
160
|
/**
|
|
26
161
|
* 获取AI聊天对象
|
|
@@ -205,7 +340,9 @@ class AIChatUtil {
|
|
|
205
340
|
const chatOptions = {
|
|
206
341
|
locale: ibiz.i18n.getLang(),
|
|
207
342
|
enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
|
|
208
|
-
projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
|
|
343
|
+
projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
|
|
344
|
+
knowledgeBaseView: editorParams.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
|
|
345
|
+
selectAIProjectId: editorParams.srfselectaiprojectid
|
|
209
346
|
};
|
|
210
347
|
if (editorParams.srfaiappendcurdata) {
|
|
211
348
|
chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
|
|
@@ -323,6 +460,16 @@ class AIChatUtil {
|
|
|
323
460
|
editorParams
|
|
324
461
|
);
|
|
325
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
|
+
};
|
|
326
473
|
chatOptions.fetchKnowledgeBaseList = (args2 = {}) => {
|
|
327
474
|
return this.getKnowledgeBaseList(context, params, editorParams, args2);
|
|
328
475
|
};
|
|
@@ -356,6 +503,7 @@ class AIChatUtil {
|
|
|
356
503
|
}
|
|
357
504
|
const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
|
|
358
505
|
chatOptions.fileSystemOptions = fileSystemOptions;
|
|
506
|
+
chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
|
|
359
507
|
chatOptions.history = async (ctx, param, other) => {
|
|
360
508
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
361
509
|
const historyRequestData = {};
|
|
@@ -416,37 +564,37 @@ class AIChatUtil {
|
|
|
416
564
|
return true;
|
|
417
565
|
};
|
|
418
566
|
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
|
|
419
|
-
let updateFlag = true;
|
|
420
567
|
const state = getChatState(aiChat);
|
|
421
568
|
state.id = createUUID();
|
|
422
569
|
state.abortController = new AbortController();
|
|
423
570
|
const { id, abortController } = state;
|
|
424
571
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
572
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
425
573
|
try {
|
|
426
|
-
const
|
|
574
|
+
const requestData = {
|
|
427
575
|
messages: arr,
|
|
428
576
|
sessionid: sessionid2
|
|
429
577
|
};
|
|
430
578
|
if (srfaiagent)
|
|
431
|
-
|
|
579
|
+
requestData.srfaiagent = srfaiagent;
|
|
432
580
|
if (srfmode)
|
|
433
|
-
|
|
581
|
+
requestData.mode = srfmode;
|
|
434
582
|
if (srfscope)
|
|
435
|
-
|
|
583
|
+
requestData.srfscope = srfscope;
|
|
436
584
|
if (srfproject)
|
|
437
|
-
|
|
585
|
+
requestData.srfproject = srfproject;
|
|
438
586
|
if (srfknowledgebases)
|
|
439
|
-
|
|
587
|
+
requestData.knowledgebases = srfknowledgebases;
|
|
440
588
|
if (srfaiagentconfig) {
|
|
441
|
-
Object.assign(
|
|
589
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
442
590
|
}
|
|
443
591
|
if (mcpservers) {
|
|
444
|
-
Object.assign(
|
|
592
|
+
Object.assign(requestData, {
|
|
445
593
|
mcpservers
|
|
446
594
|
});
|
|
447
595
|
}
|
|
448
596
|
if (sessionmeta) {
|
|
449
|
-
Object.assign(
|
|
597
|
+
Object.assign(requestData, {
|
|
450
598
|
srfuimeta: JSON.stringify(sessionmeta)
|
|
451
599
|
});
|
|
452
600
|
}
|
|
@@ -458,68 +606,33 @@ class AIChatUtil {
|
|
|
458
606
|
Object.assign(extParams, { ...appendcurdata });
|
|
459
607
|
}
|
|
460
608
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
461
|
-
Object.assign(
|
|
609
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
462
610
|
}
|
|
463
611
|
aiChat.addWaitingMessage(id);
|
|
464
612
|
await deService.aiChatSse(
|
|
465
|
-
|
|
466
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
467
|
-
aiChat.removeWaitingMessage(id);
|
|
468
|
-
if (msg.asextparam && localMsgID && updateFlag) {
|
|
469
|
-
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
470
|
-
updateFlag = false;
|
|
471
|
-
}
|
|
472
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
473
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
474
|
-
}
|
|
475
|
-
aiChat.addMessage({
|
|
476
|
-
messageid: id,
|
|
477
|
-
state: msg.actionstate,
|
|
478
|
-
type: "DEFAULT",
|
|
479
|
-
role: "ASSISTANT",
|
|
480
|
-
content: msg.actionresult,
|
|
481
|
-
status: "pending"
|
|
482
|
-
});
|
|
483
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
484
|
-
const result = JSON.parse(msg.actionresult);
|
|
485
|
-
if (result.usage) {
|
|
486
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
487
|
-
}
|
|
488
|
-
if (result.files) {
|
|
489
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
490
|
-
}
|
|
491
|
-
const choices = result.choices;
|
|
492
|
-
if (choices && choices.length > 0) {
|
|
493
|
-
aiChat.replaceMessage({
|
|
494
|
-
messageid: id,
|
|
495
|
-
state: msg.actionstate,
|
|
496
|
-
type: "DEFAULT",
|
|
497
|
-
role: "ASSISTANT",
|
|
498
|
-
content: choices[0].content || "",
|
|
499
|
-
realmessageid: choices[0].messageid,
|
|
500
|
-
status: "sent"
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
aiChat.setActiveAsyncacitonId("");
|
|
504
|
-
} else if (msg.actionstate === 40) {
|
|
505
|
-
aiChat.replaceMessage({
|
|
506
|
-
messageid: id,
|
|
507
|
-
state: msg.actionstate,
|
|
508
|
-
type: "ERROR",
|
|
509
|
-
role: "ASSISTANT",
|
|
510
|
-
errorText: msg.actionresult,
|
|
511
|
-
status: "failed"
|
|
512
|
-
});
|
|
513
|
-
aiChat.setActiveAsyncacitonId("");
|
|
514
|
-
}
|
|
515
|
-
},
|
|
613
|
+
onMsg,
|
|
516
614
|
abortController,
|
|
517
615
|
ctx,
|
|
518
616
|
{ srfactag: param.srfactag },
|
|
519
|
-
{ ...
|
|
617
|
+
{ ...requestData }
|
|
520
618
|
);
|
|
521
619
|
} catch (error) {
|
|
522
|
-
|
|
620
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
621
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
622
|
+
if (errMsg === "network error" && asyncacitonid) {
|
|
623
|
+
const resumed = await this.autoResumeChat(
|
|
624
|
+
aiChat,
|
|
625
|
+
ctx,
|
|
626
|
+
param,
|
|
627
|
+
deService,
|
|
628
|
+
state,
|
|
629
|
+
{ asyncacitonid, sessionid: sessionid2, srfaiagent, srfproject },
|
|
630
|
+
onMsg
|
|
631
|
+
);
|
|
632
|
+
if (resumed)
|
|
633
|
+
return true;
|
|
634
|
+
}
|
|
635
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
523
636
|
aiChat.replaceMessage({
|
|
524
637
|
messageid: id,
|
|
525
638
|
state: 40,
|
|
@@ -533,7 +646,8 @@ class AIChatUtil {
|
|
|
533
646
|
aiChat.replaceMessage(
|
|
534
647
|
{
|
|
535
648
|
...lastMessage,
|
|
536
|
-
state: 40
|
|
649
|
+
state: 40,
|
|
650
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
537
651
|
},
|
|
538
652
|
false
|
|
539
653
|
);
|
|
@@ -586,77 +700,33 @@ class AIChatUtil {
|
|
|
586
700
|
state.abortController = new AbortController();
|
|
587
701
|
const { id, abortController } = state;
|
|
588
702
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
589
|
-
const
|
|
703
|
+
const requestData = { asyncacitonid: other.asyncacitonid };
|
|
590
704
|
if (other.sessionid) {
|
|
591
|
-
Object.assign(
|
|
705
|
+
Object.assign(requestData, {
|
|
592
706
|
sessionid: other.sessionid
|
|
593
707
|
});
|
|
594
708
|
}
|
|
595
709
|
if (other.srfaiagent) {
|
|
596
|
-
Object.assign(
|
|
710
|
+
Object.assign(requestData, {
|
|
597
711
|
srfaiagent: other.srfaiagent
|
|
598
712
|
});
|
|
599
713
|
}
|
|
600
714
|
if (other.srfproject)
|
|
601
|
-
Object.assign(
|
|
715
|
+
Object.assign(requestData, {
|
|
602
716
|
srfproject: other.srfproject
|
|
603
717
|
});
|
|
718
|
+
const onMsg = this.createChatSseHandler(aiChat, id, "");
|
|
604
719
|
try {
|
|
605
720
|
await deService.aiResumeSse(
|
|
606
|
-
|
|
607
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
608
|
-
aiChat.isLoading.value = true;
|
|
609
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
610
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
611
|
-
}
|
|
612
|
-
aiChat.addMessage({
|
|
613
|
-
messageid: id,
|
|
614
|
-
state: msg.actionstate,
|
|
615
|
-
type: "DEFAULT",
|
|
616
|
-
role: "ASSISTANT",
|
|
617
|
-
content: msg.actionresult,
|
|
618
|
-
status: "pending"
|
|
619
|
-
});
|
|
620
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
621
|
-
const result = JSON.parse(msg.actionresult);
|
|
622
|
-
if (result.usage) {
|
|
623
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
624
|
-
}
|
|
625
|
-
if (result.files) {
|
|
626
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
627
|
-
}
|
|
628
|
-
const choices = result.choices;
|
|
629
|
-
if (choices && choices.length > 0) {
|
|
630
|
-
aiChat.replaceMessage({
|
|
631
|
-
messageid: id,
|
|
632
|
-
state: msg.actionstate,
|
|
633
|
-
type: "DEFAULT",
|
|
634
|
-
role: "ASSISTANT",
|
|
635
|
-
content: choices[0].content || "",
|
|
636
|
-
realmessageid: choices[0].messageid,
|
|
637
|
-
status: "sent"
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
aiChat.setActiveAsyncacitonId("");
|
|
641
|
-
} else if (msg.actionstate === 40) {
|
|
642
|
-
aiChat.replaceMessage({
|
|
643
|
-
messageid: id,
|
|
644
|
-
state: msg.actionstate,
|
|
645
|
-
type: "ERROR",
|
|
646
|
-
role: "ASSISTANT",
|
|
647
|
-
errorText: msg.actionresult,
|
|
648
|
-
status: "failed"
|
|
649
|
-
});
|
|
650
|
-
aiChat.setActiveAsyncacitonId("");
|
|
651
|
-
}
|
|
652
|
-
},
|
|
721
|
+
onMsg,
|
|
653
722
|
abortController,
|
|
654
723
|
ctx,
|
|
655
724
|
{ srfactag: param.srfactag },
|
|
656
|
-
{ ...
|
|
725
|
+
{ ...requestData }
|
|
657
726
|
);
|
|
658
727
|
} catch (error) {
|
|
659
|
-
|
|
728
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
729
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
660
730
|
if (error && error.message !== this.PRE_ERROR_MESSAGE) {
|
|
661
731
|
aiChat.replaceMessage({
|
|
662
732
|
messageid: id,
|
|
@@ -671,7 +741,8 @@ class AIChatUtil {
|
|
|
671
741
|
aiChat.replaceMessage(
|
|
672
742
|
{
|
|
673
743
|
...lastMessage,
|
|
674
|
-
state: 40
|
|
744
|
+
state: 40,
|
|
745
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
675
746
|
},
|
|
676
747
|
false
|
|
677
748
|
);
|
|
@@ -1029,8 +1100,14 @@ class AIChatUtil {
|
|
|
1029
1100
|
const chatOptions = {
|
|
1030
1101
|
locale: ibiz.i18n.getLang(),
|
|
1031
1102
|
enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
|
|
1032
|
-
projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
|
|
1033
|
-
|
|
1103
|
+
projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
|
|
1104
|
+
knowledgeBaseView: params.srfaiknowledgebaseview || ibiz.config.common.aiKnowledgeBaseView,
|
|
1105
|
+
selectAIProjectId: params.srfselectaiprojectid
|
|
1106
|
+
};
|
|
1107
|
+
if (params.hasOwnProperty("srfaiknowledgebaseview"))
|
|
1108
|
+
delete params.srfaiknowledgebaseview;
|
|
1109
|
+
if (params.hasOwnProperty("srfselectaiprojectid"))
|
|
1110
|
+
delete params.srfselectaiprojectid;
|
|
1034
1111
|
if (params.hasOwnProperty("srfenableaiprojectselect"))
|
|
1035
1112
|
delete params.srfenableaiprojectselect;
|
|
1036
1113
|
if (params.hasOwnProperty("srfprojectselectplaceholder"))
|
|
@@ -1171,6 +1248,16 @@ class AIChatUtil {
|
|
|
1171
1248
|
} else {
|
|
1172
1249
|
chatOptions.enableWorkSpace = ibiz.config.common.aiEnableWorkSpace;
|
|
1173
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
|
+
};
|
|
1174
1261
|
chatOptions.fetchAgentList = (args2 = {}) => {
|
|
1175
1262
|
const { query, agentid } = args2;
|
|
1176
1263
|
return this.getAIAgentList(context, {
|
|
@@ -1211,6 +1298,7 @@ class AIChatUtil {
|
|
|
1211
1298
|
}
|
|
1212
1299
|
const fileSystemOptions = await this.getAIFileSystemOptions(filePreviewMode);
|
|
1213
1300
|
chatOptions.fileSystemOptions = fileSystemOptions;
|
|
1301
|
+
chatOptions.asyncActionOptions = await this.getAIAsyncActionOptions();
|
|
1214
1302
|
chatOptions.history = async (ctx, param, other) => {
|
|
1215
1303
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1216
1304
|
const historyRequestData = {};
|
|
@@ -1271,35 +1359,35 @@ class AIChatUtil {
|
|
|
1271
1359
|
return true;
|
|
1272
1360
|
};
|
|
1273
1361
|
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
|
|
1274
|
-
let updateFlag = true;
|
|
1275
1362
|
const state = getChatState(aiChat);
|
|
1276
1363
|
state.id = createUUID();
|
|
1277
1364
|
state.abortController = new AbortController();
|
|
1278
1365
|
const { id, abortController } = state;
|
|
1279
1366
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1367
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
1280
1368
|
try {
|
|
1281
|
-
const
|
|
1369
|
+
const requestData = {
|
|
1282
1370
|
messages: arr,
|
|
1283
1371
|
sessionid
|
|
1284
1372
|
};
|
|
1285
1373
|
if (srfaiagent)
|
|
1286
|
-
|
|
1374
|
+
requestData.srfaiagent = srfaiagent;
|
|
1287
1375
|
if (srfmode)
|
|
1288
|
-
|
|
1376
|
+
requestData.mode = srfmode;
|
|
1289
1377
|
if (srfscope)
|
|
1290
|
-
|
|
1378
|
+
requestData.srfscope = srfscope;
|
|
1291
1379
|
if (srfproject)
|
|
1292
|
-
|
|
1380
|
+
requestData.srfproject = srfproject;
|
|
1293
1381
|
if (srfknowledgebases)
|
|
1294
|
-
|
|
1382
|
+
requestData.knowledgebases = srfknowledgebases;
|
|
1295
1383
|
if (srfaiagentconfig) {
|
|
1296
|
-
Object.assign(
|
|
1384
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
1297
1385
|
}
|
|
1298
1386
|
if (mcpservers) {
|
|
1299
|
-
Object.assign(
|
|
1387
|
+
Object.assign(requestData, { mcpservers });
|
|
1300
1388
|
}
|
|
1301
1389
|
if (sessionmeta) {
|
|
1302
|
-
Object.assign(
|
|
1390
|
+
Object.assign(requestData, {
|
|
1303
1391
|
srfuimeta: JSON.stringify(sessionmeta)
|
|
1304
1392
|
});
|
|
1305
1393
|
}
|
|
@@ -1311,68 +1399,33 @@ class AIChatUtil {
|
|
|
1311
1399
|
Object.assign(extParams, { ...appendcurdata });
|
|
1312
1400
|
}
|
|
1313
1401
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
1314
|
-
Object.assign(
|
|
1402
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
1315
1403
|
}
|
|
1316
1404
|
aiChat.addWaitingMessage(id);
|
|
1317
1405
|
await deService.aiChatSse(
|
|
1318
|
-
|
|
1319
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1320
|
-
aiChat.removeWaitingMessage(id);
|
|
1321
|
-
if (msg.asextparam && localMsgID && updateFlag) {
|
|
1322
|
-
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
1323
|
-
updateFlag = false;
|
|
1324
|
-
}
|
|
1325
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1326
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1327
|
-
}
|
|
1328
|
-
aiChat.addMessage({
|
|
1329
|
-
messageid: id,
|
|
1330
|
-
state: msg.actionstate,
|
|
1331
|
-
type: "DEFAULT",
|
|
1332
|
-
role: "ASSISTANT",
|
|
1333
|
-
content: msg.actionresult,
|
|
1334
|
-
status: "pending"
|
|
1335
|
-
});
|
|
1336
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1337
|
-
const result = JSON.parse(msg.actionresult);
|
|
1338
|
-
if (result.usage) {
|
|
1339
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
1340
|
-
}
|
|
1341
|
-
if (result.files) {
|
|
1342
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
1343
|
-
}
|
|
1344
|
-
const choices = result.choices;
|
|
1345
|
-
if (choices && choices.length > 0) {
|
|
1346
|
-
aiChat.replaceMessage({
|
|
1347
|
-
messageid: id,
|
|
1348
|
-
state: msg.actionstate,
|
|
1349
|
-
type: "DEFAULT",
|
|
1350
|
-
role: "ASSISTANT",
|
|
1351
|
-
content: choices[0].content || "",
|
|
1352
|
-
realmessageid: choices[0].messageid,
|
|
1353
|
-
status: "sent"
|
|
1354
|
-
});
|
|
1355
|
-
}
|
|
1356
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1357
|
-
} else if (msg.actionstate === 40) {
|
|
1358
|
-
aiChat.replaceMessage({
|
|
1359
|
-
messageid: id,
|
|
1360
|
-
state: msg.actionstate,
|
|
1361
|
-
type: "ERROR",
|
|
1362
|
-
role: "ASSISTANT",
|
|
1363
|
-
errorText: msg.actionresult,
|
|
1364
|
-
status: "failed"
|
|
1365
|
-
});
|
|
1366
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1367
|
-
}
|
|
1368
|
-
},
|
|
1406
|
+
onMsg,
|
|
1369
1407
|
abortController,
|
|
1370
1408
|
ctx,
|
|
1371
1409
|
{ srfactag: param.srfactag },
|
|
1372
|
-
{ ...
|
|
1410
|
+
{ ...requestData }
|
|
1373
1411
|
);
|
|
1374
1412
|
} catch (error) {
|
|
1375
|
-
|
|
1413
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
1414
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
1415
|
+
if (errMsg === "network error" && asyncacitonid) {
|
|
1416
|
+
const resumed = await this.autoResumeChat(
|
|
1417
|
+
aiChat,
|
|
1418
|
+
ctx,
|
|
1419
|
+
param,
|
|
1420
|
+
deService,
|
|
1421
|
+
state,
|
|
1422
|
+
{ asyncacitonid, sessionid, srfaiagent, srfproject },
|
|
1423
|
+
onMsg
|
|
1424
|
+
);
|
|
1425
|
+
if (resumed)
|
|
1426
|
+
return true;
|
|
1427
|
+
}
|
|
1428
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
1376
1429
|
aiChat.replaceMessage({
|
|
1377
1430
|
messageid: id,
|
|
1378
1431
|
state: 40,
|
|
@@ -1386,7 +1439,8 @@ class AIChatUtil {
|
|
|
1386
1439
|
aiChat.replaceMessage(
|
|
1387
1440
|
{
|
|
1388
1441
|
...lastMessage,
|
|
1389
|
-
state: 40
|
|
1442
|
+
state: 40,
|
|
1443
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
1390
1444
|
},
|
|
1391
1445
|
false
|
|
1392
1446
|
);
|
|
@@ -1439,77 +1493,33 @@ class AIChatUtil {
|
|
|
1439
1493
|
state.abortController = new AbortController();
|
|
1440
1494
|
const { id, abortController } = state;
|
|
1441
1495
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1442
|
-
const
|
|
1496
|
+
const requestData = { asyncacitonid: other.asyncacitonid };
|
|
1443
1497
|
if (other.sessionid) {
|
|
1444
|
-
Object.assign(
|
|
1498
|
+
Object.assign(requestData, {
|
|
1445
1499
|
sessionid: other.sessionid
|
|
1446
1500
|
});
|
|
1447
1501
|
}
|
|
1448
1502
|
if (other.srfaiagent) {
|
|
1449
|
-
Object.assign(
|
|
1503
|
+
Object.assign(requestData, {
|
|
1450
1504
|
srfaiagent: other.srfaiagent
|
|
1451
1505
|
});
|
|
1452
1506
|
}
|
|
1453
1507
|
if (other.srfproject)
|
|
1454
|
-
Object.assign(
|
|
1508
|
+
Object.assign(requestData, {
|
|
1455
1509
|
srfproject: other.srfproject
|
|
1456
1510
|
});
|
|
1511
|
+
const onMsg = this.createChatSseHandler(aiChat, id, "");
|
|
1457
1512
|
try {
|
|
1458
1513
|
await deService.aiResumeSse(
|
|
1459
|
-
|
|
1460
|
-
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1461
|
-
aiChat.isLoading.value = true;
|
|
1462
|
-
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1463
|
-
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1464
|
-
}
|
|
1465
|
-
aiChat.addMessage({
|
|
1466
|
-
messageid: id,
|
|
1467
|
-
state: msg.actionstate,
|
|
1468
|
-
type: "DEFAULT",
|
|
1469
|
-
role: "ASSISTANT",
|
|
1470
|
-
content: msg.actionresult,
|
|
1471
|
-
status: "pending"
|
|
1472
|
-
});
|
|
1473
|
-
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1474
|
-
const result = JSON.parse(msg.actionresult);
|
|
1475
|
-
if (result.usage) {
|
|
1476
|
-
aiChat.updateMsgUsage(id, result.usage);
|
|
1477
|
-
}
|
|
1478
|
-
if (result.files) {
|
|
1479
|
-
aiChat.updateMsgOutputFiles(id, result.files);
|
|
1480
|
-
}
|
|
1481
|
-
const choices = result.choices;
|
|
1482
|
-
if (choices && choices.length > 0) {
|
|
1483
|
-
aiChat.replaceMessage({
|
|
1484
|
-
messageid: id,
|
|
1485
|
-
state: msg.actionstate,
|
|
1486
|
-
type: "DEFAULT",
|
|
1487
|
-
role: "ASSISTANT",
|
|
1488
|
-
content: choices[0].content || "",
|
|
1489
|
-
realmessageid: choices[0].messageid,
|
|
1490
|
-
status: "sent"
|
|
1491
|
-
});
|
|
1492
|
-
}
|
|
1493
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1494
|
-
} else if (msg.actionstate === 40) {
|
|
1495
|
-
aiChat.replaceMessage({
|
|
1496
|
-
messageid: id,
|
|
1497
|
-
state: msg.actionstate,
|
|
1498
|
-
type: "ERROR",
|
|
1499
|
-
role: "ASSISTANT",
|
|
1500
|
-
errorText: msg.actionresult,
|
|
1501
|
-
status: "failed"
|
|
1502
|
-
});
|
|
1503
|
-
aiChat.setActiveAsyncacitonId("");
|
|
1504
|
-
}
|
|
1505
|
-
},
|
|
1514
|
+
onMsg,
|
|
1506
1515
|
abortController,
|
|
1507
1516
|
ctx,
|
|
1508
1517
|
{ srfactag: param.srfactag },
|
|
1509
|
-
{ ...
|
|
1518
|
+
{ ...requestData }
|
|
1510
1519
|
);
|
|
1511
1520
|
} catch (error) {
|
|
1512
|
-
|
|
1521
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
1522
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
1513
1523
|
if (error && error.message !== this.PRE_ERROR_MESSAGE) {
|
|
1514
1524
|
aiChat.replaceMessage({
|
|
1515
1525
|
messageid: id,
|
|
@@ -1524,7 +1534,8 @@ class AIChatUtil {
|
|
|
1524
1534
|
aiChat.replaceMessage(
|
|
1525
1535
|
{
|
|
1526
1536
|
...lastMessage,
|
|
1527
|
-
state: 40
|
|
1537
|
+
state: 40,
|
|
1538
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
1528
1539
|
},
|
|
1529
1540
|
false
|
|
1530
1541
|
);
|
|
@@ -2225,6 +2236,77 @@ class AIChatUtil {
|
|
|
2225
2236
|
};
|
|
2226
2237
|
return fileSystemOptions;
|
|
2227
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
|
+
}
|
|
2228
2310
|
}
|
|
2229
2311
|
|
|
2230
2312
|
export { AIChatUtil };
|