Prepare structured D&D reference context

This commit is contained in:
2026-11-29 18:09:09 +00:00
parent f84e737b2a
commit e0554209f0
22 changed files with 465 additions and 65 deletions

View File

@@ -37,13 +37,21 @@ var _ contracts.Extractor[dnd.ItemRegistry] = (*Extractor)(nil)
type Options struct{}
type Extractor struct{}
type Extractor struct{ context shared.PreparedContext }
func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
if len(references) > 1 {
return nil, extractorErrorf("at most one reference set may be supplied")
}
return &Extractor{}, nil
var set contracts.ReferenceSet
if len(references) == 1 {
set = references[0]
}
context, err := shared.PrepareContext(set)
if err != nil {
return nil, extractorErrorf("prepare references: %w", err)
}
return &Extractor{context: context}, nil
}
func (e *Extractor) Key() string { return Key }
@@ -61,7 +69,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
order := shared.NewSourceRefOrderForSource(req.Source, req.SourceIndex)
sourceID := req.Source.ID
materials := shared.PromptInputs(sourceInput, req.References)
materials := e.context.Inputs(sourceInput)
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
for name, material := range materials {
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))