Jidoka.Context (Jidoka v0.9.0)

Copy Markdown View Source

Canonical runtime context passed to Jidoka policy code.

Jidoka.Context is the public, data-only shape for controls and approval predicates. It keeps application context in data and exposes the current request, operation, and result metadata without requiring callers to reach into turn internals.

Summary

Functions

Returns caller-provided application context data.

Fetches an application context value by atom or string key without creating atoms.

Fetches a runtime-only value by atom or string key without creating atoms.

Builds a request context from caller-provided application data.

Builds a request context from caller-provided application data or raises.

Normalizes trusted runtime context input and preserves runtime-only fields.

Returns an application context value by atom or string key without creating atoms.

Returns a runtime-only value by atom or string key without creating atoms.

Builds a runtime context from keyword or map attributes.

Builds a runtime context and raises if the attributes are invalid.

Returns trusted runtime-only context values.

Drops runtime-only values before persisting or projecting context.

Returns the Zoi schema for runtime context data.

Projects caller data into the context map expected by Jido actions.

Types

boundary()

@type boundary() :: :input | :operation | :output

t()

@type t() :: %Jidoka.Context{
  agent_id: nil | nil | binary(),
  agent_state: nil | nil | any(),
  arguments: map(),
  boundary: (:input | :operation) | :output,
  control: nil | nil | atom(),
  control_name: nil | nil | binary(),
  data: map(),
  idempotency: (((:pure | :idempotent) | :dedupe) | :reconcile) | :unsafe_once,
  idempotency_key: nil | nil | binary(),
  input: nil | nil | binary(),
  loop_index: nil | nil | integer(),
  metadata: map(),
  operation: nil | nil | binary(),
  operation_kind:
    (((((((((:action | :operation) | :tool) | :ash_resource) | :browser)
         | :skill)
        | :mcp)
       | :catalog)
      | :workflow)
     | :subagent)
    | :handoff,
  operation_metadata: map(),
  operation_source: nil | nil | binary(),
  plan: nil | nil | any(),
  request: nil | nil | any(),
  request_id: nil | nil | binary(),
  request_metadata: map(),
  result: nil | nil | any(),
  result_value: nil | nil | any(),
  runtime: map(),
  session_id: nil | nil | binary(),
  spec: nil | nil | any()
}

Functions

data(context)

@spec data(t()) :: map()

Returns caller-provided application context data.

fetch(context, key)

@spec fetch(t() | map(), atom() | String.t()) :: {:ok, term()} | :error

Fetches an application context value by atom or string key without creating atoms.

fetch_runtime(context, key)

@spec fetch_runtime(t() | map(), atom() | String.t()) :: {:ok, term()} | :error

Fetches a runtime-only value by atom or string key without creating atoms.

from_data(data, attrs \\ [])

@spec from_data(t() | keyword() | map() | nil, keyword() | map()) ::
  {:ok, t()} | {:error, term()}

Builds a request context from caller-provided application data.

Passing an existing Jidoka.Context uses only its public data. Use from_input/1 when trusted code needs to preserve runtime fields.

from_data!(data, attrs \\ [])

@spec from_data!(t() | keyword() | map() | nil, keyword() | map()) :: t()

Builds a request context from caller-provided application data or raises.

from_input(context)

@spec from_input(t() | keyword() | map()) :: {:ok, t()} | {:error, term()}

Normalizes trusted runtime context input and preserves runtime-only fields.

get(context, key, default \\ nil)

@spec get(t() | map(), atom() | String.t(), term()) :: term()

Returns an application context value by atom or string key without creating atoms.

get_runtime(context, key, default \\ nil)

@spec get_runtime(t() | map(), atom() | String.t(), term()) :: term()

Returns a runtime-only value by atom or string key without creating atoms.

new(attrs)

@spec new(keyword() | map()) :: {:ok, t()} | {:error, term()}

Builds a runtime context from keyword or map attributes.

new!(attrs)

@spec new!(keyword() | map()) :: t()

Builds a runtime context and raises if the attributes are invalid.

runtime(context)

@spec runtime(t()) :: map()

Returns trusted runtime-only context values.

sanitize(context)

@spec sanitize(t()) :: t()

Drops runtime-only values before persisting or projecting context.

schema()

@spec schema() :: Zoi.schema()

Returns the Zoi schema for runtime context data.

to_action_context(context)

@spec to_action_context(t()) :: map()

Projects caller data into the context map expected by Jido actions.