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

@@ -65,6 +65,7 @@ var _ contracts.Extractor[dnd.SpellList] = (*Extractor)(nil)
type Options struct{}
type Extractor struct {
context shared.PreparedContext
catalogPromptInput []byte
npcResolver *npcregistry.Resolver
}
@@ -77,6 +78,10 @@ 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)
}
effectiveCatalog, err := spellcatalog.ResolveEffectiveCatalog(referenceSet)
if err != nil {
return nil, extractorErrorf("resolve effective spell catalog: %w", err)
@@ -89,7 +94,7 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
if err != nil {
return nil, extractorErrorf("prepare NPC registry prompt input: %w", err)
}
return &Extractor{catalogPromptInput: catalogPromptInput, npcResolver: npcResolver}, nil
return &Extractor{context: context, catalogPromptInput: catalogPromptInput, npcResolver: npcResolver}, nil
}
func (e *Extractor) Key() string {
@@ -115,7 +120,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
return nil, extractorErrorf("resolve NPC registry: %w", err)
}
materials := shared.PromptInputs(sourceInput, req.References)
materials := e.context.Inputs(sourceInput)
inputs := make(map[string]promptkit.ArtifactRef, len(materials)+2)
for name, material := range materials {
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))