Module: OmniAI::Tools::Browser::PageInspect::LinkSummarizer
- Defined in:
- lib/omniai/tools/browser/page_inspect/link_summarizer.rb
Overview
Module to handle link elements summarization for AI agents
Class Method Summary collapse
- .extract_destination(href) ⇒ Object
- .find_navigation_links(doc) ⇒ Object
- .format_link_group(links, title) ⇒ Object
- .format_nav_link(link) ⇒ Object
- .format_navigation(links) ⇒ Object
- .get_link_text(link) ⇒ Object
- .main_navigation?(link) ⇒ Boolean
- .navigation_link?(link) ⇒ Boolean
- .skip_link?(link) ⇒ Boolean
- .summarize_key_navigation(doc) ⇒ Object
- .workflow_link?(link) ⇒ Boolean
Class Method Details
.extract_destination(href) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 90 def extract_destination(href) return "" if href.nil? || href.empty? return "" unless href.include?("/") path = href.split("/").last return "" if path.nil? || path.empty? " → #{path}" end |
.find_navigation_links(doc) ⇒ Object
18 19 20 21 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 18 def (doc) links = doc.css("a[href]").reject { |link| skip_link?(link) } links.select { |link| (link) } end |
.format_link_group(links, title) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 74 def format_link_group(links, title) return "" if links.empty? result = "#{title}:\n" links.first(6).each { |link| result += format_nav_link(link) } result += " ... and #{links.size - 6} more\n" if links.size > 6 result += "\n" end |
.format_nav_link(link) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 83 def format_nav_link(link) text = get_link_text(link) destination = extract_destination(link["href"]) " • #{text}#{destination}\n" end |
.format_navigation(links) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 62 def (links) result = "🧭 Key Navigation:\n" main_nav = links.select { |l| (l) } actions = links.select { |l| workflow_link?(l) && !(l) } result += format_link_group(main_nav, "📍 Main Menu") result += format_link_group(actions, "🔗 Quick Actions") "#{result}\n" end |
.get_link_text(link) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 54 def get_link_text(link) text = link.text.strip text = link["title"] if text.empty? && link["title"] text = link["aria-label"] if text.empty? && link["aria-label"] text.empty? ? "Link" : text end |
.main_navigation?(link) ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 39 def (link) ancestors = link.ancestors.map { |el| el["class"] }.compact.join(" ") nav_indicators = %w[nav navigation menu main-nav primary-nav app-menu breadcrumb] nav_indicators.any? { |indicator| ancestors.include?(indicator) } end |
.navigation_link?(link) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 32 def (link) return true if (link) return true if workflow_link?(link) false end |
.skip_link?(link) ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 23 def skip_link?(link) href = link["href"] return true if href.nil? || href.empty? || href == "#" return true if href.start_with?("javascript:") return true if link["style"]&.include?("display: none") false end |
.summarize_key_navigation(doc) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 11 def (doc) nav_links = (doc) return "" if nav_links.empty? (nav_links) end |
.workflow_link?(link) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/omniai/tools/browser/page_inspect/link_summarizer.rb', line 46 def workflow_link?(link) text = get_link_text(link).downcase workflow_keywords = %w[dashboard home create new add edit settings invoice estimate customer payment back continue] workflow_keywords.any? { |keyword| text.include?(keyword) } end |