Class: AgUi::Server::RecordingBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ag_ui/server.rb

Overview

Wraps the StreamBuilder so opened runs record into the store.

Instance Method Summary collapse

Constructor Details

#initialize(builder, store) ⇒ RecordingBuilder

Returns a new instance of RecordingBuilder.



159
160
161
162
# File 'lib/ag_ui/server.rb', line 159

def initialize(builder, store)
  @builder = builder
  @store = store
end

Instance Method Details

#open(thread_id:, run_id:, validate: true, &block) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ag_ui/server.rb', line 164

def open(thread_id:, run_id:, validate: true, &block)
  @store.begin_run(thread_id, run_id)

  @builder.open(
    thread_id: thread_id,
    run_id: run_id,
    validate: validate,
    on_event: ->(payload) { @store.record(thread_id, payload) },
    on_finish: -> { @store.finish_run(thread_id) },
    on_task: ->(task) { @store.attach_task(thread_id, task) },
    &block
  )
end