Class: RailsAgents::Base::RunResult
- Inherits:
-
Object
- Object
- RailsAgents::Base::RunResult
- Defined in:
- lib/rails_agents/base.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(response, client:) ⇒ RunResult
constructor
A new instance of RunResult.
-
#items ⇒ Object
Typed turn items: message (+ optional result).
-
#output ⇒ Object
Prefer the sync create_run body; otherwise drain the SSE stream.
-
#output_data ⇒ Object
Optional structured final payload (when a schema/result was requested).
-
#output_text ⇒ Object
Eve-aligned: final assistant Markdown (provider-agnostic).
- #run_id ⇒ Object
- #status ⇒ Object
- #stream(&block) ⇒ Object
- #trace ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
213 214 215 |
# File 'lib/rails_agents/base.rb', line 213 def client @client end |
#response ⇒ Object (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
#format ⇒ Object
271 272 273 |
# File 'lib/rails_agents/base.rb', line 271 def format response["format"] || dig_data("format") || "markdown" end |
#items ⇒ Object
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 |
#output ⇒ Object
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_data ⇒ Object
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_text ⇒ Object
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_id ⇒ Object
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 |
#status ⇒ Object
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 |
#trace ⇒ Object
279 280 281 |
# File 'lib/rails_agents/base.rb', line 279 def trace response["trace"] || dig_data("trace") end |