🐛 Correctly reset state when streaming fails

Closes #2094
This commit is contained in:
Baptiste Arnaud 2025-03-24 18:44:25 +01:00
parent 80498808ff
commit 413e29bc9e
No known key found for this signature in database
4 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.3.71",
"version": "0.3.72",
"description": "Javascript library to display typebots on your website",
"license": "FSL-1.1-ALv2",
"type": "module",

View File

@ -227,6 +227,11 @@ export const ConversationContainer = (props: Props) => {
};
const sendMessage = async (answer?: InputSubmitContent) => {
if (hasError() && clientSideActions().length > 0) {
setHasError(false);
await processClientSideActions(clientSideActions());
return;
}
setHasError(false);
const currentInputBlock = [...chatChunks()].pop()?.input;
@ -421,6 +426,7 @@ export const ConversationContainer = (props: Props) => {
};
const processClientSideActions = async (actions: ClientSideAction[]) => {
let hasStreamError = false;
for (const action of actions) {
if (
"streamOpenAiChatCompletion" in action ||
@ -439,6 +445,7 @@ export const ConversationContainer = (props: Props) => {
onMessageStream: streamMessage,
onStreamError: async (error) => {
setHasError(true);
hasStreamError = true;
await saveLogs([error]);
props.onNewLogs?.([error]);
},
@ -450,6 +457,7 @@ export const ConversationContainer = (props: Props) => {
continue;
}
}
if (hasStreamError) return;
setClientSideActions((actions) => actions.slice(1));
if (response && "logs" in response) saveLogs(response.logs);

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.3.71",
"version": "0.3.72",
"license": "FSL-1.1-ALv2",
"description": "Convenient library to display typebots on your Next.js website",
"type": "module",

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.3.71",
"version": "0.3.72",
"description": "Convenient library to display typebots on your React app",
"license": "FSL-1.1-ALv2",
"type": "module",