Define typed producer assessment and native execution dependencies

This commit is contained in:
2026-11-21 23:12:01 +00:00
parent b899ee32a6
commit 797320b4da
23 changed files with 657 additions and 707 deletions

View File

@@ -11,9 +11,10 @@ import (
)
type ValidatorSpec struct {
Key string `json:"key"`
ExecutionClass contracts.ExecutionClass `json:"execution_class"`
CorrectionProtocol contracts.CorrectionProtocol `json:"correction_protocol,omitempty"`
Key string `json:"key"`
ExecutionClass contracts.ExecutionClass `json:"execution_class"`
// Prompts identifies assessment requests, not a producer correction loop.
Prompts []string `json:"prompts,omitempty"`
}
type SerializedValidatorSpec struct {
@@ -116,7 +117,7 @@ func RegisterTypedValidatorBuilder[T any](registry *ValidatorRegistry, kind cont
if err != nil {
return contracts.ValidationResult{}, err
}
return validator.Validate(ctx, contracts.TypedValidationRequest[T]{Stage: string(target.stage), LaneID: target.laneID, ModuleKey: target.moduleKey, Source: target.source, SourceID: target.sourceID, SourceInput: target.sourceInput, SessionID: target.sessionID, References: target.references, LLMProfile: target.llmProfile, StructuredOutputRepairAttempts: target.structuredOutputRepairAttempts, Metadata: target.metadata, Chunk: target.chunk, Chunks: target.chunks, Ref: target.ref, Value: value})
return validator.Validate(ctx, contracts.TypedValidationRequest[T]{Stage: string(target.stage), LaneID: target.laneID, ModuleKey: target.moduleKey, Source: target.source, SourceID: target.sourceID, SourceInput: target.sourceInput, SessionID: target.sessionID, References: target.references, LLMProfile: target.llmProfile, Execution: target.execution, Metadata: target.metadata, Chunk: target.chunk, Chunks: target.chunks, Ref: target.ref, Value: value})
},
}
return nil
@@ -239,14 +240,14 @@ func (r *ValidatorRegistry) Spec(key string) (ValidatorSpec, bool) {
}
normalized := strings.TrimSpace(key)
if entry, found := r.chunkEntries[normalized]; found {
return entry.spec, true
return cloneValidatorSpec(entry.spec), true
}
if entry, found := r.serializedEntries[normalized]; found {
return entry.spec.ValidatorSpec, true
return cloneValidatorSpec(entry.spec.ValidatorSpec), true
}
if kinds := r.registeredTypedKinds(normalized); len(kinds) > 0 {
entry, found := r.typedEntry(normalized, kinds[0])
return entry.spec, found
return cloneValidatorSpec(entry.spec), found
}
return ValidatorSpec{}, false
}
@@ -323,9 +324,9 @@ func (r *ValidatorRegistry) RegisteredKeys() []string {
func normalizeValidatorSpec(spec ValidatorSpec) (ValidatorSpec, error) {
normalized := ValidatorSpec{
Key: strings.TrimSpace(spec.Key),
ExecutionClass: spec.ExecutionClass,
CorrectionProtocol: contracts.CorrectionProtocol(strings.TrimSpace(string(spec.CorrectionProtocol))),
Key: strings.TrimSpace(spec.Key),
ExecutionClass: spec.ExecutionClass,
Prompts: normalizeStringSet(spec.Prompts),
}
if normalized.Key == "" {
return ValidatorSpec{}, fmt.Errorf("validator key must not be empty")
@@ -335,12 +336,14 @@ func normalizeValidatorSpec(spec ValidatorSpec) (ValidatorSpec, error) {
default:
return ValidatorSpec{}, fmt.Errorf("validator %q execution class %q is not supported", normalized.Key, normalized.ExecutionClass)
}
if normalized.CorrectionProtocol != "" {
return ValidatorSpec{}, fmt.Errorf("validator %q correction protocol is not supported", normalized.Key)
}
return normalized, nil
}
func sortValidatorSpecs(specs []ValidatorSpec) {
sort.Slice(specs, func(i, j int) bool { return specs[i].Key < specs[j].Key })
}
func cloneValidatorSpec(spec ValidatorSpec) ValidatorSpec {
spec.Prompts = append([]string(nil), spec.Prompts...)
return spec
}