Class: RailsAiContext::Tools::GetComponentCatalog

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rails_ai_context/tools/get_component_catalog.rb

Constant Summary

Constants inherited from BaseTool

BaseTool::SESSION_CONTEXT, BaseTool::SHARED_CACHE

Class Method Summary collapse

Methods inherited from BaseTool

abstract!, abstract?, cache_key, cached_context, config, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, inherited, not_found_response, paginate, rails_app, registered_tools, reset_all_caches!, reset_cache!, session_queries, session_record, session_reset!, set_call_params, text_response

Class Method Details

.call(component: nil, detail: "standard", offset: 0, limit: nil, server_context: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rails_ai_context/tools/get_component_catalog.rb', line 36

def self.call(component: nil, detail: "standard", offset: 0, limit: nil, server_context: nil)
  data = cached_context[:components]

  unless data.is_a?(Hash) && !data[:error]
    return text_response("No component data available. Ensure :components introspector is enabled and app/components/ exists.")
  end

  components = data[:components] || []

  if component
    component = component.to_s.strip

    if components.empty?
      return text_response("Component '#{component}' not found — no components exist in app/components/. Create ViewComponent or Phlex components first.")
    end

    found = components.find { |c|
      c[:name]&.downcase == component.downcase ||
      c[:name]&.underscore&.downcase == component.downcase ||
      c[:name]&.sub(/Component\z/, "")&.downcase == component.downcase
    }

    return not_found_response("component", component,
      components.map { |c| c[:name] },
      recovery_tool: "rails_get_component_catalog") unless found

    text_response(render_single(found, detail))
  else
    if components.empty?
      return text_response(
        "No components found in app/components/.\n\n" \
        "This app may use ERB partials instead of ViewComponent/Phlex. Try:\n" \
        "- `rails_get_partial_interface(partial:\"shared/partial_name\")` — partial locals contract + usage\n" \
        "- `rails_get_view(controller:\"name\")` — view templates with partial/Stimulus references"
      )
    end
    text_response(render_catalog(components, data[:summary], detail, offset: offset, limit: limit))
  end
end