acadapter

package
v0.7.17 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package acadapter is the context-guru glue between context-guru's own call sites and the shared host runtime github.com/rossoctl/accountant/host (accountant#150, migration phase 5).

The host module is deliberately generic: it names no host, no injector and no component (host/boundary_test.go, host/doc.go). context-guru's real call sites, by contrast, speak context-guru's own concepts: its operator prefix "context-guru.", its ChangeID namespace "cg:", its own expand and adjudicate injector tools, its primary-thread name (thread.Primary, "") and bifrost's ModelProvider. This package holds exactly the small, context-guru-specific conversions a future wiring step needs to swap a context-guru package for the matching host package, so that swap is mechanical.

This package is LEAF glue. Nothing in context-guru imports it yet: the proxy, accwire, accrec, providerusage, respfacts and apply keep running on their own code (phase 5 item 1 adds the library; a later PR wires the proxy to it, phase 5 item 2, and deletes the moved code, item 3). It imports github.com/rossoctl/accountant, github.com/rossoctl/accountant/host/... and context-guru's own packages; none of those import it back.

What each host package needed:

  • host/wire: an Owner callback that names context-guru's expand/adjudicate injectors, plus EnvelopeOps bound to context-guru's prefix and namespace. See wire.go.
  • host/record: the primary-thread-to-"main" mapping (ThreadID, ThreadOf, PingKey), which depends on context-guru's own thread identifiers and so cannot live in the generic package. See thread.go.
  • host/usage: a field-for-field conversion between providerusage.Tiers and usage.Tiers (the structs are identical), and to accountant.Usage. See usage.go.
  • host/providerfacts: a classifier from bifrost's ModelProvider to providerfacts.Provider (the wire dialect), which is a context-guru/bifrost concept the generic table cannot read for itself. See providerfacts.go.
  • host/skip: NO adapter. context-guru's accrec.Rejected and accrec.ShouldCompute already match skip.Rejected and skip.Reason's reason strings, so a caller can use skip directly. skip_test.go proves it; there is no skip.go on purpose.
  • host/snapshot: NO adapter here. context-guru's on-disk state format (accrec/state.go, proxy/accountant_state.go) is incompatible with snapshot.Payload, and a one-time cold start on the switch was already decided for the shared package. A context-guru legacy reader is out of scope for this adapter-only PR; the proxy-wiring PR accepts the one-time cold start.

Index

Constants

View Source
const ChangeNamespace = "cg:"

ChangeNamespace is context-guru's ChangeID namespace for the envelope operations ("cg:"). It is the prefix accwire.envelopeOp already uses ("cg:" + component + ":" + key). The one-hour relabel keeps its bare "headttl:" ChangeID whatever the namespace is, because the engine keys the 1h premium on that prefix (design §4.4); host/wire.EnvelopeOps handles that itself.

View Source
const OperatorPrefix = accwire.OperatorPrefix

OperatorPrefix is the host prefix context-guru books on every operator ("context-guru."). The generic library may not name a host, so EnvelopeOps takes it as an argument. It is accwire's own constant, so the adapter and the current proxy name one prefix.

Variables

This section is empty.

Functions

func Accountant

func Accountant(t usage.Tiers) accountant.Usage

Accountant converts host/usage.Tiers straight into accountant.Usage, the type Request.Compute takes. It is RecordUsage(t).Accountant(), the same result accrec.Usage.Accountant produces today from the same counts.

func EnvelopeOps

func EnvelopeOps(client, forwarded []byte) []accountant.Operation

EnvelopeOps lists the operations that explain the difference between the client body and the forwarded body in the tools array, the system section and the top-level cache_control TTL, with context-guru's prefix, namespace and injector Owner already applied. It is the host/wire replacement for accwire's own envelopeOps.

Note: this is the pipeline-independent envelope diff only. context-guru's accwire also builds the tool-deferral message operations (accwire.messageOps) from the billed body; those stay host-side (they depend on the deferral's own names and the billed-body rule) and are not part of this function. A future wiring step appends them after EnvelopeOps, as accrec.Record does today.

func For

func For(p bschemas.ModelProvider, model string, forwarded []byte) accountant.EntryFacts

