Class: RailsAiBridge::Registry::ContextProviderDefinition

Inherits:
Data
  • Object
show all
Defined in:
lib/rails_ai_bridge/registry/context_provider_definition.rb

Overview

Immutable value object describing a context provider service declared in the registry manifest.

Context providers are external services (currently MCP servers) that the bridge can query for project context. This definition is preparatory — the data structures mirror the Rust runtime's manifest format, but no integration consumes them yet.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointString (readonly)

Returns provider HTTP endpoint base URL.

Returns:

  • (String)

    provider HTTP endpoint base URL



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_ai_bridge/registry/context_provider_definition.rb', line 21

ContextProviderDefinition = Data.define(:type, :endpoint, :optional, :tools) do
  # Builds a {ContextProviderDefinition} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [ContextProviderDefinition]
  # @raise [ArgumentError] when a required field is missing
  def self.from_json(hash)
    new(
      type: hash.fetch('type'),
      endpoint: hash.fetch('endpoint'),
      optional: hash.fetch('optional', false),
      tools: (hash['tools'] || []).map { |tool| ContextToolSpec.from_json(tool) }
    )
  rescue KeyError => error
    raise ArgumentError, "Context provider definition missing required field: #{error.key}"
  end

  # @return [Boolean]
  def optional? = optional
end

#optionalBoolean (readonly)

Returns whether the provider may be skipped when unavailable.

Returns:

  • (Boolean)

    whether the provider may be skipped when unavailable



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_ai_bridge/registry/context_provider_definition.rb', line 21

ContextProviderDefinition = Data.define(:type, :endpoint, :optional, :tools) do
  # Builds a {ContextProviderDefinition} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [ContextProviderDefinition]
  # @raise [ArgumentError] when a required field is missing
  def self.from_json(hash)
    new(
      type: hash.fetch('type'),
      endpoint: hash.fetch('endpoint'),
      optional: hash.fetch('optional', false),
      tools: (hash['tools'] || []).map { |tool| ContextToolSpec.from_json(tool) }
    )
  rescue KeyError => error
    raise ArgumentError, "Context provider definition missing required field: #{error.key}"
  end

  # @return [Boolean]
  def optional? = optional
end

#toolsArray<ContextToolSpec> (readonly)

Returns tools requested from the provider.

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_ai_bridge/registry/context_provider_definition.rb', line 21

ContextProviderDefinition = Data.define(:type, :endpoint, :optional, :tools) do
  # Builds a {ContextProviderDefinition} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [ContextProviderDefinition]
  # @raise [ArgumentError] when a required field is missing
  def self.from_json(hash)
    new(
      type: hash.fetch('type'),
      endpoint: hash.fetch('endpoint'),
      optional: hash.fetch('optional', false),
      tools: (hash['tools'] || []).map { |tool| ContextToolSpec.from_json(tool) }
    )
  rescue KeyError => error
    raise ArgumentError, "Context provider definition missing required field: #{error.key}"
  end

  # @return [Boolean]
  def optional? = optional
end

#typeString (readonly)

Returns provider type, e.g. "mcp".

Returns:

  • (String)

    provider type, e.g. "mcp"



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_ai_bridge/registry/context_provider_definition.rb', line 21

ContextProviderDefinition = Data.define(:type, :endpoint, :optional, :tools) do
  # Builds a {ContextProviderDefinition} from a parsed JSON hash.
  #
  # @param hash [Hash] parsed JSON object
  # @return [ContextProviderDefinition]
  # @raise [ArgumentError] when a required field is missing
  def self.from_json(hash)
    new(
      type: hash.fetch('type'),
      endpoint: hash.fetch('endpoint'),
      optional: hash.fetch('optional', false),
      tools: (hash['tools'] || []).map { |tool| ContextToolSpec.from_json(tool) }
    )
  rescue KeyError => error
    raise ArgumentError, "Context provider definition missing required field: #{error.key}"
  end

  # @return [Boolean]
  def optional? = optional
end

Class Method Details

.from_json(hash) ⇒ ContextProviderDefinition

Builds a RailsAiBridge::Registry::ContextProviderDefinition from a parsed JSON hash.

Parameters:

  • hash (Hash)

    parsed JSON object

Returns:

Raises:

  • (ArgumentError)

    when a required field is missing



27
28
29
30
31
32
33
34
35
36
# File 'lib/rails_ai_bridge/registry/context_provider_definition.rb', line 27

def self.from_json(hash)
  new(
    type: hash.fetch('type'),
    endpoint: hash.fetch('endpoint'),
    optional: hash.fetch('optional', false),
    tools: (hash['tools'] || []).map { |tool| ContextToolSpec.from_json(tool) }
  )
rescue KeyError => error
  raise ArgumentError, "Context provider definition missing required field: #{error.key}"
end

Instance Method Details

#optional?Boolean

Returns:

  • (Boolean)


39
# File 'lib/rails_ai_bridge/registry/context_provider_definition.rb', line 39

def optional? = optional