feat(AI资源广场): Skill资源相关功能开发
解析Skill压缩包文件时,自动解析压缩包内的name,自动填充,减少用户内容输入
This commit is contained in:
parent
0643fda6b6
commit
41ec65b242
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue