ai 5.0.0-beta.32 → 5.0.0-beta.33

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
@@ -1823,12 +1823,15 @@ function createToolModelOutput({
1823
1823
  if (errorMode === "text") {
1824
1824
  return { type: "error-text", value: getErrorMessage4(output) };
1825
1825
  } else if (errorMode === "json") {
1826
- return { type: "error-json", value: output };
1826
+ return { type: "error-json", value: toJSONValue(output) };
1827
1827
  }
1828
1828
  if (tool3 == null ? void 0 : tool3.toModelOutput) {
1829
1829
  return tool3.toModelOutput(output);
1830
1830
  }
1831
- return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: output };
1831
+ return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: toJSONValue(output) };
1832
+ }
1833
+ function toJSONValue(value) {
1834
+ return value === void 0 ? null : value;
1832
1835
  }
1833
1836
 
1834
1837
  // src/generate-text/to-response-messages.ts
@@ -5341,7 +5344,7 @@ async function embed({
5341
5344
  }),
5342
5345
  tracer,
5343
5346
  fn: async (span) => {
5344
- const { embedding, usage, response } = await retry(
5347
+ const { embedding, usage, response, providerMetadata } = await retry(
5345
5348
  () => (
5346
5349
  // nested spans to align with the embedMany telemetry data:
5347
5350
  recordSpan({
@@ -5385,6 +5388,7 @@ async function embed({
5385
5388
  return {
5386
5389
  embedding: embedding2,
5387
5390
  usage: usage2,
5391
+ providerMetadata: modelResponse.providerMetadata,
5388
5392
  response: modelResponse.response
5389
5393
  };
5390
5394
  }
@@ -5404,6 +5408,7 @@ async function embed({
5404
5408
  value,
5405
5409
  embedding,
5406
5410
  usage,
5411
+ providerMetadata,
5407
5412
  response
5408
5413
  });
5409
5414
  }
@@ -5414,6 +5419,7 @@ var DefaultEmbedResult = class {
5414
5419
  this.value = options.value;
5415
5420
  this.embedding = options.embedding;
5416
5421
  this.usage = options.usage;
5422
+ this.providerMetadata = options.providerMetadata;
5417
5423
  this.response = options.response;
5418
5424
  }
5419
5425
  };
@@ -5471,58 +5477,64 @@ async function embedMany({
5471
5477
  }),
5472
5478
  tracer,
5473
5479
  fn: async (span) => {
5480
+ var _a16;
5474
5481
  const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
5475
5482
  model.maxEmbeddingsPerCall,
5476
5483
  model.supportsParallelCalls
5477
5484
  ]);
5478
5485
  if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
5479
- const { embeddings: embeddings2, usage, response } = await retry(() => {
5480
- return recordSpan({
5481
- name: "ai.embedMany.doEmbed",
5482
- attributes: selectTelemetryAttributes({
5483
- telemetry,
5484
- attributes: {
5485
- ...assembleOperationName({
5486
- operationId: "ai.embedMany.doEmbed",
5487
- telemetry
5488
- }),
5489
- ...baseTelemetryAttributes,
5490
- // specific settings that only make sense on the outer level:
5491
- "ai.values": {
5492
- input: () => values.map((value) => JSON.stringify(value))
5486
+ const { embeddings: embeddings2, usage, response, providerMetadata: providerMetadata2 } = await retry(
5487
+ () => {
5488
+ return recordSpan({
5489
+ name: "ai.embedMany.doEmbed",
5490
+ attributes: selectTelemetryAttributes({
5491
+ telemetry,
5492
+ attributes: {
5493
+ ...assembleOperationName({
5494
+ operationId: "ai.embedMany.doEmbed",
5495
+ telemetry
5496
+ }),
5497
+ ...baseTelemetryAttributes,
5498
+ // specific settings that only make sense on the outer level:
5499
+ "ai.values": {
5500
+ input: () => values.map((value) => JSON.stringify(value))
5501
+ }
5493
5502
  }
5503
+ }),
5504
+ tracer,
5505
+ fn: async (doEmbedSpan) => {
5506
+ var _a17;
5507
+ const modelResponse = await model.doEmbed({
5508
+ values,
5509
+ abortSignal,
5510
+ headers,
5511
+ providerOptions
5512
+ });
5513
+ const embeddings3 = modelResponse.embeddings;
5514
+ const usage2 = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
5515
+ doEmbedSpan.setAttributes(
5516
+ selectTelemetryAttributes({
5517
+ telemetry,
5518
+ attributes: {
5519
+ "ai.embeddings": {
5520
+ output: () => embeddings3.map(
5521
+ (embedding) => JSON.stringify(embedding)
5522
+ )
5523
+ },
5524
+ "ai.usage.tokens": usage2.tokens
5525
+ }
5526
+ })
5527
+ );
5528
+ return {
5529
+ embeddings: embeddings3,
5530
+ usage: usage2,
5531
+ providerMetadata: modelResponse.providerMetadata,
5532
+ response: modelResponse.response
5533
+ };
5494
5534
  }
5495
- }),
5496
- tracer,
5497
- fn: async (doEmbedSpan) => {
5498
- var _a16;
5499
- const modelResponse = await model.doEmbed({
5500
- values,
5501
- abortSignal,
5502
- headers,
5503
- providerOptions
5504
- });
5505
- const embeddings3 = modelResponse.embeddings;
5506
- const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
5507
- doEmbedSpan.setAttributes(
5508
- selectTelemetryAttributes({
5509
- telemetry,
5510
- attributes: {
5511
- "ai.embeddings": {
5512
- output: () => embeddings3.map((embedding) => JSON.stringify(embedding))
5513
- },
5514
- "ai.usage.tokens": usage2.tokens
5515
- }
5516
- })
5517
- );
5518
- return {
5519
- embeddings: embeddings3,
5520
- usage: usage2,
5521
- response: modelResponse.response
5522
- };
5523
- }
5524
- });
5525
- });
5535
+ });
5536
+ }
5537
+ );
5526
5538
  span.setAttributes(
5527
5539
  selectTelemetryAttributes({
5528
5540
  telemetry,
@@ -5538,6 +5550,7 @@ async function embedMany({
5538
5550
  values,
5539
5551
  embeddings: embeddings2,
5540
5552
  usage,
5553
+ providerMetadata: providerMetadata2,
5541
5554
  responses: [response]
5542
5555
  });
5543
5556
  }
@@ -5545,6 +5558,7 @@ async function embedMany({
5545
5558
  const embeddings = [];
5546
5559
  const responses = [];
5547
5560
  let tokens = 0;
5561
+ let providerMetadata;
5548
5562
  const parallelChunks = splitArray(
5549
5563
  valueChunks,
5550
5564
  supportsParallelCalls ? maxParallelCalls : 1
@@ -5571,7 +5585,7 @@ async function embedMany({
5571
5585
  }),
5572
5586
  tracer,
5573
5587
  fn: async (doEmbedSpan) => {
5574
- var _a16;
5588
+ var _a17;
5575
5589
  const modelResponse = await model.doEmbed({
5576
5590
  values: chunk,
5577
5591
  abortSignal,
@@ -5579,7 +5593,7 @@ async function embedMany({
5579
5593
  providerOptions
5580
5594
  });
5581
5595
  const embeddings2 = modelResponse.embeddings;
5582
- const usage = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
5596
+ const usage = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
5583
5597
  doEmbedSpan.setAttributes(
5584
5598
  selectTelemetryAttributes({
5585
5599
  telemetry,
@@ -5596,6 +5610,7 @@ async function embedMany({
5596
5610
  return {
5597
5611
  embeddings: embeddings2,
5598
5612
  usage,
5613
+ providerMetadata: modelResponse.providerMetadata,
5599
5614
  response: modelResponse.response
5600
5615
  };
5601
5616
  }
@@ -5607,6 +5622,20 @@ async function embedMany({
5607
5622
  embeddings.push(...result.embeddings);
5608
5623
  responses.push(result.response);
5609
5624
  tokens += result.usage.tokens;
5625
+ if (result.providerMetadata) {
5626
+ if (!providerMetadata) {
5627
+ providerMetadata = { ...result.providerMetadata };
5628
+ } else {
5629
+ for (const [providerName, metadata] of Object.entries(
5630
+ result.providerMetadata
5631
+ )) {
5632
+ providerMetadata[providerName] = {
5633
+ ...(_a16 = providerMetadata[providerName]) != null ? _a16 : {},
5634
+ ...metadata
5635
+ };
5636
+ }
5637
+ }
5638
+ }
5610
5639
  }
5611
5640
  }
5612
5641
  span.setAttributes(
@@ -5624,6 +5653,7 @@ async function embedMany({
5624
5653
  values,
5625
5654
  embeddings,
5626
5655
  usage: { tokens },
5656
+ providerMetadata,
5627
5657
  responses
5628
5658
  });
5629
5659
  }
@@ -5634,6 +5664,7 @@ var DefaultEmbedManyResult = class {
5634
5664
  this.values = options.values;
5635
5665
  this.embeddings = options.embeddings;
5636
5666
  this.usage = options.usage;
5667
+ this.providerMetadata = options.providerMetadata;
5637
5668
  this.responses = options.responses;
5638
5669
  }
5639
5670
  };