ai 5.0.244 → 5.0.248

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
@@ -727,7 +727,7 @@ import {
727
727
  } from "@ai-sdk/provider-utils";
728
728
 
729
729
  // src/version.ts
730
- var VERSION = true ? "5.0.244" : "0.0.0-test";
730
+ var VERSION = true ? "5.0.248" : "0.0.0-test";
731
731
 
732
732
  // src/util/download/download.ts
733
733
  var download = async ({
@@ -1514,13 +1514,22 @@ function assembleOperationName({
1514
1514
  }
1515
1515
 
1516
1516
  // src/telemetry/get-base-telemetry-attributes.ts
1517
+ function getTelemetryMetadataAttributes(telemetry) {
1518
+ var _a16;
1519
+ return Object.entries((_a16 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a16 : {}).reduce(
1520
+ (attributes, [key, value]) => {
1521
+ attributes[`ai.telemetry.metadata.${key}`] = value;
1522
+ return attributes;
1523
+ },
1524
+ {}
1525
+ );
1526
+ }
1517
1527
  function getBaseTelemetryAttributes({
1518
1528
  model,
1519
1529
  settings,
1520
1530
  telemetry,
1521
1531
  headers
1522
1532
  }) {
1523
- var _a16;
1524
1533
  return {
1525
1534
  "ai.model.provider": model.provider,
1526
1535
  "ai.model.id": model.modelId,
@@ -1530,13 +1539,7 @@ function getBaseTelemetryAttributes({
1530
1539
  return attributes;
1531
1540
  }, {}),
1532
1541
  // add metadata as attributes:
1533
- ...Object.entries((_a16 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a16 : {}).reduce(
1534
- (attributes, [key, value]) => {
1535
- attributes[`ai.telemetry.metadata.${key}`] = value;
1536
- return attributes;
1537
- },
1538
- {}
1539
- ),
1542
+ ...getTelemetryMetadataAttributes(telemetry),
1540
1543
  // request headers
1541
1544
  ...Object.entries(headers != null ? headers : {}).reduce((attributes, [key, value]) => {
1542
1545
  if (value !== void 0) {
@@ -2622,6 +2625,7 @@ async function executeTools({
2622
2625
  operationId: "ai.toolCall",
2623
2626
  telemetry
2624
2627
  }),
2628
+ ...getTelemetryMetadataAttributes(telemetry),
2625
2629
  "ai.toolCall.name": toolName,
2626
2630
  "ai.toolCall.id": toolCallId,
2627
2631
  "ai.toolCall.args": {
@@ -4451,6 +4455,7 @@ function runToolsTransformation({
4451
4455
  operationId: "ai.toolCall",
4452
4456
  telemetry
4453
4457
  }),
4458
+ ...getTelemetryMetadataAttributes(telemetry),
4454
4459
  "ai.toolCall.name": toolCall.toolName,
4455
4460
  "ai.toolCall.id": toolCall.toolCallId,
4456
4461
  "ai.toolCall.args": {
@@ -6372,6 +6377,12 @@ import {
6372
6377
  withUserAgentSuffix as withUserAgentSuffix4
6373
6378
  } from "@ai-sdk/provider-utils";
6374
6379
 
6380
+ // src/model/get-embedding-model-max-input-bytes-per-call.ts
6381
+ import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL } from "@ai-sdk/provider-utils";
6382
+ function getEmbeddingModelMaxInputBytesPerCall(model) {
6383
+ return model[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
6384
+ }
6385
+
6375
6386
  // src/util/split-array.ts
6376
6387
  function splitArray(array, chunkSize) {
6377
6388
  if (chunkSize <= 0) {
@@ -6427,11 +6438,18 @@ async function embedMany({
6427
6438
  tracer,
6428
6439
  fn: async (span) => {
6429
6440
  var _a16;
6430
- const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
6441
+ const [
6442
+ maxEmbeddingsPerCall,
6443
+ maxInputBytesPerCall,
6444
+ supportsParallelCalls
6445
+ ] = await Promise.all([
6431
6446
  model.maxEmbeddingsPerCall,
6447
+ getEmbeddingModelMaxInputBytesPerCall(model),
6432
6448
  model.supportsParallelCalls
6433
6449
  ]);
6434
- if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
6450
+ const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
6451
+ const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
6452
+ if (!hasEmbeddingLimit && !hasInputByteLimit) {
6435
6453
  const { embeddings: embeddings2, usage, response, providerMetadata: providerMetadata2 } = await retry(
6436
6454
  () => {
6437
6455
  return recordSpan({
@@ -6503,7 +6521,11 @@ async function embedMany({
6503
6521
  responses: [response]
6504
6522
  });
6505
6523
  }
6506
- const valueChunks = splitArray(values, maxEmbeddingsPerCall);
6524
+ const valueChunks = splitByEmbeddingLimits({
6525
+ values,
6526
+ maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
6527
+ maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
6528
+ });
6507
6529
  const embeddings = [];
6508
6530
  const responses = [];
6509
6531
  let tokens = 0;
@@ -6608,6 +6630,37 @@ async function embedMany({
6608
6630
  }
6609
6631
  });
6610
6632
  }
6633
+ var textEncoder = new TextEncoder();
6634
+ function splitByEmbeddingLimits({
6635
+ values,
6636
+ maxEmbeddingsPerCall,
6637
+ maxInputBytesPerCall
6638
+ }) {
6639
+ if (maxEmbeddingsPerCall <= 0) {
6640
+ throw new Error("maxEmbeddingsPerCall must be greater than 0");
6641
+ }
6642
+ if (maxInputBytesPerCall <= 0) {
6643
+ throw new Error("maxInputBytesPerCall must be greater than 0");
6644
+ }
6645
+ if (values.length === 0) {
6646
+ return [];
6647
+ }
6648
+ const chunks = [];
6649
+ let currentChunk = [];
6650
+ let currentInputBytes = 0;
6651
+ for (const value of values) {
6652
+ const inputBytes = maxInputBytesPerCall === Infinity ? 0 : textEncoder.encode(value).length;
6653
+ if (currentChunk.length > 0 && (currentChunk.length >= maxEmbeddingsPerCall || currentInputBytes + inputBytes > maxInputBytesPerCall)) {
6654
+ chunks.push(currentChunk);
6655
+ currentChunk = [];
6656
+ currentInputBytes = 0;
6657
+ }
6658
+ currentChunk.push(value);
6659
+ currentInputBytes += inputBytes;
6660
+ }
6661
+ chunks.push(currentChunk);
6662
+ return chunks;
6663
+ }
6611
6664
  var DefaultEmbedManyResult = class {
6612
6665
  constructor(options) {
6613
6666
  this.values = options.values;