feat(AI资源广场): Skill资源相关功能开发

解析Skill压缩包文件时,自动解析压缩包内的name,自动填充,减少用户内容输入
This commit is contained in:
欧涛 2026-05-11 11:36:32 +08:00
parent 0643fda6b6
commit 41ec65b242
2 changed files with 54 additions and 5 deletions

View File

@ -23,4 +23,7 @@ public class AiSkillParseResultVo {
@ApiModelProperty(value = "Skill描述从YAML front matter中提取")
private String summary;
@ApiModelProperty(value = "Skill名称从YAML front matter中提取")
private String name;
}

View File

@ -89,13 +89,18 @@ public class AiSkillParseServiceImpl implements IAiSkillParseService {
JSONObject fileTreeJson = buildFileTreeJson(fileTreeNodes);
AiSkillParseResultVo result = new AiSkillParseResultVo();
result.setSkillMdContent(skillMdContent);
result.setFileTreeJson(fileTreeJson.toJSONString());
// YAML front matter 中提取 description 字段
// YAML front matter 中提取 name description 字段
String name = extractName(skillMdContent);
result.setName(name);
String description = extractDescription(skillMdContent);
result.setSummary(description);
result.setSkillMdContent(skillMdContent);
result.setFileTreeJson(fileTreeJson.toJSONString());
// 解析成功后自动上传ZIP文件到File微服务上传失败则阻断整个接口
SysFile sysFile = FeignUtils.getReturnData(
remoteFileService.upload(zipFile, "ai-resource", "skill", SecurityConstants.INNER)
@ -107,8 +112,6 @@ public class AiSkillParseServiceImpl implements IAiSkillParseService {
return result;
} catch (ServiceException e) {
throw e;
} catch (IOException e) {
logger.error("ZIP包解析失败", e);
throw new ServiceException("ZIP包解析失败" + e.getMessage());
@ -238,4 +241,47 @@ public class AiSkillParseServiceImpl implements IAiSkillParseService {
return null;
}
/**
* SKILL.md 内容中提取 name 字段
*
* @param skillMdContent SKILL.md 文件内容
* @return name 内容如果不存在则返回 null
*/
private String extractName(String skillMdContent) {
if (StringUtils.isEmpty(skillMdContent)) {
return null;
}
String[] lines = skillMdContent.split("\\n");
boolean inFrontMatter = false;
boolean foundStart = false;
for (String line : lines) {
String trimmed = line.trim();
if (!foundStart && trimmed.equals("---")) {
foundStart = true;
inFrontMatter = true;
continue;
}
if (foundStart && trimmed.equals("---")) {
break;
}
if (inFrontMatter && trimmed.startsWith("name:")) {
String name = trimmed.substring("name:".length()).trim();
if (name.startsWith("\"") && name.endsWith("\"")) {
return name.substring(1, name.length() - 1);
}
if (name.startsWith("'") && name.endsWith("'")) {
return name.substring(1, name.length() - 1);
}
return name;
}
}
return null;
}
}