Skip to content
Discussion options

You must be logged in to vote

Great question. The current implementation relies on TypeScript's static typing and the _getType() method, which returns "ai" for both AIMessage and AIMessageChunk. This means the provided type guards (isAIMessage, isAIMessageChunk) can't distinguish between the two at runtime, which can be confusing in streaming scenarios like yours. This isn't a bug, but it is a limitation of the current design—there's no runtime check for the actual class, just the type string, so both functions can return true for either class see source.

It would be reasonable for the library to improve these type guards to use instanceof checks, making them more robust for runtime differentiation. This would help p…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dosubot
Comment options

Answer selected by abogacki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant