ai 5.0.0-beta.31 → 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.js CHANGED
@@ -1895,12 +1895,15 @@ function createToolModelOutput({
1895
1895
  if (errorMode === "text") {
1896
1896
  return { type: "error-text", value: (0, import_provider21.getErrorMessage)(output) };
1897
1897
  } else if (errorMode === "json") {
1898
- return { type: "error-json", value: output };
1898
+ return { type: "error-json", value: toJSONValue(output) };
1899
1899
  }
1900
1900
  if (tool3 == null ? void 0 : tool3.toModelOutput) {
1901
1901
  return tool3.toModelOutput(output);
1902
1902
  }
1903
- return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: output };
1903
+ return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: toJSONValue(output) };
1904
+ }
1905
+ function toJSONValue(value) {
1906
+ return value === void 0 ? null : value;
1904
1907
  }
1905
1908
 
1906
1909
  // src/generate-text/to-response-messages.ts
@@ -5406,7 +5409,7 @@ async function embed({
5406
5409
  }),
5407
5410
  tracer,
5408
5411
  fn: async (span) => {
5409
- const { embedding, usage, response } = await retry(
5412
+ const { embedding, usage, response, providerMetadata } = await retry(
5410
5413
  () => (
5411
5414
  // nested spans to align with the embedMany telemetry data:
5412
5415
  recordSpan({
@@ -5450,6 +5453,7 @@ async function embed({
5450
5453
  return {
5451
5454
  embedding: embedding2,
5452
5455
  usage: usage2,
5456
+ providerMetadata: modelResponse.providerMetadata,
5453
5457
  response: modelResponse.response
5454
5458
  };
5455
5459
  }
@@ -5469,6 +5473,7 @@ async function embed({
5469
5473
  value,
5470
5474
  embedding,
5471
5475
  usage,
5476
+ providerMetadata,
5472
5477
  response
5473
5478
  });
5474
5479
  }
@@ -5479,6 +5484,7 @@ var DefaultEmbedResult = class {
5479
5484
  this.value = options.value;
5480
5485
  this.embedding = options.embedding;
5481
5486
  this.usage = options.usage;
5487
+ this.providerMetadata = options.providerMetadata;
5482
5488
  this.response = options.response;
5483
5489
  }
5484
5490
  };
@@ -5536,58 +5542,64 @@ async function embedMany({
5536
5542
  }),
5537
5543
  tracer,
5538
5544
  fn: async (span) => {
5545
+ var _a16;
5539
5546
  const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
5540
5547
  model.maxEmbeddingsPerCall,
5541
5548
  model.supportsParallelCalls
5542
5549
  ]);
5543
5550
  if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
5544
- const { embeddings: embeddings2, usage, response } = await retry(() => {
5545
- return recordSpan({
5546
- name: "ai.embedMany.doEmbed",
5547
- attributes: selectTelemetryAttributes({
5548
- telemetry,
5549
- attributes: {
5550
- ...assembleOperationName({
5551
- operationId: "ai.embedMany.doEmbed",
5552
- telemetry
5553
- }),
5554
- ...baseTelemetryAttributes,
5555
- // specific settings that only make sense on the outer level:
5556
- "ai.values": {
5557
- input: () => values.map((value) => JSON.stringify(value))
5551
+ const { embeddings: embeddings2, usage, response, providerMetadata: providerMetadata2 } = await retry(
5552
+ () => {
5553
+ return recordSpan({
5554
+ name: "ai.embedMany.doEmbed",
5555
+ attributes: selectTelemetryAttributes({
5556
+ telemetry,
5557
+ attributes: {
5558
+ ...assembleOperationName({
5559
+ operationId: "ai.embedMany.doEmbed",
5560
+ telemetry
5561
+ }),
5562
+ ...baseTelemetryAttributes,
5563
+ // specific settings that only make sense on the outer level:
5564
+ "ai.values": {
5565
+ input: () => values.map((value) => JSON.stringify(value))
5566
+ }
5558
5567
  }
5568
+ }),
5569
+ tracer,
5570
+ fn: async (doEmbedSpan) => {
5571
+ var _a17;
5572
+ const modelResponse = await model.doEmbed({
5573
+ values,
5574
+ abortSignal,
5575
+ headers,
5576
+ providerOptions
5577
+ });
5578
+ const embeddings3 = modelResponse.embeddings;
5579
+ const usage2 = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
5580
+ doEmbedSpan.setAttributes(
5581
+ selectTelemetryAttributes({
5582
+ telemetry,
5583
+ attributes: {
5584
+ "ai.embeddings": {
5585
+ output: () => embeddings3.map(
5586
+ (embedding) => JSON.stringify(embedding)
5587
+ )
5588
+ },
5589
+ "ai.usage.tokens": usage2.tokens
5590
+ }
5591
+ })
5592
+ );
5593
+ return {
5594
+ embeddings: embeddings3,
5595
+ usage: usage2,
5596
+ providerMetadata: modelResponse.providerMetadata,
5597
+ response: modelResponse.response
5598
+ };
5559
5599
  }
5560
- }),
5561
- tracer,
5562
- fn: async (doEmbedSpan) => {
5563
- var _a16;
5564
- const modelResponse = await model.doEmbed({
5565
- values,
5566
- abortSignal,
5567
- headers,
5568
- providerOptions
5569
- });
5570
- const embeddings3 = modelResponse.embeddings;
5571
- const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
5572
- doEmbedSpan.setAttributes(
5573
- selectTelemetryAttributes({
5574
- telemetry,
5575
- attributes: {
5576
- "ai.embeddings": {
5577
- output: () => embeddings3.map((embedding) => JSON.stringify(embedding))
5578
- },
5579
- "ai.usage.tokens": usage2.tokens
5580
- }
5581
- })
5582
- );
5583
- return {
5584
- embeddings: embeddings3,
5585
- usage: usage2,
5586
- response: modelResponse.response
5587
- };
5588
- }
5589
- });
5590
- });
5600
+ });
5601
+ }
5602
+ );
5591
5603
  span.setAttributes(
5592
5604
  selectTelemetryAttributes({
5593
5605
  telemetry,
@@ -5603,6 +5615,7 @@ async function embedMany({
5603
5615
  values,
5604
5616
  embeddings: embeddings2,
5605
5617
  usage,
5618
+ providerMetadata: providerMetadata2,
5606
5619
  responses: [response]
5607
5620
  });
5608
5621
  }
@@ -5610,6 +5623,7 @@ async function embedMany({
5610
5623
  const embeddings = [];
5611
5624
  const responses = [];
5612
5625
  let tokens = 0;
5626
+ let providerMetadata;
5613
5627
  const parallelChunks = splitArray(
5614
5628
  valueChunks,
5615
5629
  supportsParallelCalls ? maxParallelCalls : 1
@@ -5636,7 +5650,7 @@ async function embedMany({
5636
5650
  }),
5637
5651
  tracer,
5638
5652
  fn: async (doEmbedSpan) => {
5639
- var _a16;
5653
+ var _a17;
5640
5654
  const modelResponse = await model.doEmbed({
5641
5655
  values: chunk,
5642
5656
  abortSignal,
@@ -5644,7 +5658,7 @@ async function embedMany({
5644
5658
  providerOptions
5645
5659
  });
5646
5660
  const embeddings2 = modelResponse.embeddings;
5647
- const usage = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
5661
+ const usage = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
5648
5662
  doEmbedSpan.setAttributes(
5649
5663
  selectTelemetryAttributes({
5650
5664
  telemetry,
@@ -5661,6 +5675,7 @@ async function embedMany({
5661
5675
  return {
5662
5676
  embeddings: embeddings2,
5663
5677
  usage,
5678
+ providerMetadata: modelResponse.providerMetadata,
5664
5679
  response: modelResponse.response
5665
5680
  };
5666
5681
  }
@@ -5672,6 +5687,20 @@ async function embedMany({
5672
5687
  embeddings.push(...result.embeddings);
5673
5688
  responses.push(result.response);
5674
5689
  tokens += result.usage.tokens;
5690
+ if (result.providerMetadata) {
5691
+ if (!providerMetadata) {
5692
+ providerMetadata = { ...result.providerMetadata };
5693
+ } else {
5694
+ for (const [providerName, metadata] of Object.entries(
5695
+ result.providerMetadata
5696
+ )) {
5697
+ providerMetadata[providerName] = {
5698
+ ...(_a16 = providerMetadata[providerName]) != null ? _a16 : {},
5699
+ ...metadata
5700
+ };
5701
+ }
5702
+ }
5703
+ }
5675
5704
  }
5676
5705
  }
5677
5706
  span.setAttributes(
@@ -5689,6 +5718,7 @@ async function embedMany({
5689
5718
  values,
5690
5719
  embeddings,
5691
5720
  usage: { tokens },
5721
+ providerMetadata,
5692
5722
  responses
5693
5723
  });
5694
5724
  }
@@ -5699,6 +5729,7 @@ var DefaultEmbedManyResult = class {
5699
5729
  this.values = options.values;
5700
5730
  this.embeddings = options.embeddings;
5701
5731
  this.usage = options.usage;
5732
+ this.providerMetadata = options.providerMetadata;
5702
5733
  this.responses = options.responses;
5703
5734
  }
5704
5735
  };
@@ -6699,6 +6730,7 @@ var DefaultStreamObjectResult = class {
6699
6730
  this._warnings = new DelayedPromise();
6700
6731
  this._request = new DelayedPromise();
6701
6732
  this._response = new DelayedPromise();
6733
+ this._finishReason = new DelayedPromise();
6702
6734
  const model = resolveLanguageModel(modelArg);
6703
6735
  const { maxRetries, retry } = prepareRetries({
6704
6736
  maxRetries: maxRetriesArg
@@ -6918,6 +6950,7 @@ var DefaultStreamObjectResult = class {
6918
6950
  ...fullResponse,
6919
6951
  headers: response == null ? void 0 : response.headers
6920
6952
  });
6953
+ self._finishReason.resolve(finishReason != null ? finishReason : "unknown");
6921
6954
  const validationResult = await outputStrategy.validateFinalResult(
6922
6955
  latestObjectJson,
6923
6956
  {
@@ -7052,6 +7085,9 @@ var DefaultStreamObjectResult = class {
7052
7085
  get response() {
7053
7086
  return this._response.promise;
7054
7087
  }
7088
+ get finishReason() {
7089
+ return this._finishReason.promise;
7090
+ }
7055
7091
  get partialObjectStream() {
7056
7092
  return createAsyncIterableStream(
7057
7093
  this.baseStream.pipeThrough(
@@ -7904,38 +7940,38 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
7904
7940
  "2025-03-26",
7905
7941
  "2024-11-05"
7906
7942
  ];
7907
- var ClientOrServerImplementationSchema = import_v48.z.object({
7943
+ var ClientOrServerImplementationSchema = import_v48.z.looseObject({
7908
7944
  name: import_v48.z.string(),
7909
7945
  version: import_v48.z.string()
7910
- }).passthrough();
7911
- var BaseParamsSchema = import_v48.z.object({
7912
- _meta: import_v48.z.optional(import_v48.z.object({}).passthrough())
7913
- }).passthrough();
7946
+ });
7947
+ var BaseParamsSchema = import_v48.z.looseObject({
7948
+ _meta: import_v48.z.optional(import_v48.z.object({}).loose())
7949
+ });
7914
7950
  var ResultSchema = BaseParamsSchema;
7915
7951
  var RequestSchema = import_v48.z.object({
7916
7952
  method: import_v48.z.string(),
7917
7953
  params: import_v48.z.optional(BaseParamsSchema)
7918
7954
  });
7919
- var ServerCapabilitiesSchema = import_v48.z.object({
7920
- experimental: import_v48.z.optional(import_v48.z.object({}).passthrough()),
7921
- logging: import_v48.z.optional(import_v48.z.object({}).passthrough()),
7955
+ var ServerCapabilitiesSchema = import_v48.z.looseObject({
7956
+ experimental: import_v48.z.optional(import_v48.z.object({}).loose()),
7957
+ logging: import_v48.z.optional(import_v48.z.object({}).loose()),
7922
7958
  prompts: import_v48.z.optional(
7923
- import_v48.z.object({
7959
+ import_v48.z.looseObject({
7924
7960
  listChanged: import_v48.z.optional(import_v48.z.boolean())
7925
- }).passthrough()
7961
+ })
7926
7962
  ),
7927
7963
  resources: import_v48.z.optional(
7928
- import_v48.z.object({
7964
+ import_v48.z.looseObject({
7929
7965
  subscribe: import_v48.z.optional(import_v48.z.boolean()),
7930
7966
  listChanged: import_v48.z.optional(import_v48.z.boolean())
7931
- }).passthrough()
7967
+ })
7932
7968
  ),
7933
7969
  tools: import_v48.z.optional(
7934
- import_v48.z.object({
7970
+ import_v48.z.looseObject({
7935
7971
  listChanged: import_v48.z.optional(import_v48.z.boolean())
7936
- }).passthrough()
7972
+ })
7937
7973
  )
7938
- }).passthrough();
7974
+ });
7939
7975
  var InitializeResultSchema = ResultSchema.extend({
7940
7976
  protocolVersion: import_v48.z.string(),
7941
7977
  capabilities: ServerCapabilitiesSchema,
@@ -7950,21 +7986,21 @@ var ToolSchema = import_v48.z.object({
7950
7986
  description: import_v48.z.optional(import_v48.z.string()),
7951
7987
  inputSchema: import_v48.z.object({
7952
7988
  type: import_v48.z.literal("object"),
7953
- properties: import_v48.z.optional(import_v48.z.object({}).passthrough())
7954
- }).passthrough()
7955
- }).passthrough();
7989
+ properties: import_v48.z.optional(import_v48.z.object({}).loose())
7990
+ }).loose()
7991
+ }).loose();
7956
7992
  var ListToolsResultSchema = PaginatedResultSchema.extend({
7957
7993
  tools: import_v48.z.array(ToolSchema)
7958
7994
  });
7959
7995
  var TextContentSchema = import_v48.z.object({
7960
7996
  type: import_v48.z.literal("text"),
7961
7997
  text: import_v48.z.string()
7962
- }).passthrough();
7998
+ }).loose();
7963
7999
  var ImageContentSchema = import_v48.z.object({
7964
8000
  type: import_v48.z.literal("image"),
7965
- data: import_v48.z.string().base64(),
8001
+ data: import_v48.z.base64(),
7966
8002
  mimeType: import_v48.z.string()
7967
- }).passthrough();
8003
+ }).loose();
7968
8004
  var ResourceContentsSchema = import_v48.z.object({
7969
8005
  /**
7970
8006
  * The URI of this resource.
@@ -7974,17 +8010,17 @@ var ResourceContentsSchema = import_v48.z.object({
7974
8010
  * The MIME type of this resource, if known.
7975
8011
  */
7976
8012
  mimeType: import_v48.z.optional(import_v48.z.string())
7977
- }).passthrough();
8013
+ }).loose();
7978
8014
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
7979
8015
  text: import_v48.z.string()
7980
8016
  });
7981
8017
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
7982
- blob: import_v48.z.string().base64()
8018
+ blob: import_v48.z.base64()
7983
8019
  });
7984
8020
  var EmbeddedResourceSchema = import_v48.z.object({
7985
8021
  type: import_v48.z.literal("resource"),
7986
8022
  resource: import_v48.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
7987
- }).passthrough();
8023
+ }).loose();
7988
8024
  var CallToolResultSchema = ResultSchema.extend({
7989
8025
  content: import_v48.z.array(
7990
8026
  import_v48.z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
@@ -8182,11 +8218,11 @@ function isCustomMcpTransport(transport) {
8182
8218
  // src/tool/mcp/mcp-client.ts
8183
8219
  var CLIENT_VERSION = "1.0.0";
8184
8220
  async function createMCPClient(config) {
8185
- const client = new MCPClient(config);
8221
+ const client = new DefaultMCPClient(config);
8186
8222
  await client.init();
8187
8223
  return client;
8188
8224
  }
8189
- var MCPClient = class {
8225
+ var DefaultMCPClient = class {
8190
8226
  constructor({
8191
8227
  transport: transportConfig,
8192
8228
  name: name16 = "ai-sdk-mcp-client",