Capture owned resources from resolved settings
This commit is contained in:
@@ -42,6 +42,8 @@ const (
|
||||
|
||||
type loaded struct {
|
||||
result *configkit.Result[document]
|
||||
view configkit.Inspection
|
||||
diagnostics []configkit.Diagnostic
|
||||
promptMetadata map[string][]promptInputPresence
|
||||
prompts map[string]*promptEntry
|
||||
registry *backend.Registry
|
||||
@@ -187,9 +189,6 @@ func configurationDefinition() configkit.Definition[document] {
|
||||
|
||||
// load performs one ConfigKit lifecycle over the selected source tiers.
|
||||
func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error) {
|
||||
state := &loaded{
|
||||
promptMetadata: make(map[string][]promptInputPresence),
|
||||
}
|
||||
result, err := configkit.LoadLayered(main, configkit.LayeredOptions[document]{
|
||||
Underlays: underlays,
|
||||
Definition: configurationDefinition(),
|
||||
@@ -197,14 +196,40 @@ func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
view, ok := result.InspectSubtree(configkit.Keys("promptkit"))
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("load configuration: inspection unavailable")
|
||||
}
|
||||
state, err := Capture(&result.Config.PromptKit, view, result.Diagnostics())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
state.result = result
|
||||
if err := state.materializePrompts(); err != nil {
|
||||
return state, nil
|
||||
}
|
||||
|
||||
// Capture builds owned runtime resources from effective settings and native evidence.
|
||||
func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []configkit.Diagnostic) (*loaded, error) {
|
||||
config := ownSettings(input)
|
||||
state := &loaded{view: view, diagnostics: ownDiagnostics(diagnostics), promptMetadata: make(map[string][]promptInputPresence)}
|
||||
metadata := view.Metadata()
|
||||
for _, resources := range resourceSets(&config) {
|
||||
for index, entry := range resources.prompts {
|
||||
presence := make([]promptInputPresence, len(entry.Inputs))
|
||||
for i := range entry.Inputs {
|
||||
path := resources.bases.prompts.Index(index).Key("inputs").Index(i)
|
||||
presence[i] = promptInputPresence{required: finalFieldState(metadata, path.Key("required")), contentType: finalFieldState(metadata, path.Key("content_type")), description: finalFieldState(metadata, path.Key("description"))}
|
||||
}
|
||||
state.promptMetadata[indexedResourceID(resources.namespace, entry.ID)] = presence
|
||||
}
|
||||
}
|
||||
if err := state.materializePrompts(&config, metadata); err != nil {
|
||||
return nil, fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
if err := state.buildExecutionProfiles(); err != nil {
|
||||
if err := state.buildExecutionProfiles(&config); err != nil {
|
||||
return nil, fmt.Errorf("load configuration: %w", err)
|
||||
}
|
||||
state.backendIDs = sortedKeys(indexedBackends(&state.result.Config.PromptKit))
|
||||
state.backendIDs = sortedKeys(indexedBackends(&config))
|
||||
state.profileIDs = sortedKeys(state.indexedProfiles)
|
||||
for _, id := range sortedKeys(state.prompts) {
|
||||
state.promptIDs = append(state.promptIDs, domain.PromptIdentity{ID: id})
|
||||
@@ -214,8 +239,8 @@ func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error)
|
||||
"profile": resourceNamespaces(state.profileIDs),
|
||||
"prompt": promptNamespaces(state.promptIDs),
|
||||
}
|
||||
for _, namespace := range sortedKeys(result.Config.PromptKit.Collections) {
|
||||
collection := result.Config.PromptKit.Collections[namespace]
|
||||
for _, namespace := range sortedKeys(config.Collections) {
|
||||
collection := config.Collections[namespace]
|
||||
state.collections = append(state.collections, CollectionIdentity{
|
||||
Namespace: namespace, ReleaseVersion: stringPointerValue(collection.ReleaseVersion),
|
||||
})
|
||||
@@ -223,6 +248,29 @@ func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error)
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func finalFieldState(metadata configkit.Metadata, path configkit.Path) fieldState {
|
||||
info, exists := metadata.Lookup(path)
|
||||
if !exists || !info.Explicit {
|
||||
return fieldAbsent
|
||||
}
|
||||
if info.Null {
|
||||
return fieldNull
|
||||
}
|
||||
return fieldValue
|
||||
}
|
||||
|
||||
func ownDiagnostics(values []configkit.Diagnostic) []configkit.Diagnostic {
|
||||
if values == nil {
|
||||
return nil
|
||||
}
|
||||
result := append([]configkit.Diagnostic(nil), values...)
|
||||
for i := range result {
|
||||
result[i].Primary = copyPointer(result[i].Primary)
|
||||
result[i].Related = append([]configkit.Location(nil), result[i].Related...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func resourceNamespaces(ids []string) []string {
|
||||
namespaces := make(map[string]struct{})
|
||||
for _, id := range ids {
|
||||
|
||||
Reference in New Issue
Block a user