ExMCP.ACP.Adapters.ZCode.Sessions (ex_mcp v1.3.0)

Copy Markdown View Source

Pure session helpers for the ZCode ACP adapter.

ZCode sessions are keyed by the sessionId string returned by session/create or session/resume. Each session tracks the active turn (for cancellation), accumulated text/usage, and the current mode and model.

Summary

Functions

Returns the current (only) session ID, or nil.

Fetches a session from state by ID.

Fetches a session ID from ACP params.

Builds a session from a ZCode snapshot (as returned by session/create, session/resume, or embedded in event notifications).

Resolves a session ID from notification params.

Resets per-prompt accumulators on a session.

Converts a ZCode session list entry to an ACP SessionInfo map.

Types

adapter_state()

@type adapter_state() :: %{
  :sessions => %{required(String.t()) => session()},
  :model => any(),
  :mode_id => any(),
  optional(any()) => any()
}

session()

@type session() :: map()

store_state()

@type store_state() :: %{
  :sessions => %{required(String.t()) => session()},
  optional(any()) => any()
}

Functions

current_id(arg1)

@spec current_id(store_state()) :: String.t() | nil

Returns the current (only) session ID, or nil.

empty(session_id, state)

@spec empty(String.t() | nil, adapter_state()) :: session()

fetch(state, session_id)

@spec fetch(store_state(), String.t()) :: {:ok, session()} | {:error, String.t()}

Fetches a session from state by ID.

fetch_id(arg1)

@spec fetch_id(map()) :: {:ok, String.t()} | {:error, String.t()}

Fetches a session ID from ACP params.

from_snapshot(session_id, snapshot, state)

@spec from_snapshot(String.t(), map(), adapter_state()) :: session()

Builds a session from a ZCode snapshot (as returned by session/create, session/resume, or embedded in event notifications).

id_from_params(params, state)

@spec id_from_params(map(), store_state()) :: String.t() | nil

Resolves a session ID from notification params.

put(state, session_id, session)

@spec put(store_state(), String.t() | nil, session()) :: store_state()

reset_prompt_accumulators(session, acp_id)

@spec reset_prompt_accumulators(session(), term()) :: session()

Resets per-prompt accumulators on a session.

to_acp_session_info(session)

@spec to_acp_session_info(map()) :: map()

Converts a ZCode session list entry to an ACP SessionInfo map.

update(state, session_id, fun)

@spec update(adapter_state(), String.t() | nil, (session() -> session())) ::
  adapter_state()