ai 6.0.237 → 6.0.239

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.
@@ -103,6 +103,7 @@ import type {
103
103
  InferPartialOutput,
104
104
  } from './output-utils';
105
105
  import type { PrepareStepFunction } from './prepare-step';
106
+ import { prepareStepCallSettings } from './prepare-step-call-settings';
106
107
  import type { ResponseMessage } from './response-message';
107
108
  import {
108
109
  runToolsTransformation,
@@ -714,6 +715,11 @@ function createOutputTransformStream<
714
715
  textChunk += chunk.text;
715
716
  textProviderMetadata = chunk.providerMetadata ?? textProviderMetadata;
716
717
 
718
+ if (chunk.text.length === 0 && chunk.providerMetadata != null) {
719
+ controller.enqueue({ part: chunk, partialOutput: undefined });
720
+ return;
721
+ }
722
+
717
723
  // only publish if partial json can be parsed:
718
724
  const result = await output.parsePartialOutput({ text });
719
725
 
@@ -1670,6 +1676,11 @@ class DefaultStreamTextResult<
1670
1676
  prepareStepResult?.providerOptions,
1671
1677
  );
1672
1678
 
1679
+ const stepCallSettings = prepareStepCallSettings({
1680
+ callSettings,
1681
+ stepSettings: prepareStepResult,
1682
+ });
1683
+
1673
1684
  await notify({
1674
1685
  event: {
1675
1686
  stepNumber: recordedSteps.length,
@@ -1735,14 +1746,16 @@ class DefaultStreamTextResult<
1735
1746
  'gen_ai.system': stepModel.provider,
1736
1747
  'gen_ai.request.model': stepModel.modelId,
1737
1748
  'gen_ai.request.frequency_penalty':
1738
- callSettings.frequencyPenalty,
1739
- 'gen_ai.request.max_tokens': callSettings.maxOutputTokens,
1749
+ stepCallSettings.frequencyPenalty,
1750
+ 'gen_ai.request.max_tokens':
1751
+ stepCallSettings.maxOutputTokens,
1740
1752
  'gen_ai.request.presence_penalty':
1741
- callSettings.presencePenalty,
1742
- 'gen_ai.request.stop_sequences': callSettings.stopSequences,
1743
- 'gen_ai.request.temperature': callSettings.temperature,
1744
- 'gen_ai.request.top_k': callSettings.topK,
1745
- 'gen_ai.request.top_p': callSettings.topP,
1753
+ stepCallSettings.presencePenalty,
1754
+ 'gen_ai.request.stop_sequences':
1755
+ stepCallSettings.stopSequences,
1756
+ 'gen_ai.request.temperature': stepCallSettings.temperature,
1757
+ 'gen_ai.request.top_k': stepCallSettings.topK,
1758
+ 'gen_ai.request.top_p': stepCallSettings.topP,
1746
1759
  },
1747
1760
  }),
1748
1761
  tracer,
@@ -1751,7 +1764,7 @@ class DefaultStreamTextResult<
1751
1764
  startTimestampMs: now(), // get before the call
1752
1765
  doStreamSpan,
1753
1766
  result: await stepModel.doStream({
1754
- ...callSettings,
1767
+ ...stepCallSettings,
1755
1768
  tools: stepTools,
1756
1769
  toolChoice: stepToolChoice,
1757
1770
  responseFormat: await output?.responseFormat,
@@ -1878,15 +1891,18 @@ class DefaultStreamTextResult<
1878
1891
  }
1879
1892
 
1880
1893
  case 'text-delta': {
1881
- if (chunk.delta.length > 0) {
1894
+ if (
1895
+ chunk.delta.length > 0 ||
1896
+ chunk.providerMetadata != null
1897
+ ) {
1882
1898
  controller.enqueue({
1883
1899
  type: 'text-delta',
1884
1900
  id: chunk.id,
1885
1901
  text: chunk.delta,
1886
1902
  providerMetadata: chunk.providerMetadata,
1887
1903
  });
1888
- activeText += chunk.delta;
1889
1904
  }
1905
+ activeText += chunk.delta;
1890
1906
  break;
1891
1907
  }
1892
1908