LemonGateway.EngineRegistry (lemon_gateway v0.1.0)

View Source

Registry of available AI engine modules.

Maintains a mapping of engine ID strings to their implementing modules. Validates engine IDs on registration and provides lookup and resume token extraction across all registered engines.

The built-in engines are the CLI wrappers this app ships. Engines that live in another application register themselves at boot with register/1 — that is how coding_agent contributes the "lemon" engine without the gateway depending on it. Registration also updates :lemon_gateway, :engines, so a registry restart keeps the engine.

What gets written back is the union of the configured list and the runtime registrations, not the set this process is currently serving. Those differ: a configured engine whose module is not loadable yet is skipped for lookups but stays in the configuration, because "not loadable at boot" is a statement about start order, not about intent. Persisting the serving set instead would let one unrelated register/1 delete an engine the operator configured.

An engine is third-party code called from inside this process, so every call into one — LemonGateway.Engine.id/0 and LemonGateway.Engine.extract_resume/1 — is isolated. An engine that raises is logged and skipped rather than taking the registry (and, through the supervisor's restart intensity, the gateway) down with it.

Summary

Functions

Returns a specification to start this module under a supervisor.

Iterates all registered engines and calls extract_resume/1 on each until one returns a non-nil ResumeToken. Returns {:ok, token} if found, :none otherwise.

Returns the engine module for the given ID, or nil if not registered.

Returns the engine module for the given ID, or raises if not found.

Returns a list of all registered engine IDs.

Registers an engine module at runtime.

Types

engine_id()

@type engine_id() :: String.t()

engine_mod()

@type engine_mod() :: module()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

extract_resume(text)

@spec extract_resume(String.t()) :: {:ok, LemonCore.ResumeToken.t()} | :none

Iterates all registered engines and calls extract_resume/1 on each until one returns a non-nil ResumeToken. Returns {:ok, token} if found, :none otherwise.

get_engine(id)

@spec get_engine(engine_id()) :: engine_mod() | nil

Returns the engine module for the given ID, or nil if not registered.

get_engine!(id)

@spec get_engine!(engine_id()) :: engine_mod()

Returns the engine module for the given ID, or raises if not found.

list_engines()

@spec list_engines() :: [engine_id()]

Returns a list of all registered engine IDs.

register(module)

@spec register(engine_mod()) :: :ok | {:error, term()}

Registers an engine module at runtime.

Idempotent: registering the same module again is a no-op, and re-registering an id with a different module replaces it. Returns {:error, :unavailable} when the registry is not running, so a caller booting outside the gateway runtime does not crash.

start_link(opts)