Prepare resolved documents and autocorrection rules

This commit is contained in:
2026-11-30 00:31:36 +00:00
parent 5c4ca20b11
commit 4e94b2157b
22 changed files with 197 additions and 335 deletions

View File

@@ -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 {