preflight

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: 10 Imported by: 0

Documentation

Overview

Package preflight evaluates token-accounting admission checks before a backend attempt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

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

func NewChecker

func NewChecker(counter Counter, cfg Config) *Checker

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, in Input) Decision

func (*Checker) CheckWire

func (c *Checker) CheckWire(ctx context.Context, in WireInput) Decision

CheckWire evaluates token preflight over bounded wire facts and replay source without constructing a full lipapi.Call or materializing prompt text (Requirements 6.2, 15.5, 21; Task 10.4). If the counter only supports CountCall, or exact tokenizer semantics do not exist, or counting is expensive/unbounded, CheckWire returns ReasonCountUnavailable, signaling that dynamic assessment must decline to canonical processing under the same permit.

func (*Checker) Enabled

func (c *Checker) Enabled() bool

Enabled reports whether this preflight checker is non-nil and enabled.

type Config

type Config struct {
	Enabled              bool
	Mode                 Mode
	MaxInputTokens       int64
	MaxOutputTokens      int64
	MaxContextTokens     int64
	ClampMaxOutputTokens bool
	UnknownOutputPolicy  UnknownOutputPolicy
}

type Counter

type Counter interface {
	CountCall(context.Context, app.CountCallInput) (app.CountResult, error)
}

type Decision

type Decision struct {
	Allowed                 bool
	Reason                  Reason
	Warnings                []string
	Err                     error
	Count                   app.CountResult
	AdjustedMaxOutputTokens *int
	// RequireMaxOutputEnforcement is set when preflight applied a max-output
	// clamp that must be enforceable on the selected backend before Open.
	RequireMaxOutputEnforcement bool
}

type Input

type Input struct {
	Backend                  string
	Model                    string
	CallID                   string
	Call                     lipapi.Call
	RequestedMaxOutputTokens *int
	Facts                    modelcatalog.ModelFacts
}

type Mode

type Mode string
const (
	ModeAdvisory Mode = "advisory"
	ModeStrict   Mode = "strict"
)

type Reason

type Reason string
const (
	ReasonAllowed              Reason = "allowed"
	ReasonDisabled             Reason = "disabled"
	ReasonCountUnavailable     Reason = "count_unavailable"
	ReasonInputLimitExceeded   Reason = "input_limit_exceeded"
	ReasonContextLimitExceeded Reason = "context_limit_exceeded"
	ReasonOutputLimitExceeded  Reason = "output_limit_exceeded"
	ReasonUnknownOutputDenied  Reason = "unknown_output_denied"
)

type UnknownOutputPolicy

type UnknownOutputPolicy string

UnknownOutputPolicy bounds future output exposure when the client omits max output.

const (
	UnknownOutputRequireClientLimit  UnknownOutputPolicy = "require_client_limit"
	UnknownOutputConfiguredDefault   UnknownOutputPolicy = "configured_default"
	UnknownOutputModelBackendMaximum UnknownOutputPolicy = "model_backend_maximum"
	UnknownOutputClamp               UnknownOutputPolicy = "clamp"
	UnknownOutputDeny                UnknownOutputPolicy = "deny"
)

type WireInput

type WireInput struct {
	Backend                  string
	Model                    string
	CallID                   string
	ProfileID                string
	Source                   largebody.Source
	RequestedMaxOutputTokens *int
	Facts                    modelcatalog.ModelFacts
	Semantics                largebody.ExactTokenizerSemantics
	MaxScanBytes             int64
	MaxPermitHoldCPU         time.Duration
}

WireInput supplies bounded wire facts and replay source to CheckWire (Task 10.4).

Jump to

Keyboard shortcuts

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