# `AgentSessionManager.PubSub`
[🔗](https://github.com/nshkrdotcom/agent_session_manager/blob/v0.8.0/lib/agent_session_manager/pubsub.ex#L2)

Convenience functions for PubSub integration with AgentSessionManager.

Provides helpers for creating PubSub-aware event callbacks and for
subscribing to session/run topics.

## Event Callback Usage

    callback = AgentSessionManager.PubSub.event_callback(
      MyApp.PubSub,
      scope: :session
    )

    SessionManager.run_once(store, adapter, input,
      event_callback: callback
    )

## Subscription Usage

    AgentSessionManager.PubSub.subscribe(MyApp.PubSub, session_id: "ses_123")

    # In a LiveView handle_info:
    def handle_info({:asm_event, session_id, event}, socket) do
      # ...
    end

# `event_callback`

```elixir
@spec event_callback(
  module(),
  keyword()
) :: (map() -&gt; :ok | {:error, term()})
```

Returns a 1-arity event callback that broadcasts each event to PubSub.

This function returns a closure suitable for the `:event_callback` option
of `SessionManager.execute_run/4` or `SessionManager.run_once/4`.

## Options

  * `:prefix` - Topic prefix. Default `"asm"`.
  * `:scope` - `:session`, `:run`, or `:type`. Default `:session`.
  * `:message_wrapper` - Broadcast tuple tag. Default `:asm_event`.
  * `:topic` - Override with a static topic string.

# `subscribe`

```elixir
@spec subscribe(
  module(),
  keyword()
) :: :ok | {:error, term()}
```

Subscribes the calling process to ASM events on the given topic.

## Options

  * `:session_id` - Subscribe to all events for this session.
  * `:session_id` + `:run_id` - Subscribe to events for a specific run.
  * `:topic` - Subscribe to an explicit topic string.
  * `:prefix` - Topic prefix. Default `"asm"`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
