@@ -103,6 +103,7 @@ export function useRealtimeRun<TTask extends AnyTask>(
103
103
runId ,
104
104
apiClient ,
105
105
mutateRun ,
106
+ setError ,
106
107
abortControllerRef ,
107
108
typeof options ?. stopOnCompletion === "boolean" ? options . stopOnCompletion : true
108
109
) ;
@@ -150,6 +151,12 @@ export function useRealtimeRun<TTask extends AnyTask>(
150
151
} ;
151
152
} , [ runId , stop , options ?. enabled ] ) ;
152
153
154
+ useEffect ( ( ) => {
155
+ if ( run ?. finishedAt ) {
156
+ setIsComplete ( true ) ;
157
+ }
158
+ } , [ run ] ) ;
159
+
153
160
return { run, error, stop } ;
154
161
}
155
162
@@ -258,6 +265,7 @@ export function useRealtimeRunWithStreams<
258
265
mutateRun ,
259
266
mutateStreams ,
260
267
streamsRef ,
268
+ setError ,
261
269
abortControllerRef ,
262
270
typeof options ?. stopOnCompletion === "boolean" ? options . stopOnCompletion : true ,
263
271
options ?. experimental_throttleInMs
@@ -306,6 +314,12 @@ export function useRealtimeRunWithStreams<
306
314
} ;
307
315
} , [ runId , stop , options ?. enabled ] ) ;
308
316
317
+ useEffect ( ( ) => {
318
+ if ( run ?. finishedAt ) {
319
+ setIsComplete ( true ) ;
320
+ }
321
+ } , [ run ] ) ;
322
+
309
323
return { run, streams : streams ?? initialStreamsFallback , error, stop } ;
310
324
}
311
325
@@ -380,7 +394,14 @@ export function useRealtimeRunsWithTag<TTask extends AnyTask>(
380
394
const abortController = new AbortController ( ) ;
381
395
abortControllerRef . current = abortController ;
382
396
383
- await processRealtimeRunsWithTag ( tag , apiClient , mutateRuns , runsRef , abortControllerRef ) ;
397
+ await processRealtimeRunsWithTag (
398
+ tag ,
399
+ apiClient ,
400
+ mutateRuns ,
401
+ runsRef ,
402
+ setError ,
403
+ abortControllerRef
404
+ ) ;
384
405
} catch ( err ) {
385
406
// Ignore abort errors as they are expected.
386
407
if ( ( err as any ) . name === "AbortError" ) {
@@ -470,7 +491,14 @@ export function useRealtimeBatch<TTask extends AnyTask>(
470
491
const abortController = new AbortController ( ) ;
471
492
abortControllerRef . current = abortController ;
472
493
473
- await processRealtimeBatch ( batchId , apiClient , mutateRuns , runsRef , abortControllerRef ) ;
494
+ await processRealtimeBatch (
495
+ batchId ,
496
+ apiClient ,
497
+ mutateRuns ,
498
+ runsRef ,
499
+ setError ,
500
+ abortControllerRef
501
+ ) ;
474
502
} catch ( err ) {
475
503
// Ignore abort errors as they are expected.
476
504
if ( ( err as any ) . name === "AbortError" ) {
@@ -506,10 +534,12 @@ async function processRealtimeBatch<TTask extends AnyTask = AnyTask>(
506
534
apiClient : ApiClient ,
507
535
mutateRunsData : KeyedMutator < RealtimeRun < TTask > [ ] > ,
508
536
existingRunsRef : React . MutableRefObject < RealtimeRun < TTask > [ ] > ,
537
+ onError : ( e : Error ) => void ,
509
538
abortControllerRef : React . MutableRefObject < AbortController | null >
510
539
) {
511
540
const subscription = apiClient . subscribeToBatch < InferRunTypes < TTask > > ( batchId , {
512
541
signal : abortControllerRef . current ?. signal ,
542
+ onFetchError : onError ,
513
543
} ) ;
514
544
515
545
for await ( const part of subscription ) {
@@ -541,10 +571,12 @@ async function processRealtimeRunsWithTag<TTask extends AnyTask = AnyTask>(
541
571
apiClient : ApiClient ,
542
572
mutateRunsData : KeyedMutator < RealtimeRun < TTask > [ ] > ,
543
573
existingRunsRef : React . MutableRefObject < RealtimeRun < TTask > [ ] > ,
574
+ onError : ( e : Error ) => void ,
544
575
abortControllerRef : React . MutableRefObject < AbortController | null >
545
576
) {
546
577
const subscription = apiClient . subscribeToRunsWithTag < InferRunTypes < TTask > > ( tag , {
547
578
signal : abortControllerRef . current ?. signal ,
579
+ onFetchError : onError ,
548
580
} ) ;
549
581
550
582
for await ( const part of subscription ) {
@@ -582,13 +614,15 @@ async function processRealtimeRunWithStreams<
582
614
mutateRunData : KeyedMutator < RealtimeRun < TTask > > ,
583
615
mutateStreamData : KeyedMutator < StreamResults < TStreams > > ,
584
616
existingDataRef : React . MutableRefObject < StreamResults < TStreams > > ,
617
+ onError : ( e : Error ) => void ,
585
618
abortControllerRef : React . MutableRefObject < AbortController | null > ,
586
619
stopOnCompletion : boolean = true ,
587
620
throttleInMs ?: number
588
621
) {
589
622
const subscription = apiClient . subscribeToRun < InferRunTypes < TTask > > ( runId , {
590
623
signal : abortControllerRef . current ?. signal ,
591
624
closeOnComplete : stopOnCompletion ,
625
+ onFetchError : onError ,
592
626
} ) ;
593
627
594
628
type StreamUpdate = {
@@ -637,12 +671,14 @@ async function processRealtimeRun<TTask extends AnyTask = AnyTask>(
637
671
runId : string ,
638
672
apiClient : ApiClient ,
639
673
mutateRunData : KeyedMutator < RealtimeRun < TTask > > ,
674
+ onError : ( e : Error ) => void ,
640
675
abortControllerRef : React . MutableRefObject < AbortController | null > ,
641
676
stopOnCompletion : boolean = true
642
677
) {
643
678
const subscription = apiClient . subscribeToRun < InferRunTypes < TTask > > ( runId , {
644
679
signal : abortControllerRef . current ?. signal ,
645
680
closeOnComplete : stopOnCompletion ,
681
+ onFetchError : onError ,
646
682
} ) ;
647
683
648
684
for await ( const part of subscription ) {
0 commit comments