Construct engines from resolved application configuration
This commit is contained in:
@@ -16,11 +16,6 @@ import (
|
||||
"go.maximumdirect.net/promptkit/internal/settings"
|
||||
)
|
||||
|
||||
type document struct {
|
||||
PromptKit settings.Settings `yaml:"promptkit"`
|
||||
Application map[string]any `yaml:",inline"`
|
||||
}
|
||||
|
||||
type collectionConfig = settings.CollectionSettings
|
||||
type backendConfig = settings.BackendSettings
|
||||
type profileConfig = settings.ProfileSettings
|
||||
@@ -56,6 +51,9 @@ type loaded struct {
|
||||
collections []CollectionIdentity
|
||||
}
|
||||
|
||||
// Snapshot holds configuration resources captured for engine assembly.
|
||||
type Snapshot = loaded
|
||||
|
||||
type resourceBases struct {
|
||||
backends configkit.Path
|
||||
profiles configkit.Path
|
||||
@@ -136,11 +134,6 @@ func indexedProfiles(config *settings.Settings) map[string]profileConfig {
|
||||
|
||||
var envName = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
|
||||
|
||||
// Load captures one immutable effective configuration for internal consumers.
|
||||
func Load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error) {
|
||||
return load(main, underlays)
|
||||
}
|
||||
|
||||
// SequenceIdentities returns the component's native sequence registrations.
|
||||
func SequenceIdentities() []configkit.SequenceIdentity {
|
||||
return []configkit.SequenceIdentity{
|
||||
@@ -172,40 +165,6 @@ func Validate(config *settings.Settings, validation *configkit.Validation) {
|
||||
}
|
||||
}
|
||||
|
||||
func configurationDefinition() configkit.Definition[document] {
|
||||
return configkit.Definition[document]{
|
||||
SequenceIdentities: SequenceIdentities(),
|
||||
Sensitive: Sensitive,
|
||||
Resolve: func(config *document, resolution *configkit.Resolution) error {
|
||||
Resolve(&config.PromptKit, resolution)
|
||||
return nil
|
||||
},
|
||||
Validate: func(config *document, validation *configkit.Validation) {
|
||||
Validate(&config.PromptKit, validation)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// load performs one ConfigKit lifecycle over the selected source tiers.
|
||||
func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error) {
|
||||
result, err := configkit.LoadLayered(main, configkit.LayeredOptions[document]{
|
||||
Underlays: underlays,
|
||||
Definition: configurationDefinition(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
view, ok := result.InspectSubtree(configkit.Keys("promptkit"))
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("load configuration: inspection unavailable")
|
||||
}
|
||||
state, err := Capture(&result.Config.PromptKit, view, result.Diagnostics())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// Capture builds owned runtime resources from effective settings and native evidence.
|
||||
func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []configkit.Diagnostic) (*loaded, error) {
|
||||
config := ownSettings(input)
|
||||
|
||||
Reference in New Issue
Block a user