Class: ActionAgent::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ActionAgent::InstallGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/action_agent/install_generator.rb
Overview
Generator for installing the ActiveAgent Dashboard.
This will:
- Create the telemetry_traces table migration
- Add mount directive to routes
- Create initializer for dashboard configuration
Instance Method Summary collapse
Instance Method Details
#add_route ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/generators/action_agent/install_generator.rb', line 76 def add_route return if [:skip_routes] # Rails' `route` action is only idempotent on an exact string match, # so an app installed before the default path changed would get a # second mount — and two unnamed mounts of the same engine raise # "Invalid route name, already in use: 'active_agent'" at boot. routes_file = File.join(destination_root, "config/routes.rb") if File.exist?(routes_file) && File.read(routes_file).include?("ActionAgent::Engine") say_status :skip, "engine already mounted in config/routes.rb", :yellow return end route 'mount ActionAgent::Engine => "/activeagents"' end |
#copy_migrations ⇒ 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/generators/action_agent/install_generator.rb', line 36 def copy_migrations return if [:skip_migrations] # An app that installed the dashboard when it shipped inside activeagent # already has this migration. Re-emitting it aborts the whole generator # on a duplicate name, so upgrade that install in place instead: the # table exists but predates agent attribution, and only agent_id is # missing. if existing_migration?("create_active_agent_telemetry_traces") say_status :skip, "create_active_agent_telemetry_traces already exists", :yellow unless existing_migration?("add_agent_id_to_active_agent_telemetry_traces") migration_template( "add_agent_id_to_active_agent_telemetry_traces.rb.erb", "db/migrate/add_agent_id_to_active_agent_telemetry_traces.rb" ) end else migration_template( "create_active_agent_telemetry_traces.rb.erb", "db/migrate/create_active_agent_telemetry_traces.rb" ) end # The rest of the dashboard — agents, runs, versions, conversations, # evaluations, sandboxes, recordings, keys. Skippable for an app that # only wants to be a trace sink. return if [:traces_only] if existing_migration?("create_active_agent_dashboard_tables") say_status :skip, "create_active_agent_dashboard_tables already exists", :yellow return end migration_template( "create_active_agent_dashboard_tables.rb.erb", "db/migrate/create_active_agent_dashboard_tables.rb" ) end |
#create_initializer ⇒ Object
92 93 94 95 96 97 |
# File 'lib/generators/action_agent/install_generator.rb', line 92 def create_initializer template( "action_agent.rb.erb", "config/initializers/action_agent.rb" ) end |
#show_readme ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/generators/action_agent/install_generator.rb', line 99 def show_readme say "\n" say "ActiveAgent Dashboard installed successfully!", :green say "\n" say "Next steps:" say " 1. Run migrations: rails db:migrate" say " 2. Configure telemetry in config/active_agent.yml:" say " telemetry:" say " enabled: true" say " local_storage: true" say " 3. Visit /activeagents to view the dashboard" unless [:traces_only] say "\n" say "The dashboard stores API keys and provider credentials encrypted." say "Run `rails db:encryption:init` and add the keys to your credentials" say "before creating any." end say "\n" end |