创建智能体

This commit is contained in:
2026-08-05 17:22:00 +08:00
parent fb421cd021
commit 2fff814c79
3 changed files with 175 additions and 73 deletions

View File

@@ -367,7 +367,8 @@
getUserInfo, getUserInfo,
getUserAvatar, getUserAvatar,
conversationMessageDownload, conversationMessageDownload,
getAgentList getAgentList,
addConversationAgent
} from '@/utils/cloud-api.js' } from '@/utils/cloud-api.js'
import { import {
getToken, getToken,
@@ -773,32 +774,26 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
} }
const handleAgentSelect = async (agent) => { const handleAgentSelect = async (agent) => {
console.log("点击了",agent.title); closeAgentModal()
// try { uni.showLoading({ title: '正在创建智能体...', mask: true })
// closeAgentModal() try {
// const chars = '0123456789abcdef' const result = await addConversationAgent(userToken.value, agent._id)
// let name = '' if (!result || !result.conversation_id) {
// for (let i = 0; i < 24; i++) { uni.hideLoading()
// name += chars[Math.floor(Math.random() * chars.length)] uni.showToast({ title: '智能体会话创建失败', icon: 'none' })
// } return
// const workspaceId = await createWorkspace(userToken.value, name) }
// if (!workspaceId) { // 刷新会话列表
// uni.showToast({ title: '工作区创建失败', icon: 'none' }) await takeUserConversations()
// return // 切换到新创建的会话
// } currentSessionId.value = result.conversation_id
// const loginInfo = uni.getStorageSync('yxd_login_info') uni.hideLoading()
// const userName = loginInfo ? (loginInfo.username || '') : '' uni.showToast({ title: `已创建「${result.title || agent.title}」会话`, icon: 'success' })
// const conversationId = await createConversation(userToken.value, workspaceId, agent.title, userName) } catch (error) {
// if (!conversationId) { uni.hideLoading()
// uni.showToast({ title: '智能体会话创建失败', icon: 'none' }) console.error('创建智能体会话失败:', error)
// return uni.showToast({ title: typeof error === 'string' ? error : '创建失败,请重试', icon: 'none' })
// } }
// uni.showToast({ title: `已创建「${agent.title}」会话`, icon: 'success' })
// takeUserConversations()
// } catch (error) {
// console.error('创建智能体会话失败:', error)
// uni.showToast({ title: '创建失败,请重试', icon: 'none' })
// }
} }
// 侧边栏相关 // 侧边栏相关
@@ -1720,8 +1715,7 @@ import { openFile as openFileNative, downloadAndOpen } from '@/utils/fileOpener.
const rawMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize, 0) || []; const rawMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize, 0) || [];
// API 返回的数据已被过滤,无法通过数量判断是否有更多,始终尝试加载更多 // API 返回的数据已被过滤,无法通过数量判断是否有更多,始终尝试加载更多
allmessages.value = rawMessages allmessages.value = rawMessages
console.log("获取到的所有消息:", JSON.stringify(allmessages.value) ); // console.log("获取到的所有消息:", JSON.stringify(allmessages.value) );
// console.log("获取到的所有消息:", allmessages.value);
// currentMessages.value = allmessages.value.slice(-pageInfoNumber); // currentMessages.value = allmessages.value.slice(-pageInfoNumber);
// 数据获取后执行滚动 // 数据获取后执行滚动
scrollToBottom(); scrollToBottom();

View File

