Files
Your Name cf46b27610 fix: P0-1 RateLimiter并发写安全 + P0-2工单操作错误码区分 + P1 rows.Close修复
P0-1 (limits.go): Allow()方法改为全程使用写锁保护counters map读写,避免RLock写入时的data race
P0-2 (ticket_workflow.go+ticket_handler.go): Assign/Resolve/Close操作先查询ticket存在性和状态,返回明确的CS_TICKET_4001/CS_TKT_4002/CS_TICKET_4092/CS_TICKET_4093错误码,handler根据错误前缀路由HTTP状态码
P1-1 (ticket_store.go): 移除GetStats中3处手动rows.Close(),只保留defer Close()
2026-05-01 20:56:25 +08:00

31 lines
827 B
Go

package handoff
import (
"context"
domain "github.com/bridge/ai-customer-service/internal/domain/intent"
)
type Decision struct {
ShouldHandoff bool `json:"should_handoff"`
Reason string `json:"reason"`
Priority string `json:"priority"`
}
type Service struct{}
func NewService() *Service { return &Service{} }
func (s *Service) ShouldHandoff(_ context.Context, intent *domain.Result, turnCount int) (*Decision, error) {
if intent == nil {
return &Decision{}, nil
}
if intent.NeedsHuman || intent.Sensitive {
return &Decision{ShouldHandoff: true, Reason: intent.Intent, Priority: "P1"}, nil
}
if turnCount >= 5 && intent.Confidence < 0.60 {
return &Decision{ShouldHandoff: true, Reason: "low_confidence", Priority: "P2"}, nil
}
return &Decision{ShouldHandoff: false, Priority: "P3"}, nil
}