Class: RailsAgents::Base::RunResult

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_agents/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, client:) ⇒ RunResult

Returns a new instance of RunResult.



215
216
217
218
# File 'lib/rails_agents/base.rb', line 215

def initialize(response, client:)
  @response = response
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



213
214
215
# File 'lib/rails_agents/base.rb', line 213

def client
  @client
end

#responseObject (readonly)

Returns the value of attribute response.



213
214
215
# File 'lib/rails_agents/base.rb', line 213

def response
  @response
end

Instance Method Details

#formatObject



271
272
273
# File 'lib/rails_agents/base.rb', line 271

def format
  response["format"] || dig_data("format") || "markdown"
end

#itemsObject

Typed turn items: message (+ optional result). Tool trail lives on #trace.



267
268
269
# File 'lib/rails_agents/base.rb', line 267

def items
  response["items"] || dig_data("items") || []
end

#outputObject

Prefer the sync create_run body; otherwise drain the SSE stream. Legacy alias for output_text (Markdown final answer).



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rails_agents/base.rb', line 232

def output
  text = output_text
  return text if text.is_a?(String) && !text.empty?

  final = nil
  chunks = []
  stream do |event|
    # Prefer terminal / normalized payloads (done / output events).
    if event["output_text"].is_a?(String) && !event["output_text"].empty?
      final = event["output_text"]
    elsif event["output"].is_a?(String) && !event["output"].empty? &&
          (event.key?("items") || event.key?("format") || event.key?("status"))
      final = event["output"]
    else
      piece = event["content"] || event["text"]
      chunks << piece if piece.is_a?(String) && !piece.empty?
    end
  end
  final || chunks.join
end

#output_dataObject

Optional structured final payload (when a schema/result was requested).



262
263
264
# File 'lib/rails_agents/base.rb', line 262

def output_data
  response["output_data"] || dig_data("output_data")
end

#output_textObject

Eve-aligned: final assistant Markdown (provider-agnostic).



254
255
256
257
258
259
# File 'lib/rails_agents/base.rb', line 254

def output_text
  response["output_text"] ||
    dig_data("output_text") ||
    response["output"] ||
    dig_data("output")
end

#run_idObject



220
221
222
223
224
# File 'lib/rails_agents/base.rb', line 220

def run_id
  response["id"] ||
    response["run_id"] ||
    dig_data("id")
end

#statusObject



275
276
277
# File 'lib/rails_agents/base.rb', line 275

def status
  response["status"] || dig_data("status")
end

#stream(&block) ⇒ Object



226
227
228
# File 'lib/rails_agents/base.rb', line 226

def stream(&block)
  client.stream_run(run_id, &block)
end

#traceObject



279
280
281
# File 'lib/rails_agents/base.rb', line 279

def trace
  response["trace"] || dig_data("trace")
end