session

package
v0.10.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package session provides session event stores and a reusable conformance test suite for validating SessionEventStore implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileSessionService

func NewFileSessionService[M adk.MessageType](dir string, cfg *FileStoreConfig) (adk.SessionService[M], error)

NewFileSessionService creates a local, process-scoped service backed by FileStore.

func NewInMemorySessionService

func NewInMemorySessionService[M adk.MessageType]() adk.SessionService[M]

NewInMemorySessionService creates a local, process-scoped session service.

func RunConformanceTests

func RunConformanceTests[M adk.MessageType](
	t *testing.T,
	factory func(testing.TB) adk.SessionEventStore[M],
	makeMessage func(content string) M,
)

RunConformanceTests validates the SessionEventStore contract shared by provider-facing session persistence implementations.

The contract assumes single-writer-per-session: tests do NOT exercise concurrent AppendEvents calls for the same sessionID.

func RunSerializerConformanceTests

func RunSerializerConformanceTests[M adk.MessageType](
	t *testing.T,
	factory func(testing.TB, schema.Serializer) adk.SessionEventStore[M],
	makeMessage func(content string) M,
)

RunSerializerConformanceTests validates that a concrete SessionEventStore implementation honors its implementation-local serializer configuration.

Types

type FileStore

type FileStore[M adk.MessageType] struct {
	// contains filtered or unexported fields
}

FileStore is a process-local, file-backed implementation of adk.SessionEventStore. Each session is stored as one event log file under the configured directory:

<root>/<url.PathEscape(sessionID)>.evlog

Each line is formatted as: <EventID>\t<Kind>\t<Data>\n where Data is the raw serialized bytes written directly to the line.

IMPORTANT: FileStore requires that serialized event data does NOT contain raw newline (\n) or carriage-return (\r) characters, because these would corrupt the line-oriented file format. The default HumanReadableSerializer (compact JSON) satisfies this constraint. Serializers that may emit \n or \r in their output (e.g. GobSerializer, raw protobuf) are NOT compatible with FileStore — use InMemoryStore or a custom store implementation instead. AppendEvents will return an error if Data contains \n or \r.

FileStore does not implement CheckPointStore; runner checkpoints should use a dedicated checkpoint store.

FileStore synchronizes access within the current process. It does not provide cross-process write safety.

func NewFileStore

func NewFileStore[M adk.MessageType](dir string, cfg *FileStoreConfig) (*FileStore[M], error)

NewFileStore creates a file-backed SessionService rooted at dir.

func (*FileStore[M]) AppendEvents

AppendEvents appends events to the session's event log.

Each SessionEvent.EventID MUST be non-empty. The expected tail and event append are validated under the same process-local lock. Duplicate event IDs are accepted only for exact batch replay after a successful prior append.

func (*FileStore[M]) LoadEvents

LoadEvents loads events with pagination and direction support.

type FileStoreConfig

type FileStoreConfig struct {
	// EventSerializer encodes typed session events before storage. Defaults to
	// schema.HumanReadableSerializer. Output must not contain raw CR/LF bytes.
	EventSerializer schema.Serializer
}

FileStoreConfig configures FileStore.

type InMemoryStore

type InMemoryStore[M adk.MessageType] struct {
	// contains filtered or unexported fields
}

InMemoryStore is a thread-safe, in-memory implementation of adk.SessionEventStore and CheckPointStore (with Delete support). Suitable for testing and single-process deployments where durability is not required.

func NewInMemoryStore

func NewInMemoryStore[M adk.MessageType](cfg *InMemoryStoreConfig) *InMemoryStore[M]

NewInMemoryStore creates a new InMemoryStore.

func (*InMemoryStore[M]) AppendEvents

AppendEvents appends events to the session's event log.

func (*InMemoryStore[M]) Delete

func (s *InMemoryStore[M]) Delete(_ context.Context, checkPointID string) error

Delete removes a checkpoint.

func (*InMemoryStore[M]) Get

func (s *InMemoryStore[M]) Get(_ context.Context, checkPointID string) ([]byte, bool, error)

Get retrieves a checkpoint value. Returns an independent copy.

func (*InMemoryStore[M]) LoadEvents

LoadEvents loads events with pagination and direction support.

func (*InMemoryStore[M]) Set

func (s *InMemoryStore[M]) Set(_ context.Context, checkPointID string, checkPoint []byte) error

Set stores a checkpoint value.

type InMemoryStoreConfig

type InMemoryStoreConfig struct {
	// EventSerializer encodes typed session events before storage. Defaults to
	// schema.HumanReadableSerializer.
	EventSerializer schema.Serializer
}

InMemoryStoreConfig configures InMemoryStore.

Jump to

Keyboard shortcuts

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