Skip to content
Kward Search API index

Class: Kward::SessionTreeRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/session_tree_renderer.rb

Overview

Terminal renderer for persisted session tree choices.

Instance Method Summary collapse

Constructor Details

#initialize(roots:, current_leaf_id:) ⇒ SessionTreeRenderer

Returns a new instance of SessionTreeRenderer.



10
11
12
13
# File 'lib/kward/session_tree_renderer.rb', line 10

def initialize(roots:, current_leaf_id:)
  @roots = roots
  @current_leaf_id = current_leaf_id
end

Instance Method Details

#itemsObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kward/session_tree_renderer.rb', line 15

def items
  tree_nodes = SessionTreeNodes.new(roots: @roots, current_leaf: @current_leaf_id)
  tool_calls_by_id = tree_nodes.tool_calls

  tree_nodes.layout_rows.map do |row|
    prefix = row[:prefix].empty? ? "" : "      #{row[:prefix]}"
    {
      entry: row[:entry],
      label: session_tree_label(row[:entry], row[:source], prefix, row[:active_path], tool_calls_by_id)
    }
  end
end