Documentation
¶
Overview ¶
Package state provides persistent sessions and conversational FSM scenes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachSession ¶
func SessionMiddleware ¶
func SessionMiddleware(repo storage.SessionRepository, ttl time.Duration) middleware.Middleware
SessionMiddleware serializes updates to the same session key within this process. Multi-process stores must provide their own cross-process control.
Types ¶
type FSM ¶
type FSM struct {
// contains filtered or unexported fields
}
FSM registers scenes and routes active sessions to their current step.
func NewFSM ¶
func NewFSM(repo storage.SessionRepository, ttl time.Duration) *FSM
NewFSM creates a scene manager backed by a session repository.
func (*FSM) Middleware ¶
func (f *FSM) Middleware() middleware.Middleware
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene is an ordered conversational flow of named steps.
func (*Scene) CurrentStep ¶
type Session ¶
type Session interface {
Get(key string) any
Set(key string, value any)
Delete(key string)
Values() map[string]any
Save(ctx context.Context) error
}
Session stores mutable scene data and persists it through a repository.
func LoadSession ¶ added in v2.0.2
func LoadSession(ctx context.Context, repo storage.SessionRepository, key string, ttl time.Duration) (Session, error)
LoadSession loads a session, returning storage and decoding failures to the caller.
func NewSession ¶
NewSession is kept for source compatibility. Prefer LoadSession when load failures must be handled before running application code.