From 577b4413a90247cd0314f9df69241af41034bb96 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Thu, 20 Feb 2025 01:20:19 +0100 Subject: [PATCH] fix(react): output non-abort errors in console, handle bogus message type --- libs/sdk-js/src/react/stream.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/sdk-js/src/react/stream.tsx b/libs/sdk-js/src/react/stream.tsx index 106cfea5e..900368b14 100644 --- a/libs/sdk-js/src/react/stream.tsx +++ b/libs/sdk-js/src/react/stream.tsx @@ -62,6 +62,14 @@ class MessageTupleManager { } add(serialized: Message): string | null { + // TODO: this is sometimes sent from the API + // figure out how to prevent this or move this to LC.js + if (serialized.type.endsWith("MessageChunk")) { + serialized.type = serialized.type + .slice(0, -"MessageChunk".length) + .toLowerCase() as Message["type"]; + } + const chunk = convertToChunk(coerceMessageLikeToMessage(serialized)); const id = chunk.id; @@ -772,6 +780,7 @@ export function useStream< (error.name === "AbortError" || error.name === "TimeoutError") ) ) { + console.error(error); setStreamError(error); onError?.(error); } @@ -785,7 +794,7 @@ export function useStream< } }; - const error = isLoading ? streamError : historyError; + const error = streamError ?? historyError; const values = streamValues ?? historyValues; return {