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;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
]">
|
||||
<span class="w-2 h-2 rounded-full bg-[#BEDBFF] flex-none"></span>
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="truncate text-sm">{{ item.conversationId }}</div>
|
||||
<div class="truncate text-sm">{{ item.conversationTitle }}</div>
|
||||
</div>
|
||||
<button v-if="item.conversationId === selectedConversationId"
|
||||
class="bg-transparent border-0 text-gray-500 text-lg px-1 py-0">…</button>
|
||||
@@ -32,7 +32,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, defineEmits } from 'vue'
|
||||
import { RiAddLine, RiArrowRightSLine, RiArrowDownSLine } from '@remixicon/vue'
|
||||
import { getConversationList } from '../../api/ConversationApi';
|
||||
import { getSessionList } from '../../api/SessionsApi';
|
||||
|
||||
interface HistoryMessage {
|
||||
conversationId: string;
|
||||
@@ -72,11 +72,11 @@ onMounted(() => {
|
||||
|
||||
/// 获取历史会话列表
|
||||
const getHistoryConversationList = async () => {
|
||||
const list = await getConversationList({ pageSize: 20, pageNum: 1 })
|
||||
if (!list || !list.records) return;
|
||||
groups.value.push(...list.records.map((item: any) => ({
|
||||
conversationId: item.conversationId,
|
||||
conversationTitle: item.conversationTitle
|
||||
const list = await getSessionList({ limit: 50, offset: 0 })
|
||||
if (!list || !list.sessions) return;
|
||||
groups.value.push(...list.sessions.map((item: any) => ({
|
||||
conversationId: item.session_id,
|
||||
conversationTitle: item.title
|
||||
})))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user