Macro for integrating A2UI into a Phoenix LiveView.
Add use A2UI.Live to your LiveView module to get:
@a2ui_surfacesassign initialized viaon_mount- Automatic handling of
{:a2ui_message, msg}info messages - Automatic handling of
a2ui_actionanda2ui_input_changeevents - A
handle_a2ui_action/3callback for your action logic
Example
defmodule MyAppWeb.DemoLive do
use MyAppWeb, :live_view
use A2UI.Live
def mount(_params, _session, socket) do
# connect to an agent and start receiving messages
{:ok, socket}
end
@impl A2UI.Live
def handle_a2ui_action(action, metadata, socket) do
# handle user actions from A2UI components
{:noreply, socket}
end
end
Summary
Callbacks
@callback handle_a2ui_action( action :: A2UI.Protocol.Messages.Action.t(), metadata :: map(), socket :: Phoenix.LiveView.Socket.t() ) :: {:noreply, Phoenix.LiveView.Socket.t()}
@callback handle_a2ui_error( error :: A2UI.Protocol.Messages.Error.t(), metadata :: map(), socket :: Phoenix.LiveView.Socket.t() ) :: {:noreply, Phoenix.LiveView.Socket.t()}