@@ -146,6 +147,11 @@ import { clearCitationChunkCache } from '@/utils/citationChunkCache';
import ChatReferencesDrawer from '@/components/ChatReferencesDrawer.vue';
import ChatAttachmentPreviewDrawer from '@/components/ChatAttachmentPreviewDrawer.vue';
import FollowUpSuggestions from '@/components/chat/FollowUpSuggestions.vue';
+import ChatHeader from '@/components/ChatHeader.vue';
+import {
+ notifySessionMutation,
+ SESSION_MUTATION_EVENT,
+} from '@/components/sessionMutations';
import {
ensureMessageSuggestions,
getMessageSuggestions,
@@ -208,6 +214,7 @@ const attachStreamDebugToMessage = (message) => {
};
const route = useRoute();
const session_id = ref(props.session_id || route.params.chatid);
+const currentSession = ref(null);
// 拉 session 详情,并按其 last_request_state 把输入栏状态恢复到当时的发起态。
// 嵌入式(embeddedMode)由宿主页面注入 agent/KB,所以跳过整套恢复逻辑,
@@ -216,7 +223,8 @@ const loadSessionAndHydrate = async (sid) => {
if (!sid || props.embeddedMode) return;
try {
const sessionRes = await getSession(sid);
- if (sessionRes?.data) {
+ if (sessionRes?.data && sid === session_id.value) {
+ currentSession.value = sessionRes.data;
const lastState = sessionRes.data.last_request_state;
if (lastState) {
// 先把当前的"全局默认"快照下来,再用 session 状态覆盖;
@@ -434,6 +442,7 @@ watch([() => route.params], async (newvalue) => {
}
messagesList.splice(0);
session_id.value = newvalue[0].chatid;
+ currentSession.value = null;
clearCitationChunkCache();
// 切换会话时,重置状态
@@ -909,17 +918,27 @@ onChunk((data) => {
});
usemenuStore.updatasessionTitle(data.data.session_id, title);
usemenuStore.changeIsFirstSession(false);
- window.dispatchEvent(new CustomEvent('session-title-updated', {
- detail: { sessionId: data.data.session_id, title },
- }));
+ notifySessionMutation({
+ sessionId: data.data.session_id,
+ patch: { title },
+ });
}
return;
}
processStreamChunk(data);
});
-const handleSessionCleared = (e) => {
- if (e.detail?.sessionId === session_id.value) {
+const handleSessionMutation = (event) => {
+ const detail = event.detail;
+ if (detail?.sessionId !== session_id.value) return;
+
+ if (detail.patch) {
+ currentSession.value = {
+ ...(currentSession.value || { id: session_id.value }),
+ ...detail.patch,
+ };
+ }
+ if (detail.messagesCleared) {
messagesList.splice(0);
created_at.value = '';
hasMoreHistory.value = true;
@@ -947,7 +966,7 @@ onBeforeMount(async () => {
});
onMounted(async () => {
- window.addEventListener('session-messages-cleared', handleSessionCleared);
+ window.addEventListener(SESSION_MUTATION_EVENT, handleSessionMutation);
messagesList.splice(0);
// 初始化状态:加载历史消息时不应显示loading
@@ -988,7 +1007,7 @@ const clearData = () => {
isImRecovering.value = false;
}
onUnmounted(() => {
- window.removeEventListener('session-messages-cleared', handleSessionCleared);
+ window.removeEventListener(SESSION_MUTATION_EVENT, handleSessionMutation);
if (recoverPollTimer) { clearTimeout(recoverPollTimer); recoverPollTimer = null; }
});
onBeforeRouteLeave((to, from, next) => {
@@ -1008,7 +1027,7 @@ onBeforeRouteUpdate((to, from, next) => {
.chat {
font-size: 20px;
// 右侧不留 padding,滚动条贴到内容区最右缘
- padding: 20px 0 20px 20px;
+ padding: 0 0 20px 20px;
box-sizing: border-box;
flex: 1;
// The parent .platform-route-outlet is a flex column with min-height:0
@@ -1086,6 +1105,8 @@ onBeforeRouteUpdate((to, from, next) => {
// this box instead of stretching it.
min-height: 0;
width: 100%;
+ padding-top: 8px;
+ box-sizing: border-box;
overflow-y: auto;
// 使用系统原生滚动条(macOS 滚动时自动显示 overlay 滚动条,类似 ChatGPT)
scrollbar-width: auto;