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
- #cost_label(cost) ⇒ Object
- #pretty_args(hash) ⇒ Object
-
#silas_engine_path(helper, *args) ⇒ Object
Engine paths that resolve in EVERY render context.
-
#silas_relative_time(time) ⇒ Object
Prefixed: this helper is registered host-wide (broadcast renders need it), and "relative_time" is exactly the name a host app would define.
- #status_pill(status) ⇒ Object
-
#step_structured(step) ⇒ Object
The final_answer payload, when the agent declared a schema.
- #step_text(step) ⇒ Object
Instance Method Details
#cost_label(cost) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/silas/inbox/trace_helper.rb', line 30 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
26 27 28 |
# File 'app/helpers/silas/inbox/trace_helper.rb', line 26 def pretty_args(hash) JSON.pretty_generate(hash || {}) end |
#silas_engine_path(helper, *args) ⇒ Object
Engine paths that resolve in EVERY render context. The mounted proxy
(silas.) leans on the rendering scope's url_options, which Turbo's
bare broadcast renderer doesn't have — so broadcast-rendered partials
build paths from the engine's own route set + the discovered mount.
52 53 54 |
# File 'app/helpers/silas/inbox/trace_helper.rb', line 52 def silas_engine_path(helper, *args) Silas::Engine.routes.url_helpers.public_send(helper, *args, script_name: Silas::Inbox.mount_path) end |
#silas_relative_time(time) ⇒ Object
Prefixed: this helper is registered host-wide (broadcast renders need it), and "relative_time" is exactly the name a host app would define.
42 43 44 45 46 |
# File 'app/helpers/silas/inbox/trace_helper.rb', line 42 def silas_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_structured(step) ⇒ Object
The final_answer payload, when the agent declared a schema.
22 23 24 |
# File 'app/helpers/silas/inbox/trace_helper.rb', line 22 def step_structured(step) Array(step.response_blocks).reverse.find { |b| b["type"] == "structured" }&.dig("data") 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 |