Cleanup, make more robust

This commit is contained in:
Tat Dat Duong
2025-04-30 16:52:35 +02:00
parent e556b13a06
commit 58dd69d1a2
2 changed files with 14 additions and 11 deletions

View File

@@ -32,13 +32,12 @@ function CustomComponent({
return (
<Fragment key={message.id}>
{customComponents.map((customComponent) => (
<Fragment key={customComponent.id}>
<LoadExternalComponent
key={customComponent.id}
stream={thread}
message={customComponent}
meta={{ ui: customComponent, artifact }}
/>
</Fragment>
))}
</Fragment>
);

View File

@@ -9,6 +9,8 @@ import { useStream } from "@langchain/langgraph-sdk/react";
import { type Message } from "@langchain/langgraph-sdk";
import {
uiMessageReducer,
isUIMessage,
isRemoveUIMessage,
type UIMessage,
type RemoveUIMessage,
} from "@langchain/langgraph-sdk/react-ui";
@@ -82,10 +84,12 @@ const StreamSession = ({
assistantId,
threadId: threadId ?? null,
onCustomEvent: (event, options) => {
if (isUIMessage(event) || isRemoveUIMessage(event)) {
options.mutate((prev) => {
const ui = uiMessageReducer(prev.ui ?? [], event);
return { ...prev, ui };
});
}
},
onThreadId: (id) => {
setThreadId(id);