nlux
nlux copied to clipboard
custom message renderer or wrapper
Several chat UIs out there have extra widgets along a message like thumbs up / down, share, report, etc.
It would be handy to have a way to decorate the message box with interactive components. I think there are 3 ways to approach this:
-
custom components to render messages
-
custom component to wrap the message (keep current rendering)
-
injecting a widget/markup in the current
nluxc-text-message-content
div
element -
In Discord @salmenus mentioned something along passing a custom rendered:
<AiChat messageRenderer={MyCustomMessageRenderer} />
type CustomMessageRenderer = (message: string, extras: OtherMessageRelatedInfo): ReactElement
But I guess this won't work in stream mode, I mean it will work as in fetch mode unless we make the component also deal with the streaming adapter.
-
Alternatively a wrapper would just decorate the message which is rendered by the original core component (
<AiChat />
renders<MyCustomMessageWrapper message={message} extras={extras}>{children}</Myβ¦>
) where{children}
is the original core component that does handle streaming, markdown, etc. And I guess while streaming themessage
andextras
props will get updated, maybe acomplete
prop (fed from the streaming adapter observer?) would be needed too to know that now I can interact with my decorations? -
Like 2, let's keep the original rendering but instead of wrapping it just add some custom component in React or markup in js:
<AiChat messageHeader={MyCustomMessageHeader} messageFooter={MyCustomMessageFooter} />
But even injecting plain markup would be enough with React, having messageHeader={<div className="header"></div>}
would allow me to render what I need inside with createPortal
.
It would be nice if the customisation could be done in a way to works at core component level, such that could be used in both js and react.