ai 4.1.13 → 4.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "4.1.13",
3
+ "version": "4.1.15",
4
4
  "description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -40,10 +40,10 @@
40
40
  }
41
41
  },
42
42
  "dependencies": {
43
- "@ai-sdk/provider": "1.0.6",
44
- "@ai-sdk/provider-utils": "2.1.5",
45
- "@ai-sdk/react": "1.1.7",
46
- "@ai-sdk/ui-utils": "1.1.7",
43
+ "@ai-sdk/provider": "1.0.7",
44
+ "@ai-sdk/provider-utils": "2.1.6",
45
+ "@ai-sdk/react": "1.1.8",
46
+ "@ai-sdk/ui-utils": "1.1.8",
47
47
  "@opentelemetry/api": "1.9.0",
48
48
  "jsondiffpatch": "0.6.0"
49
49
  },
@@ -979,7 +979,9 @@ function convertToCoreMessages(messages, options) {
979
979
  var _a9;
980
980
  const tools = (_a9 = options == null ? void 0 : options.tools) != null ? _a9 : {};
981
981
  const coreMessages = [];
982
- for (const message of messages) {
982
+ for (let i = 0; i < messages.length; i++) {
983
+ const message = messages[i];
984
+ const isLastMessage = i === messages.length - 1;
983
985
  const { role, content, toolInvocations, experimental_attachments } = message;
984
986
  switch (role) {
985
987
  case "system": {
@@ -1008,11 +1010,11 @@ function convertToCoreMessages(messages, options) {
1008
1010
  var _a10;
1009
1011
  return Math.max(max, (_a10 = toolInvocation.step) != null ? _a10 : 0);
1010
1012
  }, 0);
1011
- for (let i = 0; i <= maxStep; i++) {
1013
+ for (let i2 = 0; i2 <= maxStep; i2++) {
1012
1014
  const stepInvocations = toolInvocations.filter(
1013
1015
  (toolInvocation) => {
1014
1016
  var _a10;
1015
- return ((_a10 = toolInvocation.step) != null ? _a10 : 0) === i;
1017
+ return ((_a10 = toolInvocation.step) != null ? _a10 : 0) === i2;
1016
1018
  }
1017
1019
  );
1018
1020
  if (stepInvocations.length === 0) {
@@ -1021,6 +1023,7 @@ function convertToCoreMessages(messages, options) {
1021
1023
  coreMessages.push({
1022
1024
  role: "assistant",
1023
1025
  content: [
1026
+ ...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
1024
1027
  ...stepInvocations.map(
1025
1028
  ({ toolCallId, toolName, args }) => ({
1026
1029
  type: "tool-call",
@@ -1057,7 +1060,7 @@ function convertToCoreMessages(messages, options) {
1057
1060
  })
1058
1061
  });
1059
1062
  }
1060
- if (content) {
1063
+ if (content && !isLastMessage) {
1061
1064
  coreMessages.push({ role: "assistant", content });
1062
1065
  }
1063
1066
  break;