Documentation
¶
Overview ¶
Package accwire reads a request body for the accountant, one adapter per wire.
The accountant library is wire-agnostic: it takes a Body of hashed positions, cache-mark breakpoints and operations. This package turns a provider request into those. Each wire reads its own shape in four places, and they all sit behind one Wire value, chosen once per body:
- Body and Parse cut a body into tools, system and messages (the hash space of the positions);
- Breakpoints finds the cache marks;
- EnvelopeOps and MessageOps report the edits that no pipeline component reports;
- WireIndex maps a pipeline slot path to the wire position it sits in.
A new wire (accountant#17) adds one kind here, and no other place. The package is a library: it imports no host package (proxy, proxyapp, dash).
The write side stays out. apply's slot types rewrite the request that goes upstream, so only this read side sits behind the interface (#1164).
Index ¶
Constants ¶
const ( // OpKeeper is accountant.PingOps's operator: the keep-alive ping's spend. It has no host prefix. // The library exports no constant for it; TestOpKeeperIsThePingOperator reads it from PingOps. OpKeeper = "keeper" // OpHeadTTL is the 1h head TTL, a host option (apply/headttl.go, envelopeOps). OpHeadTTL = "headttl" // OpTailBreakpoint is the trailing cache mark apply adds (apply/ops.go). OpTailBreakpoint = "tailbreakpoint" // OpToolDefer is tool deferral (accrec's billed-body pass, the proxy's MessageOps). OpToolDefer = "tooldefer" // OpExpand and OpAdjudicate are the tool declarations expand and adjudicate inject (envelopeOwner). OpExpand = "expand" OpAdjudicate = "adjudicate" // OpExpandRestore is the copy fixed_restore inserts (apply/restore.go, #481). OpExpandRestore = "expand_restore" )
The operators that book savings but are not registered components (components.Names()). Each emit site uses its constant, so OperatorsOutsideRegistry cannot miss a name the code books.
const OperatorPrefix = "context-guru."
OperatorPrefix is the host prefix of every operator name context-guru books. The accountant's metrics sink cuts it off, so the `component` label is the bare name.
Variables ¶
This section is empty.
Functions ¶
func FindCacheMark ¶
FindCacheMark returns the gjson path of the first cache-control mark under v, or "" when there is none. A mark is a cache_control key on v itself or on a block of a content array, at any depth of content nesting (a tool_result block's own content). It goes down only through "content" arrays, so a cache_control key anywhere else stays in the hash: a tool's input_schema.properties.cache_control parameter, or a tool_use block's input value, is part of what the provider caches, and a change to it must change the hash (#1272). It never looks inside a string.
func Operator ¶ added in v0.7.9
Operator returns the booked operator name of name: the host prefix and the bare name.
func OperatorsOutsideRegistry ¶ added in v0.7.9
func OperatorsOutsideRegistry() []string
OperatorsOutsideRegistry lists every operator that books savings and is not a registered component. A metrics sink built with WithComponents(components.Names()...) pushes these as component="other"; accrec.MetricComponents adds them.
func WithoutCacheMarks ¶
WithoutCacheMarks is one element's JSON without its cache_control marks: the element's own, the ones on its content blocks, and the ones nested deeper in content, such as a mark inside a tool_result block's own content array (issue #917). A key named cache_control anywhere else is data, not a mark, and stays (see FindCacheMark). An element with none is returned as it is, byte for byte, so the common case costs no allocation. The result is only hashed. It is never sent anywhere.
Types ¶
type Wire ¶
type Wire interface {
// Name is "messages" or "responses".
Name() string
// Body hashes a request body in the provider's order: tools, system, messages. A body without a
// conversation (or with invalid JSON) gives an empty Body.
Body(raw []byte) accountant.Body
// Parse is Body and Breakpoints on one parse of the body. count prices each thinking block the
// proxy saw a model make (accountant design D16); nil gives every block the fixed price. The
// hashes and sizes do not depend on it.
Parse(raw []byte, count accountant.OpaqueCount) (accountant.Body, []accountant.Breakpoint)
// Breakpoints lists the cache marks as positions in the same space as Body.
Breakpoints(raw []byte) []accountant.Breakpoint
// EnvelopeOps lists the operations that explain the tools and system sections' difference
// between the client body and the forwarded body. It is nil when either has no conversation.
EnvelopeOps(client, forwarded []byte) []accountant.Operation
// MessageOps explains a change to the messages that an edit made AFTER the pipeline, with the
// edit's own operator.
MessageOps(operator string, before, after []byte) []accountant.Operation
// WireIndex maps a normalized slot path, such as "messages.3.content.1.text" or
// "input.3.content.1.text", to the wire position it sits in. ok is false when the path names
// no position of this wire.
WireIndex(slotPath string) (index int, ok bool)
}
Wire is the accountant's reader for one provider wire.