fix(agent): harden @mention scope and simplify must_use hints
Tighten per-turn @MCP/@Skill/@tag handling after review: enforce agent MCP/Skill whitelist, ignore mentions when selection mode is none, tag-scope grep_chunks, and simplified English must_use lines without tool dumps. Skip persisting scope envelopes to history rendered_content.
This commit is contained in:
@@ -289,6 +289,9 @@ const isKnowledgeBaseDisabledByAgent = computed(() => {
|
||||
return agentKBSelectionMode.value === 'none';
|
||||
});
|
||||
const isMentionDisabled = computed(() => {
|
||||
if (settingsStore.isAgentStreamMode && isKnowledgeBaseDisabledByAgent.value) {
|
||||
return agentMCPSelectionMode.value === 'none' && agentSkillsSelectionMode.value === 'none';
|
||||
}
|
||||
return isKnowledgeBaseLockedByAgent.value && !settingsStore.isAgentStreamMode;
|
||||
});
|
||||
|
||||
@@ -354,6 +357,30 @@ const isSkillAllowedByAgent = (skillName: string) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
// 切换智能体时清理不允许的 MCP / Skill @mention
|
||||
watch([selectedAgentId, agentMCPSelectionMode, agentSkillsSelectionMode], ([newAgentId], [oldAgentId]) => {
|
||||
if (settingsStore._isApplyingSessionState) return;
|
||||
if (newAgentId === oldAgentId || oldAgentId === undefined) return;
|
||||
|
||||
const mcpMode = agentMCPSelectionMode.value;
|
||||
if (mcpMode === 'none') {
|
||||
settingsStore.settings.selectedMCPServices = [];
|
||||
} else if (mcpMode === 'selected') {
|
||||
const allowed = new Set(agentMCPServiceIds.value);
|
||||
settingsStore.settings.selectedMCPServices = (settingsStore.settings.selectedMCPServices || [])
|
||||
.filter(id => allowed.has(id));
|
||||
}
|
||||
|
||||
const skillsMode = agentSkillsSelectionMode.value;
|
||||
if (skillsMode === 'none') {
|
||||
settingsStore.settings.selectedSkills = [];
|
||||
} else if (skillsMode === 'selected') {
|
||||
const allowed = new Set(agentSelectedSkills.value);
|
||||
settingsStore.settings.selectedSkills = (settingsStore.settings.selectedSkills || [])
|
||||
.filter(name => allowed.has(name));
|
||||
}
|
||||
});
|
||||
|
||||
// 从 KB 对象里抽能力位,优先用 backend 显式的 capabilities 字段;否则回退到 indexing_strategy,
|
||||
// 最后拿 kb.type === 'faq' 兜底。shared / owned / agent-scope 三路的 KB 响应结构一致。
|
||||
const kbToScopeCaps = (kb: any): Partial<ScopeCapabilities> => {
|
||||
@@ -519,7 +546,9 @@ const selectedFiles = computed(() => {
|
||||
});
|
||||
|
||||
const skillMentionItems = computed<MentionItem[]>(() => {
|
||||
return selectedSkillNames.value.map((name: string) => {
|
||||
return selectedSkillNames.value
|
||||
.filter((name: string) => isSkillAllowedByAgent(name))
|
||||
.map((name: string) => {
|
||||
const skill = editorResources.skills.find(s => s.name === name);
|
||||
return {
|
||||
id: name,
|
||||
@@ -1237,7 +1266,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
mentionGroupCounts.value.kb = kbItems.length;
|
||||
|
||||
const tagKeyword = q.trim();
|
||||
const tagSources = availableKbs.slice(0, 20);
|
||||
const tagSources = availableKbs;
|
||||
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 });
|
||||
@@ -1252,6 +1281,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
||||
}));
|
||||
}));
|
||||
tagItems = tagResults.flat();
|
||||
mentionGroupCounts.value.tag = tagItems.length;
|
||||
} catch (e) {
|
||||
console.error('[Mention] listKnowledgeTags error:', e);
|
||||
tagItems = [];
|
||||
|
||||
@@ -576,9 +576,18 @@ export const useSettingsStore = defineStore("settings", {
|
||||
// 需要 lazy 拉取。保留 store 现值,避免误删用户刚加进来的文件映射。
|
||||
}
|
||||
if (Array.isArray(state.mentioned_items)) {
|
||||
this.settings.selectedTags = state.mentioned_items
|
||||
const fromMentions = 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 }));
|
||||
const covered = new Set(fromMentions.map(t => t.id));
|
||||
const orphanTagIds = (state.tag_ids || []).filter(id => id && !covered.has(id));
|
||||
if (orphanTagIds.length > 0 && Array.isArray(state.knowledge_base_ids) && state.knowledge_base_ids.length === 1) {
|
||||
const kbId = state.knowledge_base_ids[0];
|
||||
orphanTagIds.forEach(id => {
|
||||
fromMentions.push({ id, name: id, kbId, kbName: undefined });
|
||||
});
|
||||
}
|
||||
this.settings.selectedTags = fromMentions;
|
||||
} else if (Array.isArray(state.tag_ids)) {
|
||||
const existing = this.settings.selectedTags || [];
|
||||
this.settings.selectedTags = existing.filter(tag => state.tag_ids?.includes(tag.id));
|
||||
|
||||
@@ -655,9 +655,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 selectedMcpServiceIds = props.embeddedMode ? [] : (useSettingsStoreInstance.settings.selectedMCPServices || []);
|
||||
const requestMcpServiceIds = mcpServiceIds.length > 0 ? mcpServiceIds : selectedMcpServiceIds;
|
||||
const requestMcpServiceIds = agentEnabled ? mcpServiceIds : [];
|
||||
const requestSkillNames = agentEnabled ? skillNames : [];
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
@@ -669,7 +668,7 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
enable_memory: enableMemoryOverride,
|
||||
summary_model_id: modelId,
|
||||
mcp_service_ids: requestMcpServiceIds,
|
||||
skill_names: skillNames,
|
||||
skill_names: requestSkillNames,
|
||||
tag_ids: tagIds,
|
||||
mentioned_items: mentionedItems,
|
||||
images: imageAttachments.length > 0 ? imageAttachments : undefined,
|
||||
|
||||
Reference in New Issue
Block a user