Add PromptKit catalog providers
This commit is contained in:
@@ -31,8 +31,9 @@ type ProfileRequest struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
// Suite describes application-owned input, shared state, and named inspection
|
||||
// capabilities. Its private issues retain adapter construction failures.
|
||||
// Suite describes application-owned input, shared state, and optional catalog
|
||||
// and named inspection capabilities. Its private issues retain adapter
|
||||
// construction failures.
|
||||
// Factory results and callback effects remain caller-owned: Command does not
|
||||
// deep-copy arbitrary objects or repair aliases returned by factories.
|
||||
// Factories are not invoked during construction, installation, help, or version,
|
||||
@@ -45,14 +46,22 @@ type Suite[I, S any] struct {
|
||||
// NewState is called once when inspection is reached, after input checks
|
||||
// pass. If nil, state is the zero value of S, including nil for pointer types.
|
||||
NewState func() S
|
||||
// Selectors declares the original typed flags accepted by definition commands.
|
||||
// Selectors declares the original typed flags accepted by definition and
|
||||
// catalog commands.
|
||||
Selectors []commandkit.Flag[I]
|
||||
// CheckInput validates the selected definition inputs before state creation.
|
||||
// CheckInput validates selected definition or catalog input before state
|
||||
// creation.
|
||||
CheckInput func(ckconfig.Selection, I) error
|
||||
// InspectPrompt inspects the selected prompt after input and state preparation.
|
||||
InspectPrompt func(context.Context, PromptRequest, I, S) (commandkit.Acquired[*promptkit.PromptInspection], error)
|
||||
// InspectProfile inspects the selected profile after input and state preparation.
|
||||
InspectProfile func(context.Context, ProfileRequest, I, S) (commandkit.Acquired[*promptkit.ProfileInspection], error)
|
||||
// ListPrompts lists prompt identities after input and state preparation.
|
||||
// It is optional; a nil callback does not install a prompt catalog command.
|
||||
ListPrompts func(context.Context, ckconfig.Selection, I, S) (commandkit.Acquired[[]promptkit.PromptIdentity], error)
|
||||
// ListProfiles lists profile IDs after input and state preparation.
|
||||
// It is optional; a nil callback does not install a profile catalog command.
|
||||
ListProfiles func(context.Context, ckconfig.Selection, I, S) (commandkit.Acquired[[]string], error)
|
||||
|
||||
issues []error
|
||||
}
|
||||
@@ -130,17 +139,34 @@ func promptKitContextError(ctx context.Context) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
// FromEngine creates named prompt and profile inspection callbacks backed by a
|
||||
// PromptKit engine loader. It does not call the loader during construction. Each
|
||||
// selected inspection passes its context, supplied selection, initialized input,
|
||||
// and shared invocation state to the loader before calling PromptKit's public
|
||||
// inspection method. A nil loader is retained as an adapter issue.
|
||||
// FromEngine creates prompt and profile catalog and inspection callbacks backed
|
||||
// by a PromptKit engine loader. It does not call the loader during construction.
|
||||
// Each selected operation passes its context, supplied selection, initialized
|
||||
// input, and shared invocation state to the loader before calling PromptKit's
|
||||
// public listing or inspection method. A nil loader is retained as an adapter
|
||||
// issue.
|
||||
func FromEngine[I, S any](load func(context.Context, ckconfig.Selection, I, S) (*promptkit.Engine, error)) Suite[I, S] {
|
||||
if load == nil {
|
||||
return Suite[I, S]{issues: []error{errors.New("PromptKit engine loader is nil")}}
|
||||
}
|
||||
|
||||
return Suite[I, S]{
|
||||
ListPrompts: func(ctx context.Context, selection ckconfig.Selection, input I, state S) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
engine, _, diagnostics, err := loadPromptKitEngine(ctx, selection, input, state, "", load)
|
||||
if err != nil {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Diagnostics: diagnostics}, err
|
||||
}
|
||||
prompts, err := engine.ListPrompts(ctx)
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: prompts, Diagnostics: diagnostics}, err
|
||||
},
|
||||
ListProfiles: func(ctx context.Context, selection ckconfig.Selection, input I, state S) (commandkit.Acquired[[]string], error) {
|
||||
engine, _, diagnostics, err := loadPromptKitEngine(ctx, selection, input, state, "", load)
|
||||
if err != nil {
|
||||
return commandkit.Acquired[[]string]{Diagnostics: diagnostics}, err
|
||||
}
|
||||
profiles, err := engine.ListProfiles(ctx)
|
||||
return commandkit.Acquired[[]string]{Value: profiles, Diagnostics: diagnostics}, err
|
||||
},
|
||||
InspectPrompt: func(ctx context.Context, request PromptRequest, input I, state S) (commandkit.Acquired[*promptkit.PromptInspection], error) {
|
||||
engine, _, diagnostics, err := loadPromptKitEngine(ctx, request.Selection, input, state, "", load)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user