Files
promptkit/listing.go

68 lines
2.6 KiB
Go

package promptkit
import (
"context"
"fmt"
)
// PromptIdentity identifies one prompt ID and exact version in the effective
// configuration captured when an Engine is constructed. It has no stable JSON
// representation.
type PromptIdentity struct {
ID string
Version string
}
// ListProfiles returns profile IDs in the effective configuration captured
// when the engine was constructed. Maintained and consumer profiles are
// included; an inherited profile retains its own ID. IDs are preserved exactly
// and sorted lexically. The returned slice is caller-owned and safe to mutate
// while the engine is used concurrently. Empty inventories succeed.
//
// Listing reports membership, not execution readiness. It does not reload
// configuration or perform resource, credential, provider, or execution work.
// Profile IDs are application data and may be sensitive. A nil or zero-value
// engine returns an error matching ErrInvalidConfig. Cancellation or deadline
// expiration returns the context error and no partial result.
func (e *Engine) ListProfiles(ctx context.Context) ([]string, error) {
if e == nil || e.internal == nil {
return nil, fmt.Errorf("%w: engine is nil", ErrInvalidConfig)
}
profiles, err := e.internal.ListProfiles(ctx)
if err != nil {
return nil, mapPublicError(err)
}
return profiles, nil
}
// ListPrompts returns every prompt ID and exact version in the effective
// configuration captured when the engine was constructed, sorted lexically by
// ID and then version. Versions are not interpreted or prioritized. The
// returned slice is caller-owned and safe to mutate while the engine is used
// concurrently. Empty inventories succeed.
//
// Listing reports membership, not execution readiness. It does not reload
// configuration or perform resource, credential, provider, or execution work.
// Prompt identities are application data and may be sensitive. A nil or
// zero-value engine returns an error matching ErrInvalidConfig. Cancellation
// or deadline expiration returns the context error and no partial result.
func (e *Engine) ListPrompts(ctx context.Context) ([]PromptIdentity, error) {
if e == nil || e.internal == nil {
return nil, fmt.Errorf("%w: engine is nil", ErrInvalidConfig)
}
identities, err := e.internal.ListPrompts(ctx)
if err != nil {
return nil, mapPublicError(err)
}
public := make([]PromptIdentity, len(identities))
for i, identity := range identities {
public[i] = PromptIdentity{ID: identity.ID, Version: identity.Version}
}
if err := ctx.Err(); err != nil {
return nil, mapPublicError(err)
}
return public, nil
}