towerops/lib/towerops_web/channels/agent_socket.ex
Graham McIntire e1b9976219
Add Dialyzer typespecs to WebSocket agent code and Agents context
- Add @spec to AgentSocket callbacks (connect/3, id/1)
- Add @spec to AgentChannel callbacks (join/3, handle_info/2, handle_in/3)
- Add @spec to AgentChannel private function build_jobs_for_agent/1
- Add @spec to Agents.verify_agent_token/1
- Add @spec to Agents.update_agent_token_heartbeat/3
- Add @spec to Agents.list_agent_polling_targets/1

These specs provide strict type checking for the critical WebSocket
agent communication code implemented in this session.
2026-01-17 10:37:27 -06:00

31 lines
901 B
Elixir

defmodule ToweropsWeb.AgentSocket do
@moduledoc """
WebSocket endpoint for remote agent communication.
Agents connect to: ws://server/socket/agent/websocket
Authentication token is sent in the channel join payload.
Uses binary Protocol Buffers encoding for all messages.
"""
use Phoenix.Socket
channel "agent:*", ToweropsWeb.AgentChannel
@impl true
@spec connect(map(), Phoenix.Socket.t(), map()) :: {:ok, Phoenix.Socket.t()}
def connect(_params, socket, _connect_info) do
# Allow all connections - authentication happens at channel join
{:ok, socket}
end
@impl true
@spec id(Phoenix.Socket.t()) :: String.t() | nil
def id(socket) do
# Return nil before authentication (channel join will set agent_token_id)
case Map.get(socket.assigns, :agent_token_id) do
nil -> nil
agent_token_id -> "agent_socket:#{agent_token_id}"
end
end
end