defmodule SyntropyWeb.Api.HistoryJSON do @moduledoc false alias SyntropyWeb.Api.AgentConnections @spec snapshot(map()) :: map() def snapshot(snapshot) do %{ id: snapshot.id, node_id: Map.get(snapshot, :node_id, "local"), trigger_kind: snapshot.trigger_kind, task_id: snapshot.task_id, proposal_id: snapshot.proposal_id, ranked_agent_ids: snapshot.ranked_agent_ids, inserted_at: DateTime.to_iso8601(snapshot.inserted_at), agents: Enum.map(snapshot.agents, &agent_snapshot/1) } end defp agent_snapshot(agent) do %{ id: agent.id, runtime_id: Map.get(agent, :runtime_id, agent.id), node_id: Map.get(agent, :node_id, "local"), name: agent.name, perspective: agent.perspective, position: agent.position, temporary: agent.temporary, connections: AgentConnections.ordered(agent) } end end