Class: AgentHarness::Providers::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/agent_harness/providers/registry.rb

Overview

Registry for provider classes

Manages registration and lookup of provider classes. Supports dynamic registration of custom providers and aliasing of provider names.

Examples:

Registering a custom provider

AgentHarness::Providers::Registry.instance.register(:my_provider, MyProviderClass)

Looking up a provider

klass = AgentHarness::Providers::Registry.instance.get(:claude)

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



20
21
22
23
24
# File 'lib/agent_harness/providers/registry.rb', line 20

def initialize
  @providers = {}
  @aliases = {}
  @builtin_registered = false
end

Instance Method Details

#allArray<Symbol>

List all registered provider names

Returns:

  • (Array<Symbol>)

    provider names



69
70
71
72
# File 'lib/agent_harness/providers/registry.rb', line 69

def all
  ensure_builtin_providers_registered
  @providers.keys
end

#availableArray<Symbol>

List available providers (CLI installed)

Returns:

  • (Array<Symbol>)

    available provider names



77
78
79
80
# File 'lib/agent_harness/providers/registry.rb', line 77

def available
  ensure_builtin_providers_registered
  @providers.select { |_, klass| klass.available? }.keys
end

#get(name) ⇒ Class

Get provider class by name

Parameters:

  • name (Symbol, String)

    the provider name

Returns:

  • (Class)

    the provider class

Raises:



50
51
52
53
54
# File 'lib/agent_harness/providers/registry.rb', line 50

def get(name)
  ensure_builtin_providers_registered
  name = resolve_alias(name.to_sym)
  @providers[name] || raise(ConfigurationError, "Unknown provider: #{name}")
end

#installation_contract(name, **options) ⇒ Hash?

Fetch installation metadata for a provider.

Parameters:

  • name (Symbol, String)

    the provider name

  • options (Hash)

    optional target selection (for example, ‘version:`)

Returns:

  • (Hash, nil)

    provider installation contract, or nil when the registered provider class does not define ‘.installation_contract`

Raises:



89
90
91
92
93
94
# File 'lib/agent_harness/providers/registry.rb', line 89

def installation_contract(name, **options)
  provider_class = get(name)
  return nil unless provider_class.respond_to?(:installation_contract)

  provider_class.installation_contract(**options)
end

#installation_contractsHash<Symbol, Hash>

Get installation metadata for all providers that expose it.

Returns:

  • (Hash<Symbol, Hash>)

    installation contracts keyed by provider



99
100
101
102
103
104
105
106
107
108
# File 'lib/agent_harness/providers/registry.rb', line 99

def installation_contracts
  ensure_builtin_providers_registered

  @providers.each_with_object({}) do |(name, klass), contracts|
    next unless klass.respond_to?(:installation_contract)

    contract = klass.installation_contract
    contracts[name] = contract if contract
  end
end

#register(name, klass, aliases: []) ⇒ void

This method returns an undefined value.

Register a provider class

Parameters:

  • name (Symbol, String)

    the provider name

  • klass (Class)

    the provider class

  • aliases (Array<Symbol, String>) (defaults to: [])

    alternative names



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agent_harness/providers/registry.rb', line 32

def register(name, klass, aliases: [])
  name = name.to_sym
  validate_provider_class!(klass)

  @providers[name] = klass

  aliases.each do |alias_name|
    @aliases[alias_name.to_sym] = name
  end

  AgentHarness.logger&.debug("[AgentHarness::Registry] Registered provider: #{name}")
end

#registered?(name) ⇒ Boolean

Check if provider is registered

Parameters:

  • name (Symbol, String)

    the provider name

Returns:

  • (Boolean)

    true if registered



60
61
62
63
64
# File 'lib/agent_harness/providers/registry.rb', line 60

def registered?(name)
  ensure_builtin_providers_registered
  name = resolve_alias(name.to_sym)
  @providers.key?(name)
end

#reset!void

This method returns an undefined value.

Reset registry (useful for testing)



139
140
141
142
143
# File 'lib/agent_harness/providers/registry.rb', line 139

def reset!
  @providers.clear
  @aliases.clear
  @builtin_registered = false
end

#smoke_test_contract(name) ⇒ Hash?

Get smoke-test metadata for a provider.

Parameters:

  • name (Symbol, String)

    the provider name

Returns:

  • (Hash, nil)

    smoke-test contract

Raises:



115
116
117
118
119
120
# File 'lib/agent_harness/providers/registry.rb', line 115

def smoke_test_contract(name)
  klass = get(name)
  return nil unless klass.respond_to?(:smoke_test_contract)

  klass.smoke_test_contract
end

#smoke_test_contractsHash<Symbol, Hash>

Get smoke-test metadata for all providers that expose it.

Returns:

  • (Hash<Symbol, Hash>)

    smoke-test contracts keyed by provider



125
126
127
128
129
130
131
132
133
134
# File 'lib/agent_harness/providers/registry.rb', line 125

def smoke_test_contracts
  ensure_builtin_providers_registered

  @providers.each_with_object({}) do |(name, klass), contracts|
    next unless klass.respond_to?(:smoke_test_contract)

    contract = klass.smoke_test_contract
    contracts[name] = contract if contract
  end
end