Class: Rubino::API::Operations::Sessions::RetryOperation
- Inherits:
-
Object
- Object
- Rubino::API::Operations::Sessions::RetryOperation
- Defined in:
- lib/rubino/api/operations/sessions/retry_operation.rb
Overview
POST /v1/sessions/:id/retry Deletes the last user message and everything after it, then enqueues a fresh run with the same input. Returns 202 with the new run id.
Class Method Summary collapse
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(session_repository: nil, message_store: nil, run_repository: nil, executor: nil) ⇒ RetryOperation
constructor
Accepts alternate collaborators (session repo, message store, run repo, executor) for tests.
Constructor Details
#initialize(session_repository: nil, message_store: nil, run_repository: nil, executor: nil) ⇒ RetryOperation
Accepts alternate collaborators (session repo, message store, run repo, executor) for tests.
20 21 22 23 24 25 |
# File 'lib/rubino/api/operations/sessions/retry_operation.rb', line 20 def initialize(session_repository: nil, message_store: nil, run_repository: nil, executor: nil) @session_repo = session_repository || ::Rubino::Session::Repository.new @message_store = || ::Rubino::Session::Store.new @run_repo = run_repository || ::Rubino::Run::Repository.new @executor = executor || ::Rubino::Run::Executor.new end |
Class Method Details
.call(request) ⇒ Object
15 16 17 |
# File 'lib/rubino/api/operations/sessions/retry_operation.rb', line 15 def self.call(request) new.call(request) end |
Instance Method Details
#call(request) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubino/api/operations/sessions/retry_operation.rb', line 27 def call(request) session_id = request.params.fetch("id") raise NotFoundError.new("session", session_id) unless @session_repo.find(session_id) last_user = @message_store.last_for_role(session_id, "user") raise ConflictError, "no user message to retry" unless last_user @message_store.delete_from_inclusive(session_id, from_id: last_user.id) run = @run_repo.create(session_id: session_id, input_text: last_user.content) @executor.start(run) [202, { run_id: run[:id], session_id: session_id, status: "running" }] end |