host

package module
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 0 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 host is the shared provider-API proxy host runtime for github.com/rossoctl/accountant: the request and usage parsing, request lifecycle and bounded stores that any host built on accountant needs, and that each host wrote on its own before this module existed (accountant#150).

This module is separate from the root module because it needs a JSON library (gjson/sjson) to parse a provider's request and response bodies, and the root module imports only the standard library (R3). It still knows no host: no sweep, no keep-alive preset, no host component name. It knows cache tiers, breakpoints, operations, pings and requests, the same generic vocabulary as the root module, plus the Anthropic and OpenAI wire shapes that carry them -- a provider concept, not a host concept.

A host still keeps anything that depends on its own concepts: its own operator names, its own operation attribution for a change a host-specific component made, its own dashboard or event output. See the wiring document in docs/ for what a host built on this package still has to do itself.

wire/ reads a provider's inference request body into accountant.Body and []accountant.Breakpoint (wire.Parse), and answers whether every cache_control mark in a body asks for the one-hour tier (wire.AllMarksAsk1h). A host's own endpoint-to-wire-format mapping stays with the host: Parse does not need it, since it detects the body's own shape. wire.EnvelopeOps diffs the two bodies a host sends -- the client body and the forwarded body -- and reports the operations that explain their difference in the tools array, the system section, and the top-level cache_control TTL (accountant#150), with wire.ContentChangeID and wire.TextChangeID for the stable ChangeIDs. A host passes its own operator prefix and ChangeID namespace, and a wire.Owner callback that names the operator of a declaration the host's own injector added, so this package imports no host injector.

providerfacts/ gives the accountant.EntryFacts a provider's prompt cache has for a model (providerfacts.For): Anthropic's two breakpoint tiers, and OpenAI's documented GPT-5.6+ minimum retention. A host's own provider classification (an endpoint path's wire dialect, or a provider value its own request pipeline set) stays with the host: For only needs the dialect, not which company serves it.

sse/ reads the payload of a Server-Sent Events stream (sse.Data, sse.EventData, sse.DataLine), the framing a provider's streamed response uses.

thinkcount/ keeps the token count of each thinking block a model made (accountant design D16), so a host can price a block at its own count when the client sends it back (accountant.NewBodyCounted). A Table is a bounded, concurrency-safe, JSON-(un)marshalable map from a thinking signature's accountant.OpaqueKey to its token count; FromBody and Collector read the count and the signatures from a provider's response, buffered or streamed.

skip/ answers whether to call accountant.Request.Compute for a finished request, and why not when the answer is no (skip.Reason over skip.Input, accountant#150). It reads only structural facts the host knows before pricing: the status (skip.Rejected), the round count, whether there is a session, whether the provider holds the prompt history (skip.ServerHeldHistory reads the body), and whether a body rewrite could not be placed. Whether the usage is priceable, and a library panic, stay with the host: a different axis each host orders its own way, and a result of the call, not a fact before it.

usage/ reads the billed token tiers out of a provider's usage block (usage.Parse into usage.Tiers), and merges those tiers across a stream's events into one set (usage.Merger). It reads the Anthropic and OpenAI (Responses and chat) dialects. The merge replaces the fresh-input count with the last event that reported a nonzero one, and takes the maximum of each cache tier and the output, which is what a streamed response needs. A host keeps its own miss classification and request-lifecycle wiring: this package gives the neutral tiers and the merge only.

record/ holds the three bounded, concurrency-safe stores a host keeps beside the accountant to price a request's cache entry across turns (accountant#150). record.PingStore remembers a thread's latest keep-alive ping facts until its next request takes them. record.SiblingStore remembers each thread's last forwarded body, to give accountant.EntryFacts.SharedWarm: the prefix another thread of the session kept warm, which a rescue must not credit again (R54). record.TierStore remembers whether a thread's last write was billed at the one-hour tier. A nil store is a no-op; each holds only the library's hash-and-size Body and plain facts, never content. record.PingKey gives the one key format PingStore and TierStore share. The rule that reads TierStore after the response (a downgraded entry TTL) stays with the host: it depends on the host's own billed-tier split. record.Recorder runs the accountant calls around one request (record.NewRecorder, Begin, End, ComputeSafe, Price): it composes the three stores with the accountant.Trackers and a thinkcount.Table, prices a finished request or says why it books no figure, and fails open on a library panic. The primary-thread-to-"main" mapping and the body rewrites a host reports as operations stay with the host.

snapshot/ saves and restores a host's accounting state to one file, so a restart does not drop the state of every live thread (accountant#150). snapshot.Save writes a snapshot.Payload atomically (temp file, sync, rename), creating the directory if it is missing; snapshot.Load reads it back and cleans an old-enough temp file a crash left behind, a bound that also keeps Load safe to call while a Save or a Keep is in flight on the same path. A Payload carries the opaque library blob (accountant.Trackers.Snapshot's output) plus any further opaque JSON a host keeps beside it, and a SavedAt the age is measured from -- the content's own timestamp, never the file's mtime, so a copy or a backup cannot corrupt the age. snapshot.Keep is the one-goroutine periodic saver: it skips the write on a tick whose build reports nothing changed, and does a final save on cancellation. The max age, any version gate and any size bound stay with the host: each is a host policy, and trimming needs the payload's shape this package does not have.

examplehost/ is a worked, runnable skeleton of this wiring: about 140 lines that show the four steps a host repeats for each request (Begin, the host's own rewrite, End, Price), over made-up bodies and usage. It is not a real proxy. Run it with "cd host && go run ./examplehost". A new host can copy it instead of reading a real host's much larger code. See its README and the wiring document in docs/ (W6) for the full lifecycle.

Directories

Path Synopsis
Command examplehost is a worked, runnable skeleton of the wiring a provider-API proxy does around the accountant and accountant/host libraries.
Command examplehost is a worked, runnable skeleton of the wiring a provider-API proxy does around the accountant and accountant/host libraries.
Package providerfacts gives the accountant.EntryFacts a provider's prompt cache has for a model: the cache lifetime its wire dialect promises, from one table (accountant#150).
Package providerfacts gives the accountant.EntryFacts a provider's prompt cache has for a model: the cache lifetime its wire dialect promises, from one table (accountant#150).
Package record holds the bounded, concurrency-safe stores a provider-API proxy keeps beside the accountant to price a request's cache entry across turns: the ping store, the sibling store and the tier store.
Package record holds the bounded, concurrency-safe stores a provider-API proxy keeps beside the accountant to price a request's cache entry across turns: the ping store, the sibling store and the tier store.
Package skip answers one host question: should the host call accountant.Request.Compute for a finished request, and if not, why (the host wiring document in docs/, W6.1)? Every provider-API proxy built on accountant asks it, and each wrote the same answer on its own before this package existed (accountant#150).
Package skip answers one host question: should the host call accountant.Request.Compute for a finished request, and if not, why (the host wiring document in docs/, W6.1)? Every provider-API proxy built on accountant asks it, and each wrote the same answer on its own before this package existed (accountant#150).
Package snapshot saves and restores a host's accounting state to one file on disk, so a restart does not drop the state of every live thread.
Package snapshot saves and restores a host's accounting state to one file on disk, so a restart does not drop the state of every live thread.
Package sse reads the payload of a Server-Sent Events stream, the framing a provider's streamed response uses (accountant#150).
Package sse reads the payload of a Server-Sent Events stream, the framing a provider's streamed response uses (accountant#150).
Package thinkcount keeps the token count of each thinking block a model made, so the accountant can price a block at its own count when the client sends it back (accountant design D16, issue #1187; moved from a host's own copy at accountant#150).
Package thinkcount keeps the token count of each thinking block a model made, so the accountant can price a block at its own count when the client sends it back (accountant design D16, issue #1187; moved from a host's own copy at accountant#150).
Package usage reads the billed token tiers out of a provider's `usage` block, and merges them across a stream's events into one set.
Package usage reads the billed token tiers out of a provider's `usage` block, and merges them across a stream's events into one set.
Package wire reads a provider's inference request body into the shape github.com/rossoctl/accountant hashes: tools, then system, then messages, one []byte per position, in the provider's cache order.
Package wire reads a provider's inference request body into the shape github.com/rossoctl/accountant hashes: tools, then system, then messages, one []byte per position, in the provider's cache order.

Jump to

Keyboard shortcuts

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