from afk_developer.backends.base import ( CoderBackend, ReasonerBackend, ResearcherBackend, ValidatorBackend, ) from afk_developer.config import Config, EndpointType class BackendRegistry: """Resolves role routes to provider implementations. Provider adapters are added incrementally. Raising an explicit error here avoids silently executing a role with a different provider or model than configured. """ def __init__(self, config: Config): self.config = config def get_reasoner(self) -> ReasonerBackend: endpoint = self.config.endpoint_for("reasoner") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleReasoner return OpenAICompatibleReasoner(self.config, "reasoner") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotReasoner return CopilotReasoner(self.config, "reasoner") raise ValueError(f"Unsupported reasoner endpoint type: {endpoint.type}") def get_coder(self) -> CoderBackend: endpoint = self.config.endpoint_for("coder") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleCoder return OpenAICompatibleCoder(self.config, "coder") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotCoder return CopilotCoder(self.config, "coder") raise ValueError(f"Unsupported coder endpoint type: {endpoint.type}") def get_researcher(self) -> ResearcherBackend: endpoint = self.config.endpoint_for("researcher") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleResearcher return OpenAICompatibleResearcher(self.config, "researcher") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotResearcher return CopilotResearcher(self.config, "researcher") raise ValueError(f"Unsupported researcher endpoint type: {endpoint.type}") def get_validator(self) -> ValidatorBackend: endpoint = self.config.endpoint_for("validator") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleValidator return OpenAICompatibleValidator(self.config, "validator") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotValidator return CopilotValidator(self.config, "validator") raise ValueError(f"Unsupported validator endpoint type: {endpoint.type}") def get_foreman(self) -> ReasonerBackend: endpoint = self.config.endpoint_for("foreman") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleReasoner return OpenAICompatibleReasoner(self.config, "foreman") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotReasoner return CopilotReasoner(self.config, "foreman") raise ValueError(f"Unsupported foreman endpoint type: {endpoint.type}") def get_supervisor(self) -> ReasonerBackend: """Return a proposal-only supervisor; trusted code still applies decisions.""" endpoint = self.config.endpoint_for("supervisor") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleReasoner return OpenAICompatibleReasoner(self.config, "supervisor") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotReasoner return CopilotReasoner(self.config, "supervisor") raise ValueError(f"Unsupported supervisor endpoint type: {endpoint.type}") def get_coder_light(self) -> CoderBackend: endpoint = self.config.endpoint_for("coder_light") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleCoder return OpenAICompatibleCoder(self.config, "coder_light") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotCoder return CopilotCoder(self.config, "coder_light") raise ValueError(f"Unsupported coder_light endpoint type: {endpoint.type}") def get_ledger_checker(self) -> ReasonerBackend: """Cheapest configured route, used only for yes/no questions against the ledger.""" endpoint = self.config.endpoint_for("coder_light") if endpoint.type is EndpointType.OPENAI_COMPATIBLE: from afk_developer.backends.openai_compatible import OpenAICompatibleReasoner return OpenAICompatibleReasoner(self.config, "coder_light") if endpoint.type is EndpointType.COPILOT: from afk_developer.backends.copilot import CopilotReasoner return CopilotReasoner(self.config, "coder_light") raise ValueError(f"Unsupported coder_light endpoint type: {endpoint.type}")