fix: ensure botTemplate saved for workflow-template bot creation (#1021)#1035
fix: ensure botTemplate saved for workflow-template bot creation (#1021)#1035zicojiao wants to merge 1 commit intoiflytek:mainfrom
Conversation
Made-with: Cursor
There was a problem hiding this comment.
Code Review
This pull request adds a fallback mechanism to ensure botTemplate is persisted when creating an assistant from a workflow template. The changes on the frontend proactively populate botTemplate, and the backend adds a fallback to resolve it from core_scenarios if it's missing. My review focuses on the frontend implementation where I've identified a couple of areas for improvement regarding type safety and code duplication. Addressing these points will improve the code's quality, maintainability, and robustness.
| if (flag) { | ||
| req['maasId'] = item.maasId; | ||
| req['name'] = item.title + Date.now(); | ||
| const coreScenarios = item?.coreScenarios as any; |
There was a problem hiding this comment.
Using as any bypasses TypeScript's type checking, which can lead to runtime errors and makes the code harder to maintain. It's better to provide a specific type for coreScenarios. A more comprehensive fix would be to type the entire item object, which seems to correspond to the MaasTemplate entity from the backend, and update the getStarTemplate service to return a typed response instead of any.
| const coreScenarios = item?.coreScenarios as any; | |
| const coreScenarios = item?.coreScenarios as Partial<Record<'botTemplate' | 'bot_template' | 'inputTemplate' | 'input_template' | 'description', string>>; |
| const botTemplateFromTemplate = | ||
| coreScenarios?.botTemplate ?? | ||
| coreScenarios?.bot_template ?? | ||
| coreScenarios?.inputTemplate ?? | ||
| coreScenarios?.input_template ?? | ||
| coreScenarios?.description; |
There was a problem hiding this comment.
This logic for finding a bot template from a set of possible keys (botTemplate, bot_template, etc.) is duplicated in the backend (BotMaasServiceImpl.java). Having duplicated logic can lead to maintenance issues and bugs if one part is updated and the other is not. To improve maintainability, consider consolidating this logic. If that's not feasible, at least add comments in both frontend and backend code to reference the duplicated implementation and ensure they are kept in sync.
When creating an assistant from a workflow template, the request payload may miss botTemplate, causing chat_bot_base.bot_template not to be persisted.
This change populates botTemplate on the frontend when available and adds a backend fallback to resolve it from maas_template.core_scenarios.
Related: #1021