Jido.Messaging.AdapterBridge (Jido Messaging v1.0.0)

Copy Markdown View Source

Runtime bridge between Jido.Messaging and Jido.Chat.Adapter.

This module is the only boundary used by the messaging runtime for outbound operations and adapter capability/failure normalization.

Summary

Functions

Returns messaging content capabilities for an adapter.

Returns adapter channel type, falling back to module name inference.

Classifies adapter failures into retry/degrade/crash classes.

Deletes an adapter-scoped provider ingress subscription.

Edits media payload through adapter-native or replacement behavior.

Normalizes outbound edit through canonical adapter boundary.

Ensures an adapter-scoped provider ingress subscription.

Maps failure class to runtime disposition.

Lists adapter-scoped provider ingress subscriptions.

Returns listener child specs for an adapter, defaulting to no listeners.

Sanitizes outbound payload when adapter provides custom sanitize callback.

Sends media payload through the canonical adapter boundary.

Normalizes outbound send through canonical adapter boundary.

Checks whether adapter supports a messaging capability.

Verifies inbound sender when adapter supports verification.

Types

failure_class()

@type failure_class() :: :recoverable | :degraded | :fatal

failure_disposition()

@type failure_disposition() :: :retry | :degrade | :crash

Functions

capabilities(adapter_module)

@spec capabilities(module()) :: [atom()]

Returns messaging content capabilities for an adapter.

Adapters may expose either:

channel_type(adapter_module)

@spec channel_type(module()) :: atom()

Returns adapter channel type, falling back to module name inference.

classify_failure(reason)

@spec classify_failure(term()) :: failure_class()

Classifies adapter failures into retry/degrade/crash classes.

delete_ingress_subscription(adapter_module, bridge_id, subscription_id, opts \\ [])

@spec delete_ingress_subscription(module(), String.t(), String.t(), keyword()) ::
  {:ok, term()} | {:error, term()}

Deletes an adapter-scoped provider ingress subscription.

edit_media(adapter_module, external_room_id, external_message_id, payload, opts \\ [])

@spec edit_media(
  module(),
  String.t() | integer(),
  String.t() | integer(),
  map(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Edits media payload through adapter-native or replacement behavior.

Preference order:

  1. adapter-native edit_media/4
  2. replacement edit: send the new media and delete the old message

edit_message(adapter_module, external_room_id, external_message_id, text, opts \\ [])

@spec edit_message(
  module(),
  String.t() | integer(),
  String.t() | integer(),
  String.t(),
  keyword()
) ::
  {:ok, map()} | {:error, term()}

Normalizes outbound edit through canonical adapter boundary.

ensure_ingress_subscription(adapter_module, bridge_id, opts \\ [])

@spec ensure_ingress_subscription(module(), String.t(), keyword()) ::
  {:ok, term()} | {:error, term()}

Ensures an adapter-scoped provider ingress subscription.

The callback is intentionally optional and lives outside the core Jido.Chat.Adapter behaviour. Adapter packages can implement ensure_ingress_subscription/2 when the provider supports control-plane webhook/event subscription provisioning.

failure_disposition(reason_or_failure)

@spec failure_disposition(failure_class() | map() | term()) :: failure_disposition()

Maps failure class to runtime disposition.

list_ingress_subscriptions(adapter_module, bridge_id, opts \\ [])

@spec list_ingress_subscriptions(module(), String.t(), keyword()) ::
  {:ok, term()} | {:error, term()}

Lists adapter-scoped provider ingress subscriptions.

listener_child_specs(adapter_module, bridge_id, opts \\ [])

@spec listener_child_specs(module(), String.t(), keyword()) ::
  {:ok, [Supervisor.child_spec()]} | {:error, map()}

Returns listener child specs for an adapter, defaulting to no listeners.

Runtime passes a standard listener context in opts:

  • :instance_module - messaging runtime instance module
  • :bridge_id - bridge identifier
  • :bridge_config - resolved bridge config
  • :settings - bridge config opts map
  • :ingress - normalized ingress settings map
  • :sink_mfa - sink callback MFA {module, function, base_args}

sanitize_outbound(adapter_module, outbound, opts \\ [])

@spec sanitize_outbound(module(), term(), keyword()) ::
  {:ok, term()} | {:ok, term(), map()} | {:error, term()}

Sanitizes outbound payload when adapter provides custom sanitize callback.

Default is passthrough {:ok, outbound}.

send_media(adapter_module, external_room_id, payload, opts \\ [])

@spec send_media(module(), String.t() | integer(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Sends media payload through the canonical adapter boundary.

Preference order:

  1. adapter-native send_media/3
  2. canonical post_message/4 or send_file/4 fallback through Jido.Chat.Adapter

send_message(adapter_module, external_room_id, text, opts \\ [])

@spec send_message(module(), String.t() | integer(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Normalizes outbound send through canonical adapter boundary.

supports?(adapter_module, capability)

@spec supports?(module(), atom()) :: boolean()

Checks whether adapter supports a messaging capability.

verify_sender(adapter_module, incoming_message, raw_payload)

@spec verify_sender(module(), map(), map()) :: :ok | {:ok, map()} | {:error, term()}

Verifies inbound sender when adapter supports verification.

Default is permissive :ok.