ai 5.0.0-alpha.12 → 5.0.0-alpha.14

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
@@ -74,24 +74,22 @@ var InvalidStreamPartError = class extends AISDKError2 {
74
74
  };
75
75
  _a2 = symbol2;
76
76
 
77
- // src/error/invalid-tool-arguments-error.ts
77
+ // src/error/invalid-tool-input-error.ts
78
78
  import { AISDKError as AISDKError3, getErrorMessage } from "@ai-sdk/provider";
79
- var name3 = "AI_InvalidToolArgumentsError";
79
+ var name3 = "AI_InvalidToolInputError";
80
80
  var marker3 = `vercel.ai.error.${name3}`;
81
81
  var symbol3 = Symbol.for(marker3);
82
82
  var _a3;
83
- var InvalidToolArgumentsError = class extends AISDKError3 {
83
+ var InvalidToolInputError = class extends AISDKError3 {
84
84
  constructor({
85
- toolArgs,
85
+ toolInput,
86
86
  toolName,
87
87
  cause,
88
- message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
89
- cause
90
- )}`
88
+ message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}`
91
89
  }) {
92
90
  super({ name: name3, message, cause });
93
91
  this[_a3] = true;
94
- this.toolArgs = toolArgs;
92
+ this.toolInput = toolInput;
95
93
  this.toolName = toolName;
96
94
  }
