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, notnullcontent- the text content of the message, notnullmessageId- an optional identifier assigned to user messages by the orchestrator, used to correlate with attachment data stored viaAttachmentSubmitListener; may benulltime- the timestamp when the message was created; may benull
- 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe role of a message sender in a conversation. -
Constructor Summary
ConstructorsConstructorDescriptionChatMessage(ChatMessage.Role role, String content, String messageId, Instant time) Creates a new chat message. -
Method Summary
Modifier and TypeMethodDescriptioncontent()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of themessageIdrecord component.role()Returns the value of therolerecord component.time()Returns the value of thetimerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ChatMessage
Creates a new chat message.- Parameters:
role- the role of the message sendercontent- the text content of the messagemessageId- an optional identifier for this message, may benulltime- the timestamp when the message was created, may benull- Throws:
NullPointerException- if role or content isnull
-
-
Method Details
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
role
Returns the value of therolerecord component.- Returns:
- the value of the
rolerecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
messageId
Returns the value of themessageIdrecord component.- Returns:
- the value of the
messageIdrecord component
-
time
Returns the value of thetimerecord component.- Returns:
- the value of the
timerecord component
-