Jido.AI.Signal.Helpers (Jido AI v2.2.0)

Copy Markdown View Source

Shared helpers for signal correlation and signal-safe payload shaping.

Summary

Functions

Extracts the best available request/call correlation identifier from signal data.

Builds a normalized AI runtime error envelope.

Normalizes arbitrary error values into the canonical AI error envelope.

Ensures result payloads use {:ok, term, effects} or {:error, reason, effects} tuples.

retryable?(reason) deprecated

Returns whether a result or error should be treated as retryable by runtime policy.

Sanitizes streaming deltas by removing control bytes and truncating payload size.

Types

error_envelope()

@type error_envelope() :: Jido.AI.Error.error_envelope()

Functions

correlation_id(data)

@spec correlation_id(Jido.Signal.t() | map() | nil) :: String.t() | nil

Extracts the best available request/call correlation identifier from signal data.

error_envelope(type, message, details \\ %{}, retryable? \\ false)

This function is deprecated. Use Jido.AI.Error.error_envelope/4.
@spec error_envelope(atom(), String.t(), map(), boolean()) :: error_envelope()

Builds a normalized AI runtime error envelope.

Prefer Jido.AI.Error.error_envelope/4 for new runtime code.

normalize_error(reason, fallback_type \\ :execution_error, fallback_message \\ "Execution failed", extra_details \\ %{})

This function is deprecated. Use Jido.AI.Error.normalize/4.
@spec normalize_error(term(), atom(), String.t(), map()) :: error_envelope()

Normalizes arbitrary error values into the canonical AI error envelope.

Prefer Jido.AI.Error.normalize/4 for new runtime code.

normalize_result(result, fallback_type \\ :invalid_result, fallback_message \\ "Invalid result envelope")

This function is deprecated. Use Jido.AI.Error.normalize_result/3.
@spec normalize_result(term(), atom(), String.t()) ::
  {:ok, term(), [term()]} | {:error, error_envelope(), [term()]}

Ensures result payloads use {:ok, term, effects} or {:error, reason, effects} tuples.

Prefer Jido.AI.Error.normalize_result/3 for new runtime code.

retryable?(reason)

This function is deprecated. Use Jido.AI.Error.retryable?/1.
@spec retryable?(term()) :: boolean()

Returns whether a result or error should be treated as retryable by runtime policy.

Prefer Jido.AI.Error.retryable?/1 for new runtime code.

sanitize_delta(delta, max_chars \\ 4000)

@spec sanitize_delta(term(), non_neg_integer()) :: String.t()

Sanitizes streaming deltas by removing control bytes and truncating payload size.