Attach prompt export values in module registry
This commit is contained in:
@@ -21,6 +21,8 @@ type ModuleContext struct {
|
||||
|
||||
type ModuleBuilder func(ModuleContext, any) (*module.Output, error)
|
||||
|
||||
type ModulePromptExporter func(value any) (any, error)
|
||||
|
||||
type ModuleDefinition struct {
|
||||
ID module.ID
|
||||
StanzaName string
|
||||
@@ -31,6 +33,7 @@ type ModuleDefinition struct {
|
||||
MissingData module.MissingDataBehavior
|
||||
AllowDuplicate bool
|
||||
Builder ModuleBuilder
|
||||
PromptExporter ModulePromptExporter
|
||||
}
|
||||
|
||||
type ModuleRegistry struct {
|
||||
@@ -130,6 +133,15 @@ func (r ModuleRegistry) BuildModule(ctx ModuleContext, item module.ConfigItem) (
|
||||
if output.StanzaName != definition.StanzaName {
|
||||
return nil, fmt.Errorf("module %q produced stanza %q, want %q", definition.ID, output.StanzaName, definition.StanzaName)
|
||||
}
|
||||
if definition.PromptExporter == nil {
|
||||
output.PromptValue = output.Value
|
||||
return output, nil
|
||||
}
|
||||
promptValue, err := definition.PromptExporter(output.Value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("module %q stanza %q prompt export: %w", definition.ID, definition.StanzaName, err)
|
||||
}
|
||||
output.PromptValue = promptValue
|
||||
return output, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user