Share prepared pipeline source validation

This commit is contained in:
2026-11-28 04:07:44 +00:00
parent 9e82b5f6b8
commit 8617f936a4
4 changed files with 78 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package pipeline
import (
"context"
"fmt"
"reflect"
"strings"
@@ -10,6 +11,30 @@ import (
"go.maximumdirect.net/promptkit"
)
// ParseSource parses and validates input using the prepared input adapter.
func (prepared *PreparedPipeline) ParseSource(ctx context.Context, request contracts.ParseRequest) (*source.SourceDocument, error) {
metadata, err := cloneMetadata(request.Metadata)
if err != nil {
return nil, fmt.Errorf("clone input adapter metadata: %w", err)
}
if err := ctx.Err(); err != nil {
return nil, err
}
request.Metadata = metadata
request.LLMProfile = prepared.resolved.Input.LLMProfile
doc, err := prepared.input.Parse(ctx, request)
if ctxErr := ctx.Err(); ctxErr != nil {
return nil, ctxErr
}
if err != nil {
return nil, fmt.Errorf("parse input with adapter %q: %w", prepared.input.Key(), err)
}
if err := source.ValidateDocument(doc); err != nil {
return nil, fmt.Errorf("validate source document: %w", err)
}
return doc, nil
}
// PreparedPipeline owns the constructed, run-local implementation set for one
// resolved pipeline. Its implementation values are private so execution cannot
// replace or reconfigure them after preparation.