This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new e731d88c25b1 CAMEL-27135: camel-jbang - press t on a GenAI span in the 
Spans tab to read its conversation (#30522)
e731d88c25b1 is described below

commit e731d88c25b177f2fcac1ad66d9ef1d8bb476918
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 20 22:23:59 2026 +0100

    CAMEL-27135: camel-jbang - press t on a GenAI span in the Spans tab to read 
its conversation (#30522)
    
    At GenAI observability level full the spans carry the messages as JSON 
strings, shown as one line each in the detail panel. GenAiTranscript turns them 
into a conversation (system instructions, user and assistant messages, each 
tool call with its arguments and its result, the finish reason); an agent run 
shows its last model call, which holds the whole run. t opens it as Markdown 
over the waterfall, and the detail panel of a GenAI span says whether there are 
messages or at which level  [...]
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../images/jbang/camel-tui-spans-conversation.png  | Bin 0 -> 235261 bytes
 .../ROOT/pages/camel-jbang-tui-observe.adoc        |   7 +
 .../jbang/core/commands/tui/GenAiTranscript.java   | 375 +++++++++++++++++++++
 .../dsl/jbang/core/commands/tui/SpansTab.java      |  74 ++++
 .../jbang/core/commands/tui/TranscriptOverlay.java | 154 +++++++++
 .../src/main/resources/tui/help/spans.md           |  19 ++
 .../core/commands/tui/GenAiTranscriptTest.java     | 206 +++++++++++
 .../core/commands/tui/SpansTabRenderTest.java      |  62 ++++
 8 files changed, 897 insertions(+)

diff --git 
a/docs/user-manual/modules/ROOT/images/jbang/camel-tui-spans-conversation.png 
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-spans-conversation.png
new file mode 100644
index 000000000000..51459c7a7ebb
Binary files /dev/null and 
b/docs/user-manual/modules/ROOT/images/jbang/camel-tui-spans-conversation.png 
differ
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
index bbb2ace40c32..57da30036add 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
@@ -264,10 +264,17 @@ Features:
 * *Sort and search* -- sort by trace ID, route, status, duration, or span 
count;
   filter with text search
 * *Error highlighting* -- failed spans (status ERROR) are highlighted in red
+* *AI conversations* -- on a GenAI span (a model call, an agent run or a tool 
call), press *t* to read its
+  conversation: the system instructions, the user and assistant messages, and 
each tool call with its arguments
+  and result. An agent run shows the input and output of its last model call, 
which hold the whole run. The
+  messages are recorded at the GenAI observability level `full` 
(`camel.aiObservability.level=full`); at a lower
+  level the detail panel says so
 
 This is especially useful for understanding latency in multi-route 
integrations and for
 correlating Camel processing with external service calls (HTTP, database, 
messaging).
 
+image::jbang/camel-tui-spans-conversation.png[The conversation of an agent 
run: the question, the call of a route tool with its result, and the answer]
+
 == Process Information
 
 The Process tab (under More, shortcut *p*) shows JVM process details for the 
selected
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscript.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscript.java
new file mode 100644
index 000000000000..83782d2e1f85
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscript.java
@@ -0,0 +1,375 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiMessages;
+import org.apache.camel.component.ai.observability.GenAiOperationName;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+
+/**
+ * The conversation of a GenAI span, from the message attributes the Camel AI 
producers record at observability level
+ * {@code full} ({@code gen_ai.system_instructions}, {@code 
gen_ai.input.messages}, {@code gen_ai.output.messages}, and
+ * the arguments and result of a tool call), in the shape of the OpenTelemetry 
GenAI semantic conventions: messages with
+ * a {@code role} and {@code parts} of type {@code text}, {@code reasoning}, 
{@code tool_call} and
+ * {@code tool_call_response}.
+ * <p/>
+ * An agent run ({@code invoke_agent}) shows the input and output of its last 
model call: that input already holds the
+ * whole conversation of the run, with every tool call and result.
+ */
+final class GenAiTranscript {
+
+    enum Kind {
+        TEXT,
+        REASONING,
+        TOOL_CALL,
+        TOOL_RESULT
+    }
+
+    /**
+     * A part of a message: a text, a tool call with its arguments, or a tool 
result. {@code id} pairs a tool call with
+     * its result.
+     */
+    record Part(Kind kind, String text, String toolName, String id) {
+
+        Part(Kind kind, String text) {
+            this(kind, text, null, null);
+        }
+    }
+
+    /** A message: its role (system, user, assistant, tool), its parts, and 
the finish reason of an output message. */
+    record Turn(String role, List<Part> parts, String finishReason) {
+    }
+
+    /** The mark {@code GenAiMessages} puts at the end of a text cut at {@code 
contentMaxLength}. */
+    static final String TRUNCATED = "...[truncated]";
+
+    private static final List<String> CONTENT_ATTRIBUTES = List.of(
+            GenAiAttributes.INPUT_MESSAGES, GenAiAttributes.OUTPUT_MESSAGES, 
GenAiAttributes.SYSTEM_INSTRUCTIONS,
+            GenAiAttributes.TOOL_CALL_ARGUMENTS, 
GenAiAttributes.TOOL_CALL_RESULT);
+    private static final int MAX_PARENT_HOPS = 50;
+
+    private final List<Turn> turns;
+
+    private GenAiTranscript(List<Turn> turns) {
+        this.turns = List.copyOf(turns);
+    }
+
+    List<Turn> turns() {
+        return turns;
+    }
+
+    boolean isEmpty() {
+        return turns.isEmpty();
+    }
+
+    /**
+     * The conversation as Markdown: a heading per message, the texts as they 
are (a model answers in Markdown), and the
+     * tool arguments and results as code blocks.
+     */
+    String toMarkdown() {
+        StringBuilder sb = new StringBuilder();
+        for (Turn turn : turns) {
+            sb.append("### ").append(heading(turn)).append("\n\n");
+            for (Part part : turn.parts()) {
+                switch (part.kind()) {
+                    case TEXT -> 
sb.append(markTruncated(part.text())).append("\n\n");
+                    case REASONING -> {
+                        for (String line : ("*Thinking:* " + 
markTruncated(part.text())).split("\n")) {
+                            sb.append("> ").append(line).append('\n');
+                        }
+                        sb.append('\n');
+                    }
+                    case TOOL_CALL -> {
+                        sb.append("Calls **").append(part.toolName() != null ? 
part.toolName() : "a tool").append("**\n\n");
+                        codeBlock(sb, part.text());
+                    }
+                    case TOOL_RESULT -> codeBlock(sb, part.text());
+                }
+            }
+        }
+        return sb.toString().strip();
+    }
+
+    private static String heading(Turn turn) {
+        String role = turn.role() != null && !turn.role().isEmpty() ? 
turn.role() : "message";
+        String heading = Character.toUpperCase(role.charAt(0)) + 
role.substring(1);
+        if (GenAiMessages.TOOL.equals(role)) {
+            String name = turn.parts().isEmpty() ? null : 
turn.parts().get(0).toolName();
+            if (name != null) {
+                heading += " " + name;
+            }
+        }
+        if (turn.finishReason() != null) {
+            heading += " · " + turn.finishReason();
+        }
+        return heading;
+    }
+
+    private static String markTruncated(String text) {
+        if (text == null) {
+            return "*(empty)*";
+        }
+        return text.endsWith(TRUNCATED)
+                ? text.substring(0, text.length() - TRUNCATED.length()) + " … 
*(truncated)*"
+                : text;
+    }
+
+    /** A tool argument or result: pretty JSON when it is JSON, else the text, 
in a fence it cannot close. */
+    private static void codeBlock(StringBuilder sb, String text) {
+        if (text == null) {
+            sb.append("*(empty)*\n\n");
+            return;
+        }
+        boolean truncated = text.endsWith(TRUNCATED);
+        String body = truncated ? text.substring(0, text.length() - 
TRUNCATED.length()) : text;
+        String language = "";
+        if (!truncated) {
+            try {
+                Object parsed = Jsoner.deserialize(body);
+                if (parsed instanceof Map || parsed instanceof List) {
+                    body = Jsoner.prettyPrint(body, 2);
+                    language = "json";
+                }
+            } catch (Exception e) {
+                // not JSON: shown as it is
+            }
+        }
+        String fence = body.contains("```") ? "````" : "```";
+        
sb.append(fence).append(language).append('\n').append(body.strip()).append('\n').append(fence).append("\n\n");
+        if (truncated) {
+            sb.append("*(truncated)*\n\n");
+        }
+    }
+
+    /** Whether the span is a GenAI span: a model call, an agent run or a tool 
call. */
+    static boolean isGenAiSpan(SpanEntry span) {
+        return span != null && span.attributes() != null
+                && 
span.attributes().containsKey(GenAiAttributes.OPERATION_NAME);
+    }
+
+    /** Whether the span carries message content, recorded at observability 
level {@code full}. */
+    static boolean hasContent(SpanEntry span) {
+        if (!isGenAiSpan(span)) {
+            return false;
+        }
+        for (String key : CONTENT_ATTRIBUTES) {
+            if (span.attributes().containsKey(key)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * The conversation of a GenAI span. {@code traceSpans} are the spans of 
its trace, where the model calls of an
+     * agent run are found.
+     */
+    static GenAiTranscript of(SpanEntry span, List<SpanEntry> traceSpans) {
+        if (!isGenAiSpan(span)) {
+            return new GenAiTranscript(List.of());
+        }
+        String operation = 
String.valueOf(span.attributes().get(GenAiAttributes.OPERATION_NAME));
+        if (GenAiOperationName.EXECUTE_TOOL.value().equals(operation)) {
+            return toolCall(span.attributes());
+        }
+        SpanEntry source = span;
+        if (GenAiOperationName.INVOKE_AGENT.value().equals(operation)) {
+            SpanEntry lastCall = lastModelCallOf(span, traceSpans);
+            if (lastCall != null) {
+                source = lastCall;
+            }
+        }
+        List<Turn> turns = new ArrayList<>();
+        // the system instructions of the run, when its model call has none of 
its own
+        String instructions = text(source.attributes(), 
GenAiAttributes.SYSTEM_INSTRUCTIONS);
+        if (instructions == null) {
+            instructions = text(span.attributes(), 
GenAiAttributes.SYSTEM_INSTRUCTIONS);
+        }
+        List<Turn> input = parseMessages(text(source.attributes(), 
GenAiAttributes.INPUT_MESSAGES));
+        if (instructions != null && !startsWithSystem(input)) {
+            List<Turn> system = parseMessages(instructions);
+            List<Part> parts = system.isEmpty()
+                    ? List.of(new Part(Kind.TEXT, instructions))
+                    : system.get(0).parts();
+            turns.add(new Turn(GenAiMessages.SYSTEM, parts, null));
+        }
+        turns.addAll(input);
+        turns.addAll(parseMessages(text(source.attributes(), 
GenAiAttributes.OUTPUT_MESSAGES)));
+        return new GenAiTranscript(nameToolResults(turns));
+    }
+
+    private static GenAiTranscript toolCall(Map<String, Object> attrs) {
+        String name = text(attrs, GenAiAttributes.TOOL_NAME);
+        List<Turn> turns = new ArrayList<>();
+        String arguments = text(attrs, GenAiAttributes.TOOL_CALL_ARGUMENTS);
+        if (arguments != null) {
+            turns.add(new Turn(GenAiMessages.ASSISTANT, List.of(new 
Part(Kind.TOOL_CALL, arguments, name, null)), null));
+        }
+        String result = text(attrs, GenAiAttributes.TOOL_CALL_RESULT);
+        if (result != null) {
+            turns.add(new Turn(GenAiMessages.TOOL, List.of(new 
Part(Kind.TOOL_RESULT, result, name, null)), null));
+        }
+        return new GenAiTranscript(turns);
+    }
+
+    /** The model call with messages that started last inside the agent run. */
+    private static SpanEntry lastModelCallOf(SpanEntry agent, List<SpanEntry> 
traceSpans) {
+        if (traceSpans == null || agent.spanId() == null) {
+            return null;
+        }
+        Map<String, SpanEntry> byId = new HashMap<>();
+        for (SpanEntry s : traceSpans) {
+            if (s.spanId() != null) {
+                byId.put(s.spanId(), s);
+            }
+        }
+        SpanEntry last = null;
+        for (SpanEntry s : traceSpans) {
+            if (s != agent && isGenAiSpan(s) && 
s.attributes().containsKey(GenAiAttributes.INPUT_MESSAGES)
+                    && !isAgentOrTool(s) && isInside(s, agent.spanId(), byId)
+                    && (last == null || s.startEpochNanos() >= 
last.startEpochNanos())) {
+                last = s;
+            }
+        }
+        return last;
+    }
+
+    private static boolean isAgentOrTool(SpanEntry span) {
+        Object operation = 
span.attributes().get(GenAiAttributes.OPERATION_NAME);
+        return GenAiOperationName.INVOKE_AGENT.value().equals(operation)
+                || GenAiOperationName.EXECUTE_TOOL.value().equals(operation);
+    }
+
+    private static boolean isInside(SpanEntry span, String ancestorId, 
Map<String, SpanEntry> byId) {
+        SpanEntry current = span;
+        for (int hops = 0; hops < MAX_PARENT_HOPS && current != null && 
!current.isRoot(); hops++) {
+            if (ancestorId.equals(current.parentSpanId())) {
+                return true;
+            }
+            current = byId.get(current.parentSpanId());
+        }
+        return false;
+    }
+
+    private static boolean startsWithSystem(List<Turn> turns) {
+        return !turns.isEmpty() && 
GenAiMessages.SYSTEM.equals(turns.get(0).role());
+    }
+
+    /** A tool result names its tool only by the id of the call: give it the 
name of that call. */
+    private static List<Turn> nameToolResults(List<Turn> turns) {
+        Map<String, String> namesById = new HashMap<>();
+        List<Turn> named = new ArrayList<>(turns.size());
+        for (Turn turn : turns) {
+            List<Part> parts = new ArrayList<>(turn.parts().size());
+            for (Part part : turn.parts()) {
+                if (part.kind() == Kind.TOOL_CALL && part.id() != null) {
+                    namesById.put(part.id(), part.toolName());
+                } else if (part.kind() == Kind.TOOL_RESULT && part.toolName() 
== null && part.id() != null) {
+                    part = new Part(Kind.TOOL_RESULT, part.text(), 
namesById.get(part.id()), part.id());
+                }
+                parts.add(part);
+            }
+            named.add(new Turn(turn.role(), parts, turn.finishReason()));
+        }
+        return named;
+    }
+
+    /**
+     * Parses a {@code gen_ai.*.messages} or {@code 
gen_ai.system_instructions} attribute. A value that is not a JSON
+     * array of messages is shown as one text.
+     */
+    static List<Turn> parseMessages(String json) {
+        if (json == null || json.isBlank()) {
+            return List.of();
+        }
+        Object parsed;
+        try {
+            parsed = Jsoner.deserialize(json);
+        } catch (Exception e) {
+            return List.of(new Turn(GenAiMessages.USER, List.of(new 
Part(Kind.TEXT, json)), null));
+        }
+        if (!(parsed instanceof JsonArray array)) {
+            return List.of(new Turn(GenAiMessages.USER, List.of(new 
Part(Kind.TEXT, json)), null));
+        }
+        List<Turn> turns = new ArrayList<>();
+        for (Object item : array) {
+            if (item instanceof JsonObject message) {
+                if (message.containsKey("role")) {
+                    turns.add(new Turn(
+                            message.getString("role"), 
parseParts(message.getCollection("parts")),
+                            message.getString("finish_reason")));
+                } else {
+                    // system instructions: an array of parts
+                    turns.add(new Turn(GenAiMessages.SYSTEM, 
parseParts(List.of(message)), null));
+                }
+            }
+        }
+        return turns;
+    }
+
+    private static List<Part> parseParts(Collection<?> parts) {
+        List<Part> result = new ArrayList<>();
+        if (parts == null) {
+            return result;
+        }
+        for (Object item : parts) {
+            if (!(item instanceof JsonObject part)) {
+                continue;
+            }
+            String type = part.getStringOrDefault("type", "text");
+            switch (type) {
+                case "tool_call" -> result.add(new Part(
+                        Kind.TOOL_CALL, jsonText(part.get("arguments")),
+                        part.getString("name"), part.getString("id")));
+                case "tool_call_response" -> result.add(new Part(
+                        Kind.TOOL_RESULT, jsonText(part.get("response")),
+                        null, part.getString("id")));
+                case "reasoning" -> result.add(new Part(Kind.REASONING, 
part.getString("content")));
+                default -> result.add(new Part(Kind.TEXT, 
jsonText(part.get("content"))));
+            }
+        }
+        return result;
+    }
+
+    private static String jsonText(Object value) {
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof String s) {
+            return s;
+        }
+        return Jsoner.serialize(value);
+    }
+
+    private static String text(Map<String, Object> attrs, String key) {
+        Object value = attrs != null ? attrs.get(key) : null;
+        if (value == null) {
+            return null;
+        }
+        String text = value.toString();
+        return text.isBlank() ? null : text;
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
index d308ff38e5a9..8b655074e6dc 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTab.java
@@ -79,6 +79,9 @@ class SpansTab extends AbstractTab {
     private int sortIndex;
     private boolean sortReversed;
     private final FilterField filter = new FilterField(this::filterChanged);
+    private final TranscriptOverlay transcript = new TranscriptOverlay();
+    /** The nodes the waterfall rendered last, for the footer (which renders 
every frame too). */
+    private List<WaterfallNode> renderedNodes = List.of();
 
     private volatile boolean spanRefreshRequested;
 
@@ -104,12 +107,16 @@ class SpansTab extends AbstractTab {
     @Override
     public void onIntegrationChanged() {
         spanRefreshRequested = true;
+        transcript.close();
         waterfallView = false;
         selectedTraceId = null;
     }
 
     @Override
     public boolean handleKeyEvent(KeyEvent ke) {
+        if (transcript.isVisible()) {
+            return transcript.handleKey(ke);
+        }
         if (waterfallView) {
             return handleWaterfallKeys(ke);
         }
@@ -194,6 +201,10 @@ class SpansTab extends AbstractTab {
             waterfallScroll = 0;
             return true;
         }
+        if (ke.isChar('t')) {
+            openTranscript();
+            return true;
+        }
         if (ke.isKey(KeyCode.F5)) {
             spanRefreshRequested = true;
             return true;
@@ -210,6 +221,12 @@ class SpansTab extends AbstractTab {
                 return true;
             }
         }
+        if (waterfallView && transcript.isVisible()) {
+            if (me.kind() == MouseEventKind.SCROLL_UP || me.kind() == 
MouseEventKind.SCROLL_DOWN) {
+                transcript.scrollBy(me.kind() == MouseEventKind.SCROLL_UP ? 
-MOUSE_SCROLL_LINES : MOUSE_SCROLL_LINES);
+            }
+            return true;
+        }
         if (waterfallView) {
             if (me.kind() == MouseEventKind.SCROLL_UP) {
                 if (waterfallSelected > 0) {
@@ -228,6 +245,10 @@ class SpansTab extends AbstractTab {
 
     @Override
     public boolean handleEscape() {
+        if (transcript.isVisible()) {
+            transcript.close();
+            return true;
+        }
         if (filter.isEditing()) {
             return filter.handleEscape();
         }
@@ -303,6 +324,9 @@ class SpansTab extends AbstractTab {
 
         if (waterfallView && selectedTraceId != null) {
             renderWaterfallView(frame, area);
+            if (transcript.isVisible()) {
+                transcript.render(frame, area);
+            }
         } else {
             renderTraceList(frame, area);
         }
@@ -409,8 +433,10 @@ class SpansTab extends AbstractTab {
 
     private void renderWaterfallView(Frame frame, Rect area) {
         List<WaterfallNode> nodes = buildWaterfallNodes(selectedTraceId);
+        renderedNodes = nodes;
         if (nodes.isEmpty()) {
             waterfallView = false;
+            transcript.close();
             return;
         }
 
@@ -603,6 +629,9 @@ class SpansTab extends AbstractTab {
             }
             lines.add(Line.from(ctx));
         }
+        if (GenAiTranscript.isGenAiSpan(span)) {
+            lines.add(conversationLine(span));
+        }
 
         // Attributes as individual key: value lines
         if (span.attributes() != null && !span.attributes().isEmpty()) {
@@ -626,11 +655,50 @@ class SpansTab extends AbstractTab {
                 area);
     }
 
+    /** Whether the selected span of the waterfall has a conversation to show 
with t. */
+    private Line conversationLine(SpanEntry span) {
+        if (GenAiTranscript.hasContent(span)) {
+            return Line.from(
+                    Span.styled(" Conversation: ", Theme.muted()),
+                    Span.styled("t", Theme.label().bold()),
+                    Span.styled(" shows the messages", Theme.muted()));
+        }
+        return Line.from(
+                Span.styled(" Conversation: ", Theme.muted()),
+                Span.styled("recorded at camel.aiObservability.level=full", 
Theme.muted()));
+    }
+
+    /** Opens the conversation of the selected GenAI span, from the spans of 
its trace. */
+    private void openTranscript() {
+        List<WaterfallNode> nodes = buildWaterfallNodes(selectedTraceId);
+        if (waterfallSelected < 0 || waterfallSelected >= nodes.size()) {
+            return;
+        }
+        SpanEntry span = nodes.get(waterfallSelected).span;
+        if (!GenAiTranscript.isGenAiSpan(span)) {
+            return;
+        }
+        List<SpanEntry> trace = spans.get().stream().filter(s -> 
selectedTraceId.equals(s.traceId())).toList();
+        transcript.open("Conversation · " + spanLabel(span), 
GenAiTranscript.of(span, trace));
+    }
+
+    /** The overlay with the conversation of a GenAI span (tests). */
+    TranscriptOverlay transcriptForTesting() {
+        return transcript;
+    }
+
     @Override
     public void renderFooter(List<Span> spans) {
+        if (waterfallView && transcript.isVisible()) {
+            transcript.renderFooter(spans);
+            return;
+        }
         if (waterfallView) {
             hint(spans, "Esc", "back");
             hint(spans, "F5", "refresh");
+            if (selectedSpanIsGenAi()) {
+                hint(spans, "t", "conversation");
+            }
             hint(spans, "c", camelOnly ? "camel-only [on]" : "camel-only 
[off]");
             hint(spans, "p", showProcessors ? "processors [on]" : "processors 
[off]");
             hintLast(spans, "PgUp/Dn", "page");
@@ -645,6 +713,12 @@ class SpansTab extends AbstractTab {
         filter.renderHint(spans);
     }
 
+    private boolean selectedSpanIsGenAi() {
+        List<WaterfallNode> nodes = renderedNodes;
+        return waterfallSelected >= 0 && waterfallSelected < nodes.size()
+                && 
GenAiTranscript.isGenAiSpan(nodes.get(waterfallSelected).span);
+    }
+
     private List<TraceSummary> buildTraceSummaries() {
         List<SpanEntry> currentSpans = spans.get();
         Map<String, TraceSummary> byTrace = new LinkedHashMap<>();
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
new file mode 100644
index 000000000000..9a29e084050c
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TranscriptOverlay.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.List;
+
+import dev.tamboui.layout.Constraint;
+import dev.tamboui.layout.Layout;
+import dev.tamboui.layout.Rect;
+import dev.tamboui.markdown.MarkdownView;
+import dev.tamboui.style.Style;
+import dev.tamboui.terminal.Frame;
+import dev.tamboui.text.Line;
+import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.widgets.Clear;
+import dev.tamboui.widgets.block.Block;
+import dev.tamboui.widgets.block.BorderType;
+import dev.tamboui.widgets.block.Borders;
+import dev.tamboui.widgets.block.Title;
+import dev.tamboui.widgets.scrollbar.Scrollbar;
+import dev.tamboui.widgets.scrollbar.ScrollbarState;
+
+import static org.apache.camel.dsl.jbang.core.commands.tui.TuiHelper.hint;
+import static org.apache.camel.dsl.jbang.core.commands.tui.TuiHelper.hintLast;
+
+/**
+ * The conversation of a GenAI span over the Spans tab: the system 
instructions, the user and assistant messages, and
+ * each tool call with its arguments and result, as Markdown that scrolls.
+ */
+final class TranscriptOverlay {
+
+    static final String NO_CONTENT
+            = "The messages are recorded at GenAI observability level full: 
set camel.aiObservability.level=full.";
+
+    private final ScrollbarState scrollbarState = new ScrollbarState();
+    private boolean visible;
+    private String title;
+    private String markdown;
+    private int scroll;
+    private int maxScroll;
+    private int pageHeight = 10;
+
+    boolean isVisible() {
+        return visible;
+    }
+
+    /** Opens the conversation; an empty one says at which level the messages 
are recorded. */
+    void open(String title, GenAiTranscript transcript) {
+        this.title = title;
+        this.markdown = transcript.isEmpty() ? "*" + NO_CONTENT + "*" : 
transcript.toMarkdown();
+        this.scroll = 0;
+        this.maxScroll = 0;
+        this.visible = true;
+    }
+
+    void close() {
+        visible = false;
+        markdown = null;
+    }
+
+    /** The keys of the overlay: it takes all of them while it is open. */
+    boolean handleKey(KeyEvent ke) {
+        if (ke.isKey(KeyCode.ESCAPE) || ke.isChar('q') || ke.isChar('t')) {
+            close();
+        } else if (ke.isUp()) {
+            scrollBy(-1);
+        } else if (ke.isDown()) {
+            scrollBy(1);
+        } else if (ke.isPageUp() || ke.isKey(KeyCode.PAGE_UP)) {
+            scrollBy(-pageHeight);
+        } else if (ke.isPageDown() || ke.isKey(KeyCode.PAGE_DOWN) || 
ke.isChar(' ')) {
+            scrollBy(pageHeight);
+        } else if (ke.isKey(KeyCode.HOME) || ke.isChar('g')) {
+            scroll = 0;
+        } else if (ke.isKey(KeyCode.END) || ke.isChar('G')) {
+            scroll = maxScroll;
+        }
+        return true;
+    }
+
+    void scrollBy(int lines) {
+        scroll = Math.max(0, Math.min(maxScroll, scroll + lines));
+    }
+
+    void render(Frame frame, Rect area) {
+        if (!visible || area.width() < 10 || area.height() < 4) {
+            return;
+        }
+        frame.renderWidget(Clear.INSTANCE, area);
+        Block block = Block.builder()
+                .borderType(BorderType.ROUNDED).borders(Borders.ALL)
+                .borderStyle(Style.EMPTY.fg(Theme.accent()))
+                .title(Title.from(Line.from(Span.styled(" " + title + " ", 
Style.EMPTY.fg(Theme.accent()).bold()))))
+                .titleBottom(Title.from(Line.from(Span.styled(position(), 
Theme.muted()))).right())
+                .build();
+        frame.renderWidget(block, area);
+        Rect inner = block.inner(area);
+        List<Rect> columns = Layout.horizontal()
+                .constraints(Constraint.fill(), Constraint.length(1))
+                .split(inner);
+        Rect content = columns.get(0);
+        if (content.width() < 4 || content.height() < 1) {
+            return;
+        }
+        MarkdownView.Builder view = MarkdownView.builder()
+                .source(markdown)
+                .styles(Theme.chatMarkdownStyles())
+                .syntaxTheme(Theme.syntaxTheme());
+        int totalHeight = view.build().computeHeight(content.width());
+        pageHeight = Math.max(1, content.height() - 1);
+        maxScroll = Math.max(0, totalHeight - content.height());
+        scroll = Math.min(scroll, maxScroll);
+        frame.renderWidget(view.scroll(scroll).build(), content);
+        if (totalHeight > content.height()) {
+            
scrollbarState.contentLength(totalHeight).viewportContentLength(content.height()).position(scroll);
+            frame.renderStatefulWidget(Scrollbar.builder().build(), 
columns.get(1), scrollbarState);
+        }
+    }
+
+    private String position() {
+        if (maxScroll == 0) {
+            return " ";
+        }
+        return " " + (scroll * 100 / maxScroll) + "% ";
+    }
+
+    void renderFooter(List<Span> spans) {
+        hint(spans, "Esc", "close");
+        hint(spans, "↑↓", "scroll");
+        hint(spans, "PgUp/Dn", "page");
+        hintLast(spans, "Home/End", "top/end");
+    }
+
+    /** The Markdown shown (tests). */
+    String markdownForTesting() {
+        return markdown;
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/spans.md 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/spans.md
index 09db24bef568..479f5df71404 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/spans.md
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/spans.md
@@ -47,6 +47,24 @@ flow. Error spans are always shown regardless of the toggle.
 
 Press **Esc** to return to the trace list.
 
+### AI Conversations
+
+On a GenAI span (a model call such as `chat`, an agent run `invoke_agent`,
+or a tool call `execute_tool`) press **t** to read its conversation: the
+system instructions, the user and assistant messages, and each tool call
+with its arguments and result, shown as formatted text you can scroll.
+An agent run shows the input and output of its last model call, which
+already hold the whole run. Texts cut at `contentMaxLength` are marked
+*(truncated)*.
+
+The messages are only recorded at GenAI observability level `full`:
+
+```
+camel.aiObservability.level = full
+```
+
+At a lower level the detail panel says so. Press **Esc** to close.
+
 Example waterfall for an order-processing integration:
 
 ```
@@ -79,6 +97,7 @@ Example waterfall for an order-processing integration:
 | S | Reverse sort direction |
 | p | Toggle processor spans in waterfall |
 | c | Toggle camel-only (hide 3rd-party agent spans) |
+| t | Show the conversation of a GenAI span (level `full`) |
 | F5 | Refresh span data |
 
 ## Filtering
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscriptTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscriptTest.java
new file mode 100644
index 000000000000..15366e120ae5
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/GenAiTranscriptTest.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiMessages;
+import org.apache.camel.dsl.jbang.core.commands.tui.GenAiTranscript.Kind;
+import org.apache.camel.dsl.jbang.core.commands.tui.GenAiTranscript.Part;
+import org.apache.camel.dsl.jbang.core.commands.tui.GenAiTranscript.Turn;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class GenAiTranscriptTest {
+
+    /** The input of the second model call of a run: the user question, the 
tool call and its result. */
+    private static final String SECOND_CALL_INPUT = new GenAiMessages()
+            .text(GenAiMessages.SYSTEM, "You are a support agent.")
+            .text(GenAiMessages.USER, "What is the status of order A-17?")
+            .text(GenAiMessages.ASSISTANT, null)
+            .toolCall("call-1", "lookupOrder", "{\"orderId\":\"A-17\"}")
+            .toolResult("call-1", 
"{\"orderId\":\"A-17\",\"status\":\"DELIVERED\"}")
+            .toJson(8192);
+    private static final String SECOND_CALL_OUTPUT = new GenAiMessages()
+            .text(GenAiMessages.ASSISTANT, "Order A-17 was delivered.")
+            .finishReason("STOP")
+            .toJson(8192);
+
+    @Test
+    void modelCallShowsItsInputAndOutput() {
+        SpanEntry chat = span("chat2", "agent", attrs("chat",
+                GenAiAttributes.INPUT_MESSAGES, SECOND_CALL_INPUT,
+                GenAiAttributes.OUTPUT_MESSAGES, SECOND_CALL_OUTPUT));
+
+        List<Turn> turns = GenAiTranscript.of(chat, List.of(chat)).turns();
+
+        assertThat(turns).extracting(Turn::role).containsExactly("system", 
"user", "assistant", "tool", "assistant");
+        Part call = turns.get(2).parts().get(0);
+        assertThat(call.kind()).isEqualTo(Kind.TOOL_CALL);
+        assertThat(call.toolName()).isEqualTo("lookupOrder");
+        assertThat(call.text()).isEqualTo("{\"orderId\":\"A-17\"}");
+        // the result names its tool by the id of the call
+        Part result = turns.get(3).parts().get(0);
+        assertThat(result.kind()).isEqualTo(Kind.TOOL_RESULT);
+        assertThat(result.toolName()).isEqualTo("lookupOrder");
+        assertThat(turns.get(4).finishReason()).isEqualTo("stop");
+    }
+
+    @Test
+    void agentRunShowsItsLastModelCall() {
+        SpanEntry agent = span("agent", "route", attrs("invoke_agent",
+                GenAiAttributes.INPUT_MESSAGES,
+                new GenAiMessages().text(GenAiMessages.USER, "What is the 
status of order A-17?").toJson(8192)));
+        SpanEntry chat1 = span("chat1", "agent", attrs("chat",
+                GenAiAttributes.INPUT_MESSAGES,
+                new GenAiMessages().text(GenAiMessages.USER, "What is the 
status of order A-17?").toJson(8192)));
+        SpanEntry tool = span("tool", "agent", attrs("execute_tool",
+                GenAiAttributes.TOOL_CALL_ARGUMENTS, 
"{\"orderId\":\"A-17\"}"));
+        // nested one level deeper, under a Camel span, and started last
+        SpanEntry step = span("step", "agent", Map.of("camel.uri", 
"openai:chat-completion"));
+        SpanEntry chat2 = new SpanEntry(
+                "trace-1", "chat2", "step", "chat", "CLIENT", "OK", 300, 400, 
1, "r", null,
+                "camel", attrs("chat",
+                        GenAiAttributes.INPUT_MESSAGES, SECOND_CALL_INPUT,
+                        GenAiAttributes.OUTPUT_MESSAGES, SECOND_CALL_OUTPUT));
+
+        GenAiTranscript transcript = GenAiTranscript.of(agent, List.of(agent, 
chat1, tool, step, chat2));
+
+        assertThat(transcript.turns()).hasSize(5);
+        
assertThat(transcript.turns().get(4).parts().get(0).text()).isEqualTo("Order 
A-17 was delivered.");
+    }
+
+    @Test
+    void agentRunWithoutModelCallsShowsItsOwnMessages() {
+        SpanEntry agent = span("agent", "route", attrs("invoke_agent",
+                GenAiAttributes.SYSTEM_INSTRUCTIONS, 
GenAiMessages.systemInstructions("Be brief.", 8192),
+                GenAiAttributes.INPUT_MESSAGES, new 
GenAiMessages().text(GenAiMessages.USER, "Hi").toJson(8192)));
+
+        List<Turn> turns = GenAiTranscript.of(agent, List.of(agent)).turns();
+
+        assertThat(turns).extracting(Turn::role).containsExactly("system", 
"user");
+        assertThat(turns.get(0).parts().get(0).text()).isEqualTo("Be brief.");
+    }
+
+    @Test
+    void systemInstructionsAreNotRepeatedWhenTheInputHasASystemMessage() {
+        SpanEntry chat = span("chat", "", attrs("chat",
+                GenAiAttributes.SYSTEM_INSTRUCTIONS, 
GenAiMessages.systemInstructions("You are a support agent.", 8192),
+                GenAiAttributes.INPUT_MESSAGES, SECOND_CALL_INPUT));
+
+        assertThat(GenAiTranscript.of(chat, List.of(chat)).turns())
+                .filteredOn(turn -> "system".equals(turn.role())).hasSize(1);
+    }
+
+    @Test
+    void toolCallShowsItsArgumentsAndResult() {
+        SpanEntry tool = span("tool", "agent", attrs("execute_tool",
+                GenAiAttributes.TOOL_NAME, "lookupOrder",
+                GenAiAttributes.TOOL_CALL_ARGUMENTS, "{\"orderId\":\"A-17\"}",
+                GenAiAttributes.TOOL_CALL_RESULT, "DELIVERED"));
+
+        List<Turn> turns = GenAiTranscript.of(tool, List.of(tool)).turns();
+
+        assertThat(turns).extracting(Turn::role).containsExactly("assistant", 
"tool");
+        assertThat(turns).allSatisfy(turn -> 
assertThat(turn.parts().get(0).toolName()).isEqualTo("lookupOrder"));
+        assertThat(turns.get(1).parts().get(0).text()).isEqualTo("DELIVERED");
+    }
+
+    @Test
+    void spanWithoutMessagesHasNoContent() {
+        SpanEntry basic = span("chat", "", attrs("chat", 
GenAiAttributes.REQUEST_MODEL, "llama3.2"));
+        SpanEntry route = span("route", "", Map.of("camel.uri", "timer:ask"));
+
+        assertThat(GenAiTranscript.isGenAiSpan(basic)).isTrue();
+        assertThat(GenAiTranscript.hasContent(basic)).isFalse();
+        assertThat(GenAiTranscript.of(basic, 
List.of(basic)).isEmpty()).isTrue();
+        assertThat(GenAiTranscript.isGenAiSpan(route)).isFalse();
+        assertThat(GenAiTranscript.of(route, 
List.of(route)).isEmpty()).isTrue();
+    }
+
+    @Test
+    void messageWithoutARoleStillHasAHeading() {
+        String input = 
"[{\"role\":\"\",\"parts\":[{\"type\":\"text\",\"content\":\"hello\"}]},"
+                       // a part without a message around it, as in 
gen_ai.system_instructions
+                       + "{\"type\":\"text\",\"content\":\"instructions\"}]";
+        SpanEntry chat = span("chat", "", attrs("chat", 
GenAiAttributes.INPUT_MESSAGES, input));
+
+        assertThat(GenAiTranscript.of(chat, List.of(chat)).toMarkdown())
+                .contains("### Message\n\nhello")
+                .contains("### System\n\ninstructions");
+    }
+
+    @Test
+    void textThatIsNotJsonIsShownAsItIs() {
+        assertThat(GenAiTranscript.parseMessages("not json")).singleElement()
+                .satisfies(turn -> 
assertThat(turn.parts().get(0).text()).isEqualTo("not json"));
+        assertThat(GenAiTranscript.parseMessages(null)).isEmpty();
+    }
+
+    @Test
+    void markdownHasAHeadingPerMessageAndToolDataAsCode() {
+        SpanEntry chat = span("chat2", "agent", attrs("chat",
+                GenAiAttributes.INPUT_MESSAGES, SECOND_CALL_INPUT,
+                GenAiAttributes.OUTPUT_MESSAGES, SECOND_CALL_OUTPUT));
+
+        String markdown = GenAiTranscript.of(chat, List.of(chat)).toMarkdown();
+
+        assertThat(markdown)
+                .contains("### System\n\nYou are a support agent.")
+                .contains("### User\n\nWhat is the status of order A-17?")
+                .contains("Calls **lookupOrder**\n\n```json\n{\n  \"orderId\": 
\"A-17\"\n}\n```")
+                .contains("### Tool lookupOrder\n\n```json\n")
+                .contains("### Assistant · stop\n\nOrder A-17 was delivered.");
+    }
+
+    @Test
+    void markdownMarksCutTextsAndKeepsFencesClosed() {
+        String cut = new GenAiMessages().text(GenAiMessages.USER, 
"a".repeat(20)).toJson(10);
+        SpanEntry chat = span("chat", "", attrs("chat",
+                GenAiAttributes.INPUT_MESSAGES, cut,
+                GenAiAttributes.OUTPUT_MESSAGES, new 
GenAiMessages().text(GenAiMessages.ASSISTANT, null)
+                        .toolCall(null, "run", 
"```shell\nls\n```").toJson(8192)));
+
+        String markdown = GenAiTranscript.of(chat, List.of(chat)).toMarkdown();
+
+        assertThat(markdown).contains("aaaaaaaaaa … 
*(truncated)*").contains("````\n```shell\nls\n```\n````");
+    }
+
+    private static Map<String, Object> attrs(String operation, String... 
keyValues) {
+        Map<String, Object> attrs = new HashMap<>();
+        attrs.put(GenAiAttributes.OPERATION_NAME, operation);
+        for (int i = 0; i < keyValues.length; i += 2) {
+            attrs.put(keyValues[i], keyValues[i + 1]);
+        }
+        return attrs;
+    }
+
+    private static SpanEntry span(String spanId, String parentSpanId, 
Map<String, Object> attributes) {
+        long start = switch (spanId) {
+            case "chat1" -> 100;
+            case "tool" -> 200;
+            default -> 250;
+        };
+        return new SpanEntry(
+                "trace-1", spanId, parentSpanId, spanId, "CLIENT", "OK", 
start, start + 50, 1, "r", null,
+                "camel", attributes);
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
index f0afae119cda..1e0bd3b2ed56 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/SpansTabRenderTest.java
@@ -26,6 +26,11 @@ import dev.tamboui.layout.Rect;
 import dev.tamboui.style.Color;
 import dev.tamboui.terminal.Frame;
 import dev.tamboui.text.Span;
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import dev.tamboui.tui.event.KeyModifiers;
+import org.apache.camel.component.ai.observability.GenAiAttributes;
+import org.apache.camel.component.ai.observability.GenAiMessages;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -152,6 +157,63 @@ class SpansTabRenderTest {
         assertTrue(rendered.contains("cccc3333"), "Should render second trace 
ID");
     }
 
+    @Test
+    void tOpensTheConversationOfAGenAiSpan() {
+        String input = new GenAiMessages()
+                .text(GenAiMessages.USER, "What is the status of order A-17?")
+                .toJson(8192);
+        String output = new GenAiMessages()
+                .text(GenAiMessages.ASSISTANT, "Order A-17 was delivered.")
+                .finishReason("stop")
+                .toJson(8192);
+        spans.get().add(new SpanEntry(
+                "trace0001", "span001", null, "chat llama3.2", "CLIENT", "OK", 
0L, 500_000_000L, 500, "route1", null,
+                "camel", Map.of(GenAiAttributes.OPERATION_NAME, "chat",
+                        GenAiAttributes.INPUT_MESSAGES, input,
+                        GenAiAttributes.OUTPUT_MESSAGES, output)));
+        SpansTab tab = new SpansTab(ctx, spans);
+        TuiTestHelper.renderToString(tab, 140, 30);
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.ENTER));
+
+        assertThat(TuiTestHelper.renderToString(tab, 140, 
30)).contains("Conversation: t shows the messages");
+        assertThat(footer(tab)).contains("conversation");
+
+        tab.handleKeyEvent(KeyEvent.ofChar('t', KeyModifiers.NONE));
+
+        assertThat(tab.transcriptForTesting().isVisible()).isTrue();
+        assertThat(TuiTestHelper.renderToString(tab, 140, 30))
+                .contains("Conversation · ")
+                .contains("What is the status of order A-17?")
+                .contains("Order A-17 was delivered.");
+        assertThat(footer(tab)).contains("close").doesNotContain("refresh");
+
+        assertThat(tab.handleEscape()).isTrue();
+        assertThat(tab.transcriptForTesting().isVisible()).isFalse();
+    }
+
+    @Test
+    void conversationOfASpanWithoutMessagesSaysTheLevel() {
+        spans.get().add(new SpanEntry(
+                "trace0001", "span001", null, "chat llama3.2", "CLIENT", "OK", 
0L, 500_000_000L, 500, "route1", null,
+                "camel", Map.of(GenAiAttributes.OPERATION_NAME, "chat", 
GenAiAttributes.REQUEST_MODEL, "llama3.2")));
+        SpansTab tab = new SpansTab(ctx, spans);
+        TuiTestHelper.renderToString(tab, 140, 30);
+        tab.handleKeyEvent(KeyEvent.ofKey(KeyCode.ENTER));
+
+        assertThat(TuiTestHelper.renderToString(tab, 140, 30))
+                .contains("Conversation: recorded at 
camel.aiObservability.level=full");
+
+        tab.handleKeyEvent(KeyEvent.ofChar('t', KeyModifiers.NONE));
+
+        
assertThat(tab.transcriptForTesting().markdownForTesting()).contains(TranscriptOverlay.NO_CONTENT);
+    }
+
+    private static String footer(SpansTab tab) {
+        List<Span> footerSpans = new ArrayList<>();
+        tab.renderFooter(footerSpans);
+        return footerSpans.stream().map(Span::content).reduce("", 
String::concat);
+    }
+
     // ---- Helper methods ----
 
     private SpanEntry createSpan(String traceId, String spanId, String name, 
String status, long durationMs) {

Reply via email to