Record Class UiComponentEvent

java.lang.Object
java.lang.Record
com.tnsai.events.UiComponentEvent
Record Components:
eventId - unique identifier for this event
timestamp - when the event occurred
componentType - the type of UI component to render
payload - a map containing data and options specific to the component type
All Implemented Interfaces:
TnsAIEvent

public record UiComponentEvent(String eventId, Instant timestamp, String componentType, Map<String,Object> payload) extends Record implements TnsAIEvent
Event representing a request to render a specific UI component in the frontend. This allows agents to generate rich, interactive UI elements beyond plain text.

Supports AG-UI Generative UI pattern with streaming and interactive components.

Component Types

  • chart - Data visualizations (bar, line, pie, etc.)
  • table - Tabular data display
  • code - Code blocks with syntax highlighting
  • markdown - Formatted text content
  • form - Interactive forms with inputs
  • card - Card-based layouts
  • list - List displays
  • image - Image content
  • progress - Progress indicators
  • alert - Notifications and alerts
  • custom - Custom registered components
  • Field Details

  • Constructor Details

    • UiComponentEvent

      public UiComponentEvent(String eventId, Instant timestamp, String componentType, Map<String,Object> payload)
      Creates an instance of a UiComponentEvent record class.
      Parameters:
      eventId - the value for the eventId record component
      timestamp - the value for the timestamp record component
      componentType - the value for the componentType record component
      payload - the value for the payload record component
  • Method Details

    • of

      public static UiComponentEvent of(String componentType, Map<String,Object> payload)
      Creates a UI component event with the specified type and payload.
      Parameters:
      componentType - the component type
      payload - the component data
      Returns:
      a new UiComponentEvent
    • chart

      public static UiComponentEvent chart(Map<String,Object> chartData)
      Creates a chart component.
      Parameters:
      chartData - chart configuration and data
      Returns:
      a new chart UiComponentEvent
    • chart

      public static UiComponentEvent chart(String chartType, List<String> labels, List<Map<String,Object>> datasets)
      Creates a chart component with specific chart type.
      Parameters:
      chartType - the chart type (bar, line, pie, area, scatter, etc.)
      labels - data labels
      datasets - chart datasets
      Returns:
      a new chart UiComponentEvent
    • table

      public static UiComponentEvent table(Map<String,Object> tableData)
      Creates a table component.
      Parameters:
      tableData - table configuration and data
      Returns:
      a new table UiComponentEvent
    • table

      public static UiComponentEvent table(List<Map<String,Object>> columns, List<Map<String,Object>> rows)
      Creates a table component with columns and rows.
      Parameters:
      columns - column definitions
      rows - table data rows
      Returns:
      a new table UiComponentEvent
    • code

      public static UiComponentEvent code(String language, String content, String filename)
      Creates a code block component.
      Parameters:
      language - programming language for syntax highlighting
      content - the code content
      filename - optional filename to display
      Returns:
      a new code UiComponentEvent
    • code

      public static UiComponentEvent code(String language, String content)
      Creates a code block component without filename.
      Parameters:
      language - programming language
      content - the code content
      Returns:
      a new code UiComponentEvent
    • markdown

      public static UiComponentEvent markdown(String content)
      Creates a markdown component.
      Parameters:
      content - markdown text
      Returns:
      a new markdown UiComponentEvent
    • form

      public static UiComponentEvent form(String formId, List<Map<String,Object>> fields, String submitLabel)
      Creates a form component.
      Parameters:
      formId - unique form identifier
      fields - form field definitions
      submitLabel - submit button label
      Returns:
      a new form UiComponentEvent
    • card

      public static UiComponentEvent card(String title, String content, List<Map<String,Object>> actions)
      Creates a card component.
      Parameters:
      title - card title
      content - card content
      actions - optional action buttons
      Returns:
      a new card UiComponentEvent
    • list

      public static UiComponentEvent list(List<String> items, boolean ordered)
      Creates a list component.
      Parameters:
      items - list items
      ordered - whether the list is ordered
      Returns:
      a new list UiComponentEvent
    • image

      public static UiComponentEvent image(String src, String alt, String caption)
      Creates an image component.
      Parameters:
      src - image source (URL or base64)
      alt - alternative text
      caption - optional caption
      Returns:
      a new image UiComponentEvent
    • progress

      public static UiComponentEvent progress(int value, String label)
      Creates a progress indicator component.
      Parameters:
      value - progress value (0-100)
      label - progress label
      Returns:
      a new progress UiComponentEvent
    • alert

      public static UiComponentEvent alert(String type, String message)
      Creates an alert/notification component.
      Parameters:
      type - alert type (info, success, warning, error)
      message - alert message
      Returns:
      a new alert UiComponentEvent
    • alert

      public static UiComponentEvent alert(String type, String title, String message)
      Creates an alert with title.
      Parameters:
      type - alert type
      title - alert title
      message - alert message
      Returns:
      a new alert UiComponentEvent
    • custom

      public static UiComponentEvent custom(String customType, Map<String,Object> props)
      Creates a custom component.
      Parameters:
      customType - the registered custom component type
      props - component properties
      Returns:
      a new custom UiComponentEvent
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • eventId

      public String eventId()
      Returns the value of the eventId record component.
      Specified by:
      eventId in interface TnsAIEvent
      Returns:
      the value of the eventId record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Specified by:
      timestamp in interface TnsAIEvent
      Returns:
      the value of the timestamp record component
    • componentType

      public String componentType()
      Returns the value of the componentType record component.
      Returns:
      the value of the componentType record component
    • payload

      public Map<String,Object> payload()
      Returns the value of the payload record component.
      Returns:
      the value of the payload record component