72 lines
3.2 KiB
Go
72 lines
3.2 KiB
Go
// Package register composes the production D&D module family.
|
|
package register
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/modules/chunk/dnd/scenes"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/modules/extract/dnd/spells"
|
|
spellshape "gitea.maximumdirect.net/eric/notarius/internal/validators/extract/dnd/spells/shape"
|
|
spellsourcerefs "gitea.maximumdirect.net/eric/notarius/internal/validators/extract/dnd/spells/source_refs"
|
|
spellrelatedness "gitea.maximumdirect.net/eric/notarius/internal/validators/extract/dnd/spells/source_relatedness"
|
|
validjson "gitea.maximumdirect.net/eric/notarius/internal/validators/generic/valid_json"
|
|
validjsonschema "gitea.maximumdirect.net/eric/notarius/internal/validators/generic/valid_json_schema"
|
|
)
|
|
|
|
// Register adds all production D&D modules, validators, policy, and assets.
|
|
func Register(registries pipeline.Registries, assets *llm.AssetRegistry) error {
|
|
if err := validateRegistries(registries, assets); err != nil {
|
|
return err
|
|
}
|
|
registrations := []struct {
|
|
name string
|
|
register func() error
|
|
}{
|
|
{name: "scenes chunker", register: func() error { return scenes.Register(registries.Chunkers) }},
|
|
{name: "spells extractor", register: func() error { return spells.Register(registries.Extractors) }},
|
|
{name: "spell shape validator", register: func() error { return spellshape.Register(registries.Validators) }},
|
|
{name: "spell source references validator", register: func() error { return spellsourcerefs.Register(registries.Validators) }},
|
|
{name: "spell source relatedness validator", register: func() error { return spellrelatedness.Register(registries.Validators) }},
|
|
{name: "scenes prompt assets", register: func() error { return scenes.RegisterPromptAssets(assets) }},
|
|
{name: "spells prompt assets", register: func() error { return spells.RegisterPromptAssets(assets) }},
|
|
}
|
|
for _, registration := range registrations {
|
|
if err := registration.register(); err != nil {
|
|
return fmt.Errorf("register dnd %s: %w", registration.name, err)
|
|
}
|
|
}
|
|
if err := registries.ValidatorChains.Register(pipeline.ValidatorChainMapping{
|
|
Stage: pipeline.StageExtract,
|
|
Module: spells.Key,
|
|
Validators: []pipeline.ModuleBinding{
|
|
pipeline.Binding(validjson.Key),
|
|
pipeline.Binding(validjsonschema.Key),
|
|
pipeline.Binding(spellshape.Key),
|
|
pipeline.Binding(spellsourcerefs.Key),
|
|
pipeline.Binding(spellrelatedness.Key),
|
|
},
|
|
}); err != nil {
|
|
return fmt.Errorf("register dnd spells validator chain: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateRegistries(registries pipeline.Registries, assets *llm.AssetRegistry) error {
|
|
switch {
|
|
case registries.Chunkers == nil:
|
|
return fmt.Errorf("dnd registrar: chunker registry must not be nil")
|
|
case registries.Extractors == nil:
|
|
return fmt.Errorf("dnd registrar: extractor registry must not be nil")
|
|
case registries.Validators == nil:
|
|
return fmt.Errorf("dnd registrar: validator registry must not be nil")
|
|
case registries.ValidatorChains == nil:
|
|
return fmt.Errorf("dnd registrar: validator chain registry must not be nil")
|
|
case assets == nil:
|
|
return fmt.Errorf("dnd registrar: asset registry must not be nil")
|
|
default:
|
|
return nil
|
|
}
|
|
}
|