Documentation
¶
Index ¶
- func AttachRecorderHooks(hc *protocol.HandleContext, recorder *ProtocolRecorder, model string, ...)
- type ProtocolRecorder
- func (sr *ProtocolRecorder) BindProvider(provider *typ.Provider, model string, mode obs.RecordMode)
- func (sr *ProtocolRecorder) EnableStreaming()
- func (sr *ProtocolRecorder) RecordError(err error)
- func (sr *ProtocolRecorder) RecordResponse(provider *typ.Provider, model string)
- func (sr *ProtocolRecorder) RecordStreamChunk(eventType string, chunk interface{})
- func (sr *ProtocolRecorder) SetActiveService(provider *typ.Provider, model string)
- func (sr *ProtocolRecorder) SetAssembledResponse(response any)
- func (sr *ProtocolRecorder) SetOriginalRequest(req *obs.RecordRequest)
- func (sr *ProtocolRecorder) SetTransformSteps(steps []string)
- func (sr *ProtocolRecorder) SetTransformedRequest(req *obs.RecordRequest)
- type StreamRecorder
- func (sr *StreamRecorder) Finish(model string, usage *protocol.TokenUsage)
- func (sr *StreamRecorder) RecordError(err error)
- func (sr *StreamRecorder) RecordRawMapEvent(eventType string, event map[string]interface{})
- func (sr *StreamRecorder) RecordResponse(provider *typ.Provider, model string)
- func (sr *StreamRecorder) SetupStreamRecorderInContext(c *gin.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachRecorderHooks ¶
func AttachRecorderHooks(hc *protocol.HandleContext, recorder *ProtocolRecorder, model string, provider *typ.Provider)
AttachRecorderHooks wires a ProtocolRecorder into a native Anthropic stream HandleContext. Raw SSE chunks are mirrored into the recorder's chunk log; an internal assembler synthesises the final *anthropic.Message once the stream completes; completion and error finalise the record.
Types ¶
type ProtocolRecorder ¶
type ProtocolRecorder struct {
// contains filtered or unexported fields
}
ProtocolRecorder captures a single client→tingly-box→provider cycle.
It carries both the scenario-level (client/final) and protocol-level (transformed) request/response pairs, plus optional streaming state. The recorder is mode-driven: which fields are emitted to the sink is decided by RecordMode (set at construction).
Lifecycle:
- EnsureProtocolRecorder at handler entry — captures client request, session, mode.
- Optional: transform pipeline writes SetOriginalRequest / SetTransformedRequest via TransformRecorder.
- For streaming, hooks call EnableStreaming + RecordStreamChunk + SetAssembledResponse.
- RecordResponse (success) or RecordError (failure) emits one *obs.Record.
func GetRecorderFromContext ¶
func GetRecorderFromContext(c *gin.Context) (*ProtocolRecorder, bool)
GetRecorderFromContext returns the ProtocolRecorder stashed in c by EnsureProtocolRecorder, if any. Exported for root callers (failover_dispatch.go, protocol_cross.go — both still Step 7-9 territory) that need to re-bind or inspect the active recorder mid-request.
func NewProtocolRecorder ¶
func NewProtocolRecorder(c *gin.Context, sink *obs.Sink, scenario string, mode obs.RecordMode, body []byte) (*ProtocolRecorder, error)
func (*ProtocolRecorder) BindProvider ¶
func (sr *ProtocolRecorder) BindProvider(provider *typ.Provider, model string, mode obs.RecordMode)
func (*ProtocolRecorder) EnableStreaming ¶
func (sr *ProtocolRecorder) EnableStreaming()
EnableStreaming puts the recorder into streaming mode.
func (*ProtocolRecorder) RecordError ¶
func (sr *ProtocolRecorder) RecordError(err error)
RecordError emits an error record. err may be nil.
func (*ProtocolRecorder) RecordResponse ¶
func (sr *ProtocolRecorder) RecordResponse(provider *typ.Provider, model string)
RecordResponse finalises provider/model and emits a Record to the sink.
func (*ProtocolRecorder) RecordStreamChunk ¶
func (sr *ProtocolRecorder) RecordStreamChunk(eventType string, chunk interface{})
RecordStreamChunk records a single stream chunk.
func (*ProtocolRecorder) SetActiveService ¶
func (sr *ProtocolRecorder) SetActiveService(provider *typ.Provider, model string)
SetActiveService re-binds the recorder to a new provider/model. The failover orchestrator calls this between attempts so records reflect the service currently being attempted. Breaker accounting is owned by the failover loop, not by recording.
func (*ProtocolRecorder) SetAssembledResponse ¶
func (sr *ProtocolRecorder) SetAssembledResponse(response any)
SetAssembledResponse stores the final assembled (post-stream) response. Accepts map, []byte, or any JSON-marshall-able value.
func (*ProtocolRecorder) SetOriginalRequest ¶
func (sr *ProtocolRecorder) SetOriginalRequest(req *obs.RecordRequest)
SetOriginalRequest stores the pre-transform request.
func (*ProtocolRecorder) SetTransformSteps ¶
func (sr *ProtocolRecorder) SetTransformSteps(steps []string)
SetTransformSteps records which transforms were applied.
func (*ProtocolRecorder) SetTransformedRequest ¶
func (sr *ProtocolRecorder) SetTransformedRequest(req *obs.RecordRequest)
SetTransformedRequest stores the post-transform request.
type StreamRecorder ¶
type StreamRecorder struct {
// contains filtered or unexported fields
}
StreamRecorder couples a ProtocolRecorder with a stream assembler so that raw SSE events emitted during protocol conversion are mirrored into both the recorder's chunk log and an assembler that synthesises the final response body once the stream ends.
It backs the gin-context StreamEventRecorder path used by the Responses→Anthropic conversion handlers. Native Anthropic streams instead use AttachRecorderHooks, which relies on the assembler that protocol's HandleContext now owns. Exported (moved from unexported streamRecorder) because root's protocol_cross.go (Step 7 territory) still constructs one directly via NewStreamRecorder and calls its methods.
func NewStreamRecorder ¶
func NewStreamRecorder(recorder *ProtocolRecorder) *StreamRecorder
NewStreamRecorder is the exported constructor for StreamRecorder.
func (*StreamRecorder) Finish ¶
func (sr *StreamRecorder) Finish(model string, usage *protocol.TokenUsage)
Finish carries the converter's final TokenUsage into the assembler so the recorded response has the full shape (input/output + cache_read). When usage is nil or empty, any in-stream usage harvested via RecordRawMapEvent is used as a fallback.
func (*StreamRecorder) RecordError ¶
func (sr *StreamRecorder) RecordError(err error)
func (*StreamRecorder) RecordRawMapEvent ¶
func (sr *StreamRecorder) RecordRawMapEvent(eventType string, event map[string]interface{})
RecordRawMapEvent feeds a generic map-encoded SSE event into both the assembler (best-effort) and the recorder's chunk log. Updates the usage counters from message_delta events.
func (*StreamRecorder) RecordResponse ¶
func (sr *StreamRecorder) RecordResponse(provider *typ.Provider, model string)
func (*StreamRecorder) SetupStreamRecorderInContext ¶
func (sr *StreamRecorder) SetupStreamRecorderInContext(c *gin.Context)