@@ -6,6 +6,7 @@ local sessions = {}
66local active_id = nil
77local counter = 0
88
9+ --- Create a new session from the given spec, store it, and set it as active.
910--- @param spec codex.SessionSpec
1011--- @return string id
1112function M .create (spec )
@@ -25,12 +26,14 @@ function M.create(spec)
2526 return id
2627end
2728
29+ --- Look up a session by its id.
2830--- @param id string
2931--- @return codex.Session | nil
3032function M .get (id )
3133 return sessions [id ]
3234end
3335
36+ --- Return the currently active session, or nil if none is active.
3437--- @return codex.Session | nil
3538function M .get_active ()
3639 if active_id then
@@ -39,12 +42,14 @@ function M.get_active()
3942 return nil
4043end
4144
45+ --- Set the active session id; pass nil to clear the active session.
4246--- @param id string | nil
4347--- @return nil
4448function M .set_active (id )
4549 active_id = id
4650end
4751
52+ --- Mark a session as no longer alive and clear it from active if it was active.
4853--- @param id string
4954--- @return nil
5055function M .mark_dead (id )
@@ -56,6 +61,7 @@ function M.mark_dead(id)
5661 end
5762end
5863
64+ --- Remove a session from the store entirely and clear it from active if needed.
5965--- @param id string
6066--- @return nil
6167function M .remove (id )
@@ -65,6 +71,7 @@ function M.remove(id)
6571 end
6672end
6773
74+ --- Return a list of all stored sessions.
6875--- @return codex.Session[]
6976function M .list ()
7077 --- @type codex.Session[]
@@ -75,6 +82,7 @@ function M.list()
7582 return result
7683end
7784
85+ --- Clear all sessions, the active id, and reset the id counter.
7886--- @return nil
7987function M .reset ()
8088 sessions = {}
0 commit comments