Class: Kward::RPC::SessionTreeRows
- Inherits:
-
Object
- Object
- Kward::RPC::SessionTreeRows
- Defined in:
- lib/kward/rpc/session_tree_rows.rb
Overview
Builds frontend-neutral RPC row payloads from a persisted session tree.
SessionManager owns session lifecycle and decides when a tree is needed;
this class owns only the mechanics of flattening tree nodes into the row
fields sent over JSON-RPC. Keeping row presentation here prevents the RPC
session coordinator from accumulating rendering details while preserving the
exact RPC payload shape.
Instance Method Summary collapse
-
#initialize(roots:, current_leaf:, selectable:) ⇒ SessionTreeRows
constructor
A new instance of SessionTreeRows.
-
#rows ⇒ Array<Hash>
Returns flattened RPC row hashes in active-path-first display order.
Constructor Details
#initialize(roots:, current_leaf:, selectable:) ⇒ SessionTreeRows
Returns a new instance of SessionTreeRows.
21 22 23 24 25 |
# File 'lib/kward/rpc/session_tree_rows.rb', line 21 def initialize(roots:, current_leaf:, selectable:) @roots = roots @current_leaf = current_leaf @selectable = selectable end |
Instance Method Details
#rows ⇒ Array<Hash>
Returns flattened RPC row hashes in active-path-first display order.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kward/rpc/session_tree_rows.rb', line 30 def rows tree_nodes = SessionTreeNodes.new(roots: @roots, current_leaf: @current_leaf) tool_calls_by_id = tree_nodes.tool_calls tree_nodes.layout_rows.map do |row| entry = row[:entry] entry_id = entry["id"].to_s formatted = tree_entry_display(entry, tool_calls_by_id) { entryId: entry_id, parentId: entry["parentId"], role: formatted[:role], text: formatted[:text], current: !@current_leaf.to_s.empty? && entry_id == @current_leaf.to_s, depth: row[:depth], isLast: row[:is_last], ancestorContinues: row[:gutters].map { |gutter| gutter[:show] }, activePath: row[:active_path], selectable: @selectable.call(entry), label: row[:source]["label"] || entry["resolvedLabel"], labelTimestamp: row[:source]["labelTimestamp"], prefix: row[:prefix] }.compact end end |