Class: Silas::Api::V1::TurnsController

Inherits:
BaseController
  • Object
show all
Includes:
Serialization
Defined in:
app/controllers/silas/api/v1/turns_controller.rb

Instance Method Summary collapse

Methods included from Serialization

#invocation_json, #session_json, #step_json, #turn_json

Instance Method Details

#cancelObject

POST /silas/api/v1/turns/:id/cancel Running turns are flagged (honored at the next step boundary); queued/parked turns cancel immediately — cancel: reflects which.



24
25
26
27
28
# File 'app/controllers/silas/api/v1/turns_controller.rb', line 24

def cancel
  turn = Silas::Turn.find(params[:id])
  outcome = turn.cancel!(reason: "canceled via api by #{current_actor}")
  render json: turn_json(turn.reload).merge(cancel: outcome)
end

#createObject

POST /silas/api/v1/sessions/:session_id/turns { input: } 409 when a turn is already active — an API must surface it, not swallow it the way the webhook channels do.



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/silas/api/v1/turns_controller.rb', line 10

def create
  session = Silas::Session.find(params[:session_id])
  input = params[:input].to_s.strip
  return render json: { error: "input is required" }, status: :unprocessable_entity if input.empty?

  turn = session.continue(input: input)
  render json: turn_json(turn), status: :created
rescue Silas::TurnInProgressError => e
  render json: { error: e.message }, status: :conflict
end