ai 6.0.216 → 6.0.218

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
@@ -23,7 +23,7 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
23
23
  // src/generate-text/generate-text.ts
24
24
  import {
25
25
  createIdGenerator,
26
- getErrorMessage as getErrorMessage5,
26
+ getErrorMessage as getErrorMessage4,
27
27
  withUserAgentSuffix as withUserAgentSuffix2
28
28
  } from "@ai-sdk/provider-utils";
29
29
 
@@ -1171,7 +1171,7 @@ import {
1171
1171
  } from "@ai-sdk/provider-utils";
1172
1172
 
1173
1173
  // src/version.ts
1174
- var VERSION = true ? "6.0.216" : "0.0.0-test";
1174
+ var VERSION = true ? "6.0.218" : "0.0.0-test";
1175
1175
 
1176
1176
  // src/util/download/download.ts
1177
1177
  var download = async ({
@@ -2675,7 +2675,9 @@ function mergeObjects(base, overrides) {
2675
2675
  // src/util/retry-with-exponential-backoff.ts
2676
2676
  import { APICallError as APICallError2 } from "@ai-sdk/provider";
2677
2677
  import { GatewayError } from "@ai-sdk/gateway";
2678
- import { delay, getErrorMessage as getErrorMessage4, isAbortError } from "@ai-sdk/provider-utils";
2678
+ import {
2679
+ retryWithExponentialBackoff
2680
+ } from "@ai-sdk/provider-utils";
2679
2681
  function getRetryDelayInMs({
2680
2682
  error,
2681
2683
  exponentialBackoffDelay
@@ -2710,66 +2712,18 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
2710
2712
  initialDelayInMs = 2e3,
2711
2713
  backoffFactor = 2,
2712
2714
  abortSignal
2713
- } = {}) => async (f) => _retryWithExponentialBackoff(f, {
2715
+ } = {}) => retryWithExponentialBackoff({
2714
2716
  maxRetries,
2715
- delayInMs: initialDelayInMs,
2717
+ initialDelayInMs,
2716
2718
  backoffFactor,
2717
- abortSignal
2719
+ abortSignal,
2720
+ shouldRetry: (error) => error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true),
2721
+ getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
2722
+ error,
2723
+ exponentialBackoffDelay
2724
+ }),
2725
+ createRetryError: ({ message, reason, errors }) => new RetryError({ message, reason, errors })
2718
2726
  });
2719
- async function _retryWithExponentialBackoff(f, {
2720
- maxRetries,
2721
- delayInMs,
2722
- backoffFactor,
2723
- abortSignal
2724
- }, errors = []) {
2725
- try {
2726
- return await f();
2727
- } catch (error) {
2728
- if (isAbortError(error)) {
2729
- throw error;
2730
- }
2731
- if (maxRetries === 0) {
2732
- throw error;
2733
- }
2734
- const errorMessage = getErrorMessage4(error);
2735
- const newErrors = [...errors, error];
2736
- const tryNumber = newErrors.length;
2737
- if (tryNumber > maxRetries) {
2738
- throw new RetryError({
2739
- message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
2740
- reason: "maxRetriesExceeded",
2741
- errors: newErrors
2742
- });
2743
- }
2744
- if (error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
2745
- await delay(
2746
- getRetryDelayInMs({
2747
- error,
2748
- exponentialBackoffDelay: delayInMs
2749
- }),
2750
- { abortSignal }
2751
- );
2752
- return _retryWithExponentialBackoff(
2753
- f,
2754
- {
2755
- maxRetries,
2756
- delayInMs: backoffFactor * delayInMs,
2757
- backoffFactor,
2758
- abortSignal
2759
- },
2760
- newErrors
2761
- );
2762
- }
2763
- if (tryNumber === 1) {
2764
- throw error;
2765
- }
2766
- throw new RetryError({
2767
- message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
2768
- reason: "errorNotRetryable",
2769
- errors: newErrors
2770
- });
2771
- }
2772
- }
2773
2727
 
2774
2728
  // src/util/prepare-retries.ts
