Jido.Browser.ActionHelpers (Jido Browser v2.1.0)

Copy Markdown View Source

Shared helper functions for Jido.Browser action modules.

Provides common utilities like session extraction with proper error handling (returning {:error, reason} tuples instead of raising).

Summary

Functions

Extracts the browser session from the action context.

Fetches a value from a result map by atom or string key.

Unwraps adapter results that may be nested under a :result or "result" key.

Functions

get_session(context)

@spec get_session(map()) ::
  {:ok, Jido.Browser.Session.t()}
  | {:error, Jido.Browser.Error.InvalidError.t()}

Extracts the browser session from the action context.

Looks for the session in these locations (in order):

  • context[:session]
  • context[:browser_session]
  • context[:tool_context][:session]

Returns {:ok, session} if found, or {:error, InvalidError} if not.

Examples

iex> get_session(%{session: session})
{:ok, session}

iex> get_session(%{})
{:error, %Jido.Browser.Error.InvalidError{message: "No browser session in context"}}

get_value(map, key)

@spec get_value(map(), atom()) :: term()

Fetches a value from a result map by atom or string key.

unwrap_result(map)

@spec unwrap_result(map()) :: map()

Unwraps adapter results that may be nested under a :result or "result" key.