Record Class ChatMessage

java.lang.Object
java.lang.Record
com.vaadin.flow.component.ai.common.ChatMessage
Record Components:
role - the role of the message sender, not null
content - the text content of the message, not null
messageId - an optional identifier assigned to user messages by the orchestrator, used to correlate with attachment data stored via AttachmentSubmitListener; may be null
time - the timestamp when the message was created; may be null
All Implemented Interfaces:
Serializable

public record ChatMessage(ChatMessage.Role role, String content, String messageId, Instant time) extends Record implements Serializable
Represents a chat message in a conversation history.

This is a text-only, framework-agnostic representation used with AIOrchestrator.getHistory() and Builder.withHistory() to persist and restore conversation state across sessions. File attachments are not stored in this record; they can be provided separately via Builder.withHistory(List, Map) using the messageId() as the correlation key. The following data is not preserved:

  • Tool call requests and tool execution results
  • Provider-specific metadata
  • System messages (re-injected by the orchestrator on each request)
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • ChatMessage

      public ChatMessage(ChatMessage.Role role, String content, String messageId, Instant time)
      Creates a new chat message.
      Parameters:
      role - the role of the message sender
      content - the text content of the message
      messageId - an optional identifier for this message, may be null
      time - the timestamp when the message was created, may be null
      Throws:
      NullPointerException - if role or content is null
  • Method Details

    • 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.
    • role

      public ChatMessage.Role role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • content

      public String content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • messageId

      public String messageId()
      Returns the value of the messageId record component.
      Returns:
      the value of the messageId record component
    • time

      public Instant time()
      Returns the value of the time record component.
      Returns:
      the value of the time record component