🚸 (openai) Parse stream on client to correctly handle errors
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ChatReply, Theme } from '@typebot.io/schemas'
|
||||
import { ChatReply, SendMessageInput, Theme } from '@typebot.io/schemas'
|
||||
import { InputBlockType } from '@typebot.io/schemas/features/blocks/inputs/enums'
|
||||
import { createEffect, createSignal, For, onMount, Show } from 'solid-js'
|
||||
import { sendMessageQuery } from '@/queries/sendMessageQuery'
|
||||
@@ -79,7 +79,7 @@ export const ConversationContainer = (props: Props) => {
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
sendMessage(response.replyToSend)
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
@@ -95,7 +95,11 @@ export const ConversationContainer = (props: Props) => {
|
||||
)
|
||||
})
|
||||
|
||||
const sendMessage = async (message: string | undefined) => {
|
||||
const sendMessage = async (
|
||||
message: string | undefined,
|
||||
clientLogs?: SendMessageInput['clientLogs']
|
||||
) => {
|
||||
if (clientLogs) props.onNewLogs?.(clientLogs)
|
||||
setHasError(false)
|
||||
const currentInputBlock = [...chatChunks()].pop()?.input
|
||||
if (currentInputBlock?.id && props.onAnswer && message)
|
||||
@@ -114,6 +118,7 @@ export const ConversationContainer = (props: Props) => {
|
||||
apiHost: props.context.apiHost,
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
message,
|
||||
clientLogs,
|
||||
})
|
||||
clearTimeout(longRequest)
|
||||
setIsSending(false)
|
||||
@@ -151,7 +156,7 @@ export const ConversationContainer = (props: Props) => {
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
sendMessage(response.replyToSend)
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
@@ -200,7 +205,7 @@ export const ConversationContainer = (props: Props) => {
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
sendMessage(response.replyToSend)
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
|
||||
Reference in New Issue
Block a user