@ibiz-template/vue3-components 0.7.41-alpha.165 → 0.7.41-alpha.166
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-CCoBeNIV.js} +6 -6
- package/dist/{index.es-CA0rGKdK.js → index.es-D1vng-7i.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-B0ZpE6o-.js} +1 -1
- package/dist/{xlsx-util-Bv9fDQB8.js → xlsx-util-Djaaq9Po.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/util/ai-chat-util/ai-chat-util.mjs +217 -240
- 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/util/ai-chat-util/ai-chat-util.cjs +217 -240
- 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/util/ai-chat-util/ai-chat-util.ts +256 -276
|
@@ -21,6 +21,133 @@ class AIChatUtil {
|
|
|
21
21
|
__publicField(this, "PRE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: application/json;charset=UTF-8");
|
|
22
22
|
// 无流内容回来
|
|
23
23
|
__publicField(this, "NONE_ERROR_MESSAGE", "Expected content-type to be text/event-stream, Actual: null");
|
|
24
|
+
// 网络中断自动续传的最大重试次数
|
|
25
|
+
__publicField(this, "AUTO_RESUME_MAX_RETRY", 3);
|
|
26
|
+
// 网络中断自动续传的退避基数(毫秒),按 1s/2s/4s 指数退避
|
|
27
|
+
__publicField(this, "AUTO_RESUME_BACKOFF_BASE", 1e3);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @description 创建 AI 聊天 SSE 流式消息处理回调(提问与恢复会话共用)
|
|
31
|
+
* @param {any} aiChat 单实例聊天总控
|
|
32
|
+
* @param {string} id 本次问答的流式消息 id
|
|
33
|
+
* @param {string} localMsgID 本地用户消息 id(用于回填真实消息 id;为空串时为恢复会话场景,状态 20 走 isLoading 加载分支)
|
|
34
|
+
* @return {*} {(msg: IPortalAsyncAction) => void}
|
|
35
|
+
* @memberof AIChatUtil
|
|
36
|
+
*/
|
|
37
|
+
createChatSseHandler(aiChat, id, localMsgID) {
|
|
38
|
+
let updateFlag = true;
|
|
39
|
+
return (msg) => {
|
|
40
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
41
|
+
if (localMsgID) {
|
|
42
|
+
aiChat.removeWaitingMessage(id);
|
|
43
|
+
if (msg.asextparam && updateFlag) {
|
|
44
|
+
aiChat.updateMsgRealMessageID(localMsgID, msg.asextparam);
|
|
45
|
+
updateFlag = false;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
aiChat.isLoading.value = true;
|
|
49
|
+
}
|
|
50
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
51
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
52
|
+
}
|
|
53
|
+
aiChat.addMessage({
|
|
54
|
+
messageid: id,
|
|
55
|
+
state: msg.actionstate,
|
|
56
|
+
type: "DEFAULT",
|
|
57
|
+
role: "ASSISTANT",
|
|
58
|
+
content: msg.actionresult,
|
|
59
|
+
status: "pending"
|
|
60
|
+
});
|
|
61
|
+
} else if (msg.actionstate === 30 && msg.actionresult) {
|
|
62
|
+
const result = JSON.parse(msg.actionresult);
|
|
63
|
+
if (result.usage) {
|
|
64
|
+
aiChat.updateMsgUsage(id, result.usage);
|
|
65
|
+
}
|
|
66
|
+
if (result.files) {
|
|
67
|
+
aiChat.updateMsgOutputFiles(id, result.files);
|
|
68
|
+
}
|
|
69
|
+
const choices = result.choices;
|
|
70
|
+
if (choices && choices.length > 0) {
|
|
71
|
+
aiChat.replaceMessage({
|
|
72
|
+
messageid: id,
|
|
73
|
+
state: msg.actionstate,
|
|
74
|
+
type: "DEFAULT",
|
|
75
|
+
role: "ASSISTANT",
|
|
76
|
+
content: choices[0].content || "",
|
|
77
|
+
realmessageid: choices[0].messageid,
|
|
78
|
+
status: "sent"
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
aiChat.setActiveAsyncacitonId("");
|
|
82
|
+
} else if (msg.actionstate === 40) {
|
|
83
|
+
aiChat.replaceMessage({
|
|
84
|
+
messageid: id,
|
|
85
|
+
state: msg.actionstate,
|
|
86
|
+
type: "ERROR",
|
|
87
|
+
role: "ASSISTANT",
|
|
88
|
+
errorText: msg.actionresult,
|
|
89
|
+
status: "failed"
|
|
90
|
+
});
|
|
91
|
+
aiChat.setActiveAsyncacitonId("");
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @description 网络中断(network error)后按 asyncacitonid 自动续传,指数退避重试;成功返回 true,不可恢复/重试耗尽返回 false 交回调用方走既有错误处理
|
|
97
|
+
* @param {any} aiChat 单实例聊天总控
|
|
98
|
+
* @param {IContext} ctx 上下文
|
|
99
|
+
* @param {IParams} param 视图参数
|
|
100
|
+
* @param {*} deService 实体服务
|
|
101
|
+
* @param {{ id: string; abortController: AbortController }} state 聊天实例提问状态(WeakMap 持有的同一对象引用)
|
|
102
|
+
* @param {{ asyncacitonid: string; sessionid?: string; srfaiagent?: string; srfproject?: string }} resumeInfo 续传参数
|
|
103
|
+
* @param {(msg: IPortalAsyncAction) => void} onMsg SSE 流式消息处理回调
|
|
104
|
+
* @return {*} {Promise<boolean>} 是否续传成功
|
|
105
|
+
* @memberof AIChatUtil
|
|
106
|
+
*/
|
|
107
|
+
async autoResumeChat(aiChat, ctx, param, deService, state, resumeInfo, onMsg) {
|
|
108
|
+
var _a;
|
|
109
|
+
(_a = state.abortController) == null ? void 0 : _a.abort();
|
|
110
|
+
state.abortController = new AbortController();
|
|
111
|
+
for (let attempt = 1; attempt <= this.AUTO_RESUME_MAX_RETRY; attempt++) {
|
|
112
|
+
try {
|
|
113
|
+
await new Promise((resolve) => {
|
|
114
|
+
setTimeout(
|
|
115
|
+
resolve,
|
|
116
|
+
this.AUTO_RESUME_BACKOFF_BASE * 2 ** (attempt - 1)
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
const resumeRequestData = {
|
|
120
|
+
asyncacitonid: resumeInfo.asyncacitonid
|
|
121
|
+
};
|
|
122
|
+
if (resumeInfo.sessionid) {
|
|
123
|
+
resumeRequestData.sessionid = resumeInfo.sessionid;
|
|
124
|
+
}
|
|
125
|
+
if (resumeInfo.srfaiagent) {
|
|
126
|
+
resumeRequestData.srfaiagent = resumeInfo.srfaiagent;
|
|
127
|
+
}
|
|
128
|
+
if (resumeInfo.srfproject) {
|
|
129
|
+
resumeRequestData.srfproject = resumeInfo.srfproject;
|
|
130
|
+
}
|
|
131
|
+
await deService.aiResumeSse(
|
|
132
|
+
onMsg,
|
|
133
|
+
state.abortController,
|
|
134
|
+
ctx,
|
|
135
|
+
{ srfactag: param.srfactag },
|
|
136
|
+
{ ...resumeRequestData }
|
|
137
|
+
);
|
|
138
|
+
return true;
|
|
139
|
+
} catch (resumeError) {
|
|
140
|
+
const resumeMsg = (resumeError == null ? void 0 : resumeError.message) || "";
|
|
141
|
+
if ((resumeError == null ? void 0 : resumeError.name) === "AbortError") {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (resumeMsg === this.NONE_ERROR_MESSAGE) {
|
|
145
|
+
aiChat.setActiveAsyncacitonId("");
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
24
151
|
}
|
|
25
152
|
/**
|
|
26
153
|
* 获取AI聊天对象
|
|
@@ -205,7 +332,8 @@ class AIChatUtil {
|
|
|
205
332
|
const chatOptions = {
|
|
206
333
|
locale: ibiz.i18n.getLang(),
|
|
207
334
|
enableAIProject: editorParams.srfenableaiprojectselect ? editorParams.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
|
|
208
|
-
projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
|
|
335
|
+
projectSelectPlaceholder: editorParams.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
|
|
336
|
+
selectAIProjectId: editorParams.srfselectaiprojectid
|
|
209
337
|
};
|
|
210
338
|
if (editorParams.srfaiappendcurdata) {
|
|
211
339
|
chatOptions.appendCurData = editorParams.srfaiappendcurdata === "true" ? data : void 0;
|
|
@@ -416,37 +544,37 @@ class AIChatUtil {
|
|
|
416
544
|
return true;
|
|
417
545
|
};
|
|
418
546
|
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid2, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
|
|
419
|
-
let updateFlag = true;
|
|
420
547
|
const state = getChatState(aiChat);
|
|
421
548
|
state.id = createUUID();
|
|
422
549
|
state.abortController = new AbortController();
|
|
423
550
|
const { id, abortController } = state;
|
|
424
551
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
552
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
425
553
|
try {
|
|
426
|
-
const
|
|
554
|
+
const requestData = {
|
|
427
555
|
messages: arr,
|
|
428
556
|
sessionid: sessionid2
|
|
429
557
|
};
|
|
430
558
|
if (srfaiagent)
|
|
431
|
-
|
|
559
|
+
requestData.srfaiagent = srfaiagent;
|
|
432
560
|
if (srfmode)
|
|
433
|
-
|
|
561
|
+
requestData.mode = srfmode;
|
|
434
562
|
if (srfscope)
|
|
435
|
-
|
|
563
|
+
requestData.srfscope = srfscope;
|
|
436
564
|
if (srfproject)
|
|
437
|
-
|
|
565
|
+
requestData.srfproject = srfproject;
|
|
438
566
|
if (srfknowledgebases)
|
|
439
|
-
|
|
567
|
+
requestData.knowledgebases = srfknowledgebases;
|
|
440
568
|
if (srfaiagentconfig) {
|
|
441
|
-
Object.assign(
|
|
569
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
442
570
|
}
|
|
443
571
|
if (mcpservers) {
|
|
444
|
-
Object.assign(
|
|
572
|
+
Object.assign(requestData, {
|
|
445
573
|
mcpservers
|
|
446
574
|
});
|
|
447
575
|
}
|
|
448
576
|
if (sessionmeta) {
|
|
449
|
-
Object.assign(
|
|
577
|
+
Object.assign(requestData, {
|
|
450
578
|
srfuimeta: JSON.stringify(sessionmeta)
|
|
451
579
|
});
|
|
452
580
|
}
|
|
@@ -458,68 +586,33 @@ class AIChatUtil {
|
|
|
458
586
|
Object.assign(extParams, { ...appendcurdata });
|
|
459
587
|
}
|
|
460
588
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
461
|
-
Object.assign(
|
|
589
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
462
590
|
}
|
|
463
591
|
aiChat.addWaitingMessage(id);
|
|
464
592
|
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
|
-
},
|
|
593
|
+
onMsg,
|
|
516
594
|
abortController,
|
|
517
595
|
ctx,
|
|
518
596
|
{ srfactag: param.srfactag },
|
|
519
|
-
{ ...
|
|
597
|
+
{ ...requestData }
|
|
520
598
|
);
|
|
521
599
|
} catch (error) {
|
|
522
|
-
|
|
600
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
601
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
602
|
+
if (errMsg === "network error" && asyncacitonid) {
|
|
603
|
+
const resumed = await this.autoResumeChat(
|
|
604
|
+
aiChat,
|
|
605
|
+
ctx,
|
|
606
|
+
param,
|
|
607
|
+
deService,
|
|
608
|
+
state,
|
|
609
|
+
{ asyncacitonid, sessionid: sessionid2, srfaiagent, srfproject },
|
|
610
|
+
onMsg
|
|
611
|
+
);
|
|
612
|
+
if (resumed)
|
|
613
|
+
return true;
|
|
614
|
+
}
|
|
615
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
523
616
|
aiChat.replaceMessage({
|
|
524
617
|
messageid: id,
|
|
525
618
|
state: 40,
|
|
@@ -533,7 +626,8 @@ class AIChatUtil {
|
|
|
533
626
|
aiChat.replaceMessage(
|
|
534
627
|
{
|
|
535
628
|
...lastMessage,
|
|
536
|
-
state: 40
|
|
629
|
+
state: 40,
|
|
630
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
537
631
|
},
|
|
538
632
|
false
|
|
539
633
|
);
|
|
@@ -586,77 +680,33 @@ class AIChatUtil {
|
|
|
586
680
|
state.abortController = new AbortController();
|
|
587
681
|
const { id, abortController } = state;
|
|
588
682
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
589
|
-
const
|
|
683
|
+
const requestData = { asyncacitonid: other.asyncacitonid };
|
|
590
684
|
if (other.sessionid) {
|
|
591
|
-
Object.assign(
|
|
685
|
+
Object.assign(requestData, {
|
|
592
686
|
sessionid: other.sessionid
|
|
593
687
|
});
|
|
594
688
|
}
|
|
595
689
|
if (other.srfaiagent) {
|
|
596
|
-
Object.assign(
|
|
690
|
+
Object.assign(requestData, {
|
|
597
691
|
srfaiagent: other.srfaiagent
|
|
598
692
|
});
|
|
599
693
|
}
|
|
600
694
|
if (other.srfproject)
|
|
601
|
-
Object.assign(
|
|
695
|
+
Object.assign(requestData, {
|
|
602
696
|
srfproject: other.srfproject
|
|
603
697
|
});
|
|
698
|
+
const onMsg = this.createChatSseHandler(aiChat, id, "");
|
|
604
699
|
try {
|
|
605
700
|
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
|
-
},
|
|
701
|
+
onMsg,
|
|
653
702
|
abortController,
|
|
654
703
|
ctx,
|
|
655
704
|
{ srfactag: param.srfactag },
|
|
656
|
-
{ ...
|
|
705
|
+
{ ...requestData }
|
|
657
706
|
);
|
|
658
707
|
} catch (error) {
|
|
659
|
-
|
|
708
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
709
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
660
710
|
if (error && error.message !== this.PRE_ERROR_MESSAGE) {
|
|
661
711
|
aiChat.replaceMessage({
|
|
662
712
|
messageid: id,
|
|
@@ -671,7 +721,8 @@ class AIChatUtil {
|
|
|
671
721
|
aiChat.replaceMessage(
|
|
672
722
|
{
|
|
673
723
|
...lastMessage,
|
|
674
|
-
state: 40
|
|
724
|
+
state: 40,
|
|
725
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
675
726
|
},
|
|
676
727
|
false
|
|
677
728
|
);
|
|
@@ -1029,8 +1080,11 @@ class AIChatUtil {
|
|
|
1029
1080
|
const chatOptions = {
|
|
1030
1081
|
locale: ibiz.i18n.getLang(),
|
|
1031
1082
|
enableAIProject: params.srfenableaiprojectselect ? params.srfenableaiprojectselect === "true" : ibiz.config.common.enableAIProjectSelect,
|
|
1032
|
-
projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder
|
|
1083
|
+
projectSelectPlaceholder: params.srfprojectselectplaceholder || ibiz.config.common.aiProjectSelectPlaceholder,
|
|
1084
|
+
selectAIProjectId: params.srfselectaiprojectid
|
|
1033
1085
|
};
|
|
1086
|
+
if (params.hasOwnProperty("srfselectaiprojectid"))
|
|
1087
|
+
delete params.srfselectaiprojectid;
|
|
1034
1088
|
if (params.hasOwnProperty("srfenableaiprojectselect"))
|
|
1035
1089
|
delete params.srfenableaiprojectselect;
|
|
1036
1090
|
if (params.hasOwnProperty("srfprojectselectplaceholder"))
|
|
@@ -1271,35 +1325,35 @@ class AIChatUtil {
|
|
|
1271
1325
|
return true;
|
|
1272
1326
|
};
|
|
1273
1327
|
chatOptions.question = async (aiChat, ctx, param, other, arr, sessionid, srfaiagent, srfmode, srfscope, srfknowledgebases, srfaiagentconfig, appendcurdata, mcpservers, sessionmeta, srfproject, localMsgID) => {
|
|
1274
|
-
let updateFlag = true;
|
|
1275
1328
|
const state = getChatState(aiChat);
|
|
1276
1329
|
state.id = createUUID();
|
|
1277
1330
|
state.abortController = new AbortController();
|
|
1278
1331
|
const { id, abortController } = state;
|
|
1279
1332
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1333
|
+
const onMsg = this.createChatSseHandler(aiChat, id, localMsgID);
|
|
1280
1334
|
try {
|
|
1281
|
-
const
|
|
1335
|
+
const requestData = {
|
|
1282
1336
|
messages: arr,
|
|
1283
1337
|
sessionid
|
|
1284
1338
|
};
|
|
1285
1339
|
if (srfaiagent)
|
|
1286
|
-
|
|
1340
|
+
requestData.srfaiagent = srfaiagent;
|
|
1287
1341
|
if (srfmode)
|
|
1288
|
-
|
|
1342
|
+
requestData.mode = srfmode;
|
|
1289
1343
|
if (srfscope)
|
|
1290
|
-
|
|
1344
|
+
requestData.srfscope = srfscope;
|
|
1291
1345
|
if (srfproject)
|
|
1292
|
-
|
|
1346
|
+
requestData.srfproject = srfproject;
|
|
1293
1347
|
if (srfknowledgebases)
|
|
1294
|
-
|
|
1348
|
+
requestData.knowledgebases = srfknowledgebases;
|
|
1295
1349
|
if (srfaiagentconfig) {
|
|
1296
|
-
Object.assign(
|
|
1350
|
+
Object.assign(requestData, srfaiagentconfig);
|
|
1297
1351
|
}
|
|
1298
1352
|
if (mcpservers) {
|
|
1299
|
-
Object.assign(
|
|
1353
|
+
Object.assign(requestData, { mcpservers });
|
|
1300
1354
|
}
|
|
1301
1355
|
if (sessionmeta) {
|
|
1302
|
-
Object.assign(
|
|
1356
|
+
Object.assign(requestData, {
|
|
1303
1357
|
srfuimeta: JSON.stringify(sessionmeta)
|
|
1304
1358
|
});
|
|
1305
1359
|
}
|
|
@@ -1311,68 +1365,33 @@ class AIChatUtil {
|
|
|
1311
1365
|
Object.assign(extParams, { ...appendcurdata });
|
|
1312
1366
|
}
|
|
1313
1367
|
if (extParams && Object.keys(extParams).length > 0) {
|
|
1314
|
-
Object.assign(
|
|
1368
|
+
Object.assign(requestData, { srfextparams: extParams });
|
|
1315
1369
|
}
|
|
1316
1370
|
aiChat.addWaitingMessage(id);
|
|
1317
1371
|
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
|
-
},
|
|
1372
|
+
onMsg,
|
|
1369
1373
|
abortController,
|
|
1370
1374
|
ctx,
|
|
1371
1375
|
{ srfactag: param.srfactag },
|
|
1372
|
-
{ ...
|
|
1376
|
+
{ ...requestData }
|
|
1373
1377
|
);
|
|
1374
1378
|
} catch (error) {
|
|
1375
|
-
|
|
1379
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
1380
|
+
const asyncacitonid = aiChat.getActiveAsyncacitonId();
|
|
1381
|
+
if (errMsg === "network error" && asyncacitonid) {
|
|
1382
|
+
const resumed = await this.autoResumeChat(
|
|
1383
|
+
aiChat,
|
|
1384
|
+
ctx,
|
|
1385
|
+
param,
|
|
1386
|
+
deService,
|
|
1387
|
+
state,
|
|
1388
|
+
{ asyncacitonid, sessionid, srfaiagent, srfproject },
|
|
1389
|
+
onMsg
|
|
1390
|
+
);
|
|
1391
|
+
if (resumed)
|
|
1392
|
+
return true;
|
|
1393
|
+
}
|
|
1394
|
+
if (error && errMsg !== this.PRE_ERROR_MESSAGE) {
|
|
1376
1395
|
aiChat.replaceMessage({
|
|
1377
1396
|
messageid: id,
|
|
1378
1397
|
state: 40,
|
|
@@ -1386,7 +1405,8 @@ class AIChatUtil {
|
|
|
1386
1405
|
aiChat.replaceMessage(
|
|
1387
1406
|
{
|
|
1388
1407
|
...lastMessage,
|
|
1389
|
-
state: 40
|
|
1408
|
+
state: 40,
|
|
1409
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
1390
1410
|
},
|
|
1391
1411
|
false
|
|
1392
1412
|
);
|
|
@@ -1439,77 +1459,33 @@ class AIChatUtil {
|
|
|
1439
1459
|
state.abortController = new AbortController();
|
|
1440
1460
|
const { id, abortController } = state;
|
|
1441
1461
|
const deService = await ibiz.hub.getApp(ctx.srfappid).deService.getService(ctx, other.appDataEntityId);
|
|
1442
|
-
const
|
|
1462
|
+
const requestData = { asyncacitonid: other.asyncacitonid };
|
|
1443
1463
|
if (other.sessionid) {
|
|
1444
|
-
Object.assign(
|
|
1464
|
+
Object.assign(requestData, {
|
|
1445
1465
|
sessionid: other.sessionid
|
|
1446
1466
|
});
|
|
1447
1467
|
}
|
|
1448
1468
|
if (other.srfaiagent) {
|
|
1449
|
-
Object.assign(
|
|
1469
|
+
Object.assign(requestData, {
|
|
1450
1470
|
srfaiagent: other.srfaiagent
|
|
1451
1471
|
});
|
|
1452
1472
|
}
|
|
1453
1473
|
if (other.srfproject)
|
|
1454
|
-
Object.assign(
|
|
1474
|
+
Object.assign(requestData, {
|
|
1455
1475
|
srfproject: other.srfproject
|
|
1456
1476
|
});
|
|
1477
|
+
const onMsg = this.createChatSseHandler(aiChat, id, "");
|
|
1457
1478
|
try {
|
|
1458
1479
|
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
|
-
},
|
|
1480
|
+
onMsg,
|
|
1506
1481
|
abortController,
|
|
1507
1482
|
ctx,
|
|
1508
1483
|
{ srfactag: param.srfactag },
|
|
1509
|
-
{ ...
|
|
1484
|
+
{ ...requestData }
|
|
1510
1485
|
);
|
|
1511
1486
|
} catch (error) {
|
|
1512
|
-
|
|
1487
|
+
const errMsg = (error == null ? void 0 : error.message) || "";
|
|
1488
|
+
if (error && errMsg !== this.NONE_ERROR_MESSAGE) {
|
|
1513
1489
|
if (error && error.message !== this.PRE_ERROR_MESSAGE) {
|
|
1514
1490
|
aiChat.replaceMessage({
|
|
1515
1491
|
messageid: id,
|
|
@@ -1524,7 +1500,8 @@ class AIChatUtil {
|
|
|
1524
1500
|
aiChat.replaceMessage(
|
|
1525
1501
|
{
|
|
1526
1502
|
...lastMessage,
|
|
1527
|
-
state: 40
|
|
1503
|
+
state: 40,
|
|
1504
|
+
errorText: ibiz.i18n.t("app.aiError")
|
|
1528
1505
|
},
|
|
1529
1506
|
false
|
|
1530
1507
|
);
|
package/lib/editor/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ require('./date-range-select/index.cjs');
|
|
|
36
36
|
require('./map-picker/index.cjs');
|
|
37
37
|
require('./ai-chat/index.cjs');
|
|
38
38
|
require('./html-preview/index.cjs');
|
|
39
|
+
require('./work-space/index.cjs');
|
|
39
40
|
var ibizImageCropping = require('./upload/ibiz-image-cropping/ibiz-image-cropping.cjs');
|
|
40
41
|
var span = require('./span/span/span.cjs');
|
|
41
42
|
var spanLink = require('./span/span-link/span-link.cjs');
|
|
@@ -80,6 +81,7 @@ var ibizSearchcondEdit = require('./user/ibiz-searchcond-edit/ibiz-searchcond-ed
|
|
|
80
81
|
var ibizCarousel = require('./carousel/ibiz-carousel/ibiz-carousel.cjs');
|
|
81
82
|
var ibizMapPicker = require('./map-picker/ibiz-map-picker/ibiz-map-picker.cjs');
|
|
82
83
|
var embedAiChat = require('./ai-chat/embed-ai-chat/embed-ai-chat.cjs');
|
|
84
|
+
var embedWorkSpace = require('./work-space/embed-work-space/embed-work-space.cjs');
|
|
83
85
|
var ibizHtmlPreview = require('./html-preview/ibiz-html-preview/ibiz-html-preview.cjs');
|
|
84
86
|
var dateRangeSelect = require('./date-range-select/date-range-select-picker/date-range-select.cjs');
|
|
85
87
|
var ibizVirtualizedList = require('./dropdown-list/ibiz-virtualized-list/ibiz-virtualized-list.cjs');
|
|
@@ -112,6 +114,7 @@ var colorPickerEditor_provider = require('./color-picker/color-picker-editor.pro
|
|
|
112
114
|
var ibizSearchcondEdit_provider = require('./user/ibiz-searchcond-edit/ibiz-searchcond-edit.provider.cjs');
|
|
113
115
|
var mapPickerEditor_provider = require('./map-picker/map-picker-editor.provider.cjs');
|
|
114
116
|
var embedAiChatEditor_provider = require('./ai-chat/embed-ai-chat-editor.provider.cjs');
|
|
117
|
+
var embedWorkSpace_provider = require('./work-space/embed-work-space.provider.cjs');
|
|
115
118
|
var carouselEditor_provider = require('./carousel/carousel-editor.provider.cjs');
|
|
116
119
|
|
|
117
120
|
"use strict";
|
|
@@ -162,6 +165,7 @@ const IBizEditor = {
|
|
|
162
165
|
v.component(ibizCarousel.IBizCarousel.name, ibizCarousel.IBizCarousel);
|
|
163
166
|
v.component(ibizMapPicker.IBizMapPicker.name, ibizMapPicker.IBizMapPicker);
|
|
164
167
|
v.component(embedAiChat.IBizEmbedAIChat.name, embedAiChat.IBizEmbedAIChat);
|
|
168
|
+
v.component(embedWorkSpace.IBizEmbedWorkSpace.name, embedWorkSpace.IBizEmbedWorkSpace);
|
|
165
169
|
v.component(
|
|
166
170
|
"IBizHtml",
|
|
167
171
|
vue.defineAsyncComponent(() => Promise.resolve().then(function () { return require('./html/wang-editor/wang-editor.cjs'); }))
|
|
@@ -459,6 +463,10 @@ const IBizEditor = {
|
|
|
459
463
|
"TEXTAREA_EMBED_AI_CHAT",
|
|
460
464
|
() => new embedAiChatEditor_provider.EmbedAIChatEditorProvider()
|
|
461
465
|
);
|
|
466
|
+
runtime.registerEditorProvider(
|
|
467
|
+
"TEXTAREA_EMBED_WORK_SPACE",
|
|
468
|
+
() => new embedWorkSpace_provider.EmbedWorkSpaceProvider()
|
|
469
|
+
);
|
|
462
470
|
runtime.registerEditorProvider(
|
|
463
471
|
"FIELD_IMAGE_PICTURE_ONE",
|
|
464
472
|
() => new uploadEditor_provider.FileUploaderEditorProvider("PICTURE_ONE")
|