feat: add directory browsing and selection to knowledge pickers#26296
feat: add directory browsing and selection to knowledge pickers#26296silentoplayz wants to merge 1 commit into
Conversation
|
@silentoplayz I've already merged your calendar fix into my fork, please let me know when you've fixed this PR. I would love to merge this into my personal fork. |
This PR isn't broken in any way AFAIK and there aren't any merge conflicts against the |
6b950ef to
278c4c1
Compare
278c4c1 to
a90557e
Compare
|
Notice regarding PR context This pull request does not link to a related issue or discussion. Please add a relevant GitHub issue/discussion reference, such as This pull request has been closed. |
|
Rebased on the latest |
|
Thanks @silentoplayz I'll be sure to grab your changes for my fork. |
… to knowledge pickers This PR adds directory browsing and selection support to all three knowledge picker UIs in Open WebUI, allowing users to navigate into knowledge base directory structures, browse files at each level, and selectively attach individual files or entire directories as context. ## What this PR does ### Core Feature: Directory Browsing in Knowledge Pickers - Adds full directory navigation to the '#' command dropdown, Attach Knowledge (+ button) menu, and model editor knowledge selector - Users can now browse into knowledge base directory structures instead of seeing only a flat list of files - Collections now show a chevron and '+' button; clicking navigates into them - Directories are displayed with folder icons and can be navigated into - Breadcrumb navigation with back arrow allows easy traversal - '+' buttons on directories allow batch selection of all files within ### Files Changed (5): 1. **Commands/Knowledge.svelte** - The '#' command dropdown (most-used picker) - Added browsing state (browsingCollection, currentDirectoryId, etc.) - Added navigation functions (browseIntoCollection, browseIntoDirectory, navigateBack) - Added directory selection (selectDirectory) for batch file attachment - Template now has two modes: top-level flat view vs. browsing view - Collections show chevron and '+' button; clicking navigates in 2. **CommandSuggestionList.svelte** - Handles onSelect callbacks - Added 'knowledge-directory' event type handler - Iterates through resolved files and calls onUpload for each one - Enables batch attachment of entire directory contents 3. **InputMenu/Knowledge.svelte** - The Attach Knowledge (+ button) menu - Now passes currentDirectoryId to scope results - Tracks selectedFileDirectories and selectedFileBreadcrumbs - Renders directories with navigation and selection above file list 4. **Models/Knowledge/KnowledgeSelector.svelte** - Model editor knowledge picker - Same pattern as '#' command dropdown, adapted for Dropdown component - Collections are now browsable with directory navigation - Browsing state resets when dropdown closes 5. **Models/Knowledge.svelte** - Parent wrapper for KnowledgeSelector - Added null guard for selectedItems to prevent TypeError - Handles Svelte 5 runtime prop getter edge case ## Key Design Decisions 1. **No backend changes required**: The searchKnowledgeFilesById API already supports directoryId filtering and returns directories/breadcrumbs 2. **Non-recursive directory selection**: Selecting a directory attaches only files directly within it, not nested subdirectories 3. **Collection click behavior change**: Clicking a collection now navigates into it instead of immediately selecting. Old behavior preserved via '+' button. 4. **All strings wrapped in .t()**: New UI strings are i18n-ready ## Merge Notes - Resolved conflicts in Commands/Knowledge.svelte by integrating PR's directory browsing template with HEAD's styling conventions - PR's directory browsing functionality was cleanly additive, requiring only template-level conflict resolution - All changes are frontend-only with zero new dependencies Closes/Relates to open-webui#27011 PR: open-webui#26296
… to knowledge pickers This PR adds directory browsing and selection support to all three knowledge picker UIs in Open WebUI, allowing users to navigate into knowledge base directory structures, browse files at each level, and selectively attach individual files or entire directories as context. ## What this PR does ### Core Feature: Directory Browsing in Knowledge Pickers - Adds full directory navigation to the '#' command dropdown, Attach Knowledge (+ button) menu, and model editor knowledge selector - Users can now browse into knowledge base directory structures instead of seeing only a flat list of files - Collections now show a chevron and '+' button; clicking navigates into them - Directories are displayed with folder icons and can be navigated into - Breadcrumb navigation with back arrow allows easy traversal - '+' buttons on directories allow batch selection of all files within ### Files Changed (5): 1. **Commands/Knowledge.svelte** - The '#' command dropdown (most-used picker) - Added browsing state (browsingCollection, currentDirectoryId, etc.) - Added navigation functions (browseIntoCollection, browseIntoDirectory, navigateBack) - Added directory selection (selectDirectory) for batch file attachment - Template now has two modes: top-level flat view vs. browsing view - Collections show chevron and '+' button; clicking navigates in 2. **CommandSuggestionList.svelte** - Handles onSelect callbacks - Added 'knowledge-directory' event type handler - Iterates through resolved files and calls onUpload for each one - Enables batch attachment of entire directory contents 3. **InputMenu/Knowledge.svelte** - The Attach Knowledge (+ button) menu - Now passes currentDirectoryId to scope results - Tracks selectedFileDirectories and selectedFileBreadcrumbs - Renders directories with navigation and selection above file list 4. **Models/Knowledge/KnowledgeSelector.svelte** - Model editor knowledge picker - Same pattern as '#' command dropdown, adapted for Dropdown component - Collections are now browsable with directory navigation - Browsing state resets when dropdown closes 5. **Models/Knowledge.svelte** - Parent wrapper for KnowledgeSelector - Added null guard for selectedItems to prevent TypeError - Handles Svelte 5 runtime prop getter edge case ## Key Design Decisions 1. **No backend changes required**: The searchKnowledgeFilesById API already supports directoryId filtering and returns directories/breadcrumbs 2. **Non-recursive directory selection**: Selecting a directory attaches only files directly within it, not nested subdirectories 3. **Collection click behavior change**: Clicking a collection now navigates into it instead of immediately selecting. Old behavior preserved via '+' button. 4. **All strings wrapped in .t()**: New UI strings are i18n-ready ## Merge Notes - Resolved conflicts in Commands/Knowledge.svelte by integrating PR's directory browsing template with HEAD's styling conventions - PR's directory browsing functionality was cleanly additive, requiring only template-level conflict resolution - All changes are frontend-only with zero new dependencies Closes/Relates to open-webui#27011 PR: open-webui#26296
a90557e to
340ffff
Compare
|
This PR has yet again been rebased on the latest |
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR. For bug fixes referencing an existing Issue, linking the Issue is sufficient.
Before submitting, make sure you've checked the following:
Closes #___/Relates to #___. If one does not exist, create one first. PRs without a linked issue or discussion may be closed without review.devbranch. PRs targetingmainwill be immediately closed.dev, and contains no unrelated commits.Summary
Open WebUI supports organizing files within knowledge bases into directories, but this directory structure was invisible in every knowledge picker UI — the
#command dropdown, the Attach Knowledge (+button) menu, and the model editor knowledge selector all displayed a flat list of files. Users had no way to navigate, browse, or select a specific directory when attaching knowledge to a chat or model.This PR surfaces the existing directory structure in all three knowledge picker UIs by leveraging the
searchKnowledgeFilesByIdAPI's existingdirectoryIdparameter — no backend changes required.Why this matters
Approach
The core idea is simple: instead of calling
searchKnowledgeFilesByIdwithout adirectoryId(which returns every file in the KB flat), passdirectoryIdto scope results to a specific level. The API already returnsdirectories,breadcrumbs, anditemsin its response — the frontend was simply ignoring the first two.Each modified component adds:
browsingCollection,currentDirectoryId,browsingBreadcrumbs, etc.) — local component state tracking where the user is navigatingbrowseIntoCollection,browseIntoDirectory,navigateBack) — drive the browsing state and re-fetch scoped resultsselectDirectory) — fetches all files directly in a directory and attaches them individually as chat context+buttons for both "select entire collection" and "select directory"Interaction changes
+button on the right side of the row selects the entire collection+to select all filesFiles Changed (5)
src/lib/components/chat/MessageInput/Commands/Knowledge.svelteThe
#command dropdown — the most-used knowledge picker. Added full browsing state, navigation logic, and a two-mode template (top-level flat view vs. browsing view). Collections now show a chevron and+button; clicking navigates in. The browsing view renders a header with back/breadcrumbs/select-all, then directories grouped above files.src/lib/components/chat/MessageInput/CommandSuggestionList.svelteHandles the
onSelectcallback from the#command Knowledge component. Added a newknowledge-directoryevent type handler that iterates through all resolved files and callsonUploadfor each one — enabling batch attachment of an entire directory's files.src/lib/components/chat/MessageInput/InputMenu/Knowledge.svelteThe Attach Knowledge panel (via
+button). Previously calledsearchKnowledgeFilesByIdwithout adirectoryId, resulting in a flat file dump. Now passescurrentDirectoryIdto scope results, tracksselectedFileDirectoriesandselectedFileBreadcrumbsfrom the response, and renders directories with navigation and selection above the file list within each expanded KB.src/lib/components/workspace/Models/Knowledge/KnowledgeSelector.svelteThe knowledge picker dropdown in the model editor (used for both base and workspace models). Same pattern as the
#command dropdown, adapted for theDropdowncomponent andcreateEventDispatcherpattern. Collections are now browsable; directories appear with navigation and selection. Browsing state resets when the dropdown closes.src/lib/components/workspace/Models/Knowledge.svelteThe parent wrapper that consumes
KnowledgeSelectorevents. Added a null guard (selectedItems ?? []) to theon:selecthandler to preventTypeError: can't access property "find"whenselectDirectorydispatches multipleselectevents — the Svelte 5 runtime's prop getter can returnundefinedbefore the reactive initializer runs.Key design decisions
No backend changes: The
searchKnowledgeFilesByIdAPI already supportsdirectoryIdfiltering and returnsdirectories/breadcrumbsin every response. All changes are frontend-only.Non-recursive directory selection: Selecting a directory attaches only files directly within it, not files in nested subdirectories. This gives users precise control — they can navigate deeper and select subdirectories individually.
Collection click behavior change: Clicking a collection row now navigates into it instead of immediately selecting it. The old "select entire collection" behavior is preserved via a
+button. This tradeoff favors browsability (the common case when you have directories) while keeping immediate selection one click away.All strings wrapped in
$i18n.t(): New user-facing strings ('Directories','This directory is empty.','Select directory','Select collection','Directory') are all i18n-ready.Changelog Entry
Description
#command dropdown, Attach Knowledge menu, model editor knowledge selector), allowing users to navigate into knowledge base directory structures, browse files at each level, and selectively attach individual files or entire directories as contextAdded
#command dropdown with back button, breadcrumb trail, and directory/file listing+button) menu within expanded knowledge basesknowledge-directoryevent type inCommandSuggestionListfor batch file attachment from directory selection+button on collection and directory rows for quick selection without navigating into themFixed
selectedItemsin the model editor knowledge wrapper to preventTypeErrorwhen selecting directories (Svelte 5 runtime prop getter edge case)Additional Information
searchKnowledgeFilesByIdAPI already returneddirectoriesandbreadcrumbsin its response; the frontend was simply not using themFolder,ArrowLeft,ChevronRight,Plus), Tooltip wrapping, and hover/dark-mode styling as the rest of the codebaseScreenshots or Videos
#Command DropdownAttach Knowledge (
+Button) MenuModel Editor Knowledge Selector
Manual Verification Performed
#command dropdown: Typed#in chat input → verified collections show chevron → clicked collection → saw directories and files at root level → navigated into a directory → verified breadcrumbs update → clicked back arrow → returned to root → clicked+on a directory → verified all files in that directory attached to chat → clicked+on header → verified entire collection selected+→ Knowledge → expanded a KB → verified directories appear above files → clicked a directory → navigated in with breadcrumbs → clicked a file → verified it attached → used+on a directory → verified batch attachment+→ verified all files added to model knowledge without errors#dropdown with no behavioral changesContributor License Agreement
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.