Class: TranscriptViewer::View
- Inherits:
-
Object
- Object
- TranscriptViewer::View
- Defined in:
- lib/transcript_viewer/view.rb
Constant Summary collapse
- DEFAULT_ASSET_DIR =
File.("../../assets", __dir__)
Instance Method Summary collapse
-
#initialize(session_id:, events:, forked_transcript: false, ancestor_lookup: nil, export_href: nil, forked_transcript_href: nil, hide_forked_transcript_href: nil, asset_dir: nil) ⇒ View
constructor
A new instance of View.
- #to_h ⇒ Object
Constructor Details
#initialize(session_id:, events:, forked_transcript: false, ancestor_lookup: nil, export_href: nil, forked_transcript_href: nil, hide_forked_transcript_href: nil, asset_dir: nil) ⇒ View
Returns a new instance of View.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/transcript_viewer/view.rb', line 13 def initialize(session_id:, events:, forked_transcript: false, ancestor_lookup: nil, export_href: nil, forked_transcript_href: nil, hide_forked_transcript_href: nil, asset_dir: nil) @session_id = session_id @events = events @forked_transcript = !!forked_transcript @ancestor_lookup = ancestor_lookup @export_href = export_href @forked_transcript_href = forked_transcript_href @hide_forked_transcript_href = hide_forked_transcript_href @asset_dir = asset_dir || DEFAULT_ASSET_DIR end |
Instance Method Details
#to_h ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/transcript_viewer/view.rb', line 24 def to_h session_entries = load_session_entries fork_parent_id = session_entries.first&.dig(:parent_id) ancestor_entries = forked_transcript ? load_ancestor_entries(fork_parent_id) : [] raw_entries = ancestor_entries + session_entries tool_name_by_call_id = build_tool_call_name_map(raw_entries) ancestor_count = ancestor_entries.map { |entry| map_entry(entry, tool_name_by_call_id) }.compact.length entries = normalize_parent_links( raw_entries.map { |entry| map_entry(entry, tool_name_by_call_id) }.compact, raw_entries, ) leaf_id = entries.last&.dig(:id) { css: stylesheet, header: build_header(entries), entries: entries, sidebar_entries: (entries, ancestor_count: ancestor_count), leaf_id: leaf_id, path_entries: path_to_entry(entries, leaf_id), stats: compute_stats(entries), forked_transcript_available: Support.present?(fork_parent_id), forked_transcript_enabled: forked_transcript, forked_ancestor_count: ancestor_count, export_href: export_href, forked_transcript_href: forked_transcript_href || "?forked_transcript=1", hide_forked_transcript_href: hide_forked_transcript_href || "?forked_transcript=0", } end |