transcript-viewer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +154 -0
  4. data/assets/dark.json +85 -0
  5. data/assets/template.css +1078 -0
  6. data/lib/transcript_viewer/configuration.rb +17 -0
  7. data/lib/transcript_viewer/page.rb +42 -0
  8. data/lib/transcript_viewer/renderer.rb +367 -0
  9. data/lib/transcript_viewer/support.rb +38 -0
  10. data/lib/transcript_viewer/templates/app.html.erb +10 -0
  11. data/lib/transcript_viewer/templates/assistant_block.html.erb +10 -0
  12. data/lib/transcript_viewer/templates/compaction.html.erb +3 -0
  13. data/lib/transcript_viewer/templates/entry.html.erb +3 -0
  14. data/lib/transcript_viewer/templates/fetch_tool_table.html.erb +1 -0
  15. data/lib/transcript_viewer/templates/fork_bar.html.erb +1 -0
  16. data/lib/transcript_viewer/templates/hamburger.html.erb +3 -0
  17. data/lib/transcript_viewer/templates/header.html.erb +5 -0
  18. data/lib/transcript_viewer/templates/info_item.html.erb +1 -0
  19. data/lib/transcript_viewer/templates/main_content.html.erb +11 -0
  20. data/lib/transcript_viewer/templates/message_entry.html.erb +8 -0
  21. data/lib/transcript_viewer/templates/message_tree_content.html.erb +2 -0
  22. data/lib/transcript_viewer/templates/script.html.erb +80 -0
  23. data/lib/transcript_viewer/templates/server_tool_use.html.erb +4 -0
  24. data/lib/transcript_viewer/templates/session.html.erb +13 -0
  25. data/lib/transcript_viewer/templates/sidebar.html.erb +1 -0
  26. data/lib/transcript_viewer/templates/tool_call.html.erb +6 -0
  27. data/lib/transcript_viewer/templates/tree_content.html.erb +2 -0
  28. data/lib/transcript_viewer/templates/tree_node.html.erb +4 -0
  29. data/lib/transcript_viewer/tool_execution.rb +74 -0
  30. data/lib/transcript_viewer/tool_template_registry.rb +67 -0
  31. data/lib/transcript_viewer/version.rb +5 -0
  32. data/lib/transcript_viewer/view.rb +475 -0
  33. data/lib/transcript_viewer.rb +47 -0
  34. metadata +76 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8a80438f994b3a96d79edff990c80ebb54f1a4b22f1c3de5a3d265d4658dfb3d
