ai 5.0.0-alpha.10 → 5.0.0-alpha.12

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.js CHANGED
@@ -583,6 +583,15 @@ var uiMessageStreamPartSchema = import_zod.z.union([
583
583
  providerMetadata: import_zod.z.any().optional()
584
584
  // Use z.any() for generic metadata
585
585
  }),
586
+ import_zod.z.object({
587
+ type: import_zod.z.literal("source-document"),
588
+ sourceId: import_zod.z.string(),
589
+ mediaType: import_zod.z.string(),
590
+ title: import_zod.z.string(),
591
+ filename: import_zod.z.string().optional(),
592
+ providerMetadata: import_zod.z.any().optional()
593
+ // Use z.any() for generic metadata
594
+ }),
586
595
  import_zod.z.object({
587
596
  type: import_zod.z.literal("file"),
588
597
  url: import_zod.z.string(),
@@ -803,8 +812,137 @@ var SerialJobExecutor = class {
803
812
  }
804
813
  };
805
814
 
815
+ // src/ui/convert-file-list-to-file-ui-parts.ts
816
+ async function convertFileListToFileUIParts(files) {
817
+ if (files == null) {
818
+ return [];
819
+ }
820
+ if (!globalThis.FileList || !(files instanceof globalThis.FileList)) {
821
+ throw new Error("FileList is not supported in the current environment");
822
+ }
823
+ return Promise.all(
824
+ Array.from(files).map(async (file) => {
825
+ const { name: name17, type } = file;
826
+ const dataUrl = await new Promise((resolve, reject) => {
827
+ const reader = new FileReader();
828
+ reader.onload = (readerEvent) => {
829
+ var _a17;
830
+ resolve((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
831
+ };
832
+ reader.onerror = (error) => reject(error);
833
+ reader.readAsDataURL(file);
834
+ });
835
+ return {
836
+ type: "file",
837
+ mediaType: type,
838
+ filename: name17,
839
+ url: dataUrl
840
+ };
841
+ })
842
+ );
843
+ }
844
+
845
+ // src/ui/default-chat-transport.ts
846
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
847
+ var getOriginalFetch2 = () => fetch;
848
+ async function fetchUIMessageStream({
849
+ api,
850
+ body,
851
+ credentials,
852
+ headers,
853
+ abortSignal,
854
+ fetch: fetch2 = getOriginalFetch2(),
855
+ requestType = "generate"
856
+ }) {
857
+ var _a17;
858
+ const response = requestType === "resume" ? await fetch2(`${api}?id=${body.id}`, {
859
+ method: "GET",
860
+ headers: {
861
+ "Content-Type": "application/json",
862
+ ...headers
863
+ },
864
+ signal: abortSignal,
865
+ credentials
866
+ }) : await fetch2(api, {
867
+ method: "POST",
868
+ body: JSON.stringify(body),
869
+ headers: {
870
+ "Content-Type": "application/json",
871
+ ...headers
872
+ },
873
+ signal: abortSignal,
874
+ credentials
875
+ });
876
+ if (!response.ok) {
877
+ throw new Error(
878
+ (_a17 = await response.text()) != null ? _a17 : "Failed to fetch the chat response."
879
+ );
880
+ }
881
+ if (!response.body) {
882
+ throw new Error("The response body is empty.");
883
+ }
884
+ return (0, import_provider_utils2.parseJsonEventStream)({
885
+ stream: response.body,
886
+ schema: uiMessageStreamPartSchema
887
+ }).pipeThrough(
888
+ new TransformStream({
889
+ async transform(part, controller) {
890
+ if (!part.success) {
891
+ throw part.error;
892
+ }
893
+ controller.enqueue(part.value);
894
+ }
895
+ })
896
+ );
897
+ }
898
+ var DefaultChatTransport = class {
899
+ constructor({
900
+ api = "/api/chat",
901
+ credentials,
902
+ headers,
903
+ body,
904
+ fetch: fetch2,
905
+ prepareRequest
906
+ } = {}) {
907
+ this.api = api;
908
+ this.credentials = credentials;
909
+ this.headers = headers;
910
+ this.body = body;
911
+ this.fetch = fetch2;
912
+ this.prepareRequest = prepareRequest;
913
+ }
914
+ submitMessages({
915
+ chatId,
916
+ messages,
917
+ abortSignal,
918
+ metadata,
919
+ headers,
920
+ body,
921
+ requestType
922
+ }) {
923
+ var _a17, _b;
924
+ const preparedRequest = (_a17 = this.prepareRequest) == null ? void 0 : _a17.call(this, {
925
+ id: chatId,
926
+ messages,
927
+ body: { ...this.body, ...body },
928
+ headers: { ...this.headers, ...headers },
929
+ credentials: this.credentials,
930
+ requestMetadata: metadata
931
+ });
932
+ return fetchUIMessageStream({
933
+ api: this.api,
934
+ body: (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : { ...this.body, ...body, id: chatId, messages },
935
+ headers: (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? preparedRequest.headers : { ...this.headers, ...headers },
936
+ credentials: (_b = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _b : this.credentials,
937
+ abortSignal,
938
+ fetch: this.fetch,
939
+ requestType
940
+ });
941
+ }
942
+ };
943
+
806
944
  // src/ui/process-ui-message-stream.ts
807
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
945
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
808
946
 
809
947
  // src/util/merge-objects.ts
810
948
  function mergeObjects(base, overrides) {
@@ -840,7 +978,7 @@ function mergeObjects(base, overrides) {
840
978
  }
841
979
 
842
980
  // src/util/parse-partial-json.ts
843
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
981
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
844
982
 
845
983
  // src/util/fix-json.ts
846
984
  function fixJson(input) {
@@ -1165,11 +1303,11 @@ async function parsePartialJson(jsonText) {
1165
1303
  if (jsonText === void 0) {
1166
1304
  return { value: void 0, state: "undefined-input" };
1167
1305
  }
1168
- let result = await (0, import_provider_utils2.safeParseJSON)({ text: jsonText });
1306
+ let result = await (0, import_provider_utils3.safeParseJSON)({ text: jsonText });
1169
1307
  if (result.success) {
1170
1308
  return { value: result.value, state: "successful-parse" };
1171
1309
  }
1172
- result = await (0, import_provider_utils2.safeParseJSON)({ text: fixJson(jsonText) });
1310
+ result = await (0, import_provider_utils3.safeParseJSON)({ text: fixJson(jsonText) });
1173
1311
  if (result.success) {
1174
1312
  return { value: result.value, state: "repaired-parse" };
1175
1313
  }
@@ -1230,7 +1368,7 @@ function processUIMessageStream({
1230
1368
  if (metadata != null) {
1231
1369
  const mergedMetadata = state.message.metadata != null ? mergeObjects(state.message.metadata, metadata) : metadata;
1232
1370
  if (messageMetadataSchema != null) {
1233
- await (0, import_provider_utils3.validateTypes)({
1371
+ await (0, import_provider_utils4.validateTypes)({
1234
1372
  value: mergedMetadata,
1235
1373
  schema: messageMetadataSchema
1236
1374
  });
@@ -1293,6 +1431,18 @@ function processUIMessageStream({
1293
1431
  write();
1294
1432
  break;
1295
1433
  }
1434
+ case "source-document": {
1435
+ state.message.parts.push({
1436
+ type: "source-document",
1437
+ sourceId: part.sourceId,
1438
+ mediaType: part.mediaType,
1439
+ title: part.title,
1440
+ filename: part.filename,
1441
+ providerMetadata: part.providerMetadata
1442
+ });
1443
+ write();
1444
+ break;
1445
+ }
1296
1446
  case "tool-call-streaming-start": {
1297
1447
  const toolInvocations = getToolInvocations(state.message);
1298
1448
  state.partialToolCalls[part.toolCallId] = {
@@ -1473,135 +1623,6 @@ function isAssistantMessageWithCompletedToolCalls(message) {
1473
1623
  return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "result" in part.toolInvocation);
1474
1624
  }
1475
1625
 
1476
- // src/ui/default-chat-transport.ts
1477
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
1478
- var getOriginalFetch2 = () => fetch;
1479
- async function fetchUIMessageStream({
1480
- api,
1481
- body,
1482
- credentials,
1483
- headers,
1484
- abortSignal,
1485
- fetch: fetch2 = getOriginalFetch2(),
1486
- requestType = "generate"
1487
- }) {
1488
- var _a17;
1489
- const response = requestType === "resume" ? await fetch2(`${api}?id=${body.id}`, {
1490
- method: "GET",
1491
- headers: {
1492
- "Content-Type": "application/json",
1493
- ...headers
1494
- },
1495
- signal: abortSignal,
1496
- credentials
1497
- }) : await fetch2(api, {
1498
- method: "POST",
1499
- body: JSON.stringify(body),
1500
- headers: {
1501
- "Content-Type": "application/json",
1502
- ...headers
1503
- },
1504
- signal: abortSignal,
1505
- credentials
1506
- });
1507
- if (!response.ok) {
1508
- throw new Error(
1509
- (_a17 = await response.text()) != null ? _a17 : "Failed to fetch the chat response."
1510
- );
1511
- }
1512
- if (!response.body) {
1513
- throw new Error("The response body is empty.");
1514
- }
1515
- return (0, import_provider_utils4.parseJsonEventStream)({
1516
- stream: response.body,
1517
- schema: uiMessageStreamPartSchema
1518
- }).pipeThrough(
1519
- new TransformStream({
1520
- async transform(part, controller) {
1521
- if (!part.success) {
1522
- throw part.error;
1523
- }
1524
- controller.enqueue(part.value);
1525
- }
1526
- })
1527
- );
1528
- }
1529
- var DefaultChatTransport = class {
1530
- constructor({
1531
- api = "/api/chat",
1532
- credentials,
1533
- headers,
1534
- body,
1535
- fetch: fetch2,
1536
- prepareRequest
1537
- } = {}) {
1538
- this.api = api;
1539
- this.credentials = credentials;
1540
- this.headers = headers;
1541
- this.body = body;
1542
- this.fetch = fetch2;
1543
- this.prepareRequest = prepareRequest;
1544
- }
1545
- submitMessages({
1546
- chatId,
1547
- messages,
1548
- abortSignal,
1549
- metadata,
1550
- headers,
1551
- body,
1552
- requestType
1553
- }) {
1554
- var _a17, _b;
1555
- const preparedRequest = (_a17 = this.prepareRequest) == null ? void 0 : _a17.call(this, {
1556
- id: chatId,
1557
- messages,
1558
- body: { ...this.body, ...body },
1559
- headers: { ...this.headers, ...headers },
1560
- credentials: this.credentials,
1561
- requestMetadata: metadata
1562
- });
1563
- return fetchUIMessageStream({
1564
- api: this.api,
1565
- body: (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : { ...this.body, ...body, id: chatId, messages },
1566
- headers: (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? preparedRequest.headers : { ...this.headers, ...headers },
1567
- credentials: (_b = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _b : this.credentials,
1568
- abortSignal,
1569
- fetch: this.fetch,
1570
- requestType
1571
- });
1572
- }
1573
- };
1574
-
1575
- // src/ui/convert-file-list-to-file-ui-parts.ts
1576
- async function convertFileListToFileUIParts(files) {
1577
- if (files == null) {
1578
- return [];
1579
- }
1580
- if (!globalThis.FileList || !(files instanceof globalThis.FileList)) {
1581
- throw new Error("FileList is not supported in the current environment");
1582
- }
1583
- return Promise.all(
1584
- Array.from(files).map(async (file) => {
1585
- const { name: name17, type } = file;
1586
- const dataUrl = await new Promise((resolve, reject) => {
1587
- const reader = new FileReader();
1588
- reader.onload = (readerEvent) => {
1589
- var _a17;
1590
- resolve((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
1591
- };
1592
- reader.onerror = (error) => reject(error);
1593
- reader.readAsDataURL(file);
1594
- });
1595
- return {
1596
- type: "file",
1597
- mediaType: type,
1598
- filename: name17,
1599
- url: dataUrl
1600
- };
1601
- })
1602
- );
1603
- }
1604
-
1605
1626
  // src/ui/chat.ts
1606
1627
  var AbstractChat = class {
1607
1628
  constructor({
@@ -1616,7 +1637,6 @@ var AbstractChat = class {
1616
1637
  onToolCall,
1617
1638
  onFinish
1618
1639
  }) {
1619
- this.subscribers = /* @__PURE__ */ new Set();
1620
1640
  this.activeResponse = void 0;
1621
1641
  this.jobExecutor = new SerialJobExecutor();
1622
1642
  this.removeAssistantResponse = () => {
@@ -1628,7 +1648,6 @@ var AbstractChat = class {
1628
1648
  throw new Error("Last message is not an assistant message");
1629
1649
  }
1630
1650
  this.state.popMessage();
1631
- this.emit({ type: "messages-changed" });
1632
1651
  };
1633
1652
  /**
1634
1653
  * Append a user message to the chat list. This triggers the API call to fetch
@@ -1653,7 +1672,6 @@ var AbstractChat = class {
1653
1672
  id: (_a17 = uiMessage.id) != null ? _a17 : this.generateId(),
1654
1673
  role: (_b = uiMessage.role) != null ? _b : "user"
1655
1674
  });
1656
- this.emit({ type: "messages-changed" });
1657
1675
  await this.triggerRequest({ requestType: "generate", ...options });
1658
1676
  };
1659
1677
  /**
@@ -1665,7 +1683,6 @@ var AbstractChat = class {
1665
1683
  }
1666
1684
  if (this.lastMessage.role === "assistant") {
1667
1685
  this.state.popMessage();
1668
- this.emit({ type: "messages-changed" });
1669
1686
  }
1670
1687
  await this.triggerRequest({ requestType: "generate", ...options });
1671
1688
  };
@@ -1739,7 +1756,6 @@ var AbstractChat = class {
1739
1756
  return;
1740
1757
  this.state.status = status;
1741
1758
  this.state.error = error;
1742
- this.emit({ type: "status-changed" });
1743
1759
  }
1744
1760
  get error() {
1745
1761
  return this.state.error;
@@ -1750,18 +1766,8 @@ var AbstractChat = class {
1750
1766
  get lastMessage() {
1751
1767
  return this.state.messages[this.state.messages.length - 1];
1752
1768
  }
1753
- subscribe(subscriber) {
1754
- this.subscribers.add(subscriber);
1755
- return () => this.subscribers.delete(subscriber);
1756
- }
1757
1769
  set messages(messages) {
1758
1770
  this.state.messages = messages;
1759
- this.emit({ type: "messages-changed" });
1760
- }
1761
- emit(event) {
1762
- for (const subscriber of this.subscribers) {
1763
- subscriber.onChange(event);
1764
- }
1765
1771
  }
1766
1772
  async triggerRequest({
1767
1773
  requestType,
@@ -1809,9 +1815,6 @@ var AbstractChat = class {
1809
1815
  } else {
1810
1816
  this.state.pushMessage(activeResponse.state.message);
1811
1817
  }
1812
- this.emit({
1813
- type: "messages-changed"
1814
- });
1815
1818
  }
1816
1819
  })
1817
1820
  )
@@ -2214,7 +2217,10 @@ function createUIMessageStream({
2214
2217
  safeEnqueue(value);
2215
2218
  }
2216
2219
  })().catch((error) => {
2217
- safeEnqueue({ type: "error", errorText: onError(error) });
2220
+ safeEnqueue({
2221
+ type: "error",
2222
+ errorText: onError(error)
2223
+ });
2218
2224
  })
2219
2225
  );
2220
2226
  },
@@ -2224,12 +2230,18 @@ function createUIMessageStream({
2224
2230
  if (result) {
2225
2231
  ongoingStreamPromises.push(
2226
2232
  result.catch((error) => {
2227
- safeEnqueue({ type: "error", errorText: onError(error) });
2233
+ safeEnqueue({
2234
+ type: "error",
2235
+ errorText: onError(error)
2236
+ });
2228
2237
  })
2229
2238
  );
2230
2239
  }
2231
2240
  } catch (error) {
2232
- safeEnqueue({ type: "error", errorText: onError(error) });
2241
+ safeEnqueue({
2242
+ type: "error",
2243
+ errorText: onError(error)
2244
+ });
2233
2245
  }
2234
2246
  const waitForStreams = new Promise(async (resolve) => {
2235
2247
  while (ongoingStreamPromises.length > 0) {
@@ -2251,16 +2263,6 @@ function createUIMessageStream({
2251
2263
  });
2252
2264
  }
2253
2265
 
2254
- // src/ui-message-stream/ui-message-stream-headers.ts
2255
- var uiMessageStreamHeaders = {
2256
- "content-type": "text/event-stream",
2257
- "cache-control": "no-cache",
2258
- connection: "keep-alive",
2259
- "x-vercel-ai-ui-message-stream": "v1",
2260
- "x-accel-buffering": "no"
2261
- // disable nginx buffering
2262
- };
2263
-
2264
2266
  // src/ui-message-stream/json-to-sse-transform-stream.ts
2265
2267
  var JsonToSseTransformStream = class extends TransformStream {
2266
2268
  constructor() {
@@ -2277,6 +2279,16 @@ var JsonToSseTransformStream = class extends TransformStream {
2277
2279
  }
2278
2280
  };
2279
2281
 
2282
+ // src/ui-message-stream/ui-message-stream-headers.ts
2283
+ var uiMessageStreamHeaders = {
2284
+ "content-type": "text/event-stream",
2285
+ "cache-control": "no-cache",
2286
+ connection: "keep-alive",
2287
+ "x-vercel-ai-ui-message-stream": "v1",
2288
+ "x-accel-buffering": "no"
2289
+ // disable nginx buffering
2290
+ };
2291
+
2280
2292
  // src/ui-message-stream/create-ui-message-stream-response.ts
2281
2293
  function createUIMessageStreamResponse({
2282
2294
  status,
@@ -4918,7 +4930,8 @@ var DefaultStreamObjectResult = class {
4918
4930
  }),
4919
4931
  providerOptions,
4920
4932
  abortSignal,
4921
- headers
4933
+ headers,
4934
+ includeRawChunks: false
4922
4935
  };
4923
4936
  const transformer = {
4924
4937
  transform: (chunk, controller) => {
@@ -5957,6 +5970,14 @@ async function executeTools({
5957
5970
  const toolResults = await Promise.all(
5958
5971
  toolCalls.map(async ({ toolCallId, toolName, args }) => {
5959
5972
  const tool2 = tools[toolName];
5973
+ if ((tool2 == null ? void 0 : tool2.onArgsAvailable) != null) {
5974
+ await tool2.onArgsAvailable({
5975
+ args,
5976
+ toolCallId,
5977
+ messages,
5978
+ abortSignal
5979
+ });
5980
+ }
5960
5981
  if ((tool2 == null ? void 0 : tool2.execute) == null) {
5961
5982
  return void 0;
5962
5983
  }
@@ -6260,7 +6281,6 @@ var import_provider_utils21 = require("@ai-sdk/provider-utils");
6260
6281
  function runToolsTransformation({
6261
6282
  tools,
6262
6283
  generatorStream,
6263
- toolCallStreaming,
6264
6284
  tracer,
6265
6285
  telemetry,
6266
6286
  system,
@@ -6301,6 +6321,10 @@ function runToolsTransformation({
6301
6321
  controller.enqueue(chunk);
6302
6322
  break;
6303
6323
  }
6324
+ case "raw": {
6325
+ controller.enqueue(chunk);
6326
+ break;
6327
+ }
6304
6328
  case "file": {
6305
6329
  controller.enqueue({
6306
6330
  type: "file",
@@ -6312,22 +6336,20 @@ function runToolsTransformation({
6312
6336
  break;
6313
6337
  }
6314
6338
  case "tool-call-delta": {
6315
- if (toolCallStreaming) {
6316
- if (!activeToolCalls[chunk.toolCallId]) {
6317
- controller.enqueue({
6318
- type: "tool-call-streaming-start",
6319
- toolCallId: chunk.toolCallId,
6320
- toolName: chunk.toolName
6321
- });
6322
- activeToolCalls[chunk.toolCallId] = true;
6323
- }
6339
+ if (!activeToolCalls[chunk.toolCallId]) {
6324
6340
  controller.enqueue({
6325
- type: "tool-call-delta",
6341
+ type: "tool-call-streaming-start",
6326
6342
  toolCallId: chunk.toolCallId,
6327
- toolName: chunk.toolName,
6328
- argsTextDelta: chunk.argsTextDelta
6343
+ toolName: chunk.toolName
6329
6344
  });
6345
+ activeToolCalls[chunk.toolCallId] = true;
6330
6346
  }
6347
+ controller.enqueue({
6348
+ type: "tool-call-delta",
6349
+ toolCallId: chunk.toolCallId,
6350
+ toolName: chunk.toolName,
6351
+ argsTextDelta: chunk.argsTextDelta
6352
+ });
6331
6353
  break;
6332
6354
  }
6333
6355
  case "tool-call": {
@@ -6341,6 +6363,14 @@ function runToolsTransformation({
6341
6363
  });
6342
6364
  controller.enqueue(toolCall);
6343
6365
  const tool2 = tools[toolCall.toolName];
6366
+ if (tool2.onArgsAvailable != null) {
6367
+ await tool2.onArgsAvailable({
6368
+ args: toolCall.args,
6369
+ toolCallId: toolCall.toolCallId,
6370
+ messages,
6371
+ abortSignal
6372
+ });
6373
+ }
6344
6374
  if (tool2.execute != null) {
6345
6375
  const toolExecutionId = (0, import_provider_utils21.generateId)();
6346
6376
  outstandingToolResults.add(toolExecutionId);
@@ -6470,12 +6500,11 @@ function streamText({
6470
6500
  experimental_telemetry: telemetry,
6471
6501
  prepareStep,
6472
6502
  providerOptions,
6473
- experimental_toolCallStreaming = false,
6474
- toolCallStreaming = experimental_toolCallStreaming,
6475
6503
  experimental_activeTools,
6476
6504
  activeTools = experimental_activeTools,
6477
6505
  experimental_repairToolCall: repairToolCall,
6478
6506
  experimental_transform: transform,
6507
+ includeRawChunks = false,
6479
6508
  onChunk,
6480
6509
  onError = ({ error }) => {
6481
6510
  console.error(error);
@@ -6501,7 +6530,6 @@ function streamText({
6501
6530
  messages,
6502
6531
  tools,
6503
6532
  toolChoice,
6504
- toolCallStreaming,
6505
6533
  transforms: asArray(transform),
6506
6534
  activeTools,
6507
6535
  repairToolCall,
@@ -6509,6 +6537,7 @@ function streamText({
6509
6537
  output,
6510
6538
  providerOptions,
6511
6539
  prepareStep,
6540
+ includeRawChunks,
6512
6541
  onChunk,
6513
6542
  onError,
6514
6543
  onFinish,
@@ -6579,7 +6608,6 @@ var DefaultStreamTextResult = class {
6579
6608
  messages,
6580
6609
  tools,
6581
6610
  toolChoice,
6582
- toolCallStreaming,
6583
6611
  transforms,
6584
6612
  activeTools,
6585
6613
  repairToolCall,
@@ -6587,6 +6615,7 @@ var DefaultStreamTextResult = class {
6587
6615
  output,
6588
6616
  providerOptions,
6589
6617
  prepareStep,
6618
+ includeRawChunks,
6590
6619
  now: now2,
6591
6620
  currentDate,
6592
6621
  generateId: generateId3,
@@ -6599,6 +6628,7 @@ var DefaultStreamTextResult = class {
6599
6628
  this._finishReason = new DelayedPromise();
6600
6629
  this._steps = new DelayedPromise();
6601
6630
  this.output = output;
6631
+ this.includeRawChunks = includeRawChunks;
6602
6632
  this.generateId = generateId3;
6603
6633
  let stepFinish;
6604
6634
  let activeReasoningPart = void 0;
@@ -6806,6 +6836,7 @@ var DefaultStreamTextResult = class {
6806
6836
  usage
6807
6837
  }) {
6808
6838
  var _a17, _b, _c, _d;
6839
+ const includeRawChunks2 = self.includeRawChunks;
6809
6840
  stepFinish = new DelayedPromise();
6810
6841
  const initialPrompt = await standardizePrompt({
6811
6842
  system,
@@ -6892,7 +6923,8 @@ var DefaultStreamTextResult = class {
6892
6923
  prompt: promptMessages,
6893
6924
  providerOptions,
6894
6925
  abortSignal,
6895
- headers
6926
+ headers,
6927
+ includeRawChunks: includeRawChunks2
6896
6928
  })
6897
6929
  };
6898
6930
  }
@@ -6901,7 +6933,6 @@ var DefaultStreamTextResult = class {
6901
6933
  const streamWithToolResults = runToolsTransformation({
6902
6934
  tools,
6903
6935
  generatorStream: stream2,
6904
- toolCallStreaming,
6905
6936
  tracer,
6906
6937
  telemetry,
6907
6938
  system,
@@ -7031,8 +7062,28 @@ var DefaultStreamTextResult = class {
7031
7062
  controller.enqueue(chunk);
7032
7063
  break;
7033
7064
  }
7034
- case "tool-call-streaming-start":
7065
+ case "tool-call-streaming-start": {
7066
+ const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7067
+ if ((tool2 == null ? void 0 : tool2.onArgsStreamingStart) != null) {
7068
+ await tool2.onArgsStreamingStart({
7069
+ toolCallId: chunk.toolCallId,
7070
+ messages: stepInputMessages,
7071
+ abortSignal
7072
+ });
7073
+ }
7074
+ controller.enqueue(chunk);
7075
+ break;
7076
+ }
7035
7077
  case "tool-call-delta": {
7078
+ const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7079
+ if ((tool2 == null ? void 0 : tool2.onArgsStreamingDelta) != null) {
7080
+ await tool2.onArgsStreamingDelta({
7081
+ argsTextDelta: chunk.argsTextDelta,
7082
+ toolCallId: chunk.toolCallId,
7083
+ messages: stepInputMessages,
7084
+ abortSignal
7085
+ });
7086
+ }
7036
7087
  controller.enqueue(chunk);
7037
7088
  break;
7038
7089
  }
@@ -7041,6 +7092,10 @@ var DefaultStreamTextResult = class {
7041
7092
  stepFinishReason = "error";
7042
7093
  break;
7043
7094
  }
7095
+ case "raw": {
7096
+ controller.enqueue(chunk);
7097
+ break;
7098
+ }
7044
7099
  default: {
7045
7100
  const exhaustiveCheck = chunkType;
7046
7101
  throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
@@ -7312,7 +7367,7 @@ var DefaultStreamTextResult = class {
7312
7367
  break;
7313
7368
  }
7314
7369
  case "source": {
7315
- if (sendSources) {
7370
+ if (sendSources && part.sourceType === "url") {
7316
7371
  controller.enqueue({
7317
7372
  type: "source-url",
7318
7373
  sourceId: part.id,
@@ -7321,6 +7376,16 @@ var DefaultStreamTextResult = class {
7321
7376
  providerMetadata: part.providerMetadata
7322
7377
  });
7323
7378
  }
7379
+ if (sendSources && part.sourceType === "document") {
7380
+ controller.enqueue({
7381
+ type: "source-document",
7382
+ sourceId: part.id,
7383
+ mediaType: part.mediaType,
7384
+ title: part.title,
7385
+ filename: part.filename,
7386
+ providerMetadata: part.providerMetadata
7387
+ });
7388
+ }
7324
7389
  break;
7325
7390
  }
7326
7391
  case "tool-call-streaming-start": {
@@ -7400,6 +7465,9 @@ var DefaultStreamTextResult = class {
7400
7465
  }
7401
7466
  break;
7402
7467
  }
7468
+ case "raw": {
7469
+ break;
7470
+ }
7403
7471
  default: {
7404
7472
  const exhaustiveCheck = partType;
7405
7473
  throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);