LemonCore.BindingResolver (lemon_core v0.1.0)

View Source

Canonical binding resolver shared by gateway and channels.

Resolves bindings and settings for a given chat scope. Bindings map transport/chat/topic combinations to projects, engines, and queue modes.

Both LemonGateway.BindingResolver and LemonChannels.BindingResolver delegate here after converting their local structs to LemonCore types.

Summary

Functions

Returns the project override for a given scope from the unified store table.

Looks up a project by id from dynamic store, then static config.

Resolve the agent_id for a given scope.

Resolves a binding for the given scope.

Resolves the working directory for a given scope based on project binding.

Resolves the engine to use for a given scope, hint, and resume token.

Resolves the queue mode for a given scope.

Functions

get_project_override(scope)

@spec get_project_override(LemonCore.ChatScope.t()) :: String.t() | nil

Returns the project override for a given scope from the unified store table.

lookup_project(project_id, config_provider \\ nil)

@spec lookup_project(String.t(), (-> map()) | nil) :: map() | nil

Looks up a project by id from dynamic store, then static config.

The optional config_provider is a 0-arity function that returns a %{projects: %{...}} map (used by gateway/channels to inject their own config source).

resolve_agent_id(scope, opts \\ [])

@spec resolve_agent_id(
  LemonCore.ChatScope.t(),
  keyword()
) :: String.t()

Resolve the agent_id for a given scope.

If no binding exists or no agent_id is set, returns "default".

resolve_binding(scope, opts \\ [])

@spec resolve_binding(
  LemonCore.ChatScope.t(),
  keyword()
) :: LemonCore.Binding.t() | nil

Resolves a binding for the given scope.

Returns the most specific binding that matches:

  • Topic-level binding (transport + chat_id + topic_id) takes precedence
  • Falls back to chat-level binding (transport + chat_id)
  • Returns nil if no binding matches

resolve_cwd(scope, opts \\ [])

@spec resolve_cwd(
  LemonCore.ChatScope.t(),
  keyword()
) :: String.t() | nil

Resolves the working directory for a given scope based on project binding.

Returns the project root path if a binding with a project exists, nil otherwise.

resolve_engine(scope, engine_hint, resume, opts \\ [])

@spec resolve_engine(
  LemonCore.ChatScope.t(),
  String.t() | nil,
  map() | nil,
  keyword()
) ::
  String.t() | nil

Resolves the engine to use for a given scope, hint, and resume token.

Priority order (highest to lowest):

  1. Resume token engine (from conversation continuation)
  2. Engine hint (from /engine command)
  3. Topic binding default_engine
  4. Chat binding default_engine
  5. Project default_engine
  6. Agent profile default_engine
  7. Global default_engine from config

resolve_queue_mode(scope, opts \\ [])

@spec resolve_queue_mode(
  LemonCore.ChatScope.t(),
  keyword()
) :: atom() | nil

Resolves the queue mode for a given scope.

Returns the queue_mode from the binding, or nil if no binding or queue_mode is set.