4
+ data.tar.gz: 4737dd99ed1c92b7bf8883af889b3845e1d1a58c6a78907df9d6892643dc91bf
5
+ SHA512:
6
+ metadata.gz: 7e76bedd2db7b0aa7e51b293c698c02991579fa26556f5824f0268ba197f74a9aead0f6f2aebd9c59b1acaa5102df2048646cd2a8e08152162be1b32f2e30836
7
+ data.tar.gz: 3d1dc552dabef7b8ca38cfcc849d28043bfc56fceeb074792fa659e783954cb654c70670c78970aa24f7ef862352dbdbe6b55a46dabad4d8a122c25255b733dc
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # transcript-viewer
2
+
3
+ Pure Ruby renderer for LLM/agent transcript event hashes. It generates a self-contained HTML page with embedded CSS and JavaScript.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ require "transcript_viewer"
9
+
10
+ html = TranscriptViewer.render(
11
+ session_id: 103,
12
+ events: [
13
+ {
14
+ id: "1",
15
+ parent_id: nil,
16
+ timestamp: Time.now.iso8601,
17
+ type: "message",
18
+ usage: nil,
19
+ data: {
20
+ role: "assistant",
21
+ content: [{ type: "text", text: "Hello" }],
22
+ },
23
+ },
24
+ ],
25
+ export_href: "/admin/agent_session/103/export",
26
+ )
27
+
28
+ File.write("session.html", html)
29
+ ```
30
+
31
+ ## Composable rendering
32
+
33
+ Use `TranscriptViewer.page` when the host application owns the surrounding page chrome. The page normalizes the transcript once and can render its stylesheet, interactive transcript application, and JavaScript separately:
34
+
35
+ ```ruby
36
+ page = TranscriptViewer.page(session_id: 103, events: events)
37
+
38
+ page.stylesheet # CSS string
39
+ page.app_html # Sidebar and transcript content
40
+ page.javascript # Script tag for transcript interactions
41
+ page.render # The complete standalone HTML document
42
+ ```
43
+
44
+ Pass trusted host markup with `before_html:` and `after_html:` to place application controls above and below the transcript within `app_html`:
45
+
46
+ ```ruby
47
+ page = TranscriptViewer.page(
48
+ session_id: 103,
49
+ events: events,
50
+ before_html: "<section>Run controls</section>",
51
+ after_html: "<form>Continue</form>",
52
+ )
53
+ ```
54
+
55
+ The host is responsible for placing the stylesheet in its document head and the JavaScript after `app_html`.
56
+
57
+ ## Custom tool templates
58
+
59
+ Consumers can register an ERB for an exact tool name. Registration is normally done once during application startup:
60
+
61
+ ```ruby
62
+ TranscriptViewer.configure do |config|
63
+ config.register_tool_template(
64
+ "fetch_pull_requests",
65
+ File.expand_path("templates/tools/fetch_pull_requests.html.erb", __dir__),
66
+ )
67
+ end
68
+ ```
69
+
70
+ A tool template receives a `tool` local and can use renderer helpers such as `h` and `pretty_json`:
71
+
72
+ ```erb
73
+ <section class="pull-request-tool" data-status="<%= h(tool.status) %>">
74
+ <h2><%= h(tool.name) %></h2>
75
+ <pre><%= h(pretty_json(tool.input)) %></pre>
76
+
77
+ <% if tool.result_json %>
78
+ <pre><%= h(pretty_json(tool.result_json)) %></pre>
79
+ <% elsif tool.result_text != "" %>
80
+ <pre><%= h(tool.result_text) %></pre>
81
+ <% end %>
82
+ </section>
83
+ ```
84
+
85
+ The tool execution interface includes:
86
+
87
+ - `name`, `id`, `input` (also available as `arguments`)
88
+ - `result`, `result_content`, `result_text`, `result_json`, and `images`
89
+ - `status`, `pending?`, `success?`, and `error?`
90
+ - `call` and `result_entry` for access to the normalized underlying hashes
91
+
92
+ Templates can also be supplied for one render. These override globally registered templates with the same tool name:
93
+
94
+ ```ruby
95
+ TranscriptViewer.render(
96
+ session_id: 103,
97
+ events: events,
98
+ tool_templates: {
99
+ "fetch_pull_requests" => "/path/to/fetch_pull_requests.html.erb",
100
+ },
101
+ )
102
+ ```
103
+
104
+ Unregistered tools retain the built-in display. Server tools also use their existing built-in display for now.
105
+
106
+ ## Rails adapter example
107
+
108
+ This gem does not depend on Rails or ActiveSupport. In a Rails app, keep database access in the app and pass plain hashes into the renderer:
109
+
110
+ ```ruby
111
+ session = AgentSession.find(params[:session_id])
112
+
113
+ events = session.agent_session_events.order(:position).map do |event|
114
+ {
115
+ id: event.event_id,
116
+ parent_id: event.parent_id,
117
+ timestamp: event.timestamp&.iso8601,
118
+ type: event.event_type,
119
+ usage: event.usage_json,
120
+ data: event.data_json,
121
+ }
122
+ end
123
+
124
+ html = TranscriptViewer.render(
125
+ session_id: session.id,
126
+ events: events,
127
+ export_href: admin_export_agent_session_path(session.id),
128
+ forked_transcript: params[:forked_transcript],
129
+ ancestor_lookup: lambda do |event_id|
130
+ event = AgentSessionEvent.find_by(event_id: event_id)
131
+ next nil unless event
132
+
133
+ {
134
+ id: event.event_id,
135
+ parent_id: event.parent_id,
136
+ timestamp: event.timestamp&.iso8601,
137
+ type: event.event_type,
138
+ usage: event.usage_json,
139
+ data: event.data_json,
140
+ }
141
+ end,
142
+ )
143
+
144
+ render html: html.html_safe, layout: false
145
+ ```
146
+
147
+ ## Supported event types
148
+
149
+ - `message`
150
+ - `reasoning_change`
151
+ - `model_change`
152
+ - `compaction`
153
+
154
+ Message content supports text, thinking/reasoning, tool calls/results, and server tool use/results.
data/assets/dark.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json",
3
+ "name": "dark",
4
+ "vars": {
5
+ "cyan": "#00d7ff",
6
+ "blue": "#5f87ff",
7
+ "green": "#b5bd68",
8
+ "red": "#cc6666",
9
+ "yellow": "#ffff00",
10
+ "gray": "#808080",
11
+ "dimGray": "#666666",
12
+ "darkGray": "#505050",
13
+ "accent": "#8abeb7",
14
+ "selectedBg": "#3a3a4a",
15
+ "userMsgBg": "#343541",
16
+ "toolPendingBg": "#282832",
17
+ "toolSuccessBg": "#283228",
18
+ "toolErrorBg": "#3c2828",
19
+ "customMsgBg": "#2d2838"
20
+ },
21
+ "colors": {
22
+ "accent": "accent",
23
+ "border": "blue",
24
+ "borderAccent": "cyan",
25
+ "borderMuted": "darkGray",
26
+ "success": "green",
27
+ "error": "red",
28
+ "warning": "yellow",
29
+ "muted": "gray",
30
+ "dim": "dimGray",
31
+ "text": "",
32
+ "thinkingText": "gray",
33
+
34
+ "selectedBg": "selectedBg",
35
+ "userMessageBg": "userMsgBg",
36
+ "userMessageText": "",
37
+ "customMessageBg": "customMsgBg",
38
+ "customMessageText": "",
39
+ "customMessageLabel": "#9575cd",
40
+ "toolPendingBg": "toolPendingBg",
41
+ "toolSuccessBg": "toolSuccessBg",
42
+ "toolErrorBg": "toolErrorBg",
43
+ "toolTitle": "",
44
+ "toolOutput": "gray",
45
+
46
+ "mdHeading": "#f0c674",
47
+ "mdLink": "#81a2be",
48
+ "mdLinkUrl": "dimGray",
49
+ "mdCode": "accent",
50
+ "mdCodeBlock": "green",
51
+ "mdCodeBlockBorder": "gray",
52
+ "mdQuote": "gray",
53
+ "mdQuoteBorder": "gray",
54
+ "mdHr": "gray",
55
+ "mdListBullet": "accent",
56
+
57
+ "toolDiffAdded": "green",
58
+ "toolDiffRemoved": "red",
59
+ "toolDiffContext": "gray",
60
+
61
+ "syntaxComment": "#6A9955",
62
+ "syntaxKeyword": "#569CD6",
63
+ "syntaxFunction": "#DCDCAA",
64
+ "syntaxVariable": "#9CDCFE",
65
+ "syntaxString": "#CE9178",
66
+ "syntaxNumber": "#B5CEA8",
67
+ "syntaxType": "#4EC9B0",
68
+ "syntaxOperator": "#D4D4D4",
69
+ "syntaxPunctuation": "#D4D4D4",
70
+
71
+ "thinkingOff": "darkGray",
72
+ "thinkingMinimal": "#6e6e6e",
73
+ "thinkingLow": "#5f87af",
74
+ "thinkingMedium": "#81a2be",
75
+ "thinkingHigh": "#b294bb",
76
+ "thinkingXhigh": "#d183e8",
77
+
78
+ "bashMode": "green"
79
+ },
80
+ "export": {
81
+ "pageBg": "#18181e",
82
+ "cardBg": "#1e1e24",
83
+ "infoBg": "#3c3728"
84
+ }
85
+ }