Wardrik. Orgs behaviour
(wardrik v0.1.0-rc.1)
Copy Markdown
Gives each org its own settings, alongside the deployment's. See Wardrik.OrgSettings.
Wardrik.start_link(name: MyApp.AgentRuntime, orgs: {MyApp.Orgs, []})
defmodule MyApp.Orgs do
@behaviour Wardrik.Orgs
@impl true
def settings(org, _config) do
plan = MyApp.Billing.plan!(org)
{:ok, %Wardrik.OrgSettings{ceilings: %{"plan" => [usd: plan.usd, per: :month]}}}
end
endAn agent's org is the first part of its ID: acme for acme/@maria/assistant.
Wardrik reads an org's settings each time one of its agents starts, wakes or is defined. To
apply new settings to awake agents, call Wardrik.refresh/2. Invalid settings stop the agent
from starting, with the reason.
For an org that doesn't exist, return an error:
{:error, Wardrik.Error.new(:not_found, "There's no org globex here.")}Its agents then can't start or be defined, and no secrets, servers or tokens can be stored for it.
Summary
Callbacks
Returns org's settings, or an error if it doesn't exist.
Functions
Returns the agent id's defaults: the deployment's, overridden by its org's.
Returns opts with the org's policy and ceilings added.
Returns :ok if org exists, or the error settings/2 returns.
Returns the org of the agent id.
Applies the org's current settings to its awake agents. Returns a line for each failure.
Returns org's settings, with each policy and ceiling built, or an error if they're invalid.
Returns what the org's agents have spent against each ceiling, by name. See
Wardrik.Ceiling.spent/3.
Returns wardrik with the org's policies and defaults merged in.
Callbacks
@callback settings(org :: String.t(), config :: term()) :: {:ok, Wardrik.OrgSettings.t()} | {:error, term()}
Returns org's settings, or an error if it doesn't exist.
Functions
Returns the agent id's defaults: the deployment's, overridden by its org's.
@spec hold(keyword(), Wardrik.t(), String.t(), Wardrik.OrgSettings.t()) :: keyword()
Returns opts with the org's policy and ceilings added.
@spec known(Wardrik.t(), String.t()) :: :ok | {:error, Wardrik.Error.t()}
Returns :ok if org exists, or the error settings/2 returns.
"deployment", the deployment's own namespace, always exists.
Returns the org of the agent id.
Applies the org's current settings to its awake agents. Returns a line for each failure.
@spec settings(Wardrik.t(), String.t()) :: {:ok, Wardrik.OrgSettings.t()} | {:error, Wardrik.Error.t()}
Returns org's settings, with each policy and ceiling built, or an error if they're invalid.
Without :orgs, every org gets empty settings.
@spec spent(atom() | Wardrik.t(), String.t()) :: {:ok, %{required(String.t()) => map()}} | {:error, Wardrik.Error.t()}
Returns what the org's agents have spent against each ceiling, by name. See
Wardrik.Ceiling.spent/3.
Wardrik.Orgs.spent(MyApp.AgentRuntime, "acme")
#=> {:ok, %{"spending-cap" => %{limit: %{usd: 20.0, tokens: nil}, spent: %{usd: 12.4, tokens: 81_200}, ...}}}
@spec within(Wardrik.t(), Wardrik.OrgSettings.t()) :: Wardrik.t()
Returns wardrik with the org's policies and defaults merged in.