refactor: replace skill code with skill ID across the application

- Updated skill handling to use skill IDs instead of skill codes in various components, services, and models.
- Modified tests to reflect changes in skill identification.
- Removed references to skill codes in favor of skill IDs for consistency and clarity.
- Updated localization files to remove skill code references and adjust error messages accordingly.
This commit is contained in:
mlogclub
2026-06-20 20:42:07 +08:00
parent 39c648f3c1
commit 541e4c5874
49 changed files with 258 additions and 341 deletions
+9 -23
View File
@@ -2,13 +2,10 @@ package skills
import (
"context"
"strings"
"agent-desk/internal/models"
"agent-desk/internal/pkg/enums"
"agent-desk/internal/pkg/errorsx"
"github.com/mlogclub/simple/common/strs"
)
type intentTriggerConfig struct {
@@ -18,45 +15,34 @@ type intentTriggerConfig struct {
// MatchSkill 对单个 SkillDefinition 执行命中判断。
func MatchSkill(execCtx context.Context, ctx RuntimeContext) (*models.SkillDefinition, string, *RouteTrace, error) {
loader := newCandidateLoader()
if strs.IsNotBlank(ctx.ManualSkillCode) {
skill := loader.findManualSkillDefinition(ctx.ManualSkillCode)
if ctx.ManualSkillDefinitionID > 0 {
skill := loader.findManualSkillDefinition(ctx.ManualSkillDefinitionID)
if skill == nil || skill.Status != enums.StatusOk {
return nil, "", nil, errorsx.InvalidParamI18n("error.e0054")
}
return skill, "manual_skill_code", &RouteTrace{
Status: "manual_selected",
SelectedSkillCode: skill.Code,
return skill, "manual_skill_id", &RouteTrace{
Status: "manual_selected",
SelectedSkillID: skill.ID,
}, nil
}
candidates := loader.loadCandidateSkills(ctx.AIAgent)
trace := &RouteTrace{
Status: "started",
CandidateSkillCodes: make([]string, 0, len(candidates)),
Status: "started",
CandidateSkillIDs: make([]int64, 0, len(candidates)),
}
for _, item := range candidates {
trace.CandidateSkillCodes = append(trace.CandidateSkillCodes, item.Code)
trace.CandidateSkillIDs = append(trace.CandidateSkillIDs, item.ID)
}
if len(candidates) == 0 {
trace.Status = "no_candidate"
return nil, "no_enabled_skill_bound", trace, nil
}
intentCode := strings.TrimSpace(ctx.IntentCode)
if intentCode != "" {
for _, item := range candidates {
if strings.EqualFold(strings.TrimSpace(item.Code), intentCode) {
trace.Status = "intent_selected"
trace.SelectedSkillCode = item.Code
return &item, "intent_code", trace, nil
}
}
}
selected, routeTrace, err := routeSkillWithLLM(execCtx, ctx, candidates)
if routeTrace != nil {
trace.Status = routeTrace.Status
trace.SelectedSkillCode = routeTrace.SelectedSkillCode
trace.SelectedSkillID = routeTrace.SelectedSkillID
trace.RawDecision = routeTrace.RawDecision
trace.LatencyMs = routeTrace.LatencyMs
trace.Error = routeTrace.Error