Class: RailsAiContext::Tools::GetComponentCatalog
- Defined in:
- lib/rails_ai_context/tools/get_component_catalog.rb
Constant Summary
Constants inherited from BaseTool
BaseTool::DEFAULT_SESSION, BaseTool::MAX_SESSIONS, BaseTool::MAX_SESSION_ID_LENGTH, BaseTool::SESSION_CONTEXT, BaseTool::SHARED_CACHE
Class Method Summary collapse
Methods inherited from BaseTool
abstract!, abstract?, api_only_app?, api_only_note, cache_key, cached_context, config, current_session, #dedupe_put_patch_routes, detail_param?, error_response, evict_oldest_sessions, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, guide_row, inherited, introspection_warnings_note, invalid_detail_note, normalize_detail, not_found_response, paginate, rails_app, rails_env_name, registered_tools, reset_all_caches!, reset_cache!, session_from, session_params, session_queries, session_record, session_reset!, static_tier_banner, static_tier_refusal, text_response, touch_session, unavailable_note, with_session, with_session_for
Methods included from SectionFetch
Class Method Details
.call(component: nil, detail: "standard", offset: 0, limit: nil, server_context: nil) ⇒ Object
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 75 76 77 78 79 80 81 82 83 |
# File 'lib/rails_ai_context/tools/get_component_catalog.rb', line 43 def self.call(component: nil, detail: "standard", offset: 0, limit: nil, server_context: nil) fetch_section(:components, unusable_message: "No component data available. Ensure :components introspector is enabled and app/components/ exists.") do |data| components = data[:components] || [] if component component = component.to_s.strip if components.empty? note = api_only_note("app/components") return text_response(note) if note 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? note = api_only_note("app/components") return text_response(note) if note 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 end |