usagenorm

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package usagenorm validates and normalizes provider token-usage wire values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTokenCounts

func AddTokenCounts(field Field, left, right content.TokenCount) (content.TokenCount, error)

AddTokenCounts adds normalized counts without wrapping.

func RequireEqual

func RequireEqual(field Field, reported, calculated content.TokenCount) error

RequireEqual rejects contradictory reported and calculated values.

func SubtractTokenCounts

func SubtractTokenCounts(field Field, total, first, second content.TokenCount) (content.TokenCount, error)

SubtractTokenCounts removes two disjoint components from a reported total.

Types

type Count

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

Count preserves whether a JSON count field was absent and defers semantic validation until the owning codec supplies its typed field identity.

func (Count) OptionalTokenCount

func (c Count) OptionalTokenCount(field Field) (content.TokenCount, error)

OptionalTokenCount returns zero when an optional usage-detail field is absent or explicitly null. Every present non-null value retains TokenCount's strict numeric validation.

func (Count) Present

func (c Count) Present() bool

Present reports whether the JSON field was explicitly present.

func (Count) TokenCount

func (c Count) TokenCount(field Field) (content.TokenCount, error)

TokenCount returns zero for an absent count and rejects malformed or negative explicit values before converting an int64 to TokenCount.

func (*Count) UnmarshalJSON

func (c *Count) UnmarshalJSON(data []byte) error

UnmarshalJSON captures one syntactically valid JSON value without losing explicit null or numeric representation details.

type Field

type Field uint8

Field is the closed set of usage fields normalization may report.

const (
	FieldInputTokens Field = iota + 1
	FieldOutputTokens
	FieldCacheReadTokens
	FieldCacheCreationTokens
	FieldReasoningTokens
	FieldContextTokens
	FieldTotalTokens
)

Jump to

Keyboard shortcuts

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