Use unified PromptKit sources for execution and preflight
This commit is contained in:
@@ -254,6 +254,11 @@ Prompt size: dependency/notices and one source-construction boundary.
|
||||
|
||||
## Stage 3 — Switch Runtime And Preflight To Shared Engine Configuration
|
||||
|
||||
> Completion: complete. The native command build passes. Test compilation is
|
||||
> still blocked by removed PromptKit setup APIs and legacy fixtures in
|
||||
> `asset_registry_test.go`, `promptkit_client_test.go`, and
|
||||
> `production_contract_test.go`; the fixture work remains in Stages 4–5.
|
||||
|
||||
Goal: restore application compilation and consistent sources.
|
||||
|
||||
Inspect `NewPromptKitClient`, `NewPromptKitProfileInspector`,
|
||||
|
||||
@@ -53,6 +53,18 @@ type LLMProfileRecorder struct {
|
||||
profiles map[string]artifacts.LLMProfileManifest
|
||||
}
|
||||
|
||||
type promptKitClientConfigurationError struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *promptKitClientConfigurationError) Error() string {
|
||||
return "PromptKit client configuration is invalid or unreadable"
|
||||
}
|
||||
|
||||
func (e *promptKitClientConfigurationError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
var _ contracts.StructuredLLMClient = (*PromptKitClient)(nil)
|
||||
var _ contracts.LLMProfileManifestProvider = (*PromptKitClient)(nil)
|
||||
|
||||
@@ -60,29 +72,28 @@ func NewPromptKitClient(cfg PromptKitClientConfig) (*PromptKitClient, error) {
|
||||
if cfg.Assets == nil {
|
||||
return nil, fmt.Errorf("PromptKit client assets must not be nil")
|
||||
}
|
||||
profileSource, profileOptions, err := promptKitProfileSourceEngineOptions(PromptKitProfileSourceConfig{
|
||||
profileSource, sources, options, err := promptKitEngineConfiguration(PromptKitProfileSourceConfig{
|
||||
ProfileDir: cfg.ProfileDir,
|
||||
ProfileFile: cfg.ProfileFile,
|
||||
LocalBackend: cfg.LocalBackend,
|
||||
})
|
||||
}, cfg.Assets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, &promptKitClientConfigurationError{err: err}
|
||||
}
|
||||
options, fallbackProfileDigest, err := cfg.Assets.promptKitOptions()
|
||||
fallbackProfileDigest, err := cfg.Assets.FallbackProfileDigest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, &promptKitClientConfigurationError{err: err}
|
||||
}
|
||||
options = append(options, profileOptions...)
|
||||
options = append(options, cfg.EngineOptions...)
|
||||
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{
|
||||
ProfileDir: profileSource.ProfileDir,
|
||||
Sources: sources,
|
||||
Timeout: cfg.Timeout,
|
||||
HTTPClient: cfg.HTTPClient,
|
||||
TransientRetries: cfg.TransientRetries,
|
||||
}, options...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create PromptKit engine: %w", err)
|
||||
return nil, &promptKitClientConfigurationError{err: err}
|
||||
}
|
||||
recorder := cfg.Recorder
|
||||
if recorder == nil {
|
||||
|
||||
@@ -75,22 +75,12 @@ func (e *promptKitProfileConfigurationError) Unwrap() error {
|
||||
}
|
||||
|
||||
func NewPromptKitProfileInspector(cfg PromptKitProfileInspectorConfig) (*PromptKitProfileInspector, error) {
|
||||
source, options, err := promptKitProfileSourceEngineOptions(cfg.Source)
|
||||
_, sources, options, err := promptKitEngineConfiguration(cfg.Source, cfg.Assets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cfg.Assets != nil {
|
||||
fallbackOption, hasFallback, err := cfg.Assets.promptKitFallbackProfileOption()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if hasFallback {
|
||||
options = append(options, fallbackOption)
|
||||
}
|
||||
return nil, &promptKitProfileConfigurationError{err: err}
|
||||
}
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{
|
||||
PromptDir: ".",
|
||||
ProfileDir: source.ProfileDir,
|
||||
Sources: sources,
|
||||
}, options...)
|
||||
if err != nil {
|
||||
return nil, &promptKitProfileConfigurationError{err: err}
|
||||
@@ -122,6 +112,25 @@ func (i *PromptKitProfileInspector) InspectProfile(ctx context.Context, profileI
|
||||
}, nil
|
||||
}
|
||||
|
||||
func promptKitEngineConfiguration(cfg PromptKitProfileSourceConfig, assets *AssetRegistry) (PromptKitProfileSourceConfig, promptkit.ConfigurationSources, []promptkit.Option, error) {
|
||||
profileSource, profileSources, err := promptKitProfileConfigurationSources(cfg)
|
||||
if err != nil {
|
||||
return PromptKitProfileSourceConfig{}, promptkit.ConfigurationSources{}, nil, err
|
||||
}
|
||||
sources := promptkit.ConfigurationSources{}
|
||||
var options []promptkit.Option
|
||||
if assets != nil {
|
||||
maintainedSources, maintainedOptions, err := assets.PromptKitConfigurationSources()
|
||||
if err != nil {
|
||||
return PromptKitProfileSourceConfig{}, promptkit.ConfigurationSources{}, nil, err
|
||||
}
|
||||
sources = maintainedSources
|
||||
options = append(options, maintainedOptions...)
|
||||
}
|
||||
sources.Underlays = append(sources.Underlays, profileSources.Underlays...)
|
||||
return profileSource, sources, options, nil
|
||||
}
|
||||
|
||||
func promptKitProfileConfigurationSources(cfg PromptKitProfileSourceConfig) (PromptKitProfileSourceConfig, promptkit.ConfigurationSources, error) {
|
||||
source := PromptKitProfileSourceConfig{
|
||||
ProfileDir: strings.TrimSpace(cfg.ProfileDir),
|
||||
|
||||
Reference in New Issue
Block a user