Documentation
¶
Overview ¶
Package app coordinates token counting through provider and local tokenizer ports.
The package owns orchestration policy only: provider-vs-local mode selection, fallback behavior, context checks, and result metadata defaults. Concrete provider count APIs, tokenizer adapters, persistence, runtime integration, and protocol endpoints live outside this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCountingDisabled = errors.New("token counting disabled") ErrProviderUnsupported = errors.New("provider token counting unsupported") )
Functions ¶
This section is empty.
Types ¶
type CountCallInput ¶
type CountOutputInput ¶
type CountResult ¶
type CountResult struct {
InputTokens int
OutputTokens int
CacheReadTokens int
CacheWriteTokens int
ReasoningTokens int
TotalTokens int
// TotalTokensPresent distinguishes an authoritative total (including
// explicit zero) from an omitted total that may be inferred later.
TotalTokensPresent bool
Accounting lipapi.UsageAccountingMetadata
Fallbacks []Fallback
}
type CountTextInput ¶
type Fallback ¶
type Fallback struct {
Reason FallbackReason
Message string
Err error
}
type FallbackReason ¶
type FallbackReason string
const ( FallbackReasonProviderUnsupported FallbackReason = "provider_unsupported" FallbackReasonProviderError FallbackReason = "provider_error" FallbackReasonLocalError FallbackReason = "local_error" FallbackReasonLocalDefaultEncoding FallbackReason = "local_default_encoding" )
type LocalCounter ¶
type LocalCounter interface {
CountText(context.Context, CountTextInput) (CountResult, error)
CountCall(context.Context, CountCallInput) (CountResult, error)
CountOutput(context.Context, CountOutputInput) (CountResult, error)
}
type ProviderCountInput ¶
type ProviderCounter ¶
type ProviderCounter interface {
SupportsCount(context.Context, ProviderCountInput) ProviderSupport
CountText(context.Context, CountTextInput) (CountResult, error)
CountCall(context.Context, CountCallInput) (CountResult, error)
CountOutput(context.Context, CountOutputInput) (CountResult, error)
}
type ProviderSupport ¶
type ProviderSupport struct {
Status SupportStatus
Message string
Err error
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(cfg ServiceConfig, provider ProviderCounter, local LocalCounter) *Service
func (*Service) CountCall ¶
func (s *Service) CountCall(ctx context.Context, input CountCallInput) (CountResult, error)
func (*Service) CountOutput ¶
func (s *Service) CountOutput(ctx context.Context, input CountOutputInput) (CountResult, error)
func (*Service) CountText ¶
func (s *Service) CountText(ctx context.Context, input CountTextInput) (CountResult, error)
type ServiceConfig ¶
type ServiceConfig struct {
Mode Mode
}
type SupportStatus ¶
type SupportStatus string
const ( SupportStatusSupported SupportStatus = "supported" SupportStatusUnsupported SupportStatus = "unsupported" )
Click to show internal directories.
Click to hide internal directories.