Capture schema roots from configuration sources
This commit is contained in:
@@ -40,6 +40,19 @@ func (state *loaded) materializePrompts() error {
|
||||
}
|
||||
return metadata.Lookup(path)
|
||||
}
|
||||
applicationRoot, err := state.captureSchemaRoot(state.result.Config.SchemaRoot, configkit.Keys("schema_root"), lookupOrigin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roots := make(map[string]*domain.ResourceBinding, len(state.result.Config.Collections))
|
||||
for _, name := range sortedKeys(state.result.Config.Collections) {
|
||||
collection := state.result.Config.Collections[name]
|
||||
root, err := state.captureSchemaRoot(collection.SchemaRoot, configkit.Keys("collections", name, "schema_root"), lookupOrigin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roots[name] = root
|
||||
}
|
||||
for _, resources := range resourceSets(&state.result.Config) {
|
||||
for index, raw := range resources.prompts {
|
||||
promptBase := resources.bases.prompts.Index(index)
|
||||
@@ -51,12 +64,39 @@ func (state *loaded) materializePrompts() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entry.definition.SchemaRoot = applicationRoot
|
||||
if root := roots[resources.namespace]; resources.isCollection && root != nil {
|
||||
entry.definition.SchemaRoot = root
|
||||
}
|
||||
state.prompts[fullID] = entry
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (state *loaded) captureSchemaRoot(root *string, fieldPath configkit.Path, lookupOrigin func(configkit.Path) (configkit.FieldInfo, bool)) (*domain.ResourceBinding, error) {
|
||||
if root == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if strings.TrimSpace(*root) == "" {
|
||||
return nil, fmt.Errorf("%s: schema_root must not be blank", fieldPath)
|
||||
}
|
||||
field, found := lookupOrigin(fieldPath)
|
||||
if !found || len(field.Origin.Locations) != 1 {
|
||||
return nil, fmt.Errorf("%s: schema_root needs one contributing source with a filesystem context", fieldPath)
|
||||
}
|
||||
sourceID := field.Origin.Locations[0].SourceID
|
||||
context, found := state.result.SourceContext(sourceID)
|
||||
if !found || context.FS == nil {
|
||||
return nil, fmt.Errorf("%s: schema_root source %s has no filesystem context", fieldPath, sourceID)
|
||||
}
|
||||
resolved, _, err := filecatalog.ResolveFSPath(".", context.BaseDir, *root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: invalid schema_root: %w", fieldPath, err)
|
||||
}
|
||||
return &domain.ResourceBinding{FS: context.FS, Path: resolved}, nil
|
||||
}
|
||||
|
||||
func (state *loaded) materializePrompt(id string, raw promptConfig, base configkit.Path, lookupOrigin func(configkit.Path) (configkit.FieldInfo, bool)) (*promptEntry, error) {
|
||||
if len(raw.Messages) == 0 {
|
||||
return nil, fmt.Errorf("%s: at least one message is required", base.Key("messages"))
|
||||
@@ -275,6 +315,14 @@ func (state *loaded) lookupPromptEntry(id string) (*promptEntry, error) {
|
||||
|
||||
func ownPromptDefinition(definition domain.PromptDefinition) *domain.PromptDefinition {
|
||||
definition.Validation = ownOutputContract(definition.Validation)
|
||||
if definition.SchemaRoot != nil {
|
||||
root := *definition.SchemaRoot
|
||||
definition.SchemaRoot = &root
|
||||
}
|
||||
if definition.SchemaFile != nil {
|
||||
file := *definition.SchemaFile
|
||||
definition.SchemaFile = &file
|
||||
}
|
||||
definition.Inputs = append([]domain.PromptInput(nil), definition.Inputs...)
|
||||
definition.Templates = append([]domain.PromptMessageTemplate(nil), definition.Templates...)
|
||||
for index := range definition.Templates {
|
||||
|
||||
Reference in New Issue
Block a user