Order spell and NPC extraction by document position

This commit is contained in:
2026-07-24 14:29:19 +00:00
parent 83fde83a58
commit 9bbf2535dd
8 changed files with 138 additions and 111 deletions

View File

@@ -17,7 +17,7 @@ const Key = "dnd/spells"
const ArtifactType = "dnd.spell_cast"
const SchemaVersion = "v1"
const mappingPolicy = "dnd.spells.extract_mapping.v1"
const mappingPolicy = "dnd.spells.extract_mapping.v2"
const (
NPCRegistryReferenceSlot = npcregistry.ReferenceSlot
@@ -185,6 +185,7 @@ func (e *Extractor) Extract(ctx context.Context, req contracts.TypedExtractionRe
if err != nil {
return contracts.TypedExtractionResult[dnd.SpellList]{}, extractorErrorf("%w", err)
}
order := shared.NewSourceRefOrder(req.Source)
npcRegistry, err := e.npcResolver.Resolve(req.References)
if err != nil {
return contracts.TypedExtractionResult[dnd.SpellList]{}, extractorErrorf("resolve NPC registry: %w", err)
@@ -204,7 +205,7 @@ func (e *Extractor) Extract(ctx context.Context, req contracts.TypedExtractionRe
}, &response); err != nil {
return contracts.TypedExtractionResult[dnd.SpellList]{}, extractorErrorf("complete structured output: %w", err)
}
canonicalizeResponse(&response)
canonicalizeResponse(&response, order, req.Source.ID)
return contracts.TypedExtractionResult[dnd.SpellList]{Value: canonicalSpellList(response, req.Source.ID)}, nil
}