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)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit/internal/artifact"
|
||||
"go.maximumdirect.net/promptkit/internal/capacity"
|
||||
"go.maximumdirect.net/promptkit/internal/configuration"
|
||||
@@ -22,29 +21,18 @@ import (
|
||||
|
||||
// Config carries construction settings selected by the public facade.
|
||||
type Config struct {
|
||||
Sources ConfigurationSources
|
||||
Timeout time.Duration
|
||||
HTTPClient *http.Client
|
||||
TransientRetries *int
|
||||
}
|
||||
|
||||
// ConfigurationSources identifies caller-selected ConfigKit layers.
|
||||
type ConfigurationSources struct {
|
||||
Underlays []configkit.Underlay
|
||||
Main *configkit.Input
|
||||
}
|
||||
|
||||
// Options collects construction choices from the public facade.
|
||||
type Options struct {
|
||||
llmClient llm.Client
|
||||
artifactReader artifact.Reader
|
||||
artifactSource bool
|
||||
disableBundledOpenRouter bool
|
||||
llmClient llm.Client
|
||||
artifactReader artifact.Reader
|
||||
artifactSource bool
|
||||
}
|
||||
|
||||
// SetBundledOpenRouter selects whether the built-in OpenRouter source is installed.
|
||||
func (o *Options) SetBundledOpenRouter(enabled bool) { o.disableBundledOpenRouter = !enabled }
|
||||
|
||||
// SetLLMClient selects the client collaborator for one engine.
|
||||
func (o *Options) SetLLMClient(client llm.Client) { o.llmClient = client }
|
||||
|
||||
@@ -101,25 +89,11 @@ type ListingFilter struct {
|
||||
}
|
||||
|
||||
// New assembles an engine from facade-selected configuration and collaborators.
|
||||
func New(cfg Config, options Options) (*Engine, error) {
|
||||
func New(snapshot *configuration.Snapshot, cfg Config, options Options) (*Engine, error) {
|
||||
defaultRetries, err := domain.ResolveTransientRetries(2, cfg.TransientRetries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
underlays := cfg.Sources.Underlays
|
||||
if !options.disableBundledOpenRouter {
|
||||
underlays = make([]configkit.Underlay, 1, len(cfg.Sources.Underlays)+1)
|
||||
underlays[0] = configuration.BundledOpenRouterUnderlay()
|
||||
underlays = append(underlays, cfg.Sources.Underlays...)
|
||||
}
|
||||
main := configkit.Input{Source: configkit.NoSource()}
|
||||
if cfg.Sources.Main != nil {
|
||||
main = *cfg.Sources.Main
|
||||
}
|
||||
snapshot, err := configuration.Load(main, underlays)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manager, err := capacity.NewManager(snapshot.CapacityPolicies())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to construct backend capacity manager: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user