Share runtime glossaries with inspection commands
This commit is contained in:
@@ -24,6 +24,7 @@ type invocationState struct {
|
||||
}
|
||||
type engineEntry struct {
|
||||
selection ckconfig.Selection
|
||||
input acquisitionInput
|
||||
engine *pk.Engine
|
||||
}
|
||||
|
||||
@@ -48,15 +49,15 @@ func acquireApplication(ctx context.Context, selection ckconfig.Selection, input
|
||||
return loaded, reportBootstrap(ctx, report, err)
|
||||
}
|
||||
|
||||
func loadApplication(ctx context.Context, selection ckconfig.Selection, _ struct{}, _ *invocationState) (*ck.Result[appconfig.Config], error) {
|
||||
loaded, err := acquireApplication(ctx, selection, acquisitionInput{})
|
||||
func loadApplication(ctx context.Context, selection ckconfig.Selection, input acquisitionInput, _ *invocationState) (*ck.Result[appconfig.Config], error) {
|
||||
loaded, err := acquireApplication(ctx, selection, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return loaded.Result, nil
|
||||
}
|
||||
|
||||
func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input struct{}, state *invocationState) (*pk.Engine, error) {
|
||||
func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input acquisitionInput, state *invocationState) (*pk.Engine, error) {
|
||||
loaded, err := loadApplication(ctx, selection, input, state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -68,10 +69,10 @@ func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input s
|
||||
return llm.NewEngine(ctx, loaded, client)
|
||||
}
|
||||
|
||||
func capturePromptEngine(ctx context.Context, selection ckconfig.Selection, input struct{}, state *invocationState) (*pk.Engine, error) {
|
||||
func capturePromptEngine(ctx context.Context, selection ckconfig.Selection, input acquisitionInput, state *invocationState) (*pk.Engine, error) {
|
||||
if state != nil {
|
||||
for _, entry := range state.engines {
|
||||
if reflect.DeepEqual(entry.selection, selection) {
|
||||
if reflect.DeepEqual(entry.selection, selection) && reflect.DeepEqual(entry.input, input) {
|
||||
return entry.engine, nil
|
||||
}
|
||||
}
|
||||
@@ -81,27 +82,38 @@ func capturePromptEngine(ctx context.Context, selection ckconfig.Selection, inpu
|
||||
return nil, err
|
||||
}
|
||||
if state != nil {
|
||||
state.engines = append(state.engines, engineEntry{selection: selection, engine: engine})
|
||||
state.engines = append(state.engines, engineEntry{selection: selection, input: acquisitionInput{GlossaryFiles: append([]string(nil), input.GlossaryFiles...)}, engine: engine})
|
||||
}
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
func shareComparisonGlossaries(scope ckconfig.Scope[acquisitionInput, *invocationState]) ckconfig.Scope[acquisitionInput, *invocationState] {
|
||||
compare := scope.Compare
|
||||
scope.Compare = func(ctx context.Context, request ckconfig.ComparisonRequest[acquisitionInput], state *invocationState) (commandkit.Acquired[[]ck.Difference], error) {
|
||||
request.Right.Input.GlossaryFiles = append([]string(nil), request.Left.Input.GlossaryFiles...)
|
||||
return compare(ctx, request, state)
|
||||
}
|
||||
return scope
|
||||
}
|
||||
|
||||
func buildApplication(extra ...commandkit.Declaration) (*commandkit.App, error) {
|
||||
return buildApplicationWithClient(nil, extra...)
|
||||
}
|
||||
|
||||
func buildApplicationWithClient(client *http.Client, extra ...commandkit.Declaration) (*commandkit.App, error) {
|
||||
selector := commandkit.RepeatFlag(commandkit.FlagMeta{Name: "glossary-file", Usage: "Runtime glossary file (repeatable)."}, nil, func(s string) (string, error) { return s, nil }, func(in *acquisitionInput, value commandkit.Supplied[[]string]) { in.GlossaryFiles = value.Value })
|
||||
appScope := ckconfig.FromConfigKit("app", "Audita application settings.", loadApplication)
|
||||
appScope.Features.Overrides = true
|
||||
appScope = withBootstrapContext(appScope)
|
||||
promptScope := withBootstrapContext(ckprompt.ConfigScope(loadPromptEngine))
|
||||
configCommand := ckconfig.Command(ckconfig.Suite[struct{}, *invocationState]{NewState: func() *invocationState { return &invocationState{client: client} }, Scopes: []ckconfig.Scope[struct{}, *invocationState]{appScope, promptScope}})
|
||||
appScope = shareComparisonGlossaries(withBootstrapContext(appScope))
|
||||
promptScope := shareComparisonGlossaries(withBootstrapContext(ckprompt.ConfigScope(loadPromptEngine)))
|
||||
configCommand := ckconfig.Command(ckconfig.Suite[acquisitionInput, *invocationState]{NewState: func() *invocationState { return &invocationState{client: client} }, Selectors: []ckconfig.Selector[acquisitionInput]{{Binding: selector, Scopes: []string{"app", "promptkit"}}}, Scopes: []ckconfig.Scope[acquisitionInput, *invocationState]{appScope, promptScope}})
|
||||
definitions := ckprompt.WithNamespaces(ckprompt.FromEngine(capturePromptEngine), pk.Namespaces{})
|
||||
definitions.NewState = func() *invocationState { return &invocationState{client: client} }
|
||||
definitions = ckprompt.WithRequestValidation(definitions, capturePromptEngine, func(_ context.Context, seed ckprompt.ValidationRequest, _ struct{}, _ *invocationState) (pk.RunRequest, error) {
|
||||
definitions.Selectors = []commandkit.Flag[acquisitionInput]{selector}
|
||||
definitions = ckprompt.WithRequestValidation(definitions, capturePromptEngine, func(_ context.Context, seed ckprompt.ValidationRequest, _ acquisitionInput, _ *invocationState) (pk.RunRequest, error) {
|
||||
return applicationPromptRequest(seed.Request, seed.Namespaces), nil
|
||||
})
|
||||
definitions = ckprompt.WithRequestPreparation(definitions, capturePromptEngine, func(_ context.Context, seed ckprompt.PreparationRequest, _ struct{}, _ *invocationState) (pk.RunRequest, error) {
|
||||
definitions = ckprompt.WithRequestPreparation(definitions, capturePromptEngine, func(_ context.Context, seed ckprompt.PreparationRequest, _ acquisitionInput, _ *invocationState) (pk.RunRequest, error) {
|
||||
return applicationPromptRequest(seed.Request, seed.Namespaces), nil
|
||||
})
|
||||
definitions = ckprompt.WithSmokeTesting(definitions, capturePromptEngine, nil)
|
||||
|
||||
Reference in New Issue
Block a user