2775
2729
  function prepareRetries({
@@ -4799,7 +4753,7 @@ async function generateText({
4799
4753
  toolCallId: toolCall.toolCallId,
4800
4754
  toolName: toolCall.toolName,
4801
4755
  input: toolCall.input,
4802
- error: getErrorMessage5(toolCall.error),
4756
+ error: getErrorMessage4(toolCall.error),
4803
4757
  dynamic: true
4804
4758
  });
4805
4759
  }
@@ -5260,13 +5214,13 @@ function asContent({
5260
5214
 
5261
5215
  // src/generate-text/stream-text.ts
5262
5216
  import {
5263
- getErrorMessage as getErrorMessage7,
5217
+ getErrorMessage as getErrorMessage6,
5264
5218
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
5265
5219
  } from "@ai-sdk/provider";
5266
5220
  import {
5267
5221
  createIdGenerator as createIdGenerator2,
5268
5222
  DelayedPromise,
5269
- isAbortError as isAbortError2
5223
+ isAbortError
5270
5224
  } from "@ai-sdk/provider-utils";
5271
5225
 
5272
5226
  // src/util/prepare-headers.ts
@@ -6509,7 +6463,7 @@ function createStitchableStream() {
6509
6463
 
6510
6464
  // src/generate-text/run-tools-transformation.ts
6511
6465
  import {
6512
- getErrorMessage as getErrorMessage6
6466
+ getErrorMessage as getErrorMessage5
6513
6467
  } from "@ai-sdk/provider-utils";
6514
6468
  function runToolsTransformation({
6515
6469
  tools,
@@ -6625,7 +6579,7 @@ function runToolsTransformation({
6625
6579
  toolCallId: toolCall.toolCallId,
6626
6580
  toolName: toolCall.toolName,
6627
6581
  input: toolCall.input,
6628
- error: getErrorMessage6(toolCall.error),
6582
+ error: getErrorMessage5(toolCall.error),
6629
6583
  dynamic: true,
6630
6584
  title: toolCall.title,
6631
6585
  ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
@@ -7293,7 +7247,7 @@ var DefaultStreamTextResult = class {
7293
7247
  // The `reason` is usually of type DOMException, but it can also be of any type,
7294
7248
  // so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
7295
7249
  // See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
7296
- ...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage7(abortSignal.reason) } : {}
7250
+ ...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage6(abortSignal.reason) } : {}
7297
7251
  });
7298
7252
  controller.close();
7299
7253
  }
@@ -7309,7 +7263,7 @@ var DefaultStreamTextResult = class {
7309
7263
  }
7310
7264
  controller.enqueue(value);
7311
7265
  } catch (error) {
7312
- if (isAbortError2(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
7266
+ if (isAbortError(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
7313
7267
  abort();
7314
7268
  } else {
7315
7269
  controller.error(error);
@@ -11004,12 +10958,12 @@ function simulateReadableStream({
11004
10958
  _internal
11005
10959
  }) {
11006
10960
  var _a22;
11007
- const delay2 = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
10961
+ const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
11008
10962
  let index = 0;
11009
10963
  return new ReadableStream({
11010
10964
  async pull(controller) {
11011
10965
  if (index < chunks.length) {
11012
- await delay2(index === 0 ? initialDelayInMs : chunkDelayInMs);
10966
+ await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);
11013
10967
  controller.enqueue(chunks[index++]);
11014
10968
  } else {
11015
10969
  controller.close();
@@ -11753,7 +11707,7 @@ var CHUNKING_REGEXPS = {
11753
11707
  function smoothStream({
11754
11708
  delayInMs = 10,
11755
11709
  chunking = "word",
11756
- _internal: { delay: delay2 = originalDelay } = {}
11710
+ _internal: { delay = originalDelay } = {}
11757
11711
  } = {}) {
11758
11712
  let detectChunk;
11759
11713
  if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
@@ -11834,7 +11788,7 @@ function smoothStream({
11834
11788
  while ((match = detectChunk(buffer)) != null) {
11835
11789
  controller.enqueue({ type, text: match, id });
11836
11790
  buffer = buffer.slice(match.length);
11837
- await delay2(delayInMs);
11791
+ await delay(delayInMs);
11838
11792
  }
11839
11793
  }
11840
11794
  });
@@ -11857,6 +11811,8 @@ async function experimental_generateVideo({
11857
11811
  duration,
11858
11812
  fps,
11859
11813
  seed,
11814
+ frameImages,
11815
+ inputReferences,
11860
11816
  generateAudio,
11861
11817
  providerOptions,
11862
11818
  maxRetries: maxRetriesArg,
@@ -11864,7 +11820,7 @@ async function experimental_generateVideo({
11864
11820
  headers,
11865
11821
  download: downloadFn = defaultDownload
11866
11822
  }) {
11867
- var _a22;
11823
+ var _a22, _b;
11868
11824
  const model = resolveVideoModel(modelArg);
11869
11825
  const headersWithUserAgent = withUserAgentSuffix8(
11870
11826
  headers != null ? headers : {},
@@ -11875,7 +11831,32 @@ async function experimental_generateVideo({
11875
11831
  abortSignal
11876
11832
  });
11877
11833
  const { prompt, image } = normalizePrompt2(promptArg);
11878
- const maxVideosPerCallWithDefault = (_a22 = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _a22 : 1;
11834
+ const normalizedFrameImages = frameImages == null ? void 0 : frameImages.map((frame) => ({
11835
+ image: normalizeImageData(frame.image),
11836
+ frameType: frame.frameType
11837
+ }));
11838
+ const normalizedInputReferences = inputReferences == null ? void 0 : inputReferences.map(
11839
+ (reference) => normalizeImageData(reference)
11840
+ );
11841
+ const effectiveInputReferences = normalizedFrameImages != null && normalizedFrameImages.length > 0 ? void 0 : normalizedInputReferences;
11842
+ const warnings = [];
11843
+ if (normalizedFrameImages != null && normalizedFrameImages.length > 0 && normalizedInputReferences != null && normalizedInputReferences.length > 0) {
11844
+ warnings.push({
11845
+ type: "other",
11846
+ message: "inputReferences were ignored because frameImages were provided; frameImages and inputReferences cannot be combined."
11847
+ });
11848
+ }
11849
+ const firstFrameImage = (_a22 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
11850
+ (frame) => frame.frameType === "first_frame"
11851
+ )) == null ? void 0 : _a22.image;
11852
+ if (image != null && firstFrameImage != null) {
11853
+ warnings.push({
11854
+ type: "other",
11855
+ message: "prompt.image was ignored because a first_frame frameImage was provided; the first_frame frameImage takes precedence as the start image."
11856
+ });
11857
+ }
11858
+ const resolvedImage = firstFrameImage != null ? firstFrameImage : image;
11859
+ const maxVideosPerCallWithDefault = (_b = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _b : 1;
11879
11860
  const callCount = Math.ceil(n / maxVideosPerCallWithDefault);
11880
11861
  const callVideoCounts = Array.from({ length: callCount }, (_, index) => {
11881
11862
  const remaining = n - index * maxVideosPerCallWithDefault;
@@ -11883,7 +11864,7 @@ async function experimental_generateVideo({
11883
11864
  });
11884
11865
  const results = await Promise.all(
11885
11866
  callVideoCounts.map(
11886
- async (callVideoCount) => retry(
11867
+ async (callVideoCount) => await retry(
11887
11868
  () => model.doGenerate({
11888
11869
  prompt,
11889
11870
  n: callVideoCount,
@@ -11892,8 +11873,10 @@ async function experimental_generateVideo({
11892
11873
  duration,
11893
11874
  fps,
11894
11875
  seed,
11876
+ image: resolvedImage,
11877
+ frameImages: normalizedFrameImages,
11878
+ inputReferences: effectiveInputReferences,
11895
11879
  generateAudio,
11896
- image,
11897
11880
  providerOptions: providerOptions != null ? providerOptions : {},
11898
11881
  headers: headersWithUserAgent,
11899
11882
  abortSignal
@@ -11902,7 +11885,6 @@ async function experimental_generateVideo({
11902
11885
  )
11903
11886
  );
11904
11887
  const videos = [];
11905
- const warnings = [];
11906
11888
  const responses = [];
11907
11889
  const providerMetadata = {};
11908
11890
  for (const result of results) {
@@ -11998,56 +11980,49 @@ async function experimental_generateVideo({
11998
11980
  };
11999
11981
  }
12000
11982
  function normalizePrompt2(promptArg) {
12001
- var _a22, _b;
12002
11983
  if (typeof promptArg === "string") {
12003
11984
  return {
12004
11985
  prompt: promptArg,
12005
11986
  image: void 0
12006
11987
  };
12007
11988
  }
12008
- let image;
12009
- if (promptArg.image != null) {
12010
- const dataContent = promptArg.image;
12011
- if (typeof dataContent === "string") {
12012
- if (dataContent.startsWith("http://") || dataContent.startsWith("https://")) {
12013
- image = {
12014
- type: "url",
12015
- url: dataContent
12016
- };
12017
- } else if (dataContent.startsWith("data:")) {
12018
- const { mediaType, base64Content } = splitDataUrl(dataContent);
12019
- image = {
12020
- type: "file",
12021
- mediaType: mediaType != null ? mediaType : "image/png",
12022
- data: convertBase64ToUint8Array6(base64Content != null ? base64Content : "")
12023
- };
12024
- } else {
12025
- const bytes = convertBase64ToUint8Array6(dataContent);
12026
- const mediaType = (_a22 = detectMediaType({
12027
- data: bytes,
12028
- signatures: imageMediaTypeSignatures
12029
- })) != null ? _a22 : "image/png";
12030
- image = {
12031
- type: "file",
12032
- mediaType,
12033
- data: bytes
12034
- };
12035
- }
12036
- } else if (dataContent instanceof Uint8Array) {
12037
- const mediaType = (_b = detectMediaType({
12038
- data: dataContent,
12039
- signatures: imageMediaTypeSignatures
12040
- })) != null ? _b : "image/png";
12041
- image = {
11989
+ return {
11990
+ prompt: promptArg.text,
11991
+ image: promptArg.image != null ? normalizeImageData(promptArg.image) : void 0
11992
+ };
11993
+ }
11994
+ function normalizeImageData(dataContent) {
11995
+ var _a22, _b;
11996
+ if (typeof dataContent === "string") {
11997
+ if (dataContent.startsWith("http://") || dataContent.startsWith("https://")) {
11998
+ return {
11999
+ type: "url",
12000
+ url: dataContent
12001
+ };
12002
+ }
12003
+ if (dataContent.startsWith("data:")) {
12004
+ const { mediaType, base64Content } = splitDataUrl(dataContent);
12005
+ return {
12042
12006
  type: "file",
12043
- mediaType,
12044
- data: dataContent
12007
+ mediaType: mediaType != null ? mediaType : "image/png",
12008
+ data: convertBase64ToUint8Array6(base64Content != null ? base64Content : "")
12045
12009
  };
12046
12010
  }
12011
+ const bytes2 = convertBase64ToUint8Array6(dataContent);
12012
+ return {
12013
+ type: "file",
12014
+ mediaType: (_a22 = detectMediaType({
12015
+ data: bytes2,
12016
+ signatures: imageMediaTypeSignatures
12017
+ })) != null ? _a22 : "image/png",
12018
+ data: bytes2
12019
+ };
12047
12020
  }
12021
+ const bytes = convertDataContentToUint8Array(dataContent);
12048
12022
  return {
12049
- prompt: promptArg.text,
12050
- image
12023
+ type: "file",
12024
+ mediaType: (_b = detectMediaType({ data: bytes, signatures: imageMediaTypeSignatures })) != null ? _b : "image/png",
12025
+ data: bytes
12051
12026
  };
12052
12027
  }
12053
12028
  async function invokeModelMaxVideosPerCall(model) {