ai 3.2.27 → 3.2.29

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/dist/index.d.mts CHANGED
@@ -706,15 +706,12 @@ The result of a `streamObject` call that contains the partial object stream and
706
706
  */
707
707
  declare class StreamObjectResult<T> {
708
708
  private readonly originalStream;
709
+ private readonly objectPromise;
709
710
  /**
710
711
  Warnings from the model provider (e.g. unsupported settings)
711
712
  */
712
713
  readonly warnings: CallWarning[] | undefined;
713
714
  /**
714
- The generated object (typed according to the schema). Resolved when the response is finished.
715
- */
716
- readonly object: Promise<T>;
717
- /**
718
715
  The token usage of the generated response. Resolved when the response is finished.
719
716
  */
720
717
  readonly usage: Promise<CompletionTokenUsage$1>;
@@ -737,6 +734,10 @@ declare class StreamObjectResult<T> {
737
734
  onFinish: Parameters<typeof streamObject<T>>[0]['onFinish'];
738
735
  });
739
736
  /**
737
+ The generated object (typed according to the schema). Resolved when the response is finished.
738
+ */
739
+ get object(): Promise<T>;
740
+ /**
740
741
  Stream of partial objects. It gets more complete as the stream progresses.
741
742
 
742
743
  Note that the partial object is not validated.
@@ -909,7 +910,7 @@ Converts an array of messages from useChat into an array of CoreMessages that ca
909
910
  with the AI core functions (e.g. `streamText`).
910
911
  */
911
912
  declare function convertToCoreMessages(messages: Array<{
912
- role: 'user' | 'assistant';
913
+ role: 'user' | 'assistant' | 'system';
913
914
  content: string;
914
915
  toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
915
916
  experimental_attachments?: Attachment[];
@@ -1183,7 +1184,7 @@ If set and supported by the model, calls will generate deterministic results.
1183
1184
  @return
1184
1185
  A result object for accessing different stream types and additional information.
1185
1186
  */
1186
- declare function streamText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, experimental_telemetry: telemetry, onFinish, ...settings }: CallSettings & Prompt & {
1187
+ declare function streamText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, experimental_telemetry: telemetry, experimental_toolCallStreaming: toolCallStreaming, onFinish, ...settings }: CallSettings & Prompt & {
1187
1188
  /**
1188
1189
  The language model to use.
1189
1190
  */
@@ -1197,10 +1198,14 @@ The tool choice strategy. Default: 'auto'.
1197
1198
  */
1198
1199
  toolChoice?: CoreToolChoice<TOOLS>;
1199
1200
  /**
1200
- * Optional telemetry configuration (experimental).
1201
+ Optional telemetry configuration (experimental).
1201
1202
  */
1202
1203
  experimental_telemetry?: TelemetrySettings;
1203
1204
  /**
1205
+ Enable streaming of tool call deltas as they are generated. Disabled by default.
1206
+ */
1207
+ experimental_toolCallStreaming?: boolean;
1208
+ /**
1204
1209
  Callback that is called when the LLM response and all request tool executions
1205
1210
  (for tools that have an `execute` function) are finished.
1206
1211
  */
@@ -1246,8 +1251,14 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
1246
1251
  } | ({
1247
1252
  type: 'tool-call';
1248
1253
  } & ToToolCall<TOOLS>) | {
1249
- type: 'error';
1250
- error: unknown;
1254
+ type: 'tool-call-streaming-start';
1255
+ toolCallId: string;
1256
+ toolName: string;
1257
+ } | {
1258
+ type: 'tool-call-delta';
1259
+ toolCallId: string;
1260
+ toolName: string;
1261
+ argsTextDelta: string;
1251
1262
  } | ({
1252
1263
  type: 'tool-result';
1253
1264
  } & ToToolResult<TOOLS>) | {
@@ -1259,6 +1270,9 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
1259
1270
  completionTokens: number;
1260
1271
  totalTokens: number;
1261
1272
  };
1273
+ } | {
1274
+ type: 'error';
1275
+ error: unknown;
1262
1276
  };
