Prepare shared context for all D&D extractors

This commit is contained in:
2026-11-29 18:13:45 +00:00
parent e0554209f0
commit 03e4c0d64d
22 changed files with 189 additions and 176 deletions

View File

@@ -0,0 +1,16 @@
package locationoccurrences
import (
"testing"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)
func TestConstructionRejectsInvalidSharedReference(t *testing.T) {
refs := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
"glossary": {Items: []contracts.ReferenceItem{{MediaType: "application/json", Content: []byte("{}")}}},
}}
if _, err := New(Options{}, refs); err == nil {
t.Fatal("invalid glossary accepted during construction")
}
}

View File

@@ -56,6 +56,7 @@ var _ contracts.Extractor[dnd.LocationOccurrenceList] = (*Extractor)(nil)
type Options struct{}
type Extractor struct {
context shared.PreparedContext
locationResolver *locationregistry.Resolver
}
@@ -67,11 +68,15 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
if len(references) == 1 {
referenceSet = references[0]
}
context, err := shared.PrepareContext(referenceSet)
if err != nil {
return nil, extractorErrorf("prepare references: %w", err)
}
locationResolver, err := locationregistry.NewResolver(referenceSet)
if err != nil {
return nil, extractorErrorf("prepare location registry prompt input: %w", err)
}
return &Extractor{locationResolver: locationResolver}, nil
return &Extractor{context: context, locationResolver: locationResolver}, nil
}
func (e *Extractor) Key() string { return Key }
@@ -106,7 +111,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
order := shared.NewSourceRefOrderForSource(req.Source, index)
sourceID := req.Source.ID
materials := shared.PromptInputs(sourceInput, req.References)
materials := e.context.Inputs(sourceInput)
materials[LocationRegistryReferenceSlot] = grounding.PromptInput()
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
for name, material := range materials {