Packages

A Fair Source multi-agent runtime with deterministic agent scoring and replayable run history.

Current section

Files

Jump to
syntropy lib syntropy_web controllers api graph_controller.ex
Raw

lib/syntropy_web/controllers/api/graph_controller.ex

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 graph view model consumed by API clients and the platform:
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