session

package
v0.1.67 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package session identifies the client session a request belongs to, so the gateway can route one conversation consistently and group its audit 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