Documentation
¶
Overview ¶
Package domain reconciles already-emitted token usage into billing-plane choices.
It is pure domain logic: it does not count tokens, price usage, call providers, persist state, or collect runtime streams.
Reconciliation is deterministic by usage plane. Non-policy_reserved candidates win over reservations for the same plane; reservations are additive only when no actual candidate exists for that plane. Strict provider billing requires an authoritative provider_billable entry sourced from provider_reported or provider_count_api.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BillingPolicy ¶
type BillingPolicy string
BillingPolicy selects which reconciled usage plane should be billable.
const ( PolicyBillProvider BillingPolicy = "bill_provider" PolicyBillClientVisible BillingPolicy = "bill_client_visible" PolicyBillProxyBillable BillingPolicy = "bill_proxy_billable" PolicyProviderThenClient BillingPolicy = "provider_then_client" PolicyStrictProviderRequired BillingPolicy = "strict_provider_required" PolicyRequireSamePlaneExactness BillingPolicy = "require_same_plane_exactness" )
type Conflict ¶
type Conflict struct {
Code ConflictCode
Plane lipapi.UsagePlane
Message string
}
type ConflictCode ¶
type ConflictCode string
ConflictCode identifies reconciliation mismatches that callers may audit.
const ( ConflictPlaneCandidates ConflictCode = "plane_candidates" ConflictTransformedUsage ConflictCode = "transformed_usage" )
type Result ¶
type Result struct {
Planes map[lipapi.UsagePlane]lipapi.ScopedUsageDelta
BillablePlane lipapi.UsagePlane
BillableUsage lipapi.ScopedUsageDelta
Conflicts []Conflict
Warnings []Warning
Complete bool
IncompleteReason string
}
func Reconcile ¶
func Reconcile(policy BillingPolicy, entries ...lipapi.ScopedUsageDelta) Result
Reconcile reconciles already-collected usage candidates. Exact duplicate non-policy-reserved entries are counted once. Per plane, actual candidates win over policy reservations; reservations are additive only when no actual usage exists for that plane.
func ReconcileEvents ¶
func ReconcileEvents(policy BillingPolicy, events ...lipapi.Event) Result
func (Result) UsageForPlane ¶
func (r Result) UsageForPlane(plane lipapi.UsagePlane) (lipapi.ScopedUsageDelta, bool)
type Warning ¶
type Warning struct {
Code WarningCode
Plane lipapi.UsagePlane
Message string
}
type WarningCode ¶
type WarningCode string
WarningCode identifies non-fatal input quality issues.
const ( WarningUnknownPlane WarningCode = "unknown_plane" WarningUnknownSource WarningCode = "unknown_source" WarningZeroUsage WarningCode = "zero_usage" )