Prepare resolved documents and autocorrection rules
This commit is contained in:
@@ -138,10 +138,10 @@ type CampaignInputsConfig struct {
|
||||
System *string `yaml:"system" json:"system"`
|
||||
Glossary map[string]any `yaml:"glossary" json:"glossary"`
|
||||
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file" json:"autocorrect_file"`
|
||||
AutocorrectFile string `yaml:"-" json:"-"`
|
||||
GlossaryFile *string `yaml:"glossary_file" json:"glossary_file"`
|
||||
PartyFile string `yaml:"party_file" json:"party_file"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file" json:"spell_catalog_file"`
|
||||
SpellCatalogFile string `yaml:"-" json:"-"`
|
||||
Autocorrect []AutocorrectionRule `yaml:"autocorrect" json:"autocorrect"`
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,20 @@ func sessionFieldExplicit(cfg *SessionConfig, name string) bool {
|
||||
return result != nil && result.Metadata().IsExplicit(configkit.Keys("inputs", name))
|
||||
}
|
||||
|
||||
// AutocorrectionSource identifies the authored source of the selected rules.
|
||||
func AutocorrectionSource(cfg *Config) string {
|
||||
if cfg == nil || cfg.Session == nil {
|
||||
return "derived_from_configuration"
|
||||
}
|
||||
if sessionFieldExplicit(cfg.Session, "autocorrect") || (cfg.Session.ConfigKitResult() == nil && cfg.Session.Inputs.Autocorrect != nil) {
|
||||
return "session_config"
|
||||
}
|
||||
if cfg.Campaign != nil && cfg.Campaign.Inputs.Autocorrect != nil {
|
||||
return "campaign_config"
|
||||
}
|
||||
return "derived_from_configuration"
|
||||
}
|
||||
|
||||
func documentResource(resolution *configkit.Resolution, path configkit.Path, value *string, invocationDir string, sources map[string]string) {
|
||||
if info, ok := resolution.EntryInfo(path); ok && len(info.Origin.Locations) == 1 {
|
||||
if source, ok := resolution.Source(info.Origin.Locations[0].SourceID); ok {
|
||||
|
||||
@@ -69,13 +69,9 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
if result != nil {
|
||||
metadata = result.Metadata()
|
||||
}
|
||||
// Materialized sessions retain authored overrides and receiving-campaign defaults.
|
||||
inputValue := func(name, value string) *string {
|
||||
if result != nil {
|
||||
if !metadata.IsExplicit(configkit.Keys("inputs", name)) {
|
||||
return nil
|
||||
}
|
||||
} else if value == "" {
|
||||
// Materialized sessions carry the resolved values needed independently of the campaign.
|
||||
inputValue := func(value string) *string {
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
@@ -87,8 +83,8 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||
glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, true)}
|
||||
inputValue(doc.Inputs.SpeakersFile),
|
||||
glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, false)}
|
||||
autocorrectPath := configkit.Keys("inputs", "autocorrect")
|
||||
if result != nil && metadata.IsExplicit(autocorrectPath) {
|
||||
if info, ok := metadata.Lookup(autocorrectPath); ok && info.Null {
|
||||
@@ -96,7 +92,7 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
} else {
|
||||
inputs.Extra["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
} else if result == nil && doc.Inputs.Autocorrect != nil {
|
||||
} else if doc.Inputs.Autocorrect != nil {
|
||||
inputs.Extra["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
value := struct {
|
||||
@@ -110,6 +106,16 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
return yaml.Marshal(value)
|
||||
}
|
||||
|
||||
// RenderAutocorrection produces the Seriatim rule-list envelope.
|
||||
func RenderAutocorrection(rules []AutocorrectionRule) ([]byte, error) {
|
||||
if rules == nil {
|
||||
rules = []AutocorrectionRule{}
|
||||
}
|
||||
return yaml.Marshal(struct {
|
||||
Autocorrect []AutocorrectionRule `yaml:"autocorrect"`
|
||||
}{Autocorrect: rules})
|
||||
}
|
||||
|
||||
func glossaryFields(hasResult bool, metadata configkit.Metadata, setting, system, file *string, glossary map[string]any, authoredOnly bool) map[string]any {
|
||||
result := map[string]any{}
|
||||
for _, field := range []struct {
|
||||
|
||||
@@ -304,10 +304,8 @@ func deriveStableInputs(campaignCfg *CampaignConfig, sessionCfg *SessionConfig,
|
||||
campaignOnly bool
|
||||
}{
|
||||
{"speakers_file", sessionCfg.Inputs.SpeakersFile, &stable.SpeakersFile, false},
|
||||
{"autocorrect_file", sessionCfg.Inputs.AutocorrectFile, &stable.AutocorrectFile, false},
|
||||
{"glossary_file", OptionalString(sessionCfg.Inputs.GlossaryFile), &stable.GlossaryFile, false},
|
||||
{"party_file", campaignCfg.Inputs.PartyFile, &stable.PartyFile, true},
|
||||
{"spell_catalog_file", sessionCfg.Inputs.SpellCatalogFile, &stable.SpellCatalogFile, false},
|
||||
} {
|
||||
reference := ResolvedInputFile{Path: field.value, ConfigPath: sessionPath, Source: "session_config"}
|
||||
metadata := sessionCfg.resolution
|
||||
|
||||
@@ -66,6 +66,13 @@ narratio:
|
||||
if len(again.Inputs.Autocorrect) != tc.rules || (again.Inputs.Glossary != nil) != tc.glossary {
|
||||
t.Fatalf("snapshot: %s", output)
|
||||
}
|
||||
standalone, err := LoadSessionBytesWithOptions("snapshot.yml", output, SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("standalone snapshot: %v\n%s", err, output)
|
||||
}
|
||||
if len(standalone.Inputs.Autocorrect) != tc.rules || (standalone.Inputs.Glossary != nil) != tc.glossary {
|
||||
t.Fatalf("standalone snapshot: %s", output)
|
||||
}
|
||||
})
|
||||
}
|
||||
output, err := RenderCampaignDocument(&Config{Campaign: campaign})
|
||||
|
||||
@@ -37,7 +37,7 @@ func Validate(cfg *Config) error {
|
||||
if _, err := DeriveArtifactCatalog(cfg.Pipeline, cfg.Party); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateCrossConfig(cfg.Pipeline, cfg.Session, cfg.StableInputs); err != nil {
|
||||
if err := validateCrossConfig(cfg.Pipeline, cfg.Session); err != nil {
|
||||
return fmt.Errorf("pipeline/session config invalid: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||
)
|
||||
|
||||
@@ -118,19 +117,10 @@ func validateSessionIdentifier(fieldName, value string, required bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCrossConfig(pipeline *PipelineConfig, session *SessionConfig, stableInputs ResolvedStableInputs) error {
|
||||
func validateCrossConfig(pipeline *PipelineConfig, session *SessionConfig) error {
|
||||
if pipeline == nil || session == nil {
|
||||
return nil
|
||||
}
|
||||
if pipeline.Notarius != nil && pipeline.Notarius.Enabled {
|
||||
for _, selector := range sortedStringKeys(pipeline.Notarius.References) {
|
||||
source := pipeline.Notarius.References[selector]
|
||||
if source == artifactpolicy.SourceInputSpellCatalog && strings.TrimSpace(stableInputs.SpellCatalogFile.Path) == "" {
|
||||
return fmt.Errorf("pipeline.notarius.references.%s requires campaign.inputs.spell_catalog_file or session.inputs.spell_catalog_file", selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
audioS3Enabled := session.Inputs.AudioS3 != nil
|
||||
publishUploadEnabled := publishUploadConfiguredForS3(pipeline)
|
||||
if audioS3Enabled && !strings.EqualFold(strings.TrimSpace(pipeline.Storage.Backend), StorageBackendS3) {
|
||||
|
||||
Reference in New Issue
Block a user