Merge branch 'main' into FEATURE/Vision

This commit is contained in:
Henry Heng
2024-02-14 18:06:33 +08:00
committed by GitHub
130 changed files with 6581 additions and 284 deletions
+22
View File
@@ -662,6 +662,28 @@ export const convertSchemaToZod = (schema: string | object): ICommonObject => {
}
}
/**
* Flatten nested object
* @param {ICommonObject} obj
* @param {string} parentKey
* @returns {ICommonObject}
*/
export const flattenObject = (obj: ICommonObject, parentKey?: string) => {
let result: any = {}
Object.keys(obj).forEach((key) => {
const value = obj[key]
const _key = parentKey ? parentKey + '.' + key : key
if (typeof value === 'object') {
result = { ...result, ...flattenObject(value, _key) }
} else {
result[_key] = value
}
})
return result
}
/**
* Convert BaseMessage to IMessage
* @param {BaseMessage[]} messages