1263
1277
  /**
1264
1278
  A result object for accessing different stream types and additional information.
@@ -1369,11 +1383,15 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1369
1383
  Converts the result to a streamed response object with a stream data part stream.
1370
1384
  It can be used with the `useChat` and `useCompletion` hooks.
1371
1385
 
1372
- @param init Optional headers.
1386
+ @param options An object with an init property (ResponseInit) and a data property.
1387
+ You can also pass in a ResponseInit directly (deprecated).
1373
1388
 
1374
1389
  @return A response object.
1375
1390
  */
1376
- toAIStreamResponse(init?: ResponseInit): Response;
1391
+ toAIStreamResponse(options?: ResponseInit | {
1392
+ init?: ResponseInit;
1393
+ data?: StreamData;
1394
+ }): Response;
1377
1395
  /**
1378
1396
  Creates a simple text stream response.
1379
1397
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
package/dist/index.d.ts CHANGED
@@ -706,15 +706,12 @@ The result of a `streamObject` call that contains the partial object stream and
706
706
  */
707
707
  declare class StreamObjectResult<T> {
708
708
  private readonly originalStream;
709
+ private readonly objectPromise;
709
710
  /**
710
711
  Warnings from the model provider (e.g. unsupported settings)
711
712
  */
712
713
  readonly warnings: CallWarning[] | undefined;
713
714
  /**
714
- The generated object (typed according to the schema). Resolved when the response is finished.
715
- */
716
- readonly object: Promise<T>;
717
- /**
718
715
  The token usage of the generated response. Resolved when the response is finished.
719
716
  */
720
717
  readonly usage: Promise<CompletionTokenUsage$1>;
@@ -737,6 +734,10 @@ declare class StreamObjectResult<T> {
737
734
  onFinish: Parameters<typeof streamObject<T>>[0]['onFinish'];
738
735
  });
739
736
  /**
737
+ The generated object (typed according to the schema). Resolved when the response is finished.
738
+ */
739
+ get object(): Promise<T>;
740
+ /**
740
741
  Stream of partial objects. It gets more complete as the stream progresses.
741
742
 
742
743
  Note that the partial object is not validated.
@@ -909,7 +910,7 @@ Converts an array of messages from useChat into an array of CoreMessages that ca
909
910
  with the AI core functions (e.g. `streamText`).
910
911
  */
911
912
  declare function convertToCoreMessages(messages: Array<{
912
- role: 'user' | 'assistant';
913
+ role: 'user' | 'assistant' | 'system';
913
914
  content: string;
914
915
  toolInvocations?: Array<ToolResult<string, unknown, unknown>>;
915
916
  experimental_attachments?: Attachment[];
@@ -1183,7 +1184,7 @@ If set and supported by the model, calls will generate deterministic results.
1183
1184
  @return
1184
1185
  A result object for accessing different stream types and additional information.
1185
1186
  */
1186
- declare function streamText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, experimental_telemetry: telemetry, onFinish, ...settings }: CallSettings & Prompt & {
1187
+ declare function streamText<TOOLS extends Record<string, CoreTool>>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, experimental_telemetry: telemetry, experimental_toolCallStreaming: toolCallStreaming, onFinish, ...settings }: CallSettings & Prompt & {
1187
1188
  /**
1188
1189
  The language model to use.
1189
1190
  */
@@ -1197,10 +1198,14 @@ The tool choice strategy. Default: 'auto'.
1197
1198
  */
1198
1199
  toolChoice?: CoreToolChoice<TOOLS>;
1199
1200
  /**
1200
- * Optional telemetry configuration (experimental).
1201
+ Optional telemetry configuration (experimental).
1201
1202
  */
1202
1203
  experimental_telemetry?: TelemetrySettings;
1203
1204
  /**
1205
+ Enable streaming of tool call deltas as they are generated. Disabled by default.
1206
+ */
1207
+ experimental_toolCallStreaming?: boolean;
1208
+ /**
1204
1209
  Callback that is called when the LLM response and all request tool executions
1205
1210
  (for tools that have an `execute` function) are finished.
1206
1211
  */
@@ -1246,8 +1251,14 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
1246
1251
  } | ({
1247
1252
  type: 'tool-call';
1248
1253
  } & ToToolCall<TOOLS>) | {
1249
- type: 'error';
1250
- error: unknown;
1254
+ type: 'tool-call-streaming-start';
1255
+ toolCallId: string;
1256
+ toolName: string;
1257
+ } | {
1258
+ type: 'tool-call-delta';
1259
+ toolCallId: string;
1260
+ toolName: string;
1261
+ argsTextDelta: string;
1251
1262
  } | ({
1252
1263
  type: 'tool-result';
1253
1264
  } & ToToolResult<TOOLS>) | {
@@ -1259,6 +1270,9 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
1259
1270
  completionTokens: number;
1260
1271
  totalTokens: number;
1261
1272
  };
1273
+ } | {
1274
+ type: 'error';
1275
+ error: unknown;
1262
1276
  };
