42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package commandkit
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit"
|
|
)
|
|
|
|
// NewPromptKitScope adapts PromptKit's captured configuration inspection to
|
|
// CommandKit's configuration commands. The loader runs only when a selected
|
|
// configuration operation acquires this scope. Successful construction and
|
|
// inspection supply validation; the adapter does not execute prompts, resolve
|
|
// credentials, or probe model availability.
|
|
func NewPromptKitScope[C any](
|
|
load func(context.Context, Selection, C) (*promptkit.Engine, error),
|
|
) (ConfigScope[C], error) {
|
|
if load == nil {
|
|
return ConfigScope[C]{}, fmt.Errorf("PromptKit configuration loader is nil")
|
|
}
|
|
|
|
return ConfigScope[C]{
|
|
Name: "promptkit",
|
|
Summary: "PromptKit engine configuration.",
|
|
Operations: []ConfigOperation{ConfigValidate, ConfigShow, ConfigSources, ConfigExplain},
|
|
Acquire: func(ctx context.Context, request ConfigRequest, appContext C) (Acquired[ConfigView], error) {
|
|
_, inspection, diagnostics, err := loadPromptKitInspection(ctx, request.Selection, appContext, load)
|
|
if err != nil {
|
|
return Acquired[ConfigView]{Diagnostics: diagnostics}, err
|
|
}
|
|
return Acquired[ConfigView]{
|
|
Value: ConfigView{
|
|
Effective: inspection,
|
|
Sources: inspection,
|
|
Explanation: inspection,
|
|
},
|
|
Diagnostics: diagnostics,
|
|
}, nil
|
|
},
|
|
}, nil
|
|
}
|