ai 5.0.0-canary.14 → 5.0.0-canary.16

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
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name17 in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // index.ts
@@ -61,7 +51,7 @@ __export(ai_exports, {
61
51
  UnsupportedFunctionalityError: () => import_provider21.UnsupportedFunctionalityError,
62
52
  appendClientMessage: () => appendClientMessage,
63
53
  appendResponseMessages: () => appendResponseMessages,
64
- asSchema: () => asSchema,
54
+ asSchema: () => import_provider_utils4.asSchema,
65
55
  callChatApi: () => callChatApi,
66
56
  callCompletionApi: () => callCompletionApi,
67
57
  convertToCoreMessages: () => convertToCoreMessages,
@@ -73,7 +63,7 @@ __export(ai_exports, {
73
63
  cosineSimilarity: () => cosineSimilarity,
74
64
  createDataStream: () => createDataStream,
75
65
  createDataStreamResponse: () => createDataStreamResponse,
76
- createIdGenerator: () => import_provider_utils22.createIdGenerator,
66
+ createIdGenerator: () => import_provider_utils21.createIdGenerator,
77
67
  createProviderRegistry: () => createProviderRegistry,
78
68
  customProvider: () => customProvider,
79
69
  defaultSettingsMiddleware: () => defaultSettingsMiddleware,
@@ -87,16 +77,15 @@ __export(ai_exports, {
87
77
  experimental_transcribe: () => transcribe,
88
78
  extractMaxToolInvocationStep: () => extractMaxToolInvocationStep,
89
79
  extractReasoningMiddleware: () => extractReasoningMiddleware,
90
- fillMessageParts: () => fillMessageParts,
91
80
  formatDataStreamPart: () => formatDataStreamPart,
92
- generateId: () => import_provider_utils22.generateId,
81
+ generateId: () => import_provider_utils21.generateId,
93
82
  generateObject: () => generateObject,
94
83
  generateText: () => generateText,
95
- getMessageParts: () => getMessageParts,
96
84
  getTextFromDataUrl: () => getTextFromDataUrl,
85
+ getToolInvocations: () => getToolInvocations,
97
86
  isAssistantMessageWithCompletedToolCalls: () => isAssistantMessageWithCompletedToolCalls,
98
87
  isDeepEqualData: () => isDeepEqualData,
99
- jsonSchema: () => jsonSchema,
88
+ jsonSchema: () => import_provider_utils4.jsonSchema,
100
89
  parseDataStreamPart: () => parseDataStreamPart,
101
90
  parsePartialJson: () => parsePartialJson,
102
91
  pipeDataStreamToResponse: () => pipeDataStreamToResponse,
@@ -111,16 +100,15 @@ __export(ai_exports, {
111
100
  streamText: () => streamText,
112
101
  tool: () => tool,
113
102
  updateToolCallResult: () => updateToolCallResult,
114
- wrapLanguageModel: () => wrapLanguageModel,
115
- zodSchema: () => zodSchema
103
+ wrapLanguageModel: () => wrapLanguageModel
116
104
  });
117
105
  module.exports = __toCommonJS(ai_exports);
118
106
 
119
107
  // core/index.ts
120
- var import_provider_utils22 = require("@ai-sdk/provider-utils");
108
+ var import_provider_utils21 = require("@ai-sdk/provider-utils");
121
109
 
122
110
  // core/util/index.ts
123
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
111
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
124
112
 
125
113
  // core/util/process-chat-response.ts
126
114
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
@@ -137,6 +125,21 @@ function calculateLanguageModelUsage({
137
125
  };
138
126
  }
139
127
 
128
+ // core/ui/get-tool-invocations.ts
129
+ function getToolInvocations(message) {
130
+ return message.parts.filter(
131
+ (part) => part.type === "tool-invocation"
132
+ ).map((part) => part.toolInvocation);
133
+ }
134
+
135
+ // core/util/extract-max-tool-invocation-step.ts
136
+ function extractMaxToolInvocationStep(toolInvocations) {
137
+ return toolInvocations == null ? void 0 : toolInvocations.reduce((max, toolInvocation) => {
138
+ var _a17;
139
+ return Math.max(max, (_a17 = toolInvocation.step) != null ? _a17 : 0);
140
+ }, 0);
141
+ }
142
+
140
143
  // core/util/parse-partial-json.ts
141
144
  var import_provider_utils = require("@ai-sdk/provider-utils");
142
145
 
@@ -859,13 +862,9 @@ async function processChatResponse({
859
862
  getCurrentDate = () => /* @__PURE__ */ new Date(),
860
863
  lastMessage
861
864
  }) {
862
- var _a17, _b;
865
+ var _a17;
863
866
  const replaceLastMessage = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
864
- let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
865
- ((_b = (_a17 = lastMessage.toolInvocations) == null ? void 0 : _a17.reduce((max, toolInvocation) => {
866
- var _a18;
867
- return Math.max(max, (_a18 = toolInvocation.step) != null ? _a18 : 0);
868
- }, 0)) != null ? _b : 0) : 0;
867
+ let step = replaceLastMessage ? 1 + ((_a17 = extractMaxToolInvocationStep(getToolInvocations(lastMessage))) != null ? _a17 : 0) : 0;
869
868
  const message = replaceLastMessage ? structuredClone(lastMessage) : {
870
869
  id: generateId3(),
871
870
  createdAt: getCurrentDate(),
@@ -935,19 +934,17 @@ async function processChatResponse({
935
934
  execUpdate();
936
935
  },
937
936
  onReasoningPart(value) {
938
- var _a18;
939
937
  if (currentReasoningPart == null) {
940
938
  currentReasoningPart = {
941
939
  type: "reasoning",
942
- reasoning: value.text,
940
+ text: value.text,
943
941
  providerMetadata: value.providerMetadata
944
942
  };
945
943
  message.parts.push(currentReasoningPart);
946
944
  } else {
947
- currentReasoningPart.reasoning += value.text;
945
+ currentReasoningPart.text += value.text;
948
946
  currentReasoningPart.providerMetadata = value.providerMetadata;
949
947
  }
950
- message.reasoning = ((_a18 = message.reasoning) != null ? _a18 : "") + value.text;
951
948
  execUpdate();
952
949
  },
953
950
  onReasoningPartFinish(value) {
@@ -971,24 +968,20 @@ async function processChatResponse({
971
968
  execUpdate();
972
969
  },
973
970
  onToolCallStreamingStartPart(value) {
974
- if (message.toolInvocations == null) {
975
- message.toolInvocations = [];
976
- }
971
+ const toolInvocations = getToolInvocations(message);
977
972
  partialToolCalls[value.toolCallId] = {
978
973
  text: "",
979
974
  step,
980
975
  toolName: value.toolName,
981
- index: message.toolInvocations.length
976
+ index: toolInvocations.length
982
977
  };
983
- const invocation = {
978
+ updateToolInvocationPart(value.toolCallId, {
984
979
  state: "partial-call",
985
980
  step,
986
981
  toolCallId: value.toolCallId,
987
982
  toolName: value.toolName,
988
983
  args: void 0
989
- };
990
- message.toolInvocations.push(invocation);
991
- updateToolInvocationPart(value.toolCallId, invocation);
984
+ });
992
985
  execUpdate();
993
986
  },
994
987
  async onToolCallDeltaPart(value) {
@@ -997,68 +990,53 @@ async function processChatResponse({
997
990
  const { value: partialArgs } = await parsePartialJson(
998
991
  partialToolCall.text
999
992
  );
1000
- const invocation = {
993
+ updateToolInvocationPart(value.toolCallId, {
1001
994
  state: "partial-call",
1002
995
  step: partialToolCall.step,
1003
996
  toolCallId: value.toolCallId,
1004
997
  toolName: partialToolCall.toolName,
1005
998
  args: partialArgs
1006
- };
1007
- message.toolInvocations[partialToolCall.index] = invocation;
1008
- updateToolInvocationPart(value.toolCallId, invocation);
999
+ });
1009
1000
  execUpdate();
1010
1001
  },
1011
1002
  async onToolCallPart(value) {
1012
- const invocation = {
1003
+ updateToolInvocationPart(value.toolCallId, {
1013
1004
  state: "call",
1014
1005
  step,
1015
1006
  ...value
1016
- };
1017
- if (partialToolCalls[value.toolCallId] != null) {
1018
- message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
1019
- } else {
1020
- if (message.toolInvocations == null) {
1021
- message.toolInvocations = [];
1022
- }
1023
- message.toolInvocations.push(invocation);
1024
- }
1025
- updateToolInvocationPart(value.toolCallId, invocation);
1007
+ });
1026
1008
  execUpdate();
1027
1009
  if (onToolCall) {
1028
1010
  const result = await onToolCall({ toolCall: value });
1029
1011
  if (result != null) {
1030
- const invocation2 = {
1012
+ updateToolInvocationPart(value.toolCallId, {
1031
1013
  state: "result",
1032
1014
  step,
1033
1015
  ...value,
1034
1016
  result
1035
- };
1036
- message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
1037
- updateToolInvocationPart(value.toolCallId, invocation2);
1017
+ });
1038
1018
  execUpdate();
1039
1019
  }
1040
1020
  }
1041
1021
  },
1042
1022
  onToolResultPart(value) {
1043
- const toolInvocations = message.toolInvocations;
1023
+ const toolInvocations = getToolInvocations(message);
1044
1024
  if (toolInvocations == null) {
1045
1025
  throw new Error("tool_result must be preceded by a tool_call");
1046
1026
  }
1047
1027
  const toolInvocationIndex = toolInvocations.findIndex(
1048
- (invocation2) => invocation2.toolCallId === value.toolCallId
1028
+ (invocation) => invocation.toolCallId === value.toolCallId
1049
1029
  );
1050
1030
  if (toolInvocationIndex === -1) {
1051
1031
  throw new Error(
1052
1032
  "tool_result must be preceded by a tool_call with the same toolCallId"
1053
1033
  );
1054
1034
  }
1055
- const invocation = {
1035
+ updateToolInvocationPart(value.toolCallId, {
1056
1036
  ...toolInvocations[toolInvocationIndex],
1057
1037
  state: "result",
1058
1038
  ...value
1059
- };
1060
- toolInvocations[toolInvocationIndex] = invocation;
1061
- updateToolInvocationPart(value.toolCallId, invocation);
1039
+ });
1062
1040
  execUpdate();
1063
1041
  },
1064
1042
  onDataPart(value) {
@@ -1354,40 +1332,6 @@ function getTextFromDataUrl(dataUrl) {
1354
1332
  }
1355
1333
  }
1356
1334
 
1357
- // core/util/extract-max-tool-invocation-step.ts
1358
- function extractMaxToolInvocationStep(toolInvocations) {
1359
- return toolInvocations == null ? void 0 : toolInvocations.reduce((max, toolInvocation) => {
1360
- var _a17;
1361
- return Math.max(max, (_a17 = toolInvocation.step) != null ? _a17 : 0);
1362
- }, 0);
1363
- }
1364
-
1365
- // core/util/get-message-parts.ts
1366
- function getMessageParts(message) {
1367
- var _a17;
1368
- return (_a17 = message.parts) != null ? _a17 : [
1369
- ...message.toolInvocations ? message.toolInvocations.map((toolInvocation) => ({
1370
- type: "tool-invocation",
1371
- toolInvocation
1372
- })) : [],
1373
- ...message.reasoning ? [
1374
- {
1375
- type: "reasoning",
1376
- reasoning: message.reasoning
1377
- }
1378
- ] : [],
1379
- ...message.content ? [{ type: "text", text: message.content }] : []
1380
- ];
1381
- }
1382
-
1383
- // core/util/fill-message-parts.ts
1384
- function fillMessageParts(messages) {
1385
- return messages.map((message) => ({
1386
- ...message,
1387
- parts: getMessageParts(message)
1388
- }));
1389
- }
1390
-
1391
1335
  // core/util/is-deep-equal-data.ts
1392
1336
  function isDeepEqualData(obj1, obj2) {
1393
1337
  if (obj1 === obj2)
@@ -1428,7 +1372,7 @@ async function prepareAttachmentsForRequest(attachmentsFromOptions) {
1428
1372
  if (!attachmentsFromOptions) {
1429
1373
  return [];
1430
1374
  }
1431
- if (attachmentsFromOptions instanceof FileList) {
1375
+ if (globalThis.FileList && attachmentsFromOptions instanceof globalThis.FileList) {
1432
1376
  return Promise.all(
1433
1377
  Array.from(attachmentsFromOptions).map(async (attachment) => {
1434
1378
  const { name: name17, type } = attachment;
@@ -1455,52 +1399,25 @@ async function prepareAttachmentsForRequest(attachmentsFromOptions) {
1455
1399
  throw new Error("Invalid attachments type");
1456
1400
  }
1457
1401
 
1458
- // core/util/schema.ts
1459
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
1460
-
1461
- // core/util/zod-schema.ts
1462
- var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
1463
- function zodSchema(zodSchema2, options) {
1464
- var _a17;
1465
- const useReferences = (_a17 = options == null ? void 0 : options.useReferences) != null ? _a17 : false;
1466
- return jsonSchema(
1467
- (0, import_zod_to_json_schema.default)(zodSchema2, {
1468
- $refStrategy: useReferences ? "root" : "none",
1469
- target: "jsonSchema7"
1470
- // note: openai mode breaks various gemini conversions
1471
- }),
1472
- {
1473
- validate: (value) => {
1474
- const result = zodSchema2.safeParse(value);
1475
- return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
1476
- }
1477
- }
1402
+ // core/util/update-tool-call-result.ts
1403
+ function updateToolCallResult({
1404
+ messages,
1405
+ toolCallId,
1406
+ toolResult: result
1407
+ }) {
1408
+ const lastMessage = messages[messages.length - 1];
1409
+ const invocationPart = lastMessage.parts.find(
1410
+ (part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId
1478
1411
  );
1479
- }
1480
-
1481
- // core/util/schema.ts
1482
- var schemaSymbol = Symbol.for("vercel.ai.schema");
1483
- function jsonSchema(jsonSchema2, {
1484
- validate
1485
- } = {}) {
1486
- return {
1487
- [schemaSymbol]: true,
1488
- _type: void 0,
1489
- // should never be used directly
1490
- [import_provider_utils4.validatorSymbol]: true,
1491
- jsonSchema: jsonSchema2,
1492
- validate
1412
+ if (invocationPart == null) {
1413
+ return;
1414
+ }
1415
+ invocationPart.toolInvocation = {
1416
+ ...invocationPart.toolInvocation,
1417
+ state: "result",
1418
+ result
1493
1419
  };
1494
1420
  }
1495
- function isSchema(value) {
1496
- return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
1497
- }
1498
- function asSchema(schema) {
1499
- return schema == null ? jsonSchema({
1500
- properties: {},
1501
- additionalProperties: false
1502
- }) : isSchema(schema) ? schema : zodSchema(schema);
1503
- }
1504
1421
 
1505
1422
  // core/util/should-resubmit-messages.ts
1506
1423
  function shouldResubmitMessages({
@@ -1515,9 +1432,9 @@ function shouldResubmitMessages({
1515
1432
  // check if the feature is enabled:
1516
1433
  maxSteps > 1 && // ensure there is a last message:
1517
1434
  lastMessage != null && // ensure we actually have new steps (to prevent infinite loops in case of errors):
1518
- (messages.length > originalMessageCount || extractMaxToolInvocationStep(lastMessage.toolInvocations) !== originalMaxToolInvocationStep) && // check that next step is possible:
1435
+ (messages.length > originalMessageCount || extractMaxToolInvocationStep(getToolInvocations(lastMessage)) !== originalMaxToolInvocationStep) && // check that next step is possible:
1519
1436
  isAssistantMessageWithCompletedToolCalls(lastMessage) && // limit the number of automatic steps:
1520
- ((_a17 = extractMaxToolInvocationStep(lastMessage.toolInvocations)) != null ? _a17 : 0) < maxSteps
1437
+ ((_a17 = extractMaxToolInvocationStep(getToolInvocations(lastMessage))) != null ? _a17 : 0) < maxSteps
1521
1438
  );
1522
1439
  }
1523
1440
  function isAssistantMessageWithCompletedToolCalls(message) {
@@ -1531,31 +1448,6 @@ function isAssistantMessageWithCompletedToolCalls(message) {
1531
1448
  return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "result" in part.toolInvocation);
1532
1449
  }
1533
1450
 
1534
- // core/util/update-tool-call-result.ts
1535
- function updateToolCallResult({
1536
- messages,
1537
- toolCallId,
1538
- toolResult: result
1539
- }) {
1540
- var _a17;
1541
- const lastMessage = messages[messages.length - 1];
1542
- const invocationPart = lastMessage.parts.find(
1543
- (part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === toolCallId
1544
- );
1545
- if (invocationPart == null) {
1546
- return;
1547
- }
1548
- const toolResult = {
1549
- ...invocationPart.toolInvocation,
1550
- state: "result",
1551
- result
1552
- };
1553
- invocationPart.toolInvocation = toolResult;
1554
- lastMessage.toolInvocations = (_a17 = lastMessage.toolInvocations) == null ? void 0 : _a17.map(
1555
- (toolInvocation) => toolInvocation.toolCallId === toolCallId ? toolResult : toolInvocation
1556
- );
1557
- }
1558
-
1559
1451
  // core/data-stream/create-data-stream.ts
1560
1452
  function createDataStream({
1561
1453
  execute,
@@ -1764,7 +1656,7 @@ _a = symbol;
1764
1656
 
1765
1657
  // util/retry-with-exponential-backoff.ts
1766
1658
  var import_provider3 = require("@ai-sdk/provider");
1767
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1659
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1768
1660
 
1769
1661
  // util/retry-error.ts
1770
1662
  var import_provider2 = require("@ai-sdk/provider");
@@ -1808,13 +1700,13 @@ async function _retryWithExponentialBackoff(f, {
1808
1700
  try {
1809
1701
  return await f();
1810
1702
  } catch (error) {
1811
- if ((0, import_provider_utils6.isAbortError)(error)) {
1703
+ if ((0, import_provider_utils5.isAbortError)(error)) {
1812
1704
  throw error;
1813
1705
  }
1814
1706
  if (maxRetries === 0) {
1815
1707
  throw error;
1816
1708
  }
1817
- const errorMessage = (0, import_provider_utils6.getErrorMessage)(error);
1709
+ const errorMessage = (0, import_provider_utils5.getErrorMessage)(error);
1818
1710
  const newErrors = [...errors, error];
1819
1711
  const tryNumber = newErrors.length;
1820
1712
  if (tryNumber > maxRetries) {
@@ -1825,7 +1717,7 @@ async function _retryWithExponentialBackoff(f, {
1825
1717
  });
1826
1718
  }
1827
1719
  if (error instanceof Error && import_provider3.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
1828
- await (0, import_provider_utils6.delay)(delayInMs);
1720
+ await (0, import_provider_utils5.delay)(delayInMs);
1829
1721
  return _retryWithExponentialBackoff(
1830
1722
  f,
1831
1723
  { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
@@ -2394,7 +2286,7 @@ var NoImageGeneratedError = class extends import_provider4.AISDKError {
2394
2286
  _a3 = symbol3;
2395
2287
 
2396
2288
  // core/generate-text/generated-file.ts
2397
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
2289
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
2398
2290
  var DefaultGeneratedFile = class {
2399
2291
  constructor({
2400
2292
  data,
@@ -2408,14 +2300,14 @@ var DefaultGeneratedFile = class {
2408
2300
  // lazy conversion with caching to avoid unnecessary conversion overhead:
2409
2301
  get base64() {
2410
2302
  if (this.base64Data == null) {
2411
- this.base64Data = (0, import_provider_utils7.convertUint8ArrayToBase64)(this.uint8ArrayData);
2303
+ this.base64Data = (0, import_provider_utils6.convertUint8ArrayToBase64)(this.uint8ArrayData);
2412
2304
  }
2413
2305
  return this.base64Data;
2414
2306
  }
2415
2307
  // lazy conversion with caching to avoid unnecessary conversion overhead:
2416
2308
  get uint8Array() {
2417
2309
  if (this.uint8ArrayData == null) {
2418
- this.uint8ArrayData = (0, import_provider_utils7.convertBase64ToUint8Array)(this.base64Data);
2310
+ this.uint8ArrayData = (0, import_provider_utils6.convertBase64ToUint8Array)(this.base64Data);
2419
2311
  }
2420
2312
  return this.uint8ArrayData;
2421
2313
  }
@@ -2428,7 +2320,7 @@ var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
2428
2320
  };
2429
2321
 
2430
2322
  // core/util/detect-media-type.ts
2431
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
2323
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
2432
2324
  var imageMediaTypeSignatures = [
2433
2325
  {
2434
2326
  mediaType: "image/gif",
@@ -2535,7 +2427,7 @@ var audioMediaTypeSignatures = [
2535
2427
  }
2536
2428
  ];
2537
2429
  var stripID3 = (data) => {
2538
- const bytes = typeof data === "string" ? (0, import_provider_utils8.convertBase64ToUint8Array)(data) : data;
2430
+ const bytes = typeof data === "string" ? (0, import_provider_utils7.convertBase64ToUint8Array)(data) : data;
2539
2431
  const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
2540
2432
  return bytes.slice(id3Size + 10);
2541
2433
  };
@@ -2639,7 +2531,7 @@ var DefaultGenerateImageResult = class {
2639
2531
 
2640
2532
  // core/generate-object/generate-object.ts
2641
2533
  var import_provider13 = require("@ai-sdk/provider");
2642
- var import_provider_utils13 = require("@ai-sdk/provider-utils");
2534
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
2643
2535
 
2644
2536
  // errors/no-object-generated-error.ts
2645
2537
  var import_provider5 = require("@ai-sdk/provider");
@@ -2733,7 +2625,7 @@ async function download({ url }) {
2733
2625
 
2734
2626
  // core/prompt/data-content.ts
2735
2627
  var import_provider8 = require("@ai-sdk/provider");
2736
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2628
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
2737
2629
  var import_zod = require("zod");
2738
2630
 
2739
2631
  // core/prompt/invalid-data-content-error.ts
@@ -2820,9 +2712,9 @@ function convertDataContentToBase64String(content) {
2820
2712
  return content;
2821
2713
  }
2822
2714
  if (content instanceof ArrayBuffer) {
2823
- return (0, import_provider_utils9.convertUint8ArrayToBase64)(new Uint8Array(content));
2715
+ return (0, import_provider_utils8.convertUint8ArrayToBase64)(new Uint8Array(content));
2824
2716
  }
2825
- return (0, import_provider_utils9.convertUint8ArrayToBase64)(content);
2717
+ return (0, import_provider_utils8.convertUint8ArrayToBase64)(content);
2826
2718
  }
2827
2719
  function convertDataContentToUint8Array(content) {
2828
2720
  if (content instanceof Uint8Array) {
@@ -2830,7 +2722,7 @@ function convertDataContentToUint8Array(content) {
2830
2722
  }
2831
2723
  if (typeof content === "string") {
2832
2724
  try {
2833
- return (0, import_provider_utils9.convertBase64ToUint8Array)(content);
2725
+ return (0, import_provider_utils8.convertBase64ToUint8Array)(content);
2834
2726
  } catch (error) {
2835
2727
  throw new InvalidDataContentError({
2836
2728
  message: "Invalid data content. Content string is not a base64-encoded media.",
@@ -2874,7 +2766,7 @@ var InvalidMessageRoleError = class extends import_provider9.AISDKError {
2874
2766
  _a7 = symbol7;
2875
2767
 
2876
2768
  // core/prompt/convert-to-language-model-prompt.ts
2877
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
2769
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
2878
2770
  async function convertToLanguageModelPrompt({
2879
2771
  prompt,
2880
2772
  supportedUrls,
@@ -3011,7 +2903,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
3011
2903
  }
3012
2904
  return { mediaType, data };
3013
2905
  }).filter(
3014
- (part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils10.isUrlSupported)({
2906
+ (part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils9.isUrlSupported)({
3015
2907
  url: part.data.toString(),
3016
2908
  mediaType: part.mediaType,
3017
2909
  supportedUrls
@@ -3182,7 +3074,7 @@ function prepareCallSettings({
3182
3074
 
3183
3075
  // core/prompt/standardize-prompt.ts
3184
3076
  var import_provider11 = require("@ai-sdk/provider");
3185
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
3077
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
3186
3078
  var import_zod7 = require("zod");
3187
3079
 
3188
3080
  // core/prompt/attachments-to-parts.ts
@@ -3344,7 +3236,7 @@ function convertToCoreMessages(messages, options) {
3344
3236
  case "reasoning": {
3345
3237
  content2.push({
3346
3238
  type: "reasoning",
3347
- text: part.reasoning,
3239
+ text: part.text,
3348
3240
  providerOptions: part.providerMetadata
3349
3241
  });
3350
3242
  break;
@@ -3434,73 +3326,11 @@ function convertToCoreMessages(messages, options) {
3434
3326
  processBlock2();
3435
3327
  break;
3436
3328
  }
3437
- const toolInvocations = message.toolInvocations;
3438
- if (toolInvocations == null || toolInvocations.length === 0) {
3439
- coreMessages.push({ role: "assistant", content });
3440
- break;
3441
- }
3442
- const maxStep = toolInvocations.reduce((max, toolInvocation) => {
3443
- var _a18;
3444
- return Math.max(max, (_a18 = toolInvocation.step) != null ? _a18 : 0);
3445
- }, 0);
3446
- for (let i2 = 0; i2 <= maxStep; i2++) {
3447
- const stepInvocations = toolInvocations.filter(
3448
- (toolInvocation) => {
3449
- var _a18;
3450
- return ((_a18 = toolInvocation.step) != null ? _a18 : 0) === i2;
3451
- }
3452
- );
3453
- if (stepInvocations.length === 0) {
3454
- continue;
3455
- }
3456
- coreMessages.push({
3457
- role: "assistant",
3458
- content: [
3459
- ...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
3460
- ...stepInvocations.map(
3461
- ({ toolCallId, toolName, args }) => ({
3462
- type: "tool-call",
3463
- toolCallId,
3464
- toolName,
3465
- args
3466
- })
3467
- )
3468
- ]
3469
- });
3470
- coreMessages.push({
3471
- role: "tool",
3472
- content: stepInvocations.map((toolInvocation) => {
3473
- if (!("result" in toolInvocation)) {
3474
- throw new MessageConversionError({
3475
- originalMessage: message,
3476
- message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
3477
- });
3478
- }
3479
- const { toolCallId, toolName, result } = toolInvocation;
3480
- const tool2 = tools[toolName];
3481
- return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
3482
- type: "tool-result",
3483
- toolCallId,
3484
- toolName,
3485
- result: tool2.experimental_toToolResultContent(result),
3486
- experimental_content: tool2.experimental_toToolResultContent(result)
3487
- } : {
3488
- type: "tool-result",
3489
- toolCallId,
3490
- toolName,
3491
- result
3492
- };
3493
- })
3494
- });
3495
- }
3496
3329
  if (content && !isLastMessage) {
3497
3330
  coreMessages.push({ role: "assistant", content });
3498
3331
  }
3499
3332
  break;
3500
3333
  }
3501
- case "data": {
3502
- break;
3503
- }
3504
3334
  default: {
3505
3335
  const _exhaustiveCheck = role;
3506
3336
  throw new MessageConversionError({
@@ -3731,7 +3561,7 @@ async function standardizePrompt({
3731
3561
  message: "messages must not be empty"
3732
3562
  });
3733
3563
  }
3734
- const validationResult = await (0, import_provider_utils11.safeValidateTypes)({
3564
+ const validationResult = await (0, import_provider_utils10.safeValidateTypes)({
3735
3565
  value: messages,
3736
3566
  schema: import_zod7.z.array(coreMessageSchema)
3737
3567
  });
@@ -3771,7 +3601,7 @@ function addLanguageModelUsage(usage1, usage2) {
3771
3601
 
3772
3602
  // core/generate-object/output-strategy.ts
3773
3603
  var import_provider12 = require("@ai-sdk/provider");
3774
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
3604
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
3775
3605
 
3776
3606
  // core/util/async-iterable-stream.ts
3777
3607
  function createAsyncIterableStream(source) {
@@ -3827,7 +3657,7 @@ var objectOutputStrategy = (schema) => ({
3827
3657
  };
3828
3658
  },
3829
3659
  async validateFinalResult(value) {
3830
- return (0, import_provider_utils12.safeValidateTypes)({ value, schema });
3660
+ return (0, import_provider_utils11.safeValidateTypes)({ value, schema });
3831
3661
  },
3832
3662
  createElementStream() {
3833
3663
  throw new import_provider12.UnsupportedFunctionalityError({
@@ -3871,7 +3701,7 @@ var arrayOutputStrategy = (schema) => {
3871
3701
  const resultArray = [];
3872
3702
  for (let i = 0; i < inputArray.length; i++) {
3873
3703
  const element = inputArray[i];
3874
- const result = await (0, import_provider_utils12.safeValidateTypes)({ value: element, schema });
3704
+ const result = await (0, import_provider_utils11.safeValidateTypes)({ value: element, schema });
3875
3705
  if (i === inputArray.length - 1 && !isFinalDelta) {
3876
3706
  continue;
3877
3707
  }
@@ -3912,7 +3742,7 @@ var arrayOutputStrategy = (schema) => {
3912
3742
  }
3913
3743
  const inputArray = value.elements;
3914
3744
  for (const element of inputArray) {
3915
- const result = await (0, import_provider_utils12.safeValidateTypes)({ value: element, schema });
3745
+ const result = await (0, import_provider_utils11.safeValidateTypes)({ value: element, schema });
3916
3746
  if (!result.success) {
3917
3747
  return result;
3918
3748
  }
@@ -3985,10 +3815,36 @@ var enumOutputStrategy = (enumValues) => {
3985
3815
  })
3986
3816
  };
3987
3817
  },
3988
- validatePartialResult() {
3989
- throw new import_provider12.UnsupportedFunctionalityError({
3990
- functionality: "partial results in enum mode"
3991
- });
3818
+ async validatePartialResult({ value, textDelta }) {
3819
+ if (!(0, import_provider12.isJSONObject)(value) || typeof value.result !== "string") {
3820
+ return {
3821
+ success: false,
3822
+ error: new import_provider12.TypeValidationError({
3823
+ value,
3824
+ cause: 'value must be an object that contains a string in the "result" property.'
3825
+ })
3826
+ };
3827
+ }
3828
+ const result = value.result;
3829
+ const possibleEnumValues = enumValues.filter(
3830
+ (enumValue) => enumValue.startsWith(result)
3831
+ );
3832
+ if (value.result.length === 0 || possibleEnumValues.length === 0) {
3833
+ return {
3834
+ success: false,
3835
+ error: new import_provider12.TypeValidationError({
3836
+ value,
3837
+ cause: "value must be a string in the enum"
3838
+ })
3839
+ };
3840
+ }
3841
+ return {
3842
+ success: true,
3843
+ value: {
3844
+ partial: possibleEnumValues.length > 1 ? result : possibleEnumValues[0],
3845
+ textDelta
3846
+ }
3847
+ };
3992
3848
  },
3993
3849
  createElementStream() {
3994
3850
  throw new import_provider12.UnsupportedFunctionalityError({
@@ -4004,9 +3860,9 @@ function getOutputStrategy({
4004
3860
  }) {
4005
3861
  switch (output) {
4006
3862
  case "object":
4007
- return objectOutputStrategy(asSchema(schema));
3863
+ return objectOutputStrategy((0, import_provider_utils4.asSchema)(schema));
4008
3864
  case "array":
4009
- return arrayOutputStrategy(asSchema(schema));
3865
+ return arrayOutputStrategy((0, import_provider_utils4.asSchema)(schema));
4010
3866
  case "enum":
4011
3867
  return enumOutputStrategy(enumValues);
4012
3868
  case "no-schema":
@@ -4137,7 +3993,7 @@ function validateObjectGenerationInput({
4137
3993
  }
4138
3994
 
4139
3995
  // core/generate-object/generate-object.ts
4140
- var originalGenerateId = (0, import_provider_utils13.createIdGenerator)({ prefix: "aiobj", size: 24 });
3996
+ var originalGenerateId = (0, import_provider_utils12.createIdGenerator)({ prefix: "aiobj", size: 24 });
4141
3997
  async function generateObject(options) {
4142
3998
  const {
4143
3999
  model,
@@ -4220,7 +4076,7 @@ async function generateObject(options) {
4220
4076
  });
4221
4077
  const promptMessages = await convertToLanguageModelPrompt({
4222
4078
  prompt: standardizedPrompt,
4223
- supportedUrls: await model.getSupportedUrls()
4079
+ supportedUrls: await model.supportedUrls
4224
4080
  });
4225
4081
  const generateResult = await retry(
4226
4082
  () => recordSpan({
@@ -4312,7 +4168,7 @@ async function generateObject(options) {
4312
4168
  request = (_a17 = generateResult.request) != null ? _a17 : {};
4313
4169
  response = generateResult.responseData;
4314
4170
  async function processResult(result2) {
4315
- const parseResult = await (0, import_provider_utils13.safeParseJSON)({ text: result2 });
4171
+ const parseResult = await (0, import_provider_utils12.safeParseJSON)({ text: result2 });
4316
4172
  if (!parseResult.success) {
4317
4173
  throw new NoObjectGeneratedError({
4318
4174
  message: "No object generated: could not parse the response.",
@@ -4408,7 +4264,7 @@ var DefaultGenerateObjectResult = class {
4408
4264
  };
4409
4265
 
4410
4266
  // core/generate-object/stream-object.ts
4411
- var import_provider_utils14 = require("@ai-sdk/provider-utils");
4267
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
4412
4268
 
4413
4269
  // util/delayed-promise.ts
4414
4270
  var DelayedPromise = class {
@@ -4552,7 +4408,7 @@ function now() {
4552
4408
  }
4553
4409
 
4554
4410
  // core/generate-object/stream-object.ts
4555
- var originalGenerateId2 = (0, import_provider_utils14.createIdGenerator)({ prefix: "aiobj", size: 24 });
4411
+ var originalGenerateId2 = (0, import_provider_utils13.createIdGenerator)({ prefix: "aiobj", size: 24 });
4556
4412
  function streamObject(options) {
4557
4413
  const {
4558
4414
  model,
@@ -4574,6 +4430,7 @@ function streamObject(options) {
4574
4430
  } = {},
4575
4431
  ...settings
4576
4432
  } = options;
4433
+ const enumValues = "enum" in options && options.enum ? options.enum : void 0;
4577
4434
  const {
4578
4435
  schema: inputSchema,
4579
4436
  schemaDescription,
@@ -4583,9 +4440,14 @@ function streamObject(options) {
4583
4440
  output,
4584
4441
  schema: inputSchema,
4585
4442
  schemaName,
4586
- schemaDescription
4443
+ schemaDescription,
4444
+ enumValues
4445
+ });
4446
+ const outputStrategy = getOutputStrategy({
4447
+ output,
4448
+ schema: inputSchema,
4449
+ enumValues
4587
4450
  });
4588
- const outputStrategy = getOutputStrategy({ output, schema: inputSchema });
4589
4451
  return new DefaultStreamObjectResult({
4590
4452
  model,
4591
4453
  telemetry,
@@ -4693,7 +4555,7 @@ var DefaultStreamObjectResult = class {
4693
4555
  ...prepareCallSettings(settings),
4694
4556
  prompt: await convertToLanguageModelPrompt({
4695
4557
  prompt: standardizedPrompt,
4696
- supportedUrls: await model.getSupportedUrls()
4558
+ supportedUrls: await model.supportedUrls
4697
4559
  }),
4698
4560
  providerOptions,
4699
4561
  abortSignal,
@@ -5047,7 +4909,7 @@ var DefaultStreamObjectResult = class {
5047
4909
  };
5048
4910
 
5049
4911
  // core/generate-text/generate-text.ts
5050
- var import_provider_utils16 = require("@ai-sdk/provider-utils");
4912
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
5051
4913
 
5052
4914
  // errors/no-output-specified-error.ts
5053
4915
  var import_provider14 = require("@ai-sdk/provider");
@@ -5123,7 +4985,7 @@ function prepareToolsAndToolChoice({
5123
4985
  type: "function",
5124
4986
  name: name17,
5125
4987
  description: tool2.description,
5126
- parameters: asSchema(tool2.parameters).jsonSchema
4988
+ parameters: (0, import_provider_utils4.asSchema)(tool2.parameters).jsonSchema
5127
4989
  };
5128
4990
  case "provider-defined":
5129
4991
  return {
@@ -5156,7 +5018,7 @@ function removeTextAfterLastWhitespace(text2) {
5156
5018
  }
5157
5019
 
5158
5020
  // core/generate-text/parse-tool-call.ts
5159
- var import_provider_utils15 = require("@ai-sdk/provider-utils");
5021
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
5160
5022
 
5161
5023
  // errors/invalid-tool-arguments-error.ts
5162
5024
  var import_provider16 = require("@ai-sdk/provider");
@@ -5253,7 +5115,7 @@ async function parseToolCall({
5253
5115
  tools,
5254
5116
  parameterSchema: ({ toolName }) => {
5255
5117
  const { parameters } = tools[toolName];
5256
- return asSchema(parameters).jsonSchema;
5118
+ return (0, import_provider_utils4.asSchema)(parameters).jsonSchema;
5257
5119
  },
5258
5120
  system,
5259
5121
  messages,
@@ -5283,8 +5145,8 @@ async function doParseToolCall({
5283
5145
  availableTools: Object.keys(tools)
5284
5146
  });
5285
5147
  }
5286
- const schema = asSchema(tool2.parameters);
5287
- const parseResult = toolCall.args.trim() === "" ? await (0, import_provider_utils15.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils15.safeParseJSON)({ text: toolCall.args, schema });
5148
+ const schema = (0, import_provider_utils4.asSchema)(tool2.parameters);
5149
+ const parseResult = toolCall.args.trim() === "" ? await (0, import_provider_utils14.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils14.safeParseJSON)({ text: toolCall.args, schema });
5288
5150
  if (parseResult.success === false) {
5289
5151
  throw new InvalidToolArgumentsError({
5290
5152
  toolName,
@@ -5378,11 +5240,11 @@ function toResponseMessages({
5378
5240
  }
5379
5241
 
5380
5242
  // core/generate-text/generate-text.ts
5381
- var originalGenerateId3 = (0, import_provider_utils16.createIdGenerator)({
5243
+ var originalGenerateId3 = (0, import_provider_utils15.createIdGenerator)({
5382
5244
  prefix: "aitxt",
5383
5245
  size: 24
5384
5246
  });
5385
- var originalGenerateMessageId = (0, import_provider_utils16.createIdGenerator)({
5247
+ var originalGenerateMessageId = (0, import_provider_utils15.createIdGenerator)({
5386
5248
  prefix: "msg",
5387
5249
  size: 24
5388
5250
  });
@@ -5487,7 +5349,7 @@ async function generateText({
5487
5349
  system: initialPrompt.system,
5488
5350
  messages: stepInputMessages
5489
5351
  },
5490
- supportedUrls: await model.getSupportedUrls()
5352
+ supportedUrls: await model.supportedUrls
5491
5353
  });
5492
5354
  const stepModel = (_a17 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a17 : model;
5493
5355
  const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
@@ -5867,7 +5729,7 @@ __export(output_exports, {
5867
5729
  object: () => object,
5868
5730
  text: () => text
5869
5731
  });
5870
- var import_provider_utils17 = require("@ai-sdk/provider-utils");
5732
+ var import_provider_utils16 = require("@ai-sdk/provider-utils");
5871
5733
 
5872
5734
  // errors/index.ts
5873
5735
  var import_provider21 = require("@ai-sdk/provider");
@@ -5928,7 +5790,7 @@ var text = () => ({
5928
5790
  var object = ({
5929
5791
  schema: inputSchema
5930
5792
  }) => {
5931
- const schema = asSchema(inputSchema);
5793
+ const schema = (0, import_provider_utils4.asSchema)(inputSchema);
5932
5794
  return {
5933
5795
  type: "object",
5934
5796
  responseFormat: {
@@ -5954,7 +5816,7 @@ var object = ({
5954
5816
  }
5955
5817
  },
5956
5818
  async parseOutput({ text: text2 }, context) {
5957
- const parseResult = await (0, import_provider_utils17.safeParseJSON)({ text: text2 });
5819
+ const parseResult = await (0, import_provider_utils16.safeParseJSON)({ text: text2 });
5958
5820
  if (!parseResult.success) {
5959
5821
  throw new NoObjectGeneratedError({
5960
5822
  message: "No object generated: could not parse the response.",
@@ -5965,7 +5827,7 @@ var object = ({
5965
5827
  finishReason: context.finishReason
5966
5828
  });
5967
5829
  }
5968
- const validationResult = await (0, import_provider_utils17.safeValidateTypes)({
5830
+ const validationResult = await (0, import_provider_utils16.safeValidateTypes)({
5969
5831
  value: parseResult.value,
5970
5832
  schema
5971
5833
  });
@@ -5985,7 +5847,7 @@ var object = ({
5985
5847
  };
5986
5848
 
5987
5849
  // core/generate-text/smooth-stream.ts
5988
- var import_provider_utils18 = require("@ai-sdk/provider-utils");
5850
+ var import_provider_utils17 = require("@ai-sdk/provider-utils");
5989
5851
  var import_provider22 = require("@ai-sdk/provider");
5990
5852
  var CHUNKING_REGEXPS = {
5991
5853
  word: /\S+\s+/m,
@@ -5994,7 +5856,7 @@ var CHUNKING_REGEXPS = {
5994
5856
  function smoothStream({
5995
5857
  delayInMs = 10,
5996
5858
  chunking = "word",
5997
- _internal: { delay: delay2 = import_provider_utils18.delay } = {}
5859
+ _internal: { delay: delay2 = import_provider_utils17.delay } = {}
5998
5860
  } = {}) {
5999
5861
  let detectChunk;
6000
5862
  if (typeof chunking === "function") {
@@ -6054,7 +5916,7 @@ function smoothStream({
6054
5916
  }
6055
5917
 
6056
5918
  // core/generate-text/stream-text.ts
6057
- var import_provider_utils19 = require("@ai-sdk/provider-utils");
5919
+ var import_provider_utils18 = require("@ai-sdk/provider-utils");
6058
5920
 
6059
5921
  // util/as-array.ts
6060
5922
  function asArray(value) {
@@ -6253,7 +6115,7 @@ function runToolsTransformation({
6253
6115
  controller.enqueue(toolCall);
6254
6116
  const tool2 = tools[toolCall.toolName];
6255
6117
  if (tool2.execute != null) {
6256
- const toolExecutionId = (0, import_provider_utils5.generateId)();
6118
+ const toolExecutionId = (0, import_provider_utils4.generateId)();
6257
6119
  outstandingToolResults.add(toolExecutionId);
6258
6120
  recordSpan({
6259
6121
  name: "ai.toolCall",
@@ -6371,11 +6233,11 @@ function runToolsTransformation({
6371
6233
  }
6372
6234
 
6373
6235
  // core/generate-text/stream-text.ts
6374
- var originalGenerateId4 = (0, import_provider_utils19.createIdGenerator)({
6236
+ var originalGenerateId4 = (0, import_provider_utils18.createIdGenerator)({
6375
6237
  prefix: "aitxt",
6376
6238
  size: 24
6377
6239
  });
6378
- var originalGenerateMessageId2 = (0, import_provider_utils19.createIdGenerator)({
6240
+ var originalGenerateMessageId2 = (0, import_provider_utils18.createIdGenerator)({
6379
6241
  prefix: "msg",
6380
6242
  size: 24
6381
6243
  });
@@ -6811,7 +6673,7 @@ var DefaultStreamTextResult = class {
6811
6673
  system: initialPrompt.system,
6812
6674
  messages: stepInputMessages
6813
6675
  },
6814
- supportedUrls: await model.getSupportedUrls()
6676
+ supportedUrls: await model.supportedUrls
6815
6677
  });
6816
6678
  const toolsAndToolChoice = {
6817
6679
  ...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
@@ -7960,8 +7822,8 @@ var doWrap = ({
7960
7822
  provider: providerId != null ? providerId : model.provider,
7961
7823
  modelId: modelId != null ? modelId : model.modelId,
7962
7824
  // TODO middleware should be able to modify the supported urls
7963
- async getSupportedUrls() {
7964
- return model.getSupportedUrls();
7825
+ get supportedUrls() {
7826
+ return model.supportedUrls;
7965
7827
  },
7966
7828
  async doGenerate(params) {
7967
7829
  const transformedParams = await doTransform({ params, type: "generate" });
@@ -8001,7 +7863,7 @@ function appendResponseMessages({
8001
7863
  responseMessages,
8002
7864
  _internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
8003
7865
  }) {
8004
- var _a17, _b, _c, _d, _e;
7866
+ var _a17, _b, _c;
8005
7867
  const clonedMessages = structuredClone(messages);
8006
7868
  for (const message of responseMessages) {
8007
7869
  const role = message.role;
@@ -8009,7 +7871,7 @@ function appendResponseMessages({
8009
7871
  const isLastMessageAssistant = lastMessage.role === "assistant";
8010
7872
  switch (role) {
8011
7873
  case "assistant": {
8012
- let getToolInvocations2 = function(step) {
7874
+ let getToolInvocationsForStep2 = function(step) {
8013
7875
  return (typeof message.content === "string" ? [] : message.content.filter((part) => part.type === "tool-call")).map((call) => ({
8014
7876
  state: "call",
8015
7877
  step,
@@ -8018,7 +7880,7 @@ function appendResponseMessages({
8018
7880
  toolName: call.toolName
8019
7881
  }));
8020
7882
  };
8021
- var getToolInvocations = getToolInvocations2;
7883
+ var getToolInvocationsForStep = getToolInvocationsForStep2;
8022
7884
  const parts = [{ type: "step-start" }];
8023
7885
  let textContent = "";
8024
7886
  let reasoningTextContent = void 0;
@@ -8045,12 +7907,12 @@ function appendResponseMessages({
8045
7907
  if (reasoningPart == null) {
8046
7908
  reasoningPart = {
8047
7909
  type: "reasoning",
8048
- reasoning: ""
7910
+ text: ""
8049
7911
  };
8050
7912
  parts.push(reasoningPart);
8051
7913
  }
8052
7914
  reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
8053
- reasoningPart.reasoning += part.text;
7915
+ reasoningPart.text += part.text;
8054
7916
  reasoningPart.providerMetadata = part.providerOptions;
8055
7917
  break;
8056
7918
  }
@@ -8074,17 +7936,13 @@ function appendResponseMessages({
8074
7936
  }
8075
7937
  if (isLastMessageAssistant) {
8076
7938
  const maxStep = extractMaxToolInvocationStep(
8077
- lastMessage.toolInvocations
7939
+ getToolInvocations(lastMessage)
7940
+ // TODO remove once Message is removed
8078
7941
  );
8079
7942
  (_b = lastMessage.parts) != null ? _b : lastMessage.parts = [];
8080
7943
  lastMessage.content = textContent;
8081
- lastMessage.reasoning = reasoningTextContent;
8082
7944
  lastMessage.parts.push(...parts);
8083
- lastMessage.toolInvocations = [
8084
- ...(_c = lastMessage.toolInvocations) != null ? _c : [],
8085
- ...getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1)
8086
- ];
8087
- getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1).map((call) => ({
7945
+ getToolInvocationsForStep2(maxStep === void 0 ? 0 : maxStep + 1).map((call) => ({
8088
7946
  type: "tool-invocation",
8089
7947
  toolInvocation: call
8090
7948
  })).forEach((part) => {
@@ -8097,11 +7955,9 @@ function appendResponseMessages({
8097
7955
  createdAt: currentDate(),
8098
7956
  // generate a createdAt date for the message, will be overridden by the client
8099
7957
  content: textContent,
8100
- reasoning: reasoningTextContent,
8101
- toolInvocations: getToolInvocations2(0),
8102
7958
  parts: [
8103
7959
  ...parts,
8104
- ...getToolInvocations2(0).map((call) => ({
7960
+ ...getToolInvocationsForStep2(0).map((call) => ({
8105
7961
  type: "tool-invocation",
8106
7962
  toolInvocation: call
8107
7963
  }))
@@ -8111,17 +7967,17 @@ function appendResponseMessages({
8111
7967
  break;
8112
7968
  }
8113
7969
  case "tool": {
8114
- (_d = lastMessage.toolInvocations) != null ? _d : lastMessage.toolInvocations = [];
8115
7970
  if (lastMessage.role !== "assistant") {
8116
7971
  throw new Error(
8117
7972
  `Tool result must follow an assistant message: ${lastMessage.role}`
8118
7973
  );
8119
7974
  }
8120
- (_e = lastMessage.parts) != null ? _e : lastMessage.parts = [];
7975
+ (_c = lastMessage.parts) != null ? _c : lastMessage.parts = [];
8121
7976
  for (const contentPart of message.content) {
8122
- const toolCall = lastMessage.toolInvocations.find(
8123
- (call) => call.toolCallId === contentPart.toolCallId
8124
- );
7977
+ const toolCall = getToolInvocations(
7978
+ lastMessage
7979
+ // TODO remove once Message is removed
7980
+ ).find((call) => call.toolCallId === contentPart.toolCallId);
8125
7981
  const toolCallPart = lastMessage.parts.find(
8126
7982
  (part) => part.type === "tool-invocation" && part.toolInvocation.toolCallId === contentPart.toolCallId
8127
7983
  );
@@ -8304,7 +8160,7 @@ function tool(tool2) {
8304
8160
  }
8305
8161
 
8306
8162
  // core/tool/mcp/mcp-sse-transport.ts
8307
- var import_provider_utils20 = require("@ai-sdk/provider-utils");
8163
+ var import_provider_utils19 = require("@ai-sdk/provider-utils");
8308
8164
 
8309
8165
  // core/tool/mcp/json-rpc-message.ts
8310
8166
  var import_zod9 = require("zod");
@@ -8475,7 +8331,7 @@ var SseMCPTransport = class {
8475
8331
  (_b = this.onerror) == null ? void 0 : _b.call(this, error);
8476
8332
  return reject(error);
8477
8333
  }
8478
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough((0, import_provider_utils20.createEventSourceParserStream)());
8334
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough((0, import_provider_utils19.createEventSourceParserStream)());
8479
8335
  const reader = stream.getReader();
8480
8336
  const processEvents = async () => {
8481
8337
  var _a18, _b2, _c2;
@@ -8674,6 +8530,24 @@ var MCPClient = class {
8674
8530
  await ((_a17 = this.transport) == null ? void 0 : _a17.close());
8675
8531
  this.onClose();
8676
8532
  }
8533
+ assertCapability(method) {
8534
+ switch (method) {
8535
+ case "initialize":
8536
+ break;
8537
+ case "tools/list":
8538
+ case "tools/call":
8539
+ if (!this.serverCapabilities.tools) {
8540
+ throw new MCPClientError({
8541
+ message: `Server does not support tools`
8542
+ });
8543
+ }
8544
+ break;
8545
+ default:
8546
+ throw new MCPClientError({
8547
+ message: `Unsupported method: ${method}`
8548
+ });
8549
+ }
8550
+ }
8677
8551
  async request({
8678
8552
  request,
8679
8553
  resultSchema,
@@ -8687,6 +8561,7 @@ var MCPClient = class {
8687
8561
  })
8688
8562
  );
8689
8563
  }
8564
+ this.assertCapability(request.method);
8690
8565
  const signal = options == null ? void 0 : options.signal;
8691
8566
  signal == null ? void 0 : signal.throwIfAborted();
8692
8567
  const messageId = this.requestMessageId++;
@@ -8715,7 +8590,7 @@ var MCPClient = class {
8715
8590
  resolve(result);
8716
8591
  } catch (error) {
8717
8592
  const parseError = new MCPClientError({
8718
- message: "Failed to parse server initialization result",
8593
+ message: "Failed to parse server response",
8719
8594
  cause: error
8720
8595
  });
8721
8596
  reject(parseError);
@@ -8731,11 +8606,6 @@ var MCPClient = class {
8731
8606
  params,
8732
8607
  options
8733
8608
  } = {}) {
8734
- if (!this.serverCapabilities.tools) {
8735
- throw new MCPClientError({
8736
- message: `Server does not support tools`
8737
- });
8738
- }
8739
8609
  try {
8740
8610
  return this.request({
8741
8611
  request: { method: "tools/list", params },
@@ -8751,11 +8621,6 @@ var MCPClient = class {
8751
8621
  args,
8752
8622
  options
8753
8623
  }) {
8754
- if (!this.serverCapabilities.tools) {
8755
- throw new MCPClientError({
8756
- message: `Server does not support tools`
8757
- });
8758
- }
8759
8624
  try {
8760
8625
  return this.request({
8761
8626
  request: { method: "tools/call", params: { name: name17, arguments: args } },
@@ -8790,7 +8655,7 @@ var MCPClient = class {
8790
8655
  if (schemas !== "automatic" && !(name17 in schemas)) {
8791
8656
  continue;
8792
8657
  }
8793
- const parameters = schemas === "automatic" ? jsonSchema({
8658
+ const parameters = schemas === "automatic" ? (0, import_provider_utils4.jsonSchema)({
8794
8659
  ...inputSchema,
8795
8660
  properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
8796
8661
  additionalProperties: false
@@ -8880,7 +8745,7 @@ function cosineSimilarity(vector1, vector2) {
8880
8745
  }
8881
8746
 
8882
8747
  // core/util/simulate-readable-stream.ts
8883
- var import_provider_utils21 = require("@ai-sdk/provider-utils");
8748
+ var import_provider_utils20 = require("@ai-sdk/provider-utils");
8884
8749
  function simulateReadableStream({
8885
8750
  chunks,
8886
8751
  initialDelayInMs = 0,
@@ -8888,7 +8753,7 @@ function simulateReadableStream({
8888
8753
  _internal
8889
8754
  }) {
8890
8755
  var _a17;
8891
- const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 : import_provider_utils21.delay;
8756
+ const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 : import_provider_utils20.delay;
8892
8757
  let index = 0;
8893
8758
  return new ReadableStream({
8894
8759
  async pull(controller) {
@@ -9026,13 +8891,12 @@ var StreamData = class {
9026
8891
  experimental_transcribe,
9027
8892
  extractMaxToolInvocationStep,
9028
8893
  extractReasoningMiddleware,
9029
- fillMessageParts,
9030
8894
  formatDataStreamPart,
9031
8895
  generateId,
9032
8896
  generateObject,
9033
8897
  generateText,
9034
- getMessageParts,
9035
8898
  getTextFromDataUrl,
8899
+ getToolInvocations,
9036
8900
  isAssistantMessageWithCompletedToolCalls,
9037
8901
  isDeepEqualData,
9038
8902
  jsonSchema,
@@ -9050,7 +8914,6 @@ var StreamData = class {
9050
8914
  streamText,
9051
8915
  tool,
9052
8916
  updateToolCallResult,
9053
- wrapLanguageModel,
9054
- zodSchema
8917
+ wrapLanguageModel
9055
8918
  });
9056
8919
  //# sourceMappingURL=index.js.map