Class: A2A::PluginManager
- Inherits:
-
Object
- Object
- A2A::PluginManager
- Defined in:
- lib/a2a/plugin_manager.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
private
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
private
Returns the value of attribute logger.
Instance Method Summary collapse
-
#auth_plugins ⇒ Array<A2A::Plugin::AuthPlugin>
Get authentication plugins.
-
#build_middleware_chain ⇒ Array<Proc>
Create middleware chain from plugins.
-
#configure_plugins(plugins) ⇒ Object
Configure auto-loading plugins.
-
#execute_request_hooks(event, request) ⇒ Hash
Execute request hooks.
-
#execute_response_hooks(event, response, request = nil) ⇒ Object
Execute response hooks.
-
#find_auth_strategy(auth_name) ⇒ A2A::Plugin::AuthPlugin?
Find auth plugin by name.
-
#find_transport(transport_name) ⇒ A2A::Plugin::TransportPlugin?
Find transport plugin by name.
-
#initialize(config = A2A.config) ⇒ PluginManager
constructor
Initialize plugin manager.
-
#load_all_plugins ⇒ Object
Load all configured plugins.
-
#load_plugin(name, **config) ⇒ Object
Load a specific plugin.
-
#middleware_plugins ⇒ Array<A2A::Plugin::MiddlewarePlugin>
Get middleware plugins.
-
#status ⇒ Hash
Get plugin status.
-
#transport_plugins ⇒ Array<A2A::Plugin::TransportPlugin>
Get transport plugins.
-
#unload_plugin(name) ⇒ Object
Unload a plugin.
Constructor Details
#initialize(config = A2A.config) ⇒ PluginManager
Initialize plugin manager
15 16 17 18 19 20 |
# File 'lib/a2a/plugin_manager.rb', line 15 def initialize(config = A2A.config) @config = config @logger = config.logger @auto_load_plugins = [] @plugin_configs = {} end |
Instance Attribute Details
#config ⇒ Object (readonly, private)
Returns the value of attribute config.
157 158 159 |
# File 'lib/a2a/plugin_manager.rb', line 157 def config @config end |
#logger ⇒ Object (readonly, private)
Returns the value of attribute logger.
157 158 159 |
# File 'lib/a2a/plugin_manager.rb', line 157 def logger @logger end |
Instance Method Details
#auth_plugins ⇒ Array<A2A::Plugin::AuthPlugin>
Get authentication plugins
74 75 76 |
# File 'lib/a2a/plugin_manager.rb', line 74 def auth_plugins A2A::Plugin.loaded_plugins(type: :auth) end |
#build_middleware_chain ⇒ Array<Proc>
Create middleware chain from plugins
133 134 135 136 137 |
# File 'lib/a2a/plugin_manager.rb', line 133 def build_middleware_chain middleware_plugins.map do |plugin| proc { |request, next_middleware| plugin.call(request, next_middleware) } end end |
#configure_plugins(plugins) ⇒ Object
Configure auto-loading plugins
24 25 26 27 28 29 30 |
# File 'lib/a2a/plugin_manager.rb', line 24 def configure_plugins(plugins) @plugin_configs = plugins plugins.each do |name, plugin_config| @auto_load_plugins << name if plugin_config[:auto_load] end end |
#execute_request_hooks(event, request) ⇒ Hash
Execute request hooks
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/a2a/plugin_manager.rb', line 108 def execute_request_hooks(event, request) results = A2A::Plugin.execute_hooks(event, request) # Apply modifications from hooks results.each do |result| request.merge!(result) if result.is_a?(Hash) end request end |
#execute_response_hooks(event, response, request = nil) ⇒ Object
Execute response hooks
124 125 126 127 128 129 |
# File 'lib/a2a/plugin_manager.rb', line 124 def execute_response_hooks(event, response, request = nil) results = A2A::Plugin.execute_hooks(event, response, request) # Return last non-nil result or original response results.reverse.find { |result| !result.nil? } || response end |
#find_auth_strategy(auth_name) ⇒ A2A::Plugin::AuthPlugin?
Find auth plugin by name
97 98 99 100 101 102 |
# File 'lib/a2a/plugin_manager.rb', line 97 def find_auth_strategy(auth_name) auth_plugins.find do |plugin| plugin.respond_to?(:strategy_name) && plugin.strategy_name == auth_name end end |
#find_transport(transport_name) ⇒ A2A::Plugin::TransportPlugin?
Find transport plugin by name
87 88 89 90 91 92 |
# File 'lib/a2a/plugin_manager.rb', line 87 def find_transport(transport_name) transport_plugins.find do |plugin| plugin.respond_to?(:transport_name) && plugin.transport_name == transport_name end end |
#load_all_plugins ⇒ Object
Load all configured plugins
33 34 35 36 37 |
# File 'lib/a2a/plugin_manager.rb', line 33 def load_all_plugins @auto_load_plugins.each do |plugin_name| load_plugin(plugin_name) end end |
#load_plugin(name, **config) ⇒ Object
Load a specific plugin
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/a2a/plugin_manager.rb', line 42 def load_plugin(name, **config) plugin_config = @plugin_configs[name] || {} merged_config = plugin_config.merge(config) # Load dependencies first if A2A::Plugin.registry[name] dependencies = A2A::Plugin.registry[name][:class].dependencies dependencies.each do |dep| load_plugin(dep) unless A2A::Plugin.loaded?(dep) end end A2A::Plugin.load(name, **merged_config) rescue A2A::Errors::PluginError => e @logger&.error("Failed to load plugin #{name}: #{e.}") raise end |
#middleware_plugins ⇒ Array<A2A::Plugin::MiddlewarePlugin>
Get middleware plugins
80 81 82 |
# File 'lib/a2a/plugin_manager.rb', line 80 def middleware_plugins A2A::Plugin.loaded_plugins(type: :middleware) end |
#status ⇒ Hash
Get plugin status
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/a2a/plugin_manager.rb', line 141 def status { loaded_plugins: A2A::Plugin.loaded_plugins.size, registered_plugins: A2A::Plugin.registry.size, plugins_by_type: { transport: transport_plugins.size, auth: auth_plugins.size, middleware: middleware_plugins.size }, auto_load_plugins: @auto_load_plugins, plugin_list: A2A::Plugin.list } end |
#transport_plugins ⇒ Array<A2A::Plugin::TransportPlugin>
Get transport plugins
68 69 70 |
# File 'lib/a2a/plugin_manager.rb', line 68 def transport_plugins A2A::Plugin.loaded_plugins(type: :transport) end |