defmodule SyntropyWeb.Api.GraphController do use SyntropyWeb, :controller alias Syntropy.{ClusterInventory, TaskScheduler} alias SyntropyWeb.GraphViewModel @doc """ Live lattice graph in the shared `ReplayGraphModel` presentation contract. Returns the same view model the mission-control LiveView renders: nodes with scalar positions and selection/activity flags, plus weighted co-interaction edges. """ @spec show(Plug.Conn.t(), map()) :: Plug.Conn.t() def show(conn, _params) do agents = ClusterInventory.cluster_agents() active_agent_ids = TaskScheduler.active_tasks_snapshot() |> ClusterInventory.busy_runtime_ids() |> MapSet.to_list() latest_task_result = List.first(TaskScheduler.recent(1)) graph = GraphViewModel.from_live(agents, selected_agent_ids: GraphViewModel.task_selected_runtime_ids(latest_task_result), active_agent_ids: active_agent_ids, task_id: latest_task_result && latest_task_result.task_id ) json(conn, %{data: graph}) end end