MingaAgent.SessionManager (Minga v0.1.0)

Copy Markdown View Source

Owns agent session lifecycle independently of any UI.

Maps human-readable session IDs (e.g., "session-1") to session PIDs. Sessions are started via MingaAgent.Supervisor (DynamicSupervisor) and monitored here. When a session dies, the manager broadcasts an :agent_session_stopped event so the Editor (or any subscriber) can react without monitoring PIDs directly.

Summary

Types

An entry in the sessions map.

Internal state of the SessionManager.

Functions

Aborts the current operation on a session by ID.

Returns a specification to start this module under a supervisor.

Looks up the PID for a session ID.

Lists all active sessions as {id, pid, metadata} tuples.

Sends a user prompt to a session by ID.

Looks up the session ID for a PID.

Starts the SessionManager.

Starts a new agent session with a generated human-readable ID.

Stops a session by its human-readable ID.

Stops a session by its PID (looks up the ID internally).

Types

session_entry()

@type session_entry() :: %{pid: pid(), monitor_ref: reference()}

An entry in the sessions map.

state()

@type state() :: %{
  sessions: %{required(String.t()) => session_entry()},
  next_id: pos_integer()
}

Internal state of the SessionManager.

Functions

abort(session_id)

@spec abort(String.t()) :: :ok | {:error, :not_found}

Aborts the current operation on a session by ID.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_session(session_id)

@spec get_session(String.t()) :: {:ok, pid()} | {:error, :not_found}

Looks up the PID for a session ID.

list_sessions()

@spec list_sessions() :: [{String.t(), pid(), MingaAgent.SessionMetadata.t()}]

Lists all active sessions as {id, pid, metadata} tuples.

send_prompt(session_id, prompt)

@spec send_prompt(String.t(), String.t()) :: :ok | {:error, term()}

Sends a user prompt to a session by ID.

session_id_for_pid(pid)

@spec session_id_for_pid(pid()) :: {:ok, String.t()} | {:error, :not_found}

Looks up the session ID for a PID.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the SessionManager.

start_session(opts \\ [])

@spec start_session(keyword()) :: {:ok, String.t(), pid()} | {:error, term()}

Starts a new agent session with a generated human-readable ID.

Returns {:ok, session_id, pid} on success.

stop_session(session_id)

@spec stop_session(String.t()) :: :ok | {:error, :not_found}

Stops a session by its human-readable ID.

stop_session_by_pid(pid)

@spec stop_session_by_pid(pid()) :: :ok | {:error, :not_found}

Stops a session by its PID (looks up the ID internally).