For is host/providerfacts.For for a context-guru request: it classifies the bifrost provider and reads whether every raw cache_control mark of the forwarded body asks for the one-hour tier (wire.AllMarksAsk1h). It returns the TTL and Lifetime the entry's dialect promises, the base facts accrec.EntryFacts then folds a ping and the billed-tier correction into. It is the host/providerfacts replacement for the dialect part of apply.CacheLifetime.

It does not apply a ping, a session floor or the billed-tier (BilledTTL) correction: those depend on context-guru's own stores and stay host-side, exactly as the generic table's doc requires.

func FromProviderUsage

func FromProviderUsage(t providerusage.Tiers) usage.Tiers

FromProviderUsage converts context-guru's providerusage.Tiers into host/usage.Tiers. The two structs carry the same five fields (FreshInput, CacheRead, CacheWrite, CacheWrite1h, Output), so this is a field-for-field copy. It exists so a future wiring step that replaces providerusage.Parse with usage.Parse (and usage.Merger for a stream) can cross the two types mechanically, and so the differential test can compare the two parsers' output on one block.

func Owner

func Owner() wire.Owner

Owner is the host/wire.Owner callback for context-guru: it names the operator component of a tool declaration one of context-guru's own injectors added. expand and adjudicate inject a declaration under a name only they use; the callback maps that name to the injector's component. It returns ok=false for every other name, so host/wire gives the default attribution (toolschema for a rewrite, toolfilter for a removal), exactly as accwire.envelopeOwner does today.

This is the one piece of accwire's envelope logic that cannot move into the generic host package: it is the only place that imports context-guru's injector packages (expand, adjudicate), which a generic library must not name.

func PingKey

func PingKey(session, threadID string) string

PingKey is the key record.PingStore and record.TierStore keep one thread's facts under, with the primary thread mapped to "main" first. It is record.PingKey(session, ThreadID(threadID)), the same NUL-joined format accrec.PingKey builds today.

func Provider

Provider classifies a bifrost ModelProvider into the wire dialect host/providerfacts keys its cache table by. This mapping is the context-guru-specific piece: the generic table knows only the dialect, not bifrost's provider type (providerfacts.go, "Classify stays with each host").

  • A provider that honours cache_control breakpoints (Anthropic, Bedrock, BedrockMantle, Vertex, per modelinfo.HonoursCacheControl) is the Anthropic dialect: explicit breakpoints, an exact TTL.
  • OpenAI is the Chat/Responses dialect: a provider-managed cache with a documented minimum on GPT-5.6+ and an unknown lifetime otherwise (host/providerfacts.For gates the model itself).
  • Every other provider is Unknown.

It uses modelinfo.HonoursCacheControl as the single source of truth for the breakpoint set, so it cannot drift from apply.CacheLifetime, which uses the same predicate.

func RecordUsage

func RecordUsage(t usage.Tiers) record.Usage

RecordUsage is host/usage.Tiers as the host/record.Recorder's billed-usage type. record.Usage has no Output field, because accountant.Usage prices the prompt tiers only (output is priced on its own path). This is the conversion a future wiring step feeds into record.Recorder.Compute/Price.

func ThreadID

func ThreadID(id string) string

ThreadID maps context-guru's primary thread (thread.Primary, the empty string) onto "main", the library's name for the first thread. Every other id passes through unchanged. host/record is key-agnostic and does not normalize (record.ThreadOf, record.PingKey keep the id they are given), because the primary-thread name depends on context-guru's own thread identifiers. So a caller maps here first, then calls the generic store. This mirrors accrec.ThreadID.

func ThreadOf

func ThreadOf(id, parent string, hasParent bool) accountant.Thread

ThreadOf is the library thread for a context-guru thread id and, when the thread continues another by content, its parent. It maps the primary thread to "main" first, then calls record.ThreadOf. A continuing thread names its parent but starts with no state of its own (design §4.1). This mirrors accrec.ThreadOf. When hasParent is false, parent is ignored (record.ThreadOf drops it), so a primary-thread "" parent is never mismapped.

func ToProviderUsage

func ToProviderUsage(t usage.Tiers) providerusage.Tiers

ToProviderUsage is the reverse of FromProviderUsage: host/usage.Tiers into providerusage.Tiers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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