-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
42 lines (37 loc) · 1.08 KB
/
Copy pathoptions.go
File metadata and controls
42 lines (37 loc) · 1.08 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
package contexty
import "slices"
// DropHeadConfig configures how DropHeadStrategy trims older messages.
type DropHeadConfig struct {
// KeepTurnAtomicity enables atomic removal of assistant tool-call turns.
// Nil means true (default).
KeepTurnAtomicity *bool
MinMessages int
ProtectedRoles []string
}
func (cfg DropHeadConfig) keepTurnAtomicity() bool {
if cfg.KeepTurnAtomicity == nil {
return true
}
return *cfg.KeepTurnAtomicity
}
func (cfg DropHeadConfig) normalized() DropHeadConfig {
normalized := DropHeadConfig{
KeepTurnAtomicity: cfg.KeepTurnAtomicity,
MinMessages: cfg.MinMessages,
}
if len(cfg.ProtectedRoles) == 0 {
return normalized
}
normalized.ProtectedRoles = make([]string, 0, len(cfg.ProtectedRoles))
for _, role := range cfg.ProtectedRoles {
if role == "" || slices.Contains(normalized.ProtectedRoles, role) {
continue
}
normalized.ProtectedRoles = append(normalized.ProtectedRoles, role)
}
return normalized
}
// BoolPtr returns a pointer to b (helper for optional config fields).
func BoolPtr(b bool) *bool {
return new(b)
}