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.mjs CHANGED
@@ -498,6 +498,15 @@ var uiMessageStreamPartSchema = z.union([
498
498
  providerMetadata: z.any().optional()
499
499
  // Use z.any() for generic metadata
500
500
  }),
501
+ z.object({
502
+ type: z.literal("source-document"),
503
+ sourceId: z.string(),
504
+ mediaType: z.string(),
505
+ title: z.string(),
506
+ filename: z.string().optional(),
507
+ providerMetadata: z.any().optional()
508
+ // Use z.any() for generic metadata
509
+ }),
501
510
  z.object({
502
511
  type: z.literal("file"),
503
512
  url: z.string(),
@@ -720,6 +729,137 @@ var SerialJobExecutor = class {
720
729
  }
721
730
  };
722
731
 
732
+ // src/ui/convert-file-list-to-file-ui-parts.ts
733
+ async function convertFileListToFileUIParts(files) {
734
+ if (files == null) {
735
+ return [];
736
+ }
737
+ if (!globalThis.FileList || !(files instanceof globalThis.FileList)) {
738
+ throw new Error("FileList is not supported in the current environment");
739
+ }
740
+ return Promise.all(
741
+ Array.from(files).map(async (file) => {
742
+ const { name: name17, type } = file;
743
+ const dataUrl = await new Promise((resolve, reject) => {
744
+ const reader = new FileReader();
745
+ reader.onload = (readerEvent) => {
746
+ var _a17;
747
+ resolve((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
748
+ };
749
+ reader.onerror = (error) => reject(error);
750
+ reader.readAsDataURL(file);
751
+ });
752
+ return {
753
+ type: "file",
754
+ mediaType: type,
755
+ filename: name17,
756
+ url: dataUrl
757
+ };
758
+ })
759
+ );
760
+ }
761
+
762
+ // src/ui/default-chat-transport.ts
763
+ import {
764
+ parseJsonEventStream as parseJsonEventStream2
765
+ } from "@ai-sdk/provider-utils";
766
+ var getOriginalFetch2 = () => fetch;
767
+ async function fetchUIMessageStream({
768
+ api,
769
+ body,
770
+ credentials,
771
+ headers,
772
+ abortSignal,
773
+ fetch: fetch2 = getOriginalFetch2(),
774
+ requestType = "generate"
775
+ }) {
776
+ var _a17;
777
+ const response = requestType === "resume" ? await fetch2(`${api}?id=${body.id}`, {
778
+ method: "GET",
779
+ headers: {
780
+ "Content-Type": "application/json",
781
+ ...headers
782
+ },
783
+ signal: abortSignal,
784
+ credentials
785
+ }) : await fetch2(api, {
786
+ method: "POST",
787
+ body: JSON.stringify(body),
788
+ headers: {
789
+ "Content-Type": "application/json",
790
+ ...headers
791
+ },
792
+ signal: abortSignal,
793
+ credentials
794
+ });
795
+ if (!response.ok) {
796
+ throw new Error(
797
+ (_a17 = await response.text()) != null ? _a17 : "Failed to fetch the chat response."
798
+ );
799
+ }
800
+ if (!response.body) {
801
+ throw new Error("The response body is empty.");
802
+ }
803
+ return parseJsonEventStream2({
804
+ stream: response.body,
805
+ schema: uiMessageStreamPartSchema
806
+ }).pipeThrough(
807
+ new TransformStream({
808
+ async transform(part, controller) {
809
+ if (!part.success) {
810
+ throw part.error;
811
+ }
812
+ controller.enqueue(part.value);
813
+ }
814
+ })
815
+ );
816
+ }
817
+ var DefaultChatTransport = class {
818
+ constructor({
819
+ api = "/api/chat",
820
+ credentials,
821
+ headers,
822
+ body,
823
+ fetch: fetch2,
824
+ prepareRequest
825
+ } = {}) {
826
+ this.api = api;
827
+ this.credentials = credentials;
828
+ this.headers = headers;
829
+ this.body = body;
830
+ this.fetch = fetch2;
831
+ this.prepareRequest = prepareRequest;
832
+ }
833
+ submitMessages({
834
+ chatId,
835
+ messages,
836
+ abortSignal,
837
+ metadata,
838
+ headers,
839
+ body,
840
+ requestType
841
+ }) {
842
+ var _a17, _b;
843
+ const preparedRequest = (_a17 = this.prepareRequest) == null ? void 0 : _a17.call(this, {
844
+ id: chatId,
845
+ messages,
846
+ body: { ...this.body, ...body },
847
+ headers: { ...this.headers, ...headers },
848
+ credentials: this.credentials,
849
+ requestMetadata: metadata
850
+ });
851
+ return fetchUIMessageStream({
852
+ api: this.api,
853
+ body: (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : { ...this.body, ...body, id: chatId, messages },
854
+ headers: (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? preparedRequest.headers : { ...this.headers, ...headers },
855
+ credentials: (_b = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _b : this.credentials,
856
+ abortSignal,
857
+ fetch: this.fetch,
858
+ requestType
859
+ });
860
+ }
861
+ };
862
+
723
863
  // src/ui/process-ui-message-stream.ts
724
864
  import {
725
865
  validateTypes
@@ -1212,6 +1352,18 @@ function processUIMessageStream({
1212
1352
  write();
1213
1353
  break;
1214
1354
  }
1355
+ case "source-document": {
1356
+ state.message.parts.push({
1357
+ type: "source-document",
1358
+ sourceId: part.sourceId,
1359
+ mediaType: part.mediaType,
1360
+ title: part.title,
1361
+ filename: part.filename,
1362
+ providerMetadata: part.providerMetadata
1363
+ });
1364
+ write();
1365
+ break;
1366
+ }
1215
1367
  case "tool-call-streaming-start": {
1216
1368
  const toolInvocations = getToolInvocations(state.message);
1217
1369
  state.partialToolCalls[part.toolCallId] = {
@@ -1392,137 +1544,6 @@ function isAssistantMessageWithCompletedToolCalls(message) {
1392
1544
  return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "result" in part.toolInvocation);
1393
1545
  }
1394
1546
 
1395
- // src/ui/default-chat-transport.ts
1396
- import {
1397
- parseJsonEventStream as parseJsonEventStream2
1398
- } from "@ai-sdk/provider-utils";
1399
- var getOriginalFetch2 = () => fetch;
1400
- async function fetchUIMessageStream({
1401
- api,
1402
- body,
1403
- credentials,
1404
- headers,
1405
- abortSignal,
1406
- fetch: fetch2 = getOriginalFetch2(),
1407
- requestType = "generate"
1408
- }) {
1409
- var _a17;
1410
- const response = requestType === "resume" ? await fetch2(`${api}?id=${body.id}`, {
1411
- method: "GET",
1412
- headers: {
1413
- "Content-Type": "application/json",
1414
- ...headers
1415
- },
1416
- signal: abortSignal,
1417
- credentials
1418
- }) : await fetch2(api, {
1419
- method: "POST",
1420
- body: JSON.stringify(body),
1421
- headers: {
1422
- "Content-Type": "application/json",
1423
- ...headers
1424
- },
1425
- signal: abortSignal,
1426
- credentials
1427
- });
1428
- if (!response.ok) {
1429
- throw new Error(
1430
- (_a17 = await response.text()) != null ? _a17 : "Failed to fetch the chat response."
1431
- );
1432
- }
1433
- if (!response.body) {
1434
- throw new Error("The response body is empty.");
1435
- }
1436
- return parseJsonEventStream2({
1437
- stream: response.body,
1438
- schema: uiMessageStreamPartSchema
1439
- }).pipeThrough(
1440
- new TransformStream({
1441
- async transform(part, controller) {
1442
- if (!part.success) {
1443
- throw part.error;
1444
- }
1445
- controller.enqueue(part.value);
1446
- }
1447
- })
1448
- );
1449
- }
1450
- var DefaultChatTransport = class {
1451
- constructor({
1452
- api = "/api/chat",
1453
- credentials,
1454
- headers,
1455
- body,
1456
- fetch: fetch2,
1457
- prepareRequest
1458
- } = {}) {
1459
- this.api = api;
1460
- this.credentials = credentials;
1461
- this.headers = headers;
1462
- this.body = body;
1463
- this.fetch = fetch2;
1464
- this.prepareRequest = prepareRequest;
1465
- }
1466
- submitMessages({
1467
- chatId,
1468
- messages,
1469
- abortSignal,
1470
- metadata,
1471
- headers,
1472
- body,
1473
- requestType
1474
- }) {
1475
- var _a17, _b;
1476
- const preparedRequest = (_a17 = this.prepareRequest) == null ? void 0 : _a17.call(this, {
1477
- id: chatId,
1478
- messages,
1479
- body: { ...this.body, ...body },
1480
- headers: { ...this.headers, ...headers },
1481
- credentials: this.credentials,
1482
- requestMetadata: metadata
1483
- });
1484
- return fetchUIMessageStream({
1485
- api: this.api,
1486
- body: (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : { ...this.body, ...body, id: chatId, messages },
1487
- headers: (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? preparedRequest.headers : { ...this.headers, ...headers },
1488
- credentials: (_b = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _b : this.credentials,
1489
- abortSignal,
1490
- fetch: this.fetch,
1491
- requestType
1492
- });
1493
- }
1494
- };
1495
-
1496
- // src/ui/convert-file-list-to-file-ui-parts.ts
1497
- async function convertFileListToFileUIParts(files) {
1498
- if (files == null) {
1499
- return [];
1500
- }
1501
- if (!globalThis.FileList || !(files instanceof globalThis.FileList)) {
1502
- throw new Error("FileList is not supported in the current environment");
1503
- }
1504
- return Promise.all(
1505
- Array.from(files).map(async (file) => {
1506
- const { name: name17, type } = file;
1507
- const dataUrl = await new Promise((resolve, reject) => {
1508
- const reader = new FileReader();
1509
- reader.onload = (readerEvent) => {
1510
- var _a17;
1511
- resolve((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
1512
- };
1513
- reader.onerror = (error) => reject(error);
1514
- reader.readAsDataURL(file);
1515
- });
1516
- return {
1517
- type: "file",
1518
- mediaType: type,
1519
- filename: name17,
1520
- url: dataUrl
1521
- };
1522
- })
1523
- );
1524
- }
1525
-
1526
1547
  // src/ui/chat.ts
1527
1548
  var AbstractChat = class {
1528
1549
  constructor({
@@ -1537,7 +1558,6 @@ var AbstractChat = class {
1537
1558
  onToolCall,
1538
1559
  onFinish
1539
1560
  }) {
1540
- this.subscribers = /* @__PURE__ */ new Set();
1541
1561
  this.activeResponse = void 0;
1542
1562
  this.jobExecutor = new SerialJobExecutor();
1543
1563
  this.removeAssistantResponse = () => {
@@ -1549,7 +1569,6 @@ var AbstractChat = class {
1549
1569
  throw new Error("Last message is not an assistant message");
1550
1570
  }
1551
1571
  this.state.popMessage();
1552
- this.emit({ type: "messages-changed" });
1553
1572
  };
1554
1573
  /**
1555
1574
  * Append a user message to the chat list. This triggers the API call to fetch
@@ -1574,7 +1593,6 @@ var AbstractChat = class {
1574
1593
  id: (_a17 = uiMessage.id) != null ? _a17 : this.generateId(),
1575
1594
  role: (_b = uiMessage.role) != null ? _b : "user"
1576
1595
  });
1577
- this.emit({ type: "messages-changed" });
1578
1596
  await this.triggerRequest({ requestType: "generate", ...options });
1579
1597
  };
1580
1598
  /**
@@ -1586,7 +1604,6 @@ var AbstractChat = class {
1586
1604
  }
1587
1605
  if (this.lastMessage.role === "assistant") {
1588
1606
  this.state.popMessage();
1589
- this.emit({ type: "messages-changed" });
1590
1607
  }
1591
1608
  await this.triggerRequest({ requestType: "generate", ...options });
1592
1609
  };
@@ -1660,7 +1677,6 @@ var AbstractChat = class {
1660
1677
  return;
1661
1678
  this.state.status = status;
1662
1679
  this.state.error = error;
1663
- this.emit({ type: "status-changed" });
1664
1680
  }
1665
1681
  get error() {
1666
1682
  return this.state.error;
@@ -1671,18 +1687,8 @@ var AbstractChat = class {
1671
1687
  get lastMessage() {
1672
1688
  return this.state.messages[this.state.messages.length - 1];
1673
1689
  }
1674
- subscribe(subscriber) {
1675
- this.subscribers.add(subscriber);
1676
- return () => this.subscribers.delete(subscriber);
1677
- }
1678
1690
  set messages(messages) {
1679
1691
  this.state.messages = messages;
1680
- this.emit({ type: "messages-changed" });
1681
- }
1682
- emit(event) {
1683
- for (const subscriber of this.subscribers) {
1684
- subscriber.onChange(event);
1685
- }
1686
1692
  }
1687
1693
  async triggerRequest({
1688
1694
  requestType,
@@ -1730,9 +1736,6 @@ var AbstractChat = class {
1730
1736
  } else {
1731
1737
  this.state.pushMessage(activeResponse.state.message);
1732
1738
  }
1733
- this.emit({
1734
- type: "messages-changed"
1735
- });
1736
1739
  }
1737
1740
  })
1738
1741
  )
@@ -2135,7 +2138,10 @@ function createUIMessageStream({
2135
2138
  safeEnqueue(value);
2136
2139
  }
2137
2140
  })().catch((error) => {
2138
- safeEnqueue({ type: "error", errorText: onError(error) });
2141
+ safeEnqueue({
2142
+ type: "error",
2143
+ errorText: onError(error)
2144
+ });
2139
2145
  })
2140
2146
  );
2141
2147
  },
@@ -2145,12 +2151,18 @@ function createUIMessageStream({
2145
2151
  if (result) {
2146
2152
  ongoingStreamPromises.push(
2147
2153
  result.catch((error) => {
2148
- safeEnqueue({ type: "error", errorText: onError(error) });
2154
+ safeEnqueue({
2155
+ type: "error",
2156
+ errorText: onError(error)
2157
+ });
2149
2158
  })
2150
2159
  );
2151
2160
  }
2152
2161
  } catch (error) {
2153
- safeEnqueue({ type: "error", errorText: onError(error) });
2162
+ safeEnqueue({
2163
+ type: "error",
2164
+ errorText: onError(error)
2165
+ });
2154
2166
  }
2155
2167
  const waitForStreams = new Promise(async (resolve) => {
2156
2168
  while (ongoingStreamPromises.length > 0) {
@@ -2172,16 +2184,6 @@ function createUIMessageStream({
2172
2184
  });
2173
2185
  }
2174
2186
 
2175
- // src/ui-message-stream/ui-message-stream-headers.ts
2176
- var uiMessageStreamHeaders = {
2177
- "content-type": "text/event-stream",
2178
- "cache-control": "no-cache",
2179
- connection: "keep-alive",
2180
- "x-vercel-ai-ui-message-stream": "v1",
2181
- "x-accel-buffering": "no"
2182
- // disable nginx buffering
2183
- };
2184
-
2185
2187
  // src/ui-message-stream/json-to-sse-transform-stream.ts
2186
2188
  var JsonToSseTransformStream = class extends TransformStream {
2187
2189
  constructor() {
@@ -2198,6 +2200,16 @@ var JsonToSseTransformStream = class extends TransformStream {
2198
2200
  }
2199
2201
  };
2200
2202
 
2203
+ // src/ui-message-stream/ui-message-stream-headers.ts
2204
+ var uiMessageStreamHeaders = {
2205
+ "content-type": "text/event-stream",
2206
+ "cache-control": "no-cache",
2207
+ connection: "keep-alive",
2208
+ "x-vercel-ai-ui-message-stream": "v1",
2209
+ "x-accel-buffering": "no"
2210
+ // disable nginx buffering
2211
+ };
2212
+
2201
2213
  // src/ui-message-stream/create-ui-message-stream-response.ts
2202
2214
  function createUIMessageStreamResponse({
2203
2215
  status,
@@ -4864,7 +4876,8 @@ var DefaultStreamObjectResult = class {
4864
4876
  }),
4865
4877
  providerOptions,
4866
4878
  abortSignal,
4867
- headers
4879
+ headers,
4880
+ includeRawChunks: false
4868
4881
  };
4869
4882
  const transformer = {
4870
4883
  transform: (chunk, controller) => {
@@ -5907,6 +5920,14 @@ async function executeTools({
5907
5920
  const toolResults = await Promise.all(
5908
5921
  toolCalls.map(async ({ toolCallId, toolName, args }) => {
5909
5922
  const tool2 = tools[toolName];
5923
+ if ((tool2 == null ? void 0 : tool2.onArgsAvailable) != null) {
5924
+ await tool2.onArgsAvailable({
5925
+ args,
5926
+ toolCallId,
5927
+ messages,
5928
+ abortSignal
5929
+ });
5930
+ }
5910
5931
  if ((tool2 == null ? void 0 : tool2.execute) == null) {
5911
5932
  return void 0;
5912
5933
  }
@@ -6214,7 +6235,6 @@ import { generateId } from "@ai-sdk/provider-utils";
6214
6235
  function runToolsTransformation({
6215
6236
  tools,
6216
6237
  generatorStream,
6217
- toolCallStreaming,
6218
6238
  tracer,
6219
6239
  telemetry,
6220
6240
  system,
@@ -6255,6 +6275,10 @@ function runToolsTransformation({
6255
6275
  controller.enqueue(chunk);
6256
6276
  break;
6257
6277
  }
6278
+ case "raw": {
6279
+ controller.enqueue(chunk);
6280
+ break;
6281
+ }
6258
6282
  case "file": {
6259
6283
  controller.enqueue({
6260
6284
  type: "file",
@@ -6266,22 +6290,20 @@ function runToolsTransformation({
6266
6290
  break;
6267
6291
  }
6268
6292
  case "tool-call-delta": {
6269
- if (toolCallStreaming) {
6270
- if (!activeToolCalls[chunk.toolCallId]) {
6271
- controller.enqueue({
6272
- type: "tool-call-streaming-start",
6273
- toolCallId: chunk.toolCallId,
6274
- toolName: chunk.toolName
6275
- });
6276
- activeToolCalls[chunk.toolCallId] = true;
6277
- }
6293
+ if (!activeToolCalls[chunk.toolCallId]) {
6278
6294
  controller.enqueue({
6279
- type: "tool-call-delta",
6295
+ type: "tool-call-streaming-start",
6280
6296
  toolCallId: chunk.toolCallId,
6281
- toolName: chunk.toolName,
6282
- argsTextDelta: chunk.argsTextDelta
6297
+ toolName: chunk.toolName
6283
6298
  });
6299
+ activeToolCalls[chunk.toolCallId] = true;
6284
6300
  }
6301
+ controller.enqueue({
6302
+ type: "tool-call-delta",
6303
+ toolCallId: chunk.toolCallId,
6304
+ toolName: chunk.toolName,
6305
+ argsTextDelta: chunk.argsTextDelta
6306
+ });
6285
6307
  break;
6286
6308
  }
6287
6309
  case "tool-call": {
@@ -6295,6 +6317,14 @@ function runToolsTransformation({
6295
6317
  });
6296
6318
  controller.enqueue(toolCall);
6297
6319
  const tool2 = tools[toolCall.toolName];
6320
+ if (tool2.onArgsAvailable != null) {
6321
+ await tool2.onArgsAvailable({
6322
+ args: toolCall.args,
6323
+ toolCallId: toolCall.toolCallId,
6324
+ messages,
6325
+ abortSignal
6326
+ });
6327
+ }
6298
6328
  if (tool2.execute != null) {
6299
6329
  const toolExecutionId = generateId();
6300
6330
  outstandingToolResults.add(toolExecutionId);
@@ -6424,12 +6454,11 @@ function streamText({
6424
6454
  experimental_telemetry: telemetry,
6425
6455
  prepareStep,
6426
6456
  providerOptions,
6427
- experimental_toolCallStreaming = false,
6428
- toolCallStreaming = experimental_toolCallStreaming,
6429
6457
  experimental_activeTools,
6430
6458
  activeTools = experimental_activeTools,
6431
6459
  experimental_repairToolCall: repairToolCall,
6432
6460
  experimental_transform: transform,
6461
+ includeRawChunks = false,
6433
6462
  onChunk,
6434
6463
  onError = ({ error }) => {
6435
6464
  console.error(error);
@@ -6455,7 +6484,6 @@ function streamText({
6455
6484
  messages,
6456
6485
  tools,
6457
6486
  toolChoice,
6458
- toolCallStreaming,
6459
6487
  transforms: asArray(transform),
6460
6488
  activeTools,
6461
6489
  repairToolCall,
@@ -6463,6 +6491,7 @@ function streamText({
6463
6491
  output,
6464
6492
  providerOptions,
6465
6493
  prepareStep,
6494
+ includeRawChunks,
6466
6495
  onChunk,
6467
6496
  onError,
6468
6497
  onFinish,
@@ -6533,7 +6562,6 @@ var DefaultStreamTextResult = class {
6533
6562
  messages,
6534
6563
  tools,
6535
6564
  toolChoice,
6536
- toolCallStreaming,
6537
6565
  transforms,
6538
6566
  activeTools,
6539
6567
  repairToolCall,
@@ -6541,6 +6569,7 @@ var DefaultStreamTextResult = class {
6541
6569
  output,
6542
6570
  providerOptions,
6543
6571
  prepareStep,
6572
+ includeRawChunks,
6544
6573
  now: now2,
6545
6574
  currentDate,
6546
6575
  generateId: generateId3,
@@ -6553,6 +6582,7 @@ var DefaultStreamTextResult = class {
6553
6582
  this._finishReason = new DelayedPromise();
6554
6583
  this._steps = new DelayedPromise();
6555
6584
  this.output = output;
6585
+ this.includeRawChunks = includeRawChunks;
6556
6586
  this.generateId = generateId3;
6557
6587
  let stepFinish;
6558
6588
  let activeReasoningPart = void 0;
@@ -6760,6 +6790,7 @@ var DefaultStreamTextResult = class {
6760
6790
  usage
6761
6791
  }) {
6762
6792
  var _a17, _b, _c, _d;
6793
+ const includeRawChunks2 = self.includeRawChunks;
6763
6794
  stepFinish = new DelayedPromise();
6764
6795
  const initialPrompt = await standardizePrompt({
6765
6796
  system,
@@ -6846,7 +6877,8 @@ var DefaultStreamTextResult = class {
6846
6877
  prompt: promptMessages,
6847
6878
  providerOptions,
6848
6879
  abortSignal,
6849
- headers
6880
+ headers,
6881
+ includeRawChunks: includeRawChunks2
6850
6882
  })
6851
6883
  };
6852
6884
  }
@@ -6855,7 +6887,6 @@ var DefaultStreamTextResult = class {
6855
6887
  const streamWithToolResults = runToolsTransformation({
6856
6888
  tools,
6857
6889
  generatorStream: stream2,
6858
- toolCallStreaming,
6859
6890
  tracer,
6860
6891
  telemetry,
6861
6892
  system,
@@ -6985,8 +7016,28 @@ var DefaultStreamTextResult = class {
6985
7016
  controller.enqueue(chunk);
6986
7017
  break;
6987
7018
  }
6988
- case "tool-call-streaming-start":
7019
+ case "tool-call-streaming-start": {
7020
+ const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7021
+ if ((tool2 == null ? void 0 : tool2.onArgsStreamingStart) != null) {
7022
+ await tool2.onArgsStreamingStart({
7023
+ toolCallId: chunk.toolCallId,
7024
+ messages: stepInputMessages,
7025
+ abortSignal
7026
+ });
7027
+ }
7028
+ controller.enqueue(chunk);
7029
+ break;
7030
+ }
6989
7031
  case "tool-call-delta": {
7032
+ const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7033
+ if ((tool2 == null ? void 0 : tool2.onArgsStreamingDelta) != null) {
7034
+ await tool2.onArgsStreamingDelta({
7035
+ argsTextDelta: chunk.argsTextDelta,
7036
+ toolCallId: chunk.toolCallId,
7037
+ messages: stepInputMessages,
7038
+ abortSignal
7039
+ });
7040
+ }
6990
7041
  controller.enqueue(chunk);
6991
7042
  break;
6992
7043
  }
@@ -6995,6 +7046,10 @@ var DefaultStreamTextResult = class {
6995
7046
  stepFinishReason = "error";
6996
7047
  break;
6997
7048
  }
7049
+ case "raw": {
7050
+ controller.enqueue(chunk);
7051
+ break;
7052
+ }
6998
7053
  default: {
6999
7054
  const exhaustiveCheck = chunkType;
7000
7055
  throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
@@ -7266,7 +7321,7 @@ var DefaultStreamTextResult = class {
7266
7321
  break;
7267
7322
  }
7268
7323
  case "source": {
7269
- if (sendSources) {
7324
+ if (sendSources && part.sourceType === "url") {
7270
7325
  controller.enqueue({
7271
7326
  type: "source-url",
7272
7327
  sourceId: part.id,
@@ -7275,6 +7330,16 @@ var DefaultStreamTextResult = class {
7275
7330
  providerMetadata: part.providerMetadata
7276
7331
  });
7277
7332
  }
7333
+ if (sendSources && part.sourceType === "document") {
7334
+ controller.enqueue({
7335
+ type: "source-document",
7336
+ sourceId: part.id,
7337
+ mediaType: part.mediaType,
7338
+ title: part.title,
7339
+ filename: part.filename,
7340
+ providerMetadata: part.providerMetadata
7341
+ });
7342
+ }
7278
7343
  break;
7279
7344
  }
7280
7345
  case "tool-call-streaming-start": {
@@ -7354,6 +7419,9 @@ var DefaultStreamTextResult = class {
7354
7419
  }
7355
7420
  break;
7356
7421
  }
7422
+ case "raw": {
7423
+ break;
7424
+ }
7357
7425
  default: {
7358
7426
  const exhaustiveCheck = partType;
7359
7427
  throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);