AgentSessionManager.PubSub (AgentSessionManager v0.8.0)

Copy Markdown View Source

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

Summary

Functions

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

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

Functions

event_callback(pubsub, opts \\ [])

@spec event_callback(
  module(),
  keyword()
) :: (map() -> :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(pubsub, opts)

@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".