Class: OllamaAgent::ExternalAgents::Registry
- Inherits:
-
Object
- Object
- OllamaAgent::ExternalAgents::Registry
- Defined in:
- lib/ollama_agent/external_agents/registry.rb
Overview
Loads merged default + user agent definitions (YAML).
Constant Summary collapse
- DEFAULT_FILE =
File.join(__dir__, "default_agents.yml")
- USER_FILE =
File.join(Dir.home, ".config", "ollama_agent", "agents.yml")
Instance Attribute Summary collapse
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
Class Method Summary collapse
Instance Method Summary collapse
- #find(id) ⇒ Object
-
#initialize(agents) ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize(agents) ⇒ Registry
Returns a new instance of Registry.
14 15 16 17 |
# File 'lib/ollama_agent/external_agents/registry.rb', line 14 def initialize(agents) @agents = agents @by_id = agents.to_h { |a| [a["id"].to_s, a] } end |
Instance Attribute Details
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
12 13 14 |
# File 'lib/ollama_agent/external_agents/registry.rb', line 12 def agents @agents end |
Class Method Details
.load ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ollama_agent/external_agents/registry.rb', line 19 def self.load base = safe_read_yaml(DEFAULT_FILE) user_path = ENV.fetch("OLLAMA_AGENT_EXTERNAL_AGENTS_CONFIG", nil) user_path = USER_FILE if user_path.to_s.strip.empty? && File.file?(USER_FILE) user = user_path && File.file?(user_path.to_s) ? safe_read_yaml(user_path) : {} merged = merge_agents(base["agents"] || [], user["agents"] || []) new(merged) end |
.merge_agents(base, extra) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ollama_agent/external_agents/registry.rb', line 36 def self.merge_agents(base, extra) by_id = base.to_h { |a| [a["id"].to_s, a] } extra.each do |a| id = a["id"].to_s by_id[id] = by_id[id] ? by_id[id].merge(a) : a end by_id.values end |
.safe_read_yaml(path) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ollama_agent/external_agents/registry.rb', line 28 def self.safe_read_yaml(path) YAML.safe_load( File.read(path, encoding: Encoding::UTF_8), permitted_classes: [], aliases: true ) || {} end |
Instance Method Details
#find(id) ⇒ Object
45 46 47 |
# File 'lib/ollama_agent/external_agents/registry.rb', line 45 def find(id) @by_id[id.to_s] end |