1263
1277
  /**
1264
1278
  A result object for accessing different stream types and additional information.
@@ -1369,11 +1383,15 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
1369
1383
  Converts the result to a streamed response object with a stream data part stream.
1370
1384
  It can be used with the `useChat` and `useCompletion` hooks.
1371
1385
 
1372
- @param init Optional headers.
1386
+ @param options An object with an init property (ResponseInit) and a data property.
1387
+ You can also pass in a ResponseInit directly (deprecated).
1373
1388
 
1374
1389
  @return A response object.
1375
1390
  */
1376
- toAIStreamResponse(init?: ResponseInit): Response;
1391
+ toAIStreamResponse(options?: ResponseInit | {
1392
+ init?: ResponseInit;
1393
+ data?: StreamData;
1394
+ }): Response;
1377
1395
  /**
1378
1396
  Creates a simple text stream response.
1379
1397
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
package/dist/index.js CHANGED
@@ -67,7 +67,7 @@ __export(streams_exports, {
67
67
  OpenAIStream: () => OpenAIStream,
68
68
  ReplicateStream: () => ReplicateStream,
69
69
  RetryError: () => import_provider8.RetryError,
70
- StreamData: () => StreamData,
70
+ StreamData: () => StreamData2,
71
71
  StreamObjectResult: () => StreamObjectResult,
72
72
  StreamTextResult: () => StreamTextResult,
73
73
  StreamingTextResponse: () => StreamingTextResponse,
@@ -841,6 +841,44 @@ function createAsyncIterableStream(source, transformer) {
841
841
  return transformedStream;
842
842
  }
843
843
 
844
+ // core/util/delayed-promise.ts
845
+ var DelayedPromise = class {
846
+ constructor() {
847
+ this.status = { type: "pending" };
848
+ this._resolve = void 0;
849
+ this._reject = void 0;
850
+ }
851
+ get value() {
852
+ if (this.promise) {
853
+ return this.promise;
854
+ }
855
+ this.promise = new Promise((resolve, reject) => {
856
+ if (this.status.type === "resolved") {
857
+ resolve(this.status.value);
858
+ } else if (this.status.type === "rejected") {
859
+ reject(this.status.error);
860
+ }
861
+ this._resolve = resolve;
862
+ this._reject = reject;
863
+ });
864
+ return this.promise;
865
+ }
866
+ resolve(value) {
867
+ var _a;
868
+ this.status = { type: "resolved", value };
869
+ if (this.promise) {
870
+ (_a = this._resolve) == null ? void 0 : _a.call(this, value);
871
+ }
872
+ }
873
+ reject(error) {
874
+ var _a;
875
+ this.status = { type: "rejected", error };
876
+ if (this.promise) {
877
+ (_a = this._reject) == null ? void 0 : _a.call(this, error);
878
+ }
879
+ }
880
+ };
881
+
844
882
  // core/generate-object/stream-object.ts
845
883
  async function streamObject({
846
884
  model,
@@ -985,12 +1023,7 @@ var StreamObjectResult = class {
985
1023
  }) {
986
1024
  this.warnings = warnings;
987
1025
  this.rawResponse = rawResponse;
988
- let resolveObject;
989
- let rejectObject;
990
- this.object = new Promise((resolve, reject) => {
991
- resolveObject = resolve;
992
- rejectObject = reject;
993
- });
1026
+ this.objectPromise = new DelayedPromise();
994
1027
  let resolveUsage;
995
1028
  this.usage = new Promise((resolve) => {
996
1029
  resolveUsage = resolve;
@@ -1001,6 +1034,7 @@ var StreamObjectResult = class {
1001
1034
  let accumulatedText = "";
1002
1035
  let delta = "";
1003
1036
  let latestObject = void 0;
1037
+ const self = this;
1004
1038
  this.originalStream = stream.pipeThrough(
1005
1039
  new TransformStream({
1006
1040
  async transform(chunk, controller) {
@@ -1041,10 +1075,10 @@ var StreamObjectResult = class {
1041
1075
  });
1042
1076
  if (validationResult.success) {
1043
1077
  object = validationResult.value;
1044
- resolveObject(object);
1078
+ self.objectPromise.resolve(object);
1045
1079
  } else {
1046
1080
  error = validationResult.error;
1047
- rejectObject(error);
1081
+ self.objectPromise.reject(error);
1048
1082
  }
1049
1083
  break;
1050
1084
  }
@@ -1076,6 +1110,12 @@ var StreamObjectResult = class {
1076
1110
  );
1077
1111
  }
1078
1112
  /**
1113
+ The generated object (typed according to the schema). Resolved when the response is finished.
1114
+ */
1115
+ get object() {
1116
+ return this.objectPromise.value;
1117
+ }
1118
+ /**
1079
1119
  Stream of partial objects. It gets more complete as the stream progresses.
1080
1120
 
1081
1121
  Note that the partial object is not validated.
@@ -1637,12 +1677,101 @@ function toResponseMessages({
1637
1677
  }
1638
1678
  var experimental_generateText = generateText;
1639
1679
 
1680
+ // core/util/merge-streams.ts
1681
+ function mergeStreams(stream1, stream2) {
1682
+ const reader1 = stream1.getReader();
1683
+ const reader2 = stream2.getReader();
1684
+ let lastRead1 = void 0;
1685
+ let lastRead2 = void 0;
1686
+ let stream1Done = false;
1687
+ let stream2Done = false;
1688
+ async function readStream1(controller) {
1689
+ try {
1690
+ if (lastRead1 == null) {
1691
+ lastRead1 = reader1.read();
1692
+ }
1693
+ const result = await lastRead1;
1694
+ lastRead1 = void 0;
1695
+ if (!result.done) {
1696
+ controller.enqueue(result.value);
1697
+ } else {
1698
+ controller.close();
1699
+ }
1700
+ } catch (error) {
1701
+ controller.error(error);
1702
+ }
1703
+ }
1704
+ async function readStream2(controller) {
1705
+ try {
1706
+ if (lastRead2 == null) {
1707
+ lastRead2 = reader2.read();
1708
+ }
1709
+ const result = await lastRead2;
1710
+ lastRead2 = void 0;
1711
+ if (!result.done) {
1712
+ controller.enqueue(result.value);
1713
+ } else {
1714
+ controller.close();
1715
+ }
1716
+ } catch (error) {
1717
+ controller.error(error);
1718
+ }
1719
+ }
1720
+ return new ReadableStream({
1721
+ async pull(controller) {
1722
+ try {
1723
+ if (stream1Done) {
1724
+ await readStream2(controller);
1725
+ return;
1726
+ }
1727
+ if (stream2Done) {
1728
+ await readStream1(controller);
1729
+ return;
1730
+ }
1731
+ if (lastRead1 == null) {
1732
+ lastRead1 = reader1.read();
1733
+ }
1734
+ if (lastRead2 == null) {
1735
+ lastRead2 = reader2.read();
1736
+ }
1737
+ const { result, reader } = await Promise.race([
1738
+ lastRead1.then((result2) => ({ result: result2, reader: reader1 })),
1739
+ lastRead2.then((result2) => ({ result: result2, reader: reader2 }))
1740
+ ]);
1741
+ if (!result.done) {
1742
+ controller.enqueue(result.value);
1743
+ }
1744
+ if (reader === reader1) {
1745
+ lastRead1 = void 0;
1746
+ if (result.done) {
1747
+ await readStream2(controller);
1748
+ stream1Done = true;
1749
+ }
1750
+ } else {
1751
+ lastRead2 = void 0;
1752
+ if (result.done) {
1753
+ stream2Done = true;
1754
+ await readStream1(controller);
1755
+ }
1756
+ }
1757
+ } catch (error) {
1758
+ controller.error(error);
1759
+ }
1760
+ },
1761
+ cancel() {
1762
+ reader1.cancel();
1763
+ reader2.cancel();
1764
+ }
1765
+ });
1766
+ }
1767
+
1640
1768
  // core/generate-text/run-tools-transformation.ts
1641
1769
  var import_provider7 = require("@ai-sdk/provider");
1642
1770
  var import_ui_utils2 = require("@ai-sdk/ui-utils");
1643
1771
  function runToolsTransformation({
1644
1772
  tools,
1645
1773
  generatorStream,
1774
+ toolCallStreaming,
1646
1775
  tracer
1647
1776
  }) {
1648
1777
  let canClose = false;
@@ -1653,6 +1782,7 @@ function runToolsTransformation({
1653
1782
  toolResultsStreamController = controller;
1654
1783
  }
1655
1784
  });
1785
+ const activeToolCalls = {};
1656
1786
  const forwardStream = new TransformStream({
1657
1787
  transform(chunk, controller) {
1658
1788
  const chunkType = chunk.type;
@@ -1662,6 +1792,25 @@ function runToolsTransformation({
1662
1792
  controller.enqueue(chunk);
1663
1793
  break;
1664
1794
  }
1795
+ case "tool-call-delta": {
1796
+ if (toolCallStreaming) {
1797
+ if (!activeToolCalls[chunk.toolCallId]) {
1798
+ controller.enqueue({
1799
+ type: "tool-call-streaming-start",
1800
+ toolCallId: chunk.toolCallId,
1801
+ toolName: chunk.toolName
1802
+ });
1803
+ activeToolCalls[chunk.toolCallId] = true;
1804
+ }
1805
+ controller.enqueue({
1806
+ type: "tool-call-delta",
1807
+ toolCallId: chunk.toolCallId,
1808
+ toolName: chunk.toolName,
1809
+ argsTextDelta: chunk.argsTextDelta
1810
+ });
1811
+ }
1812
+ break;
1813
+ }
1665
1814
  case "tool-call": {
1666
1815
  const toolName = chunk.toolName;
1667
1816
  if (tools == null) {
@@ -1747,9 +1896,6 @@ function runToolsTransformation({
1747
1896
  });
1748
1897
  break;
1749
1898
  }
1750
- case "tool-call-delta": {
1751
- break;
1752
- }
1753
1899
  default: {
1754
1900
  const _exhaustiveCheck = chunkType;
1755
1901
  throw new Error(`Unhandled chunk type: ${_exhaustiveCheck}`);
@@ -1802,6 +1948,7 @@ async function streamText({
1802
1948
  abortSignal,
1803
1949
  headers,
1804
1950
  experimental_telemetry: telemetry,
1951
+ experimental_toolCallStreaming: toolCallStreaming = false,
1805
1952
  onFinish,
1806
1953
  ...settings
1807
1954
  }) {
@@ -1862,6 +2009,7 @@ async function streamText({
1862
2009
  stream: runToolsTransformation({
1863
2010
  tools,
1864
2011
  generatorStream: stream,
2012
+ toolCallStreaming,
1865
2013
  tracer
1866
2014
  }),
1867
2015
  warnings,
@@ -1939,6 +2087,8 @@ var StreamTextResult = class {
1939
2087
  resolveText(text);
1940
2088
  resolveToolCalls(toolCalls);
1941
2089
  break;
2090
+ case "tool-call-streaming-start":
2091
+ case "tool-call-delta":
1942
2092
  case "error":
1943
2093
  break;
1944
2094
  default: {
@@ -2080,12 +2230,29 @@ var StreamTextResult = class {
2080
2230
  await callbacks.onFinal(aggregatedResponse);
2081
2231
  }
2082
2232
  });
2083
- const streamDataTransformer = new TransformStream({
2233
+ const streamPartsTransformer = new TransformStream({
2084
2234
  transform: async (chunk, controller) => {
2085
- switch (chunk.type) {
2235
+ const chunkType = chunk.type;
2236
+ switch (chunkType) {
2086
2237
  case "text-delta":
2087
2238
  controller.enqueue((0, import_ui_utils6.formatStreamPart)("text", chunk.textDelta));
2088
2239
  break;
2240
+ case "tool-call-streaming-start":
2241
+ controller.enqueue(
2242
+ (0, import_ui_utils6.formatStreamPart)("tool_call_streaming_start", {
2243
+ toolCallId: chunk.toolCallId,
2244
+ toolName: chunk.toolName
2245
+ })
2246
+ );
2247
+ break;
2248
+ case "tool-call-delta":
2249
+ controller.enqueue(
2250
+ (0, import_ui_utils6.formatStreamPart)("tool_call_delta", {
2251
+ toolCallId: chunk.toolCallId,
2252
+ argsTextDelta: chunk.argsTextDelta
2253
+ })
2254
+ );
2255
+ break;
2089
2256
  case "tool-call":
2090
2257
  controller.enqueue(
2091
2258
  (0, import_ui_utils6.formatStreamPart)("tool_call", {
@@ -2110,10 +2277,16 @@ var StreamTextResult = class {
2110
2277
  (0, import_ui_utils6.formatStreamPart)("error", JSON.stringify(chunk.error))
2111
2278
  );
2112
2279
  break;
2280
+ case "finish":
2281
+ break;
2282
+ default: {
2283
+ const exhaustiveCheck = chunkType;
2284
+ throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
2285
+ }
2113
2286
  }
2114
2287
  }
2115
2288
  });
2116
- return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamDataTransformer).pipeThrough(new TextEncoderStream());
2289
+ return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamPartsTransformer).pipeThrough(new TextEncoderStream());
2117
2290
  }
2118
2291
  /**
2119
2292
  Writes stream data output to a Node.js response-like object.
@@ -2181,12 +2354,27 @@ var StreamTextResult = class {
2181
2354
  Converts the result to a streamed response object with a stream data part stream.
2182
2355
  It can be used with the `useChat` and `useCompletion` hooks.
2183
2356
 
2184
- @param init Optional headers.
2357
+ @param options An object with an init property (ResponseInit) and a data property.
2358
+ You can also pass in a ResponseInit directly (deprecated).
2185
2359
 
2186
2360
  @return A response object.
2187
2361
  */
