GetSessionStatus returns a lightweight snapshot of the session's current runtime state. Designed for late-joining SSE consumers that need to know the session's state without waiting for the next event transition.
(ctx context.Context, id string)
| 256 | // runtime state. Designed for late-joining SSE consumers that need to know |
| 257 | // the session's state without waiting for the next event transition. |
| 258 | func (sm *SessionManager) GetSessionStatus(ctx context.Context, id string) (*api.SessionStatusResponse, error) { |
| 259 | rs, ok := sm.runtimeSessions.Load(id) |
| 260 | if !ok { |
| 261 | return nil, fmt.Errorf("session %s not found", id) |
| 262 | } |
| 263 | |
| 264 | sess := rs.session |
| 265 | |
| 266 | // Probe streaming state: TryLock succeeds only when no RunStream is |
| 267 | // in progress. Immediately unlock so we don't interfere. |
| 268 | streaming := !rs.streaming.TryLock() |
| 269 | if !streaming { |
| 270 | rs.streaming.Unlock() |
| 271 | } |
| 272 | |
| 273 | return &api.SessionStatusResponse{ |
| 274 | ID: sess.ID, |
| 275 | Title: sess.Title, |
| 276 | Streaming: streaming, |
| 277 | Agent: rs.runtime.CurrentAgentName(ctx), |
| 278 | InputTokens: sess.InputTokens, |
| 279 | OutputTokens: sess.OutputTokens, |
| 280 | NumMessages: len(sess.GetAllMessages()), |
| 281 | }, nil |
| 282 | } |
| 283 | |
| 284 | // GetSessionSnapshot returns the full, self-contained state of a session: its |
| 285 | // stored fields plus, when an active runtime is attached, its live runtime |
no test coverage detected