Add immutable namespace views
This commit is contained in:
@@ -84,6 +84,13 @@ type Engine struct {
|
||||
smokeTester *usecase.SmokeTester
|
||||
inspection configuration.Inspection
|
||||
listing identityInventory
|
||||
namespaces resourceNamespaces
|
||||
}
|
||||
|
||||
type resourceNamespaces struct {
|
||||
prompt string
|
||||
profile string
|
||||
backend string
|
||||
}
|
||||
|
||||
type identityInventory interface {
|
||||
@@ -145,6 +152,14 @@ func New(cfg Config, options Options) (*Engine, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithNamespaces returns an immutable view sharing this engine's assembled
|
||||
// collaborators and configuration snapshot.
|
||||
func (e *Engine) WithNamespaces(prompt, profile, backend string) *Engine {
|
||||
view := *e
|
||||
view.namespaces = resourceNamespaces{prompt: prompt, profile: profile, backend: backend}
|
||||
return &view
|
||||
}
|
||||
|
||||
// InspectConfiguration returns read-only operations over the captured result.
|
||||
func (e *Engine) InspectConfiguration() configuration.Inspection {
|
||||
if e == nil {
|
||||
@@ -203,14 +218,43 @@ func (e *Engine) ListPrompts(ctx context.Context) ([]domain.PromptIdentity, erro
|
||||
return e.listing.ListPrompts(ctx)
|
||||
}
|
||||
func (e *Engine) Prepare(ctx context.Context, request domain.RunRequest) (*domain.PreparedRun, error) {
|
||||
request, err := e.qualifyRunRequest(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.runner.Prepare(ctx, request)
|
||||
}
|
||||
func (e *Engine) PrepareExecution(ctx context.Context, request domain.RunRequest) (*usecase.PreparedExecution, error) {
|
||||
request, err := e.qualifyRunRequest(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.runner.PrepareExecution(ctx, request)
|
||||
}
|
||||
func (e *Engine) Run(ctx context.Context, request domain.RunRequest) (*domain.RunResult, error) {
|
||||
request, err := e.qualifyRunRequest(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.runner.Run(ctx, request)
|
||||
}
|
||||
|
||||
func (e *Engine) qualifyRunRequest(request domain.RunRequest) (domain.RunRequest, error) {
|
||||
var ok bool
|
||||
if request.PromptID != "" {
|
||||
request.PromptID, ok = domain.QualifyResourceID(request.PromptID, e.namespaces.prompt)
|
||||
if !ok {
|
||||
return domain.RunRequest{}, fmt.Errorf("%w: invalid prompt ID", usecase.ErrInvalidRequest)
|
||||
}
|
||||
}
|
||||
if request.ProfileID != "" {
|
||||
request.ProfileID, ok = domain.QualifyResourceID(request.ProfileID, e.namespaces.profile)
|
||||
if !ok {
|
||||
return domain.RunRequest{}, fmt.Errorf("%w: invalid profile ID", usecase.ErrInvalidRequest)
|
||||
}
|
||||
}
|
||||
return request, nil
|
||||
}
|
||||
func (e *Engine) RunPrepared(ctx context.Context, prepared *usecase.PreparedExecution) (*domain.RunResult, error) {
|
||||
return e.runner.RunPrepared(ctx, prepared)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user