@@ -1586,6 +1586,49 @@ if (uni.restoreGlobal) {
} else { } else {
reject(`获取智能体列表失败:${res.statusCode}`); reject(`获取智能体列表失败:${res.statusCode}`);
} }
},
fail: (err) => {
const msg = err.errMsg || "网络错误";
reject(msg);
}
});
});
};
const addConversationAgent = (token, agent_id) => {
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL$1}/cloud_api/phone/conversation/agent/add`,
method: "POST",
header: {
"Content-Type": "application/json"
},
data: {
"access_token": token,
"agent_id": agent_id
},
success: (res) => {
if (res.statusCode === 200) {
const respond = res.data;
if ((respond == null ? void 0 : respond.success) && (respond == null ? void 0 : respond.conversation_id)) {
if (respond.workspace_id) {
uni.setStorageSync("workspace_id", respond.workspace_id);
}
resolve({
conversation_id: respond.conversation_id,
workspace_id: respond.workspace_id,
title: respond.title || ""
});
} else {
const msg = (respond == null ? void 0 : respond.error) || "创建智能体会话出错啦";
reject(msg);
}
} else {
reject(`创建智能体会话失败:${res.statusCode}`);
}
},
fail: (err) => {
const msg = err.errMsg || "网络错误";
reject(msg);
} }
}); });
}); });
@@ -5769,7 +5812,7 @@ This will fail in production.`);
if (friendSocketStore.isConnected) if (friendSocketStore.isConnected)
return; return;
if (!userToken.value || !UserId.value) { if (!userToken.value || !UserId.value) {
formatAppLog("warn", "at pages/Chat/Chat.vue:408", "Token或UserId未准备好"); formatAppLog("warn", "at pages/Chat/Chat.vue:409", "Token或UserId未准备好");
return; return;
} }
friendSocketStore.connect({ friendSocketStore.connect({
@@ -5966,7 +6009,7 @@ This will fail in production.`);
}); });
return html; return html;
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:616", "解析失败", e2); formatAppLog("error", "at pages/Chat/Chat.vue:617", "解析失败", e2);
return content; return content;
} }
}; };
@@ -6017,7 +6060,7 @@ This will fail in production.`);
files files
}; };
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:685", "解析文件信息失败:", e2); formatAppLog("error", "at pages/Chat/Chat.vue:686", "解析文件信息失败:", e2);
return { return {
textContent: content, textContent: content,
files: [] files: []
@@ -6055,7 +6098,7 @@ This will fail in production.`);
closeNewChatModal(); closeNewChatModal();
takeUserConversations(); takeUserConversations();
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:731", "新建普通会话失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:732", "新建普通会话失败:", error);
uni.showToast({ uni.showToast({
title: "创建会话失败,请重试", title: "创建会话失败,请重试",
icon: "none" icon: "none"
@@ -6082,7 +6125,7 @@ This will fail in production.`);
uni.showToast({ title: "获取智能体列表失败", icon: "none" }); uni.showToast({ title: "获取智能体列表失败", icon: "none" });
} }
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:763", "获取智能体列表失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:764", "获取智能体列表失败:", error);
uni.showToast({ title: "获取智能体列表失败,请重试", icon: "none" }); uni.showToast({ title: "获取智能体列表失败,请重试", icon: "none" });
} finally { } finally {
agentLoading.value = false; agentLoading.value = false;
@@ -6093,7 +6136,24 @@ This will fail in production.`);
agentList.value = []; agentList.value = [];
}; };
const handleAgentSelect = async (agent) => { const handleAgentSelect = async (agent) => {
formatAppLog("log", "at pages/Chat/Chat.vue:776", "点击了", agent.title); closeAgentModal();
uni.showLoading({ title: "正在创建智能体...", mask: true });
try {
const result = await addConversationAgent(userToken.value, agent._id);
if (!result || !result.conversation_id) {
uni.hideLoading();
uni.showToast({ title: "智能体会话创建失败", icon: "none" });
return;
}
await takeUserConversations();
currentSessionId.value = result.conversation_id;
uni.hideLoading();
uni.showToast({ title: `已创建「${result.title || agent.title}」会话`, icon: "success" });
} catch (error) {
uni.hideLoading();
formatAppLog("error", "at pages/Chat/Chat.vue:794", "创建智能体会话失败:", error);
uni.showToast({ title: typeof error === "string" ? error : "创建失败,请重试", icon: "none" });
}
}; };
const isChatSidebar = vue.ref(false); const isChatSidebar = vue.ref(false);
const handleChatSidebar = () => { const handleChatSidebar = () => {
@@ -6180,7 +6240,7 @@ This will fail in production.`);
}; };
const previewFileArray = vue.ref([]); const previewFileArray = vue.ref([]);
const uploadPhoto = () => { const uploadPhoto = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:916", "点击了拍照上传"); formatAppLog("log", "at pages/Chat/Chat.vue:911", "点击了拍照上传");
uni.chooseImage({ uni.chooseImage({
count: 1, count: 1,
sourceType: ["camera", "album"], sourceType: ["camera", "album"],
@@ -6203,7 +6263,7 @@ This will fail in production.`);
}); });
}, },
fail: (err) => { fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:934", "选择图片失败", err); formatAppLog("error", "at pages/Chat/Chat.vue:929", "选择图片失败", err);
} }
}); });
}; };
@@ -6212,12 +6272,12 @@ This will fail in production.`);
}; };
const fileList = vue.ref([]); const fileList = vue.ref([]);
const uploadFile = () => { const uploadFile = () => {
formatAppLog("log", "at pages/Chat/Chat.vue:945", "点击了上传文件"); formatAppLog("log", "at pages/Chat/Chat.vue:940", "点击了上传文件");
chooseFile({ chooseFile({
count: 5, count: 5,
type: "all", type: "all",
success: (res) => { success: (res) => {
formatAppLog("log", "at pages/Chat/Chat.vue:950", "成功了"); formatAppLog("log", "at pages/Chat/Chat.vue:945", "成功了");
fileList.value = res.tempFiles; fileList.value = res.tempFiles;
previewFileArray.value.push(...res.tempFiles); previewFileArray.value.push(...res.tempFiles);
uni.showToast({ uni.showToast({
@@ -6226,7 +6286,7 @@ This will fail in production.`);
}); });
}, },
fail: (err) => { fail: (err) => {
formatAppLog("error", "at pages/Chat/Chat.vue:961", "选择失败:", err); formatAppLog("error", "at pages/Chat/Chat.vue:956", "选择失败:", err);
uni.showToast({ uni.showToast({
title: "选择失败", title: "选择失败",
icon: "error" icon: "error"
@@ -6465,7 +6525,7 @@ This will fail in production.`);
previewFileArray.value = []; previewFileArray.value = [];
} catch (err) { } catch (err) {
uni.hideLoading(); uni.hideLoading();
formatAppLog("error", "at pages/Chat/Chat.vue:1236", "文件上传失败:", err); formatAppLog("error", "at pages/Chat/Chat.vue:1231", "文件上传失败:", err);
uni.showToast({ uni.showToast({
title: "文件上传失败,请重试", title: "文件上传失败,请重试",
icon: "error" icon: "error"
@@ -6599,15 +6659,15 @@ This will fail in production.`);
} }
}; };
const stopConversation = async () => { const stopConversation = async () => {
formatAppLog("log", "at pages/Chat/Chat.vue:1406", "中断对话 - 当前会话ID:", currentSessionId.value); formatAppLog("log", "at pages/Chat/Chat.vue:1401", "中断对话 - 当前会话ID:", currentSessionId.value);
try { try {
await socketStore.send({ await socketStore.send({
type: "stop", type: "stop",
conversation_id: currentSessionId.value conversation_id: currentSessionId.value
}); });
formatAppLog("log", "at pages/Chat/Chat.vue:1412", "中断指令已发送成功"); formatAppLog("log", "at pages/Chat/Chat.vue:1407", "中断指令已发送成功");
} catch (err) { } catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1414", "中断指令发送失败:", err); formatAppLog("error", "at pages/Chat/Chat.vue:1409", "中断指令发送失败:", err);
} }
if (streamingMessageId.value) { if (streamingMessageId.value) {
allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value); allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value);
@@ -6625,9 +6685,9 @@ This will fail in production.`);
}); });
}; };
vue.watch(() => socketStore.isThinking, async (newVal, oldVal) => { vue.watch(() => socketStore.isThinking, async (newVal, oldVal) => {
formatAppLog("log", "at pages/Chat/Chat.vue:1438", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString); formatAppLog("log", "at pages/Chat/Chat.vue:1433", "isThinking 变化:", oldVal, "→", newVal, "messageString:", socketStore.messageString);
if (!oldVal && newVal) { if (!oldVal && newVal) {
formatAppLog("log", "at pages/Chat/Chat.vue:1441", "AI开始回复跨设备同步锁定输入框"); formatAppLog("log", "at pages/Chat/Chat.vue:1436", "AI开始回复跨设备同步锁定输入框");
isThinking.value = true; isThinking.value = true;
if (!isSelfSent.value) { if (!isSelfSent.value) {
await takeConversationMessages(); await takeConversationMessages();
@@ -6644,7 +6704,7 @@ This will fail in production.`);
return; return;
} }
if (oldVal && !newVal) { if (oldVal && !newVal) {
formatAppLog("log", "at pages/Chat/Chat.vue:1460", "AI回复结束正常/中断),解锁并刷新消息列表"); formatAppLog("log", "at pages/Chat/Chat.vue:1455", "AI回复结束正常/中断),解锁并刷新消息列表");
await takeConversationMessages(); await takeConversationMessages();
if (streamingMessageId.value) { if (streamingMessageId.value) {
allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value); allmessages.value = allmessages.value.filter((m) => m._id !== streamingMessageId.value);
@@ -6715,15 +6775,15 @@ This will fail in production.`);
UserData.value = await getUserInfo(userToken.value); UserData.value = await getUserInfo(userToken.value);
UserId.value = UserData.value._id; UserId.value = UserData.value._id;
UserAvatar.value = UserData.value.avatar || ""; UserAvatar.value = UserData.value.avatar || "";
formatAppLog("log", "at pages/Chat/Chat.vue:1547", "用户信息已加载:", UserId.value, UserAvatar.value); formatAppLog("log", "at pages/Chat/Chat.vue:1542", "用户信息已加载:", UserId.value, UserAvatar.value);
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1549", "获取用户信息失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:1544", "获取用户信息失败:", error);
} }
}; };
const takeUserConversations = async () => { const takeUserConversations = async () => {
try { try {
userToken.value = getToken(); userToken.value = getToken();
formatAppLog("log", "at pages/Chat/Chat.vue:1557", "token:", userToken.value); formatAppLog("log", "at pages/Chat/Chat.vue:1552", "token:", userToken.value);
UserConversations.value = await getUserConversations(userToken.value) || []; UserConversations.value = await getUserConversations(userToken.value) || [];
const savedSessionId = getCurrentSessionId(); const savedSessionId = getCurrentSessionId();
if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) { if (savedSessionId && UserConversations.value.some((c) => c._id === savedSessionId)) {
@@ -6733,7 +6793,7 @@ This will fail in production.`);
} else { } else {
currentSessionId.value = ""; currentSessionId.value = "";
} }
formatAppLog("log", "at pages/Chat/Chat.vue:1569", "保存会话id", currentSessionId.value); formatAppLog("log", "at pages/Chat/Chat.vue:1564", "保存会话id", currentSessionId.value);
uni.setStorageSync("currentSessionId", currentSessionId.value); uni.setStorageSync("currentSessionId", currentSessionId.value);
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({
@@ -6745,17 +6805,17 @@ This will fail in production.`);
const FriendInfoList = vue.ref([]); const FriendInfoList = vue.ref([]);
const takeFriendList = async () => { const takeFriendList = async () => {
try { try {
formatAppLog("log", "at pages/Chat/Chat.vue:1584", "开始获取好友列表"); formatAppLog("log", "at pages/Chat/Chat.vue:1579", "开始获取好友列表");
const friendList = await getChatFriend(UserId.value); const friendList = await getChatFriend(UserId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1587", "friendList:", friendList); formatAppLog("log", "at pages/Chat/Chat.vue:1582", "friendList:", friendList);
if (friendList && friendList.length) { if (friendList && friendList.length) {
FriendInfoList.value = await takeUserAvatar(friendList); FriendInfoList.value = await takeUserAvatar(friendList);
} else { } else {
FriendInfoList.value = []; FriendInfoList.value = [];
formatAppLog("log", "at pages/Chat/Chat.vue:1592", "好友列表为空"); formatAppLog("log", "at pages/Chat/Chat.vue:1587", "好友列表为空");
} }
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1595", "获取好友列表失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:1590", "获取好友列表失败:", error);
FriendInfoList.value = []; FriendInfoList.value = [];
} finally { } finally {
UserConversations.value = FriendInfoList.value; UserConversations.value = FriendInfoList.value;
@@ -6782,17 +6842,17 @@ This will fail in production.`);
}; };
}); });
} catch (err) { } catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1625", "获取好友头像失败", err); formatAppLog("error", "at pages/Chat/Chat.vue:1620", "获取好友头像失败", err);
return friendList; return friendList;
} }
}; };
const GroupList = vue.ref([]); const GroupList = vue.ref([]);
const takeGroupList = async () => { const takeGroupList = async () => {
try { try {
formatAppLog("log", "at pages/Chat/Chat.vue:1635", "开始获取群聊列表"); formatAppLog("log", "at pages/Chat/Chat.vue:1630", "开始获取群聊列表");
GroupList.value = await getGroup(UserId.value); GroupList.value = await getGroup(UserId.value);
} catch (error) { } catch (error) {
formatAppLog("error", "at pages/Chat/Chat.vue:1640", "获取群聊列表失败:", error); formatAppLog("error", "at pages/Chat/Chat.vue:1635", "获取群聊列表失败:", error);
GroupList.value = []; GroupList.value = [];
} finally { } finally {
UserConversations.value = GroupList.value; UserConversations.value = GroupList.value;
@@ -6804,22 +6864,22 @@ This will fail in production.`);
return []; return [];
try { try {
const memberIds = memberList.map((item) => item.groupContactId); const memberIds = memberList.map((item) => item.groupContactId);
formatAppLog("log", "at pages/Chat/Chat.vue:1654", "请求头像的ID列表:", memberIds); formatAppLog("log", "at pages/Chat/Chat.vue:1649", "请求头像的ID列表:", memberIds);
const memberAvatarList = await getUserAvatar(userToken.value, memberIds); const memberAvatarList = await getUserAvatar(userToken.value, memberIds);
formatAppLog("log", "at pages/Chat/Chat.vue:1656", "头像接口返回数据:", memberAvatarList); formatAppLog("log", "at pages/Chat/Chat.vue:1651", "头像接口返回数据:", memberAvatarList);
const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []); const userMap = new Map(memberAvatarList.map((user) => [user.user_id, user]) || []);
formatAppLog("log", "at pages/Chat/Chat.vue:1659", "userMap的keys:", Array.from(userMap.keys())); formatAppLog("log", "at pages/Chat/Chat.vue:1654", "userMap的keys:", Array.from(userMap.keys()));
return memberList.map((member) => { return memberList.map((member) => {
const memberId = member.groupContactId; const memberId = member.groupContactId;
const userInfo = userMap.get(memberId); const userInfo = userMap.get(memberId);
formatAppLog("log", "at pages/Chat/Chat.vue:1664", `查找 ${memberId} 的头像:`, userInfo); formatAppLog("log", "at pages/Chat/Chat.vue:1659", `查找 ${memberId} 的头像:`, userInfo);
return { return {
...member, ...member,
avatar: (userInfo == null ? void 0 : userInfo.avatar) || null avatar: (userInfo == null ? void 0 : userInfo.avatar) || null
}; };
}); });
} catch (err) { } catch (err) {
formatAppLog("error", "at pages/Chat/Chat.vue:1671", "获取群成员头像失败", err); formatAppLog("error", "at pages/Chat/Chat.vue:1666", "获取群成员头像失败", err);
return memberList; return memberList;
} }
}; };
@@ -6852,7 +6912,6 @@ This will fail in production.`);
hasMoreAIMessages.value = true; hasMoreAIMessages.value = true;
const rawMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize$1, 0) || []; const rawMessages = await getConversationMessages(userToken.value, currentSessionId.value, pageSize$1, 0) || [];
allmessages.value = rawMessages; allmessages.value = rawMessages;
formatAppLog("log", "at pages/Chat/Chat.vue:1723", "获取到的所有消息:", JSON.stringify(allmessages.value));
scrollToBottom(); scrollToBottom();
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({
@@ -6885,12 +6944,12 @@ This will fail in production.`);
hasMoreGroupMessages.value = true; hasMoreGroupMessages.value = true;
const rawMessages = await getGroupMessages(currentSessionId.value, pageSize$1, 0) || []; const rawMessages = await getGroupMessages(currentSessionId.value, pageSize$1, 0) || [];
allmessages.value = rawMessages; allmessages.value = rawMessages;
formatAppLog("log", "at pages/Chat/Chat.vue:1761", "群聊消息:", allmessages.value); formatAppLog("log", "at pages/Chat/Chat.vue:1755", "群聊消息:", allmessages.value);
const memberList = await getGroupMemberList(currentSessionId.value); const memberList = await getGroupMemberList(currentSessionId.value);
formatAppLog("log", "at pages/Chat/Chat.vue:1764", "获取到的群成员列表:", memberList); formatAppLog("log", "at pages/Chat/Chat.vue:1758", "获取到的群成员列表:", memberList);
if (memberList && memberList.length) { if (memberList && memberList.length) {
groupMemberList.value = await takeGroupMemberAvatar(memberList); groupMemberList.value = await takeGroupMemberAvatar(memberList);
formatAppLog("log", "at pages/Chat/Chat.vue:1767", "群成员列表(带头像):", groupMemberList.value); formatAppLog("log", "at pages/Chat/Chat.vue:1761", "群成员列表(带头像):", groupMemberList.value);
} else { } else {
groupMemberList.value = []; groupMemberList.value = [];
} }
@@ -6929,7 +6988,7 @@ This will fail in production.`);
hasMoreAIMessages.value = false; hasMoreAIMessages.value = false;
} }
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:1829", "加载更多消息失败:", e2); formatAppLog("error", "at pages/Chat/Chat.vue:1823", "加载更多消息失败:", e2);
uni.showToast({ title: "加载更多失败", icon: "none" }); uni.showToast({ title: "加载更多失败", icon: "none" });
} finally { } finally {
isAILoadingMore.value = false; isAILoadingMore.value = false;
@@ -6951,7 +7010,7 @@ This will fail in production.`);
hasMoreFriendMessages.value = false; hasMoreFriendMessages.value = false;
} }
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:1854", "加载更多好友消息失败:", e2); formatAppLog("error", "at pages/Chat/Chat.vue:1848", "加载更多好友消息失败:", e2);
uni.showToast({ title: "加载更多失败", icon: "none" }); uni.showToast({ title: "加载更多失败", icon: "none" });
} finally { } finally {
isFriendLoadingMore.value = false; isFriendLoadingMore.value = false;
@@ -6973,7 +7032,7 @@ This will fail in production.`);
hasMoreGroupMessages.value = false; hasMoreGroupMessages.value = false;
} }
} catch (e2) { } catch (e2) {
formatAppLog("error", "at pages/Chat/Chat.vue:1879", "加载更多群聊消息失败:", e2); formatAppLog("error", "at pages/Chat/Chat.vue:1873", "加载更多群聊消息失败:", e2);
uni.showToast({ title: "加载更多失败", icon: "none" }); uni.showToast({ title: "加载更多失败", icon: "none" });
} finally { } finally {
isGroupLoadingMore.value = false; isGroupLoadingMore.value = false;
@@ -6989,9 +7048,9 @@ This will fail in production.`);
} }
}; };
vue.watch(() => friendSocketStore.MessageReceived, (newId) => { vue.watch(() => friendSocketStore.MessageReceived, (newId) => {
formatAppLog("log", "at pages/Chat/Chat.vue:1900", "收到了好友消息"); formatAppLog("log", "at pages/Chat/Chat.vue:1894", "收到了好友消息");
if (newId) { if (newId) {
formatAppLog("log", "at pages/Chat/Chat.vue:1902", "ChatType:", ChatType.value); formatAppLog("log", "at pages/Chat/Chat.vue:1896", "ChatType:", ChatType.value);
switch (ChatType.value) { switch (ChatType.value) {
case 0: case 0:
takeConversationMessages(); takeConversationMessages();
@@ -7006,7 +7065,7 @@ This will fail in production.`);
friendSocketStore.MessageReceived = false; friendSocketStore.MessageReceived = false;
break; break;
default: default:
formatAppLog("log", "at pages/Chat/Chat.vue:1918", "default 分支"); formatAppLog("log", "at pages/Chat/Chat.vue:1912", "default 分支");
friendSocketStore.MessageReceived = false; friendSocketStore.MessageReceived = false;
break; break;
} }
@@ -7113,6 +7172,8 @@ This will fail in production.`);
return conversationMessageDownload; return conversationMessageDownload;
}, get getAgentList() { }, get getAgentList() {
return getAgentList; return getAgentList;
}, get addConversationAgent() {
return addConversationAgent;
}, get getToken() { }, get getToken() {
return getToken; return getToken;
}, get getCurrentSessionId() { }, get getCurrentSessionId() {

View File

@@ -1759,6 +1759,53 @@ export const getAgentList = (token) => {
} else { } else {
reject(`获取智能体列表失败:${res.statusCode}`) reject(`获取智能体列表失败:${res.statusCode}`)
} }
},
fail: (err) => {
const msg = err.errMsg || '网络错误';
reject(msg);
}
})
})
}
// 创建智能体会话
export const addConversationAgent = (token, agent_id) => {
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL}/cloud_api/phone/conversation/agent/add`,
method: "POST",
header: {
"Content-Type": "application/json"
},
data: {
"access_token": token,
"agent_id": agent_id
},
success: (res) => {
if (res.statusCode === 200) {
const respond = res.data
// 返回格式: { success: true, title: "...", conversation_id: "...", workspace_id: "..." }
if (respond?.success && respond?.conversation_id) {
// 保存 workspace_id 到本地存储
if (respond.workspace_id) {
uni.setStorageSync('workspace_id', respond.workspace_id)
}
resolve({
conversation_id: respond.conversation_id,
workspace_id: respond.workspace_id,
title: respond.title || ''
})
} else {
const msg = respond?.error || '创建智能体会话出错啦'
reject(msg)
}
} else {
reject(`创建智能体会话失败:${res.statusCode}`)
}
},
fail: (err) => {
const msg = err.errMsg || '网络错误'
reject(msg)
} }
}) })
}) })