module RubyLLM::AgUI::Rails::Streaming

The controller concern that serves one AG-UI run as one SSE response.

class AgentRunsController < ApplicationController
  include RubyLLM::AgUI::Rails::Streaming

  def create
    stream_ag_ui_run do |input|
      chat = ag_ui_chats.find_by!(ag_ui_thread_id: input.thread_id)
      authorize! chat
      chat
    end
  end
end

What the host owns, and the concern never guesses:

Refusals are decided before the response is committed, so a client that cannot read an event stream, or that sent an input the gem will not accept, gets a status code instead of half a run.