ai 7.0.6 → 7.0.8
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 +16 -0
- package/dist/index.d.ts +19 -2
- package/dist/index.js +68 -48
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-ai-sdk-core/38-video-generation.mdx +40 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +15 -7
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +11 -2
- package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +12 -0
- package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +2 -2
- package/package.json +4 -4
- package/src/generate-video/generate-video.ts +122 -49
- package/src/ui/convert-to-model-messages.ts +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0274f34: feat (video): add first-class `frameImages` and `inputReferences` call options for video generation
|
|
8
|
+
- Updated dependencies [0274f34]
|
|
9
|
+
- @ai-sdk/provider@4.0.1
|
|
10
|
+
- @ai-sdk/gateway@4.0.6
|
|
11
|
+
- @ai-sdk/provider-utils@5.0.2
|
|
12
|
+
|
|
13
|
+
## 7.0.7
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- d598481: Fix: `convertToModelMessages` no longer emits an empty assistant message when a block contains only unknown data parts (e.g. a data part before `step-start` with no `convertDataPart` provided)
|
|
18
|
+
|
|
3
19
|
## 7.0.6
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
|
2
|
-
import { EmbeddingModelV4, EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV4Embedding, EmbeddingModelV4Middleware, ImageModelV4, ImageModelV3, ImageModelV2, ImageModelV4ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV4Middleware, JSONValue as JSONValue$1, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4Warning, LanguageModelV4Source, LanguageModelV4Middleware, RerankingModelV4, RerankingModelV3, SharedV4ProviderMetadata, SharedV4ProviderReference, SpeechModelV4, SpeechModelV3, SpeechModelV2, TranscriptionModelV4, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV4Usage, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, EmbeddingModelV4CallOptions, Experimental_RealtimeFactoryV4, Experimental_RealtimeFactoryV4GetTokenOptions, Experimental_RealtimeFactoryV4GetTokenResult, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4SessionConfig, Experimental_RealtimeModelV4ToolDefinition, FilesV4, SkillsV4, NoSuchModelError, FilesV4UploadFileCallOptions, SkillsV4UploadSkillResult, SkillsV4UploadSkillCallOptions, SkillsV4File } from '@ai-sdk/provider';
|
|
2
|
+
import { EmbeddingModelV4, EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV4Embedding, EmbeddingModelV4Middleware, ImageModelV4, ImageModelV3, ImageModelV2, ImageModelV4ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV4Middleware, JSONValue as JSONValue$1, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4Warning, LanguageModelV4Source, LanguageModelV4Middleware, RerankingModelV4, RerankingModelV3, SharedV4ProviderMetadata, SharedV4ProviderReference, SpeechModelV4, SpeechModelV3, SpeechModelV2, TranscriptionModelV4, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV4Usage, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, Experimental_VideoModelV4FrameType, EmbeddingModelV4CallOptions, Experimental_RealtimeFactoryV4, Experimental_RealtimeFactoryV4GetTokenOptions, Experimental_RealtimeFactoryV4GetTokenResult, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4SessionConfig, Experimental_RealtimeModelV4ToolDefinition, FilesV4, SkillsV4, NoSuchModelError, FilesV4UploadFileCallOptions, SkillsV4UploadSkillResult, SkillsV4UploadSkillCallOptions, SkillsV4File } from '@ai-sdk/provider';
|
|
3
3
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
|
4
4
|
import { GatewayModelId } from '@ai-sdk/gateway';
|
|
5
5
|
export { GatewayModelId, createGateway, gateway } from '@ai-sdk/gateway';
|
|
@@ -7879,7 +7879,7 @@ type GenerateVideoPrompt = string | {
|
|
|
7879
7879
|
image: DataContent;
|
|
7880
7880
|
text?: string;
|
|
7881
7881
|
};
|
|
7882
|
-
declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, generateAudio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, }: {
|
|
7882
|
+
declare function experimental_generateVideo({ model: modelArg, prompt: promptArg, n, maxVideosPerCall, aspectRatio, resolution, duration, fps, seed, frameImages, inputReferences, generateAudio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, download: downloadFn, }: {
|
|
7883
7883
|
/**
|
|
7884
7884
|
* The video model to use.
|
|
7885
7885
|
*/
|
|
@@ -7916,6 +7916,23 @@ declare function experimental_generateVideo({ model: modelArg, prompt: promptArg
|
|
|
7916
7916
|
* Seed for the video generation.
|
|
7917
7917
|
*/
|
|
7918
7918
|
seed?: number;
|
|
7919
|
+
/**
|
|
7920
|
+
* Role-tagged image inputs for image-to-video and first-last-frame generation.
|
|
7921
|
+
*/
|
|
7922
|
+
frameImages?: Array<{
|
|
7923
|
+
/**
|
|
7924
|
+
* The image for this frame.
|
|
7925
|
+
*/
|
|
7926
|
+
image: DataContent;
|
|
7927
|
+
/**
|
|
7928
|
+
* Which frame this image represents.
|
|
7929
|
+
*/
|
|
7930
|
+
frameType: Experimental_VideoModelV4FrameType;
|
|
7931
|
+
}>;
|
|
7932
|
+
/**
|
|
7933
|
+
* Reference image inputs for reference-to-video generation.
|
|
7934
|
+
*/
|
|
7935
|
+
inputReferences?: Array<DataContent>;
|
|
7919
7936
|
/**
|
|
7920
7937
|
* Whether the model should generate audio alongside the video.
|
|
7921
7938
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1089,7 +1089,7 @@ import {
|
|
|
1089
1089
|
} from "@ai-sdk/provider-utils";
|
|
1090
1090
|
|
|
1091
1091
|
// src/version.ts
|
|
1092
|
-
var VERSION = true ? "7.0.
|
|
1092
|
+
var VERSION = true ? "7.0.8" : "0.0.0-test";
|
|
1093
1093
|
|
|
1094
1094
|
// src/util/download/download.ts
|
|
1095
1095
|
var download = async ({
|
|
@@ -10458,10 +10458,12 @@ async function convertToModelMessages(messages, options) {
|
|
|
10458
10458
|
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
|
10459
10459
|
}
|
|
10460
10460
|
}
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10461
|
+
if (content.length > 0) {
|
|
10462
|
+
modelMessages.push({
|
|
10463
|
+
role: "assistant",
|
|
10464
|
+
content
|
|
10465
|
+
});
|
|
10466
|
+
}
|
|
10465
10467
|
const toolParts = block.filter(
|
|
10466
10468
|
(part) => {
|
|
10467
10469
|
var _a23;
|
|
@@ -13427,6 +13429,8 @@ async function experimental_generateVideo({
|
|
|
13427
13429
|
duration,
|
|
13428
13430
|
fps,
|
|
13429
13431
|
seed,
|
|
13432
|
+
frameImages,
|
|
13433
|
+
inputReferences,
|
|
13430
13434
|
generateAudio,
|
|
13431
13435
|
providerOptions,
|
|
13432
13436
|
maxRetries: maxRetriesArg,
|
|
@@ -13434,7 +13438,7 @@ async function experimental_generateVideo({
|
|
|
13434
13438
|
headers,
|
|
13435
13439
|
download: downloadFn = defaultDownload
|
|
13436
13440
|
}) {
|
|
13437
|
-
var _a22;
|
|
13441
|
+
var _a22, _b;
|
|
13438
13442
|
const model = resolveVideoModel(modelArg);
|
|
13439
13443
|
const headersWithUserAgent = withUserAgentSuffix9(
|
|
13440
13444
|
headers != null ? headers : {},
|
|
@@ -13445,7 +13449,32 @@ async function experimental_generateVideo({
|
|
|
13445
13449
|
abortSignal
|
|
13446
13450
|
});
|
|
13447
13451
|
const { prompt, image } = normalizePrompt2(promptArg);
|
|
13448
|
-
const
|
|
13452
|
+
const normalizedFrameImages = frameImages == null ? void 0 : frameImages.map((frame) => ({
|
|
13453
|
+
image: normalizeImageData(frame.image),
|
|
13454
|
+
frameType: frame.frameType
|
|
13455
|
+
}));
|
|
13456
|
+
const normalizedInputReferences = inputReferences == null ? void 0 : inputReferences.map(
|
|
13457
|
+
(reference) => normalizeImageData(reference)
|
|
13458
|
+
);
|
|
13459
|
+
const effectiveInputReferences = normalizedFrameImages != null && normalizedFrameImages.length > 0 ? void 0 : normalizedInputReferences;
|
|
13460
|
+
const warnings = [];
|
|
13461
|
+
if (normalizedFrameImages != null && normalizedFrameImages.length > 0 && normalizedInputReferences != null && normalizedInputReferences.length > 0) {
|
|
13462
|
+
warnings.push({
|
|
13463
|
+
type: "other",
|
|
13464
|
+
message: "inputReferences were ignored because frameImages were provided; frameImages and inputReferences cannot be combined."
|
|
13465
|
+
});
|
|
13466
|
+
}
|
|
13467
|
+
const firstFrameImage = (_a22 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
|
|
13468
|
+
(frame) => frame.frameType === "first_frame"
|
|
13469
|
+
)) == null ? void 0 : _a22.image;
|
|
13470
|
+
if (image != null && firstFrameImage != null) {
|
|
13471
|
+
warnings.push({
|
|
13472
|
+
type: "other",
|
|
13473
|
+
message: "prompt.image was ignored because a first_frame frameImage was provided; the first_frame frameImage takes precedence as the start image."
|
|
13474
|
+
});
|
|
13475
|
+
}
|
|
13476
|
+
const resolvedImage = firstFrameImage != null ? firstFrameImage : image;
|
|
13477
|
+
const maxVideosPerCallWithDefault = (_b = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _b : 1;
|
|
13449
13478
|
const callCount = Math.ceil(n / maxVideosPerCallWithDefault);
|
|
13450
13479
|
const callVideoCounts = Array.from({ length: callCount }, (_, index) => {
|
|
13451
13480
|
const remaining = n - index * maxVideosPerCallWithDefault;
|
|
@@ -13462,8 +13491,10 @@ async function experimental_generateVideo({
|
|
|
13462
13491
|
duration,
|
|
13463
13492
|
fps,
|
|
13464
13493
|
seed,
|
|
13494
|
+
image: resolvedImage,
|
|
13495
|
+
frameImages: normalizedFrameImages,
|
|
13496
|
+
inputReferences: effectiveInputReferences,
|
|
13465
13497
|
generateAudio,
|
|
13466
|
-
image,
|
|
13467
13498
|
providerOptions: providerOptions != null ? providerOptions : {},
|
|
13468
13499
|
headers: headersWithUserAgent,
|
|
13469
13500
|
abortSignal
|
|
@@ -13472,7 +13503,6 @@ async function experimental_generateVideo({
|
|
|
13472
13503
|
)
|
|
13473
13504
|
);
|
|
13474
13505
|
const videos = [];
|
|
13475
|
-
const warnings = [];
|
|
13476
13506
|
const responses = [];
|
|
13477
13507
|
const providerMetadata = {};
|
|
13478
13508
|
for (const result of results) {
|
|
@@ -13568,56 +13598,46 @@ async function experimental_generateVideo({
|
|
|
13568
13598
|
};
|
|
13569
13599
|
}
|
|
13570
13600
|
function normalizePrompt2(promptArg) {
|
|
13571
|
-
var _a22, _b;
|
|
13572
13601
|
if (typeof promptArg === "string") {
|
|
13573
13602
|
return {
|
|
13574
13603
|
prompt: promptArg,
|
|
13575
13604
|
image: void 0
|
|
13576
13605
|
};
|
|
13577
13606
|
}
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
const bytes = convertBase64ToUint8Array5(dataContent);
|
|
13596
|
-
const mediaType = (_a22 = detectMediaType4({
|
|
13597
|
-
data: bytes,
|
|
13598
|
-
topLevelType: "image"
|
|
13599
|
-
})) != null ? _a22 : "image/png";
|
|
13600
|
-
image = {
|
|
13601
|
-
type: "file",
|
|
13602
|
-
mediaType,
|
|
13603
|
-
data: bytes
|
|
13604
|
-
};
|
|
13605
|
-
}
|
|
13606
|
-
} else if (dataContent instanceof Uint8Array) {
|
|
13607
|
-
const mediaType = (_b = detectMediaType4({
|
|
13608
|
-
data: dataContent,
|
|
13609
|
-
topLevelType: "image"
|
|
13610
|
-
})) != null ? _b : "image/png";
|
|
13611
|
-
image = {
|
|
13607
|
+
return {
|
|
13608
|
+
prompt: promptArg.text,
|
|
13609
|
+
image: promptArg.image != null ? normalizeImageData(promptArg.image) : void 0
|
|
13610
|
+
};
|
|
13611
|
+
}
|
|
13612
|
+
function normalizeImageData(dataContent) {
|
|
13613
|
+
var _a22, _b;
|
|
13614
|
+
if (typeof dataContent === "string") {
|
|
13615
|
+
if (dataContent.startsWith("http://") || dataContent.startsWith("https://")) {
|
|
13616
|
+
return {
|
|
13617
|
+
type: "url",
|
|
13618
|
+
url: dataContent
|
|
13619
|
+
};
|
|
13620
|
+
}
|
|
13621
|
+
if (dataContent.startsWith("data:")) {
|
|
13622
|
+
const { mediaType, base64Content } = splitDataUrl(dataContent);
|
|
13623
|
+
return {
|
|
13612
13624
|
type: "file",
|
|
13613
|
-
mediaType,
|
|
13614
|
-
data:
|
|
13625
|
+
mediaType: mediaType != null ? mediaType : "image/png",
|
|
13626
|
+
data: convertBase64ToUint8Array5(base64Content != null ? base64Content : "")
|
|
13615
13627
|
};
|
|
13616
13628
|
}
|
|
13629
|
+
const bytes2 = convertBase64ToUint8Array5(dataContent);
|
|
13630
|
+
return {
|
|
13631
|
+
type: "file",
|
|
13632
|
+
mediaType: (_a22 = detectMediaType4({ data: bytes2, topLevelType: "image" })) != null ? _a22 : "image/png",
|
|
13633
|
+
data: bytes2
|
|
13634
|
+
};
|
|
13617
13635
|
}
|
|
13636
|
+
const bytes = convertDataContentToUint8Array(dataContent);
|
|
13618
13637
|
return {
|
|
13619
|
-
|
|
13620
|
-
image
|
|
13638
|
+
type: "file",
|
|
13639
|
+
mediaType: (_b = detectMediaType4({ data: bytes, topLevelType: "image" })) != null ? _b : "image/png",
|
|
13640
|
+
data: bytes
|
|
13621
13641
|
};
|
|
13622
13642
|
}
|
|
13623
13643
|
async function invokeModelMaxVideosPerCall(model) {
|