feat: 重新对接了会话及相关的接口
This commit is contained in:
@@ -88,7 +88,7 @@ import { Session } from '../../utils/storage';
|
||||
|
||||
import userAvatar from '@assets/images/login/user_icon.png';
|
||||
import aiAvatar from '@assets/images/login/blue_logo.png';
|
||||
import { createConversation, conversationMessageList } from '../../api/ConversationApi';
|
||||
import { createSession, getSessionMessages } from '../../api/SessionsApi';
|
||||
import { ElMessage, ElLoading } from 'element-plus'
|
||||
|
||||
// 支持外部通过 prop 控制是否为引导页
|
||||
@@ -275,7 +275,7 @@ onMounted(() => {
|
||||
|
||||
// token存在,初始化数据
|
||||
const initHandler = async () => {
|
||||
console.log("initHandler");
|
||||
console.log("initHandler:检查 token 并初始化数据");
|
||||
const token = getAccessToken();
|
||||
if (!token) return;
|
||||
await createConversationRequest();
|
||||
@@ -296,11 +296,11 @@ const checkToken = async () => {
|
||||
|
||||
// 调用接口创建新会话
|
||||
const createConversationRequest = async (): Promise<string | null> => {
|
||||
const res = await createConversation();
|
||||
if (res && res.conversationId) {
|
||||
conversationId.value = res.conversationId;
|
||||
const res = await createSession({});
|
||||
if (res && res.session_id) {
|
||||
conversationId.value = res.session_id;
|
||||
console.log("创建新会话,ID:", conversationId.value);
|
||||
return res.conversationId;
|
||||
return res.session_id;
|
||||
} else {
|
||||
console.log("创建会话失败,接口返回异常");
|
||||
return null;
|
||||
@@ -310,13 +310,14 @@ const createConversationRequest = async (): Promise<string | null> => {
|
||||
// 加载历史会话消息
|
||||
const loadConversationMessages = async (convId: string) => {
|
||||
try {
|
||||
const res = await conversationMessageList({ conversationId: convId, pageSize: 50, pageNum: 1 });
|
||||
const res = await getSessionMessages({ session_id: convId, limit: 50, offset: 0 });
|
||||
// 将消息转换为 ChatMessage 格式
|
||||
chatMsgList.value = res.records.map((msg: any) => ({
|
||||
messageId: msg.messageId,
|
||||
messageRole: msg.messageSenderRole === 'user' ? MessageRole.ME : MessageRole.AI,
|
||||
messageContent: msg.messageContent,
|
||||
timestamp: msg.timestamp,
|
||||
chatMsgList.value = res.messages.map((msg: any) => ({
|
||||
messageId: msg.message_id,
|
||||
messageRole: msg.role === 'user' ? MessageRole.ME : MessageRole.AI,
|
||||
messageContent: msg.content,
|
||||
messageContentList: [msg.content],
|
||||
timestamp: msg.created_at_ts,
|
||||
finished: true, // 历史消息已完成
|
||||
}));
|
||||
console.log("加载历史消息:", chatMsgList.value);
|
||||
@@ -493,7 +494,7 @@ const handleWebSocketMessage = (data: any) => {
|
||||
chatMsgList.value[aiMsgIndex].messageContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理toolCall
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].toolCall = data.toolCall;
|
||||
|
||||
Reference in New Issue
Block a user