Class: Aidp::Providers::CapabilityRegistry
- Inherits:
-
Object
- Object
- Aidp::Providers::CapabilityRegistry
- Defined in:
- lib/aidp/providers/capability_registry.rb
Overview
CapabilityRegistry maintains a queryable registry of provider capabilities and features. This enables runtime feature detection and provider selection based on required capabilities.
Constant Summary collapse
- CAPABILITY_KEYS =
Standard capability keys
[ :reasoning_tiers, # Array of supported reasoning tiers (mini, standard, thinking, etc.) :context_window, # Maximum context window size in tokens :supports_json_mode, # Boolean: supports JSON mode output :supports_tool_use, # Boolean: supports tool/function calling :supports_vision, # Boolean: supports image/vision inputs :supports_file_upload, # Boolean: supports file uploads :supports_mcp, # Boolean: supports Model Context Protocol :max_tokens, # Maximum tokens per response :supports_dangerous_mode # Boolean: supports elevated permissions mode ].freeze
Instance Method Summary collapse
-
#capabilities_for(provider_name) ⇒ Hash?
Get capabilities for a specific provider.
-
#capability_statistics ⇒ Hash
Get capability statistics across all providers.
-
#clear ⇒ void
Clear all registered providers.
-
#compatibility_report(provider_name1, provider_name2) ⇒ Hash
Check capability compatibility between providers.
-
#find_providers(**requirements) ⇒ Array<String>
Find providers that match capability requirements.
-
#has_capability?(provider_name, capability, value = nil) ⇒ Boolean
Check if a provider has a specific capability.
-
#initialize ⇒ CapabilityRegistry
constructor
A new instance of CapabilityRegistry.
-
#provider_info ⇒ Hash
Get detailed information about all registered providers.
-
#register(provider) ⇒ void
Register a provider and its capabilities.
-
#registered_providers ⇒ Array<String>
Get all registered providers.
-
#unregister(provider_name) ⇒ void
Unregister a provider.
Constructor Details
#initialize ⇒ CapabilityRegistry
Returns a new instance of CapabilityRegistry.
24 25 26 27 |
# File 'lib/aidp/providers/capability_registry.rb', line 24 def initialize @capabilities = {} @providers = {} end |
Instance Method Details
#capabilities_for(provider_name) ⇒ Hash?
Get capabilities for a specific provider
59 60 61 |
# File 'lib/aidp/providers/capability_registry.rb', line 59 def capabilities_for(provider_name) @capabilities[provider_name] end |
#capability_statistics ⇒ Hash
Get capability statistics across all providers
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/aidp/providers/capability_registry.rb', line 171 def capability_statistics stats = {} CAPABILITY_KEYS.each do |key| stats[key] = { total_providers: @providers.size, supporting_providers: 0, providers: [] } end @capabilities.each do |provider_name, caps| caps.each do |key, value| next unless stats.key?(key) if value.is_a?(TrueClass) || (value.is_a?(Array) && !value.empty?) || (value.is_a?(Integer) && value > 0) stats[key][:supporting_providers] += 1 stats[key][:providers] << provider_name end end end stats end |
#clear ⇒ void
This method returns an undefined value.
Clear all registered providers
198 199 200 201 |
# File 'lib/aidp/providers/capability_registry.rb', line 198 def clear @capabilities.clear @providers.clear end |
#compatibility_report(provider_name1, provider_name2) ⇒ Hash
Check capability compatibility between providers
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/aidp/providers/capability_registry.rb', line 140 def compatibility_report(provider_name1, provider_name2) caps1 = @capabilities[provider_name1] caps2 = @capabilities[provider_name2] return {error: "Provider not found"} unless caps1 && caps2 common = {} differences = {} all_keys = (caps1.keys + caps2.keys).uniq all_keys.each do |key| val1 = caps1[key] val2 = caps2[key] if val1 == val2 common[key] = val1 else differences[key] = {provider_name1 => val1, provider_name2 => val2} end end { common_capabilities: common, differences: differences, compatibility_score: common.size.to_f / all_keys.size } end |
#find_providers(**requirements) ⇒ Array<String>
Find providers that match capability requirements
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/aidp/providers/capability_registry.rb', line 86 def find_providers(**requirements) matching = [] @capabilities.each do |provider_name, caps| matches = requirements.all? do |key, required_value| case key when :min_context_window caps[:context_window] && caps[:context_window] >= required_value when :max_context_window caps[:context_window] && caps[:context_window] <= required_value when :reasoning_tier caps[:reasoning_tiers]&.include?(required_value) else # Exact match for boolean and other values caps[key] == required_value end end matching << provider_name if matches end matching end |
#has_capability?(provider_name, capability, value = nil) ⇒ Boolean
Check if a provider has a specific capability
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/aidp/providers/capability_registry.rb', line 68 def has_capability?(provider_name, capability, value = nil) caps = @capabilities[provider_name] return false unless caps if value.nil? # Just check if capability exists and is truthy caps.key?(capability) && caps[capability] else # Check if capability matches specific value caps[capability] == value end end |
#provider_info ⇒ Hash
Get detailed information about all registered providers
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/aidp/providers/capability_registry.rb', line 118 def provider_info info = {} @providers.each do |provider_name, provider| caps = @capabilities[provider_name] || {} info[provider_name] = { display_name: provider.display_name, available: provider.available?, capabilities: caps, dangerous_mode_enabled: provider.dangerous_mode_enabled?, health_status: provider.health_status } end info end |
#register(provider) ⇒ void
This method returns an undefined value.
Register a provider and its capabilities
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aidp/providers/capability_registry.rb', line 32 def register(provider) provider_name = provider.name @providers[provider_name] = provider # Collect capabilities from provider caps = provider.capabilities.dup caps[:supports_mcp] = provider.supports_mcp? caps[:supports_dangerous_mode] = provider.supports_dangerous_mode? @capabilities[provider_name] = caps Aidp.log_debug("CapabilityRegistry", "registered provider", provider: provider_name, capabilities: caps.keys) end |
#registered_providers ⇒ Array<String>
Get all registered providers
112 113 114 |
# File 'lib/aidp/providers/capability_registry.rb', line 112 def registered_providers @providers.keys end |
#unregister(provider_name) ⇒ void
This method returns an undefined value.
Unregister a provider
51 52 53 54 |
# File 'lib/aidp/providers/capability_registry.rb', line 51 def unregister(provider_name) @capabilities.delete(provider_name) @providers.delete(provider_name) end |