Class: ActionAgent::Api::AgentRunsController

Inherits:
BaseController show all
Defined in:
app/controllers/action_agent/api/agent_runs_controller.rb

Instance Method Summary collapse

Methods inherited from ActionAgent::ApplicationController

allow_unauthenticated_access

Instance Method Details

#cancelObject

POST /api/runs/:id/cancel



22
23
24
25
# File 'app/controllers/action_agent/api/agent_runs_controller.rb', line 22

def cancel
  @run.cancel!
  render json: { run: @run.summary }
end

#indexObject

GET /api/runs



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/action_agent/api/agent_runs_controller.rb', line 28

def index
  # Scoped to the caller's own agents: this listed (and counted) every
  # run in the database regardless of who owned it.
  scope = AgentRun.includes(:agent).where(agent: owner_agents).recent

  scope = scope.where(agent_id: params[:agent_id]) if params[:agent_id].present?
  scope = scope.where(status: params[:status]) if params[:status].present?

  page = (params[:page] || 1).to_i
  per_page = (params[:per_page] || 20).to_i
  total = scope.count
  runs = scope.offset((page - 1) * per_page).limit(per_page)

  render json: {
    runs: runs.map { |run| run_json(run, include_agent: true) },
    meta: {
      page: page,
      per_page: per_page,
      total: total
    }
  }
end

#showObject

GET /api/runs/:id



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/action_agent/api/agent_runs_controller.rb', line 9

def show
  render json: {
    run: run_json(@run),
    messages: interaction_messages(@run),
    agent: {
      id: @run.agent.id,
      name: @run.agent.name,
      slug: @run.agent.slug
    }
  }
end