| | |
| | | private final AiParamService aiParamService; |
| | | private final AiPromptService aiPromptService; |
| | | private final AiMcpMountService aiMcpMountService; |
| | | private final AiRedisSupport aiRedisSupport; |
| | | |
| | | /** |
| | | * 按租户解析一次完整的 AI 运行配置。 |
| | | * 该方法是对话入口、运行态摘要和配置中心共用的统一解析点, |
| | | * 负责把当前生效的参数、Prompt 和 MCP 挂载聚合成一个不可再拆分的配置对象。 |
| | | */ |
| | | @Override |
| | | public AiResolvedConfig resolve(String promptCode, Long tenantId) { |
| | | return resolve(promptCode, tenantId, null); |
| | | } |
| | | |
| | | @Override |
| | | public AiResolvedConfig resolve(String promptCode, Long tenantId, Long aiParamId) { |
| | | if (tenantId == null) { |
| | | throw new CoolException("当前租户不存在"); |
| | | } |
| | | String finalPromptCode = StringUtils.hasText(promptCode) ? promptCode : AiDefaults.DEFAULT_PROMPT_CODE; |
| | | return AiResolvedConfig.builder() |
| | | // 配置解析是多个入口共享的热点路径,命中缓存时可以避免三张配置表的重复查询。 |
| | | AiResolvedConfig cached = aiRedisSupport.getResolvedConfig(tenantId, finalPromptCode, aiParamId); |
| | | if (cached != null) { |
| | | return cached; |
| | | } |
| | | AiResolvedConfig resolvedConfig = AiResolvedConfig.builder() |
| | | .promptCode(finalPromptCode) |
| | | .aiParam(aiParamService.getActiveParam(tenantId)) |
| | | .aiParam(aiParamService.getChatParam(tenantId, aiParamId)) |
| | | .prompt(aiPromptService.getActivePrompt(finalPromptCode, tenantId)) |
| | | .mcpMounts(aiMcpMountService.listActiveMounts(tenantId)) |
| | | .build(); |
| | | aiRedisSupport.cacheResolvedConfig(tenantId, finalPromptCode, aiParamId, resolvedConfig); |
| | | return resolvedConfig; |
| | | } |
| | | } |