Adopt location 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.LocationList
|
||||
list dnd.LocationRegistry
|
||||
canonical []byte
|
||||
digest string
|
||||
projectionDigest string
|
||||
@@ -68,7 +68,7 @@ func (r *Resolver) Resolve(references contracts.ReferenceSet) (*Registry, error)
|
||||
return r.resolver.Resolve(references)
|
||||
}
|
||||
|
||||
// Resolve validates an optional location-list reference. An absent reference
|
||||
// Resolve validates an optional location-registry reference. An absent reference
|
||||
// uses the canonical empty projection and has no durable registry identity.
|
||||
func Resolve(references contracts.ReferenceSet) (*Registry, error) {
|
||||
item, present, err := registryresolver.ResolveOptionalSingleItem(references, locationReferenceSpec())
|
||||
@@ -102,7 +102,7 @@ func emptyRegistry() *Registry {
|
||||
content := []byte(emptyPrompt)
|
||||
projectionDigest := semanticDigest(content)
|
||||
return &Registry{
|
||||
list: dnd.LocationList{Locations: []dnd.Location{}},
|
||||
list: dnd.LocationRegistry{Locations: []dnd.Location{}},
|
||||
canonical: append([]byte(nil), content...),
|
||||
projectionDigest: projectionDigest,
|
||||
promptInput: contracts.NewLLMInputMaterial(ReferenceSlot, locationcodec.MediaType, content, projectionDigest, ""),
|
||||
@@ -124,7 +124,7 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
|
||||
return nil, fmt.Errorf("encode canonical location registry: approved location value could not be encoded")
|
||||
}
|
||||
|
||||
list := cloneLocationList(value)
|
||||
list := cloneLocationRegistry(value)
|
||||
lookupByID := make(map[string]int, len(list.Locations))
|
||||
for index, location := range list.Locations {
|
||||
lookupByID[location.ID] = index
|
||||
@@ -157,12 +157,12 @@ func (r *Registry) Locations() []dnd.Location {
|
||||
return cloneLocations(r.list.Locations)
|
||||
}
|
||||
|
||||
// List returns a defensive copy of the validated location list.
|
||||
func (r *Registry) List() dnd.LocationList {
|
||||
// List returns a defensive copy of the validated location registry.
|
||||
func (r *Registry) List() dnd.LocationRegistry {
|
||||
if r == nil {
|
||||
return dnd.LocationList{}
|
||||
return dnd.LocationRegistry{}
|
||||
}
|
||||
return cloneLocationList(r.list)
|
||||
return cloneLocationRegistry(r.list)
|
||||
}
|
||||
|
||||
// CanonicalBytes returns a defensive copy of the canonical durable JSON.
|
||||
@@ -236,12 +236,12 @@ type projectedLocation struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type projectedLocationList struct {
|
||||
type projectedLocationRegistry struct {
|
||||
Locations []projectedLocation `json:"locations"`
|
||||
}
|
||||
|
||||
func promptProjection(list dnd.LocationList) ([]byte, error) {
|
||||
projection := projectedLocationList{Locations: make([]projectedLocation, len(list.Locations))}
|
||||
func promptProjection(list dnd.LocationRegistry) ([]byte, error) {
|
||||
projection := projectedLocationRegistry{Locations: make([]projectedLocation, len(list.Locations))}
|
||||
for index, location := range list.Locations {
|
||||
projection.Locations[index] = projectedLocation{ID: location.ID, Name: location.Name}
|
||||
}
|
||||
@@ -256,8 +256,8 @@ func formatIdentityIssues(issues []identity.Issue) string {
|
||||
return diagnostics.Aggregate("validate location registry identity", parts)
|
||||
}
|
||||
|
||||
func cloneLocationList(value dnd.LocationList) dnd.LocationList {
|
||||
return dnd.LocationList{Locations: cloneLocations(value.Locations)}
|
||||
func cloneLocationRegistry(value dnd.LocationRegistry) dnd.LocationRegistry {
|
||||
return dnd.LocationRegistry{Locations: cloneLocations(value.Locations)}
|
||||
}
|
||||
|
||||
func cloneLocations(values []dnd.Location) []dnd.Location {
|
||||
|
||||
Reference in New Issue
Block a user