Class: OllamaAgent::Plugins::Registry
- Inherits:
-
Object
- Object
- OllamaAgent::Plugins::Registry
- Defined in:
- lib/ollama_agent/plugins/registry.rb
Overview
Central plugin registry.
A plugin is any object (module, class, or struct) that can register extensions at one or more extension points.
Extension points:
:tools — Array<Tools::Base subclass instances>
:prompts — Array<Hash { name:, content: }>
:policies — Array<Proc(tool, args, ctx) → nil | String>
:providers — Array<Providers::Base instances>
:postprocessors — Array<Proc(response) → response>
:memory_adapters — Array<Memory::Base-like objects>
:command_handlers — Array<Hash { slash_command:, handler: Proc }>
Constant Summary collapse
- EXTENSION_POINTS =
%i[ tools prompts policies providers postprocessors memory_adapters command_handlers ].freeze
Class Method Summary collapse
- .all_command_handlers ⇒ Object
- .all_policies ⇒ Object
- .all_postprocessors ⇒ Object
- .all_prompts ⇒ Object
- .all_providers ⇒ Object
- .all_tools ⇒ Object
- .extensions_for(point) ⇒ Object
- .instance ⇒ Object
- .plugin_names ⇒ Object
-
.register(name, plugin = nil) ⇒ Object
Delegate class methods to the singleton.
- .reset! ⇒ Object
Instance Method Summary collapse
- #add_command(slash_command:, &handler) ⇒ Object
- #add_policy(&block) ⇒ Object
- #add_prompt(hash) ⇒ Object
- #add_provider(provider) ⇒ Object
-
#add_tool(tool) ⇒ Object
Shorthand helpers.
-
#extend(point, handler) ⇒ Object
Add an extension at a specific extension point.
- #extensions_for(point) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #plugin_names ⇒ Object
-
#register(name, plugin = nil, &block) ⇒ Object
Register a plugin by name.
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
48 49 50 |
# File 'lib/ollama_agent/plugins/registry.rb', line 48 def initialize reset! end |
Class Method Details
.all_command_handlers ⇒ Object
43 |
# File 'lib/ollama_agent/plugins/registry.rb', line 43 def all_command_handlers = instance.extensions_for(:command_handlers) |
.all_policies ⇒ Object
40 |
# File 'lib/ollama_agent/plugins/registry.rb', line 40 def all_policies = instance.extensions_for(:policies) |
.all_postprocessors ⇒ Object
42 |
# File 'lib/ollama_agent/plugins/registry.rb', line 42 def all_postprocessors = instance.extensions_for(:postprocessors) |
.all_prompts ⇒ Object
39 |
# File 'lib/ollama_agent/plugins/registry.rb', line 39 def all_prompts = instance.extensions_for(:prompts) |
.all_providers ⇒ Object
41 |
# File 'lib/ollama_agent/plugins/registry.rb', line 41 def all_providers = instance.extensions_for(:providers) |
.all_tools ⇒ Object
38 |
# File 'lib/ollama_agent/plugins/registry.rb', line 38 def all_tools = instance.extensions_for(:tools) |
.extensions_for(point) ⇒ Object
37 |
# File 'lib/ollama_agent/plugins/registry.rb', line 37 def extensions_for(point) = instance.extensions_for(point) |
.instance ⇒ Object
31 32 33 |
# File 'lib/ollama_agent/plugins/registry.rb', line 31 def instance @instance ||= new end |
.plugin_names ⇒ Object
44 |
# File 'lib/ollama_agent/plugins/registry.rb', line 44 def plugin_names = instance.plugin_names |
.register(name, plugin = nil) ⇒ Object
Delegate class methods to the singleton.
36 |
# File 'lib/ollama_agent/plugins/registry.rb', line 36 def register(name, plugin = nil, &) = instance.register(name, plugin, &) |
.reset! ⇒ Object
45 |
# File 'lib/ollama_agent/plugins/registry.rb', line 45 def reset! = instance.reset! |
Instance Method Details
#add_command(slash_command:, &handler) ⇒ Object
88 89 90 91 |
# File 'lib/ollama_agent/plugins/registry.rb', line 88 def add_command(slash_command:, &handler) extend(:command_handlers, { slash_command: slash_command, handler: handler }) end |
#add_policy(&block) ⇒ Object
85 |
# File 'lib/ollama_agent/plugins/registry.rb', line 85 def add_policy(&block) = extend(:policies, block) |
#add_prompt(hash) ⇒ Object
84 |
# File 'lib/ollama_agent/plugins/registry.rb', line 84 def add_prompt(hash) = extend(:prompts, hash) |
#add_provider(provider) ⇒ Object
86 |
# File 'lib/ollama_agent/plugins/registry.rb', line 86 def add_provider(provider) = extend(:providers, provider) |
#add_tool(tool) ⇒ Object
Shorthand helpers
83 |
# File 'lib/ollama_agent/plugins/registry.rb', line 83 def add_tool(tool) = extend(:tools, tool) |
#extend(point, handler) ⇒ Object
Add an extension at a specific extension point.
72 73 74 75 76 77 78 79 80 |
# File 'lib/ollama_agent/plugins/registry.rb', line 72 def extend(point, handler) point = point.to_sym unless EXTENSION_POINTS.include?(point) raise ArgumentError, "Unknown extension point: #{point}. Valid: #{EXTENSION_POINTS.join(", ")}" end @extensions[point] << handler end |
#extensions_for(point) ⇒ Object
93 94 95 |
# File 'lib/ollama_agent/plugins/registry.rb', line 93 def extensions_for(point) @extensions[point.to_sym].dup end |
#plugin_names ⇒ Object
97 98 99 |
# File 'lib/ollama_agent/plugins/registry.rb', line 97 def plugin_names @plugins.keys end |
#register(name, plugin = nil, &block) ⇒ Object
Register a plugin by name.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ollama_agent/plugins/registry.rb', line 56 def register(name, plugin = nil, &block) name = name.to_sym raise ArgumentError, "Plugin #{name} is already registered" if @plugins.key?(name) @plugins[name] = plugin if block block.call(self) elsif plugin.respond_to?(:register) plugin.register(self) end end |
#reset! ⇒ Object
101 102 103 104 |
# File 'lib/ollama_agent/plugins/registry.rb', line 101 def reset! @plugins = {} @extensions = Hash.new { |h, k| h[k] = [] } end |