53 lines
2.0 KiB
Go
53 lines
2.0 KiB
Go
// Package catalog selects the maintained configuration assets supplied with
|
|
// PromptKit. ConfigKit owns their composition and effective validation.
|
|
package catalog
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io/fs"
|
|
|
|
"gitea.maximumdirect.net/eric/ConfigKit"
|
|
openrouter "gitea.maximumdirect.net/eric/promptkit-backend-openrouter/v3"
|
|
rakestrawhome "gitea.maximumdirect.net/eric/promptkit-backend-rakestrawhome/v3"
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/backend"
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/filecatalog"
|
|
)
|
|
|
|
// Underlays selects external catalogs followed by PromptKit-owned profiles.
|
|
// Neither group is interpreted before the final effective configuration loads.
|
|
func Underlays() ([]configkit.Underlay, error) {
|
|
openrouterInputs, err := assetInputs("OpenRouter catalog", openrouter.FS(), openrouter.Root)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rakestrawhomeInputs, err := assetInputs("Rakestrawhome catalog", rakestrawhome.FS(), rakestrawhome.Root)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
catalogInputs := append(openrouterInputs, rakestrawhomeInputs...)
|
|
owned := configkit.Input{Source: configkit.Mapping("PromptKit-owned profiles", map[string]any{
|
|
"profiles": map[string]any{
|
|
"promptkit-openrouter-standard": map[string]any{"extends": "gemini-flash-latest"},
|
|
"promptkit-openrouter-auto": map[string]any{"backend": backend.OpenRouterID, "model": "openrouter/auto"},
|
|
},
|
|
})}
|
|
return []configkit.Underlay{{Inputs: catalogInputs}, {Inputs: []configkit.Input{owned}}}, nil
|
|
}
|
|
|
|
func assetInputs(label string, filesystem fs.FS, root string) ([]configkit.Input, error) {
|
|
files, err := filecatalog.FindFSYAMLFiles(context.Background(), filesystem, root)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("discover %s configuration: %w", label, err)
|
|
}
|
|
namespace := configkit.NewFilesystem(label, filesystem)
|
|
inputs := make([]configkit.Input, 0, len(files))
|
|
for _, name := range files {
|
|
inputs = append(inputs, configkit.Input{
|
|
Source: namespace.File(name),
|
|
Filesystem: &configkit.FilesystemContext{FS: &namespace, Root: root},
|
|
})
|
|
}
|
|
return inputs, nil
|
|
}
|