ai 6.0.236 → 6.0.238

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,25 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.238
4
+
5
+ ### Patch Changes
6
+
7
+ - 9ecdefe: Prevent validated downloads on Node.js from reaching private or internal services through DNS aliases or DNS rebinding by validating and pinning every resolved address at connection time.
8
+ - 26d10c0: support overriding model call settings for individual `prepareStep` invocations
9
+ - 7767170: Preserve provider metadata from empty text deltas in `streamText`.
10
+ - Updated dependencies [9ecdefe]
11
+ - Updated dependencies [87fb433]
12
+ - @ai-sdk/provider-utils@4.0.41
13
+ - @ai-sdk/gateway@3.0.160
14
+
15
+ ## 6.0.237
16
+
17
+ ### Patch Changes
18
+
19
+ - f6020d7: Avoid synthesizing client tool errors for invalid provider-executed tool calls.
20
+ - Updated dependencies [de438f5]
21
+ - @ai-sdk/gateway@3.0.159
22
+
3
23
  ## 6.0.236
4
24
 
5
25
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -861,7 +861,8 @@ type StepResult<TOOLS extends ToolSet> = {
861
861
  */
862
862
  readonly content: Array<ContentPart<TOOLS>>;
863
863
  /**
864
- * The generated text.
864
+ * The concatenation of all text parts generated in this step.
865
+ * It is an empty string if the step contains no text parts.
865
866
  */
866
867
  readonly text: string;
867
868
  /**
@@ -947,6 +948,7 @@ type StepResult<TOOLS extends ToolSet> = {
947
948
  readonly providerMetadata: ProviderMetadata | undefined;
948
949
  };
949
950
 
951
+ type PrepareStepCallSettings = Pick<CallSettings, 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed'>;
950
952
  /**
951
953
  * Function that you can use to provide different settings for a step.
952
954
  *
@@ -984,9 +986,13 @@ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Too
984
986
  }) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
985
987
  /**
986
988
  * The result type returned by a {@link PrepareStepFunction},
987
- * allowing per-step overrides of model, tools, or messages.
989
+ * allowing per-step overrides of model call settings, model, tools, or
990
+ * messages.
991
+ *
992
+ * Model call setting overrides apply only to the current step. Undefined
993
+ * settings fall back to the outer call settings.
988
994
  */
989
- type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
995
+ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = ({
990
996
  /**
991
997
  * Optionally override which LanguageModel instance is used for this step.
992
998
  */
@@ -1023,7 +1029,7 @@ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>
1023
1029
  * container IDs for Anthropic's code execution.
1024
1030
  */
1025
1031
  providerOptions?: ProviderOptions;
1026
- } | undefined;
1032
+ } & PrepareStepCallSettings) | undefined;
1027
1033
 
