Skip to content

fix: ensure botTemplate saved for workflow-template bot creation (#1021)#1035

Open
zicojiao wants to merge 1 commit intoiflytek:mainfrom
zicojiao:fix/issue-1021-bot-template
Open

fix: ensure botTemplate saved for workflow-template bot creation (#1021)#1035
zicojiao wants to merge 1 commit intoiflytek:mainfrom
zicojiao:fix/issue-1021-bot-template

Conversation

@zicojiao
Copy link
Copy Markdown

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
const coreScenarios = item?.coreScenarios as any;
const coreScenarios = item?.coreScenarios as Partial<Record<'botTemplate' | 'bot_template' | 'inputTemplate' | 'input_template' | 'description', string>>;

Comment on lines +55 to +60
const botTemplateFromTemplate =
coreScenarios?.botTemplate ??
coreScenarios?.bot_template ??
coreScenarios?.inputTemplate ??
coreScenarios?.input_template ??
coreScenarios?.description;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants