Raxol.Payments.Directive.Pay (Raxol Payments v0.2.0)

Copy Markdown View Source

Semantic payment directive.

Carries the spend metadata an agent runtime hook (SpendingHook) needs to authorize before the side effect runs: amount and domain. The side effect itself is a zero-arity perform closure that returns {:ok, result} or {:error, reason}.

Result messages

Results land at the agent's update/2 as:

  • {:command_result, {:pay_result, result}} on {:ok, result}
  • {:command_result, {:pay_error, reason}} on {:error, reason}
  • {:command_result, {:pay_error, {:exception, message}}} on raise

Example

Raxol.Payments.Directive.Pay.new(
  amount: Decimal.new("0.05"),
  domain: "api.openai.com",
  agent_id: :research_bot,
  perform: fn ->
    Req.post("https://api.openai.com/...")
  end
)

Summary

Functions

Construct a Pay directive.

Types

perform()

@type perform() :: (-> {:ok, term()} | {:error, term()})

t()

@type t() :: %Raxol.Payments.Directive.Pay{
  agent_id: term() | nil,
  amount: Decimal.t(),
  domain: String.t(),
  meta: map(),
  perform: perform()
}

Functions

new(opts)

@spec new(keyword()) :: t()

Construct a Pay directive.

Required: :amount, :domain, :perform. Optional: :agent_id, :meta.