mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-06 02:48:04 +00:00
feat(chat): support folder, note, and model drag-and-drop from sidebar as context references
This commit is contained in:
parent
43523b4481
commit
734b653f10
3 changed files with 65 additions and 1 deletions
|
|
@ -57,6 +57,8 @@
|
|||
import { generateAutoCompletion } from '$lib/apis';
|
||||
import { deleteFileById } from '$lib/apis/files';
|
||||
import { getChatById } from '$lib/apis/chats';
|
||||
import { getFolderById } from '$lib/apis/folders';
|
||||
import { getNoteById } from '$lib/apis/notes';
|
||||
import { getSessionUser } from '$lib/apis/auths';
|
||||
|
||||
import { WEBUI_BASE_URL, WEBUI_API_BASE_URL, PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
|
||||
|
|
@ -855,7 +857,7 @@
|
|||
e.preventDefault();
|
||||
console.log(e);
|
||||
|
||||
// Check if the dropped data is a sidebar chat item
|
||||
// Check if the dropped data is a sidebar chat, folder, note, or model item
|
||||
const textData = e.dataTransfer?.getData('text/plain');
|
||||
if (textData) {
|
||||
try {
|
||||
|
|
@ -878,6 +880,49 @@
|
|||
dragged = false;
|
||||
e.stopPropagation();
|
||||
return;
|
||||
} else if (data.type === 'folder' && data.id) {
|
||||
// Fetch the folder to get its name, then add as a reference folder
|
||||
const folder = await getFolderById(localStorage.token, data.id);
|
||||
if (folder) {
|
||||
const folderItem = {
|
||||
type: 'folder',
|
||||
id: folder.id,
|
||||
name: folder.name,
|
||||
status: 'processed'
|
||||
};
|
||||
if (!files.find((f) => f.id === folderItem.id)) {
|
||||
files = [...files, folderItem];
|
||||
}
|
||||
}
|
||||
dragged = false;
|
||||
e.stopPropagation();
|
||||
return;
|
||||
} else if (data.type === 'note' && data.id) {
|
||||
// Fetch the note to get its title, then add as a reference note
|
||||
const note = await getNoteById(localStorage.token, data.id);
|
||||
if (note) {
|
||||
const noteItem = {
|
||||
type: 'note',
|
||||
id: note.id,
|
||||
name: note.title,
|
||||
status: 'processed'
|
||||
};
|
||||
if (!files.find((f) => f.id === noteItem.id)) {
|
||||
files = [...files, noteItem];
|
||||
}
|
||||
}
|
||||
dragged = false;
|
||||
e.stopPropagation();
|
||||
return;
|
||||
} else if (data.type === 'model' && data.id) {
|
||||
// Find the model from the store and set as @-selected model
|
||||
const model = $models.find((m) => m.id === data.id);
|
||||
if (model) {
|
||||
atSelectedModel = model;
|
||||
}
|
||||
dragged = false;
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
// Not valid JSON — fall through to file handling
|
||||
|
|
|
|||
|
|
@ -18,6 +18,15 @@
|
|||
if (pinnedModelsList && !$mobile) {
|
||||
new Sortable(pinnedModelsList, {
|
||||
animation: 150,
|
||||
setData: function (dataTransfer, dragEl) {
|
||||
dataTransfer.setData(
|
||||
'text/plain',
|
||||
JSON.stringify({
|
||||
type: 'model',
|
||||
id: dragEl.dataset.id
|
||||
})
|
||||
);
|
||||
},
|
||||
onUpdate: async (event) => {
|
||||
const modelId = event.item.dataset.id;
|
||||
const newIndex = event.newIndex;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,16 @@
|
|||
<div
|
||||
class="flex items-center text-gray-800 dark:text-gray-200 cursor-grab relative group rounded-xl px-2.5 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-900 transition"
|
||||
data-id={note.id}
|
||||
draggable="true"
|
||||
on:dragstart={(e) => {
|
||||
e.dataTransfer.setData(
|
||||
'text/plain',
|
||||
JSON.stringify({
|
||||
type: 'note',
|
||||
id: note.id
|
||||
})
|
||||
);
|
||||
}}
|
||||
>
|
||||
<a
|
||||
class="grow flex items-center gap-2.5 text-sm"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue