ReqManagedAgents.Host.SessionServer (req_managed_agents_host v0.1.0)

Copy Markdown View Source

Per-external-id GenServer driving one turn at a time through ReqManagedAgents.Session.run/2.

Fresh (Locator has no session_id for this external id): opens with no :session_id opt; the provider mints one and Session.run/2 returns it, which is persisted into a Locator.Record. Reattach (Locator already has a session_id): passes it back in as :session_id, so the provider consolidates into the existing upstream session and the request_response reattach seam delivers the message as a fresh user.message rather than a new kickoff. Either way a turn is exactly one Session.run/2 call — no Client, no hand-sent events.

Idle for config.idle_timeout_ms after replying to a turn: stops normally. The Locator row (and thus the upstream session id) survives the stop — the next deliver/2 for the same external id starts a fresh server and reattaches instead of minting a new upstream session.

Summary

Functions

Run one turn: deliver message and block for the resulting SessionResult.

Start the server for external_id, registered under via/1.

The Registry-backed name a server for external_id runs under.

Types

t()

@type t() :: %ReqManagedAgents.Host.SessionServer{
  config: ReqManagedAgents.Host.Config.t(),
  external_id: ReqManagedAgents.Host.Locator.external_id(),
  idle_ref: reference() | nil
}

Functions

deliver(server, message)

@spec deliver(GenServer.server(), String.t()) ::
  {:ok, ReqManagedAgents.SessionResult.t()} | {:error, term()}

Run one turn: deliver message and block for the resulting SessionResult.

start_link(arg)

Start the server for external_id, registered under via/1.

via(external_id)

The Registry-backed name a server for external_id runs under.