Class: SharedTools::Tools::NotificationTool

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/shared_tools/tools/notification_tool.rb

Overview

Cross-platform notification tool for desktop banners, modal dialogs, and TTS.

Supports macOS (osascript, say) and Linux (notify-send, zenity/terminal, espeak-ng/espeak). On unsupported platforms all actions return false.

Examples:

Desktop notification

tool = SharedTools::Tools::NotificationTool.new
tool.execute(action: 'notify', message: 'Build complete', title: 'CI')

Modal alert

result = tool.execute(action: 'alert', message: 'Deploy to production?', buttons: ['Yes', 'No'])
result[:button] # => 'Yes' or 'No'

Text-to-speech

tool.execute(action: 'speak', message: 'Task finished')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver: nil) ⇒ NotificationTool

Returns a new instance of NotificationTool.

Parameters:



57
58
59
# File 'lib/shared_tools/tools/notification_tool.rb', line 57

def initialize(driver: nil)
  @driver = driver || default_driver
end

Class Method Details

.nameObject



21
# File 'lib/shared_tools/tools/notification_tool.rb', line 21

def self.name = 'notification_tool'

Instance Method Details

#execute(action:, message: nil, title: nil, subtitle: nil, sound: nil, buttons: nil, default_button: nil, voice: nil, rate: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/shared_tools/tools/notification_tool.rb', line 61

def execute(action:, message: nil, title: nil, subtitle: nil, sound: nil,
            buttons: nil, default_button: nil, voice: nil, rate: nil)
  buttons ||= ['OK']

  case action
  when 'notify'
    return missing_param('message', 'notify') if blank?(message)
    @driver.notify(message:, title:, subtitle:, sound:)
  when 'alert'
    return missing_param('message', 'alert') if blank?(message)
    @driver.alert(message:, title:, buttons:, default_button:)
  when 'speak'
    return missing_param('message', 'speak') if blank?(message)
    @driver.speak(text: message, voice:, rate:)
  else
    { success: false, error: "Unknown action: #{action.inspect}. Must be notify, alert, or speak." }
  end
end