refactor(agent): fix grep scope loss and consolidate per-turn @mention scoping

- Fix grep_chunks dropping the full-KB scope when a turn mixes @KB with
  @tag/@file: extract scopeClause and OR knowledge-ID and (kb,tenant)
  predicates together, matching knowledge_search's fan-out.
- Consolidate the three scattered per-request @Skill/@MCP scope blocks in
  buildAgentConfig into applyPerRequestSkillScope / applyPerRequestMCPScope,
  each narrowing the whitelist and computing the must_use pin in one place.
- Dedupe the two identical selection-mode normalizers in Input-field.vue.
- Fix knowledge_create_test passing "" for the tagIDs []string parameter,
  which made the whole service test package fail to compile.
- Add unit tests for scopeClause and the per-request scope helpers.
This commit is contained in:
wizardchen
2026-06-29 17:17:38 +08:00
committed by lyingbug
parent b86efe3f92
commit d24e830c85
6 changed files with 203 additions and 83 deletions
+6 -9
View File
@@ -313,13 +313,14 @@ const agentAllowedTools = computed<string[]>(() => {
return currentAgentConfig.value?.allowed_tools || [];
});
const normalizeMCPSelectionMode = (mode?: string): 'all' | 'selected' | 'none' => {
type SelectionMode = 'all' | 'selected' | 'none';
const normalizeSelectionMode = (mode?: string): SelectionMode => {
return mode === 'all' || mode === 'selected' || mode === 'none' ? mode : 'none';
};
const agentMCPSelectionMode = computed<'all' | 'selected' | 'none'>(() => {
const agentMCPSelectionMode = computed<SelectionMode>(() => {
if (!settingsStore.isAgentStreamMode || !hasAgentConfig.value) return 'none';
return normalizeMCPSelectionMode(currentAgentConfig.value?.mcp_selection_mode);
return normalizeSelectionMode(currentAgentConfig.value?.mcp_selection_mode);
});
const agentMCPServiceIds = computed<string[]>(() => {
@@ -335,13 +336,9 @@ const isMCPAllowedByAgent = (service: MCPService) => {
return true;
};
const normalizeSkillsSelectionMode = (mode?: string): 'all' | 'selected' | 'none' => {
return mode === 'all' || mode === 'selected' || mode === 'none' ? mode : 'none';
};
const agentSkillsSelectionMode = computed<'all' | 'selected' | 'none'>(() => {
const agentSkillsSelectionMode = computed<SelectionMode>(() => {
if (!settingsStore.isAgentStreamMode || !hasAgentConfig.value) return 'none';
return normalizeSkillsSelectionMode(currentAgentConfig.value?.skills_selection_mode);
return normalizeSelectionMode(currentAgentConfig.value?.skills_selection_mode);
});
const agentSelectedSkills = computed<string[]>(() => {