Upgrade PromptKit and assemble native configuration sources
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/readonlyfs"
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
)
|
||||
@@ -99,43 +100,43 @@ func (r *AssetRegistry) FallbackProfileDigest() (string, error) {
|
||||
return digest, err
|
||||
}
|
||||
|
||||
func (r *AssetRegistry) PromptKitOptions() ([]promptkit.Option, error) {
|
||||
options, _, err := r.promptKitOptions()
|
||||
return options, err
|
||||
}
|
||||
|
||||
func (r *AssetRegistry) promptKitOptions() ([]promptkit.Option, string, error) {
|
||||
promptFS, err := r.PromptFS()
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("prepare prompt assets: %w", err)
|
||||
// PromptKitConfigurationSources returns the registered prompt and fallback
|
||||
// profile assets as native PromptKit underlay groups. Schema assets remain a
|
||||
// separate PromptKit option because they are runtime validation resources.
|
||||
func (r *AssetRegistry) PromptKitConfigurationSources() (promptkit.ConfigurationSources, []promptkit.Option, error) {
|
||||
if r == nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("asset registry must not be nil")
|
||||
}
|
||||
underlays, err := promptKitFilesystemUnderlays(r.prompts, "notarius-prompts")
|
||||
if err != nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("prepare prompt configuration sources: %w", err)
|
||||
}
|
||||
profiles, err := promptKitFilesystemUnderlays(r.fallbackProfiles, "notarius-fallback-profiles")
|
||||
if err != nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("prepare fallback profile configuration sources: %w", err)
|
||||
}
|
||||
underlays = append(underlays, profiles...)
|
||||
schemaFS, err := r.SchemaFS()
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("prepare schema assets: %w", err)
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("prepare schema assets: %w", err)
|
||||
}
|
||||
options := []promptkit.Option{
|
||||
promptkit.WithPromptFS(promptFS, "."),
|
||||
return promptkit.ConfigurationSources{Underlays: underlays}, []promptkit.Option{
|
||||
promptkit.WithSchemaFS(schemaFS, "."),
|
||||
}
|
||||
fallbackFS, fallbackDigest, hasFallback, err := r.fallbackProfileAssets()
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if hasFallback {
|
||||
options = append(options, promptkit.WithFallbackProfileFS(fallbackFS, "."))
|
||||
}
|
||||
return options, fallbackDigest, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *AssetRegistry) promptKitFallbackProfileOption() (promptkit.Option, bool, error) {
|
||||
fallbackFS, _, hasFallback, err := r.fallbackProfileAssets()
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
func promptKitFilesystemUnderlays(sources []AssetSource, label string) ([]configkit.Underlay, error) {
|
||||
underlays := make([]configkit.Underlay, 0, len(sources))
|
||||
for index, source := range sources {
|
||||
inputs, err := promptkit.FilesystemInputs(fmt.Sprintf("%s-%d", label, index), source.FS, source.Root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("select filesystem inputs: %w", err)
|
||||
}
|
||||
if len(inputs) != 0 {
|
||||
underlays = append(underlays, configkit.Underlay{Inputs: inputs})
|
||||
}
|
||||
}
|
||||
if !hasFallback {
|
||||
return nil, false, nil
|
||||
}
|
||||
return promptkit.WithFallbackProfileFS(fallbackFS, "."), true, nil
|
||||
return underlays, nil
|
||||
}
|
||||
|
||||
func (r *AssetRegistry) fallbackProfileAssets() (fs.FS, string, bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user