Discover selected pipeline model targets
This commit is contained in:
@@ -161,6 +161,8 @@ limit domain changes to checks needed by the accepted local-preparation contract
|
||||
|
||||
## Stage 3: Discover Selected Initial Targets Without Executing Work
|
||||
|
||||
**Status:** Complete.
|
||||
|
||||
**Goal:** Produce scoped, deduplicated profile/backend selections for preflight.
|
||||
|
||||
**Inspect:** `ModuleSpec`, `ValidatorSpec`, resolved pipeline/validator structures,
|
||||
|
||||
@@ -26,7 +26,9 @@ type ModuleSpec struct {
|
||||
ExecutionClass contracts.ExecutionClass
|
||||
// Prompts lists statically selected initial/correction IDs shared with the
|
||||
// module's request builders. Dynamic selections are checked at execution.
|
||||
Prompts []string
|
||||
Prompts []string
|
||||
// InitialPrompts identifies requests that independently select a target.
|
||||
InitialPrompts []string
|
||||
ArtifactKind contracts.ArtifactKind
|
||||
Provides []string
|
||||
Requires []string
|
||||
@@ -40,6 +42,7 @@ func normalizeModuleSpec(spec ModuleSpec) ModuleSpec {
|
||||
Stage: spec.Stage,
|
||||
ExecutionClass: executionClass,
|
||||
Prompts: normalizeStringSet(spec.Prompts),
|
||||
InitialPrompts: normalizeStringSet(spec.InitialPrompts),
|
||||
ArtifactKind: normalizeArtifactKind(spec.ArtifactKind),
|
||||
Provides: normalizeCapabilities(spec.Provides),
|
||||
Requires: normalizeCapabilities(spec.Requires),
|
||||
@@ -78,6 +81,7 @@ func cloneModuleSpec(spec ModuleSpec) ModuleSpec {
|
||||
Stage: spec.Stage,
|
||||
ExecutionClass: spec.ExecutionClass,
|
||||
Prompts: append([]string(nil), spec.Prompts...),
|
||||
InitialPrompts: append([]string(nil), spec.InitialPrompts...),
|
||||
ArtifactKind: spec.ArtifactKind,
|
||||
Provides: append([]string(nil), spec.Provides...),
|
||||
Requires: append([]string(nil), spec.Requires...),
|
||||
|
||||
@@ -105,7 +105,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageChunk,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ReferenceSlots: shared.ReferenceSlots(referenceSlotDescriptions),
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestNewModuleSpecAndRegister(t *testing.T) {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageChunk,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: []string{"source.transcript"},
|
||||
Provides: []string{"chunks"},
|
||||
ReferenceSlots: wantReferenceSlots(),
|
||||
|
||||
@@ -172,7 +172,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.CombatTurnListKind,
|
||||
|
||||
@@ -138,7 +138,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.EnemyEventListKind,
|
||||
|
||||
@@ -132,7 +132,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.ItemOccurrenceListKind,
|
||||
|
||||
@@ -86,7 +86,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
func ModuleSpec() pipeline.ModuleSpec {
|
||||
return pipeline.ModuleSpec{
|
||||
Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.ItemRegistryKind, ReferenceSlots: referenceSlots(),
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestModuleRegistrationAndNativeDependencies(t *testing.T) {
|
||||
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one") {
|
||||
t.Fatalf("New() error = %v, want reference-set rejection", err)
|
||||
}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.item_registry"}, ArtifactKind: dnd.ItemRegistryKind, ReferenceSlots: referenceSlots()}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.item_registry"}, ArtifactKind: dnd.ItemRegistryKind, ReferenceSlots: referenceSlots()}
|
||||
if got := ModuleSpec(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("ModuleSpec() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
func ModuleSpec() pipeline.ModuleSpec {
|
||||
return pipeline.ModuleSpec{
|
||||
Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.LocationOccurrenceListKind, ReferenceSlots: referenceSlots(),
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
func ModuleSpec() pipeline.ModuleSpec {
|
||||
return pipeline.ModuleSpec{
|
||||
Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.LocationRegistryKind, ReferenceSlots: referenceSlots(),
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestModuleRegistrationAndNativeDependencies(t *testing.T) {
|
||||
if _, err := New(Options{}, contracts.ReferenceSet{}, contracts.ReferenceSet{}); err == nil || !strings.Contains(err.Error(), "at most one") {
|
||||
t.Fatalf("New() error = %v, want reference-set rejection", err)
|
||||
}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.location_registry"}, ArtifactKind: dnd.LocationRegistryKind, ReferenceSlots: referenceSlots()}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.location_registry"}, ArtifactKind: dnd.LocationRegistryKind, ReferenceSlots: referenceSlots()}
|
||||
if got := ModuleSpec(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("ModuleSpec() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.NPCOccurrenceListKind,
|
||||
|
||||
@@ -94,7 +94,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.NPCRegistryKind,
|
||||
|
||||
@@ -25,10 +25,10 @@ func TestModuleSpecAndReferenceSlots(t *testing.T) {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Requires: []string{"chunks", "source.transcript"},
|
||||
Provides: []string{"dnd.npc_registry"},
|
||||
ArtifactKind: dnd.NPCRegistryKind,
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: []string{"chunks", "source.transcript"},
|
||||
Provides: []string{"dnd.npc_registry"},
|
||||
ArtifactKind: dnd.NPCRegistryKind,
|
||||
ReferenceSlots: []contracts.ReferenceSlot{
|
||||
{Name: "glossary", Description: "Optional campaign glossary reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "party", Description: "Optional party roster reference material used only for NPC disambiguation.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
|
||||
@@ -126,7 +126,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.SceneDescriptionListKind,
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestNewRejectsAmbiguousReferences(t *testing.T) {
|
||||
|
||||
func TestModuleSpecAndReferenceSlots(t *testing.T) {
|
||||
want := pipeline.ModuleSpec{
|
||||
Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.scene_descriptions"}, ArtifactKind: dnd.SceneDescriptionListKind,
|
||||
Key: Key, Stage: pipeline.StageExtract, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"chunks", "source.transcript"}, Provides: []string{"dnd.scene_descriptions"}, ArtifactKind: dnd.SceneDescriptionListKind,
|
||||
ReferenceSlots: []contracts.ReferenceSlot{
|
||||
{Name: "glossary", Description: "Optional campaign glossary reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
{Name: "party", Description: "Optional party roster reference material used only to disambiguate scene descriptions.", AcceptedMediaTypes: []string{"application/json", "application/x-yaml", "application/yaml", "text/markdown", "text/plain"}},
|
||||
|
||||
@@ -147,7 +147,7 @@ func ModuleSpec() pipeline.ModuleSpec {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: append([]string(nil), requiredCapabilities...),
|
||||
Provides: append([]string(nil), providedCapabilities...),
|
||||
ArtifactKind: dnd.SpellListKind,
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestModuleSpec(t *testing.T) {
|
||||
Key: Key,
|
||||
Stage: pipeline.StageExtract,
|
||||
ExecutionClass: contracts.ExecutionClassLLMBacked,
|
||||
Prompts: []string{PromptID, CorrectionPromptID},
|
||||
Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID},
|
||||
Requires: []string{
|
||||
"chunks",
|
||||
"source.transcript",
|
||||
|
||||
@@ -312,7 +312,7 @@ func duplicateFinding(retainedIndex int, removed []int) diagnostics.Finding {
|
||||
func itemScope(index int) string { return fmt.Sprintf("items[%d]", index) }
|
||||
|
||||
func ModuleSpec() pipeline.ModuleSpec {
|
||||
return pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...), ArtifactKind: dnd.ItemRegistryKind}
|
||||
return pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...), ArtifactKind: dnd.ItemRegistryKind}
|
||||
}
|
||||
func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
return pipeline.RegisterNormalizerBuilder(registry, ModuleSpec(), validateOptions, func(request pipeline.BuildRequest) (contracts.Normalizer[dnd.ItemRegistry], error) {
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func TestModuleContractAndNativeDependencies(t *testing.T) {
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: []string{"merged"}, Provides: []string{"normalized"}, ArtifactKind: dnd.ItemRegistryKind}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"merged"}, Provides: []string{"normalized"}, ArtifactKind: dnd.ItemRegistryKind}
|
||||
if got := ModuleSpec(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("ModuleSpec() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ func duplicateFinding(retainedIndex int, removed []int) diagnostics.Finding {
|
||||
func locationScope(index int) string { return fmt.Sprintf("locations[%d]", index) }
|
||||
|
||||
func ModuleSpec() pipeline.ModuleSpec {
|
||||
return pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...), ArtifactKind: dnd.LocationRegistryKind}
|
||||
return pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...), ArtifactKind: dnd.LocationRegistryKind}
|
||||
}
|
||||
func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
return pipeline.RegisterNormalizerBuilder(registry, ModuleSpec(), validateOptions, func(request pipeline.BuildRequest) (contracts.Normalizer[dnd.LocationRegistry], error) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func TestModuleContractAndNativeDependencies(t *testing.T) {
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: []string{"merged"}, Provides: []string{"normalized"}, ArtifactKind: dnd.LocationRegistryKind}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"merged"}, Provides: []string{"normalized"}, ArtifactKind: dnd.LocationRegistryKind}
|
||||
if got := ModuleSpec(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("ModuleSpec() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ func duplicateFinding(retainedIndex int, removed []int) diagnostics.Finding {
|
||||
func npcScope(index int) string { return fmt.Sprintf("npcs[%d]", index) }
|
||||
|
||||
func ModuleSpec() pipeline.ModuleSpec {
|
||||
return pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...), ArtifactKind: dnd.NPCRegistryKind}
|
||||
return pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: append([]string(nil), requiredCapabilities...), Provides: append([]string(nil), providedCapabilities...), ArtifactKind: dnd.NPCRegistryKind}
|
||||
}
|
||||
|
||||
func Register(registry *pipeline.NormalizerRegistry) error {
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestModuleContractAndIdentity(t *testing.T) {
|
||||
if _, err := DecodeOptions(map[string]any{"unexpected": true}); err == nil {
|
||||
t.Fatal("DecodeOptions() accepted unknown option")
|
||||
}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, Requires: []string{"merged"}, Provides: []string{"normalized"}, ArtifactKind: dnd.NPCRegistryKind}
|
||||
want := pipeline.ModuleSpec{Key: Key, Stage: pipeline.StageNormalize, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{PromptID, CorrectionPromptID}, InitialPrompts: []string{PromptID}, Requires: []string{"merged"}, Provides: []string{"normalized"}, ArtifactKind: dnd.NPCRegistryKind}
|
||||
if got := ModuleSpec(); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("ModuleSpec() = %#v, want %#v", got, want)
|
||||
}
|
||||
|
||||
156
internal/preflight/targets.go
Normal file
156
internal/preflight/targets.go
Normal file
@@ -0,0 +1,156 @@
|
||||
package preflight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// BindingScope identifies selected work associated with a native target.
|
||||
type BindingScope struct {
|
||||
Step string `json:"step,omitempty" yaml:"step,omitempty"`
|
||||
Lane string `json:"lane,omitempty" yaml:"lane,omitempty"`
|
||||
Role pipeline.ModuleStage `json:"role" yaml:"role"`
|
||||
Module string `json:"module" yaml:"module"`
|
||||
Validator string `json:"validator,omitempty" yaml:"validator,omitempty"`
|
||||
}
|
||||
|
||||
type ProfileTarget struct {
|
||||
ID string
|
||||
Bindings []BindingScope
|
||||
}
|
||||
|
||||
type AccessTarget struct {
|
||||
BackendID string
|
||||
ProfileID string
|
||||
Bindings []BindingScope
|
||||
}
|
||||
|
||||
type Targets struct {
|
||||
Profiles []ProfileTarget
|
||||
Access []AccessTarget
|
||||
}
|
||||
|
||||
// DiscoverTargets identifies initial request targets without invoking providers.
|
||||
func DiscoverTargets(ctx context.Context, resolved pipeline.ResolvedPipeline, catalog pipeline.ModuleCatalog, engine *promptkit.Engine) (Targets, error) {
|
||||
var targets Targets
|
||||
if ctx == nil {
|
||||
return targets, errors.New("preflight context must not be nil")
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return targets, err
|
||||
}
|
||||
profiles := make(map[string]int)
|
||||
access := make(map[string]int)
|
||||
add := func(scope BindingScope, class contracts.ExecutionClass, profile string, prompts []string) error {
|
||||
if class != contracts.ExecutionClassLLMBacked {
|
||||
return nil
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if engine == nil {
|
||||
return fmt.Errorf("%v: %w: native engine is required", scope, promptkit.ErrInvalidConfig)
|
||||
}
|
||||
ids := prompts
|
||||
if len(ids) == 0 {
|
||||
ids = []string{""}
|
||||
}
|
||||
for _, promptID := range ids {
|
||||
selected := profile
|
||||
if selected == "" && promptID != "" {
|
||||
prompt, err := engine.InspectPrompt(ctx, promptID)
|
||||
if err != nil {
|
||||
return resourceFinding(fmt.Errorf("%v prompt %q: %w", scope, promptID, err))
|
||||
}
|
||||
if prompt.DefaultProfileID != nil {
|
||||
selected = *prompt.DefaultProfileID
|
||||
}
|
||||
}
|
||||
if selected == "" {
|
||||
return fmt.Errorf("%v: no statically selected profile for initial prompt %q", scope, promptID)
|
||||
}
|
||||
p, err := engine.InspectProfile(ctx, selected)
|
||||
if err != nil {
|
||||
return resourceFinding(fmt.Errorf("%v profile %q: %w", scope, selected, err))
|
||||
}
|
||||
pi, ok := profiles[selected]
|
||||
if !ok {
|
||||
pi = len(targets.Profiles)
|
||||
profiles[selected] = pi
|
||||
targets.Profiles = append(targets.Profiles, ProfileTarget{ID: selected})
|
||||
}
|
||||
targets.Profiles[pi].Bindings = appendScope(targets.Profiles[pi].Bindings, scope)
|
||||
key := "profile:" + selected
|
||||
backend := ""
|
||||
if p.Backend != nil && *p.Backend != "" {
|
||||
backend = *p.Backend
|
||||
key = "backend:" + backend
|
||||
}
|
||||
ai, ok := access[key]
|
||||
if !ok {
|
||||
ai = len(targets.Access)
|
||||
access[key] = ai
|
||||
targets.Access = append(targets.Access, AccessTarget{BackendID: backend, ProfileID: selected})
|
||||
}
|
||||
targets.Access[ai].Bindings = appendScope(targets.Access[ai].Bindings, scope)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
input, _ := catalog.Inputs.Spec(resolved.Input.Module)
|
||||
if err := add(BindingScope{Role: pipeline.StageInput, Module: resolved.Input.Module}, resolved.InputExecutionClass, resolved.Input.LLMProfile, input.InitialPrompts); err != nil {
|
||||
return targets, err
|
||||
}
|
||||
chunk, _ := catalog.Chunkers.Spec(resolved.Chunk.Module)
|
||||
if err := add(BindingScope{Role: pipeline.StageChunk, Module: resolved.Chunk.Module}, resolved.ChunkExecutionClass, resolved.Chunk.LLMProfile, chunk.InitialPrompts); err != nil {
|
||||
return targets, err
|
||||
}
|
||||
steps := make(map[string]string)
|
||||
for _, step := range resolved.Steps {
|
||||
for _, lane := range step.ArtifactLanes {
|
||||
steps[lane.ID] = step.ID
|
||||
extract, _ := catalog.Extractors.Spec(lane.Extract.Module)
|
||||
merge, _ := catalog.Mergers.Spec(lane.Merge.Module)
|
||||
normalize, _ := catalog.Normalizers.Spec(lane.Normalize.Module)
|
||||
for _, item := range []struct {
|
||||
role pipeline.ModuleStage
|
||||
binding pipeline.ModuleBinding
|
||||
class contracts.ExecutionClass
|
||||
prompts []string
|
||||
}{
|
||||
{pipeline.StageExtract, lane.Extract, lane.ExtractExecutionClass, extract.InitialPrompts},
|
||||
{pipeline.StageMerge, lane.Merge, lane.MergeExecutionClass, merge.InitialPrompts},
|
||||
{pipeline.StageNormalize, lane.Normalize, lane.NormalizeExecutionClass, normalize.InitialPrompts},
|
||||
} {
|
||||
if err := add(BindingScope{Step: step.ID, Lane: lane.ID, Role: item.role, Module: item.binding.Module}, item.class, item.binding.LLMProfile, item.prompts); err != nil {
|
||||
return targets, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, chain := range resolved.ValidatorChains {
|
||||
for _, validator := range chain.Validators {
|
||||
if err := add(BindingScope{Step: steps[chain.LaneID], Lane: chain.LaneID, Role: chain.Stage, Module: chain.ModuleKey, Validator: validator.Binding.Module}, validator.ExecutionClass, validator.Binding.LLMProfile, validator.Prompts); err != nil {
|
||||
return targets, err
|
||||
}
|
||||
}
|
||||
}
|
||||
output, _ := catalog.Outputs.Spec(resolved.Output.Module)
|
||||
if err := add(BindingScope{Role: pipeline.StageOutput, Module: resolved.Output.Module}, resolved.OutputExecutionClass, resolved.Output.LLMProfile, output.InitialPrompts); err != nil {
|
||||
return targets, err
|
||||
}
|
||||
return targets, nil
|
||||
}
|
||||
|
||||
func appendScope(scopes []BindingScope, scope BindingScope) []BindingScope {
|
||||
for _, existing := range scopes {
|
||||
if existing == scope {
|
||||
return scopes
|
||||
}
|
||||
}
|
||||
return append(scopes, scope)
|
||||
}
|
||||
78
internal/preflight/targets_test.go
Normal file
78
internal/preflight/targets_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package preflight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestDiscoverTargetsUsesInitialPromptAndDeduplicates(t *testing.T) {
|
||||
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Underlays: []configkit.Underlay{{Inputs: []configkit.Input{promptkit.SettingsInput(configkit.Bytes("targets", []byte(`backends:
|
||||
- id: shared
|
||||
endpoint: https://example.invalid
|
||||
profiles:
|
||||
- id: primary
|
||||
backend: shared
|
||||
- id: secondary
|
||||
backend: shared
|
||||
- id: endpoint-only
|
||||
endpoint: https://example.invalid
|
||||
- id: unused
|
||||
backend: shared
|
||||
prompts:
|
||||
- id: initial
|
||||
default_profile: primary
|
||||
messages: [{role: user, content: 'Initial'}]
|
||||
output: {format: text, validation_mode: none}
|
||||
- id: correction
|
||||
default_profile: unused
|
||||
messages: [{role: user, content: 'Correct'}]
|
||||
output: {format: text, validation_mode: none}
|
||||
- id: validator
|
||||
default_profile: secondary
|
||||
messages: [{role: user, content: 'Assess'}]
|
||||
output: {format: text, validation_mode: none}
|
||||
`)))}}}}}, promptkit.WithBundledOpenRouter(false), promptkit.WithLLMClient(noGeneration{t}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chunkers := pipeline.NewChunkerRegistry()
|
||||
err = chunkers.RegisterWithSpec(pipeline.ModuleSpec{Key: "chunk", Stage: pipeline.StageChunk, ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{"initial", "correction"}, InitialPrompts: []string{"initial"}}, func() (contracts.Chunker, error) { t.Fatal("constructed chunker"); return nil, nil })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog := pipeline.ModuleCatalog{Chunkers: chunkers}
|
||||
resolved := pipeline.ResolvedPipeline{Chunk: pipeline.Binding("chunk"), ChunkExecutionClass: contracts.ExecutionClassLLMBacked, ValidatorChains: []pipeline.ResolvedValidatorChain{{Stage: pipeline.StageChunk, ModuleKey: "chunk", Validators: []pipeline.ResolvedValidator{{Binding: pipeline.Binding("validator"), ExecutionClass: contracts.ExecutionClassLLMBacked, Prompts: []string{"validator"}}}}}}
|
||||
targets, err := DiscoverTargets(context.Background(), resolved, catalog, engine)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(targets.Profiles) != 2 || targets.Profiles[0].ID != "primary" || targets.Profiles[1].ID != "secondary" || len(targets.Access) != 1 || targets.Access[0].BackendID != "shared" || len(targets.Access[0].Bindings) != 2 {
|
||||
t.Fatalf("targets = %+v", targets)
|
||||
}
|
||||
resolved.ValidatorChains[0].Validators[0].Binding.LLMProfile = "primary"
|
||||
targets, err = DiscoverTargets(context.Background(), resolved, catalog, engine)
|
||||
if err != nil || len(targets.Profiles) != 1 || len(targets.Profiles[0].Bindings) != 2 {
|
||||
t.Fatalf("shared profile = %+v, %v", targets, err)
|
||||
}
|
||||
resolved.ValidatorChains[0].Validators[0].Binding.LLMProfile = ""
|
||||
resolved.Chunk.LLMProfile = "endpoint-only"
|
||||
targets, err = DiscoverTargets(context.Background(), resolved, catalog, engine)
|
||||
if err != nil || len(targets.Access) != 2 || targets.Access[0].BackendID != "" || targets.Access[0].ProfileID != "endpoint-only" {
|
||||
t.Fatalf("endpoint target = %+v, %v", targets, err)
|
||||
}
|
||||
resolved.Chunk.LLMProfile = "missing"
|
||||
if _, err := DiscoverTargets(context.Background(), resolved, catalog, engine); !errors.Is(err, promptkit.ErrProfileNotFound) {
|
||||
t.Fatalf("missing profile cause = %v", err)
|
||||
}
|
||||
resolved.Chunk.LLMProfile = ""
|
||||
resolved.Chunk.Module = "dynamic"
|
||||
if _, err := DiscoverTargets(context.Background(), resolved, catalog, engine); err == nil {
|
||||
t.Fatal("unresolved target was silently omitted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user