Documentation
¶
Overview ¶
Package session provides session event stores and a reusable conformance test suite for validating SessionEventStore implementations.
Index ¶
- func NewFileSessionService[M adk.MessageType](dir string, cfg *FileStoreConfig) (adk.SessionService[M], error)
- func NewInMemorySessionService[M adk.MessageType]() adk.SessionService[M]
- func RunConformanceTests[M adk.MessageType](t *testing.T, factory func(testing.TB) adk.SessionEventStore[M], ...)
- func RunSerializerConformanceTests[M adk.MessageType](t *testing.T, ...)
- type FileStore
- type FileStoreConfig
- type InMemoryStore
- func (s *InMemoryStore[M]) AppendEvents(_ context.Context, req *adk.AppendSessionEventsRequest[M]) (*adk.AppendSessionEventsResult, error)
- func (s *InMemoryStore[M]) Delete(_ context.Context, checkPointID string) error
- func (s *InMemoryStore[M]) Get(_ context.Context, checkPointID string) ([]byte, bool, error)
- func (s *InMemoryStore[M]) LoadEvents(_ context.Context, opts *adk.LoadSessionEventsRequest) (*adk.LoadSessionEventsResult[M], error)
- func (s *InMemoryStore[M]) Set(_ context.Context, checkPointID string, checkPoint []byte) error
- type InMemoryStoreConfig
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 ¶
func (s *FileStore[M]) AppendEvents(_ context.Context, req *adk.AppendSessionEventsRequest[M]) (*adk.AppendSessionEventsResult, error)
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 ¶
func (s *FileStore[M]) LoadEvents(_ context.Context, opts *adk.LoadSessionEventsRequest) (*adk.LoadSessionEventsResult[M], error)
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 ¶
func (s *InMemoryStore[M]) AppendEvents(_ context.Context, req *adk.AppendSessionEventsRequest[M]) (*adk.AppendSessionEventsResult, error)
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]) LoadEvents ¶
func (s *InMemoryStore[M]) LoadEvents(_ context.Context, opts *adk.LoadSessionEventsRequest) (*adk.LoadSessionEventsResult[M], error)
LoadEvents loads events with pagination and direction support.
type InMemoryStoreConfig ¶
type InMemoryStoreConfig struct {
// EventSerializer encodes typed session events before storage. Defaults to
// schema.HumanReadableSerializer.
EventSerializer schema.Serializer
}
InMemoryStoreConfig configures InMemoryStore.