Member Junction
    Preparing search index...

    Server-side lifecycle manager for AIAgentSession records (not the media/socket transport — that arrives in P5). Stateless with respect to the caller: every method takes the request's contextUser and request-scoped IMetadataProvider so all entity operations run under the correct identity/provider and never pin the process-global provider.

    The only in-memory state it holds is a small per-session last-heartbeat-write timestamp map used purely to coalesce Heartbeat writes; it carries no user or provider state across calls.

    Responsibilities:

    • Create — authorize (CanRun), optionally mint a Conversation, persist an Active session.
    • Close — terminal transition; disconnect channels; idempotent.
    • Heartbeat — coalesced LastActiveAt bump; reactivates Idle → Active.
    • MarkIdleActive → Idle transition when the last channel goes quiet.

    P5 will extend CloseSession to also abort any in-flight AIAgentRun (via its cancellation token) and call ClientToolRequestManager.ClearSession(...); those resources don't exist yet at this layer, so close here only reconciles the durable record + channel rows.

    Index

    Constructors

    Methods

    • Close a session (terminal). Sets Status = 'Closed' + ClosedAt = now + CloseReason, then disconnects all of its channel rows. Idempotent: closing an already-Closed session is a no-op that returns true (and never overwrites the original CloseReason). A missing/unloadable session returns false.

      Parameters

      • agentSessionID: string
      • contextUser: UserInfo
      • provider: IMetadataProvider
      • closeReason: SessionCloseReason = 'Explicit'

        Why the session is being closed. Defaults to 'Explicit' so existing call sites (the user-initiated close mutations) stamp the common case without modification; background callers (janitor sweeps, shutdown drain, error teardowns) must pass their reason explicitly. NULL rows remain only for legacy data closed before the column existed.

      • OptionalpreloadedChannels: MJAIAgentSessionChannelEntity[]

      Returns Promise<boolean>

      P5 adds in-flight-run abort + ClientToolRequestManager.ClearSession here.

    • Record activity on a session. Coalesces persisted writes so at most one LastActiveAt update lands per session per HEARTBEAT_MIN_WRITE_INTERVAL_MS; intervening calls return true without touching the DB. Reactivates an Idle session to Active. A Closed session is not reactivated (returns false).

      Parameters

      Returns Promise<boolean>