1028
1034
  type StopCondition<TOOLS extends ToolSet> = (options: {
1029
1035
  steps: Array<StepResult<TOOLS>>;
@@ -1055,7 +1061,9 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
1055
1061
  */
1056
1062
  readonly content: Array<ContentPart<TOOLS>>;
1057
1063
  /**
1058
- * The text that was generated in the last step.
1064
+ * The concatenation of all text parts generated in the final step.
1065
+ * It is an empty string if the final step contains no text parts.
1066
+ * Inspect `content` for a text part to distinguish that case.
1059
1067
  */
1060
1068
  readonly text: string;
1061
1069
  /**
@@ -2347,8 +2355,9 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
2347
2355
  readonly providerMetadata: PromiseLike<ProviderMetadata | undefined>;
2348
2356
  /**
2349
2357
  * A text stream that returns only the generated text deltas. You can use it
2350
- * as either an AsyncIterable or a ReadableStream. When an error occurs, the
2351
- * stream will throw the error.
2358
+ * as either an AsyncIterable or a ReadableStream. Error parts are not
2359
+ * surfaced in this stream. Use the `onError` callback or `fullStream` to
2360
+ * observe them.
2352
2361
  */
2353
2362
  readonly textStream: AsyncIterableStream<string>;
2354
2363
  /**
package/dist/index.d.ts CHANGED
@@ -861,7 +861,8 @@ type StepResult<TOOLS extends ToolSet> = {
861
861
  */
862
862
  readonly content: Array<ContentPart<TOOLS>>;
863
863
  /**
864
- * The generated text.
864
+ * The concatenation of all text parts generated in this step.
865
+ * It is an empty string if the step contains no text parts.
865
866
  */
866
867
  readonly text: string;
867
868
  /**
@@ -947,6 +948,7 @@ type StepResult<TOOLS extends ToolSet> = {
947
948
  readonly providerMetadata: ProviderMetadata | undefined;
948
949
  };
949
950
 
951
+ type PrepareStepCallSettings = Pick<CallSettings, 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed'>;
950
952
  /**
951
953
  * Function that you can use to provide different settings for a step.
952
954
  *
@@ -984,9 +986,13 @@ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Too
984
986
  }) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
985
987
  /**
986
988
  * The result type returned by a {@link PrepareStepFunction},
987
- * allowing per-step overrides of model, tools, or messages.
989
+ * allowing per-step overrides of model call settings, model, tools, or
990
+ * messages.
991
+ *
992
+ * Model call setting overrides apply only to the current step. Undefined
993
+ * settings fall back to the outer call settings.
988
994
  */
989
- type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
995
+ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = ({
990
996
  /**
991
997
  * Optionally override which LanguageModel instance is used for this step.
992
998
  */
@@ -1023,7 +1029,7 @@ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>
1023
1029
  * container IDs for Anthropic's code execution.
1024
1030
  */
1025
1031
  providerOptions?: ProviderOptions;
1026
- } | undefined;
1032
+ } & PrepareStepCallSettings) | undefined;
1027
1033
 
1028
1034
  type StopCondition<TOOLS extends ToolSet> = (options: {
1029
1035
  steps: Array<StepResult<TOOLS>>;
@@ -1055,7 +1061,9 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
1055
1061
  */
1056
1062
  readonly content: Array<ContentPart<TOOLS>>;
1057
1063
  /**
1058
- * The text that was generated in the last step.
1064
+ * The concatenation of all text parts generated in the final step.
1065
+ * It is an empty string if the final step contains no text parts.
1066
+ * Inspect `content` for a text part to distinguish that case.
1059
1067
  */
1060
1068
  readonly text: string;
1061
1069
  /**
@@ -2347,8 +2355,9 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
2347
2355
  readonly providerMetadata: PromiseLike<ProviderMetadata | undefined>;
2348
2356
  /**
2349
2357
  * A text stream that returns only the generated text deltas. You can use it
2350
- * as either an AsyncIterable or a ReadableStream. When an error occurs, the
2351
- * stream will throw the error.
2358
+ * as either an AsyncIterable or a ReadableStream. Error parts are not
2359
+ * surfaced in this stream. Use the `onError` callback or `fullStream` to
2360
+ * observe them.
2352
2361
  */
2353
2362
  readonly textStream: AsyncIterableStream<string>;
2354
2363
  /**
package/dist/index.js CHANGED
@@ -1304,7 +1304,7 @@ function detectMediaType({
1304
1304
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1305
1305
 
1306
1306
  // src/version.ts
1307
- var VERSION = true ? "6.0.236" : "0.0.0-test";
1307
+ var VERSION = true ? "6.0.238" : "0.0.0-test";
1308
1308
 
1309
1309
  // src/util/download/download.ts
1310
1310
  var download = async ({
@@ -4189,6 +4189,24 @@ async function doParseToolCall({
4189
4189
  };
4190
4190
  }
4191
4191
 
4192
+ // src/generate-text/prepare-step-call-settings.ts
4193
+ function prepareStepCallSettings({
4194
+ callSettings,
4195
+ stepSettings
4196
+ }) {
4197
+ var _a22, _b, _c, _d, _e, _f, _g, _h;
4198
+ return prepareCallSettings({
4199
+ maxOutputTokens: (_a22 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a22 : callSettings.maxOutputTokens,
4200
+ temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
4201
+ topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
4202
+ topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
4203
+ presencePenalty: (_e = stepSettings == null ? void 0 : stepSettings.presencePenalty) != null ? _e : callSettings.presencePenalty,
4204
+ frequencyPenalty: (_f = stepSettings == null ? void 0 : stepSettings.frequencyPenalty) != null ? _f : callSettings.frequencyPenalty,
4205
+ stopSequences: (_g = stepSettings == null ? void 0 : stepSettings.stopSequences) != null ? _g : callSettings.stopSequences,
4206
+ seed: (_h = stepSettings == null ? void 0 : stepSettings.seed) != null ? _h : callSettings.seed
4207
+ });
4208
+ }
4209
+
4192
4210
  // src/generate-text/step-result.ts
4193
4211
  var DefaultStepResult = class {
4194
4212
  constructor({
@@ -4744,6 +4762,10 @@ async function generateText({
4744
4762
  providerOptions,
4745
4763
  prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
4746
4764
  );
4765
+ const stepCallSettings = prepareStepCallSettings({
4766
+ callSettings: callSettings2,
4767
+ stepSettings: prepareStepResult
4768
+ });
4747
4769
  await notify({
4748
4770
  event: {
4749
4771
  stepNumber: steps.length,
@@ -4771,113 +4793,110 @@ async function generateText({
4771
4793
  ]
4772
4794
  });
4773
4795
  currentModelResponse = await retry(
4774
- () => {
4775
- var _a23;
4776
- return recordSpan({
4777
- name: "ai.generateText.doGenerate",
4778
- attributes: selectTelemetryAttributes({
4779
- telemetry,
4780
- attributes: {
4781
- ...assembleOperationName({
4782
- operationId: "ai.generateText.doGenerate",
4783
- telemetry
4784
- }),
4785
- ...baseTelemetryAttributes,
4786
- // model:
4787
- "ai.model.provider": stepModel.provider,
4788
- "ai.model.id": stepModel.modelId,
4789
- // prompt:
4790
- "ai.prompt.messages": {
4791
- input: () => stringifyForTelemetry(promptMessages)
4792
- },
4793
- "ai.prompt.tools": {
4794
- // convert the language model level tools:
4795
- input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
4796
- },
4797
- "ai.prompt.toolChoice": {
4798
- input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
4799
- },
4800
- // standardized gen-ai llm span attributes:
4801
- "gen_ai.system": stepModel.provider,
4802
- "gen_ai.request.model": stepModel.modelId,
4803
- "gen_ai.request.frequency_penalty": settings.frequencyPenalty,
4804
- "gen_ai.request.max_tokens": settings.maxOutputTokens,
4805
- "gen_ai.request.presence_penalty": settings.presencePenalty,
4806
- "gen_ai.request.stop_sequences": settings.stopSequences,
4807
- "gen_ai.request.temperature": (_a23 = settings.temperature) != null ? _a23 : void 0,
4808
- "gen_ai.request.top_k": settings.topK,
4809
- "gen_ai.request.top_p": settings.topP
4810
- }
4811
- }),
4812
- tracer,
4813
- fn: async (span2) => {
4814
- var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
4815
- const result = await stepModel.doGenerate({
4816
- ...callSettings2,
4817
- tools: stepTools,
4818
- toolChoice: stepToolChoice,
4819
- responseFormat: await (output == null ? void 0 : output.responseFormat),
4820
- prompt: promptMessages,
4821
- providerOptions: stepProviderOptions,
4822
- abortSignal: mergedAbortSignal,
4823
- headers: headersWithUserAgent
4824
- });
4825
- const responseData = {
4826
- id: (_b2 = (_a24 = result.response) == null ? void 0 : _a24.id) != null ? _b2 : generateId2(),
4827
- timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
4828
- modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
4829
- headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
4830
- body: (_h2 = result.response) == null ? void 0 : _h2.body
4831
- };
4832
- const usage = asLanguageModelUsage(result.usage);
4833
- span2.setAttributes(
4834
- await selectTelemetryAttributes({
4835
- telemetry,
4836
- attributes: {
4837
- "ai.response.finishReason": result.finishReason.unified,
4838
- "ai.response.text": {
4839
- output: () => extractTextContent(result.content)
4840
- },
4841
- "ai.response.reasoning": {
4842
- output: () => extractReasoningContent(result.content)
4843
- },
4844
- "ai.response.toolCalls": {
4845
- output: () => {
4846
- const toolCalls = asToolCalls(result.content);
4847
- return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
4848
- }
4849
- },
4850
- "ai.response.id": responseData.id,
4851
- "ai.response.model": responseData.modelId,
4852
- "ai.response.timestamp": responseData.timestamp.toISOString(),
4853
- "ai.response.providerMetadata": JSON.stringify(
4854
- result.providerMetadata
4855
- ),
4856
- "ai.usage.inputTokens": result.usage.inputTokens.total,
4857
- "ai.usage.inputTokenDetails.noCacheTokens": result.usage.inputTokens.noCache,
4858
- "ai.usage.inputTokenDetails.cacheReadTokens": result.usage.inputTokens.cacheRead,
4859
- "ai.usage.inputTokenDetails.cacheWriteTokens": result.usage.inputTokens.cacheWrite,
4860
- "ai.usage.outputTokens": result.usage.outputTokens.total,
4861
- "ai.usage.outputTokenDetails.textTokens": result.usage.outputTokens.text,
4862
- "ai.usage.outputTokenDetails.reasoningTokens": result.usage.outputTokens.reasoning,
4863
- "ai.usage.totalTokens": usage.totalTokens,
4864
- "ai.usage.reasoningTokens": result.usage.outputTokens.reasoning,
4865
- "ai.usage.cachedInputTokens": result.usage.inputTokens.cacheRead,
4866
- // standardized gen-ai llm span attributes:
4867
- "gen_ai.response.finish_reasons": [
4868
- result.finishReason.unified
4869
- ],
4870
- "gen_ai.response.id": responseData.id,
4871
- "gen_ai.response.model": responseData.modelId,
4872
- "gen_ai.usage.input_tokens": result.usage.inputTokens.total,
4873
- "gen_ai.usage.output_tokens": result.usage.outputTokens.total
4874
- }
4875
- })
4876
- );
4877
- return { ...result, response: responseData };
4796
+ () => recordSpan({
4797
+ name: "ai.generateText.doGenerate",
4798
+ attributes: selectTelemetryAttributes({
4799
+ telemetry,
4800
+ attributes: {
4801
+ ...assembleOperationName({
4802
+ operationId: "ai.generateText.doGenerate",
4803
+ telemetry
4804
+ }),
4805
+ ...baseTelemetryAttributes,
4806
+ // model:
4807
+ "ai.model.provider": stepModel.provider,
4808
+ "ai.model.id": stepModel.modelId,
4809
+ // prompt:
4810
+ "ai.prompt.messages": {
4811
+ input: () => stringifyForTelemetry(promptMessages)
4812
+ },
4813
+ "ai.prompt.tools": {
4814
+ // convert the language model level tools:
4815
+ input: () => stepTools == null ? void 0 : stepTools.map((tool2) => JSON.stringify(tool2))
4816
+ },
4817
+ "ai.prompt.toolChoice": {
4818
+ input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : void 0
4819
+ },
4820
+ // standardized gen-ai llm span attributes:
4821
+ "gen_ai.system": stepModel.provider,
4822
+ "gen_ai.request.model": stepModel.modelId,
4823
+ "gen_ai.request.frequency_penalty": stepCallSettings.frequencyPenalty,
4824
+ "gen_ai.request.max_tokens": stepCallSettings.maxOutputTokens,
4825
+ "gen_ai.request.presence_penalty": stepCallSettings.presencePenalty,
4826
+ "gen_ai.request.stop_sequences": stepCallSettings.stopSequences,
4827
+ "gen_ai.request.temperature": stepCallSettings.temperature,
4828
+ "gen_ai.request.top_k": stepCallSettings.topK,
4829
+ "gen_ai.request.top_p": stepCallSettings.topP
4878
4830
  }
4879
- });
4880
- }
4831
+ }),
4832
+ tracer,
4833
+ fn: async (span2) => {
4834
+ var _a23, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
4835
+ const result = await stepModel.doGenerate({
4836
+ ...stepCallSettings,
4837
+ tools: stepTools,
4838
+ toolChoice: stepToolChoice,
4839
+ responseFormat: await (output == null ? void 0 : output.responseFormat),
4840
+ prompt: promptMessages,
4841
+ providerOptions: stepProviderOptions,
4842
+ abortSignal: mergedAbortSignal,
4843
+ headers: headersWithUserAgent
4844
+ });
4845
+ const responseData = {
4846
+ id: (_b2 = (_a23 = result.response) == null ? void 0 : _a23.id) != null ? _b2 : generateId2(),
4847
+ timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
4848
+ modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
4849
+ headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
4850
+ body: (_h2 = result.response) == null ? void 0 : _h2.body
4851
+ };
4852
+ const usage = asLanguageModelUsage(result.usage);
4853
+ span2.setAttributes(
4854
+ await selectTelemetryAttributes({
4855
+ telemetry,
4856
+ attributes: {
4857
+ "ai.response.finishReason": result.finishReason.unified,
4858
+ "ai.response.text": {
4859
+ output: () => extractTextContent(result.content)
4860
+ },
4861
+ "ai.response.reasoning": {
4862
+ output: () => extractReasoningContent(result.content)
4863
+ },
4864
+ "ai.response.toolCalls": {
4865
+ output: () => {
4866
+ const toolCalls = asToolCalls(result.content);
4867
+ return toolCalls == null ? void 0 : JSON.stringify(toolCalls);
4868
+ }
4869
+ },
4870
+ "ai.response.id": responseData.id,
4871
+ "ai.response.model": responseData.modelId,
4872
+ "ai.response.timestamp": responseData.timestamp.toISOString(),
4873
+ "ai.response.providerMetadata": JSON.stringify(
4874
+ result.providerMetadata
4875
+ ),
4876
+ "ai.usage.inputTokens": result.usage.inputTokens.total,
4877
+ "ai.usage.inputTokenDetails.noCacheTokens": result.usage.inputTokens.noCache,
4878
+ "ai.usage.inputTokenDetails.cacheReadTokens": result.usage.inputTokens.cacheRead,
4879
+ "ai.usage.inputTokenDetails.cacheWriteTokens": result.usage.inputTokens.cacheWrite,
4880
+ "ai.usage.outputTokens": result.usage.outputTokens.total,
4881
+ "ai.usage.outputTokenDetails.textTokens": result.usage.outputTokens.text,
4882
+ "ai.usage.outputTokenDetails.reasoningTokens": result.usage.outputTokens.reasoning,
4883
+ "ai.usage.totalTokens": usage.totalTokens,
4884
+ "ai.usage.reasoningTokens": result.usage.outputTokens.reasoning,
4885
+ "ai.usage.cachedInputTokens": result.usage.inputTokens.cacheRead,
4886
+ // standardized gen-ai llm span attributes:
4887
+ "gen_ai.response.finish_reasons": [
4888
+ result.finishReason.unified
4889
+ ],
4890
+ "gen_ai.response.id": responseData.id,
4891
+ "gen_ai.response.model": responseData.modelId,
4892
+ "gen_ai.usage.input_tokens": result.usage.inputTokens.total,
4893
+ "gen_ai.usage.output_tokens": result.usage.outputTokens.total
4894
+ }
4895
+ })
4896
+ );
4897
+ return { ...result, response: responseData };
4898
+ }
4899
+ })
4881
4900
  );
4882
4901
  const stepToolCalls = await Promise.all(
4883
4902
  currentModelResponse.content.filter(
@@ -4941,7 +4960,7 @@ async function generateText({
4941
4960
  }
4942
4961
  }
4943
4962
  const invalidToolCalls = stepToolCalls.filter(
4944
- (toolCall) => toolCall.invalid && toolCall.dynamic
4963
+ (toolCall) => toolCall.invalid && toolCall.dynamic && !toolCall.providerExecuted
4945
4964
  );
4946
4965
  clientToolOutputs = [];
4947
4966
  for (const toolCall of invalidToolCalls) {
@@ -6818,16 +6837,18 @@ function runToolsTransformation({
6818
6837
  toolCallsByToolCallId.set(toolCall.toolCallId, toolCall);
6819
6838
  controller.enqueue(toolCall);
6820
6839
  if (toolCall.invalid) {
6821
- enqueueToolResult({
6822
- type: "tool-error",
6823
- toolCallId: toolCall.toolCallId,
6824
- toolName: toolCall.toolName,
6825
- input: toolCall.input,
6826
- error: (0, import_provider_utils19.getErrorMessage)(toolCall.error),
6827
- dynamic: true,
6828
- title: toolCall.title,
6829
- ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
6830
- });
6840
+ if (!toolCall.providerExecuted) {
6841
+ enqueueToolResult({
6842
+ type: "tool-error",
6843
+ toolCallId: toolCall.toolCallId,
6844
+ toolName: toolCall.toolName,
6845
+ input: toolCall.input,
6846
+ error: (0, import_provider_utils19.getErrorMessage)(toolCall.error),
6847
+ dynamic: true,
6848
+ title: toolCall.title,
6849
+ ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
6850
+ });
6851
+ }
6831
6852
  break;
6832
6853
  }
6833
6854
  const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
@@ -7142,6 +7163,10 @@ function createOutputTransformStream(output) {
7142
7163
  text2 += chunk.text;
7143
7164
  textChunk += chunk.text;
7144
7165
  textProviderMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textProviderMetadata;
7166
+ if (chunk.text.length === 0 && chunk.providerMetadata != null) {
7167
+ controller.enqueue({ part: chunk, partialOutput: void 0 });
7168
+ return;
7169
+ }
7145
7170
  const result = await output.parsePartialOutput({ text: text2 });
7146
7171
  if (result !== void 0) {
7147
7172
  const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
@@ -7793,6 +7818,10 @@ var DefaultStreamTextResult = class {
7793
7818
  providerOptions,
7794
7819
  prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
7795
7820
  );
7821
+ const stepCallSettings = prepareStepCallSettings({
7822
+ callSettings,
7823
+ stepSettings: prepareStepResult
7824
+ });
7796
7825
  await notify({
7797
7826
  event: {
7798
7827
  stepNumber: recordedSteps.length,
@@ -7850,13 +7879,13 @@ var DefaultStreamTextResult = class {
7850
7879
  // standardized gen-ai llm span attributes:
7851
7880
  "gen_ai.system": stepModel.provider,
7852
7881
  "gen_ai.request.model": stepModel.modelId,
7853
- "gen_ai.request.frequency_penalty": callSettings.frequencyPenalty,
7854
- "gen_ai.request.max_tokens": callSettings.maxOutputTokens,
7855
- "gen_ai.request.presence_penalty": callSettings.presencePenalty,
7856
- "gen_ai.request.stop_sequences": callSettings.stopSequences,
7857
- "gen_ai.request.temperature": callSettings.temperature,
7858
- "gen_ai.request.top_k": callSettings.topK,
7859
- "gen_ai.request.top_p": callSettings.topP
7882
+ "gen_ai.request.frequency_penalty": stepCallSettings.frequencyPenalty,
7883
+ "gen_ai.request.max_tokens": stepCallSettings.maxOutputTokens,
7884
+ "gen_ai.request.presence_penalty": stepCallSettings.presencePenalty,
7885
+ "gen_ai.request.stop_sequences": stepCallSettings.stopSequences,
7886
+ "gen_ai.request.temperature": stepCallSettings.temperature,
7887
+ "gen_ai.request.top_k": stepCallSettings.topK,
7888
+ "gen_ai.request.top_p": stepCallSettings.topP
7860
7889
  }
7861
7890
  }),
7862
7891
  tracer,
@@ -7866,7 +7895,7 @@ var DefaultStreamTextResult = class {
7866
7895
  // get before the call
7867
7896
  doStreamSpan: doStreamSpan2,
7868
7897
  result: await stepModel.doStream({
7869
- ...callSettings,
7898
+ ...stepCallSettings,
7870
7899
  tools: stepTools,
7871
7900
  toolChoice: stepToolChoice,
7872
7901
  responseFormat: await (output == null ? void 0 : output.responseFormat),
@@ -7957,15 +7986,15 @@ var DefaultStreamTextResult = class {
7957
7986
  break;
7958
7987
  }
7959
7988
  case "text-delta": {
7960
- if (chunk.delta.length > 0) {
7989
+ if (chunk.delta.length > 0 || chunk.providerMetadata != null) {
7961
7990
  controller.enqueue({
7962
7991
  type: "text-delta",
7963
7992
  id: chunk.id,
7964
7993
  text: chunk.delta,
7965
7994
  providerMetadata: chunk.providerMetadata
7966
7995
  });
7967
- activeText += chunk.delta;
7968
7996
  }
7997
+ activeText += chunk.delta;
7969
7998
  break;
7970
7999
  }
7971
8000
  case "reasoning-start":