Class AiChatLoader
- All Implemented Interfaces:
ComponentLoader<AiChat<?>>
AiChat from a view descriptor.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.jmix.flowui.xml.layout.ComponentLoader
ComponentLoader.AutowireTask, ComponentLoader.ComponentContext, ComponentLoader.Context, ComponentLoader.FragmentContext, ComponentLoader.InitTask -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable ActionLoaderSupportprotected @Nullable AiComponentLoaderSupportprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringFields inherited from class io.jmix.flowui.xml.layout.loader.AbstractComponentLoader
applicationContext, componentLoaderSupport, context, element, factory, loaderResolver, loaderSupport, resultComponent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AiChat<?> protected ActionLoaderSupportprotected AiComponentLoaderSupportprotected voidinitAutoSave(boolean autoSave) Installs the default persistence delegates whenautoSaveis on: the common handling every view otherwise retypes.voidCreates result component by XML-elementvoidLoads component properties by XML definition.protected voidBinds the declared collection container as the chat's message source.protected voidloadI18n()Applies the labels declared in the nestedi18nelement on top of the localization the component resolved from the message bundle when it was created — the chat's own announcements, and, from the nestedmessageInputandmessageListelements, the labels of the two components it composes.protected voidLoads the system prompt from the nestedsystemPromptelement, or, when it is absent, from thesystemPromptattribute — the same pairaiCodeBlockoffers for its code, and for the same reason: a prompt is routinely multi-line.protected ObjectsaveMessage(DataContext dataContext, Object message) The default save delegate: merges the message into the context, saves, and returns the tracked instance the database's answer was merged back into.protected EntitySetsaveOrEvict(DataContext dataContext, Object entity) Saves the context, evicting the given entity if the save fails.Methods inherited from class io.jmix.flowui.xml.layout.loader.AbstractComponentLoader
componentLoader, getContext, getElement, getFactory, getLayoutLoader, getLoaderResolver, getLoaderSupport, getResultComponent, loadBoolean, loadBoolean, loadDouble, loadDouble, loadEnum, loadEnum, loadId, loadInteger, loadInteger, loadResourceString, loadResourceString, loadResourceString, loadString, loadString, loadString, loadVisible, setApplicationContext, setContext, setElement, setFactory, setLoaderResolver, setLoaderSupport
-
Field Details
-
DATA_CONTAINER_ATTRIBUTE_NAME
- See Also:
-
SYSTEM_PROMPT_ELEMENT_NAME
- See Also:
-
MAX_ROWS_ATTRIBUTE_NAME
- See Also:
-
ENTER_ACTION_ATTRIBUTE_NAME
- See Also:
-
INPUT_PREFIX_ELEMENT_NAME
- See Also:
-
INPUT_SUFFIX_ELEMENT_NAME
- See Also:
-
INPUT_HEADER_ELEMENT_NAME
- See Also:
-
INPUT_FOOTER_ELEMENT_NAME
- See Also:
-
THINKING_INDICATOR_ELEMENT_NAME
- See Also:
-
USER_ACTIONS_ELEMENT_NAME
- See Also:
-
ASSISTANT_ACTIONS_ELEMENT_NAME
- See Also:
-
EMPTY_STATE_HEADER_ELEMENT_NAME
- See Also:
-
EMPTY_STATE_FOOTER_ELEMENT_NAME
- See Also:
-
AUTO_SAVE_ATTRIBUTE_NAME
- See Also:
-
aiComponentLoaderSupport
-
actionLoaderSupport
-
-
Constructor Details
-
AiChatLoader
public AiChatLoader()
-
-
Method Details
-
createComponent
- Specified by:
createComponentin classAbstractComponentLoader<AiChat<?>>
-
initComponent
public void initComponent()Description copied from interface:ComponentLoaderCreates result component by XML-element- Specified by:
initComponentin interfaceComponentLoader<AiChat<?>>- Overrides:
initComponentin classAbstractComponentLoader<AiChat<?>>
-
loadComponent
public void loadComponent()Description copied from interface:ComponentLoaderLoads component properties by XML definition. -
loadSystemPrompt
protected void loadSystemPrompt()Loads the system prompt from the nestedsystemPromptelement, or, when it is absent, from thesystemPromptattribute — the same pairaiCodeBlockoffers for its code, and for the same reason: a prompt is routinely multi-line. Absent from both is not an error; the provider's own default then applies. A present but blank element is an error: loading it as "" would silently shadow the attribute. -
loadI18n
protected void loadI18n()Applies the labels declared in the nestedi18nelement on top of the localization the component resolved from the message bundle when it was created — the chat's own announcements, and, from the nestedmessageInputandmessageListelements, the labels of the two components it composes.The element edits the tree the chat already carries rather than building a fresh one, so a label it does not declare keeps its bundle value instead of falling back to the client's hardcoded English.
-
loadDataContainer
protected void loadDataContainer()Binds the declared collection container as the chat's message source.Resolved by hand rather than through
DataLoaderSupport:AiChatbinds through its ownAiChatItemsabstraction and deliberately does not implementSupportsItemsContainer, so nothing in the framework would pick this up. -
initAutoSave
protected void initAutoSave(boolean autoSave) Installs the default persistence delegates whenautoSaveis on: the common handling every view otherwise retypes. Both go through the view'sDataContext, so the instance the component keeps is the tracked one thatsave()merges the database's answer back into.Two kinds of warning are logged here, and they are deliberately not the same:
- Nothing is installed when the context cannot persist — absent, or read-only. Installing a delegate that silently saves nothing would be worse than leaving the attribute inert, because the component would report every message as stored.
- The delegates are installed anyway when the descriptor declares no
dataContainer.autoSaveis XML-only, so a descriptor attribute is the only way to turn it on, but a chat bound programmatically inonInit()to an entity-backedContainerAiChatItemshas nodataContainerattribute either, and is a legitimate, fully-working configuration. Making that case inert too would break it, so this one only warns — it does not know at load time what the view will bind, and the warning is an unavoidable false positive for that programmatic case. Do not "fix" the inconsistency by making this case inert as well.
- Parameters:
autoSave- whether the descriptor asked for automatic persistence
-
saveMessage
The default save delegate: merges the message into the context, saves, and returns the tracked instance the database's answer was merged back into.- Parameters:
dataContext- the context to save throughmessage- the committed message- Returns:
- the tracked instance
- Throws:
IllegalStateException- when the context reports no save for the message
-
saveOrEvict
Saves the context, evicting the given entity if the save fails.DataContextImpl#saveclears its modified and removed sets only after the store accepted them, so a rejected entity stays queued and is retried by every later save — re-failing forever on a constraint, or inserting out of order once the cause clears. Evicting drops it from both sets, which is what makes the failure recoverable.- Parameters:
dataContext- the context to saveentity- the entity to evict if the save fails- Returns:
- the entities the context reported as saved
-
getAiComponentLoaderSupport
-
getActionLoaderSupport
-