Capture owned resources from resolved settings
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"go.maximumdirect.net/promptkit/internal/jsonvalue"
|
||||
"go.maximumdirect.net/promptkit/internal/prompt"
|
||||
"go.maximumdirect.net/promptkit/internal/promptdef"
|
||||
"go.maximumdirect.net/promptkit/internal/settings"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,30 +31,25 @@ type promptEntry struct {
|
||||
messages []*template.Template
|
||||
}
|
||||
|
||||
func (state *loaded) materializePrompts() error {
|
||||
func (state *loaded) materializePrompts(config *settings.Settings, metadata configkit.Metadata) error {
|
||||
state.prompts = make(map[string]*promptEntry)
|
||||
var metadata *configkit.Metadata
|
||||
lookupOrigin := func(path configkit.Path) (configkit.FieldInfo, bool) {
|
||||
if metadata == nil {
|
||||
captured := state.result.Metadata()
|
||||
metadata = &captured
|
||||
}
|
||||
return metadata.Lookup(path)
|
||||
}
|
||||
applicationRoot, err := state.captureSchemaRoot(state.result.Config.PromptKit.SchemaRoot, configkit.Keys("promptkit", "schema_root"), lookupOrigin)
|
||||
applicationRoot, err := state.captureSchemaRoot(config.SchemaRoot, configkit.Keys("promptkit", "schema_root"), lookupOrigin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roots := make(map[string]*domain.ResourceBinding, len(state.result.Config.PromptKit.Collections))
|
||||
for _, name := range sortedKeys(state.result.Config.PromptKit.Collections) {
|
||||
collection := state.result.Config.PromptKit.Collections[name]
|
||||
roots := make(map[string]*domain.ResourceBinding, len(config.Collections))
|
||||
for _, name := range sortedKeys(config.Collections) {
|
||||
collection := config.Collections[name]
|
||||
root, err := state.captureSchemaRoot(collection.SchemaRoot, configkit.Keys("promptkit", "collections", name, "schema_root"), lookupOrigin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roots[name] = root
|
||||
}
|
||||
for _, resources := range resourceSets(&state.result.Config.PromptKit) {
|
||||
for _, resources := range resourceSets(config) {
|
||||
root := applicationRoot
|
||||
if selected := roots[resources.namespace]; resources.isCollection && selected != nil {
|
||||
root = selected
|
||||
@@ -284,7 +280,7 @@ func (state *loaded) bindResource(fieldPath configkit.Path, name, label string,
|
||||
return nil, "", fmt.Errorf("%s: %s needs one contributing source with a filesystem context", fieldPath, label)
|
||||
}
|
||||
sourceID := field.Origin.Locations[0].SourceID
|
||||
context, found := state.result.SourceContext(sourceID)
|
||||
context, found := state.view.SourceContext(sourceID)
|
||||
if !found || context.FS == nil {
|
||||
return nil, "", fmt.Errorf("%s: %s source %s has no filesystem context", fieldPath, label, sourceID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user