Module: LlmCostTracker::Capture::SdkPayload

Defined in:
lib/llm_cost_tracker/capture/sdk_payload.rb

Class Method Summary collapse

Class Method Details

.container_for(value) ⇒ Object



27
28
29
30
31
# File 'lib/llm_cost_tracker/capture/sdk_payload.rb', line 27

def container_for(value)
  value.try(:deep_to_h) || value.try(:to_h)
rescue StandardError
  nil
end

.normalize(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/llm_cost_tracker/capture/sdk_payload.rb', line 11

def normalize(value)
  case value
  when Hash
    value.each_with_object({}) { |(key, nested), out| out[key.to_s] = normalize(nested) }
  when Array
    value.map { |nested| normalize(nested) }
  when Symbol
    value.to_s
  when NilClass
    nil
  else
    converted = container_for(value)
    converted ? normalize(converted) : value.deep_dup
  end
end