2188
- toAIStreamResponse(init) {
2189
- return new StreamingTextResponse(this.toAIStream(), init);
2362
+ toAIStreamResponse(options) {
2363
+ var _a;
2364
+ const init = options == null ? void 0 : "init" in options ? options.init : {
2365
+ headers: "headers" in options ? options.headers : void 0,
2366
+ status: "status" in options ? options.status : void 0,
2367
+ statusText: "statusText" in options ? options.statusText : void 0
2368
+ };
2369
+ const data = options == null ? void 0 : "data" in options ? options.data : void 0;
2370
+ const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
2371
+ return new Response(stream, {
2372
+ status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
2373
+ statusText: init == null ? void 0 : init.statusText,
2374
+ headers: prepareResponseHeaders(init, {
2375
+ contentType: "text/plain; charset=utf-8"
2376
+ })
2377
+ });
2190
2378
  }
2191
2379
  /**
2192
2380
  Creates a simple text stream response.
@@ -2272,6 +2460,13 @@ function convertToCoreMessages(messages) {
2272
2460
  experimental_attachments
2273
2461
  } of messages) {
2274
2462
  switch (role) {
2463
+ case "system": {
2464
+ coreMessages.push({
2465
+ role: "system",
2466
+ content
2467
+ });
2468
+ break;
2469
+ }
2275
2470
  case "user": {
2276
2471
  coreMessages.push({
2277
2472
  role: "user",
@@ -2604,7 +2799,7 @@ function readableFromAsyncIterable(iterable) {
2604
2799
 
2605
2800
  // streams/stream-data.ts
2606
2801
  var import_ui_utils3 = require("@ai-sdk/ui-utils");
2607
- var StreamData = class {
2802
+ var StreamData2 = class {
2608
2803
  constructor() {
2609
2804
  this.encoder = new TextEncoder();
2610
2805
  this.controller = null;
@@ -2675,7 +2870,7 @@ function createStreamDataTransformer() {
2675
2870
  }
2676
2871
  });
2677
2872
  }
2678
- var experimental_StreamData = class extends StreamData {
2873
+ var experimental_StreamData = class extends StreamData2 {
2679
2874
  };
2680
2875
 
2681
2876
  // streams/anthropic-stream.ts
@@ -3440,94 +3635,6 @@ async function ReplicateStream(res, cb, options) {
3440
3635
  );
3441
3636
  }
3442
3637
 
3443
- // core/util/merge-streams.ts
3444
- function mergeStreams(stream1, stream2) {
3445
- const reader1 = stream1.getReader();
3446
- const reader2 = stream2.getReader();
3447
- let lastRead1 = void 0;
3448
- let lastRead2 = void 0;
3449
- let stream1Done = false;
3450
- let stream2Done = false;
3451
- async function readStream1(controller) {
3452
- try {
3453
- if (lastRead1 == null) {
3454
- lastRead1 = reader1.read();
3455
- }
3456
- const result = await lastRead1;
3457
- lastRead1 = void 0;
3458
- if (!result.done) {
3459
- controller.enqueue(result.value);
3460
- } else {
3461
- controller.close();
3462
- }
3463
- } catch (error) {
3464
- controller.error(error);
3465
- }
3466
- }
3467
- async function readStream2(controller) {
3468
- try {
3469
- if (lastRead2 == null) {
3470
- lastRead2 = reader2.read();
3471
- }
3472
- const result = await lastRead2;
3473
- lastRead2 = void 0;
3474
- if (!result.done) {
3475
- controller.enqueue(result.value);
3476
- } else {
3477
- controller.close();
3478
- }
3479
- } catch (error) {
3480
- controller.error(error);
3481
- }
3482
- }
3483
- return new ReadableStream({
3484
- async pull(controller) {
3485
- try {
3486
- if (stream1Done) {
3487
- readStream2(controller);
3488
- return;
3489
- }
3490
- if (stream2Done) {
3491
- readStream1(controller);
3492
- return;
3493
- }
3494
- if (lastRead1 == null) {
3495
- lastRead1 = reader1.read();
3496
- }
3497
- if (lastRead2 == null) {
3498
- lastRead2 = reader2.read();
3499
- }
3500
- const { result, reader } = await Promise.race([
3501
- lastRead1.then((result2) => ({ result: result2, reader: reader1 })),
3502
- lastRead2.then((result2) => ({ result: result2, reader: reader2 }))
3503
- ]);
3504
- if (!result.done) {
3505
- controller.enqueue(result.value);
3506
- }
3507
- if (reader === reader1) {
3508
- lastRead1 = void 0;
3509
- if (result.done) {
3510
- readStream2(controller);
3511
- stream1Done = true;
3512
- }
3513
- } else {
3514
- lastRead2 = void 0;
3515
- if (result.done) {
3516
- stream2Done = true;
3517
- readStream1(controller);
3518
- }
3519
- }
3520
- } catch (error) {
3521
- controller.error(error);
3522
- }
3523
- },
3524
- cancel() {
3525
- reader1.cancel();
3526
- reader2.cancel();
3527
- }
3528
- });
3529
- }
3530
-
3531
3638
  // streams/stream-to-response.ts
3532
3639
  function streamToResponse(res, response, init, data) {
3533
3640
  var _a;