Class: Smith::Workflow::UsageEntry

Inherits:
Struct
  • Object
show all
Defined in:
lib/smith/workflow.rb

Overview

One row per agent provider call. ‘usage_id` is a UUID generated at recording time and stable across persist/restore — hadithi uses it as the idempotency anchor on `usage_events.smith_usage_id`. Includes `to_h`/`from_h` for JSON serialization (plain Struct JSON-encodes to `“#<struct …>”` — useless).

keyword_init: true gives forward/backward compatibility:

  • Adding a new field: old persisted hashes restore cleanly (new field defaults to nil).

  • Reading new persisted hashes with an older Smith version: from_h slices to known members (unknown keys silently dropped).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#agent_nameObject

Returns the value of attribute agent_name

Returns:

  • (Object)

    the current value of agent_name



109
110
111
# File 'lib/smith/workflow.rb', line 109

def agent_name
  @agent_name
end

#attempt_kindObject

Returns the value of attribute attempt_kind

Returns:

  • (Object)

    the current value of attempt_kind



109
110
111
# File 'lib/smith/workflow.rb', line 109

def attempt_kind
  @attempt_kind
end

#costObject

Returns the value of attribute cost

Returns:

  • (Object)

    the current value of cost



109
110
111
# File 'lib/smith/workflow.rb', line 109

def cost
  @cost
end

#input_tokensObject

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



109
110
111
# File 'lib/smith/workflow.rb', line 109

def input_tokens
  @input_tokens
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



109
110
111
# File 'lib/smith/workflow.rb', line 109

def model
  @model
end

#output_tokensObject

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



109
110
111
# File 'lib/smith/workflow.rb', line 109

def output_tokens
  @output_tokens
end

#recorded_atObject

Returns the value of attribute recorded_at

Returns:

  • (Object)

    the current value of recorded_at



109
110
111
# File 'lib/smith/workflow.rb', line 109

def recorded_at
  @recorded_at
end

#usage_idObject

Returns the value of attribute usage_id

Returns:

  • (Object)

    the current value of usage_id



109
110
111
# File 'lib/smith/workflow.rb', line 109

def usage_id
  @usage_id
end

Class Method Details

.from_h(hash) ⇒ Object



120
121
122
123
124
125
126
127
128
# File 'lib/smith/workflow.rb', line 120

def self.from_h(hash)
  sym = hash.transform_keys(&:to_sym)
  filtered = sym.slice(*members)
  # Symbolize :agent_name and :attempt_kind for backward compat
  # with callers that consume the field as Symbol.
  filtered[:agent_name] = filtered[:agent_name].to_sym if filtered[:agent_name].is_a?(String)
  filtered[:attempt_kind] = filtered[:attempt_kind].to_sym if filtered[:attempt_kind].is_a?(String)
  new(**filtered)
end