Files
cneicy ceddfd3d6b feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
2026-09-26 04:49:11 +08:00

53 lines
1.3 KiB
Go

package model
// SelectionTrace is populated by the selector while its candidate snapshot is
// still locked. It never retains Channel objects, keys or provider settings.
type SelectionTrace struct {
Candidates []SelectionCandidate `json:"candidates"`
Total int `json:"candidate_total"`
SelectedID int `json:"-"`
}
type SelectionCandidate struct {
ChannelID int `json:"channel_id"`
Name string `json:"name"`
Group string `json:"group"`
Model string `json:"model"`
Priority int64 `json:"priority"`
Weight int `json:"weight"`
Reason string `json:"reason"`
}
func (t *SelectionTrace) Add(ch *Channel, id int, group, model, reason string) {
if t == nil {
return
}
t.Total++
if len(t.Candidates) >= 100 {
return
}
c := SelectionCandidate{ChannelID: id, Group: group, Model: model, Reason: reason}
if ch != nil {
c.Name = ch.Name
c.Priority = ch.GetPriority()
c.Weight = ch.GetWeight()
}
t.Candidates = append(t.Candidates, c)
}
func (t *SelectionTrace) Finish(ch *Channel) {
if t == nil || ch == nil {
return
}
t.SelectedID = ch.Id
for i := range t.Candidates {
c := &t.Candidates[i]
if c.ChannelID == ch.Id && c.Reason == "eligible" {
c.Reason = "selected"
}
if c.Reason == "eligible" && c.Priority != ch.GetPriority() {
c.Reason = "different_priority"
}
}
}