Class: RailsAiBridge::Tools::GetProviderContext::ResultFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/get_provider_context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Formats aggregate results as markdown for MCP response.

Constant Summary collapse

STATUS_LABELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  success: 'All OK',
  partial_failure: 'Partial Failure',
  error: 'Failed'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(result, provider_name: nil) ⇒ ResultFormatter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ResultFormatter.

Parameters:



204
205
206
207
# File 'lib/rails_ai_bridge/tools/get_provider_context.rb', line 204

def initialize(result, provider_name: nil)
  @result = result
  @provider_name = provider_name
end

Instance Method Details

#formatString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns markdown body.

Returns:

  • (String)

    markdown body



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rails_ai_bridge/tools/get_provider_context.rb', line 210

def format
  lines = []
  lines << header
  lines << ''

  if @result.results.any?
    @result.results.each do |name, data|
      lines << "## #{name}"
      lines << ''
      lines << format_data(data)
      lines << ''
      lines << "_Source: #{name}_"
      lines << ''
    end
  end

  if @result.failures.any?
    lines << '## Failures'
    lines << ''
    @result.failures.each do |error|
      provider = (error.provider_name if error.respond_to?(:provider_name)) || 'unknown'
      lines << "- **#{provider}** (#{error.class.name.demodulize}): #{error.message}"
    end
    lines << ''
  end

  lines << "_Elapsed: #{@result.elapsed_ms}ms_"
  lines.join("\n")
end