# `ADK.Phoenix.ChatLive`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/phoenix/chat_live.ex#L2)

Production-quality Phoenix LiveView chat interface for ADK agents.

Features:
- **Streaming display** — tokens appear as they arrive via session subscribers
- **Typing indicators** — visual feedback while the agent is thinking
- **Tool call visualization** — collapsible display of tool calls and responses
- **Agent transfer display** — shows when conversations transfer between agents
- **Message types** — user, agent, system, error messages with distinct styling
- **Markdown rendering** — basic markdown support in agent responses
- **LiveView streams** — efficient DOM updates (no deprecated phx-update=append)
- **Reconnection handling** — graceful recovery from disconnects

## Usage

### Direct mount via router

    live_session :chat, session: %{"agent" => &MyApp.Agents.assistant/0, "app_name" => "my_app"} do
      live "/chat", ADK.Phoenix.ChatLive
    end

### Wrapper LiveView (more control)

    defmodule MyAppWeb.ChatLive do
      use MyAppWeb, :live_view

      def mount(_params, _session, socket) do
        {:ok, ADK.Phoenix.ChatLive.init_chat(socket,
          agent: MyApp.Agents.assistant(),
          app_name: "my_app"
        )}
      end

      defdelegate handle_event(event, params, socket), to: ADK.Phoenix.ChatLive
      defdelegate handle_info(msg, socket), to: ADK.Phoenix.ChatLive
      defdelegate render(assigns), to: ADK.Phoenix.ChatLive
    end

## Styling

All elements have CSS classes (`.adk-chat-*`) for custom styling.
Inline styles provide a complete default look without requiring Tailwind or external CSS.
Override with your own CSS targeting the class names.

# `init_chat`

```elixir
@spec init_chat(
  Phoenix.LiveView.Socket.t(),
  keyword()
) :: Phoenix.LiveView.Socket.t()
```

Initialize chat assigns on a socket.

## Options
- `:agent` — the ADK agent (struct or 0-arity function)
- `:app_name` — application name for session namespacing
- `:user_id` — user identifier (default: "anonymous")
- `:session_id` — session identifier (auto-generated if omitted)

---

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