Adopt native configuration discovery and a single PromptKit entry file
This commit is contained in:
@@ -5,23 +5,20 @@ import (
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// Document is Scriptorium's ConfigKit-native application configuration shape.
|
||||
type Document struct {
|
||||
PromptKitSources []SourceSelection `yaml:"promptkit_sources"`
|
||||
SchemaDir string `yaml:"schema_dir"`
|
||||
PromptKit PromptKitDocument `yaml:"promptkit"`
|
||||
TransientRetries *int `yaml:"transient_retries"`
|
||||
Server ServerDocument `yaml:"server"`
|
||||
Defaults DefaultsDocument `yaml:"defaults"`
|
||||
}
|
||||
|
||||
// SourceSelection identifies one PromptKit configuration file or directory.
|
||||
type SourceSelection struct {
|
||||
File string `yaml:"file"`
|
||||
Directory string `yaml:"directory"`
|
||||
// PromptKitDocument selects framework acquisition, not embedded definitions.
|
||||
type PromptKitDocument struct {
|
||||
Configuration string `yaml:"configuration"`
|
||||
SchemaDir string `yaml:"schema_dir"`
|
||||
}
|
||||
|
||||
type ServerDocument struct {
|
||||
@@ -32,10 +29,6 @@ type ServerDocument struct {
|
||||
MaxResponseBytes int64 `yaml:"max_response_bytes"`
|
||||
}
|
||||
|
||||
type DefaultsDocument struct {
|
||||
RenderFormat string `yaml:"render_format"`
|
||||
}
|
||||
|
||||
func documentDefinition() configkit.Definition[Document] {
|
||||
return configkit.Definition[Document]{
|
||||
Defaults: documentDefaults,
|
||||
@@ -46,14 +39,13 @@ func documentDefinition() configkit.Definition[Document] {
|
||||
|
||||
func documentDefaults() Document {
|
||||
return Document{
|
||||
SchemaDir: defaults.SchemaDirDefault,
|
||||
PromptKit: PromptKitDocument{SchemaDir: defaults.SchemaDirDefault},
|
||||
Server: ServerDocument{
|
||||
Addr: defaults.HTTPAddrDefault,
|
||||
MaxRequestBytes: defaults.HTTPMaxRequestBytesDefault,
|
||||
MaxArtifactBytes: defaults.HTTPMaxArtifactBytesDefault,
|
||||
MaxResponseBytes: defaults.HTTPMaxResponseBytesDefault,
|
||||
},
|
||||
Defaults: DefaultsDocument{RenderFormat: string(renderformat.DefaultPreparedRunOutputFormat)},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,28 +65,15 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
||||
}
|
||||
}
|
||||
|
||||
for i := range document.PromptKitSources {
|
||||
path := configkit.Keys("promptkit_sources").Index(i)
|
||||
normalizePath(path.Key("file"), &document.PromptKitSources[i].File)
|
||||
normalizePath(path.Key("directory"), &document.PromptKitSources[i].Directory)
|
||||
}
|
||||
normalizePath(configkit.Keys("schema_dir"), &document.SchemaDir)
|
||||
normalizePath(configkit.Keys("promptkit", "configuration"), &document.PromptKit.Configuration)
|
||||
normalizePath(configkit.Keys("promptkit", "schema_dir"), &document.PromptKit.SchemaDir)
|
||||
normalizePath(configkit.Keys("server", "artifact_root"), &document.Server.ArtifactRoot)
|
||||
normalizeString(configkit.Keys("server", "addr"), &document.Server.Addr,
|
||||
strings.TrimSpace(document.Server.Addr), "trimmed server address")
|
||||
normalizeString(configkit.Keys("defaults", "render_format"), &document.Defaults.RenderFormat,
|
||||
strings.ToLower(strings.TrimSpace(document.Defaults.RenderFormat)), "normalized render format")
|
||||
return nil
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
@@ -107,9 +86,4 @@ func validateDocument(document *Document, validation *configkit.Validation) {
|
||||
if document.Server.MaxResponseBytes < 0 {
|
||||
validation.Error(configkit.Keys("server", "max_response_bytes"), "must be greater than or equal to zero")
|
||||
}
|
||||
switch document.Defaults.RenderFormat {
|
||||
case string(renderformat.OutputFormatText), string(renderformat.OutputFormatJSON):
|
||||
default:
|
||||
validation.Error(configkit.Keys("defaults", "render_format"), "must be text or json")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user