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:
@@ -3,6 +3,7 @@ package callbacks
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -142,17 +143,19 @@ func (h *RuntimeTraceHandler) tryActivateSkill(argumentsInJSON string) {
|
||||
if err := json.Unmarshal([]byte(strings.TrimSpace(argumentsInJSON)), &args); err != nil {
|
||||
return
|
||||
}
|
||||
code := strings.TrimSpace(args.Skill)
|
||||
if code == "" {
|
||||
skillKey := strings.TrimSpace(args.Skill)
|
||||
if skillKey == "" {
|
||||
return
|
||||
}
|
||||
meta, ok := h.skillMetadataBy[code]
|
||||
meta, ok := h.skillMetadataBy[skillKey]
|
||||
if !ok {
|
||||
meta = SkillMetadata{Code: code}
|
||||
if id, err := strconv.ParseInt(skillKey, 10, 64); err == nil {
|
||||
meta = SkillMetadata{ID: id}
|
||||
}
|
||||
}
|
||||
buf, err := json.Marshal(map[string]any{
|
||||
"source": "eino_skill_tool",
|
||||
"skill": code,
|
||||
"source": "eino_skill_tool",
|
||||
"skillId": skillKey,
|
||||
})
|
||||
routeTrace := ""
|
||||
if err == nil {
|
||||
|
||||
@@ -42,18 +42,18 @@ func TestTryActivateSkill(t *testing.T) {
|
||||
handler := &RuntimeTraceHandler{
|
||||
collector: collector,
|
||||
skillMetadataBy: map[string]SkillMetadata{
|
||||
"after_sales_escalation_skill": {
|
||||
Code: "after_sales_escalation_skill",
|
||||
"44": {
|
||||
ID: 44,
|
||||
Name: "售后升级",
|
||||
AllowedToolCodes: []string{"graph/handoff_to_human"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
handler.tryActivateSkill(`{"skill":"after_sales_escalation_skill"}`)
|
||||
handler.tryActivateSkill(`{"skill":"44"}`)
|
||||
|
||||
if collector.Data.Skill.Code != "after_sales_escalation_skill" {
|
||||
t.Fatalf("unexpected skill code: %#v", collector.Data.Skill)
|
||||
if collector.Data.Skill.ID != 44 {
|
||||
t.Fatalf("unexpected skill id: %#v", collector.Data.Skill)
|
||||
}
|
||||
if collector.Data.Skill.Name != "售后升级" {
|
||||
t.Fatalf("unexpected skill name: %#v", collector.Data.Skill)
|
||||
|
||||
@@ -52,7 +52,7 @@ func (c *RuntimeTraceCollector) SetSkillMiddleware(enabled bool, toolName string
|
||||
}
|
||||
|
||||
type SkillMetadata struct {
|
||||
Code string
|
||||
ID int64
|
||||
Name string
|
||||
Description string
|
||||
AllowedToolCodes []string
|
||||
@@ -64,20 +64,20 @@ func (c *RuntimeTraceCollector) SetVisibleSkills(skills map[string]SkillMetadata
|
||||
}
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
codes := make([]string, 0, len(skills))
|
||||
for code := range skills {
|
||||
if code == "" {
|
||||
ids := make([]int64, 0, len(skills))
|
||||
for _, skill := range skills {
|
||||
if skill.ID <= 0 {
|
||||
continue
|
||||
}
|
||||
codes = append(codes, code)
|
||||
ids = append(ids, skill.ID)
|
||||
}
|
||||
c.Data.Skill.VisibleCodes = append([]string(nil), codes...)
|
||||
c.Data.Skill.VisibleIDs = append([]int64(nil), ids...)
|
||||
}
|
||||
|
||||
func (c *RuntimeTraceCollector) ActivateSkill(skill SkillMetadata, routeReason string, routeTrace string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.Data.Skill.Code = skill.Code
|
||||
c.Data.Skill.ID = skill.ID
|
||||
c.Data.Skill.Name = skill.Name
|
||||
c.Data.Skill.Description = skill.Description
|
||||
c.Data.Skill.AllowedToolCodes = append([]string(nil), skill.AllowedToolCodes...)
|
||||
|
||||
@@ -152,7 +152,7 @@ type RuntimeTraceData struct {
|
||||
}
|
||||
|
||||
type SkillTraceData struct {
|
||||
Code string `json:"code,omitempty"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
RouteReason string `json:"routeReason,omitempty"`
|
||||
@@ -161,7 +161,7 @@ type SkillTraceData struct {
|
||||
FilteredToolCodes []string `json:"filteredToolCodes,omitempty"`
|
||||
MiddlewareEnabled bool `json:"middlewareEnabled,omitempty"`
|
||||
MiddlewareToolName string `json:"middlewareToolName,omitempty"`
|
||||
VisibleCodes []string `json:"visibleCodes,omitempty"`
|
||||
VisibleIDs []int64 `json:"visibleIds,omitempty"`
|
||||
}
|
||||
|
||||
type InterruptTraceContext struct {
|
||||
|
||||
Reference in New Issue
Block a user