feat: 更新后端skill服务

- 更新 skill_handler.go handler层
- 更新 skill.go model层
- 更新 skill_repo.go repository层
- 更新 skill_service.go service层
- 更新 main.go 入口文件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 15:23:22 +08:00
parent e2c9bbd0d1
commit 414147911a
5 changed files with 163 additions and 43 deletions

View File

@@ -121,19 +121,15 @@ func ensureAdminWorkspace() {
}
}
// 创建 admin 工作空间
workspacePath := filepath.Join(projectRoot, "account", "admin")
if err := os.MkdirAll(workspacePath, 0755); err != nil {
log.Printf("Warning: failed to create admin workspace: %v", err)
return
// 创建 skills 目录结构: core/agents/skills/{system,user}
skillsRoot := filepath.Join(projectRoot, "core", "agents", "skills")
for _, dir := range []string{"system", "user"} {
if err := os.MkdirAll(filepath.Join(skillsRoot, dir), 0755); err != nil {
log.Printf("Warning: failed to create skills directory %s: %v", dir, err)
}
}
// 创建子目录: skills(技能), scripts(脚本), sandbox(沙盒), files(文件), temp(临时)
for _, dir := range []string{"skills", "scripts", "sandbox", "files", "temp"} {
os.MkdirAll(filepath.Join(workspacePath, dir), 0755)
}
log.Printf("Admin workspace created at: %s", workspacePath)
log.Printf("Skills workspace created at: %s", skillsRoot)
}
func main() {
@@ -240,6 +236,11 @@ func main() {
// 使用GORM Migrator添加缺失的列
migrator := db.Migrator()
// Skill 表迁移
if !migrator.HasColumn(&model.Skill{}, "created_by") {
migrator.AddColumn(&model.Skill{}, "created_by")
}
if !migrator.HasColumn(&model.Tool{}, "security_level") {
migrator.AddColumn(&model.Tool{}, "security_level")
}
@@ -306,12 +307,12 @@ func main() {
log.Println("Default tools initialized")
}
// 4.3 初始化 skills
if err := skillService.InitSkills(); err != nil {
log.Printf("Warning: Failed to init skills: %v", err)
} else {
log.Println("Skills initialized")
}
// 4.3 初始化 skills(已禁用自动加载,如需启用请调用 /skill/sync 接口)
// if err := skillService.InitSkills(); err != nil {
// log.Printf("Warning: Failed to init skills: %v", err)
// } else {
// log.Println("Skills initialized")
// }
// 6. 初始化 Handler
dbHandler := handler.NewDatabaseHandler(dbService)