-
Notifications
You must be signed in to change notification settings - Fork 19
feat: integrate RAG environment selection in chat window #1227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <script lang="ts"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { faBook } from '@fortawesome/free-solid-svg-icons/faBook'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Fa from 'svelte-fa'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { cn } from '/@/lib/chat/utils/shadcn'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ragEnvironments } from '/@/stores/rag-environments'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { RagEnvironment } from '/@api/rag/rag-environment'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import CheckCircleFillIcon from './icons/check-circle-fill.svelte'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ChevronDownIcon from './icons/chevron-down.svelte'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Button } from './ui/button'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenu, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenuContent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenuGroup, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenuItem, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenuLabel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenuSeparator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownMenuTrigger, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from './ui/dropdown-menu'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface Props { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| open?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelect: (env: RagEnvironment | undefined) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let { class: className, disabled = false, open = $bindable(false), onSelect }: Props = $props(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Filter RAG environments to only show those with an MCP server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ragEnvironmentsWithMCP = $derived($ragEnvironments.filter(env => env.mcpServer !== undefined)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let selected = $state<RagEnvironment | undefined>(undefined); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const selectedText = $derived(selected?.name ?? 'No Knowledge Base'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function onSelectRagEnvironment(env: RagEnvironment | undefined, event: Event): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event.preventDefault(); // prevent dropdown from closing itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelect(env); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selected = env; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| open = false; // close the dropdown after selection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reset invalid selection when RAG environments change. Line 34-43 keeps Proposed fix let selected = $state<RagEnvironment | undefined>(undefined);
const selectedText = $derived(selected?.name ?? 'No Knowledge Base');
+
+$effect(() => {
+ if (!selected) return;
+ const stillAvailable = ragEnvironmentsWithMCP.some(
+ env =>
+ env.name === selected.name &&
+ env.ragConnection.providerId === selected.ragConnection.providerId &&
+ env.ragConnection.name === selected.ragConnection.name,
+ );
+ if (!stillAvailable) {
+ selected = undefined;
+ onSelect(undefined);
+ }
+});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenu {open} onOpenChange={(val): boolean => (open = val)}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuTrigger> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {#snippet child({ props })} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...props} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-label="Select knowledge base" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| variant="outline" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {disabled} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class={cn('data-[state=open]:bg-accent data-[state=open]:text-accent-foreground w-fit md:h-[34px] md:px-2', className)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Fa icon={faBook} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {selectedText} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChevronDownIcon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/snippet} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuTrigger> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuContent align="start" class="min-w-[300px]"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuLabel> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="flex flex-col gap-1"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="font-semibold">Select Knowledge Base</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="text-xs font-normal text-muted-foreground">Choose a knowledge environment to enhance your chat</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuLabel> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuSeparator /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {#if ragEnvironmentsWithMCP.length === 0} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuItem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="group/item flex flex-row items-center justify-between gap-4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No RAG environments with MCP available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuItem> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {:else} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuGroup> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <!-- No Knowledge Base option --> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuItem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelect={onSelectRagEnvironment.bind(undefined, undefined)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="group/item flex flex-row items-center justify-between gap-4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data-active={selected === undefined} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="flex flex-col items-start gap-1"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="font-medium">No Knowledge Base</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="text-xs text-muted-foreground">Chat without RAG enhancement</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="text-foreground dark:text-foreground opacity-0 group-data-[active=true]/item:opacity-100" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <CheckCircleFillIcon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuItem> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuSeparator /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <!-- RAG Environment options --> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {#each ragEnvironmentsWithMCP as ragEnv (ragEnv.name)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DropdownMenuItem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSelect={onSelectRagEnvironment.bind(undefined, ragEnv)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="group/item flex flex-row items-center justify-between gap-4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data-active={selected?.name === ragEnv.name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="flex flex-col items-start gap-1"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="font-medium">{ragEnv.name}</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="text-xs text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {ragEnv.ragConnection.providerId} • {ragEnv.files.length} sources | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class="text-foreground dark:text-foreground opacity-0 group-data-[active=true]/item:opacity-100" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <CheckCircleFillIcon /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuItem> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/each} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuGroup> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenuContent> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </DropdownMenu> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the selected RAG MCP payload as fallback when syncing tools.
At Line 87-90, selection is applied only if the server is found in
$mcpRemoteServerInfos. If that store is temporarily stale/empty, selecting a RAG environment silently does nothing and tool count won’t update.Proposed fix
function onMCPServerAdd(mcpServer: MCPRemoteServerInfo): void { - const server = $mcpRemoteServerInfos.find(r => r.id === mcpServer.id); - if (server) { - selectedMCPTools.set(mcpServer.id, new SvelteSet(Object.keys(server.tools))); - } + const server = $mcpRemoteServerInfos.find(r => r.id === mcpServer.id) ?? mcpServer; + selectedMCPTools.set(mcpServer.id, new SvelteSet(Object.keys(server.tools))); }📝 Committable suggestion
🤖 Prompt for AI Agents