From a9568acba704062243b3a12e66c334e8f0e33181 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:51:38 +0000 Subject: [PATCH] fix: improve Node.js stream type handling in form data --- src/resources/messages.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/resources/messages.ts b/src/resources/messages.ts index ef8868ac..4db4d783 100644 --- a/src/resources/messages.ts +++ b/src/resources/messages.ts @@ -328,8 +328,14 @@ export class Messages extends Resource { const contentId = attachment.contentId || `file${index}`; // Handle different types of content (Buffer, ReadableStream, string) let file; - if (attachment.content instanceof ReadableStream || attachment.content instanceof Readable) { - // For ReadableStream or NodeJS.ReadableStream, use it directly as the file + if (attachment.content instanceof ReadableStream) { + // For web ReadableStream + file = attachment.content; + } else if ( + // @ts-ignore - Check for Node.js Readable stream + typeof attachment.content?.pipe === 'function' + ) { + // For Node.js streams (which have pipe method) file = attachment.content; } else if ( attachment.content instanceof Buffer ||