feat(agent): enhance suggested questions API with tag scopes

Update the SuggestedQuestionsRequest to include TagScopes for better filtering of knowledge items based on their parent knowledge bases. Modify related API documentation and frontend interfaces to accommodate the new structure. Ensure backend services handle the new tag scope logic correctly, including tests for the updated functionality.
This commit is contained in:
wizardchen
2026-07-17 10:16:58 +08:00
committed by lyingbug
parent c21c34b3c0
commit eedd7d4641
34 changed files with 1041 additions and 338 deletions
+7 -2
View File
@@ -362,12 +362,17 @@ export interface SuggestedQuestion {
// 根据智能体关联的知识库范围返回推荐问题,用于前端对话面板快捷提问
export function getSuggestedQuestions(
agentId: string,
params?: { knowledge_base_ids?: string[]; knowledge_ids?: string[]; tag_ids?: string[]; limit?: number }
params?: {
knowledge_base_ids?: string[];
knowledge_ids?: string[];
tag_scopes?: Array<{ knowledge_base_id: 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?.tag_scopes?.length) query.set('tag_scopes', JSON.stringify(params.tag_scopes));
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 : ''}`);
+13 -5
View File
@@ -470,13 +470,21 @@ export const useSettingsStore = defineStore("settings", {
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])];
const tagScopes = Object.entries(tags.reduce<Record<string, string[]>>((scopes, tag) => {
if (!tag.id || !tag.kbId) return scopes;
(scopes[tag.kbId] ||= []).push(tag.id);
return scopes;
}, {})).map(([knowledge_base_id, ids]) => ({
knowledge_base_id,
tag_ids: [...new Set(ids)],
}));
return {
knowledge_base_ids: kbIds.length > 0 ? kbIds : undefined,
// A tag's parent KB is only an ownership hint, not an explicit whole-KB
// selection. Keep it in tag_scopes so the backend cannot widen a tag to
// every document in that KB.
knowledge_base_ids: selectedKBs.length > 0 ? selectedKBs : undefined,
knowledge_ids: selectedFiles.length > 0 ? selectedFiles : undefined,
tag_ids: tagIds.length > 0 ? tagIds : undefined,
tag_scopes: tagScopes.length > 0 ? tagScopes : undefined,
limit,
};
},