refactor: Move MCP health checks to background process from core layout
This commit is contained in:
parent
cde9d45008
commit
2d59005d37
|
|
@ -10,12 +10,6 @@
|
|||
|
||||
let { onOpenChange, open = $bindable(false) }: Props = $props();
|
||||
|
||||
$effect(() => {
|
||||
if (open) {
|
||||
mcpStore.runHealthChecksForServers(mcpStore.getServers());
|
||||
}
|
||||
});
|
||||
|
||||
function handleClose() {
|
||||
onOpenChange?.(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,9 +237,6 @@ class ConversationsStore {
|
|||
this.activeMessages = messages;
|
||||
}
|
||||
|
||||
// Run MCP health checks for enabled servers in this conversation
|
||||
this.runMcpHealthChecksForConversation(conversation.mcpServerOverrides);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to load conversation:', error);
|
||||
|
|
@ -247,31 +244,6 @@ class ConversationsStore {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs MCP health checks for servers enabled in a conversation.
|
||||
* Runs asynchronously in the background without blocking conversation loading.
|
||||
*/
|
||||
private runMcpHealthChecksForConversation(mcpServerOverrides?: McpServerOverride[]): void {
|
||||
if (!mcpServerOverrides?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const enabledServers = mcpStore.getEnabledServersForConversation(mcpServerOverrides);
|
||||
|
||||
if (enabledServers.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[conversationsStore] Running health checks for ${enabledServers.length} MCP server(s)`
|
||||
);
|
||||
|
||||
// Run health checks in background (don't await)
|
||||
mcpStore.runHealthChecksForServers(enabledServers).catch((error) => {
|
||||
console.warn('[conversationsStore] MCP health checks failed:', error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the active conversation and messages.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<script lang="ts">
|
||||
import '../app.css';
|
||||
import { base } from '$app/paths';
|
||||
import { browser } from '$app/environment';
|
||||
import { page } from '$app/state';
|
||||
import { untrack } from 'svelte';
|
||||
import { ChatSidebar, DialogConversationTitleUpdate } from '$lib/components/app';
|
||||
|
|
@ -14,6 +15,7 @@
|
|||
import { Toaster } from 'svelte-sonner';
|
||||
import { goto } from '$app/navigation';
|
||||
import { modelsStore } from '$lib/stores/models.svelte';
|
||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||
import { TOOLTIP_DELAY_DURATION } from '$lib/constants/tooltip-config';
|
||||
import { KeyboardKey } from '$lib/enums';
|
||||
import { IsMobile } from '$lib/hooks/is-mobile.svelte';
|
||||
|
|
@ -142,6 +144,26 @@
|
|||
}
|
||||
});
|
||||
|
||||
// Background MCP server health checks on app load
|
||||
// Fetch enabled servers from settings and run health checks in background
|
||||
$effect(() => {
|
||||
if (!browser) return;
|
||||
|
||||
const mcpServers = mcpStore.getServers();
|
||||
|
||||
// Only run health checks if we have enabled servers with URLs
|
||||
const enabledServers = mcpServers.filter((s) => s.enabled && s.url.trim());
|
||||
|
||||
if (enabledServers.length > 0) {
|
||||
untrack(() => {
|
||||
// Run health checks in background (don't await)
|
||||
mcpStore.runHealthChecksForServers(enabledServers, false).catch((error) => {
|
||||
console.warn('[layout] MCP health checks failed:', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Monitor API key changes and redirect to error page if removed or changed when required
|
||||
$effect(() => {
|
||||
const apiKey = config().apiKey;
|
||||
|
|
|
|||
Loading…
Reference in New Issue