-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_display.go
More file actions
131 lines (121 loc) · 3.44 KB
/
Copy pathmodel_display.go
File metadata and controls
131 lines (121 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package adminapi
import "strings"
type modelDisplay struct {
StatusLabel string
PolicyLabel string
PrimaryReason string
SecondaryReasons []string
}
func decorateModelDisplay(models []uiModel, role string) {
for i := range models {
applyModelDisplay(&models[i], role, false)
}
}
func applyModelDisplay(m *uiModel, role string, current bool) {
d := modelDisplayFor(*m, role, current)
m.StatusLabel = d.StatusLabel
m.PolicyLabel = d.PolicyLabel
m.PrimaryReason = d.PrimaryReason
m.SecondaryReasons = d.SecondaryReasons
}
func modelDisplayFor(m uiModel, role string, current bool) modelDisplay {
status := modelStatusLabel(m, current)
policy := modelPolicyLabel(m, status)
primary := modelPrimaryReason(m, role, status)
secondary := modelSecondaryReasons(m.Reasons, primary)
return modelDisplay{
StatusLabel: status,
PolicyLabel: policy,
PrimaryReason: primary,
SecondaryReasons: secondary,
}
}
func modelStatusLabel(m uiModel, current bool) string {
if current {
return "Current"
}
switch {
case m.Policy == "manual_deny" || m.Policy == "free_blocked":
return "Blocked"
case m.Section == "recommended" || m.Recommended:
return "Recommended"
case m.Section == "untested" || m.Source == "untested" || m.Policy == "free_unverified":
return "Untested"
case m.Section == "watchlist" || m.Source == "watchlist":
return "Needs review"
case m.Section == "interesting" || m.Source == "near_frontier" || m.Source == "manual" || m.Policy == "manual_allow":
return "Interesting"
}
return "Candidate"
}
func modelPolicyLabel(m uiModel, status string) string {
switch m.Policy {
case "", "candidate", "recommended":
return ""
case "manual_allow":
return "Manual allow"
case "manual_deny":
return "Manual deny"
case "free_unverified":
return "Free unverified"
case "free_verified":
return "Free verified"
case "free_degraded":
return "Free degraded"
case "free_blocked":
return "Free blocked"
default:
label := strings.ReplaceAll(m.Policy, "_", " ")
return strings.ToUpper(label[:1]) + label[1:]
}
}
func modelPrimaryReason(m uiModel, role, status string) string {
switch {
case m.Recommended:
if role != "" {
return "Pareto frontier for " + role
}
return "Pareto frontier"
case m.Policy == "manual_allow":
return firstNonEmpty("Manual allow", m.OverrideNote)
case m.Policy == "manual_deny":
return firstNonEmpty("Manual deny", m.OverrideNote)
case m.Policy == "free_blocked":
return "Free endpoint is blocked"
case m.Policy == "free_degraded":
return "Free endpoint degraded"
case m.Policy == "free_verified":
return "Free endpoint verified"
case m.Policy == "free_unverified":
return "Free endpoint needs a check"
case m.Source == "near_frontier":
if role != "" {
return "Near frontier for " + role
}
return "Near recommendation frontier"
case m.Source == "watchlist":
return "Outside proven model family allowlist"
case status == "Untested":
return "Compatible but missing role evidence"
}
if len(m.Reasons) > 0 {
return m.Reasons[0]
}
return ""
}
func modelSecondaryReasons(reasons []string, primary string) []string {
out := make([]string, 0, len(reasons))
for _, reason := range uniqueStrings(reasons) {
if reason == "" || reason == primary {
continue
}
out = append(out, reason)
}
return out
}
func firstNonEmpty(fallback, value string) string {
if strings.TrimSpace(value) != "" {
return fallback + ": " + strings.TrimSpace(value)
}
return fallback
}