session

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 18 Imported by: 0 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 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

View Source
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

func NewDetector(rules []Rule, autoDetect bool) *Detector

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.

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.

func BuiltinRules

func BuiltinRules() []Rule

BuiltinRules returns a copy of the default registry.

Jump to

Keyboard shortcuts

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