source

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneMetadata added in v0.2.0

func CloneMetadata(metadata map[string]any) (map[string]any, error)

CloneMetadata returns an independently owned copy of JSON-shaped metadata. It preserves concrete map, slice, and array types while rejecting values that cannot be safely represented as JSON-shaped metadata.

func DigestChunk added in v0.2.0

func DigestChunk(chunk Chunk) (string, error)

DigestChunk returns a deterministic digest of a chunk, including its source provenance, content, units, and metadata.

func DigestChunkPlan added in v0.2.0

func DigestChunkPlan(plan ChunkPlan) (string, error)

DigestChunkPlan returns a deterministic digest of the logical plan. Storage schema, producer provenance, warnings, and timestamps are intentionally not part of the digest.

func DigestDocument added in v0.2.0

func DigestDocument(doc *SourceDocument) (string, error)

DigestDocument returns a deterministic digest of the canonical source document content. The existing Digest field is excluded from its own digest.

func UnitIndex

func UnitIndex(doc *SourceDocument, unitID int) (int, bool)

func ValidateChunkAnnotations added in v0.2.0

func ValidateChunkAnnotations(annotations ChunkAnnotations) error

ValidateChunkAnnotations requires annotations to already contain canonical JSON. CanonicalizeChunkAnnotations can be used at producer boundaries.

func ValidateChunkPlan added in v0.2.0

func ValidateChunkPlan(doc *SourceDocument, plan ChunkPlan) error

ValidateChunkPlan validates a canonical plan against the current source. Ranges may contain gaps or overlap, but their start positions must increase.

func ValidateDocument

func ValidateDocument(doc *SourceDocument) error

func ValidateRef

func ValidateRef(doc *SourceDocument, ref SourceRef) error

Types

type Chunk added in v0.2.0

type Chunk struct {
	ID              string           `json:"id"`
	SourceID        string           `json:"source_id"`
	Index           int              `json:"index"`
	Ref             SourceRef        `json:"ref"`
	Content         []byte           `json:"-"`
	MediaType       string           `json:"media_type"`
	Units           []SourceUnit     `json:"units"`
	Metadata        map[string]any   `json:"metadata,omitempty"`
	Annotations     ChunkAnnotations `json:"annotations,omitempty"`
	PlanAnnotations ChunkAnnotations `json:"plan_annotations,omitempty"`
}

func MaterializeChunkPlan added in v0.2.0

func MaterializeChunkPlan(doc *SourceDocument, plan ChunkPlan) ([]Chunk, error)

MaterializeChunkPlan deterministically expands a validated plan into chunks.

type ChunkAnnotations added in v0.2.0

type ChunkAnnotations map[string]json.RawMessage

func CanonicalizeChunkAnnotations added in v0.2.0

func CanonicalizeChunkAnnotations(annotations ChunkAnnotations) (ChunkAnnotations, error)

CanonicalizeChunkAnnotations validates annotation namespaces and JSON values and returns an independently owned map whose values use canonical JSON bytes.

func CloneChunkAnnotations added in v0.2.0

func CloneChunkAnnotations(annotations ChunkAnnotations) ChunkAnnotations

CloneChunkAnnotations returns a deep clone, including every raw JSON value.

type ChunkPlan added in v0.2.0

type ChunkPlan struct {
	SourceDigest string           `json:"source_digest"`
	Ranges       []ChunkRange     `json:"ranges"`
	Annotations  ChunkAnnotations `json:"annotations,omitempty"`
}

func CanonicalizeChunkPlan added in v0.2.0

func CanonicalizeChunkPlan(plan ChunkPlan) (ChunkPlan, error)

CanonicalizeChunkPlan returns a deep clone with canonical annotation bytes.

func CloneChunkPlan added in v0.2.0

func CloneChunkPlan(plan ChunkPlan) ChunkPlan

CloneChunkPlan returns a deep clone of a chunk plan.

type ChunkRange added in v0.2.0

type ChunkRange struct {
	StartUnitID int              `json:"start_unit_id"`
	EndUnitID   int              `json:"end_unit_id"`
	Annotations ChunkAnnotations `json:"annotations,omitempty"`
}

type DocumentIndex added in v0.2.0

type DocumentIndex struct {
	// contains filtered or unexported fields
}

DocumentIndex is an immutable snapshot of a source document's identity and unit positions for repeated source-reference operations.

func NewDocumentIndex added in v0.2.0

func NewDocumentIndex(doc *SourceDocument) DocumentIndex

NewDocumentIndex snapshots doc without retaining or mutating it.

func (DocumentIndex) DocumentID added in v0.2.0

func (i DocumentIndex) DocumentID() (string, bool)

DocumentID returns the indexed document identity.

func (DocumentIndex) Position added in v0.2.0

func (i DocumentIndex) Position(unitID int) (int, bool)

Position returns the indexed document position for unitID.

func (DocumentIndex) ValidateRef added in v0.2.0

func (i DocumentIndex) ValidateRef(ref SourceRef) error

ValidateRef validates ref against the indexed document snapshot.

type SourceDocument

type SourceDocument struct {
	ID       string         `json:"id"`
	Kind     string         `json:"kind"`
	Format   string         `json:"format"`
	Digest   string         `json:"digest"`
	Units    []SourceUnit   `json:"units"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type SourceRef

type SourceRef struct {
	SourceID    string `json:"source_id"`
	StartUnitID int    `json:"start_unit_id"`
	EndUnitID   int    `json:"end_unit_id"`
}

type SourceUnit

type SourceUnit struct {
	ID       int            `json:"id"`
	Kind     string         `json:"kind"`
	Text     string         `json:"text"`
	Ref      SourceRef      `json:"ref"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL