-
Notifications
You must be signed in to change notification settings - Fork 71
refactor(CodeactAgentConfig): 调整配置类结构并优化搜索工具管理 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -148,19 +148,48 @@ private SearchResultSet executeUnifiedSearch(Map<String, Object> params, ToolCon | |||||||||||||||||
| String query = (String) params.get("query"); | ||||||||||||||||||
| Integer limit = params.containsKey("limit") ? ((Number) params.get("limit")).intValue() : 10; | ||||||||||||||||||
|
|
||||||||||||||||||
| // 解析要搜索的源类型列表 | ||||||||||||||||||
| List<SearchSourceType> sourceTypes = parseSourceTypes(params); | ||||||||||||||||||
| // 解析要搜索的源 keys (可以是类型名,也可以是 provider 名) | ||||||||||||||||||
| List<String> sourceKeys = parseSourceKeys(params); | ||||||||||||||||||
|
|
||||||||||||||||||
| log.info("UnifiedSearchCodeactTool#executeUnifiedSearch - reason=开始统一搜索, query={}, sourceTypes={}, limit={}", | ||||||||||||||||||
| query, sourceTypes, limit); | ||||||||||||||||||
| log.info("UnifiedSearchCodeactTool#executeUnifiedSearch - reason=开始统一搜索, query={}, sources={}, limit={}", | ||||||||||||||||||
| query, sourceKeys, limit); | ||||||||||||||||||
|
|
||||||||||||||||||
| // 并行搜索多个数据源 | ||||||||||||||||||
| List<SearchResultItem> allItems = new ArrayList<>(); | ||||||||||||||||||
| int successCount = 0; | ||||||||||||||||||
| int failureCount = 0; | ||||||||||||||||||
|
|
||||||||||||||||||
| for (SearchSourceType sourceType : sourceTypes) { | ||||||||||||||||||
| for (String key : sourceKeys) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| // 1. 尝试作为 Provider Name 匹配 | ||||||||||||||||||
| Optional<SearchProvider> namedProvider = searchProviders.stream() | ||||||||||||||||||
| .filter(p -> p.getName().equalsIgnoreCase(key)) | ||||||||||||||||||
| .findFirst(); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (namedProvider.isPresent()) { | ||||||||||||||||||
| // 按指定 Provider 名称搜索 | ||||||||||||||||||
| SearchProvider provider = namedProvider.get(); | ||||||||||||||||||
| // 当指定具体 Provider 时,尝试使用 CUSTOM 类型,或者该 Provider 支持的第一个类型 | ||||||||||||||||||
| // 这里为了简单,我们传递 CUSTOM 类型,如果 Provider 不处理 SourceType 也没关系 | ||||||||||||||||||
| SearchRequest request = buildSearchRequest(query, SearchSourceType.CUSTOM, limit); | ||||||||||||||||||
|
|
||||||||||||||||||
| List<SearchResultItem> items = provider.search(request); | ||||||||||||||||||
| allItems.addAll(items); | ||||||||||||||||||
| successCount++; | ||||||||||||||||||
| log.debug("UnifiedSearchCodeactTool#executeUnifiedSearch - reason=指定Provider搜索成功, provider={}, resultCount={}", | ||||||||||||||||||
| provider.getName(), items.size()); | ||||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // 2. 尝试作为 SourceType 匹配 | ||||||||||||||||||
| SearchSourceType sourceType; | ||||||||||||||||||
| try { | ||||||||||||||||||
| sourceType = SearchSourceType.valueOf(key.toUpperCase()); | ||||||||||||||||||
| } catch (IllegalArgumentException e) { | ||||||||||||||||||
| log.warn("UnifiedSearchCodeactTool#executeUnifiedSearch - reason=无效的源类型或Provider名称, key={}", key); | ||||||||||||||||||
| continue; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // 查找支持该源类型的 provider | ||||||||||||||||||
| List<SearchProvider> providers = searchProviders.stream() | ||||||||||||||||||
| .filter(p -> p.supports(sourceType)) | ||||||||||||||||||
|
|
@@ -185,8 +214,8 @@ private SearchResultSet executeUnifiedSearch(Map<String, Object> params, ToolCon | |||||||||||||||||
| } | ||||||||||||||||||
| catch (Exception e) { | ||||||||||||||||||
| failureCount++; | ||||||||||||||||||
| log.error("UnifiedSearchCodeactTool#executeUnifiedSearch - reason=单源搜索失败, sourceType={}, error={}", | ||||||||||||||||||
| sourceType, e.getMessage(), e); | ||||||||||||||||||
| log.error("UnifiedSearchCodeactTool#executeUnifiedSearch - reason=搜索执行失败, sourceKey={}, error={}", | ||||||||||||||||||
| key, e.getMessage(), e); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -208,35 +237,49 @@ private SearchResultSet executeUnifiedSearch(Map<String, Object> params, ToolCon | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * 解析要搜索的源类型列表。 | ||||||||||||||||||
| * 解析要搜索的源列表(字符串)。 | ||||||||||||||||||
| */ | ||||||||||||||||||
| private List<SearchSourceType> parseSourceTypes(Map<String, Object> params) { | ||||||||||||||||||
| List<SearchSourceType> sourceTypes = new ArrayList<>(); | ||||||||||||||||||
| private List<String> parseSourceKeys(Map<String, Object> params) { | ||||||||||||||||||
| List<String> keys = new ArrayList<>(); | ||||||||||||||||||
|
|
||||||||||||||||||
| // 如果指定了 sources 参数 | ||||||||||||||||||
| if (params.containsKey("sources")) { | ||||||||||||||||||
| Object sourcesObj = params.get("sources"); | ||||||||||||||||||
| if (sourcesObj instanceof List) { | ||||||||||||||||||
| List<?> sourcesList = (List<?>) sourcesObj; | ||||||||||||||||||
| for (Object source : sourcesList) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| SearchSourceType type = SearchSourceType.valueOf(source.toString().toUpperCase()); | ||||||||||||||||||
| sourceTypes.add(type); | ||||||||||||||||||
| } | ||||||||||||||||||
| catch (Exception e) { | ||||||||||||||||||
| log.warn("UnifiedSearchCodeactTool#parseSourceTypes - reason=无效的源类型, source={}", source); | ||||||||||||||||||
| if (source != null) { | ||||||||||||||||||
| keys.add(source.toString()); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // 如果没有指定或解析失败,使用默认的源类型 | ||||||||||||||||||
| if (sourceTypes.isEmpty()) { | ||||||||||||||||||
| sourceTypes.add(SearchSourceType.PROJECT); | ||||||||||||||||||
| sourceTypes.add(SearchSourceType.KNOWLEDGE); | ||||||||||||||||||
| // 如果没有指定,使用默认的源类型 | ||||||||||||||||||
| if (keys.isEmpty()) { | ||||||||||||||||||
| keys.add(SearchSourceType.PROJECT.name()); | ||||||||||||||||||
| keys.add(SearchSourceType.KNOWLEDGE.name()); | ||||||||||||||||||
|
Comment on lines
+260
to
+263
|
||||||||||||||||||
| // 如果没有指定,使用默认的源类型 | |
| if (keys.isEmpty()) { | |
| keys.add(SearchSourceType.PROJECT.name()); | |
| keys.add(SearchSourceType.KNOWLEDGE.name()); | |
| // 如果没有指定,使用默认的源类型(与 getAvailableSourceNames 的小写形式保持一致) | |
| if (keys.isEmpty()) { | |
| keys.add(SearchSourceType.PROJECT.name().toLowerCase()); | |
| keys.add(SearchSourceType.KNOWLEDGE.name().toLowerCase()); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation description has been updated to mention "支持标准类型(project, knowledge, web等)或指定Provider名称" which correctly reflects the new functionality. However, the example values shown as "project, knowledge, web等" don't match the actual enum values returned by getAvailableSourceNames() which uses lowercase. Consider updating the documentation to clarify the expected format.
| .description("要搜索的数据源列表,支持标准类型(project, knowledge, web等)或指定Provider名称") | |
| .description("要搜索的数据源列表,支持标准小写类型(如:project、knowledge、web 等)或指定 Provider 名称") |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation description mentions "支持标准类型或Provider名称" but doesn't clarify the format. The actual enum values are lowercase (from getAvailableSourceNames()), but the documentation example doesn't make this clear. Consider being more explicit about the expected format.
| sourcesProp.put("description", "要搜索的数据源列表,支持标准类型或Provider名称"); | |
| sourcesProp.put("description", | |
| "要搜索的数据源列表。每个元素为小写字符串,必须匹配 getAvailableSourceNames() 返回的标准类型名称或 Provider 名称。"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential NullPointerException: if provider.search(request) returns null on line 176, calling allItems.addAll(items) will throw an NPE. Consider adding a null check or ensuring search() never returns null.