Implement NPC extraction follow-up fixes
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
npccodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/npcs"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/diagnostics"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/identity"
|
||||
)
|
||||
|
||||
@@ -56,14 +57,14 @@ func resolveNPCRegistry(references contracts.ReferenceSet) (npcRegistryPromptInp
|
||||
codec := npccodec.New()
|
||||
value, err := codec.Decode(item.Content)
|
||||
if err != nil {
|
||||
return npcRegistryPromptInput{}, fmt.Errorf("decode NPC registry: %w", err)
|
||||
return npcRegistryPromptInput{}, fmt.Errorf("decode NPC registry: invalid approved NPC JSON")
|
||||
}
|
||||
if issues := identity.ValidateList(value); len(issues) > 0 {
|
||||
return npcRegistryPromptInput{}, fmt.Errorf("validate NPC registry identity: %s", formatNPCIdentityIssues(issues))
|
||||
return npcRegistryPromptInput{}, fmt.Errorf("%s", formatNPCIdentityIssues(issues))
|
||||
}
|
||||
content, err := codec.Encode(value)
|
||||
if err != nil {
|
||||
return npcRegistryPromptInput{}, fmt.Errorf("encode canonical NPC registry: %w", err)
|
||||
return npcRegistryPromptInput{}, fmt.Errorf("encode canonical NPC registry: approved NPC value could not be encoded")
|
||||
}
|
||||
|
||||
digest := semanticNPCRegistryDigest(content)
|
||||
@@ -83,7 +84,11 @@ func semanticNPCRegistryDigest(content []byte) string {
|
||||
func formatNPCIdentityIssues(issues []identity.Issue) string {
|
||||
parts := make([]string, len(issues))
|
||||
for index, issue := range issues {
|
||||
parts[index] = fmt.Sprintf("%s at record %d", issue.Code, issue.RecordIndex)
|
||||
location := fmt.Sprintf("record %d", issue.RecordIndex)
|
||||
if issue.AliasIndex >= 0 {
|
||||
location += fmt.Sprintf(" alias %d", issue.AliasIndex)
|
||||
}
|
||||
parts[index] = fmt.Sprintf("%s at %s", issue.Code, location)
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
return diagnostics.Aggregate("validate NPC registry identity", parts)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user