Nous.PubSub (nous v0.13.3)
View SourceThin PubSub abstraction for Nous.
Wraps Phoenix.PubSub with graceful fallback when it's not available.
Provides application-level configuration so users don't need to pass
pubsub: MyApp.PubSub to every AgentServer.
Configuration
# In config/config.exs
config :nous, pubsub: MyApp.PubSubUsage
# Subscribe (no-op if PubSub unavailable)
Nous.PubSub.subscribe(MyApp.PubSub, "agent:session_123")
# Broadcast (no-op if PubSub unavailable)
Nous.PubSub.broadcast(MyApp.PubSub, "agent:session_123", {:agent_delta, "Hello"})
# Use configured PubSub
pubsub = Nous.PubSub.configured_pubsub()
Summary
Functions
Build an agent topic for the given session ID.
Build an approval topic for the given session ID.
Checks if PubSub is available (Phoenix.PubSub loaded and a module configured).
Checks if PubSub is available for the given module.
Broadcast a message on a topic.
Returns the application-configured PubSub module.
Build a research topic for the given session ID.
Subscribe the calling process to a topic.
Functions
Build an agent topic for the given session ID.
iex> Nous.PubSub.agent_topic("abc123")
"nous:agent:abc123"
Build an approval topic for the given session ID.
iex> Nous.PubSub.approval_topic("abc123")
"nous:approval:abc123"
@spec available?() :: boolean()
Checks if PubSub is available (Phoenix.PubSub loaded and a module configured).
Checks if PubSub is available for the given module.
Returns true if Phoenix.PubSub is loaded and pubsub is not nil.
Broadcast a message on a topic.
No-op if PubSub is unavailable.
@spec configured_pubsub() :: module() | nil
Returns the application-configured PubSub module.
Reads from Application.get_env(:nous, :pubsub).
Returns nil if not configured.
Build a research topic for the given session ID.
iex> Nous.PubSub.research_topic("abc123")
"nous:research:abc123"
Subscribe the calling process to a topic.
No-op if PubSub is unavailable.