Documentation
¶
Overview ¶
Package provider turns a context of state file records into one LLM request and the streamed response back into records. Five envelopes exist. Same context, same envelope, same bytes: the step record's request hash proves it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
Cache is the step record's cache header, facts only. Marks are the ids of the records that end a cache breakpoint. Anthropic and bedrock put one after the system prompt and one after the last user block; openai and gemini place their own, so the mark is the last record sent. TTL is seconds from the step's sent time, set only where the request the harness sends fixes it: anthropic and bedrock. The step's usage says what was read and written.
type Call ¶
type Call struct {
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
Call is the body of a call record.
type Envelope ¶
type Envelope interface {
Name() string
Accepts(typ string) bool
Owns(field string) bool
Compile(req Request) (body []byte, cache json.RawMessage, err error)
Stream(resp io.Reader, emit func(statefile.Record)) (statefile.Header, error)
}
Envelope is one wire shape. Name tags the thinking and step records it produces; only thinking with its own name is replayed. Compile is deterministic and returns the cache markers it placed, which go on the step record. Stream calls emit once per block as the stream completes it and returns the step header with usage. Accepts is the media types the envelope encodes as media; a record of any other type goes as text. Owns is the body fields Compile builds from the session, which params may not set.
type Provider ¶
type Provider struct {
URL string // full endpoint. gemini and bedrock take the model in the path, see Endpoint
Key string
Envelope Envelope
Headers func(req *http.Request, key string) // auth and version headers
Endpoint func(url, model string) string // nil means URL as is
}
func Bedrock ¶
Bedrock authenticates with a Bedrock API key (AWS_BEARER_TOKEN_BEDROCK), not SigV4. Model is an inference profile id such as us.anthropic.claude-haiku-4-5-20251001-v1:0.
func OpenAIChat ¶
OpenAIChat is the Chat Completions envelope for OpenAI-compatible endpoints. Thinking records are never replayed.
type Request ¶
type Request struct {
Model string
Key string // session id, the routing key for prefix caches
Tools []Tool
Context []statefile.Record // statefile.Build output
Params map[string]json.RawMessage
}
Params are the session's vendor fields, see encode.
type Tool ¶
type Tool struct {
Name string
Description string
Schema json.RawMessage // JSON Schema for the arguments object
}
type Turn ¶
type Turn struct {
Assistant bool
Records []statefile.Record
// contains filtered or unexported fields
}
Turns groups the non-system context into alternating turns in API order: user turns hold results, messages, later system records, summaries, and errors; assistant turns hold the blocks one step closed. The step record ends its assistant turn. A step that closed no blocks, a model that said nothing, is no turn at all: every provider rejects an empty assistant turn, and every provider merges the user turns around it.