Files
promptkit/internal/configuration/resolve_prompts.go

69 lines
2.4 KiB
Go

package configuration
import (
"strings"
"go.maximumdirect.net/configkit"
"go.maximumdirect.net/promptkit/internal/domain"
)
func resolvePrompts(entries []promptConfig, base configkit.Path, resolution *configkit.Resolution) {
if !eligibleResourceList(entries, func(v promptConfig) string { return v.ID }) {
return
}
for i := range entries {
entry := &entries[i]
path := base.Index(i)
for _, field := range []struct {
value **string
name string
}{{&entry.Description, "description"}, {&entry.SessionID, "session_id"}} {
if *field.value != nil {
recordStringNormalization(field.value, path.Key(field.name), resolution, strings.TrimSpace(**field.value))
}
}
for j := range entry.Inputs {
input := &entry.Inputs[j]
inputPath := path.Key("inputs").Index(j)
if normalized := strings.TrimSpace(input.Name); normalized != input.Name {
configkit.Normalize(resolution, inputPath.Key("name"), &input.Name, normalized, "Normalize input name")
}
for _, field := range []struct {
value **string
name string
}{{&input.ContentType, "content_type"}, {&input.Description, "description"}} {
if *field.value != nil {
recordStringNormalization(field.value, inputPath.Key(field.name), resolution, strings.TrimSpace(**field.value))
}
}
}
if entry.Output != nil && entry.Output.SchemaPath != nil {
recordStringNormalization(&entry.Output.SchemaPath, path.Key("output").Key("schema_path"), resolution, strings.TrimSpace(*entry.Output.SchemaPath))
}
for j := range entry.Messages {
message := &entry.Messages[j]
messagePath := path.Key("messages").Index(j)
if message.Role != nil {
if value, err := domain.NormalizeMessageRole(*message.Role); err == nil {
recordStringNormalization(&message.Role, messagePath.Key("role"), resolution, value)
}
}
if message.CacheControl == nil || message.CacheControl.Type == nil {
continue
}
cache := message.CacheControl
control := &domain.CacheControl{Type: domain.CacheControlType(*cache.Type)}
if cache.TTL != nil {
control.TTL = *cache.TTL
}
if normalized, err := domain.NormalizeCacheControl(control); err == nil {
cachePath := messagePath.Key("cache_control")
recordStringNormalization(&cache.Type, cachePath.Key("type"), resolution, string(normalized.Type))
if cache.TTL != nil {
recordStringNormalization(&cache.TTL, cachePath.Key("ttl"), resolution, normalized.TTL)
}
}
}
}
}