Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/renderer/src/components/settings/DifyKnowledgeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</template>

<script setup lang="ts">
import { ref, computed, onMounted, watch, toRaw } from 'vue'
import { ref, computed, onMounted, watch, toRaw, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { Icon } from '@iconify/vue'
import { Button } from '@/components/ui/button'
Expand Down Expand Up @@ -402,11 +402,6 @@ watch(
}
)

// 组件挂载时加载配置
onMounted(async () => {
await loadDifyConfigFromMcp()
})

// 监听URL查询参数,设置活动标签页
watch(
() => route.query.subtab,
Expand All @@ -417,4 +412,26 @@ watch(
},
{ immediate: true }
)

// 组件挂载时加载配置
let unwatch: () => void // only use here, so declare it here
onMounted(async () => {
unwatch = watch(
() => mcpStore.config.ready,
async (ready) => {
if (ready) {
unwatch() // only run once to avoid multiple calls
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接使用 https://vuejs.org/guide/essentials/watchers.html#once-watchers
{once:true} 应该就可以

await loadDifyConfigFromMcp()
}
},
{ immediate: true }
)
})

// cancel the watch to avoid memory leaks
onUnmounted(() => {
if (unwatch) {
unwatch()
}
})
</script>
22 changes: 20 additions & 2 deletions src/renderer/src/components/settings/FastGptKnowledgeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</template>

<script setup lang="ts">
import { ref, computed, onMounted, watch, toRaw } from 'vue'
import { ref, computed, onMounted, watch, toRaw, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { Icon } from '@iconify/vue'
import { Button } from '@/components/ui/button'
Expand Down Expand Up @@ -355,6 +355,7 @@ const updateFastGptConfigToMcp = async () => {
const loadFastGptConfigFromMcp = async () => {
try {
// 获取fastGptKnowledge服务器配置
console.log(mcpStore.config)
const serverConfig = mcpStore.config.mcpServers['fastGptKnowledge']
if (serverConfig && serverConfig.env) {
// 解析配置 - env可能是JSON字符串
Expand Down Expand Up @@ -412,7 +413,24 @@ watch(
)

// 组件挂载时加载配置
let unwatch: () => void // only use here, so declare it here
onMounted(async () => {
await loadFastGptConfigFromMcp()
unwatch = watch(
() => mcpStore.config.ready,
async (ready) => {
if (ready) {
unwatch() // only run once to avoid multiple calls
await loadFastGptConfigFromMcp()
}
},
{ immediate: true }
)
})

// cancel the watch to avoid memory leaks
onUnmounted(() => {
if (unwatch) {
unwatch()
}
})
</script>
21 changes: 19 additions & 2 deletions src/renderer/src/components/settings/RagflowKnowledgeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</template>

<script setup lang="ts">
import { ref, computed, onMounted, watch, toRaw } from 'vue'
import { ref, computed, onMounted, watch, toRaw, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { Icon } from '@iconify/vue'
import { Button } from '@/components/ui/button'
Expand Down Expand Up @@ -431,7 +431,24 @@ watch(
)

// 组件挂载时加载配置
let unwatch: () => void // only use here, so declare it here
onMounted(async () => {
await loadRagflowConfigFromMcp()
unwatch = watch(
() => mcpStore.config.ready,
async (ready) => {
if (ready) {
unwatch() // only run once to avoid multiple calls
await loadRagflowConfigFromMcp()
}
},
{ immediate: true }
)
})

// cancel the watch to avoid memory leaks
onUnmounted(() => {
if (unwatch) {
unwatch()
}
})
</script>
7 changes: 4 additions & 3 deletions src/renderer/src/stores/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const useMcpStore = defineStore('mcp', () => {
const config = ref<MCPConfig>({
mcpServers: {},
defaultServers: [],
mcpEnabled: false // 添加MCP启用状态
mcpEnabled: false, // 添加MCP启用状态
ready: false // if init finished, the ready will be true
})

// MCP全局启用状态
Expand Down Expand Up @@ -108,11 +109,11 @@ export const useMcpStore = defineStore('mcp', () => {
mcpPresenter.getMcpDefaultServers(),
mcpPresenter.getMcpEnabled()
])

config.value = {
mcpServers: servers,
defaultServers: defaultServers,
mcpEnabled: enabled
mcpEnabled: enabled,
ready: true // config is loaded
}

// 获取服务器运行状态
Expand Down
1 change: 1 addition & 0 deletions src/shared/presenter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ export interface MCPConfig {
mcpServers: Record<string, MCPServerConfig>
defaultServers: string[]
mcpEnabled: boolean
ready: boolean
}

export interface MCPToolDefinition {
Expand Down