Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public BotInfoDto createFromTemplate(String uid, MaasDuplicate maasDuplicate, Ht
Long spaceId = SpaceInfoUtil.getSpaceId();
// Create an event, consumed by /maasCopySynchronize
Long maasId = maasDuplicate.getMaasId();
// Ensure botTemplate is present; it is used to populate chat_bot_base.bot_template.
// Some workflow template create flows don't provide botTemplate in request payload.
if (maasDuplicate.getBotTemplate() == null || maasDuplicate.getBotTemplate().trim().isEmpty()) {
MaasTemplate template = maasTemplateMapper.selectOne(
new LambdaQueryWrapper<MaasTemplate>().eq(MaasTemplate::getMaasId, maasId)
);
String resolved = resolveBotTemplateFromCoreScenarios(
template != null ? template.getCoreScenarios() : null
);
if (resolved != null && !resolved.trim().isEmpty()) {
maasDuplicate.setBotTemplate(resolved);
}
}
UserLangChainInfo userLangChainInfo = userLangChainDataService.selectByMaasId(maasId);
if (Objects.isNull(userLangChainInfo)) {
log.info("----- Xinghuo did not find Astron workflow: {}", JSONObject.toJSONString(userLangChainInfo));
Expand All @@ -79,6 +92,27 @@ public BotInfoDto createFromTemplate(String uid, MaasDuplicate maasDuplicate, Ht
return botInfoDto;
}

private String resolveBotTemplateFromCoreScenarios(JSONObject coreScenarios) {
if (coreScenarios == null) {
return null;
}
// Try common key names from template scenario config.
String[] keys = new String[] {
"botTemplate",
"bot_template",
"inputTemplate",
"input_template",
"description"
};
for (String key : keys) {
String value = coreScenarios.getString(key);
if (value != null && !value.trim().isEmpty()) {
return value;
}
}
return null;
}

@Override
public Integer maasCopySynchronize(CloneSynchronize synchronize) {
log.info("------ Astron workflow copy synchronization: {}", JSONObject.toJSONString(synchronize));
Expand Down
14 changes: 14 additions & 0 deletions console/frontend/src/components/make-creation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ const MakeCreateModal: React.FC<MakeCreateModalProps> = ({
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>>;

const botTemplateFromTemplate =
coreScenarios?.botTemplate ??
coreScenarios?.bot_template ??
coreScenarios?.inputTemplate ??
coreScenarios?.input_template ??
coreScenarios?.description;
Comment on lines +55 to +60
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.


if (
typeof botTemplateFromTemplate === 'string' &&
botTemplateFromTemplate.trim()
) {
req['botTemplate'] = botTemplateFromTemplate;
}
await createFromTemplate(req)
.then((res: any) => {
navigate(`/work_flow/${res.flowId}/arrange`);
Expand Down