Module: OmniAI::Tools::Browser::PageInspect::ButtonSummarizer
- Defined in:
- lib/omniai/tools/browser/page_inspect/button_summarizer.rb
Overview
Module to handle button elements summarization for AI agents
Class Method Summary collapse
- .critical_action?(button) ⇒ Boolean
- .distinctive_text?(button) ⇒ Boolean
- .find_primary_buttons(doc) ⇒ Object
- .format_action_button(button) ⇒ Object
- .format_button_group(buttons, title) ⇒ Object
- .format_primary_actions(buttons) ⇒ Object
- .get_button_selector(button) ⇒ Object
- .get_button_text(button) ⇒ Object
- .primary_action?(button) ⇒ Boolean
- .primary_button_class?(button) ⇒ Boolean
- .primary_button_text?(button) ⇒ Boolean
- .skip_button?(button) ⇒ Boolean
- .summarize_primary_actions(doc) ⇒ Object
- .workflow_action_button?(button) ⇒ Boolean
Class Method Details
.critical_action?(button) ⇒ Boolean
100 101 102 103 104 105 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 100 def critical_action?() text = ().downcase %w[save submit send create].any? do |keyword| text.include?(keyword) end end |
.distinctive_text?(button) ⇒ Boolean
132 133 134 135 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 132 def distinctive_text?() text = () text.length > 2 && text != "Button" end |
.find_primary_buttons(doc) ⇒ Object
18 19 20 21 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 18 def (doc) = doc.css('button, input[type="button"], input[type="submit"], [role="button"], [tabindex="0"]') .select { |btn| primary_action?(btn) && !(btn) } end |
.format_action_button(button) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 118 def () text = () selector = () " • #{text} (#{selector})\n" end |
.format_button_group(buttons, title) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 107 def (, title) return "" if .empty? result = "#{title}:\n" .first(5).each do |btn| result += (btn) end result += " ... and #{.size - 5} more\n" if .size > 5 result += "\n" end |
.format_primary_actions(buttons) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 87 def format_primary_actions() result = "⚡ Primary Actions:\n" # Group by importance critical = .select(&method(:critical_action?)) regular = - critical result += (critical, "🔥 Critical") result += (regular, "📝 Actions") "#{result}\n" end |
.get_button_selector(button) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 125 def () return ["id"] if ["id"] && !["id"].empty? return "text:#{()}" if distinctive_text?() "css-selector-needed" end |
.get_button_text(button) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 79 def () text = .text.strip text = ["value"] if text.empty? && ["value"] text = ["aria-label"] if text.empty? && ["aria-label"] text.empty? ? "Button" : text end |
.primary_action?(button) ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 29 def primary_action?() return true if ["type"] == "submit" return true if () return true if () return true if () false end |
.primary_button_class?(button) ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 53 def () classes = ["class"] || "" # Generic primary button patterns (universal) primary_classes = %w[primary submit btn-primary button--primary save continue] generic_match = primary_classes.any? { |css_class| classes.include?(css_class) } # Generic link-button patterns (works across frameworks) = %w[button--link btn-link link-button button-link] link_match = .any? { |pattern| classes.include?(pattern) } generic_match || link_match end |
.primary_button_text?(button) ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 38 def () text = ().downcase # Direct keyword matches primary_keywords = %w[save submit continue next finish send create update delete cancel close done confirm proceed add edit] return true if primary_keywords.any? { |keyword| text.include?(keyword) } # Workflow action patterns return true if text.include?("add") && text.match?(/item|customer|discount|product|contact|line/) return true if text.include?("choose") || text.include?("select") false end |
.skip_button?(button) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 23 def () ["disabled"] || ["style"]&.include?("display: none") || ["aria-hidden"] == "true" end |
.summarize_primary_actions(doc) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 11 def summarize_primary_actions(doc) = (doc) return "" if .empty? format_primary_actions() end |
.workflow_action_button?(button) ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/omniai/tools/browser/page_inspect/button_summarizer.rb', line 67 def () text = ().downcase # Check for common workflow patterns return true if text.match?(/add.*(item|customer|discount|product|contact)/i) return true if text.match?(/edit.*(column|field|profile)/i) return true if text.match?(/choose.*(different|customer)/i) return true if text.match?(/(create|new).*(item|customer|product)/i) false end |