ai 4.1.48 → 4.1.50

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
@@ -1256,12 +1256,12 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
1256
1256
  );
1257
1257
  }
1258
1258
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1259
- var _a16;
1259
+ var _a16, _b, _c, _d;
1260
1260
  if (part.type === "text") {
1261
1261
  return {
1262
1262
  type: "text",
1263
1263
  text: part.text,
1264
- providerMetadata: part.experimental_providerMetadata
1264
+ providerMetadata: (_a16 = part.providerOptions) != null ? _a16 : part.experimental_providerMetadata
1265
1265
  };
1266
1266
  }
1267
1267
  let mimeType = part.mimeType;
@@ -1309,13 +1309,13 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1309
1309
  switch (type) {
1310
1310
  case "image": {
1311
1311
  if (normalizedData instanceof Uint8Array) {
1312
- mimeType = (_a16 = detectImageMimeType(normalizedData)) != null ? _a16 : mimeType;
1312
+ mimeType = (_b = detectImageMimeType(normalizedData)) != null ? _b : mimeType;
1313
1313
  }
1314
1314
  return {
1315
1315
  type: "image",
1316
1316
  image: normalizedData,
1317
1317
  mimeType,
1318
- providerMetadata: part.experimental_providerMetadata
1318
+ providerMetadata: (_c = part.providerOptions) != null ? _c : part.experimental_providerMetadata
1319
1319
  };
1320
1320
  }
1321
1321
  case "file": {
@@ -1326,7 +1326,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1326
1326
  type: "file",
1327
1327
  data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
1328
1328
  mimeType,
1329
- providerMetadata: part.experimental_providerMetadata
1329
+ providerMetadata: (_d = part.providerOptions) != null ? _d : part.experimental_providerMetadata
1330
1330
  };
1331
1331
  }
1332
1332
  }
@@ -6135,7 +6135,7 @@ function appendResponseMessages({
6135
6135
  const lastMessage = clonedMessages[clonedMessages.length - 1];
6136
6136
  const isLastMessageAssistant = lastMessage.role === "assistant";
6137
6137
  switch (role) {
6138
- case "assistant":
6138
+ case "assistant": {
6139
6139
  let getToolInvocations2 = function(step) {
6140
6140
  return (typeof message.content === "string" ? [] : message.content.filter((part) => part.type === "tool-call")).map((call) => ({
6141
6141
  state: "call",
@@ -6146,19 +6146,74 @@ function appendResponseMessages({
6146
6146
  }));
6147
6147
  };
6148
6148
  var getToolInvocations = getToolInvocations2;
6149
- const textContent = typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
6149
+ const parts = [];
6150
+ let textContent = "";
6151
+ let reasoningTextContent = void 0;
6152
+ if (typeof message.content === "string") {
6153
+ textContent = message.content;
6154
+ parts.push({
6155
+ type: "text",
6156
+ text: message.content
6157
+ });
6158
+ } else {
6159
+ let reasoningPart = void 0;
6160
+ for (const part of message.content) {
6161
+ switch (part.type) {
6162
+ case "text": {
6163
+ reasoningPart = void 0;
6164
+ textContent += part.text;
6165
+ parts.push({
6166
+ type: "text",
6167
+ text: part.text
6168
+ });
6169
+ break;
6170
+ }
6171
+ case "reasoning": {
6172
+ if (reasoningPart == null) {
6173
+ reasoningPart = {
6174
+ type: "reasoning",
6175
+ reasoning: "",
6176
+ details: []
6177
+ };
6178
+ parts.push(reasoningPart);
6179
+ }
6180
+ reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
6181
+ reasoningPart.reasoning += part.text;
6182
+ reasoningPart.details.push({
6183
+ type: "text",
6184
+ text: part.text,
6185
+ signature: part.signature
6186
+ });
6187
+ break;
6188
+ }
6189
+ case "redacted-reasoning": {
6190
+ if (reasoningPart == null) {
6191
+ reasoningPart = {
6192
+ type: "reasoning",
6193
+ reasoning: "",
6194
+ details: []
6195
+ };
6196
+ parts.push(reasoningPart);
6197
+ }
6198
+ reasoningPart.details.push({
6199
+ type: "redacted",
6200
+ data: part.data
6201
+ });
6202
+ break;
6203
+ }
6204
+ case "tool-call":
6205
+ break;
6206
+ }
6207
+ }
6208
+ }
6150
6209
  if (isLastMessageAssistant) {
6151
6210
  const maxStep = extractMaxToolInvocationStep(
6152
6211
  lastMessage.toolInvocations
6153
6212
  );
6154
6213
  (_a16 = lastMessage.parts) != null ? _a16 : lastMessage.parts = [];
6155
6214
  lastMessage.content = textContent;
6156
- if (textContent.length > 0) {
6157
- lastMessage.parts.push({
6158
- type: "text",
6159
- text: textContent
6160
- });
6161
- }
6215
+ lastMessage.reasoning = reasoningTextContent;
6216
+ lastMessage.parts.push(...parts);
6162
6217
  lastMessage.toolInvocations = [
6163
6218
  ...(_b = lastMessage.toolInvocations) != null ? _b : [],
6164
6219
  ...getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1)
@@ -6176,9 +6231,10 @@ function appendResponseMessages({
6176
6231
  createdAt: currentDate(),
6177
6232
  // generate a createdAt date for the message, will be overridden by the client
6178
6233
  content: textContent,
6234
+ reasoning: reasoningTextContent,
6179
6235
  toolInvocations: getToolInvocations2(0),
6180
6236
  parts: [
6181
- ...textContent.length > 0 ? [{ type: "text", text: textContent }] : [],
6237
+ ...parts,
6182
6238
  ...getToolInvocations2(0).map((call) => ({
6183
6239
  type: "tool-invocation",
6184
6240
  toolInvocation: call
@@ -6187,6 +6243,7 @@ function appendResponseMessages({
6187
6243
  });
6188
6244
  }
6189
6245
  break;
6246
+ }
6190
6247
  case "tool": {
6191
6248
  (_c = lastMessage.toolInvocations) != null ? _c : lastMessage.toolInvocations = [];
6192
6249
  if (lastMessage.role !== "assistant") {