Skip to content

🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"

TypeScript

fix(skills): 修复设置页 Skills 列表为空(下划线/连字符命名不匹配)

Connor2cfccd3d6e9a
diff --git a/backend/src/agents/skills.ts b/backend/src/agents/skills.ts
index 8f9a32a..82369a7 100644
--- a/backend/src/agents/skills.ts
+++ b/backend/src/agents/skills.ts
@@ -31,15 +31,17 @@ const AGENT_SKILL_MAP: Record<string, string[]> = {
],
}
-/** 每个 Agent 的 Workspace(filesystem 工作目录 + 原生技能注册) */
+/** 每个 Agent 的 Workspace(filesystem 工作目录 + 原生技能注册)
+ * skills 用动态解析器按目录前缀匹配:设置页新建的子技能无需重启即可被发现 */
export const skillWorkspaces: Record<string, Workspace> = Object.fromEntries(
- Object.entries(AGENT_SKILL_MAP).map(([agentType, relPaths]) => [
+ Object.entries(AGENT_SKILL_MAP).map(([agentType, prefixes]) => [
agentType,
new Workspace({
id: `workspace-${agentType}`,
name: `${agentType} workspace`,
filesystem: new LocalFilesystem({ basePath: WORKSPACE_DIR }),
- skills: relPaths.map(rel => `skills/${rel}`),
+ skills: () => scanSkillPaths().filter(p =>
+ prefixes.some(prefix => p === `skills/${prefix}` || p.startsWith(`skills/${prefix}/`))),
}),
]),
)
@@ -76,11 +78,17 @@ function formatSkillSection(skillId: string, content: string): string {
return [`## Skill: ${skillId}`, content].join('\n')
}
-/** 读取 Agent 专属技能全文(经 workspace.skills API,保持原注入格式) */
+/** 读取 Agent 专属技能全文(经 workspace.skills API,保持原注入格式)
+ * AGENT_SKILL_MAP 的目录按前缀匹配:目录自身及其子目录下所有 SKILL.md 都会注入,
+ * 因此设置页新建的子技能(如 storyboard-breaker/xxx)无需改代码即可生效 */
export async function loadAgentSkills(agentType: string): Promise<string> {
const workspace = skillWorkspaces[agentType]
- const relPaths = AGENT_SKILL_MAP[agentType] || []
- if (!workspace || !relPaths.length) return ''
+ const prefixes = AGENT_SKILL_MAP[agentType] || []
+ if (!workspace || !prefixes.length) return ''
+
+ const allPaths = scanSkillPaths().map(p => p.replace(/^skills\//, ''))
+ const relPaths = allPaths.filter(p =>
+ prefixes.some(prefix => p === prefix || p.startsWith(prefix + '/')))
const contents: string[] = []
for (const relPath of relPaths) {
diff --git a/frontend/app/pages/settings.vue b/frontend/app/pages/settings.vue
index ba9feba..717c628 100644
--- a/frontend/app/pages/settings.vue
+++ b/frontend/app/pages/settings.vue
@@ -257,7 +257,7 @@
placeholder="编写 SKILL.md 内容..."
/>
<div class="skill-card-foot">
- <span class="dim" style="font-size:11px">skills/{{ selectedAgentType }}/{{ s.id }}/SKILL.md</span>
+ <span class="dim" style="font-size:11px">skills/{{ s.id }}/SKILL.md</span>
<span v-if="skillSaved === s.id" class="tag tag-success" style="margin-left:8px">
<Check :size="10" /> 已保存
</span>
@@ -673,12 +673,19 @@ const selectedAgentType = computed(() => selectedAgent.value)
const selectedAgentLabel = computed(() => agentDefs.find(a => a.type === selectedAgent.value)?.label || '')
const selectedAgentIcon = computed(() => agentDefs.find(a => a.type === selectedAgent.value)?.icon || '')
+// agent type 用下划线(script_rewriter),skill 目录按 Mastra 规范用连字符(script-rewriter)
+const skillDirOf = (type) => type.replace(/_/g, '-')
+const skillBelongsTo = (skillId, type) => {
+ const dir = skillDirOf(type)
+ return skillId === dir || skillId.startsWith(dir + '/')
+}
+
function agentSkillCount(type) {
- return allSkills.value.filter(s => s.id === type || s.id.startsWith(type + '/')).length
+ return allSkills.value.filter(s => skillBelongsTo(s.id, type)).length
}
const currentSkills = computed(() =>
- allSkills.value.filter(s => s.id === selectedAgent.value || s.id.startsWith(selectedAgent.value + '/'))
+ allSkills.value.filter(s => skillBelongsTo(s.id, selectedAgent.value))
)
async function loadAllSkills() {
@@ -700,7 +707,7 @@ function startAddSkill() {
async function confirmAddSkill() {
if (!newSkillForm.id) return
- const skillId = `${selectedAgent.value}/${newSkillForm.id}`
+ const skillId = `${skillDirOf(selectedAgent.value)}/${newSkillForm.id}`
try {
await skillsAPI.create({ id: skillId, name: newSkillForm.name, description: newSkillForm.description })
addSkillDialog.value = false