diff --git a/src/Client.ts b/src/Client.ts index f7597dd..d09f891 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -7,7 +7,7 @@ import * as core from "./core"; import * as Cohere from "./api/index"; import * as serializers from "./serialization/index"; import urlJoin from "url-join"; -import * as stream from "stream"; +import * as stream from "readable-stream"; import * as errors from "./errors/index"; import { EmbedJobs } from "./api/resources/embedJobs/client/Client"; import { Datasets } from "./api/resources/datasets/client/Client"; diff --git a/src/core/form-data-utils/FormDataWrapper.ts b/src/core/form-data-utils/FormDataWrapper.ts index fb88797..fbec47f 100644 --- a/src/core/form-data-utils/FormDataWrapper.ts +++ b/src/core/form-data-utils/FormDataWrapper.ts @@ -37,8 +37,8 @@ export async function newFormData(): Promise { class Node18FormData implements CrossPlatformFormData { private fd: | { - append(name: string, value: unknown, fileName?: string): void; - } + append(name: string, value: unknown, fileName?: string): void; + } | undefined; public async setup() { @@ -50,7 +50,7 @@ class Node18FormData implements CrossPlatformFormData { } public async appendFile(key: string, value: unknown, fileName?: string): Promise { - if (value instanceof (await import("stream")).Readable) { + if (value instanceof (await import("readable-stream")).Readable) { this.fd?.append(key, { type: undefined, name: fileName, @@ -67,7 +67,7 @@ class Node18FormData implements CrossPlatformFormData { public async getRequest(): Promise> { const encoder = new (await import("form-data-encoder")).FormDataEncoder(this.fd as any); return { - body: await (await import("stream")).Readable.from(encoder), + body: await (await import("readable-stream")).Readable.from(encoder), headers: encoder.headers, duplex: "half", }; @@ -80,22 +80,22 @@ class Node18FormData implements CrossPlatformFormData { class Node16FormData implements CrossPlatformFormData { private fd: | { - append( - name: string, - value: unknown, - options?: - | string - | { - header?: string | Headers; - knownLength?: number; - filename?: string; - filepath?: string; - contentType?: string; - } - ): void; - - getHeaders(): Record; - } + append( + name: string, + value: unknown, + options?: + | string + | { + header?: string | Headers; + knownLength?: number; + filename?: string; + filepath?: string; + contentType?: string; + } + ): void; + + getHeaders(): Record; + } | undefined; public async setup(): Promise { @@ -108,7 +108,7 @@ class Node16FormData implements CrossPlatformFormData { public async appendFile(key: string, value: unknown, fileName?: string): Promise { let bufferedValue; - if (!(value instanceof (await import("stream")).Readable)) { + if (!(value instanceof (await import("readable-stream")).Readable)) { bufferedValue = Buffer.from(await (value as any).arrayBuffer()); } else { bufferedValue = value; diff --git a/src/core/streaming-fetcher/Stream.ts b/src/core/streaming-fetcher/Stream.ts index dccdb79..d290076 100644 --- a/src/core/streaming-fetcher/Stream.ts +++ b/src/core/streaming-fetcher/Stream.ts @@ -1,4 +1,4 @@ -import { Readable } from "stream"; +import { Readable } from "readable-stream"; import { RUNTIME } from "../runtime"; export declare namespace Stream {