GenAI.Graph.NodeProtocol protocol (GenAI Core v0.1.1)
Protocol for managing Graph Nodes.
Link to this section Summary
Functions
Obtain the description of a graph node.
Obtain the description of a graph node, or return a default value if the description is nil.
Obtain the handle of a graph node.
Obtain the handle of a graph node, or return a default value if the handle is nil.
Obtain the id of a graph node.
Obtain inbound links of a graph node.
Obtain the name of a graph node.
Obtain the name of a graph node, or return a default value if the name is nil.
Obtain outbound links of a graph node.
Register a link with the graph node.
Ensure the graph node has an id, generating one if necessary.
Link to this section Types
@type t() :: term()
All the types that implement this protocol.
Link to this section Functions
description(graph_node)
@spec description(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.description(), GenAI.Types.details())
Obtain the description of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{description: "B"}
...> GenAI.Graph.NodeProtocol.description(node)
{:ok, "B"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{description: nil}
...> GenAI.Graph.NodeProtocol.description(node)
{:error, {:description, :is_nil}}
description(graph_node, default)
@spec description( graph_node :: GenAI.Types.Graph.graph_node(), default :: GenAI.Types.description() ) :: GenAI.Types.result(GenAI.Types.description(), GenAI.Types.details())
Obtain the description of a graph node, or return a default value if the description is nil.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{description: "B"}
...> GenAI.Graph.NodeProtocol.description(node, "default")
{:ok, "B"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{description: nil}
...> GenAI.Graph.NodeProtocol.description(node, "default")
{:ok, "default"}
handle(graph_node)
@spec handle(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.handle(), GenAI.Types.details())
Obtain the handle of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{handle: :foo}
...> GenAI.Graph.NodeProtocol.handle(node)
{:ok, :foo}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{handle: nil}
...> GenAI.Graph.NodeProtocol.handle(node)
{:error, {:handle, :is_nil}}
handle(graph_node, default)
@spec handle( graph_node :: GenAI.Types.Graph.graph_node(), default :: GenAI.Types.handle() ) :: GenAI.Types.result(GenAI.Types.handle(), GenAI.Types.details())
Obtain the handle of a graph node, or return a default value if the handle is nil.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{handle: :foo}
...> GenAI.Graph.NodeProtocol.handle(node, :default)
{:ok, :foo}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{handle: nil}
...> GenAI.Graph.NodeProtocol.handle(node, :default)
{:ok, :default}
id(graph_node)
@spec id(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node_id(), GenAI.Types.details())
Obtain the id of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{id: UUID.uuid4()}
...> GenAI.Graph.NodeProtocol.id(node)
{:ok, node.id}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{id: nil}
...> GenAI.Graph.NodeProtocol.id(node)
{:error, {:id, :is_nil}}
inbound_links(graph_node, graph, options)
@spec inbound_links( graph_node :: GenAI.Types.Graph.graph_node(), graph :: GenAI.Types.Graph.graph(), options :: map() ) :: {:ok, [GenAI.Types.Graph.graph_link_id()]} | {:error, term()}
Obtain inbound links of a graph node.
name(graph_node)
@spec name(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.name(), GenAI.Types.details())
Obtain the name of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{name: "A"}
...> GenAI.Graph.NodeProtocol.name(node)
{:ok, "A"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{name: nil}
...> GenAI.Graph.NodeProtocol.name(node)
{:error, {:name, :is_nil}}
name(graph_node, default)
@spec name( graph_node :: GenAI.Types.Graph.graph_node(), default :: GenAI.Types.name() ) :: GenAI.Types.result(GenAI.Types.name(), GenAI.Types.details())
Obtain the name of a graph node, or return a default value if the name is nil.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{name: "A"}
...> GenAI.Graph.NodeProtocol.name(node, "default")
{:ok, "A"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{name: nil}
...> GenAI.Graph.NodeProtocol.name(node, "default")
{:ok, "default"}
outbound_links(graph_node, graph, options)
@spec outbound_links( graph_node :: GenAI.Types.Graph.graph_node(), graph :: GenAI.Types.Graph.graph(), options :: map() ) :: {:ok, [GenAI.Types.Graph.graph_link_id()]} | {:error, term()}
Obtain outbound links of a graph node.
register_link(graph_node, graph, link, options)
@spec register_link( graph_node :: GenAI.Types.Graph.graph_node(), graph :: GenAI.Types.Graph.graph(), link :: GenAI.Types.Graph.graph_link(), options :: map() ) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
Register a link with the graph node.
examples
Examples
iex> n1 = UUID.uuid5(:oid, "node-1")
...> n2 = UUID.uuid5(:oid, "node-2")
...> n = %GenAI.Graph.Node{id: n1}
...> link = GenAI.Graph.Link.new(n1, n2)
...> link_id = link.id
...> {:ok, updated} = GenAI.Graph.NodeProtocol.register_link(n, %{}, link, nil)
...> updated
%GenAI.Graph.Node{outbound_links: %{default: [^link_id]}} = updated
with_id(graph_node)
@spec with_id(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
Ensure the graph node has an id, generating one if necessary.
examples
Examples
when-already-set
When Already Set
iex> node = %GenAI.Graph.Node{id: UUID.uuid4()}
...> {:ok, node2} = GenAI.Graph.NodeProtocol.with_id(node)
...> %{was_nil: is_nil(node.id), is_nil: is_nil(node2.id), id_change: node.id != node2.id}
%{was_nil: false, is_nil: false, id_change: false}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{id: nil}
...> {:ok, node2} = GenAI.Graph.NodeProtocol.with_id(node)
...> %{was_nil: is_nil(node.id), is_nil: is_nil(node2.id), id_change: node.id != node2.id}
%{was_nil: true, is_nil: false, id_change: true}