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
@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"}}
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.