88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package configuration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/domain"
|
|
)
|
|
|
|
// CollectionIdentity is the captured metadata for one final collection entry.
|
|
type CollectionIdentity struct {
|
|
Namespace string
|
|
ReleaseVersion *string
|
|
}
|
|
|
|
func (state *loaded) ListProfiles(ctx context.Context) ([]string, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
profiles := append([]string(nil), state.profileIDs...)
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return profiles, nil
|
|
}
|
|
|
|
func (state *loaded) ListBackends(ctx context.Context) ([]string, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
backends := append([]string(nil), state.backendIDs...)
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return backends, nil
|
|
}
|
|
|
|
func (state *loaded) ListNamespaces(ctx context.Context, kinds []string) ([]string, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
selected := kinds
|
|
if len(selected) == 0 {
|
|
selected = []string{"backend", "profile", "prompt"}
|
|
}
|
|
set := make(map[string]struct{})
|
|
for _, kind := range selected {
|
|
for _, namespace := range state.namespaces[kind] {
|
|
set[namespace] = struct{}{}
|
|
}
|
|
}
|
|
namespaces := sortedKeys(set)
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return namespaces, nil
|
|
}
|
|
|
|
func (state *loaded) ListCollections(ctx context.Context) ([]CollectionIdentity, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
collections := make([]CollectionIdentity, len(state.collections))
|
|
for index, collection := range state.collections {
|
|
collections[index] = CollectionIdentity{
|
|
Namespace: collection.Namespace,
|
|
ReleaseVersion: stringPointerValue(collection.ReleaseVersion),
|
|
}
|
|
}
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return collections, nil
|
|
}
|
|
|
|
func (state *loaded) ListPrompts(ctx context.Context) ([]domain.PromptIdentity, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
prompts := append([]domain.PromptIdentity(nil), state.promptIDs...)
|
|
for index := range prompts {
|
|
prompts[index].Version = stringPointerValue(prompts[index].Version)
|
|
}
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return prompts, nil
|
|
}
|