@zero-library/chat-agent 2.2.14 → 2.2.16
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.cjs.js +15 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.esm.js +15 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -930,6 +930,37 @@ interface ChatHooks {
|
|
|
930
930
|
* @param isBuiltIn - 是否为内嵌布局
|
|
931
931
|
*/
|
|
932
932
|
onAfterFilePreview?: (file?: FileUrlType | FileTextType, isBuiltIn?: boolean) => void;
|
|
933
|
+
/**
|
|
934
|
+
* 设置引用消息前回调
|
|
935
|
+
* 在设置引用消息前调用,返回false可阻止设置
|
|
936
|
+
*
|
|
937
|
+
* @param references - 要设置的引用消息, 空则表示正在清除引用消息
|
|
938
|
+
* @returns boolean | Promise<boolean> | void - 返回false阻止设置
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* onBeforeSetReferences: (references) => {
|
|
942
|
+
* // 验证引用消息内容
|
|
943
|
+
* if (!references || !references.content) {
|
|
944
|
+
* message.error('引用消息内容不能为空')
|
|
945
|
+
* return false
|
|
946
|
+
* }
|
|
947
|
+
* return true
|
|
948
|
+
* }
|
|
949
|
+
*/
|
|
950
|
+
onBeforeSetReferences?: (references?: ReferencesType) => boolean | Promise<boolean> | void;
|
|
951
|
+
/**
|
|
952
|
+
* 设置引用消息后回调
|
|
953
|
+
* 在设置引用消息完成后调用
|
|
954
|
+
*
|
|
955
|
+
* @param references - 已设置的引用消息, 空则表示已清除引用消息
|
|
956
|
+
*
|
|
957
|
+
* @example
|
|
958
|
+
* onAfterSetReferences: (references) => {
|
|
959
|
+
* console.log('引用消息已设置:', references)
|
|
960
|
+
* // 可以在这里更新界面状态或其他相关操作
|
|
961
|
+
* }
|
|
962
|
+
*/
|
|
963
|
+
onAfterSetReferences?: (references?: ReferencesType) => void;
|
|
933
964
|
}
|
|
934
965
|
/**
|
|
935
966
|
* 聊天参数接口
|
|
@@ -1387,7 +1418,7 @@ interface ChatHandle {
|
|
|
1387
1418
|
* 设置引用消息
|
|
1388
1419
|
* 在输入框中设置引用内容,将在下次发送消息时包含引用信息
|
|
1389
1420
|
*
|
|
1390
|
-
* @param references -
|
|
1421
|
+
* @param references - 引用内容对象, 空则表示清除引用消息
|
|
1391
1422
|
*
|
|
1392
1423
|
* @example
|
|
1393
1424
|
* // 设置Markdown引用
|
package/dist/index.d.ts
CHANGED
|
@@ -930,6 +930,37 @@ interface ChatHooks {
|
|
|
930
930
|
* @param isBuiltIn - 是否为内嵌布局
|
|
931
931
|
*/
|
|
932
932
|
onAfterFilePreview?: (file?: FileUrlType | FileTextType, isBuiltIn?: boolean) => void;
|
|
933
|
+
/**
|
|
934
|
+
* 设置引用消息前回调
|
|
935
|
+
* 在设置引用消息前调用,返回false可阻止设置
|
|
936
|
+
*
|
|
937
|
+
* @param references - 要设置的引用消息, 空则表示正在清除引用消息
|
|
938
|
+
* @returns boolean | Promise<boolean> | void - 返回false阻止设置
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* onBeforeSetReferences: (references) => {
|
|
942
|
+
* // 验证引用消息内容
|
|
943
|
+
* if (!references || !references.content) {
|
|
944
|
+
* message.error('引用消息内容不能为空')
|
|
945
|
+
* return false
|
|
946
|
+
* }
|
|
947
|
+
* return true
|
|
948
|
+
* }
|
|
949
|
+
*/
|
|
950
|
+
onBeforeSetReferences?: (references?: ReferencesType) => boolean | Promise<boolean> | void;
|
|
951
|
+
/**
|
|
952
|
+
* 设置引用消息后回调
|
|
953
|
+
* 在设置引用消息完成后调用
|
|
954
|
+
*
|
|
955
|
+
* @param references - 已设置的引用消息, 空则表示已清除引用消息
|
|
956
|
+
*
|
|
957
|
+
* @example
|
|
958
|
+
* onAfterSetReferences: (references) => {
|
|
959
|
+
* console.log('引用消息已设置:', references)
|
|
960
|
+
* // 可以在这里更新界面状态或其他相关操作
|
|
961
|
+
* }
|
|
962
|
+
*/
|
|
963
|
+
onAfterSetReferences?: (references?: ReferencesType) => void;
|
|
933
964
|
}
|
|
934
965
|
/**
|
|
935
966
|
* 聊天参数接口
|
|
@@ -1387,7 +1418,7 @@ interface ChatHandle {
|
|
|
1387
1418
|
* 设置引用消息
|
|
1388
1419
|
* 在输入框中设置引用内容,将在下次发送消息时包含引用信息
|
|
1389
1420
|
*
|
|
1390
|
-
* @param references -
|
|
1421
|
+
* @param references - 引用内容对象, 空则表示清除引用消息
|
|
1391
1422
|
*
|
|
1392
1423
|
* @example
|
|
1393
1424
|
* // 设置Markdown引用
|
package/dist/index.esm.js
CHANGED
|
@@ -274,7 +274,7 @@ var classifyTime = (timestamp) => {
|
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
var replaceMarkdownTags = (str) => {
|
|
277
|
-
return str.replace(/<think>/g, ":::alert type=think data={content:'").replace(/<\/think>/g, "'}
|
|
277
|
+
return str.replace(/<think>/g, ":::alert type=think data={content:'").replace(/<\/think>/g, "'} :::\n");
|
|
278
278
|
};
|
|
279
279
|
var getChatSocketUrl = (baseURL, params) => {
|
|
280
280
|
return buildUrlParams(params, getWebSocketUrl(`${baseURL}/lolr/conversation/ws/subscribe`), "comma");
|
|
@@ -681,8 +681,13 @@ function createChatStore() {
|
|
|
681
681
|
const setSpeakHuman = (speakHuman) => {
|
|
682
682
|
conversation.messages[conversation.active.id].speakHuman = speakHuman;
|
|
683
683
|
};
|
|
684
|
-
const setReferences = (references) => {
|
|
684
|
+
const setReferences = async (references) => {
|
|
685
|
+
const canProceed = await config.hooks?.onBeforeSetReferences?.(references);
|
|
686
|
+
if (canProceed === false) {
|
|
687
|
+
throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
|
|
688
|
+
}
|
|
685
689
|
conversation.messages[conversation.active.id].references = references;
|
|
690
|
+
config.hooks?.onAfterSetReferences?.(references);
|
|
686
691
|
};
|
|
687
692
|
const setContent = (content) => {
|
|
688
693
|
conversation.messages[conversation.active.id].content = content;
|
|
@@ -1185,13 +1190,6 @@ var MessageRender_default = ({ message: message2, placement, onFilePreview }) =>
|
|
|
1185
1190
|
] }) });
|
|
1186
1191
|
};
|
|
1187
1192
|
|
|
1188
|
-
// src/core/constants.ts
|
|
1189
|
-
var MEMBER_TYPE = {
|
|
1190
|
-
1: "user",
|
|
1191
|
-
2: "other",
|
|
1192
|
-
3: "agent"
|
|
1193
|
-
};
|
|
1194
|
-
|
|
1195
1193
|
// src/ui/common/BubbleListItems.tsx
|
|
1196
1194
|
init_Context();
|
|
1197
1195
|
|
|
@@ -1276,6 +1274,7 @@ var BubbleListItems_default = ({ firstMessage = false, welcomeMessage = true, av
|
|
|
1276
1274
|
const roles = {};
|
|
1277
1275
|
if (conversationState.active.member.user) {
|
|
1278
1276
|
roles.user = {
|
|
1277
|
+
id: conversationState.active.member.user.memberId,
|
|
1279
1278
|
user: "user",
|
|
1280
1279
|
placement: "end",
|
|
1281
1280
|
avatar: (isBoolean(avatar) ? avatar : avatar?.user) ? /* @__PURE__ */ jsx(
|
|
@@ -1290,6 +1289,7 @@ var BubbleListItems_default = ({ firstMessage = false, welcomeMessage = true, av
|
|
|
1290
1289
|
}
|
|
1291
1290
|
if (conversationState.active.member.agent) {
|
|
1292
1291
|
roles.agent = {
|
|
1292
|
+
id: conversationState.active.member.agent.memberId,
|
|
1293
1293
|
user: "agent",
|
|
1294
1294
|
placement: "start",
|
|
1295
1295
|
avatar: (isBoolean(avatar) ? avatar : avatar?.agent) ? { src: conversationState.active.member.agent?.memberAvatar, icon: /* @__PURE__ */ jsx(OpenAIOutlined, {}) } : null
|
|
@@ -1297,6 +1297,7 @@ var BubbleListItems_default = ({ firstMessage = false, welcomeMessage = true, av
|
|
|
1297
1297
|
}
|
|
1298
1298
|
if (conversationState.active.member.other) {
|
|
1299
1299
|
roles.other = {
|
|
1300
|
+
id: conversationState.active.member.other.memberId,
|
|
1300
1301
|
user: "other",
|
|
1301
1302
|
placement: "start",
|
|
1302
1303
|
avatar: (isBoolean(avatar) ? avatar : avatar?.other) ? { src: conversationState.active.member.other?.memberAvatar, icon: /* @__PURE__ */ jsx(OpenAIOutlined, {}) } : null
|
|
@@ -1344,9 +1345,13 @@ var BubbleListItems_default = ({ firstMessage = false, welcomeMessage = true, av
|
|
|
1344
1345
|
] : [],
|
|
1345
1346
|
[chatMessage?.questionList]
|
|
1346
1347
|
);
|
|
1348
|
+
const getRole = (sender) => {
|
|
1349
|
+
const roleKey = Object.keys(conversationRoles).find((key) => conversationRoles[key].id === sender.id);
|
|
1350
|
+
return conversationRoles[roleKey] || {};
|
|
1351
|
+
};
|
|
1347
1352
|
const chatRecords = useMemo(() => {
|
|
1348
1353
|
return (chatMessage?.message || []).map((message2, index) => {
|
|
1349
|
-
const role =
|
|
1354
|
+
const role = getRole(message2.sender);
|
|
1350
1355
|
return {
|
|
1351
1356
|
key: message2.id,
|
|
1352
1357
|
placement: role.placement,
|