@ibiz-template/vue3-components 0.7.41-alpha.149 → 0.7.41-alpha.150
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-BRBBeU_2.js → index-Dki2yYe9.js} +26 -26
- package/dist/{index.es-BezvNJVH.js → index.es-7UWnjdb2.js} +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/{wang-editor-9d2x6WBQ.js → wang-editor-DRcvMIVh.js} +1 -1
- package/dist/{xlsx-util-Dr9uwITS.js → xlsx-util-CkixgGjt.js} +1 -1
- package/es/util/ai-chat-util/ai-chat-util.mjs +210 -2
- package/lib/util/ai-chat-util/ai-chat-util.cjs +210 -2
- package/package.json +5 -5
- package/src/util/ai-chat-util/ai-chat-util.ts +258 -2
|
@@ -50,6 +50,10 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
50
50
|
private PRE_ERROR_MESSAGE: string =
|
|
51
51
|
'Expected content-type to be text/event-stream, Actual: application/json;charset=UTF-8';
|
|
52
52
|
|
|
53
|
+
// 无流内容回来
|
|
54
|
+
private NONE_ERROR_MESSAGE: string =
|
|
55
|
+
'Expected content-type to be text/event-stream, Actual: null';
|
|
56
|
+
|
|
53
57
|
/**
|
|
54
58
|
* 获取AI聊天对象
|
|
55
59
|
*/
|
|
@@ -524,7 +528,10 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
524
528
|
(msg: IPortalAsyncAction) => {
|
|
525
529
|
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
526
530
|
if (msg.actionstate === 20 && msg.actionresult) {
|
|
527
|
-
|
|
531
|
+
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
532
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
533
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
534
|
+
}
|
|
528
535
|
aiChat.addMessage({
|
|
529
536
|
messageid: id,
|
|
530
537
|
state: msg.actionstate,
|
|
@@ -594,6 +601,8 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
594
601
|
} finally {
|
|
595
602
|
// 标记当前消息已经交互完成
|
|
596
603
|
aiChat.completeMessage(id, true);
|
|
604
|
+
// 清空异步消息任务
|
|
605
|
+
aiChat.setActiveAsyncacitonId('');
|
|
597
606
|
return true;
|
|
598
607
|
}
|
|
599
608
|
};
|
|
@@ -639,6 +648,127 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
639
648
|
// 标记当前消息已经交互完成
|
|
640
649
|
await aiChat.completeMessage(id, true);
|
|
641
650
|
};
|
|
651
|
+
// 恢复会话
|
|
652
|
+
chatOptions.resumeQuestion = async (
|
|
653
|
+
aiChat: any,
|
|
654
|
+
ctx: IContext,
|
|
655
|
+
param: IParams,
|
|
656
|
+
other: IParams,
|
|
657
|
+
arr: IChatMessage[],
|
|
658
|
+
) => {
|
|
659
|
+
if (other.asyncacitonid) {
|
|
660
|
+
id = createUUID();
|
|
661
|
+
abortController = new AbortController();
|
|
662
|
+
const deService = await ibiz.hub
|
|
663
|
+
.getApp(ctx.srfappid)
|
|
664
|
+
.deService.getService(ctx, other.appDataEntityId);
|
|
665
|
+
const resumeRequestData: IData = { asyncacitonid: other.asyncacitonid };
|
|
666
|
+
if (other.sessionid) {
|
|
667
|
+
Object.assign(resumeRequestData, {
|
|
668
|
+
sessionid: other.sessionid,
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
if (other.srfaiagent) {
|
|
672
|
+
Object.assign(resumeRequestData, {
|
|
673
|
+
srfaiagent: other.srfaiagent,
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
if (other.srfproject)
|
|
677
|
+
Object.assign(resumeRequestData, {
|
|
678
|
+
srfproject: other.srfproject,
|
|
679
|
+
});
|
|
680
|
+
try {
|
|
681
|
+
await deService.aiResumeSse(
|
|
682
|
+
(msg: IPortalAsyncAction) => {
|
|
683
|
+
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
684
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
685
|
+
// 设置当前聊天在加载中
|
|
686
|
+
aiChat.isLoading.value = true;
|
|
687
|
+
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
688
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
689
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
690
|
+
}
|
|
691
|
+
aiChat.addMessage({
|
|
692
|
+
messageid: id,
|
|
693
|
+
state: msg.actionstate,
|
|
694
|
+
type: 'DEFAULT',
|
|
695
|
+
role: 'ASSISTANT',
|
|
696
|
+
content: msg.actionresult as string,
|
|
697
|
+
status: 'pending',
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
701
|
+
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
702
|
+
const result = JSON.parse(msg.actionresult as string);
|
|
703
|
+
if (result.usage) {
|
|
704
|
+
aiChat.updateMsgUsage(id, result.usage);
|
|
705
|
+
}
|
|
706
|
+
const choices = result.choices;
|
|
707
|
+
if (choices && choices.length > 0) {
|
|
708
|
+
aiChat.replaceMessage({
|
|
709
|
+
messageid: id,
|
|
710
|
+
state: msg.actionstate,
|
|
711
|
+
type: 'DEFAULT',
|
|
712
|
+
role: 'ASSISTANT',
|
|
713
|
+
content: choices[0].content || '',
|
|
714
|
+
realmessageid: choices[0].messageid,
|
|
715
|
+
status: 'sent',
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
// 40: 回答报错,展示错误信息
|
|
720
|
+
else if (msg.actionstate === 40) {
|
|
721
|
+
aiChat.replaceMessage({
|
|
722
|
+
messageid: id,
|
|
723
|
+
state: msg.actionstate,
|
|
724
|
+
type: 'ERROR',
|
|
725
|
+
role: 'ASSISTANT',
|
|
726
|
+
errorText: msg.actionresult as string,
|
|
727
|
+
status: 'failed',
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
abortController,
|
|
732
|
+
ctx,
|
|
733
|
+
{ srfactag: param.srfactag },
|
|
734
|
+
{ ...resumeRequestData },
|
|
735
|
+
);
|
|
736
|
+
} catch (error) {
|
|
737
|
+
// 等于NONE_ERROR_MESSAGE,代码该异步行为已经完成,不需要做处理
|
|
738
|
+
if (error && (error as Error).message !== this.NONE_ERROR_MESSAGE) {
|
|
739
|
+
if (error && (error as Error).message !== this.PRE_ERROR_MESSAGE) {
|
|
740
|
+
aiChat.replaceMessage({
|
|
741
|
+
messageid: id,
|
|
742
|
+
state: 40,
|
|
743
|
+
type: 'ERROR',
|
|
744
|
+
role: 'ASSISTANT',
|
|
745
|
+
errorText:
|
|
746
|
+
(error as IData).message || ibiz.i18n.t('app.aiError'),
|
|
747
|
+
status: 'failed',
|
|
748
|
+
});
|
|
749
|
+
} else {
|
|
750
|
+
const lastMessage = arr[arr.length - 1];
|
|
751
|
+
aiChat.replaceMessage(
|
|
752
|
+
{
|
|
753
|
+
...lastMessage,
|
|
754
|
+
state: 40,
|
|
755
|
+
},
|
|
756
|
+
false,
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
abortController?.abort();
|
|
761
|
+
} finally {
|
|
762
|
+
// 设置当前聊天加载状态已完成
|
|
763
|
+
aiChat.isLoading.value = false;
|
|
764
|
+
// 标记当前消息已经交互完成
|
|
765
|
+
aiChat.completeMessage(id, true);
|
|
766
|
+
// 清空异步消息任务
|
|
767
|
+
aiChat.setActiveAsyncacitonId('');
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
};
|
|
642
772
|
// 调整方向
|
|
643
773
|
chatOptions.supplementQuestion = async (
|
|
644
774
|
aiChat: any,
|
|
@@ -1401,7 +1531,10 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1401
1531
|
(msg: IPortalAsyncAction) => {
|
|
1402
1532
|
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
1403
1533
|
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1404
|
-
|
|
1534
|
+
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
1535
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1536
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1537
|
+
}
|
|
1405
1538
|
aiChat.addMessage({
|
|
1406
1539
|
messageid: id,
|
|
1407
1540
|
state: msg.actionstate,
|
|
@@ -1469,6 +1602,8 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1469
1602
|
}
|
|
1470
1603
|
abortController?.abort();
|
|
1471
1604
|
} finally {
|
|
1605
|
+
// 清空异步消息任务
|
|
1606
|
+
aiChat.setActiveAsyncacitonId('');
|
|
1472
1607
|
// 标记当前消息已经交互完成
|
|
1473
1608
|
aiChat.completeMessage(id, true);
|
|
1474
1609
|
return true;
|
|
@@ -1516,6 +1651,127 @@ export class AIChatUtil implements IApiAIChatUtil {
|
|
|
1516
1651
|
// 标记当前消息已经交互完成
|
|
1517
1652
|
await aiChat.completeMessage(id, true);
|
|
1518
1653
|
};
|
|
1654
|
+
// 恢复会话
|
|
1655
|
+
chatOptions.resumeQuestion = async (
|
|
1656
|
+
aiChat: any,
|
|
1657
|
+
ctx: IContext,
|
|
1658
|
+
param: IParams,
|
|
1659
|
+
other: IParams,
|
|
1660
|
+
arr: IChatMessage[],
|
|
1661
|
+
) => {
|
|
1662
|
+
if (other.asyncacitonid) {
|
|
1663
|
+
id = createUUID();
|
|
1664
|
+
abortController = new AbortController();
|
|
1665
|
+
const deService = await ibiz.hub
|
|
1666
|
+
.getApp(ctx.srfappid)
|
|
1667
|
+
.deService.getService(ctx, other.appDataEntityId);
|
|
1668
|
+
const resumeRequestData: IData = { asyncacitonid: other.asyncacitonid };
|
|
1669
|
+
if (other.sessionid) {
|
|
1670
|
+
Object.assign(resumeRequestData, {
|
|
1671
|
+
sessionid: other.sessionid,
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
if (other.srfaiagent) {
|
|
1675
|
+
Object.assign(resumeRequestData, {
|
|
1676
|
+
srfaiagent: other.srfaiagent,
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
if (other.srfproject)
|
|
1680
|
+
Object.assign(resumeRequestData, {
|
|
1681
|
+
srfproject: other.srfproject,
|
|
1682
|
+
});
|
|
1683
|
+
try {
|
|
1684
|
+
await deService.aiResumeSse(
|
|
1685
|
+
(msg: IPortalAsyncAction) => {
|
|
1686
|
+
// 20: 持续回答中,消息会持续推送。同一个消息 id 会显示在同一个框内
|
|
1687
|
+
if (msg.actionstate === 20 && msg.actionresult) {
|
|
1688
|
+
// 设置当前聊天在加载中
|
|
1689
|
+
aiChat.isLoading.value = true;
|
|
1690
|
+
// 不存在才设置,存在则不设置(下方设置的时候需要去存储话题数据中)
|
|
1691
|
+
if (!aiChat.getActiveAsyncacitonId()) {
|
|
1692
|
+
aiChat.setActiveAsyncacitonId(msg.asyncacitonid);
|
|
1693
|
+
}
|
|
1694
|
+
aiChat.addMessage({
|
|
1695
|
+
messageid: id,
|
|
1696
|
+
state: msg.actionstate,
|
|
1697
|
+
type: 'DEFAULT',
|
|
1698
|
+
role: 'ASSISTANT',
|
|
1699
|
+
content: msg.actionresult as string,
|
|
1700
|
+
status: 'pending',
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
// 30: 回答完成,包含具体所有消息内容。直接覆盖之前的临时拼接消息
|
|
1704
|
+
else if (msg.actionstate === 30 && msg.actionresult) {
|
|
1705
|
+
const result = JSON.parse(msg.actionresult as string);
|
|
1706
|
+
if (result.usage) {
|
|
1707
|
+
aiChat.updateMsgUsage(id, result.usage);
|
|
1708
|
+
}
|
|
1709
|
+
const choices = result.choices;
|
|
1710
|
+
if (choices && choices.length > 0) {
|
|
1711
|
+
aiChat.replaceMessage({
|
|
1712
|
+
messageid: id,
|
|
1713
|
+
state: msg.actionstate,
|
|
1714
|
+
type: 'DEFAULT',
|
|
1715
|
+
role: 'ASSISTANT',
|
|
1716
|
+
content: choices[0].content || '',
|
|
1717
|
+
realmessageid: choices[0].messageid,
|
|
1718
|
+
status: 'sent',
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
// 40: 回答报错,展示错误信息
|
|
1723
|
+
else if (msg.actionstate === 40) {
|
|
1724
|
+
aiChat.replaceMessage({
|
|
1725
|
+
messageid: id,
|
|
1726
|
+
state: msg.actionstate,
|
|
1727
|
+
type: 'ERROR',
|
|
1728
|
+
role: 'ASSISTANT',
|
|
1729
|
+
errorText: msg.actionresult as string,
|
|
1730
|
+
status: 'failed',
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
},
|
|
1734
|
+
abortController,
|
|
1735
|
+
ctx,
|
|
1736
|
+
{ srfactag: param.srfactag },
|
|
1737
|
+
{ ...resumeRequestData },
|
|
1738
|
+
);
|
|
1739
|
+
} catch (error) {
|
|
1740
|
+
// 等于NONE_ERROR_MESSAGE,代码该异步行为已经完成,不需要做处理
|
|
1741
|
+
if (error && (error as Error).message !== this.NONE_ERROR_MESSAGE) {
|
|
1742
|
+
if (error && (error as Error).message !== this.PRE_ERROR_MESSAGE) {
|
|
1743
|
+
aiChat.replaceMessage({
|
|
1744
|
+
messageid: id,
|
|
1745
|
+
state: 40,
|
|
1746
|
+
type: 'ERROR',
|
|
1747
|
+
role: 'ASSISTANT',
|
|
1748
|
+
errorText:
|
|
1749
|
+
(error as IData).message || ibiz.i18n.t('app.aiError'),
|
|
1750
|
+
status: 'failed',
|
|
1751
|
+
});
|
|
1752
|
+
} else {
|
|
1753
|
+
const lastMessage = arr[arr.length - 1];
|
|
1754
|
+
aiChat.replaceMessage(
|
|
1755
|
+
{
|
|
1756
|
+
...lastMessage,
|
|
1757
|
+
state: 40,
|
|
1758
|
+
},
|
|
1759
|
+
false,
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
abortController?.abort();
|
|
1764
|
+
} finally {
|
|
1765
|
+
// 设置当前聊天加载状态已完成
|
|
1766
|
+
aiChat.isLoading.value = false;
|
|
1767
|
+
// 标记当前消息已经交互完成
|
|
1768
|
+
aiChat.completeMessage(id, true);
|
|
1769
|
+
// 清空异步消息任务
|
|
1770
|
+
aiChat.setActiveAsyncacitonId('');
|
|
1771
|
+
return true;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1519
1775
|
// 调整方向
|
|
1520
1776
|
chatOptions.supplementQuestion = async (
|
|
1521
1777
|
aiChat: any,
|