Documentation
¶
Overview ¶
Package engine hosts the squoze optimization pipeline.
v2 pipeline: detect wire format → walk message structures with targeted JSON-path edits (gjson/sjson) → squeeze only provably-safe text (machine output classified by the router) → report savings. Untouched bytes stay byte-identical: sjson edits in place instead of re-marshalling maps, which is what keeps provider prompt caches stable.
Contracts: fail-open (unknown/invalid input passes through), never-elide (error lines survive), savings floor, idempotent markers.
Index ¶
Constants ¶
const DefaultMemoCapacity = 4096
DefaultMemoCapacity bounds pinned decisions per process (~4k blobs).
const (
SkipBodyTooLarge = "body_too_large"
)
Skip reasons reported in Result.SkipReason. They are stable strings: 2papi forwards them verbatim in the X-Gateway-Squoze-Skip response header, so renaming one is a breaking change for anything parsing that header.
const Version = "0.4.0"
Version is reported by `squoze version` and stamped into response headers.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the pipeline with its cache-guard state attached.
func NewEngineWith ¶
NewEngineWith attaches an external originals store (e.g. persisted).
func NewEngineWithLimits ¶ added in v0.4.0
NewEngineWithLimits returns an isolated instance bounded by lim. The zero Limits is v0.3.0 behaviour, so NewEngine(cap) and NewEngineWithLimits(cap, Limits{}) are interchangeable.
func (*Engine) Apply ¶
Apply runs the full pipeline: detect → route → squeeze (profile- and memo-aware) → report. Unknown or invalid input passes through byte-for-byte (fail-open).
type Limits ¶ added in v0.4.0
type Limits struct {
// MaxBodyBytes skips the whole request, without so much as sniffing its
// wire format, once the body exceeds this many bytes. 0 means no cap.
//
// This is the only limit that reports itself: Result.Skipped is set and
// Result.SkipReason says why, so a gateway can surface "this request was
// too big to optimize" instead of a silent zero-savings pass.
MaxBodyBytes int
// MaxBlockBytes leaves an individual content block alone once it exceeds
// this many bytes. 0 means no cap. Use it when a single pathological
// tool_result should not be allowed to dominate a request's latency
// budget while the rest of the messages still get optimized.
MaxBlockBytes int
// MinBlockBytes replaces the built-in 64-byte floor below which a block
// is not worth examining. 0 keeps the built-in floor; a value below it
// is ignored, because under 64 bytes no pass can produce savings that
// survive the marker it would have to write.
MinBlockBytes int
}
Limits bounds the work one Engine is willing to do on a request.
Every field is opt-in: the zero value is v0.3.0 behaviour, byte for byte. That is not a convention but a tested contract — TestZeroLimitsMatchV030 runs the corpus through NewEngine and NewEngineWithLimits(cap, Limits{}) and requires bytes.Equal, so an embedder that never mentions Limits cannot be affected by this type existing.
The bounds are sizes, never durations. A wall-clock deadline would make the output depend on how loaded the host was, and squoze's cache-safety contract is that identical original bytes always produce byte-identical output — a deadline would silently break every provider prompt cache downstream of it.
type Result ¶
type Result struct {
Format wire.Format
Family string // model family the request was optimized for
OriginalBytes int
SentBytes int
SavedBytes int
BlocksSqueezed int
MemoHits int // blocks served byte-identical from the decision memo
Transforms []string
DurationMS float64
// Skipped is set when the request came back untouched without being
// examined, which today means one thing: it was larger than
// Limits.MaxBodyBytes. A request that was examined and simply had nothing
// worth squeezing is not "skipped" — it reports SavedBytes 0 instead.
Skipped bool
SkipReason string // one of the Skip* constants; "" unless Skipped
}
Result describes one processed request body.