ai 3.2.22 → 3.2.24

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
@@ -1339,7 +1339,7 @@ async function generateText({
1339
1339
  },
1340
1340
  tracer,
1341
1341
  fn: async (span) => {
1342
- var _a2, _b, _c;
1342
+ var _a2, _b, _c, _d;
1343
1343
  const retry = retryWithExponentialBackoff({ maxRetries });
1344
1344
  const validatedPrompt = getValidatedPrompt({
1345
1345
  system,
@@ -1355,10 +1355,11 @@ async function generateText({
1355
1355
  let currentModelResponse;
1356
1356
  let currentToolCalls = [];
1357
1357
  let currentToolResults = [];
1358
- let roundtrips = 0;
1358
+ let roundtripCount = 0;
1359
1359
  const responseMessages = [];
1360
+ const roundtrips = [];
1360
1361
  do {
1361
- const currentInputFormat = roundtrips === 0 ? validatedPrompt.type : "messages";
1362
+ const currentInputFormat = roundtripCount === 0 ? validatedPrompt.type : "messages";
1362
1363
  currentModelResponse = await retry(
1363
1364
  () => recordSpan({
1364
1365
  name: "ai.generateText.doGenerate",
@@ -1396,9 +1397,18 @@ async function generateText({
1396
1397
  tools,
1397
1398
  tracer
1398
1399
  });
1399
- const newResponseMessages = toResponseMessages({
1400
+ roundtrips.push({
1400
1401
  text: (_b = currentModelResponse.text) != null ? _b : "",
1401
1402
  toolCalls: currentToolCalls,
1403
+ toolResults: currentToolResults,
1404
+ finishReason: currentModelResponse.finishReason,
1405
+ usage: calculateCompletionTokenUsage(currentModelResponse.usage),
1406
+ warnings: currentModelResponse.warnings,
1407
+ logprobs: currentModelResponse.logprobs
1408
+ });
1409
+ const newResponseMessages = toResponseMessages({
1410
+ text: (_c = currentModelResponse.text) != null ? _c : "",
1411
+ toolCalls: currentToolCalls,
1402
1412
  toolResults: currentToolResults
1403
1413
  });
1404
1414
  responseMessages.push(...newResponseMessages);
@@ -1409,7 +1419,7 @@ async function generateText({
1409
1419
  // there are tool calls:
1410
1420
  currentToolCalls.length > 0 && // all current tool calls have results:
1411
1421
  currentToolResults.length === currentToolCalls.length && // the number of roundtrips is less than the maximum:
1412
- roundtrips++ < maxToolRoundtrips
1422
+ roundtripCount++ < maxToolRoundtrips
1413
1423
  );
1414
1424
  span.setAttributes({
1415
1425
  "ai.finishReason": currentModelResponse.finishReason,
@@ -1422,7 +1432,7 @@ async function generateText({
1422
1432
  // Always return a string so that the caller doesn't have to check for undefined.
1423
1433
  // If they need to check if the model did not return any text,
1424
1434
  // they can check the length of the string:
1425
- text: (_c = currentModelResponse.text) != null ? _c : "",
1435
+ text: (_d = currentModelResponse.text) != null ? _d : "",
1426
1436
  toolCalls: currentToolCalls,
1427
1437
  toolResults: currentToolResults,
1428
1438
  finishReason: currentModelResponse.finishReason,
@@ -1430,7 +1440,8 @@ async function generateText({
1430
1440
  warnings: currentModelResponse.warnings,
1431
1441
  rawResponse: currentModelResponse.rawResponse,
1432
1442
  logprobs: currentModelResponse.logprobs,
1433
- responseMessages
1443
+ responseMessages,
1444
+ roundtrips
1434
1445
  });
1435
1446
  }
1436
1447
  });
@@ -1488,6 +1499,7 @@ var GenerateTextResult = class {
1488
1499
  this.rawResponse = options.rawResponse;
1489
1500
  this.logprobs = options.logprobs;
1490
1501
  this.responseMessages = options.responseMessages;
1502
+ this.roundtrips = options.roundtrips;
1491
1503
  }
1492
1504
  };
1493
1505
  function toResponseMessages({