ai 6.0.48 → 6.0.50

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.50
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [cbf1704]
8
+ - @ai-sdk/gateway@3.0.23
9
+
10
+ ## 6.0.49
11
+
12
+ ### Patch Changes
13
+
14
+ - ded661b: feat(ai): add onStepFinish to agent.generate and agent.stream
15
+
3
16
  ## 6.0.48
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2793,10 +2793,19 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
2793
2793
  readonly output: InferCompleteOutput<OUTPUT>;
2794
2794
  }
2795
2795
 
2796
+ /**
2797
+ Callback that is set using the `onStepFinish` option.
2798
+
2799
+ @param stepResult - The result of the step.
2800
+ */
2801
+ type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
2802
+
2796
2803
  /**
2797
2804
  * Parameters for calling an agent.
2798
2805
  */
2799
- type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
2806
+ type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
2807
+ CALL_OPTIONS
2808
+ ] extends [never] ? {
2800
2809
  options?: never;
2801
2810
  } : {
2802
2811
  options: CALL_OPTIONS;
@@ -2835,11 +2844,15 @@ type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
2835
2844
  * Timeout in milliseconds. Can be specified as a number or as an object with `totalMs`.
2836
2845
  */
2837
2846
  timeout?: TimeoutConfiguration;
2847
+ /**
2848
+ * Callback that is called when each step (LLM call) is finished, including intermediate steps.
2849
+ */
2850
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
2838
2851
  };
2839
2852
  /**
2840
2853
  * Parameters for streaming an output from an agent.
2841
2854
  */
