ai 4.1.13 → 4.1.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
@@ -1525,7 +1525,9 @@ function convertToCoreMessages(messages, options) {
1525
1525
  var _a15;
1526
1526
  const tools = (_a15 = options == null ? void 0 : options.tools) != null ? _a15 : {};
1527
1527
  const coreMessages = [];
1528
- for (const message of messages) {
1528
+ for (let i = 0; i < messages.length; i++) {
1529
+ const message = messages[i];
1530
+ const isLastMessage = i === messages.length - 1;
1529
1531
  const { role, content, toolInvocations, experimental_attachments } = message;
1530
1532
  switch (role) {
1531
1533
  case "system": {
@@ -1554,11 +1556,11 @@ function convertToCoreMessages(messages, options) {
1554
1556
  var _a16;
1555
1557
  return Math.max(max, (_a16 = toolInvocation.step) != null ? _a16 : 0);
1556
1558
  }, 0);
1557
- for (let i = 0; i <= maxStep; i++) {
1559
+ for (let i2 = 0; i2 <= maxStep; i2++) {
1558
1560
  const stepInvocations = toolInvocations.filter(
1559
1561
  (toolInvocation) => {
1560
1562
  var _a16;
1561
- return ((_a16 = toolInvocation.step) != null ? _a16 : 0) === i;
1563
+ return ((_a16 = toolInvocation.step) != null ? _a16 : 0) === i2;
1562
1564
  }
1563
1565
  );
1564
1566
  if (stepInvocations.length === 0) {
@@ -1567,6 +1569,7 @@ function convertToCoreMessages(messages, options) {
1567
1569
  coreMessages.push({
1568
1570
  role: "assistant",
1569
1571
  content: [
1572
+ ...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
1570
1573
  ...stepInvocations.map(
1571
1574
  ({ toolCallId, toolName, args }) => ({
1572
1575
  type: "tool-call",
@@ -1603,7 +1606,7 @@ function convertToCoreMessages(messages, options) {
1603
1606
  })
1604
1607
  });
1605
1608
  }
1606
- if (content) {
1609
+ if (content && !isLastMessage) {
1607
1610
  coreMessages.push({ role: "assistant", content });
1608
1611
  }
1609
1612
  break;