feat(chat): add @Skill/@MCP mentions with scoped agent runtime
Wire per-turn @mentions for skills, MCP services, tags, and files through QA handlers into agent config, runtime_context/must_use user blocks, and tool registration. Fix tag-only scopes dropping KB tools, refresh suggested questions on mention changes, and strengthen MCP must_use so @selected services are invoked before local KB search.
This commit is contained in:
@@ -326,11 +326,12 @@ export interface SuggestedQuestion {
|
||||
// 根据智能体关联的知识库范围返回推荐问题,用于前端对话面板快捷提问
|
||||
export function getSuggestedQuestions(
|
||||
agentId: string,
|
||||
params?: { knowledge_base_ids?: string[]; knowledge_ids?: string[]; limit?: number }
|
||||
params?: { knowledge_base_ids?: string[]; knowledge_ids?: string[]; tag_ids?: string[]; limit?: number }
|
||||
) {
|
||||
const query = new URLSearchParams();
|
||||
if (params?.knowledge_base_ids?.length) query.set('knowledge_base_ids', params.knowledge_base_ids.join(','));
|
||||
if (params?.knowledge_ids?.length) query.set('knowledge_ids', params.knowledge_ids.join(','));
|
||||
if (params?.tag_ids?.length) query.set('tag_ids', params.tag_ids.join(','));
|
||||
if (params?.limit) query.set('limit', String(params.limit));
|
||||
const qs = query.toString();
|
||||
return get<{ data: { questions: SuggestedQuestion[] } }>(`/api/v1/agents/${agentId}/suggested-questions${qs ? '?' + qs : ''}`);
|
||||
|
||||
@@ -36,7 +36,7 @@ export function useStream() {
|
||||
let renderTimer: number | null = null
|
||||
|
||||
// 启动流式请求
|
||||
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; enable_memory?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; images?: Array<{data: string}>; attachment_uploads?: Array<{data: string; file_name: string; file_size: number}>; method: string; url: string; embed_token?: string; embed_session_sig?: string }) => {
|
||||
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; tag_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; enable_memory?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; skill_names?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string; kb_id?: string; kb_name?: string; service_id?: string; skill_name?: string}>; images?: Array<{data: string}>; attachment_uploads?: Array<{data: string; file_name: string; file_size: number}>; method: string; url: string; embed_token?: string; embed_session_sig?: string }) => {
|
||||
const myGeneration = ++streamGeneration
|
||||
// 重置状态
|
||||
output.value = '';
|
||||
@@ -115,6 +115,12 @@ export function useStream() {
|
||||
if (params.mcp_service_ids !== undefined && params.mcp_service_ids.length > 0) {
|
||||
postBody.mcp_service_ids = params.mcp_service_ids;
|
||||
}
|
||||
if (params.skill_names !== undefined && params.skill_names.length > 0) {
|
||||
postBody.skill_names = params.skill_names;
|
||||
}
|
||||
if (params.tag_ids !== undefined && params.tag_ids.length > 0) {
|
||||
postBody.tag_ids = params.tag_ids;
|
||||
}
|
||||
// Include mentioned_items if provided (for displaying @mentions in chat)
|
||||
if (params.mentioned_items !== undefined && params.mentioned_items.length > 0) {
|
||||
postBody.mentioned_items = params.mentioned_items;
|
||||
@@ -220,4 +226,4 @@ export function useStream() {
|
||||
startStream, // 启动流
|
||||
stopStream // 手动停止
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import { MessagePlugin } from "tdesign-vue-next";
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { listKnowledgeBases, searchKnowledge, batchQueryKnowledge } from '@/api/knowledge-base';
|
||||
import { listKnowledgeBases, searchKnowledge, batchQueryKnowledge, listKnowledgeTags } from '@/api/knowledge-base';
|
||||
import { listMCPServices, type MCPService } from '@/api/mcp-service';
|
||||
import { stopSession } from '@/api/chat';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
import KnowledgeBaseSelector from './KnowledgeBaseSelector.vue';
|
||||
@@ -18,6 +19,7 @@ import { getRootZoom, rectToCssPx, cssViewportSize } from '@/utils/zoom';
|
||||
import { type ModelConfig } from '@/api/model';
|
||||
import { type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
|
||||
import { useChatResourcesStore } from '@/stores/chatResources';
|
||||
import { useEditorResourcesStore } from '@/stores/editorResources';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import AttachmentUpload, { type AttachmentFile } from './AttachmentUpload.vue';
|
||||
import {
|
||||
@@ -34,6 +36,7 @@ import {
|
||||
type AgentNotReadyReasonKey,
|
||||
} from '@/utils/agent-readiness';
|
||||
import { formatLocalizedList } from '@/utils/format-list';
|
||||
import type { MentionItem, MentionItemType, MentionRequestItem } from '@/types/mention';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -42,6 +45,7 @@ const uiStore = useUIStore();
|
||||
const orgStore = useOrganizationStore();
|
||||
const menuStore = useMenuStore();
|
||||
const chatResources = useChatResourcesStore();
|
||||
const editorResources = useEditorResourcesStore();
|
||||
const {
|
||||
agents,
|
||||
disabledOwnAgentIds,
|
||||
@@ -284,6 +288,9 @@ const isKnowledgeBaseDisabledByAgent = computed(() => {
|
||||
if (!hasAgentConfig.value) return false;
|
||||
return agentKBSelectionMode.value === 'none';
|
||||
});
|
||||
const isMentionDisabled = computed(() => {
|
||||
return isKnowledgeBaseLockedByAgent.value && !settingsStore.isAgentStreamMode;
|
||||
});
|
||||
|
||||
// 智能体配置的模型 ID
|
||||
const agentModelId = computed(() => {
|
||||
@@ -303,6 +310,50 @@ const agentAllowedTools = computed<string[]>(() => {
|
||||
return currentAgentConfig.value?.allowed_tools || [];
|
||||
});
|
||||
|
||||
const normalizeMCPSelectionMode = (mode?: string): 'all' | 'selected' | 'none' => {
|
||||
return mode === 'all' || mode === 'selected' || mode === 'none' ? mode : 'none';
|
||||
};
|
||||
|
||||
const agentMCPSelectionMode = computed<'all' | 'selected' | 'none'>(() => {
|
||||
if (!settingsStore.isAgentStreamMode || !hasAgentConfig.value) return 'none';
|
||||
return normalizeMCPSelectionMode(currentAgentConfig.value?.mcp_selection_mode);
|
||||
});
|
||||
|
||||
const agentMCPServiceIds = computed<string[]>(() => {
|
||||
if (agentMCPSelectionMode.value !== 'selected') return [];
|
||||
return currentAgentConfig.value?.mcp_services || [];
|
||||
});
|
||||
|
||||
const isMCPAllowedByAgent = (service: MCPService) => {
|
||||
if (!settingsStore.isAgentStreamMode || !service.enabled) return false;
|
||||
const mode = agentMCPSelectionMode.value;
|
||||
if (mode === 'none') return false;
|
||||
if (mode === 'selected') return agentMCPServiceIds.value.includes(service.id);
|
||||
return true;
|
||||
};
|
||||
|
||||
const normalizeSkillsSelectionMode = (mode?: string): 'all' | 'selected' | 'none' => {
|
||||
return mode === 'all' || mode === 'selected' || mode === 'none' ? mode : 'none';
|
||||
};
|
||||
|
||||
const agentSkillsSelectionMode = computed<'all' | 'selected' | 'none'>(() => {
|
||||
if (!settingsStore.isAgentStreamMode || !hasAgentConfig.value) return 'none';
|
||||
return normalizeSkillsSelectionMode(currentAgentConfig.value?.skills_selection_mode);
|
||||
});
|
||||
|
||||
const agentSelectedSkills = computed<string[]>(() => {
|
||||
if (agentSkillsSelectionMode.value !== 'selected') return [];
|
||||
return currentAgentConfig.value?.selected_skills || [];
|
||||
});
|
||||
|
||||
const isSkillAllowedByAgent = (skillName: string) => {
|
||||
if (!settingsStore.isAgentStreamMode || !editorResources.skillsAvailable) return false;
|
||||
const mode = agentSkillsSelectionMode.value;
|
||||
if (mode === 'none') return false;
|
||||
if (mode === 'selected') return agentSelectedSkills.value.includes(skillName);
|
||||
return true;
|
||||
};
|
||||
|
||||
// 从 KB 对象里抽能力位,优先用 backend 显式的 capabilities 字段;否则回退到 indexing_strategy,
|
||||
// 最后拿 kb.type === 'faq' 兜底。shared / owned / agent-scope 三路的 KB 响应结构一致。
|
||||
const kbToScopeCaps = (kb: any): Partial<ScopeCapabilities> => {
|
||||
@@ -366,16 +417,19 @@ const isModelLockedByAgent = computed(() => {
|
||||
// Mention related state
|
||||
const showMention = ref(false);
|
||||
const mentionQuery = ref("");
|
||||
const mentionItems = ref<Array<{ id: string; name: string; type: 'kb' | 'file'; kbType?: 'document' | 'faq'; count?: number; kbName?: string; orgName?: string; kbId?: string }>>([]);
|
||||
const mentionItems = ref<MentionItem[]>([]);
|
||||
/** 文件 ID -> 知识库 ID(用于批量查询时传 kb_id,支持共享知识库下的文档) */
|
||||
const fileIdToKbId = ref<Record<string, string>>({});
|
||||
const mcpServices = ref<MCPService[]>([]);
|
||||
const mentionActiveIndex = ref(0);
|
||||
const mentionStyle = ref<Record<string, string>>({});
|
||||
const textareaRef = ref<any>(null); // Ref to t-textarea component
|
||||
const mentionSelectorRef = ref<any>(null);
|
||||
const mentionStartPos = ref(0);
|
||||
const isComposing = ref(false);
|
||||
const isMentionTriggeredByButton = ref(false);
|
||||
const mentionHasMore = ref(false);
|
||||
const mentionGroupCounts = ref<Partial<Record<MentionItemType, number>>>({});
|
||||
// 当前 @ 会话可见的 KB ID 集合(含工具兼容性过滤),分页加载文件时复用,
|
||||
// 避免 append 请求把不兼容 KB 的文件漏进来。`null` 表示"不受限制"(非智能体场景)
|
||||
const mentionAllowedKbIds = ref<Set<string> | null>(null);
|
||||
@@ -417,6 +471,9 @@ const isAgentEnabled = computed(() => settingsStore.isAgentEnabled);
|
||||
const isWebSearchEnabled = computed(() => settingsStore.isWebSearchEnabled);
|
||||
const selectedKbIds = computed(() => settingsStore.settings.selectedKnowledgeBases || []);
|
||||
const selectedFileIds = computed(() => settingsStore.settings.selectedFiles || []);
|
||||
const selectedTags = computed(() => settingsStore.settings.selectedTags || []);
|
||||
const selectedMCPServiceIds = computed(() => settingsStore.settings.selectedMCPServices || []);
|
||||
const selectedSkillNames = computed(() => settingsStore.settings.selectedSkills || []);
|
||||
|
||||
// 已就绪的知识库(来自租户级缓存)
|
||||
const knowledgeBases = computed(() => chatResources.validKnowledgeBases);
|
||||
@@ -461,6 +518,33 @@ const selectedFiles = computed(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const skillMentionItems = computed<MentionItem[]>(() => {
|
||||
return selectedSkillNames.value.map((name: string) => {
|
||||
const skill = editorResources.skills.find(s => s.name === name);
|
||||
return {
|
||||
id: name,
|
||||
name: skill?.name || name,
|
||||
type: 'skill' as const,
|
||||
skillName: name,
|
||||
description: skill?.description || '',
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const selectedMCPItems = computed<MentionItem[]>(() => {
|
||||
return selectedMCPServiceIds.value
|
||||
.map((id: string) => mcpServices.value.find(service => service.id === id))
|
||||
.filter((svc): svc is MCPService => !!svc && isMCPAllowedByAgent(svc))
|
||||
.map((svc) => {
|
||||
return {
|
||||
id: svc.id,
|
||||
name: svc.name,
|
||||
type: 'mcp' as const,
|
||||
description: svc.description || '',
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
// 合并所有选中项(用于输入框内显示)
|
||||
// 现在智能体配置的知识库也在 store 中,统一从 selectedKbs 获取
|
||||
const allSelectedItems = computed(() => {
|
||||
@@ -501,19 +585,49 @@ const allSelectedItems = computed(() => {
|
||||
// 智能体配置的放在前面
|
||||
const agentConfiguredKbs = allKbs.filter(kb => kb.isAgentConfigured);
|
||||
const userSelectedKbs = allKbs.filter(kb => !kb.isAgentConfigured);
|
||||
const tags = selectedTags.value.map((tag: any) => ({
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
type: 'tag' as const,
|
||||
kbId: tag.kbId,
|
||||
kbName: tag.kbName,
|
||||
description: tag.kbName || '',
|
||||
isAgentConfigured: false,
|
||||
}));
|
||||
|
||||
return [...agentConfiguredKbs, ...userSelectedKbs, ...files];
|
||||
return [...agentConfiguredKbs, ...userSelectedKbs, ...files, ...tags, ...selectedMCPItems.value, ...skillMentionItems.value];
|
||||
});
|
||||
|
||||
// 移除选中项(智能体配置的项也可以移除)
|
||||
const removeSelectedItem = (item: { id: string; type: 'kb' | 'file'; isAgentConfigured?: boolean }) => {
|
||||
const removeSelectedItem = (item: MentionItem) => {
|
||||
if (item.type === 'kb') {
|
||||
settingsStore.removeKnowledgeBase(item.id);
|
||||
} else {
|
||||
} else if (item.type === 'file') {
|
||||
settingsStore.removeFile(item.id);
|
||||
} else if (item.type === 'tag') {
|
||||
settingsStore.removeTag(item.id, item.kbId);
|
||||
} else if (item.type === 'mcp') {
|
||||
settingsStore.removeMCPService(item.id);
|
||||
} else if (item.type === 'skill') {
|
||||
settingsStore.removeSkill(item.skillName || item.id);
|
||||
}
|
||||
};
|
||||
|
||||
const getMentionIcon = (item: MentionItem) => {
|
||||
switch (item.type) {
|
||||
case 'file': return 'file';
|
||||
case 'tag': return 'tag';
|
||||
case 'mcp': return 'tools';
|
||||
case 'skill': return 'bookmark';
|
||||
default: return 'folder';
|
||||
}
|
||||
};
|
||||
|
||||
const getMentionChipClass = (item: MentionItem) => {
|
||||
if (item.type === 'kb') return item.kbType === 'faq' ? 'mention-chip--faq' : 'mention-chip--kb';
|
||||
return `mention-chip--${item.type}`;
|
||||
};
|
||||
|
||||
// 使用 computed 从 store 读取,并通过 setter 同步回 store
|
||||
const selectedModelId = computed({
|
||||
get: () => settingsStore.conversationModels.selectedChatModelId || '',
|
||||
@@ -637,6 +751,15 @@ const loadFiles = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadMCPServices = async () => {
|
||||
try {
|
||||
mcpServices.value = await listMCPServices();
|
||||
} catch (error) {
|
||||
console.error('Failed to load MCP services:', error);
|
||||
mcpServices.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
watch(selectedFileIds, () => {
|
||||
loadFiles();
|
||||
}, { immediate: true });
|
||||
@@ -1000,6 +1123,9 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
|
||||
// 根据智能体的 kb_selection_mode 过滤知识库;选中共享智能体时使用该租户下的知识库,否则使用本租户 + 共享给自己的
|
||||
let kbItems: any[] = [];
|
||||
let tagItems: MentionItem[] = [];
|
||||
let mcpItems: MentionItem[] = [];
|
||||
let skillItems: MentionItem[] = [];
|
||||
if (!append) {
|
||||
let availableKbs: any[];
|
||||
const sourceTenantId = settingsStore.selectedAgentSourceTenantId;
|
||||
@@ -1088,14 +1214,81 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
const kbs = availableKbs.filter((kb: any) =>
|
||||
!q || (kb.name && kb.name.toLowerCase().includes(q.toLowerCase()))
|
||||
);
|
||||
kbItems = kbs.map((kb: any) => ({
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
type: 'kb' as const,
|
||||
kbType: kb.type || 'document',
|
||||
count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0),
|
||||
orgName: kb.org_name || sharedAgentOrgName.value || undefined
|
||||
kbItems = await Promise.all(kbs.map(async (kb: any) => {
|
||||
const kbType = kb.type || 'document';
|
||||
let count = kbType === 'faq' ? Number(kb.chunk_count || 0) : Number(kb.knowledge_count || 0);
|
||||
if (!count) {
|
||||
const detail = await chatResources.fetchKnowledgeBaseById(kb.id);
|
||||
if (detail) {
|
||||
count = detail.type === 'faq'
|
||||
? Number(detail.chunk_count || 0)
|
||||
: Number(detail.knowledge_count || 0);
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
type: 'kb' as const,
|
||||
kbType: kbType === 'faq' ? 'faq' as const : 'document' as const,
|
||||
count,
|
||||
orgName: kb.org_name || sharedAgentOrgName.value || undefined
|
||||
};
|
||||
}));
|
||||
mentionGroupCounts.value.kb = kbItems.length;
|
||||
|
||||
const tagKeyword = q.trim();
|
||||
const tagSources = availableKbs.slice(0, 20);
|
||||
try {
|
||||
const tagResults = await Promise.all(tagSources.map(async (kb: any) => {
|
||||
const res: any = await listKnowledgeTags(kb.id, { page: 1, page_size: 20, keyword: tagKeyword || undefined });
|
||||
const payload = res?.data ?? res;
|
||||
const list = Array.isArray(payload?.data) ? payload.data : (Array.isArray(payload) ? payload : []);
|
||||
return list.map((tag: any) => ({
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
type: 'tag' as const,
|
||||
kbId: kb.id,
|
||||
kbName: kb.name,
|
||||
}));
|
||||
}));
|
||||
tagItems = tagResults.flat();
|
||||
} catch (e) {
|
||||
console.error('[Mention] listKnowledgeTags error:', e);
|
||||
tagItems = [];
|
||||
}
|
||||
|
||||
const mcpMode = agentMCPSelectionMode.value;
|
||||
if (mcpMode !== 'none') {
|
||||
mcpItems = mcpServices.value
|
||||
.filter(service => isMCPAllowedByAgent(service))
|
||||
.filter(service => !q || service.name?.toLowerCase().includes(q.toLowerCase()) || (service.description || '').toLowerCase().includes(q.toLowerCase()))
|
||||
.map(service => ({
|
||||
id: service.id,
|
||||
name: service.name,
|
||||
type: 'mcp' as const,
|
||||
description: service.description || '',
|
||||
}));
|
||||
}
|
||||
|
||||
const skillsMode = agentSkillsSelectionMode.value;
|
||||
if (skillsMode !== 'none') {
|
||||
await editorResources.ensureSkills();
|
||||
skillItems = editorResources.skills
|
||||
.filter(skill => isSkillAllowedByAgent(skill.name))
|
||||
.map(skill => ({
|
||||
id: skill.name,
|
||||
name: skill.name,
|
||||
type: 'skill' as const,
|
||||
skillName: skill.name,
|
||||
description: skill.description || '',
|
||||
}))
|
||||
.filter(skill => {
|
||||
if (!q) return true;
|
||||
const keyword = q.toLowerCase();
|
||||
return skill.name.toLowerCase().includes(keyword)
|
||||
|| (skill.description || '').toLowerCase().includes(keyword);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch Files from API
|
||||
@@ -1131,6 +1324,8 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
console.log('[Mention] searchKnowledge response:', res);
|
||||
if (res.data && Array.isArray(res.data)) {
|
||||
let files = res.data;
|
||||
const rawTotal = typeof res.total === 'number' ? res.total : undefined;
|
||||
const apiPageSize = res.data.length;
|
||||
// 按当前 @ 会话的兼容 KB 集合过滤:
|
||||
// - 非智能体场景:`mentionAllowedKbIds` 为 null,跳过;
|
||||
// - 智能体场景(含 shared agent):'selected' 会把 ID 收敛到用户勾的 KB,
|
||||
@@ -1163,6 +1358,14 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
orgName: fileOrgName || undefined
|
||||
};
|
||||
});
|
||||
if (!append) {
|
||||
const clientFiltered = !!mentionAllowedKbIds.value && fileItems.length < apiPageSize;
|
||||
if (!clientFiltered && rawTotal != null) {
|
||||
mentionGroupCounts.value.file = rawTotal;
|
||||
} else {
|
||||
delete mentionGroupCounts.value.file;
|
||||
}
|
||||
}
|
||||
}
|
||||
mentionHasMore.value = res.has_more || false;
|
||||
mentionOffset.value += fileItems.length;
|
||||
@@ -1180,9 +1383,9 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
// Append file items to existing list
|
||||
mentionItems.value = [...mentionItems.value, ...fileItems];
|
||||
} else {
|
||||
mentionItems.value = [...kbItems, ...fileItems];
|
||||
mentionItems.value = [...kbItems, ...tagItems, ...mcpItems, ...skillItems, ...fileItems];
|
||||
}
|
||||
console.log('[Mention] Total items:', mentionItems.value.length, { kbItems: kbItems.length, fileItems: fileItems.length });
|
||||
console.log('[Mention] Total items:', mentionItems.value.length, { kbItems: kbItems.length, fileItems: fileItems.length, tagItems: tagItems.length, mcpItems: mcpItems.length, skillItems: skillItems.length });
|
||||
|
||||
// Only reset index if query changed or explicitly requested
|
||||
if (resetIndex || q !== lastMentionQuery) {
|
||||
@@ -1263,11 +1466,7 @@ const onInput = (val: string | InputEvent) => {
|
||||
} else {
|
||||
if (textBeforeCursor.endsWith('@')) {
|
||||
// 如果智能体禁用了知识库,不触发 @ 菜单
|
||||
if (isKnowledgeBaseDisabledByAgent.value) {
|
||||
return;
|
||||
}
|
||||
// 如果智能体锁定了知识库且不允许用户选择,也不触发 @ 菜单
|
||||
if (isKnowledgeBaseLockedByAgent.value) {
|
||||
if (isMentionDisabled.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1336,8 +1535,8 @@ const onCompositionEnd = (e: CompositionEvent) => {
|
||||
};
|
||||
|
||||
const triggerMention = () => {
|
||||
// 如果智能体锁定或禁用了知识库,不允许打开选择器
|
||||
if (isKnowledgeBaseLockedByAgent.value) {
|
||||
// 如果当前没有任何可提及资源,不允许打开选择器
|
||||
if (isMentionDisabled.value) {
|
||||
const msgKey = isKnowledgeBaseDisabledByAgent.value ? 'input.kbDisabledByAgent' : 'input.kbLockedByAgent';
|
||||
MessagePlugin.warning(t(msgKey));
|
||||
return;
|
||||
@@ -1401,6 +1600,14 @@ const onMentionSelect = (item: any) => {
|
||||
if (!fileList.value.find(f => f.id === item.id)) {
|
||||
fileList.value.push({ id: item.id, name: item.name });
|
||||
}
|
||||
} else if (item.type === 'tag') {
|
||||
if (item.kbId) {
|
||||
settingsStore.addTag({ id: item.id, name: item.name, kbId: item.kbId, kbName: item.kbName });
|
||||
}
|
||||
} else if (item.type === 'mcp') {
|
||||
settingsStore.addMCPService(item.id);
|
||||
} else if (item.type === 'skill') {
|
||||
settingsStore.addSkill(item.skillName || item.id);
|
||||
}
|
||||
|
||||
const textarea = getTextareaEl();
|
||||
@@ -1505,6 +1712,7 @@ onMounted(() => {
|
||||
loadWebSearchConfig(),
|
||||
loadChatModels(),
|
||||
loadAgents(),
|
||||
loadMCPServices(),
|
||||
]);
|
||||
window.addEventListener(CHAT_FILE_DROP_EVENT, handleChatFileDrop as EventListener);
|
||||
|
||||
@@ -1595,7 +1803,7 @@ watch([selectedKbIds, selectedFileIds], ([kbIds, fileIds]) => {
|
||||
}, { deep: true });
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'send-msg', query: string, modelId: string, mentionedItems: any[], imageFiles: File[], attachmentFiles: AttachmentFile[]): void;
|
||||
(e: 'send-msg', query: string, modelId: string, mentionedItems: MentionRequestItem[], imageFiles: File[], attachmentFiles: AttachmentFile[]): void;
|
||||
(e: 'stop-generation'): void;
|
||||
}>();
|
||||
|
||||
@@ -1648,11 +1856,15 @@ const createSession = async (val: string) => {
|
||||
return;
|
||||
}
|
||||
// 获取@提及的知识库和文件信息
|
||||
const mentionedItems = allSelectedItems.value.map(item => ({
|
||||
const mentionedItems: MentionRequestItem[] = allSelectedItems.value.map(item => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
type: item.type,
|
||||
kb_type: item.type === 'kb' ? (item.kbType || 'document') : undefined
|
||||
kb_type: item.type === 'kb' ? (item.kbType || 'document') : undefined,
|
||||
kb_id: item.kbId,
|
||||
kb_name: item.kbName,
|
||||
service_id: item.serviceId,
|
||||
skill_name: item.skillName,
|
||||
}));
|
||||
const imageFiles = uploadedImages.value.map(img => img.file);
|
||||
const attachmentFiles = uploadedAttachments.value;
|
||||
@@ -1897,22 +2109,23 @@ const onKeydown = (val: string, event: { e: { preventDefault(): unknown; keyCode
|
||||
if (showMention.value) {
|
||||
if (event.e.keyCode === 38) { // Up
|
||||
event.e.preventDefault();
|
||||
mentionActiveIndex.value = Math.max(0, mentionActiveIndex.value - 1);
|
||||
mentionSelectorRef.value?.moveActive(-1);
|
||||
return;
|
||||
}
|
||||
if (event.e.keyCode === 40) { // Down
|
||||
event.e.preventDefault();
|
||||
mentionActiveIndex.value = Math.min(mentionItems.value.length - 1, mentionActiveIndex.value + 1);
|
||||
mentionSelectorRef.value?.moveActive(1);
|
||||
return;
|
||||
}
|
||||
if (event.e.keyCode === 13) { // Enter
|
||||
event.e.preventDefault();
|
||||
if (mentionItems.value[mentionActiveIndex.value]) {
|
||||
onMentionSelect(mentionItems.value[mentionActiveIndex.value]);
|
||||
}
|
||||
mentionSelectorRef.value?.confirmActive();
|
||||
return;
|
||||
}
|
||||
if (event.e.keyCode === 27) { // Esc
|
||||
if (mentionSelectorRef.value?.leaveGroup()) {
|
||||
return;
|
||||
}
|
||||
showMention.value = false;
|
||||
return;
|
||||
}
|
||||
@@ -2196,14 +2409,14 @@ defineExpose({
|
||||
|
||||
<!-- 选中的知识库和文件标签(显示在输入框内顶部) -->
|
||||
<div v-if="allSelectedItems.length > 0" class="selected-tags-inline">
|
||||
<span v-for="item in allSelectedItems" :key="item.id" class="mention-chip" :class="[
|
||||
item.type === 'kb' ? (item.kbType === 'faq' ? 'mention-chip--faq' : 'mention-chip--kb') : 'mention-chip--file',
|
||||
<span v-for="item in allSelectedItems" :key="`${item.type}:${item.id}`" class="mention-chip" :class="[
|
||||
getMentionChipClass(item),
|
||||
{ 'mention-chip--agent': item.isAgentConfigured }
|
||||
]">
|
||||
<span class="mention-chip__icon-wrap" :class="{ 'has-org': item.org_name }">
|
||||
<span class="mention-chip__icon">
|
||||
<t-icon v-if="item.type === 'kb'" :name="item.kbType === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
<t-icon v-else name="file" />
|
||||
<t-icon v-else :name="getMentionIcon(item)" />
|
||||
</span>
|
||||
<span v-if="item.org_name" class="mention-chip__org-badge">
|
||||
<img :src="getImgSrc(item.type === 'file' ? 'organization-grey.svg' : 'organization-green.svg')"
|
||||
@@ -2323,7 +2536,7 @@ defineExpose({
|
||||
<!-- @ 知识库/文件选择按钮 -->
|
||||
<t-tooltip placement="top" theme="light" :popupProps="{ overlayClassName: 'input-field-tooltip' }">
|
||||
<template #content>
|
||||
<div v-if="isKnowledgeBaseDisabledByAgent" class="tooltip-with-link">
|
||||
<div v-if="isMentionDisabled && isKnowledgeBaseDisabledByAgent" class="tooltip-with-link">
|
||||
<span>{{ $t('input.kbDisabledByAgent') }}</span>
|
||||
<a href="#" @click.prevent="handleGoToAgentSettings('knowledge')">{{ $t('input.goToAgentSettings')
|
||||
}}</a>
|
||||
@@ -2335,7 +2548,7 @@ defineExpose({
|
||||
</template>
|
||||
<div ref="atButtonRef" class="control-btn kb-btn" data-guide="chat-kb-mention" :class="{
|
||||
'active': allSelectedItems.length > 0,
|
||||
'disabled': isKnowledgeBaseDisabledByAgent
|
||||
'disabled': isMentionDisabled
|
||||
}" @click.stop @mousedown.prevent="triggerMention">
|
||||
<svg width="18" height="18" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"
|
||||
class="control-icon at-icon">
|
||||
@@ -2418,8 +2631,8 @@ defineExpose({
|
||||
|
||||
<!-- Mention Selector -->
|
||||
<Teleport to="body">
|
||||
<MentionSelector :visible="showMention" :style="mentionStyle" :items="mentionItems" :hasMore="mentionHasMore"
|
||||
:loading="mentionLoading" :emptyHint="mentionEmptyHint" v-model:activeIndex="mentionActiveIndex"
|
||||
<MentionSelector ref="mentionSelectorRef" :visible="showMention" :style="mentionStyle" :items="mentionItems" :hasMore="mentionHasMore"
|
||||
:loading="mentionLoading" :emptyHint="mentionEmptyHint" :query="mentionQuery" :group-counts="mentionGroupCounts" v-model:activeIndex="mentionActiveIndex"
|
||||
@select="onMentionSelect" @loadMore="loadMoreMentionItems" />
|
||||
</Teleport>
|
||||
|
||||
@@ -2610,6 +2823,24 @@ const getImgSrc = (url: string) => {
|
||||
color: var(--td-text-color-secondary, #6b7280);
|
||||
}
|
||||
|
||||
.mention-chip--tag,
|
||||
.mention-chip--mcp,
|
||||
.mention-chip--tool {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.mention-chip--tag .mention-chip__icon-wrap {
|
||||
color: #9f7aea;
|
||||
}
|
||||
|
||||
.mention-chip--mcp .mention-chip__icon-wrap {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.mention-chip--tool .mention-chip__icon-wrap {
|
||||
color: #b7791f;
|
||||
}
|
||||
|
||||
/* 智能体预配置:虚线边框区分 */
|
||||
.mention-chip--agent {
|
||||
border-style: dashed;
|
||||
|
||||
@@ -1,154 +1,258 @@
|
||||
<template>
|
||||
<div v-if="visible" class="mention-menu" :style="style" ref="menuRef" @click.stop @scroll="onScroll">
|
||||
<!-- Knowledge Bases Group -->
|
||||
<div v-if="kbItems.length > 0" class="mention-group">
|
||||
<div class="mention-group-header">{{ $t('common.knowledgeBase') }}</div>
|
||||
<t-popup
|
||||
v-for="(item, index) in kbItems"
|
||||
:key="item.id"
|
||||
placement="right-start"
|
||||
trigger="hover"
|
||||
:show-arrow="false"
|
||||
:delay="[320, 80]"
|
||||
:disabled="isScrolling"
|
||||
:overlay-class-name="'mention-detail-popup'"
|
||||
:overlay-inner-class-name="'mention-detail-popup-wrap'"
|
||||
@visible-change="(v: boolean) => v && fetchKbDetail(item)"
|
||||
>
|
||||
<div
|
||||
class="mention-item"
|
||||
:class="{ active: index === activeIndex }"
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', index)"
|
||||
<div v-if="visible" class="mention-menu" :style="style" ref="menuRef" @click.stop>
|
||||
<div class="mention-list" ref="listRef" @scroll="onScroll">
|
||||
<template v-if="!currentGroupType && !isFlatMode">
|
||||
<button
|
||||
v-for="(group, index) in groupRows"
|
||||
:key="group.type"
|
||||
type="button"
|
||||
class="mention-group-entry"
|
||||
:class="{ active: index === groupActiveIndex }"
|
||||
@click.stop="enterGroup(group.type)"
|
||||
@mouseenter="groupActiveIndex = index"
|
||||
>
|
||||
<div class="icon-wrap">
|
||||
<div class="icon" :class="item.kbType === 'faq' ? 'faq-icon' : 'kb-icon'">
|
||||
<t-icon :name="item.kbType === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
<span class="mention-group-entry__icon">
|
||||
<t-icon :name="group.icon" />
|
||||
</span>
|
||||
<span class="mention-group-entry__label">{{ group.label }}</span>
|
||||
<span class="mention-group-entry__count">{{ formatGroupCount(group) }}</span>
|
||||
<t-icon class="mention-group-entry__arrow" name="chevron-right" />
|
||||
</button>
|
||||
<div v-if="groupRows.length === 0 && !loading" class="empty">
|
||||
{{ emptyHint || $t('common.noResult') }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<button v-if="!isFlatMode" type="button" class="mention-back-row" @click.stop="leaveGroup">
|
||||
<t-icon name="chevron-left" />
|
||||
<span>{{ currentGroup?.label }}</span>
|
||||
</button>
|
||||
|
||||
<div
|
||||
v-if="isFlatMode && groupTabs.length > 1 && kbItems.length > 0"
|
||||
class="mention-group-header"
|
||||
>
|
||||
{{ $t('common.knowledgeBase') }}
|
||||
</div>
|
||||
<!-- Knowledge Bases Group -->
|
||||
<div v-if="(isFlatMode || currentGroupType === 'kb') && kbItems.length > 0" class="mention-group" data-group-type="kb">
|
||||
<t-popup
|
||||
v-for="(item, index) in kbItems"
|
||||
:key="item.id"
|
||||
placement="right-start"
|
||||
trigger="hover"
|
||||
:show-arrow="false"
|
||||
:delay="[320, 80]"
|
||||
:disabled="isScrolling"
|
||||
:overlay-class-name="'mention-detail-popup'"
|
||||
:overlay-inner-class-name="'mention-detail-popup-wrap'"
|
||||
@visible-change="(v: boolean) => v && fetchKbDetail(item)"
|
||||
>
|
||||
<div
|
||||
class="mention-item"
|
||||
:class="{ active: index === activeIndex }"
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', index)"
|
||||
>
|
||||
<div class="icon-wrap">
|
||||
<div class="icon" :class="item.kbType === 'faq' ? 'faq-icon' : 'kb-icon'">
|
||||
<t-icon :name="item.kbType === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-main">
|
||||
<span class="name">{{ item.name }}</span>
|
||||
<span class="count">{{ item.count || 0 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-main">
|
||||
<span class="name">{{ item.name }}</span>
|
||||
<span class="count">{{ item.count || 0 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
<template v-if="detailCache[item.id]?.loading">
|
||||
<div class="detail-loading"><t-loading size="small" /></div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.error">
|
||||
<div class="detail-error">{{ detailCache[item.id].error }}</div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.data">
|
||||
<div class="detail-header">
|
||||
<span class="detail-name">{{ detailCache[item.id].data.name }}</span>
|
||||
<span class="detail-type-badge" :class="detailCache[item.id].data.type === 'faq' ? 'faq' : 'doc'">
|
||||
{{ detailCache[item.id].data.type === 'faq' ? $t('knowledgeEditor.basic.typeFAQ') : $t('knowledgeEditor.basic.typeDocument') }}
|
||||
</span>
|
||||
</div>
|
||||
<p v-if="detailCache[item.id].data.description" class="detail-desc">{{ detailCache[item.id].data.description }}</p>
|
||||
<div class="detail-meta">
|
||||
<span v-if="detailCache[item.id].data.type === 'faq'">
|
||||
{{ $t('mentionDetail.faqCount', { count: detailCache[item.id].data.chunk_count ?? detailCache[item.id].data.count ?? 0 }) }}
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ $t('mentionDetail.kbCount', { count: detailCache[item.id].data.knowledge_count ?? detailCache[item.id].data.count ?? 0 }) }}
|
||||
</span>
|
||||
<span v-if="detailCache[item.id].data.org_name || item.orgName" class="detail-org">
|
||||
<img src="@/assets/img/organization-green.svg" class="detail-icon-img" alt="" aria-hidden="true" />
|
||||
<span class="detail-label">{{ $t('mentionDetail.belongsToOrg') }}</span>
|
||||
<span
|
||||
class="detail-value clickable"
|
||||
@click.stop="handleOrgClick(detailCache[item.id].data.org_name || item.orgName)"
|
||||
>
|
||||
{{ detailCache[item.id].data.org_name || item.orgName }}
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
<template v-if="detailCache[item.id]?.loading">
|
||||
<div class="detail-loading"><t-loading size="small" /></div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.error">
|
||||
<div class="detail-error">{{ detailCache[item.id].error }}</div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.data">
|
||||
<div class="detail-header">
|
||||
<span class="detail-name">{{ detailCache[item.id].data.name }}</span>
|
||||
<span class="detail-type-badge" :class="detailCache[item.id].data.type === 'faq' ? 'faq' : 'doc'">
|
||||
{{ detailCache[item.id].data.type === 'faq' ? $t('knowledgeEditor.basic.typeFAQ') : $t('knowledgeEditor.basic.typeDocument') }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="agentIdForDetail && (detailCache[item.id].data.org_name || item.orgName)" class="detail-readonly-hint">
|
||||
{{ $t('mentionDetail.readOnlyFromAgent') }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- Files Group -->
|
||||
<div v-if="fileItems.length > 0" class="mention-group">
|
||||
<div class="mention-group-header">{{ $t('common.file') }}</div>
|
||||
<t-popup
|
||||
v-for="(item, index) in fileItems"
|
||||
:key="item.id"
|
||||
placement="right-start"
|
||||
trigger="hover"
|
||||
:show-arrow="false"
|
||||
:delay="[320, 80]"
|
||||
:disabled="isScrolling"
|
||||
:overlay-class-name="'mention-detail-popup'"
|
||||
:overlay-inner-class-name="'mention-detail-popup-wrap'"
|
||||
@visible-change="(v: boolean) => v && fetchFileDetail(item)"
|
||||
>
|
||||
</div>
|
||||
<p v-if="detailCache[item.id].data.description" class="detail-desc">{{ detailCache[item.id].data.description }}</p>
|
||||
<div class="detail-meta">
|
||||
<span v-if="detailCache[item.id].data.type === 'faq'">
|
||||
{{ $t('mentionDetail.faqCount', { count: detailCache[item.id].data.chunk_count ?? detailCache[item.id].data.count ?? 0 }) }}
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ $t('mentionDetail.kbCount', { count: detailCache[item.id].data.knowledge_count ?? detailCache[item.id].data.count ?? 0 }) }}
|
||||
</span>
|
||||
<span v-if="detailCache[item.id].data.org_name || item.orgName" class="detail-org">
|
||||
<img src="@/assets/img/organization-green.svg" class="detail-icon-img" alt="" aria-hidden="true" />
|
||||
<span class="detail-label">{{ $t('mentionDetail.belongsToOrg') }}</span>
|
||||
<span
|
||||
class="detail-value clickable"
|
||||
@click.stop="handleOrgClick(detailCache[item.id].data.org_name || item.orgName)"
|
||||
>
|
||||
{{ detailCache[item.id].data.org_name || item.orgName }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="agentIdForDetail && (detailCache[item.id].data.org_name || item.orgName)" class="detail-readonly-hint">
|
||||
{{ $t('mentionDetail.readOnlyFromAgent') }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<template v-for="group in activeExtraGroups" :key="group.type">
|
||||
<div
|
||||
class="mention-item"
|
||||
:class="{ active: (kbItems.length + index) === activeIndex }"
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', kbItems.length + index)"
|
||||
v-if="isFlatMode && groupTabs.length > 1"
|
||||
class="mention-group-header"
|
||||
>
|
||||
<div class="icon-wrap">
|
||||
<div class="icon file-icon">
|
||||
<t-icon name="file" />
|
||||
{{ group.label }}
|
||||
</div>
|
||||
<div class="mention-group" :data-group-type="group.type">
|
||||
<t-popup
|
||||
v-for="(item, index) in group.items"
|
||||
:key="`${item.type}:${item.id}`"
|
||||
placement="right-start"
|
||||
trigger="hover"
|
||||
:show-arrow="false"
|
||||
:delay="[320, 80]"
|
||||
:disabled="isScrolling"
|
||||
:overlay-class-name="'mention-detail-popup'"
|
||||
:overlay-inner-class-name="'mention-detail-popup-wrap'"
|
||||
>
|
||||
<div
|
||||
class="mention-item"
|
||||
:class="{ active: group.offset + index === activeIndex }"
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', group.offset + index)"
|
||||
>
|
||||
<div class="icon-wrap">
|
||||
<div class="icon" :class="`${item.type}-icon`">
|
||||
<t-icon :name="group.icon" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-main">
|
||||
<span class="name">{{ item.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="name">{{ item.name }}</span>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
<template v-if="detailCache[item.id]?.loading">
|
||||
<div class="detail-loading"><t-loading size="small" /></div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.error">
|
||||
<div class="detail-error">{{ detailCache[item.id].error }}</div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.data">
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
<div class="detail-header">
|
||||
<span class="detail-name">{{ detailCache[item.id].data.title || detailCache[item.id].data.file_name || item.name }}</span>
|
||||
<span class="detail-name">{{ item.name }}</span>
|
||||
</div>
|
||||
<p v-if="detailCache[item.id].data.description" class="detail-desc">{{ detailCache[item.id].data.description }}</p>
|
||||
<p v-if="item.description" class="detail-desc">{{ item.description }}</p>
|
||||
<div class="detail-meta">
|
||||
<span v-if="detailCache[item.id].data.knowledge_base_name || item.kbName" class="detail-kb">
|
||||
<span v-if="item.kbName" class="detail-kb">
|
||||
<t-icon name="folder" class="detail-icon" />
|
||||
<span class="detail-label">{{ $t('mentionDetail.belongsToKb') }}</span>
|
||||
<span
|
||||
<span
|
||||
class="detail-value clickable"
|
||||
@click.stop="handleKbClick(detailCache[item.id].data.knowledge_base_id || (item as any).kbId)"
|
||||
@click.stop="handleKbClick(item.kbId)"
|
||||
>
|
||||
{{ detailCache[item.id].data.knowledge_base_name || item.kbName }}
|
||||
{{ item.kbName }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="item.orgName" class="detail-org">
|
||||
<img src="@/assets/img/organization-green.svg" class="detail-icon-img" alt="" aria-hidden="true" />
|
||||
<span class="detail-label">{{ $t('mentionDetail.belongsToOrg') }}</span>
|
||||
<span
|
||||
class="detail-value clickable"
|
||||
@click.stop="handleOrgClick(item.orgName)"
|
||||
>
|
||||
{{ item.orgName }}
|
||||
</span>
|
||||
<span v-if="item.serviceName" class="detail-kb">
|
||||
<t-icon name="tools" class="detail-icon" />
|
||||
<span class="detail-label">MCP:</span>
|
||||
<span class="detail-value">{{ item.serviceName }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
<!-- Loading indicator -->
|
||||
<div v-if="loading" class="loading-more">
|
||||
<t-loading size="small" />
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div
|
||||
v-if="isFlatMode && groupTabs.length > 1 && fileItems.length > 0"
|
||||
class="mention-group-header"
|
||||
>
|
||||
{{ $t('common.file') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="items.length === 0 && !loading" class="empty">
|
||||
{{ emptyHint || $t('common.noResult') }}
|
||||
<!-- Files Group -->
|
||||
<div v-if="(isFlatMode || currentGroupType === 'file') && fileItems.length > 0" class="mention-group" data-group-type="file">
|
||||
<t-popup
|
||||
v-for="(item, index) in fileItems"
|
||||
:key="item.id"
|
||||
placement="right-start"
|
||||
trigger="hover"
|
||||
:show-arrow="false"
|
||||
:delay="[320, 80]"
|
||||
:disabled="isScrolling"
|
||||
:overlay-class-name="'mention-detail-popup'"
|
||||
:overlay-inner-class-name="'mention-detail-popup-wrap'"
|
||||
@visible-change="(v: boolean) => v && fetchFileDetail(item)"
|
||||
>
|
||||
<div
|
||||
class="mention-item"
|
||||
:class="{ active: (fileGroupOffset + index) === activeIndex }"
|
||||
@click="$emit('select', item)"
|
||||
@mouseenter="$emit('update:activeIndex', fileGroupOffset + index)"
|
||||
>
|
||||
<div class="icon-wrap">
|
||||
<div class="icon file-icon">
|
||||
<t-icon name="file" />
|
||||
</div>
|
||||
</div>
|
||||
<span class="name">{{ item.name }}</span>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="mention-detail-content">
|
||||
<template v-if="detailCache[item.id]?.loading">
|
||||
<div class="detail-loading"><t-loading size="small" /></div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.error">
|
||||
<div class="detail-error">{{ detailCache[item.id].error }}</div>
|
||||
</template>
|
||||
<template v-else-if="detailCache[item.id]?.data">
|
||||
<div class="detail-header">
|
||||
<span class="detail-name">{{ detailCache[item.id].data.title || detailCache[item.id].data.file_name || item.name }}</span>
|
||||
</div>
|
||||
<p v-if="detailCache[item.id].data.description" class="detail-desc">{{ detailCache[item.id].data.description }}</p>
|
||||
<div class="detail-meta">
|
||||
<span v-if="detailCache[item.id].data.knowledge_base_name || item.kbName" class="detail-kb">
|
||||
<t-icon name="folder" class="detail-icon" />
|
||||
<span class="detail-label">{{ $t('mentionDetail.belongsToKb') }}</span>
|
||||
<span
|
||||
class="detail-value clickable"
|
||||
@click.stop="handleKbClick(detailCache[item.id].data.knowledge_base_id || (item as any).kbId)"
|
||||
>
|
||||
{{ detailCache[item.id].data.knowledge_base_name || item.kbName }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="item.orgName" class="detail-org">
|
||||
<img src="@/assets/img/organization-green.svg" class="detail-icon-img" alt="" aria-hidden="true" />
|
||||
<span class="detail-label">{{ $t('mentionDetail.belongsToOrg') }}</span>
|
||||
<span
|
||||
class="detail-value clickable"
|
||||
@click.stop="handleOrgClick(item.orgName)"
|
||||
>
|
||||
{{ item.orgName }}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
<!-- Loading indicator -->
|
||||
<div v-if="loading" class="loading-more">
|
||||
<t-loading size="small" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="items.length === 0 && !loading" class="empty">
|
||||
{{ emptyHint || $t('common.noResult') }}
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -156,32 +260,42 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watch, ref, nextTick, onBeforeUnmount } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getKnowledgeBaseById } from '@/api/knowledge-base';
|
||||
import { getKnowledgeDetails } from '@/api/knowledge-base';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import type { MentionItem, MentionItemType } from '@/types/mention';
|
||||
|
||||
type DetailState = { loading: boolean; error?: string; data?: any };
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
style: any;
|
||||
items: Array<{ id: string; name: string; type: 'kb' | 'file'; kbType?: 'document' | 'faq'; count?: number; kbName?: string; orgName?: string; kbId?: string }>;
|
||||
items: MentionItem[];
|
||||
activeIndex: number;
|
||||
hasMore?: boolean;
|
||||
loading?: boolean;
|
||||
// 空态下替换默认 "无结果" 文案,用于给上游(如"被智能体工具兼容性过滤掉了")透传具体原因
|
||||
emptyHint?: string;
|
||||
// 输入 @ 后的筛选关键词;非空时平铺展示匹配项,不再要求进入二级目录
|
||||
query?: string;
|
||||
// 分组入口展示用的总数(如文件搜索的 total),避免仅用首屏已加载条数
|
||||
groupCounts?: Partial<Record<MentionItemType, number>>;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits(['select', 'update:activeIndex', 'loadMore']);
|
||||
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const orgStore = useOrganizationStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const menuRef = ref<HTMLElement | null>(null);
|
||||
const listRef = ref<HTMLElement | null>(null);
|
||||
const detailCache = ref<Record<string, DetailState>>({});
|
||||
const isScrolling = ref(false);
|
||||
const currentGroupType = ref<MentionItemType | null>(null);
|
||||
const groupActiveIndex = ref(0);
|
||||
let scrollTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
@@ -198,6 +312,135 @@ const agentIdForDetail = computed(() => {
|
||||
const kbItems = computed(() => props.items.filter(item => item.type === 'kb'));
|
||||
const fileItems = computed(() => props.items.filter(item => item.type === 'file'));
|
||||
|
||||
const mentionGroupDefs = computed<Array<{ type: MentionItemType; label: string; icon: string }>>(() => [
|
||||
{ type: 'kb', label: t('common.knowledgeBase'), icon: 'folder' },
|
||||
{ type: 'tag', label: '标签', icon: 'tag' },
|
||||
{ type: 'mcp', label: 'MCP', icon: 'tools' },
|
||||
{ type: 'skill', label: 'Skills', icon: 'bookmark' },
|
||||
{ type: 'file', label: t('common.file'), icon: 'file' },
|
||||
]);
|
||||
|
||||
const mentionGroups = computed(() => {
|
||||
let offset = 0;
|
||||
return mentionGroupDefs.value.map(def => {
|
||||
const items = props.items.filter(item => item.type === def.type);
|
||||
const loadedCount = items.length;
|
||||
const count = props.groupCounts?.[def.type] ?? loadedCount;
|
||||
const group = { ...def, items, offset, count, loadedCount };
|
||||
offset += items.length;
|
||||
return group;
|
||||
});
|
||||
});
|
||||
|
||||
const formatGroupCount = (group: { type: MentionItemType; count: number; loadedCount: number }) => {
|
||||
if (props.groupCounts?.[group.type] != null) {
|
||||
return props.groupCounts[group.type]!;
|
||||
}
|
||||
if (group.type === 'file' && props.hasMore) {
|
||||
return `${group.loadedCount}+`;
|
||||
}
|
||||
return group.count;
|
||||
};
|
||||
|
||||
const groupTabs = computed(() => mentionGroups.value.filter(group => group.count > 0));
|
||||
const groupRows = computed(() => groupTabs.value);
|
||||
const isFlatMode = computed(() => (props.query ?? '').trim().length > 0);
|
||||
const currentGroup = computed(() => mentionGroups.value.find(group => group.type === currentGroupType.value));
|
||||
const extraGroups = computed(() => mentionGroups.value.filter(group =>
|
||||
group.type !== 'kb' && group.type !== 'file' && group.count > 0
|
||||
));
|
||||
const activeExtraGroups = computed(() => {
|
||||
if (isFlatMode.value) return extraGroups.value;
|
||||
return extraGroups.value.filter(group => group.type === currentGroupType.value);
|
||||
});
|
||||
const fileGroupOffset = computed(() => mentionGroups.value.find(group => group.type === 'file')?.offset || 0);
|
||||
|
||||
const enterGroup = (type: MentionItemType) => {
|
||||
const group = mentionGroups.value.find(item => item.type === type && item.count > 0);
|
||||
if (!group || !listRef.value) return;
|
||||
|
||||
currentGroupType.value = type;
|
||||
emit('update:activeIndex', group.offset);
|
||||
|
||||
nextTick(() => {
|
||||
if (!listRef.value) return;
|
||||
listRef.value.scrollTo({
|
||||
top: 0,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const leaveGroup = () => {
|
||||
if (isFlatMode.value) return false;
|
||||
if (!currentGroupType.value) return false;
|
||||
const rowIndex = groupRows.value.findIndex(group => group.type === currentGroupType.value);
|
||||
groupActiveIndex.value = Math.max(0, rowIndex);
|
||||
currentGroupType.value = null;
|
||||
nextTick(() => {
|
||||
if (listRef.value) listRef.value.scrollTop = 0;
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
const updateActiveGroupFromIndex = (index: number) => {
|
||||
const group = groupTabs.value.find(item => index >= item.offset && index < item.offset + item.count);
|
||||
if (group) currentGroupType.value = group.type;
|
||||
};
|
||||
|
||||
watch(groupTabs, (groups) => {
|
||||
if (groupActiveIndex.value >= groups.length) {
|
||||
groupActiveIndex.value = Math.max(0, groups.length - 1);
|
||||
}
|
||||
});
|
||||
|
||||
const moveActive = (delta: number) => {
|
||||
if (isFlatMode.value) {
|
||||
const next = Math.min(props.items.length - 1, Math.max(0, props.activeIndex + delta));
|
||||
emit('update:activeIndex', next);
|
||||
scrollToItem(next);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentGroupType.value) {
|
||||
const maxIndex = Math.max(0, groupRows.value.length - 1);
|
||||
groupActiveIndex.value = Math.min(maxIndex, Math.max(0, groupActiveIndex.value + delta));
|
||||
return;
|
||||
}
|
||||
|
||||
const group = currentGroup.value;
|
||||
if (!group) return;
|
||||
const currentLocalIndex = props.activeIndex - group.offset;
|
||||
const nextLocalIndex = Math.min(group.count - 1, Math.max(0, currentLocalIndex + delta));
|
||||
emit('update:activeIndex', group.offset + nextLocalIndex);
|
||||
scrollToItem(nextLocalIndex);
|
||||
};
|
||||
|
||||
const confirmActive = () => {
|
||||
if (isFlatMode.value) {
|
||||
const item = props.items[props.activeIndex];
|
||||
if (item) emit('select', item);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentGroupType.value) {
|
||||
const group = groupRows.value[groupActiveIndex.value];
|
||||
if (group) enterGroup(group.type);
|
||||
return;
|
||||
}
|
||||
|
||||
const group = currentGroup.value;
|
||||
if (!group) return;
|
||||
const localIndex = props.activeIndex - group.offset;
|
||||
const item = group.items[localIndex];
|
||||
if (item) emit('select', item);
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
moveActive,
|
||||
confirmActive,
|
||||
leaveGroup,
|
||||
});
|
||||
|
||||
async function fetchKbDetail(item: { id: string }) {
|
||||
if (detailCache.value[item.id]?.data || detailCache.value[item.id]?.loading) return;
|
||||
detailCache.value = { ...detailCache.value, [item.id]: { loading: true } };
|
||||
@@ -251,33 +494,51 @@ const onScroll = (e: Event) => {
|
||||
|
||||
const target = e.target as HTMLElement;
|
||||
const { scrollTop, scrollHeight, clientHeight } = target;
|
||||
if (scrollHeight - scrollTop - clientHeight < 50 && props.hasMore && !props.loading) {
|
||||
if ((currentGroupType.value === 'file' || isFlatMode.value) && scrollHeight - scrollTop - clientHeight < 50 && props.hasMore && !props.loading) {
|
||||
emit('loadMore');
|
||||
}
|
||||
};
|
||||
|
||||
watch(() => props.activeIndex, (newIndex) => {
|
||||
scrollToItem(newIndex);
|
||||
if (isFlatMode.value) {
|
||||
scrollToItem(newIndex);
|
||||
return;
|
||||
}
|
||||
if (currentGroupType.value) {
|
||||
updateActiveGroupFromIndex(newIndex);
|
||||
const group = currentGroup.value;
|
||||
if (group) scrollToItem(newIndex - group.offset);
|
||||
}
|
||||
});
|
||||
|
||||
watch(isFlatMode, (flat) => {
|
||||
if (flat) {
|
||||
currentGroupType.value = null;
|
||||
nextTick(() => {
|
||||
if (listRef.value) listRef.value.scrollTop = 0;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => props.visible, (newVisible) => {
|
||||
if (newVisible) {
|
||||
nextTick(() => {
|
||||
if (menuRef.value) menuRef.value.scrollTop = 0;
|
||||
scrollToItem(props.activeIndex);
|
||||
if (listRef.value) listRef.value.scrollTop = 0;
|
||||
currentGroupType.value = null;
|
||||
groupActiveIndex.value = 0;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const scrollToItem = (index: number) => {
|
||||
nextTick(() => {
|
||||
if (!menuRef.value) return;
|
||||
if (!listRef.value) return;
|
||||
|
||||
const items = menuRef.value.querySelectorAll('.mention-item');
|
||||
const items = listRef.value.querySelectorAll('.mention-item');
|
||||
if (!items || items.length <= index) return;
|
||||
|
||||
const activeItem = items[index] as HTMLElement;
|
||||
const menu = menuRef.value;
|
||||
const menu = listRef.value;
|
||||
|
||||
if (activeItem) {
|
||||
const menuRect = menu.getBoundingClientRect();
|
||||
@@ -304,12 +565,100 @@ const scrollToItem = (index: number) => {
|
||||
border: 1px solid var(--td-component-stroke, #e7e9eb);
|
||||
border-radius: var(--td-radius-extraLarge, 12px);
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||
width: 288px;
|
||||
max-height: 344px;
|
||||
overflow-y: auto;
|
||||
width: 220px;
|
||||
max-height: 388px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.mention-list {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.mention-group-entry,
|
||||
.mention-back-row {
|
||||
width: calc(100% - 12px);
|
||||
min-height: 32px;
|
||||
margin: 1px 6px;
|
||||
padding: 0 8px;
|
||||
border: 0;
|
||||
border-radius: var(--td-radius-medium, 6px);
|
||||
background: transparent;
|
||||
color: var(--td-text-color-primary, #333);
|
||||
font-family: var(--app-font-family);
|
||||
font-size: var(--td-font-size-body-medium, 14px);
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
cursor: pointer;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.mention-group-entry:hover,
|
||||
.mention-group-entry.active,
|
||||
.mention-back-row:hover {
|
||||
background: var(--td-bg-color-secondarycontainer, #f3f3f3);
|
||||
}
|
||||
|
||||
.mention-group-entry__icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.mention-group-entry__label,
|
||||
.mention-back-row span {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-align: left;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
.mention-group-entry__count {
|
||||
flex-shrink: 0;
|
||||
min-width: 18px;
|
||||
padding: 0 6px;
|
||||
border-radius: 999px;
|
||||
background: var(--td-bg-color-secondarycontainer, #f3f3f3);
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
font-size: var(--td-font-size-mark-small, 12px);
|
||||
line-height: 18px;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.mention-group-entry__arrow {
|
||||
flex-shrink: 0;
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.mention-back-row {
|
||||
min-height: 30px;
|
||||
margin-bottom: 4px;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
border-bottom: 1px solid var(--td-component-stroke, #f0f0f0);
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.mention-back-row span {
|
||||
font-size: var(--td-font-size-body-medium, 14px);
|
||||
}
|
||||
|
||||
.mention-group {
|
||||
@@ -332,8 +681,8 @@ const scrollToItem = (index: number) => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-height: 40px;
|
||||
padding: 7px 10px;
|
||||
min-height: 32px;
|
||||
padding: 4px 8px;
|
||||
margin: 1px 6px;
|
||||
box-sizing: border-box;
|
||||
cursor: pointer;
|
||||
@@ -417,7 +766,7 @@ const scrollToItem = (index: number) => {
|
||||
}
|
||||
|
||||
.name {
|
||||
font-weight: 500;
|
||||
font-weight: 400;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -47,6 +47,22 @@
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&.tag-tag .tag_icon {
|
||||
color: #9f7aea;
|
||||
}
|
||||
|
||||
&.mcp-tag .tag_icon {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
&.skill-tag .tag_icon {
|
||||
color: #7c3aed;
|
||||
}
|
||||
|
||||
&.tool-tag .tag_icon {
|
||||
color: #b7791f;
|
||||
}
|
||||
|
||||
.tag_icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -15,6 +15,9 @@ interface Settings {
|
||||
selectedKnowledgeBases: string[]; // 当前选中的知识库ID列表
|
||||
selectedFiles: string[]; // 当前选中的文件ID列表
|
||||
selectedFileKbMap: Record<string, string>; // 文件ID -> 知识库ID,用于刷新后带 kb_id 拉取共享知识库文件
|
||||
selectedTags: Array<{ id: string; name: string; kbId: string; kbName?: string }>;
|
||||
selectedMCPServices: string[];
|
||||
selectedSkills: string[];
|
||||
modelConfig: ModelConfig; // 模型配置
|
||||
ollamaConfig: OllamaConfig; // Ollama配置
|
||||
webSearchEnabled: boolean; // 网络搜索是否启用
|
||||
@@ -81,6 +84,9 @@ const defaultSettings: Settings = {
|
||||
selectedKnowledgeBases: [], // 默认为空数组
|
||||
selectedFiles: [], // 默认为空数组
|
||||
selectedFileKbMap: {}, // 文件ID -> 知识库ID
|
||||
selectedTags: [],
|
||||
selectedMCPServices: [],
|
||||
selectedSkills: [],
|
||||
modelConfig: {
|
||||
chatModels: [],
|
||||
embeddingModels: [],
|
||||
@@ -108,6 +114,10 @@ function loadAndReconcileSettings(): Settings {
|
||||
const loaded = JSON.parse(
|
||||
localStorage.getItem("WeKnora_settings") || JSON.stringify(defaultSettings),
|
||||
) as Settings;
|
||||
loaded.selectedTags ||= [];
|
||||
loaded.selectedMCPServices ||= [];
|
||||
loaded.selectedSkills ||= loaded.selectedTools || [];
|
||||
loaded.selectedFileKbMap ||= {};
|
||||
if (reconcileBuiltinAgentMode(loaded)) {
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(loaded));
|
||||
}
|
||||
@@ -406,6 +416,53 @@ export const useSettingsStore = defineStore("settings", {
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
addTag(tag: { id: string; name: string; kbId: string; kbName?: string }) {
|
||||
if (!this.settings.selectedTags) this.settings.selectedTags = [];
|
||||
if (!this.settings.selectedTags.some(t => t.id === tag.id && t.kbId === tag.kbId)) {
|
||||
this.settings.selectedTags.push(tag);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
removeTag(tagId: string, kbId?: string) {
|
||||
if (!this.settings.selectedTags) return;
|
||||
this.settings.selectedTags = this.settings.selectedTags.filter(t => !(t.id === tagId && (!kbId || t.kbId === kbId)));
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
clearTags() {
|
||||
this.settings.selectedTags = [];
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
addMCPService(serviceId: string) {
|
||||
if (!this.settings.selectedMCPServices) this.settings.selectedMCPServices = [];
|
||||
if (!this.settings.selectedMCPServices.includes(serviceId)) {
|
||||
this.settings.selectedMCPServices.push(serviceId);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
removeMCPService(serviceId: string) {
|
||||
if (!this.settings.selectedMCPServices) return;
|
||||
this.settings.selectedMCPServices = this.settings.selectedMCPServices.filter(id => id !== serviceId);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
addSkill(skillName: string) {
|
||||
if (!this.settings.selectedSkills) this.settings.selectedSkills = [];
|
||||
if (!this.settings.selectedSkills.includes(skillName)) {
|
||||
this.settings.selectedSkills.push(skillName);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
removeSkill(skillName: string) {
|
||||
if (!this.settings.selectedSkills) return;
|
||||
this.settings.selectedSkills = this.settings.selectedSkills.filter(name => name !== skillName);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
setFileKbMap(updates: Record<string, string>) {
|
||||
if (!this.settings.selectedFileKbMap) this.settings.selectedFileKbMap = {};
|
||||
Object.assign(this.settings.selectedFileKbMap, updates);
|
||||
@@ -420,6 +477,22 @@ export const useSettingsStore = defineStore("settings", {
|
||||
getSelectedFiles(): string[] {
|
||||
return this.settings.selectedFiles || [];
|
||||
},
|
||||
|
||||
/** Scope for suggested-questions API (KB / file / tag @mentions). */
|
||||
getSuggestedQuestionsParams(limit = 6) {
|
||||
const selectedKBs = this.getSelectedKnowledgeBases();
|
||||
const selectedFiles = this.getSelectedFiles();
|
||||
const tags = this.settings.selectedTags || [];
|
||||
const tagIds = [...new Set(tags.map((t) => t.id).filter(Boolean))];
|
||||
const tagKbIds = [...new Set(tags.map((t) => t.kbId).filter(Boolean))];
|
||||
const kbIds = [...new Set([...selectedKBs, ...tagKbIds])];
|
||||
return {
|
||||
knowledge_base_ids: kbIds.length > 0 ? kbIds : undefined,
|
||||
knowledge_ids: selectedFiles.length > 0 ? selectedFiles : undefined,
|
||||
tag_ids: tagIds.length > 0 ? tagIds : undefined,
|
||||
limit,
|
||||
};
|
||||
},
|
||||
|
||||
// 选择智能体(sourceTenantId 仅在使用共享智能体时传入)
|
||||
selectAgent(agentId: string, sourceTenantId?: string | null) {
|
||||
@@ -438,6 +511,9 @@ export const useSettingsStore = defineStore("settings", {
|
||||
this.settings.selectedKnowledgeBases = [];
|
||||
this.settings.selectedFiles = [];
|
||||
this.settings.selectedFileKbMap = {};
|
||||
this.settings.selectedTags = [];
|
||||
this.settings.selectedMCPServices = [];
|
||||
this.settings.selectedSkills = [];
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
@@ -499,6 +575,28 @@ export const useSettingsStore = defineStore("settings", {
|
||||
// selectedFileKbMap 此时无法重建(state 里没存 KB 归属),交给前端按
|
||||
// 需要 lazy 拉取。保留 store 现值,避免误删用户刚加进来的文件映射。
|
||||
}
|
||||
if (Array.isArray(state.mentioned_items)) {
|
||||
this.settings.selectedTags = state.mentioned_items
|
||||
.filter(item => item.type === "tag" && item.id && item.kb_id)
|
||||
.map(item => ({ id: item.id, name: item.name || item.id, kbId: item.kb_id!, kbName: item.kb_name }));
|
||||
} else if (Array.isArray(state.tag_ids)) {
|
||||
const existing = this.settings.selectedTags || [];
|
||||
this.settings.selectedTags = existing.filter(tag => state.tag_ids?.includes(tag.id));
|
||||
}
|
||||
if (Array.isArray(state.mcp_service_ids)) {
|
||||
this.settings.selectedMCPServices = [...state.mcp_service_ids];
|
||||
} else if (Array.isArray(state.mentioned_items)) {
|
||||
this.settings.selectedMCPServices = state.mentioned_items
|
||||
.filter(item => item.type === "mcp" && item.id)
|
||||
.map(item => item.id);
|
||||
}
|
||||
if (Array.isArray(state.skill_names)) {
|
||||
this.settings.selectedSkills = [...state.skill_names];
|
||||
} else if (Array.isArray(state.mentioned_items)) {
|
||||
this.settings.selectedSkills = state.mentioned_items
|
||||
.filter(item => item.type === "skill" && item.id)
|
||||
.map(item => item.skill_name || item.id);
|
||||
}
|
||||
if (typeof state.web_search_enabled === "boolean") {
|
||||
this.settings.webSearchEnabled = state.web_search_enabled;
|
||||
}
|
||||
@@ -526,6 +624,16 @@ export interface SessionLastRequestStatePayload {
|
||||
model_id?: string;
|
||||
knowledge_base_ids?: string[];
|
||||
knowledge_ids?: string[];
|
||||
tag_ids?: string[];
|
||||
mcp_service_ids?: string[];
|
||||
skill_names?: string[];
|
||||
mentioned_items?: Array<{
|
||||
id: string;
|
||||
name?: string;
|
||||
type: string;
|
||||
kb_id?: string;
|
||||
kb_name?: string;
|
||||
skill_name?: string;
|
||||
}>;
|
||||
web_search_enabled?: boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
export type MentionItemType = 'kb' | 'file' | 'tag' | 'mcp' | 'skill';
|
||||
|
||||
export interface MentionItem {
|
||||
id: string;
|
||||
name: string;
|
||||
type: MentionItemType;
|
||||
group?: string;
|
||||
description?: string;
|
||||
kbType?: 'document' | 'faq';
|
||||
count?: number;
|
||||
kbName?: string;
|
||||
kbId?: string;
|
||||
orgName?: string;
|
||||
serviceId?: string;
|
||||
serviceName?: string;
|
||||
skillName?: string;
|
||||
isAgentConfigured?: boolean;
|
||||
}
|
||||
|
||||
export interface MentionRequestItem {
|
||||
id: string;
|
||||
name: string;
|
||||
type: MentionItemType;
|
||||
kb_type?: 'document' | 'faq';
|
||||
kb_id?: string;
|
||||
kb_name?: string;
|
||||
service_id?: string;
|
||||
skill_name?: string;
|
||||
}
|
||||
@@ -4,12 +4,12 @@
|
||||
<!-- 显示@的知识库和文件(非 Agent 模式下显示) -->
|
||||
<div v-if="!session.isAgentMode && mentionedItems && mentionedItems.length > 0" class="mentioned_items">
|
||||
<span v-for="item in mentionedItems" :key="item.id" class="mentioned_tag" :class="[
|
||||
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
||||
mentionTagClass(item)
|
||||
]">
|
||||
<span class="tag_icon">
|
||||
<t-icon v-if="item.type === 'kb'"
|
||||
:name="item.kb_type === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
<t-icon v-else name="file" />
|
||||
<t-icon v-else :name="mentionTagIcon(item)" />
|
||||
</span>
|
||||
<span class="tag_name">{{ item.name }}</span>
|
||||
</span>
|
||||
@@ -106,6 +106,18 @@ import { vStableHtml } from '@/directives/stableHtml';
|
||||
|
||||
ensureMermaidInitialized();
|
||||
|
||||
const mentionTagClass = (item) => {
|
||||
if (item.type === 'kb') return item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag';
|
||||
return `${item.type || 'file'}-tag`;
|
||||
};
|
||||
|
||||
const mentionTagIcon = (item) => {
|
||||
if (item.type === 'tag') return 'tag';
|
||||
if (item.type === 'mcp') return 'tools';
|
||||
if (item.type === 'skill') return 'bookmark';
|
||||
return 'file';
|
||||
};
|
||||
|
||||
const emit = defineEmits(['scroll-bottom'])
|
||||
const { t } = useI18n()
|
||||
const uiStore = useUIStore();
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
<!-- 显示@的知识库和文件 -->
|
||||
<div v-if="mentioned_items && mentioned_items.length > 0" class="mentioned_items">
|
||||
<span v-for="item in mentioned_items" :key="item.id" class="mentioned_tag" :class="[
|
||||
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
||||
mentionTagClass(item)
|
||||
]">
|
||||
<span class="tag_icon">
|
||||
<t-icon v-if="item.type === 'kb'" :name="item.kb_type === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
<t-icon v-else name="file" />
|
||||
<t-icon v-else :name="mentionTagIcon(item)" />
|
||||
</span>
|
||||
<span class="tag_name">{{ item.name }}</span>
|
||||
</span>
|
||||
@@ -51,6 +51,18 @@ import { useI18n } from 'vue-i18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const mentionTagClass = (item) => {
|
||||
if (item.type === 'kb') return item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag';
|
||||
return `${item.type || 'file'}-tag`;
|
||||
};
|
||||
|
||||
const mentionTagIcon = (item) => {
|
||||
if (item.type === 'tag') return 'tag';
|
||||
if (item.type === 'mcp') return 'tools';
|
||||
if (item.type === 'skill') return 'bookmark';
|
||||
return 'file';
|
||||
};
|
||||
|
||||
const props = defineProps({
|
||||
content: {
|
||||
type: String,
|
||||
|
||||
@@ -275,13 +275,7 @@ const fetchSuggestedQuestions = async () => {
|
||||
try {
|
||||
const agentId = useSettingsStoreInstance.selectedAgentId;
|
||||
if (!agentId) return;
|
||||
const selectedKBs = useSettingsStoreInstance.getSelectedKnowledgeBases();
|
||||
const selectedFiles = useSettingsStoreInstance.getSelectedFiles();
|
||||
const res = await getSuggestedQuestions(agentId, {
|
||||
knowledge_base_ids: selectedKBs.length > 0 ? selectedKBs : undefined,
|
||||
knowledge_ids: selectedFiles.length > 0 ? selectedFiles : undefined,
|
||||
limit: 6,
|
||||
});
|
||||
const res = await getSuggestedQuestions(agentId, useSettingsStoreInstance.getSuggestedQuestionsParams(6));
|
||||
if (fetchId === suggestedQuestionsFetchId) {
|
||||
suggestedQuestions.value = res?.data?.questions || [];
|
||||
}
|
||||
@@ -312,18 +306,16 @@ const debouncedFetchSuggestions = () => {
|
||||
suggestedDebounceTimer = setTimeout(() => { fetchSuggestedQuestionsIfNeeded(); }, 300);
|
||||
};
|
||||
|
||||
// 监听 Agent / 知识库 / 文件切换,重新获取推荐问题
|
||||
// 监听 Agent / 知识库 / 文件 / 标签 / MCP / Skill @mention,重新获取推荐问题
|
||||
watch(
|
||||
() => useSettingsStoreInstance.selectedAgentId,
|
||||
debouncedFetchSuggestions,
|
||||
);
|
||||
watch(
|
||||
() => useSettingsStoreInstance.settings.selectedKnowledgeBases,
|
||||
debouncedFetchSuggestions,
|
||||
{ deep: true },
|
||||
);
|
||||
watch(
|
||||
() => useSettingsStoreInstance.settings.selectedFiles,
|
||||
() => ({
|
||||
agentId: useSettingsStoreInstance.selectedAgentId,
|
||||
kbs: useSettingsStoreInstance.settings.selectedKnowledgeBases,
|
||||
files: useSettingsStoreInstance.settings.selectedFiles,
|
||||
tags: useSettingsStoreInstance.settings.selectedTags,
|
||||
mcps: useSettingsStoreInstance.settings.selectedMCPServices,
|
||||
skills: useSettingsStoreInstance.settings.selectedSkills,
|
||||
}),
|
||||
debouncedFetchSuggestions,
|
||||
{ deep: true },
|
||||
);
|
||||
@@ -654,6 +646,9 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
}
|
||||
const kbIds = [...kbIdSet];
|
||||
const knowledgeIds = [...fileIdSet];
|
||||
const tagIds = [...new Set((mentionedItems || []).filter(item => item.type === 'tag' && item.id).map(item => item.id))];
|
||||
const mcpServiceIds = [...new Set((mentionedItems || []).filter(item => item.type === 'mcp' && item.id).map(item => item.id))];
|
||||
const skillNames = [...new Set((mentionedItems || []).filter(item => item.type === 'skill' && item.id).map(item => item.skill_name || item.id))];
|
||||
|
||||
// Get selected agent ID (backend resolves shared agent and its tenant from share relation)
|
||||
const selectedAgentId = props.embeddedMode ? props.agentId : (useSettingsStoreInstance.selectedAgentId || '');
|
||||
@@ -661,7 +656,8 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
const endpoint = agentEnabled ? '/api/v1/agent-chat' : '/api/v1/knowledge-chat';
|
||||
|
||||
// Get selected MCP services from settings store (if available)
|
||||
const mcpServiceIds = props.embeddedMode ? [] : (useSettingsStoreInstance.settings.selectedMCPServices || []);
|
||||
const selectedMcpServiceIds = props.embeddedMode ? [] : (useSettingsStoreInstance.settings.selectedMCPServices || []);
|
||||
const requestMcpServiceIds = mcpServiceIds.length > 0 ? mcpServiceIds : selectedMcpServiceIds;
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
@@ -672,7 +668,9 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
web_search_enabled: webSearchEnabled,
|
||||
enable_memory: enableMemoryOverride,
|
||||
summary_model_id: modelId,
|
||||
mcp_service_ids: mcpServiceIds,
|
||||
mcp_service_ids: requestMcpServiceIds,
|
||||
skill_names: skillNames,
|
||||
tag_ids: tagIds,
|
||||
mentioned_items: mentionedItems,
|
||||
images: imageAttachments.length > 0 ? imageAttachments : undefined,
|
||||
attachment_uploads: attachmentUploads.length > 0 ? attachmentUploads : undefined,
|
||||
|
||||
@@ -139,13 +139,7 @@ const fetchSuggestedQuestions = async () => {
|
||||
try {
|
||||
const agentId = settingsStore.selectedAgentId;
|
||||
if (!agentId) return;
|
||||
const selectedKBs = settingsStore.getSelectedKnowledgeBases();
|
||||
const selectedFiles = settingsStore.getSelectedFiles();
|
||||
const res = await getSuggestedQuestions(agentId, {
|
||||
knowledge_base_ids: selectedKBs.length > 0 ? selectedKBs : undefined,
|
||||
knowledge_ids: selectedFiles.length > 0 ? selectedFiles : undefined,
|
||||
limit: 6,
|
||||
});
|
||||
const res = await getSuggestedQuestions(agentId, settingsStore.getSuggestedQuestionsParams(6));
|
||||
if (fetchId === suggestedQuestionsFetchId) {
|
||||
sqCardsRevealed.value = false;
|
||||
sqRenderKey.value++;
|
||||
@@ -169,10 +163,19 @@ const debouncedFetch = () => {
|
||||
debounceTimer = setTimeout(() => { fetchSuggestedQuestions(); }, 300);
|
||||
};
|
||||
|
||||
// 监听 Agent / 知识库 / 文件切换
|
||||
watch(() => settingsStore.selectedAgentId, debouncedFetch);
|
||||
watch(() => settingsStore.settings.selectedKnowledgeBases, debouncedFetch, { deep: true });
|
||||
watch(() => settingsStore.settings.selectedFiles, debouncedFetch, { deep: true });
|
||||
// 监听 Agent / 知识库 / 文件 / 标签 / MCP / Skill @mention
|
||||
watch(
|
||||
() => ({
|
||||
agentId: settingsStore.selectedAgentId,
|
||||
kbs: settingsStore.settings.selectedKnowledgeBases,
|
||||
files: settingsStore.settings.selectedFiles,
|
||||
tags: settingsStore.settings.selectedTags,
|
||||
mcps: settingsStore.settings.selectedMCPServices,
|
||||
skills: settingsStore.settings.selectedSkills,
|
||||
}),
|
||||
debouncedFetch,
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
onMounted(() => { fetchSuggestedQuestions(); });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user