Construct engines from resolved application configuration

This commit is contained in:
2026-11-21 14:24:30 +00:00
parent 3a948a1e02
commit 74a77b3c32
5 changed files with 191 additions and 81 deletions

View File

@@ -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)