Documentation
¶
Overview ¶
Package callrecord encodes model call evidence and rebuilds exact requests. Stores retain opaque bodies; this package owns their deterministic JSON v2 format.
Index ¶
- Variables
- func BuildRequest(ctx context.Context, store runstore.Store, scope string, req *model.Request, ...) (RequestParts, MessageBytes, error)
- func DecodeMessage(data []byte) (*model.Message, error)
- func DecodeRequest(data []byte) (*model.Request, error)
- func DecodeResponse(data []byte) (*model.Response, error)
- func Encode(value any) ([]byte, error)
- func Rebuild(ctx context.Context, store runstore.Store, scope string, started Started, ...) (*model.Request, error)
- func RequestDigest(req *model.Request) (runstore.Hash, error)
- func SnapshotMessages(messages []*model.Message) ([]*model.Message, error)
- type ActivityKind
- type CallError
- type Completion
- type MessageBytes
- type MessageSegment
- type Params
- type RequestParts
- type Started
- type ViewLoader
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRequestMismatch means the rebuilt request differs from the recorded request. ErrRequestMismatch = errors.New("callrecord request rebuild mismatch") )
Functions ¶
func BuildRequest ¶
func BuildRequest(ctx context.Context, store runstore.Store, scope string, req *model.Request, ref index.ViewRef, view []*model.Message) (RequestParts, MessageBytes, error)
BuildRequest stores content, encodes spans against the pre-policy view, and verifies the rebuild. Unstable messages and a mismatching rebuild use hashes.
func DecodeMessage ¶
DecodeMessage restores a recorded message while preserving exact dynamic numeric tokens.
func DecodeRequest ¶
DecodeRequest restores an exported request without a store or view renderer. Dynamic message and schema values retain exact numeric tokens, including integers above 2^53. This is the decoder for self-contained RunRecord exports.
func DecodeResponse ¶
DecodeResponse restores recorded response content through the exact message decoder. Dynamic metadata and tool inputs retain numeric precision, and tool call payloads retain their original bytes. A JSON null response returns nil.
func Encode ¶
Encode returns deterministic JSON v2, preserving numeric tokens and durations. Reordering raw objects also sorts maps emitted by Message.MarshalJSON.
func Rebuild ¶
func Rebuild(ctx context.Context, store runstore.Store, scope string, started Started, load ViewLoader) (*model.Request, error)
Rebuild resolves all parts and verifies the full exported request encoding. The unexported completion validator is intentionally outside this format.
func RequestDigest ¶
RequestDigest computes the verification-only hash of the canonical request. The complete encoding is never stored as addressed content.
func SnapshotMessages ¶
SnapshotMessages owns the exact encoded view before history policy can mutate it. It preserves dynamic numeric tokens without imposing model-request bounds on a view from which the planner may select only a small subset.
Types ¶
type ActivityKind ¶
type ActivityKind string
ActivityKind identifies the activity that owns a model call.
const ( // ActivityPlanner identifies planner calls, including auxiliary calls. ActivityPlanner ActivityKind = "planner" // ActivitySummarize reserves the summarizer activity kind for K15. ActivitySummarize ActivityKind = "summarize" )
type Completion ¶
type Completion struct {
Response *runstore.Hash `json:"response"`
Error *CallError `json:"error"`
Usage model.TokenUsage `json:"usage"`
Latency time.Duration `json:"latency"`
Facts *contextmeasure.RequestFacts `json:"facts"`
}
Completion is the terminal outcome, written after storing any response.
func DecodeCompletion ¶
func DecodeCompletion(data []byte) (Completion, error)
DecodeCompletion restores a completion body, including nanosecond latency.
type MessageBytes ¶
MessageBytes measures encoded request messages inside and outside the view. Counts include repetitions; a hash segment contributes outside bytes.
type MessageSegment ¶
type MessageSegment struct {
ViewFrom int `json:"view_from,omitzero"`
ViewTo int `json:"view_to,omitzero"`
Hash runstore.Hash `json:"hash,omitzero"`
}
MessageSegment is either a zero-based half-open view span or one message hash. A nonempty Hash requires both positions to be zero.
type Params ¶
type Params struct {
RunID string `json:"run_id"`
Temperature float32 `json:"temperature"`
ToolChoice *model.ToolChoice `json:"tool_choice"`
MaxTokens int `json:"max_tokens"`
StructuredOutput *model.StructuredOutput `json:"structured_output"`
Stream bool `json:"stream"`
Thinking *model.ThinkingOptions `json:"thinking"`
Cache *model.CacheOptions `json:"cache"`
}
Params contains every request field outside messages, tools and provenance.
type RequestParts ¶
type RequestParts struct {
System runstore.Hash `json:"system"`
Tools runstore.Hash `json:"tools"`
View *index.ViewRef `json:"view"`
Messages []MessageSegment `json:"messages"`
Params runstore.Hash `json:"params"`
// Request is the canonical verification digest, not stored content.
Request runstore.Hash `json:"request"`
}
RequestParts names the request content and its ordered message segments. View is the committed reference used by spans, or nil when no spans exist.
type Started ¶
type Started struct {
Key runstore.CallKey `json:"key"`
Activity ActivityKind `json:"activity"`
TurnID string `json:"turn_id"`
Step int `json:"step"`
Request RequestParts `json:"request"`
Started time.Time `json:"started"`
Model string `json:"model"`
ModelID string `json:"model_id"`
Class model.ModelClass `json:"class"`
Context string `json:"context"`
Prompts []prompt.PromptRef `json:"prompts"`
}
Started is the immutable request and identity written before sending. Step is the planner step; TurnID remains the conversational turn.
func DecodeStarted ¶
DecodeStarted restores a started body using the codec's duration options.