Documentation
¶
Overview ¶
Package session identifies the client session a request belongs to, so the gateway can route one conversation consistently and group its request log entries.
Index ¶
Constants ¶
const ( SourceHeader = "header" SourceBody = "body" // TransformSessionUUID extracts a session UUID from Anthropic // metadata.user_id values. Claude Code sends either a JSON object string // with a "session_id" field or the legacy "user_<hash>_…_session_<uuid>" // form; both embed the session UUID this transform returns. TransformSessionUUID = "session-uuid" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector resolves the session id for a request. Explicit header rules win over body rules, which win over content-based auto-detection.
func NewDetector ¶
NewDetector builds a Detector from an ordered rule list. Rules keep their relative order within each source; header rules are always evaluated first.
func NewDetectorFromConfig ¶
func NewDetectorFromConfig(cfg config.SessionConfig) *Detector
NewDetectorFromConfig builds the request session detector from application config. Returns nil when session keeping is disabled, which downstream consumers treat as "no session".
func (*Detector) Detect ¶
func (d *Detector) Detect(snapshot *core.RequestSnapshot, userPath string) string
Detect returns the stable session id for the captured request, or "" when the request carries no session signal. Explicit client-provided ids are scoped by user path so no caller-controlled value can collide across tenants.
func (*Detector) DetectChained ¶ added in v0.2.10
func (d *Detector) DetectChained(ctx context.Context, snapshot *core.RequestSnapshot, userPath string, previous PreviousSession) string
DetectChained is Detect for a caller that can resolve previous_response_id. A Responses follow-up resends only its new input, so nothing in it is stable across turns: without an explicit signal it takes the session of the response it continues, and falls back to content detection when previous knows none.
type PreviousSession ¶ added in v0.2.10
PreviousSession returns the session of the stored response a Responses request continues, or "" when the caller may not inherit one.
type Rule ¶
type Rule struct {
// Source is SourceHeader or SourceBody.
Source string
// Header is the HTTP header name to read (Source == SourceHeader).
Header string
// BodyPath is the gjson path into the JSON request body (Source == SourceBody).
BodyPath string
// Transform optionally post-processes the raw value; an empty result means
// the rule did not match. Empty string uses the value as-is.
Transform string
}
Rule identifies where a client session id lives in a request.