File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -289,7 +289,11 @@ class Replicate {
289
289
290
290
if ( prediction . urls && prediction . urls . stream ) {
291
291
const { signal } = options ;
292
- const stream = new Stream ( prediction . urls . stream , { signal } ) ;
292
+ const stream = new Stream ( {
293
+ url : prediction . urls . stream ,
294
+ fetch : this . fetch ,
295
+ options : { signal } ,
296
+ } ) ;
293
297
yield * stream ;
294
298
} else {
295
299
throw new Error ( "Prediction does not support streaming" ) ;
Original file line number Diff line number Diff line change @@ -48,10 +48,12 @@ class Stream extends Readable {
48
48
/**
49
49
* Create a new stream of server-sent events.
50
50
*
51
- * @param {string } url The URL to connect to.
52
- * @param {object } options The fetch options.
51
+ * @param {object } config
52
+ * @param {string } config.url The URL to connect to.
53
+ * @param {Function } [config.fetch] The fetch implemention to use.
54
+ * @param {object } [config.options] The fetch options.
53
55
*/
54
- constructor ( url , options ) {
56
+ constructor ( { url, fetch = globalThis . fetch , options = { } } ) {
55
57
if ( ! Readable ) {
56
58
throw new Error (
57
59
"Readable streams are not supported. Please use Node.js 18 or later, or install the readable-stream package."
@@ -60,6 +62,7 @@ class Stream extends Readable {
60
62
61
63
super ( ) ;
62
64
this . url = url ;
65
+ this . fetch = fetch ;
63
66
this . options = options ;
64
67
65
68
this . event = null ;
@@ -104,7 +107,7 @@ class Stream extends Readable {
104
107
}
105
108
106
109
async * [ Symbol . asyncIterator ] ( ) {
107
- const response = await fetch ( this . url , {
110
+ const response = await this . fetch ( this . url , {
108
111
...this . options ,
109
112
headers : {
110
113
Accept : "text/event-stream" ,
You can’t perform that action at this time.
0 commit comments