Install native PromptKit diagnostics and reusable execution overrides
This commit is contained in:
@@ -7,14 +7,22 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/ckprompt"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// NewApplication declares the native command surface. Acquisition is deferred to
|
||||
// the selected handler; construction performs no configuration or engine work.
|
||||
func NewApplication(version string, options Options) (*commandkit.App, error) {
|
||||
newState := func() *nativeLoaders { return &nativeLoaders{lookupEnv: options.LookupEnv} }
|
||||
newState := func() *nativeLoaders {
|
||||
state := &nativeLoaders{lookupEnv: options.LookupEnv, runtime: options.LLMRuntime}
|
||||
if options.LLMClient != nil {
|
||||
state.engineOptions = []promptkit.Option{promptkit.WithLLMClient(options.LLMClient)}
|
||||
}
|
||||
return state
|
||||
}
|
||||
load := func(ctx context.Context, selection ckconfig.Selection, _ struct{}, state *nativeLoaders) (*configkit.Result[config.Document], error) {
|
||||
return state.application(ctx, selection)
|
||||
}
|
||||
@@ -22,17 +30,33 @@ func NewApplication(version string, options Options) (*commandkit.App, error) {
|
||||
appScope.Features.Overrides = true
|
||||
promptScope := ckconfig.FromConfigKitSubtree("promptkit", "Native PromptKit configuration.", configkit.Keys("promptkit"), load)
|
||||
promptScope.Features.Overrides = true
|
||||
return commandkit.New(commandkit.Identity{Name: "notarius", Version: version},
|
||||
loadEngine := func(ctx context.Context, selection ckconfig.Selection, _ struct{}, state *nativeLoaders) (*promptkit.Engine, error) {
|
||||
return state.engine(ctx, selection)
|
||||
}
|
||||
definitions := ckprompt.FromEngine(loadEngine)
|
||||
definitions.NewState = newState
|
||||
definitions.CheckInput = func(selection ckconfig.Selection, _ struct{}) error { return checkConfigSelection(selection) }
|
||||
definitions = ckprompt.WithRequestValidation(definitions, loadEngine, nil)
|
||||
definitions = ckprompt.WithRequestPreparation(definitions, loadEngine, nil)
|
||||
definitions = ckprompt.WithSmokeTesting(definitions, loadEngine, nil)
|
||||
definitions = ckprompt.WithNamespaces(definitions, promptkit.Namespaces{})
|
||||
declarations := []commandkit.Declaration{
|
||||
commandkit.Completion("notarius"),
|
||||
ckconfig.Command(ckconfig.Suite[struct{}, *nativeLoaders]{
|
||||
NewState: newState,
|
||||
CheckInput: func(_ string, selection ckconfig.Selection, _ struct{}) error {
|
||||
if selection.Config.Set && strings.TrimSpace(selection.Config.Value) == "" {
|
||||
return fmt.Errorf("--config must not be empty")
|
||||
}
|
||||
return nil
|
||||
return checkConfigSelection(selection)
|
||||
},
|
||||
Scopes: []ckconfig.Scope[struct{}, *nativeLoaders]{appScope, promptScope},
|
||||
}),
|
||||
)
|
||||
}
|
||||
declarations = append(declarations, ckprompt.Declarations(definitions)...)
|
||||
return commandkit.New(commandkit.Identity{Name: "notarius", Version: version}, declarations...)
|
||||
}
|
||||
|
||||
func checkConfigSelection(selection ckconfig.Selection) error {
|
||||
if selection.Config.Set && strings.TrimSpace(selection.Config.Value) == "" {
|
||||
return fmt.Errorf("--config must not be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user