Class: Miniswen::Agent::Result

Inherits:
Data
  • Object
show all
Defined in:
lib/miniswen/agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cached_tokensObject (readonly)

Returns the value of attribute cached_tokens

Returns:

  • (Object)

    the current value of cached_tokens



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def cached_tokens
  @cached_tokens
end

#cost_sourceObject (readonly)

Returns the value of attribute cost_source

Returns:

  • (Object)

    the current value of cost_source



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def cost_source
  @cost_source
end

#cost_usdObject (readonly)

Returns the value of attribute cost_usd

Returns:

  • (Object)

    the current value of cost_usd



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def cost_usd
  @cost_usd
end

#errorObject (readonly)

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def error
  @error
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def input_tokens
  @input_tokens
end

#messagesObject (readonly)

Returns the value of attribute messages

Returns:

  • (Object)

    the current value of messages



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def messages
  @messages
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def output_tokens
  @output_tokens
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def status
  @status
end

#stepsObject (readonly)

Returns the value of attribute steps

Returns:

  • (Object)

    the current value of steps



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def steps
  @steps
end

#submissionObject (readonly)

Returns the value of attribute submission

Returns:

  • (Object)

    the current value of submission



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def submission
  @submission
end

#thinking_tokensObject (readonly)

Returns the value of attribute thinking_tokens

Returns:

  • (Object)

    the current value of thinking_tokens



188
189
190
# File 'lib/miniswen/agent.rb', line 188

def thinking_tokens
  @thinking_tokens
end

Class Method Details

.deep_symbolize(value) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/miniswen/agent.rb', line 212

def self.deep_symbolize(value)
  case value
  when Hash
    value.to_h do |key, item|
      key = key.to_sym
      # Tool-call arguments and reasoning details keep their provider-style string keys.
      [key, %i[arguments reasoning_details].include?(key) ? item : deep_symbolize(item)]
    end
  when Array then value.map { deep_symbolize(_1) }
  else value
  end
end

.from_h(payload) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/miniswen/agent.rb', line 195

def self.from_h(payload)
  data = deep_symbolize(payload)
  source = data[:cost_source]
  new(
    status: data[:status]&.to_sym,
    submission: data[:submission],
    messages: data[:messages] || [],
    steps: data[:steps],
    cost_source: source && CostSource.new(name: source[:name]&.to_sym, model: source[:model],
                                          priced_as: source[:priced_as], registry: source[:registry]),
    input_tokens: data[:input_tokens], output_tokens: data[:output_tokens],
    cached_tokens: data[:cached_tokens], thinking_tokens: data[:thinking_tokens],
    cost_usd: data[:cost_usd],
    error: data[:error]
  )
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


191
# File 'lib/miniswen/agent.rb', line 191

def success? = status == :submitted

#to_hObject



193
# File 'lib/miniswen/agent.rb', line 193

def to_h = super.merge(cost_source: cost_source&.to_h, version: Miniswen::VERSION)