Compose runtime glossary files with native configuration
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/responseschema"
|
||||
@@ -30,6 +31,23 @@ type Config struct {
|
||||
PromptKit pk.Settings `yaml:"promptkit"`
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Overlay string
|
||||
Overrides []ck.Override
|
||||
GlossaryFiles []string
|
||||
}
|
||||
|
||||
type Acquisition struct {
|
||||
*ck.Result[Config]
|
||||
GlossarySources []string
|
||||
}
|
||||
|
||||
// GlossaryInputError identifies failures in the separate runtime input load.
|
||||
type GlossaryInputError struct{ Err error }
|
||||
|
||||
func (e *GlossaryInputError) Error() string { return e.Err.Error() }
|
||||
func (e *GlossaryInputError) Unwrap() error { return e.Err }
|
||||
|
||||
const glossaryImports = `config:
|
||||
imports:
|
||||
- path: glossary.yml
|
||||
@@ -71,7 +89,7 @@ func Definition() ck.Definition[Config] {
|
||||
}
|
||||
|
||||
// Load composes built-in resources and optional companions with the selected input.
|
||||
func Load(ctx context.Context, input ck.Input, overlay string, overrides ...ck.Override) (*ck.Result[Config], *ck.SecretsReport, error) {
|
||||
func Load(ctx context.Context, input ck.Input, options Options) (*Acquisition, *ck.SecretsReport, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -83,6 +101,38 @@ func Load(ctx context.Context, input ck.Input, overlay string, overrides ...ck.O
|
||||
return nil, report, err
|
||||
}
|
||||
input.Source = prepared
|
||||
var glossarySources []string
|
||||
overrides := append([]ck.Override(nil), options.Overrides...)
|
||||
if len(options.GlossaryFiles) > 0 {
|
||||
inputs := make([]ck.Input, len(options.GlossaryFiles))
|
||||
for i, path := range options.GlossaryFiles {
|
||||
absolute, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, report, &GlossaryInputError{Err: err}
|
||||
}
|
||||
inputs[i] = ck.Input{Source: ck.File(absolute), Imports: true}
|
||||
}
|
||||
underlays := make([]ck.Underlay, 0, len(inputs)-1)
|
||||
for _, item := range inputs[:len(inputs)-1] {
|
||||
underlays = append(underlays, ck.Underlay{Inputs: []ck.Input{item}})
|
||||
}
|
||||
glossaries, err := ck.LoadLayered(inputs[len(inputs)-1], ck.LayeredOptions[map[string]any]{
|
||||
Definition: ck.Definition[map[string]any]{SequenceIdentities: []ck.SequenceIdentity{config.GlossaryEntryIdentity(nil)}},
|
||||
Underlays: underlays,
|
||||
})
|
||||
if canceled := ctx.Err(); canceled != nil {
|
||||
return nil, report, errors.Join(err, canceled)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, report, &GlossaryInputError{Err: err}
|
||||
}
|
||||
for _, source := range glossaries.Sources() {
|
||||
if source.Kind == ck.SourceKindFile {
|
||||
glossarySources = append(glossarySources, source.Path)
|
||||
}
|
||||
}
|
||||
overrides = append(overrides, ck.Override{Path: ck.Keys("glossary_collections"), Value: glossaries.Config, Flag: "--glossary-file"})
|
||||
}
|
||||
embedded, err := pk.FilesystemInputs("Audita embedded prompts", prompts.Filesystem(), prompts.AssetRoot)
|
||||
if err != nil {
|
||||
return nil, report, &AssetError{Err: fmt.Errorf("discover embedded prompts: %w", err)}
|
||||
@@ -99,7 +149,7 @@ func Load(ctx context.Context, input ck.Input, overlay string, overrides ...ck.O
|
||||
input.Imports = true
|
||||
result, err := ck.LoadLayered(input, ck.LayeredOptions[Config]{
|
||||
Definition: Definition(),
|
||||
Overlay: overlay,
|
||||
Overlay: options.Overlay,
|
||||
Overrides: overrides,
|
||||
Underlays: []ck.Underlay{
|
||||
pk.BundledOpenRouterUnderlay(),
|
||||
@@ -113,5 +163,8 @@ func Load(ctx context.Context, input ck.Input, overlay string, overrides ...ck.O
|
||||
if canceled := ctx.Err(); canceled != nil {
|
||||
return nil, report, errors.Join(err, canceled)
|
||||
}
|
||||
return result, report, err
|
||||
if err != nil {
|
||||
return nil, report, err
|
||||
}
|
||||
return &Acquisition{Result: result, GlossarySources: glossarySources}, report, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user