@gradio/client 2.0.0-dev.0 → 2.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -163,457 +163,459 @@ export function submit(
163
163
  });
164
164
  }
165
165
 
166
- this.handle_blob(config.root, resolved_data, endpoint_info).then(
167
- async (_payload) => {
168
- let input_data = handle_payload(
169
- _payload,
170
- dependency,
171
- config.components,
172
- "input",
173
- true
174
- );
175
- payload = {
176
- data: input_data || [],
177
- event_data,
166
+ const job = this.handle_blob(
167
+ config.root,
168
+ resolved_data,
169
+ endpoint_info
170
+ ).then(async (_payload) => {
171
+ let input_data = handle_payload(
172
+ _payload,
173
+ dependency,
174
+ config.components,
175
+ "input",
176
+ true
177
+ );
178
+ payload = {
179
+ data: input_data || [],
180
+ event_data,
181
+ fn_index,
182
+ trigger_id
183
+ };
184
+ if (skip_queue(fn_index, config)) {
185
+ fire_event({
186
+ type: "status",
187
+ endpoint: _endpoint,
188
+ stage: "pending",
189
+ queue: false,
178
190
  fn_index,
179
- trigger_id
180
- };
181
- if (skip_queue(fn_index, config)) {
182
- fire_event({
183
- type: "status",
184
- endpoint: _endpoint,
185
- stage: "pending",
186
- queue: false,
187
- fn_index,
188
- time: new Date()
189
- });
190
-
191
- post_data(
192
- `${config.root}${api_prefix}/run${
193
- _endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
194
- }${url_params ? "?" + url_params : ""}`,
195
- {
196
- ...payload,
197
- session_hash
198
- }
199
- )
200
- .then(([output, status_code]: any) => {
201
- const data = output.data;
202
- if (status_code == 200) {
203
- fire_event({
204
- type: "data",
205
- endpoint: _endpoint,
206
- fn_index,
207
- data: handle_payload(
208
- data,
209
- dependency,
210
- config.components,
211
- "output",
212
- options.with_null_state
213
- ),
214
- time: new Date(),
215
- event_data,
216
- trigger_id
217
- });
218
- if (output.render_config) {
219
- handle_render_config(output.render_config);
220
- }
221
-
222
- fire_event({
223
- type: "status",
224
- endpoint: _endpoint,
225
- fn_index,
226
- stage: "complete",
227
- eta: output.average_duration,
228
- queue: false,
229
- time: new Date()
230
- });
231
- } else {
232
- fire_event({
233
- type: "status",
234
- stage: "error",
235
- endpoint: _endpoint,
236
- fn_index,
237
- message: output.error,
238
- queue: false,
239
- time: new Date()
240
- });
241
- }
242
- })
243
- .catch((e) => {
244
- fire_event({
245
- type: "status",
246
- stage: "error",
247
- message: e.message,
248
- endpoint: _endpoint,
249
- fn_index,
250
- queue: false,
251
- time: new Date()
252
- });
253
- });
254
- } else if (protocol == "sse") {
255
- fire_event({
256
- type: "status",
257
- stage: "pending",
258
- queue: true,
259
- endpoint: _endpoint,
260
- fn_index,
261
- time: new Date()
262
- });
263
- var params = new URLSearchParams({
264
- fn_index: fn_index.toString(),
265
- session_hash: session_hash
266
- }).toString();
267
- let url = new URL(
268
- `${config.root}${api_prefix}/${SSE_URL}?${
269
- url_params ? url_params + "&" : ""
270
- }${params}`
271
- );
272
-
273
- if (this.jwt) {
274
- url.searchParams.set("__sign", this.jwt);
275
- }
276
-
277
- stream = this.stream(url);
191
+ time: new Date()
192
+ });
278
193
 
279
- if (!stream) {
280
- return Promise.reject(
281
- new Error("Cannot connect to SSE endpoint: " + url.toString())
282
- );
194
+ post_data(
195
+ `${config.root}${api_prefix}/run${
196
+ _endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
197
+ }${url_params ? "?" + url_params : ""}`,
198
+ {
199
+ ...payload,
200
+ session_hash
283
201
  }
202
+ )
203
+ .then(async ([output, status_code]: any) => {
204
+ const data = output.data;
284
205
 
285
- stream.onmessage = async function (event: MessageEvent) {
286
- const _data = JSON.parse(event.data);
287
- const { type, status, data } = handle_message(
288
- _data,
289
- last_status[fn_index]
290
- );
291
-
292
- if (type === "update" && status && !complete) {
293
- // call 'status' listeners
206
+ if (status_code == 200) {
294
207
  fire_event({
295
- type: "status",
208
+ type: "data",
296
209
  endpoint: _endpoint,
297
210
  fn_index,
298
- time: new Date(),
299
- ...status
300
- });
301
- if (status.stage === "error") {
302
- stream?.close();
303
- close();
304
- }
305
- } else if (type === "data") {
306
- let [_, status] = await post_data(
307
- `${config.root}${api_prefix}/queue/data`,
308
- {
309
- ...payload,
310
- session_hash,
311
- event_id
312
- }
313
- );
314
- if (status !== 200) {
315
- fire_event({
316
- type: "status",
317
- stage: "error",
318
- message: BROKEN_CONNECTION_MSG,
319
- queue: true,
320
- endpoint: _endpoint,
321
- fn_index,
322
- time: new Date()
323
- });
324
- stream?.close();
325
- close();
326
- }
327
- } else if (type === "complete") {
328
- complete = status;
329
- } else if (type === "log") {
330
- fire_event({
331
- type: "log",
332
- title: data.title,
333
- log: data.log,
334
- level: data.level,
335
- endpoint: _endpoint,
336
- duration: data.duration,
337
- visible: data.visible,
338
- fn_index
339
- });
340
- } else if (type === "generating" || type === "streaming") {
341
- fire_event({
342
- type: "status",
343
- time: new Date(),
344
- ...status,
345
- stage: status?.stage!,
346
- queue: true,
347
- endpoint: _endpoint,
348
- fn_index
349
- });
350
- }
351
- if (data) {
352
- fire_event({
353
- type: "data",
354
- time: new Date(),
355
211
  data: handle_payload(
356
- data.data,
212
+ data,
357
213
  dependency,
358
214
  config.components,
359
215
  "output",
360
216
  options.with_null_state
361
217
  ),
362
- endpoint: _endpoint,
363
- fn_index,
218
+ time: new Date(),
364
219
  event_data,
365
220
  trigger_id
366
221
  });
367
-
368
- if (complete) {
369
- fire_event({
370
- type: "status",
371
- time: new Date(),
372
- ...complete,
373
- stage: status?.stage!,
374
- queue: true,
375
- endpoint: _endpoint,
376
- fn_index
377
- });
378
- stream?.close();
379
- close();
222
+ if (output.render_config) {
223
+ await handle_render_config(output.render_config);
380
224
  }
381
- }
382
- };
383
- } else if (
384
- protocol == "sse_v1" ||
385
- protocol == "sse_v2" ||
386
- protocol == "sse_v2.1" ||
387
- protocol == "sse_v3"
388
- ) {
389
- // latest API format. v2 introduces sending diffs for intermediate outputs in generative functions, which makes payloads lighter.
390
- // v3 only closes the stream when the backend sends the close stream message.
391
- fire_event({
392
- type: "status",
393
- stage: "pending",
394
- queue: true,
395
- endpoint: _endpoint,
396
- fn_index,
397
- time: new Date()
398
- });
399
- let hostname = "";
400
- if (
401
- typeof window !== "undefined" &&
402
- typeof document !== "undefined"
403
- ) {
404
- hostname = window?.location?.hostname;
405
- }
406
225
 
407
- let hfhubdev = "dev.spaces.huggingface.tech";
408
- const origin = hostname.includes(".dev.")
409
- ? `https://moon-${hostname.split(".")[1]}.${hfhubdev}`
410
- : `https://huggingface.co`;
411
-
412
- const is_zerogpu_iframe =
413
- typeof window !== "undefined" &&
414
- typeof document !== "undefined" &&
415
- window.parent != window &&
416
- window.supports_zerogpu_headers;
417
- const zerogpu_auth_promise = is_zerogpu_iframe
418
- ? post_message<Map<string, string>>("zerogpu-headers", origin)
419
- : Promise.resolve(null);
420
- const post_data_promise = zerogpu_auth_promise.then((headers) => {
421
- return post_data(
422
- `${config.root}${api_prefix}/${SSE_DATA_URL}?${url_params}`,
423
- {
424
- ...payload,
425
- session_hash
426
- },
427
- headers
428
- );
429
- });
430
- post_data_promise.then(async ([response, status]: any) => {
431
- if (status === 503) {
432
226
  fire_event({
433
227
  type: "status",
434
- stage: "error",
435
- message: QUEUE_FULL_MSG,
436
- queue: true,
437
228
  endpoint: _endpoint,
438
229
  fn_index,
230
+ stage: "complete",
231
+ eta: output.average_duration,
232
+ queue: false,
439
233
  time: new Date()
440
234
  });
441
- } else if (status === 422) {
235
+ } else {
442
236
  fire_event({
443
237
  type: "status",
444
238
  stage: "error",
445
- message: response.detail,
446
- queue: true,
447
239
  endpoint: _endpoint,
448
240
  fn_index,
449
- code: "validation_error",
241
+ message: output.error,
242
+ queue: false,
450
243
  time: new Date()
451
244
  });
245
+ }
246
+ })
247
+ .catch((e) => {
248
+ fire_event({
249
+ type: "status",
250
+ stage: "error",
251
+ message: e.message,
252
+ endpoint: _endpoint,
253
+ fn_index,
254
+ queue: false,
255
+ time: new Date()
256
+ });
257
+ });
258
+ } else if (protocol == "sse") {
259
+ fire_event({
260
+ type: "status",
261
+ stage: "pending",
262
+ queue: true,
263
+ endpoint: _endpoint,
264
+ fn_index,
265
+ time: new Date()
266
+ });
267
+ var params = new URLSearchParams({
268
+ fn_index: fn_index.toString(),
269
+ session_hash: session_hash
270
+ }).toString();
271
+ let url = new URL(
272
+ `${config.root}${api_prefix}/${SSE_URL}?${
273
+ url_params ? url_params + "&" : ""
274
+ }${params}`
275
+ );
276
+
277
+ if (this.jwt) {
278
+ url.searchParams.set("__sign", this.jwt);
279
+ }
280
+
281
+ stream = this.stream(url);
282
+
283
+ if (!stream) {
284
+ return Promise.reject(
285
+ new Error("Cannot connect to SSE endpoint: " + url.toString())
286
+ );
287
+ }
288
+
289
+ stream.onmessage = async function (event: MessageEvent) {
290
+ const _data = JSON.parse(event.data);
291
+ const { type, status, data } = handle_message(
292
+ _data,
293
+ last_status[fn_index]
294
+ );
295
+
296
+ if (type === "update" && status && !complete) {
297
+ // call 'status' listeners
298
+ fire_event({
299
+ type: "status",
300
+ endpoint: _endpoint,
301
+ fn_index,
302
+ time: new Date(),
303
+ ...status
304
+ });
305
+ if (status.stage === "error") {
306
+ stream?.close();
452
307
  close();
453
- } else if (status !== 200) {
308
+ }
309
+ } else if (type === "data") {
310
+ let [_, status] = await post_data(
311
+ `${config.root}${api_prefix}/queue/data`,
312
+ {
313
+ ...payload,
314
+ session_hash,
315
+ event_id
316
+ }
317
+ );
318
+ if (status !== 200) {
454
319
  fire_event({
455
320
  type: "status",
456
321
  stage: "error",
457
- broken: false,
458
- message: response.detail,
322
+ message: BROKEN_CONNECTION_MSG,
459
323
  queue: true,
460
324
  endpoint: _endpoint,
461
325
  fn_index,
462
326
  time: new Date()
463
327
  });
464
- } else {
465
- event_id = response.event_id as string;
466
- event_id_final = event_id;
467
- let callback = async function (_data: object): Promise<void> {
468
- try {
469
- const { type, status, data, original_msg } = handle_message(
470
- _data,
471
- last_status[fn_index]
472
- );
473
-
474
- if (type == "heartbeat") {
475
- return;
476
- }
328
+ stream?.close();
329
+ close();
330
+ }
331
+ } else if (type === "complete") {
332
+ complete = status;
333
+ } else if (type === "log") {
334
+ fire_event({
335
+ type: "log",
336
+ title: data.title,
337
+ log: data.log,
338
+ level: data.level,
339
+ endpoint: _endpoint,
340
+ duration: data.duration,
341
+ visible: data.visible,
342
+ fn_index
343
+ });
344
+ } else if (type === "generating" || type === "streaming") {
345
+ fire_event({
346
+ type: "status",
347
+ time: new Date(),
348
+ ...status,
349
+ stage: status?.stage!,
350
+ queue: true,
351
+ endpoint: _endpoint,
352
+ fn_index
353
+ });
354
+ }
355
+ if (data) {
356
+ fire_event({
357
+ type: "data",
358
+ time: new Date(),
359
+ data: handle_payload(
360
+ data.data,
361
+ dependency,
362
+ config.components,
363
+ "output",
364
+ options.with_null_state
365
+ ),
366
+ endpoint: _endpoint,
367
+ fn_index,
368
+ event_data,
369
+ trigger_id
370
+ });
477
371
 
478
- if (type === "update" && status && !complete) {
479
- // call 'status' listeners
480
- fire_event({
481
- type: "status",
482
- endpoint: _endpoint,
483
- fn_index,
484
- time: new Date(),
485
- original_msg: original_msg,
486
- ...status
487
- });
488
- } else if (type === "complete") {
489
- complete = status;
490
- } else if (
491
- type == "unexpected_error" ||
492
- type == "broken_connection"
372
+ if (complete) {
373
+ fire_event({
374
+ type: "status",
375
+ time: new Date(),
376
+ ...complete,
377
+ stage: status?.stage!,
378
+ queue: true,
379
+ endpoint: _endpoint,
380
+ fn_index
381
+ });
382
+ stream?.close();
383
+ close();
384
+ }
385
+ }
386
+ };
387
+ } else if (
388
+ protocol == "sse_v1" ||
389
+ protocol == "sse_v2" ||
390
+ protocol == "sse_v2.1" ||
391
+ protocol == "sse_v3"
392
+ ) {
393
+ // latest API format. v2 introduces sending diffs for intermediate outputs in generative functions, which makes payloads lighter.
394
+ // v3 only closes the stream when the backend sends the close stream message.
395
+ fire_event({
396
+ type: "status",
397
+ stage: "pending",
398
+ queue: true,
399
+ endpoint: _endpoint,
400
+ fn_index,
401
+ time: new Date()
402
+ });
403
+ let hostname = "";
404
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
405
+ hostname = window?.location?.hostname;
406
+ }
407
+
408
+ let hfhubdev = "dev.spaces.huggingface.tech";
409
+ const origin = hostname.includes(".dev.")
410
+ ? `https://moon-${hostname.split(".")[1]}.${hfhubdev}`
411
+ : `https://huggingface.co`;
412
+
413
+ const is_zerogpu_iframe =
414
+ typeof window !== "undefined" &&
415
+ typeof document !== "undefined" &&
416
+ window.parent != window &&
417
+ window.supports_zerogpu_headers;
418
+ const zerogpu_auth_promise = is_zerogpu_iframe
419
+ ? post_message<Map<string, string>>("zerogpu-headers", origin)
420
+ : Promise.resolve(null);
421
+ const post_data_promise = zerogpu_auth_promise.then((headers) => {
422
+ return post_data(
423
+ `${config.root}${api_prefix}/${SSE_DATA_URL}?${url_params}`,
424
+ {
425
+ ...payload,
426
+ session_hash
427
+ },
428
+ headers
429
+ );
430
+ });
431
+
432
+ return post_data_promise.then(async ([response, status]: any) => {
433
+ if (response.event_id) {
434
+ event_id_final = response.event_id as string;
435
+ }
436
+
437
+ if (status === 503) {
438
+ fire_event({
439
+ type: "status",
440
+ stage: "error",
441
+ message: QUEUE_FULL_MSG,
442
+ queue: true,
443
+ endpoint: _endpoint,
444
+ fn_index,
445
+ time: new Date(),
446
+ visible: true
447
+ });
448
+ } else if (status === 422) {
449
+ fire_event({
450
+ type: "status",
451
+ stage: "error",
452
+ message: response.detail,
453
+ queue: true,
454
+ endpoint: _endpoint,
455
+ fn_index,
456
+ code: "validation_error",
457
+ time: new Date(),
458
+ visible: true
459
+ });
460
+ close();
461
+ } else if (status !== 200) {
462
+ fire_event({
463
+ type: "status",
464
+ stage: "error",
465
+ broken: false,
466
+ message: response.detail,
467
+ queue: true,
468
+ endpoint: _endpoint,
469
+ fn_index,
470
+ time: new Date(),
471
+ visible: true
472
+ });
473
+ } else {
474
+ event_id = response.event_id as string;
475
+ event_id_final = event_id;
476
+ let callback = async function (_data: object): Promise<void> {
477
+ try {
478
+ const { type, status, data, original_msg } = handle_message(
479
+ _data,
480
+ last_status[fn_index]
481
+ );
482
+
483
+ if (type == "heartbeat") {
484
+ return;
485
+ }
486
+
487
+ if (type === "update" && status && !complete) {
488
+ // call 'status' listeners
489
+ fire_event({
490
+ type: "status",
491
+ endpoint: _endpoint,
492
+ fn_index,
493
+ time: new Date(),
494
+ original_msg: original_msg,
495
+ ...status
496
+ });
497
+ } else if (type === "complete") {
498
+ complete = status;
499
+ } else if (
500
+ type == "unexpected_error" ||
501
+ type == "broken_connection"
502
+ ) {
503
+ console.error("Unexpected error", status?.message);
504
+ const broken = type === "broken_connection";
505
+ fire_event({
506
+ type: "status",
507
+ stage: "error",
508
+ message: status?.message || "An Unexpected Error Occurred!",
509
+ queue: true,
510
+ endpoint: _endpoint,
511
+ broken,
512
+ session_not_found: status?.session_not_found,
513
+ fn_index,
514
+ time: new Date()
515
+ });
516
+ } else if (type === "log") {
517
+ fire_event({
518
+ type: "log",
519
+ title: data.title,
520
+ log: data.log,
521
+ level: data.level,
522
+ endpoint: _endpoint,
523
+ duration: data.duration,
524
+ visible: data.visible,
525
+ fn_index
526
+ });
527
+ return;
528
+ } else if (type === "generating" || type === "streaming") {
529
+ fire_event({
530
+ type: "status",
531
+ time: new Date(),
532
+ ...status,
533
+ stage: status?.stage!,
534
+ queue: true,
535
+ endpoint: _endpoint,
536
+ fn_index
537
+ });
538
+ if (
539
+ data &&
540
+ dependency.connection !== "stream" &&
541
+ ["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)
493
542
  ) {
494
- console.error("Unexpected error", status?.message);
495
- const broken = type === "broken_connection";
496
- fire_event({
497
- type: "status",
498
- stage: "error",
499
- message:
500
- status?.message || "An Unexpected Error Occurred!",
501
- queue: true,
502
- endpoint: _endpoint,
503
- broken,
504
- session_not_found: status?.session_not_found,
505
- fn_index,
506
- time: new Date()
507
- });
508
- } else if (type === "log") {
509
- fire_event({
510
- type: "log",
511
- title: data.title,
512
- log: data.log,
513
- level: data.level,
514
- endpoint: _endpoint,
515
- duration: data.duration,
516
- visible: data.visible,
517
- fn_index
518
- });
519
- return;
520
- } else if (type === "generating" || type === "streaming") {
543
+ apply_diff_stream(pending_diff_streams, event_id!, data);
544
+ }
545
+ }
546
+ if (data) {
547
+ fire_event({
548
+ type: "data",
549
+ time: new Date(),
550
+ data: handle_payload(
551
+ data.data,
552
+ dependency,
553
+ config.components,
554
+ "output",
555
+ options.with_null_state
556
+ ),
557
+ endpoint: _endpoint,
558
+ fn_index
559
+ });
560
+ if (data.render_config) {
561
+ await handle_render_config(data.render_config);
562
+ }
563
+
564
+ if (complete) {
521
565
  fire_event({
522
566
  type: "status",
523
567
  time: new Date(),
524
- ...status,
568
+ ...complete,
525
569
  stage: status?.stage!,
526
570
  queue: true,
527
571
  endpoint: _endpoint,
528
572
  fn_index
529
573
  });
530
- if (
531
- data &&
532
- dependency.connection !== "stream" &&
533
- ["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)
534
- ) {
535
- apply_diff_stream(pending_diff_streams, event_id!, data);
536
- }
537
- }
538
- if (data) {
539
- fire_event({
540
- type: "data",
541
- time: new Date(),
542
- data: handle_payload(
543
- data.data,
544
- dependency,
545
- config.components,
546
- "output",
547
- options.with_null_state
548
- ),
549
- endpoint: _endpoint,
550
- fn_index
551
- });
552
- if (data.render_config) {
553
- await handle_render_config(data.render_config);
554
- }
555
-
556
- if (complete) {
557
- fire_event({
558
- type: "status",
559
- time: new Date(),
560
- ...complete,
561
- stage: status?.stage!,
562
- queue: true,
563
- endpoint: _endpoint,
564
- fn_index
565
- });
566
- close();
567
- }
574
+ close();
568
575
  }
576
+ }
569
577
 
570
- if (
571
- status?.stage === "complete" ||
572
- status?.stage === "error"
573
- ) {
574
- if (event_callbacks[event_id!]) {
575
- delete event_callbacks[event_id!];
576
- }
577
- if (event_id! in pending_diff_streams) {
578
- delete pending_diff_streams[event_id!];
579
- }
578
+ if (status?.stage === "complete" || status?.stage === "error") {
579
+ if (event_callbacks[event_id!]) {
580
+ delete event_callbacks[event_id!];
580
581
  }
581
- } catch (e) {
582
- console.error("Unexpected client exception", e);
583
- fire_event({
584
- type: "status",
585
- stage: "error",
586
- message: "An Unexpected Error Occurred!",
587
- queue: true,
588
- endpoint: _endpoint,
589
- fn_index,
590
- time: new Date()
591
- });
592
- if (["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)) {
593
- close_stream(stream_status, that.abort_controller);
594
- stream_status.open = false;
595
- close();
582
+ if (event_id! in pending_diff_streams) {
583
+ delete pending_diff_streams[event_id!];
596
584
  }
597
585
  }
598
- };
599
-
600
- if (event_id in pending_stream_messages) {
601
- pending_stream_messages[event_id].forEach((msg) =>
602
- callback(msg)
603
- );
604
- delete pending_stream_messages[event_id];
605
- }
606
- // @ts-ignore
607
- event_callbacks[event_id] = callback;
608
- unclosed_events.add(event_id);
609
- if (!stream_status.open) {
610
- await this.open_stream();
586
+ } catch (e) {
587
+ console.error("Unexpected client exception", e);
588
+ fire_event({
589
+ type: "status",
590
+ stage: "error",
591
+ message: "An Unexpected Error Occurred!",
592
+ queue: true,
593
+ endpoint: _endpoint,
594
+ fn_index,
595
+ time: new Date()
596
+ });
597
+ if (["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)) {
598
+ close_stream(stream_status, that.abort_controller);
599
+ stream_status.open = false;
600
+ close();
601
+ }
611
602
  }
603
+ };
604
+
605
+ if (event_id in pending_stream_messages) {
606
+ pending_stream_messages[event_id].forEach((msg) => callback(msg));
607
+ delete pending_stream_messages[event_id];
612
608
  }
613
- });
614
- }
609
+ // @ts-ignore
610
+ event_callbacks[event_id] = callback;
611
+ unclosed_events.add(event_id);
612
+ if (!stream_status.open) {
613
+ await this.open_stream();
614
+ }
615
+ }
616
+ });
615
617
  }
616
- );
618
+ });
617
619
 
618
620
  let done = false;
619
621
  const values: (IteratorResult<GradioEvent> | PromiseLike<never>)[] = [];
@@ -665,10 +667,28 @@ export function submit(
665
667
  },
666
668
  return: async () => {
667
669
  close();
668
- return next();
670
+ return { value: undefined, done: true as const };
669
671
  },
670
672
  cancel,
671
- event_id: event_id_cb
673
+ send_chunk: (payload: Record<string, unknown>) => {
674
+ this.post_data(`${config.root}${api_prefix}/stream/${event_id_final}`, {
675
+ ...payload,
676
+ session_hash: this.session_hash
677
+ });
678
+ },
679
+ close_stream: () => {
680
+ this.post_data(
681
+ `${config.root}${api_prefix}/stream/${event_id_final}/close`,
682
+ {}
683
+ );
684
+
685
+ close();
686
+ },
687
+ event_id: () => event_id_final,
688
+ wait_for_id: async () => {
689
+ await job;
690
+ return event_id;
691
+ }
672
692
  };
673
693
 
674
694
  return iterator;