Add MCP examples and dynamic example selection
Browse files
src/lib/components/chat/ChatWindow.svelte
CHANGED
|
@@ -25,7 +25,9 @@
|
|
| 25 |
import { useSettingsStore } from "$lib/stores/settings";
|
| 26 |
import ModelSwitch from "./ModelSwitch.svelte";
|
| 27 |
import { routerExamples } from "$lib/constants/routerExamples";
|
|
|
|
| 28 |
import type { RouterFollowUp, RouterExample } from "$lib/constants/routerExamples";
|
|
|
|
| 29 |
import { shareModal } from "$lib/stores/shareModal";
|
| 30 |
import CarbonTools from "~icons/carbon/tools";
|
| 31 |
|
|
@@ -282,9 +284,13 @@
|
|
| 282 |
let focused = $state(false);
|
| 283 |
|
| 284 |
let activeRouterExamplePrompt = $state<string | null>(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
let routerFollowUps = $derived<RouterFollowUp[]>(
|
| 286 |
activeRouterExamplePrompt
|
| 287 |
-
? (
|
| 288 |
: []
|
| 289 |
);
|
| 290 |
let routerUserMessages = $derived(messages.filter((msg) => msg.from === "user"));
|
|
@@ -310,7 +316,7 @@
|
|
| 310 |
return;
|
| 311 |
}
|
| 312 |
|
| 313 |
-
const match =
|
| 314 |
activeRouterExamplePrompt = match ? match.prompt : null;
|
| 315 |
});
|
| 316 |
|
|
@@ -432,11 +438,11 @@
|
|
| 432 |
dark:from-gray-900 dark:via-gray-900/100
|
| 433 |
dark:to-gray-900/0 max-sm:py-0 sm:px-5 md:pb-4 xl:max-w-4xl [&>*]:pointer-events-auto"
|
| 434 |
>
|
| 435 |
-
{#if !draft.length && !messages.length && !sources.length && !loading && currentModel.isRouter &&
|
| 436 |
<div
|
| 437 |
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"
|
| 438 |
>
|
| 439 |
-
{#each
|
| 440 |
<button
|
| 441 |
class="flex items-center rounded-lg bg-gray-100/90 px-2 py-0.5 text-center text-sm backdrop-blur hover:text-gray-500 dark:bg-gray-700/50 dark:hover:text-gray-400"
|
| 442 |
onclick={() => startExample(ex)}>{ex.title}</button
|
|
|
|
| 25 |
import { useSettingsStore } from "$lib/stores/settings";
|
| 26 |
import ModelSwitch from "./ModelSwitch.svelte";
|
| 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 |
|
|
|
|
| 284 |
let focused = $state(false);
|
| 285 |
|
| 286 |
let activeRouterExamplePrompt = $state<string | null>(null);
|
| 287 |
+
// Use MCP examples when all base servers are enabled, otherwise use router examples
|
| 288 |
+
let activeExamples = $derived<RouterExample[]>(
|
| 289 |
+
$allBaseServersEnabled ? mcpExamples : routerExamples
|
| 290 |
+
);
|
| 291 |
let routerFollowUps = $derived<RouterFollowUp[]>(
|
| 292 |
activeRouterExamplePrompt
|
| 293 |
+
? (activeExamples.find((ex) => ex.prompt === activeRouterExamplePrompt)?.followUps ?? [])
|
| 294 |
: []
|
| 295 |
);
|
| 296 |
let routerUserMessages = $derived(messages.filter((msg) => msg.from === "user"));
|
|
|
|
| 316 |
return;
|
| 317 |
}
|
| 318 |
|
| 319 |
+
const match = activeExamples.find((ex) => ex.prompt.trim() === firstUserMessage.content.trim());
|
| 320 |
activeRouterExamplePrompt = match ? match.prompt : null;
|
| 321 |
});
|
| 322 |
|
|
|
|
| 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 |
>
|
| 445 |
+
{#each activeExamples as ex}
|
| 446 |
<button
|
| 447 |
class="flex items-center rounded-lg bg-gray-100/90 px-2 py-0.5 text-center text-sm backdrop-blur hover:text-gray-500 dark:bg-gray-700/50 dark:hover:text-gray-400"
|
| 448 |
onclick={() => startExample(ex)}>{ex.title}</button
|
src/lib/constants/mcpExamples.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { RouterExample } from "./routerExamples";
|
| 2 |
+
|
| 3 |
+
// Examples that showcase MCP tool capabilities (web search, Hugging Face, etc.)
|
| 4 |
+
export const mcpExamples: RouterExample[] = [
|
| 5 |
+
{
|
| 6 |
+
title: "Latest world news",
|
| 7 |
+
prompt: "What is the latest world news?",
|
| 8 |
+
followUps: [
|
| 9 |
+
{
|
| 10 |
+
title: "Tech focus",
|
| 11 |
+
prompt: "What about technology news?",
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
title: "San Francisco",
|
| 15 |
+
prompt: "What's happening in San Francisco?",
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
title: "vs last week",
|
| 19 |
+
prompt: "How does this compare to last week's news?",
|
| 20 |
+
},
|
| 21 |
+
],
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
title: "Trending models",
|
| 25 |
+
prompt: "What are the top trending models on Hugging Face?",
|
| 26 |
+
followUps: [
|
| 27 |
+
{
|
| 28 |
+
title: "Text generation",
|
| 29 |
+
prompt: "What about text generation models?",
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
title: "Image generation",
|
| 33 |
+
prompt: "What about text-to-image models?",
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
title: "How to use",
|
| 37 |
+
prompt: "Show me how to use the most popular one",
|
| 38 |
+
},
|
| 39 |
+
],
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
title: "Plan a trip",
|
| 43 |
+
prompt: "Things to do in Tokyo next week",
|
| 44 |
+
followUps: [
|
| 45 |
+
{
|
| 46 |
+
title: "Transport & prices",
|
| 47 |
+
prompt: "How do I get around and how much will it cost?",
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
title: "Weather",
|
| 51 |
+
prompt: "What's the weather like in Tokyo next week?",
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
title: "Meet people",
|
| 55 |
+
prompt: "Where can I meet new people and make friends?",
|
| 56 |
+
},
|
| 57 |
+
],
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
title: "Compare technologies",
|
| 61 |
+
prompt: "Search the web to compare React, Vue, and Svelte for building web apps in 2025",
|
| 62 |
+
followUps: [
|
| 63 |
+
{
|
| 64 |
+
title: "Performance benchmarks",
|
| 65 |
+
prompt: "Search for recent performance benchmarks comparing these frameworks",
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
title: "Job market",
|
| 69 |
+
prompt: "Search for job market trends for each of these frameworks",
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
title: "Migration guides",
|
| 73 |
+
prompt: "Search for guides on migrating from React to Svelte",
|
| 74 |
+
},
|
| 75 |
+
],
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
title: "Find a dataset",
|
| 79 |
+
prompt: "Find datasets on Hugging Face for training a sentiment analysis model",
|
| 80 |
+
followUps: [
|
| 81 |
+
{
|
| 82 |
+
title: "Dataset details",
|
| 83 |
+
prompt: "Tell me more about the largest dataset - its size, format, and how to load it",
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
title: "Find models",
|
| 87 |
+
prompt: "Find pre-trained models that were trained on this dataset",
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
title: "Code snippet",
|
| 91 |
+
prompt: "Show me how to load and preprocess this dataset with the datasets library",
|
| 92 |
+
},
|
| 93 |
+
],
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
title: "Gift ideas",
|
| 97 |
+
prompt: "Search for unique gift ideas for someone who loves cooking",
|
| 98 |
+
followUps: [
|
| 99 |
+
{
|
| 100 |
+
title: "Budget options",
|
| 101 |
+
prompt: "Search for gift ideas under $50",
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
title: "Top rated",
|
| 105 |
+
prompt: "Search for the top-rated cooking gadgets of this year",
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
title: "DIY gifts",
|
| 109 |
+
prompt: "Search for homemade gift ideas for cooking enthusiasts",
|
| 110 |
+
},
|
| 111 |
+
],
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
title: "Learn something new",
|
| 115 |
+
prompt: "Search for the best resources to learn Rust programming in 2025",
|
| 116 |
+
followUps: [
|
| 117 |
+
{
|
| 118 |
+
title: "Project ideas",
|
| 119 |
+
prompt: "Search for beginner Rust project ideas to practice with",
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
title: "Find tools",
|
| 123 |
+
prompt: "Search for the most popular Rust tools and libraries I should know about",
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
title: "Community",
|
| 127 |
+
prompt: "Search for Rust communities and forums where I can ask questions",
|
| 128 |
+
},
|
| 129 |
+
],
|
| 130 |
+
},
|
| 131 |
+
];
|
src/lib/stores/mcpServers.ts
CHANGED
|
@@ -122,6 +122,15 @@ export const enabledServers = derived([allMcpServers, selectedServerIds], ([$all
|
|
| 122 |
// Derived store: count of enabled servers
|
| 123 |
export const enabledServersCount = derived(enabledServers, ($enabled) => $enabled.length);
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
// Note: Authorization overlay (with user's HF token) for the Hugging Face MCP host
|
| 126 |
// is applied server-side when enabled via MCP_FORWARD_HF_USER_TOKEN.
|
| 127 |
|
|
|
|
| 122 |
// Derived store: count of enabled servers
|
| 123 |
export const enabledServersCount = derived(enabledServers, ($enabled) => $enabled.length);
|
| 124 |
|
| 125 |
+
// Derived store: true if all base servers are enabled
|
| 126 |
+
export const allBaseServersEnabled = derived(
|
| 127 |
+
[allMcpServers, selectedServerIds],
|
| 128 |
+
([$all, $selected]) => {
|
| 129 |
+
const baseServers = $all.filter((s) => s.type === "base");
|
| 130 |
+
return baseServers.length > 0 && baseServers.every((s) => $selected.has(s.id));
|
| 131 |
+
}
|
| 132 |
+
);
|
| 133 |
+
|
| 134 |
// Note: Authorization overlay (with user's HF token) for the Hugging Face MCP host
|
| 135 |
// is applied server-side when enabled via MCP_FORWARD_HF_USER_TOKEN.
|
| 136 |
|