Class: Raif::Admin::AgentsController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/raif/admin/agents_controller.rb

Instance Method Summary collapse

Methods inherited from Raif::ApplicationController

#raif_current_user

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/raif/admin/agents_controller.rb', line 8

def index
  @agent_types = Raif::Agent.distinct.pluck(:type)
  @selected_type = params[:agent_type].present? ? params[:agent_type] : "all"

  @selected_status = params[:status].present? ? params[:status].to_sym : :all

  @selected_llm_model_key = params[:llm_model_key].presence
  @llm_model_keys = Raif::Agent.distinct.order(:llm_model_key).pluck(:llm_model_key)

  agents = Raif::Agent.order(created_at: :desc)
  agents = agents.where(type: @selected_type) if @selected_type.present? && @selected_type != "all"

  if @selected_status.present? && @selected_status != :all
    case @selected_status
    when :completed
      agents = agents.completed
    when :failed
      agents = agents.failed
    when :running
      agents = agents.started.where(completed_at: nil, failed_at: nil)
    when :pending
      agents = agents.where(started_at: nil)
    end
  end

  agents = agents.where(llm_model_key: @selected_llm_model_key) if @selected_llm_model_key.present?

  @pagy, @agents = pagy(agents)
end

#showObject



38
39
40
# File 'app/controllers/raif/admin/agents_controller.rb', line 38

def show
  @agent = Raif::Agent.find(params[:id])
end