types

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 2 Imported by: ? 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 types holds the session contracts.

Index

Constants

View Source
const (
	// DefaultSessionTTL is the default time-to-live for sessions (2 hours)
	DefaultSessionTTL = 2 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

type Session interface {
	ID() string
	Type() SessionType
	CreatedAt() time.Time
	UpdatedAt() time.Time

	// Data and metadata methods
	GetData() interface{}
	SetData(data interface{})
	GetMetadata() map[string]string
	GetMetadataValue(key string) (string, bool)
	SetMetadata(key, value string)
}

Session interface defines the contract for all session types

type SessionType

type SessionType string

SessionType represents the type of session

const (
	// SessionTypeMCP represents a standard MCP session
	SessionTypeMCP SessionType = "mcp"
	// SessionTypeSSE represents an SSE (Server-Sent Events) session
	SessionTypeSSE SessionType = "sse"
	// SessionTypeStreamable represents a streamable HTTP session
	SessionTypeStreamable SessionType = "streamable"
)

type Storage

type Storage interface {
	// Create atomically inserts a session, returning ErrSessionAlreadyExists on collision.
	Create(ctx context.Context, session Session) error

	// Store creates or updates a session in the storage backend.
	// If the session already exists, it will be overwritten.
	Store(ctx context.Context, session Session) error

	// Load retrieves a session by ID from the storage backend.
	// Returns ErrSessionNotFound if the session doesn't exist.
	//
	// Implementations should refresh their backend's eviction TTL on every Load to
	// prevent active sessions from expiring between reads. For Redis, this is done via
	// GETEX. For LocalStorage, Load updates a storage-owned last-access timestamp so
	// that DeleteExpired does not evict sessions that are actively being accessed.
	Load(ctx context.Context, id string) (Session, error)

	// LoadIfOwner atomically validates expectedOwner against the current record,
	// refreshes its eviction TTL only on a match, and returns that same record.
	// It returns ErrSessionNotFound when the record is absent or has another owner.
	LoadIfOwner(ctx context.Context, id, expectedOwner string) (Session, error)

	// LoadMetadata retrieves authoritative session metadata without refreshing the
	// session's eviction TTL or exposing a live session object.
	LoadMetadata(ctx context.Context, id string) (map[string]string, error)

	// StoreIfOwner replaces a session only when the current record has expectedOwner.
	// It returns false without modifying the record when it is absent or has another owner.
	StoreIfOwner(ctx context.Context, session Session, expectedOwner string) (bool, error)

	// Delete removes a session from the storage backend.
	// It is not an error if the session doesn't exist.
	Delete(ctx context.Context, id string) error

	// DeleteIfOwner removes a session only when its current owner is expectedOwner.
	// It returns false without modifying the record when it is absent or has another owner.
	DeleteIfOwner(ctx context.Context, id, expectedOwner string) (bool, error)

	// DeleteExpired removes all sessions that haven't been updated since the given time.
	// This is used by the cleanup routine to remove stale sessions.
	DeleteExpired(ctx context.Context, before time.Time) error

	// Close performs cleanup of the storage backend.
	// For local storage, this clears all sessions. For remote storage, it closes connections.
	Close() error
}

Storage defines the minimal interface for session storage backends. This interface is designed to be simple and efficient, supporting both local in-memory storage and distributed storage backends like Redis/Valkey.

Jump to

Keyboard shortcuts

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