69 lines
2.7 KiB
Go
69 lines
2.7 KiB
Go
package promptkit
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// PromptIdentity identifies one prompt ID and its optional descriptive version
|
|
// label in the effective configuration captured when an Engine is constructed.
|
|
// A nil Version means no label was declared; a non-nil empty string is an
|
|
// explicit label. 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 in the effective configuration captured
|
|
// when the engine was constructed, sorted lexically by ID. Each identity may
|
|
// include its descriptive version label. The returned slice and each Version
|
|
// pointer are 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: copyStringPtr(identity.Version)}
|
|
}
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, mapPublicError(err)
|
|
}
|
|
return public, nil
|
|
}
|