Layr8.Config (layr8 v0.2.5)

Copy Markdown View Source

Configuration for a Layr8 client.

Fields can be supplied explicitly or resolved from environment variables:

  • LAYR8_NODE_URL — WebSocket URL of the cloud-node
  • LAYR8_API_KEY — authentication key
  • LAYR8_AGENT_DID — agent DID (optional; ephemeral DID created on connect if absent)

HTTP(S) URLs are automatically normalized to WebSocket scheme:

  • https://wss://
  • http://ws://

Example

config = Layr8.Config.resolve!(%{node_url: "wss://node.example.com/plugin_socket/websocket", api_key: "secret"})

Summary

Functions

Resolves a config map or struct, filling missing fields from environment variables, normalizing the URL scheme, and validating required fields.

Derives the REST API base URL from a WebSocket URL.

Types

t()

@type t() :: %Layr8.Config{
  agent_did: String.t(),
  api_key: String.t(),
  node_url: String.t()
}

Functions

resolve!(cfg \\ %{})

@spec resolve!(map()) :: t()

Resolves a config map or struct, filling missing fields from environment variables, normalizing the URL scheme, and validating required fields.

Raises Layr8.Error if required fields are missing.

rest_url_from_websocket(ws_url)

@spec rest_url_from_websocket(String.t()) :: String.t()

Derives the REST API base URL from a WebSocket URL.

iex> Layr8.Config.rest_url_from_websocket("wss://node.example.com/plugin_socket/websocket")
"https://node.example.com"

iex> Layr8.Config.rest_url_from_websocket("ws://localhost:4000/plugin_socket/websocket")
"http://localhost:4000"