Package io.jmix.aichat.data
Class ContainerAiChatItems<T extends AiChatMessage>
java.lang.Object
io.jmix.aichat.data.AbstractAiChatItems<T>
io.jmix.aichat.data.ContainerAiChatItems<T>
- Type Parameters:
T- the application's message type
- All Implemented Interfaces:
AiChatItems<T>,ContainerDataUnit<T>,DataUnit,EntityDataUnit,Serializable
public class ContainerAiChatItems<T extends AiChatMessage>
extends AbstractAiChatItems<T>
implements ContainerDataUnit<T>
AiChatItems implementation over a Jmix CollectionContainer:
the container is the source of truth, and generated messages are appended to
it, so the chat takes part in the view's ordinary load and save cycle.
Whether a message is tracked by a DataContext is decided by the
AiChatMessageFactory that creates it; this unit only stores instances
and never saves anything.
Messages are rendered in container order, so the loader must sort them
chronologically ascending — on the entity's own persistent timestamp attribute,
not on the derived AiChatMessage.getTime() property. This unit neither
sorts nor validates; AiChat warns once per binding when the order it
reads here is not ascending. A timestamp stamped per entity at
prePersist does not order two messages saved in one commit, so a loader
batching a turn needs a deterministic tiebreaker.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.jmix.aichat.data.AiChatItems
AiChatItems.ItemsChangeEvent<T extends AiChatMessage>, AiChatItems.ItemsChangeTypeNested classes/interfaces inherited from interface io.jmix.flowui.data.DataUnit
DataUnit.StateChangeEvent -
Field Summary
FieldsFields inherited from class io.jmix.aichat.data.AbstractAiChatItems
eventBus -
Constructor Summary
ConstructorsConstructorDescriptionContainerAiChatItems(CollectionContainer<T> container) Creates a unit over the given container, subscribing to its collection and item property changes. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends a message to the end of the conversation.protected voidprotected voidprotected AiChatItems.ItemsChangeTypeconvertToItemsChangeType(CollectionChangeType changeType) Returns theCollectionContainerassociated with this data unit.getItems()Returns the messages in render order.voidremoveItem(T item) Removes a message from the conversation.Methods inherited from class io.jmix.aichat.data.AbstractAiChatItems
addItemsChangeListener, addStateChangeListener, fireItemsChangeEvent, getEventBus, getStateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jmix.flowui.data.DataUnit
addStateChangeListener, getState
-
Field Details
-
container
-
-
Constructor Details
-
ContainerAiChatItems
Creates a unit over the given container, subscribing to its collection and item property changes.- Parameters:
container- the container to wrap, notnull
-
-
Method Details
-
getItems
Description copied from interface:AiChatItemsReturns the messages in render order. The returned list is not modifiable; useAiChatItems.addItem(AiChatMessage)andAiChatItems.removeItem(AiChatMessage)instead.- Specified by:
getItemsin interfaceAiChatItems<T extends AiChatMessage>- Returns:
- the messages in render order
-
addItem
Description copied from interface:AiChatItemsAppends a message to the end of the conversation. Implementations must fire anAiChatItems.ItemsChangeEventof typeAiChatItems.ItemsChangeType.ADD—AiChatre-renders on that notification alone, so a silent mutation leaves the message unrendered.- Specified by:
addItemin interfaceAiChatItems<T extends AiChatMessage>- Parameters:
item- the message to append
-
removeItem
Description copied from interface:AiChatItemsRemoves a message from the conversation. Does nothing when the message is not present. Implementations must fire anAiChatItems.ItemsChangeEventof typeAiChatItems.ItemsChangeType.REMOVEfor an actual removal —AiChatre-renders on that notification alone, so a silent mutation leaves the message rendered.- Specified by:
removeItemin interfaceAiChatItems<T extends AiChatMessage>- Parameters:
item- the message to remove
-
getContainer
Description copied from interface:ContainerDataUnitReturns theCollectionContainerassociated with this data unit.- Specified by:
getContainerin interfaceContainerDataUnit<T extends AiChatMessage>- Returns:
- the container that holds a collection of entity instances
-
getEntityMetaClass
- Specified by:
getEntityMetaClassin interfaceEntityDataUnit- Returns:
MetaClassof an entity contained in the source
-
containerCollectionChanged
-
containerItemPropertyChanged
-
convertToItemsChangeType
-