ai 6.0.263 → 6.0.264

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.
@@ -164,7 +164,7 @@ function detectMediaType({
164
164
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
165
165
 
166
166
  // src/version.ts
167
- var VERSION = true ? "6.0.263" : "0.0.0-test";
167
+ var VERSION = true ? "6.0.264" : "0.0.0-test";
168
168
 
169
169
  // src/util/download/download.ts
170
170
  var download = async ({
@@ -144,7 +144,7 @@ import {
144
144
  } from "@ai-sdk/provider-utils";
145
145
 
146
146
  // src/version.ts
147
- var VERSION = true ? "6.0.263" : "0.0.0-test";
147
+ var VERSION = true ? "6.0.264" : "0.0.0-test";
148
148
 
149
149
  // src/util/download/download.ts
150
150
  var download = async ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "6.0.263",
3
+ "version": "6.0.264",
4
4
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -891,6 +891,35 @@ class DefaultStreamTextResult<
891
891
  let recordedNoOutputError: NoOutputGeneratedError | undefined;
892
892
  let currentStepToolSet = tools;
893
893
 
894
+ // provider-assigned text/reasoning part IDs are only unique within a
895
+ // single model call (e.g. Anthropic uses the content block index, which
896
+ // restarts at 0 for every call), so colliding IDs are remapped to keep
897
+ // them unique across the whole multi-step stream:
898
+ const createPartIdReserver = () => {
899
+ const usedIds = new Set<string>();
900
+
901
+ return (id: string) => {
902
+ if (!usedIds.has(id)) {
903
+ usedIds.add(id);
904
+ return id;
905
+ }
906
+
907
+ const generatedId = generateId();
908
+ let uniqueId = generatedId;
909
+ let suffix = 0;
910
+
911
+ while (usedIds.has(uniqueId)) {
912
+ uniqueId = `${generatedId}-${++suffix}`;
913
+ }
914
+
915
+ usedIds.add(uniqueId);
916
+ return uniqueId;
917
+ };
918
+ };
919
+
920
+ const reserveTextPartId = createPartIdReserver();
921
+ const reserveReasoningPartId = createPartIdReserver();
922
+
894
923
  // Track provider-executed tool calls that support deferred results
895
924
  // (e.g., code_execution in programmatic tool calling scenarios).
896
925
  // These tools may not return their results in the same turn as their call.
@@ -1847,6 +1876,11 @@ class DefaultStreamTextResult<
1847
1876
  // raw text as it comes from the provider. recorded for telemetry.
1848
1877
  let activeText = '';
1849
1878
 
1879
+ // Maps provider-assigned IDs to stream-unique IDs for the text and
1880
+ // reasoning parts that are active in this step.
1881
+ const textPartIds = new Map<string, string>();
1882
+ const reasoningPartIds = new Map<string, string>();
1883
+
1850
1884
  self.addStream(
1851
1885
  streamWithToolResults.pipeThrough(
1852
1886
  new TransformStream<
@@ -1890,13 +1924,27 @@ class DefaultStreamTextResult<
1890
1924
  }
1891
1925
 
1892
1926
  switch (chunkType) {
1893
- case 'tool-approval-request':
1894
- case 'text-start':
1895
- case 'text-end': {
1927
+ case 'tool-approval-request': {
1896
1928
  controller.enqueue(chunk);
1897
1929
  break;
1898
1930
  }
1899
1931
 
1932
+ case 'text-start': {
1933
+ const id = reserveTextPartId(chunk.id);
1934
+ textPartIds.set(chunk.id, id);
1935
+ controller.enqueue({ ...chunk, id });
1936
+ break;
1937
+ }
1938
+
1939
+ case 'text-end': {
1940
+ controller.enqueue({
1941
+ ...chunk,
1942
+ id: textPartIds.get(chunk.id) ?? chunk.id,
1943
+ });
1944
+ textPartIds.delete(chunk.id);
1945
+ break;
1946
+ }
1947
+
1900
1948
  case 'text-delta': {
1901
1949
  if (
1902
1950
  chunk.delta.length > 0 ||
@@ -1904,7 +1952,7 @@ class DefaultStreamTextResult<
1904
1952
  ) {
1905
1953
  controller.enqueue({
1906
1954
  type: 'text-delta',
1907
- id: chunk.id,
1955
+ id: textPartIds.get(chunk.id) ?? chunk.id,
1908
1956
  text: chunk.delta,
1909
1957
  providerMetadata: chunk.providerMetadata,
1910
1958
  });
@@ -1913,16 +1961,26 @@ class DefaultStreamTextResult<
1913
1961
  break;
1914
1962
  }
1915
1963
 
1916
- case 'reasoning-start':
1964
+ case 'reasoning-start': {
1965
+ const id = reserveReasoningPartId(chunk.id);
1966
+ reasoningPartIds.set(chunk.id, id);
1967
+ controller.enqueue({ ...chunk, id });
1968
+ break;
1969
+ }
1970
+
1917
1971
  case 'reasoning-end': {
1918
- controller.enqueue(chunk);
1972
+ controller.enqueue({
1973
+ ...chunk,
1974
+ id: reasoningPartIds.get(chunk.id) ?? chunk.id,
1975
+ });
1976
+ reasoningPartIds.delete(chunk.id);
1919
1977
  break;
1920
1978
  }
1921
1979
 
1922
1980
  case 'reasoning-delta': {
1923
1981
  controller.enqueue({
1924
1982
  type: 'reasoning-delta',
1925
- id: chunk.id,
1983
+ id: reasoningPartIds.get(chunk.id) ?? chunk.id,
1926
1984
  text: chunk.delta,
1927
1985
  providerMetadata: chunk.providerMetadata,
1928
1986
  });