Class: LanguageOperator::CLI::Errors::Suggestions

Inherits:
Object
  • Object
show all
Extended by:
Helpers::UxHelper
Defined in:
lib/language_operator/cli/errors/suggestions.rb

Overview

Provides helpful suggestions for error recovery

Class Method Summary collapse

Methods included from Helpers::UxHelper

box, highlight_ruby_code, logo, pastel, prompt, spinner, table

Class Method Details

.find_similar(input_name, available_names, limit: 3) ⇒ Object

Find similar resource names using fuzzy matching



15
16
17
18
19
20
21
# File 'lib/language_operator/cli/errors/suggestions.rb', line 15

def find_similar(input_name, available_names, limit: 3)
  return [] if available_names.empty?

  spell_checker = DidYouMean::SpellChecker.new(dictionary: available_names)
  corrections = spell_checker.correct(input_name)
  corrections.first(limit)
end

.for_error(error_type, context = {}) ⇒ Object

Generate context-aware suggestions based on error type



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/language_operator/cli/errors/suggestions.rb', line 24

def for_error(error_type, context = {})
  case error_type
  when :agent_not_found
    agent_not_found_suggestions(context)
  when :tool_not_found
    tool_not_found_suggestions(context)
  when :model_not_found
    model_not_found_suggestions(context)
  when :persona_not_found
    persona_not_found_suggestions(context)
  when :cluster_not_found
    cluster_not_found_suggestions(context)
  when :no_cluster_selected
    no_cluster_selected_suggestions
  when :no_models_available
    no_models_available_suggestions(context)
  when :synthesis_failed
    synthesis_failed_suggestions
  when :already_exists
    already_exists_suggestions(context)
  else
    []
  end
end