File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 11import { FormData , File } from 'formdata-node' ;
22import { ReadableStream } from 'node:stream/web' ;
3- import { Readable } from 'node:stream' ;
43import APIClient , { RequestOptionsParams } from '../apiClient.js' ;
54import { Overrides } from '../config.js' ;
65import {
@@ -328,13 +327,15 @@ export class Messages extends Resource {
328327 const contentId = attachment . contentId || `file${ index } ` ;
329328 // Handle different types of content (Buffer, ReadableStream, string)
330329 let file ;
330+ // Type guard for Node.js streams
331+ const isNodeStream = ( value : unknown ) : value is { pipe : Function } => {
332+ return value !== null && typeof value === 'object' && typeof ( value as any ) . pipe === 'function' ;
333+ } ;
334+
331335 if ( attachment . content instanceof ReadableStream ) {
332336 // For web ReadableStream
333337 file = attachment . content ;
334- } else if (
335- // @ts -ignore - Check for Node.js Readable stream
336- typeof attachment . content ?. pipe === 'function'
337- ) {
338+ } else if ( isNodeStream ( attachment . content ) ) {
338339 // For Node.js streams (which have pipe method)
339340 file = attachment . content ;
340341 } else if (
You can’t perform that action at this time.
0 commit comments