app

package
v0.1.0 Latest Latest
Warning

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

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

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")
	ErrProviderUnavailable = errors.New("provider token counting unavailable")
	ErrLocalUnavailable    = errors.New("local token counting unavailable")
)

Functions

This section is empty.

Types

type CountCallInput

type CountCallInput struct {
	Backend string
	Model   string
	CallID  string
	Call    lipapi.Call
}

type CountKind

type CountKind string
const (
	CountKindText   CountKind = "text"
	CountKindCall   CountKind = "call"
	CountKindOutput CountKind = "output"
)

type CountOutputInput

type CountOutputInput struct {
	Backend string
	Model   string
	CallID  string
	Text    string
	Events  []lipapi.Event
}

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 CountTextInput struct {
	Backend string
	Model   string
	CallID  string
	Text    string
}

type Fallback

type Fallback struct {
	Reason  FallbackReason
	Message string
	Err     error
}

type FallbackReason

type FallbackReason string
const (
	FallbackReasonProviderUnsupported  FallbackReason = "provider_unsupported"
	FallbackReasonProviderUnavailable  FallbackReason = "provider_unavailable"
	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 Mode

type Mode string
const (
	ModeProviderFirst Mode = "provider_first"
	ModeLocalFirst    Mode = "local_first"
	ModeProviderOnly  Mode = "provider_only"
	ModeLocalOnly     Mode = "local_only"
	ModeDisabled      Mode = "disabled"
)

type ProviderCountInput

type ProviderCountInput struct {
	Backend string
	Model   string
	Kind    CountKind
}

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"
	SupportStatusUnavailable SupportStatus = "unavailable"
)

Jump to

Keyboard shortcuts

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