97
95
  static isInstance(error) {
@@ -242,7 +240,7 @@ var symbol10 = Symbol.for(marker10);
242
240
  var _a10;
243
241
  var ToolExecutionError = class extends AISDKError10 {
244
242
  constructor({
245
- toolArgs,
243
+ toolInput,
246
244
  toolName,
247
245
  toolCallId,
248
246
  cause,
@@ -250,7 +248,7 @@ var ToolExecutionError = class extends AISDKError10 {
250
248
  }) {
251
249
  super({ name: name10, message, cause });
252
250
  this[_a10] = true;
253
- this.toolArgs = toolArgs;
251
+ this.toolInput = toolInput;
254
252
  this.toolName = toolName;
255
253
  this.toolCallId = toolCallId;
256
254
  }
@@ -455,42 +453,45 @@ import { parseJsonEventStream } from "@ai-sdk/provider-utils";
455
453
  // src/ui-message-stream/ui-message-stream-parts.ts
456
454
  import { z } from "zod";
457
455
  var uiMessageStreamPartSchema = z.union([
458
- z.object({
456
+ z.strictObject({
459
457
  type: z.literal("text"),
460
458
  text: z.string()
461
459
  }),
462
- z.object({
460
+ z.strictObject({
463
461
  type: z.literal("error"),
464
462
  errorText: z.string()
465
463
  }),
466
- z.object({
467
- type: z.literal("tool-call-streaming-start"),
464
+ z.strictObject({
465
+ type: z.literal("tool-input-start"),
468
466
  toolCallId: z.string(),
469
467
  toolName: z.string()
470
468
  }),
471
- z.object({
472
- type: z.literal("tool-call-delta"),
469
+ z.strictObject({
470
+ type: z.literal("tool-input-delta"),
473
471
  toolCallId: z.string(),
474
- argsTextDelta: z.string()
472
+ inputTextDelta: z.string()
475
473
  }),
476
- z.object({
477
- type: z.literal("tool-call"),
474
+ z.strictObject({
475
+ type: z.literal("tool-input-available"),
478
476
  toolCallId: z.string(),
479
477
  toolName: z.string(),
480
- args: z.unknown()
478
+ input: z.unknown()
481
479
  }),
482
- z.object({
483
- type: z.literal("tool-result"),
480
+ z.strictObject({
481
+ type: z.literal("tool-output-available"),
484
482
  toolCallId: z.string(),
485
- result: z.unknown(),
483
+ output: z.unknown(),
486
484
  providerMetadata: z.any().optional()
487
485
  }),
488
- z.object({
486
+ z.strictObject({
489
487
  type: z.literal("reasoning"),
490
488
  text: z.string(),
491
489
  providerMetadata: z.record(z.any()).optional()
492
490
  }),
493
- z.object({
491
+ z.strictObject({
492
+ type: z.literal("reasoning-part-finish")
493
+ }),
494
+ z.strictObject({
494
495
  type: z.literal("source-url"),
495
496
  sourceId: z.string(),
496
497
  url: z.string(),
@@ -498,7 +499,7 @@ var uiMessageStreamPartSchema = z.union([
498
499
  providerMetadata: z.any().optional()
499
500
  // Use z.any() for generic metadata
500
501
  }),
501
- z.object({
502
+ z.strictObject({
502
503
  type: z.literal("source-document"),
503
504
  sourceId: z.string(),
504
505
  mediaType: z.string(),
@@ -507,39 +508,34 @@ var uiMessageStreamPartSchema = z.union([
507
508
  providerMetadata: z.any().optional()
508
509
  // Use z.any() for generic metadata
509
510
  }),
510
- z.object({
511
+ z.strictObject({
511
512
  type: z.literal("file"),
512
513
  url: z.string(),
513
514
  mediaType: z.string()
514
515
  }),
515
- z.object({
516
+ z.strictObject({
516
517
  type: z.string().startsWith("data-"),
517
518
  id: z.string().optional(),
518
519
  data: z.unknown()
519
520
  }),
520
- z.object({
521
- type: z.literal("metadata"),
522
- value: z.object({ metadata: z.unknown() })
523
- }),
524
- z.object({
525
- type: z.literal("start-step"),
526
- metadata: z.unknown().optional()
521
+ z.strictObject({
522
+ type: z.literal("start-step")
527
523
  }),
528
- z.object({
529
- type: z.literal("finish-step"),
530
- metadata: z.unknown().optional()
524
+ z.strictObject({
525
+ type: z.literal("finish-step")
531
526
  }),
532
- z.object({
527
+ z.strictObject({
533
528
  type: z.literal("start"),
534
529
  messageId: z.string().optional(),
535
- metadata: z.unknown().optional()
530
+ messageMetadata: z.unknown().optional()
536
531
  }),
537
- z.object({
532
+ z.strictObject({
538
533
  type: z.literal("finish"),
539
- metadata: z.unknown().optional()
534
+ messageMetadata: z.unknown().optional()
540
535
  }),
541
- z.object({
542
- type: z.literal("reasoning-part-finish")
536
+ z.strictObject({
537
+ type: z.literal("message-metadata"),
538
+ messageMetadata: z.unknown()
543
539
  })
544
540
  ]);
545
541
  function isDataUIMessageStreamPart(part) {
@@ -1235,27 +1231,26 @@ async function parsePartialJson(jsonText) {
1235
1231
  return { value: void 0, state: "failed-parse" };
1236
1232
  }
1237
1233
 
1238
- // src/ui/get-tool-invocations.ts
1239
- function getToolInvocations(message) {
1240
- return message.parts.filter(
1241
- (part) => part.type === "tool-invocation"
1242
- ).map((part) => part.toolInvocation);
1234
+ // src/ui/ui-messages.ts
1235
+ function isToolUIPart(part) {
1236
+ return part.type.startsWith("tool-");
1237
+ }
1238
+ function getToolName(part) {
1239
+ return part.type.split("-")[1];
1243
1240
  }
1244
1241
 
1245
1242
  // src/ui/process-ui-message-stream.ts
1246
1243
  function createStreamingUIMessageState({
1247
1244
  lastMessage,
1248
- newMessageId = ""
1249
- } = {}) {
1250
- const isContinuation = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
1251
- const message = isContinuation ? lastMessage : {
1252
- id: newMessageId,
1253
- metadata: {},
1254
- role: "assistant",
1255
- parts: []
1256
- };
1245
+ messageId
1246
+ }) {
1257
1247
  return {
1258
- message,
1248
+ message: (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage : {
1249
+ id: messageId,
1250
+ metadata: void 0,
1251
+ role: "assistant",
1252
+ parts: []
1253
+ },
1259
1254
  activeTextPart: void 0,
1260
1255
  activeReasoningPart: void 0,
1261
1256
  partialToolCalls: {}
@@ -1272,16 +1267,21 @@ function processUIMessageStream({
1272
1267
  new TransformStream({
1273
1268
  async transform(part, controller) {
1274
1269
  await runUpdateMessageJob(async ({ state, write }) => {
1275
- function updateToolInvocationPart(toolCallId, invocation) {
1270
+ function updateToolInvocationPart(options) {
1276
1271
  const part2 = state.message.parts.find(
1277
- (part3) => isToolInvocationUIPart(part3) && part3.toolInvocation.toolCallId === toolCallId
1272
+ (part3) => isToolUIPart(part3) && part3.toolCallId === options.toolCallId
1278
1273
  );
1279
1274
  if (part2 != null) {
1280
- part2.toolInvocation = invocation;
1275
+ part2.state = options.state;
1276
+ part2.input = options.input;
1277
+ part2.output = options.output;
1281
1278
  } else {
1282
1279
  state.message.parts.push({
1283
- type: "tool-invocation",
1284
- toolInvocation: invocation
1280
+ type: `tool-${options.toolName}`,
1281
+ toolCallId: options.toolCallId,
1282
+ state: options.state,
1283
+ input: options.input,
1284
+ output: options.output
1285
1285
  });
1286
1286
  }
1287
1287
  }
@@ -1364,43 +1364,43 @@ function processUIMessageStream({
1364
1364
  write();
1365
1365
  break;
1366
1366
  }
1367
- case "tool-call-streaming-start": {
1368
- const toolInvocations = getToolInvocations(state.message);
1367
+ case "tool-input-start": {
1368
+ const toolInvocations = state.message.parts.filter(isToolUIPart);
1369
1369
  state.partialToolCalls[part.toolCallId] = {
1370
1370
  text: "",
1371
1371
  toolName: part.toolName,
1372
1372
  index: toolInvocations.length
1373
1373
  };
1374
- updateToolInvocationPart(part.toolCallId, {
1375
- state: "partial-call",
1374
+ updateToolInvocationPart({
1376
1375
  toolCallId: part.toolCallId,
1377
1376
  toolName: part.toolName,
1378
- args: void 0
1377
+ state: "input-streaming",
1378
+ input: void 0
1379
1379
  });
1380
1380
  write();
1381
1381
  break;
1382
1382
  }
1383
- case "tool-call-delta": {
1383
+ case "tool-input-delta": {
1384
1384
  const partialToolCall = state.partialToolCalls[part.toolCallId];
1385
- partialToolCall.text += part.argsTextDelta;
1385
+ partialToolCall.text += part.inputTextDelta;
1386
1386
  const { value: partialArgs } = await parsePartialJson(
1387
1387
  partialToolCall.text
1388
1388
  );
1389
- updateToolInvocationPart(part.toolCallId, {
1390
- state: "partial-call",
1389
+ updateToolInvocationPart({
1391
1390
  toolCallId: part.toolCallId,
1392
1391
  toolName: partialToolCall.toolName,
1393
- args: partialArgs
1392
+ state: "input-streaming",
1393
+ input: partialArgs
1394
1394
  });
1395
1395
  write();
1396
1396
  break;
1397
1397
  }
1398
- case "tool-call": {
1399
- updateToolInvocationPart(part.toolCallId, {
1400
- state: "call",
1398
+ case "tool-input-available": {
1399
+ updateToolInvocationPart({
1401
1400
  toolCallId: part.toolCallId,
1402
1401
  toolName: part.toolName,
1403
- args: part.args
1402
+ state: "input-available",
1403
+ input: part.input
1404
1404
  });
1405
1405
  write();
1406
1406
  if (onToolCall) {
@@ -1408,20 +1408,20 @@ function processUIMessageStream({
1408
1408
  toolCall: part
1409
1409
  });
1410
1410
  if (result != null) {
1411
- updateToolInvocationPart(part.toolCallId, {
1412
- state: "result",
1411
+ updateToolInvocationPart({
1413
1412
  toolCallId: part.toolCallId,
1414
1413
  toolName: part.toolName,
1415
- args: part.args,
1416
- result
1414
+ state: "output-available",
1415
+ input: part.input,
1416
+ output: result
1417
1417
  });
1418
1418
  write();
1419
1419
  }
1420
1420
  }
1421
1421
  break;
1422
1422
  }
1423
- case "tool-result": {
1424
- const toolInvocations = getToolInvocations(state.message);
1423
+ case "tool-output-available": {
1424
+ const toolInvocations = state.message.parts.filter(isToolUIPart);
1425
1425
  if (toolInvocations == null) {
1426
1426
  throw new Error("tool_result must be preceded by a tool_call");
1427
1427
  }
@@ -1433,49 +1433,48 @@ function processUIMessageStream({
1433
1433
  "tool_result must be preceded by a tool_call with the same toolCallId"
1434
1434
  );
1435
1435
  }
1436
- updateToolInvocationPart(part.toolCallId, {
1437
- ...toolInvocations[toolInvocationIndex],
1438
- state: "result",
1439
- result: part.result
1436
+ const toolName = getToolName(
1437
+ toolInvocations[toolInvocationIndex]
1438
+ );
1439
+ updateToolInvocationPart({
1440
+ toolCallId: part.toolCallId,
1441
+ toolName,
1442
+ state: "output-available",
1443
+ input: toolInvocations[toolInvocationIndex].input,
1444
+ output: part.output
1440
1445
  });
1441
1446
  write();
1442
1447
  break;
1443
1448
  }
1444
1449
  case "start-step": {
1445
1450
  state.message.parts.push({ type: "step-start" });
1446
- await updateMessageMetadata(part.metadata);
1447
- write();
1448
1451
  break;
1449
1452
  }
1450
1453
  case "finish-step": {
1451
1454
  state.activeTextPart = void 0;
1452
1455
  state.activeReasoningPart = void 0;
1453
- await updateMessageMetadata(part.metadata);
1454
- if (part.metadata != null) {
1455
- write();
1456
- }
1457
1456
  break;
1458
1457
  }
1459
1458
  case "start": {
1460
1459
  if (part.messageId != null) {
1461
1460
  state.message.id = part.messageId;
1462
1461
  }
1463
- await updateMessageMetadata(part.metadata);
1464
- if (part.messageId != null || part.metadata != null) {
1462
+ await updateMessageMetadata(part.messageMetadata);
1463
+ if (part.messageId != null || part.messageMetadata != null) {
1465
1464
  write();
1466
1465
  }
1467
1466
  break;
1468
1467
  }
1469
1468
  case "finish": {
1470
- await updateMessageMetadata(part.metadata);
1471
- if (part.metadata != null) {
1469
+ await updateMessageMetadata(part.messageMetadata);
1470
+ if (part.messageMetadata != null) {
1472
1471
  write();
1473
1472
  }
1474
1473
  break;
1475
1474
  }
1476
- case "metadata": {
1477
- await updateMessageMetadata(part.metadata);
1478
- if (part.metadata != null) {
1475
+ case "message-metadata": {
1476
+ await updateMessageMetadata(part.messageMetadata);
1477
+ if (part.messageMetadata != null) {
1479
1478
  write();
1480
1479
  }
1481
1480
  break;
@@ -1503,9 +1502,6 @@ function processUIMessageStream({
1503
1502
  })
1504
1503
  );
1505
1504
  }
1506
- function isToolInvocationUIPart(part) {
1507
- return part.type === "tool-invocation";
1508
- }
1509
1505
  function isObject(value) {
1510
1506
  return typeof value === "object" && value !== null;
1511
1507
  }
@@ -1540,8 +1536,8 @@ function isAssistantMessageWithCompletedToolCalls(message) {
1540
1536
  const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
1541
1537
  return part.type === "step-start" ? index : lastIndex;
1542
1538
  }, -1);
1543
- const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter((part) => part.type === "tool-invocation");
1544
- return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "result" in part.toolInvocation);
1539
+ const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
1540
+ return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
1545
1541
  }
1546
1542
 
1547
1543
  // src/ui/chat.ts
@@ -1615,13 +1611,13 @@ var AbstractChat = class {
1615
1611
  };
1616
1612
  this.addToolResult = async ({
1617
1613
  toolCallId,
1618
- result
1614
+ output
1619
1615
  }) => {
1620
1616
  this.jobExecutor.run(async () => {
1621
- updateToolCallResult({
1617
+ updateToolOutput({
1622
1618
  messages: this.state.messages,
1623
1619
  toolCallId,
1624
- toolResult: result
1620
+ output
1625
1621
  });
1626
1622
  this.messages = this.state.messages;
1627
1623
  if (this.status === "submitted" || this.status === "streaming") {
@@ -1644,7 +1640,6 @@ var AbstractChat = class {
1644
1640
  return;
1645
1641
  if ((_a17 = this.activeResponse) == null ? void 0 : _a17.abortController) {
1646
1642
  this.activeResponse.abortController.abort();
1647
- this.activeResponse.abortController = void 0;
1648
1643
  }
1649
1644
  };
1650
1645
  this.id = id;
@@ -1705,7 +1700,7 @@ var AbstractChat = class {
1705
1700
  const activeResponse = {
1706
1701
  state: createStreamingUIMessageState({
1707
1702
  lastMessage: this.state.snapshot(lastMessage),
1708
- newMessageId: this.generateId()
1703
+ messageId: this.generateId()
1709
1704
  }),
1710
1705
  abortController: new AbortController()
1711
1706
  };
@@ -1782,23 +1777,20 @@ var AbstractChat = class {
1782
1777
  }
1783
1778
  }
1784
1779
  };
1785
- function updateToolCallResult({
1780
+ function updateToolOutput({
1786
1781
  messages,
1787
1782
  toolCallId,
1788
- toolResult: result
1783
+ output
1789
1784
  }) {
1790
1785
  const lastMessage = messages[messages.length - 1];
1791
- const invocationPart = lastMessage.parts.find(
1792
- (part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId
1786
+ const toolPart = lastMessage.parts.find(
1787
+ (part) => isToolUIPart(part) && part.toolCallId === toolCallId
1793
1788
  );
1794
- if (invocationPart == null) {
1789
+ if (toolPart == null) {
1795
1790
  return;
1796
1791
  }
1797
- invocationPart.toolInvocation = {
1798
- ...invocationPart.toolInvocation,
1799
- state: "result",
1800
- result
1801
- };
1792
+ toolPart.state = "output-available";
1793
+ toolPart.output = output;
1802
1794
  }
1803
1795
 
1804
1796
  // src/ui/convert-to-model-messages.ts
@@ -1839,75 +1831,71 @@ function convertToModelMessages(messages, options) {
1839
1831
  }
1840
1832
  const content = [];
1841
1833
  for (const part of block) {
1842
- switch (part.type) {
1843
- case "text": {
1844
- content.push(part);
1845
- break;
1846
- }
1847
- case "file": {
1848
- content.push({
1849
- type: "file",
1850
- mediaType: part.mediaType,
1851
- data: part.url
1852
- });
1853
- break;
1854
- }
1855
- case "reasoning": {
1856
- content.push({
1857
- type: "reasoning",
1858
- text: part.text,
1859
- providerOptions: part.providerMetadata
1834
+ if (part.type === "text") {
1835
+ content.push(part);
1836
+ } else if (part.type === "file") {
1837
+ content.push({
1838
+ type: "file",
1839
+ mediaType: part.mediaType,
1840
+ data: part.url
1841
+ });
1842
+ } else if (part.type === "reasoning") {
1843
+ content.push({
1844
+ type: "reasoning",
1845
+ text: part.text,
1846
+ providerOptions: part.providerMetadata
1847
+ });
1848
+ } else if (isToolUIPart(part)) {
1849
+ const toolName = getToolName(part);
1850
+ if (part.state === "input-streaming") {
1851
+ throw new MessageConversionError({
1852
+ originalMessage: message,
1853
+ message: `incomplete tool input is not supported: ${part.toolCallId}`
1860
1854
  });
1861
- break;
1862
- }
1863
- case "tool-invocation":
1855
+ } else {
1864
1856
  content.push({
1865
1857
  type: "tool-call",
1866
- toolCallId: part.toolInvocation.toolCallId,
1867
- toolName: part.toolInvocation.toolName,
1868
- args: part.toolInvocation.args
1858
+ toolCallId: part.toolCallId,
1859
+ toolName,
1860
+ input: part.input
1869
1861
  });
1870
- break;
1871
- default: {
1872
- const _exhaustiveCheck = part;
1873
- throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
1874
1862
  }
1863
+ } else {
1864
+ const _exhaustiveCheck = part;
1865
+ throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
1875
1866
  }
1876
1867
  }
1877
1868
  modelMessages.push({
1878
1869
  role: "assistant",
1879
1870
  content
1880
1871
  });
1881
- const stepInvocations = block.filter(
1882
- (part) => part.type === "tool-invocation"
1883
- ).map((part) => part.toolInvocation);
1884
- if (stepInvocations.length > 0) {
1872
+ const toolParts = block.filter(isToolUIPart);
1873
+ if (toolParts.length > 0) {
1885
1874
  modelMessages.push({
1886
1875
  role: "tool",
1887
- content: stepInvocations.map(
1888
- (toolInvocation) => {
1889
- if (!("result" in toolInvocation)) {
1890
- throw new MessageConversionError({
1891
- originalMessage: message,
1892
- message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
1893
- });
1894
- }
1895
- const { toolCallId, toolName, result } = toolInvocation;
1896
- const tool2 = tools[toolName];
1897
- return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
1898
- type: "tool-result",
1899
- toolCallId,
1900
- toolName,
1901
- result: tool2.experimental_toToolResultContent(result),
1902
- experimental_content: tool2.experimental_toToolResultContent(result)
1903
- } : {
1904
- type: "tool-result",
1905
- toolCallId,
1906
- toolName,
1907
- result
1908
- };
1876
+ content: toolParts.map((toolPart) => {
1877
+ if (toolPart.state !== "output-available") {
1878
+ throw new MessageConversionError({
1879
+ originalMessage: message,
1880
+ message: "ToolInvocation must have a result: " + JSON.stringify(toolPart)
1881
+ });
1909
1882
  }
1910
- )
1883
+ const toolName = getToolName(toolPart);
1884
+ const { toolCallId, output } = toolPart;
1885
+ const tool2 = tools[toolName];
1886
+ return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
1887
+ type: "tool-result",
1888
+ toolCallId,
1889
+ toolName,
1890
+ output: tool2.experimental_toToolResultContent(output),
1891
+ experimental_content: tool2.experimental_toToolResultContent(output)
1892
+ } : {
1893
+ type: "tool-result",
1894
+ toolCallId,
1895
+ toolName,
1896
+ output
1897
+ };
1898
+ })
1911
1899
  });
1912
1900
  }
1913
1901
  block = [];
@@ -1915,18 +1903,10 @@ function convertToModelMessages(messages, options) {
1915
1903
  var processBlock = processBlock2;
1916
1904
  let block = [];
1917
1905
  for (const part of message.parts) {
1918
- switch (part.type) {
1919
- case "text":
1920
- case "reasoning":
1921
- case "file":
1922
- case "tool-invocation": {
1923
- block.push(part);
1924
- break;
1925
- }
1926
- case "step-start": {
1927
- processBlock2();
1928
- break;
1929
- }
1906
+ if (part.type === "text" || part.type === "reasoning" || part.type === "file" || isToolUIPart(part)) {
1907
+ block.push(part);
1908
+ } else if (part.type === "step-start") {
1909
+ processBlock2();
1930
1910
  }
1931
1911
  }
1932
1912
  processBlock2();
@@ -2056,9 +2036,14 @@ var TextStreamChatTransport = class {
2056
2036
  }
2057
2037
  };
2058
2038
 
2039
+ // src/ui-message-stream/create-ui-message-stream.ts
2040
+ import {
2041
+ generateId as generateIdFunc2
2042
+ } from "@ai-sdk/provider-utils";
2043
+
2059
2044
  // src/ui-message-stream/handle-ui-message-stream-finish.ts
2060
2045
  function handleUIMessageStreamFinish({
2061
- newMessageId,
2046
+ messageId,
2062
2047
  originalMessages = [],
2063
2048
  onFinish,
2064
2049
  stream
@@ -2066,19 +2051,30 @@ function handleUIMessageStreamFinish({
2066
2051
  if (onFinish == null) {
2067
2052
  return stream;
2068
2053
  }
2069
- const lastMessage = originalMessages[originalMessages.length - 1];
2070
- const isContinuation = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
2071
- const messageId = isContinuation ? lastMessage.id : newMessageId;
2054
+ const lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
2072
2055
  const state = createStreamingUIMessageState({
2073
- lastMessage: structuredClone(lastMessage),
2074
- newMessageId: messageId
2056
+ lastMessage: lastMessage ? structuredClone(lastMessage) : void 0,
2057
+ messageId
2058
+ // will be overridden by the stream
2075
2059
  });
2076
2060
  const runUpdateMessageJob = async (job) => {
2077
2061
  await job({ state, write: () => {
2078
2062
  } });
2079
2063
  };
2080
2064
  return processUIMessageStream({
2081
- stream,
2065
+ stream: stream.pipeThrough(
2066
+ new TransformStream({
2067
+ transform(chunk, controller) {
2068
+ if (chunk.type === "start") {
2069
+ const startChunk = chunk;
2070
+ if (startChunk.messageId == null) {
2071
+ startChunk.messageId = messageId;
2072
+ }
2073
+ }
2074
+ controller.enqueue(chunk);
2075
+ }
2076
+ })
2077
+ ),
2082
2078
  runUpdateMessageJob
2083
2079
  }).pipeThrough(
2084
2080
  new TransformStream({
@@ -2086,12 +2082,12 @@ function handleUIMessageStreamFinish({
2086
2082
  controller.enqueue(chunk);
2087
2083
  },
2088
2084
  flush() {
2089
- const isContinuation2 = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
2085
+ const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
2090
2086
  onFinish({
2091
- isContinuation: isContinuation2,
2087
+ isContinuation,
2092
2088
  responseMessage: state.message,
2093
2089
  messages: [
2094
- ...isContinuation2 ? originalMessages.slice(0, -1) : originalMessages,
2090
+ ...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
2095
2091
  state.message
2096
2092
  ]
2097
2093
  });
@@ -2106,7 +2102,8 @@ function createUIMessageStream({
2106
2102
  onError = () => "An error occurred.",
2107
2103
  // mask error messages for safety by default
2108
2104
  originalMessages,
2109
- onFinish
2105
+ onFinish,
2106
+ generateId: generateId3 = generateIdFunc2
2110
2107
  }) {
2111
2108
  let controller;
2112
2109
  const ongoingStreamPromises = [];
@@ -2178,7 +2175,7 @@ function createUIMessageStream({
2178
2175
  });
2179
2176
  return handleUIMessageStreamFinish({
2180
2177
  stream,
2181
- newMessageId: "",
2178
+ messageId: generateId3(),
2182
2179
  originalMessages,
2183
2180
  onFinish
2184
2181
  });
@@ -3444,7 +3441,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
3444
3441
  type: "tool-call",
3445
3442
  toolCallId: part.toolCallId,
3446
3443
  toolName: part.toolName,
3447
- args: part.args,
3444
+ input: part.input,
3448
3445
  providerOptions
3449
3446
  };
3450
3447
  }
@@ -3460,7 +3457,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
3460
3457
  type: "tool-result",
3461
3458
  toolCallId: part.toolCallId,
3462
3459
  toolName: part.toolName,
3463
- result: part.result,
3460
+ output: part.output,
3464
3461
  content: part.experimental_content,
3465
3462
  isError: part.isError,
3466
3463
  providerOptions: part.providerOptions
@@ -3747,14 +3744,14 @@ var toolCallPartSchema = z6.object({
3747
3744
  type: z6.literal("tool-call"),
3748
3745
  toolCallId: z6.string(),
3749
3746
  toolName: z6.string(),
3750
- args: z6.unknown(),
3747
+ input: z6.unknown(),
3751
3748
  providerOptions: providerMetadataSchema.optional()
3752
3749
  });
3753
3750
  var toolResultPartSchema = z6.object({
3754
3751
  type: z6.literal("tool-result"),
3755
3752
  toolCallId: z6.string(),
3756
3753
  toolName: z6.string(),
3757
- result: z6.unknown(),
3754
+ output: z6.unknown(),
3758
3755
  content: toolResultContentSchema.optional(),
3759
3756
  isError: z6.boolean().optional(),
3760
3757
  providerOptions: providerMetadataSchema.optional()
@@ -5360,11 +5357,18 @@ function prepareToolsAndToolChoice({
5360
5357
  type: "function",
5361
5358
  name: name17,
5362
5359
  description: tool2.description,
5363
- parameters: asSchema2(tool2.parameters).jsonSchema
5360
+ inputSchema: asSchema2(tool2.inputSchema).jsonSchema
5364
5361
  };
5365
- case "provider-defined":
5362
+ case "provider-defined-client":
5366
5363
  return {
5367
- type: "provider-defined",
5364
+ type: "provider-defined-client",
5365
+ name: name17,
5366
+ id: tool2.id,
5367
+ args: tool2.args
5368
+ };
5369
+ case "provider-defined-server":
5370
+ return {
5371
+ type: "provider-defined-server",
5368
5372
  name: name17,
5369
5373
  id: tool2.id,
5370
5374
  args: tool2.args
@@ -5448,7 +5452,7 @@ async function parseToolCall({
5448
5452
  try {
5449
5453
  return await doParseToolCall({ toolCall, tools });
5450
5454
  } catch (error) {
5451
- if (repairToolCall == null || !(NoSuchToolError.isInstance(error) || InvalidToolArgumentsError.isInstance(error))) {
5455
+ if (repairToolCall == null || !(NoSuchToolError.isInstance(error) || InvalidToolInputError.isInstance(error))) {
5452
5456
  throw error;
5453
5457
  }
5454
5458
  let repairedToolCall = null;
@@ -5456,9 +5460,9 @@ async function parseToolCall({
5456
5460
  repairedToolCall = await repairToolCall({
5457
5461
  toolCall,
5458
5462
  tools,
5459
- parameterSchema: ({ toolName }) => {
5460
- const { parameters } = tools[toolName];
5461
- return asSchema3(parameters).jsonSchema;
5463
+ inputSchema: ({ toolName }) => {
5464
+ const { inputSchema } = tools[toolName];
5465
+ return asSchema3(inputSchema).jsonSchema;
5462
5466
  },
5463
5467
  system,
5464
5468
  messages,
@@ -5488,12 +5492,12 @@ async function doParseToolCall({
5488
5492
  availableTools: Object.keys(tools)
5489
5493
  });
5490
5494
  }
5491
- const schema = asSchema3(tool2.parameters);
5492
- const parseResult = toolCall.args.trim() === "" ? await safeValidateTypes3({ value: {}, schema }) : await safeParseJSON3({ text: toolCall.args, schema });
5495
+ const schema = asSchema3(tool2.inputSchema);
5496
+ const parseResult = toolCall.input.trim() === "" ? await safeValidateTypes3({ value: {}, schema }) : await safeParseJSON3({ text: toolCall.input, schema });
5493
5497
  if (parseResult.success === false) {
5494
- throw new InvalidToolArgumentsError({
5498
+ throw new InvalidToolInputError({
5495
5499
  toolName,
5496
- toolArgs: toolCall.args,
5500
+ toolInput: toolCall.input,
5497
5501
  cause: parseResult.error
5498
5502
  });
5499
5503
  }
@@ -5501,7 +5505,7 @@ async function doParseToolCall({
5501
5505
  type: "tool-call",
5502
5506
  toolCallId: toolCall.toolCallId,
5503
5507
  toolName,
5504
- args: parseResult == null ? void 0 : parseResult.value
5508
+ input: parseResult.value
5505
5509
  };
5506
5510
  }
5507
5511
 
@@ -5604,15 +5608,15 @@ function toResponseMessages({
5604
5608
  type: "tool-result",
5605
5609
  toolCallId: toolResult.toolCallId,
5606
5610
  toolName: toolResult.toolName,
5607
- result: tool2.experimental_toToolResultContent(toolResult.result),
5611
+ output: tool2.experimental_toToolResultContent(toolResult.output),
5608
5612
  experimental_content: tool2.experimental_toToolResultContent(
5609
- toolResult.result
5613
+ toolResult.output
5610
5614
  )
5611
5615
  } : {
5612
5616
  type: "tool-result",
5613
5617
  toolCallId: toolResult.toolCallId,
5614
5618
  toolName: toolResult.toolName,
5615
- result: toolResult.result
5619
+ output: toolResult.output
5616
5620
  };
5617
5621
  });
5618
5622
  if (toolResultContent.length > 0) {
@@ -5918,11 +5922,11 @@ async function executeTools({
5918
5922
  abortSignal
5919
5923
  }) {
5920
5924
  const toolResults = await Promise.all(
5921
- toolCalls.map(async ({ toolCallId, toolName, args }) => {
5925
+ toolCalls.map(async ({ toolCallId, toolName, input }) => {
5922
5926
  const tool2 = tools[toolName];
5923
- if ((tool2 == null ? void 0 : tool2.onArgsAvailable) != null) {
5924
- await tool2.onArgsAvailable({
5925
- args,
5927
+ if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
5928
+ await tool2.onInputAvailable({
5929
+ input,
5926
5930
  toolCallId,
5927
5931
  messages,
5928
5932
  abortSignal
@@ -5942,15 +5946,15 @@ async function executeTools({
5942
5946
  }),
5943
5947
  "ai.toolCall.name": toolName,
5944
5948
  "ai.toolCall.id": toolCallId,
5945
- "ai.toolCall.args": {
5946
- output: () => JSON.stringify(args)
5949
+ "ai.toolCall.input": {
5950
+ output: () => JSON.stringify(input)
5947
5951
  }
5948
5952
  }
5949
5953
  }),
5950
5954
  tracer,
5951
5955
  fn: async (span) => {
5952
5956
  try {
5953
- const result2 = await tool2.execute(args, {
5957
+ const result2 = await tool2.execute(input, {
5954
5958
  toolCallId,
5955
5959
  messages,
5956
5960
  abortSignal
@@ -5973,7 +5977,7 @@ async function executeTools({
5973
5977
  throw new ToolExecutionError({
5974
5978
  toolCallId,
5975
5979
  toolName,
5976
- toolArgs: args,
5980
+ toolInput: input,
5977
5981
  cause: error
5978
5982
  });
5979
5983
  }
@@ -5983,8 +5987,8 @@ async function executeTools({
5983
5987
  type: "tool-result",
5984
5988
  toolCallId,
5985
5989
  toolName,
5986
- args,
5987
- result
5990
+ input,
5991
+ output: result
5988
5992
  };
5989
5993
  })
5990
5994
  );
@@ -6074,7 +6078,7 @@ function asToolCalls(content) {
6074
6078
  toolCallType: toolCall.toolCallType,
6075
6079
  toolCallId: toolCall.toolCallId,
6076
6080
  toolName: toolCall.toolName,
6077
- args: toolCall.args
6081
+ input: toolCall.input
6078
6082
  }));
6079
6083
  }
6080
6084
 
@@ -6302,7 +6306,7 @@ function runToolsTransformation({
6302
6306
  type: "tool-call-delta",
6303
6307
  toolCallId: chunk.toolCallId,
6304
6308
  toolName: chunk.toolName,
6305
- argsTextDelta: chunk.argsTextDelta
6309
+ inputTextDelta: chunk.inputTextDelta
6306
6310
  });
6307
6311
  break;
6308
6312
  }
@@ -6317,9 +6321,9 @@ function runToolsTransformation({
6317
6321
  });
6318
6322
  controller.enqueue(toolCall);
6319
6323
  const tool2 = tools[toolCall.toolName];
6320
- if (tool2.onArgsAvailable != null) {
6321
- await tool2.onArgsAvailable({
6322
- args: toolCall.args,
6324
+ if (tool2.onInputAvailable != null) {
6325
+ await tool2.onInputAvailable({
6326
+ input: toolCall.input,
6323
6327
  toolCallId: toolCall.toolCallId,
6324
6328
  messages,
6325
6329
  abortSignal
@@ -6339,22 +6343,22 @@ function runToolsTransformation({
6339
6343
  }),
6340
6344
  "ai.toolCall.name": toolCall.toolName,
6341
6345
  "ai.toolCall.id": toolCall.toolCallId,
6342
- "ai.toolCall.args": {
6343
- output: () => JSON.stringify(toolCall.args)
6346
+ "ai.toolCall.input": {
6347
+ output: () => JSON.stringify(toolCall.input)
6344
6348
  }
6345
6349
  }
6346
6350
  }),
6347
6351
  tracer,
6348
- fn: async (span) => tool2.execute(toolCall.args, {
6352
+ fn: async (span) => tool2.execute(toolCall.input, {
6349
6353
  toolCallId: toolCall.toolCallId,
6350
6354
  messages,
6351
6355
  abortSignal
6352
6356
  }).then(
6353
- (result) => {
6357
+ (output) => {
6354
6358
  toolResultsStreamController.enqueue({
6355
6359
  ...toolCall,
6356
6360
  type: "tool-result",
6357
- result
6361
+ output
6358
6362
  });
6359
6363
  outstandingToolResults.delete(toolExecutionId);
6360
6364
  attemptClose();
@@ -6363,8 +6367,8 @@ function runToolsTransformation({
6363
6367
  selectTelemetryAttributes({
6364
6368
  telemetry,
6365
6369
  attributes: {
6366
- "ai.toolCall.result": {
6367
- output: () => JSON.stringify(result)
6370
+ "ai.toolCall.output": {
6371
+ output: () => JSON.stringify(output)
6368
6372
  }
6369
6373
  }
6370
6374
  })
@@ -6378,7 +6382,7 @@ function runToolsTransformation({
6378
6382
  error: new ToolExecutionError({
6379
6383
  toolCallId: toolCall.toolCallId,
6380
6384
  toolName: toolCall.toolName,
6381
- toolArgs: toolCall.args,
6385
+ toolInput: toolCall.input,
6382
6386
  cause: error
6383
6387
  })
6384
6388
  });
@@ -6434,6 +6438,18 @@ function runToolsTransformation({
6434
6438
  });
6435
6439
  }
6436
6440
 
6441
+ // src/ui-message-stream/get-response-ui-message-id.ts
6442
+ function getResponseUIMessageId({
6443
+ originalMessages,
6444
+ responseMessageId
6445
+ }) {
6446
+ if (originalMessages == null) {
6447
+ return void 0;
6448
+ }
6449
+ const lastMessage = originalMessages[originalMessages.length - 1];
6450
+ return (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage.id : typeof responseMessageId === "function" ? responseMessageId() : responseMessageId;
6451
+ }
6452
+
6437
6453
  // core/generate-text/stream-text.ts
6438
6454
  var originalGenerateId4 = createIdGenerator4({
6439
6455
  prefix: "aitxt",
@@ -6598,7 +6614,7 @@ var DefaultStreamTextResult = class {
6598
6614
  async transform(chunk, controller) {
6599
6615
  controller.enqueue(chunk);
6600
6616
  const { part } = chunk;
6601
- if (part.type === "text" || part.type === "reasoning" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta") {
6617
+ if (part.type === "text" || part.type === "reasoning" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta" || part.type === "raw") {
6602
6618
  await (onChunk == null ? void 0 : onChunk({ chunk: part }));
6603
6619
  }
6604
6620
  if (part.type === "error") {
@@ -7018,8 +7034,8 @@ var DefaultStreamTextResult = class {
7018
7034
  }
7019
7035
  case "tool-call-streaming-start": {
7020
7036
  const tool2 = tools == null ? void 0 : tools[chunk.toolName];
7021
- if ((tool2 == null ? void 0 : tool2.onArgsStreamingStart) != null) {
7022
- await tool2.onArgsStreamingStart({
7037
+ if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
7038
+ await tool2.onInputStart({
7023
7039
  toolCallId: chunk.toolCallId,
7024
7040
  messages: stepInputMessages,
7025
7041
  abortSignal
@@ -7030,9 +7046,9 @@ var DefaultStreamTextResult = class {
7030
7046
  }
7031
7047
  case "tool-call-delta": {
7032
7048
  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,
7049
+ if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
7050
+ await tool2.onInputDelta({
7051
+ inputTextDelta: chunk.inputTextDelta,
7036
7052
  toolCallId: chunk.toolCallId,
7037
7053
  messages: stepInputMessages,
7038
7054
  abortSignal
@@ -7047,7 +7063,9 @@ var DefaultStreamTextResult = class {
7047
7063
  break;
7048
7064
  }
7049
7065
  case "raw": {
7050
- controller.enqueue(chunk);
7066
+ if (includeRawChunks2) {
7067
+ controller.enqueue(chunk);
7068
+ }
7051
7069
  break;
7052
7070
  }
7053
7071
  default: {
@@ -7270,23 +7288,24 @@ var DefaultStreamTextResult = class {
7270
7288
  );
7271
7289
  }
7272
7290
  toUIMessageStream({
7273
- newMessageId,
7274
- originalMessages = [],
7291
+ originalMessages,
7275
7292
  onFinish,
7276
7293
  messageMetadata,
7277
- sendReasoning = false,
7294
+ sendReasoning = true,
7278
7295
  sendSources = false,
7279
7296
  sendStart = true,
7280
7297
  sendFinish = true,
7281
7298
  onError = () => "An error occurred."
7282
7299
  // mask error messages for safety by default
7283
7300
  } = {}) {
7284
- const lastMessage = originalMessages[originalMessages.length - 1];
7285
- const isContinuation = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
7286
- const messageId = isContinuation ? lastMessage.id : newMessageId;
7301
+ const responseMessageId = getResponseUIMessageId({
7302
+ originalMessages,
7303
+ responseMessageId: this.generateId
7304
+ });
7287
7305
  const baseStream = this.fullStream.pipeThrough(
7288
7306
  new TransformStream({
7289
7307
  transform: async (part, controller) => {
7308
+ const messageMetadataValue = messageMetadata == null ? void 0 : messageMetadata({ part });
7290
7309
  const partType = part.type;
7291
7310
  switch (partType) {
7292
7311
  case "text": {
@@ -7344,7 +7363,7 @@ var DefaultStreamTextResult = class {
7344
7363
  }
7345
7364
  case "tool-call-streaming-start": {
7346
7365
  controller.enqueue({
7347
- type: "tool-call-streaming-start",
7366
+ type: "tool-input-start",
7348
7367
  toolCallId: part.toolCallId,
7349
7368
  toolName: part.toolName
7350
7369
  });
@@ -7352,26 +7371,26 @@ var DefaultStreamTextResult = class {
7352
7371
  }
7353
7372
  case "tool-call-delta": {
7354
7373
  controller.enqueue({
7355
- type: "tool-call-delta",
7374
+ type: "tool-input-delta",
7356
7375
  toolCallId: part.toolCallId,
7357
- argsTextDelta: part.argsTextDelta
7376
+ inputTextDelta: part.inputTextDelta
7358
7377
  });
7359
7378
  break;
7360
7379
  }
7361
7380
  case "tool-call": {
7362
7381
  controller.enqueue({
7363
- type: "tool-call",
7382
+ type: "tool-input-available",
7364
7383
  toolCallId: part.toolCallId,
7365
7384
  toolName: part.toolName,
7366
- args: part.args
7385
+ input: part.input
7367
7386
  });
7368
7387
  break;
7369
7388
  }
7370
7389
  case "tool-result": {
7371
7390
  controller.enqueue({
7372
- type: "tool-result",
7391
+ type: "tool-output-available",
7373
7392
  toolCallId: part.toolCallId,
7374
- result: part.result
7393
+ output: part.output
7375
7394
  });
7376
7395
  break;
7377
7396
  }
@@ -7383,38 +7402,28 @@ var DefaultStreamTextResult = class {
7383
7402
  break;
7384
7403
  }
7385
7404
  case "start-step": {
7386
- const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
7387
- controller.enqueue({
7388
- type: "start-step",
7389
- metadata
7390
- });
7405
+ controller.enqueue({ type: "start-step" });
7391
7406
  break;
7392
7407
  }
7393
7408
  case "finish-step": {
7394
- const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
7395
- controller.enqueue({
7396
- type: "finish-step",
7397
- metadata
7398
- });
7409
+ controller.enqueue({ type: "finish-step" });
7399
7410
  break;
7400
7411
  }
7401
7412
  case "start": {
7402
7413
  if (sendStart) {
7403
- const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
7404
7414
  controller.enqueue({
7405
7415
  type: "start",
7406
- messageId,
7407
- metadata
7416
+ messageId: responseMessageId,
7417
+ messageMetadata: messageMetadataValue
7408
7418
  });
7409
7419
  }
7410
7420
  break;
7411
7421
  }
7412
7422
  case "finish": {
7413
7423
  if (sendFinish) {
7414
- const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
7415
7424
  controller.enqueue({
7416
7425
  type: "finish",
7417
- metadata
7426
+ messageMetadata: messageMetadataValue
7418
7427
  });
7419
7428
  }
7420
7429
  break;
@@ -7427,18 +7436,23 @@ var DefaultStreamTextResult = class {
7427
7436
  throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
7428
7437
  }
7429
7438
  }
7439
+ if (messageMetadataValue != null && partType !== "start" && partType !== "finish") {
7440
+ controller.enqueue({
7441
+ type: "message-metadata",
7442
+ messageMetadata: messageMetadataValue
7443
+ });
7444
+ }
7430
7445
  }
7431
7446
  })
7432
7447
  );
7433
7448
  return handleUIMessageStreamFinish({
7434
7449
  stream: baseStream,
7435
- newMessageId: messageId != null ? messageId : this.generateId(),
7450
+ messageId: responseMessageId != null ? responseMessageId : this.generateId(),
7436
7451
  originalMessages,
7437
7452
  onFinish
7438
7453
  });
7439
7454
  }
7440
7455
  pipeUIMessageStreamToResponse(response, {
7441
- newMessageId,
7442
7456
  originalMessages,
7443
7457
  onFinish,
7444
7458
  messageMetadata,
@@ -7452,7 +7466,6 @@ var DefaultStreamTextResult = class {
7452
7466
  pipeUIMessageStreamToResponse({
7453
7467
  response,
7454
7468
  stream: this.toUIMessageStream({
7455
- newMessageId,
7456
7469
  originalMessages,
7457
7470
  onFinish,
7458
7471
  messageMetadata,
@@ -7473,7 +7486,6 @@ var DefaultStreamTextResult = class {
7473
7486
  });
7474
7487
  }
7475
7488
  toUIMessageStreamResponse({
7476
- newMessageId,
7477
7489
  originalMessages,
7478
7490
  onFinish,
7479
7491
  messageMetadata,
@@ -7486,7 +7498,6 @@ var DefaultStreamTextResult = class {
7486
7498
  } = {}) {
7487
7499
  return createUIMessageStreamResponse({
7488
7500
  stream: this.toUIMessageStream({
7489
- newMessageId,
7490
7501
  originalMessages,
7491
7502
  onFinish,
7492
7503
  messageMetadata,
@@ -8390,15 +8401,14 @@ var MCPClient = class {
8390
8401
  if (schemas !== "automatic" && !(name17 in schemas)) {
8391
8402
  continue;
8392
8403
  }
8393
- const parameters = schemas === "automatic" ? jsonSchema({
8394
- ...inputSchema,
8395
- properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
8396
- additionalProperties: false
8397
- }) : schemas[name17].parameters;
8398
8404
  const self = this;
8399
8405
  const toolWithExecute = tool({
8400
8406
  description,
8401
- parameters,
8407
+ inputSchema: schemas === "automatic" ? jsonSchema({
8408
+ ...inputSchema,
8409
+ properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
8410
+ additionalProperties: false
8411
+ }) : schemas[name17].inputSchema,
8402
8412
  execute: async (args, options) => {
8403
8413
  var _a18;
8404
8414
  (_a18 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a18.throwIfAborted();
@@ -8530,7 +8540,7 @@ export {
8530
8540
  InvalidPromptError,
8531
8541
  InvalidResponseDataError,
8532
8542
  InvalidStreamPartError,
8533
- InvalidToolArgumentsError,
8543
+ InvalidToolInputError,
8534
8544
  JSONParseError,
8535
8545
  JsonToSseTransformStream,
8536
8546
  LoadAPIKeyError,
@@ -8583,9 +8593,10 @@ export {
8583
8593
  generateObject,
8584
8594
  generateText,
8585
8595
  getTextFromDataUrl,
8586
- getToolInvocations,
8596
+ getToolName,
8587
8597
  hasToolCall,
8588
8598
  isDeepEqualData,
8599
+ isToolUIPart,
8589
8600
  jsonSchema2 as jsonSchema,
8590
8601
  modelMessageSchema,
8591
8602
  parsePartialJson,