Migrate NPC registry durable contract
This commit is contained in:
@@ -27,7 +27,7 @@ const (
|
||||
// grounding. All accessors return defensive copies.
|
||||
type Registry struct {
|
||||
bound bool
|
||||
list dnd.NPCList
|
||||
list dnd.NPCRegistry
|
||||
canonical []byte
|
||||
digest string
|
||||
projectionDigest string
|
||||
@@ -105,7 +105,7 @@ func emptyRegistry() *Registry {
|
||||
content := []byte(emptyPrompt)
|
||||
projectionDigest := semanticDigest(content)
|
||||
return &Registry{
|
||||
list: dnd.NPCList{NPCs: []dnd.NPC{}},
|
||||
list: dnd.NPCRegistry{NPCs: []dnd.NPC{}},
|
||||
canonical: append([]byte(nil), content...),
|
||||
projectionDigest: projectionDigest,
|
||||
promptInput: contracts.NewLLMInputMaterial(ReferenceSlot, npccodec.MediaType, content, projectionDigest, ""),
|
||||
@@ -127,7 +127,7 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
|
||||
return nil, fmt.Errorf("encode canonical NPC registry: approved NPC value could not be encoded")
|
||||
}
|
||||
|
||||
list := cloneNPCList(value)
|
||||
list := cloneNPCRegistry(value)
|
||||
lookupByKey := make(map[string]int, len(list.NPCs))
|
||||
for index, npc := range list.NPCs {
|
||||
lookupByKey[identity.ComparisonKey(npc.Name)] = index
|
||||
@@ -161,11 +161,11 @@ func (r *Registry) NPCs() []dnd.NPC {
|
||||
}
|
||||
|
||||
// List returns a defensive copy of the validated NPC list.
|
||||
func (r *Registry) List() dnd.NPCList {
|
||||
func (r *Registry) List() dnd.NPCRegistry {
|
||||
if r == nil {
|
||||
return dnd.NPCList{}
|
||||
return dnd.NPCRegistry{}
|
||||
}
|
||||
return cloneNPCList(r.list)
|
||||
return cloneNPCRegistry(r.list)
|
||||
}
|
||||
|
||||
// CanonicalBytes returns a defensive copy of the canonical durable JSON.
|
||||
@@ -233,12 +233,12 @@ type projectedNPC struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type projectedNPCList struct {
|
||||
type projectedNPCRegistry struct {
|
||||
NPCs []projectedNPC `json:"npcs"`
|
||||
}
|
||||
|
||||
func nameProjection(list dnd.NPCList) ([]byte, error) {
|
||||
projection := projectedNPCList{NPCs: make([]projectedNPC, len(list.NPCs))}
|
||||
func nameProjection(list dnd.NPCRegistry) ([]byte, error) {
|
||||
projection := projectedNPCRegistry{NPCs: make([]projectedNPC, len(list.NPCs))}
|
||||
for index, npc := range list.NPCs {
|
||||
projection.NPCs[index] = projectedNPC{Name: npc.Name}
|
||||
}
|
||||
@@ -254,8 +254,8 @@ func formatIdentityIssues(issues []identity.Issue) string {
|
||||
return diagnostics.Aggregate("validate NPC registry identity", parts)
|
||||
}
|
||||
|
||||
func cloneNPCList(value dnd.NPCList) dnd.NPCList {
|
||||
return dnd.NPCList{NPCs: cloneNPCs(value.NPCs)}
|
||||
func cloneNPCRegistry(value dnd.NPCRegistry) dnd.NPCRegistry {
|
||||
return dnd.NPCRegistry{NPCs: cloneNPCs(value.NPCs)}
|
||||
}
|
||||
|
||||
func cloneNPCs(values []dnd.NPC) []dnd.NPC {
|
||||
|
||||
@@ -164,14 +164,14 @@ func TestResolverHandlesConstructionAndOperationReferences(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func registryFixture() dnd.NPCList {
|
||||
return dnd.NPCList{NPCs: []dnd.NPC{
|
||||
func registryFixture() dnd.NPCRegistry {
|
||||
return dnd.NPCRegistry{NPCs: []dnd.NPC{
|
||||
{ID: identity.DeriveID("Mira Thorn"), Name: "Mira Thorn", SourceRefs: []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 1, EndUnitID: 2}}},
|
||||
{ID: identity.DeriveID("Captain Vale"), Name: "Captain Vale", SourceRefs: []source.SourceRef{{SourceID: "session-alpha", StartUnitID: 3, EndUnitID: 3}}},
|
||||
}}
|
||||
}
|
||||
|
||||
func resolveList(t *testing.T, list dnd.NPCList) *Registry {
|
||||
func resolveList(t *testing.T, list dnd.NPCRegistry) *Registry {
|
||||
t.Helper()
|
||||
registry, err := Resolve(listReferenceSet(t, list))
|
||||
if err != nil {
|
||||
@@ -180,7 +180,7 @@ func resolveList(t *testing.T, list dnd.NPCList) *Registry {
|
||||
return registry
|
||||
}
|
||||
|
||||
func listReferenceSet(t *testing.T, list dnd.NPCList) contracts.ReferenceSet {
|
||||
func listReferenceSet(t *testing.T, list dnd.NPCRegistry) contracts.ReferenceSet {
|
||||
t.Helper()
|
||||
content, err := npccodec.New().Encode(list)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user