🌿 fix: forking a long conversation breaks chat structure (#4778)

* fix: branching and forking sometimes break conversation structure

* fix test for forking.

* chore: message type issues

* test: add conversation structure tests for message handling

---------

Co-authored-by: xyqyear <xyqyear@gmail.com>
This commit is contained in:
Danny Avila 2024-11-22 16:10:59 -05:00 committed by GitHub
parent 7d5be68747
commit c87a51eaab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 248 additions and 16 deletions

View file

@ -73,15 +73,17 @@ async function saveMessage(req, params, metadata) {
* @async
* @function bulkSaveMessages
* @param {Object[]} messages - An array of message objects to save.
* @param {boolean} [overrideTimestamp=false] - Indicates whether to override the timestamps of the messages. Defaults to false.
* @returns {Promise<Object>} The result of the bulk write operation.
* @throws {Error} If there is an error in saving messages in bulk.
*/
async function bulkSaveMessages(messages) {
async function bulkSaveMessages(messages, overrideTimestamp=false) {
try {
const bulkOps = messages.map((message) => ({
updateOne: {
filter: { messageId: message.messageId },
update: message,
timestamps: !overrideTimestamp,
upsert: true,
},
}));