Class: Silas::Api::V1::ApprovalsController

Inherits:
BaseController
  • Object
show all
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

Methods included from Serialization

#invocation_json, #session_json, #step_json, #turn_json

Instance Method Details

#answerObject

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.message }, status: :conflict
end

#approveObject

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.message }, status: :conflict
end

#declineObject

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.message }, status: :conflict
end

#indexObject

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