Replace legacy framework config with source selectors
This commit is contained in:
@@ -11,21 +11,17 @@ import (
|
||||
|
||||
// Document is Scriptorium's ConfigKit-native application configuration shape.
|
||||
type Document struct {
|
||||
PromptDir string `yaml:"prompt_dir"`
|
||||
ProfileDir string `yaml:"profile_dir"`
|
||||
SchemaDir string `yaml:"schema_dir"`
|
||||
TransientRetries *int `yaml:"transient_retries"`
|
||||
Server ServerDocument `yaml:"server"`
|
||||
Defaults DefaultsDocument `yaml:"defaults"`
|
||||
Backends map[string]BackendDocument `yaml:"backends"`
|
||||
PromptKitSources []SourceSelection `yaml:"promptkit_sources"`
|
||||
SchemaDir string `yaml:"schema_dir"`
|
||||
TransientRetries *int `yaml:"transient_retries"`
|
||||
Server ServerDocument `yaml:"server"`
|
||||
Defaults DefaultsDocument `yaml:"defaults"`
|
||||
}
|
||||
|
||||
type BackendDocument struct {
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
APIKeyEnv string `yaml:"api_key_env"`
|
||||
ExtraParams map[string]any `yaml:"extra_params"`
|
||||
ConcurrencyLimit int `yaml:"concurrency_limit"`
|
||||
QueueCapacity *int `yaml:"queue_capacity"`
|
||||
// SourceSelection identifies one PromptKit configuration file or directory.
|
||||
type SourceSelection struct {
|
||||
File string `yaml:"file"`
|
||||
Directory string `yaml:"directory"`
|
||||
}
|
||||
|
||||
type ServerDocument struct {
|
||||
@@ -62,14 +58,16 @@ func documentDefaults() Document {
|
||||
}
|
||||
|
||||
func resolveDocument(document *Document, resolution *configkit.Resolution) error {
|
||||
normalizePath := func(path configkit.Path, value *string) {
|
||||
normalizePath := func(path configkit.Path, value *string) bool {
|
||||
cleaned := strings.TrimSpace(*value)
|
||||
if cleaned != "" {
|
||||
cleaned = filepath.Clean(cleaned)
|
||||
}
|
||||
if cleaned != *value {
|
||||
configkit.Normalize(resolution, path, value, cleaned, "normalized application path")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
normalizeString := func(path configkit.Path, value *string, normalized, reason string) {
|
||||
if normalized != *value {
|
||||
@@ -77,8 +75,15 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
||||
}
|
||||
}
|
||||
|
||||
normalizePath(configkit.Keys("prompt_dir"), &document.PromptDir)
|
||||
normalizePath(configkit.Keys("profile_dir"), &document.ProfileDir)
|
||||
sourcePathsChanged := false
|
||||
for i := range document.PromptKitSources {
|
||||
path := configkit.Keys("promptkit_sources").Index(i)
|
||||
sourcePathsChanged = normalizePath(path.Key("file"), &document.PromptKitSources[i].File) || sourcePathsChanged
|
||||
sourcePathsChanged = normalizePath(path.Key("directory"), &document.PromptKitSources[i].Directory) || sourcePathsChanged
|
||||
}
|
||||
if sourcePathsChanged {
|
||||
resolution.Record(configkit.Keys("promptkit_sources"), configkit.ChangeNormalization, "normalized selected source paths")
|
||||
}
|
||||
normalizePath(configkit.Keys("schema_dir"), &document.SchemaDir)
|
||||
normalizePath(configkit.Keys("server", "artifact_root"), &document.Server.ArtifactRoot)
|
||||
normalizeString(configkit.Keys("server", "addr"), &document.Server.Addr,
|
||||
@@ -89,6 +94,13 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
||||
}
|
||||
|
||||
func validateDocument(document *Document, validation *configkit.Validation) {
|
||||
for i, source := range document.PromptKitSources {
|
||||
hasFile := source.File != ""
|
||||
hasDirectory := source.Directory != ""
|
||||
if hasFile == hasDirectory {
|
||||
validation.Error(configkit.Keys("promptkit_sources").Index(i), "exactly one of file or directory must be non-empty")
|
||||
}
|
||||
}
|
||||
if document.TransientRetries != nil && *document.TransientRetries < 0 {
|
||||
validation.Error(configkit.Keys("transient_retries"), "must be greater than or equal to zero")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user