Skip to content
Kward Search API index

Class: Kward::CLI::Tabs::TabQuestionPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/cli/tabs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli) ⇒ TabQuestionPrompt

Returns a new instance of TabQuestionPrompt.



56
57
58
# File 'lib/kward/cli/tabs.rb', line 56

def initialize(cli)
  @cli = cli
end

Instance Attribute Details

#tabObject

Returns the value of attribute tab.



54
55
56
# File 'lib/kward/cli/tabs.rb', line 54

def tab
  @tab
end

Instance Method Details

#ask_tool_approval(tool_name:, args:, reason: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kward/cli/tabs.rb', line 64

def ask_tool_approval(tool_name:, args:, reason: nil)
  answers = ask_user_question([
    {
      header: "Approval required · #{tool_name.to_s.tr("_", " ").capitalize}",
      question: (["The agent wants to use #{tool_name}.", "Arguments:\n#{JSON.pretty_generate(args.to_h)}", reason].compact).join("\n"),
      options: [
        { label: "Allow once", description: "Run this tool call." },
        { label: "Allow this tool for this session", description: "Run this call and future calls to #{tool_name}." },
        { label: "Deny", description: "Do not run this tool call." }
      ]
    }
  ])
  answer = answers&.first
  return { denied_message: answer[:answer] } if answer&.fetch(:custom, false) && !answer[:answer].to_s.empty?

  case answer&.fetch(:answer, nil)
  when "Allow once" then true
  when "Allow this tool for this session" then :allow_for_session
  else false
  end
end

#ask_user_question(questions, cancellation: nil) ⇒ Object



60
61
62
# File 'lib/kward/cli/tabs.rb', line 60

def ask_user_question(questions, cancellation: nil)
  @cli.send(:ask_tab_user_question, @tab, questions, cancellation: cancellation)
end