LemonChannels.Adapters.ModelPolicyShared behaviour (lemon_channels v0.1.0)

View Source

Shared ModelPolicyAdapter logic for all channel transports.

Provides model and thinking-level resolution with session overrides (ephemeral) and persistent policy storage via LemonChannels.ModelPolicy.

Usage

defmodule MyAdapter do
  use LemonChannels.Adapters.ModelPolicyShared

  @impl true
  def channel_name, do: "telegram"

  @impl true
  def build_route(account_id, chat_id, thread_id) do
    thread_str = if is_integer(thread_id), do: to_string(thread_id), else: nil
    Route.new("telegram", account_id, to_string(chat_id), thread_str)
  end

  @impl true
  def session_get(session_key), do: ...

  @impl true
  def session_put(session_key, model), do: ...

  @impl true
  def format_source_labels, do: %{topic: "topic default", chat: "chat default"}
end

Optional callbacks

  • session_delete/1 — for channels that support clearing session overrides
  • legacy_model_fallback/3 — for channels with pre-ModelPolicy data
  • legacy_thinking_fallback/3 — for channels with pre-ModelPolicy thinking data
  • chat_id_guard/1 — override the default guard type check

Summary

Callbacks

build_route(account_id, chat_id, thread_id)

@callback build_route(account_id :: String.t(), chat_id :: term(), thread_id :: term()) ::
  LemonChannels.ModelPolicy.Route.t()

channel_name()

@callback channel_name() :: String.t()

clear_legacy_thinking(legacy_key)

(optional)
@callback clear_legacy_thinking(legacy_key :: term()) :: term()

format_source_labels()

@callback format_source_labels() :: %{topic: String.t(), chat: String.t()}

legacy_model_fallback(account_id, chat_id, thread_id)

(optional)
@callback legacy_model_fallback(
  account_id :: String.t(),
  chat_id :: term(),
  thread_id :: term()
) :: String.t() | nil

legacy_thinking_fallback(account_id, chat_id, thread_id)

(optional)
@callback legacy_thinking_fallback(
  account_id :: String.t(),
  chat_id :: term(),
  thread_id :: term()
) :: String.t() | nil

session_delete(session_key)

(optional)
@callback session_delete(session_key :: String.t()) :: :ok

session_get(session_key)

@callback session_get(session_key :: String.t()) :: String.t() | nil

session_put(session_key, model)

@callback session_put(session_key :: String.t(), model :: String.t()) :: :ok

Functions

default_thinking_line()

exact_policy_thinking_level(route)

normalize_model_id(model_id)

normalize_thinking_level(level)

placeholder_model_id()

placeholder_only_policy?(policy)

policy_model_id(arg1)

resolve_policy_model(route)

resolved_policy_thinking_level(module, account_id, chat_id, thread_id)

thinking_level_atom(level)