Module: Silas::Inbox::TraceHelper

Defined in:
app/helpers/silas/inbox/trace_helper.rb

Constant Summary collapse

STATUS_CLASS =
{
  "queued" => "pill-grey", "running" => "pill-blue pill-pulse",
  "waiting" => "pill-amber", "in_doubt" => "pill-amber",
  "completed" => "pill-green", "failed" => "pill-red", "canceled" => "pill-red",
  # tool-invocation statuses
  "pending" => "pill-grey", "started" => "pill-blue", "declined" => "pill-red",
  "approved" => "pill-green", "required" => "pill-amber", "expired" => "pill-red"
}.freeze

Instance Method Summary collapse

Instance Method Details

#cost_label(cost) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/helpers/silas/inbox/trace_helper.rb', line 25

def cost_label(cost)
  tokens = "#{number_with_delimiter(cost[:input_tokens])} in / #{number_with_delimiter(cost[:output_tokens])} out"
  money = Silas::Inbox::Cost.format(cost[:microcents])
  if cost[:unpriced] || money.nil?
    "#{tokens} · cost unavailable"
  else
    "#{tokens} · #{money}"
  end
end

#pretty_args(hash) ⇒ Object



21
22
23
# File 'app/helpers/silas/inbox/trace_helper.rb', line 21

def pretty_args(hash)
  JSON.pretty_generate(hash || {})
end

#relative_time(time) ⇒ Object



35
36
37
38
39
# File 'app/helpers/silas/inbox/trace_helper.rb', line 35

def relative_time(time)
  return "" unless time

  "#{time_ago_in_words(time)} ago"
end

#status_pill(status) ⇒ Object



13
14
15
# File 'app/helpers/silas/inbox/trace_helper.rb', line 13

def status_pill(status)
  tag.span(status.to_s.tr("_", " "), class: "pill #{STATUS_CLASS[status.to_s] || 'pill-grey'}")
end

#step_text(step) ⇒ Object



17
18
19
# File 'app/helpers/silas/inbox/trace_helper.rb', line 17

def step_text(step)
  Array(step.response_blocks).select { |b| b["type"] == "text" }.map { |b| b["text"] }.join.presence
end