SagentsLiveDebugger.Live.Components.MessageComponents (Sagents LiveDebugger v0.6.2)

Copy Markdown

Shared components for rendering messages and tools.

These components are used by both the main AgentListLive and SubagentsTab to provide consistent message and tool rendering with expandable/collapsible UI.

Summary

Functions

Renders a single content part (text, thinking, image, etc.).

Build the display payload for a middleware's config section.

A longer preview of a message's content, accepting either a plain string or a list of content parts. Prefers the answer the same way extract_text_preview/1 does.

A short preview of a message's text, for a list where only one line fits.

Returns a tool result's content as display text.

Inspect values for debug display.

Renders a single message item with role emoji, content, tool calls/results, and metadata.

Renders the message's status badge.

Renders the provider's own account of why a message stopped.

Renders the middleware config display, dispatching on the shape of the payload returned by display_config/1.

Renders a single config entry within middleware.

Renders a single middleware item with expandable configuration. Expects a MiddlewareEntry struct with id and config fields.

Renders a model configuration within middleware.

Renders a middleware section with a list of middleware entries. Expects an agent struct with a middleware field containing MiddlewareEntry structs.

Returns a content part's utterance marker: "narration", "answer", or nil when it carries none.

Renders message content, handling both binary and multimodal content.

Classifies a tool result's content for display as {format, body}.

Renders a tool call item.

Renders a tool item with expandable description and parameters. Expects a tool struct or map with name, description, parameters, and async fields.

Renders a tool result item.

Renders the label for a content part's utterance marker.

Functions

content_part(assigns)

Renders a single content part (text, thinking, image, etc.).

Attributes

  • part (:map) (required)
  • prefix (:string) - Defaults to "".

display_config(arg)

Build the display payload for a middleware's config section.

Returns:

  • {:map, map} — render as a key/value config table
  • {:string, text} — render as a single highlighted code block

Prefers the middleware module's own Sagents.Middleware.debug_summary/1 callback when exported. The callback owns the decision of what's useful to surface; falling back to the raw config is the safe default for middleware that hasn't opted in.

extract_content_preview(content)

@spec extract_content_preview(term()) :: String.t()

A longer preview of a message's content, accepting either a plain string or a list of content parts. Prefers the answer the same way extract_text_preview/1 does.

extract_text_preview(content_parts)

@spec extract_text_preview(term()) :: String.t()

A short preview of a message's text, for a list where only one line fits.

Prefers the answer over a preamble sitting in front of it, and says so when the message is only the model describing work in progress. Previewing the first text part would show the preamble and hide the reply.

format_config_key(key)

format_config_value(value)

format_module_name(module)

format_tool_arguments(arguments)

format_tool_result(content)

Returns a tool result's content as display text.

get_model_name(model)

inspect_for_display(value)

Inspect values for debug display.

Uses bounded :limit and :printable_limit so that an unexpectedly large middleware config (or any other value) cannot dominate render time and DOM size. Middleware modules that hold large structures should implement Sagents.Middleware.debug_summary/1 to provide a curated view; this function is the safety net for everything else.

message_item(assigns)

Renders a single message item with role emoji, content, tool calls/results, and metadata.

Attributes

  • message (:map) (required)
  • index (:integer) - Defaults to nil.

message_role_emoji(_)

message_status(assigns)

Renders the message's status badge.

The status value is shown verbatim, since it is the name a developer reads in their own code. What it means goes in the tooltip instead. Nothing is rendered for a message carrying no status.

Attributes

  • message (:map) (required)

message_stop_note(assigns)

Renders the provider's own account of why a message stopped.

Nothing is rendered when the provider named no cause. Placed as a sibling of the message body rather than inside it: a filtered response arrives with empty or near-empty content, so a note nested in the body has nothing to sit beside.

Attributes

  • message (:map) (required)

middleware_config_display(assigns)

Renders the middleware config display, dispatching on the shape of the payload returned by display_config/1.

Multi-clause function components let us pick the template at compile time via pattern matching, instead of a runtime case inside HEEx.

Attributes

  • display (:any) (required)

middleware_config_entry(assigns)

Renders a single config entry within middleware.

Attributes

  • key (:any) (required)
  • value (:any) (required)

middleware_item(assigns)

Renders a single middleware item with expandable configuration. Expects a MiddlewareEntry struct with id and config fields.

The prefix attribute is used to create unique DOM IDs when the same middleware is displayed in multiple contexts (e.g., main agent vs sub-agent views).

Attributes

  • entry (:map) (required)
  • prefix (:string) - Defaults to "".

middleware_model_config(assigns)

Renders a model configuration within middleware.

Attributes

  • model (:map) (required)
  • entry_id (:any) (required)
  • prefix (:string) - Defaults to "".

middleware_section(assigns)

Renders a middleware section with a list of middleware entries. Expects an agent struct with a middleware field containing MiddlewareEntry structs.

The prefix attribute is used to create unique DOM IDs when middleware is displayed in multiple contexts (e.g., main agent vs sub-agent views).

Attributes

  • agent (:map) (required)
  • prefix (:string) - Defaults to "".

part_utterance(part)

@spec part_utterance(term()) :: String.t() | nil

Returns a content part's utterance marker: "narration", "answer", or nil when it carries none.

Reads the :utterance key of the part's options directly rather than calling LangChain.Message.ContentPart.utterance/1, which does not exist in every langchain version the sagents requirement admits. Under a langchain that predates the marker, no part carries one and every part returns nil.

A LangChain.Message.ContentPart struct is read like any other map. The parts reaching these components are not always structs: state restored from a store arrives as plain maps, and its options may be a keyword list or a string-keyed map depending on where it came from.

render_message_content(message)

Renders message content, handling both binary and multimodal content.

result_display(content)

@spec result_display(term()) :: {:json | :text | :parts | :empty, String.t() | list()}

Classifies a tool result's content for display as {format, body}.

content holds what was sent to the LLM: a list of ContentParts, or a plain string. Text parts are joined and returned as {:json, pretty} when the text is a JSON object or array, otherwise as {:text, text}. Content carrying anything other than text (an image, a file) is returned as {:parts, parts} for content_part/1 to render. Absent or empty content is {:empty, ""}.

tool_call_item(assigns)

Renders a tool call item.

Attributes

  • tool_call (:map) (required)

tool_item(assigns)

Renders a tool item with expandable description and parameters. Expects a tool struct or map with name, description, parameters, and async fields.

The prefix attribute is used to create unique DOM IDs when the same tool is displayed in multiple contexts (e.g., main agent vs sub-agent views).

Attributes

  • tool (:map) (required)
  • prefix (:string) - Defaults to "".

tool_result_item(assigns)

Renders a tool result item.

Attributes

  • tool_result (:map) (required)

utterance_label(assigns)

Renders the label for a content part's utterance marker.

Renders nothing when the part carries no marker, which is every provider that does not label its output.

Attributes

  • utterance (:string) - Defaults to nil.