@@ -117,6 +117,7 @@ If set and supported by the model, calls will generate deterministic results.
117
117
@param experimental_generateMessageId - Generate a unique ID for each message.
118
118
119
119
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
120
+ @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
120
121
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
121
122
@param onFinish - Callback that is called when the LLM response and all request tool executions
122
123
(for tools that have an `execute` function) are finished.
@@ -151,6 +152,7 @@ export function streamText<
151
152
experimental_repairToolCall : repairToolCall ,
152
153
experimental_transform : transform ,
153
154
onChunk,
155
+ onError,
154
156
onFinish,
155
157
onStepFinish,
156
158
_internal : {
@@ -267,6 +269,11 @@ Callback that is called for each chunk of the stream. The stream processing will
267
269
> ;
268
270
} ) => Promise < void > | void ;
269
271
272
+ /**
273
+ Callback that is invoked when an error occurs during streaming. You can use it to log errors.
274
+ */
275
+ onError ?: ( event : { error : unknown } ) => Promise < void > | void ;
276
+
270
277
/**
271
278
Callback that is called when the LLM response and all request tool executions
272
279
(for tools that have an `execute` function) are finished.
@@ -317,6 +324,7 @@ Internal. For test use only. May change without notice.
317
324
continueSteps,
318
325
providerOptions,
319
326
onChunk,
327
+ onError,
320
328
onFinish,
321
329
onStepFinish,
322
330
now,
@@ -478,6 +486,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT, PARTIAL_OUTPUT>
478
486
continueSteps,
479
487
providerOptions,
480
488
onChunk,
489
+ onError,
481
490
onFinish,
482
491
onStepFinish,
483
492
now,
@@ -520,6 +529,7 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT, PARTIAL_OUTPUT>
520
529
}
521
530
> ;
522
531
} ) => Promise < void > | void ) ;
532
+ onError : undefined | ( ( event : { error : unknown } ) => Promise < void > | void ) ;
523
533
onFinish :
524
534
| undefined
525
535
| ( (
@@ -588,6 +598,10 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT, PARTIAL_OUTPUT>
588
598
await onChunk ?.( { chunk : part } ) ;
589
599
}
590
600
601
+ if ( part . type === 'error' ) {
602
+ await onError ?.( { error : part . error } ) ;
603
+ }
604
+
591
605
if ( part . type === 'text-delta' ) {
592
606
recordedStepText += part . textDelta ;
593
607
recordedContinuationText += part . textDelta ;
0 commit comments