diff --git a/web/src/components/AgentChatComponent.vue b/web/src/components/AgentChatComponent.vue index 07902024..11dddc75 100644 --- a/web/src/components/AgentChatComponent.vue +++ b/web/src/components/AgentChatComponent.vue @@ -991,7 +991,7 @@ const initAll = async () => { onMounted(async () => { await initAll(); scrollController.enableAutoScroll(); - }); +}); watch(currentAgentId, async (newAgentId, oldAgentId) => { if (newAgentId !== oldAgentId) { diff --git a/web/src/components/AgentConfigSidebar.vue b/web/src/components/AgentConfigSidebar.vue index ba9fbdac..a7299c8f 100644 --- a/web/src/components/AgentConfigSidebar.vue +++ b/web/src/components/AgentConfigSidebar.vue @@ -423,6 +423,10 @@ const getToolNameById = (toolId) => { const loadAvailableTools = async () => { try { + // 避免重复加载,如果已经有工具就直接返回 + if (availableTools.value && Object.keys(availableTools.value).length > 0) { + return; + } await agentStore.fetchTools(); } catch (error) { console.error('加载工具列表失败:', error); diff --git a/web/src/stores/agent.js b/web/src/stores/agent.js index 86f31339..e6048a38 100644 --- a/web/src/stores/agent.js +++ b/web/src/stores/agent.js @@ -33,6 +33,7 @@ export const useAgentStore = defineStore('agent', () => { // 初始化状态 const isInitialized = ref(false) + const isInitializing = ref(false) // ==================== 计算属性 ==================== const selectedAgent = computed(() => @@ -76,6 +77,10 @@ export const useAgentStore = defineStore('agent', () => { async function initialize() { if (isInitialized.value) return + // 防止并发初始化 + if (isInitializing.value) return + isInitializing.value = true + try { await fetchAgents() await fetchDefaultAgent() @@ -111,6 +116,8 @@ export const useAgentStore = defineStore('agent', () => { console.error('Failed to initialize agent store:', err) handleChatError(err, 'initialize') error.value = err.message + } finally { + isInitializing.value = false } } @@ -321,6 +328,7 @@ export const useAgentStore = defineStore('agent', () => { isLoadingAgentDetail.value = false error.value = null isInitialized.value = false + isInitializing.value = false } return { diff --git a/web/src/views/AgentView.vue b/web/src/views/AgentView.vue index ec94302b..9e12b8de 100644 --- a/web/src/views/AgentView.vue +++ b/web/src/views/AgentView.vue @@ -165,13 +165,6 @@ const loadAgentConfig = async () => { } }; -// 监听智能体选择变化 -watch( - () => selectedAgentId.value, - () => { - loadAgentConfig(); - } -); // 选择智能体(使用store方法) const selectAgent = (agentId) => {