ai 7.0.10 → 7.0.12

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.
@@ -83,7 +83,7 @@ import {
83
83
  } from "@ai-sdk/provider-utils";
84
84
 
85
85
  // src/version.ts
86
- var VERSION = true ? "7.0.10" : "0.0.0-test";
86
+ var VERSION = true ? "7.0.12" : "0.0.0-test";
87
87
 
88
88
  // src/util/download/download.ts
89
89
  var download = async ({
@@ -2303,10 +2303,9 @@ async function loadDiagnosticsChannel() {
2303
2303
  return void 0;
2304
2304
  }
2305
2305
  if (diagnosticsChannelPromise == null) {
2306
- diagnosticsChannelPromise = import(
2307
- /* webpackIgnore: true */
2308
- "diagnostics_channel"
2309
- ).catch(() => void 0);
2306
+ diagnosticsChannelPromise = Promise.resolve(
2307
+ loadBuiltinModule("node:diagnostics_channel")
2308
+ );
2310
2309
  }
2311
2310
  return diagnosticsChannelPromise;
2312
2311
  }
@@ -3329,6 +3328,7 @@ async function toResponseMessages({
3329
3328
  tools
3330
3329
  }) {
3331
3330
  const responseMessages = [];
3331
+ const toolCallOrder = /* @__PURE__ */ new Map();
3332
3332
  const content = [];
3333
3333
  for (const part of inputContent) {
3334
3334
  if (part.type === "source") {
@@ -3379,6 +3379,9 @@ async function toResponseMessages({
3379
3379
  });
3380
3380
  break;
3381
3381
  case "tool-call":
3382
+ if (!toolCallOrder.has(part.toolCallId)) {
3383
+ toolCallOrder.set(part.toolCallId, toolCallOrder.size);
3384
+ }
3382
3385
  content.push({
3383
3386
  type: "tool-call",
3384
3387
  toolCallId: part.toolCallId,
@@ -3486,11 +3489,37 @@ async function toResponseMessages({
3486
3489
  if (toolResultContent.length > 0) {
3487
3490
  responseMessages.push({
3488
3491
  role: "tool",
3489
- content: toolResultContent
3492
+ content: sortToolResultContentByToolCallOrder({
3493
+ toolResultContent,
3494
+ toolCallOrder
3495
+ })
3490
3496
  });
3491
3497
  }
3492
3498
  return responseMessages;
3493
3499
  }
3500
+ function sortToolResultContentByToolCallOrder({
3501
+ toolResultContent,
3502
+ toolCallOrder
3503
+ }) {
3504
+ const sortedToolResults = toolResultContent.filter((part) => part.type === "tool-result").map((part, index) => ({ part, index })).sort((a, b) => {
3505
+ const aOrder = toolCallOrder.get(a.part.toolCallId);
3506
+ const bOrder = toolCallOrder.get(b.part.toolCallId);
3507
+ if (aOrder == null && bOrder == null) {
3508
+ return a.index - b.index;
3509
+ }
3510
+ if (aOrder == null) {
3511
+ return 1;
3512
+ }
3513
+ if (bOrder == null) {
3514
+ return -1;
3515
+ }
3516
+ return aOrder - bOrder || a.index - b.index;
3517
+ }).map(({ part }) => part);
3518
+ let toolResultIndex = 0;
3519
+ return toolResultContent.map(
3520
+ (part) => part.type === "tool-result" ? sortedToolResults[toolResultIndex++] : part
3521
+ );
3522
+ }
3494
3523
  export {
3495
3524
  DefaultStepResult,
3496
3525
  addLanguageModelUsage,