lib/huggingface_client/inference/hardcoded_mappings.ex

defmodule HuggingfaceClient.HardcodedMappings do
  @moduledoc """
  Agent-backed store for runtime dev overrides of provider/model mappings.

  Useful in tests or local development to pin specific model→provider mappings
  without hitting the Hub API.  Keyed by `{provider, hf_model_id}`.

  ## Example

      HuggingfaceClient.HardcodedMappings.add("groq", "meta-llama/Llama-3-8B", %{
        "provider"    => "groq",
        "hf_model_id" => "meta-llama/Llama-3-8B",
        "provider_id" => "llama-3-8b",
        "status"      => "live",
        "task"        => "conversational"
      })

      mapping = HuggingfaceClient.HardcodedMappings.get("groq", "meta-llama/Llama-3-8B")
  """

  use Agent

  @doc false
  def start_link(_opts \\ []) do
    Agent.start_link(fn -> %{} end, name: __MODULE__)
  end

  @doc """
  Returns the mapping for `{provider, model_id}`, or `nil` if not present.
  """
  @spec get(String.t(), String.t()) :: map() | nil
  def get(provider, model_id) do
    Agent.get(__MODULE__, &Map.get(&1, {provider, model_id}))
  end

  @doc """
  Adds or replaces a mapping for `{provider, model_id}`.  Last write wins.
  """
  @spec add(String.t(), String.t(), map()) :: :ok
  def add(provider, model_id, mapping) do
    Agent.update(__MODULE__, &Map.put(&1, {provider, model_id}, mapping))
  end

  @doc """
  Removes the mapping for `{provider, model_id}`.  No-op if not present.
  """
  @spec remove(String.t(), String.t()) :: :ok
  def remove(provider, model_id) do
    Agent.update(__MODULE__, &Map.delete(&1, {provider, model_id}))
  end

  @doc "Clears all runtime additions."
  @spec reset() :: :ok
  def reset do
    Agent.update(__MODULE__, fn _ -> %{} end)
  end
end