ai 5.0.93 → 5.0.95

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.95
4
+
5
+ ### Patch Changes
6
+
7
+ - a20e687: feat(provider/gateway): add support for image models
8
+ - Updated dependencies [a20e687]
9
+ - @ai-sdk/gateway@2.0.11
10
+
11
+ ## 5.0.94
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [646dc54]
16
+ - @ai-sdk/gateway@2.0.10
17
+
3
18
  ## 5.0.93
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -168,7 +168,7 @@ type Embedding = EmbeddingModelV2Embedding;
168
168
  /**
169
169
  Image model that is used by the AI SDK Core functions.
170
170
  */
171
- type ImageModel = ImageModelV2;
171
+ type ImageModel = string | ImageModelV2;
172
172
  /**
173
173
  Warning from the model provider for this call. The call will proceed, but e.g.
174
174
  some settings might not be supported, which can lead to suboptimal results.
@@ -2868,11 +2868,11 @@ as body parameters.
2868
2868
 
2869
2869
  @returns A result object that contains the generated images.
2870
2870
  */
2871
- declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
2871
+ declare function generateImage({ model: modelArg, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
2872
2872
  /**
2873
2873
  The image model to use.
2874
2874
  */
2875
- model: ImageModelV2;
2875
+ model: ImageModel;
2876
2876
  /**
2877
2877
  The prompt that should be used to generate the image.
2878
2878
  */
package/dist/index.d.ts CHANGED
@@ -168,7 +168,7 @@ type Embedding = EmbeddingModelV2Embedding;
168
168
  /**
169
169
  Image model that is used by the AI SDK Core functions.
170
170
  */
171
- type ImageModel = ImageModelV2;
171
+ type ImageModel = string | ImageModelV2;
172
172
  /**
173
173
  Warning from the model provider for this call. The call will proceed, but e.g.
174
174
  some settings might not be supported, which can lead to suboptimal results.
@@ -2868,11 +2868,11 @@ as body parameters.
2868
2868
 
2869
2869
  @returns A result object that contains the generated images.
2870
2870
  */
2871
- declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
2871
+ declare function generateImage({ model: modelArg, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
2872
2872
  /**
2873
2873
  The image model to use.
2874
2874
  */
2875
- model: ImageModelV2;
2875
+ model: ImageModel;
2876
2876
  /**
2877
2877
  The prompt that should be used to generate the image.
2878
2878
  */
package/dist/index.js CHANGED
@@ -567,6 +567,19 @@ function resolveEmbeddingModel(model) {
567
567
  model
568
568
  );
569
569
  }
570
+ function resolveImageModel(model) {
571
+ if (typeof model !== "string") {
572
+ if (model.specificationVersion !== "v2") {
573
+ throw new UnsupportedModelVersionError({
574
+ version: model.specificationVersion,
575
+ provider: model.provider,
576
+ modelId: model.modelId
577
+ });
578
+ }
579
+ return model;
580
+ }
581
+ return getGlobalProvider().imageModel(model);
582
+ }
570
583
  function getGlobalProvider() {
571
584
  var _a16;
572
585
  return (_a16 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a16 : import_gateway.gateway;
@@ -764,7 +777,7 @@ function detectMediaType({
764
777
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
765
778
 
766
779
  // src/version.ts
767
- var VERSION = true ? "5.0.93" : "0.0.0-test";
780
+ var VERSION = true ? "5.0.95" : "0.0.0-test";
768
781
 
769
782
  // src/util/download/download.ts
770
783
  var download = async ({ url }) => {
@@ -6436,7 +6449,7 @@ var DefaultEmbedManyResult = class {
6436
6449
  // src/generate-image/generate-image.ts
6437
6450
  var import_provider_utils18 = require("@ai-sdk/provider-utils");
6438
6451
  async function generateImage({
6439
- model,
6452
+ model: modelArg,
6440
6453
  prompt,
6441
6454
  n = 1,
6442
6455
  maxImagesPerCall,
@@ -6449,13 +6462,7 @@ async function generateImage({
6449
6462
  headers
6450
6463
  }) {
6451
6464
  var _a16, _b;
6452
- if (model.specificationVersion !== "v2") {
6453
- throw new UnsupportedModelVersionError({
6454
- version: model.specificationVersion,
6455
- provider: model.provider,
6456
- modelId: model.modelId
6457
- });
6458
- }
6465
+ const model = resolveImageModel(modelArg);
6459
6466
  const headersWithUserAgent = (0, import_provider_utils18.withUserAgentSuffix)(
6460
6467
  headers != null ? headers : {},
6461
6468
  `ai/${VERSION}`
@@ -6511,10 +6518,26 @@ async function generateImage({
6511
6518
  warnings.push(...result.warnings);
6512
6519
  if (result.providerMetadata) {
6513
6520
  for (const [providerName, metadata] of Object.entries(result.providerMetadata)) {
6514
- (_b = providerMetadata[providerName]) != null ? _b : providerMetadata[providerName] = { images: [] };
6515
- providerMetadata[providerName].images.push(
6516
- ...result.providerMetadata[providerName].images
6517
- );
6521
+ if (providerName === "gateway") {
6522
+ const currentEntry = providerMetadata[providerName];
6523
+ if (currentEntry != null && typeof currentEntry === "object") {
6524
+ providerMetadata[providerName] = {
6525
+ ...currentEntry,
6526
+ ...metadata
6527
+ };
6528
+ } else {
6529
+ providerMetadata[providerName] = metadata;
6530
+ }
6531
+ const imagesValue = providerMetadata[providerName].images;
6532
+ if (Array.isArray(imagesValue) && imagesValue.length === 0) {
6533
+ delete providerMetadata[providerName].images;
6534
+ }
6535
+ } else {
6536
+ (_b = providerMetadata[providerName]) != null ? _b : providerMetadata[providerName] = { images: [] };
6537
+ providerMetadata[providerName].images.push(
6538
+ ...result.providerMetadata[providerName].images
6539
+ );
6540
+ }
6518
6541
  }
6519
6542
  }
6520
6543
  responses.push(result.response);