2026-07-30 21:00:05 +00:00
|
|
|
package usecase
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
2026-11-02 14:38:00 +00:00
|
|
|
"go.maximumdirect.net/promptkit/internal/domain"
|
2026-07-30 21:00:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type resolvedPromptDefinition struct {
|
|
|
|
|
definition *domain.PromptDefinition
|
|
|
|
|
hash string
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 05:47:14 +00:00
|
|
|
func (r *Runner) resolvePromptDefinition(ctx context.Context, promptID string) (*resolvedPromptDefinition, error) {
|
2026-07-30 21:00:05 +00:00
|
|
|
if strings.TrimSpace(promptID) == "" {
|
|
|
|
|
return nil, fmt.Errorf("%w: prompt id is required", ErrInvalidRequest)
|
|
|
|
|
}
|
|
|
|
|
if r == nil || r.promptDefs == nil {
|
|
|
|
|
return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad)
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 19:55:10 +00:00
|
|
|
definition, hash, err := r.promptDefs.GetPromptSnapshot(ctx, promptID)
|
2026-07-30 21:00:05 +00:00
|
|
|
if err != nil {
|
2026-11-05 13:42:56 +00:00
|
|
|
return nil, promptLookupError(err)
|
2026-07-30 21:00:05 +00:00
|
|
|
}
|
|
|
|
|
if definition == nil {
|
|
|
|
|
return nil, fmt.Errorf("%w: prompt repository returned nil definition", ErrPromptLoad)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &resolvedPromptDefinition{definition: definition, hash: hash}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 05:47:14 +00:00
|
|
|
func (r *Runner) resolvePromptInspection(ctx context.Context, promptID string) (*domain.PromptInspection, error) {
|
2026-07-30 21:00:05 +00:00
|
|
|
if strings.TrimSpace(promptID) == "" {
|
|
|
|
|
return nil, fmt.Errorf("%w: prompt id is required", ErrInvalidRequest)
|
|
|
|
|
}
|
2026-10-09 00:45:25 +00:00
|
|
|
if r == nil || r.promptDefs == nil {
|
|
|
|
|
return nil, fmt.Errorf("%w: prompt repository is not configured", ErrPromptLoad)
|
|
|
|
|
}
|
2026-11-05 19:55:10 +00:00
|
|
|
inspection, err := r.promptDefs.GetPromptInspection(ctx, promptID)
|
2026-07-30 21:00:05 +00:00
|
|
|
if err != nil {
|
2026-11-05 19:55:10 +00:00
|
|
|
return nil, promptLookupError(err)
|
|
|
|
|
}
|
|
|
|
|
if inspection == nil {
|
|
|
|
|
return nil, fmt.Errorf("%w: prompt repository returned nil inspection", ErrPromptLoad)
|
2026-07-30 21:00:05 +00:00
|
|
|
}
|
2026-11-05 19:55:10 +00:00
|
|
|
return inspection, nil
|
2026-07-30 21:00:05 +00:00
|
|
|
}
|