Class: ActionAgent::Api::AgentRunsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ActionAgent::ApplicationController
- BaseController
- ActionAgent::Api::AgentRunsController
- Defined in:
- app/controllers/action_agent/api/agent_runs_controller.rb
Instance Method Summary collapse
-
#cancel ⇒ Object
POST /api/runs/:id/cancel.
-
#index ⇒ Object
GET /api/runs.
-
#show ⇒ Object
GET /api/runs/:id.
Methods inherited from ActionAgent::ApplicationController
Instance Method Details
#cancel ⇒ Object
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 |
#index ⇒ Object
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 |
#show ⇒ Object
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: (@run), agent: { id: @run.agent.id, name: @run.agent.name, slug: @run.agent.slug } } end |