Class AiMessageListItem
java.lang.Object
io.jmix.aichat.component.messagelist.AiMessageListItem
- All Implemented Interfaces:
Serializable
Item to render as a message component inside an
AiMessageList. Each
item has a MessageRole: assistant messages are rendered as Markdown
(with embedded code blocks), user messages as plain text with preserved
newlines.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA display attachment shown with the message. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<AiMessageListItem.Attachment> protected @Nullable Stringprotected @Nullable AiMessageListprotected MessageRoleprotected @Nullable AiChatMessageprotected @Nullable Stringprotected @Nullable Instantprotected @Nullable String -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty message list item with the defaultMessageRole.USERrole.AiMessageListItem(@Nullable String text) Creates a message list item with the provided text and the defaultMessageRole.USERrole.AiMessageListItem(@Nullable String text, MessageRole role) Creates a message list item with the provided text and role. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachment(AiMessageListItem.Attachment attachment) Adds an attachment to this message.voidaddClassNames(String... classNames) Adds one or more class names to this item.voidaddThemeNames(String... themeNames) Adds one or more theme names to this message.voidappendText(@Nullable String text) Appends the provided text to the message's text content.static AiMessageListItemCreates an assistant message with the given text.Gets the attachments displayed with this message.protected @Nullable List<AiMessageListItem.Attachment> protected @Nullable Stringprotected @Nullable AiMessageListgetHost()getRole()Gets the role of the message.protected String<M extends AiChatMessage>
@Nullable MGets the domain message this item was rendered from.@Nullable StringgetText()Gets the text content of the message.protected @Nullable StringgetTheme()@Nullable InstantgetTime()Gets the time of sending the message.@Nullable StringGets the user name of the message sender.booleanhasClassName(String className) Checks if the message has the given class name.booleanhasThemeName(String themeName) Checks if the message has the given theme name.protected voidvoidremoveClassNames(String... classNames) Removes one or more class names from this item.voidremoveThemeNames(String... themeNames) Removes one or more theme names from this message.voidsetAttachments(List<AiMessageListItem.Attachment> attachments) Sets the attachments displayed with this message, replacing any current ones.protected voidsetHost(@Nullable AiMessageList host) voidsetRole(MessageRole role) Sets the role of the message.voidsetSourceMessage(@Nullable AiChatMessage sourceMessage) Sets the domain message this item was rendered from.voidSets the text content of the message.voidSets the time of sending the message.voidsetUserName(@Nullable String userName) Sets the user name of the message sender.static AiMessageListItemCreates a user message with the given text.
-
Field Details
-
host
-
text
-
clientText
-
time
-
role
-
sourceMessage
-
userName
-
attachments
-
themeNames
-
classNames
-
-
Constructor Details
-
AiMessageListItem
public AiMessageListItem()Creates an empty message list item with the defaultMessageRole.USERrole. -
AiMessageListItem
Creates a message list item with the provided text and the defaultMessageRole.USERrole.- Parameters:
text- the text content of the message
-
AiMessageListItem
Creates a message list item with the provided text and role.- Parameters:
text- the text content of the messagerole- the message role, notnull
-
-
Method Details
-
user
Creates a user message with the given text.- Parameters:
text- the text content of the message- Returns:
- a new item with role
MessageRole.USER
-
assistant
Creates an assistant message with the given text.- Parameters:
text- the text content of the message- Returns:
- a new item with role
MessageRole.ASSISTANT
-
getText
Gets the text content of the message.- Returns:
- the message's text content, or
nullif none is set
-
setText
Sets the text content of the message.- Parameters:
text- the message's text content to set, ornullto remove the content
-
appendText
Appends the provided text to the message's text content.- Parameters:
text- the text to append to the message's text content
-
getRole
Gets the role of the message.- Returns:
- the message role (never
null)
-
setRole
Sets the role of the message. The role decides how the message is rendered and styled.- Parameters:
role- the message role, notnull
-
getRoleJson
-
getSourceMessage
Gets the domain message this item was rendered from.AiChatpopulates it for every item it renders from its bound message source, which is how a per-message action identifies the message it was clicked on. The accessor is self-typed, so no cast is needed:
The reference is server-side only and never reaches the client.ChatMessage message = event.getItem().getSourceMessage();- Type Parameters:
M- the application's own message type- Returns:
- the message this item was rendered from, or
nullwhen there is none — the streaming placeholder, the transient bubble a stopped or failed generation leaves behind (whose action bar is clickable), and any item an application built itself
-
setSourceMessage
Sets the domain message this item was rendered from. Server-side metadata: it is not serialized to the client, so setting it schedules no client update.- Parameters:
sourceMessage- the message this item was rendered from, ornullto remove it
-
getTime
Gets the time of sending the message.- Returns:
- the time of the message, or
nullif none is set
-
setTime
Sets the time of sending the message. Retained as optional metadata; not rendered by default in the AI-chat layout.- Parameters:
time- the time of the message to set, ornullto remove the time
-
getUserName
Gets the user name of the message sender.- Returns:
- the message sender's user name, or
nullif none is set
-
setUserName
Sets the user name of the message sender. Retained as optional metadata (used for the message's accessible description); not rendered visually by default.- Parameters:
userName- the message sender's user name, ornullto remove it
-
getAttachments
Gets the attachments displayed with this message.- Returns:
- an unmodifiable view of the attachments (never
null)
-
setAttachments
Sets the attachments displayed with this message, replacing any current ones.- Parameters:
attachments- the attachments to set
-
addAttachment
Adds an attachment to this message.- Parameters:
attachment- the attachment to add
-
getAttachmentsJson
-
addThemeNames
Adds one or more theme names to this message.- Parameters:
themeNames- the theme name or theme names to be added to the message
-
removeThemeNames
Removes one or more theme names from this message.- Parameters:
themeNames- the theme name or theme names to be removed from the message
-
hasThemeName
Checks if the message has the given theme name.- Parameters:
themeName- the theme name to check for- Returns:
trueif the message has the given theme name,falseotherwise
-
getTheme
-
addClassNames
Adds one or more class names to this item.- Parameters:
classNames- the class name or class names to be added to the item
-
removeClassNames
Removes one or more class names from this item.- Parameters:
classNames- the class name or class names to be removed from the item
-
hasClassName
Checks if the message has the given class name.- Parameters:
className- the class name to check for- Returns:
trueif the message has the given class name,falseotherwise
-
getClassName
-
propsChanged
protected void propsChanged() -
setHost
-
getHost
-