Class AiChatHubFragment
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<com.vaadin.flow.component.orderedlayout.VerticalLayout>
io.jmix.flowui.fragment.Fragment<com.vaadin.flow.component.orderedlayout.VerticalLayout>
io.jmix.aitoolsflowui.view.chathub.AiChatHubFragment
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasStyle,FacetOwner,FragmentOwner,Serializable
public class AiChatHubFragment
extends Fragment<com.vaadin.flow.component.orderedlayout.VerticalLayout>
Self-contained chat hub UI. Embeds the reusable chat input, shows the
current user's most recent chats next to it, and a full searchable,
date-bucketed history in a
SidePanelLayout. Designed to be dropped
into any host view.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class io.jmix.flowui.fragment.Fragment
Fragment.ReadyEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChatDateTimeSupportprotected AiChatServiceprotected AiChatInputFragmentprotected AiConversationServiceprotected Dialogsprotected static final Stringprotected CollectionContainer<AiConversation> protected Stringprotected com.vaadin.flow.component.orderedlayout.VerticalLayoutprotected com.vaadin.flow.component.html.Spanprotected SidePanelLayoutprotected com.vaadin.flow.component.html.Divprotected AiIconProviderprotected Map<AiConversation, AiChatMessage> Latest message of each listed conversation; refreshed together with the conversations.protected @Nullable com.vaadin.flow.function.SerializableSupplier<com.vaadin.flow.component.Component> protected MessageBundleprotected AiChatMessageServiceprotected MetadataToolsprotected Notificationsprotected AiToolsFlowuiPropertiesprotected @Nullable Integerprotected CollectionContainer<AiConversation> protected GridLayout<AiConversation> protected com.vaadin.flow.component.Componentprotected RouteSupportprotected ViewNavigatorsFields inherited from class io.jmix.flowui.fragment.Fragment
fragmentActions, fragmentData, fragmentFacets, parentController, uiComponents -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected List<AiConversation> applyHistoryFilter(List<AiConversation> conversations) protected StringbucketLabel(HistoryBucket bucket) protected voidconfirmDelete(AiConversation conversation) protected AiConversationCardcreateCard(AiConversation conversation, boolean deletable) protected StringcreateConversationHref(AiConversation conversation) Builds the address of a conversation's chat route, used as thehrefof its card so that the card behaves as a regular link.protected AiConversationCardcreateHistoryCard(AiConversation conversation) protected com.vaadin.flow.component.ComponentcreateHistoryGroup(String bucketLabel, List<AiConversation> conversations) protected AiConversationCardcreateRecentCard(AiConversation conversation) protected voiddeleteConversation(AiConversation conversation) protected @Nullable StringformatDateTime(@Nullable OffsetDateTime dateTime) protected Map<HistoryBucket, List<AiConversation>> groupByBucket(List<AiConversation> conversations) protected voidvoidonHistoryCloseBtnClick(com.vaadin.flow.component.ClickEvent<JmixButton> event) voidonHistoryNewBtnClick(com.vaadin.flow.component.ClickEvent<JmixButton> event) voidonHistorySearchFieldValueChange(SupportsTypedValue.TypedValueChangeEvent<TypedTextField<String>, String> event) voidonReady(Fragment.ReadyEvent event) voidonShowAllHistoryBtnClick(com.vaadin.flow.component.ClickEvent<JmixButton> event) protected voidopenConversation(AiConversation conversation) protected List<AiConversation> orderByActivity(List<AiConversation> conversations) Orders conversations most recently active first; conversations with equal activity keep their incoming order.protected com.vaadin.flow.data.renderer.ComponentRenderer<AiConversationCard, AiConversation> protected voidDisables the composer and warns the user when the chat model is not configured — starting a new chat would fail.protected voidprotected voidprotected @Nullable OffsetDateTimeresolveActivity(AiConversation conversation) Resolves when a conversation was last active: the date of its latest message, or its creation date when it has no messages.protected com.vaadin.flow.component.Componentprotected intvoidsetMarkIconSupplier(@Nullable com.vaadin.flow.function.SerializableSupplier<com.vaadin.flow.component.Component> markIconSupplier) Sets a supplier of the brand mark icon shown on the hub hero and conversation cards, letting the host override the default add-on icon.voidsetRecentChatsCount(int recentChatsCount) Overrides the number of recent chats shown next to the chat input.protected voidstartConversation(String prompt) Methods inherited from class io.jmix.flowui.fragment.Fragment
addReadyListener, findInnerComponent, getFragmentActions, getFragmentData, getFragmentFacets, getInnerComponent, getParentController, initContent, onAttach, onDetach, setFragmentActions, setFragmentData, setFragmentFacets, setParentController, setUiComponentsMethods inherited from class com.vaadin.flow.component.Composite
getChildren, getContent, getElementMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface io.jmix.flowui.facet.FacetOwner
getIdMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Field Details
-
HERO_ICON_CN
- See Also:
-
messageBundle
-
hubHeroIcon
-
composerFragment
-
recentConversationsDc
-
historyConversationsDc
-
recentConversationsGridLayout
-
recentConversationsHeader
-
historySidePanel
-
historyListContainer
@ViewComponent protected com.vaadin.flow.component.orderedlayout.VerticalLayout historyListContainer -
historyPanelCount
-
metadataTools
-
chatDateTimeSupport
-
routeSupport
-
dialogs
-
notifications
-
conversationService
-
messageService
-
chatService
-
properties
-
iconProvider
-
latestMessages
Latest message of each listed conversation; refreshed together with the conversations. -
recentChatsCount
-
historyFilter
-
markIconSupplier
protected @Nullable com.vaadin.flow.function.SerializableSupplier<com.vaadin.flow.component.Component> markIconSupplier
-
-
Constructor Details
-
AiChatHubFragment
public AiChatHubFragment()
-
-
Method Details
-
setMarkIconSupplier
public void setMarkIconSupplier(@Nullable com.vaadin.flow.function.SerializableSupplier<com.vaadin.flow.component.Component> markIconSupplier) Sets a supplier of the brand mark icon shown on the hub hero and conversation cards, letting the host override the default add-on icon. The supplier must return a fresh component on every call.- Parameters:
markIconSupplier- supplier of the mark icon, ornullto use the default
-
setRecentChatsCount
public void setRecentChatsCount(int recentChatsCount) Overrides the number of recent chats shown next to the chat input. When unset, the value comes fromjmix.aitools.ui.chat-hub-recent-chats-count(default 6).- Parameters:
recentChatsCount- number of recent chats to show
-
onReady
-
recentConversationsGridLayoutRenderer
@Supply(to="recentConversationsGridLayout", subject="renderer") protected com.vaadin.flow.data.renderer.ComponentRenderer<AiConversationCard,AiConversation> recentConversationsGridLayoutRenderer() -
onShowAllHistoryBtnClick
@Subscribe("showAllHistoryBtn") public void onShowAllHistoryBtnClick(com.vaadin.flow.component.ClickEvent<JmixButton> event) -
onHistoryCloseBtnClick
@Subscribe("historyCloseBtn") public void onHistoryCloseBtnClick(com.vaadin.flow.component.ClickEvent<JmixButton> event) -
onHistoryNewBtnClick
@Subscribe("historyNewBtn") public void onHistoryNewBtnClick(com.vaadin.flow.component.ClickEvent<JmixButton> event) -
onHistorySearchFieldValueChange
@Subscribe("historySearchField") public void onHistorySearchFieldValueChange(SupportsTypedValue.TypedValueChangeEvent<TypedTextField<String>, String> event) -
startConversation
-
refreshRecentConversationsVisibility
protected void refreshRecentConversationsVisibility() -
refreshComposerAvailability
protected void refreshComposerAvailability()Disables the composer and warns the user when the chat model is not configured — starting a new chat would fail. -
loadConversations
protected void loadConversations() -
createRecentCard
-
createHistoryCard
-
createCard
-
openConversation
-
createConversationHref
Builds the address of a conversation's chat route, used as thehrefof its card so that the card behaves as a regular link.- Parameters:
conversation- conversation to link to- Returns:
- the conversation's route address
-
confirmDelete
-
deleteConversation
-
renderHistoryList
protected void renderHistoryList() -
applyHistoryFilter
-
groupByBucket
-
bucketLabel
-
createHistoryGroup
protected com.vaadin.flow.component.Component createHistoryGroup(String bucketLabel, List<AiConversation> conversations) -
resolveRecentChatsCount
protected int resolveRecentChatsCount() -
resolveMarkIcon
protected com.vaadin.flow.component.Component resolveMarkIcon() -
formatDateTime
-
orderByActivity
Orders conversations most recently active first; conversations with equal activity keep their incoming order.- Parameters:
conversations- conversations to order- Returns:
- a new list, most recently active first
-
resolveActivity
Resolves when a conversation was last active: the date of its latest message, or its creation date when it has no messages.- Parameters:
conversation- the conversation- Returns:
- the last-activity time, or
nullwhen the conversation has neither
-