refac
This commit is contained in:
1 parent
e61bcc8500
commit
591e0aafa1
4 files changed
+141
-120
No files matched your search
@@ -360,18 +360,21 @@ class KnowledgeTable:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Apply filename / content search
|
# Apply filename / content search
|
||||||
# Use ->> (as_string) instead of CAST(-> AS TEXT) to avoid
|
|
||||||
# PostgreSQL "invalid memory alloc request size" on large
|
|
||||||
# extracted-content rows (#24670).
|
|
||||||
content_text = File.data['content'].as_string()
|
|
||||||
search_filter = None
|
search_filter = None
|
||||||
if filter:
|
if filter:
|
||||||
q = filter.get('query')
|
q = filter.get('query')
|
||||||
if q:
|
if q:
|
||||||
search_filter = or_(
|
if filter.get('include_content'):
|
||||||
File.filename.ilike(f'%{q}%'),
|
# Use ->> (as_string) instead of CAST(-> AS TEXT)
|
||||||
content_text.ilike(f'%{q}%'),
|
# to avoid PostgreSQL "invalid memory alloc request
|
||||||
)
|
# size" on large extracted-content rows (#24670).
|
||||||
|
content_text = File.data['content'].as_string()
|
||||||
|
search_filter = or_(
|
||||||
|
File.filename.ilike(f'%{q}%'),
|
||||||
|
content_text.ilike(f'%{q}%'),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
search_filter = File.filename.ilike(f'%{q}%')
|
||||||
stmt = stmt.filter(search_filter)
|
stmt = stmt.filter(search_filter)
|
||||||
|
|
||||||
# Order by file changes
|
# Order by file changes
|
||||||
@@ -546,16 +549,19 @@ class KnowledgeTable:
|
|||||||
if filter:
|
if filter:
|
||||||
query_key = filter.get('query')
|
query_key = filter.get('query')
|
||||||
if query_key:
|
if query_key:
|
||||||
# Use ->> (as_string) instead of CAST(-> AS TEXT) to
|
if filter.get('include_content'):
|
||||||
# avoid PostgreSQL memory allocation failures on large
|
# Use ->> (as_string) instead of CAST(-> AS TEXT)
|
||||||
# content (#24670).
|
# to avoid PostgreSQL memory allocation failures on
|
||||||
content_text = File.data['content'].as_string()
|
# large content (#24670).
|
||||||
stmt = stmt.filter(
|
content_text = File.data['content'].as_string()
|
||||||
or_(
|
stmt = stmt.filter(
|
||||||
File.filename.ilike(f'%{query_key}%'),
|
or_(
|
||||||
content_text.ilike(f'%{query_key}%'),
|
File.filename.ilike(f'%{query_key}%'),
|
||||||
|
content_text.ilike(f'%{query_key}%'),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
else:
|
||||||
|
stmt = stmt.filter(File.filename.ilike(f'%{query_key}%'))
|
||||||
|
|
||||||
view_option = filter.get('view_option')
|
view_option = filter.get('view_option')
|
||||||
if view_option == 'created':
|
if view_option == 'created':
|
||||||
@@ -692,7 +698,9 @@ class KnowledgeTable:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def reset_knowledge_by_id(self, id: str, include_directories: bool = True, db: Optional[AsyncSession] = None) -> Optional[KnowledgeModel]:
|
async def reset_knowledge_by_id(
|
||||||
|
self, id: str, include_directories: bool = True, db: Optional[AsyncSession] = None
|
||||||
|
) -> Optional[KnowledgeModel]:
|
||||||
try:
|
try:
|
||||||
async with get_async_db_context(db) as db:
|
async with get_async_db_context(db) as db:
|
||||||
# Delete all knowledge_file entries for this knowledge_id
|
# Delete all knowledge_file entries for this knowledge_id
|
||||||
@@ -819,9 +827,7 @@ class KnowledgeTable:
|
|||||||
) -> list[KnowledgeDirectoryModel]:
|
) -> list[KnowledgeDirectoryModel]:
|
||||||
"""List directories at a given level (parent_id=None for root)."""
|
"""List directories at a given level (parent_id=None for root)."""
|
||||||
async with get_async_db_context(db) as db:
|
async with get_async_db_context(db) as db:
|
||||||
stmt = select(KnowledgeDirectory).filter(
|
stmt = select(KnowledgeDirectory).filter(KnowledgeDirectory.knowledge_id == knowledge_id)
|
||||||
KnowledgeDirectory.knowledge_id == knowledge_id
|
|
||||||
)
|
|
||||||
if parent_id:
|
if parent_id:
|
||||||
stmt = stmt.filter(KnowledgeDirectory.parent_id == parent_id)
|
stmt = stmt.filter(KnowledgeDirectory.parent_id == parent_id)
|
||||||
else:
|
else:
|
||||||
@@ -859,10 +865,7 @@ class KnowledgeTable:
|
|||||||
.join(KnowledgeFile, File.id == KnowledgeFile.file_id)
|
.join(KnowledgeFile, File.id == KnowledgeFile.file_id)
|
||||||
.filter(KnowledgeFile.knowledge_id == knowledge_id)
|
.filter(KnowledgeFile.knowledge_id == knowledge_id)
|
||||||
)
|
)
|
||||||
return [
|
return [(FileModel.model_validate(file), dir_id) for file, dir_id in result.all()]
|
||||||
(FileModel.model_validate(file), dir_id)
|
|
||||||
for file, dir_id in result.all()
|
|
||||||
]
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -870,9 +873,7 @@ class KnowledgeTable:
|
|||||||
self, directory_id: str, db: Optional[AsyncSession] = None
|
self, directory_id: str, db: Optional[AsyncSession] = None
|
||||||
) -> Optional[KnowledgeDirectoryModel]:
|
) -> Optional[KnowledgeDirectoryModel]:
|
||||||
async with get_async_db_context(db) as db:
|
async with get_async_db_context(db) as db:
|
||||||
result = await db.execute(
|
result = await db.execute(select(KnowledgeDirectory).filter_by(id=directory_id))
|
||||||
select(KnowledgeDirectory).filter_by(id=directory_id)
|
|
||||||
)
|
|
||||||
directory = result.scalars().first()
|
directory = result.scalars().first()
|
||||||
return KnowledgeDirectoryModel.model_validate(directory) if directory else None
|
return KnowledgeDirectoryModel.model_validate(directory) if directory else None
|
||||||
|
|
||||||
@@ -892,9 +893,7 @@ class KnowledgeTable:
|
|||||||
|
|
||||||
while current_id and current_id not in seen:
|
while current_id and current_id not in seen:
|
||||||
seen.add(current_id)
|
seen.add(current_id)
|
||||||
result = await db.execute(
|
result = await db.execute(select(KnowledgeDirectory).filter_by(id=current_id))
|
||||||
select(KnowledgeDirectory).filter_by(id=current_id)
|
|
||||||
)
|
|
||||||
directory = result.scalars().first()
|
directory = result.scalars().first()
|
||||||
if not directory:
|
if not directory:
|
||||||
break
|
break
|
||||||
@@ -913,9 +912,7 @@ class KnowledgeTable:
|
|||||||
async with get_async_db_context(db) as db:
|
async with get_async_db_context(db) as db:
|
||||||
try:
|
try:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
update(KnowledgeDirectory)
|
update(KnowledgeDirectory).filter_by(id=directory_id).values(name=name, updated_at=int(time.time()))
|
||||||
.filter_by(id=directory_id)
|
|
||||||
.values(name=name, updated_at=int(time.time()))
|
|
||||||
)
|
)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
return await self.get_directory_by_id(directory_id, db=db)
|
return await self.get_directory_by_id(directory_id, db=db)
|
||||||
@@ -941,9 +938,7 @@ class KnowledgeTable:
|
|||||||
if current == directory_id:
|
if current == directory_id:
|
||||||
return None # Would create a cycle
|
return None # Would create a cycle
|
||||||
seen.add(current)
|
seen.add(current)
|
||||||
result = await db.execute(
|
result = await db.execute(select(KnowledgeDirectory.parent_id).filter_by(id=current))
|
||||||
select(KnowledgeDirectory.parent_id).filter_by(id=current)
|
|
||||||
)
|
|
||||||
row = result.first()
|
row = result.first()
|
||||||
current = row[0] if row else None
|
current = row[0] if row else None
|
||||||
|
|
||||||
@@ -991,9 +986,7 @@ class KnowledgeTable:
|
|||||||
async with get_async_db_context(db) as db:
|
async with get_async_db_context(db) as db:
|
||||||
try:
|
try:
|
||||||
# Get the directory to find its parent
|
# Get the directory to find its parent
|
||||||
result = await db.execute(
|
result = await db.execute(select(KnowledgeDirectory).filter_by(id=directory_id))
|
||||||
select(KnowledgeDirectory).filter_by(id=directory_id)
|
|
||||||
)
|
|
||||||
directory = result.scalars().first()
|
directory = result.scalars().first()
|
||||||
if not directory:
|
if not directory:
|
||||||
return False
|
return False
|
||||||
@@ -1003,9 +996,7 @@ class KnowledgeTable:
|
|||||||
if move_files_to_parent:
|
if move_files_to_parent:
|
||||||
# Move files in this directory to its parent (or root)
|
# Move files in this directory to its parent (or root)
|
||||||
await db.execute(
|
await db.execute(
|
||||||
update(KnowledgeFile)
|
update(KnowledgeFile).filter_by(directory_id=directory_id).values(directory_id=parent_id)
|
||||||
.filter_by(directory_id=directory_id)
|
|
||||||
.values(directory_id=parent_id)
|
|
||||||
)
|
)
|
||||||
# Recursively move files from all subdirectories too
|
# Recursively move files from all subdirectories too
|
||||||
await self._move_files_from_subtree(directory_id, parent_id, db=db)
|
await self._move_files_from_subtree(directory_id, parent_id, db=db)
|
||||||
@@ -1014,9 +1005,7 @@ class KnowledgeTable:
|
|||||||
await self._delete_files_in_subtree(directory_id, db=db)
|
await self._delete_files_in_subtree(directory_id, db=db)
|
||||||
|
|
||||||
# CASCADE on parent_id will handle deleting subdirectories
|
# CASCADE on parent_id will handle deleting subdirectories
|
||||||
await db.execute(
|
await db.execute(delete(KnowledgeDirectory).filter_by(id=directory_id))
|
||||||
delete(KnowledgeDirectory).filter_by(id=directory_id)
|
|
||||||
)
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1030,16 +1019,12 @@ class KnowledgeTable:
|
|||||||
db: AsyncSession,
|
db: AsyncSession,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Recursively move all files from a directory subtree to the target."""
|
"""Recursively move all files from a directory subtree to the target."""
|
||||||
result = await db.execute(
|
result = await db.execute(select(KnowledgeDirectory.id).filter_by(parent_id=directory_id))
|
||||||
select(KnowledgeDirectory.id).filter_by(parent_id=directory_id)
|
|
||||||
)
|
|
||||||
child_ids = [row[0] for row in result.all()]
|
child_ids = [row[0] for row in result.all()]
|
||||||
|
|
||||||
for child_id in child_ids:
|
for child_id in child_ids:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
update(KnowledgeFile)
|
update(KnowledgeFile).filter_by(directory_id=child_id).values(directory_id=target_directory_id)
|
||||||
.filter_by(directory_id=child_id)
|
|
||||||
.values(directory_id=target_directory_id)
|
|
||||||
)
|
)
|
||||||
await self._move_files_from_subtree(child_id, target_directory_id, db=db)
|
await self._move_files_from_subtree(child_id, target_directory_id, db=db)
|
||||||
|
|
||||||
@@ -1049,12 +1034,8 @@ class KnowledgeTable:
|
|||||||
db: AsyncSession,
|
db: AsyncSession,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Recursively delete all files from a directory subtree."""
|
"""Recursively delete all files from a directory subtree."""
|
||||||
await db.execute(
|
await db.execute(delete(KnowledgeFile).filter_by(directory_id=directory_id))
|
||||||
delete(KnowledgeFile).filter_by(directory_id=directory_id)
|
result = await db.execute(select(KnowledgeDirectory.id).filter_by(parent_id=directory_id))
|
||||||
)
|
|
||||||
result = await db.execute(
|
|
||||||
select(KnowledgeDirectory.id).filter_by(parent_id=directory_id)
|
|
||||||
)
|
|
||||||
child_ids = [row[0] for row in result.all()]
|
child_ids = [row[0] for row in result.all()]
|
||||||
for child_id in child_ids:
|
for child_id in child_ids:
|
||||||
await self._delete_files_in_subtree(child_id, db=db)
|
await self._delete_files_in_subtree(child_id, db=db)
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ async def search_knowledge_bases(
|
|||||||
@router.get('/search/files', response_model=KnowledgeFileListResponse)
|
@router.get('/search/files', response_model=KnowledgeFileListResponse)
|
||||||
async def search_knowledge_files(
|
async def search_knowledge_files(
|
||||||
query: str | None = None,
|
query: str | None = None,
|
||||||
|
include_content: bool = Query(False, description='Include file content in search (expensive).'),
|
||||||
page: int | None = 1,
|
page: int | None = 1,
|
||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
db: AsyncSession = Depends(get_async_session),
|
db: AsyncSession = Depends(get_async_session),
|
||||||
@@ -228,6 +229,8 @@ async def search_knowledge_files(
|
|||||||
filter = {}
|
filter = {}
|
||||||
if query:
|
if query:
|
||||||
filter['query'] = query
|
filter['query'] = query
|
||||||
|
if include_content:
|
||||||
|
filter['include_content'] = True
|
||||||
|
|
||||||
groups = await Groups.get_groups_by_member_id(user.id, db=db)
|
groups = await Groups.get_groups_by_member_id(user.id, db=db)
|
||||||
if groups:
|
if groups:
|
||||||
@@ -558,6 +561,7 @@ async def update_knowledge_access_by_id(
|
|||||||
async def get_knowledge_files_by_id(
|
async def get_knowledge_files_by_id(
|
||||||
id: str,
|
id: str,
|
||||||
query: str | None = None,
|
query: str | None = None,
|
||||||
|
include_content: bool = Query(False, description='Include file content in search (expensive).'),
|
||||||
view_option: str | None = None,
|
view_option: str | None = None,
|
||||||
order_by: str | None = None,
|
order_by: str | None = None,
|
||||||
direction: str | None = None,
|
direction: str | None = None,
|
||||||
@@ -602,6 +606,8 @@ async def get_knowledge_files_by_id(
|
|||||||
filter = {}
|
filter = {}
|
||||||
if query:
|
if query:
|
||||||
filter['query'] = query
|
filter['query'] = query
|
||||||
|
if include_content:
|
||||||
|
filter['include_content'] = True
|
||||||
if view_option:
|
if view_option:
|
||||||
filter['view_option'] = view_option
|
filter['view_option'] = view_option
|
||||||
if order_by:
|
if order_by:
|
||||||
@@ -996,9 +1002,9 @@ async def reset_knowledge_by_id(
|
|||||||
|
|
||||||
|
|
||||||
class FileManifestEntry(BaseModel):
|
class FileManifestEntry(BaseModel):
|
||||||
filename: str # basename: "readme.md"
|
filename: str # basename: "readme.md"
|
||||||
path: str # relative dir: "docs/api" or "" for root
|
path: str # relative dir: "docs/api" or "" for root
|
||||||
checksum: str # SHA-256 of raw bytes
|
checksum: str # SHA-256 of raw bytes
|
||||||
size: int
|
size: int
|
||||||
|
|
||||||
|
|
||||||
@@ -1007,13 +1013,13 @@ class SyncDiffForm(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class SyncDiffResponse(BaseModel):
|
class SyncDiffResponse(BaseModel):
|
||||||
added: list[dict] # [{filename, path}] — new files
|
added: list[dict] # [{filename, path}] — new files
|
||||||
modified: list[dict] # [{filename, path, stale_file_id}] — changed files
|
modified: list[dict] # [{filename, path, stale_file_id}] — changed files
|
||||||
deleted: list[dict] # [{file_id, filename}] — files to remove
|
deleted: list[dict] # [{file_id, filename}] — files to remove
|
||||||
mkdir: list[str] # directory paths to create
|
mkdir: list[str] # directory paths to create
|
||||||
rmdir: list[str] # directory IDs to remove
|
rmdir: list[str] # directory IDs to remove
|
||||||
unmodified_count: int
|
unmodified_count: int
|
||||||
directory_map: dict[str, str] # existing path → directory ID
|
directory_map: dict[str, str] # existing path → directory ID
|
||||||
|
|
||||||
|
|
||||||
@router.post('/{id}/sync/diff', response_model=SyncDiffResponse)
|
@router.post('/{id}/sync/diff', response_model=SyncDiffResponse)
|
||||||
@@ -1073,11 +1079,13 @@ async def sync_knowledge_diff(
|
|||||||
if key not in indexed_files:
|
if key not in indexed_files:
|
||||||
added.append({'filename': entry.filename, 'path': entry.path})
|
added.append({'filename': entry.filename, 'path': entry.path})
|
||||||
elif indexed_files[key]['checksum'] != entry.checksum:
|
elif indexed_files[key]['checksum'] != entry.checksum:
|
||||||
modified.append({
|
modified.append(
|
||||||
'filename': entry.filename,
|
{
|
||||||
'path': entry.path,
|
'filename': entry.filename,
|
||||||
'stale_file_id': indexed_files[key]['file_id'],
|
'path': entry.path,
|
||||||
})
|
'stale_file_id': indexed_files[key]['file_id'],
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
unmodified_count += 1
|
unmodified_count += 1
|
||||||
|
|
||||||
@@ -1091,12 +1099,9 @@ async def sync_knowledge_diff(
|
|||||||
if entry.path:
|
if entry.path:
|
||||||
segments = entry.path.split('/')
|
segments = entry.path.split('/')
|
||||||
for depth in range(len(segments)):
|
for depth in range(len(segments)):
|
||||||
required_directory_paths.add('/'.join(segments[:depth + 1]))
|
required_directory_paths.add('/'.join(segments[: depth + 1]))
|
||||||
|
|
||||||
mkdir = sorted(
|
mkdir = sorted([p for p in required_directory_paths if p not in directory_id_by_path], key=lambda p: p.count('/'))
|
||||||
[p for p in required_directory_paths if p not in directory_id_by_path],
|
|
||||||
key=lambda p: p.count('/')
|
|
||||||
)
|
|
||||||
|
|
||||||
orphaned_directory_paths = set(directory_id_by_path) - required_directory_paths
|
orphaned_directory_paths = set(directory_id_by_path) - required_directory_paths
|
||||||
rmdir = [directory_id_by_path[p] for p in orphaned_directory_paths]
|
rmdir = [directory_id_by_path[p] for p in orphaned_directory_paths]
|
||||||
@@ -1118,8 +1123,8 @@ async def sync_knowledge_diff(
|
|||||||
|
|
||||||
|
|
||||||
class SyncCleanupForm(BaseModel):
|
class SyncCleanupForm(BaseModel):
|
||||||
file_ids: list[str] # file IDs to delete
|
file_ids: list[str] # file IDs to delete
|
||||||
dir_ids: list[str] = [] # directory IDs to rmdir
|
dir_ids: list[str] = [] # directory IDs to rmdir
|
||||||
|
|
||||||
|
|
||||||
@router.post('/{id}/sync/cleanup')
|
@router.post('/{id}/sync/cleanup')
|
||||||
@@ -1144,12 +1149,8 @@ async def sync_knowledge_cleanup(
|
|||||||
await Knowledges.remove_file_from_knowledge_by_id(id, file_id, db=db)
|
await Knowledges.remove_file_from_knowledge_by_id(id, file_id, db=db)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await ASYNC_VECTOR_DB_CLIENT.delete(
|
await ASYNC_VECTOR_DB_CLIENT.delete(collection_name=id, filter={'file_id': file_id})
|
||||||
collection_name=id, filter={'file_id': file_id}
|
await ASYNC_VECTOR_DB_CLIENT.delete(collection_name=id, filter={'hash': file.hash})
|
||||||
)
|
|
||||||
await ASYNC_VECTOR_DB_CLIENT.delete(
|
|
||||||
collection_name=id, filter={'hash': file.hash}
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -1342,9 +1343,7 @@ class KnowledgeFileMoveForm(BaseModel):
|
|||||||
directory_id: Optional[str] = None
|
directory_id: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
async def _verify_knowledge_write_access(
|
async def _verify_knowledge_write_access(id: str, user, db: AsyncSession):
|
||||||
id: str, user, db: AsyncSession
|
|
||||||
):
|
|
||||||
"""Verify the user has write access to the knowledge base. Returns the knowledge model."""
|
"""Verify the user has write access to the knowledge base. Returns the knowledge model."""
|
||||||
knowledge = await Knowledges.get_knowledge_by_id(id=id, db=db)
|
knowledge = await Knowledges.get_knowledge_by_id(id=id, db=db)
|
||||||
if not knowledge:
|
if not knowledge:
|
||||||
@@ -1494,4 +1493,3 @@ async def move_file_in_knowledge(
|
|||||||
detail='Failed to move file.',
|
detail='Failed to move file.',
|
||||||
)
|
)
|
||||||
return {'status': True}
|
return {'status': True}
|
||||||
|
|
||||||
@@ -115,11 +115,12 @@ export const searchKnowledgeBases = async (
|
|||||||
|
|
||||||
export const searchKnowledgeFiles = async (
|
export const searchKnowledgeFiles = async (
|
||||||
token: string,
|
token: string,
|
||||||
query?: string | null = null,
|
query?: string | null,
|
||||||
viewOption?: string | null = null,
|
viewOption?: string | null,
|
||||||
orderBy?: string | null = null,
|
orderBy?: string | null,
|
||||||
direction?: string | null = null,
|
direction?: string | null,
|
||||||
page: number = 1
|
page: number = 1,
|
||||||
|
includeContent: boolean = false
|
||||||
) => {
|
) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
@@ -129,6 +130,7 @@ export const searchKnowledgeFiles = async (
|
|||||||
if (orderBy) searchParams.append('order_by', orderBy);
|
if (orderBy) searchParams.append('order_by', orderBy);
|
||||||
if (direction) searchParams.append('direction', direction);
|
if (direction) searchParams.append('direction', direction);
|
||||||
searchParams.append('page', page.toString());
|
searchParams.append('page', page.toString());
|
||||||
|
if (includeContent) searchParams.append('include_content', 'true');
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${WEBUI_API_BASE_URL}/knowledge/search/files?${searchParams.toString()}`,
|
`${WEBUI_API_BASE_URL}/knowledge/search/files?${searchParams.toString()}`,
|
||||||
@@ -197,12 +199,13 @@ export const getKnowledgeById = async (token: string, id: string) => {
|
|||||||
export const searchKnowledgeFilesById = async (
|
export const searchKnowledgeFilesById = async (
|
||||||
token: string,
|
token: string,
|
||||||
id: string,
|
id: string,
|
||||||
query?: string | null = null,
|
query?: string | null,
|
||||||
viewOption?: string | null = null,
|
viewOption?: string | null,
|
||||||
orderBy?: string | null = null,
|
orderBy?: string | null,
|
||||||
direction?: string | null = null,
|
direction?: string | null,
|
||||||
page: number = 1,
|
page: number = 1,
|
||||||
directoryId?: string | null = undefined
|
directoryId?: string | null,
|
||||||
|
includeContent: boolean = false
|
||||||
) => {
|
) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
@@ -216,6 +219,7 @@ export const searchKnowledgeFilesById = async (
|
|||||||
if (directoryId !== undefined) {
|
if (directoryId !== undefined) {
|
||||||
searchParams.append('directory_id', directoryId ?? '');
|
searchParams.append('directory_id', directoryId ?? '');
|
||||||
}
|
}
|
||||||
|
if (includeContent) searchParams.append('include_content', 'true');
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${WEBUI_API_BASE_URL}/knowledge/${id}/files?${searchParams.toString()}`,
|
`${WEBUI_API_BASE_URL}/knowledge/${id}/files?${searchParams.toString()}`,
|
||||||
@@ -546,7 +550,6 @@ export const syncKnowledgeCleanup = async (
|
|||||||
export const deleteKnowledgeById = async (token: string, id: string) => {
|
export const deleteKnowledgeById = async (token: string, id: string) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
|
|
||||||
const res = await fetch(`${WEBUI_API_BASE_URL}/knowledge/${id}/delete`, {
|
const res = await fetch(`${WEBUI_API_BASE_URL}/knowledge/${id}/delete`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -65,6 +65,9 @@
|
|||||||
import Search from '$lib/components/icons/Search.svelte';
|
import Search from '$lib/components/icons/Search.svelte';
|
||||||
import FilesOverlay from '$lib/components/chat/MessageInput/FilesOverlay.svelte';
|
import FilesOverlay from '$lib/components/chat/MessageInput/FilesOverlay.svelte';
|
||||||
import DropdownOptions from '$lib/components/common/DropdownOptions.svelte';
|
import DropdownOptions from '$lib/components/common/DropdownOptions.svelte';
|
||||||
|
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||||
|
import Checkbox from '$lib/components/common/Checkbox.svelte';
|
||||||
|
import AdjustmentsHorizontal from '$lib/components/icons/AdjustmentsHorizontal.svelte';
|
||||||
import Pagination from '$lib/components/common/Pagination.svelte';
|
import Pagination from '$lib/components/common/Pagination.svelte';
|
||||||
import AttachWebpageModal from '$lib/components/chat/MessageInput/AttachWebpageModal.svelte';
|
import AttachWebpageModal from '$lib/components/chat/MessageInput/AttachWebpageModal.svelte';
|
||||||
|
|
||||||
@@ -107,6 +110,7 @@
|
|||||||
let inputFiles = null;
|
let inputFiles = null;
|
||||||
|
|
||||||
let query = '';
|
let query = '';
|
||||||
|
let includeContent = false;
|
||||||
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
let searchDebounceTimer: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
let viewOption = null;
|
let viewOption = null;
|
||||||
@@ -150,7 +154,8 @@
|
|||||||
viewOption !== undefined &&
|
viewOption !== undefined &&
|
||||||
sortKey !== undefined &&
|
sortKey !== undefined &&
|
||||||
direction !== undefined &&
|
direction !== undefined &&
|
||||||
currentPage !== undefined
|
currentPage !== undefined &&
|
||||||
|
includeContent !== undefined
|
||||||
) {
|
) {
|
||||||
getItemsPage();
|
getItemsPage();
|
||||||
}
|
}
|
||||||
@@ -182,7 +187,8 @@
|
|||||||
sortKey,
|
sortKey,
|
||||||
direction,
|
direction,
|
||||||
currentPage,
|
currentPage,
|
||||||
currentDirectoryId
|
currentDirectoryId,
|
||||||
|
includeContent
|
||||||
).catch(() => {
|
).catch(() => {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -1272,6 +1278,37 @@
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Dropdown align="end">
|
||||||
|
<button
|
||||||
|
class="p-1.5 mr-1 rounded-xl text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800 transition"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<AdjustmentsHorizontal className="size-3.5" strokeWidth="2" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div slot="content">
|
||||||
|
<div
|
||||||
|
class="min-w-[180px] rounded-2xl px-1 py-1 border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class="select-none flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl w-full"
|
||||||
|
type="button"
|
||||||
|
on:click={() => {
|
||||||
|
includeContent = !includeContent;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
state={includeContent ? 'checked' : 'unchecked'}
|
||||||
|
on:change={(e) => {
|
||||||
|
includeContent = e.detail === 'checked';
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{$i18n.t('File content')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Dropdown>
|
||||||
|
|
||||||
{#if knowledge?.write_access}
|
{#if knowledge?.write_access}
|
||||||
<div>
|
<div>
|
||||||
<AddContentMenu
|
<AddContentMenu
|
||||||
@@ -1293,28 +1330,16 @@
|
|||||||
if (pendingSyncFiles?.length) {
|
if (pendingSyncFiles?.length) {
|
||||||
showSyncConfirmModal = true;
|
showSyncConfirmModal = true;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onReset={() => {
|
onReset={() => {
|
||||||
showResetConfirm = true;
|
showResetConfirm = true;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if currentDirectoryId !== null}
|
|
||||||
<div class="px-5 -mt-1 pb-2">
|
|
||||||
<KnowledgeBreadcrumbs
|
|
||||||
rootLabel={knowledge.name}
|
|
||||||
{breadcrumbs}
|
|
||||||
onNavigate={(dirId) => navigateToDirectory(dirId)}
|
|
||||||
onMoveFile={(fileId, dirId) => moveFileToDirectoryHandler(fileId, dirId)}
|
|
||||||
onMoveDir={(dirId, targetId) => moveDirectoryHandler(dirId, targetId)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="px-3 flex justify-between">
|
<div class="px-3 flex justify-between">
|
||||||
<div
|
<div
|
||||||
class="flex w-full bg-transparent overflow-x-auto scrollbar-none"
|
class="flex w-full bg-transparent overflow-x-auto scrollbar-none"
|
||||||
@@ -1371,6 +1396,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if currentDirectoryId !== null}
|
||||||
|
<div class="px-5 mt-1 pb-1">
|
||||||
|
<KnowledgeBreadcrumbs
|
||||||
|
rootLabel={knowledge.name}
|
||||||
|
{breadcrumbs}
|
||||||
|
onNavigate={(dirId) => navigateToDirectory(dirId)}
|
||||||
|
onMoveFile={(fileId, dirId) => moveFileToDirectoryHandler(fileId, dirId)}
|
||||||
|
onMoveDir={(dirId, targetId) => moveDirectoryHandler(dirId, targetId)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if syncing}
|
{#if syncing}
|
||||||
<div class="mx-2.5 mt-2.5 -mb-0.5">
|
<div class="mx-2.5 mt-2.5 -mb-0.5">
|
||||||
<div class="flex items-center gap-2.5 rounded-xl py-2 px-3 bg-gray-50 dark:bg-gray-850">
|
<div class="flex items-center gap-2.5 rounded-xl py-2 px-3 bg-gray-50 dark:bg-gray-850">
|
||||||
@@ -1543,6 +1580,8 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="text-sm text-gray-700 dark:text-gray-300 flex-1 line-clamp-3">
|
<div class="text-sm text-gray-700 dark:text-gray-300 flex-1 line-clamp-3">
|
||||||
{$i18n.t('This will remove all files and directories from this knowledge base. This action cannot be undone.')}
|
{$i18n.t(
|
||||||
|
'This will remove all files and directories from this knowledge base. This action cannot be undone.'
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ConfirmDialog>
|
</ConfirmDialog>
|
||||||
Reference in new issue
Block a user