Spaces:
Sleeping
Sleeping
| defined( 'ABSPATH' ) || exit; | |
| /** | |
| * Provider registry + active-provider resolver. | |
| * | |
| * v0.5 ships with the `simulated` provider only. Future providers attach by | |
| * extending the provider catalog — `get_provider_choices()` for the dropdown, | |
| * `instantiate()` for the factory branch. | |
| * | |
| * If the saved provider id is not enabled or is unknown, the registry falls | |
| * back to `simulated`. This guarantees Strategy Review always returns a result | |
| * even if the operator's configured provider is unreachable. | |
| */ | |
| class SA_Orch_LLM_Providers { | |
| /** | |
| * Catalog of provider id → human label, for the settings dropdown. | |
| * Only the simulated provider is wired up in v0.5; the others are listed | |
| * as inert placeholders so the operator can see the seam. | |
| */ | |
| public static function get_provider_choices(): array { | |
| return [ | |
| 'simulated' => 'Simulated (no API call) — heuristic expansion of deterministic audit', | |
| 'openai' => 'OpenAI (Chat Completions; works with any OpenAI-compatible endpoint)', | |
| 'anthropic' => 'Anthropic (not implemented yet)', | |
| 'local' => 'Local model endpoint (not implemented yet)', | |
| 'custom' => 'Custom HTTP endpoint (not implemented yet)', | |
| ]; | |
| } | |
| /** | |
| * Resolve the active provider. Falls back to simulated when: | |
| * - settings.enabled is false | |
| * - settings.provider is unknown | |
| * - the configured provider's class is not yet implemented | |
| */ | |
| public static function get_active_provider(): SA_Orch_LLM_Provider_Interface { | |
| $settings = SA_Orch_LLM_Settings::get(); | |
| if ( empty( $settings['enabled'] ) ) { | |
| return new SA_Orch_LLM_Provider_Simulated(); | |
| } | |
| $instance = self::instantiate( (string) ( $settings['provider'] ?? '' ) ); | |
| if ( $instance instanceof SA_Orch_LLM_Provider_Interface ) { | |
| return $instance; | |
| } | |
| // Fallback | |
| return new SA_Orch_LLM_Provider_Simulated(); | |
| } | |
| private static function instantiate( $id ): ?SA_Orch_LLM_Provider_Interface { | |
| switch ( $id ) { | |
| case 'simulated': | |
| return new SA_Orch_LLM_Provider_Simulated(); | |
| case 'openai': | |
| return new SA_Orch_LLM_Provider_OpenAI(); | |
| // Future: add cases here as providers land. | |
| // case 'anthropic': return new SA_Orch_LLM_Provider_Anthropic(); | |
| // case 'local': return new SA_Orch_LLM_Provider_Local(); | |
| // case 'custom': return new SA_Orch_LLM_Provider_Custom(); | |
| } | |
| return null; | |
| } | |
| } | |