Class: Silas::Api::V1::TurnsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Silas::Api::V1::TurnsController
- Includes:
- Serialization
- Defined in:
- app/controllers/silas/api/v1/turns_controller.rb
Instance Method Summary collapse
-
#cancel ⇒ Object
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.
-
#create ⇒ Object
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.
Methods included from Serialization
#invocation_json, #session_json, #step_json, #turn_json
Instance Method Details
#cancel ⇒ Object
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 |
#create ⇒ Object
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. }, status: :conflict end |