Compose application and prompt configuration together
This commit is contained in:
89
internal/appconfig/config.go
Normal file
89
internal/appconfig/config.go
Normal file
@@ -0,0 +1,89 @@
|
||||
// Package appconfig composes Audita and PromptKit configuration sources.
|
||||
package appconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/responseschema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/prompts"
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// Config combines Audita's root settings with native PromptKit settings.
|
||||
type Config struct {
|
||||
Application config.Config `yaml:",inline"`
|
||||
PromptKit pk.Settings `yaml:"promptkit"`
|
||||
}
|
||||
|
||||
const glossaryImports = `config:
|
||||
imports:
|
||||
- path: glossary.yml
|
||||
required: false
|
||||
destination: [glossary_collections]
|
||||
- dir: glossary
|
||||
required: false
|
||||
recursive: true
|
||||
pattern: ["*.yml", "*.yaml"]
|
||||
destination: [glossary_collections]
|
||||
`
|
||||
|
||||
const operatorImports = `config:
|
||||
imports:
|
||||
- path: prompts.yml
|
||||
required: false
|
||||
- dir: prompts
|
||||
required: false
|
||||
recursive: true
|
||||
pattern: ["*.yml", "*.yaml"]
|
||||
`
|
||||
|
||||
// Definition combines application rules with PromptKit's native rules.
|
||||
func Definition() ck.Definition[Config] {
|
||||
domain := config.Definition()
|
||||
definition := ck.Definition[Config]{
|
||||
Defaults: func() Config { return Config{Application: domain.Defaults()} },
|
||||
Version: domain.Version,
|
||||
SequenceIdentities: domain.SequenceIdentities,
|
||||
Sensitive: domain.Sensitive,
|
||||
Resolve: func(value *Config, resolution *ck.Resolution) error {
|
||||
return domain.Resolve(&value.Application, resolution)
|
||||
},
|
||||
Validate: func(value *Config, validation *ck.Validation) {
|
||||
domain.Validate(&value.Application, validation)
|
||||
},
|
||||
}
|
||||
return pk.Configure(definition, func(value *Config) *pk.Settings { return &value.PromptKit })
|
||||
}
|
||||
|
||||
// Load composes built-in resources and optional companions with the selected input.
|
||||
func Load(input ck.Input, overlay string, overrides ...ck.Override) (*ck.Result[Config], error) {
|
||||
embedded, err := pk.FilesystemInputs("Audita embedded prompts", prompts.Filesystem(), prompts.AssetRoot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("discover embedded prompts: %w", err)
|
||||
}
|
||||
for i := range embedded {
|
||||
embedded[i].Destination = ck.Keys("promptkit")
|
||||
}
|
||||
schemas := ck.NewFilesystem("Audita embedded schemas", responseschema.Filesystem())
|
||||
embedded = append(embedded, ck.Input{
|
||||
Source: pk.SchemaRootSource("Audita embedded schemas", responseschema.AssetRoot),
|
||||
Destination: ck.Keys("promptkit"),
|
||||
Filesystem: &ck.FilesystemContext{FS: &schemas, Root: ".", BaseDir: "."},
|
||||
})
|
||||
input.Imports = true
|
||||
return ck.LoadLayered(input, ck.LayeredOptions[Config]{
|
||||
Definition: Definition(),
|
||||
Overlay: overlay,
|
||||
Overrides: overrides,
|
||||
Underlays: []ck.Underlay{
|
||||
pk.BundledOpenRouterUnderlay(),
|
||||
{Inputs: embedded},
|
||||
{Inputs: []ck.Input{
|
||||
{Source: ck.Bytes("Audita glossary imports", []byte(glossaryImports)), Imports: true, MainRelative: ck.MainRelative()},
|
||||
{Source: ck.Bytes("Audita automatic prompt imports", []byte(operatorImports)), Destination: ck.Keys("promptkit"), Imports: true, MainRelative: ck.MainRelative()},
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user