Add type-safe artifact lane resolution
This commit is contained in:
@@ -13,10 +13,10 @@ import (
|
||||
|
||||
var _ contracts.InputAdapter = compositionAdapter{}
|
||||
var _ contracts.Chunker = compositionChunker{}
|
||||
var _ contracts.Extractor = compositionExtractor{}
|
||||
var _ contracts.Merger = compositionMerger{}
|
||||
var _ contracts.Normalizer = compositionNormalizer{}
|
||||
var _ contracts.Validator = compositionValidator{}
|
||||
var _ contracts.LegacyRawExtractor = compositionExtractor{}
|
||||
var _ contracts.LegacyRawMerger = compositionMerger{}
|
||||
var _ contracts.LegacyRawNormalizer = compositionNormalizer{}
|
||||
var _ contracts.LegacyRawValidator = compositionValidator{}
|
||||
var _ contracts.StructuredLLMClient = compositionLLMClient{}
|
||||
var _ contracts.OutputEncoder = compositionOutputEncoder{}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ type ExtractionResult struct {
|
||||
Warnings []Warning `json:"warnings,omitempty"`
|
||||
}
|
||||
|
||||
type Extractor interface {
|
||||
type LegacyRawExtractor interface {
|
||||
Key() string
|
||||
ReferenceSlots() []ReferenceSlot
|
||||
Extract(ctx context.Context, req ExtractionRequest) (ExtractionResult, error)
|
||||
@@ -279,7 +279,7 @@ type ValidationResult struct {
|
||||
Warnings []Warning `json:"warnings,omitempty"`
|
||||
}
|
||||
|
||||
type Validator interface {
|
||||
type LegacyRawValidator interface {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
Validate(ctx context.Context, req ValidationRequest) (ValidationResult, error)
|
||||
@@ -328,7 +328,7 @@ type MergeOutput struct {
|
||||
Payload RawPayload `json:"payload"`
|
||||
}
|
||||
|
||||
type Merger interface {
|
||||
type LegacyRawMerger interface {
|
||||
Key() string
|
||||
Merge(ctx context.Context, req MergeRequest) (MergeResult, error)
|
||||
}
|
||||
@@ -359,7 +359,7 @@ type NormalizeOutput struct {
|
||||
Payload RawPayload `json:"payload"`
|
||||
}
|
||||
|
||||
type Normalizer interface {
|
||||
type LegacyRawNormalizer interface {
|
||||
Key() string
|
||||
ReferenceSlots() []ReferenceSlot
|
||||
Normalize(ctx context.Context, req NormalizeRequest) (NormalizeResult, error)
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
|
||||
var _ InputAdapter = fakeAdapter{}
|
||||
var _ Chunker = fakeChunker{}
|
||||
var _ Extractor = fakeExtractor{}
|
||||
var _ Merger = fakeMerger{}
|
||||
var _ Normalizer = fakeNormalizer{}
|
||||
var _ Validator = fakeValidator{}
|
||||
var _ LegacyRawExtractor = fakeExtractor{}
|
||||
var _ LegacyRawMerger = fakeMerger{}
|
||||
var _ LegacyRawNormalizer = fakeNormalizer{}
|
||||
var _ LegacyRawValidator = fakeValidator{}
|
||||
var _ StructuredLLMClient = fakeLLMClient{}
|
||||
var _ OutputEncoder = fakeOutputEncoder{}
|
||||
|
||||
|
||||
164
internal/framework/contracts/typed_pipeline.go
Normal file
164
internal/framework/contracts/typed_pipeline.go
Normal file
@@ -0,0 +1,164 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
)
|
||||
|
||||
// ExtractArtifact carries a typed per-chunk value with framework provenance.
|
||||
type ExtractArtifact[T any] struct {
|
||||
LaneID string
|
||||
ExtractorKey string
|
||||
SourceID string
|
||||
ChunkID string
|
||||
ChunkIndex int
|
||||
ChunkRef source.SourceRef
|
||||
Value T
|
||||
}
|
||||
|
||||
// MergeArtifact carries a typed merged value with framework provenance.
|
||||
type MergeArtifact[T any] struct {
|
||||
LaneID string
|
||||
MergerKey string
|
||||
SourceID string
|
||||
Value T
|
||||
}
|
||||
|
||||
// NormalizeArtifact carries a typed normalized value with framework provenance.
|
||||
type NormalizeArtifact[T any] struct {
|
||||
LaneID string
|
||||
NormalizerKey string
|
||||
SourceID string
|
||||
Value T
|
||||
}
|
||||
|
||||
type TypedExtractionRequest struct {
|
||||
Source *source.SourceDocument
|
||||
Chunk *source.Chunk
|
||||
AmbientContext map[string]any
|
||||
SourceInput LLMInputMaterial
|
||||
SessionID string
|
||||
References ReferenceSet
|
||||
LLMProfile string
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type TypedExtractionResult[T any] struct {
|
||||
Value T
|
||||
Warnings []Warning
|
||||
}
|
||||
|
||||
type Extractor[T any] interface {
|
||||
Key() string
|
||||
ReferenceSlots() []ReferenceSlot
|
||||
Extract(context.Context, TypedExtractionRequest) (TypedExtractionResult[T], error)
|
||||
}
|
||||
|
||||
type TypedMergeRequest[T any] struct {
|
||||
Source *source.SourceDocument
|
||||
LaneID string
|
||||
ExtractOutputs []ExtractArtifact[T]
|
||||
SourceInput LLMInputMaterial
|
||||
SessionID string
|
||||
References ReferenceSet
|
||||
LLMProfile string
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type TypedMergeResult[T any] struct {
|
||||
Value T
|
||||
Warnings []Warning
|
||||
}
|
||||
|
||||
type Merger[T any] interface {
|
||||
Key() string
|
||||
Merge(context.Context, TypedMergeRequest[T]) (TypedMergeResult[T], error)
|
||||
}
|
||||
|
||||
type TypedNormalizeRequest[T any] struct {
|
||||
Source *source.SourceDocument
|
||||
LaneID string
|
||||
MergeOutput MergeArtifact[T]
|
||||
SourceInput LLMInputMaterial
|
||||
SessionID string
|
||||
References ReferenceSet
|
||||
LLMProfile string
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
type TypedNormalizeResult[T any] struct {
|
||||
Value T
|
||||
Warnings []Warning
|
||||
}
|
||||
|
||||
type Normalizer[T any] interface {
|
||||
Key() string
|
||||
ReferenceSlots() []ReferenceSlot
|
||||
Normalize(context.Context, TypedNormalizeRequest[T]) (TypedNormalizeResult[T], error)
|
||||
}
|
||||
|
||||
type TypedValidationRequest[T any] struct {
|
||||
Stage string
|
||||
LaneID string
|
||||
ModuleKey string
|
||||
Source *source.SourceDocument
|
||||
SourceID string
|
||||
SourceInput LLMInputMaterial
|
||||
SessionID string
|
||||
References ReferenceSet
|
||||
LLMProfile string
|
||||
Metadata map[string]any
|
||||
Chunk *source.Chunk
|
||||
Chunks []source.Chunk
|
||||
Ref source.SourceRef
|
||||
Value T
|
||||
}
|
||||
|
||||
type TypedValidator[T any] interface {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
Validate(context.Context, TypedValidationRequest[T]) (ValidationResult, error)
|
||||
}
|
||||
|
||||
type ChunkValidationRequest struct {
|
||||
ModuleKey string
|
||||
Source *source.SourceDocument
|
||||
SourceID string
|
||||
SourceInput LLMInputMaterial
|
||||
SessionID string
|
||||
References ReferenceSet
|
||||
LLMProfile string
|
||||
Metadata map[string]any
|
||||
Chunks []source.Chunk
|
||||
}
|
||||
|
||||
type ChunkValidator interface {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
Validate(context.Context, ChunkValidationRequest) (ValidationResult, error)
|
||||
}
|
||||
|
||||
type SerializedValidationRequest struct {
|
||||
Stage string
|
||||
LaneID string
|
||||
ModuleKey string
|
||||
Source *source.SourceDocument
|
||||
SourceID string
|
||||
SourceInput LLMInputMaterial
|
||||
SessionID string
|
||||
References ReferenceSet
|
||||
LLMProfile string
|
||||
Metadata map[string]any
|
||||
Chunk *source.Chunk
|
||||
Chunks []source.Chunk
|
||||
Schema ArtifactSchema
|
||||
MediaType string
|
||||
Content []byte
|
||||
}
|
||||
|
||||
type SerializedValidator interface {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
Validate(context.Context, SerializedValidationRequest) (ValidationResult, error)
|
||||
}
|
||||
Reference in New Issue
Block a user