Module: TheLocal::DiskProviders
- Defined in:
- lib/the_local/disk_providers.rb
Constant Summary collapse
- AGENTS_GLOB =
File.join("the_local", "agents", "*.md")
- LEGACY_AGENTS_GLOB =
File.join("lib", "**", "the_local", "agents", "*.md")
Class Method Summary collapse
- .agent_files(path) ⇒ Object
- .agent_from(gem_name, file) ⇒ Object
- .load(registry:, specs:) ⇒ Object
- .register(registry, spec) ⇒ Object
Class Method Details
.agent_files(path) ⇒ Object
16 17 18 19 |
# File 'lib/the_local/disk_providers.rb', line 16 def self.agent_files(path) rendered = Dir.glob(File.join(path, AGENTS_GLOB)) rendered.any? ? rendered : Dir.glob(File.join(path, LEGACY_AGENTS_GLOB)) end |
.agent_from(gem_name, file) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/the_local/disk_providers.rb', line 33 def self.agent_from(gem_name, file) prefix, _, name = File.basename(file, ".md").rpartition("-") Agent.new(gem_name: gem_name, prefix: prefix, name: name, description: nil, tools: nil, body: nil, knowledge: nil, source_path: file, scope: FrontMatter.new(File.read(file)).scope) end |
.load(registry:, specs:) ⇒ Object
12 13 14 |
# File 'lib/the_local/disk_providers.rb', line 12 def self.load(registry:, specs:) specs.each { |spec| register(registry, spec) } end |
.register(registry, spec) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/the_local/disk_providers.rb', line 21 def self.register(registry, spec) files = agent_files(spec[:path]) return if files.empty? agents = files.map { |file| agent_from(spec[:name], file) } representative = agents.find(&:scope) || agents.first registry.add_provider( Provider.new(gem_name: spec[:name], prefix: representative.prefix, scope: representative.scope) ) agents.each { |agent| registry.add(agent) } end |