Merge branch 'refs-sidebar' into dev

This commit is contained in:
Wenjie Zhang 2025-04-27 19:00:44 +08:00
commit aba91f719c
6 changed files with 689 additions and 307 deletions

View File

@ -26,7 +26,7 @@
"less": "^4.1.3",
"marked": "^13.0.2",
"marked-highlight": "^2.1.4",
"md-editor-v3": "^4.16.7",
"md-editor-v3": "^4.21.3",
"pinia": "^2.0.32",
"vue": "^3.5.13",
"vue-router": "^4.1.6"

View File

@ -81,13 +81,15 @@
</div>
<div class="chat-box" :class="{ 'wide-screen': meta.wideScreen, 'font-smaller': meta.fontSize === 'smaller', 'font-larger': meta.fontSize === 'larger' }">
<MessageComponent
v-for="message in conv.messages"
v-for="(message, index) in conv.messages"
:message="message"
:key="message.id"
:is-processing="isStreaming"
:show-refs="true"
:show-refs="['copy', 'regenerate', 'subGraph', 'webSearch', 'knowledgeBase']"
:is-latest-message="isLatestMessage(index)"
@retry="retryMessage(message.id)"
@retryStoppedMessage="retryStoppedMessage(message.id)"
@openRefs="handleOpenRefs"
>
</MessageComponent>
</div>
@ -142,6 +144,13 @@
<p class="note">请注意辨别内容的可靠性 By {{ configStore.config?.model_provider }}: {{ configStore.config?.model_name }}</p>
</div>
</div>
<!-- 添加全局Refs侧边栏 -->
<RefsSidebar
ref="refsSidebarRef"
:visible="refsSidebarVisible"
:latestRefs="currentRefs"
@update:visible="refsSidebarVisible = $event"
/>
</div>
</template>
@ -178,6 +187,7 @@ import { useConfigStore } from '@/stores/config'
import { message } from 'ant-design-vue'
import MessageInputComponent from '@/components/MessageInputComponent.vue'
import MessageComponent from '@/components/MessageComponent.vue'
import RefsSidebar from '@/components/RefsSidebar.vue'
const props = defineProps({
conv: Object,
@ -222,6 +232,41 @@ const meta = reactive(JSON.parse(localStorage.getItem('meta')) || {
wideScreen: false,
})
// refs
const refsSidebarVisible = ref(false)
const currentRefs = ref({})
// refs
const handleOpenRefs = ({ type, refs }) => {
console.log('ChatComponent handleOpenRefs called with type:', type);
console.log('Refs data structure:', JSON.stringify(refs));
//
currentRefs.value = Object.assign({}, refs);
// tick
nextTick(() => {
//
refsSidebarVisible.value = true;
//
console.log('Updated refs data:', JSON.stringify(currentRefs.value));
// type
if (refsSidebarRef.value) {
console.log('Setting active tab to:', type);
// 50
setTimeout(() => {
refsSidebarRef.value.setActiveTab(type);
}, 50);
} else {
console.error('refsSidebarRef is not available');
}
});
}
// RefsSidebarref
const refsSidebarRef = ref(null)
const consoleMsg = (msg) => console.log(msg)
onClickOutside(panel, () => setTimeout(() => opts.showPanel = false, 30))
@ -393,6 +438,11 @@ const updateMessage = (info) => {
propertiesToUpdate.forEach(prop => {
if (info[prop] != null && (typeof info[prop] !== 'string' || info[prop] !== '')) {
msg[prop] = info[prop];
// refsrefs
if (prop === 'refs' && info.refs) {
currentRefs.value = info.refs;
}
}
});
@ -481,6 +531,12 @@ const fetchChatResponse = (user_input, cur_res_id) => {
console.log(msg)
groupRefs(cur_res_id);
updateMessage({showThinking: "no", id: cur_res_id});
// refsrefs
if (msg && msg.refs) {
// refs
currentRefs.value = JSON.parse(JSON.stringify(msg.refs));
console.log('Updated currentRefs on response completion:', currentRefs.value);
}
isStreaming.value = false;
if (conv.value.messages.length === 2) { renameTitle(); }
return;
@ -606,6 +662,11 @@ onMounted(() => {
const parsedMeta = JSON.parse(storedMeta);
Object.assign(meta, parsedMeta);
}
// refsSidebarRef
nextTick(() => {
console.log('Is refsSidebarRef mounted?', !!refsSidebarRef.value);
});
});
onUnmounted(() => {
@ -677,6 +738,26 @@ const selectModel = (provider, name) => {
configStore.setConfigValue('model_name', name)
// message.success(`: ${name} | ${provider}`)
}
//
const isLatestMessage = (index) => {
//
const lastAssistantMsgIndex = findLastIndex(conv.value.messages,
msg => (msg.role === 'received' || msg.role === 'assistant') && msg.status === 'finished');
//
return index === lastAssistantMsgIndex;
}
//
const findLastIndex = (array, predicate) => {
for (let i = array.length - 1; i >= 0; i--) {
if (predicate(array[i])) {
return i;
}
}
return -1;
}
</script>
<style lang="less" scoped>

View File

@ -4,7 +4,7 @@
<script setup>
import { Graph } from "@antv/g6";
import { onMounted, watch, ref } from 'vue';
import { onMounted, watch, ref, onUnmounted } from 'vue';
const props = defineProps({
graphData: {
@ -16,21 +16,49 @@ const props = defineProps({
const container = ref(null);
let graphInstance = null;
let resizeObserver = null;
const initGraph = () => {
//
const width = container.value.offsetWidth;
const height = container.value.offsetHeight;
if (width < 100) {
//
setTimeout(initGraph, 100);
return;
}
//
if (container.value) {
container.value.innerHTML = '';
}
//
if (graphInstance) {
graphInstance.destroy();
graphInstance = null;
}
graphInstance = new Graph({
container: container.value,
width: container.value.offsetWidth,
height: container.value.offsetHeight,
width: width,
height: height,
autoFit: true,
autoResize: true,
layout: {
type: 'd3-force',
preventOverlap: true,
kr: 20,
kr: 30,
linkDistance: 200,
nodeStrength: -100,
collide: {
strength: 1.0,
strength: 1.5,
radius: 60,
},
alpha: 0.8,
alphaDecay: 0.028,
center: [width / 2, height / 2],
},
node: {
type: 'circle',
@ -56,10 +84,51 @@ const initGraph = () => {
};
const renderGraph = () => {
//
if (graphInstance && container.value) {
const currentWidth = container.value.offsetWidth;
const currentHeight = container.value.offsetHeight;
let graphWidth = 0;
let graphHeight = 0;
//
try {
if (typeof graphInstance.getWidth === 'function') {
graphWidth = graphInstance.getWidth();
} else if (graphInstance.cfg && graphInstance.cfg.width) {
graphWidth = graphInstance.cfg.width;
}
if (typeof graphInstance.getHeight === 'function') {
graphHeight = graphInstance.getHeight();
} else if (graphInstance.cfg && graphInstance.cfg.height) {
graphHeight = graphInstance.cfg.height;
}
} catch (e) {
console.error('Error getting graph dimensions:', e);
}
// 50px
if (Math.abs(currentWidth - graphWidth) > 50 || Math.abs(currentHeight - graphHeight) > 50) {
graphInstance.destroy();
graphInstance = null;
//
if (container.value) {
container.value.innerHTML = '';
}
}
}
if (!graphInstance) {
initGraph();
}
if (!graphInstance) {
//
return;
}
const formattedData = {
nodes: props.graphData.nodes.map(node => ({
id: node.id,
@ -74,14 +143,86 @@ const renderGraph = () => {
graphInstance.setData(formattedData);
graphInstance.render();
//
setTimeout(() => {
if (graphInstance) {
graphInstance.fitCenter();
graphInstance.fitView();
}
}, 300);
};
//
const refreshGraph = () => {
//
if (graphInstance) {
graphInstance.destroy();
graphInstance = null;
}
//
if (container.value) {
container.value.innerHTML = '';
}
//
setTimeout(() => {
renderGraph();
}, 100);
};
//
defineExpose({
refreshGraph
});
onMounted(() => {
// 使ResizeObserver
if (window.ResizeObserver) {
resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
if (entry.target === container.value) {
renderGraph();
}
}
});
if (container.value) {
resizeObserver.observe(container.value);
}
}
renderGraph();
window.addEventListener('resize', renderGraph);
});
watch(() => props.graphData, renderGraph, { deep: true });
//
onUnmounted(() => {
window.removeEventListener('resize', renderGraph);
if (resizeObserver) {
resizeObserver.disconnect();
resizeObserver = null;
}
if (graphInstance) {
graphInstance.destroy();
graphInstance = null;
}
//
if (container.value) {
container.value.innerHTML = '';
}
});
watch(() => props.graphData, (newData, oldData) => {
//
if (newData !== oldData) {
refreshGraph();
}
}, { deep: true });
</script>
<style scoped>

View File

@ -67,7 +67,7 @@
<div v-if="(message.role=='received' || message.role=='assistant') && message.status=='finished' && showRefs">
<RefsComponent :message="message" :show-refs="showRefs" @retry="emit('retry')" />
<RefsComponent :message="message" :show-refs="showRefs" :is-latest-message="isLatestMessage" @retry="emit('retry')" @openRefs="emit('openRefs', $event)" />
</div>
<!-- 错误消息 -->
</div>
@ -111,6 +111,11 @@ const props = defineProps({
type: Boolean,
default: false
},
//
isLatestMessage: {
type: Boolean,
default: false
}
});
const editorRef = ref()
@ -122,7 +127,7 @@ const statusDefination = {
error: '错误'
}
const emit = defineEmits(['retry', 'retryStoppedMessage']);
const emit = defineEmits(['retry', 'retryStoppedMessage', 'openRefs']);
//
const reasoningActiveKey = ref(['show']);

View File

@ -11,101 +11,32 @@
v-if="showKey('regenerate')"
class="item btn" @click="regenerateMessage()" title="重新生成"><ReloadOutlined /></span>
<span
v-if="showKey('subGraph') && hasSubGraphData(msg)"
v-if="isLatestMessage && showKey('subGraph') && hasSubGraphData(msg)"
class="item btn"
@click="openSubGraph(msg)"
@click="openGlobalRefs('graph')"
>
<DeploymentUnitOutlined /> 关系图
</span>
<span
class="item btn"
@click="showWebResult(msg)"
v-if="showKey('webSearch') && msg.refs?.web_search.results.length > 0"
v-if="isLatestMessage && showKey('webSearch') && msg.refs?.web_search.results.length > 0"
@click="openGlobalRefs('webSearch')"
>
<GlobalOutlined /> 网页搜索 {{ msg.refs.web_search?.results.length }}
</span>
<span class="filetag item btn"
v-for="(results, filename) in msg.groupedResults"
:key="filename"
@click="toggleDrawer(filename)"
<span
class="item btn"
v-if="isLatestMessage && showKey('knowledgeBase') && hasKnowledgeBaseData(msg)"
@click="openGlobalRefs('knowledgeBase')"
>
<FileTextOutlined /> {{ filename }}
<a-drawer
v-model:open="openDetail[filename]"
:title="filename"
width="700"
:contentWrapperStyle="{ maxWidth: '100%'}"
placement="right"
class="retrieval-detail"
rootClassName="root"
>
<div class="fileinfo">
<p><FileOutlined /> {{ results[0].file.type }}</p>
<p><ClockCircleOutlined /> {{ formatDate(results[0].file.created_at) }}</p>
</div>
<div class="results-list">
<div v-for="res in results" :key="res.id" class="result-item">
<div class="result-meta">
<div class="score-info">
<span>
<strong>相似度</strong>
<a-progress :percent="getPercent(res.distance)"/>
</span>
<span v-if="res.rerank_score">
<strong>重排序</strong>
<a-progress :percent="getPercent(res.rerank_score)"/>
</span>
</div>
<div class="result-id">ID: #{{ res.id }}</div>
</div>
<div class="result-text">{{ res.entity.text }}</div>
</div>
</div>
</a-drawer>
<FileTextOutlined /> 知识库
</span>
</div>
<a-modal
v-model:open="subGraphVisible"
title="相关实体与关系"
:width="800"
:footer="null"
>
<GraphContainer :graphData="subGraphData" />
</a-modal>
<a-drawer
v-model:open="webResultVisible"
title="网页搜索结果"
width="700"
:contentWrapperStyle="{ maxWidth: '100%'}"
placement="right"
class="web-result-detail"
rootClassName="root"
>
<div class="results-list">
<div v-for="result in webResults" :key="result.url" class="result-item">
<div class="result-meta">
<div class="score-info">
<span>
<strong>相关度</strong>
<a-progress :percent="getPercent(result.score)"/>
</span>
</div>
<div class="result-url">
<a :href="result.url" target="_blank">{{ result.url }}</a>
</div>
</div>
<div class="result-content">
<h3 class="result-title">{{ result.title }}</h3>
<div class="result-text">{{ result.content }}</div>
</div>
</div>
</div>
</a-drawer>
</div>
</template>
<script setup>
import { ref, computed, reactive } from 'vue'
import { ref, computed } from 'vue'
import { useClipboard } from '@vueuse/core'
import { message } from 'ant-design-vue'
import {
@ -114,19 +45,19 @@ import {
CopyOutlined,
DeploymentUnitOutlined,
BulbOutlined,
FileOutlined,
ClockCircleOutlined,
ReloadOutlined,
} from '@ant-design/icons-vue'
import GraphContainer from './GraphContainer.vue' // GraphContainer
const emit = defineEmits(['retry']);
const emit = defineEmits(['retry', 'openRefs']);
const props = defineProps({
message: Object,
showRefs: {
type: [Array, Boolean],
default: () => false
},
isLatestMessage: {
type: Boolean,
default: false
}
})
@ -158,58 +89,14 @@ const copyText = async (text) => {
}
}
//
const likeThisResponse = (msg) => {
console.log('Like this response:', msg)
}
const dislikeThisResponse = (msg) => {
console.log('Dislike this response:', msg)
}
// 使 reactive
const openDetail = reactive({})
// openDetail
for (const filename in msg.value.groupedResults) {
openDetail[filename] = false
}
const toggleDrawer = (filename) => {
openDetail[filename] = !openDetail[filename]
}
const showRefs = computed(() => (msg.value.role=='received' || msg.value.role=='assistant') && msg.value.status=='finished')
const subGraphVisible = ref(false)
const subGraphData = ref(null)
const openSubGraph = (msg) => {
if (hasSubGraphData(msg)) {
subGraphData.value = msg.refs.graph_base.results
subGraphVisible.value = true
} else {
console.error('无法获取子图数据')
}
}
const closeSubGraph = () => {
subGraphVisible.value = false
}
//
const webResultVisible = ref(false)
const webResults = ref(null)
//
const showWebResult = (msg) => {
if (msg.refs?.web_search) {
webResults.value = msg.refs?.web_search.results
webResultVisible.value = true
} else {
console.error('无法获取网页搜索结果')
}
// refs
const openGlobalRefs = (type) => {
emit('openRefs', {
type,
refs: msg.value.refs
})
}
const hasSubGraphData = (msg) => {
@ -218,14 +105,10 @@ const hasSubGraphData = (msg) => {
msg.refs.graph_base.results.nodes.length > 0;
}
//
const formatDate = (timestamp) => {
return new Date(timestamp * 1000).toLocaleString()
}
//
const getPercent = (value) => {
return parseFloat((value * 100).toFixed(2))
const hasKnowledgeBaseData = (msg) => {
return msg.refs &&
msg.refs.knowledge_base &&
msg.refs.knowledge_base.results.length > 0;
}
//
@ -265,160 +148,6 @@ const regenerateMessage = () => {
display: flex;
flex-wrap: wrap;
gap: 10px;
.filetag {
display: flex;
align-items: center;
gap: 5px;
}
}
}
.retrieval-detail {
.fileinfo {
display: flex;
justify-content: space-between;
padding: 12px 16px;
background-color: #f5f5f5;
border-radius: 4px;
margin-bottom: 16px;
p {
margin: 0;
color: #666;
}
}
.score-info {
display: flex;
flex-wrap: wrap;
gap: 2rem;
margin-bottom: 8px;
span {
display: flex;
align-items: center;
strong {
margin-right: 8px;
white-space: nowrap;
color: #666;
}
.ant-progress {
width: 170px;
margin-bottom: 0;
margin-inline: 10px;
.ant-progress-bg {
background-color: #666;
}
}
}
}
.result-id {
font-size: 12px;
color: #999;
margin-bottom: 8px;
}
.result-text {
font-size: 14px;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
background-color: #f9f9f9;
padding: 12px;
border-radius: 4px;
border: 1px solid #e8e8e8;
}
}
.results-list {
.result-item {
border-bottom: 1px solid #f0f0f0;
padding: 16px 0;
&:last-child {
border-bottom: none;
}
}
.result-meta {
margin-bottom: 12px;
}
}
.web-result-detail {
.results-list {
.result-item {
border-bottom: 1px solid #f0f0f0;
padding: 16px 0;
&:last-child {
border-bottom: none;
}
}
.result-meta {
margin-bottom: 12px;
.score-info {
display: flex;
flex-wrap: wrap;
gap: 2rem;
margin-bottom: 8px;
span {
display: flex;
align-items: center;
strong {
margin-right: 8px;
white-space: nowrap;
color: #666;
}
.ant-progress {
width: 170px;
margin-bottom: 0;
margin-inline: 10px;
.ant-progress-bg {
background-color: #666;
}
}
}
}
.result-url {
font-size: 12px;
color: #1677FF;
margin-bottom: 8px;
word-break: break-all;
}
}
.result-content {
.result-title {
font-size: 16px;
font-weight: bold;
margin-bottom: 8px;
color: #333;
}
.result-text {
font-size: 14px;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
background-color: #f9f9f9;
padding: 12px;
border-radius: 4px;
border: 1px solid #e8e8e8;
}
}
}
}
</style>

View File

@ -0,0 +1,426 @@
<template>
<div>
<a-drawer
:open="visible"
title="参考信息"
:width="700"
:contentWrapperStyle="{ maxWidth: '100%'}"
placement="right"
class="refs-sidebar"
rootClassName="root"
@close="$emit('update:visible', false)"
@afterOpenChange="handleAfterVisibleChange"
>
<a-tabs v-model:activeKey="activeTab">
<!-- 关系图 -->
<a-tab-pane key="graph" tab="关系图" :disabled="!hasGraphData">
<div v-if="hasGraphData" class="graph-container">
<GraphContainer :graphData="latestRefs.graph_base.results" ref="graphContainerRef" />
</div>
<div v-else class="empty-data">
<p>当前对话没有关系图数据</p>
</div>
</a-tab-pane>
<!-- 网页搜索 -->
<a-tab-pane key="webSearch" tab="网页搜索" :disabled="!hasWebSearchData">
<div v-if="hasWebSearchData" class="results-list">
<div v-for="result in latestRefs.web_search.results" :key="result.url" class="result-item">
<div class="result-meta">
<div class="score-info">
<span>
<strong>相关度</strong>
<a-progress :percent="getPercent(result.score)"/>
</span>
</div>
</div>
<div class="result-content">
<h3 class="result-title">{{ result.title }}</h3>
<div class="result-url">
<a :href="result.url" target="_blank">{{ result.url }}</a>
</div>
<div class="result-text">{{ result.content }}</div>
</div>
</div>
</div>
<div v-else class="empty-data">
<p>当前对话没有网页搜索数据</p>
</div>
</a-tab-pane>
<!-- 知识库 -->
<a-tab-pane key="knowledgeBase" tab="知识库" :disabled="!hasKnowledgeBaseData">
<div v-if="hasKnowledgeBaseData">
<div class="file-list">
<a-collapse v-model:activeKey="activeFiles">
<a-collapse-panel
v-for="(results, filename) in groupedKnowledgeResults"
:key="filename"
:header="filename"
>
<div class="fileinfo" v-if="results.length > 0">
<p><FileOutlined /> {{ results[0].file.type }}</p>
<p><ClockCircleOutlined /> {{ formatDate(results[0].file.created_at) }}</p>
</div>
<div class="results-list">
<div v-for="res in results" :key="res.id" class="result-item">
<div class="result-meta">
<div class="score-info">
<span>
<strong>相似度</strong>
<a-progress :percent="getPercent(res.distance)"/>
</span>
<span v-if="res.rerank_score">
<strong>重排序</strong>
<a-progress :percent="getPercent(res.rerank_score)"/>
</span>
</div>
<div class="result-id">ID: #{{ res.id }}</div>
</div>
<div class="result-text">{{ res.entity.text }}</div>
</div>
</div>
</a-collapse-panel>
</a-collapse>
</div>
</div>
<div v-else class="empty-data">
<p>当前对话没有知识库查询数据</p>
</div>
</a-tab-pane>
</a-tabs>
</a-drawer>
</div>
</template>
<script setup>
import { ref, computed, reactive, watch, nextTick } from 'vue'
import {
FileOutlined,
ClockCircleOutlined,
} from '@ant-design/icons-vue'
import GraphContainer from './GraphContainer.vue'
const props = defineProps({
visible: {
type: Boolean,
default: false
},
latestRefs: {
type: Object,
default: () => ({})
}
})
const emit = defineEmits(['update:visible'])
//
const activeTab = ref('graph')
const activeFiles = ref([])
//
const hasGraphData = computed(() => {
try {
return !!(props.latestRefs &&
props.latestRefs.graph_base &&
props.latestRefs.graph_base.results &&
props.latestRefs.graph_base.results.nodes &&
Array.isArray(props.latestRefs.graph_base.results.nodes) &&
props.latestRefs.graph_base.results.nodes.length > 0);
} catch (e) {
console.error('Error checking graph data:', e);
return false;
}
})
const hasWebSearchData = computed(() => {
try {
//
return !!(props.latestRefs &&
props.latestRefs.web_search &&
Array.isArray(props.latestRefs.web_search.results) &&
props.latestRefs.web_search.results.length > 0);
} catch (e) {
console.error('Error checking web search data:', e);
return false;
}
})
const hasKnowledgeBaseData = computed(() => {
try {
return !!(props.latestRefs &&
props.latestRefs.knowledge_base &&
props.latestRefs.knowledge_base.results &&
Array.isArray(props.latestRefs.knowledge_base.results) &&
props.latestRefs.knowledge_base.results.length > 0);
} catch (e) {
console.error('Error checking knowledge base data:', e);
return false;
}
})
//
const groupedKnowledgeResults = computed(() => {
if (!hasKnowledgeBaseData.value) return {}
return props.latestRefs.knowledge_base.results
.filter(result => result.file && result.file.filename)
.reduce((acc, result) => {
const { filename } = result.file
if (!acc[filename]) {
acc[filename] = []
}
acc[filename].push(result)
return acc
}, {})
})
//
watch(() => props.visible, (newValue) => {
console.log('RefsSidebar visible changed to', newValue, 'activeTab is', activeTab.value);
if (newValue) {
console.log('Checking which tabs are available');
// activeTab
const currentTabValid =
(activeTab.value === 'graph' && hasGraphData.value) ||
(activeTab.value === 'webSearch' && hasWebSearchData.value) ||
(activeTab.value === 'knowledgeBase' && hasKnowledgeBaseData.value);
if (!currentTabValid) {
console.log('Current tab is invalid, finding first available tab');
//
if (hasGraphData.value) {
console.log('Selected graph tab');
activeTab.value = 'graph';
} else if (hasWebSearchData.value) {
console.log('Selected webSearch tab');
activeTab.value = 'webSearch';
} else if (hasKnowledgeBaseData.value) {
console.log('Selected knowledgeBase tab');
activeTab.value = 'knowledgeBase';
//
if (Object.keys(groupedKnowledgeResults.value).length > 0) {
activeFiles.value = [Object.keys(groupedKnowledgeResults.value)[0]];
}
} else {
console.log('No valid tabs available');
}
} else {
console.log('Current tab is valid, keeping it:', activeTab.value);
}
}
});
//
const getPercent = (value) => {
return parseFloat((value * 100).toFixed(2))
}
//
const formatDate = (timestamp) => {
return new Date(timestamp * 1000).toLocaleString()
}
//
const setActiveTab = (tab) => {
console.log('RefsSidebar setActiveTab called with tab:', tab);
console.log('Current tabs available:', {
graph: hasGraphData.value,
webSearch: hasWebSearchData.value,
knowledgeBase: hasKnowledgeBaseData.value
});
console.log('Full latestRefs structure:', JSON.stringify(props.latestRefs));
//
if ((tab === 'graph' && hasGraphData.value) ||
(tab === 'webSearch' && hasWebSearchData.value) ||
(tab === 'knowledgeBase' && hasKnowledgeBaseData.value)) {
console.log('Setting activeTab to:', tab);
activeTab.value = tab;
} else {
console.warn(`Cannot set tab to ${tab}, tab is disabled or invalid`);
//
if (tab === 'webSearch' && props.latestRefs.web_search) {
console.log('Forcing webSearch tab even though hasWebSearchData is false');
activeTab.value = 'webSearch';
} else if (tab === 'knowledgeBase' && props.latestRefs.knowledge_base) {
console.log('Forcing knowledgeBase tab even though hasKnowledgeBaseData is false');
activeTab.value = 'knowledgeBase';
} else if (tab === 'graph' && props.latestRefs.graph_base) {
console.log('Forcing graph tab even though hasGraphData is false');
activeTab.value = 'graph';
}
}
}
// ref
const graphContainerRef = ref(null);
//
const handleAfterVisibleChange = (visible) => {
console.log('RefsSidebar afterOpenChange fired, visible:', visible, 'activeTab:', activeTab.value);
if (!visible) return;
//
nextTick(() => {
if (activeTab.value === 'graph' && hasGraphData.value) {
console.log('Refreshing graph after drawer opened');
//
if (graphContainerRef.value && graphContainerRef.value.refreshGraph) {
graphContainerRef.value.refreshGraph();
}
} else {
console.log('Current active tab is', activeTab.value, 'no need to refresh graph');
}
});
};
//
watch(activeTab, (newTab) => {
if (newTab === 'graph' && hasGraphData.value && props.visible) {
//
nextTick(() => {
if (graphContainerRef.value && graphContainerRef.value.refreshGraph) {
graphContainerRef.value.refreshGraph();
}
});
}
});
// latestRefs便
watch(() => props.latestRefs, (newRefs) => {
console.log('RefsSidebar latestRefs changed:', {
hasGraph: hasGraphData.value,
hasWeb: hasWebSearchData.value,
hasKB: hasKnowledgeBaseData.value,
graph: newRefs.graph_base?.results?.nodes?.length,
web: newRefs.web_search?.results?.length,
kb: newRefs.knowledge_base?.results?.length
});
}, { deep: true });
//
defineExpose({
setActiveTab
})
</script>
<style lang="less" scoped>
.refs-sidebar {
.empty-data {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
color: #999;
font-size: 14px;
background-color: #f9f9f9;
border-radius: 4px;
}
.graph-container {
min-height: 500px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.fileinfo {
display: flex;
justify-content: space-between;
padding: 12px 16px;
background-color: #f5f5f5;
border-radius: 4px;
margin-bottom: 16px;
p {
margin: 0;
color: #666;
}
}
.results-list {
.result-item {
border-bottom: 1px solid #f0f0f0;
padding: 16px 0;
&:last-child {
border-bottom: none;
}
}
.result-meta {
margin-bottom: 12px;
.score-info {
display: flex;
flex-wrap: wrap;
gap: 2rem;
margin-bottom: 8px;
span {
display: flex;
align-items: center;
strong {
margin-right: 8px;
white-space: nowrap;
color: #666;
}
.ant-progress {
width: 170px;
margin-bottom: 0;
margin-inline: 10px;
.ant-progress-bg {
background-color: #666;
}
}
}
}
.result-id {
font-size: 12px;
color: #999;
margin-bottom: 8px;
}
}
.result-content {
.result-title {
font-size: 16px;
font-weight: bold;
margin-bottom: 8px;
color: #333;
}
.result-url {
font-size: 12px;
color: #0563e7;
margin-bottom: 8px;
a {
color: #0563e7;
word-break: break-all;
}
}
.result-text {
font-size: 14px;
line-height: 1.6;
white-space: pre-wrap;
word-break: break-word;
background-color: #f9f9f9;
padding: 12px;
border-radius: 4px;
border: 1px solid #e8e8e8;
}
}
}
}
</style>