feat: Enhance FAQ management and search functionality

- Added a new menu item for searching FAQs directly from the menu, improving user accessibility.
- Implemented batch action options for selected FAQs, allowing users to perform bulk operations such as enabling, disabling, and deleting entries.
- Updated localization strings to support new features and improve user experience across multiple languages.
- Enhanced the handling of FAQ selection changes to dynamically update the UI based on user interactions.
This commit is contained in:
wizardchen
2025-11-23 17:27:30 +08:00
parent 1a3d36f2c1
commit e853605cea
16 changed files with 303 additions and 35 deletions
+75 -9
View File
@@ -758,13 +758,39 @@ const handleDocFolderChange = async (event: Event) => {
return
}
// 检查是否启用了VLM
const vlmEnabled = currentKbInfo.value?.vlm_config?.enabled || false
// 过滤有效文件(文件夹上传始终使用静默模式)
const validFiles: File[] = []
let invalidCount = 0
let hiddenFileCount = 0
let imageFilteredCount = 0
for (let i = 0; i < files.length; i++) {
const file = files[i]
// 文件夹上传时始终静默过滤
const relativePath = (file as any).webkitRelativePath || file.name
// 1. 过滤隐藏文件和隐藏文件夹
// 检查路径中是否包含以 . 开头的文件或文件夹
const pathParts = relativePath.split('/')
const hasHiddenComponent = pathParts.some((part: string) => part.startsWith('.'))
if (hasHiddenComponent) {
hiddenFileCount++
continue
}
// 2. 如果未启用VLM,过滤图片文件
if (!vlmEnabled) {
const fileExt = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
const imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
if (imageTypes.includes(fileExt)) {
imageFilteredCount++
continue
}
}
// 3. 文件类型验证(文件夹上传时始终静默过滤)
if (kbFileTypeVerification(file, true)) {
invalidCount++
} else {
@@ -774,8 +800,19 @@ const handleDocFolderChange = async (event: Event) => {
// 如果没有有效文件,直接返回
if (validFiles.length === 0) {
if (invalidCount > 0) {
MessagePlugin.error(t('knowledgeBase.noValidFilesInFolder', { total: files.length }))
const totalFiltered = invalidCount + hiddenFileCount + imageFilteredCount
if (totalFiltered > 0) {
let filterReasons = []
if (hiddenFileCount > 0) {
filterReasons.push(t('knowledgeBase.hiddenFilesFiltered', { count: hiddenFileCount }))
}
if (imageFilteredCount > 0) {
filterReasons.push(t('knowledgeBase.imagesFilteredNoVLM', { count: imageFilteredCount }))
}
if (invalidCount > 0) {
filterReasons.push(t('knowledgeBase.invalidFilesFiltered', { count: invalidCount }))
}
MessagePlugin.warning(t('knowledgeBase.noValidFilesInFolder', { total: files.length }) + '\n' + filterReasons.join('\n'))
} else {
MessagePlugin.error(t('knowledgeBase.noValidFiles'))
}
@@ -785,11 +822,24 @@ const handleDocFolderChange = async (event: Event) => {
// 显示过滤后的上传提示
const totalCount = validFiles.length
if (invalidCount > 0) {
MessagePlugin.info(t('knowledgeBase.uploadingValidFiles', {
valid: totalCount,
total: files.length
}))
const totalFiltered = invalidCount + hiddenFileCount + imageFilteredCount
if (totalFiltered > 0) {
let filterInfo = []
if (hiddenFileCount > 0) {
filterInfo.push(t('knowledgeBase.hiddenFilesFiltered', { count: hiddenFileCount }))
}
if (imageFilteredCount > 0) {
filterInfo.push(t('knowledgeBase.imagesFilteredNoVLM', { count: imageFilteredCount }))
}
if (invalidCount > 0) {
filterInfo.push(t('knowledgeBase.invalidFilesFiltered', { count: invalidCount }))
}
MessagePlugin.info(
t('knowledgeBase.uploadingValidFiles', {
valid: totalCount,
total: files.length
}) + '\n' + filterInfo.join(', ')
)
} else {
MessagePlugin.info(t('knowledgeBase.uploadingFolder', { total: totalCount }))
}
@@ -801,7 +851,23 @@ const handleDocFolderChange = async (event: Event) => {
for (const file of validFiles) {
try {
await uploadKnowledgeFile(kbId, { file })
// 获取文件的相对路径(webkitRelativePath)
const relativePath = (file as any).webkitRelativePath
let fileName = file.name
// 如果存在相对路径,提取子文件夹路径并拼接到文件名前
if (relativePath) {
// webkitRelativePath 格式: "文件夹名/子文件夹/文件名.ext"
// 我们需要去掉第一层文件夹名,保留子路径
const pathParts = relativePath.split('/')
if (pathParts.length > 2) {
// 有子文件夹,拼接子路径到文件名
const subPath = pathParts.slice(1, -1).join('/') // 去掉顶层文件夹和文件名本身
fileName = `${subPath}/${file.name}`
}
}
await uploadKnowledgeFile(kbId, { file, fileName })
successCount++
} catch (error: any) {
failCount++
+3
View File
@@ -59,6 +59,9 @@ export default {
noValidFiles: 'No valid files',
noValidFilesInFolder: 'All {total} files in folder are unsupported',
noValidFilesSelected: 'All selected files are unsupported',
hiddenFilesFiltered: 'Filtered {count} hidden files',
imagesFilteredNoVLM: 'Filtered {count} image files (VLM not enabled)',
invalidFilesFiltered: 'Filtered {count} unsupported files',
unsupportedFileType: 'Unsupported file type',
failedFilesList: 'Failed files:',
andMoreFiles: '...and {count} more files',
+3
View File
@@ -59,6 +59,9 @@ export default {
noValidFiles: 'Нет действительных файлов',
noValidFilesInFolder: 'Все {total} файлов в папке не поддерживаются',
noValidFilesSelected: 'Все выбранные файлы не поддерживаются',
hiddenFilesFiltered: 'Отфильтровано {count} скрытых файлов',
imagesFilteredNoVLM: 'Отфильтровано {count} изображений (VLM не включен)',
invalidFilesFiltered: 'Отфильтровано {count} неподдерживаемых файлов',
unsupportedFileType: 'Неподдерживаемый тип файла',
failedFilesList: 'Неудавшиеся файлы:',
andMoreFiles: '...и ещё {count} файлов',
+3
View File
@@ -58,6 +58,9 @@ export default {
noValidFiles: "没有有效的文件",
noValidFilesInFolder: "文件夹中的 {total} 个文件均不支持",
noValidFilesSelected: "选中的文件均不支持",
hiddenFilesFiltered: "已过滤 {count} 个隐藏文件",
imagesFilteredNoVLM: "已过滤 {count} 个图片文件(未启用VLM)",
invalidFilesFiltered: "已过滤 {count} 个不支持的文件",
unsupportedFileType: "不支持的文件格式",
failedFilesList: "失败文件列表:",
andMoreFiles: "...及其他 {count} 个文件",
+29 -2
View File
@@ -18,7 +18,8 @@ export type DisplayType =
| 'plan'
| 'database_query'
| 'web_search_results'
| 'web_fetch_results';
| 'web_fetch_results'
| 'grep_results';
// Search result item
export interface SearchResultItem {
@@ -192,6 +193,31 @@ export interface WebFetchResultsData {
count?: number;
}
// Grep chunk result item
export interface GrepChunkItem {
id: string;
content: string;
chunk_index: number;
knowledge_id: string;
knowledge_base_id: string;
chunk_type?: string;
knowledge_title?: string;
}
// Grep results data
export interface GrepResultsData {
display_type: 'grep_results';
pattern: string;
case_sensitive: boolean;
use_regex: boolean;
results: GrepChunkItem[];
result_count: number;
total_matches: number;
knowledge_base_ids?: string[];
knowledge_ids?: string[];
limit: number;
}
// Union type for all tool result data
export type ToolResultData =
| SearchResultsData
@@ -204,7 +230,8 @@ export type ToolResultData =
| PlanData
| DatabaseQueryData
| WebSearchResultsData
| WebFetchResultsData;
| WebFetchResultsData
| GrepResultsData;
// Action data (from index.vue)
export interface ActionData {
+2
View File
@@ -7,6 +7,7 @@
export const toolIcons: Record<string, string> = {
multi_kb_search: '🔍',
knowledge_search: '📚',
grep_chunks: '🔎',
get_chunk_detail: '📄',
list_knowledge_bases: '📂',
list_knowledge_chunks: '🧩',
@@ -42,6 +43,7 @@ export function getToolDisplayName(toolName: string): string {
const displayNames: Record<string, string> = {
multi_kb_search: '跨库搜索',
knowledge_search: '知识库搜索',
grep_chunks: '文本模式搜索',
get_chunk_detail: '获取片段详情',
list_knowledge_chunks: '查看知识分块',
list_knowledge_bases: '列出知识库',
@@ -117,6 +117,11 @@
<div class="results-summary-text" v-html="t('agent.webSearchFound', { count: getResultsCount(event.tool_data) })"></div>
</div>
<!-- Grep Results Summary (Fixed, always visible, outside action-details) -->
<div v-if="!event.pending && event.tool_name === 'grep_chunks' && event.tool_data" class="search-results-summary-fixed grep-summary">
<div class="results-summary-text" v-html="getGrepResultsSummary(event.tool_data)"></div>
</div>
<div v-if="isEventExpanded(event.tool_call_id) && !event.pending" class="action-details">
<!-- Thinking tool: only render markdown thought content -->
<template v-if="event.tool_name === 'thinking' && event.tool_data?.thought">
@@ -223,6 +228,7 @@ const { t } = useI18n();
const TOOL_NAME_I18N: Record<string, string> = {
search_knowledge: '知识库检索',
knowledge_search: '知识库检索',
grep_chunks: '文本模式搜索',
web_search: '网络搜索',
web_fetch: '网页抓取',
get_document_info: '获取文档信息',
@@ -1195,6 +1201,8 @@ const getToolIcon = (toolName: string): string => {
return thinkingIcon;
} else if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
return knowledgeIcon;
} else if (toolName === 'grep_chunks') {
return knowledgeIcon; // Use same icon as knowledge_search for consistency
} else if (toolName === 'web_search') {
return webSearchGlobeGreenIcon;
} else if (toolName === 'get_document_info' || toolName === 'list_knowledge_chunks') {
@@ -1236,6 +1244,26 @@ const getResultsCount = (toolData: any): number => {
return toolData.results?.length || toolData.count || 0;
};
// Get grep results summary text (returns HTML with colored numbers)
const getGrepResultsSummary = (toolData: any): string => {
if (!toolData) return '';
const pattern = toolData.pattern || '';
const totalMatches = toolData.total_matches || 0;
const resultCount = toolData.result_count || 0;
if (totalMatches === 0) {
return `未找到匹配 <code>${pattern}</code> 的内容`;
}
let summary = `找到 <strong>${totalMatches}</strong> 处匹配`;
if (totalMatches > resultCount) {
summary += `(显示 <strong>${resultCount}</strong> 个)`;
}
return summary;
};
// Extract and format query parameters from args
const getQueryText = (args: any): string => {
if (!args) return '';
@@ -67,6 +67,12 @@
:data="toolData as WebFetchResultsData"
/>
<!-- Grep Results Display -->
<GrepResults
v-else-if="displayType === 'grep_results'"
:data="toolData as GrepResultsData"
/>
<!-- Fallback: Display raw output -->
<div v-else class="fallback-output">
<div class="fallback-header">
@@ -93,7 +99,8 @@ import type {
PlanData,
DatabaseQueryData,
WebSearchResultsData,
WebFetchResultsData
WebFetchResultsData,
GrepResultsData
} from '@/types/tool-results';
import SearchResults from './tool-results/SearchResults.vue';
@@ -107,6 +114,7 @@ import PlanDisplay from './tool-results/PlanDisplay.vue';
import DatabaseQuery from './tool-results/DatabaseQuery.vue';
import WebSearchResults from './tool-results/WebSearchResults.vue';
import WebFetchResults from './tool-results/WebFetchResults.vue';
import GrepResults from './tool-results/GrepResults.vue';
interface Props {
displayType?: DisplayType;