Add mcpServersLoaded store to track server load state
Browse filesIntroduces a new writable store, mcpServersLoaded, to indicate when MCP servers have finished loading. Updates ChatWindow.svelte to only show router examples after servers are loaded, improving UI consistency and preventing premature rendering.
src/lib/components/chat/ChatWindow.svelte
CHANGED
|
@@ -27,7 +27,7 @@
|
|
| 27 |
import { routerExamples } from "$lib/constants/routerExamples";
|
| 28 |
import { mcpExamples } from "$lib/constants/mcpExamples";
|
| 29 |
import type { RouterFollowUp, RouterExample } from "$lib/constants/routerExamples";
|
| 30 |
-
import { allBaseServersEnabled } from "$lib/stores/mcpServers";
|
| 31 |
import { shareModal } from "$lib/stores/shareModal";
|
| 32 |
import CarbonTools from "~icons/carbon/tools";
|
| 33 |
|
|
@@ -438,7 +438,7 @@
|
|
| 438 |
dark:from-gray-900 dark:via-gray-900/100
|
| 439 |
dark:to-gray-900/0 max-sm:py-0 sm:px-5 md:pb-4 xl:max-w-4xl [&>*]:pointer-events-auto"
|
| 440 |
>
|
| 441 |
-
{#if !draft.length && !messages.length && !sources.length && !loading && currentModel.isRouter && activeExamples.length && !hideRouterExamples && !lastIsError}
|
| 442 |
<div
|
| 443 |
class="no-scrollbar mb-3 flex w-full select-none justify-start gap-2 overflow-x-auto whitespace-nowrap text-gray-400 dark:text-gray-500"
|
| 444 |
>
|
|
|
|
| 27 |
import { routerExamples } from "$lib/constants/routerExamples";
|
| 28 |
import { mcpExamples } from "$lib/constants/mcpExamples";
|
| 29 |
import type { RouterFollowUp, RouterExample } from "$lib/constants/routerExamples";
|
| 30 |
+
import { allBaseServersEnabled, mcpServersLoaded } from "$lib/stores/mcpServers";
|
| 31 |
import { shareModal } from "$lib/stores/shareModal";
|
| 32 |
import CarbonTools from "~icons/carbon/tools";
|
| 33 |
|
|
|
|
| 438 |
dark:from-gray-900 dark:via-gray-900/100
|
| 439 |
dark:to-gray-900/0 max-sm:py-0 sm:px-5 md:pb-4 xl:max-w-4xl [&>*]:pointer-events-auto"
|
| 440 |
>
|
| 441 |
+
{#if !draft.length && !messages.length && !sources.length && !loading && currentModel.isRouter && activeExamples.length && !hideRouterExamples && !lastIsError && $mcpServersLoaded}
|
| 442 |
<div
|
| 443 |
class="no-scrollbar mb-3 flex w-full select-none justify-start gap-2 overflow-x-auto whitespace-nowrap text-gray-400 dark:text-gray-500"
|
| 444 |
>
|
src/lib/stores/mcpServers.ts
CHANGED
|
@@ -104,6 +104,9 @@ function saveDisabledBaseIds(ids: Set<string>) {
|
|
| 104 |
// Store for all servers (base + custom)
|
| 105 |
export const allMcpServers = writable<MCPServer[]>([]);
|
| 106 |
|
|
|
|
|
|
|
|
|
|
| 107 |
// Store for selected server IDs
|
| 108 |
export const selectedServerIds = writable<Set<string>>(loadSelectedIds());
|
| 109 |
|
|
@@ -176,10 +179,12 @@ export async function refreshMcpServers() {
|
|
| 176 |
|
| 177 |
return newSelection;
|
| 178 |
});
|
|
|
|
| 179 |
} catch (error) {
|
| 180 |
console.error("Failed to refresh MCP servers:", error);
|
| 181 |
// On error, just use custom servers
|
| 182 |
allMcpServers.set(loadCustomServers());
|
|
|
|
| 183 |
}
|
| 184 |
}
|
| 185 |
|
|
|
|
| 104 |
// Store for all servers (base + custom)
|
| 105 |
export const allMcpServers = writable<MCPServer[]>([]);
|
| 106 |
|
| 107 |
+
// Track if initial server load has completed
|
| 108 |
+
export const mcpServersLoaded = writable<boolean>(false);
|
| 109 |
+
|
| 110 |
// Store for selected server IDs
|
| 111 |
export const selectedServerIds = writable<Set<string>>(loadSelectedIds());
|
| 112 |
|
|
|
|
| 179 |
|
| 180 |
return newSelection;
|
| 181 |
});
|
| 182 |
+
mcpServersLoaded.set(true);
|
| 183 |
} catch (error) {
|
| 184 |
console.error("Failed to refresh MCP servers:", error);
|
| 185 |
// On error, just use custom servers
|
| 186 |
allMcpServers.set(loadCustomServers());
|
| 187 |
+
mcpServersLoaded.set(true);
|
| 188 |
}
|
| 189 |
}
|
| 190 |
|