Class: Legion::TTY::Components::WizardPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/tty/components/wizard_prompt.rb

Constant Summary collapse

PROVIDERS =
{
  'Claude (Anthropic)' => 'claude',
  'OpenAI' => 'openai',
  'Gemini (Google)' => 'gemini',
  'Azure OpenAI' => 'azure',
  'AWS Bedrock' => 'bedrock',
  'Local (Ollama/LM Studio)' => 'local',
  'Skip for now' => nil
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(prompt: nil) ⇒ WizardPrompt

Returns a new instance of WizardPrompt.



19
20
21
# File 'lib/legion/tty/components/wizard_prompt.rb', line 19

def initialize(prompt: nil)
  @prompt = prompt || ::TTY::Prompt.new
end

Instance Method Details

#ask_api_key(provider:) ⇒ Object



35
36
37
# File 'lib/legion/tty/components/wizard_prompt.rb', line 35

def ask_api_key(provider:)
  @prompt.mask("Enter API key for #{provider}:")
end

#ask_nameObject



23
24
25
# File 'lib/legion/tty/components/wizard_prompt.rb', line 23

def ask_name
  @prompt.ask('What should I call you?', required: true) { |q| q.modify(:strip) }
end

#ask_name_with_default(default) ⇒ Object



27
28
29
# File 'lib/legion/tty/components/wizard_prompt.rb', line 27

def ask_name_with_default(default)
  @prompt.ask('What should I call you?', default: default) { |q| q.modify(:strip) }
end

#ask_secret(question) ⇒ Object



39
40
41
# File 'lib/legion/tty/components/wizard_prompt.rb', line 39

def ask_secret(question)
  @prompt.mask(question)
end

#ask_with_default(question, default) ⇒ Object



43
44
45
# File 'lib/legion/tty/components/wizard_prompt.rb', line 43

def ask_with_default(question, default)
  @prompt.ask(question, default: default)
end

#confirm(question) ⇒ Object

rubocop:disable Naming/PredicateMethod



48
49
50
# File 'lib/legion/tty/components/wizard_prompt.rb', line 48

def confirm(question)
  @prompt.yes?(question)
end

#display_provider_results(providers) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/tty/components/wizard_prompt.rb', line 57

def display_provider_results(providers)
  providers.each do |p|
    icon = case p[:status]
           when :ok then "\u2705"
           when :configured then "\U0001F511"
           else "\u274C"
           end
    latency = "#{p[:latency_ms]}ms"
    label = "#{icon} #{p[:name]} (#{p[:model]}) \u2014 #{latency}"
    label += p[:status] == :configured ? ' [configured, not validated]' : " [#{p[:error]}]" if p[:error]
    @prompt.say(label)
  end
end

#select_default_provider(working_providers) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/legion/tty/components/wizard_prompt.rb', line 71

def select_default_provider(working_providers)
  return nil if working_providers.empty?
  return working_providers.first[:name] if working_providers.size == 1

  choices = working_providers.map do |p|
    { name: "#{p[:name]} (#{p[:model]}, #{p[:latency_ms]}ms)", value: p[:name] }
  end
  choices << { name: 'Skip for now', value: nil }
  @prompt.select('Multiple providers available. Choose your default:', choices)
end

#select_from(question, choices) ⇒ Object

rubocop:enable Naming/PredicateMethod



53
54
55
# File 'lib/legion/tty/components/wizard_prompt.rb', line 53

def select_from(question, choices)
  @prompt.select(question, choices)
end

#select_providerObject



31
32
33
# File 'lib/legion/tty/components/wizard_prompt.rb', line 31

def select_provider
  @prompt.select('Choose an AI provider:', PROVIDERS)
end