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',
  'Local (Ollama/LM Studio)' => 'local'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(prompt: nil) ⇒ WizardPrompt

Returns a new instance of WizardPrompt.



17
18
19
# File 'lib/legion/tty/components/wizard_prompt.rb', line 17

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

Instance Method Details

#ask_api_key(provider:) ⇒ Object



33
34
35
# File 'lib/legion/tty/components/wizard_prompt.rb', line 33

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

#ask_nameObject



21
22
23
# File 'lib/legion/tty/components/wizard_prompt.rb', line 21

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

#ask_name_with_default(default) ⇒ Object



25
26
27
# File 'lib/legion/tty/components/wizard_prompt.rb', line 25

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

#ask_secret(question) ⇒ Object



37
38
39
# File 'lib/legion/tty/components/wizard_prompt.rb', line 37

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

#ask_with_default(question, default) ⇒ Object



41
42
43
# File 'lib/legion/tty/components/wizard_prompt.rb', line 41

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

#confirm(question) ⇒ Object

rubocop:disable Naming/PredicateMethod



46
47
48
# File 'lib/legion/tty/components/wizard_prompt.rb', line 46

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

#display_provider_results(providers) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/legion/tty/components/wizard_prompt.rb', line 55

def display_provider_results(providers)
  providers.each do |p|
    icon = p[:status] == :ok ? "\u2705" : "\u274C"
    latency = "#{p[:latency_ms]}ms"
    label = "#{icon} #{p[:name]} (#{p[:model]}) \u2014 #{latency}"
    label += " [#{p[:error]}]" if p[:error]
    @prompt.say(label)
  end
end

#select_default_provider(working_providers) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/legion/tty/components/wizard_prompt.rb', line 65

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
  @prompt.select('Multiple providers available. Choose your default:', choices)
end

#select_from(question, choices) ⇒ Object

rubocop:enable Naming/PredicateMethod



51
52
53
# File 'lib/legion/tty/components/wizard_prompt.rb', line 51

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

#select_providerObject



29
30
31
# File 'lib/legion/tty/components/wizard_prompt.rb', line 29

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