Class: Silas::Inbox::TurnsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Silas::Inbox::TurnsController
- Defined in:
- app/controllers/silas/inbox/turns_controller.rb
Overview
The web composer: append a turn to an existing session. Same write-auth gate as approve/decline. Deliberately thin — the turn runs on the durable loop and the model's after_commit broadcasts render it live, so this controller only enqueues and redirects.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel from the trace.
- #create ⇒ Object
-
#raise_budget ⇒ Object
Top up a budget-parked turn and resume it — the CHANGELOG promised this card in 0.1.5; completed steps replay from rows, same as approvals.
Instance Method Details
#cancel ⇒ Object
Cancel from the trace. Running turns are flagged and honored at the next step boundary (the same safe point as budgets); parked/queued turns cancel immediately.
24 25 26 27 28 29 |
# File 'app/controllers/silas/inbox/turns_controller.rb', line 24 def cancel turn = Silas::Turn.find(params[:id]) outcome = turn.cancel!(reason: "canceled from inbox by #{current_actor}") notice = outcome == :cancel_requested ? "Cancel requested — honored at the next step boundary." : "Turn canceled." redirect_to inbox_session_path(turn.session_id), notice: notice end |
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/silas/inbox/turns_controller.rb', line 10 def create agent_session = Silas::Session.find(params[:session_id]) input = params[:input].to_s.strip return redirect_to inbox_session_path(agent_session), alert: "Type a message first." if input.empty? agent_session.continue(input: input) redirect_to inbox_session_path(agent_session) rescue Silas::TurnInProgressError redirect_to inbox_session_path(agent_session), alert: "A turn is already running — wait for it to settle." end |
#raise_budget ⇒ Object
Top up a budget-parked turn and resume it — the CHANGELOG promised this card in 0.1.5; completed steps replay from rows, same as approvals.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/silas/inbox/turns_controller.rb', line 33 def raise_budget turn = Silas::Turn.find(params[:id]) unless turn.budget_parked? return redirect_to inbox_session_path(turn.session_id), alert: "Turn ##{turn.index} is not budget-parked." end reason = turn.failure_reason.to_s value = params[:value].to_s numeric = reason == "max_cost" ? value.to_f : value.to_i turn.raise_budget!(**{ reason.to_sym => numeric }) redirect_to inbox_session_path(turn.session_id), notice: "#{reason} raised — resuming." rescue Silas::Error, ArgumentError => e redirect_to inbox_session_path(turn.session_id), alert: e. end |