Class: Silas::Api::V1::ApprovalsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Silas::Api::V1::ApprovalsController
- Includes:
- Serialization
- Defined in:
- app/controllers/silas/api/v1/approvals_controller.rb
Overview
The headline feature over HTTP: list what's parked, approve or decline it — the exact same approve!/decline! as the inbox, Slack, and email.
Instance Method Summary collapse
-
#answer ⇒ Object
POST /silas/api/v1/approvals/:id/answer { text: "..." } ask_question's verdict: the text becomes the tool result.
-
#approve ⇒ Object
POST /silas/api/v1/approvals/:id/approve.
-
#decline ⇒ Object
POST /silas/api/v1/approvals/:id/decline { reason: (optional) }.
-
#index ⇒ Object
GET /silas/api/v1/sessions/:session_id/approvals.
Methods included from Serialization
#invocation_json, #session_json, #step_json, #turn_json
Instance Method Details
#answer ⇒ Object
POST /silas/api/v1/approvals/:id/answer { text: "..." } ask_question's verdict: the text becomes the tool result.
35 36 37 38 39 40 41 |
# File 'app/controllers/silas/api/v1/approvals_controller.rb', line 35 def answer invocation = Silas::ToolInvocation.find(params[:id]) invocation.answer!(text: params[:text].to_s.strip, by: current_actor) render json: invocation_json(invocation.reload) rescue Silas::Error => e render json: { error: e. }, status: :conflict end |
#approve ⇒ Object
POST /silas/api/v1/approvals/:id/approve
16 17 18 19 20 21 22 |
# File 'app/controllers/silas/api/v1/approvals_controller.rb', line 16 def approve invocation = Silas::ToolInvocation.find(params[:id]) invocation.approve!(by: current_actor) render json: invocation_json(invocation.reload) rescue Silas::Error => e render json: { error: e. }, status: :conflict end |
#decline ⇒ Object
POST /silas/api/v1/approvals/:id/decline { reason: (optional) }
25 26 27 28 29 30 31 |
# File 'app/controllers/silas/api/v1/approvals_controller.rb', line 25 def decline invocation = Silas::ToolInvocation.find(params[:id]) invocation.decline!(reason: params[:reason].presence || "declined via api", by: current_actor) render json: invocation_json(invocation.reload) rescue Silas::Error => e render json: { error: e. }, status: :conflict end |
#index ⇒ Object
GET /silas/api/v1/sessions/:session_id/approvals
10 11 12 13 |
# File 'app/controllers/silas/api/v1/approvals_controller.rb', line 10 def index session = Silas::Session.find(params[:session_id]) render json: { approvals: session.pending_approvals.order(:id).map { |i| invocation_json(i) } } end |