From 5ccc3711e69b8ec5139044f6f98fd20a3c0de405 Mon Sep 17 00:00:00 2001 From: poimen Date: Tue, 8 Sep 2026 17:05:17 -0700 Subject: [PATCH] refactor: extract synthesis types to pkg/types DRY fix: Shared types (SynthesisInput, ExtractedEntity, ExtractedFact, ContradictionResult, PersistInput) moved to pkg/types/synthesis.go. Both workflow and activity packages now import from pkg/types. Re-exported as type aliases for backward compatibility. Fixes: Duplicate type definitions between workflow and activity packages. --- pkg/types/synthesis.go | 59 ++++++++++++++++++++++++++++++++++++++++++ workflow/synthesis.go | 52 ++++++------------------------------- 2 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 pkg/types/synthesis.go diff --git a/pkg/types/synthesis.go b/pkg/types/synthesis.go new file mode 100644 index 0000000..53a481b --- /dev/null +++ b/pkg/types/synthesis.go @@ -0,0 +1,59 @@ +package types + +import "time" + +// SynthesisInput contains the input for the synthesis workflow. +type SynthesisInput struct { + Project string `json:"project"` + Source string `json:"source"` + Text string `json:"text"` + Kind string `json:"kind"` // L1, L2, reference + Tags []string `json:"tags,omitempty"` +} + +// SynthesisResult contains the output of the synthesis workflow. +type SynthesisResult struct { + ChunkID string `json:"chunk_id"` + EntitiesExtracted int `json:"entities_extracted"` + FactsExtracted int `json:"facts_extracted"` + Contradictions int `json:"contradictions"` + ReviewQueued int `json:"review_queued"` + Entities []ExtractedEntity `json:"entities"` + Facts []ExtractedFact `json:"facts"` + Duration time.Duration `json:"duration"` +} + +// ExtractedEntity represents an entity found during synthesis. +type ExtractedEntity struct { + Name string `json:"name"` + EntityType string `json:"entity_type"` + Confidence float64 `json:"confidence"` +} + +// ExtractedFact represents a fact extracted during synthesis. +type ExtractedFact struct { + Subject string `json:"subject"` + Predicate string `json:"predicate"` + Object string `json:"object"` + Confidence float64 `json:"confidence"` +} + +// ContradictionResult represents a contradiction detection result. +type ContradictionResult struct { + FactA ExtractedFact `json:"fact_a"` + FactB ExtractedFact `json:"fact_b"` + Severity string `json:"severity"` // low, medium, high + AutoResolved bool `json:"auto_resolved"` + QueuedReview bool `json:"queued_review"` +} + +// PersistInput groups all synthesis results for persistence. +type PersistInput struct { + ChunkID string `json:"chunk_id"` + Project string `json:"project"` + Source string `json:"source"` + Kind string `json:"kind"` + Entities []ExtractedEntity `json:"entities"` + Facts []ExtractedFact `json:"facts"` + Contradictions []ContradictionResult `json:"contradictions"` +} diff --git a/workflow/synthesis.go b/workflow/synthesis.go index ca0d1f9..dac9339 100644 --- a/workflow/synthesis.go +++ b/workflow/synthesis.go @@ -6,52 +6,16 @@ import ( "go.temporal.io/sdk/temporal" "go.temporal.io/sdk/workflow" + "github.com/rockliang/poimen/workflows/pkg/types" ) -// SynthesisInput contains the input for the synthesis workflow. -type SynthesisInput struct { - Project string `json:"project"` - Source string `json:"source"` - Text string `json:"text"` - Kind string `json:"kind"` // L1, L2, reference - Tags []string `json:"tags,omitempty"` -} - -// SynthesisResult contains the output of the synthesis workflow. -type SynthesisResult struct { - ChunkID string `json:"chunk_id"` - EntitiesExtracted int `json:"entities_extracted"` - FactsExtracted int `json:"facts_extracted"` - Contradictions int `json:"contradictions"` - ReviewQueued int `json:"review_queued"` - Entities []ExtractedEntity `json:"entities"` - Facts []ExtractedFact `json:"facts"` - Duration time.Duration `json:"duration"` -} - -// ExtractedEntity represents an entity found during synthesis. -type ExtractedEntity struct { - Name string `json:"name"` - EntityType string `json:"entity_type"` - Confidence float64 `json:"confidence"` -} - -// ExtractedFact represents a fact extracted during synthesis. -type ExtractedFact struct { - Subject string `json:"subject"` - Predicate string `json:"predicate"` - Object string `json:"object"` - Confidence float64 `json:"confidence"` -} - -// ContradictionResult represents a contradiction detection result. -type ContradictionResult struct { - FactA ExtractedFact `json:"fact_a"` - FactB ExtractedFact `json:"fact_b"` - Severity string `json:"severity"` // low, medium, high - AutoResolved bool `json:"auto_resolved"` - QueuedReview bool `json:"queued_review"` -} +// Re-export shared types from pkg/types for backward compatibility +type SynthesisInput = types.SynthesisInput +type SynthesisResult = types.SynthesisResult +type ExtractedEntity = types.ExtractedEntity +type ExtractedFact = types.ExtractedFact +type ContradictionResult = types.ContradictionResult +type PersistInput = types.PersistInput var synthesisActivityOptions = workflow.ActivityOptions{ StartToCloseTimeout: 60 * time.Second,