🐛 (openai) Fix assistant sequence was not correctly saved
Also add logs to debug open ai errors. Related to #393.
This commit is contained in:
@@ -1,27 +1,38 @@
|
||||
import { Variable } from '@typebot.io/schemas'
|
||||
import { parseVariables } from './parseVariables'
|
||||
import {
|
||||
defaultParseVariablesOptions,
|
||||
parseVariables,
|
||||
ParseVariablesOptions,
|
||||
} from './parseVariables'
|
||||
|
||||
export const deepParseVariables =
|
||||
(variables: Variable[]) =>
|
||||
(
|
||||
variables: Variable[],
|
||||
options: ParseVariablesOptions = defaultParseVariablesOptions
|
||||
) =>
|
||||
<T extends Record<string, unknown>>(object: T): T =>
|
||||
Object.keys(object).reduce<T>((newObj, key) => {
|
||||
const currentValue = object[key]
|
||||
|
||||
if (typeof currentValue === 'string')
|
||||
return { ...newObj, [key]: parseVariables(variables)(currentValue) }
|
||||
return {
|
||||
...newObj,
|
||||
[key]: parseVariables(variables, options)(currentValue),
|
||||
}
|
||||
|
||||
if (currentValue instanceof Object && currentValue.constructor === Object)
|
||||
return {
|
||||
...newObj,
|
||||
[key]: deepParseVariables(variables)(
|
||||
currentValue as Record<string, unknown>
|
||||
),
|
||||
[key]: deepParseVariables(
|
||||
variables,
|
||||
options
|
||||
)(currentValue as Record<string, unknown>),
|
||||
}
|
||||
|
||||
if (currentValue instanceof Array)
|
||||
return {
|
||||
...newObj,
|
||||
[key]: currentValue.map(deepParseVariables(variables)),
|
||||
[key]: currentValue.map(deepParseVariables(variables, options)),
|
||||
}
|
||||
|
||||
return { ...newObj, [key]: currentValue }
|
||||
|
||||
Reference in New Issue
Block a user