2842
- type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS> & {
2855
+ type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS, TOOLS> & {
2843
2856
  /**
2844
2857
  * Optional stream transformations.
2845
2858
  * They are applied in the order they are provided.
@@ -2871,7 +2884,7 @@ interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends
2871
2884
  /**
2872
2885
  * Generates an output from the agent (non-streaming).
2873
2886
  */
2874
- generate(options: AgentCallParameters<CALL_OPTIONS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
2887
+ generate(options: AgentCallParameters<CALL_OPTIONS, TOOLS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
2875
2888
  /**
2876
2889
  * Streams an output from the agent (streaming).
2877
2890
  */
@@ -2902,13 +2915,6 @@ type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepRes
2902
2915
  experimental_context?: unknown;
2903
2916
  }) => PromiseLike<void> | void;
2904
2917
 
2905
- /**
2906
- Callback that is set using the `onStepFinish` option.
2907
-
2908
- @param stepResult - The result of the step.
2909
- */
2910
- type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
2911
-
2912
2918
  /**
2913
2919
  * Configuration options for an agent.
2914
2920
  */
@@ -3000,7 +3006,7 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
3000
3006
  *
3001
3007
  * You can use this to have templates based on call options.
3002
3008
  */
3003
- prepareCall?: (options: AgentCallParameters<CALL_OPTIONS> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
3009
+ prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>>, 'onStepFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
3004
3010
  };
3005
3011
 
3006
3012
  /**
@@ -3027,14 +3033,15 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
3027
3033
  */
3028
3034
  get tools(): TOOLS;
3029
3035
  private prepareCall;
3036
+ private mergeOnStepFinishCallbacks;
3030
3037
  /**
3031
3038
  * Generates an output from the agent (non-streaming).
3032
3039
  */
3033
- generate({ abortSignal, timeout, ...options }: AgentCallParameters<CALL_OPTIONS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3040
+ generate({ abortSignal, timeout, onStepFinish, ...options }: AgentCallParameters<CALL_OPTIONS, TOOLS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3034
3041
  /**
3035
3042
  * Streams an output from the agent (streaming).
3036
3043
  */
3037
- stream({ abortSignal, timeout, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
3044
+ stream({ abortSignal, timeout, experimental_transform, onStepFinish, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
3038
3045
  }
3039
3046
 
3040
3047
  /**
@@ -3052,6 +3059,7 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
3052
3059
  *
3053
3060
  * @param agent - The agent to run.
3054
3061
  * @param uiMessages - The input UI messages.
3062
+ * @param onStepFinish - Callback that is called when each step is finished. Optional.
3055
3063
  *
3056
3064
  * @returns The response object.
3057
3065
  */
@@ -3062,6 +3070,7 @@ declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends
3062
3070
  timeout?: TimeoutConfiguration;
3063
3071
  options?: CALL_OPTIONS;
3064
3072
  experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3073
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
3065
3074
  } & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<Response>;
3066
3075
 
3067
3076
  declare const getOriginalFetch: () => typeof fetch;
@@ -3773,16 +3782,18 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
3773
3782
  * @param timeout - Timeout in milliseconds. Optional.
3774
3783
  * @param options - The options for the agent.
3775
3784
  * @param experimental_transform - The stream transformations. Optional.
3785
+ * @param onStepFinish - Callback that is called when each step is finished. Optional.
3776
3786
  *
3777
3787
  * @returns The UI message stream.
3778
3788
  */
3779
- declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, ...uiMessageStreamOptions }: {
3789
+ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, onStepFinish, ...uiMessageStreamOptions }: {
3780
3790
  agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
3781
3791
  uiMessages: unknown[];
3782
3792
  abortSignal?: AbortSignal;
3783
3793
  timeout?: TimeoutConfiguration;
3784
3794
  options?: CALL_OPTIONS;
3785
3795
  experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3796
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
3786
3797
  } & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<AsyncIterableStream<InferUIMessageChunk<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>>>;
3787
3798
 
3788
3799
  /**
@@ -3790,6 +3801,7 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
3790
3801
  *
3791
3802
  * @param agent - The agent to run.
3792
3803
  * @param uiMessages - The input UI messages.
3804
+ * @param onStepFinish - Callback that is called when each step is finished. Optional.
3793
3805
  */
3794
3806
  declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
3795
3807
  response: ServerResponse;
@@ -3799,6 +3811,7 @@ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends
3799
3811
  timeout?: TimeoutConfiguration;
3800
3812
  options?: CALL_OPTIONS;
3801
3813
  experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3814
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
3802
3815
  } & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<void>;
3803
3816
 
3804
3817
  /**
package/dist/index.d.ts CHANGED
@@ -2793,10 +2793,19 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
2793
2793
  readonly output: InferCompleteOutput<OUTPUT>;
2794
2794
  }
2795
2795
 
2796
+ /**
2797
+ Callback that is set using the `onStepFinish` option.
2798
+
2799
+ @param stepResult - The result of the step.
2800
+ */
2801
+ type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
2802
+
2796
2803
  /**
2797
2804
  * Parameters for calling an agent.
2798
2805
  */
2799
- type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
2806
+ type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
2807
+ CALL_OPTIONS
2808
+ ] extends [never] ? {
2800
2809
  options?: never;
2801
2810
  } : {
2802
2811
  options: CALL_OPTIONS;
@@ -2835,11 +2844,15 @@ type AgentCallParameters<CALL_OPTIONS> = ([CALL_OPTIONS] extends [never] ? {
2835
2844
  * Timeout in milliseconds. Can be specified as a number or as an object with `totalMs`.
2836
2845
  */
2837
2846
  timeout?: TimeoutConfiguration;
2847
+ /**
2848
+ * Callback that is called when each step (LLM call) is finished, including intermediate steps.
2849
+ */
2850
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
2838
2851
  };
2839
2852
  /**
2840
2853
  * Parameters for streaming an output from an agent.
2841
2854
  */
2842
- type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS> & {
2855
+ type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS, TOOLS> & {
2843
2856
  /**
2844
2857
  * Optional stream transformations.
2845
2858
  * They are applied in the order they are provided.
@@ -2871,7 +2884,7 @@ interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends
2871
2884
  /**
2872
2885
  * Generates an output from the agent (non-streaming).
2873
2886
  */
2874
- generate(options: AgentCallParameters<CALL_OPTIONS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
2887
+ generate(options: AgentCallParameters<CALL_OPTIONS, TOOLS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
2875
2888
  /**
2876
2889
  * Streams an output from the agent (streaming).
2877
2890
  */
@@ -2902,13 +2915,6 @@ type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepRes
2902
2915
  experimental_context?: unknown;
2903
2916
  }) => PromiseLike<void> | void;
2904
2917
 
2905
- /**
2906
- Callback that is set using the `onStepFinish` option.
2907
-
2908
- @param stepResult - The result of the step.
2909
- */
2910
- type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
2911
-
2912
2918
  /**
2913
2919
  * Configuration options for an agent.
2914
2920
  */
@@ -3000,7 +3006,7 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
3000
3006
  *
3001
3007
  * You can use this to have templates based on call options.
3002
3008
  */
3003
- prepareCall?: (options: AgentCallParameters<CALL_OPTIONS> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
3009
+ prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>>, 'onStepFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
3004
3010
  };
3005
3011
 
3006
3012
  /**
@@ -3027,14 +3033,15 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
3027
3033
  */
3028
3034
  get tools(): TOOLS;
3029
3035
  private prepareCall;
3036
+ private mergeOnStepFinishCallbacks;
3030
3037
  /**
3031
3038
  * Generates an output from the agent (non-streaming).
3032
3039
  */
3033
- generate({ abortSignal, timeout, ...options }: AgentCallParameters<CALL_OPTIONS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3040
+ generate({ abortSignal, timeout, onStepFinish, ...options }: AgentCallParameters<CALL_OPTIONS, TOOLS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3034
3041
  /**
3035
3042
  * Streams an output from the agent (streaming).
3036
3043
  */
3037
- stream({ abortSignal, timeout, experimental_transform, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
3044
+ stream({ abortSignal, timeout, experimental_transform, onStepFinish, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
3038
3045
  }
3039
3046
 
3040
3047
  /**
@@ -3052,6 +3059,7 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
3052
3059
  *
3053
3060
  * @param agent - The agent to run.
3054
3061
  * @param uiMessages - The input UI messages.
3062
+ * @param onStepFinish - Callback that is called when each step is finished. Optional.
3055
3063
  *
3056
3064
  * @returns The response object.
3057
3065
  */
@@ -3062,6 +3070,7 @@ declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends
3062
3070
  timeout?: TimeoutConfiguration;
3063
3071
  options?: CALL_OPTIONS;
3064
3072
  experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3073
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
3065
3074
  } & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<Response>;
3066
3075
 
3067
3076
  declare const getOriginalFetch: () => typeof fetch;
@@ -3773,16 +3782,18 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
3773
3782
  * @param timeout - Timeout in milliseconds. Optional.
3774
3783
  * @param options - The options for the agent.
3775
3784
  * @param experimental_transform - The stream transformations. Optional.
3785
+ * @param onStepFinish - Callback that is called when each step is finished. Optional.
3776
3786
  *
3777
3787
  * @returns The UI message stream.
3778
3788
  */
3779
- declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, ...uiMessageStreamOptions }: {
3789
+ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, onStepFinish, ...uiMessageStreamOptions }: {
3780
3790
  agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
3781
3791
  uiMessages: unknown[];
3782
3792
  abortSignal?: AbortSignal;
3783
3793
  timeout?: TimeoutConfiguration;
3784
3794
  options?: CALL_OPTIONS;
3785
3795
  experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3796
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
3786
3797
  } & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<AsyncIterableStream<InferUIMessageChunk<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>>>;
3787
3798
 
3788
3799
  /**
@@ -3790,6 +3801,7 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
3790
3801
  *
3791
3802
  * @param agent - The agent to run.
3792
3803
  * @param uiMessages - The input UI messages.
3804
+ * @param onStepFinish - Callback that is called when each step is finished. Optional.
3793
3805
  */
3794
3806
  declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
3795
3807
  response: ServerResponse;
@@ -3799,6 +3811,7 @@ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends
3799
3811
  timeout?: TimeoutConfiguration;
3800
3812
  options?: CALL_OPTIONS;
3801
3813
  experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3814
+ onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
3802
3815
  } & UIMessageStreamResponseInit & UIMessageStreamOptions<UIMessage<MESSAGE_METADATA, never, InferUITools<TOOLS>>>): Promise<void>;
3803
3816
 
3804
3817
  /**
package/dist/index.js CHANGED
@@ -1073,7 +1073,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1073
1073
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1074
1074
 
1075
1075
  // src/version.ts
1076
- var VERSION = true ? "6.0.48" : "0.0.0-test";
1076
+ var VERSION = true ? "6.0.50" : "0.0.0-test";
1077
1077
 
1078
1078
  // src/util/download/download.ts
1079
1079
  var download = async ({ url }) => {
@@ -7508,12 +7508,16 @@ var ToolLoopAgent = class {
7508
7508
  }
7509
7509
  async prepareCall(options) {
7510
7510
  var _a18, _b, _c, _d;
7511
+ const { onStepFinish: _settingsOnStepFinish, ...settingsWithoutCallback } = this.settings;
7511
7512
  const baseCallArgs = {
7512
- ...this.settings,
7513
+ ...settingsWithoutCallback,
7513
7514
  stopWhen: (_a18 = this.settings.stopWhen) != null ? _a18 : stepCountIs(20),
7514
7515
  ...options
7515
7516
  };
7516
- const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? void 0 : _c.call(_b, baseCallArgs))) != null ? _d : baseCallArgs;
7517
+ const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? void 0 : _c.call(
7518
+ _b,
7519
+ baseCallArgs
7520
+ ))) != null ? _d : baseCallArgs;
7517
7521
  const { instructions, messages, prompt, ...callArgs } = preparedCallArgs;
7518
7522
  return {
7519
7523
  ...callArgs,
@@ -7521,18 +7525,30 @@ var ToolLoopAgent = class {
7521
7525
  ...{ system: instructions, messages, prompt }
7522
7526
  };
7523
7527
  }
7528
+ mergeOnStepFinishCallbacks(methodCallback) {
7529
+ const constructorCallback = this.settings.onStepFinish;
7530
+ if (methodCallback && constructorCallback) {
7531
+ return async (stepResult) => {
7532
+ await constructorCallback(stepResult);
7533
+ await methodCallback(stepResult);
7534
+ };
7535
+ }
7536
+ return methodCallback != null ? methodCallback : constructorCallback;
7537
+ }
7524
7538
  /**
7525
7539
  * Generates an output from the agent (non-streaming).
7526
7540
  */
7527
7541
  async generate({
7528
7542
  abortSignal,
7529
7543
  timeout,
7544
+ onStepFinish,
7530
7545
  ...options
7531
7546
  }) {
7532
7547
  return generateText({
7533
7548
  ...await this.prepareCall(options),
7534
7549
  abortSignal,
7535
- timeout
7550
+ timeout,
7551
+ onStepFinish: this.mergeOnStepFinishCallbacks(onStepFinish)
7536
7552
  });
7537
7553
  }
7538
7554
  /**
@@ -7542,13 +7558,15 @@ var ToolLoopAgent = class {
7542
7558
  abortSignal,
7543
7559
  timeout,
7544
7560
  experimental_transform,
7561
+ onStepFinish,
7545
7562
  ...options
7546
7563
  }) {
7547
7564
  return streamText({
7548
7565
  ...await this.prepareCall(options),
7549
7566
  abortSignal,
7550
7567
  timeout,
7551
- experimental_transform
7568
+ experimental_transform,
7569
+ onStepFinish: this.mergeOnStepFinishCallbacks(onStepFinish)
7552
7570
  });
7553
7571
  }
7554
7572
  };
@@ -8307,6 +8325,7 @@ async function createAgentUIStream({
8307
8325
  abortSignal,
8308
8326
  timeout,
8309
8327
  experimental_transform,
8328
+ onStepFinish,
8310
8329
  ...uiMessageStreamOptions
8311
8330
  }) {
8312
8331
  const validatedMessages = await validateUIMessages({
@@ -8321,7 +8340,8 @@ async function createAgentUIStream({
8321
8340
  options,
8322
8341
  abortSignal,
8323
8342
  timeout,
8324
- experimental_transform
8343
+ experimental_transform,
8344
+ onStepFinish
8325
8345
  });
8326
8346
  return result.toUIMessageStream(uiMessageStreamOptions);
8327
8347
  }